生成订单
This commit is contained in:
@@ -261,7 +261,22 @@ public class ProductService {
|
||||
productRepository.increaseStock(productId, quantity);
|
||||
} else if ("decrease".equals(operation)) {
|
||||
// 减少库存
|
||||
Long currentStock = (Long) redisService.get(stockKey);
|
||||
Object stockObj = redisService.get(stockKey);
|
||||
Long currentStock = null;
|
||||
if (stockObj != null) {
|
||||
if (stockObj instanceof Integer) {
|
||||
currentStock = ((Integer) stockObj).longValue();
|
||||
} else if (stockObj instanceof Long) {
|
||||
currentStock = (Long) stockObj;
|
||||
} else if (stockObj instanceof String) {
|
||||
try {
|
||||
currentStock = Long.parseLong((String) stockObj);
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("库存数据格式错误: 商品ID={}, 数据={}", productId, stockObj);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (currentStock == null || currentStock < quantity) {
|
||||
log.warn("库存不足: 商品ID={}, 当前库存={}, 需要扣减={}", productId, currentStock, quantity);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user