From 8e2bff56406a46b99d0a0cce5795994afe3cdbf0 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Wed, 21 Sep 2022 15:23:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=83=E7=B4=A0=E9=94=99=E8=AF=AF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=20pepProjectId=20=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/.vscode/launch.json | 2 +- api/app/lib/controllers/alarm/app.js | 4 ++- api/app/lib/controllers/alarm/data.js | 7 ++-- api/app/lib/controllers/organization/index.js | 34 ++++++++++++++++++- api/app/lib/models/user.js | 2 +- api/app/lib/utils/dataRange.js | 24 ++++++++----- script/0.0.1/1.init_tables.sql | 2 +- 7 files changed, 58 insertions(+), 17 deletions(-) diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 02b37cf..2cc7fd3 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -51,7 +51,7 @@ "--clickHousePepEmis pepca8", "--clickHouseProjectManage peppm8", "--clickHouseVcmp video_accrss1", - "--clickHouseDataAlarm default123", + "--clickHouseDataAlarm default", ] }, { diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index b352d6a..32e3e1c 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -278,7 +278,9 @@ async function apiErrorList (ctx) { for (let lr of listRes.rows) { if (lr.app && lr.app.projectCorrelations) { for (let p of lr.app.projectCorrelations) { - pepProjectIds.add(p.pepProjectId) + if (p.pepProjectId) { + pepProjectIds.add(p.pepProjectId) + } } } } diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index e763322..d57245a 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -4,13 +4,13 @@ async function list (ctx) { try { const { models } = ctx.fs.dc; const { clickHouse } = ctx.app.fs - const { utils: { judgeSuper, anxinStrucRange } } = ctx.app.fs + const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs const { database: anxinyun } = clickHouse.anxinyun.opts.config const isSuper = judgeSuper(ctx) let anxinStrucIds = null if (!isSuper) { - anxinStrucIds = await anxinStrucRange(ctx) + anxinStrucIds = await anxinStrucIdRange(ctx) } const alarmRes = await clickHouse.dataAlarm.query(` SELECT @@ -18,7 +18,8 @@ async function list (ctx) { FROM alarms LEFT JOIN ${anxinyun}.t_structure - ON ${anxinyun}.t_structure.id = alarms.StructureId + ON ${anxinyun}.t_structure.id = alarms.StructureId + ${anxinStrucIds ? 'WHERE ' + anxinyun + '.t_structure.id IN (' + anxinStrucIds.join(",") + ')' : ''} `).toPromise(); ctx.status = 200; diff --git a/api/app/lib/controllers/organization/index.js b/api/app/lib/controllers/organization/index.js index 2fcee4e..e0d2511 100644 --- a/api/app/lib/controllers/organization/index.js +++ b/api/app/lib/controllers/organization/index.js @@ -209,11 +209,43 @@ async function user (ctx) { }) let userIds = new Set() + let pomsProjectIds = new Set() for (let u of userRes.rows.concat(adminRes)) { userIds.add(u.pepUserId) + for (let pid of u.correlationProject) { + pomsProjectIds.add(pid) + } } + // 查用户所属的项企pep的部门、人员信息 let userPepRes = userIds.size ? - await clickHouse.pepEmis.query(`SELECT DISTINCT user.id AS id, "user"."name" AS name, department.name AS depName, department.id AS depId 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(',')}) AND department.delete=false`).toPromise() : + await clickHouse.pepEmis.query(` + SELECT DISTINCT + user.id AS id, "user"."name" AS name, department.name AS depName, department.id AS depId + 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(',')}) + AND department.delete=false` + ).toPromise() : + [] + + let pomsProjectRes = await models.ProjectCorrelation.findAll({ + where: { + id: { $in: pomsProjectIds } + } + }) + let pepPojectIds = new Set() + for (let pid of pomsProjectRes) { + + } + + let pepProjectRes = pomsProjectRes.length ? + await clickHouse.pepEmis.query(` + + `).toPromise() : [] for (let u of userRes.rows.concat(adminRes)) { diff --git a/api/app/lib/models/user.js b/api/app/lib/models/user.js index 52d3f56..f541651 100644 --- a/api/app/lib/models/user.js +++ b/api/app/lib/models/user.js @@ -37,7 +37,7 @@ module.exports = dc => { type: DataTypes.ARRAY(DataTypes.INTEGER), allowNull: true, defaultValue: null, - comment: "关联的项目管理的项目id", + comment: "关联的poms的项目id", primaryKey: false, field: "correlation_project", autoIncrement: false diff --git a/api/app/lib/utils/dataRange.js b/api/app/lib/utils/dataRange.js index 70431a3..0c2d515 100644 --- a/api/app/lib/utils/dataRange.js +++ b/api/app/lib/utils/dataRange.js @@ -14,7 +14,7 @@ module.exports = function (app, opts) { } } - async function anxinStrucRange (ctx) { + async function anxinStrucIdRange (ctx) { try { const { models } = ctx.fs.dc; const { userInfo = {} } = ctx.fs.api || {}; @@ -22,15 +22,21 @@ module.exports = function (app, opts) { const bindRes = await models.ProjectCorrelation.findAll({ where: { - pepProjectId: { $in: correlationProject } + id: { $in: correlationProject }, + del: false } }) - return bindRes.reduce((arr, b) => { - for (let sid of b.anxinProjectId) { - arr.add(sid); - } - return arr; - }, new Set()) + return [ + ...bindRes.reduce( + (arr, b) => { + for (let sid of b.anxinProjectId) { + arr.add(sid); + } + return arr; + }, + new Set() + ) + ] } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); } @@ -38,6 +44,6 @@ module.exports = function (app, opts) { return { judgeSuper, - anxinStrucRange + anxinStrucIdRange } } \ No newline at end of file diff --git a/script/0.0.1/1.init_tables.sql b/script/0.0.1/1.init_tables.sql index 298fbc3..9e07174 100644 --- a/script/0.0.1/1.init_tables.sql +++ b/script/0.0.1/1.init_tables.sql @@ -19,7 +19,7 @@ comment on column "user".pep_user_id is '项企对应用户id'; comment on column "user".role is '角色 也对应权限 admin 管理员 / all 全部角色 / data_analyst 数据分析 / after_sale 售后运维 / resource_manage 资源管理 / customer_service 客户服务'; -comment on column "user".correlation_project is '关联的项目管理的项目id'; +comment on column "user".correlation_project is '关联的poms的项目id'; comment on column "user".online_duration is '在线时长 单位 s';