|
|
@@ -29,7 +29,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
private static Logger logger = Logger.getLogger(MatchDataServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
- private MatchDataMapper matchDataMapper;
|
|
|
+ private MatchDataMapper matchDataMapper;
|
|
|
@Autowired
|
|
|
private MatchInfoService matchInfoService;
|
|
|
@Autowired
|
|
|
@@ -173,11 +173,11 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
winnerId = matchData.getUser2();
|
|
|
}
|
|
|
|
|
|
- int currentNum = matchData.getRound();
|
|
|
- int currentRound = matchData.getLoopNum();
|
|
|
- int totalRound = (int) (Math.log(matchInfo.getTotalNum()) / Math.log(2));
|
|
|
+ int currentNum = matchData.getRound();
|
|
|
+ int currentRound = matchData.getLoopNum();
|
|
|
+ int totalRound = (int) (Math.log(matchInfo.getTotalNum()) / Math.log(2));
|
|
|
int currentNumInRound = currentNum - GeometricProgressionSum(currentRound, totalRound - 1);
|
|
|
- int nextRound = currentRound + 1;
|
|
|
+ int nextRound = currentRound + 1;
|
|
|
if (nextRound > totalRound) return;
|
|
|
int nextNum = (int) Math.ceil(currentNumInRound / 2.0) + GeometricProgressionSum(nextRound, totalRound - 1);
|
|
|
|
|
|
@@ -233,15 +233,15 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
// abandon = matchData.getAbandon1();
|
|
|
// }
|
|
|
|
|
|
- int currentNum = matchData.getRound();
|
|
|
- boolean loseRound = currentNum > matchInfo.getTotalNum() - 1;
|
|
|
- int winnerRound = (int) (Math.log(matchInfo.getTotalNum()) / Math.log(2));
|
|
|
- int totalRound = (winnerRound - 1) * 2;
|
|
|
- int currentRound = matchData.getLoopNum();
|
|
|
+ int currentNum = matchData.getRound();
|
|
|
+ boolean loseRound = currentNum > matchInfo.getTotalNum() - 1;
|
|
|
+ int winnerRound = (int) (Math.log(matchInfo.getTotalNum()) / Math.log(2));
|
|
|
+ int totalRound = (winnerRound - 1) * 2;
|
|
|
+ int currentRound = matchData.getLoopNum();
|
|
|
|
|
|
Integer winnerId, loserId;
|
|
|
boolean winnerBye = false;
|
|
|
- boolean loseBye = false;
|
|
|
+ boolean loseBye = false;
|
|
|
if (matchData.getBye1() && !matchData.getBye2()) {
|
|
|
winnerId = matchData.getUser2();
|
|
|
loserId = null;
|
|
|
@@ -351,7 +351,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
currentNumInRound -= getLostRoundNum(i, totalRound);
|
|
|
}
|
|
|
int nextRound = currentRound + 1;
|
|
|
- int nextNum = matchInfo.getTotalNum() - 1;
|
|
|
+ int nextNum = matchInfo.getTotalNum() - 1;
|
|
|
for (int i = 1; i <= currentRound; i++) {
|
|
|
nextNum += getLostRoundNum(i, totalRound);
|
|
|
}
|
|
|
@@ -407,10 +407,10 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
|
|
|
} else {
|
|
|
int currentNumInRound = currentNum - GeometricProgressionSum(currentRound, winnerRound - 1);
|
|
|
- int nextRoundWin = currentRound + 1;
|
|
|
- int nextNumWin = (int) Math.ceil(currentNumInRound / 2.0) + GeometricProgressionSum(nextRoundWin, winnerRound - 1);
|
|
|
- int nextRoundLose = currentRound == 1 ? 1 : ((currentRound - 1) * 2);
|
|
|
- int nextNumLose = matchInfo.getTotalNum() - 1;
|
|
|
+ int nextRoundWin = currentRound + 1;
|
|
|
+ int nextNumWin = (int) Math.ceil(currentNumInRound / 2.0) + GeometricProgressionSum(nextRoundWin, winnerRound - 1);
|
|
|
+ int nextRoundLose = currentRound == 1 ? 1 : ((currentRound - 1) * 2);
|
|
|
+ int nextNumLose = matchInfo.getTotalNum() - 1;
|
|
|
for (int i = 1; i < nextRoundLose; i++) {
|
|
|
nextNumLose += getLostRoundNum(i, totalRound);
|
|
|
}
|
|
|
@@ -512,7 +512,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
MatchData matchData = new MatchData();
|
|
|
matchData.setMatchId(matchId);
|
|
|
List<MatchData> matchDataList = getMatchDataList(matchData);
|
|
|
- MatchInfo matchInfo = matchInfoService.getMatchInfoById(matchId.toString());
|
|
|
+ MatchInfo matchInfo = matchInfoService.getMatchInfoById(matchId.toString());
|
|
|
for (MatchData md : matchDataList) {
|
|
|
if (md.getBye1() || md.getBye2()) {
|
|
|
switch (matchInfo.getType()) {
|
|
|
@@ -533,17 +533,24 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
@Override
|
|
|
public List<MatchData> userMatchData(Integer matchId, Integer userId) {
|
|
|
try {
|
|
|
- MatchInfo matchInfo = matchInfoService.getMatchInfoById(matchId.toString());
|
|
|
- if (matchInfo.getJudgeMode() == 2) {
|
|
|
+ List<MatchData> list;
|
|
|
+ if (matchId != null) {
|
|
|
+ MatchInfo matchInfo = matchInfoService.getMatchInfoById(matchId.toString());
|
|
|
+ if (matchInfo.getJudgeMode() == 2) {
|
|
|
+ if (!userId.equals(matchInfo.getUserId())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list = matchDataMapper.userMatchData(matchId, userId);
|
|
|
if (!userId.equals(matchInfo.getUserId())) {
|
|
|
- return null;
|
|
|
+ list.removeIf(matchData -> userId.equals(matchData.getUploadUser()));
|
|
|
}
|
|
|
+ return list;
|
|
|
+ } else {
|
|
|
+ list = matchDataMapper.allUserMatchData(userId);
|
|
|
+ list.removeIf(matchData -> userId.equals(matchData.getUploadUser()) && !userId.equals(matchData.getUserId()));
|
|
|
+ return list;
|
|
|
}
|
|
|
- List<MatchData> list = matchDataMapper.userMatchData(matchId, userId);
|
|
|
- if (!userId.equals(matchInfo.getUserId())) {
|
|
|
- list.removeIf(matchData -> userId.equals(matchData.getUploadUser()));
|
|
|
- }
|
|
|
- return list;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("userMatchData", e);
|
|
|
}
|
|
|
@@ -576,14 +583,14 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
ApplyInfo applyInfo = new ApplyInfo();
|
|
|
applyInfo.setMatchId(matchInfo.getId());
|
|
|
List<ApplyInfo> applyList = applyInfoService.getApplyInfoList(applyInfo);
|
|
|
- int num = matchInfo.getStageInfo().get(0).getTotalNum() / 2;
|
|
|
+ int num = matchInfo.getStageInfo().get(0).getTotalNum() / 2;
|
|
|
List<MatchData> list = Stream.generate(MatchData::new)
|
|
|
.limit(num)
|
|
|
.collect(Collectors.toList());
|
|
|
- Iterator<ApplyInfo> it = applyList.iterator();
|
|
|
- int index = 0;
|
|
|
+ Iterator<ApplyInfo> it = applyList.iterator();
|
|
|
+ int index = 0;
|
|
|
while (it.hasNext()) {
|
|
|
- ApplyInfo a = it.next();
|
|
|
+ ApplyInfo a = it.next();
|
|
|
MatchData matchData = list.get(index % num);
|
|
|
if (index < num) {
|
|
|
matchData.setMatchId(matchInfo.getId());
|
|
|
@@ -631,14 +638,14 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
ApplyInfo applyInfo = new ApplyInfo();
|
|
|
applyInfo.setMatchId(matchInfo.getId());
|
|
|
List<ApplyInfo> applyList = applyInfoService.getApplyInfoList(applyInfo);
|
|
|
- int num = matchInfo.getStageInfo().get(0).getTotalNum() / 2;
|
|
|
+ int num = matchInfo.getStageInfo().get(0).getTotalNum() / 2;
|
|
|
List<MatchData> list = Stream.generate(MatchData::new)
|
|
|
.limit(num)
|
|
|
.collect(Collectors.toList());
|
|
|
- Iterator<ApplyInfo> it = applyList.iterator();
|
|
|
- int index = 0;
|
|
|
+ Iterator<ApplyInfo> it = applyList.iterator();
|
|
|
+ int index = 0;
|
|
|
while (it.hasNext()) {
|
|
|
- ApplyInfo a = it.next();
|
|
|
+ ApplyInfo a = it.next();
|
|
|
MatchData matchData = list.get(index % num);
|
|
|
if (index < num) {
|
|
|
matchData.setMatchId(matchInfo.getId());
|
|
|
@@ -663,9 +670,9 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
private void initRoundRobinMatchData(MatchInfo matchInfo) {
|
|
|
ApplyInfo applyInfo = new ApplyInfo();
|
|
|
applyInfo.setMatchId(matchInfo.getId());
|
|
|
- List<ApplyInfo> applyList = applyInfoService.getApplyInfoList(applyInfo);
|
|
|
- int groupNum = 0;
|
|
|
- int totalGroup = Integer.toString(matchInfo.getStageInfo().get(0).getTotalNum() / matchInfo.getStageInfo().get(0).getGroupNum(), 26).length();
|
|
|
+ List<ApplyInfo> applyList = applyInfoService.getApplyInfoList(applyInfo);
|
|
|
+ int groupNum = 0;
|
|
|
+ int totalGroup = Integer.toString(matchInfo.getStageInfo().get(0).getTotalNum() / matchInfo.getStageInfo().get(0).getGroupNum(), 26).length();
|
|
|
while (applyList.size() > 0) {
|
|
|
List<ApplyInfo> group = RandomDataUtil.generateRandomDataNoRepeat(applyList, matchInfo.getStageInfo().get(0).getGroupNum());
|
|
|
for (int i = 0; i < group.size(); i++) {
|
|
|
@@ -700,13 +707,13 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
}
|
|
|
|
|
|
private MatchData initByeDataSingle(MatchInfo matchInfo, MatchData matchData) {
|
|
|
- int currentNum = matchData.getRound();
|
|
|
- int currentRound = matchData.getLoopNum();
|
|
|
- int totalRound = (int) (Math.log(matchInfo.getTotalNum()) / Math.log(2));
|
|
|
- int currentNumInRound = currentNum - GeometricProgressionSum(currentRound, totalRound - 1);
|
|
|
- int nextRound = currentRound + 1;
|
|
|
- int nextNum = (int) Math.ceil(currentNumInRound / 2.0) + GeometricProgressionSum(nextRound, totalRound - 1);
|
|
|
- MatchData nextMatchData = new MatchData();
|
|
|
+ int currentNum = matchData.getRound();
|
|
|
+ int currentRound = matchData.getLoopNum();
|
|
|
+ int totalRound = (int) (Math.log(matchInfo.getTotalNum()) / Math.log(2));
|
|
|
+ int currentNumInRound = currentNum - GeometricProgressionSum(currentRound, totalRound - 1);
|
|
|
+ int nextRound = currentRound + 1;
|
|
|
+ int nextNum = (int) Math.ceil(currentNumInRound / 2.0) + GeometricProgressionSum(nextRound, totalRound - 1);
|
|
|
+ MatchData nextMatchData = new MatchData();
|
|
|
nextMatchData.setMatchId(matchData.getMatchId());
|
|
|
nextMatchData.setRound(nextNum);
|
|
|
nextMatchData.setLoopNum(nextRound);
|
|
|
@@ -732,7 +739,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
}
|
|
|
|
|
|
private int GeometricProgressionSum(int level, int topLevel) {
|
|
|
- int sum = 0;
|
|
|
+ int sum = 0;
|
|
|
int factor = (int) Math.pow(2, topLevel);
|
|
|
while (level > 1) {
|
|
|
sum += factor;
|