Browse Source

add the organization structure API

pull/49/head
cKey 5 years ago
parent
commit
4ffbd5fe2b
  1. 27
      aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs
  2. 2
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IOrganizationUnitAppService.cs
  3. 8
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs
  4. 7
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/OrganizationUnitController.cs
  5. 9
      vueJs/src/api/organizationunit.ts
  6. 48
      vueJs/src/views/admin/organization-unit/components/EditOrganizationUint.vue

27
aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs

@ -49,22 +49,25 @@ namespace LINGYUN.Abp.Account
var wehchatOpenId = await WeChatOpenIdFinder.FindAsync(input.Code); var wehchatOpenId = await WeChatOpenIdFinder.FindAsync(input.Code);
var user = await UserManager.FindByLoginAsync("WeChat", wehchatOpenId.OpenId); var user = await UserManager.FindByLoginAsync("WeChat", wehchatOpenId.OpenId);
if (user == null) if (user != null)
{
// 应该要抛出微信号已注册异常,而不是直接返回注册用户数据,否则造成用户信息泄露
throw new UserFriendlyException(L["DuplicateWeChat"]);
}
var userName = input.UserName ?? wehchatOpenId.OpenId;
var userEmail = input.EmailAddress ?? $"{userName}@{new Random().Next(1000, 99999)}.com";//如果邮件地址不验证,随意写入一个
user = new IdentityUser(GuidGenerator.Create(), userName, userEmail, CurrentTenant.Id)
{ {
var userName = input.UserName ?? wehchatOpenId.OpenId; Name = input.Name ?? userName
var userEmail = input.EmailAddress ?? $"{userName}@{new Random().Next(1000, 99999)}.com";//如果邮件地址不验证,随意写入一个 };
(await UserManager.CreateAsync(user, input.Password)).CheckErrors();
user = new IdentityUser(GuidGenerator.Create(), userName, userEmail, CurrentTenant.Id) (await UserManager.AddDefaultRolesAsync(user)).CheckErrors();
{
Name = input.Name ?? userName
};
(await UserManager.CreateAsync(user, input.Password)).CheckErrors();
(await UserManager.AddDefaultRolesAsync(user)).CheckErrors(); var userLogin = new UserLoginInfo("WeChat", wehchatOpenId.OpenId, "微信认证登录");
(await UserManager.AddLoginAsync(user, userLogin)).CheckErrors();
var userLogin = new UserLoginInfo("WeChat", wehchatOpenId.OpenId, "微信认证登录");
(await UserManager.AddLoginAsync(user, userLogin)).CheckErrors();
}
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
} }
/// <summary> /// <summary>

2
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IOrganizationUnitAppService.cs

@ -18,6 +18,8 @@ namespace LINGYUN.Abp.Identity
Task MoveAsync(Guid id, OrganizationUnitMoveDto input); Task MoveAsync(Guid id, OrganizationUnitMoveDto input);
Task<ListResultDto<OrganizationUnitDto>> GetRootAsync();
Task<ListResultDto<OrganizationUnitDto>> FindChildrenAsync(OrganizationUnitGetChildrenDto input); Task<ListResultDto<OrganizationUnitDto>> FindChildrenAsync(OrganizationUnitGetChildrenDto input);
Task<PagedResultDto<IdentityRoleDto>> GetRolesAsync(OrganizationUnitGetRoleByPagedDto input); Task<PagedResultDto<IdentityRoleDto>> GetRolesAsync(OrganizationUnitGetRoleByPagedDto input);

8
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs

@ -58,6 +58,14 @@ namespace LINGYUN.Abp.Identity
await OrganizationUnitManager.DeleteAsync(id); await OrganizationUnitManager.DeleteAsync(id);
} }
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetRootAsync()
{
var rootOriganizationUnits = await OrganizationUnitManager.FindChildrenAsync(null, recursive: false);
return new ListResultDto<OrganizationUnitDto>(
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(rootOriganizationUnits));
}
public virtual async Task<ListResultDto<OrganizationUnitDto>> FindChildrenAsync(OrganizationUnitGetChildrenDto input) public virtual async Task<ListResultDto<OrganizationUnitDto>> FindChildrenAsync(OrganizationUnitGetChildrenDto input)
{ {
var origanizationUnitChildren = await OrganizationUnitManager.FindChildrenAsync(input.Id, input.Recursive); var origanizationUnitChildren = await OrganizationUnitManager.FindChildrenAsync(input.Id, input.Recursive);

7
aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/OrganizationUnitController.cs

@ -64,6 +64,13 @@ namespace LINGYUN.Abp.Identity
return await OrganizationUnitAppService.GetAsync(id); return await OrganizationUnitAppService.GetAsync(id);
} }
[HttpGet]
[Route("root-node")]
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetRootAsync()
{
return await OrganizationUnitAppService.GetRootAsync();
}
[HttpGet] [HttpGet]
[Route("last-children")] [Route("last-children")]
public virtual async Task<OrganizationUnitDto> GetLastChildOrNullAsync(Guid? parentId) public virtual async Task<OrganizationUnitDto> GetLastChildOrNullAsync(Guid? parentId)

