feat(dept): 添加部门树形结构功能和相关API接口

This commit is contained in:
wcg
2026-01-04 10:23:42 +08:00
parent fe7c1763ba
commit b69c6d86c1
3 changed files with 187 additions and 0 deletions

View File

@@ -3,6 +3,8 @@ using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Yi.Framework.Core.Data;
using Yi.Framework.Core.Helper;
using Yi.Framework.Rbac.Domain.Shared.Dtos;
namespace Yi.Framework.Rbac.Domain.Entities
{
@@ -87,4 +89,40 @@ namespace Yi.Framework.Rbac.Domain.Entities
public string? Remark { get; set; }
}
/// <summary>
/// 部门实体扩展
/// </summary>
public static class DeptEntityExtensions
{
/// <summary>
/// 构建部门树形列表
/// </summary>
/// <param name="depts">部门列表</param>
/// <returns>树形结构的部门列表</returns>
public static List<DeptTreeDto> DeptTreeBuild(this List<DeptAggregateRoot> depts)
{
// 过滤启用的部门
var filteredDepts = depts
.Where(d => d.State == true)
.ToList();
List<DeptTreeDto> deptTrees = new();
foreach (var dept in filteredDepts)
{
var deptTree = new DeptTreeDto
{
Id = dept.Id,
OrderNum = dept.OrderNum,
DeptName = dept.DeptName,
State = dept.State,
ParentId = dept.ParentId,
};
deptTrees.Add(deptTree);
}
return TreeHelper.SetTree(deptTrees);
}
}
}