|
|
|
@ -42,6 +42,8 @@ import java.util.concurrent.*; |
|
|
|
@Service |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|
|
|
public class ScreenService implements IScreenService { |
|
|
|
@Autowired |
|
|
|
private ClientService clientService; |
|
|
|
@Autowired |
|
|
|
private GameUserPayDao gameUserPayDao; |
|
|
|
@Autowired |
|
|
|
@ -74,6 +76,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 传入用户信息,返回游戏大屏路径 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@ -127,8 +130,16 @@ public class ScreenService implements IScreenService{ |
|
|
|
gameRecord.setId(snowflake.nextId()); |
|
|
|
gameRecord.setUserPayId(gameUserPay.getId()); |
|
|
|
gameRecord.setTaskId(memberGame.getTaskId()); |
|
|
|
gameRecord.setUrl(WebConstant.TEST_URL_GAME + gameType.getScreenUrl() + "?id="+gameRecord.getId()); |
|
|
|
gameRecord.setQrCodeUrl(WebConstant.TEST_URL_GAME + gameRecord.getId() + File.separator + gameType.getClientUrl()); |
|
|
|
//添加路径
|
|
|
|
String gameUrl = WebConstant.TEST_URL_GAME_SQ; |
|
|
|
switch (gameType.getCode()){ |
|
|
|
case GameConstant.GAME_TYPE_SQ: break; |
|
|
|
case GameConstant.GAME_TYPE_SP: gameUrl = WebConstant.TEST_URL_GAME_SP; break; |
|
|
|
case GameConstant.GAME_TYPE_BH: gameUrl = WebConstant.TEST_URL_GAME_BH; break; |
|
|
|
default:break; |
|
|
|
} |
|
|
|
gameRecord.setUrl(gameUrl + gameType.getScreenUrl() + "?id=" + gameRecord.getId()); |
|
|
|
gameRecord.setQrCodeUrl(gameUrl + gameRecord.getId() + File.separator + gameType.getClientUrl()); |
|
|
|
gameRecordDao.insertSelective(gameRecord); |
|
|
|
//4、 判断是否有分组,如果是分组游戏,添加两条分组信息
|
|
|
|
if (gameType.getIsGroup() == 1) { |
|
|
|
@ -136,11 +147,13 @@ public class ScreenService implements IScreenService{ |
|
|
|
gameGroupRed.setId(snowflake.nextId()); |
|
|
|
gameGroupRed.setRecordId(gameRecord.getId()); |
|
|
|
gameGroupRed.setName(memberGame.getFirstTeam()); |
|
|
|
gameGroupRed.setCode(GameConstant.FIRST_GROUP); |
|
|
|
gameGroupDao.insertSelective(gameGroupRed); |
|
|
|
GameGroup gameGroupBlue = new GameGroup(); |
|
|
|
gameGroupBlue.setId(snowflake.nextId()); |
|
|
|
gameGroupBlue.setRecordId(gameRecord.getId()); |
|
|
|
gameGroupBlue.setName(memberGame.getSecondTeam()); |
|
|
|
gameGroupBlue.setCode(GameConstant.SECOND_GROUP); |
|
|
|
gameGroupDao.insertSelective(gameGroupBlue); |
|
|
|
} |
|
|
|
|
|
|
|
@ -175,6 +188,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取游戏基本信息 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@ -204,22 +218,9 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
//总人数
|
|
|
|
gameInfoVo.setTotalMembers(totalUsers == null ? 0 : totalUsers.intValue()); |
|
|
|
|
|
|
|
//获取分组信息
|
|
|
|
GameGroupExample gameGroupExample = new GameGroupExample(); |
|
|
|
gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()); |
|
|
|
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample); |
|
|
|
if(CollectionUtil.isNotEmpty(gameGroupList)){ |
|
|
|
List<ScreenVo.Group> groups = new ArrayList<>(); |
|
|
|
for(GameGroup gameGroup:gameGroupList){ |
|
|
|
ScreenVo.Group group = new ScreenVo.Group(); |
|
|
|
group.setGroupId(gameGroup.getId()); |
|
|
|
group.setGroupName(gameGroup.getName()); |
|
|
|
groups.add(group); |
|
|
|
} |
|
|
|
gameInfoVo.setGroups(groups); |
|
|
|
} |
|
|
|
|
|
|
|
//获取分组的信息
|
|
|
|
List<ScreenVo.GroupVo> groupVo = getGroupScore(gameRecord.getId()); |
|
|
|
gameInfoVo.setGroups(groupVo); |
|
|
|
switch (gameInfoVo.getGameStatus()) { |
|
|
|
case 0: |
|
|
|
ScreenVo.PendingData pendingData = new ScreenVo.PendingData(); |
|
|
|
@ -268,7 +269,6 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取游戏状态 |
|
|
|
*/ |
|
|
|
@ -284,8 +284,9 @@ public class ScreenService implements IScreenService{ |
|
|
|
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId()); |
|
|
|
|
|
|
|
gameStatusVo.setGameStatus(gameRecord.getGameStatus()); |
|
|
|
|
|
|
|
|
|
|
|
//获取分组的信息
|
|
|
|
List<ScreenVo.GroupVo> groupVo = getGroupScore(gameRecord.getId()); |
|
|
|
gameStatusVo.setGroups(groupVo); |
|
|
|
// 查询总人数
|
|
|
|
Long total = redisUtil.zsGetSize(GameConstant.generateGameKey(gameRecord.getId())); |
|
|
|
log.info("redis查询gameRecordID:{}总人数:{}", gameRecord.getId(), total); |
|
|
|
@ -296,10 +297,11 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
gameStatusVo.setTotalMembers(total == null ? 0 : total.intValue()); |
|
|
|
|
|
|
|
|
|
|
|
switch (gameStatusVo.getGameStatus()) { |
|
|
|
case 0: |
|
|
|
case GameConstant.GAME_PENDING: |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
case GameConstant.GAME_PREPARATION: |
|
|
|
ScreenVo.PreparingData preparingData = new ScreenVo.PreparingData(); |
|
|
|
if (ObjectUtil.isNull(params.getUserId())) { |
|
|
|
// 无userId,默认大屏,获取大屏的游戏开始时间
|
|
|
|
@ -311,7 +313,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
gameStatusVo.setPreparingData(preparingData); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
case GameConstant.GAME_PROCESSING: |
|
|
|
//查询游戏是否有分组
|
|
|
|
if (gameType.getIsGroup() == 0) { |
|
|
|
//普通游戏返回前十名的信息
|
|
|
|
@ -326,7 +328,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
gameStatusVo.setProcessingData(groupVoList); |
|
|
|
} |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
case GameConstant.GAME_COMPLETED: |
|
|
|
ScreenVo.CompletedData completedData = null; |
|
|
|
if (gameType.getIsGroup() == 0) { |
|
|
|
completedData = getCompletedData(memberRecord.getMemberRecord()); |
|
|
|
@ -355,6 +357,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
ScreenVo.GroupVo groupVo = new ScreenVo.GroupVo(); |
|
|
|
groupVo.setGroupId(gameGroup.getId()); |
|
|
|
groupVo.setGroupName(gameGroup.getName()); |
|
|
|
groupVo.setCode(gameGroup.getCode()); |
|
|
|
|
|
|
|
Map<String, Object> group = getGroupTotalScore(gameGroup.getId()); |
|
|
|
if (CollectionUtil.isNotEmpty(group)) { |
|
|
|
@ -400,6 +403,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
return completedData; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取队伍的总分 |
|
|
|
*/ |
|
|
|
@ -428,6 +432,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询总分数,总次数,平均以及前十名 |
|
|
|
* |
|
|
|
* @param gameRecordId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -471,6 +476,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询参加游戏的用户信息 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param gameRecordId |
|
|
|
* @return |
|
|
|
@ -488,6 +494,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询游戏信息 |
|
|
|
* |
|
|
|
* @param gameRecordId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -508,6 +515,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询前十名 |
|
|
|
* |
|
|
|
* @param gameRecordId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -563,8 +571,16 @@ public class ScreenService implements IScreenService{ |
|
|
|
gameRecordNew = new GameRecord(); |
|
|
|
gameRecordNew.setId(snowflake.nextId()); |
|
|
|
gameRecordNew.setUserPayId(gameUserPay.getId()); |
|
|
|
gameRecordNew.setUrl(WebConstant.TEST_URL_GAME + gameType.getScreenUrl() + "?id="+gameRecordNew.getId()); |
|
|
|
gameRecordNew.setQrCodeUrl(WebConstant.TEST_URL_GAME + gameRecordNew.getId() + File.separator + gameType.getClientUrl()); |
|
|
|
//添加路径
|
|
|
|
String gameUrl = WebConstant.TEST_URL_GAME_SQ; |
|
|
|
switch (gameType.getCode()){ |
|
|
|
case GameConstant.GAME_TYPE_SQ: break; |
|
|
|
case GameConstant.GAME_TYPE_SP: gameUrl = WebConstant.TEST_URL_GAME_SP ; break; |
|
|
|
case GameConstant.GAME_TYPE_BH: gameUrl = WebConstant.TEST_URL_GAME_BH; break; |
|
|
|
default:break; |
|
|
|
} |
|
|
|
gameRecordNew.setUrl(gameUrl + gameType.getScreenUrl() + "?id=" + gameRecordNew.getId()); |
|
|
|
gameRecordNew.setQrCodeUrl(gameUrl+ gameRecordNew.getId() + File.separator + gameType.getClientUrl()); |
|
|
|
gameRecordDao.insertSelective(gameRecordNew); |
|
|
|
//修改购买的游戏的使用次数
|
|
|
|
gameUserPay.setUsedCount(gameUserPay.getUsedCount() + 1); |
|
|
|
@ -613,6 +629,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
return ruleList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询活动奖品 |
|
|
|
*/ |
|
|
|
@ -632,6 +649,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
return prizeList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 奖券使用说明表 |
|
|
|
*/ |
|
|
|
@ -683,11 +701,9 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 开始游戏 |
|
|
|
* |
|
|
|
* @param start |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -704,8 +720,10 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
//判断游戏状态,仅未开始允许操作开始
|
|
|
|
switch (gameRecord.getGameStatus().byteValue()) { |
|
|
|
case GameConstant.GAME_PREPARATION: throw new BaseException(CodeEnum.GAME_PREPARATION); |
|
|
|
case GameConstant.GAME_PROCESSING: throw new BaseException(CodeEnum.GAME_PROCESSING); |
|
|
|
case GameConstant.GAME_PREPARATION: |
|
|
|
throw new BaseException(CodeEnum.GAME_PREPARATION); |
|
|
|
case GameConstant.GAME_PROCESSING: |
|
|
|
throw new BaseException(CodeEnum.GAME_PROCESSING); |
|
|
|
case GameConstant.GAME_COMPLETED: |
|
|
|
if (start.getStartStatus() == null || start.getStartStatus().byteValue() != GameConstant.GAME_RESTART_STATUS) { |
|
|
|
throw new BaseException(CodeEnum.GAME_COMPLETED); |
|
|
|
@ -779,7 +797,14 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(userJoins)) { |
|
|
|
userJoins.forEach(userJoin -> { |
|
|
|
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin); |
|
|
|
Long groupId = null; |
|
|
|
GameUserJoinGroupExample joinGroupExample = new GameUserJoinGroupExample(); |
|
|
|
joinGroupExample.createCriteria().andUserJoinIdEqualTo(userJoin.getId()); |
|
|
|
List<GameUserJoinGroup> gameUserJoinGroups = gameUserJoinGroupDao.selectByExample(joinGroupExample); |
|
|
|
if (CollectionUtil.isNotEmpty(gameUserJoinGroups)) { |
|
|
|
groupId = gameUserJoinGroups.get(0).getGameGroupId(); |
|
|
|
} |
|
|
|
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin, groupId); |
|
|
|
redisUtil.zsSet(GameConstant.generateGameKey(gameRecord.getId()), JSON.toJSONString(user), 0, GameConstant.REDIS_TIME); |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -791,9 +816,9 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 推送客户端状态 |
|
|
|
* |
|
|
|
* @param gameRecord |
|
|
|
* @param executor |
|
|
|
*/ |
|
|
|
|