package adaptors import ( "encoding/json" "goInOut/consumers/AXYraw" "goInOut/dbOperate" "goInOut/models" "log" "time" ) // Adaptor_Savoir_LastTheme 知物云 kafka theme数据 转换 es设备数据 type Adaptor_Savoir_LastTheme struct { AXYraw.Info Redis *dbOperate.RedisHelper } func (the Adaptor_Savoir_LastTheme) Transform(topic, rawMsg string) *models.EsTheme { theme := models.SavoirTheme{} err := json.Unmarshal([]byte(rawMsg), &theme) if err != nil { log.Printf("反序列化 异常 dev数据=%s", rawMsg) return nil } return the.Theme2Es(theme) } func (the Adaptor_Savoir_LastTheme) Theme2Es(theme models.SavoirTheme) *models.EsTheme { if theme.DataEmpty || len(theme.Data) == 0 { bs, _ := json.Marshal(theme) log.Printf("测点[%s]数据为空 => %s", theme.Station.Name, bs) return nil } ////log.Printf("设备[%s] 数据时间 %s", iotaData.DeviceId, iotaData.TriggerTime) //deviceInfo := the.GetDeviceInfo(iotaData.DeviceId) // ////查不到信息的数据 //if deviceInfo.Name == "" { // log.Printf("设备[%s] 无deviceInfo信息 %s", iotaData.DeviceId, iotaData.TriggerTime) // return nil //} // Atime, err := time.Parse("2006-01-02T15:04:05.000+0800", theme.AcqTime) if err != nil { log.Printf("知物云 测点[%s] 数据时间 %s 解析错误", theme.Station.Name, theme.AcqTime) return nil } themeData := &models.EsTheme{ SensorName: theme.Station.Name, FactorName: theme.Station.Factor.Name, FactorProtoCode: theme.Station.Factor.ProtoCode, Data: theme.Data, FactorProtoName: theme.Station.Factor.ProtoName, Factor: theme.Station.Factor.Id, CollectTime: Atime, Sensor: theme.Station.Id, Structure: theme.Station.Structure.Id, IotaDevice: []string{}, CreateTime: time.Now(), } return themeData }