9
vueJs/src/api/organizationunit.ts

@ -18,6 +18,15 @@ export default class OrganizationUnitService {
return ApiService.Post<OrganizationUnit>(_url, payload, serviceUrl) return ApiService.Post<OrganizationUnit>(_url, payload, serviceUrl)
} }
/**
*
* @returns OrganizationUnit
*/
public static getRootOrganizationUnits() {
const _url = '/api/identity/organization-units/root-node'
return ApiService.Get<PagedResultDto<OrganizationUnit>>(_url, serviceUrl)
}
/** /**
* *
* @param payload * @param payload

48
vueJs/src/views/admin/organization-unit/components/EditOrganizationUint.vue

@ -48,7 +48,8 @@
<script lang="ts"> <script lang="ts">
import { Component, Vue } from 'vue-property-decorator' import { Component, Vue } from 'vue-property-decorator'
import OrganizationUnitService, { OrganizationUnitCreate } from '@/api/organizationunit' import { ListResultDto } from '@/api/types'
import OrganizationUnitService, { OrganizationUnitCreate, OrganizationUnit } from '@/api/organizationunit'
class OrganizationUnitTree { class OrganizationUnitTree {
id?: string id?: string
@ -86,38 +87,29 @@ export default class extends Vue {
rootOrganizationUnit.displayName = '组织机构' rootOrganizationUnit.displayName = '组织机构'
return resolve([rootOrganizationUnit]) return resolve([rootOrganizationUnit])
} }
let organizationUnitItems = new ListResultDto<OrganizationUnit>()
if (node.data.id === undefined) { if (node.data.id === undefined) {
const result = await OrganizationUnitService.findOrganizationUnitLastChildren(node.data.id) //
if (result) { organizationUnitItems = await OrganizationUnitService.getRootOrganizationUnits()
} else {
//
organizationUnitItems = await OrganizationUnitService.findOrganizationUnitChildren(node.data.id, undefined)
}
if (organizationUnitItems.items.length !== 0) {
const organizationUnits = new Array<OrganizationUnitTree>()
organizationUnitItems.items.map((item) => {
const organizationUnit = new OrganizationUnitTree() const organizationUnit = new OrganizationUnitTree()
organizationUnit.id = result.id organizationUnit.id = item.id
organizationUnit.parentId = result.parentId organizationUnit.parentId = item.parentId
organizationUnit.code = result.code organizationUnit.code = item.code
organizationUnit.displayName = result.displayName organizationUnit.displayName = item.displayName
organizationUnits.push(organizationUnit)
const children = node.data.children as OrganizationUnitTree[] const children = node.data.children as OrganizationUnitTree[]
if (!children.every(x => x.id === result.id)) { if (!children.every(x => x.id === item.id)) {
children.push(organizationUnit) children.push(organizationUnit)
} }
return resolve([organizationUnit]) })
} return resolve(organizationUnits)
} else {
const result = await OrganizationUnitService.findOrganizationUnitChildren(node.data.id, undefined)
if (result.items.length !== 0) {
const organizationUnits = new Array<OrganizationUnitTree>()
result.items.map((item) => {
const organizationUnit = new OrganizationUnitTree()
organizationUnit.id = item.id
organizationUnit.parentId = item.parentId
organizationUnit.code = item.code
organizationUnit.displayName = item.displayName
organizationUnits.push(organizationUnit)
const children = node.data.children as OrganizationUnitTree[]
if (!children.every(x => x.id === item.id)) {
children.push(organizationUnit)
}
})
return resolve(organizationUnits)
}
} }
return resolve([]) return resolve([])
} }

Loading…
Cancel
Save