From 4e24c63554a7a234c7b79fdcd8991b8024ef7a5f Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期四, 04 九月 2025 10:48:02 +0800
Subject: [PATCH] 保养规范修改导入与返回值

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java    |  118 ++++++++++++++++++++++++++++++++------
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java |   55 +++++++++++++----
 2 files changed, 139 insertions(+), 34 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java
index 001f12d..745df06 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java
@@ -323,17 +323,49 @@
             // 缁熻瀵煎叆缁撴灉
             int successCount = 0;
             int failureCount = 0;
+            Result<?> importResult = new Result<>();
+
+            // 鐢ㄤ簬鏀堕泦鎵�鏈夋湭鎵惧埌鐨勮澶囩紪鐮�
+            List<String> allNotFoundCodes = new ArrayList<>();
 
             for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                 MultipartFile file = entity.getValue();
                 String fileName = file.getOriginalFilename();
-                Result<?> importResult=eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND",null);
+                importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND", null);
+
                 if (importResult.isSuccess()) {
+                    // 妫�鏌ユ槸鍚﹀寘鍚儴鍒嗘垚鍔熶俊鎭�
+                    String message = importResult.getMessage();
+                    if (message.contains("浠ヤ笅璁惧缂栫爜鏈壘鍒帮細")) {
+                        // 鎻愬彇鏈壘鍒扮殑璁惧缂栫爜
+                        String notFoundPart = message.substring(message.indexOf("浠ヤ笅璁惧缂栫爜鏈壘鍒帮細") + 9);
+                        allNotFoundCodes.addAll(Arrays.asList(notFoundPart.split(", ")));
+
+                        // 淇敼涓洪儴鍒嗘垚鍔熸秷鎭�
+                        importResult.setMessage(message.substring(0, message.indexOf("锛涗絾")));
+                    }
                     successCount++;
                 } else {
                     results.put(fileName, importResult.getMessage());
                     failureCount++;
                 }
+            }
+
+            // 濡傛灉鏈夋湭鎵惧埌鐨勮澶囩紪鐮侊紝娣诲姞鍒版渶缁堢粨鏋�
+            if (!allNotFoundCodes.isEmpty()) {
+                String notFoundMsg = "浠ヤ笅璁惧缂栫爜鏈壘鍒帮細" + String.join(", ", allNotFoundCodes);
+                if (successCount > 0) {
+                    // 閮ㄥ垎鎴愬姛
+                    return Result.ok("閮ㄥ垎瀵煎叆鎴愬姛锛屾垚鍔熸枃浠舵暟锛�" + successCount +
+                            "锛屽け璐ユ枃浠舵暟锛�" + failureCount + "锛�" + notFoundMsg);
+                } else {
+                    // 鍏ㄩ儴澶辫触
+                    return Result.error("瀵煎叆澶辫触锛�" + notFoundMsg);
+                }
+            }
+
+            if (successCount == 1) {
+                return importResult;
             }
 
             // 鏋勫缓鏈�缁堝搷搴�
@@ -358,17 +390,50 @@
             // 缁熻瀵煎叆缁撴灉
             int successCount = 0;
             int failureCount = 0;
+            Result<?> importResult = new Result<>();
+
+            // 鐢ㄤ簬鏀堕泦鎵�鏈夋湭鎵惧埌鐨勮澶囩紪鐮�
+            List<String> allNotFoundCodes = new ArrayList<>();
 
             for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                 MultipartFile file = entity.getValue();
                 String fileName = file.getOriginalFilename();
-                Result<?> importResult= eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD",null);
+                // 淇锛氫笁淇濆鍏ュ簲璇ヤ娇鐢�"THIRD"绫诲瀷
+                importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD", null);
+
                 if (importResult.isSuccess()) {
+                    // 妫�鏌ユ槸鍚﹀寘鍚儴鍒嗘垚鍔熶俊鎭�
+                    String message = importResult.getMessage();
+                    if (message.contains("浠ヤ笅璁惧缂栫爜鏈壘鍒帮細")) {
+                        // 鎻愬彇鏈壘鍒扮殑璁惧缂栫爜
+                        String notFoundPart = message.substring(message.indexOf("浠ヤ笅璁惧缂栫爜鏈壘鍒帮細") + 9);
+                        allNotFoundCodes.addAll(Arrays.asList(notFoundPart.split(", ")));
+
+                        // 淇敼涓洪儴鍒嗘垚鍔熸秷鎭�
+                        importResult.setMessage(message.substring(0, message.indexOf("锛涗絾")));
+                    }
                     successCount++;
                 } else {
                     results.put(fileName, importResult.getMessage());
                     failureCount++;
                 }
