'use strict'; /** * help(指令)子类型群白名单改为通配:所有群都支持(幂等)。 * * 原播种为 store.after_sales / warehouse.customer_service / express.after_sales 三条精确白名单, * 其他群子类型(如 store.receiving)无法触发指令。改为 group_type='*' 通配行, * 引擎 _groupAllowed 对 '*' 直接放行;help 函数 groups=[COMMON] 本身所有群可用。 */ const SUB_TYPE_TABLE = 'wms_after_sale_sub_type'; const REL_GROUP_TABLE = 'wms_after_sale_sub_type_group'; 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(SUB_TYPE_TABLE) || !exists(REL_GROUP_TABLE)) return; const q1 = async (sql, replacements) => { const [ rows ] = await sequelize.query(sql, { replacements }); return rows && rows.length > 0 ? rows[0] : null; }; const sub = await q1( 'SELECT id FROM `' + SUB_TYPE_TABLE + '` WHERE type = :t AND sub_type = :s AND warehouse_id IS NULL LIMIT 1', { t: 'help', s: 'instruction' } ); if (!sub) return; const sid = sub.id; const wildcard = await q1( 'SELECT id FROM `' + REL_GROUP_TABLE + '` WHERE sub_type_id = :s AND group_type = :g LIMIT 1', { s: sid, g: '*' } ); if (wildcard) { console.log('[help-whitelist-all-groups] 已存在通配白名单,跳过'); return; } const [ del ] = await sequelize.query( 'DELETE FROM `' + REL_GROUP_TABLE + '` WHERE sub_type_id = :s', { replacements: { s: sid } } ); await sequelize.query( 'INSERT INTO `' + REL_GROUP_TABLE + '` (sub_type_id, group_type, sub_group, is_system, sort_order, created_at, updated_at) VALUES (:s, :g, :sg, 1, 0, NOW(), NOW())', { replacements: { s: sid, g: '*', sg: '' } } ); console.log(`[help-whitelist-all-groups] deleted=${del.affectedRows || 0} inserted-wildcard=1`); }, down: async () => { // 不回退(语义修正) }, };