|
@@ -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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|