Browse Source

用户绑定项目信息查询

dev
巴林闲侠 2 years ago
parent
commit
5d20a61a20
  1. 41
      api/app/lib/controllers/organization/index.js
  2. 14
      api/app/lib/controllers/project/bind.js

41
api/app/lib/controllers/organization/index.js

@ -232,23 +232,30 @@ async function user (ctx) {
).toPromise() : ).toPromise() :
[] []
// 查用户绑定的当前系统的项目 id
let pomsProjectRes = await models.ProjectCorrelation.findAll({ let pomsProjectRes = await models.ProjectCorrelation.findAll({
where: { where: {
id: { $in: pomsProjectIds } id: { $in: [...pomsProjectIds] },
// del: false
} }
}) })
// 获取响应的绑定的 项企项目的 id
let pepPojectIds = new Set() 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 ? let pepProjectRes = pepPojectIds.size ?
await clickHouse.pepEmis.query(` await clickHouse.projectManage.query(`
SELECT id, project_name, isdelete FROM t_pim_project WHERE id IN (${[...pepPojectIds]})
`).toPromise() : `).toPromise() :
[] []
// 遍历用户并将查到的信息拼合
for (let u of userRes.rows.concat(adminRes)) { for (let u of userRes.rows.concat(adminRes)) {
// 用户信息
const corUsers = userPepRes.filter(up => up.id == u.pepUserId) const corUsers = userPepRes.filter(up => up.id == u.pepUserId)
u.dataValues.name = corUsers.length ? corUsers[0].name : '' u.dataValues.name = corUsers.length ? corUsers[0].name : ''
u.dataValues.departments = corUsers.length ? corUsers.map(cu => { u.dataValues.departments = corUsers.length ? corUsers.map(cu => {
@ -257,6 +264,26 @@ async function user (ctx) {
id: cu.depId 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 ctx.status = 200

14
api/app/lib/controllers/project/bind.js

@ -15,6 +15,13 @@ async function bindAnxin2pep (ctx) {
let bindId_ = bindId let bindId_ = bindId
const now = moment() const now = moment()
let storageData = {
name, pepProjectId, anxinProjectId,
updateTime: now,
del: false,
}
// 仅限已有 pepProjectId 的项目 // 仅限已有 pepProjectId 的项目
const existRes = pepProjectId ? await models.ProjectCorrelation.findOne({ const existRes = pepProjectId ? await models.ProjectCorrelation.findOne({
where: Object.assign( where: Object.assign(
@ -79,13 +86,10 @@ async function bindAnxin2pep (ctx) {
})) { })) {
throw `当前项企项目已绑定` throw `当前项企项目已绑定`
} }
storageData.name = null
} }
let storageData = {
name, pepProjectId, anxinProjectId,
updateTime: now,
del: false,
}
if (bindId) { if (bindId) {
// 修改 // 修改

Loading…
Cancel
Save