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