|
|
@@ -1,5 +1,6 @@
|
|
|
package com.ylx.usercenter.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
@@ -11,6 +12,7 @@ import com.ylx.lottery.service.LotteryCountService;
|
|
|
import com.ylx.massage.domain.TWxUser;
|
|
|
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;
|
|
|
@@ -22,6 +24,9 @@ import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@@ -29,13 +34,15 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
|
|
|
|
|
|
@Value("${remote.user-center.base-url}")
|
|
|
private String userCenterBaseUrl;
|
|
|
- @Value("${remote.local-live.client-id}")
|
|
|
+ @Value("${remote.night-fragrance.client-id}")
|
|
|
private String clientId;
|
|
|
|
|
|
// 定义接口路径常量
|
|
|
private static final String QUERY_BIND_PATH = "/userApp/queryBind";
|
|
|
private static final String BIND_PATH = "/userApp/bind";
|
|
|
private static final String UNBIND_PATH = "/userApp/unbind";
|
|
|
+ private static final String QUERY_CLIENTS_PATH = "/userApp/queryClients";
|
|
|
+ private static final int DEFAULT_TIMEOUT = 5000; // 5秒超时
|
|
|
@Resource
|
|
|
private TWxUserService wxUserService;
|
|
|
@Resource
|
|
|
@@ -95,6 +102,12 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
|
|
|
return executePost(UNBIND_PATH, dto, "解除用户绑定信息");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public OneAccountVO queryClients(String uuid) {
|
|
|
+ log.info("调用一账通查询平台绑定信息:{}", uuid);
|
|
|
+ return this.queryClientsByUuid(uuid);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通用 HTTP POST 请求执行模板
|
|
|
*/
|
|
|
@@ -241,4 +254,59 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private OneAccountVO queryClientsByUuid(String uuid) {
|
|
|
+ try {
|
|
|
+ // 1. 构建请求参数
|
|
|
+ String url = userCenterBaseUrl + QUERY_CLIENTS_PATH;
|
|
|
+ Map<String, Object> params = Collections.singletonMap("uuid", uuid);
|
|
|
+
|
|
|
+ // 2. 发送请求
|
|
|
+ String resultJson = HttpUtil.get(url, params, DEFAULT_TIMEOUT);
|
|
|
+
|
|
|
+ // 3. 校验结果
|
|
|
+ if (StrUtil.isEmpty(resultJson)) {
|
|
|
+ throw new RuntimeException("调用一账通查询平台绑定信息接口失败:接口返回空结果");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 解析结果
|
|
|
+ UnifiedUserCenterResponseVO<List<OneAccountVO>> response = JSON.parseObject(
|
|
|
+ resultJson,
|
|
|
+ new TypeReference<UnifiedUserCenterResponseVO<List<OneAccountVO>>>() {
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ // 5. 处理业务状态
|
|
|
+ if (ObjUtil.isNull(response) || !response.isSuccess()) {
|
|
|
+ String msg = ObjUtil.isNotNull(response) ? response.getMessage() : "未知错误";
|
|
|
+ Integer code = ObjUtil.isNotNull(response) ? response.getCode() : -1;
|
|
|
+
|
|
|
+ log.warn("调用一账通查询平台绑定信息接口失败: code={}, msg={}", code, msg);
|
|
|
+ throw new ServiceException("远程接口返回失败: " + msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 获取数据列表
|
|
|
+ List<OneAccountVO> oneAccountVOs = response.getData();
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(oneAccountVOs)) {
|
|
|
+ log.info("未查询到相关活动数据");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ OneAccountVO oneAccount = oneAccountVOs.stream().filter(item -> item.getClientId().equals(clientId)).findFirst().orElse(null);
|
|
|
+
|
|
|
+ log.info("成功获取调用一账通查询平台绑定信息: {}", JSON.toJSONString(oneAccount));
|
|
|
+
|
|
|
+ return oneAccount;
|
|
|
+
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ // 透传业务异常,不要重复包装
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用一账通查询平台绑定信息接口发生系统异常", e);
|
|
|
+ // 优化点:只抛出消息,不要直接把整个 Exception 对象 toString() 拼接到字符串里
|
|
|
+ throw new ServiceException("调用一账通查询平台绑定信息接口异常: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|