Browse Source

fix 告警无项目

dev
巴林闲侠 2 years ago
parent
commit
488e04935a
  1. 4
      api/app/lib/controllers/alarm/data.js
  2. 89
      api/app/lib/controllers/alarm/video.js
  3. 8
      api/app/lib/utils/dataRange.js

4
api/app/lib/controllers/alarm/data.js

@ -176,8 +176,8 @@ async function list (ctx) {
} else { } else {
corConfirmedData = {} corConfirmedData = {}
} }
ar.confirmedContent = 'corConfirmedData.Content' ar.confirmedContent = corConfirmedData.Content
ar.confirmedTime = 'corConfirmedData.Time' ar.confirmedTime = corConfirmedData.Time
// 告警详情的数量 // 告警详情的数量
ar.detailCount = (alarmDetailCount.find(adc => adc.AlarmId == ar.AlarmId) || { count: 0 }).count ar.detailCount = (alarmDetailCount.find(adc => adc.AlarmId == ar.AlarmId) || { count: 0 }).count

89
api/app/lib/controllers/alarm/video.js

@ -18,34 +18,101 @@ async function alarmList (ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { keyword } = cyx.query const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs
const { database: anxinyun } = clickHouse.anxinyun.opts.config
const { pepProjectId, keywordTarget, keyword } = ctx.query
const alarmRes = await clickHouse.vcmp.query(` let anxinStruc = await anxinStrucIdRange({
ctx, pepProjectId, keywordTarget, keyword
})
const alarmRes = await clickHouse.vcmp.query(
`
SELECT
cameraAlarm.cameraId AS cameraId,
cameraAlarm.cameraName AS cameraName,
cameraAlarm.cameraSerialNo AS cameraSerialNo,
cameraAlarm.cameraChannelNo AS cameraChannelNo,
cameraAlarm.alarmId AS alarmId,
cameraAlarm.createTime AS createTime,
cameraAlarm.updateTime AS updateTime,
cameraAlarm.platform AS platform,
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,
anxinStruc.name AS strucName,
anxinStruc.id AS strucId
FROM
(
SELECT SELECT
camera.id AS cameraId, camera.id AS cameraId,
camera.gb_id AS gbId,
camera.name AS cameraName, camera.name AS cameraName,
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.update_time AS updateTime,
camera_status_alarm.platform AS platform, camera_status_alarm.platform AS platform,
camera_status_resolve.resolve AS resolve camera_status_alarm.status_id AS statusId,
FROM camera_status_alarm.serial_no AS cameraSerialNo,
camera_status_alarm camera_status_alarm.channel_no AS cameraChannelNo
FROM camera_status_alarm
LEFT JOIN camera LEFT 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
WHERE camera.delete = false AND camera.recycle_time is null
AND alarmId IN (
SELECT camera_status_alarm.id AS alarmId
FROM camera_status_alarm
RIGHT JOIN ${anxinyun}.t_video_ipc
ON toString(${anxinyun}.t_video_ipc.channel_no) = camera_status_alarm.channel_no
AND ${anxinyun}.t_video_ipc.serial_no = camera_status_alarm.serial_no
${
//`WHERE ${anxinyun}.t_video_ipc.structure IN (422)`
''
}
)
) AS cameraAlarm
LEFT JOIN camera_status LEFT JOIN camera_status
ON camera_status_alarm.platform = camera_status.platform ON cameraAlarm.platform = camera_status.platform
AND camera_status_alarm.status_id = 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
`).toPromise() LEFT JOIN "gbCamera"
ON "gbCamera".id = cameraAlarm.gbId
LEFT JOIN ${anxinyun}.t_video_ipc AS anxinIpc
ON toString(anxinIpc.channel_no) = cameraAlarm.cameraChannelNo
AND anxinIpc.serial_no = cameraAlarm.cameraSerialNo
LEFT JOIN ${anxinyun}.t_structure AS anxinStruc
ON anxinStruc.id = anxinIpc.structure
`
).toPromise()
let returnD = [] let returnD = []
let positionD = {}
// 每个设备一个告警 // 每个设备一个告警
// for (let a of alarmRes) { for (let a of alarmRes) {
// if () if (positionD[a.cameraId]) {
// }
} else {
let d = {
cameraId: a.cameraId,
alarmId: a.alarmId,
resolve: [],
struc: []
}
if (a.resolveId) {
d.resolve.push({
id: a.resolveId,
resolve: a.resolve
})
}
returnD.push(d)
}
}
ctx.status = 200; ctx.status = 200;
ctx.body = [] ctx.body = []

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

@ -38,7 +38,7 @@ module.exports = function (app, opts) {
// 根据 poms 的项目绑定关系查相关联的项企项目、安心云项目id信息 // 根据 poms 的项目绑定关系查相关联的项企项目、安心云项目id信息
const bindRes = await models.ProjectCorrelation.findAll(findOption) const bindRes = await models.ProjectCorrelation.findAll(findOption)
// 获取不重复的 安心云项目id // 获取不重复的 项企项目id
let pepProjectIds = [] let pepProjectIds = []
for (let b of bindRes) { for (let b of bindRes) {
if (b.pepProjectId) { if (b.pepProjectId) {
@ -74,6 +74,7 @@ module.exports = function (app, opts) {
[] []
// 获取不重复的 安心云项目 id
const anxinProjectIds = [ const anxinProjectIds = [
...( ...(
bindRes.filter(b => pepProjectRes.some(pp => pp.id == b.pepProjectId)) bindRes.filter(b => pepProjectRes.some(pp => pp.id == b.pepProjectId))
@ -129,9 +130,10 @@ module.exports = function (app, opts) {
undelStruc.push({ undelStruc.push({
strucId: s.strucId, strucId: s.strucId,
strucName: s.strucName, strucName: s.strucName,
// projectId: s.projectId,
pepProject: pepProjectRes.filter(pp => { pepProject: pepProjectRes.filter(pp => {
return bindRes.find(br => { return bindRes.some(br => {
return br.pepProjectId == pp.id && br.anxinProjectId.some(braId => braId == s.strucId) return br.pepProjectId == pp.id && br.anxinProjectId.some(braId => braId == s.projectId)
}) })
}) })
}) })

Loading…
Cancel
Save