feat: 新增mml到工具模块
This commit is contained in:
98
src/modules/tool/controller/mml.go
Normal file
98
src/modules/tool/controller/mml.go
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"be.ems/src/framework/i18n"
|
||||||
|
"be.ems/src/framework/reqctx"
|
||||||
|
"be.ems/src/framework/resp"
|
||||||
|
neService "be.ems/src/modules/network_element/service"
|
||||||
|
"be.ems/src/modules/tool/service"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化控制层 MMLController 结构体
|
||||||
|
var NewMML = &MMLController{
|
||||||
|
neInfoService: neService.NewNeInfo,
|
||||||
|
mmlSystemService: service.NewMMLSystem,
|
||||||
|
mmlSubscriberService: service.NewMMLSubscriber,
|
||||||
|
}
|
||||||
|
|
||||||
|
// MML 网元MML
|
||||||
|
//
|
||||||
|
// PATH /tool/mml
|
||||||
|
type MMLController struct {
|
||||||
|
neInfoService *neService.NeInfo // 网元信息服务
|
||||||
|
mmlSystemService *service.MMLSystem
|
||||||
|
mmlSubscriberService *service.MMLSubscriber
|
||||||
|
}
|
||||||
|
|
||||||
|
// SystemList MML网元列表
|
||||||
|
//
|
||||||
|
// GET /system/list
|
||||||
|
func (s MMLController) SystemList(c *gin.Context) {
|
||||||
|
query := reqctx.QueryMap(c)
|
||||||
|
rows, total := s.mmlSystemService.FindByPage(query)
|
||||||
|
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SubscriberList MML网元UDM列表
|
||||||
|
//
|
||||||
|
// GET /subscriber/list
|
||||||
|
func (s MMLController) SubscriberList(c *gin.Context) {
|
||||||
|
query := reqctx.QueryMap(c)
|
||||||
|
rows, total := s.mmlSubscriberService.FindByPage(query)
|
||||||
|
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command MML命令执行
|
||||||
|
//
|
||||||
|
// POST /command
|
||||||
|
func (s MMLController) Command(c *gin.Context) {
|
||||||
|
language := reqctx.AcceptLanguage(c)
|
||||||
|
var body struct {
|
||||||
|
NeType string `json:"neType" binding:"required"` // 网元类型
|
||||||
|
NeId string `json:"neId" binding:"required"` // 网元ID
|
||||||
|
Command []string `json:"command" binding:"required"` // 命令
|
||||||
|
Type string `json:"type" binding:"required,oneof=General Standard"` // 类型UPF标准版 General Standard
|
||||||
|
}
|
||||||
|
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||||
|
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||||
|
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询网元获取IP
|
||||||
|
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
|
||||||
|
}
|
||||||
|
// 网元主机的Telnet客户端
|
||||||
|
num := 1
|
||||||
|
if body.Type == "Standard" {
|
||||||
|
num = 2
|
||||||
|
}
|
||||||
|
telnetClient, err := s.neInfoService.NeRunTelnetClient(neInfo.NeType, neInfo.NeId, num)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer telnetClient.Close()
|
||||||
|
if body.Type == "Standard" {
|
||||||
|
telnetClient.WindowChange(1024, 1024)
|
||||||
|
}
|
||||||
|
// 发送MML
|
||||||
|
result := []string{}
|
||||||
|
for _, v := range body.Command {
|
||||||
|
output, err := telnetClient.RunCMD(v + "\r\r")
|
||||||
|
if err != nil {
|
||||||
|
result = append(result, err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result = append(result, strings.TrimSpace(output))
|
||||||
|
}
|
||||||
|
c.JSON(200, resp.OkData(result))
|
||||||
|
}
|
||||||
19
src/modules/tool/model/mml_subscriber.go
Normal file
19
src/modules/tool/model/mml_subscriber.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
// MMLSubscriber MML网元UDM命令
|
||||||
|
type MMLSubscriber struct {
|
||||||
|
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
|
||||||
|
NeType string `json:"neType" gorm:"column:ne_type"`
|
||||||
|
Category string `json:"category" gorm:"column:category"`
|
||||||
|
CatDisplay string `json:"catDisplay" gorm:"column:cat_display"`
|
||||||
|
Operation string `json:"operation" gorm:"column:operation"`
|
||||||
|
Object string `json:"object" gorm:"column:object"`
|
||||||
|
MmlDisplay string `json:"mmlDisplay" gorm:"column:mml_display"`
|
||||||
|
ParamJson string `json:"paramJson" gorm:"column:param_json"`
|
||||||
|
Status string `json:"status" gorm:"column:status"` // 激活: Active 未激活: Inactive
|
||||||
|
}
|
||||||
|
|
||||||
|
// TableName 表名称
|
||||||
|
func (*MMLSubscriber) TableName() string {
|
||||||
|
return "mml_subscriber"
|
||||||
|
}
|
||||||
20
src/modules/tool/model/mml_system.go
Normal file
20
src/modules/tool/model/mml_system.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
// MMLSystem MML网元命令
|
||||||
|
type MMLSystem struct {
|
||||||
|
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
|
||||||
|
NeType string `json:"neType" gorm:"column:ne_type"`
|
||||||
|
Category string `json:"category" gorm:"column:category"`
|
||||||
|
CatDisplay string `json:"catDisplay" gorm:"column:cat_display"`
|
||||||
|
Operation string `json:"operation" gorm:"column:operation"` // 操作行为
|
||||||
|
Object string `json:"object" gorm:"column:object"` // 操作对象
|
||||||
|
MmlDisplay string `json:"mmlDisplay" gorm:"column:mml_display"` // 显示
|
||||||
|
ObjectType string `json:"objectType" gorm:"column:object_type"`
|
||||||
|
ParamJson string `json:"paramJson" gorm:"column:param_json"`
|
||||||
|
Status string `json:"status" gorm:"column:status"` // 激活: Active 未激活: Inactive
|
||||||
|
}
|
||||||
|
|
||||||
|
// TableName 表名称
|
||||||
|
func (*MMLSystem) TableName() string {
|
||||||
|
return "mml_system"
|
||||||
|
}
|
||||||
44
src/modules/tool/repository/mml_subscriber.go
Normal file
44
src/modules/tool/repository/mml_subscriber.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"be.ems/src/framework/database/db"
|
||||||
|
"be.ems/src/framework/logger"
|
||||||
|
"be.ems/src/modules/tool/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化数据层 MMLSubscriber 结构体
|
||||||
|
var NewMMLSubscriber = &MMLSubscriber{}
|
||||||
|
|
||||||
|
// MMLSubscriber MML网元UDM命令 数据层处理
|
||||||
|
type MMLSubscriber struct{}
|
||||||
|
|
||||||
|
// SelectByPage 分页查询集合
|
||||||
|
func (r MMLSubscriber) SelectByPage(query map[string]string) ([]model.MMLSubscriber, int64) {
|
||||||
|
tx := db.DB("").Model(&model.MMLSubscriber{})
|
||||||
|
// 查询条件拼接
|
||||||
|
if v, ok := query["neType"]; ok && v != "" {
|
||||||
|
tx = tx.Where("ne_type = ?", v)
|
||||||
|
}
|
||||||
|
if v, ok := query["status"]; ok && v != "" {
|
||||||
|
tx = tx.Where("status = ?", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询结果
|
||||||
|
var total int64 = 0
|
||||||
|
rows := []model.MMLSubscriber{}
|
||||||
|
|
||||||
|
// 查询数量为0直接返回
|
||||||
|
if err := tx.Count(&total).Error; err != nil || total <= 0 {
|
||||||
|
return rows, total
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询数据分页
|
||||||
|
pageNum, pageSize := db.PageNumSize(query["pageNum"], query["pageSize"])
|
||||||
|
tx = tx.Limit(pageSize).Offset(pageSize * pageNum)
|
||||||
|
err := tx.Find(&rows).Error
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("query find err => %v", err.Error())
|
||||||
|
return rows, total
|
||||||
|
}
|
||||||
|
return rows, total
|
||||||
|
}
|
||||||
44
src/modules/tool/repository/mml_system.go
Normal file
44
src/modules/tool/repository/mml_system.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"be.ems/src/framework/database/db"
|
||||||
|
"be.ems/src/framework/logger"
|
||||||
|
"be.ems/src/modules/tool/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化数据层 MMLSystem 结构体
|
||||||
|
var NewMMLSystem = &MMLSystem{}
|
||||||
|
|
||||||
|
// MMLSystem MML网元命令 数据层处理
|
||||||
|
type MMLSystem struct{}
|
||||||
|
|
||||||
|
// SelectByPage 分页查询集合
|
||||||
|
func (r MMLSystem) SelectByPage(query map[string]string) ([]model.MMLSystem, int64) {
|
||||||
|
tx := db.DB("").Model(&model.MMLSystem{})
|
||||||
|
// 查询条件拼接
|
||||||
|
if v, ok := query["neType"]; ok && v != "" {
|
||||||
|
tx = tx.Where("ne_type = ?", v)
|
||||||
|
}
|
||||||
|
if v, ok := query["status"]; ok && v != "" {
|
||||||
|
tx = tx.Where("status = ?", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询结果
|
||||||
|
var total int64 = 0
|
||||||
|
rows := []model.MMLSystem{}
|
||||||
|
|
||||||
|
// 查询数量为0直接返回
|
||||||
|
if err := tx.Count(&total).Error; err != nil || total <= 0 {
|
||||||
|
return rows, total
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询数据分页
|
||||||
|
pageNum, pageSize := db.PageNumSize(query["pageNum"], query["pageSize"])
|
||||||
|
tx = tx.Limit(pageSize).Offset(pageSize * pageNum)
|
||||||
|
err := tx.Find(&rows).Error
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("query find err => %v", err.Error())
|
||||||
|
return rows, total
|
||||||
|
}
|
||||||
|
return rows, total
|
||||||
|
}
|
||||||
21
src/modules/tool/service/mml_subscriber.go
Normal file
21
src/modules/tool/service/mml_subscriber.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"be.ems/src/modules/tool/model"
|
||||||
|
"be.ems/src/modules/tool/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化数据层 MMLSubscriber 结构体
|
||||||
|
var NewMMLSubscriber = &MMLSubscriber{
|
||||||
|
mmlSubscriberRepository: repository.NewMMLSubscriber,
|
||||||
|
}
|
||||||
|
|
||||||
|
// MMLSubscriber MML网元命令 服务层处理
|
||||||
|
type MMLSubscriber struct {
|
||||||
|
mmlSubscriberRepository *repository.MMLSubscriber
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindByPage 分页查询列表数据
|
||||||
|
func (s MMLSubscriber) FindByPage(query map[string]string) ([]model.MMLSubscriber, int64) {
|
||||||
|
return s.mmlSubscriberRepository.SelectByPage(query)
|
||||||
|
}
|
||||||
21
src/modules/tool/service/mml_system.go
Normal file
21
src/modules/tool/service/mml_system.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"be.ems/src/modules/tool/model"
|
||||||
|
"be.ems/src/modules/tool/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化数据层 MMLSystem 结构体
|
||||||
|
var NewMMLSystem = &MMLSystem{
|
||||||
|
mmlSystemRepository: repository.NewMMLSystem,
|
||||||
|
}
|
||||||
|
|
||||||
|
// MMLSystem MML网元命令 服务层处理
|
||||||
|
type MMLSystem struct {
|
||||||
|
mmlSystemRepository *repository.MMLSystem
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindByPage 分页查询列表数据
|
||||||
|
func (s MMLSystem) FindByPage(query map[string]string) ([]model.MMLSystem, int64) {
|
||||||
|
return s.mmlSystemRepository.SelectByPage(query)
|
||||||
|
}
|
||||||
@@ -54,4 +54,23 @@ func Setup(router *gin.Engine) {
|
|||||||
controller.NewPing.Run,
|
controller.NewPing.Run,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MML 网元MML
|
||||||
|
mml := controller.NewMML
|
||||||
|
mmlGroup := router.Group("/tool/mml")
|
||||||
|
{
|
||||||
|
mmlGroup.GET("/system/list",
|
||||||
|
middleware.AuthorizeUser(nil),
|
||||||
|
mml.SystemList,
|
||||||
|
)
|
||||||
|
mmlGroup.GET("/subscriber/list",
|
||||||
|
middleware.AuthorizeUser(nil),
|
||||||
|
mml.SubscriberList,
|
||||||
|
)
|
||||||
|
mmlGroup.POST("/command",
|
||||||
|
middleware.AuthorizeUser(nil),
|
||||||
|
mml.Command,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user