From b60b39fc30384a1fa75765e8e10f9ad3bffe9480 Mon Sep 17 00:00:00 2001
From: sfd <sun.sunshine@163.com>
Date: 星期五, 23 五月 2025 15:15:34 +0800
Subject: [PATCH] Update ApsStandardProcessController.java
---
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java | 233 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 229 insertions(+), 4 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..53dd3b5 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,9 +1489,61 @@
// 鏌ヨ鍘熷鏁版嵁锛堜笉渚濊禆鏁版嵁搴撹仛鍚堬級
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);
+ }
+
result.put("plantTable", plantTable);
result.put("timePoints", timePoints);
+ result.put("rowGroupBy", rowGroupBy);
+
return result;
}
@@ -1499,6 +1551,8 @@
// 浣跨敤缁勫悎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) {
@@ -1550,6 +1604,14 @@
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();
@@ -1596,8 +1658,17 @@
rowDetail.put("workshop", groupInfo.get("workshop"));
}
- // 淇濈暀宸ュ簭鍚嶇О淇℃伅锛屼互渚垮墠绔睍绀�
- if (!"processName".equals(rowGroupBy)) {
+ // 澶勭悊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"));
}
@@ -1608,13 +1679,13 @@
for (String timePoint : timePoints) {
Map<String, Object> pointData = new HashMap<>();
pointData.put("planDay", timePoint);
- pointData.put("designTimes", 0); // 璁捐宸ユ椂鏆傛椂缁�0
// 鑾峰彇璇ユ椂闂寸偣鐨勯渶姹傚伐鏃讹紝濡傛灉涓嶅瓨鍦ㄥ垯璁句负0
BigDecimal requireTimes = timeMap.getOrDefault(timePoint, BigDecimal.ZERO);
pointData.put("requireTimes", requireTimes);
- // 璁$畻浜ц兘璐熻嵎锛堟殏鏃朵负0锛�
+ // 璁捐宸ユ椂鍜屼骇鑳借礋鑽风◢鍚庤绠�
+ pointData.put("designTimes", 0);
pointData.put("capacityLoad", 0);
timeDataList.add(pointData);
@@ -1625,6 +1696,160 @@
plantTable.add(rowEntry);
}
+ // 鍦ㄨ繑鍥炲墠鏌ヨ璁捐浜ц兘鏁版嵁骞惰绠椾骇鑳借礋鑽�
+ 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");
+
+ // 鑾峰彇鍩烘湰淇℃伅
+ 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;
+
+ // 澶勭悊涓嶅悓鐨剅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, null, 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, null, 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);
+ }
+ }
+ }
+ }
+ }
+
result.put("plantTable", plantTable);
result.put("timePoints", timePoints);
result.put("rowGroupBy", rowGroupBy);
--
Gitblit v1.9.3