From 4b2ce5d77af3dd84b1b23dcad78645d924b7c393 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 20 Sep 2022 16:44:40 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/alarm/app.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index cd0950e..b352d6a 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -198,7 +198,7 @@ async function apiErrorList (ctx) { $or: [] }, include: [{ - model: models.ProjectApp, + model: models.App, where: { }, @@ -225,10 +225,10 @@ async function apiErrorList (ctx) { if (projectRes.length) { findOption.where.$or.push( { - '$projectApp.projectCorrelation.pep_project_id$': { + '$app->projectCorrelations.pep_project_id$': { $in: projectRes.map(p => p.id) }, - '$projectApp.name$': { $like: `%${keyword}%` } + '$app.name$': { $like: `%${keyword}%` } } ) } @@ -276,8 +276,10 @@ async function apiErrorList (ctx) { // 没有关键字筛选 查询关联的项目信息 let pepProjectIds = new Set() for (let lr of listRes.rows) { - if (lr.projectApp && lr.projectApp.projectCorrelation) { - pepProjectIds.add(lr.projectApp.projectCorrelation.pepProjectId) + if (lr.app && lr.app.projectCorrelations) { + for (let p of lr.app.projectCorrelations) { + pepProjectIds.add(p.pepProjectId) + } } } if (pepProjectIds.size) { @@ -289,10 +291,12 @@ async function apiErrorList (ctx) { } for (let lr of listRes.rows) { - if (lr.projectApp && lr.projectApp.projectCorrelation) { - let corPepProject = projectRes.find(p => p.id == lr.projectApp.projectCorrelation.pepProjectId) - if (corPepProject) { - lr.projectApp.projectCorrelation.dataValues.pepProject = corPepProject + 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 + } } } } From 3bb398ac760c5fd7e8994ff989ccee7f25d5ad6d Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 20 Sep 2022 20:16:58 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E9=A1=B9=E7=9B=AE=E5=88=A4=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/project/bind.js | 55 ++++++++++++++++++------ api/app/lib/controllers/project/index.js | 8 +++- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/api/app/lib/controllers/project/bind.js b/api/app/lib/controllers/project/bind.js index b79d089..39aa102 100644 --- a/api/app/lib/controllers/project/bind.js +++ b/api/app/lib/controllers/project/bind.js @@ -9,20 +9,53 @@ async function bindAnxin2pep (ctx) { const { userId, pepUserId } = ctx.fs.api const { bindId, name, pepProjectId, anxinProjectId = [], appId = [] } = ctx.request.body - if(name && pepProjectId){ + if (name && pepProjectId) { throw '项企项目与自定义项目名称仅可选择一项' } let bindId_ = bindId const now = moment() - const existRes = await models.ProjectCorrelation.findOne({ - where: { - pepProjectId: pepProjectId - }, - include: { - model: models.ProjectApp + // 仅限已有 pepProjectId 的项目 + const existRes = pepProjectId ? await models.ProjectCorrelation.findOne({ + where: Object.assign( + {}, + pepProjectId ? { + pepProjectId: pepProjectId + } : { + name, + } + ), + }) : null + + if (name) { + const pepRepeatNameCount = await clickHouse.projectManage.query(`SELECT COUNT(*) AS count FROM t_pim_project WHERE project_name='${name}'`).toPromise() + if (pepRepeatNameCount[0].count) { + throw `已有相同名称【${name}】的项企项目` } - }) + const pomsRepeatNameRes = await models.ProjectCorrelation.findAll({ + where: { + name + } + }) + if (pomsRepeatNameRes.some((pr) => { + return ( + ( + // 有修改id但是不等于当前修改id的 + bindId && pr.id != bindId && !pr.del + ) || ( + !bindId && ( + ( + existRes && pr.id != existRes.id && !pr.del + ) || ( + !existRes && !pr.del + ) + ) + ) + ) + })) { + throw `已有相同名称【${name}】的自定义项目` + } + } let storageData = { name, pepProjectId, anxinProjectId, @@ -31,12 +64,6 @@ async function bindAnxin2pep (ctx) { if (bindId) { // 修改 - if (!existRes) { - throw '尚无已绑定的项企项目' - } - if (name) { - - } await models.ProjectCorrelation.update(storageData, { where: { pepProjectId: pepProjectId diff --git a/api/app/lib/controllers/project/index.js b/api/app/lib/controllers/project/index.js index 7248d2a..0d3be44 100644 --- a/api/app/lib/controllers/project/index.js +++ b/api/app/lib/controllers/project/index.js @@ -47,9 +47,13 @@ async function pomsProject (ctx) { let pepProjectIds = new Set() let anxinProjectIds = new Set() for (let p of proRes.rows) { - pepProjectIds.add(p.pepProjectId) + if (p.pepProjectId) { + pepProjectIds.add(p.pepProjectId) + } for (let ap of p.anxinProjectId) { - anxinProjectIds.add(ap) + if (ap) { + anxinProjectIds.add(ap) + } } } const pepProjectRes = pepProjectIds.size ? From f033364bd36423c4400e529186c4b071897bae35 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 20 Sep 2022 20:30:13 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E9=A1=B9=E7=9B=AE=E5=88=A4=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/project/bind.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/app/lib/controllers/project/bind.js b/api/app/lib/controllers/project/bind.js index 39aa102..9b5ac1b 100644 --- a/api/app/lib/controllers/project/bind.js +++ b/api/app/lib/controllers/project/bind.js @@ -66,7 +66,7 @@ async function bindAnxin2pep (ctx) { // 修改 await models.ProjectCorrelation.update(storageData, { where: { - pepProjectId: pepProjectId + id: bindId }, transaction }) From 89a5d9a28a81f928f76d3dec150226e2d303b191 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 20 Sep 2022 20:40:57 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/project/bind.js | 5 +++-- api/app/lib/controllers/project/index.js | 1 + api/app/lib/models/project_correlation.js | 11 ++++++++++- script/0.0.3/2.alter_table_project_correlation.sql | 5 ++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/api/app/lib/controllers/project/bind.js b/api/app/lib/controllers/project/bind.js index 9b5ac1b..f78b7f3 100644 --- a/api/app/lib/controllers/project/bind.js +++ b/api/app/lib/controllers/project/bind.js @@ -59,6 +59,7 @@ async function bindAnxin2pep (ctx) { let storageData = { name, pepProjectId, anxinProjectId, + updateTime: now, del: false, } @@ -129,7 +130,7 @@ async function bindAnxin2pep (ctx) { async function del (ctx) { try { const models = ctx.fs.dc.models; - const { bindId } = ctx.query + const { bindId } = ctx.params await models.ProjectCorrelation.update({ del: true @@ -139,7 +140,7 @@ async function del (ctx) { } }) - ctx.status = 20; + ctx.status = 204; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.status = 400; diff --git a/api/app/lib/controllers/project/index.js b/api/app/lib/controllers/project/index.js index 0d3be44..247f544 100644 --- a/api/app/lib/controllers/project/index.js +++ b/api/app/lib/controllers/project/index.js @@ -29,6 +29,7 @@ async function pomsProject (ctx) { where: { del: false }, + order: [['updateTime', 'desc']], distinct: true, include: { model: models.App, diff --git a/api/app/lib/models/project_correlation.js b/api/app/lib/models/project_correlation.js index 0996bb7..b0ae1be 100644 --- a/api/app/lib/models/project_correlation.js +++ b/api/app/lib/models/project_correlation.js @@ -68,7 +68,16 @@ module.exports = dc => { primaryKey: false, field: "del", autoIncrement: false - } + }, + updateTime: { + type: DataTypes.DATE, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: false, + field: "update_time", + autoIncrement: false + }, }, { tableName: "project_correlation", comment: "", diff --git a/script/0.0.3/2.alter_table_project_correlation.sql b/script/0.0.3/2.alter_table_project_correlation.sql index a6f9088..5df88da 100644 --- a/script/0.0.3/2.alter_table_project_correlation.sql +++ b/script/0.0.3/2.alter_table_project_correlation.sql @@ -6,4 +6,7 @@ alter table project_correlation alter table project_correlation add del bool default false; -alter table project_correlation alter column pep_project_id drop not null; \ No newline at end of file +alter table project_correlation alter column pep_project_id drop not null; + +alter table project_correlation + add update_time timestamp with time zone; \ No newline at end of file