From d76b518341ec0644c3500555d5c4121bc30d581e Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期四, 31 七月 2025 09:24:09 +0800
Subject: [PATCH] 台账导入导出字段修改

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java         |    4 
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java              |   97 +++++++++++++++++++++++-
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java                     |   14 ++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java    |   35 ++++++++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java |   68 ++++++++++++++--
 5 files changed, 194 insertions(+), 24 deletions(-)

diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java
index 7462ff2..e35853c 100644
--- a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java
@@ -257,7 +257,15 @@
     /**
      * 鍑哄巶鏃ユ湡
      */
-    @Excel(name = "鍑哄巶鏃ユ湡", width = 25, format = "yyyy/MM/dd", orderNum = "26")
+    @Excel(name = "鍑哄巶鏃ユ湡", width = 25,  orderNum = "26")
+    @ApiModelProperty(value = "鍑哄巶鏃ユ湡")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    private transient String leaveFactory;
+
+    /**
+     * 鍑哄巶鏃ユ湡
+     */
     @ApiModelProperty(value = "鍑哄巶鏃ユ湡")
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
     @DateTimeFormat(pattern = "yyyy-MM-dd")
@@ -389,7 +397,7 @@
 
     /**涓嬫涓変繚鏃ユ湡*/
     @TableField(exist = false)
-    @Excel(name = "涓嬫涓変繚鏃ユ湡", width = 15, format = "yyyy/MM/dd", orderNum = "43")
+    @Excel(name = "涓変繚鏃ユ湡", width = 15, format = "yyyy/MM/dd", orderNum = "43")
     @ApiModelProperty(value = "涓嬫涓変繚鏃ユ湡")
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
     @DateTimeFormat(pattern = "yyyy-MM-dd")
@@ -410,7 +418,7 @@
     private java.util.Date latestTechnologyCheck;
     /**鎶�鏈姸鎬佷笅娆¢壌瀹氭棩鏈�*/
     @TableField(exist = false)
-    @Excel(name = "鎶�鏈姸鎬佷笅娆¢壌瀹氭棩鏈�", width = 15, format = "yyyy/MM/dd", orderNum = "46")
+    @Excel(name = "鎶�鏈姸鎬侀壌瀹氭棩鏈�", width = 15, format = "yyyy/MM/dd", orderNum = "46")
     @ApiModelProperty(value = "鎶�鏈姸鎬佷笅娆¢壌瀹氭棩鏈�")
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
     @DateTimeFormat(pattern = "yyyy-MM-dd")
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
index c9b3516..a0a1d4e 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
@@ -41,15 +41,16 @@
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
-
+import org.apache.commons.lang3.time.DateUtils;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.text.ParseException;
+import java.util.*;
+import java.util.function.Consumer;
 import java.util.stream.Collectors;
