From bc0fdd1f0c20ca4737e8f073050f37b27a658694 Mon Sep 17 00:00:00 2001
From: hongjli <3117313295@qq.com>
Date: 星期四, 22 五月 2025 16:31:12 +0800
Subject: [PATCH] 管路&气柜产能负载优化,实现动态row聚合统计

---
 aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelinePredictionServiceImpl.java |   46 ++++++++++++++++++++++++----------------------
 1 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelinePredictionServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelinePredictionServiceImpl.java
index f6e3a61..f4715e4 100644
--- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelinePredictionServiceImpl.java
+++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelinePredictionServiceImpl.java
@@ -22,6 +22,7 @@
 import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
 /**
@@ -112,9 +113,9 @@
         int rows = sheet.getLastRowNum();
         if (rows > 0) {
             List<ApsGasPipelinePrediction> list = new ArrayList<>();
-
-            /*鏁版嵁鍒椾粠1寮�濮�*/
-            for (int i = 1; i <= rows; i++) {
+            Set<String> keys = new HashSet<>();
+            /*鏁版嵁琛屼粠1寮�濮�*/
+            for (int i = rows; i > 0; --i) {
                 Row row = sheet.getRow(i);
                 if (row.getCell(0) == null) {
                     continue;
@@ -137,32 +138,33 @@
                     item.setCreateTime(DateUtils.getNowDate());
                     item.setPredictQuantity(new BigDecimal(quantity));
                     item.setPredictDate(new Timestamp(date.getTime()));
-                    list.add(item);
+                    if (!keys.contains(item.getKey())) {
+                        keys.add(item.getKey());
+                        list.add(item);
+                    }
                 }
             }
             if (!list.isEmpty()) {
-
-                List<Map<String, Object>> facCodeKey = apsGasPipelinePredictionMapper.selectByFacOrMaterial(
-                        list.stream().map(ApsGasPipelinePrediction::getFactory).collect(Collectors.toSet()),
-                        list.stream().map(ApsGasPipelinePrediction::getMaterialCode).collect(Collectors.toSet())
-                );
+                List<Map<String, Object>> facCodeKey = apsGasPipelinePredictionMapper.selectByFacOrMaterial(keys);
                 if (!facCodeKey.isEmpty()) {
-                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                     Iterator<ApsGasPipelinePrediction> it = list.iterator();
                     while (it.hasNext()) {
                         ApsGasPipelinePrediction item = it.next();
-                        String key = item.getFactory() + "##" + item.getMaterialCode() + "##" + sdf.format(item.getPredictDate());
-                        facCodeKey.stream()
-                                .filter(map -> map.get("key").equals(key))
-                                .forEach(row -> {
-                                    item.setId((Long) row.get("id"));
-                                    item.setCreateBy(null);
-                                    item.setCreateTime(null);
-                                    item.setUpdateBy(SecurityUtils.getUsername());
-                                    item.setUpdateTime(new Timestamp(System.currentTimeMillis()));
-                                    apsGasPipelinePredictionMapper.updateById(item);
-                                    it.remove();
-                                });
+                        int count = 0;
+                        for (Map<String, Object> map : facCodeKey) {
+                            if (map.get("key").equals(item.getKey())) {
+                                item.setId((Long) map.get("id"));
+                                item.setCreateBy(null);
+                                item.setCreateTime(null);
+                                item.setUpdateBy(SecurityUtils.getUsername());
+                                item.setUpdateTime(new Timestamp(System.currentTimeMillis()));
+                                apsGasPipelinePredictionMapper.updateById(item);
+                                count++;
+                            }
+                        }
+                        if (count > 0){
+                            it.remove();
+                        }
                     }
                 }
                 if (!list.isEmpty()) {

--
Gitblit v1.9.3