Skip to content

Commit

Permalink
优惠劵模板相关逻辑的迁移
Browse files Browse the repository at this point in the history
  • Loading branch information
YunaiV committed Aug 22, 2020
1 parent cb0c774 commit 6fd899b
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package cn.iocoder.mall.managementweb.controller.promotion.coupon;

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.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.security.annotations.RequiresPermissions;
import io.swagger.annotations.Api;
Expand All @@ -11,10 +14,7 @@
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

Expand All @@ -32,19 +32,13 @@ public class CouponTemplateController {
@Autowired
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")
@ApiOperation("更新优惠劵模板")
@RequiresPermissions("promotion:coupon-template:update-card")
public CommonResult<Boolean> updateCouponTemplateCard(@Valid CouponTemplateCardUpdateReqVO updateVO) {
couponTemplateManager.updateCouponTemplateCard(updateVO);
return success(true);
@GetMapping("/page")
@ApiOperation("获得优惠劵模板分页")
@RequiresPermissions("promotion:coupon-template:page")
public CommonResult<PageResult<CouponTemplateRespVO>> pageCouponTemplate(CouponTemplatePageReqVO pageVO) {
return success(couponTemplateManager.pageCouponTemplate(pageVO));
}

@PostMapping("/update-status")
Expand All @@ -60,4 +54,21 @@ public CommonResult<Boolean> updateCouponTemplateStatus(@RequestParam("id") Inte
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);
}

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.List;

@ApiModel("优惠劵(码)模板 VO")
@Data
Expand Down Expand Up @@ -44,7 +45,7 @@ public class CouponTemplateRespVO {
@ApiModelProperty(value = "可用范围的类型", required = true, example = "10", notes = "参见 RangeTypeEnum 枚举")
private Integer rangeType;
@ApiModelProperty(value = "指定商品 / 分类列表,使用逗号分隔商品编号", example = "1,3,5")
private String rangeValues;
private List<Integer> rangeValues;
@ApiModelProperty(value = "生效日期类型", example = "1", notes = "参见 CouponTemplateDateTypeEnum 枚举")
private Integer dateType;
@ApiModelProperty(value = "固定日期-生效开始时间", notes = "当 dateType 为固定日期时,非空")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
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.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.CouponTemplatePageReqDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponTemplateRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

Expand All @@ -12,4 +17,8 @@ public interface CouponTemplateConvert {

CouponCardTemplateUpdateReqDTO convert(CouponTemplateCardUpdateReqVO bean);

CouponTemplatePageReqDTO convert(CouponTemplatePageReqVO bean);

PageResult<CouponTemplateRespVO> convertPage(PageResult<CouponTemplateRespDTO> page);

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package cn.iocoder.mall.managementweb.manager.promotion.coupon;

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.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.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.CouponTemplateRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
Expand All @@ -17,6 +21,23 @@ public class CouponTemplateManager {
@DubboReference(version = "${dubbo.consumer.CouponTemplateRpc.version}")
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) {
return null;
}
Expand All @@ -27,10 +48,4 @@ public void updateCouponTemplateCard(CouponTemplateCardUpdateReqVO updateVO) {
updateCouponCardTemplateResult.checkError();
}

public void updateCouponTemplateStatus(Integer id, Integer status) {
CommonResult<Boolean> updateCouponTemplateStatusResult = couponTemplateRpc.updateCouponTemplateStatus(
new CouponCardTemplateUpdateStatusReqDTO().setId(id).setStatus(status));
updateCouponTemplateStatusResult.checkError();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

import java.util.Arrays;

/**
* 可用范围的类型枚举
*/
public enum RangeTypeEnum implements IntArrayValuable {

ALL(10, "所有可用"),
PRODUCT_INCLUDE_PART(20, "部分商品可用,或指定商品可用"),
PRODUCT_EXCLUDE_PART(21, "部分商品不可用,或指定商品可用"),
PRODUCT_EXCLUDE_PART(21, "部分商品不可用,或指定商品不可用"),
CATEGORY_INCLUDE_PART(30, "部分分类可用,或指定分类可用"),
CATEGORY_EXCLUDE_PART(31, "部分分类不可用,或指定分类可用"),
CATEGORY_EXCLUDE_PART(31, "部分分类不可用,或指定分类不可用"),
;

public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(RangeTypeEnum::getValue).toArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import java.util.Arrays;

/**
* 优惠劵(码)模板的时间类型的枚举
*/
public enum CouponTemplateDateTypeEnum implements IntArrayValuable {

FIXED_DATE(1, "固定日期"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import java.util.Arrays;

/**
* 优惠劵(码)模板的状态的枚举
*/
public enum CouponTemplateStatusEnum implements IntArrayValuable {

ENABLE(1, "生效中"),
Expand Down

This file was deleted.

0 comments on commit 6fd899b

Please sign in to comment.