新增文件上传方法 修改ftppdf和ftpimage 方法增加类型
This commit is contained in:
parent
c4e49c9265
commit
19df9ec6da
@ -8,8 +8,12 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* 文件工具类
|
||||
@ -81,4 +85,41 @@ public class FileUtils {
|
||||
return sha256Hex + '.' + FileTypeUtil.getType(new ByteArrayInputStream(content));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Base64编码的字符串保存为文件。
|
||||
*
|
||||
* @param base64String Base64编码的字符串
|
||||
* @param folderPath 文件保存的文件夹路径
|
||||
* @param fileName 文件名(不包含扩展名)
|
||||
* @param extension 文件扩展名(例如 "png", "jpg", "txt")
|
||||
* @throws IOException 如果写入文件时发生错误
|
||||
*/
|
||||
public static void saveBase64ToFile(String base64String, String folderPath, String fileName, String extension) throws IOException {
|
||||
// 检查文件名是否有效
|
||||
if (fileName.contains("..") || fileName.contains("/") || fileName.contains("\\")) {
|
||||
throw new IllegalArgumentException("Invalid file name.");
|
||||
}
|
||||
|
||||
// 解码Base64字符串为字节数组
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(base64String);
|
||||
|
||||
|
||||
// 创建文件的路径
|
||||
Path folder = Paths.get(folderPath);
|
||||
if (!Files.exists(folder)) {
|
||||
// 如果文件夹不存在,则创建它
|
||||
Files.createDirectories(folder);
|
||||
}
|
||||
// 构建完整的文件名(包括扩展名)
|
||||
Path filePath = folder.resolve(fileName + "." + extension);
|
||||
|
||||
// 使用Files.newOutputStream创建OutputStream,并设置为追加模式
|
||||
try (java.io.OutputStream outputStream = Files.newOutputStream(filePath, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
|
||||
outputStream.write(decodedBytes);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,4 +25,5 @@ public class IoUtils {
|
||||
return StrUtil.utf8Str(IoUtil.read(in, isClose));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.tblist.controller.admin.patientexamlist;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.org.OrgUnitDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.org.OrgUnitService;
|
||||
@ -396,12 +397,28 @@ public class PatientexamlistController {
|
||||
@Operation(summary = "获取pdf上传ftp")
|
||||
public void FtpPdf(@RequestBody inspdfscreenshotVO insimagescreenshotVO) {
|
||||
String base64String = insimagescreenshotVO.getImagebase();
|
||||
String fileName = System.currentTimeMillis() + ".pdf";
|
||||
if(insimagescreenshotVO.getModel().equals("0"))
|
||||
{
|
||||
// 解码Base64字符串
|
||||
String base64Image = base64String.split(",")[1];
|
||||
try
|
||||
{
|
||||
FileUtils.saveBase64ToFile(base64Image,insimagescreenshotVO.getFolderPath(),fileName.split("\\.")[0],"pdf");
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
System.out.println("文件上传失败"+ignored.getMessage());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String ftpServer = "114.55.171.231";
|
||||
int ftpPort = 21; // FTP端口,默认为21
|
||||
String ftpUser = "pacs";
|
||||
String ftpPassword = "pacs";
|
||||
String uploadPath = "/";
|
||||
String fileName = System.currentTimeMillis() + ".pdf";
|
||||
|
||||
|
||||
FTPClient ftpClient = new FTPClient();
|
||||
|
||||
@ -423,19 +440,7 @@ public class PatientexamlistController {
|
||||
|
||||
// 上传文件
|
||||
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());
|
||||
PatientexamlistSaveReqVO updateReqVO = new PatientexamlistSaveReqVO();
|
||||
updateReqVO.setId(insimagescreenshotVO.getID());
|
||||
updateReqVO.setPdfurl("http://114.55.171.231:48082/" + fileName);
|
||||
patientexamlistService.updatePatientexamlist(updateReqVO);
|
||||
} else {
|
||||
System.out.println("文件上传失败");
|
||||
}
|
||||
|
||||
|
||||
// 断开连接
|
||||
ftpClient.logout();
|
||||
@ -453,6 +458,18 @@ public class PatientexamlistController {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//上传成功
|
||||
//当前时间
|
||||
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());
|
||||
PatientexamlistSaveReqVO updateReqVO = new PatientexamlistSaveReqVO();
|
||||
updateReqVO.setId(insimagescreenshotVO.getID());
|
||||
updateReqVO.setPdfurl("https://pacs.gw12320.com/video/" +insimagescreenshotVO.getID()+"/"+ fileName);
|
||||
patientexamlistService.updatePatientexamlist(updateReqVO);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,4 +9,8 @@ public class inspdfscreenshotVO {
|
||||
|
||||
private String imagebase;
|
||||
|
||||
private String model;
|
||||
|
||||
private String folderPath;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic.medicalimg;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SaveFileBase64 {
|
||||
|
||||
@Schema(description = "文件保存的文件夹路径")
|
||||
private String folderPath;
|
||||
@Schema(description = "Base64编码的字符串")
|
||||
private String imagebase;
|
||||
@Schema(description = "文件名(不包含扩展名)")
|
||||
private String fileName;
|
||||
@Schema(description = "文件扩展名(例如 \"png\", \"jpg\", \"txt\")")
|
||||
private String extension;
|
||||
|
||||
private String orgId;
|
||||
}
|
@ -17,5 +17,8 @@ public class insimagescreenshotVO {
|
||||
private String imgDescription;
|
||||
|
||||
private String orgId;
|
||||
//
|
||||
private String model;
|
||||
|
||||
private String folderPath;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dicomworklist.DicomImagesDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dicomworklist.DicomSeriesDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dicomworklist.DicompatientDO;
|
||||
@ -14,6 +15,7 @@ import cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic.image.I
|
||||
import cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic.image.PatientInfoVO;
|
||||
import cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic.image.SeriesVO;
|
||||
import cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic.image.StudyVO;
|
||||
import cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic.medicalimg.SaveFileBase64;
|
||||
import cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic.medicalimg.insimagescreenshotVO;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic.medicalimg.upmedicalimgVO;
|
||||
@ -35,15 +37,11 @@ import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
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.LoggerFactory;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -430,17 +428,32 @@ public class ultrasonicController {
|
||||
@Operation(summary = "获取图片上传ftp")
|
||||
public void FtpImage(@RequestBody insimagescreenshotVO insimagescreenshotVO) {
|
||||
String base64String = insimagescreenshotVO.getImagebase();
|
||||
String fileName = System.currentTimeMillis() + ".jpg";
|
||||
if(insimagescreenshotVO.getModel().equals("0"))
|
||||
{
|
||||
// 解码Base64字符串
|
||||
String base64Image = base64String.split(",")[1];
|
||||
try
|
||||
{
|
||||
FileUtils.saveBase64ToFile(base64Image,insimagescreenshotVO.getFolderPath(),fileName.split("\\.")[0],"jpg");
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
System.out.println("文件上传失败"+ignored.getMessage());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String ftpServer = "192.168.0.110"; //114.55.171.231
|
||||
int ftpPort = 21; // FTP端口,默认为21
|
||||
String ftpUser = "pacs";
|
||||
String ftpPassword = "pacs123";
|
||||
String uploadPath = "/";
|
||||
String fileName = System.currentTimeMillis() + ".jpg";
|
||||
|
||||
|
||||
FTPClient ftpClient = new FTPClient();
|
||||
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
try {
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
// 连接FTP服务器
|
||||
ftpClient.connect(ftpServer, ftpPort);
|
||||
ftpClient.login(ftpUser, ftpPassword);
|
||||
@ -457,33 +470,6 @@ public class ultrasonicController {
|
||||
|
||||
// 上传文件
|
||||
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("http://192.168.0.110:48082/" + fileName);
|
||||
medicalimgDO.setCreatePerson("");
|
||||
medicalimgDO.setCreateDate(dateTime);
|
||||
medicalimgDO.setRegId(insimagescreenshotVO.getID());
|
||||
if (insimagescreenshotVO.getOrgId() != null && !insimagescreenshotVO.getOrgId().trim().equals(""))
|
||||
medicalimgDO.setOrgId(insimagescreenshotVO.getOrgId().trim());
|
||||
else if (user != null && user.getOrgId() != null)
|
||||
medicalimgDO.setOrgId(user.getOrgId());
|
||||
medicalimgDO.setSelected("0");
|
||||
if (insimagescreenshotVO.getImgType() == null || insimagescreenshotVO.getImgType().trim().equals(""))
|
||||
medicalimgDO.setImgType("1");
|
||||
else
|
||||
medicalimgDO.setImgType(insimagescreenshotVO.getImgType().trim());
|
||||
int count = medicalimgService.insimage(medicalimgDO);
|
||||
} else {
|
||||
System.out.println("文件上传失败");
|
||||
}
|
||||
|
||||
// 断开连接
|
||||
ftpClient.logout();
|
||||
@ -501,7 +487,31 @@ public class ultrasonicController {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//上传成功
|
||||
//当前时间
|
||||
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/" +insimagescreenshotVO.getID()+"/"+ fileName);
|
||||
medicalimgDO.setCreatePerson("");
|
||||
medicalimgDO.setCreateDate(dateTime);
|
||||
medicalimgDO.setRegId(insimagescreenshotVO.getID());
|
||||
if (insimagescreenshotVO.getOrgId() != null && !insimagescreenshotVO.getOrgId().trim().equals(""))
|
||||
medicalimgDO.setOrgId(insimagescreenshotVO.getOrgId().trim());
|
||||
else if (user != null && user.getOrgId() != null)
|
||||
medicalimgDO.setOrgId(user.getOrgId());
|
||||
medicalimgDO.setSelected("0");
|
||||
if (insimagescreenshotVO.getImgType() == null || insimagescreenshotVO.getImgType().trim().equals(""))
|
||||
medicalimgDO.setImgType("1");
|
||||
else
|
||||
medicalimgDO.setImgType(insimagescreenshotVO.getImgType().trim());
|
||||
int count = medicalimgService.insimage(medicalimgDO);
|
||||
|
||||
}
|
||||
|
||||
@ -622,5 +632,16 @@ public class ultrasonicController {
|
||||
return success("插入成功");
|
||||
}
|
||||
|
||||
@PostMapping("/SaveFileBase64")
|
||||
@Operation(summary = "base64保存文件")
|
||||
public String SaveFileBase64(@RequestBody SaveFileBase64 fileBase64){
|
||||
try{
|
||||
String base=fileBase64.getImagebase();
|
||||
FileUtils.saveBase64ToFile(base,fileBase64.getFolderPath(),fileBase64.getFileName(),fileBase64.getExtension());
|
||||
return "上传成功";
|
||||
} catch (Exception e) {
|
||||
return "上传失败" +e.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user