mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-12 09:32:49 +00:00
添加 roleIds
This commit is contained in:
parent
b8b40b4bf2
commit
355ca45e68
@ -9,6 +9,7 @@ import { BaseSysUserRoleEntity } from '../../entity/sys/user_role';
|
|||||||
import * as md5 from 'md5';
|
import * as md5 from 'md5';
|
||||||
import { BaseSysDepartmentEntity } from '../../entity/sys/department';
|
import { BaseSysDepartmentEntity } from '../../entity/sys/department';
|
||||||
import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager';
|
import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager';
|
||||||
|
import { BaseSysRoleEntity } from '../../entity/sys/role';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户
|
* 系统用户
|
||||||
@ -70,15 +71,15 @@ export class BaseSysUserService extends BaseService {
|
|||||||
// 匹配角色
|
// 匹配角色
|
||||||
if (!_.isEmpty(result.list)) {
|
if (!_.isEmpty(result.list)) {
|
||||||
const userIds = result.list.map(e => e.id);
|
const userIds = result.list.map(e => e.id);
|
||||||
const roles = await this.nativeQuery(
|
const roles: BaseSysRoleEntity[] = await this.nativeQuery(
|
||||||
'SELECT b.name, a.userId FROM base_sys_user_role a LEFT JOIN base_sys_role b ON a.roleId = b.id WHERE a.userId in (?) ',
|
'SELECT b.name, a.userId FROM base_sys_user_role a LEFT JOIN base_sys_role b ON a.roleId = b.id WHERE a.userId in (?) ',
|
||||||
[userIds]
|
[userIds]
|
||||||
);
|
);
|
||||||
result.list.forEach(e => {
|
result.list.forEach(e => {
|
||||||
e['roleName'] = roles
|
const arr = roles.filter(a => a.userId == e.id);
|
||||||
.filter(role => role.userId == e.id)
|
|
||||||
.map(role => role.name)
|
e['roleIds'] = arr.map(a => a.userId);
|
||||||
.join(',');
|
e['roleName'] = arr.map(a => a.name).join(',');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user