From 6314219f1caec313fe3ffb9967e0bea7ed00e642 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期四, 17 七月 2025 20:37:28 +0800
Subject: [PATCH] 三保验收人修改

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java |  164 ++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 126 insertions(+), 38 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java
index ab94a57..e6cd5e5 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java
@@ -19,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.StrUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
 import org.jeecg.modules.eam.constant.*;
@@ -31,7 +32,6 @@
 import org.jeecg.modules.eam.mapper.EamInspectionOrderMapper;
 import org.jeecg.modules.eam.service.*;
 import org.jeecg.modules.eam.util.DateUtils;
-import org.jeecg.modules.eam.vo.InspectionVo;
 import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
 import org.jeecg.modules.flowable.apithird.business.service.impl.FlowMyBusinessServiceImpl;
 import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI;
@@ -39,19 +39,19 @@
 import org.jeecg.modules.flowable.service.IFlowDefinitionService;
 import org.jeecg.modules.flowable.service.IFlowTaskService;
 import org.jeecg.modules.system.service.ISysDictService;
+import org.jeecg.modules.system.service.ISysUserService;
+import org.jeecg.modules.system.vo.UserSelector;
 import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.time.LocalDate;
-import java.time.LocalDateTime;
 import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
-import java.util.stream.IntStream;
 
 /**
  * @Description: 鐐规宸ュ崟
@@ -90,6 +90,10 @@
     private IEamMaintenanceStandardDetailService eamMaintenanceStandardDetailService;
     @Resource
     private ISysDictService sysDictService;
+    @Resource
+    private ISysUserService sysUserService;
+    @Resource
+    private IEamBaseHFCodeService eamBaseHFCodeService;
 
     @Override
     public IPage<EamInspectionOrder> queryPageList(Page<EamInspectionOrder> page, EamInspectionOrderQuery query) {
@@ -170,6 +174,14 @@
      */
     @Override
     public JSONObject exportInspectionOrderBaseInfo(String equipmentCode, String inspectionDate) {
+        if (StrUtils.isEmpty(inspectionDate)) {
+            // 鑾峰彇褰撳墠鏃ユ湡
+            LocalDate currentDate = LocalDate.now();
+            // 瀹氫箟鏃ユ湡鏍煎紡
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+            // 鏍煎紡鍖栧綋鍓嶆湀浠�
+            inspectionDate = currentDate.format(formatter);
+        }
         // 鍒涘缓缁撴灉瀵硅薄
         JSONObject result = new JSONObject();
         EamInspectionOrderBaseResponse eamInspectionOrderBaseResponse = eamInspectionOrderMapper.findInsOrderBaseInfo(equipmentCode, inspectionDate);
@@ -189,6 +201,14 @@
      */
     @Override
     public JSONObject exportInspectionOrderDetailList(String equipmentCode, String inspectionDate) {
+        if (StrUtils.isEmpty(inspectionDate)) {
+            // 鑾峰彇褰撳墠鏃ユ湡
+            LocalDate currentDate = LocalDate.now();
+            // 瀹氫箟鏃ユ湡鏍煎紡
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+            // 鏍煎紡鍖栧綋鍓嶆湀浠�
+            inspectionDate = currentDate.format(formatter);
+        }
         // 鍒涘缓缁撴灉瀵硅薄
         JSONObject result = new JSONObject();
         List<EamInsOrderDetailResultResponse> eamInsOrderDetailResultResponseList = eamInspectionOrderMapper.findInsOrderDetailList(equipmentCode, inspectionDate);
@@ -232,19 +252,21 @@
             for (int i = 1; i <= 31; i++) {
                 if (collect.containsKey(i)) {
                     String inspectionResult = "";
-                    switch (collect.get(i).getInspectionResult()) {
-                        case "NORMAL":
-                            inspectionResult = "鈭�";
-                            break;
-                        case "ANOMALY":
-                            inspectionResult = "脳";
-                            break;
-                        case "FAULT":
-                            inspectionResult = "鈻�";
-                            break;
-                        case "CLOSE":
-                            inspectionResult = "T";
-                            break;
+                    if (!StrUtils.isEmpty(collect.get(i).getInspectionResult())) {
+                        switch (collect.get(i).getInspectionResult()) {
+                            case "NORMAL":
+                                inspectionResult = "鈭�";
+                                break;
+                            case "ANOMALY":
+                                inspectionResult = "脳";
+                                break;
+                            case "FAULT":
+                                inspectionResult = "鈻�";
+                                break;
+                            case "CLOSE":
+                                inspectionResult = "T";
+                                break;
+                        }
                     }
                     resultMap.put("inspectionResult" + i, inspectionResult);
                 } else {
@@ -265,6 +287,14 @@
      */
     @Override
     public JSONObject exportInspectionOrderDetailUserList(String equipmentCode, String inspectionDate) {
+        if (StrUtils.isEmpty(inspectionDate)) {
+            // 鑾峰彇褰撳墠鏃ユ湡
+            LocalDate currentDate = LocalDate.now();
+            // 瀹氫箟鏃ユ湡鏍煎紡
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+            // 鏍煎紡鍖栧綋鍓嶆湀浠�
+            inspectionDate = currentDate.format(formatter);
+        }
         // 鍒涘缓缁撴灉瀵硅薄
         JSONObject result = new JSONObject();
         List<EamInsOrderDetailUserResponse> eamInsOrderDetailUserResponseList = eamInspectionOrderMapper.findInspectionOrderDetailUserList(equipmentCode, inspectionDate);
@@ -308,6 +338,14 @@
      */
     @Override
     public JSONObject exportWeekInsDetailList(String equipmentCode, String inspectionDate) {
+        if (StrUtils.isEmpty(inspectionDate)) {
+            // 鑾峰彇褰撳墠鏃ユ湡
+            LocalDate currentDate = LocalDate.now();
+            // 瀹氫箟鏃ユ湡鏍煎紡
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+            // 鏍煎紡鍖栧綋鍓嶆湀浠�
+            inspectionDate = currentDate.format(formatter);
+        }
         // 鍒涘缓缁撴灉瀵硅薄
         JSONObject result = new JSONObject();
         List<EamWeekInsDetailResultResponse> eamWeekInsDetailResultResponseList = eamInspectionOrderMapper.findWeekInsDetailList(equipmentCode, inspectionDate);
@@ -350,19 +388,21 @@
             for (int i = 1; i <= 5; i++) {
                 if (collect.containsKey(i)) {
                     String inspectionResult = "";
-                    switch (collect.get(i).getInspectionResult()) {
-                        case "NORMAL":
-                            inspectionResult = "鈭�";
-                            break;
-                        case "ANOMALY":
-                            inspectionResult = "脳";
-                            break;
-                        case "FAULT":
-                            inspectionResult = "鈻�";
-                            break;
-                        case "CLOSE":
-                            inspectionResult = "T";
-                            break;
+                    if (!StrUtils.isEmpty(collect.get(i).getInspectionResult())) {
+                        switch (collect.get(i).getInspectionResult()) {
+                            case "NORMAL":
+                                inspectionResult = "鈭�";
+                                break;
+                            case "ANOMALY":
+                                inspectionResult = "脳";
+                                break;
+                            case "FAULT":
+                                inspectionResult = "鈻�";
+                                break;
+                            case "CLOSE":
+                                inspectionResult = "T";
+                                break;
+                        }
                     }
                     resultMap.put("inspectionResult" + i, inspectionResult);
                 } else {
@@ -383,6 +423,14 @@
      */
     @Override
     public JSONObject exportWeekInsOrderDetailUserList(String equipmentCode, String inspectionDate) {
+        if (StrUtils.isEmpty(inspectionDate)) {
+            // 鑾峰彇褰撳墠鏃ユ湡
+            LocalDate currentDate = LocalDate.now();
+            // 瀹氫箟鏃ユ湡鏍煎紡
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+            // 鏍煎紡鍖栧綋鍓嶆湀浠�
+            inspectionDate = currentDate.format(formatter);
+        }
         // 鍒涘缓缁撴灉瀵硅薄
         JSONObject result = new JSONObject();
         List<EamWeekInsDetailUserResponse> eamWeekInsDetailUserResponseList = eamInspectionOrderMapper.findWeekInsOrderDetailUserList(equipmentCode, inspectionDate);
@@ -429,6 +477,12 @@
         //淇敼鐘舵��
         eamInspectionOrder.setInspectionStatus(InspectionStatus.WAIT_INSPECTION.name());
         eamInspectionOrder.setDelFlag(CommonConstant.DEL_FLAG_0);
+        //HF鐮佸鐞�
+        EamBaseHFCode eamBaseHFCode = eamBaseHFCodeService.selectByCategory(HfTemplateCategoryEnum.INSPECTION.name());
+        if (eamBaseHFCode == null) {
+            return Result.error("娣诲姞澶辫触,鏈厤缃偣妫�HF缂栫爜锛�");
+        }
+        eamInspectionOrder.setHfCode(eamBaseHFCode.getHfCode());
         save(eamInspectionOrder);
         //澶勭悊鏃ョ偣妫�鏄庣粏鏁版嵁
         if (StrUtil.isNotBlank(eamInspectionOrderRequest.getStandardId())) {
@@ -479,7 +533,7 @@
         } else {
             eamInspectionOrder.setEquipmentId(equipment.getId());
         }
-        flowCommonService.initActBusiness("宸ュ崟鍙�: " + eamInspectionOrder.getOrderNum() + ";璁惧缂栧彿: " + equipment.getEquipmentCode() + (equipment.getInstallationPosition() == null ? "" : ";瀹夎浣嶇疆: " + equipment.getInstallationPosition()),
+        flowCommonService.initActBusiness("宸ュ崟鍙�: " + eamInspectionOrder.getOrderNum() + ";璁惧缂栧彿: " + equipment.getEquipmentCode(),
                 eamInspectionOrder.getId(), "IEamInspectionOrderService", "eam_inspection", null);
         Map<String, Object> variables = new HashMap<>();
         variables.put("dataId", eamInspectionOrder.getId());
@@ -598,8 +652,26 @@
                 throw new JeecgBootException("浠诲姟涓嶅瓨鍦ㄣ�佸凡瀹屾垚鎴栧凡琚粬浜鸿棰�");
             }
 
+            EamEquipment equipment = eamEquipmentService.getById(eamInspectionOrder.getEquipmentId());
+            if (equipment == null) {
+                throw new JeecgBootException("璁惧涓嶅瓨鍦紝璇锋鏌ワ紒");
+            }
+
+            // 妫�鏌ュ懆淇濊繃鏈熸椂闂�
+            if (eamInspectionOrderRequest.getTableWeekDetailList() == null || eamInspectionOrderRequest.getTableWeekDetailList().isEmpty()) {
+                List<EamWeekInspectionDetail> weekInspectionDetailList = eamWeekInspectionDetailService.list(new LambdaQueryWrapper<EamWeekInspectionDetail>().eq(EamWeekInspectionDetail::getStandardId, eamInspectionOrderRequest.getStandardId()).between(EamWeekInspectionDetail::getPlanInspectionDate, DateUtils.getFirstDayOfWeek(eamInspectionOrderRequest.getInspectionDate()), DateUtils.getLastDayOfWeek(eamInspectionOrderRequest.getInspectionDate())));
+                if (weekInspectionDetailList != null && !weekInspectionDetailList.isEmpty()) {
+                    if (StrUtil.isEmpty(eamInspectionOrderRequest.getOperator())) {
+                        Date lastDate = DateUtils.getLastDayOfWeek(eamInspectionOrderRequest.getInspectionDate());
+                        if (DateUtils.isSameDay(lastDate, new Date())) {
+                            throw new JeecgBootException("鏈懆鐐规鏈畬鎴愶紝璇疯繘琛屽~鎶ワ紒");
+                        }
+                    }
+                }
+            }
+
             // 璁剧疆娴佺▼鍙橀噺
-            setupProcessVariables(eamInspectionOrderRequest, eamInspectionOrder, user);
+            setupProcessVariables(eamInspectionOrderRequest, eamInspectionOrder, user, equipment);
 
             // 瀹屾垚娴佺▼浠诲姟
             Result result = flowTaskService.complete(eamInspectionOrderRequest);
@@ -661,13 +733,20 @@
         return true;
     }
 
-    private void setupProcessVariables(EamInspectionOrderRequest request, EamInspectionOrder order, LoginUser user) {
+    private void setupProcessVariables(EamInspectionOrderRequest request, EamInspectionOrder order, LoginUser user, EamEquipment equipment) {
         Map<String, Object> values = new HashMap<>();
         if (InspectionStatus.UNDER_INSPECTION.name().equals(order.getInspectionStatus()) && user.getUsername().equals(order.getOperator())) {
             // 鐐规浜虹偣妫�缁撴潫
             values.put("dataId", order.getId());
             values.put("organization", "鐐规浜虹偣妫�缁撴潫");
             values.put("comment", "鐐规浜虹偣妫�缁撴潫");
+            // 鑾峰彇涓嬩竴姝ユ墽琛屼汉
+            List<UserSelector> userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0002);
+            if (CollectionUtil.isEmpty(userSelectors)) {
+                throw new JeecgBootException("璁惧鏈垎閰嶇粰缁翠慨宸ワ紝鏃犳硶杩涘叆涓嬬骇瀹℃壒锛�");
+            }
+            List<String> userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
+            values.put("NextAssignee", userApprovalList);
             request.setComment("鐐规浜虹偣妫�缁撴潫");
         } else {
             // 缁翠慨宸ョ‘璁�
@@ -696,10 +775,17 @@
                 eamInspectionOrderDetailService.remove(new QueryWrapper<EamInspectionOrderDetail>().eq("order_id", order.getId()));
                 eamInspectionOrderDetailService.saveBatch(request.getTableDetailList());
 
+                //璁剧疆鍛ㄧ偣妫�
                 if (request.getTableWeekDetailList() != null && !request.getTableWeekDetailList().isEmpty()) {
-                    // 璁剧疆鍛ㄧ偣妫�
-//                eamWeekInspectionDetailService.remove(new QueryWrapper<EamWeekInspectionDetail>().eq("order_id", order.getId()));
-                    eamWeekInspectionDetailService.saveOrUpdateBatch(request.getTableWeekDetailList());
+                    List<EamWeekInspectionDetail> tableWeekDetailList = request.getTableWeekDetailList();
+                    for (EamWeekInspectionDetail eamWeekInspectionDetail : tableWeekDetailList) {
+                        if (StringUtils.isEmpty(eamWeekInspectionDetail.getInspectionResult())) {
+                            break;
+                        }
+                        eamWeekInspectionDetail.setInspector(user.getUsername());
+                        eamWeekInspectionDetail.setInspectTime(new Date());
+                    }
+                    eamWeekInspectionDetailService.saveOrUpdateBatch(tableWeekDetailList);
                 }
             } else if (InspectionStatus.WAIT_CONFIRM.name().equals(order.getInspectionStatus()) && StrUtil.isNotEmpty(request.getConfirmDealType())) {
                 // 鐝粍闀跨‘璁や换鍔�
@@ -723,8 +809,10 @@
      */
     private void updateEamInspectionOrderDetail(EamInspectionOrder eamInspectionOrder) {
         List<EamInspectionOrderDetail> eamInspectionOrderDetails = eamInspectionOrderDetailService
-                .list(new QueryWrapper<EamInspectionOrderDetail>()
-                        .eq("order_id", eamInspectionOrder.getId()).eq("report_flag", "1").eq("inspection_result", "2"));
+                .list(new LambdaQueryWrapper<EamInspectionOrderDetail>()
+                        .eq(EamInspectionOrderDetail::getOrderId, eamInspectionOrder.getId()).eq(EamInspectionOrderDetail::getReportFlag, "1"));
+
+        // TODO 鐐规瀹屾垚鍚庤嚜鍔ㄤ繚淇�
         eamReportRepairService.reportRepairFromInspection(eamInspectionOrder.getEquipmentId(), eamInspectionOrder.getOperator(), eamInspectionOrderDetails);
     }
 

--
Gitblit v1.9.3