增加上传ftp图片方法
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled
yudao-ui-admin CI / build (14.x) (push) Has been cancelled
yudao-ui-admin CI / build (16.x) (push) Has been cancelled
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled
yudao-ui-admin CI / build (14.x) (push) Has been cancelled
yudao-ui-admin CI / build (16.x) (push) Has been cancelled
This commit is contained in:
parent
a680fd3830
commit
4f310cf310
@ -130,6 +130,10 @@
|
|||||||
<artifactId>yudao-spring-boot-starter-excel</artifactId>
|
<artifactId>yudao-spring-boot-starter-excel</artifactId>
|
||||||
<version>2.1.0-jdk8-snapshot</version>
|
<version>2.1.0-jdk8-snapshot</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-net</groupId>
|
||||||
|
<artifactId>commons-net</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic.medica
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class insimagescreenshotVO {
|
public class insimagescreenshotVO {
|
||||||
|
|
||||||
@ -9,4 +11,11 @@ public class insimagescreenshotVO {
|
|||||||
private String ID;
|
private String ID;
|
||||||
|
|
||||||
private String imagebase;
|
private String imagebase;
|
||||||
|
|
||||||
|
private String imgType;
|
||||||
|
|
||||||
|
private String imgDescription;
|
||||||
|
|
||||||
|
private String orgId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.apache.commons.net.ftp.FTP;
|
||||||
|
import org.apache.commons.net.ftp.FTPClient;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@ -31,6 +33,10 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.SocketException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -371,19 +377,93 @@ public class ultrasonicController {
|
|||||||
LocalDateTime dateTime = LocalDateTime.parse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
|
LocalDateTime dateTime = LocalDateTime.parse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
|
||||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||||
//当前登陆用户
|
//当前登陆用户
|
||||||
AdminUserDO user = userService.getUser(getLoginUserId());
|
// AdminUserDO user = userService.getUser(getLoginUserId());
|
||||||
// 生成随机 UUID
|
// 生成随机 UUID
|
||||||
UUID randomUUID = UUID.randomUUID();
|
UUID randomUUID = UUID.randomUUID();
|
||||||
medicalimgDO medicalimgDO = new medicalimgDO();
|
medicalimgDO medicalimgDO = new medicalimgDO();
|
||||||
medicalimgDO.setId(randomUUID.toString());
|
medicalimgDO.setId(randomUUID.toString());
|
||||||
medicalimgDO.setImgUrl(insimagescreenshotVO.getImagebase());
|
medicalimgDO.setImgUrl(insimagescreenshotVO.getImagebase());
|
||||||
medicalimgDO.setCreatePerson(user.getUsername());
|
medicalimgDO.setCreatePerson("");
|
||||||
|
medicalimgDO.setCreateDate(dateTime);
|
||||||
|
medicalimgDO.setRegId(insimagescreenshotVO.getID());
|
||||||
|
medicalimgDO.setOrgId(insimagescreenshotVO.getOrgId());
|
||||||
|
medicalimgDO.setSelected("0");
|
||||||
|
medicalimgDO.setImgType(insimagescreenshotVO.getImgType());
|
||||||
|
return medicalimgService.insimage(medicalimgDO);
|
||||||
|
|
||||||
|
}
|
||||||
|
@PostMapping("/ftpimage")
|
||||||
|
@Operation(summary = "获取图片上传ftp")
|
||||||
|
public void FtpImage(@RequestBody insimagescreenshotVO insimagescreenshotVO)
|
||||||
|
{
|
||||||
|
String base64String = insimagescreenshotVO.getImagebase();
|
||||||
|
String ftpServer = "114.55.171.231";
|
||||||
|
int ftpPort = 21; // FTP端口,默认为21
|
||||||
|
String ftpUser = "pacs";
|
||||||
|
String ftpPassword = "pacs";
|
||||||
|
String uploadPath = "/";
|
||||||
|
String fileName = System.currentTimeMillis()+".jpg";
|
||||||
|
|
||||||
|
FTPClient ftpClient = new FTPClient();
|
||||||
|
|
||||||
|
ftpClient.enterLocalPassiveMode();
|
||||||
|
try {
|
||||||
|
// 连接FTP服务器
|
||||||
|
ftpClient.connect(ftpServer, ftpPort);
|
||||||
|
ftpClient.login(ftpUser, ftpPassword);
|
||||||
|
|
||||||
|
// 设置文件传输类型为二进制
|
||||||
|
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
|
||||||
|
// 解码Base64字符串
|
||||||
|
String base64Image = base64String.split(",")[1]; // 去掉数据URL的头部
|
||||||
|
// 解码Base64字符串
|
||||||
|
byte[] decodedBytes = Base64.getDecoder().decode(base64Image);
|
||||||
|
|
||||||
|
// 创建输入流
|
||||||
|
InputStream inputStream = new ByteArrayInputStream(decodedBytes);
|
||||||
|
|
||||||
|
// 上传文件
|
||||||
|
boolean result = ftpClient.storeFile(uploadPath + "/" + fileName, inputStream);
|
||||||
|
if (result) {
|
||||||
|
//上传成功
|
||||||
|
//当前时间
|
||||||
|
LocalDateTime dateTime = LocalDateTime.parse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
|
||||||
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
AdminUserDO user = userService.getUser(getLoginUserId());
|
||||||
|
// 生成随机 UUID
|
||||||
|
UUID randomUUID = UUID.randomUUID();
|
||||||
|
medicalimgDO medicalimgDO = new medicalimgDO();
|
||||||
|
medicalimgDO.setId(randomUUID.toString());
|
||||||
|
medicalimgDO.setImgUrl("/video/"+fileName);
|
||||||
|
medicalimgDO.setCreatePerson("");
|
||||||
medicalimgDO.setCreateDate(dateTime);
|
medicalimgDO.setCreateDate(dateTime);
|
||||||
medicalimgDO.setRegId(insimagescreenshotVO.getID());
|
medicalimgDO.setRegId(insimagescreenshotVO.getID());
|
||||||
medicalimgDO.setOrgId(user.getOrgId());
|
medicalimgDO.setOrgId(user.getOrgId());
|
||||||
medicalimgDO.setSelected("0");
|
medicalimgDO.setSelected("0");
|
||||||
medicalimgDO.setImgType("1");
|
medicalimgDO.setImgType("1");
|
||||||
return medicalimgService.insimage(medicalimgDO);
|
int count=medicalimgService.insimage(medicalimgDO);
|
||||||
|
} else {
|
||||||
|
System.out.println("文件上传失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 断开连接
|
||||||
|
ftpClient.logout();
|
||||||
|
ftpClient.disconnect();
|
||||||
|
} catch (SocketException e) {
|
||||||
|
System.err.println("无法连接到FTP服务器: " + e.getMessage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("IO异常: " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (ftpClient.isConnected()) {
|
||||||
|
ftpClient.disconnect();
|
||||||
|
}
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user