|
@@ -15,6 +15,7 @@ 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.*;
|
|
|
+import org.dromara.system.mapper.GameAthleteMapper;
|
|
|
import org.dromara.system.mapper.GameEventProjectMapper;
|
|
|
import org.dromara.system.service.IGameAthleteService;
|
|
|
import org.dromara.system.service.IGameEventProjectService;
|
|
@@ -53,7 +54,7 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
private final GameScoreMapper baseMapper;
|
|
|
private final IGameTeamService gameTeamService;
|
|
|
private final IGameAthleteService gameAthleteService;
|
|
|
-
|
|
|
+ private final GameAthleteMapper gameAthleteMapper;
|
|
|
private final GameEventProjectMapper projectMapper;
|
|
|
private final IGameEventProjectService gameEventProjectService;
|
|
|
|
|
@@ -917,63 +918,96 @@ public class GameScoreServiceImpl implements IGameScoreService {
|
|
|
* 用户端查询项目成绩信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<AppScoreVo> listAppScore(Long eventId, Long projectId) {
|
|
|
- // 获取项目详细信息
|
|
|
- GameEventProjectVo project = gameEventProjectService.queryById(projectId);
|
|
|
+ public List<AppScoreVo> listAppScore(Long eventId) {
|
|
|
+ try {
|
|
|
+ // 1. 获取所有相关成绩
|
|
|
+ List<GameScoreVo> allScores = baseMapper.selectVoList(
|
|
|
+ Wrappers.lambdaQuery(GameScore.class)
|
|
|
+ .eq(GameScore::getEventId, eventId)
|
|
|
+ );
|
|
|
|
|
|
- // 查询参与了该项目的运动员
|
|
|
- List<GameAthleteVo> athletes = gameAthleteService.queryListByEventIdAndProjectId(eventId, projectId, null);
|
|
|
-
|
|
|
- // 获取所有相关成绩
|
|
|
- GameScoreBo scoreBo = new GameScoreBo();
|
|
|
- scoreBo.setEventId(eventId);
|
|
|
- scoreBo.setProjectId(projectId);
|
|
|
- List<GameScoreVo> scores = queryList(scoreBo);
|
|
|
-
|
|
|
- // 创建成绩映射 athleteId -> GameScoreVo
|
|
|
- Map<Long, GameScoreVo> scoreMap = scores.stream()
|
|
|
- .collect(Collectors.toMap(GameScoreVo::getAthleteId, Function.identity(), (existing, replacement) -> existing));
|
|
|
-
|
|
|
- // 队伍id与名称的映射
|
|
|
- Set<Long> teamIds = athletes.stream().map(GameAthleteVo::getTeamId).collect(Collectors.toSet());
|
|
|
- Map<Long, String> teamMap = gameTeamService.queryTeamIdAndName(teamIds);
|
|
|
-
|
|
|
- List<AppScoreVo> result = result = athletes.stream().map(athlete -> {
|
|
|
- AppScoreVo vo = new AppScoreVo();
|
|
|
- vo.setProjectId(projectId);
|
|
|
- vo.setProjectName(project != null ? project.getProjectName() : "");
|
|
|
- vo.setClassification(project != null ? project.getClassification() : "");
|
|
|
- vo.setAthleteId(athlete.getAthleteId());
|
|
|
- vo.setAthleteName(athlete.getName());
|
|
|
- vo.setTeamId(athlete.getTeamId());
|
|
|
-
|
|
|
- // 获取队伍信息
|
|
|
- if (athlete.getTeamId() != null) {
|
|
|
- String teamName = teamMap.get(athlete.getTeamId());
|
|
|
- vo.setTeamName(teamName != null ? teamName : "");
|
|
|
+ if (allScores.isEmpty()) {
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
- // 获取成绩信息
|
|
|
- GameScoreVo score = scoreMap.get(athlete.getAthleteId());
|
|
|
- if (score != null) {
|
|
|
+ // 2. 获取所有运动员信息
|
|
|
+ List<GameAthleteVo> athletes = gameAthleteMapper.queryAthleteIdAndName(eventId);
|
|
|
+ Map<Long, GameAthleteVo> athleteMap = athletes.stream()
|
|
|
+ .collect(Collectors.toMap(GameAthleteVo::getAthleteId, Function.identity(), (existing, replacement) -> existing));
|
|
|
+
|
|
|
+ // 3. 获取所有队伍信息
|
|
|
+ Set<Long> teamIds = athletes.stream()
|
|
|
+ .map(GameAthleteVo::getTeamId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ Map<Long, String> teamMap = gameTeamService.queryTeamIdAndName(teamIds);
|
|
|
+
|
|
|
+ // 4. 获取所有项目信息
|
|
|
+ GameEventProjectBo projectQuery = new GameEventProjectBo();
|
|
|
+ projectQuery.setEventId(eventId);
|
|
|
+ List<GameEventProjectVo> projects = gameEventProjectService.queryList(projectQuery);
|
|
|
+ Map<Long, GameEventProjectVo> projectMap = projects.stream()
|
|
|
+ .collect(Collectors.toMap(GameEventProjectVo::getProjectId, Function.identity(), (existing, replacement) -> existing));
|
|
|
+
|
|
|
+ // 5. 构建结果
|
|
|
+ List<AppScoreVo> result = new ArrayList<>();
|
|
|
+
|
|
|
+ for (GameScoreVo score : allScores) {
|
|
|
+ AppScoreVo vo = new AppScoreVo();
|
|
|
+
|
|
|
+ // 设置基本信息
|
|
|
+ vo.setAthleteId(score.getAthleteId());
|
|
|
+ vo.setTeamId(score.getTeamId());
|
|
|
+ vo.setProjectId(score.getProjectId());
|
|
|
+
|
|
|
+ // 设置运动员名称
|
|
|
+ GameAthleteVo athlete = athleteMap.get(score.getAthleteId());
|
|
|
+ if (athlete != null) {
|
|
|
+ vo.setAthleteName(athlete.getName());
|
|
|
+ } else {
|
|
|
+ vo.setAthleteName("");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置队伍名称
|
|
|
+ if (score.getTeamId() != null) {
|
|
|
+ String teamName = teamMap.get(score.getTeamId());
|
|
|
+ vo.setTeamName(teamName != null ? teamName : "");
|
|
|
+ } else {
|
|
|
+ vo.setTeamName("");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置项目信息
|
|
|
+ GameEventProjectVo project = projectMap.get(score.getProjectId());
|
|
|
+ if (project != null) {
|
|
|
+ vo.setProjectName(project.getProjectName());
|
|
|
+ vo.setClassification(project.getClassification());
|
|
|
+ } else {
|
|
|
+ vo.setProjectName("");
|
|
|
+ vo.setClassification("");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置成绩信息
|
|
|
vo.setIndividualPerformance(convertToBigDecimal(score.getIndividualPerformance()));
|
|
|
vo.setTeamPerformance(convertToBigDecimal(score.getTeamPerformance()));
|
|
|
- vo.setScorePoint(score.getScorePoint());
|
|
|
- vo.setScoreRank(score.getScoreRank());
|
|
|
- } else {
|
|
|
- vo.setIndividualPerformance(BigDecimal.ZERO);
|
|
|
- vo.setTeamPerformance(BigDecimal.ZERO);
|
|
|
- vo.setScorePoint(0);
|
|
|
- vo.setScoreRank(0);
|
|
|
+ vo.setScorePoint(score.getScorePoint() != null ? score.getScorePoint() : 0);
|
|
|
+ vo.setScoreRank(score.getScoreRank() != null ? score.getScoreRank() : 0);
|
|
|
+
|
|
|
+ result.add(vo);
|
|
|
}
|
|
|
|
|
|
- return vo;
|
|
|
- }).toList();
|
|
|
+ // 6. 按排名排序(排名为0或null的排在最后)
|
|
|
+ return result.stream()
|
|
|
+ .sorted((a, b) -> {
|
|
|
+ Integer rankA = a.getScoreRank() != null ? a.getScoreRank() : Integer.MAX_VALUE;
|
|
|
+ Integer rankB = b.getScoreRank() != null ? b.getScoreRank() : Integer.MAX_VALUE;
|
|
|
+ return Integer.compare(rankA, rankB);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- // 按排名排序
|
|
|
- return result.stream()
|
|
|
- .sorted(Comparator.comparing(AppScoreVo::getScoreRank))
|
|
|
- .collect(Collectors.toList());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询用户端成绩信息失败", e);
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|