src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -17,9 +17,13 @@
import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils;
import com.dji.sample.territory.pojo.TerritoryConfigPojo;
import com.dji.sample.territory.service.ITbFJService;
import com.dji.sample.wayline.dao.IWaylineJobBreakPointMapper;
import com.dji.sample.wayline.dao.IWaylineJobMapper;
import com.dji.sample.wayline.model.dto.WaylineFileDTO;
import com.dji.sample.wayline.model.dto.WaylineJobDTO;
import com.dji.sample.wayline.model.entity.WaylineFileEntity;
import com.dji.sample.wayline.model.entity.WaylineJobBreakPointEntity;
import com.dji.sample.wayline.model.entity.WaylineJobEntity;
import com.dji.sample.wayline.model.param.CreateJobParam;
import com.dji.sample.wayline.service.IWaylineFileService;
import com.dji.sample.wayline.service.IWaylineJobBreakPointService;
@@ -39,16 +43,13 @@
import org.springframework.web.multipart.MultipartFile;
import java.nio.file.StandardCopyOption;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.*;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ExecutorService;
@@ -69,7 +70,8 @@
    private PatchesConfigPojo patchesConfigPojo;
    @Autowired
    public IWaylineFileService waylineFileService;
    @Autowired
    private IWaylineJobService waylineJobService;
    @Autowired
    private ITbFJService tbFJService;
    @Autowired
@@ -78,7 +80,10 @@
    @Autowired
    private GetPatchesMapper patchesMapper;
    @Autowired
    private IWaylineJobService waylineJobService;
    private IWaylineJobMapper waylineJobMapper;
    @Autowired
    private IWaylineJobBreakPointMapper jobBreakPointMapper;
    @Autowired
    private TerritoryConfigPojo territoryConfigPojo;
    @Autowired
