v3.4.6
This commit is contained in:
@@ -102,62 +102,42 @@ public class RoleService : IRoleService, IDynamicApiController, ITransient
|
||||
SqlSugarPagedList<RoleListOutput>? data = new SqlSugarPagedList<RoleListOutput>();
|
||||
if (childOrgIds.Any())
|
||||
{
|
||||
// 拼接查询
|
||||
List<ISugarQueryable<RoleListOutput>>? listQuery = new List<ISugarQueryable<RoleListOutput>>();
|
||||
foreach (string item in childOrgIds)
|
||||
{
|
||||
var quer = _repository.AsSugarClient().Queryable<OrganizeRelationEntity, RoleEntity>((a, b) => new JoinQueryInfos(JoinType.Left, b.Id == a.ObjectId))
|
||||
.Where((a, b) => item == a.OrganizeId)
|
||||
.WhereIF(!pageInput.keyword.IsNullOrEmpty(), (a, b) => b.FullName.Contains(pageInput.keyword) || b.EnCode.Contains(pageInput.keyword))
|
||||
.WhereIF(!_userManager.IsAdministrator, a => dataScope.Contains(a.ObjectId))
|
||||
.Where((a, b) => b.DeleteMark == null)
|
||||
data = await _repository.AsSugarClient().Queryable<RoleEntity, OrganizeRelationEntity>((a, b) => new JoinQueryInfos(JoinType.Left, a.Id == b.ObjectId))
|
||||
.Where((a, b) => childOrgIds.Contains(b.OrganizeId)).Where((a, b) => a.DeleteMark == null)
|
||||
.WhereIF(!pageInput.keyword.IsNullOrEmpty(), (a, b) => a.FullName.Contains(pageInput.keyword) || a.EnCode.Contains(pageInput.keyword))
|
||||
.WhereIF(!_userManager.IsAdministrator, (a, b) => dataScope.Contains(b.OrganizeId))
|
||||
.GroupBy((a, b) => new { a.Id, a.Type, a.GlobalMark, a.EnCode, a.FullName, a.EnabledMark, a.CreatorTime, a.SortCode })
|
||||
.Select((a, b) => new RoleListOutput
|
||||
{
|
||||
id = b.Id,
|
||||
parentId = b.Type,
|
||||
type = SqlFunc.IIF(b.GlobalMark == 1, "全局", "组织"),
|
||||
enCode = b.EnCode,
|
||||
fullName = b.FullName,
|
||||
enabledMark = b.EnabledMark,
|
||||
creatorTime = b.CreatorTime,
|
||||
sortCode = b.SortCode
|
||||
});
|
||||
listQuery.Add(quer);
|
||||
}
|
||||
var sql = _repository.AsSugarClient().UnionAll(listQuery).Where(a => !SqlFunc.IsNullOrEmpty(a.id)).ToSqlString();
|
||||
data = await _repository.AsSugarClient().UnionAll(listQuery).Where(a => !SqlFunc.IsNullOrEmpty(a.id))
|
||||
.GroupBy(a => new { a.id, a.parentId, a.type, a.creatorTime, a.enCode, a.fullName, a.sortCode, a.enabledMark })
|
||||
.Select(a => new RoleListOutput
|
||||
{
|
||||
id = a.id,
|
||||
parentId = a.parentId,
|
||||
type = a.type,
|
||||
creatorTime = a.creatorTime,
|
||||
enCode = a.enCode,
|
||||
fullName = a.fullName,
|
||||
sortCode = a.sortCode
|
||||
}).ToPagedListAsync(input.currentPage, input.pageSize);
|
||||
id = a.Id,
|
||||
parentId = a.Type,
|
||||
type = SqlFunc.IIF(a.GlobalMark == 1, "全局", "组织"),
|
||||
enCode = a.EnCode,
|
||||
fullName = a.FullName,
|
||||
enabledMark = a.EnabledMark,
|
||||
creatorTime = a.CreatorTime,
|
||||
sortCode = a.SortCode
|
||||
}).MergeTable().OrderBy(a => a.sortCode).OrderBy(a => a.creatorTime, OrderByType.Desc).ToPagedListAsync(input.currentPage, input.pageSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = await _repository.AsSugarClient().Queryable<RoleEntity>()
|
||||
.WhereIF(input.organizeId == "0", a => a.GlobalMark == 1)
|
||||
.WhereIF(!_userManager.IsAdministrator, a => a.GlobalMark == 0)
|
||||
.WhereIF(!_userManager.IsAdministrator, a => a.GlobalMark == 1)
|
||||
.WhereIF(!string.IsNullOrEmpty(input.keyword), a => a.FullName.Contains(input.keyword) || a.EnCode.Contains(input.keyword))
|
||||
.Where(a => a.DeleteMark == null)
|
||||
.Select((a) => new RoleListOutput
|
||||
{
|
||||
id = a.Id,
|
||||
parentId = a.Type,
|
||||
type = SqlFunc.IIF(a.GlobalMark == 1, "全局", "组织"),
|
||||
enCode = a.EnCode,
|
||||
fullName = a.FullName,
|
||||
description = a.Description,
|
||||
enabledMark = a.EnabledMark,
|
||||
creatorTime = a.CreatorTime,
|
||||
sortCode = a.SortCode
|
||||
}).MergeTable().OrderBy(a => a.sortCode).OrderBy(a => a.creatorTime, OrderByType.Desc).ToPagedListAsync(input.currentPage, input.pageSize);
|
||||
data = await _repository.AsSugarClient().Queryable<RoleEntity, OrganizeRelationEntity>((a, b) => new JoinQueryInfos(JoinType.Left, a.Id == b.ObjectId))
|
||||
.Where((a, b) => a.DeleteMark == null)
|
||||
.WhereIF(input.organizeId == "0", (a, b) => a.GlobalMark == 1)
|
||||
.WhereIF(!pageInput.keyword.IsNullOrEmpty(), (a, b) => a.FullName.Contains(pageInput.keyword) || a.EnCode.Contains(pageInput.keyword))
|
||||
.WhereIF(!_userManager.IsAdministrator && input.organizeId != "0", (a, b) => dataScope.Contains(b.OrganizeId))
|
||||
.GroupBy((a, b) => new { a.Id, a.Type, a.GlobalMark, a.EnCode, a.FullName, a.EnabledMark, a.CreatorTime, a.SortCode })
|
||||
.Select((a, b) => new RoleListOutput
|
||||
{
|
||||
id = a.Id,
|
||||
parentId = a.Type,
|
||||
type = SqlFunc.IIF(a.GlobalMark == 1, "全局", "组织"),
|
||||
enCode = a.EnCode,
|
||||
fullName = a.FullName,
|
||||
enabledMark = a.EnabledMark,
|
||||
creatorTime = a.CreatorTime,
|
||||
sortCode = a.SortCode
|
||||
}).MergeTable().OrderBy(a => a.sortCode).OrderBy(a => a.creatorTime, OrderByType.Desc).ToPagedListAsync(input.currentPage, input.pageSize);
|
||||
}
|
||||
|
||||
#region 处理 多组织
|
||||
@@ -169,11 +149,8 @@ public class RoleService : IRoleService, IDynamicApiController, ITransient
|
||||
// 获取组织集合
|
||||
var organizeList = orgUserIdAll.Where(x => x.ObjectId == item.id).Select(x => x.OrganizeId).ToList();
|
||||
item.organizeInfo = string.Join(" ; ", orgTreeNameList.Where(x => organizeList.Contains(x.Id)).Select(x => x.Description));
|
||||
item.sortCode = 999;
|
||||
if (organizeList.Contains(input.organizeId)) item.sortCode = 0;
|
||||
}
|
||||
|
||||
data.list = data.list.OrderBy(x => x.sortCode).ToList();
|
||||
#endregion
|
||||
|
||||
return PageResult<RoleListOutput>.SqlSugarPageResult(data);
|
||||
|
||||
Reference in New Issue
Block a user