From 413b554f689934cb8a28e364a88b570dddabab8d Mon Sep 17 00:00:00 2001 From: Lei OT Date: Fri, 14 Feb 2025 09:30:32 +0800 Subject: [PATCH] =?UTF-8?q?perf(WAI):=20=E4=B8=8D=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=86=99=E5=85=A5session=20id;=20=E9=83=A8=E5=88=86=E5=AD=97?= =?UTF-8?q?=E6=AE=B5getter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wai-server/core/handler/whatsappHandler.js | 6 +++--- wai-server/models/outbound_messages.js | 16 ++++++++++++++++ wai-server/services/connections.service.js | 6 +++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/wai-server/core/handler/whatsappHandler.js b/wai-server/core/handler/whatsappHandler.js index ed7b143..9ea1b62 100644 --- a/wai-server/core/handler/whatsappHandler.js +++ b/wai-server/core/handler/whatsappHandler.js @@ -116,7 +116,7 @@ const setupConnectionHandler = () => { getUserLogger(connectionData.phone).info({ msg: `连接https://web.whatsapp.com/`, connectionData }); // find Or create await addCurrentConnection({ - ...objectMapper(connectionData, { phone: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id', createTimestamp: 'createtime', version: 'version' }, false), + ...objectMapper(connectionData, { phone: [{ key: 'wa_id' }], channelId: 'channel_id', createTimestamp: 'createtime', version: 'version' }, false), service_type: 'baileys', status: 'connecting', }); @@ -130,7 +130,7 @@ const setupConnectionHandler = () => { getUserLogger(connectionData.whatsAppNo).info({ msg: `已登录`, connectionData }); await updateConnection( { - ...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id' }), + ...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }], channelId: 'channel_id' }), service_type: 'baileys', closetime: null, }, @@ -148,7 +148,7 @@ const setupConnectionHandler = () => { sessionStore.removeSession(connectionData.channelId); await updateConnection( { - ...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id' }), + ...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }], channelId: 'channel_id' }), service_type: 'baileys', }, { connect_domain: domain, connect_name: domainName }, diff --git a/wai-server/models/outbound_messages.js b/wai-server/models/outbound_messages.js index 812b6d9..2d4ec19 100644 --- a/wai-server/models/outbound_messages.js +++ b/wai-server/models/outbound_messages.js @@ -20,6 +20,10 @@ module.exports = function(sequelize, DataTypes) { actionId: { type: DataTypes.STRING(100), allowNull: true, + get() { + const rawValue = this.getDataValue('actionId'); + return rawValue === null ? '' : rawValue; + }, }, opi_sn: { type: DataTypes.INTEGER, @@ -71,6 +75,10 @@ module.exports = function(sequelize, DataTypes) { type: DataTypes.STRING(50), allowNull: true, comment: '消息状态 read、send等', + get() { + const rawValue = this.getDataValue('msg_status'); + return rawValue === null ? '' : rawValue; + }, }, errors_code: { type: DataTypes.STRING(50), @@ -132,6 +140,10 @@ module.exports = function(sequelize, DataTypes) { IVADS_caption: { type: DataTypes.STRING(1024), allowNull: true, + get() { + const rawValue = this.getDataValue('IVADS_caption'); + return rawValue === null ? '' : rawValue; + }, }, IVADS_id: { type: DataTypes.STRING(100), @@ -148,6 +160,10 @@ module.exports = function(sequelize, DataTypes) { IVADS_filename: { type: DataTypes.TEXT, allowNull: true, + get() { + const rawValue = this.getDataValue('IVADS_filename'); + return rawValue === null ? '' : rawValue; + }, }, location_latitude: { type: DataTypes.STRING(50), diff --git a/wai-server/services/connections.service.js b/wai-server/services/connections.service.js index 98ff92b..b6238cc 100644 --- a/wai-server/services/connections.service.js +++ b/wai-server/services/connections.service.js @@ -19,7 +19,7 @@ const addConnection = async data => { */ const addCurrentConnection = async data => { const [r, createdId] = await ConnectionsModel.findOrCreate({ - where: { connect_domain: domain, connect_name: name, sesson_id: data.sesson_id }, + where: { connect_domain: domain, connect_name: name, wa_id: data.wa_id }, defaults: { ...data, connect_domain: domain, connect_name: name, closetime: null }, }); return r; @@ -30,10 +30,10 @@ const updateConnection = async (data, where = {}) => { { ...data, ...(data.status === 'open' ? { opentime: Sequelize.fn('NOW') } : {}), - ...(data.status === 'close' ? { closetime: Sequelize.fn('NOW') } : {}), + ...(['close', 'offline'].includes(data.status) ? { closetime: Sequelize.fn('NOW') } : {}), updatetime: Sequelize.fn('NOW'), }, - { where: { ...where, sesson_id: data.sesson_id } }, + { where: { ...where, wa_id: data.wa_id } }, ); return r; };