Browse Source

fix 告警无项目

dev
巴林闲侠 2 years ago
parent
commit
488e04935a
  1. 4
      api/app/lib/controllers/alarm/data.js
  2. 115
      api/app/lib/controllers/alarm/video.js
  3. 46
      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

115
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({
SELECT ctx, pepProjectId, keywordTarget, keyword
camera.id AS cameraId, })
camera.name AS cameraName,
camera_status_alarm.id AS alarmId, const alarmRes = await clickHouse.vcmp.query(
camera_status_alarm.create_time AS createTime, `
camera_status_alarm.update_time AS updateTime, SELECT
camera_status_alarm.platform AS platform, cameraAlarm.cameraId AS cameraId,
camera_status_resolve.resolve AS resolve cameraAlarm.cameraName AS cameraName,
FROM cameraAlarm.cameraSerialNo AS cameraSerialNo,
camera_status_alarm cameraAlarm.cameraChannelNo AS cameraChannelNo,
LEFT JOIN camera cameraAlarm.alarmId AS alarmId,
ON camera.serial_no = camera_status_alarm.serial_no cameraAlarm.createTime AS createTime,
AND camera.channel_no = camera_status_alarm.channel_no cameraAlarm.updateTime AS updateTime,
LEFT JOIN camera_status cameraAlarm.platform AS platform,
ON camera_status_alarm.platform = camera_status.platform camera_status_resolve.id AS resolveId,
AND camera_status_alarm.status_id = camera_status.id camera_status.describe AS statusDescribe,
LEFT JOIN camera_status_resolve camera_status_resolve.resolve AS resolve,
ON camera_status_resolve.status_id = camera_status.id "gbCamera".online AS cameraOnline,
`).toPromise() anxinIpc.t_video_ipc.name,
anxinStruc.name AS strucName,
anxinStruc.id AS strucId
FROM
(
SELECT
camera.id AS cameraId,
camera.gb_id AS gbId,
camera.name AS cameraName,
camera_status_alarm.id AS alarmId,
camera_status_alarm.create_time AS createTime,
camera_status_alarm.update_time AS updateTime,
camera_status_alarm.platform AS platform,
camera_status_alarm.status_id AS statusId,
camera_status_alarm.serial_no AS cameraSerialNo,
camera_status_alarm.channel_no AS cameraChannelNo
FROM camera_status_alarm
LEFT 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.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
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
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 = []

46
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))
@ -99,25 +100,25 @@ module.exports = function (app, opts) {
const undelStrucRes = anxinProjectIds.length ? const undelStrucRes = anxinProjectIds.length ?
await clickHouse.anxinyun.query( await clickHouse.anxinyun.query(
` `
SELECT SELECT
t_project.id AS projectId, t_project.id AS projectId,
t_structure.id AS strucId, t_structure.id AS strucId,
t_structure.name AS strucName, t_structure.name AS strucName,
project_state project_state
FROM FROM
t_project t_project
LEFT JOIN LEFT JOIN
t_project_structure t_project_structure
ON t_project_structure.project = t_project.id ON t_project_structure.project = t_project.id
RIGHT JOIN RIGHT JOIN
t_structure t_structure
ON t_structure.id = t_project_structure.structure ON t_structure.id = t_project_structure.structure
WHERE WHERE
project_state != -1 project_state != -1
AND AND
t_project.id IN (${anxinProjectIds.join(',')}) t_project.id IN (${anxinProjectIds.join(',')})
${undelStrucWhereOptions.length ? `AND ${undelStrucWhereOptions.join(' AND ')}` : ''} ${undelStrucWhereOptions.length ? `AND ${undelStrucWhereOptions.join(' AND ')}` : ''}
` `
).toPromise() : ).toPromise() :
[] []
@ -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