1、修改同步组织
2、新增北斗定位
This commit is contained in:
@@ -31,6 +31,10 @@
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-transport-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-lbs-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-user-api</artifactId>
|
||||
|
||||
+19
@@ -53,6 +53,8 @@ import org.springblade.transport.pojo.dto.WaybillImportBatchRequest;
|
||||
import org.springblade.transport.pojo.vo.BusinessRemoveResultVO;
|
||||
import org.springblade.transport.pojo.vo.LoadingManageVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillImportBatchVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillLocateVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillTrackVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillPunchRecordsVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillVO;
|
||||
import org.springblade.transport.pojo.dto.WaybillMileageRequest;
|
||||
@@ -109,6 +111,23 @@ public class WaybillController extends BladeController {
|
||||
return R.data(waybillService.listPunchRecords(waybillId));
|
||||
}
|
||||
|
||||
@PostMapping("/locate")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "车辆实时定位", description = "按运单绑定车牌调用 LBS_LOCATE")
|
||||
public R<WaybillLocateVO> locate(@Parameter(description = "运单ID", required = true) @RequestParam Long id) {
|
||||
return R.data(waybillService.locateVehicle(id));
|
||||
}
|
||||
|
||||
@PostMapping("/track")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "车辆历史轨迹", description = "按运单绑定车牌 + 日期区间调用 LBS_LOCATE")
|
||||
public R<WaybillTrackVO> track(
|
||||
@Parameter(description = "运单ID", required = true) @RequestParam Long id,
|
||||
@Parameter(description = "开始日期 YYYY-MM-DD", required = true) @RequestParam String startDate,
|
||||
@Parameter(description = "结束日期 YYYY-MM-DD", required = true) @RequestParam String endDate) {
|
||||
return R.data(waybillService.trackVehicle(id, startDate, endDate));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "分页", description = "传入waybill")
|
||||
|
||||
+20
@@ -28,6 +28,8 @@ import org.springblade.transport.excel.WaybillExcel;
|
||||
import org.springblade.transport.pojo.entity.Waybill;
|
||||
import org.springblade.transport.pojo.vo.BusinessRemoveResultVO;
|
||||
import org.springblade.transport.pojo.vo.LoadingManageVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillLocateVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillTrackVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillPunchRecordsVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillVO;
|
||||
import org.springblade.transport.pojo.dto.WaybillMileageRequest;
|
||||
@@ -49,6 +51,24 @@ public interface IWaybillService extends BaseService<Waybill> {
|
||||
*/
|
||||
WaybillPunchRecordsVO listPunchRecords(Long waybillId);
|
||||
|
||||
/**
|
||||
* 运单车辆实时定位(按运单绑定车牌调用 LBS)
|
||||
*
|
||||
* @param id 运单ID
|
||||
* @return 定位结果
|
||||
*/
|
||||
WaybillLocateVO locateVehicle(Long id);
|
||||
|
||||
/**
|
||||
* 运单历史轨迹回放(按运单绑定车牌 + 日期区间调用 LBS)
|
||||
*
|
||||
* @param id 运单ID
|
||||
* @param startDate 开始日期 YYYY-MM-DD
|
||||
* @param endDate 结束日期 YYYY-MM-DD
|
||||
* @return 轨迹结果
|
||||
*/
|
||||
WaybillTrackVO trackVehicle(Long id, String startDate, String endDate);
|
||||
|
||||
Waybill syncDriverAcceptState(Waybill waybill);
|
||||
boolean submit(Waybill waybill);
|
||||
boolean saveDraft(Waybill waybill);
|
||||
|
||||
+197
-3
@@ -25,6 +25,7 @@ package org.springblade.transport.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
@@ -32,10 +33,10 @@ import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.system.cache.UserCache;
|
||||
import org.springblade.system.pojo.entity.Dept;
|
||||
import org.springblade.thirdparty.lbs.feign.ILbsClient;
|
||||
import org.springblade.thirdparty.lbs.pojo.dto.LbsLocateRequest;
|
||||
import org.springblade.thirdparty.lbs.pojo.vo.LbsLocateResponse;
|
||||
import org.springblade.transport.excel.WaybillExcel;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import org.springblade.transport.mapper.WaybillEnroutePunchMapper;
|
||||
import org.springblade.transport.mapper.WaybillMapper;
|
||||
import org.springblade.transport.mapper.WaybillNodePunchMapper;
|
||||
@@ -49,6 +50,8 @@ import org.springblade.transport.pojo.entity.WaybillNodePunch;
|
||||
import org.springblade.transport.pojo.dto.WaybillMileageRequest;
|
||||
import org.springblade.transport.pojo.vo.BusinessRemoveResultVO;
|
||||
import org.springblade.transport.pojo.vo.LoadingManageVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillLocateVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillTrackVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillPunchPhotoVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillPunchRecordItemVO;
|
||||
import org.springblade.transport.pojo.vo.WaybillPunchRecordsVO;
|
||||
@@ -67,7 +70,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -111,6 +118,9 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
|
||||
@jakarta.annotation.Resource
|
||||
private WaybillEnroutePunchMapper waybillEnroutePunchMapper;
|
||||
|
||||
@jakarta.annotation.Resource
|
||||
private ILbsClient lbsClient;
|
||||
|
||||
@Override
|
||||
public IPage<WaybillVO> selectWaybillPage(IPage<Waybill> page, WaybillVO waybill) {
|
||||
IPage<Waybill> entityPage = page(page, buildQuery(waybill));
|
||||
@@ -128,6 +138,190 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
if (pointMaps.isEmpty()) {
|
||||
throw new ServiceException("暂无车辆实时定位数据");
|
||||
}
|
||||
return buildLocateVO(id, vehicleNo, pointMaps.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaybillTrackVO trackVehicle(Long id, String startDate, String endDate) {
|
||||
Waybill waybill = requireWaybillWithVehicleNo(id, "无法查询历史轨迹");
|
||||
String vehicleNo = waybill.getVehicleNo().trim();
|
||||
String normalizedStart = normalizeTrackDate(startDate, "开始日期");
|
||||
String normalizedEnd = normalizeTrackDate(endDate, "结束日期");
|
||||
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());
|
||||
WaybillTrackVO trackVO = new WaybillTrackVO();
|
||||
trackVO.setWaybillId(id);
|
||||
trackVO.setVehicleNo(vehicleNo);
|
||||
trackVO.setStartDate(normalizedStart);
|
||||
trackVO.setEndDate(normalizedEnd);
|
||||
List<WaybillTrackVO.WaybillTrackPointVO> points = new ArrayList<>();
|
||||
for (Map<String, Object> pointMap : pointMaps) {
|
||||
WaybillTrackVO.WaybillTrackPointVO point = buildTrackPoint(vehicleNo, pointMap);
|
||||
if (point.getLongitude() != null && point.getLatitude() != null) {
|
||||
points.add(point);
|
||||
}
|
||||
}
|
||||
trackVO.setPoints(points);
|
||||
trackVO.setTotal(points.size());
|
||||
return trackVO;
|
||||
}
|
||||
|
||||
private Waybill requireWaybillWithVehicleNo(Long id, String actionTip) {
|
||||
if (id == null) {
|
||||
throw new ServiceException("运单ID不能为空");
|
||||
}
|
||||
Waybill waybill = getById(id);
|
||||
if (waybill == null || Objects.equals(waybill.getIsDeleted(), 1)) {
|
||||
throw new ServiceException("运单不存在");
|
||||
}
|
||||
String vehicleNo = Func.toStr(waybill.getVehicleNo(), "").trim();
|
||||
if (Func.isEmpty(vehicleNo)) {
|
||||
throw new ServiceException("运单未绑定车牌号," + actionTip);
|
||||
}
|
||||
waybill.setVehicleNo(vehicleNo);
|
||||
return waybill;
|
||||
}
|
||||
|
||||
private LbsLocateResponse invokeLbsLocate(Long waybillId, String vehicleNo, LbsLocateRequest request, String scene) {
|
||||
LbsLocateResponse response;
|
||||
try {
|
||||
response = lbsClient.locate(request);
|
||||
} catch (Exception exception) {
|
||||
log.error("调用LBS{}失败 waybillId={}, vehicleNo={}", scene, waybillId, vehicleNo, exception);
|
||||
throw new ServiceException("调用车辆" + scene + "接口失败");
|
||||
}
|
||||
if (response == null || !response.isSuccess()) {
|
||||
String errorMessage = response == null ? "车辆" + scene + "无返回" : response.errorMessage();
|
||||
throw new ServiceException(errorMessage);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private String normalizeTrackDate(String dateText, String fieldName) {
|
||||
if (Func.isEmpty(dateText)) {
|
||||
throw new ServiceException(fieldName + "不能为空");
|
||||
}
|
||||
String normalized = dateText.trim();
|
||||
try {
|
||||
return LocalDate.parse(normalized, DateTimeFormatter.ISO_LOCAL_DATE).toString();
|
||||
} catch (DateTimeParseException exception) {
|
||||
throw new ServiceException(fieldName + "格式必须为YYYY-MM-DD");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取 LBS 轨迹点列表,兼容 data 数组 或 data.list 数组
|
||||
*/
|
||||
private List<Map<String, Object>> extractLbsPointMaps(JsonNode dataNode) {
|
||||
List<Map<String, Object>> pointMaps = new ArrayList<>();
|
||||
if (dataNode == null || dataNode.isNull()) {
|
||||
return pointMaps;
|
||||
}
|
||||
JsonNode listNode = dataNode;
|
||||
if (dataNode.isObject() && dataNode.has("list")) {
|
||||
listNode = dataNode.get("list");
|
||||
}
|
||||
if (listNode != null && listNode.isArray()) {
|
||||
for (JsonNode item : listNode) {
|
||||
if (item != null && item.isObject()) {
|
||||
pointMaps.add(JsonUtil.toMap(item.toString()));
|
||||
}
|
||||
}
|
||||
return pointMaps;
|
||||
}
|
||||
if (dataNode.isObject()) {
|
||||
pointMaps.add(JsonUtil.toMap(dataNode.toString()));
|
||||
}
|
||||
return pointMaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 LBS 单点数据归一化为实时定位结果
|
||||
*/
|
||||
private WaybillLocateVO buildLocateVO(Long waybillId, String vehicleNo, Map<String, Object> pointMap) {
|
||||
WaybillLocateVO locateVO = new WaybillLocateVO();
|
||||
locateVO.setWaybillId(waybillId);
|
||||
locateVO.setVehicleNo(vehicleNo);
|
||||
locateVO.setRawData(pointMap);
|
||||
fillPointFields(locateVO, pointMap);
|
||||
return locateVO;
|
||||
}
|
||||
|
||||
private WaybillTrackVO.WaybillTrackPointVO buildTrackPoint(String vehicleNo, Map<String, Object> pointMap) {
|
||||
WaybillTrackVO.WaybillTrackPointVO point = new WaybillTrackVO.WaybillTrackPointVO();
|
||||
point.setVehicleNo(vehicleNo);
|
||||
fillPointFields(point, pointMap);
|
||||
return point;
|
||||
}
|
||||
|
||||
private void fillPointFields(WaybillLocateVO target, Map<String, Object> pointMap) {
|
||||
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.setDirection(firstText(pointMap, "direct", "direction", "h", "fx", "Direction", "FX", "course", "H"));
|
||||
String responseVehicleNo = firstText(pointMap, "cph", "vehicleNo", "plateNo", "CPH");
|
||||
if (Func.isNotEmpty(responseVehicleNo)) {
|
||||
target.setVehicleNo(responseVehicleNo);
|
||||
}
|
||||
}
|
||||
|
||||
private void fillPointFields(WaybillTrackVO.WaybillTrackPointVO target, Map<String, Object> pointMap) {
|
||||
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.setDirection(firstText(pointMap, "direct", "direction", "h", "fx", "Direction", "FX", "course", "H"));
|
||||
String responseVehicleNo = firstText(pointMap, "cph", "vehicleNo", "plateNo", "CPH");
|
||||
if (Func.isNotEmpty(responseVehicleNo)) {
|
||||
target.setVehicleNo(responseVehicleNo);
|
||||
}
|
||||
}
|
||||
|
||||
private BigDecimal firstDecimal(Map<String, Object> rawData, String... keys) {
|
||||
String text = firstText(rawData, keys);
|
||||
if (Func.isEmpty(text)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new BigDecimal(text.trim());
|
||||
} catch (NumberFormatException exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String firstText(Map<String, Object> rawData, String... keys) {
|
||||
if (rawData == null || rawData.isEmpty() || keys == null) {
|
||||
return null;
|
||||
}
|
||||
for (String key : keys) {
|
||||
Object value = rawData.get(key);
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
String text = String.valueOf(value).trim();
|
||||
if (Func.isNotEmpty(text) && !"null".equalsIgnoreCase(text)) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaybillPunchRecordsVO listPunchRecords(Long waybillId) {
|
||||
WaybillPunchRecordsVO vo = new WaybillPunchRecordsVO();
|
||||
|
||||
@@ -8,3 +8,10 @@ spring:
|
||||
url: ${blade.datasource.dev.url}
|
||||
username: ${blade.datasource.dev.username}
|
||||
password: ${blade.datasource.dev.password}
|
||||
|
||||
# LBS 车辆实时定位(Authorization 与 OA 人员接口一致)
|
||||
thirdParty:
|
||||
lbs:
|
||||
baseUrl: ${LBS_BASE_URL:http://172.16.204.83:38000}
|
||||
locateUrl: ${LBS_LOCATE_URL:/gwzh/LBS/LBS_LOCATE}
|
||||
authorization: ${LBS_AUTHORIZATION:${OA_AUTHORIZATION:${IAM_SSO_AUTHORIZATION:Z3d6aF90bXMtOVJJU0RVN1U6YW0yYkcwWnBJZ0RQZmtrSjNaZkZjUDBSaGFuSEtxQng=}}}
|
||||
|
||||
Reference in New Issue
Block a user