Browse Source

完成定时任务

tags/v1.1.0
qiujinyang 2 years ago
parent
commit
94bfd82e30
4 changed files with 70 additions and 2 deletions
  1. +3
    -0
      tuoheng-admin/src/main/java/com/tuoheng/admin/AdminApplication.java
  2. +5
    -0
      tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/ThMission.java
  3. +2
    -2
      tuoheng-admin/src/main/java/com/tuoheng/admin/service/IThInspectionService.java
  4. +60
    -0
      tuoheng-admin/src/main/java/com/tuoheng/admin/task/ScheduledTask.java

+ 3
- 0
tuoheng-admin/src/main/java/com/tuoheng/admin/AdminApplication.java View File

@@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.oas.annotations.EnableOpenApi;

@@ -14,6 +15,8 @@ import springfox.documentation.oas.annotations.EnableOpenApi;
@MapperScan("com.tuoheng.**.mapper")
@EnableTransactionManagement
@EnableOpenApi
// 开启定时任务支持
@EnableScheduling
public class AdminApplication {

public static void main(String[] args) {

+ 5
- 0
tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/ThMission.java View File

@@ -163,6 +163,11 @@ public class ThMission extends BaseEntity implements Serializable {
*/
private Double progressbar;

/**
* 执行状态,1:执行过,2:未执行
*/
private Integer executionStatus;

/**
* 备注
*/

+ 2
- 2
tuoheng-admin/src/main/java/com/tuoheng/admin/service/IThInspectionService.java View File

@@ -26,9 +26,9 @@ public interface IThInspectionService extends IBaseService<ThInspection> {

List<AirLineVO> airLine(Integer droneId) throws ServiceException;

JsonResult executeTask(String taskId) throws ServiceException;

AirWeatherVO getWeather(Integer airportId);

JsonResult executeTask(String taskId) throws ServiceException;

JsonResult lineTrack(Integer missionId);
}

+ 60
- 0
tuoheng-admin/src/main/java/com/tuoheng/admin/task/ScheduledTask.java View File

@@ -0,0 +1,60 @@
package com.tuoheng.admin.task;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.entity.domain.ThMission;
import com.tuoheng.admin.enums.MarkTypeEnum;
import com.tuoheng.admin.enums.TaskStatusEnum;
import com.tuoheng.admin.mapper.ThMissionMapper;
import com.tuoheng.admin.service.IMissionService;
import com.tuoheng.admin.service.IThInspectionService;
import com.tuoheng.common.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Component
@Slf4j
public class ScheduledTask {

@Autowired
private ThMissionMapper missionMapper;

@Autowired
private IThInspectionService inspectionService;


private final static SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


/* @Scheduled(fixedRate = 3000)
public void scheduledTask() {

log.info("执行定时执行飞行任务:" + LocalDateTime.now());



List<ThMission> thMissions = missionMapper.selectList(new LambdaQueryWrapper<ThMission>()
.eq(ThMission::getMark, MarkTypeEnum.VALID.getCode())
.ge(ThMission::getExecutionStartTime, dateformat.format(new Date()))
.ge(ThMission::getExecutionStatus, 1)
.eq(ThMission::getStatus, TaskStatusEnum.WAIT.getCode()));

log.info("三秒钟一次");

for (ThMission thMission : thMissions) {
JsonResult jsonResult = inspectionService.executeTask(String.valueOf(thMission.getId()));
thMission.setExecutionStatus(2);
if(jsonResult.getCode()!=0 && ObjectUtil.isEmpty(jsonResult.getData())){
thMission.setStatus(TaskStatusEnum.FAIL.getCode());
}
missionMapper.updateById(thMission);
}
}*/
}

Loading…
Cancel
Save