@@ -87,6 +92,7 @@
    private IDeviceMapper deviceMapper;
    @Autowired
    private DbUploadMapper dbUploadMapper;
    /**
     * 定时器,将没有规划的图斑生成航线,并将航线飞完后的成果数据进行保存推送
     *
@@ -141,6 +147,16 @@
        executor.shutdown();
    }
    @Scheduled(cron = "0 45 8-18 * * ?")
    public void runTask() throws SQLException {
        WaylineJobEntity job = processWaylineJobs();
        if (job != null) {
            // 调用其他方法进行后续处理
            handleJobId(job);
        } else {
            System.out.println("未找到符合条件的对象");
        }
    }
    //    public void myTask3() throws SQLException {
//        String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
//        String name = getNowDay();
@@ -283,6 +299,7 @@
        }
    }
    @Scheduled(cron = "0 3 17 * * ?")
   public void GtdbOperation() throws Exception {
    String taskId = "";
@@ -364,7 +381,7 @@
     * @return
     */
    public WaylineFileEntity backWayline(MultipartFile multipartFile, String waylineName, String workspaceId, String username) {
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, username);
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, username, 1);
        WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
        try {
            waylineFileService.getObjectUrl(workspaceId, entity.getWaylineId());
@@ -417,6 +434,7 @@
                .eq(LotInfo::getWorkspaceId, workspaceId));
        return groupTasks(list);
    }
    public List<List<LotInfo>> getNoPush() {
        List<LotInfo> list = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>()
                .eq(LotInfo::getIsPush, 0)
@@ -596,6 +614,7 @@
      DeviceEntity entity=  deviceMapper.selectOne(new LambdaQueryWrapper<DeviceEntity>().eq(DeviceEntity::getDeviceSn,docksn));
      return entity.getWorkspaceId();
    }
    public static void sendPostWithParameters(String name, String fileId, String time, List<Long> taskDays, List<List<Long>> taskPeriods) throws IOException {
        try {
            RestTemplate restTemplate = new RestTemplate();
@@ -725,6 +744,7 @@
            throw new RuntimeException("Db文件复制失败", e); // 捕获并抛出原始异常
        }
    }
    public String dbSaveGt(String path, String folder, String taskId) {
        try {
            String fileName = taskId + ".db";
@@ -766,6 +786,7 @@
        }
        return folder;
    }
    private static File fileFold(String fold,String taskId) {
        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();
@@ -782,6 +803,7 @@
        }
        return folder;
    }
    public static Long getCurrentTimestampPlus8Hours(long hours) {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
@@ -796,12 +818,13 @@
        // 将毫秒级时间戳转换为秒级时间戳
        return timestamp / 1000;
    }
    public static long getNextDayEightAMTimestamp(int hour) {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        // 获取第二天的日期并设置时间为08:00
        LocalDateTime nextDayEightAM = now.plusDays(1).withHour(8).withMinute(0).withSecond(0).withNano(0);
        LocalDateTime nextDayEightAM = now.plusDays(1).withHour(8).withMinute(30).withSecond(0).withNano(0);
        // 根据传入的hour参数增加小时
        LocalDateTime adjustedTime = nextDayEightAM.plusHours(hour);
@@ -811,7 +834,17 @@
        return zonedDateTime.toEpochSecond();
    }
    public static long getAdjustedTimestamp(int hour) {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        // 根据传入的hour参数增加小时
        LocalDateTime adjustedTime = now.plusSeconds(hour);
        // 转换为时间戳(秒级)
        ZonedDateTime zonedDateTime = adjustedTime.atZone(ZoneId.systemDefault());
        return zonedDateTime.toEpochSecond();
    }
    public static Long addOneHourToTimestamp(Long timestampInSeconds, long hours, long min) {
        // 将输入的秒级时间戳转换为Instant对象
        Instant instant = Instant.ofEpochSecond(timestampInSeconds);
@@ -857,6 +890,7 @@
        // 格式化时间,生成当前时间
        return currentTime.format(DateTimeFormatter.ofPattern("MMddHHmmssSSS"));
    }
    public static long getFileSize(File file) {
        if (file == null || !file.exists() || !file.isFile()) {
            return -1L; // 文件不存在或不是普通文件
@@ -869,8 +903,46 @@
        long size = getFileSize(file);
        System.out.println("文件大小: " + size + " 字节");
    }
    public static void  getFileInfo(File file){
        long size=getFileSize(file);
    }
    public WaylineJobEntity processWaylineJobs() {
        // 获取昨天 00:00 和 23:59:59 的时间戳
        LocalDate yesterday = LocalDate.now().minusDays(1);
        long startOfDayMillis = LocalDateTime.of(yesterday, LocalTime.MIN).toInstant(ZoneOffset.UTC).toEpochMilli();
        long endOfDayMillis = LocalDateTime.of(yesterday, LocalTime.MAX).toInstant(ZoneOffset.UTC).toEpochMilli();
        // 查询符合条件的 wayline_job_break_point 对象
        List<WaylineJobBreakPointEntity> breakPoints = jobBreakPointMapper.selectList(
                new LambdaQueryWrapper<WaylineJobBreakPointEntity>()
                        .ge(WaylineJobBreakPointEntity::getCreateTime, startOfDayMillis)
                        .le(WaylineJobBreakPointEntity::getCreateTime, endOfDayMillis)
                        .like(WaylineJobBreakPointEntity::getJobId, "~")
                        .orderByAsc(WaylineJobBreakPointEntity::getCreateTime)
        );
        for (WaylineJobBreakPointEntity breakPoint : breakPoints) {
            String jobId = breakPoint.getJobId();
            // 根据 jobId 查询 wayline_job 表
            WaylineJobEntity job = waylineJobMapper.selectOne(
                    new LambdaQueryWrapper<WaylineJobEntity>()
                            .eq(WaylineJobEntity::getJobId, jobId)
            );
            // 检查 statues 是否等于 3
            if (job != null && job.getStatus() != 3) {
                // 返回符合条件的对象
                return job;
            }
        }
        return null;
    }
    private void handleJobId(WaylineJobEntity entity) throws SQLException {
        Optional<WaylineJobDTO> waylineJobDTO = waylineJobService.getJobByJobId(entity.getWorkspaceId(), entity.getJobId(),true);
        waylineJobService.publishOneFlightTask(waylineJobDTO.get());
    }
}