LiveCodeService.java
3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package cn.com.glsx.stoassistant.service;
import cn.com.glsx.stoassistant.config.GSCServicePoolConfig;
import cn.com.glsx.stoassistant.constans.GSCServiceConstants;
import cn.com.glsx.stoassistant.request.LiveCodeRequest;
import cn.com.glsx.stoassistant.response.LiveCodeResponse;
import cn.com.glsx.stoassistant.utils.SpringCloudHttpUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* 活码服务
*/
@Slf4j
@Service
public class LiveCodeService {
@Autowired
private GSCServicePoolConfig gscServicePoolConfig;
/**
* 获取群活码
*/
public LiveCodeResponse getLiveCode(LiveCodeRequest request) {
// 默认调用 gsc-vcp-pad-facade 服务
return getLiveCode(request, GSCServiceConstants.GSC_VCP_PAD_FACADE);
}
/**
* 获取群活码(支持指定服务)
*
* @param request 请求参数
* @param serviceName 服务名称(如 gsc-vcp-pad-facade、gsc-vcp-web-facade)
* @return 活码响应
*/
public LiveCodeResponse getLiveCode(LiveCodeRequest request, String serviceName) {
try {
// 获取指定服务的配置
GSCServicePoolConfig.GSCServiceParam serviceParam = gscServicePoolConfig.getServiceParam(serviceName);
// 构建请求参数
Map<String, Object> params = new HashMap<>();
params.put("reportUuidId", request.getReportUuidId());
log.info("调用服务:{},请求参数:{}", serviceName, params);
// 调用指定服务的接口
String result = SpringCloudHttpUtil.post(
serviceParam,
params,
String.class,
"/liveCode/generate",
null
);
log.info("调用服务:{} 返回结果:{}", serviceName, result);
// 解析返回结果
Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
if (resultMap == null) {
throw new RuntimeException("调用服务失败:返回结果为空");
}
Integer code = (Integer) resultMap.get("code");
if (code == null || code != 0) {
String msg = (String) resultMap.get("msg");
throw new RuntimeException("调用服务失败:" + msg);
}
Map<String, Object> data = (Map<String, Object>) resultMap.get("data");
if (data == null) {
throw new RuntimeException("调用服务失败:data为空");
}
LiveCodeResponse response = new LiveCodeResponse();
response.setH5Url((String) data.get("h5Url"));
response.setQrCodeUrl((String) data.get("qrCodeUrl"));
return response;
} catch (Exception e) {
log.error("获取群活码失败,服务:{}", serviceName, e);
throw new RuntimeException("获取群活码失败:" + e.getMessage(), e);
}
}
}