|
@ -15,7 +15,7 @@ module.exports = function (app, opts) { |
|
|
// interval: '12 0 0 0 */1 *',
|
|
|
// interval: '12 0 0 0 */1 *',
|
|
|
immediate: isDev, |
|
|
immediate: isDev, |
|
|
proRun: !isDev, |
|
|
proRun: !isDev, |
|
|
// proRun: true
|
|
|
// disabled: true
|
|
|
}, |
|
|
}, |
|
|
async () => { |
|
|
async () => { |
|
|
try { |
|
|
try { |
|
@ -140,11 +140,6 @@ module.exports = function (app, opts) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.log('corPomsProject', corPomsProject); |
|
|
|
|
|
console.log('pepProjectName_', pepProjectName_); |
|
|
|
|
|
console.log('pepProject_name', pepProject_name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const anxinProjectId = [...curAnxinProjectId] |
|
|
const anxinProjectId = [...curAnxinProjectId] |
|
|
// 查当前 poms 下的结构物 并把不包含的去掉
|
|
|
// 查当前 poms 下的结构物 并把不包含的去掉
|
|
|
// 可能有结构物已解绑
|
|
|
// 可能有结构物已解绑
|
|
@ -198,8 +193,6 @@ module.exports = function (app, opts) { |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
console.log('strucListRes', strucListRes); |
|
|
|
|
|
|
|
|
|
|
|
let strucThingId = [] |
|
|
let strucThingId = [] |
|
|
let strucMap = {} |
|
|
let strucMap = {} |
|
|
let searchStrucIds = strucListRes.map(s => { |
|
|
let searchStrucIds = strucListRes.map(s => { |
|
@ -505,10 +498,6 @@ module.exports = function (app, opts) { |
|
|
if (c.alarmSubType) dataAlarmSubType = dataAlarmSubType.concat(c.alarmSubType['device_exception']) |
|
|
if (c.alarmSubType) dataAlarmSubType = dataAlarmSubType.concat(c.alarmSubType['device_exception']) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('dataAlarmGroupOption', dataAlarmGroupOption); |
|
|
|
|
|
console.log('searchStrucIds', searchStrucIds); |
|
|
|
|
|
|
|
|
|
|
|
// 查数据告警 三警合一
|
|
|
// 查数据告警 三警合一
|
|
|
if (dataAlarmGroupOption.length && searchStrucIds.length) { |
|
|
if (dataAlarmGroupOption.length && searchStrucIds.length) { |
|
|
dataAlarmGroupOption.push(-1) |
|
|
dataAlarmGroupOption.push(-1) |
|
@ -742,7 +731,6 @@ module.exports = function (app, opts) { |
|
|
k: 'factor', |
|
|
k: 'factor', |
|
|
// f: (d) => {
|
|
|
// f: (d) => {
|
|
|
// // d.factor.join('<b/>')
|
|
|
// // d.factor.join('<b/>')
|
|
|
// // console.log(21211231131,d.factor);
|
|
|
|
|
|
// let data = []
|
|
|
// let data = []
|
|
|
// d.factor.map(f => data.push(f.name + '(' + f.breakData + '/' + f.sum + ')'))
|
|
|
// d.factor.map(f => data.push(f.name + '(' + f.breakData + '/' + f.sum + ')'))
|
|
|
// return data.join('<br/>')
|
|
|
// return data.join('<br/>')
|
|
@ -890,10 +878,10 @@ module.exports = function (app, opts) { |
|
|
let dataAlarmG45 = []; |
|
|
let dataAlarmG45 = []; |
|
|
let deviceStatistic = new Set() |
|
|
let deviceStatistic = new Set() |
|
|
let dataAlarmDetails = [] |
|
|
let dataAlarmDetails = [] |
|
|
if (proDebug) { |
|
|
|
|
|
console.log(`查得数据告警 ${dataAlarms.length} 条`); |
|
|
pLog(`查得数据告警 ${dataAlarms.length} 条`); |
|
|
console.log(dataAlarms); |
|
|
pLog(dataAlarms); |
|
|
} |
|
|
|
|
|
if (dataAlarms.length) { |
|
|
if (dataAlarms.length) { |
|
|
const alarmIds = dataAlarms |
|
|
const alarmIds = dataAlarms |
|
|
.map(ar => "'" + ar.AlarmId + "'") |
|
|
.map(ar => "'" + ar.AlarmId + "'") |
|
@ -904,12 +892,8 @@ module.exports = function (app, opts) { |
|
|
AND AlarmState = 0 |
|
|
AND AlarmState = 0 |
|
|
`).toPromise()
|
|
|
`).toPromise()
|
|
|
} |
|
|
} |
|
|
if (proDebug) { |
|
|
|
|
|
console.log(`查得数据告警详情数据 ${dataAlarmDetails.length} 条`); |
|
|
pLog(`查得数据告警详情数据 ${dataAlarmDetails.length} 条`); |
|
|
} |
|
|
|
|
|
if (proDebug) { |
|
|
|
|
|
console.log(`pomsStrucFactorId:`, pomsStrucFactorId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let deviceIds = new Set() |
|
|
let deviceIds = new Set() |
|
|
for (let d of dataAlarms) { |
|
|
for (let d of dataAlarms) { |
|
@ -1135,15 +1119,15 @@ module.exports = function (app, opts) { |
|
|
const factorData = await clickHouse.anxinyun.query( |
|
|
const factorData = await clickHouse.anxinyun.query( |
|
|
`
|
|
|
`
|
|
|
SELECT |
|
|
SELECT |
|
|
t_structure_factor.structure AS structureId, |
|
|
t_structure_factor.structure AS structureId, |
|
|
t_factor.name AS name, |
|
|
t_factor.name AS name, |
|
|
t_factor.id AS id |
|
|
t_factor.id AS id |
|
|
FROM |
|
|
FROM |
|
|
t_structure_factor |
|
|
t_structure_factor |
|
|
LEFT JOIN t_factor |
|
|
LEFT JOIN t_factor |
|
|
ON t_factor.id = t_structure_factor.factor |
|
|
ON t_factor.id = t_structure_factor.factor |
|
|
WHERE |
|
|
WHERE |
|
|
t_structure_factor.structure IN (${[...dataAlarmG1StructureId]}) |
|
|
t_structure_factor.structure IN (${[...dataAlarmG1StructureId]}) |
|
|
` |
|
|
` |
|
|
).toPromise() || [] |
|
|
).toPromise() || [] |
|
|
|
|
|
|
|
@ -1163,7 +1147,7 @@ module.exports = function (app, opts) { |
|
|
LEFT JOIN t_device_sensor |
|
|
LEFT JOIN t_device_sensor |
|
|
ON t_device_sensor.sensor = t_sensor.id |
|
|
ON t_device_sensor.sensor = t_sensor.id |
|
|
WHERE |
|
|
WHERE |
|
|
t_sensor.structure IN (${[...dataAlarmG1StructureId]}) |
|
|
t_sensor.structure IN (${[...dataAlarmG1StructureId]},) |
|
|
AND |
|
|
AND |
|
|
t_sensor.factor IN (${factorId.join(',')}) |
|
|
t_sensor.factor IN (${factorId.join(',')}) |
|
|
` |
|
|
` |
|
@ -1180,7 +1164,8 @@ module.exports = function (app, opts) { |
|
|
alarms.StartTime AS StartTime, |
|
|
alarms.StartTime AS StartTime, |
|
|
alarms.SourceName AS SourceName, |
|
|
alarms.SourceName AS SourceName, |
|
|
alarms.AlarmCode AS AlarmCode, |
|
|
alarms.AlarmCode AS AlarmCode, |
|
|
alarms.SourceTypeId AS SourceTypeId |
|
|
alarms.SourceTypeId AS SourceTypeId, |
|
|
|
|
|
alarms.StructureId AS StructureId |
|
|
FROM |
|
|
FROM |
|
|
alarms |
|
|
alarms |
|
|
WHERE |
|
|
WHERE |
|
@ -1193,11 +1178,14 @@ module.exports = function (app, opts) { |
|
|
).toPromise() || [] |
|
|
).toPromise() || [] |
|
|
|
|
|
|
|
|
// 为设备分配自己产生的告警数据
|
|
|
// 为设备分配自己产生的告警数据
|
|
|
|
|
|
let matchedAlarmIds = [] |
|
|
|
|
|
// 这一步能被分配的告警应该也能最终体现在邮件中
|
|
|
equipment.map(f => { |
|
|
equipment.map(f => { |
|
|
f.alarmDatas = [] |
|
|
f.alarmDatas = [] |
|
|
alarmDatas.map(r => { |
|
|
alarmDatas.map(r => { |
|
|
if (r.sourceId == f.iotaDeviceId) { |
|
|
if (r.sourceId == f.iotaDeviceId) { |
|
|
f.alarmDatas.push({ ...r }) |
|
|
f.alarmDatas.push({ ...r }) |
|
|
|
|
|
matchedAlarmIds.push(r.alarmId) |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
@ -1238,9 +1226,60 @@ module.exports = function (app, opts) { |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// console.log('数据组合', JSON.stringify(pepProject_name));
|
|
|
|
|
|
pLog('数据组合' + JSON.stringify(pepProject_name)) |
|
|
pLog('数据组合' + JSON.stringify(pepProject_name)) |
|
|
|
|
|
|
|
|
|
|
|
// 上面的代码自内而外构建数据
|
|
|
|
|
|
// 下面的逻辑自外向内!!!
|
|
|
|
|
|
|
|
|
|
|
|
// 处理那些没有被匹配到的告警信息
|
|
|
|
|
|
// 将设备没有绑定到测点的告警也推出去
|
|
|
|
|
|
for (let a of alarmDatas) { |
|
|
|
|
|
if (!matchedAlarmIds.includes(a.alarmId)) { |
|
|
|
|
|
let curStruc = strucMap[a.StructureId] |
|
|
|
|
|
if (curStruc) { |
|
|
|
|
|
// curStruc 可以推出 告警属于哪个 project -> pomsProject
|
|
|
|
|
|
let curProject = pepProject_name.filter(p => p.anxinProjectId && p.anxinProjectId.includes(curStruc.projectId)); |
|
|
|
|
|
for (let cp of curProject) { |
|
|
|
|
|
// cp.projects 是结构物信息
|
|
|
|
|
|
let curStruc = cp.projects.find(cpp => cpp.id == a.StructureId) |
|
|
|
|
|
if (!curStruc) { |
|
|
|
|
|
console.error(`没有查到结构物信息:${a.StructureId}?!不应该不应该!`); |
|
|
|
|
|
} else { |
|
|
|
|
|
// let emptyFactor = { id: -1 }
|
|
|
|
|
|
let emptyFactor = curStruc.factor.find(f => f.id == -1) |
|
|
|
|
|
if (!emptyFactor) { |
|
|
|
|
|
curStruc.factor.push({ |
|
|
|
|
|
id: -1, |
|
|
|
|
|
devices: [{ |
|
|
|
|
|
alarmDatas: [ |
|
|
|
|
|
{ ...a } |
|
|
|
|
|
], |
|
|
|
|
|
iotaDeviceId: a.sourceId, |
|
|
|
|
|
name: a.SourceName, |
|
|
|
|
|
structureId: a.StructureId, |
|
|
|
|
|
}] |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
let curDevice = emptyFactor.devices.find(d => d.iotaDeviceId == a.sourceId) |
|
|
|
|
|
if (!curDevice) { |
|
|
|
|
|
emptyFactor.devices.push({ |
|
|
|
|
|
alarmDatas: [ |
|
|
|
|
|
{ ...a } |
|
|
|
|
|
], |
|
|
|
|
|
iotaDeviceId: a.sourceId, |
|
|
|
|
|
name: a.SourceName, |
|
|
|
|
|
structureId: a.StructureId, |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
curDevice.alarmDatas.push({ ...a }) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
pepProject_name.forEach(h => { |
|
|
pepProject_name.forEach(h => { |
|
|
let rowspan1 = 0 |
|
|
let rowspan1 = 0 |
|
|
if (h.projects.length) { |
|
|
if (h.projects.length) { |
|
@ -1301,7 +1340,7 @@ module.exports = function (app, opts) { |
|
|
h.rowspan = rowspan1 |
|
|
h.rowspan = rowspan1 |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
dataAlarmG1 = pepProject_name.filter(b => b.projects && b.projects.length > 0) || [] |
|
|
dataAlarmG1 = pepProject_name //.filter(b => b.projects && b.projects.length > 0) || []
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1359,7 +1398,7 @@ module.exports = function (app, opts) { |
|
|
break; |
|
|
break; |
|
|
case 'factor': |
|
|
case 'factor': |
|
|
if (showOne3 && showOne4) { |
|
|
if (showOne3 && showOne4) { |
|
|
tableData += `<th rowspan=${f.rowspan}>${(f['name'] + '(' + f.problem + '/' + f.devicesLength + ')') || ''}</th>` |
|
|
tableData += `<th rowspan=${f.rowspan}>${((f['name'] || '--') + '(' + f.problem + '/' + f.devicesLength + ')') || ''}</th>` |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case 'SourceName': |
|
|
case 'SourceName': |
|
@ -1405,7 +1444,6 @@ module.exports = function (app, opts) { |
|
|
alarmHtml += `<tr><td colspan="${alarmTitleArr.length}" style="background-color:#ffff00">` + tableTitlePrefix + '</td></tr>' |
|
|
alarmHtml += `<tr><td colspan="${alarmTitleArr.length}" style="background-color:#ffff00">` + tableTitlePrefix + '</td></tr>' |
|
|
alarmHtml += alarmHtmlTitle |
|
|
alarmHtml += alarmHtmlTitle |
|
|
alarmHtml += alarmContent |
|
|
alarmHtml += alarmContent |
|
|
console.log('表格结果', alarmContent); |
|
|
|
|
|
alarmHtml += '</table><br/>' |
|
|
alarmHtml += '</table><br/>' |
|
|
|
|
|
|
|
|
return alarmHtml |
|
|
return alarmHtml |
|
@ -1525,9 +1563,7 @@ module.exports = function (app, opts) { |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (proDebug) { |
|
|
pLog(`ifEmailSend:${ifEmailSend}`); |
|
|
console.log('ifEmailSend:', ifEmailSend); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (ifEmailSend) { |
|
|
if (ifEmailSend) { |
|
|
// 查接收人的信息
|
|
|
// 查接收人的信息
|
|
@ -1551,9 +1587,7 @@ module.exports = function (app, opts) { |
|
|
emails = ['1650192445@qq.com'] |
|
|
emails = ['1650192445@qq.com'] |
|
|
// emails = ['wen.lele@free-sun.com.cn']
|
|
|
// emails = ['wen.lele@free-sun.com.cn']
|
|
|
} |
|
|
} |
|
|
if (proDebug) { |
|
|
|
|
|
console.log('emails', emails); |
|
|
|
|
|
} |
|
|
|
|
|
if (emails.length) { |
|
|
if (emails.length) { |
|
|
pLog(`推送给${emails.length}人`); |
|
|
pLog(`推送给${emails.length}人`); |
|
|
pLog(moment().format()) |
|
|
pLog(moment().format()) |
|
|