rain
2024-06-20 3904fbdccb96a9b1b4f919d18505d5ebb8ef976a
src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -14,14 +14,17 @@
import com.dji.sample.territory.pojo.TerritoryConfigPojo;
import com.dji.sample.territory.service.ITbFJService;
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.param.CreateJobParam;
import com.dji.sample.wayline.service.IWaylineFileService;
import com.dji.sample.wayline.service.IWaylineJobBreakPointService;
import com.dji.sample.wayline.service.IWaylineJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.*;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -42,10 +45,7 @@
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
@@ -76,7 +76,8 @@
    private IWaylineJobService waylineJobService;
    @Autowired
    private TerritoryConfigPojo territoryConfigPojo;
    @Autowired
    private IWaylineJobBreakPointService jobBreakPointService;
    /**
     * 定时器,将没有规划的图斑生成航线,并将航线飞完后的成果数据进行保存推送
@@ -86,16 +87,14 @@
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void myTask() throws Exception {
        Long time = getCurrentTimestampPlus8Hours();
        Long time = getCurrentTimestampPlus8Hours(14);
        String taskId = "";
        String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
//        获取未规划的图斑集合
        List<List<LotInfo>> lists = getNoPlan(workspaceId);
        List<List<LotInfo>> convertedLists = convertToLists(lists);
        for (List<LotInfo> list : convertedLists) {
            long timestamp = System.currentTimeMillis();
            time = addOneHourToTimestamp(time);
            String waylineName = "云飞行调查" + timestamp;
            String waylineName = getNowTimeName();
            //根据获取的图斑集合获得kmz航线文件
            MultipartFile multipartFile = null;
            try {
@@ -113,8 +112,9 @@
            List<Long> lists1 = new ArrayList<>();
            lists1.add(time);
            String times = convertTimestampToFormattedString(time);
            sendPostWithParameters("云飞行计划" + timestamp, waylineFile.getWaylineId(), times, lists1, listOfLists);
            sendPostWithParameters(waylineName, waylineFile.getWaylineId(), times, lists1, listOfLists);
            updatePatchesStatu(list);
            time = addOneHourToTimestamp(time);
        }
    }
@@ -130,6 +130,29 @@
            }
        });
        executor.shutdown();
    }
    public void myTask3() throws SQLException {
        String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
        String name = getNowDay();
        List<String> jobs = waylineJobService.selectJobIdByName(name);
        List<String> jobIds = jobBreakPointService.selectHaveBreak(jobs);
        for (String jobid : jobIds) {
            Optional<WaylineJobDTO> waylineJobDTO = waylineJobService.getJobByJobId(workspaceId, jobid, true);
            waylineJobService.publishOneFlightTask(waylineJobDTO.get());
        }
    }
    @Scheduled(cron = "0 0 0 * * ?")
    public void mytask4() throws IOException {
        Long time = getCurrentTimestampPlus8Hours(9);
        List<List<Long>> listOfLists = new ArrayList<>();
        List<Long> sublist = new ArrayList<>();
        sublist.add(time); // 添加整数值
        listOfLists.add(sublist);
        List<Long> lists1 = new ArrayList<>();
        lists1.add(time);
        String times = convertTimestampToFormattedString(time);
        sendPostWithParameters("九洲巡查","73e14492-f1b2-4fc4-81c0-7ca65cd3bc56", times, lists1, listOfLists);
    }
    /**
@@ -510,12 +533,12 @@
        return folder;
    }
    public static Long getCurrentTimestampPlus8Hours() {
    public static Long getCurrentTimestampPlus8Hours(long hours) {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        // 加上8小时
        LocalDateTime nowPlus8Hours = now.plusHours(8);
        LocalDateTime nowPlus8Hours = now.plusHours(hours);
        // 转换为UTC时间戳
        ZonedDateTime zonedDateTime = nowPlus8Hours.atZone(ZoneId.systemDefault());
@@ -533,7 +556,7 @@
        ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault());
        // 加上一小时
        ZonedDateTime zonedDateTimePlusOneHour = zonedDateTime.plusHours(1);
        ZonedDateTime zonedDateTimePlusOneHour = zonedDateTime.plusHours(1).plusMinutes(30);
        // 将ZonedDateTime对象转换回秒级时间戳
        return zonedDateTimePlusOneHour.toInstant().getEpochSecond();
@@ -552,4 +575,17 @@
        return chinaTime.format(formatter);
    }
    public static String getNowTimeName() {
        LocalDateTime currentTime = LocalDateTime.now();
        // 格式化时间,生成当前时间
        return "云飞行计划" + currentTime.format(DateTimeFormatter.ofPattern("MMddHHmmssSS"));
    }
    public static String getNowDay() {
        LocalDateTime currentTime = LocalDateTime.now();
        // 格式化时间,生成当前时间
        return "云飞行计划" + currentTime.format(DateTimeFormatter.ofPattern("MMdd"));
    }
}