feat: 网元软件接口安装接口

This commit is contained in:
TsMask
2024-03-12 09:51:11 +08:00
parent 3f02e2e557
commit d20dc98123
7 changed files with 61 additions and 14 deletions

View File

@@ -23,6 +23,9 @@ const (
// 切片
CHUNK = "chunk"
// 软件包
SOFTWARE = "software"
)
// 子路径类型映射
@@ -34,4 +37,5 @@ var UploadSubpath = map[string]string{
COMMON: "通用上传",
DOWNLOAD: "下载",
CHUNK: "切片",
SOFTWARE: "软件包",
}

View File

@@ -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))
}

View File

@@ -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 表名称

View File

@@ -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鉴权用户信息

View File

@@ -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)

View File

@@ -24,4 +24,7 @@ type INeSoftware interface {
// CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一
CheckUniqueTypeAndFileNameAndVersion(neType, fileName, version, id string) bool
// Install 安装软件包
Install(neSoftware model.NeSoftware) (string, error)
}

View File

@@ -78,3 +78,8 @@ func (r *NeSoftwareImpl) CheckUniqueTypeAndFileNameAndVersion(neType, fileName,
}
return uniqueId == ""
}
// Install 安装软件包
func (r *NeSoftwareImpl) Install(neSoftware model.NeSoftware) (string, error) {
return "", nil
}