diff --git a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/controller/admin/productinfo/vo/ProductInfoExcelVO.java b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/controller/admin/productinfo/vo/ProductInfoExcelVO.java index b4d7ee1..175f116 100644 --- a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/controller/admin/productinfo/vo/ProductInfoExcelVO.java +++ b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/controller/admin/productinfo/vo/ProductInfoExcelVO.java @@ -67,6 +67,10 @@ public class ProductInfoExcelVO { @ExcelProperty("材质(颜色)") private String material; + @Schema(description = "单价") + @ExcelProperty("单价") + private String price; + @Schema(description = "备注") @ExcelProperty("备注") private String remarks; diff --git a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoService.java b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoService.java index ee6e897..d6d2505 100644 --- a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoService.java +++ b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoService.java @@ -77,7 +77,7 @@ public interface ProductInfoService { /** * 按产品ID查询价格 * - * @param productId 材质id + * @param productId 材质ide * @param currency 货币 * @return {@link BigDecimal } */ 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 9e14de7..43af834 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 @@ -27,17 +27,23 @@ import cn.hangtag.module.oms.service.productprocess.ProductProcessService; import cn.hutool.cache.CacheUtil; import cn.hutool.cache.impl.LFUCache; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; + import javax.annotation.Resource; + import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.*; + import cn.hangtag.module.oms.controller.admin.productinfo.vo.*; import cn.hangtag.module.oms.dal.dataobject.productinfo.ProductInfoDO; import cn.hangtag.framework.common.pojo.PageResult; @@ -70,23 +76,24 @@ public class ProductInfoServiceImpl implements ProductInfoService { private final BrandService brandService; private final DraftDesignDataService draftDesignDataService; private final DraftDesignDataMapper draftDesignDataMapper; - + private static final int TMP_CACHE_TIME = 1000 * 60; + @Override @Transactional(rollbackFor = Exception.class) public Long createProductInfo(ProductInfoSaveReqVO createReqVO) { // 插入 ProductInfoDO productInfo = BeanUtils.toBean(createReqVO, ProductInfoDO.class); String code = productInfo.getCode(); - if(FuncUtil.isNotEmpty(code)){ - checkCode(productInfo.getId(),code); - }else { + if (FuncUtil.isNotEmpty(code)) { + checkCode(productInfo.getId(), code); + } else { productInfo.setCode(getNewCode()); } productInfoMapper.insert(productInfo); List productProcessList = createReqVO.getProductProcessList(); - if(FuncUtil.isNotEmpty(productProcessList)){ + if (FuncUtil.isNotEmpty(productProcessList)) { List subList = new ArrayList<>(); for (ProductProcessSaveReqVO reqVO : productProcessList) { ProductProcessDO processDO = new ProductProcessDO(); @@ -111,13 +118,13 @@ public class ProductInfoServiceImpl implements ProductInfoService { ProductInfoDO productInfoDO = validateProductInfoExists(updateReqVO.getId()); String code = updateReqVO.getCode(); - if(FuncUtil.isNotEmpty(code)){ - checkCode(updateReqVO.getId(),code); - }else { + if (FuncUtil.isNotEmpty(code)) { + checkCode(updateReqVO.getId(), code); + } else { updateReqVO.setCode(getNewCode()); } List productProcessList = updateReqVO.getProductProcessList(); - if(FuncUtil.isNotEmpty(productProcessList)){ + if (FuncUtil.isNotEmpty(productProcessList)) { List addList = new ArrayList<>(); List updateList = new ArrayList<>(); for (ProductProcessSaveReqVO reqVO : productProcessList) { @@ -126,29 +133,29 @@ public class ProductInfoServiceImpl implements ProductInfoService { processDO.setName(reqVO.getName()); processDO.setRemark(reqVO.getRemark()); processDO.setStep(reqVO.getStep()); - if(FuncUtil.isEmpty(reqVO.getId())){ + if (FuncUtil.isEmpty(reqVO.getId())) { addList.add(processDO); - }else{ + } else { processDO.setId(reqVO.getId()); updateList.add(processDO); } } - if(FuncUtil.isNotEmpty(addList)){ + if (FuncUtil.isNotEmpty(addList)) { productProcessMapper.insertBatch(addList); } - if(FuncUtil.isNotEmpty(updateList)){ + if (FuncUtil.isNotEmpty(updateList)) { productProcessMapper.updateBatch(updateList); } } // 更新 ProductInfoDO updateObj = BeanUtils.toBean(updateReqVO, ProductInfoDO.class); productInfoMapper.updateById(updateObj); - if (!FuncUtil.equals(productInfoDO.getBrandId(),updateReqVO.getBrandId())) { + if (!FuncUtil.equals(productInfoDO.getBrandId(), updateReqVO.getBrandId())) { // 产品的品牌发生变化时 brandService.updateProductCount(updateReqVO.getBrandId()); brandService.updateProductCount(productInfoDO.getBrandId()); } - if (!FuncUtil.equals(productInfoDO.getDraftDesignDataId(),updateReqVO.getDraftDesignDataId())) { + if (!FuncUtil.equals(productInfoDO.getDraftDesignDataId(), updateReqVO.getDraftDesignDataId())) { // 产品的品牌发生变化时 draftDesignDataService.updateProductCount(productInfoDO.getDraftDesignDataId()); draftDesignDataService.updateProductCount(updateReqVO.getDraftDesignDataId()); @@ -177,12 +184,13 @@ public class ProductInfoServiceImpl implements ProductInfoService { @Override public ProductInfoDO getProductInfo(Long id) { ProductInfoDO productInfoDO = productInfoMapper.selectById(id); - if(FuncUtil.isNotEmpty(productInfoDO)){ + if (FuncUtil.isNotEmpty(productInfoDO)) { productInfoDO.setProductTypeName(togProductTypeName(productInfoDO.getProductTypeId())); } - + return productInfoDO; } + @Override public ProductInfoRespVO getFrontProductInfo(Long id) { ProductInfoDO infoDO = productInfoMapper.selectById(id); @@ -201,15 +209,15 @@ public class ProductInfoServiceImpl implements ProductInfoService { Set brandIds = new HashSet<>(); for (ProductInfoDO infoDO : list) { String customerGroupId = infoDO.getCustomerGroupId(); - if(FuncUtil.isNotEmpty(customerGroupId)){ + if (FuncUtil.isNotEmpty(customerGroupId)) { groupIds.add(customerGroupId); } Long productTypeId = infoDO.getProductTypeId(); - if(FuncUtil.isNotEmpty(productTypeId)){ + if (FuncUtil.isNotEmpty(productTypeId)) { productTypeIds.add(productTypeId); } Long brandId = infoDO.getBrandId(); - if(FuncUtil.isNotEmpty(brandId)){ + if (FuncUtil.isNotEmpty(brandId)) { brandIds.add(brandId); } } @@ -225,7 +233,8 @@ public class ProductInfoServiceImpl implements ProductInfoService { }); return new PageResult<>(resList, productInfoDOPageResult.getTotal()); } - @Override + + @Override public PageResult exportExcel(ProductInfoPageReqVO pageReqVO) { PageResult productInfoDOPageResult = productInfoMapper.selectPage(pageReqVO); List list = productInfoDOPageResult.getList(); @@ -235,15 +244,15 @@ public class ProductInfoServiceImpl implements ProductInfoService { Set brandIds = new HashSet<>(); for (ProductInfoDO infoDO : list) { String customerGroupId = infoDO.getCustomerGroupId(); - if(FuncUtil.isNotEmpty(customerGroupId)){ + if (FuncUtil.isNotEmpty(customerGroupId)) { groupIds.add(customerGroupId); } Long productTypeId = infoDO.getProductTypeId(); - if(FuncUtil.isNotEmpty(productTypeId)){ + if (FuncUtil.isNotEmpty(productTypeId)) { productTypeIds.add(productTypeId); } Long brandId = infoDO.getBrandId(); - if(FuncUtil.isNotEmpty(brandId)){ + if (FuncUtil.isNotEmpty(brandId)) { brandIds.add(brandId); } } @@ -260,13 +269,26 @@ public class ProductInfoServiceImpl implements ProductInfoService { vo.setCode(productInfoDO.getCode()); vo.setName(productInfoDO.getName()); vo.setIntroduction(productInfoDO.getProductionInfo()); - vo.setSpecWidth(FuncUtil.toStr(productInfoDO.getSpecSizeWidth(),"")); - vo.setSpecHeight(FuncUtil.toStr(productInfoDO.getSpecSizeHeight(),"")); - vo.setSpecThickness(FuncUtil.toStr(productInfoDO.getSpecSizeThk(),"")); - vo.setMaterial(FuncUtil.toStr(productInfoDO.getSpecMaterial(),"")); + vo.setSpecWidth(FuncUtil.toStr(productInfoDO.getSpecSizeWidth(), "")); + vo.setSpecHeight(FuncUtil.toStr(productInfoDO.getSpecSizeHeight(), "")); + vo.setSpecThickness(FuncUtil.toStr(productInfoDO.getSpecSizeThk(), "")); + vo.setMaterial(FuncUtil.toStr(productInfoDO.getSpecMaterial(), "")); vo.setProductType(respVO.getProductTypeName()); vo.setBrandName(respVO.getBrandName()); vo.setRemarks(productInfoDO.getRemark()); + String priceList = productInfoDO.getPriceList(); + String priceStr = ""; + if (FuncUtil.isNotEmpty(priceList)) { + List jsonObjects = JsonUtil.readList(priceList, JSONObject.class); + for (JSONObject object : jsonObjects) { + // 获取默认单价 + if( FuncUtil.toBoolean(object.get("d"),false)){ + priceStr =FuncUtil.toStr(object.get("p")); + break; + } + } + } + vo.setPrice(priceStr); resList.add(vo); }); return new PageResult<>(resList, productInfoDOPageResult.getTotal()); @@ -281,39 +303,40 @@ public class ProductInfoServiceImpl implements ProductInfoService { return new PageResult<>(resList, productInfoDOPageResult.getTotal()); } - private void checkCode(Long id, String code){ - if(FuncUtil.isNotEmpty(code)){ + private void checkCode(Long id, String code) { + if (FuncUtil.isNotEmpty(code)) { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.select(ProductInfoDO::getId,ProductInfoDO::getCode, BaseDO::getDeleted); + lambdaQueryWrapper.select(ProductInfoDO::getId, ProductInfoDO::getCode, BaseDO::getDeleted); lambdaQueryWrapper.eq(ProductInfoDO::getCode, code); - lambdaQueryWrapper.eq(ProductInfoDO::getDeleted,false); + lambdaQueryWrapper.eq(ProductInfoDO::getDeleted, false); List dos = productInfoMapper.selectList(lambdaQueryWrapper); - if(FuncUtil.isEmpty(id) && FuncUtil.isNotEmpty(dos)){ + if (FuncUtil.isEmpty(id) && FuncUtil.isNotEmpty(dos)) { throw exception(GlobalErrorCodeConstants.DATA_DUPLICATE); } if (FuncUtil.isNotEmpty(id) && FuncUtil.isNotEmpty(dos)) { for (ProductInfoDO aDo : dos) { // 出现重复并当前id 不一致 - if(!FuncUtil.equals(aDo.getId(), id)){ + if (!FuncUtil.equals(aDo.getId(), id)) { throw exception(GlobalErrorCodeConstants.DATA_DUPLICATE); } } } } } + @Override public String getNewCode() { String s = ""; int count = 10; - while (true){ - count --; + while (true) { + count--; try { - s = CodingRulesUtils.generateCode(codeId, false); - checkCode(null,s); + s = CodingRulesUtils.generateCode(codeId, false); + checkCode(null, s); return s; - }catch (ServiceException e){ + } catch (ServiceException e) { log.warn("重复或者下一个编码"); - if(count < 0){ + if (count < 0) { log.error("编码获取失败"); return ""; } @@ -324,12 +347,12 @@ public class ProductInfoServiceImpl implements ProductInfoService { @Override public BigDecimal queryPriceByProductId(Long productId, String currency) { ProductInfoDO infoDO = productInfoMapper.selectById(productId); - if(FuncUtil.isNotEmpty(infoDO)){ + if (FuncUtil.isNotEmpty(infoDO)) { String priceList = infoDO.getPriceList(); - if(FuncUtil.isNotEmpty(priceList)){ + if (FuncUtil.isNotEmpty(priceList)) { List dtos = JsonUtil.readList(priceList, PriceListItemDTO.class); for (PriceListItemDTO dto : dtos) { - if(FuncUtil.equals(dto.getC(), currency)){ + if (FuncUtil.equals(dto.getC(), currency)) { return dto.getP(); } } @@ -339,7 +362,7 @@ public class ProductInfoServiceImpl implements ProductInfoService { } - private static LFUCache brandIdCache = CacheUtil.newLFUCache(10000, 1000 * 60 *30); + private static LFUCache brandIdCache = CacheUtil.newLFUCache(10000, 1000 * 60 * 30); @Override public String importExcel(List list) { @@ -347,13 +370,13 @@ public class ProductInfoServiceImpl implements ProductInfoService { List updateList = new ArrayList<>(); LambdaQueryWrapper brandDOLambdaQueryWrapper = new LambdaQueryWrapper<>(); - brandDOLambdaQueryWrapper.select(BrandDO::getName,BrandDO::getId,BrandDO::getCode); - brandDOLambdaQueryWrapper.eq(BaseDO::getDeleted,false); + brandDOLambdaQueryWrapper.select(BrandDO::getName, BrandDO::getId, BrandDO::getCode); + brandDOLambdaQueryWrapper.eq(BaseDO::getDeleted, false); List brandDOS = brandMapper.selectList(brandDOLambdaQueryWrapper); for (BrandDO brandDO : brandDOS) { - brandIdCache.put(brandDO.getName(),brandDO.getId()); + brandIdCache.put(brandDO.getName(), brandDO.getId()); } - + Map priceMap = new HashMap<>(); for (int i = 0; i < list.size(); i++) { ProductInfoExcelVO excelVO = list.get(i); // 判断是否为空行 下拉导致很多空行 @@ -363,109 +386,144 @@ public class ProductInfoServiceImpl implements ProductInfoService { ProductInfoDO productInfo = new ProductInfoDO(); productInfo.setName(excelVO.getName()); + String price = excelVO.getPrice(); String code = excelVO.getCode(); - if(FuncUtil.isNotEmpty(code)){ + if (FuncUtil.isNotEmpty(code)) { // 覆盖 try { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.eq(ProductInfoDO::getCode, code); - lambdaQueryWrapper.eq(ProductInfoDO::getDeleted,false); + lambdaQueryWrapper.eq(ProductInfoDO::getDeleted, false); lambdaQueryWrapper.last("limit 1"); ProductInfoDO dos = productInfoMapper.selectOne(lambdaQueryWrapper); - if(FuncUtil.isNotEmpty(dos)){ + if (FuncUtil.isNotEmpty(dos)) { - // 合并属性 - BeanUtil.copyProperties(dos, productInfo); - productInfo.setName(excelVO.getName()); - productInfo.setSummary(excelVO.getIntroduction()); - productInfo.setId(dos.getId()); - String brandName = excelVO.getBrandName(); - productInfo.setCode(code); - productInfo.setSpecSizeWidth(FuncUtil.toDouble(excelVO.getSpecWidth(),null)); - productInfo.setSpecSizeHeight(FuncUtil.toDouble(excelVO.getSpecHeight(),null)); - productInfo.setSpecSizeThk(FuncUtil.toDouble(excelVO.getSpecThickness(),null)); - productInfo.setSpecMaterial(FuncUtil.toStr(excelVO.getMaterial(),null)); - productInfo.setRemark(FuncUtil.toStr(excelVO.getRemarks(),null)); + // 合并属性 + BeanUtil.copyProperties(dos, productInfo); + productInfo.setName(excelVO.getName()); + productInfo.setSummary(excelVO.getIntroduction()); + productInfo.setId(dos.getId()); + String brandName = excelVO.getBrandName(); + productInfo.setCode(code); + productInfo.setSpecSizeWidth(FuncUtil.toDouble(excelVO.getSpecWidth(), null)); + productInfo.setSpecSizeHeight(FuncUtil.toDouble(excelVO.getSpecHeight(), null)); + productInfo.setSpecSizeThk(FuncUtil.toDouble(excelVO.getSpecThickness(), null)); + productInfo.setSpecMaterial(FuncUtil.toStr(excelVO.getMaterial(), null)); + productInfo.setRemark(FuncUtil.toStr(excelVO.getRemarks(), null)); - if(FuncUtil.isNotEmpty(excelVO.getProductType())){ - Long productTypeId = toProductTypeId(excelVO.getProductType()); - productInfo.setProductTypeId(productTypeId); - } + if (FuncUtil.isNotEmpty(excelVO.getProductType())) { + 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()); - } - } - } + 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()); + } + } + } + if (FuncUtil.isNotEmpty(price)) { + String priceList = dos.getPriceList(); + JSONObject jsonObject = new JSONObject(); +// [{p:100.25,c:"RMB",d:true}] + jsonObject.set("p", price); + jsonObject.set("c", "RMB"); + jsonObject.set("d", true); + List newPriceList = new ArrayList<>(); + if(FuncUtil.isNotEmpty(priceList)){ + newPriceList = JsonUtil.readList(priceList, JSONObject.class); + newPriceList.forEach(json -> { + json.set("d", false); + }); - updateList.add(productInfo); - continue; - } - }catch (Exception e){ - return "第"+(i+1)+"行覆盖失败:"+code+e.getMessage(); + } + + newPriceList.add(0, jsonObject); + productInfo.setPriceList(JsonUtil.toJson(newPriceList)); + } + + updateList.add(productInfo); + continue; + } + } catch (Exception e) { + return "第" + (i + 1) + "行覆盖失败:" + code + e.getMessage(); } - }else { + } else { code = productInfo.getCode(); } - if(FuncUtil.isEmpty(code)){ - return "第"+(i+1)+"行编码 不能为空:"+code; + if (FuncUtil.isEmpty(code)) { + return "第" + (i + 1) + "行编码 不能为空:" + code; } - String brandName = FuncUtil.toStr(excelVO.getBrandName(),"").trim(); - if(FuncUtil.isEmpty(brandName)){ + String brandName = FuncUtil.toStr(excelVO.getBrandName(), "").trim(); + if (FuncUtil.isEmpty(brandName)) { - return "第"+(i+1)+"行品牌名称 不能为空:"+brandName; + return "第" + (i + 1) + "行品牌名称 不能为空:" + brandName; } - String productType = FuncUtil.toStr(excelVO.getProductType(),"").trim(); - if(FuncUtil.isEmpty(productType)){ - return "第"+(i+1)+"行品类(尺码唛,价钱卡,纸盒,主唛,挂卡,洗水唛) 不能为空:"+productType; + String productType = FuncUtil.toStr(excelVO.getProductType(), "").trim(); + if (FuncUtil.isEmpty(productType)) { + return "第" + (i + 1) + "行品类(尺码唛,价钱卡,纸盒,主唛,挂卡,洗水唛) 不能为空:" + productType; } Long typeId = toProductTypeId(productType); - if(FuncUtil.isEmpty(typeId)){ + if (FuncUtil.isEmpty(typeId)) { ProductTypeIdCache.clear(); - return "第"+(i+1)+"行品类(尺码唛,价钱卡,纸盒,主唛,挂卡,洗水唛) 请维护该分类的的资料:"+productType; + return "第" + (i + 1) + "行品类(尺码唛,价钱卡,纸盒,主唛,挂卡,洗水唛) 请维护该分类的的资料:" + productType; } productInfo.setProductTypeId(typeId); productInfo.setCode(code); productInfo.setTemplateType("2"); - productInfo.setSpecSizeWidth(FuncUtil.toDouble(excelVO.getSpecWidth(),null)); - productInfo.setSpecSizeHeight(FuncUtil.toDouble(excelVO.getSpecHeight(),null)); - productInfo.setSpecSizeThk(FuncUtil.toDouble(excelVO.getSpecThickness(),null)); + productInfo.setSpecSizeWidth(FuncUtil.toDouble(excelVO.getSpecWidth(), null)); + productInfo.setSpecSizeHeight(FuncUtil.toDouble(excelVO.getSpecHeight(), null)); + productInfo.setSpecSizeThk(FuncUtil.toDouble(excelVO.getSpecThickness(), null)); productInfo.setSpecMaterial(excelVO.getMaterial()); productInfo.setRemark(excelVO.getRemarks()); Long brandId = brandIdCache.get(brandName); - if(FuncUtil.isNotEmpty(brandId)){ + if (FuncUtil.isNotEmpty(brandId)) { productInfo.setBrandId(brandId); - }else { + } else { BrandDO brandDO = brandService.getBrandByName(brandName); - if(FuncUtil.isEmpty(brandDO)){ - return "第"+(i+1)+"行品牌不存在,请维护该品牌的资料:"+brandName; + if (FuncUtil.isEmpty(brandDO)) { + return "第" + (i + 1) + "行品牌不存在,请维护该品牌的资料:" + brandName; } productInfo.setBrandId(brandDO.getId()); - brandIdCache.put(brandName,brandDO.getId()); + brandIdCache.put(brandName, brandDO.getId()); + } + Long id = IdUtil.getSnowflakeNextId(); + productInfo.setId(id); + if(FuncUtil.isNotEmpty(price)){ + if (FuncUtil.isNotEmpty(price)) { + JSONObject jsonObject = new JSONObject(); +// [{p:100.25,c:"RMB",d:true}] + jsonObject.set("p", price); + jsonObject.set("c", "RMB"); + jsonObject.set("d", true); + List jsonObjects = new ArrayList<>(); + jsonObjects.add(jsonObject); + productInfo.setPriceList(JsonUtil.toJson(jsonObjects)); + } } newList.add(productInfo); } - if(FuncUtil.isNotEmpty(newList)){ + if (FuncUtil.isNotEmpty(newList)) { productInfoMapper.insertBatch(newList); } - if(FuncUtil.isNotEmpty(updateList)){ + if (FuncUtil.isNotEmpty(updateList)) { updateList.forEach(productInfoMapper::updateById); } - log.info("导出成功{},更新成功{}",newList.size(),updateList.size()); + + log.info("导出成功{},更新成功{}", newList.size(), updateList.size()); return ""; } @@ -474,14 +532,15 @@ public class ProductInfoServiceImpl implements ProductInfoService { return true; } // - if(FuncUtil.isEmpty(excelVO.getCode()) + if (FuncUtil.isEmpty(excelVO.getCode()) && FuncUtil.isEmpty(excelVO.getName()) - ){ + ) { return true; } return false; } - private List wrapperRespVO(List list){ + + private List wrapperRespVO(List list) { List resList = new ArrayList<>(); list.forEach(productInfoDO -> { ProductInfoRespVO vo = BeanUtils.toBean(productInfoDO, ProductInfoRespVO.class); @@ -499,10 +558,11 @@ public class ProductInfoServiceImpl implements ProductInfoService { ProductTypeIdCache.clear(); return resList; } - private ProductInfoRespVO wrapperFileIds(ProductInfoRespVO vo){ - if(FuncUtil.isNotEmpty(vo)){ + + private ProductInfoRespVO wrapperFileIds(ProductInfoRespVO vo) { + if (FuncUtil.isNotEmpty(vo)) { String draftDesignDataIds = vo.getDraftDesignDataId(); - if(FuncUtil.isNotEmpty(draftDesignDataIds)){ + if (FuncUtil.isNotEmpty(draftDesignDataIds)) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.in(DraftDesignDataDO::getId, Arrays.asList(draftDesignDataIds.split(","))); queryWrapper.eq(DraftDesignDataDO::getDeleted, false); @@ -510,38 +570,39 @@ public class ProductInfoServiceImpl implements ProductInfoService { queryWrapper.orderByDesc(BaseDO::getCreateTime); List dos = draftDesignDataMapper.selectList(queryWrapper); List fileIds = new ArrayList<>(); - if(FuncUtil.isNotEmpty(dos)){ + if (FuncUtil.isNotEmpty(dos)) { for (DraftDesignDataDO designDataDO : dos) { List strList = FuncUtil.toStrList(designDataDO.getFileIds()); fileIds.addAll(strList); } } - if(FuncUtil.isNotEmpty(fileIds)){ - vo.setFileIds(String.join(",",fileIds)); + if (FuncUtil.isNotEmpty(fileIds)) { + vo.setFileIds(String.join(",", fileIds)); } } } return vo; } + private static LFUCache CustomerGroupNameCache = CacheUtil.newLFUCache(10000, TMP_CACHE_TIME); - private ProductInfoRespVO wrapperCustomerGroupName(ProductInfoRespVO vo){ - if(FuncUtil.isNotEmpty(vo)){ - if(FuncUtil.isNotEmpty(vo.getCustomerGroupId())){ + private ProductInfoRespVO wrapperCustomerGroupName(ProductInfoRespVO vo) { + if (FuncUtil.isNotEmpty(vo)) { + if (FuncUtil.isNotEmpty(vo.getCustomerGroupId())) { String s = CustomerGroupNameCache.get(vo.getCustomerGroupId()); - if(FuncUtil.isNotEmpty(s)){ + if (FuncUtil.isNotEmpty(s)) { vo.setCustomerGroupName(s); - }else { + } else { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.in(CustomerGroupDO::getId, FuncUtil.toStrList(vo.getCustomerGroupId())); - wrapper.eq(BaseDO::getDeleted,false); + wrapper.eq(BaseDO::getDeleted, false); List groupDOS = customerGroupMapper.selectList(wrapper); String name = null; - if(FuncUtil.isNotEmpty(groupDOS)){ + if (FuncUtil.isNotEmpty(groupDOS)) { List names = new ArrayList<>(); for (CustomerGroupDO groupDO : groupDOS) { - if(names.contains(groupDO.getName())){ + if (names.contains(groupDO.getName())) { continue; } names.add(groupDO.getName()); @@ -556,18 +617,19 @@ public class ProductInfoServiceImpl implements ProductInfoService { } return vo; } - private void initCustomerGroupNameCache(Set ids){ + + private void initCustomerGroupNameCache(Set ids) { if (FuncUtil.isNotEmpty(ids)) { for (String db : ids) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.in(CustomerGroupDO::getId, FuncUtil.toStrList(db)); - wrapper.eq(BaseDO::getDeleted,false); + wrapper.eq(BaseDO::getDeleted, false); List groupDOS = customerGroupMapper.selectList(wrapper); String name = null; - if(FuncUtil.isNotEmpty(groupDOS)){ + if (FuncUtil.isNotEmpty(groupDOS)) { List names = new ArrayList<>(); for (CustomerGroupDO groupDO : groupDOS) { - if(names.contains(groupDO.getName())){ + if (names.contains(groupDO.getName())) { continue; } names.add(groupDO.getName()); @@ -581,20 +643,22 @@ public class ProductInfoServiceImpl implements ProductInfoService { } private static LFUCache ProductTypeNameCache = CacheUtil.newLFUCache(10000, TMP_CACHE_TIME); - private ProductInfoRespVO wrapperProductTypeName(ProductInfoRespVO vo){ - if(FuncUtil.isNotEmpty(vo)){ + + private ProductInfoRespVO wrapperProductTypeName(ProductInfoRespVO vo) { + if (FuncUtil.isNotEmpty(vo)) { vo.setProductTypeName(togProductTypeName(vo.getProductTypeId())); } return vo; } - private String togProductTypeName(Long productTypeId){ - if(FuncUtil.isNotEmpty(productTypeId)){ + + private String togProductTypeName(Long productTypeId) { + if (FuncUtil.isNotEmpty(productTypeId)) { String s = ProductTypeNameCache.get(productTypeId); - if (FuncUtil.isNotEmpty(s)){ + if (FuncUtil.isNotEmpty(s)) { return s; - }else { + } else { ProductTypeDO productTypeDO = productTypeMapper.selectById(productTypeId); - if(FuncUtil.isNotEmpty(productTypeDO)){ + if (FuncUtil.isNotEmpty(productTypeDO)) { ProductTypeNameCache.put(productTypeId, productTypeDO.getLabel()); return productTypeDO.getLabel(); } @@ -603,28 +667,29 @@ public class ProductInfoServiceImpl implements ProductInfoService { return ""; } - private static LFUCache ProductTypeIdCache = CacheUtil.newLFUCache(10000, TMP_CACHE_TIME); + private static LFUCache ProductTypeIdCache = CacheUtil.newLFUCache(10000, TMP_CACHE_TIME); - private Long toProductTypeId(String name){ - if(FuncUtil.isEmpty(name)){ + private Long toProductTypeId(String name) { + if (FuncUtil.isEmpty(name)) { return null; } Long s = ProductTypeIdCache.get(name); if (FuncUtil.isEmpty(s)) { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(ProductTypeDO::getLabel,name); + lambdaQueryWrapper.eq(ProductTypeDO::getLabel, name); lambdaQueryWrapper.last("limit 1"); ProductTypeDO productTypeDO = productTypeMapper.selectOne(lambdaQueryWrapper); - if(FuncUtil.isNotEmpty(productTypeDO)){ + if (FuncUtil.isNotEmpty(productTypeDO)) { s = productTypeDO.getId(); ProductTypeIdCache.put(name, productTypeDO.getId()); } } return s; } - private void initProductTypeNameCache(Set ids){ + + private void initProductTypeNameCache(Set ids) { ProductTypeNameCache.clear(); - if(FuncUtil.isNotEmpty(ids)){ + if (FuncUtil.isNotEmpty(ids)) { List dos = productTypeMapper.selectBatchIds(ids); for (ProductTypeDO db : dos) { ProductTypeNameCache.put(db.getId(), db.getLabel()); @@ -634,15 +699,16 @@ public class ProductInfoServiceImpl implements ProductInfoService { private static LFUCache brandNameCache = CacheUtil.newLFUCache(10000, TMP_CACHE_TIME); - private ProductInfoRespVO wrapperBrandName(ProductInfoRespVO vo){ - if(FuncUtil.isNotEmpty(vo)){ - if(FuncUtil.isNotEmpty(vo.getBrandId())){ + + private ProductInfoRespVO wrapperBrandName(ProductInfoRespVO vo) { + if (FuncUtil.isNotEmpty(vo)) { + if (FuncUtil.isNotEmpty(vo.getBrandId())) { String s = brandNameCache.get(vo.getBrandId()); - if(FuncUtil.isNotEmpty(s)){ + if (FuncUtil.isNotEmpty(s)) { vo.setBrandName(s); - }else { + } else { BrandDO brandDO = brandMapper.selectById(vo.getBrandId()); - if(FuncUtil.isNotEmpty(brandDO)){ + if (FuncUtil.isNotEmpty(brandDO)) { vo.setBrandName(brandDO.getName()); brandNameCache.put(vo.getBrandId(), brandDO.getName()); } @@ -651,8 +717,9 @@ public class ProductInfoServiceImpl implements ProductInfoService { } return vo; } - private void initBrandNameCache(Set ids){ - if(FuncUtil.isNotEmpty(ids)){ + + private void initBrandNameCache(Set ids) { + if (FuncUtil.isNotEmpty(ids)) { List brandDOS = brandMapper.selectBatchIds(ids); for (BrandDO brandDO : brandDOS) { brandNameCache.put(brandDO.getId(), brandDO.getName());