guoshilong
2023-09-26 3ba2ea4de914835bc316826f2c7f93a648760e9c
Merge remote-tracking branch 'origin/main'
10 files modified
105 ■■■■ changed files
src/main/java/com/dji/sample/component/mqtt/model/CommonTopicReceiver.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/component/mqtt/model/CommonTopicResponse.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/component/mqtt/service/IMessageSenderService.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/component/mqtt/service/impl/MessageSenderServiceImpl.java 37 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/control/service/IControlService.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/control/service/impl/ControlServiceImpl.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/controller/WaylineFileController.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/controller/WaylineJobController.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/service/impl/WaylineJobServiceImpl.java 30 ●●●● patch | view | raw | blame | history
src/main/resources/application.yml 4 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/component/mqtt/model/CommonTopicReceiver.java
@@ -4,7 +4,7 @@
import lombok.Data;
/**
 * Unified topic receiving format.
 * 统一主题接收格式。
 * @author sean.zhou
 * @date 2021/11/10
 * @version 0.1
src/main/java/com/dji/sample/component/mqtt/model/CommonTopicResponse.java
@@ -7,7 +7,7 @@
import lombok.NoArgsConstructor;
/**
 * Unified Topic response format
 * 统一主题响应格式
 * @author sean.zhou
 * @date 2021/11/15
 * @version 0.1
@@ -28,6 +28,7 @@
    private String bid;
    private String method;
    private String gateway;
    private T data;
src/main/java/com/dji/sample/component/mqtt/service/IMessageSenderService.java
@@ -88,4 +88,11 @@
     * @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);
}
src/main/java/com/dji/sample/component/mqtt/service/impl/MessageSenderServiceImpl.java
@@ -71,7 +71,7 @@
            response.setBid(UUID.randomUUID().toString());
            response.setTid(UUID.randomUUID().toString());
        }
        throw new RuntimeException("No message reply received.");
        throw new RuntimeException("没有收到消息回复。");
    }
    @Override
@@ -113,4 +113,39 @@
        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);
    }
}
src/main/java/com/dji/sample/control/service/IControlService.java
@@ -76,4 +76,7 @@
     * @return
     */
    ResponseResult payloadCommands(PayloadCommandsParam param) throws Exception;
    ResponseResult requestsConfig(String sn,String method, RequestsParam param);
}
src/main/java/com/dji/sample/control/service/impl/ControlServiceImpl.java
@@ -298,4 +298,12 @@
                : 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();
    }
}
src/main/java/com/dji/sample/wayline/controller/WaylineFileController.java
@@ -181,12 +181,11 @@
     * @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();
src/main/java/com/dji/sample/wayline/controller/WaylineJobController.java
@@ -31,7 +31,7 @@
    private IWaylineJobService waylineJobService;
    /**
     * Create a wayline task for the Dock.
     * 创建航路任务。
     * @param request
     * @param param
     * @param workspaceId
@@ -48,7 +48,7 @@
    }
    /**
     * Paginate through all jobs in this workspace.
     * 分页查询
     * @param page
     * @param pageSize
     * @param workspaceId
@@ -63,7 +63,7 @@
    }
    /**
     * Send the command to cancel the jobs.
     * 发送命令取消作业。
     * @param jobIds
     * @param workspaceId
     * @return
@@ -77,7 +77,7 @@
    }
    /**
     * Set the media files for this job to upload immediately.
     * 将此作业的媒体文件设置为立即上传。
     * @param workspaceId
     * @param jobId
     * @return
src/main/java/com/dji/sample/wayline/service/impl/WaylineJobServiceImpl.java
@@ -142,24 +142,26 @@
    }
    /**
     * 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()) {
@@ -173,16 +175,16 @@
                }
                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();
@@ -232,13 +234,13 @@
        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
src/main/resources/application.yml
@@ -59,7 +59,7 @@
    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
@@ -135,7 +135,7 @@
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: