Browse Source

多结构物重复项目不同

dev
巴林闲侠 2 years ago
parent
commit
f4d11274a6
  1. 65
      api/app/lib/schedule/alarms_push.js
  2. 43
      api/app/lib/utils/dataRange.js

65
api/app/lib/schedule/alarms_push.js

@ -53,7 +53,7 @@ module.exports = function (app, opts) {
for (let { dataValues: c } of configListRes) {
if (c.tacticsParams && c.tactics) {
const { projectCorrelation, strucId } = c
const { projectCorrelation, strucId, pomsProjectId } = c
const { interval, deviceProportion } = c.tacticsParams
if (
@ -70,7 +70,7 @@ module.exports = function (app, opts) {
)
) {
// TODO 查当前 poms 下的结构物 并把不包含的去掉
const strucListRes = strucId.length ? await clickHouse.anxinyun.query(`
SELECT id, iota_thing_id, name
FROM t_structure
@ -83,14 +83,21 @@ module.exports = function (app, opts) {
let videoAlarms = []
let appAlarmWhereOption = {
confirmTime: null,
}
let appAlarms = []
let deviceCount = 0
let cameraCount = 0
// 判断推送策略
let pointTime = moment().subtract(interval, 'minute').format('YYYY-MM-DD HH:mm:ss')
if (c.tactics == 'immediately') {
dataAlarmOption.push(`StartTime >= '${pointTime}'`);
appAlarmWhereOption.createTime = { $gte: pointTime }
} else if (c.tactics == 'continue') {
dataAlarmOption.push(`StartTime <= '${pointTime}'`);
appAlarmWhereOption.createTime = { $lte: pointTime }
} else if (c.tactics == 'abnormal_rate') {
dataAlarmOption.push(`StartTime <= '${pointTime}'`);
if (c.alarmType.includes('data_outages') || c.alarmType.includes('data_exception')) {
@ -110,6 +117,7 @@ module.exports = function (app, opts) {
`).toPromise())[0].count
: 0
}
appAlarmWhereOption.createTime = { $lte: pointTime }
}
// 判断告警数据范围
@ -135,9 +143,7 @@ module.exports = function (app, opts) {
cameraAlarm.confirmContent AS confirmContent,
cameraAlarm.confirmTime AS confirmTime,
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,
anxinIpc.t_video_ipc.name AS anxinIpcPosition,
anxinStation.id AS anxinStationId,
@ -155,7 +161,7 @@ module.exports = function (app, opts) {
camera_status_alarm.serial_no AS cameraSerialNo,
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
FROM camera_status_alarm
INNER JOIN ${anxinyun}.t_video_ipc
@ -165,15 +171,13 @@ module.exports = function (app, opts) {
INNER JOIN camera
ON camera.serial_no = camera_status_alarm.serial_no
AND camera.channel_no = camera_status_alarm.channel_no
WHERE
camera.delete = false
AND camera.delete = false
AND camera.recycle_time is null
WHERE camera_status_alarm.confirm_time IS null
) AS cameraAlarm
LEFT JOIN camera_status
ON cameraAlarm.platform = camera_status.platform
AND cameraAlarm.statusId = camera_status.id
LEFT JOIN camera_status_resolve
ON camera_status_resolve.status_id = camera_status.id
LEFT JOIN "gbCamera"
ON "gbCamera".id = cameraAlarm.gbId
@ -196,12 +200,7 @@ module.exports = function (app, opts) {
for (let a of videoAlarms) {
if (positionD[a.cameraId]) {
let curD = returnD[positionD[a.cameraId].positionReturnD]
if (a.resolveId && !curD.resolve.some(r => r.id == a.resolveId)) {
curD.resolve.push({
id: a.resolveId,
resolve: a.resolve
})
}
if (a.strucId && !curD.struc.some(s => s.id == a.strucId)) {
curD.struc.push({
id: a.strucId,
@ -231,32 +230,10 @@ module.exports = function (app, opts) {
alarmId: a.alarmId,
confirmContent: a.confirmContent,
confirmTime: a.confirmTime,
venderId: a.venderId,
venderName: a.venderName,
cameraKindId: a.cameraKindId,
resolve: [],
struc: [],
station: []
}
// pep 项目
// d.pomsProject = (
// anxinStruc.find(as => as.strucId == a.strucId) ||
// {
// pomsProject: [
// ]
// }
// ).pomsProject
if (a.resolveId) {
d.resolve.push({
id: a.resolveId,
resolve: a.resolve
})
}
if (a.strucId) {
d.struc.push({
id: a.strucId,
@ -280,7 +257,19 @@ module.exports = function (app, opts) {
let p = 1
}
if (c.alarmType.includes('app_exception')) {
appAlarms = await models.AppAlarm.findAll({
where: appAlarmWhereOption,
include: [{
model: models.App,
include: [{
model: models.ProjectApp,
where: {
projectId: pomsProjectId
},
}]
}]
})
let a = 2
}
if (c.alarmType.includes('device_exception')) {
dataAlarmGroupOption.push(4)

43
api/app/lib/utils/dataRange.js

@ -160,24 +160,43 @@ module.exports = function (app, opts) {
// 并保存信息至数据
let undelStruc = []
for (let s of undelStrucRes) {
if (!undelStruc.some(us => us.strucId == s.strucId)) {
let pomsProject = []
for (let { dataValues: br } of bindRes) {
if (br.anxinProjectId.some(braId => braId == s.projectId)) {
let corPepProject = pepProjectRes.find(pp => pp.id == br.pepProjectId)
pomsProject.push({
let corStruc = undelStruc.find(us => us.strucId == s.strucId)
if (corStruc) {
if (!corStruc.project.some(cp => cp.id == s.projectId)) {
corStruc.project.push({
id: s.projectId
})
}
} else {
corStruc = {
strucId: s.strucId,
strucName: s.strucName,
projectId: s.projectId,
project: [{
id: s.projectId,
}],
pomsProject: []
}
undelStruc.push(corStruc)
}
for (let { dataValues: br } of bindRes) {
if (br.anxinProjectId.some(braId => braId == s.projectId)) {
let corPepProject = pepProjectRes.find(pp => pp.id == br.pepProjectId)
let corPomsProject = corStruc.pomsProject.find(cp => cp.id == br.id)
if (corPomsProject) {
// poms 的 project 和 pep 的 project 是一对一的关系 所以这个情况不用处理
} else {
corStruc.pomsProject.push({
...br,
pepProject: corPepProject
})
}
}
undelStruc.push({
strucId: s.strucId,
strucName: s.strucName,
projectId: s.projectId,
pomsProject: pomsProject
})
}
}
return undelStruc
}

Loading…
Cancel
Save