zhaowenyu
2025-11-20 1d427f8b485ad3ed405fdc4a0292fcbd811790db
ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java
@@ -179,13 +179,14 @@
        }
        Optional<WaylineJobDTO> waylineJobOpt = this.createWaylineJob(param, loginUser.getUsername(),
                param.getExecuteTime(), param.getExecuteTime());
        if (waylineJobOpt.isEmpty()) {
            return ResponseResult.error("创建机场任务失败!");
        }
        // 循环任务
        if (param.getTaskType() == WaylineTaskTypeEnum.LOOP.getVal()) {
            // 循环任务,不立即执行,由定时任务发布
            return ResponseResult.success();
        }
        if (waylineJobOpt.isEmpty()) {
            return ResponseResult.error("创建机场任务失败!");
        }
        WaylineJobDTO waylineJob = waylineJobOpt.get();
@@ -262,20 +263,20 @@
        // 飞行命令先注释掉
        // Issue an immediate task execution command.
//        if (WaylineTaskTypeEnum.IMMEDIATE.getVal() == waylineJob.getTaskType()) {
//            if (!executeFlightTask(waylineJob.getJobId())) {
//                return ResponseResult.error("Failed to execute job.");
//            }
//        }
//
//        if (WaylineTaskTypeEnum.TIMED.getVal() == waylineJob.getTaskType()) {
//            boolean isAdd = RedisOpsUtils.zAdd(RedisConst.WAYLINE_JOB_TIMED_EXECUTE,
//                     waylineJob.getDockSn() + RedisConst.DELIMITER + waylineJob.getJobId(),
//                    waylineJob.getBeginTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
//            if (!isAdd) {
//                return ResponseResult.error("Failed to create scheduled job.");
//            }
//        }
        if (WaylineTaskTypeEnum.IMMEDIATE.getVal() == waylineJob.getTaskType()) {
            if (!executeFlightTask(waylineJob.getJobId())) {
                return ResponseResult.error("Failed to execute job.");
            }
        }
        if (WaylineTaskTypeEnum.TIMED.getVal() == waylineJob.getTaskType()) {
            boolean isAdd = RedisOpsUtils.zAdd(RedisConst.WAYLINE_JOB_TIMED_EXECUTE,
                     waylineJob.getDockSn() + RedisConst.DELIMITER + waylineJob.getJobId(),
                    waylineJob.getBeginTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
            if (!isAdd) {
                return ResponseResult.error("Failed to create scheduled job.");
            }
        }
        return ResponseResult.success();
    }
@@ -350,20 +351,20 @@
        // 飞行命令先注释掉
        // Issue an immediate task execution command.
//        if (WaylineTaskTypeEnum.IMMEDIATE.getVal() == waylineJob.getTaskType()) {
//            if (!executeFlightTask(waylineJob.getJobId())) {
//                return ResponseResult.error("Failed to execute job.");
//            }
//        }
//
//        if (WaylineTaskTypeEnum.TIMED.getVal() == waylineJob.getTaskType()) {
//            boolean isAdd = RedisOpsUtils.zAdd(RedisConst.WAYLINE_JOB_TIMED_EXECUTE,
//                     waylineJob.getDockSn() + RedisConst.DELIMITER + waylineJob.getJobId(),
//                    waylineJob.getBeginTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
//            if (!isAdd) {
//                return ResponseResult.error("Failed to create scheduled job.");
//            }
//        }
        if (WaylineTaskTypeEnum.IMMEDIATE.getVal() == waylineJob.getTaskType()) {
            if (!executeFlightTask(waylineJob.getJobId())) {
                return ResponseResult.error("Failed to execute job.");
            }
        }
        if (WaylineTaskTypeEnum.TIMED.getVal() == waylineJob.getTaskType()) {
            boolean isAdd = RedisOpsUtils.zAdd(RedisConst.WAYLINE_JOB_TIMED_EXECUTE,
                     waylineJob.getDockSn() + RedisConst.DELIMITER + waylineJob.getJobId(),
                    waylineJob.getBeginTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
            if (!isAdd) {
                return ResponseResult.error("Failed to create scheduled job.");
            }
        }
        return ResponseResult.success();
    }
@@ -439,8 +440,9 @@
        // Check if the task status is correct.
        boolean isErr = !jobIds.removeAll(waylineJobIds) || !jobIds.isEmpty();
        if (isErr) {
            throw new IllegalArgumentException("These tasks have an incorrect status and cannot be canceled. "
                    + Arrays.toString(jobIds.toArray()));
            throw new IllegalArgumentException("任务开始后,无法取消。" + Arrays.toString(jobIds.toArray()));
//            throw new IllegalArgumentException("These tasks have an incorrect status and cannot be canceled. "
//                    + Arrays.toString(jobIds.toArray()));
        }
        // Group job id by dock sn.
@@ -778,14 +780,27 @@
            return null;
        }
        // 修改航线文件名称,从ard_route_info航线表中取;
        String fileId = entity.getFileId();
        String fileName = "";
        try {
            if (fileId != null) {
                ArdRouteInfo ardRouteInfo = _ardRouteInfoService.selectArdRouteInfoById(fileId);
                if (ardRouteInfo != null) {
                    fileName = Optional.ofNullable(ardRouteInfo.getName()).orElse("");
                }
            }
        }
        catch (Exception e) {
            log.info("获取航线名称失败,fileId:{},异常原因:{}", fileId,e.getMessage());
            fileName = "";
        }
        WaylineJobDTO.WaylineJobDTOBuilder builder = WaylineJobDTO.builder()
                .jobId(entity.getJobId())
                .jobName(entity.getName())
                .fileId(entity.getFileId())
//                .fileName(waylineFileService.getWaylineByWaylineId(entity.getFileId())
//                        .orElse(WaylineFileDTO.builder().build()).getName())
                .fileName(_ardRouteInfoService.selectArdRouteInfoById(entity.getFileId())
                        .getName())
                .fileName(fileName)
                .dockSn(entity.getDockSn())
                .dockName(deviceService.getDeviceBySn(entity.getDockSn())
                        .orElse(DeviceDTO.builder().build()).getNickname())