CluesService.java
7 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package cn.com.glsx.stoassistant.service.clues;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.com.glsx.stoassistant.config.GSCServicePoolConfig;
import cn.com.glsx.stoassistant.constans.GSCServiceConstants;
import cn.com.glsx.stoassistant.request.clues.CluesPadPageReq;
import cn.com.glsx.stoassistant.request.clues.CluesStatusCountReq;
import cn.com.glsx.stoassistant.response.clues.CluesPageResp;
import cn.com.glsx.stoassistant.response.clues.CluesStatusCountResp;
import cn.com.glsx.stoassistant.utils.Pagination;
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 CluesService {
@Autowired
private GSCServicePoolConfig gscServicePoolConfig;
public RopResponse<Pagination<CluesPageResp>> page(CluesPadPageReq request) {
try {
// 获取指定服务的配置
GSCServicePoolConfig.GSCServiceParam serviceParam = gscServicePoolConfig.getServiceParam(GSCServiceConstants.GSC_VCP_PAD_FACADE);
// 构建请求参数
Map<String, Object> params = new HashMap<>();
Map<String, Object> tParams = new HashMap<>();
tParams.put("cluesStatus", request.getCluesStatus());
tParams.put("keyword", request.getKeyword());
tParams.put("sellerUserId", request.getSellerUserId());
tParams.put("sellerMerchantId", request.getSellerMerchantId());
params.put("t", tParams);
params.put("pageSize", request.getPageSize());
params.put("currentPage", request.getCurrentPage());
log.info("二手车线索分页查询调用服务:{},请求参数params:{}", GSCServiceConstants.GSC_VCP_PAD_FACADE, params);
// 调用指定服务的接口
String result = SpringCloudHttpUtil.post(
serviceParam,
params,
String.class,
"/clues/page",
null
);
log.info("二手车线索分页查询调用服务:{} 返回结果result:{}", GSCServiceConstants.GSC_VCP_PAD_FACADE, 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为空");
}
log.info("二手车线索分页查询调用服务:{},二手车线索分页查询,响应结果:{}", GSCServiceConstants.GSC_VCP_PAD_FACADE, data);
Pagination<CluesPageResp> pagination = new Pagination<>();
pagination.setPageNum((Integer) data.get("current"));
pagination.setPageSize((Integer) data.get("size"));
pagination.setCount((Integer) data.get("total"));
pagination.setData(JSON.parseArray(JSON.toJSONString(data.get("records")), CluesPageResp.class));
return RopResponse.success(pagination);
} catch (Exception e) {
log.error("二手车线索分页查询失败,服务:{}", GSCServiceConstants.GSC_VCP_PAD_FACADE, e);
throw new RuntimeException("二手车线索分页查询失败:" + e.getMessage(), e);
}
}
public RopResponse<CluesStatusCountResp> statusCount(CluesStatusCountReq request) {
try {
// 获取指定服务的配置
GSCServicePoolConfig.GSCServiceParam serviceParam = gscServicePoolConfig.getServiceParam(GSCServiceConstants.GSC_VCP_PAD_FACADE);
// 构建请求参数
Map<String, Object> params = new HashMap<>();
params.put("sellerUserId", request.getSellerUserId());
params.put("sellerMerchantId", request.getSellerMerchantId());
params.put("keyword", request.getKeyword());
log.info("二手车线索状态数量统计调用服务:{},请求参数params:{}", GSCServiceConstants.GSC_VCP_PAD_FACADE, params);
// 调用指定服务的接口
String result = SpringCloudHttpUtil.post(
serviceParam,
params,
String.class,
"/clues/statusCount",
null
);
log.info("二手车线索状态数量统计调用服务:{} 返回结果result:{}", GSCServiceConstants.GSC_VCP_PAD_FACADE, 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为空");
}
log.info("二手车线索状态数量统计调用服务:{},二手车线索状态数量统计查询,响应结果:{}", GSCServiceConstants.GSC_VCP_PAD_FACADE, data);
CluesStatusCountResp cluesStatusCountResp = buildStatusCountResp(data);
return RopResponse.success(cluesStatusCountResp);
} catch (Exception e) {
log.error("二手车线索线索状态数量统计查询失败,服务:{}", GSCServiceConstants.GSC_VCP_PAD_FACADE, e);
throw new RuntimeException("二手车线索线索状态数量统计失败:" + e.getMessage(), e);
}
}
/**
* 构建二手车线索状态数量统计
*
* @param data
* @return
*/
private static CluesStatusCountResp buildStatusCountResp(Map<String, Object> data) {
CluesStatusCountResp response = new CluesStatusCountResp();
response.setTotalCount(Long.parseLong(data.get("totalCount").toString()));
response.setPendingFollowCount(Long.parseLong(data.get("pendingFollowCount").toString()));
response.setFollowingCount(Long.parseLong(data.get("followingCount").toString()));
response.setTempLostCount(Long.parseLong(data.get("tempLostCount").toString()));
response.setSuccessCount(Long.parseLong(data.get("successCount").toString()));
return response;
}
}