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:
@@ -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"],
|
||||
@@ -153,14 +170,14 @@ func connDB() *gorm.DB {
|
||||
}
|
||||
|
||||
// saveDB 表插入或更新
|
||||
func saveDB(s model.NeConfig) string {
|
||||
func saveDB(s model.NeConfig) int64 {
|
||||
db := connDB()
|
||||
// 检查是否存在
|
||||
var id string
|
||||
db.Raw("SELECT id FROM ne_config WHERE ne_type = ? AND param_name = ?", s.NeType, s.ParamName).Scan(&id)
|
||||
var id int64
|
||||
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 != "" {
|
||||
if id > 0 {
|
||||
s.ID = id
|
||||
db.Save(&s)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user