@@ -12,6 +12,7 @@ import { QueryDepartmentDto } from './dto/department.query';
1212import { PageEnum , StatusEnum } from '@src/enums' ;
1313import { mapToObj } from '@src/utils' ;
1414import { AccountTypeEnum } from '@src/enums/account.type.enum' ;
15+ import { AccountEntity } from '../account/entities/account.entity' ;
1516
1617@Injectable ( )
1718export class DepartmentService {
@@ -32,14 +33,14 @@ export class DepartmentService {
3233 async createDepartmentApi ( req : DepartmentDto , currentUser : ICurrentUserType ) : Promise < string > {
3334 // 1.判断部门存在吗
3435 const { tenantId } = currentUser ;
35- const departmentEntity : Pick < DepartmentEntity , 'id' > | null =
36- await this . departmentRepository . findOne ( {
37- where : { tenantId, title : req . title } ,
38- select : [ 'id' ] ,
39- } ) ;
40- if ( departmentEntity ?. id ) {
41- throw new HttpException ( `${ req . title } 已经存在` , HttpStatusCode . Ok ) ;
42- }
36+ // const departmentEntity: Pick<DepartmentEntity, 'id'> | null =
37+ // await this.departmentRepository.findOne({
38+ // where: { tenantId, title: req.title },
39+ // select: ['id'],
40+ // });
41+ // if (departmentEntity?.id) {
42+ // throw new HttpException(`${req.title}已经存在`, HttpStatusCode.Ok);
43+ // }
4344 const data = this . departmentRepository . create ( { ...req , tenantId } ) ;
4445 await this . departmentRepository . save ( data ) ;
4546 return '创建成功' ;
@@ -290,9 +291,9 @@ export class DepartmentService {
290291 . createQueryBuilder ( 'department' )
291292 . select ( 'department.id' , 'id' )
292293 . addSelect ( 'department.title' , 'title' )
293- . addSelect ( 'department.name' , 'name' )
294294 . addSelect ( 'department.mobile' , 'mobile' )
295295 . addSelect ( 'department.email' , 'email' )
296+ . addSelect ( 'department.accountId' , 'accountId' )
296297 . addSelect ( 'department.tenantId' , 'tenantId' )
297298 . addSelect ( 'department.parentId' , 'parentId' )
298299 . addSelect ( 'department.sort' , 'sort' )
@@ -318,6 +319,16 @@ export class DepartmentService {
318319 . from ( TenantEntity , 'tenant' ) ,
319320 'tenant' ,
320321 'department.tenantId=tenant.tenantId'
322+ )
323+ . leftJoinAndMapOne (
324+ 'xx' ,
325+ ( qb ) =>
326+ qb
327+ . select ( 'account.id' , 'accountId' )
328+ . addSelect ( 'account.username' , 'name' )
329+ . from ( AccountEntity , 'account' ) ,
330+ 'account' ,
331+ 'department.accountId=account.accountId'
321332 ) ;
322333 }
323334}
0 commit comments