Commit 8a1798607ca771c322b3b03cb37190c128b38659
1 parent
b69ba946
【BUG】修改电子优惠券指定发放不能保存的问题
Showing
2 changed files
with
63 additions
and
2 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/template/CouponTemplateBaseVO.java
| @@ -2,9 +2,11 @@ package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template; | @@ -2,9 +2,11 @@ package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.ObjectUtil; | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | +import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; | ||
| 5 | import cn.iocoder.yudao.framework.common.validation.InEnum; | 6 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 6 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; | 7 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; |
| 7 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; | 8 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; |
| 9 | +import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; | ||
| 8 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; | 10 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; |
| 9 | import com.fasterxml.jackson.annotation.JsonFormat; | 11 | import com.fasterxml.jackson.annotation.JsonFormat; |
| 10 | import com.fasterxml.jackson.annotation.JsonIgnore; | 12 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| @@ -12,6 +14,7 @@ import io.swagger.v3.oas.annotations.media.Schema; | @@ -12,6 +14,7 @@ import io.swagger.v3.oas.annotations.media.Schema; | ||
| 12 | import lombok.Data; | 14 | import lombok.Data; |
| 13 | import org.springframework.format.annotation.DateTimeFormat; | 15 | import org.springframework.format.annotation.DateTimeFormat; |
| 14 | 16 | ||
| 17 | +import jakarta.validation.Validator; | ||
| 15 | import jakarta.validation.constraints.AssertTrue; | 18 | import jakarta.validation.constraints.AssertTrue; |
| 16 | import jakarta.validation.constraints.Min; | 19 | import jakarta.validation.constraints.Min; |
| 17 | import jakarta.validation.constraints.NotNull; | 20 | import jakarta.validation.constraints.NotNull; |
| @@ -37,11 +40,11 @@ public class CouponTemplateBaseVO { | @@ -37,11 +40,11 @@ public class CouponTemplateBaseVO { | ||
| 37 | private String description; | 40 | private String description; |
| 38 | 41 | ||
| 39 | @Schema(description = "发行总量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") // -1 - 则表示不限制发放数量 | 42 | @Schema(description = "发行总量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") // -1 - 则表示不限制发放数量 |
| 40 | - @NotNull(message = "发行总量不能为空") | 43 | + @NotNull(message = "发行总量不能为空", groups = {User.class}) |
| 41 | private Integer totalCount; | 44 | private Integer totalCount; |
| 42 | 45 | ||
| 43 | @Schema(description = "每人限领个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "66") // -1 - 则表示不限制 | 46 | @Schema(description = "每人限领个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "66") // -1 - 则表示不限制 |
| 44 | - @NotNull(message = "每人限领个数不能为空") | 47 | + @NotNull(message = "每人限领个数不能为空", groups = {User.class}) |
| 45 | private Integer takeLimitCount; | 48 | private Integer takeLimitCount; |
| 46 | 49 | ||
| 47 | @Schema(description = "领取方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 50 | @Schema(description = "领取方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| @@ -89,13 +92,16 @@ public class CouponTemplateBaseVO { | @@ -89,13 +92,16 @@ public class CouponTemplateBaseVO { | ||
| 89 | private Integer discountType; | 92 | private Integer discountType; |
| 90 | 93 | ||
| 91 | @Schema(description = "折扣百分比", example = "80") // 例如说,80% 为 80 | 94 | @Schema(description = "折扣百分比", example = "80") // 例如说,80% 为 80 |
| 95 | + @NotNull(message = "折扣百分比不能为空", groups = {Percent.class}) | ||
| 92 | private Integer discountPercent; | 96 | private Integer discountPercent; |
| 93 | 97 | ||
| 94 | @Schema(description = "优惠金额", example = "10") | 98 | @Schema(description = "优惠金额", example = "10") |
| 95 | @Min(value = 0, message = "优惠金额需要大于等于 0") | 99 | @Min(value = 0, message = "优惠金额需要大于等于 0") |
| 100 | + @NotNull(message = "优惠金额不能为空", groups = {Price.class}) | ||
| 96 | private Integer discountPrice; | 101 | private Integer discountPrice; |
| 97 | 102 | ||
| 98 | @Schema(description = "折扣上限", example = "100") // 单位:分,仅在 discountType 为 PERCENT 使用 | 103 | @Schema(description = "折扣上限", example = "100") // 单位:分,仅在 discountType 为 PERCENT 使用 |
| 104 | + @NotNull(message = "折扣上限不能为空", groups = {Percent.class}) | ||
| 99 | private Integer discountLimitPrice; | 105 | private Integer discountLimitPrice; |
| 100 | 106 | ||
| 101 | @AssertTrue(message = "商品范围编号的数组不能为空") | 107 | @AssertTrue(message = "商品范围编号的数组不能为空") |
| @@ -154,4 +160,54 @@ public class CouponTemplateBaseVO { | @@ -154,4 +160,54 @@ public class CouponTemplateBaseVO { | ||
| 154 | || discountLimitPrice != null; | 160 | || discountLimitPrice != null; |
| 155 | } | 161 | } |
| 156 | 162 | ||
| 163 | + //-------------------------领取方式校验start---------------------------- | ||
| 164 | + | ||
| 165 | + /** | ||
| 166 | + * 直接领取 | ||
| 167 | + */ | ||
| 168 | + public interface User { | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + /** | ||
| 172 | + * 指定发放 | ||
| 173 | + */ | ||
| 174 | + public interface Admin { | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + //-------------------------领取方式校验end------------------------------ | ||
| 178 | + | ||
| 179 | + //-------------------------优惠类型校验start---------------------------- | ||
| 180 | + | ||
| 181 | + /** | ||
| 182 | + * 满减 | ||
| 183 | + */ | ||
| 184 | + public interface Price { | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + /** | ||
| 188 | + * 折扣 | ||
| 189 | + */ | ||
| 190 | + public interface Percent { | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + //-------------------------优惠类型校验end------------------------------ | ||
| 194 | + | ||
| 195 | + public void validate(Validator validator) { | ||
| 196 | + | ||
| 197 | + //领取方式校验 | ||
| 198 | + if (CouponTakeTypeEnum.USER.getType().equals(takeType)) { | ||
| 199 | + ValidationUtils.validate(validator, this, User.class); | ||
| 200 | + } else if (CouponTakeTypeEnum.ADMIN.getType().equals(takeType)) { | ||
| 201 | + ValidationUtils.validate(validator, this, Admin.class); | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + //优惠类型校验 | ||
| 205 | + if (PromotionDiscountTypeEnum.PRICE.getType().equals(discountType)){ | ||
| 206 | + ValidationUtils.validate(validator, this, Price.class); | ||
| 207 | + } else if (PromotionDiscountTypeEnum.PERCENT.getType().equals(discountType)) { | ||
| 208 | + ValidationUtils.validate(validator, this, Percent.class); | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + } | ||
| 212 | + | ||
| 157 | } | 213 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java
| @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper; | @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper; | ||
| 13 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; | 13 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; |
| 14 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; | 14 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; |
| 15 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
| 16 | +import jakarta.validation.Validator; | ||
| 16 | import org.springframework.validation.annotation.Validated; | 17 | import org.springframework.validation.annotation.Validated; |
| 17 | 18 | ||
| 18 | import jakarta.annotation.Resource; | 19 | import jakarta.annotation.Resource; |
| @@ -40,9 +41,13 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | @@ -40,9 +41,13 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | ||
| 40 | private ProductCategoryApi productCategoryApi; | 41 | private ProductCategoryApi productCategoryApi; |
| 41 | @Resource | 42 | @Resource |
| 42 | private ProductSpuApi productSpuApi; | 43 | private ProductSpuApi productSpuApi; |
| 44 | + @Resource | ||
| 45 | + private Validator validator; | ||
| 43 | 46 | ||
| 44 | @Override | 47 | @Override |
| 45 | public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) { | 48 | public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) { |
| 49 | + // 校验参数 | ||
| 50 | + createReqVO.validate(validator); | ||
| 46 | // 校验商品范围 | 51 | // 校验商品范围 |
| 47 | validateProductScope(createReqVO.getProductScope(), createReqVO.getProductScopeValues()); | 52 | validateProductScope(createReqVO.getProductScope(), createReqVO.getProductScopeValues()); |
| 48 | // 插入 | 53 | // 插入 |