wuqun
2 years ago
2 changed files with 93 additions and 0 deletions
@ -0,0 +1,90 @@ |
|||
'use strict'; |
|||
const moment = require('moment'); |
|||
|
|||
async function dataList (ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { userId, pepUserId, userInfo = {}, pepUserInfo } = ctx.fs.api |
|||
const { clickHouse } = ctx.app.fs |
|||
const { utils: { judgeSuper, anxinStrucIdRange, pomsProjectRange } } = ctx.app.fs |
|||
const { database: anxinyun } = clickHouse.anxinyun.opts.config |
|||
const { pepProjectId } = ctx.request.query |
|||
|
|||
|
|||
let anxinStruc = await anxinStrucIdRange({ |
|||
ctx, pepProjectId |
|||
}) |
|||
let pomsProject = await pomsProjectRange({ |
|||
ctx, pepProjectId, |
|||
}) |
|||
const pomsProjectIds = pomsProject.map(p => p.id) |
|||
|
|||
if (anxinStruc.length) { |
|||
|
|||
const anxinStrucIds = anxinStruc.map(a => a.strucId) || [] |
|||
|
|||
const dataAlarm = await clickHouse.dataAlarm.query(` |
|||
SELECT |
|||
formatDateTime(alarmData.StartTime,'%F %H') hours, count(AlarmId) count |
|||
FROM |
|||
( SELECT |
|||
AlarmId,State,StartTime |
|||
FROM |
|||
alarms |
|||
WHERE |
|||
alarms.StructureId IN (${anxinStrucIds.join(",")}) |
|||
AND |
|||
AlarmGroup = 3) AS alarmData |
|||
GROUP BY hours |
|||
`).toPromise();
|
|||
|
|||
// const confirmedAlarm = dataAlarm
|
|||
// // TODO: 开发临时注释
|
|||
// .filter(ar => ar.State && ar.State > 2)
|
|||
// .map(ar => "'" + ar.AlarmId + "'")
|
|||
|
|||
// // formatDateTime(Time,'%F %H') hours, count(AlarmId) count
|
|||
|
|||
// const dataConfirme = confirmedAlarm.length ?
|
|||
// await clickHouse.dataAlarm.query(`
|
|||
// SELECT
|
|||
// max(Time) AS Time, AlarmId
|
|||
// FROM
|
|||
// alarm_details
|
|||
// WHERE
|
|||
// AlarmId IN (${confirmedAlarm.join(',')})
|
|||
// GROUP BY AlarmId
|
|||
// `).toPromise() :
|
|||
// [];
|
|||
|
|||
|
|||
// dataAlarm.forEach(ar => {
|
|||
// ar.confirme =
|
|||
// dataConfirme.find(as => as.AlarmId == ar.AlarmId) || {}
|
|||
|
|||
// })
|
|||
ctx.status = 200 |
|||
ctx.body = dataAlarm |
|||
} else { |
|||
ctx.status = 200 |
|||
ctx.body = { |
|||
dataAlarm: 0, |
|||
} |
|||
} |
|||
|
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
module.exports = { |
|||
dataList, |
|||
}; |
Loading…
Reference in new issue