feat: 网元配置文件备份记录文件下载/记录更新功能接口
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -43,8 +44,8 @@ func (s *NeConfigBackupController) List(c *gin.Context) {
|
||||
|
||||
// 网元配置文件备份记录信息
|
||||
//
|
||||
// GET /?id=xx
|
||||
func (s *NeConfigBackupController) Info(c *gin.Context) {
|
||||
// GET /download?id=xx
|
||||
func (s *NeConfigBackupController) Download(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
id, ok := c.GetQuery("id")
|
||||
if !ok || id == "" {
|
||||
@@ -59,7 +60,46 @@ func (s *NeConfigBackupController) Info(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(item))
|
||||
if _, err := os.Stat(item.Path); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neConfigBackup.notFoundFile")))
|
||||
return
|
||||
}
|
||||
c.FileAttachment(item.Path, item.Name)
|
||||
}
|
||||
|
||||
// 网元配置文件备份记录修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *NeConfigBackupController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
ID string `json:"id" binding:"required"` // 记录ID
|
||||
Name string `json:"name" binding:"required"` // 名称
|
||||
Remark string `json:"remark" binding:"required"` // 备注
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
data := s.neConfigBackupService.SelectById(body.ID)
|
||||
if data.ID != body.ID {
|
||||
// 没有可访问主机命令数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neConfig.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
data.Name = body.Name
|
||||
data.Remark = body.Remark
|
||||
data.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.neConfigBackupService.Update(data)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元配置文件备份记录删除
|
||||
|
||||
@@ -317,12 +317,18 @@ func Setup(router *gin.Engine) {
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeConfigBackup.List,
|
||||
)
|
||||
neConfigBackupGroup.GET("",
|
||||
neConfigBackupGroup.GET("/download",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeConfigBackup.Info,
|
||||
controller.NewNeConfigBackup.Download,
|
||||
)
|
||||
neConfigBackupGroup.PUT("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigBackup", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewNeConfigBackup.Edit,
|
||||
)
|
||||
neConfigBackupGroup.DELETE("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigBackup", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeConfigBackup.Remove,
|
||||
)
|
||||
neConfigBackupGroup.POST("/import",
|
||||
|
||||
Reference in New Issue
Block a user