|
|
@@ -1,6 +1,8 @@
|
|
|
package com.izouma.awesomeadmin.service.impl;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
@@ -137,8 +139,19 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
logger.info("updateMatchData");
|
|
|
try {
|
|
|
MatchData m = getMatchDataById(record.getId().toString());
|
|
|
- if (m.getState() == 2) {
|
|
|
+ boolean reset = m.getState() == 2;
|
|
|
+ if (reset) {
|
|
|
delChildren(record.getId());
|
|
|
+ matchDataMapper.findChildrenByParentId(record.getId()).forEach(child -> {
|
|
|
+ if (StringUtils.isNotEmpty(child.getParentId())) {
|
|
|
+ matchDataMapper.findByIdStr(child.getParentId()).forEach(parent -> {
|
|
|
+ if (parent.getState() == 2) {
|
|
|
+ parent.setState(1);
|
|
|
+ matchDataMapper.updateByPrimaryKeySelective(parent);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
int updates = matchDataMapper.updateByPrimaryKeySelective(record);
|
|
|
@@ -198,12 +211,12 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
boolean insert = nextMatchData == null;
|
|
|
if (insert) {
|
|
|
nextMatchData = new MatchData();
|
|
|
- nextMatchData.setParentId(matchData.getId());
|
|
|
nextMatchData.setMatchId(matchData.getMatchId());
|
|
|
nextMatchData.setRound(nextNum);
|
|
|
nextMatchData.setLoopNum(nextRound);
|
|
|
nextMatchData.setGroupName("第" + nextRound + "轮");
|
|
|
}
|
|
|
+ addParentId(nextMatchData, matchData);
|
|
|
if (currentNum % 2 == 0) {
|
|
|
if (winnerId == -1) {
|
|
|
nextMatchData.setBye2(true);
|
|
|
@@ -304,7 +317,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
nextData = getMatchData(nextData);
|
|
|
if (nextData == null) {
|
|
|
nextData = new MatchData();
|
|
|
- nextData.setParentId(matchData.getId());
|
|
|
+ addParentId(nextData, matchData);
|
|
|
nextData.setMatchId(matchInfo.getId());
|
|
|
nextData.setRound(nextNum);
|
|
|
nextData.setLoopNum(totalRound + 1);
|
|
|
@@ -319,7 +332,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
nextLoseData = getMatchData(nextLoseData);
|
|
|
if (nextLoseData == null) {
|
|
|
nextLoseData = new MatchData();
|
|
|
- nextLoseData.setParentId(matchData.getId());
|
|
|
+ addParentId(nextLoseData, matchData);
|
|
|
nextLoseData.setMatchId(matchInfo.getId());
|
|
|
nextLoseData.setRound(currentNum * 2 - 1);
|
|
|
nextLoseData.setLoopNum(totalRound);
|
|
|
@@ -328,6 +341,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
nextLoseData.setBye2(loseBye);
|
|
|
createMatchData(nextLoseData);
|
|
|
} else {
|
|
|
+ addParentId(nextLoseData, matchData);
|
|
|
nextLoseData.setUser2(loserId);
|
|
|
nextLoseData.setBye2(loseBye);
|
|
|
if (nextLoseData.getBye1() || nextLoseData.getBye2()) {
|
|
|
@@ -341,6 +355,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
}
|
|
|
createMatchData(nextData);
|
|
|
} else {
|
|
|
+ nextData.setMatchId(matchInfo.getId());
|
|
|
if (loseRound) {
|
|
|
nextData.setUser2(winnerId);
|
|
|
} else {
|
|
|
@@ -359,7 +374,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
Integer lastWinner = lastWinData.getScore1() > lastWinData.getScore2() ? lastWinData.getUser1() : lastWinData.getUser2();
|
|
|
if (!lastWinner.equals(winnerId)) {
|
|
|
MatchData nextData = new MatchData();
|
|
|
- nextData.setParentId(matchData.getId());
|
|
|
+ addParentId(nextData, matchData);
|
|
|
nextData.setMatchId(matchInfo.getId());
|
|
|
nextData.setUser1(matchData.getUser1());
|
|
|
nextData.setUser2(matchData.getUser2());
|
|
|
@@ -394,12 +409,12 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
boolean insert = nextData == null;
|
|
|
if (nextData == null) {
|
|
|
nextData = new MatchData();
|
|
|
- nextData.setParentId(matchData.getId());
|
|
|
nextData.setMatchId(matchInfo.getId());
|
|
|
nextData.setRound(nextNum);
|
|
|
nextData.setLoopNum(nextRound);
|
|
|
nextData.setGroupName("败者组第" + nextRound + "轮");
|
|
|
}
|
|
|
+ addParentId(nextData, matchData);
|
|
|
if (nextRound % 2 == 0) {
|
|
|
nextData.setUser1(winnerId);
|
|
|
nextData.setBye1(winnerBye);
|
|
|
@@ -442,7 +457,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
nextWinData = getMatchData(nextWinData);
|
|
|
if (nextWinData == null) {
|
|
|
nextWinData = new MatchData();
|
|
|
- nextWinData.setParentId(matchData.getId());
|
|
|
+ addParentId(nextWinData, matchData);
|
|
|
nextWinData.setMatchId(matchData.getMatchId());
|
|
|
nextWinData.setRound(nextNumWin);
|
|
|
nextWinData.setLoopNum(nextRoundWin);
|
|
|
@@ -454,6 +469,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
}
|
|
|
createMatchData(nextWinData);
|
|
|
} else {
|
|
|
+ addParentId(nextWinData, matchData);
|
|
|
if (currentNum % 2 == 0) {
|
|
|
nextWinData.setUser2(winnerId);
|
|
|
} else {
|
|
|
@@ -469,7 +485,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
nextLoseData = getMatchData(nextLoseData);
|
|
|
if (nextLoseData == null) {
|
|
|
nextLoseData = new MatchData();
|
|
|
- nextLoseData.setParentId(matchData.getId());
|
|
|
+ addParentId(nextLoseData, matchData);
|
|
|
nextLoseData.setMatchId(matchData.getMatchId());
|
|
|
nextLoseData.setRound(nextNumLose);
|
|
|
nextLoseData.setLoopNum(nextRoundLose);
|
|
|
@@ -483,6 +499,7 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
}
|
|
|
createMatchData(nextLoseData);
|
|
|
} else {
|
|
|
+ addParentId(nextLoseData, matchData);
|
|
|
nextLoseData.setUser2(loserId);
|
|
|
nextLoseData.setBye2(loseBye);
|
|
|
if (nextLoseData.getBye1() || nextLoseData.getBye2()) {
|
|
|
@@ -793,17 +810,35 @@ public class MatchDataServiceImpl implements MatchDataService {
|
|
|
return sum;
|
|
|
}
|
|
|
|
|
|
- private void delChildren(Integer parentId) {
|
|
|
- MatchData matchData = new MatchData();
|
|
|
- matchData.setParentId(parentId);
|
|
|
- List<MatchData> list = matchDataMapper.queryAllMatchData(matchData);
|
|
|
- for (MatchData data : list) {
|
|
|
- delChildren(data.getId());
|
|
|
+ private void addParentId(MatchData matchData, MatchData parent) {
|
|
|
+ if (StringUtils.isEmpty(matchData.getParentId())) {
|
|
|
+ matchData.setParentId(parent.getId().toString());
|
|
|
+ } else {
|
|
|
+ if (Arrays.stream(matchData.getParentId().split(",")).map(Integer::parseInt).noneMatch(integer -> integer.equals(parent.getId()))) {
|
|
|
+ matchData.setParentId(matchData.getParentId() + "," + parent.getId());
|
|
|
+ }
|
|
|
}
|
|
|
- for (MatchData data : list) {
|
|
|
- deleteMatchData(data.getId().toString());
|
|
|
+ addSuperiorId(matchData, parent);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addSuperiorId(MatchData matchData, MatchData superior) {
|
|
|
+ Set<String> ids = new HashSet<>();
|
|
|
+ if (StringUtils.isNotEmpty(matchData.getSuperiorId())) {
|
|
|
+ ids.addAll(Arrays.asList(matchData.getSuperiorId().split(",")));
|
|
|
}
|
|
|
+ if (StringUtils.isNotEmpty(superior.getSuperiorId())) {
|
|
|
+ ids.addAll(Arrays.asList(superior.getSuperiorId().split(",")));
|
|
|
+ }
|
|
|
+ ids.add(superior.getId().toString());
|
|
|
+ matchData.setSuperiorId(StringUtils.join(ids, ","));
|
|
|
}
|
|
|
|
|
|
+ private void delChildren(Integer parentId) {
|
|
|
+ matchDataMapper.findChildrenByParentId(parentId).forEach(child -> {
|
|
|
+ delChildren(child.getId());
|
|
|
+ matchDataMapper.delete(child.getId().toString());
|
|
|
+ });
|
|
|
+ matchDataMapper.deleteBySuperiorId(parentId);
|
|
|
+ }
|
|
|
}
|
|
|
|