Explorar o código

fix: 处理投保,同一个游客乘坐去和回的航次,上一个航次的离船日期和下一个航次的登船日期相同导致投保失败的问题

luofeiyun hai 2 días
pai
achega
865aab8063

+ 39 - 6
ship-module-trade/ship-module-trade-biz/src/main/java/com/yc/ship/module/trade/service/insurance/InsuranceServiceImpl.java

@@ -2,6 +2,7 @@ package com.yc.ship.module.trade.service.insurance;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.date.LocalDateTimeUtil;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.extra.pinyin.PinyinUtil;
 import cn.hutool.http.HttpUtil;
@@ -45,6 +46,7 @@ import org.springframework.validation.annotation.Validated;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
 import java.util.*;
 
 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.setInsuranceEffectDate(voyage.getBoardingTime());
         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);
         if (!commonResult.isSuccess()) {
             InsuranceDO insuranceDO1 = insuranceMapper.selectByVisitorId(id);
@@ -487,6 +509,22 @@ public class InsuranceServiceImpl implements InsuranceService {
             if (msg.contains("重复投保")) {
                 String insuranceId1 = msg.substring(msg.indexOf("此前已有投保单")+7, msg.indexOf("投保成功")).trim();
                 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) {
                     insuranceDO1.setInsuranceStatus(InsuranceStatusEnum.SUCCESS.getValue());
                     insuranceMapper.deleteById(insuranceDO1.getId());
@@ -517,12 +555,7 @@ public class InsuranceServiceImpl implements InsuranceService {
             }
             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