优惠劵模板相关逻辑的迁移

This commit is contained in:
YunaiV 2020-08-22 13:49:38 +08:00
parent cb0c7744ac
commit 6fd899bca2
9 changed files with 93 additions and 84 deletions

View File

@ -1,8 +1,11 @@
package cn.iocoder.mall.managementweb.controller.promotion.coupon; package cn.iocoder.mall.managementweb.controller.promotion.coupon;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardCreateReqVO; import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardCreateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardUpdateReqVO; import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardUpdateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplatePageReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateRespVO;
import cn.iocoder.mall.managementweb.manager.promotion.coupon.CouponTemplateManager; import cn.iocoder.mall.managementweb.manager.promotion.coupon.CouponTemplateManager;
import cn.iocoder.security.annotations.RequiresPermissions; import cn.iocoder.security.annotations.RequiresPermissions;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -11,10 +14,7 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid; import javax.validation.Valid;
@ -32,19 +32,13 @@ public class CouponTemplateController {
@Autowired @Autowired
private CouponTemplateManager couponTemplateManager; private CouponTemplateManager couponTemplateManager;
@PostMapping("/create-card") // ========== 通用逻辑 =========
@ApiOperation("创建优惠劵模板")
@RequiresPermissions("promotion:coupon-template:create-card")
public CommonResult<Integer> createCouponTemplateCard(@Valid CouponTemplateCardCreateReqVO createVO) {
return success(couponTemplateManager.createCouponTemplateCard(createVO));
}
@PostMapping("/update-card") @GetMapping("/page")
@ApiOperation("更新优惠劵模板") @ApiOperation("获得优惠劵模板分页")
@RequiresPermissions("promotion:coupon-template:update-card") @RequiresPermissions("promotion:coupon-template:page")
public CommonResult<Boolean> updateCouponTemplateCard(@Valid CouponTemplateCardUpdateReqVO updateVO) { public CommonResult<PageResult<CouponTemplateRespVO>> pageCouponTemplate(CouponTemplatePageReqVO pageVO) {
couponTemplateManager.updateCouponTemplateCard(updateVO); return success(couponTemplateManager.pageCouponTemplate(pageVO));
return success(true);
} }
@PostMapping("/update-status") @PostMapping("/update-status")
@ -60,4 +54,21 @@ public class CouponTemplateController {
return success(true); return success(true);
} }
// ========== 优惠劵模板 ==========
@PostMapping("/create-card")
@ApiOperation("创建优惠劵模板")
@RequiresPermissions("promotion:coupon-template:create-card")
public CommonResult<Integer> createCouponTemplateCard(@Valid CouponTemplateCardCreateReqVO createVO) {
return success(couponTemplateManager.createCouponTemplateCard(createVO));
}
@PostMapping("/update-card")
@ApiOperation("更新优惠劵模板")
@RequiresPermissions("promotion:coupon-template:update-card")
public CommonResult<Boolean> updateCouponTemplateCard(@Valid CouponTemplateCardUpdateReqVO updateVO) {
couponTemplateManager.updateCouponTemplateCard(updateVO);
return success(true);
}
} }

View File

@ -0,0 +1,23 @@
package cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template;
import cn.iocoder.common.framework.vo.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ApiModel("优惠劵(码)模板分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class CouponTemplatePageReqVO extends PageParam {
@ApiModelProperty(value = "类型", example = "1", notes = "参考 CouponTemplateTypeEnum 枚举")
private Integer type;
@ApiModelProperty(value = "标题", example = "优惠劵牛逼")
private String title;
@ApiModelProperty(value = "状态", example = "1", notes = "参考 CouponTemplateStatusEnum 枚举")
private Integer status;
@ApiModelProperty(value = "优惠类型", example = "1", notes = "参见 PreferentialTypeEnum 枚举")
private Integer preferentialType;
}

View File

