fix: 网元参数配置可用属性值数据表ne_config,缓存NeConfig
This commit is contained in:
@@ -60,7 +60,7 @@ func (s *NeConfigController) Info(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 将字符串转json数据
|
||||
if err := json.Unmarshal([]byte(data.ParamJSONStr), &data.ParamData); err != nil {
|
||||
if err := json.Unmarshal([]byte(data.ParamJson), &data.ParamData); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, err.Error()))
|
||||
return
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func (s *NeConfigController) Add(c *gin.Context) {
|
||||
c.JSON(400, result.CodeMsg(400, err.Error()))
|
||||
return
|
||||
}
|
||||
body.ParamJSONStr = string(paramDataByte)
|
||||
body.ParamJson = string(paramDataByte)
|
||||
|
||||
insertId := s.neConfigService.Insert(body)
|
||||
if insertId != "" {
|
||||
@@ -120,7 +120,7 @@ func (s *NeConfigController) Edit(c *gin.Context) {
|
||||
c.JSON(400, result.CodeMsg(400, err.Error()))
|
||||
return
|
||||
}
|
||||
body.ParamJSONStr = string(paramDataByte)
|
||||
body.ParamJson = string(paramDataByte)
|
||||
|
||||
rows := s.neConfigService.Update(body)
|
||||
if rows > 0 {
|
||||
@@ -176,9 +176,9 @@ func (s *NeConfigController) ListByNeType(c *gin.Context) {
|
||||
func (s *NeConfigController) Data(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"` // 网元类型
|
||||
NeId string `form:"neId" binding:"required"` // 网元ID
|
||||
TopTag string `form:"topTag" binding:"required"` // 可用属性
|
||||
NeType string `form:"neType" binding:"required"` // 网元类型
|
||||
NeId string `form:"neId" binding:"required"` // 网元ID
|
||||
ParamName string `form:"paramName" binding:"required"` // 可用属性
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
@@ -192,7 +192,7 @@ func (s *NeConfigController) Data(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 网元直连
|
||||
resData, err := neFetchlink.NeConfigInfo(neInfo, querys.TopTag)
|
||||
resData, err := neFetchlink.NeConfigInfo(neInfo, querys.ParamName)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
|
||||
@@ -50,9 +50,9 @@ func NeConfigOMC(neInfo model.NeInfo) (map[string]any, error) {
|
||||
}
|
||||
|
||||
// NeConfigInfo 网元配置信息
|
||||
func NeConfigInfo(neInfo model.NeInfo, name string) (map[string]any, error) {
|
||||
func NeConfigInfo(neInfo model.NeInfo, paramName string) (map[string]any, error) {
|
||||
// 网元配置对端网管信息
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), name)
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName)
|
||||
resBytes, err := fetch.Get(neUrl, nil, 1000)
|
||||
if err != nil {
|
||||
logger.Warnf("NeConfigInfo %s Get \"%s\"", err.Error(), neUrl)
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package model
|
||||
|
||||
// NeConfig 网元参数配置可用属性值
|
||||
// NeConfig 网元_参数配置可用属性值
|
||||
type NeConfig struct {
|
||||
ID string `json:"id" gorm:"id"`
|
||||
NeType string `json:"neType" binding:"required" gorm:"ne_type"` // 网元类型
|
||||
NeId string `json:"-" gorm:"ne_id"`
|
||||
TopTag string `json:"topTag" binding:"required" gorm:"top_tag"`
|
||||
TopDisplay string `json:"topDisplay" binding:"required" gorm:"top_display"`
|
||||
Method string `json:"method" gorm:"method"` // 操作属性 get只读强制不可编辑删除 put可编辑 delete可删除 post可新增
|
||||
ParamJSONStr string `json:"-" gorm:"param_json"` // accesss属性控制:只读read-only/read/ro 读写read-write
|
||||
|
||||
ID string `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
|
||||
NeType string `json:"neType" binding:"required" gorm:"ne_type"` // 网元类型
|
||||
ParamName string `json:"paramName" binding:"required" gorm:"param_name"` // 参数名
|
||||
ParamDisplay string `json:"paramDisplay" binding:"required" gorm:"param_display"` // 参数显示名
|
||||
ParamType string `json:"paramType" gorm:"param_type"` // 参数类型 list列表单层 array数组多层
|
||||
ParamJson string `json:"-" gorm:"param_json"` // accesss属性控制:只读read-only/read/ro 读写read-write
|
||||
ParamSort int64 `json:"paramSort" gorm:"param_sort"` // 参数排序
|
||||
ParamPerms string `json:"paramPerms" gorm:"param_perms"` // 操作权限 get只读 put可编辑 delete可删除 post可新增
|
||||
UpdateTime int64 `json:"updateTime" gorm:"update_time"` // 更新时间
|
||||
// ====== 非数据库字段属性 ======
|
||||
|
||||
ParamData map[string]any `json:"paramData,omitempty" binding:"required" gorm:"-"` // 与ParamJSONStr配合转换
|
||||
ParamData []map[string]any `json:"paramData,omitempty" binding:"required" gorm:"-"` // 与ParamJSONStr配合转换
|
||||
}
|
||||
|
||||
// TableName 表名称
|
||||
func (*NeConfig) TableName() string {
|
||||
return "param_config"
|
||||
return "ne_config"
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
@@ -12,18 +13,18 @@ import (
|
||||
|
||||
// NewNeConfigImpl 网元参数配置可用属性值 实例化数据层
|
||||
var NewNeConfigImpl = &NeConfigImpl{
|
||||
selectSql: `select
|
||||
id, ne_type, ne_id, top_tag, top_display, method, param_json
|
||||
from param_config`,
|
||||
selectSql: `select id, ne_type, param_name, param_display, param_type, param_json, param_sort, param_perms, update_time from ne_config`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"ne_type": "NeType",
|
||||
"ne_id": "NeId",
|
||||
"top_tag": "TopTag",
|
||||
"top_display": "TopDisplay",
|
||||
"method": "Method",
|
||||
"param_json": "ParamJSONStr",
|
||||
"id": "ID",
|
||||
"ne_type": "NeType",
|
||||
"param_name": "ParamName",
|
||||
"param_display": "ParamDisplay",
|
||||
"param_type": "ParamType",
|
||||
"param_json": "ParamJson",
|
||||
"param_sort": "ParamSort",
|
||||
"param_perms": "ParamPerms",
|
||||
"update_time": "UpdateTime",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -59,8 +60,8 @@ func (r *NeConfigImpl) SelectPage(query map[string]any) map[string]any {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
if v, ok := query["topTag"]; ok && v != "" {
|
||||
conditions = append(conditions, "top_tag = ?")
|
||||
if v, ok := query["paramName"]; ok && v != "" {
|
||||
conditions = append(conditions, "param_name = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
|
||||
@@ -76,7 +77,7 @@ func (r *NeConfigImpl) SelectPage(query map[string]any) map[string]any {
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(id) as 'total' from param_config"
|
||||
totalSql := "select count(id) as 'total' from ne_config"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
@@ -117,9 +118,9 @@ func (r *NeConfigImpl) SelectList(param model.NeConfig) []model.NeConfig {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, param.NeType)
|
||||
}
|
||||
if param.TopTag != "" {
|
||||
conditions = append(conditions, "top_tag = ?")
|
||||
params = append(params, param.TopTag)
|
||||
if param.ParamName != "" {
|
||||
conditions = append(conditions, "param_name = ?")
|
||||
params = append(params, param.ParamName)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
@@ -129,7 +130,7 @@ func (r *NeConfigImpl) SelectList(param model.NeConfig) []model.NeConfig {
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by id asc "
|
||||
querySql := r.selectSql + whereSql + " order by param_sort asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
@@ -160,25 +161,27 @@ func (r *NeConfigImpl) Insert(param model.NeConfig) string {
|
||||
if param.NeType != "" {
|
||||
params["ne_type"] = param.NeType
|
||||
}
|
||||
if param.NeId != "" {
|
||||
params["ne_id"] = param.NeId
|
||||
if param.ParamName != "" {
|
||||
params["param_name"] = param.ParamName
|
||||
}
|
||||
if param.TopTag != "" {
|
||||
params["top_tag"] = param.TopTag
|
||||
if param.ParamDisplay != "" {
|
||||
params["param_display"] = param.ParamDisplay
|
||||
}
|
||||
if param.TopDisplay != "" {
|
||||
params["top_display"] = param.TopDisplay
|
||||
if param.ParamType != "" {
|
||||
params["param_type"] = param.ParamType
|
||||
}
|
||||
if param.Method != "" {
|
||||
params["method"] = param.Method
|
||||
if param.ParamJson != "" {
|
||||
params["param_json"] = param.ParamJson
|
||||
}
|
||||
if param.ParamJSONStr != "" {
|
||||
params["param_json"] = param.ParamJSONStr
|
||||
params["param_sort"] = param.ParamSort
|
||||
if param.ParamPerms != "" {
|
||||
params["param_perms"] = param.ParamPerms
|
||||
}
|
||||
params["update_time"] = time.Now().UnixMilli()
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into param_config (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
sql := "insert into ne_config (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
@@ -210,25 +213,27 @@ func (r *NeConfigImpl) Update(param model.NeConfig) int64 {
|
||||
if param.NeType != "" {
|
||||
params["ne_type"] = param.NeType
|
||||
}
|
||||
if param.NeId != "" {
|
||||
params["ne_id"] = param.NeId
|
||||
if param.ParamName != "" {
|
||||
params["param_name"] = param.ParamName
|
||||
}
|
||||
if param.TopTag != "" {
|
||||
params["top_tag"] = param.TopTag
|
||||
if param.ParamDisplay != "" {
|
||||
params["param_display"] = param.ParamDisplay
|
||||
}
|
||||
if param.TopDisplay != "" {
|
||||
params["top_display"] = param.TopDisplay
|
||||
if param.ParamType != "" {
|
||||
params["param_type"] = param.ParamType
|
||||
}
|
||||
if param.Method != "" {
|
||||
params["method"] = param.Method
|
||||
if param.ParamJson != "" {
|
||||
params["param_json"] = param.ParamJson
|
||||
}
|
||||
if param.ParamJSONStr != "" {
|
||||
params["param_json"] = param.ParamJSONStr
|
||||
params["param_sort"] = param.ParamSort
|
||||
if param.ParamPerms != "" {
|
||||
params["param_perms"] = param.ParamPerms
|
||||
}
|
||||
params["update_time"] = time.Now().UnixMilli()
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
sql := "update param_config set " + strings.Join(keys, ",") + " where id = ?"
|
||||
sql := "update ne_config set " + strings.Join(keys, ",") + " where id = ?"
|
||||
|
||||
// 执行更新
|
||||
values = append(values, param.ID)
|
||||
@@ -243,7 +248,7 @@ func (r *NeConfigImpl) Update(param model.NeConfig) int64 {
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeConfigImpl) DeleteByIds(ids []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(ids))
|
||||
sql := "delete from param_config where id in (" + placeholder + ")"
|
||||
sql := "delete from ne_config where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(ids)
|
||||
results, err := datasource.ExecDB("", sql, parameters)
|
||||
if err != nil {
|
||||
|
||||
@@ -37,11 +37,11 @@ func (r *NeConfigImpl) RefreshByNeTypeAndNeID(neType string) []model.NeConfig {
|
||||
}
|
||||
}
|
||||
for k, v := range neConfigGroup {
|
||||
key := fmt.Sprintf("%sparam_config:%s", cachekey.NE_DATA_KEY, strings.ToUpper(k))
|
||||
key := fmt.Sprintf("%sNeConfig:%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 {
|
||||
if err := json.Unmarshal([]byte(item.ParamJson), &item.ParamData); err != nil {
|
||||
continue
|
||||
}
|
||||
v[i] = item
|
||||
@@ -54,14 +54,14 @@ func (r *NeConfigImpl) RefreshByNeTypeAndNeID(neType string) []model.NeConfig {
|
||||
return neConfigList
|
||||
}
|
||||
// 单个
|
||||
key := fmt.Sprintf("%sparam_config:%s", cachekey.NE_DATA_KEY, strings.ToUpper(neType))
|
||||
key := fmt.Sprintf("%sNeConfig:%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 {
|
||||
if err := json.Unmarshal([]byte(v.ParamJson), &v.ParamData); err != nil {
|
||||
continue
|
||||
}
|
||||
neConfigList[i] = v
|
||||
@@ -74,9 +74,9 @@ func (r *NeConfigImpl) RefreshByNeTypeAndNeID(neType string) []model.NeConfig {
|
||||
|
||||
// ClearNeCacheByNeType 清除网元类型参数配置缓存
|
||||
func (r *NeConfigImpl) ClearNeCacheByNeType(neType string) bool {
|
||||
key := fmt.Sprintf("%sparam_config:%s", cachekey.NE_DATA_KEY, neType)
|
||||
key := fmt.Sprintf("%sNeConfig:%s", cachekey.NE_DATA_KEY, neType)
|
||||
if neType == "*" {
|
||||
key = fmt.Sprintf("%sparam_config:*", cachekey.NE_DATA_KEY)
|
||||
key = fmt.Sprintf("%sNeConfig:*", cachekey.NE_DATA_KEY)
|
||||
}
|
||||
keys, err := redis.GetKeys("", key)
|
||||
if err != nil {
|
||||
@@ -89,7 +89,7 @@ func (r *NeConfigImpl) ClearNeCacheByNeType(neType string) bool {
|
||||
// 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))
|
||||
key := fmt.Sprintf("%sNeConfig:%s", cachekey.NE_DATA_KEY, strings.ToUpper(neType))
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
err := json.Unmarshal([]byte(jsonStr), &neConfigList)
|
||||
|
||||
Reference in New Issue
Block a user