Browse Source

update 初始化map

dev
lucas 1 month ago
parent
commit
a74e9c784c
  1. 32
      configHelper.go

32
configHelper.go

@ -62,6 +62,28 @@ func initDeviceInfoMapCache() {
DeviceMetaCache = make(map[string]common_models.DeviceMeta) DeviceMetaCache = make(map[string]common_models.DeviceMeta)
} }
if deviceStationIdsCache == nil {
deviceStationIdsCache = make(map[string][]int)
}
if stationCache == nil {
stationCache = make(map[int]common_models.Station)
}
if deviceFactorProtoMap == nil {
deviceFactorProtoMap = make(map[string]common_models.DeviceFactorProto)
}
if FormulaCache == nil {
FormulaCache = make(map[int]common_models.Formula)
}
if ProtoCache == nil {
ProtoCache = make(map[string]common_models.Proto)
}
if AlarmCodeCache == nil {
AlarmCodeCache = make(map[string]common_models.AlarmCode)
}
} }
// GetDeviceInfo 通过 // GetDeviceInfo 通过
@ -205,9 +227,13 @@ func (the *ConfigHelper) GetDeviceStationObjs(deviceId string) ([]common_models.
//err = the.redisHelper.GetObj(k, &result) //err = the.redisHelper.GetObj(k, &result)
value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k) value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k)
if v, ok := value.(string); ok { if v, ok := value.(string); ok {
if v == "" {
log.Printf("LoadableChinCache[%s]=空", k)
return result, err
}
err = json.Unmarshal([]byte(v), &result) err = json.Unmarshal([]byte(v), &result)
if err != nil { if err != nil {
log.Printf("json unmarshal error:%s \n", err.Error()) log.Printf("json unmarshal error:%s", err.Error())
} }
} }
return result, err return result, err
@ -474,14 +500,12 @@ func (the *ConfigHelper) GetFilter(stationId int) (common_models.Filter, error)
return result, err return result, err
} }
func (the *ConfigHelper) GetAlarmCode(alarmCode string) (common_models.AlarmCode, error) { func (the *ConfigHelper) GetAlarmCode(alarmCode string) (common_models.AlarmCode, error) {
//var iotaDevice common_models.IotaDevice
var err error var err error
result, ok := AlarmCodeCache[alarmCode] result, ok := AlarmCodeCache[alarmCode]
if !ok { //去redis查询 if !ok { //去redis查询
//thing_struct:5da9aa1b-05b7-4943-be57-dedb34f7a1bd
k := fmt.Sprintf("%s:%s", redisKey.Alarm_code, alarmCode) k := fmt.Sprintf("%s:%s", redisKey.Alarm_code, alarmCode)
err = the.redisHelper.GetObj(k, &result) err = the.redisHelper.GetObj(k, &result)
AlarmCodeCache[alarmCode] = result
} }
return result, err return result, err
} }

Loading…
Cancel
Save