packServer/backend/database/migrations/20261018240000-add-scan-record-workstation-snapshot.js
liufumingren 228723e0c3 设备端扫码上报 + 桌面端/Android 正式包发布脚手架
AndroidStation(原中控改造为纯设备端)
- 只做三件事:UDP 48899 被桌面端发现、TCP 8087 推送 USB 扫码结果、离线语音播报
- 扫码不再经过 UI:去掉逐键重绘,50ms 自动提交,同一码重复扫码也一律上报
- 离线语音种子(数字/字母/“开始打包”/欢迎语)随包安装,MediaPlayer 播放,启动把音量拉满
- 启动播报「欢迎使用溯源系统,初始化已经完成,扫码即可开始打包」
- 移除 Device Owner / 设备管理员 / lock task / 网络与 IP 设置等非普通应用能力(仅保留开机自启)
- 正式签名 keystore + release 签名配置,versionName/versionCode 可由打包脚本覆盖

发布脚手架
- backend/android_client:Android 正式包构建(build.ps1 + package.config.json)
- backend/scripts/deploy/publish-android.cjs + npm run android:build / android:publish
- 桌面端安装包改为 download/desktop,Android 为 download/android_client;
  version.json 仍走 /download/version.json(老客户端写死),新增 /download/android_client/version.json
- 谷歌插件随桌面端 MSI 安装到 <安装目录>\extension,工具菜单新增「复制谷歌插件地址」
- git-safety-check 增加仓库级禁区(keystore.properties / *.jks / local.properties)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-21 05:53:27 +08:00

86 lines
3.3 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';
/**
* 扫码记录:带上「当时的工作台快照」+ 运单查询要用的索引
*
* 为什么要快照:录像回放要按**当时的**工作台配置(哪台录像机、哪些摄像头、怎么布局、
* 录制范围多少秒)去拉流。工作台后来被改/被删了,历史运单照样要能查回来,
* 所以扫码入库时就把配置冻一份 JSON 存这里。
*
* - `workstation_id`:便于按工作台统计/过滤(快照里也有,这个列只是方便 JOIN)
* - `workstation_snapshot`:JSON,结构见 `app/service/pack.js` 的 `buildSnapshot()`
*
* 索引:
* - `(subject_id, barcode)`:按运单号查(主体内精确匹配)
* - `(scanner_id, channel_id, scan_time)`:散单要取同通道的「上一条/下一条」扫码时间
*
* 注意:`sql/schema.sql` 基线已经包含这些列和索引,空库执行时必须幂等。
*/
async function hasColumn(queryInterface, table, column) {
try {
const description = await queryInterface.describeTable(table);
return Boolean(description[column]);
} catch (error) {
return false;
}
}
async function hasIndex(queryInterface, table, name) {
try {
const indexes = await queryInterface.showIndex(table);
return indexes.some(item => item.name === name);
} catch (error) {
return false;
}
}
module.exports = {
async up(queryInterface, Sequelize) {
const { BIGINT, JSON: JSONType } = Sequelize;
if (!await hasColumn(queryInterface, 'scan_records', 'workstation_id')) {
await queryInterface.addColumn('scan_records', 'workstation_id', {
type: BIGINT.UNSIGNED,
allowNull: true,
comment: '当时绑定的工作台 workstations.id(快照里有完整信息)',
});
}
if (!await hasColumn(queryInterface, 'scan_records', 'workstation_snapshot')) {
await queryInterface.addColumn('scan_records', 'workstation_snapshot', {
type: JSONType,
allowNull: true,
comment: '工作台快照(录像机/摄像头/布局/录制范围),回放按它拉流',
});
}
if (!await hasIndex(queryInterface, 'scan_records', 'idx_scan_subject_barcode')) {
await queryInterface.addIndex('scan_records', [ 'subject_id', 'barcode' ], {
name: 'idx_scan_subject_barcode',
});
}
if (!await hasIndex(queryInterface, 'scan_records', 'idx_scan_channel_seq')) {
await queryInterface.addIndex('scan_records', [ 'scanner_id', 'channel_id', 'scan_time' ], {
name: 'idx_scan_channel_seq',
});
}
// 中控上报时按 (scanner_id, channel_id) 找工作台,没索引会全表扫
if (!await hasIndex(queryInterface, 'workstation_scan_channels', 'idx_wsc_scanner_channel')) {
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');
},
};