From dd8f6f952879861b1b3a38dd768b1fc0743d921d Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 27 Sep 2022 09:30:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BA=8F=E5=88=97=E5=8F=B7+?= =?UTF-8?q?=E9=80=9A=E9=81=93=E5=8F=B7=E5=94=AF=E4=B8=80=E7=9A=84=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E6=91=84=E5=83=8F=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/VideoAccess-VCMP/api/.vscode/launch.json | 3 +- .../api/app/lib/controllers/camera/index.js | 35 +++++++++++++++++++ .../api/app/lib/controllers/status/alarm.js | 17 ++++++--- .../api/app/lib/models/camera_status_alarm.js | 30 +++++++++++----- .../api/app/lib/routes/camera/index.js | 3 ++ code/VideoAccess-VCMP/api/config.js | 1 + .../api/sequelize-automate.config.js | 2 +- .../schema/1.create_camera_status_alarm.sql | 12 ++++--- 8 files changed, 84 insertions(+), 19 deletions(-) diff --git a/code/VideoAccess-VCMP/api/.vscode/launch.json b/code/VideoAccess-VCMP/api/.vscode/launch.json index 2aa9572..82ad12c 100644 --- a/code/VideoAccess-VCMP/api/.vscode/launch.json +++ b/code/VideoAccess-VCMP/api/.vscode/launch.json @@ -15,7 +15,8 @@ "args": [ "-p 4000", "-f http://localhost:4000", - "-g postgres://postgres:123@10.8.30.32:5432/video_access", + // "-g postgres://postgres:123@10.8.30.32:5432/video_access", + "-g postgres://postgres:123@10.8.30.166:5432/video_access-dev", "--redisHost 10.8.30.112", "--redisPort 6379", "--axyApiUrl http://127.0.0.1:4100", diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js index 365cca3..581bbee 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js @@ -301,6 +301,40 @@ async function getCameraListAll (ctx) { } } +async function getCmaeraUniqueConfig (ctx) { + // 为 李玉 python 摄像头状态查询的摄像头列表查询 + // 获取所有已配置的序列号+通道号唯一的摄像头 + try { + const { models } = ctx.fs.dc; + const sequelize = ctx.fs.dc.orm; + // TODO: 目前只获取 yingshi 的 + + const cameraRes = await sequelize.query(` + SELECT DISTINCT("serial_no", "channel_no"), + camera.id, + "camera"."serial_no" AS "serialNo", + "camera"."type" AS "type", + "camera"."channel_no" AS "channelNo", + "secretYingshi"."token" AS "yingshiToken" + FROM "camera" AS "camera" + LEFT OUTER JOIN "secret_yingshi" AS "secretYingshi" + ON "camera"."yingshi_secret_id" = "secretYingshi"."id" + WHERE "camera"."delete" = false + AND "camera"."type" = 'yingshi' + AND "camera"."recycle_time" IS NULL; + `) + + ctx.status = 200; + ctx.body = cameraRes[0] + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + async function banned (ctx) { try { const { models } = ctx.fs.dc; @@ -587,6 +621,7 @@ module.exports = { getCameraProject, getCamera, getCameraListAll, + getCmaeraUniqueConfig, detail, banned, del, diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js b/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js index 5b22be6..75d0b88 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js @@ -4,11 +4,12 @@ const moment = require('moment'); async function record (ctx) { try { const { models } = ctx.fs.dc; - const { statusCode, description = '', cameraId, platform = 'yingshi' } = ctx.request.body; + const { statusCode, description = '', cameraId, platform = 'yingshi', serialNo, channelNo } = ctx.request.body; let statusRes = await models.CameraStatus.findOne({ where: { - status: statusCode + status: statusCode, + platform, } }) let alarmRes = null; @@ -25,7 +26,10 @@ async function record (ctx) { statusId: statusRes.id, description, cameraId, - confirm: null + confirm: null, + serialNo, + channelNo, + platform, } }) } @@ -34,14 +38,17 @@ async function record (ctx) { updateTime: moment().format() }) } else { - await models.CameraStatusAlarm.create({ + alarmRes = await models.CameraStatusAlarm.create({ statusId: statusRes.id, description, createTime: moment().format(), cameraId, + serialNo, + channelNo, + platform, }) } - + ctx.status = 204; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: error`); diff --git a/code/VideoAccess-VCMP/api/app/lib/models/camera_status_alarm.js b/code/VideoAccess-VCMP/api/app/lib/models/camera_status_alarm.js index 32e7aa3..dc8540c 100644 --- a/code/VideoAccess-VCMP/api/app/lib/models/camera_status_alarm.js +++ b/code/VideoAccess-VCMP/api/app/lib/models/camera_status_alarm.js @@ -73,18 +73,32 @@ module.exports = dc => { field: "update_time", autoIncrement: false }, - cameraId: { - type: DataTypes.INTEGER, + serialNo: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "序列号", + primaryKey: false, + field: "serial_no", + autoIncrement: false + }, + channelNo: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "通道号", + primaryKey: false, + field: "channel_no", + autoIncrement: false + }, + platform: { + type: DataTypes.STRING, allowNull: true, defaultValue: null, comment: null, primaryKey: false, - field: "camera_id", - autoIncrement: false, - references: { - key: "id", - model: "camera" - } + field: "platform", + autoIncrement: false } }, { tableName: "camera_status_alarm", diff --git a/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js b/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js index 2a3ce05..229d524 100644 --- a/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js @@ -73,4 +73,7 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['POST/camera/remark'] = { content: '编辑摄像头备注', visible: false }; router.post('/camera/remark', camera.remark); + + app.fs.api.logAttr['GET/camera/unique/all'] = { content: '获取全部摄像头,序列号+通道号唯一', visible: false }; + router.get('/camera/unique/all', camera.getCmaeraUniqueConfig); }; diff --git a/code/VideoAccess-VCMP/api/config.js b/code/VideoAccess-VCMP/api/config.js index 68bf66a..7bfbc54 100644 --- a/code/VideoAccess-VCMP/api/config.js +++ b/code/VideoAccess-VCMP/api/config.js @@ -95,6 +95,7 @@ const product = { { p: '/camera', o: 'GET' }, // 暂时滴 { p: '/application/check', o: 'GET' }, // 暂时滴 { p: '/status/alarm', o: 'POST' }, + { p: '/camera/unique/all', o: 'GET' }, ], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由 redis: { host: IOTA_REDIS_SERVER_HOST, diff --git a/code/VideoAccess-VCMP/api/sequelize-automate.config.js b/code/VideoAccess-VCMP/api/sequelize-automate.config.js index 9a97578..1e04c58 100644 --- a/code/VideoAccess-VCMP/api/sequelize-automate.config.js +++ b/code/VideoAccess-VCMP/api/sequelize-automate.config.js @@ -26,7 +26,7 @@ module.exports = { dir: './app/lib/models', // 指定输出 models 文件的目录 typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义 emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir` - tables: ['camera_status_alarm',], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 + tables: ['camera_status_alarm_camera',], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性 tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中 ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面 diff --git a/code/VideoAccess-VCMP/script/1.3.3/schema/1.create_camera_status_alarm.sql b/code/VideoAccess-VCMP/script/1.3.3/schema/1.create_camera_status_alarm.sql index f7bc4ae..3799ccc 100644 --- a/code/VideoAccess-VCMP/script/1.3.3/schema/1.create_camera_status_alarm.sql +++ b/code/VideoAccess-VCMP/script/1.3.3/schema/1.create_camera_status_alarm.sql @@ -7,13 +7,13 @@ create table if not exists camera_status_alarm confirm_time timestamp with time zone, create_time timestamp with time zone, update_time timestamp with time zone, - camera_id integer, + serial_no varchar(64), + channel_no varchar(64), + platform varchar(32), constraint camera_status_alarm_pk primary key (id), constraint camera_status_alarm_camera_status_id_fk - foreign key (status_id) references camera_status, - constraint camera_status_alarm_camera_id_fk - foreign key (camera_id) references camera + foreign key (status_id) references camera_status ); comment on column camera_status_alarm.description is '描述'; @@ -24,6 +24,10 @@ comment on column camera_status_alarm.create_time is '生成时间'; comment on column camera_status_alarm.update_time is '更新时间'; +comment on column camera_status_alarm.serial_no is '序列号'; + +comment on column camera_status_alarm.channel_no is '通道号'; + create unique index if not exists camera_status_alarm_id_uindex on camera_status_alarm (id);