wenlele 1 year ago
parent
commit
786f55a221
  1. 92
      api/app/lib/schedule/alarms_push.js

92
api/app/lib/schedule/alarms_push.js

@ -4,7 +4,7 @@ let isDev = false
// isDev = true // isDev = true
let proDebug = false let proDebug = false
proDebug = true // proDebug = true
module.exports = function (app, opts) { module.exports = function (app, opts) {
const alarmsPush = app.fs.scheduleInit( const alarmsPush = app.fs.scheduleInit(
@ -105,9 +105,13 @@ module.exports = function (app, opts) {
pLog(`curMinOfYear / ${curMinOfYear}`) pLog(`curMinOfYear / ${curMinOfYear}`)
for (let { dataValues: c } of configListRes) { for (let { dataValues: c } of configListRes) {
if (isDev && c.id != 86) { // if (isDev && c.id != 20) {
continue // continue
} // }
// if (isDev && c.name != '张掖持续') {
// continue
// }
if (c.tacticsParams && c.tactics) { if (c.tacticsParams && c.tactics) {
pLog(`当前运行EM配置:id=${c.id} name=${c.name}`); pLog(`当前运行EM配置:id=${c.id} name=${c.name}`);
@ -132,8 +136,8 @@ module.exports = function (app, opts) {
// 找对应的项企项目 // 找对应的项企项目
const corPepProject = const corPepProject =
pepProjectRes.find(p => p.id == poms.pepProjectId) pepProjectRes.find(p => p.id == poms.pepProjectId)
//添加true,优化成EM推送不需要关联项企项目的状态 //添加true,优化成EM推送不需要关联项企项目的状态
if (corPepProject && (c.timeType.some(ct => ct == corPepProject.construction_status_id)||true)) { if (corPepProject && (c.timeType.some(ct => ct == corPepProject.construction_status_id) || true)) {
pepProjectName_.push(corPepProject.project_name) pepProjectName_.push(corPepProject.project_name)
pepProject_name.push({ id: poms.id, anxinProjectId: poms.anxinProjectId, name: corPepProject.project_name }) pepProject_name.push({ id: poms.id, anxinProjectId: poms.anxinProjectId, name: corPepProject.project_name })
} else { } else {
@ -1246,7 +1250,9 @@ module.exports = function (app, opts) {
LEFT JOIN ${iota}.Device LEFT JOIN ${iota}.Device
ON Device.id = toString(t_device_sensor.iota_device_id) ON Device.id = toString(t_device_sensor.iota_device_id)
WHERE WHERE
t_sensor.structure IN (${[...dataAlarmG1StructureId, -1].join(',')}) t_sensor.structure IN (${[...dataAlarmG1StructureId, -1].join(',')
// 3025
})
AND AND
t_sensor.factor IN (${[...factorId, -1].join(',')}) t_sensor.factor IN (${[...factorId, -1].join(',')})
` `
@ -1285,7 +1291,9 @@ module.exports = function (app, opts) {
FROM FROM
alarms alarms
WHERE WHERE
alarms.StructureId In (${[...dataAlarmG1StructureId, ...dataAlarmStructureId, -1].join(',')}) alarms.StructureId In (${[...dataAlarmG1StructureId, ...dataAlarmStructureId, -1].join(',')
// 3025
})
AND AND
alarms.AlarmGroup IN (1,4,5) alarms.AlarmGroup IN (1,4,5)
AND AND
@ -1314,17 +1322,19 @@ module.exports = function (app, opts) {
// 这一步能被分配的告警应该也能最终体现在邮件中 // 这一步能被分配的告警应该也能最终体现在邮件中
let deviceRepeatMap = {} let deviceRepeatMap = {}
equipment.map(f => {
f.alarmDatas = [] equipment.map(equip => {
equip.alarmDatas = []
alarmDatas.map(r => { alarmDatas.map(r => {
if (r.sourceId == f.iotaDeviceId) { // !!! 这里这里 经常这两个id对不上导致告警没有推送
if (r.sourceId == equip.iotaDeviceId) {
if (!deviceRepeatMap[r.sourceId]) { if (!deviceRepeatMap[r.sourceId]) {
// 没有这个deviceId则不重复 // 没有这个deviceId则不重复
deviceRepeatMap[r.sourceId] = true deviceRepeatMap[r.sourceId] = true
f.alarmDatas.push({ equip.alarmDatas.push({
...r, ...r,
// 可能有的设备绑定了不同的测点 所以这里展示测点名称 // 可能有的设备绑定了不同的测点 所以这里展示测点名称
SourceName: r.SubDevices && r.SubDevices.length ? f. SourceName: r.SubDevices && r.SubDevices.length ? equip.
deviceName : r.SourceName deviceName : r.SourceName
}) })
} }
@ -1334,16 +1344,16 @@ module.exports = function (app, opts) {
}) })
// 为监测因素分配绑定的设备 // 为监测因素分配绑定的设备
factorData.map(v => { factorData.map(factor => {
v.devices = [] factor.devices = []
equipment.map(f => { equipment.map(f => {
if (v.id == f.factorId && v.structureId == f.structureId) { if (factor.id == f.factorId && factor.structureId == f.structureId) {
v.devices.push({ ...f }) factor.devices.push({ ...f })
} }
}) })
if (strucMap[v.structureId]) { if (strucMap[factor.structureId]) {
// 并为 strucMap 补充 factor 监测因素信息 // 并为 strucMap 补充 factor 监测因素信息
strucMap[v.structureId].factor.push({ ...v }) strucMap[factor.structureId].factor.push({ ...factor })
} }
}) })
@ -1506,35 +1516,35 @@ module.exports = function (app, opts) {
//调整结构物位置 //调整结构物位置
alarmData.map((h, hi) => { alarmData.map((h, hi) => {
if (h.projects && h.projects.length) { if (h.projects && h.projects.length) {
h.projects.map((x, xi) => { h.projects.map((x, xi) => {
let problem = 0; let problem = 0;
let count = 0; let count = 0;
if (x.factor && x.factor.length) { if (x.factor && x.factor.length) {
x.factor.map((f, fi) => { x.factor.map((f, fi) => {
problem += f.problem; problem += f.problem;
count += f.devicesLength; count += f.devicesLength;
}); });
// 如果 problem 等于 count,将该结构物移到前面 // 如果 problem 等于 count,将该结构物移到前面
if (problem === count) { if (problem === count) {
h.projects.splice(xi, 1); // 先移除当前元素 h.projects.splice(xi, 1); // 先移除当前元素
h.projects.unshift(x); // 然后将该结构物移到数组前面 h.projects.unshift(x); // 然后将该结构物移到数组前面
}
} }
} });
});
} }
}) })
alarmData.map((h, hi) => { alarmData.map((h, hi) => {
accumulate += h.rowspan || 0 accumulate += h.rowspan || 0
if (h.projects && h.projects.length) { if (h.projects && h.projects.length) {
h.projects.map((x, xi) => { h.projects.map((x, xi) => {
//用于设备全部中断做特殊标记 //用于设备全部中断做特殊标记
let problem=0 let problem = 0
let count=0 let count = 0
let showOne1 = (xi == 0) ? true : false let showOne1 = (xi == 0) ? true : false
if (x.factor && x.factor.length) { if (x.factor && x.factor.length) {
x.factor.map((f, fi) => { x.factor.map((f, fi) => {
problem+=f.problem problem += f.problem
count+=f.devicesLength count += f.devicesLength
let showOne2 = (fi == 0) ? true : false let showOne2 = (fi == 0) ? true : false
if (f.devices && f.devices.length) { if (f.devices && f.devices.length) {
f.devices.map((c, ci) => { f.devices.map((c, ci) => {
@ -1559,7 +1569,7 @@ module.exports = function (app, opts) {
break; break;
case 'Structure': case 'Structure':
if (showOne2 && showOne3 && showOne4) { if (showOne2 && showOne3 && showOne4) {
tableData +=problem==count?`<th style="color: red;" rowspan=${x.rowspan}>${x['name']+'('+'测点数据全部中断'+')' || ''}</th>`: `<th rowspan=${x.rowspan}>${x['name'] || ''}</th>` tableData += problem == count ? `<th style="color: red;" rowspan=${x.rowspan}>${x['name'] + '(' + '测点数据全部中断' + ')' || ''}</th>` : `<th rowspan=${x.rowspan}>${x['name'] || ''}</th>`
} }
break; break;
case 'factor': case 'factor':
@ -1748,8 +1758,8 @@ module.exports = function (app, opts) {
if (isDev) { if (isDev) {
// !开发测试用的数据 // !开发测试用的数据
// emails = ['gao.zhiyuan@free-sun.com.cn'] emails = ['gao.zhiyuan@free-sun.com.cn']
emails=['zhao.bin@free-sun.com.cn'] // emails = ['zhao.bin@free-sun.com.cn']
// emails = ['wen.lele@free-sun.com.cn'] // emails = ['wen.lele@free-sun.com.cn']
} }

Loading…
Cancel
Save