promotion:增加优惠劵的后端分页接口
parent
2c39405bce
commit
a89d5a83db
@ -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,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,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;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue