fix: reload after batch add or del
This commit is contained in:
@@ -146,6 +146,9 @@ func (s *IMSUserController) Add(c *gin.Context) {
|
|||||||
// 命令ok时
|
// 命令ok时
|
||||||
if strings.Contains(data, "ok") {
|
if strings.Contains(data, "ok") {
|
||||||
body.NeId = neId
|
body.NeId = neId
|
||||||
|
if body.Tag == model.TAG_VoIP {
|
||||||
|
body.IMSI = body.MSISDN
|
||||||
|
}
|
||||||
s.imsUserService.Insert(neId, body)
|
s.imsUserService.Insert(neId, body)
|
||||||
}
|
}
|
||||||
c.JSON(200, result.OkData(data))
|
c.JSON(200, result.OkData(data))
|
||||||
@@ -194,7 +197,11 @@ func (s *IMSUserController) Adds(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
// 命令ok时
|
// 命令ok时
|
||||||
if strings.Contains(data, "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))
|
c.JSON(200, result.OkData(data))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,8 +182,7 @@ func (s *VoIPAuthController) Adds(c *gin.Context) {
|
|||||||
defer telnetClient.Close()
|
defer telnetClient.Close()
|
||||||
|
|
||||||
// 发送MML
|
// 发送MML
|
||||||
cmd := fmt.Sprintf("baa voip:start_username=%s,password=%s,sub_num=%s,",
|
cmd := fmt.Sprintf("baa voip:start_username=%s,sub_num=%s,", body.UserName, num)
|
||||||
body.UserName, body.Password, num)
|
|
||||||
cmd += s.voipAuthService.ParseCommandParams(body)
|
cmd += s.voipAuthService.ParseCommandParams(body)
|
||||||
data, err := telnet.ConvertToStr(telnetClient, cmd)
|
data, err := telnet.ConvertToStr(telnetClient, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ type Repository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convertResultRows 将结果记录转实体结果组
|
// convertResultRows 将结果记录转实体结果组
|
||||||
func (r *Repository) convertResultRows(rows []map[string]any) []VoLTEUser {
|
func (r *Repository) convertResultRows(rows []map[string]any) []IMSUser {
|
||||||
arr := make([]VoLTEUser, 0)
|
arr := make([]IMSUser, 0)
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
item := VoLTEUser{}
|
item := IMSUser{}
|
||||||
for key, value := range row {
|
for key, value := range row {
|
||||||
if keyMapper, ok := r.resultMap[key]; ok {
|
if keyMapper, ok := r.resultMap[key]; ok {
|
||||||
repo.SetFieldValue(&item, keyMapper, value)
|
repo.SetFieldValue(&item, keyMapper, value)
|
||||||
@@ -57,7 +57,7 @@ func (r *Repository) convertResultRows(rows []map[string]any) []VoLTEUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ClearAndInsert 清空ne_id后新增实体
|
// ClearAndInsert 清空ne_id后新增实体
|
||||||
func (r *Repository) ClearAndInsert(neId string, u []VoLTEUser) int64 {
|
func (r *Repository) ClearAndInsert(neId string, u []IMSUser) int64 {
|
||||||
// 不指定neID时,用 TRUNCATE 清空表快
|
// 不指定neID时,用 TRUNCATE 清空表快
|
||||||
// _, err := datasource.ExecDB("", "TRUNCATE TABLE u_ims_user", nil)
|
// _, err := datasource.ExecDB("", "TRUNCATE TABLE u_ims_user", nil)
|
||||||
_, err := datasource.ExecDB("", "DELETE FROM u_ims_user WHERE ne_id = ?", []any{neId})
|
_, 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{
|
result := map[string]any{
|
||||||
"total": 0,
|
"total": 0,
|
||||||
"rows": []VoLTEUser{},
|
"rows": []IMSUser{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询数量 长度为0直接返回
|
// 查询数量 长度为0直接返回
|
||||||
@@ -179,7 +179,7 @@ func (r *Repository) SelectPage(query map[string]any) map[string]any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SelectList 根据实体查询
|
// SelectList 根据实体查询
|
||||||
func (r *Repository) SelectList(u VoLTEUser) []VoLTEUser {
|
func (r *Repository) SelectList(u IMSUser) []IMSUser {
|
||||||
// 查询条件拼接
|
// 查询条件拼接
|
||||||
var conditions []string
|
var conditions []string
|
||||||
var params []any
|
var params []any
|
||||||
@@ -210,23 +210,23 @@ func (r *Repository) SelectList(u VoLTEUser) []VoLTEUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SelectByIMSIAndNeID 通过imsi和ne_id查询
|
// 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 = ?"
|
querySql := r.selectSql + " where imsi = ? and ne_id = ?"
|
||||||
results, err := datasource.RawDB("", querySql, []any{imsi, neId})
|
results, err := datasource.RawDB("", querySql, []any{imsi, neId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("query err => %v", err)
|
logger.Errorf("query err => %v", err)
|
||||||
return VoLTEUser{}
|
return IMSUser{}
|
||||||
}
|
}
|
||||||
// 转换实体
|
// 转换实体
|
||||||
rows := r.convertResultRows(results)
|
rows := r.convertResultRows(results)
|
||||||
if len(rows) > 0 {
|
if len(rows) > 0 {
|
||||||
return rows[0]
|
return rows[0]
|
||||||
}
|
}
|
||||||
return VoLTEUser{}
|
return IMSUser{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert 批量添加
|
// Insert 批量添加
|
||||||
func (r *Repository) Inserts(uArr []VoLTEUser) int64 {
|
func (r *Repository) Inserts(uArr []IMSUser) int64 {
|
||||||
// multi-tenancy
|
// multi-tenancy
|
||||||
r.SetTenantID(&uArr)
|
r.SetTenantID(&uArr)
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ func (r *Repository) DeletePrefixByIMSI(imsiPrefix, neId string) int64 {
|
|||||||
return tx.RowsAffected
|
return tx.RowsAffected
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) SetTenantID(subArr *[]VoLTEUser) {
|
func (r *Repository) SetTenantID(subArr *[]IMSUser) {
|
||||||
for s := 0; s < len(*subArr); s++ {
|
for s := 0; s < len(*subArr); s++ {
|
||||||
var tenantID []string
|
var tenantID []string
|
||||||
err := dborm.DefaultDB().Table("sys_tenant").
|
err := dborm.DefaultDB().Table("sys_tenant").
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ func (r *IMSUserService) SelectList(u model.IMSUser) []model.IMSUser {
|
|||||||
// Insert 从数据中读取后删除imsi再存入数据库
|
// Insert 从数据中读取后删除imsi再存入数据库
|
||||||
// imsi长度15,ki长度32,opc长度0或者32
|
// imsi长度15,ki长度32,opc长度0或者32
|
||||||
func (r *IMSUserService) Insert(neId string, u model.IMSUser) int64 {
|
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 {
|
if len(uArr) > 0 {
|
||||||
r.imsUserRepository.Delete(u.IMSI, neId)
|
r.imsUserRepository.Delete(u.IMSI, neId)
|
||||||
return r.imsUserRepository.Inserts(uArr)
|
return r.imsUserRepository.Inserts(uArr)
|
||||||
@@ -187,10 +187,17 @@ func (r *IMSUserService) LoadData(neId, imsi, num string) {
|
|||||||
subNum, _ := strconv.ParseInt(num, 10, 64)
|
subNum, _ := strconv.ParseInt(num, 10, 64)
|
||||||
var i int64
|
var i int64
|
||||||
for i = 0; i < subNum; i++ {
|
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)
|
r.imsUserRepository.Delete(keyIMSI, neId)
|
||||||
arr := r.dataByRedis(keyIMSI, neId)
|
arr := r.dataByRedis(keyIMSI+":*", neId)
|
||||||
if len(arr) < 1 {
|
if len(arr) < 1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ type VoIPAuthService struct {
|
|||||||
voipAuthRepository *repository.VoIPAuthRepository // VoLTE用户信息数据信息
|
voipAuthRepository *repository.VoIPAuthRepository // VoLTE用户信息数据信息
|
||||||
}
|
}
|
||||||
|
|
||||||
// dataByRedis UDM签约用户 db:0 中 volte:*
|
// dataByRedis VoIP鉴权数据 db:0 中 voip:*
|
||||||
func (r *VoIPAuthService) dataByRedis(userName, neId string) []model.VoIPAuth {
|
func (r *VoIPAuthService) dataByRedis(userName, neId string) []model.VoIPAuth {
|
||||||
arr := []model.VoIPAuth{}
|
arr := []model.VoIPAuth{}
|
||||||
key := fmt.Sprintf("voip:%s", userName)
|
key := fmt.Sprintf("voip:%s", userName)
|
||||||
|
|||||||
Reference in New Issue
Block a user