WMS_MAIN/app/model/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

64 lines
1.6 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';
/**
* 站内信屏蔽表 Model。
* 按群ID+用户ID维度屏蔽,后续来自该群+用户的消息不再触发 AI 回信。
* group_id 和 user_id 均为 NULL 时表示全局屏蔽(预留)。
*
* @param {Object} app Egg.js Application 实例。
* @return {Object} Sequelize Model 定义。
*/
module.exports = app => {
const { BIGINT, STRING, INTEGER, TINYINT, DATE } = app.Sequelize;
const InboxBlock = app.model.define('inbox_block', {
id: {
type: BIGINT.UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键',
},
warehouse_id: {
type: INTEGER(10),
allowNull: false,
comment: '仓库ID',
},
group_id: {
type: STRING(100),
allowNull: true,
comment: '群ID',
},
user_id: {
type: STRING(100),
allowNull: true,
comment: '用户ID',
},
is_robot: {
type: TINYINT(1),
allowNull: false,
defaultValue: 0,
comment: '是否机器人账号:机器人屏蔽在仓库群同样生效(仓库群默认忽略仅用户级屏蔽)',
},
created_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
}, {
tableName: 'wms_inbox_block',
timestamps: false,
comment: '站内信屏蔽表',
indexes: [
{
name: 'uk_warehouse_group_user',
unique: true,
fields: [ 'warehouse_id', 'group_id', 'user_id' ],
},
],
});
return InboxBlock;
};