You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.6 KiB
2.6 KiB
组织单位创建
**本文档引用的文件** - [OrganizationUnitCreateDto.cs](file://aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/OrganizationUnitCreateDto.cs) - [OrganizationUnitAppService.cs](file://aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs) - [OrganizationUnitDto.cs](file://aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/OrganizationUnitDto.cs)目录
简介
本文档详细说明了组织单位创建功能的实现机制。组织单位是系统中用于管理用户和权限的树形结构实体,支持多级嵌套。创建操作通过应用服务层协调领域逻辑,确保数据一致性与业务规则的执行。
核心组件
[深入分析核心组件及其关系]
Section sources
- OrganizationUnitAppService.cs
- OrganizationUnitCreateDto.cs
创建逻辑实现
CreateAsync 方法是创建组织单位的核心入口,其逻辑流程如下:
- 参数验证: 方法接收
OrganizationUnitCreateDto对象作为输入,该对象的DisplayName属性被[Required]和[DynamicStringLength]特性修饰,确保在进入方法体前已进行非空和长度验证。 - 实体构建: 使用输入的
DisplayName、ParentId以及当前租户ID,通过OrganizationUnitManager创建一个新的OrganizationUnit实体实例。 - 关联处理: 如果指定了
ParentId,则在创建过程中会自动建立与父级组织单位的关联。 - 层级路径生成: 在创建实体时,
OrganizationUnitManager会根据父级信息自动生成并维护Code字段,该字段代表了从根节点到当前节点的完整路径,用于高效查询和权限继承。 - 唯一性约束检查: 在
OrganizationUnitManager的CreateAsync方法内部,会检查在同一个父级