优惠劵相关逻辑的迁移

This commit is contained in:
YunaiV
2020-08-20 19:47:29 +08:00
parent 2c6331eb75
commit 5b3c464faf
106 changed files with 1277 additions and 2621 deletions

View File

@@ -1,36 +0,0 @@
package cn.iocoder.mall.promotion.biz.dao;
import cn.iocoder.mall.promotion.biz.dataobject.CouponCardDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface CouponCardMapper {
CouponCardDO selectById(@Param("id") Integer id);
List<CouponCardDO> selectListByUserIdAndStatus(@Param("userId") Integer userId,
@Param("status") Integer status);
List<CouponCardDO> selectListByPage(@Param("userId") Integer userId,
@Param("status") Integer status,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByPage(@Param("userId") Integer userId,
@Param("status") Integer status);
int selectCountByUserIdAndTemplateId(@Param("userId") Integer userId,
@Param("templateId") Integer templateId);
void insert(CouponCardDO couponCardDO);
int update(CouponCardDO couponCardDO);
int updateByIdAndStatus(@Param("id") Integer id,
@Param("status") Integer status,
@Param("updateObj") CouponCardDO updateObj);
}

View File

@@ -1,35 +0,0 @@
package cn.iocoder.mall.promotion.biz.dao;
import cn.iocoder.mall.promotion.biz.dataobject.CouponTemplateDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
@Repository
public interface CouponTemplateMapper {
CouponTemplateDO selectById(@Param("id") Integer id);
List<CouponTemplateDO> selectListByIds(@Param("ids") Collection<Integer> ids);
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);
void insert(CouponTemplateDO couponTemplate);
int update(CouponTemplateDO couponTemplate);
int updateStatFetchNumIncr(@Param("id") Integer id);
}

View File

@@ -1,119 +0,0 @@
package cn.iocoder.mall.promotion.biz.dataobject;
import cn.iocoder.mall.mybatis.core.dataobject.BaseDO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 优惠劵 DO
*/
@Data
@Accessors(chain = true)
public class CouponCardDO extends BaseDO {
// ========== 基本信息 BEGIN ==========
/**
* 优惠劵编号
*/
private Integer id;
/**
* 优惠劵(码)分组编号,{@link CouponTemplateDO} 的 id
*/
private Integer templateId;
/**
* 优惠劵名
*
* 冗余自 {@link CouponTemplateDO} 的 title
*
* TODO 芋艿,暂时不考虑冗余的更新
*/
private String title;
// /**
// * 核销码
// */
// private String verifyCode;
/**
* 优惠码状态
*
* 1-未使用
* 2-已使用
* 3-已失效
*/
private Integer status;
// ========== 基本信息 END ==========
// ========== 领取情况 BEGIN ==========
/**
* 用户编号
*/
private Integer userId;
/**
* 领取类型
*
* 1 - 用户主动领取
* 2 - 后台自动发放
*/
private Integer takeType;
// ========== 领取情况 END ==========
// ========== 使用规则 BEGIN ==========
/**
* 是否设置满多少金额可用,单位:分
*/
private Integer priceAvailable;
/**
* 生效开始时间
*/
private Date validStartTime;
/**
* 生效结束时间
*/
private Date validEndTime;
// ========== 使用规则 END ==========
// ========== 使用效果 BEGIN ==========
/**
* 优惠类型
*
* 1-代金卷
* 2-折扣卷
*/
private Integer preferentialType;
/**
* 折扣
*/
private Integer percentOff;
/**
* 优惠金额,单位:分。
*/
private Integer priceOff;
/**
* 折扣上限,仅在 {@link #preferentialType} 等于 2 时生效。
*
* 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。
*/
private Integer discountPriceLimit;
// ========== 使用效果 END ==========
// ========== 使用情况 BEGIN ==========
// /**
// * 使用订单号
// */
// private Integer usedOrderId; // TODO 芋艿,暂时不考虑这个字段
// /**
// * 订单中优惠面值,单位:分
// */
// private Integer usedPrice; // TODO 芋艿,暂时不考虑这个字段
/**
* 使用时间
*/
private Date usedTime;
// TODO 芋艿,后续要加优惠劵的使用日志,因为下单后,可能会取消。
// ========== 使用情况 END ==========
}

View File

