hyy 4 kuukautta sitten
vanhempi
commit
232dbcda26

+ 4 - 7
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/controller/admin/specimeninfo/SpecimenInfoController.java

@@ -18,8 +18,10 @@ import io.swagger.v3.oas.annotations.Operation;
 
 import javax.validation.*;
 import javax.servlet.http.*;
+import java.io.File;
 import java.math.BigDecimal;
 import java.net.URLEncoder;
+import java.nio.file.Files;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.io.IOException;
@@ -184,17 +186,12 @@ public class SpecimenInfoController {
         // 处理标本图片的导入(如果存在)
         if (imageFile != null && !imageFile.isEmpty()) {
             String imageResult = specimenInfoService.importSpecimenImages(imageFile);
-            // 确保返回的数据不为 null
+//             确保返回的数据不为 null
             if (imageResult == null) {
                 throw exception(INVALID_IMAGE_FORMAT);
             }
         }
-
-        // 如果没有上传任何文件,返回相应的提示信息
-        if (importResult == null && imageFile == null) {
-            throw exception(SPECIMEN_FILE_OR_IMAGE_REQUIRED);
-        }
-
+        System.gc();
         return success(importResult);
     }
 

+ 5 - 6
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/dal/mysql/specimeninfo/SpecimenInfoMapper.java

@@ -153,15 +153,14 @@ public interface SpecimenInfoMapper extends BaseMapperX<SpecimenInfoDO> {
     @Select("SELECT * FROM museums_specimen_info WHERE image_name = #{imageName}")
     SpecimenInfoDO selectByImageName(@Param("imageName") String imageName);
 
-    @Select("SELECT * FROM museums_specimen_info WHERE image_name LIKE CONCAT('%', #{imageName}, '%')")
-    SpecimenInfoDO selectByImageNames(@Param("imageName") String imageName);
+    default SpecimenInfoDO selectByImageNames(String imageName) {
+        return selectOne(new LambdaQueryWrapperX<SpecimenInfoDO>()
+                .likeIfPresent(SpecimenInfoDO::getImageName, imageName)
+        );
+    }
 
     List<Map<String, Object>> selectMonthlyEntryStatisticsByYear(@Param("year") int year);
 
     boolean existsByNumber(String number);
 
-
-
-
-
 }

+ 32 - 19
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimeninfo/SpecimenInfoServiceImpl.java

@@ -90,19 +90,30 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
 //        specimenInfoMapper.updateById(updateObj);
 //    }
 
+//    @Override
+//    @LogRecord(type = MUSEUMS_SPECIMEN_TYPE, subType = MUSEUMS_SPECIMEN_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
+//            success = MUSEUMS_SPECIMEN_UPDATE_SUCCESS , extra = "{{#updateReqVO.id}}")
+//    public void updateSpecimenInfo(SpecimenInfoSaveReqVO updateReqVO) {
+//        // 校验存在
+//        validateSpecimenInfoExists(updateReqVO.getId());
+//        // 更新
+//        SpecimenInfoDO updateObj = BeanUtils.toBean(updateReqVO, SpecimenInfoDO.class);
+//        specimenInfoMapper.updateById(updateObj);
+//        // 记录操作日志上下文
+//        LogRecordContext.putVariable("update-specimen", updateObj);
+//    }
     @Override
     @LogRecord(type = MUSEUMS_SPECIMEN_TYPE, subType = MUSEUMS_SPECIMEN_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
             success = MUSEUMS_SPECIMEN_UPDATE_SUCCESS , extra = "{{#updateReqVO.id}}")
     public void updateSpecimenInfo(SpecimenInfoSaveReqVO updateReqVO) {
         // 校验存在
-        validateSpecimenInfoExists(updateReqVO.getId());
-        // 更新
-        SpecimenInfoDO updateObj = BeanUtils.toBean(updateReqVO, SpecimenInfoDO.class);
-        specimenInfoMapper.updateById(updateObj);
-        // 记录操作日志上下文
-        LogRecordContext.putVariable("update-specimen", updateObj);
+        SpecimenInfoDO specimenInfo = specimenInfoMapper.selectById(updateReqVO.getId());
+        if(specimenInfo != null){
+            SpecimenInfoDO updateObj = BeanUtils.toBean(updateReqVO, SpecimenInfoDO.class);
+            specimenInfoMapper.updateById(updateObj);
+            LogRecordContext.putVariable("update-specimen", updateObj);
+        }
     }
