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/ApsGasPipelineMoServiceImpl.java |   65 +++++++-------------------------
 1 files changed, 15 insertions(+), 50 deletions(-)

diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelineMoServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelineMoServiceImpl.java
index d714577..b326ae6 100644
--- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelineMoServiceImpl.java
+++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelineMoServiceImpl.java
@@ -2,25 +2,18 @@
 
 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.ApsGasPipelineMo;
 import com.aps.core.mapper.ApsGasPipelineMoMapper;
 import com.aps.core.service.IApsGasPipelineMoService;
-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.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -108,49 +101,21 @@
     @Transactional(rollbackFor = Exception.class)
     @Override
     public int batchInsertGasPipelineMo(MultipartFile file) {
-        Workbook workbook = WorkbookFactory.create(file.getInputStream());
 
-        Sheet sheet = workbook.getSheetAt(0);
-        int rows = sheet.getLastRowNum();
-        if (rows > 0) {
-            List<ApsGasPipelineMo> list = new ArrayList<>();
+        ExcelUtil<ApsGasPipelineMo> util = new ExcelUtil<>(ApsGasPipelineMo.class);
+        List<ApsGasPipelineMo> tempList = util.importExcel(file.getInputStream());
+        DictUtils.CacheValue cacheValue = DictUtils.getCacheValue("aps_factory");
+        tempList.forEach(apsGasPipelineMo -> {
+            apsGasPipelineMo.setId(IdUtil.getSnowflakeNextId());
+            apsGasPipelineMo.setFactory(cacheValue.get(apsGasPipelineMo.getFactory()));
+            apsGasPipelineMo.setCreateBy(SecurityUtils.getUsername());
+            apsGasPipelineMo.setCreateTime(DateUtils.getNowDate());
+        });
 
-            /*鏁版嵁鍒椾粠1寮�濮�*/
-            for (int i = 1; i <= rows; i++) {
-                Row row = sheet.getRow(i);
-                if (row.getCell(0) == null){
-                    continue;
-                }
-                String mo = row.getCell(0).getStringCellValue();
-                if (StringUtils.isEmpty(mo)){
-                    continue;
-                }
-                String factory = row.getCell(1).getStringCellValue();
-                String materialNum = row.getCell(2).getStringCellValue();
-                double quantity = row.getCell(3).getNumericCellValue();
-                Date planEnd = row.getCell(4).getDateCellValue();
-                if (StringUtils.isNotBlank(factory) &&
-                    StringUtils.isNotBlank(materialNum) &&
-                    planEnd != null) {
-                    ApsGasPipelineMo apsGasPipelineMo = new ApsGasPipelineMo();
-                    apsGasPipelineMo.setMo(mo);
-                    apsGasPipelineMo.setMaterialCode(materialNum);
-                    apsGasPipelineMo.setId(IdUtil.getSnowflakeNextId());
-                    apsGasPipelineMo.setFactory(factory);
-                    apsGasPipelineMo.setCreateBy(SecurityUtils.getUsername());
-                    apsGasPipelineMo.setCreateTime(DateUtils.getNowDate());
-                    apsGasPipelineMo.setQuantity(new BigDecimal(quantity));
-                    apsGasPipelineMo.setPlanEnd(new Timestamp(planEnd.getTime()));
-                    list.add(apsGasPipelineMo);
-                }
-            }
-            if (!list.isEmpty()) {
-                apsGasPipelineMoMapper.deleteAll();
-                apsGasPipelineMoMapper.insert(list);
-            }
-            return list.size();
+        if (!tempList.isEmpty()) {
+            apsGasPipelineMoMapper.deleteAll();
+            apsGasPipelineMoMapper.insert(tempList);
         }
-        return 0;
-
+        return tempList.size();
     }
 }

--
Gitblit v1.9.3