|
@@ -12,6 +12,7 @@ import info.aspirecn.iov.sjjh.entity.Response;
|
|
import info.aspirecn.iov.sjjh.entity.VehicleHistoryPositionRequestParam;
|
|
import info.aspirecn.iov.sjjh.entity.VehicleHistoryPositionRequestParam;
|
|
import info.aspirecn.iov.sjjh.entity.VehicleHistoryPositionResponse;
|
|
import info.aspirecn.iov.sjjh.entity.VehicleHistoryPositionResponse;
|
|
import info.aspirecn.iov.sjjh.entity.geocoding.GeocodingResponseObject;
|
|
import info.aspirecn.iov.sjjh.entity.geocoding.GeocodingResponseObject;
|
|
|
|
+import info.aspirecn.iov.sjjh.enums.VehicleHistoryPositionQueryType;
|
|
import info.aspirecn.iov.sjjh.service.VehicleService;
|
|
import info.aspirecn.iov.sjjh.service.VehicleService;
|
|
import info.aspirecn.iov.sjjh.util.DateUtil;
|
|
import info.aspirecn.iov.sjjh.util.DateUtil;
|
|
import info.aspirecn.iov.sjjh.util.PostUtil;
|
|
import info.aspirecn.iov.sjjh.util.PostUtil;
|
|
@@ -45,7 +46,8 @@ public class VehicleServiceImpl implements VehicleService {
|
|
private OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
|
|
private OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ChannelTypeHandleResponseObject vehicleHistoryPositionQuery(HttpServletRequest request, String customBody, int outTime) {
|
|
|
|
|
|
+ public ChannelTypeHandleResponseObject vehicleHistoryPositionQuery(HttpServletRequest request, String customBody,
|
|
|
|
+ int outTime, Integer type) {
|
|
ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
ret.setCode(Constant.SUCCESS);
|
|
ret.setCode(Constant.SUCCESS);
|
|
@@ -100,7 +102,15 @@ public class VehicleServiceImpl implements VehicleService {
|
|
ErrorUtils.captureException(e);
|
|
ErrorUtils.captureException(e);
|
|
ret.setCode(Constant.FAIL);
|
|
ret.setCode(Constant.FAIL);
|
|
}
|
|
}
|
|
- upstreamCode = setVehicleHistoryPositionQueryResponse(ret, response, requestParam);
|
|
|
|
|
|
+ if (type.equals(VehicleHistoryPositionQueryType.VEHICLE_HISTORY_POSITION_QUERY.getValue())) {
|
|
|
|
+ // 车辆轨迹核验
|
|
|
|
+ upstreamCode = setVehicleHistoryPositionQueryResponse(ret, response, requestParam);
|
|
|
|
+ } else {
|
|
|
|
+ // 车辆线上线下一致性验证
|
|
|
|
+ upstreamCode = setVehiclePositionConsistencyCheckResponse(ret, response, requestParam);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
@@ -116,7 +126,7 @@ public class VehicleServiceImpl implements VehicleService {
|
|
upstreamCode = positionResponse.getResultCode();
|
|
upstreamCode = positionResponse.getResultCode();
|
|
if (positionResponse.getResultCode().equals(Constants.RESULT_CODE_0)) {
|
|
if (positionResponse.getResultCode().equals(Constants.RESULT_CODE_0)) {
|
|
if (positionResponse.getData() != null && positionResponse.getData().size() > 0) {
|
|
if (positionResponse.getData() != null && positionResponse.getData().size() > 0) {
|
|
- String result = vehicleHistoryPositionQueryByBaidu(positionResponse.getData(), requestParam);
|
|
|
|
|
|
+ String result = vehicleHistoryPositionQuery(positionResponse.getData(), requestParam);
|
|
if (StringUtils.isBlank(result)) {
|
|
if (StringUtils.isBlank(result)) {
|
|
JSONObject vehicleLocationInfo = new JSONObject();
|
|
JSONObject vehicleLocationInfo = new JSONObject();
|
|
vehicleLocationInfo.put("vehicleLocationInfo", positionResponse.getData());
|
|
vehicleLocationInfo.put("vehicleLocationInfo", positionResponse.getData());
|
|
@@ -152,7 +162,7 @@ public class VehicleServiceImpl implements VehicleService {
|
|
return upstreamCode;
|
|
return upstreamCode;
|
|
}
|
|
}
|
|
|
|
|
|
- private String vehicleHistoryPositionQueryByBaidu(List<VehicleHistoryPositionResponse.Data> positionList,
|
|
|
|
|
|
+ private String vehicleHistoryPositionQuery(List<VehicleHistoryPositionResponse.Data> positionList,
|
|
VehicleHistoryPositionRequestParam requestParam) {
|
|
VehicleHistoryPositionRequestParam requestParam) {
|
|
/**
|
|
/**
|
|
* 1、云雁调取A-到B+之间所有的车辆轨迹(每30秒有一个经纬度数据)。
|
|
* 1、云雁调取A-到B+之间所有的车辆轨迹(每30秒有一个经纬度数据)。
|
|
@@ -237,32 +247,111 @@ public class VehicleServiceImpl implements VehicleService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 校验省区划代码是否一致
|
|
|
|
- */
|
|
|
|
- private Boolean getGeocodingCheck(int outTime, String location,String adcode) {
|
|
|
|
- try {
|
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
- String requestUrl = supplierConfig.getBaiduUrl() + "?ak="+ supplierConfig.getBaiduAk()
|
|
|
|
- + "&output=json&coordtype=wgs84ll&location=" + location;
|
|
|
|
- Request okRequest = new Request.Builder().get().url(requestUrl).build();
|
|
|
|
- OkHttpClient client = okHttpClient.newBuilder().connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
|
- .readTimeout(outTime, TimeUnit.MILLISECONDS).writeTimeout(outTime, TimeUnit.MILLISECONDS).build();
|
|
|
|
- okhttp3.Response response = client.newCall(okRequest).execute();
|
|
|
|
- String responseContext = response.body().string();
|
|
|
|
- GeocodingResponseObject responseObject = objectMapper.readValue(responseContext,
|
|
|
|
- GeocodingResponseObject.class);
|
|
|
|
- log.info("supplier-vehicle.getGeocodingCheck.responseObject={}", responseContext);
|
|
|
|
- if (responseObject!=null) {
|
|
|
|
- if (responseObject.getStatus()==0&&adcode.equals(responseObject.getResult().getAddressComponent().getAdcode())) {
|
|
|
|
- return true;
|
|
|
|
|
|
+ private String setVehiclePositionConsistencyCheckResponse(ChannelTypeHandleResponseObject ret, Response response,
|
|
|
|
+ VehicleHistoryPositionRequestParam requestParam) {
|
|
|
|
+ String upstreamCode = "";
|
|
|
|
+ log.info("supplier-vehicle.vehicleHistoryPositionCheck-responseStatus:{}", response.getStatusCode());
|
|
|
|
+ log.info("supplier-vehicle.vehicleHistoryPositionCheck-responseBody:{}", response.getBody());
|
|
|
|
+ if (response.getStatusCode() == Constants.STATUS_CODE_200) {
|
|
|
|
+ VehicleHistoryPositionResponse positionResponse = JSON.toJavaObject(JSON.parseObject(response.getBody()),
|
|
|
|
+ VehicleHistoryPositionResponse.class);
|
|
|
|
+ upstreamCode = positionResponse.getResultCode();
|
|
|
|
+ if (positionResponse.getResultCode().equals(Constants.RESULT_CODE_0)) {
|
|
|
|
+ if (positionResponse.getData() != null && positionResponse.getData().size() > 0) {
|
|
|
|
+ String result = vehiclePositionConsistencyCheck(positionResponse.getData(), requestParam);
|
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
|
+ ret.setResultBody(Constant.MATCH);
|
|
|
|
+ ret.setResultDesc(Constant.QUERY_SUCCESS);
|
|
|
|
+ } else {
|
|
|
|
+ ret.setResultCode(Constant.UN_MATCH_CODE);
|
|
|
|
+ ret.setResultBody(result);
|
|
|
|
+ ret.setResultDesc(Constant.QUERY_SUCCESS);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ret.setResultCode(Constant.UN_FIND_NUM_CODE);
|
|
|
|
+ ret.setResultBody(Constants.NO_RESULT);
|
|
|
|
+ ret.setResultDesc(Constants.NO_RESULT);
|
|
|
|
+ }
|
|
|
|
+ ret.setIsCharge(Constant.IS_CHARGE);
|
|
|
|
+ } else if (positionResponse.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);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
|
+ upstreamCode += response.getStatusCode();
|
|
|
|
+ }
|
|
|
|
+ return upstreamCode;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String vehiclePositionConsistencyCheck(List<VehicleHistoryPositionResponse.Data> positionList,
|
|
|
|
+ VehicleHistoryPositionRequestParam requestParam) {
|
|
|
|
+ /**
|
|
|
|
+ * 1、云雁调取A-到B+之间的车辆轨迹
|
|
|
|
+ * 2、将B点与B-到B+时间点内的行政区划代码做对比,得出比对结果一
|
|
|
|
+ * 将A点与A-到A+时间点内的行政区划代码做对比,得出比对结果二
|
|
|
|
+ * 3、核验结果有一个不一致的情况下返回不一致结果
|
|
|
|
+ * 4、核验结果一致的情况下一致结果
|
|
|
|
+ */
|
|
|
|
+ // A-
|
|
|
|
+ String startTimeA = DateUtil.addHours(requestParam.getStartTime(), supplierConfig.getReduceHours());
|
|
|
|
+ // B-
|
|
|
|
+ String startTimeB = DateUtil.addHours(requestParam.getEndTime(), supplierConfig.getReduceHours());
|
|
|
|
+
|
|
|
|
+ // 4小时*2=8小时(A-A+间隔),8小时*2=16个点(每半个小时取1个点)
|
|
|
|
+ int pointNumber = supplierConfig.getAddHours()*2*2;
|
|
|
|
+
|
|
|
|
+ List<String> checkTimeListA = new ArrayList<>();
|
|
|
|
+ String tempStartTime = startTimeA;
|
|
|
|
+ for (int i = 0; i < pointNumber+1; i++) {
|
|
|
|
+ checkTimeListA.add(tempStartTime);
|
|
|
|
+ tempStartTime = DateUtil.addMinutes(tempStartTime, 30);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<String> checkTimeListB = new ArrayList<>();
|
|
|
|
+ tempStartTime = startTimeB;
|
|
|
|
+ for (int i = 0; i < pointNumber+1; i++) {
|
|
|
|
+ checkTimeListB.add(tempStartTime);
|
|
|
|
+ tempStartTime = DateUtil.addMinutes(tempStartTime, 30);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // todo 这个集合为了查看位置是否正确
|
|
|
|
+ List<VehicleHistoryPositionResponse.Data> verificationPositionListA = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < checkTimeListA.size()-1; i++) {
|
|
|
|
+ for (VehicleHistoryPositionResponse.Data position : positionList) {
|
|
|
|
+ if (Long.parseLong(position.getPositionTime()) > Long.parseLong(checkTimeListA.get(i))
|
|
|
|
+ && Long.parseLong(position.getPositionTime()) <= Long.parseLong(checkTimeListA.get(i+1))) {
|
|
|
|
+ verificationPositionListA.add(position);
|
|
|
|
+ if (!requestParam.getLoadingCountrySubdivisionCode().equals(position.getPositionDescribe())) {
|
|
|
|
+ return "loadingCountrySubdivisionCode";
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // todo 这个集合为了查看位置是否正确
|
|
|
|
+ List<VehicleHistoryPositionResponse.Data> verificationPositionListB = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < checkTimeListB.size()-1; i++) {
|
|
|
|
+ for (VehicleHistoryPositionResponse.Data position : positionList) {
|
|
|
|
+ if (Long.parseLong(position.getPositionTime()) > Long.parseLong(checkTimeListB.get(i))
|
|
|
|
+ && Long.parseLong(position.getPositionTime()) <= Long.parseLong(checkTimeListB.get(i+1))) {
|
|
|
|
+ verificationPositionListB.add(position);
|
|
|
|
+ if (!requestParam.getReceiptCountrySubdivisionCode().equals(position.getPositionDescribe())) {
|
|
|
|
+ return "receiptCountrySubdivisionCode";
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return false;
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- ErrorUtils.captureException(e);
|
|
|
|
- log.info("supplier-vehicle.Exception.e={}", e);
|
|
|
|
}
|
|
}
|
|
- return false;
|
|
|
|
|
|
+ return "";
|
|
}
|
|
}
|
|
}
|
|
}
|