|
|
|
'use strict';
|
|
|
|
|
|
|
|
const moment = require("moment")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function countIssueByState(ctx, next) {
|
|
|
|
const sequelize = ctx.fs.dc.orm
|
|
|
|
const { projectId } = ctx.query
|
|
|
|
try {
|
|
|
|
const rslt = await sequelize.query(`
|
|
|
|
SELECT COUNT(CASE WHEN prih.state=4 THEN 1 END) AS waitingRepair,
|
|
|
|
COUNT(CASE WHEN prih.state=1 THEN 1 END) AS waitingPlan,
|
|
|
|
COUNT(CASE WHEN prih.state=5 THEN 1 END) AS waitingCheck,
|
|
|
|
COUNT(CASE WHEN prih.state=2 THEN 1 END) AS waitingExamine
|
|
|
|
FROM patrol_record rd
|
|
|
|
INNER JOIN patrol_record_issue_handle prih
|
|
|
|
ON rd.id = prih.patrol_record_id
|
|
|
|
WHERE rd.project_id in (${projectId})
|
|
|
|
`)
|
|
|
|
ctx.status = 200
|
|
|
|
ctx.body = rslt[0][0]
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = { message: '根据状态分类查询问题处理失败' }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//近30天的问题统计
|
|
|
|
async function countDayIssue(ctx, next) {
|
|
|
|
const sequelize = ctx.fs.dc.orm
|
|
|
|
const { projectId } = ctx.query
|
|
|
|
try {
|
|
|
|
const rslt = await sequelize.query(`
|
|
|
|
SELECT
|
|
|
|
date_sequence::DATE AS date,
|
|
|
|
COALESCE(COUNT(patrol_record.inspection_time), 0) AS count
|
|
|
|
FROM
|
|
|
|
generate_series(CURRENT_DATE - INTERVAL '29 days', CURRENT_DATE, '1 day'::interval) date_sequence
|
|
|
|
LEFT JOIN patrol_record
|
|
|
|
ON date_sequence::DATE = DATE(patrol_record.inspection_time)
|
|
|
|
AND patrol_record.project_id in (:projectId)
|
|
|
|
AND patrol_record.alarm='true'
|
|
|
|
GROUP BY date
|
|
|
|
ORDER BY date;
|
|
|
|
`, {
|
|
|
|
replacements: {
|
|
|
|
projectId: projectId.split(',').map(Number),
|
|
|
|
},
|
|
|
|
type: sequelize.QueryTypes.SELECT,
|
|
|
|
})
|
|
|
|
ctx.status = 200
|
|
|
|
ctx.body = rslt
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = { message: '近30天的问题统计查询失败' }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
countIssueByState,
|
|
|
|
countDayIssue
|
|
|
|
}
|