同步商品库存给思迅数据库

This commit is contained in:
liyj 2025-09-24 10:35:25 +08:00
parent 9710b321de
commit 53aca6ede9
2 changed files with 11 additions and 10 deletions

View File

@ -4211,7 +4211,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
if (ObjectUtil.equal(order_item_inventory_lock, 1001) || ObjectUtil.equal(order_item_inventory_lock, 1002)) {
Long item_id = order_item_row.getItem_id();
ShopProductItem shopProductItem = shopProductItemService.get(item_id);
if (shopProductItem != null && CheckUtil.isEmpty(shopProductItem.getItem_src_id())) {
if (shopProductItem != null && CheckUtil.isNotEmpty(shopProductItem.getItem_src_id())) {
shopProductItem.setItem_quantity_frozen(shopProductItem.getItem_quantity_frozen() - order_item_quantity);
if (!shopProductItemService.edit(shopProductItem)) {
throw new ApiException(String.format(I18nUtil._("释放: %s 冻结库存失败!"), order_item_row.getItem_id()));
@ -7224,7 +7224,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
// start 判断增加冻结库存
Integer _product_inventory_lock = Convert.toInt(_item.get("product_inventory_lock"));
if (ObjectUtil.equal(_product_inventory_lock, 1001) && CheckUtil.isEmpty(item_src_id)) {
if (ObjectUtil.equal(_product_inventory_lock, 1001) && CheckUtil.isNotEmpty(item_src_id)) {
if (shopProductItemService.lockSkuStock(item_id, cart_quantity) <= 0) {
throw new ApiException(String.format(I18nUtil._("更改: %s 冻结库存失败!"), item.get("item_id")));
}

View File

@ -853,20 +853,21 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
continue;
}
ShopProductItem spuItem = shopProductItems.get(0);
cn.hutool.json.JSONArray array_item_spec= JSONUtil.parseArray(spuItem.getItem_spec());
if(array_item_spec.isEmpty()){
continue;
}
cn.hutool.json.JSONObject item = (cn.hutool.json.JSONObject) ((cn.hutool.json.JSONObject) array_item_spec.get(0)).get("item");
String name = Convert.toStr(item.get("name"));
BigDecimal itemQuaryty = getBigDecimal(delta, name);
String key=RedisKey.STOREDATARELEASE+":"+spuItem.getStore_id();
Long productId = spuItem.getProduct_id();
ShopProductBase productBase = shopProductBaseService.get(productId);
if(productBase==null){
continue;
}
String itemId=productBase.getProduct_number();
String key=RedisKey.STOREDATARELEASE+":"+productBase.getStore_id();
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());
continue;
}
cn.hutool.json.JSONObject item = (cn.hutool.json.JSONObject) ((cn.hutool.json.JSONObject) array_item_spec.get(0)).get("item");
String name = Convert.toStr(item.get("name"));
BigDecimal itemQuaryty = getBigDecimal(delta, name);
// 使用 Redis HINCRBY 保证原子性和高性能
redisTemplate.opsForHash().increment(key, itemId, itemQuaryty.doubleValue());
} catch (Exception e) {