@@ -1,43 +0,0 @@
package cn.iocoder.mall.promotion.biz.dataobject;
import cn.iocoder.mall.mybatis.core.dataobject.BaseDO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 优惠码
*/
@Data
@Accessors(chain = true)
public class CouponCodeDO extends BaseDO {
/**
* 编号
*/
private Integer id;
/**
* 模板编号 {@link CouponTemplateDO} 的 id
*/
private Integer templateId;
/**
* 优惠码
*/
private Integer code;
/**
* 领取时间
*/
private Date takeTime;
/**
* 领取用户编号
*/
private Integer userId;
/**
* 领取的优惠劵编号
*/
private Integer couponId;
// TODO 芋艿,后续要考虑状态的追踪
}

View File

@@ -1,220 +0,0 @@
package cn.iocoder.mall.promotion.biz.dataobject;
import cn.iocoder.mall.mybatis.core.dataobject.BaseDO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 优惠劵(码)模板 DO
*
* 当用户领取时,会生成 {@link CouponCardDO} 优惠劵(码)。
*/
@Data
@Accessors(chain = true)
public class CouponTemplateDO extends BaseDO {
// ========== 基本信息 BEGIN ==========
/**
* 模板编号,自增唯一。
*/
private Integer id;
/**
* 标题
*/
private String title;
/**
* 使用说明
*/
private String description;
/**
* 类型
*
* 1-优惠劵
* 2-优惠码
*/
private Integer type;
/**
* 优惠码状态
*
* {@link cn.iocoder.mall.promotion.api.enums.CouponTemplateStatusEnum}
*
* 当优惠劵(码)开启中,可以手动操作,设置禁用中。
*/
private Integer status;
// /**
// * 是否可分享领取链接
// */
// private Boolean isShare;
// /**
// * 设置为失效时间
// */
// private Date invalidTime;
// /**
// * 删除时间
// */
// private Date deleteTime;
// ========== 基本信息 END ==========
// ========== 领取规则 BEGIN ==========
// /**
// * 是否限制领用者的等级
// *
// * 0-不限制
// * 大于0-领用者必须是这个等级编号
// *
// * 【优惠劵独有】
// */
// private Integer needUserLevel;
/**
* 每人限领个数
*
* null - 则表示不限制
*/
private Integer quota;
/**
* 发行总量
*/
private Integer total;
// ========== 领取规则 END ==========
// ========== 使用规则 BEGIN ==========
// /**
// * 是否仅原价购买商品时可用
// *
// * true-是
// * false-否
// */
// private Boolean isForbidPreference;
/**
* 是否设置满多少金额可用,单位:分
*
* 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;
// /**
// * 是否到期前4天发送提醒
// *
// * true-发送
// * false-不发送
// */
// private Boolean expireNotice;
// ========== 使用规则 END ==========
// ========== 使用效果 BEGIN ==========
/**
* 优惠类型
*
* 1-代金卷
* 2-折扣卷
*/
private Integer preferentialType;
/**
* 折扣百分比。
*
* 例如80% 为 80。
* 当 100% 为 100 ,则代表免费。
*/
private Integer percentOff;
// /**
// * 是否是随机优惠券
// *
// * true-随机
// * false-不随机
// *
// * 【优惠劵独有】
// */
// private Boolean isRandom;
/**
* 优惠金额,单位:分
*/
// * 当 {@link #isRandom} 为 true 时,代表随机优惠金额的下限
private Integer priceOff;
// /**
// * 优惠金额上限
// *
// * 【优惠劵独有】
// */
// private Integer valueRandomTo;
/**
* 折扣上限,仅在 {@link #preferentialType} 等于 2 时生效。
*
* 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。
*/
private Integer discountPriceLimit;
// ========== 使用效果 END ==========
// ========== 统计信息 BEGIN ==========
// /**
// * 领取优惠券的人数
// */
// private Integer statFetchUserNum;
/**
* 领取优惠券的次数
*/
private Integer statFetchNum;
// /**
// * 使用优惠券的次数
// */
// private Integer statUseNum;
// ========== 统计信息 END ==========
// ========== 优惠码 BEGIN ==========
/**
* 码类型
*
* 1-一卡一码UNIQUE
* 2-通用码GENERAL
*
* 【优惠码独有】 @see CouponCodeDO
*/
private Integer codeType;
/**
* 通用码
*/
private String commonCode;
// ========== 优惠码 BEGIN ==========
}

View File

