Forráskód Böngészése

feat: 简单工厂搭建发奖领域

seamew 2 éve
szülő
commit
3659f20a87
25 módosított fájl, 659 hozzáadás és 36 törlés
  1. 75 0
      lottery-common/src/main/java/com/seamew/lottery/common/Constants.java
  2. 21 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/annotation/AwardMode.java
  3. 64 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/model/req/GoodsReq.java
  4. 50 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/model/res/DistributionRes.java
  5. 76 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/model/vo/ShippingAddress.java
  6. 12 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/repository/IAwardRepository.java
  7. 17 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/repository/impl/AwardRepository.java
  8. 18 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/factory/DistributionGoodsFactory.java
  9. 39 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/factory/GoodsConfig.java
  10. 24 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/DistributionBase.java
  11. 28 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/IDistributionGoods.java
  12. 39 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/impl/CouponGoods.java
  13. 38 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/impl/DescGoods.java
  14. 39 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/impl/PhysicalGoods.java
  15. 39 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/impl/RedeemCodeGoods.java
  16. 16 1
      lottery-domain/src/main/java/com/seamew/lottery/domain/strategy/model/vo/DrawAwardInfo.java
  17. 6 0
      lottery-domain/src/main/java/com/seamew/lottery/domain/strategy/repository/IStrategyRepository.java
  18. 1 2
      lottery-domain/src/main/java/com/seamew/lottery/domain/strategy/service/draw/AbstractDrawBase.java
  19. 3 3
      lottery-domain/src/main/java/com/seamew/lottery/domain/strategy/service/draw/DrawConfig.java
  20. 5 5
      lottery-interfaces/src/main/resources/mybatis/mapper/Activity_Mapper.xml
  21. 2 2
      lottery-interfaces/src/main/resources/mybatis/mapper/Award_Mapper.xml
  22. 7 7
      lottery-interfaces/src/main/resources/mybatis/mapper/StrategyDetail_Mapper.xml
  23. 3 3
      lottery-interfaces/src/main/resources/mybatis/mapper/Strategy_Mapper.xml
  24. 37 8
      lottery-interfaces/src/test/java/com/seamew/lottery/test/DrawAlgorithmTest.java
  25. 0 5
      pom.xml

+ 75 - 0
lottery-common/src/main/java/com/seamew/lottery/common/Constants.java

@@ -103,4 +103,79 @@ public class Constants {
         }
 
     }
+
+    /**
+     * 发奖状态:0等待发奖、1发奖成功、2发奖失败
+     */
+    public enum AwardState {
+
+        /**
+         * 等待发奖
+         */
+        WAIT(0, "等待发奖"),
+
+        /**
+         * 发奖成功
+         */
+        SUCCESS(1, "发奖成功"),
+
+        /**
+         * 发奖失败
+         */
+        FAILURE(2, "发奖失败");
+
+        private final Integer code;
+        private final String info;
+
+        AwardState(Integer code, String info) {
+            this.code = code;
+            this.info = info;
+        }
+
+        public Integer getCode() {
+            return code;
+        }
+
+        public String getInfo() {
+            return info;
+        }
+    }
+
+    /**
+     * 奖品类型(1:文字描述、2:兑换码、3:优惠券、4:实物奖品)
+     */
+    public enum AwardType {
+        /**
+         * 文字描述
+         */
+        DESC(1, "文字描述"),
+        /**
+         * 兑换码
+         */
+        RedeemCodeGoods(2, "兑换码"),
+        /**
+         * 优惠券
+         */
+        CouponGoods(3, "优惠券"),
+        /**
+         * 实物奖品
+         */
+        PhysicalGoods(4, "实物奖品");
+
+        private final Integer code;
+        private final String info;
+
+        AwardType(Integer code, String info) {
+            this.code = code;
+            this.info = info;
+        }
+
+        public Integer getCode() {
+            return code;
+        }
+
+        public String getInfo() {
+            return info;
+        }
+    }
 }

