feat: 网元参数配置可用属性数据用缓存
This commit is contained in:
@@ -156,6 +156,20 @@ func (s *NeConfigController) Remove(c *gin.Context) {
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
}
|
||||
|
||||
// 网元参数配置可用属性值列表指定网元类型全部无分页
|
||||
//
|
||||
// GET /list/:neType
|
||||
func (s *NeConfigController) ListByNeType(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neType := c.Param("neType")
|
||||
if neType == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
data := s.neConfigService.SelectNeConfigByNeType(neType)
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// 网元参数配置数据信息
|
||||
//
|
||||
// GET /data
|
||||
@@ -283,6 +283,10 @@ func Setup(router *gin.Engine) {
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfig", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeConfig.Remove,
|
||||
)
|
||||
neConfigGroup.GET("/list/:neType",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeConfig.ListByNeType,
|
||||
)
|
||||
neConfigGroup.GET("/data",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeConfig.Data,
|
||||
@@ -299,4 +303,7 @@ func InitLoad() {
|
||||
if para5GMap, err := service.NewNeInfoImpl.NeConfPara5GRead(); para5GMap != nil && err == nil {
|
||||
service.NewNeInfoImpl.NeConfPara5GWirte(para5GMap, nil)
|
||||
}
|
||||
// 启动时,清除缓存-网元参数配置可用属性值
|
||||
service.NewNeConfigImpl.ClearNeCacheByNeType("*")
|
||||
service.NewNeConfigImpl.RefreshByNeTypeAndNeID("*")
|
||||
}
|
||||
|
||||
@@ -4,7 +4,16 @@ import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeConfig 网元参数配置可用属性值 服务层接口
|
||||
type INeConfig interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
// RefreshByNeType 通过ne_type刷新redis中的缓存
|
||||
RefreshByNeTypeAndNeID(neType string) []model.NeConfig
|
||||
|
||||
// ClearNeCacheByNeType 清除网元类型参数配置缓存
|
||||
ClearNeCacheByNeType(neType string) bool
|
||||
|
||||
// SelectNeConfigByNeType 查询网元类型参数配置
|
||||
SelectNeConfigByNeType(neType string) []model.NeConfig
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/constants/cachekey"
|
||||
"be.ems/src/framework/redis"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
@@ -18,6 +22,86 @@ type NeConfigImpl struct {
|
||||
neConfigRepository repository.INeConfig
|
||||
}
|
||||
|
||||
// RefreshByNeType 通过ne_type刷新redis中的缓存
|
||||
func (r *NeConfigImpl) RefreshByNeTypeAndNeID(neType string) []model.NeConfig {
|
||||
// 多个
|
||||
if neType == "" || neType == "*" {
|
||||
neConfigList := r.neConfigRepository.SelectList(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("%sparam_config:%s", cachekey.NE_DATA_KEY, strings.ToUpper(k))
|
||||
redis.Del("", key)
|
||||
if len(v) > 0 {
|
||||
for i, item := range v {
|
||||
if err := json.Unmarshal([]byte(item.ParamJSONStr), &item.ParamData); err != nil {
|
||||
continue
|
||||
}
|
||||
v[i] = item
|
||||
}
|
||||
values, _ := json.Marshal(v)
|
||||
redis.Set("", key, string(values))
|
||||
}
|
||||
}
|
||||
}
|
||||
return neConfigList
|
||||
}
|
||||
// 单个
|
||||
key := fmt.Sprintf("%sparam_config:%s", cachekey.NE_DATA_KEY, strings.ToUpper(neType))
|
||||
redis.Del("", key)
|
||||
neConfigList := r.neConfigRepository.SelectList(model.NeConfig{
|
||||
NeType: neType,
|
||||
})
|
||||
if len(neConfigList) > 0 {
|
||||
for i, v := range neConfigList {
|
||||
if err := json.Unmarshal([]byte(v.ParamJSONStr), &v.ParamData); err != nil {
|
||||
continue
|
||||
}
|
||||
neConfigList[i] = v
|
||||
}
|
||||
values, _ := json.Marshal(neConfigList)
|
||||
redis.Set("", key, string(values))
|
||||
}
|
||||
return neConfigList
|
||||
}
|
||||
|
||||
// ClearNeCacheByNeType 清除网元类型参数配置缓存
|
||||
func (r *NeConfigImpl) ClearNeCacheByNeType(neType string) bool {
|
||||
key := fmt.Sprintf("%sparam_config:%s", cachekey.NE_DATA_KEY, neType)
|
||||
if neType == "*" {
|
||||
key = fmt.Sprintf("%sparam_config:*", cachekey.NE_DATA_KEY)
|
||||
}
|
||||
keys, err := redis.GetKeys("", key)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
delOk, _ := redis.DelKeys("", keys)
|
||||
return delOk
|
||||
}
|
||||
|
||||
// SelectNeConfigByNeType 查询网元类型参数配置
|
||||
func (r *NeConfigImpl) SelectNeConfigByNeType(neType string) []model.NeConfig {
|
||||
var neConfigList []model.NeConfig
|
||||
key := fmt.Sprintf("%sparam_config:%s", cachekey.NE_DATA_KEY, strings.ToUpper(neType))
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
err := json.Unmarshal([]byte(jsonStr), &neConfigList)
|
||||
if err != nil {
|
||||
neConfigList = []model.NeConfig{}
|
||||
}
|
||||
} else {
|
||||
neConfigList = r.RefreshByNeTypeAndNeID(neType)
|
||||
}
|
||||
return neConfigList
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeConfigImpl) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neConfigRepository.SelectPage(query)
|
||||
|
||||
Reference in New Issue
Block a user