|
|
@@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.yc.ship.framework.common.pojo.CommonResult;
|
|
|
import com.yc.ship.framework.common.pojo.PageResult;
|
|
|
+import com.yc.ship.framework.common.util.collection.CollectionUtils;
|
|
|
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
import com.yc.ship.framework.mybatis.core.util.MyBatisUtils;
|
|
|
import com.yc.ship.module.infra.api.config.ConfigApi;
|
|
|
@@ -26,6 +27,7 @@ import com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO
|
|
|
import com.yc.ship.module.trade.controller.admin.order.vo.order.TradeVisitorRespVO;
|
|
|
import com.yc.ship.module.trade.dal.dataobject.insurance.InsuranceDO;
|
|
|
import com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO;
|
|
|
+import com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO;
|
|
|
import com.yc.ship.module.trade.dal.mysql.insurance.InsuranceMapper;
|
|
|
import com.yc.ship.module.trade.dal.mysql.order.TradeOrderMapper;
|
|
|
import com.yc.ship.module.trade.dal.mysql.order.TradeVisitorMapper;
|
|
|
@@ -43,10 +45,7 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception0;
|
|
|
@@ -385,6 +384,130 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
tradeOrderMapper.update(new LambdaUpdateWrapper<TradeOrderDO>().set(TradeOrderDO::getIsInsure, insuranceStatus).eq(TradeOrderDO::getOrderNo, insuranceDO.getInsuranceNo()));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void applyInsuranceNew(Long id) {
|
|
|
+ TradeVisitorDO tradeVisitorDO = tradeVisitorMapper.selectById(id);
|
|
|
+ Integer isInsure = tradeVisitorDO.getIsInsure();
|
|
|
+ if(isInsure != null ) {
|
|
|
+ if(isInsure == InsuranceStatusEnum.SUCCESS.getValue()) {
|
|
|
+ throw exception0(500, "该订单已投保成功");
|
|
|
+ }else if(isInsure == InsuranceStatusEnum.INSURE.getValue()) {
|
|
|
+ throw exception0(500, "该订单正在投保中");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ TradeOrderDO orderDO = tradeOrderMapper.selectById(tradeVisitorDO.getOrderId());
|
|
|
+ VoyageDO voyage = voyageService.getVoyage(orderDO.getVoyageId());
|
|
|
+ InsuranceDO insuranceDO = new InsuranceDO();
|
|
|
+ Long insuranceId = IdWorker.getId(insuranceDO);
|
|
|
+
|
|
|
+ InsuranceApplyReqDTO insuranceApplyReqDTO = new InsuranceApplyReqDTO();
|
|
|
+ // 个保 - apply; 团保 - applyTeam
|
|
|
+ insuranceApplyReqDTO.setService("apply");
|
|
|
+ // 回调地址
|
|
|
+ insuranceApplyReqDTO.setReplyUrl(notifyUrl);
|
|
|
+ // 使用在线支付时填1, 不使用在线支付填0
|
|
|
+ insuranceApplyReqDTO.setOnlinePayInd("0");
|
|
|
+
|
|
|
+ //订单对象, 一个订单下可以有一批被保险人
|
|
|
+ InsuranceOrderInfoDTO insuranceOrderInfoDTO = new InsuranceOrderInfoDTO();
|
|
|
+
|
|
|
+ //投保人信息
|
|
|
+ insuranceOrderInfoDTO.setExternalOrderNo(insuranceId.toString());
|
|
|
+ insuranceOrderInfoDTO.setExternalPolicyNumber(insuranceId.toString());
|
|
|
+ //TODO: 当前写死
|
|
|
+ insuranceOrderInfoDTO.setProductNo(configApi.getConfigValueByKey("insuranceConfig.product_no"));
|
|
|
+ insuranceOrderInfoDTO.setBeginDate(DateUtil.format(voyage.getBoardingTime(), "yyyy-MM-dd"));
|
|
|
+ insuranceOrderInfoDTO.setEndDate(DateUtil.format(voyage.getLeaveTime(), "yyyy-MM-dd"));
|
|
|
+ insuranceOrderInfoDTO.setCurrencyCode("CNY");
|
|
|
+ insuranceOrderInfoDTO.setBizType(0);
|
|
|
+ insuranceOrderInfoDTO.setApplicantType(1);
|
|
|
+ insuranceOrderInfoDTO.setApplicant(configApi.getConfigValueByKey("insuranceConfig.applicant"));
|
|
|
+ insuranceOrderInfoDTO.setApplicantCertificateType(6);
|
|
|
+ insuranceOrderInfoDTO.setApplicantCertificateNo(configApi.getConfigValueByKey("insuranceConfig.applicant_certificate_no"));
|
|
|
+ insuranceOrderInfoDTO.setApplicantBirthday("1990-01-01");
|
|
|
+ insuranceOrderInfoDTO.setApplicantSex(1);
|
|
|
+
|
|
|
+ //销售人信息
|
|
|
+ insuranceOrderInfoDTO.setSellCorp("营销中心");
|
|
|
+ insuranceOrderInfoDTO.setSellDept("营销中心");
|
|
|
+ insuranceOrderInfoDTO.setSellUser("营销中心");
|
|
|
+ insuranceApplyReqDTO.setOrder(insuranceOrderInfoDTO);
|
|
|
+
|
|
|
+ //被保人对象列表, 其下可多位被保险人, 他们在同个订单下
|
|
|
+ List<InsuredDTO> insuredList = new ArrayList<>();
|
|
|
+ InsuredDTO insuredDTO = new InsuredDTO();
|
|
|
+ insuredDTO.setExternalPolicyNumber(tradeVisitorDO.getId().toString());
|
|
|
+ String name = tradeVisitorDO.getName();
|
|
|
+ insuredDTO.setInsuredName(name);
|
|
|
+ if(9 == tradeVisitorDO.getCredentialType()) {
|
|
|
+ if(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 {
|
|
|
+ insuredDTO.setInsuredName(name);
|
|
|
+ if(name.contains("/")) {
|
|
|
+ insuredDTO.setFirstName(name.substring(0, name.indexOf("/")));
|
|
|
+ insuredDTO.setLastName(name.substring(name.indexOf("/") + 1));
|
|
|
+ }else {
|
|
|
+ insuredDTO.setFirstName(name.substring(0, name.indexOf(" ")));
|
|
|
+ insuredDTO.setLastName(name.substring(name.indexOf(" ") + 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ insuredDTO.setCertificateType(transCredentialType(tradeVisitorDO.getCredentialType()));
|
|
|
+ insuredDTO.setCertificateNo(tradeVisitorDO.getCredentialNo());
|
|
|
+ insuredDTO.setBirthday(tradeVisitorDO.getBirthday());
|
|
|
+ insuredDTO.setSex(tradeVisitorDO.getGender());
|
|
|
+ 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(id);
|
|
|
+ CommonResult commonResult = insuranceUtil.sendInsuranceApply(insuranceApplyReqDTO);
|
|
|
+ if (!commonResult.isSuccess()) {
|
|
|
+ log.error("投保失败:{}", commonResult.getMsg());
|
|
|
+ InsuranceDO insuranceDO1 = insuranceMapper.selectByVisitorId(id);
|
|
|
+ if(insuranceDO1 != null) {
|
|
|
+ insuranceDO1.setInsuranceStatus(InsuranceStatusEnum.FAIL.getValue());
|
|
|
+ insuranceDO1.setResMsg(commonResult.getMsg());
|
|
|
+ insuranceMapper.updateById(insuranceDO1);
|
|
|
+ }else {
|
|
|
+ insuranceDO.setInsuranceStatus(InsuranceStatusEnum.FAIL.getValue());
|
|
|
+ insuranceDO.setResMsg(commonResult.getMsg());
|
|
|
+ insuranceMapper.insert(insuranceDO);
|
|
|
+ }
|
|
|
+ throw exception0(commonResult.getCode(), commonResult.getMsg());
|
|
|
+ }
|
|
|
+ //保存投保信息
|
|
|
+ insuranceMapper.deleteByVisitorId(id);
|
|
|
+ insuranceDO.setResMsg(String.valueOf(commonResult.getCheckedData()));
|
|
|
+ insuranceMapper.insert(insuranceDO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<InsuranceDO> getListByVisitorIds(List<Long> visitorIds) {
|
|
|
+ if(CollectionUtils.isAnyEmpty(visitorIds)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return insuranceMapper.selectListByVisitorIds(visitorIds);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void queryInsuranceByOrderId(Long id) {
|
|
|
InsuranceDO insuranceDO = insuranceMapper.selectById(id);
|