diff --git a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoServiceImpl.java b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoServiceImpl.java index 384984d..0677a59 100644 --- a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoServiceImpl.java +++ b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoServiceImpl.java @@ -290,6 +290,7 @@ public class ProductInfoServiceImpl implements ProductInfoService { @Override public String importExcel(List list) { List newList = new ArrayList<>(); + List updateList = new ArrayList<>(); LambdaQueryWrapper 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 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) {