feat: 网元配置文件备份记录功能接口
This commit is contained in:
82
src/modules/network_element/controller/ne_config_backup.go
Normal file
82
src/modules/network_element/controller/ne_config_backup.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// NewNeConfigBackup 实例化控制层 NeConfigBackupController 结构体
|
||||
var NewNeConfigBackup = &NeConfigBackupController{
|
||||
neConfigBackupService: neService.NewNeConfigBackupImpl,
|
||||
}
|
||||
|
||||
// 网元配置文件备份记录
|
||||
//
|
||||
// PATH /config/backup
|
||||
type NeConfigBackupController struct {
|
||||
// 网元配置文件备份记录服务
|
||||
neConfigBackupService neService.INeConfigBackup
|
||||
}
|
||||
|
||||
// 网元配置文件备份记录列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *NeConfigBackupController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.neConfigBackupService.SelectPage(querys)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// 网元配置文件备份记录信息
|
||||
//
|
||||
// GET /?id=xx
|
||||
func (s *NeConfigBackupController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
id, ok := c.GetQuery("id")
|
||||
if !ok || id == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
item := s.neConfigBackupService.SelectById(id)
|
||||
if item.ID != id {
|
||||
// 没有可访问主机命令数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neConfigBackup.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(item))
|
||||
}
|
||||
|
||||
// 网元配置文件备份记录删除
|
||||
//
|
||||
// DELETE /?id=xx
|
||||
func (s *NeConfigBackupController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
id, ok := c.GetQuery("id")
|
||||
if !ok || id == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(id, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.neConfigBackupService.DeleteByIds(uniqueIDs)
|
||||
if err != nil {
|
||||
c.JSON(200, result.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))
|
||||
}
|
||||
Reference in New Issue
Block a user