56 lines
2.3 KiB
JavaScript
56 lines
2.3 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 扫码记录:带上「当时的工作台快照」+ 运单查询要用的索引
|
||
*
|
||
* 为什么要快照:录像回放要按**当时的**工作台配置(哪台录像机、哪些摄像头、怎么布局、
|
||
* 录制范围多少秒)去拉流。工作台后来被改/被删了,历史运单照样要能查回来,
|
||
* 所以扫码入库时就把配置冻一份 JSON 存这里。
|
||
*
|
||
* - `workstation_id`:便于按工作台统计/过滤(快照里也有,这个列只是方便 JOIN)
|
||
* - `workstation_snapshot`:JSON,结构见 `app/service/pack.js` 的 `buildSnapshot()`
|
||
*
|
||
* 索引:
|
||
* - `(subject_id, barcode)`:按运单号查(主体内精确匹配)
|
||
* - `(scanner_id, channel_id, scan_time)`:散单要取同通道的「上一条/下一条」扫码时间
|
||
*/
|
||
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
const { BIGINT, JSON: JSONType } = Sequelize;
|
||
|
||
await queryInterface.addColumn('scan_records', 'workstation_id', {
|
||
type: BIGINT.UNSIGNED,
|
||
allowNull: true,
|
||
comment: '当时绑定的工作台 workstations.id(快照里有完整信息)',
|
||
});
|
||
|
||
await queryInterface.addColumn('scan_records', 'workstation_snapshot', {
|
||
type: JSONType,
|
||
allowNull: true,
|
||
comment: '工作台快照(录像机/摄像头/布局/录制范围),回放按它拉流',
|
||
});
|
||
|
||
await queryInterface.addIndex('scan_records', [ 'subject_id', 'barcode' ], {
|
||
name: 'idx_scan_subject_barcode',
|
||
});
|
||
|
||
await queryInterface.addIndex('scan_records', [ 'scanner_id', 'channel_id', 'scan_time' ], {
|
||
name: 'idx_scan_channel_seq',
|
||
});
|
||
|
||
// 中控上报时按 (scanner_id, channel_id) 找工作台,没索引会全表扫
|
||
await queryInterface.addIndex('workstation_scan_channels', [ 'scanner_id', 'channel_id' ], {
|
||
name: 'idx_wsc_scanner_channel',
|
||
});
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.removeIndex('workstation_scan_channels', 'idx_wsc_scanner_channel');
|
||
await queryInterface.removeIndex('scan_records', 'idx_scan_channel_seq');
|
||
await queryInterface.removeIndex('scan_records', 'idx_scan_subject_barcode');
|
||
await queryInterface.removeColumn('scan_records', 'workstation_snapshot');
|
||
await queryInterface.removeColumn('scan_records', 'workstation_id');
|
||
},
|
||
};
|