+import java.time.LocalDate;
+import java.time.ZoneId;
 
 /**
  * @Description: 璁惧鍙拌处
@@ -308,6 +309,51 @@
                     }else {
                         eamEquipment.setRepairDepartOrgCode(eamBaseRepairDepart.getOrgCode());
                     }
+                    // 瀛楁鏍¢獙涓庡~鍏�
+                    if (StringUtils.isNotBlank(eamEquipment.getLeaveFactory())) {
+                        String leaveFactoryStr = eamEquipment.getLeaveFactory();
+                        try {
+                            // 瀹氫箟鏀寔瑙f瀽鐨勬棩鏈熸牸寮�
+                            String[] parsePatterns = {
+                                    "yyyy/MM/dd", "yyyy-MM-dd", "yyyyMMdd"
+                            };
+                            // 鏍煎紡1: 鍖呭惈鍒嗛殧绗︾殑鏃ユ湡鏍煎紡 (濡�2025/07/30, 2025-07-30绛�)
+                            if (leaveFactoryStr.contains("/") || leaveFactoryStr.contains("-") ||
+                                    (leaveFactoryStr.length() == 8 && leaveFactoryStr.matches("\\d{8}"))) {
+
+                                // 浣跨敤鎸囧畾鐨勬牸寮忔暟缁勮В鏋愭棩鏈�
+                                Date leaveFactoryDate = DateUtils.parseDate(leaveFactoryStr, parsePatterns);
+                                eamEquipment.setLeaveFactoryDate(leaveFactoryDate);
+                            } else {
+                                log.warn("绂诲紑宸ュ巶鏃ユ湡鏍煎紡鏃犳晥: {}", leaveFactoryStr);
+                            }
+                        } catch (ParseException e) {
+                            log.error("鏃ユ湡瑙f瀽澶辫触: {}", leaveFactoryStr, e);
+                        }
+                    }
+                    // 璁$畻涓変繚鏃ユ湡
+                    if (eamEquipment.getNextThirdMaintenance() != null &&
+                            eamEquipment.getThirdMaintenancePeriod() != null) {
+
+                        calculateMaintenanceDates(
+                                eamEquipment.getNextThirdMaintenance(),
+                                eamEquipment.getThirdMaintenancePeriod(),
+                                newDate -> eamEquipment.setNextThirdMaintenance(newDate),
+                                latestDate -> eamEquipment.setLatestThirdMaintenance(latestDate)
+                        );
+                    }
+
+                    // 璁$畻鎶�鏈姸鎬侀壌瀹氭棩鏈�
+                    if (eamEquipment.getNextTechnologyCheck() != null &&
+                            eamEquipment.getTechnologyCheckPeriod() != null) {
+
+                        calculateMaintenanceDates(
+                                eamEquipment.getNextTechnologyCheck(),
+                                eamEquipment.getTechnologyCheckPeriod(),
+                                newDate -> eamEquipment.setNextTechnologyCheck(newDate),
+                                latestDate -> eamEquipment.setLatestTechnologyCheck(latestDate)
+                        );
+                    }
                     EamEquipment equipment = eamEquipmentService.saveEquipment(eamEquipment);
                     if (equipment == null) {
                         //淇濆瓨澶辫触锛岃烦杩囨湰娆″惊鐜�
@@ -401,4 +447,45 @@
         }
     }
 
+    // 鏃ユ湡璁$畻宸ュ叿鏂规硶
+    private void calculateMaintenanceDates(Date nextDate, Integer periodYears,
+                                           Consumer<Date> setNextMaintenance,
+                                           Consumer<Date> setLatestMaintenance) {
+        if (nextDate == null || periodYears == null || periodYears <= 0) {
+            return;
+        }
+
+        // 杞崲涓篔ava 8鏃ユ湡绫诲瀷
+        LocalDate nextLocal = nextDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        LocalDate today = LocalDate.now();
+
+        // 纭繚鏈夋晥鐨勮绠楀懆鏈�
+        int period = Math.max(1, periodYears); // 闃叉浼犲叆0鎴栬礋鍊�
+
+        if (nextLocal.isAfter(today)) {
+            // 鏈繃鏈燂細璁$畻鏈�杩戠淮鎶ゆ棩鏈�
+            setLatestMaintenance.accept(
+                    Date.from(nextLocal.minusYears(period).atStartOfDay()
+                            .atZone(ZoneId.systemDefault()).toInstant())
+            );
+        } else {
+            // 宸茶繃鏈燂細璁$畻鏂扮殑涓嬫缁存姢鏃ユ湡
+            while (!nextLocal.isAfter(today)) {
+                nextLocal = nextLocal.plusYears(period);
+            }
+
+            // 璁剧疆鏂版棩鏈�
+            setNextMaintenance.accept(
+                    Date.from(nextLocal.atStartOfDay()
+                            .atZone(ZoneId.systemDefault()).toInstant())
+            );
+
+            // 璁$畻鏈�杩戠淮鎶ゆ棩鏈�
+            setLatestMaintenance.accept(
+                    Date.from(nextLocal.minusYears(period).atStartOfDay()
+                            .atZone(ZoneId.systemDefault()).toInstant())
+            );
+        }
+    }
+
 }
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 0d7d06e..11a2161 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
@@ -286,7 +286,7 @@
             for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                 MultipartFile file = entity.getValue();
                 String fileName = file.getOriginalFilename();
-                Result<?> importResult=eamMaintenanceStandardService.importPointInspectionExcel(file);
+                Result<?> importResult=eamMaintenanceStandardService.importPointInspectionExcel(file,null);
                 if (importResult.isSuccess()) {
                     successCount++;
                 } else {
@@ -322,7 +322,7 @@
             for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                 MultipartFile file = entity.getValue();
                 String fileName = file.getOriginalFilename();
-                Result<?> importResult=eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND");
+                Result<?> importResult=eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND",null);
                 if (importResult.isSuccess()) {
                     successCount++;
                 } else {
@@ -357,7 +357,7 @@
             for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                 MultipartFile file = entity.getValue();
                 String fileName = file.getOriginalFilename();
-                Result<?> importResult= eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD");
+                Result<?> importResult= eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD",null);
                 if (importResult.isSuccess()) {
                     successCount++;
                 } else {
@@ -375,6 +375,35 @@
         }
     }
 
+    /**
+     * 鍗囩増瀵煎叆
+     * @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) {
+            return Result.error("璇烽�夋嫨闇�瑕佸崌鐗堢殑淇濆吇鏍囧噯");
+        }else {
+            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:
+                    break;
+            }
+        }
+        return Result.error("鍗囩増瀵煎叆澶辫触");
+    }
+
     private Result<?> getResult(Map<String, String> results, int fileCount, int successCount, int failureCount) {
         List<String> response = new ArrayList<>();
         response.add("鎬绘枃浠舵暟锛�" + fileCount);
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java
index 9c0abaa..631159d 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java
@@ -87,10 +87,10 @@
     /**
      * 鐐规琛ㄥ鍏ュ叆鍙�
      */
