package com.ydtech.components; 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.*; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; @Slf4j @Component public class ZhongmeiRequestComponents { @Autowired private RestTemplate restTemplate; @Value("${zm.quote.url}") private String zmQuoteUrl; @Value("${zm.audit.url}") private String zmAuditUrl; @Value("${zm.getPolicyPrint.url}") private String zmGetPolicyPrintUrl; @Value("${zm.image.url}") private String zmImageUrl; @Value("${zm.verifyPayment.url}") private String zmVerifyPaymentUrl; @Value("${zm.modelQuery.url}") private String zmModelQueryUrl; @Value("${zm.vinSearch.url}") private String zmVinSearchUrl; @Value("${zm.ascription.url}") private String zmAscriptionUrl; @Value("${zm.manualUnderwriting.url}") private String zmManualUnderwritingUrl; public Response post(K k, String url, ParameterizedTypeReference> responseType) { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); HttpEntity yaQuoteInfoVoHttpEntity = new HttpEntity<>(k, httpHeaders); ResponseEntity> stringResponseEntity = restTemplate.exchange(url, HttpMethod.POST, yaQuoteInfoVoHttpEntity, responseType); Response body = stringResponseEntity.getBody(); if (body == null) { throw new SystemException("中煤接口请求失败"); } if (body.getCode() == 400) { throw new SystemException(body.getMessage()); } return body; } public Response modelQuery(K k, ParameterizedTypeReference> responseType) { return post(k, zmModelQueryUrl, responseType); } // @MethodLogAnnotation(title = "中煤-报价-请求python") public Response quote(K k, ParameterizedTypeReference> responseType) { return post(k, zmQuoteUrl, responseType); } // @MethodLogAnnotation(title = "中煤-核保-请求python") public Response audit(K k, ParameterizedTypeReference> responseType) { return post(k, zmAuditUrl, responseType); } public void submitImage(K k, ParameterizedTypeReference> responseType) { post(k, zmImageUrl, responseType); } public Response zmGetPolicyPrint(K k, ParameterizedTypeReference> responseType) { return post(k, zmGetPolicyPrintUrl, responseType); } public Response verifyPayment(K k, ParameterizedTypeReference> responseType) { return post(k, zmVerifyPaymentUrl, responseType); } public Response vinSearch(K k, ParameterizedTypeReference> responseType) { return post(k, zmVinSearchUrl, responseType); } public Response ascription(K k, ParameterizedTypeReference> responseType) { return post(k, zmAscriptionUrl, responseType); } public Response manualUnderwriting(K k, ParameterizedTypeReference> responseType) { return post(k, zmManualUnderwritingUrl, responseType); } }