From b5b95f50e7905e9424628254b3cba7b92aa77cde Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Wed, 03 Dec 2025 14:52:56 +0800
Subject: [PATCH] 2025-12-03 zwy 维护大疆上云、司空错误码!返回前端的错误码和错误详情。

---
 ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java |   83 +++++++++++++++++++++++++++--------------
 1 files changed, 54 insertions(+), 29 deletions(-)

diff --git a/ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java b/ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java
index 5714a29..8b649e9 100644
--- a/ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java
+++ b/ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java
@@ -1,6 +1,6 @@
 package com.ard.sample.wayline.service.impl;
 
-import com.ard.oss.service.impl.OssServiceContext;
+import com.ard.ossdock.service.impl.OssDockServiceContext;
 import com.ard.route.domain.route.ArdRouteInfo;
 import com.ard.route.service.IArdRouteInfoService;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
@@ -77,7 +77,7 @@
     private IArdRouteInfoService _ardRouteInfoService;
 
     @Resource
-    private OssServiceContext _ossService;
+    private OssDockServiceContext _ossService;
 
     @Autowired
     private IDeviceService deviceService;
@@ -195,7 +195,7 @@
 
         boolean isOnline = deviceService.checkDeviceOnline(waylineJob.getDockSn());
         if (!isOnline) {
-            return ResponseResult.error("机场不在线!");
+            return ResponseResult.error(CommonErrorEnum.DEVICE_OFFLINE.getErrorMsg());
         }
 
         // get wayline file
@@ -212,11 +212,11 @@
         // get file url
 //        URL url = waylineFileService.getObjectUrl(waylineFile.get().getWaylineId());
         URL url = null;