-    Result<?> importPointInspectionExcel(MultipartFile file);
+    Result<?> importPointInspectionExcel(MultipartFile file,String id);
 
 
-    Result<?> importMaintenanceStandard(MultipartFile file, String type);
+    Result<?> importMaintenanceStandard(MultipartFile file, String type,String id);
 
     /**
      * 鏌ヨ淇濆吇绫诲瀷涓嬫甯哥殑淇濆吇鏍囧噯
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 111e961..159c091 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
@@ -562,7 +562,11 @@
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Result<?> importPointInspectionExcel(MultipartFile file) {
+    public Result<?> importPointInspectionExcel(MultipartFile file,String id) {
+        EamMaintenanceStandard eamMaintenanceStandardOld=new EamMaintenanceStandard();
+        if (StrUtil.isNotEmpty(id)){
+            eamMaintenanceStandardOld=eamMaintenanceStandardMapper.selectById(id);
+        }
         try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
             Sheet sheet = workbook.getSheetAt(0);
 
@@ -577,14 +581,32 @@
 
             eamMaintenanceStandard.setStandardName(name);
 
-            // 妫�鏌ラ噸澶�
-            EamMaintenanceStandard exist = checkDuplicate(eamMaintenanceStandard.getEquipmentId(),
-                    eamMaintenanceStandard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name());
-            if (exist != null) {
-                return Result.error(name + ": 璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞");
+            // 妫�鏌ラ噸澶�,鍙鍏ユ牎楠岋紝鍗囩増涓嶆牎楠�
+            if (StrUtil.isEmpty(id)){
+                EamMaintenanceStandard exist = checkDuplicate(eamMaintenanceStandard.getEquipmentId(),
+                        eamMaintenanceStandard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name());
+                if (exist != null) {
+                    return Result.error(name + ": 璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞");
+                }
+            }
+            if (eamMaintenanceStandardOld.getEquipmentId().equals(eamMaintenanceStandard.getEquipmentId())
+                &&eamMaintenanceStandardOld.getMaintenanceCategory().equals(eamMaintenanceStandard.getMaintenanceCategory())) {
+                //鍗囩増鎿嶄綔锛屼綔搴熷師鏈�
+                eamMaintenanceStandardOld.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name());
+                eamMaintenanceStandardMapper.updateById(eamMaintenanceStandard);
+                //鐗堟湰閫掑鑾峰彇鏁板瓧
+                Pattern pattern = Pattern.compile("(\\d+)(?:\\.\\d+)*$");
+                Matcher matcher = pattern.matcher(eamMaintenanceStandardOld.getStandardVersion());
+                if (matcher.find()) {
+                    try {
+                        int mainVersion = Integer.parseInt(matcher.group(1));
+                        eamMaintenanceStandard.setStandardVersion("v" + (mainVersion + 1));
+                    } catch (NumberFormatException ignored) {
+                    }
+                }
             }
             eamMaintenanceStandard.setInitialDate(new Date());
-            eamMaintenanceStandardMapper.insert(eamMaintenanceStandard);
+            eamMaintenanceStandardMapper.insert(eamMaintenanceStandardOld);
 
             Map<Integer, String> rowErrors = new HashMap<>();
 
@@ -1094,7 +1116,7 @@
      */
     @Override
     @Transactional