+ 21 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/annotation/AwardMode.java

@@ -0,0 +1,21 @@
+package com.seamew.lottery.domain.award.annotation;
+
+import com.seamew.lottery.common.Constants;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @Author: seamew
+ * @Title: AwardMode
+ * @CreateTime: 2023年02月15日 11:00:00
+ * @Description: 发奖类型枚举
+ * @Version: 1.0
+ */
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface AwardMode {
+    Constants.AwardType awardMode();
+}

+ 64 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/model/req/GoodsReq.java

@@ -0,0 +1,64 @@
+package com.seamew.lottery.domain.award.model.req;
+
+import com.seamew.lottery.domain.award.model.vo.ShippingAddress;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @Author: seamew
+ * @Title: GoodsReq
+ * @CreateTime: 2023年02月15日 10:32:00
+ * @Description: 奖品发货信息
+ * @Version: 1.0
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class GoodsReq {
+    /**
+     * 用户ID
+     */
+    private String uId;
+
+    /**
+     * 抽奖单号 ID
+     */
+    private String orderId;
+
+    /**
+     * 奖品ID
+     */
+    private String awardId;
+
+    /**
+     * 奖品名称
+     */
+    private String awardName;
+
+    /**
+     * 奖品内容「描述、奖品码、sku」
+     */
+    private String awardContent;
+
+    /**
+     * 四级送货地址(只有实物类商品需要地址)
+     */
+    private ShippingAddress shippingAddress;
+
+    /**
+     * 扩展信息,用于一些个性商品发放所需要的透传字段内容
+     */
+    private String extInfo;
+
+    public GoodsReq(String uId, String orderId, String awardId, String awardName, String awardContent) {
+        this.uId = uId;
+        this.orderId = orderId;
+        this.awardId = awardId;
+        this.awardName = awardName;
+        this.awardContent = awardContent;
+    }
+
+
+}

+ 50 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/model/res/DistributionRes.java

@@ -0,0 +1,50 @@
+package com.seamew.lottery.domain.award.model.res;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @Author: seamew
+ * @Title: DistributionRes
+ * @CreateTime: 2023年02月15日 10:36:00
+ * @Description: 商品配送结果
+ * @Version: 1.0
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class DistributionRes {
+    /**
+     * 用户ID
+     */
+    private String uId;
+
+    /**
+     * 编码
+     */
+    private Integer code;
+    /**
+     * 描述
+     */
+    private String info;
+
+    /**
+     * 结算单ID,如:发券后有券码、发货后有单号等,用于存根查询
+     */
+    private String statementId;
+
+    /**
+     * 构造函数
+     *
+     * @param uId   用户ID
+     * @param code  编码
+     * @param info  描述
+     */
+    public DistributionRes(String uId, Integer code, String info) {
+        this.uId = uId;
+        this.code = code;
+        this.info = info;
+    }
+}

+ 76 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/model/vo/ShippingAddress.java

@@ -0,0 +1,76 @@
+package com.seamew.lottery.domain.award.model.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @Author: seamew
+ * @Title: ShippingAddress
+ * @CreateTime: 2023年02月15日 10:33:00
+ * @Description:
+ * @Version: 1.0
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class ShippingAddress {
+    /**
+     * 收获人
+     */
+    private String name;
+
+    /**
+     * 一级地址ID
+     */
+    private String provinceId;
+    /**
+     * 一级地址名称
+     */
+    private String provinceName;
+
+    /**
+     * 二级地址ID
+     */
+    private String cityId;
+    /**
+     * 二级地址名称
+     */
+    private String cityName;
+
+    /**
+     * 三级地址ID
+     */
+    private String countyId;
+    /**
+     * 三级地址名称
+     */
+    private String countyName;
+
+    /**
+     * 四级地址ID
+     */
+    private String townId;
+    /**
+     * 四级地址名称
+     */
+    private String townName;
+
+    /**
+     * 详细地址
+     */
+    private String address;
+
+    /**
+     * 手机号
+     */
+    private String phone;
+    /**
+     * 邮箱
+     */
+    private String email;
+    /**
+     * 备注
+     */
+    private String remark;
+}

