|
@@ -1,23 +1,22 @@
|
|
|
package cn.iocoder.yudao.module.promotion.controller.admin.reward.vo;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.BooleanUtil;
|
|
|
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
|
|
import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum;
|
|
|
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
-import lombok.Data;
|
|
|
-import org.springframework.format.annotation.DateTimeFormat;
|
|
|
-
|
|
|
import jakarta.validation.Valid;
|
|
|
import jakarta.validation.constraints.AssertTrue;
|
|
|
import jakarta.validation.constraints.Future;
|
|
|
import jakarta.validation.constraints.Min;
|
|
|
import jakarta.validation.constraints.NotNull;
|
|
|
+import lombok.Data;
|
|
|
+
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
-
|
|
|
-import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 满减送活动 Base VO,提供给添加、修改、详细的子 VO 使用
|
|
@@ -32,12 +31,10 @@ public class RewardActivityBaseVO {
|
|
|
|
|
|
@Schema(description = "开始时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
|
@NotNull(message = "开始时间不能为空")
|
|
|
- @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
|
|
private LocalDateTime startTime;
|
|
|
|
|
|
@Schema(description = "结束时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
|
@NotNull(message = "结束时间不能为空")
|
|
|
- @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
|
|
@Future(message = "结束时间必须大于当前时间")
|
|
|
private LocalDateTime endTime;
|
|
|
|
|
@@ -54,8 +51,8 @@ public class RewardActivityBaseVO {
|
|
|
@InEnum(value = PromotionProductScopeEnum.class, message = "商品范围必须是 {value}")
|
|
|
private Integer productScope;
|
|
|
|
|
|
- @Schema(description = "商品 SPU 编号的数组", example = "1,2,3")
|
|
|
- private List<Long> productSpuIds;
|
|
|
+ @Schema(description = "商品范围编号的数组", example = "[1, 3]")
|
|
|
+ private List<Long> productScopeValues;
|
|
|
|
|
|
/**
|
|
|
* 优惠规则的数组
|
|
@@ -63,6 +60,13 @@ public class RewardActivityBaseVO {
|
|
|
@Valid // 校验下子对象
|
|
|
private List<Rule> rules;
|
|
|
|
|
|
+ @AssertTrue(message = "商品范围编号的数组不能为空")
|
|
|
+ @JsonIgnore
|
|
|
+ public boolean isProductScopeValuesValid() {
|
|
|
+ return Objects.equals(productScope, PromotionProductScopeEnum.ALL.getScope()) // 全部范围时,可以为空
|
|
|
+ || CollUtil.isNotEmpty(productScopeValues);
|
|
|
+ }
|
|
|
+
|
|
|
@Schema(description = "优惠规则")
|
|
|
@Data
|
|
|
public static class Rule {
|
|
@@ -76,12 +80,20 @@ public class RewardActivityBaseVO {
|
|
|
private Integer discountPrice;
|
|
|
|
|
|
@Schema(description = "是否包邮", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
|
|
+ @NotNull(message = "规则是否包邮不能为空")
|
|
|
private Boolean freeDelivery;
|
|
|
|
|
|
+ @Schema(description = "是否赠送积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
|
|
+ @NotNull(message = "规则是否赠送积分不能为空")
|
|
|
+ private Boolean givePoint;
|
|
|
+
|
|
|
@Schema(description = "赠送的积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
|
|
- @Min(value = 1L, message = "赠送的积分必须大于等于 1")
|
|
|
private Integer point;
|
|
|
|
|
|
+ @Schema(description = "是否赠送优惠券", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
|
|
+ @NotNull(message = "规则是否赠送优惠券不能为空")
|
|
|
+ private Boolean giveCoupon;
|
|
|
+
|
|
|
@Schema(description = "赠送的优惠劵编号的数组", example = "1,2,3")
|
|
|
private List<Long> couponIds;
|
|
|
|
|
@@ -91,7 +103,13 @@ public class RewardActivityBaseVO {
|
|
|
@AssertTrue(message = "优惠劵和数量必须一一对应")
|
|
|
@JsonIgnore
|
|
|
public boolean isCouponCountsValid() {
|
|
|
- return CollUtil.size(couponCounts) == CollUtil.size(couponCounts);
|
|
|
+ return BooleanUtil.isFalse(givePoint) || CollUtil.size(couponIds) == CollUtil.size(couponCounts);
|
|
|
+ }
|
|
|
+
|
|
|
+ @AssertTrue(message = "赠送的积分不能小于 1")
|
|
|
+ @JsonIgnore
|
|
|
+ public boolean isPointValid() {
|
|
|
+ return BooleanUtil.isFalse(givePoint) || (point != null && point >= 1);
|
|
|
}
|
|
|
|
|
|
}
|