diff --git a/ZR.Repository/System/SysUserRepository.cs b/ZR.Repository/System/SysUserRepository.cs index 6c263a4..bb3d1b9 100644 --- a/ZR.Repository/System/SysUserRepository.cs +++ b/ZR.Repository/System/SysUserRepository.cs @@ -2,6 +2,7 @@ using Infrastructure.Extensions; using SqlSugar; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using ZR.Model; @@ -33,10 +34,15 @@ namespace ZR.Repository.System if (user.DeptId != 0) { - SysDept dept = Context.Queryable().First(f => f.DeptId == user.DeptId); - string[] deptArr = dept?.Ancestors.Split(",").ToArray(); + List depts = Context.Queryable().ToList(); - exp.AndIF(user.DeptId != 0, u => u.DeptId == user.DeptId);// || deptArr.Contains(u.DeptId.ToString())); + var newDepts = depts.FindAll(delegate (SysDept dept) + { + string[] parentDeptId = dept.Ancestors.Split(",", StringSplitOptions.RemoveEmptyEntries); + return parentDeptId.Contains(user.DeptId.ToString()); + }); + string[] deptArr = newDepts.Select(x => x.DeptId.ToString()).ToArray(); + exp.AndIF(user.DeptId != 0, u => u.DeptId == user.DeptId || deptArr.Contains(u.DeptId.ToString())); } var query = Context.Queryable() .LeftJoin((u, dept) => u.DeptId == dept.DeptId)