调整定位
This commit is contained in:
+1
-1
@@ -120,7 +120,7 @@ public class WaybillController extends BladeController {
|
||||
|
||||
@PostMapping("/track")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "车辆历史轨迹", description = "按运单绑定车牌 + 日期区间调用 LBS_LOCATE")
|
||||
@Operation(summary = "车辆历史轨迹", description = "按运单绑定车牌 + 日期区间调用 LBS_TRACK")
|
||||
public R<WaybillTrackVO> track(
|
||||
@Parameter(description = "运单ID", required = true) @RequestParam Long id,
|
||||
@Parameter(description = "开始日期 YYYY-MM-DD", required = true) @RequestParam String startDate,
|
||||
|
||||
+52
-25
@@ -142,8 +142,8 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
|
||||
public WaybillLocateVO locateVehicle(Long id) {
|
||||
Waybill waybill = requireWaybillWithVehicleNo(id, "无法实时定位");
|
||||
String vehicleNo = waybill.getVehicleNo().trim();
|
||||
LbsLocateResponse response = invokeLbsLocate(id, vehicleNo, new LbsLocateRequest(vehicleNo), "实时定位");
|
||||
List<Map<String, Object>> pointMaps = extractLbsPointMaps(response.getData());
|
||||
LbsLocateResponse response = invokeLbs(id, vehicleNo, new LbsLocateRequest(vehicleNo), false, "实时定位");
|
||||
List<Map<String, Object>> pointMaps = extractLbsPointMaps(response);
|
||||
if (pointMaps.isEmpty()) {
|
||||
throw new ServiceException("暂无车辆实时定位数据");
|
||||
}
|
||||
@@ -159,9 +159,9 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
|
||||
if (LocalDate.parse(normalizedStart).isAfter(LocalDate.parse(normalizedEnd))) {
|
||||
throw new ServiceException("开始日期不能晚于结束日期");
|
||||
}
|
||||
LbsLocateResponse response = invokeLbsLocate(id, vehicleNo,
|
||||
new LbsLocateRequest(vehicleNo, normalizedStart, normalizedEnd), "历史轨迹");
|
||||
List<Map<String, Object>> pointMaps = extractLbsPointMaps(response.getData());
|
||||
LbsLocateResponse response = invokeLbs(id, vehicleNo,
|
||||
new LbsLocateRequest(vehicleNo, normalizedStart, normalizedEnd), true, "历史轨迹");
|
||||
List<Map<String, Object>> pointMaps = extractLbsPointMaps(response);
|
||||
WaybillTrackVO trackVO = new WaybillTrackVO();
|
||||
trackVO.setWaybillId(id);
|
||||
trackVO.setVehicleNo(vehicleNo);
|
||||
@@ -195,10 +195,11 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
|
||||
return waybill;
|
||||
}
|
||||
|
||||
private LbsLocateResponse invokeLbsLocate(Long waybillId, String vehicleNo, LbsLocateRequest request, String scene) {
|
||||
private LbsLocateResponse invokeLbs(Long waybillId, String vehicleNo, LbsLocateRequest request,
|
||||
boolean trackMode, String scene) {
|
||||
LbsLocateResponse response;
|
||||
try {
|
||||
response = lbsClient.locate(request);
|
||||
response = trackMode ? lbsClient.track(request) : lbsClient.locate(request);
|
||||
} catch (Exception exception) {
|
||||
log.error("调用LBS{}失败 waybillId={}, vehicleNo={}", scene, waybillId, vehicleNo, exception);
|
||||
throw new ServiceException("调用车辆" + scene + "接口失败");
|
||||
@@ -223,29 +224,55 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取 LBS 轨迹点列表,兼容 data 数组 或 data.list 数组
|
||||
* 提取 LBS 轨迹点:优先 list,其次 obj,再兼容 data / data.list / data.obj
|
||||
*/
|
||||
private List<Map<String, Object>> extractLbsPointMaps(JsonNode dataNode) {
|
||||
private List<Map<String, Object>> extractLbsPointMaps(LbsLocateResponse response) {
|
||||
List<Map<String, Object>> pointMaps = new ArrayList<>();
|
||||
if (dataNode == null || dataNode.isNull()) {
|
||||
if (response == null) {
|
||||
return pointMaps;
|
||||
}
|
||||
JsonNode listNode = dataNode;
|
||||
if (dataNode.isObject() && dataNode.has("list")) {
|
||||
listNode = dataNode.get("list");
|
||||
appendLbsNodes(pointMaps, response.getList());
|
||||
if (!pointMaps.isEmpty()) {
|
||||
return pointMaps;
|
||||
}
|
||||
if (listNode != null && listNode.isArray()) {
|
||||
for (JsonNode item : listNode) {
|
||||
appendLbsNodes(pointMaps, response.getObj());
|
||||
if (!pointMaps.isEmpty()) {
|
||||
return pointMaps;
|
||||
}
|
||||
JsonNode dataNode = response.getData();
|
||||
if (dataNode != null && !dataNode.isNull()) {
|
||||
if (dataNode.isObject() && dataNode.has("list")) {
|
||||
appendLbsNodes(pointMaps, dataNode.get("list"));
|
||||
if (!pointMaps.isEmpty()) {
|
||||
return pointMaps;
|
||||
}
|
||||
}
|
||||
if (dataNode.isObject() && dataNode.has("obj")) {
|
||||
appendLbsNodes(pointMaps, dataNode.get("obj"));
|
||||
if (!pointMaps.isEmpty()) {
|
||||
return pointMaps;
|
||||
}
|
||||
}
|
||||
appendLbsNodes(pointMaps, dataNode);
|
||||
}
|
||||
return pointMaps;
|
||||
}
|
||||
|
||||
private void appendLbsNodes(List<Map<String, Object>> pointMaps, JsonNode node) {
|
||||
if (node == null || node.isNull()) {
|
||||
return;
|
||||
}
|
||||
if (node.isArray()) {
|
||||
for (JsonNode item : node) {
|
||||
if (item != null && item.isObject()) {
|
||||
pointMaps.add(JsonUtil.toMap(item.toString()));
|
||||
}
|
||||
}
|
||||
return pointMaps;
|
||||
return;
|
||||
}
|
||||
if (dataNode.isObject()) {
|
||||
pointMaps.add(JsonUtil.toMap(dataNode.toString()));
|
||||
if (node.isObject()) {
|
||||
pointMaps.add(JsonUtil.toMap(node.toString()));
|
||||
}
|
||||
return pointMaps;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,10 +298,10 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
|
||||
target.setLongitude(firstDecimal(pointMap, "longitude", "lon", "lng", "x", "jd", "Longitude", "LON", "LNG", "JD", "X"));
|
||||
target.setLatitude(firstDecimal(pointMap, "latitude", "lat", "y", "wd", "Latitude", "LAT", "WD", "Y"));
|
||||
target.setAddress(firstText(pointMap, "address", "addr", "adr", "wz", "Address", "ADDR", "ADR"));
|
||||
target.setLocateTime(firstText(pointMap, "locationTime", "pos_time", "locateTime", "gpsTime", "gpstime", "time", "gpszdsj", "GPSTime", "Time"));
|
||||
target.setSpeed(firstText(pointMap, "speed", "v", "sd", "Speed", "SD", "V"));
|
||||
target.setLocateTime(firstText(pointMap, "utc", "locationTime", "pos_time", "locateTime", "gpsTime", "gpstime", "time", "gpszdsj", "GPSTime", "Time"));
|
||||
target.setSpeed(firstText(pointMap, "spd", "speed", "v", "sd", "Speed", "SD", "V"));
|
||||
target.setDirection(firstText(pointMap, "direct", "direction", "h", "fx", "Direction", "FX", "course", "H"));
|
||||
String responseVehicleNo = firstText(pointMap, "cph", "vehicleNo", "plateNo", "CPH");
|
||||
String responseVehicleNo = firstText(pointMap, "vno", "cph", "vehicleNo", "plateNo", "CPH", "VNO");
|
||||
if (Func.isNotEmpty(responseVehicleNo)) {
|
||||
target.setVehicleNo(responseVehicleNo);
|
||||
}
|
||||
@@ -284,10 +311,10 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
|
||||
target.setLongitude(firstDecimal(pointMap, "longitude", "lon", "lng", "x", "jd", "Longitude", "LON", "LNG", "JD", "X"));
|
||||
target.setLatitude(firstDecimal(pointMap, "latitude", "lat", "y", "wd", "Latitude", "LAT", "WD", "Y"));
|
||||
target.setAddress(firstText(pointMap, "address", "addr", "adr", "wz", "Address", "ADDR", "ADR"));
|
||||
target.setLocateTime(firstText(pointMap, "locationTime", "pos_time", "locateTime", "gpsTime", "gpstime", "time", "gpszdsj", "GPSTime", "Time"));
|
||||
target.setSpeed(firstText(pointMap, "speed", "v", "sd", "Speed", "SD", "V"));
|
||||
target.setLocateTime(firstText(pointMap, "utc", "locationTime", "pos_time", "locateTime", "gpsTime", "gpstime", "time", "gpszdsj", "GPSTime", "Time"));
|
||||
target.setSpeed(firstText(pointMap, "spd", "speed", "v", "sd", "Speed", "SD", "V"));
|
||||
target.setDirection(firstText(pointMap, "direct", "direction", "h", "fx", "Direction", "FX", "course", "H"));
|
||||
String responseVehicleNo = firstText(pointMap, "cph", "vehicleNo", "plateNo", "CPH");
|
||||
String responseVehicleNo = firstText(pointMap, "vno", "cph", "vehicleNo", "plateNo", "CPH", "VNO");
|
||||
if (Func.isNotEmpty(responseVehicleNo)) {
|
||||
target.setVehicleNo(responseVehicleNo);
|
||||
}
|
||||
|
||||
@@ -14,4 +14,5 @@ thirdParty:
|
||||
lbs:
|
||||
baseUrl: ${LBS_BASE_URL:http://172.16.204.83:38000}
|
||||
locateUrl: ${LBS_LOCATE_URL:/gwzh/LBS/LBS_LOCATE}
|
||||
trackUrl: ${LBS_TRACK_URL:/gwzh/LBS/LBS_TRACK}
|
||||
authorization: ${LBS_AUTHORIZATION:${OA_AUTHORIZATION:${IAM_SSO_AUTHORIZATION:Z3d6aF90bXMtOVJJU0RVN1U6YW0yYkcwWnBJZ0RQZmtrSjNaZkZjUDBSaGFuSEtxQng=}}}
|
||||
|
||||
Reference in New Issue
Block a user