Commit 979ba0f9161f36e76aeb14486f1549c9180669c0
1 parent
035c2cf2
promotion:实现优惠劵模板的逻辑
Showing
14 changed files
with
699 additions
and
8 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
| @@ -19,4 +19,8 @@ public interface ErrorCodeConstants { | @@ -19,4 +19,8 @@ public interface ErrorCodeConstants { | ||
| 19 | ErrorCode COUPON_NO_MATCH_SPU = new ErrorCode(1003003000, "优惠劵没有可使用的商品!"); | 19 | ErrorCode COUPON_NO_MATCH_SPU = new ErrorCode(1003003000, "优惠劵没有可使用的商品!"); |
| 20 | ErrorCode COUPON_NO_MATCH_MIN_PRICE = new ErrorCode(1003003000, "不满足优惠劵使用的最低金额"); | 20 | ErrorCode COUPON_NO_MATCH_MIN_PRICE = new ErrorCode(1003003000, "不满足优惠劵使用的最低金额"); |
| 21 | 21 | ||
| 22 | + // ========== 优惠劵模板 1003004000 ========== | ||
| 23 | + ErrorCode COUPON_TEMPLATE_NOT_EXISTS = new ErrorCode(1003004000, "优惠劵模板不存在"); | ||
| 24 | + ErrorCode COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL = new ErrorCode(1003004001, "发放数量不能小于已领取数量({})"); | ||
| 25 | + | ||
| 22 | } | 26 | } |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/coupon/CouponTemplateValidityTypeEnum.java
| @@ -15,8 +15,8 @@ import java.util.Arrays; | @@ -15,8 +15,8 @@ import java.util.Arrays; | ||
| 15 | @Getter | 15 | @Getter |
| 16 | public enum CouponTemplateValidityTypeEnum implements IntArrayValuable { | 16 | public enum CouponTemplateValidityTypeEnum implements IntArrayValuable { |
| 17 | 17 | ||
| 18 | - FIXED_DATE(1, "固定日期"), | ||
| 19 | - FIXED_TERM_TODAY(2, "领取日期"), | 18 | + DATE(1, "固定日期可用"), |
| 19 | + TERM(2, "领取之后可用"), | ||
| 20 | ; | 20 | ; |
| 21 | 21 | ||
| 22 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponTemplateValidityTypeEnum::getType).toArray(); | 22 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponTemplateValidityTypeEnum::getType).toArray(); |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/CouponTemplateController.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateCreateReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplatePageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateRespVO; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateUpdateReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.promotion.convert.coupon.CouponTemplateConvert; | ||
| 10 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | ||
| 11 | +import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService; | ||
| 12 | +import io.swagger.annotations.Api; | ||
| 13 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 14 | +import io.swagger.annotations.ApiOperation; | ||
| 15 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 16 | +import org.springframework.validation.annotation.Validated; | ||
| 17 | +import org.springframework.web.bind.annotation.*; | ||
| 18 | + | ||
| 19 | +import javax.annotation.Resource; | ||
| 20 | +import javax.validation.Valid; | ||
| 21 | + | ||
| 22 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 23 | + | ||
| 24 | +@Api(tags = "管理后台 - 优惠劵模板") | ||
| 25 | +@RestController | ||
| 26 | +@RequestMapping("/promotion/coupon-template") | ||
| 27 | +@Validated | ||
| 28 | +public class CouponTemplateController { | ||
| 29 | + | ||
| 30 | + @Resource | ||
| 31 | + private CouponTemplateService couponTemplateService; | ||
| 32 | + | ||
| 33 | + @PostMapping("/create") | ||
| 34 | + @ApiOperation("创建优惠劵模板") | ||
| 35 | + @PreAuthorize("@ss.hasPermission('promotion:coupon-template:create')") | ||
| 36 | + public CommonResult<Long> createCouponTemplate(@Valid @RequestBody CouponTemplateCreateReqVO createReqVO) { | ||
| 37 | + return success(couponTemplateService.createCouponTemplate(createReqVO)); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @PutMapping("/update") | ||
| 41 | + @ApiOperation("更新优惠劵模板") | ||
| 42 | + @PreAuthorize("@ss.hasPermission('promotion:coupon-template:update')") | ||
| 43 | + public CommonResult<Boolean> updateCouponTemplate(@Valid @RequestBody CouponTemplateUpdateReqVO updateReqVO) { | ||
| 44 | + couponTemplateService.updateCouponTemplate(updateReqVO); | ||
| 45 | + return success(true); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + @DeleteMapping("/delete") | ||
| 49 | + @ApiOperation("删除优惠劵模板") | ||
| 50 | + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) | ||
| 51 | + @PreAuthorize("@ss.hasPermission('promotion:coupon-template:delete')") | ||
| 52 | + public CommonResult<Boolean> deleteCouponTemplate(@RequestParam("id") Long id) { | ||
| 53 | + couponTemplateService.deleteCouponTemplate(id); | ||
| 54 | + return success(true); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @GetMapping("/get") | ||
| 58 | + @ApiOperation("获得优惠劵模板") | ||
| 59 | + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | ||
| 60 | + @PreAuthorize("@ss.hasPermission('promotion:coupon-template:query')") | ||
| 61 | + public CommonResult<CouponTemplateRespVO> getCouponTemplate(@RequestParam("id") Long id) { | ||
| 62 | + CouponTemplateDO couponTemplate = couponTemplateService.getCouponTemplate(id); | ||
| 63 | + return success(CouponTemplateConvert.INSTANCE.convert(couponTemplate)); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @GetMapping("/page") | ||
| 67 | + @ApiOperation("获得优惠劵模板分页") | ||
| 68 | + @PreAuthorize("@ss.hasPermission('promotion:coupon-template:query')") | ||
| 69 | + public CommonResult<PageResult<CouponTemplateRespVO>> getCouponTemplatePage(@Valid CouponTemplatePageReqVO pageVO) { | ||
| 70 | + PageResult<CouponTemplateDO> pageResult = couponTemplateService.getCouponTemplatePage(pageVO); | ||
| 71 | + return success(CouponTemplateConvert.INSTANCE.convertPage(pageResult)); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponTemplateBaseVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.hutool.core.util.ObjectUtil; | ||
| 5 | +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.PromotionProductScopeEnum; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; | ||
| 9 | +import io.swagger.annotations.ApiModelProperty; | ||
| 10 | +import lombok.Data; | ||
| 11 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 12 | + | ||
| 13 | +import javax.validation.constraints.AssertTrue; | ||
| 14 | +import javax.validation.constraints.Min; | ||
| 15 | +import javax.validation.constraints.NotNull; | ||
| 16 | +import java.util.Date; | ||
| 17 | +import java.util.List; | ||
| 18 | +import java.util.Objects; | ||
| 19 | + | ||
| 20 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | +* 优惠劵模板 Base VO,提供给添加、修改、详细的子 VO 使用 | ||
| 24 | +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||
| 25 | +*/ | ||
| 26 | +@Data | ||
| 27 | +public class CouponTemplateBaseVO { | ||
| 28 | + | ||
| 29 | + @ApiModelProperty(value = "优惠劵名", required = true, example = "春节送送送") | ||
| 30 | + @NotNull(message = "优惠劵名不能为空") | ||
| 31 | + private String name; | ||
| 32 | + | ||
| 33 | + @ApiModelProperty(value = "发行总量", required = true, example = "1024", notes = "-1 - 则表示不限制发放数量") | ||
| 34 | + @NotNull(message = "发行总量不能为空") | ||
| 35 | + private Integer totalCount; | ||
| 36 | + | ||
| 37 | + @ApiModelProperty(value = "每人限领个数", required = true, example = "66", notes = "-1 - 则表示不限制") | ||
| 38 | + @NotNull(message = "每人限领个数不能为空") | ||
| 39 | + private Integer takeLimitCount; | ||
| 40 | + | ||
| 41 | + @ApiModelProperty(value = "领取方式", required = true, example = "1", notes = "参见 CouponTakeTypeEnum 枚举类") | ||
| 42 | + @NotNull(message = "领取方式不能为空") | ||
| 43 | + private Integer takeType; | ||
| 44 | + | ||
| 45 | + @ApiModelProperty(value = "是否设置满多少金额可用", required = true, example = "100", notes = "单位:分;0 - 不限制") | ||
| 46 | + @NotNull(message = "是否设置满多少金额可用不能为空") | ||
| 47 | + private Integer usePrice; | ||
| 48 | + | ||
| 49 | + @ApiModelProperty(value = "商品范围", required = true, example = "1", notes = "参见 PromotionProductScopeEnum 枚举类") | ||
| 50 | + @NotNull(message = "商品范围不能为空") | ||
| 51 | + @InEnum(PromotionProductScopeEnum.class) | ||
| 52 | + private Integer productScope; | ||
| 53 | + | ||
| 54 | + @ApiModelProperty(value = "商品 SPU 编号的数组", example = "1,3") | ||
| 55 | + private List<Long> productSpuIds; | ||
| 56 | + | ||
| 57 | + @ApiModelProperty(value = "生效日期类型", required = true, example = "1") | ||
| 58 | + @NotNull(message = "生效日期类型不能为空") | ||
| 59 | + @InEnum(CouponTemplateValidityTypeEnum.class) | ||
| 60 | + private Integer validityType; | ||
| 61 | + | ||
| 62 | + @ApiModelProperty(value = "固定日期 - 生效开始时间") | ||
| 63 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 64 | + private Date validStartTime; | ||
| 65 | + | ||
| 66 | + @ApiModelProperty(value = "固定日期 - 生效结束时间") | ||
| 67 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 68 | + private Date validEndTime; | ||
| 69 | + | ||
| 70 | + @ApiModelProperty(value = "领取日期 - 开始天数") | ||
| 71 | + @Min(value = 0L, message = "开始天数必须大于 0") | ||
| 72 | + private Integer fixedStartTerm; | ||
| 73 | + | ||
| 74 | + @ApiModelProperty(value = "领取日期 - 结束天数") | ||
| 75 | + @Min(value = 1L, message = "开始天数必须大于 1") | ||
| 76 | + private Integer fixedEndTerm; | ||
| 77 | + | ||
| 78 | + @ApiModelProperty(value = "优惠类型", required = true, example = "1", notes = "参见 PromotionDiscountTypeEnum 枚举") | ||
| 79 | + @NotNull(message = "优惠类型不能为空") | ||
| 80 | + @InEnum(PromotionDiscountTypeEnum.class) | ||
| 81 | + private Integer discountType; | ||
| 82 | + | ||
| 83 | + @ApiModelProperty(value = "折扣百分比", example = "80", notes = "例如说,80% 为 80") | ||
| 84 | + @Min(value = 1) | ||
| 85 | + private Integer discountPercent; | ||
| 86 | + | ||
| 87 | + @ApiModelProperty(value = "优惠金额", example = "10", notes = "单位:分") | ||
| 88 | + @Min(value = 1) | ||
| 89 | + private Integer discountPrice; | ||
| 90 | + | ||
| 91 | + @ApiModelProperty(value = "折扣上限", example = "100", notes = "单位:分,仅在 discountType 为 PERCENT 使用") | ||
| 92 | + private Integer discountPriceLimit; | ||
| 93 | + | ||
| 94 | + @AssertTrue(message = "商品 SPU 编号的数组不能为空") | ||
| 95 | + public boolean isProductSpuIdsValid() { | ||
| 96 | + return Objects.equals(productScope, PromotionProductScopeEnum.ALL.getScope()) // 全部范围时,可以为空 | ||
| 97 | + || CollUtil.isNotEmpty(productSpuIds); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + @AssertTrue(message = "生效开始时间不能为空") | ||
| 101 | + public boolean isValidStartTimeValid() { | ||
| 102 | + return ObjectUtil.notEqual(validityType, CouponTemplateValidityTypeEnum.DATE.getType()) | ||
| 103 | + || validStartTime != null; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @AssertTrue(message = "生效结束时间不能为空") | ||
| 107 | + public boolean isValidEndTimeValid() { | ||
| 108 | + return ObjectUtil.notEqual(validityType, CouponTemplateValidityTypeEnum.DATE.getType()) | ||
| 109 | + || validEndTime != null; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + @AssertTrue(message = "开始天数不能为空") | ||
| 113 | + public boolean isFixedStartTermValid() { | ||
| 114 | + return ObjectUtil.notEqual(validityType, CouponTemplateValidityTypeEnum.TERM.getType()) | ||
| 115 | + || fixedStartTerm != null; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + @AssertTrue(message = "结束天数不能为空") | ||
| 119 | + public boolean isFixedEndTermValid() { | ||
| 120 | + return ObjectUtil.notEqual(validityType, CouponTemplateValidityTypeEnum.TERM.getType()) | ||
| 121 | + || fixedEndTerm != null; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + @AssertTrue(message = "折扣百分比不能为空") | ||
| 125 | + public boolean isDiscountPercentValid() { | ||
| 126 | + return ObjectUtil.notEqual(discountType, PromotionDiscountTypeEnum.PERCENT.getType()) | ||
| 127 | + || discountPercent != null; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + @AssertTrue(message = "优惠金额不能为空") | ||
| 131 | + public boolean isDiscountPriceValid() { | ||
| 132 | + return ObjectUtil.notEqual(discountType, PromotionDiscountTypeEnum.PRICE.getType()) | ||
| 133 | + || discountPrice != null; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + @AssertTrue(message = "折扣上限不能为空") | ||
| 137 | + public boolean isDiscountPriceLimit() { | ||
| 138 | + return ObjectUtil.notEqual(discountType, PromotionDiscountTypeEnum.PERCENT.getType()) | ||
| 139 | + || discountPriceLimit != null; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponTemplateCreateReqVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import lombok.Data; | ||
| 5 | +import lombok.EqualsAndHashCode; | ||
| 6 | +import lombok.ToString; | ||
| 7 | + | ||
| 8 | +@ApiModel("管理后台 - 优惠劵模板创建 Request VO") | ||
| 9 | +@Data | ||
| 10 | +@EqualsAndHashCode(callSuper = true) | ||
| 11 | +@ToString(callSuper = true) | ||
| 12 | +public class CouponTemplateCreateReqVO extends CouponTemplateBaseVO { | ||
| 13 | + | ||
| 14 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponTemplatePageReqVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; | ||
| 6 | +import io.swagger.annotations.ApiModel; | ||
| 7 | +import io.swagger.annotations.ApiModelProperty; | ||
| 8 | +import lombok.Data; | ||
| 9 | +import lombok.EqualsAndHashCode; | ||
| 10 | +import lombok.ToString; | ||
| 11 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 12 | + | ||
| 13 | +import javax.validation.constraints.NotNull; | ||
| 14 | +import java.util.Date; | ||
| 15 | + | ||
| 16 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 17 | + | ||
| 18 | +@ApiModel("管理后台 - 优惠劵模板分页 Request VO") | ||
| 19 | +@Data | ||
| 20 | +@EqualsAndHashCode(callSuper = true) | ||
| 21 | +@ToString(callSuper = true) | ||
| 22 | +public class CouponTemplatePageReqVO extends PageParam { | ||
| 23 | + | ||
| 24 | + @ApiModelProperty(value = "优惠劵名", example = "你好") | ||
| 25 | + private String name; | ||
| 26 | + | ||
| 27 | + @ApiModelProperty(value = "状态", example = "1", notes = "参见 CommonStatusEnum 枚举类") | ||
| 28 | + private Integer status; | ||
| 29 | + | ||
| 30 | + @ApiModelProperty(value = "优惠类型", example = "1", notes = "参见 PromotionDiscountTypeEnum 枚举") | ||
| 31 | + private Integer discountType; | ||
| 32 | + | ||
| 33 | + @ApiModelProperty(value = "创建时间") | ||
| 34 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 35 | + private Date[] createTime; | ||
| 36 | + | ||
| 37 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponTemplateRespVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 5 | +import io.swagger.annotations.ApiModel; | ||
| 6 | +import io.swagger.annotations.ApiModelProperty; | ||
| 7 | +import lombok.Data; | ||
| 8 | +import lombok.EqualsAndHashCode; | ||
| 9 | +import lombok.ToString; | ||
| 10 | + | ||
| 11 | +import java.util.Date; | ||
| 12 | + | ||
| 13 | +@ApiModel("管理后台 - 优惠劵模板 Response VO") | ||
| 14 | +@Data | ||
| 15 | +@EqualsAndHashCode(callSuper = true) | ||
| 16 | +@ToString(callSuper = true) | ||
| 17 | +public class CouponTemplateRespVO extends CouponTemplateBaseVO { | ||
| 18 | + | ||
| 19 | + @ApiModelProperty(value = "模板编号", required = true, example = "1024") | ||
| 20 | + private Long id; | ||
| 21 | + | ||
| 22 | + @ApiModelProperty(value = "状态", required = true, example = "1") | ||
| 23 | + @InEnum(CommonStatusEnum.class) | ||
| 24 | + private Integer status; | ||
| 25 | + | ||
| 26 | + @ApiModelProperty(value = "领取优惠券的数量", required = true, example = "1024") | ||
| 27 | + private Integer takeNum; | ||
| 28 | + | ||
| 29 | + @ApiModelProperty(value = "使用优惠券的次数", required = true, example = "2048") | ||
| 30 | + private Integer useCount; | ||
| 31 | + | ||
| 32 | + @ApiModelProperty(value = "创建时间", required = true) | ||
| 33 | + private Date createTime; | ||
| 34 | + | ||
| 35 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponTemplateUpdateReqVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.EqualsAndHashCode; | ||
| 7 | +import lombok.ToString; | ||
| 8 | + | ||
| 9 | +import javax.validation.constraints.NotNull; | ||
| 10 | + | ||
| 11 | +@ApiModel("管理后台 - 优惠劵模板更新 Request VO") | ||
| 12 | +@Data | ||
| 13 | +@EqualsAndHashCode(callSuper = true) | ||
| 14 | +@ToString(callSuper = true) | ||
| 15 | +public class CouponTemplateUpdateReqVO extends CouponTemplateBaseVO { | ||
| 16 | + | ||
| 17 | + @ApiModelProperty(value = "模板编号", required = true, example = "1024") | ||
| 18 | + @NotNull(message = "模板编号不能为空") | ||
| 19 | + private Long id; | ||
| 20 | + | ||
| 21 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponTemplateConvert.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.convert.coupon; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateCreateReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateRespVO; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateUpdateReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | ||
| 8 | +import org.mapstruct.Mapper; | ||
| 9 | +import org.mapstruct.factory.Mappers; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 优惠劵模板 Convert | ||
| 13 | + * | ||
| 14 | + * @author 芋道源码 | ||
| 15 | + */ | ||
| 16 | +@Mapper | ||
| 17 | +public interface CouponTemplateConvert { | ||
| 18 | + | ||
| 19 | + CouponTemplateConvert INSTANCE = Mappers.getMapper(CouponTemplateConvert.class); | ||
| 20 | + | ||
| 21 | + CouponTemplateDO convert(CouponTemplateCreateReqVO bean); | ||
| 22 | + | ||
| 23 | + CouponTemplateDO convert(CouponTemplateUpdateReqVO bean); | ||
| 24 | + | ||
| 25 | + CouponTemplateRespVO convert(CouponTemplateDO bean); | ||
| 26 | + | ||
| 27 | + PageResult<CouponTemplateRespVO> convertPage(PageResult<CouponTemplateDO> page); | ||
| 28 | + | ||
| 29 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/coupon/CouponTemplateDO.java
| @@ -73,7 +73,7 @@ public class CouponTemplateDO extends BaseDO { | @@ -73,7 +73,7 @@ public class CouponTemplateDO extends BaseDO { | ||
| 73 | * 是否设置满多少金额可用,单位:分 | 73 | * 是否设置满多少金额可用,单位:分 |
| 74 | * | 74 | * |
| 75 | * 0 - 不限制 | 75 | * 0 - 不限制 |
| 76 | - * 大于0 - 多少金额可用 | 76 | + * 大于 0 - 多少金额可用 |
| 77 | */ | 77 | */ |
| 78 | private Integer usePrice; | 78 | private Integer usePrice; |
| 79 | /** | 79 | /** |
| @@ -96,19 +96,19 @@ public class CouponTemplateDO extends BaseDO { | @@ -96,19 +96,19 @@ public class CouponTemplateDO extends BaseDO { | ||
| 96 | /** | 96 | /** |
| 97 | * 固定日期 - 生效开始时间 | 97 | * 固定日期 - 生效开始时间 |
| 98 | * | 98 | * |
| 99 | - * 当 {@link #validityType} 为 {@link CouponTemplateValidityTypeEnum#FIXED_DATE} | 99 | + * 当 {@link #validityType} 为 {@link CouponTemplateValidityTypeEnum#DATE} |
| 100 | */ | 100 | */ |
| 101 | private Date validStartTime; | 101 | private Date validStartTime; |
| 102 | /** | 102 | /** |
| 103 | * 固定日期 - 生效结束时间 | 103 | * 固定日期 - 生效结束时间 |
| 104 | * | 104 | * |
| 105 | - * 当 {@link #validityType} 为 {@link CouponTemplateValidityTypeEnum#FIXED_DATE} | 105 | + * 当 {@link #validityType} 为 {@link CouponTemplateValidityTypeEnum#DATE} |
| 106 | */ | 106 | */ |
| 107 | private Date validEndTime; | 107 | private Date validEndTime; |
| 108 | /** | 108 | /** |
| 109 | * 领取日期 - 结束天数 | 109 | * 领取日期 - 结束天数 |
| 110 | * | 110 | * |
| 111 | - * 当 {@link #validityType} 为 {@link CouponTemplateValidityTypeEnum#FIXED_TERM_TODAY} | 111 | + * 当 {@link #validityType} 为 {@link CouponTemplateValidityTypeEnum#TERM} |
| 112 | */ | 112 | */ |
| 113 | private Integer fixedEndTerm; | 113 | private Integer fixedEndTerm; |
| 114 | // ========== 使用规则 END ========== | 114 | // ========== 使用规则 END ========== |
| @@ -129,11 +129,11 @@ public class CouponTemplateDO extends BaseDO { | @@ -129,11 +129,11 @@ public class CouponTemplateDO extends BaseDO { | ||
| 129 | /** | 129 | /** |
| 130 | * 优惠金额,单位:分 | 130 | * 优惠金额,单位:分 |
| 131 | * | 131 | * |
| 132 | - * 当 {@link #discountType} 为 {@link PromotionDiscountTypeEnum#PRICE} | 132 | + * 当 {@link #discountType} 为 {@link PromotionDiscountTypeEnum#PRICE} 生效 |
| 133 | */ | 133 | */ |
| 134 | private Integer discountPrice; | 134 | private Integer discountPrice; |
| 135 | /** | 135 | /** |
| 136 | - * 折扣上限,仅在 {@link #discountType} 等于 {@link PromotionDiscountTypeEnum#PRICE} 时生效 | 136 | + * 折扣上限,仅在 {@link #discountType} 等于 {@link PromotionDiscountTypeEnum#PERCENT} 时生效 |
| 137 | * | 137 | * |
| 138 | * 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。 | 138 | * 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。 |
| 139 | */ | 139 | */ |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponTemplateMapper.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.dal.mysql.coupon; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplatePageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | ||
| 8 | +import org.apache.ibatis.annotations.Mapper; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 优惠劵模板 Mapper | ||
| 12 | + * | ||
| 13 | + * @author 芋道源码 | ||
| 14 | + */ | ||
| 15 | +@Mapper | ||
| 16 | +public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> { | ||
| 17 | + | ||
| 18 | + default PageResult<CouponTemplateDO> selectPage(CouponTemplatePageReqVO reqVO) { | ||
| 19 | + return selectPage(reqVO, new LambdaQueryWrapperX<CouponTemplateDO>() | ||
| 20 | + .likeIfPresent(CouponTemplateDO::getName, reqVO.getName()) | ||
| 21 | + .eqIfPresent(CouponTemplateDO::getStatus, reqVO.getStatus()) | ||
| 22 | + .eqIfPresent(CouponTemplateDO::getDiscountType, reqVO.getDiscountType()) | ||
| 23 | + .betweenIfPresent(CouponTemplateDO::getCreateTime, reqVO.getCreateTime()) | ||
| 24 | + .orderByDesc(CouponTemplateDO::getId)); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateService.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.service.coupon; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateCreateReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplatePageReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateUpdateReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | ||
| 8 | + | ||
| 9 | +import javax.validation.Valid; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 优惠劵模板 Service 接口 | ||
| 13 | + * | ||
| 14 | + * @author 芋道源码 | ||
| 15 | + */ | ||
| 16 | +public interface CouponTemplateService { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 创建优惠劵模板 | ||
| 20 | + * | ||
| 21 | + * @param createReqVO 创建信息 | ||
| 22 | + * @return 编号 | ||
| 23 | + */ | ||
| 24 | + Long createCouponTemplate(@Valid CouponTemplateCreateReqVO createReqVO); | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 更新优惠劵模板 | ||
| 28 | + * | ||
| 29 | + * @param updateReqVO 更新信息 | ||
| 30 | + */ | ||
| 31 | + void updateCouponTemplate(@Valid CouponTemplateUpdateReqVO updateReqVO); | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 删除优惠劵模板 | ||
| 35 | + * | ||
| 36 | + * @param id 编号 | ||
| 37 | + */ | ||
| 38 | + void deleteCouponTemplate(Long id); | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 获得优惠劵模板 | ||
| 42 | + * | ||
| 43 | + * @param id 编号 | ||
| 44 | + * @return 优惠劵模板 | ||
| 45 | + */ | ||
| 46 | + CouponTemplateDO getCouponTemplate(Long id); | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * 获得优惠劵模板分页 | ||
| 50 | + * | ||
| 51 | + * @param pageReqVO 分页查询 | ||
| 52 | + * @return 优惠劵模板分页 | ||
| 53 | + */ | ||
| 54 | + PageResult<CouponTemplateDO> getCouponTemplatePage(CouponTemplatePageReqVO pageReqVO); | ||
| 55 | + | ||
| 56 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.service.coupon; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateCreateReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplatePageReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateUpdateReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.convert.coupon.CouponTemplateConvert; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | ||
| 9 | +import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | + | ||
| 15 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 16 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 优惠劵模板 Service 实现类 | ||
| 20 | + * | ||
| 21 | + * @author 芋道源码 | ||
| 22 | + */ | ||
| 23 | +@Service | ||
| 24 | +@Validated | ||
| 25 | +public class CouponTemplateServiceImpl implements CouponTemplateService { | ||
| 26 | + | ||
| 27 | + @Resource | ||
| 28 | + private CouponTemplateMapper couponTemplateMapper; | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) { | ||
| 32 | + // 插入 | ||
| 33 | + CouponTemplateDO couponTemplate = CouponTemplateConvert.INSTANCE.convert(createReqVO); | ||
| 34 | + couponTemplateMapper.insert(couponTemplate); | ||
| 35 | + // 返回 | ||
| 36 | + return couponTemplate.getId(); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public void updateCouponTemplate(CouponTemplateUpdateReqVO updateReqVO) { | ||
| 41 | + // 校验存在 | ||
| 42 | + CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId()); | ||
| 43 | + // 校验发放数量不能过小 | ||
| 44 | + if (updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) { | ||
| 45 | + throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount()); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + // 更新 | ||
| 49 | + CouponTemplateDO updateObj = CouponTemplateConvert.INSTANCE.convert(updateReqVO); | ||
| 50 | + couponTemplateMapper.updateById(updateObj); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Override | ||
| 54 | + public void deleteCouponTemplate(Long id) { | ||
| 55 | + // 校验存在 | ||
| 56 | + validateCouponTemplateExists(id); | ||
| 57 | + // 删除 | ||
| 58 | + couponTemplateMapper.deleteById(id); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + private CouponTemplateDO validateCouponTemplateExists(Long id) { | ||
| 62 | + CouponTemplateDO couponTemplate = couponTemplateMapper.selectById(id); | ||
| 63 | + if (couponTemplate == null) { | ||
| 64 | + throw exception(COUPON_TEMPLATE_NOT_EXISTS); | ||
| 65 | + } | ||
| 66 | + return couponTemplate; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @Override | ||
| 70 | + public CouponTemplateDO getCouponTemplate(Long id) { | ||
| 71 | + return couponTemplateMapper.selectById(id); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public PageResult<CouponTemplateDO> getCouponTemplatePage(CouponTemplatePageReqVO pageReqVO) { | ||
| 76 | + return couponTemplateMapper.selectPage(pageReqVO); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImplTest.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.service.coupon; | ||
| 2 | + | ||
| 3 | +import org.junit.jupiter.api.Disabled; | ||
| 4 | +import org.junit.jupiter.api.Test; | ||
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 6 | + | ||
| 7 | +import javax.annotation.Resource; | ||
| 8 | + | ||
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||
| 10 | + | ||
| 11 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.*; | ||
| 12 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | ||
| 13 | +import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper; | ||
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 15 | + | ||
| 16 | +import javax.annotation.Resource; | ||
| 17 | +import org.springframework.context.annotation.Import; | ||
| 18 | +import java.util.*; | ||
| 19 | + | ||
| 20 | +import static cn.hutool.core.util.RandomUtil.*; | ||
| 21 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | ||
| 22 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | ||
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | ||
| 24 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | ||
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | ||
| 26 | +import static org.junit.jupiter.api.Assertions.*; | ||
| 27 | +import static org.mockito.Mockito.*; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | +* {@link CouponTemplateServiceImpl} 的单元测试类 | ||
| 31 | +* | ||
| 32 | +* @author 芋道源码 | ||
| 33 | +*/ | ||
| 34 | +@Import(CouponTemplateServiceImpl.class) | ||
| 35 | +public class CouponTemplateServiceImplTest extends BaseDbUnitTest { | ||
| 36 | + | ||
| 37 | + @Resource | ||
| 38 | + private CouponTemplateServiceImpl couponTemplateService; | ||
| 39 | + | ||
| 40 | + @Resource | ||
| 41 | + private CouponTemplateMapper couponTemplateMapper; | ||
| 42 | + | ||
| 43 | + @Test | ||
| 44 | + public void testCreateCouponTemplate_success() { | ||
| 45 | + // 准备参数 | ||
| 46 | + CouponTemplateCreateReqVO reqVO = randomPojo(CouponTemplateCreateReqVO.class); | ||
| 47 | + | ||
| 48 | + // 调用 | ||
| 49 | + Long couponTemplateId = couponTemplateService.createCouponTemplate(reqVO); | ||
| 50 | + // 断言 | ||
| 51 | + assertNotNull(couponTemplateId); | ||
| 52 | + // 校验记录的属性是否正确 | ||
| 53 | + CouponTemplateDO couponTemplate = couponTemplateMapper.selectById(couponTemplateId); | ||
| 54 | + assertPojoEquals(reqVO, couponTemplate); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @Test | ||
| 58 | + public void testUpdateCouponTemplate_success() { | ||
| 59 | + // mock 数据 | ||
| 60 | + CouponTemplateDO dbCouponTemplate = randomPojo(CouponTemplateDO.class); | ||
| 61 | + couponTemplateMapper.insert(dbCouponTemplate);// @Sql: 先插入出一条存在的数据 | ||
| 62 | + // 准备参数 | ||
| 63 | + CouponTemplateUpdateReqVO reqVO = randomPojo(CouponTemplateUpdateReqVO.class, o -> { | ||
| 64 | + o.setId(dbCouponTemplate.getId()); // 设置更新的 ID | ||
| 65 | + }); | ||
| 66 | + | ||
| 67 | + // 调用 | ||
| 68 | + couponTemplateService.updateCouponTemplate(reqVO); | ||
| 69 | + // 校验是否更新正确 | ||
| 70 | + CouponTemplateDO couponTemplate = couponTemplateMapper.selectById(reqVO.getId()); // 获取最新的 | ||
| 71 | + assertPojoEquals(reqVO, couponTemplate); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Test | ||
| 75 | + public void testUpdateCouponTemplate_notExists() { | ||
| 76 | + // 准备参数 | ||
| 77 | + CouponTemplateUpdateReqVO reqVO = randomPojo(CouponTemplateUpdateReqVO.class); | ||
| 78 | + | ||
| 79 | + // 调用, 并断言异常 | ||
| 80 | + assertServiceException(() -> couponTemplateService.updateCouponTemplate(reqVO), COUPON_TEMPLATE_NOT_EXISTS); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Test | ||
| 84 | + public void testDeleteCouponTemplate_success() { | ||
| 85 | + // mock 数据 | ||
| 86 | + CouponTemplateDO dbCouponTemplate = randomPojo(CouponTemplateDO.class); | ||
| 87 | + couponTemplateMapper.insert(dbCouponTemplate);// @Sql: 先插入出一条存在的数据 | ||
| 88 | + // 准备参数 | ||
| 89 | + Long id = dbCouponTemplate.getId(); | ||
| 90 | + | ||
| 91 | + // 调用 | ||
| 92 | + couponTemplateService.deleteCouponTemplate(id); | ||
| 93 | + // 校验数据不存在了 | ||
| 94 | + assertNull(couponTemplateMapper.selectById(id)); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Test | ||
| 98 | + public void testDeleteCouponTemplate_notExists() { | ||
| 99 | + // 准备参数 | ||
| 100 | + Long id = randomLongId(); | ||
| 101 | + | ||
| 102 | + // 调用, 并断言异常 | ||
| 103 | + assertServiceException(() -> couponTemplateService.deleteCouponTemplate(id), COUPON_TEMPLATE_NOT_EXISTS); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @Test | ||
| 107 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | ||
| 108 | + public void testGetCouponTemplatePage() { | ||
| 109 | + // mock 数据 | ||
| 110 | + CouponTemplateDO dbCouponTemplate = randomPojo(CouponTemplateDO.class, o -> { // 等会查询到 | ||
| 111 | + o.setName(null); | ||
| 112 | + o.setStatus(null); | ||
| 113 | + o.setType(null); | ||
| 114 | + o.setCreateTime(null); | ||
| 115 | + }); | ||
| 116 | + couponTemplateMapper.insert(dbCouponTemplate); | ||
| 117 | + // 测试 name 不匹配 | ||
| 118 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setName(null))); | ||
| 119 | + // 测试 status 不匹配 | ||
| 120 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setStatus(null))); | ||
| 121 | + // 测试 type 不匹配 | ||
| 122 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setType(null))); | ||
| 123 | + // 测试 createTime 不匹配 | ||
| 124 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setCreateTime(null))); | ||
| 125 | + // 准备参数 | ||
| 126 | + CouponTemplatePageReqVO reqVO = new CouponTemplatePageReqVO(); | ||
| 127 | + reqVO.setName(null); | ||
| 128 | + reqVO.setStatus(null); | ||
| 129 | + reqVO.setType(null); | ||
| 130 | + reqVO.setCreateTime((new Date[]{})); | ||
| 131 | + | ||
| 132 | + // 调用 | ||
| 133 | + PageResult<CouponTemplateDO> pageResult = couponTemplateService.getCouponTemplatePage(reqVO); | ||
| 134 | + // 断言 | ||
| 135 | + assertEquals(1, pageResult.getTotal()); | ||
| 136 | + assertEquals(1, pageResult.getList().size()); | ||
| 137 | + assertPojoEquals(dbCouponTemplate, pageResult.getList().get(0)); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + @Test | ||
| 141 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | ||
| 142 | + public void testGetCouponTemplateList() { | ||
| 143 | + // mock 数据 | ||
| 144 | + CouponTemplateDO dbCouponTemplate = randomPojo(CouponTemplateDO.class, o -> { // 等会查询到 | ||
| 145 | + o.setName(null); | ||
| 146 | + o.setStatus(null); | ||
| 147 | + o.setType(null); | ||
| 148 | + o.setCreateTime(null); | ||
| 149 | + }); | ||
| 150 | + couponTemplateMapper.insert(dbCouponTemplate); | ||
| 151 | + // 测试 name 不匹配 | ||
| 152 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setName(null))); | ||
| 153 | + // 测试 status 不匹配 | ||
| 154 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setStatus(null))); | ||
| 155 | + // 测试 type 不匹配 | ||
| 156 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setType(null))); | ||
| 157 | + // 测试 createTime 不匹配 | ||
| 158 | + couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setCreateTime(null))); | ||
| 159 | + // 准备参数 | ||
| 160 | + CouponTemplateExportReqVO reqVO = new CouponTemplateExportReqVO(); | ||
| 161 | + reqVO.setName(null); | ||
| 162 | + reqVO.setStatus(null); | ||
| 163 | + reqVO.setType(null); | ||
| 164 | + reqVO.setCreateTime((new Date[]{})); | ||
| 165 | + | ||
| 166 | + // 调用 | ||
| 167 | + List<CouponTemplateDO> list = couponTemplateService.getCouponTemplateList(reqVO); | ||
| 168 | + // 断言 | ||
| 169 | + assertEquals(1, list.size()); | ||
| 170 | + assertPojoEquals(dbCouponTemplate, list.get(0)); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | +} |