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 B post(String url, String message, @Nullable T requestBody, Class responseType) { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); HttpEntity yaQuoteInfoVoHttpEntity = new HttpEntity<>(requestBody, httpHeaders); String request = JSON.toJSONString(requestBody); log.info("---------> 请求参数:{}", request); ResponseEntity 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 B quote(T t, Class responseType) { return post(rbQuoteUrl, "人保报价", t, responseType); } public B audit(T t, Class responseType) { return post(rbAuditUrl, "人保核保", t, responseType); } public B licensePlateQuery(T t, Class responseType) { return post(rbCarSearchUrl, "人保车牌号查询车辆信息", t, responseType); } public B modelsQuery(T t, Class responseType) { return post(rbBrandSearchUrl, "人保车辆查询", t, responseType); } }