packServer/backend/database/migrations/20261024101000-create-workstation-login-records.js
liufumingren f8aa4c4899 feat(工作台): 成员扫码登入、面单摄像头与虚拟通道
- 工作台成员扫码登入:workstation_login_records 记录谁在什么时候登入/下线了哪台工作台,
  超时(团购 1h / 散单 30min)由 schedule/workstation_idle_offline 自动下线;
  运单查询的 packers 取当时的登入成员
- 面单摄像头识别:workstation_cameras.is_label_camera + service/label_scan 下发本机该跑的识别配置,
  设备端(桌面端 LabelScan 工作线程)按配置做面单识别并上报
- 虚拟通道 CAM-<工作台id>:工作台没接扫码枪时,面单摄像头那一路顶替扫码枪上报,records 规则按 ws_type 区分
- 桌面端:新增 LabelScanMonitor/LabelScanWorker/ScanDeviceKind 与面单预览页,扫描通道支持改名,静默窗口 5s

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-29 17:19:24 +08:00

82 lines
4.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';
/**
* 成员登录记录表(workstation_login_records)
*
* 一行 = 某个成员在某台工作台上的一次登录(扫码登录):
* - `status = 1` 表示**还在线**,`logout_at` 为空;
* - `status = 0` 表示已下线(手动下线 / 重置登录码 / 长时间不活跃),`logout_at` + `logout_reason` 有值。
*
* 两种用途:
* 1. 工作台「当前成员」:`status = 1` 且 `workstation_id = ?`;
* 2. 运单回放定位打包人:按 `workstation_id + login_at/logout_at` 找「该次扫码发生时还在线的人」,
* 所以 `(workstation_id, login_at)` 必须有索引。
*
* `name` 是登录当时记下的名字:属于该主体的成员记成员姓名(= 工号),否则记用户自己设置的昵称。
* `type` 预留给后续的登录方式扩展(当前只有 1 扫码登录)。
*
* 本表是流水 + 状态表,**不用软删除**,需要清理按时间物理删除。
*/
module.exports = {
async up(queryInterface, Sequelize) {
const { BIGINT, STRING, TINYINT, DATE, literal } = Sequelize;
await queryInterface.createTable('workstation_login_records', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
subject_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体 subjects.id' },
workstation_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '工作台 workstations.id' },
user_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '登录用户 users.id' },
member_id: { type: BIGINT.UNSIGNED, allowNull: true, comment: '主体成员 subject_members.id(非成员为空)' },
name: { type: STRING(64), allowNull: false, defaultValue: '', comment: '登录时记录的名字(成员工号/姓名,非成员用昵称)' },
type: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '登录类型:1 扫码登录(预留后续扩展)' },
login_code: { type: STRING(64), allowNull: true, comment: '登录时使用的工作台登录码(重置后便于对账)' },
login_at: { type: DATE, allowNull: false, comment: '登录时间' },
logout_at: { type: DATE, allowNull: true, comment: '下线时间(在线为空)' },
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1在线 0已下线' },
logout_reason: { type: STRING(32), allowNull: true, comment: '下线原因:manual / reset_code / idle_timeout / relogin' },
login_ip: { type: STRING(45), allowNull: true, comment: '登录 IP' },
created_at: {
type: DATE,
allowNull: false,
defaultValue: literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
updated_at: {
type: DATE,
allowNull: false,
defaultValue: literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
comment: '更新时间',
},
}, {
engine: 'InnoDB',
charset: 'utf8mb4',
collate: 'utf8mb4_general_ci',
comment: '工作台成员登录记录表',
});
// 按「工作台 + 时间」查历史(运单回放定位打包人)
await queryInterface.addIndex('workstation_login_records', [ 'workstation_id', 'login_at' ], {
name: 'idx_wlr_ws_login_at',
});
// 当前在线成员(工作台详情弹窗)
await queryInterface.addIndex('workstation_login_records', [ 'workstation_id', 'status' ], {
name: 'idx_wlr_ws_status',
});
// 一个人在多台工作台上的在线状态
await queryInterface.addIndex('workstation_login_records', [ 'user_id', 'status' ], {
name: 'idx_wlr_user_status',
});
await queryInterface.addIndex('workstation_login_records', [ 'subject_id', 'login_at' ], {
name: 'idx_wlr_subject_login_at',
});
// 定时任务每分钟扫「还在线」的记录
await queryInterface.addIndex('workstation_login_records', [ 'status' ], {
name: 'idx_wlr_status',
});
},
async down(queryInterface) {
await queryInterface.dropTable('workstation_login_records');
},
};