feat: 网元参数配置数据支持版本区分功能,,适应mme版本配置

This commit is contained in:
TsMask
2025-10-17 11:06:27 +08:00
parent c325b89f6f
commit 7f7f4e2581
19 changed files with 924 additions and 351 deletions

View File

@@ -164,18 +164,28 @@ func (s NeConfigController) Remove(c *gin.Context) {
// @Accept json
// @Produce json
// @Param neType path string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Network Element Parameter Configuration Available Attribute Values List Specify Network Element Type All Unpaged
// @Description Network Element Parameter Configuration Available Attribute Values List Specify Network Element Type All Unpaged
// @Router /ne/config/list/{neType} [get]
func (s NeConfigController) ListByNeType(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
neId := c.DefaultQuery("neId", "001")
neType := c.Param("neType")
if neType == "" {
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: neType is empty"))
return
}
data := s.neConfigService.FindByNeType(neType)
neInfo := s.neInfoService.FindByNeTypeAndNeID(neType, neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
data := s.neConfigService.FindByNeType(neInfo.NeType, neInfo.NeVersion)
c.JSON(200, resp.OkData(data))
}
@@ -313,8 +323,14 @@ func (s NeConfigController) DataAdd(c *gin.Context) {
return
}
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeId)
if neInfo.NeId != body.NeId || neInfo.IP == "" {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 检查是否array
info := s.neConfigService.FindByNeTypeAndParamName(body.NeType, body.ParamName)
info := s.neConfigService.FindByNeTypeAndParamName(body.NeType, neInfo.NeVersion, body.ParamName)
if info.ParamType != "array" {
c.JSON(200, resp.ErrMsg("this attribute does not support adding"))
return
@@ -326,12 +342,6 @@ func (s NeConfigController) DataAdd(c *gin.Context) {
return
}
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeId)
if neInfo.NeId != body.NeId || neInfo.IP == "" {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元直连
resData, err := neFetchlink.NeConfigAdd(neInfo, body.ParamName, body.Loc, body.ParamData)
if err != nil {
@@ -371,19 +381,19 @@ func (s NeConfigController) DataRemove(c *gin.Context) {
return
}
// 检查是否array
info := s.neConfigService.FindByNeTypeAndParamName(query.NeType, query.ParamName)
if info.ParamType != "array" {
c.JSON(200, resp.ErrMsg("this attribute does not support adding"))
return
}
neInfo := s.neInfoService.FindByNeTypeAndNeID(query.NeType, query.NeId)
if neInfo.NeId != query.NeId || neInfo.IP == "" {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 检查是否array
info := s.neConfigService.FindByNeTypeAndParamName(query.NeType, neInfo.NeVersion, query.ParamName)
if info.ParamType != "array" {
c.JSON(200, resp.ErrMsg("this attribute does not support adding"))
return
}
// 网元直连
resData, err := neFetchlink.NeConfigDelete(neInfo, query.ParamName, query.Loc)
if err != nil {

View File

@@ -395,6 +395,7 @@ func (s NeInfoController) Add(c *gin.Context) {
// 已有网元可获取的信息
if body.ServerState != nil {
if v, ok := body.ServerState["version"]; ok && v != nil {
body.NeVersion = fmt.Sprint(v)
neVersion.Version = fmt.Sprint(v)
}
if v, ok := body.ServerState["sn"]; ok && v != nil {
@@ -497,6 +498,7 @@ func (s NeInfoController) Edit(c *gin.Context) {
// 已有网元可获取的信息
if body.ServerState != nil {
if v, ok := body.ServerState["version"]; ok && v != nil {
body.NeVersion = fmt.Sprint(v)
neVersion.Version = fmt.Sprint(v)
neVersion.UpdateBy = loginUserName
}

View File

@@ -3,7 +3,9 @@ package model
// NeConfig 网元_参数配置可用属性值
type NeConfig struct {
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
NeType string `json:"neType" binding:"required" gorm:"column:ne_type"` // 网元类型
NeVersion string `json:"neVersion" gorm:"column:ne_version"` // 网元版本 前缀匹配
ParamName string `json:"paramName" binding:"required" gorm:"column:param_name"` // 参数名
ParamDisplay string `json:"paramDisplay" binding:"required" gorm:"column:param_display"` // 参数显示名
ParamType string `json:"paramType" gorm:"column:param_type"` // 参数类型 list列表单层 array数组多层
@@ -11,7 +13,6 @@ type NeConfig struct {
ParamSort int64 `json:"paramSort" gorm:"column:param_sort"` // 参数排序
ParamPerms string `json:"paramPerms" gorm:"column:param_perms"` // 操作权限 get只读 put可编辑 delete可删除 post可新增
Visible string `json:"visible" gorm:"column:visible"` // 可见性 默认public 单独网元self
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
// ====== 非数据库字段属性 ======

View File

@@ -3,10 +3,17 @@ package model
// NeInfo 网元信息对象 ne_info
type NeInfo struct {
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
CreateBy string `json:"createBy" gorm:"column:create_by"` // 创建者
CreateTime int64 `json:"createTime" gorm:"column:create_time"` // 创建时间
UpdateBy string `json:"updateBy" gorm:"column:update_by"` // 更新者
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
Remark string `json:"remark" gorm:"column:remark"` // 备注
NeType string `json:"neType" gorm:"column:ne_type" binding:"required"` // 网元类型
NeId string `json:"neId" gorm:"column:ne_id" binding:"required"` // 网元ID
RmUID string `json:"rmUid" gorm:"column:rm_uid"` // 网元资源唯一标识
NeName string `json:"neName" gorm:"column:ne_name"` // 网元名称
NeVersion string `json:"neVersion" gorm:"column:ne_version"` // 网元版本
RmUID string `json:"rmUid" gorm:"column:rm_uid"` // 网元资源唯一标识
Schema string `json:"schema" gorm:"column:schema"` // 网元模式 http/https
IP string `json:"ip" gorm:"column:ip" binding:"required"` // 网元服务IP
Port int64 `json:"port" gorm:"column:port" binding:"required,number,max=65535,min=1"` // 端口
PvFlag string `json:"pvFlag" gorm:"column:pv_flag" binding:"omitempty,oneof=PNF VNF"` // 网元虚拟化标识 物理PNF 虚拟VNF
@@ -16,11 +23,6 @@ type NeInfo struct {
NeAddress string `json:"neAddress" gorm:"column:ne_address"` // MAC地址
HostIDs string `json:"hostIds" gorm:"column:host_ids"` // 网元主机ID组 数据格式(ssh,telnet) UDM(ssh,telnet,redis) UPF(ssh,telnet,telnet)
Status int64 `json:"status" gorm:"column:status"` // 网元状态 0离线 1在线 2配置待下发 3备用模式
Remark string `json:"remark" gorm:"column:remark"` // 备注
CreateBy string `json:"createBy" gorm:"column:create_by"` // 创建者
CreateTime int64 `json:"createTime" gorm:"column:create_time"` // 创建时间
UpdateBy string `json:"updateBy" gorm:"column:update_by"` // 更新者
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
// ====== 非数据库字段属性 ======

View File

@@ -41,23 +41,39 @@ func TestConfig(t *testing.T) {
if configParamFile == "*" {
for _, v := range fileNameList {
params := parseData(filepath.Join(configParamDir, v))
filePath := filepath.Join(configParamDir, v)
version := parseVersion(filePath)
params := parseData(filePath)
if params == nil {
return
}
saveData(params)
saveData(version, params)
}
} else {
params := parseData(filepath.Join(configParamDir, configParamFile))
filePath := filepath.Join(configParamDir, configParamFile)
version := parseVersion(filePath)
params := parseData(filePath)
if params == nil {
return
}
saveData(params)
saveData(version, params)
}
}
// ========= Main =============
// 根据文件名获取版本号 mme_2_param_config.yaml -> 2
func parseVersion(filePaht string) string {
version := "2"
splits := strings.Split(filepath.Base(filePaht), "_")
if len(splits) > 0 {
if splits[2] == "param" {
version = splits[1]
}
}
return version
}
// parseData 文件转map数据
func parseData(filePaht string) []map[string]string {
data, err := parseStrToMap(filePaht)
@@ -74,7 +90,7 @@ func parseData(filePaht string) []map[string]string {
}
// saveData 保存数据
func saveData(params []map[string]string) {
func saveData(version string, params []map[string]string) {
// 定义排序函数
sort.Slice(params, func(i, j int) bool {
paramSortI := params[i]["paramSort"]
@@ -109,6 +125,7 @@ func saveData(params []map[string]string) {
}
neConfig := model.NeConfig{
NeVersion: version,
NeType: v["neType"],
ParamName: v["paramName"],
ParamDisplay: v["paramDisplay"],
@@ -157,7 +174,7 @@ func saveDB(s model.NeConfig) int64 {
db := connDB()
// 检查是否存在
var id int64
db.Raw("SELECT id FROM ne_config WHERE ne_type = ? AND param_name = ?", s.NeType, s.ParamName).Scan(&id)
db.Raw("SELECT id FROM ne_config WHERE ne_type = ? AND ne_version = ? AND param_name = ?", s.NeType, s.NeVersion, s.ParamName).Scan(&id)
// 更新时间
s.UpdateTime = time.Now().UnixMilli()
if id > 0 {

View File

@@ -239,3 +239,23 @@ func (r NeInfo) UpdateState(id int64, status int64) int64 {
}
return tx.RowsAffected
}
// UpdateVersion 修改网元版本
func (r NeInfo) UpdateVersion(id int64, neVersion string) int64 {
if id <= 0 {
return 0
}
tx := db.DB("").Model(&model.NeInfo{})
// 构建查询条件
tx = tx.Where("id = ?", id)
tx.Updates(map[string]any{
"ne_version": neVersion,
"update_time": time.Now().UnixMilli(),
})
// 执行更新
if err := tx.Error; err != nil {
logger.Errorf("update err => %v", err.Error())
return 0
}
return tx.RowsAffected
}

View File

@@ -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
}

View File

@@ -37,7 +37,7 @@ func (r NeConfig) GetOMCYaml(paramName string) []map[string]any {
// ModifyOMCYaml 修改OMC网元配置文件
func (r NeConfig) ModifyOMCYaml(paramName, loc string, paramData any) error {
neConfig := r.FindByNeTypeAndParamName("OMC", paramName)
neConfig := r.FindByNeTypeAndParamName("OMC", config.Version, paramName)
if neConfig.ParamType == "list" {
if paramName == "notificationEmail" {
notificationEmailData := config.Get("notification.email").(map[string]any)

View File

@@ -7,7 +7,6 @@ import (
"path/filepath"
"runtime"
"strings"
"time"
"be.ems/src/framework/constants"
"be.ems/src/framework/database/redis"
@@ -187,7 +186,6 @@ func (r NeInfo) bandNeStatus(arr *[]model.NeInfo) {
if v.Status != 0 {
v.Status = 0
(*arr)[i].Status = v.Status
(*arr)[i].UpdateTime = time.Now().UnixMilli()
r.neInfoRepository.UpdateState(v.ID, v.Status)
}
continue
@@ -205,8 +203,14 @@ func (r NeInfo) bandNeStatus(arr *[]model.NeInfo) {
}
(*arr)[i].Status = status
if v.Status != status {
(*arr)[i].UpdateTime = time.Now().UnixMilli()
r.neInfoRepository.UpdateState(v.ID, status)
r.RefreshByNeTypeAndNeID(v.NeType, v.NeId)
}
// 网元版本设置为当前版本
version, ok := result["version"].(string)
if ok && version != v.NeVersion {
r.neInfoRepository.UpdateVersion(v.ID, version)
r.RefreshByNeTypeAndNeID(v.NeType, v.NeId)
}
}
}

View File

@@ -64,12 +64,12 @@ func (r NeVersion) checkNeVersion(arr *[]model.NeVersion) {
continue
}
if v, ok := result["version"]; ok && v != nil {
ver := v.(string)
ver := fmt.Sprint(v)
if ver == item.Version {
continue
}
item.Name = "-"
item.Path = "-"
// item.Name = "-"
// item.Path = "-"
item.Version = ver
}
if item.NeType != neInfo.NeType || item.NeId != neInfo.NeId {