运维服务中台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.1 KiB

'use strict';
const fs = require('fs');
const moment = require('moment')
module.exports = function (app, opts) {
function judgeSuper (ctx) {
try {
const { userInfo = {} } = ctx.fs.api || {};
const { role = [] } = userInfo
return role.includes('SuperAdmin')
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
}
}
async function anxinStrucIdRange ({ ctx, pepProjectId }) {
try {
const { models } = ctx.fs.dc;
const { userInfo = {} } = ctx.fs.api || {};
const { clickHouse } = ctx.app.fs
const { correlationProject = [] } = userInfo
const isSuper = judgeSuper(ctx)
let findOption = {
where: {
del: false
}
}
if (pepProjectId) {
findOption.where.pepProjectId = pepProjectId
} else if (!isSuper) {
findOption.where.id = { $in: correlationProject }
}
// TODO 这儿也许需要判断传进来的 pepProjectId 在不在当前用户的关注范围内
const bindRes = await models.ProjectCorrelation.findAll(findOption)
const anxinStrucIds = [
...bindRes.reduce(
(arr, b) => {
for (let sid of b.anxinProjectId) {
arr.add(sid);
}
return arr;
},
new Set()
)
]
// 查结构物 左联 项目 ,项目 id 在关注的项目里
const undelStrucRes = anxinStrucIds.length ?
await clickHouse.anxinyun.query(`
SELECT
id
FROM
t_project
WHERE
project_state != -1
AND
id IN (${anxinStrucIds.join(',')})
`).toPromise() :
[]
return undelStrucRes.map(s => s.id)
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
}
}
return {
judgeSuper,
anxinStrucIdRange
}
}