From dd890a133f35b4b21ed00ec557ca83f733ff04dc Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期三, 03 九月 2025 18:03:24 +0800
Subject: [PATCH] 实现二保三保规范一个Word文档中包含多个保养内容(即多个设备)导入

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderServiceImpl.java |   49 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderServiceImpl.java
index 17fff29..10cb913 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderServiceImpl.java
@@ -9,6 +9,7 @@
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.flowable.engine.TaskService;
@@ -18,6 +19,7 @@
 import org.jeecg.common.constant.DataBaseConstant;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
 import org.jeecg.modules.eam.constant.*;
@@ -50,6 +52,10 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.temporal.TemporalAdjusters;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -61,12 +67,12 @@
  * @Version: V1.0
  */
 @Service("IEamSecondMaintenanceOrderService")
+@Slf4j
 public class EamSecondMaintenanceOrderServiceImpl extends ServiceImpl<EamSecondMaintenanceOrderMapper, EamSecondMaintenanceOrder> implements IEamSecondMaintenanceOrderService, FlowCallBackServiceI {
     @Resource
     private EamSecondMaintenanceOrderMapper eamSecondMaintenanceOrderMapper;
     @Autowired
     private IEamSecondMaintenanceOrderDetailService secondMaintenanceOrderDetailService;
-
     @Autowired
     private FlowCommonService flowCommonService;
     @Autowired
@@ -97,6 +103,8 @@
     private BaseFactoryMapper baseFactoryMapper;
     @Autowired
     private IEamSecondMaintenanceOrderDetailService eamSecondMaintenanceOrderDetailService;
+    @Autowired
+    private IEamFactorySecondMaintPlanService factorySecondMaintPlanService;
 
     @Override
     public IPage<EamSecondMaintenanceOrder> queryPageList(Page<EamSecondMaintenanceOrder> page, EamSecondMaintenanceQuery query) {
@@ -340,6 +348,11 @@
             });
             secondMaintenanceOrderDetailService.saveBatch(requestTableDetailList);
         }
+        // 鎻掑叆棣栭〉浜屼繚鍏昏鍒�
+        // 浣跨敤 SimpleDateFormat 鐩存帴鏍煎紡鍖栦负鈥測yyy骞碝M鏈堚�濇牸寮�
+//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy骞碝M鏈�");
+//        String formattedDate = sdf.format(order.getMaintenanceDate());
+//        factorySecondMaintPlanService.add(order.getEquipmentId(), formattedDate);
         return true;
     }
 
@@ -357,9 +370,14 @@
         if (!SecondMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(entity.getMaintenanceStatus())) {
             throw new JeecgBootException("鍙湁寰呬繚鍏荤姸鎬佺殑鏁版嵁鎵嶅彲缂栬緫锛�");
         }
+        // 缂栬緫棣栭〉浜屼繚鍏昏鍒�
+        // 浣跨敤 SimpleDateFormat 鐩存帴鏍煎紡鍖栦负鈥測yyy骞碝M鏈堚�濇牸寮�
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy骞碝M鏈�");
+        String oldFormattedDate = sdf.format(entity.getMaintenanceDate());
+        String newFormattedDate = sdf.format(request.getMaintenanceDate());
+        factorySecondMaintPlanService.dateChange(entity.getEquipmentId(), oldFormattedDate,newFormattedDate);
         entity.setMaintenanceDate(request.getMaintenanceDate());
         entity.setRemark(request.getRemark());
-
         eamSecondMaintenanceOrderMapper.updateById(entity);
         //鍒ゆ柇鏄惁瀛樺湪淇濆吇浜� 濡傛灉瀛樺湪鍒欏惎鍔ㄦ祦绋�
         if (StringUtils.isNotBlank(entity.getOperator())) {
@@ -389,7 +407,6 @@
                 eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_SECOND_MAINTENANCE.name());
                 return result.isSuccess();
             }
-
         }
         return true;
     }
@@ -470,7 +487,7 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.SECOND_MAINTENANCE, businessTable = "eam_second_maintenance_order")
-    public EamSecondMaintenanceOrder approval(EamSecondMaintenanceRequest request) {
+    public EamSecondMaintenanceOrder approval(EamSecondMaintenanceRequest request) throws ParseException {
         EamSecondMaintenanceOrder entity = eamSecondMaintenanceOrderMapper.selectById(request.getId());
         if (entity == null) {
             throw new JeecgBootException("瀹℃壒鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�");
@@ -665,10 +682,34 @@
         }
         //淇濆瓨宸ュ崟
         eamSecondMaintenanceOrderMapper.updateById(entity);
+        //寮傛鐢熸垚涓嬫浜屼繚宸ュ崟
+        if (SecondMaintenanceStatusEnum.COMPLETE.name().equals(entity.getMaintenanceStatus())) {
+            //濉厖璁$畻涓嬫浜屼繚鏃ユ湡
+            EamEquipmentExtend eamEquipmentExtend=eamEquipmentExtendService.getById(entity.getEquipmentId());
+            eamEquipmentExtend.setLatestSecondMaintenance(entity.getMaintenanceDate());
+            eamEquipmentExtend.setNextSecondMaintenance(calculateNextMaintenanceDate(entity.getMaintenanceDate()));
+            eamEquipmentExtendService.updateById(eamEquipmentExtend);
+        }
         return entity;
     }
 
     /**
+     * 璁$畻鍏釜鏈堝悗鐨勫綋鏈堟渶鍚庝竴澶�
+     * @param currentDate 褰撳墠宸ュ崟鏃ユ湡
+     * @return 鍏釜鏈堝悗鐨勫綋鏈堟渶鍚庝竴澶�
+     */
+    private Date calculateNextMaintenanceDate(Date currentDate) {
+        // 杞崲涓篖ocalDate澶勭悊鏃ユ湡
+        LocalDate localDate = DateUtils.dateToLocalDate(currentDate);
+        // 璁$畻鍏釜鏈堝悗鐨勬棩鏈�
+        LocalDate sixMonthsLater = localDate.plusMonths(6);
+        // 璋冩暣鍒板綋鏈堢殑鏈�鍚庝竴澶�
+        LocalDate lastDayOfMonth = sixMonthsLater.with(TemporalAdjusters.lastDayOfMonth());
+        // 杞崲鍥濪ate绫诲瀷
+        return DateUtils.localDateToDate(lastDayOfMonth);
+    }
+
+    /**
      * 鎵归噺鎵撳嵃浜屼繚宸ュ崟
      * @param ids
      * @return

--
Gitblit v1.9.3