123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package Handle
- import (
- "Yunlot/logs"
- "Yunlot/models/Device"
- "Yunlot/models/Product"
- "fmt"
- "go.mongodb.org/mongo-driver/bson"
- "reflect"
- )
- func AnalysisMap(Device_r *Device.Device, ProductType_r Product.ProductType, ArticleSlide map[string]interface{}, JointTab string) {
- //JointTab += "."
- T_r := make(map[string]interface{})
- for key, value := range ArticleSlide {
- //fmt.Println(reflect.TypeOf(value).String())
- switch reflect.TypeOf(value).String() {
- case "map[string]interface {}":
- AnalysisMap(Device_r, ProductType_r, value.(map[string]interface{}), JointTab+key+".")
- break
- case "[]interface {}":
- for _, valuex := range value.([]interface{}) {
- if reflect.TypeOf(valuex).String() == "map[string]interface {}" {
- AnalysisMap(Device_r, ProductType_r, valuex.(map[string]interface{}), JointTab+key+".")
- }
- }
- break
- default:
- T_r[key] = value
- // 根 TAB
- if len(JointTab) == 0 {
- Device.Data_Add(Device_r.T_sn+"_"+key, &bson.M{key: value})
- }
- break
- }
- }
- if len(JointTab) == 0 {
- return
- }
- // 多级 TAB
- JointTab = JointTab[:len(JointTab)-1]
- fmt.Println(JointTab, "-------")
- bson_r := bson.M{}
- for key, value := range T_r {
- fmt.Println(key, "->:", value)
- bson_r[key] = value
- }
- // 消息转发
- //Relay(Device_r, ProductType_r, JointTab, ArticleSlide)
- // 数据存储
- Device.Data_Add(Device_r.T_sn+"_"+JointTab, &bson_r)
- }
- // 设备->平台
- func T(Device_r Device.Device, topic string, message []byte) {
- // 设备类型
- ProductType_r := Product.ProductType{T_ProductID: Device_r.T_ProductID}
- if !ProductType_r.Read() {
- logs.Println("MqttServer", Device_r.T_sn+"|"+Device_r.T_ProductID+" 设备类型找不到!")
- return
- }
- // 设备协议
- ProductProt_r := Product.ProductProt{Id: ProductType_r.T_prot}
- if !ProductProt_r.Read() {
- logs.Println("MqttServer", Device_r.T_sn+"|"+Device_r.T_ProductID+"-"+fmt.Sprintf("%d", ProductType_r.T_prot)+" 设备协议找不到!")
- return
- }
- //
- //// 根据库的存放路径加载库
- //p, err := plugin.Open(conf.Analysis_Dir + ProductProt_r.T_analysis)
- //if err != nil {
- // println(err)
- // panic(any(err))
- //}
- //
- //// 查找库导出信息
- //s, err := p.Lookup("T")
- //if err != nil {
- // println(err)
- // panic(any(err))
- //}
- //// 类型转换
- //f := s.(func(b []byte) []byte)(message)
- ////0:Mqtt 1:http 2:tcp 3:CoAP 4:websocket
- //switch ProductProt_r.T_mode {
- //case 0: //Mqtt
- // MqttServer.Mqtt_publish(topic, f) // 返回数据
- // break
- //case 1: //http
- //
- // break
- //case 2: //tcp
- //
- // break
- //case 3: //CoAP
- //
- // break
- //case 4: //websocket
- //
- // break
- //
- //}
- return
- }
|