新增商品规格名称匹配

This commit is contained in:
liyj 2025-07-23 15:14:46 +08:00
parent 6f9565331a
commit 1c5b4648f5
4 changed files with 27 additions and 26 deletions

View File

@ -5606,11 +5606,11 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
//计算规格
if (CollUtil.isNotEmpty(newProducts)) {
productMappingService.computeProductMapping(newProducts, newProducts.get(0).getStore_id(), false,DicEnum.YESORNO_0.getCode());
productMappingService.computeProductMapping(newProducts, newProducts.get(0).getStore_id(), false);
}
if (CollUtil.isNotEmpty(updateProducts)) {//如果时自动优先则按平台规则切割商品
if (DicEnum.PRIORITY_MODE_2.getCode().equals(priorityMode)) {
productMappingService.computeProductMapping(updateProducts, updateProducts.get(0).getStore_id(), true,DicEnum.YESORNO_0.getCode());
productMappingService.computeProductMapping(updateProducts, updateProducts.get(0).getStore_id(), true);
}
}
return Pair.of(true, String.format("处理成功,新增%d条更新%d条",

View File

@ -20,9 +20,8 @@ public interface ProductMappingService extends IBaseService<ProductMapping> {
* @param shopProductBaseList
* @param storeId
* @param isUpdate
* @param isFilter 1:只更新未匹配商品规格0更新全部商品规格
*/
void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId, boolean isUpdate,String isFilter);
void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId, boolean isUpdate);
Map getProductMapping(Integer storeId);

View File

@ -123,14 +123,12 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
}
@Override
public void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId,boolean isUpdate,String isFilter) {
if(DicEnum.YESORNO_1.getCode().equals(isFilter)){
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());
if (CollUtil.isEmpty(shopProductBaseList)) {
log.info("没有规格数据要处理");
return;
}
}
Map shopProductSpecItemMap = shopProductSpecItemService.getExistItem(storeId);
Map productMappingMap = this.getProductMapping(storeId);
@ -339,22 +337,19 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
*/
private ShopProductSpecItem processShopProductSpecItem(ShopProductBase base,Integer categoryId,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,Integer specItemId){
String productName=base.getProduct_name();
if(null!=productMappingMap.get(productName)||StringUtils.isNotEmpty(base.getSpecItem())){
if(null!=productMappingMap.get(productName)){
ShopBaseProductSpec shopBaseProductSpec= (ShopBaseProductSpec) ShopBaseProductSpecMap.get(categoryId);
if(null==shopBaseProductSpec){
shopBaseProductSpec= (ShopBaseProductSpec) ShopBaseProductSpecMap.get(String.valueOf(categoryId));
}
Integer specId= shopBaseProductSpec.getSpec_id();
String Spec_item_name=base.getSpecItem()+(StringUtils.isNotEmpty(base.getSpecUnit())?base.getSpecUnit():"");
ShopProductSpecItem addShopProductSpecItem=new ShopProductSpecItem();
if(StringUtils.isEmpty(Spec_item_name)){//如不是切割规格不需要重置价格
ProductMapping productMapping= (ProductMapping) productMappingMap.get(productName);
Spec_item_name=productMapping.getProductName()+ BigDecimalFormatter.formatWithoutTrailingZeros(productMapping.getSpecValue())+productMapping.getSpecUnit();
String Spec_item_name=productMapping.getProductName()+ BigDecimalFormatter.formatWithoutTrailingZeros(productMapping.getSpecValue())+productMapping.getSpecUnit();
//计算价格
BigDecimal[] bigDecimals= ProductPriceCalculator.calculatePriceAndQuantity(base.getUnit_price(),base.getShop_weight(),productMapping.getSpecValue(),productMapping.getSpecUnit());
addShopProductSpecItem.setItemPrice(bigDecimals[0]);
addShopProductSpecItem.setItemQuantity(bigDecimals[1]);
}
Integer Spec_item_id = null;
addShopProductSpecItem.setUpdate(true);
if(ObjectUtil.isNotEmpty(shopProductSpecItemMap.get(Spec_item_name))){
@ -422,7 +417,7 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
int finalI = i;
Integer finalStoreId = storeId;
futures.add(executor.submit(() -> {
this.computeProductMapping(shopProductBaseService.lists(queryWrapper, finalI,SHOPBASEPAGE).getRecords(), finalStoreId,false,DicEnum.YESORNO_1.getCode());
this.computeProductMapping(shopProductBaseService.lists(queryWrapper, finalI,SHOPBASEPAGE).getRecords(), finalStoreId,false);
return "成功" + finalI;
}));
}

View File

@ -735,9 +735,7 @@ public abstract class SyncBaseThirdSxAbstract{
shopProductBase.setCategoryId(categoryId);
shopProductBase.setProduct_sale_time(Convert.toDate(DateUtil.current() + 600)); //10分钟
shopProductBase.setStore_id(storeIdInt);
shopProductBase.setProduct_number((String) jsonObj.get("product_number"));
shopProductBase.setProduct_name((String) jsonObj.get("product_name"));
shopProductBase.setStore_name(store_row.getStore_name());
shopProductBase.setProduct_tips("");
@ -778,6 +776,15 @@ 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():"";
productName=productName+spectItem+"/"+unit;
}
shopProductBase.setProduct_name(productName);
// ShopProductIndex
ShopProductIndex shopProductIndex = new ShopProductIndex();
shopProductIndex.setProduct_add_time(currentDate.getTime());
@ -785,8 +792,8 @@ public abstract class SyncBaseThirdSxAbstract{
shopProductIndex.setStore_category_ids(""); // 店铺分类编号(DOT)
shopProductIndex.setProduct_tags("");// 商品标签(DOT)
shopProductIndex.setBrand_id(0);
shopProductIndex.setProduct_name(shopProductBase.getProduct_name()); // 产品名称:店铺平台先在对用表中检索后通过id检索,检索使用
shopProductIndex.setProduct_name_index(shopProductIndex.getProduct_name()); // 名称索引关键字(DOT)
shopProductIndex.setProduct_name(productName); // 产品名称:店铺平台先在对用表中检索后通过id检索,检索使用
shopProductIndex.setProduct_name_index(productName); // 名称索引关键字(DOT)
shopProductIndex.setCategory_id(categoryId); // 商品分类
shopProductIndex.setProduct_fx_enable(0); // 供应商是否允许批发市场分销
shopProductIndex.setProduct_dist_enable(0); // 是否允许三级分销
@ -864,7 +871,7 @@ public abstract class SyncBaseThirdSxAbstract{
//shopProductImage
ShopProductImage shopProductImage = new ShopProductImage();
shopProductImage.setStore_id(storeIdInt);
shopProductImage.setProduct_name(jsonObj.getStr("product_name"));
shopProductImage.setProduct_name(productName);
shopProductImage.setProduct_from("1005");
//添加数据到list