feat: 接口网元状态/网元列表
This commit is contained in:
@@ -8,4 +8,7 @@ import (
|
||||
type INeInfo interface {
|
||||
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||
SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo
|
||||
|
||||
// SelectNeList 查询网元列表
|
||||
SelectNeList(ne model.NeInfo) []model.NeInfo
|
||||
}
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/datasource"
|
||||
"ems.agt/src/framework/logger"
|
||||
"ems.agt/src/framework/utils/repo"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// neListSort 网元列表预设排序
|
||||
var neListSort = []string{
|
||||
"OMC",
|
||||
"MME",
|
||||
"AMF",
|
||||
"AUSF",
|
||||
"UDM",
|
||||
"SMF",
|
||||
"PCF",
|
||||
"UPF",
|
||||
"NRF",
|
||||
"NSSF",
|
||||
"IMS",
|
||||
"N3IWF",
|
||||
"NEF",
|
||||
"LMF",
|
||||
}
|
||||
|
||||
// 实例化数据层 NeInfoImpl 结构体
|
||||
var NewNeInfoImpl = &NeInfoImpl{
|
||||
selectSql: `select id, ne_type, ne_id, rm_uid, ne_name, ip, port, pv_flag, province, vendor_name, dn, ne_address, status, update_time from ne_info`,
|
||||
@@ -49,6 +70,31 @@ func (r *NeInfoImpl) convertResultRows(rows []map[string]any) []model.NeInfo {
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
|
||||
// 排序
|
||||
sort.Slice(arr, func(i, j int) bool {
|
||||
// 前一个
|
||||
after := arr[i]
|
||||
afterIndex := 0
|
||||
for i, v := range neListSort {
|
||||
if after.NeType == v {
|
||||
afterIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
// 后一个
|
||||
befter := arr[j]
|
||||
befterIndex := 0
|
||||
for i, v := range neListSort {
|
||||
if befter.NeType == v {
|
||||
befterIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
// 升序
|
||||
return afterIndex < befterIndex
|
||||
})
|
||||
|
||||
return arr
|
||||
}
|
||||
|
||||
@@ -67,3 +113,34 @@ func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeIn
|
||||
}
|
||||
return model.NeInfo{}
|
||||
}
|
||||
|
||||
// SelectNeList 查询网元列表
|
||||
func (r *NeInfoImpl) SelectNeList(ne model.NeInfo) []model.NeInfo {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if ne.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, ne.NeType)
|
||||
}
|
||||
if ne.NeId != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, ne.NeId)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by ne_type asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user