feat: omc原始代码
This commit is contained in:
158
src/modules/network_element/controller/ne_action.go
Normal file
158
src/modules/network_element/controller/ne_action.go
Normal file
@@ -0,0 +1,158 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"nms_nbi/src/framework/i18n"
|
||||
"nms_nbi/src/framework/utils/ctx"
|
||||
"nms_nbi/src/framework/utils/file"
|
||||
"nms_nbi/src/framework/utils/ssh"
|
||||
"nms_nbi/src/framework/vo/result"
|
||||
neService "nms_nbi/src/modules/network_element/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 NeActionController 结构体
|
||||
var NewNeAction = &NeActionController{
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
}
|
||||
|
||||
// 网元处理请求
|
||||
//
|
||||
// PATH /action
|
||||
type NeActionController struct {
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
}
|
||||
|
||||
// 发送文件到网元端
|
||||
//
|
||||
// POST /pushFile
|
||||
func (s *NeActionController) PushFile(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"`
|
||||
NeID string `json:"neId" binding:"required"`
|
||||
UploadPath string `json:"uploadPath" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID)
|
||||
if neInfo.NeId != body.NeID || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 本地文件
|
||||
localPath := file.ParseUploadFilePath(body.UploadPath)
|
||||
nePath := "/tmp" //config.Get("mml.upload").(string)
|
||||
// 复制到远程
|
||||
err := ssh.FileSCPLocalToNe(neInfo.IP, localPath, nePath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 网元端文件路径
|
||||
fileName := localPath[strings.LastIndex(localPath, "/")+1:]
|
||||
neFilePath := fmt.Sprintf("%s/%s", nePath, fileName)
|
||||
c.JSON(200, result.OkData(filepath.ToSlash(neFilePath)))
|
||||
}
|
||||
|
||||
// 获取文件从网元到本地
|
||||
//
|
||||
// GET /pullFile
|
||||
func (s *NeActionController) PullFile(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"`
|
||||
NeID string `form:"neId" binding:"required"`
|
||||
Path string `form:"path" binding:"required"`
|
||||
FileName string `form:"fileName" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
|
||||
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
nePath := fmt.Sprintf("%s/%s", querys.Path, querys.FileName)
|
||||
localPath := fmt.Sprintf("/tmp/omc/pullFile/%s", querys.FileName)
|
||||
err := ssh.FileSCPNeToLocal(neInfo.IP, nePath, localPath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.FileAttachment(localPath, querys.FileName)
|
||||
}
|
||||
|
||||
// 网元端文件列表
|
||||
//
|
||||
// GET /files
|
||||
func (s *NeActionController) Files(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"`
|
||||
NeID string `form:"neId" binding:"required"`
|
||||
Path string `form:"path" binding:"required"`
|
||||
PageNum int64 `form:"pageNum" binding:"required"`
|
||||
PageSize int64 `form:"pageSize" binding:"required"`
|
||||
Search string `form:"search"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
|
||||
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
totalSize, rows, err := ssh.FileList(querys.Path, neInfo.IP, querys.Search)
|
||||
if err != nil {
|
||||
c.JSON(200, result.Ok(map[string]any{
|
||||
"path": querys.Path,
|
||||
"totalSize": totalSize,
|
||||
"total": len(rows),
|
||||
"rows": []ssh.FileListRow{},
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
// 对数组进行切片分页
|
||||
lenNum := int64(len(rows))
|
||||
start := (querys.PageNum - 1) * querys.PageSize
|
||||
end := start + querys.PageSize
|
||||
var splitRows []ssh.FileListRow
|
||||
if start >= lenNum {
|
||||
splitRows = []ssh.FileListRow{}
|
||||
} else if end >= lenNum {
|
||||
splitRows = rows[start:]
|
||||
} else {
|
||||
splitRows = rows[start:end]
|
||||
}
|
||||
|
||||
c.JSON(200, result.Ok(map[string]any{
|
||||
"path": querys.Path,
|
||||
"totalSize": totalSize,
|
||||
"total": lenNum,
|
||||
"rows": splitRows,
|
||||
}))
|
||||
}
|
||||
357
src/modules/network_element/controller/ne_host.go
Normal file
357
src/modules/network_element/controller/ne_host.go
Normal file
@@ -0,0 +1,357 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"nms_nbi/src/framework/i18n"
|
||||
"nms_nbi/src/framework/utils/ctx"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/utils/ssh"
|
||||
"nms_nbi/src/framework/utils/telnet"
|
||||
"nms_nbi/src/framework/vo/result"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
neService "nms_nbi/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))
|
||||
}
|
||||
153
src/modules/network_element/controller/ne_host_cmd.go
Normal file
153
src/modules/network_element/controller/ne_host_cmd.go
Normal file
@@ -0,0 +1,153 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"nms_nbi/src/framework/i18n"
|
||||
"nms_nbi/src/framework/utils/ctx"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/vo/result"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
neService "nms_nbi/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))
|
||||
}
|
||||
294
src/modules/network_element/controller/ne_info.go
Normal file
294
src/modules/network_element/controller/ne_info.go
Normal file
@@ -0,0 +1,294 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"nms_nbi/src/framework/i18n"
|
||||
"nms_nbi/src/framework/utils/ctx"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/vo/result"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
neService "nms_nbi/src/modules/network_element/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 NeInfoController 结构体
|
||||
var NewNeInfo = &NeInfoController{
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
}
|
||||
|
||||
// 网元信息请求
|
||||
//
|
||||
// PATH /
|
||||
type NeInfoController struct {
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
}
|
||||
|
||||
// neStateCacheMap 网元状态缓存最后一次成功的信息
|
||||
var neStateCacheMap sync.Map
|
||||
var mutex sync.Mutex
|
||||
|
||||
// 网元信息状态
|
||||
//
|
||||
// GET /state
|
||||
func (s *NeInfoController) State(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
|
||||
}
|
||||
neKey := fmt.Sprintf("%s_%s", neInfo.NeType, neInfo.NeId)
|
||||
|
||||
// 网元直连
|
||||
resData, err := neService.NeState(neInfo)
|
||||
if err != nil {
|
||||
mutex.Lock()
|
||||
// 异常取上次缓存
|
||||
resDataCache, ok := neStateCacheMap.Load(neKey)
|
||||
if ok && resDataCache != nil {
|
||||
resDataCache.(map[string]any)["online"] = false
|
||||
} else {
|
||||
resDataCache = map[string]any{
|
||||
"online": false,
|
||||
"neId": neInfo.NeId,
|
||||
"neName": neInfo.NeName,
|
||||
"neType": neInfo.NeType,
|
||||
"neIP": neInfo.IP,
|
||||
}
|
||||
}
|
||||
neStateCacheMap.Store(neKey, resDataCache)
|
||||
mutex.Unlock()
|
||||
c.JSON(200, result.OkData(resDataCache))
|
||||
return
|
||||
}
|
||||
|
||||
// 存入缓存
|
||||
resData["online"] = true
|
||||
mutex.Lock()
|
||||
neStateCacheMap.Store(neKey, resData)
|
||||
mutex.Unlock()
|
||||
c.JSON(200, result.OkData(resData))
|
||||
}
|
||||
|
||||
// 网元信息列表
|
||||
//
|
||||
// GET /list
|
||||
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"`
|
||||
NeId string `form:"neId"`
|
||||
BandStatus string `form:"bandStatus"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询实体参数
|
||||
ne := model.NeInfo{}
|
||||
if querys.NeType != "" {
|
||||
ne.NeType = querys.NeType
|
||||
}
|
||||
if querys.NeId != "" {
|
||||
ne.NeId = querys.NeId
|
||||
}
|
||||
bandStatus := parse.Boolean(querys.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))
|
||||
}
|
||||
181
src/modules/network_element/controller/ne_software.go
Normal file
181
src/modules/network_element/controller/ne_software.go
Normal file
@@ -0,0 +1,181 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"nms_nbi/src/framework/i18n"
|
||||
"nms_nbi/src/framework/utils/ctx"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/vo/result"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
neService "nms_nbi/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))
|
||||
}
|
||||
151
src/modules/network_element/controller/ne_version.go
Normal file
151
src/modules/network_element/controller/ne_version.go
Normal file
@@ -0,0 +1,151 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"nms_nbi/src/framework/i18n"
|
||||
"nms_nbi/src/framework/utils/ctx"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/vo/result"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
neService "nms_nbi/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))
|
||||
}
|
||||
472
src/modules/network_element/controller/udm_auth.go
Normal file
472
src/modules/network_element/controller/udm_auth.go
Normal file
@@ -0,0 +1,472 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mmlclient "nms_nbi/lib/core/mml_client"
|
||||
"nms_nbi/src/framework/constants/uploadsubpath"
|
||||
"nms_nbi/src/framework/i18n"
|
||||
"nms_nbi/src/framework/utils/ctx"
|
||||
"nms_nbi/src/framework/utils/file"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/utils/ssh"
|
||||
"nms_nbi/src/framework/vo/result"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
neService "nms_nbi/src/modules/network_element/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 UDMAuthController 结构体
|
||||
var NewUDMAuth = &UDMAuthController{
|
||||
udmAuthService: neService.NewUDMAuthImpl,
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
}
|
||||
|
||||
// UDM鉴权用户请求
|
||||
//
|
||||
// PATH /udm/auth
|
||||
type UDMAuthController struct {
|
||||
// UDM鉴权信息服务
|
||||
udmAuthService neService.IUDMAuth
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
}
|
||||
|
||||
// UDM鉴权用户-获取全部保存数据库
|
||||
//
|
||||
// POST /resetData/:neId
|
||||
func (s *UDMAuthController) ResetData(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
if neId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
neId = ""
|
||||
data := s.udmAuthService.Save(neId)
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// UDM鉴权用户
|
||||
//
|
||||
// GET /list
|
||||
func (s *UDMAuthController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
querys["neId"] = ""
|
||||
data := s.udmAuthService.Page(querys)
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// UDM鉴权用户-信息
|
||||
//
|
||||
// GET /:neId/:imsi
|
||||
func (s *UDMAuthController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
imsi := c.Param("imsi")
|
||||
if neId == "" || imsi == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("dsp authdat:imsi=%s", imsi)
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToMap(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if len(data) == 0 {
|
||||
c.JSON(200, result.ErrMsg("No Auth Data"))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询数据库是否存在并存入
|
||||
neId = ""
|
||||
var userInfo model.UDMAuth
|
||||
list := s.udmAuthService.List(model.UDMAuth{NeID: neId, Imsi: imsi})
|
||||
if len(list) > 0 {
|
||||
userInfo = list[0]
|
||||
// 返回查询的用户信息
|
||||
userInfo.Amf = data["amf"]
|
||||
userInfo.AlgoIndex = data["algo"]
|
||||
userInfo.Opc = data["opc"]
|
||||
userInfo.Ki = data["ki"]
|
||||
} else {
|
||||
userInfo := model.UDMAuth{
|
||||
Imsi: imsi,
|
||||
Amf: data["amf"],
|
||||
AlgoIndex: data["algo"],
|
||||
Opc: data["opc"],
|
||||
Ki: data["ki"],
|
||||
}
|
||||
s.udmAuthService.Insert(neId, userInfo)
|
||||
}
|
||||
c.JSON(200, result.OkData(userInfo))
|
||||
}
|
||||
|
||||
// UDM鉴权用户-增加
|
||||
//
|
||||
// POST /:neId
|
||||
func (s *UDMAuthController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
if neId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
var body model.UDMAuth
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.Imsi == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("add authdat:imsi=%s,ki=%s,amf=%s,algo=%s,opc=%s", body.Imsi, body.Ki, body.Amf, body.AlgoIndex, body.Opc)
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
neId = ""
|
||||
s.udmAuthService.Insert(neId, body)
|
||||
}
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// UDM鉴权用户-批量添加
|
||||
//
|
||||
// POST /:neId/:num
|
||||
func (s *UDMAuthController) Adds(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
num := c.Param("num")
|
||||
if neId == "" || num == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
var body model.UDMAuth
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.Imsi == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("baa authdat:start_imsi=%s,sub_num=%s,ki=%s,amf=%s,algo=%s,opc=%s", body.Imsi, num, body.Ki, body.Amf, body.AlgoIndex, body.Opc)
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
neId = ""
|
||||
s.udmAuthService.Inserts(neId, body, num)
|
||||
}
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// UDM鉴权用户-修改
|
||||
//
|
||||
// PUT /:neId
|
||||
func (s *UDMAuthController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
if neId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
var body model.UDMAuth
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.Imsi == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("mod authdata:imsi=%s", body.Imsi)
|
||||
// 修改的参数名称
|
||||
if body.Ki != "" {
|
||||
msg += fmt.Sprintf(",ki=%s", body.Ki)
|
||||
}
|
||||
if body.Amf != "" {
|
||||
msg += fmt.Sprintf(",amf=%s", body.Amf)
|
||||
}
|
||||
if body.AlgoIndex != "" {
|
||||
msg += fmt.Sprintf(",algo=%s", body.AlgoIndex)
|
||||
}
|
||||
if body.Opc != "" {
|
||||
msg += fmt.Sprintf(",opc=%s", body.Opc)
|
||||
}
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
neId = ""
|
||||
s.udmAuthService.Update(neId, body)
|
||||
}
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// UDM鉴权用户-删除
|
||||
//
|
||||
// DELETE /:neId/:imsi
|
||||
func (s *UDMAuthController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
imsi := c.Param("imsi")
|
||||
if neId == "" || imsi == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
imsiArr := strings.Split(imsi, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(imsiArr)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
resultData := map[string]string{}
|
||||
for _, imsi := range uniqueIDs {
|
||||
msg := fmt.Sprintf("del authdat:imsi=%s", imsi)
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
resultData[imsi] = err.Error()
|
||||
}
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
neId = ""
|
||||
s.udmAuthService.Delete(neId, imsi)
|
||||
resultData[imsi] = data
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(resultData))
|
||||
}
|
||||
|
||||
// UDM鉴权用户-批量删除
|
||||
//
|
||||
// DELETE /:neId/:imsi/:num
|
||||
func (s *UDMAuthController) Removes(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
imsi := c.Param("imsi")
|
||||
num := c.Param("num")
|
||||
if neId == "" || imsi == "" || num == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("bde authdat:start_imsi=%s,sub_num=%s", imsi, num)
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
neId = ""
|
||||
s.udmAuthService.Deletes(neId, imsi, num)
|
||||
}
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// UDM鉴权用户-导出
|
||||
//
|
||||
// POST /export
|
||||
func (s *UDMAuthController) Export(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeId string `json:"neId" binding:"required"`
|
||||
Type string `json:"type" binding:"required"`
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
if !(body.Type == "csv" || body.Type == "txt") {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserAuthFileFormat")))
|
||||
return
|
||||
}
|
||||
|
||||
neId := ""
|
||||
list := s.udmAuthService.List(model.UDMAuth{NeID: neId})
|
||||
// 文件名
|
||||
fileName := fmt.Sprintf("OMC_AUTH_USER_EXPORT_%s_%d.%s", neId, time.Now().UnixMilli(), body.Type)
|
||||
filePath := fmt.Sprintf("%s/%s", file.ParseUploadFileDir(uploadsubpath.EXPORT), fileName)
|
||||
|
||||
if body.Type == "csv" {
|
||||
// 转换数据
|
||||
data := [][]string{}
|
||||
data = append(data, []string{"imsi", "ki", "algo", "amf", "opc"})
|
||||
for _, v := range list {
|
||||
data = append(data, []string{v.Imsi, v.Ki, v.AlgoIndex, v.Amf, v.Opc})
|
||||
}
|
||||
// 输出到文件
|
||||
err := file.WriterCSVFile(data, filePath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if body.Type == "txt" {
|
||||
// 转换数据
|
||||
data := [][]string{}
|
||||
for _, v := range list {
|
||||
data = append(data, []string{v.Imsi, v.Ki, v.AlgoIndex, v.Amf, v.Opc})
|
||||
}
|
||||
// 输出到文件
|
||||
err = file.WriterTxtFile(data, filePath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.FileAttachment(filePath, fileName)
|
||||
}
|
||||
|
||||
// UDM鉴权用户-导入
|
||||
//
|
||||
// POST /import
|
||||
func (s *UDMAuthController) Import(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.PostForm("neId")
|
||||
if neId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
formFile, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
// 获取文件名
|
||||
if !(strings.HasSuffix(formFile.Filename, ".csv") || strings.HasSuffix(formFile.Filename, ".txt")) {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserAuthFileFormat")))
|
||||
return
|
||||
}
|
||||
// 上传文件转存
|
||||
upFilePath, err := file.TransferUploadFile(formFile, uploadsubpath.IMPORT, nil)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 本地文件
|
||||
localPath := file.ParseUploadFilePath(upFilePath)
|
||||
nePath := "/tmp" //config.Get("mml.upload").(string)
|
||||
// 复制到远程
|
||||
err = ssh.FileSCPLocalToNe(neInfo.IP, localPath, nePath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
fileName := localPath[strings.LastIndex(localPath, "/")+1:]
|
||||
msg := fmt.Sprintf("import authdat:path=%s", fmt.Sprintf("%s/%s", nePath, fileName))
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
if strings.HasSuffix(fileName, ".csv") {
|
||||
data := file.ReadCSVFile(localPath)
|
||||
neId = ""
|
||||
go s.udmAuthService.InsertCSV(neId, data)
|
||||
}
|
||||
if strings.HasSuffix(fileName, ".txt") {
|
||||
data := file.ReadTxtFile(localPath)
|
||||
neId = ""
|
||||
go s.udmAuthService.InsertTxt(neId, data)
|
||||
}
|
||||
}
|
||||
c.JSON(200, result.OkMsg(data))
|
||||
}
|
||||
550
src/modules/network_element/controller/udm_sub.go
Normal file
550
src/modules/network_element/controller/udm_sub.go
Normal file
@@ -0,0 +1,550 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mmlclient "nms_nbi/lib/core/mml_client"
|
||||
"nms_nbi/src/framework/constants/uploadsubpath"
|
||||
"nms_nbi/src/framework/i18n"
|
||||
"nms_nbi/src/framework/utils/ctx"
|
||||
"nms_nbi/src/framework/utils/file"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/utils/ssh"
|
||||
"nms_nbi/src/framework/vo/result"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
neService "nms_nbi/src/modules/network_element/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 UDMSubController 结构体
|
||||
var NewUDMSub = &UDMSubController{
|
||||
udmSubService: neService.NewUDMSubImpl,
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
}
|
||||
|
||||
// UDM签约用户请求
|
||||
//
|
||||
// PATH /udm/sub
|
||||
type UDMSubController struct {
|
||||
// UDM鉴权信息服务
|
||||
udmSubService neService.IUDMSub
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
}
|
||||
|
||||
// UDM签约用户-获取全部保存数据库
|
||||
//
|
||||
// POST /resetData/:neId
|
||||
func (s *UDMSubController) ResetData(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
if neId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
neId = ""
|
||||
data := s.udmSubService.Save(neId)
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// UDM签约用户
|
||||
//
|
||||
// GET /list
|
||||
func (s *UDMSubController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
querys["neId"] = ""
|
||||
data := s.udmSubService.Page(querys)
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// UDM签约用户-信息
|
||||
//
|
||||
// GET /:neId/:imsi
|
||||
func (s *UDMSubController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
imsi := c.Param("imsi")
|
||||
if neId == "" || imsi == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("dsp udmuser:imsi=%s", imsi)
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToMap(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if len(data) == 0 {
|
||||
c.JSON(200, result.ErrMsg("No Subs Data"))
|
||||
return
|
||||
}
|
||||
|
||||
// 解析返回的数据
|
||||
cnType, _ := strconv.ParseInt(data["CNType"][:4], 0, 64)
|
||||
rat, _ := strconv.ParseInt(data["RAT"][:4], 0, 64)
|
||||
msisdn := data["MSISDN"]
|
||||
imsMsisdnLen := strings.Index(msisdn, ",")
|
||||
if imsMsisdnLen != -1 {
|
||||
msisdn = msisdn[:imsMsisdnLen]
|
||||
}
|
||||
userInfo := model.UDMSub{
|
||||
Imsi: imsi,
|
||||
Msisdn: msisdn,
|
||||
Ambr: data["AMBR"],
|
||||
Arfb: data["AreaForbidden"],
|
||||
Cn: fmt.Sprint(cnType),
|
||||
SmData: data["SM-Data(snssai+dnn[1..n])"],
|
||||
Sar: data["ServiceAreaRestriction"],
|
||||
Nssai: data["NSSAI"],
|
||||
SmfSel: data["Smf-Selection"],
|
||||
Rat: fmt.Sprint(rat),
|
||||
}
|
||||
// 1,64,24,65,def_eps,1,2,010200000000,-
|
||||
if v, ok := data["EPS-Data"]; ok {
|
||||
userInfo.EpsDat = v
|
||||
arr := strings.Split(v, ",")
|
||||
userInfo.EpsFlag = arr[0]
|
||||
userInfo.EpsOdb = arr[1]
|
||||
userInfo.HplmnOdb = arr[2]
|
||||
userInfo.Ard = arr[3]
|
||||
userInfo.Epstpl = arr[4]
|
||||
userInfo.ContextId = arr[5]
|
||||
userInfo.ApnContext = arr[7]
|
||||
userInfo.StaticIp = arr[8]
|
||||
}
|
||||
|
||||
// 查询数据库是否存在并存入更新
|
||||
neId = ""
|
||||
list := s.udmSubService.List(model.UDMSub{NeID: neId, Imsi: imsi})
|
||||
if len(list) > 0 {
|
||||
listItme := list[0]
|
||||
userInfo.ID = listItme.ID
|
||||
s.udmSubService.Update(neId, userInfo)
|
||||
} else {
|
||||
s.udmSubService.Insert(neId, userInfo)
|
||||
}
|
||||
c.JSON(200, result.OkData(userInfo))
|
||||
}
|
||||
|
||||
// UDM签约用户-增加
|
||||
//
|
||||
// POST /:neId
|
||||
func (s *UDMSubController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
if neId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
var body model.UDMSub
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.Imsi == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("add udmuser:imsi=%s,msisdn=%s,ambr=%s,nssai=%s,arfb=%s,sar=%s,rat=%s,cn=%s,smf_sel=%s,sm_data=%s,eps_flag=%s,eps_odb=%s,hplmn_odb=%s,ard=%s,epstpl=%s,context_id=%s,apn_context=%s",
|
||||
body.Imsi, body.Msisdn, body.Ambr, body.Nssai, body.Arfb, body.Sar, body.Rat, body.Cn, body.SmfSel, body.SmData, body.EpsFlag, body.EpsOdb, body.HplmnOdb, body.Ard, body.Epstpl, body.ContextId, body.ApnContext)
|
||||
// static_ip指给4G UE分配的静态IP,没有可不带此字段名,批量添加IP会自动递增
|
||||
if body.StaticIp != "" {
|
||||
msg += fmt.Sprintf(",static_ip=%s", body.StaticIp)
|
||||
}
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
neId = ""
|
||||
s.udmSubService.Insert(neId, body)
|
||||
}
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// UDM签约用户-批量添加
|
||||
//
|
||||
// POST /:neId/:num
|
||||
func (s *UDMSubController) Adds(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
num := c.Param("num")
|
||||
if neId == "" || num == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
var body model.UDMSub
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.Imsi == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("baa udmuser:start_imsi=%s,start_msisdn=%s,sub_num=%s,ambr=%s,nssai=%s,arfb=%s,sar=%s,rat=%s,cn=%s,smf_sel=%s,sm_data=%s,eps_flag=%s,eps_odb=%s,hplmn_odb=%s,ard=%s,epstpl=%s,context_id=%s,apn_context=%s",
|
||||
body.Imsi, body.Msisdn, num, body.Ambr, body.Nssai, body.Arfb, body.Sar, body.Rat, body.Cn, body.SmfSel, body.SmData, body.EpsFlag, body.EpsOdb, body.HplmnOdb, body.Ard, body.Epstpl, body.ContextId, body.ApnContext)
|
||||
// static_ip指给4G UE分配的静态IP,没有可不带此字段名,批量添加IP会自动递增
|
||||
if body.StaticIp != "" {
|
||||
msg += fmt.Sprintf(",static_ip=%s", body.StaticIp)
|
||||
}
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
neId = ""
|
||||
s.udmSubService.Inserts(neId, body, num)
|
||||
}
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// UDM签约用户-修改
|
||||
//
|
||||
// PUT /:neId
|
||||
func (s *UDMSubController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
if neId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
var body model.UDMSub
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.Imsi == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("mod udmuser:imsi=%s", body.Imsi)
|
||||
// 修改的参数名称
|
||||
if body.Msisdn != "" {
|
||||
msg += fmt.Sprintf(",msisdn=%s", body.Msisdn)
|
||||
}
|
||||
if body.Ambr != "" {
|
||||
msg += fmt.Sprintf(",ambr=%s", body.Ambr)
|
||||
}
|
||||
if body.Nssai != "" {
|
||||
msg += fmt.Sprintf(",nssai=%s", body.Nssai)
|
||||
}
|
||||
if body.Arfb != "" {
|
||||
msg += fmt.Sprintf(",arfb=%s", body.Arfb)
|
||||
}
|
||||
if body.Sar != "" {
|
||||
msg += fmt.Sprintf(",sar=%s", body.Sar)
|
||||
}
|
||||
if body.Rat != "" {
|
||||
msg += fmt.Sprintf(",rat=%s", body.Rat)
|
||||
}
|
||||
if body.Cn != "" {
|
||||
msg += fmt.Sprintf(",cn=%s", body.Cn)
|
||||
}
|
||||
if body.SmfSel != "" {
|
||||
msg += fmt.Sprintf(",smf_sel=%s", body.SmfSel)
|
||||
}
|
||||
if body.SmData != "" {
|
||||
msg += fmt.Sprintf(",sm_data=%s", body.SmData)
|
||||
}
|
||||
if body.EpsDat != "" {
|
||||
msg += fmt.Sprintf(",eps_dat=%s", body.EpsDat)
|
||||
}
|
||||
if body.EpsFlag != "" {
|
||||
msg += fmt.Sprintf(",eps_flag=%s", body.EpsFlag)
|
||||
}
|
||||
if body.EpsOdb != "" {
|
||||
msg += fmt.Sprintf(",eps_odb=%s", body.EpsOdb)
|
||||
}
|
||||
if body.HplmnOdb != "" {
|
||||
msg += fmt.Sprintf(",hplmn_odb=%s", body.HplmnOdb)
|
||||
}
|
||||
if body.Epstpl != "" {
|
||||
msg += fmt.Sprintf(",epstpl=%s", body.Epstpl)
|
||||
}
|
||||
if body.Ard != "" {
|
||||
msg += fmt.Sprintf(",ard=%s", body.Ard)
|
||||
}
|
||||
if body.ContextId != "" {
|
||||
msg += fmt.Sprintf(",context_id=%s", body.ContextId)
|
||||
}
|
||||
if body.ApnContext != "" {
|
||||
msg += fmt.Sprintf(",apn_context=%s", body.ApnContext)
|
||||
}
|
||||
if body.StaticIp != "" {
|
||||
msg += fmt.Sprintf(",static_ip=%s", body.StaticIp)
|
||||
}
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
neId = ""
|
||||
s.udmSubService.Update(neId, body)
|
||||
}
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// UDM签约用户-删除
|
||||
//
|
||||
// DELETE /:neId/:imsi
|
||||
func (s *UDMSubController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
imsi := c.Param("imsi")
|
||||
if neId == "" || imsi == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
imsiArr := strings.Split(imsi, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(imsiArr)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
resultData := map[string]string{}
|
||||
for _, imsi := range uniqueIDs {
|
||||
msg := fmt.Sprintf("del udmuser:imsi=%s", imsi)
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
resultData[imsi] = err.Error()
|
||||
}
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
neId = ""
|
||||
s.udmSubService.Delete(neId, imsi)
|
||||
resultData[imsi] = data
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(resultData))
|
||||
}
|
||||
|
||||
// UDM签约用户-批量删除
|
||||
//
|
||||
// DELETE /:neId/:imsi/:num
|
||||
func (s *UDMSubController) Removes(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.Param("neId")
|
||||
imsi := c.Param("imsi")
|
||||
num := c.Param("num")
|
||||
if neId == "" || imsi == "" || num == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("bde udmuser:start_imsi=%s,sub_num=%s", imsi, num)
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
neId = ""
|
||||
s.udmSubService.Deletes(neId, imsi, num)
|
||||
}
|
||||
c.JSON(200, result.OkData(data))
|
||||
}
|
||||
|
||||
// UDM签约用户-导出
|
||||
//
|
||||
// POST /export
|
||||
func (s *UDMSubController) Export(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeId string `json:"neId" binding:"required"`
|
||||
Type string `json:"type" binding:"required"`
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
if !(body.Type == "csv" || body.Type == "txt") {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserSubFileFormat")))
|
||||
return
|
||||
}
|
||||
|
||||
neId := ""
|
||||
list := s.udmSubService.List(model.UDMSub{NeID: neId})
|
||||
// 文件名
|
||||
fileName := fmt.Sprintf("OMC_SUB_USER_EXPORT_%s_%d.%s", neId, time.Now().UnixMilli(), body.Type)
|
||||
filePath := fmt.Sprintf("%s/%s", file.ParseUploadFileDir(uploadsubpath.EXPORT), fileName)
|
||||
|
||||
if body.Type == "csv" {
|
||||
// 转换数据
|
||||
data := [][]string{}
|
||||
data = append(data, []string{"imsi", "msisdn", "ambr", "nssai", "arfb", "sar", "rat", "cn", "smf_sel", "sm_dat", "eps_dat"})
|
||||
for _, v := range list {
|
||||
epsDat := fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s,%s", v.EpsFlag, v.EpsOdb, v.HplmnOdb, v.Ard, v.Epstpl, v.ContextId, v.ApnContext, v.StaticIp)
|
||||
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)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if body.Type == "txt" {
|
||||
// 转换数据
|
||||
data := [][]string{}
|
||||
for _, v := range list {
|
||||
epsDat := fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s,%s", v.EpsFlag, v.EpsOdb, v.HplmnOdb, v.Ard, v.Epstpl, v.ContextId, v.ApnContext, v.StaticIp)
|
||||
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)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.FileAttachment(filePath, fileName)
|
||||
}
|
||||
|
||||
// UDM签约用户-导入
|
||||
//
|
||||
// POST /import
|
||||
func (s *UDMSubController) Import(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
neId := c.PostForm("neId")
|
||||
if neId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
formFile, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
// 获取文件名
|
||||
if !(strings.HasSuffix(formFile.Filename, ".csv") || strings.HasSuffix(formFile.Filename, ".txt")) {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserSubFileFormat")))
|
||||
return
|
||||
}
|
||||
// 上传文件转存
|
||||
upFilePath, err := file.TransferUploadFile(formFile, uploadsubpath.IMPORT, nil)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 本地文件
|
||||
localPath := file.ParseUploadFilePath(upFilePath)
|
||||
nePath := "/tmp" //config.Get("mml.upload").(string)
|
||||
// 复制到远程
|
||||
err = ssh.FileSCPLocalToNe(neInfo.IP, localPath, nePath)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
fileName := localPath[strings.LastIndex(localPath, "/")+1:]
|
||||
msg := fmt.Sprintf("import udmuser:path=%s", fmt.Sprintf("%s/%s", nePath, fileName))
|
||||
|
||||
// 发送MML
|
||||
data, err := mmlclient.MMLSendMsgToString(neInfo.IP, msg)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 命令ok时
|
||||
if strings.Contains(data, "ok") {
|
||||
if strings.HasSuffix(fileName, ".csv") {
|
||||
data := file.ReadCSVFile(localPath)
|
||||
neId = ""
|
||||
go s.udmSubService.InsertCSV(neId, data)
|
||||
}
|
||||
if strings.HasSuffix(fileName, ".txt") {
|
||||
data := file.ReadTxtFile(localPath)
|
||||
neId = ""
|
||||
go s.udmSubService.InsertTxt(neId, data)
|
||||
}
|
||||
}
|
||||
c.JSON(200, result.OkMsg(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"
|
||||
}
|
||||
28
src/modules/network_element/model/ne_info.go
Normal file
28
src/modules/network_element/model/ne_info.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package model
|
||||
|
||||
// NeInfo 网元信息对象 ne_info
|
||||
type NeInfo struct {
|
||||
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" 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: 待下发配置
|
||||
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"
|
||||
}
|
||||
17
src/modules/network_element/model/udm_auth.go
Normal file
17
src/modules/network_element/model/udm_auth.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
// UDMAuth UDM鉴权用户对象 u_auth_user
|
||||
type UDMAuth struct {
|
||||
ID string `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
|
||||
Imsi string `json:"imsi" gorm:"column:imsi"` // SIM卡号
|
||||
Amf string `json:"amf" gorm:"column:amf"` // ANF
|
||||
Status string `json:"status" gorm:"column:status"` // 状态
|
||||
Ki string `json:"ki" gorm:"column:ki"` // ki
|
||||
AlgoIndex string `json:"algoIndex" gorm:"column:algo_index"` // AlgoIndex
|
||||
Opc string `json:"opc" gorm:"column:opc"`
|
||||
NeID string `json:"neId" gorm:"column:ne_id"` // UDM网元标识-子系统
|
||||
}
|
||||
|
||||
func (UDMAuth) TableName() string {
|
||||
return "u_auth_user"
|
||||
}
|
||||
33
src/modules/network_element/model/udm_sub.go
Normal file
33
src/modules/network_element/model/udm_sub.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package model
|
||||
|
||||
// UDMSub UDM签约用户对象 u_sub_user
|
||||
type UDMSub struct {
|
||||
ID string `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
|
||||
Msisdn string `json:"msisdn" gorm:"column:msisdn"` // 相当手机号
|
||||
Imsi string `json:"imsi" gorm:"column:imsi"` // SIM卡号
|
||||
Ambr string `json:"ambr" gorm:"column:ambr"`
|
||||
Nssai string `json:"nssai" gorm:"column:nssai"`
|
||||
Rat string `json:"rat" gorm:"column:rat"`
|
||||
Arfb string `json:"arfb" gorm:"column:arfb"`
|
||||
Sar string `json:"sar" gorm:"column:sar"`
|
||||
Cn string `json:"cn" gorm:"column:cn"`
|
||||
SmData string `json:"smData" gorm:"column:sm_data"`
|
||||
SmfSel string `json:"smfSel" gorm:"column:smf_sel"`
|
||||
EpsDat string `json:"epsDat" gorm:"column:eps_dat"`
|
||||
NeID string `json:"neId" gorm:"column:ne_id"` // UDM网元标识-子系统
|
||||
|
||||
EpsFlag string `json:"epsFlag" gorm:"column:eps_flag"`
|
||||
EpsOdb string `json:"epsOdb" gorm:"column:eps_odb"`
|
||||
HplmnOdb string `json:"hplmnOdb" gorm:"column:hplmn_odb"`
|
||||
Ard string `json:"ard" gorm:"column:ard"`
|
||||
Epstpl string `json:"epstpl" gorm:"column:epstpl"`
|
||||
ContextId string `json:"contextId" gorm:"column:context_id"`
|
||||
ApnContext string `json:"apnContext" gorm:"column:apn_context"`
|
||||
StaticIp string `json:"staticIp" gorm:"column:static_ip"`
|
||||
|
||||
SubNum string `json:"subNum,omitempty" gorm:"-"` // 批量数
|
||||
}
|
||||
|
||||
func (UDMSub) TableName() string {
|
||||
return "u_sub_user"
|
||||
}
|
||||
326
src/modules/network_element/network_element.go
Normal file
326
src/modules/network_element/network_element.go
Normal file
@@ -0,0 +1,326 @@
|
||||
package networkelement
|
||||
|
||||
import (
|
||||
"nms_nbi/src/framework/logger"
|
||||
"nms_nbi/src/framework/middleware"
|
||||
"nms_nbi/src/framework/middleware/collectlogs"
|
||||
"nms_nbi/src/framework/middleware/repeat"
|
||||
"nms_nbi/src/modules/network_element/controller"
|
||||
"nms_nbi/src/modules/network_element/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 模块路由注册
|
||||
func Setup(router *gin.Engine) {
|
||||
logger.Infof("开始加载 ====> network_element 模块路由")
|
||||
|
||||
// 启动时需要的初始参数
|
||||
InitLoad()
|
||||
|
||||
neGroup := router.Group("/ne")
|
||||
|
||||
// 网元操作处理
|
||||
neActionGroup := neGroup.Group("/action")
|
||||
{
|
||||
neActionGroup.GET("/files",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeAction.Files,
|
||||
)
|
||||
neActionGroup.GET("/pullFile",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewNeAction.PullFile,
|
||||
)
|
||||
neActionGroup.POST("/pushFile",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neAction", collectlogs.BUSINESS_TYPE_IMPORT)),
|
||||
controller.NewNeAction.PushFile,
|
||||
)
|
||||
}
|
||||
|
||||
// 网元信息
|
||||
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")
|
||||
{
|
||||
udmAuthGroup.PUT("/resetData/:neId",
|
||||
repeat.RepeatSubmit(5),
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_CLEAN)),
|
||||
controller.NewUDMAuth.ResetData,
|
||||
)
|
||||
udmAuthGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewUDMAuth.List,
|
||||
)
|
||||
udmAuthGroup.GET("/:neId/:imsi",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewUDMAuth.Info,
|
||||
)
|
||||
udmAuthGroup.POST("/:neId",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewUDMAuth.Add,
|
||||
)
|
||||
udmAuthGroup.POST("/:neId/:num",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewUDMAuth.Adds,
|
||||
)
|
||||
udmAuthGroup.PUT("/:neId",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewUDMAuth.Edit,
|
||||
)
|
||||
udmAuthGroup.DELETE("/:neId/:imsi",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewUDMAuth.Remove,
|
||||
)
|
||||
udmAuthGroup.DELETE("/:neId/:imsi/:num",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewUDMAuth.Removes,
|
||||
)
|
||||
udmAuthGroup.POST("/export",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_EXPORT)),
|
||||
controller.NewUDMAuth.Export,
|
||||
)
|
||||
udmAuthGroup.POST("/import",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_IMPORT)),
|
||||
controller.NewUDMAuth.Import,
|
||||
)
|
||||
}
|
||||
|
||||
// UDM签约用户信息
|
||||
udmSubGroup := neGroup.Group("/udm/sub")
|
||||
{
|
||||
udmSubGroup.PUT("/resetData/:neId",
|
||||
repeat.RepeatSubmit(5),
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_CLEAN)),
|
||||
controller.NewUDMSub.ResetData,
|
||||
)
|
||||
udmSubGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewUDMSub.List,
|
||||
)
|
||||
udmSubGroup.GET("/:neId/:imsi",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewUDMSub.Info,
|
||||
)
|
||||
udmSubGroup.POST("/:neId",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewUDMSub.Add,
|
||||
)
|
||||
udmSubGroup.POST("/:neId/:num",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_INSERT)),
|
||||
controller.NewUDMSub.Adds,
|
||||
)
|
||||
udmSubGroup.PUT("/:neId",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_UPDATE)),
|
||||
controller.NewUDMSub.Edit,
|
||||
)
|
||||
udmSubGroup.DELETE("/:neId/:imsi",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewUDMSub.Remove,
|
||||
)
|
||||
udmSubGroup.DELETE("/:neId/:imsi/:num",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
controller.NewUDMSub.Removes,
|
||||
)
|
||||
udmSubGroup.POST("/export",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_EXPORT)),
|
||||
controller.NewUDMSub.Export,
|
||||
)
|
||||
udmSubGroup.POST("/import",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_IMPORT)),
|
||||
controller.NewUDMSub.Import,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// InitLoad 初始参数
|
||||
func InitLoad() {
|
||||
// 启动时,清除缓存-网元类型
|
||||
service.NewNeInfoImpl.ClearNeCacheByNeType("*")
|
||||
}
|
||||
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 "nms_nbi/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"
|
||||
|
||||
"nms_nbi/src/framework/datasource"
|
||||
"nms_nbi/src/framework/logger"
|
||||
"nms_nbi/src/framework/utils/crypto"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/utils/repo"
|
||||
"nms_nbi/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 "nms_nbi/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"
|
||||
|
||||
"nms_nbi/src/framework/datasource"
|
||||
"nms_nbi/src/framework/logger"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/utils/repo"
|
||||
"nms_nbi/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
|
||||
}
|
||||
32
src/modules/network_element/repository/ne_info.go
Normal file
32
src/modules/network_element/repository/ne_info.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 网元信息 数据层接口
|
||||
type INeInfo interface {
|
||||
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||
SelectNeInfoByNeTypeAndNeID(neType, neID string) 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
|
||||
}
|
||||
393
src/modules/network_element/repository/ne_info.impl.go
Normal file
393
src/modules/network_element/repository/ne_info.impl.go
Normal file
@@ -0,0 +1,393 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"nms_nbi/src/framework/datasource"
|
||||
"nms_nbi/src/framework/logger"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/utils/repo"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// neListSort 网元列表预设排序
|
||||
var neListSort = []string{
|
||||
"OMC",
|
||||
"MME",
|
||||
"AMF",
|
||||
"AUSF",
|
||||
"UDM",
|
||||
"SMF",
|
||||
"PCF",
|
||||
"UPF",
|
||||
"NRF",
|
||||
"NSSF",
|
||||
"IMS",
|
||||
"N3IWF",
|
||||
"NEF",
|
||||
"LMF",
|
||||
}
|
||||
|
||||
// 实例化数据层 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, host_ids from ne_info`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"ne_type": "NeType",
|
||||
"ne_id": "NeId",
|
||||
"rm_uid": "RmUID",
|
||||
"ne_name": "NeName",
|
||||
"ip": "IP",
|
||||
"port": "Port",
|
||||
"pv_flag": "PvFlag",
|
||||
"province": "Province",
|
||||
"vendor_name": "VendorName",
|
||||
"dn": "Dn",
|
||||
"ne_address": "NeAddress",
|
||||
"status": "Status",
|
||||
"update_time": "UpdateTime",
|
||||
"host_ids": "HostIDs",
|
||||
},
|
||||
}
|
||||
|
||||
// NeInfoImpl 网元信息表 数据层处理
|
||||
type NeInfoImpl struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *NeInfoImpl) convertResultRows(rows []map[string]any) []model.NeInfo {
|
||||
arr := make([]model.NeInfo, 0)
|
||||
for _, row := range rows {
|
||||
item := model.NeInfo{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
|
||||
// 排序
|
||||
sort.Slice(arr, func(i, j int) bool {
|
||||
// 前一个
|
||||
after := arr[i]
|
||||
afterIndex := 0
|
||||
for i, v := range neListSort {
|
||||
if after.NeType == v {
|
||||
afterIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
// 后一个
|
||||
befter := arr[j]
|
||||
befterIndex := 0
|
||||
for i, v := range neListSort {
|
||||
if befter.NeType == v {
|
||||
befterIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
// 升序
|
||||
return afterIndex < befterIndex
|
||||
})
|
||||
|
||||
return arr
|
||||
}
|
||||
|
||||
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||
func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
querySql := r.selectSql + " where ne_type = ? and ne_id = ?"
|
||||
results, err := datasource.RawDB("", querySql, []any{neType, neID})
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
return model.NeInfo{}
|
||||
}
|
||||
// 转换实体
|
||||
rows := r.convertResultRows(results)
|
||||
if len(rows) > 0 {
|
||||
return rows[0]
|
||||
}
|
||||
return model.NeInfo{}
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询
|
||||
func (r *NeInfoImpl) 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["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)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by ne_type asc, ne_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 *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 "nms_nbi/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
|
||||
}
|
||||
319
src/modules/network_element/repository/ne_software.impl.go
Normal file
319
src/modules/network_element/repository/ne_software.impl.go
Normal file
@@ -0,0 +1,319 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"nms_nbi/src/framework/datasource"
|
||||
"nms_nbi/src/framework/logger"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/utils/repo"
|
||||
"nms_nbi/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.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 "nms_nbi/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"
|
||||
|
||||
"nms_nbi/src/framework/datasource"
|
||||
"nms_nbi/src/framework/logger"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/utils/repo"
|
||||
"nms_nbi/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
|
||||
}
|
||||
26
src/modules/network_element/repository/udm_auth.go
Normal file
26
src/modules/network_element/repository/udm_auth.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// UDM鉴权信息 数据层接口
|
||||
type IUDMAuth interface {
|
||||
// ClearAndInsert 清空ne_id后新增实体
|
||||
ClearAndInsert(neID string, authArr []model.UDMAuth) int64
|
||||
|
||||
// SelectPage 根据条件分页查询
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(auth model.UDMAuth) []model.UDMAuth
|
||||
|
||||
// Insert 批量添加
|
||||
Inserts(authUsers []model.UDMAuth) int64
|
||||
|
||||
// Delete 删除实体
|
||||
Delete(neID, imsi string) int64
|
||||
|
||||
// DeletePrefixImsi 删除前缀匹配的实体
|
||||
DeletePrefixImsi(neID, imsi string) int64
|
||||
}
|
||||
191
src/modules/network_element/repository/udm_auth.impl.go
Normal file
191
src/modules/network_element/repository/udm_auth.impl.go
Normal file
@@ -0,0 +1,191 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"nms_nbi/src/framework/datasource"
|
||||
"nms_nbi/src/framework/logger"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/utils/repo"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 UDMAuthImpl 结构体
|
||||
var NewUDMAuthImpl = &UDMAuthImpl{
|
||||
selectSql: `select id, imsi, amf, status, ki, algo_index, opc, ne_id from u_auth_user`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"imsi": "Imsi",
|
||||
"amf": "Amf",
|
||||
"status": "Status",
|
||||
"ki": "Ki",
|
||||
"algo_index": "AlgoIndex",
|
||||
"opc": "Opc",
|
||||
"ne_id": "NeID",
|
||||
},
|
||||
}
|
||||
|
||||
// UDMAuthImpl UDM鉴权信息表 数据层处理
|
||||
type UDMAuthImpl struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *UDMAuthImpl) convertResultRows(rows []map[string]any) []model.UDMAuth {
|
||||
arr := make([]model.UDMAuth, 0)
|
||||
for _, row := range rows {
|
||||
item := model.UDMAuth{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// ClearAndInsert 清空ne_id后新增实体
|
||||
func (r *UDMAuthImpl) ClearAndInsert(neID string, authArr []model.UDMAuth) int64 {
|
||||
// 清空指定ne_id
|
||||
_, err := datasource.ExecDB("", "TRUNCATE TABLE u_auth_user", nil)
|
||||
if err != nil {
|
||||
logger.Errorf("TRUNCATE err => %v", err)
|
||||
}
|
||||
|
||||
return r.Inserts(authArr)
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询
|
||||
func (r *UDMAuthImpl) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["imsi"]; ok && v != "" {
|
||||
conditions = append(conditions, "imsi like concat(concat('%', ?), '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["neId"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.UDMAuth{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from u_auth_user"
|
||||
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)
|
||||
|
||||
// 排序
|
||||
sortSql := ""
|
||||
if v, ok := query["sortField"]; ok && v != "" {
|
||||
if v == "imsi" {
|
||||
sortSql += " order by imsi "
|
||||
}
|
||||
if o, ok := query["sortOrder"]; ok && o != nil && v != "" {
|
||||
if o == "desc" {
|
||||
sortSql += " desc "
|
||||
} else {
|
||||
sortSql += " asc "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + sortSql + pageSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
result["rows"] = r.convertResultRows(results)
|
||||
return result
|
||||
}
|
||||
|
||||
// SelectList 根据实体查询
|
||||
func (r *UDMAuthImpl) SelectList(auth model.UDMAuth) []model.UDMAuth {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if auth.Imsi != "" {
|
||||
conditions = append(conditions, "imsi = ?")
|
||||
params = append(params, auth.Imsi)
|
||||
}
|
||||
if auth.NeID != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, auth.NeID)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by imsi asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// Insert 批量添加
|
||||
func (r *UDMAuthImpl) Inserts(authUsers []model.UDMAuth) int64 {
|
||||
tx := datasource.DefaultDB().CreateInBatches(authUsers, 3000)
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("CreateInBatches err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// Delete 删除实体
|
||||
func (r *UDMAuthImpl) Delete(neID, imsi string) int64 {
|
||||
tx := datasource.DefaultDB().Where("imsi = ? and ne_id = ?", imsi, neID).Delete(&model.UDMAuth{})
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("Delete err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// DeletePrefixImsi 删除前缀匹配的实体
|
||||
func (r *UDMAuthImpl) DeletePrefixImsi(neID, imsi string) int64 {
|
||||
tx := datasource.DefaultDB().Where("imsi like concat(?, '%') and ne_id = ?", imsi, neID).Delete(&model.UDMAuth{})
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("DeletePrefixImsi err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
35
src/modules/network_element/repository/udm_sub.go
Normal file
35
src/modules/network_element/repository/udm_sub.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// UDM签约信息 数据层接口
|
||||
type IUDMSub interface {
|
||||
// ClearAndInsert 清空ne_id后新增实体
|
||||
ClearAndInsert(neID string, subArr []model.UDMSub) int64
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(subUser model.UDMSub) []model.UDMSub
|
||||
|
||||
// Insert 新增实体
|
||||
Insert(subUser model.UDMSub) string
|
||||
|
||||
// Insert 批量添加
|
||||
Inserts(subUser []model.UDMSub) int64
|
||||
|
||||
// Update 修改更新
|
||||
Update(neID string, subUser model.UDMSub) int64
|
||||
|
||||
// Delete 删除实体
|
||||
Delete(neID, imsi string) int64
|
||||
|
||||
// DeletePrefixImsi 删除前缀匹配的实体
|
||||
DeletePrefixImsi(neID, imsi string) int64
|
||||
|
||||
// Delete 删除范围实体
|
||||
Deletes(neID, imsi, num string) int64
|
||||
}
|
||||
312
src/modules/network_element/repository/udm_sub.impl.go
Normal file
312
src/modules/network_element/repository/udm_sub.impl.go
Normal file
@@ -0,0 +1,312 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"nms_nbi/src/framework/datasource"
|
||||
"nms_nbi/src/framework/logger"
|
||||
"nms_nbi/src/framework/utils/parse"
|
||||
"nms_nbi/src/framework/utils/repo"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
// 实例化数据层 UDMSubImpl 结构体
|
||||
var NewUDMSubImpl = &UDMSubImpl{
|
||||
selectSql: `select
|
||||
id, msisdn, imsi, ambr, nssai, rat, arfb, sar, cn, sm_data, smf_sel, eps_dat, ne_id, eps_flag, eps_odb, hplmn_odb, ard, epstpl, context_id, apn_context, static_ip
|
||||
from u_sub_user`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
"id": "ID",
|
||||
"msisdn": "Msisdn",
|
||||
"imsi": "Imsi",
|
||||
"ambr": "Ambr",
|
||||
"nssai": "Nssai",
|
||||
"rat": "Rat",
|
||||
"arfb": "Arfb",
|
||||
"sar": "Sar",
|
||||
"cn": "Cn",
|
||||
"sm_data": "SmData",
|
||||
"smf_sel": "SmfSel",
|
||||
"eps_dat": "EpsDat",
|
||||
"ne_id": "NeID",
|
||||
"eps_flag": "EpsFlag",
|
||||
"eps_odb": "EpsOdb",
|
||||
"hplmn_odb": "HplmnOdb",
|
||||
"ard": "Ard",
|
||||
"epstpl": "Epstpl",
|
||||
"context_id": "ContextId",
|
||||
"apn_context": "ApnContext",
|
||||
"static_ip": "StaticIp",
|
||||
},
|
||||
}
|
||||
|
||||
// UDMSubImpl UDM签约信息表 数据层处理
|
||||
type UDMSubImpl struct {
|
||||
// 查询视图对象SQL
|
||||
selectSql string
|
||||
// 结果字段与实体映射
|
||||
resultMap map[string]string
|
||||
}
|
||||
|
||||
// convertResultRows 将结果记录转实体结果组
|
||||
func (r *UDMSubImpl) convertResultRows(rows []map[string]any) []model.UDMSub {
|
||||
arr := make([]model.UDMSub, 0)
|
||||
for _, row := range rows {
|
||||
item := model.UDMSub{}
|
||||
for key, value := range row {
|
||||
if keyMapper, ok := r.resultMap[key]; ok {
|
||||
repo.SetFieldValue(&item, keyMapper, value)
|
||||
}
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// ClearAndInsert 清空ne_id后新增实体
|
||||
func (r *UDMSubImpl) ClearAndInsert(neID string, subArr []model.UDMSub) int64 {
|
||||
// 清空指定ne_id
|
||||
_, err := datasource.ExecDB("", "TRUNCATE TABLE u_sub_user", nil)
|
||||
if err != nil {
|
||||
logger.Errorf("TRUNCATE err => %v", err)
|
||||
}
|
||||
|
||||
return r.Inserts(subArr)
|
||||
}
|
||||
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
func (r *UDMSubImpl) SelectPage(query map[string]any) map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["msisdn"]; ok && v != "" {
|
||||
conditions = append(conditions, "msisdn like concat(concat('%', ?), '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["imsi"]; ok && v != "" {
|
||||
conditions = append(conditions, "imsi like concat(concat('%', ?), '%')")
|
||||
params = append(params, strings.Trim(v.(string), " "))
|
||||
}
|
||||
if v, ok := query["neId"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"total": 0,
|
||||
"rows": []model.UDMSub{},
|
||||
}
|
||||
|
||||
// 查询数量 长度为0直接返回
|
||||
totalSql := "select count(1) as 'total' from u_sub_user"
|
||||
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)
|
||||
|
||||
// 排序
|
||||
sortSql := ""
|
||||
if v, ok := query["sortField"]; ok && v != "" {
|
||||
if v == "imsi" {
|
||||
sortSql += " order by imsi "
|
||||
}
|
||||
if v == "msisdn" {
|
||||
sortSql += " order by msisdn "
|
||||
}
|
||||
if o, ok := query["sortOrder"]; ok && o != nil && v != "" {
|
||||
if o == "desc" {
|
||||
sortSql += " desc "
|
||||
} else {
|
||||
sortSql += " asc "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + sortSql + 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 *UDMSubImpl) SelectList(subUser model.UDMSub) []model.UDMSub {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if subUser.Imsi != "" {
|
||||
conditions = append(conditions, "imsi = ?")
|
||||
params = append(params, subUser.Imsi)
|
||||
}
|
||||
if subUser.NeID != "" {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, subUser.NeID)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " where " + strings.Join(conditions, " and ")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
querySql := r.selectSql + whereSql + " order by imsi asc "
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
|
||||
// 转换实体
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// Insert 新增实体
|
||||
func (r *UDMSubImpl) Insert(subUser model.UDMSub) string {
|
||||
err := datasource.DefaultDB().Create(&subUser).Error
|
||||
if err != nil {
|
||||
logger.Errorf("Create err => %v", err)
|
||||
}
|
||||
return subUser.ID
|
||||
}
|
||||
|
||||
// Insert 批量添加
|
||||
func (r *UDMSubImpl) Inserts(subUser []model.UDMSub) int64 {
|
||||
tx := datasource.DefaultDB().CreateInBatches(subUser, 2000)
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("CreateInBatches err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// Update 修改更新
|
||||
func (r *UDMSubImpl) Update(neID string, subUser model.UDMSub) int64 {
|
||||
// 查询先
|
||||
var user model.UDMSub
|
||||
err := datasource.DefaultDB().Where("imsi = ? and ne_id = ?", subUser.Imsi, neID).First(&user).Error
|
||||
if err != nil {
|
||||
logger.Errorf("Update First err => %v", err)
|
||||
}
|
||||
|
||||
if user.Msisdn != subUser.Msisdn {
|
||||
user.Msisdn = subUser.Msisdn
|
||||
}
|
||||
if user.Ambr != subUser.Ambr {
|
||||
user.Ambr = subUser.Ambr
|
||||
}
|
||||
if user.Arfb != subUser.Arfb {
|
||||
user.Arfb = subUser.Arfb
|
||||
}
|
||||
if user.Sar != subUser.Sar {
|
||||
user.Sar = subUser.Sar
|
||||
}
|
||||
if user.Rat != subUser.Rat {
|
||||
user.Rat = subUser.Rat
|
||||
}
|
||||
if user.Cn != subUser.Cn {
|
||||
user.Cn = subUser.Cn
|
||||
}
|
||||
if user.SmfSel != subUser.SmfSel {
|
||||
user.SmfSel = subUser.SmfSel
|
||||
}
|
||||
if user.SmData != subUser.SmData {
|
||||
user.SmData = subUser.SmData
|
||||
}
|
||||
if user.EpsDat != subUser.EpsDat {
|
||||
user.EpsDat = subUser.EpsDat
|
||||
}
|
||||
if user.EpsFlag != subUser.EpsFlag {
|
||||
user.EpsFlag = subUser.EpsFlag
|
||||
}
|
||||
if user.EpsDat != subUser.EpsDat {
|
||||
user.EpsOdb = subUser.EpsOdb
|
||||
}
|
||||
if user.HplmnOdb != subUser.HplmnOdb {
|
||||
user.HplmnOdb = subUser.HplmnOdb
|
||||
}
|
||||
if user.Epstpl != subUser.Epstpl {
|
||||
user.Epstpl = subUser.Epstpl
|
||||
}
|
||||
if user.Ard != subUser.Ard {
|
||||
user.Ard = subUser.Ard
|
||||
}
|
||||
if user.ContextId != subUser.ContextId {
|
||||
user.ContextId = subUser.ContextId
|
||||
}
|
||||
if user.ApnContext != subUser.ApnContext {
|
||||
user.ApnContext = subUser.ApnContext
|
||||
}
|
||||
if user.StaticIp != subUser.StaticIp {
|
||||
user.StaticIp = subUser.StaticIp
|
||||
}
|
||||
|
||||
tx := datasource.DefaultDB().Save(user)
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("Update Save err => %v", err)
|
||||
return 0
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// Delete 删除实体
|
||||
func (r *UDMSubImpl) Delete(neID, imsi string) int64 {
|
||||
tx := datasource.DefaultDB().Where("imsi = ? and ne_id = ?", imsi, neID).Delete(&model.UDMSub{})
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("Delete err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// DeletePrefixImsi 删除前缀匹配的实体
|
||||
func (r *UDMSubImpl) DeletePrefixImsi(neID, imsi string) int64 {
|
||||
tx := datasource.DefaultDB().Where("imsi like concat(?, '%') and ne_id = ?", imsi, neID).Delete(&model.UDMSub{})
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("DeletePrefixImsi err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// Delete 删除范围实体
|
||||
func (r *UDMSubImpl) Deletes(neID, imsi, num string) int64 {
|
||||
imsiV, err := strconv.Atoi(imsi)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
numV, err := strconv.Atoi(num)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
tx := datasource.DefaultDB().Where("imsi >= ? and imsi < ? and ne_id = ?", imsiV, imsiV+numV, neID).Delete(&model.UDMSub{})
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("Deletes err => %v", err)
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
80
src/modules/network_element/service/ne_direct_link.go
Normal file
80
src/modules/network_element/service/ne_direct_link.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"nms_nbi/src/framework/logger"
|
||||
"nms_nbi/src/framework/utils/fetch"
|
||||
"nms_nbi/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, 250)
|
||||
if err != nil {
|
||||
logger.Warnf("NeState %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
var resData map[string]any
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Warnf("NeState Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return map[string]any{
|
||||
"neType": neInfo.NeType,
|
||||
"neId": neInfo.NeId,
|
||||
"neName": neInfo.NeName,
|
||||
"neIP": neInfo.IP,
|
||||
"refreshTime": time.Now().UnixMilli(), // 获取时间
|
||||
"version": resData["version"],
|
||||
"capability": resData["capability"],
|
||||
"sn": resData["serialNum"],
|
||||
"expire": resData["expiryDate"],
|
||||
"cpu": resData["cpuUsage"],
|
||||
"mem": resData["memUsage"],
|
||||
"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 "nms_nbi/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"
|
||||
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
"nms_nbi/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 "nms_nbi/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"
|
||||
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
"nms_nbi/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 == ""
|
||||
}
|
||||
42
src/modules/network_element/service/ne_info.go
Normal file
42
src/modules/network_element/service/ne_info.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package service
|
||||
|
||||
import "nms_nbi/src/modules/network_element/model"
|
||||
|
||||
// 网元信息 服务层接口
|
||||
type INeInfo interface {
|
||||
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||
SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo
|
||||
|
||||
// RefreshByNeTypeAndNeID 通过ne_type和ne_id刷新redis中的缓存
|
||||
RefreshByNeTypeAndNeID(neType, neID string) model.NeInfo
|
||||
|
||||
// ClearNeCacheByNeType 清除网元类型缓存
|
||||
ClearNeCacheByNeType(neType string) bool
|
||||
|
||||
// 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
|
||||
}
|
||||
261
src/modules/network_element/service/ne_info.impl.go
Normal file
261
src/modules/network_element/service/ne_info.impl.go
Normal file
@@ -0,0 +1,261 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"nms_nbi/src/framework/constants/cachekey"
|
||||
"nms_nbi/src/framework/redis"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
"nms_nbi/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)
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
err := json.Unmarshal([]byte(jsonStr), &neInfo)
|
||||
if err != nil {
|
||||
neInfo = model.NeInfo{}
|
||||
}
|
||||
} else {
|
||||
neInfo = r.neInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
|
||||
if neInfo.NeId == neID {
|
||||
redis.Del("", key)
|
||||
values, _ := json.Marshal(neInfo)
|
||||
redis.Set("", key, string(values))
|
||||
}
|
||||
}
|
||||
return neInfo
|
||||
}
|
||||
|
||||
// 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)
|
||||
redis.Del("", key)
|
||||
neInfo = r.neInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
|
||||
if neInfo.NeId == neID {
|
||||
values, _ := json.Marshal(neInfo)
|
||||
redis.Set("", key, string(values))
|
||||
}
|
||||
return neInfo
|
||||
}
|
||||
|
||||
// ClearNeCacheByNeType 清除网元类型缓存
|
||||
func (r *NeInfoImpl) ClearNeCacheByNeType(neType string) bool {
|
||||
key := fmt.Sprintf("%s*", cachekey.NE_KEY)
|
||||
if neType != "*" {
|
||||
key = fmt.Sprintf("%s%s*", cachekey.NE_KEY, neType)
|
||||
}
|
||||
keys, err := redis.GetKeys("", key)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
delOk, _ := redis.DelKeys("", keys)
|
||||
return delOk
|
||||
}
|
||||
|
||||
// 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 {
|
||||
neList := &list
|
||||
for i := range *neList {
|
||||
v := (*neList)[i]
|
||||
result, err := NeState(v)
|
||||
if err != nil {
|
||||
(*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 == ""
|
||||
}
|
||||
30
src/modules/network_element/service/ne_software.go
Normal file
30
src/modules/network_element/service/ne_software.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package service
|
||||
|
||||
import "nms_nbi/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)
|
||||
|
||||
// CheckUniqueTypeAndFileNameAndVersion 校验网元类型和文件名版本是否唯一
|
||||
CheckUniqueTypeAndFileNameAndVersion(neType, fileName, version, id string) bool
|
||||
|
||||
// Install 安装软件包
|
||||
Install(neSoftware model.NeSoftware) (string, error)
|
||||
}
|
||||
85
src/modules/network_element/service/ne_software.impl.go
Normal file
85
src/modules/network_element/service/ne_software.impl.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
"nms_nbi/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")
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
27
src/modules/network_element/service/ne_version.go
Normal file
27
src/modules/network_element/service/ne_version.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package service
|
||||
|
||||
import "nms_nbi/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)
|
||||
|
||||
// CheckUniqueTypeAndID 校验网元类型和网元ID是否唯一
|
||||
CheckUniqueTypeAndID(neType, neId, id string) bool
|
||||
}
|
||||
79
src/modules/network_element/service/ne_version.impl.go
Normal file
79
src/modules/network_element/service/ne_version.impl.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
"nms_nbi/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{}
|
||||
}
|
||||
neHosts := r.neVersionRepository.SelectByIds([]string{id})
|
||||
if len(neHosts) > 0 {
|
||||
return neHosts[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")
|
||||
}
|
||||
|
||||
// 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 == ""
|
||||
}
|
||||
37
src/modules/network_element/service/udm_auth.go
Normal file
37
src/modules/network_element/service/udm_auth.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package service
|
||||
|
||||
import "nms_nbi/src/modules/network_element/model"
|
||||
|
||||
// UDM鉴权信息 服务层接口
|
||||
type IUDMAuth interface {
|
||||
// Save UDM鉴权用户-获取redis全部保存数据库
|
||||
Save(neID string) int64
|
||||
|
||||
// Page UDM鉴权用户-分页查询数据库
|
||||
Page(query map[string]any) map[string]any
|
||||
|
||||
// List UDM鉴权用户-查询数据库
|
||||
List(authUser model.UDMAuth) []model.UDMAuth
|
||||
|
||||
// Insert UDM鉴权用户-新增单个
|
||||
// imsi长度15,ki长度32,opc长度0或者32
|
||||
Insert(neID string, authUser model.UDMAuth) int64
|
||||
|
||||
// Insert UDM鉴权用户-批量添加
|
||||
Inserts(neID string, authUser model.UDMAuth, num string) int64
|
||||
|
||||
// InsertCSV UDM鉴权用户-批量添加
|
||||
InsertCSV(neID string, data []map[string]string) int64
|
||||
|
||||
// InsertTxt UDM鉴权用户-批量添加
|
||||
InsertTxt(neID string, data [][]string) int64
|
||||
|
||||
// Insert UDM鉴权用户-修改更新
|
||||
Update(neID string, authUser model.UDMAuth) int64
|
||||
|
||||
// Insert UDM鉴权用户-删除单个
|
||||
Delete(neID, imsi string) int64
|
||||
|
||||
// Insert UDM鉴权用户-删除范围
|
||||
Deletes(neID, imsi, num string) int64
|
||||
}
|
||||
179
src/modules/network_element/service/udm_auth.impl.go
Normal file
179
src/modules/network_element/service/udm_auth.impl.go
Normal file
@@ -0,0 +1,179 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"nms_nbi/src/framework/redis"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
"nms_nbi/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 UDMAuthImpl 结构体
|
||||
var NewUDMAuthImpl = &UDMAuthImpl{
|
||||
udmAuthRepository: repository.NewUDMAuthImpl,
|
||||
}
|
||||
|
||||
// UDM鉴权信息 服务层处理
|
||||
type UDMAuthImpl struct {
|
||||
// UDM鉴权信息数据信息
|
||||
udmAuthRepository repository.IUDMAuth
|
||||
}
|
||||
|
||||
// authDataByRedis UDM鉴权用户
|
||||
func (r *UDMAuthImpl) authDataByRedis(imsi, neID string) []model.UDMAuth {
|
||||
arr := []model.UDMAuth{}
|
||||
key := fmt.Sprintf("ausf:%s", imsi)
|
||||
ausfArr, err := redis.GetKeys("udmuser", key)
|
||||
if err != nil {
|
||||
return arr
|
||||
}
|
||||
for _, key := range ausfArr {
|
||||
m, err := redis.GetHash("udmuser", key)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// 跳过-号数据
|
||||
imsi := key[5:]
|
||||
if strings.Contains(imsi, "-") {
|
||||
continue
|
||||
}
|
||||
|
||||
status := "1" // 默认给1
|
||||
|
||||
amf := ""
|
||||
if v, ok := m["amf"]; ok {
|
||||
amf = strings.Replace(v, "\r\n", "", 1)
|
||||
}
|
||||
a := model.UDMAuth{
|
||||
Imsi: imsi,
|
||||
Amf: amf,
|
||||
Status: status,
|
||||
Ki: m["ki"],
|
||||
AlgoIndex: m["algo"],
|
||||
Opc: m["opc"],
|
||||
NeID: neID,
|
||||
}
|
||||
arr = append(arr, a)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// Save UDM鉴权用户-获取redis全部保存数据库
|
||||
func (r *UDMAuthImpl) Save(neID string) int64 {
|
||||
authArr := r.authDataByRedis("*", neID)
|
||||
// 数据清空后添加
|
||||
go r.udmAuthRepository.ClearAndInsert(neID, authArr)
|
||||
return int64(len(authArr))
|
||||
}
|
||||
|
||||
// Page UDM鉴权用户-分页查询数据库
|
||||
func (r *UDMAuthImpl) Page(query map[string]any) map[string]any {
|
||||
return r.udmAuthRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// List UDM鉴权用户-查询数据库
|
||||
func (r *UDMAuthImpl) List(authUser model.UDMAuth) []model.UDMAuth {
|
||||
return r.udmAuthRepository.SelectList(authUser)
|
||||
}
|
||||
|
||||
// Insert UDM鉴权用户-新增单个
|
||||
// imsi长度15,ki长度32,opc长度0或者32
|
||||
func (r *UDMAuthImpl) Insert(neID string, authUser model.UDMAuth) int64 {
|
||||
authArr := r.authDataByRedis(authUser.Imsi, neID)
|
||||
if len(authArr) > 0 {
|
||||
r.udmAuthRepository.Delete(neID, authUser.Imsi)
|
||||
r.udmAuthRepository.Inserts(authArr)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Insert UDM鉴权用户-批量添加
|
||||
func (r *UDMAuthImpl) Inserts(neID string, authUser model.UDMAuth, num string) int64 {
|
||||
startIMSI := authUser.Imsi
|
||||
startIMSI = startIMSI[:len(startIMSI)-len(num)] + "*"
|
||||
// keys udm-sd:4600001000004*
|
||||
authArr := r.authDataByRedis(startIMSI, neID)
|
||||
if len(authArr) > 0 {
|
||||
for _, v := range authArr {
|
||||
r.udmAuthRepository.Delete(neID, v.Imsi)
|
||||
}
|
||||
return r.udmAuthRepository.Inserts(authArr)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// InsertCSV UDM鉴权用户-批量添加
|
||||
func (r *UDMAuthImpl) InsertCSV(neID string, data []map[string]string) int64 {
|
||||
prefixes := make(map[string]struct{})
|
||||
for _, v := range data {
|
||||
imsi := v["imsi"]
|
||||
if len(imsi) < 5 {
|
||||
continue
|
||||
}
|
||||
prefix := imsi[:len(imsi)-4]
|
||||
prefixes[prefix] = struct{}{}
|
||||
}
|
||||
// 分组插入
|
||||
var num int64 = 0
|
||||
for prefix := range prefixes {
|
||||
r.udmAuthRepository.DeletePrefixImsi(neID, prefix)
|
||||
subArr := r.authDataByRedis(prefix+"*", neID)
|
||||
if len(subArr) > 0 {
|
||||
num += r.udmAuthRepository.Inserts(subArr)
|
||||
}
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
// InsertTxt UDM鉴权用户-批量添加
|
||||
func (r *UDMAuthImpl) InsertTxt(neID string, data [][]string) int64 {
|
||||
prefixes := make(map[string]struct{})
|
||||
for _, v := range data {
|
||||
imsi := v[0]
|
||||
if len(imsi) < 5 {
|
||||
continue
|
||||
}
|
||||
prefix := imsi[:len(imsi)-4]
|
||||
prefixes[prefix] = struct{}{}
|
||||
}
|
||||
// 分组插入
|
||||
var num int64 = 0
|
||||
for prefix := range prefixes {
|
||||
r.udmAuthRepository.DeletePrefixImsi(neID, prefix)
|
||||
subArr := r.authDataByRedis(prefix+"*", neID)
|
||||
if len(subArr) > 0 {
|
||||
num += r.udmAuthRepository.Inserts(subArr)
|
||||
}
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
// Insert UDM鉴权用户-修改更新
|
||||
func (r *UDMAuthImpl) Update(neID string, authUser model.UDMAuth) int64 {
|
||||
authArr := r.authDataByRedis(authUser.Imsi, neID)
|
||||
if len(authArr) > 0 {
|
||||
r.udmAuthRepository.Delete(neID, authUser.Imsi)
|
||||
return r.udmAuthRepository.Inserts(authArr)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Insert UDM鉴权用户-删除单个
|
||||
func (r *UDMAuthImpl) Delete(neID, imsi string) int64 {
|
||||
return r.udmAuthRepository.Delete(neID, imsi)
|
||||
}
|
||||
|
||||
// Insert UDM鉴权用户-删除范围
|
||||
func (r *UDMAuthImpl) Deletes(neID, imsi, num string) int64 {
|
||||
prefix := imsi[:len(imsi)-len(num)-1]
|
||||
// 直接删除前缀的记录
|
||||
r.udmAuthRepository.DeletePrefixImsi(neID, prefix)
|
||||
// keys ausf:4600001000004*
|
||||
authArr := r.authDataByRedis(prefix+"*", neID)
|
||||
if len(authArr) > 0 {
|
||||
return r.udmAuthRepository.Inserts(authArr)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
37
src/modules/network_element/service/udm_sub.go
Normal file
37
src/modules/network_element/service/udm_sub.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package service
|
||||
|
||||
import "nms_nbi/src/modules/network_element/model"
|
||||
|
||||
// UDM签约用户信息 服务层接口
|
||||
type IUDMSub interface {
|
||||
// Save UDM签约用户-获取redis全部保存数据库
|
||||
Save(neID string) int64
|
||||
|
||||
// Page UDM签约用户-分页查询数据库
|
||||
Page(query map[string]any) map[string]any
|
||||
|
||||
// List UDM签约用户-查询数据库
|
||||
List(subUser model.UDMSub) []model.UDMSub
|
||||
|
||||
// Insert UDM签约用户-新增单个
|
||||
// imsi长度15,ki长度32,opc长度0或者32
|
||||
Insert(neID string, subUser model.UDMSub) int64
|
||||
|
||||
// Insert UDM签约用户-批量添加
|
||||
Inserts(neID string, subUser model.UDMSub, num string) int64
|
||||
|
||||
// InsertCSV UDM签约用户-批量添加
|
||||
InsertCSV(neID string, data []map[string]string) int64
|
||||
|
||||
// InsertTxt UDM签约用户-批量添加
|
||||
InsertTxt(neID string, data [][]string) int64
|
||||
|
||||
// Insert UDM签约用户-修改更新
|
||||
Update(neID string, subUser model.UDMSub) int64
|
||||
|
||||
// Insert UDM签约用户-删除单个
|
||||
Delete(neID, imsi string) int64
|
||||
|
||||
// Insert UDM签约用户-删除范围
|
||||
Deletes(neID, imsi, num string) int64
|
||||
}
|
||||
195
src/modules/network_element/service/udm_sub.impl.go
Normal file
195
src/modules/network_element/service/udm_sub.impl.go
Normal file
@@ -0,0 +1,195 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"nms_nbi/src/framework/redis"
|
||||
"nms_nbi/src/modules/network_element/model"
|
||||
"nms_nbi/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// 实例化服务层 UDMSubImpl 结构体
|
||||
var NewUDMSubImpl = &UDMSubImpl{
|
||||
udmSubRepository: repository.NewUDMSubImpl,
|
||||
}
|
||||
|
||||
// UDM签约信息 服务层处理
|
||||
type UDMSubImpl struct {
|
||||
// UDM签约信息数据信息
|
||||
udmSubRepository repository.IUDMSub
|
||||
}
|
||||
|
||||
// subDataByRedis UDM签约用户
|
||||
func (r *UDMSubImpl) subDataByRedis(imsi, neID string) []model.UDMSub {
|
||||
arr := []model.UDMSub{}
|
||||
key := fmt.Sprintf("udm-sd:%s", imsi)
|
||||
udmsdArr, err := redis.GetKeys("udmuser", key)
|
||||
if err != nil {
|
||||
return arr
|
||||
}
|
||||
for _, key := range udmsdArr {
|
||||
m, err := redis.GetHash("udmuser", key)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
a := model.UDMSub{
|
||||
Imsi: key[7:],
|
||||
Msisdn: m["gpsi"], // 46003550072 strings.TrimPrefix(m["gpsi"], "86"),
|
||||
SmfSel: m["smf-sel"],
|
||||
SmData: m["sm-dat"], // 1-000001&cmnet&ims&3gnet
|
||||
NeID: neID,
|
||||
}
|
||||
|
||||
// def_ambr,def_nssai,0,def_arfb,def_sar,3,1,12000,1,1000,0,1,-
|
||||
if v, ok := m["am-dat"]; ok {
|
||||
arr := strings.Split(v, ",")
|
||||
a.Ambr = arr[0]
|
||||
a.Nssai = arr[1]
|
||||
a.Rat = arr[2]
|
||||
a.Arfb = arr[3]
|
||||
a.Sar = arr[4]
|
||||
a.Cn = arr[5]
|
||||
}
|
||||
// 1,64,24,65,def_eps,1,2,010200000000,-
|
||||
if v, ok := m["eps-dat"]; ok {
|
||||
arr := strings.Split(v, ",")
|
||||
// 跳过非常规数据
|
||||
if len(arr) > 9 {
|
||||
continue
|
||||
}
|
||||
a.EpsDat = v
|
||||
a.EpsFlag = arr[0]
|
||||
a.EpsOdb = arr[1]
|
||||
a.HplmnOdb = arr[2]
|
||||
a.Ard = arr[3]
|
||||
a.Epstpl = arr[4]
|
||||
a.ContextId = arr[5]
|
||||
a.ApnContext = arr[7]
|
||||
// [6] 是不要的,导入和导出不用
|
||||
a.StaticIp = arr[8]
|
||||
}
|
||||
|
||||
arr = append(arr, a)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// Save UDM签约用户-获取redis全部保存数据库
|
||||
func (r *UDMSubImpl) Save(neID string) int64 {
|
||||
subArr := r.subDataByRedis("*", neID)
|
||||
// 数据清空后添加
|
||||
go r.udmSubRepository.ClearAndInsert(neID, subArr)
|
||||
return int64(len(subArr))
|
||||
}
|
||||
|
||||
// Page UDM签约用户-分页查询数据库
|
||||
func (r *UDMSubImpl) Page(query map[string]any) map[string]any {
|
||||
return r.udmSubRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// List UDM签约用户-查询数据库
|
||||
func (r *UDMSubImpl) List(subUser model.UDMSub) []model.UDMSub {
|
||||
return r.udmSubRepository.SelectList(subUser)
|
||||
}
|
||||
|
||||
// Insert UDM签约用户-新增单个
|
||||
// imsi长度15,ki长度32,opc长度0或者32
|
||||
func (r *UDMSubImpl) Insert(neID string, subUser model.UDMSub) int64 {
|
||||
authArr := r.subDataByRedis(subUser.Imsi, neID)
|
||||
if len(authArr) > 0 {
|
||||
r.udmSubRepository.Delete(neID, subUser.Imsi)
|
||||
r.udmSubRepository.Inserts(authArr)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Insert UDM签约用户-批量添加
|
||||
func (r *UDMSubImpl) Inserts(neID string, subUser model.UDMSub, num string) int64 {
|
||||
startIMSI := subUser.Imsi
|
||||
startIMSI = startIMSI[:len(startIMSI)-len(num)] + "*"
|
||||
// keys udm-sd:4600001000004*
|
||||
subArr := r.subDataByRedis(startIMSI, neID)
|
||||
if len(subArr) > 0 {
|
||||
for _, v := range subArr {
|
||||
r.udmSubRepository.Delete(neID, v.Imsi)
|
||||
}
|
||||
return r.udmSubRepository.Inserts(subArr)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// InsertCSV UDM签约用户-批量添加
|
||||
func (r *UDMSubImpl) InsertCSV(neID string, data []map[string]string) int64 {
|
||||
prefixes := make(map[string]struct{})
|
||||
for _, v := range data {
|
||||
imsi := v["imsi"]
|
||||
if len(imsi) < 5 {
|
||||
continue
|
||||
}
|
||||
prefix := imsi[:len(imsi)-4]
|
||||
prefixes[prefix] = struct{}{}
|
||||
}
|
||||
// 分组插入
|
||||
var num int64 = 0
|
||||
for prefix := range prefixes {
|
||||
r.udmSubRepository.DeletePrefixImsi(neID, prefix)
|
||||
subArr := r.subDataByRedis(prefix+"*", neID)
|
||||
if len(subArr) > 0 {
|
||||
num += r.udmSubRepository.Inserts(subArr)
|
||||
}
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
// InsertTxt UDM签约用户-批量添加
|
||||
func (r *UDMSubImpl) InsertTxt(neID string, data [][]string) int64 {
|
||||
prefixes := make(map[string]struct{})
|
||||
for _, v := range data {
|
||||
imsi := v[0]
|
||||
if len(imsi) < 5 {
|
||||
continue
|
||||
}
|
||||
prefix := imsi[:len(imsi)-4]
|
||||
prefixes[prefix] = struct{}{}
|
||||
}
|
||||
// 分组插入
|
||||
var num int64 = 0
|
||||
for prefix := range prefixes {
|
||||
r.udmSubRepository.DeletePrefixImsi(neID, prefix)
|
||||
subArr := r.subDataByRedis(prefix+"*", neID)
|
||||
if len(subArr) > 0 {
|
||||
num += r.udmSubRepository.Inserts(subArr)
|
||||
}
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
// Insert UDM签约用户-修改更新
|
||||
func (r *UDMSubImpl) Update(neID string, subUser model.UDMSub) int64 {
|
||||
authArr := r.subDataByRedis(subUser.Imsi, neID)
|
||||
if len(authArr) > 0 {
|
||||
r.udmSubRepository.Delete(neID, subUser.Imsi)
|
||||
return r.udmSubRepository.Inserts(authArr)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Insert UDM签约用户-删除单个
|
||||
func (r *UDMSubImpl) Delete(neID, imsi string) int64 {
|
||||
return r.udmSubRepository.Delete(neID, imsi)
|
||||
}
|
||||
|
||||
// Insert UDM签约用户-删除范围
|
||||
func (r *UDMSubImpl) Deletes(neID, imsi, num string) int64 {
|
||||
prefix := imsi[:len(imsi)-len(num)-1]
|
||||
// 直接删除前缀的记录
|
||||
r.udmSubRepository.DeletePrefixImsi(neID, prefix)
|
||||
// keys udm-sd:4600001000004*
|
||||
authArr := r.subDataByRedis(prefix+"*", neID)
|
||||
if len(authArr) > 0 {
|
||||
return r.udmSubRepository.Inserts(authArr)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user