|
@@ -2,6 +2,7 @@ package com.yc.ship.module.trade.service.insurance;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.extra.pinyin.PinyinUtil;
|
|
import cn.hutool.extra.pinyin.PinyinUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
@@ -45,6 +46,7 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
@@ -479,6 +481,26 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
insuranceDO.setRationType(insuranceOrderInfoDTO.getProductNo());
|
|
insuranceDO.setRationType(insuranceOrderInfoDTO.getProductNo());
|
|
|
insuranceDO.setInsuranceEffectDate(voyage.getBoardingTime());
|
|
insuranceDO.setInsuranceEffectDate(voyage.getBoardingTime());
|
|
|
insuranceDO.setId(insuranceId);
|
|
insuranceDO.setId(insuranceId);
|
|
|
|
|
+ // 处理投保逻辑
|
|
|
|
|
+ CommonResult commonResult = handleInsuranceApply(id, voyage, insuranceDO, tradeVisitorDO, insuranceApplyReqDTO);
|
|
|
|
|
+ tradeVisitorDO.setIsInsure(InsuranceStatusEnum.INSURE.getValue());
|
|
|
|
|
+ tradeVisitorMapper.updateById(tradeVisitorDO);
|
|
|
|
|
+ //保存投保信息
|
|
|
|
|
+ insuranceMapper.deleteByVisitorId(id);
|
|
|
|
|
+ insuranceDO.setResMsg(String.valueOf(commonResult.getCheckedData()));
|
|
|
|
|
+ insuranceMapper.insert(insuranceDO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理投保
|
|
|
|
|
+ * @param id
|
|
|
|
|
+ * @param voyage
|
|
|
|
|
+ * @param insuranceDO
|
|
|
|
|
+ * @param tradeVisitorDO
|
|
|
|
|
+ * @param insuranceApplyReqDTO
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private CommonResult handleInsuranceApply(Long id, VoyageDO voyage, InsuranceDO insuranceDO, TradeVisitorDO tradeVisitorDO, InsuranceApplyReqDTO insuranceApplyReqDTO) {
|
|
|
CommonResult commonResult = insuranceUtil.sendInsuranceApply(insuranceApplyReqDTO);
|
|
CommonResult commonResult = insuranceUtil.sendInsuranceApply(insuranceApplyReqDTO);
|
|
|
if (!commonResult.isSuccess()) {
|
|
if (!commonResult.isSuccess()) {
|
|
|
InsuranceDO insuranceDO1 = insuranceMapper.selectByVisitorId(id);
|
|
InsuranceDO insuranceDO1 = insuranceMapper.selectByVisitorId(id);
|
|
@@ -487,6 +509,22 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
if (msg.contains("重复投保")) {
|
|
if (msg.contains("重复投保")) {
|
|
|
String insuranceId1 = msg.substring(msg.indexOf("此前已有投保单")+7, msg.indexOf("投保成功")).trim();
|
|
String insuranceId1 = msg.substring(msg.indexOf("此前已有投保单")+7, msg.indexOf("投保成功")).trim();
|
|
|
String policyNo = msg.substring(msg.indexOf("对应的保单号是")+7, msg.indexOf("\"}]}"));
|
|
String policyNo = msg.substring(msg.indexOf("对应的保单号是")+7, msg.indexOf("\"}]}"));
|
|
|
|
|
+ // 判断一下是不是同一个航次开始
|
|
|
|
|
+ InsuranceDO insuranceDO2 = insuranceMapper.selectById(insuranceId1);
|
|
|
|
|
+ if(insuranceDO2 != null) {
|
|
|
|
|
+ Long orderId = insuranceDO2.getOrderId();
|
|
|
|
|
+ TradeOrderDO orderDO = tradeOrderMapper.selectById(orderId);
|
|
|
|
|
+ // 不是同一个航次,但是上一个航次的离船时间和当前航次的登船日期为同一天,所以保险开始日期要往后延一天,再次投保
|
|
|
|
|
+ if(orderDO != null && !Objects.equals(voyage.getId(), orderDO.getVoyageId())) {
|
|
|
|
|
+ LocalDateTime boardingTime = voyage.getBoardingTime();
|
|
|
|
|
+ LocalDateTime offset = LocalDateTimeUtil.offset(boardingTime, 1, ChronoUnit.DAYS);
|
|
|
|
|
+ insuranceApplyReqDTO.getOrder().setBeginDate(DateUtil.format(offset, "yyyy-MM-dd"));
|
|
|
|
|
+ // 递归去投保,直到成功
|
|
|
|
|
+ commonResult = handleInsuranceApply(id, voyage, insuranceDO, tradeVisitorDO, insuranceApplyReqDTO);
|
|
|
|
|
+ return commonResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断是否同一个航次结束
|
|
|
if(insuranceDO1 != null) {
|
|
if(insuranceDO1 != null) {
|
|
|
insuranceDO1.setInsuranceStatus(InsuranceStatusEnum.SUCCESS.getValue());
|
|
insuranceDO1.setInsuranceStatus(InsuranceStatusEnum.SUCCESS.getValue());
|
|
|
insuranceMapper.deleteById(insuranceDO1.getId());
|
|
insuranceMapper.deleteById(insuranceDO1.getId());
|
|
@@ -517,12 +555,7 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
}
|
|
}
|
|
|
throw exception0(commonResult.getCode(), msg);
|
|
throw exception0(commonResult.getCode(), msg);
|
|
|
}
|
|
}
|
|
|
- tradeVisitorDO.setIsInsure(InsuranceStatusEnum.INSURE.getValue());
|
|
|
|
|
- tradeVisitorMapper.updateById(tradeVisitorDO);
|
|
|
|
|
- //保存投保信息
|
|
|
|
|
- insuranceMapper.deleteByVisitorId(id);
|
|
|
|
|
- insuranceDO.setResMsg(String.valueOf(commonResult.getCheckedData()));
|
|
|
|
|
- insuranceMapper.insert(insuranceDO);
|
|
|
|
|
|
|
+ return commonResult;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|