|
|
@ -167,6 +167,9 @@ func (the *ConfigHelper) GetDeviceStationIds(deviceId string) ([]int, error) { |
|
|
|
k := fmt.Sprintf("%s:%s", redisKey.Device_stationIds, deviceId) |
|
|
|
//var deviceMeta common_models.DeviceMeta
|
|
|
|
s := the.redisHelper.Get(k) |
|
|
|
if s == "" { |
|
|
|
return result, errors.New(fmt.Sprintf("redis 中无key=[%s] 缓存", k)) |
|
|
|
} |
|
|
|
err = json.Unmarshal([]byte(s), &result) |
|
|
|
//err = the.redisHelper.GetObj(k, &result)
|
|
|
|
} |
|
|
@ -174,16 +177,21 @@ func (the *ConfigHelper) GetDeviceStationIds(deviceId string) ([]int, error) { |
|
|
|
} |
|
|
|
func (the *ConfigHelper) SetChainedCacheObj(k string, obj any) error { |
|
|
|
var value string |
|
|
|
if v, ok := obj.(string); !ok { |
|
|
|
v, err := json.Marshal(obj) |
|
|
|
var err error |
|
|
|
switch obj.(type) { |
|
|
|
case string: |
|
|
|
value = obj.(string) |
|
|
|
case []byte: |
|
|
|
value = string(obj.([]byte)) |
|
|
|
default: |
|
|
|
bs, err := json.Marshal(obj) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
value = string(v) |
|
|
|
} else { |
|
|
|
value = v |
|
|
|
value = string(bs) |
|
|
|
} |
|
|
|
err := the.chainedCache.LoadableChinCache.Set(the.ctx, k, value) |
|
|
|
|
|
|
|
err = the.chainedCache.LoadableChinCache.Set(the.ctx, k, value) |
|
|
|
return err |
|
|
|
} |
|
|
|
func (the *ConfigHelper) SetChainedCacheObjWithExpiration(k string, obj any, duration time.Duration) error { |
|
|
@ -200,6 +208,10 @@ func (the *ConfigHelper) SetChainedCacheObjWithExpiration(k string, obj any, dur |
|
|
|
err := the.chainedCache.LoadableChinCache.Set(the.ctx, k, value, store.WithExpiration(duration)) |
|
|
|
return err |
|
|
|
} |
|
|
|
func (the *ConfigHelper) DeleteChainedCacheObj(k string) error { |
|
|
|
err := the.chainedCache.LoadableChinCache.Delete(the.ctx, k) |
|
|
|
return err |
|
|
|
} |
|
|
|
func (the *ConfigHelper) GetCacheWindowObj(key_cacheWindow string) (common_models.CacheWindow, error) { |
|
|
|
var redisCacheWin common_models.CacheWinSave |
|
|
|
value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, key_cacheWindow) |
|
|
@ -250,7 +262,11 @@ func (the *ConfigHelper) SetDeviceStationObjs(deviceId string, stations common_m |
|
|
|
var err error |
|
|
|
k := fmt.Sprintf("%s:%s", redisKey.Device_stationObjs, deviceId) |
|
|
|
|
|
|
|
err = the.SetChainedCacheObj(k, &stations) |
|
|
|
bytes, err := json.Marshal(stations) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
go the.SetChainedCacheObj(k, bytes) |
|
|
|
|
|
|
|
return err |
|
|
|
} |
|
|
@ -386,6 +402,9 @@ func (the *ConfigHelper) GetStationGroup(groupId int) (common_models.StationGrou |
|
|
|
k := fmt.Sprintf("%s:%d", redisKey.Group, groupId) |
|
|
|
value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k) |
|
|
|
if v, ok := value.(string); ok { |
|
|
|
if v == "" { |
|
|
|
return group, err |
|
|
|
} |
|
|
|
err = json.Unmarshal([]byte(v), &group) |
|
|
|
if err != nil { |
|
|
|
log.Printf("json unmarshal error:%s \n", err.Error()) |
|
|
@ -560,6 +579,22 @@ func (the *ConfigHelper) GetFilter(stationId int) (common_models.Filter, error) |
|
|
|
|
|
|
|
return result, err |
|
|
|
} |
|
|
|
func (the *ConfigHelper) GetFilterItem(stationId int, item string) (common_models.FilterItem, error) { |
|
|
|
|
|
|
|
result, err := the.GetFilter(stationId) |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
for _, filterItem := range result.Items { |
|
|
|
if filterItem.FieldName == item { |
|
|
|
return filterItem, err |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Printf("获取GetFilterItem err=%s", err.Error()) |
|
|
|
} |
|
|
|
|
|
|
|
return common_models.FilterItem{}, err |
|
|
|
} |
|
|
|
func (the *ConfigHelper) GetAlarmCode(alarmCode string) (common_models.AlarmCode, error) { |
|
|
|
var err error |
|
|
|
result, ok := AlarmCodeCache[alarmCode] |
|
|
@ -585,7 +620,7 @@ func (the *ConfigHelper) GetIotaScheme(dimensionId string) (common_models.IotaSc |
|
|
|
formattedStr := strings.Replace(v, "+0800", "+08:00", -1) |
|
|
|
err = json.Unmarshal([]byte(formattedStr), &scheme) |
|
|
|
if err != nil { |
|
|
|
log.Printf("json unmarshal error:%s \n", err.Error()) |
|
|
|
log.Printf("【GetIotaScheme】json unmarshal error:%s \n", err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
return scheme, err |
|
|
|