41 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 摄像头(NVR 通道)表模型(cameras)
*
* 一条记录 = 某台 NVR 上的一个通道。唯一键 `(nvr_id, channel_no)`:
* 同一台 NVR 重复导入同一个通道时做「更新/复活」,不会产生第二条。
*
* `ip` / `port` 是该数字通道对应的前端设备(可能是 ONVIF 摄像机),做展示与排障用。
*/
module.exports = (app) => {
const { BIGINT, STRING, INTEGER, TINYINT, BOOLEAN } = app.Sequelize;
const Camera = app.model.define('camera', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
subjectId: { type: BIGINT.UNSIGNED, comment: '所属主体 subjects.id(跟随 NVR)' },
nvrId: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属 NVR(nvrs.id)' },
channelNo: { type: INTEGER.UNSIGNED, allowNull: false, comment: '海康通道号' },
name: { type: STRING(64), allowNull: false, defaultValue: '', comment: '摄像头名称(业务别名)' },
channelName: { type: STRING(64), comment: '设备通道名(ISAPI,拉取时刷新)' },
type: { type: STRING(16), allowNull: false, defaultValue: 'digital', comment: 'analog / digital' },
ip: { type: STRING(45), comment: '前端设备 IP' },
port: { type: INTEGER.UNSIGNED, comment: '前端设备管理端口' },
enabled: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '通道是否已配置' },
hasPtz: { type: BOOLEAN, allowNull: false, defaultValue: false, comment: '是否支持云台(PTZ)' },
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1启用 0停用' },
remark: { type: STRING(255), comment: '备注' },
}, {
tableName: 'cameras',
paranoid: true,
comment: '摄像头(NVR 通道)表',
});
Camera.associate = function() {
app.model.Camera.belongsTo(app.model.Nvr, { foreignKey: 'nvr_id', as: 'nvr' });
app.model.Camera.hasMany(app.model.WorkstationCamera, { foreignKey: 'camera_id', as: 'workstationLinks' });
};
return Camera;
};