| | |
| | | import com.xiaopeng.common.core.enums.PushMessageTypeEnum; |
| | | import com.xiaopeng.common.redis.service.RedisService; |
| | | import com.xiaopeng.pushMessage.utils.MapMatchingUtil; |
| | | import com.xiaopeng.pushMessage.utils.TrackPoint; |
| | | import com.xiaopeng.pushMessage.utils.TrajectoryDensifier; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.powermock.core.ListMap; |
| | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.time.Instant; |
| | | import java.util.*; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | |
| | | } |
| | | Object cacheObject = redisService.getCacheObject(key); |
| | | RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class); |
| | | |
| | | log.info("缓存获取的轨迹 {}", JSON.toJSONString(routeVo)); |
| | | if(Objects.nonNull(routeVo)){ |
| | | //开始对轨迹进行点位补全,然后更新缓存中的轨迹数据 |
| | | if(xpOrder.getStatus() == 2 || xpOrder.getStatus() == 5){ |
| | | List<LonLatDto> polyline = routeVo.getPolyline(); |
| | | List<LonLatDto> new_polyline = new ArrayList<>(); |
| | | for (int i = 0; i < polyline.size(); i++) { |
| | | if(i == polyline.size() - 1){ |
| | | new_polyline.add(polyline.get(i)); |
| | | break; |
| | | } |
| | | LonLatDto lonLatDto = polyline.get(i); |
| | | LonLatDto lonLatDto1 = polyline.get(i + 1); |
| | | //对两个点位进行坐标补全 |
| | | List<TrackPoint> track = new ArrayList<>(); |
| | | // 模拟数据:两个点相差 20 秒 |
| | | track.add(new TrackPoint(lonLatDto.getLatitude(), lonLatDto.getLongitude(), null)); |
| | | track.add(new TrackPoint(lonLatDto1.getLatitude(), lonLatDto1.getLongitude(), null)); |
| | | //10米补全一个点位 |
| | | List<TrackPoint> densified = TrajectoryDensifier.densifyByTime(track, 10); |
| | | for (TrackPoint trackPoint : densified) { |
| | | new_polyline.add(new LonLatDto(trackPoint.getLongitude(), trackPoint.getLatitude())); |
| | | } |
| | | } |
| | | routeVo.setPolyline(new_polyline); |
| | | redisService.setCacheObject(key, JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS); |
| | | } |
| | | Integer distance = dto.getDistance(); |
| | | Integer duration = dto.getDuration(); |
| | | // 计算实时点位到线段的最优截取 |
| | |
| | | List<LonLatDto> lonLatDtos1 = remainingNavigation.get("served"); |
| | | routeVo.setPolyline(lonLatDtos); |
| | | routeVo.setServed(lonLatDtos1); |
| | | |
| | | log.info("线路截取后存储的轨迹 {}", JSON.toJSONString(routeVo)); |
| | | // 存储最新路线偏离缓存,后续进行轨迹截取 |
| | | redisService.setCacheObject(key, JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS); |
| | | |
| | | //将车辆的当前位置加入到第一个轨迹点位集合中 |
| | | lonLatDtos.add(0, new LonLatDto(dto.getLongitude(), dto.getLatitude())); |
| | | // 封装轨迹点位集合 |
| | | List<Map<String, Object>> polyline = new ArrayList<>(); |
| | | for (LonLatDto lonLatDto : lonLatDtos) { |
| | | Map<String, Object> polylineMap = new HashMap<>(); |
| | | polylineMap.put("longitude",lonLatDto.getLongitude()); |
| | | polylineMap.put("latitude",lonLatDto.getLatitude()); |
| | | polyline.add(polylineMap); |
| | | } |
| | | List<Map<String, Object>> served = new ArrayList<>(); |
| | | for (LonLatDto lonLatDto : lonLatDtos1) { |
| | | Map<String, Object> polylineMap = new HashMap<>(); |
| | | polylineMap.put("longitude",lonLatDto.getLongitude()); |
| | | polylineMap.put("latitude",lonLatDto.getLatitude()); |
| | | served.add(polylineMap); |
| | | } |
| | | // 封装路由详情 |
| | | Map<String, Object> route = new HashMap<>(); |
| | | route.put("distance",distance); |
| | | route.put("duration",duration); |
| | | route.put("polyline",JSONObject.toJSONString(polyline)); |
| | | route.put("served",JSONObject.toJSONString(served)); |
| | | route.put("polyline",JSONObject.toJSONString(lonLatDtos)); |
| | | route.put("served",JSONObject.toJSONString(lonLatDtos1)); |
| | | |
| | | Map<String, Object> content = new HashMap<>(); |
| | | content.put("orderId",dto.getOrderId().toString()); |