liujie
2026-03-09 65cc684c4c1f4a2d028d4ed5b92994f17492401e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.xiaopeng.maintenance.controller;
 
import cn.hutool.core.util.IdUtil;
import com.xiaopeng.api.dto.automaticPilot.PushOrderDto;
import com.xiaopeng.api.dto.operation.NewCruiseOrderDto;
import com.xiaopeng.api.feignClient.automaticPilot.OrderMissionClient;
import com.xiaopeng.api.feignClient.operation.XpCruisePlanClient;
import com.xiaopeng.api.feignClient.order.XpCruiseOrderClient;
import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient;
import com.xiaopeng.api.model.order.XpCruiseOrder;
import com.xiaopeng.api.model.vehicleConvoy.XpVehicle;
import com.xiaopeng.api.vo.OrderType;
import com.xiaopeng.api.vo.automaticPilot.VehiclePosition;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.web.page.PageInfo;
import com.xiaopeng.maintenance.dto.VehicleDispatchAcceptDTO;
import com.xiaopeng.maintenance.dto.VehicleDispatchDepartureDTO;
import com.xiaopeng.maintenance.model.query.OperationRecordsQuery;
import com.xiaopeng.maintenance.model.vo.OperationRecordsVO;
import com.xiaopeng.maintenance.service.IXpVehiclePreparationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
 
/**
 * <p>
 * 车辆管理 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2026-02-03
 */
@Slf4j
@RestController
@Api(tags = "车辆运维")
public class XpVehicleOperationsController {
 
    @Resource
    private IXpVehiclePreparationService xpVehiclePreparationService;
    @Resource
    private XpVehicleClient xpVehicleClient;
    @Resource
    private XpCruiseOrderClient xpCruiseOrderClient;
    @Resource
    private MongoTemplate mongoTemplate;
    @Resource
    private OrderMissionClient orderMissionClient;
    @Autowired
    private XpCruisePlanClient xpCruisePlanClient;
 
    /**
     * 车辆详情-车辆调度-发车 收车
     */
    @ApiOperation(value = "车辆运维-车辆调度-发车/收车", tags = {"运维APP-车辆管理"})
    @PostMapping("/api/v1/vehicle/vehicleDispatchDeparture")
    public R<String> vehicleDispatchDeparture(@RequestBody VehicleDispatchDepartureDTO dto) {
 
        // 判断是否有正在进行的正常订单
        // 查询车辆
        XpVehicle xpVehicle = xpVehicleClient.queryById(dto.getVehicleId()).getData();
        if(xpVehicle.getState()==1){
            return R.fail("车辆正在接单中");
        }
        xpVehicle.setOperatingStatus(dto.getDepartureStatus());
        xpVehicleClient.updateVehicleById(xpVehicle);
 
        // 发车
        if(dto.getDepartureStatus()==1){
            // 找车辆的任务  生成巡游单子 下发命令
            R<XpCruiseOrder> newCruiseOrder = xpCruisePlanClient.getNewCruiseOrder(new NewCruiseOrderDto(xpVehicle.getId(),xpVehicle.getVehicleVin(),xpVehicle.getFleetId()));
            if(newCruiseOrder.getData()!=null){
                // 下发命令
                PushOrderDto pushOrderDto = new PushOrderDto();
                pushOrderDto.setVin(xpVehicle.getVehicleVin());
                pushOrderDto.setOrderId(newCruiseOrder.getData().getId());
                pushOrderDto.setStartLatitude(newCruiseOrder.getData().getStartLat());
                pushOrderDto.setStartLongitude(newCruiseOrder.getData().getStartLon());
                pushOrderDto.setEndLatitude(newCruiseOrder.getData().getEndLat());
                pushOrderDto.setEndLongitude(newCruiseOrder.getData().getEndLon());
                pushOrderDto.setOrderType(OrderType.CRUISE_ORDER);
                pushOrderDto.setStage(2);
                orderMissionClient.pushOrder(pushOrderDto);
            }
 
 
        }else if(dto.getDepartureStatus()==3){
            // 收车 关闭当前巡游单子 生成新的返程单子  找到收车站点
            R<String> r = xpCruiseOrderClient.updateCruiseOrder(xpVehicle.getVehicleVin());
 
            // redis 获取当前最新经纬度位置
            VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class);
            XpCruiseOrder xpCruiseOrder = new XpCruiseOrder();
            if(vehiclePosition!=null){
                double x = vehiclePosition.getPoint().getX();
                double y = vehiclePosition.getPoint().getY();
                xpCruiseOrder.setStartLon(x);
                xpCruiseOrder.setStartLat(y);
            }
 
            xpCruiseOrder.setId("XU"+ IdUtil.fastUUID());
            xpCruiseOrder.setVehicleId(xpVehicle.getId());
            xpCruiseOrder.setFleetId(xpVehicle.getFleetId());
            xpCruiseOrder.setOrderType(2);
            xpCruiseOrder.setStatus(1);
            xpCruiseOrder.setOrderReverse(1);
            xpCruiseOrder.setLastOrderId(r.getData());
 
            // 找到收车站点
            R<XpCruiseOrder> returnCruisePoint = xpCruisePlanClient.findReturnCruisePoint(xpCruiseOrder);
            if(returnCruisePoint!=null){
                xpCruiseOrderClient.addCruiseOrder(returnCruisePoint.getData());
                // 下发命令
                PushOrderDto pushOrderDto = new PushOrderDto();
                pushOrderDto.setVin(returnCruisePoint.getData().getVehicleVin());
                pushOrderDto.setOrderId(returnCruisePoint.getData().getId());
                pushOrderDto.setStartLatitude(returnCruisePoint.getData().getStartLat());
                pushOrderDto.setStartLongitude(returnCruisePoint.getData().getStartLon());
                pushOrderDto.setEndLatitude(returnCruisePoint.getData().getEndLat());
                pushOrderDto.setEndLongitude(returnCruisePoint.getData().getEndLon());
                pushOrderDto.setOrderType(OrderType.CRUISE_ORDER);
                pushOrderDto.setStage(2);
                orderMissionClient.pushOrder(pushOrderDto);
            }
 
        }
        return R.ok();
    }
 
    /**
     * 车辆详情-车辆调度-接单、测试
     */
    @ApiOperation(value = "车辆运维-车辆调度-接单、测试", tags = {"运维APP-车辆管理"})
    @PostMapping("/api/v1/vehicle/vehicleDispatchAccept")
    public R<String> vehicleDispatchAccept(@RequestBody VehicleDispatchAcceptDTO dto) {
        // 查询车辆
        XpVehicle xpVehicle = xpVehicleClient.queryById(dto.getVehicleId()).getData();
        xpVehicle.setAcceptOrTest(dto.getAcceptOrTest());
        xpVehicle.setAcceptOrTestStatus(dto.getAcceptOrTestStatus());
        xpVehicleClient.updateVehicleById(xpVehicle);
        return R.ok();
    }
 
    /**
     * 车辆详情-车辆调度-运维记录
     */
    @ApiOperation(value = "车辆运维-车辆调度-运维记录", tags = {"运维APP-车辆管理"})
    @PostMapping("/api/v1/vehicle/operationRecords")
    public R<PageInfo<OperationRecordsVO>> operationRecords(@Validated @RequestBody OperationRecordsQuery query) {
        PageInfo<OperationRecordsVO> operationRecords = xpVehiclePreparationService.operationRecords(query);
        return R.ok(operationRecords);
    }
 
}