|
@@ -5,6 +5,8 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
|
|
import cn.iocoder.yudao.module.museums.dal.dataobject.specimenoutbound.SpecimenOutboundDO;
|
|
|
import cn.iocoder.yudao.module.museums.dal.mysql.specimenoutbound.SpecimenOutboundMapper;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.apache.tomcat.util.http.fileupload.FileUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -169,8 +171,75 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
return true;
|
|
|
}
|
|
|
//图片导入
|
|
|
+// @Override
|
|
|
+// @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
+// public String importSpecimenImages(MultipartFile file) throws Exception {
|
|
|
+// // 校验文件类型
|
|
|
+// if (!file.getOriginalFilename().endsWith(".zip")) {
|
|
|
+// throw exception(UPLOADED_FOLDER_CANNOT_EMPTY);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 创建临时目录存放解压后的文件
|
|
|
+// File tempDir = Files.createTempDirectory("specimen_images").toFile();
|
|
|
+// try (ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream())) {
|
|
|
+// ZipEntry entry;
|
|
|
+// while ((entry = zipInputStream.getNextEntry()) != null) {
|
|
|
+// if (!entry.isDirectory()) {
|
|
|
+// File newFile = new File(tempDir, entry.getName());
|
|
|
+// // 进行解压
|
|
|
+// try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))) {
|
|
|
+// byte[] buffer = new byte[1024];
|
|
|
+// int len;
|
|
|
+// while ((len = zipInputStream.read(buffer)) > 0) {
|
|
|
+// bos.write(buffer, 0, len);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 处理每个图片文件
|
|
|
+// File[] imageFiles = tempDir.listFiles();
|
|
|
+// if (imageFiles != null) {
|
|
|
+// for (File imageFile : imageFiles) {
|
|
|
+// String imageName = imageFile.getName();
|
|
|
+// if (!isValidImageName(imageName)) {
|
|
|
+// System.err.println("无效的图片格式: " + imageName);
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// // 根据图片名称查找对应的标本
|
|
|
+// SpecimenInfoDO specimenInfo = specimenInfoMapper.selectByImageNames(imageName);
|
|
|
+// if (specimenInfo != null) {
|
|
|
+// // 上传图片并获取URL
|
|
|
+// String imagePath = fileApi.createFile(Files.readAllBytes(imageFile.toPath()));
|
|
|
+// // 获取当前的图片路径
|
|
|
+// Set<String> imagePathsSet = new HashSet<>();
|
|
|
+// String existingImagePaths = specimenInfo.getImagePath();
|
|
|
+//
|
|
|
+// // 如果 existingImagePaths 为空或仅包含空白字符,则不添加
|
|
|
+// if (existingImagePaths != null && !existingImagePaths.trim().isEmpty()) {
|
|
|
+// Collections.addAll(imagePathsSet, existingImagePaths.split(","));
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 检查 imagePath 是否有效
|
|
|
+// if (imagePath != null && !imagePath.trim().isEmpty()) {
|
|
|
+// imagePathsSet.add(imagePath);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 转换回字符串,避免前面出现多余的逗号
|
|
|
+// String newImagePaths = String.join(",", imagePathsSet);
|
|
|
+// specimenInfo.setImagePath(newImagePaths);
|
|
|
+//
|
|
|
+// updateSpecimenInfo(BeanUtils.toBean(specimenInfo, SpecimenInfoSaveReqVO.class));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 清理临时文件
|
|
|
+// FileUtils.deleteDirectory(tempDir);
|
|
|
+// return "标本图片导入成功";
|
|
|
+// }
|
|
|
+
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public String importSpecimenImages(MultipartFile file) throws Exception {
|
|
|
// 校验文件类型
|
|
|
if (!file.getOriginalFilename().endsWith(".zip")) {
|
|
@@ -194,6 +263,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// 处理每个图片文件
|
|
|
File[] imageFiles = tempDir.listFiles();
|
|
|
if (imageFiles != null) {
|
|
@@ -203,39 +273,64 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
System.err.println("无效的图片格式: " + imageName);
|
|
|
continue;
|
|
|
}
|
|
|
+
|
|
|
// 根据图片名称查找对应的标本
|
|
|
SpecimenInfoDO specimenInfo = specimenInfoMapper.selectByImageNames(imageName);
|
|
|
if (specimenInfo != null) {
|
|
|
- // 上传图片并获取URL
|
|
|
+ // 上传图片并获取 URL
|
|
|
String imagePath = fileApi.createFile(Files.readAllBytes(imageFile.toPath()));
|
|
|
+
|
|
|
// 获取当前的图片路径
|
|
|
- Set<String> imagePathsSet = new HashSet<>();
|
|
|
+ List<String> imagePathsList = new ArrayList<>();
|
|
|
String existingImagePaths = specimenInfo.getImagePath();
|
|
|
|
|
|
- // 如果 existingImagePaths 为空或仅包含空白字符,则不添加
|
|
|
+ // 如果 existingImagePaths 不为空,则加入已存在路径
|
|
|
if (existingImagePaths != null && !existingImagePaths.trim().isEmpty()) {
|
|
|
- Collections.addAll(imagePathsSet, existingImagePaths.split(","));
|
|
|
+ // 解析已存在的 JSON 字符串
|
|
|
+ try {
|
|
|
+ List<String> existingPaths = new ObjectMapper().readValue(existingImagePaths, new TypeReference<List<String>>() {});
|
|
|
+ imagePathsList.addAll(existingPaths);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("解析现有路径失败: " + e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 检查 imagePath 是否有效
|
|
|
if (imagePath != null && !imagePath.trim().isEmpty()) {
|
|
|
- imagePathsSet.add(imagePath);
|
|
|
+ // 直接添加 URL
|
|
|
+ imagePathsList.add(imagePath.trim()); // 修剪空格
|
|
|
}
|
|
|
|
|
|
- // 转换回字符串,避免前面出现多余的逗号
|
|
|
- String newImagePaths = String.join(",", imagePathsSet);
|
|
|
- specimenInfo.setImagePath(newImagePaths);
|
|
|
+ // 生成有效的 JSON
|
|
|
+ String newImagePathsJson = convertListToJson(imagePathsList);
|
|
|
+ specimenInfo.setImagePath(newImagePathsJson);
|
|
|
|
|
|
+ // 更新数据库中的标本信息
|
|
|
updateSpecimenInfo(BeanUtils.toBean(specimenInfo, SpecimenInfoSaveReqVO.class));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ } finally {
|
|
|
+ // 清理临时文件
|
|
|
+ FileUtils.deleteDirectory(tempDir);
|
|
|
}
|
|
|
- // 清理临时文件
|
|
|
- FileUtils.deleteDirectory(tempDir);
|
|
|
return "标本图片导入成功";
|
|
|
}
|
|
|
|
|
|
+ // 将 List 转换为 JSON 格式的字符串
|
|
|
+ private String convertListToJson(List<String> list) {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ return objectMapper.writeValueAsString(list); // 直接将列表转换为 JSON
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ System.err.println("转换 List 到 JSON 失败: " + e.getMessage());
|
|
|
+ return "[]"; // 返回空数组的 JSON 表示
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//工作台
|
|
|
//根据入库的登记情况统计本年标本入库信息
|
|
|
@Override
|
|
@@ -370,14 +465,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //根据入馆凭证中标本来源的登记情况统计
|
|
|
- //不好用,准备废弃
|
|
|
- @Override
|
|
|
- public List<SpecimenInfoDO> getSpecimenSourceStatistics(int year) {
|
|
|
- return specimenInfoMapper.selectSpecimenSourceStatistics(year);
|
|
|
- }
|
|
|
-
|
|
|
//标本库管理
|
|
|
//实现对标本操作记录进行追溯查看,包括入库记录、编辑记录、出库记录、回库记录等。
|
|
|
@Override
|