Parcourir la source

feat(game-event): 增加手机号查询用户及运动员信息功能

- 修改数据库连接配置,更新数据库名为 game-event
- 在 GameAthleteMapper 中新增 selectByPhone 方法
- 在 GameUserMapper 中新增 selectUserByIdAndPhone 方法,并为现有查询增加 del_flag 过滤条件
- 扩展 UserEventService 和 UserEventController,支持通过 userId 和 phone 获取用户赛事信息
- 在 UserEventInfoVo 和 UserLoginVo 中新增 phone 字段,用于传输手机号信息
- 更新登录逻辑,保存并更新用户手机号- 调整查询逻辑,使用手机号关联查询运动员信息
zhou il y a 3 semaines
Parent
commit
9fd9ecce95

+ 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/ry-vue?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
 #          password: P@ssw0rd
           password: 123456

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

@@ -41,10 +41,11 @@ public class UserEventController {
         }
     }
 
-    @GetMapping("/eventInfo/{userId}")
-    public R<UserEventInfoVo> getUserEventInfo(@PathVariable Long userId) {
+    @Log(title = "我的赛事-用户获取信息", businessType = BusinessType.OTHER)
+    @GetMapping("/eventInfo/{userId}/{phone}")
+    public R<UserEventInfoVo> getUserEventInfo(@PathVariable Long userId, @PathVariable String phone) {
         try {
-            UserEventInfoVo result = userEventService.getUserEventInfo(userId);
+            UserEventInfoVo result = userEventService.getUserEventInfo(userId, phone);
             return R.ok(result);
         } catch (Exception e) {
             return R.fail("获取用户赛事信息失败:" + e.getMessage());

+ 1 - 0
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/domain/vo/app/UserEventInfoVo.java

@@ -24,6 +24,7 @@ public class UserEventInfoVo implements Serializable {
     private String username;
     private String nickName;
     private String avatar;
+    private String phone;
 
     // 运动员信息
     private GameAthleteVo athleteInfo;

+ 6 - 1
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/domain/vo/app/UserLoginVo.java

@@ -31,10 +31,15 @@ public class UserLoginVo implements Serializable {
     private String avatarUrl;
 
     /**
-     * 性别 0-未知 1-男 2-女
+     * 性别 1-男 2-女 3-混合
      */
     private Integer gender;
 
+    /**
+     * 手机号
+     */
+    private String phone;
+
     /**
      * 国家
      */

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

@@ -19,6 +19,9 @@ 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 * from game_athlete where phone = #{phone} AND del_flag = '0'")
+    GameAthlete selectByPhone(String phone);
+
     @Select("select athlete_id,name,team_id from game_athlete where event_id = #{eventId} and del_flag = '0'")
     List<GameAthleteVo> queryAthleteIdAndName(Long eventId);
 }

+ 12 - 2
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/mapper/app/GameUserMapper.java

@@ -18,7 +18,7 @@ public interface GameUserMapper extends BaseMapperPlus<GameUser, GameUserVo> {
      * @param username 用户名
      * @return 用户
      */
-    @Select("select * from game_user where username = #{username}")
+    @Select("select * from game_user where username = #{username} AND del_flag = '0'")
     GameUser selectUserByUserName(String username);
 
     /**
@@ -27,9 +27,19 @@ public interface GameUserMapper extends BaseMapperPlus<GameUser, GameUserVo> {
      * @param userId 用户ID
      * @return 用户
      */
-    @Select("select * from game_user where user_id = #{userId}")
+    @Select("select * from game_user where user_id = #{userId} AND del_flag = '0'")
     GameUser selectUserById(Long userId);
 
+    /**
+     * 根据用户ID和手机号查询用户
+     *
+     * @param userId 用户ID
+     * @param phone  手机号
+     * @return 用户
+     */
+    @Select("select * from game_user where user_id = #{userId} AND phone = #{phone} AND del_flag = '0'")
+    GameUser selectUserByIdAndPhone(Long userId, String phone);
+
     /**
      * 根据微信openid查询用户
      *

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

@@ -8,5 +8,5 @@ public interface IUserEventService {
     UserEventInfoVo login(UserLoginVo loginVo);
 
     // 获取用户赛事信息
-    UserEventInfoVo getUserEventInfo(Long userId);
+    UserEventInfoVo getUserEventInfo(Long userId, String phone);
 }

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

@@ -74,6 +74,7 @@ public class UserEventServiceImpl implements IUserEventService {
             result.setUsername(user.getUsername());
             result.setNickName(user.getNickname());
             result.setAvatar(user.getAvatar());
+            result.setPhone(user.getPhone());
 
             return result;
         } catch (Exception e) {
@@ -157,6 +158,7 @@ public class UserEventServiceImpl implements IUserEventService {
             user.setUsername("wx_" + openid.substring(0, Math.min(8, openid.length()))); // 生成用户名
             user.setNickname(loginVo.getNickName() != null ? loginVo.getNickName() : "微信用户");
             user.setAvatar(loginVo.getAvatarUrl());
+            user.setPhone(loginVo.getPhone());
             // 注意:如果数据库password字段允许为NULL,则不需要设置密码
             // 如果数据库password字段不允许为NULL,请取消注释下面这行代码
             // user.setPassword("WX_LOGIN_" + System.currentTimeMillis());
@@ -175,6 +177,9 @@ public class UserEventServiceImpl implements IUserEventService {
             if (loginVo.getAvatarUrl() != null && !loginVo.getAvatarUrl().isEmpty()) {
                 user.setAvatar(loginVo.getAvatarUrl());
             }
+            if (loginVo.getAvatarUrl() != null && !loginVo.getAvatarUrl().isEmpty()) {
+                user.setPhone(loginVo.getPhone());
+            }
             user.setUpdateTime(new Date());
 
             // 更新用户
@@ -185,7 +190,7 @@ public class UserEventServiceImpl implements IUserEventService {
     }
 
     @Override
-    public UserEventInfoVo getUserEventInfo(Long userId) {
+    public UserEventInfoVo getUserEventInfo(Long userId, String phone) {
         // 步骤1:查询用户基本信息
         GameUser user = gameUserMapper.selectUserById(userId);
         if (user == null) {
@@ -193,7 +198,7 @@ public class UserEventServiceImpl implements IUserEventService {
         }
 
         // 步骤2:查询用户关联的运动员信息
-        GameAthlete athlete = gameAthleteMapper.selectByUserId(userId);
+        GameAthlete athlete = gameAthleteMapper.selectByPhone(phone);
         if (athlete == null) {
             throw new RuntimeException("用户未关联运动员信息");
         }
@@ -224,6 +229,7 @@ public class UserEventServiceImpl implements IUserEventService {
         result.setUsername(user.getUsername());
         result.setNickName(user.getNickname());
         result.setAvatar(user.getAvatar());
+        result.setPhone(athlete.getPhone());
 
         // 设置运动员信息
         GameAthleteVo athleteInfo = MapstructUtils.convert(athlete, GameAthleteVo.class);
@@ -244,6 +250,7 @@ public class UserEventServiceImpl implements IUserEventService {
         result.setUsername(user.getUsername());
         result.setNickName(user.getNickname());
         result.setAvatar(user.getAvatar());
+        result.setPhone(athlete.getPhone());
 
         // 组装运动员信息
         GameAthleteVo athleteInfo = MapstructUtils.convert(athlete, GameAthleteVo.class);