+            }
+
+            // 濡傛灉鏈夋湭鎵惧埌鐨勮澶囩紪鐮侊紝娣诲姞鍒版渶缁堢粨鏋�
+            if (!allNotFoundCodes.isEmpty()) {
+                String notFoundMsg = "浠ヤ笅璁惧缂栫爜鏈壘鍒帮細" + String.join(", ", allNotFoundCodes);
+                if (successCount > 0) {
+                    // 閮ㄥ垎鎴愬姛
+                    return Result.ok("閮ㄥ垎瀵煎叆鎴愬姛锛屾垚鍔熸枃浠舵暟锛�" + successCount +
+                            "锛屽け璐ユ枃浠舵暟锛�" + failureCount + "锛�" + notFoundMsg);
+                } else {
+                    // 鍏ㄩ儴澶辫触
+                    return Result.error("瀵煎叆澶辫触锛�" + notFoundMsg);
+                }
+            }
+
+            if (successCount == 1) {
+                return importResult;
             }
 
             // 鏋勫缓鏈�缁堝搷搴�
@@ -382,31 +447,44 @@
 
     /**
      * 鍗囩増瀵煎叆
-     * @param id,file
-     * @return
      */
-    @ApiOperation(value = "鍗囩増瀵煎叆", notes = "鍗囩増瀵煎叆")
     @PostMapping(value = "/importUpgrade")
