lishiqiang 6 日 前
コミット
eaba5a4fea

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

@@ -6,6 +6,7 @@ import cn.hutool.core.map.MapUtil;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -237,7 +238,6 @@ public class InsuranceServiceImpl implements InsuranceService {
     /**
      * 退保
      *
-     * @param orderId
      */
     @Override
     @Transactional
@@ -324,13 +324,72 @@ public class InsuranceServiceImpl implements InsuranceService {
         if (!commonResult.isSuccess()) {
             throw exception0(commonResult.getCode(), commonResult.getMsg());
         }
+        //{"phase":"INSURE","externalOrderNo":"tys-20261001-YC-14",
+        // "paiedAmount":"10.00","total":"1","insuredCount":"1","insureProcessingCount":"0",
+        // "cancelledCount":"0","cancelProcessingCount":"0","refundedAmount":"0.0",
+        // "cipher":"26e2e422d370653274ee74ef3edc7f93","policies":[{"externalPolicyNumber":"2037220248460828673",
+        // "service":"applyTeam","status":"SUCCESS","msg":"投保成功","policyNo":"HW61927008L7JB7J8Q00"}]}
+        String checkedData = (String) commonResult.getCheckedData();
+        com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(checkedData);
+        BigDecimal paiedAmount = jsonObject.getBigDecimal("paiedAmount");
+        JSONArray policies = jsonObject.getJSONArray("policies");
+        if(policies == null) {
+            handleInsuranceQuery(paiedAmount, "", insuranceDO.getOrderId(), "FAIL");
+        }
+        com.alibaba.fastjson.JSONObject policy = policies.getJSONObject(0);
+        if(policy == null) {
+            handleInsuranceQuery(paiedAmount, "", insuranceDO.getOrderId(), "FAIL");
+        }
+        String status = policy.getString("status");
+        if("PROCESSING".equals(status)) {
+            log.error("保险查询结果,投保中,继续查询"+insuranceDO.getInsuranceNo());
+        } else if("FAIL".equals(status)) {
+            log.error("保险查询结果,投保失败,不再查询"+insuranceDO.getInsuranceNo());
+        } else if("SUCCESS".equals(status)) {
+            log.error("保险查询结果,投保成功,不再查询"+insuranceDO.getInsuranceNo());
+            Long externalPolicyNumber = policy.getLong("externalPolicyNumber");
+            String policyNo = policy.getString("policyNo");
+            handleInsuranceQuery(paiedAmount, policyNo, externalPolicyNumber, status);
+        }
     }
 
 
     @Override
     public void queryInsuranceQuey() {
         List<InsuranceDO> list = insuranceMapper.selectList(new LambdaQueryWrapper<InsuranceDO>().eq(InsuranceDO::getInsuranceStatus, 0).ge(InsuranceDO::getCreateTime, DateUtil.yesterday()));
-        list.forEach(insuranceDO -> insuranceUtil.queryInsurance(insuranceDO.getInsuranceNo()));
+        for (InsuranceDO insuranceDO : list) {
+            CommonResult commonResult = insuranceUtil.queryInsuranceNew(insuranceDO.getInsuranceNo(), insuranceDO.getOrderId());
+            if (!commonResult.isSuccess()) {
+                throw exception0(commonResult.getCode(), commonResult.getMsg());
+            }
+            //{"phase":"INSURE","externalOrderNo":"tys-20261001-YC-14",
+            // "paiedAmount":"10.00","total":"1","insuredCount":"1","insureProcessingCount":"0",
+            // "cancelledCount":"0","cancelProcessingCount":"0","refundedAmount":"0.0",
+            // "cipher":"26e2e422d370653274ee74ef3edc7f93","policies":[{"externalPolicyNumber":"2037220248460828673",
+            // "service":"applyTeam","status":"SUCCESS","msg":"投保成功","policyNo":"HW61927008L7JB7J8Q00"}]}
+            String checkedData = (String) commonResult.getCheckedData();
+            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(checkedData);
+            BigDecimal paiedAmount = jsonObject.getBigDecimal("paiedAmount");
+            JSONArray policies = jsonObject.getJSONArray("policies");
+            if(policies == null) {
+                handleInsuranceQuery(paiedAmount, "", insuranceDO.getOrderId(), "FAIL");
+            }
+            com.alibaba.fastjson.JSONObject policy = policies.getJSONObject(0);
+            if(policy == null) {
+                handleInsuranceQuery(paiedAmount, "", insuranceDO.getOrderId(), "FAIL");
+            }
+            String status = policy.getString("status");
+            if("PROCESSING".equals(status)) {
+                log.error("保险查询结果,投保中,继续查询"+insuranceDO.getInsuranceNo());
+            } else if("FAIL".equals(status)) {
+                log.error("保险查询结果,投保失败,不再查询"+insuranceDO.getInsuranceNo());
+            } else if("SUCCESS".equals(status)) {
+                log.error("保险查询结果,投保成功,不再查询"+insuranceDO.getInsuranceNo());
+                Long externalPolicyNumber = policy.getLong("externalPolicyNumber");
+                String policyNo = policy.getString("policyNo");
+                handleInsuranceQuery(paiedAmount, policyNo, externalPolicyNumber, status);
+            }
+        }
     }
 
     /**

+ 2 - 40
ship-module-trade/ship-module-trade-biz/src/main/java/com/yc/ship/module/trade/utils/InsuranceUtil.java

@@ -1,13 +1,11 @@
 package com.yc.ship.module.trade.utils;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.anji.captcha.util.MD5Util;
 import com.yc.ship.framework.common.pojo.CommonResult;
 import com.yc.ship.framework.common.util.http.HttpUtils;
 import com.yc.ship.module.trade.api.insurance.dto.InsuranceApplyReqDTO;
 import com.yc.ship.module.trade.api.insurance.dto.InsuranceCancelReqDTO;
-import com.yc.ship.module.trade.service.insurance.InsuranceService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.http.*;
@@ -16,9 +14,7 @@ import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 
-import javax.annotation.Resource;
 import java.io.UnsupportedEncodingException;
-import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -52,9 +48,6 @@ public class InsuranceUtil {
      */
     private RestTemplate restTemplate;
 
-    @Resource
-    private InsuranceService insuranceService;
-
     /**
      * 构造函数
      */
@@ -302,41 +295,10 @@ public class InsuranceUtil {
             params.add("externalOrderNo", orderNo);
             params.add("sign", sign);
             String url = HOST + QUERY_URL + "?appId=" + APPID + "&externalOrderNo=" + orderNo + "&sign=" + sign;
-            log.error("发送查询请求到阳光系统: {}", url);
+            log.error(orderNo+"发送查询请求到阳光系统: {}", url);
             String s = HttpUtils.get(url, null);
-            log.error("阳光系统查询响应内容: {}", s);
-            //{"phase":"INSURE","externalOrderNo":"tys-20261001-YC-14",
-            // "paiedAmount":"10.00","total":"1","insuredCount":"1","insureProcessingCount":"0",
-            // "cancelledCount":"0","cancelProcessingCount":"0","refundedAmount":"0.0",
-            // "cipher":"26e2e422d370653274ee74ef3edc7f93","policies":[{"externalPolicyNumber":"2037220248460828673",
-            // "service":"applyTeam","status":"SUCCESS","msg":"投保成功","policyNo":"HW61927008L7JB7J8Q00"}]}
+            log.error(orderNo+"阳光系统查询响应内容: {}", s);
 
-            String msg = "";
-            JSONObject jsonObject = JSONObject.parseObject(s);
-            BigDecimal paiedAmount = jsonObject.getBigDecimal("paiedAmount");
-            JSONArray policies = jsonObject.getJSONArray("policies");
-            if(policies == null) {
-                msg = "查询失败";
-                insuranceService.handleInsuranceQuery(paiedAmount, "", orderId, "FAIL");
-                return CommonResult.error(500, msg);
-            }
-            JSONObject policy = policies.getJSONObject(0);
-            if(policy == null) {
-                insuranceService.handleInsuranceQuery(paiedAmount, "", orderId, "FAIL");
-                return CommonResult.error(500, "查询失败");
-            }
-            String status = policy.getString("status");
-            if("PROCESSING".equals(status)) {
-                log.error("保险查询结果,投保中,继续查询");
-            } else if("FAIL".equals(status)) {
-                log.error("保险查询结果,投保失败,不再查询");
-                insuranceService.handleInsuranceQuery(paiedAmount, "", orderId, "FAIL");
-            } else if("SUCCESS".equals(status)) {
-                log.error("保险查询结果,投保成功,不再查询");
-                Long externalPolicyNumber = policy.getLong("externalPolicyNumber");
-                String policyNo = policy.getString("policyNo");
-                insuranceService.handleInsuranceQuery(paiedAmount, policyNo, externalPolicyNumber, status);
-            }
             return CommonResult.success(s);
         } catch (Exception e) {
             log.error("发送查询请求失败", e);