From 25cc1b887f5421353d94c5e6be0fca56b3f2e668 Mon Sep 17 00:00:00 2001
From: zhanghl <253316343@qq.com>
Date: 星期三, 21 五月 2025 16:29:24 +0800
Subject: [PATCH] 优化Job
---
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelinePredictionServiceImpl.java | 88 ++++++++++++++++++++++++++++---------------
1 files changed, 57 insertions(+), 31 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 7a85b16..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
@@ -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,87 @@
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.concurrent.atomic.AtomicBoolean;
+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);
}
@@ -117,12 +113,16 @@
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;
+ }
+
String materialCode = row.getCell(0).getStringCellValue();
- if (StringUtils.isEmpty(materialCode)){
+ if (StringUtils.isEmpty(materialCode)) {
continue;
}
String factory = row.getCell(1).getStringCellValue();
@@ -138,12 +138,38 @@
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()) {
- apsGasPipelinePredictionMapper.deleteAll();
- apsGasPipelinePredictionMapper.insert(list);
+ 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);
+ }
}
return list.size();
}
--
Gitblit v1.9.3