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 ?