diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js
index ef7d60c..21e7afa 100644
--- a/api/app/lib/schedule/alarms_push.js
+++ b/api/app/lib/schedule/alarms_push.js
@@ -1,7 +1,7 @@
const moment = require('moment')
-let isDev = false
-// let isDev = true
+// let isDev = false
+let isDev = true
let proDebug = false
proDebug = true
@@ -9,7 +9,8 @@ proDebug = true
module.exports = function (app, opts) {
const alarmsPush = app.fs.scheduleInit(
{
- interval: '12 */1 * * * *',
+ // interval: '12 */1 * * * *',
+ interval: '12 0 0 0 */1 *',
immediate: isDev,
proRun: !isDev,
},
@@ -87,6 +88,7 @@ module.exports = function (app, opts) {
}
for (let { dataValues: c } of configListRes) {
+
if (c.tacticsParams && c.tactics) {
if (proDebug) {
console.log(`当前运行EM配置:id=${c.id} name=${c.name}`);
@@ -95,13 +97,12 @@ module.exports = function (app, opts) {
const { strucId, pomsProjectId, pomsStrucFactorId } = c
const { interval, deviceProportion } = c.tacticsParams
- if (
- curMinOfYear % parseInt(interval) == 0 || isDev
- ) {
+ if (curMinOfYear % parseInt(interval) == 0 || isDev) {
const corPomsProject = pomsProjectRes.filter(poms => pomsProjectId.includes(poms.id))
let curAnxinProjectId = new Set()
let pepProjectName_ = []
+ let pepProject_name = []
for (let { dataValues: poms } of corPomsProject) {
if (poms.pepProjectId) {
// 找对应的项企项目
@@ -109,13 +110,18 @@ module.exports = function (app, opts) {
pepProjectRes.find(p => p.id == poms.pepProjectId)
if (corPepProject && c.timeType.some(ct => ct == corPepProject.construction_status_id)) {
pepProjectName_.push(corPepProject.project_name)
+ pepProject_name.push({ id: poms.id, anxinProjectId: poms.anxinProjectId, name: corPepProject.project_name })
} else {
// 不符合当前项目的时间节点
continue
}
} 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
for (let axId of poms.anxinProjectId) {
@@ -164,6 +170,18 @@ module.exports = function (app, opts) {
`
).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 strucMap = {}
let searchStrucIds = strucListRes.map(s => {
@@ -171,7 +189,7 @@ module.exports = function (app, opts) {
strucThingId.push(s.iotaThingId)
}
strucMap[s.id] = {
- ...s
+ ...s, factor: []
}
return s.id
})
@@ -179,7 +197,7 @@ module.exports = function (app, opts) {
// !开发测试用的数据
if (isDev) {
// 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) {
@@ -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('')
+ // // console.log(21211231131,d.factor);
+ // let data = []
+ // d.factor.map(f => data.push(f.name + '(' + f.breakData + '/' + f.sum + ')'))
+ // return data.join('
')
+ // }
+ // }, {
+ // 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 = [{
n: '项目',
- k: '',
- v: pepProjectName
+ k: 'name',
+ // v: pepProjectName
}, {
n: '结构物',
- k: '',
- f: (d) => {
- return (strucMap[d.StructureId] || { name: '' }).name
- // return (strucListRes.find(s => s.id == d.StructureId) || { name: '' }).name
- }
+ k: 'Structure',
+ // 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('')
- // console.log(21211231131,d.factor);
- let data = []
- d.factor.map(f => data.push(f.name + '(' + f.breakData + '/' + f.sum + ')'))
- return data.join('
')
- }
+ k: 'factor',
+ // f: (d) => {
+ // // d.factor.join('')
+ // // console.log(21211231131,d.factor);
+ // let data = []
+ // d.factor.map(f => data.push(f.name + '(' + f.breakData + '/' + f.sum + ')'))
+ // return data.join('
')
+ // }
}, {
- n: '告警源名称',
+ 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: '中断时间',
@@ -802,84 +854,86 @@ 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
- FROM
- t_sensor
- LEFT JOIN t_device_sensor
- ON t_device_sensor.sensor = t_sensor.id
- WHERE
- t_sensor.structure = (${d.StructureId})
- 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
- FROM
- alarms
- WHERE
- alarms.StructureId = (${d.StructureId})
- AND
- alarms.AlarmGroup = 1
- AND
- alarms.State < 3
- `
- ).toPromise() || []
-
- equipment.map(r => {
- alarmDatas.map(u => {
- if (r.iotaDeviceId == u.sourceId) {
- r.sourceId = u.sourceId
- }
- })
- })
-
- d.factor = []
- factorData.map(c => {
- let breakData = equipment.filter(m => (m.factorId == c.id && m.sourceId))
- d.factor.push({
- name: c.name,
- sum: equipment.length,
- breakData: breakData.length
- })
- })
-
- }
-
- dataAlarmG1.push(d)
+ // 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
+ // FROM
+ // t_sensor
+ // LEFT JOIN t_device_sensor
+ // ON t_device_sensor.sensor = t_sensor.id
+ // WHERE
+ // t_sensor.structure = (${d.StructureId})
+ // 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
+ // FROM
+ // alarms
+ // WHERE
+ // alarms.StructureId = (${d.StructureId})
+ // AND
+ // alarms.AlarmGroup = 1
+ // AND
+ // alarms.State < 3
+ // `
+ // ).toPromise() || []
+
+ // equipment.map(r => {
+ // alarmDatas.map(u => {
+ // if (r.iotaDeviceId == u.sourceId) {
+ // r.sourceId = u.sourceId
+ // }
+ // })
+ // })
+
+ // d.factor = []
+ // factorData.map(c => {
+ // let breakData = equipment.filter(m => (m.factorId == c.id && m.sourceId))
+ // d.factor.push({
+ // name: c.name,
+ // sum: equipment.filter(d => d.factorId == c.id).length,
+ // breakData: breakData.length
+ // })
+ // d.factors = equipment.filter(d => d.factorId == c.id)
+ // d.breakData = breakData
+ // })
+
+ // }
+
+ // dataAlarmG1.push(d)
} else if (d.AlarmGroup == 2) {
dataAlarmG2.push(d)
@@ -947,6 +1001,7 @@ module.exports = function (app, opts) {
} else if (d.AlarmGroup == 4 || d.AlarmGroup == 5) {
dataAlarmG45.push(d)
}
+
deviceStatistic.add(d.SourceId)
}
if (c.tactics == 'abnormal_rate') {
@@ -990,12 +1045,158 @@ module.exports = function (app, opts) {