feat: ne模块名称变更
This commit is contained in:
177
src/modules/network_element/service/udm_auth.impl.go
Normal file
177
src/modules/network_element/service/udm_auth.impl.go
Normal file
@@ -0,0 +1,177 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/redis"
|
||||
"ems.agt/src/modules/network_element/model"
|
||||
"ems.agt/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{}
|
||||
ausfArr, err := redis.GetKeys("udmuser", fmt.Sprintf("ausf:%s", imsi))
|
||||
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 := "0"
|
||||
if _, ok := m["auth_success"]; ok {
|
||||
status = "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 {
|
||||
var num int64 = 0
|
||||
authArr := r.authDataByRedis("*", neID)
|
||||
// 有数据才清空
|
||||
if len(authArr) == 0 {
|
||||
return num
|
||||
}
|
||||
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"]
|
||||
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]
|
||||
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)]
|
||||
// keys udm-sd:4600001000004*
|
||||
authArr := r.authDataByRedis(prefix+"*", neID)
|
||||
if len(authArr) > 0 {
|
||||
r.udmAuthRepository.DeletePrefixImsi(neID, prefix)
|
||||
return r.udmAuthRepository.Inserts(authArr)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user