From dfb52b5f71f9846cfd470c2ae1fab64b17914ba0 Mon Sep 17 00:00:00 2001
From: Zhu Zhonghua <zhonghua@qq.com>
Date: 星期四, 22 五月 2025 17:04:10 +0800
Subject: [PATCH] 修改循环删除问题
---
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsMaterialProductGroupManagementServiceImpl.java | 45 ++++++++++++++++++++++++++++++++++++++-------
1 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsMaterialProductGroupManagementServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsMaterialProductGroupManagementServiceImpl.java
index 18cb143..9cb9f90 100644
--- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsMaterialProductGroupManagementServiceImpl.java
+++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsMaterialProductGroupManagementServiceImpl.java
@@ -2,9 +2,8 @@
import java.math.BigDecimal;
import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
import cn.hutool.core.util.IdUtil;
import com.aps.common.core.utils.DateUtils;
@@ -13,6 +12,7 @@
import com.aps.core.domain.ApsMaterialProductGroupManagement;
import com.aps.core.mapper.ApsMaterialProductGroupManagementMapper;
import com.aps.core.service.IApsMaterialProductGroupManagementService;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.micrometer.common.util.StringUtils;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.Row;
@@ -68,6 +68,8 @@
@Override
public int insertApsMaterialProductGroupManagement(ApsMaterialProductGroupManagement apsMaterialProductGroupManagement)
{
+ apsMaterialProductGroupManagement.setId(IdUtil.getSnowflakeNextId());
+ apsMaterialProductGroupManagement.setCreateBy(SecurityUtils.getUsername());
apsMaterialProductGroupManagement.setCreateTime(DateUtils.getNowDate());
return apsMaterialProductGroupManagementMapper.insertApsMaterialProductGroupManagement(apsMaterialProductGroupManagement);
}
@@ -82,6 +84,7 @@
public int updateApsMaterialProductGroupManagement(ApsMaterialProductGroupManagement apsMaterialProductGroupManagement)
{
apsMaterialProductGroupManagement.setUpdateTime(DateUtils.getNowDate());
+ apsMaterialProductGroupManagement.setUpdateBy(SecurityUtils.getUsername());
return apsMaterialProductGroupManagementMapper.updateApsMaterialProductGroupManagement(apsMaterialProductGroupManagement);
}
@@ -119,9 +122,13 @@
if (rows > 0) {
List<ApsMaterialProductGroupManagement> list = new ArrayList<>();
- /*鏁版嵁鍒椾粠1寮�濮�*/
- for (int i = 1; i <= rows; i++) {
+ /*鏁版嵁琛屼粠1寮�濮�*/
+ Set<String> keys = new HashSet<>();
+ 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)){
continue;
@@ -143,11 +150,35 @@
item.setIsMain(isMain);
item.setCreateBy(SecurityUtils.getUsername());
item.setCreateTime(DateUtils.getNowDate());
- list.add(item);
+ if (!keys.contains(item.getKey())) {
+ keys.add(item.getKey());
+ list.add(item);
+ }
}
}
if (!list.isEmpty()) {
- apsMaterialProductGroupManagementMapper.insert(list);
+ Set<String> facCodeKey = apsMaterialProductGroupManagementMapper.selectByFacOrMaterial(keys);
+ if (!facCodeKey.isEmpty()) {
+ Iterator<ApsMaterialProductGroupManagement> it = list.iterator();
+ while (it.hasNext()) {
+ ApsMaterialProductGroupManagement item = it.next();
+ if (facCodeKey.contains(item.getKey())) {
+ LambdaUpdateWrapper<ApsMaterialProductGroupManagement> wrapper = new LambdaUpdateWrapper<>();
+ wrapper.eq(ApsMaterialProductGroupManagement::getFactory, item.getFactory());
+ wrapper.eq(ApsMaterialProductGroupManagement::getMaterialCode, item.getMaterialCode());
+ item.setCreateBy(null);
+ item.setCreateTime(null);
+ item.setUpdateBy(SecurityUtils.getUsername());
+ item.setUpdateTime(new Timestamp(System.currentTimeMillis()));
+ apsMaterialProductGroupManagementMapper.update(item, wrapper);
+ it.remove();
+ }
+ }
+ }
+
+ if (!list.isEmpty()) {
+ apsMaterialProductGroupManagementMapper.insert(list);
+ }
}
return list.size();
}
--
Gitblit v1.9.3