Commit 0e5b7734acba55d9dae9267eb25f4331ef9cfcbf
1 parent
873b5306
promotion:增加满减送活动的后端 20%
Showing
16 changed files
with
604 additions
and
58 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
| @@ -27,4 +27,7 @@ public interface ErrorCodeConstants { | @@ -27,4 +27,7 @@ public interface ErrorCodeConstants { | ||
| 27 | ErrorCode COUPON_NOT_EXISTS = new ErrorCode(1003005000, "优惠劵不存在"); | 27 | ErrorCode COUPON_NOT_EXISTS = new ErrorCode(1003005000, "优惠劵不存在"); |
| 28 | ErrorCode COUPON_DELETE_FAIL_USED = new ErrorCode(1003005001, "回收优惠劵失败,优惠劵已被使用"); | 28 | ErrorCode COUPON_DELETE_FAIL_USED = new ErrorCode(1003005001, "回收优惠劵失败,优惠劵已被使用"); |
| 29 | 29 | ||
| 30 | + // ========== 满减送活动 1003006000 ========== | ||
| 31 | + ErrorCode REWARD_ACTIVITY_NOT_EXISTS = new ErrorCode(1003006000, "满减送活动不存在"); | ||
| 32 | + | ||
| 30 | } | 33 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/RewardActivityController.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.reward; | ||
| 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.reward.vo.RewardActivityCreateReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityRespVO; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.promotion.convert.reward.RewardActivityConvert; | ||
| 10 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | ||
| 11 | +import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityService; | ||
| 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/reward-activity") | ||
| 27 | +@Validated | ||
| 28 | +public class RewardActivityController { | ||
| 29 | + | ||
| 30 | + @Resource | ||
| 31 | + private RewardActivityService rewardActivityService; | ||
| 32 | + | ||
| 33 | + @PostMapping("/create") | ||
| 34 | + @ApiOperation("创建满减送活动") | ||
| 35 | + @PreAuthorize("@ss.hasPermission('promotion:reward-activity:create')") | ||
| 36 | + public CommonResult<Long> createRewardActivity(@Valid @RequestBody RewardActivityCreateReqVO createReqVO) { | ||
| 37 | + return success(rewardActivityService.createRewardActivity(createReqVO)); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @PutMapping("/update") | ||
| 41 | + @ApiOperation("更新满减送活动") | ||
| 42 | + @PreAuthorize("@ss.hasPermission('promotion:reward-activity:update')") | ||
| 43 | + public CommonResult<Boolean> updateRewardActivity(@Valid @RequestBody RewardActivityUpdateReqVO updateReqVO) { | ||
| 44 | + rewardActivityService.updateRewardActivity(updateReqVO); | ||
| 45 | + return success(true); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + @DeleteMapping("/delete") | ||
| 49 | + @ApiOperation("删除满减送活动") | ||
| 50 | + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class) | ||
| 51 | + @PreAuthorize("@ss.hasPermission('promotion:reward-activity:delete')") | ||
| 52 | + public CommonResult<Boolean> deleteRewardActivity(@RequestParam("id") Integer id) { | ||
| 53 | + rewardActivityService.deleteRewardActivity(id); | ||
| 54 | + return success(true); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @GetMapping("/get") | ||
| 58 | + @ApiOperation("获得满减送活动") | ||
| 59 | + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class) | ||
| 60 | + @PreAuthorize("@ss.hasPermission('promotion:reward-activity:query')") | ||
| 61 | + public CommonResult<RewardActivityRespVO> getRewardActivity(@RequestParam("id") Integer id) { | ||
| 62 | + RewardActivityDO rewardActivity = rewardActivityService.getRewardActivity(id); | ||
| 63 | + return success(RewardActivityConvert.INSTANCE.convert(rewardActivity)); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @GetMapping("/page") | ||
| 67 | + @ApiOperation("获得满减送活动分页") | ||
| 68 | + @PreAuthorize("@ss.hasPermission('promotion:reward-activity:query')") | ||
| 69 | + public CommonResult<PageResult<RewardActivityRespVO>> getRewardActivityPage(@Valid RewardActivityPageReqVO pageVO) { | ||
| 70 | + PageResult<RewardActivityDO> pageResult = rewardActivityService.getRewardActivityPage(pageVO); | ||
| 71 | + return success(RewardActivityConvert.INSTANCE.convertPage(pageResult)); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/vo/RewardActivityBaseVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.reward.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 7 | + | ||
| 8 | +import javax.validation.constraints.NotNull; | ||
| 9 | +import java.util.Date; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | +* 满减送活动 Base VO,提供给添加、修改、详细的子 VO 使用 | ||
| 16 | +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||
| 17 | +*/ | ||
| 18 | +@Data | ||
| 19 | +public class RewardActivityBaseVO { | ||
| 20 | + | ||
| 21 | + @ApiModelProperty(value = "活动标题", required = true, example = "满啦满啦") | ||
| 22 | + @NotNull(message = "活动标题不能为空") | ||
| 23 | + private String name; | ||
| 24 | + | ||
| 25 | + @ApiModelProperty(value = "开始时间", required = true) | ||
| 26 | + @NotNull(message = "开始时间不能为空") | ||
| 27 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 28 | + private Date startTime; | ||
| 29 | + | ||
| 30 | + @ApiModelProperty(value = "结束时间", required = true) | ||
| 31 | + @NotNull(message = "结束时间不能为空") | ||
| 32 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 33 | + private Date endTime; | ||
| 34 | + | ||
| 35 | + @ApiModelProperty(value = "备注", example = "biubiubiu") | ||
| 36 | + private String remark; | ||
| 37 | + | ||
| 38 | + @ApiModelProperty(value = "条件类型", required = true, example = "1") | ||
| 39 | + @NotNull(message = "条件类型不能为空") | ||
| 40 | + private Integer conditionType; | ||
| 41 | + | ||
| 42 | + @ApiModelProperty(value = "商品范围", required = true, example = "1") | ||
| 43 | + @NotNull(message = "商品范围不能为空") | ||
| 44 | + private Integer productScope; | ||
| 45 | + | ||
| 46 | + @ApiModelProperty(value = "商品 SPU 编号的数组", example = "1,2,3") | ||
| 47 | + private List<Long> productSpuIds; | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * 优惠规则的数组 | ||
| 51 | + */ | ||
| 52 | + private List<Rule> rules; | ||
| 53 | + | ||
| 54 | + @ApiModel("优惠规则") | ||
| 55 | + @Data | ||
| 56 | + public static class Rule { | ||
| 57 | + | ||
| 58 | + @ApiModelProperty(value = "优惠门槛", required = true, example = "100", notes = "1. 满 N 元,单位:分; 2. 满 N 件") | ||
| 59 | + private Integer limit; | ||
| 60 | + | ||
| 61 | + @ApiModelProperty(value = "优惠价格", required = true, example = "100", notes = "单位:分") | ||
| 62 | + private Integer discountPrice; | ||
| 63 | + | ||
| 64 | + @ApiModelProperty(value = "是否包邮", required = true, example = "true") | ||
| 65 | + private Boolean freeDelivery; | ||
| 66 | + | ||
| 67 | + @ApiModelProperty(value = "赠送的积分", required = true, example = "100") | ||
| 68 | + private Integer point; | ||
| 69 | + | ||
| 70 | + @ApiModelProperty(value = "赠送的优惠劵编号的数组", example = "1,2,3") | ||
| 71 | + private List<Long> couponIds; | ||
| 72 | + | ||
| 73 | + @ApiModelProperty(value = "赠送的优惠卷数量的数组", example = "1,2,3") | ||
| 74 | + private List<Integer> couponCounts; | ||
| 75 | + | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/vo/RewardActivityCreateReqVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.reward.vo; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | +import io.swagger.annotations.*; | ||
| 5 | + | ||
| 6 | +@ApiModel("管理后台 - 满减送活动创建 Request VO") | ||
| 7 | +@Data | ||
| 8 | +@EqualsAndHashCode(callSuper = true) | ||
| 9 | +@ToString(callSuper = true) | ||
| 10 | +public class RewardActivityCreateReqVO extends RewardActivityBaseVO { | ||
| 11 | + | ||
| 12 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/vo/RewardActivityPageReqVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.reward.vo; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | +import io.swagger.annotations.*; | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 6 | + | ||
| 7 | +@ApiModel("管理后台 - 满减送活动分页 Request VO") | ||
| 8 | +@Data | ||
| 9 | +@EqualsAndHashCode(callSuper = true) | ||
| 10 | +@ToString(callSuper = true) | ||
| 11 | +public class RewardActivityPageReqVO extends PageParam { | ||
| 12 | + | ||
| 13 | + @ApiModelProperty(value = "活动标题", example = "满啦满啦") | ||
| 14 | + private String name; | ||
| 15 | + | ||
| 16 | + @ApiModelProperty(value = "活动状态", example = "1") | ||
| 17 | + private Integer status; | ||
| 18 | + | ||
| 19 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/vo/RewardActivityRespVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.reward.vo; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | +import java.util.*; | ||
| 5 | +import io.swagger.annotations.*; | ||
| 6 | + | ||
| 7 | +@ApiModel("管理后台 - 满减送活动 Response VO") | ||
| 8 | +@Data | ||
| 9 | +@EqualsAndHashCode(callSuper = true) | ||
| 10 | +@ToString(callSuper = true) | ||
| 11 | +public class RewardActivityRespVO extends RewardActivityBaseVO { | ||
| 12 | + | ||
| 13 | + @ApiModelProperty(value = "活动编号", required = true, example = "1024") | ||
| 14 | + private Integer id; | ||
| 15 | + | ||
| 16 | + @ApiModelProperty(value = "活动状态", required = true, example = "1") | ||
| 17 | + private Integer status; | ||
| 18 | + | ||
| 19 | + @ApiModelProperty(value = "创建时间", required = true) | ||
| 20 | + private Date createTime; | ||
| 21 | + | ||
| 22 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/vo/RewardActivityUpdateReqVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.reward.vo; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | +import io.swagger.annotations.*; | ||
| 5 | +import javax.validation.constraints.*; | ||
| 6 | + | ||
| 7 | +@ApiModel("管理后台 - 满减送活动更新 Request VO") | ||
| 8 | +@Data | ||
| 9 | +@EqualsAndHashCode(callSuper = true) | ||
| 10 | +@ToString(callSuper = true) | ||
| 11 | +public class RewardActivityUpdateReqVO extends RewardActivityBaseVO { | ||
| 12 | + | ||
| 13 | + @ApiModelProperty(value = "活动编号", required = true, example = "1024") | ||
| 14 | + @NotNull(message = "活动编号不能为空") | ||
| 15 | + private Integer id; | ||
| 16 | + | ||
| 17 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/reward/RewardActivityConvert.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.convert.reward; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityRespVO; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | ||
| 8 | +import org.mapstruct.Mapper; | ||
| 9 | +import org.mapstruct.factory.Mappers; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 满减送活动 Convert | ||
| 13 | + * | ||
| 14 | + * @author 芋道源码 | ||
| 15 | + */ | ||
| 16 | +@Mapper | ||
| 17 | +public interface RewardActivityConvert { | ||
| 18 | + | ||
| 19 | + RewardActivityConvert INSTANCE = Mappers.getMapper(RewardActivityConvert.class); | ||
| 20 | + | ||
| 21 | + RewardActivityDO convert(RewardActivityCreateReqVO bean); | ||
| 22 | + | ||
| 23 | + RewardActivityDO convert(RewardActivityUpdateReqVO bean); | ||
| 24 | + | ||
| 25 | + RewardActivityRespVO convert(RewardActivityDO bean); | ||
| 26 | + | ||
| 27 | + PageResult<RewardActivityRespVO> convertPage(PageResult<RewardActivityDO> page); | ||
| 28 | + | ||
| 29 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/reward/RewardActivityMapper.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.dal.mysql.reward; | ||
| 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.reward.vo.RewardActivityPageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | ||
| 8 | +import org.apache.ibatis.annotations.Mapper; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 满减送活动 Mapper | ||
| 12 | + * | ||
| 13 | + * @author 芋道源码 | ||
| 14 | + */ | ||
| 15 | +@Mapper | ||
| 16 | +public interface RewardActivityMapper extends BaseMapperX<RewardActivityDO> { | ||
| 17 | + | ||
| 18 | + default PageResult<RewardActivityDO> selectPage(RewardActivityPageReqVO reqVO) { | ||
| 19 | + return selectPage(reqVO, new LambdaQueryWrapperX<RewardActivityDO>() | ||
| 20 | + .likeIfPresent(RewardActivityDO::getName, reqVO.getName()) | ||
| 21 | + .eqIfPresent(RewardActivityDO::getStatus, reqVO.getStatus()) | ||
| 22 | + .orderByDesc(RewardActivityDO::getId)); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/price/PriceServiceImpl.java
| @@ -13,9 +13,9 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | @@ -13,9 +13,9 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | ||
| 13 | import cn.iocoder.yudao.module.promotion.enums.common.*; | 13 | import cn.iocoder.yudao.module.promotion.enums.common.*; |
| 14 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; | 14 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; |
| 15 | import cn.iocoder.yudao.module.promotion.service.discount.DiscountService; | 15 | import cn.iocoder.yudao.module.promotion.service.discount.DiscountService; |
| 16 | -import cn.iocoder.yudao.module.promotion.service.reward.RewardService; | ||
| 17 | import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; | 16 | import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; |
| 18 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; | 17 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; |
| 18 | +import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityService; | ||
| 19 | import com.google.common.base.Suppliers; | 19 | import com.google.common.base.Suppliers; |
| 20 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 21 | import org.springframework.validation.annotation.Validated; | 21 | import org.springframework.validation.annotation.Validated; |
| @@ -56,7 +56,7 @@ public class PriceServiceImpl implements PriceService { | @@ -56,7 +56,7 @@ public class PriceServiceImpl implements PriceService { | ||
| 56 | @Resource | 56 | @Resource |
| 57 | private DiscountService discountService; | 57 | private DiscountService discountService; |
| 58 | @Resource | 58 | @Resource |
| 59 | - private RewardService rewardService; | 59 | + private RewardActivityService rewardActivityService; |
| 60 | @Resource | 60 | @Resource |
| 61 | private CouponService couponService; | 61 | private CouponService couponService; |
| 62 | 62 | ||
| @@ -188,7 +188,7 @@ public class PriceServiceImpl implements PriceService { | @@ -188,7 +188,7 @@ public class PriceServiceImpl implements PriceService { | ||
| 188 | private void calculatePriceForOrderLevel(Long userId, PriceCalculateRespDTO priceCalculate) { | 188 | private void calculatePriceForOrderLevel(Long userId, PriceCalculateRespDTO priceCalculate) { |
| 189 | // 获取 SKU 级别的所有优惠信息 | 189 | // 获取 SKU 级别的所有优惠信息 |
| 190 | Set<Long> spuIds = convertSet(priceCalculate.getOrder().getItems(), PriceCalculateRespDTO.OrderItem::getSpuId); | 190 | Set<Long> spuIds = convertSet(priceCalculate.getOrder().getItems(), PriceCalculateRespDTO.OrderItem::getSpuId); |
| 191 | - Map<RewardActivityDO, Set<Long>> rewardActivities = rewardService.getMatchRewardActivities(spuIds); | 191 | + Map<RewardActivityDO, Set<Long>> rewardActivities = rewardActivityService.getMatchRewardActivities(spuIds); |
| 192 | 192 | ||
| 193 | // 处理满减送活动 | 193 | // 处理满减送活动 |
| 194 | if (CollUtil.isNotEmpty(rewardActivities)) { | 194 | if (CollUtil.isNotEmpty(rewardActivities)) { |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.service.reward; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | ||
| 8 | + | ||
| 9 | +import javax.validation.Valid; | ||
| 10 | +import java.util.Collection; | ||
| 11 | +import java.util.List; | ||
| 12 | +import java.util.Map; | ||
| 13 | +import java.util.Set; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * 满减送活动 Service 接口 | ||
| 17 | + * | ||
| 18 | + * @author 芋道源码 | ||
| 19 | + */ | ||
| 20 | +public interface RewardActivityService { | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 创建满减送活动 | ||
| 24 | + * | ||
| 25 | + * @param createReqVO 创建信息 | ||
| 26 | + * @return 编号 | ||
| 27 | + */ | ||
| 28 | + Long createRewardActivity(@Valid RewardActivityCreateReqVO createReqVO); | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 更新满减送活动 | ||
| 32 | + * | ||
| 33 | + * @param updateReqVO 更新信息 | ||
| 34 | + */ | ||
| 35 | + void updateRewardActivity(@Valid RewardActivityUpdateReqVO updateReqVO); | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 删除满减送活动 | ||
| 39 | + * | ||
| 40 | + * @param id 编号 | ||
| 41 | + */ | ||
| 42 | + void deleteRewardActivity(Integer id); | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 获得满减送活动 | ||
| 46 | + * | ||
| 47 | + * @param id 编号 | ||
| 48 | + * @return 满减送活动 | ||
| 49 | + */ | ||
| 50 | + RewardActivityDO getRewardActivity(Integer id); | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 获得满减送活动列表 | ||
| 54 | + * | ||
| 55 | + * @param ids 编号 | ||
| 56 | + * @return 满减送活动列表 | ||
| 57 | + */ | ||
| 58 | + List<RewardActivityDO> getRewardActivityList(Collection<Integer> ids); | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 获得满减送活动分页 | ||
| 62 | + * | ||
| 63 | + * @param pageReqVO 分页查询 | ||
| 64 | + * @return 满减送活动分页 | ||
| 65 | + */ | ||
| 66 | + PageResult<RewardActivityDO> getRewardActivityPage(RewardActivityPageReqVO pageReqVO); | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 基于指定的 SPU 编号数组,获得它们匹配的满减送活动 | ||
| 70 | + * | ||
| 71 | + * @param spuIds SPU 编号数组 | ||
| 72 | + * @return 满减送活动,与对应的 SPU 编号的映射。即,value 就是 SPU 编号的集合 | ||
| 73 | + */ | ||
| 74 | + Map<RewardActivityDO, Set<Long>> getMatchRewardActivities(Set<Long> spuIds); | ||
| 75 | + | ||
| 76 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.service.reward; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityCreateReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityPageReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivityUpdateReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.convert.reward.RewardActivityConvert; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | ||
| 9 | +import cn.iocoder.yudao.module.promotion.dal.mysql.reward.RewardActivityMapper; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | +import java.util.Collection; | ||
| 15 | +import java.util.List; | ||
| 16 | +import java.util.Map; | ||
| 17 | +import java.util.Set; | ||
| 18 | + | ||
| 19 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 20 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.REWARD_ACTIVITY_NOT_EXISTS; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * 满减送活动 Service 实现类 | ||
| 24 | + * | ||
| 25 | + * @author 芋道源码 | ||
| 26 | + */ | ||
| 27 | +@Service | ||
| 28 | +@Validated | ||
| 29 | +public class RewardActivityServiceImpl implements RewardActivityService { | ||
| 30 | + | ||
| 31 | + @Resource | ||
| 32 | + private RewardActivityMapper rewardActivityMapper; | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public Long createRewardActivity(RewardActivityCreateReqVO createReqVO) { | ||
| 36 | + // 插入 | ||
| 37 | + RewardActivityDO rewardActivity = RewardActivityConvert.INSTANCE.convert(createReqVO); | ||
| 38 | + rewardActivityMapper.insert(rewardActivity); | ||
| 39 | + // 返回 | ||
| 40 | + return rewardActivity.getId(); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Override | ||
| 44 | + public void updateRewardActivity(RewardActivityUpdateReqVO updateReqVO) { | ||
| 45 | + // 校验存在 | ||
| 46 | + this.validateRewardActivityExists(updateReqVO.getId()); | ||
| 47 | + // 更新 | ||
| 48 | + RewardActivityDO updateObj = RewardActivityConvert.INSTANCE.convert(updateReqVO); | ||
| 49 | + rewardActivityMapper.updateById(updateObj); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public void deleteRewardActivity(Integer id) { | ||
| 54 | + // 校验存在 | ||
| 55 | + this.validateRewardActivityExists(id); | ||
| 56 | + // 删除 | ||
| 57 | + rewardActivityMapper.deleteById(id); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + private void validateRewardActivityExists(Integer id) { | ||
| 61 | + if (rewardActivityMapper.selectById(id) == null) { | ||
| 62 | + throw exception(REWARD_ACTIVITY_NOT_EXISTS); | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public RewardActivityDO getRewardActivity(Integer id) { | ||
| 68 | + return rewardActivityMapper.selectById(id); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public List<RewardActivityDO> getRewardActivityList(Collection<Integer> ids) { | ||
| 73 | + return rewardActivityMapper.selectBatchIds(ids); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public PageResult<RewardActivityDO> getRewardActivityPage(RewardActivityPageReqVO pageReqVO) { | ||
| 78 | + return rewardActivityMapper.selectPage(pageReqVO); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @Override | ||
| 82 | + public Map<RewardActivityDO, Set<Long>> getMatchRewardActivities(Set<Long> spuIds) { | ||
| 83 | + // TODO 芋艿:待实现 | ||
| 84 | + return null; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardService.java deleted
| 1 | -package cn.iocoder.yudao.module.promotion.service.reward; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | ||
| 4 | - | ||
| 5 | -import java.util.Map; | ||
| 6 | -import java.util.Set; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * 满减送 Service 接口 | ||
| 10 | - * | ||
| 11 | - * @author 芋道源码 | ||
| 12 | - */ | ||
| 13 | -public interface RewardService { | ||
| 14 | - | ||
| 15 | - /** | ||
| 16 | - * 基于指定的 SPU 编号数组,获得它们匹配的满减送活动 | ||
| 17 | - * | ||
| 18 | - * @param spuIds SPU 编号数组 | ||
| 19 | - * @return 满减送活动,与对应的 SPU 编号的映射。即,value 就是 SPU 编号的集合 | ||
| 20 | - */ | ||
| 21 | - Map<RewardActivityDO, Set<Long>> getMatchRewardActivities(Set<Long> spuIds); | ||
| 22 | - | ||
| 23 | -} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardServiceImpl.java deleted
| 1 | -package cn.iocoder.yudao.module.promotion.service.reward; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | ||
| 4 | -import org.springframework.stereotype.Service; | ||
| 5 | -import org.springframework.validation.annotation.Validated; | ||
| 6 | - | ||
| 7 | -import java.util.Collections; | ||
| 8 | -import java.util.Map; | ||
| 9 | -import java.util.Set; | ||
| 10 | - | ||
| 11 | -/** | ||
| 12 | - * 满减送 Service 实现类 | ||
| 13 | - * | ||
| 14 | - * @author 芋道源码 | ||
| 15 | - */ | ||
| 16 | -@Service | ||
| 17 | -@Validated | ||
| 18 | -public class RewardServiceImpl implements RewardService { | ||
| 19 | - | ||
| 20 | - // TODO 芋艿:待实现 | ||
| 21 | - @Override | ||
| 22 | - public Map<RewardActivityDO, Set<Long>> getMatchRewardActivities(Set<Long> spuIds) { | ||
| 23 | - return Collections.emptyMap(); | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | -} |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/price/PriceServiceTest.java
| @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.promotion.service.price; | @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.promotion.service.price; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.map.MapUtil; | 3 | import cn.hutool.core.map.MapUtil; |
| 4 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | 4 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; |
| 5 | +import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; | ||
| 6 | +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; | ||
| 5 | import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO; | 7 | import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO; |
| 6 | import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO; | 8 | import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO; |
| 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| @@ -10,9 +12,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | @@ -10,9 +12,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; | ||
| 10 | import cn.iocoder.yudao.module.promotion.enums.common.*; | 12 | import cn.iocoder.yudao.module.promotion.enums.common.*; |
| 11 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; | 13 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; |
| 12 | import cn.iocoder.yudao.module.promotion.service.discount.DiscountService; | 14 | import cn.iocoder.yudao.module.promotion.service.discount.DiscountService; |
| 13 | -import cn.iocoder.yudao.module.promotion.service.reward.RewardService; | ||
| 14 | -import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; | ||
| 15 | -import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; | 15 | +import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityService; |
| 16 | import org.junit.jupiter.api.Test; | 16 | import org.junit.jupiter.api.Test; |
| 17 | import org.mockito.InjectMocks; | 17 | import org.mockito.InjectMocks; |
| 18 | import org.mockito.Mock; | 18 | import org.mockito.Mock; |
| @@ -43,7 +43,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest { | @@ -43,7 +43,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest { | ||
| 43 | @Mock | 43 | @Mock |
| 44 | private DiscountService discountService; | 44 | private DiscountService discountService; |
| 45 | @Mock | 45 | @Mock |
| 46 | - private RewardService rewardService; | 46 | + private RewardActivityService rewardActivityService; |
| 47 | @Mock | 47 | @Mock |
| 48 | private CouponService couponService; | 48 | private CouponService couponService; |
| 49 | @Mock | 49 | @Mock |
| @@ -205,7 +205,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest { | @@ -205,7 +205,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest { | ||
| 205 | Map<RewardActivityDO, Set<Long>> matchRewardActivities = new LinkedHashMap<>(); | 205 | Map<RewardActivityDO, Set<Long>> matchRewardActivities = new LinkedHashMap<>(); |
| 206 | matchRewardActivities.put(rewardActivity01, asSet(1L, 2L)); | 206 | matchRewardActivities.put(rewardActivity01, asSet(1L, 2L)); |
| 207 | matchRewardActivities.put(rewardActivity02, asSet(3L)); | 207 | matchRewardActivities.put(rewardActivity02, asSet(3L)); |
| 208 | - when(rewardService.getMatchRewardActivities(eq(asSet(1L, 2L, 3L)))).thenReturn(matchRewardActivities); | 208 | + when(rewardActivityService.getMatchRewardActivities(eq(asSet(1L, 2L, 3L)))).thenReturn(matchRewardActivities); |
| 209 | 209 | ||
| 210 | // 调用 | 210 | // 调用 |
| 211 | PriceCalculateRespDTO priceCalculate = priceService.calculatePrice(calculateReqDTO); | 211 | PriceCalculateRespDTO priceCalculate = priceService.calculatePrice(calculateReqDTO); |
| @@ -302,7 +302,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest { | @@ -302,7 +302,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest { | ||
| 302 | .setRules(singletonList(new RewardActivityDO.Rule().setLimit(351).setDiscountPrice(70)))); | 302 | .setRules(singletonList(new RewardActivityDO.Rule().setLimit(351).setDiscountPrice(70)))); |
| 303 | Map<RewardActivityDO, Set<Long>> matchRewardActivities = new LinkedHashMap<>(); | 303 | Map<RewardActivityDO, Set<Long>> matchRewardActivities = new LinkedHashMap<>(); |
| 304 | matchRewardActivities.put(rewardActivity01, asSet(1L, 2L)); | 304 | matchRewardActivities.put(rewardActivity01, asSet(1L, 2L)); |
| 305 | - when(rewardService.getMatchRewardActivities(eq(asSet(1L, 2L)))).thenReturn(matchRewardActivities); | 305 | + when(rewardActivityService.getMatchRewardActivities(eq(asSet(1L, 2L)))).thenReturn(matchRewardActivities); |
| 306 | 306 | ||
| 307 | // 调用 | 307 | // 调用 |
| 308 | PriceCalculateRespDTO priceCalculate = priceService.calculatePrice(calculateReqDTO); | 308 | PriceCalculateRespDTO priceCalculate = priceService.calculatePrice(calculateReqDTO); |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/rewardactivity/RewardActivityServiceImplTest.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.service.rewardactivity; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityServiceImpl; | ||
| 4 | +import org.junit.jupiter.api.Disabled; | ||
| 5 | +import org.junit.jupiter.api.Test; | ||
| 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.reward.vo.*; | ||
| 12 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.rewardactivity.RewardActivityDO; | ||
| 13 | +import cn.iocoder.yudao.module.promotion.dal.mysql.reward.RewardActivityMapper; | ||
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 15 | + | ||
| 16 | +import org.springframework.context.annotation.Import; | ||
| 17 | +import java.util.*; | ||
| 18 | + | ||
| 19 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | ||
| 20 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | ||
| 21 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | ||
| 22 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | ||
| 23 | +import static org.junit.jupiter.api.Assertions.*; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | +* {@link RewardActivityServiceImpl} 的单元测试类 | ||
| 27 | +* | ||
| 28 | +* @author 芋道源码 | ||
| 29 | +*/ | ||
| 30 | +@Import(RewardActivityServiceImpl.class) | ||
| 31 | +public class RewardActivityServiceImplTest extends BaseDbUnitTest { | ||
| 32 | + | ||
| 33 | + @Resource | ||
| 34 | + private RewardActivityServiceImpl rewardActivityService; | ||
| 35 | + | ||
| 36 | + @Resource | ||
| 37 | + private RewardActivityMapper rewardActivityMapper; | ||
| 38 | + | ||
| 39 | + @Test | ||
| 40 | + public void testCreateRewardActivity_success() { | ||
| 41 | + // 准备参数 | ||
| 42 | + RewardActivityCreateReqVO reqVO = randomPojo(RewardActivityCreateReqVO.class); | ||
| 43 | + | ||
| 44 | + // 调用 | ||
| 45 | + Integer rewardActivityId = rewardActivityService.createRewardActivity(reqVO); | ||
| 46 | + // 断言 | ||
| 47 | + assertNotNull(rewardActivityId); | ||
| 48 | + // 校验记录的属性是否正确 | ||
| 49 | + RewardActivityDO rewardActivity = rewardActivityMapper.selectById(rewardActivityId); | ||
| 50 | + assertPojoEquals(reqVO, rewardActivity); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Test | ||
| 54 | + public void testUpdateRewardActivity_success() { | ||
| 55 | + // mock 数据 | ||
| 56 | + RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class); | ||
| 57 | + rewardActivityMapper.insert(dbRewardActivity);// @Sql: 先插入出一条存在的数据 | ||
| 58 | + // 准备参数 | ||
| 59 | + RewardActivityUpdateReqVO reqVO = randomPojo(RewardActivityUpdateReqVO.class, o -> { | ||
| 60 | + o.setId(dbRewardActivity.getId()); // 设置更新的 ID | ||
| 61 | + }); | ||
| 62 | + | ||
| 63 | + // 调用 | ||
| 64 | + rewardActivityService.updateRewardActivity(reqVO); | ||
| 65 | + // 校验是否更新正确 | ||
| 66 | + RewardActivityDO rewardActivity = rewardActivityMapper.selectById(reqVO.getId()); // 获取最新的 | ||
| 67 | + assertPojoEquals(reqVO, rewardActivity); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Test | ||
| 71 | + public void testUpdateRewardActivity_notExists() { | ||
| 72 | + // 准备参数 | ||
| 73 | + RewardActivityUpdateReqVO reqVO = randomPojo(RewardActivityUpdateReqVO.class); | ||
| 74 | + | ||
| 75 | + // 调用, 并断言异常 | ||
| 76 | + assertServiceException(() -> rewardActivityService.updateRewardActivity(reqVO), REWARD_ACTIVITY_NOT_EXISTS); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Test | ||
| 80 | + public void testDeleteRewardActivity_success() { | ||
| 81 | + // mock 数据 | ||
| 82 | + RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class); | ||
| 83 | + rewardActivityMapper.insert(dbRewardActivity);// @Sql: 先插入出一条存在的数据 | ||
| 84 | + // 准备参数 | ||
| 85 | + Integer id = dbRewardActivity.getId(); | ||
| 86 | + | ||
| 87 | + // 调用 | ||
| 88 | + rewardActivityService.deleteRewardActivity(id); | ||
| 89 | + // 校验数据不存在了 | ||
| 90 | + assertNull(rewardActivityMapper.selectById(id)); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Test | ||
| 94 | + public void testDeleteRewardActivity_notExists() { | ||
| 95 | + // 准备参数 | ||
| 96 | + Integer id = randomIntegerId(); | ||
| 97 | + | ||
| 98 | + // 调用, 并断言异常 | ||
| 99 | + assertServiceException(() -> rewardActivityService.deleteRewardActivity(id), REWARD_ACTIVITY_NOT_EXISTS); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + @Test | ||
| 103 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | ||
| 104 | + public void testGetRewardActivityPage() { | ||
| 105 | + // mock 数据 | ||
| 106 | + RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class, o -> { // 等会查询到 | ||
| 107 | + o.setName(null); | ||
| 108 | + o.setStatus(null); | ||
| 109 | + }); | ||
| 110 | + rewardActivityMapper.insert(dbRewardActivity); | ||
| 111 | + // 测试 name 不匹配 | ||
| 112 | + rewardActivityMapper.insert(cloneIgnoreId(dbRewardActivity, o -> o.setName(null))); | ||
| 113 | + // 测试 status 不匹配 | ||
| 114 | + rewardActivityMapper.insert(cloneIgnoreId(dbRewardActivity, o -> o.setStatus(null))); | ||
| 115 | + // 准备参数 | ||
| 116 | + RewardActivityPageReqVO reqVO = new RewardActivityPageReqVO(); | ||
| 117 | + reqVO.setName(null); | ||
| 118 | + reqVO.setStatus(null); | ||
| 119 | + | ||
| 120 | + // 调用 | ||
| 121 | + PageResult<RewardActivityDO> pageResult = rewardActivityService.getRewardActivityPage(reqVO); | ||
| 122 | + // 断言 | ||
| 123 | + assertEquals(1, pageResult.getTotal()); | ||
| 124 | + assertEquals(1, pageResult.getList().size()); | ||
| 125 | + assertPojoEquals(dbRewardActivity, pageResult.getList().get(0)); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + @Test | ||
| 129 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | ||
| 130 | + public void testGetRewardActivityList() { | ||
| 131 | + // mock 数据 | ||
| 132 | + RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class, o -> { // 等会查询到 | ||
| 133 | + o.setName(null); | ||
| 134 | + o.setStatus(null); | ||
| 135 | + }); | ||
| 136 | + rewardActivityMapper.insert(dbRewardActivity); | ||
| 137 | + // 测试 name 不匹配 | ||
| 138 | + rewardActivityMapper.insert(cloneIgnoreId(dbRewardActivity, o -> o.setName(null))); | ||
| 139 | + // 测试 status 不匹配 | ||
| 140 | + rewardActivityMapper.insert(cloneIgnoreId(dbRewardActivity, o -> o.setStatus(null))); | ||
| 141 | + // 准备参数 | ||
| 142 | + RewardActivityExportReqVO reqVO = new RewardActivityExportReqVO(); | ||
| 143 | + reqVO.setName(null); | ||
| 144 | + reqVO.setStatus(null); | ||
| 145 | + | ||
| 146 | + // 调用 | ||
| 147 | + List<RewardActivityDO> list = rewardActivityService.getRewardActivityList(reqVO); | ||
| 148 | + // 断言 | ||
| 149 | + assertEquals(1, list.size()); | ||
| 150 | + assertPojoEquals(dbRewardActivity, list.get(0)); | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | +} |