From ad853219d4a8c85eaf8c51e66e6efc49df5433bc Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期三, 09 七月 2025 18:51:22 +0800
Subject: [PATCH] art: 技术状态鉴定规范3个导入-接口修改

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java |  279 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 267 insertions(+), 12 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java
index 4c8d7b6..8bb7a21 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java
@@ -28,7 +28,6 @@
 import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandardDetail;
 import org.jeecg.modules.eam.mapper.EamTechnicalStatusEvaluationStandardMapper;
 import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationStandardRequest;
-import org.jeecg.modules.eam.request.ImportException;
 import org.jeecg.modules.eam.service.IEamEquipmentService;
 import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardDetailService;
 import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardService;
@@ -342,7 +341,7 @@
                         builder.append(paragraph.getText().trim());
                     }
                 });
-                if (!checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK)) {
+                if (checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK)) {
                     return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒");
                 }
                 //鑾峰彇璁惧淇℃伅
@@ -350,7 +349,7 @@
                 //鏌ョ湅鏄惁鏈夋璁惧鍚敤鐨勮鑼冧俊鎭�
                 EamTechnicalStatusEvaluationStandard originalStandard = checkDuplicate(equipment.getId(), null);
                 if (originalStandard != null && TechnicalStatusEvaluationStandardEnum.ENABLE.name().equals(originalStandard.getStandardStatus())) {
-                    return Result.error(fileName + ":姝よ澶囩殑瀹夊叏瑁呯疆妫�鏌ラ」宸叉坊鍔狅紝璇疯繘琛岀紪杈戞垨鍗囩増锛�");
+                    return Result.error(fileName + ":姝よ澶囧凡瀛樺湪鍚敤鐨勮鑼冿紝璇疯繘琛岀紪杈戞垨鍗囩増锛�");
                 }
                 //鑾峰彇妫�鏌ラ」淇℃伅
                 List<EamTechnicalStatusEvaluationStandardDetail> detailList = extractSafetyEquipmentCheckItems(tables);
@@ -365,6 +364,9 @@
                     detailList.forEach(standardDetail -> {
                         standardDetail.setStandardId(originalStandard.getId());
                     });
+                    //鍏堝垹闄わ紝鍚庢坊鍔�
+                    standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name());
+                    //閲嶆柊娣诲姞
                     standardDetailService.saveBatch(detailList);
                 }else {
                     String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_STANDARD_CODE_RULE);
@@ -379,12 +381,9 @@
                     request.setTableDetailList(detailList);
                     this.addEamTechnicalStatusEvaluationStandard(request);
                 }
