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