|
@ -34,15 +34,16 @@ async function list (ctx) { |
|
|
const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs |
|
|
const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs |
|
|
const { database: anxinyun } = clickHouse.anxinyun.opts.config |
|
|
const { database: anxinyun } = clickHouse.anxinyun.opts.config |
|
|
|
|
|
|
|
|
const { pepProjectId, keyword, groupId, groupUnitId, sustainTimeStart, sustainTimeEnd, limit, page, projectOrStructKeyword } = ctx.query |
|
|
const { pepProjectId, keywordTarget, keyword, groupId, groupUnitId, sustainTimeStart, sustainTimeEnd, limit, page, projectOrStructKeyword } = ctx.query |
|
|
|
|
|
|
|
|
const isSuper = judgeSuper(ctx) |
|
|
let anxinStruc = await anxinStrucIdRange({ |
|
|
let anxinStrucIds = await anxinStrucIdRange({ |
|
|
ctx, pepProjectId, keywordTarget, keyword |
|
|
ctx, pepProjectId, projectOrStructKeyword, |
|
|
|
|
|
}) |
|
|
}) |
|
|
let whereOption = [] |
|
|
let whereOption = [] |
|
|
if (anxinStrucIds.length ||1) { |
|
|
if (anxinStruc.length || 1) { |
|
|
whereOption.push(`alarms.StructureId IN (${anxinStrucIds.join(",")})`) |
|
|
const anxinStrucIds = anxinStruc.map(a => a.strucId) |
|
|
|
|
|
// TODO: 开发临时注释
|
|
|
|
|
|
// whereOption.push(`alarms.StructureId IN (${anxinStrucIds.join(",")})`)
|
|
|
|
|
|
|
|
|
if (groupId) { |
|
|
if (groupId) { |
|
|
whereOption.push(`alarms.AlarmGroup IN (${groupId})`) |
|
|
whereOption.push(`alarms.AlarmGroup IN (${groupId})`) |
|
@ -67,6 +68,9 @@ async function list (ctx) { |
|
|
) |
|
|
) |
|
|
`)
|
|
|
`)
|
|
|
} |
|
|
} |
|
|
|
|
|
if (keywordTarget == 'source' && keyword) { |
|
|
|
|
|
whereOption.push(`SourceName LIKE '%${keyword}%'`) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const alarmRes = await clickHouse.dataAlarm.query(` |
|
|
const alarmRes = await clickHouse.dataAlarm.query(` |
|
|
SELECT |
|
|
SELECT |
|
@ -76,31 +80,61 @@ async function list (ctx) { |
|
|
alarms.CurrentLevel AS CurrentLevel, |
|
|
alarms.CurrentLevel AS CurrentLevel, |
|
|
SourceTypeId, |
|
|
SourceTypeId, |
|
|
AlarmAdviceProblem, AlarmGroup, AlarmGroupUnit, AlarmAdviceProblem, |
|
|
AlarmAdviceProblem, AlarmGroup, AlarmGroupUnit, AlarmAdviceProblem, |
|
|
|
|
|
alarms.StructureId AS StructureId, |
|
|
${anxinyun}.t_structure.name AS StructureName, |
|
|
${anxinyun}.t_structure.name AS StructureName, |
|
|
StructureId, |
|
|
|
|
|
${anxinyun}.t_alarm_code.name AS AlarmCodeName |
|
|
${anxinyun}.t_alarm_code.name AS AlarmCodeName |
|
|
|
|
|
|
|
|
FROM |
|
|
FROM |
|
|
alarms |
|
|
alarms |
|
|
LEFT JOIN ${anxinyun}.t_structure |
|
|
LEFT JOIN ${anxinyun}.t_structure |
|
|
ON ${anxinyun}.t_structure.id = alarms.StructureId |
|
|
ON ${anxinyun}.t_structure.id = alarms.StructureId |
|
|
LEFT JOIN ${anxinyun}.t_alarm_code |
|
|
LEFT JOIN ${anxinyun}.t_alarm_code |
|
|
ON ${anxinyun}.t_alarm_code.code = alarms.AlarmTypeCode |
|
|
ON ${anxinyun}.t_alarm_code.code = alarms.AlarmTypeCode |
|
|
|
|
|
${whereOption.length ? 'WHERE ' + whereOption.join(' AND ') : ''} |
|
|
|
|
|
ORDER BY alarms.StartTime DESC |
|
|
|
|
|
${limit ? 'LIMIT ' + limit : ''} |
|
|
|
|
|
${limit && page ? 'OFFSET ' + parseInt(limit) * parseInt(page) : ''} |
|
|
`).toPromise();
|
|
|
`).toPromise();
|
|
|
|
|
|
|
|
|
// alarm_details.Time, alarm_details.Content
|
|
|
const confirmedAlarm = alarmRes |
|
|
|
|
|
// TODO: 开发临时注释
|
|
|
// LEFT JOIN alarm_details
|
|
|
// .filter(ar => ar.State && ar.State > 2)
|
|
|
// ON alarms.AlarmId = alarm_details.AlarmId
|
|
|
.map(ar => "'" + ar.AlarmId + "'") |
|
|
// AND alarm_details.Time = (
|
|
|
const confirmedAlarmDetailMax = confirmedAlarm.length ? |
|
|
// SELECT MAX(alarm_details.Time) from alarm_details WHERE AlarmId = alarms.AlarmId
|
|
|
await clickHouse.dataAlarm.query(` |
|
|
// )
|
|
|
SELECT |
|
|
|
|
|
max(Time) AS Time,AlarmId |
|
|
|
|
|
FROM |
|
|
|
|
|
alarm_details |
|
|
|
|
|
WHERE |
|
|
|
|
|
AlarmId IN (${confirmedAlarm.join(',')}) |
|
|
|
|
|
GROUP BY AlarmId |
|
|
|
|
|
`).toPromise() :
|
|
|
|
|
|
[]; |
|
|
|
|
|
|
|
|
// State = 3 是 自动恢复 / 4 是 人工恢复 / 其他数字 是 需要恢复
|
|
|
// State = 3 是 自动恢复 / 4 是 人工恢复 / 其他数字 是 需要恢复
|
|
|
// const SourceType = { 0: 'DTU', 1: '传感器', 2: '测点' };
|
|
|
// state = 2 是 等级提升 / 1 是持续产生 / 0 是首次产生
|
|
|
|
|
|
// SourceType 0: 'DTU' / 1: '传感器' / 2: '测点'
|
|
|
|
|
|
|
|
|
|
|
|
alarmRes.forEach(ar => { |
|
|
|
|
|
ar.pepProject = (anxinStruc.find(as => as.strucId == ar.StructureId) || |
|
|
|
|
|
{ |
|
|
|
|
|
// TODO: 开发临时添加
|
|
|
|
|
|
pepProject: [{ |
|
|
|
|
|
id: 999, |
|
|
|
|
|
name: '这是假的开发の数据,看到请拨打110', |
|
|
|
|
|
isdelete: 0, |
|
|
|
|
|
}] |
|
|
|
|
|
}).pepProject |
|
|
|
|
|
|
|
|
|
|
|
let corConfirmedData = (confirmedAlarmDetailMax.find(cdm => cdm.AlarmId == ar.AlarmId) || {}); |
|
|
|
|
|
if (corConfirmedData.AlarmState && corConfirmedData.AlarmState > 2) { |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
corConfirmedData = {} |
|
|
|
|
|
} |
|
|
|
|
|
ar.confirmedContent = 'corConfirmedData.Content' |
|
|
|
|
|
ar.confirmedTime = 'corConfirmedData.Time' |
|
|
|
|
|
}) |
|
|
ctx.body = alarmRes |
|
|
ctx.body = alarmRes |
|
|
} else { |
|
|
} else { |
|
|
ctx.body = [] |
|
|
ctx.body = [] |
|
|