Commit f9aec7d8fd27a75250256ecb6df19cbd9b6acfbc
1 parent
0a3a6825
优惠券:完善我的优惠券接口
Showing
7 changed files
with
36 additions
and
29 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/coupon/CouponPageReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon; |
| 2 | 2 | |
| 3 | 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.coupon.CouponStatusEnum; | |
| 4 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 7 | import lombok.Data; |
| 6 | 8 | import lombok.EqualsAndHashCode; |
| ... | ... | @@ -8,6 +10,7 @@ import lombok.ToString; |
| 8 | 10 | import org.springframework.format.annotation.DateTimeFormat; |
| 9 | 11 | |
| 10 | 12 | import java.time.LocalDateTime; |
| 13 | +import java.util.Collection; | |
| 11 | 14 | |
| 12 | 15 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 13 | 16 | |
| ... | ... | @@ -21,6 +24,7 @@ public class CouponPageReqVO extends PageParam { |
| 21 | 24 | private Long templateId; |
| 22 | 25 | |
| 23 | 26 | @Schema(description = "优惠码状态", example = "1") |
| 27 | + @InEnum(value = CouponStatusEnum.class, message = "优惠劵状态,必须是 {value}") | |
| 24 | 28 | private Integer status; |
| 25 | 29 | |
| 26 | 30 | @Schema(description = "创建时间") |
| ... | ... | @@ -30,4 +34,7 @@ public class CouponPageReqVO extends PageParam { |
| 30 | 34 | @Schema(description = "用户昵称", example = "芋艿") |
| 31 | 35 | private String nickname; |
| 32 | 36 | |
| 37 | + @Schema(description = "用户编号", example = "1") | |
| 38 | + private Collection<Long> userIds; | |
| 39 | + | |
| 33 | 40 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java
| ... | ... | @@ -8,6 +8,8 @@ import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCoup |
| 8 | 8 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponPageReqVO; |
| 9 | 9 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponRespVO; |
| 10 | 10 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplatePageReqVO; |
| 11 | +import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; | |
| 12 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | |
| 11 | 13 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; |
| 12 | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | 15 | import io.swagger.v3.oas.annotations.tags.Tag; |
| ... | ... | @@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.*; |
| 17 | 19 | import javax.annotation.Resource; |
| 18 | 20 | import java.time.LocalDateTime; |
| 19 | 21 | import java.util.ArrayList; |
| 22 | +import java.util.Collections; | |
| 20 | 23 | import java.util.List; |
| 21 | 24 | import java.util.Random; |
| 22 | 25 | |
| ... | ... | @@ -71,33 +74,12 @@ public class AppCouponController { |
| 71 | 74 | return success(list); |
| 72 | 75 | } |
| 73 | 76 | |
| 74 | - // TODO 芋艿:待实现 | |
| 75 | 77 | @GetMapping("/page") |
| 76 | 78 | @Operation(summary = "优惠劵列表", description = "我的优惠劵") |
| 77 | 79 | public CommonResult<PageResult<AppCouponRespVO>> takeCoupon(AppCouponPageReqVO pageReqVO) { |
| 78 | - List<AppCouponRespVO> list = new ArrayList<>(); | |
| 79 | - Random random = new Random(); | |
| 80 | - for (int i = 0; i < 10; i++) { | |
| 81 | - AppCouponRespVO vo = new AppCouponRespVO(); | |
| 82 | - vo.setId(i + 1L); | |
| 83 | - vo.setName("优惠劵" + (i + 1)); | |
| 84 | - vo.setStatus(pageReqVO.getStatus()); | |
| 85 | - vo.setUsePrice(random.nextInt(100) * 100); | |
| 86 | - vo.setValidStartTime(LocalDateTime.now().plusDays(random.nextInt(10))); | |
| 87 | - vo.setValidEndTime(LocalDateTime.now().plusDays(random.nextInt(20) + 10)); | |
| 88 | - vo.setDiscountType(random.nextInt(2) + 1); | |
| 89 | - if (vo.getDiscountType() == 1) { | |
| 90 | - vo.setDiscountPercent(null); | |
| 91 | - vo.setDiscountPrice(random.nextInt(50) * 100); | |
| 92 | - vo.setDiscountLimitPrice(null); | |
| 93 | - } else { | |
| 94 | - vo.setDiscountPercent(random.nextInt(90) + 10); | |
| 95 | - vo.setDiscountPrice(null); | |
| 96 | - vo.setDiscountLimitPrice(random.nextInt(200) * 100); | |
| 97 | - } | |
| 98 | - list.add(vo); | |
| 99 | - } | |
| 100 | - return success(new PageResult<>(list, 20L)); | |
| 80 | + PageResult<CouponDO> pageResult = couponService.getCouponPage( | |
| 81 | + CouponConvert.INSTANCE.convert(pageReqVO, Collections.singleton(getLoginUserId()))); | |
| 82 | + return success(CouponConvert.INSTANCE.convertAppPage(pageResult)); | |
| 101 | 83 | } |
| 102 | 84 | |
| 103 | 85 | @GetMapping(value = "/get-unused-count") | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponPageReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon; |
| 2 | 2 | |
| 3 | 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.coupon.CouponStatusEnum; | |
| 4 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 7 | import lombok.Data; |
| 6 | 8 | import lombok.EqualsAndHashCode; |
| ... | ... | @@ -13,6 +15,7 @@ import lombok.ToString; |
| 13 | 15 | public class AppCouponPageReqVO extends PageParam { |
| 14 | 16 | |
| 15 | 17 | @Schema(description = "优惠劵状态", example = "1") |
| 18 | + @InEnum(value = CouponStatusEnum.class, message = "优惠劵状态,必须是 {value}") | |
| 16 | 19 | private Integer status; |
| 17 | 20 | |
| 18 | 21 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponConvert.java
| ... | ... | @@ -3,6 +3,9 @@ package cn.iocoder.yudao.module.promotion.convert.coupon; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; |
| 5 | 5 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageItemRespVO; |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponRespVO; | |
| 6 | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 7 | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 8 | 11 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; |
| ... | ... | @@ -11,6 +14,7 @@ import org.mapstruct.Mapper; |
| 11 | 14 | import org.mapstruct.factory.Mappers; |
| 12 | 15 | |
| 13 | 16 | import java.time.LocalDateTime; |
| 17 | +import java.util.Collection; | |
| 14 | 18 | |
| 15 | 19 | /** |
| 16 | 20 | * 优惠劵 Convert |
| ... | ... | @@ -49,4 +53,8 @@ public interface CouponConvert { |
| 49 | 53 | } |
| 50 | 54 | return couponDO; |
| 51 | 55 | } |
| 56 | + | |
| 57 | + CouponPageReqVO convert(AppCouponPageReqVO pageReqVO, Collection<Long> userIds); | |
| 58 | + | |
| 59 | + PageResult<AppCouponRespVO> convertAppPage(PageResult<CouponDO> pageResult); | |
| 52 | 60 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponTemplateConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.convert.coupon; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.map.MapUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 5 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateCreateReqVO; |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; | |
| 5 | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateRespVO; |
| 6 | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateUpdateReqVO; |
| 9 | +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplatePageReqVO; | |
| 10 | +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplateRespVO; | |
| 7 | 11 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 8 | 12 | import org.mapstruct.Mapper; |
| 9 | 13 | import org.mapstruct.factory.Mappers; |
| 10 | 14 | |
| 15 | +import java.util.List; | |
| 16 | +import java.util.Map; | |
| 17 | + | |
| 11 | 18 | /** |
| 12 | 19 | * 优惠劵模板 Convert |
| 13 | 20 | * | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java
| ... | ... | @@ -22,11 +22,11 @@ import java.util.List; |
| 22 | 22 | @Mapper |
| 23 | 23 | public interface CouponMapper extends BaseMapperX<CouponDO> { |
| 24 | 24 | |
| 25 | - default PageResult<CouponDO> selectPage(CouponPageReqVO reqVO, Collection<Long> userIds) { | |
| 25 | + default PageResult<CouponDO> selectPage(CouponPageReqVO reqVO) { | |
| 26 | 26 | return selectPage(reqVO, new LambdaQueryWrapperX<CouponDO>() |
| 27 | 27 | .eqIfPresent(CouponDO::getTemplateId, reqVO.getTemplateId()) |
| 28 | 28 | .eqIfPresent(CouponDO::getStatus, reqVO.getStatus()) |
| 29 | - .inIfPresent(CouponDO::getUserId, userIds) | |
| 29 | + .inIfPresent(CouponDO::getUserId, reqVO.getUserIds()) | |
| 30 | 30 | .betweenIfPresent(CouponDO::getCreateTime, reqVO.getCreateTime()) |
| 31 | 31 | .orderByDesc(CouponDO::getId)); |
| 32 | 32 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java
| ... | ... | @@ -80,16 +80,16 @@ public class CouponServiceImpl implements CouponService { |
| 80 | 80 | @Override |
| 81 | 81 | public PageResult<CouponDO> getCouponPage(CouponPageReqVO pageReqVO) { |
| 82 | 82 | // 获得用户编号 |
| 83 | - Set<Long> userIds = null; | |
| 84 | 83 | if (StrUtil.isNotEmpty(pageReqVO.getNickname())) { |
| 85 | - userIds = CollectionUtils.convertSet(memberUserApi.getUserListByNickname(pageReqVO.getNickname()), | |
| 84 | + Set<Long> userIds = CollectionUtils.convertSet(memberUserApi.getUserListByNickname(pageReqVO.getNickname()), | |
| 86 | 85 | MemberUserRespDTO::getId); |
| 87 | 86 | if (CollUtil.isEmpty(userIds)) { |
| 88 | 87 | return PageResult.empty(); |
| 89 | 88 | } |
| 89 | + pageReqVO.setUserIds(userIds); | |
| 90 | 90 | } |
| 91 | 91 | // 分页查询 |
| 92 | - return couponMapper.selectPage(pageReqVO, userIds); | |
| 92 | + return couponMapper.selectPage(pageReqVO); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | @Override | ... | ... |