+ 12 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/repository/IAwardRepository.java

@@ -0,0 +1,12 @@
+package com.seamew.lottery.domain.award.repository;
+
+/**
+ * @Author: seamew
+ * @Title: IAwardRepository
+ * @CreateTime: 2023年02月15日 10:39:00
+ * @Description: 奖品表仓储服务接口
+ * @Version: 1.0
+ */
+public interface IAwardRepository {
+    // TODO 对分库分表中的用户中奖纪录操作
+}

+ 17 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/repository/impl/AwardRepository.java

@@ -0,0 +1,17 @@
+package com.seamew.lottery.domain.award.repository.impl;
+
+import com.seamew.lottery.domain.award.repository.IAwardRepository;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author: seamew
+ * @Title: AwardRepository
+ * @CreateTime: 2023年02月15日 10:39:00
+ * @Description: 奖品表仓储服务
+ * @Version: 1.0
+ */
+@Component
+public class AwardRepository implements IAwardRepository {
+
+}
+

+ 18 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/factory/DistributionGoodsFactory.java

@@ -0,0 +1,18 @@
+package com.seamew.lottery.domain.award.service.factory;
+
+import com.seamew.lottery.domain.award.service.goods.IDistributionGoods;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Author: seamew
+ * @Title: DistributionGoodsFactory
+ * @CreateTime: 2023年02月15日 11:12:00
+ * @Description: 配送商品简单工厂,提供获取配送服务
+ * @Version: 1.0
+ */
+@Service
+public class DistributionGoodsFactory extends GoodsConfig {
+    public IDistributionGoods getDistributionGoodsService(Integer awardType){
+        return goodsMap.get(awardType);
+    }
+}

+ 39 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/factory/GoodsConfig.java

@@ -0,0 +1,39 @@
+package com.seamew.lottery.domain.award.service.factory;
+
+import com.seamew.lottery.domain.award.annotation.AwardMode;
+import com.seamew.lottery.domain.award.service.goods.IDistributionGoods;
+import org.springframework.core.annotation.AnnotationUtils;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @Author: seamew
+ * @Title: GoodsConfig
+ * @CreateTime: 2023年02月15日 10:59:00
+ * @Description: 各类发奖奖品配置类
+ * @Version: 1.0
+ */
+public class GoodsConfig {
+    /**
+     * 奖品发放策略组
+     */
+    protected static Map<Integer, IDistributionGoods> goodsMap = new ConcurrentHashMap<>();
+
+    @Resource
+    private List<IDistributionGoods> distributionGoodsList = new ArrayList<>();
+
+    @PostConstruct
+    public void init() {
+        distributionGoodsList.forEach(element -> {
+            AwardMode awardMode = AnnotationUtils.findAnnotation(element.getClass(), AwardMode.class);
+            if (awardMode != null) {
+                goodsMap.put(awardMode.awardMode().getCode(), element);
+            }
+        });
+    }
+}

+ 24 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/DistributionBase.java

@@ -0,0 +1,24 @@
+package com.seamew.lottery.domain.award.service.goods;
+
+import com.seamew.lottery.domain.award.repository.IAwardRepository;
+import lombok.extern.slf4j.Slf4j;
+
+import javax.annotation.Resource;
+
+/**
+ * @Author: seamew
+ * @Title: DistributionBase
+ * @CreateTime: 2023年02月15日 10:38:00
+ * @Description: 配送货物基础共用类
+ * @Version: 1.0
+ */
+@Slf4j
+public class DistributionBase {
+    @Resource
+    private IAwardRepository awardRepository;
+
+    protected void updateUserAwardState(String uId, String orderId, String awardId, Integer awardState, String awardStateInfo) {
+        // TODO 后期添加更新分库分表中,用户个人的抽奖记录表中奖品发奖状态
+        log.info("TODO 后期添加更新分库分表中,用户个人的抽奖记录表中奖品发奖状态 uId:{}", uId);
+    }
+}

