|
|
@ -29,6 +29,11 @@ func (the Adaptor_AXY_LastRAW) raw2es(iotaData models.IotaData) *models.EsRaw { |
|
|
|
log.Printf("设备[%s] 数据时间 %s", iotaData.DeviceId, iotaData.TriggerTime) |
|
|
|
deviceInfo := the.GetDeviceInfo(iotaData.DeviceId) |
|
|
|
|
|
|
|
//查不到信息的数据
|
|
|
|
if deviceInfo.Name == "" { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
dataType := "" |
|
|
|
if _dataType, ok := iotaData.Data.Data["_data_type"]; ok { |
|
|
|
if v, ok := _dataType.(string); ok { |
|
|
@ -61,12 +66,15 @@ func (the Adaptor_AXY_LastRAW) GetDeviceInfo(deviceId string) models.DeviceInfo |
|
|
|
return v |
|
|
|
} |
|
|
|
} |
|
|
|
v := the.GetDeviceInfoFromRedis(deviceId) |
|
|
|
v, err := the.GetDeviceInfoFromRedis(deviceId) |
|
|
|
if err != nil { |
|
|
|
log.Printf("设备%s 无法查询到对应信息", deviceId) |
|
|
|
} |
|
|
|
deviceInfoMap[deviceId] = v |
|
|
|
return v |
|
|
|
} |
|
|
|
|
|
|
|
func (the Adaptor_AXY_LastRAW) GetDeviceInfoFromRedis(deviceId string) models.DeviceInfo { |
|
|
|
func (the Adaptor_AXY_LastRAW) GetDeviceInfoFromRedis(deviceId string) (models.DeviceInfo, error) { |
|
|
|
Key_Iota_device := "iota_device" |
|
|
|
key_Thing_struct := "thing_struct" |
|
|
|
key_Iota_meta := "iota_meta" |
|
|
@ -75,13 +83,23 @@ func (the Adaptor_AXY_LastRAW) GetDeviceInfoFromRedis(deviceId string) models.De |
|
|
|
thingStruct := models.ThingStruct{} |
|
|
|
devMeta := models.DeviceMeta{} |
|
|
|
err1 := the.Redis.GetObj(k1, &dev) |
|
|
|
if err1 != nil { |
|
|
|
return models.DeviceInfo{RefreshTime: time.Now()}, err1 |
|
|
|
} |
|
|
|
k2 := fmt.Sprintf("%s:%s", key_Thing_struct, dev.ThingId) |
|
|
|
err2 := the.Redis.GetObj(k2, &thingStruct) |
|
|
|
if err2 != nil { |
|
|
|
return models.DeviceInfo{RefreshTime: time.Now()}, err2 |
|
|
|
} |
|
|
|
k3 := fmt.Sprintf("%s:%s", key_Iota_meta, dev.DeviceMeta.Id) |
|
|
|
err3 := the.Redis.GetObj(k3, &devMeta) |
|
|
|
if err1 != nil || err2 != nil || err3 != nil { |
|
|
|
log.Printf("redis读取异常,err1=%s, err2=%s, err3=%s", err1, err2, err3) |
|
|
|
if err3 != nil { |
|
|
|
return models.DeviceInfo{RefreshTime: time.Now()}, err3 |
|
|
|
} |
|
|
|
//if err1 != nil || err2 != nil || err3 != nil {
|
|
|
|
// log.Printf("redis读取异常,err1=%s, err2=%s, err3=%s", err1, err2, err3)
|
|
|
|
// return models.DeviceInfo{}
|
|
|
|
//}
|
|
|
|
|
|
|
|
s := models.Structure{ |
|
|
|
ThingId: thingStruct.ThingId, |
|
|
@ -95,10 +113,15 @@ func (the Adaptor_AXY_LastRAW) GetDeviceInfoFromRedis(deviceId string) models.De |
|
|
|
Structure: s, |
|
|
|
DeviceMeta: devMeta, |
|
|
|
RefreshTime: time.Now(), |
|
|
|
} |
|
|
|
}, nil |
|
|
|
} |
|
|
|
|
|
|
|
func toEsRaw(deviceData *models.DeviceData) *models.EsRaw { |
|
|
|
|
|
|
|
if deviceData == nil { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
dataOutMeta := deviceData.DeviceInfo.DeviceMeta.GetOutputProps() |
|
|
|
createNativeRaw := models.EsRaw{ |
|
|
|
StructId: deviceData.StructId, |
|
|
|