package Handle import ( "Yunlot/Handle/MqttServer" "Yunlot/conf" "Yunlot/logs" "Yunlot/models/Device" "Yunlot/models/Product" "fmt" "go.mongodb.org/mongo-driver/bson" "plugin" "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 if len(JointTab) == 0 { Device.Data_Add("202300000001_"+key, &bson.M{key: value}) } break } } if len(JointTab) == 0 { return } 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("202300000001_"+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 }