fix(product):多规格商品空规格列表保存 500 改为明确参数拒绝

新建商品开多规格开关(specType=true)但不传规格列表时,validateSkuList
收集到的 propertyIds 为空集合,getPropertyList 走 selectByIds 生成
IN() 非法 SQL 直接 500(A33)。

补空集合短路:propertyIds 为空时抛新增业务错误 SKU_PROPERTIES_EMPTY
(1_008_006_005) 明确拒绝,不再崩到 SQL 层。
This commit is contained in:
dadiyang
2026-09-24 21:27:51 +08:00
parent 8e43004cf6
commit a83a9e0429
2 changed files with 8 additions and 3 deletions
@@ -44,6 +44,7 @@ public interface ErrorCodeConstants {
ErrorCode SPU_ATTR_NUMBERS_MUST_BE_EQUALS = new ErrorCode(1_008_006_002, "一个 SPU 下的每个 SKU,其属性项必须一致");
ErrorCode SPU_SKU_NOT_DUPLICATE = new ErrorCode(1_008_006_003, "一个 SPU 下的每个 SKU,必须不重复");
ErrorCode SKU_STOCK_NOT_ENOUGH = new ErrorCode(1_008_006_004, "商品 SKU 库存不足");
ErrorCode SKU_PROPERTIES_EMPTY = new ErrorCode(1_008_006_005, "多规格商品必须从规格列表选择属性组合,SKU 属性不能为空");
// ========== 商品 评价 1-008-007-000 ==========
ErrorCode COMMENT_NOT_EXISTS = new ErrorCode(1_008_007_000, "商品评价不存在");
@@ -106,9 +106,13 @@ public class ProductSkuServiceImpl implements ProductSkuService {
Set<Long> propertyIds = skus.stream().filter(p -> p.getProperties() != null)
// 遍历多个 Property 属性
.flatMap(p -> p.getProperties().stream())
// 将每个 Property 转换成对应的 propertyId,最后形成集合
.map(ProductSkuSaveReqVO.Property::getPropertyId)
.collect(Collectors.toSet());
// 将每个 Property 转换成对应的 propertyId,最后形成集合
.map(ProductSkuSaveReqVO.Property::getPropertyId)
.collect(Collectors.toSet());
// 多规格下,属性组合不能为空:空集合会让后续按 id 批量查询生成非法 SQL(IN())而 500,这里明确拒绝
if (CollUtil.isEmpty(propertyIds)) {
throw exception(SKU_PROPERTIES_EMPTY);
}
List<ProductPropertyDO> propertyList = productPropertyService.getPropertyList(propertyIds);
if (propertyList.size() != propertyIds.size()) {
throw exception(PROPERTY_NOT_EXISTS);