|
|
@ -440,7 +440,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
a++; |
|
|
|
} |
|
|
|
} |
|
|
|
over = a / userJoinList.size() * 100; |
|
|
|
over = a * 100 / userJoinList.size(); |
|
|
|
} |
|
|
|
completedData.setTotalTimes(totalTimes); |
|
|
|
completedData.setTotalScore(totalScore); |
|
|
@ -528,14 +528,27 @@ public class ScreenService implements IScreenService{ |
|
|
|
}); |
|
|
|
//更新用户游戏开始时间和结束时间
|
|
|
|
gameUserJoinDao.updateTimeBatch(gameRecord.getId(), gameRecord.getStartTime(), gameRecord.getEndTime()); |
|
|
|
//查询游戏用户,通知游戏开始和结束
|
|
|
|
List<ClientDto.RedisUser> userJoins = sendMsg.getAllScore(gameRecord); |
|
|
|
|
|
|
|
//推送客户端
|
|
|
|
pushClient(gameRecord, executor, userJoins); |
|
|
|
//返回大屏开始时间
|
|
|
|
ScreenVo.StartGame startGame = new ScreenVo.StartGame(); |
|
|
|
startGame.setStartLocalTime(gameRecord.getStartTime() + moreTime); |
|
|
|
|
|
|
|
// 查询参与游戏的用户,添加到redis
|
|
|
|
GameUserJoinExample joinExample = new GameUserJoinExample(); |
|
|
|
joinExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()); |
|
|
|
List<GameUserJoin> userJoins = gameUserJoinDao.selectByExample(joinExample); |
|
|
|
if (CollectionUtil.isEmpty(userJoins)) { |
|
|
|
return startGame; |
|
|
|
} |
|
|
|
userJoins.forEach( userJoin -> { |
|
|
|
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin); |
|
|
|
redisUtil.zsSet(GameConstant.generateGameKey(gameRecord.getId()), JSON.toJSONString(user), 0, GameConstant.REDIS_TIME); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
//推送客户端
|
|
|
|
pushClient(gameRecord, executor); |
|
|
|
|
|
|
|
return startGame; |
|
|
|
} |
|
|
|
|
|
|
@ -545,12 +558,15 @@ public class ScreenService implements IScreenService{ |
|
|
|
* 推送客户端状态 |
|
|
|
* @param gameRecord |
|
|
|
* @param executor |
|
|
|
* @param userJoins |
|
|
|
*/ |
|
|
|
private void pushClient(GameRecord gameRecord, ScheduledExecutorService executor, List<ClientDto.RedisUser> userJoins) { |
|
|
|
private void pushClient(GameRecord gameRecord, ScheduledExecutorService executor) { |
|
|
|
|
|
|
|
new Thread(()->{ |
|
|
|
sendMsg.sendMsg(executor, 0, ()->{ |
|
|
|
try { |
|
|
|
//查询游戏用户,通知游戏倒计时
|
|
|
|
List<ClientDto.RedisUser> userJoins = sendMsg.getAllScore(gameRecord); |
|
|
|
log.info("通知倒计时:{}", gameRecord); |
|
|
|
sendMsg.sendStatus(gameRecord, userJoins, GameConstant.GAME_PREPARATION); |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
e.printStackTrace(); |
|
|
@ -558,7 +574,10 @@ public class ScreenService implements IScreenService{ |
|
|
|
}); |
|
|
|
long startTime = gameRecord.getStartTime() - System.currentTimeMillis(); |
|
|
|
sendMsg.sendMsg(executor, startTime > 0 ? startTime : 0, ()->{ |
|
|
|
//查询游戏用户,通知游戏开始
|
|
|
|
List<ClientDto.RedisUser> userJoins = sendMsg.getAllScore(gameRecord); |
|
|
|
try { |
|
|
|
log.info("通知游戏进行中:{}", gameRecord); |
|
|
|
sendMsg.sendStatus(gameRecord, userJoins, GameConstant.GAME_PROCESSING); |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
e.printStackTrace(); |
|
|
@ -569,7 +588,9 @@ public class ScreenService implements IScreenService{ |
|
|
|
System.out.println("游戏结束"); |
|
|
|
sendMsg.sendMsg(executor, endTime > 0 ? endTime : 0, ()->{ |
|
|
|
try { |
|
|
|
System.out.println("-----游戏结束"); |
|
|
|
//查询游戏用户,通知游戏结束
|
|
|
|
List<ClientDto.RedisUser> userJoins = sendMsg.getAllScore(gameRecord); |
|
|
|
log.info("通知游戏结束:{}", gameRecord); |
|
|
|
sendMsg.sendStatus(gameRecord, userJoins, GameConstant.GAME_COMPLETED); |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
e.printStackTrace(); |
|
|
@ -577,6 +598,8 @@ public class ScreenService implements IScreenService{ |
|
|
|
}); |
|
|
|
|
|
|
|
}).start(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|