新增 产品导入导出增加默认价格
This commit is contained in:
parent
3c550c6f50
commit
287afdc119
|
|
@ -67,6 +67,10 @@ public class ProductInfoExcelVO {
|
|||
@ExcelProperty("材质(颜色)")
|
||||
private String material;
|
||||
|
||||
@Schema(description = "单价")
|
||||
@ExcelProperty("单价")
|
||||
private String price;
|
||||
|
||||
@Schema(description = "备注")
|
||||
@ExcelProperty("备注")
|
||||
private String remarks;
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public interface ProductInfoService {
|
|||
/**
|
||||
* 按产品ID查询价格
|
||||
*
|
||||
* @param productId 材质id
|
||||
* @param productId 材质ide
|
||||
* @param currency 货币
|
||||
* @return {@link BigDecimal }
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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<ProductProcessSaveReqVO> productProcessList = createReqVO.getProductProcessList();
|
||||
if(FuncUtil.isNotEmpty(productProcessList)){
|
||||
if (FuncUtil.isNotEmpty(productProcessList)) {
|
||||
List<ProductProcessDO> 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<ProductProcessSaveReqVO> productProcessList = updateReqVO.getProductProcessList();
|
||||
if(FuncUtil.isNotEmpty(productProcessList)){
|
||||
if (FuncUtil.isNotEmpty(productProcessList)) {
|
||||
List<ProductProcessDO> addList = new ArrayList<>();
|
||||
List<ProductProcessDO> 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<Long> 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<ProductInfoExcelVO> exportExcel(ProductInfoPageReqVO pageReqVO) {
|
||||
PageResult<ProductInfoDO> productInfoDOPageResult = productInfoMapper.selectPage(pageReqVO);
|
||||
List<ProductInfoDO> list = productInfoDOPageResult.getList();
|
||||
|
|
@ -235,15 +244,15 @@ public class ProductInfoServiceImpl implements ProductInfoService {
|
|||
Set<Long> 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<JSONObject> 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<ProductInfoDO> 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<ProductInfoDO> 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<PriceListItemDTO> 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<String,Long> brandIdCache = CacheUtil.newLFUCache(10000, 1000 * 60 *30);
|
||||
private static LFUCache<String, Long> brandIdCache = CacheUtil.newLFUCache(10000, 1000 * 60 * 30);
|
||||
|
||||
@Override
|
||||
public String importExcel(List<ProductInfoExcelVO> list) {
|
||||
|
|
@ -347,13 +370,13 @@ public class ProductInfoServiceImpl implements ProductInfoService {
|
|||
List<ProductInfoDO> updateList = new ArrayList<>();
|
||||
|
||||
LambdaQueryWrapper<BrandDO> 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<BrandDO> brandDOS = brandMapper.selectList(brandDOLambdaQueryWrapper);
|
||||
for (BrandDO brandDO : brandDOS) {
|
||||
brandIdCache.put(brandDO.getName(),brandDO.getId());
|
||||
brandIdCache.put(brandDO.getName(), brandDO.getId());
|
||||
}
|
||||
|
||||
Map<String, String> 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<ProductInfoDO> 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<JSONObject> 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<JSONObject> 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<ProductInfoRespVO> wrapperRespVO(List<ProductInfoDO> list){
|
||||
|
||||
private List<ProductInfoRespVO> wrapperRespVO(List<ProductInfoDO> list) {
|
||||
List<ProductInfoRespVO> 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<DraftDesignDataDO> 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<DraftDesignDataDO> dos = draftDesignDataMapper.selectList(queryWrapper);
|
||||
List<String> fileIds = new ArrayList<>();
|
||||
if(FuncUtil.isNotEmpty(dos)){
|
||||
if (FuncUtil.isNotEmpty(dos)) {
|
||||
for (DraftDesignDataDO designDataDO : dos) {
|
||||
List<String> 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<String, String> 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<CustomerGroupDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(CustomerGroupDO::getId, FuncUtil.toStrList(vo.getCustomerGroupId()));
|
||||
wrapper.eq(BaseDO::getDeleted,false);
|
||||
wrapper.eq(BaseDO::getDeleted, false);
|
||||
List<CustomerGroupDO> groupDOS = customerGroupMapper.selectList(wrapper);
|
||||
String name = null;
|
||||
if(FuncUtil.isNotEmpty(groupDOS)){
|
||||
if (FuncUtil.isNotEmpty(groupDOS)) {
|
||||
List<String> 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<String> ids){
|
||||
|
||||
private void initCustomerGroupNameCache(Set<String> ids) {
|
||||
if (FuncUtil.isNotEmpty(ids)) {
|
||||
for (String db : ids) {
|
||||
LambdaQueryWrapper<CustomerGroupDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(CustomerGroupDO::getId, FuncUtil.toStrList(db));
|
||||
wrapper.eq(BaseDO::getDeleted,false);
|
||||
wrapper.eq(BaseDO::getDeleted, false);
|
||||
List<CustomerGroupDO> groupDOS = customerGroupMapper.selectList(wrapper);
|
||||
String name = null;
|
||||
if(FuncUtil.isNotEmpty(groupDOS)){
|
||||
if (FuncUtil.isNotEmpty(groupDOS)) {
|
||||
List<String> 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<Long, String> 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<String,Long> ProductTypeIdCache = CacheUtil.newLFUCache(10000, TMP_CACHE_TIME);
|
||||
private static LFUCache<String, Long> 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<ProductTypeDO> 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<Long> ids){
|
||||
|
||||
private void initProductTypeNameCache(Set<Long> ids) {
|
||||
ProductTypeNameCache.clear();
|
||||
if(FuncUtil.isNotEmpty(ids)){
|
||||
if (FuncUtil.isNotEmpty(ids)) {
|
||||
List<ProductTypeDO> 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<Long, String> 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<Long> ids){
|
||||
if(FuncUtil.isNotEmpty(ids)){
|
||||
|
||||
private void initBrandNameCache(Set<Long> ids) {
|
||||
if (FuncUtil.isNotEmpty(ids)) {
|
||||
List<BrandDO> brandDOS = brandMapper.selectBatchIds(ids);
|
||||
for (BrandDO brandDO : brandDOS) {
|
||||
brandNameCache.put(brandDO.getId(), brandDO.getName());
|
||||
|
|
|
|||
Loading…
Reference in New Issue