From 360af284c3656f9f3df16f0dcda36a0d25453b18 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Tue, 20 Aug 2024 18:06:35 +0800
Subject: [PATCH] 机场设备和无人机设备推送,图片、文件上传类型区分举证、航点和航测

---
 src/main/java/com/dji/sample/patches/utils/TimerUtil.java |  720 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 625 insertions(+), 95 deletions(-)

diff --git a/src/main/java/com/dji/sample/patches/utils/TimerUtil.java b/src/main/java/com/dji/sample/patches/utils/TimerUtil.java
index 7336a30..71c492b 100644
--- a/src/main/java/com/dji/sample/patches/utils/TimerUtil.java
+++ b/src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -1,12 +1,15 @@
 package com.dji.sample.patches.utils;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.dji.sample.common.model.CustomClaim;
-import com.dji.sample.common.model.ResponseResult;
+import com.dji.sample.droneairport.dao.DbUploadMapper;
+import com.dji.sample.droneairport.model.Entity.DbUploadEntity;
+import com.dji.sample.manage.dao.IDeviceMapper;
+import com.dji.sample.manage.model.entity.DeviceEntity;
 import com.dji.sample.media.dao.IFileMapper;
 import com.dji.sample.media.model.MediaFileEntity;
 import com.dji.sample.patches.config.pojo.PatchesConfigPojo;
+import com.dji.sample.patches.dao.GetPatchesMapper;
 import com.dji.sample.patches.dao.ShpToDataSourceMapper;
 import com.dji.sample.patches.model.entity.LotInfo;
 import com.dji.sample.patches.service.GetPatchesService;
@@ -14,18 +17,23 @@
 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;
 import com.dji.sample.wayline.service.IWaylineJobService;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ByteArrayResource;
 import org.springframework.http.*;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
@@ -33,32 +41,24 @@
 import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.util.UriComponentsBuilder;
 
-import javax.xml.transform.Result;
 import java.nio.file.StandardCopyOption;
-import java.time.LocalDateTime;
+import java.time.*;
 
 import java.io.*;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.sql.SQLException;
 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.concurrent.Future;
 import java.util.stream.Collectors;
 
 import static com.dji.sample.patches.utils.MultipartFileTOFileUtil.convert;
 import static com.dji.sample.patches.utils.ZipUtil.zipFolder;
+import static com.dji.sample.territory.utils.SM3.sm3;
 import static com.dji.sample.wayline.model.enums.WaylineTaskTypeEnum.TIMED;
 import static com.dji.sample.wayline.model.enums.WaylineTemplateTypeEnum.WAYPOINT;
 
@@ -71,16 +71,27 @@
     @Autowired
     public IWaylineFileService waylineFileService;
     @Autowired
-    private IFileMapper fileMapper;
+    private IWaylineJobService waylineJobService;
     @Autowired
     private ITbFJService tbFJService;
     @Autowired
     private GetPatchesService getPatchesService;
+
     @Autowired
-    private IWaylineJobService waylineJobService;
+    private GetPatchesMapper patchesMapper;
+    @Autowired
+    private IWaylineJobMapper waylineJobMapper;
+
+    @Autowired
+    private IWaylineJobBreakPointMapper jobBreakPointMapper;
     @Autowired
     private TerritoryConfigPojo territoryConfigPojo;
