Browse Source

获胜队伍

master
zhizhi wu 5 years ago
parent
commit
43ed39e14d
  1. 74
      game/src/main/java/com/ccsens/game/service/ScreenService.java

74
game/src/main/java/com/ccsens/game/service/ScreenService.java

@ -507,7 +507,7 @@ public class ScreenService implements IScreenService {
//查询游戏是否有分组
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId());
ScreenVo.CompletedData completedData;
if (gameType.getIsGroup() == 0) {
if (gameRecord.getGameGroup() == GameConstant.GAME_SINGLE) {
completedData = getCompletedData(memberRecord.getMemberRecord());
} else {
completedData = getCompletedDataByWin(memberRecord.getMemberRecord());
@ -677,37 +677,61 @@ public class ScreenService implements IScreenService {
/**
* 结束时查询胜利组的信息总分数总次数平均以及前十名
*/
private ScreenVo.CompletedData getCompletedDataByWin(Long gameRecordId) {
ScreenVo.CompletedData completedData = new ScreenVo.CompletedData();
String groupKey = gameRecordId + "_group";
Set<ZSetOperations.TypedTuple<Object>> typedTuples = redisUtil.zsRevGetWithScore(groupKey, 0, -1);
Iterator<ZSetOperations.TypedTuple<Object>> iterator = typedTuples.iterator();
ZSetOperations.TypedTuple<Object> next = iterator.next();
GameGroup gameGroup = JSON.parseObject((String) next.getValue(), GameGroup.class);
int score = next.getScore().intValue();
completedData.setTotalScore(score);
completedData.setTotalTimes(score/100);
Object o = redisUtil.get(gameGroup.getId() + GameConstant.GAME_GROUP_NUM);
if (o==null) {
o = 0;
}
completedData.setTotalMember((int)o);
completedData.setAverageTimes((int)o == 0 ? 0 : completedData.getTotalTimes()/(int)o);
completedData.setWinGroup(gameGroup.getName());
GameUserJoinExample joinExample = new GameUserJoinExample();
joinExample.createCriteria().andRecordIdEqualTo(gameRecordId).andScoreGreaterThan(completedData.getAverageTimes());
long l = gameUserJoinDao.countByExample(joinExample);
completedData.setOver((int)o == 0 ? 0 : (int) (l * 100 / (int) o));
//TODO 1、分别查询redis内每个队伍的总分,
//2、查询获胜队伍的信息
//3、redis内没有则查询数据库
//查询分组信息
GameGroupExample gameGroupExample = new GameGroupExample();
gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecordId);
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample);
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)) {
int score1 = (int) group1.get("totalScore");
int score2 = (int) group2.get("totalScore");
if (score1 > score2) {
userJoinList = (List<GameUserJoin>) group1.get("userJoinList");
completedData.setTotalMember(userJoinList.size());
completedData.setWinGroup(gameGroupList.get(0).getName());
} else {
userJoinList = (List<GameUserJoin>) group2.get("userJoinList");
completedData.setTotalMember(userJoinList.size());
completedData.setWinGroup(gameGroupList.get(1).getName());
}
}
//5、获取获胜队伍的信息
completedData = getCompletedData(userJoinList);
}
// GameGroupExample gameGroupExample = new GameGroupExample();
// gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecordId);
// List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample);
// 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)) {
// int score1 = (int) group1.get("totalScore");
// int score2 = (int) group2.get("totalScore");
// if (score1 > score2) {
// userJoinList = (List<GameUserJoin>) group1.get("userJoinList");
// completedData.setTotalMember(userJoinList.size());
// completedData.setWinGroup(gameGroupList.get(0).getName());
// } else {
// userJoinList = (List<GameUserJoin>) group2.get("userJoinList");
// completedData.setTotalMember(userJoinList.size());
// completedData.setWinGroup(gameGroupList.get(1).getName());
// }
// }
// //5、获取获胜队伍的信息
// completedData = getCompletedData(userJoinList);
// }
//前十名
List<ScreenVo.TopUsers> top2 = getTopUsers(gameRecordId);
completedData.setMembers(top2);

Loading…
Cancel
Save