kk 1 тиждень тому
батько
коміт
3e5711a5f9

+ 117 - 0
game-business/src/main/java/com/game/business/task/AppGameHanaderTask.java

@@ -0,0 +1,117 @@
+package com.game.business.task;
+
+
+import com.game.business.domain.AppGame;
+import com.game.business.domain.AppGameLottery;
+import com.game.business.service.IAppGameLotteryService;
+import com.game.business.service.IAppGameService;
+import com.game.common.utils.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+@Component
+public class AppGameHanaderTask {
+
+    @Autowired
+    private IAppGameService appGameService;
+
+    @Autowired
+    private IAppGameLotteryService appGameLotteryService;
+
+    @Autowired
+    private AppGameLotteryAutoTask appGameLotteryAutoTask;
+
+    @Autowired
+    private AppGameLotteryTask appGameLotteryTask;
+
+    public void initGameCountdown(String gameCode){
+
+        AppGame appGame = appGameService.selectAppGameByCode(gameCode);
+
+        if(appGame == null) return;
+
+        int countdown = 52;
+
+        while (true){
+
+            try {
+
+                // 推送倒计时
+
+                // 开奖
+                if(countdown == 7){
+                    this.lotteryManager(appGame.getId());
+                }
+
+                // 更新游戏信息
+                this.updateAppGameTime(appGame.getId(), countdown);
+
+                // 重新开启倒计时
+                if(countdown ==  0){
+                    countdown = 53;
+                }
+
+                Thread.sleep(1000L);
+                countdown --;
+            }catch (Exception e){
+                e.printStackTrace();
+                break;
+            }
+        }
+    }
+
+    @Async("asyncExecutor")
+    public void updateAppGameTime(Long gameId, int countdown){
+
+        String time = "00:";
+        if(countdown < 10){
+            time = time + "0" + countdown;
+        }else{
+            time = time + countdown;
+        }
+
+        // TODO 更新时间
+        AppGame appGame = new AppGame();
+        appGame.setId(gameId);
+        appGame.setGameTime(time);
+
+        if(countdown == 0){
+            appGame.setGameDate(DateUtils.dateTimeNow());
+        }
+        appGameService.updateAppGame(appGame);
+    }
+
+    @Async("asyncExecutor")
+    public void lotteryManager(Long gameId){
+        try {
+
+            // 游戏信息
+            AppGame appGame = appGameService.selectAppGameById(gameId);
+
+            // 是否已开奖
+            AppGameLottery dbAppGameLottery = appGameLotteryService.selectLottery(appGame.getClassifyId(), appGame.getId(), appGame.getGameDate());
+            if(dbAppGameLottery != null && dbAppGameLottery.getIsLottery() == 1){
+                return;
+            }
+
+            String gameLotterySucc = appGameLotteryAutoTask.autoTask(appGame, appGame.getGameDate());
+
+            // 保存开奖记录
+            AppGameLottery appGameLottery = new AppGameLottery();
+            appGameLottery.setGameId(appGame.getId());
+            appGameLottery.setClassId(appGame.getClassifyId());
+            appGameLottery.setGameDate(appGame.getGameDate());
+            appGameLottery.setIsLottery(1);
+            appGameLottery.setGameRecordDate(new Date());
+            appGameLottery.setGameLotterySucc(gameLotterySucc);
+            if(appGameLotteryService.save(appGameLottery)){
+                appGameLotteryTask.updateLottery(appGameLottery);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+}

+ 1 - 1
game-business/src/main/java/com/game/business/task/AppGameLotteryAutoTask.java

@@ -119,7 +119,7 @@ public class AppGameLotteryAutoTask {
         long count = appGameLotteryService.selectCountAuto(appGame.getClassifyId(), appGame.getId(), DateUtils.dateTime(new Date()));
 
         // 开始走最低开盘
-        if(count > 500 && diamondCoinWin.subtract(diamondCoinSum).compareTo(BigDecimal.ZERO) > 0){
+        if(count > 500 && diamondCoinWin.subtract(diamondCoinSum.multiply(new BigDecimal("0.8"))).compareTo(BigDecimal.ZERO) > 0){
 
             // 随机开奖
             if(lottertAmount - diamondCoinGameDateSum > 0){