|
@@ -0,0 +1,289 @@
|
|
|
|
|
+package com.jzg.quotation.guoren.api.component;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+import com.jzg.commons.exception.SystemException;
|
|
|
|
|
+import com.jzg.quotation.guoren.api.entity.Request.PremiumRequest;
|
|
|
|
|
+import com.jzg.quotation.guoren.api.entity.Response.PremiumResponse;
|
|
|
|
|
+import lombok.Data;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @description: 国任财险重复投保
|
|
|
|
|
+ * @author: wenks
|
|
|
|
|
+ * @date: 2023/11/8 10:40
|
|
|
|
|
+ **/
|
|
|
|
|
+public class GuorenDuplicateInsuranceComponent {
|
|
|
|
|
+
|
|
|
|
|
+ public static final String THE_FIRST_REGEX = "终保日期(.+?);";
|
|
|
|
|
+
|
|
|
|
|
+ public static final String THE_SECOND_REGEX = ".+终保日期(.+?);";
|
|
|
|
|
+
|
|
|
|
|
+ public static final String JQ = "交强险";
|
|
|
|
|
+
|
|
|
|
|
+ public static final String SY = "商业险";
|
|
|
|
|
+
|
|
|
|
|
+ protected static final Map<Integer, String> dateFormatMap;
|
|
|
|
|
+
|
|
|
|
|
+ private GuorenDuplicateInsuranceComponent() {
|
|
|
|
|
+ throw new IllegalStateException("工具方法");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ static {
|
|
|
|
|
+ dateFormatMap = new HashMap<>();
|
|
|
|
|
+ dateFormatMap.put(8, "yyyyMMdd");
|
|
|
|
|
+ dateFormatMap.put(10, "yyyyMMddHH");
|
|
|
|
|
+ dateFormatMap.put(12, "yyyyMMddHHmm");
|
|
|
|
|
+ dateFormatMap.put(14, "yyyyMMddHHmmss");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取终保日期
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param rtnMsg 返回信息
|
|
|
|
|
+ * @param regex 正则
|
|
|
|
|
+ * @return 终保日期
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getEndDate(String rtnMsg, String regex) {
|
|
|
|
|
+ String endDate = getTheExpiryDate(rtnMsg, regex);
|
|
|
|
|
+ if (!endDate.isEmpty()) {
|
|
|
|
|
+ return endDate;
|
|
|
|
|
+ }
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static String getTimelyEndDate(String rtnMsg, String regex) {
|
|
|
|
|
+ String endDate = getTimelyTheExpiryDate(rtnMsg, regex);
|
|
|
|
|
+ if (!endDate.isEmpty()) {
|
|
|
|
|
+ return endDate;
|
|
|
|
|
+ }
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取终保日期
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param message 重复投保返回信息
|
|
|
|
|
+ * @param regex 正则内容
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getTheExpiryDate(String message, String regex) {
|
|
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
|
|
+ String replace = message.replace("\r", ";").replace("\n", ";").replace(" ", "");
|
|
|
|
|
+ Matcher m = pattern.matcher(replace);
|
|
|
|
|
+
|
|
|
|
|
+ boolean b = m.find();
|
|
|
|
|
+ if (b) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String group = m.group(1);
|
|
|
|
|
+ String startDate = group.replace(":", "").replace(":", "").replace("-", "").replace(" ", "");
|
|
|
|
|
+ String string = dateFormatMap.get(startDate.length());
|
|
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat(string);
|
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ Date parse = dateFormat.parse(startDate);
|
|
|
|
|
+
|
|
|
|
|
+ return simpleDateFormat.format(parse);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new SystemException(message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public static String getTimelyTheExpiryDate(String message, String regex) {
|
|
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
|
|
+ String replace = message.replace("\r", ";").replace("\n", ";").replace(" ", "");
|
|
|
|
|
+ Matcher m = pattern.matcher(replace);
|
|
|
|
|
+
|
|
|
|
|
+ boolean b = m.find();
|
|
|
|
|
+ if (b) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String startDate = "";
|
|
|
|
|
+ String group = m.group(2);
|
|
|
|
|
+ String groupRegex = "终保日期(\\d{4}-\\d{2}-\\d{2})";
|
|
|
|
|
+ Pattern groupPattern = Pattern.compile(groupRegex);
|
|
|
|
|
+ Matcher groupMatcher = groupPattern.matcher(group);
|
|
|
|
|
+ if(groupMatcher.find()) {
|
|
|
|
|
+ startDate = groupMatcher.group(1);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ String string = "yyyy-MM-dd";
|
|
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat(string);
|
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ Date parse = dateFormat.parse(startDate);
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ calendar.setTime(parse);
|
|
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, 1); // 加一天
|
|
|
|
|
+ // 获取增加一天后的日期
|
|
|
|
|
+ Date newDate = calendar.getTime();
|
|
|
|
|
+ return simpleDateFormat.format(newDate);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new SystemException(message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 重复投保
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param resp 响应
|
|
|
|
|
+ * @param requestInfoList 返回重复信息
|
|
|
|
|
+ * @param req 重新构造请求
|
|
|
|
|
+ * @return 正确与否
|
|
|
|
|
+ */
|
|
|
|
|
+ public static boolean processor(PremiumResponse resp, List<String> requestInfoList, PremiumRequest req) {
|
|
|
|
|
+ String syEndDate = "";
|
|
|
|
|
+ PremiumResponse.DataDTO data = resp.getData();
|
|
|
|
|
+ if (ObjectUtils.isEmpty(data)) {
|
|
|
|
|
+ throw new SystemException("程序异常请联系管理员");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotEmpty(data.getBireCoverMsg()) && data.getBireCoverMsg().contains("重复投保")) {
|
|
|
|
|
+ requestInfoList.add(data.getBireCoverMsg());
|
|
|
|
|
+ syEndDate = getTheExpiryDate(data.getBireCoverMsg(), THE_FIRST_REGEX);
|
|
|
|
|
+ // 商业险
|
|
|
|
|
+ PremiumRequest.BiDTO bi = req.getBi();
|
|
|
|
|
+ bi.setBusinessTime(syEndDate);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String resultMsg = resp.getResultMsg();
|
|
|
|
|
+ //1. 交强重复投保 替换日期重新报价
|
|
|
|
|
+ if (StringUtils.isNotEmpty(resultMsg) && resultMsg.contains("重复投保")) {
|
|
|
|
|
+ requestInfoList.add(resultMsg);
|
|
|
|
|
+ String jqEndDate = getEndDate(resultMsg, THE_FIRST_REGEX);
|
|
|
|
|
+ if (resp.getResultMsg().contains(SY)) {
|
|
|
|
|
+ syEndDate = getEndDate(resultMsg, THE_SECOND_REGEX);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotEmpty(syEndDate)) {
|
|
|
|
|
+ // 商业险
|
|
|
|
|
+ PremiumRequest.BiDTO bi = req.getBi();
|
|
|
|
|
+ bi.setBusinessTime(syEndDate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotEmpty(jqEndDate)) {
|
|
|
|
|
+ // 交强
|
|
|
|
|
+ PremiumRequest.CiDTO ci = req.getCi();
|
|
|
|
|
+ ci.setTrafficTime(jqEndDate);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotEmpty(jqEndDate) || StringUtils.isNotEmpty(syEndDate)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 校验码有误
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param response 响应
|
|
|
|
|
+ * @return 正确与否
|
|
|
|
|
+ */
|
|
|
|
|
+ public static boolean theCheckCodeIsWrong(PremiumResponse response) {
|
|
|
|
|
+ if (response.getResultMsg().contains("校验码有误")) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 转保单
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param resp 响应
|
|
|
|
|
+ * @param requestInfoList 返回重复信息
|
|
|
|
|
+ * @param req 重新构造请求
|
|
|
|
|
+ * @return 正确与否
|
|
|
|
|
+ */
|
|
|
|
|
+ public static boolean buildCheckCodeParam(PremiumResponse resp, List<String> requestInfoList, PremiumRequest req) {
|
|
|
|
|
+ String ciCheckCode = resp.getData().getCicheckCode();
|
|
|
|
|
+ String biCheckCode = resp.getData().getBicheckCode();
|
|
|
|
|
+ if (StringUtils.isNotEmpty(ciCheckCode) || StringUtils.isNotEmpty(biCheckCode)) {
|
|
|
|
|
+ CheckCodeResp ccResp = gainCheckCode(ciCheckCode, biCheckCode);
|
|
|
|
|
+ req.getCi().getPrpTmain().setAnswer(ccResp.getJqImageCode());
|
|
|
|
|
+ req.getBi().getPrpTmain().setAnswer(ccResp.getSyImageCode());
|
|
|
|
|
+ requestInfoList.add("转保单");
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static String toString(Object object, String defaultValue) {
|
|
|
|
|
+ if (object == null) return defaultValue;
|
|
|
|
|
+ return String.valueOf(object);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static String toJson(Object value) {
|
|
|
|
|
+ Assert.notNull(value);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ return new ObjectMapper().writeValueAsString(value);
|
|
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
|
|
+ throw new RuntimeException(e.getMessage(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static String sendPost(String url,String bodyStr){
|
|
|
|
|
+ System.err.println("请求[post、json、body]参数:"+bodyStr);
|
|
|
|
|
+ HttpRequest request = HttpRequest.post(url)
|
|
|
|
|
+ .header("Content-Type", "application/json")//以json的方式传递
|
|
|
|
|
+// .header("authorization","Bearer abcdefghijklmnopqrstuvwxyz")
|
|
|
|
|
+ .body(bodyStr);
|
|
|
|
|
+
|
|
|
|
|
+ HttpResponse response = request.execute();
|
|
|
|
|
+ String respStr = response.body();
|
|
|
|
|
+ System.err.println("返回[post、json、body]参数:"+ respStr);
|
|
|
|
|
+
|
|
|
|
|
+ return respStr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取图片验证码 校验的code
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author: lig
|
|
|
|
|
+ * @date: 2023年10月13日 0013
|
|
|
|
|
+ */
|
|
|
|
|
+ private static CheckCodeResp gainCheckCode(String jqImageStr, String syImageStr) {
|
|
|
|
|
+ Map<String, String> bodyMap = new HashMap<>();
|
|
|
|
|
+ bodyMap.put("jqImage", toString(jqImageStr, ""));
|
|
|
|
|
+ bodyMap.put("syImage", toString(syImageStr, ""));
|
|
|
|
|
+ String sendBody = toJson(bodyMap);
|
|
|
|
|
+ String ocrStr = sendPost("http://39.98.41.104:8088/getres", sendBody);
|
|
|
|
|
+ return JSONUtil.toBean(ocrStr, CheckCodeResp.class);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Data
|
|
|
|
|
+ static class CheckCodeResp {
|
|
|
|
|
+
|
|
|
|
|
+ @JsonProperty(value = "jqImageCode")
|
|
|
|
|
+ String jqImageCode;
|
|
|
|
|
+
|
|
|
|
|
+ @JsonProperty(value = "syImageCode")
|
|
|
|
|
+ String syImageCode;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|