mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-10 16:12:50 +00:00
可以看到自己创建的
This commit is contained in:
parent
68f8b7202f
commit
21d928167e
@ -11,6 +11,11 @@ import { BaseSysDepartmentService } from '../../../service/sys/department';
|
||||
api: ['add', 'delete', 'update', 'list'],
|
||||
entity: BaseSysDepartmentEntity,
|
||||
service: BaseSysDepartmentService,
|
||||
insertParam: ctx => {
|
||||
return {
|
||||
userId: ctx.admin.userId,
|
||||
};
|
||||
},
|
||||
})
|
||||
export class BaseDepartmentController extends BaseController {
|
||||
@Inject()
|
||||
|
||||
@ -11,6 +11,11 @@ import { BaseSysUserService } from '../../../service/sys/user';
|
||||
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
|
||||
entity: BaseSysUserEntity,
|
||||
service: BaseSysUserService,
|
||||
insertParam: ctx => {
|
||||
return {
|
||||
userId: ctx.admin.userId,
|
||||
};
|
||||
},
|
||||
})
|
||||
export class BaseSysUserController extends BaseController {
|
||||
@Inject()
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { BaseEntity } from '../base';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { Column, Entity, Index } from 'typeorm';
|
||||
|
||||
/**
|
||||
* 部门
|
||||
@ -9,6 +9,10 @@ export class BaseSysDepartmentEntity extends BaseEntity {
|
||||
@Column({ comment: '部门名称' })
|
||||
name: string;
|
||||
|
||||
@Index()
|
||||
@Column({ comment: '创建者ID', nullable: true })
|
||||
userId: number;
|
||||
|
||||
@Column({ comment: '上级部门ID', nullable: true })
|
||||
parentId: number;
|
||||
|
||||
|
||||
@ -10,6 +10,10 @@ export class BaseSysUserEntity extends BaseEntity {
|
||||
@Column({ comment: '部门ID', nullable: true })
|
||||
departmentId: number;
|
||||
|
||||
@Index()
|
||||
@Column({ comment: '创建者ID', nullable: true })
|
||||
userId: number;
|
||||
|
||||
@Column({ comment: '姓名', nullable: true })
|
||||
name: string;
|
||||
|
||||
|
||||
@ -39,10 +39,12 @@ export class BaseSysDepartmentService extends BaseService {
|
||||
|
||||
// 过滤部门权限
|
||||
const find = this.baseSysDepartmentEntity.createQueryBuilder('a');
|
||||
if (this.ctx.admin.username !== 'admin')
|
||||
if (this.ctx.admin.username !== 'admin') {
|
||||
find.andWhere('a.id in (:...ids)', {
|
||||
ids: !_.isEmpty(permsDepartmentArr) ? permsDepartmentArr : [null],
|
||||
});
|
||||
find.orWhere('a.userId = :userId', { userId: this.ctx.admin.userId });
|
||||
}
|
||||
find.addOrderBy('a.orderNum', 'ASC');
|
||||
const departments: BaseSysDepartmentEntity[] = await find.getMany();
|
||||
|
||||
|
||||
@ -40,8 +40,9 @@ export class BaseSysUserService extends BaseService {
|
||||
*/
|
||||
async page(query) {
|
||||
const { keyWord, status, departmentIds = [] } = query;
|
||||
const userId = this.ctx.admin.userId;
|
||||
const permsDepartmentArr = await this.baseSysPermsService.departmentIds(
|
||||
this.ctx.admin.userId
|
||||
userId
|
||||
); // 部门权限
|
||||
const sql = `
|
||||
SELECT
|
||||
@ -64,7 +65,7 @@ export class BaseSysUserService extends BaseService {
|
||||
${this.setSql(true, 'and a.username != ?', ['admin'])}
|
||||
${this.setSql(
|
||||
this.ctx.admin.username !== 'admin',
|
||||
'and a.departmentId in (?)',
|
||||
`and (a.departmentId in (?) or a.userId = ${userId})`,
|
||||
[!_.isEmpty(permsDepartmentArr) ? permsDepartmentArr : [null]]
|
||||
)} `;
|
||||
const result = await this.sqlRenderPage(sql, query);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user