|
|
@@ -4,6 +4,7 @@ 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.core.util.IdUtil;
|
|
|
import cn.hutool.extra.pinyin.PinyinUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
@@ -177,7 +178,7 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
|
|
|
//被保人对象列表, 其下可多位被保险人, 他们在同个订单下
|
|
|
List<TradeVisitorRespVO> tradeVisitorRespVOS = tradeVisitorMapper.queryVisitorByOrderId(orderId);
|
|
|
- if(tradeVisitorRespVOS == null || tradeVisitorRespVOS.size() == 0) {
|
|
|
+ if(tradeVisitorRespVOS == null || tradeVisitorRespVOS.isEmpty()) {
|
|
|
log.error("订单{}下没有被保人信息, 投保失败", orderId);
|
|
|
throw exception(INSURANCE_NO_INSURED);
|
|
|
}
|
|
|
@@ -227,7 +228,7 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
insuranceDO.setRationType(insuranceOrderInfoDTO.getProductNo());
|
|
|
insuranceDO.setInsuranceEffectDate(voyage.getBoardingTime());
|
|
|
insuranceDO.setId(id);
|
|
|
- CommonResult commonResult = insuranceUtil.sendInsuranceApply(insuranceApplyReqDTO);
|
|
|
+ CommonResult commonResult = insuranceUtil.sendInsuranceApply(insuranceApplyReqDTO,insuranceDO.getOrderId());
|
|
|
if (!commonResult.isSuccess()) {
|
|
|
log.error("投保失败:{}", commonResult.getMsg());
|
|
|
InsuranceDO insuranceDO1 = insuranceMapper.selectByOrderId(orderId);
|
|
|
@@ -389,19 +390,37 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
@Override
|
|
|
public void applyInsuranceNew(Long id) {
|
|
|
TradeVisitorDO tradeVisitorDO = tradeVisitorMapper.selectById(id);
|
|
|
+ if (tradeVisitorDO == null) {
|
|
|
+ throw exception0(500, "游客信息不存在");
|
|
|
+ }
|
|
|
Integer isInsure = tradeVisitorDO.getIsInsure();
|
|
|
if(isInsure != null ) {
|
|
|
- if(isInsure == InsuranceStatusEnum.SUCCESS.getValue()) {
|
|
|
+ if(isInsure.equals(InsuranceStatusEnum.SUCCESS.getValue())) {
|
|
|
throw exception0(500, "该订单已投保成功");
|
|
|
- }else if(isInsure == InsuranceStatusEnum.INSURE.getValue()) {
|
|
|
+ }else if(isInsure.equals(InsuranceStatusEnum.INSURE.getValue())) {
|
|
|
throw exception0(500, "该订单正在投保中");
|
|
|
}
|
|
|
}
|
|
|
TradeOrderDO orderDO = tradeOrderMapper.selectById(tradeVisitorDO.getOrderId());
|
|
|
+ if (orderDO == null) {
|
|
|
+ throw exception0(500, "订单信息不存在");
|
|
|
+ }
|
|
|
VoyageDO voyage = voyageService.getVoyage(orderDO.getVoyageId());
|
|
|
+ if (voyage == null) {
|
|
|
+ throw exception0(500, "航次信息不存在");
|
|
|
+ }
|
|
|
InsuranceDO insuranceDO = new InsuranceDO();
|
|
|
+ String productNo = configApi.getConfigValueByKey("insuranceConfig.product_no");
|
|
|
+ // 开始投保
|
|
|
+ insuranceDO.setOrderId(orderDO.getId());
|
|
|
+ insuranceDO.setVisitorId(tradeVisitorDO.getId());
|
|
|
+ insuranceDO.setInsuranceStatus(InsuranceStatusEnum.INSURE.getValue());
|
|
|
+ insuranceDO.setInsuredNum(1);
|
|
|
+ insuranceDO.setInsuranceNo(orderDO.getOrderNo());
|
|
|
+ insuranceDO.setTenantId(voyage.getTenantId());
|
|
|
+ insuranceDO.setRationType(productNo);
|
|
|
+ insuranceDO.setInsuranceEffectDate(voyage.getBoardingTime());
|
|
|
Long insuranceId = IdWorker.getId(insuranceDO);
|
|
|
-
|
|
|
InsuranceApplyReqDTO insuranceApplyReqDTO = new InsuranceApplyReqDTO();
|
|
|
// 个保 - apply; 团保 - applyTeam
|
|
|
insuranceApplyReqDTO.setService("apply");
|
|
|
@@ -412,12 +431,11 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
|
|
|
//订单对象, 一个订单下可以有一批被保险人
|
|
|
InsuranceOrderInfoDTO insuranceOrderInfoDTO = new InsuranceOrderInfoDTO();
|
|
|
-
|
|
|
//投保人信息
|
|
|
insuranceOrderInfoDTO.setExternalOrderNo(insuranceId.toString());
|
|
|
insuranceOrderInfoDTO.setExternalPolicyNumber(insuranceId.toString());
|
|
|
//TODO: 当前写死
|
|
|
- insuranceOrderInfoDTO.setProductNo(configApi.getConfigValueByKey("insuranceConfig.product_no"));
|
|
|
+ insuranceOrderInfoDTO.setProductNo(productNo);
|
|
|
insuranceOrderInfoDTO.setBeginDate(DateUtil.format(voyage.getBoardingTime(), "yyyy-MM-dd"));
|
|
|
insuranceOrderInfoDTO.setEndDate(DateUtil.format(voyage.getLeaveTime(), "yyyy-MM-dd"));
|
|
|
insuranceOrderInfoDTO.setCurrencyCode("CNY");
|
|
|
@@ -441,20 +459,29 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
insuredDTO.setExternalPolicyNumber(insuranceId.toString());
|
|
|
String name = tradeVisitorDO.getName();
|
|
|
insuredDTO.setInsuredName(name);
|
|
|
- if(9 == tradeVisitorDO.getCredentialType()) {
|
|
|
- if(PinyinUtil.isChinese(name.charAt(0))) {
|
|
|
+ if(Integer.valueOf(9).equals(tradeVisitorDO.getCredentialType())) {
|
|
|
+ if(name != null && !name.isEmpty() && PinyinUtil.isChinese(name.charAt(0))) {
|
|
|
String pinyin = PinyinUtil.getPinyin(name, " ");
|
|
|
insuredDTO.setInsuredName(pinyin);
|
|
|
- insuredDTO.setFirstName(pinyin.substring(0, pinyin.indexOf(" ")));
|
|
|
- insuredDTO.setLastName(pinyin.substring(pinyin.indexOf(" ") + 1));
|
|
|
- }else {
|
|
|
+ int spaceIdx = pinyin.indexOf(" ");
|
|
|
+ if (spaceIdx > 0) {
|
|
|
+ insuredDTO.setFirstName(pinyin.substring(0, spaceIdx));
|
|
|
+ insuredDTO.setLastName(pinyin.substring(spaceIdx + 1));
|
|
|
+ } else {
|
|
|
+ insuredDTO.setFirstName(pinyin);
|
|
|
+ insuredDTO.setLastName("");
|
|
|
+ }
|
|
|
+ }else if(name != null && !name.isEmpty()) {
|
|
|
insuredDTO.setInsuredName(name);
|
|
|
if(name.contains("/")) {
|
|
|
insuredDTO.setFirstName(name.substring(0, name.indexOf("/")));
|
|
|
insuredDTO.setLastName(name.substring(name.indexOf("/") + 1));
|
|
|
- }else {
|
|
|
+ }else if(name.contains(" ")) {
|
|
|
insuredDTO.setFirstName(name.substring(0, name.indexOf(" ")));
|
|
|
insuredDTO.setLastName(name.substring(name.indexOf(" ") + 1));
|
|
|
+ } else {
|
|
|
+ insuredDTO.setFirstName(name);
|
|
|
+ insuredDTO.setLastName("");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -462,27 +489,14 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
insuredDTO.setCertificateNo(tradeVisitorDO.getCredentialNo());
|
|
|
insuredDTO.setBirthday(tradeVisitorDO.getBirthday());
|
|
|
insuredDTO.setSex(tradeVisitorDO.getGender());
|
|
|
- insuredDTO.setRelation(2); //不是保单持有人,只是被保险人
|
|
|
+ //不是保单持有人,只是被保险人
|
|
|
+ insuredDTO.setRelation(2);
|
|
|
insuredList.add(insuredDTO);
|
|
|
insuranceApplyReqDTO.setInsureds(insuredList);
|
|
|
|
|
|
-// //验证投保信息
|
|
|
-// CommonResult commonResult = insuranceUtil.validateInsuranceRequest(insuranceApplyReqDTO);
|
|
|
-// if (!commonResult.isSuccess()) {
|
|
|
-// throw exception0(commonResult.getCode(), commonResult.getMsg());
|
|
|
-// }
|
|
|
- // 开始投保
|
|
|
- insuranceDO.setOrderId(orderDO.getId());
|
|
|
- insuranceDO.setVisitorId(tradeVisitorDO.getId());
|
|
|
- insuranceDO.setInsuranceStatus(InsuranceStatusEnum.INSURE.getValue());
|
|
|
- insuranceDO.setInsuredNum(1);
|
|
|
- insuranceDO.setInsuranceNo(orderDO.getOrderNo());
|
|
|
- insuranceDO.setTenantId(voyage.getTenantId());
|
|
|
- insuranceDO.setRationType(insuranceOrderInfoDTO.getProductNo());
|
|
|
- insuranceDO.setInsuranceEffectDate(voyage.getBoardingTime());
|
|
|
insuranceDO.setId(insuranceId);
|
|
|
// 处理投保逻辑
|
|
|
- CommonResult commonResult = handleInsuranceApply(id, voyage, insuranceDO, tradeVisitorDO, insuranceApplyReqDTO);
|
|
|
+ CommonResult<?> commonResult = handleInsuranceApply(id, voyage, insuranceDO, tradeVisitorDO, insuranceApplyReqDTO);
|
|
|
tradeVisitorDO.setIsInsure(InsuranceStatusEnum.INSURE.getValue());
|
|
|
tradeVisitorMapper.updateById(tradeVisitorDO);
|
|
|
//保存投保信息
|
|
|
@@ -500,19 +514,19 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
* @param insuranceApplyReqDTO
|
|
|
* @return
|
|
|
*/
|
|
|
- private CommonResult handleInsuranceApply(Long id, VoyageDO voyage, InsuranceDO insuranceDO, TradeVisitorDO tradeVisitorDO, InsuranceApplyReqDTO insuranceApplyReqDTO) {
|
|
|
- CommonResult commonResult = insuranceUtil.sendInsuranceApply(insuranceApplyReqDTO);
|
|
|
+ private CommonResult<?> handleInsuranceApply(Long id, VoyageDO voyage, InsuranceDO insuranceDO, TradeVisitorDO tradeVisitorDO, InsuranceApplyReqDTO insuranceApplyReqDTO) {
|
|
|
+ CommonResult<?> commonResult = insuranceUtil.sendInsuranceApply(insuranceApplyReqDTO,id);
|
|
|
if (!commonResult.isSuccess()) {
|
|
|
- InsuranceDO insuranceDO1 = insuranceMapper.selectByVisitorId(id);
|
|
|
+ InsuranceDO insurance1 = insuranceMapper.selectByVisitorId(id);
|
|
|
String msg = commonResult.getMsg();
|
|
|
- log.error("投保失败:{}", msg);
|
|
|
+ log.error("handleInsuranceApply投保失败:{}", msg);
|
|
|
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();
|
|
|
+ InsuranceDO insurance2 = insuranceMapper.selectById(insuranceId1);
|
|
|
+ if(insurance2 != null) {
|
|
|
+ Long orderId = insurance2.getOrderId();
|
|
|
TradeOrderDO orderDO = tradeOrderMapper.selectById(orderId);
|
|
|
// 不是同一个航次,但是上一个航次的离船时间和当前航次的登船日期为同一天,所以保险开始日期要往后延一天,再次投保
|
|
|
if(orderDO != null && !Objects.equals(voyage.getId(), orderDO.getVoyageId())) {
|
|
|
@@ -525,12 +539,12 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
}
|
|
|
}
|
|
|
// 判断是否同一个航次结束
|
|
|
- if(insuranceDO1 != null) {
|
|
|
- insuranceDO1.setInsuranceStatus(InsuranceStatusEnum.SUCCESS.getValue());
|
|
|
- insuranceMapper.deleteById(insuranceDO1.getId());
|
|
|
- insuranceDO1.setId(Long.valueOf(insuranceId1));
|
|
|
- insuranceDO1.setPolicyNo(policyNo);
|
|
|
- insuranceMapper.insert(insuranceDO1);
|
|
|
+ if(insurance1 != null) {
|
|
|
+ insurance1.setInsuranceStatus(InsuranceStatusEnum.SUCCESS.getValue());
|
|
|
+ insuranceMapper.deleteById(insurance1.getId());
|
|
|
+ insurance1.setId(Long.valueOf(insuranceId1));
|
|
|
+ insurance1.setPolicyNo(policyNo);
|
|
|
+ insuranceMapper.insert(insurance1);
|
|
|
}else {
|
|
|
insuranceDO.setInsuranceStatus(InsuranceStatusEnum.SUCCESS.getValue());
|
|
|
insuranceDO.setId(Long.valueOf(insuranceId1));
|
|
|
@@ -540,10 +554,10 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
tradeVisitorDO.setIsInsure(InsuranceStatusEnum.SUCCESS.getValue());
|
|
|
tradeVisitorMapper.updateById(tradeVisitorDO);
|
|
|
} else {
|
|
|
- if(insuranceDO1 != null) {
|
|
|
- insuranceDO1.setInsuranceStatus(InsuranceStatusEnum.FAIL.getValue());
|
|
|
- insuranceDO1.setResMsg(msg);
|
|
|
- insuranceMapper.updateById(insuranceDO1);
|
|
|
+ if(insurance1 != null) {
|
|
|
+ insurance1.setInsuranceStatus(InsuranceStatusEnum.FAIL.getValue());
|
|
|
+ insurance1.setResMsg(msg);
|
|
|
+ insuranceMapper.updateById(insurance1);
|
|
|
}else {
|
|
|
insuranceDO.setInsuranceStatus(InsuranceStatusEnum.FAIL.getValue());
|
|
|
insuranceDO.setResMsg(msg);
|