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 | package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon; | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 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 | import io.swagger.v3.oas.annotations.media.Schema; | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import lombok.EqualsAndHashCode; | 8 | import lombok.EqualsAndHashCode; |
| @@ -8,6 +10,7 @@ import lombok.ToString; | @@ -8,6 +10,7 @@ import lombok.ToString; | ||
| 8 | import org.springframework.format.annotation.DateTimeFormat; | 10 | import org.springframework.format.annotation.DateTimeFormat; |
| 9 | 11 | ||
| 10 | import java.time.LocalDateTime; | 12 | import java.time.LocalDateTime; |
| 13 | +import java.util.Collection; | ||
| 11 | 14 | ||
| 12 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | 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,6 +24,7 @@ public class CouponPageReqVO extends PageParam { | ||
| 21 | private Long templateId; | 24 | private Long templateId; |
| 22 | 25 | ||
| 23 | @Schema(description = "优惠码状态", example = "1") | 26 | @Schema(description = "优惠码状态", example = "1") |
| 27 | + @InEnum(value = CouponStatusEnum.class, message = "优惠劵状态,必须是 {value}") | ||
| 24 | private Integer status; | 28 | private Integer status; |
| 25 | 29 | ||
| 26 | @Schema(description = "创建时间") | 30 | @Schema(description = "创建时间") |
| @@ -30,4 +34,7 @@ public class CouponPageReqVO extends PageParam { | @@ -30,4 +34,7 @@ public class CouponPageReqVO extends PageParam { | ||
| 30 | @Schema(description = "用户昵称", example = "芋艿") | 34 | @Schema(description = "用户昵称", example = "芋艿") |
| 31 | private String nickname; | 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,6 +8,8 @@ import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCoup | ||
| 8 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponPageReqVO; | 8 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponPageReqVO; |
| 9 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponRespVO; | 9 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponRespVO; |
| 10 | import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplatePageReqVO; | 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 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; | 13 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; |
| 12 | import io.swagger.v3.oas.annotations.Operation; | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | import io.swagger.v3.oas.annotations.tags.Tag; | 15 | import io.swagger.v3.oas.annotations.tags.Tag; |
| @@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.*; | @@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.*; | ||
| 17 | import javax.annotation.Resource; | 19 | import javax.annotation.Resource; |
| 18 | import java.time.LocalDateTime; | 20 | import java.time.LocalDateTime; |
| 19 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
| 22 | +import java.util.Collections; | ||
| 20 | import java.util.List; | 23 | import java.util.List; |
| 21 | import java.util.Random; | 24 | import java.util.Random; |
| 22 | 25 | ||
| @@ -71,33 +74,12 @@ public class AppCouponController { | @@ -71,33 +74,12 @@ public class AppCouponController { | ||
| 71 | return success(list); | 74 | return success(list); |
| 72 | } | 75 | } |
| 73 | 76 | ||
| 74 | - // TODO 芋艿:待实现 | ||
| 75 | @GetMapping("/page") | 77 | @GetMapping("/page") |
| 76 | @Operation(summary = "优惠劵列表", description = "我的优惠劵") | 78 | @Operation(summary = "优惠劵列表", description = "我的优惠劵") |
| 77 | public CommonResult<PageResult<AppCouponRespVO>> takeCoupon(AppCouponPageReqVO pageReqVO) { | 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 | @GetMapping(value = "/get-unused-count") | 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 | package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon; | 1 | package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 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 | import io.swagger.v3.oas.annotations.media.Schema; | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import lombok.EqualsAndHashCode; | 8 | import lombok.EqualsAndHashCode; |
| @@ -13,6 +15,7 @@ import lombok.ToString; | @@ -13,6 +15,7 @@ import lombok.ToString; | ||
| 13 | public class AppCouponPageReqVO extends PageParam { | 15 | public class AppCouponPageReqVO extends PageParam { |
| 14 | 16 | ||
| 15 | @Schema(description = "优惠劵状态", example = "1") | 17 | @Schema(description = "优惠劵状态", example = "1") |
| 18 | + @InEnum(value = CouponStatusEnum.class, message = "优惠劵状态,必须是 {value}") | ||
| 16 | private Integer status; | 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,6 +3,9 @@ package cn.iocoder.yudao.module.promotion.convert.coupon; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; | 4 | import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; |
| 5 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageItemRespVO; | 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 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 8 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; | 11 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; |
| @@ -11,6 +14,7 @@ import org.mapstruct.Mapper; | @@ -11,6 +14,7 @@ import org.mapstruct.Mapper; | ||
| 11 | import org.mapstruct.factory.Mappers; | 14 | import org.mapstruct.factory.Mappers; |
| 12 | 15 | ||
| 13 | import java.time.LocalDateTime; | 16 | import java.time.LocalDateTime; |
| 17 | +import java.util.Collection; | ||
| 14 | 18 | ||
| 15 | /** | 19 | /** |
| 16 | * 优惠劵 Convert | 20 | * 优惠劵 Convert |
| @@ -49,4 +53,8 @@ public interface CouponConvert { | @@ -49,4 +53,8 @@ public interface CouponConvert { | ||
| 49 | } | 53 | } |
| 50 | return couponDO; | 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 | package cn.iocoder.yudao.module.promotion.convert.coupon; | 1 | package cn.iocoder.yudao.module.promotion.convert.coupon; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.map.MapUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateCreateReqVO; | 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 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateRespVO; | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateRespVO; |
| 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateUpdateReqVO; | 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 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | 11 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 8 | import org.mapstruct.Mapper; | 12 | import org.mapstruct.Mapper; |
| 9 | import org.mapstruct.factory.Mappers; | 13 | import org.mapstruct.factory.Mappers; |
| 10 | 14 | ||
| 15 | +import java.util.List; | ||
| 16 | +import java.util.Map; | ||
| 17 | + | ||
| 11 | /** | 18 | /** |
| 12 | * 优惠劵模板 Convert | 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,11 +22,11 @@ import java.util.List; | ||
| 22 | @Mapper | 22 | @Mapper |
| 23 | public interface CouponMapper extends BaseMapperX<CouponDO> { | 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 | return selectPage(reqVO, new LambdaQueryWrapperX<CouponDO>() | 26 | return selectPage(reqVO, new LambdaQueryWrapperX<CouponDO>() |
| 27 | .eqIfPresent(CouponDO::getTemplateId, reqVO.getTemplateId()) | 27 | .eqIfPresent(CouponDO::getTemplateId, reqVO.getTemplateId()) |
| 28 | .eqIfPresent(CouponDO::getStatus, reqVO.getStatus()) | 28 | .eqIfPresent(CouponDO::getStatus, reqVO.getStatus()) |
| 29 | - .inIfPresent(CouponDO::getUserId, userIds) | 29 | + .inIfPresent(CouponDO::getUserId, reqVO.getUserIds()) |
| 30 | .betweenIfPresent(CouponDO::getCreateTime, reqVO.getCreateTime()) | 30 | .betweenIfPresent(CouponDO::getCreateTime, reqVO.getCreateTime()) |
| 31 | .orderByDesc(CouponDO::getId)); | 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,16 +80,16 @@ public class CouponServiceImpl implements CouponService { | ||
| 80 | @Override | 80 | @Override |
| 81 | public PageResult<CouponDO> getCouponPage(CouponPageReqVO pageReqVO) { | 81 | public PageResult<CouponDO> getCouponPage(CouponPageReqVO pageReqVO) { |
| 82 | // 获得用户编号 | 82 | // 获得用户编号 |
| 83 | - Set<Long> userIds = null; | ||
| 84 | if (StrUtil.isNotEmpty(pageReqVO.getNickname())) { | 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 | MemberUserRespDTO::getId); | 85 | MemberUserRespDTO::getId); |
| 87 | if (CollUtil.isEmpty(userIds)) { | 86 | if (CollUtil.isEmpty(userIds)) { |
| 88 | return PageResult.empty(); | 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 | @Override | 95 | @Override |