|
@ -1,7 +1,7 @@ |
|
|
const moment = require('moment') |
|
|
const moment = require('moment') |
|
|
|
|
|
|
|
|
let isDev = false |
|
|
// let isDev = false
|
|
|
// let isDev = true
|
|
|
let isDev = true |
|
|
|
|
|
|
|
|
let proDebug = false |
|
|
let proDebug = false |
|
|
proDebug = true |
|
|
proDebug = true |
|
@ -9,7 +9,8 @@ proDebug = true |
|
|
module.exports = function (app, opts) { |
|
|
module.exports = function (app, opts) { |
|
|
const alarmsPush = app.fs.scheduleInit( |
|
|
const alarmsPush = app.fs.scheduleInit( |
|
|
{ |
|
|
{ |
|
|
interval: '12 */1 * * * *', |
|
|
// interval: '12 */1 * * * *',
|
|
|
|
|
|
interval: '12 0 0 0 */1 *', |
|
|
immediate: isDev, |
|
|
immediate: isDev, |
|
|
proRun: !isDev, |
|
|
proRun: !isDev, |
|
|
}, |
|
|
}, |
|
@ -87,6 +88,7 @@ module.exports = function (app, opts) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (let { dataValues: c } of configListRes) { |
|
|
for (let { dataValues: c } of configListRes) { |
|
|
|
|
|
|
|
|
if (c.tacticsParams && c.tactics) { |
|
|
if (c.tacticsParams && c.tactics) { |
|
|
if (proDebug) { |
|
|
if (proDebug) { |
|
|
console.log(`当前运行EM配置:id=${c.id} name=${c.name}`); |
|
|
console.log(`当前运行EM配置:id=${c.id} name=${c.name}`); |
|
@ -95,13 +97,12 @@ module.exports = function (app, opts) { |
|
|
const { strucId, pomsProjectId, pomsStrucFactorId } = c |
|
|
const { strucId, pomsProjectId, pomsStrucFactorId } = c |
|
|
const { interval, deviceProportion } = c.tacticsParams |
|
|
const { interval, deviceProportion } = c.tacticsParams |
|
|
|
|
|
|
|
|
if ( |
|
|
if (curMinOfYear % parseInt(interval) == 0 || isDev) { |
|
|
curMinOfYear % parseInt(interval) == 0 || isDev |
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
|
|
|
const corPomsProject = pomsProjectRes.filter(poms => pomsProjectId.includes(poms.id)) |
|
|
const corPomsProject = pomsProjectRes.filter(poms => pomsProjectId.includes(poms.id)) |
|
|
let curAnxinProjectId = new Set() |
|
|
let curAnxinProjectId = new Set() |
|
|
let pepProjectName_ = [] |
|
|
let pepProjectName_ = [] |
|
|
|
|
|
let pepProject_name = [] |
|
|
for (let { dataValues: poms } of corPomsProject) { |
|
|
for (let { dataValues: poms } of corPomsProject) { |
|
|
if (poms.pepProjectId) { |
|
|
if (poms.pepProjectId) { |
|
|
// 找对应的项企项目
|
|
|
// 找对应的项企项目
|
|
@ -109,13 +110,18 @@ module.exports = function (app, opts) { |
|
|
pepProjectRes.find(p => p.id == poms.pepProjectId) |
|
|
pepProjectRes.find(p => p.id == poms.pepProjectId) |
|
|
if (corPepProject && c.timeType.some(ct => ct == corPepProject.construction_status_id)) { |
|
|
if (corPepProject && c.timeType.some(ct => ct == corPepProject.construction_status_id)) { |
|
|
pepProjectName_.push(corPepProject.project_name) |
|
|
pepProjectName_.push(corPepProject.project_name) |
|
|
|
|
|
pepProject_name.push({ id: poms.id, anxinProjectId: poms.anxinProjectId, name: corPepProject.project_name }) |
|
|
} else { |
|
|
} else { |
|
|
// 不符合当前项目的时间节点
|
|
|
// 不符合当前项目的时间节点
|
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
// 是自定义项目
|
|
|
// 是自定义项目
|
|
|
poms.name ? pepProjectName_.push(poms.name) : null |
|
|
if (poms.name) { |
|
|
|
|
|
pepProjectName_.push(poms.name) |
|
|
|
|
|
pepProject_name.push({ id: poms.id, anxinProjectId: poms.anxinProjectId, name: poms.name }) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
// 筛选全部的 anxinProjectId pepProjectId
|
|
|
// 筛选全部的 anxinProjectId pepProjectId
|
|
|
for (let axId of poms.anxinProjectId) { |
|
|
for (let axId of poms.anxinProjectId) { |
|
@ -164,6 +170,18 @@ module.exports = function (app, opts) { |
|
|
` |
|
|
` |
|
|
).toPromise() : |
|
|
).toPromise() : |
|
|
[] |
|
|
[] |
|
|
|
|
|
|
|
|
|
|
|
//在数据里加入项企项目或自定义项目id
|
|
|
|
|
|
|
|
|
|
|
|
strucListRes.map(f => { |
|
|
|
|
|
f.pepProject = [] |
|
|
|
|
|
pepProject_name.map(s => { |
|
|
|
|
|
if (s.anxinProjectId.includes(f.projectId)) { |
|
|
|
|
|
f.pepProject.push(s.id) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
let strucThingId = [] |
|
|
let strucThingId = [] |
|
|
let strucMap = {} |
|
|
let strucMap = {} |
|
|
let searchStrucIds = strucListRes.map(s => { |
|
|
let searchStrucIds = strucListRes.map(s => { |
|
@ -171,7 +189,7 @@ module.exports = function (app, opts) { |
|
|
strucThingId.push(s.iotaThingId) |
|
|
strucThingId.push(s.iotaThingId) |
|
|
} |
|
|
} |
|
|
strucMap[s.id] = { |
|
|
strucMap[s.id] = { |
|
|
...s |
|
|
...s, factor: [] |
|
|
} |
|
|
} |
|
|
return s.id |
|
|
return s.id |
|
|
}) |
|
|
}) |
|
@ -179,7 +197,7 @@ module.exports = function (app, opts) { |
|
|
// !开发测试用的数据
|
|
|
// !开发测试用的数据
|
|
|
if (isDev) { |
|
|
if (isDev) { |
|
|
// searchStrucIds = searchStrucIds.concat([991, 1052, 700])
|
|
|
// searchStrucIds = searchStrucIds.concat([991, 1052, 700])
|
|
|
searchStrucIds = searchStrucIds.concat([27, 4003, 700]) |
|
|
searchStrucIds = searchStrucIds.concat([27, 991, 1040, 50, 59.128, 407, 409, 877, 1035, 1077]) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (searchStrucIds.length) { |
|
|
if (searchStrucIds.length) { |
|
@ -554,70 +572,104 @@ 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 dataLnterruptTitle = [{ |
|
|
let dataLnterruptTitle = [{ |
|
|
n: '项目', |
|
|
n: '项目', |
|
|
k: '', |
|
|
k: 'name', |
|
|
v: pepProjectName |
|
|
// v: pepProjectName
|
|
|
}, { |
|
|
}, { |
|
|
n: '结构物', |
|
|
n: '结构物', |
|
|
k: '', |
|
|
k: 'Structure', |
|
|
f: (d) => { |
|
|
// f: (d) => {
|
|
|
return (strucMap[d.StructureId] || { name: '' }).name |
|
|
// return (strucMap[d.StructureId] || { name: '' }).name
|
|
|
// return (strucListRes.find(s => s.id == d.StructureId) || { name: '' }).name
|
|
|
// // return (strucListRes.find(s => s.id == d.StructureId) || { name: '' }).name
|
|
|
} |
|
|
// }
|
|
|
}, { |
|
|
}, { |
|
|
n: '监测因素(中断比例)', |
|
|
n: '监测因素(中断比例)', |
|
|
k: '', |
|
|
k: 'factor', |
|
|
f: (d) => { |
|
|
// f: (d) => {
|
|
|
// d.factor.join('<b/>')
|
|
|
// // d.factor.join('<b/>')
|
|
|
// console.log(21211231131,d.factor);
|
|
|
// // 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/>')
|
|
|
} |
|
|
// }
|
|
|
}, { |
|
|
}, { |
|
|
n: '告警源名称', |
|
|
n: '告警源', |
|
|
k: 'SourceName' |
|
|
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: '中断时间', |
|
|
n: '中断时间', |
|
@ -802,84 +854,86 @@ module.exports = function (app, opts) { |
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
if (d.AlarmGroup == 1) { |
|
|
if (d.AlarmGroup == 1) { |
|
|
if (d.StructureId) { |
|
|
// if (d.StructureId) {
|
|
|
//查询结构物的监测因素
|
|
|
// //查询结构物的监测因素
|
|
|
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 = (${d.StructureId}) |
|
|
// t_structure_factor.structure = (${d.StructureId})
|
|
|
|
|
|
|
|
|
` |
|
|
// `
|
|
|
).toPromise() || [] |
|
|
// ).toPromise() || []
|
|
|
let factorId = factorData.map(f => f.id) |
|
|
// let factorId = factorData.map(f => f.id)
|
|
|
|
|
|
|
|
|
//查询结构物对应的设备
|
|
|
// //查询结构物对应的设备
|
|
|
const equipment = await clickHouse.anxinyun.query( |
|
|
// const equipment = await clickHouse.anxinyun.query(
|
|
|
`
|
|
|
// `
|
|
|
SELECT |
|
|
// SELECT
|
|
|
t_sensor.id AS id, |
|
|
// t_sensor.id AS id,
|
|
|
t_sensor.name AS name, |
|
|
// t_sensor.name AS name,
|
|
|
t_sensor.structure AS structureId, |
|
|
// t_sensor.structure AS structureId,
|
|
|
t_sensor.factor AS factorId, |
|
|
// t_sensor.factor AS factorId,
|
|
|
t_device_sensor.iota_device_id AS iotaDeviceId |
|
|
// t_device_sensor.iota_device_id AS iotaDeviceId
|
|
|
FROM |
|
|
// FROM
|
|
|
t_sensor |
|
|
// t_sensor
|
|
|
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 = (${d.StructureId}) |
|
|
// t_sensor.structure = (${d.StructureId})
|
|
|
AND |
|
|
// AND
|
|
|
t_sensor.factor IN (${factorId.join(',')}) |
|
|
// t_sensor.factor IN (${factorId.join(',')})
|
|
|
` |
|
|
// `
|
|
|
).toPromise() || [] |
|
|
// ).toPromise() || []
|
|
|
|
|
|
|
|
|
const alarmDatas = await clickHouse.dataAlarm.query( |
|
|
// const alarmDatas = await clickHouse.dataAlarm.query(
|
|
|
`
|
|
|
// `
|
|
|
SELECT |
|
|
// SELECT
|
|
|
alarms.AlarmId AS alarmId, |
|
|
// alarms.AlarmId AS alarmId,
|
|
|
alarms.State AS state, |
|
|
// alarms.State AS state,
|
|
|
alarms.AlarmGroup AS alarmGroup, |
|
|
// alarms.AlarmGroup AS alarmGroup,
|
|
|
alarms.SourceId AS sourceId |
|
|
// alarms.SourceId AS sourceId
|
|
|
FROM |
|
|
// FROM
|
|
|
alarms |
|
|
// alarms
|
|
|
WHERE |
|
|
// WHERE
|
|
|
alarms.StructureId = (${d.StructureId}) |
|
|
// alarms.StructureId = (${d.StructureId})
|
|
|
AND |
|
|
// AND
|
|
|
alarms.AlarmGroup = 1 |
|
|
// alarms.AlarmGroup = 1
|
|
|
AND |
|
|
// AND
|
|
|
alarms.State < 3 |
|
|
// alarms.State < 3
|
|
|
` |
|
|
// `
|
|
|
).toPromise() || [] |
|
|
// ).toPromise() || []
|
|
|
|
|
|
|
|
|
equipment.map(r => { |
|
|
// equipment.map(r => {
|
|
|
alarmDatas.map(u => { |
|
|
// alarmDatas.map(u => {
|
|
|
if (r.iotaDeviceId == u.sourceId) { |
|
|
// if (r.iotaDeviceId == u.sourceId) {
|
|
|
r.sourceId = u.sourceId |
|
|
// r.sourceId = u.sourceId
|
|
|
} |
|
|
// }
|
|
|
}) |
|
|
// })
|
|
|
}) |
|
|
// })
|
|
|
|
|
|
|
|
|
d.factor = [] |
|
|
// d.factor = []
|
|
|
factorData.map(c => { |
|
|
// factorData.map(c => {
|
|
|
let breakData = equipment.filter(m => (m.factorId == c.id && m.sourceId)) |
|
|
// let breakData = equipment.filter(m => (m.factorId == c.id && m.sourceId))
|
|
|
d.factor.push({ |
|
|
// d.factor.push({
|
|
|
name: c.name, |
|
|
// name: c.name,
|
|
|
sum: equipment.length, |
|
|
// sum: equipment.filter(d => d.factorId == c.id).length,
|
|
|
breakData: breakData.length |
|
|
// breakData: breakData.length
|
|
|
}) |
|
|
// })
|
|
|
}) |
|
|
// d.factors = equipment.filter(d => d.factorId == c.id)
|
|
|
|
|
|
// d.breakData = breakData
|
|
|
} |
|
|
// })
|
|
|
|
|
|
|
|
|
dataAlarmG1.push(d) |
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// dataAlarmG1.push(d)
|
|
|
|
|
|
|
|
|
} else if (d.AlarmGroup == 2) { |
|
|
} else if (d.AlarmGroup == 2) { |
|
|
dataAlarmG2.push(d) |
|
|
dataAlarmG2.push(d) |
|
@ -947,6 +1001,7 @@ module.exports = function (app, opts) { |
|
|
} else if (d.AlarmGroup == 4 || d.AlarmGroup == 5) { |
|
|
} else if (d.AlarmGroup == 4 || d.AlarmGroup == 5) { |
|
|
dataAlarmG45.push(d) |
|
|
dataAlarmG45.push(d) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deviceStatistic.add(d.SourceId) |
|
|
deviceStatistic.add(d.SourceId) |
|
|
} |
|
|
} |
|
|
if (c.tactics == 'abnormal_rate') { |
|
|
if (c.tactics == 'abnormal_rate') { |
|
@ -990,12 +1045,158 @@ module.exports = function (app, opts) { |
|
|
<h5 style="margin-bottom:12px">${emailSubTitle}</h5> |
|
|
<h5 style="margin-bottom:12px">${emailSubTitle}</h5> |
|
|
` |
|
|
` |
|
|
|
|
|
|
|
|
|
|
|
let dataAlarmG1Data = dataAlarms.filter(a => a.AlarmGroup == 1) |
|
|
|
|
|
if (dataAlarmG1Data.length) { |
|
|
|
|
|
let dataAlarmG1StructureId = new Set() |
|
|
|
|
|
dataAlarmG1Data.map(c => { |
|
|
|
|
|
dataAlarmG1StructureId.add(c.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 IN (${[...dataAlarmG1StructureId]}) |
|
|
|
|
|
|
|
|
|
|
|
` |
|
|
|
|
|
).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 |
|
|
|
|
|
FROM |
|
|
|
|
|
t_sensor |
|
|
|
|
|
LEFT JOIN t_device_sensor |
|
|
|
|
|
ON t_device_sensor.sensor = t_sensor.id |
|
|
|
|
|
WHERE |
|
|
|
|
|
t_sensor.structure IN (${[...dataAlarmG1StructureId]}) |
|
|
|
|
|
AND |
|
|
|
|
|
t_sensor.factor IN (${factorId.join(',')}) |
|
|
|
|
|
` |
|
|
|
|
|
).toPromise() || [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const alarmDatas = await clickHouse.dataAlarm.query( |
|
|
|
|
|
`
|
|
|
|
|
|
SELECT |
|
|
|
|
|
alarms.AlarmId AS alarmId, |
|
|
|
|
|
alarms.State AS state, |
|
|
|
|
|
alarms.AlarmGroup AS alarmGroup, |
|
|
|
|
|
alarms.SourceId AS sourceId, |
|
|
|
|
|
alarms.StartTime AS StartTime, |
|
|
|
|
|
alarms.SourceName AS SourceName |
|
|
|
|
|
FROM |
|
|
|
|
|
alarms |
|
|
|
|
|
WHERE |
|
|
|
|
|
alarms.StructureId In (${[...dataAlarmG1StructureId]}) |
|
|
|
|
|
AND |
|
|
|
|
|
alarms.AlarmGroup = 1 |
|
|
|
|
|
AND |
|
|
|
|
|
alarms.State < 3 |
|
|
|
|
|
` |
|
|
|
|
|
).toPromise() || [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
equipment.map(f => { |
|
|
|
|
|
f.alarmDatas = [] |
|
|
|
|
|
alarmDatas.map(r => { |
|
|
|
|
|
if (r.sourceId == f.iotaDeviceId) { |
|
|
|
|
|
f.alarmDatas.push({ ...r }) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
factorData.map(v => { |
|
|
|
|
|
v.devices = [] |
|
|
|
|
|
equipment.map(f => { |
|
|
|
|
|
if (v.id == f.factorId) { |
|
|
|
|
|
v.devices.push({ ...f }) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
factorData.map(a => { |
|
|
|
|
|
if (strucMap[a.structureId]) { |
|
|
|
|
|
strucMap[a.structureId].factor.push({ ...a }) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
pepProject_name.map(s => { |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
let projectList = [] |
|
|
|
|
|
for (let key in strucMap) { |
|
|
|
|
|
if (strucMap[key].factor.length > 0) { |
|
|
|
|
|
projectList.push(strucMap[key]) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (projectList.length) { |
|
|
|
|
|
pepProject_name.map(s => { |
|
|
|
|
|
s.projects = [] |
|
|
|
|
|
projectList.map(f => { |
|
|
|
|
|
if (s.anxinProjectId.includes(f.projectId)) { |
|
|
|
|
|
s.projects.push(f) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
pepProject_name.map(h => { |
|
|
|
|
|
if (h.projects.length) { |
|
|
|
|
|
h.projects.map(x => { |
|
|
|
|
|
if (x.factor.length) { |
|
|
|
|
|
x.factor.map(f => { |
|
|
|
|
|
if (f.devices.length) { |
|
|
|
|
|
f.devices.map(c => { |
|
|
|
|
|
if (c.alarmDatas.length) { |
|
|
|
|
|
c.alarmDatas.map(a => { |
|
|
|
|
|
dataAlarmG1.push({ |
|
|
|
|
|
name: h.name, |
|
|
|
|
|
Structure:x.name, |
|
|
|
|
|
factor:f.name, |
|
|
|
|
|
SourceName:a.SourceName, |
|
|
|
|
|
StartTime:a.StartTime |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
pepProject_name.map(h => { |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function packageAlarmData2Table ({ |
|
|
function packageAlarmData2Table ({ |
|
|
titlePrefix, alarmData, alarmTitleArr, keyOfStartTime = 'StartTime' |
|
|
titlePrefix, alarmData, alarmTitleArr, keyOfStartTime = 'StartTime', type |
|
|
}) { |
|
|
}) { |
|
|
if (!alarmData.length) { |
|
|
if (!alarmData.length) { |
|
|
return '' |
|
|
return '' |
|
|
} |
|
|
} |
|
|
|
|
|
strucMap = { ...strucMap } |
|
|
|
|
|
pepProject_name = [...pepProject_name] |
|
|
ifEmailSend = true |
|
|
ifEmailSend = true |
|
|
let tableTitlePrefix = titlePrefix + '告警源' |
|
|
let tableTitlePrefix = titlePrefix + '告警源' |
|
|
let newAddCount = 0 |
|
|
let newAddCount = 0 |
|
@ -1003,8 +1204,57 @@ module.exports = function (app, opts) { |
|
|
let alarmContent = '' |
|
|
let alarmContent = '' |
|
|
let alarmHtmlTitle = packageTableTitle(alarmTitleArr) |
|
|
let alarmHtmlTitle = packageTableTitle(alarmTitleArr) |
|
|
|
|
|
|
|
|
|
|
|
// // if (type == 1) {
|
|
|
|
|
|
// let projectData = []
|
|
|
|
|
|
// //按项目分类
|
|
|
|
|
|
// pepProject_name.map(c => {
|
|
|
|
|
|
|
|
|
|
|
|
// let OneProjectdata = []
|
|
|
|
|
|
|
|
|
|
|
|
// alarmData.map(a => {
|
|
|
|
|
|
// let OneStructure = (strucMap[a.StructureId] || {}).pepProject || []
|
|
|
|
|
|
// if (OneStructure.includes(c.id)) {
|
|
|
|
|
|
// OneProjectdata.push({
|
|
|
|
|
|
// ...a,
|
|
|
|
|
|
// pepProjectId: c.id,
|
|
|
|
|
|
// pepProjectName: c.name
|
|
|
|
|
|
// })
|
|
|
|
|
|
// }
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
// if (OneProjectdata.length) {
|
|
|
|
|
|
// projectData.push(OneProjectdata)
|
|
|
|
|
|
// }
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
// let projectType = []
|
|
|
|
|
|
// projectData.map(p => {
|
|
|
|
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let [index, a] of alarmData.entries()) { |
|
|
for (let [index, a] of alarmData.entries()) { |
|
|
alarmContent += packageTableData({ data: a, titleArr: alarmTitleArr }) |
|
|
// if (type == 1) {
|
|
|
|
|
|
|
|
|
|
|
|
// let tableData = '<tr>'
|
|
|
|
|
|
// for (let t of titleArr) {
|
|
|
|
|
|
// if (t.v) {
|
|
|
|
|
|
// tableData += `<td>${t.v || ''}</td>`
|
|
|
|
|
|
// } else if (t.f) {
|
|
|
|
|
|
// tableData += `<td>${t.f(data) || ''}</td>`
|
|
|
|
|
|
// } else if (t.k) {
|
|
|
|
|
|
// tableData += `<td>${data[t.k] || ''}</td>`
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// tableData += `<td></td>`
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// tableData += '</tr>'
|
|
|
|
|
|
// alarmContent += tableData
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
alarmContent += packageTableData({ data: a, titleArr: alarmTitleArr }) |
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
if (a[keyOfStartTime] && moment(a[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) { |
|
|
if (a[keyOfStartTime] && moment(a[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) { |
|
|
newAddCount++ |
|
|
newAddCount++ |
|
@ -1023,11 +1273,13 @@ module.exports = function (app, opts) { |
|
|
|
|
|
|
|
|
return alarmHtml |
|
|
return alarmHtml |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (c.alarmType.includes('data_outages')) { |
|
|
if (c.alarmType.includes('data_outages')) { |
|
|
html += packageAlarmData2Table({ |
|
|
html += packageAlarmData2Table({ |
|
|
titlePrefix: '数据中断', |
|
|
titlePrefix: '数据中断', |
|
|
alarmData: dataAlarmG1, |
|
|
alarmData: dataAlarmG1, |
|
|
alarmTitleArr: dataLnterruptTitle, |
|
|
alarmTitleArr: dataLnterruptTitle, |
|
|
|
|
|
type: 1 |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
if (c.alarmType.includes('data_exception')) { |
|
|
if (c.alarmType.includes('data_exception')) { |
|
|