jiazx0107@163.com
2023-11-10 d52795fc5de0b6ed748cd2ef217dcd1371e4b8e9
src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java
@@ -7,10 +7,8 @@
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.gateway.data.BaseReqData;
import com.fzzy.mqtt.MqttGatewayService;
import com.fzzy.mqtt.MqttProviderConfig;
import com.fzzy.mqtt.MqttPublishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -39,9 +37,7 @@
        try {
            CloudSendData cloudSendData = JSONObject.parseObject(message, CloudSendData.class);
            String functionId = cloudSendData.getFunctionId();
            //粮情采集
            if (ScConstant.FUNCTION_getTAndRHInfo.equals(functionId)) {
                getTAndRHInfo(cloudSendData);
@@ -59,7 +55,7 @@
        GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
        SyncReqData syncReqData = new SyncReqData();
        BaseReqData syncReqData = new BaseReqData();
        syncReqData.setDeviceId(deviceId);
        syncReqData.setMessageId(cloudSendData.getMessageId());
        syncReqData.setMessageType(cloudSendData.getMessageType());
@@ -67,19 +63,17 @@
        syncReqData.setAutoReplay(true);
        syncReqData.setDevice(device);
        BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain2(syncReqData);
        //TODO --->>暂时返回测试数据
        //BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain(syncReqData);
        BaseResp resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrain(syncReqData);
        //自动推送
        if (200 == resp.getCode() && syncReqData.isAutoReplay()) {
            String topic = ScConstant.TOPIC_REPORT;
            topic = topic.replace("${productId}", device.getProductId()).replace("${deviceId}", device.getDeviceId());
            mqttGatewayService.publishMqttWithTopic(resp.getData(), topic);
            log.info("----------------------------推送MQTT信息---------------------------");
            log.info("-----TOPIC-----{}",topic);
            log.info("-----Message-----{}",resp.getData());
            syncReqData.setData(resp.getData());
            gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainData(syncReqData);
        }
    }
}