Browse Source

add the organization structure API

pull/49/head
cKey 5 years ago
parent
commit
4ffbd5fe2b
  1. 7
      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. 28
      vueJs/src/views/admin/organization-unit/components/EditOrganizationUint.vue

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

@ -49,8 +49,11 @@ namespace LINGYUN.Abp.Account
var wehchatOpenId = await WeChatOpenIdFinder.FindAsync(input.Code);
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";//如果邮件地址不验证,随意写入一个
@ -64,7 +67,7 @@ namespace LINGYUN.Abp.Account
var userLogin = new UserLoginInfo("WeChat", wehchatOpenId.OpenId, "微信认证登录");
(await UserManager.AddLoginAsync(user, userLogin)).CheckErrors();
}
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
}
/// <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<ListResultDto<OrganizationUnitDto>> GetRootAsync();
Task<ListResultDto<OrganizationUnitDto>> FindChildrenAsync(OrganizationUnitGetChildrenDto 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);
}
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)
{
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);
}
[HttpGet]
[Route("root-node")]
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetRootAsync()
{
return await OrganizationUnitAppService.GetRootAsync();
}
[HttpGet]
[Route("last-children")]
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)
}
/**
*
* @returns OrganizationUnit
*/
public static getRootOrganizationUnits() {
const _url = '/api/identity/organization-units/root-node'
return ApiService.Get<PagedResultDto<OrganizationUnit>>(_url, serviceUrl)
}
/**
*
* @param payload

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

@ -48,7 +48,8 @@
<script lang="ts">
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 {
id?: string
@ -86,25 +87,17 @@ export default class extends Vue {
rootOrganizationUnit.displayName = '组织机构'
return resolve([rootOrganizationUnit])
}
let organizationUnitItems = new ListResultDto<OrganizationUnit>()
if (node.data.id === undefined) {
const result = await OrganizationUnitService.findOrganizationUnitLastChildren(node.data.id)
if (result) {
const organizationUnit = new OrganizationUnitTree()
organizationUnit.id = result.id
organizationUnit.parentId = result.parentId
organizationUnit.code = result.code
organizationUnit.displayName = result.displayName
const children = node.data.children as OrganizationUnitTree[]
if (!children.every(x => x.id === result.id)) {
children.push(organizationUnit)
}
return resolve([organizationUnit])
}
//
organizationUnitItems = await OrganizationUnitService.getRootOrganizationUnits()
} else {
const result = await OrganizationUnitService.findOrganizationUnitChildren(node.data.id, undefined)
if (result.items.length !== 0) {
//
organizationUnitItems = await OrganizationUnitService.findOrganizationUnitChildren(node.data.id, undefined)
}
if (organizationUnitItems.items.length !== 0) {
const organizationUnits = new Array<OrganizationUnitTree>()
result.items.map((item) => {
organizationUnitItems.items.map((item) => {
const organizationUnit = new OrganizationUnitTree()
organizationUnit.id = item.id
organizationUnit.parentId = item.parentId
@ -118,7 +111,6 @@ export default class extends Vue {
})
return resolve(organizationUnits)
}
}
return resolve([])
}

Loading…
Cancel
Save