'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 () => { // 不回退(系统预设种子) }, };