From ba78f764042ca15bf3f3be62e7a3fc699df56d67 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期六, 07 三月 2026 20:59:53 +0800
Subject: [PATCH] 提交管理后台新接口,修改XPU报文相关功能,增加测试小程序状态流转接口
---
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/controller/OrderMissionController.java | 467 ----------------------------------------------------------
1 files changed, 3 insertions(+), 464 deletions(-)
diff --git a/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/controller/OrderMissionController.java b/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/controller/OrderMissionController.java
index 1735027..ae3fb3d 100644
--- a/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/controller/OrderMissionController.java
+++ b/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/controller/OrderMissionController.java
@@ -2,51 +2,24 @@
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
-import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONObject;
import com.xiaopeng.api.dto.automaticPilot.MqttPublishDto;
import com.xiaopeng.api.dto.automaticPilot.PushOrderDto;
-import com.xiaopeng.api.dto.map.OrderRouteAndFareDto;
-import com.xiaopeng.api.dto.operation.LonLatDto;
-import com.xiaopeng.api.dto.order.PopOrderDto;
-import com.xiaopeng.api.dto.pushMessage.PushOrderRouteDTO;
-import com.xiaopeng.api.dto.pushMessage.SendMessageDTO;
import com.xiaopeng.api.dto.vehicleConvoy.UpdateVehicleStateDto;
-import com.xiaopeng.api.feignClient.map.XpMapClient;
-import com.xiaopeng.api.feignClient.order.XpOrderClient;
-import com.xiaopeng.api.feignClient.pushMessage.XpPushMessageClient;
import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient;
-import com.xiaopeng.api.model.order.XpOrder;import com.xiaopeng.api.model.vehicleConvoy.XpVehicle;
-import com.xiaopeng.api.vo.automaticPilot.VehiclePosition;
import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.RTTask;
import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.TaskStatus;
import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.TaskType;
import com.xiaopeng.api.vo.automaticPilot.protobuf.*;
-import com.xiaopeng.api.vo.operation.RouteVo;
-import com.xiaopeng.api.vo.order.OrderTrajectoryVo;
import com.xiaopeng.automaticPilot.util.XPUUtil;
import com.xiaopeng.common.core.domain.R;
-import com.xiaopeng.common.core.enums.OrderStatusEnum;
-import com.xiaopeng.common.core.enums.PushMessageTypeEnum;
import com.xiaopeng.common.core.utils.SnowFlake;
-import com.xiaopeng.common.core.utils.StringUtils;
import com.xiaopeng.common.redis.service.RedisService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.data.geo.Point;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
-import org.springframework.data.mongodb.core.query.Criteria;
-import org.springframework.data.mongodb.core.query.Query;
-import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
-import java.util.*;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
@Slf4j
@RestController
@@ -74,45 +47,6 @@
}else {
taskBuilder.setTaskType(OrderType.ORDER_TYPE_ROBOTAXI);
}
- //构建点位信息
- Waypoint.Builder pointBuilder = Waypoint.newBuilder();
- //巡游订单
- if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.CRUISE_ORDER)){
- pointBuilder.setPointType(PointType.CRUISE_END_POINT);
- pointBuilder.setSequence(1);
- //构建终点坐标
- GeoPoint.Builder geoPointBuilder = GeoPoint.newBuilder();
- geoPointBuilder.setLatitude(dto.getEndLatitude());
- geoPointBuilder.setLongitude(dto.getEndLatitude());
- // geoPointBuilder.setPoiName("Start Point"); // GeoPoint might not have poi_name
- pointBuilder.setPoint(geoPointBuilder.build());
- }else{
- //用户订单
- if(dto.getStage() == 1){
- //开往上车点
- pointBuilder.setPointType(PointType.START_POINT);
- pointBuilder.setActionType(ActionType.PICK_UP);
- pointBuilder.setSequence(1);
- //构建起点坐标
- GeoPoint.Builder geoPointBuilder = GeoPoint.newBuilder();
- geoPointBuilder.setLatitude(dto.getStartLatitude());
- geoPointBuilder.setLongitude(dto.getStartLongitude());
- // geoPointBuilder.setPoiName("Start Point"); // GeoPoint might not have poi_name
- pointBuilder.setPoint(geoPointBuilder.build());
- }else{
- //开往终点
- pointBuilder.setPointType(PointType.END_POINT);
- pointBuilder.setActionType(ActionType.PICK_UP);
- pointBuilder.setSequence(1);
- //构建起点坐标
- GeoPoint.Builder geoPointBuilder = GeoPoint.newBuilder();
- geoPointBuilder.setLatitude(dto.getEndLatitude());
- geoPointBuilder.setLongitude(dto.getEndLatitude());
- // geoPointBuilder.setPoiName("Start Point"); // GeoPoint might not have poi_name
- pointBuilder.setPoint(geoPointBuilder.build());
- }
- }
- taskBuilder.addPoints(pointBuilder);
RtTaskList.Builder taskListBuilder = RtTaskList.newBuilder();
taskListBuilder.addTasks(taskBuilder.build());
@@ -143,405 +77,10 @@
SnowFlake snowFlake = new SnowFlake(0, 0);
snowFlake.withStartTimestamp(1420041600000L);
long sequence = snowFlake.nextId();
- MqttPublishDto mqttPublishDto = xpuUtil.cloudOrderOperation(operationBuilder.build(), dto.getVin(), sequence);
-
- if (mqttPublishDto.getCode() == 200) {
- if(!dto.getOrderId().contains("XU")){
- // 正常订单处理
- redisService.setCacheObject(String.valueOf(sequence), "cancelOrder_" + dto.getOrderId() + "_" + dto.getVin(), 30l, TimeUnit.MINUTES);
- }
- return R.ok(true);
- }
-
- return R.ok(false);
+ xpuUtil.cloudOrderOperation(operationBuilder.build(), dto.getVin(), sequence);
+ redisService.setCacheObject(String.valueOf(sequence), "cancelOrder_" + dto.getOrderId() + "_" + dto.getVin(), 30l, TimeUnit.MINUTES);
+ return R.ok(true);
}
-
-
-
-
-
-
-
-
-
-
-
-
-
- //-----------------------------------------------用户测试阶段模拟车机报文调用流程接口实现业务闭环--------------------------------------//
-
-
- @Resource
- private XpOrderClient xpOrderClient;
-
- @Resource
- private XpMapClient xpMapClient;
-
- @Resource
- private MongoTemplate mongoTemplate;
-
- @Resource
- public RedisTemplate redisTemplate;
-
- @Resource
- private XpPushMessageClient xpPushMessageClient;
-
-
- /**
- * 模拟接单
- * @param orderId 订单id
- * @param vehicleId 车辆id
- * @param startLon 车子当前位置经度
- * @param startLat 车子当前位置维度
- * @return
- */
- @GetMapping("/base/v1/order/acceptingOrder")
- public R acceptingOrder(Long orderId, String code, Long vehicleId, Double startLon, Double startLat){
- if(null == vehicleId){
- vehicleId = 1L;
- }
- if(null == startLat || null == startLon){
- startLat = 30.583407D;
- startLon = 104.040251D;
- }
- XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData();
- XpOrder xpOrder = null;
- if(null != orderId){
- xpOrder = xpOrderClient.queryOrderById(orderId).getData();
- }
- if(StringUtils.isNotEmpty(code)){
- xpOrder = xpOrderClient.queryOrderByOrderNo(code).getData();
- }
- orderId = xpOrder.getId();
- OrderRouteAndFareDto dto = new OrderRouteAndFareDto();
- dto.setOrderId(orderId);
- LonLatDto origin = new LonLatDto();
- origin.setLongitude(startLon);
- origin.setLatitude(startLat);
- dto.setOrigin(origin);
- LonLatDto destination = new LonLatDto();
- destination.setLongitude(xpOrder.getStartLon());
- destination.setLatitude(xpOrder.getStartLat());
- dto.setDestination(destination);
- dto.setRouteType(1);
- R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto);
- if (200 != routeVoR.getCode()) {
- throw new RuntimeException("获取订单线路和运费失败");
- }
- RouteVo routeVo = routeVoR.getData();
- //缓存数据,用于后续推给乘客导航线路
- redisService.setCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId(), JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS);
-
- PopOrderDto dto1 = new PopOrderDto();
- dto1.setOrderId(Long.valueOf(orderId));
- dto1.setXpVehicleVin(xpVehicle.getVehicleVin());
- dto1.setOrderType(com.xiaopeng.api.vo.OrderType.USER_ORDER);
- R<?> r = xpOrderClient.popOrder(dto1);
-
- //构建推送消息
- Map<String, Object> params = new HashMap<>();
- Map<String, Object> content = new HashMap<>();
- content.put("orderId", orderId.toString());
- content.put("status", 3);
- params.put("type", PushMessageTypeEnum.ORDER_STATUS.getDesc());
- params.put("content", JSONObject.toJSONString(content));
- params.put("timestamp", System.currentTimeMillis() + "");
- String message = JSONObject.toJSONString(params);
- Long appUserId = xpOrder.getAppUserId();
- SendMessageDTO dto2 = new SendMessageDTO();
- dto2.setAppUserId(appUserId + "");
- dto2.setMessage(message);
- R<String> stringR = xpPushMessageClient.sendStatus(dto2);
- if (R.isError(stringR)) {
- log.error("推送消息失败:{}", stringR.getMsg());
- }
- xpOrderClient.updateOrderStatus(orderId, OrderStatusEnum.PICK_UP.getCode());
- return r;
- }
-
-
- /**
- * 推送司机接驾轨迹和实时位置
- * @param orderId
- */
- @GetMapping("/base/v1/order/pushStartDriverLocation")
- private void pushStartDriverLocation(Long vehicleId, Long orderId, String code){
- if(null == vehicleId){
- vehicleId = 1L;
- }
- XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData();
- XpOrder xpOrder = null;
- if(null != orderId){
- xpOrder = xpOrderClient.queryOrderById(orderId).getData();
- }
- if(StringUtils.isNotEmpty(code)){
- xpOrder = xpOrderClient.queryOrderByOrderNo(code).getData();
- }
- orderId = xpOrder.getId();
- String vin = xpVehicle.getVehicleVin();
- Long appUserId = xpOrder.getAppUserId();
-// Object cacheObject = redisService.getCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId());
-// RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class);
- RouteVo routeVo =new RouteVo();
- ArrayList<LonLatDto> lonLatDtos = new ArrayList<>();
- LonLatDto lonLatDto1 = new LonLatDto();
- lonLatDto1.setLatitude(30.575685);
- lonLatDto1.setLongitude(104.001118);
- lonLatDtos.add(lonLatDto1);
- routeVo.setPolyline(lonLatDtos);
-
-
- ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1000));
- Long finalOrderId = orderId;
- threadPoolExecutor.execute(() -> {
- //等待10秒后开始执行车子位移
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- List<LonLatDto> polyline = routeVo.getPolyline();
- for (LonLatDto lonLatDto : polyline) {
- Double latitude = lonLatDto.getLatitude();
- Double longitude = lonLatDto.getLongitude();
-
- //保存车辆实时位置到redis
- redisTemplate.opsForGeo().add("vehiclePosition:" + vin, new Point(longitude, latitude), vin);
-
- //保存车辆实时信息到mongodb
- VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(vin)), VehiclePosition.class);
- if (null == vehiclePosition) {
- vehiclePosition = new VehiclePosition();
- }
- vehiclePosition.setVin(vin);
- vehiclePosition.setPoint(new GeoJsonPoint(longitude, latitude));
- vehiclePosition.setCourse(60D);
- vehiclePosition.setAlt(100F);
- //车辆动态信息
- vehiclePosition.setSpeed(50F);
- vehiclePosition.setCurrentElectricity(80);
- vehiclePosition.setMileageRange(300f);
- vehiclePosition.setOrderId(finalOrderId);
- mongoTemplate.save(vehiclePosition);
- //调用推送服务接口
- if (null != finalOrderId) {
- PushOrderRouteDTO dto = new PushOrderRouteDTO();
- dto.setOrderId(finalOrderId);
- dto.setRouteType(1);
- dto.setLongitude(longitude);
- dto.setLatitude(latitude);
- dto.setDuration(10);
- dto.setDistance(2);
- dto.setDirection(60);
- xpPushMessageClient.pushOrderRoute(dto);
- }
-
- //2秒钟循环一次
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- //构建推送消息
- Map<String, Object> params = new HashMap<>();
- Map<String, Object> content = new HashMap<>();
- content.put("orderId", finalOrderId.toString());
- content.put("status", 4);
- params.put("type", PushMessageTypeEnum.ORDER_STATUS.getDesc());
- params.put("content", JSONObject.toJSONString(content));
- params.put("timestamp", System.currentTimeMillis() + "");
- String message = JSONObject.toJSONString(params);
- SendMessageDTO dto2 = new SendMessageDTO();
- dto2.setAppUserId(appUserId + "");
- dto2.setMessage(message);
- R<String> stringR = xpPushMessageClient.sendStatus(dto2);
- if (R.isError(stringR)) {
- log.error("推送消息失败:{}", stringR.getMsg());
- }
- xpOrderClient.updateOrderStatus(finalOrderId, OrderStatusEnum.PICK_UP_GUESTS.getCode());
- });
-
- }
-
-
- /**
- * 修改订单状态
- * @param orderId
- * @param status
- * @return
- */
- @GetMapping("/base/v1/order/updateOrderStatus")
- public R updateOrderStatus(Long orderId, String code, Integer status) {
- XpOrder xpOrder = null;
- if(null != orderId){
- xpOrder = xpOrderClient.queryOrderById(orderId).getData();
- }
- if(StringUtils.isNotEmpty(code)){
- xpOrder = xpOrderClient.queryOrderByOrderNo(code).getData();
- }
- orderId = xpOrder.getId();
- //构建推送消息
- Map<String, Object> params = new HashMap<>();
- Map<String, Object> content = new HashMap<>();
- content.put("orderId", orderId.toString());
- content.put("status", status);
- params.put("type", PushMessageTypeEnum.ORDER_STATUS.getDesc());
- params.put("content", JSONObject.toJSONString(content));
- params.put("timestamp", System.currentTimeMillis() + "");
- String message = JSONObject.toJSONString(params);
- SendMessageDTO dto2 = new SendMessageDTO();
- dto2.setAppUserId(xpOrder.getAppUserId() + "");
- dto2.setMessage(message);
- R<String> stringR = xpPushMessageClient.sendStatus(dto2);
- if (R.isError(stringR)) {
- log.error("推送消息失败:{}", stringR.getMsg());
- }
- xpOrderClient.updateOrderStatus(orderId, status);
- if(5 == status){
- //主动推一次全程轨迹
- Object cacheObject = redisService.getCacheObject("ORDER_NAVIGATION_END_DATA:" + xpOrder.getAppUserId());
- RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class);
- com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject();
- jsonObject.put("type", "ORDER_ROUTE");
- jsonObject.put("timestamp", System.currentTimeMillis());
- com.alibaba.fastjson2.JSONObject content1 = new com.alibaba.fastjson2.JSONObject();
- content1.put("orderId", orderId.toString());
- content1.put("routeType", 1);
- com.alibaba.fastjson2.JSONObject route = new com.alibaba.fastjson2.JSONObject();
- route.put("distance", routeVo.getDistance());
- route.put("duration", routeVo.getDuration());
- route.put("routeID", routeVo.getRouteID());
-
- List<com.alibaba.fastjson2.JSONObject> collect = routeVo.getPolyline().stream().map(item -> {
- com.alibaba.fastjson2.JSONObject point = new com.alibaba.fastjson2.JSONObject();
- point.put("latitude", item.getLatitude());
- point.put("longitude", item.getLongitude());
- return point;
- }).collect(Collectors.toList());
-
- route.put("polyline", JSON.toJSONString(collect));
- content1.put("route", route.toJSONString());
- jsonObject.put("content", content1.toJSONString());
- SendMessageDTO messageDTO = new SendMessageDTO();
- messageDTO.setAppUserId(xpOrder.getAppUserId().toString());
- messageDTO.setMessage(jsonObject.toJSONString());
- xpPushMessageClient.sendRoute(messageDTO);
- }
- return R.ok();
- }
-
-
-
- /**
- * 推送司机接驾轨迹和实时位置
- * @param orderId
- */
- @GetMapping("/base/v1/order/pushEndDriverLocation")
- private void pushEndDriverLocation(Long vehicleId, Long orderId, String code){
- if(null == vehicleId){
- vehicleId = 1L;
- }
- XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData();
- XpOrder xpOrder = null;
- if(null != orderId){
- xpOrder = xpOrderClient.queryOrderById(orderId).getData();
- }
- if(StringUtils.isNotEmpty(code)){
- xpOrder = xpOrderClient.queryOrderByOrderNo(code).getData();
- }
- orderId = xpOrder.getId();
- String vin = xpVehicle.getVehicleVin();
- Long appUserId = xpOrder.getAppUserId();
- Object cacheObject = redisService.getCacheObject("ORDER_NAVIGATION_END_DATA:" + xpOrder.getAppUserId());
- RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class);
-
- ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1000));
- Long finalOrderId = orderId;
- threadPoolExecutor.execute(() -> {
- //等待10秒后开始执行车子位移
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
-
- List<LonLatDto> polyline = routeVo.getPolyline();
- for (LonLatDto lonLatDto : polyline) {
- Double latitude = lonLatDto.getLatitude();
- Double longitude = lonLatDto.getLongitude();
-
- //保存车辆实时位置到redis
- redisTemplate.opsForGeo().add("vehiclePosition:" + vin, new Point(longitude, latitude), vin);
-
- //保存车辆实时信息到mongodb
- VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(vin)), VehiclePosition.class);
- if (null == vehiclePosition) {
- vehiclePosition = new VehiclePosition();
- }
- vehiclePosition.setVin(vin);
- vehiclePosition.setPoint(new GeoJsonPoint(longitude, latitude));
- vehiclePosition.setCourse(60D);
- vehiclePosition.setAlt(100F);
- //车辆动态信息
- vehiclePosition.setSpeed(50F);
- vehiclePosition.setCurrentElectricity(80);
- vehiclePosition.setMileageRange(300f);
- vehiclePosition.setOrderId(finalOrderId);
- mongoTemplate.save(vehiclePosition);
- //调用推送服务接口
- if (null != finalOrderId) {
- PushOrderRouteDTO dto = new PushOrderRouteDTO();
- dto.setOrderId(finalOrderId);
- dto.setRouteType(1);
- dto.setLongitude(longitude);
- dto.setLatitude(latitude);
- dto.setDuration(20);
- dto.setDistance(10);
- dto.setDirection(60);
- xpPushMessageClient.pushOrderRoute(dto);
-
- //存储历史轨迹
- OrderTrajectoryVo orderTrajectory = new OrderTrajectoryVo();
- orderTrajectory.setOrderId(finalOrderId);
- orderTrajectory.setLocation(longitude + "," + latitude);
- orderTrajectory.setDirection(dto.getDirection());
- orderTrajectory.setSpeed(0D);
- orderTrajectory.setLocatetime(System.currentTimeMillis());
- orderTrajectory.setCreateTime(new Date());
- xpOrderClient.saveVehicleLocation(orderTrajectory);
- }
-
- //5秒钟循环一次
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- //构建推送消息
- Map<String, Object> params = new HashMap<>();
- Map<String, Object> content = new HashMap<>();
- content.put("orderId", finalOrderId.toString());
- content.put("status", 7);
- params.put("type", PushMessageTypeEnum.ORDER_STATUS.getDesc());
- params.put("content", JSONObject.toJSONString(content));
- params.put("timestamp", System.currentTimeMillis() + "");
- String message = JSONObject.toJSONString(params);
- SendMessageDTO dto2 = new SendMessageDTO();
- dto2.setAppUserId(appUserId + "");
- dto2.setMessage(message);
- R<String> stringR = xpPushMessageClient.sendStatus(dto2);
- if (R.isError(stringR)) {
- log.error("推送消息失败:{}", stringR.getMsg());
- }
- xpOrderClient.updateOrderStatus(finalOrderId, OrderStatusEnum.SEE_OFF_GUESTS.getCode());
- });
- }
-
-
}
--
Gitblit v1.7.1