rain
2024-07-15 638408723ebbf884f59ecaafcaab1c29f69bc689
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
package com.dji.sample.patches.utils;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dji.sample.common.model.CustomClaim;
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;
import com.dji.sample.patches.xml.mode.XMLTemplateModel;
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.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;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
 
import java.nio.file.StandardCopyOption;
import java.time.Instant;
import java.time.LocalDateTime;
 
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;
import java.util.concurrent.Executors;
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.wayline.model.enums.WaylineTaskTypeEnum.TIMED;
import static com.dji.sample.wayline.model.enums.WaylineTemplateTypeEnum.WAYPOINT;
 
@Component
public class TimerUtil {
    @Autowired
    private ShpToDataSourceMapper shpToDataSourceMapper;
    @Autowired
    private PatchesConfigPojo patchesConfigPojo;
    @Autowired
    public IWaylineFileService waylineFileService;
 
    @Autowired
    private ITbFJService tbFJService;
    @Autowired
    private GetPatchesService getPatchesService;
 
    @Autowired
    private GetPatchesMapper patchesMapper;
    @Autowired
    private IWaylineJobService waylineJobService;
    @Autowired
    private TerritoryConfigPojo territoryConfigPojo;
    @Autowired
    private IWaylineJobBreakPointService jobBreakPointService;
 
    /**
     * 定时器,将没有规划的图斑生成航线,并将航线飞完后的成果数据进行保存推送
     *
     * @throws IOException
     * @throws SQLException
     */
    @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(workspaceId);
        List<List<LotInfo>> convertedLists = convertToLists(lists);
        for (List<LotInfo> list : convertedLists) {
            String waylineName = getNowTimeName();
            //根据获取的图斑集合获得kmz航线文件
            MultipartFile multipartFile = null;
            try {
                multipartFile = getFile(waylineName, list,28.62452712442823, 115.85666327144976);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            //上传航线文件
            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);
            time = addOneHourToTimestamp(time, 1, 0);
        }
 
    }
 
    @Scheduled(cron = "0 1 0 * * ?")
    public void myTask2() {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.execute(() -> {
            try {
                dbOperation();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
        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("别墅巡查一段", "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);
    }
    /**
     * 完成对未推送的图斑数据进行整合发送
     *
     * @throws Exception
     */
    @Transactional
    public void dbOperation() throws Exception {
        String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
        String taskId = "";
        String dkbh = null;
        List<List<LotInfo>> lists = convertToLists(getNoPush(workspaceId));
        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);
                }
            }
            //存储db到服务器
            dbSave(territoryConfigPojo.getResult(), territoryConfigPojo.getResultsave(), taskId);
 
            //发送请求给第三方接口
            sendPostWithFileAndParameter(territoryConfigPojo.getResult(), taskId);
 
        }
    }
 
    /**
     * 创建航线
     *
     * @param waylineName
     * @param list
     * @return
     * @throws IOException
     */
    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());
        // 压缩文件夹中的内容
        String destKMZFile = patchesConfigPojo.getDestKMZFile() + waylineName + ".kmz"; // 输出的KMZ文件路径
        zipFolder(patchesConfigPojo.getSourceDir(), destKMZFile);
        return convert(new File(destKMZFile));
    }
 
    /**
     * 将航线上传Oss
     *
     * @param multipartFile
     * @param waylineName
     * @param workspaceId
     * @param username
     * @return
     */
    public WaylineFileEntity backWayline(MultipartFile multipartFile, String waylineName, String workspaceId, String username) {
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, username);
        WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
        try {
            waylineFileService.getObjectUrl(workspaceId, entity.getWaylineId());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return entity;
    }
 
    /**
     * 获取未规划的图斑集合
     *
     * @return
     */
    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()
                .map(ArrayList::new)
                .collect(Collectors.toList());
        return combinedTasks;
    }
 
    /**
     * 更新图斑执行状态
     *
     * @param list
     */
    public void updatePatchesStatu(List<LotInfo> list) {
        for (LotInfo lotInfo : list) {
            lotInfo.setIsPlan(1);
            shpToDataSourceMapper.updateById(lotInfo);
        }
    }
 
    /**
     * 获取未推送的图斑集合
     *
     * @param workspaceId
     * @return
     */
    public List<List<LotInfo>> getNoPush(String workspaceId) {
        List<LotInfo> list = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>()
                .eq(LotInfo::getIsPush, 0)
                .eq(LotInfo::getInvestigate, 1)
                .eq(LotInfo::getWorkspaceId, workspaceId));
        return groupTasks(list);
    }
 
 
    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 <T> List<List<T>> convertToLists(List<List<T>> listOfLists) {
        List<List<T>> convertedLists = new ArrayList<>();
        for (List<T> list : listOfLists) {
            convertedLists.add(new ArrayList<>(list));
        }
        return convertedLists;
    }
 
 
    /**
     * 根据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());
            if (!groupedTasks.containsKey(taskId)) {
                groupedTasks.put(taskId, new ArrayList<>());
            }
            groupedTasks.get(taskId).add(mediaFile);
        }
        return new ArrayList<>(groupedTasks.values());
    }
 
    /**
     * 从filename中获取taskId
     *
     * @param filename
     * @return
     */
    public static String getTaskId(String filename) {
        int startIndex = filename.indexOf("~") + 1;
        int endIndex = filename.indexOf(".");
        return filename.substring(startIndex, endIndex);
    }
 
    /**
     * 从filename中获取地块编号
     *
     * @param filename
     * @return
     */
    public static String getDkbh(String filename) {
        int startIndex = filename.indexOf("点") + 1;
        int endIndex = filename.indexOf("~");
        return filename.substring(startIndex, endIndex);
    }
 
    /**
     * 将成果发送post请求到第三方接口
     *
     * @param filePath
     * @param taskId
     * @throws IOException
     */
    public void sendPostWithFileAndParameter(String filePath, String taskId) throws IOException {
        // 创建 RestTemplate 实例
        try {
            RestTemplate restTemplate = new RestTemplate();
 
            // 读取文件内容为字节数组
            byte[] fileContent = readFileToBytes(filePath);
 
            // 构建请求体
            MultiValueMap<String, Object> body = buildRequestBody(taskId, fileContent, filePath);
 
            // 设置请求头
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.MULTIPART_FORM_DATA);
            headers.set("X-SHARE-TOKEN", "981D9B822A9A09DE28B66243AA330DC666E1A82826B58EC3FE63FEB1EC8AA190");
            headers.set("X-SHARE-AK", "gwc952d483-bfe5-476b-8431-ae15fe94c006");
 
            // 构建请求实体
            HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
 
            // 发送请求
            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);
        } catch (Exception e) {
            throw new IllegalArgumentException("db推送失败" + e.getMessage());
        }
    }
 
    /**
     * 发送的请求参数
     *
     * @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);
        body.add("file", new ByteArrayResource(fileContent) {
            @Override
            public String getFilename() {
                return Paths.get(filePath).getFileName().toString();
            }
        });
        return body;
    }
 
    private static byte[] readFileToBytes(String filePath) throws IOException {
        Path path = Paths.get(filePath);
        return Files.readAllBytes(path);
    }
 
    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);
    }
 
    /**
     * 将上传的db保存一份到本地
     *
     * @param path
     * @param folder
     * @param taskId
     */
    public void dbSave(String path, String folder, String taskId) {
        String sourceFilePath = path; // 源文件路径
        String targetFolderPath = fileFold(folder).getPath(); // 目标文件夹路径
 
        try {
            // 创建目标文件夹
            File targetFolder = new File(targetFolderPath);
            if (!targetFolder.exists()) {
                targetFolder.mkdirs();
            }
 
            // 获取当前时间
            LocalDateTime currentTime = LocalDateTime.now();
 
            // 格式化时间,生成文件名
            String timeName = currentTime.format(DateTimeFormatter.ofPattern("HHmmss"));
            String fileName = timeName + "_" + taskId + ".db";
            // 构建目标文件路径
            String targetFilePath = targetFolderPath + File.separator + fileName;
 
            // 复制文件到目标文件夹
            Path sourcePath = Paths.get(sourceFilePath);
            Path targetPath = Paths.get(targetFilePath);
            Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            throw new RuntimeException("Db文件复制失败", e); // 捕获并抛出原始异常
        }
    }
 
    /**
     * 根据时间创建db存储时的文件夹
     *
     * @param fold
     * @return
     */
    private static File fileFold(String fold) {
        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();
 
        // 格式化时间,生成文件夹名字
        String folderName = currentTime.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
 
        // 拼接文件夹路径
        String folderPath = fold + File.separator + folderName;
 
        // 创建文件夹
        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 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 getNowDay() {
        LocalDateTime currentTime = LocalDateTime.now();
 
        // 格式化时间,生成当前时间
        return "云飞行计划" + currentTime.format(DateTimeFormatter.ofPattern("MMdd"));
    }
}