@ -6,6 +6,7 @@ import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.util.Date; import java.util.Date;
import java.util.List;
@ApiModel("优惠劵(码)模板 VO") @ApiModel("优惠劵(码)模板 VO")
@Data @Data
@ -44,7 +45,7 @@ public class CouponTemplateRespVO {
@ApiModelProperty(value = "可用范围的类型", required = true, example = "10", notes = "参见 RangeTypeEnum 枚举") @ApiModelProperty(value = "可用范围的类型", required = true, example = "10", notes = "参见 RangeTypeEnum 枚举")
private Integer rangeType; private Integer rangeType;
@ApiModelProperty(value = "指定商品 / 分类列表,使用逗号分隔商品编号", example = "1,3,5") @ApiModelProperty(value = "指定商品 / 分类列表,使用逗号分隔商品编号", example = "1,3,5")
private String rangeValues; private List<Integer> rangeValues;
@ApiModelProperty(value = "生效日期类型", example = "1", notes = "参见 CouponTemplateDateTypeEnum 枚举") @ApiModelProperty(value = "生效日期类型", example = "1", notes = "参见 CouponTemplateDateTypeEnum 枚举")
private Integer dateType; private Integer dateType;
@ApiModelProperty(value = "固定日期-生效开始时间", notes = "当 dateType 为固定日期时,非空") @ApiModelProperty(value = "固定日期-生效开始时间", notes = "当 dateType 为固定日期时,非空")

View File

@ -1,7 +1,12 @@
package cn.iocoder.mall.managementweb.convert.promotion.coupon; package cn.iocoder.mall.managementweb.convert.promotion.coupon;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardUpdateReqVO; import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardUpdateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplatePageReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateRespVO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponCardTemplateUpdateReqDTO; import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponCardTemplateUpdateReqDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponTemplatePageReqDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponTemplateRespDTO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -12,4 +17,8 @@ public interface CouponTemplateConvert {
CouponCardTemplateUpdateReqDTO convert(CouponTemplateCardUpdateReqVO bean); CouponCardTemplateUpdateReqDTO convert(CouponTemplateCardUpdateReqVO bean);
CouponTemplatePageReqDTO convert(CouponTemplatePageReqVO bean);
PageResult<CouponTemplateRespVO> convertPage(PageResult<CouponTemplateRespDTO> page);
} }

View File

@ -1,11 +1,15 @@
package cn.iocoder.mall.managementweb.manager.promotion.coupon; package cn.iocoder.mall.managementweb.manager.promotion.coupon;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardCreateReqVO; import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardCreateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardUpdateReqVO; import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardUpdateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplatePageReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateRespVO;
import cn.iocoder.mall.managementweb.convert.promotion.coupon.CouponTemplateConvert; import cn.iocoder.mall.managementweb.convert.promotion.coupon.CouponTemplateConvert;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponTemplateRpc; import cn.iocoder.mall.promotion.api.rpc.coupon.CouponTemplateRpc;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponCardTemplateUpdateStatusReqDTO; import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponCardTemplateUpdateStatusReqDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponTemplateRespDTO;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -17,6 +21,23 @@ public class CouponTemplateManager {
@DubboReference(version = "${dubbo.consumer.CouponTemplateRpc.version}") @DubboReference(version = "${dubbo.consumer.CouponTemplateRpc.version}")
private CouponTemplateRpc couponTemplateRpc; private CouponTemplateRpc couponTemplateRpc;
// ========== 通用逻辑 =========
public PageResult<CouponTemplateRespVO> pageCouponTemplate(CouponTemplatePageReqVO pageVO) {
CommonResult<PageResult<CouponTemplateRespDTO>> pageCouponTemplateResult =
couponTemplateRpc.pageCouponTemplate(CouponTemplateConvert.INSTANCE.convert(pageVO));
pageCouponTemplateResult.checkError();
return CouponTemplateConvert.INSTANCE.convertPage(pageCouponTemplateResult.getData());
}
public void updateCouponTemplateStatus(Integer id, Integer status) {
CommonResult<Boolean> updateCouponTemplateStatusResult = couponTemplateRpc.updateCouponTemplateStatus(
new CouponCardTemplateUpdateStatusReqDTO().setId(id).setStatus(status));
updateCouponTemplateStatusResult.checkError();
}
// ========== 优惠劵模板 ==========
public Integer createCouponTemplateCard(CouponTemplateCardCreateReqVO createVO) { public Integer createCouponTemplateCard(CouponTemplateCardCreateReqVO createVO) {
return null; return null;
} }
@ -27,10 +48,4 @@ public class CouponTemplateManager {
updateCouponCardTemplateResult.checkError(); updateCouponCardTemplateResult.checkError();
} }
public void updateCouponTemplateStatus(Integer id, Integer status) {
CommonResult<Boolean> updateCouponTemplateStatusResult = couponTemplateRpc.updateCouponTemplateStatus(
new CouponCardTemplateUpdateStatusReqDTO().setId(id).setStatus(status));
updateCouponTemplateStatusResult.checkError();
}
} }

