From 915bd476d5d39f9443a3197c67191abf979063b7 Mon Sep 17 00:00:00 2001 From: chenwenkai <1084072318@qq.com> Date: Fri, 1 Nov 2024 12:16:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=95=B0=E6=8D=AE=E7=BC=BA=E5=B0=91bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/Tnb.Systems/Permission/UsersService.cs | 69 +++++++++++++++++-- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/system/Tnb.Systems/Permission/UsersService.cs b/system/Tnb.Systems/Permission/UsersService.cs index ad73a566..e8919468 100644 --- a/system/Tnb.Systems/Permission/UsersService.cs +++ b/system/Tnb.Systems/Permission/UsersService.cs @@ -1414,12 +1414,69 @@ public class UsersService : IUsersService, IDynamicApiController, ITransient // 用户信息列表 List? userList = new List(); - ISugarQueryable? sqlQuery = _repository.AsSugarClient().Queryable((a, b) => new JoinQueryInfos(JoinType.Left, b.Id == SqlFunc.ToString(a.OrganizeId))) - .WhereIF(!string.IsNullOrWhiteSpace(input.organizeId), a => a.OrganizeId == input.organizeId) // 组织机构 - .WhereIF(!input.keyword.IsNullOrEmpty(), a => a.Account.Contains(input.keyword) || a.RealName.Contains(input.keyword)) - .Where(a => a.DeleteMark == null) - .OrderBy(a => a.SortCode).OrderBy(a => a.CreatorTime, OrderByType.Desc) - .Select(a => new UserListImportDataInput() + // 获取分级管理组织 + var dataScope = _userManager.DataScope.Where(x => x.Select).Select(x => x.organizeId).Distinct().ToList(); + + #region 获取组织层级 + + List? childOrgIds = new List(); + if (input.organizeId.IsNotEmptyOrNull()) + { + childOrgIds.Add(input.organizeId); + + // 根据组织Id 获取所有子组织Id集合 + childOrgIds.AddRange(_repository.AsSugarClient().Queryable().ToChildList(x => x.ParentId, input.organizeId).Select(x => x.Id).ToList()); + childOrgIds = childOrgIds.Distinct().ToList(); + } + + #endregion + + #region 老代码 + //ISugarQueryable? sqlQuery = _repository.AsSugarClient().Queryable((a, b) => new JoinQueryInfos(JoinType.Left, b.Id == SqlFunc.ToString(a.OrganizeId))) + // .WhereIF(!string.IsNullOrWhiteSpace(input.organizeId), a => a.OrganizeId == input.organizeId) // 组织机构 + // .WhereIF(!input.keyword.IsNullOrEmpty(), a => a.Account.Contains(input.keyword) || a.RealName.Contains(input.keyword)) + // .Where(a => a.DeleteMark == null) + // .OrderBy(a => a.SortCode).OrderBy(a => a.CreatorTime, OrderByType.Desc) + // .Select(a => new UserListImportDataInput() + // { + // id = a.Id, + // account = a.Account, + // realName = a.RealName, + // birthday = SqlFunc.ToString(a.Birthday), + // certificatesNumber = a.CertificatesNumber, + // managerId = SqlFunc.Subqueryable().Where(e => e.Id == a.ManagerId).Select(u => SqlFunc.MergeString(u.RealName, "/", u.Account)), + // organizeId = a.OrganizeId, // 组织结构 + // positionId = a.PositionId, // 岗位 + // roleId = a.RoleId, // 多角色 + // certificatesType = SqlFunc.Subqueryable().Where(d => d.DictionaryTypeId == "7866376d5f694d4d851c7164bd00ebfc" && d.Id == a.CertificatesType).Select(b => b.FullName), + // education = SqlFunc.Subqueryable().Where(d => d.DictionaryTypeId == "6a6d6fb541b742fbae7e8888528baa16" && d.Id == a.Education).Select(b => b.FullName), + // gender = SqlFunc.Subqueryable().Where(d => d.DictionaryTypeId == "963255a34ea64a2584c5d1ba269c1fe6" && d.EnCode == SqlFunc.ToString(a.Gender)).Select(b => b.FullName), + // nation = SqlFunc.Subqueryable().Where(d => d.DictionaryTypeId == "b6cd65a763fa45eb9fe98e5057693e40" && d.Id == a.Nation).Select(b => b.FullName), + // description = a.Description, + // entryDate = SqlFunc.ToString(a.EntryDate), + // email = a.Email, + // enabledMark = SqlFunc.IF(a.EnabledMark.Equals(0)).Return("禁用").ElseIF(a.EnabledMark.Equals(1)).Return("正常").End("锁定"), + // mobilePhone = a.MobilePhone, + // nativePlace = a.NativePlace, + // postalAddress = a.PostalAddress, + // telePhone = a.TelePhone, + // urgentContacts = a.UrgentContacts, + // urgentTelePhone = a.UrgentTelePhone, + // landline = a.Landline, + // sortCode = a.SortCode.ToString() + // }); + + #endregion + + ISugarQueryable? sqlQuery = _repository.AsSugarClient().Queryable((a, b) => new JoinQueryInfos(JoinType.Left, b.UserId == a.Id)) + .Where((a, b) => a.DeleteMark == null && !a.Account.Equals("admin")) + .WhereIF(childOrgIds.Any(), (a, b) => childOrgIds.Contains(b.ObjectId)) + .WhereIF(!input.keyword.IsNullOrEmpty(), (a, b) => a.Account.Contains(input.keyword) || a.RealName.Contains(input.keyword)) + .WhereIF(!_userManager.IsAdministrator, (a, b) => dataScope.Contains(b.ObjectId)) + .OrderBy((a, b) => a.SortCode).OrderBy((a, b) => a.CreatorTime, OrderByType.Desc).OrderBy((a, b) => a.LastModifyTime, OrderByType.Desc) + .GroupBy((a, b) => new { a.Id, a.Account, a.RealName, a.CreatorTime, a.LastModifyTime, a.Gender, a.MobilePhone, a.SortCode, a.EnabledMark, a.UnLockTime }) + //.OrderBy(a => a.SortCode).OrderBy(a => a.CreatorTime, OrderByType.Desc) + .Select((a, b) => new UserListImportDataInput() { id = a.Id, account = a.Account,