'use strict'; /** * 工作台 ↔ 扫码通道 绑定表(workstation_scan_channels) * * 「扫码通道」本身在中控上(scan_channels 表,键是 scanner_id + channel_id), * 这里存的是工作台与「某个中控的某个通道」的绑定,并冗余一份通道名快照, * 避免中控改名/离线时列表显示空白。 * * 唯一键 `(workstation_id, scanner_id, channel_id)`;解绑是物理删除。 */ module.exports = (app) => { const { BIGINT, STRING, INTEGER } = app.Sequelize; const WorkstationScanChannel = app.model.define('workstationScanChannel', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, workstationId: { type: BIGINT.UNSIGNED, allowNull: false, comment: '工作台 id' }, scannerId: { type: BIGINT.UNSIGNED, allowNull: false, comment: '扫码中控 id(scanners.id)' }, channelId: { type: STRING(64), allowNull: false, comment: '通道 id' }, channelName: { type: STRING(128), allowNull: false, defaultValue: '', comment: '通道名快照' }, sortNo: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '排序' }, remark: { type: STRING(255), comment: '备注' }, }, { tableName: 'workstation_scan_channels', timestamps: true, paranoid: false, comment: '工作台-扫码通道绑定表', }); WorkstationScanChannel.associate = function() { app.model.WorkstationScanChannel.belongsTo(app.model.Workstation, { foreignKey: 'workstation_id', as: 'workstation' }); app.model.WorkstationScanChannel.belongsTo(app.model.Scanner, { foreignKey: 'scanner_id', as: 'scanner' }); }; return WorkstationScanChannel; };