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

pull/4/MERGE
YunaiV 2020-08-21 22:32:52 +08:00
parent b5e939fdb4
commit cb0c7744ac
74 changed files with 711 additions and 2366 deletions

View File

@ -66,6 +66,12 @@
<artifactId>product-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<!-- 营销服务 -->
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- Registry 和 Config 相关 -->
<dependency>

View File

@ -0,0 +1,63 @@
package cn.iocoder.mall.managementweb.controller.promotion.coupon;
import cn.iocoder.common.framework.vo.CommonResult;
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.manager.promotion.coupon.CouponTemplateManager;
import cn.iocoder.security.annotations.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
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 javax.validation.Valid;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* Controller
*/
@RestController
@RequestMapping("/promotion/coupon-template")
@Api(tags = "优惠劵(码)模板 API")
@Validated
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);
}
@PostMapping("/update-status")
@ApiOperation("更新优惠劵(码)模板")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "优惠劵(码)模板编号", required = true, example = "1"),
@ApiImplicitParam(name = "status", value = "状态。1 - 开启2 - 禁用", required = true, example = "1"),
})
@RequiresPermissions("promotion:coupon-template:update-status")
public CommonResult<Boolean> updateCouponTemplateStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
couponTemplateManager.updateCouponTemplateStatus(id, status);
return success(true);
}
}

View File

