Ver código fonte

标本导出

hyy 1 mês atrás
pai
commit
66713da699

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

@@ -93,24 +93,24 @@ public class SpecimenInfoController {
         return success(BeanUtils.toBean(pageResult, SpecimenInfoRespVO.class));
     }
 
-//    @GetMapping("/export-excel")
-//    @Operation(summary = "导出标本管理 Excel")
-//    @PreAuthorize("@ss.hasPermission('museums:specimen-info:export')")
-//    @ApiAccessLog(operateType = EXPORT)
-//    public void exportSpecimenInfoExcel(@Valid SpecimenInfoExportReqVO pageReqVO,
-//              HttpServletResponse response) throws IOException {
-//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
-//        List<SpecimenInfoDO> list = specimenInfoService.getSpecimenInfoExcel(pageReqVO).getList();
-//        // 导出 Excel
-//        ExcelUtils.write(response, "标本总表.xls", "数据", SpecimenInfoExportRespVO.class,
-//                        BeanUtils.toBean(list, SpecimenInfoExportRespVO.class));
-//    }
-
     @GetMapping("/export-excel")
     @Operation(summary = "导出标本管理 Excel")
     @PreAuthorize("@ss.hasPermission('museums:specimen-info:export')")
     @ApiAccessLog(operateType = EXPORT)
     public void exportSpecimenInfoExcel(@Valid SpecimenInfoExportReqVO pageReqVO,
+              HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<SpecimenInfoDO> list = specimenInfoService.getSpecimenInfoExcel(pageReqVO).getList();
+        // 导出 Excel
+        ExcelUtils.write(response, "标本总表.xls", "数据", SpecimenInfoExportRespVO.class,
+                        BeanUtils.toBean(list, SpecimenInfoExportRespVO.class));
+    }
+
+    @GetMapping("/select-excel")
+    @Operation(summary = "导出标本管理 Excel")
+    @PreAuthorize("@ss.hasPermission('museums:specimen-info:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportSpecimenInfoSelectExcel(@Valid SpecimenInfoExportReqVO pageReqVO,
                                         @RequestParam List<Long> ids,  // 接收前端传递的 ID 数组
                                         HttpServletResponse response) throws IOException {
         // 如果有 ID 数组,设置查询条件,过滤查询
@@ -119,7 +119,7 @@ public class SpecimenInfoController {
         }
 
         pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);  // 设置不分页
