Commit a89d5a83db4d0c7a01d881c5f9256c591cd3488c
1 parent
2c39405b
promotion:增加优惠劵的后端分页接口
Showing
20 changed files
with
433 additions
and
102 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
| ... | ... | @@ -23,4 +23,7 @@ public interface ErrorCodeConstants { |
| 23 | 23 | ErrorCode COUPON_TEMPLATE_NOT_EXISTS = new ErrorCode(1003004000, "优惠劵模板不存在"); |
| 24 | 24 | ErrorCode COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL = new ErrorCode(1003004001, "发放数量不能小于已领取数量({})"); |
| 25 | 25 | |
| 26 | + // ========== 优惠劵模板 1003005000 ========== | |
| 27 | + ErrorCode COUPON_NOT_EXISTS = new ErrorCode(1003005000, "优惠劵不存在"); | |
| 28 | + | |
| 26 | 29 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/pom.xml
| ... | ... | @@ -29,6 +29,11 @@ |
| 29 | 29 | <artifactId>yudao-module-product-api</artifactId> |
| 30 | 30 | <version>${revision}</version> |
| 31 | 31 | </dependency> |
| 32 | + <dependency> | |
| 33 | + <groupId>cn.iocoder.boot</groupId> | |
| 34 | + <artifactId>yudao-module-member-api</artifactId> | |
| 35 | + <version>${revision}</version> | |
| 36 | + </dependency> | |
| 32 | 37 | |
| 33 | 38 | <!-- 业务组件 --> |
| 34 | 39 | <dependency> | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/CouponController.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 7 | +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | |
| 8 | +import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; | |
| 9 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponPageItemRespVO; | |
| 10 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponPageReqVO; | |
| 11 | +import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; | |
| 12 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | |
| 13 | +import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; | |
| 14 | +import io.swagger.annotations.Api; | |
| 15 | +import io.swagger.annotations.ApiOperation; | |
| 16 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 17 | +import org.springframework.validation.annotation.Validated; | |
| 18 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 19 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 20 | +import org.springframework.web.bind.annotation.RestController; | |
| 21 | + | |
| 22 | +import javax.annotation.Resource; | |
| 23 | +import javax.validation.Valid; | |
| 24 | +import java.util.Map; | |
| 25 | +import java.util.Set; | |
| 26 | + | |
| 27 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 28 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 29 | + | |
| 30 | +@Api(tags = "管理后台 - 优惠劵") | |
| 31 | +@RestController | |
| 32 | +@RequestMapping("/promotion/coupon") | |
| 33 | +@Validated | |
| 34 | +public class CouponController { | |
| 35 | + | |
| 36 | + @Resource | |
| 37 | + private CouponService couponService; | |
| 38 | + @Resource | |
| 39 | + private MemberUserApi memberUserApi; | |
| 40 | + | |
| 41 | +// @GetMapping("/get") | |
| 42 | +// @ApiOperation("获得优惠劵") | |
| 43 | +// @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | |
| 44 | +// @PreAuthorize("@ss.hasPermission('promotion:coupon:query')") | |
| 45 | +// public CommonResult<CouponRespVO> getCoupon(@RequestParam("id") Long id) { | |
| 46 | +// CouponDO coupon = couponService.getCoupon(id); | |
| 47 | +// return success(CouponConvert.INSTANCE.convert(coupon)); | |
| 48 | +// } | |
| 49 | + | |
| 50 | + @GetMapping("/page") | |
| 51 | + @ApiOperation("获得优惠劵分页") | |
| 52 | + @PreAuthorize("@ss.hasPermission('promotion:coupon:query')") | |
| 53 | + public CommonResult<PageResult<CouponPageItemRespVO>> getCouponPage(@Valid CouponPageReqVO pageVO) { | |
| 54 | + PageResult<CouponDO> pageResult = couponService.getCouponPage(pageVO); | |
| 55 | + PageResult<CouponPageItemRespVO> pageResulVO = CouponConvert.INSTANCE.convertPage(pageResult); | |
| 56 | + if (CollUtil.isEmpty(pageResulVO.getList())) { | |
| 57 | + return success(pageResulVO); | |
| 58 | + } | |
| 59 | + // 读取用户信息,进行拼接 | |
| 60 | + Set<Long> userIds = convertSet(pageResult.getList(), CouponDO::getUserId); | |
| 61 | + Map<Long, UserRespDTO> userMap = memberUserApi.getUserMap(userIds); | |
| 62 | + pageResulVO.getList().forEach(itemRespVO -> MapUtils.findAndThen(userMap, itemRespVO.getUserId(), | |
| 63 | + userRespDTO -> itemRespVO.setNickname(userRespDTO.getNickname()))); | |
| 64 | + return success(pageResulVO); | |
| 65 | + } | |
| 66 | + | |
| 67 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponBaseVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 4 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; | |
| 5 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; | |
| 6 | +import com.fasterxml.jackson.annotation.JsonFormat; | |
| 7 | +import io.swagger.annotations.ApiModelProperty; | |
| 8 | +import lombok.Data; | |
| 9 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.Min; | |
| 12 | +import javax.validation.constraints.NotNull; | |
| 13 | +import java.util.Date; | |
| 14 | +import java.util.List; | |
| 15 | + | |
| 16 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 17 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT; | |
| 18 | + | |
| 19 | +/** | |
| 20 | +* 优惠劵 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 21 | +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 22 | +*/ | |
| 23 | +@Data | |
| 24 | +public class CouponBaseVO { | |
| 25 | + | |
| 26 | + // ========== 基本信息 BEGIN ========== | |
| 27 | + @ApiModelProperty(value = "优惠劵模板编号", required = true, example = "1024") | |
| 28 | + @NotNull(message = "优惠劵模板编号不能为空") | |
| 29 | + private Integer templateId; | |
| 30 | + | |
| 31 | + @ApiModelProperty(value = "优惠劵名", required = true, example = "春节送送送") | |
| 32 | + @NotNull(message = "优惠劵名不能为空") | |
| 33 | + private String name; | |
| 34 | + | |
| 35 | + @ApiModelProperty(value = "优惠码状态", required = true, example = "1", notes = "参见 CouponStatusEnum 枚举") | |
| 36 | + private Integer status; | |
| 37 | + | |
| 38 | + // ========== 基本信息 END ========== | |
| 39 | + | |
| 40 | + // ========== 领取情况 BEGIN ========== | |
| 41 | + @ApiModelProperty(value = "用户编号", required = true, example = "1") | |
| 42 | + @NotNull(message = "用户编号不能为空") | |
| 43 | + private Long userId; | |
| 44 | + | |
| 45 | + @ApiModelProperty(value = "领取方式", required = true, example = "1", notes = "参见 CouponTakeTypeEnum 枚举类") | |
| 46 | + @NotNull(message = "领取方式不能为空") | |
| 47 | + private Integer takeType; | |
| 48 | + // ========== 领取情况 END ========== | |
| 49 | + | |
| 50 | + // ========== 使用规则 BEGIN ========== | |
| 51 | + @ApiModelProperty(value = "是否设置满多少金额可用", required = true, example = "100", notes = "单位:分;0 - 不限制") | |
| 52 | + @NotNull(message = "是否设置满多少金额可用不能为空") | |
| 53 | + private Integer usePrice; | |
| 54 | + | |
| 55 | + @ApiModelProperty(value = "固定日期 - 生效开始时间") | |
| 56 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 57 | + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) | |
| 58 | + private Date validStartTime; | |
| 59 | + | |
| 60 | + @ApiModelProperty(value = "固定日期 - 生效结束时间") | |
| 61 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 62 | + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) | |
| 63 | + private Date validEndTime; | |
| 64 | + | |
| 65 | + @ApiModelProperty(value = "商品范围", required = true, example = "1", notes = "参见 PromotionProductScopeEnum 枚举类") | |
| 66 | + @NotNull(message = "商品范围不能为空") | |
| 67 | + @InEnum(PromotionProductScopeEnum.class) | |
| 68 | + private Integer productScope; | |
| 69 | + | |
| 70 | + @ApiModelProperty(value = "商品 SPU 编号的数组", example = "1,3") | |
| 71 | + private List<Long> productSpuIds; | |
| 72 | + // ========== 使用规则 END ========== | |
| 73 | + | |
| 74 | + // ========== 使用效果 BEGIN ========== | |
| 75 | + @ApiModelProperty(value = "优惠类型", required = true, example = "1", notes = "参见 PromotionDiscountTypeEnum 枚举") | |
| 76 | + @NotNull(message = "优惠类型不能为空") | |
| 77 | + @InEnum(PromotionDiscountTypeEnum.class) | |
| 78 | + private Integer discountType; | |
| 79 | + | |
| 80 | + @ApiModelProperty(value = "折扣百分比", example = "80", notes = "例如说,80% 为 80") | |
| 81 | + private Integer discountPercent; | |
| 82 | + | |
| 83 | + @ApiModelProperty(value = "优惠金额", example = "10", notes = "单位:分") | |
| 84 | + @Min(value = 0, message = "优惠金额需要大于等于 0") | |
| 85 | + private Integer discountPrice; | |
| 86 | + | |
| 87 | + @ApiModelProperty(value = "折扣上限", example = "100", notes = "单位:分,仅在 discountType 为 PERCENT 使用") | |
| 88 | + private Integer discountLimitPrice; | |
| 89 | + // ========== 使用效果 END ========== | |
| 90 | + | |
| 91 | + // ========== 使用情况 BEGIN ========== | |
| 92 | + | |
| 93 | + @ApiModelProperty(value = "使用订单号", example = "4096") | |
| 94 | + private Long useOrderId; | |
| 95 | + | |
| 96 | + @ApiModelProperty(value = "使用时间") | |
| 97 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 98 | + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) | |
| 99 | + private Date useTime; | |
| 100 | + | |
| 101 | + // ========== 使用情况 END ========== | |
| 102 | + | |
| 103 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponPageItemRespVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +@ApiModel("管理后台 - 优惠劵分页的每一项 Response VO") | |
| 10 | +@Data | |
| 11 | +@EqualsAndHashCode(callSuper = true) | |
| 12 | +@ToString(callSuper = true) | |
| 13 | +public class CouponPageItemRespVO extends CouponRespVO { | |
| 14 | + | |
| 15 | + @ApiModelProperty(value = "用户昵称", example = "老芋艿") | |
| 16 | + private String nickname; | |
| 17 | + | |
| 18 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponPageReqVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.annotations.ApiModel; | |
| 5 | +import io.swagger.annotations.ApiModelProperty; | |
| 6 | +import lombok.Data; | |
| 7 | +import lombok.EqualsAndHashCode; | |
| 8 | +import lombok.ToString; | |
| 9 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 10 | + | |
| 11 | +import java.util.Date; | |
| 12 | + | |
| 13 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 14 | + | |
| 15 | +@ApiModel("管理后台 - 优惠劵分页 Request VO") | |
| 16 | +@Data | |
| 17 | +@EqualsAndHashCode(callSuper = true) | |
| 18 | +@ToString(callSuper = true) | |
| 19 | +public class CouponPageReqVO extends PageParam { | |
| 20 | + | |
| 21 | + @ApiModelProperty(value = "优惠劵模板编号", example = "2048") | |
| 22 | + private Long templateId; | |
| 23 | + | |
| 24 | + @ApiModelProperty(value = "创建时间") | |
| 25 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 26 | + private Date[] createTime; | |
| 27 | + | |
| 28 | + @ApiModelProperty(value = "用户昵称", example = "芋艿", notes = "模糊匹配") | |
| 29 | + private String nickname; | |
| 30 | + | |
| 31 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/vo/CouponRespVO.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +import java.util.Date; | |
| 10 | + | |
| 11 | +@ApiModel("管理后台 - 优惠劵 Response VO") | |
| 12 | +@Data | |
| 13 | +@EqualsAndHashCode(callSuper = true) | |
| 14 | +@ToString(callSuper = true) | |
| 15 | +public class CouponRespVO extends CouponBaseVO { | |
| 16 | + | |
| 17 | + @ApiModelProperty(value = "优惠劵编号", required = true, example = "1024") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @ApiModelProperty(value = "创建时间", required = true) | |
| 21 | + private Date createTime; | |
| 22 | + | |
| 23 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponConvert.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.convert.coupon; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponPageItemRespVO; | |
| 5 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | |
| 6 | +import org.mapstruct.Mapper; | |
| 7 | +import org.mapstruct.factory.Mappers; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 优惠劵 Convert | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@Mapper | |
| 15 | +public interface CouponConvert { | |
| 16 | + | |
| 17 | + CouponConvert INSTANCE = Mappers.getMapper(CouponConvert.class); | |
| 18 | + | |
| 19 | + PageResult<CouponPageItemRespVO> convertPage(PageResult<CouponDO> page); | |
| 20 | + | |
| 21 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java
0 → 100755
| 1 | +package cn.iocoder.yudao.module.promotion.dal.mysql.coupon; | |
| 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.coupon.vo.CouponPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | |
| 8 | +import org.apache.ibatis.annotations.Mapper; | |
| 9 | + | |
| 10 | +import java.util.Collection; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 优惠劵 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface CouponMapper extends BaseMapperX<CouponDO> { | |
| 19 | + | |
| 20 | + default PageResult<CouponDO> selectPage(CouponPageReqVO reqVO, Collection<Long> userIds) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<CouponDO>() | |
| 22 | + .eqIfPresent(CouponDO::getTemplateId, reqVO.getTemplateId()) | |
| 23 | + .inIfPresent(CouponDO::getUserId, userIds) | |
| 24 | + .betweenIfPresent(CouponDO::getCreateTime, reqVO.getCreateTime()) | |
| 25 | + .orderByDesc(CouponDO::getId)); | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.service.coupon; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponPageReqVO; | |
| 3 | 5 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 4 | 6 | |
| 5 | 7 | /** |
| ... | ... | @@ -21,4 +23,12 @@ public interface CouponService { |
| 21 | 23 | */ |
| 22 | 24 | CouponDO validCoupon(Long id, Long userId); |
| 23 | 25 | |
| 26 | + /** | |
| 27 | + * 获得优惠劵分页 | |
| 28 | + * | |
| 29 | + * @param pageReqVO 分页查询 | |
| 30 | + * @return 优惠劵分页 | |
| 31 | + */ | |
| 32 | + PageResult<CouponDO> getCouponPage(CouponPageReqVO pageReqVO); | |
| 33 | + | |
| 24 | 34 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.service.coupon; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.util.StrUtil; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 7 | +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | |
| 8 | +import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; | |
| 9 | +import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponPageReqVO; | |
| 3 | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 11 | +import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper; | |
| 4 | 12 | import org.springframework.stereotype.Service; |
| 5 | 13 | import org.springframework.validation.annotation.Validated; |
| 6 | 14 | |
| 15 | +import javax.annotation.Resource; | |
| 16 | +import java.util.Set; | |
| 17 | + | |
| 7 | 18 | /** |
| 8 | 19 | * 优惠劵 Service 实现类 |
| 9 | 20 | * |
| ... | ... | @@ -13,9 +24,30 @@ import org.springframework.validation.annotation.Validated; |
| 13 | 24 | @Validated |
| 14 | 25 | public class CouponServiceImpl implements CouponService { |
| 15 | 26 | |
| 27 | + @Resource | |
| 28 | + private MemberUserApi memberUserApi; | |
| 29 | + @Resource | |
| 30 | + private CouponMapper couponMapper; | |
| 31 | + | |
| 16 | 32 | // TODO 芋艿:待实现 |
| 17 | 33 | @Override |
| 18 | 34 | public CouponDO validCoupon(Long id, Long userId) { |
| 19 | 35 | return null; |
| 20 | 36 | } |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public PageResult<CouponDO> getCouponPage(CouponPageReqVO pageReqVO) { | |
| 40 | + // 获得用户编号 | |
| 41 | + Set<Long> userIds = null; | |
| 42 | + if (StrUtil.isNotEmpty(pageReqVO.getNickname())) { | |
| 43 | + userIds = CollectionUtils.convertSet(memberUserApi.getUserListByNickname(pageReqVO.getNickname()), | |
| 44 | + UserRespDTO::getId); | |
| 45 | + if (CollUtil.isEmpty(userIds)) { | |
| 46 | + return PageResult.empty(); | |
| 47 | + } | |
| 48 | + } | |
| 49 | + // 分页查询 | |
| 50 | + return couponMapper.selectPage(pageReqVO, userIds); | |
| 51 | + } | |
| 52 | + | |
| 21 | 53 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/price/PriceServiceTest.java
| ... | ... | @@ -7,10 +7,7 @@ import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO; |
| 7 | 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 8 | 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.discount.DiscountProductDO; |
| 9 | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; |
| 10 | -import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; | |
| 11 | -import cn.iocoder.yudao.module.promotion.enums.common.PromotionLevelEnum; | |
| 12 | -import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; | |
| 13 | -import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; | |
| 10 | +import cn.iocoder.yudao.module.promotion.enums.common.*; | |
| 14 | 11 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; |
| 15 | 12 | import cn.iocoder.yudao.module.promotion.service.discount.DiscountService; |
| 16 | 13 | import cn.iocoder.yudao.module.promotion.service.reward.RewardService; |
| ... | ... | @@ -374,13 +371,11 @@ public class PriceServiceTest extends BaseMockitoUnitTest { |
| 374 | 371 | when(productSkuApi.getSkuList(eq(asSet(10L, 20L, 30L)))).thenReturn(asList(productSku01, productSku02, productSku03)); |
| 375 | 372 | // mock 方法(优惠劵 Coupon 信息) |
| 376 | 373 | CouponDO coupon = randomPojo(CouponDO.class, o -> o.setId(1024L).setName("程序员节") |
| 377 | - .setProductScope(PromotionProductScopeEnum.SPU.getScope()).setSpuIds(asList(1L, 2L)) | |
| 378 | - .setPriceAvailable(350).setPreferentialType(2).setPercentOff(50).setDiscountPriceLimit(70)); | |
| 374 | + .setProductScope(PromotionProductScopeEnum.SPU.getScope()).setProductSpuIds(asList(1L, 2L)) | |
| 375 | + .setUsePrice(350).setDiscountType(PromotionDiscountTypeEnum.PERCENT.getType()) | |
| 376 | + .setDiscountPercent(50).setDiscountLimitPrice(70)); | |
| 379 | 377 | when(couponService.validCoupon(eq(1024L), eq(calculateReqDTO.getUserId()))).thenReturn(coupon); |
| 380 | 378 | |
| 381 | - // 200 + 150; 350 | |
| 382 | - // | |
| 383 | - | |
| 384 | 379 | // 调用 |
| 385 | 380 | PriceCalculateRespDTO priceCalculate = priceService.calculatePrice(calculateReqDTO); |
| 386 | 381 | // 断言 Order 部分 | ... | ... |
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java
| ... | ... | @@ -2,6 +2,12 @@ package cn.iocoder.yudao.module.member.api.user; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; |
| 4 | 4 | |
| 5 | +import java.util.Collection; | |
| 6 | +import java.util.List; | |
| 7 | +import java.util.Map; | |
| 8 | + | |
| 9 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 10 | + | |
| 5 | 11 | /** |
| 6 | 12 | * 会员用户的 API 接口 |
| 7 | 13 | * |
| ... | ... | @@ -17,4 +23,30 @@ public interface MemberUserApi { |
| 17 | 23 | */ |
| 18 | 24 | UserRespDTO getUser(Long id); |
| 19 | 25 | |
| 26 | + /** | |
| 27 | + * 获得会员用户信息们 | |
| 28 | + * | |
| 29 | + * @param ids 用户编号的数组 | |
| 30 | + * @return 用户信息们 | |
| 31 | + */ | |
| 32 | + List<UserRespDTO> getUsers(Collection<Long> ids); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 获得会员用户 Map | |
| 36 | + * | |
| 37 | + * @param ids 用户编号的数组 | |
| 38 | + * @return 会员用户 Map | |
| 39 | + */ | |
| 40 | + default Map<Long, UserRespDTO> getUserMap(Collection<Long> ids) { | |
| 41 | + return convertMap(getUsers(ids), UserRespDTO::getId); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * 基于用户昵称,模糊匹配用户列表 | |
| 46 | + * | |
| 47 | + * @param nickname 用户昵称,模糊匹配 | |
| 48 | + * @return 用户信息的列表 | |
| 49 | + */ | |
| 50 | + List<UserRespDTO> getUserListByNickname(String nickname); | |
| 51 | + | |
| 20 | 52 | } | ... | ... |
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/UserInfoDTO.java deleted
| 1 | -package cn.iocoder.yudao.module.member.api.user.dto; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | -import lombok.Data; | |
| 5 | - | |
| 6 | -import java.util.Date; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 用户信息 Response DTO | |
| 10 | - * | |
| 11 | - * @author 芋道源码 | |
| 12 | - */ | |
| 13 | -@Data | |
| 14 | -public class UserInfoDTO { | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 用户ID | |
| 18 | - */ | |
| 19 | - private Long id; | |
| 20 | - /** | |
| 21 | - * 用户昵称 | |
| 22 | - */ | |
| 23 | - private String nickname; | |
| 24 | - /** | |
| 25 | - * 用户头像 | |
| 26 | - */ | |
| 27 | - private String avatar; | |
| 28 | - /** | |
| 29 | - * 帐号状态 | |
| 30 | - * | |
| 31 | - * 枚举 {@link CommonStatusEnum} | |
| 32 | - */ | |
| 33 | - private Integer status; | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * 手机 | |
| 37 | - */ | |
| 38 | - private String mobile; | |
| 39 | - /** | |
| 40 | - * 注册 IP | |
| 41 | - */ | |
| 42 | - private String registerIp; | |
| 43 | - /** | |
| 44 | - * 最后登录IP | |
| 45 | - */ | |
| 46 | - private String loginIp; | |
| 47 | - /** | |
| 48 | - * 最后登录时间 | |
| 49 | - */ | |
| 50 | - private Date loginDate; | |
| 51 | - | |
| 52 | -} |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java
| ... | ... | @@ -8,6 +8,8 @@ import org.springframework.stereotype.Service; |
| 8 | 8 | import org.springframework.validation.annotation.Validated; |
| 9 | 9 | |
| 10 | 10 | import javax.annotation.Resource; |
| 11 | +import java.util.Collection; | |
| 12 | +import java.util.List; | |
| 11 | 13 | |
| 12 | 14 | /** |
| 13 | 15 | * 会员用户的 API 实现类 |
| ... | ... | @@ -27,4 +29,14 @@ public class MemberUserApiImpl implements MemberUserApi { |
| 27 | 29 | return UserConvert.INSTANCE.convert2(user); |
| 28 | 30 | } |
| 29 | 31 | |
| 32 | + @Override | |
| 33 | + public List<UserRespDTO> getUsers(Collection<Long> ids) { | |
| 34 | + return UserConvert.INSTANCE.convertList2(userService.getUserList(ids)); | |
| 35 | + } | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + public List<UserRespDTO> getUserListByNickname(String nickname) { | |
| 39 | + return UserConvert.INSTANCE.convertList2(userService.getUserListByNickname(nickname)); | |
| 40 | + } | |
| 41 | + | |
| 30 | 42 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/UserController.java deleted
| 1 | -package cn.iocoder.yudao.module.member.controller.admin.user; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | -import cn.iocoder.yudao.module.member.api.user.dto.UserInfoDTO; | |
| 5 | -import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; | |
| 6 | -import cn.iocoder.yudao.module.member.convert.user.UserConvert; | |
| 7 | -import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; | |
| 8 | -import cn.iocoder.yudao.module.member.service.user.MemberUserService; | |
| 9 | -import io.swagger.annotations.Api; | |
| 10 | -import io.swagger.annotations.ApiOperation; | |
| 11 | -import lombok.extern.slf4j.Slf4j; | |
| 12 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 13 | -import org.springframework.web.bind.annotation.PathVariable; | |
| 14 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 15 | -import org.springframework.web.bind.annotation.RestController; | |
| 16 | - | |
| 17 | -import javax.annotation.Resource; | |
| 18 | - | |
| 19 | -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 20 | - | |
| 21 | -/** | |
| 22 | - * @author Banging | |
| 23 | - */ | |
| 24 | -@Slf4j | |
| 25 | -@Api("用户管理") | |
| 26 | -@RestController(value = "memberUserController") | |
| 27 | -@RequestMapping("/user") | |
| 28 | -public class UserController { | |
| 29 | - | |
| 30 | - @Resource | |
| 31 | - private MemberUserService userService; | |
| 32 | - | |
| 33 | - @ApiOperation(value = "用户信息获取",notes = "用户基本信息的获取") | |
| 34 | - @GetMapping("/{tel}") | |
| 35 | - public CommonResult<UserInfoDTO> getUserInfo(@PathVariable String tel){ | |
| 36 | - MemberUserDO user = userService.getUserByMobile(tel); | |
| 37 | - return CommonResult.success(UserConvert.INSTANCE.convertInfo(user)); | |
| 38 | - } | |
| 39 | -} |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/UserConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.member.convert.user; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.member.api.user.dto.UserInfoDTO; | |
| 4 | 3 | import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; |
| 5 | 4 | import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoRespVO; |
| 6 | 5 | import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; |
| 7 | 6 | import org.mapstruct.Mapper; |
| 8 | 7 | import org.mapstruct.factory.Mappers; |
| 9 | 8 | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 10 | 11 | @Mapper |
| 11 | 12 | public interface UserConvert { |
| 12 | 13 | |
| ... | ... | @@ -15,5 +16,7 @@ public interface UserConvert { |
| 15 | 16 | AppUserInfoRespVO convert(MemberUserDO bean); |
| 16 | 17 | |
| 17 | 18 | UserRespDTO convert2(MemberUserDO bean); |
| 18 | - UserInfoDTO convertInfo(MemberUserDO bean); | |
| 19 | + | |
| 20 | + List<UserRespDTO> convertList2(List<MemberUserDO> list); | |
| 21 | + | |
| 19 | 22 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.member.dal.mysql.user; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 4 | 5 | import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; |
| 5 | 6 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 7 | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 7 | 10 | /** |
| 8 | 11 | * 会员 User Mapper |
| 9 | 12 | * |
| ... | ... | @@ -16,4 +19,9 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> { |
| 16 | 19 | return selectOne(MemberUserDO::getMobile, mobile); |
| 17 | 20 | } |
| 18 | 21 | |
| 22 | + default List<MemberUserDO> selectListByNicknameLike(String nickname) { | |
| 23 | + return selectList(new LambdaQueryWrapperX<MemberUserDO>() | |
| 24 | + .likeIfPresent(MemberUserDO::getNickname, nickname)); | |
| 25 | + } | |
| 26 | + | |
| 19 | 27 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java
| ... | ... | @@ -5,6 +5,8 @@ import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobile |
| 5 | 5 | import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; |
| 6 | 6 | |
| 7 | 7 | import java.io.InputStream; |
| 8 | +import java.util.Collection; | |
| 9 | +import java.util.List; | |
| 8 | 10 | |
| 9 | 11 | /** |
| 10 | 12 | * 会员用户 Service 接口 |
| ... | ... | @@ -22,6 +24,15 @@ public interface MemberUserService { |
| 22 | 24 | MemberUserDO getUserByMobile(String mobile); |
| 23 | 25 | |
| 24 | 26 | /** |
| 27 | + * 基于用户昵称,模糊匹配用户列表 | |
| 28 | + * | |
| 29 | + * @param nickname 用户昵称,模糊匹配 | |
| 30 | + * @return 用户信息的列表 | |
| 31 | + */ | |
| 32 | + List<MemberUserDO> getUserListByNickname(String nickname); | |
| 33 | + | |
| 34 | + | |
| 35 | + /** | |
| 25 | 36 | * 基于手机号创建用户。 |
| 26 | 37 | * 如果用户已经存在,则直接进行返回 |
| 27 | 38 | * |
| ... | ... | @@ -48,6 +59,14 @@ public interface MemberUserService { |
| 48 | 59 | MemberUserDO getUser(Long id); |
| 49 | 60 | |
| 50 | 61 | /** |
| 62 | + * 通过用户 ID 查询用户们 | |
| 63 | + * | |
| 64 | + * @param ids 用户 ID | |
| 65 | + * @return 用户对象信息数组 | |
| 66 | + */ | |
| 67 | + List<MemberUserDO> getUserList(Collection<Long> ids); | |
| 68 | + | |
| 69 | + /** | |
| 51 | 70 | * 修改用户昵称 |
| 52 | 71 | * @param userId 用户id |
| 53 | 72 | * @param nickname 用户新昵称 | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java
| ... | ... | @@ -19,7 +19,9 @@ import org.springframework.transaction.annotation.Transactional; |
| 19 | 19 | import javax.annotation.Resource; |
| 20 | 20 | import javax.validation.Valid; |
| 21 | 21 | import java.io.InputStream; |
| 22 | +import java.util.Collection; | |
| 22 | 23 | import java.util.Date; |
| 24 | +import java.util.List; | |
| 23 | 25 | |
| 24 | 26 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 25 | 27 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; |
| ... | ... | @@ -52,6 +54,11 @@ public class MemberUserServiceImpl implements MemberUserService { |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | 56 | @Override |
| 57 | + public List<MemberUserDO> getUserListByNickname(String nickname) { | |
| 58 | + return memberUserMapper.selectListByNicknameLike(nickname); | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Override | |
| 55 | 62 | public MemberUserDO createUserIfAbsent(String mobile, String registerIp) { |
| 56 | 63 | // 用户已经存在 |
| 57 | 64 | MemberUserDO user = memberUserMapper.selectByMobile(mobile); |
| ... | ... | @@ -87,6 +94,11 @@ public class MemberUserServiceImpl implements MemberUserService { |
| 87 | 94 | } |
| 88 | 95 | |
| 89 | 96 | @Override |
| 97 | + public List<MemberUserDO> getUserList(Collection<Long> ids) { | |
| 98 | + return memberUserMapper.selectBatchIds(ids); | |
| 99 | + } | |
| 100 | + | |
| 101 | + @Override | |
| 90 | 102 | public void updateUserNickname(Long userId, String nickname) { |
| 91 | 103 | MemberUserDO user = this.checkUserExists(userId); |
| 92 | 104 | // 仅当新昵称不等于旧昵称时进行修改 | ... | ... |