From bee520ee2a73951d14cb774a22d2d0b09699fc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sat, 22 Jan 2022 09:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=A0=B9=E6=8D=AE=E9=83=A8=E9=97=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Repository/System/SysUserRepository.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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)