feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
traceService "be.ems/src/modules/trace/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 PacketController 结构体
|
||||
@@ -26,85 +28,89 @@ type PacketController struct {
|
||||
// GET /devices
|
||||
func (s *PacketController) Devices(c *gin.Context) {
|
||||
data := s.packetService.NetworkDevices()
|
||||
c.JSON(200, result.OkData(data))
|
||||
c.JSON(200, resp.OkData(data))
|
||||
}
|
||||
|
||||
// 信令跟踪开始
|
||||
//
|
||||
// POST /start
|
||||
func (s *PacketController) Start(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
TaskNo string `json:"taskNo" binding:"required"` // 任务编号
|
||||
Device string `json:"device" binding:"required"` // 网卡设备
|
||||
Filter string `json:"filter" ` // 过滤表达式(port 33030 or 33040)
|
||||
OutputPCAP bool `json:"outputPCAP" ` // 输出PCAP文件 (默认false)
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
msg, err := s.packetService.LiveStart(body.TaskNo, body.Device, body.Filter, body.OutputPCAP)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(msg))
|
||||
c.JSON(200, resp.OkData(msg))
|
||||
}
|
||||
|
||||
// 信令跟踪结束
|
||||
//
|
||||
// POST /stop
|
||||
func (s *PacketController) Stop(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
TaskNo string `json:"taskNo" binding:"required"` // 任务编号
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.packetService.LiveStop(body.TaskNo); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 信令跟踪过滤
|
||||
//
|
||||
// PUT /filter
|
||||
func (s *PacketController) Filter(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
TaskNo string `json:"taskNo" binding:"required"` // 任务编号
|
||||
Expr string `json:"expr" ` // 过滤表达式(port 33030 or 33040)
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.packetService.LiveFilter(body.TaskNo, body.Expr); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 信令跟踪续期保活
|
||||
//
|
||||
// PUT /keep-alive
|
||||
func (s *PacketController) KeepAlive(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
TaskNo string `json:"taskNo" binding:"required"` // 任务编号
|
||||
Duration int `json:"duration" ` // 服务失效的时间,默认设置为120秒
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -114,8 +120,8 @@ func (s *PacketController) KeepAlive(c *gin.Context) {
|
||||
}
|
||||
|
||||
if err := s.packetService.LiveTimeout(body.TaskNo, body.Duration); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
traceService "be.ems/src/modules/trace/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -35,7 +37,7 @@ type TCPdumpController struct {
|
||||
// @Description Network Element Capture Packet PACP Start
|
||||
// @Router /trace/tcpdump/start [post]
|
||||
func (s *TCPdumpController) DumpStart(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"` // 网元类型
|
||||
NeId string `json:"neId" binding:"required"` // 网元ID
|
||||
@@ -43,16 +45,17 @@ func (s *TCPdumpController) DumpStart(c *gin.Context) {
|
||||
}
|
||||
err := c.ShouldBindBodyWithJSON(&body)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
taskCode, err := s.tcpdumpService.DumpStart(body.NeType, body.NeId, body.Cmd)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(taskCode))
|
||||
c.JSON(200, resp.OkData(taskCode))
|
||||
}
|
||||
|
||||
// 网元抓包PACP 结束
|
||||
@@ -69,7 +72,7 @@ func (s *TCPdumpController) DumpStart(c *gin.Context) {
|
||||
// @Description Network Element Capture Packet PACP Stop
|
||||
// @Router /trace/tcpdump/stop [post]
|
||||
func (s *TCPdumpController) DumpStop(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"` // 网元类型
|
||||
NeId string `json:"neId" binding:"required"` // 网元ID
|
||||
@@ -77,16 +80,17 @@ func (s *TCPdumpController) DumpStop(c *gin.Context) {
|
||||
}
|
||||
err := c.ShouldBindBodyWithJSON(&body)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
logFiles, err := s.tcpdumpService.DumpStop(body.NeType, body.NeId, body.TaskCode)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(logFiles))
|
||||
c.JSON(200, resp.OkData(logFiles))
|
||||
}
|
||||
|
||||
// UPF标准版内部抓包
|
||||
@@ -103,7 +107,7 @@ func (s *TCPdumpController) DumpStop(c *gin.Context) {
|
||||
// @Description UPF Standard Edition Internal Grab Bag
|
||||
// @Router /trace/tcpdump/upf [post]
|
||||
func (s *TCPdumpController) UPFTrace(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"` // 网元类型
|
||||
NeId string `json:"neId" binding:"required"` // 网元ID
|
||||
@@ -111,14 +115,15 @@ func (s *TCPdumpController) UPFTrace(c *gin.Context) {
|
||||
}
|
||||
err := c.ShouldBindBodyWithJSON(&body)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
msg, err := s.tcpdumpService.UPFTrace(body.NeType, body.NeId, body.Cmd)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(msg))
|
||||
c.JSON(200, resp.OkData(msg))
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
traceService "be.ems/src/modules/trace/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -20,43 +19,42 @@ var NewTraceData = &TraceDataController{
|
||||
//
|
||||
// PATH /data
|
||||
type TraceDataController struct {
|
||||
// 跟踪_数据信息服务
|
||||
traceDataService *traceService.TraceData
|
||||
traceDataService *traceService.TraceData // 跟踪_数据信息服务
|
||||
}
|
||||
|
||||
// 跟踪任务数据列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *TraceDataController) List(c *gin.Context) {
|
||||
query := ctx.QueryMap(c)
|
||||
|
||||
// 查询数据
|
||||
data := s.traceDataService.SelectPage(query)
|
||||
c.JSON(200, result.Ok(data))
|
||||
query := reqctx.QueryMap(c)
|
||||
rows, total := s.traceDataService.FindByPage(query)
|
||||
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
|
||||
}
|
||||
|
||||
// 跟踪任务数据删除
|
||||
//
|
||||
// DELETE /:ids
|
||||
// DELETE /:id
|
||||
func (s *TraceDataController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
rowIds := c.Param("ids")
|
||||
if rowIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
id := c.Param("id")
|
||||
if id == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(rowIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
|
||||
// 转换成int64数组类型
|
||||
ids := make([]int64, 0)
|
||||
for _, v := range uniqueIDs {
|
||||
ids = append(ids, parse.Number(v))
|
||||
}
|
||||
rows, err := s.traceDataService.DeleteByIds(uniqueIDs)
|
||||
|
||||
rows, err := s.traceDataService.DeleteByIds(ids)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
c.JSON(200, resp.OkMsg(msg))
|
||||
}
|
||||
|
||||
@@ -4,16 +4,15 @@ import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/modules/trace/model"
|
||||
traceService "be.ems/src/modules/trace/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 TraceTaskController 结构体
|
||||
@@ -33,116 +32,125 @@ type TraceTaskController struct {
|
||||
//
|
||||
// GET /list
|
||||
func (s *TraceTaskController) List(c *gin.Context) {
|
||||
query := ctx.QueryMap(c)
|
||||
|
||||
// 查询数据
|
||||
data := s.traceTaskService.SelectPage(query)
|
||||
c.JSON(200, result.Ok(data))
|
||||
query := reqctx.QueryMap(c)
|
||||
rows, total := s.traceTaskService.FindByPage(query)
|
||||
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
|
||||
}
|
||||
|
||||
// 跟踪任务信息
|
||||
//
|
||||
// GET /:id
|
||||
func (s *TraceTaskController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
id := c.Param("id")
|
||||
if id == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
id := parse.Number(c.Param("id"))
|
||||
if id <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
data := s.traceTaskService.SelectById(id)
|
||||
data := s.traceTaskService.FindById(id)
|
||||
if data.ID == id {
|
||||
c.JSON(200, result.OkData(data))
|
||||
c.JSON(200, resp.OkData(data))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 跟踪任务新增
|
||||
//
|
||||
// POST /
|
||||
func (s *TraceTaskController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body model.TraceTask
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID != "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
err := c.ShouldBindBodyWithJSON(&body)
|
||||
if err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.ID > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id not is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
body.CreateBy = reqctx.LoginUserToUserName(c)
|
||||
if err = s.traceTaskService.Insert(body); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 跟踪任务修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *TraceTaskController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body model.TraceTask
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
err := c.ShouldBindBodyWithJSON(&body)
|
||||
if err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.ID == 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
taskInfo := s.traceTaskService.SelectById(body.ID)
|
||||
taskInfo := s.traceTaskService.FindById(body.ID)
|
||||
if taskInfo.ID != body.ID {
|
||||
// 没有可访问任务信息数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "task.noData")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "task.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
body.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
if err = s.traceTaskService.Update(body); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 跟踪任务删除
|
||||
//
|
||||
// DELETE /:ids
|
||||
// DELETE /:id
|
||||
func (s *TraceTaskController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
rowIds := c.Param("ids")
|
||||
if rowIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
id := c.Param("id")
|
||||
if id == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(rowIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
|
||||
// 转换成int64数组类型
|
||||
ids := make([]int64, 0)
|
||||
for _, v := range uniqueIDs {
|
||||
ids = append(ids, parse.Number(v))
|
||||
}
|
||||
rows, err := s.traceTaskService.DeleteByIds(uniqueIDs)
|
||||
|
||||
rows, err := s.traceTaskService.DeleteByIds(ids)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
c.JSON(200, resp.OkMsg(msg))
|
||||
}
|
||||
|
||||
// 跟踪任务文件
|
||||
//
|
||||
// GET /filePull
|
||||
func (s *TraceTaskController) FilePull(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
TraceId string `form:"traceId" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -5,18 +5,17 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/utils/generate"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"be.ems/src/modules/trace/model"
|
||||
traceService "be.ems/src/modules/trace/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 TraceTaskHlrController 结构体
|
||||
@@ -37,49 +36,50 @@ type TraceTaskHlrController struct {
|
||||
//
|
||||
// GET /list
|
||||
func (s *TraceTaskHlrController) List(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys model.TraceTaskHlrQuery
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var query model.TraceTaskHlrQuery
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
data := s.traceTaskHlrService.SelectPage(querys)
|
||||
c.JSON(200, result.Ok(data))
|
||||
rows, total := s.traceTaskHlrService.FindByPage(query)
|
||||
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
|
||||
}
|
||||
|
||||
// 跟踪任务删除
|
||||
//
|
||||
// DELETE /:ids
|
||||
// DELETE /:id
|
||||
func (s *TraceTaskHlrController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
rowIds := c.Param("ids")
|
||||
if rowIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
id := c.Param("id")
|
||||
if id == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(rowIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
|
||||
// 转换成int64数组类型
|
||||
ids := make([]int64, 0)
|
||||
for _, v := range uniqueIDs {
|
||||
ids = append(ids, parse.Number(v))
|
||||
}
|
||||
rows, err := s.traceTaskHlrService.DeleteByIds(uniqueIDs)
|
||||
|
||||
rows, err := s.traceTaskHlrService.DeleteByIds(ids)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
c.JSON(200, resp.OkMsg(msg))
|
||||
}
|
||||
|
||||
// 跟踪任务创建
|
||||
//
|
||||
// POST /start
|
||||
func (s *TraceTaskHlrController) Start(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
IMSI string `json:"imsi"` // IMSI
|
||||
MSISDN string `json:"msisdn"` // MSISDN
|
||||
@@ -87,13 +87,13 @@ func (s *TraceTaskHlrController) Start(c *gin.Context) {
|
||||
EndTime int64 `json:"endTime"` // 结束时间
|
||||
Remark string `json:"remark"` // 备注说明
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
if body.IMSI == "" && body.MSISDN == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "imsi amd msisdn is empty"))
|
||||
c.JSON(400, resp.CodeMsg(400, "imsi amd msisdn is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -103,88 +103,88 @@ func (s *TraceTaskHlrController) Start(c *gin.Context) {
|
||||
StartTime: body.StartTime,
|
||||
EndTime: body.EndTime,
|
||||
Remark: body.Remark,
|
||||
CreateBy: ctx.LoginUserToUserName(c),
|
||||
CreateBy: reqctx.LoginUserToUserName(c),
|
||||
}
|
||||
id, err := s.traceTaskHlrService.Start(task)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(id))
|
||||
c.JSON(200, resp.OkData(id))
|
||||
}
|
||||
|
||||
// 跟踪任务停止
|
||||
//
|
||||
// POST /stop
|
||||
func (s *TraceTaskHlrController) Stop(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
ID string `json:"id" binding:"required"` // 任务ID
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(body.ID, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
uniqueIDs := parse.RemoveDuplicatesToArray(body.ID, ",")
|
||||
// 转换成int64数组类型
|
||||
ids := make([]int64, 0)
|
||||
for _, v := range uniqueIDs {
|
||||
ids = append(ids, parse.Number(v))
|
||||
}
|
||||
|
||||
errArr := []map[string]any{}
|
||||
for _, id := range uniqueIDs {
|
||||
task := s.traceTaskHlrService.SelectById(id)
|
||||
if task.ID != id || task.ID == "" {
|
||||
for _, id := range ids {
|
||||
task := s.traceTaskHlrService.FindById(id)
|
||||
if task.ID == 0 || task.ID != id {
|
||||
errArr = append(errArr, map[string]any{"id": id, "err": "task not found"})
|
||||
continue
|
||||
}
|
||||
|
||||
task.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
task.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
err := s.traceTaskHlrService.Stop(task)
|
||||
if err != nil {
|
||||
errArr = append(errArr, map[string]any{"id": id, "err": err.Error()})
|
||||
continue
|
||||
}
|
||||
}
|
||||
c.JSON(200, result.OkData(errArr))
|
||||
c.JSON(200, resp.OkData(errArr))
|
||||
}
|
||||
|
||||
// 跟踪任务文件
|
||||
//
|
||||
// POST /file
|
||||
func (s *TraceTaskHlrController) File(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
ID string `json:"id" binding:"required"` // 任务ID
|
||||
ID int64 `json:"id" binding:"required"` // 任务ID
|
||||
Dir string `json:"dir" binding:"required"` // 网元文件目录
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
task := s.traceTaskHlrService.SelectById(body.ID)
|
||||
if task.ID != body.ID || task.ID == "" {
|
||||
c.JSON(200, result.CodeMsg(400, "task not found"))
|
||||
task := s.traceTaskHlrService.FindById(body.ID)
|
||||
if task.ID == 0 || task.ID != body.ID {
|
||||
c.JSON(200, resp.CodeMsg(400, "task not found"))
|
||||
return
|
||||
}
|
||||
|
||||
list, err := s.traceTaskHlrService.File(task.TraceId, body.Dir)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(list))
|
||||
c.JSON(200, resp.OkData(list))
|
||||
}
|
||||
|
||||
// 跟踪任务文件从网元到本地
|
||||
//
|
||||
// GET /filePull
|
||||
func (s *TraceTaskHlrController) FilePull(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"`
|
||||
NeID string `form:"neId" binding:"required"`
|
||||
@@ -193,28 +193,29 @@ func (s *TraceTaskHlrController) FilePull(c *gin.Context) {
|
||||
DelTemp bool `form:"delTemp"` // 删除本地临时文件
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
|
||||
neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
|
||||
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
defer sshClient.Close()
|
||||
// 网元主机的SSH客户端进行文件传输
|
||||
sftpClient, err := sshClient.NewClientSFTP()
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
defer sftpClient.Close()
|
||||
@@ -227,7 +228,7 @@ func (s *TraceTaskHlrController) FilePull(c *gin.Context) {
|
||||
}
|
||||
// 复制到本地
|
||||
if err = sftpClient.CopyFileRemoteToLocal(nePath, localFilePath); err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user