diff --git a/YD_Event.Application/Menu/SysMenuService.cs b/YD_Event.Application/Menu/SysMenuService.cs index 27ae9e0..5c35344 100644 --- a/YD_Event.Application/Menu/SysMenuService.cs +++ b/YD_Event.Application/Menu/SysMenuService.cs @@ -359,8 +359,8 @@ public class SysMenuService : BaseService, ITransient { if (_authManager.IsSuperAdmin) return true; var cache = await GetAuthButtonCodeList(_authManager.UserId); - var output = cache.FirstOrDefault(x => x.Code.Contains(code, StringComparison.CurrentCultureIgnoreCase)); - return output?.Access ?? true; + var output = cache.FirstOrDefault(x => string.Equals(x.Code, code, StringComparison.CurrentCultureIgnoreCase)); + return output?.Access ?? false; } /// @@ -371,21 +371,35 @@ public class SysMenuService : BaseService, ITransient [NonAction] public async Task> GetAuthButtonCodeList(long userId) { - var cache = await _easyCachingProvider.GetAsync($"{CacheConst.PermissionButtonCodeKey}{userId}", async () => + var cacheKey = $"{CacheConst.PermissionButtonCodeKey}v2.{userId}"; + var cache = await _easyCachingProvider.GetAsync(cacheKey, async () => { - var queryable = _sysMenuRepository.AsSugarClient().Queryable() - .InnerJoin((role, userRole) => role.Id == userRole.RoleId) - .InnerJoin((role, userRole, roleMenu) => role.Id == roleMenu.RoleId) - .Where(role => role.Status == AvailabilityStatus.Enable) - .Select((role, userRole, roleMenu) => roleMenu); - var list = await _sysMenuRepository.AsQueryable().LeftJoin(queryable, (menu, roleMenu) => menu.Id == roleMenu.MenuId) - .Where(menu => menu.Type == MenuType.Button || menu.Type == MenuType.DataScope) - .Select((menu, roleMenu) => new CheckPermissionOutput - { - Code = menu.Code, - Access = SqlFunc.IIF(SqlFunc.IsNull(roleMenu.Id, 0) > 0 || menu.Status == AvailabilityStatus.Disable, true, false) - }).ToListAsync(); - return list.Distinct().ToList(); + var list = await _sysMenuRepository.AsSugarClient() + .Queryable() + .InnerJoin((userRole, role) => userRole.RoleId == role.Id) + .InnerJoin((userRole, role, roleMenu) => role.Id == roleMenu.RoleId) + .InnerJoin((userRole, role, roleMenu, menu) => roleMenu.MenuId == menu.Id) + .Where((userRole, role, roleMenu, menu) => + userRole.UserId == userId && + role.Status == AvailabilityStatus.Enable && + menu.Status == AvailabilityStatus.Enable && + (menu.Type == MenuType.Button || menu.Type == MenuType.DataScope)) + .Select((userRole, role, roleMenu, menu) => new CheckPermissionOutput + { + Code = menu.Code, + Access = true + }) + .ToListAsync(); + + return list + .Where(x => !string.IsNullOrWhiteSpace(x.Code)) + .GroupBy(x => x.Code) + .Select(g => new CheckPermissionOutput + { + Code = g.Key, + Access = true + }) + .ToList(); }, TimeSpan.FromDays(1)); return cache.Value; } @@ -409,4 +423,4 @@ public class SysMenuService : BaseService, ITransient } } } -} \ No newline at end of file +} diff --git a/YD_Event.Application/User/SysUserService.cs b/YD_Event.Application/User/SysUserService.cs index e8c11d8..0d4bdb5 100644 --- a/YD_Event.Application/User/SysUserService.cs +++ b/YD_Event.Application/User/SysUserService.cs @@ -344,12 +344,20 @@ public class SysUserService : BaseService, ITransient { dto.AuthBtnList = _repository.AsSugarClient().Queryable() .Where(x => x.Type == MenuType.Button || x.Type == MenuType.DataScope) - .Select(x => x.Code).ToList(); + .Select(x => x.Code) + .ToList() + .Where(x => !string.IsNullOrWhiteSpace(x)) + .Distinct() + .ToList(); } else { var list = _sysMenuService.GetAuthButtonCodeList(userId).GetAwaiter().GetResult(); - dto.AuthBtnList = list.Where(x => x.Access).Select(x => x.Code).ToList(); + dto.AuthBtnList = list + .Where(x => x.Access && !string.IsNullOrWhiteSpace(x.Code)) + .Select(x => x.Code) + .Distinct() + .ToList(); } }) .FirstAsync();