-    public Result<?> importMaintenanceStandard(MultipartFile file, String type) {
+    public Result<?> importMaintenanceStandard(MultipartFile file, String type,String id) {
         String fileName = file.getOriginalFilename();
 
         try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) {
@@ -1140,11 +1162,35 @@
                         return Result.error(fileName + ": 璁惧淇℃伅鎻愬彇澶辫触");
                     }
 
+                    EamMaintenanceStandard eamMaintenanceStandardOld=new EamMaintenanceStandard();
+                    if (StrUtil.isNotEmpty(id)){
+                        eamMaintenanceStandardOld=eamMaintenanceStandardMapper.selectById(id);
+                    }
+
                     // 閰嶇疆绫诲瀷鐩稿叧鍙傛暟
                     configureStandard(standard, type, file);
-                    EamMaintenanceStandard exist = checkDuplicate(standard.getEquipmentId(), standard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name());
-                    if (exist != null) {
-                        return Result.error(fileName + ": 璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞");
+                    if (StrUtil.isEmpty(id)){
+                        EamMaintenanceStandard exist = checkDuplicate(standard.getEquipmentId(), standard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name());
+                        if (exist != null) {
+                            return Result.error(fileName + ": 璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞");
+                        }
+                    }
+
+                    if (eamMaintenanceStandardOld.getEquipmentId().equals(standard.getEquipmentId())
+                            &&eamMaintenanceStandardOld.getMaintenanceCategory().equals(standard.getMaintenanceCategory())) {
+                        //鍗囩増鎿嶄綔锛屼綔搴熷師鏈�
+                        eamMaintenanceStandardOld.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name());
+                        eamMaintenanceStandardMapper.updateById(eamMaintenanceStandardOld);
+                        //鐗堟湰閫掑鑾峰彇鏁板瓧
+                        Pattern pattern = Pattern.compile("(\\d+)(?:\\.\\d+)*$");
+                        Matcher matcher = pattern.matcher(eamMaintenanceStandardOld.getStandardVersion());
+                        if (matcher.find()) {
+                            try {
+                                int mainVersion = Integer.parseInt(matcher.group(1));
+                                standard.setStandardVersion("v" + (mainVersion + 1));
+                            } catch (NumberFormatException ignored) {
+                            }
+                        }
                     }
                     standard.setStandardName(documentTitle);
                     eamMaintenanceStandardMapper.insert(standard);

--
Gitblit v1.9.3