| | |
| | | |
| | | /** |
| | | * 对于即时任务,以服务器时间为准。 |
| | | * |
| | | * @param param |
| | | */ |
| | | private void fillImmediateTime(CreateJobParam param) { |
| | |
| | | |
| | | @Override |
| | | public ResponseResult publishFlightTask(CreateJobParam param, CustomClaim customClaim) throws SQLException { |
| | | |
| | | //当重复定时和连续执行时走这个逻辑 |
| | | if (param.getTaskType().getVal() == WaylineTaskTypeEnum.CONDITION.getVal()){ |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //保存数据 |
| | | WaylineJobEntity waylineJobEntity = WaylineJobEntity.builder() |
| | | .jobId(UUID.randomUUID().toString()) |
| | | .name(param.getName()) |
| | | .dockSn(param.getDockSn()) |
| | | .fileId(param.getFileId()) |
| | | .username(customClaim.getUsername()) |
| | | .workspaceId(customClaim.getWorkspaceId()) |
| | | |
| | | |
| | | .beginTime(param.getTaskDays().get(0)*1000) |
| | | .endTime(param.getTaskDays().get(1)*1000) |
| | | .status(WaylineJobStatusEnum.PENDING.getVal()) |
| | | .taskType(param.getTaskType().getVal()) |
| | | .waylineType(param.getWaylineType().getVal()) |
| | | .outOfControlAction(param.getOutOfControlAction()) |
| | | .batteryCapacity(param.getMinBatteryCapacity()) |
| | | .rthAltitude(param.getRthAltitude()) |
| | | .mediaCount(0) |
| | | .repFreVal(param.getRepFreVal()) |
| | | .repFreType(param.getRepFreType()) |
| | | .repRuleType(param.getRepRuleType()) |
| | | .repRuleVal(param.getRepRuleVal()) |
| | | .executeTimeArr(param.getTaskPeriods()) |
| | | .executeStartTimeArr(param.getExecuteStartTimeArr()) |
| | | .build(); |
| | | |
| | | Boolean insert = mapper.insert(waylineJobEntity)>0; |
| | | |
| | | return ResponseResult.success(insert); |
| | | } |
| | | |
| | | fillImmediateTime(param); |
| | | |
| | | // param.getTaskDays().sort((a, b) -> (int) (a - b)); |
| | |
| | | return response; |
| | | } |
| | | } |
| | | } |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult publishFlightTaskCondition(CreateJobParam param, CustomClaim customClaim) throws SQLException { |
| | | //开始日期 |
| | | LocalDate startDate = LocalDate.ofInstant(Instant.ofEpochSecond(param.getTaskDays().get(0)), ZoneId.systemDefault()); |
| | | long start = LocalDateTime.of(startDate, LocalTime.ofInstant(Instant.ofEpochSecond(param.getExecuteStartTimeArr().get(0).get(0)), ZoneId.systemDefault())) |
| | | .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | |
| | | //结束日期 |
| | | LocalDate endDate = LocalDate.ofInstant(Instant.ofEpochSecond(param.getTaskDays().get(1)), ZoneId.systemDefault()); |
| | | long end = LocalDateTime.of(endDate, LocalTime.ofInstant(Instant.ofEpochSecond(param.getExecuteStartTimeArr().get(param.getExecuteStartTimeArr().size() - 1).get(0)), ZoneId.systemDefault())) |
| | | .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | |
| | | //保存数据 |
| | | WaylineJobEntity waylineJobEntity = WaylineJobEntity.builder() |
| | | .jobId(UUID.randomUUID().toString()) |
| | | .name(param.getName()) |
| | | .dockSn(param.getDockSn()) |
| | | .fileId(param.getFileId()) |
| | | .username(customClaim.getUsername()) |
| | | .workspaceId(customClaim.getWorkspaceId()) |
| | | |
| | | .beginTime(start) |
| | | .endTime(end) |
| | | .status(WaylineJobStatusEnum.PENDING.getVal()) |
| | | .taskType(param.getTaskType().getVal()) |
| | | .waylineType(param.getWaylineType().getVal()) |
| | | .outOfControlAction(param.getOutOfControlAction()) |
| | | .batteryCapacity(param.getMinBatteryCapacity()) |
| | | .rthAltitude(param.getRthAltitude()) |
| | | .mediaCount(0) |
| | | .repFreVal(param.getRepFreVal()) |
| | | .repFreType(param.getRepFreType()) |
| | | .repRuleType(param.getRepRuleType()) |
| | | .repRuleVal(param.getRepRuleVal()) |
| | | .executeTimeArr(param.getTaskPeriods()) |
| | | .executeStartTimeArr(param.getExecuteStartTimeArr()) |
| | | .build(); |
| | | |
| | | Optional<WaylineJobDTO> waylineJobOpt = insertWaylineJob(waylineJobEntity); |
| | | |
| | | if (waylineJobOpt.isEmpty()) { |
| | | throw new SQLException("任务创建失败"); |
| | | } |
| | | |
| | | WaylineJobDTO waylineJob = waylineJobOpt.get(); |
| | | |
| | | //循环执行时间 |
| | | for (List<Long> timeArr : param.getExecuteStartTimeArr()) { |
| | | LocalDate date = LocalDate.ofInstant(Instant.ofEpochSecond(timeArr.get(0)), ZoneId.systemDefault()); |
| | | long beginTime = LocalDateTime.of(date, LocalTime.ofInstant(Instant.ofEpochSecond(timeArr.get(0)), ZoneId.systemDefault())) |
| | | .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | |
| | | long endTime = timeArr.size() > 1 && Objects.nonNull(timeArr.get(1)) ? |
| | | LocalDateTime.of(date, LocalTime.ofInstant(Instant.ofEpochSecond(timeArr.get(1)), ZoneId.systemDefault())) |
| | | .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() : beginTime; |
| | | |
| | | if (WaylineTaskTypeEnum.IMMEDIATE != param.getTaskType() && endTime < System.currentTimeMillis()) { |
| | | //中断当前循环执行下一个 |
| | | continue; |
| | | } |
| | | |
| | | |
| | | //条件任务 |
| | | if (param.getTaskType() == WaylineTaskTypeEnum.CONDITION) { |
| | | //如果是条件任务类型,需要在任务参数中添加条件。 |
| | | waylineJob.setConditions( |
| | | WaylineTaskConditionDTO.builder() |
| | | .executableConditions(Objects.nonNull(param.getMinStorageCapacity()) ? WaylineTaskExecutableConditionDTO.builder().storageCapacity(param.getMinStorageCapacity()).build() : null) |
| | | .readyConditions(WaylineTaskReadyConditionDTO.builder() |
| | | .batteryCapacity(param.getMinBatteryCapacity()) |
| | | .beginTime(beginTime) |
| | | .endTime(endTime) |
| | | .build()) |
| | | .build()); |
| | | } |
| | | |
| | | ResponseResult response = this.publishOneFlightTask(waylineJob); |
| | | if (ResponseResult.CODE_SUCCESS != response.getCode()) { |
| | | return response; |
| | | } |
| | | |
| | | } |
| | | return ResponseResult.success(); |
| | | } |
| | |
| | | } |
| | | |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean publishFlightTask(WaylineJobEntity waylineJobEntity) { |
| | | WaylineJobDTO waylineJob = new WaylineJobDTO(); |
| | | |
| | | |
| | | waylineJob.setConditions( |
| | | WaylineTaskConditionDTO.builder() |
| | | .executableConditions(null) |
| | | .readyConditions(WaylineTaskReadyConditionDTO.builder() |
| | | .batteryCapacity(waylineJobEntity.getBatteryCapacity()) |
| | | |
| | | .build()) |
| | | .build()); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private Boolean prepareFlightTask(WaylineJobDTO waylineJob) throws SQLException { |
| | |
| | | |
| | | Set<String> waylineJobIds = waylineJobs.stream().map(WaylineJobDTO::getJobId).collect(Collectors.toSet()); |
| | | // Check if the task status is correct. |
| | | boolean isErr = !jobIds.removeAll(waylineJobIds) || !jobIds.isEmpty() ; |
| | | boolean isErr = !jobIds.removeAll(waylineJobIds) || !jobIds.isEmpty(); |
| | | if (isErr) { |
| | | throw new IllegalArgumentException("以下任务状态不正确,不能取消" + Arrays.toString(jobIds.toArray())); |
| | | } |
| | |
| | | |
| | | public List<WaylineJobDTO> getJobsByConditions(String workspaceId, Collection<String> jobIds, WaylineJobStatusEnum status) { |
| | | return mapper.selectList( |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | | .eq(Objects.nonNull(status), WaylineJobEntity::getStatus, status.getVal()) |
| | | .in(!CollectionUtils.isEmpty(jobIds), WaylineJobEntity::getJobId, jobIds)) |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | | .eq(Objects.nonNull(status), WaylineJobEntity::getStatus, status.getVal()) |
| | | .in(!CollectionUtils.isEmpty(jobIds), WaylineJobEntity::getJobId, jobIds)) |
| | | .stream() |
| | | .map(this::entity2Dto) |
| | | .collect(Collectors.toList()); |
| | |
| | | // |
| | | // .orderByDesc(WaylineJobEntity::getId)); |
| | | |
| | | Page<WaylineJobEntity> pageData = mapper.getPage(new Page<WaylineJobEntity>(page, pageSize),waylineJobQueryParam,workspaceId); |
| | | |
| | | Page<WaylineJobEntity> pageData = mapper.getPage(new Page<WaylineJobEntity>(page, pageSize), waylineJobQueryParam, workspaceId); |
| | | |
| | | |
| | | List<WaylineJobDTO> records = pageData.getRecords() |
| | |
| | | @ServiceActivator(inputChannel = ChannelName.INBOUND_REQUESTS_FLIGHT_TASK_RESOURCE_GET, outputChannel = ChannelName.OUTBOUND) |
| | | @Transactional(isolation = Isolation.READ_UNCOMMITTED) |
| | | public void flightTaskResourceGet(CommonTopicReceiver receiver, MessageHeaders headers) { |
| | | Map<String, String> jobIdMap = objectMapper.convertValue(receiver.getData(), new TypeReference<Map<String, String>>() {}); |
| | | Map<String, String> jobIdMap = objectMapper.convertValue(receiver.getData(), new TypeReference<Map<String, String>>() { |
| | | }); |
| | | String jobId = jobIdMap.get(MapKeyConst.FLIGHT_ID); |
| | | |
| | | CommonTopicResponse.CommonTopicResponseBuilder<RequestsReply> builder = CommonTopicResponse.<RequestsReply>builder() |
| | |
| | | return WaylineJobStatusEnum.UNKNOWN; |
| | | } |
| | | |
| | | @Override |
| | | public WaylineJobEntity getLatestJob(String workspaceId, WaylineJobQueryParam waylineJobQueryParam) { |
| | | // List<WaylineJobEntity> waylineJobEntities = mapper.selectList(new LambdaQueryWrapper<>(WaylineJobEntity.class) |
| | | // .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | | // .eq(WaylineJobEntity::getDockSn, waylineJobQueryParam.getDockSn()) |
| | | // //获取状态为待执行 |
| | | // .eq(WaylineJobEntity::getStatus,1) |
| | | // .orderByDesc(WaylineJobEntity::getBeginTime) |
| | | // ); |
| | | |
| | | WaylineJobEntity waylineJobEntity = mapper.getLatest(workspaceId,waylineJobQueryParam); |
| | | |
| | | |
| | | return waylineJobEntity; |
| | | } |
| | | |
| | | private void pauseJob(String workspaceId, String dockSn, String jobId, WaylineJobStatusEnum statusEnum) { |
| | | if (WaylineJobStatusEnum.PAUSED == statusEnum && jobId.equals(waylineRedisService.getPausedWaylineJobId(dockSn))) { |
| | | waylineRedisService.setPausedWaylineJob(dockSn, jobId); |
| | |
| | | .workspaceId(entity.getWorkspaceId()) |
| | | .status(WaylineJobStatusEnum.IN_PROGRESS.getVal() == entity.getStatus() && |
| | | entity.getJobId().equals(waylineRedisService.getPausedWaylineJobId(entity.getDockSn())) ? |
| | | WaylineJobStatusEnum.PAUSED.getVal() : entity.getStatus()) |
| | | WaylineJobStatusEnum.PAUSED.getVal() : entity.getStatus()) |
| | | .code(entity.getErrorCode()) |
| | | .beginTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(entity.getBeginTime()), ZoneId.systemDefault())) |
| | | .endTime(Objects.nonNull(entity.getEndTime()) ? |
| | |
| | | Object mediaFileCount = RedisOpsUtils.hashGet(countKey, entity.getJobId()); |
| | | if (Objects.nonNull(mediaFileCount)) { |
| | | builder.uploadedCount(((MediaFileCountDTO) mediaFileCount).getUploadedCount()) |
| | | .uploading(RedisOpsUtils.checkExist(key) && entity.getJobId().equals(((MediaFileCountDTO)RedisOpsUtils.get(key)).getJobId())); |
| | | .uploading(RedisOpsUtils.checkExist(key) && entity.getJobId().equals(((MediaFileCountDTO) RedisOpsUtils.get(key)).getJobId())); |
| | | return builder.build(); |
| | | } |
| | | |