From aba5f5bf919b7023744dc70ea28d479656e07c9b Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Mon, 08 Jul 2024 18:36:21 +0800
Subject: [PATCH] 更新图片信息返回提示信息

---
 src/main/java/com/dji/sample/patches/utils/TimerUtil.java |  150 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 125 insertions(+), 25 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 cce124f..7ed512d 100644
--- a/src/main/java/com/dji/sample/patches/utils/TimerUtil.java
+++ b/src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -14,14 +14,18 @@
 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.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;
@@ -42,10 +46,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;
@@ -63,8 +64,7 @@
     private PatchesConfigPojo patchesConfigPojo;
     @Autowired
     public IWaylineFileService waylineFileService;
-    @Autowired
-    private IFileMapper fileMapper;
+
     @Autowired
     private ITbFJService tbFJService;
     @Autowired
@@ -76,7 +76,8 @@
     private IWaylineJobService waylineJobService;
     @Autowired
     private TerritoryConfigPojo territoryConfigPojo;
-
+    @Autowired
+    private IWaylineJobBreakPointService jobBreakPointService;
 
     /**
      * 定时器,将没有规划的图斑生成航线,并将航线飞完后的成果数据进行保存推送
@@ -86,20 +87,18 @@
      */
     @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 {
-                multipartFile = getFile(waylineName, list);
+                multipartFile = getFile(waylineName, list,28.62452712442823, 115.85666327144976);
             } catch (IOException e) {
                 throw new RuntimeException(e);
             }
@@ -113,13 +112,14 @@
             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, 1, 0);
         }
 
     }
 
-    @Scheduled(cron = "0 0 0 * * ?")
+    @Scheduled(cron = "0 1 0 * * ?")
     public void myTask2() {
         ExecutorService executor = Executors.newSingleThreadExecutor();
         executor.execute(() -> {
@@ -132,6 +132,92 @@
         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 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("别墅巡查一段", "c1b9c70e-2e58-4147-b43e-aa4f639726bb", 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);
+    }
     /**
      * 完成对未推送的图斑数据进行整合发送
      *
@@ -162,7 +248,7 @@
             dbSave(territoryConfigPojo.getResult(), territoryConfigPojo.getResultsave(), taskId);
 
             //发送请求给第三方接口
-            sendPostWithFileAndParameter(territoryConfigPojo.getResult(), taskId, dkbh, workspaceId);
+            sendPostWithFileAndParameter(territoryConfigPojo.getResult(), taskId);
 
         }
     }
@@ -175,8 +261,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());
         // 压缩文件夹中的内容
@@ -328,7 +415,7 @@
      * @param taskId
      * @throws IOException
      */
-    public void sendPostWithFileAndParameter(String filePath, String taskId, String dkbh, String workspaceId) throws IOException {
+    public void sendPostWithFileAndParameter(String filePath, String taskId) throws IOException {
         // 创建 RestTemplate 实例
         try {
             RestTemplate restTemplate = new RestTemplate();
@@ -350,12 +437,11 @@
 
             // 发送请求
             ResponseEntity<String> response = restTemplate.exchange(
-                    "http://39.98.48.180:8087/landCloudWork/artifact/media/upload.action",
+                    "http://39.98.49.177:8083/landCloudWork/artifact/media/upload.action",
 //                    "http://localhost:6789/territory/tbdkjbxx/upload",
                     HttpMethod.POST,
                     requestEntity,
                     String.class);
-            System.out.println(response);
         } catch (Exception e) {
             throw new IllegalArgumentException("db推送失败" + e.getMessage());
         }
@@ -432,7 +518,7 @@
                 + "\"dock_sn\":\"4TADKCM0010016\","
                 + "\"task_type\":1,"
                 + "\"select_execute_time\":\"%s\","
-                + "\"rth_altitude\":80,"
+                + "\"rth_altitude\":100,"
                 + "\"out_of_control_action\":0,"
                 + "\"executeTimeContinuousArr\":[{\"index\":1,\"value\":[]}],"
                 + "\"executeTimeRepeatArr\":[{\"index\":1,\"value\":\"\"}],"
@@ -440,6 +526,7 @@
                 + "\"rep_fre_type\":3,"
                 + "\"rep_rule_type\":1,"
                 + "\"time_range\":[],"
+                + "\"rth_mode\":1,"
                 + "\"1conValue\":[],"
                 + "\"1repValue\":\"\","
                 + "\"task_days\":%s,"
@@ -510,12 +597,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());
@@ -525,7 +612,7 @@
         return timestamp / 1000;
     }
 
-    public static Long addOneHourToTimestamp(Long timestampInSeconds) {
+    public static Long addOneHourToTimestamp(Long timestampInSeconds, long hours, long min) {
         // 将输入的秒级时间戳转换为Instant对象
         Instant instant = Instant.ofEpochSecond(timestampInSeconds);
 
@@ -533,7 +620,7 @@
         ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault());
 
         // 加上一小时
-        ZonedDateTime zonedDateTimePlusOneHour = zonedDateTime.plusHours(1);
+        ZonedDateTime zonedDateTimePlusOneHour = zonedDateTime.plusHours(hours).plusMinutes(min);
 
         // 将ZonedDateTime对象转换回秒级时间戳
         return zonedDateTimePlusOneHour.toInstant().getEpochSecond();
@@ -552,4 +639,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"));
+    }
 }

--
Gitblit v1.9.3