新增商品规格同步
This commit is contained in:
parent
0c2808ee6a
commit
6f9565331a
@ -182,5 +182,12 @@ public class ShopProductBase implements Serializable{
|
||||
@TableField(exist = false)
|
||||
private Integer categoryId;
|
||||
|
||||
@ApiModelProperty(value = "规格")
|
||||
@TableField(exist = false)
|
||||
private String specItem;
|
||||
|
||||
@ApiModelProperty(value = "规格单位")
|
||||
@TableField(exist = false)
|
||||
private String specUnit;
|
||||
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ public class ProductTitleUtil {
|
||||
|
||||
//特殊商品
|
||||
public static final Set<String> SPECIAL_NAME = Collections.unmodifiableSet(new HashSet<>(
|
||||
Arrays.asList("水饺", "面条", "包子","卷纸","卫生纸","紫菜汤","猪肉包","叉烧包","香菇青菜包","面包")
|
||||
Arrays.asList("水饺", "面条", "包子","卷纸","卫生纸","紫菜汤","猪肉包","叉烧包","香菇青菜包","面包","黑米")
|
||||
));
|
||||
|
||||
static {
|
||||
|
||||
@ -255,6 +255,7 @@ public class ShopNumberSeqServiceImpl extends BaseServiceImpl<ShopNumberSeqMappe
|
||||
if(null!=redisService.get(RedisKey.STOREDATASPECITEMID)){
|
||||
start=(Integer) redisService.get(RedisKey.STOREDATASPECITEMID);
|
||||
redisService.set(RedisKey.STOREDATASPECITEMID,start+batchSize);
|
||||
return IntStream.rangeClosed(start+1, start+batchSize).boxed().collect(Collectors.toList());
|
||||
}
|
||||
QueryWrapper<ShopProductSpecItem> queryWrapper= new QueryWrapper<>();
|
||||
queryWrapper.select("max(spec_item_id) as spec_item_id");
|
||||
@ -282,6 +283,7 @@ public class ShopNumberSeqServiceImpl extends BaseServiceImpl<ShopNumberSeqMappe
|
||||
if(null!=redisService.get(RedisKey.STOREDATACCOUNTBASEID)){
|
||||
start=(Integer) redisService.get(RedisKey.STOREDATACCOUNTBASEID);
|
||||
redisService.set(RedisKey.STOREDATACCOUNTBASEID,start+batchSize);
|
||||
return IntStream.rangeClosed(start+1, start+batchSize).boxed().collect(Collectors.toList());
|
||||
}
|
||||
Integer maxId= accountService.getAccountMaxId();
|
||||
if(null!=maxId){
|
||||
|
||||
@ -874,6 +874,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
if (StrUtil.isNotBlank(product_number)) {
|
||||
QueryWrapper<ShopProductIndex> indexQueryWrapper = new QueryWrapper<>();
|
||||
indexQueryWrapper.eq("product_number", product_number);
|
||||
indexQueryWrapper.eq("store_id",store_id);
|
||||
ShopProductIndex temp_info_row = shopProductIndexService.findOne(indexQueryWrapper);
|
||||
if (temp_info_row != null && !ObjectUtil.equal(temp_info_row.getProduct_id(), productId)) {
|
||||
// 商品货号已经存在,不可重
|
||||
@ -5605,11 +5606,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(), false,DicEnum.YESORNO_0.getCode());
|
||||
}
|
||||
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(), true,DicEnum.YESORNO_0.getCode());
|
||||
}
|
||||
}
|
||||
return Pair.of(true, String.format("处理成功,新增%d条,更新%d条",
|
||||
|
||||
@ -15,7 +15,14 @@ public interface ProductMappingService extends IBaseService<ProductMapping> {
|
||||
|
||||
CommonResult findPageProductMapping(ProductMapping productMapping,Integer pageNum,Integer pageSize);
|
||||
|
||||
void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId, boolean isUpdate);
|
||||
/**
|
||||
*
|
||||
* @param shopProductBaseList
|
||||
* @param storeId
|
||||
* @param isUpdate
|
||||
* @param isFilter 1:只更新未匹配商品规格,0:更新全部商品规格
|
||||
*/
|
||||
void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId, boolean isUpdate,String isFilter);
|
||||
|
||||
Map getProductMapping(Integer storeId);
|
||||
|
||||
|
||||
@ -123,14 +123,17 @@ 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,boolean isUpdate,String isFilter) {
|
||||
if(DicEnum.YESORNO_1.getCode().equals(isFilter)){
|
||||
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);
|
||||
}
|
||||
@ -203,27 +206,33 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
index++;
|
||||
}
|
||||
proccessItemAndInfo(shopProductItems.get(i),shopProductInfoList.get(i),shopProductSpecItem,isUpdate);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(CollUtil.isNotEmpty(addShopProductSpecItemList)){
|
||||
shopProductSpecItemService.saveBatch(addShopProductSpecItemList,addShopProductSpecItemList.size());
|
||||
}
|
||||
synchronized (this){
|
||||
if(CollUtil.isNotEmpty(updateShopProductSpecItemList)){
|
||||
shopProductSpecItemService.updateBatchById(updateShopProductSpecItemList);
|
||||
shopProductSpecItemService.updateBatchById(updateShopProductSpecItemList,updateShopProductSpecItemList.size());
|
||||
}
|
||||
}
|
||||
if(CollUtil.isNotEmpty(updateShopProductBaseList)){
|
||||
shopProductBaseService.updateBatchById(updateShopProductBaseList);
|
||||
shopProductBaseService.updateBatchById(updateShopProductBaseList,updateShopProductBaseList.size());
|
||||
saveShopProductIndexList(updateShopProductBaseList);
|
||||
}
|
||||
if(CollUtil.isNotEmpty(updateShopProductItemList)){
|
||||
shopProductItemService.updateBatchById(updateShopProductItemList);
|
||||
shopProductItemService.updateBatchById(updateShopProductItemList,updateShopProductItemList.size());
|
||||
}
|
||||
if(CollUtil.isNotEmpty(updateShopProductInfoList)){
|
||||
shopProductInfoService.updateBatchById(updateShopProductInfoList);
|
||||
shopProductInfoService.updateBatchById(updateShopProductInfoList,updateShopProductInfoList.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param item
|
||||
*/
|
||||
@ -279,7 +288,7 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
updateShopProductIndexList.forEach(shopProductIndex -> {
|
||||
shopProductIndex.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);
|
||||
});
|
||||
shopProductIndexService.updateBatchById(updateShopProductIndexList);
|
||||
shopProductIndexService.updateBatchById(updateShopProductIndexList,updateShopProductIndexList.size());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -330,16 +339,23 @@ 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)){
|
||||
if(null!=productMappingMap.get(productName)||StringUtils.isNotEmpty(base.getSpecItem())){
|
||||
ShopBaseProductSpec shopBaseProductSpec= (ShopBaseProductSpec) ShopBaseProductSpecMap.get(categoryId);
|
||||
if(null==shopBaseProductSpec){
|
||||
shopBaseProductSpec= (ShopBaseProductSpec) ShopBaseProductSpecMap.get(String.valueOf(categoryId));
|
||||
}
|
||||
Integer specId= shopBaseProductSpec.getSpec_id();
|
||||
ProductMapping productMapping= (ProductMapping) productMappingMap.get(productName);
|
||||
String Spec_item_name=productMapping.getProductName()+ BigDecimalFormatter.formatWithoutTrailingZeros(productMapping.getSpecValue())+productMapping.getSpecUnit();//
|
||||
Integer Spec_item_id = null;
|
||||
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();
|
||||
//计算价格
|
||||
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))){
|
||||
Spec_item_id= (Integer) shopProductSpecItemMap.get(Spec_item_name);
|
||||
@ -356,9 +372,7 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
addShopProductSpecItem.setSpec_item_name(Spec_item_name);
|
||||
addShopProductSpecItem.setSpec_item_enable(1);//上架
|
||||
addShopProductSpecItem.setSpec_item_order("10");
|
||||
BigDecimal[] bigDecimals= ProductPriceCalculator.calculatePriceAndQuantity(base.getUnit_price(),base.getShop_weight(),productMapping.getSpecValue(),productMapping.getSpecUnit());
|
||||
addShopProductSpecItem.setItemPrice(bigDecimals[0]);
|
||||
addShopProductSpecItem.setItemQuantity(bigDecimals[1]);
|
||||
|
||||
List<Map<String, Object>> items=new ArrayList<>();
|
||||
Map<String,Object> item=new HashMap<>();
|
||||
item.put("name",addShopProductSpecItem.getSpec_item_name());//规格列表
|
||||
@ -408,7 +422,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);
|
||||
this.computeProductMapping(shopProductBaseService.lists(queryWrapper, finalI,SHOPBASEPAGE).getRecords(), finalStoreId,false,DicEnum.YESORNO_1.getCode());
|
||||
return "成功" + finalI;
|
||||
}));
|
||||
}
|
||||
|
||||
@ -771,6 +771,10 @@ public abstract class SyncBaseThirdSxAbstract{
|
||||
shopProductBase.setUnit_price(BigDecimal.valueOf(jsonObj.getDouble("retail_price")));
|
||||
}else {
|
||||
shopProductBase.setShop_weight(stock);
|
||||
if(null!= jsonObj.getJSONArray("product_spec")){
|
||||
shopProductBase.setSpecItem((String) jsonObj.getJSONArray("product_spec").get(0));//规格
|
||||
shopProductBase.setSpecUnit(jsonObj.getStr("unit"));//规格单位
|
||||
}
|
||||
shopProductBase.setProduct_state_id(StateCode.PRODUCT_STATE_OFF_THE_SHELF);//默认是下架
|
||||
shopProductBase.setUnit_price(BigDecimal.valueOf(jsonObj.getDouble("retail_price")));
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ public class SyncShopImageServiceImpl implements SyncShopImageService {
|
||||
@Override
|
||||
public void syncMapingShopImages(Integer storeId) {
|
||||
mappingProductImages(MAPPING_BARCODE,storeId);
|
||||
mappingProductImages(MAPPING_PRODUCTSHORTNAME,storeId);
|
||||
// mappingProductImages(MAPPING_PRODUCTSHORTNAME,storeId);
|
||||
mappingProductImages(MAPPING_PRODUCTNAME,storeId);
|
||||
}
|
||||
|
||||
|
||||
@ -571,6 +571,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
syncPrimaryKey();
|
||||
shopNumberSeqService.clearKey();
|
||||
shopBaseProductCategoryService.clearCategoryCache(storeId);
|
||||
shopNumberSeqService.clearKeyStoreItemSepcId();
|
||||
ExecutorService executor = Executors.newFixedThreadPool(6);
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
// 提交任务
|
||||
@ -626,6 +627,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
//记录到数据库
|
||||
syncPrimaryKey();
|
||||
shopNumberSeqService.clearKey();
|
||||
shopNumberSeqService.clearKeyStoreItemSepcId();
|
||||
shopBaseProductCategoryService.clearCategoryCache(storeId);
|
||||
shopProductSpecItemService.clearExistItem(Integer.valueOf(storeId));
|
||||
baseProductSpecService.clearShopBaseProductSpecMap(Integer.valueOf(storeId));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user