package common_models import ( "encoding/json" ) type IotaInstances struct { Instances map[string]IotaInstance `json:"instances"` } // redis序列化 func (m *IotaInstances) MarshalBinary() (data []byte, err error) { return json.Marshal(m) } // redis序列化 func (m *IotaInstances) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, m) } type IotaInstance struct { Instance DeployInstance `json:"instance"` Type string `json:"type"` //s.l or s.d or s.iota } type DeployInstance struct { DeviceMetaId string `json:"deviceMetaId"` Visibility string `json:"visibility"` Name string `json:"name"` From ToFrom To ToFrom } type ToFrom struct { ShapeType string `json:"shapeType"` OwnerShapeType string `json:"ownerShapeType"` OwnerSvgId string `json:"ownerSvgId"` } type DeviceTree struct { Node DeviceNode } type DeviceNode struct { Id string Name string Depth int pid string Child []DeviceNode } func (the *DeviceNode) SearchSub(deviceId string) (subList []string) { if the.Id == deviceId { for _, child := range the.Child { subList = append(subList, child.Id) } } else { for _, child := range the.Child { subList = child.SearchSub(deviceId) } } return subList } func (the *DeviceNode) SearchSubAll(deviceId string) (subList []string) { if the.Id == deviceId { for _, child := range the.Child { subList = append(subList, child.Id) subList = append(subList, child.SearchSub(child.Id)...) } } else { for _, child := range the.Child { subList = child.SearchSubAll(deviceId) } } return subList }