+ 28 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/IDistributionGoods.java

@@ -0,0 +1,28 @@
+package com.seamew.lottery.domain.award.service.goods;
+
+import com.seamew.lottery.domain.award.model.req.GoodsReq;
+import com.seamew.lottery.domain.award.model.res.DistributionRes;
+
+/**
+ * @Author: seamew
+ * @Title: IDistributionGoods
+ * @CreateTime: 2023年02月15日 10:27:00
+ * @Description: 抽奖,抽象出配送货物接口,把各类奖品模拟成货物、配送代表着发货,包括虚拟奖品和实物奖品
+ * @Version: 1.0
+ */
+public interface IDistributionGoods {
+    /**
+     * 奖品配送接口,奖品类型(1:文字描述、2:兑换码、3:优惠券、4:实物奖品)
+     *
+     * @param req   物品信息
+     * @return      配送结果
+     */
+    DistributionRes doDistribution(GoodsReq req);
+
+    /**
+     * 获取配送的奖品名称
+     *
+     * @return 奖品对应的code
+     */
+    Integer getDistributionGoodsName();
+}

+ 39 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/impl/CouponGoods.java

@@ -0,0 +1,39 @@
+package com.seamew.lottery.domain.award.service.goods.impl;
+
+import com.seamew.lottery.common.Constants;
+import com.seamew.lottery.domain.award.annotation.AwardMode;
+import com.seamew.lottery.domain.award.model.req.GoodsReq;
+import com.seamew.lottery.domain.award.model.res.DistributionRes;
+import com.seamew.lottery.domain.award.service.goods.DistributionBase;
+import com.seamew.lottery.domain.award.service.goods.IDistributionGoods;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author: seamew
+ * @Title: CouponGoods
+ * @CreateTime: 2023年02月15日 10:40:00
+ * @Description: 优惠券商品
+ * @Version: 1.0
+ */
+@Component
+@Slf4j
+@AwardMode(awardMode = Constants.AwardType.CouponGoods)
+public class CouponGoods extends DistributionBase implements IDistributionGoods {
+    @Override
+    public DistributionRes doDistribution(GoodsReq req) {
+
+        // 模拟调用优惠券发放接口
+        log.info("模拟调用优惠券发放接口 uId:{} awardContent:{}", req.getUId(), req.getAwardContent());
+
+        // 更新用户领奖结果
+        updateUserAwardState(req.getUId(), req.getOrderId(), req.getAwardId(), Constants.AwardState.SUCCESS.getCode(), Constants.AwardState.SUCCESS.getInfo());
+
+        return new DistributionRes(req.getUId(), Constants.AwardState.SUCCESS.getCode(), Constants.AwardState.SUCCESS.getInfo());
+    }
+
+    @Override
+    public Integer getDistributionGoodsName() {
+        return Constants.AwardType.CouponGoods.getCode();
+    }
+}

+ 38 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/impl/DescGoods.java

