fix: import issue
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user