-
+    @Autowired
+    private IWaylineJobBreakPointService jobBreakPointService;
+    @Autowired
+    private IDeviceMapper deviceMapper;
+    @Autowired
+    private DbUploadMapper dbUploadMapper;
 
     /**
      * 定时器,将没有规划的图斑生成航线,并将航线飞完后的成果数据进行保存推送
@@ -90,31 +101,40 @@
      */
     @Scheduled(cron = "0 0 0 * * ?")
     public void myTask() throws Exception {
+        Long time = getCurrentTimestampPlus8Hours(14);
         String taskId = "";
         String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
 //        获取未规划的图斑集合
-        List<List<LotInfo>> lists = getNoPlan();
+        List<List<LotInfo>> lists = getNoPlan(workspaceId);
         List<List<LotInfo>> convertedLists = convertToLists(lists);
         for (List<LotInfo> list : convertedLists) {
-            long timestamp = System.currentTimeMillis();
-            String waylineName = "云飞行调查" + timestamp;
+            String waylineName = getNowTimeName();
             //根据获取的图斑集合获得kmz航线文件
             MultipartFile multipartFile = null;
             try {
-                multipartFile = getFile(waylineName, list);
+                multipartFile = getFile(waylineName, list, 28.62452712442823, 115.85666327144976);
             } catch (IOException e) {
                 throw new RuntimeException(e);
             }
+            taskId = list.get(0).getTaskId();
             //上传航线文件
-            backWayline(multipartFile, waylineName, workspaceId, backclaim().getUsername());
+            WaylineFileEntity waylineFile = backWayline(multipartFile, waylineName, workspaceId, backclaim().getUsername());
             //将为规划的图斑状态更新为已规划
+            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(waylineName, waylineFile.getWaylineId(), times, lists1, listOfLists);
             updatePatchesStatu(list);
-//            waylineJobService.publishFlightTask(JobParam("656c62f4-cb86-4911-930d-b38089829348"),backclaim());
+            time = addOneHourToTimestamp(time, 1, 0);
         }
 
     }
 