@@ -0,0 +1,38 @@
+package com.seamew.lottery.domain.award.service.goods.impl;
+
+import com.seamew.lottery.common.Constants;
+import com.seamew.lottery.domain.award.annotation.AwardMode;
+import com.seamew.lottery.domain.award.model.req.GoodsReq;
+import com.seamew.lottery.domain.award.model.res.DistributionRes;
+import com.seamew.lottery.domain.award.service.goods.DistributionBase;
+import com.seamew.lottery.domain.award.service.goods.IDistributionGoods;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author: seamew
+ * @Title: DescGoods
+ * @CreateTime: 2023年02月15日 10:51:00
+ * @Description: 描述类商品,以文字形式展示给用户
+ * @Version: 1.0
+ */
+@Component
+@Slf4j
+@AwardMode(awardMode = Constants.AwardType.DESC)
+public class DescGoods extends DistributionBase implements IDistributionGoods {
+    @Override
+    public DistributionRes doDistribution(GoodsReq req) {
+        // 模拟调用描述类商品发奖
+        log.info("模拟描述类商品发奖 uId:{} awardContent:{}", req.getUId(), req.getAwardContent());
+
+        // 更新用户领奖结果
+        updateUserAwardState(req.getUId(), req.getOrderId(), req.getAwardId(), Constants.AwardState.SUCCESS.getCode(), Constants.AwardState.SUCCESS.getInfo());
+
+        return new DistributionRes(req.getUId(), Constants.AwardState.SUCCESS.getCode(), Constants.AwardState.SUCCESS.getInfo());
+    }
+
+    @Override
+    public Integer getDistributionGoodsName() {
+        return Constants.AwardType.DESC.getCode();
+    }
+}

+ 39 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/impl/PhysicalGoods.java

@@ -0,0 +1,39 @@
+package com.seamew.lottery.domain.award.service.goods.impl;
+
+import com.seamew.lottery.common.Constants;
+import com.seamew.lottery.domain.award.annotation.AwardMode;
+import com.seamew.lottery.domain.award.model.req.GoodsReq;
+import com.seamew.lottery.domain.award.model.res.DistributionRes;
+import com.seamew.lottery.domain.award.service.goods.DistributionBase;
+import com.seamew.lottery.domain.award.service.goods.IDistributionGoods;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author: seamew
+ * @Title: PhysicalGoods
+ * @CreateTime: 2023年02月15日 10:52:00
+ * @Description: 实物发货类商品
+ * @Version: 1.0
+ */
+@Component
+@Slf4j
+@AwardMode(awardMode = Constants.AwardType.PhysicalGoods)
+public class PhysicalGoods extends DistributionBase implements IDistributionGoods {
+    @Override
+    public DistributionRes doDistribution(GoodsReq req) {
+
+        // 模拟调用实物发奖
+        log.info("模拟调用实物发奖 uId:{} awardContent:{}", req.getUId(), req.getAwardContent());
+
+        // 更新用户领奖结果
+        updateUserAwardState(req.getUId(), req.getOrderId(), req.getAwardId(), Constants.AwardState.SUCCESS.getCode(), Constants.AwardState.SUCCESS.getInfo());
+
+        return new DistributionRes(req.getUId(), Constants.AwardState.SUCCESS.getCode(), Constants.AwardState.SUCCESS.getInfo());
+    }
+
+    @Override
+    public Integer getDistributionGoodsName() {
+        return Constants.AwardType.PhysicalGoods.getCode();
+    }
+}

+ 39 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/award/service/goods/impl/RedeemCodeGoods.java

@@ -0,0 +1,39 @@
+package com.seamew.lottery.domain.award.service.goods.impl;
+
+import com.seamew.lottery.common.Constants;
+import com.seamew.lottery.domain.award.annotation.AwardMode;
+import com.seamew.lottery.domain.award.model.req.GoodsReq;
+import com.seamew.lottery.domain.award.model.res.DistributionRes;
+import com.seamew.lottery.domain.award.service.goods.DistributionBase;
+import com.seamew.lottery.domain.award.service.goods.IDistributionGoods;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author: seamew
+ * @Title: RedeemCodeGoods
+ * @CreateTime: 2023年02月15日 10:54:00
+ * @Description: 兑换码类商品
+ * @Version: 1.0
+ */
+@Component
+@Slf4j
+@AwardMode(awardMode = Constants.AwardType.RedeemCodeGoods)
+public class RedeemCodeGoods extends DistributionBase implements IDistributionGoods {
+    @Override
+    public DistributionRes doDistribution(GoodsReq req) {
+
+        // 模拟调用兑换码
+        log.info("模拟调用兑换码 uId:{} awardContent:{}", req.getUId(), req.getAwardContent());
+
+        // 更新用户领奖结果
+        updateUserAwardState(req.getUId(), req.getOrderId(), req.getAwardId(), Constants.AwardState.SUCCESS.getCode(), Constants.AwardState.SUCCESS.getInfo());
+
+        return new DistributionRes(req.getUId(), Constants.AwardState.SUCCESS.getCode(), Constants.AwardState.SUCCESS.getInfo());
+    }
+
+    @Override
+    public Integer getDistributionGoodsName() {
+        return Constants.AwardType.RedeemCodeGoods.getCode();
+    }
+}

