From 6fd899bca2205f2eb834782c18d4b525cca8baea Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 22 Aug 2020 13:49:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=8A=B5=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coupon/CouponTemplateController.java | 43 +++++++++----- .../vo/template/CouponTemplatePageReqVO.java | 23 ++++++++ .../vo/template/CouponTemplateRespVO.java | 3 +- .../coupon/CouponTemplateConvert.java | 9 +++ .../coupon/CouponTemplateManager.java | 27 +++++++-- .../promotion/api/enums/RangeTypeEnum.java | 7 ++- .../template/CouponTemplateDateTypeEnum.java | 3 + .../template/CouponTemplateStatusEnum.java | 3 + .../admins/AdminsCouponController.java | 59 ------------------- 9 files changed, 93 insertions(+), 84 deletions(-) create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplatePageReqVO.java delete mode 100644 promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/CouponTemplateController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/CouponTemplateController.java index cf17e175d..2a70c7df3 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/CouponTemplateController.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/CouponTemplateController.java @@ -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; @@ -11,10 +14,7 @@ import io.swagger.annotations.ApiImplicitParams; 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; @@ -32,19 +32,13 @@ public class CouponTemplateController { @Autowired private CouponTemplateManager couponTemplateManager; - @PostMapping("/create-card") - @ApiOperation("创建优惠劵模板") - @RequiresPermissions("promotion:coupon-template:create-card") - public CommonResult createCouponTemplateCard(@Valid CouponTemplateCardCreateReqVO createVO) { - return success(couponTemplateManager.createCouponTemplateCard(createVO)); - } + // ========== 通用逻辑 ========= - @PostMapping("/update-card") - @ApiOperation("更新优惠劵模板") - @RequiresPermissions("promotion:coupon-template:update-card") - public CommonResult updateCouponTemplateCard(@Valid CouponTemplateCardUpdateReqVO updateVO) { - couponTemplateManager.updateCouponTemplateCard(updateVO); - return success(true); + @GetMapping("/page") + @ApiOperation("获得优惠劵模板分页") + @RequiresPermissions("promotion:coupon-template:page") + public CommonResult> pageCouponTemplate(CouponTemplatePageReqVO pageVO) { + return success(couponTemplateManager.pageCouponTemplate(pageVO)); } @PostMapping("/update-status") @@ -60,4 +54,21 @@ public class CouponTemplateController { return success(true); } + // ========== 优惠劵模板 ========== + + @PostMapping("/create-card") + @ApiOperation("创建优惠劵模板") + @RequiresPermissions("promotion:coupon-template:create-card") + public CommonResult createCouponTemplateCard(@Valid CouponTemplateCardCreateReqVO createVO) { + return success(couponTemplateManager.createCouponTemplateCard(createVO)); + } + + @PostMapping("/update-card") + @ApiOperation("更新优惠劵模板") + @RequiresPermissions("promotion:coupon-template:update-card") + public CommonResult updateCouponTemplateCard(@Valid CouponTemplateCardUpdateReqVO updateVO) { + couponTemplateManager.updateCouponTemplateCard(updateVO); + return success(true); + } + } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplatePageReqVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplatePageReqVO.java new file mode 100644 index 000000000..7c3550610 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplatePageReqVO.java @@ -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; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplateRespVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplateRespVO.java index 846e307fb..47be80f77 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplateRespVO.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplateRespVO.java @@ -6,6 +6,7 @@ import lombok.Data; import lombok.experimental.Accessors; import java.util.Date; +import java.util.List; @ApiModel("优惠劵(码)模板 VO") @Data @@ -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 rangeValues; @ApiModelProperty(value = "生效日期类型", example = "1", notes = "参见 CouponTemplateDateTypeEnum 枚举") private Integer dateType; @ApiModelProperty(value = "固定日期-生效开始时间", notes = "当 dateType 为固定日期时,非空") diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/coupon/CouponTemplateConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/coupon/CouponTemplateConvert.java index c98af864b..a40102d18 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/coupon/CouponTemplateConvert.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/coupon/CouponTemplateConvert.java @@ -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; @@ -12,4 +17,8 @@ public interface CouponTemplateConvert { CouponCardTemplateUpdateReqDTO convert(CouponTemplateCardUpdateReqVO bean); + CouponTemplatePageReqDTO convert(CouponTemplatePageReqVO bean); + + PageResult convertPage(PageResult page); + } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/coupon/CouponTemplateManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/coupon/CouponTemplateManager.java index 30653f74f..6d79668b7 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/coupon/CouponTemplateManager.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/coupon/CouponTemplateManager.java @@ -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; @@ -17,6 +21,23 @@ public class CouponTemplateManager { @DubboReference(version = "${dubbo.consumer.CouponTemplateRpc.version}") private CouponTemplateRpc couponTemplateRpc; + // ========== 通用逻辑 ========= + + public PageResult pageCouponTemplate(CouponTemplatePageReqVO pageVO) { + CommonResult> pageCouponTemplateResult = + couponTemplateRpc.pageCouponTemplate(CouponTemplateConvert.INSTANCE.convert(pageVO)); + pageCouponTemplateResult.checkError(); + return CouponTemplateConvert.INSTANCE.convertPage(pageCouponTemplateResult.getData()); + } + + public void updateCouponTemplateStatus(Integer id, Integer status) { + CommonResult updateCouponTemplateStatusResult = couponTemplateRpc.updateCouponTemplateStatus( + new CouponCardTemplateUpdateStatusReqDTO().setId(id).setStatus(status)); + updateCouponTemplateStatusResult.checkError(); + } + + // ========== 优惠劵模板 ========== + public Integer createCouponTemplateCard(CouponTemplateCardCreateReqVO createVO) { return null; } @@ -27,10 +48,4 @@ public class CouponTemplateManager { updateCouponCardTemplateResult.checkError(); } - public void updateCouponTemplateStatus(Integer id, Integer status) { - CommonResult updateCouponTemplateStatusResult = couponTemplateRpc.updateCouponTemplateStatus( - new CouponCardTemplateUpdateStatusReqDTO().setId(id).setStatus(status)); - updateCouponTemplateStatusResult.checkError(); - } - } diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/RangeTypeEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/RangeTypeEnum.java index 63bffdae0..bfdb437bc 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/RangeTypeEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/RangeTypeEnum.java @@ -4,13 +4,16 @@ import cn.iocoder.common.framework.core.IntArrayValuable; 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(); diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateDateTypeEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateDateTypeEnum.java index cce189ff1..a23a0e956 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateDateTypeEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateDateTypeEnum.java @@ -4,6 +4,9 @@ import cn.iocoder.common.framework.core.IntArrayValuable; import java.util.Arrays; +/** + * 优惠劵(码)模板的时间类型的枚举 + */ public enum CouponTemplateDateTypeEnum implements IntArrayValuable { FIXED_DATE(1, "固定日期"), diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateStatusEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateStatusEnum.java index eb309599a..0dbfa3125 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateStatusEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateStatusEnum.java @@ -4,6 +4,9 @@ import cn.iocoder.common.framework.core.IntArrayValuable; import java.util.Arrays; +/** + * 优惠劵(码)模板的状态的枚举 + */ public enum CouponTemplateStatusEnum implements IntArrayValuable { ENABLE(1, "生效中"), diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java b/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java deleted file mode 100644 index 204cf1211..000000000 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java +++ /dev/null @@ -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 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)); - } - -}