- Java锁的逻辑(结合对象头和ObjectMonitor)
- 还在用饼状图?来瞧瞧这些炫酷的百分比可视化新图形(附代码实现)⛵
- 自动注册实体类到EntityFrameworkCore上下文,并适配ABP及ABPVNext
- 基于Sklearn机器学习代码实战
@ 。
身份管理模块的领域层依赖Volo.Abp.Identity.Domain 。
Abp为我们实现了一套身份管理模块,此模块包含用户管理、角色管理、组织管理、权限管理等功能。详细请参考 身份管理模块 .
我们将基于Volo.Abp.Identity模块按需求扩展。将为其扩展组织管理功能的接口,以及人员关系(Relation)功能.
Relation是人员之间的关系,比如:签约、关注,或者朋友关系等。人员之间的关系是单项的,也就是说可以A是B的好友,但B不一定是A的好友.
关系类型由Type来定义 。
正向关系:User -> RelatedUser,由查询GetRelatedToUsersAsync实现; 。
反向关系:RelatedUser -> User,由查询GetRelatedFromUsersAsync实现.
添加Relation实体:
public class Relation : FullAuditedAggregateRoot<long>
{
public Guid? TenantId { get; set; }
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public override long Id { get; protected set; }
public Guid UserId { get; set; }
[ForeignKey("UserId")]
public IdentityUser User { get; set; }
public Guid RelatedUserId { get; set; }
[ForeignKey("RelatedUserId")]
public IdentityUser RelatedUser { get; set; }
public string Type { get; set; }
}
在模块配置中添加 。
public class IdentityEntityFrameworkCoreModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<IdentityDbContext>(options =>
{
options.AddRepository<IdentityUserOrganizationUnit, EfCoreRepository<IdentityDbContext, IdentityUserOrganizationUnit>>();
options.AddRepository<Relation.Relation, EfCoreRepository<IdentityDbContext, Relation.Relation>>();
});
}
}
创建RelationManager,实现人员关系的正向和反向查询 。
public async Task<List<Relation>> GetRelatedToUsersAsync(Guid userId, string type)
{
var query = (await Repository.GetQueryableAsync())
.WhereIf(userId != null, c => userId == c.UserId)
.WhereIf(!string.IsNullOrEmpty(type), c => c.Type == type);
var items = query.ToList();
return items;
}
public async Task<List<Relation>> GetRelatedFromUsersAsync(Guid userId, string type)
{
var query = (await Repository.GetQueryableAsync())
.Where(c => userId == c.RelatedUserId)
.WhereIf(!string.IsNullOrEmpty(type), c => c.Type == type);
var items = query.ToList();
return items;
}
组织(OrganizationUnit)是身份管理模块的核心概念,组织是树形结构,组织之间存在父子关系.
我们对功能模块的接口进行扩展:
增加OrganizationUnit的增删查改接口; 。
增加OrganizationUnit的移动接口; 。
增加人员与组织架构管理接口,如添加/删除人员到组织架构,查询组织架构下的人员,查询未分配组织的人员等; 。
增加查询根组织(GetRootOrganizationUnit)接口.
完整的应用层接口如下:
public interface IOrganizationUnitAppService : IBasicCurdAppService<OrganizationUnitDto, Guid, CreateOrganizationUnitInput, UpdateOrganizationUnitInput>, IApplicationService
{
Task AddToOrganizationUnitAsync(UserToOrganizationUnitInput input);
Task<List<OrganizationUnitDto>> GetCurrentOrganizationUnitsAsync();
Task<PagedResultDto<IdentityUserDto>> GetOrganizationUnitUsersByPageAsync(GetOrganizationUnitUsersInput input);
Task<List<IdentityUserDto>> GetOrganizationUnitUsersAsync(GetOrganizationUnitUsersInput input);
Task<OrganizationUnitDto> GetRootOrganizationUnitAsync(Guid id);
Task<List<OrganizationUnitDto>> GetRootOrganizationUnitsAsync(IEnumerable<Guid> ids);
Task<OrganizationUnitDto> GetRootOrganizationUnitByDisplayNameAsync(GetRootOrganizationUnitByDisplayName input);
Task<List<OrganizationUnitDto>> GetRootOrganizationUnitsByParentAsync(GetRootOrganizationUnitsByParentInput input);
Task<bool> IsInOrganizationUnitAsync(UserToOrganizationUnitInput input);
Task MoveOrganizationUnitAsync(MoveOrganizationUnitInput input);
Task RemoveUserFromOrganizationUnitAsync(UserToOrganizationUnitInput input);
Task<List<IdentityUserDto>> GetUsersWithoutOrganizationAsync(GetUserWithoutOrganizationInput input);
Task<PagedResultDto<IdentityUserDto>> GetUsersWithoutOrganizationByPageAsync(GetUserWithoutOrganizationInput input);
}
通用查询接口过滤条件需要对IQueryable进行拼接,由于Volo.Abp.Identity.IIdentityUserRepository继承自IBasicRepository,我们需要重新编写一个IdentityUser的可查询仓储:QueryableIdentityUserRepository 。
其实现接口IQueryableIdentityUserRepository的定义如下:
public interface IQueryableIdentityUserRepository : IIdentityUserRepository
{
Task<IQueryable<OrganizationUnit>> GetOrganizationUnitsQueryableAsync(Guid id, bool includeDetails = false);
Task<IQueryable<IdentityUser>> GetOrganizationUnitUsersAsync(
Guid id, string keyword, string[] type,
bool includeDetails = false);
Task<IQueryable<IdentityUser>> GetUsersWithoutOrganizationAsync(string keyword, string[] type);
}
为OrganizationUnitAppService 以及 RelationAppService 创建MVC控制器 。
完整的 OrganizationUnitController 代码如下:
namespace Matoapp.Identity.OrganizationUnit
{
[Area(IdentityRemoteServiceConsts.ModuleName)]
[RemoteService(Name = IdentityRemoteServiceConsts.RemoteServiceName)]
[Route("api/identity/organizationUnit")]
public class OrganizationUnitController : IdentityController, IOrganizationUnitAppService
{
private readonly IOrganizationUnitAppService _organizationUnitAppService;
public OrganizationUnitController(IOrganizationUnitAppService organizationUnitAppService)
{
_organizationUnitAppService = organizationUnitAppService;
}
[HttpPost]
[Route("AddToOrganizationUnit")]
public async Task AddToOrganizationUnitAsync(UserToOrganizationUnitInput input)
{
await _organizationUnitAppService.AddToOrganizationUnitAsync(input);
}
[HttpPost]
[Route("Create")]
public async Task<OrganizationUnitDto> CreateAsync(CreateOrganizationUnitInput input)
{
return await _organizationUnitAppService.CreateAsync(input);
}
[HttpDelete]
[Route("Delete")]
public async Task DeleteAsync(Guid id)
{
await _organizationUnitAppService.DeleteAsync(id);
}
[HttpGet]
[Route("Get")]
public async Task<OrganizationUnitDto> GetAsync(Guid id)
{
return await _organizationUnitAppService.GetAsync(id);
}
[HttpGet]
[Route("GetCurrentOrganizationUnits")]
public async Task<List<OrganizationUnitDto>> GetCurrentOrganizationUnitsAsync()
{
return await _organizationUnitAppService.GetCurrentOrganizationUnitsAsync();
}
[HttpGet]
[Route("GetOrganizationUnitUsers")]
public async Task<List<IdentityUserDto>> GetOrganizationUnitUsersAsync(GetOrganizationUnitUsersInput input)
{
return await _organizationUnitAppService.GetOrganizationUnitUsersAsync(input);
}
[HttpGet]
[Route("GetOrganizationUnitUsersByPage")]
public async Task<PagedResultDto<IdentityUserDto>> GetOrganizationUnitUsersByPageAsync(GetOrganizationUnitUsersInput input)
{
return await _organizationUnitAppService.GetOrganizationUnitUsersByPageAsync(input);
}
[HttpGet]
[Route("GetRootOrganizationUnit")]
public async Task<OrganizationUnitDto> GetRootOrganizationUnitAsync(Guid id)
{
return await _organizationUnitAppService.GetRootOrganizationUnitAsync(id);
}
[HttpGet]
[Route("GetRootOrganizationUnits")]
public async Task<List<OrganizationUnitDto>> GetRootOrganizationUnitsAsync(IEnumerable<Guid> ids)
{
return await _organizationUnitAppService.GetRootOrganizationUnitsAsync(ids);
}
[HttpGet]
[Route("GetRootOrganizationUnitByDisplayName")]
public async Task<OrganizationUnitDto> GetRootOrganizationUnitByDisplayNameAsync(GetRootOrganizationUnitByDisplayName input)
{
return await _organizationUnitAppService.GetRootOrganizationUnitByDisplayNameAsync(input);
}
[HttpGet]
[Route("GetRootOrganizationUnitsByParent")]
public async Task<List<OrganizationUnitDto>> GetRootOrganizationUnitsByParentAsync(GetRootOrganizationUnitsByParentInput input)
{
return await _organizationUnitAppService.GetRootOrganizationUnitsByParentAsync(input);
}
[HttpGet]
[Route("GetUsersWithoutOrganization")]
public async Task<List<IdentityUserDto>> GetUsersWithoutOrganizationAsync(GetUserWithoutOrganizationInput input)
{
return await _organizationUnitAppService.GetUsersWithoutOrganizationAsync(input);
}
[HttpGet]
[Route("GetUsersWithoutOrganizationByPage")]
public async Task<PagedResultDto<IdentityUserDto>> GetUsersWithoutOrganizationByPageAsync(GetUserWithoutOrganizationInput input)
{
return await _organizationUnitAppService.GetUsersWithoutOrganizationByPageAsync(input);
}
[HttpGet]
[Route("IsInOrganizationUnit")]
public async Task<bool> IsInOrganizationUnitAsync(UserToOrganizationUnitInput input)
{
return await _organizationUnitAppService.IsInOrganizationUnitAsync(input);
}
[HttpPost]
[Route("MoveOrganizationUnit")]
public async Task MoveOrganizationUnitAsync(MoveOrganizationUnitInput input)
{
await _organizationUnitAppService.MoveOrganizationUnitAsync(input);
}
[HttpPost]
[Route("RemoveUserFromOrganizationUnit")]
public async Task RemoveUserFromOrganizationUnitAsync(UserToOrganizationUnitInput input)
{
await _organizationUnitAppService.RemoveUserFromOrganizationUnitAsync(input);
}
[HttpPut]
[Route("Update")]
public async Task<OrganizationUnitDto> UpdateAsync(UpdateOrganizationUnitInput input)
{
return await _organizationUnitAppService.UpdateAsync(input);
}
}
完整的 RelationController 代码如下:
[Area(IdentityRemoteServiceConsts.ModuleName)]
[RemoteService(Name = IdentityRemoteServiceConsts.RemoteServiceName)]
[Route("api/identity/relation")]
public class RelationController : IdentityController, IRelationAppService
{
private readonly IRelationAppService _relationAppService;
public RelationController(IRelationAppService relationAppService)
{
_relationAppService = relationAppService;
}
[HttpDelete]
[Route("ClearAllRelatedFromUsers")]
public async Task ClearAllRelatedFromUsersAsync(GetRelatedUsersInput input)
{
await _relationAppService.ClearAllRelatedFromUsersAsync(input);
}
[HttpDelete]
[Route("ClearAllRelatedToUsers")]
public async Task ClearAllRelatedToUsersAsync(GetRelatedUsersInput input)
{
await _relationAppService.ClearAllRelatedToUsersAsync(input);
}
[HttpPost]
[Route("Create")]
public async Task<RelationDto> CreateAsync(ModifyRelationInput input)
{
return await _relationAppService.CreateAsync(input);
}
[HttpDelete]
[Route("Delete")]
public async Task DeleteAsync(EntityDto<long> input)
{
await _relationAppService.DeleteAsync(input);
}
[HttpDelete]
[Route("DeleteByUserId")]
public async Task DeleteByUserIdAsync(ModifyRelationInput input)
{
await _relationAppService.DeleteByUserIdAsync(input);
}
[HttpGet]
[Route("GetRelatedFromUsers")]
public async Task<List<IdentityUserDto>> GetRelatedFromUsersAsync(GetRelatedUsersInput input)
{
return await _relationAppService.GetRelatedFromUsersAsync(input);
}
[HttpGet]
[Route("GetRelatedToUsers")]
public async Task<List<IdentityUserDto>> GetRelatedToUsersAsync(GetRelatedUsersInput input)
{
return await _relationAppService.GetRelatedToUsersAsync(input);
}
[HttpGet]
[Route("GetRelatedToUserIds")]
public async Task<List<Guid>> GetRelatedToUserIdsAsync(GetRelatedUsersInput input)
{
return await _relationAppService.GetRelatedToUserIdsAsync(input);
}
[HttpGet]
[Route("GetRelatedFromUserIds")]
public async Task<List<Guid>> GetRelatedFromUserIdsAsync(GetRelatedUsersInput input)
{
return await _relationAppService.GetRelatedFromUserIdsAsync(input);
}
}
上一章节我们已经将三个模组的依赖添加到MatoappHttpApiModule中,直接启动HttpApi.Host就可以访问接口了.
[DependsOn(
...
typeof(CommonHttpApiModule),
typeof(HealthHttpApiModule),
typeof(IdentityHttpApiModule)
)]
public class MatoappHttpApiModule : AbpModule
Relation相关接口:
OrganizationUnit相关接口:
下一章节将介绍如何利用Identity模块为用户的查询提供组织架构和用户关系的条件过滤.
最后此篇关于怎样优雅地增删查改(二):扩展身份管理模块的文章就讲到这里了,如果你想了解更多关于怎样优雅地增删查改(二):扩展身份管理模块的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
您如何优雅编码同一tableView中的两种类型的单元格? 显然我可以这样: NSDictionary *cellInfo = [_userInformation objectAtIndex:inde
假设我正在编写一个仅包含标题或主要包含标题的库,并且具有以下代码: using my_type = int; namespace detail { inline void foo() { my
我正在使用复选框和输入进行一系列启用/禁用选择,我想知道我是否可以使用循环、变量或复合语句来简单地处理这个js?感觉就像是使用大量代码来实现相对简单的功能。 这是我正在做的事情的一个 fiddle :
我正在尝试为来自维基百科的 API 响应编写一个解析器。它真的很困惑,我已经求助于旧的 RegEx 来清理大部分东西。然而,我坚持这一点。考虑一个字符串: var a ="[[December 1]
我正在通过一个 channel 接收多个消息,并在对其进行迭代之后,我想保留最后一个元素以供进一步使用。我的第一个(可能很糟糕!)方法是声明一些变量,然后在每个循环中分配它。 let last = 0
我正在编写一个 PHP Web 应用程序,它将在不久的将来在生产环境下运行,而不是使用非用户友好的 die() , 我想我会想出一个 Class处理错误消息。 基本上,我的思考过程是这样的: 如果 W
我们有 elb 负载平衡 2 台运行 tomcat 作为应用程序服务器的 WAS 机器。要实现AWS环境下的不间断部署,我们应该, 选择部署目标 WAS。 让它停止来自 elb 的交易。(elb 暂停
何为pythonic? pythonic如果翻译成中文的话就是很python。很+名词结构的用法在中国不少,比如:很娘,很国足,很CCTV等等。 我的理解为,很+名词表达了一种特殊和强调的意味。
认为已经有对此的答案,但找不到。我一直在以某种方式解析方法选项,并想检查并确保它是最优雅/最简洁的方式。 这是我通常做的: def some_method *args options = args
我正在清理我的一个旧项目。它必须做的一件事是——给定笛卡尔网格系统和网格上的两个正方形,找到所有正方形的列表,连接这两个正方形中心的线将通过这些正方形。 这里的特殊情况是所有起点和终点都被限制在正方形
如何使系统 ( SystemB1 ) 访问另一个系统 ( SystemA::sub ) 的字段,就好像它是自己的字段一样? SystemA是一个拥有自己领域的实用系统 Sub* sub . Syste
我有一个包含约 8.000.000 条记录的 MySQL 数据库。因为我需要处理所有这些,所以我使用 BlockingQueue 作为生产者从数据库读取数据并将 1000 条记录放入队列中。 Cons
我正在让我的 HTTP 服务器正常关闭。我从帖子中获取了提示 here ,到目前为止,我的代码是这样设置的: func start() { //...... //START HTTP/
示例脚本只是“wc -m”命令的包装器,简单的符号计数器。我尝试只用“teststrings” slice 元素提供输入。并在输出监听器 goroutine 接收每个字符串的符号数。寻找一种让“wc”
我想干净/优雅地关闭 Internet Explorer。 taskkill 会关闭它,但是当重新打开它时,它会询问您是否要重新打开上一个 session 。 最佳答案 尝试 CloseMainWin
Haskell 的简洁和优雅给我留下了深刻的印象。但我在 .Net 公司工作,所以当我可以使用 F# 时我会使用它——我可能是全国数百个使用它的人中唯一的一个。 ADO.NET 或 F# 是否提供像
如果我们不想在我们的类中实现 init 方法,并且记住 NSObject 中的 init 只返回一个没有初始化的对象实例,如果我们已经得到了,我不明白调用 init 的意义带有分配的实例。我已经尝试过
我们的组织中有许多初级 Delphi 开发人员,作为向他们教授 Delphi 过程的一部分,我希望他们能够看到“干净”、编写良好、设计良好的 Delphi 代码。 我要寻找的一些标准包括: 优秀的类(
我有一个 3D 图像扫描(形状:335x306x306,总元素:31368060),我想用相同大小的 3D bool 掩码来掩盖它以返回相同大小的蒙版图像。 当我简单地用掩码索引数组时: masked
如何使适配器类适本地支持 const 和非 const 底层数据? 具体例子 RigidBody是描述对象物理属性的类。 这是其非常简化的版本(1D):- class RigidBody{ f
我是一名优秀的程序员,十分优秀!