puzhibing
2026-02-27 e4e49b4458120047ed882d8c03ea6bcbb1e94b67
xp-robotaxi-itinerary-boot/src/main/java/com/xiaopeng/itinerary/service/impl/XpPricingServiceImpl.java
@@ -9,13 +9,16 @@
import com.xiaopeng.api.dto.account.GetUserCouponDto;
import com.xiaopeng.api.dto.map.RouteAndFareDto;
import com.xiaopeng.api.dto.operation.LonLatDto;
import com.xiaopeng.api.dto.pushMessage.SendMessageDTO;
import com.xiaopeng.api.feignClient.account.XpAppUserClient;
import com.xiaopeng.api.feignClient.account.XpAppUserCouponClient;
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.model.account.XpAppUser;
import com.xiaopeng.api.model.operation.*;
import com.xiaopeng.api.model.order.XpOrder;
import com.xiaopeng.api.model.order.XpOrderDetail;
import com.xiaopeng.api.vo.account.UserCouponVo;
import com.xiaopeng.api.vo.operation.FareVo;
import com.xiaopeng.api.vo.operation.RouteAndFareVo;
@@ -39,6 +42,7 @@
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
@@ -88,7 +92,6 @@
    @Resource
    private XpElectronicFenceAreaMapper xpElectronicFenceAreaMapper;
    @Resource
    private XpWhitelistMapper xpWhitelistMapper;
@@ -106,6 +109,9 @@
    @Autowired
    private XpPointService xpPointService;
    @Resource
    private XpPushMessageClient xpPushMessageClient;
    // 自定义线程池用于并行执行任务
@@ -547,6 +553,8 @@
        // 静默处理 不推单
        if (isSilent) {
            // todo 用于测试流程,正式联调需要删除此代码
            testOrder(orderId);
            return orderId;
        }
@@ -606,7 +614,6 @@
        xpGeoQueryEntity.setStatus(0);
        geoQueryEntityService.save(xpGeoQueryEntity);
        return orderId;