-    public Result<?> importUpgrade(String id,MultipartFile file) {
-        EamMaintenanceStandard eamMaintenanceStandard=eamMaintenanceStandardService.getById(id);
-        if (eamMaintenanceStandard==null) {
+    public Result<?> importUpgrade(String id, MultipartFile file) {
+        EamMaintenanceStandard eamMaintenanceStandard = eamMaintenanceStandardService.getById(id);
+        if (eamMaintenanceStandard == null) {
             return Result.error("璇烽�夋嫨闇�瑕佸崌鐗堢殑淇濆吇鏍囧噯");
-        }else {
-            switch (eamMaintenanceStandard.getMaintenanceCategory()){
+        } else {
+            Result<?> importResult;
+            switch (eamMaintenanceStandard.getMaintenanceCategory()) {
                 case "POINT_INSPECTION":
-                    //鐐规鍗囩増瀵煎叆
-                    return eamMaintenanceStandardService.importPointInspectionExcel(file,id);
-                case "SECOND_MAINTENANCE":
-                    //浜屼繚鍗囩増瀵煎叆
-                    return eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND",id);
-                case "THIRD_MAINTENANCE":
-                    //涓変繚鍗囩増瀵煎叆
-                    return eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD",id);
-                default:
+                    // 鐐规鍗囩増瀵煎叆
+                    importResult = eamMaintenanceStandardService.importPointInspectionExcel(file, id);
                     break;
+                case "SECOND_MAINTENANCE":
+                    // 浜屼繚鍗囩増瀵煎叆
+                    importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND", id);
+                    break;
+                case "THIRD_MAINTENANCE":
+                    // 涓変繚鍗囩増瀵煎叆
+                    importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD", id);
+                    break;
+                default:
+                    return Result.error("涓嶆敮鎸佺殑淇濆吇绫诲瀷");
+            }
+
+            // 澶勭悊鍗囩増瀵煎叆涓殑璁惧鏈壘鍒版儏鍐�
+            if (importResult.isSuccess()) {
+                String message = importResult.getMessage();
+                if (message.contains("浠ヤ笅璁惧缂栫爜鏈壘鍒帮細")) {
+                    // 鎻愬彇鏈壘鍒扮殑璁惧缂栫爜
+                    String notFoundPart = message.substring(message.indexOf("浠ヤ笅璁惧缂栫爜鏈壘鍒帮細") + 9);
+                    return Result.error("鍗囩増瀵煎叆澶辫触锛�" + notFoundPart);
+                }
+                return importResult;
+            } else {
+                return importResult;
             }
         }
-        return Result.error("鍗囩増瀵煎叆澶辫触");
     }
 
     private Result<?> getResult(Map<String, String> results, int fileCount, int successCount, int failureCount) {
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java
index f7a0afa..a3171aa 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java
@@ -1213,11 +1213,7 @@
 
         // 妫�鏌ラ」鐩悕绉板垪
         Cell nameCell = row.getCell(1);
-        if (nameCell != null && nameCell.getCellType() != CellType.BLANK) {
-            return false;
-        }
-
-        return true;
+        return nameCell == null || nameCell.getCellType() == CellType.BLANK;
     }
 
     /**
@@ -1324,7 +1320,7 @@
             EamMaintenanceStandard oldStandardForRevision = null;
             Map<String, Integer> deviceVersionMap = new HashMap<>();
             Map<String, Integer> compositeVersionMap = new HashMap<>();
-
+            List<String> notFoundEquipmentCodes = new ArrayList<>();
             // 鑾峰彇鏂囨。涓殑鎵�鏈夋钀�
             List<XWPFParagraph> paragraphs = doc.getParagraphs();
 
@@ -1358,6 +1354,21 @@
                     EamMaintenanceStandard standard = extractDeviceInfo(table, type);
                     if (standard == null) {
                         throw new ImportException("琛ㄦ牸" + (i+1) + "锛氳澶囦俊鎭彁鍙栧け璐�");
+                    }
+
+                    if (StrUtil.isEmpty(standard.getEquipmentId())) {
+                        // 璁板綍鏈壘鍒扮殑璁惧缂栫爜
+                        if (StrUtil.isNotEmpty(standard.getEquipmentCode())) {
+                            notFoundEquipmentCodes.add(standard.getEquipmentCode());
+                        } else {
+                            notFoundEquipmentCodes.add("鏈煡缂栫爜锛堣〃鏍�" + (i+1) + "锛�");
+                        }
+
+                        // 璺宠繃褰撳墠璁惧锛岀户缁鐞嗕笅涓�涓�
+                        do {
+                            i++;
+                        } while (i < tables.size() && !isDeviceInfoTable(tables.get(i)));
+                        continue;
                     }
 
                     // 浠庢枃妗d腑鑾峰彇鏍囬锛堣〃鏍煎墠鐨勬钀斤級
@@ -1409,6 +1420,11 @@
 
             // 鏍¢獙璁惧鏁伴噺
             if (standards.isEmpty()) {
+                // 濡傛灉鎵�鏈夎澶囬兘鏈壘鍒帮紝杩斿洖鐗瑰畾閿欒
+                if (!notFoundEquipmentCodes.isEmpty()) {
+                    return Result.error(fileName + "锛氭墍鏈夎澶囩紪鐮佸潎鏈壘鍒帮細" +
+                            String.join(", ", notFoundEquipmentCodes));
+                }
                 return Result.error(fileName + "锛氭湭鎵惧埌鏈夋晥鐨勮澶囦俊鎭〃鏍�");
             }
 
@@ -1431,7 +1447,15 @@
             // 浣滃簾鏃х増鏈紙淇濈暀鏈�鏂扮増鏈級
             obsoleteOldVersionsByCompositeKey(deviceVersionMap);
 
+            if (!notFoundEquipmentCodes.isEmpty()) {
+                String successMsg = fileName + "閮ㄥ垎瀵煎叆鎴愬姛锛岃澶囨暟锛�" + standards.size() +
+                        "锛岄」鐩暟锛�" + allItems.size();
+                String errorMsg = "浠ヤ笅璁惧缂栫爜鏈壘鍒帮細" + String.join(", ", notFoundEquipmentCodes);
+                return Result.ok(successMsg + "锛涗絾" + errorMsg);
+            }
+
             return Result.ok(fileName + "瀵煎叆鎴愬姛锛岃澶囨暟锛�" + standards.size() + "锛岄」鐩暟锛�" + allItems.size());
+
 
         } catch (ImportException e) {
             return Result.error(fileName + "锛�" + e.getMessage());
@@ -1471,13 +1495,10 @@
 
 
     /**
-     * 浠庤〃鏍煎墠鐨勬钀戒腑鎻愬彇鏍囬锛堜慨澶嶇増锛�
+     * 浠庤〃鏍煎墠鐨勬钀戒腑鎻愬彇鏍囬
      */
     private String extractTitleBeforeTable(XWPFTable table, List<XWPFParagraph> paragraphs) {
         try {
-            // 鑾峰彇琛ㄦ牸鐨凜TTbl瀵硅薄
-            CTTbl ctTbl = table.getCTTbl();
-
             // 鑾峰彇琛ㄦ牸鎵�鍦ㄧ殑body
             IBody body = table.getBody();
 
@@ -1513,7 +1534,7 @@
                 XWPFTableRow firstRow = table.getRow(0);
                 for (XWPFTableCell cell : firstRow.getTableCells()) {
                     String text = getCellText(cell);
-                    if (text != null && text.contains("淇濆吇瑙勮寖")) {
+                    if (text.contains("淇濆吇瑙勮寖")) {
                         return text.trim();
                     }
                 }
@@ -1864,15 +1885,21 @@
         standard.setEquipmentName(row2Data.get("璁惧鍚嶇О"));
         standard.setEquipmentModel(row2Data.get("璁惧鍨嬪彿"));
 
-        // 鍏宠仈璁惧ID
+        // 鍏宠仈璁惧ID - 淇敼鐐癸細璁惧鏈壘鍒版椂涓嶆姏鍑哄紓甯�
         if (StrUtil.isNotEmpty(standard.getEquipmentCode())) {
             EamEquipment equipment = eamEquipmentService.selectByEquipmentCode(standard.getEquipmentCode());
             if (equipment == null) {
-                log.warn("璁惧缂栫爜鏈壘鍒�: {}", standard.getEquipmentCode());
-                return null;
+                // 璁板綍鏈壘鍒拌澶囩紪鐮佺殑鏃ュ織
+                log.error("璁惧缂栫爜鏈壘鍒�: {}", standard.getEquipmentCode());
+                // 杩斿洖瀵硅薄浣嗚澶嘔D涓虹┖锛岃〃绀鸿澶囨湭鎵惧埌
+                return standard;
             } else {
                 standard.setEquipmentId(equipment.getId());
             }
+        } else {
+            // 澶勭悊璁惧缂栫爜涓虹┖鐨勬儏鍐�
+            log.error("璁惧缂栫爜涓虹┖");
+            return standard;
         }
 
         return standard;

--
Gitblit v1.9.3