Compare commits

..

2 Commits

Author SHA1 Message Date
085799d908 优化批量更新同步商品匹配操作 2025-07-31 09:15:26 +08:00
77a994bcfe 商品sku列表更新接口优化 2025-07-30 16:38:20 +08:00
5 changed files with 81 additions and 42 deletions

View File

@ -124,7 +124,6 @@ public class StoreDbConfig implements Serializable {
private String priorityMode="1";
@TableField(value = "shop_gap_time",updateStrategy = FieldStrategy.NOT_EMPTY)
@ApiModelProperty(value = "商品同步间隔时间,由于商品同步时异步,要等同步完成才同步商品和活动,所以要设置间隔时间")
@NotBlank(message = "商品同步间隔时间不能为空")
private String shopGapTime;
}

View File

@ -5364,7 +5364,9 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
Integer product_state_id = Integer.valueOf(existBaseIdAndState[1]);
base.setProduct_id(existId);
base.setProduct_src_id(existId);
base.setProduct_state_id(product_state_id);
if(!(base.getProduct_state_id()==StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK)){//重新分配
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);
@ -5622,14 +5624,14 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
logger.info("处理成功,新增{}条,更新{}条", newProducts.size(), updateProducts.size());
//计算规格
if (CollUtil.isNotEmpty(newProducts)) {
productMappingService.computeProductMapping(newProducts, newProducts.get(0).getStore_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap, isUpdatePrice,DicEnum.YESORNO_0.getCode());
}
if (CollUtil.isNotEmpty(updateProducts)) {//如果时自动优先则按平台规则切割商品
if (DicEnum.PRIORITY_MODE_2.getCode().equals(priorityMode)) {
productMappingService.computeProductMapping(updateProducts, updateProducts.get(0).getStore_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap, true,DicEnum.YESORNO_0.getCode());
}
}
// if (CollUtil.isNotEmpty(newProducts)) {
// productMappingService.computeProductMapping(newProducts, newProducts.get(0).getStore_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap, isUpdatePrice,DicEnum.YESORNO_0.getCode());
// }
// if (CollUtil.isNotEmpty(updateProducts)) {//如果时自动优先则按平台规则切割商品
// if (DicEnum.PRIORITY_MODE_2.getCode().equals(priorityMode)) {
// productMappingService.computeProductMapping(updateProducts, updateProducts.get(0).getStore_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap, true,DicEnum.YESORNO_0.getCode());
// }
// }
return Pair.of(true, String.format("处理成功,新增%d条更新%d条",
newProducts.size(), updateProducts.size()));
} catch (RuntimeException e) {

View File

@ -2305,49 +2305,81 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
List<ShopProductItem> updateShopProductItem=new ArrayList<>();
List<ShopProductBase> updateShopProductBase=new ArrayList<>();
List<ShopProductIndex> updateShopProductIndex=new ArrayList<>();
for (ShopProductItem shopProductItem : shopProductItemList) {
queryWrapper.eq("product_id",shopProductItem.getProduct_id());
List<ShopProductItem> oldShopProductItems= shopProductItemService.list(queryWrapper);
List<ShopProductItem> oldShopProductItemList= oldShopProductItems.stream().filter(s -> s.getItem_id().equals(shopProductItem.getItem_id())).collect(Collectors.toList());
if(CollUtil.isEmpty(oldShopProductItemList)){
return CommonResult.failed("不存在商品sku");
//校验数据
Iterator<ShopProductItem> itemIs=shopProductItemList.iterator();
StringBuilder ids= new StringBuilder();
Long productId=shopProductItemList.get(0).getProduct_id();
while (itemIs.hasNext()) {//去重
ShopProductItem shopProductItem=itemIs.next();
if(ObjectUtil.isEmpty(shopProductItem.getProduct_id())){
return CommonResult.failed("产品id不能为空");
}
if(ObjectUtil.isEmpty(shopProductItem.getItem_id())){
return CommonResult.failed("商品sku不能为空");
}
ShopProductItem oldShopProductItem=oldShopProductItemList.get(0);
if(ObjectUtil.isEmpty(shopProductItem.getItem_quantity())){
return CommonResult.failed("库存不能为空");
}
if(ObjectUtil.isEmpty(shopProductItem.getItem_unit_price())){
return CommonResult.failed("价格不能为空");
}
if(!productId.equals(shopProductItem.getProduct_id())){
return CommonResult.failed("只能修改相同产品的sku列表");
}
if(ids.toString().contains(shopProductItem.getItem_id().toString())){
itemIs.remove();
}else {
ids.append(shopProductItem.getItem_id());
}
}
BigDecimal item_unit_price = shopProductItemList.stream().map(ShopProductItem::getItem_unit_price).min(BigDecimal::compareTo).get();
BigDecimal item_unit_price_max =shopProductItemList.stream().map(ShopProductItem::getItem_unit_price).max(BigDecimal::compareTo).get();
BigDecimal item_unit_price =shopProductItem.getItem_unit_price();
BigDecimal item_unit_price_max =shopProductItem.getItem_unit_price();
BigDecimal item_unit_price_old = oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).min(BigDecimal::compareTo).get();
ShopProductIndex shopProductIndex=new ShopProductIndex();
if(item_unit_price_old.compareTo(item_unit_price)>0){
ShopProductBase shopProductBase=new ShopProductBase();
shopProductBase.setProduct_id(shopProductItem.getProduct_id());
shopProductBase.setProduct_unit_price(item_unit_price);
shopProductIndex.setProduct_unit_price(item_unit_price);
shopProductIndex.setProduct_id(shopProductItem.getProduct_id());
updateShopProductBase.add(shopProductBase);
// shopProductBaseService.updateById(shopProductBase);
}
BigDecimal item_unit_price_max_old=oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).max(BigDecimal::compareTo).get();
if(item_unit_price_max.compareTo(item_unit_price_max_old)>0){
shopProductIndex.setProduct_id(shopProductItem.getProduct_id());
shopProductIndex.setProduct_unit_price_max(item_unit_price_max);
}
if(ObjectUtil.isNotEmpty(shopProductIndex.getProduct_id())){
updateShopProductIndex.add(shopProductIndex);
//shopProductIndexService.updateById(shopProductIndex);
queryWrapper.eq("product_id",productId);
List<ShopProductItem> oldShopProductItems= shopProductItemService.list(queryWrapper);
BigDecimal item_unit_price_old = oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).min(BigDecimal::compareTo).get();
BigDecimal item_unit_price_max_old=oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).max(BigDecimal::compareTo).get();
for (ShopProductItem shopProductItem : shopProductItemList) {
List<ShopProductItem> oldShopProductItemList= oldShopProductItems.stream().filter(s -> s.getItem_id().equals(shopProductItem.getItem_id())).collect(Collectors.toList());
if(CollUtil.isEmpty(oldShopProductItemList)){
return CommonResult.failed("不存在商品sku");
}
ShopProductItem oldShopProductItem=oldShopProductItemList.get(0);
oldShopProductItem.setItem_quantity(shopProductItem.getItem_quantity());
oldShopProductItem.setItem_unit_price(shopProductItem.getItem_unit_price());
updateShopProductItem.add(oldShopProductItem);
// shopProductItemService.updateById(oldShopProductItem);
}
ShopProductIndex shopProductIndex=new ShopProductIndex();
ShopProductBase shopProductBase=new ShopProductBase();
if(item_unit_price_old.compareTo(item_unit_price)>0&&oldShopProductItems.size()>1){
shopProductBase.setProduct_id(productId);
shopProductBase.setProduct_unit_price(item_unit_price);
shopProductIndex.setProduct_unit_price(item_unit_price);
shopProductIndex.setProduct_id(productId);
updateShopProductBase.add(shopProductBase);
}
if(item_unit_price_max.compareTo(item_unit_price_max_old)>0&&oldShopProductItems.size()>1){
shopProductIndex.setProduct_id(productId);
shopProductIndex.setProduct_unit_price_max(item_unit_price_max);
}
if(oldShopProductItems.size()==1){
shopProductBase.setProduct_id(productId);
shopProductBase.setProduct_unit_price(item_unit_price);
shopProductIndex.setProduct_id(productId);
shopProductIndex.setProduct_unit_price(item_unit_price);
shopProductIndex.setProduct_unit_price_max(item_unit_price);
shopProductIndex.setProduct_id(productId);
updateShopProductBase.add(shopProductBase);
}
if(ObjectUtil.isNotEmpty(shopProductIndex.getProduct_id())){
updateShopProductIndex.add(shopProductIndex);
}
if(!updateShopProductBase.isEmpty()){
shopProductBaseService.updateBatchById(updateShopProductBase);
}

