|
|
@@ -39,6 +39,7 @@ import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
@@ -130,11 +131,16 @@ public class ChengTaiApiRequestImpl implements ChengTaiApiRequest {
|
|
|
*/
|
|
|
private String extractEndDate(PremiumCalculationResponse response) {
|
|
|
String targetText = response.getHead().getErrorMessage();
|
|
|
- Pattern pattern = Pattern.compile("终保日期 (\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2})");
|
|
|
+ Pattern pattern = Pattern.compile("终保日期[:\\s]+(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}(?::\\d{2})?)");
|
|
|
Matcher matcher = pattern.matcher(targetText);
|
|
|
if (matcher.find()) {
|
|
|
String dateStr = matcher.group(1);
|
|
|
- return dateStr + ":00";
|
|
|
+ // 已经包含秒(以 :数字数字 结尾),不拼接
|
|
|
+ if (dateStr.length() == 16) {
|
|
|
+ return dateStr + ":00";
|
|
|
+ } else {
|
|
|
+ return dateStr;
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
@@ -146,82 +152,211 @@ public class ChengTaiApiRequestImpl implements ChengTaiApiRequest {
|
|
|
*/
|
|
|
private PremiumCalculationResponse getResponse(PremiumCalculationRequest premiumCalculationRequest, QuoteVo quoteVo,BigDecimal carActualValue,
|
|
|
ChengTaiApiParameters parameters, CarModelQueryResponse.vehicle vehicle, String apiUrl) throws Exception {
|
|
|
+ int index = 0;
|
|
|
+ PremiumCalculationResponse premiumCalculationResponse = new PremiumCalculationResponse();
|
|
|
+ String ciQuestion = null,biQuestion = null;
|
|
|
+ while(true) {
|
|
|
+ if(index >=5){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ premiumCalculationResponse = chengTaiRequestApiComponent.premiumCalculation(premiumCalculationRequest,apiUrl);
|
|
|
+ index++;
|
|
|
|
|
|
- PremiumCalculationResponse premiumCalculationResponse = chengTaiRequestApiComponent.premiumCalculation(premiumCalculationRequest,apiUrl);
|
|
|
- if (!premiumCalculationResponse.getHead().getErrorMessage().equals("成功")) {
|
|
|
- /**
|
|
|
- * 重复投保
|
|
|
- */
|
|
|
- // 获取新起保时间 终保时间
|
|
|
- final String startDate = extractEndDate(premiumCalculationResponse);
|
|
|
- String endDate;
|
|
|
- if (startDate != null){
|
|
|
- if (startDate.endsWith("00:00:00")) {
|
|
|
- endDate = TimeProcessing.minusOneSecondAfterYear(startDate);
|
|
|
- } else {
|
|
|
- endDate = TimeProcessing.plusOneYearToString(startDate);
|
|
|
- }
|
|
|
- final String formatStartDate = startDate;
|
|
|
- final String formatEndDate = endDate;
|
|
|
- PremiumCalculationResponse finalPremiumCalculationResponse = premiumCalculationResponse;
|
|
|
- if (quoteVo.getCiRiskInfoVo() != null && finalPremiumCalculationResponse.getHead().getErrorMessage().contains("交强")) {
|
|
|
- quoteVo.getCiRiskInfoVo().setStartDate(startDate);
|
|
|
- quoteVo.getCiRiskInfoVo().setEndDate(endDate);
|
|
|
+ // 如果返回出现问题
|
|
|
+ if (!premiumCalculationResponse.getHead().getResponseCode().equals("0000")){
|
|
|
+ // 是否是校验码有误
|
|
|
+ if(premiumCalculationResponse.getHead().getErrorMessage().contains("校验码有误")){
|
|
|
+ if(Objects.nonNull(ciQuestion)){
|
|
|
+ if(Objects.isNull(premiumCalculationResponse.getCompRisk())){
|
|
|
+ premiumCalculationResponse.setCompRisk(new PremiumCalculationResponse.compRisk());
|
|
|
+ }
|
|
|
+ if(Objects.isNull(premiumCalculationResponse.getCompRisk().getBasePart())){
|
|
|
+ premiumCalculationResponse.getCompRisk().setBasePart(new PremiumCalculationResponse.compRisk.basePart());
|
|
|
+ }
|
|
|
+ premiumCalculationResponse.getCompRisk().getBasePart().setQuestion(ciQuestion);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(Objects.nonNull(biQuestion)){
|
|
|
+ if(Objects.isNull(premiumCalculationResponse.getCommRisk())){
|
|
|
+ premiumCalculationResponse.setCommRisk(new PremiumCalculationResponse.commRisk());
|
|
|
+ }
|
|
|
+ if(Objects.isNull(premiumCalculationResponse.getCommRisk().getBasePart())){
|
|
|
+ premiumCalculationResponse.getCommRisk().setBasePart(new PremiumCalculationResponse.commRisk.basePart());
|
|
|
+ }
|
|
|
+ premiumCalculationResponse.getCommRisk().getBasePart().setQuestion(biQuestion);
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
- // 处理商业险的即时起保
|
|
|
- if (quoteVo.getBiRiskInfoVo() != null) {
|
|
|
- if (!formatStartDate.endsWith("00:00:00")) {
|
|
|
- String start, end = "";
|
|
|
- end = TimeProcessing.tomorrowDateTime(formatEndDate);
|
|
|
- quoteVo.getBiRiskInfoVo().setStartDate(formatStartDate);
|
|
|
- quoteVo.getBiRiskInfoVo().setEndDate(end);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!premiumCalculationResponse.getHead().getErrorMessage().equals("成功")) {
|
|
|
+ /**
|
|
|
+ * 重复投保
|
|
|
+ */
|
|
|
+ // 获取新起保时间 终保时间
|
|
|
+ //判断出现两次起保日期
|
|
|
+ boolean hasTwoStartDates = premiumCalculationResponse.getHead().getErrorMessage() != null
|
|
|
+ && premiumCalculationResponse.getHead().getErrorMessage().indexOf("起保日期") != -1 // 第一次出现
|
|
|
+ && premiumCalculationResponse.getHead().getErrorMessage().indexOf("起保日期",
|
|
|
+ premiumCalculationResponse.getHead().getErrorMessage().indexOf("起保日期") + 1) != -1; // 第二次出现
|
|
|
+
|
|
|
+ final String startDate = extractEndDate(premiumCalculationResponse);
|
|
|
+ String endDate;
|
|
|
+ if (startDate != null) {
|
|
|
+
|
|
|
+ //如果出现起保日期两次 就是 交强商业都重复投保了
|
|
|
+ if (hasTwoStartDates) {
|
|
|
+ String jqEndDate, syEndDate = "";
|
|
|
+ List<String> timeList = multipleStartDate(premiumCalculationResponse);
|
|
|
+ for (int i = 0; i < timeList.size(); i++) {
|
|
|
+ timeList.set(i, addOneYear(timeList.get(i)));
|
|
|
+ }
|
|
|
+ if (timeList.size() < 2) {
|
|
|
+ throw new SystemException("处理重复投保时间异常");
|
|
|
+ }
|
|
|
+ if (timeList.get(0).endsWith("00:00:00")) {
|
|
|
+ jqEndDate = TimeProcessing.minusOneSecondAfterYear(timeList.get(0));
|
|
|
+ } else {
|
|
|
+ jqEndDate = TimeProcessing.plusOneYearToString(timeList.get(0));
|
|
|
+ }
|
|
|
+ if (timeList.get(1).endsWith("00:00:00")) {
|
|
|
+ syEndDate = TimeProcessing.minusOneSecondAfterYear(timeList.get(1));
|
|
|
+ } else {
|
|
|
+ syEndDate = TimeProcessing.plusOneYearToString(timeList.get(1));
|
|
|
+ }
|
|
|
+ String jqFinalEndDate = jqEndDate;
|
|
|
+ String syFinalEndDate = syEndDate;
|
|
|
+ if (quoteVo.getCiRiskInfoVo() != null) {
|
|
|
+ quoteVo.getCiRiskInfoVo().setStartDate(timeList.get(0));
|
|
|
+ quoteVo.getCiRiskInfoVo().setEndDate(jqFinalEndDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理商业险的即时起保
|
|
|
+ if (quoteVo.getBiRiskInfoVo() != null) {
|
|
|
+ quoteVo.getBiRiskInfoVo().setStartDate(timeList.get(1));
|
|
|
+ quoteVo.getBiRiskInfoVo().setEndDate(syFinalEndDate);
|
|
|
+ }
|
|
|
} else {
|
|
|
- quoteVo.getBiRiskInfoVo().setStartDate(startDate);
|
|
|
- quoteVo.getBiRiskInfoVo().setEndDate(endDate);
|
|
|
+ if (startDate.endsWith("00:00:00")) {
|
|
|
+ endDate = TimeProcessing.minusOneSecondAfterYear(startDate);
|
|
|
+ } else {
|
|
|
+ endDate = TimeProcessing.plusOneYearToString(startDate);
|
|
|
+ }
|
|
|
+ final String formatStartDate = startDate;
|
|
|
+ final String formatEndDate = endDate;
|
|
|
+ PremiumCalculationResponse finalPremiumCalculationResponse = premiumCalculationResponse;
|
|
|
+
|
|
|
+ if (quoteVo.getCiRiskInfoVo() != null && finalPremiumCalculationResponse.getHead().getErrorMessage().contains("交强")) {
|
|
|
+ quoteVo.getCiRiskInfoVo().setStartDate(formatStartDate);
|
|
|
+ quoteVo.getCiRiskInfoVo().setEndDate(formatEndDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理商业险的即时起保
|
|
|
+ if (quoteVo.getBiRiskInfoVo() != null && finalPremiumCalculationResponse.getHead().getErrorMessage().contains("商业险")) {
|
|
|
+ quoteVo.getBiRiskInfoVo().setStartDate(formatStartDate);
|
|
|
+ quoteVo.getBiRiskInfoVo().setEndDate(formatEndDate);
|
|
|
+ }
|
|
|
}
|
|
|
+ premiumCalculationRequest = new PremiumCalculationRequest(quoteVo, carActualValue, parameters, vehicle, null);
|
|
|
+
|
|
|
+ } else if (premiumCalculationResponse.getHead().getErrorMessage().contains("重复投保")) {
|
|
|
+ throw new SystemException(premiumCalculationResponse.getHead().getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ // 转保车处理
|
|
|
+ ciQuestion = premiumCalculationResponse.getCompRisk() != null
|
|
|
+ ? premiumCalculationResponse.getCompRisk().getBasePart().getQuestion()
|
|
|
+ : null;
|
|
|
+ biQuestion = premiumCalculationResponse.getCommRisk() != null
|
|
|
+ ? premiumCalculationResponse.getCommRisk().getBasePart().getQuestion()
|
|
|
+ : null;
|
|
|
+ // 订单号
|
|
|
+ if (ciQuestion != null || biQuestion != null) {
|
|
|
+ String orderNumber = premiumCalculationResponse.getCompRisk() != null
|
|
|
+ ? premiumCalculationResponse.getCompRisk().getFtrno().getOrderNumber()
|
|
|
+ : premiumCalculationResponse.getCommRisk().getFtrno().getOrderNumber();
|
|
|
+ Map<String, String> bodyMap = new HashMap<>();
|
|
|
+ if (Objects.nonNull(ciQuestion)) {
|
|
|
+ bodyMap.put("jqImage", ciQuestion);
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(biQuestion)) {
|
|
|
+ bodyMap.put("syImage", biQuestion);
|
|
|
+ }
|
|
|
+ String sendBody = JSON.toJSONString(bodyMap);
|
|
|
+ if (!"{}".equals(sendBody)) {
|
|
|
+ String ocrStr = HttpUtil.sendPost("http://39.98.41.104:8088/getres", sendBody);
|
|
|
+ CheckCodeResp resp = JSONUtil.toBean(ocrStr, CheckCodeResp.class);
|
|
|
+ if(StringUtils.isNotEmpty(resp.getJqImageCode())){
|
|
|
+ quoteVo.setCiTransferCode(resp.getJqImageCode().replace("0", "O"));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(resp.getSyImageCode())){
|
|
|
+ quoteVo.setBiTransferCode(resp.getSyImageCode().replace("0", "O"));
|
|
|
+ }
|
|
|
+ premiumCalculationRequest = new PremiumCalculationRequest(quoteVo, carActualValue, parameters, vehicle, orderNumber);
|
|
|
+
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ break;
|
|
|
}
|
|
|
- premiumCalculationRequest = new PremiumCalculationRequest(quoteVo,carActualValue,parameters,vehicle,null);
|
|
|
- premiumCalculationResponse = chengTaiRequestApiComponent.premiumCalculation(premiumCalculationRequest, apiUrl);
|
|
|
- }
|
|
|
- }
|
|
|
- // 转保车处理
|
|
|
- String ciQuestion = null;
|
|
|
- String biQuestion = null;
|
|
|
- if (premiumCalculationResponse.getCompRisk() != null && premiumCalculationResponse.getCompRisk().getBasePart() != null){
|
|
|
- ciQuestion = premiumCalculationResponse.getCompRisk().getBasePart().getQuestion();
|
|
|
- }
|
|
|
- if (premiumCalculationResponse.getCommRisk() != null && premiumCalculationResponse.getCommRisk().getBasePart() != null){
|
|
|
- biQuestion = premiumCalculationResponse.getCommRisk().getBasePart().getQuestion();
|
|
|
- }
|
|
|
- // 订单号
|
|
|
- if (ciQuestion!= null || biQuestion != null) {
|
|
|
- String orderNumber = premiumCalculationResponse.getCompRisk() != null
|
|
|
- ? premiumCalculationResponse.getCompRisk().getFtrno().getOrderNumber()
|
|
|
- : premiumCalculationResponse.getCommRisk().getFtrno().getOrderNumber();
|
|
|
- Map<String, String> bodyMap = new HashMap<>();
|
|
|
- if (Objects.nonNull(ciQuestion)) {
|
|
|
- bodyMap.put("jqImage", ciQuestion);
|
|
|
}
|
|
|
- if (Objects.nonNull(biQuestion)) {
|
|
|
- bodyMap.put("syImage", biQuestion);
|
|
|
+ //处理订单号
|
|
|
+ if( premiumCalculationResponse.getCompRisk() != null && premiumCalculationResponse.getCompRisk().getFtrno() != null){
|
|
|
+ premiumCalculationRequest.getBasePart().setOrderNumber(premiumCalculationResponse.getCompRisk().getFtrno().getOrderNumber());
|
|
|
}
|
|
|
- String sendBody = JSON.toJSONString(bodyMap);
|
|
|
- if (!"{}".equals(sendBody)) {
|
|
|
- // 获取图片中的二维码
|
|
|
- String ocrStr = HttpUtil.sendPost("http://39.98.41.104:8088/getres", sendBody);
|
|
|
- CheckCodeResp resp = JSONUtil.toBean(ocrStr, CheckCodeResp.class);
|
|
|
- if(StringUtils.isNotEmpty(resp.getJqImageCode())){
|
|
|
- quoteVo.setCiTransferCode(resp.getJqImageCode().replace("0", "O"));
|
|
|
- }
|
|
|
- if(StringUtils.isNotEmpty(resp.getSyImageCode())){
|
|
|
- quoteVo.setBiTransferCode(resp.getSyImageCode().replace("0", "O"));
|
|
|
- }
|
|
|
- premiumCalculationRequest = new PremiumCalculationRequest(quoteVo,carActualValue,parameters,vehicle,orderNumber);
|
|
|
- premiumCalculationResponse = chengTaiRequestApiComponent.premiumCalculation(premiumCalculationRequest, apiUrl);
|
|
|
+ if( premiumCalculationResponse.getCommRisk() != null && premiumCalculationResponse.getCommRisk().getFtrno() != null){
|
|
|
+ premiumCalculationRequest.getBasePart().setOrderNumber(premiumCalculationResponse.getCommRisk().getFtrno().getOrderNumber());
|
|
|
}
|
|
|
}
|
|
|
return premiumCalculationResponse;
|
|
|
}
|
|
|
+ private List<String> multipleStartDate(PremiumCalculationResponse response) {
|
|
|
+ List<String> timeList = new ArrayList<>();
|
|
|
+ if (response == null || response.getHead() == null) {
|
|
|
+ return timeList;
|
|
|
+ }
|
|
|
+
|
|
|
+ String errorMsg = response.getHead().getErrorMessage();
|
|
|
+ if (errorMsg == null || errorMsg.isEmpty()) {
|
|
|
+ return timeList;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 正则匹配:起保日期 + 日期时间(兼容所有格式)
|
|
|
+ Pattern pattern = Pattern.compile("起保日期[\\s:]+([\\d\\s:-]+)");
|
|
|
+ Matcher matcher = pattern.matcher(errorMsg);
|
|
|
+
|
|
|
+ while (matcher.find() && timeList.size() < 2) {
|
|
|
+ String rawDate = matcher.group(1).trim();
|
|
|
+ String formattedDate = formatToStandardDateTime(rawDate);
|
|
|
+ timeList.add(formattedDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ return timeList;
|
|
|
+ }
|
|
|
+ private String formatToStandardDateTime(String raw) {
|
|
|
+ if (raw == null || raw.isEmpty()) return "";
|
|
|
+
|
|
|
+ // 提取所有数字
|
|
|
+ List<String> nums = new ArrayList<>();
|
|
|
+ Matcher m = Pattern.compile("\\d+").matcher(raw);
|
|
|
+ while (m.find()) nums.add(m.group());
|
|
|
+
|
|
|
+ if (nums.size() < 3) return raw;
|
|
|
+
|
|
|
+ String ymd = nums.get(0) + "-" + nums.get(1) + "-" + nums.get(2);
|
|
|
+ String hh = nums.size() >= 4 ? nums.get(3) : "00";
|
|
|
+ String mm = nums.size() >= 5 ? nums.get(4) : "00";
|
|
|
+ String ss = nums.size() >= 6 ? nums.get(5) : "00";
|
|
|
+
|
|
|
+ return ymd + " " + hh + ":" + mm + ":" + ss;
|
|
|
+ }
|
|
|
+ private String addOneYear(String dateStr) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ LocalDateTime dateTime = LocalDateTime.parse(dateStr, formatter);
|
|
|
+ // 加 1 年
|
|
|
+ LocalDateTime nextYear = dateTime.plusYears(1);
|
|
|
+ return nextYear.format(formatter);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public UnderwritingResultsVo underwriting(UnderwritingVo underwritingVo) throws Exception {
|