yzx 1 сар өмнө
parent
commit
620baf69fe

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

@@ -366,16 +366,19 @@ public class SpecimenInfoController {
         Class<?> voClass = null;
 
         // 使用 if 语句选择不同的模板
-        if (specimenType == 0) { // 矿物
+        if (specimenType == -1) { // 总表
+            voClass = SpecimenImportExcelVO.class;
+            list = getAllExcel();
+        } else if (specimenType == 0) { // 矿物
             voClass = MineralSpecimenImportExcelVO.class;
             list = getMineralTemplate();
         } else if (specimenType == 1) { // 岩石-矿石
             voClass = RockSpecimenImportExcelVO.class;
             list = getRockTemplate();
-        } else if (specimenType == 2) { // 总表
-            voClass = SpecimenImportExcelVO.class;
-            list = getAllExcel();
-        } else if (specimenType == 3) { // 化石
+        }else if (specimenType == 2) { // 岩石-矿石
+            voClass = RockSpecimenImportExcelVO.class;
+            list = getRockTemplate();
+        } else  if (specimenType == 3) { // 化石
             voClass = FossilSpecimenImportExcelVO.class;
             list = getFossilTemplate();
         } else if (specimenType == 4) { // 陨石
@@ -580,8 +583,6 @@ public class SpecimenInfoController {
     }
 
 
-
-
     @PostMapping("/import-specimen-with-images")
     @Operation(summary = "导入标本及其图片")
     @Parameters({
@@ -593,33 +594,28 @@ public class SpecimenInfoController {
     public CommonResult<SpecimenImportRespVO> importSpecimenWithImages(
             @RequestParam(value = "file", required = false) MultipartFile file,
             @RequestParam(value = "imageFile", required = false) MultipartFile imageFile,
-            @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
-
-        // 验证输入条件
-        //必须同时上传Excel文件和压缩包文件,或者只上传Excel文件。
-        if (imageFile != null && !imageFile.isEmpty() && (file == null || file.isEmpty())) {
+            @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport,
+            @RequestParam(value = "updateType", required = false, defaultValue = "null") Integer updateType) throws Exception {
+        if (file == null || file.isEmpty()) {
             throw exception(MUST_UPLOADED_EXCEL_AND_IMAGE);
         }
+        List<SpecimenImportExcelVO> specimenList = ExcelUtils.read(file, SpecimenImportExcelVO.class);
+        try {
+            // 调用服务层创建照片组并上传照片
+            SpecimenImportRespVO importResult
+                    = specimenInfoService.importSpecimenListAndImages(specimenList, imageFile, updateType, updateSupport);
+            System.gc();
+            return success(importResult);
+        } catch (Exception e) {
+            // 处理异常,返回失败的响应
+            throw exception(UPLOADED_FOLDER_CANNOT_EMPTY);
+        }
+    }
 
-        SpecimenImportRespVO importResult = null;
 
-        // 处理 Excel 文件中的标本数据(如果存在)
-        if (file != null && !file.isEmpty()) {
-            List<SpecimenImportExcelVO> specimenList = ExcelUtils.read(file, SpecimenImportExcelVO.class);
-            importResult = specimenInfoService.importSpecimenList(specimenList, updateSupport);
-        }
 
-        // 处理标本图片的导入(如果存在)
-        if (imageFile != null && !imageFile.isEmpty()) {
-            importResult = specimenInfoService.importSpecimenImages(imageFile);
-            if (importResult == null) {
-                throw exception(INVALID_IMAGE_FORMAT);
-            }
-        }
+    //工作台
 
-        System.gc();
-        return success(importResult);
-    }
 
 
     //工作台