From 60b0043a785860b4070035625c65967d1ff566aa Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 22 Aug 2020 17:58:52 +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 | 10 +- .../CouponTemplateCardCreateReqVO.java | 3 + .../coupon/CouponTemplateConvert.java | 4 + .../coupon/CouponTemplateManager.java | 9 +- .../template/CouponTemplateTypeEnum.java | 3 + .../CouponCardTemplateCreateReqDTO.java | 2 +- .../CouponCardTemplateUpdateReqDTO.java | 2 +- .../service/coupon/CouponTemplateService.java | 6 +- .../biz/service/CouponServiceImpl.java | 165 ------------------ 9 files changed, 26 insertions(+), 178 deletions(-) delete mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.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 2a70c7df3..b04758be2 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 @@ -42,7 +42,7 @@ public class CouponTemplateController { } @PostMapping("/update-status") - @ApiOperation("更新优惠劵(码)模板") + @ApiOperation("更新优惠劵(码)模板的状态") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "优惠劵(码)模板编号", required = true, example = "1"), @ApiImplicitParam(name = "status", value = "状态。1 - 开启;2 - 禁用", required = true, example = "1"), @@ -59,15 +59,15 @@ public class CouponTemplateController { @PostMapping("/create-card") @ApiOperation("创建优惠劵模板") @RequiresPermissions("promotion:coupon-template:create-card") - public CommonResult createCouponTemplateCard(@Valid CouponTemplateCardCreateReqVO createVO) { - return success(couponTemplateManager.createCouponTemplateCard(createVO)); + public CommonResult createCouponCardTemplate(@Valid CouponTemplateCardCreateReqVO createVO) { + return success(couponTemplateManager.createCouponCardTemplate(createVO)); } @PostMapping("/update-card") @ApiOperation("更新优惠劵模板") @RequiresPermissions("promotion:coupon-template:update-card") - public CommonResult updateCouponTemplateCard(@Valid CouponTemplateCardUpdateReqVO updateVO) { - couponTemplateManager.updateCouponTemplateCard(updateVO); + public CommonResult updateCouponCardTemplate(@Valid CouponTemplateCardUpdateReqVO updateVO) { + couponTemplateManager.updateCouponCardTemplate(updateVO); return success(true); } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplateCardCreateReqVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplateCardCreateReqVO.java index 5cadd1adb..3c17e9f45 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplateCardCreateReqVO.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/coupon/vo/template/CouponTemplateCardCreateReqVO.java @@ -9,6 +9,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; +import org.springframework.format.annotation.DateTimeFormat; import javax.validation.constraints.Max; import javax.validation.constraints.Min; @@ -52,8 +53,10 @@ public class CouponTemplateCardCreateReqVO { @InEnum(value = CouponTemplateDateTypeEnum.class, message = "生效日期类型必须在 {value}") private Integer dateType; @ApiModelProperty(value = "固定日期-生效开始时间", notes = "当 dateType 为固定日期时,非空") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date validStartTime; @ApiModelProperty(value = "固定日期-生效结束时间", notes = "当 dateType 为固定日期时,非空") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date validEndTime; @ApiModelProperty(value = "领取日期-开始天数", example = "0", notes = "例如,0-当天;1-次天") @Min(value = 0L, message = "领取日期开始时间最小为 {value}") 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 a40102d18..b39223ae0 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,9 +1,11 @@ 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.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.promotion.api.rpc.coupon.dto.template.CouponCardTemplateCreateReqDTO; 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; @@ -21,4 +23,6 @@ public interface CouponTemplateConvert { PageResult convertPage(PageResult page); + CouponCardTemplateCreateReqDTO convert(CouponTemplateCardCreateReqVO bean); + } 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 6d79668b7..99742ef39 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 @@ -38,11 +38,14 @@ public class CouponTemplateManager { // ========== 优惠劵模板 ========== - public Integer createCouponTemplateCard(CouponTemplateCardCreateReqVO createVO) { - return null; + public Integer createCouponCardTemplate(CouponTemplateCardCreateReqVO createVO) { + CommonResult createCouponCardTemplateResult = couponTemplateRpc.createCouponCardTemplate( + CouponTemplateConvert.INSTANCE.convert(createVO)); + createCouponCardTemplateResult.checkError(); + return createCouponCardTemplateResult.getData(); } - public void updateCouponTemplateCard(CouponTemplateCardUpdateReqVO updateVO) { + public void updateCouponCardTemplate(CouponTemplateCardUpdateReqVO updateVO) { CommonResult updateCouponCardTemplateResult = couponTemplateRpc.updateCouponCardTemplate( CouponTemplateConvert.INSTANCE.convert(updateVO)); updateCouponCardTemplateResult.checkError(); diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateTypeEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateTypeEnum.java index d34bb998c..7d86a6ed0 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateTypeEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateTypeEnum.java @@ -2,6 +2,9 @@ package cn.iocoder.mall.promotion.api.enums.coupon.template; import java.util.Arrays; +/** + * 优惠劵(码)模板的类型的枚举 + */ public enum CouponTemplateTypeEnum { CARD(1, "优惠劵"), diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/template/CouponCardTemplateCreateReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/template/CouponCardTemplateCreateReqDTO.java index d7dcf0848..60d3cd775 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/template/CouponCardTemplateCreateReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/template/CouponCardTemplateCreateReqDTO.java @@ -100,7 +100,7 @@ public class CouponCardTemplateCreateReqDTO implements Serializable { * 例如,0-当天;1-次天 */ @Min(value = 0L, message = "领取日期开始时间最小为 {value}") - private Integer fixedBeginTerm; + private Integer fixedStartTerm; /** * 领取日期-结束天数 */ diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/template/CouponCardTemplateUpdateReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/template/CouponCardTemplateUpdateReqDTO.java index 11e0dfa25..67289428b 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/template/CouponCardTemplateUpdateReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/template/CouponCardTemplateUpdateReqDTO.java @@ -99,7 +99,7 @@ public class CouponCardTemplateUpdateReqDTO implements Serializable { // * 例如,0-当天;1-次天 // */ // @Min(value = 0L, message = "领取日期开始时间最小为 {value}") -// private Integer fixedBeginTerm; +// private Integer fixedStartTerm; // /** // * 领取日期-结束天数 // */ diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponTemplateService.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponTemplateService.java index 5ece056c1..e087459b5 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponTemplateService.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponTemplateService.java @@ -73,7 +73,7 @@ public class CouponTemplateService { couponTemplateMapper.updateById(updateTemplateDO); } - private Boolean checkCouponTemplateDateType(Integer dateType, Date validStartTime, Date validEndTime, Integer fixedBeginTerm, Integer fixedEndTerm) { + private Boolean checkCouponTemplateDateType(Integer dateType, Date validStartTime, Date validEndTime, Integer fixedStartTerm, Integer fixedEndTerm) { // TODO 芋艿:后续这种类型的校验,看看怎么优化到对象里 if (CouponTemplateDateTypeEnum.FIXED_DATE.getValue().equals(dateType)) { // 固定日期 if (validStartTime == null) { @@ -86,7 +86,7 @@ public class CouponTemplateService { throw ServiceExceptionUtil.exception(BAD_REQUEST, "生效开始时间不能大于生效结束时间"); } } else if (CouponTemplateDateTypeEnum.FIXED_TERM.getValue().equals(dateType)) { // 领取日期 - if (fixedBeginTerm == null) { + if (fixedStartTerm == null) { throw ServiceExceptionUtil.exception(BAD_REQUEST, "领取日期开始时间不能为空"); } if (fixedEndTerm == null) { @@ -129,7 +129,7 @@ public class CouponTemplateService { // 校验生效日期相关 checkCouponTemplateDateType(createReqDTO.getDateType(), createReqDTO.getValidStartTime(), createReqDTO.getValidEndTime(), - createReqDTO.getFixedBeginTerm(), createReqDTO.getFixedEndTerm()); + createReqDTO.getFixedStartTerm(), createReqDTO.getFixedEndTerm()); // 校验优惠类型 checkCouponTemplatePreferentialType(createReqDTO.getPreferentialType(), createReqDTO.getPercentOff(), createReqDTO.getPriceOff(), createReqDTO.getPriceAvailable()); diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java deleted file mode 100644 index 4cf2bcf2a..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java +++ /dev/null @@ -1,165 +0,0 @@ -package cn.iocoder.mall.promotion.biz.service; - -import cn.iocoder.common.framework.enums.SysErrorCodeEnum; -import cn.iocoder.common.framework.util.DateUtil; -import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.common.framework.util.StringUtil; -import cn.iocoder.mall.promotion.api.CouponService; -import cn.iocoder.mall.promotion.api.bo.*; -import cn.iocoder.mall.promotion.api.enums.*; -import cn.iocoder.mall.promotion.api.dto.*; -import cn.iocoder.mall.promotion.biz.convert.CouponCardConvert; -import cn.iocoder.mall.promotion.biz.convert.CouponTemplateConvert; -import cn.iocoder.mall.promotion.biz.dao.CouponCardMapper; -import cn.iocoder.mall.promotion.biz.dao.CouponTemplateMapper; -import cn.iocoder.mall.promotion.biz.dataobject.CouponCardDO; -import cn.iocoder.mall.promotion.biz.dataobject.CouponTemplateDO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; -import java.util.stream.Collectors; - -@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示 -@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.CouponService.version}") -public class CouponServiceImpl implements CouponService { - - @Autowired - private CouponTemplateMapper couponTemplateMapper; - - // ========== 优惠劵(码)模板 ========== - - @Override - public CouponTemplateBO getCouponTemplate(Integer couponTemplateId) { - CouponTemplateDO template = couponTemplateMapper.selectById(couponTemplateId); - return CouponTemplateConvert.INSTANCE.convert(template); - } - - @Override - public CouponTemplatePageBO getCouponTemplatePage(CouponTemplatePageDTO couponTemplatePageDTO) { - CouponTemplatePageBO couponTemplatePageBO = new CouponTemplatePageBO(); - // 查询分页数据 - int offset = (couponTemplatePageDTO.getPageNo() - 1) * couponTemplatePageDTO.getPageSize(); - couponTemplatePageBO.setList(CouponTemplateConvert.INSTANCE.convertToBO(couponTemplateMapper.selectListByPage( - couponTemplatePageDTO.getType(), couponTemplatePageDTO.getTitle(), - couponTemplatePageDTO.getStatus(), couponTemplatePageDTO.getPreferentialType(), - offset, couponTemplatePageDTO.getPageSize()))); - // 查询分页总数 - couponTemplatePageBO.setTotal(couponTemplateMapper.selectCountByPage( - couponTemplatePageDTO.getType(), couponTemplatePageDTO.getTitle(), - couponTemplatePageDTO.getStatus(), couponTemplatePageDTO.getPreferentialType())); - return couponTemplatePageBO; - } - - @Override - public CouponTemplateBO addCouponCodeTemplate(CouponCodeTemplateAddDTO couponCodeTemplateAddDTO) { - return null; - } - - @Override - public CouponTemplateBO addCouponCardTemplate(CouponCardTemplateAddDTO couponCardTemplateAddDTO) { - // 校验生效日期相关 - checkCouponTemplateDateType(couponCardTemplateAddDTO.getDateType(), - couponCardTemplateAddDTO.getValidStartTime(), couponCardTemplateAddDTO.getValidEndTime(), - couponCardTemplateAddDTO.getFixedBeginTerm(), couponCardTemplateAddDTO.getFixedEndTerm()); - // 校验优惠类型 - Boolean checkCouponTemplateDateTypeResult = checkCouponTemplatePreferentialType( - couponCardTemplateAddDTO.getPreferentialType(), couponCardTemplateAddDTO.getPercentOff(), - couponCardTemplateAddDTO.getPriceOff(), couponCardTemplateAddDTO.getPriceAvailable()); - // 保存优惠劵模板到数据库 - CouponTemplateDO template = CouponTemplateConvert.INSTANCE.convert(couponCardTemplateAddDTO) - .setType(CouponTemplateTypeEnum.CARD.getValue()) - .setStatus(CouponTemplateStatusEnum.ENABLE.getValue()) - .setStatFetchNum(0); - template.setCreateTime(new Date()); - couponTemplateMapper.insert(template); - // 返回成功 - return CouponTemplateConvert.INSTANCE.convert(template); - } - - @Override - public Boolean updateCouponCodeTemplate(CouponCodeTemplateUpdateDTO couponCodeTemplateUpdateDTO) { - return null; - } - - @Override - public Boolean updateCouponCardTemplate(CouponCardTemplateUpdateDTO couponCardTemplateUpdateDTO) { - // 校验 CouponCardTemplate 存在 - CouponTemplateDO template = couponTemplateMapper.selectById(couponCardTemplateUpdateDTO.getId()); - if (template == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.COUPON_TEMPLATE_NOT_EXISTS.getCode()); - } - // 校验 CouponCardTemplate 是 CARD - if (!CouponTemplateTypeEnum.CARD.getValue().equals(template.getType())) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.COUPON_TEMPLATE_NOT_CARD.getCode()); - } - // 校验发放数量不能减少 - if (couponCardTemplateUpdateDTO.getTotal() < template.getTotal()) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.COUPON_TEMPLATE_TOTAL_CAN_NOT_REDUCE.getCode()); - } - // 更新优惠劵模板到数据库 - CouponTemplateDO updateTemplateDO = CouponTemplateConvert.INSTANCE.convert(couponCardTemplateUpdateDTO); - couponTemplateMapper.update(updateTemplateDO); - // 返回成功 - return true; - } - - @Override - public Boolean updateCouponTemplateStatus(Integer adminId, Integer couponTemplateId, Integer status) { - // 校验 CouponCardTemplate 存在 - CouponTemplateDO template = couponTemplateMapper.selectById(couponTemplateId); - if (template == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.COUPON_TEMPLATE_NOT_EXISTS.getCode()); - } - // 更新到数据库 - CouponTemplateDO updateTemplateDO = new CouponTemplateDO().setId(couponTemplateId).setStatus(status); - couponTemplateMapper.update(updateTemplateDO); - // 返回成功 - return true; - } - - private Boolean checkCouponTemplateDateType(Integer dateType, Date validStartTime, Date validEndTime, Integer fixedBeginTerm, Integer fixedEndTerm) { - if (CouponTemplateDateTypeEnum.FIXED_DATE.getValue().equals(dateType)) { // 固定日期 - if (validStartTime == null) { - throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "生效开始时间不能为空"); - } - if (validEndTime == null) { - throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "生效结束时间不能为空"); - } - if (validStartTime.after(validEndTime)) { - throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "生效开始时间不能大于生效结束时间"); - } - } else if (CouponTemplateDateTypeEnum.FIXED_TERM.getValue().equals(dateType)) { // 领取日期 - if (fixedBeginTerm == null) { - throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "领取日期开始时间不能为空"); - } - if (fixedEndTerm == null) { - throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "领取日期结束时间不能为空"); - } - } else { - throw new IllegalArgumentException("未知的生效日期类型:" + dateType); - } - return true; - } - - private Boolean checkCouponTemplatePreferentialType(Integer preferentialType, Integer percentOff, - Integer priceOff, Integer priceAvailable) { - if (PreferentialTypeEnum.PRICE.getValue().equals(preferentialType)) { - if (priceOff == null) { - throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "优惠金额不能为空"); - } - if (priceOff >= priceAvailable) { - throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "优惠金额不能d大于等于使用金额门槛"); - } - } else if (PreferentialTypeEnum.DISCOUNT.getValue().equals(preferentialType)) { - if (percentOff == null) { - throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "折扣百分比不能为空"); - } - } else { - throw new IllegalArgumentException("未知的优惠类型:" + preferentialType); - } - return true; - } - -}