| | |
| | | } |
| | | |
| | | if (waylineJobOpt.isEmpty()) { |
| | | return ResponseResult.error("创建机场任务失败!"); |
| | | return ResponseResult.error(314013000,"创建机场任务失败!"); |
| | | } |
| | | |
| | | WaylineJobDTO waylineJob = waylineJobOpt.get(); |
| | |
| | | // } |
| | | // 换航线表 |
| | | ArdRouteInfo ardRouteOpt = _ardRouteInfoService.selectArdRouteInfoById(waylineJob.getFileId()); |
| | | if (ardRouteOpt == null) { |
| | | return ResponseResult.error("机场任务航线不存在!"); |
| | | if (ardRouteOpt == null || ardRouteOpt.getPath1() == null || ardRouteOpt.getPath1().isEmpty()) { |
| | | return ResponseResult.error(314013001,"机场任务航线不存在!"); |
| | | } |
| | | |
| | | // get file url |
| | |
| | | log.info("机场任务航线文件md5值:{}", md5); |
| | | } catch (Exception e) { |
| | | log.error("机场任务航线文件地址错误!{}", e.getMessage()); |
| | | return ResponseResult.error("机场任务航线文件地址错误!" + e.getMessage()); |
| | | return ResponseResult.error(314013002,"机场任务航线文件地址错误!" + e.getMessage()); |
| | | } |
| | | |
| | | log.info("机场任务-rth_mode的值:{}", waylineJob.getRthMode()); |
| | |
| | | // Issue an immediate task execution command. |
| | | if (WaylineTaskTypeEnum.IMMEDIATE.getVal() == waylineJob.getTaskType()) { |
| | | if (!executeFlightTask(waylineJob.getJobId())) { |
| | | return ResponseResult.error("Failed to execute job."); |
| | | return ResponseResult.error("无法执行作业。"); |
| | | } |
| | | } |
| | | |
| | |
| | | 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.error("无法创建计划作业。"); |
| | | } |
| | | } |
| | | |
| | |
| | | public ResponseResult publishFlightTaskPrepare(Optional<WaylineJobDTO> waylineJobOpt) throws SQLException{ |
| | | |
| | | if (waylineJobOpt.isEmpty()) { |
| | | return ResponseResult.error("创建机场任务失败!"); |
| | | return ResponseResult.error(314013000,"创建机场任务失败!"); |
| | | } |
| | | WaylineJobDTO waylineJob = waylineJobOpt.get(); |
| | | boolean isOnline = deviceService.checkDeviceOnline(waylineJob.getDockSn()); |
| | |
| | | } |
| | | // 换航线表 |
| | | ArdRouteInfo ardRouteOpt = _ardRouteInfoService.selectArdRouteInfoById(waylineJob.getFileId()); |
| | | if (ardRouteOpt == null) { |
| | | return ResponseResult.error("机场任务航线不存在!"); |
| | | if (ardRouteOpt == null || ardRouteOpt.getPath1() == null || ardRouteOpt.getPath1().isEmpty()) { |
| | | return ResponseResult.error(314013001,"机场任务航线不存在!"); |
| | | } |
| | | // 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("机场任务航线文件url地址:{}", url); |
| | | log.info("机场任务航线文件md5值:{}", md5); |
| | | } catch (Exception e) { |
| | | log.error("机场任务航线文件地址错误!{}", e.getMessage()); |
| | | return ResponseResult.error("机场任务航线文件地址错误!" + e.getMessage()); |
| | | return ResponseResult.error(314013002,"机场任务航线文件地址错误!" + e.getMessage()); |
| | | } |
| | | |
| | | WaylineTaskCreateDTO flightTask = WaylineTaskCreateDTO.builder() |
| | |
| | | .waylineType(waylineJob.getWaylineType()) |
| | | .rthAltitude(waylineJob.getRthAltitude()) |
| | | .outOfControlAction(waylineJob.getOutOfControlAction()) |
| | | .rthMode(waylineJob.getRthMode()) |
| | | .file(WaylineTaskFileDTO.builder() |
| | | .url(url.toString()) |
| | | // .fingerprint(waylineFile.get().getSign()) |
| | |
| | | // Issue an immediate task execution command. |
| | | if (WaylineTaskTypeEnum.IMMEDIATE.getVal() == waylineJob.getTaskType()) { |
| | | if (!executeFlightTask(waylineJob.getJobId())) { |
| | | return ResponseResult.error("Failed to execute job."); |
| | | return ResponseResult.error("无法执行作业。"); |
| | | } |
| | | } |
| | | |
| | |
| | | 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.error("无法创建计划作业。"); |
| | | } |
| | | } |
| | | |
| | |
| | | //// + Arrays.toString(jobIds.toArray())); |
| | | // } |
| | | |
| | | // Group job id by dock sn. |
| | | // 按 dock sn 对作业 ID 进行分组。 |
| | | Map<String, List<String>> dockJobs = waylineJobs.stream() |
| | | .collect(Collectors.groupingBy(WaylineJobDTO::getDockSn, |
| | | Collectors.mapping(WaylineJobDTO::getJobId, Collectors.toList()))); |
| | |
| | | */ |
| | | @Override |
| | | public ResponseResult publishCancelTask(String dockSn, List<String> jobIds) { |
| | | |
| | | for(String jobId : jobIds) { |
| | | Optional<WaylineJobDTO> waylineJobDTO = this.getJobByJobId(jobId); |
| | | if (waylineJobDTO.isEmpty()) { |
| | | return ResponseResult.error("任务不存在,jobId: " + jobId); |
| | | } |
| | | if (waylineJobDTO.get().getTaskType() == 3) { |
| | | // 已经执行完的子任务一起全部删除 |
| | | this.deleteTask(jobId); |
| | | log.info("删除循环任务已经完成,主任务ID:{}。", waylineJobDTO.get().getJobId()); |
| | | List<WaylineJobDTO> waylineParentIds = this.getJobByJobParentId(jobId); |
| | | if (!waylineParentIds.isEmpty()) { |
| | | for (WaylineJobDTO waylineJob : waylineParentIds) { |
| | | this.deleteTask(waylineJob.getJobId()); |
| | | RedisOpsUtils.zRemove(RedisConst.WAYLINE_JOB_TIMED_EXECUTE, dockSn + RedisConst.DELIMITER + waylineJob.getJobId()); |
| | | log.info("删除循环子任务已经完成,子任务ID:{}。", waylineJob.getJobId()); |
| | | } |
| | | } |
| | | return ResponseResult.success(); |
| | | } |
| | | } |
| | | boolean isOnline = deviceService.checkDeviceOnline(dockSn); |
| | | if (!isOnline) { |
| | | Integer errorCode = CommonErrorEnum.DEVICE_OFFLINE.getErrorCode(); |
| | |
| | | .status(WaylineJobStatusEnum.CANCEL.getVal()) |
| | | .completedTime(LocalDateTime.now()) |
| | | .build()); |
| | | RedisOpsUtils.zRemove(RedisConst.WAYLINE_JOB_TIMED_EXECUTE, RedisConst.DELIMITER + dockSn + RedisConst.DELIMITER + jobId); |
| | | RedisOpsUtils.zRemove(RedisConst.WAYLINE_JOB_TIMED_EXECUTE, dockSn + RedisConst.DELIMITER + jobId); |
| | | // 原流程是修改表中数据的status状态值,现在的精力是直接删除 |
| | | this.deleteTask(jobId); |
| | | } |
| | |
| | | public List<WaylineJobDTO> getJobsByConditions(Collection<String> jobIds, WaylineJobStatusEnum status) { |
| | | return mapper.selectList( |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(Objects.nonNull(status), WaylineJobEntity::getStatus, status.getVal()) |
| | | // 不过滤状态, |
| | | //.eq(Objects.nonNull(status), WaylineJobEntity::getStatus, status.getVal()) |
| | | .and(!CollectionUtils.isEmpty(jobIds), |
| | | wrapper -> jobIds.forEach(id -> wrapper.eq(WaylineJobEntity::getJobId, id).or()))) |
| | | .stream() |
| | |
| | | .orderByDesc(WaylineJobEntity::getId)); |
| | | } |
| | | |
| | | /** |
| | | * 获取所有待定状态的定时任务,未执行即将要执行的。 |
| | | * */ |
| | | public List<WaylineJobEntity> selectScheduledTaskList(){ |
| | | // "1":"定时任务" |
| | | return mapper.selectList(new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(WaylineJobEntity::getTaskType, 1) |
| | | .eq(WaylineJobEntity::getStatus, WaylineJobStatusEnum.PENDING.getVal()) |
| | | .gt(WaylineJobEntity::getBeginTime, System.currentTimeMillis()) |
| | | .orderByDesc(WaylineJobEntity::getBeginTime)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据航班任务ID获取航班任务资源 |