| | |
| | | import com.dji.sample.wayline.model.enums.*; |
| | | import com.dji.sample.wayline.model.param.CreateJobParam; |
| | | import com.dji.sample.wayline.model.param.UpdateJobParam; |
| | | import com.dji.sample.wayline.model.param.WaylineJobQueryParam; |
| | | import com.dji.sample.wayline.service.IWaylineFileService; |
| | | import com.dji.sample.wayline.service.IWaylineJobService; |
| | | import com.dji.sample.wayline.service.IWaylineRedisService; |
| | |
| | | } |
| | | |
| | | /** |
| | | * For immediate tasks, the server time shall prevail. |
| | | * 对于即时任务,以服务器时间为准。 |
| | | * @param param |
| | | */ |
| | | private void fillImmediateTime(CreateJobParam param) { |
| | | if (WaylineTaskTypeEnum.IMMEDIATE != param.getTaskType()) { |
| | | return; |
| | | } |
| | | long now = System.currentTimeMillis() / 1000; |
| | | param.setTaskDays(Collections.singletonList(now)); |
| | | param.setTaskPeriods(Collections.singletonList(Collections.singletonList(now))); |
| | | long now = System.currentTimeMillis() / 1000 - 10; |
| | | // param.setTaskDays(Collections.singletonList(now)); |
| | | // param.setTaskPeriods(Collections.singletonList(Collections.singletonList(now))); |
| | | param.setTaskDays(List.of(now)); |
| | | param.setTaskPeriods(List.of(List.of(now))); |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult publishFlightTask(CreateJobParam param, CustomClaim customClaim) throws SQLException { |
| | | fillImmediateTime(param); |
| | | |
| | | param.getTaskDays().sort((a, b) -> (int) (a - b)); |
| | | param.getTaskPeriods().sort((a, b) -> (int) (a.get(0) - b.get(0))); |
| | | // param.getTaskDays().sort((a, b) -> (int) (a - b)); |
| | | // param.getTaskPeriods().sort((a, b) -> (int) (a.get(0) - b.get(0))); |
| | | for (Long taskDay : param.getTaskDays()) { |
| | | LocalDate date = LocalDate.ofInstant(Instant.ofEpochSecond(taskDay), ZoneId.systemDefault()); |
| | | for (List<Long> taskPeriod : param.getTaskPeriods()) { |
| | |
| | | } |
| | | Optional<WaylineJobDTO> waylineJobOpt = this.createWaylineJob(param, customClaim.getWorkspaceId(), customClaim.getUsername(), beginTime, endTime); |
| | | if (waylineJobOpt.isEmpty()) { |
| | | return ResponseResult.error("Failed to create wayline job."); |
| | | throw new SQLException("Failed to create wayline job."); |
| | | } |
| | | |
| | | WaylineJobDTO waylineJob = waylineJobOpt.get(); |
| | | if (WaylineTaskTypeEnum.IMMEDIATE == param.getTaskType()) { |
| | | return this.publishOneFlightTask(waylineJob); |
| | | } |
| | | |
| | | // If it is a conditional task type, add conditions to the job parameters. |
| | | addPreparedJob(waylineJob, param, beginTime, endTime); |
| | | |
| | | ResponseResult response = this.publishOneFlightTask(waylineJob); |
| | | if (ResponseResult.CODE_SUCCESS != response.getCode()) { |
| | | return response; |
| | | } |
| | | } |
| | | } |
| | | return ResponseResult.success(); |
| | |
| | | |
| | | boolean isOnline = deviceRedisService.checkDeviceOnline(waylineJob.getDockSn()); |
| | | if (!isOnline) { |
| | | throw new RuntimeException("Dock is offline."); |
| | | throw new RuntimeException("设备离线。"); |
| | | } |
| | | |
| | | // get wayline file |
| | | Optional<WaylineFileDTO> waylineFile = waylineFileService.getWaylineByWaylineId(waylineJob.getWorkspaceId(), waylineJob.getFileId()); |
| | | if (waylineFile.isEmpty()) { |
| | | throw new SQLException("Wayline file doesn't exist."); |
| | | throw new SQLException("航线文件不存在。"); |
| | | } |
| | | |
| | | // get file url |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PaginationData<WaylineJobDTO> getJobsByWorkspaceId(String workspaceId, long page, long pageSize) { |
| | | Page<WaylineJobEntity> pageData = mapper.selectPage( |
| | | new Page<WaylineJobEntity>(page, pageSize), |
| | | new LambdaQueryWrapper<WaylineJobEntity>() |
| | | .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | | .orderByDesc(WaylineJobEntity::getId)); |
| | | public PaginationData<WaylineJobDTO> getJobsByWorkspaceId(String workspaceId, long page, long pageSize, WaylineJobQueryParam waylineJobQueryParam) { |
| | | // Page<WaylineJobEntity> pageData = mapper.selectPage( |
| | | // new Page<WaylineJobEntity>(page, pageSize), |
| | | // new LambdaQueryWrapper<WaylineJobEntity>() |
| | | // .eq(WaylineJobEntity::getWorkspaceId, workspaceId) |
| | | // .eq(waylineJobDTO.getTaskType() !=null, WaylineJobEntity::getTaskType, waylineJobDTO.getTaskType()) |
| | | // .eq(waylineJobDTO.getStatus()!=null, WaylineJobEntity::getStatus, waylineJobDTO.getStatus()) |
| | | // .like(StringUtils.hasText(waylineJobDTO.getJobName()),WaylineJobEntity::getName,waylineJobDTO.getJobName()) |
| | | // |
| | | // |
| | | // .orderByDesc(WaylineJobEntity::getId)); |
| | | |
| | | Page<WaylineJobEntity> pageData = mapper.getPage(new Page<WaylineJobEntity>(page, pageSize),waylineJobQueryParam,workspaceId); |
| | | |
| | | |
| | | |
| | | List<WaylineJobDTO> records = pageData.getRecords() |
| | | .stream() |
| | | .map(this::entity2Dto) |