Bläddra i källkod

feat(game-event): 查询成绩接口更新

zhou 1 månad sedan
förälder
incheckning
8cf8e49b41

+ 5 - 5
pom.xml

@@ -91,10 +91,7 @@
                 <monitor.username>ruoyi</monitor.username>
                 <monitor.password>123456</monitor.password>
             </properties>
-            <activation>
-                <!-- 默认环境 -->
-                <activeByDefault>true</activeByDefault>
-            </activation>
+
 
         </profile>
         <profile>
@@ -105,7 +102,10 @@
                 <monitor.username>ruoyi</monitor.username>
                 <monitor.password>123456</monitor.password>
             </properties>
-
+            <activation>
+                <!-- 默认环境 -->
+                <activeByDefault>true</activeByDefault>
+            </activation>
 
         </profile>
     </profiles>

+ 1 - 1
ruoyi-admin/src/main/resources/application-dev.yml

@@ -50,7 +50,7 @@ spring:
           # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
           # rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
 #          url: jdbc:mysql://192.168.1.146:3306/game_event?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
-          url: jdbc:mysql://localhost:3306/game_event?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
+          url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
           username: root
 #          password: P@ssw0rd
           password: 123456

+ 4 - 3
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/controller/app/ScoreController.java

@@ -44,12 +44,13 @@ public class ScoreController {
 
     /**
      * 查询成绩
+     * @param eventId 赛事ID
+     * @response {@link R<List<AppScoreVo>>}
      */
     @GetMapping("/list")
     public R<List<AppScoreVo>> listScore(
-        @RequestParam("eventId") Long eventId,
-        @RequestParam("projectId") Long projectId){
-        List<AppScoreVo> result = gameScoreService.listAppScore(eventId, projectId);
+        @RequestParam("eventId") Long eventId){
+        List<AppScoreVo> result = gameScoreService.listAppScore(eventId);
         return R.ok(result);
     }
 

+ 35 - 3
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/domain/vo/AppScoreVo.java

@@ -1,5 +1,6 @@
 package org.dromara.system.domain.vo;
 
+import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
 import lombok.Data;
 
 import java.io.Serial;
@@ -8,6 +9,7 @@ import java.math.BigDecimal;
 
 /**
  * 小程序端查询成绩信息结果Vo
+ * @author zlt
  */
 @Data
 public class AppScoreVo implements Serializable {
@@ -15,19 +17,49 @@ public class AppScoreVo implements Serializable {
     @Serial
     private static final long serialVersionUID = 1L;
 
+    /**
+     * 项目id
+     */
     private Long projectId;
+    /**
+     * 项目名称
+     */
     private String projectName;
+    /**
+     * 项目归类
+     */
     private String classification;
-
+    /**
+     * 队伍id
+     */
     private Long teamId;
+    /**
+     * 队伍名称
+     */
     private String teamName;
-
+    /**
+     * 运动员id
+     */
     private Long athleteId;
+    /**
+     * 运动员名称
+     */
     private String athleteName;
-
+    /**
+     * 个人成绩
+     */
     private BigDecimal individualPerformance;
+    /**
+     * 团队成绩
+     */
     private BigDecimal teamPerformance;
+    /**
+     * 积分
+     */
     private Integer scorePoint;
+    /**
+     * 排名
+     */
     private Integer scoreRank;
 
 }

+ 6 - 0
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/mapper/GameAthleteMapper.java

@@ -5,6 +5,9 @@ import org.dromara.system.domain.GameAthlete;
 import org.dromara.system.domain.vo.GameAthleteVo;
 import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * 参赛队员Mapper接口
  *
@@ -15,4 +18,7 @@ public interface GameAthleteMapper extends BaseMapperPlus<GameAthlete, GameAthle
 
     @Select("select * from game_athlete where user_id = #{userId} AND del_flag = '0'")
     GameAthlete selectByUserId(Long userId);
+
+    @Select("select athlete_id,name,team_id from game_athlete where event_id = #{eventId} and del_flag = '0'")
+    List<GameAthleteVo> queryAthleteIdAndName(Long eventId);
 }

+ 1 - 2
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/service/IGameScoreService.java

@@ -121,10 +121,9 @@ public interface IGameScoreService {
     /**
      * 用户端查询项目成绩信息
      * @param eventId
-     * @param projectId
      * @return
      */
-    List<AppScoreVo> listAppScore(Long eventId, Long projectId);
+    List<AppScoreVo> listAppScore(Long eventId);
 
     /**
      * 获取加分数据

+ 84 - 50
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/service/impl/GameScoreServiceImpl.java

@@ -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<>();
+        }
     }
 
     /**