Browse Source

fix: 添加订单投保状态和错误信息

luofeiyun 1 week ago
parent
commit
2e4de6795e

+ 1 - 0
ship-module-trade/ship-module-trade-api/src/main/java/com/yc/ship/module/trade/enums/ErrorCodeConstants.java

@@ -37,6 +37,7 @@ public interface ErrorCodeConstants {
     ErrorCode ORDER_NOT_EXISTS = new ErrorCode(15_002, "保险订单不存在");
     ErrorCode ORDER_NOT_EXISTS = new ErrorCode(15_002, "保险订单不存在");
     ErrorCode INSURE_FAILED = new ErrorCode(15_002_01, "保险投保失败");
     ErrorCode INSURE_FAILED = new ErrorCode(15_002_01, "保险投保失败");
     ErrorCode INSURE_CANCEL_FAILED = new ErrorCode(15_002_02, "保险退保失败");
     ErrorCode INSURE_CANCEL_FAILED = new ErrorCode(15_002_02, "保险退保失败");
+    ErrorCode INSURANCE_NO_INSURED = new ErrorCode(15_002_03, "该订单没有被保人信息");
 
 
 // ========== 短信发送配置  ==========
 // ========== 短信发送配置  ==========
     ErrorCode SMS_SENDCONFIG_NOT_EXISTS = new ErrorCode(17_001_01, "短信发送配置不存在");
     ErrorCode SMS_SENDCONFIG_NOT_EXISTS = new ErrorCode(17_001_01, "短信发送配置不存在");

+ 3 - 0
ship-module-trade/ship-module-trade-biz/src/main/java/com/yc/ship/module/trade/controller/admin/order/vo/order/TradeOrderRespNewVO.java

@@ -260,6 +260,9 @@ public class TradeOrderRespNewVO {
     @Schema(description  = "待支付金额")
     @Schema(description  = "待支付金额")
     private BigDecimal loadPayAmount;
     private BigDecimal loadPayAmount;
 
 
+    @Schema(description = "投保错误描述")
+    private String resMsg;
+
 
 
 
 
 
 

+ 3 - 0
ship-module-trade/ship-module-trade-biz/src/main/java/com/yc/ship/module/trade/controller/admin/order/vo/order/TradeOrderRespVO.java

@@ -562,5 +562,8 @@ public class TradeOrderRespVO {
     @Schema(description = "待支付金额")
     @Schema(description = "待支付金额")
     private BigDecimal loadPayAmount;
     private BigDecimal loadPayAmount;
 
 
+    @Schema(description = "投保错误描述")
+    private String resMsg;
+
 
 
 }
 }

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

@@ -50,8 +50,7 @@ import java.util.Map;
 
 
 import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception0;
 import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception0;
-import static com.yc.ship.module.trade.enums.ErrorCodeConstants.INSURANCE_NOT_EXISTS;
-import static com.yc.ship.module.trade.enums.ErrorCodeConstants.ORDER_NOT_EXISTS;
+import static com.yc.ship.module.trade.enums.ErrorCodeConstants.*;
 
 
 
 
 /**
 /**
@@ -128,10 +127,18 @@ public class InsuranceServiceImpl implements InsuranceService {
      * @return
      * @return
      */
      */
     @Override
     @Override
-    @Transactional
+//    @Transactional
     public boolean applyInsurance(Long orderId) {
     public boolean applyInsurance(Long orderId) {
 
 
-        TradeOrderRespVO orderInfo = tradeOrderMapper.getOrderInfo(orderId);
+        TradeOrderDO orderInfo = tradeOrderMapper.selectById(orderId);
+        Integer isInsure = orderInfo.getIsInsure();
+        if(isInsure != null ) {
+            if(isInsure == 1) {
+                throw exception0(500, "该订单已投保成功");
+            }else if(isInsure == 0) {
+                throw exception0(500, "该订单正在投保中");
+            }
+        }
         VoyageDO voyage = voyageService.getVoyage(orderInfo.getVoyageId());
         VoyageDO voyage = voyageService.getVoyage(orderInfo.getVoyageId());
         InsuranceDO insuranceDO = new InsuranceDO();
         InsuranceDO insuranceDO = new InsuranceDO();
         Long id = IdWorker.getId(insuranceDO);
         Long id = IdWorker.getId(insuranceDO);
@@ -170,7 +177,8 @@ public class InsuranceServiceImpl implements InsuranceService {
         //被保人对象列表, 其下可多位被保险人, 他们在同个订单下
         //被保人对象列表, 其下可多位被保险人, 他们在同个订单下
         List<TradeVisitorRespVO> tradeVisitorRespVOS = tradeVisitorMapper.queryVisitorByOrderId(orderId);
         List<TradeVisitorRespVO> tradeVisitorRespVOS = tradeVisitorMapper.queryVisitorByOrderId(orderId);
         if(tradeVisitorRespVOS == null || tradeVisitorRespVOS.size() == 0) {
         if(tradeVisitorRespVOS == null || tradeVisitorRespVOS.size() == 0) {
-            return false;
+            log.error("订单{}下没有被保人信息, 投保失败", orderId);
+            throw exception(INSURANCE_NO_INSURED);
         }
         }
         List<InsuredDTO> insuredList = new ArrayList<>();
         List<InsuredDTO> insuredList = new ArrayList<>();
         tradeVisitorRespVOS.forEach(tradeVisitorRespVO -> {
         tradeVisitorRespVOS.forEach(tradeVisitorRespVO -> {
@@ -210,22 +218,34 @@ public class InsuranceServiceImpl implements InsuranceService {
 //            throw exception0(commonResult.getCode(), commonResult.getMsg());
 //            throw exception0(commonResult.getCode(), commonResult.getMsg());
 //        }
 //        }
         // 开始投保
         // 开始投保
-        CommonResult commonResult = insuranceUtil.sendInsuranceApply(insuranceApplyReqDTO);
-        if (!commonResult.isSuccess()) {
-            throw exception0(commonResult.getCode(), commonResult.getMsg());
-        }
-        //保存投保信息
-        insuranceMapper.deleteByOrderId(orderId);
-
         insuranceDO.setOrderId(orderId);
         insuranceDO.setOrderId(orderId);
         insuranceDO.setInsuranceStatus(InsuranceStatusEnum.INSURE.getValue());
         insuranceDO.setInsuranceStatus(InsuranceStatusEnum.INSURE.getValue());
         insuranceDO.setInsuredNum(insuredList.size());
         insuranceDO.setInsuredNum(insuredList.size());
         insuranceDO.setInsuranceNo(orderInfo.getOrderNo());
         insuranceDO.setInsuranceNo(orderInfo.getOrderNo());
         insuranceDO.setTenantId(voyage.getTenantId());
         insuranceDO.setTenantId(voyage.getTenantId());
         insuranceDO.setRationType(insuranceOrderInfoDTO.getProductNo());
         insuranceDO.setRationType(insuranceOrderInfoDTO.getProductNo());
-        insuranceDO.setResMsg(String.valueOf(commonResult.getCheckedData()));
         insuranceDO.setInsuranceEffectDate(voyage.getBoardingTime());
         insuranceDO.setInsuranceEffectDate(voyage.getBoardingTime());
         insuranceDO.setId(id);
         insuranceDO.setId(id);
+        CommonResult commonResult = insuranceUtil.sendInsuranceApply(insuranceApplyReqDTO);
+        if (!commonResult.isSuccess()) {
+            log.error("投保失败:{}", commonResult.getMsg());
+            InsuranceDO insuranceDO1 = insuranceMapper.selectByOrderId(orderId);
+            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);
+            }
+            tradeOrderMapper.update(new LambdaUpdateWrapper<TradeOrderDO>().set(TradeOrderDO::getIsInsure, InsuranceStatusEnum.FAIL.getValue()).eq(TradeOrderDO::getId, orderId));
+            throw exception0(commonResult.getCode(), commonResult.getMsg());
+        }
+        //保存投保信息
+        insuranceMapper.deleteByOrderId(orderId);
+        insuranceDO.setResMsg(String.valueOf(commonResult.getCheckedData()));
+
         insuranceMapper.insert(insuranceDO);
         insuranceMapper.insert(insuranceDO);
         // 发送查询投保接口通知
         // 发送查询投保接口通知
         tradePublishUtils.publishInsuranceQueryMsg(id.toString());
         tradePublishUtils.publishInsuranceQueryMsg(id.toString());

+ 1 - 4
ship-module-trade/ship-module-trade-biz/src/main/java/com/yc/ship/module/trade/service/notify/NotifyServiceImpl.java

@@ -1,7 +1,5 @@
 package com.yc.ship.module.trade.service.notify;
 package com.yc.ship.module.trade.service.notify;
 
 
-import cn.hutool.core.date.LocalDateTimeUtil;
-import com.yc.ship.framework.common.util.date.DateUtils;
 import com.yc.ship.module.system.api.notify.NotifyMessageSendApi;
 import com.yc.ship.module.system.api.notify.NotifyMessageSendApi;
 import com.yc.ship.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
 import com.yc.ship.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
 import com.yc.ship.module.trade.controller.admin.notify.vo.NotifyInsuranceReqVO;
 import com.yc.ship.module.trade.controller.admin.notify.vo.NotifyInsuranceReqVO;
@@ -13,8 +11,6 @@ import com.yc.ship.module.trade.service.order.TradeOrderRepositoryService;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -66,6 +62,7 @@ public class NotifyServiceImpl implements NotifyService {
             reqDTO.setTemplateParams(templateData);
             reqDTO.setTemplateParams(templateData);
             reqDTO.setTemplateCode("send_insurance_fail");
             reqDTO.setTemplateCode("send_insurance_fail");
             notifyMessageSendApi.sendSingleMessageToMember(reqDTO);
             notifyMessageSendApi.sendSingleMessageToMember(reqDTO);
+            insuranceDO.setResMsg(msg);
         }
         }
         insuranceMapper.updateById(insuranceDO);
         insuranceMapper.updateById(insuranceDO);
         tradeOrderRepositoryService.updateOrderInsureStatus(insuranceDO.getOrderId(),insuranceDO.getInsuranceStatus());
         tradeOrderRepositoryService.updateOrderInsureStatus(insuranceDO.getOrderId(),insuranceDO.getInsuranceStatus());

+ 3 - 2
ship-module-trade/ship-module-trade-biz/src/main/resources/mapper/order/TradeOrderMapper.xml

@@ -493,7 +493,7 @@
 
 
     <select id="getTradeOrderUserPage"
     <select id="getTradeOrderUserPage"
             resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
             resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
-        SELECT td.*,toa.audit_time auditTime,tou.contact_name,tou.credential_no,tou.mobile,count(tdl.id) num,sum(CASE WHEN tdl.voucher_status in (1,2,3,4,6,8,9) THEN	1 ELSE 0 END) realnum,(tr.origin_amount-tr.refund_amount) feeAmount,tdl.product_name,tdl.spec_type,ifnull(tr.origin_amount-tr.refund_amount,0) realAmount
+        SELECT td.*,tins.res_msg,toa.audit_time auditTime,tou.contact_name,tou.credential_no,tou.mobile,count(tdl.id) num,sum(CASE WHEN tdl.voucher_status in (1,2,3,4,6,8,9) THEN	1 ELSE 0 END) realnum,(tr.origin_amount-tr.refund_amount) feeAmount,tdl.product_name,tdl.spec_type,ifnull(tr.origin_amount-tr.refund_amount,0) realAmount
              ,tr.refund_amount refundAmount,
              ,tr.refund_amount refundAmount,
              ps.product_tag productTag,ps.product_tag2 productTag2,ps.product_tag3 productTag3,ps.product_tag4 productTag4
              ps.product_tag productTag,ps.product_tag2 productTag2,ps.product_tag3 productTag3,ps.product_tag4 productTag4
         FROM trade_order td
         FROM trade_order td
@@ -504,7 +504,8 @@
         LEFT JOIN trade_order_audit toa on toa.order_id = td.id and toa.audit_status = 1
         LEFT JOIN trade_order_audit toa on toa.order_id = td.id and toa.audit_status = 1
         LEFT JOIN (select m2.order_id,sum(m2.refund_amount) refund_amount,sum(m2.origin_amount) origin_amount from trade_refund m2  where m2.refund_status = 6 and m2.refund_method !=2 GROUP BY m2.order_id) tr on td.id = tr.order_id
         LEFT JOIN (select m2.order_id,sum(m2.refund_amount) refund_amount,sum(m2.origin_amount) origin_amount from trade_refund m2  where m2.refund_status = 6 and m2.refund_method !=2 GROUP BY m2.order_id) tr on td.id = tr.order_id
         LEFT JOIN trade_order_room_model torm on torm.order_id = td.id
         LEFT JOIN trade_order_room_model torm on torm.order_id = td.id
-        where td.deleted = 0 and tou.deleted = 0
+        left join trade_insurance tins on tins.order_id = td.id
+        where td.deleted = 0 and tou.deleted = 0 and tins.deleted = 0
         <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
         <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
             and  td.order_status in
             and  td.order_status in
             <foreach collection="vo.orderStatus" item="item" separator=","  open="(" close=")">
             <foreach collection="vo.orderStatus" item="item" separator=","  open="(" close=")">