@@ -1,12 +0,0 @@
package cn.iocoder.mall.promotion.biz.mybatis;
import cn.iocoder.mall.mybatis.core.type.JSONTypeHandler;
import cn.iocoder.mall.promotion.biz.dataobject.PromotionActivityDO;
public class TestHandler extends JSONTypeHandler<PromotionActivityDO.TimeLimitedDiscount> {
public TestHandler(Class<PromotionActivityDO.TimeLimitedDiscount> clazz) {
super(clazz);
}
}

View File

@@ -1,9 +0,0 @@
package cn.iocoder.mall.promotion.biz.scheduler;
/**
* 优惠劵过期 Job
*
* TODO 芋艿
*/
public class CouponCardExpireJob {
}

View File

@@ -1,76 +0,0 @@
spring:
# datasource
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://s1.iocoder.cn:3306/mall_promotion?useSSL=false&useUnicode=true&characterEncoding=UTF-8
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 3WLiVUBEwTbvAfsh
# Spring Cloud 配置项
cloud:
nacos:
# Spring Cloud Nacos Discovery 配置项
discovery:
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
# mybatis-plus
mybatis-plus:
configuration:
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
global-config:
db-config:
id-type: auto
mapper-locations: classpath*:mapper/*.xml
type-aliases-package: cn.iocoder.mall.promotion.biz.dataobject
# Dubbo 配置项
dubbo:
# Dubbo 注册中心
registry:
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
# Spring Cloud Alibaba Dubbo 专属配置
cloud:
subscribed-services: admin-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用
# Dubbo 提供者的协议
protocol:
name: dubbo
port: -1
# Dubbo 提供服务的扫描基础包
scan:
base-packages: cn.iocoder.mall.promotion.biz.service
consumer:
ProductSpuService:
version: 1.0.0
# Dubbo 服务提供者的配置
provider:
filter: -exception
BannerService:
version: 1.0.0
CouponService:
version: 1.0.0
ProductRecommendService:
version: 1.0.0
PromotionActivityService:
version: 1.0.0
# Seata 配置项
seata:
tx-service-group: default # Seata 事务组编号,用于 TC 集群名
# 服务配置项,对应 ServiceProperties 类
service:
# 虚拟组和分组的映射
vgroup-mapping:
default: default
# Seata 注册中心配置项
registry:
type: nacos # 注册中心类型
nacos:
serverAddr: ${spring.cloud.nacos.discovery.server-addr} # Nacos 服务地址
namespace: # Nacos 命名空间
cluster: default # 使用的 Seata 分组
# logging
logging:
level:
cn.iocoder.mall.promotion.dao: debug

View File

@@ -1,134 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.iocoder.mall.promotion.biz.dao.CouponCardMapper">
<sql id="FIELDS">
id, template_id, title, status, user_id, take_type,
price_available, valid_start_time, valid_end_time, preferential_type, percent_off, price_off,
discount_price_limit, used_time,
create_time
</sql>
<!-- <select id="selectListByPidAndStatusOrderBySort" resultType="CouponCardDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM coupon_card-->
<!-- WHERE pid = #{pid}-->
<!-- AND status = #{status}-->
<!-- AND deleted = 0-->
<!-- ORDER BY sort ASC-->
<!-- </select>-->
<!-- <select id="selectList" resultType="CouponCardDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM coupon_card-->
<!-- WHERE deleted = 0-->
<!-- </select>-->
<select id="selectById" parameterType="Integer" resultType="CouponCardDO">
SELECT
<include refid="FIELDS" />
FROM coupon_card
WHERE id = #{id}
</select>
<select id="selectListByUserIdAndStatus" resultType="CouponCardDO">
SELECT
<include refid="FIELDS" />
FROM coupon_card
<where>
<if test="userId != null">
AND user_id = #{userId}
</if>
<if test="status != null">
AND status = #{status}
</if>
</where>
</select>
<select id="selectListByPage" resultType="CouponCardDO">
SELECT
<include refid="FIELDS" />
FROM coupon_card
<where>
<if test="userId != null">
AND user_id = #{userId}
</if>
<if test="status != null">
AND status = #{status}
</if>
</where>
LIMIT #{offset}, #{limit}
</select>
<select id="selectCountByPage" resultType="Integer">
SELECT
COUNT(1)
FROM coupon_card
<where>
<if test="userId != null">
AND user_id = #{userId}
</if>
<if test="status != null">
AND status = #{status}
</if>
</where>
</select>
<select id="selectCountByUserIdAndTemplateId" resultType="Integer">
SELECT
COUNT(1)
FROM coupon_card
<where>
<if test="userId != null">
AND user_id = #{userId}
</if>
<if test="templateId != null">
AND template_id = #{templateId}
</if>
</where>
</select>
<insert id="insert" parameterType="CouponCardDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO coupon_card (
template_id, title, status, user_id, take_type,
price_available, valid_start_time, valid_end_time, preferential_type, percent_off, price_off,
discount_price_limit, used_time,
create_time
) VALUES (
#{templateId}, #{title}, #{status}, #{userId}, #{takeType},
#{priceAvailable}, #{validStartTime}, #{validEndTime}, #{preferentialType}, #{percentOff}, #{priceOff},
#{discountPriceLimit}, #{usedTime},
#{createTime}
)
</insert>
<update id="update" parameterType="CouponCardDO">
UPDATE coupon_card
<set>
<if test="status != null">
status = #{status},
</if>
<if test="usedTime != null">
used_time = #{usedTime},
</if>
</set>
WHERE id = #{id}
</update>
<update id="updateByIdAndStatus">
UPDATE coupon_card
<set>
<if test="updateObj.status != null">
status = #{updateObj.status},
</if>
<if test="updateObj.usedTime != null">
used_time = #{updateObj.usedTime},
</if>
</set>
WHERE id = #{id}
AND status = #{status}
</update>
</mapper>

View File

@@ -1,169 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.iocoder.mall.promotion.biz.dao.CouponTemplateMapper">
<sql id="FIELDS">
id, title, description, type, code_type,
status, quota, total, price_available, range_type,
range_values, date_type, valid_start_time, valid_end_time, fixed_start_term, fixed_end_term,
preferential_type, percent_off, price_off, discount_price_limit, stat_fetch_num,
create_time
</sql>
<!-- <select id="selectListByPidAndStatusOrderBySort" resultType="CouponTemplateDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM coupon_template-->
<!-- WHERE pid = #{pid}-->
<!-- AND status = #{status}-->
<!-- AND deleted = 0-->
<!-- ORDER BY sort ASC-->
<!-- </select>-->
<!-- <select id="selectList" resultType="CouponTemplateDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM coupon_template-->
<!-- WHERE deleted = 0-->
<!-- </select>-->
<select id="selectById" parameterType="Integer" resultType="CouponTemplateDO">
SELECT
<include refid="FIELDS" />
FROM coupon_template
WHERE id = #{id}
</select>
<select id="selectListByIds" resultType="CouponTemplateDO">
SELECT
<include refid="FIELDS"/>
FROM coupon_template
WHERE id IN
<foreach item="id" collection="ids" separator="," open="(" close=")" index="">
#{id}
</foreach>
</select>
<select id="selectListByPage" resultType="CouponTemplateDO">
SELECT
<include refid="FIELDS" />
FROM coupon_template
<where>
<if test="type != null">
AND type = #{type}
</if>
<if test="title != null">
AND title LIKE "%"#{title}"%"
</if>
<if test="status != null">
AND status = #{status}
</if>
<if test="preferentialType != null">
AND preferential_type = #{preferentialType}
</if>
</where>
LIMIT #{offset}, #{limit}
</select>
<select id="selectCountByPage" resultType="Integer">
SELECT
COUNT(1)
FROM coupon_template
<where>
<if test="type != null">
AND type = #{type}
</if>
<if test="title != null">
AND title LIKE "%"#{title}"%"
</if>
<if test="status != null">
AND status = #{status}
</if>
<if test="preferentialType != null">
AND preferential_type = #{preferentialType}
</if>
</where>
</select>
<insert id="insert" parameterType="CouponTemplateDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO coupon_template (
title, description, type, code_type,
status, quota, total, price_available, range_type,
range_values, date_type, valid_start_time, valid_end_time, fixed_start_term, fixed_end_term,
preferential_type, percent_off, price_off, discount_price_limit, stat_fetch_num,
create_time
) VALUES (
#{title}, #{description}, #{type}, #{codeType},
#{status}, #{quota}, #{total}, #{priceAvailable}, #{rangeType},
#{rangeValues}, #{dateType}, #{validStartTime}, #{validEndTime}, #{fixedStartTerm}, #{fixedEndTerm}
#{preferentialType}, #{percentOff}, #{priceOff}, #{discountPriceLimit}, #{statFetchNum},
#{createTime}
)
</insert>
<update id="update" parameterType="CouponTemplateDO">
UPDATE coupon_template
<set>
<if test="title != null">
title = #{title},
</if>
<if test="description != null">
description = #{description},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="quota != null">
quota = #{quota},
</if>
<if test="total != null">
total = #{total},
</if>
<if test="priceAvailable != null">
price_available = #{priceAvailable},
</if>
<if test="rangeType != null">
range_type = #{rangeType},
</if>
<if test="rangeValues != null">
range_values = #{rangeValues},
</if>
<if test="dateType != null">
date_type = #{dateType},
</if>
<if test="validStartTime != null">
valid_start_time = #{validStartTime},
</if>
<if test="validEndTime != null">
valid_end_time = #{validEndTime},
</if>
<if test="fixedStartTerm != null">
fixed_start_term = #{fixedStartTerm},
</if>
<if test="fixedEndTerm != null">
fixed_end_term = #{fixedEndTerm},
</if>
<if test="preferentialType != null">
preferential_type = #{preferentialType},
</if>
<if test="percentOff != null">
percent_off = #{percentOff},
</if>
<if test="priceOff != null">
price_off = #{priceOff},
</if>
<if test="discountPriceLimit != null">
discount_price_limit = #{discountPriceLimit},
</if>
</set>
WHERE id = #{id}
</update>
<update id="updateStatFetchNumIncr" parameterType="Integer">
UPDATE coupon_template
SET stat_fetch_Num = stat_fetch_Num + 1
WHERE id = #{id}
AND total > stat_fetch_Num
</update>
</mapper>

View File

@@ -1,7 +0,0 @@
package cn.iocoder.mall.promotion.biz;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.promotion"})
public class Application {
}

View File

@@ -1,94 +0,0 @@
package cn.iocoder.mall.promotion.biz.dao;
import cn.iocoder.common.framework.util.DateUtil;
import cn.iocoder.mall.promotion.api.enums.PreferentialTypeEnum;
import cn.iocoder.mall.promotion.api.enums.PromotionActivityStatusEnum;
import cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
import cn.iocoder.mall.promotion.biz.dataobject.PromotionActivityDO;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class PromotionActivityMapperTest {
@Autowired
private PromotionActivityMapper promotionActivityMapper;
/**
* 插入限时折扣活动
*/
@Test
@Ignore
public void testInsert01() {
// 创建 PromotionActivityDO 对象
PromotionActivityDO activityDO = new PromotionActivityDO();
activityDO.setTitle("老板跑路了");
activityDO.setActivityType(PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT.getValue());
activityDO.setStatus(PromotionActivityStatusEnum.RUN.getValue());
activityDO.setStartTime(new Date());
activityDO.setEndTime(DateUtil.addDate(new Date(), Calendar.DAY_OF_YEAR, 100));
activityDO.setCreateTime(new Date());
// 创建 TimeLimitedDiscount 对象
PromotionActivityDO.TimeLimitedDiscount discount = new PromotionActivityDO.TimeLimitedDiscount();
discount.setQuota(0);
discount.setItems(new ArrayList<>());
PromotionActivityDO.TimeLimitedDiscount.Item item01 = new PromotionActivityDO.TimeLimitedDiscount.Item();
item01.setSpuId(32);
item01.setPreferentialType(PreferentialTypeEnum.DISCOUNT.getValue());
item01.setPreferentialValue(40);
discount.getItems().add(item01);
activityDO.setTimeLimitedDiscount(discount);
promotionActivityMapper.insert(activityDO);
}
/**
* 插入满减送活动
*/
@Test
public void testInsert02() {
// 创建 PromotionActivityDO 对象
PromotionActivityDO activityDO = new PromotionActivityDO();
activityDO.setTitle("老四赶海");
activityDO.setActivityType(PromotionActivityTypeEnum.FULL_PRIVILEGE.getValue());
activityDO.setStatus(PromotionActivityStatusEnum.RUN.getValue());
activityDO.setStartTime(new Date());
activityDO.setEndTime(DateUtil.addDate(new Date(), Calendar.DAY_OF_YEAR, 100));
activityDO.setCreateTime(new Date());
// 创建 TimeLimitedDiscount 对象
PromotionActivityDO.FullPrivilege fullPrivilege = new PromotionActivityDO.FullPrivilege();
fullPrivilege.setRangeType(RangeTypeEnum.ALL.getValue());
fullPrivilege.setCycled(Boolean.FALSE);
fullPrivilege.setPrivileges(new ArrayList<>());
PromotionActivityDO.FullPrivilege.Privilege privilege01 = new PromotionActivityDO.FullPrivilege.Privilege();
privilege01.setMeetType(1); // TODO 芋艿,硬编码
privilege01.setMeetValue(20);
privilege01.setPreferentialType(PreferentialTypeEnum.DISCOUNT.getValue());
privilege01.setPreferentialValue(80);
fullPrivilege.getPrivileges().add(privilege01);
activityDO.setFullPrivilege(fullPrivilege);
promotionActivityMapper.insert(activityDO);
}
/**
* 查询促销活动
*/
@Test
public void testSelectById() {
PromotionActivityDO activity01 = promotionActivityMapper.selectById(1);
System.out.println(activity01);
PromotionActivityDO activity02 = promotionActivityMapper.selectById(2);
System.out.println(activity02);
}
}

