|
@@ -359,13 +359,11 @@ func ImportUser(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
user.LoginName = us[0]
|
|
user.LoginName = us[0]
|
|
user.Nid = us[1]
|
|
user.Nid = us[1]
|
|
if len(us[0]) == 0 {
|
|
if len(us[0]) == 0 {
|
|
- errors = append(errors, fmt.Sprintf("第%d行错误: %s", rowNum, "用户名不能为空"))
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- if len(us[1]) == 0 {
|
|
|
|
- errors = append(errors, fmt.Sprintf("第%d行错误: %s", rowNum, "编号不能为空"))
|
|
|
|
|
|
+ errors = append(errors, fmt.Sprintf("第%d行错误: %s", rowNum, "账号不能为空"))
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
+ // !查询用户,确保账号名唯一,用数据库唯一索引约束:db.users.createIndex({ loginName: 1 }, { unique: true })
|
|
|
|
+
|
|
roles := []string{}
|
|
roles := []string{}
|
|
if us[2] == "管理员" {
|
|
if us[2] == "管理员" {
|
|
roles = []string{"admin"}
|
|
roles = []string{"admin"}
|
|
@@ -383,14 +381,13 @@ func ImportUser(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
} else if len(us[3]) == 32 {
|
|
} else if len(us[3]) == 32 {
|
|
user.Password = us[3]
|
|
user.Password = us[3]
|
|
}
|
|
}
|
|
- user.LoginName = fmt.Sprintf("%s_%s", user.LoginName, user.Nid)
|
|
|
|
|
|
|
|
user.CreateTime = time.Now()
|
|
user.CreateTime = time.Now()
|
|
user.UpdateTime = time.Now()
|
|
user.UpdateTime = time.Now()
|
|
|
|
|
|
_, err = repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionUser, user)
|
|
_, err = repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionUser, user)
|
|
if err != nil {
|
|
if err != nil {
|
|
- errors = append(errors, fmt.Sprintf("第%d行错误: %s", rowNum, "保存数据失败, 请检查数据格式是否正确/编号是否重复"))
|
|
|
|
|
|
+ errors = append(errors, fmt.Sprintf("第%d行错误: %s", rowNum, "保存数据失败, 请检查数据格式是否正确/账号是否重复"))
|
|
log.Error(err)
|
|
log.Error(err)
|
|
}
|
|
}
|
|
|
|
|