-
     @Override
     @Transactional(rollbackFor = Exception.class)
     @LogRecord(type = MUSEUMS_SPECIMEN_TYPE, subType = MUSEUMS_SPECIMEN_DELETE_SUB_TYPE, bizNo = "{{#id}}",
@@ -233,20 +244,24 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
     @Transactional(rollbackFor = Exception.class)
     public String importSpecimenImages(MultipartFile file) throws Exception {
         // 校验文件类型
-        if (!file.getOriginalFilename().toLowerCase().endsWith(".zip")) {
+        if (!file.getOriginalFilename().endsWith(".zip")) {
             throw exception(UPLOADED_FOLDER_CANNOT_EMPTY);
         }
-
         // 创建临时目录存放解压后的文件
         File tempDir = Files.createTempDirectory("specimen_images").toFile();
-        ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream());
-        try {
+        // 创建一个临时文件用于存储上传的 ZIP 文件
+        File tempZipFile = File.createTempFile("uploaded_", ".zip");
+        // 将 MultipartFile 的内容复制到临时文件
+        file.transferTo(tempZipFile);
+        try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(tempZipFile.toPath()))) {
             ZipEntry entry;
             while ((entry = zipInputStream.getNextEntry()) != null) {
                 if (!entry.isDirectory()) {
                     File newFile = new File(tempDir, entry.getName());
+                    // 确保目录存在
+                    newFile.getParentFile().mkdirs();
                     // 进行解压
-                    try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))) {
+                    try (BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(newFile.toPath()))) {
                         byte[] buffer = new byte[1024];
                         int len;
                         while ((len = zipInputStream.read(buffer)) > 0) {
@@ -256,7 +271,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
                 }
                 zipInputStream.closeEntry();
             }
-
             // 处理每个图片文件
             File[] imageFiles = tempDir.listFiles();
             if (imageFiles != null) {
@@ -279,16 +293,16 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
                             // 添加新上传的路径
                             imagePathsSet.add(imagePath.trim());
 
-                            // 获取已存在的路径,并处理空值或无效的路径
+                            // 添加已存在的路径
                             String existingImagePaths = specimenInfo.getImagePath();
-                            if (existingImagePaths != null && !existingImagePaths.trim().isEmpty() && !existingImagePaths.equals("[]")) {
-                                // 如果原路径是有效的且不是空数组,则拆分并添加到 Set 中
+                            if (existingImagePaths != null && !existingImagePaths.trim().isEmpty()) {
                                 String[] existingPaths = existingImagePaths.split(",\\s*");
                                 Collections.addAll(imagePathsSet, existingPaths);
                             }
                         }
                     }
                 }
+
                 // 生成最终的逗号分隔的字符串
                 String newImagePaths = String.join(", ", imagePathsSet);
                 // 更新所有标本的信息,确保只更新一次
@@ -301,16 +315,15 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
                     }
                 }
             }
-        } finally {
             zipInputStream.close();
-
+            System.gc();
+        } finally {
             // 清理临时文件
             FileUtils.deleteDirectory(tempDir);
         }
         return "标本图片导入成功";
     }
 
-
     //工作台
     //根据入库的登记情况统计本年标本入库信息
     @Override

+ 2 - 1
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimenoutbound/SpecimenOutboundServiceImpl.java

@@ -243,7 +243,8 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
                 .setSpecimenCondition(updateReqVO.getSpecimenCondition()) // 设置标本状态
                 .setReturner(updateReqVO.getReturner()) // 设置归还人
                 .setReceiver(updateReqVO.getReceiver()) // 设置接收人
-                .setRemarks(updateReqVO.getRemarks()); // 设置备注
+                .setRemarks(updateReqVO.getRemarks()) // 设置备注
+                .setSampleStatus(updateReqVO.getSampleStatus());//回库附件上传
 
         // 更新数据库
         specimenOutboundMapper.updateById(existingSpecimen);