商品图库匹配优化

This commit is contained in:
liyj 2025-07-24 17:26:42 +08:00
parent f8fddd621b
commit 3443721a96
8 changed files with 116 additions and 79 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -123,16 +123,12 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
}
@Override
public void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId,boolean isUpdate) {
public void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdate) {
shopProductBaseList= shopProductBaseList.stream().filter(base ->StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK==(base.getProduct_state_id())).collect(Collectors.toList());
if (CollUtil.isEmpty(shopProductBaseList)) {
log.info("没有规格数据要处理");
return;
}
Map shopProductSpecItemMap = shopProductSpecItemService.getExistItem(storeId);
Map productMappingMap = this.getProductMapping(storeId);
Map ShopBaseProductSpecMap = baseProductSpecService.getShopBaseProductSpecMap(storeId);
dealData(shopProductBaseList,shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,isUpdate);
}
@ -163,17 +159,21 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
List<ShopProductSpecItem> updateShopProductSpecItemList=new ArrayList<>();
List<ShopProductBase> updateShopProductBaseList=new ArrayList<>();
List<ShopProductIndex> updateShopProductIndexList=new ArrayList<>();
List<ShopProductItem> updateShopProductItemList=new ArrayList<>();
List<ShopProductInfo> updateShopProductInfoList=new ArrayList<>();
//找出需要更新的列表
for (int i = 0; i < shopProductBaseList.size(); i++){
ShopProductSpecItem shopProductSpecItem=processShopProductSpecItem(shopProductBaseList.get(i),shopProductItems.get(i).getCategory_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,null);
if(shopProductSpecItem!=null){
shopProductBaseList.get(i).setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
ShopProductIndex shopProductIndex=new ShopProductIndex();
shopProductIndex.setProduct_id(shopProductBaseList.get(i).getProduct_id());
shopProductIndex.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
shopProductItems.get(i).setItem_enable(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
Integer stateId= shopProductBaseList.get(i).getProduct_state_id();
if(stateId!=StateCode.PRODUCT_STATE_NORMAL){
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);
if(shopProductSpecItem.isUpdate()){
shopProductBaseList.get(i).setProduct_unit_price(shopProductSpecItem.getItemPrice());
@ -183,10 +183,13 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
shopProductBaseList.get(i).setProduct_market_price(shopProductSpecItem.getItemPrice());
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));
updateShopProductItemList.add(shopProductItems.get(i));
updateShopProductInfoList.add(shopProductInfoList.get(i));
proccessItemAndInfo(shopProductItems.get(i),shopProductInfoList.get(i),shopProductSpecItem,isUpdate);
shopProductIndex.setProduct_unit_price(shopProductItems.get(i).getItem_unit_price());
updateShopProductIndexList.add(shopProductIndex);
}
}
//再次变量根据addShopProductSpecItemList算出id,这样防止多次链接redis
@ -204,7 +207,6 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
index++;
}
proccessItemAndInfo(shopProductItems.get(i),shopProductInfoList.get(i),shopProductSpecItem,isUpdate);
}
}
}
@ -217,17 +219,22 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
shopProductSpecItemService.updateBatchById(updateShopProductSpecItemList,updateShopProductSpecItemList.size());
}
}
if(CollUtil.isNotEmpty(updateShopProductBaseList)){
shopProductBaseService.updateBatchById(updateShopProductBaseList,updateShopProductBaseList.size());
saveShopProductIndexList(updateShopProductBaseList);
synchronized (this) {
if (CollUtil.isNotEmpty(updateShopProductBaseList)) {
shopProductBaseService.updateBatchById(updateShopProductBaseList, updateShopProductBaseList.size());
shopProductIndexService.updateBatchById(updateShopProductIndexList, updateShopProductIndexList.size());
}
if(CollUtil.isNotEmpty(updateShopProductItemList)){
shopProductItemService.updateBatchById(updateShopProductItemList,updateShopProductItemList.size());
}
synchronized (this) {
if (CollUtil.isNotEmpty(updateShopProductItemList)) {
shopProductItemService.updateBatchById(updateShopProductItemList, updateShopProductItemList.size());
}
}
synchronized (this) {
if(CollUtil.isNotEmpty(updateShopProductInfoList)){
shopProductInfoService.updateBatchById(updateShopProductInfoList,updateShopProductInfoList.size());
}
}
}
@ -245,6 +252,7 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
}else {
item.setItem_unit_price(shopProductSpecItem.getItemPrice());
item.setItem_market_price(shopProductSpecItem.getItemPrice());
item.setItem_advice_price(shopProductSpecItem.getItemPrice());
}
}
JSONArray array_item_spec = JSONUtil.parseArray(item_spec);
@ -265,29 +273,6 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
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());
}
/**
*
@ -413,11 +398,16 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
ExecutorService executor = Executors.newFixedThreadPool(6);
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++){
int finalI = i;
Integer finalStoreId = storeId;
List<ShopProductBase> shopProductBaseList=shopProductBaseService.lists(queryWrapper, finalI,SHOPBASEPAGE).getRecords();
futures.add(executor.submit(() -> {
this.computeProductMapping(shopProductBaseService.lists(queryWrapper, finalI,SHOPBASEPAGE).getRecords(), finalStoreId,false);
this.computeProductMapping(shopProductBaseList, finalStoreId,shopProductSpecItemMap,ShopBaseProductSpecMap, productMappingMap,isUpDatePrice);
return "成功" + finalI;
}));
}

View File

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

View File

@ -135,16 +135,26 @@ public class SyncShopImageServiceImpl implements SyncShopImageService {
List<ShopProductImage> list=pageList.getRecords();
final int finalI = i;
futures.add(executor.submit(() -> {
try {
List<ImageMappingDto> imageMappingDtos=CovertToShopProductImage(list);
syncBatchShopImage(imageMappingDtos);
success.getAndIncrement();
return "成功" + finalI;
} catch (Exception e) {
fails.getAndIncrement();
log.info("图库匹配失败:"+e.getMessage());
return "失败"+finalI+":"+e.getMessage();
int index=0;
String message="";
while (index<3){
try {
List<ImageMappingDto> imageMappingDtos=CovertToShopProductImage(list);//调用es排除异常重新连接
syncBatchShopImage(imageMappingDtos);
success.getAndIncrement();
message= "成功" + finalI;
break;
} catch (Exception e) {
log.info("图库匹配失败:"+e.getMessage());
index++;
if(index==3){
message= "失败"+finalI+":"+e.getMessage();
fails.getAndIncrement();
break;
}
}
}
return message;
}));
}
}else {
@ -224,8 +234,10 @@ public class SyncShopImageServiceImpl implements SyncShopImageService {
shopProductIndex.setProduct_state_id(StateCode.PRODUCT_STATE_NORMAL);
shopProductIndexList.add(shopProductIndex);
}
if(CollectionUtil.isNotEmpty(shopProductImageList)){
shopProductImageService.updateBatchById(shopProductImageList);
synchronized (this){
if(CollectionUtil.isNotEmpty(shopProductImageList)){
shopProductImageService.updateBatchById(shopProductImageList);
}
}
if(CollectionUtil.isNotEmpty(shopProductBaseList)){
@ -279,7 +291,8 @@ public class SyncShopImageServiceImpl implements SyncShopImageService {
productImageSearchDTOS.add(productImageSearchDTO);
}
}
Map<String,List<ProductImageSearchDTO>> productImageList= searchService.searchProductImageList(productImageSearchDTOS, DicEnum.ES_SEARCH_TYPE_2.getCode());
Map<String,List<ProductImageSearchDTO>> productImageList=new HashMap<>();
productImageList= searchService.searchProductImageList(productImageSearchDTOS, DicEnum.ES_SEARCH_TYPE_2.getCode());
productImageList.forEach((k,v)->{
if(!v.isEmpty()){
ImageMappingDto imageMappingDto=new ImageMappingDto();

View File

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