Merge remote-tracking branch 'origin/main'
| | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * Unified topic receiving format. |
| | | * 统一主题接收格式。 |
| | | * @author sean.zhou |
| | | * @date 2021/11/10 |
| | | * @version 0.1 |
| | |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | /** |
| | | * Unified Topic response format |
| | | * 统一主题响应格式 |
| | | * @author sean.zhou |
| | | * @date 2021/11/15 |
| | | * @version 0.1 |
| | |
| | | private String bid; |
| | | |
| | | private String method; |
| | | private String gateway; |
| | | |
| | | private T data; |
| | | |
| | |
| | | * @return |
| | | */ |
| | | ServiceReply publishServicesTopic(String sn, String method, Object data); |
| | | |
| | | <T> ServiceReply<T> publishRequestsTopic(TypeReference<T> clazz, String sn, String method, Object data, String bid); |
| | | |
| | | ServiceReply publishRequestsTopic(String sn, String method, Object data, String bid); |
| | | |
| | | ServiceReply publishRequestsTopic(String sn, String method, Object data); |
| | | |
| | | } |
| | |
| | | response.setBid(UUID.randomUUID().toString()); |
| | | response.setTid(UUID.randomUUID().toString()); |
| | | } |
| | | throw new RuntimeException("No message reply received."); |
| | | throw new RuntimeException("没有收到消息回复。"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return this.publishServicesTopic(null, sn, method, data, null); |
| | | } |
| | | |
| | | @Override |
| | | public <T> ServiceReply<T> publishRequestsTopic(TypeReference<T> clazz, String sn, String method, Object data, String bid) { |
| | | String topic = TopicConst.THING_MODEL_PRE + TopicConst.PRODUCT + sn + TopicConst.REQUESTS_SUF; |
| | | ServiceReply reply = this.publishWithReply(ServiceReply.class, topic, |
| | | CommonTopicResponse.builder() |
| | | .tid(UUID.randomUUID().toString()) |
| | | .bid(StringUtils.hasText(bid) ? bid : UUID.randomUUID().toString()) |
| | | .timestamp(System.currentTimeMillis()) |
| | | .gateway(sn) |
| | | .method(method) |
| | | .data(Objects.requireNonNullElse(data, "")) |
| | | .build()); |
| | | if (Objects.isNull(clazz)) { |
| | | return reply; |
| | | } |
| | | // put together in "output" |
| | | if (Objects.nonNull(reply.getInfo())) { |
| | | reply.setOutput(mapper.convertValue(reply.getInfo(), clazz)); |
| | | } |
| | | if (Objects.nonNull(reply.getOutput())) { |
| | | reply.setOutput(mapper.convertValue(reply.getOutput(), clazz)); |
| | | } |
| | | return reply; |
| | | } |
| | | |
| | | @Override |
| | | public ServiceReply publishRequestsTopic(String sn, String method, Object data, String bid) { |
| | | return this.publishRequestsTopic(null, sn, method, data, bid); |
| | | } |
| | | |
| | | @Override |
| | | public ServiceReply publishRequestsTopic(String sn, String method, Object data) { |
| | | return this.publishRequestsTopic(null, sn, method, data, null); |
| | | } |
| | | |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | ResponseResult payloadCommands(PayloadCommandsParam param) throws Exception; |
| | | |
| | | ResponseResult requestsConfig(String sn,String method, RequestsParam param); |
| | | |
| | | } |
| | |
| | | : ResponseResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult requestsConfig(String sn,String method, RequestsParam param) { |
| | | ServiceReply serviceReply = messageSenderService.publishRequestsTopic(sn, method, param); |
| | | return ResponseResult.CODE_SUCCESS != serviceReply.getResult() ? |
| | | ResponseResult.error(serviceReply.getResult(), " Error Code:" + serviceReply.getResult()) |
| | | : ResponseResult.success(); |
| | | } |
| | | |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | @PostMapping("/{workspace_id}/waylines/file/upload") |
| | | public ResponseResult importKmzFile(HttpServletRequest request, MultipartFile file) { |
| | | public ResponseResult importKmzFile(@PathVariable(name = "workspace_id") String workspaceId,HttpServletRequest request, MultipartFile file) { |
| | | if (Objects.isNull(file)) { |
| | | return ResponseResult.error("No file received."); |
| | | } |
| | | CustomClaim customClaim = (CustomClaim)request.getAttribute(TOKEN_CLAIM); |
| | | String workspaceId = customClaim.getWorkspaceId(); |
| | | String creator = customClaim.getUsername(); |
| | | waylineFileService.importKmzFile(file, workspaceId, creator); |
| | | return ResponseResult.success(); |
| | |
| | | private IWaylineJobService waylineJobService; |
| | | |
| | | /** |
| | | * Create a wayline task for the Dock. |
| | | * 创建航路任务。 |
| | | * @param request |
| | | * @param param |
| | | * @param workspaceId |
| | |
| | | } |
| | | |
| | | /** |
| | | * Paginate through all jobs in this workspace. |
| | | * 分页查询 |
| | | * @param page |
| | | * @param pageSize |
| | | * @param workspaceId |
| | |
| | | } |
| | | |
| | | /** |
| | | * Send the command to cancel the jobs. |
| | | * 发送命令取消作业。 |
| | | * @param jobIds |
| | | * @param workspaceId |
| | | * @return |
| | |
| | | } |
| | | |
| | | /** |
| | | * Set the media files for this job to upload immediately. |
| | | * 将此作业的媒体文件设置为立即上传。 |
| | | * @param workspaceId |
| | | * @param jobId |
| | | * @return |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | path: |
| | | # Topics that need to be subscribed when initially connecting to mqtt, multiple topics are divided by ",". |
| | | # inbound-topic: sys/product/+/status,thing/product/+/requests |
| | | inbound-topic: sys/product/+/status,thing/product/+/requests |
| | | inbound-topic: sys/product/+/+,thing/product/+/+ |
| | | DRC: |
| | | protocol: WS # @see com.dji.sample.component.mqtt.model.MqttProtocolEnum |
| | | host: 182.106.212.58 |
| | |
| | | |
| | | ntp: |
| | | server: |
| | | host: Google.mzr.me |
| | | host: ntp.ntsc.ac.cn |
| | | |
| | | # To create a license for an application: https://developer.dji.com/user/apps/#all |
| | | cloud-api: |