Compare commits

..

No commits in common. "d4833f235b909aa3eff621894a7194d07c79228f" and "2d12bb9353cb503c0a8a1c8bf2b3e41dc1ac037f" have entirely different histories.

15 changed files with 66 additions and 249 deletions

View File

@ -612,7 +612,7 @@ public class SxDataDao extends BaseDao{
public Integer getNewActiveCount(DataBaseInfo dataBaseInfo){
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(),
T_PUB_PLAN_MASTER+" b",where);
T_PUB_PLAN_MASTER,where);
}
/**

View File

@ -74,18 +74,15 @@ public abstract class SxDataAbstService {
sxCategoryModel.setCategory_name(sxSyncCategory.getItem_clsname());
sxCategoryModel.setBrandName(clsBrandMap.get(sxSyncCategory.getItem_clsname()));
//寻找父级
if(StringUtils.isNotEmpty(sxSyncCategory.getCls_parent())){
if(null!=sxSyncCategory.getCls_parent()){
SxSyncCategory firstNode=getParentNode(allSxSyncCategories,sxSyncCategory.getCls_parent());
if(null==firstNode){
sxCategoryModel.setFirst_category_name("");
sxCategoryModel.setProduct_type(sxCategoryModel.getCategory_name());
sxCategoryModels.add(sxCategoryModel);
continue;
}
sxCategoryModel.setParent_name(firstNode.getItem_clsname());//todo 暂时无用
//如何存在上级的上级则上级为第二层上上及为第一层
if(StringUtils.isNotEmpty(firstNode.getCls_parent())) {//还存在上级
SxSyncCategory secondNode=getParentNode(allSxSyncCategories,firstNode.getCls_parent());
if(null!=firstNode.getCls_parent()) {//还存在上级
SxSyncCategory secondNode=getParentNode(allSxSyncCategories,sxSyncCategory.getCls_parent());
if(null!=secondNode && secondNode.getItem_clsno().equals(firstNode.getCls_parent())){
sxCategoryModel.setFirst_category_name(secondNode.getItem_clsname());
sxCategoryModel.setSecond_category_name(firstNode.getItem_clsname());
@ -101,28 +98,9 @@ public abstract class SxDataAbstService {
sxCategoryModel.setProduct_type(sxCategoryModel.getCategory_name());
sxCategoryModels.add(sxCategoryModel);
}
sxCategoryModels=filterCategories(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

View File

@ -728,7 +728,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
String where="where 1=1";
Integer total =0;
if(StringUtils.isNotEmpty(commentModel.getSyncTime())){
where+=" and b.oper_date>'"+commentModel.getSyncTime()+"' ";
where+=" and b.start_date>'"+commentModel.getSyncTime()+"' ";
// where+=" or b.oper_date>'"+commentModel.getSyncTime()+"') ";
}
dataBaseInfo.setWhere(where);

View File

@ -172,8 +172,7 @@ public class ShopProductBase implements Serializable{
private BigDecimal shop_weight;
@ApiModelProperty("是否特价商品,0否1是")
@TableField(updateStrategy=NOT_EMPTY)
private String is_special;
private String is_special="0";
@ApiModelProperty(value = "单价")
@TableField(updateStrategy=NOT_EMPTY)

View File

@ -18,7 +18,6 @@ import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
@ -328,15 +327,5 @@ public class CommonUtil {
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));
}
}

View File

@ -39,7 +39,7 @@ public interface ShopBaseProductBrandService extends IBaseService<ShopBaseProduc
* @param brand_name
* @return
*/
List<ShopBaseProductBrand> selectByBrandName(String brand_name,Integer storeId);
List<ShopBaseProductBrand> selectByBrandName(String brand_name);
/**
* 新增或更新品牌判断品牌名一样后不一样新增再判断关键字段是否一样不一样更改

View File

@ -185,10 +185,9 @@ public class ShopBaseProductBrandServiceImpl extends BaseServiceImpl<ShopBasePro
* @return
*/
@Override
public List<ShopBaseProductBrand> selectByBrandName(String brand_name,Integer storeId) {
public List<ShopBaseProductBrand> selectByBrandName(String brand_name) {
QueryWrapper<ShopBaseProductBrand> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("brand_name", brand_name);
queryWrapper.eq("store_id", storeId);
return list(queryWrapper);
}
@ -201,7 +200,7 @@ public class ShopBaseProductBrandServiceImpl extends BaseServiceImpl<ShopBasePro
@Override
public int saveOrUpdateBrand2(ShopBaseProductBrand shopBaseProductBrand) {
List<ShopBaseProductBrand> list = selectByBrandName(shopBaseProductBrand.getBrand_name(),shopBaseProductBrand.getStore_id());
List<ShopBaseProductBrand> list = selectByBrandName(shopBaseProductBrand.getBrand_name());
if (ObjectUtil.isEmpty(list)) {
// 新增记录
if (saveOrUpdateBrand(shopBaseProductBrand)) {

View File

@ -59,6 +59,8 @@ public class ShopSyncImportController extends BaseControllerImpl {
@ApiOperation(value = "品牌数据导入", notes = "品牌数据导入")
@RequestMapping(value = "/brandImportData", method = RequestMethod.POST)
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);
}
@ -69,6 +71,8 @@ public class ShopSyncImportController extends BaseControllerImpl {
@ApiOperation(value = "商品分类数据导入", notes = "分类数据导入")
@RequestMapping(value = "/categoryImportData", method = RequestMethod.POST)
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);
}
@ -79,6 +83,8 @@ public class ShopSyncImportController extends BaseControllerImpl {
@ApiOperation(value = "商品数据导入", notes = "分类数据导入")
@RequestMapping(value = "/shopImportData", method = RequestMethod.POST)
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);
return CommonResult.success("服务器正则处理文件,稍后查看商品列表");
}

View File

@ -26,7 +26,7 @@ public class SxCategoryModelExcel {
*/
@ApiModelProperty(value = "产品类型")
@ExcelIgnore
private String product_type=this.category_name;
private String product_type=category_name;
/**
* 第一级分类 当前分类的最顶层 生鲜->蔬菜->菜苗 如果当前分类category_name为菜苗则第一级分类是生鲜第二级分类是蔬菜如果当前分类是蔬菜则第一级分类是生鲜第二级分类为空
* 第二级分类 当前分类最顶层数的第二层
@ -39,6 +39,6 @@ public class SxCategoryModelExcel {
private String second_category_name;
@ApiModelProperty(value = "品牌名称")
@ExcelProperty(value = "品牌名称", index =3)
private String brandName;
@ExcelIgnore
private String brandName="其他品牌";
}

View File

@ -6,7 +6,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* 思迅同步商品数据入口数据
@ -19,19 +18,19 @@ public class SxGoosModelExcel {
private String product_name;
@ApiModelProperty("商品货号")
@ExcelIgnore
@ExcelProperty(value = "商品货号", index = 1)
private String product_number;
@ApiModelProperty("商品条形码")
@ExcelProperty(value = "商品条形码", index = 1)
@ExcelProperty(value = "商品条形码", index = 2)
private String product_barcode;
@ApiModelProperty("所属分类")
@ExcelProperty(value = "所属分类", index = 2)
@ExcelProperty(value = "所属分类", index = 3)
private String first_category_name;
@ApiModelProperty("零售价")
@ExcelProperty(value = "零售价", index = 3)
@ExcelProperty(value = "零售价", index = 4)
private BigDecimal retail_price;
@ApiModelProperty("原价")
@ -39,28 +38,15 @@ public class SxGoosModelExcel {
private BigDecimal original_price=retail_price;
@ApiModelProperty("库存")
@ExcelProperty(value = "库存", index = 4)
@ExcelProperty(value = "库存", index = 5)
private BigDecimal stock;
@ApiModelProperty("规格")
@ExcelProperty(value = "规格", index = 5)
private String shop_spec;
@ApiModelProperty("规格单位")
@ExcelProperty(value = "规格单位", index = 6)
private String unit;
@ApiModelProperty("规格(JSON)-规格、规格值、goods_id 规格不需要全选就可以添加对应数据[")
@ExcelIgnore
private List<String> product_spec;
@ApiModelProperty("商品限购数量")
@ExcelProperty(value = "商品限购数量", index = 7)
@ApiModelProperty("最大购买商品量")
@ExcelProperty(value = "最大购买商品量", index = 7)
private Integer buy_limit;
@ApiModelProperty("品牌名称")
@ExcelProperty(value = "品牌名称", index = 8)
private String brand_name;
}

View File

@ -1,12 +1,9 @@
package com.suisung.mall.shop.sync.listen;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
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.service.SyncThirdDataService;
import lombok.Getter;
@ -14,19 +11,17 @@ import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@Component
@Slf4j
public class ShopBatchSubmitListener extends AnalysisEventListener<SxGoosModelExcel> {
// 批处理阈值
private static final int BATCH_SIZE = 500;
private static final int BATCH_SIZE = 10;
// 数据缓存
private List<SxGoosModelExcel> cachedDataList = new ArrayList<>(BATCH_SIZE);
@ -56,8 +51,7 @@ public class ShopBatchSubmitListener extends AnalysisEventListener<SxGoosModelEx
this.syncThirdDataService = syncThirdDataService;
// 创建线程池根据CPU核心数优化
int corePoolSize = Runtime.getRuntime().availableProcessors();
log.info("核心线程数量{}" , corePoolSize);
this.executorService = Executors.newFixedThreadPool(6);
this.executorService = Executors.newFixedThreadPool(corePoolSize);
this.futures = new ArrayList<>();
this.success = new AtomicInteger();
this.fails = new AtomicInteger();
@ -104,61 +98,21 @@ public class ShopBatchSubmitListener extends AnalysisEventListener<SxGoosModelEx
private void submitBatch() {
// 复制当前批次数据避免异步修改
List<SxGoosModelExcel> batchCopy = new ArrayList<>(deduplicateById(cachedDataList));
log.info("去重前:{};去重后:{}" , cachedDataList.size(), batchCopy.size());
final int index = batchSize.get();
List<SxGoosModelExcel> batchCopy = new ArrayList<>(cachedDataList);
futures.add(executorService.submit(()->{
int i=0;
while (true){
i++;
try {
Gson gson=new Gson();
String jsonShops=gson.toJson(batchCopy);
JSONArray jsonArray=new JSONArray(jsonShops);
syncThirdDataService.baseSaveOrUpdateGoodsBatch(jsonArray,storeId,isNegativeAllowed,brandMaps);
log.info("已提交批次: {} 条", batchCopy.size());
log.info("已提交批次: {} 条", cachedDataList.size());
success.getAndIncrement();
return "完成批次:"+index;
return "完成"+batchSize.get();
} catch (Exception e) {
if(i<2){
continue;
}
fails.getAndIncrement();
return "失败批次:"+index+";失败原因:"+e.getMessage();
}
return "失败:"+batchSize.get()+";失败原因:"+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());
}
}

View File

@ -197,5 +197,4 @@ public interface SyncThirdDataService {
int baseSaveOrUpdateGoodsBatch(JSONArray goodsListJSON,String storeId,String isNegativeAllowed,
Map<String,Integer> brandMaps);
void syncPrimaryKey();
}

View File

@ -6,18 +6,14 @@ import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.Gson;
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.modules.base.ShopBaseProductBrand;
import com.suisung.mall.common.modules.base.ShopBaseProductCategory;
import com.suisung.mall.common.modules.sync.StoreDbConfig;
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.exelModel.*;
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.StoreDbConfigService;
import com.suisung.mall.shop.sync.service.SyncThirdDataService;
@ -52,15 +48,7 @@ public class ShopSyncImportServiceImpl implements ShopSyncImportService {
private ShopBaseProductBrandService productBrandService;
@Autowired
private StoreDbConfigService storeDbConfigService;
@Autowired
private ProductMappingService productMappingService;
@Autowired
private ShopNumberSeqService shopNumberSeqService;
@Autowired
private ShopBaseProductCategoryService shopBaseProductCategoryService;
private final int limitCnt = 100;
@Override
public void downloadBrandTemplate(HttpServletResponse response) {
try {
@ -205,20 +193,14 @@ public class ShopSyncImportServiceImpl implements ShopSyncImportService {
}
// 读取商品分类Excel数据
private List<SxCategoryModelExcel> readCategoryExcelData(String filePath) {
List<SxCategoryModelExcel> excelList= EasyExcel.read(filePath)
return EasyExcel.read(filePath)
.head(SxCategoryModelExcel.class)
.sheet()
.doReadSync();
excelList.forEach(excel->{
excel.setProduct_type(excel.getCategory_name());
});
return excelList;
}
// 读取商品Excel数据
private void readAndImportShopsExcelData(String filePath,String storeId) {
cleanCache(storeId);//清理redis数据
initData(storeId);//初始化分类到redis缓存
Map<String, Integer> brandMaps = productBrandService.getBrandMapByStoreId(storeId);
QueryWrapper<StoreDbConfig> storeDbConfigQueryWrapper = new QueryWrapper<>();
storeDbConfigQueryWrapper.eq("store_id", storeId);
@ -229,22 +211,5 @@ public class ShopSyncImportServiceImpl implements ShopSyncImportService {
shopBatchSubmitListener.setBrandMaps(brandMaps);
shopBatchSubmitListener.setIsNegativeAllowed(isNegativeAllowed);
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);
}
}

View File

@ -130,7 +130,6 @@ public abstract class SyncBaseThirdSxAbstract{
String storeId){
int count = 0;
List<ShopBaseProductType> productTypeList = new ArrayList<>();
Map<String,String> productTypeListMap=new HashMap<>();
for (int i = 0; i < list.size(); i++) {
String categoryName=list.get(i).getCategory_name();
if(StringUtils.isNotEmpty(getForbidCategory(categoryName))){
@ -144,15 +143,7 @@ public abstract class SyncBaseThirdSxAbstract{
ShopBaseProductType productType=new ShopBaseProductType();
productType.setType_is_draft(1);//发布
productType.setStore_id(Integer.valueOf(storeId));
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(","));
String brandName=o.getStr("brandName","其他品牌");
if (o != null) {
// 重要分类类型处理强调共性
Integer typeId = 1001;
@ -162,20 +153,24 @@ public abstract class SyncBaseThirdSxAbstract{
if (productType != null) {
typeId = productType.getType_id();
} 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();
newProductType.setType_name(o.getStr("product_type"));
newProductType.setType_buildin(0);
newProductType.setType_is_draft(0);//发布
newProductType.setStore_id(Integer.valueOf(storeId));
if(null!=shopBaseProductBrand){
newProductType.setType_brand_ids(String.valueOf(shopBaseProductBrand.getBrand_id()));
}
if (productTypeService.save(newProductType)) {
typeId = newProductType.getType_id();
}
productType=newProductType;
}
if(StringUtils.isNotEmpty(brandIds)){
productType.setType_brand_ids(brandIds);
}
list.get(i).setType_id(typeId);
}
@ -191,38 +186,16 @@ public abstract class SyncBaseThirdSxAbstract{
}
// TODO 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) {
list.get(i).setCategory_parent_id(cate.getCategory_id());
first_category_name_type.setType_category_id(cate.getCategory_id());
firstParentId=cate.getCategory_id();
} else{
// 新增一个第一级父类
ShopBaseProductCategory firstCate = new ShopBaseProductCategory();
firstCate.setCategory_name(firstCategoryName);
firstCate.setParent_id(0);
firstCate.setStore_id(storeId);
firstCate.setType_id(firstTypeId);
firstCate.setType_id(typeId);
firstCate.setData_source(2);
firstCate.setCategory_image(list.get(i).getCategory_image());
List<LibraryProductDTO> libraryProductDTOS=libraryProductService.matchLibraryProducts(null,firstCategoryName,new ArrayList<>());
if(CollectionUtil.isNotEmpty(libraryProductDTOS)){
firstCate.setCategory_image(libraryProductDTOS.get(0).getThumb());
@ -233,11 +206,6 @@ public abstract class SyncBaseThirdSxAbstract{
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());
}
}
@ -250,35 +218,16 @@ public abstract class SyncBaseThirdSxAbstract{
}
// TODO 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) {
list.get(i).setCategory_parent_id(cate.getCategory_id());
second_category_type.setType_category_id(cate.getCategory_id());
} else {
// 新增一个第二级父类
ShopBaseProductCategory secondCate = new ShopBaseProductCategory();
secondCate.setCategory_name(secondCategoryName);
secondCate.setCategory_parent_id(firstParentId);
secondCate.setStore_id(storeId);
secondCate.setType_id(secondTypeId);
secondCate.setType_id(typeId);
secondCate.setData_source(2);
secondCate.setCategory_image(list.get(i).getCategory_image());
List<LibraryProductDTO> libraryProductDTOS=libraryProductService.matchLibraryProducts(null,secondCategoryName,new ArrayList<>());
if(CollectionUtil.isNotEmpty(libraryProductDTOS)){
secondCate.setCategory_image(libraryProductDTOS.get(0).getThumb());
@ -286,17 +235,11 @@ public abstract class SyncBaseThirdSxAbstract{
if (productCategoryService.saveOrUpdate(secondCate)) {
// 当前子分类的第二级父类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());
if (productCategoryTemp != null) {
// 更改记录
@ -319,11 +262,7 @@ public abstract class SyncBaseThirdSxAbstract{
count++;
}
productType.setType_category_id(list.get(i).getCategory_id());
if(null==productTypeListMap.get(productType.getType_name())){
productTypeList.add(productType);
productTypeListMap.put(productType.getType_name(),productType.getType_name());
}
}
saveBatchShopProductProductSpec(storeId,productTypeList);
return count;
@ -810,7 +749,7 @@ public abstract class SyncBaseThirdSxAbstract{
shopProductBase.setProduct_from(1005);// 商品来源(ENUM):1000-发布;1001-天猫;1002-淘宝;1003-阿里巴巴;1004-京东;1005-思迅;
shopProductBase.setProduct_add_time(currentDate.getTime());
shopProductBase.setProduct_unit_price(BigDecimal.valueOf(jsonObj.getDouble("retail_price")));
String isSpecial=jsonObj.getStr("isSpecial",DicEnum.YESORNO_0.getCode());
String isSpecial=jsonObj.getStr("isSpecial");
if(ObjectUtil.equals(isSpecial,DicEnum.YESORNO_0.getCode())||ObjectUtil.equals(isSpecial,DicEnum.YESORNO_1.getCode())){
shopProductBase.setIs_special(isSpecial);//是否特价商品 特价商品需要手动上架 todo 是否要开发定时上架功能
}else {
@ -928,9 +867,7 @@ public abstract class SyncBaseThirdSxAbstract{
shopProductItem.setItem_advice_price(BigDecimal.valueOf(jsonObj.getDouble("retail_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_quantity(stock.intValue());
//todo 特色商品切割
//负数产品判断
@ -1059,7 +996,7 @@ public abstract class SyncBaseThirdSxAbstract{
if(CollectionUtil.isNotEmpty(shopBaseProductTypes)){
productTypeService.updateBatchById(shopBaseProductTypes,shopBaseProductTypes.size());
}
productCategoryService.clearCategoryCache(storeId);
}
@ -1071,7 +1008,7 @@ public abstract class SyncBaseThirdSxAbstract{
.map(ShopBaseProductSpec::getSpec_name)
.distinct()
.collect(Collectors.toList());
List<ShopBaseProductSpec> existing = batchGetByStoreAndShopBaseProductSpec(storeProductPairs,productSpecs.get(0).getStore_id());
List<ShopBaseProductSpec> existing = batchGetByStoreAndShopBaseProductSpec(storeProductPairs);
return existing.stream()
.collect(Collectors.toMap(
ShopBaseProductSpec::getSpec_name,
@ -1082,14 +1019,14 @@ public abstract class SyncBaseThirdSxAbstract{
/**
* 批量根据店铺和货号查询商品
*/
private List<ShopBaseProductSpec> batchGetByStoreAndShopBaseProductSpec(List<String> ShopBaseProductSpecStr,Integer storeId) {
private List<ShopBaseProductSpec> batchGetByStoreAndShopBaseProductSpec(List<String> ShopBaseProductSpecStr) {
if (CollUtil.isEmpty(ShopBaseProductSpecStr)) {
return Collections.emptyList();
}
QueryWrapper<ShopBaseProductSpec> query = new QueryWrapper<>();
query.select("spec_id", "spec_name");
ShopBaseProductSpecStr.forEach(specName -> {
query.or(q -> q.eq("spec_name", specName).eq("store_id",storeId));
query.or(q -> q.eq("spec_name", specName));
});
return shopBaseProductSpecService.list(query);

View File

@ -151,6 +151,11 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
@Autowired
private ShopBaseProductCategoryService shopBaseProductCategoryService;
@Autowired
private ShopProductSpecItemService shopProductSpecItemService;
@Autowired
private ShopBaseProductSpecService baseProductSpecService;
@Value("#{accountBaseConfigService.getConfig('tengxun_default_dir')}")
private String TENGXUN_DEFA;