巴林闲侠 2 years ago
parent
commit
9b522db84a
  1. 35
      api/app/lib/controllers/alarm/data.js
  2. 2
      web/client/index.ejs

35
api/app/lib/controllers/alarm/data.js

@ -6,7 +6,8 @@ async function list (ctx) {
const { clickHouse } = ctx.app.fs
const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs
const { database: anxinyun } = clickHouse.anxinyun.opts.config
const { pepProjectId, groupId, sustainTimeStart, sustainTimeEnd } = ctx.query
const { pepProjectId, groupId, groupUnitId, sustainTimeStart, sustainTimeEnd } = ctx.query
const isSuper = judgeSuper(ctx)
let anxinStrucIds = null
@ -15,28 +16,48 @@ async function list (ctx) {
}
let whereOption = []
if (anxinStrucIds) {
whereOption.push(`${anxinyun}.t_structure.id IN (${anxinStrucIds.join(",")})`)
whereOption.push(`alarms.StructureId IN (${anxinStrucIds.join(",")})`)
}
if (groupId) {
whereOption.push(`${anxinyun}.t_alarm_code.alarm_group=${groupId}`)
whereOption.push(`alarms.AlarmGroup=${groupId}`)
}
if (groupUnitId) {
whereOption.push(`${anxinyun}.t_alarm_code.alarm_group=${groupId}`)
whereOption.push(`alarms.AlarmGroupUnit=${groupId}`)
}
if (sustainTimeStart && sustainTimeEnd) {
whereOption.push(``)
let momentStart = moment(sustainTimeStart).format()
let momentEnd = moment(sustainTimeEnd).format()
whereOption.push(`
(
alarms."StartTime"
BETWEEN '${momentStart}' AND '${momentEnd}'
OR
"alarms"."EndTime" BETWEEN '${momentStart}' AND '${momentEnd}'
OR (
"alarms"."StartTime" <= '${momentStart}'
AND
"alarms"."EndTime" >= '${momentEnd}'
)
)
`)
}
const alarmRes = await clickHouse.dataAlarm.query(`
SELECT
AlarmId, SourceName,
alarms.AlarmId, alarms.State, SourceName, StartTime, EndTime, alarms.CurrentLevel, SourceTypeId, AlarmAdviceProblem,AlarmGroup, AlarmGroupUnit, AlarmAdviceProblem,
${anxinyun}.t_structure.name AS StructureName, StructureId,
${anxinyun}.t_alarm_code.name AS AlarmCodeDescribe
${anxinyun}.t_alarm_code.name AS AlarmCodeName,
alarm_details.Time, alarm_details.Content
FROM
alarms
LEFT JOIN ${anxinyun}.t_structure
ON ${anxinyun}.t_structure.id = alarms.StructureId
LEFT JOIN ${anxinyun}.t_alarm_code
ON ${anxinyun}.t_alarm_code.code = alarms.AlarmTypeCode
LEFT JOIN alarm_details
ON alarms.AlarmId = alarm_details.AlarmId
AND alarm_details.Time = (
SELECT MAX(alarm_details.Time) from alarm_details WHERE AlarmId = alarms.AlarmId
)
${whereOption.length ? 'WHERE ' + whereOption.join(' AND ') : ''}
`).toPromise();

2
web/client/index.ejs

@ -5,7 +5,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
<!-- <meta content="upgrade-insecure-requests" http-equiv="Content-Security-Policy"> -->
<meta content="upgrade-insecure-requests" http-equiv="Content-Security-Policy">
<link rel="shortcut icon" href="/assets/images/favicon.ico">
<script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script>

Loading…
Cancel
Save