diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/coupon/CouponPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/coupon/CouponPageReqVO.java index 11d61a518..75aa2f74b 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/coupon/CouponPageReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/coupon/CouponPageReqVO.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -8,6 +10,7 @@ import lombok.ToString; import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; +import java.util.Collection; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -21,6 +24,7 @@ public class CouponPageReqVO extends PageParam { private Long templateId; @Schema(description = "优惠码状态", example = "1") + @InEnum(value = CouponStatusEnum.class, message = "优惠劵状态,必须是 {value}") private Integer status; @Schema(description = "创建时间") @@ -30,4 +34,7 @@ public class CouponPageReqVO extends PageParam { @Schema(description = "用户昵称", example = "芋艿") private String nickname; + @Schema(description = "用户编号", example = "1") + private Collection userIds; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java index 8a9b82bbb..625df7942 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java +++ b/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 import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponPageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponRespVO; import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplatePageReqVO; +import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Random; @@ -71,33 +74,12 @@ public class AppCouponController { return success(list); } - // TODO 芋艿:待实现 @GetMapping("/page") @Operation(summary = "优惠劵列表", description = "我的优惠劵") public CommonResult> takeCoupon(AppCouponPageReqVO pageReqVO) { - List list = new ArrayList<>(); - Random random = new Random(); - for (int i = 0; i < 10; i++) { - AppCouponRespVO vo = new AppCouponRespVO(); - vo.setId(i + 1L); - vo.setName("优惠劵" + (i + 1)); - vo.setStatus(pageReqVO.getStatus()); - vo.setUsePrice(random.nextInt(100) * 100); - vo.setValidStartTime(LocalDateTime.now().plusDays(random.nextInt(10))); - vo.setValidEndTime(LocalDateTime.now().plusDays(random.nextInt(20) + 10)); - vo.setDiscountType(random.nextInt(2) + 1); - if (vo.getDiscountType() == 1) { - vo.setDiscountPercent(null); - vo.setDiscountPrice(random.nextInt(50) * 100); - vo.setDiscountLimitPrice(null); - } else { - vo.setDiscountPercent(random.nextInt(90) + 10); - vo.setDiscountPrice(null); - vo.setDiscountLimitPrice(random.nextInt(200) * 100); - } - list.add(vo); - } - return success(new PageResult<>(list, 20L)); + PageResult pageResult = couponService.getCouponPage( + CouponConvert.INSTANCE.convert(pageReqVO, Collections.singleton(getLoginUserId()))); + return success(CouponConvert.INSTANCE.convertAppPage(pageResult)); } @GetMapping(value = "/get-unused-count") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponPageReqVO.java index 5bd057f37..0c423959b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponPageReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponPageReqVO.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -13,6 +15,7 @@ import lombok.ToString; public class AppCouponPageReqVO extends PageParam { @Schema(description = "优惠劵状态", example = "1") + @InEnum(value = CouponStatusEnum.class, message = "优惠劵状态,必须是 {value}") private Integer status; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponConvert.java index 364095a4d..d2359e7c7 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponConvert.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageItemRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; @@ -11,6 +14,7 @@ import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import java.time.LocalDateTime; +import java.util.Collection; /** * 优惠劵 Convert @@ -49,4 +53,8 @@ public interface CouponConvert { } return couponDO; } + + CouponPageReqVO convert(AppCouponPageReqVO pageReqVO, Collection userIds); + + PageResult convertAppPage(PageResult pageResult); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponTemplateConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponTemplateConvert.java index b6d3bed9b..1c5c9b31f 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponTemplateConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponTemplateConvert.java @@ -1,13 +1,20 @@ package cn.iocoder.yudao.module.promotion.convert.coupon; +import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplatePageReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplateRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; +import java.util.List; +import java.util.Map; + /** * 优惠劵模板 Convert * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java index f79f23c21..744989849 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java +++ b/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; @Mapper public interface CouponMapper extends BaseMapperX { - default PageResult selectPage(CouponPageReqVO reqVO, Collection userIds) { + default PageResult selectPage(CouponPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(CouponDO::getTemplateId, reqVO.getTemplateId()) .eqIfPresent(CouponDO::getStatus, reqVO.getStatus()) - .inIfPresent(CouponDO::getUserId, userIds) + .inIfPresent(CouponDO::getUserId, reqVO.getUserIds()) .betweenIfPresent(CouponDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(CouponDO::getId)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java index ab96fd14f..fcf515ec5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java +++ b/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 { @Override public PageResult getCouponPage(CouponPageReqVO pageReqVO) { // 获得用户编号 - Set userIds = null; if (StrUtil.isNotEmpty(pageReqVO.getNickname())) { - userIds = CollectionUtils.convertSet(memberUserApi.getUserListByNickname(pageReqVO.getNickname()), + Set userIds = CollectionUtils.convertSet(memberUserApi.getUserListByNickname(pageReqVO.getNickname()), MemberUserRespDTO::getId); if (CollUtil.isEmpty(userIds)) { return PageResult.empty(); } + pageReqVO.setUserIds(userIds); } // 分页查询 - return couponMapper.selectPage(pageReqVO, userIds); + return couponMapper.selectPage(pageReqVO); } @Override