From 6da289fff756eaecc600422d77c4afff1ddebab0 Mon Sep 17 00:00:00 2001
From: zhanghl <253316343@qq.com>
Date: 星期五, 23 五月 2025 15:23:50 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelinePredictionServiceImpl.java |  112 +++++++++++++++++++++----------------------------------
 1 files changed, 43 insertions(+), 69 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 f4715e4..c9f6153 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
@@ -2,27 +2,19 @@
 
 import cn.hutool.core.util.IdUtil;
 import com.aps.common.core.utils.DateUtils;
+import com.aps.common.core.utils.poi.ExcelUtil;
+import com.aps.common.security.utils.DictUtils;
 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;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.math.BigDecimal;
 import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
 /**
@@ -107,72 +99,54 @@
     @SneakyThrows
     @Override
     public int batchInsertApsGasPipelinePrediction(MultipartFile file) {
-        Workbook workbook = WorkbookFactory.create(file.getInputStream());
 
-        Sheet sheet = workbook.getSheetAt(0);
-        int rows = sheet.getLastRowNum();
-        if (rows > 0) {
-            List<ApsGasPipelinePrediction> list = new ArrayList<>();
-            Set<String> keys = new HashSet<>();
-            /*鏁版嵁琛屼粠1寮�濮�*/
-            for (int i = rows; i > 0; --i) {
-                Row row = sheet.getRow(i);
-                if (row.getCell(0) == null) {
-                    continue;
-                }
+        ExcelUtil<ApsGasPipelinePrediction> util = new ExcelUtil<>(ApsGasPipelinePrediction.class);
+        List<ApsGasPipelinePrediction> list = util.importExcel(file.getInputStream());
+        DictUtils.CacheValue cacheValue = DictUtils.getCacheValue("aps_factory");
+        Set<String> keys = new HashSet<>();
+        list.forEach(item -> {
+            item.setId(IdUtil.getSnowflakeNextId());
+            item.setFactory(cacheValue.get(item.getFactory()));
+            item.setCreateBy(SecurityUtils.getUsername());
+            item.setCreateTime(DateUtils.getNowDate());
+        });
+        Collections.reverse(list);
+        list = list.stream().filter(item -> {
+            item.setKey(null);
+            if (!keys.contains(item.getKey())) {
+                keys.add(item.getKey());
+                return true;
+            }
+            return false;
+        }).collect(Collectors.toList());
 
-                String materialCode = row.getCell(0).getStringCellValue();
-                if (StringUtils.isEmpty(materialCode)) {
-                    continue;
-                }
-                String factory = row.getCell(1).getStringCellValue();
-                double quantity = row.getCell(2).getNumericCellValue();
-                Date date = row.getCell(3).getDateCellValue();
-                if (StringUtils.isNotBlank(factory) &&
-                    date != null) {
-                    ApsGasPipelinePrediction item = new ApsGasPipelinePrediction();
-                    item.setId(IdUtil.getSnowflakeNextId());
-                    item.setFactory(factory);
-                    item.setMaterialCode(materialCode);
-                    item.setCreateBy(SecurityUtils.getUsername());
-                    item.setCreateTime(DateUtils.getNowDate());
-                    item.setPredictQuantity(new BigDecimal(quantity));
-                    item.setPredictDate(new Timestamp(date.getTime()));
-                    if (!keys.contains(item.getKey())) {
-                        keys.add(item.getKey());
-                        list.add(item);
+        if (!list.isEmpty()) {
+            List<Map<String, Object>> facCodeKey = apsGasPipelinePredictionMapper.selectByFacOrMaterial(keys);
+            if (!facCodeKey.isEmpty()) {
+                Iterator<ApsGasPipelinePrediction> it = list.iterator();
+                while (it.hasNext()) {
+                    ApsGasPipelinePrediction item = it.next();
+                    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()) {
-                List<Map<String, Object>> facCodeKey = apsGasPipelinePredictionMapper.selectByFacOrMaterial(keys);
-                if (!facCodeKey.isEmpty()) {
-                    Iterator<ApsGasPipelinePrediction> it = list.iterator();
-                    while (it.hasNext()) {
-                        ApsGasPipelinePrediction item = it.next();
-                        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()) {
-                    apsGasPipelinePredictionMapper.insert(list);
-                }
+                apsGasPipelinePredictionMapper.insert(list);
             }
-            return list.size();
         }
-        return 0;
+        return list.size();
     }
 }

--
Gitblit v1.9.3