|
@ -4,6 +4,7 @@ import ( |
|
|
"context" |
|
|
"context" |
|
|
"gitea.anxinyun.cn/container/common_models/constant/settlementParam" |
|
|
"gitea.anxinyun.cn/container/common_models/constant/settlementParam" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
//"encoding/json"
|
|
|
//"encoding/json"
|
|
|
"errors" |
|
|
"errors" |
|
@ -37,12 +38,11 @@ type ConfigHelper struct { |
|
|
redisHelper *RedisHelper //普通缓存用
|
|
|
redisHelper *RedisHelper //普通缓存用
|
|
|
chainedCache *ChainedCache |
|
|
chainedCache *ChainedCache |
|
|
ctx context.Context |
|
|
ctx context.Context |
|
|
|
|
|
mu sync.RWMutex |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewConfigHelper(redisAddr string) *ConfigHelper { |
|
|
func NewConfigHelper(redisAddr string) *ConfigHelper { |
|
|
|
|
|
|
|
|
initDeviceInfoMapCache() |
|
|
initDeviceInfoMapCache() |
|
|
|
|
|
|
|
|
return &ConfigHelper{ |
|
|
return &ConfigHelper{ |
|
|
redisHelper: NewRedisHelper("", redisAddr), |
|
|
redisHelper: NewRedisHelper("", redisAddr), |
|
|
chainedCache: NewChainedCache(redisAddr), |
|
|
chainedCache: NewChainedCache(redisAddr), |
|
@ -94,8 +94,10 @@ func initDeviceInfoMapCache() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// GetDeviceInfo 通过
|
|
|
|
|
|
func (the *ConfigHelper) GetDeviceInfo(deviceId string) (*common_models.DeviceInfo, error) { |
|
|
func (the *ConfigHelper) GetDeviceInfo(deviceId string) (*common_models.DeviceInfo, error) { |
|
|
|
|
|
the.mu.Lock() |
|
|
|
|
|
defer the.mu.Unlock() |
|
|
|
|
|
|
|
|
deviceInfo, ok := DeviceInfoCache[deviceId] |
|
|
deviceInfo, ok := DeviceInfoCache[deviceId] |
|
|
if !ok { //去redis查询
|
|
|
if !ok { //去redis查询
|
|
|
device, err := the.GetIotaDevice(deviceId) |
|
|
device, err := the.GetIotaDevice(deviceId) |
|
@ -130,8 +132,8 @@ func (the *ConfigHelper) GetDeviceInfo(deviceId string) (*common_models.DeviceIn |
|
|
DeviceInfoCache[deviceId] = deviceInfo |
|
|
DeviceInfoCache[deviceId] = deviceInfo |
|
|
} |
|
|
} |
|
|
return &deviceInfo, nil |
|
|
return &deviceInfo, nil |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (the *ConfigHelper) GetFormulaInfo(formulaId int) (common_models.Formula, error) { |
|
|
func (the *ConfigHelper) GetFormulaInfo(formulaId int) (common_models.Formula, error) { |
|
|
var err error |
|
|
var err error |
|
|
result, ok := FormulaCache[formulaId] |
|
|
result, ok := FormulaCache[formulaId] |
|
@ -407,7 +409,7 @@ func (the *ConfigHelper) GetStationGroup(groupId int) (common_models.StationGrou |
|
|
} |
|
|
} |
|
|
err = json.Unmarshal([]byte(v), &group) |
|
|
err = json.Unmarshal([]byte(v), &group) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Printf("json unmarshal error:%s \n", err.Error()) |
|
|
log.Printf("【redisKey.Group】【%s】json unmarshal error:%s \n", k, err.Error()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -429,7 +431,7 @@ func (the *ConfigHelper) GetStationGroupInfo(stationId int) (common_models.Stati |
|
|
if v, ok := value.(string); ok { |
|
|
if v, ok := value.(string); ok { |
|
|
err = json.Unmarshal([]byte(v), &info) |
|
|
err = json.Unmarshal([]byte(v), &info) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Printf("json unmarshal error:%s \n", err.Error()) |
|
|
log.Printf("【redisKey.Station_group】【%s】json unmarshal error:%s \n", k, err.Error()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return info, err |
|
|
return info, err |
|
@ -448,7 +450,7 @@ func (the *ConfigHelper) GetStationCorrGroups(stationId int) ([]common_models.St |
|
|
if v, ok := value.(string); ok { |
|
|
if v, ok := value.(string); ok { |
|
|
err = json.Unmarshal([]byte(v), &groupIds) |
|
|
err = json.Unmarshal([]byte(v), &groupIds) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Printf("json unmarshal error:%s \n", err.Error()) |
|
|
log.Printf("【redisKey.Station_corr_group】【%s】json unmarshal error:%s \n", k, err.Error()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if err != nil { |
|
|
if err != nil { |
|
|