jiazx0107@163.com
2023-11-10 d52795fc5de0b6ed748cd2ef217dcd1371e4b8e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.fzzy.gateway.hx2023.service;
 
import com.alibaba.fastjson2.JSONObject;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.api.GatewayRemoteManager;
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.data.BaseReqData;
import com.fzzy.mqtt.MqttGatewayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 * 根据接受到的MQTT信息执行
 */
@Slf4j
@Component
public class OnReceiveMqttService {
 
    @Resource
    private GatewayRemoteManager gatewayRemoteManager;
    @Resource
    private MqttGatewayService mqttGatewayService;
 
 
    /**
     * 当前接收到云端发送信息
     *
     * @param message
     */
    public void onReceiveMessage(String topic,String 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);
        }
 
    }
 
    private void getTAndRHInfo(CloudSendData cloudSendData) {
 
        String deviceId = cloudSendData.getDeviceId();
 
        GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
 
        BaseReqData syncReqData = new BaseReqData();
        syncReqData.setDeviceId(deviceId);
        syncReqData.setMessageId(cloudSendData.getMessageId());
        syncReqData.setMessageType(cloudSendData.getMessageType());
        syncReqData.setFunctionId(cloudSendData.getFunctionId());
        syncReqData.setAutoReplay(true);
        syncReqData.setDevice(device);
 
 
        //TODO --->>暂时返回测试数据
 
        //BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain(syncReqData);
 
        BaseResp resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrain(syncReqData);
 
        //自动推送
        if (200 == resp.getCode() && syncReqData.isAutoReplay()) {
            syncReqData.setData(resp.getData());
            gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainData(syncReqData);
        }
    }
}