|
|
|
'use strict';
|
|
|
|
async function deviceType (ctx) {
|
|
|
|
try {
|
|
|
|
const { models } = ctx.fs.dc;
|
|
|
|
|
|
|
|
ctx.status = 200;
|
|
|
|
ctx.body = []
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = {
|
|
|
|
message: typeof error == 'string' ? error : undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function alarmList (ctx) {
|
|
|
|
try {
|
|
|
|
const { models } = ctx.fs.dc;
|
|
|
|
const { clickHouse } = ctx.app.fs
|
|
|
|
const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs
|
|
|
|
const { database: anxinyun } = clickHouse.anxinyun.opts.config
|
|
|
|
const { pepProjectId, keywordTarget, keyword } = ctx.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
|
|
|
|
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 positionD = {}
|
|
|
|
// 每个设备一个告警
|
|
|
|
for (let a of alarmRes) {
|
|
|
|
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,
|
|
|
|
name: a.strucName
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let d = {
|
|
|
|
cameraId: a.cameraId,
|
|
|
|
cameraName: a.cameraName,
|
|
|
|
camerOnline: a.cameraOnline,
|
|
|
|
cameraSerialNo: a.cameraSerialNo,
|
|
|
|
cameraChannelNo: a.cameraChannelNo,
|
|
|
|
createTime: a.createTime,
|
|
|
|
updateTime: a.updateTime,
|
|
|
|
platform: a.platform,
|
|
|
|
statusDescribe: a.statusDescribe,
|
|
|
|
alarmId: a.alarmId,
|
|
|
|
resolve: [],
|
|
|
|
struc: []
|
|
|
|
}
|
|
|
|
if (a.resolveId) {
|
|
|
|
d.resolve.push({
|
|
|
|
id: a.resolveId,
|
|
|
|
resolve: a.resolve
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (a.strucId) {
|
|
|
|
d.struc.push({
|
|
|
|
id: a.strucId,
|
|
|
|
name: a.strucName
|
|
|
|
})
|
|
|
|
}
|
|
|
|
returnD.push(d)
|
|
|
|
positionD[a.cameraId] = {
|
|
|
|
positionReturnD: returnD.length - 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.status = 200;
|
|
|
|
ctx.body = returnD
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = {
|
|
|
|
message: typeof error == 'string' ? error : undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function confirm (ctx) {
|
|
|
|
try {
|
|
|
|
const { models } = ctx.fs.dc;
|
|
|
|
|
|
|
|
ctx.status = 20;
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = {
|
|
|
|
message: typeof error == 'string' ? error : undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
deviceType,
|
|
|
|
alarmList
|
|
|
|
};
|