|
@@ -1,7 +1,16 @@
|
|
package com.seamew.lottery.test;
|
|
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.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 com.seamew.lottery.domain.strategy.service.draw.IDrawExec;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
@@ -18,21 +27,41 @@ import javax.annotation.Resource;
|
|
*/
|
|
*/
|
|
@RunWith(SpringRunner.class)
|
|
@RunWith(SpringRunner.class)
|
|
@SpringBootTest
|
|
@SpringBootTest
|
|
|
|
+@Slf4j
|
|
public class DrawAlgorithmTest {
|
|
public class DrawAlgorithmTest {
|
|
@Resource
|
|
@Resource
|
|
private IDrawExec drawExec;
|
|
private IDrawExec drawExec;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private DistributionGoodsFactory distributionGoodsFactory;
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void test_drawExec() {
|
|
public void test_drawExec() {
|
|
drawExec.doDrawExec(new DrawReq("小佳佳", 10001L));
|
|
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));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|