-            } catch (ImportException e) {
-                log.error(e.getMessage(), e);
-                return Result.error(fileName + ":" + e.getMessage() + "锛�");
             } catch (Exception e) {
                 log.error(e.getMessage(), e);
-                return Result.error(fileName + ":绯荤粺閿欒-" + e.getMessage() + "锛�");
+                return Result.error(fileName + ":" + e.getMessage() + "锛�");
             }
         } else {
             return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�");
@@ -393,16 +392,170 @@
         return Result.OK(fileName + ":瀵煎叆鎴愬姛锛�");
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> importPrecisionCheck(MultipartFile file) {
+        String fileName = file.getOriginalFilename();
+        if (StringUtils.isBlank(fileName)) {
+            return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�");
+        }
+        String fileSuffix = FileUtil.getFileSuffix(fileName);
+        //鍙敮鎸� .docx 鐨剋ord鏂囨。
+        if ("docx".equals(fileSuffix)) {
+            try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) {
+                List<XWPFParagraph> paragraphs = doc.getParagraphs();
+                List<XWPFTable> tables = doc.getTables();
+                if (CollectionUtil.isEmpty(paragraphs) || CollectionUtil.isEmpty(tables)) {
+                    return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎璁惧绮惧害妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒");
+                }
+                //鑾峰彇鏂囦欢鏍囬
+                StringBuilder builder = new StringBuilder();
+                paragraphs.forEach(paragraph -> {
+                    if (StringUtils.isNotBlank(paragraph.getText())) {
+                        builder.append(paragraph.getText().trim());
+                    }
+                });
+                if (checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK)) {
+                    return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎璁惧绮惧害妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒");
+                }
+                //鑾峰彇璁惧淇℃伅
+                EamEquipment equipment = extractEquipmentInfo(tables.get(0));
+                //鏌ョ湅鏄惁鏈夋璁惧鍚敤鐨勮鑼冧俊鎭�
+                EamTechnicalStatusEvaluationStandard originalStandard = checkDuplicate(equipment.getId(), null);
+                if (originalStandard != null && TechnicalStatusEvaluationStandardEnum.ENABLE.name().equals(originalStandard.getStandardStatus())) {
+                    return Result.error(fileName + ":姝よ澶囧凡瀛樺湪鍚敤鐨勮鑼冿紝璇疯繘琛岀紪杈戞垨鍗囩増锛�");
+                }
+                //鑾峰彇妫�鏌ラ」淇℃伅
+                List<EamTechnicalStatusEvaluationStandardDetail> detailList = extractPrecisionCheckItems(tables);
+                if(CollectionUtil.isEmpty(detailList)){
+                    return Result.error(fileName + ":鏈В鏋愬埌妫�鏌ラ」鍐呭锛岃妫�鏌ワ紒");
+                }
+                if(originalStandard != null) {
+                    //宸插瓨鍦ㄦ妧鏈姸鎬侀壌瀹氳鑼�,涓旇鑼冪姸鎬佷负宸叉彁浜�
+                    originalStandard.setHasPrecisionCheck(CommonConstant.STATUS_1);
+                    originalStandard.setStandardStatus(TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name());
+                    super.getBaseMapper().updateById(originalStandard);
+                    detailList.forEach(standardDetail -> {
+                        standardDetail.setStandardId(originalStandard.getId());
+                    });
+                    //鍏堝垹闄わ紝鍚庢坊鍔�
+                    standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name());
+                    //閲嶆柊娣诲姞
+                    standardDetailService.saveBatch(detailList);
+                }else {
+                    String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_STANDARD_CODE_RULE);
+                    //鏂板鎶�鏈姸鎬侀壌瀹氳鑼�
+                    EamTechnicalStatusEvaluationStandardRequest request = new EamTechnicalStatusEvaluationStandardRequest();
+                    request.setEquipmentId(equipment.getId());
+                    request.setHasSafetyEquipmentCheck(CommonConstant.STATUS_0);
+                    request.setHasOtherCheck(CommonConstant.STATUS_0);
+                    request.setHasPrecisionCheck(CommonConstant.STATUS_1);
+                    request.setStandardCode(codeSeq);
+                    request.setStandardName(equipment.getEquipmentName() + "鎶�鏈姸鎬侀壌瀹氳鑼�");
+                    request.setTableDetailList(detailList);
+                    this.addEamTechnicalStatusEvaluationStandard(request);
+                }
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error(fileName + ":" + e.getMessage() + "锛�");
+            }
+        } else {
+            return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�");
+        }
+
+        return Result.OK(fileName + ":瀵煎叆鎴愬姛锛�");
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> importOtherCheck(MultipartFile file) {
+        String fileName = file.getOriginalFilename();
+        if (StringUtils.isBlank(fileName)) {
+            return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�");
+        }
+        String fileSuffix = FileUtil.getFileSuffix(fileName);
+        //鍙敮鎸� .docx 鐨剋ord鏂囨。
+        if ("docx".equals(fileSuffix)) {
+            try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) {
+                List<XWPFParagraph> paragraphs = doc.getParagraphs();
+                List<XWPFTable> tables = doc.getTables();
+                if (CollectionUtil.isEmpty(paragraphs) || CollectionUtil.isEmpty(tables)) {
+                    return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒");
+                }
+                //鑾峰彇鏂囦欢鏍囬
+                StringBuilder builder = new StringBuilder();
+                paragraphs.forEach(paragraph -> {
+                    if (StringUtils.isNotBlank(paragraph.getText())) {
+                        builder.append(paragraph.getText().trim());
+                    }
+                });
+                if (checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK)) {
+                    return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎鍏朵粬妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒");
+                }
+                //鑾峰彇璁惧淇℃伅
+                EamEquipment equipment = extractEquipmentInfo(tables.get(0));
+                //鏌ョ湅鏄惁鏈夋璁惧鍚敤鐨勮鑼冧俊鎭�
+                EamTechnicalStatusEvaluationStandard originalStandard = checkDuplicate(equipment.getId(), null);
+                if (originalStandard != null && TechnicalStatusEvaluationStandardEnum.ENABLE.name().equals(originalStandard.getStandardStatus())) {
+                    return Result.error(fileName + ":姝よ澶囧凡瀛樺湪鍚敤鐨勮鑼冿紝璇疯繘琛岀紪杈戞垨鍗囩増锛�");
+                }
+                //鑾峰彇妫�鏌ラ」淇℃伅
+                List<EamTechnicalStatusEvaluationStandardDetail> detailList = extractOtherCheckItems(tables);
+                if(CollectionUtil.isEmpty(detailList)){
+                    return Result.error(fileName + ":鏈В鏋愬埌妫�鏌ラ」鍐呭锛岃妫�鏌ワ紒");
+                }
+                if(originalStandard != null) {
+                    //宸插瓨鍦ㄦ妧鏈姸鎬侀壌瀹氳鑼�,涓旇鑼冪姸鎬佷负宸叉彁浜�
+                    originalStandard.setHasOtherCheck(CommonConstant.STATUS_1);
+                    originalStandard.setStandardStatus(TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name());
+                    super.getBaseMapper().updateById(originalStandard);
+                    detailList.forEach(standardDetail -> {
+                        standardDetail.setStandardId(originalStandard.getId());
+                    });
+                    //鍏堝垹闄わ紝鍚庢坊鍔�
+                    standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name());
+                    //閲嶆柊娣诲姞
+                    standardDetailService.saveBatch(detailList);
+                }else {
+                    String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_STANDARD_CODE_RULE);
+                    //鏂板鎶�鏈姸鎬侀壌瀹氳鑼�
+                    EamTechnicalStatusEvaluationStandardRequest request = new EamTechnicalStatusEvaluationStandardRequest();
+                    request.setEquipmentId(equipment.getId());
+                    request.setHasSafetyEquipmentCheck(CommonConstant.STATUS_0);
+                    request.setHasOtherCheck(CommonConstant.STATUS_1);
+                    request.setHasPrecisionCheck(CommonConstant.STATUS_0);
+                    request.setStandardCode(codeSeq);
+                    request.setStandardName(equipment.getEquipmentName() + "鎶�鏈姸鎬侀壌瀹氳鑼�");
+                    request.setTableDetailList(detailList);
+                    this.addEamTechnicalStatusEvaluationStandard(request);
+                }
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error(fileName + ":" + e.getMessage() + "锛�");
+            }
+        } else {
+            return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�");
+        }
+
+        return Result.OK(fileName + ":瀵煎叆鎴愬姛锛�");
+    }
+
+    /**
+     * 妫�鏌ュ鍏ユ枃浠跺垎绫绘槸鍚﹀尮閰�
+     * @param title 鏍囬娈佃惤瀛楃涓�
+     * @param category 鍒嗙被
+     * @return true 涓嶅尮閰嶏紝 false  鍖归厤
+     */
     private boolean checkImportCategory(String title, TechnicalStatusEvaluationCheckCategoryEnum category) {
         switch (category) {
             case SAFETY_EQUIPMENT_CHECK:
-                return title.contains("瀹夊叏瑁呯疆妫�鏌�");
+                return !title.contains("瀹夊叏瑁呯疆妫�鏌�");
             case PRECISION_CHECK:
-                return title.contains("绮惧害妫�鏌ュ崟");
+                return !title.contains("绮惧害妫�鏌ュ崟");
             case OTHER_CHECK:
-                return title.contains("鍏朵粬妫�鏌�");
+                return !title.contains("鍏朵粬妫�鏌�");
         }
-        return false;
+        return true;
     }
 
 
