|
|
@ -5,19 +5,25 @@ |
|
|
|
*/ |
|
|
|
package com.shop.cereshop.business.service.checkImport.impl; |
|
|
|
|
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.shop.cereshop.business.param.product.*; |
|
|
|
import com.shop.cereshop.business.service.checkImport.ImportCheckService; |
|
|
|
import com.shop.cereshop.business.service.product.CereProductClassifyService; |
|
|
|
import com.shop.cereshop.business.service.product.CereProductSkuService; |
|
|
|
import com.shop.cereshop.business.service.product.CereShopProductService; |
|
|
|
import com.shop.cereshop.business.service.shop.CerePlatformShopService; |
|
|
|
import com.shop.cereshop.business.service.shop.CereShopGroupService; |
|
|
|
import com.shop.cereshop.business.service.storehouse.CereShopStorehouseService; |
|
|
|
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; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
@ -27,6 +33,7 @@ import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
|
|
|
|
@Autowired |
|
|
@ -41,6 +48,12 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
@Autowired |
|
|
|
private CereProductClassifyService cereProductClassifyService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CereShopGroupService cereShopGroupService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CereShopStorehouseService cereShopStorehouseService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<ProductSaveParam> checkProduct(List<ProductImport> list) throws CoBusinessException { |
|
|
|
String message=""; |
|
|
@ -61,20 +74,37 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
} |
|
|
|
//定义分类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 |
|
|
|
Map<String,CereShopStorehouse> storehouseMap=new HashMap<>(); |
|
|
|
//查询所有分类数据 |
|
|
|
List<CereProductClassify> classifies=cereProductClassifyService.selectAll(); |
|
|
|
if(!EmptyUtils.isEmpty(classifies)){ |
|
|
|
classifies.forEach((item)->classifyMap.put(item.getClassifyHierarchy(),item)); |
|
|
|
} |
|
|
|
|
|
|
|
//分组数据 |
|
|
|
List<CereShopGroup> groups=cereShopGroupService.selectAll(); |
|
|
|
if(!EmptyUtils.isEmpty(groups)){ |
|
|
|
groups.forEach((item)->groupMap.put(item.getShopId()+"-"+item.getGroupName(), item)); |
|
|
|
} |
|
|
|
//查询所有商品数据 |
|
|
|
List<CereShopProduct> productList=cereShopProductService.selectAll(); |
|
|
|
if(!EmptyUtils.isEmpty(productList)){ |
|
|
|
productList.forEach((item)->productMap.put(item.getShopId()+"-"+item.getClassifyId()+"-"+item.getProductName(),item)); |
|
|
|
} |
|
|
|
|
|
|
|
//查询所有仓库 |
|
|
|
List<CereShopStorehouse> storehouseList= cereShopStorehouseService.selectAll(); |
|
|
|
if(!EmptyUtils.isEmpty(storehouseList)){ |
|
|
|
storehouseList.forEach((item)->storehouseMap.put(item.getShopId()+"-"+item.getStorehouseName(),item)); |
|
|
|
} |
|
|
|
|
|
|
|
//查询所有商家 |
|
|
|
List<CerePlatformShop> shops=cerePlatformShopService.selectAll(); |
|
|
|
if(!EmptyUtils.isEmpty(shops)){ |
|
|
@ -93,7 +123,9 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
//根据商家名称查询商家是否存在 |
|
|
|
if(EmptyUtils.isEmpty(shopMap.get(productImport.getShopName()))){ |
|
|
|
message+="第"+(i+3)+"行商家未注册;"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
String classifyName=""; |
|
|
|
if(!EmptyUtils.isEmpty(productImport.getOneClassifyName())){ |
|
|
|
classifyName+="-"+productImport.getOneClassifyName(); |
|
|
@ -104,13 +136,27 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
if(!EmptyUtils.isEmpty(productImport.getThreeClassifyName())){ |
|
|
|
classifyName+="-"+productImport.getThreeClassifyName(); |
|
|
|
} |
|
|
|
//查询分类是否存在 |
|
|
|
if(EmptyUtils.isEmpty(classifyMap.get(classifyName))){ |
|
|
|
message+="第"+(i+3)+"行分类不存在;"; |
|
|
|
} |
|
|
|
CerePlatformShop shop = shopMap.get(productImport.getShopName()); |
|
|
|
log.info("商品分类:"+classifyName); |
|
|
|
CereProductClassify classify = classifyMap.get(classifyName); |
|
|
|
if(EmptyUtils.isEmpty(classify)){ |
|
|
|
message+="第"+(i+3)+"行分类出错;"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String key=shop.getShopId()+"-"+classify.getClassifyId()+"-"+productImport.getProductName(); |
|
|
|
CereShopGroup cereShopGroup = groupMap.get(shop.getShopId()+"-"+productImport.getShopGroupName()); |
|
|
|
|
|
|
|
if(EmptyUtils.isEmpty(cereShopGroup)){ |
|
|
|
message+="第"+(i+3)+"行分类数据出错;"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
if(EmptyUtils.isEmpty(storehouseMap.get(shop.getShopId()+"-"+productImport.getStorehouseName()))){ |
|
|
|
message+="第"+(i+3)+"行仓库出错;"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
//校验商品是否已存在 |
|
|
|
if(!EmptyUtils.isEmpty(productMap.get(key))){ |
|
|
|
message+="第"+(i+3)+"行商品已存在;"; |
|
|
@ -120,6 +166,9 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
param.setClassifyId(classify.getClassifyId()); |
|
|
|
param.setProductName(productImport.getProductName()); |
|
|
|
param.setSupplierName(productImport.getSupplierName()); |
|
|
|
|
|
|
|
param.setShopGroupId(cereShopGroup.getShopGroupId()); |
|
|
|
|
|
|
|
if(!EmptyUtils.isEmpty(productImport.getIfLogistics())){ |
|
|
|
if(productImport.getIfLogistics().equals(StringEnum.YES.getCode())){ |
|
|
|
param.setIfLogistics(String.valueOf(IntegerEnum.YES.getCode())); |
|
|
@ -156,9 +205,21 @@ public class importCheckServiceImpl implements ImportCheckService { |
|
|
|
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); |
|
|
|
}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); |
|
|
|
param.setSkus(skus); |
|
|
|
products.add(param); |
|
|
|