WMS_MAIN/app/model/inbox_message.js
liufumingren c2a761ca26 feat(inbox): 新增开门/到货/进场/离场车牌登记与 extend_props 持久化
- functions 新增 openDoor/registerLicensePlate/enter/departure(规则表+权限分组)
- 到货登记表 wms_inbox_arrival_register(含消费字段,离场闭环,货主收货群优先推送)
- 回执 extend_props 持久化落库与定时补发送下发(重推兜底回读)
- 车牌提取正则兼容异体字(粤/粵)
- 售后类型/关键字/函数/回复 v2 模型与迁移
- INBOX V2 HTTP 测试报告与指南
2026-09-17 02:41:43 +08:00

197 lines
5.2 KiB
JavaScript
Raw Permalink 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。
* 统一管理消息推送状态追踪:谁发来的、要推到哪、推送状态。
* inbound(外部→WMS)与 outbound(WMS→外部)共表,direction + parent_id 形成对话链。
* @param {Object} app Egg.js Application 实例。
* @return {Object} Sequelize Model 定义。
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DATE, INTEGER, JSON: JSON_TYPE } = app.Sequelize;
const InboxMessage = app.model.define('inbox_message', {
id: {
type: BIGINT.UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键ID',
},
ext_id: {
type: STRING(128),
allowNull: false,
comment: '外部唯一消息主键(IM msgId / API requestId 等),用于幂等去重',
},
warehouse_id: {
type: BIGINT.UNSIGNED,
allowNull: false,
comment: '所属仓库ID',
},
store_id: {
type: BIGINT.UNSIGNED,
allowNull: true,
comment: '关联货主ID',
},
direction: {
type: STRING(10),
allowNull: false,
defaultValue: 'inbound',
validate: {
isIn: {
args: [[ 'inbound', 'outbound' ]],
msg: 'direction 必须是 inbound 或 outbound',
},
},
comment: '消息方向:inbound=外部→WMS收件 / outbound=WMS→外部回信',
},
parent_id: {
type: BIGINT.UNSIGNED,
allowNull: true,
comment: '关联消息ID(回信时指向原消息,形成对话链)',
},
source_type: {
type: STRING(20),
allowNull: false,
validate: {
isIn: {
args: [[ 'im', 'api', 'system' ]],
msg: 'source_type 必须是 im、api 或 system',
},
},
comment: '来源类型:im / api / system',
},
source_extra: {
type: STRING(100),
allowNull: true,
comment: '来源附加信息(IM 平台 / API app_id)',
},
target_type: {
type: STRING(20),
allowNull: false,
validate: {
isIn: {
args: [[ 'im', 'api', 'webhook' ]],
msg: 'target_type 必须是 im、api 或 webhook',
},
},
comment: '目标类型:im / api / webhook',
},
group_name: {
type: STRING(100),
allowNull: true,
comment: '群名称(外部传入)',
},
user_name: {
type: STRING(100),
allowNull: true,
comment: '用户名称(外部传入)',
},
group_id: {
type: STRING(100),
allowNull: true,
comment: '外部群ID',
},
user_id: {
type: STRING(100),
allowNull: true,
comment: '外部用户ID',
},
content: {
type: app.Sequelize.TEXT,
allowNull: true,
comment: '消息正文/摘要,用于列表展示和关键词搜索',
},
ext_data: {
type: JSON_TYPE,
allowNull: true,
comment: '外部透传数据,外部传入任意JSON,WMS不解析,回信时原样返回',
},
extend_props: {
type: JSON_TYPE,
allowNull: true,
comment: '回执扩展属性(notify.reply 的 extend_props),重推时原样带回',
},
flags: {
type: JSON_TYPE,
allowNull: true,
comment: '处理标记,外部传入控制WMS处理行为',
},
ai_thoughts: {
type: JSON_TYPE,
allowNull: true,
comment: 'AI 多轮推理思考过程 [{round,action,function,params,reason,functionResult}]',
},
push_status: {
type: TINYINT(4),
allowNull: false,
defaultValue: 0,
validate: {
isIn: {
args: [[ 0, 1, 2, 3 ]],
msg: 'push_status 必须是 0(待推送)、1(推送中)、2(已送达)、3(失败)',
},
},
comment: '推送状态:0=待推送 1=推送中 2=已送达 3=失败',
},
push_started_at: {
type: DATE,
allowNull: true,
comment: '开始推送时间(僵尸检测:超5分钟仍为1则重置为0)',
},
retry_count: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '已重试次数',
},
push_response: {
type: JSON_TYPE,
allowNull: true,
comment: '目标响应(http_status, body, error)',
},
pushed_at: {
type: DATE,
allowNull: true,
comment: '推送完成时间',
},
work_order_id: {
type: BIGINT.UNSIGNED,
allowNull: true,
comment: '关联工单ID(预留)',
},
work_order_no: {
type: STRING(50),
allowNull: true,
comment: '工单号(预留)',
},
created_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
updated_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '更新时间',
},
deleted_at: {
type: DATE,
allowNull: true,
comment: '软删除时间',
},
}, {
tableName: 'wms_inbox_message',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
deletedAt: 'deleted_at',
paranoid: true,
comment: '站内信消息推送状态追踪表',
});
return InboxMessage;
};