WMS_MAIN/database/migrations/20260916170000-seed-inbox-number-rules.js
liufumingren c2a761ca26 feat(inbox): 新增开门/到货/进场/离场车牌登记与 extend_props 持久化
- functions 新增 openDoor/registerLicensePlate/enter/departure(规则表+权限分组)
- 到货登记表 wms_inbox_arrival_register(含消费字段,离场闭环,货主收货群优先推送)
- 回执 extend_props 持久化落库与定时补发送下发(重推兜底回读)
- 车牌提取正则兼容异体字(粤/粵)
- 售后类型/关键字/函数/回复 v2 模型与迁移
- INBOX V2 HTTP 测试报告与指南
2026-09-17 02:41:43 +08:00

80 lines
2.8 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';
/**
* 播种取号规则数据:把 app/service/inbox/rules.js 现有硬编码的提取方法
* (extractWaybills / extractOrders / EXPRESS_NAMES)落库为 wms_inbox_number_rule 规则。
*
* 幂等设计:基于唯一索引 uk_name 做 INSERT IGNORE,不会重复插入。
*
* 说明:现有提取逻辑中正则之外的部分(运单号过滤:手机号/座机/日期戳/售后单号;
* 订单号兜底取纯数字)仍由代码兜底处理,正则列只存核心匹配源串。
*/
const TABLE = 'wms_inbox_number_rule';
const SEED_RULES = [
{
name: '运单号提取',
target: 'waybill_no',
// 对应 extractWaybills 的核心匹配:[A-Za-z0-9_-]{10,24}(过滤逻辑由代码兜底)
regexp: '[A-Za-z0-9_-]{10,24}',
sort_order: 1,
},
{
name: '订单编号提取',
target: 'order_no',
// 对应 extractOrders 优先规则:SYS/SO/DD 前缀及字母数字混合号
regexp: '(?<![A-Za-z0-9])SYS\\d{4,}|(?<![A-Za-z0-9])SO[A-Za-z0-9-]{4,}|(?<![A-Za-z0-9])DD[A-Za-z0-9-]{4,}|(?<![A-Za-z0-9])[A-Z]{2,8}-?\\d{4,}',
sort_order: 2,
},
{
name: '平台订单号提取',
target: 'source_order_codes',
// 对应 extractOrders 兜底规则:12~20 位纯数字(多个合成,代码侧去重)
regexp: '(?<!\\d)\\d{12,20}(?!\\d)',
sort_order: 3,
},
{
name: '快递名称提取',
target: 'express_name',
// 对应 EXPRESS_NAMES 列表(长名在前,避免短名截断)
regexp: '中通快运|中通快递|极兔速递|京东快递|圆通快递|申通快递|顺丰速运|韵达快递|邮政小包|圆通|中通|申通|顺丰|韵达|极兔|邮政|EMS|京东|德邦',
sort_order: 4,
},
];
module.exports = {
up: async queryInterface => {
const tables = await queryInterface.showAllTables();
const exists = tables.some(t => (typeof t === 'string' ? t : t.tableName) === TABLE);
if (!exists) {
throw new Error(`表 ${TABLE} 不存在,请先执行 20260916160000-create-wms-inbox-number-rule-and-link-sub-type.js`);
}
const { sequelize } = queryInterface;
for (const rule of SEED_RULES) {
await sequelize.query(
'INSERT IGNORE INTO `' + TABLE + '` (name, target, `regexp`, sort_order, created_at, updated_at) '
+ 'VALUES (:name, :target, :regexp, :sortOrder, NOW(), NOW())',
{
replacements: {
name: rule.name,
target: rule.target,
regexp: rule.regexp,
sortOrder: rule.sort_order,
},
type: sequelize.QueryTypes.INSERT,
}
);
}
},
down: async queryInterface => {
const names = SEED_RULES.map(r => r.name);
await queryInterface.sequelize.query(
'DELETE FROM `' + TABLE + '` WHERE name IN (:names)',
{ replacements: { names } }
);
},
};