- backend/:Egg 3 纯 JSON 接口服务(MySQL 8 + Redis),全部走 header 令牌鉴权; 已彻底去掉服务端渲染(删除 page 控制器 / app/view / nunjucks / session / CSRF), 开发时把页面请求反代到前端 dev server,生产托管 frontend/dist(SPA 回退)。 单测 91 个通过(不需要本机数据库)。 - frontend/:Vite + Vue3 + TypeScript 的 SPA(登录 / 注册 / 找回密码 / 扫码登录与确认 / 首页统计 / 设备管理 / 扫码记录 / 个人中心 / 测试页),vue-tsc 类型检查与构建通过。 - extension/:MV3 浏览器扩展(零构建),注入第三方 WMS 页面识别运单号并打开溯源页。 - 忽略规则统一放根 .gitignore:node_modules、dist、logs / logs-*、run、typings、 .env*、config.local.js(含本机数据库与 Redis 密码,绝不入库)。
35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 扫码记录表模型(scan_records)
|
||
*
|
||
* 中控通过 POST /api/scan/records 上报扫码流水:条码 + 扫描时间 + 通道 id。
|
||
* 去重靠唯一键 (scanner_id, channel_id, barcode, scan_time):完全相同的上报只入库一次。
|
||
*
|
||
* 本表是流水表,**不用软删除**(paranoid 关闭):
|
||
* 软删除会让记录占用唯一键,导致同一条扫码数据再也无法入库;
|
||
* 需要清理请按时间物理删除。
|
||
*/
|
||
module.exports = (app) => {
|
||
const { BIGINT, STRING, DATE } = app.Sequelize;
|
||
|
||
const ScanRecord = app.model.define('scanRecord', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
scannerId: { type: BIGINT.UNSIGNED, allowNull: false, comment: '上报的中控(= scanners.id)' },
|
||
channelId: { type: STRING(64), allowNull: false, comment: '通道 id' },
|
||
barcode: { type: STRING(255), allowNull: false, comment: '条码内容' },
|
||
scanTime: { type: DATE, allowNull: false, comment: '扫描时间(中控上报,秒级)' },
|
||
reportedAt: { type: DATE, allowNull: false, defaultValue: app.Sequelize.NOW, comment: '服务端接收时间' },
|
||
}, {
|
||
tableName: 'scan_records',
|
||
paranoid: false,
|
||
comment: '扫码记录表(去重)',
|
||
});
|
||
|
||
ScanRecord.associate = function() {
|
||
app.model.ScanRecord.belongsTo(app.model.Scanner, { foreignKey: 'scanner_id', as: 'scanner' });
|
||
};
|
||
|
||
return ScanRecord;
|
||
};
|