From 7c266bff815ebed897e51f401ef5987629d77c44 Mon Sep 17 00:00:00 2001
From: sfd <sun.sunshine@163.com>
Date: 星期三, 21 五月 2025 11:08:29 +0800
Subject: [PATCH] 修改管路预测与物料产品组导入功能 根据工厂及料号更新与插入

---
 aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelinePredictionServiceImpl.java |   76 ++++++++++++++++++++++++--------------
 1 files changed, 48 insertions(+), 28 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 cf3d710..f6e3a61 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
@@ -4,8 +4,10 @@
 import com.aps.common.core.utils.DateUtils;
 import com.aps.common.security.utils.SecurityUtils;
 import com.aps.core.domain.ApsGasPipelinePrediction;
+import com.aps.core.domain.ApsMaterialProductGroupManagement;
 import com.aps.core.mapper.ApsGasPipelinePredictionMapper;
 import com.aps.core.service.IApsGasPipelinePredictionService;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import io.micrometer.common.util.StringUtils;
 import lombok.SneakyThrows;
 import org.apache.poi.ss.usermodel.Row;
@@ -18,93 +20,86 @@
 
 import java.math.BigDecimal;
 import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁Service涓氬姟灞傚鐞�
- * 
+ *
  * @author ruoyi
  * @date 2025-05-19
  */
 @Service
-public class ApsGasPipelinePredictionServiceImpl implements IApsGasPipelinePredictionService
-{
+public class ApsGasPipelinePredictionServiceImpl implements IApsGasPipelinePredictionService {
     @Autowired
     private ApsGasPipelinePredictionMapper apsGasPipelinePredictionMapper;
 
     /**
      * 鏌ヨ绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁
-     * 
+     *
      * @param id 绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁涓婚敭
      * @return 绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁
      */
     @Override
-    public ApsGasPipelinePrediction selectApsGasPipelinePredictionById(Long id)
-    {
+    public ApsGasPipelinePrediction selectApsGasPipelinePredictionById(Long id) {
         return apsGasPipelinePredictionMapper.selectApsGasPipelinePredictionById(id);
     }
 
     /**
      * 鏌ヨ绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁鍒楄〃
-     * 
+     *
      * @param apsGasPipelinePrediction 绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁
      * @return 绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁
      */
     @Override
-    public List<ApsGasPipelinePrediction> selectApsGasPipelinePredictionList(ApsGasPipelinePrediction apsGasPipelinePrediction)
-    {
+    public List<ApsGasPipelinePrediction> selectApsGasPipelinePredictionList(ApsGasPipelinePrediction apsGasPipelinePrediction) {
         return apsGasPipelinePredictionMapper.selectApsGasPipelinePredictionList(apsGasPipelinePrediction);
     }
 
     /**
      * 鏂板绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁
-     * 
+     *
      * @param apsGasPipelinePrediction 绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁
      * @return 缁撴灉
      */
     @Override
-    public int insertApsGasPipelinePrediction(ApsGasPipelinePrediction apsGasPipelinePrediction)
-    {
+    public int insertApsGasPipelinePrediction(ApsGasPipelinePrediction apsGasPipelinePrediction) {
         apsGasPipelinePrediction.setCreateTime(DateUtils.getNowDate());
         return apsGasPipelinePredictionMapper.insertApsGasPipelinePrediction(apsGasPipelinePrediction);
     }
 
     /**
      * 淇敼绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁
-     * 
+     *
      * @param apsGasPipelinePrediction 绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁
      * @return 缁撴灉
      */
     @Override
-    public int updateApsGasPipelinePrediction(ApsGasPipelinePrediction apsGasPipelinePrediction)
-    {
+    public int updateApsGasPipelinePrediction(ApsGasPipelinePrediction apsGasPipelinePrediction) {
         apsGasPipelinePrediction.setUpdateTime(DateUtils.getNowDate());
         return apsGasPipelinePredictionMapper.updateApsGasPipelinePrediction(apsGasPipelinePrediction);
     }
 
     /**
      * 鎵归噺鍒犻櫎绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁
-     * 
+     *
      * @param ids 闇�瑕佸垹闄ょ殑绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁涓婚敭
      * @return 缁撴灉
      */
     @Override
-    public int deleteApsGasPipelinePredictionByIds(Long[] ids)
-    {
+    public int deleteApsGasPipelinePredictionByIds(Long[] ids) {
         return apsGasPipelinePredictionMapper.deleteApsGasPipelinePredictionByIds(ids);
     }
 
     /**
      * 鍒犻櫎绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁淇℃伅
-     * 
+     *
      * @param id 绠¤矾鎵嬪伐姘斾綋棰勬祴鏁版嵁涓婚敭
      * @return 缁撴灉
      */
     @Override
-    public int deleteApsGasPipelinePredictionById(Long id)
-    {
+    public int deleteApsGasPipelinePredictionById(Long id) {
         return apsGasPipelinePredictionMapper.deleteApsGasPipelinePredictionById(id);
     }
 
@@ -121,12 +116,12 @@
             /*鏁版嵁鍒椾粠1寮�濮�*/
             for (int i = 1; i <= rows; i++) {
                 Row row = sheet.getRow(i);
-                if (row.getCell(0) == null){
+                if (row.getCell(0) == null) {
                     continue;
                 }
 
                 String materialCode = row.getCell(0).getStringCellValue();
-                if (StringUtils.isEmpty(materialCode)){
+                if (StringUtils.isEmpty(materialCode)) {
                     continue;
                 }
                 String factory = row.getCell(1).getStringCellValue();
@@ -146,8 +141,33 @@
                 }
             }
             if (!list.isEmpty()) {
-                apsGasPipelinePredictionMapper.deleteAll();
-                apsGasPipelinePredictionMapper.insert(list);
+
+                List<Map<String, Object>> facCodeKey = apsGasPipelinePredictionMapper.selectByFacOrMaterial(
+                        list.stream().map(ApsGasPipelinePrediction::getFactory).collect(Collectors.toSet()),
+                        list.stream().map(ApsGasPipelinePrediction::getMaterialCode).collect(Collectors.toSet())
+                );
+                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();
+                                });
+                    }
+                }
+                if (!list.isEmpty()) {
+                    apsGasPipelinePredictionMapper.insert(list);
+                }
             }
             return list.size();
         }

--
Gitblit v1.9.3