Kaynağa Gözat

太平财险 + 图像识别

wks 1 yıl önce
ebeveyn
işleme
df6a1066d3

+ 1 - 0
tenant/insurance/pom.xml

@@ -18,6 +18,7 @@
         <module>quotation-zhongmei</module>
         <module>quotation-zijin</module>
         <module>quotation-bohai</module>
+        <module>quotation-taiping</module>
     </modules>
 
     <dependencies>

+ 35 - 12
tenant/insurance/quotation-commons/src/main/java/com/jzg/quotation/commons/component/RequestComponent.java

@@ -31,7 +31,7 @@ public class RequestComponent {
 
     /**
      * -- GETTER --
-     *  获取webClient
+     * 获取webClient
      *
      * @return webClient
      */
@@ -61,8 +61,7 @@ public class RequestComponent {
      * @return 响应返回值
      */
     private <Response> Response bodyIsEmpty(ResponseEntity<Response> responseEntity, String description) {
-        return Optional
-                .ofNullable(responseEntity)
+        return Optional.ofNullable(responseEntity)
                 .map(ResponseEntity::getBody)
                 .orElseThrow(() -> new SystemException(description + "请求异常"));
     }
@@ -79,8 +78,7 @@ public class RequestComponent {
      * @return 响应
      */
     public <Response> Response get(String url, Map<String, Object> param, String description, Class<Response> responseClass, HttpHeaders headers) {
-        ResponseEntity<Response> responseEntity = webClient
-                .get()
+        ResponseEntity<Response> responseEntity = webClient.get()
                 .uri(url, param)
                 .headers(setHeaders(headers))
                 .retrieve()
@@ -89,9 +87,17 @@ public class RequestComponent {
         return bodyIsEmpty(responseEntity, description);
     }
 
+    /**
+     * @param url               请求地址
+     * @param param             get 拼接对象
+     * @param description       描述信息
+     * @param bodyTypeReference 响应类 泛型
+     * @param headers           请求头
+     * @param <Response>        响应实体
+     * @return 响应
+     */
     public <Response> Response get(String url, Map<String, Object> param, String description, ParameterizedTypeReference<Response> bodyTypeReference, HttpHeaders headers) {
-        ResponseEntity<Response> responseEntity = webClient
-                .get()
+        ResponseEntity<Response> responseEntity = webClient.get()
                 .uri(url, param)
                 .headers(setHeaders(headers))
                 .retrieve()
@@ -120,11 +126,8 @@ public class RequestComponent {
      * @return 响应
      */
     public <Response> ResponseEntity<Response> post(String url, String body, Class<Response> responseClass, HttpHeaders headers) {
-        body = Optional
-                .ofNullable(body)
-                .orElse("");
-        return webClient
-                .post()
+        body = Optional.ofNullable(body).orElse("");
+        return webClient.post()
                 .uri(url)
                 .headers(setHeaders(headers))
                 .body(BodyInserters.fromValue(body))
@@ -133,6 +136,26 @@ public class RequestComponent {
                 .block();
     }
 
+    /**
+     * @param url               请求地址
+     * @param body              请求体
+     * @param bodyTypeReference 泛型响应类
+     * @param headers           请求头
+     * @param <Response>        响应实体
+     * @return 响应
+     */
+    public <Response> Response post(String url, Object body, String description, ParameterizedTypeReference<Response> bodyTypeReference, HttpHeaders headers) {
+        String requestBody = JSON.toJSONString(body);
+        ResponseEntity<Response> responseEntity = webClient.post()
+                .uri(url)
+                .body(BodyInserters.fromValue(requestBody))
+                .headers(setHeaders(headers))
+                .retrieve()
+                .toEntity(bodyTypeReference)
+                .block();
+        return bodyIsEmpty(responseEntity, description);
+    }
+
     /**
      * @param url           请求地址
      * @param body          请求体

+ 2 - 4
tenant/insurance/quotation-commons/src/main/java/com/jzg/quotation/commons/constant/enums/base/ExpenseRequestUrl.java

@@ -13,10 +13,8 @@ import lombok.Getter;
 @AllArgsConstructor
 public enum ExpenseRequestUrl {
 
-    CAPTCHA_IDENTIFY("", "验证码识别"),
-    REINSURANCE_CAPTCHA_IDENTIFY("", "转保验证码识别"),
-    VIN_IDENTIFY("", "车架号识别"),
-    BRAND_MODEL_IDENTIFY("", "品牌型号识别"),
+    CAPTCHA_IDENTIFY("/identify/captcha", "验证码识别"),
+    REINSURANCE_CAPTCHA_IDENTIFY("/reinsurance/captcha", "转保验证码识别"),
     ;
 
     private final String uri;

+ 18 - 0
tenant/insurance/quotation-commons/src/main/java/com/jzg/quotation/commons/entity/vo/base/R.java

@@ -0,0 +1,18 @@
+package com.jzg.quotation.commons.entity.vo.base;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class R<T> {
+
+    private int code;
+
+    private String message;
+
+    private T data;
+
+}

+ 19 - 0
tenant/insurance/quotation-commons/src/main/java/com/jzg/quotation/commons/entity/vo/identify/ReinsuranceCaptchaVo.java

@@ -0,0 +1,19 @@
+package com.jzg.quotation.commons.entity.vo.identify;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class ReinsuranceCaptchaVo {
+    /**
+     * 交强险转保验证码
+     */
+    private String ciCaptcha;
+    /**
+     * 商业险转保验证码
+     */
+    private String biCaptcha;
+}

+ 1 - 1
tenant/insurance/quotation-commons/src/main/java/com/jzg/quotation/commons/properties/CaptchaRecognitionProperties.java

@@ -18,6 +18,6 @@ public class CaptchaRecognitionProperties {
     /**
      * 识别url
      */
-    private String recognitionUrl;
+    private String url;
 
 }

+ 4 - 16
tenant/insurance/quotation-commons/src/main/java/com/jzg/quotation/commons/service/ExteriorUtilsRequest.java

@@ -1,6 +1,8 @@
 package com.jzg.quotation.commons.service;
 
 
+import com.jzg.quotation.commons.entity.vo.identify.ReinsuranceCaptchaVo;
+
 /**
  * @description: 外部工具请求 用于封装一些公用的请求地址
  * @author: wenks
@@ -22,21 +24,7 @@ public interface ExteriorUtilsRequest {
      * @param base64String
      * @return 转保验证码结果
      */
-    String reinsuranceCaptchaIdentify(String base64String);
-
-    /**
-     * 车架号识别
-     *
-     * @param vin 车架号识别
-     * @return 车辆信息列表
-     */
-    String vinIdentify(String vin);
+    ReinsuranceCaptchaVo reinsuranceCaptchaIdentify(ReinsuranceCaptchaVo reinsuranceCaptchaVo);
 
-    /**
-     * 品牌型号识别
-     *
-     * @param brandModel 品牌型号识别
-     * @return 车辆信息列表
-     */
-    String brandModelIdentify(String brandModel);
 }
+

+ 13 - 19
tenant/insurance/quotation-commons/src/main/java/com/jzg/quotation/commons/service/impl/ExteriorUtilsRequestImpl.java

@@ -2,9 +2,13 @@ package com.jzg.quotation.commons.service.impl;
 
 import com.jzg.quotation.commons.component.RequestComponent;
 import com.jzg.quotation.commons.constant.enums.base.ExpenseRequestUrl;
+import com.jzg.quotation.commons.entity.vo.base.R;
+import com.jzg.quotation.commons.entity.vo.identify.ReinsuranceCaptchaVo;
 import com.jzg.quotation.commons.properties.CaptchaRecognitionProperties;
 import com.jzg.quotation.commons.service.ExteriorUtilsRequest;
 import lombok.RequiredArgsConstructor;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpHeaders;
 import org.springframework.stereotype.Service;
 
 import java.util.Map;
@@ -31,29 +35,19 @@ public class ExteriorUtilsRequestImpl implements ExteriorUtilsRequest {
     public String captchaIdentify(String base64String) {
         base64String = prefixToRemove(base64String);
         ExpenseRequestUrl captcha = ExpenseRequestUrl.CAPTCHA_IDENTIFY;
-        String url = ExpenseRequestUrl.getUrl(captchaRecognitionProperties.getRecognitionUrl(), captcha.getUri());
-        return requestComponent.objectPost(url, Map.of("", base64String), captcha.getDescription(), String.class);
+        String url = ExpenseRequestUrl.getUrl(captchaRecognitionProperties.getUrl(), captcha.getUri());
+        R<String> response = requestComponent.post(url, Map.of("captcha", base64String), captcha.getDescription(), new ParameterizedTypeReference<>() {
+        }, new HttpHeaders());
+        return response.getData();
     }
 
     @Override
-    public String reinsuranceCaptchaIdentify(String base64String) {
+    public ReinsuranceCaptchaVo reinsuranceCaptchaIdentify(ReinsuranceCaptchaVo reinsuranceCaptchaVo) {
         ExpenseRequestUrl captcha = ExpenseRequestUrl.REINSURANCE_CAPTCHA_IDENTIFY;
-        String url = ExpenseRequestUrl.getUrl(captchaRecognitionProperties.getRecognitionUrl(), captcha.getUri());
-        return requestComponent.objectPost(url, Map.of(), captcha.getDescription(), String.class);
-    }
-
-    @Override
-    public String vinIdentify(String base64String) {
-        ExpenseRequestUrl captcha = ExpenseRequestUrl.VIN_IDENTIFY;
-        String url = ExpenseRequestUrl.getUrl(captchaRecognitionProperties.getRecognitionUrl(), captcha.getUri());
-        return requestComponent.objectPost(url, Map.of(), captcha.getDescription(), String.class);
-    }
-
-    @Override
-    public String brandModelIdentify(String base64String) {
-        ExpenseRequestUrl captcha = ExpenseRequestUrl.BRAND_MODEL_IDENTIFY;
-        String url = ExpenseRequestUrl.getUrl(captchaRecognitionProperties.getRecognitionUrl(), captcha.getUri());
-        return requestComponent.objectPost(url, Map.of(), captcha.getDescription(), String.class);
+        String url = ExpenseRequestUrl.getUrl(captchaRecognitionProperties.getUrl(), captcha.getUri());
+        R<ReinsuranceCaptchaVo> response = requestComponent.post(url, reinsuranceCaptchaVo, captcha.getDescription(), new ParameterizedTypeReference<>() {
+        }, new HttpHeaders());
+        return response.getData();
     }
 
 }

+ 6 - 9
tenant/insurance/quotation-dajia/src/main/java/com/jzg/quotation/dajia/crawler/utils/DESEncryption.java

@@ -24,12 +24,9 @@ public final class DESEncryption {
 
     private static final String SIGN = "DJCX";
 
-    /**
-     * 加密key的过程
-     *
-     * @return DES
-     */
-    private static DES des() {
+    public static final DES DES;
+
+    static {
         LocalDate localDate = LocalDate.now();
         int dayOfMonth = localDate.getDayOfMonth();
         int month = localDate.getMonthValue() - 2;
@@ -38,7 +35,7 @@ public final class DESEncryption {
                 .format(DateTimeFormatter.ofPattern("yyyyMMdd"));
         String key = now + SIGN;
         String encode = Base64.encode(key);
-        return new DES(Mode.ECB, Padding.PKCS5Padding, encode.getBytes());
+        DES = new DES(Mode.ECB, Padding.PKCS5Padding, encode.getBytes());
     }
 
     /**
@@ -48,7 +45,7 @@ public final class DESEncryption {
      * @return 加密参数
      */
     public static String encrypt(String data) {
-        return des().encryptHex(data);
+        return DES.encryptHex(data);
     }
 
     /**
@@ -59,7 +56,7 @@ public final class DESEncryption {
      */
     public static String decrypt(String data) {
         byte[] bytes = HexUtils.fromHexString(data);
-        return des().decryptStr(bytes);
+        return DES.decryptStr(bytes);
     }
 
     /**

+ 1 - 0
tenant/insurance/quotation-summary/src/main/resources/application.yaml

@@ -21,6 +21,7 @@ spring:
       - nacos:redisson
       - nacos:minio
       - nacos:mongodb
+      - nacos:identify
 
 mybatis-plus:
   mapper-locations: classpath*:/mapper/*Mapper.xml

+ 29 - 0
tenant/insurance/quotation-taiping/pom.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.jzg</groupId>
+        <artifactId>insurance</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>quotation-taiping</artifactId>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.jzg</groupId>
+            <artifactId>quotation-commons</artifactId>
+            <version>1.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+
+</project>

+ 13 - 0
tenant/insurance/quotation-taiping/src/main/java/com/jzg/quotation/taiping/crawler/component/TaiPingCrawlerRequestComponent.java

@@ -0,0 +1,13 @@
+package com.jzg.quotation.taiping.crawler.component;
+
+import com.jzg.quotation.commons.component.RequestComponent;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+@Component
+@RequiredArgsConstructor
+public class TaiPingCrawlerRequestComponent {
+
+    private final RequestComponent requestComponent;
+
+}

+ 57 - 0
tenant/insurance/quotation-taiping/src/main/java/com/jzg/quotation/taiping/crawler/utils/AESEncryption.java

@@ -0,0 +1,57 @@
+package com.jzg.quotation.taiping.crawler.utils;
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.symmetric.AES;
+import com.alibaba.fastjson2.JSON;
+
+public final class AESEncryption {
+
+    private AESEncryption()  {
+        throw new IllegalStateException("Utility class");
+    }
+
+    private final static String KEY = "Fe09wKJJycMKqOKB";
+
+    private final static AES AES;
+
+    static {
+        AES = SecureUtil.aes(KEY.getBytes());
+    }
+
+    /**
+     * 加密
+     *
+     * @param data 需要加密的报文
+     * @return 加密参数
+     */
+    public static String encrypt(String data) {
+        byte[] decryptedBytes = AES.decrypt(data);
+        return new String(decryptedBytes);
+    }
+
+    /**
+     * 解密
+     *
+     * @param data 加密参数
+     * @return 加密后的参数
+     */
+    public static String decrypt(String data) {
+        byte[] encryptedBytes = AES.encrypt(data);
+        return Base64.encode(encryptedBytes);
+    }
+
+    /**
+     * 解密并且转码
+     *
+     * @param data   加密参数
+     * @param tClass json转换后的类型
+     * @param <T>    json转换后的泛型
+     * @return 解密后的类
+     */
+    public static <T> T decrypt(String data, Class<T> tClass) {
+        String decrypt = decrypt(data);
+        return JSON.parseObject(decrypt, tClass);
+    }
+
+}