Merge branch 'main-v2' into lite-ba
This commit is contained in:
@@ -21,59 +21,39 @@ type NeConfig struct {
|
||||
neConfigRepository *repository.NeConfig // 网元参数配置可用属性值表
|
||||
}
|
||||
|
||||
// RefreshByNeType 通过ne_type刷新redis中的缓存
|
||||
func (r *NeConfig) RefreshByNeTypeAndNeID(neType string) []model.NeConfig {
|
||||
// 多个
|
||||
if neType == "" || neType == "*" {
|
||||
neConfigList := r.neConfigRepository.Select(model.NeConfig{})
|
||||
if len(neConfigList) > 0 {
|
||||
neConfigGroup := map[string][]model.NeConfig{}
|
||||
for _, v := range neConfigList {
|
||||
if item, ok := neConfigGroup[v.NeType]; ok {
|
||||
neConfigGroup[v.NeType] = append(item, v)
|
||||
} else {
|
||||
neConfigGroup[v.NeType] = []model.NeConfig{v}
|
||||
}
|
||||
}
|
||||
for k, v := range neConfigGroup {
|
||||
key := fmt.Sprintf("%s:NeConfig:%s", constants.CACHE_NE_DATA, strings.ToUpper(k))
|
||||
redis.Del("", key)
|
||||
if len(v) > 0 {
|
||||
for i, item := range v {
|
||||
if err := json.Unmarshal([]byte(item.ParamJson), &item.ParamData); err != nil {
|
||||
continue
|
||||
}
|
||||
v[i] = item
|
||||
}
|
||||
values, _ := json.Marshal(v)
|
||||
redis.Set("", key, string(values), 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
return neConfigList
|
||||
// RefreshByNeType 通过ne_type刷新redis中的缓存 并返回分组数据
|
||||
func (r *NeConfig) RefreshByNeTypeAndNeID(neType string) map[string][]model.NeConfig {
|
||||
neConfig := model.NeConfig{}
|
||||
if neType != "*" {
|
||||
neConfig.NeType = neType
|
||||
}
|
||||
// 单个
|
||||
key := fmt.Sprintf("%s:NeConfig:%s", constants.CACHE_NE_DATA, strings.ToUpper(neType))
|
||||
redis.Del("", key)
|
||||
neConfigList := r.neConfigRepository.Select(model.NeConfig{
|
||||
NeType: neType,
|
||||
})
|
||||
if len(neConfigList) > 0 {
|
||||
for i, v := range neConfigList {
|
||||
if err := json.Unmarshal([]byte(v.ParamJson), &v.ParamData); err != nil {
|
||||
continue
|
||||
}
|
||||
neConfigList[i] = v
|
||||
neConfigList := r.neConfigRepository.Select(neConfig)
|
||||
neConfigGroup := map[string][]model.NeConfig{}
|
||||
for _, v := range neConfigList {
|
||||
if err := json.Unmarshal([]byte(v.ParamJson), &v.ParamData); err != nil {
|
||||
continue
|
||||
}
|
||||
neTypeVerKey := fmt.Sprintf("%s:%s", strings.ToUpper(v.NeType), v.NeVersion)
|
||||
if item, ok := neConfigGroup[neTypeVerKey]; ok {
|
||||
neConfigGroup[neTypeVerKey] = append(item, v)
|
||||
} else {
|
||||
neConfigGroup[neTypeVerKey] = []model.NeConfig{v}
|
||||
}
|
||||
values, _ := json.Marshal(neConfigList)
|
||||
redis.Set("", key, string(values), 0)
|
||||
}
|
||||
return neConfigList
|
||||
for k, v := range neConfigGroup {
|
||||
key := fmt.Sprintf("%s:NeConfig:%s", constants.CACHE_NE_DATA, k)
|
||||
redis.Del("", key)
|
||||
if len(v) > 0 {
|
||||
values, _ := json.Marshal(v)
|
||||
redis.Set("", key, string(values), 0)
|
||||
}
|
||||
}
|
||||
return neConfigGroup
|
||||
}
|
||||
|
||||
// ClearNeCacheByNeType 清除网元类型参数配置缓存
|
||||
func (r *NeConfig) ClearNeCacheByNeType(neType string) bool {
|
||||
key := fmt.Sprintf("%s:NeConfig:%s", constants.CACHE_NE_DATA, neType)
|
||||
key := fmt.Sprintf("%s:NeConfig:%s:*", constants.CACHE_NE_DATA, neType)
|
||||
if neType == "*" {
|
||||
key = fmt.Sprintf("%s:NeConfig:*", constants.CACHE_NE_DATA)
|
||||
}
|
||||
@@ -85,27 +65,41 @@ func (r *NeConfig) ClearNeCacheByNeType(neType string) bool {
|
||||
}
|
||||
|
||||
// FindByNeType 查询网元类型参数配置
|
||||
func (r *NeConfig) FindByNeType(neType string) []model.NeConfig {
|
||||
var neConfigList []model.NeConfig
|
||||
key := fmt.Sprintf("%s:NeConfig:%s", constants.CACHE_NE_DATA, strings.ToUpper(neType))
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
err := json.Unmarshal([]byte(jsonStr), &neConfigList)
|
||||
if err != nil {
|
||||
neConfigList = []model.NeConfig{}
|
||||
func (r *NeConfig) FindByNeType(neType, neVersion string) []model.NeConfig {
|
||||
data := make([]model.NeConfig, 0)
|
||||
keys, _ := redis.GetKeys("", fmt.Sprintf("%s:NeConfig:%s:*", constants.CACHE_NE_DATA, strings.ToUpper(neType)))
|
||||
if len(keys) > 0 {
|
||||
for _, key := range keys {
|
||||
neTypeVer := strings.Split(key, ":")
|
||||
if len(neTypeVer) != 4 {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(neVersion, neTypeVer[3]) {
|
||||
if jsonStr, _ := redis.Get("", key); len(jsonStr) > 7 {
|
||||
json.Unmarshal([]byte(jsonStr), &data)
|
||||
}
|
||||
return data
|
||||
}
|
||||
}
|
||||
} else {
|
||||
neConfigList = r.RefreshByNeTypeAndNeID(neType)
|
||||
}
|
||||
return neConfigList
|
||||
// 从数据库刷新缓存
|
||||
neConfigGroup := r.RefreshByNeTypeAndNeID(neType)
|
||||
for k, v := range neConfigGroup {
|
||||
neTypeVer := strings.Split(k, ":")
|
||||
if len(neTypeVer) == 2 && strings.HasPrefix(neVersion, neTypeVer[1]) {
|
||||
data = v
|
||||
break
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// FindByNeTypeAndParamName 查询网元类型参数配置By参数名
|
||||
func (r *NeConfig) FindByNeTypeAndParamName(neType, paramName string) model.NeConfig {
|
||||
neConfigList := r.FindByNeType(neType)
|
||||
func (r *NeConfig) FindByNeTypeAndParamName(neType, neVersion, paramName string) model.NeConfig {
|
||||
neConfigList := r.FindByNeType(neType, neVersion)
|
||||
var neConfig model.NeConfig
|
||||
for _, v := range neConfigList {
|
||||
if v.ParamName == paramName {
|
||||
if strings.HasPrefix(neVersion, v.NeVersion) && v.ParamName == paramName {
|
||||
neConfig = v
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user