View File

@ -184,8 +184,14 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
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_enable(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
}
if(StringUtils.isNotEmpty(shopProductBaseList.get(i).getProduct_image())){
shopProductBaseList.get(i).setProduct_state_id(StateCode.PRODUCT_STATE_NORMAL);
shopProductIndex.setProduct_state_id(StateCode.PRODUCT_STATE_NORMAL);
shopProductItems.get(i).setItem_enable(StateCode.PRODUCT_STATE_NORMAL);
}
}
shopProductItems.get(i).setItem_is_default(1);
if(shopProductSpecItem.isUpdate()){
@ -282,7 +288,7 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
item.setItem_spec(item_spec);
shopProductInfo.setProduct_spec(productSpec);
}
String product_uniqid=ShopJsonUtils.generateJsonWithOrgJson(item.getSpec_item_ids(),new Object[]{item.getItem_id(),item.getItem_unit_price(),"",1002});
String product_uniqid=ShopJsonUtils.generateJsonWithOrgJson(item.getSpec_item_ids(),new Object[]{item.getItem_id(),item.getItem_unit_price(),"",item.getItem_enable()});
shopProductInfo.setProduct_uniqid(product_uniqid);
}

View File

@ -673,7 +673,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
// } catch (RuntimeException e) {
// logger.error("同步时间失败" + e.getMessage());
// }
productMappingService.syncAllProductMapping(Integer.valueOf(storeId),DicEnum.YESORNO_0.getCode());
syncShopImages(Integer.valueOf(storeId));//同时商品图库数据
}