Browse Source

标本导入

hyy 2 months ago
parent
commit
8acfe3ff53

+ 1 - 0
yudao-module-museums/yudao-module-museums-api/src/main/java/cn/iocoder/yudao/module/museums/enums/ErrorCodeConstants.java

@@ -17,6 +17,7 @@ public class ErrorCodeConstants {
     public static final ErrorCode SPECIMEN_NUMBER_NOT_EXISTS = new ErrorCode(1-016-000-005, "标本编号无效或不存在");
     public static final ErrorCode MUST_UPLOADED_EXCEL_AND_IMAGE = new ErrorCode(1-016-000-006, "必须同时上传Excel文件和图片压缩包文件,或者只上传Excel文件。");
     public static final ErrorCode INVALID_SPECIMEN_TYPE = new ErrorCode(1-016-000-007, "无效的标本类型");
+    public static final ErrorCode UPLOADED_FOLDER_CANNOT_SUCCESS = new ErrorCode(1-016-000-002, "标本批量导入失败");
 
     // ========== 标本出库回库信息 1-016-001-000 ==========
     public static final ErrorCode SPECIMEN_OUTBOUND_NOT_EXISTS = new ErrorCode(1-016-001-000, "标本出库回库信息不存在");

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

@@ -608,16 +608,10 @@ public class SpecimenInfoController {
             return success(importResult);
         } catch (Exception e) {
             // 处理异常,返回失败的响应
-            throw exception(UPLOADED_FOLDER_CANNOT_EMPTY);
+            throw exception(UPLOADED_FOLDER_CANNOT_SUCCESS);
         }
     }
 
-
-
-    //工作台
-
-
-
     //工作台
     @GetMapping("/statistics/entry/{year}")
     @Operation(summary = "统计本年标本每月入库数量")

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

@@ -367,29 +367,31 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
                 respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "图片名称格式不正确");
                 return;
             }
-
-            String[] names = importSpecimen.getImageName().split("、");
             List<String> imagePathSet = new ArrayList<>();
-            for (String importName : names) {
-                File imageFile = findImageInTempDir(tempDir, importName);
-                if (imageFile != null) {
-                    try {
-                        byte[] imageBytes = Files.readAllBytes(imageFile.toPath());
-                        String imagePath = fileApi.createFile(imageBytes);
-                        imagePathSet.add(imagePath);
-                        respVO.getCreateSpecimenImages().add(importName);
-                        // 处理上传后的路径,如存储到数据库或更新状态等
-                    } catch (IOException e) {
-                        respVO.getFailureSpecimenImages().put(importName, "图片上传失败");
+            if(importSpecimen.getImageName() != null){
+                String[] names = importSpecimen.getImageName().split("、");
+                for (String importName : names) {
+                    File imageFile = findImageInTempDir(tempDir, importName);
+                    if (imageFile != null) {
+                        try {
+                            byte[] imageBytes = Files.readAllBytes(imageFile.toPath());
+                            String imagePath = fileApi.createFile(imageBytes);
+                            imagePathSet.add(imagePath);
+                            respVO.getCreateSpecimenImages().add(importName);
+                            // 处理上传后的路径,如存储到数据库或更新状态等
+                        } catch (IOException e) {
+                            respVO.getFailureSpecimenImages().put(importName, "图片上传失败");
+                        }
+                    } else {
+                        respVO.getFailureSpecimenImages().put(importSpecimen.getSpecimenNumber(), "图片不存在压缩包中");
+                    }
+                    if (existSpecimen != null &&  imagePathSet.isEmpty()) {
+                        imagePathSet = BeanUtils.toBean(existSpecimen, SpecimenInfoRespVO.class).getImagePath();
                     }
-                } else {
-                    respVO.getFailureSpecimenImages().put(importSpecimen.getSpecimenNumber(), "图片不存在压缩包中");
-                }
-                if (existSpecimen != null &&  imagePathSet.isEmpty()) {
-                    imagePathSet = BeanUtils.toBean(existSpecimen, SpecimenInfoRespVO.class).getImagePath();
                 }
             }
 
+
             // 处理文献资料字段,如果为空就赋值 <br>
             if (importSpecimen.getDescription() == null || importSpecimen.getDescription().trim().isEmpty()) {
                 importSpecimen.setDescription("<p><br></p>");
@@ -417,8 +419,11 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
             // 更新逻辑
             SpecimenInfoDO updateSpecimen = BeanUtils.toBean(importSpecimen, SpecimenInfoDO.class);
 
-
-            updateSpecimen.setImagePath(imagePathSet.toString());
+            if(imagePathSet != null){
+                updateSpecimen.setImagePath(imagePathSet.toString());
+            }else {
+                updateSpecimen.setImagePath(null);
+            }
             if (updateType != -1) {
                 updateSpecimen.setSpecimenType(updateType);
             }