商品草稿状态也要校验

This commit is contained in:
litianxiang
2026-05-07 14:11:18 +08:00
parent 08f5a482eb
commit daf4c30a91
3 changed files with 24 additions and 27 deletions

View File

@@ -51,7 +51,7 @@ public class ListingSaveDTO implements Serializable {
@Schema(description = "适用性别: male/female") @Schema(description = "适用性别: male/female")
private String designFor; private String designFor;
/** 商品分类列表: outwear/trousers/blouse/dress/skirt/accessories */ /** 商品分类列表: outwear/trousers/blouse/dress/skirt/others/tops/bottoms */
@Schema(description = "商品分类列表: outwear/trousers/blouse/dress/skirt/accessories") @Schema(description = "商品分类列表: outwear/trousers/blouse/dress/skirt/others/tops/bottoms")
private List<String> productCategory; private List<String> productCategory;
} }

View File

@@ -18,7 +18,7 @@ public enum ProductCategoryEnum {
DRESS("dress", "连衣裙"), DRESS("dress", "连衣裙"),
SKIRT("skirt", "半身裙"), SKIRT("skirt", "半身裙"),
OTHERS("others", "其他"), OTHERS("others", "其他"),
TOP("top", "上装"), TOP("tops", "上装"),
BOTTOMS("bottoms", "下装"); BOTTOMS("bottoms", "下装");
@JsonValue @JsonValue

View File

@@ -52,7 +52,6 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
BeanUtils.copyProperties(dto, entity); BeanUtils.copyProperties(dto, entity);
entity.setSellerId(sellerId); entity.setSellerId(sellerId);
if (dto.getDesignFor() != null && DesignForEnum.of(dto.getDesignFor()) == null) { if (dto.getDesignFor() != null && DesignForEnum.of(dto.getDesignFor()) == null) {
throw new BusinessException("designFor 只能为 male/female"); throw new BusinessException("designFor 只能为 male/female");
@@ -247,29 +246,27 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
* 当 status 为 1已发布检查必填字段 * 当 status 为 1已发布检查必填字段
*/ */
private void validateListingFields(ListingSaveDTO dto) { private void validateListingFields(ListingSaveDTO dto) {
if (dto.getStatus() != null && dto.getStatus() == 1) { if (!StringUtils.hasText(dto.getTitle())) {
if (!StringUtils.hasText(dto.getTitle())) { throw new BusinessException("商品标题不能为空");
throw new BusinessException("商品标题不能为空"); }
} if (!StringUtils.hasText(dto.getDescription())) {
if (!StringUtils.hasText(dto.getDescription())) { throw new BusinessException("商品描述不能为空");
throw new BusinessException("商品描述不能为空"); }
} if (dto.getPrice() == null) {
if (dto.getPrice() == null) { throw new BusinessException("商品价格不能为空");
throw new BusinessException("商品价格不能为空"); }
} if (!StringUtils.hasText(dto.getDesignFor())) {
if (!StringUtils.hasText(dto.getDesignFor())) { throw new BusinessException("适用性别不能为空");
throw new BusinessException("适用性别不能为空"); }
} if (DesignForEnum.of(dto.getDesignFor()) == null) {
if (DesignForEnum.of(dto.getDesignFor()) == null) { throw new BusinessException("适用性别只能为 male/female");
throw new BusinessException("适用性别只能为 male/female"); }
} if (CollectionUtils.isEmpty(dto.getProductCategory())) {
if (CollectionUtils.isEmpty(dto.getProductCategory())) { throw new BusinessException("商品分类不能为空");
throw new BusinessException("商品分类不能为空"); }
} for (String category : dto.getProductCategory()) {
for (String category : dto.getProductCategory()) { if (ProductCategoryEnum.of(category) == null) {
if (ProductCategoryEnum.of(category) == null) { throw new BusinessException("商品分类只能为 outwear/trousers/blouse/dress/skirt/others/tops/bottoms");
throw new BusinessException("商品分类只能为 outwear/trousers/blouse/dress/skirt/accessories");
}
} }
} }
} }