|
@@ -23,34 +23,35 @@ public class InsCrawlerOrderComponents {
|
|
|
this.restTemplate = restTemplate;
|
|
this.restTemplate = restTemplate;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public < B> B post(String url, String logId, String message, @Nullable Object requestBody, Class<B> responseType, HttpHeaders httpHeaders) {
|
|
|
|
|
|
|
+ public <T, B> B post(String url, String logId, String message, @Nullable T requestBody, Class<B> responseType, HttpHeaders httpHeaders) {
|
|
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
|
+ HttpEntity<T> yaQuoteInfoVoHttpEntity = new HttpEntity<>(requestBody, httpHeaders);
|
|
|
|
|
+
|
|
|
String request = JSON.toJSONString(requestBody);
|
|
String request = JSON.toJSONString(requestBody);
|
|
|
InsuranceLog.infoLog(logId, "\n\t---------> {} \n\t---------> URL: {} \n\t---------> 请求参数: {}", message, url, request);
|
|
InsuranceLog.infoLog(logId, "\n\t---------> {} \n\t---------> URL: {} \n\t---------> 请求参数: {}", message, url, request);
|
|
|
-
|
|
|
|
|
- HttpEntity<String> yaQuoteInfoVoHttpEntity = new HttpEntity<>(request, httpHeaders);
|
|
|
|
|
- ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(url, yaQuoteInfoVoHttpEntity, String.class);
|
|
|
|
|
- String body = stringResponseEntity.getBody();
|
|
|
|
|
|
|
+ ResponseEntity<B> stringResponseEntity = restTemplate.postForEntity(url, yaQuoteInfoVoHttpEntity, responseType);
|
|
|
|
|
+ B body = stringResponseEntity.getBody();
|
|
|
if (body == null) {
|
|
if (body == null) {
|
|
|
throw new SystemException(message + "接口请求失败");
|
|
throw new SystemException(message + "接口请求失败");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- InsuranceLog.infoLog(logId, "\n\t---------> {} \n\t---------> 响应参数:{}", message, body);
|
|
|
|
|
- return JSON.parseObject(body, responseType);
|
|
|
|
|
|
|
+ String response = JSON.toJSONString(body);
|
|
|
|
|
+ InsuranceLog.infoLog(logId, "\n\t---------> {} \n\t---------> 响应参数:{}", message, response);
|
|
|
|
|
+ return body;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public <B> B request(String url, String companyId, String apiType, Object requestBody, Class<B> responseType) {
|
|
|
|
|
|
|
+ public <T, B> B request(String url, String companyId, String apiType, T requestBody, Class<B> responseType) {
|
|
|
// 获取保险公司枚举
|
|
// 获取保险公司枚举
|
|
|
String substring = companyId.substring(0, 4);
|
|
String substring = companyId.substring(0, 4);
|
|
|
InsuranceEnum insuranceEnum = Enum.valueOf(InsuranceEnum.class, substring);
|
|
InsuranceEnum insuranceEnum = Enum.valueOf(InsuranceEnum.class, substring);
|
|
|
return this.request(url, insuranceEnum, apiType, requestBody, responseType, new HttpHeaders());
|
|
return this.request(url, insuranceEnum, apiType, requestBody, responseType, new HttpHeaders());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public <B> B request(String url, InsuranceEnum insuranceEnum, String apiType, Object requestBody, Class<B> responseType) {
|
|
|
|
|
|
|
+ public <T, B> B request(String url, InsuranceEnum insuranceEnum, String apiType, T requestBody, Class<B> responseType) {
|
|
|
return this.request(url, insuranceEnum, apiType, requestBody, responseType, new HttpHeaders());
|
|
return this.request(url, insuranceEnum, apiType, requestBody, responseType, new HttpHeaders());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public <B> B request(String url, InsuranceEnum insuranceEnum, String apiType, Object requestBody, Class<B> responseType, HttpHeaders httpHeaders) {
|
|
|
|
|
|
|
+ public <T, B> B request(String url, InsuranceEnum insuranceEnum, String apiType, T requestBody, Class<B> responseType, HttpHeaders httpHeaders) {
|
|
|
String message = insuranceEnum.getName() + apiType;
|
|
String message = insuranceEnum.getName() + apiType;
|
|
|
return this.post(url, insuranceEnum.getPinyin(), message, requestBody, responseType, httpHeaders);
|
|
return this.post(url, insuranceEnum.getPinyin(), message, requestBody, responseType, httpHeaders);
|
|
|
}
|
|
}
|