Compare commits
3 Commits
a6f53f4535
...
8569ff08a2
| Author | SHA1 | Date | |
|---|---|---|---|
| 8569ff08a2 | |||
| 04a34e6ed9 | |||
| ce8a386026 |
@ -612,7 +612,7 @@ public class SxDataDao extends BaseDao{
|
|||||||
public Integer getNewActiveCount(DataBaseInfo dataBaseInfo){
|
public Integer getNewActiveCount(DataBaseInfo dataBaseInfo){
|
||||||
String where=dataBaseInfo.getWhere()+" and rule_no in('DD','PS','PM') and range_flag='I'";
|
String where=dataBaseInfo.getWhere()+" and rule_no in('DD','PS','PM') and range_flag='I'";
|
||||||
return getBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),
|
return getBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),
|
||||||
T_PUB_PLAN_MASTER,where);
|
T_PUB_PLAN_MASTER+" b",where);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -74,15 +74,18 @@ public abstract class SxDataAbstService {
|
|||||||
sxCategoryModel.setCategory_name(sxSyncCategory.getItem_clsname());
|
sxCategoryModel.setCategory_name(sxSyncCategory.getItem_clsname());
|
||||||
sxCategoryModel.setBrandName(clsBrandMap.get(sxSyncCategory.getItem_clsname()));
|
sxCategoryModel.setBrandName(clsBrandMap.get(sxSyncCategory.getItem_clsname()));
|
||||||
//寻找父级
|
//寻找父级
|
||||||
if(null!=sxSyncCategory.getCls_parent()){
|
if(StringUtils.isNotEmpty(sxSyncCategory.getCls_parent())){
|
||||||
SxSyncCategory firstNode=getParentNode(allSxSyncCategories,sxSyncCategory.getCls_parent());
|
SxSyncCategory firstNode=getParentNode(allSxSyncCategories,sxSyncCategory.getCls_parent());
|
||||||
if(null==firstNode){
|
if(null==firstNode){
|
||||||
sxCategoryModel.setFirst_category_name("");
|
sxCategoryModel.setFirst_category_name("");
|
||||||
|
sxCategoryModel.setProduct_type(sxCategoryModel.getCategory_name());
|
||||||
|
sxCategoryModels.add(sxCategoryModel);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
sxCategoryModel.setParent_name(firstNode.getItem_clsname());//todo 暂时无用
|
sxCategoryModel.setParent_name(firstNode.getItem_clsname());//todo 暂时无用
|
||||||
//如何存在上级的上级,则上级为第二层,上上及为第一层
|
//如何存在上级的上级,则上级为第二层,上上及为第一层
|
||||||
if(null!=firstNode.getCls_parent()) {//还存在上级
|
if(StringUtils.isNotEmpty(firstNode.getCls_parent())) {//还存在上级
|
||||||
SxSyncCategory secondNode=getParentNode(allSxSyncCategories,sxSyncCategory.getCls_parent());
|
SxSyncCategory secondNode=getParentNode(allSxSyncCategories,firstNode.getCls_parent());
|
||||||
if(null!=secondNode && secondNode.getItem_clsno().equals(firstNode.getCls_parent())){
|
if(null!=secondNode && secondNode.getItem_clsno().equals(firstNode.getCls_parent())){
|
||||||
sxCategoryModel.setFirst_category_name(secondNode.getItem_clsname());
|
sxCategoryModel.setFirst_category_name(secondNode.getItem_clsname());
|
||||||
sxCategoryModel.setSecond_category_name(firstNode.getItem_clsname());
|
sxCategoryModel.setSecond_category_name(firstNode.getItem_clsname());
|
||||||
@ -98,9 +101,28 @@ public abstract class SxDataAbstService {
|
|||||||
sxCategoryModel.setProduct_type(sxCategoryModel.getCategory_name());
|
sxCategoryModel.setProduct_type(sxCategoryModel.getCategory_name());
|
||||||
sxCategoryModels.add(sxCategoryModel);
|
sxCategoryModels.add(sxCategoryModel);
|
||||||
}
|
}
|
||||||
|
sxCategoryModels=filterCategories(sxCategoryModels);
|
||||||
return sxCategoryModels;
|
return sxCategoryModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<SxCategoryModel> filterCategories(List<SxCategoryModel> categories) {
|
||||||
|
// 步骤1: 收集所有作为父类出现的名称
|
||||||
|
Set<String> parentNames = categories.stream()
|
||||||
|
.map(SxCategoryModel::getFirst_category_name)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
Set<String> rootParents = categories.stream()
|
||||||
|
.map(SxCategoryModel::getSecond_category_name)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
// 步骤2: 保留叶子节点(没有作为父类出现的节点)
|
||||||
|
return categories.stream()
|
||||||
|
.filter(category -> !parentNames.contains(category.getCategory_name()))
|
||||||
|
.filter(category -> !rootParents.contains(category.getCategory_name()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过流查找父节点
|
* 通过流查找父节点
|
||||||
* @param sxSyncCategories
|
* @param sxSyncCategories
|
||||||
|
|||||||
@ -728,7 +728,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
|
|||||||
String where="where 1=1";
|
String where="where 1=1";
|
||||||
Integer total =0;
|
Integer total =0;
|
||||||
if(StringUtils.isNotEmpty(commentModel.getSyncTime())){
|
if(StringUtils.isNotEmpty(commentModel.getSyncTime())){
|
||||||
where+=" and b.start_date>'"+commentModel.getSyncTime()+"' ";
|
where+=" and b.oper_date>'"+commentModel.getSyncTime()+"' ";
|
||||||
// where+=" or b.oper_date>'"+commentModel.getSyncTime()+"') ";
|
// where+=" or b.oper_date>'"+commentModel.getSyncTime()+"') ";
|
||||||
}
|
}
|
||||||
dataBaseInfo.setWhere(where);
|
dataBaseInfo.setWhere(where);
|
||||||
|
|||||||
@ -172,7 +172,8 @@ public class ShopProductBase implements Serializable{
|
|||||||
private BigDecimal shop_weight;
|
private BigDecimal shop_weight;
|
||||||
|
|
||||||
@ApiModelProperty("是否特价商品,0否,1是")
|
@ApiModelProperty("是否特价商品,0否,1是")
|
||||||
private String is_special="0";
|
@TableField(updateStrategy=NOT_EMPTY)
|
||||||
|
private String is_special;
|
||||||
|
|
||||||
@ApiModelProperty(value = "单价")
|
@ApiModelProperty(value = "单价")
|
||||||
@TableField(updateStrategy=NOT_EMPTY)
|
@TableField(updateStrategy=NOT_EMPTY)
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import java.util.*;
|
|||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -353,5 +354,15 @@ public class CommonUtil {
|
|||||||
return splitRatio.compareTo(BigDecimal.ZERO) >= 0 && splitRatio.compareTo(new BigDecimal(100)) <= 0;
|
return splitRatio.compareTo(BigDecimal.ZERO) >= 0 && splitRatio.compareTo(new BigDecimal(100)) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象去重工具
|
||||||
|
* @param keyExtractor
|
||||||
|
* @return
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||||
|
Set<Object> seen = new HashSet<>();
|
||||||
|
return t -> seen.add(keyExtractor.apply(t));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ public interface ShopBaseProductBrandService extends IBaseService<ShopBaseProduc
|
|||||||
* @param brand_name
|
* @param brand_name
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<ShopBaseProductBrand> selectByBrandName(String brand_name);
|
List<ShopBaseProductBrand> selectByBrandName(String brand_name,Integer storeId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增或更新品牌,判断品牌名一样后,不一样新增,再判断关键字段是否一样,不一样更改。
|
* 新增或更新品牌,判断品牌名一样后,不一样新增,再判断关键字段是否一样,不一样更改。
|
||||||
|
|||||||
@ -185,9 +185,10 @@ public class ShopBaseProductBrandServiceImpl extends BaseServiceImpl<ShopBasePro
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<ShopBaseProductBrand> selectByBrandName(String brand_name) {
|
public List<ShopBaseProductBrand> selectByBrandName(String brand_name,Integer storeId) {
|
||||||
QueryWrapper<ShopBaseProductBrand> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<ShopBaseProductBrand> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("brand_name", brand_name);
|
queryWrapper.eq("brand_name", brand_name);
|
||||||
|
queryWrapper.eq("store_id", storeId);
|
||||||
return list(queryWrapper);
|
return list(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +201,7 @@ public class ShopBaseProductBrandServiceImpl extends BaseServiceImpl<ShopBasePro
|
|||||||
@Override
|
@Override
|
||||||
public int saveOrUpdateBrand2(ShopBaseProductBrand shopBaseProductBrand) {
|
public int saveOrUpdateBrand2(ShopBaseProductBrand shopBaseProductBrand) {
|
||||||
|
|
||||||
List<ShopBaseProductBrand> list = selectByBrandName(shopBaseProductBrand.getBrand_name());
|
List<ShopBaseProductBrand> list = selectByBrandName(shopBaseProductBrand.getBrand_name(),shopBaseProductBrand.getStore_id());
|
||||||
if (ObjectUtil.isEmpty(list)) {
|
if (ObjectUtil.isEmpty(list)) {
|
||||||
// 新增记录
|
// 新增记录
|
||||||
if (saveOrUpdateBrand(shopBaseProductBrand)) {
|
if (saveOrUpdateBrand(shopBaseProductBrand)) {
|
||||||
|
|||||||
@ -59,8 +59,6 @@ public class ShopSyncImportController extends BaseControllerImpl {
|
|||||||
@ApiOperation(value = "品牌数据导入", notes = "品牌数据导入")
|
@ApiOperation(value = "品牌数据导入", notes = "品牌数据导入")
|
||||||
@RequestMapping(value = "/brandImportData", method = RequestMethod.POST)
|
@RequestMapping(value = "/brandImportData", method = RequestMethod.POST)
|
||||||
public CommonResult brandImportData(@RequestParam("file") MultipartFile file,@RequestParam("storeId")String storeId) {
|
public CommonResult brandImportData(@RequestParam("file") MultipartFile file,@RequestParam("storeId")String storeId) {
|
||||||
// ImportResult result = productMappingService.importData(file);
|
|
||||||
// return !result.getErrorMessages().isEmpty() ?CommonResult.failed((IErrorCode) result.getErrorMessages()):CommonResult.success(result);
|
|
||||||
return shopSyncImportService.importBrandData(file,storeId);
|
return shopSyncImportService.importBrandData(file,storeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,8 +69,6 @@ public class ShopSyncImportController extends BaseControllerImpl {
|
|||||||
@ApiOperation(value = "商品分类数据导入", notes = "分类数据导入")
|
@ApiOperation(value = "商品分类数据导入", notes = "分类数据导入")
|
||||||
@RequestMapping(value = "/categoryImportData", method = RequestMethod.POST)
|
@RequestMapping(value = "/categoryImportData", method = RequestMethod.POST)
|
||||||
public CommonResult categoryImportData(@RequestParam("file") MultipartFile file,@RequestParam("storeId")String storeId) {
|
public CommonResult categoryImportData(@RequestParam("file") MultipartFile file,@RequestParam("storeId")String storeId) {
|
||||||
// ImportResult result = productMappingService.importData(file);
|
|
||||||
// return !result.getErrorMessages().isEmpty() ?CommonResult.failed((IErrorCode) result.getErrorMessages()):CommonResult.success(result);
|
|
||||||
return shopSyncImportService.importCategoryData(file,storeId);
|
return shopSyncImportService.importCategoryData(file,storeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +79,6 @@ public class ShopSyncImportController extends BaseControllerImpl {
|
|||||||
@ApiOperation(value = "商品数据导入", notes = "分类数据导入")
|
@ApiOperation(value = "商品数据导入", notes = "分类数据导入")
|
||||||
@RequestMapping(value = "/shopImportData", method = RequestMethod.POST)
|
@RequestMapping(value = "/shopImportData", method = RequestMethod.POST)
|
||||||
public CommonResult shopImportData(@RequestParam("file") MultipartFile file,@RequestParam("storeId")String storeId) {
|
public CommonResult shopImportData(@RequestParam("file") MultipartFile file,@RequestParam("storeId")String storeId) {
|
||||||
// ImportResult result = productMappingService.importData(file);
|
|
||||||
// return !result.getErrorMessages().isEmpty() ?CommonResult.failed((IErrorCode) result.getErrorMessages()):CommonResult.success(result);
|
|
||||||
shopSyncImportService.importShopsData(file,storeId);
|
shopSyncImportService.importShopsData(file,storeId);
|
||||||
return CommonResult.success("服务器正则处理文件,稍后查看商品列表");
|
return CommonResult.success("服务器正则处理文件,稍后查看商品列表");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ public class SxCategoryModelExcel {
|
|||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "产品类型")
|
@ApiModelProperty(value = "产品类型")
|
||||||
@ExcelIgnore
|
@ExcelIgnore
|
||||||
private String product_type=category_name;
|
private String product_type=this.category_name;
|
||||||
/**
|
/**
|
||||||
* 第一级分类 当前分类的最顶层,如 生鲜->蔬菜->菜苗 如果当前分类(category_name)为菜苗,则第一级分类是”生鲜“,第二级分类是”蔬菜“,如果当前分类是蔬菜,则第一级分类是生鲜,第二级分类为空
|
* 第一级分类 当前分类的最顶层,如 生鲜->蔬菜->菜苗 如果当前分类(category_name)为菜苗,则第一级分类是”生鲜“,第二级分类是”蔬菜“,如果当前分类是蔬菜,则第一级分类是生鲜,第二级分类为空
|
||||||
* 第二级分类 当前分类最顶层数的第二层
|
* 第二级分类 当前分类最顶层数的第二层
|
||||||
@ -39,6 +39,6 @@ public class SxCategoryModelExcel {
|
|||||||
private String second_category_name;
|
private String second_category_name;
|
||||||
|
|
||||||
@ApiModelProperty(value = "品牌名称")
|
@ApiModelProperty(value = "品牌名称")
|
||||||
@ExcelIgnore
|
@ExcelProperty(value = "品牌名称", index =3)
|
||||||
private String brandName="其他品牌";
|
private String brandName;
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
package com.suisung.mall.shop.sync.listen;
|
package com.suisung.mall.shop.sync.listen;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.json.JSONArray;
|
import cn.hutool.json.JSONArray;
|
||||||
import com.alibaba.excel.context.AnalysisContext;
|
import com.alibaba.excel.context.AnalysisContext;
|
||||||
import com.alibaba.excel.event.AnalysisEventListener;
|
import com.alibaba.excel.event.AnalysisEventListener;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.suisung.mall.common.utils.CommonUtil;
|
||||||
|
import com.suisung.mall.common.utils.StringUtils;
|
||||||
import com.suisung.mall.shop.sync.exelModel.SxGoosModelExcel;
|
import com.suisung.mall.shop.sync.exelModel.SxGoosModelExcel;
|
||||||
import com.suisung.mall.shop.sync.service.SyncThirdDataService;
|
import com.suisung.mall.shop.sync.service.SyncThirdDataService;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -11,17 +14,19 @@ import lombok.Setter;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ShopBatchSubmitListener extends AnalysisEventListener<SxGoosModelExcel> {
|
public class ShopBatchSubmitListener extends AnalysisEventListener<SxGoosModelExcel> {
|
||||||
// 批处理阈值
|
// 批处理阈值
|
||||||
private static final int BATCH_SIZE = 10;
|
private static final int BATCH_SIZE = 500;
|
||||||
// 数据缓存
|
// 数据缓存
|
||||||
private List<SxGoosModelExcel> cachedDataList = new ArrayList<>(BATCH_SIZE);
|
private List<SxGoosModelExcel> cachedDataList = new ArrayList<>(BATCH_SIZE);
|
||||||
|
|
||||||
@ -51,7 +56,8 @@ public class ShopBatchSubmitListener extends AnalysisEventListener<SxGoosModelEx
|
|||||||
this.syncThirdDataService = syncThirdDataService;
|
this.syncThirdDataService = syncThirdDataService;
|
||||||
// 创建线程池(根据CPU核心数优化)
|
// 创建线程池(根据CPU核心数优化)
|
||||||
int corePoolSize = Runtime.getRuntime().availableProcessors();
|
int corePoolSize = Runtime.getRuntime().availableProcessors();
|
||||||
this.executorService = Executors.newFixedThreadPool(corePoolSize);
|
log.info("核心线程数量{}" , corePoolSize);
|
||||||
|
this.executorService = Executors.newFixedThreadPool(6);
|
||||||
this.futures = new ArrayList<>();
|
this.futures = new ArrayList<>();
|
||||||
this.success = new AtomicInteger();
|
this.success = new AtomicInteger();
|
||||||
this.fails = new AtomicInteger();
|
this.fails = new AtomicInteger();
|
||||||
@ -98,21 +104,61 @@ public class ShopBatchSubmitListener extends AnalysisEventListener<SxGoosModelEx
|
|||||||
|
|
||||||
private void submitBatch() {
|
private void submitBatch() {
|
||||||
// 复制当前批次数据(避免异步修改)
|
// 复制当前批次数据(避免异步修改)
|
||||||
List<SxGoosModelExcel> batchCopy = new ArrayList<>(cachedDataList);
|
List<SxGoosModelExcel> batchCopy = new ArrayList<>(deduplicateById(cachedDataList));
|
||||||
|
log.info("去重前:{};去重后:{}" , cachedDataList.size(), batchCopy.size());
|
||||||
|
final int index = batchSize.get();
|
||||||
futures.add(executorService.submit(()->{
|
futures.add(executorService.submit(()->{
|
||||||
try {
|
int i=0;
|
||||||
Gson gson=new Gson();
|
while (true){
|
||||||
String jsonShops=gson.toJson(batchCopy);
|
i++;
|
||||||
JSONArray jsonArray=new JSONArray(jsonShops);
|
try {
|
||||||
syncThirdDataService.baseSaveOrUpdateGoodsBatch(jsonArray,storeId,isNegativeAllowed,brandMaps);
|
Gson gson=new Gson();
|
||||||
log.info("已提交批次: {} 条", cachedDataList.size());
|
String jsonShops=gson.toJson(batchCopy);
|
||||||
success.getAndIncrement();
|
JSONArray jsonArray=new JSONArray(jsonShops);
|
||||||
return "完成"+batchSize.get();
|
syncThirdDataService.baseSaveOrUpdateGoodsBatch(jsonArray,storeId,isNegativeAllowed,brandMaps);
|
||||||
} catch (Exception e) {
|
log.info("已提交批次: {} 条", batchCopy.size());
|
||||||
fails.getAndIncrement();
|
success.getAndIncrement();
|
||||||
return "失败:"+batchSize.get()+";失败原因:"+e.getMessage();
|
return "完成批次:"+index;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if(i<2){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fails.getAndIncrement();
|
||||||
|
return "失败批次:"+index+";失败原因:"+e.getMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<SxGoosModelExcel> deduplicateById(List<SxGoosModelExcel> list) {
|
||||||
|
return list.stream()
|
||||||
|
.peek(sxGoosModelExcel -> {
|
||||||
|
if(StringUtils.isNotEmpty(sxGoosModelExcel.getShop_spec())){
|
||||||
|
sxGoosModelExcel.setProduct_spec(Collections.singletonList(sxGoosModelExcel.getShop_spec()));
|
||||||
|
}
|
||||||
|
if(null==sxGoosModelExcel.getUnit()){
|
||||||
|
sxGoosModelExcel.setUnit("");
|
||||||
|
}
|
||||||
|
if(ObjectUtil.isEmpty(sxGoosModelExcel.getBuy_limit())){
|
||||||
|
sxGoosModelExcel.setBuy_limit(0);
|
||||||
|
}
|
||||||
|
if(StringUtils.isEmpty(sxGoosModelExcel.getBrand_name())){
|
||||||
|
sxGoosModelExcel.setBrand_name("其它品牌");
|
||||||
|
}
|
||||||
|
if(ObjectUtil.isEmpty(sxGoosModelExcel.getStock())){
|
||||||
|
sxGoosModelExcel.setStock(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
sxGoosModelExcel.setProduct_number(sxGoosModelExcel.getProduct_barcode());
|
||||||
|
sxGoosModelExcel.setOriginal_price(sxGoosModelExcel.getRetail_price());
|
||||||
|
})
|
||||||
|
.filter(CommonUtil.distinctByKey(SxGoosModelExcel::getProduct_number))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -197,4 +197,5 @@ public interface SyncThirdDataService {
|
|||||||
int baseSaveOrUpdateGoodsBatch(JSONArray goodsListJSON,String storeId,String isNegativeAllowed,
|
int baseSaveOrUpdateGoodsBatch(JSONArray goodsListJSON,String storeId,String isNegativeAllowed,
|
||||||
Map<String,Integer> brandMaps);
|
Map<String,Integer> brandMaps);
|
||||||
|
|
||||||
|
void syncPrimaryKey();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,14 +6,18 @@ import com.alibaba.excel.EasyExcel;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.suisung.mall.common.api.CommonResult;
|
import com.suisung.mall.common.api.CommonResult;
|
||||||
|
import com.suisung.mall.common.enums.DicEnum;
|
||||||
import com.suisung.mall.common.exception.ApiException;
|
import com.suisung.mall.common.exception.ApiException;
|
||||||
import com.suisung.mall.common.modules.base.ShopBaseProductBrand;
|
import com.suisung.mall.common.modules.base.ShopBaseProductBrand;
|
||||||
import com.suisung.mall.common.modules.base.ShopBaseProductCategory;
|
import com.suisung.mall.common.modules.base.ShopBaseProductCategory;
|
||||||
import com.suisung.mall.common.modules.sync.StoreDbConfig;
|
import com.suisung.mall.common.modules.sync.StoreDbConfig;
|
||||||
import com.suisung.mall.shop.base.service.ShopBaseProductBrandService;
|
import com.suisung.mall.shop.base.service.ShopBaseProductBrandService;
|
||||||
|
import com.suisung.mall.shop.base.service.ShopBaseProductCategoryService;
|
||||||
|
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
||||||
import com.suisung.mall.shop.sync.excleHandle.TemplateStyleHandler;
|
import com.suisung.mall.shop.sync.excleHandle.TemplateStyleHandler;
|
||||||
import com.suisung.mall.shop.sync.exelModel.*;
|
import com.suisung.mall.shop.sync.exelModel.*;
|
||||||
import com.suisung.mall.shop.sync.listen.ShopBatchSubmitListener;
|
import com.suisung.mall.shop.sync.listen.ShopBatchSubmitListener;
|
||||||
|
import com.suisung.mall.shop.sync.service.ProductMappingService;
|
||||||
import com.suisung.mall.shop.sync.service.ShopSyncImportService;
|
import com.suisung.mall.shop.sync.service.ShopSyncImportService;
|
||||||
import com.suisung.mall.shop.sync.service.StoreDbConfigService;
|
import com.suisung.mall.shop.sync.service.StoreDbConfigService;
|
||||||
import com.suisung.mall.shop.sync.service.SyncThirdDataService;
|
import com.suisung.mall.shop.sync.service.SyncThirdDataService;
|
||||||
@ -48,7 +52,15 @@ public class ShopSyncImportServiceImpl implements ShopSyncImportService {
|
|||||||
private ShopBaseProductBrandService productBrandService;
|
private ShopBaseProductBrandService productBrandService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private StoreDbConfigService storeDbConfigService;
|
private StoreDbConfigService storeDbConfigService;
|
||||||
|
@Autowired
|
||||||
|
private ProductMappingService productMappingService;
|
||||||
|
@Autowired
|
||||||
|
private ShopNumberSeqService shopNumberSeqService;
|
||||||
|
@Autowired
|
||||||
|
private ShopBaseProductCategoryService shopBaseProductCategoryService;
|
||||||
|
|
||||||
private final int limitCnt = 100;
|
private final int limitCnt = 100;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadBrandTemplate(HttpServletResponse response) {
|
public void downloadBrandTemplate(HttpServletResponse response) {
|
||||||
try {
|
try {
|
||||||
@ -193,14 +205,20 @@ public class ShopSyncImportServiceImpl implements ShopSyncImportService {
|
|||||||
}
|
}
|
||||||
// 读取商品分类Excel数据
|
// 读取商品分类Excel数据
|
||||||
private List<SxCategoryModelExcel> readCategoryExcelData(String filePath) {
|
private List<SxCategoryModelExcel> readCategoryExcelData(String filePath) {
|
||||||
return EasyExcel.read(filePath)
|
List<SxCategoryModelExcel> excelList= EasyExcel.read(filePath)
|
||||||
.head(SxCategoryModelExcel.class)
|
.head(SxCategoryModelExcel.class)
|
||||||
.sheet()
|
.sheet()
|
||||||
.doReadSync();
|
.doReadSync();
|
||||||
|
excelList.forEach(excel->{
|
||||||
|
excel.setProduct_type(excel.getCategory_name());
|
||||||
|
});
|
||||||
|
return excelList;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取商品Excel数据
|
// 读取商品Excel数据
|
||||||
private void readAndImportShopsExcelData(String filePath,String storeId) {
|
private void readAndImportShopsExcelData(String filePath,String storeId) {
|
||||||
|
cleanCache(storeId);//清理redis数据
|
||||||
|
initData(storeId);//初始化分类到redis缓存
|
||||||
Map<String, Integer> brandMaps = productBrandService.getBrandMapByStoreId(storeId);
|
Map<String, Integer> brandMaps = productBrandService.getBrandMapByStoreId(storeId);
|
||||||
QueryWrapper<StoreDbConfig> storeDbConfigQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<StoreDbConfig> storeDbConfigQueryWrapper = new QueryWrapper<>();
|
||||||
storeDbConfigQueryWrapper.eq("store_id", storeId);
|
storeDbConfigQueryWrapper.eq("store_id", storeId);
|
||||||
@ -211,5 +229,22 @@ public class ShopSyncImportServiceImpl implements ShopSyncImportService {
|
|||||||
shopBatchSubmitListener.setBrandMaps(brandMaps);
|
shopBatchSubmitListener.setBrandMaps(brandMaps);
|
||||||
shopBatchSubmitListener.setIsNegativeAllowed(isNegativeAllowed);
|
shopBatchSubmitListener.setIsNegativeAllowed(isNegativeAllowed);
|
||||||
EasyExcel.read(filePath,SxGoosModelExcel.class,shopBatchSubmitListener).sheet().doRead();
|
EasyExcel.read(filePath,SxGoosModelExcel.class,shopBatchSubmitListener).sheet().doRead();
|
||||||
|
productMappingService.syncAllProductMapping(Integer.valueOf(storeId), DicEnum.YESORNO_0.getCode());
|
||||||
|
syncThirdDataService.syncShopImages(Integer.valueOf(storeId));
|
||||||
|
cleanCache(storeId);//清理redis数据
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanCache(String storeId){
|
||||||
|
syncThirdDataService.syncPrimaryKey();
|
||||||
|
shopNumberSeqService.clearKey();
|
||||||
|
shopBaseProductCategoryService.clearCategoryCache(storeId);
|
||||||
|
shopNumberSeqService.clearKeyStoreItemSepcId();
|
||||||
|
productBrandService.clearBrandMapByStoreId(storeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initData(String storeId){
|
||||||
|
shopBaseProductCategoryService.getCategoryListByStoreId(storeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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,9 +286,15 @@ 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());
|
||||||
@ -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());
|
||||||
productTypeList.add(productType);
|
if(null==productTypeListMap.get(productType.getType_name())){
|
||||||
|
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")));
|
||||||
//积分价
|
//积分价
|
||||||
shopProductItem.setItem_unit_points(new BigDecimal(jsonObj.getInt("points")));
|
if(null!=jsonObj.get("points")){
|
||||||
|
shopProductItem.setItem_unit_points(new BigDecimal(jsonObj.getInt("points")));
|
||||||
|
}
|
||||||
shopProductItem.setItem_quantity(stock.intValue());
|
shopProductItem.setItem_quantity(stock.intValue());
|
||||||
//todo 特色商品切割
|
//todo 特色商品切割
|
||||||
//负数产品判断
|
//负数产品判断
|
||||||
@ -944,7 +1007,7 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
* @param storeId
|
* @param storeId
|
||||||
*/
|
*/
|
||||||
private synchronized void saveBatchShopProductProductSpec(String storeId,List<ShopBaseProductType> shopBaseProductTypes){
|
private synchronized void saveBatchShopProductProductSpec(String storeId,List<ShopBaseProductType> shopBaseProductTypes){
|
||||||
Map categoryMap= productCategoryService.getCategoryListByStoreId(storeId);
|
Map categoryMap= productCategoryService.getCategoryListByStoreId(storeId);
|
||||||
List<ShopBaseProductSpec> shopBaseProductSpecList=new ArrayList<>();
|
List<ShopBaseProductSpec> shopBaseProductSpecList=new ArrayList<>();
|
||||||
Set<Map.Entry> categoryMapSet= categoryMap.entrySet();
|
Set<Map.Entry> categoryMapSet= categoryMap.entrySet();
|
||||||
for(Map.Entry categoryMapEntry:categoryMapSet){
|
for(Map.Entry categoryMapEntry:categoryMapSet){
|
||||||
@ -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);
|
||||||
|
|||||||
@ -151,11 +151,6 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ShopBaseProductCategoryService shopBaseProductCategoryService;
|
private ShopBaseProductCategoryService shopBaseProductCategoryService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ShopProductSpecItemService shopProductSpecItemService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ShopBaseProductSpecService baseProductSpecService;
|
|
||||||
|
|
||||||
@Value("#{accountBaseConfigService.getConfig('tengxun_default_dir')}")
|
@Value("#{accountBaseConfigService.getConfig('tengxun_default_dir')}")
|
||||||
private String TENGXUN_DEFA;
|
private String TENGXUN_DEFA;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user