|
@@ -1275,70 +1275,73 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
teamQuery.setEventId(eventId);
|
|
|
List<GameTeamVo> teams = gameTeamService.queryList(teamQuery);
|
|
|
|
|
|
- // 批量查询所有队伍在所有项目中的成绩
|
|
|
+ // 批量查询所有队伍在所有项目中的成绩(当前赛事)
|
|
|
List<GameScoreVo> allScores = baseMapper.selectVoList(
|
|
|
Wrappers.lambdaQuery(GameScore.class)
|
|
|
.eq(GameScore::getEventId, eventId)
|
|
|
);
|
|
|
|
|
|
- // 按队伍ID和项目ID分组成绩数据
|
|
|
- Map<String, GameScoreVo> scoreMap = new HashMap<>();
|
|
|
+ // 构建 teamId -> (projectId -> 积分累计和)
|
|
|
+ Map<Long, Map<Long, Integer>> teamProjectPointSumMap = new HashMap<>();
|
|
|
for (GameScoreVo score : allScores) {
|
|
|
- if (score.getTeamId() != null && score.getProjectId() != null) {
|
|
|
- String key = score.getTeamId() + "_" + score.getProjectId();
|
|
|
- scoreMap.put(key, score);
|
|
|
+ Long teamId = score.getTeamId();
|
|
|
+ Long projectId = score.getProjectId();
|
|
|
+ if (teamId == null || projectId == null) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+ int points = score.getScorePoint() != null ? score.getScorePoint() : 0;
|
|
|
+
|
|
|
+ Map<Long, Integer> projectPointMap = teamProjectPointSumMap.computeIfAbsent(teamId, k -> new HashMap<>());
|
|
|
+ projectPointMap.merge(projectId, points, Integer::sum);
|
|
|
}
|
|
|
|
|
|
- // 构建加分数据
|
|
|
+ // 构建导出/前端展示数据
|
|
|
List<Map<String, Object>> bonusData = new ArrayList<>();
|
|
|
|
|
|
- for (int i = 0; i < teams.size(); i++) {
|
|
|
- GameTeamVo team = teams.get(i);
|
|
|
+ for (GameTeamVo team : teams) {
|
|
|
Map<String, Object> teamData = new HashMap<>();
|
|
|
-
|
|
|
- // 设置基本信息
|
|
|
teamData.put("teamId", team.getTeamId());
|
|
|
teamData.put("teamName", team.getTeamName());
|
|
|
- teamData.put("rank", i + 1);
|
|
|
|
|
|
- // 计算该队伍在各项目中的积分
|
|
|
- int totalScore = 0;
|
|
|
+ // 项目积分:按项目名称汇总
|
|
|
Map<String, Integer> projectScores = new HashMap<>();
|
|
|
- int leaderPoint = 0;
|
|
|
- int extraPoint = 0;
|
|
|
+ int totalScore = 0;
|
|
|
|
|
|
- // 设置各项目积分
|
|
|
- for (GameEventProjectVo project : projects) {
|
|
|
- String key = team.getTeamId() + "_" + project.getProjectId();
|
|
|
- GameScoreVo score = scoreMap.get(key);
|
|
|
+ Map<Long, Integer> projectPointMap = teamProjectPointSumMap.getOrDefault(team.getTeamId(), Collections.emptyMap());
|
|
|
|
|
|
- int projectScore = 0;
|
|
|
- if (score != null && score.getScorePoint() != null) {
|
|
|
- projectScore = score.getScorePoint();
|
|
|
- totalScore += projectScore;
|
|
|
+ for (GameEventProjectVo project : projects) {
|
|
|
+ int projectScore = projectPointMap.getOrDefault(project.getProjectId(), 0);
|
|
|
+ projectScores.put(project.getProjectName(), projectScore);
|
|
|
+ totalScore += projectScore;
|
|
|
+ }
|
|
|
|
|
|
- // 获取加分数据
|
|
|
+ // 读取加分(若有,取队伍该赛事下任一成绩记录中的加分;否则默认为0)
|
|
|
+ int leaderPoint = 0;
|
|
|
+ int extraPoint = 0;
|
|
|
+ for (GameScoreVo score : allScores) {
|
|
|
+ if (Objects.equals(score.getTeamId(), team.getTeamId())) {
|
|
|
if (score.getLeaderPoint() != null) {
|
|
|
leaderPoint = score.getLeaderPoint();
|
|
|
}
|
|
|
if (score.getExtraPoint() != null) {
|
|
|
extraPoint = score.getExtraPoint();
|
|
|
}
|
|
|
+ // 找到一条即可(两者若分散在不同记录中,按最后一次非空覆盖)
|
|
|
}
|
|
|
-
|
|
|
- projectScores.put(project.getProjectName(), projectScore);
|
|
|
}
|
|
|
|
|
|
+ // 汇总总分(基础项目分 + 加分)
|
|
|
+ int finalTotal = totalScore + leaderPoint + extraPoint;
|
|
|
+
|
|
|
teamData.put("projectScores", projectScores);
|
|
|
- teamData.put("totalScore", totalScore);
|
|
|
+ teamData.put("totalScore", finalTotal);
|
|
|
teamData.put("leaderPoint", leaderPoint);
|
|
|
teamData.put("extraPoint", extraPoint);
|
|
|
|
|
|
bonusData.add(teamData);
|
|
|
}
|
|
|
|
|
|
- // 按总分排序,生成排名
|
|
|
+ // 按总分排序并标注排名(并列名次同分给同名次,下例采用稳定排序+顺序名次,若需并列逻辑可再调整)
|
|
|
bonusData.sort((a, b) -> Integer.compare((Integer) b.get("totalScore"), (Integer) a.get("totalScore")));
|
|
|
for (int i = 0; i < bonusData.size(); i++) {
|
|
|
bonusData.get(i).put("rank", i + 1);
|
|
@@ -1347,7 +1350,6 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("rows", bonusData);
|
|
|
result.put("projects", projects);
|
|
|
-
|
|
|
return result;
|
|
|
|
|
|
} catch (Exception e) {
|