1
0

feat: 用户导入角色初始/网元文件列表

This commit is contained in:
TsMask
2023-12-14 21:01:05 +08:00
parent 56310cc3c9
commit 615ab2eb2e
13 changed files with 297 additions and 92 deletions

View File

@@ -66,3 +66,93 @@ func (s *NeActionController) PushFile(c *gin.Context) {
neFilePath := fmt.Sprintf("%s/%s", nePath, fileName)
c.JSON(200, result.OkData(filepath.ToSlash(neFilePath)))
}
// 从网元端获取文件
//
// GET /pullFile
func (s *NeActionController) PullFile(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
Path string `form:"path" binding:"required"`
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")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
nePath := fmt.Sprintf("%s/%s", querys.Path, querys.FileName)
localPath := fmt.Sprintf("/tmp/omc/pullFile/%s", querys.FileName)
err := ssh.FileSCPNeToLocal(neInfo.IP, nePath, localPath)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
c.FileAttachment(localPath, querys.FileName)
}
// 网元端文件列表
//
// GET /files
func (s *NeActionController) Files(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
Path string `form:"path" binding:"required"`
PageNum int64 `form:"pageNum" binding:"required"`
PageSize int64 `form:"pageSize" binding:"required"`
Search string `form:"search"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
totalSize, rows, err := ssh.FileList(querys.Path, neInfo.IP, querys.Search)
if err != nil {
c.JSON(200, result.Ok(map[string]any{
"path": querys.Path,
"totalSize": totalSize,
"total": len(rows),
"rows": []ssh.FileListRow{},
}))
return
}
// 对数组进行切片分页
lenNum := int64(len(rows))
start := (querys.PageNum - 1) * querys.PageSize
end := start + querys.PageSize
var splitRows []ssh.FileListRow
if start >= lenNum {
splitRows = []ssh.FileListRow{}
} else if end >= lenNum {
splitRows = rows[start:]
} else {
splitRows = rows[start:end]
}
c.JSON(200, result.Ok(map[string]any{
"path": querys.Path,
"totalSize": totalSize,
"total": lenNum,
"rows": splitRows,
}))
}