瀏覽代碼

feat(game-event): 更新数据库连接配置并优化用户赛事信息查询逻辑

- 修改 application-dev.yml 数据库连接地址、用户名和密码为生产环境配置- 注释本地数据库配置项,便于快速切换
- 修改 redis 密码配置
- 在 UserEventServiceImpl 中引入 JSONUtil 工具类
- 调整运动员参与项目 ID 列表的获取方式,从数据库查询改为从 athlete 对象中解析
- 修复赛事信息查询逻辑,使用 athlete 中的 eventId 替代项目中的 eventId
-优化项目列表排序逻辑,增加对 startTime 为 null 的处理,避免排序异常
zhou 3 周之前
父節點
當前提交
a181c6ea12

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

@@ -50,10 +50,13 @@ 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
-          username: root
+#          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
+#          username: root
+#          password: 123456
 #          password: P@ssw0rd
-          password: 123456
+          url: jdbc:mysql://182.92.79.54:3306/game_event?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
+          username: game_event
+          password: TxtYJXEtnC6ecmBw
 #        # 从库数据源
 #        slave:
 #          lazy: true
@@ -106,7 +109,7 @@ spring.data:
     # 数据库索引
     database: 1
     # redis 密码必须配置
-#    password: ruoyi123
+    password: 123456
     # 连接超时时间
     timeout: 10s
     # 是否开启ssl

+ 7 - 4
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/service/impl/app/UserEventServiceImpl.java

@@ -1,5 +1,6 @@
 package org.dromara.system.service.impl.app;
 
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.dromara.common.core.utils.MapstructUtils;
@@ -202,9 +203,10 @@ public class UserEventServiceImpl implements IUserEventService {
         if (athlete == null) {
             throw new RuntimeException("用户未关联运动员信息");
         }
+        athlete.setUserId(userId);
 
         // 步骤3:查询运动员参与的项目ID列表
-        List<Long> projectIds = gameScoreMapper.selectProjectIdsByAthleteId(athlete.getAthleteId());
+        List<Long> projectIds = JSONUtil.toList(athlete.getProjectValue(), Long.class);
         if (CollectionUtils.isEmpty(projectIds)) {
             // 用户没有参与任何项目
             return buildEmptyUserEventInfo(user, athlete);
@@ -214,7 +216,7 @@ public class UserEventServiceImpl implements IUserEventService {
         List<GameEventProject> projects = gameEventProjectMapper.selectBatchIds(projectIds);
 
         // 步骤5:查询赛事信息
-        GameEvent event = gameEventMapper.selectById(projects.get(0).getEventId());
+        GameEvent event = gameEventMapper.selectById(athlete.getEventId());
 
         // 步骤6:查询运动员在各项目中的成绩
         List<GameScore> scores = gameScoreMapper.selectByAthleteAndProjects(athlete.getAthleteId(), projectIds);
@@ -282,8 +284,9 @@ public class UserEventServiceImpl implements IUserEventService {
             projectList.add(projectInfo);
         }
 
-        // 按项目开始时间排序
-        projectList.sort(Comparator.comparing(GameEventProjectVo::getStartTime));
+        // 按项目开始时间排序,处理startTime为null的情况
+        projectList.sort(Comparator.comparing(GameEventProjectVo::getStartTime,
+            Comparator.nullsLast(Comparator.naturalOrder())));
         result.setProjectList(projectList);
 
         return result;