|
|
@@ -2,7 +2,10 @@ package com.sckw.fleet.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.sckw.core.exception.BusinessException;
|
|
|
import com.sckw.core.model.base.BaseModel;
|
|
|
+import com.sckw.core.model.enums.AddressTypeEnum;
|
|
|
+import com.sckw.core.model.enums.CarWaybillV1Enum;
|
|
|
import com.sckw.core.utils.DateUtils;
|
|
|
import com.sckw.core.utils.LocUtils;
|
|
|
import com.sckw.core.utils.StringUtils;
|
|
|
@@ -19,7 +22,10 @@ import com.sckw.fleet.model.vo.QueryTruckRoteVo;
|
|
|
import com.sckw.fleet.model.vo.TruckRoteDetailVo;
|
|
|
import com.sckw.fleet.repository.*;
|
|
|
import com.sckw.transport.api.dubbo.TransportRemoteService;
|
|
|
+import com.sckw.transport.api.model.vo.KwtLogisticsOrderAddressVo;
|
|
|
+import com.sckw.transport.api.model.vo.KwtWaybillOrderAddressVo;
|
|
|
import com.sckw.transport.api.model.vo.RWaybillOrderVo;
|
|
|
+import com.sckw.transport.api.model.vo.WaybillOrderSubtaskVo;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import jakarta.validation.Valid;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -190,10 +196,34 @@ public class KwfTruckRouteService {
|
|
|
public QueryTruckRoteVo queryTruckRouteByDriver(QueryTruckRouteByDriverReq req) {
|
|
|
log.info("根据司机ID和装货卸货地址查询常用路线,请求参数 :{}", JSON.toJSONString(req));
|
|
|
// 查询常用路线
|
|
|
+ WaybillOrderSubtaskVo waybillOrderSubtaskVo = transportRemoteService.queryWaybillOrderId(req.getWayBillOrderId());
|
|
|
+ // 根据运单号查询运单信息
|
|
|
+ if (Objects.isNull(waybillOrderSubtaskVo)){
|
|
|
+ throw new BusinessException("运单不存在");
|
|
|
+ }
|
|
|
+ //查询运单装卸货地址
|
|
|
+ List<KwtLogisticsOrderAddressVo> addressList = transportRemoteService.queryByWOrderId(waybillOrderSubtaskVo.getLOrderId());
|
|
|
+ if (CollectionUtils.isEmpty(addressList)){
|
|
|
+ throw new BusinessException("运单地址不存在");
|
|
|
+ }
|
|
|
+ String startLng= "";
|
|
|
+ String startLat= "";
|
|
|
+ String endLng = "";
|
|
|
+ String endLat = "";
|
|
|
+ for (KwtLogisticsOrderAddressVo kwtLogisticsOrderAddressVo : addressList) {
|
|
|
+ if (Objects.equals(kwtLogisticsOrderAddressVo.getAddressType(), AddressTypeEnum.SHIPMENT.getCode())) {
|
|
|
+ req.setStartPoint(kwtLogisticsOrderAddressVo.getDetailAddress());
|
|
|
+ startLng = kwtLogisticsOrderAddressVo.getLng();
|
|
|
+ startLat = kwtLogisticsOrderAddressVo.getLat();
|
|
|
+ } else if (Objects.equals(kwtLogisticsOrderAddressVo.getAddressType(), AddressTypeEnum.TAKE.getCode())) {
|
|
|
+ req.setUnloadingPoint(kwtLogisticsOrderAddressVo.getDetailAddress());
|
|
|
+ endLng = kwtLogisticsOrderAddressVo.getLng();
|
|
|
+ endLat = kwtLogisticsOrderAddressVo.getLat();
|
|
|
+ }
|
|
|
+ }
|
|
|
KwfTruckRoute truckRoute = truckRouteRepository.queryByDriverIdAndAddress(
|
|
|
- req.getDriverId(),
|
|
|
- req.getStartPoint(),
|
|
|
- req.getUnloadingPoint()
|
|
|
+ req.getDriverId(),
|
|
|
+ startLng, startLat,endLng ,endLat
|
|
|
);
|
|
|
|
|
|
if (Objects.isNull(truckRoute)) {
|
|
|
@@ -201,11 +231,13 @@ public class KwfTruckRouteService {
|
|
|
try {
|
|
|
log.info("未查询到,开始mock数据司机ID:{},装货地址:{},卸货地址:{} 的常用路线",
|
|
|
req.getDriverId(), req.getStartPoint(), req.getUnloadingPoint());
|
|
|
- saveTruckRote(req);
|
|
|
+ saveTruckRote(req, startLng, startLat, endLng, endLat);
|
|
|
truckRoute = truckRouteRepository.queryByDriverIdAndAddress(
|
|
|
req.getDriverId(),
|
|
|
- req.getStartPoint(),
|
|
|
- req.getUnloadingPoint()
|
|
|
+ startLng,
|
|
|
+ startLat,
|
|
|
+ endLng,
|
|
|
+ endLat
|
|
|
);
|
|
|
} catch (Exception e) {
|
|
|
log.error("新增常用路线异常", e);
|
|
|
@@ -251,64 +283,121 @@ public class KwfTruckRouteService {
|
|
|
.collect(Collectors.toList());
|
|
|
vo.setTruckRoteDetails(truckRoteDetails);
|
|
|
}
|
|
|
+// else {
|
|
|
+//
|
|
|
+// log.info("开始调用高德API生成轨迹点位,起点: {},{} 终点: {},{}", startLng, startLat, endLng, endLat);
|
|
|
+// 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.isNotEmpty(routePoints)) {
|
|
|
+// routePoints.stream().map(x->{
|
|
|
+// QueryTruckRoteVo.TruckRoteDetail truckRoteDetail = new QueryTruckRoteVo.TruckRoteDetail();
|
|
|
+// truckRoteDetail.setTs(truckRoteDetail.getTs());
|
|
|
+// truckRoteDetail.setLongitude(truckRoteDetail.getLongitude());
|
|
|
+// truckRoteDetail.setLatitude(truckRoteDetail.getLatitude());
|
|
|
+// return truckRoteDetail;
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
return vo;
|
|
|
}
|
|
|
+ private LocUtils.RouteResult generateRoutePointsWithDuration(String startLng, String startLat, String endLng, String endLat) {
|
|
|
+ try {
|
|
|
+ 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生成轨迹点位失败或返回空数据");
|
|
|
+ }
|
|
|
|
|
|
- private void saveTruckRote(QueryTruckRouteByDriverReq req) {
|
|
|
+ return routeResult;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用高德API生成轨迹点位异常", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void saveTruckRote(QueryTruckRouteByDriverReq req,String startLng,String startLat,String endLng,String endLat) {
|
|
|
RWaybillOrderVo rWaybillOrderVo = transportRemoteService.queryWaybillOrderByWayBillOrderId(req.getWayBillOrderId());
|
|
|
KwfFleetTruck kwfFleetTruck = fleetTruckRepository.findFleetByTruckId(rWaybillOrderVo.getTruckId());
|
|
|
// 在查询惯用路线之前,调用高德API生成装货地址和卸货地址之间的20个轨迹点位
|
|
|
- LocUtils.RouteResult routeResult = generateRoutePointsWithDuration(rWaybillOrderVo);
|
|
|
+ LocUtils.RouteResult routeResult = generateRoutePointsWithDuration(startLng, startLat, endLng, endLat);
|
|
|
KwfTruckRoute kwfTruckRoute = new KwfTruckRoute();
|
|
|
kwfTruckRoute.setFleetId(Optional.ofNullable(kwfFleetTruck).map(KwfFleetTruck::getFleetId).orElse(0L));
|
|
|
kwfTruckRoute.setDriverId(req.getDriverId());
|
|
|
kwfTruckRoute.setEntId(LoginUserHolder.getEntId());
|
|
|
kwfTruckRoute.setStartPoint(req.getStartPoint());
|
|
|
kwfTruckRoute.setUnloadingPoint(req.getUnloadingPoint());
|
|
|
+ kwfTruckRoute.setLoadLng(startLng);
|
|
|
+ kwfTruckRoute.setLoadLat(startLat);
|
|
|
+ kwfTruckRoute.setUnloadLng(endLng);
|
|
|
+ kwfTruckRoute.setUnloadLat(endLat);
|
|
|
// 设置装货点和卸货点的耗时时间(单位:秒)
|
|
|
if (routeResult != null && StringUtils.isNotBlank(routeResult.getDuration())) {
|
|
|
kwfTruckRoute.setShortestTime(routeResult.getDuration());
|
|
|
}
|
|
|
// 如果生成了轨迹点,更新到数据库的point_info字段
|
|
|
if (routeResult != null && StringUtils.isNotBlank(routeResult.getPointInfo())) {
|
|
|
- kwfTruckRoute.setPointInfo(routeResult.getPointInfo());
|
|
|
+ List<LocUtils.RoutePoint> routePoints = JSON.parseArray(routeResult.getPointInfo(), LocUtils.RoutePoint.class);
|
|
|
+ if (CollectionUtils.isNotEmpty(routePoints)) {
|
|
|
+ List<QueryTruckRoteVo.TruckRoteDetail> details = routePoints.stream().map(x -> {
|
|
|
+ QueryTruckRoteVo.TruckRoteDetail truckRoteDetail = new QueryTruckRoteVo.TruckRoteDetail();
|
|
|
+ truckRoteDetail.setTs(truckRoteDetail.getTs());
|
|
|
+ truckRoteDetail.setLongitude(truckRoteDetail.getLongitude());
|
|
|
+ truckRoteDetail.setLatitude(truckRoteDetail.getLatitude());
|
|
|
+ return truckRoteDetail;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ kwfTruckRoute.setPointInfo(JSON.toJSONString(details));
|
|
|
+ }
|
|
|
+ kwfTruckRoute.setTruckNo(rWaybillOrderVo.getTruckNo());
|
|
|
+ kwfTruckRoute.setTruckId(rWaybillOrderVo.getTruckId());
|
|
|
+ truckRouteRepository.save(kwfTruckRoute);
|
|
|
}
|
|
|
- kwfTruckRoute.setTruckNo(rWaybillOrderVo.getTruckNo());
|
|
|
- kwfTruckRoute.setTruckId(rWaybillOrderVo.getTruckId());
|
|
|
- truckRouteRepository.save(kwfTruckRoute);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 调用高德API生成装货地址和卸货地址之间的20个轨迹点位信息和耗时
|
|
|
+ * @param req 请求参数
|
|
|
+ * @return 轨迹点位和耗时信息
|
|
|
+ */
|
|
|
+ private LocUtils.RouteResult generateRoutePointsWithDuration (RWaybillOrderVo req){
|
|
|
+ try {
|
|
|
+ log.info("开始调用高德API生成轨迹点位和耗时,起点: {},{} 终点: {},{}",
|
|
|
+ req.getStartLng(), req.getStartLat(), req.getEndLng(), req.getEndLat());
|
|
|
|
|
|
- /**
|
|
|
- * 调用高德API生成装货地址和卸货地址之间的20个轨迹点位信息和耗时
|
|
|
- * @param req 请求参数
|
|
|
- * @return 轨迹点位和耗时信息
|
|
|
- */
|
|
|
- private LocUtils.RouteResult generateRoutePointsWithDuration(RWaybillOrderVo req) {
|
|
|
- try {
|
|
|
- log.info("开始调用高德API生成轨迹点位和耗时,起点: {},{} 终点: {},{}",
|
|
|
- req.getStartLng(), req.getStartLat(), req.getEndLng(), req.getEndLat());
|
|
|
-
|
|
|
- // 调用高德驾车路径规划API,生成20个轨迹点位和耗时
|
|
|
- LocUtils.RouteResult routeResult = com.sckw.core.utils.LocUtils.getDrivingRoutePointsWithDuration(
|
|
|
- req.getStartLng(),
|
|
|
- req.getStartLat(),
|
|
|
- req.getEndLng(),
|
|
|
- req.getEndLat(),
|
|
|
- 20
|
|
|
- );
|
|
|
-
|
|
|
- if (routeResult != null && StringUtils.isNotBlank(routeResult.getPointInfo())) {
|
|
|
- log.info("高德API生成轨迹点位成功,耗时: {}秒", routeResult.getDuration());
|
|
|
- } else {
|
|
|
- log.warn("高德API生成轨迹点位失败或返回空数据");
|
|
|
+ // 调用高德驾车路径规划API,生成20个轨迹点位和耗时
|
|
|
+ LocUtils.RouteResult routeResult = com.sckw.core.utils.LocUtils.getDrivingRoutePointsWithDuration(
|
|
|
+ req.getStartLng(),
|
|
|
+ req.getStartLat(),
|
|
|
+ req.getEndLng(),
|
|
|
+ req.getEndLat(),
|
|
|
+ 20
|
|
|
+ );
|
|
|
+
|
|
|
+ if (routeResult != null && StringUtils.isNotBlank(routeResult.getPointInfo())) {
|
|
|
+ log.info("高德API生成轨迹点位成功,耗时: {}秒", routeResult.getDuration());
|
|
|
+ } else {
|
|
|
+ log.warn("高德API生成轨迹点位失败或返回空数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ return routeResult;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用高德API生成轨迹点位异常", e);
|
|
|
+ return null;
|
|
|
}
|
|
|
-
|
|
|
- return routeResult;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("调用高德API生成轨迹点位异常", e);
|
|
|
- return null;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
}
|