WMS_MAIN/database/migrations/20260918120000-seed-system-no-number-hint.js
liufumingren 806e739267 feat(inbox): v2 规则引擎完善(help 指令/建单开关/系统回复)并修复拦截日志误写仓库 ID
- functions.js: 拦截/取消拦截波次感知写订单日志 businessId 误用仓库 ID,改为订单 ID
  (生产订单 JY2026091813795 已发起拦截但订单详情查不到拦截日志的根因)
- rules/v2/processor/config/functionSync: 新增 help 指令、create_work_order=0 时跳过
  工单登记、系统级回复与无单号提示、白名单范围修正
- after_sale_reply 模型 + 6 个迁移: create_work_order 字段与相关配置种子
- return_unpack: 列表 count 统计修复、分页排序追加主键防重漏行、视频附加 camera_name
- methods/system.json + changes + sync 脚本: 接口文档与权限同步
2026-09-18 22:38:57 +08:00

60 lines
2.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';
/**
* 补齐系统级回复配置的「取号失败引导语」基础配置(幂等,只填空值行)。
*
* 现状:系统级回复行 no_number_hint 全部为 NULL,取号失败时依赖代码内置默认值。
* 本次把基础引导语写入系统级配置:
* - 子类型关联了 target='express_name' 取号规则(如 change_carrier 改快递)→ 快递指定提示;
* - 其余子类型 → 默认运单号提示。
* 仓库级行不处理(留空时仍走代码兜底)。
*/
const REPLY_TABLE = 'wms_after_sale_reply';
const REL_TABLE = 'wms_after_sale_sub_type_rule';
const RULE_TABLE = 'wms_inbox_number_rule';
const HINT_EXPRESS = '请指定目标快递(圆通/中通/申通/顺丰/韵达/极兔/邮政/EMS/京东/德邦)';
const HINT_DEFAULT = '请提供运单号(发送:指令+运单号,多个单号用逗号或空格分隔)';
module.exports = {
up: async queryInterface => {
const { sequelize } = queryInterface;
const tables = await queryInterface.showAllTables();
const exists = t => tables.some(x => (typeof x === 'string' ? x : x.tableName) === t);
if (!exists(REPLY_TABLE)) return;
// 关联 express_name 取号规则的子类型集合
let expressIds = new Set();
if (exists(REL_TABLE) && exists(RULE_TABLE)) {
const [ relRows ] = await sequelize.query(
'SELECT DISTINCT rel.sub_type_id FROM `' + REL_TABLE + '` rel ' +
'JOIN `' + RULE_TABLE + '` r ON r.id = rel.number_rule_id WHERE r.target = :t',
{ replacements: { t: 'express_name' } }
);
expressIds = new Set(relRows.map(r => Number(r.sub_type_id)));
}
const [ rows ] = await sequelize.query(
'SELECT id, sub_type_id FROM `' + REPLY_TABLE + '` ' +
'WHERE warehouse_id IS NULL AND (no_number_hint IS NULL OR no_number_hint = :empty)',
{ replacements: { empty: '' } }
);
let updated = 0;
for (const row of rows) {
const hint = expressIds.has(Number(row.sub_type_id)) ? HINT_EXPRESS : HINT_DEFAULT;
await sequelize.query(
'UPDATE `' + REPLY_TABLE + '` SET no_number_hint = :hint WHERE id = :id',
{ replacements: { hint, id: row.id } }
);
updated += 1;
}
console.log(`[seed-system-no-number-hint] updated=${updated}`);
},
down: async () => {
// 不回退(系统预设种子)
},
};