From 7b6dc8cd44f832a5680dffb1c7b5cb7b6ccee653 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 11 Oct 2022 08:52:26 +0800 Subject: [PATCH] =?UTF-8?q?fix=205810=20=E6=99=AE=E9=80=9A=E6=88=90?= =?UTF-8?q?=E5=91=98=E7=99=BB=E5=BD=95=E5=90=8E=E6=9F=A5=E7=9C=8B=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=BC=82=E5=B8=B8=E6=95=B0=E6=8D=AE=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E6=9C=AA=E5=81=9A=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/alarm/app.js | 67 ++++++---------------------- api/app/lib/utils/dataRange.js | 37 +++++++++++++-- 2 files changed, 48 insertions(+), 56 deletions(-) diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index bd16e84..4d2a5a2 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -205,21 +205,15 @@ async function apiErrorList (ctx) { try { const models = ctx.fs.dc.models; const { clickHouse } = ctx.app.fs - const { keyword, errType, confirmState, sustainTimeStart, sustainTimeEnd, limit, page } = ctx.query - - const pepProjectSql = ` - SELECT - t_pim_project.id AS id, - t_pim_project.project_name AS project_name, - t_pim_project_construction.construction_status_id AS construction_status_id, - t_pim_project_state.construction_status AS construction_status - FROM t_pim_project - LEFT JOIN t_pim_project_construction - ON t_pim_project.id = t_pim_project_construction.project_id - LEFT JOIN t_pim_project_state - ON t_pim_project_construction.construction_status_id = t_pim_project_state.id - ` + const { utils: { anxinStrucIdRange, pomsProjectRange } } = ctx.app.fs + const { keyword, errType, confirmState, sustainTimeStart, sustainTimeEnd, limit, page, pepProjectId } = ctx.query + let pomsProject = await pomsProjectRange({ + ctx, pepProjectId, + keywordTarget: 'pepProject', + keyword, + }) + const pomsProjectIds = pomsProject.map(p => p.id) let findOption = { where: { $or: [] @@ -243,16 +237,11 @@ async function apiErrorList (ctx) { }] }] } - let projectRes = [] if (keyword) { - projectRes = await clickHouse.projectManage.query(` - ${pepProjectSql} - WHERE project_name LIKE '%${keyword}%'` - ).toPromise() findOption.where.$or.push( { - '$app->projectCorrelations.pep_project_id$': { - $in: projectRes.map(p => p.id) + '$app->projectCorrelations.id$': { + $in: pomsProjectIds }, } ) @@ -263,17 +252,8 @@ async function apiErrorList (ctx) { ) } - // if (errType) { - // if (errType == 'element') { - // findOption.where.screenshot = { $ne: null } - // } else if (errType == 'timeout') { - - // } else if (errType == 'apiError') { - // findOption.where.screenshot = null - // } - // } if (errType) { - findOption.where.type = errType + findOption.where.type = errType // element / apiError } if (confirmState) { if (confirmState == 'confirmd') { @@ -306,32 +286,13 @@ async function apiErrorList (ctx) { delete findOption.where.$or } const listRes = await models.AppAlarm.findAndCountAll(findOption) - if (!keyword) { - // 没有关键字筛选 查询关联的项目信息 - let pepProjectIds = new Set() - for (let lr of listRes.rows) { - if (lr.app && lr.app.projectCorrelations) { - for (let p of lr.app.projectCorrelations) { - if (p.pepProjectId) { - pepProjectIds.add(p.pepProjectId) - } - } - } - } - if (pepProjectIds.size) { - projectRes = await clickHouse.projectManage.query(` - ${pepProjectSql} - WHERE id IN (${[...pepProjectIds].join(',')})` - ).toPromise() - } - } for (let lr of listRes.rows) { if (lr.app && lr.app.projectCorrelations) { for (let p of lr.app.projectCorrelations) { - let corPepProject = projectRes.find(pr => pr.id == p.pepProjectId) - if (corPepProject) { - p.dataValues.pepProject = corPepProject + let corProjectCorrelations = pomsProject.find(pr => pr.id == p.id) + if (corProjectCorrelations) { + p.dataValues = corProjectCorrelations } } } diff --git a/api/app/lib/utils/dataRange.js b/api/app/lib/utils/dataRange.js index 093f51e..0f79e19 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 anxinStrucIdRange ({ ctx, pepProjectId, keywordTarget, keyword }) { + async function pomsWithPepRangeParams ({ ctx, pepProjectId, keywordTarget, keyword }) { const { models } = ctx.fs.dc; const { userInfo = {} } = ctx.fs.api || {}; const { clickHouse } = ctx.app.fs @@ -82,6 +82,15 @@ module.exports = function (app, opts) { ).toPromise() : [] + return { + pepProjectRes, bindRes, + } + } + + async function anxinStrucIdRange ({ ctx, pepProjectId, keywordTarget, keyword }) { + const { clickHouse } = ctx.app.fs + + const { pepProjectRes, bindRes, } = await pomsWithPepRangeParams({ ctx, pepProjectId, keywordTarget, keyword }) // 获取不重复的 安心云项目 id const anxinProjectIds = [ @@ -166,8 +175,30 @@ module.exports = function (app, opts) { return undelStruc } + async function pomsProjectRange ({ ctx, pepProjectId, keywordTarget, keyword }) { + + const { pepProjectRes, bindRes, } = await pomsWithPepRangeParams({ ctx, pepProjectId, keywordTarget, keyword }) + + let pomsProject = [] + for (let b of bindRes) { + if (b.pepProjectId) { + let corPepProject = pepProjectRes.find(pp => pp.id == b.pepProjectId) || {} + pomsProject.push({ + ...b.dataValues, + pepProject: corPepProject + }) + } else { + pomsProject.push({ + ...b.dataValues + }) + } + } + return pomsProject + } + return { - judgeSuper, - anxinStrucIdRange + judgeSuper, pomsWithPepRangeParams, + anxinStrucIdRange, + pomsProjectRange, } } \ No newline at end of file