Compare commits

..

No commits in common. "3443721a9689d7b26f36e30719a9b3957fe1d4f2" and "2dd516bed98f25a2802264937a7c9ca5a3d2fde5" have entirely different histories.

9 changed files with 79 additions and 145 deletions

View File

@ -118,7 +118,6 @@ public class ShopBaseProductCategoryController {
}else { }else {
oldShopBaseProductCategory.setCategory_order(shopBaseProductCategory.getCategory_order()); oldShopBaseProductCategory.setCategory_order(shopBaseProductCategory.getCategory_order());
oldShopBaseProductCategory.setCategory_is_enable(shopBaseProductCategory.getCategory_is_enable()); oldShopBaseProductCategory.setCategory_is_enable(shopBaseProductCategory.getCategory_is_enable());
oldShopBaseProductCategory.setCategory_image(shopBaseProductCategory.getCategory_image());
} }
return CommonResult.success(shopBaseProductCategoryService.editCategory(oldShopBaseProductCategory)); return CommonResult.success(shopBaseProductCategoryService.editCategory(oldShopBaseProductCategory));
} }

View File

@ -290,8 +290,7 @@ public interface ShopProductBaseService extends IBaseService<ShopProductBase> {
List<ShopProductInfo> shopProductInfoList, List<List<ShopProductItem>> shopProductItemList, List<ShopProductInfo> shopProductInfoList, List<List<ShopProductItem>> shopProductItemList,
List<ShopProductImage> shopProductImageList, List<ShopProductImage> shopProductImageList,
List<ShopProductValidPeriod> shopProductValidPeriodList, List<ShopProductValidPeriod> shopProductValidPeriodList,
List<ShopProductAssistIndex> shopProductAssistIndexList,String priorityMode, List<ShopProductAssistIndex> shopProductAssistIndexList,String priorityMode);
Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdatePrice);
/** /**
* 加载商品 * 加载商品

View File

@ -207,7 +207,11 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
@Autowired @Autowired
private ProductMappingService productMappingService; private ProductMappingService productMappingService;
@Autowired
private RedisService redisService;
@Autowired
private StoreDbConfigService storeDbConfigService;
private final static int delate_batch_limit=100;//删除最大限制 private final static int delate_batch_limit=100;//删除最大限制
@ -5300,8 +5304,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
List<ShopProductData> shopProductDataList, List<ShopProductDetail> shopProductDetailList, List<ShopProductData> shopProductDataList, List<ShopProductDetail> shopProductDetailList,
List<ShopProductInfo> shopProductInfoList, List<List<ShopProductItem>> shopProductItemList, List<ShopProductInfo> shopProductInfoList, List<List<ShopProductItem>> shopProductItemList,
List<ShopProductImage> shopProductImageList, List<ShopProductValidPeriod> shopProductValidPeriodList, List<ShopProductImage> shopProductImageList, List<ShopProductValidPeriod> shopProductValidPeriodList,
List<ShopProductAssistIndex> shopProductAssistIndexList, String priorityMode,Map shopProductSpecItemMap, List<ShopProductAssistIndex> shopProductAssistIndexList, String priorityMode) {
Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdatePrice) {
// 1. 参数校验 // 1. 参数校验
if (shopProductBaseList == null || shopProductBaseList.isEmpty()) { if (shopProductBaseList == null || shopProductBaseList.isEmpty()) {
@ -5309,7 +5312,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
} }
// 2. 检查并设置已存在商品的ID // 2. 检查并设置已存在商品的ID
Map<String, String> existingProducts = checkExistingProducts(shopProductBaseList); Map<String, Long> existingProducts = checkExistingProducts(shopProductBaseList);
// 3. 分离新增和更新的商品 // 3. 分离新增和更新的商品
List<ShopProductBase> newProducts = new ArrayList<>(); List<ShopProductBase> newProducts = new ArrayList<>();
@ -5345,13 +5348,9 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
if (existingProducts.containsKey(key)) { if (existingProducts.containsKey(key)) {
// 已存在商品设置ID并加入更新列表 // 已存在商品设置ID并加入更新列表
String existIdAndState = existingProducts.get(key); Long existId = existingProducts.get(key);
String [] existBaseIdAndState= existIdAndState.split("_");
Long existId = Long.valueOf(existBaseIdAndState[0]);
Integer product_state_id = Integer.valueOf(existBaseIdAndState[1]);
base.setProduct_id(existId); base.setProduct_id(existId);
base.setProduct_src_id(existId); base.setProduct_src_id(existId);
base.setProduct_state_id(product_state_id);
shopProductBaseList.get(i).setProduct_id(existId); shopProductBaseList.get(i).setProduct_id(existId);
//shopProductIndexList.get(i).setProduct_id(existId); //shopProductIndexList.get(i).setProduct_id(existId);
// shopProductIndexList.get(i).setProduct_unit_points(BigDecimal.ZERO); // shopProductIndexList.get(i).setProduct_unit_points(BigDecimal.ZERO);
@ -5452,7 +5451,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
newProductDataList, updateProductDataList, newShopProductDetailList, updateShopProductDetailList, newProductDataList, updateProductDataList, newShopProductDetailList, updateShopProductDetailList,
newShopProductInfoList, updateShopProductInfoList, newShopProductItemList, updateShopProductItemList, newShopProductInfoList, updateShopProductInfoList, newShopProductItemList, updateShopProductItemList,
newShopProductImageList, updateShopProductImageList, newShopProductValidPeriodList, updateShopProductValidPeriodList, newShopProductImageList, updateShopProductImageList, newShopProductValidPeriodList, updateShopProductValidPeriodList,
newShopProductAssistIndexList, updateShopProductAssistIndexList, priorityMode,shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,isUpdatePrice); newShopProductAssistIndexList, updateShopProductAssistIndexList, priorityMode);
} }
/** /**
@ -5467,7 +5466,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
List<ShopProductImage> newShopProductImageList, List<ShopProductImage> udpteShopProductImageList, List<ShopProductImage> newShopProductImageList, List<ShopProductImage> udpteShopProductImageList,
List<ShopProductValidPeriod> newShopProductValidPeriodList, List<ShopProductValidPeriod> updateShopProductValidPeriodList, List<ShopProductValidPeriod> newShopProductValidPeriodList, List<ShopProductValidPeriod> updateShopProductValidPeriodList,
List<ShopProductAssistIndex> newShopProductAssistIndexList, List<ShopProductAssistIndex> udpateShopProductAssistIndexList, List<ShopProductAssistIndex> newShopProductAssistIndexList, List<ShopProductAssistIndex> udpateShopProductAssistIndexList,
String priorityMode,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdatePrice String priorityMode
) { ) {
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
@ -5607,11 +5606,11 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
//计算规格 //计算规格
if (CollUtil.isNotEmpty(newProducts)) { if (CollUtil.isNotEmpty(newProducts)) {
productMappingService.computeProductMapping(newProducts, newProducts.get(0).getStore_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap, isUpdatePrice); productMappingService.computeProductMapping(newProducts, newProducts.get(0).getStore_id(), false);
} }
if (CollUtil.isNotEmpty(updateProducts)) {//如果时自动优先则按平台规则切割商品 if (CollUtil.isNotEmpty(updateProducts)) {//如果时自动优先则按平台规则切割商品
if (DicEnum.PRIORITY_MODE_2.getCode().equals(priorityMode)) { if (DicEnum.PRIORITY_MODE_2.getCode().equals(priorityMode)) {
productMappingService.computeProductMapping(updateProducts, updateProducts.get(0).getStore_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap, true); productMappingService.computeProductMapping(updateProducts, updateProducts.get(0).getStore_id(), true);
} }
} }
return Pair.of(true, String.format("处理成功,新增%d条更新%d条", return Pair.of(true, String.format("处理成功,新增%d条更新%d条",
@ -6033,7 +6032,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
/** /**
* 检查哪些商品已存在 * 检查哪些商品已存在
*/ */
private Map<String, String> checkExistingProducts(List<ShopProductBase> productBases) { private Map<String, Long> checkExistingProducts(List<ShopProductBase> productBases) {
// 1. 按店铺和货号分组 // 1. 按店铺和货号分组
Map<String, List<ShopProductBase>> storeProductMap = productBases.stream() Map<String, List<ShopProductBase>> storeProductMap = productBases.stream()
.collect(Collectors.groupingBy( .collect(Collectors.groupingBy(
@ -6053,7 +6052,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
return existing.stream() return existing.stream()
.collect(Collectors.toMap( .collect(Collectors.toMap(
p -> p.getStore_id() + "_" + p.getProduct_number(), p -> p.getStore_id() + "_" + p.getProduct_number(),
p -> p.getProduct_id()+"_"+ p.getProduct_state_id() ShopProductBase::getProduct_id
)); ));
} }
@ -6067,7 +6066,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
// 使用IN查询优化根据数据库特性可能需要分批 // 使用IN查询优化根据数据库特性可能需要分批
QueryWrapper<ShopProductBase> query = new QueryWrapper<>(); QueryWrapper<ShopProductBase> query = new QueryWrapper<>();
query.select("product_id", "store_id", "product_number","product_state_id"); query.select("product_id", "store_id", "product_number");
// 构建OR条件 (store_id=X AND product_number=Y) OR (store_id=A AND product_number=B)... // 构建OR条件 (store_id=X AND product_number=Y) OR (store_id=A AND product_number=B)...
storeProductPairs.forEach(pair -> { storeProductPairs.forEach(pair -> {

View File

@ -15,7 +15,6 @@ import com.suisung.mall.common.modules.sync.ProductMapping;
import com.suisung.mall.common.pojo.res.ThirdApiRes; import com.suisung.mall.common.pojo.res.ThirdApiRes;
import com.suisung.mall.common.service.impl.BaseControllerImpl; import com.suisung.mall.common.service.impl.BaseControllerImpl;
import com.suisung.mall.common.utils.ContextUtil; import com.suisung.mall.common.utils.ContextUtil;
import com.suisung.mall.common.utils.StringUtils;
import com.suisung.mall.shop.store.service.ShopStoreBaseService; import com.suisung.mall.shop.store.service.ShopStoreBaseService;
import com.suisung.mall.shop.sync.exelModel.ImportResult; import com.suisung.mall.shop.sync.exelModel.ImportResult;
import com.suisung.mall.shop.sync.service.ProductMappingService; import com.suisung.mall.shop.sync.service.ProductMappingService;
@ -188,17 +187,8 @@ public class ProductMappingController extends BaseControllerImpl {
*/ */
@ApiOperation(value = "自动计算并上架商品", notes = "自动计算并上架商品") @ApiOperation(value = "自动计算并上架商品", notes = "自动计算并上架商品")
@RequestMapping(value = "/syncProductMaping", method = RequestMethod.PUT) @RequestMapping(value = "/syncProductMaping", method = RequestMethod.PUT)
public CommonResult syncProductMaping(@RequestParam(required = false) Integer storeId) { public CommonResult syncProductMaping(Integer storeId) {
UserDto userDto=ContextUtil.getCurrentUser(); return productMappingService.syncAllProductMapping(storeId);
assert userDto != null;
if(userDto.isStore()) {//商店自己同步
return productMappingService.syncAllProductMapping(Integer.valueOf(userDto.getStore_id()));
}else {
if(ObjectUtil.isEmpty(storeId)){
return CommonResult.failed("请传入店铺id");
}
}
return productMappingService.syncAllProductMapping(storeId);
} }
/** /**
@ -280,9 +270,6 @@ public class ProductMappingController extends BaseControllerImpl {
String shopStoreId=userDto.getStore_id(); String shopStoreId=userDto.getStore_id();
syncThirdDataService.syncShopImages(Integer.valueOf(shopStoreId)); syncThirdDataService.syncShopImages(Integer.valueOf(shopStoreId));
}else {//平台同步 }else {//平台同步
if(StringUtils.isEmpty(storeId)){
return new ThirdApiRes().fail(250,"请传入店铺id");
}
syncThirdDataService.syncShopImages(Integer.valueOf(storeId)); syncThirdDataService.syncShopImages(Integer.valueOf(storeId));
} }
return new ThirdApiRes().success("服务器已执行商品图库匹配数据操作"); return new ThirdApiRes().success("服务器已执行商品图库匹配数据操作");

View File

@ -21,9 +21,7 @@ public interface ProductMappingService extends IBaseService<ProductMapping> {
* @param storeId * @param storeId
* @param isUpdate * @param isUpdate
*/ */
void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId, void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId, boolean isUpdate);
Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,
boolean isUpdate);
Map getProductMapping(Integer storeId); Map getProductMapping(Integer storeId);

View File

@ -123,12 +123,16 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
} }
@Override @Override
public void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdate) { public void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId,boolean isUpdate) {
shopProductBaseList= shopProductBaseList.stream().filter(base ->StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK==(base.getProduct_state_id())).collect(Collectors.toList()); shopProductBaseList= shopProductBaseList.stream().filter(base ->StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK==(base.getProduct_state_id())).collect(Collectors.toList());
if (CollUtil.isEmpty(shopProductBaseList)) { if (CollUtil.isEmpty(shopProductBaseList)) {
log.info("没有规格数据要处理"); log.info("没有规格数据要处理");
return; return;
} }
Map shopProductSpecItemMap = shopProductSpecItemService.getExistItem(storeId);
Map productMappingMap = this.getProductMapping(storeId);
Map ShopBaseProductSpecMap = baseProductSpecService.getShopBaseProductSpecMap(storeId);
dealData(shopProductBaseList,shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,isUpdate); dealData(shopProductBaseList,shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,isUpdate);
} }
@ -159,21 +163,17 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
List<ShopProductSpecItem> updateShopProductSpecItemList=new ArrayList<>(); List<ShopProductSpecItem> updateShopProductSpecItemList=new ArrayList<>();
List<ShopProductBase> updateShopProductBaseList=new ArrayList<>(); List<ShopProductBase> updateShopProductBaseList=new ArrayList<>();
List<ShopProductIndex> updateShopProductIndexList=new ArrayList<>();
List<ShopProductItem> updateShopProductItemList=new ArrayList<>(); List<ShopProductItem> updateShopProductItemList=new ArrayList<>();
List<ShopProductInfo> updateShopProductInfoList=new ArrayList<>(); List<ShopProductInfo> updateShopProductInfoList=new ArrayList<>();
//找出需要更新的列表 //找出需要更新的列表
for (int i = 0; i < shopProductBaseList.size(); i++){ for (int i = 0; i < shopProductBaseList.size(); i++){
ShopProductSpecItem shopProductSpecItem=processShopProductSpecItem(shopProductBaseList.get(i),shopProductItems.get(i).getCategory_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,null); ShopProductSpecItem shopProductSpecItem=processShopProductSpecItem(shopProductBaseList.get(i),shopProductItems.get(i).getCategory_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,null);
if(shopProductSpecItem!=null){ if(shopProductSpecItem!=null){
shopProductBaseList.get(i).setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
ShopProductIndex shopProductIndex=new ShopProductIndex(); ShopProductIndex shopProductIndex=new ShopProductIndex();
shopProductIndex.setProduct_id(shopProductBaseList.get(i).getProduct_id()); shopProductIndex.setProduct_id(shopProductBaseList.get(i).getProduct_id());
Integer stateId= shopProductBaseList.get(i).getProduct_state_id(); shopProductIndex.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
if(stateId!=StateCode.PRODUCT_STATE_NORMAL){ shopProductItems.get(i).setItem_enable(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
shopProductBaseList.get(i).setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
shopProductIndex.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
shopProductItems.get(i).setItem_enable(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
}
shopProductItems.get(i).setItem_is_default(1); shopProductItems.get(i).setItem_is_default(1);
if(shopProductSpecItem.isUpdate()){ if(shopProductSpecItem.isUpdate()){
shopProductBaseList.get(i).setProduct_unit_price(shopProductSpecItem.getItemPrice()); shopProductBaseList.get(i).setProduct_unit_price(shopProductSpecItem.getItemPrice());
@ -183,13 +183,10 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
shopProductBaseList.get(i).setProduct_market_price(shopProductSpecItem.getItemPrice()); shopProductBaseList.get(i).setProduct_market_price(shopProductSpecItem.getItemPrice());
addShopProductSpecItemList.add(shopProductSpecItem); addShopProductSpecItemList.add(shopProductSpecItem);
} }
proccessItemAndInfo(shopProductItems.get(i),shopProductInfoList.get(i),shopProductSpecItem,isUpdate);
shopProductBaseList.get(i).setProduct_unit_price(shopProductItems.get(i).getItem_unit_price());
updateShopProductBaseList.add(shopProductBaseList.get(i)); updateShopProductBaseList.add(shopProductBaseList.get(i));
updateShopProductItemList.add(shopProductItems.get(i)); updateShopProductItemList.add(shopProductItems.get(i));
updateShopProductInfoList.add(shopProductInfoList.get(i)); updateShopProductInfoList.add(shopProductInfoList.get(i));
shopProductIndex.setProduct_unit_price(shopProductItems.get(i).getItem_unit_price()); proccessItemAndInfo(shopProductItems.get(i),shopProductInfoList.get(i),shopProductSpecItem,isUpdate);
updateShopProductIndexList.add(shopProductIndex);
} }
} }
//再次变量根据addShopProductSpecItemList算出id,这样防止多次链接redis //再次变量根据addShopProductSpecItemList算出id,这样防止多次链接redis
@ -207,6 +204,7 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
index++; index++;
} }
proccessItemAndInfo(shopProductItems.get(i),shopProductInfoList.get(i),shopProductSpecItem,isUpdate); proccessItemAndInfo(shopProductItems.get(i),shopProductInfoList.get(i),shopProductSpecItem,isUpdate);
} }
} }
} }
@ -219,22 +217,17 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
shopProductSpecItemService.updateBatchById(updateShopProductSpecItemList,updateShopProductSpecItemList.size()); shopProductSpecItemService.updateBatchById(updateShopProductSpecItemList,updateShopProductSpecItemList.size());
} }
} }
synchronized (this) { if(CollUtil.isNotEmpty(updateShopProductBaseList)){
if (CollUtil.isNotEmpty(updateShopProductBaseList)) { shopProductBaseService.updateBatchById(updateShopProductBaseList,updateShopProductBaseList.size());
shopProductBaseService.updateBatchById(updateShopProductBaseList, updateShopProductBaseList.size()); saveShopProductIndexList(updateShopProductBaseList);
shopProductIndexService.updateBatchById(updateShopProductIndexList, updateShopProductIndexList.size());
} }
} if(CollUtil.isNotEmpty(updateShopProductItemList)){
synchronized (this) { shopProductItemService.updateBatchById(updateShopProductItemList,updateShopProductItemList.size());
if (CollUtil.isNotEmpty(updateShopProductItemList)) {
shopProductItemService.updateBatchById(updateShopProductItemList, updateShopProductItemList.size());
} }
}
synchronized (this) {
if(CollUtil.isNotEmpty(updateShopProductInfoList)){ if(CollUtil.isNotEmpty(updateShopProductInfoList)){
shopProductInfoService.updateBatchById(updateShopProductInfoList,updateShopProductInfoList.size()); shopProductInfoService.updateBatchById(updateShopProductInfoList,updateShopProductInfoList.size());
} }
}
} }
@ -252,7 +245,6 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
}else { }else {
item.setItem_unit_price(shopProductSpecItem.getItemPrice()); item.setItem_unit_price(shopProductSpecItem.getItemPrice());
item.setItem_market_price(shopProductSpecItem.getItemPrice()); item.setItem_market_price(shopProductSpecItem.getItemPrice());
item.setItem_advice_price(shopProductSpecItem.getItemPrice());
} }
} }
JSONArray array_item_spec = JSONUtil.parseArray(item_spec); JSONArray array_item_spec = JSONUtil.parseArray(item_spec);
@ -273,6 +265,29 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
shopProductInfo.setProduct_uniqid(product_uniqid); shopProductInfo.setProduct_uniqid(product_uniqid);
} }
/**
* 更新index状态为正常
* @param shopProductBaseList
*/
private void saveShopProductIndexList(List<ShopProductBase> shopProductBaseList){
if (CollUtil.isEmpty(shopProductBaseList)) {
return ;
}
// 使用IN查询优化根据数据库特性可能需要分批
QueryWrapper<ShopProductIndex> query = new QueryWrapper<>();
query.select("product_id", "product_name", "store_id","product_state_id");
// 构建OR条件 (store_id=X AND product_number=Y) OR (store_id=A AND product_number=B)...
shopProductBaseList.forEach(base -> {
query.or(q -> q.eq("store_id", base.getStore_id())
.eq("product_id", base.getProduct_id()));
});
List<ShopProductIndex> updateShopProductIndexList= shopProductIndexService.list(query);
updateShopProductIndexList.forEach(shopProductIndex -> {
shopProductIndex.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
});
shopProductIndexService.updateBatchById(updateShopProductIndexList,updateShopProductIndexList.size());
}
/** /**
* *
@ -398,16 +413,11 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
ExecutorService executor = Executors.newFixedThreadPool(6); ExecutorService executor = Executors.newFixedThreadPool(6);
List<Future<?>> futures = new ArrayList<>(); List<Future<?>> futures = new ArrayList<>();
Map shopProductSpecItemMap = shopProductSpecItemService.getExistItem(storeId);
Map productMappingMap = this.getProductMapping(storeId);
Map ShopBaseProductSpecMap = baseProductSpecService.getShopBaseProductSpecMap(storeId);
boolean isUpDatePrice=ObjectUtil.isNotEmpty(storeDbConfig.getRefreshTime());
for (int i=1;i<=pages;i++){ for (int i=1;i<=pages;i++){
int finalI = i; int finalI = i;
Integer finalStoreId = storeId; Integer finalStoreId = storeId;
List<ShopProductBase> shopProductBaseList=shopProductBaseService.lists(queryWrapper, finalI,SHOPBASEPAGE).getRecords();
futures.add(executor.submit(() -> { futures.add(executor.submit(() -> {
this.computeProductMapping(shopProductBaseList, finalStoreId,shopProductSpecItemMap,ShopBaseProductSpecMap, productMappingMap,isUpDatePrice); this.computeProductMapping(shopProductBaseService.lists(queryWrapper, finalI,SHOPBASEPAGE).getRecords(), finalStoreId,false);
return "成功" + finalI; return "成功" + finalI;
})); }));
} }

View File

@ -701,8 +701,7 @@ public abstract class SyncBaseThirdSxAbstract{
* @param storeId * @param storeId
* @return * @return
*/ */
public int baseSaveOrUpdateGoodsBatch(JSONArray goodsListJSON,String storeId,String isNegativeAllowed,String priorityMode, public int baseSaveOrUpdateGoodsBatch(JSONArray goodsListJSON,String storeId,String isNegativeAllowed,String priorityMode,Map<String,Integer> brandMaps){
Map<String,Integer> brandMaps,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdatePrice){
AtomicInteger resultCount = new AtomicInteger(); AtomicInteger resultCount = new AtomicInteger();
Map categoryMap= productCategoryService.getCategoryListByStoreId(storeId);//热数据加载 Map categoryMap= productCategoryService.getCategoryListByStoreId(storeId);//热数据加载
List<ShopProductBase> shopProductBaseList=new ArrayList<>(); List<ShopProductBase> shopProductBaseList=new ArrayList<>();
@ -763,8 +762,7 @@ public abstract class SyncBaseThirdSxAbstract{
} }
//商品总量 //商品总量
if(ObjectUtil.isNotEmpty(jsonObj.getStr("unit"))&&ObjectUtil.isNotEmpty(jsonObj.getStr("stock")) if(ObjectUtil.isNotEmpty(jsonObj.getStr("unit"))&&ObjectUtil.isNotEmpty(jsonObj.getStr("stock"))
&& "KG,kg,公斤".contains(jsonObj.getStr("unit"))&&!(productName.contains("g")||productName.contains("ml")||productName.contains("ML")||productName.contains("kg")|| && "KG,kg,公斤".contains(jsonObj.getStr("unit"))){
productName.contains("KG")||productName.contains("L")||productName.contains("l"))){//这样做主要是有些超时有了kg又打包成克来卖
shopProductBase.setShop_weight(stock); shopProductBase.setShop_weight(stock);
shopProductBase.setUnit_name(jsonObj.getStr("unit")); shopProductBase.setUnit_name(jsonObj.getStr("unit"));
shopProductBase.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK); shopProductBase.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK);
@ -777,20 +775,15 @@ public abstract class SyncBaseThirdSxAbstract{
} }
shopProductBase.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);//默认是下架 shopProductBase.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);//默认是下架
shopProductBase.setUnit_price(BigDecimal.valueOf(jsonObj.getDouble("retail_price"))); shopProductBase.setUnit_price(BigDecimal.valueOf(jsonObj.getDouble("retail_price")));
}
if(productName.contains("g")||productName.contains("ml")||productName.contains("ML")||productName.contains("kg")||
productName.contains("KG")||productName.contains("L")||productName.contains("l")){
}else {
String spectItem=StringUtils.isNotEmpty(shopProductBase.getSpecItem())?shopProductBase.getSpecItem():""; String spectItem=StringUtils.isNotEmpty(shopProductBase.getSpecItem())?shopProductBase.getSpecItem():"";
String unit=StringUtils.isNotEmpty(shopProductBase.getSpecUnit())?shopProductBase.getSpecUnit():""; String unit=StringUtils.isNotEmpty(shopProductBase.getSpecUnit())?shopProductBase.getSpecUnit():"";
if(StringUtils.isNotEmpty(spectItem)||StringUtils.isNotEmpty(unit)){ productName=productName+spectItem+"/"+unit;
productName=productName+spectItem+"/"+unit;
}
} }
// if(!(productName.contains("g")||productName.contains("ml")||productName.contains("ML")||productName.contains("kg")||
// productName.contains("KG")||productName.contains("L")||productName.contains("l"))){
// String spectItem=StringUtils.isNotEmpty(shopProductBase.getSpecItem())?shopProductBase.getSpecItem():"";
// String unit=StringUtils.isNotEmpty(shopProductBase.getSpecUnit())?shopProductBase.getSpecUnit():"";
// if(StringUtils.isNotEmpty(spectItem)||StringUtils.isNotEmpty(unit)){
// productName=productName+spectItem+"/"+unit;
// }
// }
shopProductBase.setProduct_name(productName); shopProductBase.setProduct_name(productName);
// ShopProductIndex // ShopProductIndex
ShopProductIndex shopProductIndex = new ShopProductIndex(); ShopProductIndex shopProductIndex = new ShopProductIndex();
@ -818,8 +811,6 @@ public abstract class SyncBaseThirdSxAbstract{
shopProductIndex.setProduct_transport_id(String.valueOf(StateCode.DELIVERY_TYPE_SAME_CITY)); shopProductIndex.setProduct_transport_id(String.valueOf(StateCode.DELIVERY_TYPE_SAME_CITY));
shopProductIndex.setIs_special(shopProductBase.getIs_special()); shopProductIndex.setIs_special(shopProductBase.getIs_special());
shopProductIndex.setBrand_id(brandMaps.get(jsonObj.getStr("brand_name"))); shopProductIndex.setBrand_id(brandMaps.get(jsonObj.getStr("brand_name")));
shopProductIndex.setProduct_unit_price(shopProductBase.getProduct_unit_price());
if(categoryId!=0){ if(categoryId!=0){
Integer typeId = (Integer) categoryMap.get(categoryId.toString()); Integer typeId = (Integer) categoryMap.get(categoryId.toString());
if (ObjectUtil.isNotEmpty(typeId)) { if (ObjectUtil.isNotEmpty(typeId)) {
@ -900,7 +891,7 @@ public abstract class SyncBaseThirdSxAbstract{
shopProductBaseService.saveProductBatch(shopProductBaseList,shopProductIndexList,shopProductDataList,shopProductDetailList,shopProductInfoList,shopProductItemLists, shopProductBaseService.saveProductBatch(shopProductBaseList,shopProductIndexList,shopProductDataList,shopProductDetailList,shopProductInfoList,shopProductItemLists,
shopProductImageList, shopProductImageList,
new ArrayList<ShopProductValidPeriod>(), new ArrayList<ShopProductValidPeriod>(),
new ArrayList<ShopProductAssistIndex>(),priorityMode,shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,isUpdatePrice); new ArrayList<ShopProductAssistIndex>(),priorityMode);
return resultCount.get(); return resultCount.get();
} }

View File

@ -35,7 +35,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -135,26 +134,15 @@ public class SyncShopImageServiceImpl implements SyncShopImageService {
List<ShopProductImage> list=pageList.getRecords(); List<ShopProductImage> list=pageList.getRecords();
final int finalI = i; final int finalI = i;
futures.add(executor.submit(() -> { futures.add(executor.submit(() -> {
int index=0; try {
String message=""; List<ImageMappingDto> imageMappingDtos=CovertToShopProductImage(list);
while (index<3){ syncBatchShopImage(imageMappingDtos);
try { success.getAndIncrement();
List<ImageMappingDto> imageMappingDtos=CovertToShopProductImage(list);//调用es排除异常重新连接 return "成功" + finalI;
syncBatchShopImage(imageMappingDtos); } catch (Exception e) {
success.getAndIncrement(); fails.getAndIncrement();
message= "成功" + finalI; return "失败"+finalI;
break;
} catch (Exception e) {
log.info("图库匹配失败:"+e.getMessage());
index++;
if(index==3){
message= "失败"+finalI+":"+e.getMessage();
fails.getAndIncrement();
break;
}
}
} }
return message;
})); }));
} }
}else { }else {
@ -168,7 +156,6 @@ public class SyncShopImageServiceImpl implements SyncShopImageService {
return "图库匹配成功" + finalI; return "图库匹配成功" + finalI;
} catch (Exception e) { } catch (Exception e) {
fails.getAndIncrement(); fails.getAndIncrement();
log.info("图库匹配失败:"+e.getMessage());
return "图库匹配失败"+finalI+":"+e.getMessage(); return "图库匹配失败"+finalI+":"+e.getMessage();
} }
})); }));
@ -234,35 +221,10 @@ public class SyncShopImageServiceImpl implements SyncShopImageService {
shopProductIndex.setProduct_state_id(StateCode.PRODUCT_STATE_NORMAL); shopProductIndex.setProduct_state_id(StateCode.PRODUCT_STATE_NORMAL);
shopProductIndexList.add(shopProductIndex); shopProductIndexList.add(shopProductIndex);
} }
synchronized (this){ if(CollectionUtil.isNotEmpty(shopProductImageList)){
if(CollectionUtil.isNotEmpty(shopProductImageList)){ shopProductImageService.updateBatchById(shopProductImageList);
shopProductImageService.updateBatchById(shopProductImageList);
}
} }
if(CollectionUtil.isNotEmpty(shopProductBaseList)){ if(CollectionUtil.isNotEmpty(shopProductBaseList)){
/**
* 如果没有规格不能上架
*/
QueryWrapper<ShopProductBase> shopProductBaseQueryWrapper=new QueryWrapper<>();
shopProductBaseQueryWrapper.select("product_id","product_state_id");
for(ShopProductBase shopProductBase:shopProductBaseList){
shopProductBaseQueryWrapper.or(q->q.eq("product_id",shopProductBase.getProduct_id()).eq("product_state_id",StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK));
}
List<ShopProductBase> list=shopProductBaseService.list(shopProductBaseQueryWrapper);
if(CollectionUtil.isNotEmpty(list)){
Map<Long,Integer> map=new HashMap<>();
for(ShopProductBase shopProductBase:list){
map.put(shopProductBase.getProduct_id(),shopProductBase.getProduct_state_id());
}
for(int i=0;i<shopProductBaseList.size();i++){
ShopProductBase shopBase=shopProductBaseList.get(i);
if(map.containsKey(shopBase.getProduct_id())){
shopBase.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK);
shopProductIndexList.get(i).setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK);
}
}
}
shopProductBaseService.updateBatchById(shopProductBaseList); shopProductBaseService.updateBatchById(shopProductBaseList);
} }
if(CollectionUtil.isNotEmpty(shopProductItemList)){ if(CollectionUtil.isNotEmpty(shopProductItemList)){
@ -291,8 +253,7 @@ public class SyncShopImageServiceImpl implements SyncShopImageService {
productImageSearchDTOS.add(productImageSearchDTO); productImageSearchDTOS.add(productImageSearchDTO);
} }
} }
Map<String,List<ProductImageSearchDTO>> productImageList=new HashMap<>(); Map<String,List<ProductImageSearchDTO>> productImageList= searchService.searchProductImageList(productImageSearchDTOS, DicEnum.ES_SEARCH_TYPE_2.getCode());
productImageList= searchService.searchProductImageList(productImageSearchDTOS, DicEnum.ES_SEARCH_TYPE_2.getCode());
productImageList.forEach((k,v)->{ productImageList.forEach((k,v)->{
if(!v.isEmpty()){ if(!v.isEmpty()){
ImageMappingDto imageMappingDto=new ImageMappingDto(); ImageMappingDto imageMappingDto=new ImageMappingDto();

View File

@ -180,9 +180,6 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
@Autowired @Autowired
private SearchService searchService; private SearchService searchService;
@Autowired
private ProductMappingService productMappingService;
/** /**
* 批量保存商品的分类 * 批量保存商品的分类
* *
@ -574,8 +571,6 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
syncPrimaryKey(); syncPrimaryKey();
shopNumberSeqService.clearKey(); shopNumberSeqService.clearKey();
shopBaseProductCategoryService.clearCategoryCache(storeId); shopBaseProductCategoryService.clearCategoryCache(storeId);
baseProductSpecService.clearShopBaseProductSpecMap(Integer.valueOf(storeId));
shopProductSpecItemService.clearExistItem(Integer.valueOf(storeId));
shopNumberSeqService.clearKeyStoreItemSepcId(); shopNumberSeqService.clearKeyStoreItemSepcId();
ExecutorService executor = Executors.newFixedThreadPool(6); ExecutorService executor = Executors.newFixedThreadPool(6);
List<Future<?>> futures = new ArrayList<>(); List<Future<?>> futures = new ArrayList<>();
@ -590,14 +585,10 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
QueryWrapper<StoreDbConfig> storeDbConfigQueryWrapper = new QueryWrapper<>(); QueryWrapper<StoreDbConfig> storeDbConfigQueryWrapper = new QueryWrapper<>();
storeDbConfigQueryWrapper.eq("store_id", storeId); storeDbConfigQueryWrapper.eq("store_id", storeId);
StoreDbConfig storeDbConfig = storeDbConfigService.getOne(storeDbConfigQueryWrapper); StoreDbConfig storeDbConfig = storeDbConfigService.getOne(storeDbConfigQueryWrapper);
Map shopProductSpecItemMap = shopProductSpecItemService.getExistItem(Integer.valueOf(storeId));//切割缓存
Map productMappingMap = productMappingService.getProductMapping(Integer.valueOf(storeId));//切割缓存
Map ShopBaseProductSpecMap = baseProductSpecService.getShopBaseProductSpecMap(Integer.valueOf(storeId));//切割商品缓存
for (int i = 0; i < newFolders.size(); i++) { for (int i = 0; i < newFolders.size(); i++) {
final int taskId = i; final int taskId = i;
final String isNegativeAllowed = storeDbConfig.getIsNegativeAllowed(); final String isNegativeAllowed = storeDbConfig.getIsNegativeAllowed();
String priorityMode = storeDbConfig.getPriorityMode(); String priorityMode = storeDbConfig.getPriorityMode();
boolean isUpdatePrice= ObjectUtil.isNotEmpty(storeDbConfig.getRefreshTime());//是否更新所有切割价格
threadNum.incrementAndGet(); threadNum.incrementAndGet();
futures.add(executor.submit(() -> { futures.add(executor.submit(() -> {
int count = 0;//失败重试机制当失败重试一次再次失败则记录到数据库中 int count = 0;//失败重试机制当失败重试一次再次失败则记录到数据库中
@ -607,7 +598,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
String fileName = "good_" + (taskId + 1) + ".txt"; String fileName = "good_" + (taskId + 1) + ".txt";
JSONArray jsonArray = new ThreadFileUtils().processFolder(taskName, newFolders.get(taskId)); JSONArray jsonArray = new ThreadFileUtils().processFolder(taskName, newFolders.get(taskId));
try { try {
baseSaveOrUpdateGoodsBatch(jsonArray, storeId, isNegativeAllowed, priorityMode, brandMaps,shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,isUpdatePrice); baseSaveOrUpdateGoodsBatch(jsonArray, storeId, isNegativeAllowed, priorityMode, brandMaps);
success.getAndIncrement(); success.getAndIncrement();
threadNum.decrementAndGet(); threadNum.decrementAndGet();
return "成功" + taskId; return "成功" + taskId;
@ -678,7 +669,6 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
} }
@Override @Override
@Async
public void syncShopImages(Integer storeId) { public void syncShopImages(Integer storeId) {
syncShopImageService.syncMapingShopImages(storeId); syncShopImageService.syncMapingShopImages(storeId);
} }