feat: 更新多个模块以支持新的数据结构和日志格式

This commit is contained in:
TsMask
2025-02-20 10:08:27 +08:00
parent 045a2b6b01
commit f3c33b31ac
272 changed files with 13246 additions and 15885 deletions

View File

@@ -10,11 +10,11 @@ import (
"github.com/gin-gonic/gin"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/ssh"
"be.ems/src/framework/utils/file"
"be.ems/src/framework/utils/generate"
"be.ems/src/framework/utils/ssh"
"be.ems/src/framework/vo/result"
neService "be.ems/src/modules/network_element/service"
)
@@ -45,7 +45,7 @@ type NeActionController struct {
// @Description Sending files from local to network elements
// @Router /ne/action/pushFile [post]
func (s *NeActionController) PushFile(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var body struct {
NeType string `json:"neType" binding:"required"`
NeID string `json:"neId" binding:"required"`
@@ -53,40 +53,41 @@ func (s *NeActionController) PushFile(c *gin.Context) {
DelTemp bool `json:"delTemp"` // 删除本地临时文件
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeID)
if neInfo.NeId != body.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sftpClient.Close()
// 本地文件
localFilePath := file.ParseUploadFilePath(body.UploadPath)
localFilePath := file.ParseUploadFileAbsPath(body.UploadPath)
// 网元端临时目录
sshClient.RunCMD("mkdir -p /tmp/omc/push && sudo chmod 777 -R /tmp/omc")
neFilePath := filepath.ToSlash(filepath.Join("/tmp/omc/push", filepath.Base(localFilePath)))
// 复制到远程
if err = sftpClient.CopyFileLocalToRemote(localFilePath, neFilePath); err != nil {
c.JSON(200, result.ErrMsg("Please check if the file exists or if scp is allowed to copy remotely"))
c.JSON(200, resp.ErrMsg("Please check if the file exists or if scp is allowed to copy remotely"))
return
}
@@ -95,7 +96,7 @@ func (s *NeActionController) PushFile(c *gin.Context) {
_ = os.Remove(localFilePath)
}
}()
c.JSON(200, result.OkData(filepath.ToSlash(neFilePath)))
c.JSON(200, resp.OkData(filepath.ToSlash(neFilePath)))
}
// 从网元到本地获取文件
@@ -105,7 +106,7 @@ func (s *NeActionController) PushFile(c *gin.Context) {
// @Tags network_element/action
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF)
// @Param neId query string true "NE ID" default(001)
// @Param path query string true "dir path" default(/var/log)
// @Param fileName query string true "file name"
@@ -116,7 +117,7 @@ func (s *NeActionController) PushFile(c *gin.Context) {
// @Description Getting files from the network element to the local
// @Router /ne/action/pullFile [get]
func (s *NeActionController) PullFile(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
@@ -125,28 +126,29 @@ func (s *NeActionController) PullFile(c *gin.Context) {
DelTemp bool `form:"delTemp"` // 删除本地临时文件
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sftpClient.Close()
@@ -159,7 +161,7 @@ func (s *NeActionController) PullFile(c *gin.Context) {
}
// 复制到本地
if err = sftpClient.CopyFileRemoteToLocal(nePath, localFilePath); err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -178,7 +180,7 @@ func (s *NeActionController) PullFile(c *gin.Context) {
// @Tags network_element/action
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF)
// @Param neId query string true "NE ID" default(001)
// @Param path query string true "dir path" default(/var/log)
// @Param delTemp query boolean false "Delete Temp File" default(false)
@@ -188,7 +190,7 @@ func (s *NeActionController) PullFile(c *gin.Context) {
// @Description Get directories compressed to ZIP from the network element to the local area
// @Router /ne/action/pullDirZip [get]
func (s *NeActionController) PullDirZip(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
@@ -196,28 +198,29 @@ func (s *NeActionController) PullDirZip(c *gin.Context) {
DelTemp bool `form:"delTemp"` // 删除本地临时文件
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sftpClient.Close()
@@ -231,7 +234,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) {
// 复制到本地
localDirFilePath := filepath.Join(localFilePath, "zip")
if err = sftpClient.CopyDirRemoteToLocal(nePath, localDirFilePath); err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -239,7 +242,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) {
zipFileName := fmt.Sprintf("%s-%s-%s.zip", neInfo.NeType, neInfo.NeId, dirName)
zipFilePath := filepath.Join(localFilePath, zipFileName)
if err := file.CompressZipByDir(zipFilePath, localDirFilePath); err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -258,7 +261,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) {
// @Tags network_element/action
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF)
// @Param neId query string true "NE ID" default(001)
// @Param path query string true "file path" default(/var/log)
// @Param fileName query string true "file name"
@@ -268,7 +271,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) {
// @Description Viewing the contents of a file on the network element side
// @Router /ne/action/viewFile [get]
func (s *NeActionController) ViewFile(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
@@ -276,21 +279,22 @@ func (s *NeActionController) ViewFile(c *gin.Context) {
FileName string `form:"fileName" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sshClient.Close()
@@ -301,10 +305,10 @@ func (s *NeActionController) ViewFile(c *gin.Context) {
output, err := sshClient.RunCMD(fmt.Sprintf("cat %s", nePath))
output = strings.TrimSpace(output)
if err != nil || strings.HasPrefix(output, "ls: ") {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "file view cat error")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "file view cat error")))
return
}
c.JSON(200, result.OkData(output))
c.JSON(200, resp.OkData(output))
}
// 网元端文件列表
@@ -314,7 +318,7 @@ func (s *NeActionController) ViewFile(c *gin.Context) {
// @Tags network_element/action
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF)
// @Param neId query string true "NE ID" default(001)
// @Param path query string true "file path" default(/var/log)
// @Param pageNum query number true "pageNum" default(1)
@@ -326,7 +330,7 @@ func (s *NeActionController) ViewFile(c *gin.Context) {
// @Description List of files on the network element side
// @Router /ne/action/files [get]
func (s *NeActionController) Files(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
@@ -336,21 +340,22 @@ func (s *NeActionController) Files(c *gin.Context) {
Search string `form:"search"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sshClient.Close()
@@ -358,7 +363,7 @@ func (s *NeActionController) Files(c *gin.Context) {
// 获取文件列表
rows, err := ssh.FileList(sshClient, querys.Path, querys.Search)
if err != nil {
c.JSON(200, result.Ok(map[string]any{
c.JSON(200, resp.OkData(map[string]any{
"path": querys.Path,
"total": len(rows),
"rows": []ssh.FileListRow{},
@@ -379,7 +384,7 @@ func (s *NeActionController) Files(c *gin.Context) {
splitRows = rows[start:end]
}
c.JSON(200, result.Ok(map[string]any{
c.JSON(200, resp.OkData(map[string]any{
"path": querys.Path,
"total": lenNum,
"rows": splitRows,
@@ -400,21 +405,22 @@ func (s *NeActionController) Files(c *gin.Context) {
// @Description Network element service operation
// @Router /ne/action/service [put]
func (s *NeActionController) Service(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var body struct {
NeType string `json:"neType" binding:"required"`
NeID string `json:"neId" binding:"required"`
Action string `json:"action" binding:"required,oneof=start restart stop reboot poweroff"` // 操作行为
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeID)
if neInfo.NeId != body.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -439,8 +445,8 @@ func (s *NeActionController) Service(c *gin.Context) {
_, err := s.neInfoService.NeRunSSHCmd(body.NeType, body.NeID, cmdStr)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
}

View File

@@ -2,18 +2,18 @@ package controller
import (
"encoding/json"
"strings"
"fmt"
cm_omc "be.ems/features/cm/omc"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
neFetchlink "be.ems/src/modules/network_element/fetch_link"
"be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// NewNeConfig 网元参数配置 实例化控制层
@@ -33,125 +33,127 @@ type NeConfigController struct {
// 网元参数配置可用属性值列表
//
// GET /list
func (s *NeConfigController) List(c *gin.Context) {
querys := ctx.QueryMapString(c)
rows, total := s.neConfigService.SelectPage(querys)
c.JSON(200, result.Ok(map[string]any{"total": total, "rows": rows}))
func (s NeConfigController) List(c *gin.Context) {
query := reqctx.QueryMap(c)
rows, total := s.neConfigService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
}
// 网元参数配置可用属性值信息
//
// GET /info/:id
func (s *NeConfigController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
id := c.Param("id")
if id == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
func (s NeConfigController) Info(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := parse.Number(c.Query("id"))
if id <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
data := s.neConfigService.SelectById(id)
data := s.neConfigService.FindById(id)
if data.ID != id {
// 没有可访问参数配置数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neConfig.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neConfig.noData")))
return
}
// 将字符串转json数据
if err := json.Unmarshal([]byte(data.ParamJson), &data.ParamData); err != nil {
c.JSON(400, result.CodeMsg(400, err.Error()))
c.JSON(400, resp.CodeMsg(400, err.Error()))
return
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// 网元参数配置可用属性值新增
//
// POST /
func (s *NeConfigController) Add(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeConfigController) Add(c *gin.Context) {
var body model.NeConfig
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 将json数据转字符串存储
paramDataByte, err := json.Marshal(body.ParamData)
if err != nil {
c.JSON(400, result.CodeMsg(400, err.Error()))
c.JSON(400, resp.CodeMsg(400, err.Error()))
return
}
body.ParamJson = string(paramDataByte)
insertId := s.neConfigService.Insert(body)
if insertId != "" {
c.JSON(200, result.Ok(nil))
if insertId > 0 {
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元参数配置可用属性值修改
//
// PUT /
func (s *NeConfigController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeConfigController) Edit(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeConfig
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.ID == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 检查是否存在
data := s.neConfigService.SelectById(body.ID)
data := s.neConfigService.FindById(body.ID)
if data.ID != body.ID {
// 没有可访问主机命令数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neConfig.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neConfig.noData")))
return
}
// 将json数据转字符串存储
paramDataByte, err := json.Marshal(body.ParamData)
if err != nil {
c.JSON(400, result.CodeMsg(400, err.Error()))
c.JSON(400, resp.CodeMsg(400, err.Error()))
return
}
body.ParamJson = string(paramDataByte)
rows := s.neConfigService.Update(body)
if rows > 0 {
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元参数配置可用属性值删除
//
// DELETE /
func (s *NeConfigController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
id, okId := c.GetQuery("id")
if id == "" || !okId {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
func (s NeConfigController) Remove(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := c.Query("id")
if id == "" {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
// 处理字符转id数组后去重
idsArr := strings.Split(id, ",")
uniqueIDs := parse.RemoveDuplicates(idsArr)
if len(uniqueIDs) <= 0 {
c.JSON(200, result.Err(nil))
return
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
// 转换成int64数组类型
ids := make([]int64, 0)
for _, v := range uniqueIDs {
ids = append(ids, parse.Number(v))
}
rows, err := s.neConfigService.DeleteByIds(uniqueIDs)
rows, err := s.neConfigService.DeleteByIds(ids)
if err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
c.JSON(200, resp.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))
c.JSON(200, resp.OkMsg(msg))
}
// 网元参数配置可用属性值列表指定网元类型全部无分页
@@ -161,21 +163,21 @@ func (s *NeConfigController) Remove(c *gin.Context) {
// @Tags network_element/config
// @Accept json
// @Produce json
// @Param neType path string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neType path string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Network Element Parameter Configuration Available Attribute Values List Specify Network Element Type All Unpaged
// @Description Network Element Parameter Configuration Available Attribute Values List Specify Network Element Type All Unpaged
// @Router /ne/config/list/{neType} [get]
func (s *NeConfigController) ListByNeType(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeConfigController) ListByNeType(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
neType := c.Param("neType")
if neType == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.neConfigService.SelectNeConfigByNeType(neType)
c.JSON(200, result.OkData(data))
data := s.neConfigService.FindByNeType(neType)
c.JSON(200, resp.OkData(data))
}
// 网元参数配置数据信息
@@ -185,7 +187,7 @@ func (s *NeConfigController) ListByNeType(c *gin.Context) {
// @Tags network_element/config
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string true "NE ID" default(001)
// @Param paramName query string true "Available attributes, based on querying the list of attributes"
// @Success 200 {object} object "Response Results"
@@ -193,21 +195,22 @@ func (s *NeConfigController) ListByNeType(c *gin.Context) {
// @Summary Network Element Parameter Configuration Data Information
// @Description Network Element Parameter Configuration Data Information
// @Router /ne/config/data [get]
func (s *NeConfigController) DataInfo(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeConfigController) DataInfo(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var query struct {
NeType string `form:"neType" binding:"required"` // 网元类型
NeId string `form:"neId" binding:"required"` // 网元ID
ParamName string `form:"paramName" binding:"required"` // 可用属性
}
if err := c.ShouldBindQuery(&query); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(query.NeType, query.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID(query.NeType, query.NeId)
if neInfo.NeId != query.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -215,21 +218,21 @@ func (s *NeConfigController) DataInfo(c *gin.Context) {
var o *cm_omc.ConfigOMC
resData, err := o.Query(query.ParamName)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(resData))
c.JSON(200, resp.OkData(resData))
return
}
// 网元直连
resData, err := neFetchlink.NeConfigInfo(neInfo, query.ParamName)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.Ok(resData))
c.JSON(200, resp.Ok(resData))
}
// 网元参数配置数据修改
@@ -245,8 +248,8 @@ func (s *NeConfigController) DataInfo(c *gin.Context) {
// @Summary Network element parameter configuration data modification
// @Description Network element parameter configuration data modification
// @Router /ne/config/data [put]
func (s *NeConfigController) DataEdit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeConfigController) DataEdit(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {
NeType string `json:"neType" binding:"required"` // 网元类型
NeId string `json:"neId" binding:"required"` // 网元ID
@@ -254,34 +257,35 @@ func (s *NeConfigController) DataEdit(c *gin.Context) {
ParamData map[string]any `json:"paramData" binding:"required"`
Loc string `json:"loc"` // 仅array使用与数据对象内index一致,有多层时划分嵌套层(index/subParamName/index)
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeId)
if neInfo.NeId != body.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
if body.NeType == "OMC" {
var o *cm_omc.ConfigOMC
resData, err := o.Modify(body.ParamName, body.ParamData)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(resData))
c.JSON(200, resp.OkData(resData))
return
}
// 网元直连
resData, err := neFetchlink.NeConfigUpdate(neInfo, body.ParamName, body.Loc, body.ParamData)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(resData))
c.JSON(200, resp.OkData(resData))
}
// 网元参数配置数据新增array
@@ -297,8 +301,8 @@ func (s *NeConfigController) DataEdit(c *gin.Context) {
// @Summary Network element parameter configuration data added (array)
// @Description Network element parameter configuration data added (array)
// @Router /ne/config/data [post]
func (s *NeConfigController) DataAdd(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeConfigController) DataAdd(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {
NeType string `json:"neType" binding:"required"` // 网元类型
NeId string `json:"neId" binding:"required"` // 网元ID
@@ -306,37 +310,38 @@ func (s *NeConfigController) DataAdd(c *gin.Context) {
ParamData map[string]any `json:"paramData" binding:"required"` // 数据对象
Loc string `json:"loc" binding:"required"` // 与数据对象内index一致,有多层时划分嵌套层(index/subParamName/index)
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 检查是否array
info := s.neConfigService.SelectNeConfigByNeTypeAndParamName(body.NeType, body.ParamName)
info := s.neConfigService.FindByNeTypeAndParamName(body.NeType, body.ParamName)
if info.ParamType != "array" {
c.JSON(400, result.CodeMsg(400, "this attribute does not support adding"))
c.JSON(400, resp.CodeMsg(400, "this attribute does not support adding"))
return
}
// 必须含有index
_, idxOk := body.ParamData["index"]
if info.ParamType == "array" && !idxOk {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeId)
if neInfo.NeId != body.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元直连
resData, err := neFetchlink.NeConfigInstall(neInfo, body.ParamName, body.Loc, body.ParamData)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(resData))
c.JSON(200, resp.OkData(resData))
}
// 网元参数配置数据删除array
@@ -346,7 +351,7 @@ func (s *NeConfigController) DataAdd(c *gin.Context) {
// @Tags network_element/config
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string true "NE ID" default(001)
// @Param paramName query string true "Available attributes, based on querying the list of attributes"
// @Param loc query string true "Array index"
@@ -355,8 +360,8 @@ func (s *NeConfigController) DataAdd(c *gin.Context) {
// @Summary Network element parameter configuration data deletion (array)
// @Description Network element parameter configuration data deletion (array)
// @Router /ne/config/data [delete]
func (s *NeConfigController) DataRemove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeConfigController) DataRemove(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var query struct {
NeType string `form:"neType" binding:"required"` // 网元类型
NeId string `form:"neId" binding:"required"` // 网元ID
@@ -364,28 +369,28 @@ func (s *NeConfigController) DataRemove(c *gin.Context) {
Loc string `form:"loc" binding:"required"` // 与数据对象内index一致,有多层时划分嵌套层(index/subParamName/index)
}
if err := c.ShouldBindQuery(&query); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 检查是否array
info := s.neConfigService.SelectNeConfigByNeTypeAndParamName(query.NeType, query.ParamName)
info := s.neConfigService.FindByNeTypeAndParamName(query.NeType, query.ParamName)
if info.ParamType != "array" {
c.JSON(400, result.CodeMsg(400, "this attribute does not support adding"))
c.JSON(400, resp.CodeMsg(400, "this attribute does not support adding"))
return
}
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(query.NeType, query.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID(query.NeType, query.NeId)
if neInfo.NeId != query.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元直连
resData, err := neFetchlink.NeConfigDelete(neInfo, query.ParamName, query.Loc)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(resData))
c.JSON(200, resp.OkData(resData))
}

View File

@@ -1,19 +1,20 @@
package controller
import (
"fmt"
"os"
"path/filepath"
"strings"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/file"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// NewNeConfigBackup 实例化控制层 NeConfigBackupController 结构体
@@ -33,33 +34,32 @@ type NeConfigBackupController struct {
// 网元配置文件备份记录列表
//
// GET /list
func (s *NeConfigBackupController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.neConfigBackupService.SelectPage(querys)
c.JSON(200, result.Ok(data))
func (s NeConfigBackupController) List(c *gin.Context) {
query := reqctx.QueryMap(c)
rows, total := s.neConfigBackupService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// 网元配置文件备份记录信息
//
// GET /download?id=xx
func (s *NeConfigBackupController) Download(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")))
func (s NeConfigBackupController) Download(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := parse.Number(c.Query("id"))
if id <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
item := s.neConfigBackupService.SelectById(id)
item := s.neConfigBackupService.FindById(id)
if item.ID != id {
// 没有可访问主机命令数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neConfigBackup.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neConfigBackup.noData")))
return
}
if _, err := os.Stat(item.Path); err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neConfigBackup.notFoundFile")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neConfigBackup.notFoundFile")))
return
}
c.FileAttachment(item.Path, item.Name)
@@ -68,125 +68,129 @@ func (s *NeConfigBackupController) Download(c *gin.Context) {
// 网元配置文件备份记录修改
//
// PUT /
func (s *NeConfigBackupController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeConfigBackupController) Edit(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {
ID string `json:"id" binding:"required"` // 记录ID
ID int64 `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")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 检查是否存在
data := s.neConfigBackupService.SelectById(body.ID)
data := s.neConfigBackupService.FindById(body.ID)
if data.ID != body.ID {
// 没有可访问主机命令数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neConfig.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neConfig.noData")))
return
}
data.Name = body.Name
data.Remark = body.Remark
data.UpdateBy = ctx.LoginUserToUserName(c)
data.UpdateBy = reqctx.LoginUserToUserName(c)
rows := s.neConfigBackupService.Update(data)
if rows > 0 {
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元配置文件备份记录删除
//
// 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")))
func (s NeConfigBackupController) Remove(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := c.Query("id")
if id == "" {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
// 处理字符转id数组后去重
ids := strings.Split(id, ",")
uniqueIDs := parse.RemoveDuplicates(ids)
if len(uniqueIDs) <= 0 {
c.JSON(200, result.Err(nil))
return
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
// 转换成int64数组类型
ids := make([]int64, 0)
for _, v := range uniqueIDs {
ids = append(ids, parse.Number(v))
}
rows, err := s.neConfigBackupService.DeleteByIds(uniqueIDs)
rows, err := s.neConfigBackupService.DeleteByIds(ids)
if err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
c.JSON(200, resp.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))
c.JSON(200, resp.OkMsg(msg))
}
// 网元配置文件备份导入
//
// POST /import
func (s *NeConfigBackupController) Import(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeConfigBackupController) Import(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {
NeType string `json:"neType" binding:"required"`
NeId string `json:"neId" binding:"required"`
Type string `json:"type" binding:"required,oneof=backup upload"` // 导入类型
Path string `json:"path" binding:"required"` // 文件路径
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if !strings.HasSuffix(body.Path, ".zip") {
c.JSON(200, result.ErrMsg("Only supports decompression of zip files"))
c.JSON(200, resp.ErrMsg("Only supports decompression of zip files"))
return
}
// 查网元
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeId)
if neInfo.NeId != body.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 将zip文件解压到本地后复制到网元端
localFilePath := body.Path
if body.Type == "upload" {
localFilePath = file.ParseUploadFilePath(body.Path)
localFilePath = file.ParseUploadFileAbsPath(body.Path)
}
if err := s.neConfigBackupService.NeConfigLocalToNe(neInfo, localFilePath); err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
if err := s.neConfigBackupService.FileLocalToNe(neInfo, localFilePath); err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
}
// 网元配置文件备份导出
//
// POST /export
func (s *NeConfigBackupController) Export(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeConfigBackupController) Export(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {
NeType string `json:"neType" binding:"required"`
NeId string `json:"neId" binding:"required"`
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查网元
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeId)
if neInfo.NeId != body.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 将网元文件备份到本地
zipFilePath, err := s.neConfigBackupService.NeConfigNeToLocal(neInfo)
zipFilePath, err := s.neConfigBackupService.FileNeToLocal(neInfo)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
// 新增备份记录
@@ -195,7 +199,7 @@ func (s *NeConfigBackupController) Export(c *gin.Context) {
NeId: neInfo.NeId,
Name: filepath.Base(zipFilePath),
Path: zipFilePath,
CreateBy: ctx.LoginUserToUserName(c),
CreateBy: reqctx.LoginUserToUserName(c),
}
s.neConfigBackupService.Insert(item)
c.FileAttachment(item.Path, item.Name)

View File

@@ -1,19 +1,20 @@
package controller
import (
"fmt"
"strings"
"be.ems/src/framework/database/redis"
"be.ems/src/framework/i18n"
"be.ems/src/framework/redis"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/ssh"
"be.ems/src/framework/telnet"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/utils/ssh"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 NeHostController 结构体
@@ -31,11 +32,10 @@ type NeHostController struct {
// 网元主机列表
//
// GET /list
func (s *NeHostController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.neHostService.SelectPage(querys)
func (s NeHostController) List(c *gin.Context) {
query := reqctx.QueryMap(c)
rows, total := s.neHostService.FindByPage(query)
rows := data["rows"].([]model.NeHost)
arr := &rows
for i := range *arr {
(*arr)[i].Password = "-"
@@ -43,129 +43,139 @@ func (s *NeHostController) List(c *gin.Context) {
(*arr)[i].PassPhrase = "-"
}
c.JSON(200, result.Ok(data))
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
}
// 网元主机信息
//
// GET /:hostId
func (s *NeHostController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
hostId := c.Param("hostId")
if hostId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
// GET /:id
func (s NeHostController) Info(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := parse.Number(c.Param("id"))
if id <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
neHost := s.neHostService.SelectById(hostId)
if neHost.HostID != hostId {
neHost := s.neHostService.FindById(id)
if neHost.ID != id {
// 没有可访问主机信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.noData")))
return
}
c.JSON(200, result.OkData(neHost))
c.JSON(200, resp.OkData(neHost))
}
// 网元主机新增
//
// POST /
func (s *NeHostController) Add(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeHostController) Add(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeHost
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.HostID != "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.ID == 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id not is empty"))
return
}
if body.GroupID == "1" {
// 主机信息操作【%s】失败禁止操作网元
msg := i18n.TKey(language, "neHost.banNE")
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
// 检查属性值唯一
uniqueHost := s.neHostService.CheckUniqueHostTitle(body.GroupID, body.Title, body.HostType, "")
uniqueHost := s.neHostService.CheckUniqueHostTitle(body.GroupID, body.Title, body.HostType, 0)
if !uniqueHost {
// 主机信息操作【%s】失败同组内名称已存在
msg := i18n.TTemplate(language, "neHost.errKeyExists", map[string]any{"name": body.Title})
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
body.CreateBy = ctx.LoginUserToUserName(c)
body.CreateBy = reqctx.LoginUserToUserName(c)
insertId := s.neHostService.Insert(body)
if insertId != "" {
c.JSON(200, result.Ok(nil))
if insertId > 0 {
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元主机修改
//
// PUT /
func (s *NeHostController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeHostController) Edit(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeHost
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.HostID == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.ID <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
// 检查属性值唯一
uniqueHost := s.neHostService.CheckUniqueHostTitle(body.GroupID, body.Title, body.HostType, body.HostID)
uniqueHost := s.neHostService.CheckUniqueHostTitle(body.GroupID, body.Title, body.HostType, body.ID)
if !uniqueHost {
// 主机信息操作【%s】失败同组内名称已存在
msg := i18n.TTemplate(language, "neHost.errKeyExists", map[string]any{"name": body.Title})
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
// 检查是否存在
neHost := s.neHostService.SelectById(body.HostID)
if neHost.HostID != body.HostID {
neHost := s.neHostService.FindById(body.ID)
if neHost.ID != body.ID {
// 没有可访问主机信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.noData")))
return
}
body.UpdateBy = ctx.LoginUserToUserName(c)
body.UpdateBy = reqctx.LoginUserToUserName(c)
rows := s.neHostService.Update(body)
if rows > 0 {
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元主机删除
//
// DELETE /:hostIds
func (s *NeHostController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
hostIds := c.Param("hostIds")
if hostIds == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
// DELETE /:id
func (s NeHostController) Remove(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := c.Param("id")
if id == "" {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
// 处理字符转id数组后去重
ids := strings.Split(hostIds, ",")
uniqueIDs := parse.RemoveDuplicates(ids)
if len(uniqueIDs) <= 0 {
c.JSON(200, result.Err(nil))
return
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
// 转换成int64数组类型
ids := make([]int64, 0)
for _, v := range uniqueIDs {
ids = append(ids, parse.Number(v))
}
rows, err := s.neHostService.DeleteByIds(uniqueIDs)
rows, err := s.neHostService.DeleteByIds(ids)
if err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
c.JSON(200, resp.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))
c.JSON(200, resp.OkMsg(msg))
}
// 网元主机测试连接
@@ -181,11 +191,12 @@ func (s *NeHostController) Remove(c *gin.Context) {
// @Summary Network element host test connection
// @Description Network element host test connection
// @Router /ne/host/test [post]
func (s *NeHostController) Test(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeHostController) Test(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeHost
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
@@ -201,11 +212,11 @@ func (s *NeHostController) Test(c *gin.Context) {
}
if err != nil {
// 连接主机失败,请检查连接参数后重试
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
return
}
defer client.Close()
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
@@ -216,16 +227,16 @@ func (s *NeHostController) Test(c *gin.Context) {
client, err := connTelnet.NewClient()
if err != nil {
// 连接主机失败,请检查连接参数后重试
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
return
}
defer client.Close()
// 是否有终止符
if strings.HasSuffix(client.LastResult, ">") || strings.HasSuffix(client.LastResult, "> ") || strings.HasSuffix(client.LastResult, "# ") {
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
} else {
// 连接主机失败,请检查连接参数后重试
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
}
return
}
@@ -237,11 +248,11 @@ func (s *NeHostController) Test(c *gin.Context) {
client, err := connRedis.NewClient()
if err != nil {
// 连接主机失败,请检查连接参数后重试
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
return
}
defer client.Close()
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
}
@@ -259,22 +270,23 @@ func (s *NeHostController) Test(c *gin.Context) {
// @Summary The network element host sends the command
// @Description The network element host sends the command
// @Router /ne/host/cmd [post]
func (s *NeHostController) Cmd(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeHostController) Cmd(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {
HostID string `json:"hostId" binding:"required"` // 主机ID
Cmd string `json:"cmd" binding:"required"` // 执行命令
ID int64 `json:"id" binding:"required"` // 主机ID
Cmd string `json:"cmd" binding:"required"` // 执行命令
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 检查是否存在
neHost := s.neHostService.SelectById(body.HostID)
if neHost.HostID != body.HostID {
neHost := s.neHostService.FindById(body.ID)
if neHost.ID != body.ID {
// 没有可访问主机信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.noData")))
return
}
@@ -290,7 +302,7 @@ func (s *NeHostController) Cmd(c *gin.Context) {
}
if err != nil {
// 连接主机失败,请检查连接参数后重试
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
return
}
defer client.Close()
@@ -298,10 +310,10 @@ func (s *NeHostController) Cmd(c *gin.Context) {
// 执行命令
output, err := client.RunCMD(body.Cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(output))
c.JSON(200, resp.OkData(output))
return
}
@@ -312,7 +324,7 @@ func (s *NeHostController) Cmd(c *gin.Context) {
client, err := connTelnet.NewClient()
if err != nil {
// 连接主机失败,请检查连接参数后重试
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
return
}
defer client.Close()
@@ -320,10 +332,10 @@ func (s *NeHostController) Cmd(c *gin.Context) {
// 执行命令
output, err := client.RunCMD(body.Cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(output))
c.JSON(200, resp.OkData(output))
return
}
}
@@ -341,11 +353,12 @@ func (s *NeHostController) Cmd(c *gin.Context) {
// @Summary Checking the server environment by SSH method of Net Element Hosting
// @Description Checking the server environment by SSH method of Net Element Hosting
// @Router /ne/host/checkBySSH [post]
func (s *NeHostController) CheckBySSH(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeHostController) CheckBySSH(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeHost
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
@@ -361,7 +374,7 @@ func (s *NeHostController) CheckBySSH(c *gin.Context) {
}
if err != nil {
// 连接主机失败,请检查连接参数后重试
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
return
}
defer client.Close()
@@ -381,7 +394,7 @@ func (s *NeHostController) CheckBySSH(c *gin.Context) {
// 执行命令 检查系统环境
output, err := client.RunCMD("uname -snrm && cat /etc/os-release | grep PRETTY_NAME")
if err != nil {
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
return
}
output = strings.TrimSuffix(output, "\n")
@@ -426,7 +439,7 @@ func (s *NeHostController) CheckBySSH(c *gin.Context) {
}
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// 网元主机SSH方式授权免密发送
@@ -442,11 +455,16 @@ func (s *NeHostController) CheckBySSH(c *gin.Context) {
// @Summary Network element host SSH method of authorization for password-free sending
// @Description Network element host SSH method of authorization for password-free sending
// @Router /ne/host/authorizedBySSH [post]
func (s *NeHostController) AuthorizedBySSH(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeHostController) AuthorizedBySSH(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeHost
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil || body.AuthMode == "2" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.AuthMode == "2" {
c.JSON(400, resp.CodeMsg(40010, "bind err: auth mode not equals 2"))
return
}
@@ -464,7 +482,7 @@ func (s *NeHostController) AuthorizedBySSH(c *gin.Context) {
}
if sshLink {
// 连接主机成功,无需重复免密授权认证
c.JSON(200, result.OkMsg(i18n.TKey(language, "neHost.okBySSHLink")))
c.JSON(200, resp.OkMsg(i18n.TKey(language, "neHost.okBySSHLink")))
return
}
@@ -474,7 +492,7 @@ func (s *NeHostController) AuthorizedBySSH(c *gin.Context) {
client, err := connSSH.NewClient()
if err != nil {
// 连接主机失败,请检查连接参数后重试
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
return
}
defer client.Close()
@@ -482,8 +500,8 @@ func (s *NeHostController) AuthorizedBySSH(c *gin.Context) {
// 发送密钥
err = client.SendToAuthorizedKeys()
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
}

View File

@@ -1,16 +1,16 @@
package controller
import (
"strings"
"fmt"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 NeHostCmdController 结构体
@@ -28,124 +28,125 @@ type NeHostCmdController struct {
// 网元主机命令列表
//
// GET /list
func (s *NeHostCmdController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.neHostCmdService.SelectPage(querys)
c.JSON(200, result.Ok(data))
func (s NeHostCmdController) List(c *gin.Context) {
query := reqctx.QueryMap(c)
rows, total := s.neHostCmdService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
}
// 网元主机命令信息
//
// GET /:cmdId
func (s *NeHostCmdController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
cmdId := c.Param("cmdId")
if cmdId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
// GET /:id
func (s NeHostCmdController) Info(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := parse.Number(c.Param("id"))
if id <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
neHost := s.neHostCmdService.SelectById(cmdId)
if neHost.CmdID != cmdId {
neHost := s.neHostCmdService.FindById(id)
if neHost.ID != id {
// 没有可访问主机命令数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHostCmd.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHostCmd.noData")))
return
}
c.JSON(200, result.OkData(neHost))
c.JSON(200, resp.OkData(neHost))
}
// 网元主机命令新增
//
// POST /
func (s *NeHostCmdController) Add(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeHostCmdController) Add(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeHostCmd
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.CmdID != "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 检查属性值唯一
uniqueHostCmd := s.neHostCmdService.CheckUniqueGroupTitle(body.GroupID, body.Title, body.CmdType, "")
uniqueHostCmd := s.neHostCmdService.CheckUniqueGroupTitle(body.GroupID, body.Title, body.CmdType, 0)
if !uniqueHostCmd {
// 主机命令操作【%s】失败同组内名称已存在
msg := i18n.TTemplate(language, "neHostCmd.errKeyExists", map[string]any{"name": body.Title})
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
body.CreateBy = ctx.LoginUserToUserName(c)
body.CreateBy = reqctx.LoginUserToUserName(c)
insertId := s.neHostCmdService.Insert(body)
if insertId != "" {
c.JSON(200, result.Ok(nil))
if insertId > 0 {
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元主机命令修改
//
// PUT /
func (s *NeHostCmdController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeHostCmdController) Edit(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeHostCmd
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.CmdID == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 检查属性值唯一
uniqueHostCmd := s.neHostCmdService.CheckUniqueGroupTitle(body.GroupID, body.Title, body.CmdType, body.CmdID)
uniqueHostCmd := s.neHostCmdService.CheckUniqueGroupTitle(body.GroupID, body.Title, body.CmdType, body.ID)
if !uniqueHostCmd {
// 主机命令操作【%s】失败同组内名称已存在
msg := i18n.TTemplate(language, "neHostCmd.errKeyExists", map[string]any{"name": body.Title})
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
// 检查是否存在
neHost := s.neHostCmdService.SelectById(body.CmdID)
if neHost.CmdID != body.CmdID {
neHost := s.neHostCmdService.FindById(body.ID)
if neHost.ID != body.ID {
// 没有可访问主机命令数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHostCmd.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHostCmd.noData")))
return
}
body.UpdateBy = ctx.LoginUserToUserName(c)
body.UpdateBy = reqctx.LoginUserToUserName(c)
rows := s.neHostCmdService.Update(body)
if rows > 0 {
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元主机命令删除
//
// DELETE /:cmdIds
func (s *NeHostCmdController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
cmdIds := c.Param("cmdIds")
if cmdIds == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
// DELETE /:id
func (s NeHostCmdController) Remove(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := c.Param("id")
if id == "" {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
// 处理字符转id数组后去重
ids := strings.Split(cmdIds, ",")
uniqueIDs := parse.RemoveDuplicates(ids)
if len(uniqueIDs) <= 0 {
c.JSON(200, result.Err(nil))
return
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
// 转换成int64数组类型
ids := make([]int64, 0)
for _, v := range uniqueIDs {
ids = append(ids, parse.Number(v))
}
rows, err := s.neHostCmdService.DeleteByIds(uniqueIDs)
rows, err := s.neHostCmdService.DeleteByIds(ids)
if err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
c.JSON(200, resp.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))
c.JSON(200, resp.OkMsg(msg))
}

View File

@@ -6,9 +6,9 @@ import (
"sync"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
neFetchlink "be.ems/src/modules/network_element/fetch_link"
"be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
@@ -43,27 +43,28 @@ var mutex sync.Mutex
// @Tags network_element/info
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Network element information state
// @Description Network element information state
// @Router /ne/info/state [get]
func (s *NeInfoController) State(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) State(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeId string `form:"neId" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeId)
if neInfo.NeId != querys.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
neKey := fmt.Sprintf("%s_%s", neInfo.NeType, neInfo.NeId)
@@ -87,7 +88,7 @@ func (s *NeInfoController) State(c *gin.Context) {
}
neStateCacheMap.Store(neKey, resDataCache)
mutex.Unlock()
c.JSON(200, result.OkData(resDataCache))
c.JSON(200, resp.OkData(resDataCache))
return
}
@@ -96,7 +97,7 @@ func (s *NeInfoController) State(c *gin.Context) {
mutex.Lock()
neStateCacheMap.Store(neKey, resData)
mutex.Unlock()
c.JSON(200, result.OkData(resData))
c.JSON(200, resp.OkData(resData))
}
// 网元neType和neID查询
@@ -106,30 +107,31 @@ func (s *NeInfoController) State(c *gin.Context) {
// @Tags network_element/info
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Network element neType and neID queries
// @Description Network element neType and neID queries
// @Router /ne/info/byTypeAndID [get]
func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) NeTypeAndID(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
c.JSON(200, result.OkData(neInfo))
c.JSON(200, resp.OkData(neInfo))
}
// 网元信息列表全部无分页
@@ -148,8 +150,8 @@ func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
// @Summary The list of network element information is all unpaginated
// @Description The list of network element information is all unpaginated
// @Router /ne/info/listAll [get]
func (s *NeInfoController) ListAll(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) ListAll(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType"`
NeId string `form:"neId"`
@@ -157,7 +159,8 @@ func (s *NeInfoController) ListAll(c *gin.Context) {
BandHost bool `form:"bandHost"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
@@ -169,75 +172,75 @@ func (s *NeInfoController) ListAll(c *gin.Context) {
if querys.NeId != "" {
ne.NeId = querys.NeId
}
neList := s.neInfoService.SelectList(ne, querys.BandStatus, querys.BandHost)
neList := s.neInfoService.Find(ne, querys.BandStatus, querys.BandHost)
if len(neList) == 0 {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
c.JSON(200, result.OkData(neList))
c.JSON(200, resp.OkData(neList))
}
// 网元端Para5G配置文件读取
//
// GET /para5GFile
func (s *NeInfoController) Para5GFileRead(c *gin.Context) {
func (s NeInfoController) Para5GFileRead(c *gin.Context) {
data, err := s.neInfoService.NeConfPara5GRead()
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// 网元端Para5G配置文件写入
//
// PUT /para5GFile
func (s *NeInfoController) Para5GFileWrite(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) Para5GFileWrite(c *gin.Context) {
var body struct {
Content map[string]any `json:"content" binding:"required"` // 内容
SyncNE []string `json:"syncNe"` // 同步到网元
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
err := s.neInfoService.NeConfPara5GWirte(body.Content, body.SyncNE)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
}
// 网元端OAM配置文件读取
//
// GET /oamFile
func (s *NeInfoController) OAMFileRead(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) OAMFileRead(c *gin.Context) {
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
data, err := s.neInfoService.NeConfOAMReadSync(querys.NeType, querys.NeID)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// 网元端OAM配置文件写入
//
// PUT /oamFile
func (s *NeInfoController) OAMFileWrite(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) OAMFileWrite(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {
NeType string `json:"neType" binding:"required"`
NeID string `json:"neId" binding:"required"`
@@ -245,23 +248,24 @@ func (s *NeInfoController) OAMFileWrite(c *gin.Context) {
Sync bool `json:"sync"` // 同步到网元
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeID)
if neInfo.NeId != body.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
err := s.neInfoService.NeConfOAMWirteSync(neInfo, body.Content, body.Sync)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
}
// 网元信息列表
@@ -281,19 +285,19 @@ func (s *NeInfoController) OAMFileWrite(c *gin.Context) {
// @Summary Network element information list
// @Description Network element information list
// @Router /ne/info/list [get]
func (s *NeInfoController) List(c *gin.Context) {
query := ctx.QueryMapString(c)
func (s NeInfoController) List(c *gin.Context) {
query := reqctx.QueryMap(c)
bandStatus := false
if v, ok := query["bandStatus"]; ok {
bandStatus = parse.Boolean(v)
}
rows, total := s.neInfoService.SelectPage(query, bandStatus)
c.JSON(200, result.Ok(map[string]any{"rows": rows, "total": total}))
rows, total := s.neInfoService.FindByPage(query, bandStatus)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// 网元信息
//
// GET /:infoId
// GET /:id
//
// @Tags network_element/info
// @Accept json
@@ -304,22 +308,22 @@ func (s *NeInfoController) List(c *gin.Context) {
// @Summary Network element information
// @Description Network element information
// @Router /ne/info/{value} [get]
func (s *NeInfoController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
infoId := c.Param("infoId")
if infoId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
func (s NeInfoController) Info(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := parse.Number(c.Param("id"))
if id <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
neHost := s.neInfoService.SelectById(infoId, true)
if neHost.ID != infoId {
neHost := s.neInfoService.FindById(id, true)
if neHost.ID != id {
// 没有可访问网元信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neInfo.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neInfo.noData")))
return
}
c.JSON(200, result.OkData(neHost))
c.JSON(200, resp.OkData(neHost))
}
// 网元信息新增
@@ -335,41 +339,46 @@ func (s *NeInfoController) Info(c *gin.Context) {
// @Summary Network element information addition
// @Description Network element information addition
// @Router /ne/info [post]
func (s *NeInfoController) Add(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) Add(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeInfo
err := c.ShouldBindBodyWithJSON(&body)
if err != nil || body.ID != "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.ID != 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id not is empty"))
return
}
// 检查属性值唯一
uniqueInfo := s.neInfoService.CheckUniqueNeTypeAndNeId(body.NeType, body.NeId, "")
uniqueInfo := s.neInfoService.CheckUniqueNeTypeAndNeId(body.NeType, body.NeId, 0)
if !uniqueInfo {
// 网元信息操作【%s】失败同类型下标识已存在
msg := i18n.TTemplate(language, "neInfo.errKeyExists", map[string]any{"key": body.NeId})
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
// 获取网元状态是否正常
body.ServerState, err = neFetchlink.NeState(body)
if err != nil {
body.Status = "0"
body.Status = 0
} else {
// 网元状态设置为在线
body.Status = "1"
body.Status = 1
if parse.Boolean(body.ServerState["standby"]) {
body.Status = "3"
body.Status = 3
}
// 下发网管配置信息给网元
if _, err = neFetchlink.NeConfigOMC(body); err != nil {
body.Status = "2"
body.Status = 2
}
}
loginUserName := ctx.LoginUserToUserName(c)
loginUserName := reqctx.LoginUserToUserName(c)
// 新增Version信息
neVersion := model.NeVersion{
NeType: body.NeType,
@@ -403,11 +412,11 @@ func (s *NeInfoController) Add(c *gin.Context) {
s.neLicenseService.Insert(neLicense)
body.CreateBy = loginUserName
insertId := s.neInfoService.Insert(body)
if insertId != "" {
c.JSON(200, result.OkData(insertId))
if insertId > 0 {
c.JSON(200, resp.OkData(insertId))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元信息修改
@@ -423,12 +432,17 @@ func (s *NeInfoController) Add(c *gin.Context) {
// @Summary Network element information modification
// @Description Network element information modification
// @Router /ne/info [put]
func (s *NeInfoController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) Edit(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeInfo
err := c.ShouldBindBodyWithJSON(&body)
if err != nil || body.ID == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.ID <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
@@ -437,44 +451,44 @@ func (s *NeInfoController) Edit(c *gin.Context) {
if !uniqueInfo {
// 网元信息操作【%s】失败同类型下标识已存在
msg := i18n.TTemplate(language, "neInfo.errKeyExists", map[string]any{"key": body.NeId})
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
// 检查是否存在
neInfo := s.neInfoService.SelectById(body.ID, false)
neInfo := s.neInfoService.FindById(body.ID, false)
if neInfo.ID != body.ID {
// 没有可访问网元信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neInfo.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neInfo.noData")))
return
}
// 赋予主机ID
if neInfo.HostIDs != "" && len(body.Hosts) > 0 {
hostIDs := strings.Split(neInfo.HostIDs, ",")
for index, id := range hostIDs {
body.Hosts[index].HostID = id
body.Hosts[index].ID = parse.Number(id)
}
}
// 获取网元状态是否正常
body.ServerState, err = neFetchlink.NeState(body)
body.ServerState, err = neFetchlink.NeState(neInfo)
if err != nil {
body.Status = "0"
body.Status = 0
} else {
// 网元状态设置为在线
body.Status = "1"
body.Status = 1
if parse.Boolean(body.ServerState["standby"]) {
body.Status = "3"
body.Status = 3
}
// 下发网管配置信息给网元
if _, err = neFetchlink.NeConfigOMC(body); err != nil {
body.Status = "2"
body.Status = 2
}
}
loginUserName := ctx.LoginUserToUserName(c)
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
neVersion := s.neVersionService.SelectByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
loginUserName := reqctx.LoginUserToUserName(c)
neLicense := s.neLicenseService.FindByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
neVersion := s.neVersionService.FindByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
// 已有网元可获取的信息
if body.ServerState != nil {
@@ -494,14 +508,14 @@ func (s *NeInfoController) Edit(c *gin.Context) {
}
}
if neVersion.ID != "" {
if neVersion.ID <= 0 {
if neVersion.NeType != body.NeType || neVersion.NeId != body.NeId {
neVersion.NeType = body.NeType
neVersion.NeId = body.NeId
}
s.neVersionService.Update(neVersion)
}
if neLicense.ID != "" {
if neLicense.ID <= 0 {
if neLicense.NeType != body.NeType || neLicense.NeId != body.NeId {
neLicense.NeType = body.NeType
neLicense.NeId = body.NeId
@@ -512,44 +526,46 @@ func (s *NeInfoController) Edit(c *gin.Context) {
body.UpdateBy = loginUserName
rows := s.neInfoService.Update(body)
if rows > 0 {
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元信息删除
//
// DELETE /:infoIds
// DELETE /:id
//
// @Tags network_element/info
// @Accept json
// @Produce json
// @Param value path string true "Row ID, multiple separated by a , sign"
// @Param value path string true "Row ID"
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Network element information deletion
// @Description Network element information deletion
// @Router /ne/info/{value} [delete]
func (s *NeInfoController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
infoIds := c.Param("infoIds")
if infoIds == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
// @Router /ne/info [delete]
func (s NeInfoController) Remove(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := c.Param("id")
if id == "" {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
// 处理字符转id数组后去重
ids := strings.Split(infoIds, ",")
uniqueIDs := parse.RemoveDuplicates(ids)
if len(uniqueIDs) <= 0 {
c.JSON(200, result.Err(nil))
return
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
// 转换成int64数组类型
ids := make([]int64, 0)
for _, v := range uniqueIDs {
ids = append(ids, parse.Number(v))
}
rows, err := s.neInfoService.DeleteByIds(uniqueIDs)
rows, err := s.neInfoService.DeleteByIds(ids)
if err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
c.JSON(200, resp.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))
c.JSON(200, resp.OkMsg(msg))
}

View File

@@ -6,8 +6,9 @@ import (
"github.com/gin-gonic/gin"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/parse"
neFetchlink "be.ems/src/modules/network_element/fetch_link"
"be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
@@ -34,47 +35,49 @@ type NeLicenseController struct {
// @Tags network_element/license
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Param neType query string false "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string false "NE ID"
// @Param expiryDate query string false "ExpiryDate"
// @Param pageNum query number true "pageNum" default(1)
// @Param pageSize query number true "pageSize" default(10)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Net Element License Activation List
// @Description Net Element License Activation List
// @Router /ne/license/list [get]
func (s *NeLicenseController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.neLicenseService.SelectPage(querys)
query := reqctx.QueryMap(c)
rows, total := s.neLicenseService.FindByPage(query)
// 过滤屏蔽授权文件
rows := data["rows"].([]model.NeLicense)
arr := &rows
for i := range *arr {
(*arr)[i].ActivationRequestCode = "-"
(*arr)[i].LicensePath = "-"
}
c.JSON(200, result.Ok(data))
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
}
// 网元授权激活信息
//
// GET /:licenseId
// GET /:id
func (s *NeLicenseController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
licenseId := c.Param("licenseId")
if licenseId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
language := reqctx.AcceptLanguage(c)
id := parse.Number(c.Param("id"))
if id <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
neLicense := s.neLicenseService.SelectById(licenseId)
if neLicense.ID != licenseId {
neLicense := s.neLicenseService.FindById(id)
if neLicense.ID != id {
// 没有可访问网元授权激活数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
return
}
c.JSON(200, result.OkData(neLicense))
c.JSON(200, resp.OkData(neLicense))
}
// 网元neType和neID查询
@@ -84,7 +87,7 @@ func (s *NeLicenseController) Info(c *gin.Context) {
// @Tags network_element/license
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
@@ -92,24 +95,25 @@ func (s *NeLicenseController) Info(c *gin.Context) {
// @Description Network element neType and neID queries
// @Router /ne/license/byTypeAndID [get]
func (s *NeLicenseController) NeTypeAndID(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeId string `form:"neId" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(querys.NeType, querys.NeId)
neLicense := s.neLicenseService.FindByNeTypeAndNeID(querys.NeType, querys.NeId)
if neLicense.NeId != querys.NeId {
// 没有可访问网元授权激活数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
return
}
c.JSON(200, result.OkData(neLicense))
c.JSON(200, resp.OkData(neLicense))
}
// 网元授权激活授权申请码
@@ -119,7 +123,7 @@ func (s *NeLicenseController) NeTypeAndID(c *gin.Context) {
// @Tags network_element/license
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
@@ -127,21 +131,21 @@ func (s *NeLicenseController) NeTypeAndID(c *gin.Context) {
// @Description Network Element License Activation License Application Code
// @Router /ne/license/code [get]
func (s *NeLicenseController) Code(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeId string `form:"neId" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 检查是否存在授权记录
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(querys.NeType, querys.NeId)
neLicense := s.neLicenseService.FindByNeTypeAndNeID(querys.NeType, querys.NeId)
if neLicense.NeId != querys.NeId {
// 没有可访问网元授权激活数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
return
}
@@ -155,10 +159,10 @@ func (s *NeLicenseController) Code(c *gin.Context) {
neLicense.ExpiryDate = ""
neLicense.Status = "0"
}
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
neLicense.UpdateBy = reqctx.LoginUserToUserName(c)
s.neLicenseService.Update(neLicense)
c.JSON(200, result.OkData(code))
c.JSON(200, resp.OkData(code))
}
// 网元授权激活授权文件替换
@@ -175,19 +179,19 @@ func (s *NeLicenseController) Code(c *gin.Context) {
// @Description Network element authorization activation status
// @Router /ne/license/change [post]
func (s *NeLicenseController) Change(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var body model.NeLicense
err := c.ShouldBindBodyWithJSON(&body)
if err != nil || body.LicensePath == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 检查是否存在授权记录
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(body.NeType, body.NeId)
neLicense := s.neLicenseService.FindByNeTypeAndNeID(body.NeType, body.NeId)
if neLicense.NeId != body.NeId {
// 没有可访问网元授权激活数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
return
}
@@ -197,19 +201,19 @@ func (s *NeLicenseController) Change(c *gin.Context) {
}
neLicense.LicensePath = body.LicensePath
neLicense.Status = "0"
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
neLicense.UpdateBy = reqctx.LoginUserToUserName(c)
upRows := s.neLicenseService.Update(neLicense)
if upRows > 0 {
// 进行上传替换
err = s.neLicenseService.UploadLicense(body)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元授权激活状态
@@ -219,7 +223,7 @@ func (s *NeLicenseController) Change(c *gin.Context) {
// @Tags network_element/license
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
@@ -227,28 +231,28 @@ func (s *NeLicenseController) Change(c *gin.Context) {
// @Description Network element authorization activation status
// @Router /ne/license/state [get]
func (s *NeLicenseController) State(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeId string `form:"neId" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 检查是否存在授权记录
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(querys.NeType, querys.NeId)
neLicense := s.neLicenseService.FindByNeTypeAndNeID(querys.NeType, querys.NeId)
if neLicense.NeId != querys.NeId {
// 没有可访问网元授权激活数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neLicense.noData")))
return
}
// 查询网元获取IP获取网元状态
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(neLicense.NeType, neLicense.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID(neLicense.NeType, neLicense.NeId)
if neInfo.NeId != neLicense.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
if neState, err := neFetchlink.NeState(neInfo); err == nil && neState["sn"] != nil {
@@ -263,15 +267,15 @@ func (s *NeLicenseController) State(c *gin.Context) {
}
// 更新授权信息
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
neLicense.UpdateBy = reqctx.LoginUserToUserName(c)
s.neLicenseService.Update(neLicense)
if neLicense.Status == "1" {
c.JSON(200, result.OkData(map[string]string{
c.JSON(200, resp.OkData(map[string]string{
"sn": neLicense.SerialNum,
"expire": neLicense.ExpiryDate,
}))
return
}
c.JSON(200, result.ErrMsg(fmt.Sprintf("%s service status exception", neLicense.NeType)))
c.JSON(200, resp.ErrMsg(fmt.Sprintf("%s service status exception", neLicense.NeType)))
}

View File

@@ -1,16 +1,16 @@
package controller
import (
"strings"
"fmt"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 NeSoftwareController 结构体
@@ -32,62 +32,76 @@ type NeSoftwareController struct {
// @Tags network_element/software
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Param neType query string false "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param name query string false "Name"
// @Param version query string false "Version"
// @Param pageNum query number true "pageNum" default(1)
// @Param pageSize query number true "pageSize" default(10)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary List of Network Element Software Packages
// @Description List of Network Element Software Packages
// @Router /ne/software/list [get]
func (s *NeSoftwareController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.neSoftwareService.SelectPage(querys)
c.JSON(200, result.Ok(data))
func (s NeSoftwareController) List(c *gin.Context) {
query := reqctx.QueryMap(c)
rows, total := s.neSoftwareService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
}
// 网元软件包信息
//
// GET /:softwareId
func (s *NeSoftwareController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
softwareId := c.Param("softwareId")
if softwareId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
// GET /:id
func (s NeSoftwareController) Info(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := parse.Number(c.Param("id"))
if id <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
neSoftware := s.neSoftwareService.SelectById(softwareId)
if neSoftware.ID != softwareId {
neSoftware := s.neSoftwareService.FindById(id)
if neSoftware.ID != id {
// 没有可访问网元包信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
return
}
c.JSON(200, result.OkData(neSoftware))
c.JSON(200, resp.OkData(neSoftware))
}
// 网元软件包新增
//
// POST /
func (s *NeSoftwareController) Add(c *gin.Context) {
language := ctx.AcceptLanguage(c)
//
// @Tags network_element/software
// @Accept json
// @Produce json
// @Param data body object true "Request Param"
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Additions to the Net Element package
// @Description Additions to the Net Element package
// @Router /ne/software [post]
func (s NeSoftwareController) Add(c *gin.Context) {
var body model.NeSoftware
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.Path == "" || body.ID != "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.Path == "" || body.ID > 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: path is empty or id is not empty"))
return
}
// 找到已存在的删除后重新添加
neSoftwares := s.neSoftwareService.SelectList(model.NeSoftware{
neSoftwares := s.neSoftwareService.Find(model.NeSoftware{
NeType: body.NeType,
Name: body.Name,
Version: body.Version,
})
if len(neSoftwares) > 0 {
neSoftware := neSoftwares[0]
s.neSoftwareService.DeleteByIds([]string{neSoftware.ID})
s.neSoftwareService.DeleteByIds([]int64{neSoftware.ID})
}
// 检查属性值唯一
@@ -95,28 +109,32 @@ func (s *NeSoftwareController) Add(c *gin.Context) {
// if !uniqueSoftware {
// // 网元软件包操作【%s】失败网元类型与文件名版本已存在
// msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.Name})
// c.JSON(200, result.ErrMsg(msg))
// c.JSON(200, resp.ErrMsg(msg))
// return
// }
body.CreateBy = ctx.LoginUserToUserName(c)
body.CreateBy = reqctx.LoginUserToUserName(c)
insertId := s.neSoftwareService.Insert(body)
if insertId != "" {
c.JSON(200, result.Ok(nil))
if insertId > 0 {
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元软件包修改
//
// PUT /
func (s *NeSoftwareController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeSoftwareController) Edit(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeSoftware
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.Path == "" || body.ID == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.Path == "" || body.ID == 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: path or id is empty"))
return
}
@@ -125,51 +143,53 @@ func (s *NeSoftwareController) Edit(c *gin.Context) {
if !uniqueSoftware {
// 网元软件包操作【%s】失败网元类型与文件名版本已存在
msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.Name})
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
// 检查是否存在
neSoftware := s.neSoftwareService.SelectById(body.ID)
neSoftware := s.neSoftwareService.FindById(body.ID)
if neSoftware.ID != body.ID {
// 没有可访问网元包信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
return
}
body.UpdateBy = ctx.LoginUserToUserName(c)
body.UpdateBy = reqctx.LoginUserToUserName(c)
rows := s.neSoftwareService.Update(body)
if rows > 0 {
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元软件包删除
//
// DELETE /:softwareIds
func (s *NeSoftwareController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
softwareIds := c.Param("softwareIds")
if softwareIds == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
// DELETE /:id
func (s NeSoftwareController) Remove(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := c.Param("id")
if id == "" {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
// 处理字符转id数组后去重
ids := strings.Split(softwareIds, ",")
uniqueIDs := parse.RemoveDuplicates(ids)
if len(uniqueIDs) <= 0 {
c.JSON(200, result.Err(nil))
return
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
// 转换成int64数组类型
ids := make([]int64, 0)
for _, v := range uniqueIDs {
ids = append(ids, parse.Number(v))
}
rows, err := s.neSoftwareService.DeleteByIds(uniqueIDs)
rows, err := s.neSoftwareService.DeleteByIds(ids)
if err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
c.JSON(200, resp.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))
c.JSON(200, resp.OkMsg(msg))
}
// 网元软件包设为网元新版本
@@ -185,17 +205,16 @@ func (s *NeSoftwareController) Remove(c *gin.Context) {
// @Summary Net Element package set to Net Element new version
// @Description Net Element package set to Net Element new version
// @Router /ne/software/newNeVersion [post]
func (s *NeSoftwareController) NewNeVersion(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeSoftwareController) NewNeVersion(c *gin.Context) {
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")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 找到已存在的软件包信息
neSoftwares := s.neSoftwareService.SelectList(model.NeSoftware{
neSoftwares := s.neSoftwareService.Find(model.NeSoftware{
NeType: body.NeType,
Name: body.Name,
Version: body.Version,
@@ -204,10 +223,10 @@ func (s *NeSoftwareController) NewNeVersion(c *gin.Context) {
neSoftware := neSoftwares[0]
s.neSoftwareService.UpdateVersions(neSoftware, model.NeVersion{
NeType: neSoftware.NeType,
UpdateBy: ctx.LoginUserToUserName(c),
UpdateBy: reqctx.LoginUserToUserName(c),
})
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}

View File

@@ -1,12 +1,15 @@
package controller
import (
"fmt"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/parse"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 NeVersionController 结构体
@@ -25,31 +28,30 @@ type NeVersionController struct {
//
// GET /list
func (s *NeVersionController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.neVersionService.SelectPage(querys, true)
c.JSON(200, result.Ok(data))
query := reqctx.QueryMap(c)
rows, total := s.neVersionService.FindByPage(query, true)
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
}
// 网元版本信息
//
// GET /:versionId
// GET /:id
func (s *NeVersionController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
versionId := c.Param("versionId")
if versionId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
language := reqctx.AcceptLanguage(c)
id := parse.Number(c.Param("id"))
if id <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
neVersion := s.neVersionService.SelectById(versionId)
if neVersion.ID != versionId {
neVersion := s.neVersionService.FindById(id)
if neVersion.ID != id {
// 没有可访问网元版本数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neVersion.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neVersion.noData")))
return
}
c.JSON(200, result.OkData(neVersion))
c.JSON(200, resp.OkData(neVersion))
}
// 网元版本操作
@@ -66,30 +68,31 @@ func (s *NeVersionController) Info(c *gin.Context) {
// @Description Network element version operation
// @Router /ne/version/operate [post]
func (s *NeVersionController) Operate(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var body struct {
Action string `json:"action" binding:"required,oneof=install upgrade rollback"` // 操作行为
NeType string `json:"neType" gorm:"ne_type" binding:"required"` // 网元类型
NeId string `json:"neId" gorm:"ne_id" binding:"required"` // 网元ID
Preinput map[string]string `json:"preinput" ` // 预先输入参数
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
neVersion := s.neVersionService.SelectByNeTypeAndNeID(body.NeType, body.NeId)
neVersion := s.neVersionService.FindByNeTypeAndNeID(body.NeType, body.NeId)
if neVersion.NeId != body.NeId {
// 没有可访问网元版本数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neVersion.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neVersion.noData")))
return
}
// 进行相关命令操作
output, err := s.neVersionService.Operate(body.Action, neVersion, body.Preinput)
if err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
return
}
c.JSON(200, result.OkData(output))
c.JSON(200, resp.OkData(output))
}