| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package com.ydtech.components;
- import com.alibaba.fastjson.JSON;
- import com.ydtech.aop.request.MethodLogAnnotation;
- import com.ydtech.exception.SystemException;
- import com.ydtech.modules.ins.model.request.Response;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.core.ParameterizedTypeReference;
- import org.springframework.http.HttpEntity;
- import org.springframework.http.HttpHeaders;
- import org.springframework.http.MediaType;
- import org.springframework.http.ResponseEntity;
- import org.springframework.lang.Nullable;
- import org.springframework.stereotype.Component;
- import org.springframework.web.client.RestTemplate;
- @Slf4j
- @Component
- public class RenbaoRequestComponents {
- @Autowired
- private RestTemplate restTemplate;
- @Value("${rb.quote.url}")
- private String rbQuoteUrl;
- @Value("${rb.audit.url}")
- private String rbAuditUrl;
- @Value("${rb.car.search.url}")
- private String rbCarSearchUrl;
- @Value("${rb.brand.search.url}")
- private String rbBrandSearchUrl;
- // @MethodLogAnnotation(title = "报价-请求python")
- public <T, B> B post(String url, String message, @Nullable T requestBody, Class<B> responseType) {
- HttpHeaders httpHeaders = new HttpHeaders();
- httpHeaders.setContentType(MediaType.APPLICATION_JSON);
- HttpEntity<T> yaQuoteInfoVoHttpEntity = new HttpEntity<>(requestBody, httpHeaders);
- String request = JSON.toJSONString(requestBody);
- log.info("---------> 请求参数:{}", request);
- ResponseEntity<B> stringResponseEntity = restTemplate.postForEntity(url, yaQuoteInfoVoHttpEntity, responseType);
- B body = stringResponseEntity.getBody();
- if (body == null) {
- throw new SystemException(message + "接口请求失败");
- }
- String response = JSON.toJSONString(body);
- log.info("---------> 请求参数:{}", response);
- return body;
- }
- public <T, B> B quote(T t, Class<B> responseType) {
- return post(rbQuoteUrl, "人保报价", t, responseType);
- }
- public <T, B> B audit(T t, Class<B> responseType) {
- return post(rbAuditUrl, "人保核保", t, responseType);
- }
- public <T, B> B licensePlateQuery(T t, Class<B> responseType) {
- return post(rbCarSearchUrl, "人保车牌号查询车辆信息", t, responseType);
- }
- public <T, B> B modelsQuery(T t, Class<B> responseType) {
- return post(rbBrandSearchUrl, "人保车辆查询", t, responseType);
- }
- }
|