View File

@ -4,13 +4,16 @@ import cn.iocoder.common.framework.core.IntArrayValuable;
import java.util.Arrays; import java.util.Arrays;
/**
* 可用范围的类型枚举
*/
public enum RangeTypeEnum implements IntArrayValuable { public enum RangeTypeEnum implements IntArrayValuable {
ALL(10, "所有可用"), ALL(10, "所有可用"),
PRODUCT_INCLUDE_PART(20, "部分商品可用,或指定商品可用"), PRODUCT_INCLUDE_PART(20, "部分商品可用,或指定商品可用"),
PRODUCT_EXCLUDE_PART(21, "部分商品不可用,或指定商品可用"), PRODUCT_EXCLUDE_PART(21, "部分商品不可用,或指定商品可用"),
CATEGORY_INCLUDE_PART(30, "部分分类可用,或指定分类可用"), CATEGORY_INCLUDE_PART(30, "部分分类可用,或指定分类可用"),
CATEGORY_EXCLUDE_PART(31, "部分分类不可用,或指定分类可用"), CATEGORY_EXCLUDE_PART(31, "部分分类不可用,或指定分类可用"),
; ;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(RangeTypeEnum::getValue).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(RangeTypeEnum::getValue).toArray();

View File

@ -4,6 +4,9 @@ import cn.iocoder.common.framework.core.IntArrayValuable;
import java.util.Arrays; import java.util.Arrays;
/**
* 优惠劵模板的时间类型的枚举
*/
public enum CouponTemplateDateTypeEnum implements IntArrayValuable { public enum CouponTemplateDateTypeEnum implements IntArrayValuable {
FIXED_DATE(1, "固定日期"), FIXED_DATE(1, "固定日期"),

View File

@ -4,6 +4,9 @@ import cn.iocoder.common.framework.core.IntArrayValuable;
import java.util.Arrays; import java.util.Arrays;
/**
* 优惠劵模板的状态的枚举
*/
public enum CouponTemplateStatusEnum implements IntArrayValuable { public enum CouponTemplateStatusEnum implements IntArrayValuable {
ENABLE(1, "生效中"), ENABLE(1, "生效中"),

View File

@ -1,59 +0,0 @@
package cn.iocoder.mall.promotion.application.controller.admins;
import cn.iocoder.common.framework.util.DateUtil;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.CouponService;
import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO;
import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO;
import cn.iocoder.mall.promotion.api.dto.CouponCardTemplateAddDTO;
import cn.iocoder.mall.promotion.api.dto.CouponCardTemplateUpdateDTO;
import cn.iocoder.mall.promotion.api.dto.CouponTemplatePageDTO;
import cn.iocoder.mall.promotion.application.convert.CouponTemplateConvert;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsCouponTemplatePageVO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsCouponTemplateVO;
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("admins/coupon")
@Api("优惠劵(码)模块")
public class AdminsCouponController {
@Reference(validation = "true", version = "${dubbo.provider.CouponService.version}")
private CouponService couponService;
// ========== 优惠劵模板 ==========
@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"),
})
public CommonResult<AdminsCouponTemplatePageVO> templatePage(@RequestParam(value = "type", required = false) Integer type,
@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "preferentialType", required = false) Integer preferentialType,
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
CouponTemplatePageBO result = couponService.getCouponTemplatePage(new CouponTemplatePageDTO()
.setType(type).setTitle(title).setStatus(status).setPreferentialType(preferentialType)
.setPageNo(pageNo).setPageSize(pageSize));
return success(CouponTemplateConvert.ADMINS.convertPage(result));
}
}