后端:用户优惠劵分页列表接口
This commit is contained in:
parent
315dec741f
commit
92ed97faed
@ -20,8 +20,8 @@ if (!process.env.NODE_ENV || process.env.NODE_ENV == 'development') {
|
||||
|
||||
// baseUrl = 'http://127.0.0.1';
|
||||
// baseUrl = 'http://180.167.213.26:18099';
|
||||
dataSources = 'remote';
|
||||
// dataSources = 'local';
|
||||
// dataSources = 'remote';
|
||||
dataSources = 'local';
|
||||
|
||||
export {
|
||||
baseUrl,
|
||||
|
@ -35,7 +35,10 @@ public class AdminsCouponController {
|
||||
@GetMapping("/template/page")
|
||||
@ApiOperation(value = "优惠劵(码)模板分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "type", value = "类型", example = "参考 CouponTemplateTypeEnum 枚举"),
|
||||
@ApiImplicitParam(name = "title", value = "标题,模糊匹配", example = "活动 A"),
|
||||
@ApiImplicitParam(name = "status", value = "状态", example = "参考 CouponTemplateStatusEnum 枚举"),
|
||||
@ApiImplicitParam(name = "preferentialType", value = "优惠类型", example = "参考 CouponTemplatePreferentialTypeEnum 枚举"),
|
||||
@ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"),
|
||||
})
|
||||
|
@ -3,9 +3,12 @@ package cn.iocoder.mall.promotion.application.controller.users;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.api.CouponService;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponCardBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponCardPageBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO;
|
||||
import cn.iocoder.mall.promotion.api.dto.CouponCardPageDTO;
|
||||
import cn.iocoder.mall.promotion.application.convert.CouponCardConvert;
|
||||
import cn.iocoder.mall.promotion.application.convert.CouponTemplateConvert;
|
||||
import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardPageVO;
|
||||
import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardVO;
|
||||
import cn.iocoder.mall.promotion.application.vo.users.UsersCouponTemplateVO;
|
||||
import cn.iocoder.mall.user.sdk.annotation.PermitAll;
|
||||
@ -13,6 +16,7 @@ import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -37,6 +41,22 @@ public class UsersCouponController {
|
||||
|
||||
// ========== 优惠劵 ==========
|
||||
|
||||
@GetMapping("/card/page")
|
||||
@ApiOperation(value = "优惠劵分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "status", value = "状态", example = "参考 CouponCardStatusEnum 枚举"),
|
||||
@ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"),
|
||||
})
|
||||
public CommonResult<UsersCouponCardPageVO> cardPage(@RequestParam(value = "status", required = false) Integer status,
|
||||
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
CommonResult<CouponCardPageBO> result = couponService.getCouponCardPage(new CouponCardPageDTO()
|
||||
.setStatus(status).setUserId(UserSecurityContextHolder.getContext().getUserId())
|
||||
.setPageNo(pageNo).setPageSize(pageSize));
|
||||
return CouponCardConvert.INSTANCE.convert2(result);
|
||||
}
|
||||
|
||||
@PostMapping("/card/add")
|
||||
@ApiOperation(value = "领取优惠劵")
|
||||
@ApiImplicitParam(name = "templateId", value = "优惠劵(码)模板编号", required = true, example = "10")
|
||||
|
@ -2,6 +2,8 @@ package cn.iocoder.mall.promotion.application.convert;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponCardBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponCardPageBO;
|
||||
import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardPageVO;
|
||||
import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
@ -14,6 +16,10 @@ public interface CouponCardConvert {
|
||||
|
||||
@Mappings({})
|
||||
CommonResult<UsersCouponCardVO> convert(CommonResult<CouponCardBO> result);
|
||||
|
||||
@Mappings({})
|
||||
CommonResult<UsersCouponCardPageVO> convert2(CommonResult<CouponCardPageBO> result);
|
||||
|
||||
//
|
||||
// @Mappings({})
|
||||
// List<UsersCouponTemplateVO> convertList2(List<CouponTemplateBO> banners);
|
||||
|
@ -0,0 +1,20 @@
|
||||
package cn.iocoder.mall.promotion.application.vo.users;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel("优惠劵分页 VO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UsersCouponCardPageVO {
|
||||
|
||||
@ApiModelProperty(value = "优惠劵数组")
|
||||
private List<UsersCouponCardVO> list;
|
||||
@ApiModelProperty(value = "优惠劵总数")
|
||||
private Integer total;
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package cn.iocoder.mall.promotion.api;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponCardBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponCardPageBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO;
|
||||
import cn.iocoder.mall.promotion.api.constant.CouponTemplateStatusEnum;
|
||||
@ -61,6 +62,8 @@ public interface CouponService {
|
||||
|
||||
// ========== 优惠劵 ==========
|
||||
|
||||
CommonResult<CouponCardPageBO> getCouponCardPage(CouponCardPageDTO couponCardPageDTO);
|
||||
|
||||
/**
|
||||
* 基于优惠劵模板,领取优惠劵
|
||||
*
|
||||
|
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.mall.promotion.api.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠劵分页 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class CouponCardPageBO {
|
||||
|
||||
/**
|
||||
* 优惠劵数组
|
||||
*/
|
||||
private List<CouponCardBO> list;
|
||||
/**
|
||||
* 总量
|
||||
*/
|
||||
private Integer total;
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cn.iocoder.mall.promotion.api.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 优惠劵分页 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class CouponCardPageDTO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Integer userId;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
@NotNull(message = "页码不能为空")
|
||||
private Integer pageNo;
|
||||
@NotNull(message = "每页条数不能为空")
|
||||
private Integer pageSize;
|
||||
|
||||
}
|
@ -11,9 +11,13 @@ public interface CouponCardMapper {
|
||||
|
||||
CouponCardDO selectById(@Param("id") Integer id);
|
||||
|
||||
List<CouponCardDO> selectListByPage(@Param("status") Integer status);
|
||||
List<CouponCardDO> selectListByPage(@Param("userId") Integer userId,
|
||||
@Param("status") Integer status,
|
||||
@Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
Integer selectCountByPage(@Param("status") Integer status);
|
||||
Integer selectCountByPage(@Param("userId") Integer userId,
|
||||
@Param("status") Integer status);
|
||||
|
||||
int selectCountByUserIdAndTemplateId(@Param("userId") Integer userId,
|
||||
@Param("templateId") Integer templateId);
|
||||
|
@ -6,6 +6,7 @@ import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.api.CouponService;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponCardBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponCardPageBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO;
|
||||
import cn.iocoder.mall.promotion.api.constant.*;
|
||||
@ -176,6 +177,20 @@ public class CouponServiceImpl implements CouponService {
|
||||
|
||||
// ========== 优惠劵 ==========
|
||||
|
||||
@Override
|
||||
public CommonResult<CouponCardPageBO> getCouponCardPage(CouponCardPageDTO couponCardPageDTO) {
|
||||
CouponCardPageBO pageBO = new CouponCardPageBO();
|
||||
// 查询分页数据
|
||||
int offset = (couponCardPageDTO.getPageNo() - 1) * couponCardPageDTO.getPageSize();
|
||||
pageBO.setList(CouponCardConvert.INSTANCE.convertToBO(couponCardMapper.selectListByPage(
|
||||
couponCardPageDTO.getUserId(), couponCardPageDTO.getStatus(),
|
||||
offset, couponCardPageDTO.getPageSize())));
|
||||
// 查询分页总数
|
||||
pageBO.setTotal(couponCardMapper.selectCountByPage(
|
||||
couponCardPageDTO.getUserId(), couponCardPageDTO.getStatus()));
|
||||
return CommonResult.success(pageBO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CommonResult<CouponCardBO> addCouponCard(Integer userId, Integer couponTemplateId) {
|
||||
|
@ -38,6 +38,9 @@
|
||||
<include refid="FIELDS" />
|
||||
FROM coupon_card
|
||||
<where>
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
@ -50,6 +53,9 @@
|
||||
COUNT(1)
|
||||
FROM coupon_card
|
||||
<where>
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
|
Loading…
Reference in New Issue
Block a user