From 41a7689b629b3161298de2f9c6127bc5379e768f Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Wed, 14 Sep 2022 16:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=A7=93=E5=90=8D=E3=80=81?= =?UTF-8?q?=E9=83=A8=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/organization/index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/api/app/lib/controllers/organization/index.js b/api/app/lib/controllers/organization/index.js index d246b15..ddeeae0 100644 --- a/api/app/lib/controllers/organization/index.js +++ b/api/app/lib/controllers/organization/index.js @@ -189,13 +189,17 @@ async function user (ctx) { order: [['updateTime', 'DESC']] }) - // let userIds = new Set() - // for (let u of userRes.rows.concat(adminRes)) { - // userIds.add(u.pepUserId) - // } - // let userPepRes = await clickHouse.pepEmis.query(`SELECT "user"."name" FROM department_user LEFT JOIN user ON department_user.user=user.id `).toPromise() + let userIds = new Set() + for (let u of userRes.rows.concat(adminRes)) { + userIds.add(u.pepUserId) + } + let userPepRes = await clickHouse.pepEmis.query(`SELECT user.id AS id, "user"."name" AS name, department.name AS depName FROM department_user LEFT JOIN user ON department_user.user=user.id LEFT JOIN department ON department.id=department_user.department WHERE user.id IN (${[...userIds].join(',')})`).toPromise() - // const userDepRes = await clickHouse.pepEmis.query(`SELECT * FROM department`).toPromise() + for (let u of userRes.rows.concat(adminRes)) { + const corUsers = userPepRes.filter(up => up.id == u.pepUserId) + u.dataValues.name = corUsers[0].name + u.dataValues.departments = corUsers.map(cu => cu.depName) + } ctx.status = 200 ctx.body = {