xieb
2023-09-26 6ec922e73cc857085e2a5313983c936514d389fa
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);
    }
}