diff --git a/src/modules/network_element/controller/action.go b/src/modules/network_element/controller/action.go index 14273c8f..d27da954 100644 --- a/src/modules/network_element/controller/action.go +++ b/src/modules/network_element/controller/action.go @@ -10,11 +10,11 @@ import ( "github.com/gin-gonic/gin" "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/ssh" "be.ems/src/framework/utils/file" "be.ems/src/framework/utils/generate" - "be.ems/src/framework/utils/ssh" - "be.ems/src/framework/vo/result" neService "be.ems/src/modules/network_element/service" ) @@ -45,7 +45,7 @@ type NeActionController struct { // @Description Sending files from local to network elements // @Router /ne/action/pushFile [post] func (s *NeActionController) PushFile(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"` @@ -53,28 +53,29 @@ func (s *NeActionController) PushFile(c *gin.Context) { DelTemp bool `json:"delTemp"` // 删除本地临时文件 } if err := c.ShouldBindBodyWithJSON(&body); 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(resp.CODE_PARAM_PARSER, errMsgs)) return } // 查询网元获取IP - neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID) + neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeID) if neInfo.NeId != body.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() @@ -82,11 +83,11 @@ func (s *NeActionController) PushFile(c *gin.Context) { // 本地文件 localFilePath := file.ParseUploadFilePath(body.UploadPath) // 网元端临时目录 - sshClient.RunCMD("mkdir -p /tmp/omc/push && sudo chmod 777 -R /tmp/omc") + sshClient.RunCMD("sudo mkdir -p /tmp/omc/push && sudo chmod 755 -R /tmp/omc") neFilePath := filepath.ToSlash(filepath.Join("/tmp/omc/push", filepath.Base(localFilePath))) // 复制到远程 if err = sftpClient.CopyFileLocalToRemote(localFilePath, neFilePath); err != nil { - c.JSON(200, result.ErrMsg("Please check if the file exists or if scp is allowed to copy remotely")) + c.JSON(200, resp.ErrMsg("Please check if the file exists or if scp is allowed to copy remotely")) return } @@ -95,7 +96,7 @@ func (s *NeActionController) PushFile(c *gin.Context) { _ = os.Remove(localFilePath) } }() - c.JSON(200, result.OkData(filepath.ToSlash(neFilePath))) + c.JSON(200, resp.OkData(filepath.ToSlash(neFilePath))) } // 从网元到本地获取文件 @@ -105,7 +106,7 @@ func (s *NeActionController) PushFile(c *gin.Context) { // @Tags network_element/action // @Accept json // @Produce json -// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF) +// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF) // @Param neId query string true "NE ID" default(001) // @Param path query string true "dir path" default(/var/log) // @Param fileName query string true "file name" @@ -116,7 +117,7 @@ func (s *NeActionController) PushFile(c *gin.Context) { // @Description Getting files from the network element to the local // @Router /ne/action/pullFile [get] func (s *NeActionController) PullFile(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"` @@ -125,28 +126,29 @@ func (s *NeActionController) PullFile(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(resp.CODE_PARAM_PARSER, 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() @@ -159,7 +161,7 @@ func (s *NeActionController) PullFile(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 } @@ -178,7 +180,7 @@ func (s *NeActionController) PullFile(c *gin.Context) { // @Tags network_element/action // @Accept json // @Produce json -// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF) +// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF) // @Param neId query string true "NE ID" default(001) // @Param path query string true "dir path" default(/var/log) // @Param delTemp query boolean false "Delete Temp File" default(false) @@ -188,7 +190,7 @@ func (s *NeActionController) PullFile(c *gin.Context) { // @Description Get directories compressed to ZIP from the network element to the local area // @Router /ne/action/pullDirZip [get] func (s *NeActionController) PullDirZip(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"` @@ -196,28 +198,29 @@ func (s *NeActionController) PullDirZip(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(resp.CODE_PARAM_PARSER, 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() @@ -231,7 +234,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) { // 复制到本地 localDirFilePath := filepath.Join(localFilePath, "zip") if err = sftpClient.CopyDirRemoteToLocal(nePath, localDirFilePath); err != nil { - c.JSON(200, result.ErrMsg(err.Error())) + c.JSON(200, resp.ErrMsg(err.Error())) return } @@ -239,7 +242,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) { zipFileName := fmt.Sprintf("%s-%s-%s.zip", neInfo.NeType, neInfo.NeId, dirName) zipFilePath := filepath.Join(localFilePath, zipFileName) if err := file.CompressZipByDir(zipFilePath, localDirFilePath); err != nil { - c.JSON(200, result.ErrMsg(err.Error())) + c.JSON(200, resp.ErrMsg(err.Error())) return } @@ -258,7 +261,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) { // @Tags network_element/action // @Accept json // @Produce json -// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF) +// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF) // @Param neId query string true "NE ID" default(001) // @Param path query string true "file path" default(/var/log) // @Param fileName query string true "file name" @@ -268,7 +271,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) { // @Description Viewing the contents of a file on the network element side // @Router /ne/action/viewFile [get] func (s *NeActionController) ViewFile(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"` @@ -276,21 +279,22 @@ func (s *NeActionController) ViewFile(c *gin.Context) { FileName string `form:"fileName" binding:"required"` } 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(resp.CODE_PARAM_PARSER, 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() @@ -301,10 +305,10 @@ func (s *NeActionController) ViewFile(c *gin.Context) { output, err := sshClient.RunCMD(fmt.Sprintf("cat %s", nePath)) output = strings.TrimSpace(output) if err != nil || strings.HasPrefix(output, "ls: ") { - c.JSON(200, result.ErrMsg(i18n.TKey(language, "file view cat error"))) + c.JSON(200, resp.ErrMsg(i18n.TKey(language, "file view cat error"))) return } - c.JSON(200, result.OkData(output)) + c.JSON(200, resp.OkData(output)) } // 网元端文件列表 @@ -314,7 +318,7 @@ func (s *NeActionController) ViewFile(c *gin.Context) { // @Tags network_element/action // @Accept json // @Produce json -// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF) +// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF) // @Param neId query string true "NE ID" default(001) // @Param path query string true "file path" default(/var/log) // @Param pageNum query number true "pageNum" default(1) @@ -326,7 +330,7 @@ func (s *NeActionController) ViewFile(c *gin.Context) { // @Description List of files on the network element side // @Router /ne/action/files [get] func (s *NeActionController) Files(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"` @@ -336,21 +340,22 @@ func (s *NeActionController) Files(c *gin.Context) { Search string `form:"search"` } 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(resp.CODE_PARAM_PARSER, 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() @@ -358,7 +363,7 @@ func (s *NeActionController) Files(c *gin.Context) { // 获取文件列表 rows, err := ssh.FileList(sshClient, querys.Path, querys.Search) if err != nil { - c.JSON(200, result.Ok(map[string]any{ + c.JSON(200, resp.OkData(map[string]any{ "path": querys.Path, "total": len(rows), "rows": []ssh.FileListRow{}, @@ -379,7 +384,7 @@ func (s *NeActionController) Files(c *gin.Context) { splitRows = rows[start:end] } - c.JSON(200, result.Ok(map[string]any{ + c.JSON(200, resp.OkData(map[string]any{ "path": querys.Path, "total": lenNum, "rows": splitRows, @@ -400,21 +405,22 @@ func (s *NeActionController) Files(c *gin.Context) { // @Description Network element service operation // @Router /ne/action/service [put] func (s *NeActionController) Service(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"` Action string `json:"action" binding:"required,oneof=start restart stop reboot poweroff"` // 操作行为 } if err := c.ShouldBindBodyWithJSON(&body); 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(resp.CODE_PARAM_PARSER, errMsgs)) return } // 查询网元获取IP - neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID) + neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeID) if neInfo.NeId != body.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 } @@ -439,8 +445,8 @@ func (s *NeActionController) Service(c *gin.Context) { _, err := s.neInfoService.NeRunSSHCmd(body.NeType, body.NeID, cmdStr) if err != nil { - c.JSON(200, result.ErrMsg(err.Error())) + c.JSON(200, resp.ErrMsg(err.Error())) return } - c.JSON(200, result.Ok(nil)) + c.JSON(200, resp.Ok(nil)) } diff --git a/src/modules/network_element/service/ne_config_backup.go b/src/modules/network_element/service/ne_config_backup.go index 80cfffb9..f42bea5c 100644 --- a/src/modules/network_element/service/ne_config_backup.go +++ b/src/modules/network_element/service/ne_config_backup.go @@ -75,7 +75,7 @@ func (r *NeConfigBackup) DeleteByIds(ids []string) (int64, error) { func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string) error { neTypeLower := strings.ToLower(neInfo.NeType) // 网管本地路径 - omcPath := "/usr/local/etc/omc/ne_config" + omcPath := "/usr/local/omc/backup/ne_config" if runtime.GOOS == "windows" { omcPath = fmt.Sprintf("C:%s", omcPath) } @@ -99,7 +99,7 @@ func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string // 网元配置端上的临时目录 neDirTemp := fmt.Sprintf("/tmp/omc/ne_config/%s/%s", neTypeLower, neInfo.NeId) - sshClient.RunCMD(fmt.Sprintf("mkdir -p /tmp/omc && sudo chmod 777 -R /tmp/omc && sudo rm -rf %s", neDirTemp)) + sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p /tmp/omc/ne_config && sudo chmod 755 -R /tmp/omc && sudo rm -rf %s", neDirTemp)) // 复制到网元端 if err = sftpClient.CopyDirLocalToRemote(localDirPath, neDirTemp); err != nil { return fmt.Errorf("copy config to ne err") @@ -154,14 +154,14 @@ func (r *NeConfigBackup) NeConfigNeToLocal(neInfo model.NeInfo) (string, error) neTypeLower := strings.ToLower(neInfo.NeType) // 网管本地路径 - omcPath := "/usr/local/etc/omc/ne_config" + omcPath := "/usr/local/omc/backup/ne_config" if runtime.GOOS == "windows" { omcPath = fmt.Sprintf("C:%s", omcPath) } - localDirPath := fmt.Sprintf("%s/%s/%s/backup/tmp_export", omcPath, neTypeLower, neInfo.NeId) + localDirPath := fmt.Sprintf("%s/%s/%s/from_ne_tmp", omcPath, neTypeLower, neInfo.NeId) // 网元配置文件先复制到临时目录 - sshClient.RunCMD("mkdir -p /tmp/omc && sudo chmod 777 -R /tmp/omc") + sshClient.RunCMD("sudo mkdir -p /tmp/omc/ne_config && sudo chmod 755 -R /tmp/omc") neDirTemp := fmt.Sprintf("/tmp/omc/ne_config/%s/%s", neTypeLower, neInfo.NeId) if neTypeLower == "ims" { // ims目录 @@ -196,7 +196,7 @@ func (r *NeConfigBackup) NeConfigNeToLocal(neInfo model.NeInfo) (string, error) // 压缩zip文件名 zipFileName := fmt.Sprintf("%s-%s-etc-%s.zip", neTypeLower, neInfo.NeId, date.ParseDateToStr(time.Now(), date.YYYYMMDDHHMMSS)) - zipFilePath := fmt.Sprintf("%s/%s/%s/backup/%s", omcPath, neTypeLower, neInfo.NeId, zipFileName) + zipFilePath := fmt.Sprintf("%s/%s/%s/%s", omcPath, neTypeLower, neInfo.NeId, zipFileName) if err := file.CompressZipByDir(zipFilePath, localDirPath); err != nil { return "", fmt.Errorf("compress zip err") } diff --git a/src/modules/trace/controller/packet.go b/src/modules/trace/controller/packet.go index 2fb07ee9..9978d520 100644 --- a/src/modules/trace/controller/packet.go +++ b/src/modules/trace/controller/packet.go @@ -46,7 +46,7 @@ func (s *PacketController) Start(c *gin.Context) { } if err := c.ShouldBindBodyWithJSON(&body); err != nil { errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) - c.JSON(422, resp.CodeMsg(40422, errMsgs)) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs)) return } @@ -68,7 +68,7 @@ func (s *PacketController) Stop(c *gin.Context) { } if err := c.ShouldBindBodyWithJSON(&body); err != nil { errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) - c.JSON(422, resp.CodeMsg(40422, errMsgs)) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs)) return } @@ -90,7 +90,7 @@ func (s *PacketController) Filter(c *gin.Context) { } if err := c.ShouldBindBodyWithJSON(&body); err != nil { errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) - c.JSON(422, resp.CodeMsg(40422, errMsgs)) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs)) return } @@ -112,7 +112,7 @@ func (s *PacketController) KeepAlive(c *gin.Context) { } if err := c.ShouldBindBodyWithJSON(&body); err != nil { errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) - c.JSON(422, resp.CodeMsg(40422, errMsgs)) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs)) return } @@ -137,11 +137,11 @@ func (s *PacketController) FilePull(c *gin.Context) { } if err := c.ShouldBindQuery(&querys); err != nil { errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) - c.JSON(422, resp.CodeMsg(40422, errMsgs)) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs)) return } fileName := fmt.Sprintf("%s.pcap", querys.TaskNo) - localFilePath := filepath.Join("/tmp/omc/packet", fileName) + localFilePath := filepath.Join("/usr/local/omc/packet", fileName) if runtime.GOOS == "windows" { localFilePath = fmt.Sprintf("C:%s", localFilePath) } diff --git a/src/modules/trace/controller/trace_task_hlr.go b/src/modules/trace/controller/trace_task_hlr.go index 53b5e33a..5bd30031 100644 --- a/src/modules/trace/controller/trace_task_hlr.go +++ b/src/modules/trace/controller/trace_task_hlr.go @@ -36,10 +36,10 @@ type TraceTaskHlrController struct { // // GET /list func (s *TraceTaskHlrController) List(c *gin.Context) { - 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"))) + errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs)) return } @@ -54,7 +54,7 @@ func (s *TraceTaskHlrController) Remove(c *gin.Context) { language := reqctx.AcceptLanguage(c) id := c.Param("id") if id == "" { - c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty")) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: id is empty")) return } @@ -79,7 +79,6 @@ func (s *TraceTaskHlrController) Remove(c *gin.Context) { // // POST /start func (s *TraceTaskHlrController) Start(c *gin.Context) { - language := reqctx.AcceptLanguage(c) var body struct { IMSI string `json:"imsi"` // IMSI MSISDN string `json:"msisdn"` // MSISDN @@ -88,12 +87,13 @@ func (s *TraceTaskHlrController) Start(c *gin.Context) { Remark string `json:"remark"` // 备注说明 } if err := c.ShouldBindBodyWithJSON(&body); err != nil { - c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) + errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs)) return } if body.IMSI == "" && body.MSISDN == "" { - c.JSON(400, resp.CodeMsg(400, "imsi amd msisdn is empty")) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "imsi amd msisdn is empty")) return } @@ -117,12 +117,12 @@ func (s *TraceTaskHlrController) Start(c *gin.Context) { // // POST /stop func (s *TraceTaskHlrController) Stop(c *gin.Context) { - language := reqctx.AcceptLanguage(c) var body struct { ID string `json:"id" binding:"required"` // 任务ID } if err := c.ShouldBindBodyWithJSON(&body); err != nil { - c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) + errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs)) return } @@ -162,13 +162,13 @@ func (s *TraceTaskHlrController) File(c *gin.Context) { } if err := c.ShouldBindBodyWithJSON(&body); err != nil { errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) - c.JSON(422, resp.CodeMsg(40422, errMsgs)) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs)) return } task := s.traceTaskHlrService.FindById(body.ID) if task.ID == 0 || task.ID != body.ID { - c.JSON(200, resp.CodeMsg(400, "task not found")) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "task not found")) return } @@ -194,14 +194,14 @@ func (s *TraceTaskHlrController) FilePull(c *gin.Context) { } if err := c.ShouldBindQuery(&querys); err != nil { errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) - c.JSON(422, resp.CodeMsg(40422, errMsgs)) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, 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, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo"))) + c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, i18n.TKey(language, "app.common.noNEInfo"))) return } diff --git a/src/modules/trace/service/packet.go b/src/modules/trace/service/packet.go index 4c705374..eea0fd19 100644 --- a/src/modules/trace/service/packet.go +++ b/src/modules/trace/service/packet.go @@ -119,7 +119,7 @@ func (s *Packet) LiveStart(taskNo, deviceName, filterBPF string, outputPCAP bool var f *os.File if outputPCAP { // 网管本地路径 - localFilePath := fmt.Sprintf("/tmp/omc/packet/%s.pcap", taskNo) + localFilePath := fmt.Sprintf("/usr/local/omc/packet/%s.pcap", taskNo) if runtime.GOOS == "windows" { localFilePath = fmt.Sprintf("C:%s", localFilePath) } @@ -203,7 +203,9 @@ func (s *Packet) capturePacketSource(taskInfo *Task) { if packet == nil { continue } - if packet.Metadata().Timestamp.Before(time.Now()) { + // 如果延迟超过1秒跳过 + timeDiff := time.Since(packet.Metadata().Timestamp) + if timeDiff > time.Second { continue }