浏览代码

feat(applet): 实现小程序用户信息获取接口

- 新增 AppletUserInfoVO 类,用于封装小程序用户信息
- 修改 AppletUserController 的 getUserInfo 接口返回类型为 AppletUserInfoVO
- 在 UserInfoMapper 中新增 getAppletUserInfo 方法及对应的 XML 查询语句
- 调整 UserInfoService 接口和实现类,替换原有的 getCurrentUserInfo 方法
- 更新 UserOrderInfoServiceImpl 中获取用户 openid 的调用方式
- 移除原 UserController 中的小程序用户信息接口声明
wzq 18 小时之前
父节点
当前提交
a7b336630f

+ 0 - 7
src/main/java/com/zsElectric/boot/business/controller/UserInfoController.java

@@ -32,13 +32,6 @@ public class UserInfoController  {
 
     private final UserInfoService userInfoService;
 
-    @Operation(summary = "获取当前登录用户信息", description = "小程序登录后获取当前用户详细信息")
-    @GetMapping("/current")
-    public Result<UserInfoVO> getCurrentUserInfo() {
-        UserInfoVO userInfo = userInfoService.getCurrentUserInfo();
-        return Result.success(userInfo);
-    }
-
     @Operation(summary = "个人用户信息分页列表")
     @GetMapping("/page")
     @PreAuthorize("@ss.hasPerm('business:user-info:query')")

+ 4 - 3
src/main/java/com/zsElectric/boot/business/controller/applet/AppletUserController.java

@@ -1,6 +1,7 @@
 package com.zsElectric.boot.business.controller.applet;
 
 import com.zsElectric.boot.business.model.vo.UserInfoVO;
+import com.zsElectric.boot.business.model.vo.applet.AppletUserInfoVO;
 import com.zsElectric.boot.business.service.UserInfoService;
 import com.zsElectric.boot.core.web.Result;
 import io.swagger.v3.oas.annotations.Operation;
@@ -20,8 +21,8 @@ public class AppletUserController {
 
     @Operation(summary = "微信小程序获取当前登录信息")
     @GetMapping("/getUserInfo")
-    public Result<UserInfoVO> getUserInfo() {
-        UserInfoVO currentUserInfo = userInfoService.getCurrentUserInfo();
-        return Result.success(currentUserInfo);
+    public Result<AppletUserInfoVO> getUserInfo() {
+        AppletUserInfoVO userInfoVO = userInfoService.getAppletUserInfo();
+        return Result.success(userInfoVO);
     }
 }

+ 3 - 0
src/main/java/com/zsElectric/boot/business/mapper/UserInfoMapper.java

@@ -5,7 +5,9 @@ import com.zsElectric.boot.business.model.entity.UserInfo;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zsElectric.boot.business.model.query.UserInfoQuery;
 import com.zsElectric.boot.business.model.vo.UserInfoVO;
+import com.zsElectric.boot.business.model.vo.applet.AppletUserInfoVO;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 个人用户信息Mapper接口
@@ -25,4 +27,5 @@ public interface UserInfoMapper extends BaseMapper<UserInfo> {
      */
     Page<UserInfoVO> getUserInfoPage(Page<UserInfoVO> page, UserInfoQuery queryParams);
 
+    AppletUserInfoVO getAppletUserInfo(@Param("userId") Long userId);
 }

+ 66 - 1
src/main/java/com/zsElectric/boot/business/model/vo/applet/AppletUserInfoVO.java

@@ -1,4 +1,69 @@
 package com.zsElectric.boot.business.model.vo.applet;
 
-public class AppletUserInfoVO {
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+@Schema( description = "小程序用户信息对象")
+public class AppletUserInfoVO implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 小程序用户ID
+     */
+    private Long appletUserId;
+    /**
+     * 昵称
+     */
+    private String nickName;
+    /**
+     * 手机号
+     */
+    private String phone;
+    /**
+     * 微信openid
+     */
+    private String openid;
+    /**
+     * 积分
+     */
+    private BigDecimal integralNum;
+    /**
+     * 所属第三方(无则为自营)
+     */
+    private Long groupId;
+
+    /**
+     * 可用抵用券余额
+     */
+    private BigDecimal balance;
+
+    /**
+     * 欠款金额
+     */
+    private BigDecimal amountOwed;
+
+    /**
+     * 企业ID
+     */
+    private Long firmId;
+
+    /**
+     * 用户企业身份 1 管理员 2普通员工
+     */
+    private Integer firmUserType;
+
+    /**
+     * 企业名称
+     */
+    private String firmName;
+
 }

+ 2 - 9
src/main/java/com/zsElectric/boot/business/service/UserInfoService.java

@@ -6,6 +6,7 @@ import com.zsElectric.boot.business.model.query.UserInfoQuery;
 import com.zsElectric.boot.business.model.vo.UserInfoVO;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.zsElectric.boot.business.model.vo.applet.AppletUserInfoVO;
 
 /**
  * 个人用户信息服务类
@@ -55,15 +56,6 @@ public interface UserInfoService extends IService<UserInfo> {
      */
     boolean deleteUserInfos(String ids);
 
-    /**
-     * 获取当前登录用户信息(小程序用)
-     * <p>
-     * 根据当前登录用户的手机号获取用户信息
-     *
-     * @return 当前用户信息
-     */
-    UserInfoVO getCurrentUserInfo();
-
     /**
      * 根据手机号获取用户信息
      *
@@ -83,4 +75,5 @@ public interface UserInfoService extends IService<UserInfo> {
      */
     UserInfo registerOrUpdateUserByPhone(String phone, String openId);
 
+    AppletUserInfoVO getAppletUserInfo();
 }

+ 6 - 31
src/main/java/com/zsElectric/boot/business/service/impl/UserInfoServiceImpl.java

@@ -1,6 +1,7 @@
 package com.zsElectric.boot.business.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
+import com.zsElectric.boot.business.model.vo.applet.AppletUserInfoVO;
 import com.zsElectric.boot.security.util.SecurityUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -113,39 +114,13 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
      * @return 当前用户信息
      */
     @Override
-    public UserInfoVO getCurrentUserInfo() {
-        // 从 Spring Security 上下文获取当前登录用户的ID
-        // 注意:小程序用户token中的userId就是c_user_info表的ID
+    public AppletUserInfoVO getAppletUserInfo() {
+        // 从 Spring Security 上下文获取当前登录用户的ID 注意:小程序用户token中的userId就是c_user_info表的ID
         Long userId = SecurityUtils.getUserId();
-        
-        log.info("获取当前用户信息,userId: {}", userId);
-        
-        if (ObjectUtil.isNull(userId)) {
-            log.warn("未获取到当前登录用户ID");
-            return null;
-        }
-
-        // 直接通过ID查询c_user_info表
-        UserInfo userInfo = null;
-        try {
-            log.info("准备查询用户信息,userId: {}", userId);
-            userInfo = this.getById(userId);
-            log.info("查询结果: {}", userInfo != null ? "找到用户" : "未找到用户");
-        } catch (Exception e) {
-            log.error("查询用户信息异常,userId: {}, 错误: {}", userId, e.getMessage(), e);
-            throw e;
+        if(ObjectUtil.isNotNull(userId)) {
+            return this.baseMapper.getAppletUserInfo(userId);
         }
-        
-        if (userInfo == null) {
-            log.warn("未找到用户信息,userId: {}", userId);
-            return null;
-        }
-        
-        log.info("获取用户信息成功,ID: {}, 昵称: {}, 手机号: {}", 
-                userInfo.getId(), userInfo.getNickName(), userInfo.getPhone());
-        
-        // 实体转换为VO
-        return userInfoConverter.toVO(userInfo);
+        return null;
     }
 
     /**

+ 1 - 1
src/main/java/com/zsElectric/boot/business/service/impl/UserOrderInfoServiceImpl.java

@@ -140,7 +140,7 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
     @Override
     public UserPayForm createOrder(LevelOrderForm levelOrderForm) {
         Long userId = SecurityUtils.getUserId();
-        String userOpenId = userInfoService.getCurrentUserInfo().getOpenid();
+        String userOpenId = userInfoService.getAppletUserInfo().getOpenid();
         String orderNo = createOrderNo("SP",userId);
         //创建订单
         UserOrderInfo orderInfo = new UserOrderInfo();

+ 23 - 0
src/main/resources/mapper/business/UserInfoMapper.xml

@@ -22,5 +22,28 @@
         <where>
         </where>
     </select>
+    <select id="getAppletUserInfo" resultType="com.zsElectric.boot.business.model.vo.applet.AppletUserInfoVO">
+        SELECT
+                ui.id,
+                ui.ec_id,
+                ui.nick_name,
+                ui.phone,
+                ui.openid,
+                ui.integral_num,
+                ui.group_id,
+                ua.balance,
+                ua.amount_owed,
+                uf.firm_id,
+                uf.type AS firmUserType,
+                fi.name AS firmName
+        FROM
+            c_user_info ui
+        LEFT JOIN c_user_account ua ON ui.id = ua.user_id
+        LEFT JOIN c_user_firm uf ON ui.id = uf.user_id
+        LEFT JOIN c_firm_info fi ON uf.firm_id = fi.id
+        WHERE
+            ui.is_deleted = 0
+            AND ui.id = #{userId}
+    </select>
 
 </mapper>