From 2a64b537e8e3bce9ce030585a3da17d48379c0ad Mon Sep 17 00:00:00 2001
From: sfd <sun.sunshine@163.com>
Date: 星期一, 26 五月 2025 15:04:45 +0800
Subject: [PATCH] 修改json类型转换错误
---
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java | 625 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 501 insertions(+), 124 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 ce61324..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
@@ -1489,146 +1489,523 @@
// 鏌ヨ鍘熷鏁版嵁锛堜笉渚濊禆鏁版嵁搴撹仛鍚堬級
List<Map<String, Object>> rawData = apsGasPipingRouteStatMapper.selectRawStatData(queryParams);
+ // 濡傛灉娌℃湁鏌ヨ鍒板師濮嬫暟鎹紝浣嗛渶瑕佽繑鍥炴墍鏈夊伐搴�/杞﹂棿鐨勬暟鎹�
if (rawData.isEmpty()) {
+ // 鍒涘缓娌℃湁鏃堕棿闄愬埗鐨勫熀纭�鏌ヨ鍙傛暟
+ Map<String, Object> baseParams = new HashMap<>(queryParams);
+ baseParams.remove("yearStart");
+ baseParams.remove("monthStart");
+ baseParams.remove("yearEnd");
+ baseParams.remove("monthEnd");
+
+ // 鐩存帴浠巃ps_gas_piping_route_stat琛ㄦ煡璇㈡墍鏈夊彲鑳界殑宸ュ簭鍜岃溅闂�
+ List<Map<String, Object>> baseData = apsGasPipingRouteStatMapper.selectBaseStatData(baseParams);
+
+ // 涓烘瘡涓伐搴�/杞﹂棿鍒涘缓鍩轰簬鏃堕棿鐨勭┖鏁版嵁
+ for (Map<String, Object> data : baseData) {
+ String rowGroupValue = getStringValue(data, rowGroupBy);
+ if (rowGroupValue == null || rowGroupValue.trim().isEmpty()) continue;
+
+ Map<String, Object> rowEntry = new HashMap<>();
+ Map<String, Object> rowDetail = new HashMap<>();
+
+ // 娣诲姞鍩烘湰淇℃伅
+ String plant = getStringValue(data, "plant");
+ String major = getStringValue(data, "major");
+ String workshop = getStringValue(data, "workshop");
+
+ if (groupByPlant) rowDetail.put("plant", plant);
+ if (groupByMajor) rowDetail.put("major", major);
+ if (groupByWorkshop) rowDetail.put("workshop", workshop);
+
+ // 澶勭悊宸ュ簭鍚嶇О - 濡傛灉rowGroupBy涓簑orkshop锛岄渶瑕佹坊鍔爌rocessName瀛楁
+ if ("workshop".equals(rowGroupBy)) {
+ String processName = getStringValue(data, "processName");
+ rowDetail.put("processName", processName != null ? 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(rowGroupValue, rowDetail);
+ plantTable.add(rowEntry);
+ }
+
+ // 鏇存柊缁撴灉浣嗕笉鐩存帴杩斿洖锛岀户缁墽琛屽悗缁敞鎰忕偣4鐨勫鐞�
result.put("plantTable", plantTable);
result.put("timePoints", timePoints);
- return result;
- }
-
- // 鍦⊿ervice灞傚畬鎴愯仛鍚�
- // 浣跨敤缁勫悎key鏉ュ疄鐜板缁村害鍒嗙粍锛堝姩鎬乺owGroupBy瀛楁 + 鍙�夌殑宸ュ巶/涓撲笟/杞﹂棿锛�
- Map<String, Map<String, Object>> groupInfoMap = new HashMap<>();
- Map<String, Map<String, BigDecimal>> groupTimeDataMap = new HashMap<>();
-
- // 閬嶅巻鍘熷鏁版嵁锛屾寜澶氱淮搴﹀垎缁勮繘琛岃仛鍚�
- for (Map<String, Object> data : rawData) {
- // 鑾峰彇琛屽垎缁勫瓧娈靛��
- String rowGroupValue = getStringValue(data, rowGroupBy);
- if (rowGroupValue == null || rowGroupValue.trim().isEmpty()) {
- log.warn("璺宠繃澶勭悊锛歿} 瀛楁鍊间负绌�", rowGroupBy);
- continue;
+ 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<>();
+
+ // 閬嶅巻鍘熷鏁版嵁锛屾寜澶氱淮搴﹀垎缁勮繘琛岃仛鍚�
+ 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<>());
+ }
+ 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));
+ }
}
- // 鑾峰彇宸ュ簭鍚嶇О锛堢敤浜庢棩蹇楀拰鍚庣画澶勭悊锛�
- 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);
- }
-
- // 璁$畻鏃堕棿鐐筀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"));
+ }
+
+ // 娣诲姞鏃堕棿鏁版嵁
+ 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);
}
}
-
- // 鏋勫缓鏈�缁堣繑鍥炵殑鏁版嵁缁撴瀯
- 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"));
- }
-
- // 淇濈暀宸ュ簭鍚嶇О淇℃伅锛屼互渚垮墠绔睍绀�
- 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);
- pointData.put("designTimes", 0); // 璁捐宸ユ椂鏆傛椂缁�0
+
+ // 鍦ㄨ繑鍥炲墠鏌ヨ璁捐浜ц兘鏁版嵁骞惰绠椾骇鑳借礋鑽�
+ for (Map<String, Object> rowEntry : plantTable) {
+ for (String rowKey : rowEntry.keySet()) {
+ Map<String, Object> rowDetail = (Map<String, Object>) rowEntry.get(rowKey);
+ List<Map<String, Object>> timeDataList = (List<Map<String, Object>>) rowDetail.get("timeData");
- // 鑾峰彇璇ユ椂闂寸偣鐨勯渶姹傚伐鏃讹紝濡傛灉涓嶅瓨鍦ㄥ垯璁句负0
- BigDecimal requireTimes = timeMap.getOrDefault(timePoint, BigDecimal.ZERO);
- pointData.put("requireTimes", requireTimes);
+ // 鑾峰彇鍩烘湰淇℃伅
+ String plant = rowDetail.containsKey("plant") ? (String) rowDetail.get("plant") : null;
+ String major = rowDetail.containsKey("major") ? (String) rowDetail.get("major") : null;
+ String workshop = rowDetail.containsKey("workshop") ? (String) rowDetail.get("workshop") : null;
- // 璁$畻浜ц兘璐熻嵎锛堟殏鏃朵负0锛�
- pointData.put("capacityLoad", 0);
-
- timeDataList.add(pointData);
+ // 澶勭悊涓嶅悓鐨剅owGroupBy鎯呭喌
+ if ("workshop".equals(rowGroupBy) && rowDetail.containsKey("processName")) {
+ // 鎯呭喌1: 鎸墂orkshop鑱氬悎锛岄渶瑕佹媶鍒唒rocessName瀛楁
+ String processNamesStr = (String) rowDetail.get("processName");
+ String[] processNames = processNamesStr.split(";");
+
+ // 浼樺寲鏌ヨ - 鍒涘缓缂撳瓨锛屾寜鏈堜唤缂撳瓨鏌ヨ缁撴灉
+ // Key: year-month-processName, Value: 鏌ヨ缁撴灉鍒楄〃
+ Map<String, List<ApsGasPipelineCapacityPlan>> capacityPlanCache = new HashMap<>();
+
+ // 閬嶅巻姣忎釜鏃堕棿鐐�
+ for (Map<String, Object> timeData : timeDataList) {
+ String planDay = (String) timeData.get("planDay");
+ BigDecimal requireTimes = new BigDecimal(timeData.get("requireTimes").toString());
+ BigDecimal totalDesignTimes = BigDecimal.ZERO;
+
+ // 鎷嗗垎骞存湀鏃�
+ String[] dateParts = planDay.split("-");
+ String year = dateParts[0];
+ String month = dateParts[1];
+ // 缁熶竴month鏍煎紡涓烘暣鏁板瓧绗︿覆锛屽幓鎺夊墠瀵奸浂
+ month = String.valueOf(Integer.parseInt(month));
+ String yearMonth = year + "-" + month;
+
+ // 绱姞澶氫釜宸ュ簭鐨勮璁′骇鑳�
+ for (String processName : processNames) {
+ // 鏋勫缓缂撳瓨閿�
+ String cacheKey = yearMonth + "-" + processName.trim();
+
+ // 浠庣紦瀛樿幏鍙栨垨鏌ヨ鏁版嵁
+ List<ApsGasPipelineCapacityPlan> capacityPlans;
+ if (capacityPlanCache.containsKey(cacheKey)) {
+ capacityPlans = capacityPlanCache.get(cacheKey);
+ } else {
+ // 浣跨敤涓撶敤鏌ヨ鏂规硶鏌ヨ璁捐浜ц兘鏁版嵁
+ // 鎸夋枃妗h姹傦細鏍规嵁process_name鍜宲lant鍘籥ps_gas_pipeline_capacity_plan琛ㄤ腑鏌ヨ
+ capacityPlans = apsGasPipelineCapacityPlanMapper.selectDesignCapacityForInterface2(
+ processName.trim(), year, month, major, plant);
+
+ // 灏嗙粨鏋滃瓨鍏ョ紦瀛�
+ capacityPlanCache.put(cacheKey, capacityPlans);
+ }
+
+ // 绱姞璁捐浜ц兘鍊�
+ for (ApsGasPipelineCapacityPlan plan : capacityPlans) {
+ if ("day".equalsIgnoreCase(timeGranularity)) {
+ // 鏃ョ矑搴︿娇鐢ㄦ棩浜у嚭鏁伴噺
+ if (plan.getDayProduceAllNum() != null) {
+ totalDesignTimes = totalDesignTimes.add(plan.getDayProduceAllNum());
+ }
+ } else {
+ // 鏈堢矑搴︿娇鐢ㄦ湀浜у嚭鎬绘暟閲�
+ if (plan.getMonthProduceAllNum() != null) {
+ totalDesignTimes = totalDesignTimes.add(plan.getMonthProduceAllNum());
+ }
+ }
+ }
+ }
+
+ // 鏇存柊璁捐宸ユ椂
+ timeData.put("designTimes", totalDesignTimes);
+
+ // 璁$畻浜ц兘璐熻嵎 = 闇�姹備骇鑳�/璁捐浜ц兘脳100%
+ if (totalDesignTimes.compareTo(BigDecimal.ZERO) > 0) {
+ BigDecimal capacityLoad = requireTimes
+ .divide(totalDesignTimes, 2, RoundingMode.HALF_UP)
+ .multiply(new BigDecimal(100));
+ timeData.put("capacityLoad", capacityLoad);
+ } else {
+ timeData.put("capacityLoad", 0);
+ }
+ }
+ } else {
+ // 鎯呭喌2: 鎸塸rocessName鎴栧叾浠栧瓧娈佃仛鍚�
+ String processName = rowDetail.containsKey("processName") ?
+ (String) rowDetail.get("processName") : rowKey;
+
+ // 浼樺寲鏌ヨ - 鍒涘缓缂撳瓨锛屾寜鏈堜唤缂撳瓨鏌ヨ缁撴灉
+ Map<String, List<ApsGasPipelineCapacityPlan>> capacityPlanCache = new HashMap<>();
+
+ // 閬嶅巻姣忎釜鏃堕棿鐐�
+ for (Map<String, Object> timeData : timeDataList) {
+ String planDay = (String) timeData.get("planDay");
+ BigDecimal requireTimes = new BigDecimal(timeData.get("requireTimes").toString());
+
+ // 鎷嗗垎骞存湀鏃�
+ String[] dateParts = planDay.split("-");
+ String year = dateParts[0];
+ String month = dateParts[1];
+ // 缁熶竴month鏍煎紡涓烘暣鏁板瓧绗︿覆锛屽幓鎺夊墠瀵奸浂
+ month = String.valueOf(Integer.parseInt(month));
+ String yearMonth = year + "-" + month;
+
+ // 鏋勫缓缂撳瓨閿�
+ String cacheKey = yearMonth + "-" + processName;
+
+ // 浠庣紦瀛樿幏鍙栨垨鏌ヨ鏁版嵁
+ List<ApsGasPipelineCapacityPlan> capacityPlans;
+ if (capacityPlanCache.containsKey(cacheKey)) {
+ capacityPlans = capacityPlanCache.get(cacheKey);
+ } else {
+ // 浣跨敤涓撶敤鏌ヨ鏂规硶鏌ヨ璁捐浜ц兘鏁版嵁
+ // 鎸夋枃妗h姹傦細鏍规嵁process_name鍜宲lant鍘籥ps_gas_pipeline_capacity_plan琛ㄤ腑鏌ヨ
+ capacityPlans = apsGasPipelineCapacityPlanMapper.selectDesignCapacityForInterface2(
+ processName, year, month, major, plant);
+
+ // 灏嗙粨鏋滃瓨鍏ョ紦瀛�
+ capacityPlanCache.put(cacheKey, capacityPlans);
+ }
+
+ // 绱姞璁捐浜ц兘鍊�
+ BigDecimal totalDesignTimes = BigDecimal.ZERO;
+ for (ApsGasPipelineCapacityPlan plan : capacityPlans) {
+ if ("day".equalsIgnoreCase(timeGranularity)) {
+ // 鏃ョ矑搴︿娇鐢ㄦ棩浜у嚭鏁伴噺
+ if (plan.getDayProduceAllNum() != null) {
+ totalDesignTimes = totalDesignTimes.add(plan.getDayProduceAllNum());
+ }
+ } else {
+ // 鏈堢矑搴︿娇鐢ㄦ湀浜у嚭鎬绘暟閲�
+ if (plan.getMonthProduceAllNum() != null) {
+ totalDesignTimes = totalDesignTimes.add(plan.getMonthProduceAllNum());
+ }
+ }
+ }
+
+ // 鏇存柊璁捐宸ユ椂
+ timeData.put("designTimes", totalDesignTimes);
+
+ // 璁$畻浜ц兘璐熻嵎 = 闇�姹備骇鑳�/璁捐浜ц兘脳100%
+ if (totalDesignTimes.compareTo(BigDecimal.ZERO) > 0) {
+ BigDecimal capacityLoad = requireTimes
+ .divide(totalDesignTimes, 2, RoundingMode.HALF_UP)
+ .multiply(new BigDecimal(100));
+ timeData.put("capacityLoad", capacityLoad);
+ } else {
+ timeData.put("capacityLoad", 0);
+ }
+ }
+ }
}
-
- rowDetail.put("timeData", timeDataList);
- rowEntry.put(rowGroupValue, rowDetail);
- plantTable.add(rowEntry);
}
result.put("plantTable", plantTable);
result.put("timePoints", timePoints);
result.put("rowGroupBy", rowGroupBy);
+ // 鏍规嵁鏂囨。娉ㄦ剰鐐�3锛屾坊鍔犳帓搴忛�昏緫
+ if (!plantTable.isEmpty()) {
+ // 瀵硅仛鍚堢粨鏋滆繘琛屾帓搴�
+ 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);
+ });
+ }
+
+ // 瀹炵幇娉ㄦ剰鐐�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