@@ -448,7 +601,6 @@
      * 鎻愬彇瀹夊叏瑁呯疆妫�鏌ユ槑缁�
      */
     private List<EamTechnicalStatusEvaluationStandardDetail> extractSafetyEquipmentCheckItems(List<XWPFTable> tableList) {
-
         List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>();
         EamTechnicalStatusEvaluationStandardDetail item = null;
         //瑙f瀽绗竴涓〃鏍硷紝甯﹁澶囦俊鎭�
@@ -481,4 +633,107 @@
         }
         return items;
     }
+
+    /**
+     * 鎻愬彇鍏朵粬妫�鏌ラ」鏄庣粏鍐呭
+     * @param tables
+     * @return
+     */
+    private List<EamTechnicalStatusEvaluationStandardDetail> extractOtherCheckItems(List<XWPFTable> tables) {
+        List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>();
+        EamTechnicalStatusEvaluationStandardDetail item = null;
+        //瑙f瀽绗竴涓〃鏍硷紝甯﹁澶囦俊鎭�
+        XWPFTable table = tables.get(0);
+        for (int i = 0; i < table.getNumberOfRows(); i++) {
+            XWPFTableRow row = table.getRow(i);
+            if (row == null || CollectionUtil.isEmpty(row.getTableCells()) || row.getTableCells().size() < 2) {
+                //璇诲彇鍒扮┖row鍊�
+                continue;
+            }
+            //妫�鏌ユ槸鍚﹀埌妫�鏌ラ」搴忓彿
+            String firstCell = row.getCell(0).getText().trim();
+            Integer itemCode = null;
+            try {
+                itemCode = Integer.parseInt(firstCell);
+            } catch (NumberFormatException e) {
+                //涓嶆槸妫�鏌ラ」鍐呭锛岃烦杩囨琛�
+                continue;
+            }
+            //鑾峰彇绗簩涓崟鍏冩牸
+            String secondCell = row.getCell(1).getText().trim();
+            //濡傛灉杩欎竴琛屼负搴忓彿鍒欒В鏋愭暣琛�
+            if (StringUtils.isNotBlank(secondCell)) {
+                item = new EamTechnicalStatusEvaluationStandardDetail();
+                item.setItemCode(itemCode);
+                item.setItemName(secondCell);
+                item.setCheckCategory(TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name());
+                items.add(item);
+            }
+        }
+        return items;
+    }
+
+    private List<EamTechnicalStatusEvaluationStandardDetail> extractPrecisionCheckItems(List<XWPFTable> tables) {
+        List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>();
+        EamTechnicalStatusEvaluationStandardDetail item = null;
+        //瑙f瀽绗竴涓〃鏍硷紝甯﹁澶囦俊鎭�
+        XWPFTable table = tables.get(0);
+        for (int i = 0; i < table.getNumberOfRows(); i++) {
+            XWPFTableRow row = table.getRow(i);
+            if (row == null || CollectionUtil.isEmpty(row.getTableCells()) || row.getTableCells().size() < 2) {
+                //璇诲彇鍒扮┖row鍊�
+                continue;
+            }
+            //妫�鏌ユ槸鍚﹀埌妫�鏌ラ」搴忓彿
+            String firstCell = row.getCell(0).getText().trim();
+            Integer itemCode = null;
+            try {
+                itemCode = Integer.parseInt(firstCell);
+            } catch (NumberFormatException e) {
+                //涓嶆槸妫�鏌ラ」鍐呭锛岃烦杩囨琛�
+                if(item == null) {
+                    continue;
+                }else {
+                    itemCode = item.getItemCode();
+                }
+            }
+            //鑾峰彇绗簩涓崟鍏冩牸
+            String itemName = row.getCell(1).getText().trim();
+            if(StringUtils.isBlank(itemName)) {
+                if(item != null) {
+                    itemName = item.getItemName();
+                }else {
+                    continue;
+                }
+            }
+            String subItemName = null;
+            String toleranceValue = null;
+            if(row.getTableCells().size() == 4) {
+                toleranceValue = row.getCell(2).getText().trim();
+            }else if(row.getTableCells().size() == 5) {
+                subItemName = row.getCell(2).getText().trim();
+                toleranceValue = row.getCell(3).getText().trim();
+            }else {
+                continue;
+            }
+            if(StringUtils.isBlank(toleranceValue)) {
+               //鍏佸樊鍊间笉瀛樺湪锛岃烦杩�
+               if(item != null) {
+                   toleranceValue = item.getToleranceValue();
+               }else {
+                   continue;
+               }
+            }
+            //鎷艰鏄庣粏鏁版嵁
+            item = new EamTechnicalStatusEvaluationStandardDetail();
+            item.setItemCode(itemCode);
+            item.setItemName(itemName);
+            item.setSubItemName(subItemName);
+            item.setToleranceValue(toleranceValue);
+            item.setCheckCategory(TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name());
+            items.add(item);
+        }
+        return items;
+    }
+
 }

--
Gitblit v1.9.3