|
|
|
'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) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = {
|
|
|
|
message: typeof error == 'string' ? error : undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function pomsProject (ctx) {
|
|
|
|
try {
|
|
|
|
const models = ctx.fs.dc.models;
|
|
|
|
const { clickHouse } = ctx.app.fs
|
|
|
|
const { userId, pepUserId } = ctx.fs.api
|
|
|
|
const { limit, page } = ctx.query
|
|
|
|
|
|
|
|
let findOption = {
|
|
|
|
where: {
|
|
|
|
del: false
|
|
|
|
},
|
|
|
|
distinct: true,
|
|
|
|
include: {
|
|
|
|
model: models.ProjectApp,
|
|
|
|
where: {
|
|
|
|
lock: false
|
|
|
|
},
|
|
|
|
attributes: {
|
|
|
|
exclude: ['projectId']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (limit) {
|
|
|
|
findOption.limit = limit
|
|
|
|
}
|
|
|
|
if (page && limit) {
|
|
|
|
findOption.offset = page * limit
|
|
|
|
}
|
|
|
|
|
|
|
|
const proRes = await models.ProjectCorrelation.findAndCountAll(findOption)
|
|
|
|
|
|
|
|
let pepProjectIds = new Set()
|
|
|
|
let anxinProjectIds = new Set()
|
|
|
|
for (let p of proRes.rows) {
|
|
|
|
pepProjectIds.add(p.pepProjectId)
|
|
|
|
for (let ap of p.anxinProjectId) {
|
|
|
|
anxinProjectIds.add(ap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const pepProjectRes = pepProjectIds.size ?
|
|
|
|
await clickHouse.projectManage.query(
|
|
|
|
`
|
|
|
|
SELECT
|
|
|
|
t_pim_project.id AS id,
|
|
|
|
t_pim_project.project_name AS project_name,
|
|
|
|
t_pim_project_construction.construction_status_id AS construction_status_id,
|
|
|
|
t_pim_project_state.construction_status AS construction_status
|
|
|
|
FROM t_pim_project
|
|
|
|
LEFT JOIN t_pim_project_construction
|
|
|
|
ON t_pim_project.id = t_pim_project_construction.project_id
|
|
|
|
LEFT JOIN t_pim_project_state
|
|
|
|
ON t_pim_project_construction.construction_status_id = t_pim_project_state.id
|
|
|
|
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.rows) {
|
|
|
|
const corPro = pepProjectRes.find(pp => pp.id == p.pepProjectId)
|
|
|
|
p.dataValues.pepProjectName = corPro.project_name
|
|
|
|
p.dataValues.constructionStatusId = corPro.construction_status_id
|
|
|
|
p.dataValues.constructionStatus = corPro.construction_status
|
|
|
|
let nextAnxinProject = anxinProjectRes.filter(ap => p.anxinProjectId.includes(ap.id))
|
|
|
|
p.dataValues.anxinProject = nextAnxinProject
|
|
|
|
delete p.dataValues.anxinProjectId
|
|
|
|
}
|
|
|
|
ctx.status = 200;
|
|
|
|
ctx.body = proRes
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = {
|
|
|
|
message: typeof error == 'string' ? error : undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
|
|
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
|
|
|
|
|
|
|
|
const projectRes = await clickHouse.projectManage.query(`SELECT id, project_name FROM t_pim_project WHERE isdelete=0 ORDER BY id DESC`).toPromise()
|
|
|
|
|
|
|
|
ctx.status = 200;
|
|
|
|
ctx.body = projectRes
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = {
|
|
|
|
message: typeof error == 'string' ? error : undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
appList,
|
|
|
|
projectAnxincloud,
|
|
|
|
projectPManage,
|
|
|
|
pomsProject,
|
|
|
|
};
|