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);
|
}
|
|
}
|