|
|
@ -41,7 +41,9 @@ import java.util.concurrent.*; |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|
|
|
public class ScreenService implements IScreenService{ |
|
|
|
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 |
|
|
@ -84,10 +87,10 @@ public class ScreenService implements IScreenService{ |
|
|
|
GameTypeExample gameTypeExample = new GameTypeExample(); |
|
|
|
gameTypeExample.createCriteria().andCodeEqualTo(memberGame.getGameType()); |
|
|
|
List<GameType> gameTypeList = gameTypeDao.selectByExample(gameTypeExample); |
|
|
|
if(CollectionUtil.isNotEmpty(gameTypeList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(gameTypeList)) { |
|
|
|
gameType = gameTypeList.get(0); |
|
|
|
} |
|
|
|
if(ObjectUtil.isNull(gameType)){ |
|
|
|
if (ObjectUtil.isNull(gameType)) { |
|
|
|
throw new BaseException(CodeEnum.NOT_GAME_TYPE); |
|
|
|
} |
|
|
|
//2、查找此用户购买的此游戏的信息,若没有则添加一条记录,默认已付款,结束时间为添加后的一个月,默认次数为10次
|
|
|
@ -95,9 +98,9 @@ public class ScreenService implements IScreenService{ |
|
|
|
GameUserPayExample gameUserPayExample = new GameUserPayExample(); |
|
|
|
gameUserPayExample.createCriteria().andUserIdEqualTo(params.getUserId()).andGameTypeIdEqualTo(gameType.getId()); |
|
|
|
List<GameUserPay> gameUserPayList = gameUserPayDao.selectByExample(gameUserPayExample); |
|
|
|
if(CollectionUtil.isNotEmpty(gameUserPayList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(gameUserPayList)) { |
|
|
|
gameUserPay = gameUserPayList.get(0); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
gameUserPay = new GameUserPay(); |
|
|
|
gameUserPay.setId(snowflake.nextId()); |
|
|
|
gameUserPay.setUserId(params.getUserId()); |
|
|
@ -105,11 +108,11 @@ public class ScreenService implements IScreenService{ |
|
|
|
gameUserPay.setTotalCount(10); |
|
|
|
gameUserPay.setUsedCount(0); |
|
|
|
gameUserPay.setCreatedTime(System.currentTimeMillis()); |
|
|
|
gameUserPay.setDueTime(gameUserPay.getCreatedTime() + (3600*24*30)); |
|
|
|
gameUserPay.setDueTime(gameUserPay.getCreatedTime() + (3600 * 24 * 30)); |
|
|
|
gameUserPayDao.insertSelective(gameUserPay); |
|
|
|
} |
|
|
|
//查询该任务下的游戏记录信息
|
|
|
|
if(ObjectUtil.isNotNull(memberGame.getTaskId())) { |
|
|
|
if (ObjectUtil.isNotNull(memberGame.getTaskId())) { |
|
|
|
GameRecordExample recordExample = new GameRecordExample(); |
|
|
|
recordExample.createCriteria().andTaskIdEqualTo(memberGame.getTaskId()); |
|
|
|
recordExample.setOrderByClause("created_at DESC"); |
|
|
@ -127,20 +130,30 @@ 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){ |
|
|
|
if (gameType.getIsGroup() == 1) { |
|
|
|
GameGroup gameGroupRed = new GameGroup(); |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
@ -153,15 +166,15 @@ public class ScreenService implements IScreenService{ |
|
|
|
urlVo.setRuleList(ruleList); |
|
|
|
|
|
|
|
//路径(添加项目id)
|
|
|
|
String url = gameRecord.getUrl() + "&projectId="+ memberGame.getProjectId(); |
|
|
|
String url = gameRecord.getUrl() + "&projectId=" + memberGame.getProjectId(); |
|
|
|
//给所有人发送消息发送消息
|
|
|
|
ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url,gameRecord.getId(),memberGame.getProjectId()); |
|
|
|
ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url, gameRecord.getId(), memberGame.getProjectId()); |
|
|
|
BaseMessageDto.MessageUser messageUser = null; |
|
|
|
List<BaseMessageDto.MessageUser> messageUserList = new ArrayList<>(); |
|
|
|
//获取项目下所有成员
|
|
|
|
List<Long> memberIdList = tallFeignClient.getMemberIdListByProject(memberGame.getProjectId()); |
|
|
|
if(CollectionUtil.isNotEmpty(memberIdList)){ |
|
|
|
for(Long memberId:memberIdList){ |
|
|
|
if (CollectionUtil.isNotEmpty(memberIdList)) { |
|
|
|
for (Long memberId : memberIdList) { |
|
|
|
messageUser = new BaseMessageDto.MessageUser(); |
|
|
|
messageUser.setUserId(memberId); |
|
|
|
messageUserList.add(messageUser); |
|
|
@ -175,6 +188,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取游戏基本信息 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
@ -187,7 +201,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
GameRecord gameRecord = getGameRecord(memberRecord.getMemberRecord()); |
|
|
|
|
|
|
|
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId()); |
|
|
|
if(ObjectUtil.isNull(gameUserPay)){ |
|
|
|
if (ObjectUtil.isNull(gameUserPay)) { |
|
|
|
throw new BaseException(CodeEnum.NOT_GAME_TYPE); |
|
|
|
} |
|
|
|
|
|
|
@ -204,23 +218,10 @@ 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); |
|
|
|
} |
|
|
|
|
|
|
|
switch (gameInfoVo.getGameStatus()){ |
|
|
|
//获取分组的信息
|
|
|
|
List<ScreenVo.GroupVo> groupVo = getGroupScore(gameRecord.getId()); |
|
|
|
gameInfoVo.setGroups(groupVo); |
|
|
|
switch (gameInfoVo.getGameStatus()) { |
|
|
|
case 0: |
|
|
|
ScreenVo.PendingData pendingData = new ScreenVo.PendingData(); |
|
|
|
//查询活动规则
|
|
|
@ -236,9 +237,9 @@ public class ScreenService implements IScreenService{ |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
ScreenVo.PreparingData preparingData = new ScreenVo.PreparingData(); |
|
|
|
if(ObjectUtil.isNull(params.getUserId())){ |
|
|
|
if (ObjectUtil.isNull(params.getUserId())) { |
|
|
|
preparingData.setStartLocalTime(gameRecord.getStartTime() + gameRecord.getTimeDifference()); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
GameUserJoin userJoin = getGameUserJoin(params.getUserId(), gameRecord.getId()); |
|
|
|
log.info("用户信息:{}", userJoin); |
|
|
|
if (userJoin == null) { |
|
|
@ -254,9 +255,9 @@ public class ScreenService implements IScreenService{ |
|
|
|
//查询游戏是否有分组
|
|
|
|
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId()); |
|
|
|
ScreenVo.CompletedData completedData = null; |
|
|
|
if(gameType.getIsGroup() == 0) { |
|
|
|
if (gameType.getIsGroup() == 0) { |
|
|
|
completedData = getCompletedData(memberRecord.getMemberRecord()); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
completedData = getCompletedDataByWin(memberRecord.getMemberRecord()); |
|
|
|
} |
|
|
|
gameInfoVo.setCompletedData(completedData); |
|
|
@ -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,41 +297,42 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
gameStatusVo.setTotalMembers(total == null ? 0 : total.intValue()); |
|
|
|
|
|
|
|
switch (gameStatusVo.getGameStatus()){ |
|
|
|
case 0: |
|
|
|
|
|
|
|
switch (gameStatusVo.getGameStatus()) { |
|
|
|
case GameConstant.GAME_PENDING: |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
case GameConstant.GAME_PREPARATION: |
|
|
|
ScreenVo.PreparingData preparingData = new ScreenVo.PreparingData(); |
|
|
|
if(ObjectUtil.isNull(params.getUserId())){ |
|
|
|
if (ObjectUtil.isNull(params.getUserId())) { |
|
|
|
// 无userId,默认大屏,获取大屏的游戏开始时间
|
|
|
|
preparingData.setStartLocalTime(gameRecord.getStartTime() + gameRecord.getTimeDifference()); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
// 获取用户的开始时间
|
|
|
|
GameUserJoin userJoin = getGameUserJoin(params.getUserId(), gameRecord.getId()); |
|
|
|
preparingData.setStartLocalTime(gameRecord.getStartTime() + userJoin.getTimeDifference()); |
|
|
|
} |
|
|
|
gameStatusVo.setPreparingData(preparingData); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
case GameConstant.GAME_PROCESSING: |
|
|
|
//查询游戏是否有分组
|
|
|
|
if(gameType.getIsGroup() == 0) { |
|
|
|
if (gameType.getIsGroup() == 0) { |
|
|
|
//普通游戏返回前十名的信息
|
|
|
|
ScreenVo.ProcessingData processingData = new ScreenVo.ProcessingData(); |
|
|
|
// 查询前十名(列表顺序即前十名顺序)
|
|
|
|
List<ScreenVo.TopUsers> tops = getTopUsers(gameRecordId); |
|
|
|
processingData.setTopMembers(tops); |
|
|
|
gameStatusVo.setProcessingData(processingData); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
//分组游戏则返回每个分组的信息
|
|
|
|
List<ScreenVo.GroupVo> groupVoList = getGroupScore(gameRecordId); |
|
|
|
gameStatusVo.setProcessingData(groupVoList); |
|
|
|
} |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
case GameConstant.GAME_COMPLETED: |
|
|
|
ScreenVo.CompletedData completedData = null; |
|
|
|
if(gameType.getIsGroup() == 0) { |
|
|
|
if (gameType.getIsGroup() == 0) { |
|
|
|
completedData = getCompletedData(memberRecord.getMemberRecord()); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
completedData = getCompletedDataByWin(memberRecord.getMemberRecord()); |
|
|
|
} |
|
|
|
gameStatusVo.setCompletedData(completedData); |
|
|
@ -344,20 +346,21 @@ public class ScreenService implements IScreenService{ |
|
|
|
/** |
|
|
|
* 进行中查询每个组的信息 |
|
|
|
*/ |
|
|
|
private List<ScreenVo.GroupVo> getGroupScore(Long gameRecordId){ |
|
|
|
private List<ScreenVo.GroupVo> getGroupScore(Long gameRecordId) { |
|
|
|
List<ScreenVo.GroupVo> groupVoList = new ArrayList<>(); |
|
|
|
//查询分组信息
|
|
|
|
GameGroupExample gameGroupExample = new GameGroupExample(); |
|
|
|
gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecordId); |
|
|
|
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample); |
|
|
|
if(CollectionUtil.isNotEmpty(gameGroupList)){ |
|
|
|
for(GameGroup gameGroup : gameGroupList){ |
|
|
|
if (CollectionUtil.isNotEmpty(gameGroupList)) { |
|
|
|
for (GameGroup gameGroup : gameGroupList) { |
|
|
|
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)){ |
|
|
|
Map<String, Object> group = getGroupTotalScore(gameGroup.getId()); |
|
|
|
if (CollectionUtil.isNotEmpty(group)) { |
|
|
|
List<GameUserJoin> userJoinList = (List<GameUserJoin>) group.get("userJoinList"); |
|
|
|
groupVo.setScore((Integer) group.get("totalScore")); |
|
|
|
groupVo.setTotalMembers(userJoinList.size()); |
|
|
@ -381,17 +384,17 @@ public class ScreenService implements IScreenService{ |
|
|
|
GameGroupExample gameGroupExample = new GameGroupExample(); |
|
|
|
gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecordId); |
|
|
|
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample); |
|
|
|
if(CollectionUtil.isNotEmpty(gameGroupList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(gameGroupList)) { |
|
|
|
List<GameUserJoin> userJoinList = null; |
|
|
|
//分别查找两个队伍的总分
|
|
|
|
Map<String,Object> group1 = getGroupTotalScore(gameGroupList.get(0).getId()); |
|
|
|
Map<String,Object> group2 = getGroupTotalScore(gameGroupList.get(1).getId()); |
|
|
|
if(CollectionUtil.isNotEmpty(group1) && CollectionUtil.isNotEmpty(group2)){ |
|
|
|
Map<String, Object> group1 = getGroupTotalScore(gameGroupList.get(0).getId()); |
|
|
|
Map<String, Object> group2 = getGroupTotalScore(gameGroupList.get(1).getId()); |
|
|
|
if (CollectionUtil.isNotEmpty(group1) && CollectionUtil.isNotEmpty(group2)) { |
|
|
|
int score1 = (int) group1.get("totalScore"); |
|
|
|
int score2 = (int) group1.get("totalScore"); |
|
|
|
if(score1 > score2){ |
|
|
|
if (score1 > score2) { |
|
|
|
userJoinList = (List<GameUserJoin>) group1.get("userJoinList"); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
userJoinList = (List<GameUserJoin>) group2.get("userJoinList"); |
|
|
|
} |
|
|
|
} |
|
|
@ -400,27 +403,28 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
return completedData; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取队伍的总分 |
|
|
|
*/ |
|
|
|
private Map<String,Object> getGroupTotalScore(Long groupId){ |
|
|
|
Map<String,Object> groupMap = null; |
|
|
|
private Map<String, Object> getGroupTotalScore(Long groupId) { |
|
|
|
Map<String, Object> groupMap = null; |
|
|
|
|
|
|
|
//查找队伍的参赛人
|
|
|
|
GameUserJoinGroupExample joinGroupExample = new GameUserJoinGroupExample(); |
|
|
|
joinGroupExample.createCriteria().andGameGroupIdEqualTo(groupId); |
|
|
|
List<GameUserJoinGroup> userJoinGroupList = gameUserJoinGroupDao.selectByExample(joinGroupExample); |
|
|
|
if(CollectionUtil.isNotEmpty(userJoinGroupList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(userJoinGroupList)) { |
|
|
|
groupMap = new HashMap<>(); |
|
|
|
int totalScore = 0; |
|
|
|
List<GameUserJoin> userJoinList = new ArrayList<>(); |
|
|
|
for (GameUserJoinGroup userJoinGroup : userJoinGroupList){ |
|
|
|
for (GameUserJoinGroup userJoinGroup : userJoinGroupList) { |
|
|
|
GameUserJoin userJoin = gameUserJoinDao.selectByPrimaryKey(userJoinGroup.getUserJoinId()); |
|
|
|
totalScore += userJoin.getScore(); |
|
|
|
userJoinList.add(userJoin); |
|
|
|
} |
|
|
|
groupMap.put("totalScore",totalScore); |
|
|
|
groupMap.put("userJoinList",userJoinList); |
|
|
|
groupMap.put("totalScore", totalScore); |
|
|
|
groupMap.put("userJoinList", userJoinList); |
|
|
|
} |
|
|
|
return groupMap; |
|
|
|
} |
|
|
@ -428,6 +432,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询总分数,总次数,平均以及前十名 |
|
|
|
* |
|
|
|
* @param gameRecordId |
|
|
|
* @return |
|
|
|
*/ |
|
|
@ -441,10 +446,10 @@ public class ScreenService implements IScreenService{ |
|
|
|
//总分数
|
|
|
|
completedData.setTotalScore(totalScore); |
|
|
|
// 总次数
|
|
|
|
completedData.setTotalTimes(totalScore/100); |
|
|
|
completedData.setTotalTimes(totalScore / 100); |
|
|
|
// 平均次数
|
|
|
|
int totalUsers = redisUtil.zsGetSize(key).intValue(); |
|
|
|
int averageTimes = completedData.getTotalTimes()/totalUsers; |
|
|
|
int averageTimes = completedData.getTotalTimes() / totalUsers; |
|
|
|
completedData.setAverageTimes(averageTimes); |
|
|
|
// 平均超过多少用户
|
|
|
|
int averageScore = totalScore / totalUsers; |
|
|
@ -458,7 +463,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
GameUserJoinExample gameuserJoinExample = new GameUserJoinExample(); |
|
|
|
gameuserJoinExample.createCriteria().andRecordIdEqualTo(gameRecordId); |
|
|
|
List<GameUserJoin> userJoins = gameUserJoinDao.selectByExample(gameuserJoinExample); |
|
|
|
if(CollectionUtil.isNotEmpty(userJoins)){ |
|
|
|
if (CollectionUtil.isNotEmpty(userJoins)) { |
|
|
|
completedData = getCompletedData(userJoins); |
|
|
|
} |
|
|
|
} |
|
|
@ -471,6 +476,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询参加游戏的用户信息 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param gameRecordId |
|
|
|
* @return |
|
|
@ -488,16 +494,17 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询游戏信息 |
|
|
|
* |
|
|
|
* @param gameRecordId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public GameRecord getGameRecord(long gameRecordId) { |
|
|
|
String gameRecordStr = (String)redisUtil.get(GameConstant.generateGameStatusKey(gameRecordId)); |
|
|
|
String gameRecordStr = (String) redisUtil.get(GameConstant.generateGameStatusKey(gameRecordId)); |
|
|
|
GameRecord gameRecord = null; |
|
|
|
if (StrUtil.isBlank(gameRecordStr)) { |
|
|
|
gameRecord = gameRecordDao.selectByPrimaryKey(gameRecordId); |
|
|
|
if(ObjectUtil.isNull(gameRecord)){ |
|
|
|
if (ObjectUtil.isNull(gameRecord)) { |
|
|
|
throw new BaseException(CodeEnum.NOT_GAME_RECORD); |
|
|
|
} |
|
|
|
} else { |
|
|
@ -508,6 +515,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询前十名 |
|
|
|
* |
|
|
|
* @param gameRecordId |
|
|
|
* @return |
|
|
|
*/ |
|
|
@ -525,7 +533,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
topUser.setHeadImgUrl(user.getAvatarUrl()); |
|
|
|
topUser.setNickname(user.getNickname()); |
|
|
|
topUser.setScore(type.getScore().intValue()); |
|
|
|
topUser.setTimes(type.getScore().intValue()/100); |
|
|
|
topUser.setTimes(type.getScore().intValue() / 100); |
|
|
|
finalTops.add(topUser); |
|
|
|
|
|
|
|
}); |
|
|
@ -542,44 +550,52 @@ public class ScreenService implements IScreenService{ |
|
|
|
public String startAgain(QueryDto<ScreenDto.MemberRecord> params) throws Exception { |
|
|
|
ScreenDto.MemberRecord memberRecord = params.getParam(); |
|
|
|
GameRecord gameRecord = gameRecordDao.selectByPrimaryKey(memberRecord.getMemberRecord()); |
|
|
|
if(ObjectUtil.isNull(gameRecord)){ |
|
|
|
if (ObjectUtil.isNull(gameRecord)) { |
|
|
|
throw new BaseException(CodeEnum.NOT_GAME_RECORD); |
|
|
|
} |
|
|
|
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId()); |
|
|
|
if(ObjectUtil.isNull(gameUserPay)){ |
|
|
|
if (ObjectUtil.isNull(gameUserPay)) { |
|
|
|
throw new BaseException(CodeEnum.NOT_GAME_TYPE); |
|
|
|
} |
|
|
|
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId()); |
|
|
|
if(ObjectUtil.isNull(gameType)){ |
|
|
|
if (ObjectUtil.isNull(gameType)) { |
|
|
|
throw new BaseException(CodeEnum.NOT_GAME_TYPE); |
|
|
|
} |
|
|
|
|
|
|
|
if(gameUserPay.getUsedCount() >= gameUserPay.getTotalCount()){ |
|
|
|
throw new BaseException(CodeEnum. GAME_NOT_TIMES); |
|
|
|
if (gameUserPay.getUsedCount() >= gameUserPay.getTotalCount()) { |
|
|
|
throw new BaseException(CodeEnum.GAME_NOT_TIMES); |
|
|
|
} |
|
|
|
GameRecord gameRecordNew = null; |
|
|
|
if(gameRecord.getGameStatus() == 3){ |
|
|
|
if (gameRecord.getGameStatus() == 3) { |
|
|
|
//添加一场新的游戏记录
|
|
|
|
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); |
|
|
|
gameUserPayDao.updateByPrimaryKeySelective(gameUserPay); |
|
|
|
|
|
|
|
//路径(添加项目id)
|
|
|
|
String url = gameRecord.getUrl() + "&projectId="+ memberRecord.getProjectId(); |
|
|
|
String url = gameRecord.getUrl() + "&projectId=" + memberRecord.getProjectId(); |
|
|
|
//给所有人发送消息发送消息
|
|
|
|
ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url,gameRecord.getId(),memberRecord.getProjectId()); |
|
|
|
ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url, gameRecord.getId(), memberRecord.getProjectId()); |
|
|
|
BaseMessageDto.MessageUser messageUser = null; |
|
|
|
List<BaseMessageDto.MessageUser> messageUserList = new ArrayList<>(); |
|
|
|
//获取项目下所有成员
|
|
|
|
List<Long> memberIdList = tallFeignClient.getMemberIdListByProject(memberRecord.getProjectId()); |
|
|
|
if(CollectionUtil.isNotEmpty(memberIdList)){ |
|
|
|
for(Long memberId:memberIdList){ |
|
|
|
if (CollectionUtil.isNotEmpty(memberIdList)) { |
|
|
|
for (Long memberId : memberIdList) { |
|
|
|
messageUser = new BaseMessageDto.MessageUser(); |
|
|
|
messageUser.setUserId(memberId); |
|
|
|
messageUserList.add(messageUser); |
|
|
@ -588,7 +604,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
chromeMessageDto.setReceivers(messageUserList); |
|
|
|
messageService.sendGameMessageWithGetUrl(chromeMessageDto); |
|
|
|
|
|
|
|
}else { |
|
|
|
} else { |
|
|
|
throw new BaseException(CodeEnum.GAME_NO_END); |
|
|
|
} |
|
|
|
return gameRecordNew.getUrl(); |
|
|
@ -598,10 +614,10 @@ public class ScreenService implements IScreenService{ |
|
|
|
* 查找活动规则 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<String> getGameActivityRule(Long gameTypeId){ |
|
|
|
public List<String> getGameActivityRule(Long gameTypeId) { |
|
|
|
List<String> ruleList = new ArrayList<>(); |
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(gameTypeId)) { |
|
|
|
if (ObjectUtil.isNotNull(gameTypeId)) { |
|
|
|
GameActivityRuleExample activityRuleExample = new GameActivityRuleExample(); |
|
|
|
activityRuleExample.createCriteria().andGameIdEqualTo(gameTypeId); |
|
|
|
List<GameActivityRule> gameActivityRuleList = activityRuleDao.selectByExample(activityRuleExample); |
|
|
@ -613,14 +629,15 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
return ruleList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询活动奖品 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<String> getGameActivityPrize(Long gameTypeId){ |
|
|
|
public List<String> getGameActivityPrize(Long gameTypeId) { |
|
|
|
List<String> prizeList = new ArrayList<>(); |
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(gameTypeId)) { |
|
|
|
if (ObjectUtil.isNotNull(gameTypeId)) { |
|
|
|
GameActivityPrizeExample activityPrizeExample = new GameActivityPrizeExample(); |
|
|
|
activityPrizeExample.createCriteria().andGameIdEqualTo(gameTypeId); |
|
|
|
List<GameActivityPrize> gameActivityPrizeList = activityPrizeDao.selectByExample(activityPrizeExample); |
|
|
@ -632,14 +649,15 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
return prizeList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 奖券使用说明表 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<String> getGamePrizeInstructions(Long gameTypeId){ |
|
|
|
public List<String> getGamePrizeInstructions(Long gameTypeId) { |
|
|
|
List<String> instructionsList = new ArrayList<>(); |
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(gameTypeId)) { |
|
|
|
if (ObjectUtil.isNotNull(gameTypeId)) { |
|
|
|
GamePrizeInstructionsExample prizeInstructionsExample = new GamePrizeInstructionsExample(); |
|
|
|
prizeInstructionsExample.createCriteria().andGameIdEqualTo(gameTypeId); |
|
|
|
List<GamePrizeInstructions> gamePrizeInstructionsList = prizeInstructionsDao.selectByExample(prizeInstructionsExample); |
|
|
@ -655,21 +673,21 @@ public class ScreenService implements IScreenService{ |
|
|
|
/** |
|
|
|
* 已结束时的返回值 |
|
|
|
*/ |
|
|
|
private ScreenVo.CompletedData getCompletedData(List<GameUserJoin> userJoinList){ |
|
|
|
private ScreenVo.CompletedData getCompletedData(List<GameUserJoin> userJoinList) { |
|
|
|
ScreenVo.CompletedData completedData = new ScreenVo.CompletedData(); |
|
|
|
int totalTimes = 0; |
|
|
|
int totalScore = 0; |
|
|
|
int averageTimes = 0; |
|
|
|
int over = 0; |
|
|
|
if(CollectionUtil.isNotEmpty(userJoinList)){ |
|
|
|
for(GameUserJoin userJoin : userJoinList){ |
|
|
|
if (CollectionUtil.isNotEmpty(userJoinList)) { |
|
|
|
for (GameUserJoin userJoin : userJoinList) { |
|
|
|
totalTimes += userJoin.getTimes(); |
|
|
|
totalScore += userJoin.getScore(); |
|
|
|
} |
|
|
|
averageTimes = totalTimes / userJoinList.size(); |
|
|
|
int a = 0; |
|
|
|
for(GameUserJoin userJoin : userJoinList){ |
|
|
|
if(userJoin.getTimes() < averageTimes){ |
|
|
|
for (GameUserJoin userJoin : userJoinList) { |
|
|
|
if (userJoin.getTimes() < averageTimes) { |
|
|
|
a++; |
|
|
|
} |
|
|
|
} |
|
|
@ -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); |
|
|
@ -716,7 +734,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
gameRecord.setGameStatus(GameConstant.GAME_PREPARATION); |
|
|
|
gameRecord.setStartTime(current + GameConstant.COUNT_DOWN_TIME); |
|
|
|
gameRecord.setEndTime(gameRecord.getStartTime() + GameConstant.GAME_TIME); |
|
|
|
gameRecord.setTimeDifference((int)moreTime); |
|
|
|
gameRecord.setTimeDifference((int) moreTime); |
|
|
|
gameRecordDao.updateByPrimaryKeySelective(gameRecord); |
|
|
|
//设置redis 游戏状态 准备中
|
|
|
|
redisUtil.set(GameConstant.generateGameStatusKey(gameRecord.getId()), JSON.toJSONString(gameRecord), GameConstant.REDIS_TIME); |
|
|
@ -727,7 +745,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
delUserJoin.setRecStatus(WebConstant.REC_STATUS.Deleted.value); |
|
|
|
GameUserJoinExample example = new GameUserJoinExample(); |
|
|
|
example.createCriteria().andRecordIdEqualTo(start.getMemberRecord()); |
|
|
|
gameUserJoinDao.updateByExampleSelective(delUserJoin,example); |
|
|
|
gameUserJoinDao.updateByExampleSelective(delUserJoin, example); |
|
|
|
redisUtil.del(GameConstant.generateGameKey(start.getMemberRecord())); |
|
|
|
} |
|
|
|
//延时通知
|
|
|
@ -758,7 +776,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
GameUserJoin join = new GameUserJoin(); |
|
|
|
join.setId(user.getId()); |
|
|
|
join.setScore(score); |
|
|
|
join.setTimes(score/100); |
|
|
|
join.setTimes(score / 100); |
|
|
|
gameUserJoinDao.updateByPrimaryKeySelective(join); |
|
|
|
}); |
|
|
|
} |
|
|
@ -778,8 +796,15 @@ public class ScreenService implements IScreenService{ |
|
|
|
List<GameUserJoin> userJoins = gameUserJoinDao.selectByExample(joinExample); |
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(userJoins)) { |
|
|
|
userJoins.forEach( userJoin -> { |
|
|
|
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin); |
|
|
|
userJoins.forEach(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,16 +816,16 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 推送客户端状态 |
|
|
|
* |
|
|
|
* @param gameRecord |
|
|
|
* @param executor |
|
|
|
*/ |
|
|
|
private void pushClient(GameRecord gameRecord, ScheduledExecutorService executor) { |
|
|
|
|
|
|
|
new Thread(()->{ |
|
|
|
sendMsg.sendMsg(executor, 0, ()->{ |
|
|
|
new Thread(() -> { |
|
|
|
sendMsg.sendMsg(executor, 0, () -> { |
|
|
|
try { |
|
|
|
//查询游戏用户,通知游戏倒计时
|
|
|
|
List<ClientDto.RedisUser> userJoins = sendMsg.getAllScore(gameRecord); |
|
|
@ -811,7 +836,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
}); |
|
|
|
long startTime = gameRecord.getStartTime() - System.currentTimeMillis(); |
|
|
|
sendMsg.sendMsg(executor, startTime > 0 ? startTime : 0, ()->{ |
|
|
|
sendMsg.sendMsg(executor, startTime > 0 ? startTime : 0, () -> { |
|
|
|
//查询游戏用户,通知游戏开始
|
|
|
|
List<ClientDto.RedisUser> userJoins = sendMsg.getAllScore(gameRecord); |
|
|
|
try { |
|
|
@ -824,7 +849,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
|
|
|
|
long endTime = gameRecord.getEndTime() - System.currentTimeMillis(); |
|
|
|
System.out.println("游戏结束"); |
|
|
|
sendMsg.sendMsg(executor, endTime > 0 ? endTime : 0, ()->{ |
|
|
|
sendMsg.sendMsg(executor, endTime > 0 ? endTime : 0, () -> { |
|
|
|
try { |
|
|
|
//查询游戏用户,通知游戏结束
|
|
|
|
List<ClientDto.RedisUser> userJoins = sendMsg.getAllScore(gameRecord); |
|
|
@ -844,15 +869,15 @@ public class ScreenService implements IScreenService{ |
|
|
|
* 查询游戏类型id |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Long getGameTypeId(Long recordId){ |
|
|
|
public Long getGameTypeId(Long recordId) { |
|
|
|
Long gameTypeId = null; |
|
|
|
GameRecord gameRecord = gameRecordDao.selectByPrimaryKey(recordId); |
|
|
|
if(ObjectUtil.isNotNull(gameRecord)){ |
|
|
|
if (ObjectUtil.isNotNull(gameRecord)) { |
|
|
|
//获取游戏的购买记录和类型
|
|
|
|
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId()); |
|
|
|
if(ObjectUtil.isNotNull(gameUserPay)) { |
|
|
|
if (ObjectUtil.isNotNull(gameUserPay)) { |
|
|
|
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId()); |
|
|
|
if(ObjectUtil.isNotNull(gameType)){ |
|
|
|
if (ObjectUtil.isNotNull(gameType)) { |
|
|
|
gameTypeId = gameType.getId(); |
|
|
|
} |
|
|
|
} |
|
|
@ -867,9 +892,9 @@ public class ScreenService implements IScreenService{ |
|
|
|
GameGroupExample gameGroupExample = new GameGroupExample(); |
|
|
|
gameGroupExample.createCriteria().andRecordIdEqualTo(recordId); |
|
|
|
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample); |
|
|
|
if(CollectionUtil.isNotEmpty(gameGroupList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(gameGroupList)) { |
|
|
|
groupList = new ArrayList<>(); |
|
|
|
for(GameGroup gameGroup:gameGroupList){ |
|
|
|
for (GameGroup gameGroup : gameGroupList) { |
|
|
|
ScreenVo.Group group = new ScreenVo.Group(); |
|
|
|
group.setGroupId(gameGroup.getId()); |
|
|
|
group.setGroupName(gameGroup.getName()); |
|
|
@ -880,15 +905,15 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ScreenVo.RecordInfo getRecordByTaskId(Long taskId,String gameType) { |
|
|
|
public ScreenVo.RecordInfo getRecordByTaskId(Long taskId, String gameType) { |
|
|
|
ScreenVo.RecordInfo recordInfo = new ScreenVo.RecordInfo(); |
|
|
|
|
|
|
|
GameRecordExample recordExample = new GameRecordExample(); |
|
|
|
recordExample.createCriteria().andTaskIdEqualTo(taskId); |
|
|
|
recordExample.setOrderByClause("created_at DESC"); |
|
|
|
List<GameRecord> gameRecordList = gameRecordDao.selectByExample(recordExample); |
|
|
|
if(CollectionUtil.isNotEmpty(gameRecordList)){ |
|
|
|
if(StrUtil.isNotEmpty(gameType)) { |
|
|
|
if (CollectionUtil.isNotEmpty(gameRecordList)) { |
|
|
|
if (StrUtil.isNotEmpty(gameType)) { |
|
|
|
for (GameRecord record : gameRecordList) { |
|
|
|
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(record.getUserPayId()); |
|
|
|
if (ObjectUtil.isNotNull(gameUserPay)) { |
|
|
@ -900,7 +925,7 @@ public class ScreenService implements IScreenService{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
recordInfo.setId(gameRecordList.get(0).getId()); |
|
|
|
recordInfo.setGameStatus(gameRecordList.get(0).getGameStatus()); |
|
|
|
} |
|
|
|