WMS_MAIN/database/migrations/20261119160000-add-is-robot-to-wms-inbox-block.js
liufumingren 06d0bc8ef8 feat(inbox): 屏蔽表新增 is_robot 标记,机器人屏蔽在仓库群同样生效
生产事故:机器人自身回信被桥接回灌为入站消息后仍走完整规则链路
(回复文案含录像任务号/条码/主机名,被 extractWaybills 当运单号),
形成自问自答死循环,单群 35 分钟内回信 508 条。

仓库群会忽略「仅用户级(无群ID)」的屏蔽记录,导致机器人屏蔽在内部群失效。
新增 is_robot 区分:is_robot=1 的记录不受该例外影响,仅带 user_id 时
按仓库维度全群生效;loadBlockedUserIds(真人接管判断)排除机器人记录。

同时修正屏蔽集合缓存:原先把 Set 直接写入 Redis,JSON 反序列化后恒不命中
(等于无缓存),改为纯对象+数组结构,缓存键升级为 inbox:block:v2:{id},
失效时兼容清理旧键。

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-19 18:09:10 +08:00

35 lines
1.2 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';
const TABLE_NAME = 'wms_inbox_block';
/**
* 屏蔽表新增「是否机器人账号」标记。
*
* 背景:仓库群(internal group)会忽略「仅用户级(无群ID)」的屏蔽记录,避免外部群的
* 用户级屏蔽连带跳过内部群消息;但机器人自身回信被桥接回灌成入站消息时会形成自问自答
* 死循环(生产实测单群 500+ 条/小时),这类屏蔽必须不受仓库群例外影响。
*
* 故新增 is_robot:is_robot=1 的记录在任意群(含仓库群)都生效,
* 且仅带 user_id 时按仓库维度全局生效。
*/
module.exports = {
up: async (queryInterface, Sequelize) => {
const cols = await queryInterface.describeTable(TABLE_NAME);
if (cols.is_robot) return;
await queryInterface.addColumn(TABLE_NAME, 'is_robot', {
type: Sequelize.TINYINT(1),
allowNull: false,
defaultValue: 0,
comment: '是否机器人账号:机器人屏蔽在仓库群同样生效(仓库群默认忽略仅用户级屏蔽)',
});
},
down: async queryInterface => {
const cols = await queryInterface.describeTable(TABLE_NAME);
if (!cols.is_robot) return;
await queryInterface.removeColumn(TABLE_NAME, 'is_robot');
},
};