'use strict'; /** * 扫描中控通道表模型(scan_channels) * * 一台「中控(绑定端)」可以接多个扫码设备,每个扫码设备对应一个通道; * 中控通过 POST /api/scan/channels 把通道(channel_id + channel_name)上报到服务, * 一个通道一行,唯一键 (scanner_id, channel_id):中控再次上报同名通道就是更新。 * * 注意:channel_id 只在同一中控内唯一,所以关联时要用 (scanner_id, channel_id) 两个字段。 */ module.exports = (app) => { const { BIGINT, STRING, TINYINT, DATE } = app.Sequelize; const ScanChannel = app.model.define('scanChannel', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, subjectId: { type: BIGINT.UNSIGNED, comment: '所属主体 subjects.id(跟随中控)' }, scannerId: { type: BIGINT.UNSIGNED, allowNull: false, comment: '上报的中控(= scanners.id)' }, channelId: { type: STRING(64), allowNull: false, comment: '通道 id(中控上报,同一中控内唯一)' }, channelName: { type: STRING(128), allowNull: false, defaultValue: '', comment: '通道名(中控上报)' }, lastReportAt: { type: DATE, comment: '最近一次上报时间' }, status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1正常 0停用' }, remark: { type: STRING(255), comment: '备注' }, }, { tableName: 'scan_channels', paranoid: true, comment: '扫描中控通道表', }); ScanChannel.associate = function() { app.model.ScanChannel.belongsTo(app.model.Scanner, { foreignKey: 'scanner_id', as: 'scanner' }); }; return ScanChannel; };