diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index 817d7d9..9524981 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -6,16 +6,21 @@ async function groupList (ctx) { const { models } = ctx.fs.dc; const { clickHouse } = ctx.app.fs + const { database: dataAlarm } = clickHouse.dataAlarm.opts.config const groupRes = await clickHouse.anxinyun.query(` SELECT * FROM t_alarm_group `).toPromise(); for (let g of groupRes) { g.unit = await await clickHouse.anxinyun.query(` - SELECT * FROM t_alarm_group_unit WHERE group_id = ${g.id} + SELECT DISTINCT + t_alarm_group_unit.id AS id,t_alarm_group_unit.name AS name,t_alarm_group_unit.group_id AS groupId + FROM t_alarm_group_unit + INNER JOIN ${dataAlarm}.alarms + ON t_alarm_group_unit.id = ${dataAlarm}.alarms.AlarmGroupUnit + WHERE group_id = ${g.id} `).toPromise(); } - ctx.status = 200; ctx.body = groupRes } catch (error) { diff --git a/api/app/lib/controllers/alarm/video.js b/api/app/lib/controllers/alarm/video.js index 5ba4718..24bbacf 100644 --- a/api/app/lib/controllers/alarm/video.js +++ b/api/app/lib/controllers/alarm/video.js @@ -7,9 +7,15 @@ async function deviceType (ctx) { const { clickHouse } = ctx.app.fs const kindRes = await clickHouse.vcmp.query(` - SELECT * FROM camera_kind - `).toPromise() - + SELECT DISTINCT + camera_kind.id AS id,camera_kind.kind AS kind + FROM camera_kind + INNER JOIN camera + ON camera_kind.id = camera.kind_id + INNER JOIN camera_status_alarm + ON camera.channel_no = camera_status_alarm.channel_no + AND camera.serial_no = camera_status_alarm.serial_no + `).toPromise() ctx.status = 200; ctx.body = kindRes } catch (error) {