| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- 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 <T, K> Response<T> post(K k, String url, ParameterizedTypeReference<Response<T>> responseType) {
- HttpHeaders httpHeaders = new HttpHeaders();
- httpHeaders.setContentType(MediaType.APPLICATION_JSON);
- HttpEntity<K> yaQuoteInfoVoHttpEntity = new HttpEntity<>(k, httpHeaders);
- ResponseEntity<Response<T>> stringResponseEntity = restTemplate.exchange(url, HttpMethod.POST, yaQuoteInfoVoHttpEntity, responseType);
- Response<T> body = stringResponseEntity.getBody();
- if (body == null) {
- throw new SystemException("中煤接口请求失败");
- }
- if (body.getCode() == 400) {
- throw new SystemException(body.getMessage());
- }
- return body;
- }
- public <T, K> Response<T> modelQuery(K k, ParameterizedTypeReference<Response<T>> responseType) {
- return post(k, zmModelQueryUrl, responseType);
- }
- // @MethodLogAnnotation(title = "中煤-报价-请求python")
- public <T, K> Response<T> quote(K k, ParameterizedTypeReference<Response<T>> responseType) {
- return post(k, zmQuoteUrl, responseType);
- }
- // @MethodLogAnnotation(title = "中煤-核保-请求python")
- public <T, K> Response<T> audit(K k, ParameterizedTypeReference<Response<T>> responseType) {
- return post(k, zmAuditUrl, responseType);
- }
- public <T, K> void submitImage(K k, ParameterizedTypeReference<Response<T>> responseType) {
- post(k, zmImageUrl, responseType);
- }
- public <T, K> Response<T> zmGetPolicyPrint(K k, ParameterizedTypeReference<Response<T>> responseType) {
- return post(k, zmGetPolicyPrintUrl, responseType);
- }
- public <T, K> Response<T> verifyPayment(K k, ParameterizedTypeReference<Response<T>> responseType) {
- return post(k, zmVerifyPaymentUrl, responseType);
- }
- public <T, K> Response<T> vinSearch(K k, ParameterizedTypeReference<Response<T>> responseType) {
- return post(k, zmVinSearchUrl, responseType);
- }
- public <T, K> Response<T> ascription(K k, ParameterizedTypeReference<Response<T>> responseType) {
- return post(k, zmAscriptionUrl, responseType);
- }
- public <T, K> Response<T> manualUnderwriting(K k, ParameterizedTypeReference<Response<T>> responseType) {
- return post(k, zmManualUnderwritingUrl, responseType);
- }
- }
|