feat: MML日志记录功能接口

This commit is contained in:
TsMask
2025-08-05 17:31:31 +08:00
parent 0698f02c61
commit 96b15d4cf2
9 changed files with 186 additions and 38 deletions

View File

@@ -4,13 +4,14 @@ import (
"fmt"
"strings"
"github.com/gin-gonic/gin"
"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/model"
"be.ems/src/modules/tool/service"
"github.com/gin-gonic/gin"
)
// 实例化控制层 MMLController 结构体
@@ -18,6 +19,7 @@ var NewMML = &MMLController{
neInfoService: neService.NewNeInfo,
mmlSystemService: service.NewMMLSystem,
mmlSubscriberService: service.NewMMLSubscriber,
mmlLogService: service.NewMMLLog,
}
// MML 网元MML
@@ -27,6 +29,7 @@ type MMLController struct {
neInfoService *neService.NeInfo // 网元信息服务
mmlSystemService *service.MMLSystem
mmlSubscriberService *service.MMLSubscriber
mmlLogService *service.MMLLog
}
// SystemList MML网元列表
@@ -47,6 +50,15 @@ func (s MMLController) SubscriberList(c *gin.Context) {
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// LogList MML日志列表
//
// GET /log/list
func (s MMLController) LogList(c *gin.Context) {
query := reqctx.QueryMap(c)
rows, total := s.mmlLogService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// Command MML命令执行
//
// POST /command
@@ -89,6 +101,7 @@ func (s MMLController) Command(c *gin.Context) {
}
// 发送MML
result := []string{}
resultStr := "Success"
for _, v := range body.Command {
if v == "" {
continue
@@ -96,9 +109,21 @@ func (s MMLController) Command(c *gin.Context) {
output, err := telnetClient.RunCMD(v + "\r\n")
if err != nil {
result = append(result, err.Error())
resultStr = "there is an error"
continue
}
result = append(result, strings.TrimSpace(output))
}
// 记录日志
mmlLog := model.MMLLog{
NeType: body.NeType,
NeId: body.NeId,
User: reqctx.LoginUserToUserName(c),
Ip: c.ClientIP(),
Command: strings.Join(body.Command, ";"),
Result: resultStr,
}
s.mmlLogService.Insert(mmlLog)
c.JSON(200, resp.OkData(result))
}