同步思迅库存扣减问题修复

This commit is contained in:
liyj 2025-09-24 18:32:14 +08:00
parent 4efd79c180
commit 4a11ac1867
2 changed files with 7 additions and 4 deletions

View File

@ -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);

View File

@ -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");