View File

@@ -1,13 +0,0 @@
package cn.iocoder.mall.promotion.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.promotion"})
public class PromotionApplication {
public static void main(String[] args) {
SpringApplication.run(PromotionApplication.class, args);
}
}

View File

@@ -1,28 +0,0 @@
package cn.iocoder.mall.promotion.application.convert;
import cn.iocoder.mall.promotion.api.bo.CouponCardBO;
import cn.iocoder.mall.promotion.api.bo.CouponCardPageBO;
import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardPageVO;
import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface CouponCardConvert {
CouponCardConvert INSTANCE = Mappers.getMapper(CouponCardConvert.class);
@Mappings({})
UsersCouponCardVO convert(CouponCardBO result);
@Mappings({})
UsersCouponCardPageVO convert2(CouponCardPageBO result);
//
// @Mappings({})
// List<UsersCouponTemplateVO> convertList2(List<CouponTemplateBO> banners);
}

View File

@@ -1,43 +0,0 @@
package cn.iocoder.mall.promotion.application.convert;
import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO;
import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsCouponTemplatePageVO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsCouponTemplateVO;
import cn.iocoder.mall.promotion.application.vo.users.UsersCouponTemplateVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface CouponTemplateConvert {
Users USERS = Mappers.getMapper(Users.class);
Admins ADMINS = Mappers.getMapper(Admins.class);
@Mapper
interface Admins {
@Mappings({})
AdminsCouponTemplateVO convert(CouponTemplateBO template);
@Mappings({})
AdminsCouponTemplatePageVO convertPage(CouponTemplatePageBO result);
@Mappings({})
List<AdminsCouponTemplateVO> convertList(List<CouponTemplateBO> templates);
}
@Mapper
interface Users {
@Mappings({})
UsersCouponTemplateVO convert2(CouponTemplateBO template);
}
}

