Parcourir la source

装货点和卸货点分段对比

zhaohui il y a 3 ans
Parent
commit
3844999511

+ 101 - 83
src/main/java/info/aspirecn/iov/sjjh/service/impl/VehicleServiceImpl.java

@@ -149,10 +149,6 @@ public class VehicleServiceImpl implements VehicleService {
                 ErrorUtils.captureException(e);
                 ret.setCode(Constant.FAIL);
             }
-        } else {
-            ret.setResultCode(Constant.UN_MATCH_CODE);
-            ret.setResultBody(result);
-            ret.setResultDesc(Constant.QUERY_SUCCESS);
         }
         return upstreamCode;
     }
@@ -175,7 +171,10 @@ public class VehicleServiceImpl implements VehicleService {
 
     private String vehiclePositionConsistencyTwoCheck(ChannelTypeHandleResponseObject ret, int outTime,
                                                       VehicleHistoryPositionRequestParam requestParam){
-        String upstreamCode = "";
+        ChannelTypeHandleResponseObject retA = new ChannelTypeHandleResponseObject();
+        ChannelTypeHandleResponseObject retB = new ChannelTypeHandleResponseObject();
+        String upstreamCodeA = "";
+        String upstreamCodeB = "";
         /**
          * 1、云雁分调取A-到A+和B-到B+的轨迹,并取这两段轨迹中的每个点的行政区划代码合集X和合集Y
          * 2、将合集X分别与A点行政区划进行比对,只要有一点比对一致则视为此点核验通过
@@ -212,106 +211,125 @@ public class VehicleServiceImpl implements VehicleService {
             ErrorUtils.captureException(e);
             ret.setCode(Constant.FAIL);
         }
-
+        List<String> errList = new ArrayList<>();
         if (responseA.getStatusCode() == Constants.STATUS_CODE_200) {
             VehicleHistoryPositionResponse positionResponseA = JSON.toJavaObject(JSON.parseObject(responseA.getBody()),
                     VehicleHistoryPositionResponse.class);
-            upstreamCode = positionResponseA.getResultCode();
+            upstreamCodeA = positionResponseA.getResultCode();
             if (positionResponseA.getResultCode().equals(Constants.RESULT_CODE_0)) {
                 if (positionResponseA.getData() != null && positionResponseA.getData().size() > 0) {
                     String resultA = vehiclePositionConsistencyACheck(positionResponseA.getData(), requestParam);
                     if (StringUtils.isBlank(resultA)) {
-                        ret.setResultCode(Constant.MATCH_CODE);
-                        ret.setResultBody(Constant.MATCH);
-                        ret.setResultDesc(Constant.QUERY_SUCCESS);
+                        retA.setResultCode(Constant.MATCH_CODE);
+                        retA.setResultBody(Constant.MATCH);
+                        retA.setResultDesc(Constant.QUERY_SUCCESS);
                     } else {
-                        ret.setResultCode(Constant.UN_MATCH_CODE);
-                        ret.setResultBody(resultA);
-                        ret.setResultDesc(Constant.QUERY_SUCCESS);
+                        errList.add(resultA);
+                        retA.setResultCode(Constant.UN_MATCH_CODE);
+                        retA.setResultBody(errList);
+                        retA.setResultDesc(Constant.QUERY_SUCCESS);
                     }
                 } else {
-                    ret.setResultCode(Constant.UN_FIND_NUM_CODE);
-                    ret.setResultBody(Constants.NO_RESULT);
-                    ret.setResultDesc(Constants.NO_RESULT);
+                    retA.setResultCode(Constant.UN_FIND_NUM_CODE);
+                    retA.setResultBody(Constants.NO_RESULT);
+                    retA.setResultDesc(Constants.NO_RESULT);
                 }
-                ret.setIsCharge(Constant.IS_CHARGE);
+                retA.setIsCharge(Constant.IS_CHARGE);
             } else if (positionResponseA.getResultCode().equals(Constants.RESULT_CODE_110000)) {
-                ret.setResultCode(Constant.UN_FIND_NUM_CODE);
-                ret.setResultBody(Constants.NO_RESULT);
-                ret.setResultDesc(Constants.NO_RESULT);
+                retA.setResultCode(Constant.UN_FIND_NUM_CODE);
+                retA.setResultBody(Constants.NO_RESULT);
+                retA.setResultDesc(Constants.NO_RESULT);
             } else {
-                ret.setResultCode(Constant.OTHER_ERROR_CODE);
-                ret.setResultBody(Constant.OTHER_ERROR);
-                ret.setResultDesc(Constant.OTHER_ERROR);
+                retA.setResultCode(Constant.OTHER_ERROR_CODE);
+                retA.setResultBody(Constant.OTHER_ERROR);
+                retA.setResultDesc(Constant.OTHER_ERROR);
             }
         } else {
-            ret.setResultCode(Constant.OTHER_ERROR_CODE);
-            ret.setResultBody(Constant.OTHER_ERROR);
-            ret.setResultDesc(Constant.OTHER_ERROR);
-            upstreamCode = Integer.toString(responseA.getStatusCode());
+            retA.setResultCode(Constant.OTHER_ERROR_CODE);
+            retA.setResultBody(Constant.OTHER_ERROR);
+            retA.setResultDesc(Constant.OTHER_ERROR);
+            upstreamCodeA = Integer.toString(responseA.getStatusCode());
+        }
+        // B段接口调用
+        Response responseB = new Response();
+        try {
+            RequestObject requestObject = new RequestObject();
+            requestObject.setVehicleNumber(requestParam.getPlateNumber());
+            requestObject.setLicensePlateTypeCode(requestParam.getPlateColor());
+            requestObject.setStartTime(startTimeB);
+            requestObject.setEndTime(endTimeB);
+            requestObject.setPartyFunctionCode(supplierConfig.getPartyFunctionCode());
+            responseB = PostUtil.postString(supplierConfig.getHistoryPositionUrl(), JSON.toJSONString(requestObject),
+                    supplierConfig.getAppKey(), supplierConfig.getAppSecret(), outTime);
+        } catch (IOException e) {
+            log.info("supplier-vehicle.vehicleHistoryAPositionQuery-IOException:{}", e);
+            ErrorUtils.captureException(e);
+            ret.setCode(Constant.REQUEST_TIMEOUT);
+        } catch (Exception e) {
+            log.info("supplier-vehicle.vehicleHistoryAPositionQuery-Exception:{}", e);
+            ErrorUtils.captureException(e);
+            ret.setCode(Constant.FAIL);
         }
-        //A段成功
-        if(ret.getResultCode()==Constant.MATCH_CODE){
-            // B段接口调用
-            Response responseB = new Response();
-            try {
-                RequestObject requestObject = new RequestObject();
-                requestObject.setVehicleNumber(requestParam.getPlateNumber());
-                requestObject.setLicensePlateTypeCode(requestParam.getPlateColor());
-                requestObject.setStartTime(startTimeB);
-                requestObject.setEndTime(endTimeB);
-                requestObject.setPartyFunctionCode(supplierConfig.getPartyFunctionCode());
-                responseB = PostUtil.postString(supplierConfig.getHistoryPositionUrl(), JSON.toJSONString(requestObject),
-                        supplierConfig.getAppKey(), supplierConfig.getAppSecret(), outTime);
-            } catch (IOException e) {
-                log.info("supplier-vehicle.vehicleHistoryAPositionQuery-IOException:{}", e);
-                ErrorUtils.captureException(e);
-                ret.setCode(Constant.REQUEST_TIMEOUT);
-            } catch (Exception e) {
-                log.info("supplier-vehicle.vehicleHistoryAPositionQuery-Exception:{}", e);
-                ErrorUtils.captureException(e);
-                ret.setCode(Constant.FAIL);
-            }
 
-            if (responseB.getStatusCode() == Constants.STATUS_CODE_200) {
-                VehicleHistoryPositionResponse positionResponseB = JSON.toJavaObject(JSON.parseObject(responseB.getBody()),
-                        VehicleHistoryPositionResponse.class);
-                upstreamCode = positionResponseB.getResultCode();
-                if (positionResponseB.getResultCode().equals(Constants.RESULT_CODE_0)) {
-                    if (positionResponseB.getData() != null && positionResponseB.getData().size() > 0) {
-                        String resultB = vehiclePositionConsistencyBCheck(positionResponseB.getData(), requestParam);
-                        if (StringUtils.isBlank(resultB)) {
-                            ret.setResultCode(Constant.MATCH_CODE);
-                            ret.setResultBody(Constant.MATCH);
-                            ret.setResultDesc(Constant.QUERY_SUCCESS);
-                        } else {
-                            ret.setResultCode(Constant.UN_MATCH_CODE);
-                            ret.setResultBody(resultB);
-                            ret.setResultDesc(Constant.QUERY_SUCCESS);
-                        }
+        if (responseB.getStatusCode() == Constants.STATUS_CODE_200) {
+            VehicleHistoryPositionResponse positionResponseB = JSON.toJavaObject(JSON.parseObject(responseB.getBody()),
+                    VehicleHistoryPositionResponse.class);
+            upstreamCodeB = positionResponseB.getResultCode();
+            if (positionResponseB.getResultCode().equals(Constants.RESULT_CODE_0)) {
+                if (positionResponseB.getData() != null && positionResponseB.getData().size() > 0) {
+                    String resultB = vehiclePositionConsistencyBCheck(positionResponseB.getData(), requestParam);
+                    if (StringUtils.isBlank(resultB)) {
+                        retB.setResultCode(Constant.MATCH_CODE);
+                        retB.setResultBody(Constant.MATCH);
+                        retB.setResultDesc(Constant.QUERY_SUCCESS);
                     } else {
-                        ret.setResultCode(Constant.UN_FIND_NUM_CODE);
-                        ret.setResultBody(Constants.NO_RESULT);
-                        ret.setResultDesc(Constants.NO_RESULT);
+                        errList.add(resultB);
+                        retB.setResultCode(Constant.UN_MATCH_CODE);
+                        retB.setResultBody(errList);
+                        retB.setResultDesc(Constant.QUERY_SUCCESS);
                     }
-                    ret.setIsCharge(Constant.IS_CHARGE);
-                } else if (positionResponseB.getResultCode().equals(Constants.RESULT_CODE_110000)) {
-                    ret.setResultCode(Constant.UN_FIND_NUM_CODE);
-                    ret.setResultBody(Constants.NO_RESULT);
-                    ret.setResultDesc(Constants.NO_RESULT);
                 } else {
-                    ret.setResultCode(Constant.OTHER_ERROR_CODE);
-                    ret.setResultBody(Constant.OTHER_ERROR);
-                    ret.setResultDesc(Constant.OTHER_ERROR);
+                    retB.setResultCode(Constant.UN_FIND_NUM_CODE);
+                    retB.setResultBody(Constants.NO_RESULT);
+                    retB.setResultDesc(Constants.NO_RESULT);
                 }
+                ret.setIsCharge(Constant.IS_CHARGE);
+            } else if (positionResponseB.getResultCode().equals(Constants.RESULT_CODE_110000)) {
+                retB.setResultCode(Constant.UN_FIND_NUM_CODE);
+                retB.setResultBody(Constants.NO_RESULT);
+                retB.setResultDesc(Constants.NO_RESULT);
             } else {
-                ret.setResultCode(Constant.OTHER_ERROR_CODE);
-                ret.setResultBody(Constant.OTHER_ERROR);
-                ret.setResultDesc(Constant.OTHER_ERROR);
-                upstreamCode = Integer.toString(responseA.getStatusCode());
+                retB.setResultCode(Constant.OTHER_ERROR_CODE);
+                retB.setResultBody(Constant.OTHER_ERROR);
+                retB.setResultDesc(Constant.OTHER_ERROR);
             }
+        } else {
+            retB.setResultCode(Constant.OTHER_ERROR_CODE);
+            retB.setResultBody(Constant.OTHER_ERROR);
+            retB.setResultDesc(Constant.OTHER_ERROR);
+            upstreamCodeB = Integer.toString(responseA.getStatusCode());
+        }
+
+        if(retA.getResultCode()==Constant.MATCH_CODE&&retB.getResultCode()==Constant.MATCH_CODE){
+            return upstreamCodeA;
+        }
+        if(errList.size()>0){
+            ret.setResultCode(Constant.UN_MATCH_CODE);
+            ret.setResultBody(errList);
+            ret.setResultDesc(Constant.QUERY_SUCCESS);
+            return upstreamCodeA;
+        }
+        if(retA.getResultCode()>=retB.getResultCode()){
+            ret.setResultCode(retA.getResultCode());
+            ret.setResultDesc(retA.getResultDesc());
+            ret.setResultBody("loadingCountrySubdivisionCode");
+            return upstreamCodeA;
+        }else{
+            ret.setResultCode(retB.getResultCode());
+            ret.setResultDesc(retB.getResultDesc());
+            ret.setResultBody("receiptCountrySubdivisionCode");
+            return upstreamCodeB;
         }
-        return upstreamCode;
     }
 
     private String vehiclePositionConsistencyACheck(List<VehicleHistoryPositionResponse.Data> positionList,
@@ -326,7 +344,7 @@ public class VehicleServiceImpl implements VehicleService {
             }
         }
         if (!checkResultA) {
-            return "loadingCountrySubdivisionCode与数据源不一致";
+            return "loadingCountrySubdivisionCode";
         }
         return "";
     }
@@ -343,7 +361,7 @@ public class VehicleServiceImpl implements VehicleService {
             }
         }
         if (!checkResultB) {
-            return "receiptCountrySubdivisionCode与数据源不一致";
+            return "receiptCountrySubdivisionCode";
         }
         return "";
     }