feat: support rest data return channel result

This commit is contained in:
zhangsz
2025-04-10 15:46:09 +08:00
parent a1eaaaebd7
commit a00a7da016
7 changed files with 88 additions and 74 deletions

View File

@@ -5,20 +5,20 @@ import (
"strconv"
"strings"
"be.ems/src/framework/redis"
neService "be.ems/src/modules/network_element/service"
"be.ems/features/ue/model"
"be.ems/features/ue/repository"
"be.ems/src/framework/redis"
neService "be.ems/src/modules/network_element/service"
)
// 实例化服务层 IMSUserService 结构体
var NewIMSUserService = &IMSUserService{
imsUserRepository: repository.NewIMSUserRepository,
imsUserRepository: repository.NewIMSUserRepository,
}
// VoLTE用户信息 服务层处理
type IMSUserService struct {
imsUserRepository *repository.IMSUserRepository // VoLTE用户信息数据信息
imsUserRepository *repository.IMSUserRepository // VoLTE用户信息数据信息
}
// dataByRedis UDM签约用户 db:0 中 volte:*
@@ -50,12 +50,12 @@ func (r *IMSUserService) dataByRedis(imsi, neId string) []model.IMSUser {
for k, m := range mkv {
var imsi, msisdn string
KeyParts := strings.Split(k, ":")
switch len(KeyParts) {
switch len(KeyParts) {
case 0, 1:
// 处理单个部分的情况
continue
case 2:
// 处理两个部分的情况
// 处理两个部分的情况
imsi = KeyParts[1]
msisdn = "-"
case 3:
@@ -71,14 +71,14 @@ func (r *IMSUserService) dataByRedis(imsi, neId string) []model.IMSUser {
var vni string = "-"
impiParts := strings.Split(m["impi"], "@")
if len(impiParts) > 1 {
vni = impiParts[1] // 输出: ims.mnc001.mcc110.3gppnetwork.org
}
vni = impiParts[1] // 输出: ims.mnc001.mcc110.3gppnetwork.org
}
a := model.IMSUser{
NeId: neId,
IMSI: imsi, // volte:360000100000130:8612300000130
MSISDN: msisdn, // 8612300000130
VoLTE: m["tag"], // volte = tag
VNI: vni, // ims.mnc001.mcc110.3gppnetwork.org
IMSI: imsi, // volte:360000100000130:8612300000130
MSISDN: msisdn, // 8612300000130
VoLTE: m["tag"], // volte = tag
VNI: vni, // ims.mnc001.mcc110.3gppnetwork.org
}
arr = append(arr, a)
}
@@ -209,3 +209,14 @@ func (r *IMSUserService) ParseCommandParams(item model.IMSUser) string {
return strings.Join(conditions, ",")
}
// ResetDataWithResult 重置鉴权用户数据清空数据库重新同步Redis数据
// 通过 channel 返回 ClearAndInsert 的执行结果
func (r *IMSUserService) ResetDataWithResult(neId string) chan int64 {
arr := r.dataByRedis("*", neId)
resultCh := make(chan int64, 1)
go func() {
resultCh <- r.imsUserRepository.ClearAndInsert(neId, arr)
}()
return resultCh
}

View File

@@ -5,20 +5,20 @@ import (
"strconv"
"strings"
"be.ems/src/framework/redis"
neService "be.ems/src/modules/network_element/service"
"be.ems/features/ue/model"
"be.ems/features/ue/repository"
"be.ems/src/framework/redis"
neService "be.ems/src/modules/network_element/service"
)
// 实例化服务层 VoIPAuthService 结构体
var NewVoIPAuthService = &VoIPAuthService{
voipAuthRepository: repository.NewVoIPAuthRepository,
voipAuthRepository: repository.NewVoIPAuthRepository,
}
// VoLTE用户信息 服务层处理
type VoIPAuthService struct {
voipAuthRepository *repository.VoIPAuthRepository // VoLTE用户信息数据信息
voipAuthRepository *repository.VoIPAuthRepository // VoLTE用户信息数据信息
}
// dataByRedis UDM签约用户 db:0 中 volte:*
@@ -51,13 +51,13 @@ func (r *VoIPAuthService) dataByRedis(userName, neId string) []model.VoIPAuth {
var userName string
KeyParts := strings.Split(k, ":")
if len(KeyParts) > 1 {
userName = KeyParts[1]
}
userName = KeyParts[1]
}
a := model.VoIPAuth{
NeId: neId,
UserName: userName, // userName
Password: m["password"], //
NeId: neId,
UserName: userName, // userName
Password: m["password"], //
}
arr = append(arr, a)
}
@@ -168,3 +168,14 @@ func (r *VoIPAuthService) ParseCommandParams(item model.VoIPAuth) string {
return strings.Join(conditions, ",")
}
// ResetDataWithResult 重置鉴权用户数据清空数据库重新同步Redis数据
// 通过 channel 返回 ClearAndInsert 的执行结果
func (r *VoIPAuthService) ResetDataWithResult(neId string) chan int64 {
arr := r.dataByRedis("*", neId)
resultCh := make(chan int64, 1)
go func() {
resultCh <- r.voipAuthRepository.ClearAndInsert(neId, arr)
}()
return resultCh
}