Browse Source

受压元件导入

徐展城 6 days ago
parent
commit
3e8c876fc0

+ 24 - 2
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/controller/admin/equipboiler/EquipBoilerController.java

@@ -1,6 +1,7 @@
 package cn.start.tz.module.pressure2.controller.admin.equipboiler;
 
 import lombok.extern.slf4j.Slf4j;
+import com.alibaba.excel.EasyExcel;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.bind.annotation.*;
 import jakarta.annotation.Resource;
@@ -117,8 +118,29 @@ public class EquipBoilerController {
     @Operation(summary = "导入锅炉受压元件 Excel")
     @ApiAccessLog(operateType = IMPORT)
     public CommonResult<List<EquipBoilerPressurePartExportVO>> importPressureParts(@RequestParam("file") MultipartFile file) throws IOException {
-        List<EquipBoilerPressurePartExportVO> list = ExcelUtils.read(file, EquipBoilerPressurePartExportVO.class);
-        return success(list);
+        log.info("importPressureParts file: name={}, size={}", file.getOriginalFilename(), file.getSize());
+        // 先用 raw map 读取看看原始单元格内容
+        List<Map<Integer, String>> rawList = EasyExcel.read(file.getInputStream())
+                .sheet(0).headRowNumber(0).doReadSync();
+        log.info("importPressureParts raw parsed {} rows", rawList != null ? rawList.size() : 0);
+        if (rawList != null && !rawList.isEmpty()) {
+            // 映射 raw 到 export
+            List<EquipBoilerPressurePartExportVO> exportList = new ArrayList<>();
+            for (Map<Integer, String> map : rawList) {
+                EquipBoilerPressurePartExportVO vo = new EquipBoilerPressurePartExportVO();
+                vo.setPartType(map.getOrDefault(0, ""));
+                vo.setPartName(map.getOrDefault(1, ""));
+                vo.setSpecification(map.getOrDefault(2, ""));
+                vo.setMaterial(map.getOrDefault(3, ""));
+                vo.setRemark(map.getOrDefault(4, ""));
+                exportList.add(vo);
+                log.info("importPressureParts raw->export: partType={}, partName={}, specification={}, material={}, remark={}",
+                        vo.getPartType(), vo.getPartName(), vo.getSpecification(), vo.getMaterial(), vo.getRemark());
+            }
+            log.info("importPressureParts exportList: {}", exportList.size());
+            return success(exportList);
+        }
+        return success(Collections.emptyList());
     }
 
     @GetMapping("/pressure-parts/get-import-template")

+ 29 - 0
tz-module-pressure2/tz-module-pressure2-biz/src/main/java/cn/start/tz/module/pressure2/controller/admin/equipboiler/vo/EquipBoilerPressurePartImportVO.java

@@ -0,0 +1,29 @@
+package cn.start.tz.module.pressure2.controller.admin.equipboiler.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * 锅炉受压元件 Excel 导入专用 VO(纯 index 映射,不走表头名称匹配)
+ */
+@Schema(description = "管理后台 - 锅炉受压元件 Excel 导入 VO")
+@Data
+public class EquipBoilerPressurePartImportVO {
+
+    @ExcelProperty(index = 0)
+    private String partType;
+
+    @ExcelProperty(index = 1)
+    private String partName;
+
+    @ExcelProperty(index = 2)
+    private String specification;
+
+    @ExcelProperty(index = 3)
+    private String material;
+
+    @ExcelProperty(index = 4)
+    private String remark;
+
+}