merge: 合并代码20240531
This commit is contained in:
@@ -155,3 +155,52 @@ func (s *NeActionController) Files(c *gin.Context) {
|
||||
"rows": splitRows,
|
||||
}))
|
||||
}
|
||||
|
||||
// 网元服务操作
|
||||
//
|
||||
// PUT /service
|
||||
func (s *NeActionController) Service(c *gin.Context) {
|
||||
language := ctx.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.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID)
|
||||
if neInfo.NeId != body.NeID || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
neTypeLower := strings.ToLower(neInfo.NeType)
|
||||
cmdStr := fmt.Sprintf("sudo service %s %s", neTypeLower, body.Action)
|
||||
if neTypeLower == "omc" {
|
||||
cmdStr = fmt.Sprintf("nohup sh -c \"sudo systemctl stop restagent && sleep 5s && sudo systemctl %s restagent\" > /dev/null 2>&1 &", body.Action)
|
||||
} else if neTypeLower == "ims" {
|
||||
if body.Action == "restart" {
|
||||
cmdStr = "sudo ims-stop || true && sudo ims-start"
|
||||
} else {
|
||||
cmdStr = fmt.Sprintf("sudo ims-%s", body.Action)
|
||||
}
|
||||
}
|
||||
|
||||
if body.Action == "reboot" {
|
||||
cmdStr = "sudo shutdown -r now"
|
||||
}
|
||||
if body.Action == "poweroff" {
|
||||
cmdStr = "sudo shutdown -h now"
|
||||
}
|
||||
|
||||
_, err := s.neInfoService.NeRunCMD(body.NeType, body.NeID, cmdStr)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
}
|
||||
|
||||
@@ -167,8 +167,7 @@ func (s *NeHostController) Remove(c *gin.Context) {
|
||||
func (s *NeHostController) Test(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeHost
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
@@ -176,8 +175,13 @@ func (s *NeHostController) Test(c *gin.Context) {
|
||||
if body.HostType == "ssh" {
|
||||
var connSSH ssh.ConnSSH
|
||||
body.CopyTo(&connSSH)
|
||||
|
||||
client, err := connSSH.NewClient()
|
||||
var client *ssh.ConnSSH
|
||||
var err error
|
||||
if body.AuthMode == "2" {
|
||||
client, err = connSSH.NewClientByLocalPrivate()
|
||||
} else {
|
||||
client, err = connSSH.NewClient()
|
||||
}
|
||||
if err != nil {
|
||||
// 连接主机失败,请检查连接参数后重试
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||
@@ -199,7 +203,12 @@ func (s *NeHostController) Test(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
c.JSON(200, result.Ok(nil))
|
||||
if strings.HasSuffix(client.LastResult, ">") || strings.HasSuffix(client.LastResult, "> ") || strings.HasSuffix(client.LastResult, "# ") {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
} else {
|
||||
// 连接主机失败,请检查连接参数后重试
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -213,8 +222,7 @@ func (s *NeHostController) Cmd(c *gin.Context) {
|
||||
HostID string `json:"hostId" binding:"required"` // 主机ID
|
||||
Cmd string `json:"cmd" binding:"required"` // 执行命令
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
@@ -230,8 +238,13 @@ func (s *NeHostController) Cmd(c *gin.Context) {
|
||||
if neHost.HostType == "ssh" {
|
||||
var connSSH ssh.ConnSSH
|
||||
neHost.CopyTo(&connSSH)
|
||||
|
||||
client, err := connSSH.NewClient()
|
||||
var client *ssh.ConnSSH
|
||||
var err error
|
||||
if neHost.AuthMode == "2" {
|
||||
client, err = connSSH.NewClientByLocalPrivate()
|
||||
} else {
|
||||
client, err = connSSH.NewClient()
|
||||
}
|
||||
if err != nil {
|
||||
// 连接主机失败,请检查连接参数后重试
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||
@@ -278,17 +291,21 @@ func (s *NeHostController) Cmd(c *gin.Context) {
|
||||
func (s *NeHostController) CheckBySSH(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeHost
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
var connSSH ssh.ConnSSH
|
||||
body.CopyTo(&connSSH)
|
||||
|
||||
// 创建链接SSH客户端
|
||||
client, err := connSSH.NewClient()
|
||||
var client *ssh.ConnSSH
|
||||
var err error
|
||||
if body.AuthMode == "2" {
|
||||
client, err = connSSH.NewClientByLocalPrivate()
|
||||
} else {
|
||||
client, err = connSSH.NewClient()
|
||||
}
|
||||
if err != nil {
|
||||
// 连接主机失败,请检查连接参数后重试
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||
@@ -339,18 +356,22 @@ func (s *NeHostController) CheckBySSH(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 本地免密创建链接直连
|
||||
lcoalConnSSH := ssh.ConnSSH{
|
||||
User: body.User,
|
||||
Addr: body.Addr,
|
||||
Port: body.Port,
|
||||
}
|
||||
lcoalClient, err := lcoalConnSSH.NewClientByLocalPrivate()
|
||||
if err == nil {
|
||||
if body.AuthMode == "2" {
|
||||
data["sshLink"] = true
|
||||
} else {
|
||||
data["sshLink"] = false
|
||||
lcoalConnSSH := ssh.ConnSSH{
|
||||
User: body.User,
|
||||
Addr: body.Addr,
|
||||
Port: body.Port,
|
||||
}
|
||||
lcoalClient, err := lcoalConnSSH.NewClientByLocalPrivate()
|
||||
if err == nil {
|
||||
data["sshLink"] = true
|
||||
defer lcoalClient.Close()
|
||||
} else {
|
||||
data["sshLink"] = false
|
||||
}
|
||||
}
|
||||
defer lcoalClient.Close()
|
||||
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
@@ -361,8 +382,7 @@ func (s *NeHostController) CheckBySSH(c *gin.Context) {
|
||||
func (s *NeHostController) AuthorizedBySSH(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeHost
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil || body.AuthMode == "2" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
@@ -377,8 +397,8 @@ func (s *NeHostController) AuthorizedBySSH(c *gin.Context) {
|
||||
lcoalClient, err := lcoalConnSSH.NewClientByLocalPrivate()
|
||||
if err == nil {
|
||||
sshLink = true
|
||||
defer lcoalClient.Close()
|
||||
}
|
||||
defer lcoalClient.Close()
|
||||
if sshLink {
|
||||
// 连接主机成功,无需重复免密授权认证
|
||||
c.JSON(200, result.OkMsg(i18n.TKey(language, "neHost.okBySSHLink")))
|
||||
|
||||
@@ -17,15 +17,21 @@ import (
|
||||
|
||||
// 实例化控制层 NeInfoController 结构体
|
||||
var NewNeInfo = &NeInfoController{
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
neLicenseService: neService.NewNeLicenseImpl,
|
||||
neVersionService: neService.NewNeVersionImpl,
|
||||
}
|
||||
|
||||
// 网元信息请求
|
||||
//
|
||||
// PATH /
|
||||
// PATH /info
|
||||
type NeInfoController struct {
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
// 网元授权激活信息服务
|
||||
neLicenseService neService.INeLicense
|
||||
// 网元版本信息服务
|
||||
neVersionService neService.INeVersion
|
||||
}
|
||||
|
||||
// neStateCacheMap 网元状态缓存最后一次成功的信息
|
||||
@@ -114,7 +120,8 @@ func (s *NeInfoController) ListAll(c *gin.Context) {
|
||||
var querys struct {
|
||||
NeType string `form:"neType"`
|
||||
NeId string `form:"neId"`
|
||||
BandStatus string `form:"bandStatus"`
|
||||
BandStatus bool `form:"bandStatus"`
|
||||
BandHost bool `form:"bandHost"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
@@ -129,8 +136,7 @@ func (s *NeInfoController) ListAll(c *gin.Context) {
|
||||
if querys.NeId != "" {
|
||||
ne.NeId = querys.NeId
|
||||
}
|
||||
bandStatus := parse.Boolean(querys.BandStatus)
|
||||
neList := s.neInfoService.SelectList(ne, bandStatus)
|
||||
neList := s.neInfoService.SelectList(ne, querys.BandStatus, querys.BandHost)
|
||||
if len(neList) == 0 {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
@@ -138,53 +144,74 @@ func (s *NeInfoController) ListAll(c *gin.Context) {
|
||||
c.JSON(200, result.OkData(neList))
|
||||
}
|
||||
|
||||
// 网元端配置文件读取
|
||||
// 网元端Para5G配置文件读取
|
||||
//
|
||||
// GET /configFile
|
||||
func (s *NeInfoController) ConfigFileRead(c *gin.Context) {
|
||||
// GET /para5GFile
|
||||
func (s *NeInfoController) Para5GFileRead(c *gin.Context) {
|
||||
data, err := s.neInfoService.NeConfPara5GRead()
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// 网元端Para5G配置文件写入
|
||||
//
|
||||
// PUT /para5GFile
|
||||
func (s *NeInfoController) Para5GFileWrite(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
Content map[string]any `json:"content" binding:"required"` // 内容
|
||||
SyncNE []string `json:"syncNe"` // 同步到网元
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
err := s.neInfoService.NeConfPara5GWirte(body.Content, body.SyncNE)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
}
|
||||
|
||||
// 网元端OAM配置文件读取
|
||||
//
|
||||
// GET /oamFile
|
||||
func (s *NeInfoController) OAMFileRead(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"`
|
||||
NeID string `form:"neId" binding:"required"`
|
||||
FilePath string `form:"filePath"` // 不带文件路径时进行复制覆盖本地网元配置目录
|
||||
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")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
|
||||
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
data, err := s.neInfoService.NeConfOAMRead(querys.NeType, querys.NeID)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
data := s.neInfoService.NeConfigFileRead(neInfo, querys.FilePath)
|
||||
if querys.FilePath == "" {
|
||||
c.JSON(200, result.OkData(data))
|
||||
return
|
||||
}
|
||||
if len(data) > 0 {
|
||||
c.JSON(200, result.OkData(data[0]))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.ErrMsg("no data"))
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// 网元端配置文件写入
|
||||
// 网元端OAM配置文件写入
|
||||
//
|
||||
// PUT /configFile
|
||||
func (s *NeInfoController) ConfigFileWrite(c *gin.Context) {
|
||||
// PUT /oamFile
|
||||
func (s *NeInfoController) OAMFileWrite(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"`
|
||||
NeID string `json:"neId" binding:"required"`
|
||||
FilePath string `json:"filePath" binding:"required"`
|
||||
Content string `json:"content" binding:"required"`
|
||||
Sync bool `json:"sync"`
|
||||
NeType string `json:"neType" binding:"required"`
|
||||
NeID string `json:"neId" binding:"required"`
|
||||
Content map[string]any `json:"content" binding:"required"` // 内容
|
||||
Sync bool `json:"sync"` // 同步到网元
|
||||
}
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
@@ -196,7 +223,7 @@ func (s *NeInfoController) ConfigFileWrite(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err := s.neInfoService.NeConfigFileWirte(neInfo, body.FilePath, body.Content, body.Sync)
|
||||
err := s.neInfoService.NeConfOAMSync(neInfo, body.Content, body.Sync)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
@@ -260,22 +287,53 @@ func (s *NeInfoController) Add(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 获取网元状态是否正常
|
||||
_, err = neService.NeState(body)
|
||||
body.ServerState, err = neService.NeState(body)
|
||||
if err != nil {
|
||||
body.Status = "1"
|
||||
body.Status = "0"
|
||||
} else {
|
||||
// 下发网管配置信息给网元
|
||||
_, err = neService.NeConfigOMC(body)
|
||||
if err == nil {
|
||||
body.Status = "0"
|
||||
body.Status = "1"
|
||||
} else {
|
||||
body.Status = "3"
|
||||
body.Status = "2"
|
||||
}
|
||||
}
|
||||
|
||||
loginUserName := ctx.LoginUserToUserName(c)
|
||||
// 新增Version信息
|
||||
neVersion := model.NeVersion{
|
||||
NeType: body.NeType,
|
||||
NeId: body.NeId,
|
||||
CreateBy: loginUserName,
|
||||
}
|
||||
// 新增License信息
|
||||
neLicense := model.NeLicense{
|
||||
NeType: body.NeType,
|
||||
NeId: body.NeId,
|
||||
CreateBy: loginUserName,
|
||||
}
|
||||
|
||||
// 已有网元可获取的信息
|
||||
if body.ServerState != nil {
|
||||
if v, ok := body.ServerState["version"]; ok && v != nil {
|
||||
neVersion.Version = v.(string)
|
||||
}
|
||||
if v, ok := body.ServerState["sn"]; ok && v != nil {
|
||||
neLicense.SerialNum = v.(string)
|
||||
}
|
||||
if v, ok := body.ServerState["expire"]; ok && v != nil {
|
||||
neLicense.ExpiryDate = v.(string)
|
||||
neLicense.Status = "1"
|
||||
}
|
||||
}
|
||||
|
||||
s.neVersionService.Insert(neVersion)
|
||||
s.neLicenseService.Insert(neLicense)
|
||||
body.CreateBy = loginUserName
|
||||
insertId := s.neInfoService.Insert(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, result.OkData(insertId))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
@@ -294,8 +352,8 @@ func (s *NeInfoController) Edit(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueHostCmd := s.neInfoService.CheckUniqueNeTypeAndNeId(body.NeType, body.NeId, body.ID)
|
||||
if !uniqueHostCmd {
|
||||
uniqueInfo := s.neInfoService.CheckUniqueNeTypeAndNeId(body.NeType, body.NeId, body.ID)
|
||||
if !uniqueInfo {
|
||||
// 网元信息操作【%s】失败,同类型下标识已存在
|
||||
msg := i18n.TTemplate(language, "neInfo.errKeyExists", map[string]any{"key": body.NeId})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
@@ -309,21 +367,64 @@ func (s *NeInfoController) Edit(c *gin.Context) {
|
||||
c.JSON(200, result.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
|
||||
}
|
||||
}
|
||||
|
||||
// 获取网元状态是否正常
|
||||
_, err = neService.NeState(body)
|
||||
body.ServerState, err = neService.NeState(body)
|
||||
if err != nil {
|
||||
body.Status = "1"
|
||||
body.Status = "0"
|
||||
} else {
|
||||
// 下发网管配置信息给网元
|
||||
_, err = neService.NeConfigOMC(body)
|
||||
if err == nil {
|
||||
body.Status = "0"
|
||||
body.Status = "1"
|
||||
} else {
|
||||
body.Status = "3"
|
||||
body.Status = "2"
|
||||
}
|
||||
}
|
||||
|
||||
loginUserName := ctx.LoginUserToUserName(c)
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||
neVersion := s.neVersionService.SelectByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||
|
||||
// 已有网元可获取的信息
|
||||
if body.ServerState != nil {
|
||||
if v, ok := body.ServerState["version"]; ok && v != nil {
|
||||
neVersion.Version = v.(string)
|
||||
neVersion.UpdateBy = loginUserName
|
||||
}
|
||||
if v, ok := body.ServerState["sn"]; ok && v != nil {
|
||||
neLicense.SerialNum = v.(string)
|
||||
}
|
||||
if v, ok := body.ServerState["expire"]; ok && v != nil {
|
||||
neLicense.ExpiryDate = v.(string)
|
||||
neLicense.Status = "1"
|
||||
neLicense.UpdateBy = loginUserName
|
||||
}
|
||||
}
|
||||
|
||||
if neVersion.ID != "" {
|
||||
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.NeType != body.NeType || neLicense.NeId != body.NeId {
|
||||
neLicense.NeType = body.NeType
|
||||
neLicense.NeId = body.NeId
|
||||
}
|
||||
s.neLicenseService.Update(neLicense)
|
||||
}
|
||||
|
||||
body.UpdateBy = loginUserName
|
||||
rows := s.neInfoService.Update(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
|
||||
@@ -2,11 +2,9 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"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"
|
||||
@@ -37,6 +35,14 @@ func (s *NeLicenseController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.neLicenseService.SelectPage(querys)
|
||||
|
||||
// 过滤屏蔽授权文件
|
||||
rows := data["rows"].([]model.NeLicense)
|
||||
arr := &rows
|
||||
for i := range *arr {
|
||||
(*arr)[i].ActivationRequestCode = "-"
|
||||
(*arr)[i].LicensePath = "-"
|
||||
}
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
@@ -61,109 +67,28 @@ func (s *NeLicenseController) Info(c *gin.Context) {
|
||||
c.JSON(200, result.OkData(neLicense))
|
||||
}
|
||||
|
||||
// 网元授权激活信息新增
|
||||
// 网元neType和neID查询
|
||||
//
|
||||
// POST /
|
||||
func (s *NeLicenseController) Add(c *gin.Context) {
|
||||
// GET /byTypeAndID
|
||||
func (s *NeLicenseController) NeTypeAndID(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeLicense
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID != "" {
|
||||
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")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
if neInfo.NeId != body.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueInfo := s.neLicenseService.CheckUniqueTypeAndID(neInfo.NeType, neInfo.NeId, "")
|
||||
if !uniqueInfo {
|
||||
// 网元授权激活操作【%s】失败,网元类型信息已存在
|
||||
msg := i18n.TTemplate(language, "neLicense.errKeyExists", map[string]any{"name": neInfo.NeType})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 读取授权码
|
||||
code, _ := s.neLicenseService.ReadLicenseInfo(neInfo)
|
||||
body.ActivationRequestCode = code
|
||||
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
insertId := s.neLicenseService.Insert(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元授权激活信息修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *NeLicenseController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeLicense
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueInfo := s.neLicenseService.CheckUniqueTypeAndID(body.NeType, body.NeId, body.ID)
|
||||
if !uniqueInfo {
|
||||
// 网元授权激活操作【%s】失败,网元类型信息已存在
|
||||
msg := i18n.TTemplate(language, "neLicense.errKeyExists", map[string]any{"name": body.NeType})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neLicense := s.neLicenseService.SelectById(body.ID)
|
||||
if neLicense.ID != body.ID {
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
if neLicense.NeId != querys.NeId {
|
||||
// 没有可访问网元授权激活数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.neLicenseService.Update(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元授权激活信息删除
|
||||
//
|
||||
// DELETE /:licenseIds
|
||||
func (s *NeLicenseController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
licenseIds := c.Param("licenseIds")
|
||||
if licenseIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(licenseIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.neLicenseService.DeleteByIds(uniqueIDs)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
c.JSON(200, result.OkData(neLicense))
|
||||
}
|
||||
|
||||
// 网元授权激活授权申请码
|
||||
@@ -180,15 +105,8 @@ func (s *NeLicenseController) Code(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
if neInfo.NeId != querys.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在授权记录
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
if neLicense.NeId != querys.NeId {
|
||||
// 没有可访问网元授权激活数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
@@ -196,7 +114,7 @@ func (s *NeLicenseController) Code(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 更新授权码
|
||||
code, licensePath := s.neLicenseService.ReadLicenseInfo(neInfo)
|
||||
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
|
||||
neLicense.ActivationRequestCode = code
|
||||
if licensePath != "" {
|
||||
neLicense.LicensePath = licensePath
|
||||
@@ -218,7 +136,7 @@ func (s *NeLicenseController) Change(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeLicense
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.HostId == "" {
|
||||
if err != nil || body.LicensePath == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
@@ -226,23 +144,30 @@ func (s *NeLicenseController) Change(c *gin.Context) {
|
||||
// 检查是否存在授权记录
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
if neLicense.NeId != body.NeId {
|
||||
body.Status = "0"
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
body.ID = s.neLicenseService.Insert(body)
|
||||
} else {
|
||||
neLicense.LicensePath = body.LicensePath
|
||||
neLicense.Status = "0"
|
||||
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
s.neLicenseService.Update(neLicense)
|
||||
}
|
||||
|
||||
// 进行上传替换
|
||||
err = s.neLicenseService.UploadToNeHost(body)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
// 没有可访问网元授权激活数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
|
||||
// 更新授权记录
|
||||
if body.Remark != "" {
|
||||
neLicense.Remark = body.Remark
|
||||
}
|
||||
neLicense.LicensePath = body.LicensePath
|
||||
neLicense.Status = "0"
|
||||
neLicense.UpdateBy = ctx.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()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元授权激活状态
|
||||
@@ -259,43 +184,41 @@ func (s *NeLicenseController) State(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
if neInfo.NeId != querys.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在授权记录
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
if neLicense.NeId != querys.NeId {
|
||||
// 没有可访问网元授权激活数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元状态
|
||||
neState, err := neService.NeState(neInfo)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg("network element service anomaly"))
|
||||
// 查询网元获取IP获取网元状态
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(neLicense.NeType, neLicense.NeId)
|
||||
if neInfo.NeId != neLicense.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
if neState, err := neService.NeState(neInfo); err == nil {
|
||||
neLicense.Status = "1"
|
||||
neLicense.SerialNum = fmt.Sprint(neState["sn"])
|
||||
neLicense.ExpiryDate = fmt.Sprint(neState["expire"])
|
||||
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
|
||||
neLicense.ActivationRequestCode = code
|
||||
neLicense.LicensePath = licensePath
|
||||
} else {
|
||||
neLicense.Status = "0"
|
||||
}
|
||||
|
||||
// 更新授权信息
|
||||
neLicense.SerialNum = fmt.Sprint(neState["sn"])
|
||||
neLicense.ExpiryDate = fmt.Sprint(neState["expire"])
|
||||
code, licensePath := s.neLicenseService.ReadLicenseInfo(neInfo)
|
||||
neLicense.ActivationRequestCode = code
|
||||
neLicense.LicensePath = licensePath
|
||||
neLicense.Status = "1"
|
||||
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.neLicenseService.Update(neLicense)
|
||||
if rows > 0 {
|
||||
s.neLicenseService.Update(neLicense)
|
||||
|
||||
if neLicense.Status == "1" {
|
||||
c.JSON(200, result.OkData(map[string]string{
|
||||
"sn": neLicense.SerialNum,
|
||||
"expire": neLicense.ExpiryDate,
|
||||
}))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, result.ErrMsg(fmt.Sprintf("%s service status exception", neLicense.NeType)))
|
||||
}
|
||||
|
||||
@@ -69,15 +69,26 @@ func (s *NeSoftwareController) Add(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueSoftware := s.neSoftwareService.CheckUniqueTypeAndNameAndVersion(body.NeType, body.Name, body.Version, "")
|
||||
if !uniqueSoftware {
|
||||
// 网元软件包操作【%s】失败,网元类型与文件名版本已存在
|
||||
msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.Name})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
// 找到已存在的删除后重新添加
|
||||
neSoftwares := s.neSoftwareService.SelectList(model.NeSoftware{
|
||||
NeType: body.NeType,
|
||||
Name: body.Name,
|
||||
Version: body.Version,
|
||||
})
|
||||
if len(neSoftwares) > 0 {
|
||||
neSoftware := neSoftwares[0]
|
||||
s.neSoftwareService.DeleteByIds([]string{neSoftware.ID})
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
// uniqueSoftware := s.neSoftwareService.CheckUniqueTypeAndNameAndVersion(body.NeType, body.Name, body.Version, "")
|
||||
// if !uniqueSoftware {
|
||||
// // 网元软件包操作【%s】失败,网元类型与文件名版本已存在
|
||||
// msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.Name})
|
||||
// c.JSON(200, result.ErrMsg(msg))
|
||||
// return
|
||||
// }
|
||||
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
insertId := s.neSoftwareService.Insert(body)
|
||||
if insertId != "" {
|
||||
@@ -151,40 +162,32 @@ func (s *NeSoftwareController) Remove(c *gin.Context) {
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
}
|
||||
|
||||
// 网元软件包安装检查
|
||||
// 网元软件包设为网元新版本
|
||||
//
|
||||
// POST /checkInstall
|
||||
func (s *NeSoftwareController) CheckInstall(c *gin.Context) {
|
||||
// POST /newNeVersion
|
||||
func (s *NeSoftwareController) NewNeVersion(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeSoftware
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.HostId == "" {
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在软件包记录
|
||||
// 找到已存在的软件包信息
|
||||
neSoftwares := s.neSoftwareService.SelectList(model.NeSoftware{
|
||||
NeType: body.NeType,
|
||||
Name: body.Name,
|
||||
Version: body.Version,
|
||||
})
|
||||
if len(neSoftwares) <= 0 {
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
body.ID = s.neSoftwareService.Insert(body)
|
||||
} else {
|
||||
if len(neSoftwares) > 0 {
|
||||
neSoftware := neSoftwares[0]
|
||||
neSoftware.Path = body.Path
|
||||
neSoftware.Description = body.Description
|
||||
neSoftware.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
s.neSoftwareService.Update(neSoftware)
|
||||
}
|
||||
|
||||
// 进行安装检查
|
||||
cmdStrArr, err := s.neSoftwareService.UploadToNeHost(body)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
s.neSoftwareService.UpdateVersions(neSoftware, model.NeVersion{
|
||||
NeType: neSoftware.NeType,
|
||||
UpdateBy: ctx.LoginUserToUserName(c),
|
||||
})
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(cmdStrArr))
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"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"
|
||||
@@ -57,96 +53,34 @@ func (s *NeVersionController) Info(c *gin.Context) {
|
||||
c.JSON(200, result.OkData(neVersion))
|
||||
}
|
||||
|
||||
// 网元版本信息新增
|
||||
// 网元版本操作
|
||||
//
|
||||
// POST /
|
||||
func (s *NeVersionController) Add(c *gin.Context) {
|
||||
// POST /operate
|
||||
func (s *NeVersionController) Operate(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeVersion
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID != "" {
|
||||
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")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueInfo := s.neVersionService.CheckUniqueTypeAndID(body.NeType, body.NeId, "")
|
||||
if !uniqueInfo {
|
||||
// 网元版本操作【%s】失败,网元类型信息已存在
|
||||
msg := i18n.TTemplate(language, "neVersion.errKeyExists", map[string]any{"name": body.NeType})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
insertId := s.neVersionService.Insert(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元版本信息修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *NeVersionController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeVersion
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueInfo := s.neVersionService.CheckUniqueTypeAndID(body.NeType, body.NeId, body.ID)
|
||||
if !uniqueInfo {
|
||||
// 网元版本操作【%s】失败,网元类型信息已存在
|
||||
msg := i18n.TTemplate(language, "neVersion.errKeyExists", map[string]any{"name": body.NeType})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neVersion := s.neVersionService.SelectById(body.ID)
|
||||
if neVersion.ID != body.ID {
|
||||
neVersion := s.neVersionService.SelectByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
if neVersion.NeId != body.NeId {
|
||||
// 没有可访问网元版本数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neVersion.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.neVersionService.Update(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元版本信息删除
|
||||
//
|
||||
// DELETE /:versionIds
|
||||
func (s *NeVersionController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
versionIds := c.Param("versionIds")
|
||||
if versionIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(versionIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.neVersionService.DeleteByIds(uniqueIDs)
|
||||
// 进行相关命令操作
|
||||
output, err := s.neVersionService.Operate(body.Action, neVersion, body.Preinput)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
c.JSON(200, result.OkData(output))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user