Skip to content

Commit d4437ae

Browse files
committed
feat: 查询部门
1 parent 68dcc0c commit d4437ae

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/api/account/account.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Module } from '@nestjs/common';
22
import { RouterModule } from '@nestjs/core';
33
import { TypeOrmModule } from '@nestjs/typeorm';
44
import { ADMIN_PREFIX } from '@src/constants';
5+
import { DepartmentEntity } from '../department/entities/department.entity';
56
import { TenantEntity } from '../tenant/entities/tenant.entity';
67
import { AccountController } from './account.controller';
78
import { AccountService } from './account.service';
@@ -15,7 +16,7 @@ import { AccountEntity } from './entities/account.entity';
1516
module: AccountModule,
1617
},
1718
]),
18-
TypeOrmModule.forFeature([AccountEntity, TenantEntity]),
19+
TypeOrmModule.forFeature([AccountEntity, TenantEntity, DepartmentEntity]),
1920
],
2021
controllers: [AccountController],
2122
providers: [AccountService],

src/api/account/account.service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AccountTypeEnum } from '@src/enums/account.type.enum';
1313
import { PageEnum, StatusEnum } from '@src/enums';
1414
import { mapToObj } from '@src/utils';
1515
import { TenantEntity } from '../tenant/entities/tenant.entity';
16+
import { DepartmentEntity } from '../department/entities/department.entity';
1617

1718
@Injectable()
1819
export class AccountService {
@@ -351,6 +352,7 @@ export class AccountService {
351352
.addSelect('account.accountType', 'accountType')
352353
.addSelect('account.tenantId', 'tenantId')
353354
.addSelect('account.parentId', 'parentId')
355+
.addSelect('account.departmentId', 'departmentId')
354356
.addSelect('account.sort', 'sort')
355357
.addSelect('account.status', 'status')
356358
.addSelect('account.lastLoginIp', 'lastLoginIp')
@@ -381,6 +383,16 @@ export class AccountService {
381383
.from(TenantEntity, 'tenant'),
382384
'tenant',
383385
'account.tenantId=tenant.tenantId'
386+
)
387+
.leftJoinAndMapOne(
388+
'xx',
389+
(qb) =>
390+
qb
391+
.select('department.id', 'departmentId')
392+
.addSelect('department.title', 'departmentTitle')
393+
.from(DepartmentEntity, 'department'),
394+
'department',
395+
'account.departmentId=department.departmentId'
384396
);
385397
}
386398
}

src/api/account/vo/account.vo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export class AccountVo extends QueryVo {
88
readonly tenantName!: string; // 关联到tenant表名称
99
readonly parentId!: number; // 自关联主键id
1010
readonly parentName!: number; // 自关联主键id
11+
readonly departmentId!: number; // 关联到部门表主键id
12+
readonly departmentTitle!: string; // 关联到部门表主键id
1113
readonly sort!: number; // 排序
1214
readonly status!: number; // 状态0是正常,1是禁用
1315
readonly lastLoginIp!: string; // 最后登录ip地址

0 commit comments

Comments
 (0)