From ddefa6dc2532bf0a405d216a8fa8e2a4bb0bf96f Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期六, 18 十一月 2023 14:17:42 +0800
Subject: [PATCH] 增加HTTP地磅协议实现
---
src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java | 38 +++++++++++++++++++++-----------------
1 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java b/src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java
index d863ab5..4c706c0 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java
@@ -1,14 +1,14 @@
package com.fzzy.gateway.hx2023.service;
import com.alibaba.fastjson2.JSONObject;
+import com.fzzy.api.data.GatewayDeviceProtocol;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.api.GatewayRemoteManager;
+import com.fzzy.gateway.data.BaseReqData;
import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.hx2023.ScConstant;
import com.fzzy.gateway.hx2023.data.CloudSendData;
-import com.fzzy.gateway.hx2023.data.SyncReqData;
-import com.fzzy.mqtt.MqttProviderConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -23,8 +23,6 @@
@Resource
private GatewayRemoteManager gatewayRemoteManager;
- @Resource
- private MqttProviderConfig providerClient;
/**
@@ -32,21 +30,24 @@
*
* @param message
*/
- public void onReceiveMessage(String message) {
+ public void onReceiveMessage(String topic, String message) {
+
+ // 杩欓噷鍙互澶勭悊鎺ユ敹鐨勬暟鎹�
+ log.info("----------------------------鏀跺埌璁㈤槄鍐呭---------------------------");
+ log.info("-----TOPIC-----{}", topic);
+ log.info("-----Message-----{}", message);
try {
CloudSendData cloudSendData = JSONObject.parseObject(message, CloudSendData.class);
-
String functionId = cloudSendData.getFunctionId();
-
//绮儏閲囬泦
if (ScConstant.FUNCTION_getTAndRHInfo.equals(functionId)) {
getTAndRHInfo(cloudSendData);
}
} catch (Exception e) {
-
+ log.error("--------鎵ц寮傚父-----{}", e);
}
}
@@ -57,25 +58,28 @@
GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
- SyncReqData syncReqData = new SyncReqData();
+ BaseReqData syncReqData = new BaseReqData();
syncReqData.setDeviceId(deviceId);
+ syncReqData.setProductId(device.getProductId());
+ syncReqData.setDeviceName(device.getDeviceName());
syncReqData.setMessageId(cloudSendData.getMessageId());
syncReqData.setMessageType(cloudSendData.getMessageType());
syncReqData.setFunctionId(cloudSendData.getFunctionId());
syncReqData.setAutoReplay(true);
syncReqData.setDevice(device);
- BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain2(syncReqData);
+ BaseResp resp;
+ if (GatewayDeviceProtocol.DEVICE_TEST.getCode().equals(device.getSyncProtocol())) {
+ resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrain(syncReqData);
+ } else {
+ syncReqData.setAutoReplay(false);
+ resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain(syncReqData);
+ }
//鑷姩鎺ㄩ��
if (200 == resp.getCode() && syncReqData.isAutoReplay()) {
- String topic = "/${productId}/${deviceId}/properties/report";
-
- topic = topic.replace("${productId}", device.getProductId()).replace("${deviceId}", device.getDeviceId());
-
- providerClient.publish(topic, resp.getData());
-
- log.info("=======绮儏鎺ㄩ��==========={}", resp.getData());
+ syncReqData.setData(resp.getData());
+ gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainData(syncReqData);
}
}
}
--
Gitblit v1.9.3