-        String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath());
+        String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath1());
         String md5 = "";
         try (InputStream inputStream = _ossService.getObject(kmzPath, minioUrl)) {
             md5 = DigestUtils.md5Hex(inputStream);
-            url = new URL(ardRouteOpt.getPath());
+            url = new URL(ardRouteOpt.getPath1());
             log.info("机场任务航线文件url地址:{}", url);
             log.info("机场任务航线文件md5值:{}", md5);
         } catch (Exception e) {
@@ -235,8 +235,11 @@
                 .outOfControlAction(waylineJob.getOutOfControlAction())
                 .rthMode(waylineJob.getRthMode())
                 .file(WaylineTaskFileDTO.builder()
-                        .url(url.toString().replace("https//192.168.10.103:9001", "http//192.168.10.103:9002"))
+//                        .url(url.toString().replace("https://192.168.10.103:9001", "http://192.168.10.103:9011"))
 //                        .fingerprint(waylineFile.get().getSign())
+//                        .replace("https://", "http://")
+//                        .replace("9001", "9011")
+                        .url(url.toString())
                         .fingerprint(md5)
                         .build())
 //                .simulateMission(WaylineSimulateMissionDTO.builder()
@@ -270,14 +273,16 @@
         log.info("下发任务结果: {}", serviceReply.getResult());
 
         if (ResponseResult.CODE_SUCCESS != serviceReply.getResult()) {
-            log.info("Prepare task ====> Error code: {}", serviceReply.getResult());
+            String errorMsg = CommonErrorEnum.getMsgByCode(serviceReply.getResult());
+            log.info("Prepare task ====> Error code: {},Error Msg:{}", serviceReply.getResult(), errorMsg);
             this.updateJob(WaylineJobDTO.builder()
                     .jobId(waylineJob.getJobId())
                     .executeTime(LocalDateTime.now())
                     .status(WaylineJobStatusEnum.FAILED.getVal())
                     .completedTime(LocalDateTime.now())
                     .code(serviceReply.getResult()).build());
-            return ResponseResult.error("Prepare task ====> Error code: " + serviceReply.getResult());
+            //return ResponseResult.error("Prepare task ====> Error code: " + serviceReply.getResult());
+            return ResponseResult.error(serviceReply.getResult(), errorMsg);
         }
 
         // 飞行命令先注释掉
@@ -374,14 +379,16 @@
         log.info("机场任务航线文件md5值:{}", md5);
 
         if (ResponseResult.CODE_SUCCESS != serviceReply.getResult()) {
-            log.info("Prepare task ====> Error code: {}", serviceReply.getResult());
+            String errorMsg = CommonErrorEnum.getMsgByCode(serviceReply.getResult());
+            log.info("Prepare task ====> Error code: {},Error Msg: {}", serviceReply.getResult(), errorMsg);
             this.updateJob(WaylineJobDTO.builder()
                     .jobId(waylineJob.getJobId())
                     .executeTime(LocalDateTime.now())
                     .status(WaylineJobStatusEnum.FAILED.getVal())
                     .completedTime(LocalDateTime.now())
                     .code(serviceReply.getResult()).build());
-            return ResponseResult.error("Prepare task ====> Error code: " + serviceReply.getResult());
+//            return ResponseResult.error("Prepare task ====> Error code: " + serviceReply.getResult());
+            return ResponseResult.error(serviceReply.getResult(), errorMsg);
         }
 
         // 飞行命令先注释掉
@@ -417,12 +424,13 @@
         // get job
         Optional<WaylineJobDTO> waylineJob = this.getJobByJobId(jobId);
         if (waylineJob.isEmpty()) {
-            throw new IllegalArgumentException("Job doesn't exist.");
+            throw new IllegalArgumentException("计划任务不存在。");
         }
 
         boolean isOnline = deviceService.checkDeviceOnline(waylineJob.get().getDockSn());
         if (!isOnline) {
-            throw new RuntimeException("Dock is offline.");
+//            throw new RuntimeException("Dock is offline.");
+            throw new RuntimeException(CommonErrorEnum.DEVICE_OFFLINE.getErrorMsg());
         }
 
         WaylineJobDTO job = waylineJob.get();
@@ -452,7 +460,8 @@
         log.info("下发-执行飞行任务-结果: {}", serviceReply.getResult());
 
         if (ResponseResult.CODE_SUCCESS != serviceReply.getResult()) {
-            log.info("Execute job ====> Error code: {}", serviceReply.getResult());
+            String errorMsg = CommonErrorEnum.getMsgByCode(serviceReply.getResult());
+            log.info("Execute job ====> Error code: {},Error Msg:{}", serviceReply.getResult(), errorMsg);
             this.updateJob(WaylineJobDTO.builder()
                     .jobId(jobId)
                     .executeTime(LocalDateTime.now())
@@ -511,7 +520,7 @@
     public void publishCancelTask(String dockSn, List<String> jobIds) {
         boolean isOnline = deviceService.checkDeviceOnline(dockSn);
         if (!isOnline) {
-            throw new RuntimeException("Dock is offline.");
+            throw new RuntimeException(CommonErrorEnum.DEVICE_OFFLINE.getErrorMsg());
         }
         String topic = TopicConst.THING_MODEL_PRE + TopicConst.PRODUCT + dockSn + TopicConst.SERVICES_SUF;
 
@@ -525,8 +534,10 @@
 
         ServiceReply serviceReply = messageSender.publishWithReply(topic, response);
         if (ResponseResult.CODE_SUCCESS != serviceReply.getResult()) {
-            log.info("Cancel job ====> Error code: {}", serviceReply.getResult());
-            throw new RuntimeException("Failed to cancel the wayline job of " + dockSn);
+            String errorMsg = CommonErrorEnum.getMsgByCode(serviceReply.getResult());
+            log.info("取消飞行任务失败 ====> 设备sn: {}, 错误码: {}, {}", dockSn, serviceReply.getResult(), errorMsg);
+            //throw new RuntimeException("Failed to cancel the wayline job of " + dockSn);
+            throw new RuntimeException("设备:" + dockSn + "取消飞行任务失败,错误码:" + serviceReply.getResult() + "," + errorMsg);
         }
 
         for (String jobId : jobIds) {
@@ -581,6 +592,18 @@
         return Optional.ofNullable(entity2Dto(jobEntity));
     }
 
+    public List<WaylineJobDTO> getJobByJobParentId(String parentId) {
+        List<WaylineJobEntity> jobEntities = mapper.selectList(
+                new LambdaQueryWrapper<WaylineJobEntity>()
+                        .eq(WaylineJobEntity::getParentId, parentId));
+        if (CollectionUtils.isEmpty(jobEntities)) {
+            return Collections.emptyList(); // 返回不可变空列表,更安全
+        }
+        return jobEntities.stream()
+                .map(this::entity2Dto) // 调用原有的单个转换方法
+                .collect(Collectors.toList());
+    }
+
     /**
      * 更新作业信息
      *
@@ -628,6 +651,7 @@
         Page<WaylineJobEntity> pageData = mapper.selectPage(
                 new Page<WaylineJobEntity>(page, pageSize),
                 new LambdaQueryWrapper<WaylineJobEntity>()
+                        .isNull(WaylineJobEntity::getParentId)
                         // 实际开始时间筛选,允许为空,为空则不进行筛选
                         .ge(startTime != null, WaylineJobEntity::getBeginTime, startTime)
                         .le(endTime != null, WaylineJobEntity::getBeginTime, endTime)
@@ -640,10 +664,14 @@
                         .ne(isComplete != null && !isComplete, WaylineJobEntity::getStatus, 3)
                         // 任务状态筛选,允许为空,为空则不进行筛选
                         .eq(status != null, WaylineJobEntity::getStatus, status)
-                        .orderByDesc(WaylineJobEntity::getId));
+                        .orderByDesc(WaylineJobEntity::getBeginTime));
         List<WaylineJobDTO> records = pageData.getRecords()
                 .stream()
                 .map(this::entity2Dto)
+                .peek(job -> {
+                    List<WaylineJobDTO> childOpt = this.getJobByJobParentId(job.getJobId());
+                    job.setChildren(childOpt);
+                })
                 .collect(Collectors.toList());
 
         return new PaginationData<WaylineJobDTO>(records, new Pagination(pageData));
@@ -717,20 +745,22 @@
 
         // get file url
         URL url = null;
-        String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath());
+        String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath1());
         String md5 = "";
         try (InputStream inputStream = _ossService.getObject(kmzPath, minioUrl)) {
             md5 = DigestUtils.md5Hex(inputStream);
-            url = new URL(ardRouteOpt.getPath());
+            url = new URL(ardRouteOpt.getPath1());
             log.info("机场通过flightTaskResourceGet获取航线文件地址,jobId: " + jobId + " 返回信息为url:" + url.toString() + " md5:" + md5);
 //        }
 //        try {
 //            url = waylineFileService.getObjectUrl(waylineFile.get().getWaylineId());
 //            url = new URL(ardRouteOpt.getUpPath());
 
-            Map<String, Object> jsonResourceGet = new HashMap<>();
-            jsonResourceGet.put("url", url.toString().replace("https//192.168.10.103:9001", "http//192.168.10.103:9002"));
-            jsonResourceGet.put("fingerprint", md5);
+//            Map<String, Object> jsonResourceGet = new HashMap<>();
+//            jsonResourceGet.put("url", url.toString().replace("https//192.168.10.103:9001", "http//192.168.10.103:9002"));
+//            jsonResourceGet.put("fingerprint", md5);
+//            .replace("https://", "http://")
+//            .replace("9001", "9011")
 
             builder.data(RequestsReply.success(WaylineTaskCreateDTO.builder()
                     .file(WaylineTaskFileDTO.builder()
@@ -738,12 +768,6 @@
                     .fingerprint(md5)
                     .build())
                     .build()));
-
-//            WaylineTaskFileDTO.builder()
-//                    .url(url.toString())
-////                            .fingerprint(waylineFile.get().getSign())
-//                    .fingerprint(md5)
-//                    .build()
 
         } catch (NullPointerException | IOException e) {
             e.printStackTrace();
@@ -794,7 +818,8 @@
                         .data(Map.of(MapKeyConst.FLIGHT_ID, jobId))
                         .build());
         if (ResponseResult.CODE_SUCCESS != reply.getResult()) {
-            throw new RuntimeException("Failed to set media job upload priority. Error Code: " + reply.getResult());
+            String errorMsg = CommonErrorEnum.getMsgByCode(reply.getResult());
+            throw new RuntimeException("未能设置媒体作业上传优先级. Error Code: " + reply.getResult() +", Error Msg: " + errorMsg);
         }
     }
 

--
Gitblit v1.9.3