优化 产品导入逻辑,存在相同编码覆盖数据
This commit is contained in:
parent
6d430699f9
commit
42616da7e8
|
|
@ -290,6 +290,7 @@ public class ProductInfoServiceImpl implements ProductInfoService {
|
|||
@Override
|
||||
public String importExcel(List<ProductInfoExcelVO> list) {
|
||||
List<ProductInfoDO> newList = new ArrayList<>();
|
||||
List<ProductInfoDO> updateList = new ArrayList<>();
|
||||
|
||||
LambdaQueryWrapper<BrandDO> brandDOLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
brandDOLambdaQueryWrapper.select(BrandDO::getName,BrandDO::getId,BrandDO::getCode);
|
||||
|
|
@ -309,9 +310,47 @@ public class ProductInfoServiceImpl implements ProductInfoService {
|
|||
String code = excelVO.getCode();
|
||||
if(FuncUtil.isNotEmpty(code)){
|
||||
try {
|
||||
checkCode(productInfo.getId(),code);
|
||||
|
||||
LambdaQueryWrapper<ProductInfoDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(ProductInfoDO::getCode, code);
|
||||
lambdaQueryWrapper.eq(ProductInfoDO::getDeleted,false);
|
||||
lambdaQueryWrapper.last("limit 1");
|
||||
ProductInfoDO dos = productInfoMapper.selectOne(lambdaQueryWrapper);
|
||||
if(FuncUtil.isNotEmpty(dos)){
|
||||
// 合并属性
|
||||
BeanUtil.copyProperties(dos, productInfo);
|
||||
productInfo.setId(dos.getId());
|
||||
String brandName = excelVO.getBrandName();
|
||||
productInfo.setCode(code);
|
||||
productInfo.setTemplateType("2");
|
||||
|
||||
productInfo.setSpecSizeWidth(FuncUtil.toDouble(excelVO.getSpecWidth()));
|
||||
productInfo.setSpecSizeHeight(FuncUtil.toDouble(excelVO.getSpecHeight()));
|
||||
productInfo.setSpecSizeThk(FuncUtil.toDouble(excelVO.getSpecThickness()));
|
||||
productInfo.setSpecMaterial(excelVO.getMaterial());
|
||||
productInfo.setRemark(excelVO.getRemarks());
|
||||
|
||||
Long productTypeId = toProductTypeId(excelVO.getProductType());
|
||||
productInfo.setProductTypeId(productTypeId);
|
||||
|
||||
if(FuncUtil.isNotEmpty(brandName)){
|
||||
Long brandId = brandIdCache.get(brandName);
|
||||
if(FuncUtil.isNotEmpty(brandId)){
|
||||
productInfo.setBrandId(brandId);
|
||||
}else {
|
||||
BrandDO brandDO = brandService.getBrandByName(brandName);
|
||||
if(FuncUtil.isNotEmpty(brandDO)){
|
||||
productInfo.setBrandId(brandDO.getId());
|
||||
brandIdCache.put(brandName,brandDO.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateList.add(productInfo);
|
||||
continue;
|
||||
}
|
||||
}catch (Exception e){
|
||||
return "第"+(i+1)+"行编码重复:"+code;
|
||||
return "第"+(i+1)+"行覆盖失败:"+code+e.getMessage();
|
||||
}
|
||||
}else {
|
||||
code = productInfo.getCode();
|
||||
|
|
@ -347,9 +386,14 @@ public class ProductInfoServiceImpl implements ProductInfoService {
|
|||
}
|
||||
newList.add(productInfo);
|
||||
}
|
||||
if(FuncUtil.isNotEmpty(newList)){
|
||||
productInfoMapper.insertBatch(newList);
|
||||
}
|
||||
if(FuncUtil.isNotEmpty(updateList)){
|
||||
updateList.forEach(productInfoMapper::updateById);
|
||||
}
|
||||
|
||||
productInfoMapper.insertBatch(newList);
|
||||
return "";
|
||||
return (newList.size()+updateList.size())+"";
|
||||
}
|
||||
|
||||
public boolean isAllFieldsEmpty(ProductInfoExcelVO excelVO) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue