|
@@ -15,6 +15,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
import org.dromara.system.domain.GameEventProject;
|
|
|
import org.dromara.system.domain.constant.GameEventConstant;
|
|
|
+import org.dromara.system.domain.constant.ProjectClassification;
|
|
|
+import org.dromara.system.domain.constant.SortType;
|
|
|
import org.dromara.system.domain.vo.GameAthleteVo;
|
|
|
import org.dromara.system.domain.vo.GameEventProjectVo;
|
|
|
import org.dromara.system.domain.vo.GameTeamVo;
|
|
@@ -330,7 +332,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
log.info("处理运动员: athleteId={}, name={}, teamId={}", athlete.getAthleteId(), athlete.getName(), athlete.getTeamId());
|
|
|
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
- data.put("id", athlete.getAthleteId());
|
|
|
+// data.put("id", athlete.getAthleteId());
|
|
|
data.put("athleteId", athlete.getAthleteId());
|
|
|
data.put("userId", athlete.getUserId());
|
|
|
data.put("eventId", eventId);
|
|
@@ -404,7 +406,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
}
|
|
|
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
- data.put("id", team.getTeamId());
|
|
|
+// data.put("id", team.getTeamId());
|
|
|
data.put("teamId", team.getTeamId());
|
|
|
data.put("teamName", team.getTeamName());
|
|
|
data.put("teamCode", team.getTeamCode());
|
|
@@ -581,7 +583,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
queryBo.setProjectId(projectId);
|
|
|
List<GameScoreVo> allScores = queryList(queryBo);
|
|
|
|
|
|
- if ("0".equals(classification)) {
|
|
|
+ if (ProjectClassification.SINGLE.getValue().equals(classification)) {
|
|
|
// 个人项目:按个人成绩排序
|
|
|
return handleIndividualProjectRanking(allScores, scoreValue, eventId, projectId);
|
|
|
} else {
|
|
@@ -614,8 +616,8 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
.sorted((a, b) -> {
|
|
|
BigDecimal aIndividualPerformance = a.getIndividualPerformance() != null ? a.getIndividualPerformance() : BigDecimal.ZERO;
|
|
|
BigDecimal bIndividualPerformance = b.getIndividualPerformance() != null ? b.getIndividualPerformance() : BigDecimal.ZERO;
|
|
|
-
|
|
|
- if ("0".equals(orderType)) {
|
|
|
+
|
|
|
+ if (orderType.equals(SortType.ASC.getValue())) {
|
|
|
// 升序:成绩越小越好
|
|
|
return aIndividualPerformance.compareTo(bIndividualPerformance);
|
|
|
} else {
|
|
@@ -632,7 +634,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
.toList();
|
|
|
|
|
|
// 根据orderType决定积分分配方式
|
|
|
- if ("0".equals(orderType)) {
|
|
|
+ if (orderType.equals(SortType.ASC.getValue())) {
|
|
|
// 升序项目:成绩越小,积分分配越多
|
|
|
for (int i = 0; i < sortedScores.size(); i++) {
|
|
|
GameScoreVo score = sortedScores.get(i);
|
|
@@ -711,50 +713,33 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
String orderType = project.getOrderType();
|
|
|
log.info("团体项目排名计算,projectId: {}, orderType: {}", projectId, orderType);
|
|
|
|
|
|
- // 按队伍ID分组,汇总每个队伍的积分
|
|
|
- Map<Long, Integer> teamTotalPoints = new HashMap<>();
|
|
|
+ // 按队伍ID分组,获取每个队伍的最佳成绩
|
|
|
Map<Long, BigDecimal> teamBestPerformance = new HashMap<>();
|
|
|
- Map<Long, String> teamNames = new HashMap<>();
|
|
|
-// Map<Long, String> teamCodes = new HashMap<>();
|
|
|
|
|
|
for (GameScoreVo score : allScores) {
|
|
|
Long teamId = score.getTeamId();
|
|
|
if (teamId != null) {
|
|
|
- // 累计队伍积分,处理null值
|
|
|
- Integer currentPoints = score.getScorePoint() != null ? score.getScorePoint() : 0;
|
|
|
- teamTotalPoints.merge(teamId, currentPoints, Integer::sum);
|
|
|
-
|
|
|
- // 记录队伍最佳成绩
|
|
|
+ // 记录队伍最佳成绩(团体成绩)
|
|
|
if (score.getTeamPerformance() != null && score.getTeamPerformance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
BigDecimal currentBest = teamBestPerformance.get(teamId);
|
|
|
- if (currentBest == null || score.getTeamPerformance().compareTo(currentBest) > 0) {
|
|
|
+ if (currentBest == null ||
|
|
|
+ (orderType.equals(SortType.ASC.getValue()) && score.getTeamPerformance().compareTo(currentBest) < 0) || // 升序:成绩越小越好
|
|
|
+ (!orderType.equals(SortType.ASC.getValue()) && score.getTeamPerformance().compareTo(currentBest) > 0)) { // 降序:成绩越大越好
|
|
|
teamBestPerformance.put(teamId, score.getTeamPerformance());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 记录队伍信息
|
|
|
- if (score.getTeamName() != null) {
|
|
|
- teamNames.put(teamId, score.getTeamName());
|
|
|
- }
|
|
|
-// if (score.getTeamCode() != null) {
|
|
|
-// teamCodes.put(teamId, score.getTeamCode());
|
|
|
-// }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 根据orderType决定队伍总积分排序方式
|
|
|
- // orderType: 0-升序(积分越高排名越靠前),1-降序(积分越高排名越靠前)
|
|
|
- List<Map.Entry<Long, Integer>> sortedTeams;
|
|
|
- if ("0".equals(orderType)) {
|
|
|
- // 升序:积分越高排名越靠前
|
|
|
- sortedTeams = teamTotalPoints.entrySet().stream()
|
|
|
- .sorted(Map.Entry.comparingByValue())
|
|
|
- .collect(Collectors.toList());
|
|
|
+ // 根据队伍成绩进行排序
|
|
|
+ List<Map.Entry<Long, BigDecimal>> sortedTeamsByPerformance = new ArrayList<>(teamBestPerformance.entrySet());
|
|
|
+
|
|
|
+ if (orderType.equals(SortType.ASC.getValue())) {
|
|
|
+ // 升序:成绩越小排名越靠前
|
|
|
+ sortedTeamsByPerformance.sort(Map.Entry.comparingByValue());
|
|
|
} else {
|
|
|
- // 降序:积分越高排名越靠前(默认)
|
|
|
- sortedTeams = teamTotalPoints.entrySet().stream()
|
|
|
- .sorted(Map.Entry.<Long, Integer>comparingByValue().reversed())
|
|
|
- .collect(Collectors.toList());
|
|
|
+ // 降序:成绩越大排名越靠前
|
|
|
+ sortedTeamsByPerformance.sort(Map.Entry.<Long, BigDecimal>comparingByValue().reversed());
|
|
|
}
|
|
|
|
|
|
// 解析积分分值
|
|
@@ -763,53 +748,37 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
.map(Integer::parseInt)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 根据orderType决定积分分配方式
|
|
|
- if ("0".equals(orderType)) {
|
|
|
- // 升序项目:成绩越小,积分分配越多
|
|
|
- for (int i = 0; i < sortedTeams.size(); i++) {
|
|
|
- Map.Entry<Long, Integer> teamEntry = sortedTeams.get(i);
|
|
|
- Long teamId = teamEntry.getKey();
|
|
|
- int rank = i + 1;
|
|
|
- int points = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
+ // 根据成绩排序结果分配积分和排名
|
|
|
+ Map<Long, Integer> teamPoints = new HashMap<>();
|
|
|
+ Map<Long, Integer> teamRanks = new HashMap<>();
|
|
|
|
|
|
- // 更新该队伍所有运动员的成绩记录
|
|
|
- for (GameScoreVo score : allScores) {
|
|
|
- if (teamId.equals(score.getTeamId())) {
|
|
|
- GameScoreBo updateBo = new GameScoreBo();
|
|
|
- updateBo.setScoreId(score.getScoreId());
|
|
|
- updateBo.setScoreRank(rank);
|
|
|
- updateBo.setScorePoint(points); // 使用队伍排名对应的积分
|
|
|
- updateBo.setEventId(eventId);
|
|
|
- updateBo.setProjectId(projectId);
|
|
|
-
|
|
|
- updateByBo(updateBo);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 降序项目:成绩越大,积分分配越多
|
|
|
- for (int i = 0; i < sortedTeams.size(); i++) {
|
|
|
- Map.Entry<Long, Integer> teamEntry = sortedTeams.get(i);
|
|
|
- Long teamId = teamEntry.getKey();
|
|
|
- int rank = i + 1;
|
|
|
- int points = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
+ for (int i = 0; i < sortedTeamsByPerformance.size(); i++) {
|
|
|
+ Map.Entry<Long, BigDecimal> teamEntry = sortedTeamsByPerformance.get(i);
|
|
|
+ Long teamId = teamEntry.getKey();
|
|
|
+ int points = i < pointValues.size() ? pointValues.get(i) : 0;
|
|
|
+ int rank = i + 1;
|
|
|
|
|
|
- // 更新该队伍所有运动员的成绩记录
|
|
|
- for (GameScoreVo score : allScores) {
|
|
|
- if (teamId.equals(score.getTeamId())) {
|
|
|
- GameScoreBo updateBo = new GameScoreBo();
|
|
|
- updateBo.setScoreId(score.getScoreId());
|
|
|
- updateBo.setScoreRank(rank);
|
|
|
- updateBo.setScorePoint(points); // 使用队伍排名对应的积分
|
|
|
- updateBo.setEventId(eventId);
|
|
|
- updateBo.setProjectId(projectId);
|
|
|
-
|
|
|
- updateByBo(updateBo);
|
|
|
- }
|
|
|
- }
|
|
|
+ teamPoints.put(teamId, points);
|
|
|
+ teamRanks.put(teamId, rank);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新每个队伍中所有运动员的成绩记录
|
|
|
+ for (GameScoreVo score : allScores) {
|
|
|
+ Long teamId = score.getTeamId();
|
|
|
+ if (teamId != null && teamPoints.containsKey(teamId)) {
|
|
|
+ GameScoreBo updateBo = new GameScoreBo();
|
|
|
+ updateBo.setScoreId(score.getScoreId());
|
|
|
+ updateBo.setScoreRank(teamRanks.get(teamId));
|
|
|
+ updateBo.setScorePoint(teamPoints.get(teamId));
|
|
|
+ updateBo.setEventId(eventId);
|
|
|
+ updateBo.setProjectId(projectId);
|
|
|
+
|
|
|
+ updateByBo(updateBo);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|