+ 16 - 1
lottery-domain/src/main/java/com/seamew/lottery/domain/strategy/model/vo/DrawAwardInfo.java

@@ -18,10 +18,25 @@ public class DrawAwardInfo {
     /**
      * 奖品ID
      */
-    private String rewardId;
+    private String awardId;
+
+    /**
+     * 奖品类型(1:文字描述、2:兑换码、3:优惠券、4:实物奖品)
+     */
+    private Integer awardType;
 
     /**
      * 奖品名称
      */
     private String awardName;
+
+    /**
+     * 奖品内容「描述、奖品码、sku」
+     */
+    private String awardContent;
+
+    public DrawAwardInfo(String awardId, String awardName) {
+        this.awardId = awardId;
+        this.awardName = awardName;
+    }
 }

+ 6 - 0
lottery-domain/src/main/java/com/seamew/lottery/domain/strategy/repository/IStrategyRepository.java

@@ -13,6 +13,12 @@ import java.util.List;
  * @Version: 1.0
  */
 public interface IStrategyRepository {
+    /**
+     * 查询策略详情
+     *
+     * @param strategyId 策略ID
+     * @return 策略详情
+     */
     StrategyRich queryStrategyRich(Long strategyId);
 
     Award queryAwardInfo(String awardId);

+ 1 - 2
lottery-domain/src/main/java/com/seamew/lottery/domain/strategy/service/draw/AbstractDrawBase.java

@@ -107,9 +107,8 @@ public abstract class AbstractDrawBase extends DrawStrategySupport implements ID
         }
 
         Award award = queryAwardInfoByAwardId(awardId);
-        DrawAwardInfo drawAwardInfo = new DrawAwardInfo(award.getAwardId(), award.getAwardName());
+        DrawAwardInfo drawAwardInfo = new DrawAwardInfo(award.getAwardId(), award.getAwardType(), award.getAwardName(), award.getAwardContent());
         log.info("执行策略抽奖完成【已中奖】,用户:{} 策略ID:{} 奖品ID:{} 奖品名称:{}", uId, strategyId, awardId, award.getAwardName());
-
         return new DrawResult(uId, strategyId, Constants.DrawState.SUCCESS.getCode(), drawAwardInfo);
     }
 

+ 3 - 3
lottery-domain/src/main/java/com/seamew/lottery/domain/strategy/service/draw/DrawConfig.java