-    @Scheduled(cron = "0 0 0 * * ?")
+    @Scheduled(cron = "0 1 0 * * ?")
     public void myTask2() {
         ExecutorService executor = Executors.newSingleThreadExecutor();
         executor.execute(() -> {
@@ -127,31 +147,209 @@
         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();
+//        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 1 * * ?")
+//    public void mytask4() throws IOException {
+//        Long time = getCurrentTimestampPlus8Hours(8);
+//        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("别墅巡查一段", "2a44748a-1500-406f-80cf-ad92186fe8d2", times, lists1, listOfLists);
+//    }
+//
+//    @Scheduled(cron = "0 50 0 * * ?")
+//    public void mytask5() 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("别墅巡查二段", "a07229af-471a-4058-9da6-5a2b84308b9e", times, lists1, listOfLists);
+//    }
+//
+//    @Scheduled(cron = "0 40 1 * * ?")
+//    public void mytask6() 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("九洲巡河一段", "9f471686-a73a-4e90-8f37-92eed8ed5929", times, lists1, listOfLists);
+//    }
+//
+//    @Scheduled(cron = "0 40 2 * * ?")
+//    public void mytask7() 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("九洲巡河二段", "58cd4261-02d7-4c4e-b876-25a4a2630c18", times, lists1, listOfLists);
+//    }
+//
+//    @Scheduled(cron = "0 30 2 * * ?")
+//    public void mytask8() throws IOException {
+//        Long time = getCurrentTimestampPlus8Hours(12);
+//        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("定时任务2:30", "c3a7b125-bc0b-49d4-96ed-80743200ab80", times, lists1, listOfLists);
+//    }
+//    @Scheduled(cron = "0 30 2 * * ?")
+//    public void mytask9() throws IOException {
+//        Long time = getCurrentTimestampPlus8Hours(14);
+//        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("定时任务4:30", "c3a7b125-bc0b-49d4-96ed-80743200ab80", times, lists1, listOfLists);
+//    }
+//    @Scheduled(cron = "0 0 6 * * ?")
+//    public static void mytask10() {
+//        File directory = new File("/tmp");
+//        String[] partialFileNames = {"temp", "mark"}; // 要匹配的部分文件名
+//        if (directory.isDirectory()) {
+//            File[] files = directory.listFiles();
+//            if (files != null) {
+//                for (File file : files) {
+//                    for (String partialFileName : partialFileNames) {
+//                        if (file.isFile() && file.getName().contains(partialFileName)) {
+//                            file.delete();
+//                            break; // 跳出内层循环,以免重复删除同一个文件
+//                        }
+//                    }
+//                }
+//            }
+//        }
+//    }
+
+    /**
+     * 完成对未推送的图斑数据进行整合发送
+     *
+     * @throws Exception
+     */
     @Transactional
     public void dbOperation() throws Exception {
         String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
         String taskId = "";
-        List<List<MediaFileEntity>> list = getNoadd();
-        List<List<MediaFileEntity>> medias = convertToLists(list);
-        for (List<MediaFileEntity> media : medias) {
-            //清空FJ表
-            tbFJService.deleteData();
-            for (MediaFileEntity mediaFile : media) {
-                //获取媒体文件名里的dkbh和taskId
-                String dkbh = getDkbh(mediaFile.getFileName());
-                taskId = getTaskId(mediaFile.getFileName());
-                //获取该媒体文件的图斑信息
-                LotInfo lotInfo = getPatchesService.getLotinfo(dkbh, workspaceId);
-                tbFJService.insertOneData(mediaFile, lotInfo);
-                //更新媒体文件的是否添加状态
-                updateMediaStatu(mediaFile);
+        String dkbh = null;
+        List<List<LotInfo>> lists = convertToLists(getNoPush(workspaceId));
+        if (lists.isEmpty()) {
+            return;
+        }
+        for (List<LotInfo> lotInfo : lists) {
+            for (LotInfo lotInfo1 : lotInfo) {
+                List<MediaFileEntity> media = getPatchesService.listPohto(lotInfo1.getDkbh(), workspaceId);
+                //清空FJ表
+                tbFJService.deleteData();
+                for (MediaFileEntity mediaFile : media) {
+                    //获取媒体文件名里的dkbh和taskId
+                    dkbh = getDkbh(mediaFile.getFileName());
+                    //获取该媒体文件的图斑信息
+                    LotInfo lotInfo2 = getPatchesService.getLotinfo(dkbh, workspaceId);
+                    taskId = lotInfo2.getTaskId();
+                    tbFJService.insertOneData(mediaFile, lotInfo2);
+                    getPatchesService.patchesPushed(taskId, dkbh, workspaceId);
+                }
             }
-            //发送请求给第三方接口
-            sendPostWithFileAndParameter(territoryConfigPojo.getResult(), taskId);
             //存储db到服务器
             dbSave(territoryConfigPojo.getResult(), territoryConfigPojo.getResultsave(), taskId);
+
+            //发送请求给第三方接口
+            sendPostWithFileAndParameter(territoryConfigPojo.getResult(), taskId);
+
         }
     }
+
+    @Scheduled(cron = "0 3 17 * * ?")
+    public void GtdbOperation() throws Exception {
+        String taskId = "";
+        String dkbh = null;
+        String code = "";
+        int count = 0;
+        Set<String> dkbhSet = new HashSet<>(); // 用于存储不同的dkbh
+        List<List<LotInfo>> lists = convertToLists(getNoPush());
+        if (lists.isEmpty()) {
+            return;
+        }
+        tbFJService.deleteData();
+        for (List<LotInfo> lotInfo : lists) {
+            for (LotInfo lotInfo1 : lotInfo) {
+                List<MediaFileEntity> media = getPatchesService.listPohto(lotInfo1.getDkbh());
+                // 清空FJ表
+                for (MediaFileEntity mediaFile : media) {
+                    // 获取媒体文件名里的dkbh和taskId
+                    dkbh = getDkbh(mediaFile.getFileName());
+                    dkbhSet.add(dkbh); // 添加dkbh到set中
+                    // 获取该媒体文件的图斑信息
+                    LotInfo lotInfo2 = getPatchesService.getLotinfo(dkbh);
+                    taskId = lotInfo2.getTaskId();
+                    code = lotInfo2.getXzqdm();
+                    count++;
+                    // 插入数据到数据库
+                    tbFJService.insertOneData(mediaFile, lotInfo2);
+                    getPatchesService.patchesPushed(taskId, dkbh);
+                }
+            }
+
+            // 存储db到服务器
+            String dbName = dbSaveGt(territoryConfigPojo.getResult(), territoryConfigPojo.getResultGtsave(), taskId);
+            DbUploadEntity entity = new DbUploadEntity();
+            File file = new File(territoryConfigPojo.getResult());
+            byte[] bytesArray = Files.readAllBytes(file.toPath());
+            long currentTimeMillis = System.currentTimeMillis();
+            entity.setTimestamp(currentTimeMillis);
+            entity.setSize(getFileSize(file));
+            entity.setHash(sm3(bytesArray));
+            entity.setCount(dkbhSet.size());// 统计dkbh的数量
+            entity.setUrl(territoryConfigPojo.getResultGtsave() + dbName);
+            entity.setRegioncode(code);
+            entity.setExtension(".db");
+            entity.setAttachmentCount(count);
+            entity.setTaskId(taskId);
+            dbUploadMapper.insert(entity);
+        }
+    }
+
 
     /**
      * 创建航线
@@ -161,8 +359,9 @@
      * @return
      * @throws IOException
      */
-    public MultipartFile getFile(String waylineName, List<LotInfo> list) throws IOException {
-        List<PointPO> coordinates = GeoToolsUtil.getRoutePointOrder(list, 28.62452712442823, 115.85666327144976);
+    public MultipartFile getFile(String waylineName, List<LotInfo> list, double lat, double lon) throws IOException {
+        //南昌28.62452712442823, 115.85666327144976  瑞金 25.8917266,116.020940643
+        List<PointPO> coordinates = GeoToolsUtil.getRoutePointOrder(list, lat, lon);
         XMLTemplateModel xmlModel = XMLTemplateModel.init(coordinates, list);
         CreateWaylineFileUtils.createWaylineFile(xmlModel, patchesConfigPojo.getTemplate(), patchesConfigPojo.getTargetTemplate(), patchesConfigPojo.getWaylines(), patchesConfigPojo.getTargetWaylines());
         // 压缩文件夹中的内容
@@ -170,6 +369,7 @@
         zipFolder(patchesConfigPojo.getSourceDir(), destKMZFile);
         return convert(new File(destKMZFile));
     }
+
 
     /**
      * 将航线上传Oss
@@ -180,15 +380,15 @@
      * @param username
      * @return
      */
-    public String backWayline(MultipartFile multipartFile, String waylineName, String workspaceId, String username) {
-        waylineFileService.importKmzFileBack(multipartFile, workspaceId, username);
+    public WaylineFileEntity backWayline(MultipartFile multipartFile, String waylineName, String workspaceId, String username) {
+        waylineFileService.importKmzFileBack(multipartFile, workspaceId, username, 1);
         WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
         try {
             waylineFileService.getObjectUrl(workspaceId, entity.getWaylineId());
         } catch (SQLException e) {
             throw new RuntimeException(e);
         }
-        return entity.getWaylineId();
+        return entity;
     }
 
     /**
@@ -196,8 +396,10 @@
      *
      * @return
      */
-    public List<List<LotInfo>> getNoPlan() {
-        List<LotInfo> list = shpToDataSourceMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getIsPlan, 0));
+    public List<List<LotInfo>> getNoPlan(String worksapceId) {
+        List<LotInfo> list = shpToDataSourceMapper.selectList(new LambdaQueryWrapper<LotInfo>()
+                .eq(LotInfo::getIsPlan, 0)
+                .eq(LotInfo::getWorkspaceId, worksapceId));
         List<List<LotInfo>> combinedTasks = list.stream()
                 .collect(Collectors.groupingBy(LotInfo::getTaskId))
                 .values().stream()
@@ -218,52 +420,37 @@
         }
     }
 
-    public void updateMediaStatu(MediaFileEntity mediaFile) {
-        mediaFile.setIsadd(1);
-        fileMapper.updateById(mediaFile);
+    /**
+     * 获取未推送的图斑集合
+     *
+     * @param workspaceId
+     * @return
+     */
+    public List<List<LotInfo>> getNoPush(String workspaceId) {
+        List<LotInfo> list = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>()
+                .eq(LotInfo::getIsPush, 0)
+                .eq(LotInfo::getType, 2)
+                .eq(LotInfo::getInvestigate, 1)
+                .eq(LotInfo::getWorkspaceId, workspaceId));
+        return groupTasks(list);
     }
 
-    public List<List<MediaFileEntity>> getNoadd() {
-        List<MediaFileEntity> list = fileMapper.selectList(new LambdaQueryWrapper<MediaFileEntity>()
-                .eq(MediaFileEntity::getIsadd, 0)
-                .eq(MediaFileEntity::getExamine, 1)
-                .like(MediaFileEntity::getFileName, "~"));
-        List<List<MediaFileEntity>> groupedFilenames = groupTasks(list);
-        return groupedFilenames;
+    public List<List<LotInfo>> getNoPush() {
+        List<LotInfo> list = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>()
+                .eq(LotInfo::getIsPush, 0)
+                .eq(LotInfo::getType, 1)
+                .eq(LotInfo::getInvestigate, 1));
+        return groupTasks(list);
     }
 
-    public CustomClaim backclaim() {
+
+    public static CustomClaim backclaim() {
         CustomClaim claim = new CustomClaim();
         claim.setId("1");
         claim.setUsername("adminPC");
         claim.setWorkspaceId("4a574db8-4ad3-48f7-9f16-3edbcd8056e1");
         claim.setUserType(1);
         return claim;
-    }
-
-    public static CreateJobParam JobParam(String waylineId) {
-        long timestamp = System.currentTimeMillis();
-        List<List<Long>> listOfLists = new ArrayList<>();
-        List<Long> sublist = new ArrayList<>();
-        sublist.add(1715941980L); // 添加整数值
-        listOfLists.add(sublist);
-        List<Long> list = new ArrayList<>();
-        list.add(1715941980L);
-        CreateJobParam param = new CreateJobParam();
-        param.setName("云飞行调查" + timestamp);
-        param.setExecuteStartTimeArr(listOfLists);
-        param.setTaskType(TIMED);
-        param.setOutOfControlAction(0);
-        param.setRepFreType(3);
-        param.setRepFreVal(1);
-        param.setRepRuleType(1);
-        param.setRthAltitude(80);
-        param.setWaylineType(WAYPOINT);
-        param.setTaskPeriods(listOfLists);
-        param.setTaskDays(list);
-        param.setFileId(waylineId);
-        param.setDockSn("4TADKCMB0010016");
-        return param;
     }
 
     public static <T> List<List<T>> convertToLists(List<List<T>> listOfLists) {
@@ -275,8 +462,25 @@
     }
 
 
-    // 对任务ID进行分组
-    public static List<List<MediaFileEntity>> groupTasks(List<MediaFileEntity> mediaFiles) {
+    /**
+     * 根据taskID对图斑进行分组
+     *
+     * @param lotInfos
+     * @return
+     */
+    public static List<List<LotInfo>> groupTasks(List<LotInfo> lotInfos) {
+        Map<String, List<LotInfo>> groupedTasks = new HashMap<>();
+        for (LotInfo lotInfo : lotInfos) {
+            String taskId = lotInfo.getTaskId();
+            if (!groupedTasks.containsKey(taskId)) {
+                groupedTasks.put(taskId, new ArrayList<>());
+            }
+            groupedTasks.get(taskId).add(lotInfo);
+        }
+        return new ArrayList<>(groupedTasks.values());
+    }
+
+    public static List<List<MediaFileEntity>> groupTask(List<MediaFileEntity> mediaFiles) {
         Map<String, List<MediaFileEntity>> groupedTasks = new HashMap<>();
         for (MediaFileEntity mediaFile : mediaFiles) {
             String taskId = getTaskId(mediaFile.getFileName());
@@ -288,16 +492,25 @@
         return new ArrayList<>(groupedTasks.values());
     }
 
-    // 从filename字段中提取任务ID(任务ID在文件名中以"~"开头、"."结尾)
+    /**
+     * 从filename中获取taskId
+     *
+     * @param filename
+     * @return
+     */
     public static String getTaskId(String filename) {
-        // 这里只是一个示例,你需要根据实际情况编写提取task_id的逻辑
         int startIndex = filename.indexOf("~") + 1;
         int endIndex = filename.indexOf(".");
         return filename.substring(startIndex, endIndex);
     }
 
+    /**
+     * 从filename中获取地块编号
+     *
+     * @param filename
+     * @return
+     */
     public static String getDkbh(String filename) {
-        // 这里只是一个示例,你需要根据实际情况编写提取task_id的逻辑
         int startIndex = filename.indexOf("点") + 1;
         int endIndex = filename.indexOf("~");
         return filename.substring(startIndex, endIndex);
@@ -310,7 +523,7 @@
      * @param taskId
      * @throws IOException
      */
-    public static void sendPostWithFileAndParameter(String filePath, String taskId) throws IOException {
+    public void sendPostWithFileAndParameter(String filePath, String taskId) throws IOException {
         // 创建 RestTemplate 实例
         try {
             RestTemplate restTemplate = new RestTemplate();
@@ -331,9 +544,9 @@
             HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
 
             // 发送请求
-            ResponseEntity<String> response =restTemplate.exchange(
-                    "https://jxlandcloud.org.cn/landCloudWork/artifact/media/upload.action",
-//                  "http://localhost:6789/territory/tbdkjbxx/upload",
+            ResponseEntity<String> response = restTemplate.exchange(
+                    "http://39.98.49.177:8083/landCloudWork/artifact/media/upload.action",
+//                    "http://localhost:6789/territory/tbdkjbxx/upload",
                     HttpMethod.POST,
                     requestEntity,
                     String.class);
@@ -342,6 +555,14 @@
         }
     }
 
+    /**
+     * 发送的请求参数
+     *
+     * @param taskId
+     * @param fileContent
+     * @param filePath
+     * @return
+     */
     private static MultiValueMap<String, Object> buildRequestBody(String taskId, byte[] fileContent, String filePath) {
         MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
         body.add("taskId", taskId);
@@ -358,6 +579,135 @@
         Path path = Paths.get(filePath);
         return Files.readAllBytes(path);
     }
+
+    public void sendPostWithParameters(String name, String fileId, String time, List<Long> taskDays, List<List<Long>> taskPeriods, String jobId, String docksn) throws IOException {
+        try {
+            RestTemplate restTemplate = new RestTemplate();
+
+            // 构建请求体
+            String jsonBody = buildRequestBody(name, fileId, time, taskDays, taskPeriods, jobId, docksn);
+            String workspaceId = getWorkspaceIdByDocksn(docksn);
+            // 设置请求头
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            headers.setAccept(List.of(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.ALL));
+            headers.set("Accept-Language", "zh-CN,zh;q=0.9");
+            headers.setConnection("keep-alive");
+            headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MTg1ODUxNTQsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDQ5ODUxNTQsImlhdCI6MTcxODU4NTE1NCwidXNlcm5hbWUiOiJhZG1pbkRQIn0.eTi9DTYGwcTvnIZasKTFq9OHQgMFS1-m840terb7ss0");
+
+            // 构建请求实体
+            HttpEntity<String> requestEntity = new HttpEntity<>(jsonBody, headers);
+
+            // 发送请求
+            ResponseEntity<String> response = restTemplate.exchange(
+//                    "https://wrj.shuixiongit.com/drone-api/wayline/api/v1/workspaces/4a574db8-4ad3-48f7-9f16-3edbcd8056e1/flight-tasks",
+                    "http://localhost:6789/wayline/api/v1/workspaces/" + workspaceId + "/flight-tasks",
+                    HttpMethod.POST,
+                    requestEntity,
+                    String.class);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("Request failed: " + e.getMessage());
+        }
+    }
+
+    public String getWorkspaceIdByDocksn(String docksn) {
+        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();
+
+            // 构建请求体
+            String jsonBody = buildRequestBody(name, fileId, time, taskDays, taskPeriods);
+
+            // 设置请求头
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            headers.setAccept(List.of(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.ALL));
+            headers.set("Accept-Language", "zh-CN,zh;q=0.9");
+            headers.setConnection("keep-alive");
+            headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MTg1ODUxNTQsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDQ5ODUxNTQsImlhdCI6MTcxODU4NTE1NCwidXNlcm5hbWUiOiJhZG1pbkRQIn0.eTi9DTYGwcTvnIZasKTFq9OHQgMFS1-m840terb7ss0");
+
+            // 构建请求实体
+            HttpEntity<String> requestEntity = new HttpEntity<>(jsonBody, headers);
+
+            // 发送请求
+            ResponseEntity<String> response = restTemplate.exchange(
+                    "https://wrj.shuixiongit.com/drone-api/wayline/api/v1/workspaces/4a574db8-4ad3-48f7-9f16-3edbcd8056e1/flight-tasks",
+//                    "http://localhost:6789/wayline/api/v1/workspaces/4a574db8-4ad3-48f7-9f16-3edbcd8056e1/flight-tasks",
+                    HttpMethod.POST,
+                    requestEntity,
+                    String.class);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("Request failed: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 构建请求体
+     *
+     * @param name
+     * @param fileId
+     * @param taskDays
+     * @param taskPeriods
+     * @return
+     */
+    private static String buildRequestBody(String name, String fileId, String select_execute_time, List<Long> taskDays, List<List<Long>> taskPeriods) {
+        return String.format("{"
+                + "\"name\":\"%s\","
+                + "\"file_id\":\"%s\","
+                + "\"dock_sn\":\"4TADKCM0010016\","
+                + "\"task_type\":1,"
+                + "\"select_execute_time\":\"%s\","
+                + "\"rth_altitude\":100,"
+                + "\"out_of_control_action\":0,"
+                + "\"executeTimeContinuousArr\":[{\"index\":1,\"value\":[]}],"
+                + "\"executeTimeRepeatArr\":[{\"index\":1,\"value\":\"\"}],"
+                + "\"rep_fre_val\":1,"
+                + "\"rep_fre_type\":3,"
+                + "\"rep_rule_type\":1,"
+                + "\"time_range\":[],"
+                + "\"rth_mode\":1,"
+                + "\"1conValue\":[],"
+                + "\"1repValue\":\"\","
+                + "\"task_days\":%s,"
+                + "\"task_periods\":%s,"
+                + "\"wayline_type\":0"
+                + "}", name, fileId, select_execute_time, taskDays, taskPeriods);
+    }
+
+    private static String buildRequestBody(String name, String fileId, String select_execute_time, List<Long> taskDays, List<List<Long>> taskPeriods, String jobid, String dockSn) {
+        // 将 List 和 String 类型的参数格式化为 JSON 字符串
+        String taskDaysJson = taskDays != null ? taskDays.toString() : "[]";
+        String taskPeriodsJson = taskPeriods != null ? taskPeriods.toString() : "[]";
+
+        // 使用 String.format 来生成 JSON 字符串
+        return String.format("{"
+                + "\"name\":\"%s\","
+                + "\"file_id\":\"%s\","
+                + "\"dock_sn\":\"%s\","
+                + "\"task_type\":1,"
+                + "\"select_execute_time\":\"%s\","
+                + "\"rth_altitude\":100,"
+                + "\"out_of_control_action\":0,"
+                + "\"executeTimeContinuousArr\":[{\"index\":1,\"value\":[]}],"
+                + "\"executeTimeRepeatArr\":[{\"index\":1,\"value\":\"\"}],"
+                + "\"rep_fre_val\":1,"
+                + "\"rep_fre_type\":3,"
+                + "\"rep_rule_type\":1,"
+                + "\"time_range\":[],"
+                + "\"rth_mode\":1,"
+                + "\"1conValue\":[],"
+                + "\"1repValue\":\"\","
+                + "\"task_days\":%s,"
+                + "\"task_periods\":%s,"
+                + "\"wayline_type\":0,"
+                + "\"job_id\":\"%s\""
+                + "}", name, fileId, dockSn, select_execute_time, taskDaysJson, taskPeriodsJson, jobid);
+    }
+
 
     /**
      * 将上传的db保存一份到本地
@@ -395,6 +745,28 @@
         }
     }
 
+    public String dbSaveGt(String path, String folder, String taskId) {
+        try {
+            String fileName = taskId + ".db";
+            // 构建目标文件路径
+            String targetFilePath = folder + File.separator + fileName;
+
+            // 复制文件到目标位置
+            Path sourcePath = Paths.get(path);
+            Path targetPath = Paths.get(targetFilePath);
+            Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
+            return fileName;
+        } catch (IOException e) {
+            throw new RuntimeException("Db文件复制失败", e); // 捕获并抛出原始异常
+        }
+    }
+
+    /**
+     * 根据时间创建db存储时的文件夹
+     *
+     * @param fold
+     * @return
+     */
     private static File fileFold(String fold) {
         // 获取当前时间
         LocalDateTime currentTime = LocalDateTime.now();
@@ -415,4 +787,162 @@
         return folder;
     }
 
+    private static File fileFold(String fold, String taskId) {
+        // 获取当前时间
+        LocalDateTime currentTime = LocalDateTime.now();
+
+        // 拼接文件夹路径
+        String folderPath = fold + File.separator + taskId;
+
+        // 创建文件夹
+        File folder = new File(folderPath);
+        if (!folder.exists()) {
+            if (!folder.mkdirs()) {
+                throw new RuntimeException("文件创建失败" + folderPath);
+            }
+        }
+        return folder;
+    }
+
+    public static Long getCurrentTimestampPlus8Hours(long hours) {
+        // 获取当前时间
+        LocalDateTime now = LocalDateTime.now();
+
+        // 加上8小时
+        LocalDateTime nowPlus8Hours = now.plusHours(hours);
+
+        // 转换为UTC时间戳
+        ZonedDateTime zonedDateTime = nowPlus8Hours.atZone(ZoneId.systemDefault());
+        long timestamp = zonedDateTime.toInstant().toEpochMilli();
+
+        // 将毫秒级时间戳转换为秒级时间戳
+        return timestamp / 1000;
+    }
+
+    public static long getNextDayEightAMTimestamp(int hour) {
+        // 获取当前时间
+        LocalDateTime now = LocalDateTime.now();
+
+        // 获取第二天的日期并设置时间为08:00
+        LocalDateTime nextDayEightAM = now.plusDays(1).withHour(8).withMinute(30).withSecond(0).withNano(0);
+
+        // 根据传入的hour参数增加小时
+        LocalDateTime adjustedTime = nextDayEightAM.plusHours(hour);
+
+        // 转换为时间戳(秒级)
+        ZonedDateTime zonedDateTime = adjustedTime.atZone(ZoneId.systemDefault());
+        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);
+
+        // 将Instant对象转换为ZonedDateTime对象,使用系统默认时区
+        ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault());
+
+        // 加上一小时
+        ZonedDateTime zonedDateTimePlusOneHour = zonedDateTime.plusHours(hours).plusMinutes(min);
+
+        // 将ZonedDateTime对象转换回秒级时间戳
+        return zonedDateTimePlusOneHour.toInstant().getEpochSecond();
+    }
+
+    // 方法:将时间戳转换为指定格式的字符串
+    public static String convertTimestampToFormattedString(Long timestamp) {
+        // 将时间戳转换为Instant对象
+        Instant instant = Instant.ofEpochMilli(timestamp);
+
+        // 将Instant对象转换为ZonedDateTime对象,并设置时区为UTC
+        ZonedDateTime chinaTime = instant.atZone(ZoneId.of("Asia/Shanghai"));
+
+        // 格式化时间
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.000'Z'");
+        return chinaTime.format(formatter);
+    }
+
+    public static String getNowTimeName() {
+        LocalDateTime currentTime = LocalDateTime.now();
+        // 格式化时间,生成当前时间
+        return "云飞行计划" + currentTime.format(DateTimeFormatter.ofPattern("MMddHHmmssSS"));
+    }
+
+    public static String getTimeName() {
+        LocalDateTime currentTime = LocalDateTime.now();
+        // 格式化时间,生成当前时间
+        return "国土调查云" + currentTime.format(DateTimeFormatter.ofPattern("MMddHHmmssSS"));
+    }
+
+    public static String getNowDay() {
+        LocalDateTime currentTime = LocalDateTime.now();
+
+        // 格式化时间,生成当前时间
+        return currentTime.format(DateTimeFormatter.ofPattern("MMddHHmmssSSS"));
+    }
+
+    public static long getFileSize(File file) {
+        if (file == null || !file.exists() || !file.isFile()) {
+            return -1L; // 文件不存在或不是普通文件
+        }
+        return file.length();
+    }
+
+    public static void main(String[] args) {
+        File file = new File("DB/result_db.db");
+        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());
+    }
 }

--
Gitblit v1.9.3