diff --git a/ZR.Admin.WebApi/Framework/JwtUtil.cs b/ZR.Admin.WebApi/Framework/JwtUtil.cs index f665490..c65778a 100644 --- a/ZR.Admin.WebApi/Framework/JwtUtil.cs +++ b/ZR.Admin.WebApi/Framework/JwtUtil.cs @@ -128,7 +128,7 @@ namespace ZR.Admin.WebApi.Framework var userData = jwtToken.FirstOrDefault(x => x.Type == ClaimTypes.UserData).Value; var loginUser = JsonConvert.DeserializeObject(userData); var permissions = CacheService.GetUserPerms(GlobalConstant.UserPermKEY + loginUser?.UserId); - if (loginUser?.UserName == "admin") + if (loginUser?.UserName == GlobalConstant.AdminRole) { permissions = new List() { GlobalConstant.AdminPerm }; } diff --git a/ZR.Common/Tools.cs b/ZR.Common/Tools.cs index 053802c..d95c47f 100644 --- a/ZR.Common/Tools.cs +++ b/ZR.Common/Tools.cs @@ -80,6 +80,19 @@ namespace ZR.Common return false; } } + public static bool CheckUserName(string str) + { + try + { + string rg = @"^[a-z][a-z0-9-_]*$"; + return Regex.IsMatch(str, rg); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return false; + } + } /// /// 计算密码强度 diff --git a/ZR.Service/System/SysRoleService.cs b/ZR.Service/System/SysRoleService.cs index e7770b7..f99787c 100644 --- a/ZR.Service/System/SysRoleService.cs +++ b/ZR.Service/System/SysRoleService.cs @@ -222,7 +222,7 @@ namespace ZR.Service { var roleInfo = GetFirst(x => x.RoleId == roleid); - return roleInfo.RoleKey == "admin"; + return roleInfo.RoleKey == GlobalConstant.AdminRole; } /// diff --git a/ZR.Service/System/SysUserService.cs b/ZR.Service/System/SysUserService.cs index c9a6b0f..2ab997e 100644 --- a/ZR.Service/System/SysUserService.cs +++ b/ZR.Service/System/SysUserService.cs @@ -1,5 +1,6 @@ using Infrastructure; using Infrastructure.Attribute; +using Infrastructure.Extensions; using Microsoft.AspNetCore.Http; using System; using System.Collections; @@ -221,5 +222,48 @@ namespace ZR.Service //TODO 判断用户是否有数据权限 } } + + /// + /// 导入数据 + /// + /// + /// + public string ImportUsers(List users) + { + users.ForEach(x => + { + x.Create_time = DateTime.Now; + x.Status = "0"; + x.DelFlag = "0"; + x.Password = "E10ADC3949BA59ABBE56E057F20F883E"; + x.Remark = "数据导入"; + }); + var x = Context.Storageable(users) + .SplitInsert(it => !it.Any()) + .SplitIgnore(it => it.Item.UserName == GlobalConstant.AdminRole) + .SplitError(x => x.Item.UserName.IsEmpty(), "用户名不能为空") + .SplitError(x => !Tools.CheckUserName(x.Item.UserName), "用户名不符合规范") + .WhereColumns(it => it.UserName)//如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2}) + .ToStorage(); + var result = x.AsInsertable.ExecuteCommand();//插入可插入部分; + + string msg = string.Format(" 插入{0} 更新{1} 错误数据{2} 不计算数据{3} 删除数据{4},总共{5}", + x.InsertList.Count, + x.UpdateList.Count, + x.ErrorList.Count, + x.IgnoreList.Count, + x.DeleteList.Count, + x.TotalList.Count); + //输出统计 + Console.WriteLine(msg); + + //输出错误信息 + foreach (var item in x.ErrorList) + { + Console.WriteLine("userName为" + item.Item.UserName + " : " + item.StorageMessage); + } + + return msg; + } } }