This commit is contained in:
张成
2026-02-28 16:28:28 +08:00
parent 96da90daa8
commit 5ec4e7f440
9 changed files with 242 additions and 127 deletions

62
api/model/chat_message.js Normal file
View File

@@ -0,0 +1,62 @@
const Sequelize = require('sequelize');
/**
* 聊天消息表
* 每句话一条记录;会话形态(仅 data+job用 mid=0 存一条
*/
module.exports = (db) => {
const chat_message = db.define('chat_message', {
sn_code: {
comment: '设备SN码',
type: Sequelize.STRING(50),
allowNull: false,
defaultValue: ''
},
platform: {
comment: '平台: boss / liepin',
type: Sequelize.STRING(20),
allowNull: false,
defaultValue: 'boss'
},
friendId: {
comment: '好友/会话ID',
type: Sequelize.BIGINT,
allowNull: false
},
encryptFriendId: {
comment: '好友加密ID',
type: Sequelize.STRING(100),
allowNull: true,
defaultValue: ''
},
mid: {
comment: '消息ID接口返回',
type: Sequelize.BIGINT,
allowNull: false
},
message_data: {
comment: '单条消息原始数据 JSON',
type: Sequelize.JSON,
allowNull: true,
defaultValue: null
},
fetch_time: {
comment: '拉取时间',
type: Sequelize.DATE,
allowNull: true,
defaultValue: Sequelize.NOW
}
}, {
timestamps: false,
indexes: [
{ unique: true, fields: ['sn_code', 'platform', 'friendId', 'mid'] },
{ unique: false, fields: ['sn_code', 'platform', 'friendId'] },
{ unique: false, fields: ['fetch_time'] }
]
});
// chat_message.sync({ force: true });
return chat_message;
};