Merge remote-tracking branch 'origin/main' into multi-tenant
This commit is contained in:
@@ -34,10 +34,9 @@ type NeConfigController struct {
|
||||
//
|
||||
// GET /list
|
||||
func (s *NeConfigController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.neConfigService.SelectPage(querys)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
querys := ctx.QueryMapString(c)
|
||||
rows, total := s.neConfigService.SelectPage(querys)
|
||||
c.JSON(200, result.Ok(map[string]any{"total": total, "rows": rows}))
|
||||
}
|
||||
|
||||
// 网元参数配置可用属性值信息
|
||||
@@ -199,16 +198,16 @@ func (s *NeConfigController) DataInfo(c *gin.Context) {
|
||||
}
|
||||
c.JSON(200, result.OkData(resData))
|
||||
return
|
||||
} else {
|
||||
// 网元直连
|
||||
resData, err := neFetchlink.NeConfigInfo(neInfo, query.ParamName)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.Ok(resData))
|
||||
}
|
||||
|
||||
// 网元直连
|
||||
resData, err := neFetchlink.NeConfigInfo(neInfo, query.ParamName)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.Ok(resData))
|
||||
}
|
||||
|
||||
// 网元参数配置数据修改
|
||||
@@ -242,15 +241,15 @@ func (s *NeConfigController) DataEdit(c *gin.Context) {
|
||||
}
|
||||
c.JSON(200, result.OkData(resData))
|
||||
return
|
||||
} else {
|
||||
// 网元直连
|
||||
resData, err := neFetchlink.NeConfigUpdate(neInfo, body.ParamName, body.Loc, body.ParamData)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(resData))
|
||||
}
|
||||
|
||||
// 网元直连
|
||||
resData, err := neFetchlink.NeConfigUpdate(neInfo, body.ParamName, body.Loc, body.ParamData)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(resData))
|
||||
}
|
||||
|
||||
// 网元参数配置数据新增(array)
|
||||
|
||||
@@ -79,6 +79,13 @@ func (s *NeHostController) Add(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if body.GroupID == "1" {
|
||||
// 主机信息操作【%s】失败,禁止操作网元
|
||||
msg := i18n.TKey(language, "neHost.banNE")
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueHost := s.neHostService.CheckUniqueHostTitle(body.GroupID, body.Title, body.HostType, "")
|
||||
if !uniqueHost {
|
||||
|
||||
50
src/modules/network_element/fetch_link/amf.go
Normal file
50
src/modules/network_element/fetch_link/amf.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package fetchlink
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/fetch"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// AMFNbInfoList AMF基站信息
|
||||
//
|
||||
// 查询参数 {"nbId":"7"}
|
||||
//
|
||||
// 返回结果 []
|
||||
func AMFNbInfoList(neInfo model.NeInfo, data map[string]string) ([]map[string]any, error) {
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/ueManagement/v1/elementType/amf/objectType/nbInfo", neInfo.IP, neInfo.Port)
|
||||
// 查询参数拼接
|
||||
query := []string{}
|
||||
if v, ok := data["nbId"]; ok && v != "" {
|
||||
query = append(query, fmt.Sprintf("nbId=%s", v))
|
||||
}
|
||||
if len(query) > 0 {
|
||||
neUrl = fmt.Sprintf("%s?%s", neUrl, strings.Join(query, "&"))
|
||||
}
|
||||
|
||||
var resData map[string]any
|
||||
resBytes, err := fetch.Get(neUrl, nil, 60_000)
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
logger.Warnf("AMFNbInfoList Get \"%s\"", neUrl)
|
||||
logger.Errorf("AMFNbInfoList %s", errStr)
|
||||
return nil, fmt.Errorf("NeService AMF API Error")
|
||||
}
|
||||
|
||||
// 序列化结果 {"data":[{"id":"7","name":"NR-SA-GNB","address":"192.168.5.100:60110","ueNum":0}]}
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Errorf("AMFNbInfoList Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 固定返回字段,方便前端解析
|
||||
if v, ok := resData["data"]; ok && v != nil {
|
||||
return v.([]map[string]any), nil
|
||||
}
|
||||
return []map[string]any{}, nil
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func HLRTraceStart(neInfo model.NeInfo, data map[string]any) (string, error) {
|
||||
if v, ok := resData["code"]; ok && v == "0" {
|
||||
return strings.TrimSpace(strings.ToLower(resData["message"])), nil
|
||||
}
|
||||
return "", fmt.Errorf(resData["message"])
|
||||
return "", fmt.Errorf("%s", resData["message"])
|
||||
}
|
||||
|
||||
// HLRTraceStop HLR跟踪任务停止
|
||||
@@ -64,5 +64,5 @@ func HLRTraceStop(neInfo model.NeInfo, data map[string]any) (string, error) {
|
||||
if v, ok := resData["code"]; ok && v == "0" {
|
||||
return strings.TrimSpace(strings.ToLower(resData["message"])), nil
|
||||
}
|
||||
return "", fmt.Errorf(resData["message"])
|
||||
return "", fmt.Errorf("%s", resData["message"])
|
||||
}
|
||||
|
||||
94
src/modules/network_element/fetch_link/ims.go
Normal file
94
src/modules/network_element/fetch_link/ims.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package fetchlink
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/fetch"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// IMSUeSessionNum IMS会话数量
|
||||
//
|
||||
// 返回结果 0
|
||||
func IMSUeSessionNum(neInfo model.NeInfo) (int64, error) {
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/ueManagement/v1/elementType/ims/objectType/ueNum", neInfo.IP, neInfo.Port)
|
||||
resBytes, err := fetch.Get(neUrl, nil, 60_000)
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
logger.Warnf("IMSUeSessionNum Get \"%s\"", neUrl)
|
||||
logger.Errorf("IMSUeSessionNum %s", errStr)
|
||||
return 0, fmt.Errorf("NeService IMS API Error")
|
||||
}
|
||||
// 序列化结果 {"data":{"ueNum":0}}
|
||||
var resData map[string]any
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Errorf("IMSUeSessionNum Unmarshal %s", err.Error())
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 固定返回字段,方便前端解析
|
||||
var ueNum int64 = 0
|
||||
if v, ok := resData["data"]; ok && v != nil {
|
||||
if num := v.(map[string]any)["ueNum"]; num != nil {
|
||||
ueNum = parse.Number(num)
|
||||
}
|
||||
}
|
||||
return ueNum, nil
|
||||
}
|
||||
|
||||
// IMSUeSessionList IMS会话列表
|
||||
//
|
||||
// 查询参数 {"imsi":"460001230000002","msisdn":"12307551232"}
|
||||
//
|
||||
// 返回结果 []
|
||||
func IMSUeSessionList(neInfo model.NeInfo, data map[string]string) ([]map[string]any, error) {
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/ueManagement/v1/elementType/ims/objectType/ueInfo", neInfo.IP, neInfo.Port)
|
||||
// 查询参数拼接
|
||||
query := []string{}
|
||||
if v, ok := data["imsi"]; ok && v != "" {
|
||||
query = append(query, fmt.Sprintf("imsi=%s", v))
|
||||
}
|
||||
if v, ok := data["msisdn"]; ok && v != "" {
|
||||
query = append(query, fmt.Sprintf("msisdn=%s", v))
|
||||
}
|
||||
if len(query) > 0 {
|
||||
neUrl = fmt.Sprintf("%s?%s", neUrl, strings.Join(query, "&"))
|
||||
}
|
||||
|
||||
resBytes, err := fetch.Get(neUrl, nil, 60_000)
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
logger.Warnf("IMSUeSessionList Get \"%s\"", neUrl)
|
||||
logger.Errorf("IMSUeSessionList %s", errStr)
|
||||
return nil, fmt.Errorf("NeService IMS API Error")
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
// { "data":[
|
||||
// {
|
||||
// "activeTime": "2023-11-29 17:04:54",
|
||||
// "barring": 0,
|
||||
// "impu": "sip:12307551232@ims.mnc000.mcc460.3gppnetwork.org",
|
||||
// "imsi": "460001230000002",
|
||||
// "msisdn": "12307551232",
|
||||
// "regState": 1
|
||||
// }
|
||||
// ] }
|
||||
var resData map[string]any
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Errorf("IMSUeSessionList Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 固定返回字段,方便前端解析
|
||||
if v, ok := resData["data"]; ok && v != nil {
|
||||
return v.([]map[string]any), nil
|
||||
}
|
||||
return []map[string]any{}, nil
|
||||
}
|
||||
50
src/modules/network_element/fetch_link/mme.go
Normal file
50
src/modules/network_element/fetch_link/mme.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package fetchlink
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/fetch"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// MMENbInfoList AMF基站信息
|
||||
//
|
||||
// 查询参数 {"nbId":"7"}
|
||||
//
|
||||
// 返回结果 []
|
||||
func MMENbInfoList(neInfo model.NeInfo, data map[string]string) ([]map[string]any, error) {
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/ueManagement/v1/elementType/mme/objectType/nbInfo", neInfo.IP, neInfo.Port)
|
||||
// 查询参数拼接
|
||||
query := []string{}
|
||||
if v, ok := data["nbId"]; ok && v != "" {
|
||||
query = append(query, fmt.Sprintf("nbId=%s", v))
|
||||
}
|
||||
if len(query) > 0 {
|
||||
neUrl = fmt.Sprintf("%s?%s", neUrl, strings.Join(query, "&"))
|
||||
}
|
||||
|
||||
var resData map[string]any
|
||||
resBytes, err := fetch.Get(neUrl, nil, 60_000)
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
logger.Warnf("MMENbInfoList Get \"%s\"", neUrl)
|
||||
logger.Errorf("MMENbInfoList %s", errStr)
|
||||
return nil, fmt.Errorf("NeService AMF API Error")
|
||||
}
|
||||
|
||||
// 序列化结果 {"data":[{"id":"7","name":"NR-SA-GNB","address":"192.168.5.100:60110","ueNum":0}]}
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Errorf("MMENbInfoList Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 固定返回字段,方便前端解析
|
||||
if v, ok := resData["data"]; ok && v != nil {
|
||||
return v.([]map[string]any), nil
|
||||
}
|
||||
return []map[string]any{}, nil
|
||||
}
|
||||
@@ -7,9 +7,40 @@ import (
|
||||
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/fetch"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// SMFSubNum SMF在线订阅用户数量 只含5G用户数据
|
||||
//
|
||||
// 返回结果 0
|
||||
func SMFSubNum(neInfo model.NeInfo) (int64, error) {
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/ueManagement/v1/elementType/smf/objectType/ueNum", neInfo.IP, neInfo.Port)
|
||||
resBytes, err := fetch.Get(neUrl, nil, 60_000)
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
logger.Warnf("SMFSubNum Get \"%s\"", neUrl)
|
||||
logger.Errorf("SMFSubNum %s", errStr)
|
||||
return 0, fmt.Errorf("NeService SMF API Error")
|
||||
}
|
||||
// 序列化结果 {"data":{"ueNum":0}}
|
||||
var resData map[string]any
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Errorf("IMSUeSession Unmarshal %s", err.Error())
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 固定返回字段,方便前端解析
|
||||
var ueNum int64 = 0
|
||||
if v, ok := resData["data"]; ok && v != nil {
|
||||
if num := v.(map[string]any)["ueNum"]; num != nil {
|
||||
ueNum = parse.Number(num)
|
||||
}
|
||||
}
|
||||
return ueNum, nil
|
||||
}
|
||||
|
||||
// SMFSubInfoList SMF在线订阅用户列表信息
|
||||
//
|
||||
// 查询参数 {"imsi":"360000100000130","msisdn":"8612300000130","upstate":"Inactive","pageNum":"1"}
|
||||
|
||||
@@ -35,5 +35,5 @@ func UDMImportAuth(udmIP string, data map[string]any) (string, error) {
|
||||
if v, ok := resData["code"]; ok && v == "00000" {
|
||||
return strings.TrimSpace(strings.ToLower(resData["message"])), nil
|
||||
}
|
||||
return "", fmt.Errorf(resData["message"])
|
||||
return "", fmt.Errorf("%s", resData["message"])
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@ package model
|
||||
// NeConfig 网元_参数配置可用属性值
|
||||
type NeConfig struct {
|
||||
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"` // 更新时间
|
||||
NeType string `json:"neType" binding:"required" gorm:"column:ne_type"` // 网元类型
|
||||
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数组多层
|
||||
ParamJson string `json:"-" gorm:"column:param_json"` // accesss属性控制:只读read-only/read/ro 读写read-write
|
||||
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"` // 更新时间
|
||||
|
||||
// ====== 非数据库字段属性 ======
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ func saveData(params []map[string]string) {
|
||||
})
|
||||
// 遍历插入
|
||||
for _, v := range params {
|
||||
// 排序
|
||||
paramSort := v["paramSort"]
|
||||
if len(paramSort) == 0 || paramSort == "" {
|
||||
paramSort = "0"
|
||||
@@ -101,6 +102,12 @@ func saveData(params []map[string]string) {
|
||||
sort = 0
|
||||
}
|
||||
|
||||
// 可见性 默认public
|
||||
visible := v["visible"]
|
||||
if len(visible) == 0 || visible == "" {
|
||||
visible = "public"
|
||||
}
|
||||
|
||||
neConfig := model.NeConfig{
|
||||
NeType: v["neType"],
|
||||
ParamName: v["paramName"],
|
||||
@@ -108,6 +115,7 @@ func saveData(params []map[string]string) {
|
||||
ParamType: v["paramType"],
|
||||
ParamJson: v["paramJson"],
|
||||
ParamPerms: v["paramPerms"],
|
||||
Visible: visible,
|
||||
ParamSort: sort,
|
||||
}
|
||||
neConfig.ID = saveDB(neConfig)
|
||||
@@ -215,6 +223,8 @@ func parseParamConfig(data map[string]any) ([]map[string]string, error) {
|
||||
itemMap["paramDisplay"] = iiv.(string)
|
||||
case "sort":
|
||||
itemMap["paramSort"] = fmt.Sprint(iiv)
|
||||
case "visible":
|
||||
itemMap["visible"] = fmt.Sprint(iiv)
|
||||
case "perms", "method":
|
||||
itemMap["paramPerms"] = iiv.(string)
|
||||
case "list", "array": // 参数类型为数组
|
||||
|
||||
@@ -1,259 +1,125 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 NeConfig 结构体
|
||||
var NewNeConfig = &NeConfig{
|
||||
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",
|
||||
"param_name": "ParamName",
|
||||
"param_display": "ParamDisplay",
|
||||
"param_type": "ParamType",
|
||||
"param_json": "ParamJson",
|
||||
"param_sort": "ParamSort",
|
||||
"param_perms": "ParamPerms",
|
||||
"update_time": "UpdateTime",
|
||||
},
|
||||
}
|
||||
var NewNeConfig = &NeConfig{}
|
||||
|
||||
// NeConfig 网元参数配置可用属性值 数据层处理
|
||||
type NeConfig struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
type NeConfig struct{}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *NeConfig) convertResultRows(rows []map[string]any) []model.NeConfig {
|
||||
arr := make([]model.NeConfig, 0)
|
||||
for _, row := range rows {
|
||||
item := model.NeConfig{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
func (r *NeConfig) SelectPage(query map[string]any) map[string]any {
|
||||
// SelectByPage 分页查询集合
|
||||
func (r NeConfig) SelectByPage(query map[string]string) ([]model.NeConfig, int64) {
|
||||
tx := datasource.DB("").Model(&model.NeConfig{})
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, v)
|
||||
tx = tx.Where("ne_type = ?", v)
|
||||
}
|
||||
if v, ok := query["paramName"]; ok && v != "" {
|
||||
conditions = append(conditions, "param_name = ?")
|
||||
params = append(params, v)
|
||||
tx = tx.Where("param_name = ?", v)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
// 查询结果
|
||||
var total int64 = 0
|
||||
rows := []model.NeConfig{}
|
||||
|
||||
// 查询数量为0直接返回
|
||||
if err := tx.Count(&total).Error; err != nil || total <= 0 {
|
||||
return rows, total
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.NeHost{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(id) as 'total' from ne_config"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
// 查询数据分页
|
||||
pageNum, pageSize := datasource.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
tx = tx.Limit(pageSize).Offset(pageSize * pageNum)
|
||||
err := tx.Find(&rows).Error
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
return rows, total
|
||||
}
|
||||
total := parse.Number(totalRows[0]["total"])
|
||||
if total == 0 {
|
||||
return result
|
||||
} else {
|
||||
result["total"] = total
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
result["rows"] = r.convertResultRows(results)
|
||||
return result
|
||||
return rows, total
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
func (r *NeConfig) SelectList(param model.NeConfig) []model.NeConfig {
|
||||
tx := datasource.DB("").Model(&model.NeConfig{})
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if param.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, param.NeType)
|
||||
tx = tx.Where("ne_type = ?", param.NeType)
|
||||
}
|
||||
if param.ParamName != "" {
|
||||
conditions = append(conditions, "param_name = ?")
|
||||
params = append(params, param.ParamName)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
tx = tx.Where("param_name = ?", param.ParamName)
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by param_sort asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeConfig) SelectByIds(ids []string) []model.NeConfig {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(ids))
|
||||
querySql := r.selectSql + " where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(ids)
|
||||
results, err := datasource.RawDB("", querySql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return []model.NeConfig{}
|
||||
}
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeConfig) Insert(param model.NeConfig) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if param.NeType != "" {
|
||||
params["ne_type"] = param.NeType
|
||||
}
|
||||
if param.ParamName != "" {
|
||||
params["param_name"] = param.ParamName
|
||||
}
|
||||
if param.ParamDisplay != "" {
|
||||
params["param_display"] = param.ParamDisplay
|
||||
}
|
||||
if param.ParamType != "" {
|
||||
params["param_type"] = param.ParamType
|
||||
}
|
||||
if param.ParamJson != "" {
|
||||
params["param_json"] = param.ParamJson
|
||||
}
|
||||
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 ne_config (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
tx := db.Begin()
|
||||
// 执行插入
|
||||
err := tx.Exec(sql, values...).Error
|
||||
if err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
err = tx.Raw("select last_insert_id()").Row().Scan(&insertedID)
|
||||
if err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 提交事务
|
||||
tx.Commit()
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeConfig) Update(param model.NeConfig) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if param.NeType != "" {
|
||||
params["ne_type"] = param.NeType
|
||||
}
|
||||
if param.ParamName != "" {
|
||||
params["param_name"] = param.ParamName
|
||||
}
|
||||
if param.ParamDisplay != "" {
|
||||
params["param_display"] = param.ParamDisplay
|
||||
}
|
||||
if param.ParamType != "" {
|
||||
params["param_type"] = param.ParamType
|
||||
}
|
||||
if param.ParamJson != "" {
|
||||
params["param_json"] = param.ParamJson
|
||||
}
|
||||
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 ne_config set " + strings.Join(keys, ",") + " where id = ?"
|
||||
|
||||
// 执行更新
|
||||
values = append(values, param.ID)
|
||||
rows, err := datasource.ExecDB("", sql, values)
|
||||
if err != nil {
|
||||
logger.Errorf("update row : %v", err.Error())
|
||||
return 0
|
||||
rows := []model.NeConfig{}
|
||||
if err := tx.Order("param_sort asc").Find(&rows).Error; err != nil {
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
return rows
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeConfig) DeleteByIds(ids []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(ids))
|
||||
sql := "delete from ne_config where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(ids)
|
||||
results, err := datasource.ExecDB("", sql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("delete err => %v", err)
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeConfig) SelectByIds(ids []string) []model.NeConfig {
|
||||
rows := []model.NeConfig{}
|
||||
if len(ids) <= 0 {
|
||||
return rows
|
||||
}
|
||||
tx := datasource.DB("").Model(&model.NeConfig{})
|
||||
// 构建查询条件
|
||||
tx = tx.Where("id in ?", ids)
|
||||
// 查询数据
|
||||
if err := tx.Find(&rows).Error; err != nil {
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
return rows
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeConfig) Insert(param model.NeConfig) string {
|
||||
param.UpdateTime = time.Now().UnixMilli()
|
||||
// 执行插入
|
||||
if err := datasource.DB("").Create(¶m).Error; err != nil {
|
||||
logger.Errorf("insert err => %v", err.Error())
|
||||
return ""
|
||||
}
|
||||
return param.ID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeConfig) Update(param model.NeConfig) int64 {
|
||||
if param.ID == "" {
|
||||
return 0
|
||||
}
|
||||
return results
|
||||
param.UpdateTime = time.Now().UnixMilli()
|
||||
tx := datasource.DB("").Model(&model.NeConfig{})
|
||||
// 构建查询条件
|
||||
tx = tx.Where("id = ?", param.ID)
|
||||
tx = tx.Omit("id")
|
||||
// 执行更新
|
||||
if err := tx.Updates(param).Error; err != nil {
|
||||
logger.Errorf("update err => %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeConfig) DeleteByIds(ids []string) int64 {
|
||||
if len(ids) <= 0 {
|
||||
return 0
|
||||
}
|
||||
tx := datasource.DB("").Where("id in ?", ids)
|
||||
if err := tx.Delete(&model.NeConfig{}).Error; err != nil {
|
||||
logger.Errorf("delete err => %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
@@ -111,8 +111,28 @@ func (r *NeHost) SelectPage(query map[string]any) map[string]any {
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
// 排序
|
||||
orderSql := ""
|
||||
if sv, ok := query["sortField"]; ok && sv != "" {
|
||||
sortSql := fmt.Sprint(sv)
|
||||
if sortSql == "updateTime" {
|
||||
sortSql = "update_time"
|
||||
}
|
||||
if sortSql == "createTime" {
|
||||
sortSql = "create_time"
|
||||
}
|
||||
if ov, ok := query["sortOrder"]; ok && ov != "" {
|
||||
if fmt.Sprint(ov) == "desc" {
|
||||
sortSql += " desc "
|
||||
} else {
|
||||
sortSql += " asc "
|
||||
}
|
||||
}
|
||||
orderSql = fmt.Sprintf(" order by %s ", sortSql)
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + pageSql
|
||||
querySql := r.selectSql + whereSql + orderSql + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
|
||||
@@ -18,6 +18,7 @@ var neListSort = []string{
|
||||
"IMS",
|
||||
"AMF",
|
||||
"AUSF",
|
||||
"UDR",
|
||||
"UDM",
|
||||
"SMF",
|
||||
"PCF",
|
||||
@@ -33,6 +34,8 @@ var neListSort = []string{
|
||||
"SMSF",
|
||||
"CBC",
|
||||
"CHF",
|
||||
"HLR",
|
||||
"SGWC",
|
||||
}
|
||||
|
||||
// 实例化数据层 NeInfo 结构体
|
||||
|
||||
@@ -115,8 +115,8 @@ func (r *NeConfig) SelectNeConfigByNeTypeAndParamName(neType, paramName string)
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeConfig) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neConfigRepository.SelectPage(query)
|
||||
func (r *NeConfig) SelectPage(query map[string]string) ([]model.NeConfig, int64) {
|
||||
return r.neConfigRepository.SelectByPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
|
||||
@@ -149,6 +149,13 @@ func (r *NeHost) DeleteByIds(hostIds []string) (int64, error) {
|
||||
return 0, fmt.Errorf("neHost.noData")
|
||||
}
|
||||
|
||||
for _, v := range ids {
|
||||
if v.GroupID == "1" {
|
||||
// 主机信息操作【%s】失败,禁止操作网元
|
||||
return 0, fmt.Errorf("neHost.banNE")
|
||||
}
|
||||
}
|
||||
|
||||
if len(ids) == len(hostIds) {
|
||||
rows := r.neHostRepository.DeleteByIds(hostIds)
|
||||
return rows, nil
|
||||
|
||||
Reference in New Issue
Block a user