fix: 新增发送文件到网元服务器
This commit is contained in:
Binary file not shown.
@@ -27,9 +27,9 @@ func Setup(router *gin.Engine) {
|
||||
// 系统可暴露的配置信息
|
||||
indexGroup.GET("/sys-conf", controller.NewCommont.SysConfig)
|
||||
// 系统使用文档转存
|
||||
indexGroup.POST("/help-doc",
|
||||
indexGroup.POST("/helpDoc",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("系统使用文档", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.helpDoc", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewCommont.HelpDoc,
|
||||
)
|
||||
|
||||
@@ -56,11 +56,11 @@ func Setup(router *gin.Engine) {
|
||||
indexGroup.GET("/getInfo", middleware.PreAuthorize(nil), controller.NewAccount.Info)
|
||||
indexGroup.GET("/getRouters", middleware.PreAuthorize(nil), controller.NewAccount.Router)
|
||||
indexGroup.POST("/logout",
|
||||
// middleware.RateLimit(middleware.LimitOption{
|
||||
// Time: 300,
|
||||
// Count: 5,
|
||||
// Type: middleware.LIMIT_IP,
|
||||
// }),
|
||||
middleware.RateLimit(middleware.LimitOption{
|
||||
Time: 300,
|
||||
Count: 5,
|
||||
Type: middleware.LIMIT_IP,
|
||||
}),
|
||||
controller.NewAccount.Logout,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func (s *CommontController) SysConfig(c *gin.Context) {
|
||||
|
||||
// 转存帮助文档
|
||||
//
|
||||
// POST /help-doc
|
||||
// POST /helpDoc
|
||||
func (s *CommontController) HelpDoc(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
@@ -105,8 +105,6 @@ func (s *CommontController) HelpDoc(c *gin.Context) {
|
||||
newFile := fmt.Sprintf("%s/helpDoc/%s_doc.pdf", dir, lang)
|
||||
fmt.Println(newFile)
|
||||
|
||||
// dst := ""
|
||||
|
||||
err = file.CopyUploadFile(body.UploadPath, newFile)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, err.Error()))
|
||||
|
||||
68
src/modules/network_element/controller/ne_action.go
Normal file
68
src/modules/network_element/controller/ne_action.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/config"
|
||||
"ems.agt/src/framework/i18n"
|
||||
"ems.agt/src/framework/utils/ctx"
|
||||
"ems.agt/src/framework/utils/file"
|
||||
"ems.agt/src/framework/utils/ssh"
|
||||
"ems.agt/src/framework/vo/result"
|
||||
neService "ems.agt/src/modules/network_element/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 NeActionController 结构体
|
||||
var NewNeAction = &NeActionController{
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
}
|
||||
|
||||
// 网元处理请求
|
||||
//
|
||||
// PATH /
|
||||
type NeActionController struct {
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
}
|
||||
|
||||
// 发送文件到网元端
|
||||
//
|
||||
// POST /pushFile
|
||||
func (s *NeActionController) PushFile(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"`
|
||||
NeID string `json:"neId" binding:"required"`
|
||||
UploadPath string `json:"uploadPath" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID)
|
||||
if neInfo.NeId != body.NeID || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 本地文件
|
||||
localPath := file.ParseUploadFilePath(body.UploadPath)
|
||||
nePath := config.Get("mml.upload").(string)
|
||||
// 复制到远程
|
||||
err := ssh.FileSCPLocalToNe(neInfo.IP, localPath, nePath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 网元端文件路径
|
||||
fileName := localPath[strings.LastIndex(localPath, "/")+1:]
|
||||
neFilePath := fmt.Sprintf("%s/%s", nePath, fileName)
|
||||
c.JSON(200, result.OkData(filepath.ToSlash(neFilePath)))
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
|
||||
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(neInfo))
|
||||
|
||||
@@ -22,6 +22,17 @@ func Setup(router *gin.Engine) {
|
||||
)
|
||||
}
|
||||
|
||||
// 网元处理
|
||||
neActionGroup := neGroup.Group("/action")
|
||||
{
|
||||
// 发送文件到网元服务器
|
||||
neActionGroup.POST("/pushFile",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neAction", collectlogs.BUSINESS_TYPE_IMPORT)),
|
||||
controller.NewNeAction.PushFile,
|
||||
)
|
||||
}
|
||||
|
||||
// UDM鉴权用户信息
|
||||
udmAuthGroup := neGroup.Group("/udm/auth")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user