浏览代码

调整查询绑定接口

wangzhijun 1 周之前
父节点
当前提交
3c090d132c

+ 28 - 10
nightFragrance-massage/src/main/java/com/ylx/usercenter/service/impl/UnifiedUserCenterServiceImpl.java

@@ -5,6 +5,8 @@ import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.ylx.common.core.domain.R;
 import com.ylx.common.exception.ServiceException;
@@ -14,7 +16,6 @@ import com.ylx.massage.service.TWxUserService;
 import com.ylx.usercenter.domain.dto.UnifiedUserCenterDTO;
 import com.ylx.usercenter.domain.vo.OneAccountVO;
 import com.ylx.usercenter.domain.vo.UnifiedUserCenterResponseVO;
-import com.ylx.usercenter.domain.vo.UnifiedUserClientListVO;
 import com.ylx.usercenter.service.UnifiedUserCenterService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
@@ -72,7 +73,7 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
             R<?> remoteResult = executePost(BIND_PATH, dto, "添加用户绑定信息");
 
             // 4. 判断绑定成功
-            if (!remoteResult.getData().equals(Boolean.TRUE)) {
+            if (ObjUtil.notEqual(remoteResult.getCode(), 200)) {
                 log.error("远程绑定失败, userId: {}, msg: {}", dto.getSourceUserId(), remoteResult.getMsg());
                 return R.fail("用户绑定失败:" + remoteResult.getMsg());
             }
@@ -138,7 +139,6 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
                 return R.fail(response.getData(), response.getMessage());
             }
 
-            // 5. 处理 data 字段
             Object dataObj = response.getData();
 
             // 情况 A: data 是布尔值 false (虽然 code=0,但没数据)
@@ -147,13 +147,27 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
                 return R.ok(response.getData());
             }
 
-            // 情况 B: data 是包含列表的对象 { "userClients": [...] }
-            if (dataObj instanceof UnifiedUserClientListVO) {
-                UnifiedUserClientListVO wrapper = (UnifiedUserClientListVO) dataObj;
-                return R.ok(wrapper.getUserClients(), response.getMessage());
+            // 情况 B: data 是 JSONObject (例如: { "userClients": [...] })
+            if (dataObj instanceof JSONObject) {
+                JSONObject jsonObject = (JSONObject) dataObj;
+
+                // 优先尝试获取 "userClients" 字段 (针对当前截图的场景)
+                Object userClientsObj = jsonObject.get("userClients");
+
+                if (userClientsObj instanceof JSONArray) {
+                    JSONArray userClientsArray = (JSONArray) userClientsObj;
+                    log.info("获取到用户客户端数量: {}", userClientsArray.size());
+                    // 如果需要转为具体的 List<UserClientVO>,可以在这里做转换
+                    return R.ok(userClientsArray);
+                }
+
+                // 兜底逻辑:如果是其他类型的 JSONObject (例如查询详情),直接返回整个对象
+                // 避免数据丢失
+                return R.ok(jsonObject);
             }
 
-            return R.ok();
+            // 情况 C: data 是其他类型 (例如直接是一个 String 或 Number)
+            return R.ok(dataObj);
 
         } catch (Exception e) {
             log.error("{}发生异常", logDesc, e);
@@ -172,8 +186,12 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
         if (StrUtil.isEmpty(dto.getTargetUserId())) {
             throw new IllegalArgumentException("目标用户ID不能为空");
         }
-        if (StrUtil.isEmpty(dto.getClientId())) {
-            throw new IllegalArgumentException("客户端ID不能为空");
+        if (StrUtil.isEmpty(dto.getSourceClientId())) {
+            throw new IllegalArgumentException("源客户端ID不能为空");
+        }
+
+        if (StrUtil.isEmpty(dto.getTargetClientId())) {
+            throw new IllegalArgumentException("目标客户端ID不能为空");
         }
     }