From d61b21c50e62298f185ecafa8e0b22f7ee8c4973 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期四, 21 八月 2025 18:13:17 +0800
Subject: [PATCH] 430报表接口与列表流程添加

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java |  429 +++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 382 insertions(+), 47 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 e90a510..4dd9e26 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
@@ -11,6 +11,7 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.ibatis.annotations.Param;
 import org.apache.shiro.SecurityUtils;
 import org.flowable.engine.TaskService;
 import org.flowable.task.api.Task;
@@ -19,9 +20,14 @@
 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.*;
+import org.jeecg.modules.eam.dto.DailyResponsibleInfo;
+import org.jeecg.modules.eam.dto.EamInspectionOrderDetailExport;
+import org.jeecg.modules.eam.dto.EamInspectionOrderExport;
+import org.jeecg.modules.eam.dto.WeeklyResponsibleInfo;
 import org.jeecg.modules.eam.request.*;
 import org.jeecg.modules.system.entity.BaseFactory;
 import org.jeecg.modules.system.entity.BaseFactoryUser;
@@ -47,6 +53,8 @@
 import javax.annotation.Resource;
 import java.time.LocalDate;
 import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
@@ -101,9 +109,9 @@
         if (sysUser == null) {
             return page;
         }
-        if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) {
+        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
             //閫夋嫨浜嗚澶囷紝鏍规嵁璁惧id杩囨护璁惧
-            List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(","));
+            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
             queryWrapper.in("e.equipment_code", equipArr);
         } else {
             //娌℃湁閫夋嫨璁惧锛屾牴鎹腑蹇冭繃婊よ澶�
@@ -172,6 +180,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);
@@ -191,6 +207,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);
@@ -234,19 +258,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 {
@@ -267,6 +293,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);
@@ -310,6 +344,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);
@@ -335,36 +377,40 @@
             resultMap.put("itemCode", weekInsDetailResultResponse.getItemCode());
             resultMap.put("itemName", weekInsDetailResultResponse.getItemName());
             resultMap.put("itemDemand", weekInsDetailResultResponse.getItemDemand());
-            // 浣跨敤AtomicInteger浣滀负璁℃暟鍣紝浠�1寮�濮�
-            AtomicInteger counter = new AtomicInteger(1);
             Map<Integer, EamWeekInsDetailResultResponse> collect = weekInsDetailResultResponseList
                     .stream()
                     .collect(Collectors.toMap(
-                            // 鍒嗙粍閿細浣跨敤鑷搴忓彿锛堜粠1寮�濮嬶級
-                            item -> counter.getAndIncrement(),
+                            // 鍒嗙粍閿細浣跨敤planInspectionDate瀛楁钀藉湪鏈湀鐨勫懆鏁�
+                            item -> {
+                                Calendar calendar = Calendar.getInstance();
+                                calendar.setTime(item.getPlanInspectionDate());
+                                return calendar.get(Calendar.WEEK_OF_MONTH);
+                            },
                             // 鍊硷細鐩存帴浣跨敤褰撳墠瀵硅薄
                             item -> item,
-                            // 鍚堝苟鍑芥暟锛氬綋鍚屼竴搴忓彿鏈夊涓璞℃椂锛堢悊璁轰笂涓嶄細鍙戠敓锛夛紝濡備綍澶勭悊
-                            (existing, replacement) -> existing, // 鑻ユ湁閲嶅閿紝淇濈暀宸插瓨鍦ㄧ殑瀵硅薄
+                            // 鍚堝苟鍑芥暟锛氬綋鍚屼竴鍛ㄦ湁澶氫釜瀵硅薄鏃讹紙鏍规嵁闇�姹備笉浼氬彂鐢燂紝浣嗕粛闇�鎻愪緵锛�
+                            (existing, replacement) -> existing,
                             // 鎸囧畾Map鐨勫叿浣撳疄鐜帮紙鍙�夛級
                             LinkedHashMap::new // 淇濇寔鎻掑叆椤哄簭
                     ));
             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 {
@@ -385,23 +431,35 @@
      */
     @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);
         if (eamWeekInsDetailUserResponseList == null || eamWeekInsDetailUserResponseList.isEmpty()) {
             return result;
         }
-        // 浣跨敤AtomicInteger浣滀负璁℃暟鍣紝浠�1寮�濮�
-        AtomicInteger counter = new AtomicInteger(1);
         Map<Integer, EamWeekInsDetailUserResponse> groupMap = eamWeekInsDetailUserResponseList
                 .stream()
                 .collect(Collectors.toMap(
-                        // 鍒嗙粍閿細浣跨敤鑷搴忓彿锛堜粠1寮�濮嬶級
-                        item -> counter.getAndIncrement(),
-                        // 鍊硷細鐩存帴浣跨敤褰撳墠瀵硅薄锛堜綔涓哄垵濮嬪�硷級
+                        // 鍒嗙粍閿細浣跨敤 planInspectionDate 瀛楁钀藉湪鏈湀鐨勫懆鏁�
+                        item -> {
+                            Calendar calendar = Calendar.getInstance();
+                            calendar.setTime(item.getPlanInspectionDate());
+                            return calendar.get(Calendar.WEEK_OF_MONTH);
+                        },
+                        // 鍊硷細鐩存帴浣跨敤褰撳墠瀵硅薄
                         item -> item,
-                        // 鍚堝苟鍑芥暟锛氬綋鍚屼竴鈥滃ぉ鈥濇湁澶氫釜瀵硅薄鏃讹紝濡備綍澶勭悊锛堣繖閲岀ず渚嬪彇绗竴涓級
-                        (existing, replacement) -> existing // 鑻ユ湁閲嶅閿紝淇濈暀宸插瓨鍦ㄧ殑瀵硅薄
+                        // 鍚堝苟鍑芥暟锛氬綋鍚屼竴鍛ㄦ湁澶氫釜瀵硅薄鏃讹紙鏍规嵁闇�姹備笉浼氬彂鐢燂級
+                        (existing, replacement) -> existing,
+                        // 浣跨敤 LinkedHashMap 淇濇寔鎻掑叆椤哄簭
+                        LinkedHashMap::new
                 ));
         Map<String, Object> resultMap = new LinkedHashMap<>();
         for (int i = 1; i <= 5; i++) {
@@ -464,7 +522,6 @@
                     weekInspectionDetailList.forEach(weekInspectionDetail -> {
                         weekInspectionDetail.setEquipmentId(eamInspectionOrderRequest.getEquipmentId());
                         weekInspectionDetail.setStandardId(eamInspectionOrderRequest.getStandardId());
-                        // TODO 鍛ㄧ偣妫�鏃ユ湡
                         weekInspectionDetail.setPlanInspectionDate(eamInspectionOrderRequest.getInspectionDate());
                     });
                     eamWeekInspectionDetailService.saveBatch(weekInspectionDetailList);
@@ -487,7 +544,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());
@@ -611,6 +668,19 @@
                 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, equipment);
 
@@ -624,9 +694,9 @@
             updateEamInspectionOrder(eamInspectionOrder);
 
             //鏌ヨ鏁版嵁,杩涜璁惧缁翠慨澶勭悊
-            if (eamInspectionOrder.getInspectionStatus().equals(InspectionStatus.WAIT_CONFIRM.name())) {
-                updateEamInspectionOrderDetail(eamInspectionOrder);
-            }
+//            if (eamInspectionOrder.getInspectionStatus().equals(InspectionStatus.WAIT_CONFIRM.name())) {
+//                updateEamInspectionOrderDetail(eamInspectionOrder);
+//            }
 
             return eamInspectionOrder;
         } catch (Exception e) {
@@ -634,6 +704,270 @@
         }
     }
 
+    /**
+     * 鐢熶骇璁惧鑷富缁存姢鐐规琛ㄦ墦鍗�
+     * @param ids
+     * @return
+     */
+    @Override
+    public List<EamInspectionOrderExport> printInspectionOrder(String ids) {
+
+        List<EamInspectionOrderExport> eamInspectionOrderExports =
+                this.eamInspectionOrderMapper.queryList(Arrays.asList(ids.split(",")));
+
+        if (eamInspectionOrderExports == null || eamInspectionOrderExports.isEmpty()) {
+            return null;
+        }
+
+        eamInspectionOrderExports.forEach(eamInspectionOrderExport -> {
+
+            // 鏃ユ湡澶勭悊
+            if (StrUtil.isNotEmpty(eamInspectionOrderExport.getInspectionMonth())){
+                if (eamInspectionOrderExport.getInspectionMonth().length() == 1) {
+                    eamInspectionOrderExport.setInspectionMonth("0" + eamInspectionOrderExport.getInspectionMonth());
+                }
+            }
+            String finalInspectionDate = eamInspectionOrderExport.getInspectionYear()+"-" + eamInspectionOrderExport.getInspectionMonth();
+            // 鑾峰彇璇ヨ澶囩殑鏃ョ偣妫�鏄庣粏鏁版嵁
+            List<EamInsOrderDetailResultResponse> detailResponseList =
+                    eamInspectionOrderMapper.findInsOrderDetailList(
+                            eamInspectionOrderExport.getEquipmentCode(),
+                            finalInspectionDate
+                    );
+
+            if (!detailResponseList.isEmpty()) {
+                // 鎸夐」鐩垎缁勫瓨鍌紙椤圭洰缂栫爜涓簁ey锛�
+                Map<Integer, EamInspectionOrderDetailExport> detailExportMap = new HashMap<>();
+
+                // 鍒濆鍖栭」鐩俊鎭紙姣忎釜椤圭洰瀵瑰簲涓�涓�31澶╃姸鎬佺殑瀵硅薄锛�
+                detailResponseList.forEach(detail -> {
+                    Integer itemCode = detail.getItemCode();
+                    EamInspectionOrderDetailExport export = detailExportMap.get(itemCode);
+
+                    if (export == null) {
+                        // 鍒涘缓鏂扮殑鐐规椤圭洰瀵硅薄
+                        export = new EamInspectionOrderDetailExport()
+                                .setItemCode(itemCode)
+                                .setItemName(detail.getItemName())
+                                .setItemDemand(detail.getItemDemand())
+                                .setDateFlag(new String[31]); // 鍒濆鍖�31澶╃姸鎬佹暟缁�
+
+                        detailExportMap.put(itemCode, export);
+                    }
+                });
+
+                // 濉厖鍚勯」鐩瘡鏃ョ殑鐐规鐘舵��
+                detailResponseList.forEach(detail -> {
+                    Integer itemCode = detail.getItemCode();
+                    EamInspectionOrderDetailExport export = detailExportMap.get(itemCode);
+
+                    try {
+                        Date newinspectionDate = detail.getInspectionDate();
+
+                        // 澶勭悊绌烘棩鏈熸儏鍐�
+                        if (newinspectionDate == null) {
+                            log.warn("妫�娴嬪埌绌烘棩鏈熷��, itemCode: {}");
+                            return;
+                        }
+                        // 杞崲涓篖ocalDate
+                        LocalDate date = newinspectionDate.toInstant()
+                                .atZone(ZoneId.systemDefault())
+                                .toLocalDate();
+                        int day = date.getDayOfMonth();
+                        // 瀹夊叏璁剧疆鏃ユ湡鐘舵��
+                        if (day >= 1 && day <= 31) {
+                            String[] dateFlags = export.getDateFlag();
+                            if (dateFlags == null) {
+                                dateFlags = new String[31];
+                                export.setDateFlag(dateFlags);
+                            }
+                            if (StrUtil.isNotEmpty(detail.getInspectionResult())){
+                                switch (detail.getInspectionResult()) {
+                                    case "NORMAL":
+                                        dateFlags[day - 1] = "鈭�";
+                                        break;
+                                    case "ANOMALY":
+                                        dateFlags[day - 1] = "脳";
+                                        break;
+                                    case "FAULT":
+                                        dateFlags[day - 1] = "鈻�";
+                                        break;
+                                    case "CLOSE":
+                                        dateFlags[day - 1] = "T";
+                                        break;
+                                }
+                            }
+                        } else {
+                            log.warn("闈炴硶鏃ユ湡鍊�: {}, itemCode: {}");
+                        }
+                    }
+                    catch (DateTimeParseException | NullPointerException e) {
+                        log.error("鏃ユ湡澶勭悊閿欒 - 鍘熷鍊�: {}, 椤圭洰: {}, 閿欒: {}");
+                    }
+                });
+                // 灏嗙偣妫�椤圭洰闆嗗悎杞崲涓哄垪琛�
+                List<EamInspectionOrderDetailExport> detailExports =
+                        new ArrayList<>(detailExportMap.values());
+                // 璁剧疆鍒颁富瀵煎嚭瀵硅薄涓�
+                eamInspectionOrderExport.setEamDailyInspectionList(detailExports);
+            }else {
+                eamInspectionOrderExport.setEamDailyInspectionList(null);
+            }
+            // 鑾峰彇璇ヨ澶囩殑鍛ㄧ偣妫�鏄庣粏鏁版嵁
+            List<EamWeekInsDetailResultResponse> eamWeekInsDetailResultResponseList =
+                    eamInspectionOrderMapper.findWeekInsDetailList(
+                            eamInspectionOrderExport.getEquipmentCode(),
+                            finalInspectionDate
+                    );
+            if (!eamWeekInsDetailResultResponseList.isEmpty()) {
+                // 鎸夐」鐩垎缁勫瓨鍌紙椤圭洰缂栫爜涓簁ey锛�
+                Map<Integer, EamInspectionOrderDetailExport> detailExportMap = new HashMap<>();
+                // 鍒濆鍖栭」鐩俊鎭�
+                eamWeekInsDetailResultResponseList.forEach(detail -> {
+                    Integer itemCode = detail.getItemCode();
+                    EamInspectionOrderDetailExport export = detailExportMap.get(itemCode);
+                    if (export == null) {
+                        // 鍒涘缓鏂扮殑鐐规椤圭洰瀵硅薄骞跺垵濮嬪寲weekFlag鏁扮粍
+                        export = new EamInspectionOrderDetailExport()
+                                .setItemCode(itemCode)
+                                .setItemName(detail.getItemName())
+                                .setItemDemand(detail.getItemDemand())
+                                .setWeekFlag(new String[5]); // 鏄庣‘鍒濆鍖栭暱搴︿负5
+                        detailExportMap.put(itemCode, export);
+                    }
+                });
+                // 濉厖鍚勯」鐩瘡鍛ㄧ殑鐐规鐘舵��
+                eamWeekInsDetailResultResponseList.forEach(detail -> {
+                    Integer itemCode = detail.getItemCode();
+                    EamInspectionOrderDetailExport export = detailExportMap.get(itemCode);
+
+                    Date newinspectionDate = detail.getPlanInspectionDate();
+                    if (newinspectionDate == null) {
+                        log.warn("妫�娴嬪埌绌烘棩鏈熷��, itemCode: {}");
+                        return;
+                    }
+
+                    // 璁$畻璇ユ棩鏈熸槸褰撴湀绗嚑鍛� (1-5)
+                    int week = calculateWeekOfMonth(newinspectionDate);
+
+                    if (week >= 1 && week <= 5) {
+                        String[] weekFlags = export.getWeekFlag();
+                        if (weekFlags == null) {
+                            weekFlags = new String[31];
+                            export.setWeekFlag(weekFlags);
+                        }
+                        if (StrUtil.isNotEmpty(detail.getInspectionResult())){
+                            switch (detail.getInspectionResult()) {
+                                case "NORMAL":
+                                    weekFlags[week - 1] = "鈭�";
+                                    break;
+                                case "ANOMALY":
+                                    weekFlags[week - 1] = "脳";
+                                    break;
+                                case "FAULT":
+                                    weekFlags[week - 1] = "鈻�";
+                                    break;
+                                case "CLOSE":
+                                    weekFlags[week - 1] = "T";
+                                    break;
+                            }
+                        }
+                    }
+                });
+                // 灏嗙偣妫�椤圭洰闆嗗悎杞崲涓哄垪琛�
+                List<EamInspectionOrderDetailExport> weekDetailExports =
+                        new ArrayList<>(detailExportMap.values());
+                // 璁剧疆鍒颁富瀵煎嚭瀵硅薄涓�
+                eamInspectionOrderExport.setEamWeeklyInspectionList(weekDetailExports);
+            }else {
+                eamInspectionOrderExport.setEamWeeklyInspectionList(null);
+            }
+
+
+            // ================== 娣诲姞鏃ョ偣妫�璐d换浜轰俊鎭� ==================
+            DailyResponsibleInfo dailyResponsible = new DailyResponsibleInfo();
+            List<EamInsOrderDetailUserResponse> dailyUserResponses =
+                    eamInspectionOrderMapper.findInspectionOrderDetailUserList(
+                            eamInspectionOrderExport.getEquipmentCode(),
+                            finalInspectionDate
+                    );
+
+            if (dailyUserResponses != null && !dailyUserResponses.isEmpty()) {
+                dailyUserResponses.forEach(response -> {
+                    try {
+                        Date date = response.getInspectionDate();
+                        if (date == null) return;
+
+                        LocalDate localDate = date.toInstant()
+                                .atZone(ZoneId.systemDefault())
+                                .toLocalDate();
+
+                        int day = localDate.getDayOfMonth();
+                        if (day < 1 || day > 31) return;
+
+                        // 鑾峰彇鎿嶄綔鍛樺拰纭浜哄鍚�
+                        String operator = sysDictService.queryTableDictTextByKey(
+                                "sys_user", "realname", "username", response.getOperator());
+                        String confirmUser = sysDictService.queryTableDictTextByKey(
+                                "sys_user", "realname", "username", response.getConfirmUser());
+
+                        // 璁剧疆璐d换浜轰俊鎭�
+                        dailyResponsible.setResponsibleForDay(day, operator, confirmUser);
+                    } catch (Exception e) {
+                        log.error("澶勭悊鏃ョ偣妫�璐d换浜轰俊鎭嚭閿�: {}");
+                    }
+                });
+            }
+            eamInspectionOrderExport.setDailyResponsibleInfo(dailyResponsible);
+
+            // ================== 娣诲姞鍛ㄧ偣妫�璐d换浜轰俊鎭� ==================
+            WeeklyResponsibleInfo weeklyResponsible = new WeeklyResponsibleInfo();
+            List<EamWeekInsDetailUserResponse> weeklyUserResponses =
+                    eamInspectionOrderMapper.findWeekInsOrderDetailUserList(
+                            eamInspectionOrderExport.getEquipmentCode(),
+                            finalInspectionDate
+                    );
+
+            if (weeklyUserResponses != null && !weeklyUserResponses.isEmpty()) {
+                weeklyUserResponses.forEach(response -> {
+                    try {
+                        Date date = response.getPlanInspectionDate();
+                        if (date == null) return;
+
+                        // 璁$畻鍛ㄦ暟
+                        Calendar calendar = Calendar.getInstance();
+                        calendar.setTime(date);
+                        int week = calendar.get(Calendar.WEEK_OF_MONTH);
+                        if (week < 1 || week > 5) return;
+
+                        // 鑾峰彇鎿嶄綔鍛樺拰纭浜哄鍚�
+                        String operator = sysDictService.queryTableDictTextByKey(
+                                "sys_user", "realname", "username", response.getInspector());
+                        String confirmUser = sysDictService.queryTableDictTextByKey(
+                                "sys_user", "realname", "username", response.getConfirmUser());
+
+                        // 璁剧疆璐d换浜轰俊鎭�
+                        weeklyResponsible.setResponsibleForWeek(week, operator, confirmUser);
+                    } catch (Exception e) {
+                        log.error("澶勭悊鍛ㄧ偣妫�璐d换浜轰俊鎭嚭閿�: {}");
+                    }
+                });
+            }
+            eamInspectionOrderExport.setWeeklyResponsibleInfo(weeklyResponsible);
+        });
+
+        return eamInspectionOrderExports;
+
+    }
+
+    /**
+     * 璁$畻鏃ユ湡鍦ㄥ綋鏈堟槸绗嚑鍛紙1-5锛�
+     */
+    private int calculateWeekOfMonth(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.get(Calendar.WEEK_OF_MONTH);
+    }
 
     private boolean isValidRequest(EamInspectionOrderRequest request) {
         return StrUtil.isNotBlank(request.getTaskId()) && StrUtil.isNotBlank(request.getDataId());
@@ -695,13 +1029,14 @@
             values.put("organization", request.getConfirmComment());
             values.put("comment", request.getConfirmComment());
             values.put("confirmation", request.getConfirmDealType());
-            request.setComment(request.getConfirmComment());
+            request.setComment("缁翠慨宸ョ‘璁ょ粨鏉�");
             if ("2".equals(request.getConfirmDealType())) {
                 // 缁翠慨宸ラ┏鍥�
                 List<String> usernames = new ArrayList<>();
                 usernames.add(order.getOperator());
                 order.setInspectionStatus(InspectionStatus.UNDER_INSPECTION.name());
                 values.put("NextAssignee", usernames);
+                request.setComment("缁翠慨宸ラ┏鍥炵粨鏉�");
             }
         }
         request.setValues(values);

--
Gitblit v1.9.3