From d20dc98123cae02373d11efb8ad6a7e01f90c627 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 12 Mar 2024 09:51:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BD=91=E5=85=83=E8=BD=AF=E4=BB=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=89=E8=A3=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constants/uploadsubpath/uploadsubpath.go | 4 ++ .../network_element/controller/ne_software.go | 38 +++++++++++++++++-- .../network_element/model/ne_software.go | 16 ++++---- .../network_element/network_element.go | 5 +++ .../repository/ne_software.impl.go | 4 +- .../network_element/service/ne_software.go | 3 ++ .../service/ne_software.impl.go | 5 +++ 7 files changed, 61 insertions(+), 14 deletions(-) diff --git a/src/framework/constants/uploadsubpath/uploadsubpath.go b/src/framework/constants/uploadsubpath/uploadsubpath.go index 697e3718..c58e87f7 100644 --- a/src/framework/constants/uploadsubpath/uploadsubpath.go +++ b/src/framework/constants/uploadsubpath/uploadsubpath.go @@ -23,6 +23,9 @@ const ( // 切片 CHUNK = "chunk" + + // 软件包 + SOFTWARE = "software" ) // 子路径类型映射 @@ -34,4 +37,5 @@ var UploadSubpath = map[string]string{ COMMON: "通用上传", DOWNLOAD: "下载", CHUNK: "切片", + SOFTWARE: "软件包", } diff --git a/src/modules/network_element/controller/ne_software.go b/src/modules/network_element/controller/ne_software.go index 3e824d4c..1001392f 100644 --- a/src/modules/network_element/controller/ne_software.go +++ b/src/modules/network_element/controller/ne_software.go @@ -70,8 +70,8 @@ func (s *NeSoftwareController) Add(c *gin.Context) { } // 检查属性值唯一 - uniqueVersion := s.neSoftwareService.CheckUniqueTypeAndFileNameAndVersion(body.NeType, body.FileName, body.Version, "") - if !uniqueVersion { + uniqueSoftware := s.neSoftwareService.CheckUniqueTypeAndFileNameAndVersion(body.NeType, body.FileName, body.Version, "") + if !uniqueSoftware { // 网元软件包操作【%s】失败,网元类型与文件名版本已存在 msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.FileName}) c.JSON(200, result.ErrMsg(msg)) @@ -99,8 +99,8 @@ func (s *NeSoftwareController) Edit(c *gin.Context) { } // 检查属性值唯一 - uniqueVersion := s.neSoftwareService.CheckUniqueTypeAndFileNameAndVersion(body.NeType, body.FileName, body.Version, body.ID) - if !uniqueVersion { + uniqueSoftware := s.neSoftwareService.CheckUniqueTypeAndFileNameAndVersion(body.NeType, body.FileName, body.Version, body.ID) + if !uniqueSoftware { // 网元软件包操作【%s】失败,网元类型与文件名版本已存在 msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.FileName}) c.JSON(200, result.ErrMsg(msg)) @@ -148,3 +148,33 @@ func (s *NeSoftwareController) Remove(c *gin.Context) { msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows}) c.JSON(200, result.OkMsg(msg)) } + +// 网元软件包安装 +// +// POST /install +func (s *NeSoftwareController) Install(c *gin.Context) { + language := ctx.AcceptLanguage(c) + var body model.NeSoftware + err := c.ShouldBindBodyWith(&body, binding.JSON) + if err != nil { + c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) + return + } + + // 检查是否存在 + neSoftwares := s.neSoftwareService.SelectList(body) + if len(neSoftwares) == 0 { + // 没有可访问网元版本数据! + c.JSON(200, result.ErrMsg(i18n.TKey(language, "neSoftware.noData"))) + return + } + neSoftware := neSoftwares[0] + + // 进行安装 + output, err := s.neSoftwareService.Install(neSoftware) + if err != nil { + c.JSON(200, result.OkData(output)) + return + } + c.JSON(200, result.Err(nil)) +} diff --git a/src/modules/network_element/model/ne_software.go b/src/modules/network_element/model/ne_software.go index 7a1f130b..afb6dff6 100644 --- a/src/modules/network_element/model/ne_software.go +++ b/src/modules/network_element/model/ne_software.go @@ -5,14 +5,14 @@ import "time" // NeSoftware 网元软件包 ne_software type NeSoftware struct { ID string `json:"id" gorm:"id"` - NeType string `json:"neType" gorm:"ne_type"` // 网元类型 - FileName string `json:"fileName" gorm:"file_name"` // 包名称 - Path string `json:"path" gorm:"path"` // 包路径 - Version string `json:"version" gorm:"version"` // 包版本 - Md5Sum string `json:"md5Sum" gorm:"md5_sum"` // --无使用 md5签名 - Status string `json:"status" gorm:"status"` // --无使用 - Comment string `json:"comment" gorm:"comment"` // 包说明 - UpdateTime time.Time `json:"updateTime" gorm:"update_time"` // 上传时间 + NeType string `json:"neType" gorm:"ne_type" binding:"required"` // 网元类型 + FileName string `json:"fileName" gorm:"file_name" binding:"required"` // 包名称 + Path string `json:"path" gorm:"path"` // 包路径 + Version string `json:"version" gorm:"version" binding:"required"` // 包版本 + Md5Sum string `json:"md5Sum" gorm:"md5_sum"` // --无使用 md5签名 + Status string `json:"status" gorm:"status"` // --无使用 + Comment string `json:"comment" gorm:"comment"` // 包说明 + UpdateTime time.Time `json:"updateTime" gorm:"update_time"` // 上传时间 } // TableName 表名称 diff --git a/src/modules/network_element/network_element.go b/src/modules/network_element/network_element.go index 9f4dd393..594002bc 100644 --- a/src/modules/network_element/network_element.go +++ b/src/modules/network_element/network_element.go @@ -203,6 +203,11 @@ func Setup(router *gin.Engine) { collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neSoftware", collectlogs.BUSINESS_TYPE_DELETE)), controller.NewNeSoftware.Remove, ) + neSoftwareGroup.POST("/install", + middleware.PreAuthorize(nil), + collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neSoftware", collectlogs.BUSINESS_TYPE_DELETE)), + controller.NewNeSoftware.Install, + ) } // UDM鉴权用户信息 diff --git a/src/modules/network_element/repository/ne_software.impl.go b/src/modules/network_element/repository/ne_software.impl.go index 2277e4fa..835ca51a 100644 --- a/src/modules/network_element/repository/ne_software.impl.go +++ b/src/modules/network_element/repository/ne_software.impl.go @@ -99,7 +99,7 @@ func (r *NeSoftwareImpl) SelectPage(query map[string]any) map[string]any { // 分页 pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"]) - pageSql := " limit ?,? " + pageSql := " order by id desc limit ?,? " params = append(params, pageNum*pageSize) params = append(params, pageSize) @@ -141,7 +141,7 @@ func (r *NeSoftwareImpl) SelectList(neSoftware model.NeSoftware) []model.NeSoftw } // 查询数据 - querySql := r.selectSql + whereSql + " order by update_time asc " + querySql := r.selectSql + whereSql + " order by id desc " results, err := datasource.RawDB("", querySql, params) if err != nil { logger.Errorf("query err => %v", err) diff --git a/src/modules/network_element/service/ne_software.go b/src/modules/network_element/service/ne_software.go index eb5752d8..3f9160a3 100644 --- a/src/modules/network_element/service/ne_software.go +++ b/src/modules/network_element/service/ne_software.go @@ -24,4 +24,7 @@ type INeSoftware interface { // CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一 CheckUniqueTypeAndFileNameAndVersion(neType, fileName, version, id string) bool + + // Install 安装软件包 + Install(neSoftware model.NeSoftware) (string, error) } diff --git a/src/modules/network_element/service/ne_software.impl.go b/src/modules/network_element/service/ne_software.impl.go index de6c73ec..3a6409a5 100644 --- a/src/modules/network_element/service/ne_software.impl.go +++ b/src/modules/network_element/service/ne_software.impl.go @@ -78,3 +78,8 @@ func (r *NeSoftwareImpl) CheckUniqueTypeAndFileNameAndVersion(neType, fileName, } return uniqueId == "" } + +// Install 安装软件包 +func (r *NeSoftwareImpl) Install(neSoftware model.NeSoftware) (string, error) { + return "", nil +}