增加导入同一批数据判断是否纯正相同货号
This commit is contained in:
1 parent
cfc2982081
commit
3d196b6b24
3 files changed
+46
-9
No files matched your search
@@ -13,6 +13,13 @@
|
||||
<artifactId>pjcloud-supermarket-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 幂等插件使用 -->
|
||||
<!-- 重复提交 -->
|
||||
<dependency>
|
||||
<groupId>com.bsd</groupId>
|
||||
<artifactId>pjcloud-common-idempotent</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--必备: undertow容器-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
+2
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.excel.annotation.RequestExcel;
|
||||
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
|
||||
import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.common.security.util.SecurityUtils;
|
||||
import com.bsd.pjcloud.supermarket.dto.SupermarketSpuAppQueryDTO;
|
||||
@@ -228,6 +229,7 @@ public class SmErpSpuController {
|
||||
*/
|
||||
@PostMapping("/import")
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_supermarketSpu_import')" )
|
||||
@Idempotent(key = "#key", expireTime = 10, info = "请勿重复导入,10秒后再重新尝试")
|
||||
public R importErpSpu(@RequestExcel List<SmErpSpuImportDto> dtos, BindingResult bindingResult) {
|
||||
List<SmErpSpuImportDto> collect = dtos.stream().filter(smErpSpuImportDto -> smErpSpuImportDto.getProductCode() != null).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(collect)) {
|
||||
|
||||
+37
-9
@@ -519,6 +519,19 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
Long merchantId = mchManageVoR.getData().getId();
|
||||
//错误集合
|
||||
List<Map<String, Object>> errorList = new ArrayList<>();
|
||||
|
||||
|
||||
//查询这一批导入的数据是否纯在货号相同,存在标记出行数
|
||||
// 1. 收集本次导入的所有货号及行号映射
|
||||
Map<String, List<Integer>> importProductCodeMap = new HashMap<>();
|
||||
for (int i = 0; i < smErpSpuImportDtos.size(); i++) {
|
||||
SmErpSpuImportDto dto = smErpSpuImportDtos.get(i);
|
||||
int row = i + 1;
|
||||
String code = dto.getProductCode();
|
||||
importProductCodeMap.computeIfAbsent(code, k -> new ArrayList<>()).add(row);
|
||||
}
|
||||
|
||||
|
||||
//货号-商品映射
|
||||
Map<String, SmErpSpuEntity> productCodeToSpuMap = new HashMap<>();
|
||||
|
||||
@@ -545,6 +558,19 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
String productCode = dto.getProductCode();
|
||||
|
||||
try {
|
||||
//================================ 新增代码开始 ================================//
|
||||
// 检查本批次内部重复
|
||||
List<Integer> duplicateRows = importProductCodeMap.get(productCode);
|
||||
if (duplicateRows.size() > 1) {
|
||||
String duplicateInfo = duplicateRows.stream()
|
||||
.filter(r -> r < rowNumber) // 只显示之前的重复行
|
||||
.map(r -> "第" + r + "行")
|
||||
.collect(Collectors.joining(","));
|
||||
if (!duplicateInfo.isEmpty()) {
|
||||
errorReasons.add("货号在本批导入数据中重复,重复行号:" + duplicateInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// 数据校验
|
||||
List<String> validationErrors = ErpSpuValidator.validate(dto, rowNumber);
|
||||
//添加验证错误记录
|
||||
@@ -586,17 +612,19 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
spu.setDeptId(deptId);
|
||||
|
||||
SmErpSpuEntity existingSpu = existingSpuMap.get(productCode);
|
||||
// 合并两种错误检查
|
||||
if (existingSpu != null) {
|
||||
// 更新模式:设置原有主键
|
||||
// spu.setId(existingSpu.getId());
|
||||
// updateBatch.add(spu);
|
||||
errorReasons.add(existingSpu.getProductCode()+"-"+existingSpu.getProductName()+",该货号商品系统中已存在");
|
||||
errorList.add(createErrorInfo(rowNumber, productCode, errorReasons));
|
||||
} else {
|
||||
// 新增模式
|
||||
insertBatch.add(spu);
|
||||
errorReasons.add(existingSpu.getProductCode() + "-" + existingSpu.getProductName() + ",该货号商品系统中已存在");
|
||||
}
|
||||
// spuBatch.add(spu);
|
||||
|
||||
// 如果发现错误则记录
|
||||
if (!errorReasons.isEmpty()) {
|
||||
errorList.add(createErrorInfo(rowNumber, productCode, errorReasons));
|
||||
continue; // 跳过后续处理
|
||||
}
|
||||
// 新增模式(原else逻辑)
|
||||
insertBatch.add(spu);
|
||||
|
||||
productCodeToSpuMap.put(productCode, spu);
|
||||
} catch (Exception e) {
|
||||
errorReasons.add("系统异常: " + e.getMessage());
|
||||
|
||||
Reference in new issue
Block a user