From fe7e2eb660b86bae4b17337cafd04cb4990d4002 Mon Sep 17 00:00:00 2001 From: wcg Date: Sun, 4 Jan 2026 10:31:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(user):=20=E6=B7=BB=E5=8A=A0=E6=8C=89?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IServices/IUserService.cs | 6 ++++ .../Services/System/UserService.cs | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IUserService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IUserService.cs index 343765e4..dd2f0c26 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IUserService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IUserService.cs @@ -8,5 +8,11 @@ namespace Yi.Framework.Rbac.Application.Contracts.IServices /// public interface IUserService : IYiCrudAppService { + /// + /// 获取指定部门及其所有子部门下的用户列表 + /// + /// 部门ID + /// 用户列表 + Task> GetUsersByDeptAsync(Guid deptId); } } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs index 6bd80e07..a7d7c2e2 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs @@ -236,5 +236,35 @@ namespace Yi.Framework.Rbac.Application.Services.System { return base.PostImportExcelAsync(input); } + + /// + /// 获取指定部门及其所有子部门下的用户列表 + /// + /// 部门ID + /// 用户列表 + [HttpGet] + [Route("user/dept/{deptId}")] + [Permission("system:user:list")] + public async Task> GetUsersByDeptAsync(Guid deptId) + { + // 获取当前部门及其所有子部门的ID列表 + var deptIds = await _deptService.GetChildListAsync(deptId); + + // 将当前部门ID也加入列表 + if (!deptIds.Contains(deptId)) + { + deptIds.Add(deptId); + } + + // 查询所有这些部门下的用户 + var users = await _repository._DbQueryable + .Where(u => deptIds.Contains(u.DeptId ?? Guid.Empty)) + .LeftJoin((user, dept) => user.DeptId == dept.Id) + .OrderByDescending(user => user.CreationTime) + .Select((user, dept) => new UserGetListOutputDto(), true) + .ToListAsync(); + + return users; + } } } \ No newline at end of file