|
|
@@ -4,9 +4,12 @@ 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.TypeReference;
|
|
|
+import com.ylx.common.core.domain.R;
|
|
|
import com.ylx.common.exception.ServiceException;
|
|
|
import com.ylx.usercenter.domain.dto.UnifiedUserCenterDTO;
|
|
|
-import com.ylx.usercenter.domain.vo.UnifiedUserClientVO;
|
|
|
+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;
|
|
|
@@ -27,20 +30,21 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
|
|
|
private static final String UNBIND_PATH = "/userApp/unbind";
|
|
|
|
|
|
@Override
|
|
|
- public UnifiedUserClientVO queryBind(UnifiedUserCenterDTO dto) {
|
|
|
+ public R<?> queryBind(UnifiedUserCenterDTO dto) {
|
|
|
validateDto(dto);
|
|
|
+ dto.setClientId(clientId);
|
|
|
// 只需要关注业务路径和日志描述即可
|
|
|
return executePost(QUERY_BIND_PATH, dto, "查询用户绑定信息");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public UnifiedUserClientVO bind(UnifiedUserCenterDTO dto) {
|
|
|
+ public R<?> bind(UnifiedUserCenterDTO dto) {
|
|
|
validateDto(dto);
|
|
|
return executePost(BIND_PATH, dto, "添加用户绑定信息");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public UnifiedUserClientVO unbind(UnifiedUserCenterDTO dto) {
|
|
|
+ public R<?> unbind(UnifiedUserCenterDTO dto) {
|
|
|
validateDto(dto);
|
|
|
return executePost(UNBIND_PATH, dto, "解除用户绑定信息");
|
|
|
}
|
|
|
@@ -48,13 +52,12 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
|
|
|
/**
|
|
|
* 通用 HTTP POST 请求执行模板
|
|
|
*/
|
|
|
- private UnifiedUserClientVO executePost(String path, UnifiedUserCenterDTO dto, String logDesc) {
|
|
|
+ private R<?> executePost(String path, UnifiedUserCenterDTO dto, String logDesc) {
|
|
|
try {
|
|
|
// 1. 构建 URL
|
|
|
String url = baseUrl + path;
|
|
|
|
|
|
// 2. 转换参数
|
|
|
- dto.setClientId(clientId);
|
|
|
String jsonParam = JSON.toJSONString(dto);
|
|
|
log.info("调用远程接口: {}, 参数: {}", url, jsonParam);
|
|
|
|
|
|
@@ -67,12 +70,34 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
|
|
|
}
|
|
|
|
|
|
// 5. 解析结果
|
|
|
- UnifiedUserClientVO response = JSON.parseObject(result, UnifiedUserClientVO.class);
|
|
|
- if (response == null) {
|
|
|
- throw new RuntimeException(logDesc + "失败:响应对象解析为空");
|
|
|
+ UnifiedUserCenterResponseVO response = JSON.parseObject(
|
|
|
+ result,
|
|
|
+ new TypeReference<UnifiedUserCenterResponseVO>() {
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ // 4. 处理业务状态
|
|
|
+ if (!response.isSuccess()) {
|
|
|
+ log.warn("查询绑定信息失败: data={},code={}, msg={}", response.getData(), response.getCode(), response.getMessage());
|
|
|
+ return R.fail(response.getData(), response.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 处理 data 字段
|
|
|
+ Object dataObj = response.getData();
|
|
|
+
|
|
|
+ // 情况 A: data 是布尔值 false (虽然 code=0,但没数据)
|
|
|
+ if (dataObj instanceof Boolean) {
|
|
|
+ log.info("接口返回 data 为布尔值: {}", dataObj);
|
|
|
+ return R.ok(response.getData());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 情况 B: data 是包含列表的对象 { "userClients": [...] }
|
|
|
+ if (dataObj instanceof UnifiedUserClientListVO) {
|
|
|
+ UnifiedUserClientListVO wrapper = (UnifiedUserClientListVO) dataObj;
|
|
|
+ return R.ok(wrapper.getUserClients(), response.getMessage());
|
|
|
}
|
|
|
|
|
|
- return response;
|
|
|
+ return R.ok();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("{}发生异常", logDesc, e);
|