|
|
@ -1,7 +1,7 @@ |
|
|
|
const moment = require('moment') |
|
|
|
|
|
|
|
let isDev = false |
|
|
|
// isDev = true
|
|
|
|
// let isDev = true
|
|
|
|
|
|
|
|
let proDebug = false |
|
|
|
proDebug = true |
|
|
@ -19,6 +19,7 @@ module.exports = function (app, opts) { |
|
|
|
const { apMergeDeVeAnxinProjectId = '' } = opts |
|
|
|
const { clickHouse } = app.fs |
|
|
|
const { database: anxinyun } = clickHouse.anxinyun.opts.config |
|
|
|
const { database: dataAlarm } = clickHouse.dataAlarm.opts.config |
|
|
|
const { pushBySms, pushByEmail, sendNoticeToWeb } = app.fs.utils |
|
|
|
const curMinOfYear = moment().diff(moment().startOf('year'), 'minutes') |
|
|
|
const configListRes = await models.AlarmPushConfig.findAll({ |
|
|
@ -68,11 +69,21 @@ module.exports = function (app, opts) { |
|
|
|
if (!minute && minute != 0) { |
|
|
|
return minute |
|
|
|
} |
|
|
|
let title = '' |
|
|
|
let dm = 24 * 60 |
|
|
|
let d = Math.floor(minute / dm) |
|
|
|
let h = Math.floor(minute % dm / 60) |
|
|
|
let m = (minute % dm) % 60 |
|
|
|
return `${d}天${h}时${m}分` |
|
|
|
if (d) { |
|
|
|
title = d + '天' |
|
|
|
} |
|
|
|
if (h) { |
|
|
|
title = title + h + '时' |
|
|
|
} |
|
|
|
if (h) { |
|
|
|
title = title + m + '分' |
|
|
|
} |
|
|
|
return title |
|
|
|
} |
|
|
|
|
|
|
|
for (let { dataValues: c } of configListRes) { |
|
|
@ -167,7 +178,8 @@ module.exports = function (app, opts) { |
|
|
|
|
|
|
|
// !开发测试用的数据
|
|
|
|
if (isDev) { |
|
|
|
searchStrucIds = searchStrucIds.concat([991, 1052, 700]) |
|
|
|
// searchStrucIds = searchStrucIds.concat([991, 1052, 700])
|
|
|
|
searchStrucIds = searchStrucIds.concat([27, 4003, 700]) |
|
|
|
} |
|
|
|
|
|
|
|
if (searchStrucIds.length) { |
|
|
@ -541,6 +553,80 @@ module.exports = function (app, opts) { |
|
|
|
} |
|
|
|
},] |
|
|
|
|
|
|
|
let dataLnterruptTitle = [{ |
|
|
|
n: '项目', |
|
|
|
k: '', |
|
|
|
v: pepProjectName |
|
|
|
}, { |
|
|
|
n: '结构物', |
|
|
|
k: '', |
|
|
|
f: (d) => { |
|
|
|
return (strucMap[d.StructureId] || { name: '' }).name |
|
|
|
// return (strucListRes.find(s => s.id == d.StructureId) || { name: '' }).name
|
|
|
|
} |
|
|
|
}, { |
|
|
|
n: '监测因素(中断比例)', |
|
|
|
k: '', |
|
|
|
f: (d) => { |
|
|
|
// d.factor.join('<b/>')
|
|
|
|
// console.log(21211231131,d.factor);
|
|
|
|
let data=[] |
|
|
|
d.factor.map(f => data.push(f.name + '(' + f.breakData + '/' + f.sum + ')')) |
|
|
|
return data.join('<br/>') |
|
|
|
} |
|
|
|
}, { |
|
|
|
n: '告警源名称', |
|
|
|
k: 'SourceName' |
|
|
|
}, { |
|
|
|
n: '告警源类型', |
|
|
|
k: '', |
|
|
|
f: (d) => { |
|
|
|
switch (d.SourceTypeId) { |
|
|
|
case 0: |
|
|
|
return 'DTU' |
|
|
|
case 1: |
|
|
|
return '传感器' |
|
|
|
case 2: |
|
|
|
return '测点' |
|
|
|
default: |
|
|
|
return '' |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
n: '告警信息', |
|
|
|
k: 'AlarmContent' |
|
|
|
}, { |
|
|
|
n: '告警等级(当前)', |
|
|
|
k: '', |
|
|
|
f: (d) => { |
|
|
|
switch (d.CurrentLevel) { |
|
|
|
case 1: |
|
|
|
return '一级' |
|
|
|
case 2: |
|
|
|
return '二级' |
|
|
|
case 3: |
|
|
|
return '三级' |
|
|
|
default: |
|
|
|
return '' |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
n: '持续时间', |
|
|
|
k: '', |
|
|
|
f: (d) => { |
|
|
|
return d.StartTime ? |
|
|
|
'超过' + calcMinute2DHM(moment().diff(moment(d.StartTime), 'minutes')) : '' |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
n: '中断时间', |
|
|
|
k: '', |
|
|
|
f: (d) => { |
|
|
|
return d.StartTime ? |
|
|
|
moment(d.StartTime).format('YYYY-MM-DD HH:mm:ss') : '' |
|
|
|
} |
|
|
|
},] |
|
|
|
|
|
|
|
let videoAlarmTitle = [{ |
|
|
|
n: '项目', |
|
|
|
k: '', |
|
|
@ -715,7 +801,64 @@ module.exports = function (app, opts) { |
|
|
|
// }
|
|
|
|
|
|
|
|
if (d.AlarmGroup == 1) { |
|
|
|
if (d.StructureId) { |
|
|
|
//查询结构物的监测因素
|
|
|
|
const factorData = await clickHouse.anxinyun.query( |
|
|
|
`
|
|
|
|
SELECT |
|
|
|
t_structure_factor.structure AS structureId, |
|
|
|
t_factor.name AS name, |
|
|
|
t_factor.id AS id |
|
|
|
FROM |
|
|
|
t_structure_factor |
|
|
|
LEFT JOIN t_factor |
|
|
|
ON t_factor.id = t_structure_factor.factor |
|
|
|
WHERE |
|
|
|
t_structure_factor.structure = (${d.StructureId}) |
|
|
|
|
|
|
|
` |
|
|
|
).toPromise() || [] |
|
|
|
let factorId = factorData.map(f => f.id) |
|
|
|
|
|
|
|
//查询结构物对应的设备
|
|
|
|
const equipment = await clickHouse.anxinyun.query( |
|
|
|
`
|
|
|
|
SELECT |
|
|
|
t_sensor.id AS id, |
|
|
|
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 |
|
|
|
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() || [] |
|
|
|
|
|
|
|
d.factor = [] |
|
|
|
factorData.map(c => { |
|
|
|
let breakData = equipment.filter(m => (m.iotaDeviceId && m.sourceId && m.state < 3 && m.alarmGroup == 1 && m.factorId == c.id)) |
|
|
|
d.factor.push({ |
|
|
|
name: c.name, |
|
|
|
sum: equipment.length, |
|
|
|
breakData: breakData.length |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dataAlarmG1.push(d) |
|
|
|
|
|
|
|
} else if (d.AlarmGroup == 2) { |
|
|
|
dataAlarmG2.push(d) |
|
|
|
/** 注1 |
|
|
@ -862,7 +1005,7 @@ module.exports = function (app, opts) { |
|
|
|
html += packageAlarmData2Table({ |
|
|
|
titlePrefix: '数据中断', |
|
|
|
alarmData: dataAlarmG1, |
|
|
|
alarmTitleArr: dataAlarmTitle, |
|
|
|
alarmTitleArr: dataLnterruptTitle, |
|
|
|
}) |
|
|
|
} |
|
|
|
if (c.alarmType.includes('data_exception')) { |
|
|
@ -990,7 +1133,8 @@ module.exports = function (app, opts) { |
|
|
|
|
|
|
|
if (isDev) { |
|
|
|
// !开发测试用的数据
|
|
|
|
emails = ['1650192445@qq.com'] |
|
|
|
// emails = ['1650192445@qq.com']
|
|
|
|
emails = ['2798774060@qq.com'] |
|
|
|
} |
|
|
|
|
|
|
|
if (emails.length) { |
|
|
|