diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index 265e99c..5421a26 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -143,7 +143,7 @@ async function notedInspection (ctx) { async function apiError (ctx) { try { - const { utils: { sendAppearToWeb } } = ctx.app.fs + const { utils: { sendAppearToWeb }, clickHouse } = ctx.app.fs const models = ctx.fs.dc.models; const { projectAppId, alarmContent, router, statusCode, screenshot = '', type } = ctx.request.body const now = moment().format() @@ -208,7 +208,7 @@ async function apiError (ctx) { }, include: [{ model: models.ProjectCorrelation, - attributes: ['id'], + attributes: ['id', 'name', 'pepProjectId'], where: { del: false } }] }) @@ -219,7 +219,12 @@ async function apiError (ctx) { }, attributes: ['name'], }) - let pId = belongsTo.projectCorrelation.dataValues.id;//归属项目 + let pInfo = belongsTo.projectCorrelation.dataValues;//归属项目 + let pId = pInfo.id;//归属项目id + let pepProjects = pInfo.pepProjectId ? await clickHouse.projectManage.query(` + SELECT id, project_name FROM t_pim_project WHERE id=${pInfo.pepProjectId}` + ).toPromise() : []; + let data = { projectCorrelationId: pId, alarmInfo: { messageMode: 'AlarmGeneration', sourceName: appName.name, content: alarmContent, type: constTypes[type] },//AlarmGeneration代表告警首次产生 @@ -237,7 +242,14 @@ async function apiError (ctx) { //消息推送到前端 - await sendAppearToWeb([data], 'app'); + let project = {//构造数据结构 + pomsProject: [{ + id: pId, + name: pInfo.name, + pepProject: { projectName: pepProjects.length ? pepProjects[0].project_name : '' } + }] + } + await sendAppearToWeb([data], 'app', project); } } diff --git a/api/app/lib/controllers/alarm/video.js b/api/app/lib/controllers/alarm/video.js index b9a0dbf..6c9cf56 100644 --- a/api/app/lib/controllers/alarm/video.js +++ b/api/app/lib/controllers/alarm/video.js @@ -455,7 +455,7 @@ async function alarmAdded (ctx) { //消息推送到前端 if (datas.length) { - await sendAppearToWeb(datas, 'video'); + await sendAppearToWeb(datas, 'video', exist); } } } diff --git a/api/app/lib/service/kafka.js b/api/app/lib/service/kafka.js index 889b402..cfe515a 100644 --- a/api/app/lib/service/kafka.js +++ b/api/app/lib/service/kafka.js @@ -119,8 +119,9 @@ module.exports = async function factory(app, opts) { let alarm_group = await clickHouse.anxinyun.query( `SELECT alarm_group, alarm_group_unit FROM t_alarm_code WHERE code='${alarmCode}'`).toPromise() - let type = null, alarmGroup = null;//告警类型 异常类型 + let type = null, typeId = null, alarmGroup = null;//告警类型 异常类型 if (alarm_group) { + typeId = alarm_group[0].alarm_group; type = constAlarmGroups[alarm_group[0].alarm_group];//告警类型 let gId = alarm_group[0].alarm_group_unit; let alarm_group_unit = await clickHouse.anxinyun.query( @@ -133,7 +134,7 @@ module.exports = async function factory(app, opts) { let datas = projects.map(d => {//需要 项目,告警源,异常类型,时间 return { projectCorrelationId: d, - alarmInfo: { messageMode, sourceName, alarmTypeCode, alarmCode, content, type: alarmGroup }, + alarmInfo: { messageMode, sourceName, alarmTypeCode, alarmCode, content, type: alarmGroup, typeId }, time: time, type//告警类型 } @@ -151,7 +152,7 @@ module.exports = async function factory(app, opts) { //消息推送到前端 if (datas.length) { - await sendAppearToWeb(datas, 'data'); + await sendAppearToWeb(datas, 'data', exist); } diff --git a/api/app/lib/utils/alarmHandle.js b/api/app/lib/utils/alarmHandle.js index a9fdf5a..776ca98 100644 --- a/api/app/lib/utils/alarmHandle.js +++ b/api/app/lib/utils/alarmHandle.js @@ -23,20 +23,21 @@ module.exports = function (app, opts) { 'video': '/problem/dataAlarm/videoAbnormal', 'app': '/problem/useAlarm/useAbnormal' } - async function sendAppearToWeb (datas, ttype) { + async function sendAppearToWeb(datas, ttype, aboutProject) { try { let alarmTypee = null, jumpUrl = null//告警类型 跳转地址 //项目信息 - let { projects, pepProjects } = await getProjectsInfo(datas); + //let { projects, pepProjects } = await getProjectsInfo(datas); //数据类区分alarmGroup if (ttype == 'data') { - let alarm_group = await clickHouse.anxinyun.query( - `SELECT alarm_group FROM t_alarm_code WHERE code='${datas[0].alarmInfo.alarmCode}'`).toPromise(); + // let alarm_group = await clickHouse.anxinyun.query( + // `SELECT alarm_group FROM t_alarm_code WHERE code='${datas[0].alarmInfo.alarmCode}'`).toPromise(); - alarmTypee = alarm_group.length ? constAlarmGroups[alarm_group[0].alarm_group] : null - jumpUrl = alarm_group.length ? constAlarmUrls[alarm_group[0].alarm_group] : null + let typeId = datas[0].alarmInfo.typeId;//1,2,3,4,5 + alarmTypee = constAlarmGroups[typeId] || null + jumpUrl = constAlarmUrls[typeId] || null } else { alarmTypee = constAlarmGroups[ttype] jumpUrl = constAlarmUrls[ttype] @@ -44,10 +45,10 @@ module.exports = function (app, opts) { let sendData = [] datas.map(ld => { - let pepPId = projects.find(p => p.id == ld.projectCorrelationId).pepProjectId; + let item = aboutProject.pomsProject.find(p => p.id == ld.projectCorrelationId); sendData.push({ projectCorrelationId: ld.projectCorrelationId, - project: projects.find(p => p.id == ld.projectCorrelationId).name || pepProjects.find(pp => pp.id == pepPId).project_name,//前者为自定义项目名称 + project: item.name || item.pepProject.projectName,//前者为自定义项目名称 source: ld.alarmInfo.sourceName, alarmGroup: ld.alarmInfo.type,//异常类型 time: ld.time,