|
|
@ -407,8 +407,7 @@ module.exports = function (app, opts) { |
|
|
|
ON anxinStation.id = anxinIpcStation.station |
|
|
|
ORDER BY cameraAlarm.createTime DESC |
|
|
|
` |
|
|
|
).toPromise() : [] |
|
|
|
|
|
|
|
).toPromise() : [] |
|
|
|
let returnD = [] |
|
|
|
let positionD = {} |
|
|
|
// 每个设备一个告警
|
|
|
@ -526,7 +525,7 @@ module.exports = function (app, opts) { |
|
|
|
dataAlarmSubType_.push(-1) |
|
|
|
dataAlarmOption.push(`AlarmGroupUnit IN (${dataAlarmSubType_.join(',')})`) |
|
|
|
} |
|
|
|
|
|
|
|
//安心云
|
|
|
|
dataAlarms = |
|
|
|
!c.alarmSubType || dataAlarmSubType_.length ? |
|
|
|
await clickHouse.dataAlarm.query(` |
|
|
@ -541,7 +540,25 @@ module.exports = function (app, opts) { |
|
|
|
${dataAlarmOption.length ? ' AND ' + dataAlarmOption.join(' AND ') : ''} |
|
|
|
ORDER BY StartTime DESC |
|
|
|
`).toPromise() : []
|
|
|
|
//本地化
|
|
|
|
const dataAlarmsLocal=!c.alarmSubType || dataAlarmSubType_.length ? |
|
|
|
await clickHouse.dataAlarm.query(` |
|
|
|
SELECT * FROM alarms |
|
|
|
LEFT JOIN sensors |
|
|
|
AS anxinStation |
|
|
|
ON toString(anxinStation.SensorId)= alarms.SourceId |
|
|
|
AND alarms.SourceTypeId = 2 |
|
|
|
WHERE |
|
|
|
${`State NOT IN (3, 4) AND `} |
|
|
|
StructureId IN (${searchStrucIds.join(',')}) |
|
|
|
${dataAlarmOption.length ? ' AND ' + dataAlarmOption.join(' AND ') : ''} |
|
|
|
ORDER BY StartTime DESC |
|
|
|
`).toPromise() : []
|
|
|
|
//合并本地化和安心云的告警
|
|
|
|
dataAlarms=[...dataAlarms,...dataAlarmsLocal] |
|
|
|
console.log('合并的告警列表(安心云+本地)',dataAlarms,dataAlarmsLocal) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let dataAlarmTitle2 = [{ |
|
|
|
n: '项目', |
|
|
@ -901,7 +918,7 @@ module.exports = function (app, opts) { |
|
|
|
|
|
|
|
pLog(`查得数据告警 ${dataAlarms.length} 条`); |
|
|
|
// pLog(dataAlarms);
|
|
|
|
|
|
|
|
console.log('dataAlarms111',dataAlarms) |
|
|
|
if (dataAlarms.length) { |
|
|
|
const alarmIds = dataAlarms |
|
|
|
.map(ar => "'" + ar.AlarmId + "'") |
|
|
@ -917,6 +934,7 @@ module.exports = function (app, opts) { |
|
|
|
|
|
|
|
let deviceIds = new Set() |
|
|
|
for (let d of dataAlarms) { |
|
|
|
console.log('xxxxx1111',d) |
|
|
|
d = { ...d, stationId: d.id } |
|
|
|
|
|
|
|
/** 按监测因素筛选 且为测点告警 */ |
|
|
@ -1051,7 +1069,6 @@ module.exports = function (app, opts) { |
|
|
|
// 注1 END
|
|
|
|
|
|
|
|
} else if (d.AlarmGroup == 3) { |
|
|
|
|
|
|
|
/** 按监测因项 factor-item 的名称筛选*/ |
|
|
|
if (pomsStrucFactorId) { |
|
|
|
// 兼容之前的设置 有这个信息才进行判断
|
|
|
@ -1088,6 +1105,7 @@ module.exports = function (app, opts) { |
|
|
|
|
|
|
|
deviceStatistic.add(d.SourceId) |
|
|
|
} |
|
|
|
console.log('xxxxx1112',c) |
|
|
|
if (c.tactics == 'abnormal_rate') { |
|
|
|
pLog(`异常设备数量 - ${deviceStatistic.size}`) |
|
|
|
pLog(`异常视频告警数量 - ${videoAlarms.length}`) |
|
|
@ -1105,6 +1123,7 @@ module.exports = function (app, opts) { |
|
|
|
} |
|
|
|
// 注1
|
|
|
|
if (apMergeDeVeAnxinProjectId_.length || isDev) { |
|
|
|
console.log('xascascasca',isDev) |
|
|
|
for (let a of videoAlarms) { |
|
|
|
let existStruc = a.struc.find(asc => apMergeDeVeAlarms[asc.id] || isDev) |
|
|
|
if (existStruc) { |
|
|
@ -1135,13 +1154,23 @@ module.exports = function (app, opts) { |
|
|
|
` |
|
|
|
|
|
|
|
let dataAlarmG1Data = dataAlarms.filter(a => a.AlarmGroup == 1) |
|
|
|
console.log('dataAlarmG1Datasssss',dataAlarms) |
|
|
|
console.log('dataAlarmG1Datasssss',dataAlarmG1Data.length) |
|
|
|
if (dataAlarmG1Data.length) { |
|
|
|
//安心云项目是structureId数组
|
|
|
|
let dataAlarmG1StructureId = new Set() |
|
|
|
//本地化项目structureId数组
|
|
|
|
let dataAlarmStructureId = new Set() |
|
|
|
dataAlarmG1Data.map(c => { |
|
|
|
dataAlarmG1StructureId.add(c.StructureId) |
|
|
|
if(c.project){ |
|
|
|
dataAlarmStructureId.add(c.StructureId) |
|
|
|
}else{ |
|
|
|
dataAlarmG1StructureId.add(c.StructureId) |
|
|
|
} |
|
|
|
}) |
|
|
|
//查询结构物的监测因素
|
|
|
|
const factorData = await clickHouse.anxinyun.query( |
|
|
|
console.log('xxx1qqqq',dataAlarmG1StructureId) |
|
|
|
//查询结构物的监测因素(安心云)
|
|
|
|
let factorData = await clickHouse.anxinyun.query( |
|
|
|
`
|
|
|
|
SELECT |
|
|
|
t_structure_factor.structure AS structureId, |
|
|
@ -1155,14 +1184,23 @@ module.exports = function (app, opts) { |
|
|
|
t_structure_factor.structure IN (${[...dataAlarmG1StructureId]}) |
|
|
|
` |
|
|
|
).toPromise() || [] |
|
|
|
|
|
|
|
//查询结构物的监测因素(本地化项目)
|
|
|
|
let factorDataLocal = await clickHouse.dataAlarm.query( |
|
|
|
` SELECT
|
|
|
|
StructId AS structureId,SafetyFactorTypeName AS name,SafetyFactorTypeId AS id |
|
|
|
FROM |
|
|
|
sensors |
|
|
|
WHERE sensors.StructId in (${[...dataAlarmStructureId]})` |
|
|
|
).toPromise() || [] |
|
|
|
console.log('factorDataLocal',factorDataLocal) |
|
|
|
//合并(安心云+本地化项目)
|
|
|
|
factorData=[...factorDataLocal,...factorData] |
|
|
|
let factorId = factorData.map(f => f.id) |
|
|
|
|
|
|
|
//查询结构物对应的测点
|
|
|
|
const equipment = await clickHouse.anxinyun.query( |
|
|
|
`
|
|
|
|
let factorIdLocal=factorIdLocal.map(f => f.id) |
|
|
|
//查询结构物对应的测点(安心云)
|
|
|
|
let equipment = await clickHouse.dataAlarm.query( |
|
|
|
`
|
|
|
|
SELECT |
|
|
|
t_sensor.id AS id, |
|
|
|
t_sensor.name AS name, |
|
|
|
t_sensor.structure AS structureId, |
|
|
|
t_sensor.factor AS factorId, |
|
|
@ -1177,8 +1215,21 @@ module.exports = function (app, opts) { |
|
|
|
t_sensor.factor IN (${factorId.join(',')}) |
|
|
|
` |
|
|
|
).toPromise() || [] |
|
|
|
|
|
|
|
|
|
|
|
//查询结构物对应的测点(本地化)
|
|
|
|
let equipmentLocal = await clickHouse.anxinyun.query( |
|
|
|
` SELECT
|
|
|
|
SensorLocationDescription AS name, |
|
|
|
StructId AS structureId, |
|
|
|
SafetyFactorTypeId AS factorId, |
|
|
|
SensorId AS iotaDeviceId |
|
|
|
FROM sensors |
|
|
|
WHERE sensors.StructId IN (${[...dataAlarmStructureId]},) |
|
|
|
AND sensors.SafetyFactorTypeId IN (${factorIdLocal.join(',')}) |
|
|
|
`
|
|
|
|
).toPromise() || [] |
|
|
|
console.log('equipmentLocal',equipmentLocal) |
|
|
|
//合并本地化数据+安心云数据
|
|
|
|
equipment=[...equipment,...equipmentLocal] |
|
|
|
const alarmDataRes = await clickHouse.dataAlarm.query( |
|
|
|
`
|
|
|
|
SELECT |
|
|
@ -1194,7 +1245,7 @@ module.exports = function (app, opts) { |
|
|
|
FROM |
|
|
|
alarms |
|
|
|
WHERE |
|
|
|
alarms.StructureId In (${[...dataAlarmG1StructureId]}) |
|
|
|
alarms.StructureId In (${[...dataAlarmG1StructureId,...dataAlarmStructureId]}) |
|
|
|
AND |
|
|
|
alarms.AlarmGroup = 1 |
|
|
|
AND |
|
|
@ -1203,7 +1254,7 @@ module.exports = function (app, opts) { |
|
|
|
// ,
|
|
|
|
// alarms.subStations AS subStations
|
|
|
|
).toPromise() || [] |
|
|
|
|
|
|
|
console.log('alarmDataRes111',alarmDataRes) |
|
|
|
let alarmDatas = [] |
|
|
|
for (let alarms of alarmDataRes) { |
|
|
|
if (alarms.subStations && alarms.subStations.length) { |
|
|
@ -1614,6 +1665,7 @@ module.exports = function (app, opts) { |
|
|
|
`).toPromise()
|
|
|
|
: [] |
|
|
|
let receiverId = [] |
|
|
|
console.log('接收邮件的人',receiverRes) |
|
|
|
let emails = receiverRes.reduce((arr, r) => { |
|
|
|
if (r.email) { |
|
|
|
arr.push(r.email) |
|
|
@ -1625,6 +1677,7 @@ module.exports = function (app, opts) { |
|
|
|
if (isDev) { |
|
|
|
// !开发测试用的数据
|
|
|
|
emails = ['1650192445@qq.com'] |
|
|
|
// emails=['zhao.bin@free-sun.com.cn']
|
|
|
|
// emails = ['wen.lele@free-sun.com.cn']
|
|
|
|
} |
|
|
|
|
|
|
|