diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index 658dd77..6c3492b 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -829,28 +829,47 @@ module.exports = function (app, opts) { t_sensor.name AS name, t_sensor.structure AS structureId, t_sensor.factor AS factorId, - t_device_sensor.iota_device_id AS iotaDeviceId, - ${dataAlarm}.alarms.State AS state, - ${dataAlarm}.alarms.AlarmGroup AS alarmGroup, - ${dataAlarm}.alarms.SourceId AS sourceId + t_device_sensor.iota_device_id AS iotaDeviceId FROM t_sensor LEFT JOIN t_device_sensor ON t_device_sensor.sensor = t_sensor.id - LEFT JOIN ${dataAlarm}.alarms - ON ${dataAlarm}.alarms.SourceId = t_device_sensor.iota_device_id WHERE t_sensor.structure = (${d.StructureId}) AND t_sensor.factor IN (${factorId.join(',')}) + ` + ).toPromise() || [] + + const alarmDatas = await clickHouse.dataAlarm.query( + ` + SELECT + alarms.id AS id, + alarms.State AS state, + alarms.AlarmGroup AS alarmGroup, + alarms.SourceId AS sourceId + FROM + alarms + WHERE + alarms.StructureId = (${d.StructureId}) + AND + alarms.AlarmGroup = 1 AND - ${dataAlarm}.alarms.AlarmGroup = 1 + alarms.State < 3 ` ).toPromise() || [] + + equipment.map(r => { + alarmDatas.map(u => { + if (r.iotaDeviceId == u.sourceId) { + r.sourceId = u.sourceId + } + }) + }) d.factor = [] factorData.map(c => { - let breakData = equipment.filter(m => (m.iotaDeviceId && m.sourceId && m.state < 3 && m.alarmGroup == 1 && m.factorId == c.id)) + let breakData = equipment.filter(m => (m.factorId == c.id && m.sourceId)) d.factor.push({ name: c.name, sum: equipment.length,