|
|
@@ -14,6 +14,7 @@ import com.sckw.core.model.enums.AddressTypeEnum;
|
|
|
import com.sckw.core.model.enums.CarWaybillEnum;
|
|
|
import com.sckw.core.model.enums.CarWaybillV1Enum;
|
|
|
import com.sckw.core.utils.DateUtils;
|
|
|
+import com.sckw.core.utils.LocUtils;
|
|
|
import com.sckw.core.web.constant.CommonConstants;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
import com.sckw.core.web.response.BaseIotResult;
|
|
|
@@ -33,6 +34,7 @@ import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
import com.sckw.system.api.model.dto.res.KwsEnterpriseResDto;
|
|
|
import com.sckw.system.api.model.dto.res.SysDictResDto;
|
|
|
+import com.sckw.transport.api.model.vo.RWaybillOrderVo;
|
|
|
import com.sckw.transport.common.config.UrlConfigProperties;
|
|
|
import com.sckw.transport.model.*;
|
|
|
import com.sckw.transport.model.dto.TruckDto;
|
|
|
@@ -1467,7 +1469,41 @@ public class kwfTruckTraceService {
|
|
|
if (Objects.isNull(subOrders)){
|
|
|
throw new BusinessException("子运单不存在");
|
|
|
}
|
|
|
-
|
|
|
+ //查询运单装卸货地址
|
|
|
+ List<KwtWaybillOrderAddress> addressList = kwtWaybillOrderAddressRepository.queryByWOrderId(order.getId());
|
|
|
+ if (CollectionUtils.isEmpty(addressList)){
|
|
|
+ throw new BusinessException("运单地址不存在");
|
|
|
+ }
|
|
|
+ String startLng= "";
|
|
|
+ String startLat= "";
|
|
|
+ String endLng = "";
|
|
|
+ String endLat = "";
|
|
|
+ for (KwtWaybillOrderAddress address : addressList) {
|
|
|
+ if (Objects.equals(address.getAddressType(), AddressTypeEnum.SHIPMENT.getCode())) {
|
|
|
+ startLng = address.getLng();
|
|
|
+ startLat = address.getLat();
|
|
|
+ }
|
|
|
+ if (Objects.equals(address.getAddressType(), AddressTypeEnum.TAKE.getCode())) {
|
|
|
+ endLng = address.getLng();
|
|
|
+ endLat = address.getLat();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Objects.equals(order.getStatus(), CarWaybillV1Enum.COMPLETED.getCode())){
|
|
|
+ endLng = longitude;
|
|
|
+ endLat = latitude;
|
|
|
+ }
|
|
|
+
|
|
|
+ LocUtils.RouteResult routeResult = generateRoutePointsWithDuration(startLng, startLat, endLng, endLat);
|
|
|
+ if (routeResult == null || com.sckw.core.utils.StringUtils.isBlank(routeResult.getPointInfo())) {
|
|
|
+ log.error("高德API生成轨迹点位失败,起点: {},{} 终点: {},{}", startLng, startLat, endLng, endLat);
|
|
|
+ throw new BusinessException("生成轨迹失败:高德API生成轨迹点位失败");
|
|
|
+ }
|
|
|
+ List<LocUtils.RoutePoint> routePoints = JSON.parseArray(routeResult.getPointInfo(), LocUtils.RoutePoint.class);
|
|
|
+ if (CollectionUtils.isEmpty(routePoints)) {
|
|
|
+ log.error("高德API生成轨迹点位失败,起点: {},{} 终点: {},{}", startLng, startLat, endLng, endLat);
|
|
|
+ throw new BusinessException("生成轨迹失败:高德API生成轨迹点位为空");
|
|
|
+ }
|
|
|
+
|
|
|
// 通过车牌ID查询所属车队信息
|
|
|
RFleetVo fleetByTruckId = fleetService.findFleetByTruckId(order.getTruckId());
|
|
|
|
|
|
@@ -1475,29 +1511,58 @@ public class kwfTruckTraceService {
|
|
|
KwtLogisticsOrder logisticsOrder = kwtLogisticsOrderRepository.queryByLogisticsOrderId(subOrders.getLOrderId());
|
|
|
|
|
|
// 构造要发送给数据中台的轨迹数据请求
|
|
|
- VehiclesTrajectoryReq vehiclesTrajectoryReq = getVehiclesTrajectoryReq(req, order, longitude, latitude, logisticsOrder, fleetByTruckId);
|
|
|
+ routePoints.forEach(point -> {
|
|
|
+ VehiclesTrajectoryReq vehiclesTrajectoryReq = getVehiclesTrajectoryReq(req, order, point.getLongitude(), point.getLatitude(), logisticsOrder, fleetByTruckId);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 调用数据中台保存轨迹数据
|
|
|
+ log.info("调用数据中台保存车辆轨迹数据:{}", JSON.toJSONString(vehiclesTrajectoryReq));
|
|
|
+ BaseIotResult<Void> result = vehicleTraceClient.saveVehicleData(vehiclesTrajectoryReq);
|
|
|
+ if (!Objects.equals(result.getCode(), "0")) {
|
|
|
+ log.error("保存车辆轨迹数据失败:{}", result.getMessage());
|
|
|
+ throw new BusinessException("生成轨迹失败:" + result.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果请求中包含异常类型,则同时保存到本地车辆异常表
|
|
|
+ saveException(req, order, longitude, latitude);
|
|
|
|
|
|
+ log.info("生成车辆轨迹成功,运单号:{},车牌号:{}", req.getWayOrderNo(), req.getTruckNo());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("生成车辆轨迹异常:", e);
|
|
|
+ throw new BusinessException("生成轨迹失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private LocUtils.RouteResult generateRoutePointsWithDuration(String startLng, String startLat, String endLng, String endLat) {
|
|
|
try {
|
|
|
- // 调用数据中台保存轨迹数据
|
|
|
- log.info("调用数据中台保存车辆轨迹数据:{}", JSON.toJSONString(vehiclesTrajectoryReq));
|
|
|
- BaseIotResult<Void> result = vehicleTraceClient.saveVehicleData(vehiclesTrajectoryReq);
|
|
|
- if (!Objects.equals(result.getCode(), "0")) {
|
|
|
- log.error("保存车辆轨迹数据失败:{}", result.getMessage());
|
|
|
- throw new BusinessException("生成轨迹失败:" + result.getMessage());
|
|
|
+ log.info("开始调用高德API生成轨迹点位和耗时,起点: {},{} 终点: {},{}",
|
|
|
+ startLng, startLat, endLng, endLat);
|
|
|
+
|
|
|
+ // 调用高德驾车路径规划API,生成20个轨迹点位和耗时
|
|
|
+ LocUtils.RouteResult routeResult = com.sckw.core.utils.LocUtils.getDrivingRoutePointsWithDuration(
|
|
|
+ startLng,
|
|
|
+ startLat,
|
|
|
+ endLng,
|
|
|
+ endLat,
|
|
|
+ 20
|
|
|
+ );
|
|
|
+
|
|
|
+ if (routeResult != null && com.sckw.core.utils.StringUtils.isNotBlank(routeResult.getPointInfo())) {
|
|
|
+ log.info("高德API生成轨迹点位成功,耗时: {}秒", routeResult.getDuration());
|
|
|
+ } else {
|
|
|
+ log.warn("高德API生成轨迹点位失败或返回空数据");
|
|
|
}
|
|
|
-
|
|
|
- // 如果请求中包含异常类型,则同时保存到本地车辆异常表
|
|
|
- saveException(req, order, longitude, latitude);
|
|
|
|
|
|
- log.info("生成车辆轨迹成功,运单号:{},车牌号:{}", req.getWayOrderNo(), req.getTruckNo());
|
|
|
+ return routeResult;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("生成车辆轨迹异常:", e);
|
|
|
- throw new BusinessException("生成轨迹失败:" + e.getMessage());
|
|
|
+ log.error("调用高德API生成轨迹点位异常", e);
|
|
|
+ return null;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
private void saveException(GenerateTraceReq req, KwtWaybillOrder order, String longitude, String latitude) {
|
|
|
if (Objects.nonNull(req.getExceptionType())) {
|
|
|
// 保存到车辆异常表
|