//
@@ -666,4 +673,219 @@
    }
    /**
     * 测试阶段用于自动完成小程序的整个流程数据状态流转
     * @param orderId
     */
    private void testOrder(Long orderId){
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(10000));
        poolExecutor.execute(()->{
            XpOrder xpOrder = xpOrderClient.queryOrderById(orderId).getData();
            Long appUserId = xpOrder.getAppUserId();
            xpOrder.setStatus(2);
            xpOrder.setVehicleId(1L);
            xpOrder.setFleetId(2L);
            xpOrderClient.updateOrder(xpOrder);
            //等待5秒钟
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //修改状态为接驾中
            xpOrder.setStatus(3);
            xpOrder.setAppUserId(null);
            xpOrderClient.updateOrder(xpOrder);
            //发送订单状态
            SendMessageDTO dto = new SendMessageDTO();
            dto.setAppUserId(appUserId.toString());
            dto.setMessage("{\"type\":\"ORDER_STATUS\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"status\\\":3}\",\"timestamp\":\"176569945845456\"}");
            xpPushMessageClient.sendStatus(dto);
            //推送车辆位置
            dto.setMessage("{\"type\":\"VEHICLE_LOCATION\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"lon\\\":113.385848,\\\"lat\\\":23.156841}\",\"timestamp\":\"176569945845456\"}");
            xpPushMessageClient.sendVehicleLocation(dto);
            //发送车辆到达起点的轨迹
            RouteAndFareDto routeAndFareDto = new RouteAndFareDto();
            LonLatDto destination = new LonLatDto();
            destination.setLongitude(xpOrder.getStartLon());
            destination.setLatitude(xpOrder.getStartLat());
            routeAndFareDto.setDestination(destination);
            LonLatDto origin = new LonLatDto();
            origin.setLongitude(113.385848);
            origin.setLatitude(23.156841);
            routeAndFareDto.setOrigin(origin);
            routeAndFareDto.setOpenCityId(2L);
            RouteVo routeVo = xpMapClient.getDistanceAndDuration(routeAndFareDto).getData();
            com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject();
            jsonObject.put("type", "ORDER_ROUTE");
            jsonObject.put("timestamp", System.currentTimeMillis());
            com.alibaba.fastjson2.JSONObject content = new com.alibaba.fastjson2.JSONObject();
            content.put("orderId", orderId);
            content.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", collect);
            content.put("route", route.toJSONString());
            jsonObject.put("content", content.toJSONString());
            SendMessageDTO messageDTO = new SendMessageDTO();
            messageDTO.setAppUserId(appUserId.toString());
            messageDTO.setMessage(jsonObject.toJSONString());
            xpPushMessageClient.sendRoute(messageDTO);
            //等待10秒钟
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //司机到达起点
            xpOrder.setStatus(4);
            xpOrderClient.updateOrder(xpOrder);
            dto.setMessage("{\"type\":\"ORDER_STATUS\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"status\\\":4}\",\"timestamp\":\"176569945845456\"}");
            xpPushMessageClient.sendStatus(dto);
            //推送车辆位置到起点
            dto.setMessage("{\"type\":\"VEHICLE_LOCATION\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"lon\\\":" + xpOrder.getStartLon() + ",\\\"lat\\\":" + xpOrder.getStartLat() + "}\",\"timestamp\":\"176569945845456\"}");
            xpPushMessageClient.sendVehicleLocation(dto);
            //等待5秒钟
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //乘客上车
            xpOrder.setStatus(5);
            xpOrder.setBoardingTime(LocalDateTime.now());
            xpOrder.setBoardingLat(xpOrder.getStartLat());
            xpOrder.setBoardingLon(xpOrder.getStartLon());
            xpOrder.setBoardingAddress(xpOrder.getStartAddress());
            xpOrderClient.updateOrder(xpOrder);
            dto.setMessage("{\"type\":\"ORDER_STATUS\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"status\\\":5}\",\"timestamp\":\"176569945845456\"}");
            xpPushMessageClient.sendStatus(dto);
            //等待5秒钟
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //开始服务中
            xpOrder.setStatus(6);
            xpOrder.setTripBegin(LocalDateTime.now());
            xpOrderClient.updateOrder(xpOrder);
            dto.setMessage("{\"type\":\"ORDER_STATUS\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"status\\\":6}\",\"timestamp\":\"176569945845456\"}");
            xpPushMessageClient.sendStatus(dto);
            //推送起点到终点的行驶轨迹
            routeAndFareDto = new RouteAndFareDto();
            routeAndFareDto.setDestination(new LonLatDto(xpOrder.getEndLon(), xpOrder.getEndLat()));
            routeAndFareDto.setOrigin(new LonLatDto(xpOrder.getStartLon(), xpOrder.getStartLat()));
            routeAndFareDto.setOpenCityId(2L);
            routeVo = xpMapClient.getDistanceAndDuration(routeAndFareDto).getData();
            jsonObject = new com.alibaba.fastjson2.JSONObject();
            jsonObject.put("type", "ORDER_ROUTE");
            jsonObject.put("timestamp", System.currentTimeMillis());
            content = new com.alibaba.fastjson2.JSONObject();
            content.put("orderId", orderId);
            content.put("routeType", 2);
            route = new com.alibaba.fastjson2.JSONObject();
            route.put("distance", routeVo.getDistance());
            route.put("duration", routeVo.getDuration());
            route.put("routeID", routeVo.getRouteID());
            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", collect);
            content.put("route", route.toJSONString());
            jsonObject.put("content", content.toJSONString());
            messageDTO = new SendMessageDTO();
            messageDTO.setAppUserId(appUserId.toString());
            messageDTO.setMessage(jsonObject.toJSONString());
            xpPushMessageClient.sendRoute(messageDTO);
            //等到10秒钟
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //乘客待下车
            xpOrder.setStatus(7);
            xpOrder.setTripEnd(LocalDateTime.now());
            xpOrder.setGetoffLat(xpOrder.getEndLat());
            xpOrder.setGetoffLon(xpOrder.getEndLon());
            xpOrder.setGetoffAddress(xpOrder.getEndAddress());
            xpOrder.setGetoffTime(LocalDateTime.now());
            xpOrder.setOrderMoney(new BigDecimal(50));
            xpOrder.setStartMileage(5D);
            xpOrder.setStartMoney(new BigDecimal(10));
            xpOrder.setMileageKilometers(10D);
            xpOrder.setMileageMoney(new BigDecimal(25));
            xpOrder.setDuration(20D);
            xpOrder.setDurationMoney(new BigDecimal(5));
            xpOrder.setWait(0D);
            xpOrder.setWaitMoney(new BigDecimal(0));
            xpOrder.setLongDistance(10D);
            xpOrder.setLongDistanceType(1);
            xpOrder.setLongDistancemoney(new BigDecimal(10));
            xpOrderClient.updateOrder(xpOrder);
            //添加费用明细
//            XpOrderDetail detail = new XpOrderDetail();
//            detail.setDetailType(1);
//            detail.setOrderId(orderId);
//            detail.setType(1);
//            detail.setTime("");
//            detail.setDuration(20D);
//            detail.setMileage(new BigDecimal(10));
//            detail.setMoney();
//            detail.setIsDeleted(false);
//            detail.setCreateTime(LocalDateTime.now());
//            detail.setUpdateTime(LocalDateTime.now());
//            xpOrder
            //推送车辆位置到起点
            dto.setMessage("{\"type\":\"VEHICLE_LOCATION\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"lon\\\":" + xpOrder.getEndLon() + ",\\\"lat\\\":" + xpOrder.getEndLat() + "}\",\"timestamp\":\"176569945845456\"}");
            xpPushMessageClient.sendVehicleLocation(dto);
            dto.setMessage("{\"type\":\"ORDER_STATUS\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"status\\\":7}\",\"timestamp\":\"176569945845456\"}");
            xpPushMessageClient.sendStatus(dto);
            //等到5秒钟
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //乘客待支付
            xpOrder.setStatus(8);
            xpOrderClient.updateOrder(xpOrder);
            dto.setMessage("{\"type\":\"ORDER_STATUS\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"status\\\":8}\",\"timestamp\":\"176569945845456\"}");
            xpPushMessageClient.sendStatus(dto);
            //等到5秒钟
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //乘客支付成功
            xpOrder.setStatus(9);
            xpOrderClient.updateOrder(xpOrder);
            dto.setMessage("{\"type\":\"ORDER_STATUS\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"status\\\":9}\",\"timestamp\":\"176569945845456\"}");
            xpPushMessageClient.sendStatus(dto);
        });
    }
}