1
0

marge: 合并代码

This commit is contained in:
TsMask
2023-11-28 10:22:37 +08:00
parent 5050f4f113
commit 3df3b5b5f7
18 changed files with 234 additions and 46 deletions

View File

@@ -0,0 +1,68 @@
package controller
import (
"fmt"
"path/filepath"
"strings"
"ems.agt/src/framework/config"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/utils/ssh"
"ems.agt/src/framework/vo/result"
neService "ems.agt/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 NeActionController 结构体
var NewNeAction = &NeActionController{
neInfoService: neService.NewNeInfoImpl,
}
// 网元处理请求
//
// PATH /
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 := 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)))
}

View File

@@ -35,7 +35,7 @@ func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(neType, neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
c.JSON(200, result.OkData(neInfo))

View File

@@ -76,7 +76,7 @@ func (s *UDMAuthController) Info(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -134,7 +134,7 @@ func (s *UDMAuthController) Add(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -177,7 +177,7 @@ func (s *UDMAuthController) Adds(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -219,7 +219,7 @@ func (s *UDMAuthController) Edit(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -268,7 +268,7 @@ func (s *UDMAuthController) Remove(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -305,7 +305,7 @@ func (s *UDMAuthController) Removes(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -414,7 +414,7 @@ func (s *UDMAuthController) Import(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}

View File

@@ -77,7 +77,7 @@ func (s *UDMSubController) Info(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -158,7 +158,7 @@ func (s *UDMSubController) Add(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -206,7 +206,7 @@ func (s *UDMSubController) Adds(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -253,7 +253,7 @@ func (s *UDMSubController) Edit(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -344,7 +344,7 @@ func (s *UDMSubController) Remove(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -381,7 +381,7 @@ func (s *UDMSubController) Removes(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -492,7 +492,7 @@ func (s *UDMSubController) Import(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}

View File

@@ -22,6 +22,17 @@ func Setup(router *gin.Engine) {
)
}
// 网元处理
neActionGroup := neGroup.Group("/action")
{
// 发送文件到网元服务器
neActionGroup.POST("/pushFile",
middleware.PreAuthorize(nil),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neAction", collectlogs.BUSINESS_TYPE_IMPORT)),
controller.NewNeAction.PushFile,
)
}
// UDM鉴权用户信息
udmAuthGroup := neGroup.Group("/udm/auth")
{

View File

@@ -23,7 +23,8 @@ type UDMAuthImpl struct {
// authDataByRedis UDM鉴权用户
func (r *UDMAuthImpl) authDataByRedis(imsi, neID string) []model.UDMAuth {
arr := []model.UDMAuth{}
ausfArr, err := redis.GetKeys("udmuser", fmt.Sprintf("ausf:%s", imsi))
key := fmt.Sprintf("ausf:%s", imsi)
ausfArr, err := redis.GetKeys("udmuser", key)
if err != nil {
return arr
}
@@ -39,10 +40,8 @@ func (r *UDMAuthImpl) authDataByRedis(imsi, neID string) []model.UDMAuth {
continue
}
status := "0"
if _, ok := m["auth_success"]; ok {
status = "1"
}
status := "1" // 默认给1
amf := ""
if v, ok := m["amf"]; ok {
amf = strings.Replace(v, "\r\n", "", 1)
@@ -166,11 +165,12 @@ func (r *UDMAuthImpl) Delete(neID, imsi string) int64 {
// Insert UDM鉴权用户-删除范围
func (r *UDMAuthImpl) Deletes(neID, imsi, num string) int64 {
prefix := imsi[:len(imsi)-len(num)]
// keys udm-sd:4600001000004*
prefix := imsi[:len(imsi)-len(num)-1]
// 直接删除前缀的记录
r.udmAuthRepository.DeletePrefixImsi(neID, prefix)
// keys ausf:4600001000004*
authArr := r.authDataByRedis(prefix+"*", neID)
if len(authArr) > 0 {
r.udmAuthRepository.DeletePrefixImsi(neID, prefix)
return r.udmAuthRepository.Inserts(authArr)
}
return 0

View File

@@ -23,7 +23,8 @@ type UDMSubImpl struct {
// subDataByRedis UDM签约用户
func (r *UDMSubImpl) subDataByRedis(imsi, neID string) []model.UDMSub {
arr := []model.UDMSub{}
udmsdArr, err := redis.GetKeys("udmuser", fmt.Sprintf("udm-sd:%s", imsi))
key := fmt.Sprintf("udm-sd:%s", imsi)
udmsdArr, err := redis.GetKeys("udmuser", key)
if err != nil {
return arr
}
@@ -180,11 +181,12 @@ func (r *UDMSubImpl) Delete(neID, imsi string) int64 {
// Insert UDM签约用户-删除范围
func (r *UDMSubImpl) Deletes(neID, imsi, num string) int64 {
prefix := imsi[:len(imsi)-len(num)]
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 {
r.udmSubRepository.DeletePrefixImsi(neID, prefix)
return r.udmSubRepository.Inserts(authArr)
}
return 0