15 changed files with 1653 additions and 1445 deletions
@ -0,0 +1,57 @@ |
|||
'use strict'; |
|||
const moment = require('moment'); |
|||
|
|||
async function record (ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { statusCode, description = '', cameraId, platform = 'yingshi' } = ctx.request.body; |
|||
|
|||
let statusRes = await models.CameraStatus.findOne({ |
|||
where: { |
|||
status: statusCode |
|||
} |
|||
}) |
|||
let alarmRes = null; |
|||
if (!statusRes) { |
|||
statusRes = await models.CameraStatus.create({ |
|||
platform: platform, |
|||
status: statusCode, |
|||
describe: description, |
|||
forbidden: false, |
|||
}) |
|||
} else { |
|||
alarmRes = await models.CameraStatusAlarm.findOne({ |
|||
where: { |
|||
statusId: statusRes.id, |
|||
description, |
|||
cameraId, |
|||
confirm: null |
|||
} |
|||
}) |
|||
} |
|||
if (alarmRes) { |
|||
await models.CameraStatusAlarm.update({ |
|||
updateTime: moment().format() |
|||
}) |
|||
} else { |
|||
await models.CameraStatusAlarm.create({ |
|||
statusId: statusRes.id, |
|||
description, |
|||
createTime: moment().format(), |
|||
cameraId, |
|||
}) |
|||
} |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
record, |
|||
}; |
@ -0,0 +1,96 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const CameraStatusAlarm = sequelize.define("cameraStatusAlarm", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "camera_status_alarm_id_uindex" |
|||
}, |
|||
statusId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "status_id", |
|||
autoIncrement: false, |
|||
references: { |
|||
key: "id", |
|||
model: "cameraStatus" |
|||
} |
|||
}, |
|||
description: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "描述", |
|||
primaryKey: false, |
|||
field: "description", |
|||
autoIncrement: false |
|||
}, |
|||
confirm: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "确认信息", |
|||
primaryKey: false, |
|||
field: "confirm", |
|||
autoIncrement: false |
|||
}, |
|||
confirmTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "confirm_time", |
|||
autoIncrement: false |
|||
}, |
|||
createTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "生成时间", |
|||
primaryKey: false, |
|||
field: "create_time", |
|||
autoIncrement: false |
|||
}, |
|||
updateTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "更新时间", |
|||
primaryKey: false, |
|||
field: "update_time", |
|||
autoIncrement: false |
|||
}, |
|||
cameraId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "camera_id", |
|||
autoIncrement: false, |
|||
references: { |
|||
key: "id", |
|||
model: "camera" |
|||
} |
|||
} |
|||
}, { |
|||
tableName: "camera_status_alarm", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.CameraStatusAlarm = CameraStatusAlarm; |
|||
return CameraStatusAlarm; |
|||
}; |
@ -0,0 +1,29 @@ |
|||
create table if not exists camera_status_alarm |
|||
( |
|||
id serial not null, |
|||
status_id integer not null, |
|||
description varchar(1024), |
|||
confirm varchar(1024), |
|||
confirm_time timestamp with time zone, |
|||
create_time timestamp with time zone, |
|||
update_time timestamp with time zone, |
|||
camera_id integer, |
|||
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 |
|||
); |
|||
|
|||
comment on column camera_status_alarm.description is '描述'; |
|||
|
|||
comment on column camera_status_alarm.confirm is '确认信息'; |
|||
|
|||
comment on column camera_status_alarm.create_time is '生成时间'; |
|||
|
|||
comment on column camera_status_alarm.update_time is '更新时间'; |
|||
|
|||
create unique index if not exists camera_status_alarm_id_uindex |
|||
on camera_status_alarm (id); |
|||
|
Loading…
Reference in new issue