marge: 合并代码,包名变更be.ems
This commit is contained in:
@@ -5,13 +5,12 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/config"
|
||||
"ems.agt/src/framework/i18n"
|
||||
"ems.agt/src/framework/utils/ctx"
|
||||
"ems.agt/src/framework/utils/file"
|
||||
"ems.agt/src/framework/utils/ssh"
|
||||
"ems.agt/src/framework/vo/result"
|
||||
neService "ems.agt/src/modules/network_element/service"
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"be.ems/src/framework/utils/ssh"
|
||||
"be.ems/src/framework/vo/result"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
@@ -23,7 +22,7 @@ var NewNeAction = &NeActionController{
|
||||
|
||||
// 网元处理请求
|
||||
//
|
||||
// PATH /
|
||||
// PATH /action
|
||||
type NeActionController struct {
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
@@ -53,7 +52,7 @@ func (s *NeActionController) PushFile(c *gin.Context) {
|
||||
|
||||
// 本地文件
|
||||
localPath := file.ParseUploadFilePath(body.UploadPath)
|
||||
nePath := config.Get("mml.upload").(string)
|
||||
nePath := "/tmp" //config.Get("mml.upload").(string)
|
||||
// 复制到远程
|
||||
err := ssh.FileSCPLocalToNe(neInfo.IP, localPath, nePath)
|
||||
if err != nil {
|
||||
@@ -67,7 +66,7 @@ func (s *NeActionController) PushFile(c *gin.Context) {
|
||||
c.JSON(200, result.OkData(filepath.ToSlash(neFilePath)))
|
||||
}
|
||||
|
||||
// 从网元端获取文件
|
||||
// 获取文件从网元到本地
|
||||
//
|
||||
// GET /pullFile
|
||||
func (s *NeActionController) PullFile(c *gin.Context) {
|
||||
|
||||
356
src/modules/network_element/controller/ne_host.go
Normal file
356
src/modules/network_element/controller/ne_host.go
Normal file
@@ -0,0 +1,356 @@
|
||||
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/utils/ssh"
|
||||
"be.ems/src/framework/utils/telnet"
|
||||
"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 结构体
|
||||
var NewNeHost = &NeHostController{
|
||||
neHostService: neService.NewNeHostImpl,
|
||||
}
|
||||
|
||||
// 网元主机连接请求
|
||||
//
|
||||
// PATH /host
|
||||
type NeHostController struct {
|
||||
// 网元主机连接服务
|
||||
neHostService neService.INeHost
|
||||
}
|
||||
|
||||
// 网元主机列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *NeHostController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.neHostService.SelectPage(querys)
|
||||
|
||||
rows := data["rows"].([]model.NeHost)
|
||||
arr := &rows
|
||||
for i := range *arr {
|
||||
(*arr)[i].Password = "-"
|
||||
(*arr)[i].PrivateKey = "-"
|
||||
(*arr)[i].PassPhrase = "-"
|
||||
}
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// 网元主机信息
|
||||
//
|
||||
// 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")))
|
||||
return
|
||||
}
|
||||
|
||||
neHost := s.neHostService.SelectById(hostId)
|
||||
if neHost.HostID != hostId {
|
||||
// 没有可访问主机信息数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(neHost))
|
||||
}
|
||||
|
||||
// 网元主机新增
|
||||
//
|
||||
// POST /
|
||||
func (s *NeHostController) Add(c *gin.Context) {
|
||||
language := ctx.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")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueHost := s.neHostService.CheckUniqueHostTitle(body.GroupID, body.Title, body.HostType, "")
|
||||
if !uniqueHost {
|
||||
// 主机信息操作【%s】失败,同组内名称已存在
|
||||
msg := i18n.TTemplate(language, "neHost.errKeyExists", map[string]any{"name": body.Title})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
insertId := s.neHostService.Insert(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元主机修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *NeHostController) Edit(c *gin.Context) {
|
||||
language := ctx.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")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueHost := s.neHostService.CheckUniqueHostTitle(body.GroupID, body.Title, body.HostType, body.HostID)
|
||||
if !uniqueHost {
|
||||
// 主机信息操作【%s】失败,同组内名称已存在
|
||||
msg := i18n.TTemplate(language, "neHost.errKeyExists", map[string]any{"name": body.Title})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neHost := s.neHostService.SelectById(body.HostID)
|
||||
if neHost.HostID != body.HostID {
|
||||
// 没有可访问主机信息数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.neHostService.Update(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.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")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(hostIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.neHostService.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))
|
||||
}
|
||||
|
||||
// 网元主机测试连接
|
||||
//
|
||||
// POST /test
|
||||
func (s *NeHostController) Test(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeHost
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
if body.HostType == "ssh" {
|
||||
var connSSH ssh.ConnSSH
|
||||
body.CopyTo(&connSSH)
|
||||
|
||||
client, err := connSSH.NewClient()
|
||||
if err != nil {
|
||||
// 连接主机失败,请检查连接参数后重试
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
|
||||
if body.HostType == "telnet" {
|
||||
var connTelnet telnet.ConnTelnet
|
||||
body.CopyTo(&connTelnet)
|
||||
|
||||
client, err := connTelnet.NewClient()
|
||||
if err != nil {
|
||||
// 连接主机失败,请检查连接参数后重试
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 网元主机发送命令
|
||||
//
|
||||
// POST /cmd
|
||||
func (s *NeHostController) Cmd(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
HostID string `json:"hostId" binding:"required"` // 主机ID
|
||||
Cmd string `json:"cmd" binding:"required"` // 执行命令
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neHost := s.neHostService.SelectById(body.HostID)
|
||||
if neHost.HostID != body.HostID {
|
||||
// 没有可访问主机信息数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
if neHost.HostType == "ssh" {
|
||||
var connSSH ssh.ConnSSH
|
||||
neHost.CopyTo(&connSSH)
|
||||
|
||||
client, err := connSSH.NewClient()
|
||||
if err != nil {
|
||||
// 连接主机失败,请检查连接参数后重试
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
// 执行命令
|
||||
output, err := client.RunCMD(body.Cmd)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(output))
|
||||
return
|
||||
}
|
||||
|
||||
if neHost.HostType == "telnet" {
|
||||
var connTelnet telnet.ConnTelnet
|
||||
neHost.CopyTo(&connTelnet)
|
||||
|
||||
client, err := connTelnet.NewClient()
|
||||
if err != nil {
|
||||
// 连接主机失败,请检查连接参数后重试
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
// 执行命令
|
||||
output, err := client.RunCMD(body.Cmd)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(output))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 网元主机SSH方式检查服务器环境
|
||||
//
|
||||
// POST /checkBySSH
|
||||
func (s *NeHostController) CheckBySSH(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeHost
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if 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()
|
||||
if err != nil {
|
||||
// 连接主机失败,请检查连接参数后重试
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
// 结果信息数据
|
||||
data := map[string]any{
|
||||
"addr": body.Addr, // 服务器地址
|
||||
"kernelName": "-", // 内核名称 -s
|
||||
"nodename": "-", // 网络节点主机名 -n
|
||||
"kernelRelease": "-", // 内核发布版本 -r
|
||||
"machine": "-", // 机器硬件名称 -m
|
||||
"prettyName": "-", // 系统发行版本
|
||||
"sudo": false, // 可提权
|
||||
"sshLink": false, // 可直连
|
||||
}
|
||||
|
||||
// 执行命令 检查系统环境
|
||||
output, err := client.RunCMD("uname -snrm && cat /etc/os-release | grep PRETTY_NAME")
|
||||
if err != nil {
|
||||
c.JSON(200, result.OkData(data))
|
||||
return
|
||||
}
|
||||
output = strings.TrimSuffix(output, "\n")
|
||||
sysInfoArr := strings.SplitN(output, "\n", 2)
|
||||
if len(sysInfoArr) == 2 {
|
||||
// uname -snrm
|
||||
baseInfoArr := strings.SplitN(sysInfoArr[0], " ", 4)
|
||||
data["kernelName"] = baseInfoArr[0]
|
||||
data["nodename"] = baseInfoArr[1]
|
||||
data["kernelRelease"] = baseInfoArr[2]
|
||||
data["machine"] = baseInfoArr[3]
|
||||
// cat /etc/os-release | grep PRETTY_NAME
|
||||
prettyName := sysInfoArr[1]
|
||||
index := strings.Index(prettyName, `"`)
|
||||
if index != -1 {
|
||||
data["prettyName"] = prettyName[index+1 : len(prettyName)-1]
|
||||
}
|
||||
}
|
||||
// 执行命令 检查sudo权限
|
||||
_, err = client.RunCMD("sudo -n uname")
|
||||
if err == nil {
|
||||
data["sudo"] = true
|
||||
} else {
|
||||
data["sudo"] = false
|
||||
}
|
||||
|
||||
// 本地免密创建链接直连
|
||||
lcoalConnSSH := ssh.ConnSSH{
|
||||
User: body.User,
|
||||
Addr: body.Addr,
|
||||
Port: body.Port,
|
||||
}
|
||||
lcoalClient, err := lcoalConnSSH.NewClientByLocalPrivate()
|
||||
if err == nil {
|
||||
data["sshLink"] = true
|
||||
} else {
|
||||
data["sshLink"] = false
|
||||
}
|
||||
defer lcoalClient.Close()
|
||||
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
152
src/modules/network_element/controller/ne_host_cmd.go
Normal file
152
src/modules/network_element/controller/ne_host_cmd.go
Normal file
@@ -0,0 +1,152 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// 实例化控制层 NeHostCmdController 结构体
|
||||
var NewNeHostCmd = &NeHostCmdController{
|
||||
neHostCmdService: neService.NewNeHostCmdImpl,
|
||||
}
|
||||
|
||||
// 网元主机命令请求
|
||||
//
|
||||
// PATH /hostCmd
|
||||
type NeHostCmdController struct {
|
||||
// 网元主机命令服务
|
||||
neHostCmdService neService.INeHostCmd
|
||||
}
|
||||
|
||||
// 网元主机命令列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *NeHostCmdController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.neHostCmdService.SelectPage(querys)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// 网元主机命令信息
|
||||
//
|
||||
// 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")))
|
||||
return
|
||||
}
|
||||
|
||||
neHost := s.neHostCmdService.SelectById(cmdId)
|
||||
if neHost.CmdID != cmdId {
|
||||
// 没有可访问主机命令数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHostCmd.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(neHost))
|
||||
}
|
||||
|
||||
// 网元主机命令新增
|
||||
//
|
||||
// POST /
|
||||
func (s *NeHostCmdController) Add(c *gin.Context) {
|
||||
language := ctx.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")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueHostCmd := s.neHostCmdService.CheckUniqueGroupTitle(body.GroupID, body.Title, body.CmdType, "")
|
||||
if !uniqueHostCmd {
|
||||
// 主机命令操作【%s】失败,同组内名称已存在
|
||||
msg := i18n.TTemplate(language, "neHostCmd.errKeyExists", map[string]any{"name": body.Title})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
insertId := s.neHostCmdService.Insert(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元主机命令修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *NeHostCmdController) Edit(c *gin.Context) {
|
||||
language := ctx.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")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueHostCmd := s.neHostCmdService.CheckUniqueGroupTitle(body.GroupID, body.Title, body.CmdType, body.CmdID)
|
||||
if !uniqueHostCmd {
|
||||
// 主机命令操作【%s】失败,同组内名称已存在
|
||||
msg := i18n.TTemplate(language, "neHostCmd.errKeyExists", map[string]any{"name": body.Title})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neHost := s.neHostCmdService.SelectById(body.CmdID)
|
||||
if neHost.CmdID != body.CmdID {
|
||||
// 没有可访问主机命令数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHostCmd.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.neHostCmdService.Update(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.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")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(cmdIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.neHostCmdService.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))
|
||||
}
|
||||
@@ -2,15 +2,17 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"ems.agt/src/framework/i18n"
|
||||
"ems.agt/src/framework/utils/ctx"
|
||||
"ems.agt/src/framework/utils/parse"
|
||||
"ems.agt/src/framework/vo/result"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
neService "ems.agt/src/modules/network_element/service"
|
||||
"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"
|
||||
)
|
||||
|
||||
// 实例化控制层 NeInfoController 结构体
|
||||
@@ -30,10 +32,10 @@ type NeInfoController struct {
|
||||
var neStateCacheMap sync.Map
|
||||
var mutex sync.Mutex
|
||||
|
||||
// 网元状态
|
||||
// 网元信息状态
|
||||
//
|
||||
// GET /state
|
||||
func (s *NeInfoController) NeState(c *gin.Context) {
|
||||
func (s *NeInfoController) State(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"`
|
||||
@@ -82,32 +84,23 @@ func (s *NeInfoController) NeState(c *gin.Context) {
|
||||
c.JSON(200, result.OkData(resData))
|
||||
}
|
||||
|
||||
// 网元neType和neID查询
|
||||
//
|
||||
// GET /info
|
||||
func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
|
||||
language := ctx.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")))
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
c.JSON(200, result.OkData(neInfo))
|
||||
}
|
||||
|
||||
// 网元列表
|
||||
// 网元信息列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *NeInfoController) NeList(c *gin.Context) {
|
||||
func (s *NeInfoController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
bandStatus := false
|
||||
if v, ok := querys["bandStatus"]; ok && v != nil {
|
||||
bandStatus = parse.Boolean(v)
|
||||
}
|
||||
data := s.neInfoService.SelectPage(querys, bandStatus)
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// 网元信息列表全部无分页
|
||||
//
|
||||
// GET /listAll
|
||||
func (s *NeInfoController) ListAll(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType"`
|
||||
@@ -128,10 +121,173 @@ func (s *NeInfoController) NeList(c *gin.Context) {
|
||||
ne.NeId = querys.NeId
|
||||
}
|
||||
bandStatus := parse.Boolean(querys.BandStatus)
|
||||
neList := s.neInfoService.SelectNeList(ne, bandStatus)
|
||||
neList := s.neInfoService.SelectList(ne, bandStatus)
|
||||
if len(neList) == 0 {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(neList))
|
||||
}
|
||||
|
||||
// 网元信息
|
||||
//
|
||||
// GET /:infoId
|
||||
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")))
|
||||
return
|
||||
}
|
||||
|
||||
neHost := s.neInfoService.SelectById(infoId, true)
|
||||
if neHost.ID != infoId {
|
||||
// 没有可访问网元信息数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neInfo.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(neHost))
|
||||
}
|
||||
|
||||
// 网元neType和neID查询
|
||||
//
|
||||
// GET /
|
||||
func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
|
||||
language := ctx.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")))
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
c.JSON(200, result.OkData(neInfo))
|
||||
}
|
||||
|
||||
// 网元信息新增
|
||||
//
|
||||
// POST /
|
||||
func (s *NeInfoController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeInfo
|
||||
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.neInfoService.CheckUniqueNeTypeAndNeId(body.NeType, body.NeId, "")
|
||||
if !uniqueInfo {
|
||||
// 网元信息操作【%s】失败,同类型下标识已存在
|
||||
msg := i18n.TTemplate(language, "neInfo.errKeyExists", map[string]any{"key": body.NeId})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 获取网元状态是否正常
|
||||
_, err = neService.NeState(body)
|
||||
if err != nil {
|
||||
body.Status = "1"
|
||||
} else {
|
||||
// 下发网管配置信息给网元
|
||||
_, err = neService.NeConfigOMC(body)
|
||||
if err == nil {
|
||||
body.Status = "0"
|
||||
} else {
|
||||
body.Status = "3"
|
||||
}
|
||||
}
|
||||
|
||||
insertId := s.neInfoService.Insert(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元信息修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *NeInfoController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeInfo
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueHostCmd := s.neInfoService.CheckUniqueNeTypeAndNeId(body.NeType, body.NeId, body.ID)
|
||||
if !uniqueHostCmd {
|
||||
// 网元信息操作【%s】失败,同类型下标识已存在
|
||||
msg := i18n.TTemplate(language, "neInfo.errKeyExists", map[string]any{"key": body.NeId})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neInfo := s.neInfoService.SelectById(body.ID, false)
|
||||
if neInfo.ID != body.ID {
|
||||
// 没有可访问网元信息数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neInfo.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
// 获取网元状态是否正常
|
||||
_, err = neService.NeState(body)
|
||||
if err != nil {
|
||||
body.Status = "1"
|
||||
} else {
|
||||
// 下发网管配置信息给网元
|
||||
_, err = neService.NeConfigOMC(body)
|
||||
if err == nil {
|
||||
body.Status = "0"
|
||||
} else {
|
||||
body.Status = "3"
|
||||
}
|
||||
}
|
||||
|
||||
rows := s.neInfoService.Update(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元信息删除
|
||||
//
|
||||
// DELETE /:infoIds
|
||||
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")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(infoIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.neInfoService.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))
|
||||
}
|
||||
|
||||
180
src/modules/network_element/controller/ne_software.go
Normal file
180
src/modules/network_element/controller/ne_software.go
Normal file
@@ -0,0 +1,180 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// 实例化控制层 NeSoftwareController 结构体
|
||||
var NewNeSoftware = &NeSoftwareController{
|
||||
neSoftwareService: neService.NewNeSoftwareImpl,
|
||||
}
|
||||
|
||||
// 网元软件包信息请求
|
||||
//
|
||||
// PATH /software
|
||||
type NeSoftwareController struct {
|
||||
// 网元软件包信息服务
|
||||
neSoftwareService neService.INeSoftware
|
||||
}
|
||||
|
||||
// 网元软件包信息列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *NeSoftwareController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.neSoftwareService.SelectPage(querys)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// 网元软件包信息信息
|
||||
//
|
||||
// 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")))
|
||||
return
|
||||
}
|
||||
|
||||
neSoftware := s.neSoftwareService.SelectById(softwareId)
|
||||
if neSoftware.ID != softwareId {
|
||||
// 没有可访问网元版本数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(neSoftware))
|
||||
}
|
||||
|
||||
// 网元软件包信息新增
|
||||
//
|
||||
// POST /
|
||||
func (s *NeSoftwareController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeSoftware
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID != "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueSoftware := s.neSoftwareService.CheckUniqueTypeAndFileNameAndVersion(body.NeType, body.FileName, body.Version, "")
|
||||
if !uniqueSoftware {
|
||||
// 网元软件包操作【%s】失败,网元类型与文件名版本已存在
|
||||
msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.FileName})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
insertId := s.neSoftwareService.Insert(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 网元软件包信息修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *NeSoftwareController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeSoftware
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueSoftware := s.neSoftwareService.CheckUniqueTypeAndFileNameAndVersion(body.NeType, body.FileName, body.Version, body.ID)
|
||||
if !uniqueSoftware {
|
||||
// 网元软件包操作【%s】失败,网元类型与文件名版本已存在
|
||||
msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.FileName})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neSoftware := s.neSoftwareService.SelectById(body.ID)
|
||||
if neSoftware.ID != body.ID {
|
||||
// 没有可访问网元版本数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
rows := s.neSoftwareService.Update(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.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")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(softwareIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.neSoftwareService.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))
|
||||
}
|
||||
|
||||
// 网元软件包安装
|
||||
//
|
||||
// POST /install
|
||||
func (s *NeSoftwareController) Install(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.NeSoftware
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
neSoftwares := s.neSoftwareService.SelectList(body)
|
||||
if len(neSoftwares) == 0 {
|
||||
// 没有可访问网元版本数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
|
||||
return
|
||||
}
|
||||
neSoftware := neSoftwares[0]
|
||||
|
||||
// 进行安装
|
||||
output, err := s.neSoftwareService.Install(neSoftware)
|
||||
if err != nil {
|
||||
c.JSON(200, result.OkData(output))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
150
src/modules/network_element/controller/ne_version.go
Normal file
150
src/modules/network_element/controller/ne_version.go
Normal file
@@ -0,0 +1,150 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// 实例化控制层 NeVersionController 结构体
|
||||
var NewNeVersion = &NeVersionController{
|
||||
neVersionService: neService.NewNeVersionImpl,
|
||||
}
|
||||
|
||||
// 网元版本信息请求
|
||||
//
|
||||
// PATH /version
|
||||
type NeVersionController struct {
|
||||
// 网元版本信息服务
|
||||
neVersionService neService.INeVersion
|
||||
}
|
||||
|
||||
// 网元版本信息列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *NeVersionController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.neVersionService.SelectPage(querys)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// 网元版本信息信息
|
||||
//
|
||||
// GET /:versionId
|
||||
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")))
|
||||
return
|
||||
}
|
||||
|
||||
neVersion := s.neVersionService.SelectById(versionId)
|
||||
if neVersion.ID != versionId {
|
||||
// 没有可访问网元版本数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neVersion.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(neVersion))
|
||||
}
|
||||
|
||||
// 网元版本信息新增
|
||||
//
|
||||
// POST /
|
||||
func (s *NeVersionController) Add(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, "")
|
||||
if !uniqueInfo {
|
||||
// 网元版本操作【%s】失败,网元类型信息已存在
|
||||
msg := i18n.TTemplate(language, "neVersion.errKeyExists", map[string]any{"name": body.NeType})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
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 {
|
||||
// 没有可访问网元版本数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neVersion.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
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))
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"ems.agt/lib/core/utils/date"
|
||||
"ems.agt/src/framework/i18n"
|
||||
"ems.agt/src/framework/utils/ctx"
|
||||
"ems.agt/src/framework/vo/result"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
neService "ems.agt/src/modules/network_element/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 实例化控制层 PerfKPIController 结构体
|
||||
var NewPerfKPI = &PerfKPIController{
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
perfKPIService: neService.NewPerfKPIImpl,
|
||||
}
|
||||
|
||||
// 性能统计
|
||||
//
|
||||
// PATH /kpi
|
||||
type PerfKPIController struct {
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
// 统计信息服务
|
||||
perfKPIService neService.IPerfKPI
|
||||
}
|
||||
|
||||
// 获取统计数据
|
||||
//
|
||||
// GET /data
|
||||
func (s *PerfKPIController) GoldKPI(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys model.GoldKPIQuery
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 时间格式校验
|
||||
startTime := date.ParseStrToDate(querys.StartTime, date.YYYY_MM_DD_HH_MM_SS)
|
||||
if startTime.IsZero() {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
}
|
||||
endTime := date.ParseStrToDate(querys.EndTime, date.YYYY_MM_DD_HH_MM_SS)
|
||||
if endTime.IsZero() {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
}
|
||||
|
||||
// 查询网元获取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
|
||||
}
|
||||
querys.RmUID = neInfo.RmUID
|
||||
|
||||
// 查询数据
|
||||
kpiData := s.perfKPIService.SelectGoldKPI(querys)
|
||||
c.JSON(200, result.OkData(kpiData))
|
||||
}
|
||||
|
||||
// 获取统计标题
|
||||
//
|
||||
// GET /title
|
||||
func (s *PerfKPIController) Title(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neType := c.Query("neType")
|
||||
if neType == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
kpiTitles := s.perfKPIService.SelectGoldKPITitle(neType)
|
||||
|
||||
c.JSON(200, result.OkData(kpiTitles))
|
||||
}
|
||||
@@ -5,17 +5,16 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mmlclient "ems.agt/lib/core/mml_client"
|
||||
"ems.agt/src/framework/config"
|
||||
"ems.agt/src/framework/constants/uploadsubpath"
|
||||
"ems.agt/src/framework/i18n"
|
||||
"ems.agt/src/framework/utils/ctx"
|
||||
"ems.agt/src/framework/utils/file"
|
||||
"ems.agt/src/framework/utils/parse"
|
||||
"ems.agt/src/framework/utils/ssh"
|
||||
"ems.agt/src/framework/vo/result"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
neService "ems.agt/src/modules/network_element/service"
|
||||
mmlclient "be.ems/lib/core/mml_client"
|
||||
"be.ems/src/framework/constants/uploadsubpath"
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"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"
|
||||
)
|
||||
@@ -377,7 +376,7 @@ func (s *UDMAuthController) Export(c *gin.Context) {
|
||||
data = append(data, []string{v.Imsi, v.Ki, v.AlgoIndex, v.Amf, v.Opc})
|
||||
}
|
||||
// 输出到文件
|
||||
err := file.WriterCSVFile(data, filePath)
|
||||
err := file.WriterFileCSV(data, filePath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
@@ -391,7 +390,7 @@ func (s *UDMAuthController) Export(c *gin.Context) {
|
||||
data = append(data, []string{v.Imsi, v.Ki, v.AlgoIndex, v.Amf, v.Opc})
|
||||
}
|
||||
// 输出到文件
|
||||
err = file.WriterTxtFile(data, filePath)
|
||||
err = file.WriterFileTXT(data, ",", filePath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
@@ -437,7 +436,7 @@ func (s *UDMAuthController) Import(c *gin.Context) {
|
||||
|
||||
// 本地文件
|
||||
localPath := file.ParseUploadFilePath(upFilePath)
|
||||
nePath := config.Get("mml.upload").(string)
|
||||
nePath := "/tmp" //config.Get("mml.upload").(string)
|
||||
// 复制到远程
|
||||
err = ssh.FileSCPLocalToNe(neInfo.IP, localPath, nePath)
|
||||
if err != nil {
|
||||
@@ -458,12 +457,12 @@ func (s *UDMAuthController) Import(c *gin.Context) {
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
if strings.HasSuffix(fileName, ".csv") {
|
||||
data := file.ReadCSVFile(localPath)
|
||||
data := file.ReadFileCSV(localPath)
|
||||
neId = ""
|
||||
go s.udmAuthService.InsertCSV(neId, data)
|
||||
}
|
||||
if strings.HasSuffix(fileName, ".txt") {
|
||||
data := file.ReadTxtFile(localPath)
|
||||
data := file.ReadFileTXT(",", localPath)
|
||||
neId = ""
|
||||
go s.udmAuthService.InsertTxt(neId, data)
|
||||
}
|
||||
|
||||
@@ -6,17 +6,16 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mmlclient "ems.agt/lib/core/mml_client"
|
||||
"ems.agt/src/framework/config"
|
||||
"ems.agt/src/framework/constants/uploadsubpath"
|
||||
"ems.agt/src/framework/i18n"
|
||||
"ems.agt/src/framework/utils/ctx"
|
||||
"ems.agt/src/framework/utils/file"
|
||||
"ems.agt/src/framework/utils/parse"
|
||||
"ems.agt/src/framework/utils/ssh"
|
||||
"ems.agt/src/framework/vo/result"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
neService "ems.agt/src/modules/network_element/service"
|
||||
mmlclient "be.ems/lib/core/mml_client"
|
||||
"be.ems/src/framework/constants/uploadsubpath"
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"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"
|
||||
)
|
||||
@@ -454,7 +453,7 @@ func (s *UDMSubController) Export(c *gin.Context) {
|
||||
data = append(data, []string{v.Imsi, v.Msisdn, v.Ambr, v.Nssai, v.Arfb, v.Sar, v.Rat, v.Cn, v.SmfSel, v.SmData, epsDat})
|
||||
}
|
||||
// 输出到文件
|
||||
err = file.WriterCSVFile(data, filePath)
|
||||
err = file.WriterFileCSV(data, filePath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
@@ -469,7 +468,7 @@ func (s *UDMSubController) Export(c *gin.Context) {
|
||||
data = append(data, []string{v.Imsi, v.Msisdn, v.Ambr, v.Nssai, v.Arfb, v.Sar, v.Rat, v.Cn, v.SmfSel, v.SmData, epsDat})
|
||||
}
|
||||
// 输出到文件
|
||||
err = file.WriterTxtFile(data, filePath)
|
||||
err = file.WriterFileTXT(data, ",", filePath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
@@ -515,7 +514,7 @@ func (s *UDMSubController) Import(c *gin.Context) {
|
||||
|
||||
// 本地文件
|
||||
localPath := file.ParseUploadFilePath(upFilePath)
|
||||
nePath := config.Get("mml.upload").(string)
|
||||
nePath := "/tmp" //config.Get("mml.upload").(string)
|
||||
// 复制到远程
|
||||
err = ssh.FileSCPLocalToNe(neInfo.IP, localPath, nePath)
|
||||
if err != nil {
|
||||
@@ -536,12 +535,12 @@ func (s *UDMSubController) Import(c *gin.Context) {
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
if strings.HasSuffix(fileName, ".csv") {
|
||||
data := file.ReadCSVFile(localPath)
|
||||
data := file.ReadFileCSV(localPath)
|
||||
neId = ""
|
||||
go s.udmSubService.InsertCSV(neId, data)
|
||||
}
|
||||
if strings.HasSuffix(fileName, ".txt") {
|
||||
data := file.ReadTxtFile(localPath)
|
||||
data := file.ReadFileTXT(",", localPath)
|
||||
neId = ""
|
||||
go s.udmSubService.InsertTxt(neId, data)
|
||||
}
|
||||
|
||||
40
src/modules/network_element/model/ne_host.go
Normal file
40
src/modules/network_element/model/ne_host.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// NeHost 网元主机表 ne_host
|
||||
type NeHost struct {
|
||||
HostID string `json:"hostId" gorm:"column:host_id"` // 主机主键
|
||||
HostType string `json:"hostType" gorm:"column:host_type" binding:"oneof=ssh telnet"` // 主机类型 ssh telnet
|
||||
GroupID string `json:"groupId" gorm:"column:group_id"` // 分组(0默认 1网元 2系统)
|
||||
Title string `json:"title" gorm:"column:title"` // 标题名称
|
||||
Addr string `json:"addr" gorm:"column:addr" binding:"required"` // 主机地址
|
||||
Port int64 `json:"port" gorm:"column:port" binding:"required,number,max=65535,min=1"` // SSH端口
|
||||
User string `json:"user" gorm:"column:user" binding:"required"` // 主机用户名
|
||||
AuthMode string `json:"authMode" gorm:"column:auth_mode" binding:"oneof=0 1"` // 认证模式(0密码 1主机私钥)
|
||||
Password string `json:"password" gorm:"column:password"` // 认证密码
|
||||
PrivateKey string `json:"privateKey" gorm:"column:private_key"` // 认证私钥
|
||||
PassPhrase string `json:"passPhrase" gorm:"column:pass_phrase"` // 认证私钥密码
|
||||
Remark string `json:"remark" gorm:"column:remark"` // 备注
|
||||
CreateBy string `json:"createBy" gorm:"column:create_by"` // 创建者
|
||||
CreateTime int64 `json:"createTime" gorm:"column:create_time"` // 创建时间
|
||||
UpdateBy string `json:"updateBy" gorm:"column:update_by"` // 更新者
|
||||
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
|
||||
}
|
||||
|
||||
// TableName 表名称
|
||||
func (NeHost) TableName() string {
|
||||
return "ne_host"
|
||||
}
|
||||
|
||||
// CopyTo 网元主机信息将josn同key名的结构体复制给另一个结构体
|
||||
func (m *NeHost) CopyTo(to interface{}) error {
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = json.Unmarshal(b, to); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
20
src/modules/network_element/model/ne_host_cmd.go
Normal file
20
src/modules/network_element/model/ne_host_cmd.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package model
|
||||
|
||||
// NeHostCmd 网元主机命令表 ne_host_cmd
|
||||
type NeHostCmd struct {
|
||||
CmdID string `json:"cmdId" gorm:"column:cmd_id"` // 命令主键
|
||||
CmdType string `json:"cmdType" gorm:"column:cmd_type"` // 命令类型
|
||||
GroupID string `json:"groupId" gorm:"column:group_id"` // 分组(0默认 1快速命令)
|
||||
Title string `json:"title" gorm:"column:title" binding:"required"` // 标题名称
|
||||
Command string `json:"command" gorm:"column:command" binding:"required"` // 命令字符串
|
||||
Remark string `json:"remark" gorm:"column:remark"` // 备注
|
||||
CreateBy string `json:"createBy" gorm:"column:create_by"` // 创建者
|
||||
CreateTime int64 `json:"createTime" gorm:"column:create_time"` // 创建时间
|
||||
UpdateBy string `json:"updateBy" gorm:"column:update_by"` // 更新者
|
||||
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
|
||||
}
|
||||
|
||||
// TableName 表名称
|
||||
func (*NeHostCmd) TableName() string {
|
||||
return "ne_host_cmd"
|
||||
}
|
||||
@@ -2,23 +2,27 @@ package model
|
||||
|
||||
// NeInfo 网元信息对象 ne_info
|
||||
type NeInfo struct {
|
||||
ID int64 `json:"id"`
|
||||
NeType string `json:"neType"`
|
||||
NeId string `json:"neId"`
|
||||
ID string `json:"id"`
|
||||
NeType string `json:"neType" binding:"required"`
|
||||
NeId string `json:"neId" binding:"required"`
|
||||
RmUID string `json:"rmUid"`
|
||||
NeName string `json:"neName"`
|
||||
IP string `json:"ip"`
|
||||
Port int64 `json:"port"`
|
||||
PvFlag string `json:"pvFlag"` // enum('PNF','VNF')
|
||||
IP string `json:"ip" binding:"required"`
|
||||
Port int64 `json:"port" binding:"required,number,max=65535,min=1"`
|
||||
PvFlag string `json:"pvFlag" binding:"oneof=PNF VNF"` // enum('PNF','VNF')
|
||||
Province string `json:"province"`
|
||||
VendorName string `json:"vendorName"`
|
||||
Dn string `json:"dn"`
|
||||
NeAddress string `json:"neAddress"`
|
||||
Status string `json:"status"` // 0: 在线 1: 下线 2: 备用 3: 工程
|
||||
Status string `json:"status"` // 0: 在线 1: 下线 2: 备用 3: 待下发配置
|
||||
UpdateTime string `json:"updateTime"`
|
||||
HostIDs string `json:"hostIds"` // 网元主机ID组 数据格式(ssh,telnet,telnet)
|
||||
|
||||
// ====== 非数据库字段属性 ======
|
||||
|
||||
// 服务状态
|
||||
ServerState map[string]any `json:"serverState,omitempty"`
|
||||
|
||||
// 主机对象组
|
||||
Hosts []NeHost `json:"hosts,omitempty"`
|
||||
}
|
||||
|
||||
21
src/modules/network_element/model/ne_software.go
Normal file
21
src/modules/network_element/model/ne_software.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// NeSoftware 网元软件包 ne_software
|
||||
type NeSoftware struct {
|
||||
ID string `json:"id" gorm:"id"`
|
||||
NeType string `json:"neType" gorm:"ne_type" binding:"required"` // 网元类型
|
||||
FileName string `json:"fileName" gorm:"file_name" binding:"required"` // 包名称
|
||||
Path string `json:"path" gorm:"path"` // 包路径
|
||||
Version string `json:"version" gorm:"version" binding:"required"` // 包版本
|
||||
Md5Sum string `json:"md5Sum" gorm:"md5_sum"` // --无使用 md5签名
|
||||
Status string `json:"status" gorm:"status"` // --无使用
|
||||
Comment string `json:"comment" gorm:"comment"` // 包说明
|
||||
UpdateTime time.Time `json:"updateTime" gorm:"update_time"` // 上传时间
|
||||
}
|
||||
|
||||
// TableName 表名称
|
||||
func (*NeSoftware) TableName() string {
|
||||
return "ne_software"
|
||||
}
|
||||
23
src/modules/network_element/model/ne_version.go
Normal file
23
src/modules/network_element/model/ne_version.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// NeVersion 网元版本信息 ne_version
|
||||
type NeVersion struct {
|
||||
ID string `json:"id" gorm:"id"`
|
||||
NeType string `json:"neType" gorm:"ne_type" binding:"required"` // 网元类型
|
||||
NeId string `json:"neId" gorm:"ne_id" binding:"required"` // 网元ID
|
||||
Version string `json:"version" gorm:"version"` // 当前版本
|
||||
FilePath string `json:"filePath" gorm:"file_path"` // 当前软件包
|
||||
PreVersion string `json:"preVersion" gorm:"pre_version"` // 上一版本
|
||||
PreFile string `json:"preFile" gorm:"pre_file"` // 上一版本软件包
|
||||
NewVersion string `json:"newVersion" gorm:"new_version"` // 下一版本
|
||||
NewFile string `json:"newFile" gorm:"new_file"` // 下一版本软件包
|
||||
Status string `json:"status" gorm:"status" binding:"oneof=Uploaded Inactive Active"` // 当前状态 (Uploaded下一版本上传 Inactive下一版本待激活 Active当前已激活)
|
||||
UpdateTime time.Time `json:"updateTime" gorm:"update_time"` // 更新时间
|
||||
}
|
||||
|
||||
// TableName 表名称
|
||||
func (*NeVersion) TableName() string {
|
||||
return "ne_version"
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package model
|
||||
|
||||
// GoldKPITitle 黄金指标标题信息对象 kpi_title
|
||||
type GoldKPITitle struct {
|
||||
ID string `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
|
||||
NeType string `json:"neType" gorm:"column:ne_type"`
|
||||
KPIID string `json:"kpiId" gorm:"column:kpi_id"`
|
||||
TitleJson string `json:"titleJson" gorm:"column:title_json"`
|
||||
CnTitle string `json:"cnTitle" gorm:"column:cn_title"`
|
||||
EnTitle string `json:"enTitle" gorm:"column:en_title"`
|
||||
}
|
||||
|
||||
// GoldKPIQuery 黄金指标查询参数结构体
|
||||
type GoldKPIQuery struct {
|
||||
NeType string `form:"neType" binding:"required"`
|
||||
NeID string `form:"neId" binding:"required"`
|
||||
StartTime string `form:"startTime" binding:"required"`
|
||||
EndTime string `form:"endTime" binding:"required"`
|
||||
Interval int64 `form:"interval" binding:"required"`
|
||||
RmUID string `form:"rmUID"`
|
||||
SortField string `form:"sortField" binding:"omitempty,oneof=timeGroup"`
|
||||
SortOrder string `form:"sortOrder" binding:"omitempty,oneof=asc desc"`
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package networkelement
|
||||
|
||||
import (
|
||||
"ems.agt/src/framework/logger"
|
||||
"ems.agt/src/framework/middleware"
|
||||
"ems.agt/src/framework/middleware/collectlogs"
|
||||
"ems.agt/src/framework/middleware/repeat"
|
||||
"ems.agt/src/modules/network_element/controller"
|
||||
"ems.agt/src/modules/network_element/service"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/middleware"
|
||||
"be.ems/src/framework/middleware/collectlogs"
|
||||
"be.ems/src/framework/middleware/repeat"
|
||||
"be.ems/src/modules/network_element/controller"
|
||||
"be.ems/src/modules/network_element/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -20,23 +20,7 @@ func Setup(router *gin.Engine) {
|
||||
|
||||
neGroup := router.Group("/ne")
|
||||
|
||||
// 网元信息
|
||||
{
|
||||
neGroup.GET("/info",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeInfo.NeTypeAndID,
|
||||
)
|
||||
neGroup.GET("/state",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeInfo.NeState,
|
||||
)
|
||||
neGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeInfo.NeList,
|
||||
)
|
||||
}
|
||||
|
||||
// 网元处理
|
||||
// 网元操作处理
|
||||
neActionGroup := neGroup.Group("/action")
|
||||
{
|
||||
neActionGroup.GET("/files",
|
||||
@@ -54,6 +38,178 @@ func Setup(router *gin.Engine) {
|
||||
)
|
||||
}
|
||||
|
||||
// 网元信息
|
||||
neInfoGroup := neGroup.Group("/info")
|
||||
{
|
||||
neInfoGroup.GET("/listAll",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeInfo.ListAll,
|
||||
)
|
||||
neInfoGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeInfo.List,
|
||||
)
|
||||
neInfoGroup.GET("/:infoId",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeInfo.Info,
|
||||
)
|
||||
neInfoGroup.POST("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neInfo", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewNeInfo.Add,
|
||||
)
|
||||
neInfoGroup.PUT("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neInfo", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewNeInfo.Edit,
|
||||
)
|
||||
neInfoGroup.DELETE("/:infoIds",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neInfo", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeInfo.Remove,
|
||||
)
|
||||
neInfoGroup.GET("/state",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeInfo.State,
|
||||
)
|
||||
neInfoGroup.GET("/byTypeAndID",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeInfo.NeTypeAndID,
|
||||
)
|
||||
}
|
||||
|
||||
// 网元主机
|
||||
neHostGroup := neGroup.Group("/host")
|
||||
{
|
||||
neHostGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeHost.List,
|
||||
)
|
||||
neHostGroup.GET("/:hostId",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeHost.Info,
|
||||
)
|
||||
neHostGroup.POST("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neHost", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewNeHost.Add,
|
||||
)
|
||||
neHostGroup.PUT("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neHost", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewNeHost.Edit,
|
||||
)
|
||||
neHostGroup.DELETE("/:hostIds",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neHost", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeHost.Remove,
|
||||
)
|
||||
neHostGroup.POST("/test",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neHost", collectlogs.BUSINESS_TYPE_OTHER)),
|
||||
controller.NewNeHost.Test,
|
||||
)
|
||||
neHostGroup.POST("/cmd",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neHost", collectlogs.BUSINESS_TYPE_OTHER)),
|
||||
controller.NewNeHost.Cmd,
|
||||
)
|
||||
neHostGroup.POST("/checkBySSH",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neHost", collectlogs.BUSINESS_TYPE_OTHER)),
|
||||
controller.NewNeHost.CheckBySSH,
|
||||
)
|
||||
}
|
||||
|
||||
// 网元主机命令
|
||||
neHostCmdGroup := neGroup.Group("/hostCmd")
|
||||
{
|
||||
neHostCmdGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeHostCmd.List,
|
||||
)
|
||||
neHostCmdGroup.GET("/:cmdId",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeHostCmd.Info,
|
||||
)
|
||||
neHostCmdGroup.POST("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neHostCmd", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewNeHostCmd.Add,
|
||||
)
|
||||
neHostCmdGroup.PUT("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neHostCmd", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewNeHostCmd.Edit,
|
||||
)
|
||||
neHostCmdGroup.DELETE("/:cmdIds",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neHostCmd", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeHostCmd.Remove,
|
||||
)
|
||||
}
|
||||
|
||||
// 网元版本信息
|
||||
neVersionGroup := neGroup.Group("/version")
|
||||
{
|
||||
neVersionGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeVersion.List,
|
||||
)
|
||||
neVersionGroup.GET("/:versionId",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeVersion.Info,
|
||||
)
|
||||
neVersionGroup.POST("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neVersion", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewNeVersion.Add,
|
||||
)
|
||||
neVersionGroup.PUT("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neVersion", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewNeVersion.Edit,
|
||||
)
|
||||
neVersionGroup.DELETE("/:versionIds",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neVersion", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeVersion.Remove,
|
||||
)
|
||||
}
|
||||
|
||||
// 网元软件包信息
|
||||
neSoftwareGroup := neGroup.Group("/software")
|
||||
{
|
||||
neSoftwareGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeSoftware.List,
|
||||
)
|
||||
neSoftwareGroup.GET("/:softwareId",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeSoftware.Info,
|
||||
)
|
||||
neSoftwareGroup.POST("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neSoftware", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewNeSoftware.Add,
|
||||
)
|
||||
neSoftwareGroup.PUT("",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neSoftware", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewNeSoftware.Edit,
|
||||
)
|
||||
neSoftwareGroup.DELETE("/:softwareIds",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neSoftware", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeSoftware.Remove,
|
||||
)
|
||||
neSoftwareGroup.POST("/install",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neSoftware", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewNeSoftware.Install,
|
||||
)
|
||||
}
|
||||
|
||||
// UDM鉴权用户信息
|
||||
udmAuthGroup := neGroup.Group("/udm/auth")
|
||||
{
|
||||
@@ -167,4 +323,5 @@ func Setup(router *gin.Engine) {
|
||||
func InitLoad() {
|
||||
// 启动时,清除缓存-网元类型
|
||||
service.NewNeInfoImpl.ClearNeCacheByNeType("*")
|
||||
service.NewNeInfoImpl.SelectNeInfoByRmuid("")
|
||||
}
|
||||
|
||||
27
src/modules/network_element/repository/ne_host.go
Normal file
27
src/modules/network_element/repository/ne_host.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeHost 网元主机连接 数据层接口
|
||||
type INeHost interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neHost model.NeHost) []model.NeHost
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(hostIds []string) []model.NeHost
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neHost model.NeHost) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neHost model.NeHost) int64
|
||||
|
||||
// DeleteByIds 批量删除网元主机连接信息
|
||||
DeleteByIds(hostIds []string) int64
|
||||
|
||||
// CheckUniqueNeHost 校验主机是否唯一
|
||||
CheckUniqueNeHost(neHost model.NeHost) string
|
||||
}
|
||||
404
src/modules/network_element/repository/ne_host.impl.go
Normal file
404
src/modules/network_element/repository/ne_host.impl.go
Normal file
@@ -0,0 +1,404 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/crypto"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 NewNeHostImpl 结构体
|
||||
var NewNeHostImpl = &NeHostImpl{
|
||||
selectSql: `select
|
||||
host_id, host_type, group_id, title, addr, port, user, auth_mode, password, private_key, pass_phrase, remark, create_by, create_time, update_by, update_time
|
||||
from ne_host`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"host_id": "HostID",
|
||||
"host_type": "HostType",
|
||||
"group_id": "GroupID",
|
||||
"title": "Title",
|
||||
"addr": "Addr",
|
||||
"port": "Port",
|
||||
"user": "User",
|
||||
"auth_mode": "AuthMode",
|
||||
"password": "Password",
|
||||
"private_key": "PrivateKey",
|
||||
"private_password": "PassPhrase",
|
||||
"remark": "Remark",
|
||||
"create_by": "CreateBy",
|
||||
"create_time": "CreateTime",
|
||||
"update_by": "UpdateBy",
|
||||
"update_time": "UpdateTime",
|
||||
},
|
||||
}
|
||||
|
||||
// NeHostImpl 网元主机连接 数据层处理
|
||||
type NeHostImpl struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *NeHostImpl) convertResultRows(rows []map[string]any) []model.NeHost {
|
||||
arr := make([]model.NeHost, 0)
|
||||
for _, row := range rows {
|
||||
item := model.NeHost{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
func (r *NeHostImpl) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["hostType"]; ok && v != "" {
|
||||
conditions = append(conditions, "host_type = ?")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["groupId"]; ok && v != "" {
|
||||
conditions = append(conditions, "group_id = ?")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["title"]; ok && v != "" {
|
||||
conditions = append(conditions, "title like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.NeHost{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from ne_host"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
}
|
||||
total := parse.Number(totalRows[0]["total"])
|
||||
if total == 0 {
|
||||
return result
|
||||
} else {
|
||||
result["total"] = total
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
result["rows"] = r.convertResultRows(results)
|
||||
return result
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
func (r *NeHostImpl) SelectList(neHost model.NeHost) []model.NeHost {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neHost.HostType != "" {
|
||||
conditions = append(conditions, "host_type = ?")
|
||||
params = append(params, neHost.HostType)
|
||||
}
|
||||
if neHost.GroupID != "" {
|
||||
conditions = append(conditions, "group_id = ?")
|
||||
params = append(params, neHost.GroupID)
|
||||
}
|
||||
if neHost.Title != "" {
|
||||
conditions = append(conditions, "title like concat(?, '%')")
|
||||
params = append(params, neHost.Title)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by update_time asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeHostImpl) SelectByIds(hostIds []string) []model.NeHost {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(hostIds))
|
||||
querySql := r.selectSql + " where host_id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(hostIds)
|
||||
results, err := datasource.RawDB("", querySql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return []model.NeHost{}
|
||||
}
|
||||
// 转换实体
|
||||
rows := r.convertResultRows(results)
|
||||
arr := &rows
|
||||
for i := range *arr {
|
||||
passwordDe, err := crypto.StringDecryptByAES((*arr)[i].Password)
|
||||
if err != nil {
|
||||
logger.Errorf("selectById %s StringDecryptByAES : %v", (*arr)[i].HostID, err.Error())
|
||||
(*arr)[i].Password = ""
|
||||
} else {
|
||||
(*arr)[i].Password = passwordDe
|
||||
}
|
||||
privateKeyDe, err := crypto.StringDecryptByAES((*arr)[i].PrivateKey)
|
||||
if err != nil {
|
||||
logger.Errorf("selectById %s StringDecryptByAES : %v", (*arr)[i].HostID, err.Error())
|
||||
(*arr)[i].PrivateKey = ""
|
||||
} else {
|
||||
(*arr)[i].PrivateKey = privateKeyDe
|
||||
}
|
||||
passPhraseDe, err := crypto.StringDecryptByAES((*arr)[i].PassPhrase)
|
||||
if err != nil {
|
||||
logger.Errorf("selectById %s StringDecryptByAES : %v", (*arr)[i].HostID, err.Error())
|
||||
(*arr)[i].PassPhrase = ""
|
||||
} else {
|
||||
(*arr)[i].PassPhrase = passPhraseDe
|
||||
}
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// CheckUniqueNeHost 校验主机是否唯一
|
||||
func (r *NeHostImpl) CheckUniqueNeHost(neHost model.NeHost) string {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neHost.HostType != "" {
|
||||
conditions = append(conditions, "host_type = ?")
|
||||
params = append(params, neHost.HostType)
|
||||
}
|
||||
if neHost.GroupID != "" {
|
||||
conditions = append(conditions, "group_id = ?")
|
||||
params = append(params, neHost.GroupID)
|
||||
}
|
||||
if neHost.Title != "" {
|
||||
conditions = append(conditions, "title = ?")
|
||||
params = append(params, neHost.Title)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := "select host_id as 'str' from ne_host " + whereSql + " limit 1"
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err %v", err)
|
||||
return ""
|
||||
}
|
||||
if len(results) > 0 {
|
||||
return fmt.Sprint(results[0]["str"])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeHostImpl) Insert(neHost model.NeHost) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neHost.HostType != "" {
|
||||
params["host_type"] = neHost.HostType
|
||||
}
|
||||
if neHost.GroupID != "" {
|
||||
params["group_id"] = neHost.GroupID
|
||||
}
|
||||
if neHost.Title != "" {
|
||||
params["title"] = neHost.Title
|
||||
}
|
||||
if neHost.Addr != "" {
|
||||
params["addr"] = neHost.Addr
|
||||
}
|
||||
if neHost.Port > 0 {
|
||||
params["port"] = neHost.Port
|
||||
}
|
||||
if neHost.User != "" {
|
||||
params["user"] = neHost.User
|
||||
}
|
||||
if neHost.AuthMode != "" {
|
||||
params["auth_mode"] = neHost.AuthMode
|
||||
}
|
||||
if neHost.Password != "" {
|
||||
passwordEn, err := crypto.StringEncryptByAES(neHost.Password)
|
||||
if err != nil {
|
||||
logger.Errorf("insert StringEncryptByAES : %v", err.Error())
|
||||
return ""
|
||||
}
|
||||
params["password"] = passwordEn
|
||||
}
|
||||
if neHost.PrivateKey != "" {
|
||||
privateKeyEn, err := crypto.StringEncryptByAES(neHost.PrivateKey)
|
||||
if err != nil {
|
||||
logger.Errorf("insert StringEncryptByAES : %v", err.Error())
|
||||
return ""
|
||||
}
|
||||
params["private_key"] = privateKeyEn
|
||||
}
|
||||
if neHost.PassPhrase != "" {
|
||||
passPhraseEn, err := crypto.StringEncryptByAES(neHost.PassPhrase)
|
||||
if err != nil {
|
||||
logger.Errorf("insert StringEncryptByAES : %v", err.Error())
|
||||
return ""
|
||||
}
|
||||
params["pass_phrase"] = passPhraseEn
|
||||
}
|
||||
if neHost.Remark != "" {
|
||||
params["remark"] = neHost.Remark
|
||||
}
|
||||
if neHost.CreateBy != "" {
|
||||
params["create_by"] = neHost.CreateBy
|
||||
params["create_time"] = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into ne_host (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
tx := db.Begin()
|
||||
// 执行插入
|
||||
err := tx.Exec(sql, values...).Error
|
||||
if err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
err = tx.Raw("select last_insert_id()").Row().Scan(&insertedID)
|
||||
if err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 提交事务
|
||||
tx.Commit()
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeHostImpl) Update(neHost model.NeHost) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neHost.HostType != "" {
|
||||
params["host_type"] = neHost.HostType
|
||||
}
|
||||
if neHost.GroupID != "" {
|
||||
params["group_id"] = neHost.GroupID
|
||||
}
|
||||
if neHost.Title != "" {
|
||||
params["title"] = neHost.Title
|
||||
}
|
||||
if neHost.Addr != "" {
|
||||
params["addr"] = neHost.Addr
|
||||
}
|
||||
if neHost.Port > 0 {
|
||||
params["port"] = neHost.Port
|
||||
}
|
||||
if neHost.User != "" {
|
||||
params["user"] = neHost.User
|
||||
}
|
||||
if neHost.AuthMode != "" {
|
||||
params["auth_mode"] = neHost.AuthMode
|
||||
}
|
||||
if neHost.Password != "" {
|
||||
passwordEn, err := crypto.StringEncryptByAES(neHost.Password)
|
||||
if err != nil {
|
||||
logger.Errorf("update StringEncryptByAES : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
params["password"] = passwordEn
|
||||
}
|
||||
if neHost.PrivateKey != "" {
|
||||
privateKeyEn, err := crypto.StringEncryptByAES(neHost.PrivateKey)
|
||||
if err != nil {
|
||||
logger.Errorf("update StringEncryptByAES : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
params["private_key"] = privateKeyEn
|
||||
}
|
||||
if neHost.PassPhrase != "" {
|
||||
passPhraseEn, err := crypto.StringEncryptByAES(neHost.PassPhrase)
|
||||
if err != nil {
|
||||
logger.Errorf("update StringEncryptByAES : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
params["pass_phrase"] = passPhraseEn
|
||||
}
|
||||
params["remark"] = neHost.Remark
|
||||
if neHost.UpdateBy != "" {
|
||||
params["update_by"] = neHost.UpdateBy
|
||||
params["update_time"] = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
sql := "update ne_host set " + strings.Join(keys, ",") + " where host_id = ?"
|
||||
|
||||
// 执行更新
|
||||
values = append(values, neHost.HostID)
|
||||
rows, err := datasource.ExecDB("", sql, values)
|
||||
if err != nil {
|
||||
logger.Errorf("update row : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除网元主机连接信息
|
||||
func (r *NeHostImpl) DeleteByIds(hostIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(hostIds))
|
||||
sql := "delete from ne_host where host_id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(hostIds)
|
||||
results, err := datasource.ExecDB("", sql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("delete err => %v", err)
|
||||
return 0
|
||||
}
|
||||
return results
|
||||
}
|
||||
27
src/modules/network_element/repository/ne_host_cmd.go
Normal file
27
src/modules/network_element/repository/ne_host_cmd.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeHostCmd 网元主机命令 数据层接口
|
||||
type INeHostCmd interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neHostCmd model.NeHostCmd) []model.NeHostCmd
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(cmdIds []string) []model.NeHostCmd
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neHostCmd model.NeHostCmd) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neHostCmd model.NeHostCmd) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(cmdIds []string) int64
|
||||
|
||||
// CheckUniqueGroupTitle 校验同类型组内是否唯一
|
||||
CheckUniqueGroupTitle(neHostCmd model.NeHostCmd) string
|
||||
}
|
||||
306
src/modules/network_element/repository/ne_host_cmd.impl.go
Normal file
306
src/modules/network_element/repository/ne_host_cmd.impl.go
Normal file
@@ -0,0 +1,306 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 NewNeHostCmdImpl 结构体
|
||||
var NewNeHostCmdImpl = &NeHostCmdImpl{
|
||||
selectSql: `select
|
||||
cmd_id, cmd_type, group_id, title, command, remark, create_by, create_time, update_by, update_time
|
||||
from ne_host_cmd`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"cmd_id": "CmdID",
|
||||
"cmd_type": "CmdType",
|
||||
"group_id": "GroupID",
|
||||
"title": "Title",
|
||||
"command": "Command",
|
||||
"remark": "Remark",
|
||||
"create_by": "CreateBy",
|
||||
"create_time": "CreateTime",
|
||||
"update_by": "UpdateBy",
|
||||
"update_time": "UpdateTime",
|
||||
},
|
||||
}
|
||||
|
||||
// NeHostCmdImpl 网元主机连接 数据层处理
|
||||
type NeHostCmdImpl struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *NeHostCmdImpl) convertResultRows(rows []map[string]any) []model.NeHostCmd {
|
||||
arr := make([]model.NeHostCmd, 0)
|
||||
for _, row := range rows {
|
||||
item := model.NeHostCmd{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
func (r *NeHostCmdImpl) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["cmdType"]; ok && v != "" {
|
||||
conditions = append(conditions, "cmd_type = ?")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["groupId"]; ok && v != "" {
|
||||
conditions = append(conditions, "group_id = ?")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["title"]; ok && v != "" {
|
||||
conditions = append(conditions, "title like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.NeHost{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from ne_host_cmd"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
}
|
||||
total := parse.Number(totalRows[0]["total"])
|
||||
if total == 0 {
|
||||
return result
|
||||
} else {
|
||||
result["total"] = total
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
result["rows"] = r.convertResultRows(results)
|
||||
return result
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
func (r *NeHostCmdImpl) SelectList(neHostCmd model.NeHostCmd) []model.NeHostCmd {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neHostCmd.CmdType != "" {
|
||||
conditions = append(conditions, "cmd_type = ?")
|
||||
params = append(params, neHostCmd.CmdType)
|
||||
}
|
||||
if neHostCmd.GroupID != "" {
|
||||
conditions = append(conditions, "group_id = ?")
|
||||
params = append(params, neHostCmd.GroupID)
|
||||
}
|
||||
if neHostCmd.Title != "" {
|
||||
conditions = append(conditions, "title like concat(?, '%')")
|
||||
params = append(params, neHostCmd.Title)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by update_time asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeHostCmdImpl) SelectByIds(cmdIds []string) []model.NeHostCmd {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
querySql := r.selectSql + " where cmd_id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
results, err := datasource.RawDB("", querySql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return []model.NeHostCmd{}
|
||||
}
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// CheckUniqueGroupTitle 校验同类型组内是否唯一
|
||||
func (r *NeHostCmdImpl) CheckUniqueGroupTitle(neHostCmd model.NeHostCmd) string {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neHostCmd.CmdType != "" {
|
||||
conditions = append(conditions, "cmd_type = ?")
|
||||
params = append(params, neHostCmd.CmdType)
|
||||
}
|
||||
if neHostCmd.GroupID != "" {
|
||||
conditions = append(conditions, "group_id = ?")
|
||||
params = append(params, neHostCmd.GroupID)
|
||||
}
|
||||
if neHostCmd.Title != "" {
|
||||
conditions = append(conditions, "title = ?")
|
||||
params = append(params, neHostCmd.Title)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := "select host_id as 'str' from ne_host " + whereSql + " limit 1"
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err %v", err)
|
||||
return ""
|
||||
}
|
||||
if len(results) > 0 {
|
||||
return fmt.Sprint(results[0]["str"])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeHostCmdImpl) Insert(neHostCmd model.NeHostCmd) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neHostCmd.CmdType != "" {
|
||||
params["cmd_type"] = neHostCmd.CmdType
|
||||
}
|
||||
if neHostCmd.GroupID != "" {
|
||||
params["group_id"] = neHostCmd.GroupID
|
||||
}
|
||||
if neHostCmd.Title != "" {
|
||||
params["title"] = neHostCmd.Title
|
||||
}
|
||||
if neHostCmd.Command != "" {
|
||||
params["command"] = neHostCmd.Command
|
||||
}
|
||||
if neHostCmd.Remark != "" {
|
||||
params["remark"] = neHostCmd.Remark
|
||||
}
|
||||
if neHostCmd.CreateBy != "" {
|
||||
params["create_by"] = neHostCmd.CreateBy
|
||||
params["create_time"] = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into ne_host_cmd (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
tx := db.Begin()
|
||||
// 执行插入
|
||||
err := tx.Exec(sql, values...).Error
|
||||
if err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
err = tx.Raw("select last_insert_id()").Row().Scan(&insertedID)
|
||||
if err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 提交事务
|
||||
tx.Commit()
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeHostCmdImpl) Update(neHostCmd model.NeHostCmd) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neHostCmd.CmdType != "" {
|
||||
params["cmd_type"] = neHostCmd.CmdType
|
||||
}
|
||||
if neHostCmd.GroupID != "" {
|
||||
params["group_id"] = neHostCmd.GroupID
|
||||
}
|
||||
if neHostCmd.Title != "" {
|
||||
params["title"] = neHostCmd.Title
|
||||
}
|
||||
if neHostCmd.Command != "" {
|
||||
params["command"] = neHostCmd.Command
|
||||
}
|
||||
params["remark"] = neHostCmd.Remark
|
||||
if neHostCmd.UpdateBy != "" {
|
||||
params["update_by"] = neHostCmd.UpdateBy
|
||||
params["update_time"] = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
sql := "update ne_host_cmd set " + strings.Join(keys, ",") + " where cmd_id = ?"
|
||||
|
||||
// 执行更新
|
||||
values = append(values, neHostCmd.CmdID)
|
||||
rows, err := datasource.ExecDB("", sql, values)
|
||||
if err != nil {
|
||||
logger.Errorf("update row : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeHostCmdImpl) DeleteByIds(cmdIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
sql := "delete from ne_host_cmd where cmd_id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
results, err := datasource.ExecDB("", sql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("delete err => %v", err)
|
||||
return 0
|
||||
}
|
||||
return results
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 网元信息 数据层接口
|
||||
@@ -9,6 +9,24 @@ type INeInfo interface {
|
||||
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||
SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo
|
||||
|
||||
// SelectNeList 查询网元列表
|
||||
SelectNeList(ne model.NeInfo) []model.NeInfo
|
||||
// SelectPage 根据条件分页查询
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 查询列表
|
||||
SelectList(neInfo model.NeInfo) []model.NeInfo
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(infoIds []string) []model.NeInfo
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neInfo model.NeInfo) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neInfo model.NeInfo) int64
|
||||
|
||||
// DeleteByIds 批量删除网元信息
|
||||
DeleteByIds(infoIds []string) int64
|
||||
|
||||
// CheckUniqueNeTypeAndNeId 校验同类型下标识是否唯一
|
||||
CheckUniqueNeTypeAndNeId(neInfo model.NeInfo) string
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ems.agt/src/framework/datasource"
|
||||
"ems.agt/src/framework/logger"
|
||||
"ems.agt/src/framework/utils/repo"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// neListSort 网元列表预设排序
|
||||
@@ -30,7 +33,7 @@ var neListSort = []string{
|
||||
|
||||
// 实例化数据层 NeInfoImpl 结构体
|
||||
var NewNeInfoImpl = &NeInfoImpl{
|
||||
selectSql: `select id, ne_type, ne_id, rm_uid, ne_name, ip, port, pv_flag, province, vendor_name, dn, ne_address, status, update_time from ne_info`,
|
||||
selectSql: `select id, ne_type, ne_id, rm_uid, ne_name, ip, port, pv_flag, province, vendor_name, dn, ne_address, status, update_time, host_ids from ne_info`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
@@ -47,6 +50,7 @@ var NewNeInfoImpl = &NeInfoImpl{
|
||||
"ne_address": "NeAddress",
|
||||
"status": "Status",
|
||||
"update_time": "UpdateTime",
|
||||
"host_ids": "HostIDs",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -114,18 +118,80 @@ func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeIn
|
||||
return model.NeInfo{}
|
||||
}
|
||||
|
||||
// SelectNeList 查询网元列表
|
||||
func (r *NeInfoImpl) SelectNeList(ne model.NeInfo) []model.NeInfo {
|
||||
// SelectPage 根据条件分页查询
|
||||
func (r *NeInfoImpl) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if ne.NeType != "" {
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, ne.NeType)
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if ne.NeId != "" {
|
||||
if v, ok := query["neId"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, ne.NeId)
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["rmUid"]; ok && v != "" {
|
||||
conditions = append(conditions, "rmUid like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.NeInfo{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from ne_info"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
}
|
||||
total := parse.Number(totalRows[0]["total"])
|
||||
if total == 0 {
|
||||
return result
|
||||
} else {
|
||||
result["total"] = total
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by ne_type asc, ne_id desc " + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
result["rows"] = r.convertResultRows(results)
|
||||
return result
|
||||
}
|
||||
|
||||
// SelectList 查询列表
|
||||
func (r *NeInfoImpl) SelectList(neInfo model.NeInfo) []model.NeInfo {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neInfo.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neInfo.NeType)
|
||||
}
|
||||
if neInfo.NeId != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, neInfo.NeId)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
@@ -144,3 +210,184 @@ func (r *NeInfoImpl) SelectNeList(ne model.NeInfo) []model.NeInfo {
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeInfoImpl) SelectByIds(infoIds []string) []model.NeInfo {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(infoIds))
|
||||
querySql := r.selectSql + " where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(infoIds)
|
||||
results, err := datasource.RawDB("", querySql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return []model.NeInfo{}
|
||||
}
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// CheckUniqueNeTypeAndNeId 校验同类型下标识是否唯一
|
||||
func (r *NeInfoImpl) CheckUniqueNeTypeAndNeId(neInfo model.NeInfo) string {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neInfo.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neInfo.NeType)
|
||||
}
|
||||
if neInfo.NeId != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, neInfo.NeId)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := "select id as 'str' from ne_info " + whereSql + " limit 1"
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err %v", err)
|
||||
return ""
|
||||
}
|
||||
if len(results) > 0 {
|
||||
return fmt.Sprint(results[0]["str"])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeInfoImpl) Insert(neInfo model.NeInfo) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neInfo.NeType != "" {
|
||||
params["ne_type"] = neInfo.NeType
|
||||
}
|
||||
if neInfo.NeId != "" {
|
||||
params["ne_id"] = neInfo.NeId
|
||||
}
|
||||
if neInfo.RmUID != "" {
|
||||
params["rm_uid"] = neInfo.RmUID
|
||||
}
|
||||
if neInfo.NeName != "" {
|
||||
params["ne_name"] = neInfo.NeName
|
||||
}
|
||||
if neInfo.IP != "" {
|
||||
params["ip"] = neInfo.IP
|
||||
}
|
||||
if neInfo.Port > 0 {
|
||||
params["port"] = neInfo.Port
|
||||
}
|
||||
if neInfo.PvFlag != "" {
|
||||
params["pv_flag"] = neInfo.PvFlag
|
||||
}
|
||||
if neInfo.Province != "" {
|
||||
params["province"] = neInfo.Province
|
||||
}
|
||||
if neInfo.VendorName != "" {
|
||||
params["vendor_name"] = neInfo.VendorName
|
||||
}
|
||||
if neInfo.Dn != "" {
|
||||
params["dn"] = neInfo.Dn
|
||||
}
|
||||
if neInfo.NeAddress != "" {
|
||||
params["ne_address"] = neInfo.NeAddress
|
||||
}
|
||||
params["status"] = neInfo.Status
|
||||
params["update_time"] = time.Now()
|
||||
if neInfo.HostIDs != "" {
|
||||
params["host_ids"] = neInfo.HostIDs
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into ne_info (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
tx := db.Begin()
|
||||
// 执行插入
|
||||
err := tx.Exec(sql, values...).Error
|
||||
if err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
err = tx.Raw("select last_insert_id()").Row().Scan(&insertedID)
|
||||
if err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 提交事务
|
||||
tx.Commit()
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeInfoImpl) Update(neInfo model.NeInfo) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neInfo.NeType != "" {
|
||||
params["ne_type"] = neInfo.NeType
|
||||
}
|
||||
if neInfo.NeId != "" {
|
||||
params["ne_id"] = neInfo.NeId
|
||||
}
|
||||
if neInfo.RmUID != "" {
|
||||
params["rm_uid"] = neInfo.RmUID
|
||||
}
|
||||
if neInfo.NeName != "" {
|
||||
params["ne_name"] = neInfo.NeName
|
||||
}
|
||||
if neInfo.IP != "" {
|
||||
params["ip"] = neInfo.IP
|
||||
}
|
||||
if neInfo.Port > 0 {
|
||||
params["port"] = neInfo.Port
|
||||
}
|
||||
if neInfo.PvFlag != "" {
|
||||
params["pv_flag"] = neInfo.PvFlag
|
||||
}
|
||||
params["province"] = neInfo.Province
|
||||
params["vendor_name"] = neInfo.VendorName
|
||||
params["dn"] = neInfo.Dn
|
||||
params["ne_address"] = neInfo.NeAddress
|
||||
params["status"] = neInfo.Status
|
||||
params["update_time"] = time.Now()
|
||||
if neInfo.HostIDs != "" {
|
||||
params["host_ids"] = neInfo.HostIDs
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
sql := "update ne_info set " + strings.Join(keys, ",") + " where id = ?"
|
||||
|
||||
// 执行更新
|
||||
values = append(values, neInfo.ID)
|
||||
rows, err := datasource.ExecDB("", sql, values)
|
||||
if err != nil {
|
||||
logger.Errorf("update row : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除网元信息
|
||||
func (r *NeInfoImpl) DeleteByIds(infoIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(infoIds))
|
||||
sql := "delete from ne_info where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(infoIds)
|
||||
results, err := datasource.ExecDB("", sql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("delete err => %v", err)
|
||||
return 0
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
27
src/modules/network_element/repository/ne_software.go
Normal file
27
src/modules/network_element/repository/ne_software.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeSoftware 网元软件包信息 数据层接口
|
||||
type INeSoftware interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neSoftware model.NeSoftware) []model.NeSoftware
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(ids []string) []model.NeSoftware
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neSoftware model.NeSoftware) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neSoftware model.NeSoftware) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(ids []string) int64
|
||||
|
||||
// CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一
|
||||
CheckUniqueTypeAndFileNameAndVersion(neSoftware model.NeSoftware) string
|
||||
}
|
||||
323
src/modules/network_element/repository/ne_software.impl.go
Normal file
323
src/modules/network_element/repository/ne_software.impl.go
Normal file
@@ -0,0 +1,323 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 NewNeSoftware 结构体
|
||||
var NewNeSoftwareImpl = &NeSoftwareImpl{
|
||||
selectSql: `select
|
||||
id, ne_type, file_name, path, version, md5_sum, status, comment, update_time
|
||||
from ne_software`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"ne_type": "NeType",
|
||||
"file_name": "FileName",
|
||||
"path": "Path",
|
||||
"version": "Version",
|
||||
"md5_sum": "Md5Sum",
|
||||
"status": "Status",
|
||||
"comment": "Comment",
|
||||
"update_time": "UpdateTime",
|
||||
},
|
||||
}
|
||||
|
||||
// NeSoftwareImpl 网元软件包信息 数据层处理
|
||||
type NeSoftwareImpl struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *NeSoftwareImpl) convertResultRows(rows []map[string]any) []model.NeSoftware {
|
||||
arr := make([]model.NeSoftware, 0)
|
||||
for _, row := range rows {
|
||||
item := model.NeSoftware{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
func (r *NeSoftwareImpl) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["fileName"]; ok && v != "" {
|
||||
conditions = append(conditions, "file_name like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["version"]; ok && v != "" {
|
||||
conditions = append(conditions, "version like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.NeHost{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from ne_software"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
}
|
||||
total := parse.Number(totalRows[0]["total"])
|
||||
if total == 0 {
|
||||
return result
|
||||
} else {
|
||||
result["total"] = total
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " order by id desc limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
result["rows"] = r.convertResultRows(results)
|
||||
return result
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
func (r *NeSoftwareImpl) SelectList(neSoftware model.NeSoftware) []model.NeSoftware {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neSoftware.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neSoftware.NeType)
|
||||
}
|
||||
if neSoftware.Path != "" {
|
||||
conditions = append(conditions, "path = ?")
|
||||
params = append(params, neSoftware.Path)
|
||||
}
|
||||
if neSoftware.Version != "" {
|
||||
conditions = append(conditions, "version = ?")
|
||||
params = append(params, neSoftware.Version)
|
||||
}
|
||||
if neSoftware.FileName != "" {
|
||||
conditions = append(conditions, "file_name like concat(?, '%')")
|
||||
params = append(params, neSoftware.FileName)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by id desc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeSoftwareImpl) SelectByIds(cmdIds []string) []model.NeSoftware {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
querySql := r.selectSql + " where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
results, err := datasource.RawDB("", querySql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return []model.NeSoftware{}
|
||||
}
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一
|
||||
func (r *NeSoftwareImpl) CheckUniqueTypeAndFileNameAndVersion(neSoftware model.NeSoftware) string {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neSoftware.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neSoftware.NeType)
|
||||
}
|
||||
if neSoftware.Version != "" {
|
||||
conditions = append(conditions, "version = ?")
|
||||
params = append(params, neSoftware.Version)
|
||||
}
|
||||
if neSoftware.FileName != "" {
|
||||
conditions = append(conditions, "file_name = ?")
|
||||
params = append(params, neSoftware.FileName)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := "select id as 'str' from ne_software " + whereSql + " limit 1"
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err %v", err)
|
||||
return ""
|
||||
}
|
||||
if len(results) > 0 {
|
||||
return fmt.Sprint(results[0]["str"])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeSoftwareImpl) Insert(neSoftware model.NeSoftware) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neSoftware.NeType != "" {
|
||||
params["ne_type"] = neSoftware.NeType
|
||||
}
|
||||
if neSoftware.FileName != "" {
|
||||
params["file_name"] = neSoftware.FileName
|
||||
}
|
||||
if neSoftware.Path != "" {
|
||||
params["path"] = neSoftware.Path
|
||||
}
|
||||
if neSoftware.Version != "" {
|
||||
params["version"] = neSoftware.Version
|
||||
}
|
||||
if neSoftware.Md5Sum != "" {
|
||||
params["md5_sum"] = neSoftware.Md5Sum
|
||||
}
|
||||
if neSoftware.Status != "" {
|
||||
params["status"] = neSoftware.Status
|
||||
}
|
||||
if neSoftware.Comment != "" {
|
||||
params["comment"] = neSoftware.Comment
|
||||
}
|
||||
if neSoftware.Status != "" {
|
||||
params["status"] = neSoftware.Status
|
||||
}
|
||||
params["update_time"] = time.Now()
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into ne_software (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
tx := db.Begin()
|
||||
// 执行插入
|
||||
err := tx.Exec(sql, values...).Error
|
||||
if err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
err = tx.Raw("select last_insert_id()").Row().Scan(&insertedID)
|
||||
if err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 提交事务
|
||||
tx.Commit()
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeSoftwareImpl) Update(neSoftware model.NeSoftware) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neSoftware.NeType != "" {
|
||||
params["ne_type"] = neSoftware.NeType
|
||||
}
|
||||
if neSoftware.FileName != "" {
|
||||
params["file_name"] = neSoftware.FileName
|
||||
}
|
||||
if neSoftware.Path != "" {
|
||||
params["path"] = neSoftware.Path
|
||||
}
|
||||
if neSoftware.Version != "" {
|
||||
params["version"] = neSoftware.Version
|
||||
}
|
||||
if neSoftware.Md5Sum != "" {
|
||||
params["md5_sum"] = neSoftware.Md5Sum
|
||||
}
|
||||
if neSoftware.Status != "" {
|
||||
params["status"] = neSoftware.Status
|
||||
}
|
||||
if neSoftware.Comment != "" {
|
||||
params["comment"] = neSoftware.Comment
|
||||
}
|
||||
if neSoftware.Status != "" {
|
||||
params["status"] = neSoftware.Status
|
||||
}
|
||||
params["update_time"] = time.Now()
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
sql := "update ne_software set " + strings.Join(keys, ",") + " where id = ?"
|
||||
|
||||
// 执行更新
|
||||
values = append(values, neSoftware.ID)
|
||||
rows, err := datasource.ExecDB("", sql, values)
|
||||
if err != nil {
|
||||
logger.Errorf("update row : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeSoftwareImpl) DeleteByIds(cmdIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
sql := "delete from ne_software where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
results, err := datasource.ExecDB("", sql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("delete err => %v", err)
|
||||
return 0
|
||||
}
|
||||
return results
|
||||
}
|
||||
27
src/modules/network_element/repository/ne_version.go
Normal file
27
src/modules/network_element/repository/ne_version.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeVersion 网元版本信息 数据层接口
|
||||
type INeVersion interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neVersion model.NeVersion) []model.NeVersion
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectByIds(ids []string) []model.NeVersion
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neVersion model.NeVersion) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neVersion model.NeVersion) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(ids []string) int64
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
CheckUniqueTypeAndID(neVersion model.NeVersion) string
|
||||
}
|
||||
331
src/modules/network_element/repository/ne_version.impl.go
Normal file
331
src/modules/network_element/repository/ne_version.impl.go
Normal file
@@ -0,0 +1,331 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 NewNeVersion 结构体
|
||||
var NewNeVersionImpl = &NeVersionImpl{
|
||||
selectSql: `select
|
||||
id, ne_type, ne_id, version, file_path, pre_version, pre_file, new_version, new_file, status, update_time
|
||||
from ne_version`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"ne_type": "NeType",
|
||||
"ne_id": "NeId",
|
||||
"version": "Version",
|
||||
"file_path": "FilePath",
|
||||
"pre_version": "PreVersion",
|
||||
"pre_file": "PreFile",
|
||||
"new_version": "NewVersion",
|
||||
"new_file": "NewFile",
|
||||
"status": "Status",
|
||||
"update_time": "UpdateTime",
|
||||
},
|
||||
}
|
||||
|
||||
// NeVersionImpl 网元版本信息 数据层处理
|
||||
type NeVersionImpl struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *NeVersionImpl) convertResultRows(rows []map[string]any) []model.NeVersion {
|
||||
arr := make([]model.NeVersion, 0)
|
||||
for _, row := range rows {
|
||||
item := model.NeVersion{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
func (r *NeVersionImpl) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["neId"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["version"]; ok && v != "" {
|
||||
conditions = append(conditions, "version like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["filePath"]; ok && v != "" {
|
||||
conditions = append(conditions, "file_path like concat(?, '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.NeHost{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from ne_version"
|
||||
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("total err => %v", err)
|
||||
return result
|
||||
}
|
||||
total := parse.Number(totalRows[0]["total"])
|
||||
if total == 0 {
|
||||
return result
|
||||
} else {
|
||||
result["total"] = total
|
||||
}
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
result["rows"] = r.convertResultRows(results)
|
||||
return result
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
func (r *NeVersionImpl) SelectList(neVersion model.NeVersion) []model.NeVersion {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neVersion.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neVersion.NeType)
|
||||
}
|
||||
if neVersion.NeId != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, neVersion.NeId)
|
||||
}
|
||||
if neVersion.Version != "" {
|
||||
conditions = append(conditions, "version like concat(?, '%')")
|
||||
params = append(params, neVersion.Version)
|
||||
}
|
||||
if neVersion.FilePath != "" {
|
||||
conditions = append(conditions, "file_path like concat(?, '%')")
|
||||
params = append(params, neVersion.FilePath)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by update_time asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeVersionImpl) SelectByIds(cmdIds []string) []model.NeVersion {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
querySql := r.selectSql + " where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
results, err := datasource.RawDB("", querySql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return []model.NeVersion{}
|
||||
}
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
func (r *NeVersionImpl) CheckUniqueTypeAndID(neVersion model.NeVersion) string {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if neVersion.NeType != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, neVersion.NeType)
|
||||
}
|
||||
if neVersion.NeId != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, neVersion.NeId)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := "select id as 'str' from ne_version " + whereSql + " limit 1"
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err %v", err)
|
||||
return ""
|
||||
}
|
||||
if len(results) > 0 {
|
||||
return fmt.Sprint(results[0]["str"])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeVersionImpl) Insert(neVersion model.NeVersion) string {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neVersion.NeType != "" {
|
||||
params["ne_type"] = neVersion.NeType
|
||||
}
|
||||
if neVersion.NeId != "" {
|
||||
params["ne_id"] = neVersion.NeId
|
||||
}
|
||||
if neVersion.Version != "" {
|
||||
params["version"] = neVersion.Version
|
||||
}
|
||||
if neVersion.FilePath != "" {
|
||||
params["file_path"] = neVersion.FilePath
|
||||
}
|
||||
if neVersion.PreVersion != "" {
|
||||
params["pre_version"] = neVersion.PreVersion
|
||||
}
|
||||
if neVersion.PreFile != "" {
|
||||
params["pre_file"] = neVersion.PreFile
|
||||
}
|
||||
if neVersion.NewVersion != "" {
|
||||
params["new_version"] = neVersion.NewVersion
|
||||
}
|
||||
if neVersion.NewFile != "" {
|
||||
params["new_file"] = neVersion.NewFile
|
||||
}
|
||||
if neVersion.Status != "" {
|
||||
params["status"] = neVersion.Status
|
||||
}
|
||||
params["update_time"] = time.Now()
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
sql := "insert into ne_version (" + strings.Join(keys, ",") + ")values(" + placeholder + ")"
|
||||
|
||||
db := datasource.DefaultDB()
|
||||
// 开启事务
|
||||
tx := db.Begin()
|
||||
// 执行插入
|
||||
err := tx.Exec(sql, values...).Error
|
||||
if err != nil {
|
||||
logger.Errorf("insert row : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 获取生成的自增 ID
|
||||
var insertedID string
|
||||
err = tx.Raw("select last_insert_id()").Row().Scan(&insertedID)
|
||||
if err != nil {
|
||||
logger.Errorf("insert last id : %v", err.Error())
|
||||
tx.Rollback()
|
||||
return ""
|
||||
}
|
||||
// 提交事务
|
||||
tx.Commit()
|
||||
return insertedID
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeVersionImpl) Update(neVersion model.NeVersion) int64 {
|
||||
// 参数拼接
|
||||
params := make(map[string]any)
|
||||
if neVersion.NeType != "" {
|
||||
params["ne_type"] = neVersion.NeType
|
||||
}
|
||||
if neVersion.NeId != "" {
|
||||
params["ne_id"] = neVersion.NeId
|
||||
}
|
||||
if neVersion.Version != "" {
|
||||
params["version"] = neVersion.Version
|
||||
}
|
||||
if neVersion.FilePath != "" {
|
||||
params["file_path"] = neVersion.FilePath
|
||||
}
|
||||
if neVersion.PreVersion != "" {
|
||||
params["pre_version"] = neVersion.PreVersion
|
||||
}
|
||||
if neVersion.PreFile != "" {
|
||||
params["pre_file"] = neVersion.PreFile
|
||||
}
|
||||
if neVersion.NewVersion != "" {
|
||||
params["new_version"] = neVersion.NewVersion
|
||||
}
|
||||
if neVersion.NewFile != "" {
|
||||
params["new_file"] = neVersion.NewFile
|
||||
}
|
||||
if neVersion.Status != "" {
|
||||
params["status"] = neVersion.Status
|
||||
}
|
||||
params["update_time"] = time.Now()
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
sql := "update ne_version set " + strings.Join(keys, ",") + " where id = ?"
|
||||
|
||||
// 执行更新
|
||||
values = append(values, neVersion.ID)
|
||||
rows, err := datasource.ExecDB("", sql, values)
|
||||
if err != nil {
|
||||
logger.Errorf("update row : %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeVersionImpl) DeleteByIds(cmdIds []string) int64 {
|
||||
placeholder := repo.KeyPlaceholderByQuery(len(cmdIds))
|
||||
sql := "delete from ne_version where id in (" + placeholder + ")"
|
||||
parameters := repo.ConvertIdsSlice(cmdIds)
|
||||
results, err := datasource.ExecDB("", sql, parameters)
|
||||
if err != nil {
|
||||
logger.Errorf("delete err => %v", err)
|
||||
return 0
|
||||
}
|
||||
return results
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package repository
|
||||
|
||||
import "ems.agt/src/modules/network_element/model"
|
||||
|
||||
// 性能统计 数据层接口
|
||||
type IPerfKPI interface {
|
||||
// SelectGoldKPI 通过网元指标数据信息
|
||||
SelectGoldKPI(query model.GoldKPIQuery, kpiIds []string) []map[string]any
|
||||
|
||||
// SelectGoldKPITitle
|
||||
SelectGoldKPITitle(neType string) []model.GoldKPITitle
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/datasource"
|
||||
"ems.agt/src/framework/logger"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 PerfKPIImpl 结构体
|
||||
var NewPerfKPIImpl = &PerfKPIImpl{}
|
||||
|
||||
// PerfKPIImpl 性能统计 数据层处理
|
||||
type PerfKPIImpl struct{}
|
||||
|
||||
// SelectGoldKPI 通过网元指标数据信息
|
||||
func (r *PerfKPIImpl) SelectGoldKPI(query model.GoldKPIQuery, kpiIds []string) []map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if query.RmUID != "" {
|
||||
conditions = append(conditions, "gk.rm_uid = ?")
|
||||
params = append(params, query.RmUID)
|
||||
}
|
||||
if query.NeType != "" {
|
||||
conditions = append(conditions, "gk.ne_type = ?")
|
||||
params = append(params, query.NeType)
|
||||
}
|
||||
if query.StartTime != "" {
|
||||
conditions = append(conditions, "gk.start_time >= ?")
|
||||
params = append(params, query.StartTime)
|
||||
}
|
||||
if query.EndTime != "" {
|
||||
conditions = append(conditions, "gk.start_time <= ?")
|
||||
params = append(params, query.EndTime)
|
||||
}
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询字段列
|
||||
timeFormat := "DATE_FORMAT(gk.start_time, '%Y-%m-%d %H:')"
|
||||
minuteGroup := fmt.Sprintf("LPAD(FLOOR(MINUTE(gk.start_time) / %d) * %d, 2, '0')", query.Interval, query.Interval)
|
||||
groupByField := fmt.Sprintf("CONCAT( %s, %s ) AS timeGroup", timeFormat, minuteGroup)
|
||||
var fields = []string{
|
||||
groupByField,
|
||||
"min(CASE WHEN gk.index != '' THEN gk.index ELSE 0 END) AS startIndex",
|
||||
"min(CASE WHEN gk.ne_name != '' THEN gk.ne_name ELSE 0 END) AS neName",
|
||||
}
|
||||
for _, kid := range kpiIds {
|
||||
// 特殊字段,只取最后一次收到的非0值
|
||||
if kid == "AMF.01" || kid == "UDM.01" || kid == "UDM.02" || kid == "UDM.03" {
|
||||
str := fmt.Sprintf("IFNULL(SUBSTRING_INDEX(GROUP_CONCAT( CASE WHEN gk.kpi_id = '%s' and gk.VALUE != 0 THEN gk.VALUE END ), ',', 1), 0) AS '%s'", kid, kid)
|
||||
fields = append(fields, str)
|
||||
} else {
|
||||
str := fmt.Sprintf("sum(CASE WHEN gk.kpi_id = '%s' THEN gk.value ELSE 0 END) AS '%s'", kid, kid)
|
||||
fields = append(fields, str)
|
||||
}
|
||||
}
|
||||
fieldsSql := strings.Join(fields, ",")
|
||||
|
||||
// 查询数据
|
||||
if query.SortField == "" {
|
||||
query.SortField = "timeGroup"
|
||||
}
|
||||
if query.SortOrder == "" {
|
||||
query.SortOrder = "desc"
|
||||
}
|
||||
orderSql := fmt.Sprintf(" order by %s %s", query.SortField, query.SortOrder)
|
||||
querySql := fmt.Sprintf("SELECT %s FROM gold_kpi gk %s GROUP BY timeGroup %s", fieldsSql, whereSql, orderSql)
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// SelectGoldKPITitle 通过网元指标数据信息
|
||||
func (r *PerfKPIImpl) SelectGoldKPITitle(neType string) []model.GoldKPITitle {
|
||||
result := []model.GoldKPITitle{}
|
||||
tx := datasource.DefaultDB().Table("kpi_title").Where("ne_type = ?", neType).Find(&result)
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("Delete err => %v", err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// UDM鉴权信息 数据层接口
|
||||
|
||||
@@ -3,11 +3,11 @@ package repository
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/datasource"
|
||||
"ems.agt/src/framework/logger"
|
||||
"ems.agt/src/framework/utils/parse"
|
||||
"ems.agt/src/framework/utils/repo"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 UDMAuthImpl 结构体
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// UDM签约信息 数据层接口
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/datasource"
|
||||
"ems.agt/src/framework/logger"
|
||||
"ems.agt/src/framework/utils/parse"
|
||||
"ems.agt/src/framework/utils/repo"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/utils/repo"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 UDMSubImpl 结构体
|
||||
|
||||
@@ -6,16 +6,16 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ems.agt/src/framework/logger"
|
||||
"ems.agt/src/framework/utils/fetch"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/fetch"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// NeState 获取网元端服务状态
|
||||
func NeState(neInfo model.NeInfo) (map[string]any, error) {
|
||||
// 网元直连
|
||||
// 网元状态
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/systemState", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType))
|
||||
resBytes, err := fetch.Get(neUrl, nil, 200)
|
||||
resBytes, err := fetch.Get(neUrl, nil, 250)
|
||||
if err != nil {
|
||||
logger.Warnf("NeState %s", err.Error())
|
||||
return nil, err
|
||||
@@ -44,3 +44,37 @@ func NeState(neInfo model.NeInfo) (map[string]any, error) {
|
||||
"disk": resData["diskSpace"],
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NeConfigOMC 网元配置对端网管信息
|
||||
func NeConfigOMC(neInfo model.NeInfo) (map[string]any, error) {
|
||||
// 网元配置对端网管信息
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType))
|
||||
resBytes, err := fetch.PutJSON(neUrl, map[string]any{
|
||||
"neId": neInfo.NeId,
|
||||
"neName": neInfo.NeName,
|
||||
"port": neInfo.Port,
|
||||
"province": neInfo.Province,
|
||||
"pvFlag": neInfo.PvFlag,
|
||||
"rmUID": neInfo.RmUID,
|
||||
"vendorName": neInfo.VendorName,
|
||||
"dn": neInfo.Dn,
|
||||
}, nil)
|
||||
var resData map[string]any
|
||||
if err != nil {
|
||||
status := err.Error()
|
||||
logger.Warnf("NeConfigOMC %s", status)
|
||||
if strings.HasPrefix(status, "204") {
|
||||
return resData, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Warnf("NeConfigOMC Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
30
src/modules/network_element/service/ne_host.go
Normal file
30
src/modules/network_element/service/ne_host.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package service
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeHost 网元主机连接 服务层接口
|
||||
type INeHost interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neHost model.NeHost) []model.NeHost
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectById(hostId string) model.NeHost
|
||||
|
||||
// CheckUniqueHostTitle 校验分组组和主机名称是否唯一
|
||||
CheckUniqueHostTitle(groupId, title, hostType, hostId string) bool
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neHost model.NeHost) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neHost model.NeHost) int64
|
||||
|
||||
// Insert 批量添加
|
||||
Inserts(neHosts []model.NeHost) int64
|
||||
|
||||
// DeleteByIds 批量删除网元主机连接信息
|
||||
DeleteByIds(hostIds []string) (int64, error)
|
||||
}
|
||||
92
src/modules/network_element/service/ne_host.impl.go
Normal file
92
src/modules/network_element/service/ne_host.impl.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 NeHostImpl 结构体
|
||||
var NewNeHostImpl = &NeHostImpl{
|
||||
neHostRepository: repository.NewNeHostImpl,
|
||||
}
|
||||
|
||||
// NeHostImpl 网元主机连接 服务层处理
|
||||
type NeHostImpl struct {
|
||||
// 网元主机连接表
|
||||
neHostRepository repository.INeHost
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeHostImpl) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neHostRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeHostImpl) SelectList(neHost model.NeHost) []model.NeHost {
|
||||
return r.neHostRepository.SelectList(neHost)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeHostImpl) SelectById(hostId string) model.NeHost {
|
||||
if hostId == "" {
|
||||
return model.NeHost{}
|
||||
}
|
||||
neHosts := r.neHostRepository.SelectByIds([]string{hostId})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.NeHost{}
|
||||
}
|
||||
|
||||
// Insert 批量添加
|
||||
func (r *NeHostImpl) Inserts(neHosts []model.NeHost) int64 {
|
||||
var num int64 = 0
|
||||
for _, v := range neHosts {
|
||||
hostId := r.neHostRepository.Insert(v)
|
||||
if hostId != "" {
|
||||
num += 1
|
||||
}
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeHostImpl) Insert(neHost model.NeHost) string {
|
||||
return r.neHostRepository.Insert(neHost)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeHostImpl) Update(neHost model.NeHost) int64 {
|
||||
return r.neHostRepository.Update(neHost)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除网元主机连接信息
|
||||
func (r *NeHostImpl) DeleteByIds(hostIds []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
ids := r.neHostRepository.SelectByIds(hostIds)
|
||||
if len(ids) <= 0 {
|
||||
return 0, fmt.Errorf("neHost.noData")
|
||||
}
|
||||
|
||||
if len(ids) == len(hostIds) {
|
||||
rows := r.neHostRepository.DeleteByIds(hostIds)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// CheckUniqueHostTitle 校验分组组和主机名称是否唯一
|
||||
func (r *NeHostImpl) CheckUniqueHostTitle(groupId, title, hostType, hostId string) bool {
|
||||
uniqueId := r.neHostRepository.CheckUniqueNeHost(model.NeHost{
|
||||
HostType: hostType,
|
||||
GroupID: groupId,
|
||||
Title: title,
|
||||
})
|
||||
if uniqueId == hostId {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
}
|
||||
27
src/modules/network_element/service/ne_host_cmd.go
Normal file
27
src/modules/network_element/service/ne_host_cmd.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package service
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeHostCmd 网元主机命令 服务层接口
|
||||
type INeHostCmd interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neHostCmd model.NeHostCmd) []model.NeHostCmd
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
SelectById(cmdId string) model.NeHostCmd
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neHostCmd model.NeHostCmd) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neHostCmd model.NeHostCmd) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(cmdIds []string) (int64, error)
|
||||
|
||||
// CheckUniqueGroupTitle 校验同类型组内是否唯一
|
||||
CheckUniqueGroupTitle(groupId, title, cmdType, cmdId string) bool
|
||||
}
|
||||
80
src/modules/network_element/service/ne_host_cmd.impl.go
Normal file
80
src/modules/network_element/service/ne_host_cmd.impl.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 NeHostCmdImpl 结构体
|
||||
var NewNeHostCmdImpl = &NeHostCmdImpl{
|
||||
neHostCmdRepository: repository.NewNeHostCmdImpl,
|
||||
}
|
||||
|
||||
// NeHostCmdImpl 网元主机命令 服务层处理
|
||||
type NeHostCmdImpl struct {
|
||||
// 网元主机命令表
|
||||
neHostCmdRepository repository.INeHostCmd
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeHostCmdImpl) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neHostCmdRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeHostCmdImpl) SelectList(neHostCmd model.NeHostCmd) []model.NeHostCmd {
|
||||
return r.neHostCmdRepository.SelectList(neHostCmd)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeHostCmdImpl) SelectById(cmdId string) model.NeHostCmd {
|
||||
if cmdId == "" {
|
||||
return model.NeHostCmd{}
|
||||
}
|
||||
neHosts := r.neHostCmdRepository.SelectByIds([]string{cmdId})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.NeHostCmd{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeHostCmdImpl) Insert(neHostCmd model.NeHostCmd) string {
|
||||
return r.neHostCmdRepository.Insert(neHostCmd)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeHostCmdImpl) Update(neHostCmd model.NeHostCmd) int64 {
|
||||
return r.neHostCmdRepository.Update(neHostCmd)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeHostCmdImpl) DeleteByIds(cmdIds []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
ids := r.neHostCmdRepository.SelectByIds(cmdIds)
|
||||
if len(ids) <= 0 {
|
||||
return 0, fmt.Errorf("neHostCmd.noData")
|
||||
}
|
||||
|
||||
if len(ids) == len(cmdIds) {
|
||||
rows := r.neHostCmdRepository.DeleteByIds(cmdIds)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// CheckUniqueGroupTitle 校验同类型组内是否唯一
|
||||
func (r *NeHostCmdImpl) CheckUniqueGroupTitle(groupId, title, cmdType, cmdId string) bool {
|
||||
uniqueId := r.neHostCmdRepository.CheckUniqueGroupTitle(model.NeHostCmd{
|
||||
CmdType: cmdType,
|
||||
GroupID: groupId,
|
||||
Title: title,
|
||||
})
|
||||
if uniqueId == cmdId {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package service
|
||||
|
||||
import "ems.agt/src/modules/network_element/model"
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// 网元信息 服务层接口
|
||||
type INeInfo interface {
|
||||
@@ -13,6 +13,33 @@ type INeInfo interface {
|
||||
// ClearNeCacheByNeType 清除网元类型缓存
|
||||
ClearNeCacheByNeType(neType string) bool
|
||||
|
||||
// SelectNeList 查询网元列表
|
||||
SelectNeList(ne model.NeInfo, bandStatus bool) []model.NeInfo
|
||||
// SelectNeInfoByRmuid 通过rmUID查询网元信息
|
||||
SelectNeInfoByRmuid(rmUid string) model.NeInfo
|
||||
|
||||
// SelectPage 根据条件分页查询
|
||||
//
|
||||
// bandStatus 带状态信息
|
||||
SelectPage(query map[string]any, bandStatus bool) map[string]any
|
||||
|
||||
// SelectList 查询列表
|
||||
//
|
||||
// bandStatus 带状态信息
|
||||
SelectList(ne model.NeInfo, bandStatus bool) []model.NeInfo
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
//
|
||||
// bandStatus 带主机信息
|
||||
SelectById(infoId string, bandHost bool) model.NeInfo
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neInfo model.NeInfo) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neInfo model.NeInfo) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(infoIds []string) (int64, error)
|
||||
|
||||
// CheckUniqueNeTypeAndNeId 校验同类型下标识是否唯一
|
||||
CheckUniqueNeTypeAndNeId(neType, neId, infoId string) bool
|
||||
}
|
||||
|
||||
@@ -3,28 +3,32 @@ package service
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/constants/cachekey"
|
||||
"ems.agt/src/framework/redis"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"ems.agt/src/modules/network_element/repository"
|
||||
"be.ems/src/framework/constants/cachekey"
|
||||
"be.ems/src/framework/redis"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 NeInfoImpl 结构体
|
||||
var NewNeInfoImpl = &NeInfoImpl{
|
||||
neInfoRepository: repository.NewNeInfoImpl,
|
||||
neHostRepository: repository.NewNeHostImpl,
|
||||
}
|
||||
|
||||
// 网元信息 服务层处理
|
||||
type NeInfoImpl struct {
|
||||
// 网元信息数据信息
|
||||
neInfoRepository repository.INeInfo
|
||||
// 网元主机连接表
|
||||
neHostRepository repository.INeHost
|
||||
}
|
||||
|
||||
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||
func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
var neInfo model.NeInfo
|
||||
key := fmt.Sprintf("%s%s.%s", cachekey.NE_KEY, neType, neID)
|
||||
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, neType, neID)
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
err := json.Unmarshal([]byte(jsonStr), &neInfo)
|
||||
@@ -45,7 +49,7 @@ func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeIn
|
||||
// RefreshByNeTypeAndNeID 通过ne_type和ne_id刷新redis中的缓存
|
||||
func (r *NeInfoImpl) RefreshByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
var neInfo model.NeInfo
|
||||
key := fmt.Sprintf("%s%s.%s", cachekey.NE_KEY, neType, neID)
|
||||
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, neType, neID)
|
||||
redis.Del("", key)
|
||||
neInfo = r.neInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
|
||||
if neInfo.NeId == neID {
|
||||
@@ -69,9 +73,85 @@ func (r *NeInfoImpl) ClearNeCacheByNeType(neType string) bool {
|
||||
return delOk
|
||||
}
|
||||
|
||||
// SelectNeList 查询网元列表
|
||||
func (r *NeInfoImpl) SelectNeList(ne model.NeInfo, bandStatus bool) []model.NeInfo {
|
||||
list := r.neInfoRepository.SelectNeList(ne)
|
||||
// SelectNeInfoByRmuid 通过rmUID查询网元信息
|
||||
func (r *NeInfoImpl) SelectNeInfoByRmuid(rmUid string) model.NeInfo {
|
||||
var neInfo model.NeInfo
|
||||
cacheKeys, _ := redis.GetKeys("", cachekey.NE_KEY+"*")
|
||||
if len(cacheKeys) > 0 {
|
||||
for _, key := range cacheKeys {
|
||||
var v model.NeInfo
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
json.Unmarshal([]byte(jsonStr), &v)
|
||||
}
|
||||
if v.RmUID == rmUid {
|
||||
neInfo = v
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
neInfos := r.SelectList(neInfo, false)
|
||||
for _, v := range neInfos {
|
||||
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, v.NeType, v.NeId)
|
||||
redis.Del("", key)
|
||||
values, _ := json.Marshal(v)
|
||||
redis.Set("", key, string(values))
|
||||
if v.RmUID == rmUid {
|
||||
neInfo = v
|
||||
}
|
||||
}
|
||||
}
|
||||
return neInfo
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询
|
||||
//
|
||||
// bandStatus 带状态信息
|
||||
func (r *NeInfoImpl) SelectPage(query map[string]any, bandStatus bool) map[string]any {
|
||||
data := r.neInfoRepository.SelectPage(query)
|
||||
|
||||
// 网元直连读取网元服务状态
|
||||
if bandStatus {
|
||||
rows := data["rows"].([]model.NeInfo)
|
||||
arr := &rows
|
||||
for i := range *arr {
|
||||
v := (*arr)[i]
|
||||
result, err := NeState(v)
|
||||
if err != nil {
|
||||
(*arr)[i].ServerState = map[string]any{
|
||||
"online": false,
|
||||
}
|
||||
// 网元状态设置为离线
|
||||
if v.Status != "1" {
|
||||
v.Status = "1"
|
||||
r.neInfoRepository.Update(v)
|
||||
}
|
||||
continue
|
||||
}
|
||||
result["online"] = true
|
||||
(*arr)[i].ServerState = result
|
||||
// 网元状态设置为在线
|
||||
if v.Status != "0" {
|
||||
// 下发网管配置信息给网元
|
||||
_, err = NeConfigOMC(v)
|
||||
if err != nil {
|
||||
v.Status = "3"
|
||||
} else {
|
||||
v.Status = "0"
|
||||
}
|
||||
r.neInfoRepository.Update(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
// SelectList 查询列表
|
||||
//
|
||||
// bandStatus 带状态信息
|
||||
func (r *NeInfoImpl) SelectList(ne model.NeInfo, bandStatus bool) []model.NeInfo {
|
||||
list := r.neInfoRepository.SelectList(ne)
|
||||
|
||||
// 网元直连读取网元服务状态
|
||||
if bandStatus {
|
||||
@@ -83,12 +163,130 @@ func (r *NeInfoImpl) SelectNeList(ne model.NeInfo, bandStatus bool) []model.NeIn
|
||||
(*neList)[i].ServerState = map[string]any{
|
||||
"online": false,
|
||||
}
|
||||
// 网元状态设置为离线
|
||||
if v.Status != "1" {
|
||||
v.Status = "1"
|
||||
r.neInfoRepository.Update(v)
|
||||
}
|
||||
continue
|
||||
}
|
||||
result["online"] = true
|
||||
(*neList)[i].ServerState = result
|
||||
// 网元状态设置为在线
|
||||
if v.Status != "0" {
|
||||
// 下发网管配置信息给网元
|
||||
_, err = NeConfigOMC(v)
|
||||
if err != nil {
|
||||
v.Status = "3"
|
||||
} else {
|
||||
v.Status = "0"
|
||||
}
|
||||
r.neInfoRepository.Update(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
//
|
||||
// bandStatus 带主机信息
|
||||
func (r *NeInfoImpl) SelectById(infoId string, bandHost bool) model.NeInfo {
|
||||
if infoId == "" {
|
||||
return model.NeInfo{}
|
||||
}
|
||||
neInfos := r.neInfoRepository.SelectByIds([]string{infoId})
|
||||
if len(neInfos) > 0 {
|
||||
neInfo := neInfos[0]
|
||||
// 带主机信息
|
||||
if neInfo.HostIDs != "" && bandHost {
|
||||
neInfo.Hosts = r.neHostRepository.SelectByIds(strings.Split(neInfo.HostIDs, ","))
|
||||
}
|
||||
return neInfo
|
||||
}
|
||||
return model.NeInfo{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeInfoImpl) Insert(neInfo model.NeInfo) string {
|
||||
// 主机信息新增
|
||||
if neInfo.Hosts != nil {
|
||||
var hostIDs []string
|
||||
for _, host := range neInfo.Hosts {
|
||||
host.Title = fmt.Sprintf("%s_%s_%d", strings.ToUpper(neInfo.NeType), neInfo.NeId, host.Port)
|
||||
host.GroupID = "1"
|
||||
hostId := r.neHostRepository.Insert(host)
|
||||
if hostId != "" {
|
||||
hostIDs = append(hostIDs, hostId)
|
||||
}
|
||||
}
|
||||
neInfo.HostIDs = strings.Join(hostIDs, ",")
|
||||
}
|
||||
|
||||
insertId := r.neInfoRepository.Insert(neInfo)
|
||||
if insertId != "" {
|
||||
// 刷新缓存
|
||||
r.RefreshByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||
}
|
||||
return insertId
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeInfoImpl) Update(neInfo model.NeInfo) int64 {
|
||||
// 主机信息更新
|
||||
if neInfo.Hosts != nil {
|
||||
for _, host := range neInfo.Hosts {
|
||||
if host.HostID != "" {
|
||||
host.Title = fmt.Sprintf("%s_%s_%d", strings.ToUpper(neInfo.NeType), neInfo.NeId, host.Port)
|
||||
host.GroupID = "1"
|
||||
r.neHostRepository.Update(host)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
num := r.neInfoRepository.Update(neInfo)
|
||||
if num > 0 {
|
||||
// 刷新缓存
|
||||
r.RefreshByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeInfoImpl) DeleteByIds(infoIds []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
infos := r.neInfoRepository.SelectByIds(infoIds)
|
||||
if len(infos) <= 0 {
|
||||
return 0, fmt.Errorf("neHostCmd.noData")
|
||||
}
|
||||
|
||||
if len(infos) == len(infoIds) {
|
||||
for _, v := range infos {
|
||||
// 主机信息删除
|
||||
if v.HostIDs != "" {
|
||||
hostIds := strings.Split(v.HostIDs, ",")
|
||||
r.neHostRepository.DeleteByIds(hostIds)
|
||||
}
|
||||
// 缓存信息删除
|
||||
key := fmt.Sprintf("%s%s:%s", cachekey.NE_KEY, v.NeType, v.NeId)
|
||||
redis.Del("", key)
|
||||
}
|
||||
rows := r.neInfoRepository.DeleteByIds(infoIds)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// CheckUniqueNeTypeAndNeId 校验同类型下标识是否唯一
|
||||
func (r *NeInfoImpl) CheckUniqueNeTypeAndNeId(neType, neId, infoId string) bool {
|
||||
uniqueId := r.neInfoRepository.CheckUniqueNeTypeAndNeId(model.NeInfo{
|
||||
NeType: neType,
|
||||
NeId: neId,
|
||||
})
|
||||
if uniqueId == infoId {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
}
|
||||
|
||||
33
src/modules/network_element/service/ne_software.go
Normal file
33
src/modules/network_element/service/ne_software.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package service
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeSoftware 网元软件包信息 服务层接口
|
||||
type INeSoftware interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neSoftware model.NeSoftware) []model.NeSoftware
|
||||
|
||||
// SelectById 通过ID查询
|
||||
SelectById(id string) model.NeSoftware
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neSoftware model.NeSoftware) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neSoftware model.NeSoftware) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(ids []string) (int64, error)
|
||||
|
||||
// SelectByVersionAndPath 通过文件版本和路径查询
|
||||
SelectByVersionAndPath(version, path string) model.NeSoftware
|
||||
|
||||
// CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一
|
||||
CheckUniqueTypeAndFileNameAndVersion(neType, fileName, version, id string) bool
|
||||
|
||||
// Install 安装软件包
|
||||
Install(neSoftware model.NeSoftware) (string, error)
|
||||
}
|
||||
97
src/modules/network_element/service/ne_software.impl.go
Normal file
97
src/modules/network_element/service/ne_software.impl.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 NeSoftwareImpl 结构体
|
||||
var NewNeSoftwareImpl = &NeSoftwareImpl{
|
||||
neSoftwareRepository: repository.NewNeSoftwareImpl,
|
||||
}
|
||||
|
||||
// NeSoftwareImpl 网元软件包信息 服务层处理
|
||||
type NeSoftwareImpl struct {
|
||||
// 网元软件包信息
|
||||
neSoftwareRepository repository.INeSoftware
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeSoftwareImpl) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neSoftwareRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeSoftwareImpl) SelectList(neSoftware model.NeSoftware) []model.NeSoftware {
|
||||
return r.neSoftwareRepository.SelectList(neSoftware)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeSoftwareImpl) SelectById(id string) model.NeSoftware {
|
||||
if id == "" {
|
||||
return model.NeSoftware{}
|
||||
}
|
||||
neHosts := r.neSoftwareRepository.SelectByIds([]string{id})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[0]
|
||||
}
|
||||
return model.NeSoftware{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeSoftwareImpl) Insert(neSoftware model.NeSoftware) string {
|
||||
return r.neSoftwareRepository.Insert(neSoftware)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeSoftwareImpl) Update(neSoftware model.NeSoftware) int64 {
|
||||
return r.neSoftwareRepository.Update(neSoftware)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeSoftwareImpl) DeleteByIds(ids []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
rowIds := r.neSoftwareRepository.SelectByIds(ids)
|
||||
if len(rowIds) <= 0 {
|
||||
return 0, fmt.Errorf("neSoftware.noData")
|
||||
}
|
||||
|
||||
if len(rowIds) == len(ids) {
|
||||
rows := r.neSoftwareRepository.DeleteByIds(ids)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// SelectByVersionAndPath 通过文件版本和路径查询
|
||||
func (r *NeSoftwareImpl) SelectByVersionAndPath(version, path string) model.NeSoftware {
|
||||
neSoftwares := r.neSoftwareRepository.SelectList(model.NeSoftware{
|
||||
Version: version,
|
||||
Path: path,
|
||||
})
|
||||
if len(neSoftwares) > 0 {
|
||||
return neSoftwares[0]
|
||||
}
|
||||
return model.NeSoftware{}
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一
|
||||
func (r *NeSoftwareImpl) CheckUniqueTypeAndFileNameAndVersion(neType, fileName, version, id string) bool {
|
||||
uniqueId := r.neSoftwareRepository.CheckUniqueTypeAndFileNameAndVersion(model.NeSoftware{
|
||||
NeType: neType,
|
||||
FileName: fileName,
|
||||
Version: version,
|
||||
})
|
||||
if uniqueId == id {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
}
|
||||
|
||||
// Install 安装软件包
|
||||
func (r *NeSoftwareImpl) Install(neSoftware model.NeSoftware) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
30
src/modules/network_element/service/ne_version.go
Normal file
30
src/modules/network_element/service/ne_version.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package service
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// INeVersion 网元版本信息 服务层接口
|
||||
type INeVersion interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neVersion model.NeVersion) []model.NeVersion
|
||||
|
||||
// SelectById 通过ID查询
|
||||
SelectById(id string) model.NeVersion
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neVersion model.NeVersion) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neVersion model.NeVersion) int64
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(ids []string) (int64, error)
|
||||
|
||||
// SelectByTypeAndID 通过网元类型和网元ID查询
|
||||
SelectByTypeAndID(neType, neId string) model.NeVersion
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
CheckUniqueTypeAndID(neType, neId, id string) bool
|
||||
}
|
||||
91
src/modules/network_element/service/ne_version.impl.go
Normal file
91
src/modules/network_element/service/ne_version.impl.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 NeVersionImpl 结构体
|
||||
var NewNeVersionImpl = &NeVersionImpl{
|
||||
neVersionRepository: repository.NewNeVersionImpl,
|
||||
}
|
||||
|
||||
// NeVersionImpl 网元版本信息 服务层处理
|
||||
type NeVersionImpl struct {
|
||||
// 网元版本信息表
|
||||
neVersionRepository repository.INeVersion
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeVersionImpl) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neVersionRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeVersionImpl) SelectList(neVersion model.NeVersion) []model.NeVersion {
|
||||
return r.neVersionRepository.SelectList(neVersion)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeVersionImpl) SelectById(id string) model.NeVersion {
|
||||
if id == "" {
|
||||
return model.NeVersion{}
|
||||
}
|
||||
neVersions := r.neVersionRepository.SelectByIds([]string{id})
|
||||
if len(neVersions) > 0 {
|
||||
return neVersions[0]
|
||||
}
|
||||
return model.NeVersion{}
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeVersionImpl) Insert(neVersion model.NeVersion) string {
|
||||
return r.neVersionRepository.Insert(neVersion)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeVersionImpl) Update(neVersion model.NeVersion) int64 {
|
||||
return r.neVersionRepository.Update(neVersion)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *NeVersionImpl) DeleteByIds(ids []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
rowIds := r.neVersionRepository.SelectByIds(ids)
|
||||
if len(rowIds) <= 0 {
|
||||
return 0, fmt.Errorf("neVersion.noData")
|
||||
}
|
||||
|
||||
if len(rowIds) == len(ids) {
|
||||
rows := r.neVersionRepository.DeleteByIds(ids)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// SelectByTypeAndID 通过网元类型和网元ID查询
|
||||
func (r *NeVersionImpl) SelectByTypeAndID(neType, neId string) model.NeVersion {
|
||||
neVersions := r.neVersionRepository.SelectList(model.NeVersion{
|
||||
NeType: neType,
|
||||
NeId: neId,
|
||||
})
|
||||
if len(neVersions) > 0 {
|
||||
return neVersions[0]
|
||||
}
|
||||
return model.NeVersion{}
|
||||
}
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
func (r *NeVersionImpl) CheckUniqueTypeAndID(neType, neId, id string) bool {
|
||||
uniqueId := r.neVersionRepository.CheckUniqueTypeAndID(model.NeVersion{
|
||||
NeType: neType,
|
||||
NeId: neId,
|
||||
})
|
||||
if uniqueId == id {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package service
|
||||
|
||||
import "ems.agt/src/modules/network_element/model"
|
||||
|
||||
// 性能统计 数据层接口
|
||||
type IPerfKPI interface {
|
||||
// SelectGoldKPI 通过网元指标数据信息
|
||||
SelectGoldKPI(query model.GoldKPIQuery) []map[string]any
|
||||
|
||||
// SelectGoldKPITitle
|
||||
SelectGoldKPITitle(neType string) []model.GoldKPITitle
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"ems.agt/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化数据层 PerfKPIImpl 结构体
|
||||
var NewPerfKPIImpl = &PerfKPIImpl{
|
||||
perfKPIRepository: repository.NewPerfKPIImpl,
|
||||
}
|
||||
|
||||
// PerfKPIImpl 性能统计 数据层处理
|
||||
type PerfKPIImpl struct {
|
||||
// 性能统计数据信息
|
||||
perfKPIRepository repository.IPerfKPI
|
||||
}
|
||||
|
||||
// SelectGoldKPI 通过网元指标数据信息
|
||||
func (r *PerfKPIImpl) SelectGoldKPI(query model.GoldKPIQuery) []map[string]any {
|
||||
// 获取数据指标id
|
||||
var kpiIds []string
|
||||
kpiTitles := r.perfKPIRepository.SelectGoldKPITitle(query.NeType)
|
||||
for _, kpiId := range kpiTitles {
|
||||
kpiIds = append(kpiIds, kpiId.KPIID)
|
||||
}
|
||||
|
||||
data := r.perfKPIRepository.SelectGoldKPI(query, kpiIds)
|
||||
if data == nil {
|
||||
return []map[string]any{}
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// SelectGoldKPITitle 通过网元指标数据信息
|
||||
func (r *PerfKPIImpl) SelectGoldKPITitle(neType string) []model.GoldKPITitle {
|
||||
return r.perfKPIRepository.SelectGoldKPITitle(neType)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package service
|
||||
|
||||
import "ems.agt/src/modules/network_element/model"
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// UDM鉴权信息 服务层接口
|
||||
type IUDMAuth interface {
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/redis"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"ems.agt/src/modules/network_element/repository"
|
||||
"be.ems/src/framework/redis"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 UDMAuthImpl 结构体
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package service
|
||||
|
||||
import "ems.agt/src/modules/network_element/model"
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
|
||||
// UDM签约用户信息 服务层接口
|
||||
type IUDMSub interface {
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/redis"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"ems.agt/src/modules/network_element/repository"
|
||||
"be.ems/src/framework/redis"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 UDMSubImpl 结构体
|
||||
|
||||
Reference in New Issue
Block a user