|
@ -24,6 +24,7 @@ import com.ccsens.util.bean.dto.QueryDto; |
|
|
import com.ccsens.util.exception.BaseException; |
|
|
import com.ccsens.util.exception.BaseException; |
|
|
import com.ccsens.util.wx.WxXcxUtil; |
|
|
import com.ccsens.util.wx.WxXcxUtil; |
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
|
|
import com.google.common.util.concurrent.AtomicDouble; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
import org.apache.poi.xssf.usermodel.XSSFRow; |
|
|
import org.apache.poi.xssf.usermodel.XSSFRow; |
|
@ -39,6 +40,7 @@ import java.io.*; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.concurrent.Executors; |
|
|
import java.util.concurrent.Executors; |
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @author zy |
|
|
* @author zy |
|
@ -144,7 +146,7 @@ public class ScreenService implements IScreenService { |
|
|
} else { |
|
|
} else { |
|
|
log.info("测试环境,不调用生成二维码"); |
|
|
log.info("测试环境,不调用生成二维码"); |
|
|
//给一个默认测试的
|
|
|
//给一个默认测试的
|
|
|
gameRecord.setQrCodeUrl(PropUtil.qrCode + "/gameQrCode/2020-08-19/1597822577181.png"); |
|
|
gameRecord.setQrCodeUrl(PropUtil.qrCode + "gameQrCode/2020-08-19/1597822577181.png"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//查找此任务下的游戏配置表
|
|
|
//查找此任务下的游戏配置表
|
|
@ -160,27 +162,28 @@ public class ScreenService implements IScreenService { |
|
|
//添加配置信息
|
|
|
//添加配置信息
|
|
|
saveGameRecord(wpsFilePath,gameRecord); |
|
|
saveGameRecord(wpsFilePath,gameRecord); |
|
|
} |
|
|
} |
|
|
//将游戏记录添加数据库
|
|
|
//如果是分组游戏
|
|
|
gameRecordDao.insertSelective(gameRecord); |
|
|
|
|
|
log.info("添加游戏记录:{}",gameRecord); |
|
|
log.info("添加游戏记录:{}",gameRecord); |
|
|
//配置表不存在,而且游戏类型默认为分组游戏,默认添加两个分组
|
|
|
//配置表不存在,而且游戏类型默认为分组游戏,默认添加两个分组
|
|
|
if(StrUtil.isEmpty(wpsFilePath) && gameType.getIsGroup() == 1){ |
|
|
if(StrUtil.isEmpty(wpsFilePath) && gameType.getIsGroup() == 1){ |
|
|
if (gameType.getIsGroup() == 1) { |
|
|
gameRecord.setGameGroup((byte) 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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
//将游戏记录添加数据库
|
|
|
|
|
|
gameRecordDao.insertSelective(gameRecord); |
|
|
//5、查询该游戏的规则
|
|
|
//5、查询该游戏的规则
|
|
|
List<String> ruleList = getGameActivityRule(gameType.getId()); |
|
|
List<String> ruleList = getGameActivityRule(gameType.getId()); |
|
|
//6、返回
|
|
|
//6、返回
|
|
@ -222,6 +225,9 @@ public class ScreenService implements IScreenService { |
|
|
*/ |
|
|
*/ |
|
|
private void saveGameRecord(String wpsFilePath,GameRecord gameRecord) throws Exception{ |
|
|
private void saveGameRecord(String wpsFilePath,GameRecord gameRecord) throws Exception{ |
|
|
InputStream is = new FileInputStream(new File(wpsFilePath)); |
|
|
InputStream is = new FileInputStream(new File(wpsFilePath)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//读取excel
|
|
|
//读取excel
|
|
|
XSSFWorkbook wb = new XSSFWorkbook(is); |
|
|
XSSFWorkbook wb = new XSSFWorkbook(is); |
|
|
if(ObjectUtil.isNull(wb)){ throw new BaseException(CodeEnum.NOT_CONFIG_OR_ERR); } |
|
|
if(ObjectUtil.isNull(wb)){ throw new BaseException(CodeEnum.NOT_CONFIG_OR_ERR); } |
|
@ -550,8 +556,13 @@ public class ScreenService implements IScreenService { |
|
|
//获取游戏的购买记录和类型
|
|
|
//获取游戏的购买记录和类型
|
|
|
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId()); |
|
|
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId()); |
|
|
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId()); |
|
|
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId()); |
|
|
|
|
|
|
|
|
gameStatusVo.setGameStatus(gameRecord.getGameStatus()); |
|
|
gameStatusVo.setGameStatus(gameRecord.getGameStatus()); |
|
|
|
|
|
//返回开始结束时间和时长
|
|
|
|
|
|
|
|
|
|
|
|
gameStatusVo.setStartLocalTime(gameRecord.getStartTime() + gameRecord.getTimeDifference()); |
|
|
|
|
|
gameStatusVo.setEndLocalTime(gameRecord.getEndTime() + gameRecord.getTimeDifference()); |
|
|
|
|
|
gameStatusVo.setDuration(gameRecord.getDuration()); |
|
|
|
|
|
|
|
|
//获取分组的信息
|
|
|
//获取分组的信息
|
|
|
List<ScreenVo.GroupVo> groupVo = getGroupScore2(gameRecord); |
|
|
List<ScreenVo.GroupVo> groupVo = getGroupScore2(gameRecord); |
|
|
gameStatusVo.setGroups(groupVo); |
|
|
gameStatusVo.setGroups(groupVo); |
|
@ -701,9 +712,6 @@ public class ScreenService implements IScreenService { |
|
|
/** |
|
|
/** |
|
|
* 结束时查询胜利组的信息(总分数,总次数,平均以及前十名) |
|
|
* 结束时查询胜利组的信息(总分数,总次数,平均以及前十名) |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ScreenVo.CompletedData getCompletedDataByWin(GameRecord gameRecord, int totalMember) { |
|
|
private ScreenVo.CompletedData getCompletedDataByWin(GameRecord gameRecord, int totalMember) { |
|
|
String groupKey = gameRecord.getId() + "_group"; |
|
|
String groupKey = gameRecord.getId() + "_group"; |
|
|
Set<ZSetOperations.TypedTuple<Object>> typedTuples = redisUtil.zsRevGetWithScore(groupKey, 0, -1); |
|
|
Set<ZSetOperations.TypedTuple<Object>> typedTuples = redisUtil.zsRevGetWithScore(groupKey, 0, -1); |
|
@ -711,31 +719,32 @@ public class ScreenService implements IScreenService { |
|
|
ScreenVo.CompletedData completedData = new ScreenVo.CompletedData(); |
|
|
ScreenVo.CompletedData completedData = new ScreenVo.CompletedData(); |
|
|
|
|
|
|
|
|
List<ScreenVo.CompletedData> list = new ArrayList<>(); |
|
|
List<ScreenVo.CompletedData> list = new ArrayList<>(); |
|
|
|
|
|
Double maxSore = 0d; |
|
|
|
|
|
String winGroupName = null; |
|
|
if (CollectionUtil.isNotEmpty(typedTuples)) { |
|
|
if (CollectionUtil.isNotEmpty(typedTuples)) { |
|
|
|
|
|
|
|
|
typedTuples.forEach(type -> { |
|
|
for(ZSetOperations.TypedTuple<Object> type : typedTuples) { |
|
|
completedData.setTotalScore(completedData.getTotalScore() + type.getScore().intValue()); |
|
|
completedData.setTotalScore(completedData.getTotalScore() + type.getScore().intValue()); |
|
|
|
|
|
GameGroup gameGroup = JSON.parseObject((String) type.getValue(), GameGroup.class); |
|
|
|
|
|
if (gameRecord.getRankRule() == GameConstant.RANK_RULE_AVA) { |
|
|
|
|
|
Object o = redisUtil.get(gameGroup.getId() + GameConstant.GAME_GROUP_NUM); |
|
|
|
|
|
|
|
|
|
|
|
if (o == null || (Integer) o == 0) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
Integer a = (Integer) o; |
|
|
|
|
|
if (maxSore <= type.getScore() / a) { |
|
|
|
|
|
maxSore = type.getScore() / a; |
|
|
|
|
|
winGroupName = gameGroup.getName(); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
if (maxSore <= type.getScore()) { |
|
|
|
|
|
maxSore = type.getScore(); |
|
|
|
|
|
winGroupName = gameGroup.getName(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// ScreenVo.CompletedData completedData = new ScreenVo.CompletedData();
|
|
|
|
|
|
//// GameGroup gameGroup = JSON.parseObject((String) type.getValue(), GameGroup.class);
|
|
|
|
|
|
//// int score = type.getScore().intValue();
|
|
|
|
|
|
//// Object o = redisUtil.get(gameGroup.getId() + GameConstant.GAME_GROUP_NUM);
|
|
|
|
|
|
//// if (o==null) {
|
|
|
|
|
|
//// o = 0;
|
|
|
|
|
|
//// }
|
|
|
|
|
|
//// completedData.setTotalMember((int)o);
|
|
|
|
|
|
//// completedData.setTotalScore(score);
|
|
|
|
|
|
//// completedData.setAverageScore((int)o == 0 ? 0 : completedData.getTotalScore()/(int)o);
|
|
|
|
|
|
//// completedData.setTotalTimes(score/100);
|
|
|
|
|
|
//// completedData.setAverageTimes((int)o == 0 ? 0 : completedData.getTotalTimes()/(int)o);
|
|
|
|
|
|
//// completedData.setWinGroup(gameGroup.getName());
|
|
|
|
|
|
//// GameUserJoinExample joinExample = new GameUserJoinExample();
|
|
|
|
|
|
//// joinExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()).andScoreGreaterThan(completedData.getAverageTimes());
|
|
|
|
|
|
//// long l = gameUserJoinDao.countByExample(joinExample);
|
|
|
|
|
|
//// completedData.setOver(totalMember == 0 ? 0 : (int) (l * 100 / totalMember));
|
|
|
|
|
|
//// list.add(completedData);
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
List<ScreenVo.GroupVo> groupVos = gameGroupDao.queryGroups(gameRecord.getId()); |
|
|
List<ScreenVo.GroupVo> groupVos = gameGroupDao.queryGroups(gameRecord.getId()); |
|
@ -744,70 +753,37 @@ public class ScreenService implements IScreenService { |
|
|
return new ScreenVo.CompletedData(); |
|
|
return new ScreenVo.CompletedData(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
groupVos.forEach(groupVo -> { |
|
|
for(ScreenVo.GroupVo groupVo : groupVos) { |
|
|
completedData.setTotalScore((groupVo.getScore() == null ? 0 : groupVo.getScore()) + completedData.getTotalScore()); |
|
|
if (gameRecord.getRankRule() == GameConstant.RANK_RULE_AVA) { |
|
|
// groupVo.setScore(groupVo.getTotalMembers() == null || groupVo.getTotalMembers() == 0 ? 0 : groupVo.getScore()/groupVo.getTotalMembers());
|
|
|
if (groupVo.getTotalMembers() == null || groupVo.getTotalMembers() == 0) { |
|
|
// ScreenVo.CompletedData completedData = new ScreenVo.CompletedData();
|
|
|
continue; |
|
|
//
|
|
|
} |
|
|
// int members = groupVo.getTotalMembers() == null ? 0 : groupVo.getTotalMembers();
|
|
|
if (maxSore <= groupVo.getTotalScore() / groupVo.getTotalMembers()) { |
|
|
// completedData.setTotalMember(members);
|
|
|
maxSore = (double)groupVo.getTotalScore() / groupVo.getTotalMembers(); |
|
|
// completedData.setTotalScore(groupVo.getScore());
|
|
|
winGroupName = groupVo.getGroupName(); |
|
|
// completedData.setAverageScore(members == 0 ? 0 : completedData.getTotalScore()/members);
|
|
|
} |
|
|
// completedData.setTotalTimes(groupVo.getScore() == null ? 0 : groupVo.getScore()/100);
|
|
|
} else { |
|
|
// completedData.setAverageTimes(members == 0 ? 0 : completedData.getTotalTimes()/members);
|
|
|
if (maxSore <= groupVo.getTotalScore()) { |
|
|
// completedData.setWinGroup(groupVo.getGroupName());
|
|
|
maxSore = (double)groupVo.getTotalScore(); |
|
|
// GameUserJoinExample joinExample = new GameUserJoinExample();
|
|
|
winGroupName = groupVo.getGroupName(); |
|
|
// joinExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()).andScoreGreaterThan(completedData.getAverageTimes());
|
|
|
} |
|
|
// long l = gameUserJoinDao.countByExample(joinExample);
|
|
|
} |
|
|
// completedData.setOver(totalMember == 0 ? 0 : (int) (l * 100 /totalMember));
|
|
|
} |
|
|
// list.add(completedData);
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
completedData.setAverageScore(totalMember == 0 ? 0 : completedData.getTotalScore() / totalMember); |
|
|
completedData.setAverageScore(totalMember == 0 ? 0 : completedData.getTotalScore() / totalMember); |
|
|
completedData.setTotalTimes(completedData.getTotalScore() / 100); |
|
|
completedData.setTotalTimes(completedData.getTotalScore() / 100); |
|
|
completedData.setAverageTimes(totalMember == 0 ? 0 : completedData.getTotalTimes() / totalMember); |
|
|
completedData.setAverageTimes(totalMember == 0 ? 0 : completedData.getTotalTimes() / totalMember); |
|
|
|
|
|
completedData.setTotalMember(totalMember); |
|
|
|
|
|
completedData.setWinGroup(winGroupName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GameUserJoinExample joinExample = new GameUserJoinExample(); |
|
|
GameUserJoinExample joinExample = new GameUserJoinExample(); |
|
|
joinExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()).andScoreGreaterThan(completedData.getAverageScore()); |
|
|
joinExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()).andScoreGreaterThan(completedData.getAverageScore()); |
|
|
long l = gameUserJoinDao.countByExample(joinExample); |
|
|
long l = gameUserJoinDao.countByExample(joinExample); |
|
|
completedData.setOver(totalMember == 0 ? 0 : (int) (l * 100 / totalMember)); |
|
|
completedData.setOver(totalMember == 0 ? 0 : (int) (l * 100 / totalMember)); |
|
|
// if (gameRecord.getRankRule() == GameConstant.RANK_RULE_AVA) {
|
|
|
|
|
|
// CollectionUtil.sort(list, (t1,t2)-> t2.getAverageScore() - t1.getAverageScore());
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
|
// }
|
|
|
|
|
|
//前十名
|
|
|
|
|
|
// ScreenVo.CompletedData completedData = list.get(0);
|
|
|
|
|
|
List<ScreenVo.TopUsers> top2 = getTopUsers(gameRecord.getId()); |
|
|
List<ScreenVo.TopUsers> top2 = getTopUsers(gameRecord.getId()); |
|
|
completedData.setMembers(top2); |
|
|
completedData.setMembers(top2); |
|
|
return completedData; |
|
|
return completedData; |
|
|