From 26c8536e1a95b91b7763afccd3c4a7dec9e5f5dc Mon Sep 17 00:00:00 2001
From: hongjli <3117313295@qq.com>
Date: 星期五, 23 五月 2025 12:24:30 +0800
Subject: [PATCH] 管路&气柜产能负载补充对designTimes的取值

---
 aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java |  158 +++++++++++++++++++++++++++++++++++++++
 aps-modules/aps-core/src/main/resources/mapper/core/ApsGasPipelineCapacityPlanMapper.xml           |   22 +++++
 aps-modules/aps-core/src/main/java/com/aps/core/mapper/ApsGasPipelineCapacityPlanMapper.java       |   18 ++++
 3 files changed, 196 insertions(+), 2 deletions(-)

diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/mapper/ApsGasPipelineCapacityPlanMapper.java b/aps-modules/aps-core/src/main/java/com/aps/core/mapper/ApsGasPipelineCapacityPlanMapper.java
index 22ddc1c..c19b6a8 100644
--- a/aps-modules/aps-core/src/main/java/com/aps/core/mapper/ApsGasPipelineCapacityPlanMapper.java
+++ b/aps-modules/aps-core/src/main/java/com/aps/core/mapper/ApsGasPipelineCapacityPlanMapper.java
@@ -3,6 +3,7 @@
 import com.aps.core.domain.ApsGasPipelineCapacityPlan;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -30,6 +31,23 @@
      * @return 姘斾綋绠¤矾浜ц兘瑙勫垝闆嗗悎
      */
     public List<ApsGasPipelineCapacityPlan> selectApsGasPipelineCapacityPlanList(ApsGasPipelineCapacityPlan apsGasPipelineCapacityPlan);
+    
+    /**
+     * 鏌ヨ璁捐浜ц兘鏁版嵁 - 涓撶敤浜庢帴鍙d簩鍔熻兘
+     * 
+     * @param processName 宸ュ簭鍚嶇О
+     * @param year 骞翠唤
+     * @param month 鏈堜唤
+     * @param major 涓撲笟
+     * @param orgCode 宸ュ巶浠g爜
+     * @return 姘斾綋绠¤矾浜ц兘瑙勫垝闆嗗悎
+     */
+    public List<ApsGasPipelineCapacityPlan> selectDesignCapacityForInterface2(
+            @Param("processName") String processName,
+            @Param("year") String year,
+            @Param("month") String month,
+            @Param("major") String major,
+            @Param("orgCode") String orgCode);
 
     /**
      * 鏂板姘斾綋绠¤矾浜ц兘瑙勫垝
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 247add4..49878d5 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
@@ -1627,13 +1627,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);
@@ -1644,6 +1644,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鍜宮ajor銆乸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銆乵ajor銆乸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);
+                        }
+                    }
+                }
+            }
+        }
+
         result.put("plantTable", plantTable);
         result.put("timePoints", timePoints);
         result.put("rowGroupBy", rowGroupBy);
diff --git a/aps-modules/aps-core/src/main/resources/mapper/core/ApsGasPipelineCapacityPlanMapper.xml b/aps-modules/aps-core/src/main/resources/mapper/core/ApsGasPipelineCapacityPlanMapper.xml
index 5c16e41..9cf0dc8 100644
--- a/aps-modules/aps-core/src/main/resources/mapper/core/ApsGasPipelineCapacityPlanMapper.xml
+++ b/aps-modules/aps-core/src/main/resources/mapper/core/ApsGasPipelineCapacityPlanMapper.xml
@@ -146,4 +146,26 @@
                    and org_code = #{factory}
                    and major = #{major}
     </delete>
+    
+    <!-- 鏌ヨ璁捐浜ц兘鏁版嵁 - 涓撶敤浜庢帴鍙d簩鍔熻兘 -->
+    <select id="selectDesignCapacityForInterface2" resultMap="ApsGasPipelineCapacityPlanResult">
+        <include refid="selectApsGasPipelineCapacityPlanVo"/>
+        <where>
+            <if test="processName != null and processName != ''">
+                and process_name = #{processName}
+            </if>
+            <if test="year != null and year != ''">
+                and year = #{year}
+            </if>
+            <if test="month != null and month != ''">
+                and CAST(month AS INTEGER) = CAST(#{month} AS INTEGER)
+            </if>
+            <if test="major != null and major != ''">
+                and major = #{major}
+            </if>
+            <if test="orgCode != null and orgCode != ''">
+                and org_code = #{orgCode}
+            </if>
+        </where>
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.3