2026-02-25 13:06:56 +08:00
|
|
|
|
package com.ruoyi.device.service.impl;
|
|
|
|
|
|
|
2026-03-10 10:47:15 +08:00
|
|
|
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
|
|
|
|
|
import com.ruoyi.common.core.domain.R;
|
2026-02-25 13:06:56 +08:00
|
|
|
|
import com.ruoyi.device.mapper.FlightLogMapper;
|
|
|
|
|
|
import com.ruoyi.device.mapper.FlightMapper;
|
|
|
|
|
|
import com.ruoyi.device.mapper.PreCheckLogMapper;
|
|
|
|
|
|
import com.ruoyi.device.mapper.entity.FlightEntity;
|
|
|
|
|
|
import com.ruoyi.device.mapper.entity.FlightLogEntity;
|
|
|
|
|
|
import com.ruoyi.device.mapper.entity.PreCheckLogEntity;
|
|
|
|
|
|
import com.ruoyi.device.service.FlightService;
|
2026-03-10 10:47:15 +08:00
|
|
|
|
import com.ruoyi.task.api.RemoteTaskService;
|
2026-03-23 18:20:31 +08:00
|
|
|
|
import com.ruoyi.task.api.domain.TaskResultVO;
|
2026-03-14 11:04:00 +08:00
|
|
|
|
import com.ruoyi.task.api.domain.TaskVO;
|
2026-03-10 10:47:15 +08:00
|
|
|
|
import com.ruoyi.task.api.enums.ExecuteTypeEnum;
|
|
|
|
|
|
import com.ruoyi.task.api.enums.StatusEnum;
|
|
|
|
|
|
import com.ruoyi.task.api.enums.TaskCategoryEnum;
|
2026-03-10 15:42:32 +08:00
|
|
|
|
import com.ruoyi.task.api.enums.TaskTypeEnum;
|
2026-02-25 13:06:56 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
2026-03-10 10:47:15 +08:00
|
|
|
|
import java.util.*;
|
2026-02-25 13:06:56 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 飞行服务实现类
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author ruoyi
|
|
|
|
|
|
* @date 2026-02-25
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class FlightServiceImpl implements FlightService
|
|
|
|
|
|
{
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private FlightMapper flightMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private PreCheckLogMapper preCheckLogMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private FlightLogMapper flightLogMapper;
|
|
|
|
|
|
|
2026-03-10 10:47:15 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private RemoteTaskService remoteTaskService;
|
|
|
|
|
|
|
2026-03-10 15:56:15 +08:00
|
|
|
|
|
|
|
|
|
|
public Long currentRunningTask(String sn){
|
2026-03-14 11:04:00 +08:00
|
|
|
|
R<TaskVO> taskDTOR = remoteTaskService.getCurrentTaskByUavId(sn,SecurityConstants.INNER);
|
2026-03-10 15:56:15 +08:00
|
|
|
|
return taskDTOR.getData().getId();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-10 14:56:42 +08:00
|
|
|
|
public Long createClickTakeOffTask(String sn, String routeUrl){
|
2026-03-14 11:04:00 +08:00
|
|
|
|
TaskVO taskVO = new TaskVO();
|
|
|
|
|
|
taskVO.setTaskName("一键起飞");
|
|
|
|
|
|
taskVO.setActualStartTime(new Date());
|
|
|
|
|
|
taskVO.setStartTime(new Date());
|
2026-03-10 15:08:51 +08:00
|
|
|
|
|
2026-03-14 11:04:00 +08:00
|
|
|
|
taskVO.setExecuteType(ExecuteTypeEnum.ONCE);
|
|
|
|
|
|
taskVO.setTaskCategory(TaskCategoryEnum.MANUAL);
|
|
|
|
|
|
taskVO.setTaskType(TaskTypeEnum.ONE_CLICK);
|
2026-03-10 15:08:51 +08:00
|
|
|
|
|
2026-03-14 11:04:00 +08:00
|
|
|
|
taskVO.setRouteId(-1L);
|
|
|
|
|
|
taskVO.setUavId(sn);
|
2026-03-10 15:08:51 +08:00
|
|
|
|
|
2026-03-14 11:04:00 +08:00
|
|
|
|
taskVO.setStatus(StatusEnum.PENDING);
|
|
|
|
|
|
taskVO.setRouteUrl(routeUrl);
|
2026-03-10 15:08:51 +08:00
|
|
|
|
|
2026-03-14 11:04:00 +08:00
|
|
|
|
R<Long> taskId = remoteTaskService.createTaskWithoutPlan(taskVO,SecurityConstants.INNER);
|
2026-03-10 14:56:42 +08:00
|
|
|
|
|
2026-03-10 10:47:15 +08:00
|
|
|
|
return taskId.getData();
|
|
|
|
|
|
}
|
2026-02-25 13:06:56 +08:00
|
|
|
|
|
2026-03-10 14:56:42 +08:00
|
|
|
|
//// @Override
|
|
|
|
|
|
//// @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
// public FlightEntity getOrCreateFlightByMessageId(String deviceSn, String messageId) {
|
|
|
|
|
|
// // 先查询是否存在相同 deviceSn 和 flight_id_extern 的记录
|
|
|
|
|
|
// FlightEntity flight = flightMapper.selectFlightByDeviceSnAndFlightIdExternal(deviceSn, messageId);
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (flight != null) {
|
|
|
|
|
|
// // 如果存在,直接返回
|
|
|
|
|
|
// log.info("找到已存在的飞行记录: deviceSn={}, messageId={}, flightId={}",
|
|
|
|
|
|
// deviceSn, messageId, flight.getFlightId());
|
|
|
|
|
|
// return flight;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// // 如果不存在,创建新的飞行记录
|
|
|
|
|
|
// flight = new FlightEntity();
|
|
|
|
|
|
// flight.setDeviceSn(deviceSn);
|
|
|
|
|
|
// flight.setFlightIdExternal(messageId);
|
|
|
|
|
|
// flight.setStatus("CHECKING");
|
|
|
|
|
|
// flightMapper.insertFlight(flight);
|
|
|
|
|
|
//
|
|
|
|
|
|
// log.info("创建新的飞行记录: deviceSn={}, messageId={}, flightId={}, status=CHECKING",
|
|
|
|
|
|
// deviceSn, messageId, flight.getFlightId());
|
|
|
|
|
|
//
|
|
|
|
|
|
// return flight;
|
|
|
|
|
|
// }
|
2026-02-25 13:06:56 +08:00
|
|
|
|
|
2026-03-10 10:47:15 +08:00
|
|
|
|
// @Override
|
|
|
|
|
|
// public FlightEntity getLatestFlight(String deviceSn) {
|
|
|
|
|
|
// return flightMapper.selectLatestFlightByDeviceSn(deviceSn);
|
|
|
|
|
|
// }
|
2026-02-28 10:05:38 +08:00
|
|
|
|
|
2026-02-25 13:06:56 +08:00
|
|
|
|
|
2026-03-10 10:47:15 +08:00
|
|
|
|
//
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
// public void updateFlightIdExternal(Long flightId, String flightIdExternal) {
|
|
|
|
|
|
// FlightEntity flight = new FlightEntity();
|
|
|
|
|
|
// flight.setFlightId(flightId);
|
|
|
|
|
|
// flight.setFlightIdExternal(flightIdExternal);
|
|
|
|
|
|
// flightMapper.updateFlight(flight);
|
|
|
|
|
|
// log.info("更新飞行ID: flightId={}, flightIdExternal={}", flightId, flightIdExternal);
|
|
|
|
|
|
// }
|
2026-02-25 13:06:56 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
2026-03-23 18:20:31 +08:00
|
|
|
|
public void updateFlightStatus(Long flightId, TaskResultVO status) {
|
2026-02-25 13:06:56 +08:00
|
|
|
|
|
2026-03-10 14:56:42 +08:00
|
|
|
|
remoteTaskService.updateTaskStatus(flightId,status,SecurityConstants.INNER);
|
2026-03-14 11:22:11 +08:00
|
|
|
|
|
2026-02-25 13:06:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-14 11:22:11 +08:00
|
|
|
|
|
2026-02-25 13:06:56 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Map<String, Object> getLatestFlightWithLogs(String deviceSn) {
|
2026-03-14 11:22:11 +08:00
|
|
|
|
|
|
|
|
|
|
R<TaskVO> taskVo = remoteTaskService.getCurrentTaskByUavId(deviceSn,SecurityConstants.INNER);
|
2026-02-25 13:06:56 +08:00
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
2026-03-14 11:22:11 +08:00
|
|
|
|
if(taskVo.getData()!=null){
|
|
|
|
|
|
TaskVO task = taskVo.getData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.put("flightId", task.getId());
|
|
|
|
|
|
result.put("deviceSn", deviceSn);
|
|
|
|
|
|
result.put("status", task.getStatus());
|
|
|
|
|
|
result.put("returnTime", task.getActualEndTime());
|
|
|
|
|
|
result.put("createTime", task.getActualStartTime());
|
|
|
|
|
|
|
|
|
|
|
|
List<PreCheckLogEntity> preCheckLogs = preCheckLogMapper.selectPreCheckLogListByFlightId(task.getId());
|
2026-02-28 09:42:28 +08:00
|
|
|
|
List<Map<String, Object>> preCheckLogsWithExecTime = new ArrayList<>();
|
2026-03-14 11:22:11 +08:00
|
|
|
|
|
|
|
|
|
|
Long execTime = null;
|
|
|
|
|
|
if (!preCheckLogs.isEmpty() && preCheckLogs.size() > 1) {
|
|
|
|
|
|
Date firstTime = preCheckLogs.get(0).getCreateTime();
|
|
|
|
|
|
Date lastTime = preCheckLogs.get(preCheckLogs.size() - 1).getCreateTime();
|
|
|
|
|
|
if (firstTime != null && lastTime != null) {
|
|
|
|
|
|
execTime = lastTime.getTime() - firstTime.getTime();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-02-28 09:42:28 +08:00
|
|
|
|
|
|
|
|
|
|
for (PreCheckLogEntity log : preCheckLogs) {
|
|
|
|
|
|
Map<String, Object> logMap = new HashMap<>();
|
|
|
|
|
|
logMap.put("logId", log.getLogId());
|
|
|
|
|
|
logMap.put("flightId", log.getFlightId());
|
|
|
|
|
|
logMap.put("logContent", log.getLogContent());
|
|
|
|
|
|
logMap.put("success", log.getSuccess());
|
|
|
|
|
|
logMap.put("createTime", log.getCreateTime());
|
|
|
|
|
|
logMap.put("updateTime", log.getUpdateTime());
|
|
|
|
|
|
preCheckLogsWithExecTime.add(logMap);
|
|
|
|
|
|
}
|
2026-03-14 11:22:11 +08:00
|
|
|
|
result.put("execTime", execTime);
|
2026-02-28 09:42:28 +08:00
|
|
|
|
result.put("preCheckLogs", preCheckLogsWithExecTime);
|
2026-02-25 13:06:56 +08:00
|
|
|
|
|
2026-03-14 11:22:11 +08:00
|
|
|
|
List<FlightLogEntity> flightLogs = flightLogMapper.selectFlightLogListByFlightId(task.getId());
|
2026-02-25 13:06:56 +08:00
|
|
|
|
result.put("flightLogs", flightLogs);
|
|
|
|
|
|
|
2026-03-14 11:22:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-25 13:06:56 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void insertPreCheckLog(PreCheckLogEntity logEntity) {
|
2026-02-27 08:58:36 +08:00
|
|
|
|
log.info("【FlightServiceImpl】准备插入自检日志: flightId={}, logContent={}, success={}",
|
|
|
|
|
|
logEntity.getFlightId(), logEntity.getLogContent(), logEntity.getSuccess());
|
|
|
|
|
|
|
|
|
|
|
|
int rows = preCheckLogMapper.insertPreCheckLog(logEntity);
|
|
|
|
|
|
|
|
|
|
|
|
if (rows > 0) {
|
|
|
|
|
|
log.info("【FlightServiceImpl】成功插入自检日志: flightId={}, logId={}, rows={}",
|
|
|
|
|
|
logEntity.getFlightId(), logEntity.getLogId(), rows);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
log.error("【FlightServiceImpl】插入自检日志失败,影响行数为0: flightId={}, logContent={}",
|
|
|
|
|
|
logEntity.getFlightId(), logEntity.getLogContent());
|
|
|
|
|
|
}
|
2026-02-25 13:06:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void insertFlightLog(FlightLogEntity logEntity) {
|
2026-02-27 08:58:36 +08:00
|
|
|
|
log.info("【FlightServiceImpl】准备插入飞行日志: flightId={}, logContent={}",
|
|
|
|
|
|
logEntity.getFlightId(), logEntity.getLogContent());
|
|
|
|
|
|
|
|
|
|
|
|
int rows = flightLogMapper.insertFlightLog(logEntity);
|
|
|
|
|
|
|
|
|
|
|
|
if (rows > 0) {
|
|
|
|
|
|
log.info("【FlightServiceImpl】成功插入飞行日志: flightId={}, logId={}, rows={}",
|
|
|
|
|
|
logEntity.getFlightId(), logEntity.getLogId(), rows);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
log.error("【FlightServiceImpl】插入飞行日志失败,影响行数为0: flightId={}, logContent={}",
|
|
|
|
|
|
logEntity.getFlightId(), logEntity.getLogContent());
|
|
|
|
|
|
}
|
2026-02-25 13:06:56 +08:00
|
|
|
|
}
|
2026-02-27 15:30:09 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean hasFlightLog(Long flightId) {
|
|
|
|
|
|
int count = flightLogMapper.countFlightLogByFlightId(flightId);
|
|
|
|
|
|
return count > 0;
|
|
|
|
|
|
}
|
2026-02-25 13:06:56 +08:00
|
|
|
|
}
|