Browse Source

Merge branch 'dev_trial' of https://gitea.anxinyun.cn/free-sun/FS-IOT into dev_trial

dev_trial
wenlele 3 years ago
parent
commit
c00c085919
  1. 2
      code/VideoAccess-VCMP/api/.vscode/launch.json
  2. 2
      code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js
  3. 54
      code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js
  4. 2
      code/VideoAccess-VCMP/api/app/lib/controllers/status/index.js
  5. 9
      code/VideoAccess-VCMP/api/app/lib/models/camera_status_alarm.js
  6. 1
      code/VideoAccess-VCMP/api/config.js
  7. 6
      code/VideoAccess-VCMP/api/sequelize-automate.config.js
  8. 10
      code/VideoAccess-VCMP/script/1.3.4/schema/1.alert_tables.sql

2
code/VideoAccess-VCMP/api/.vscode/launch.json

@ -15,7 +15,7 @@
"args": [ "args": [
"-p 4000", "-p 4000",
"-f http://localhost: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", "-g postgres://postgres:123@10.8.30.166:5432/video_access-dev",
"--redisHost 10.8.30.112", "--redisHost 10.8.30.112",
"--redisPort 6379", "--redisPort 6379",

2
code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js

@ -327,7 +327,7 @@ async function getCmaeraUniqueConfig (ctx) {
ctx.status = 200; ctx.status = 200;
ctx.body = cameraRes[0] ctx.body = cameraRes[0]
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined

54
code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js

@ -6,14 +6,19 @@ async function record (ctx) {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { statusCode, description = '', platform = 'yingshi', serialNo, channelNo } = ctx.request.body; const { statusCode, description = '', platform = 'yingshi', serialNo, channelNo } = ctx.request.body;
let statusRes = await models.CameraStatus.findOne({ // statusCode == 0 是自动恢复
const isRestore = statusCode == 0
let statusRes = isRestore ? null :
await models.CameraStatus.findOne({
where: { where: {
status: statusCode, status: statusCode,
platform, platform,
} }
}) })
let alarmRes = null; let alarmRes = null;
if (!statusRes) { if (!statusRes && !isRestore) {
// 没有这种告警状态就新建一个
statusRes = await models.CameraStatus.create({ statusRes = await models.CameraStatus.create({
platform: platform, platform: platform,
status: statusCode, status: statusCode,
@ -21,30 +26,47 @@ async function record (ctx) {
forbidden: false, forbidden: false,
}) })
} else { } else {
alarmRes = await models.CameraStatusAlarm.findOne({ let findWhere = {
where: { confirmTime: null,
statusId: statusRes.id,
description,
confirm: null,
serialNo, serialNo,
channelNo, channelNo,
platform, platform,
} }
if (isRestore) {
} else {
findWhere.description = description
}
if (statusRes) {
findWhere.statusId = statusRes.id
}
alarmRes = await models.CameraStatusAlarm[isRestore ? 'findAll' : 'findOne']({
where: findWhere
}) })
} }
if (alarmRes) { if (
await models.CameraStatusAlarm.update({ (!isRestore && alarmRes)
updateTime: moment().format() || (isRestore && alarmRes && alarmRes.length)
}, { ) {
let updateD = {
updateTime: 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: { where: {
id: alarmRes.id id: {
$in: isRestore ? alarmRes.map(a => a.id) : [alarmRes.id]
}
} }
}) })
} else { } else if (!isRestore) {
alarmRes = await models.CameraStatusAlarm.create({ alarmRes = await models.CameraStatusAlarm.create({
statusId: statusRes.id, statusId: statusRes.id,
description, description,
createTime: moment().format(), createTime: moment().format('YYYY-MM-DD HH:mm:ss'),
serialNo, serialNo,
channelNo, channelNo,
platform, platform,
@ -53,7 +75,7 @@ async function record (ctx) {
ctx.status = 204; ctx.status = 204;
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined
@ -66,7 +88,7 @@ async function confirm (ctx) {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { alarmId, content } = ctx.request.body; const { alarmId, content } = ctx.request.body;
await models.CameraStatusAlarm.findOne({ await models.CameraStatusAlarm.update({
confirm: content, confirm: content,
confirmTime: moment().format(), confirmTime: moment().format(),
}, { }, {

2
code/VideoAccess-VCMP/api/app/lib/controllers/status/index.js

@ -270,7 +270,7 @@ async function statusRecord (ctx) {
ctx.status = 20; ctx.status = 20;
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined

9
code/VideoAccess-VCMP/api/app/lib/models/camera_status_alarm.js

@ -99,6 +99,15 @@ module.exports = dc => {
primaryKey: false, primaryKey: false,
field: "platform", field: "platform",
autoIncrement: false autoIncrement: false
},
autoRestore: {
type: DataTypes.BOOLEAN,
allowNull: true,
defaultValue: false,
comment: "是否自动恢复的",
primaryKey: false,
field: "auto_restore",
autoIncrement: false
} }
}, { }, {
tableName: "camera_status_alarm", tableName: "camera_status_alarm",

1
code/VideoAccess-VCMP/api/config.js

@ -97,6 +97,7 @@ const product = {
{ p: '/status/alarm', o: 'POST' }, { p: '/status/alarm', o: 'POST' },
{ p: '/camera/unique/all', o: 'GET' }, { p: '/camera/unique/all', o: 'GET' },
{ p: '/status/alarm/confirm', o: 'PUT' }, { p: '/status/alarm/confirm', o: 'PUT' },
{ p: '/status/check', o: 'GET' }
], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由 ], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由
redis: { redis: {
host: IOTA_REDIS_SERVER_HOST, host: IOTA_REDIS_SERVER_HOST,

6
code/VideoAccess-VCMP/api/sequelize-automate.config.js

@ -1,11 +1,11 @@
module.exports = { module.exports = {
// 数据库配置 与 sequelize 相同 // 数据库配置 与 sequelize 相同
dbOptions: { dbOptions: {
database: 'video_access', database: 'video_access-dev',
username: 'postgres', username: 'postgres',
password: '123', password: '123',
dialect: 'postgres', dialect: 'postgres',
host: '10.8.30.32', host: '10.8.30.166',
port: 5432, port: 5432,
define: { define: {
underscored: false, underscored: false,
@ -26,7 +26,7 @@ module.exports = {
dir: './app/lib/models', // 指定输出 models 文件的目录 dir: './app/lib/models', // 指定输出 models 文件的目录
typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义 typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义
emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir` 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,则忽略改属性 skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性
tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中 tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中
ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面 ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面

10
code/VideoAccess-VCMP/script/1.3.4/schema/1.alert_tables.sql

@ -0,0 +1,10 @@
alter table camera_status_alarm
add auto_restore bool default false;
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);
Loading…
Cancel
Save