同步思迅库存扣减问题修复
This commit is contained in:
parent
12fbc5a16f
commit
52eead2229
@ -4220,7 +4220,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
if (!shopProductItemService.edit(shopProductItem)) {
|
||||
throw new ApiException(String.format(I18nUtil._("释放: %s 冻结库存失败!"), order_item_row.getItem_id()));
|
||||
}
|
||||
|
||||
log.debug("释放库存Item_src_id:{},数量:{}",shopProductItem.getItem_src_id(),order_item_quantity);
|
||||
// RMK 第三方数据同步相关:redis 给这个商品加上对应的库存
|
||||
Map<String, Integer> stockDeltaMap = new HashMap<>();
|
||||
stockDeltaMap.put(Convert.toStr(shopProductItem.getItem_src_id()), order_item_quantity);
|
||||
@ -7234,6 +7234,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
}
|
||||
|
||||
// RMK 第三方数据同步相关:redis 给这个商品减去上对应的库存
|
||||
log.debug("减库存Item_src_id:{},数量:{}",item_src_id,cart_quantity);
|
||||
Map<String, Integer> stockDeltaMap = new HashMap<>();
|
||||
stockDeltaMap.put(Convert.toStr(item_src_id), -cart_quantity);
|
||||
syncThirdDataService.incrProductStockToRedis(stockDeltaMap);
|
||||
|
||||
@ -768,6 +768,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
|
||||
@Override
|
||||
public ThirdApiRes getStoreDataRelease(String appKey, String sign) {
|
||||
// incrProductStockToRedis(new HashMap<>());
|
||||
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign)) {
|
||||
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
|
||||
}
|
||||
@ -817,7 +818,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
// 从 Redis 获取 hash 结构的所有键值对
|
||||
String key=RedisKey.STOREDATARELEASE+":"+storeId;
|
||||
Map<Object, Object> redisHash = redisTemplate.opsForHash().entries(key);
|
||||
if (redisHash == null || redisHash.isEmpty()) {
|
||||
if (redisHash.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
// 转换为 Map<String, Integer>
|
||||
@ -834,11 +835,12 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
|
||||
@Override
|
||||
public void incrProductStockToRedis(Map<String, Integer> stockDeltaMap) {
|
||||
// stockDeltaMap.put("5458", 1);
|
||||
// 校验参数,避免空指针
|
||||
if (CollectionUtil.isEmpty(stockDeltaMap)) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug("扣减库存的map:{}", JSONUtil.toJsonStr(stockDeltaMap));
|
||||
for (Map.Entry<String, Integer> entry : stockDeltaMap.entrySet()) {
|
||||
String productKey = entry.getKey();
|
||||
Integer delta = entry.getValue();
|
||||
@ -862,7 +864,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
String itemId=productBase.getProduct_number();
|
||||
cn.hutool.json.JSONArray array_item_spec= JSONUtil.parseArray(spuItem.getItem_spec());
|
||||
if(array_item_spec.isEmpty()){
|
||||
redisTemplate.opsForHash().increment(key, spuItem.getItem_id(), delta.doubleValue());
|
||||
redisTemplate.opsForHash().increment(key, itemId, delta.doubleValue());
|
||||
continue;
|
||||
}
|
||||
cn.hutool.json.JSONObject item = (cn.hutool.json.JSONObject) ((cn.hutool.json.JSONObject) array_item_spec.get(0)).get("item");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user