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

feat(database): add ne_version and schema columns to ne_info table

feat(database): update ne_info table structure in upgrade script

fix(ne_config): handle id as number in Info and Add methods

fix(ne_config): validate neId and fetch neInfo in ListByNeType and DataAdd methods

fix(ne_info): extract version from ServerState in Add and Edit methods

refactor(ne_config): update NeConfig model to include NeVersion

refactor(ne_info): add NeVersion and Schema fields to NeInfo model

test(ne_config): enhance test cases to include version parsing and saving

refactor(ne_config): improve cache handling and querying by NeType and NeVersion

fix(ne_info): update NeInfo version during status change
This commit is contained in:
TsMask
2025-10-17 10:17:07 +08:00
parent 3b053d7f47
commit 8cd86a62d6
18 changed files with 1306 additions and 254 deletions

View File

@@ -3,6 +3,7 @@ package repository
import (
"time"
"be.ems/src/framework/database/db"
"be.ems/src/framework/datasource"
"be.ems/src/framework/logger"
"be.ems/src/modules/network_element/model"
@@ -45,9 +46,9 @@ func (r NeConfig) SelectByPage(query map[string]string) ([]model.NeConfig, int64
return rows, total
}
// SelectList 根据实体查询
func (r *NeConfig) SelectList(param model.NeConfig) []model.NeConfig {
tx := datasource.DB("").Model(&model.NeConfig{})
// Select 查询集合
func (r NeConfig) Select(param model.NeConfig) []model.NeConfig {
tx := db.DB("").Model(&model.NeConfig{})
// 查询条件拼接
if param.NeType != "" {
tx = tx.Where("ne_type = ?", param.NeType)
@@ -83,19 +84,19 @@ func (r *NeConfig) SelectByIds(ids []string) []model.NeConfig {
}
// Insert 新增信息
func (r *NeConfig) Insert(param model.NeConfig) string {
func (r *NeConfig) Insert(param model.NeConfig) int64 {
param.UpdateTime = time.Now().UnixMilli()
// 执行插入
if err := datasource.DB("").Create(&param).Error; err != nil {
logger.Errorf("insert err => %v", err.Error())
return ""
return 0
}
return param.ID
}
// Update 修改信息
func (r *NeConfig) Update(param model.NeConfig) int64 {
if param.ID == "" {
if param.ID == 0 {
return 0
}
param.UpdateTime = time.Now().UnixMilli()

View File

@@ -3,6 +3,7 @@ package repository
import (
"time"
"be.ems/src/framework/database/db"
"be.ems/src/framework/datasource"
"be.ems/src/framework/logger"
"be.ems/src/modules/network_element/model"
@@ -222,6 +223,26 @@ func (r *NeInfo) UpdateState(id, status string) int64 {
return tx.RowsAffected
}
// UpdateVersion 修改网元版本
func (r NeInfo) UpdateVersion(id string, neVersion string) int64 {
if id == "" {
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
}
// DeleteByIds 批量删除网元信息
func (r NeInfo) DeleteByIds(ids []string) int64 {
if len(ids) <= 0 {