fix: import issue

This commit is contained in:
zhangsz
2025-04-16 11:22:42 +08:00
parent 82562de598
commit 4e1a50c754
3 changed files with 27 additions and 12 deletions

View File

@@ -106,31 +106,36 @@ func (r *VoIPAuthService) Insert(neId string, u model.VoIPAuth) int64 {
// InsertData 导入文件数据 dataType目前两种txt/csv
func (r *VoIPAuthService) InsertData(neId, dataType string, data any) int64 {
// userName截取前缀,重新获取部分数据
prefixes := make(map[string]struct{})
userNames := make(map[string]struct{})
if dataType == "csv" {
for _, v := range data.([]map[string]string) {
userName := v["userName"]
prefix := userName[:len(userName)-4]
prefixes[prefix] = struct{}{}
// if len(userName) < 6 {
// continue
// }
// prefix := userName[:len(userName)-4]
userNames[userName] = struct{}{}
}
}
if dataType == "txt" {
for _, v := range data.([][]string) {
userName := v[0]
prefix := userName[:len(userName)-4]
prefixes[prefix] = struct{}{}
// if len(userName) < 6 {
// continue
// }
// prefix := userName[:len(userName)-4]
userNames[userName] = struct{}{}
}
}
// 根据前缀重新加载插入
var num int64 = 0
for prefix := range prefixes {
// keys volte:4600001000004*
arr := r.dataByRedis(prefix+"*", neId)
for userName := range userNames {
// keys voip:11111
arr := r.dataByRedis(userName, neId)
if len(arr) > 0 {
r.voipAuthRepository.DeletePrefixByUserName(prefix, neId)
r.voipAuthRepository.DeleteByUserName(userName, neId)
num += r.voipAuthRepository.Inserts(arr)
}
}