ZhongmeiRequestComponents.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package com.ydtech.components;
  2. import com.ydtech.exception.SystemException;
  3. import com.ydtech.modules.ins.model.request.Response;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.beans.factory.annotation.Value;
  7. import org.springframework.core.ParameterizedTypeReference;
  8. import org.springframework.http.*;
  9. import org.springframework.stereotype.Component;
  10. import org.springframework.web.client.RestTemplate;
  11. @Slf4j
  12. @Component
  13. public class ZhongmeiRequestComponents {
  14. @Autowired
  15. private RestTemplate restTemplate;
  16. @Value("${zm.quote.url}")
  17. private String zmQuoteUrl;
  18. @Value("${zm.audit.url}")
  19. private String zmAuditUrl;
  20. @Value("${zm.getPolicyPrint.url}")
  21. private String zmGetPolicyPrintUrl;
  22. @Value("${zm.image.url}")
  23. private String zmImageUrl;
  24. @Value("${zm.verifyPayment.url}")
  25. private String zmVerifyPaymentUrl;
  26. @Value("${zm.modelQuery.url}")
  27. private String zmModelQueryUrl;
  28. @Value("${zm.vinSearch.url}")
  29. private String zmVinSearchUrl;
  30. @Value("${zm.ascription.url}")
  31. private String zmAscriptionUrl;
  32. @Value("${zm.manualUnderwriting.url}")
  33. private String zmManualUnderwritingUrl;
  34. public <T, K> Response<T> post(K k, String url, ParameterizedTypeReference<Response<T>> responseType) {
  35. HttpHeaders httpHeaders = new HttpHeaders();
  36. httpHeaders.setContentType(MediaType.APPLICATION_JSON);
  37. HttpEntity<K> yaQuoteInfoVoHttpEntity = new HttpEntity<>(k, httpHeaders);
  38. ResponseEntity<Response<T>> stringResponseEntity = restTemplate.exchange(url, HttpMethod.POST, yaQuoteInfoVoHttpEntity, responseType);
  39. Response<T> body = stringResponseEntity.getBody();
  40. if (body == null) {
  41. throw new SystemException("中煤接口请求失败");
  42. }
  43. if (body.getCode() == 400) {
  44. throw new SystemException(body.getMessage());
  45. }
  46. return body;
  47. }
  48. public <T, K> Response<T> modelQuery(K k, ParameterizedTypeReference<Response<T>> responseType) {
  49. return post(k, zmModelQueryUrl, responseType);
  50. }
  51. // @MethodLogAnnotation(title = "中煤-报价-请求python")
  52. public <T, K> Response<T> quote(K k, ParameterizedTypeReference<Response<T>> responseType) {
  53. return post(k, zmQuoteUrl, responseType);
  54. }
  55. // @MethodLogAnnotation(title = "中煤-核保-请求python")
  56. public <T, K> Response<T> audit(K k, ParameterizedTypeReference<Response<T>> responseType) {
  57. return post(k, zmAuditUrl, responseType);
  58. }
  59. public <T, K> void submitImage(K k, ParameterizedTypeReference<Response<T>> responseType) {
  60. post(k, zmImageUrl, responseType);
  61. }
  62. public <T, K> Response<T> zmGetPolicyPrint(K k, ParameterizedTypeReference<Response<T>> responseType) {
  63. return post(k, zmGetPolicyPrintUrl, responseType);
  64. }
  65. public <T, K> Response<T> verifyPayment(K k, ParameterizedTypeReference<Response<T>> responseType) {
  66. return post(k, zmVerifyPaymentUrl, responseType);
  67. }
  68. public <T, K> Response<T> vinSearch(K k, ParameterizedTypeReference<Response<T>> responseType) {
  69. return post(k, zmVinSearchUrl, responseType);
  70. }
  71. public <T, K> Response<T> ascription(K k, ParameterizedTypeReference<Response<T>> responseType) {
  72. return post(k, zmAscriptionUrl, responseType);
  73. }
  74. public <T, K> Response<T> manualUnderwriting(K k, ParameterizedTypeReference<Response<T>> responseType) {
  75. return post(k, zmManualUnderwritingUrl, responseType);
  76. }
  77. }