Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
89cefb5a8a |
12
pom.xml
12
pom.xml
|
|
@ -71,6 +71,18 @@
|
||||||
<artifactId>ruoyi-common-swagger</artifactId>
|
<artifactId>ruoyi-common-swagger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- RuoYi API Task -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>tuoheng-api-task</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- RuoYi API Device -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>tuoheng-api-device</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
package com.ruoyi.job.task;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.device.api.RemoteAircraftFlyService;
|
||||||
|
import com.ruoyi.device.api.domain.DroneTakeoffRequest;
|
||||||
|
import com.ruoyi.task.api.RemoteTaskService;
|
||||||
|
import com.ruoyi.task.api.domain.TaskVO;
|
||||||
|
import com.ruoyi.task.api.domain.TaskResultVO;
|
||||||
|
import com.ruoyi.task.api.enums.StatusEnum;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 飞行任务自动执行调度
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Component("taskAutoExecuteJob")
|
||||||
|
public class TaskAutoExecuteJob {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(TaskAutoExecuteJob.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RemoteTaskService remoteTaskService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RemoteAircraftFlyService remoteAircraftFlyService;
|
||||||
|
|
||||||
|
public void execute() {
|
||||||
|
try {
|
||||||
|
log.info("开始扫描待执行的飞行任务");
|
||||||
|
|
||||||
|
String source = SecurityConstants.INNER;
|
||||||
|
R<List<TaskVO>> response = remoteTaskService.getPendingTasksForAutoExecute(source);
|
||||||
|
|
||||||
|
if (response == null || response.getData() == null || response.getData().isEmpty()) {
|
||||||
|
log.info("没有待执行的飞行任务");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TaskVO> tasks = response.getData();
|
||||||
|
log.info("找到 {} 个待执行的飞行任务 {} ", tasks.size(), JSON.toJSONString(tasks));
|
||||||
|
//暂时注释掉
|
||||||
|
// for (TaskVO task : tasks) {
|
||||||
|
// executeTask(task, source);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.info("飞行任务自动执行完成");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("飞行任务自动执行异常", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeTask(TaskVO task, String source) {
|
||||||
|
try {
|
||||||
|
log.info("开始执行任务: taskId={}, taskName={}, startTime={}",
|
||||||
|
task.getId(), task.getTaskName(), task.getStartTime());
|
||||||
|
|
||||||
|
DroneTakeoffRequest request = new DroneTakeoffRequest();
|
||||||
|
request.setTaskId(task.getId());
|
||||||
|
request.setAirlineFileUrl(task.getRouteUrl());
|
||||||
|
request.setSn(task.getUavId());
|
||||||
|
|
||||||
|
remoteAircraftFlyService.takeoff(request);
|
||||||
|
|
||||||
|
log.info("任务 {} 起飞命令已发送,更新状态为 CHECKING", task.getId());
|
||||||
|
|
||||||
|
remoteTaskService.updateTaskStatus(task.getId(), TaskResultVO.Checking(), source);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("任务 {} 执行异常,更新状态为 FAILED", task.getId(), e);
|
||||||
|
remoteTaskService.updateTaskStatus(task.getId(), TaskResultVO.Error(e.getMessage()), source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue