From 355ca45e68ea03f54872c587c56ef51ab68a58f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E4=BB=99=E9=83=BD=E6=B2=A1=E7=94=A8?= <615206459@qq.com> Date: Fri, 7 Feb 2025 17:15:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20roleIds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/base/service/sys/user.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/modules/base/service/sys/user.ts b/src/modules/base/service/sys/user.ts index 2e1583e..a242b02 100644 --- a/src/modules/base/service/sys/user.ts +++ b/src/modules/base/service/sys/user.ts @@ -9,6 +9,7 @@ import { BaseSysUserRoleEntity } from '../../entity/sys/user_role'; import * as md5 from 'md5'; import { BaseSysDepartmentEntity } from '../../entity/sys/department'; 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)) { 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 (?) ', [userIds] ); result.list.forEach(e => { - e['roleName'] = roles - .filter(role => role.userId == e.id) - .map(role => role.name) - .join(','); + const arr = roles.filter(a => a.userId == e.id); + + e['roleIds'] = arr.map(a => a.userId); + e['roleName'] = arr.map(a => a.name).join(','); }); } return result;