diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 587ddc1..bb8c8d4 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -202,10 +202,7 @@ namespace ZR.Admin.WebApi.Controllers.System { return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误"); } - if (UserConstants.NOT_UNIQUE.Equals(sysUserService.CheckUserNameUnique(dto.Username))) - { - return ToResponse(ResultCode.CUSTOM_ERROR, $"保存用户{dto.Username}失败,注册账号已存在"); - } + SysUser user = sysUserService.Register(dto); if (user.UserId > 0) { diff --git a/ZR.Service/System/SysMenuService.cs b/ZR.Service/System/SysMenuService.cs index 2b8f41c..54b963b 100644 --- a/ZR.Service/System/SysMenuService.cs +++ b/ZR.Service/System/SysMenuService.cs @@ -205,6 +205,7 @@ namespace ZR.Service JoinType.Left, rm.Role_id == ur.RoleId, JoinType.Left, ur.RoleId == r.RoleId )) + .WithCache(60 * 10) .Where((m, rm, ur, r) => m.Status == "0" && r.Status == 0 && ur.UserId == userId) .Select((m, rm, ur, r) => m).ToList(); var menuList = menus.Where(f => !string.IsNullOrEmpty(f.Perms)); @@ -281,6 +282,7 @@ namespace ZR.Service int parentId = menu.ParentId != null ? (int)menu.ParentId : 0; var list = Queryable() + .WithCache(60 * 10) .WhereIF(!string.IsNullOrEmpty(menu.MenuName), it => it.MenuName.Contains(menu.MenuName)) .WhereIF(!string.IsNullOrEmpty(menu.Visible), it => it.Visible == menu.Visible) .WhereIF(!string.IsNullOrEmpty(menu.Status), it => it.Status == menu.Status) diff --git a/ZR.Service/System/SysRoleService.cs b/ZR.Service/System/SysRoleService.cs index 308e1f1..874e95e 100644 --- a/ZR.Service/System/SysRoleService.cs +++ b/ZR.Service/System/SysRoleService.cs @@ -294,6 +294,7 @@ namespace ZR.Service public List SelectUserRoleListByUserId(long userId) { return Context.Queryable() + .WithCache(60 * 10) .LeftJoin((ur, r) => ur.RoleId == r.RoleId) .Where((ur, r) => ur.UserId == userId && r.RoleId > 0) .Select((ur, r) => r) diff --git a/ZR.Service/System/SysUserRoleService.cs b/ZR.Service/System/SysUserRoleService.cs index 17fb032..40b70fd 100644 --- a/ZR.Service/System/SysUserRoleService.cs +++ b/ZR.Service/System/SysUserRoleService.cs @@ -64,11 +64,12 @@ namespace ZR.Service.System /// public List GetSysUsersByRoleId(long roleId) { - return Context.Queryable ((t1, u) => new JoinQueryInfos( + return Context.Queryable((t1, u) => new JoinQueryInfos( JoinType.Left, t1.UserId == u.UserId)) - .Where((t1, u) => t1.RoleId == roleId && u.DelFlag == 0) - .Select((t1, u) => u) - .ToList(); + .WithCache(60 * 10) + .Where((t1, u) => t1.RoleId == roleId && u.DelFlag == 0) + .Select((t1, u) => u) + .ToList(); } /// diff --git a/ZR.Service/System/SysUserService.cs b/ZR.Service/System/SysUserService.cs index 9080693..959bfbe 100644 --- a/ZR.Service/System/SysUserService.cs +++ b/ZR.Service/System/SysUserService.cs @@ -2,7 +2,6 @@ using Infrastructure; using Infrastructure.Attribute; using Infrastructure.Extensions; using SqlSugar; -using SqlSugar.IOC; using System; using System.Collections; using System.Collections.Generic; @@ -81,7 +80,8 @@ namespace ZR.Service /// public SysUser SelectUserById(long userId) { - var user = Queryable().Filter(null, true).Where(f => f.UserId == userId).First(); + var user = Queryable().Filter(null, true).WithCache(60 * 5) + .Where(f => f.UserId == userId).First(); if (user != null && user.UserId > 0) { user.Roles = RoleService.SelectUserRoleListByUserId(userId); @@ -219,12 +219,13 @@ namespace ZR.Service /// public SysUser Register(RegisterDto dto) { - //密码md5 - string password = NETCore.Encrypt.EncryptProvider.Md5(dto.Password); if (!Tools.PasswordStrength(dto.Password)) { throw new CustomException("密码强度不符合要求"); } + //密码md5 + string password = NETCore.Encrypt.EncryptProvider.Md5(dto.Password); + SysUser user = new() { Create_time = DateTime.Now, @@ -235,7 +236,10 @@ namespace ZR.Service DeptId = 0, Remark = "用户注册" }; - + if (UserConstants.NOT_UNIQUE.Equals(CheckUserNameUnique(dto.Username))) + { + throw new CustomException($"保存用户{dto.Username}失败,注册账号已存在"); + } user.UserId = Insertable(user).ExecuteReturnIdentity(); return user; } @@ -300,7 +304,7 @@ namespace ZR.Service x.TotalList.Count); //输出统计 Console.WriteLine(msg); - + //输出错误信息 foreach (var item in x.ErrorList) { @@ -310,7 +314,7 @@ namespace ZR.Service { Console.WriteLine("userName为" + item.Item.UserName + " : " + item.StorageMessage); } - + return (msg, x.ErrorList, x.IgnoreList); }