fix: reload after batch add or del

This commit is contained in:
zhangsz
2025-04-15 19:59:23 +08:00
parent e1edf203c9
commit 82562de598
5 changed files with 31 additions and 18 deletions

View File

@@ -146,6 +146,9 @@ func (s *IMSUserController) Add(c *gin.Context) {
// 命令ok时
if strings.Contains(data, "ok") {
body.NeId = neId
if body.Tag == model.TAG_VoIP {
body.IMSI = body.MSISDN
}
s.imsUserService.Insert(neId, body)
}
c.JSON(200, result.OkData(data))
@@ -194,7 +197,11 @@ func (s *IMSUserController) Adds(c *gin.Context) {
}
// 命令ok时
if strings.Contains(data, "ok") {
s.imsUserService.LoadData(neId, body.IMSI, num)
if body.Tag == model.TAG_VoIP {
s.imsUserService.LoadData(neId, body.MSISDN, num)
} else {
s.imsUserService.LoadData(neId, body.IMSI, num)
}
}
c.JSON(200, result.OkData(data))
}

View File

@@ -182,8 +182,7 @@ func (s *VoIPAuthController) Adds(c *gin.Context) {
defer telnetClient.Close()
// 发送MML
cmd := fmt.Sprintf("baa voip:start_username=%s,password=%s,sub_num=%s,",
body.UserName, body.Password, num)
cmd := fmt.Sprintf("baa voip:start_username=%s,sub_num=%s,", body.UserName, num)
cmd += s.voipAuthService.ParseCommandParams(body)
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {

View File

@@ -42,10 +42,10 @@ type Repository struct {
}
// convertResultRows 将结果记录转实体结果组
func (r *Repository) convertResultRows(rows []map[string]any) []VoLTEUser {
arr := make([]VoLTEUser, 0)
func (r *Repository) convertResultRows(rows []map[string]any) []IMSUser {
arr := make([]IMSUser, 0)
for _, row := range rows {
item := VoLTEUser{}
item := IMSUser{}
for key, value := range row {
if keyMapper, ok := r.resultMap[key]; ok {
repo.SetFieldValue(&item, keyMapper, value)
@@ -57,7 +57,7 @@ func (r *Repository) convertResultRows(rows []map[string]any) []VoLTEUser {
}
// ClearAndInsert 清空ne_id后新增实体
func (r *Repository) ClearAndInsert(neId string, u []VoLTEUser) int64 {
func (r *Repository) ClearAndInsert(neId string, u []IMSUser) int64 {
// 不指定neID时用 TRUNCATE 清空表快
// _, err := datasource.ExecDB("", "TRUNCATE TABLE u_ims_user", nil)
_, err := datasource.ExecDB("", "DELETE FROM u_ims_user WHERE ne_id = ?", []any{neId})
@@ -128,7 +128,7 @@ func (r *Repository) SelectPage(query map[string]any) map[string]any {
result := map[string]any{
"total": 0,
"rows": []VoLTEUser{},
"rows": []IMSUser{},
}
// 查询数量 长度为0直接返回
@@ -179,7 +179,7 @@ func (r *Repository) SelectPage(query map[string]any) map[string]any {
}
// SelectList 根据实体查询
func (r *Repository) SelectList(u VoLTEUser) []VoLTEUser {
func (r *Repository) SelectList(u IMSUser) []IMSUser {
// 查询条件拼接
var conditions []string
var params []any
@@ -210,23 +210,23 @@ func (r *Repository) SelectList(u VoLTEUser) []VoLTEUser {
}
// SelectByIMSIAndNeID 通过imsi和ne_id查询
func (r *Repository) SelectByIMSIAndNeID(imsi, neId string) VoLTEUser {
func (r *Repository) SelectByIMSIAndNeID(imsi, neId string) IMSUser {
querySql := r.selectSql + " where imsi = ? and ne_id = ?"
results, err := datasource.RawDB("", querySql, []any{imsi, neId})
if err != nil {
logger.Errorf("query err => %v", err)
return VoLTEUser{}
return IMSUser{}
}
// 转换实体
rows := r.convertResultRows(results)
if len(rows) > 0 {
return rows[0]
}
return VoLTEUser{}
return IMSUser{}
}
// Insert 批量添加
func (r *Repository) Inserts(uArr []VoLTEUser) int64 {
func (r *Repository) Inserts(uArr []IMSUser) int64 {
// multi-tenancy
r.SetTenantID(&uArr)
@@ -255,7 +255,7 @@ func (r *Repository) DeletePrefixByIMSI(imsiPrefix, neId string) int64 {
return tx.RowsAffected
}
func (r *Repository) SetTenantID(subArr *[]VoLTEUser) {
func (r *Repository) SetTenantID(subArr *[]IMSUser) {
for s := 0; s < len(*subArr); s++ {
var tenantID []string
err := dborm.DefaultDB().Table("sys_tenant").

View File

@@ -129,7 +129,7 @@ func (r *IMSUserService) SelectList(u model.IMSUser) []model.IMSUser {
// Insert 从数据中读取后删除imsi再存入数据库
// imsi长度15ki长度32opc长度0或者32
func (r *IMSUserService) Insert(neId string, u model.IMSUser) int64 {
uArr := r.dataByRedis(u.IMSI, neId)
uArr := r.dataByRedis(u.IMSI+":*", neId)
if len(uArr) > 0 {
r.imsUserRepository.Delete(u.IMSI, neId)
return r.imsUserRepository.Inserts(uArr)
@@ -187,10 +187,17 @@ func (r *IMSUserService) LoadData(neId, imsi, num string) {
subNum, _ := strconv.ParseInt(num, 10, 64)
var i int64
for i = 0; i < subNum; i++ {
keyIMSI := fmt.Sprintf("%015d", startIMSI+i)
var keyIMSI string
if len(imsi) == model.IMSI_MAX_LENGTH {
keyIMSI = fmt.Sprintf("%015d", startIMSI+i)
} else {
// 处理不满15位的IMSI, tag=TAG_VoIP
keyIMSI = fmt.Sprintf("%d", startIMSI+i)
}
// 删除原数据
r.imsUserRepository.Delete(keyIMSI, neId)
arr := r.dataByRedis(keyIMSI, neId)
arr := r.dataByRedis(keyIMSI+":*", neId)
if len(arr) < 1 {
continue
}

View File

@@ -21,7 +21,7 @@ type VoIPAuthService struct {
voipAuthRepository *repository.VoIPAuthRepository // VoLTE用户信息数据信息
}
// dataByRedis UDM签约用户 db:0 中 volte:*
// dataByRedis VoIP鉴权数据 db:0 中 voip:*
func (r *VoIPAuthService) dataByRedis(userName, neId string) []model.VoIPAuth {
arr := []model.VoIPAuth{}
key := fmt.Sprintf("voip:%s", userName)