|
|
@ -6,7 +6,9 @@ |
|
|
|
package com.shop.cereshop.business.service.checkImport.impl; |
|
|
|
|
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.shop.cereshop.business.page.storehouse.Storehouse; |
|
|
|
import com.shop.cereshop.business.param.product.*; |
|
|
|
import com.shop.cereshop.business.param.storehouse.ShopStorehouseGetAllParam; |
|
|
|
import com.shop.cereshop.business.service.checkImport.ImportCheckService; |
|
|
|
import com.shop.cereshop.business.service.product.CereProductClassifyService; |
|
|
|
import com.shop.cereshop.business.service.product.CereProductSkuService; |
|
|
@ -18,9 +20,7 @@ import com.shop.cereshop.commons.constant.IntegerEnum; |
|
|
|
import com.shop.cereshop.commons.constant.StringEnum; |
|
|
|
import com.shop.cereshop.commons.domain.product.CereProductClassify; |
|
|
|
import com.shop.cereshop.commons.domain.product.CereShopProduct; |
|
|
|
import com.shop.cereshop.commons.domain.shop.CerePlatformShop; |
|
|
|
import com.shop.cereshop.commons.domain.shop.CereShopGroup; |
|
|
|
import com.shop.cereshop.commons.domain.storehouse.CereShopStorehouse; |
|
|
|
import com.shop.cereshop.commons.exception.CoBusinessException; |
|
|
|
import com.shop.cereshop.commons.utils.EmptyUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
@ -55,33 +55,51 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
private CereShopStorehouseService cereShopStorehouseService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<ProductSaveParam> checkProduct(List<ProductImport> list) throws CoBusinessException { |
|
|
|
public List<ProductSaveParam> checkProduct(Long shopId, List<ProductImport> list) throws CoBusinessException { |
|
|
|
String message=""; |
|
|
|
List<ProductSaveParam> products=new ArrayList<>(); |
|
|
|
|
|
|
|
Map<String,ProductSaveParam> productMaps=new HashMap<>(); |
|
|
|
|
|
|
|
if(!EmptyUtils.isEmpty(list)){ |
|
|
|
Map<String,ProductImport> map=new HashMap<>(); |
|
|
|
//校验是否存在重复商品名称数据 |
|
|
|
for (ProductImport item : list) { |
|
|
|
if(!EmptyUtils.isEmpty(map.get(item.getProductName()))){ |
|
|
|
if(!EmptyUtils.isEmpty(map.get(item.getProductName() + "--" + item.getSkuValue()))){ |
|
|
|
//如果存在 |
|
|
|
message+=item.getProductName()+";"; |
|
|
|
}else { |
|
|
|
map.put(item.getProductName(),item); |
|
|
|
map.put(item.getProductName() + "--" + item.getSkuValue(),item); |
|
|
|
} |
|
|
|
} |
|
|
|
if(map.size()!=list.size()){ |
|
|
|
message+="以上数据在表格中有重复,请修改后重试!"; |
|
|
|
} |
|
|
|
if(!EmptyUtils.isEmpty(message)){ |
|
|
|
throw new CoBusinessException(message); |
|
|
|
} |
|
|
|
|
|
|
|
//校验必填项 |
|
|
|
for (ProductImport productImport : list) { |
|
|
|
if (EmptyUtils.isEmpty(productImport.getOneClassifyName()) |
|
|
|
|| EmptyUtils.isEmpty(productImport.getProductName()) |
|
|
|
|| EmptyUtils.isEmpty(productImport.getSkuValue()) || EmptyUtils.isEmpty(productImport.getPrice()) |
|
|
|
|| EmptyUtils.isEmpty(productImport.getOriginalPrice())) { |
|
|
|
message += "存在必填项为空的数据,请检查后重试"; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!EmptyUtils.isEmpty(message)){ |
|
|
|
throw new CoBusinessException(message); |
|
|
|
} |
|
|
|
|
|
|
|
//定义分类map |
|
|
|
Map<String,CereProductClassify> classifyMap=new HashMap<>(); |
|
|
|
//定义分组map |
|
|
|
Map<String,CereShopGroup> groupMap=new HashMap<>(); |
|
|
|
//定义商品map |
|
|
|
Map<String,CereShopProduct> productMap=new HashMap<>(); |
|
|
|
//定义商家map |
|
|
|
Map<String,CerePlatformShop> shopMap=new HashMap<>(); |
|
|
|
Map<String,CereShopProduct> dbProductMap=new HashMap<>(); |
|
|
|
//定义仓库map |
|
|
|
Map<String,CereShopStorehouse> storehouseMap=new HashMap<>(); |
|
|
|
Map<String,Storehouse> storehouseMap=new HashMap<>(); |
|
|
|
|
|
|
|
//查询所有分类数据 |
|
|
|
List<CereProductClassify> classifies=cereProductClassifyService.selectAll(); |
|
|
|
if(!EmptyUtils.isEmpty(classifies)){ |
|
|
@ -89,42 +107,29 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
} |
|
|
|
|
|
|
|
//分组数据 |
|
|
|
List<CereShopGroup> groups=cereShopGroupService.selectAll(); |
|
|
|
ProductGetGroupParam shopGroupParam = new ProductGetGroupParam(); |
|
|
|
shopGroupParam.setShopId(shopId); |
|
|
|
List<CereShopGroup> groups = cereShopGroupService.getGroupSelect(shopGroupParam); |
|
|
|
if(!EmptyUtils.isEmpty(groups)){ |
|
|
|
groups.forEach((item)->groupMap.put(item.getShopId()+"-"+item.getGroupName(), item)); |
|
|
|
} |
|
|
|
|
|
|
|
//查询所有商品数据 |
|
|
|
List<CereShopProduct> productList=cereShopProductService.selectAll(); |
|
|
|
List<CereShopProduct> productList=cereShopProductService.selectAllByShopId(shopId); |
|
|
|
if(!EmptyUtils.isEmpty(productList)){ |
|
|
|
productList.forEach((item)->productMap.put(item.getShopId()+"-"+item.getClassifyId()+"-"+item.getProductName(),item)); |
|
|
|
productList.forEach((item)->dbProductMap.put(item.getShopId()+"-"+item.getClassifyId()+"-"+item.getProductName(),item)); |
|
|
|
} |
|
|
|
|
|
|
|
//查询所有仓库 |
|
|
|
List<CereShopStorehouse> storehouseList= cereShopStorehouseService.selectAll(); |
|
|
|
ShopStorehouseGetAllParam storehouseParams = new ShopStorehouseGetAllParam(); |
|
|
|
storehouseParams.setShopId(shopId); |
|
|
|
List<Storehouse> storehouseList= cereShopStorehouseService.selectAllByParam(storehouseParams); |
|
|
|
if(!EmptyUtils.isEmpty(storehouseList)){ |
|
|
|
storehouseList.forEach((item)->storehouseMap.put(item.getShopId()+"-"+item.getStorehouseName(),item)); |
|
|
|
} |
|
|
|
|
|
|
|
//查询所有商家 |
|
|
|
List<CerePlatformShop> shops=cerePlatformShopService.selectAll(); |
|
|
|
if(!EmptyUtils.isEmpty(shops)){ |
|
|
|
shops.forEach((item)->shopMap.put(item.getShopName(),item)); |
|
|
|
} |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
ProductSaveParam param=new ProductSaveParam(); |
|
|
|
ProductImport productImport = list.get(i); |
|
|
|
//校验必填项 |
|
|
|
if(EmptyUtils.isEmpty(productImport.getShopName())||EmptyUtils.isEmpty(productImport.getOneClassifyName()) |
|
|
|
||EmptyUtils.isEmpty(productImport.getProductName()) |
|
|
|
||EmptyUtils.isEmpty(productImport.getSkuValue())||EmptyUtils.isEmpty(productImport.getPrice()) |
|
|
|
||EmptyUtils.isEmpty(productImport.getOriginalPrice())){ |
|
|
|
message+="存在必填项为空的数据,请检查后重试"; |
|
|
|
} |
|
|
|
//根据商家名称查询商家是否存在 |
|
|
|
if(EmptyUtils.isEmpty(shopMap.get(productImport.getShopName()))){ |
|
|
|
message+="第"+(i+3)+"行商家未注册;"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
String classifyName=""; |
|
|
|
if(!EmptyUtils.isEmpty(productImport.getOneClassifyName())){ |
|
|
@ -136,7 +141,7 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
if(!EmptyUtils.isEmpty(productImport.getThreeClassifyName())){ |
|
|
|
classifyName+="-"+productImport.getThreeClassifyName(); |
|
|
|
} |
|
|
|
CerePlatformShop shop = shopMap.get(productImport.getShopName()); |
|
|
|
|
|
|
|
log.info("商品分类:"+classifyName); |
|
|
|
CereProductClassify classify = classifyMap.get(classifyName); |
|
|
|
if(EmptyUtils.isEmpty(classify)){ |
|
|
@ -144,29 +149,32 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String key=shop.getShopId()+"-"+classify.getClassifyId()+"-"+productImport.getProductName(); |
|
|
|
CereShopGroup cereShopGroup = groupMap.get(shop.getShopId()+"-"+productImport.getShopGroupName()); |
|
|
|
CereShopGroup cereShopGroup = groupMap.get(shopId+"-"+productImport.getShopGroupName()); |
|
|
|
|
|
|
|
if(EmptyUtils.isEmpty(cereShopGroup)){ |
|
|
|
message+="第"+(i+3)+"行分类数据出错;"; |
|
|
|
message+="第"+(i+3)+"行分组数据出错;"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
if(EmptyUtils.isEmpty(storehouseMap.get(shop.getShopId()+"-"+productImport.getStorehouseName()))){ |
|
|
|
if(EmptyUtils.isEmpty(storehouseMap.get(shopId+"-"+productImport.getStorehouseName()))){ |
|
|
|
message+="第"+(i+3)+"行仓库出错;"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
//校验商品是否已存在 |
|
|
|
if(!EmptyUtils.isEmpty(productMap.get(key))){ |
|
|
|
message+="第"+(i+3)+"行商品已存在;"; |
|
|
|
|
|
|
|
String productKey = productImport.getProductName(); |
|
|
|
|
|
|
|
ProductSaveParam param = new ProductSaveParam(); |
|
|
|
if(productMaps.containsKey(productKey)){ |
|
|
|
//重复商品进行累加 |
|
|
|
param = productMaps.get(productKey); |
|
|
|
}else { |
|
|
|
productMaps.put(productKey, param); |
|
|
|
|
|
|
|
//正常商品数据封装 |
|
|
|
param.setShopId(shop.getShopId()); |
|
|
|
param.setShopId(shopId); |
|
|
|
param.setClassifyId(classify.getClassifyId()); |
|
|
|
param.setProductName(productImport.getProductName()); |
|
|
|
param.setSupplierName(productImport.getSupplierName()); |
|
|
|
|
|
|
|
param.setShopGroupId(cereShopGroup.getShopGroupId()); |
|
|
|
|
|
|
|
if(!EmptyUtils.isEmpty(productImport.getIfLogistics())){ |
|
|
@ -196,39 +204,51 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
}else { |
|
|
|
param.setShelveState(String.valueOf(IntegerEnum.YES.getCode())); |
|
|
|
} |
|
|
|
//封装规格数据 |
|
|
|
List<SkuParam> skus=new ArrayList<>(); |
|
|
|
SkuParam cereProductSku=new SkuParam(); |
|
|
|
List<SkuNameValueParam> cereSkuNames=new ArrayList<>(); |
|
|
|
NameValue nameValue=new NameValue(); |
|
|
|
nameValue.setSkuValue(productImport.getSkuValue()); |
|
|
|
cereProductSku.setNameValue(nameValue); |
|
|
|
cereProductSku.setSkuAttrCodeDTOList(cereSkuNames); |
|
|
|
cereProductSku.setPrice(productImport.getPrice()); |
|
|
|
cereProductSku.setRate(productImport.getRate()); |
|
|
|
|
|
|
|
CereShopStorehouse cereShopStorehouse = storehouseMap.get(shop.getShopId()+"-"+productImport.getStorehouseName()); |
|
|
|
cereProductSku.setStorehouseId(cereShopStorehouse.getStorehouseId().intValue()); |
|
|
|
|
|
|
|
if(!EmptyUtils.isEmpty(productImport.getIsCross())){ |
|
|
|
cereProductSku.setIsCross(0); |
|
|
|
|
|
|
|
//校验商品是否已存在 |
|
|
|
String dbProductKey=shopId+"-"+classify.getClassifyId()+"-"+productImport.getProductName(); |
|
|
|
if(dbProductMap.containsKey(dbProductKey)){ |
|
|
|
param.setProductId(dbProductMap.get(dbProductKey).getProductId()); |
|
|
|
}else { |
|
|
|
cereProductSku.setIsCross(new Integer(productImport.getIsCross())); |
|
|
|
param.setProductId(null); |
|
|
|
} |
|
|
|
cereProductSku.setSku(productImport.getSku()); |
|
|
|
cereProductSku.setOriginalPrice(productImport.getOriginalPrice()); |
|
|
|
cereProductSku.setStockNumber(productImport.getStockNumber()); |
|
|
|
cereProductSku.setWeight(productImport.getWeight()); |
|
|
|
log.info(new Gson().toJson(cereProductSku)); |
|
|
|
skus.add(cereProductSku); |
|
|
|
} |
|
|
|
|
|
|
|
//封装规格数据 |
|
|
|
List<SkuParam> skus= param.getSkus(); |
|
|
|
if(skus == null){ |
|
|
|
skus = new ArrayList<>(); |
|
|
|
param.setSkus(skus); |
|
|
|
products.add(param); |
|
|
|
} |
|
|
|
|
|
|
|
SkuParam cereProductSku=new SkuParam(); |
|
|
|
List<SkuNameValueParam> cereSkuNames=new ArrayList<>(); |
|
|
|
NameValue nameValue=new NameValue(); |
|
|
|
nameValue.setSkuValue(productImport.getSkuValue()); |
|
|
|
cereProductSku.setNameValue(nameValue); |
|
|
|
cereProductSku.setSkuAttrCodeDTOList(cereSkuNames); |
|
|
|
cereProductSku.setPrice(productImport.getPrice()); |
|
|
|
cereProductSku.setRate(productImport.getRate()); |
|
|
|
|
|
|
|
Storehouse cereShopStorehouse = storehouseMap.get(shopId+"-"+productImport.getStorehouseName()); |
|
|
|
cereProductSku.setStorehouseId(cereShopStorehouse.getStorehouseId().intValue()); |
|
|
|
|
|
|
|
if(!EmptyUtils.isEmpty(productImport.getIsCross())){ |
|
|
|
cereProductSku.setIsCross(0); |
|
|
|
}else { |
|
|
|
cereProductSku.setIsCross(new Integer(productImport.getIsCross())); |
|
|
|
} |
|
|
|
cereProductSku.setSku(productImport.getSku()); |
|
|
|
cereProductSku.setOriginalPrice(productImport.getOriginalPrice()); |
|
|
|
cereProductSku.setStockNumber(productImport.getStockNumber()); |
|
|
|
cereProductSku.setWeight(productImport.getWeight()); |
|
|
|
log.info(new Gson().toJson(cereProductSku)); |
|
|
|
skus.add(cereProductSku); |
|
|
|
} |
|
|
|
if(!EmptyUtils.isEmpty(message)){ |
|
|
|
throw new CoBusinessException(message); |
|
|
|
} |
|
|
|
} |
|
|
|
return products; |
|
|
|
return new ArrayList<>(productMaps.values()); |
|
|
|
} |
|
|
|
} |