生成订单

This commit is contained in:
2025-07-03 00:25:30 +08:00
parent 883839e97c
commit bd9330675e
3 changed files with 234 additions and 168 deletions

View File

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