WMS_MAIN/database/migrations/20261014110000-backfill-system-wechat-agreement.js
liufumingren e9e39eafa7 chore: 提交工作区其余未提交改动(微信协议版本 / 扫描报文接口 / container 模型 / 退件 like 数组)
- 微信开放平台:首次授权时写入系统默认用户须知作为首个协议版本
  (ctx.service.systems.wechat.ensureDefaultAgreementVersion),含 seed / backfill 两个迁移
- 新增扫描报文接收接口 POST /scan:把「时间 + 条码」追加写入项目根目录 scan_records.xlsx
  (串行队列 + 原子写,避免并发写坏文件)
- 新增 wms_container(容器/笼筐)模型与建表迁移
- 退件收货单 / 退件运单列表:like 查询条件支持字符串数组(多关键词 OR)
- 新增 wms_return_unpack.created_at 索引迁移
- package.json:deploy 脚本改名为 depeeloy

注:scan_records.xlsx 是 /scan 接口写入的运行时数据文件,未纳入本次提交。
2026-10-16 05:29:13 +08:00

50 lines
1.7 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';
/**
* 回填系统默认用户须知(2026-10-14):
* - 对 wms_wechat_app 中尚不存在任何用户须知版本的小程序,复制系统默认须知
* (wms_wechat_agreement_version 中 appid='system' 最新一条)作为第一版;
* - 幂等:已有任意版本的小程序跳过;无系统默认行则跳过(依赖种子迁移 20261014100000)。
*/
const TABLE_NAME = 'wms_wechat_agreement_version';
const SYSTEM_APPID = 'system';
module.exports = {
async up(queryInterface) {
const { QueryTypes } = queryInterface.sequelize;
const systemRows = await queryInterface.sequelize.query(
`SELECT content FROM ${TABLE_NAME} WHERE appid = ? ORDER BY id DESC LIMIT 1`,
{ replacements: [ SYSTEM_APPID ], type: QueryTypes.SELECT }
);
const systemContent = systemRows && systemRows.length > 0 ? systemRows[0].content : null;
if (!systemContent) {
console.log('[backfill] 缺少系统默认须知(appid=system),跳过回填');
return;
}
const appids = await queryInterface.sequelize.query(
`SELECT a.appid FROM wms_wechat_app a
WHERE NOT EXISTS (
SELECT 1 FROM ${TABLE_NAME} v WHERE v.appid = a.appid
)
ORDER BY a.id ASC`,
{ type: QueryTypes.SELECT }
);
for (const row of appids) {
await queryInterface.sequelize.query(
`INSERT INTO ${TABLE_NAME} (appid, content, created_at, updated_at) VALUES (?, ?, NOW(), NOW())`,
{ replacements: [ row.appid, systemContent ] }
);
}
console.log(`[backfill] 回填系统默认须知 appid 数量: ${appids.length}`);
},
async down() {
// 回填行与人工版本无法可靠区分,不做逆向删除
},
};