@ -0,0 +1,81 @@
package cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.enums.PreferentialTypeEnum;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateDateTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Date;
@ApiModel("优惠劵模板创建 Request VO")
@Data
@Accessors(chain = true)
public class CouponTemplateCardCreateReqVO {
// ========== 基本信息 BEGIN ==========
@ApiModelProperty(value = "标题", required = true, example = "优惠劵牛逼")
@NotEmpty(message = "标题不能为空")
@Length(min = 2, max = 16, message = "标题长度为 {min}-{max} 位")
private String title;
@ApiModelProperty(value = "使用说明", required = true, example = "我只是描述")
@Length(max = 255, message = "使用说明最大长度为 {max} 位")
private String description;
@ApiModelProperty(value = "每人限领个数", example = "1", notes = "null - 则表示不限制")
@Min(value = 1, message = "每人限领个数最小为 {value}")
private Integer quota;
@ApiModelProperty(value = "发放总量", example = "100")
@Min(value = 1, message = "每人限领个数最小为 {value}")
private Integer total;
// ========== 领取规则 END ==========
// ========== 使用规则 BEGIN ==========
@ApiModelProperty(value = "是否设置满多少金额可用,单位:分", required = true, example = "0", notes = "0-不限制大于0-多少金额可用")
@Min(value = 0L, message = "使用金额门槛最低为 {value}")
private Integer priceAvailable;
@ApiModelProperty(value = "可用范围的类型", required = true, example = "10", notes = "参见 RangeTypeEnum 枚举")
@NotNull(message = "可用范围的类型不能为空")
@InEnum(value = RangeTypeEnum.class, message = "可用范围的类型必须在 {value}")
private Integer rangeType;
@ApiModelProperty(value = "指定商品 / 分类列表,使用逗号分隔商品编号", example = "1,3,5")
private String rangeValues;
@ApiModelProperty(value = "生效日期类型", example = "1", notes = "参见 CouponTemplateDateTypeEnum 枚举")
@NotNull(message = "生效日期类型不能为空")
@InEnum(value = CouponTemplateDateTypeEnum.class, message = "生效日期类型必须在 {value}")
private Integer dateType;
@ApiModelProperty(value = "固定日期-生效开始时间", notes = "当 dateType 为固定日期时,非空")
private Date validStartTime;
@ApiModelProperty(value = "固定日期-生效结束时间", notes = "当 dateType 为固定日期时,非空")
private Date validEndTime;
@ApiModelProperty(value = "领取日期-开始天数", example = "0", notes = "例如0-当天1-次天")
@Min(value = 0L, message = "领取日期开始时间最小为 {value}")
private Integer fixedStartTerm;
@ApiModelProperty(value = "领取日期-结束天数", example = "1", notes = "当 dateType 为领取日期时,非空")
@Min(value = 1L, message = "领取日期结束时间最小为 {value}")
private Integer fixedEndTerm;
// ========== 使用效果 BEGIN ==========
@ApiModelProperty(value = "优惠类型", required = true, example = "1", notes = "参见 PreferentialTypeEnum 枚举")
@NotNull(message = "优惠类型不能为空")
@InEnum(value = PreferentialTypeEnum.class, message = "优惠类型必须在 {value}")
private Integer preferentialType;
@ApiModelProperty(value = "折扣百分比", example = "80", notes = "当 preferentialType 为现金券时,非空")
@Max(value = 100, message = "折扣比最大值为 {value}")
private Integer percentOff;
@ApiModelProperty(value = "优惠金额,单位:分", example = "100", notes = "当 preferentialType 为折扣卷时,非空")
@Min(value = 1, message = "优惠金额最小值为 {value}")
private Integer priceOff;
@ApiModelProperty(value = "折扣上限", example = "100", notes = "当 preferentialType 为折扣卷时,非空")
@Min(value = 1, message = "折扣上限最小值为 {value}")
private Integer discountPriceLimit;
// ========== 使用效果 END ==========
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("优惠劵模板更新 Request VO")
@Data
@Accessors(chain = true)
public class CouponTemplateCardUpdateReqVO {
// ========== 基本信息 BEGIN ==========
@ApiModelProperty(value = "模板编号,自增唯一", required = true, example = "1")
@NotNull(message = "编号不能为空")
private Integer id;
@ApiModelProperty(value = "标题", required = true, example = "优惠劵牛逼")
@NotEmpty(message = "标题不能为空")
@Length(min = 2, max = 16, message = "标题长度为 {min}-{max} 位")
private String title;
@ApiModelProperty(value = "使用说明", required = true, example = "我只是描述")
@Length(max = 255, message = "使用说明最大长度为 {max} 位")
private String description;
@ApiModelProperty(value = "每人限领个数", example = "1", notes = "null - 则表示不限制")
@Min(value = 1, message = "每人限领个数最小为 {value}")
private Integer quota;
@ApiModelProperty(value = "发放总量", example = "100")
@Min(value = 1, message = "每人限领个数最小为 {value}")
private Integer total;
// ========== 领取规则 END ==========
// ========== 使用规则 BEGIN ==========
@NotNull(message = "可用范围的类型不能为空")
@InEnum(value = RangeTypeEnum.class, message = "可用范围的类型必须在 {value}")
private Integer rangeType;
@ApiModelProperty(value = "指定商品 / 分类列表,使用逗号分隔商品编号", example = "1,3,5")
private String rangeValues;
// ========== 使用规则 END ==========
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.promotion.application.vo.admins;
package cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -7,10 +7,10 @@ import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel("CouponTemplate VO")
@ApiModel("优惠劵(码)模板 VO")
@Data
@Accessors(chain = true)
public class AdminsCouponTemplateVO {
public class CouponTemplateRespVO {
// ========== 基本信息 BEGIN ==========
@ApiModelProperty(value = "模板编号,自增唯一", required = true, example = "1")
@ -19,7 +19,7 @@ public class AdminsCouponTemplateVO {
private String title;
@ApiModelProperty(value = "使用说明", required = true, example = "我只是描述")
private String description;
@ApiModelProperty(value = "优惠劵类型", required = true, example = "参见 CouponTemplateTypeEnum 枚举")
@ApiModelProperty(value = "优惠劵类型", required = true, example = "1", notes = "参见 CouponTemplateTypeEnum 枚举")
private Integer type;
/**
*
@ -29,43 +29,42 @@ public class AdminsCouponTemplateVO {
*
* @see CouponCodeDO
*/
// TODO
private Integer codeType;
@ApiModelProperty(value = "优惠码状态", required = true, example = "参见 CouponTemplateStatusEnum 枚举")
@ApiModelProperty(value = "优惠码状态", required = true, example = "1", notes = "参见 CouponTemplateStatusEnum 枚举")
private Integer status;
@ApiModelProperty(value = "每人限领个数", example = "null - 则表示不限制")
@ApiModelProperty(value = "每人限领个数", example = "1", notes = "null - 则表示不限制")
private Integer quota;
@ApiModelProperty(value = "发放总量")
@ApiModelProperty(value = "发放总量", example = "100")
private Integer total;
// ========== 领取规则 END ==========
// ========== 使用规则 BEGIN ==========
@ApiModelProperty(value = "是否设置满多少金额可用,单位:分", required = true, example = "0-不限制大于0-多少金额可用")
@ApiModelProperty(value = "是否设置满多少金额可用,单位:分", required = true, example = "0", notes = "0-不限制大于0-多少金额可用")
private Integer priceAvailable;
@ApiModelProperty(value = "可用范围的类型", required = true, example = "参见 CouponTemplateRangeTypeEnum 枚举")
@ApiModelProperty(value = "可用范围的类型", required = true, example = "10", notes = "参见 RangeTypeEnum 枚举")
private Integer rangeType;
@ApiModelProperty(value = "指定商品 / 分类列表,使用逗号分隔商品编号", example = "参见 CouponTemplateRangeTypeEnum 枚举")
@ApiModelProperty(value = "指定商品 / 分类列表,使用逗号分隔商品编号", example = "1,3,5")
private String rangeValues;
@ApiModelProperty(value = "生效日期类型", example = "参见 CouponTemplateDateTypeEnum 枚举")
@ApiModelProperty(value = "生效日期类型", example = "1", notes = "参见 CouponTemplateDateTypeEnum 枚举")
private Integer dateType;
@ApiModelProperty(value = "固定日期-生效开始时间")
@ApiModelProperty(value = "固定日期-生效开始时间", notes = "当 dateType 为固定日期时,非空")
private Date validStartTime;
@ApiModelProperty(value = "固定日期-生效结束时间")
@ApiModelProperty(value = "固定日期-生效结束时间", notes = "当 dateType 为固定日期时,非空")
private Date validEndTime;
@ApiModelProperty(value = "领取日期-开始天数", example = "例如0-当天1-次天")
@ApiModelProperty(value = "领取日期-开始天数", example = "0", notes = "例如0-当天1-次天")
private Integer fixedStartTerm;
@ApiModelProperty(value = "领取日期-结束天数")
@ApiModelProperty(value = "领取日期-结束天数", example = "1", notes = "当 dateType 为领取日期时,非空")
private Integer fixedEndTerm;
// ========== 使用规则 END ==========
// ========== 使用效果 BEGIN ==========
@ApiModelProperty(value = "优惠类型", required = true, example = "参见 CouponTemplatePreferentialTypeEnum 枚举")
@ApiModelProperty(value = "优惠类型", required = true, example = "1", notes = "参见 PreferentialTypeEnum 枚举")
private Integer preferentialType;
@ApiModelProperty(value = "折扣百分比")
@ApiModelProperty(value = "折扣百分比", example = "80", notes = "当 preferentialType 为现金券时,非空")
private Integer percentOff;
@ApiModelProperty(value = "优惠金额,单位:分")
@ApiModelProperty(value = "优惠金额,单位:分", example = "100", notes = "当 preferentialType 为折扣卷时,非空")
private Integer priceOff;
@ApiModelProperty(value = "折扣上限")
@ApiModelProperty(value = "折扣上限", example = "100", notes = "当 preferentialType 为折扣卷时,非空")
private Integer discountPriceLimit;
// ========== 使用效果 END ==========

View File

@ -0,0 +1,15 @@
package cn.iocoder.mall.managementweb.convert.promotion.coupon;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardUpdateReqVO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponCardTemplateUpdateReqDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface CouponTemplateConvert {
CouponTemplateConvert INSTANCE = Mappers.getMapper(CouponTemplateConvert.class);
CouponCardTemplateUpdateReqDTO convert(CouponTemplateCardUpdateReqVO bean);
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.mall.managementweb.manager.promotion.coupon;
import cn.iocoder.common.framework.vo.CommonResult;
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.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 org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@Service
@Validated
public class CouponTemplateManager {
@DubboReference(version = "${dubbo.consumer.CouponTemplateRpc.version}")
private CouponTemplateRpc couponTemplateRpc;
public Integer createCouponTemplateCard(CouponTemplateCardCreateReqVO createVO) {
return null;
}
public void updateCouponTemplateCard(CouponTemplateCardUpdateReqVO updateVO) {
CommonResult<Boolean> updateCouponCardTemplateResult = couponTemplateRpc.updateCouponCardTemplate(
CouponTemplateConvert.INSTANCE.convert(updateVO));
updateCouponCardTemplateResult.checkError();
}
public void updateCouponTemplateStatus(Integer id, Integer status) {
CommonResult<Boolean> updateCouponTemplateStatusResult = couponTemplateRpc.updateCouponTemplateStatus(
new CouponCardTemplateUpdateStatusReqDTO().setId(id).setStatus(status));
updateCouponTemplateStatusResult.checkError();
}
}

View File

@ -6,7 +6,7 @@ import cn.iocoder.mall.managementweb.controller.systemlog.dto.SystemAccessLogPag
import cn.iocoder.mall.managementweb.controller.systemlog.vo.SystemAccessLogVO;
import cn.iocoder.mall.managementweb.convert.systemlog.SystemAccessLogConvert;
import cn.iocoder.mall.systemservice.rpc.systemlog.SystemAccessLogRpc;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
/**
@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
@Service
public class SystemAccessLogManager {
@Reference(version = "${dubbo.consumer.SystemAccessLogRpc.version}")
@DubboReference(version = "${dubbo.consumer.SystemAccessLogRpc.version}")
private SystemAccessLogRpc systemAccessLogRpc;
/**

View File

@ -57,6 +57,8 @@ dubbo:
version: 1.0.0
ProductAttrRpc:
version: 1.0.0
CouponTemplateRpc:
version: 1.0.0
# Swagger 配置项
swagger:

View File

@ -1,58 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateStatusEnum;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.*;
public interface CouponRpc {
// ========== 优惠劵(码)模板 ==========
CouponTemplateReqDTO getCouponTemplate(Integer couponTemplateId);
CouponTemplatePageRespDTO getCouponTemplatePage(CouponTemplatePageReqDTO couponTemplatePageDTO);
/**
*
*
* @param couponCodeTemplateAddDTO DTO
* @return
*/
CouponTemplateReqDTO addCouponCodeTemplate(CouponCodeTemplateAddReqDTO couponCodeTemplateAddDTO);
/**
*
*
* @param couponCardTemplateAddDTO DTO
* @return
*/
CouponTemplateReqDTO addCouponCardTemplate(CouponCardTemplateAddReqDTO couponCardTemplateAddDTO);
/**
*
*
* @param couponCodeTemplateUpdateDTO DTO
* @return
*/
Boolean updateCouponCodeTemplate(CouponCodeTemplateUpdateReqDTO couponCodeTemplateUpdateDTO);
/**
*
*
* @param couponCardTemplateUpdateDTO DTO
* @return
*/
Boolean updateCouponCardTemplate(CouponCardTemplateUpdateReqDTO couponCardTemplateUpdateDTO);
/**
*
*
* @param adminId
* @param couponTemplateId
* @param status
* @return
*/
Boolean updateCouponTemplateStatus(Integer adminId, Integer couponTemplateId,
@InEnum(value = CouponTemplateStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
}

View File

@ -0,0 +1,57 @@
package cn.iocoder.mall.promotion.api.rpc.coupon;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.*;
/**
* Rpc
*/
public interface CouponTemplateRpc {
// ========== 通用逻辑 =========
/**
*
*
* @param couponTemplateId
* @return
*/
CommonResult<CouponTemplateRespDTO> getCouponTemplate(Integer couponTemplateId);
/**
*
*
* @param pageDTO
* @return
*/
CommonResult<PageResult<CouponTemplateRespDTO>> pageCouponTemplate(CouponTemplatePageReqDTO pageDTO);
/**
*
*
* @param updateStatusReqDTO DTO
*/
CommonResult<Boolean> updateCouponTemplateStatus(CouponCardTemplateUpdateStatusReqDTO updateStatusReqDTO);
// ========== 优惠劵模板 ==========
/**
*
*
* @param createDTO DTO
* @return
*/
CommonResult<Integer> createCouponCardTemplate(CouponCardTemplateCreateReqDTO createDTO);
/**
*
*
* @param updateDTO DTO
*/
CommonResult<Boolean> updateCouponCardTemplate(CouponCardTemplateUpdateReqDTO updateDTO);
// ========== 优惠码模板 ==========
}

View File

@ -1,40 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponRpc;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
/**
* DTO
*
* {@link CouponRpc#getCouponCardList(Integer, List)}
*/
@Data
@Accessors(chain = true)
public class CouponCardSpuRespDTO implements Serializable {
/**
* SPU
*/
private Integer spuId;
/**
* SKU
*/
private Integer skuId;
/**
*
*/
private Integer categoryId;
/**
*
*/
private Integer price;
/**
*
*/
private Integer quantity;
}

View File

@ -1,14 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* DTO
*/
@Data
@Accessors(chain = true)
public class CouponCodeTemplateAddReqDTO implements Serializable {
}

View File

@ -1,14 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* DTO
*/
@Data
@Accessors(chain = true)
public class CouponCodeTemplateUpdateReqDTO implements Serializable {
}

View File

@ -1,38 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* DTO
*/
@Data
@Accessors(chain = true)
public class CouponTemplatePageReqDTO implements Serializable {
/**
*
*/
private Integer type;
/**
*
*/
private String title;
/**
*
*/
private Integer status;
/**
*
*/
private Integer preferentialType;
@NotNull(message = "页码不能为空")
private Integer pageNo;
@NotNull(message = "每页条数不能为空")
private Integer pageSize;
}

View File

@ -1,25 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
/**
* BO
*/
@Data
@Accessors(chain = true)
public class CouponTemplatePageRespDTO implements Serializable {
/**
*
*/
private List<CouponTemplateReqDTO> list;
/**
*
*/
private Integer total;
}

View File

@ -1,155 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* BO
*/
@Data
@Accessors(chain = true)
public class CouponTemplateReqDTO implements Serializable {
// ========== 基本信息 BEGIN ==========
/**
*
*/
private Integer id;
/**
*
*/
private String title;
/**
* 使
*/
private String description;
/**
*
*
* 1-
* 2-
*/
private Integer type;
/**
*
*
* 1-UNIQUE
* 2-GENERAL
*
* @see CouponCodeDO
*/
private Integer codeType;
/**
*
*
* 1-
* 2-
* 3-
*
*
*/
private Integer status;
/**
*
*
* null -
*/
private Integer quota;
/**
*
*/
private Integer total;
// ========== 领取规则 END ==========
// ========== 使用规则 BEGIN ==========
/**
*
*
* 0-
* 0-
*/
private Integer priceAvailable;
/**
*
*
* 10-ALL
* 20-PART
* 21-PART
* 30-PART
* 31-PART
*/
private Integer rangeType;
/**
* / 使
*/
private String rangeValues;
/**
*
*
* 1-
* 2- {@link #fixedStartTerm} N
*/
private Integer dateType;
/**
* -
*/
private Date validStartTime;
/**
* -
*/
private Date validEndTime;
/**
* -
*
* 0-1-
*/
private Integer fixedStartTerm;
/**
* -
*/
private Integer fixedEndTerm;
// ========== 使用规则 END ==========
// ========== 使用效果 BEGIN ==========
/**
*
*
* 1-
* 2-
*/
private Integer preferentialType;
/**
*
*
* 80% 80
* 100% 100
*/
private Integer percentOff;
/**
*
*/
private Integer priceOff;
/**
* {@link #preferentialType} 2
*
* 20 使 8 1000 20 80
*/
private Integer discountPriceLimit;
// ========== 使用效果 END ==========
// ========== 统计信息 BEGIN ==========
/**
*
*/
private Integer statFetchNum;
// ========== 统计信息 END ==========
/**
*
*/
private Date createTime;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto;
package cn.iocoder.mall.promotion.api.rpc.coupon.dto.template;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateDateTypeEnum;
@ -16,11 +16,11 @@ import java.io.Serializable;
import java.util.Date;
/**
* DTO
* Request DTO
*/
@Data
@Accessors(chain = true)
public class CouponCardTemplateAddReqDTO implements Serializable {
public class CouponCardTemplateCreateReqDTO implements Serializable {
// ========== 基本信息 BEGIN ==========
/**

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto;
package cn.iocoder.mall.promotion.api.rpc.coupon.dto.template;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
@ -12,7 +12,7 @@ import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* DTO
* Request DTO
*/
@Data
@Accessors(chain = true)
@ -139,66 +139,4 @@ public class CouponCardTemplateUpdateReqDTO implements Serializable {
// private Integer discountPriceLimit;
// ========== 使用效果 END ==========
public Integer getId() {
return id;
}
public CouponCardTemplateUpdateReqDTO setId(Integer id) {
this.id = id;
return this;
}
public String getTitle() {
return title;
}
public CouponCardTemplateUpdateReqDTO setTitle(String title) {
this.title = title;
return this;
}
public String getDescription() {
return description;
}
public CouponCardTemplateUpdateReqDTO setDescription(String description) {
this.description = description;
return this;
}
public Integer getQuota() {
return quota;
}
public CouponCardTemplateUpdateReqDTO setQuota(Integer quota) {
this.quota = quota;
return this;
}
public Integer getTotal() {
return total;
}
public CouponCardTemplateUpdateReqDTO setTotal(Integer total) {
this.total = total;
return this;
}
public Integer getRangeType() {
return rangeType;
}
public CouponCardTemplateUpdateReqDTO setRangeType(Integer rangeType) {
this.rangeType = rangeType;
return this;
}
public String getRangeValues() {
return rangeValues;
}
public CouponCardTemplateUpdateReqDTO setRangeValues(String rangeValues) {
this.rangeValues = rangeValues;
return this;
}
}

View File

@ -0,0 +1,30 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto.template;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* Request DTO
*/
@Data
@Accessors(chain = true)
public class CouponCardTemplateUpdateStatusReqDTO implements Serializable {
/**
*
*/
@NotNull(message = "编号不能为空")
private Integer id;
/**
*
*/
@NotNull(message = "状态不能为空")
@InEnum(value = CouponTemplateStatusEnum.class, message = "状态必须是 {value}")
private Integer status;
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto.template;
import cn.iocoder.common.framework.vo.PageParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* Request DTO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class CouponTemplatePageReqDTO extends PageParam {
/**
*
*/
private Integer type;
/**
*
*/
private String title;
/**
*
*/
private Integer status;
/**
*
*/
private Integer preferentialType;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.promotionservice.convert.coupon.card;
package cn.iocoder.mall.promotionservice.convert.coupon;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableRespDTO;

View File

@ -0,0 +1,37 @@
package cn.iocoder.mall.promotionservice.convert.coupon;
import cn.iocoder.common.framework.util.StringUtils;
import cn.iocoder.common.framework.vo.PageResult;
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.CouponTemplateRespDTO;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponTemplateDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface CouponTemplateConvert {
CouponTemplateConvert INSTANCE = Mappers.getMapper(CouponTemplateConvert.class);
@Mapping(source = "rangeValues", target = "rangeValues", qualifiedByName = "translateStringToIntList")
CouponTemplateRespDTO convert(CouponTemplateDO bean);
CouponTemplateDO convert(CouponCardTemplateCreateReqDTO bean);
CouponTemplateDO convert(CouponCardTemplateUpdateReqDTO bean);
@Mapping(source = "records", target = "list")
PageResult<CouponTemplateRespDTO> convertPage(IPage<CouponTemplateDO> couponTemplatePage);
@Named("translateStringToIntList")
default List<Integer> translateStringToIntList(String str) {
return StringUtils.splitToInt(str, ",");
}
}

View File

@ -1,54 +0,0 @@
package cn.iocoder.mall.promotionservice.convert.coupon.card;
import cn.iocoder.common.framework.util.StringUtils;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.*;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponTemplateRespDTO;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponTemplateDO;
import cn.iocoder.mall.promotionservice.service.coupon.bo.CouponCardTemplateAddBO;
import cn.iocoder.mall.promotionservice.service.coupon.bo.CouponCardTemplateUpdateBO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface CouponTemplateConvert {
CouponTemplateConvert INSTANCE = Mappers.getMapper(CouponTemplateConvert.class);
// @Mappings({})
// CouponTemplateBO convertToBO(CouponTemplateDO banner);
List<CouponTemplateReqDTO> convertToDTO(List<CouponTemplateDO> templateList);
@Mappings({})
CouponTemplateDO convert(CouponCodeTemplateUpdateReqDTO template);
@Mappings({})
CouponTemplateDO convert(CouponCardTemplateAddReqDTO template);
@Mappings({})
CouponTemplateDO convert(CouponCardTemplateUpdateReqDTO template);
@Mappings({})
CouponTemplateDO convert(CouponCodeTemplateAddReqDTO template);
@Mappings({})
CouponTemplateDO convert(CouponCardTemplateAddBO template);
@Mappings({})
CouponTemplateDO convert(CouponCardTemplateUpdateBO template);
@Mapping(source = "rangeValues", target = "rangeValues", qualifiedByName = "translateStringToIntList")
CouponTemplateRespDTO convert(CouponTemplateDO bean);
@Named("translateStringToIntList")
default List<Integer> translateStringToIntList(String str) {
return StringUtils.splitToInt(str, ",");
}
}

View File

@ -1,7 +1,11 @@
package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon;
import cn.iocoder.mall.mybatis.core.dataobject.BaseDO;
import cn.iocoder.mall.promotion.api.enums.PreferentialTypeEnum;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateDateTypeEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateStatusEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateTypeEnum;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -36,6 +40,8 @@ public class CouponTemplateDO extends BaseDO {
/**
*
*
* {@link CouponTemplateTypeEnum}
*
* 1-
* 2-
*/
@ -43,7 +49,7 @@ public class CouponTemplateDO extends BaseDO {
/**
*
*
* {@link CouponTemplateStatusEnum}
* {@link CouponTemplateStatusEnum}
*
*
*/
@ -103,6 +109,8 @@ public class CouponTemplateDO extends BaseDO {
/**
*
*
* {@link RangeTypeEnum}
*
* 10-ALL
* 20-PART
* 21-PART
@ -117,6 +125,8 @@ public class CouponTemplateDO extends BaseDO {
/**
*
*
* {@link CouponTemplateDateTypeEnum}
*
* 1-
* 2- {@link #fixedStartTerm} N
*/
@ -152,6 +162,8 @@ public class CouponTemplateDO extends BaseDO {
/**
*
*
* {@link PreferentialTypeEnum}
*
* 1-
* 2-
*/

View File

@ -1,26 +1,24 @@
package cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon;
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponTemplatePageReqDTO;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponTemplateDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface CouponTemplateMapper extends BaseMapper<CouponTemplateDO> {
List<CouponTemplateDO> selectListByPage(@Param("type") Integer type,
@Param("title") String title,
@Param("status") Integer status,
@Param("preferentialType") Integer preferentialType,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByPage(@Param("type") Integer type,
@Param("title") String title,
@Param("status") Integer status,
@Param("preferentialType") Integer preferentialType);
default IPage<CouponTemplateDO> selectPage(CouponTemplatePageReqDTO pageReqDTO) {
return selectPage(new Page<>(pageReqDTO.getPageNo(), pageReqDTO.getPageSize()),
new QueryWrapperX<CouponTemplateDO>().eqIfPresent("type", pageReqDTO.getType())
.likeIfPresent("title", pageReqDTO.getTitle())
.eqIfPresent("status", pageReqDTO.getStatus())
.eqIfPresent("preferential_type", pageReqDTO.getPreferentialType()));
}
/**
*

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.promotionservice.manager.coupon.card;
package cn.iocoder.mall.promotionservice.manager.coupon;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.*;

View File

@ -0,0 +1,43 @@
package cn.iocoder.mall.promotionservice.manager.coupon;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.*;
import cn.iocoder.mall.promotionservice.service.coupon.CouponTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Manager
*/
@Service
public class CouponTemplateManager {
@Autowired
private CouponTemplateService couponTemplateService;
// ========== 通用逻辑 =========
public CouponTemplateRespDTO getCouponTemplate(Integer couponTemplateId) {
return couponTemplateService.getCouponTemplate(couponTemplateId);
}
public PageResult<CouponTemplateRespDTO> pageCouponTemplate(CouponTemplatePageReqDTO pageDTO) {
return couponTemplateService.pageCouponTemplate(pageDTO);
}
public void updateCouponTemplateStatus(CouponCardTemplateUpdateStatusReqDTO updateStatusReqDTO) {
couponTemplateService.updateCouponTemplateStatus(updateStatusReqDTO.getId(), updateStatusReqDTO.getStatus());
}
// ========== 优惠劵模板 ==========
public Integer createCouponCardTemplate(CouponCardTemplateCreateReqDTO createDTO) {
return couponTemplateService.createCouponCardTemplate(createDTO);
}
public void updateCouponCardTemplate(CouponCardTemplateUpdateReqDTO updateDTO) {
couponTemplateService.updateCouponCardTemplate(updateDTO);
}
}

View File

@ -4,7 +4,7 @@ import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponCardRpc;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.*;
import cn.iocoder.mall.promotionservice.manager.coupon.card.CouponCardManager;
import cn.iocoder.mall.promotionservice.manager.coupon.CouponCardManager;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -0,0 +1,50 @@
package cn.iocoder.mall.promotionservice.rpc.coupon;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponTemplateRpc;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.*;
import cn.iocoder.mall.promotionservice.manager.coupon.CouponTemplateManager;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@DubboService
public class CouponTemplateRpcImpl implements CouponTemplateRpc {
@Autowired
private CouponTemplateManager couponTemplateManager;
// ========== 通用逻辑 =========
@Override
public CommonResult<CouponTemplateRespDTO> getCouponTemplate(Integer couponTemplateId) {
return success(couponTemplateManager.getCouponTemplate(couponTemplateId));
}
@Override
public CommonResult<PageResult<CouponTemplateRespDTO>> pageCouponTemplate(CouponTemplatePageReqDTO pageDTO) {
return success(couponTemplateManager.pageCouponTemplate(pageDTO));
}
@Override
public CommonResult<Boolean> updateCouponTemplateStatus(CouponCardTemplateUpdateStatusReqDTO updateStatusReqDTO) {
couponTemplateManager.updateCouponTemplateStatus(updateStatusReqDTO);
return success(true);
}
// ========== 优惠劵模板 ==========
@Override
public CommonResult<Integer> createCouponCardTemplate(CouponCardTemplateCreateReqDTO createDTO) {
return success(couponTemplateManager.createCouponCardTemplate(createDTO));
}
@Override
public CommonResult<Boolean> updateCouponCardTemplate(CouponCardTemplateUpdateReqDTO updateDTO) {
couponTemplateManager.updateCouponCardTemplate(updateDTO);
return success(true);
}
}

View File

@ -16,7 +16,7 @@ import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableList
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableRespDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardPageReqDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardRespDTO;
import cn.iocoder.mall.promotionservice.convert.coupon.card.CouponCardConvert;
import cn.iocoder.mall.promotionservice.convert.coupon.CouponCardConvert;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponCardDO;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponTemplateDO;
import cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon.CouponCardMapper;
@ -42,6 +42,13 @@ public class CouponCardService {
@Autowired
private CouponTemplateMapper couponTemplateMapper;
/**
*
*
* @param userId
* @param couponCardId
* @return
*/
public CouponCardRespDTO getCouponCard(Integer userId, Integer couponCardId) {
CouponCardDO card = couponCardMapper.selectById(couponCardId);
if (card == null) {

View File

@ -1,153 +0,0 @@
package cn.iocoder.mall.promotionservice.service.coupon;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateStatusEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateTypeEnum;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.CouponTemplatePageReqDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.CouponTemplatePageRespDTO;
import cn.iocoder.mall.promotionservice.convert.coupon.card.CouponTemplateConvert;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponTemplateDO;
import cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon.CouponCardMapper;
import cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon.CouponTemplateMapper;
import cn.iocoder.mall.promotionservice.service.coupon.bo.CouponCardTemplateAddBO;
import cn.iocoder.mall.promotionservice.service.coupon.bo.CouponCardTemplateUpdateBO;
import cn.iocoder.mall.promotionservice.service.coupon.bo.CouponCodeTemplateUpdateBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.Date;
@Service
@Validated
public class CouponService {
@Autowired
private CouponTemplateMapper couponTemplateMapper;
@Autowired
private CouponCardMapper couponCardMapper;
// ========== 优惠劵(码)模板 ==========
public CouponTemplatePageRespDTO getCouponTemplatePage(CouponTemplatePageReqDTO couponTemplatePageDTO) {
CouponTemplatePageRespDTO couponTemplatePageBO = new CouponTemplatePageRespDTO();
// 查询分页数据
int offset = (couponTemplatePageDTO.getPageNo() - 1) * couponTemplatePageDTO.getPageSize();
couponTemplatePageBO.setList(CouponTemplateConvert.INSTANCE.convertToDTO(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;
}
public Integer addCouponCardTemplate(CouponCardTemplateAddBO 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 template.getId();
}
public Boolean updateCouponCodeTemplate(CouponCodeTemplateUpdateBO couponCodeTemplateUpdateDTO) {
return null;
}
public Boolean updateCouponCardTemplate(CouponCardTemplateUpdateBO couponCardTemplateUpdateDTO) {
// 校验 CouponCardTemplate 存在
CouponTemplateDO template = couponTemplateMapper.selectById(couponCardTemplateUpdateDTO.getId());
if (template == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_EXISTS.getCode());
}
// 校验 CouponCardTemplate 是 CARD
if (!CouponTemplateTypeEnum.CARD.getValue().equals(template.getType())) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_CARD.getCode());
}
// 校验发放数量不能减少
if (couponCardTemplateUpdateDTO.getTotal() < template.getTotal()) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_TOTAL_CAN_NOT_REDUCE.getCode());
}
// 更新优惠劵模板到数据库
CouponTemplateDO updateTemplateDO = CouponTemplateConvert.INSTANCE.convert(couponCardTemplateUpdateDTO);
couponTemplateMapper.updateById(updateTemplateDO);
// 返回成功
return true;
}
public Boolean updateCouponTemplateStatus(Integer adminId, Integer couponTemplateId, Integer status) {
// 校验 CouponCardTemplate 存在
CouponTemplateDO template = couponTemplateMapper.selectById(couponTemplateId);
if (template == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_EXISTS.getCode());
}
// 更新到数据库
CouponTemplateDO updateTemplateDO = new CouponTemplateDO().setId(couponTemplateId).setStatus(status);
couponTemplateMapper.updateById(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;
}
// ========== 优惠劵 ==========
}

View File

@ -1,12 +1,28 @@
package cn.iocoder.mall.promotionservice.service.coupon;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.enums.PreferentialTypeEnum;
import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateDateTypeEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateStatusEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateTypeEnum;
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;
import cn.iocoder.mall.promotionservice.convert.coupon.card.CouponTemplateConvert;
import cn.iocoder.mall.promotionservice.convert.coupon.CouponTemplateConvert;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponTemplateDO;
import cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon.CouponTemplateMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.Date;
import static cn.iocoder.common.framework.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST;
/**
* Service
*/
@ -17,8 +33,141 @@ public class CouponTemplateService {
@Autowired
private CouponTemplateMapper couponTemplateMapper;
// ========== 通用逻辑 =========
/**
*
*
* @param couponCardId
* @return
*/
public CouponTemplateRespDTO getCouponTemplate(Integer couponCardId) {
return CouponTemplateConvert.INSTANCE.convert(couponTemplateMapper.selectById(couponCardId));
}
/**
*
*
* @param pageDTO
* @return
*/
public PageResult<CouponTemplateRespDTO> pageCouponTemplate(CouponTemplatePageReqDTO pageDTO) {
IPage<CouponTemplateDO> couponTemplatePage = couponTemplateMapper.selectPage(pageDTO);
return CouponTemplateConvert.INSTANCE.convertPage(couponTemplatePage);
}
/**
*
*
* @param couponTemplateId
* @param status
*/
public void updateCouponTemplateStatus(Integer couponTemplateId, Integer status) {
// 校验 CouponCardTemplate 存在
CouponTemplateDO template = couponTemplateMapper.selectById(couponTemplateId);
if (template == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_EXISTS.getCode());
}
// 更新到数据库
CouponTemplateDO updateTemplateDO = new CouponTemplateDO().setId(couponTemplateId).setStatus(status);
couponTemplateMapper.updateById(updateTemplateDO);
}
private Boolean checkCouponTemplateDateType(Integer dateType, Date validStartTime, Date validEndTime, Integer fixedBeginTerm, Integer fixedEndTerm) {
// TODO 芋艿:后续这种类型的校验,看看怎么优化到对象里
if (CouponTemplateDateTypeEnum.FIXED_DATE.getValue().equals(dateType)) { // 固定日期
if (validStartTime == null) {
throw ServiceExceptionUtil.exception(BAD_REQUEST, "生效开始时间不能为空");
}
if (validEndTime == null) {
throw ServiceExceptionUtil.exception(BAD_REQUEST, "生效结束时间不能为空");
}
if (validStartTime.after(validEndTime)) {
throw ServiceExceptionUtil.exception(BAD_REQUEST, "生效开始时间不能大于生效结束时间");
}
} else if (CouponTemplateDateTypeEnum.FIXED_TERM.getValue().equals(dateType)) { // 领取日期
if (fixedBeginTerm == null) {
throw ServiceExceptionUtil.exception(BAD_REQUEST, "领取日期开始时间不能为空");
}
if (fixedEndTerm == null) {
throw ServiceExceptionUtil.exception(BAD_REQUEST, "领取日期结束时间不能为空");
}
} 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(BAD_REQUEST, "优惠金额不能为空");
}
if (priceOff >= priceAvailable) {
throw ServiceExceptionUtil.exception(BAD_REQUEST, "优惠金额不能d大于等于使用金额门槛");
}
} else if (PreferentialTypeEnum.DISCOUNT.getValue().equals(preferentialType)) {
if (percentOff == null) {
throw ServiceExceptionUtil.exception(BAD_REQUEST, "折扣百分比不能为空");
}
} else {
throw new IllegalArgumentException("未知的优惠类型:" + preferentialType);
}
return true;
}
// ========== 优惠劵模板 ==========
/**
*
*
* @param createReqDTO
* @return
*/
public Integer createCouponCardTemplate(CouponCardTemplateCreateReqDTO createReqDTO) {
// 校验生效日期相关
checkCouponTemplateDateType(createReqDTO.getDateType(),
createReqDTO.getValidStartTime(), createReqDTO.getValidEndTime(),
createReqDTO.getFixedBeginTerm(), createReqDTO.getFixedEndTerm());
// 校验优惠类型
checkCouponTemplatePreferentialType(createReqDTO.getPreferentialType(), createReqDTO.getPercentOff(),
createReqDTO.getPriceOff(), createReqDTO.getPriceAvailable());
// 保存优惠劵模板到数据库
CouponTemplateDO template = CouponTemplateConvert.INSTANCE.convert(createReqDTO)
.setType(CouponTemplateTypeEnum.CARD.getValue())
.setStatus(CouponTemplateStatusEnum.ENABLE.getValue())
.setStatFetchNum(0);
couponTemplateMapper.insert(template);
// 返回成功
return template.getId();
}
/**
*
*
* @param updateReqDTO
*/
public void updateCouponCardTemplate(CouponCardTemplateUpdateReqDTO updateReqDTO) {
// 校验 CouponCardTemplate 存在
CouponTemplateDO template = couponTemplateMapper.selectById(updateReqDTO.getId());
if (template == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_EXISTS.getCode());
}
// 校验 CouponCardTemplate 是 CARD
if (!CouponTemplateTypeEnum.CARD.getValue().equals(template.getType())) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_CARD.getCode());
}
// 校验发放数量不能减少
if (updateReqDTO.getTotal() < template.getTotal()) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_TOTAL_CAN_NOT_REDUCE.getCode());
}
// 更新优惠劵模板到数据库
CouponTemplateDO updateTemplateDO = CouponTemplateConvert.INSTANCE.convert(updateReqDTO);
couponTemplateMapper.updateById(updateTemplateDO);
}
// ========== 优惠码模板 TODO 芋艿:以后开发 ==========
}

View File

@ -1,140 +0,0 @@
package cn.iocoder.mall.promotionservice.service.coupon.bo;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateDateTypeEnum;
import cn.iocoder.mall.promotion.api.enums.PreferentialTypeEnum;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
/**
* DTO
*/
@Data
@Accessors(chain = true)
public class CouponCardTemplateAddBO implements Serializable {
// ========== 基本信息 BEGIN ==========
/**
*
*/
@NotEmpty(message = "标题不能为空")
private String title;
/**
* 使
*/
private String description;
// ========== 基本信息 END ==========
// ========== 领取规则 BEGIN ==========
/**
*
*/
@NotNull(message = "每人限领个数不能为空")
@Min(value = 1, message = "每人限领个数最小为 {value}")
private Integer quota;
/**
*
*/
@NotNull(message = "发放总量不能为空")
@Min(value = 1, message = "每人限领个数最小为 {value}")
private Integer total;
// ========== 领取规则 END ==========
// ========== 使用规则 BEGIN ==========
/**
*
*
* 0-
* 0-
*/
@NotNull(message = "使用金额门槛不能为空")
@Min(value = 0L, message = "使用金额门槛最低为 {value}")
private Integer priceAvailable;
/**
*
*
* 10-ALL
* 20-PART
* 21-PART
* 30-PART
* 31-PART
*/
@NotNull(message = "可用范围的类型不能为空")
@InEnum(value = RangeTypeEnum.class, message = "可用范围的类型必须在 {value}")
private Integer rangeType;
/**
* / 使
*/
private String rangeValues;
/**
*
*
* 1-
* 2- {@link #fixedEndTerm} N
*/
@NotNull(message = "生效日期类型不能为空")
@InEnum(value = CouponTemplateDateTypeEnum.class, message = "生效日期类型必须在 {value}")
private Integer dateType;
/**
* -
*/
private Date validStartTime;
/**
* -
*/
private Date validEndTime;
/**
* -
*
* 0-1-
*/
@Min(value = 0L, message = "领取日期开始时间最小为 {value}")
private Integer fixedBeginTerm;
/**
* -
*/
@Min(value = 1L, message = "领取日期结束时间最小为 {value}")
private Integer fixedEndTerm;
// ========== 使用规则 END ==========
// ========== 使用效果 BEGIN ==========
/**
*
*
* 1-
* 2-
*/
@NotNull(message = "优惠类型不能为空")
@InEnum(value = PreferentialTypeEnum.class, message = "优惠类型必须在 {value}")
private Integer preferentialType;
/**
*
*/
@Min(value = 1, message = "优惠金额最小值为 {value}")
private Integer priceOff;
/**
*
*
* 80% 80
* 100% 100
*/
@Max(value = 100, message = "折扣比最大值为 {value}")
private Integer percentOff;
/**
* {@link #preferentialType} 2
*
* 20 使 8 1000 20 80
*/
@Min(value = 1, message = "折扣上限最小值为 {value}")
private Integer discountPriceLimit;
// ========== 使用效果 END ==========
}

View File

@ -1,201 +0,0 @@
package cn.iocoder.mall.promotionservice.service.coupon.bo;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* DTO
*/
@Data
@Accessors(chain = true)
public class CouponCardTemplateUpdateBO implements Serializable {
@NotNull(message = "编号不能为空")
private Integer id;
// ========== 基本信息 BEGIN ==========
/**
*
*/
@NotEmpty(message = "标题不能为空")
private String title;
/**
* 使
*/
private String description;
// ========== 基本信息 END ==========
// ========== 领取规则 BEGIN ==========
/**
*
*/
@NotNull(message = "每人限领个数不能为空")
@Min(value = 1, message = "每人限领个数最小为 {value}")
private Integer quota;
/**
*
*/
@NotNull(message = "发放总量不能为空")
@Min(value = 1, message = "每人限领个数最小为 {value}")
private Integer total;
// ========== 领取规则 END ==========
// ========== 使用规则 BEGIN ==========
// /**
// * 是否设置满多少金额可用,单位:分
// *
// * 0-不限制
// * 大于0-多少金额可用
// */
// @NotNull(message = "使用金额门槛不能为空")
// @Min(value = 0L, message = "使用金额门槛最低为 {value}")
// private Integer priceAvailable;
/**
*
*
* 10-ALL
* 20-PART
* 21-PART
* 30-PART
* 31-PART
*/
@NotNull(message = "可用范围的类型不能为空")
@InEnum(value = RangeTypeEnum.class, message = "可用范围的类型必须在 {value}")
private Integer rangeType;
/**
* / 使
*/
private String rangeValues;
// /**
// * 生效日期类型
// *
// * 1-固定日期
// * 2-领取日期:领到券 {@link #fixedEndTerm} 日开始 N 天内有效
// */
// @NotNull(message = "生效日期类型不能为空")
// @InEnum(value = CouponTemplateDateTypeEnum.class, message = "生效日期类型必须在 {value}")
// private Integer dateType;
// /**
// * 固定日期-生效开始时间
// */
// private Date validStartTime;
// /**
// * 固定日期-生效结束时间
// */
// private Date validEndTime;
// /**
// * 领取日期-开始天数
// *
// * 例如0-当天1-次天
// */
// @Min(value = 0L, message = "领取日期开始时间最小为 {value}")
// private Integer fixedBeginTerm;
// /**
// * 领取日期-结束天数
// */
// @Min(value = 1L, message = "领取日期结束时间最小为 {value}")
// private Integer fixedEndTerm;
// ========== 使用规则 END ==========
// ========== 使用效果 BEGIN ==========
// /**
// * 优惠类型
// *
// * 1-代金卷
// * 2-折扣卷
// */
// @NotNull(message = "优惠类型不能为空")
// @InEnum(value = CouponTemplatePreferentialTypeEnum.class, message = "优惠类型必须在 {value}")
// private Integer preferentialType;
// /**
// * 优惠金额,单位:分
// */
// @Min(value = 1, message = "优惠金额最小值为 {value}")
// private Integer priceOff;
// /**
// * 折扣百分比。
// *
// * 例如80% 为 80。
// * 当 100% 为 100 ,则代表免费。
// */
// @Max(value = 100, message = "折扣比最大值为 {value}")
// private Integer percentOff;
// /**
// * 折扣上限,仅在 {@link #preferentialType} 等于 2 时生效。
// *
// * 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。
// */
// @Min(value = 1, message = "折扣上限最小值为 {value}")
// private Integer discountPriceLimit;
// ========== 使用效果 END ==========
public Integer getId() {
return id;
}
public CouponCardTemplateUpdateBO setId(Integer id) {
this.id = id;
return this;
}
public String getTitle() {
return title;
}
public CouponCardTemplateUpdateBO setTitle(String title) {
this.title = title;
return this;
}
public String getDescription() {
return description;
}
public CouponCardTemplateUpdateBO setDescription(String description) {
this.description = description;
return this;
}
public Integer getQuota() {
return quota;
}
public CouponCardTemplateUpdateBO setQuota(Integer quota) {
this.quota = quota;
return this;
}
public Integer getTotal() {
return total;
}
public CouponCardTemplateUpdateBO setTotal(Integer total) {
this.total = total;
return this;
}
public Integer getRangeType() {
return rangeType;
}
public CouponCardTemplateUpdateBO setRangeType(Integer rangeType) {
this.rangeType = rangeType;
return this;
}
public String getRangeValues() {
return rangeValues;
}
public CouponCardTemplateUpdateBO setRangeValues(String rangeValues) {
this.rangeValues = rangeValues;
return this;
}
}

View File

@ -1,14 +0,0 @@
package cn.iocoder.mall.promotionservice.service.coupon.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* DTO
*/
@Data
@Accessors(chain = true)
public class CouponCodeTemplateUpdateBO implements Serializable {
}

View File

@ -1,26 +0,0 @@
package cn.iocoder.mall.promotionservice.service.coupon.bo;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.CouponTemplateReqDTO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
/**
* BO
*/
@Data
@Accessors(chain = true)
public class CouponTemplatePageBO implements Serializable {
/**
*
*/
private List<CouponTemplateReqDTO> list;
/**
*
*/
private Integer total;
}

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>promotion</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>promotion-application</artifactId>
<dependencies>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-biz</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-rpc</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>promotion</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>promotion-biz-api</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>common-framework</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -1,53 +0,0 @@
package cn.iocoder.mall.promotion.biz.api.enums;
/**
*
*
* 使 1-006-000-000
*/
public enum PromotionErrorCodeEnum {
// ========== Banner 模块 ==========
BANNER_NOT_EXISTS(1006000000, "账号不存在"),
// // ========== PRODUCT RECOMMEND 模块 ==========
// PRODUCT_RECOMMEND_NOT_EXISTS(1006001000, "商品推荐不存在"),
// PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS(1006001001, "商品不存在"),
// PRODUCT_RECOMMEND_EXISTS(1006001002, "该商品推荐已经存在"),
//
//
// // ========== COUPON TEMPLATE 模块 ==========
// COUPON_TEMPLATE_NOT_EXISTS(1006002000, "优惠劵模板(码)不存在"),
// COUPON_TEMPLATE_NOT_CARD(1006002001, "不是优惠劵模板"),
// COUPON_TEMPLATE_NOT_CODE(1006002002, "不是优惠码模板"),
// COUPON_TEMPLATE_TOTAL_CAN_NOT_REDUCE(1006002003, "优惠劵(码)模板的发放数量不能减小"),
// COUPON_TEMPLATE_STATUS_NOT_ENABLE(1006002004, "优惠劵模板(码)未开启"),
// COUPON_TEMPLATE_TOTAL_NOT_ENOUGH(1006002005, "优惠劵(码)模板的发放量不足"),
// COUPON_TEMPLATE_CARD_ADD_EXCEED_QUOTA(1006002006, "优惠劵领取到达上限"),
//
// // ========== COUPON CARD 模块 ==========
// COUPON_CARD_NOT_EXISTS(1006003000, "优惠劵不存在"),
// COUPON_CARD_ERROR_USER(1006003001, "优惠劵不属于当前用户"),
// COUPON_CARD_NOT_MATCH(1006003002, "优惠劵不匹配,无法使用"),
// COUPON_CARD_STATUS_NOT_UNUSED(1006003003, "优惠劵不处于待使用状态"),
// COUPON_CARD_STATUS_NOT_USED(1006003004, "优惠劵不处于已使用状态"),
;
private final int code;
private final String message;
PromotionErrorCodeEnum(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
}

View File

@ -1,5 +0,0 @@
/**
* author: sin
* time: 2020/5/14 15:25
*/
package cn.iocoder.mall.promotion.biz.api;

View File

@ -1,83 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>promotion</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>promotion-biz</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-biz-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- Spring 核心 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- DB 相关 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-mybatis</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 短信平台 阿里云、云片 -->
<dependency>
<groupId>com.yunpian.sdk</groupId>
<artifactId>yunpian-java-sdk</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
</dependency>
<!-- 文件服务商 -->
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
</dependency>
<!-- 工具类相关 -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher -->
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,51 +0,0 @@
package cn.iocoder.mall.promotion.biz.bo.banner;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* bannerlist
*
* author: sin
* time: 2020/5/14 16:00
*/
@Data
@Accessors(chain = true)
// TODO FROM 芋艿 to 小范:捉摸是不是先统一的 BannerBO另外biz 不使用 swagger 注解哈,其他 banner 的 dto 和 bo 也一起改改哈;
public class BannerListBO implements Serializable {
@ApiModelProperty("编号")
private Integer id;
@ApiModelProperty("标题")
private String title;
@ApiModelProperty("跳转链接")
private String url;
@ApiModelProperty("图片链接")
private String picUrl;
@ApiModelProperty("排序")
private Integer sort;
@ApiModelProperty("状态")
private Integer status;
@ApiModelProperty("备注")
private String memo;
//
// 其他
@ApiModelProperty("更新时间")
private Date updatedTime;
@ApiModelProperty("创建时间")
private Date createdTime;
}

View File

@ -1,35 +0,0 @@
package cn.iocoder.mall.promotion.biz.bo.banner;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* banner - banner
*
* author: sin
* time: 2020/5/14 16:56
*/
@Data
@Accessors(chain = true)
public class BannerListOnReleaseBO implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private String title;
/**
*
*/
private String url;
/**
*
*/
private String picUrl;
}

View File

@ -1,5 +0,0 @@
/**
* author: sin
* time: 2020/5/14 16:46
*/
package cn.iocoder.mall.promotion.biz.bo;

View File

@ -1,26 +0,0 @@
package cn.iocoder.mall.promotion.biz.convert;
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListBO;
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListOnReleaseBO;
import cn.iocoder.mall.promotion.biz.dataobject.BannerDO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerAddDTO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerUpdateDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface BannerConvert {
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class);
List<BannerListBO> convert(List<BannerDO> bannerDO);
List<BannerListOnReleaseBO> convertToBO(List<BannerListBO> bannerList);
BannerDO convert(BannerAddDTO bannerAddDTO);
BannerDO convert(BannerUpdateDTO bannerUpdateDTO);
}

View File

@ -1,45 +0,0 @@
package cn.iocoder.mall.promotion.biz.dao;
import cn.iocoder.mall.promotion.biz.dataobject.BannerDO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerListDTO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
/**
* banner
*
* author: sin
* time: 2020/5/14 14:19
*/
@Repository
@Mapper
public interface BannerMapper extends BaseMapper<BannerDO> {
/**
* -
*
* @param dto
* @return
*/
// TODO FROM 芋艿 to 小范Page 方法哈
default IPage<BannerDO> selectBannerList(BannerListDTO dto) {
LambdaQueryWrapper<BannerDO> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isEmpty(dto.getStatus())) {
queryWrapper.eq(BannerDO::getStatus, dto.getStatus());
}
if (StringUtils.isEmpty(dto.getTitle())) {
queryWrapper.like(BannerDO::getTitle, dto.getTitle());
}
queryWrapper.orderByDesc(BannerDO::getId);
IPage<BannerDO> result = selectPage(new Page<>(), queryWrapper);
return result;
}
}

View File

@ -1,47 +0,0 @@
package cn.iocoder.mall.promotion.biz.dataobject;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* Banner 广
*/
@Data
@Accessors(chain = true)
public class BannerDO extends DeletableDO {
/**
*
*/
private Integer id;
/**
*
*/
private String title;
/**
*
*/
private String url;
/**
*
*/
private String picUrl;
/**
*
*/
private Integer sort;
/**
*
*
* {@link cn.iocoder.common.framework.enums.CommonStatusEnum}
*/
private Integer status;
/**
*
*/
private String memo;
// TODO 芋艿 点击次数。&& 其他数据相关
}

View File

@ -1,41 +0,0 @@
package cn.iocoder.mall.promotion.biz.dto.banner;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* Banner DTO
*/
@Data
@Accessors(chain = true)
public class BannerAddDTO implements Serializable {
@NotNull
private Integer adminId;
@NotEmpty(message = "标题不能为空")
@Length(min = 2, max = 32, message = "标题长度为 2-32 位")
private String title;
@NotEmpty(message = "跳转链接不能为空")
@URL(message = "跳转链接格式不正确")
@Length(max = 255, message = "跳转链接最大长度为 255 位")
private String url;
@NotEmpty(message = "图片链接不能为空")
@URL(message = "图片链接格式不正确")
@Length(max = 255, message = "图片链接最大长度为 255 位")
private String picUrl;
@NotNull(message = "排序不能为空")
private Integer sort;
@Length(max = 255, message = "备注最大长度为 255 位")
private String memo;
}

View File

@ -1,26 +0,0 @@
package cn.iocoder.mall.promotion.biz.dto.banner;
import cn.iocoder.common.framework.vo.PageParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* Banner DTO
*/
@Data
@Accessors(chain = true)
public class BannerListDTO extends PageParam {
@ApiModelProperty("标题")
@NotNull(message = "页码不能为空")
private String title;
@ApiModelProperty("标题")
@NotNull(message = "页码不能为空")
private Integer status;
}

View File

@ -1,45 +0,0 @@
package cn.iocoder.mall.promotion.biz.dto.banner;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* Banner DTO
*/
@Data
@Accessors(chain = true)
public class BannerUpdateDTO implements Serializable {
@NotNull
Integer adminId;
@NotNull(message = "编号不能为空")
private Integer id;
@NotEmpty(message = "标题不能为空")
@Length(min = 2, max = 32, message = "标题长度为 2-32 位")
private String title;
@NotEmpty(message = "跳转链接不能为空")
@URL(message = "跳转链接格式不正确")
@Length(max = 255, message = "跳转链接最大长度为 255 位")
private String url;
@NotEmpty(message = "图片链接不能为空")
@URL(message = "图片链接格式不正确")
@Length(max = 255, message = "图片链接最大长度为 255 位")
private String picUrl;
@NotNull(message = "排序不能为空")
private Integer sort;
@Length(max = 255, message = "备注最大长度为 255 位")
private String memo;
}

View File

@ -1,5 +0,0 @@
/**
* author: sin
* time: 2020/5/14 16:46
*/
package cn.iocoder.mall.promotion.biz.dto;

View File

@ -1,6 +0,0 @@
/**
* author: sin
* time: 2020/5/14 14:19
*/
package cn.iocoder.mall.promotion.biz;

View File

@ -1,69 +0,0 @@
package cn.iocoder.mall.promotion.biz.service.banner;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListBO;
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListOnReleaseBO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerAddDTO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerListDTO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerUpdateDTO;
import java.util.List;
/**
* banner
*
* author: sin
* time: 2020/5/14 14:19
*/
public interface BannerService {
/**
* - banner
*
* @return
*/
List<BannerListOnReleaseBO> listBannerOnRelease();
/**
* - banner
*
* @param bannerPageDTO
* @return
*/
PageResult<BannerListBO> listBanner(BannerListDTO bannerPageDTO);
/**
* - banner
*
* @param adminsBannerAddDTO
*/
void addBanner(BannerAddDTO adminsBannerAddDTO);
/**
* - id
*
* @param adminsBannerUpdateDTO
*/
void updateBanner(BannerUpdateDTO adminsBannerUpdateDTO);
// TODO FROM 芋艿 to 小范:貌似要把 dto 搞起来,嘿嘿;
/**
* - banner
*
* @param adminId
* @param bannerId
* @param status
* @return
*/
void updateBannerStatus(Integer adminId, Integer bannerId, @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
/**
* - idbanner
*
* @param adminId
* @param bannerId
*/
void deleteBanner(Integer adminId, Integer bannerId);
}

View File

@ -1,105 +0,0 @@
package cn.iocoder.mall.promotion.biz.service.banner;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum;
import cn.iocoder.mall.promotion.biz.api.enums.PromotionErrorCodeEnum;
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListBO;
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListOnReleaseBO;
import cn.iocoder.mall.promotion.biz.convert.BannerConvert;
import cn.iocoder.mall.promotion.biz.dao.BannerMapper;
import cn.iocoder.mall.promotion.biz.dataobject.BannerDO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerAddDTO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerListDTO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerUpdateDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* banner
*
* author: sin
* time: 2020/5/14 14:19
*/
@Service
public class BannerServiceImpl implements BannerService {
@Autowired
private BannerMapper bannerMapper;
@Override
public List<BannerListOnReleaseBO> listBannerOnRelease() {
PageResult<BannerListBO> pageResult = this.listBanner(
(BannerListDTO) new BannerListDTO()
.setStatus(CommonStatusEnum.ENABLE.getValue())
.setTitle(null)
.setPageNo(1)
.setPageSize(10)
);
return BannerConvert.INSTANCE.convertToBO(pageResult.getList());
}
@Override
public PageResult<BannerListBO> listBanner(BannerListDTO dto) {
IPage<BannerDO> page = bannerMapper.selectBannerList(dto);
List<BannerListBO> list = BannerConvert.INSTANCE.convert(page.getRecords());
return new PageResult<BannerListBO>().setList(list).setTotal(page.getTotal());
}
@Override
public void addBanner(BannerAddDTO adminsBannerAddDTO) {
// 转换DO
BannerDO banner = BannerConvert.INSTANCE.convert(adminsBannerAddDTO);
// 设置默认数据
banner.setStatus(CommonStatusEnum.ENABLE.getValue());
banner.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
banner.setCreateTime(new Date());
// 保存数据
bannerMapper.insert(banner);
}
@Override
public void updateBanner(BannerUpdateDTO adminsBannerUpdateDTO) {
// 校验 Banner 存在
if (bannerMapper.selectById(adminsBannerUpdateDTO.getId()) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = BannerConvert.INSTANCE.convert(adminsBannerUpdateDTO);
updateBanner.setUpdateTime(new Date());
bannerMapper.updateById(updateBanner);
}
@Override
public void updateBannerStatus(Integer adminId, Integer bannerId, Integer status) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerId) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = new BannerDO();
updateBanner.setId(bannerId);
updateBanner.setStatus(status);
updateBanner.setUpdateTime(new Date());
bannerMapper.updateById(updateBanner);
}
@Override
public void deleteBanner(Integer adminId, Integer bannerId) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerId) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = new BannerDO();
updateBanner.setId(bannerId);
updateBanner.setUpdateTime(new Date());
updateBanner.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
bannerMapper.updateById(updateBanner);
}
}

View File

@ -1,5 +0,0 @@
/**
* author: sin
* time: 2020/5/14 16:47
*/
package cn.iocoder.mall.promotion.biz.service;

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>promotion</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>promotion-rest</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-biz</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- Web 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-web</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-security</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-swagger</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -1,84 +0,0 @@
package cn.iocoder.mall.promotion.rest.controller.banner;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListBO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerAddDTO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerListDTO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerUpdateDTO;
import cn.iocoder.mall.promotion.biz.service.banner.BannerService;
import cn.iocoder.mall.promotion.rest.convert.BannerConvert;
import cn.iocoder.mall.promotion.rest.request.banner.BannerAddRequest;
import cn.iocoder.mall.promotion.rest.request.banner.BannerListRequest;
import cn.iocoder.mall.promotion.rest.request.banner.BannerUpdateRequest;
import cn.iocoder.mall.promotion.rest.request.banner.BannerUpdateStatusRequest;
import cn.iocoder.mall.promotion.rest.response.banner.BannerListResponse;
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* Banner(API)
*
* author: sin
* time: 2020/5/14 15:27
*/
@RestController
@RequestMapping("/admins/banner")
@Api(tags = "Banner(管理员API)")
public class AdminsBannerController {
@Autowired
private BannerService bannerService;
@PostMapping("/list")
@ApiOperation(value = "列表-banner列表")
public CommonResult<PageResult<BannerListResponse>> page(@RequestBody @Valid BannerListRequest request) {
// 获取数据
BannerListDTO pageDTO = BannerConvert.INSTANCE.convert(request);
PageResult<BannerListBO> pageResult = bannerService.listBanner(pageDTO);
// 转换 response
List<BannerListResponse> responseList = BannerConvert.INSTANCE.convert(pageResult.getList());
return CommonResult.success(new PageResult<BannerListResponse>().setList(responseList).setTotal(pageResult.getTotal()));
}
@PostMapping("/add")
@ApiOperation(value = "添加-Banner")
public CommonResult<Void> add(@RequestBody @Valid BannerAddRequest request) {
BannerAddDTO bannerAddDTO = BannerConvert.INSTANCE.convert(request);
bannerAddDTO.setAdminId(AdminSecurityContextHolder.getContext().getAdminId());
bannerService.addBanner(bannerAddDTO);
return CommonResult.success(null);
}
@PutMapping("/update")
@ApiOperation(value = "更新-Banner信息")
public CommonResult<Void> update(@RequestBody @Valid BannerUpdateRequest request) {
BannerUpdateDTO bannerUpdateDTO = BannerConvert.INSTANCE.convert(request);
bannerUpdateDTO.setAdminId(AdminSecurityContextHolder.getContext().getAdminId());
bannerService.updateBanner(bannerUpdateDTO);
return CommonResult.success(null);
}
@PutMapping("/update-status")
@ApiOperation(value = "更新-banner状态")
public CommonResult<Void> updateStatus(@RequestBody @Valid BannerUpdateStatusRequest request) {
Integer adminId = AdminSecurityContextHolder.getContext().getAdminId();
bannerService.updateBannerStatus(adminId, request.getBannerId(), request.getStatus());
return CommonResult.success(null);
}
@DeleteMapping("/delete")
@ApiOperation(value = "删除-根据id删除")
@ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1")
public CommonResult<Void> delete(@RequestParam("id") Integer id) {
bannerService.deleteBanner(AdminSecurityContextHolder.getContext().getAdminId(), id);
return CommonResult.success(null);
}
}

View File

@ -1,37 +0,0 @@
package cn.iocoder.mall.promotion.rest.controller.banner;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListOnReleaseBO;
import cn.iocoder.mall.promotion.biz.service.banner.BannerService;
import cn.iocoder.mall.promotion.rest.convert.BannerConvert;
import cn.iocoder.mall.promotion.rest.response.banner.BannerListOnReleaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* Banner(API)
*
* author: sin
* time: 2020/5/14 15:27
*/
@RestController
@RequestMapping("/users/banner")
@Api(tags = "Banner(用户API)")
public class UsersBannerController {
@Autowired
private BannerService bannerService;
@GetMapping("/listBannerOnRelease")
@ApiOperation("获取-已发布的banner")
public CommonResult<List<BannerListOnReleaseResponse>> listBannerOnRelease() {
List<BannerListOnReleaseBO> releaseBOList = bannerService.listBannerOnRelease();
return CommonResult.success(BannerConvert.INSTANCE.convertReleaseResponse(releaseBOList));
}
}

View File

@ -1,5 +0,0 @@
/**
* author: sin
* time: 2020/5/14 15:27
*/
package cn.iocoder.mall.promotion.rest.controller;

View File

@ -1,33 +0,0 @@
package cn.iocoder.mall.promotion.rest.convert;
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListBO;
import cn.iocoder.mall.promotion.biz.bo.banner.BannerListOnReleaseBO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerAddDTO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerUpdateDTO;
import cn.iocoder.mall.promotion.biz.dto.banner.BannerListDTO;
import cn.iocoder.mall.promotion.rest.request.banner.BannerAddRequest;
import cn.iocoder.mall.promotion.rest.request.banner.BannerListRequest;
import cn.iocoder.mall.promotion.rest.request.banner.BannerUpdateRequest;
import cn.iocoder.mall.promotion.rest.response.banner.BannerListResponse;
import cn.iocoder.mall.promotion.rest.response.banner.BannerListOnReleaseResponse;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface BannerConvert {
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class);
BannerAddDTO convert(BannerAddRequest request);
BannerUpdateDTO convert(BannerUpdateRequest request);
BannerListDTO convert(BannerListRequest request);
List<BannerListResponse> convert(List<BannerListBO> bannerListBO);
List<BannerListOnReleaseResponse> convertReleaseResponse(List<BannerListOnReleaseBO> bannerListOnReleaseBOS);
}

View File

@ -1,35 +0,0 @@
package cn.iocoder.mall.promotion.rest.request.banner;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* banner banner
*
* author: sin
* time: 2020/5/14 15:44
*/
@Data
@Accessors(chain = true)
public class BannerAddRequest implements Serializable {
@NotNull // TODO FROM 芋艿 to 小范:提示要加下,哈哈哈
@ApiModelProperty("跳转链接")
private Integer url;
@NotNull
@ApiModelProperty("图片链接")
private Integer picUrl;
@NotNull
@ApiModelProperty("排序")
private Integer sort;
@NotNull
@ApiModelProperty("备注")
private Integer memo;
}

View File

@ -1,27 +0,0 @@
package cn.iocoder.mall.promotion.rest.request.banner;
import cn.iocoder.common.framework.vo.PageParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.web.bind.annotation.RequestParam;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* banner banner
*
* author: sin
* time: 2020/5/14 15:44
*/
@Data
@Accessors(chain = true)
public class BannerListRequest extends PageParam {
@ApiModelProperty("标题")
private String title;
@ApiModelProperty("状态")
private Integer status;
}

View File

@ -1,39 +0,0 @@
package cn.iocoder.mall.promotion.rest.request.banner;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* banner banner
*
* author: sin
* time: 2020/5/14 15:44
*/
@Data
@Accessors(chain = true)
public class BannerUpdateRequest implements Serializable {
@NotNull
@ApiModelProperty("banner编号")
private Integer bannerId;
@NotNull
@ApiModelProperty("跳转链接")
private Integer url;
@NotNull
@ApiModelProperty("图片链接")
private Integer picUrl;
@NotNull
@ApiModelProperty("排序")
private Integer sort;
@NotNull
@ApiModelProperty("备注")
private Integer memo;
}

View File

@ -1,27 +0,0 @@
package cn.iocoder.mall.promotion.rest.request.banner;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* banner status
*
* author: sin
* time: 2020/5/14 15:44
*/
@Data
@Accessors(chain = true)
public class BannerUpdateStatusRequest implements Serializable {
@NotNull
@ApiModelProperty("banner编号")
private Integer bannerId;
@NotNull
@ApiModelProperty("status状态")
private Integer status;
}

View File

@ -1,6 +0,0 @@
/**
* author: sin
* time: 2020/5/14 17:00
*/
package cn.iocoder.mall.promotion.rest.request;

View File

@ -1,34 +0,0 @@
package cn.iocoder.mall.promotion.rest.response.banner;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* banner - banner
*
* author: sin
* time: 2020/5/14 16:56
*/
@Data
@Accessors(chain = true)
public class BannerListOnReleaseResponse implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private String title;
/**
*
*/
private String url;
/**
*
*/
private String picUrl;
}

View File

@ -1,49 +0,0 @@
package cn.iocoder.mall.promotion.rest.response.banner;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* bannerlist
*
* author: sin
* time: 2020/5/14 16:00
*/
@Data
@Accessors(chain = true)
public class BannerListResponse implements Serializable {
@ApiModelProperty("编号")
private Integer id;
@ApiModelProperty("标题")
private String title;
@ApiModelProperty("跳转链接")
private String url;
@ApiModelProperty("图片链接")
private String picUrl;
@ApiModelProperty("排序")
private Integer sort;
@ApiModelProperty("状态")
private Integer status;
@ApiModelProperty("备注")
private String memo;
//
// 其他
@ApiModelProperty("更新时间")
private Date updatedTime;
@ApiModelProperty("创建时间")
private Date createdTime;
}

View File

@ -1,5 +0,0 @@
/**
* author: sin
* time: 2020/5/14 15:26
*/
package cn.iocoder.mall.promotion.rest.response;

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>promotion</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>promotion-rpc-api</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-biz-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 工具类相关 -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>promotion</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>promotion-rpc</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-rpc-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>system-biz</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- RPC 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>
<!-- Registry 和 Config 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -56,100 +56,4 @@ public class AdminsCouponController {
return success(CouponTemplateConvert.ADMINS.convertPage(result));
}
@PostMapping("/template/add_card")
@ApiOperation(value = "创建优惠劵模板")
@ApiImplicitParams({
@ApiImplicitParam(name = "title", value = "标题", required = true, example = "优惠劵牛逼"),
@ApiImplicitParam(name = "description", value = "使用说明", example = "我只是描述"),
@ApiImplicitParam(name = "quota", value = "每人限领个数", required = true),
@ApiImplicitParam(name = "total", value = "发行总量"),
@ApiImplicitParam(name = "priceAvailable", value = "是否设置满多少金额可用,单位:分", example = "0-不限制大于0-多少金额可用"),
@ApiImplicitParam(name = "rangeType", value = "可用范围的类型", required = true, example = "参见 CouponTemplateRangeTypeEnum 枚举"),
@ApiImplicitParam(name = "rangeValues", value = "指定商品 / 分类列表,使用逗号分隔商品编号"),
@ApiImplicitParam(name = "dateType", value = "生效日期类型", example = "参见 CouponTemplateDateTypeEnum 枚举"),
@ApiImplicitParam(name = "validStartTime", value = "固定日期-生效开始时间", example = "当 dateType 为固定日期时,非空"),
@ApiImplicitParam(name = "validEndTime", value = "固定日期-生效结束时间", example = "当 dateType 为固定日期时,非空"),
@ApiImplicitParam(name = "fixedBeginTerm", value = "领取日期-开始天数", example = "当 dateType 为领取日期时,非空"),
@ApiImplicitParam(name = "fixedEndTerm", value = "领取日期-结束天数", example = "当 dateType 为领取日期时,非空"),
@ApiImplicitParam(name = "preferentialType", value = "优惠类型", example = "参见 CouponTemplatePreferentialTypeEnum 枚举"),
@ApiImplicitParam(name = "priceOff", value = "优惠金额,单位:分", example = "当 preferentialType 为现金券时,非空"),
@ApiImplicitParam(name = "percentOff", value = "折扣百分比", example = "当 preferentialType 为折扣卷时,非空"),
@ApiImplicitParam(name = "discountPriceLimit", value = "折扣上限", example = "当 preferentialType 为折扣卷时,非空"),
})
public CommonResult<AdminsCouponTemplateVO> templateCardAdd(@RequestParam(value = "title") String title,
@RequestParam(value = "description", required = false) String description,
@RequestParam(value = "quota") Integer quota,
@RequestParam(value = "total", required = false) Integer total,
@RequestParam(value = "priceAvailable") Integer priceAvailable,
@RequestParam(value = "rangeType") Integer rangeType,
@RequestParam(value = "rangeValues", required = false) String rangeValues,
@RequestParam(value = "dateType") Integer dateType,
@DateTimeFormat(pattern = "yyyy-MM-dd")
@RequestParam(value = "validStartTime", required = false) Date validStartTime,
@DateTimeFormat(pattern = "yyyy-MM-dd")
@RequestParam(value = "validEndTime", required = false) Date validEndTime,
@RequestParam(value = "fixedBeginTerm", required = false) Integer fixedBeginTerm,
@RequestParam(value = "fixedEndTerm", required = false) Integer fixedEndTerm,
@RequestParam(value = "preferentialType") Integer preferentialType,
@RequestParam(value = "priceOff", required = false) Integer priceOff,
@RequestParam(value = "percentOff", required = false) Integer percentOff,
@RequestParam(value = "discountPriceLimit", required = false) Integer discountPriceLimit) {
// 创建 CouponCardTemplateAddDTO 对象
validStartTime = DateUtil.getDayBegin(validStartTime); // 开始时间,以当前 00:00:00 为准
validEndTime = DateUtil.getDayBegin(validEndTime); // 结束时间,以当前 25:59:59 为准
CouponCardTemplateAddDTO couponCardTemplateAddDTO = new CouponCardTemplateAddDTO()
.setTitle(title).setDescription(description)
.setQuota(quota).setTotal(total)
.setPriceAvailable(priceAvailable).setRangeType(rangeType).setRangeValues(rangeValues)
.setDateType(dateType).setValidStartTime(validStartTime).setValidEndTime(validEndTime)
.setFixedBeginTerm(fixedBeginTerm).setFixedEndTerm(fixedEndTerm)
.setPreferentialType(preferentialType).setPriceOff(priceOff).setPercentOff(percentOff).setDiscountPriceLimit(discountPriceLimit);
// 提交请求
CouponTemplateBO result = couponService.addCouponCardTemplate(couponCardTemplateAddDTO);
// 返回结果
return success(CouponTemplateConvert.ADMINS.convert(result));
}
@PostMapping("/template/update_card")
@ApiOperation(value = "更新优惠劵模板")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1"),
@ApiImplicitParam(name = "title", value = "标题", required = true, example = "优惠劵牛逼"),
@ApiImplicitParam(name = "description", value = "使用说明", example = "我只是描述"),
@ApiImplicitParam(name = "quota", value = "每人限领个数", required = true),
@ApiImplicitParam(name = "total", value = "发行总量"),
@ApiImplicitParam(name = "rangeType", value = "可用范围的类型", required = true, example = "参见 CouponTemplateRangeTypeEnum 枚举"),
@ApiImplicitParam(name = "rangeValues", value = "指定商品 / 分类列表,使用逗号分隔商品编号"),
})
public CommonResult<Boolean> templateCardUpdate(@RequestParam(value = "id") Integer id,
@RequestParam(value = "title") String title,
@RequestParam(value = "description", required = false) String description,
@RequestParam(value = "quota") Integer quota,
@RequestParam(value = "total", required = false) Integer total,
@RequestParam(value = "rangeType") Integer rangeType,
@RequestParam(value = "rangeValues", required = false) String rangeValues) {
// 创建 CouponCardTemplateAddDTO 对象
CouponCardTemplateUpdateDTO couponCardTemplateUpdateDTO = new CouponCardTemplateUpdateDTO()
.setId(id)
.setTitle(title).setDescription(description)
.setQuota(quota).setTotal(total)
.setRangeType(rangeType).setRangeValues(rangeValues);
return success(couponService.updateCouponCardTemplate(couponCardTemplateUpdateDTO));
}
@PostMapping("/template/update_status")
@ApiOperation(value = "更新优惠劵(码)模板状态")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1"),
@ApiImplicitParam(name = "status", value = "状态。1 - 开启2 - 禁用", required = true, example = "1"),
})
public CommonResult<Boolean> templateUpdateStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return success(couponService.updateCouponTemplateStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
}
// ========== 优惠劵 ==========
// ========== 优惠码 ==========
}

View File

@ -1,20 +0,0 @@
package cn.iocoder.mall.promotion.application.vo.admins;
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 AdminsCouponTemplatePageVO {
@ApiModelProperty(value = "优惠劵(码)数组")
private List<AdminsCouponTemplateVO> list;
@ApiModelProperty(value = "优惠劵(码)总数")
private Integer total;
}

View File

@ -1,20 +0,0 @@
package cn.iocoder.mall.promotion.application.vo.admins;
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 AdminsProductRecommendPageVO {
@ApiModelProperty(value = "商品推荐数组")
private List<AdminsProductRecommendVO> list;
@ApiModelProperty(value = "商品推荐总数")
private Integer total;
}