运维服务中台
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.

136 lines
3.7 KiB

2 years ago
'use strict';
async function appList (ctx) {
try {
const models = ctx.fs.dc.models;
const appRes = await models.ProjectApp.findAll({
attributes: {
exclude: ['projectId']
}
})
ctx.status = 200;
ctx.body = appRes
} catch (error) {
2 years ago
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
2 years ago
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
2 years ago
async function pomsProject (ctx) {
try {
const models = ctx.fs.dc.models;
const { clickHouse } = ctx.app.fs
const { userId } = ctx.fs.api
const { limit, page } = ctx.query
2 years ago
let findOption = {
where: {
del: false
},
2 years ago
include: {
model: models.ProjectApp,
where: {
lock: false
},
2 years ago
attributes: {
exclude: ['projectId']
}
}
}
if (limit) {
findOption.limit = limit
}
if (page && limit) {
findOption.offset = page * limit
}
const proRes = await models.ProjectCorrelation.findAll(findOption)
delete findOption.limit
delete findOption.offset
const proCount = await models.ProjectCorrelation.count(findOption)
2 years ago
let pepProjectIds = new Set()
let anxinProjectIds = new Set()
for (let p of proRes) {
pepProjectIds.add(p.pepProjectId)
for (let ap of p.anxinProjectId) {
anxinProjectIds.add(ap)
}
}
const pepProjectRes = pepProjectIds.size ?
await clickHouse.projectManage.query(`SELECT id, project_name FROM t_pim_project WHERE id IN (${[...pepProjectIds].join(',')})`).toPromise() :
[]
const anxinProjectRes = anxinProjectIds.size ?
await clickHouse.anxinyun.query(`SELECT id,"name" FROM t_project WHERE id IN (${[...anxinProjectIds].join(',')})`).toPromise() :
[]
for (let p of proRes) {
const corPro = pepProjectRes.find(pp => pp.id == p.pepProjectId)
p.dataValues.pepProjectName = corPro.project_name
let nextAnxinProject = anxinProjectRes.filter(ap => p.anxinProjectId.includes(ap.id))
p.dataValues.anxinProject = nextAnxinProject
delete p.dataValues.anxinProjectId
}
ctx.status = 200;
ctx.body = {
count: proCount,
rows: proRes
}
2 years ago
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
2 years ago
async function projectAnxincloud (ctx) {
try {
const models = ctx.fs.dc.models;
const { clickHouse } = ctx.app.fs
const projectRes = await clickHouse.anxinyun.query(`SELECT * FROM t_project WHERE project_state = 4 ORDER BY id DESC`).toPromise()
ctx.status = 200;
ctx.body = projectRes
} catch (error) {
2 years ago
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
2 years ago
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function projectPManage (ctx) {
try {
const models = ctx.fs.dc.models;
const { clickHouse } = ctx.app.fs
2 years ago
const projectRes = await clickHouse.projectManage.query(`SELECT id, project_name FROM t_pim_project WHERE isdelete=0 ORDER BY id DESC`).toPromise()
2 years ago
ctx.status = 200;
ctx.body = projectRes
} catch (error) {
2 years ago
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
2 years ago
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
2 years ago
2 years ago
module.exports = {
2 years ago
appList,
2 years ago
projectAnxincloud,
projectPManage,
2 years ago
pomsProject,
2 years ago
};