feat(pricing): 增加商品参数校验和默认值设置
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good

- 为每个产品增加产品类型和产品 ID 的非空校验
- 为购买数量和数量设置默认值为 1,如果未提供
This commit is contained in:
2025-09-08 14:03:15 +08:00
parent c1ca4e8631
commit 6fb3cb93a9

View File

@@ -36,6 +36,20 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService {
throw new PriceCalculationException("商品列表不能为空");
}
request.getProducts().forEach(product -> {
if (product.getProductType() == null) {
throw new PriceCalculationException("商品类型不能为空");
}
if (product.getProductId() == null) {
throw new PriceCalculationException("商品ID不能为空");
}
if (product.getPurchaseCount() == null) {
product.setPurchaseCount(1);
}
if (product.getQuantity() == null) {
product.setQuantity(1);
}
});
// 计算商品价格和原价
PriceDetails priceDetails = calculateProductsPriceWithOriginal(request.getProducts());
BigDecimal totalAmount = priceDetails.getTotalAmount();