package com.mes.interaction.vehicle.model;
|
|
import lombok.Data;
|
import java.time.LocalDateTime;
|
|
/**
|
* 车辆运行时状态
|
* 每个设备实例有独立的状态对象
|
*
|
* @author huang
|
* @since 2025-11-21
|
*/
|
@Data
|
public class VehicleStatus {
|
/**
|
* 设备ID(对应DeviceConfig.deviceId)
|
*/
|
private String deviceId;
|
|
/**
|
* 设备名称
|
*/
|
private String deviceName;
|
|
/**
|
* 当前状态
|
*/
|
private VehicleState state;
|
|
/**
|
* 当前位置
|
*/
|
private VehiclePosition currentPosition;
|
|
/**
|
* 目标位置
|
*/
|
private VehiclePosition targetPosition;
|
|
/**
|
* 当前速度
|
*/
|
private Double speed;
|
|
/**
|
* 任务开始时间
|
*/
|
private LocalDateTime taskStartTime;
|
|
/**
|
* 预计结束时间
|
*/
|
private LocalDateTime estimatedEndTime;
|
|
/**
|
* 当前任务
|
*/
|
private VehicleTask currentTask;
|
|
/**
|
* 最后更新时间
|
*/
|
private LocalDateTime lastUpdateTime;
|
|
public VehicleStatus() {
|
this.state = VehicleState.IDLE;
|
this.lastUpdateTime = LocalDateTime.now();
|
}
|
|
public VehicleStatus(String deviceId) {
|
this();
|
this.deviceId = deviceId;
|
}
|
|
public VehicleStatus(String deviceId, String deviceName) {
|
this(deviceId);
|
this.deviceName = deviceName;
|
}
|
|
/**
|
* 更新状态
|
*/
|
public void setState(VehicleState newState) {
|
this.state = newState;
|
this.lastUpdateTime = LocalDateTime.now();
|
|
if (newState == VehicleState.EXECUTING && currentTask != null) {
|
this.taskStartTime = LocalDateTime.now();
|
currentTask.setStartTime(taskStartTime);
|
currentTask.calculateEstimatedEndTime();
|
this.estimatedEndTime = currentTask.getEstimatedEndTime();
|
} else if (newState == VehicleState.IDLE) {
|
this.taskStartTime = null;
|
this.estimatedEndTime = null;
|
this.currentTask = null;
|
}
|
}
|
|
/**
|
* 检查是否可用
|
*/
|
public boolean isAvailable() {
|
return state == VehicleState.IDLE;
|
}
|
|
/**
|
* 检查是否正在执行
|
*/
|
public boolean isExecuting() {
|
return state == VehicleState.EXECUTING;
|
}
|
}
|