From 40bda2ba3aed9234bdb54dc756d5df3639a3ae06 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Sat, 8 Oct 2022 09:26:58 +0800 Subject: [PATCH 1/9] =?UTF-8?q?/status/check=20=E4=B8=8D=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/VideoAccess-VCMP/api/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/code/VideoAccess-VCMP/api/config.js b/code/VideoAccess-VCMP/api/config.js index c21ff25..9917a00 100644 --- a/code/VideoAccess-VCMP/api/config.js +++ b/code/VideoAccess-VCMP/api/config.js @@ -97,6 +97,7 @@ const product = { { p: '/status/alarm', o: 'POST' }, { p: '/camera/unique/all', o: 'GET' }, { p: '/status/alarm/confirm', o: 'PUT' }, + { p: '/status/check', o: 'GET' }, ], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由 redis: { host: IOTA_REDIS_SERVER_HOST, From b60bf61233049b2b004c49ec917cdbed6a36b1b6 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Sat, 8 Oct 2022 09:28:02 +0800 Subject: [PATCH 2/9] =?UTF-8?q?/status/check=20=E8=BF=98=E6=98=AF=E8=A6=81?= =?UTF-8?q?=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/VideoAccess-VCMP/api/config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/code/VideoAccess-VCMP/api/config.js b/code/VideoAccess-VCMP/api/config.js index 9917a00..c21ff25 100644 --- a/code/VideoAccess-VCMP/api/config.js +++ b/code/VideoAccess-VCMP/api/config.js @@ -97,7 +97,6 @@ const product = { { p: '/status/alarm', o: 'POST' }, { p: '/camera/unique/all', o: 'GET' }, { p: '/status/alarm/confirm', o: 'PUT' }, - { p: '/status/check', o: 'GET' }, ], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由 redis: { host: IOTA_REDIS_SERVER_HOST, From 50458a3a15b46ef9c74d5723b6948e60ef8ebd07 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Sat, 8 Oct 2022 14:40:11 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E8=A7=86=E9=A2=91=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=81=A2=E5=A4=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/app/lib/controllers/status/alarm.js | 66 ++++++++++++------- .../api/app/lib/models/camera_status_alarm.js | 9 +++ .../api/sequelize-automate.config.js | 6 +- .../script/1.3.4/schema/1.alert_tables.sql | 5 ++ 4 files changed, 61 insertions(+), 25 deletions(-) create mode 100644 code/VideoAccess-VCMP/script/1.3.4/schema/1.alert_tables.sql 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 894aa48..d22ce79 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js @@ -6,14 +6,19 @@ async function record (ctx) { const { models } = ctx.fs.dc; const { statusCode, description = '', platform = 'yingshi', serialNo, channelNo } = ctx.request.body; - let statusRes = await models.CameraStatus.findOne({ - where: { - status: statusCode, - platform, - } - }) + // statusCode == 0 是自动恢复 + + const isRestore = statusCode == 0 + let statusRes = isRestore ? null : + await models.CameraStatus.findOne({ + where: { + status: statusCode, + platform, + } + }) let alarmRes = null; - if (!statusRes) { + if (!statusRes && !isRestore) { + // 没有这种告警状态就新建一个 statusRes = await models.CameraStatus.create({ platform: platform, status: statusCode, @@ -21,26 +26,43 @@ async function record (ctx) { forbidden: false, }) } else { - alarmRes = await models.CameraStatusAlarm.findOne({ - where: { - statusId: statusRes.id, - description, - confirm: null, - serialNo, - channelNo, - platform, - } + let findWhere = { + confirmTime: null, + serialNo, + channelNo, + platform, + } + if (isRestore) { + + } else { + findWhere.description = description + } + if (statusRes) { + findWhere.statusId = statusRes.id + } + alarmRes = await models.CameraStatusAlarm[isRestore ? 'findAll' : 'findOne']({ + where: findWhere }) } - if (alarmRes) { - await models.CameraStatusAlarm.update({ - updateTime: moment().format() - }, { + if ( + (!isRestore && alarmRes) + || (isRestore && alarmRes && alarmRes.length) + ) { + let updateD = { + updateTime: moment().format(), + confirmTime: moment().format(), + } + if (isRestore) { + updateD.autoRestore = true + } + await models.CameraStatusAlarm.update(updateD, { where: { - id: alarmRes.id + id: { + $in: isRestore ? alarmRes.map(a => a.id) : [alarmRes.id] + } } }) - } else { + } else if (!isRestore) { alarmRes = await models.CameraStatusAlarm.create({ statusId: statusRes.id, description, 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 dc8540c..e6917e7 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 @@ -99,6 +99,15 @@ module.exports = dc => { primaryKey: false, field: "platform", autoIncrement: false + }, + autoRestore: { + type: DataTypes.BOOLEAN, + allowNull: true, + defaultValue: false, + comment: "是否自动恢复的", + primaryKey: false, + field: "auto_restore", + autoIncrement: false } }, { tableName: "camera_status_alarm", diff --git a/code/VideoAccess-VCMP/api/sequelize-automate.config.js b/code/VideoAccess-VCMP/api/sequelize-automate.config.js index 1e04c58..168adda 100644 --- a/code/VideoAccess-VCMP/api/sequelize-automate.config.js +++ b/code/VideoAccess-VCMP/api/sequelize-automate.config.js @@ -1,11 +1,11 @@ module.exports = { // 数据库配置 与 sequelize 相同 dbOptions: { - database: 'video_access', + database: 'video_access-dev', username: 'postgres', password: '123', dialect: 'postgres', - host: '10.8.30.32', + host: '10.8.30.166', port: 5432, define: { underscored: false, @@ -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_camera',], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 + tables: ['camera_status_alarm',], // 指定生成哪些表的 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.4/schema/1.alert_tables.sql b/code/VideoAccess-VCMP/script/1.3.4/schema/1.alert_tables.sql new file mode 100644 index 0000000..3b6ab0b --- /dev/null +++ b/code/VideoAccess-VCMP/script/1.3.4/schema/1.alert_tables.sql @@ -0,0 +1,5 @@ +alter table camera_status_alarm + add auto_restore bool default false; + +comment on column camera_status_alarm.auto_restore is '是否自动恢复的'; + From a3ce4ce67abd9bba09936e27a5d0883faab67d2a Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Sat, 8 Oct 2022 15:50:46 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/VideoAccess-VCMP/api/.vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/VideoAccess-VCMP/api/.vscode/launch.json b/code/VideoAccess-VCMP/api/.vscode/launch.json index 82ad12c..6e40169 100644 --- a/code/VideoAccess-VCMP/api/.vscode/launch.json +++ b/code/VideoAccess-VCMP/api/.vscode/launch.json @@ -15,7 +15,7 @@ "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.166:5432/video_access", "-g postgres://postgres:123@10.8.30.166:5432/video_access-dev", "--redisHost 10.8.30.112", "--redisPort 6379", From d007072b6abd71cd83ec19ba818e4278f61e0026 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Sun, 9 Oct 2022 09:18:14 +0800 Subject: [PATCH 5/9] =?UTF-8?q?/status/check=20=E4=B8=8D=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/VideoAccess-VCMP/api/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/code/VideoAccess-VCMP/api/config.js b/code/VideoAccess-VCMP/api/config.js index c21ff25..71511bb 100644 --- a/code/VideoAccess-VCMP/api/config.js +++ b/code/VideoAccess-VCMP/api/config.js @@ -97,6 +97,7 @@ const product = { { p: '/status/alarm', o: 'POST' }, { p: '/camera/unique/all', o: 'GET' }, { p: '/status/alarm/confirm', o: 'PUT' }, + { p: '/status/check', o: 'GET' } ], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由 redis: { host: IOTA_REDIS_SERVER_HOST, From 8d8ec1b7d22af0d43f615bf33799843de5ada8e9 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Mon, 10 Oct 2022 11:30:07 +0800 Subject: [PATCH 6/9] debug --- code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js | 2 +- code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js | 2 +- code/VideoAccess-VCMP/api/app/lib/controllers/status/index.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 581bbee..4fdb38c 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js @@ -327,7 +327,7 @@ async function getCmaeraUniqueConfig (ctx) { ctx.status = 200; ctx.body = cameraRes[0] } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined 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 d22ce79..c436d79 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js @@ -75,7 +75,7 @@ async function record (ctx) { ctx.status = 204; } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/status/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/status/index.js index 1516892..b0d5900 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/status/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/status/index.js @@ -270,7 +270,7 @@ async function statusRecord (ctx) { ctx.status = 20; } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined From c4bf7bf019d4e3a72515764f302b32328c3ff9e4 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Mon, 10 Oct 2022 16:25:45 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E8=A7=86=E9=A2=91=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c436d79..509366f 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js @@ -88,7 +88,7 @@ async function confirm (ctx) { const { models } = ctx.fs.dc; const { alarmId, content } = ctx.request.body; - await models.CameraStatusAlarm.findOne({ + await models.CameraStatusAlarm.update({ confirm: content, confirmTime: moment().format(), }, { From f1c9e66a5cce474b21a43f92f20749f965cd518d Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Mon, 10 Oct 2022 16:52:21 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E8=A7=86=E9=A2=91=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E6=97=B6=E5=8C=BA=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/app/lib/controllers/status/alarm.js | 6 +++--- .../VideoAccess-VCMP/script/1.3.4/schema/1.alert_tables.sql | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) 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 509366f..a65e243 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js @@ -49,8 +49,8 @@ async function record (ctx) { || (isRestore && alarmRes && alarmRes.length) ) { let updateD = { - updateTime: moment().format(), - confirmTime: moment().format(), + updateTime: moment().format('YYYY-MM-DD HH:mm:ss'), + confirmTime: moment().format('YYYY-MM-DD HH:mm:ss'), } if (isRestore) { updateD.autoRestore = true @@ -66,7 +66,7 @@ async function record (ctx) { alarmRes = await models.CameraStatusAlarm.create({ statusId: statusRes.id, description, - createTime: moment().format(), + createTime: moment().format('YYYY-MM-DD HH:mm:ss'), serialNo, channelNo, platform, diff --git a/code/VideoAccess-VCMP/script/1.3.4/schema/1.alert_tables.sql b/code/VideoAccess-VCMP/script/1.3.4/schema/1.alert_tables.sql index 3b6ab0b..9882213 100644 --- a/code/VideoAccess-VCMP/script/1.3.4/schema/1.alert_tables.sql +++ b/code/VideoAccess-VCMP/script/1.3.4/schema/1.alert_tables.sql @@ -3,3 +3,8 @@ alter table camera_status_alarm comment on column camera_status_alarm.auto_restore is '是否自动恢复的'; +alter table camera_status_alarm alter column confirm_time type timestamp(6) using confirm_time::timestamp(6); + +alter table camera_status_alarm alter column create_time type timestamp(6) using create_time::timestamp(6); + +alter table camera_status_alarm alter column update_time type timestamp(6) using update_time::timestamp(6); From 7cae018b1e2036efa9dae9057019fa18fe77fe94 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 11 Oct 2022 16:34:09 +0800 Subject: [PATCH 9/9] =?UTF-8?q?fix=20=E6=9B=B4=E6=96=B0=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a65e243..7fcfd82 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js @@ -50,10 +50,10 @@ async function record (ctx) { ) { let updateD = { updateTime: moment().format('YYYY-MM-DD HH:mm:ss'), - confirmTime: moment().format('YYYY-MM-DD HH:mm:ss'), } if (isRestore) { updateD.autoRestore = true + updateD.confirmTime = moment().format('YYYY-MM-DD HH:mm:ss') } await models.CameraStatusAlarm.update(updateD, { where: {