巴林闲侠 2 years ago
parent
commit
ad07f2ca80
  1. 166
      api/app/lib/schedule/alarms_handle_statistics.js

166
api/app/lib/schedule/alarms_handle_statistics.js

@ -8,7 +8,7 @@ module.exports = function (app, opts) {
const { database: anxinyun } = clickHouse.anxinyun.opts.config const { database: anxinyun } = clickHouse.anxinyun.opts.config
const alarmHandleStatistics = app.fs.scheduleInit( const alarmHandleStatistics = app.fs.scheduleInit(
{ {
interval: '40 8 15 * * *', interval: '10 41 17 * * *',
// immediate: true, // immediate: true,
//proRun: true, //proRun: true,
}, },
@ -42,10 +42,10 @@ module.exports = function (app, opts) {
//算单个项目 //算单个项目
//pomsProject.map(p => { //pomsProject.map(p => {
//let pid = p.id; //let pid = p.id;
let pid = 26 let pid = 22
let pDataAlarms = dataAlarms.filter(da => da.pomsProject.map(dap => dap.id).indexOf(pid) != -1) let pDataAlarms = dataAlarms.filter(da => da.pomsProject.indexOf(pid) != -1)
let pAppAlarms = appAlarms.filter(aa => aa.app.projectCorrelations.map(ap => ap.id).indexOf(pid) != -1) let pAppAlarms = appAlarms.filter(aa => aa.app.projectCorrelations.map(ap => ap.id).indexOf(pid) != -1)
let pVideoAlarms = videoAlarms.filter(va => va.pomsProject.map(dap => dap.id).indexOf(pid) != -1) let pVideoAlarms = videoAlarms.filter(va => va.pomsProject.indexOf(pid) != -1)
let pDataMap = calculate(pDataAlarms, pAppAlarms, pVideoAlarms) let pDataMap = calculate(pDataAlarms, pAppAlarms, pVideoAlarms)
let sm = pDataAlarms.length + pAppAlarms.length + pVideoAlarms.length; let sm = pDataAlarms.length + pAppAlarms.length + pVideoAlarms.length;
@ -154,14 +154,14 @@ module.exports = function (app, opts) {
alarms.AlarmId AS AlarmId, alarms.AlarmId AS AlarmId,
alarms.State AS State, alarms.State AS State,
alarms.StructureId AS StructureId, alarms.StructureId AS StructureId,
SourceName, StartTime, EndTime StartTime, EndTime
${alarmQueryOptionStr}`).toPromise(); ${alarmQueryOptionStr}`).toPromise();
const confirmedAlarm = alarmRes.filter(ar => ar.State && ar.State > 2).map(ar => "'" + ar.AlarmId + "'"); const confirmedAlarm = alarmRes.filter(ar => ar.State && ar.State > 2).map(ar => "'" + ar.AlarmId + "'");
const confirmedAlarmDetailMax = confirmedAlarm.length ? const confirmedAlarmDetailMax = confirmedAlarm.length ?
await clickHouse.dataAlarm.query(` await clickHouse.dataAlarm.query(`
SELECT SELECT
max(Time) AS Time, AlarmId , max(Content) AS Content max(Time) AS Time, AlarmId
FROM FROM
alarm_details alarm_details
WHERE WHERE
@ -177,7 +177,7 @@ module.exports = function (app, opts) {
// TODO: 开发临时添加 // TODO: 开发临时添加
] ]
} }
).pomsProject ).pomsProject.map(p => p.id)
// 最新告警详情 - 确认信息 // 最新告警详情 - 确认信息
let corConfirmedData = (confirmedAlarmDetailMax.find(cdm => cdm.AlarmId == ar.AlarmId) || {}); let corConfirmedData = (confirmedAlarmDetailMax.find(cdm => cdm.AlarmId == ar.AlarmId) || {});
@ -199,9 +199,7 @@ module.exports = function (app, opts) {
attributes: ['id', 'createTime', 'confirmTime'], attributes: ['id', 'createTime', 'confirmTime'],
include: [{ include: [{
model: models.App, model: models.App,
attributes: { attributes: ['id'],
exclude: ['projectId']
},
include: [{ include: [{
model: models.ProjectCorrelation, model: models.ProjectCorrelation,
attributes: ['id'] attributes: ['id']
@ -228,55 +226,27 @@ module.exports = function (app, opts) {
` `
SELECT SELECT
cameraAlarm.cameraId AS cameraId, cameraAlarm.cameraId AS cameraId,
cameraAlarm.cameraName AS cameraName,
cameraAlarm.cameraKindId AS cameraKindId,
cameraAlarm.venderId AS venderId,
cameraAlarm.venderName AS venderName,
cameraAlarm.cameraSerialNo AS cameraSerialNo,
cameraAlarm.cameraChannelNo AS cameraChannelNo,
cameraAlarm.alarmId AS alarmId, cameraAlarm.alarmId AS alarmId,
cameraAlarm.createTime AS createTime, cameraAlarm.createTime AS createTime,
cameraAlarm.updateTime AS updateTime,
cameraAlarm.platform AS platform,
cameraAlarm.confirmContent AS confirmContent,
cameraAlarm.confirmTime AS confirmTime, cameraAlarm.confirmTime AS confirmTime,
${'cameraAlarm.autoRestore AS autoRestore,'} ${'cameraAlarm.autoRestore AS autoRestore,'}
camera_status_resolve.id AS resolveId,
camera_status.describe AS statusDescribe,
camera_status_resolve.resolve AS resolve,
"gbCamera".online AS cameraOnline,
secret_yingshi.token AS yingshiToken,
anxinIpc.t_video_ipc.name AS anxinIpcPosition,
anxinStation.id AS anxinStationId,
anxinStation.name AS anxinStationName,
anxinStruc.name AS strucName,
anxinStruc.id AS strucId anxinStruc.id AS strucId
FROM FROM
( (
SELECT SELECT
camera.id AS cameraId, camera.id AS cameraId,
camera.gb_id AS gbId,
camera.name AS cameraName,
camera.kind_id AS cameraKindId,
camera.vender_id AS venderId,
camera.yingshi_secret_id AS yingshiSecretId,
vender.name AS venderName,
camera_status_alarm.id AS alarmId, camera_status_alarm.id AS alarmId,
camera_status_alarm.create_time AS createTime, camera_status_alarm.create_time AS createTime,
camera_status_alarm.update_time AS updateTime,
camera_status_alarm.platform AS platform, camera_status_alarm.platform AS platform,
camera_status_alarm.status_id AS statusId, camera_status_alarm.status_id AS statusId,
camera_status_alarm.serial_no AS cameraSerialNo, camera_status_alarm.serial_no AS cameraSerialNo,
camera_status_alarm.channel_no AS cameraChannelNo, camera_status_alarm.channel_no AS cameraChannelNo,
camera_status_alarm.confirm AS confirmContent,
${'camera_status_alarm.auto_restore AS autoRestore,'} ${'camera_status_alarm.auto_restore AS autoRestore,'}
camera_status_alarm.confirm_time AS confirmTime camera_status_alarm.confirm_time AS confirmTime
FROM camera_status_alarm FROM camera_status_alarm
INNER JOIN camera INNER JOIN camera
ON camera.serial_no = camera_status_alarm.serial_no ON camera.serial_no = camera_status_alarm.serial_no
AND camera.channel_no = camera_status_alarm.channel_no AND camera.channel_no = camera_status_alarm.channel_no
LEFT JOIN vender
ON vender.id = camera.vender_id
WHERE WHERE
camera.delete = false camera.delete = false
AND camera.recycle_time is null AND camera.recycle_time is null
@ -295,10 +265,6 @@ module.exports = function (app, opts) {
AND cameraAlarm.statusId = camera_status.id AND cameraAlarm.statusId = camera_status.id
LEFT JOIN camera_status_resolve LEFT JOIN camera_status_resolve
ON camera_status_resolve.status_id = camera_status.id ON camera_status_resolve.status_id = camera_status.id
LEFT JOIN "gbCamera"
ON "gbCamera".id = cameraAlarm.gbId
LEFT JOIN "secret_yingshi"
ON "secret_yingshi".id = cameraAlarm.yingshiSecretId
LEFT JOIN ${anxinyun}.t_video_ipc AS anxinIpc LEFT JOIN ${anxinyun}.t_video_ipc AS anxinIpc
ON toString(anxinIpc.channel_no) = cameraAlarm.cameraChannelNo ON toString(anxinIpc.channel_no) = cameraAlarm.cameraChannelNo
@ -308,8 +274,6 @@ module.exports = function (app, opts) {
AND anxinStruc.id IN (${anxinStrucIds.join(',')}) AND anxinStruc.id IN (${anxinStrucIds.join(',')})
LEFT JOIN ${anxinyun}.t_video_ipc_station AS anxinIpcStation LEFT JOIN ${anxinyun}.t_video_ipc_station AS anxinIpcStation
ON anxinIpcStation.ipc = anxinIpc.id ON anxinIpcStation.ipc = anxinIpc.id
LEFT JOIN ${anxinyun}.t_sensor AS anxinStation
ON anxinStation.id = anxinIpcStation.station
`).toPromise() : [] `).toPromise() : []
let returnD = [] let returnD = []
@ -317,51 +281,51 @@ module.exports = function (app, opts) {
// 每个设备一个告警 // 每个设备一个告警
for (let a of alarmRes) { for (let a of alarmRes) {
if (positionD[a.cameraId]) { if (positionD[a.cameraId]) {
let curD = returnD[positionD[a.cameraId].positionReturnD] //let curD = returnD[positionD[a.cameraId].positionReturnD]
if (a.resolveId && !curD.resolve.some(r => r.id == a.resolveId)) { // if (a.resolveId && !curD.resolve.some(r => r.id == a.resolveId)) {
curD.resolve.push({ // curD.resolve.push({
id: a.resolveId, // id: a.resolveId,
resolve: a.resolve // resolve: a.resolve
}) // })
} // }
if (a.strucId && !curD.struc.some(s => s.id == a.strucId)) { // if (a.strucId && !curD.struc.some(s => s.id == a.strucId)) {
curD.struc.push({ // curD.struc.push({
id: a.strucId, // id: a.strucId,
projectId: a.projectId, // projectId: a.projectId,
name: a.strucName // name: a.strucName
}) // })
} // }
if (a.anxinStationId && !curD.station.some(s => s.id == a.anxinStationId)) { // if (a.anxinStationId && !curD.station.some(s => s.id == a.anxinStationId)) {
curD.station.push({ // curD.station.push({
id: a.anxinStationId, // id: a.anxinStationId,
name: a.anxinStationName, // name: a.anxinStationName,
position: a.anxinIpcPosition // position: a.anxinIpcPosition
}) // })
} // }
} else { } else {
let d = { let d = {
cameraId: a.cameraId, cameraId: a.cameraId,
cameraName: a.cameraName, //cameraName: a.cameraName,
camerOnline: a.cameraOnline, //camerOnline: a.cameraOnline,
cameraSerialNo: a.cameraSerialNo, //cameraSerialNo: a.cameraSerialNo,
cameraChannelNo: a.cameraChannelNo, //cameraChannelNo: a.cameraChannelNo,
autoRestore: a.autoRestore, autoRestore: a.autoRestore,
createTime: a.createTime, createTime: a.createTime,
updateTime: a.updateTime, //updateTime: a.updateTime,
platform: a.platform, //platform: a.platform,
statusDescribe: a.statusDescribe, //statusDescribe: a.statusDescribe,
alarmId: a.alarmId, alarmId: a.alarmId,
confirmContent: a.confirmContent, //confirmContent: a.confirmContent,
confirmTime: a.confirmTime, confirmTime: a.confirmTime,
venderId: a.venderId, // venderId: a.venderId,
venderName: a.venderName, // venderName: a.venderName,
cameraKindId: a.cameraKindId, // cameraKindId: a.cameraKindId,
yingshiToken: a.yingshiToken, // yingshiToken: a.yingshiToken,
resolve: [], // resolve: [],
struc: [], // struc: [],
station: [] // station: []
} }
// pep 项目 // pep 项目
@ -372,28 +336,28 @@ module.exports = function (app, opts) {
] ]
} }
).pomsProject ).pomsProject.map(d => d.id)
if (a.resolveId) { // if (a.resolveId) {
d.resolve.push({ // d.resolve.push({
id: a.resolveId, // id: a.resolveId,
resolve: a.resolve // resolve: a.resolve
}) // })
} // }
if (a.strucId) { // if (a.strucId) {
d.struc.push({ // d.struc.push({
id: a.strucId, // id: a.strucId,
projectId: a.projectId, // projectId: a.projectId,
name: a.strucName // name: a.strucName
}) // })
} // }
if (a.anxinStationId) { // if (a.anxinStationId) {
d.station.push({ // d.station.push({
id: a.anxinStationId, // id: a.anxinStationId,
name: a.anxinStationName, // name: a.anxinStationName,
position: a.anxinIpcPosition // position: a.anxinIpcPosition
}) // })
} // }
returnD.push(d) returnD.push(d)
positionD[a.cameraId] = { positionD[a.cameraId] = {
positionReturnD: returnD.length - 1 positionReturnD: returnD.length - 1

Loading…
Cancel
Save