优惠券:完善我的优惠券接口

This commit is contained in:
owen 2023-09-26 21:08:11 +08:00
parent 0a3a6825d5
commit f9aec7d8fd
7 changed files with 36 additions and 29 deletions

View File

@ -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<Long> userIds;
}

View File

@ -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<PageResult<AppCouponRespVO>> takeCoupon(AppCouponPageReqVO pageReqVO) {
List<AppCouponRespVO> 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<CouponDO> pageResult = couponService.getCouponPage(
CouponConvert.INSTANCE.convert(pageReqVO, Collections.singleton(getLoginUserId())));
return success(CouponConvert.INSTANCE.convertAppPage(pageResult));
}
@GetMapping(value = "/get-unused-count")

View File

@ -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;
}

View File

@ -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<Long> userIds);
PageResult<AppCouponRespVO> convertAppPage(PageResult<CouponDO> pageResult);
}

View File

@ -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
*

View File

@ -22,11 +22,11 @@ import java.util.List;
@Mapper
public interface CouponMapper extends BaseMapperX<CouponDO> {
default PageResult<CouponDO> selectPage(CouponPageReqVO reqVO, Collection<Long> userIds) {
default PageResult<CouponDO> selectPage(CouponPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<CouponDO>()
.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));
}

View File

@ -80,16 +80,16 @@ public class CouponServiceImpl implements CouponService {
@Override
public PageResult<CouponDO> getCouponPage(CouponPageReqVO pageReqVO) {
// 获得用户编号
Set<Long> userIds = null;
if (StrUtil.isNotEmpty(pageReqVO.getNickname())) {
userIds = CollectionUtils.convertSet(memberUserApi.getUserListByNickname(pageReqVO.getNickname()),
Set<Long> 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