商品同步excel导入
This commit is contained in:
parent
04a34e6ed9
commit
8569ff08a2
@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 思迅同步商品数据入口数据
|
* 思迅同步商品数据入口数据
|
||||||
@ -18,19 +19,19 @@ public class SxGoosModelExcel {
|
|||||||
private String product_name;
|
private String product_name;
|
||||||
|
|
||||||
@ApiModelProperty("商品货号")
|
@ApiModelProperty("商品货号")
|
||||||
@ExcelProperty(value = "商品货号", index = 1)
|
@ExcelIgnore
|
||||||
private String product_number;
|
private String product_number;
|
||||||
|
|
||||||
@ApiModelProperty("商品条形码")
|
@ApiModelProperty("商品条形码")
|
||||||
@ExcelProperty(value = "商品条形码", index = 2)
|
@ExcelProperty(value = "商品条形码", index = 1)
|
||||||
private String product_barcode;
|
private String product_barcode;
|
||||||
|
|
||||||
@ApiModelProperty("所属分类")
|
@ApiModelProperty("所属分类")
|
||||||
@ExcelProperty(value = "所属分类", index = 3)
|
@ExcelProperty(value = "所属分类", index = 2)
|
||||||
private String first_category_name;
|
private String first_category_name;
|
||||||
|
|
||||||
@ApiModelProperty("零售价")
|
@ApiModelProperty("零售价")
|
||||||
@ExcelProperty(value = "零售价", index = 4)
|
@ExcelProperty(value = "零售价", index = 3)
|
||||||
private BigDecimal retail_price;
|
private BigDecimal retail_price;
|
||||||
|
|
||||||
@ApiModelProperty("原价")
|
@ApiModelProperty("原价")
|
||||||
@ -38,15 +39,28 @@ public class SxGoosModelExcel {
|
|||||||
private BigDecimal original_price=retail_price;
|
private BigDecimal original_price=retail_price;
|
||||||
|
|
||||||
@ApiModelProperty("库存")
|
@ApiModelProperty("库存")
|
||||||
@ExcelProperty(value = "库存", index = 5)
|
@ExcelProperty(value = "库存", index = 4)
|
||||||
private BigDecimal stock;
|
private BigDecimal stock;
|
||||||
|
|
||||||
|
@ApiModelProperty("规格")
|
||||||
|
@ExcelProperty(value = "规格", index = 5)
|
||||||
|
private String shop_spec;
|
||||||
|
|
||||||
@ApiModelProperty("规格单位")
|
@ApiModelProperty("规格单位")
|
||||||
@ExcelProperty(value = "规格单位", index = 6)
|
@ExcelProperty(value = "规格单位", index = 6)
|
||||||
private String unit;
|
private String unit;
|
||||||
|
|
||||||
@ApiModelProperty("最大购买商品量")
|
@ApiModelProperty("规格(JSON)-规格、规格值、goods_id 规格不需要全选就可以添加对应数据[")
|
||||||
@ExcelProperty(value = "最大购买商品量", index = 7)
|
@ExcelIgnore
|
||||||
|
private List<String> product_spec;
|
||||||
|
|
||||||
|
@ApiModelProperty("商品限购数量")
|
||||||
|
@ExcelProperty(value = "商品限购数量", index = 7)
|
||||||
private Integer buy_limit;
|
private Integer buy_limit;
|
||||||
|
|
||||||
|
@ApiModelProperty("品牌名称")
|
||||||
|
@ExcelProperty(value = "品牌名称", index = 8)
|
||||||
|
private String brand_name;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -130,6 +130,7 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
String storeId){
|
String storeId){
|
||||||
int count = 0;
|
int count = 0;
|
||||||
List<ShopBaseProductType> productTypeList = new ArrayList<>();
|
List<ShopBaseProductType> productTypeList = new ArrayList<>();
|
||||||
|
Map<String,String> productTypeListMap=new HashMap<>();
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
String categoryName=list.get(i).getCategory_name();
|
String categoryName=list.get(i).getCategory_name();
|
||||||
if(StringUtils.isNotEmpty(getForbidCategory(categoryName))){
|
if(StringUtils.isNotEmpty(getForbidCategory(categoryName))){
|
||||||
@ -143,7 +144,15 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
ShopBaseProductType productType=new ShopBaseProductType();
|
ShopBaseProductType productType=new ShopBaseProductType();
|
||||||
productType.setType_is_draft(1);//发布
|
productType.setType_is_draft(1);//发布
|
||||||
productType.setStore_id(Integer.valueOf(storeId));
|
productType.setStore_id(Integer.valueOf(storeId));
|
||||||
String brandName=o.getStr("brandName","其他品牌");
|
String brandName=o.getStr("brandName","其它品牌");
|
||||||
|
QueryWrapper<ShopBaseProductBrand> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("store_id",Integer.valueOf(storeId));
|
||||||
|
queryWrapper.in("brand_name",Arrays.asList(brandName.split(",")));
|
||||||
|
// queryWrapper.eq("brand_name",brandName);
|
||||||
|
List<ShopBaseProductBrand> shopBaseProductBrands=productBrandService.list(queryWrapper);
|
||||||
|
String brandIds=shopBaseProductBrands.stream()
|
||||||
|
.map(shopBaseProductBrand -> String.valueOf(shopBaseProductBrand.getBrand_id()))
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
// 重要:分类类型处理(强调共性)
|
// 重要:分类类型处理(强调共性)
|
||||||
Integer typeId = 1001;
|
Integer typeId = 1001;
|
||||||
@ -153,24 +162,20 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
if (productType != null) {
|
if (productType != null) {
|
||||||
typeId = productType.getType_id();
|
typeId = productType.getType_id();
|
||||||
} else {
|
} else {
|
||||||
QueryWrapper<ShopBaseProductBrand> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("store_id",Integer.valueOf(storeId));
|
|
||||||
queryWrapper.eq("brand_name",brandName);
|
|
||||||
ShopBaseProductBrand shopBaseProductBrand=productBrandService.findOne(queryWrapper);
|
|
||||||
// 新增一个类型
|
// 新增一个类型
|
||||||
ShopBaseProductType newProductType = new ShopBaseProductType();
|
ShopBaseProductType newProductType = new ShopBaseProductType();
|
||||||
newProductType.setType_name(o.getStr("product_type"));
|
newProductType.setType_name(o.getStr("product_type"));
|
||||||
newProductType.setType_buildin(0);
|
newProductType.setType_buildin(0);
|
||||||
newProductType.setType_is_draft(0);//发布
|
newProductType.setType_is_draft(0);//发布
|
||||||
newProductType.setStore_id(Integer.valueOf(storeId));
|
newProductType.setStore_id(Integer.valueOf(storeId));
|
||||||
if(null!=shopBaseProductBrand){
|
|
||||||
newProductType.setType_brand_ids(String.valueOf(shopBaseProductBrand.getBrand_id()));
|
|
||||||
}
|
|
||||||
if (productTypeService.save(newProductType)) {
|
if (productTypeService.save(newProductType)) {
|
||||||
typeId = newProductType.getType_id();
|
typeId = newProductType.getType_id();
|
||||||
}
|
}
|
||||||
productType=newProductType;
|
productType=newProductType;
|
||||||
}
|
}
|
||||||
|
if(StringUtils.isNotEmpty(brandIds)){
|
||||||
|
productType.setType_brand_ids(brandIds);
|
||||||
|
}
|
||||||
list.get(i).setType_id(typeId);
|
list.get(i).setType_id(typeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,16 +191,38 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
}
|
}
|
||||||
// TODO storeId 不判断一下吗?
|
// TODO storeId 不判断一下吗?
|
||||||
ShopBaseProductCategory cate = productCategoryService.getCategoryByName(firstCategoryName,storeId);
|
ShopBaseProductCategory cate = productCategoryService.getCategoryByName(firstCategoryName,storeId);
|
||||||
|
ShopBaseProductType first_category_name_type=productTypeService.getProductTypeByName(firstCategoryName,storeId);
|
||||||
|
Integer firstTypeId = 1001;
|
||||||
|
if(null!=first_category_name_type){
|
||||||
|
firstTypeId = first_category_name_type.getType_id();
|
||||||
|
}else {
|
||||||
|
first_category_name_type=new ShopBaseProductType();
|
||||||
|
first_category_name_type.setType_name(firstCategoryName);
|
||||||
|
first_category_name_type.setType_buildin(0);
|
||||||
|
first_category_name_type.setType_is_draft(0);//发布
|
||||||
|
first_category_name_type.setStore_id(Integer.valueOf(storeId));
|
||||||
|
if (productTypeService.save(first_category_name_type)) {
|
||||||
|
firstTypeId = first_category_name_type.getType_id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(StringUtils.isNotEmpty(brandIds)){
|
||||||
|
first_category_name_type.setType_brand_ids(brandIds);
|
||||||
|
}
|
||||||
|
|
||||||
if (cate != null) {
|
if (cate != null) {
|
||||||
list.get(i).setCategory_parent_id(cate.getCategory_id());
|
list.get(i).setCategory_parent_id(cate.getCategory_id());
|
||||||
|
first_category_name_type.setType_category_id(cate.getCategory_id());
|
||||||
|
firstParentId=cate.getCategory_id();
|
||||||
} else{
|
} else{
|
||||||
// 新增一个(第一级)父类
|
// 新增一个(第一级)父类
|
||||||
ShopBaseProductCategory firstCate = new ShopBaseProductCategory();
|
ShopBaseProductCategory firstCate = new ShopBaseProductCategory();
|
||||||
firstCate.setCategory_name(firstCategoryName);
|
firstCate.setCategory_name(firstCategoryName);
|
||||||
firstCate.setParent_id(0);
|
firstCate.setParent_id(0);
|
||||||
firstCate.setStore_id(storeId);
|
firstCate.setStore_id(storeId);
|
||||||
firstCate.setType_id(typeId);
|
firstCate.setType_id(firstTypeId);
|
||||||
firstCate.setData_source(2);
|
firstCate.setData_source(2);
|
||||||
|
firstCate.setCategory_image(list.get(i).getCategory_image());
|
||||||
List<LibraryProductDTO> libraryProductDTOS=libraryProductService.matchLibraryProducts(null,firstCategoryName,new ArrayList<>());
|
List<LibraryProductDTO> libraryProductDTOS=libraryProductService.matchLibraryProducts(null,firstCategoryName,new ArrayList<>());
|
||||||
if(CollectionUtil.isNotEmpty(libraryProductDTOS)){
|
if(CollectionUtil.isNotEmpty(libraryProductDTOS)){
|
||||||
firstCate.setCategory_image(libraryProductDTOS.get(0).getThumb());
|
firstCate.setCategory_image(libraryProductDTOS.get(0).getThumb());
|
||||||
@ -206,6 +233,11 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
list.get(i).setCategory_parent_id(firstParentId);
|
list.get(i).setCategory_parent_id(firstParentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(null==productTypeListMap.get(first_category_name_type.getType_name())){
|
||||||
|
first_category_name_type.setType_category_id(firstParentId);
|
||||||
|
productTypeList.add(first_category_name_type);
|
||||||
|
productTypeListMap.put(first_category_name_type.getType_name(),first_category_name_type.getType_name());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,16 +250,35 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
}
|
}
|
||||||
// TODO storeId 不判断一下吗?
|
// TODO storeId 不判断一下吗?
|
||||||
ShopBaseProductCategory cate = productCategoryService.getCategoryByName(secondCategoryName,storeId);
|
ShopBaseProductCategory cate = productCategoryService.getCategoryByName(secondCategoryName,storeId);
|
||||||
|
ShopBaseProductType second_category_type=productTypeService.getProductTypeByName(secondCategoryName,storeId);
|
||||||
|
Integer secondTypeId = 1001;
|
||||||
|
if(null!=second_category_type){
|
||||||
|
secondTypeId = second_category_type.getType_id();
|
||||||
|
}else {
|
||||||
|
second_category_type=new ShopBaseProductType();
|
||||||
|
second_category_type.setType_name(secondCategoryName);
|
||||||
|
second_category_type.setType_buildin(0);
|
||||||
|
second_category_type.setType_is_draft(0);//发布
|
||||||
|
second_category_type.setStore_id(Integer.valueOf(storeId));
|
||||||
|
if (productTypeService.save(second_category_type)) {
|
||||||
|
secondTypeId = second_category_type.getType_id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(StringUtils.isNotEmpty(brandIds)){
|
||||||
|
second_category_type.setType_brand_ids(brandIds);
|
||||||
|
}
|
||||||
if (cate != null) {
|
if (cate != null) {
|
||||||
list.get(i).setCategory_parent_id(cate.getCategory_id());
|
list.get(i).setCategory_parent_id(cate.getCategory_id());
|
||||||
|
second_category_type.setType_category_id(cate.getCategory_id());
|
||||||
} else {
|
} else {
|
||||||
// 新增一个(第二级)父类
|
// 新增一个(第二级)父类
|
||||||
ShopBaseProductCategory secondCate = new ShopBaseProductCategory();
|
ShopBaseProductCategory secondCate = new ShopBaseProductCategory();
|
||||||
secondCate.setCategory_name(secondCategoryName);
|
secondCate.setCategory_name(secondCategoryName);
|
||||||
secondCate.setCategory_parent_id(firstParentId);
|
secondCate.setCategory_parent_id(firstParentId);
|
||||||
secondCate.setStore_id(storeId);
|
secondCate.setStore_id(storeId);
|
||||||
secondCate.setType_id(typeId);
|
secondCate.setType_id(secondTypeId);
|
||||||
secondCate.setData_source(2);
|
secondCate.setData_source(2);
|
||||||
|
secondCate.setCategory_image(list.get(i).getCategory_image());
|
||||||
List<LibraryProductDTO> libraryProductDTOS=libraryProductService.matchLibraryProducts(null,secondCategoryName,new ArrayList<>());
|
List<LibraryProductDTO> libraryProductDTOS=libraryProductService.matchLibraryProducts(null,secondCategoryName,new ArrayList<>());
|
||||||
if(CollectionUtil.isNotEmpty(libraryProductDTOS)){
|
if(CollectionUtil.isNotEmpty(libraryProductDTOS)){
|
||||||
secondCate.setCategory_image(libraryProductDTOS.get(0).getThumb());
|
secondCate.setCategory_image(libraryProductDTOS.get(0).getThumb());
|
||||||
@ -235,11 +286,17 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
if (productCategoryService.saveOrUpdate(secondCate)) {
|
if (productCategoryService.saveOrUpdate(secondCate)) {
|
||||||
// 当前子分类的第二级父类id
|
// 当前子分类的第二级父类id
|
||||||
list.get(i).setCategory_parent_id(secondCate.getCategory_id());
|
list.get(i).setCategory_parent_id(secondCate.getCategory_id());
|
||||||
|
second_category_type.setType_category_id(secondCate.getCategory_id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(null==productTypeListMap.get(second_category_type.getType_name())) {
|
||||||
|
productTypeList.add(second_category_type);
|
||||||
|
productTypeListMap.put(second_category_type.getType_name(), second_category_type.getType_name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
ShopBaseProductCategory productCategoryTemp = productCategoryService.getCategoryByName(list.get(i).getCategory_parent_id(), list.get(i).getCategory_name(), list.get(i).getStore_id());
|
ShopBaseProductCategory productCategoryTemp = productCategoryService.getCategoryByName(list.get(i).getCategory_parent_id(), list.get(i).getCategory_name(), list.get(i).getStore_id());
|
||||||
if (productCategoryTemp != null) {
|
if (productCategoryTemp != null) {
|
||||||
// 更改记录
|
// 更改记录
|
||||||
@ -262,7 +319,11 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
productType.setType_category_id(list.get(i).getCategory_id());
|
productType.setType_category_id(list.get(i).getCategory_id());
|
||||||
|
if(null==productTypeListMap.get(productType.getType_name())){
|
||||||
productTypeList.add(productType);
|
productTypeList.add(productType);
|
||||||
|
productTypeListMap.put(productType.getType_name(),productType.getType_name());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
saveBatchShopProductProductSpec(storeId,productTypeList);
|
saveBatchShopProductProductSpec(storeId,productTypeList);
|
||||||
return count;
|
return count;
|
||||||
@ -749,7 +810,7 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
shopProductBase.setProduct_from(1005);// 商品来源(ENUM):1000-发布;1001-天猫;1002-淘宝;1003-阿里巴巴;1004-京东;1005-思迅;
|
shopProductBase.setProduct_from(1005);// 商品来源(ENUM):1000-发布;1001-天猫;1002-淘宝;1003-阿里巴巴;1004-京东;1005-思迅;
|
||||||
shopProductBase.setProduct_add_time(currentDate.getTime());
|
shopProductBase.setProduct_add_time(currentDate.getTime());
|
||||||
shopProductBase.setProduct_unit_price(BigDecimal.valueOf(jsonObj.getDouble("retail_price")));
|
shopProductBase.setProduct_unit_price(BigDecimal.valueOf(jsonObj.getDouble("retail_price")));
|
||||||
String isSpecial=jsonObj.getStr("isSpecial");
|
String isSpecial=jsonObj.getStr("isSpecial",DicEnum.YESORNO_0.getCode());
|
||||||
if(ObjectUtil.equals(isSpecial,DicEnum.YESORNO_0.getCode())||ObjectUtil.equals(isSpecial,DicEnum.YESORNO_1.getCode())){
|
if(ObjectUtil.equals(isSpecial,DicEnum.YESORNO_0.getCode())||ObjectUtil.equals(isSpecial,DicEnum.YESORNO_1.getCode())){
|
||||||
shopProductBase.setIs_special(isSpecial);//是否特价商品 特价商品需要手动上架 todo 是否要开发定时上架功能
|
shopProductBase.setIs_special(isSpecial);//是否特价商品 特价商品需要手动上架 todo 是否要开发定时上架功能
|
||||||
}else {
|
}else {
|
||||||
@ -867,7 +928,9 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
shopProductItem.setItem_advice_price(BigDecimal.valueOf(jsonObj.getDouble("retail_price")));
|
shopProductItem.setItem_advice_price(BigDecimal.valueOf(jsonObj.getDouble("retail_price")));
|
||||||
shopProductItem.setItem_market_price(BigDecimal.valueOf(jsonObj.getDouble("original_price")));
|
shopProductItem.setItem_market_price(BigDecimal.valueOf(jsonObj.getDouble("original_price")));
|
||||||
//积分价
|
//积分价
|
||||||
|
if(null!=jsonObj.get("points")){
|
||||||
shopProductItem.setItem_unit_points(new BigDecimal(jsonObj.getInt("points")));
|
shopProductItem.setItem_unit_points(new BigDecimal(jsonObj.getInt("points")));
|
||||||
|
}
|
||||||
shopProductItem.setItem_quantity(stock.intValue());
|
shopProductItem.setItem_quantity(stock.intValue());
|
||||||
//todo 特色商品切割
|
//todo 特色商品切割
|
||||||
//负数产品判断
|
//负数产品判断
|
||||||
@ -996,7 +1059,7 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
if(CollectionUtil.isNotEmpty(shopBaseProductTypes)){
|
if(CollectionUtil.isNotEmpty(shopBaseProductTypes)){
|
||||||
productTypeService.updateBatchById(shopBaseProductTypes,shopBaseProductTypes.size());
|
productTypeService.updateBatchById(shopBaseProductTypes,shopBaseProductTypes.size());
|
||||||
}
|
}
|
||||||
|
productCategoryService.clearCategoryCache(storeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1008,7 +1071,7 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
.map(ShopBaseProductSpec::getSpec_name)
|
.map(ShopBaseProductSpec::getSpec_name)
|
||||||
.distinct()
|
.distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<ShopBaseProductSpec> existing = batchGetByStoreAndShopBaseProductSpec(storeProductPairs);
|
List<ShopBaseProductSpec> existing = batchGetByStoreAndShopBaseProductSpec(storeProductPairs,productSpecs.get(0).getStore_id());
|
||||||
return existing.stream()
|
return existing.stream()
|
||||||
.collect(Collectors.toMap(
|
.collect(Collectors.toMap(
|
||||||
ShopBaseProductSpec::getSpec_name,
|
ShopBaseProductSpec::getSpec_name,
|
||||||
@ -1019,14 +1082,14 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
/**
|
/**
|
||||||
* 批量根据店铺和货号查询商品
|
* 批量根据店铺和货号查询商品
|
||||||
*/
|
*/
|
||||||
private List<ShopBaseProductSpec> batchGetByStoreAndShopBaseProductSpec(List<String> ShopBaseProductSpecStr) {
|
private List<ShopBaseProductSpec> batchGetByStoreAndShopBaseProductSpec(List<String> ShopBaseProductSpecStr,Integer storeId) {
|
||||||
if (CollUtil.isEmpty(ShopBaseProductSpecStr)) {
|
if (CollUtil.isEmpty(ShopBaseProductSpecStr)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
QueryWrapper<ShopBaseProductSpec> query = new QueryWrapper<>();
|
QueryWrapper<ShopBaseProductSpec> query = new QueryWrapper<>();
|
||||||
query.select("spec_id", "spec_name");
|
query.select("spec_id", "spec_name");
|
||||||
ShopBaseProductSpecStr.forEach(specName -> {
|
ShopBaseProductSpecStr.forEach(specName -> {
|
||||||
query.or(q -> q.eq("spec_name", specName));
|
query.or(q -> q.eq("spec_name", specName).eq("store_id",storeId));
|
||||||
});
|
});
|
||||||
|
|
||||||
return shopBaseProductSpecService.list(query);
|
return shopBaseProductSpecService.list(query);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user