diff --git a/api/app/lib/controllers/organization/index.js b/api/app/lib/controllers/organization/index.js index e0d2511..8058afc 100644 --- a/api/app/lib/controllers/organization/index.js +++ b/api/app/lib/controllers/organization/index.js @@ -232,23 +232,30 @@ async function user (ctx) { ).toPromise() : [] + // 查用户绑定的当前系统的项目 id let pomsProjectRes = await models.ProjectCorrelation.findAll({ where: { - id: { $in: pomsProjectIds } + id: { $in: [...pomsProjectIds] }, + // del: false } }) + // 获取响应的绑定的 项企项目的 id let pepPojectIds = new Set() - for (let pid of pomsProjectRes) { - + for (let p of pomsProjectRes) { + if (p.pepProjectId) { + pepPojectIds.add(p.pepProjectId) + } } - - let pepProjectRes = pomsProjectRes.length ? - await clickHouse.pepEmis.query(` - + // 查对应的项企项目信息 + let pepProjectRes = pepPojectIds.size ? + await clickHouse.projectManage.query(` + SELECT id, project_name, isdelete FROM t_pim_project WHERE id IN (${[...pepPojectIds]}) `).toPromise() : [] + // 遍历用户并将查到的信息拼合 for (let u of userRes.rows.concat(adminRes)) { + // 用户信息 const corUsers = userPepRes.filter(up => up.id == u.pepUserId) u.dataValues.name = corUsers.length ? corUsers[0].name : '' u.dataValues.departments = corUsers.length ? corUsers.map(cu => { @@ -257,6 +264,26 @@ async function user (ctx) { id: cu.depId } }) : [] + // pep项目信息 + u.dataValues.correlationProject = u.dataValues.correlationProject.map(cpid => { + let returnData = { + id: cpid, + } + const corPomsProject = pomsProjectRes.find(ppr => ppr.id == cpid) + if (corPomsProject) { + returnData.name = corPomsProject.name + returnData.del = corPomsProject.del + if (corPomsProject.pepProjectId) { + returnData.pepProjectId = corPomsProject.pepProjectId + const corPepProject = pepProjectRes.find(ppr => ppr.id == corPomsProject.pepProjectId) + if (corPepProject) { + returnData.pepProjectName = corPepProject.project_name + returnData.pepIsdelete = corPepProject.isdelete + } + } + } + return returnData + }) } ctx.status = 200 diff --git a/api/app/lib/controllers/project/bind.js b/api/app/lib/controllers/project/bind.js index 4d87cdd..b93a1e0 100644 --- a/api/app/lib/controllers/project/bind.js +++ b/api/app/lib/controllers/project/bind.js @@ -15,6 +15,13 @@ async function bindAnxin2pep (ctx) { let bindId_ = bindId const now = moment() + + let storageData = { + name, pepProjectId, anxinProjectId, + updateTime: now, + del: false, + } + // 仅限已有 pepProjectId 的项目 const existRes = pepProjectId ? await models.ProjectCorrelation.findOne({ where: Object.assign( @@ -79,13 +86,10 @@ async function bindAnxin2pep (ctx) { })) { throw `当前项企项目已绑定` } + storageData.name = null } - let storageData = { - name, pepProjectId, anxinProjectId, - updateTime: now, - del: false, - } + if (bindId) { // 修改