-        List<SpecimenInfoDO> list = specimenInfoService.getSpecimenInfoExcel(pageReqVO, ids);  // 根据 ID 查询数据
+        List<SpecimenInfoDO> list = specimenInfoService.getSpecimenInfoSelectExcel(pageReqVO, ids);  // 根据 ID 查询数据
 
         // 导出 Excel
         ExcelUtils.write(response, "标本总表.xls", "数据", SpecimenInfoExportRespVO.class,

+ 3 - 3
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/controller/admin/specimeninfo/vo/SpecimenInfoExportRespVO.java

@@ -150,9 +150,9 @@ public class SpecimenInfoExportRespVO {
     @ExcelProperty("备注")
     private String notes;
 
-    @Schema(description = "入库操作员")
-    @ExcelProperty("入库操作员")
-    private String operator;
+//    @Schema(description = "入库操作员")
+//    @ExcelProperty("入库操作员")
+//    private String operator;
 
     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
     @ExcelProperty("创建时间")

+ 2 - 2
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimeninfo/SpecimenInfoService.java

@@ -58,8 +58,8 @@ public interface SpecimenInfoService {
      * @param pageReqVO 分页查询
      * @return 标本管理分页
      */
-//    PageResult<SpecimenInfoDO> getSpecimenInfoExcel(SpecimenInfoExportReqVO pageReqVO);
-    List<SpecimenInfoDO> getSpecimenInfoExcel(SpecimenInfoExportReqVO pageReqVO, List<Long> ids);
+    PageResult<SpecimenInfoDO> getSpecimenInfoExcel(SpecimenInfoExportReqVO pageReqVO);
+    List<SpecimenInfoDO> getSpecimenInfoSelectExcel(SpecimenInfoExportReqVO pageReqVO, List<Long> ids);
 
     /**
      * 批量导入标本

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

@@ -134,13 +134,13 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
         return specimenInfoMapper.selectPage(pageReqVO);
     }
 
-//    @Override
-//    public PageResult<SpecimenInfoDO> getSpecimenInfoExcel(SpecimenInfoExportReqVO pageReqVO) {
-//        return specimenInfoMapper.selectPage(pageReqVO);
-//    }
+    @Override
+    public PageResult<SpecimenInfoDO> getSpecimenInfoExcel(SpecimenInfoExportReqVO pageReqVO) {
+        return specimenInfoMapper.selectPage(pageReqVO);
+    }
 
     @Override
-    public List<SpecimenInfoDO> getSpecimenInfoExcel(SpecimenInfoExportReqVO pageReqVO, List<Long> ids) {
+    public List<SpecimenInfoDO> getSpecimenInfoSelectExcel(SpecimenInfoExportReqVO pageReqVO, List<Long> ids) {
         if (!ids.isEmpty()) {
             return specimenInfoMapper.selectByIds(ids);  // 使用自定义的 Mapper 方法来根据 IDs 查询
         }
@@ -413,6 +413,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
             }
 
             LocalDateTime qidian = LocalDateTime.of(1, Month.JANUARY, 1, 0, 0);
+
             if (importSpecimen.getAcquisitionTime() != null
                     && parseToLocalDateTime(importSpecimen.getAcquisitionTime()).equals(qidian)) {
                 respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "无效的入藏时间!");
@@ -431,6 +432,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
                 return;
             }
 
+
             if (existSpecimen == null) {
                 // 2.2.1 不存在则插入
                 SpecimenInfoDO newSpecimen = BeanUtils.toBean(importSpecimen, SpecimenInfoDO.class);
@@ -491,39 +493,59 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
     }
 
     private static LocalDateTime parseToLocalDateTime(String dateString) {
-        // 列出支持的日期格式
+        if (dateString == null || dateString.isEmpty()) {
+            return LocalDateTime.of(1, Month.JANUARY, 1, 0, 0);  // 处理 null 或空字符串的情况
+        }
+
+        // 预处理日期字符串,确保日期部分符合格式要求
+        dateString = preprocessDateString(dateString);
+
+        // 允许的日期格式列表
         List<String> dateFormats = Arrays.asList(
-            "yyyy-MM-dd HH:mm:ss",
-            "yyyy/MM/dd HH:mm:ss",
-            "yyyy-MM-dd'T'HH:mm:ss",  // ISO_LOCAL_DATE_TIME 格式
-            "yyyy/MM/dd'T'HH:mm:ss",
-            "yyyy-MM-dd",
-            "yyyyMM/dd",
-            "dd-MM-yyyy HH:mm:ss",
-            "dd/MM/yyyy HH:mm:ss",
-            "dd-MM-yyyy",
-            "dd/MM/yyyy"
+                "yyyy-MM-dd HH:mm:ss",
+                "yyyy/MM/dd HH:mm:ss",
+                "yyyy-MM-dd",
+                "yyyy/MM/dd",  // 支持没有时间部分的日期
+                "yyyy/MM/d",   // 支持没有前导零的日期
+                "yyyy-MM-dd'T'HH:mm:ss"
         );
 
         // 尝试每种日期格式
         for (String format : dateFormats) {
             try {
                 DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
-                // 使用 parse 方法将字符串解析为 LocalDateTime
                 if (format.contains("HH")) {
                     return LocalDateTime.parse(dateString, formatter);
                 } else {
-                    // 如果格式不包含时间部分,则补充时间部分为00:00:00
+                    // 如果格式不包含时间部分,补充默认时间 "00:00:00"
                     return LocalDateTime.parse(dateString + " 00:00:00", formatter);
                 }
             } catch (DateTimeParseException e) {
+                System.err.println("解析失败: " + dateString + " 使用格式: " + format);
                 // 如果解析失败,继续尝试下一个格式
             }
         }
 
+        // 如果没有任何格式能够解析,则返回一个默认的时间值
         return LocalDateTime.of(1, Month.JANUARY, 1, 0, 0);
     }
 
+
+    // 预处理日期字符串,确保日期部分符合格式要求(补充单数字日期为双位数)
+    private static String preprocessDateString(String dateString) {
+        // 如果日期格式是 "yyyy/MM/d"(例如 "2012/5/5"),则补充单数字日期为双位数
+        String[] parts = dateString.split("/");
+        if (parts.length == 3) {
+            String year = parts[0];
+            String month = parts[1].length() == 1 ? "0" + parts[1] : parts[1];
+            String day = parts[2].length() == 1 ? "0" + parts[2] : parts[2];
+            return year + "/" + month + "/" + day;
+        }
+        return dateString;  // 如果不符合该格式则直接返回原字符串
+    }
+
+
+
     //工作台
     //根据入库的登记情况统计本年标本入库信息
     @Override

+ 2 - 2
yudao-server/src/main/resources/application.yaml

@@ -13,8 +13,8 @@ spring:
   servlet:
     # 文件上传相关配置项
     multipart:
-      max-file-size: 500MB # 单个文件大小
-      max-request-size: 500MB # 设置总上传的文件大小
+      max-file-size: 50000MB # 单个文件大小
+      max-request-size: 50000MB # 设置总上传的文件大小
 
   # Jackson 配置项
   jackson: