From 7a4a03e2c1455ba7a7c6fa60702e350faf6e25bb Mon Sep 17 00:00:00 2001
From: hongjli <3117313295@qq.com>
Date: 星期一, 26 五月 2025 14:13:42 +0800
Subject: [PATCH] 管路&气柜产能负载按日统计查不到数据时不返回空

---
 aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java |  418 +++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 273 insertions(+), 145 deletions(-)

diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java
index 248f120..42c418c 100644
--- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java
+++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java
@@ -1540,160 +1540,159 @@
                 plantTable.add(rowEntry);
             }
             
+            // 鏇存柊缁撴灉浣嗕笉鐩存帴杩斿洖锛岀户缁墽琛屽悗缁敞鎰忕偣4鐨勫鐞�
             result.put("plantTable", plantTable);
             result.put("timePoints", timePoints);
             result.put("rowGroupBy", rowGroupBy);
+        } else {
+            // 鍦⊿ervice灞傚畬鎴愯仛鍚�
+            // 浣跨敤缁勫悎key鏉ュ疄鐜板缁村害鍒嗙粍锛堝姩鎬乺owGroupBy瀛楁 + 鍙�夌殑宸ュ巶/涓撲笟/杞﹂棿锛�
+            Map<String, Map<String, Object>> groupInfoMap = new HashMap<>();
+            Map<String, Map<String, BigDecimal>> groupTimeDataMap = new HashMap<>();
+            // 瀛樺偍姣忎釜groupKey瀵瑰簲鐨刾rocessName闆嗗悎
+            Map<String, Set<String>> groupProcessNamesMap = new HashMap<>();
             
-            return result;
-        }
-        
-        // 鍦⊿ervice灞傚畬鎴愯仛鍚�
-        // 浣跨敤缁勫悎key鏉ュ疄鐜板缁村害鍒嗙粍锛堝姩鎬乺owGroupBy瀛楁 + 鍙�夌殑宸ュ巶/涓撲笟/杞﹂棿锛�
-        Map<String, Map<String, Object>> groupInfoMap = new HashMap<>();
-        Map<String, Map<String, BigDecimal>> groupTimeDataMap = new HashMap<>();
-        // 瀛樺偍姣忎釜groupKey瀵瑰簲鐨刾rocessName闆嗗悎
-        Map<String, Set<String>> groupProcessNamesMap = new HashMap<>();
-        
-        // 閬嶅巻鍘熷鏁版嵁锛屾寜澶氱淮搴﹀垎缁勮繘琛岃仛鍚�
-        for (Map<String, Object> data : rawData) {
-            // 鑾峰彇琛屽垎缁勫瓧娈靛��
-            String rowGroupValue = getStringValue(data, rowGroupBy);
-            if (rowGroupValue == null || rowGroupValue.trim().isEmpty()) {
-                log.warn("璺宠繃澶勭悊锛歿} 瀛楁鍊间负绌�", rowGroupBy);
-                continue;
-            }
-            
-            // 鑾峰彇宸ュ簭鍚嶇О锛堢敤浜庢棩蹇楀拰鍚庣画澶勭悊锛�
-            String processName = getStringValue(data, "processName");
-            
-            // 澶勭悊寮�宸ユ棩鏈�
-            Date processPlanStartDay = (Date) data.get("processPlanStartDay");
-            if (processPlanStartDay == null) {
-                log.warn("璺宠繃澶勭悊锛氳鍒掑紑宸ユ棩涓簄ull, {}={}", rowGroupBy, rowGroupValue);
-                continue;
-            }
-            
-            // 鏋勫缓鍒嗙粍閿� - 鍩轰簬row鍒嗙粍瀛楁鍜屽彲閫夌殑鍏朵粬缁村害
-            String plant = getStringValue(data, "plant");
-            String major = getStringValue(data, "major");
-            String workshop = getStringValue(data, "workshop");
-            
-            StringBuilder groupKeyBuilder = new StringBuilder(rowGroupValue);
-            
-            // 鏍规嵁鐢ㄦ埛閫夋嫨鐨勫垎缁勭淮搴︽坊鍔犲埌鍒嗙粍閿�
-            if (groupByPlant && plant != null) {
-                groupKeyBuilder.append("_PLANT_").append(plant);
-            }
-            if (groupByMajor && major != null) {
-                groupKeyBuilder.append("_MAJOR_").append(major);
-            }
-            if (groupByWorkshop && workshop != null) {
-                groupKeyBuilder.append("_WORKSHOP_").append(workshop);
-            }
-            
-            String groupKey = groupKeyBuilder.toString();
-            
-            // 璁板綍鍒嗙粍鐨勫熀鏈俊鎭紙鍙褰曚竴娆★級
-            if (!groupInfoMap.containsKey(groupKey)) {
-                Map<String, Object> groupInfo = new HashMap<>();
-                groupInfo.put(rowGroupBy, rowGroupValue);
-                groupInfo.put("plant", plant);
-                groupInfo.put("major", major);
-                groupInfo.put("workshop", workshop);
-                groupInfo.put("processName", processName);
-                groupInfoMap.put(groupKey, groupInfo);
-            }
-            
-            // 鏀堕泦processName
-            if (processName != null && !processName.trim().isEmpty()) {
-                if (!groupProcessNamesMap.containsKey(groupKey)) {
-                    groupProcessNamesMap.put(groupKey, new HashSet<>());
+            // 閬嶅巻鍘熷鏁版嵁锛屾寜澶氱淮搴﹀垎缁勮繘琛岃仛鍚�
+            for (Map<String, Object> data : rawData) {
+                // 鑾峰彇琛屽垎缁勫瓧娈靛��
+                String rowGroupValue = getStringValue(data, rowGroupBy);
+                if (rowGroupValue == null || rowGroupValue.trim().isEmpty()) {
+                    log.warn("璺宠繃澶勭悊锛歿} 瀛楁鍊间负绌�", rowGroupBy);
+                    continue;
                 }
-                groupProcessNamesMap.get(groupKey).add(processName);
-            }
-            
-            // 璁$畻鏃堕棿鐐筀ey
-            String timeKey;
-            LocalDate planStartLocalDate = processPlanStartDay.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
-            
-            if ("day".equalsIgnoreCase(timeGranularity)) {
-                // 鏃ョ矑搴�: 2025-05-25
-                timeKey = planStartLocalDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
-            } else {
-                // 鏈堢矑搴�: 2025-05
-                timeKey = planStartLocalDate.getYear() + "-" + String.format("%02d", planStartLocalDate.getMonthValue());
-            }
-            
-            // 鑾峰彇璇ュ垎缁勭殑鏃堕棿鐐规槧灏勶紝濡傛灉涓嶅瓨鍦ㄥ垯鍒涘缓
-            if (!groupTimeDataMap.containsKey(groupKey)) {
-                groupTimeDataMap.put(groupKey, new HashMap<>());
-            }
-            Map<String, BigDecimal> timeMap = groupTimeDataMap.get(groupKey);
-            
-            // 绱姞璇ュ垎缁勫湪璇ユ椂闂寸偣鐨勫伐鏃舵暟鎹�
-            BigDecimal processTotalTime = getBigDecimalValue(data, "processTotalTime");
-            if (processTotalTime != null) {
-                BigDecimal currentTotal = timeMap.getOrDefault(timeKey, BigDecimal.ZERO);
-                timeMap.put(timeKey, currentTotal.add(processTotalTime));
-            }
-        }
-        
-        // 鏋勫缓鏈�缁堣繑鍥炵殑鏁版嵁缁撴瀯
-        for (String groupKey : groupInfoMap.keySet()) {
-            Map<String, Object> rowEntry = new HashMap<>();
-            Map<String, Object> rowDetail = new HashMap<>();
-            
-            // 鑾峰彇璇ュ垎缁勭殑鍩烘湰淇℃伅
-            Map<String, Object> groupInfo = groupInfoMap.get(groupKey);
-            String rowGroupValue = (String) groupInfo.get(rowGroupBy);
-            
-            // 娣诲姞鍒嗙粍鍩烘湰淇℃伅
-            if (groupByPlant) {
-                rowDetail.put("plant", groupInfo.get("plant"));
-            }
-            if (groupByMajor) {
-                rowDetail.put("major", groupInfo.get("major"));
-            }
-            if (groupByWorkshop) {
-                rowDetail.put("workshop", groupInfo.get("workshop"));
-            }
-            
-            // 澶勭悊processName - 濡傛灉rowGroupBy涓簑orkshop锛屽垯灏嗘墍鏈塸rocessName鐢ㄥ垎鍙疯繛鎺�
-            if ("workshop".equals(rowGroupBy)) {
-                Set<String> processNames = groupProcessNamesMap.getOrDefault(groupKey, new HashSet<>());
-                if (!processNames.isEmpty()) {
-                    String joinedProcessNames = String.join(";", processNames);
-                    rowDetail.put("processName", joinedProcessNames);
+                
+                // 鑾峰彇宸ュ簭鍚嶇О锛堢敤浜庢棩蹇楀拰鍚庣画澶勭悊锛�
+                String processName = getStringValue(data, "processName");
+                
+                // 澶勭悊寮�宸ユ棩鏈�
+                Date processPlanStartDay = (Date) data.get("processPlanStartDay");
+                if (processPlanStartDay == null) {
+                    log.warn("璺宠繃澶勭悊锛氳鍒掑紑宸ユ棩涓簄ull, {}={}", rowGroupBy, rowGroupValue);
+                    continue;
+                }
+                
+                // 鏋勫缓鍒嗙粍閿� - 鍩轰簬row鍒嗙粍瀛楁鍜屽彲閫夌殑鍏朵粬缁村害
+                String plant = getStringValue(data, "plant");
+                String major = getStringValue(data, "major");
+                String workshop = getStringValue(data, "workshop");
+                
+                StringBuilder groupKeyBuilder = new StringBuilder(rowGroupValue);
+                
+                // 鏍规嵁鐢ㄦ埛閫夋嫨鐨勫垎缁勭淮搴︽坊鍔犲埌鍒嗙粍閿�
+                if (groupByPlant && plant != null) {
+                    groupKeyBuilder.append("_PLANT_").append(plant);
+                }
+                if (groupByMajor && major != null) {
+                    groupKeyBuilder.append("_MAJOR_").append(major);
+                }
+                if (groupByWorkshop && workshop != null) {
+                    groupKeyBuilder.append("_WORKSHOP_").append(workshop);
+                }
+                
+                String groupKey = groupKeyBuilder.toString();
+                
+                // 璁板綍鍒嗙粍鐨勫熀鏈俊鎭紙鍙褰曚竴娆★級
+                if (!groupInfoMap.containsKey(groupKey)) {
+                    Map<String, Object> groupInfo = new HashMap<>();
+                    groupInfo.put(rowGroupBy, rowGroupValue);
+                    groupInfo.put("plant", plant);
+                    groupInfo.put("major", major);
+                    groupInfo.put("workshop", workshop);
+                    groupInfo.put("processName", processName);
+                    groupInfoMap.put(groupKey, groupInfo);
+                }
+                
+                // 鏀堕泦processName
+                if (processName != null && !processName.trim().isEmpty()) {
+                    if (!groupProcessNamesMap.containsKey(groupKey)) {
+                        groupProcessNamesMap.put(groupKey, new HashSet<>());
+                    }
+                    groupProcessNamesMap.get(groupKey).add(processName);
+                }
+                
+                // 璁$畻鏃堕棿鐐筀ey
+                String timeKey;
+                LocalDate planStartLocalDate = processPlanStartDay.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+                
+                if ("day".equalsIgnoreCase(timeGranularity)) {
+                    // 鏃ョ矑搴�: 2025-05-25
+                    timeKey = planStartLocalDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
                 } else {
+                    // 鏈堢矑搴�: 2025-05
+                    timeKey = planStartLocalDate.getYear() + "-" + String.format("%02d", planStartLocalDate.getMonthValue());
+                }
+                
+                // 鑾峰彇璇ュ垎缁勭殑鏃堕棿鐐规槧灏勶紝濡傛灉涓嶅瓨鍦ㄥ垯鍒涘缓
+                if (!groupTimeDataMap.containsKey(groupKey)) {
+                    groupTimeDataMap.put(groupKey, new HashMap<>());
+                }
+                Map<String, BigDecimal> timeMap = groupTimeDataMap.get(groupKey);
+                
+                // 绱姞璇ュ垎缁勫湪璇ユ椂闂寸偣鐨勫伐鏃舵暟鎹�
+                BigDecimal processTotalTime = getBigDecimalValue(data, "processTotalTime");
+                if (processTotalTime != null) {
+                    BigDecimal currentTotal = timeMap.getOrDefault(timeKey, BigDecimal.ZERO);
+                    timeMap.put(timeKey, currentTotal.add(processTotalTime));
+                }
+            }
+            
+            // 鏋勫缓鏈�缁堣繑鍥炵殑鏁版嵁缁撴瀯
+            for (String groupKey : groupInfoMap.keySet()) {
+                Map<String, Object> rowEntry = new HashMap<>();
+                Map<String, Object> rowDetail = new HashMap<>();
+                
+                // 鑾峰彇璇ュ垎缁勭殑鍩烘湰淇℃伅
+                Map<String, Object> groupInfo = groupInfoMap.get(groupKey);
+                String rowGroupValue = (String) groupInfo.get(rowGroupBy);
+                
+                // 娣诲姞鍒嗙粍鍩烘湰淇℃伅
+                if (groupByPlant) {
+                    rowDetail.put("plant", groupInfo.get("plant"));
+                }
+                if (groupByMajor) {
+                    rowDetail.put("major", groupInfo.get("major"));
+                }
+                if (groupByWorkshop) {
+                    rowDetail.put("workshop", groupInfo.get("workshop"));
+                }
+                
+                // 澶勭悊processName - 濡傛灉rowGroupBy涓簑orkshop锛屽垯灏嗘墍鏈塸rocessName鐢ㄥ垎鍙疯繛鎺�
+                if ("workshop".equals(rowGroupBy)) {
+                    Set<String> processNames = groupProcessNamesMap.getOrDefault(groupKey, new HashSet<>());
+                    if (!processNames.isEmpty()) {
+                        String joinedProcessNames = String.join(";", processNames);
+                        rowDetail.put("processName", joinedProcessNames);
+                    } else {
+                        rowDetail.put("processName", groupInfo.get("processName"));
+                    }
+                } else if (!"processName".equals(rowGroupBy)) {
+                    // 淇濈暀宸ュ簭鍚嶇О淇℃伅锛屼互渚垮墠绔睍绀�
                     rowDetail.put("processName", groupInfo.get("processName"));
                 }
-            } else if (!"processName".equals(rowGroupBy)) {
-                // 淇濈暀宸ュ簭鍚嶇О淇℃伅锛屼互渚垮墠绔睍绀�
-                rowDetail.put("processName", groupInfo.get("processName"));
+                
+                // 娣诲姞鏃堕棿鏁版嵁
+                List<Map<String, Object>> timeDataList = new ArrayList<>();
+                Map<String, BigDecimal> timeMap = groupTimeDataMap.getOrDefault(groupKey, new HashMap<>());
+                
+                for (String timePoint : timePoints) {
+                    Map<String, Object> pointData = new HashMap<>();
+                    pointData.put("planDay", timePoint);
+                    
+                    // 鑾峰彇璇ユ椂闂寸偣鐨勯渶姹傚伐鏃讹紝濡傛灉涓嶅瓨鍦ㄥ垯璁句负0
+                    BigDecimal requireTimes = timeMap.getOrDefault(timePoint, BigDecimal.ZERO);
+                    pointData.put("requireTimes", requireTimes);
+                    
+                    // 璁捐宸ユ椂鍜屼骇鑳借礋鑽风◢鍚庤绠�
+                    pointData.put("designTimes", 0);
+                    pointData.put("capacityLoad", 0);
+                    
+                    timeDataList.add(pointData);
+                }
+                
+                rowDetail.put("timeData", timeDataList);
+                rowEntry.put(rowGroupValue, rowDetail);
+                plantTable.add(rowEntry);
             }
-            
-            // 娣诲姞鏃堕棿鏁版嵁
-            List<Map<String, Object>> timeDataList = new ArrayList<>();
-            Map<String, BigDecimal> timeMap = groupTimeDataMap.getOrDefault(groupKey, new HashMap<>());
-            
-            for (String timePoint : timePoints) {
-                Map<String, Object> pointData = new HashMap<>();
-                pointData.put("planDay", timePoint);
-                
-                // 鑾峰彇璇ユ椂闂寸偣鐨勯渶姹傚伐鏃讹紝濡傛灉涓嶅瓨鍦ㄥ垯璁句负0
-                BigDecimal requireTimes = timeMap.getOrDefault(timePoint, BigDecimal.ZERO);
-                pointData.put("requireTimes", requireTimes);
-                
-                // 璁捐宸ユ椂鍜屼骇鑳借礋鑽风◢鍚庤绠�
-                pointData.put("designTimes", 0);
-                pointData.put("capacityLoad", 0);
-                
-                timeDataList.add(pointData);
-            }
-            
-            rowDetail.put("timeData", timeDataList);
-            rowEntry.put(rowGroupValue, rowDetail);
-            plantTable.add(rowEntry);
         }
 
         // 鍦ㄨ繑鍥炲墠鏌ヨ璁捐浜ц兘鏁版嵁骞惰绠椾骇鑳借礋鑽�
@@ -1878,6 +1877,135 @@
             });
         }
         
+        // 瀹炵幇娉ㄦ剰鐐�4锛氬綋鏃堕棿棰楃矑搴︿负"鏃�"鏃讹紝纭繚娌℃湁鏁版嵁鐨勫伐鍘備篃杩斿洖瀹屾暣缁撴瀯
+        if ("day".equalsIgnoreCase(timeGranularity) && params.containsKey("plant")) {
+            // 鑾峰彇璇锋眰涓殑宸ュ巶鍒楄〃
+            List<String> requestedPlants = new ArrayList<>();
+            Object plantParam = params.get("plant");
+            if (plantParam instanceof List) {
+                requestedPlants.addAll((List<String>) plantParam);
+            } else if (plantParam instanceof String) {
+                String plantStr = (String) plantParam;
+                if (plantStr.contains(",")) {
+                    requestedPlants.addAll(Arrays.asList(plantStr.split(",")));
+                } else {
+                    requestedPlants.add(plantStr);
+                }
+            }
+            
+            if (!requestedPlants.isEmpty()) {
+                // 妫�鏌ュ摢浜涘伐鍘傛病鏈夋暟鎹�
+                Set<String> plantsWithData = new HashSet<>();
+                for (Map<String, Object> rowEntry : plantTable) {
+                    for (String rowKey : rowEntry.keySet()) {
+                        Map<String, Object> rowDetail = (Map<String, Object>) rowEntry.get(rowKey);
+                        if (rowDetail.containsKey("plant")) {
+                            plantsWithData.add((String) rowDetail.get("plant"));
+                        }
+                    }
+                }
+                
+                // 鎵惧嚭娌℃湁鏁版嵁鐨勫伐鍘�
+                List<String> plantsWithoutData = requestedPlants.stream()
+                        .filter(plant -> !plantsWithData.contains(plant))
+                        .collect(Collectors.toList());
+                
+                if (!plantsWithoutData.isEmpty()) {
+                    // 鑾峰彇鎵�鏈夊幓閲嶇殑processName鎴杦orkshop
+                    List<String> allUniqueValues;
+                    if ("processName".equals(rowGroupBy)) {
+                        allUniqueValues = apsGasPipingRouteStatMapper.selectDistinctProcessNames();
+                    } else if ("workshop".equals(rowGroupBy)) {
+                        allUniqueValues = apsGasPipingRouteStatMapper.selectDistinctWorkshops();
+                    } else {
+                        // 濡傛灉rowGroupBy涓嶆槸processName鎴杦orkshop锛岃烦杩囧鐞�
+                        return result;
+                    }
+                    
+                    // 涓烘瘡涓病鏈夋暟鎹殑宸ュ巶鍒涘缓绌烘暟鎹粨鏋�
+                    for (String plant : plantsWithoutData) {
+                        for (String uniqueValue : allUniqueValues) {
+                            if (uniqueValue == null || uniqueValue.trim().isEmpty()) {
+                                continue;
+                            }
+                            
+                            // 妫�鏌ユ槸鍚﹀凡缁忓瓨鍦ㄨ繖涓��
+                            boolean exists = false;
+                            for (Map<String, Object> entry : plantTable) {
+                                if (entry.containsKey(uniqueValue)) {
+                                    Map<String, Object> detail = (Map<String, Object>) entry.get(uniqueValue);
+                                    String existingPlant = detail.containsKey("plant") ? (String) detail.get("plant") : "";
+                                    if (plant.equals(existingPlant)) {
+                                        exists = true;
+                                        break;
+                                    }
+                                }
+                            }
+                            
+                            // 濡傛灉涓嶅瓨鍦紝鍒涘缓鏂扮殑绌烘暟鎹粨鏋�
+                            if (!exists) {
+                                Map<String, Object> rowEntry = new HashMap<>();
+                                Map<String, Object> rowDetail = new HashMap<>();
+                                
+                                // 璁剧疆鍩烘湰淇℃伅
+                                rowDetail.put("plant", plant);
+                                if (groupByMajor) {
+                                    rowDetail.put("major", "");
+                                }
+                                if (groupByWorkshop && !"workshop".equals(rowGroupBy)) {
+                                    rowDetail.put("workshop", "");
+                                }
+                                
+                                // 澶勭悊processName - 濡傛灉rowGroupBy涓簑orkshop锛岄渶瑕佽缃┖鐨刾rocessName
+                                if ("workshop".equals(rowGroupBy)) {
+                                    rowDetail.put("processName", "");
+                                }
+                                
+                                // 涓烘瘡涓椂闂寸偣鍒涘缓闆跺�兼暟鎹�
+                                List<Map<String, Object>> timeDataList = new ArrayList<>();
+                                for (String timePoint : timePoints) {
+                                    Map<String, Object> pointData = new HashMap<>();
+                                    pointData.put("planDay", timePoint);
+                                    pointData.put("requireTimes", BigDecimal.ZERO);
+                                    pointData.put("designTimes", BigDecimal.ZERO);
+                                    pointData.put("capacityLoad", BigDecimal.ZERO);
+                                    timeDataList.add(pointData);
+                                }
+                                
+                                rowDetail.put("timeData", timeDataList);
+                                rowEntry.put(uniqueValue, rowDetail);
+                                plantTable.add(rowEntry);
+                            }
+                        }
+                    }
+                    
+                    // 閲嶆柊鎺掑簭缁撴灉
+                    Collections.sort(plantTable, (map1, map2) -> {
+                        String key1 = map1.keySet().iterator().next();
+                        String key2 = map2.keySet().iterator().next();
+                        
+                        // 棣栧厛鎸塺owGroupBy鎺掑簭锛坧rocessName鎴杦orkshop锛�
+                        int result1 = key1.compareTo(key2);
+                        if (result1 != 0) {
+                            return result1;
+                        }
+                        
+                        // 濡傛灉rowGroupBy鐩稿悓锛屽啀鎸塸lant鎺掑簭
+                        Map<String, Object> detail1 = (Map<String, Object>) map1.get(key1);
+                        Map<String, Object> detail2 = (Map<String, Object>) map2.get(key2);
+                        
+                        String plant1 = detail1.containsKey("plant") ? (String) detail1.get("plant") : "";
+                        String plant2 = detail2.containsKey("plant") ? (String) detail2.get("plant") : "";
+                        
+                        return plant1.compareTo(plant2);
+                    });
+                    
+                    // 鏇存柊缁撴灉
+                    result.put("plantTable", plantTable);
+                }
+            }
+        }
+        
         return result;
     }
     

--
Gitblit v1.9.3