packServer/backend/app/model/scan_channel.js
liufumingren bd2363bf00 chore: 初始化仓库(backend / frontend / extension 三块)
- 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 密码,绝不入库)。
2026-10-17 08:50:32 +08:00

35 lines
1.6 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';
/**
* 扫描中控通道表模型(scan_channels)
*
* 一台「中控(绑定端)」可以接多个扫码设备,每个扫码设备对应一个通道;
* 中控通过 POST /api/scan/channels 把通道(channel_id + channel_name)上报到服务,
* 一个通道一行,唯一键 (scanner_id, channel_id):中控再次上报同名通道就是更新。
*
* 注意:channel_id 只在同一中控内唯一,所以关联时要用 (scanner_id, channel_id) 两个字段。
*/
module.exports = (app) => {
const { BIGINT, STRING, TINYINT, DATE } = app.Sequelize;
const ScanChannel = app.model.define('scanChannel', {
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(中控上报,同一中控内唯一)' },
channelName: { type: STRING(128), allowNull: false, defaultValue: '', comment: '通道名(中控上报)' },
lastReportAt: { type: DATE, comment: '最近一次上报时间' },
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1正常 0停用' },
remark: { type: STRING(255), comment: '备注' },
}, {
tableName: 'scan_channels',
paranoid: true,
comment: '扫描中控通道表',
});
ScanChannel.associate = function() {
app.model.ScanChannel.belongsTo(app.model.Scanner, { foreignKey: 'scanner_id', as: 'scanner' });
};
return ScanChannel;
};