qixiaoning
2025-07-08 fe724b50b3f1b3dfe2219eb9af4bcca96c89a158
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
package service
 
import (
    "encoding/json"
    "vamicro/saas-service/service/nodeService"
 
    "basic.com/valib/go-aiot.git/aiotProto/aiot"
    "basic.com/valib/go-aiot.git/client"
    "basic.com/valib/logger.git"
)
 
// 同步集群数据
func syncClusterData(cli *client.Client) {
    data := nodeService.Node
 
    // 非集群信息,不在syncClusterData报,在syncDeviceSdkApp里报
    if data.ClusterId == "" {
        logger.Info("is not cluster, no report cluster info")
        return
    }
    msgData, err := json.Marshal(data)
    if err != nil {
        logger.Error("Fail to marshal cluster data to saas", err)
    }
 
    report := aiot.DataReport{
        DataKey: ClusterDataReport,
        Data:    msgData,
    }
    logger.Debugf("syncClusterData data=%v, dataKey=%v", string(msgData), report.DataKey)
    // 集群数据拼装
    reportData, _ := json.Marshal(report)
    syncData := &aiot.Protocol{
        Receiver: aiot.RECEIVER_TO_SAAS,
        SenderId: nodeService.Node.NodeId,
        MsgType:  aiot.MSG_TYPE_DATA_REPORT,
        ReqType:  aiot.REQ_TYPE_REQUEST,
        MsgProto: client.GetMsgProto(""),
        Data:     reportData,
    }
    // 上报集群数据
    _ = cli.WriteBody(syncData)
}