- 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的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我最近在我的机器上安装了 cx_Oracle 模块,以便连接到远程 Oracle 数据库服务器。 (我身边没有 Oracle 客户端)。 Python:版本 2.7 x86 Oracle:版本 11.
我想从 python timeit 模块检查打印以下内容需要多少时间,如何打印, import timeit x = [x for x in range(10000)] timeit.timeit("
我盯着 vs 代码编辑器上的 java 脚本编码,当我尝试将外部模块包含到我的项目中时,代码编辑器提出了这样的建议 -->(文件是 CommonJS 模块;它可能会转换为 ES6 模块。 )..有什么
我有一个 Node 应用程序,我想在标准 ES6 模块格式中使用(即 "type": "module" in the package.json ,并始终使用 import 和 export)而不转译为
我正在学习将 BlueprintJS 合并到我的 React 网络应用程序中,并且在加载某些 CSS 模块时遇到了很多麻烦。 我已经安装了 npm install @blueprintjs/core和
我需要重构一堆具有这样的调用的文件 define(['module1','module2','module3' etc...], function(a, b, c etc...) { //bun
我是 Angular 的新手,正在学习各种教程(Codecademy、thinkster.io 等),并且已经看到了声明应用程序容器的两种方法。首先: var app = angular.module
我正在尝试将 OUnit 与 OCaml 一起使用。 单元代码源码(unit.ml)如下: open OUnit let empty_list = [] let list_a = [1;2;3] le
我在 Angular 1.x 应用程序中使用 webpack 和 ES6 模块。在我设置的 webpack.config 中: resolve: { alias: { 'angular':
internal/modules/cjs/loader.js:750 return process.dlopen(module, path.toNamespacedPath(filename));
在本教程中,您将借助示例了解 JavaScript 中的模块。 随着我们的程序变得越来越大,它可能包含许多行代码。您可以使用模块根据功能将代码分隔在单独的文件中,而不是将所有内容都放在一个文件
我想知道是否可以将此代码更改为仅调用 MyModule.RED 而不是 MyModule.COLORS.RED。我尝试将 mod 设置为变量来存储颜色,但似乎不起作用。难道是我方法不对? (funct
我有以下代码。它是一个 JavaScript 模块。 (function() { // Object var Cahootsy; Cahootsy = { hello:
关闭。这个问题是 opinion-based 。它目前不接受答案。 想要改进这个问题?更新问题,以便 editing this post 可以用事实和引文来回答它。 关闭 2 年前。 Improve
从用户的角度来看,一个模块能够通过 require 加载并返回一个 table,模块导出的接口都被定义在此 table 中(此 table 被作为一个 namespace)。所有的标准库都是模块。标
Ruby的模块非常类似类,除了: 模块不可以有实体 模块不可以有子类 模块由module...end定义. 实际上...模块的'模块类'是'类的类'这个类的父类.搞懂了吗?不懂?让我们继续看
我有一个脚本,它从 CLI 获取 3 个输入变量并将其分别插入到 3 个变量: GetOptions("old_path=s" => \$old_path, "var=s" =
我有一个简单的 python 包,其目录结构如下: wibble | |-----foo | |----ping.py | |-----bar | |----pong.py 简单的
这种语法会非常有用——这不起作用有什么原因吗?谢谢! module Foo = { let bar: string = "bar" }; let bar = Foo.bar; /* works *
我想运行一个命令: - name: install pip shell: "python {"changed": true, "cmd": "python <(curl https://boot
我是一名优秀的程序员,十分优秀!