|
@@ -194,6 +194,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
// 处理每个图片文件
|
|
|
File[] imageFiles = tempDir.listFiles();
|
|
|
if (imageFiles != null) {
|
|
|
+ Set<String> imagePathsSet = new HashSet<>(); // 使用 Set 防止重复
|
|
|
for (File imageFile : imageFiles) {
|
|
|
String imageName = imageFile.getName();
|
|
|
if (!isValidImageName(imageName)) {
|
|
@@ -207,32 +208,29 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
// 上传图片并获取 URL
|
|
|
String imagePath = fileApi.createFile(Files.readAllBytes(imageFile.toPath()));
|
|
|
|
|
|
- // 获取当前的图片路径
|
|
|
- List<String> imagePathsList = new ArrayList<>();
|
|
|
- String existingImagePaths = specimenInfo.getImagePath();
|
|
|
-
|
|
|
- // 如果 existingImagePaths 不为空,则加入已存在路径
|
|
|
- if (existingImagePaths != null && !existingImagePaths.trim().isEmpty()) {
|
|
|
- // 解析已存在的 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 是否有效
|
|
|
+ // 确保 imagePath 有效且不为空
|
|
|
if (imagePath != null && !imagePath.trim().isEmpty()) {
|
|
|
- // 直接添加 URL
|
|
|
- imagePathsList.add(imagePath.trim()); // 修剪空格
|
|
|
+ // 添加新上传的路径
|
|
|
+ imagePathsSet.add(imagePath.trim());
|
|
|
+
|
|
|
+ // 添加已存在的路径
|
|
|
+ String existingImagePaths = specimenInfo.getImagePath();
|
|
|
+ if (existingImagePaths != null && !existingImagePaths.trim().isEmpty()) {
|
|
|
+ String[] existingPaths = existingImagePaths.split(",\\s*");
|
|
|
+ Collections.addAll(imagePathsSet, existingPaths);
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 生成有效的 JSON
|
|
|
- String newImagePathsJson = convertListToJson(imagePathsList);
|
|
|
- specimenInfo.setImagePath(newImagePathsJson);
|
|
|
-
|
|
|
- // 更新数据库中的标本信息
|
|
|
+ // 生成最终的逗号分隔的字符串
|
|
|
+ String newImagePaths = String.join(", ", imagePathsSet);
|
|
|
+ // 更新所有标本的信息,确保只更新一次
|
|
|
+ for (File imageFile : imageFiles) {
|
|
|
+ String imageName = imageFile.getName();
|
|
|
+ SpecimenInfoDO specimenInfo = specimenInfoMapper.selectByImageNames(imageName);
|
|
|
+ if (specimenInfo != null) {
|
|
|
+ specimenInfo.setImagePath(newImagePaths);
|
|
|
updateSpecimenInfo(BeanUtils.toBean(specimenInfo, SpecimenInfoSaveReqVO.class));
|
|
|
}
|
|
|
}
|
|
@@ -244,16 +242,10 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
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 表示
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
//工作台
|
|
|
//根据入库的登记情况统计本年标本入库信息
|