View File

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

View File

@@ -1,54 +0,0 @@
package cn.iocoder.mall.promotion.application.vo.users;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 优惠劵 VO
*/
@Data
@Accessors(chain = true)
public class UsersCouponCardVO {
// ========== 基本信息 BEGIN ==========
@ApiModelProperty(value = "优惠劵编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "模板编号,自增唯一", required = true, example = "1")
private Integer templateId;
@ApiModelProperty(value = "优惠劵名", required = true, example = "大保剑")
private String title;
@ApiModelProperty(value = "优惠码状态", required = true, example = "参见 CouponCardStatusEnum 枚举")
private Integer status;
// ========== 基本信息 END ==========
// ========== 使用规则 BEGIN ==========
@ApiModelProperty(value = "是否设置满多少金额可用,单位:分", required = true)
private Integer priceAvailable;
@ApiModelProperty(value = "固定日期-生效开始时间", required = true)
private Date validStartTime;
@ApiModelProperty(value = "固定日期-生效结束时间", required = true)
private Date validEndTime;
// ========== 使用规则 END ==========
// ========== 使用效果 BEGIN ==========
@ApiModelProperty(value = "优惠类型", required = true, example = "参见 CouponTemplatePreferentialTypeEnum 枚举")
private Integer preferentialType;
@ApiModelProperty(value = "折扣百分比")
private Integer percentOff;
@ApiModelProperty(value = "优惠金额,单位:分")
private Integer priceOff;
@ApiModelProperty(value = "折扣上限")
private Integer discountPriceLimit;
// ========== 使用效果 END ==========
// ========== 使用情况 BEGIN ==========
// TODO 芋艿,后续要加优惠劵的使用日志,因为下单后,可能会取消。
// ========== 使用情况 END ==========
}