@@ -28,10 +28,10 @@ public class DrawConfig {
 
     @PostConstruct
     public void init() {
-        algorithmList.forEach(r -> {
-            StrategyMode strategyMode = AnnotationUtils.findAnnotation(r.getClass(), StrategyMode.class);
+        algorithmList.forEach(element -> {
+            StrategyMode strategyMode = AnnotationUtils.findAnnotation(element.getClass(), StrategyMode.class);
             if (strategyMode != null) {
-                drawAlgorithmGroup.put(strategyMode.strategyMode().getCode(), r);
+                drawAlgorithmGroup.put(strategyMode.strategyMode().getCode(), element);
             }
         });
     }

+ 5 - 5
lottery-interfaces/src/main/resources/mybatis/mapper/Activity_Mapper.xml

@@ -4,18 +4,18 @@
 
     <insert id="insert" parameterType="com.seamew.lottery.infrastructure.po.Activity">
         INSERT INTO activity
-        (activityId, activityName, activityDesc,beginDateTime, endDateTime,
-         stockCount, takeCount, state, creator, createTime, updateTime)
+        (activity_id, activity_name, activity_desc, begin_date_time, end_date_time,
+         stock_count, take_count, state, creator, create_time, update_time)
         VALUES
             (#{activityId}, #{activityName}, #{activityDesc},#{beginDateTime}, #{endDateTime},
              #{stockCount}, #{takeCount}, #{state}, #{creator}, now(), now())
     </insert>
 
     <select id="queryActivityById" parameterType="java.lang.Long" resultType="com.seamew.lottery.infrastructure.po.Activity">
-        SELECT activityId, activityName, activityDesc,beginDateTime, endDateTime,
-               stockCount, takeCount, state, creator, createTime, updateTime
+        SELECT activity_id, activity_name, activity_desc, begin_date_time, end_date_time,
+               stock_count, take_count, state, creator, create_time, update_time
         FROM activity
-        WHERE activityId = #{activityId}
+        WHERE activity_id = #{activityId}
     </select>
 
 

+ 2 - 2
lottery-interfaces/src/main/resources/mybatis/mapper/Award_Mapper.xml

@@ -4,9 +4,9 @@
 
     <select id="queryAwardInfo" parameterType="java.lang.String" resultType="com.seamew.lottery.infrastructure.po.Award">
         SELECT
-            id, awardId, awardType, awardCount, awardName, awardContent, createTime, updateTime
+            id, award_id, award_type, award_name, award_content
         FROM award
-        WHERE awardId = #{awardId}
+        WHERE award_id = #{awardId}
     </select>
 
 </mapper>

+ 7 - 7
lottery-interfaces/src/main/resources/mybatis/mapper/StrategyDetail_Mapper.xml

@@ -3,21 +3,21 @@
 <mapper namespace="com.seamew.lottery.infrastructure.dao.IStrategyDetailDao">
 
     <select id="queryStrategyDetailList" parameterType="java.lang.Long" resultType="com.seamew.lottery.infrastructure.po.StrategyDetail">
-        SELECT id, strategyId, awardId, awardCount, awardSurplusCount,
-               awardRate, createTime, updateTime
+        SELECT id, strategy_id, award_id, award_count, award_surplus_count,
+               award_rate, create_time, update_time
         FROM strategy_detail
-        WHERE strategyId = #{strategyId}
+        WHERE strategy_id = #{strategyId}
     </select>
 
     <select id="queryNoStockStrategyAwardList" parameterType="java.lang.Long" resultType="java.lang.String">
-        SELECT awardId
+        SELECT award_id AS awardId
         FROM strategy_detail
-        WHERE strategyId = #{strategyId} AND awardSurplusCount = 0
+        WHERE strategy_id = #{strategyId} AND award_surplus_count = 0
     </select>
 
     <update id="deductStock" parameterType="com.seamew.lottery.infrastructure.po.StrategyDetail">
-        UPDATE strategy_detail SET awardSurplusCount = awardSurplusCount - 1
-        WHERE strategyId = #{strategyId} AND awardId = #{awardId} AND awardSurplusCount > 0
+        UPDATE strategy_detail SET award_surplus_count = award_surplus_count - 1
+        WHERE strategy_id = #{strategyId} AND award_id = #{awardId} AND award_surplus_count > 0
     </update>
 
 </mapper>

+ 3 - 3
lottery-interfaces/src/main/resources/mybatis/mapper/Strategy_Mapper.xml

@@ -4,10 +4,10 @@
 
     <select id="queryStrategy" parameterType="java.lang.Long" resultType="com.seamew.lottery.infrastructure.po.Strategy">
         SELECT
-            id, strategyId, strategyDesc, strategyMode, grantType,
-            grantDate, extInfo , createTime, updateTime
+            id, strategy_id, strategy_desc, strategy_mode, grant_type,
+            grant_date, ext_info, create_time, update_time
         FROM strategy
-        WHERE strategyId = #{strategyId}
+        WHERE strategy_id = #{strategyId}
     </select>
 
 </mapper>

+ 37 - 8
lottery-interfaces/src/test/java/com/seamew/lottery/test/DrawAlgorithmTest.java

@@ -1,7 +1,16 @@
 package com.seamew.lottery.test;
 
+import com.alibaba.fastjson2.JSON;
+import com.seamew.lottery.common.Constants;
+import com.seamew.lottery.domain.award.model.req.GoodsReq;
+import com.seamew.lottery.domain.award.model.res.DistributionRes;
+import com.seamew.lottery.domain.award.service.factory.DistributionGoodsFactory;
+import com.seamew.lottery.domain.award.service.goods.IDistributionGoods;
 import com.seamew.lottery.domain.strategy.model.req.DrawReq;
+import com.seamew.lottery.domain.strategy.model.res.DrawResult;
+import com.seamew.lottery.domain.strategy.model.vo.DrawAwardInfo;
 import com.seamew.lottery.domain.strategy.service.draw.IDrawExec;
+import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -18,21 +27,41 @@ import javax.annotation.Resource;
  */
 @RunWith(SpringRunner.class)
 @SpringBootTest
+@Slf4j
 public class DrawAlgorithmTest {
     @Resource
     private IDrawExec drawExec;
 
+    @Resource
+    private DistributionGoodsFactory distributionGoodsFactory;
+
     @Test
     public void test_drawExec() {
         drawExec.doDrawExec(new DrawReq("小佳佳", 10001L));
-        // drawExec.doDrawExec(new DrawReq("小佳佳", 10001L));
-        // drawExec.doDrawExec(new DrawReq("小蜗牛", 10001L));
-        // drawExec.doDrawExec(new DrawReq("八杯水", 10001L));
-        // for (int i = 0; i < 100; i++) {
-        //     new Thread(() -> {
-        //         drawExec.doDrawExec(new DrawReq("小傅哥", 10001L));
-        //     }).start();
-        // }
     }
 
+    @Test
+    public void test_award() {
+        // 执行抽奖
+        DrawResult drawResult = drawExec.doDrawExec(new DrawReq("admin", 10001L));
+
+        // 判断抽奖结果
+        Integer drawState = drawResult.getDrawState();
+        if (Constants.DrawState.FAIL.getCode().equals(drawState)) {
+            log.info("未中奖 DrawAwardInfo is null");
+            return;
+        }
+
+        // 封装发奖参数,orderId:2109313442431 为模拟ID,需要在用户参与领奖活动时生成
+        DrawAwardInfo drawAwardInfo = drawResult.getDrawAwardInfo();
+        GoodsReq goodsReq = new GoodsReq(drawResult.getUId(), "2109313442431", drawAwardInfo.getAwardId(), drawAwardInfo.getAwardName(), drawAwardInfo.getAwardContent());
+
+        // 根据 awardType 从抽奖工厂中获取对应的发奖服务
+        IDistributionGoods distributionGoodsService = distributionGoodsFactory.getDistributionGoodsService(drawAwardInfo.getAwardType());
+        DistributionRes distributionRes = distributionGoodsService.doDistribution(goodsReq);
+
+        log.info("测试结果:{}", JSON.toJSONString(distributionRes));
+    }
+
+
 }

+ 0 - 5
pom.xml

@@ -37,11 +37,6 @@
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
         </dependency>
-        <dependency>
-            <groupId>log4j</groupId>
-            <artifactId>log4j</artifactId>
-            <version>1.2.17</version>
-        </dependency>
     </dependencies>
 
     <dependencyManagement>