From b1c3c1343695ce9aa73f3dd69021ffcc2dab1508 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Fri, 26 Jul 2024 18:28:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BD=91=E5=85=83=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=87=E4=BB=BD=E8=AE=B0=E5=BD=95=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E8=BD=BD/=E8=AE=B0=E5=BD=95=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=8A=9F=E8=83=BD=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ne_config_backup.go | 46 +++++++++++++++++-- .../network_element/network_element.go | 10 +++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/modules/network_element/controller/ne_config_backup.go b/src/modules/network_element/controller/ne_config_backup.go index 772c8ac4..1ba1870c 100644 --- a/src/modules/network_element/controller/ne_config_backup.go +++ b/src/modules/network_element/controller/ne_config_backup.go @@ -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)) } // 网元配置文件备份记录删除 diff --git a/src/modules/network_element/network_element.go b/src/modules/network_element/network_element.go index 5a33ea0a..a2341ea3 100644 --- a/src/modules/network_element/network_element.go +++ b/src/modules/network_element/network_element.go @@ -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",