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.
68 lines
1.8 KiB
68 lines
1.8 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
|
|
|
|
|
|
// TODO 这儿也许需要判断传进来的 pepProjectId 在不在当前用户的关注范围内
|
|
const bindRes = await models.ProjectCorrelation.findAll({
|
|
where: {
|
|
id: { $in: pepProjectId ? [pepProjectId] : correlationProject },
|
|
del: false
|
|
}
|
|
})
|
|
|
|
const anxinStrucIds = [
|
|
...bindRes.reduce(
|
|
(arr, b) => {
|
|
for (let sid of b.anxinProjectId) {
|
|
arr.add(sid);
|
|
}
|
|
return arr;
|
|
},
|
|
new Set()
|
|
)
|
|
]
|
|
|
|
const undelStrucRes = anxinStrucIds.length ?
|
|
await clickHouse.anxinyun.query(`
|
|
SELECT
|
|
id
|
|
FROM
|
|
t_project
|
|
WHERE
|
|
project_state = 4
|
|
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
|
|
}
|
|
}
|