diff --git a/data/tsp_assistant.db b/data/tsp_assistant.db index 22f3ac3..03e4e57 100644 Binary files a/data/tsp_assistant.db and b/data/tsp_assistant.db differ diff --git a/src/core/database.py b/src/core/database.py index 42273ce..0fc56ad 100644 --- a/src/core/database.py +++ b/src/core/database.py @@ -63,10 +63,8 @@ class DatabaseManager: autoflush=False, bind=self.engine ) - # 创建所有表 Base.metadata.create_all(bind=self.engine) - logger.info("数据库初始化成功") # 运行 schema 迁移(处理字段变更) self._run_migrations() @@ -169,7 +167,6 @@ class DatabaseManager: if self.engine: self.engine.dispose() self._initialize_database() - logger.info("数据库重新连接成功") return True except Exception as e: logger.error(f"数据库重新连接失败: {e}") diff --git a/src/core/session_store.py b/src/core/session_store.py index 4cd59db..7860ca8 100644 --- a/src/core/session_store.py +++ b/src/core/session_store.py @@ -191,7 +191,6 @@ def create_session_store() -> SessionStore: socket_timeout=2 ) client.ping() - logger.info("会话存储使用 Redis") return RedisSessionStore(client) except Exception as e: logger.info(f"Redis 不可用({e}),会话存储使用内存") diff --git a/src/dialogue/message_pipeline.py b/src/dialogue/message_pipeline.py index 994f92f..56e50c6 100644 --- a/src/dialogue/message_pipeline.py +++ b/src/dialogue/message_pipeline.py @@ -73,9 +73,20 @@ class MessagePipeline: 完整的消息处理流程(一步到位)。 各入口可以直接调用此方法,不需要自己管理会话。 """ + import time as _time + t0 = _time.time() + resolved_tenant = self.resolve_tenant(chat_id=chat_id, tenant_id=tenant_id) + t1 = _time.time() + session_id = self.get_or_create_session(user_id, resolved_tenant, work_order_id) + t2 = _time.time() + result = self.process(session_id, message, ip_address, invocation_method) + t3 = _time.time() + + logger.info(f"Pipeline 耗时: 租户解析={t1-t0:.2f}s, 会话管理={t2-t1:.2f}s, 消息处理={t3-t2:.2f}s, 总计={t3-t0:.2f}s") + result['tenant_id'] = resolved_tenant result['session_id'] = session_id return result diff --git a/src/integrations/feishu_longconn_service.py b/src/integrations/feishu_longconn_service.py index efb6456..29fe981 100644 --- a/src/integrations/feishu_longconn_service.py +++ b/src/integrations/feishu_longconn_service.py @@ -165,14 +165,19 @@ class FeishuLongConnService: # 使用 Pipeline 统一处理消息 session_user_id = f"feishu_{chat_id}_{sender_id}" - pipeline = service_manager.get_pipeline() - response_data = pipeline.handle_message( - user_id=session_user_id, - message=text_content, - chat_id=chat_id, - ip_address=f"feishu:{sender_id}:{sender_name}", - invocation_method=f"feishu_longconn({chat_type})" - ) + try: + pipeline = service_manager.get_pipeline() + logger.info(f"Pipeline 开始处理: user={session_user_id}, chat_id={chat_id}") + response_data = pipeline.handle_message( + user_id=session_user_id, + message=text_content, + chat_id=chat_id, + ip_address=f"feishu:{sender_id}:{sender_name}", + invocation_method=f"feishu_longconn({chat_type})" + ) + except Exception as pipe_err: + logger.error(f"Pipeline 处理异常: {pipe_err}", exc_info=True) + response_data = {"success": False, "error": str(pipe_err)} tenant_id = response_data.get('tenant_id', 'default') logger.info(f"处理结果: success={response_data.get('success')}, 租户={tenant_id}") diff --git a/src/web/blueprints/feishu_bot.py b/src/web/blueprints/feishu_bot.py index 9767251..51a5855 100644 --- a/src/web/blueprints/feishu_bot.py +++ b/src/web/blueprints/feishu_bot.py @@ -119,15 +119,20 @@ def _process_message_in_background(app, event_data: dict): logger.info(f"[Feishu Bot] 发送者={sender_name}({sender_id}), 群={chat_id}, 租户={tenant_id}") # 4. 使用 Pipeline 统一处理消息 - pipeline = service_manager.get_pipeline() - response_data = pipeline.handle_message( - user_id=user_id, - message=text_content, - tenant_id=tenant_id, - chat_id=chat_id, - ip_address=f"feishu:{sender_id}:{sender_name}", - invocation_method=f"feishu_bot({chat_type})" - ) + try: + pipeline = service_manager.get_pipeline() + logger.info(f"[Feishu Bot] Pipeline 开始处理: user={user_id}") + response_data = pipeline.handle_message( + user_id=user_id, + message=text_content, + tenant_id=tenant_id, + chat_id=chat_id, + ip_address=f"feishu:{sender_id}:{sender_name}", + invocation_method=f"feishu_bot({chat_type})" + ) + except Exception as pipe_err: + logger.error(f"[Feishu Bot] Pipeline 处理异常: {pipe_err}", exc_info=True) + response_data = {"success": False, "error": str(pipe_err)} logger.info(f"[Feishu Bot] 处理结果: success={response_data.get('success')}") # 5. 提取回复并发送 diff --git a/start_dashboard.py b/start_dashboard.py index f373430..d9ab30c 100644 --- a/start_dashboard.py +++ b/start_dashboard.py @@ -48,9 +48,6 @@ def start_feishu_longconn_service(): try: import logging logger = logging.getLogger("feishu_longconn") - logger.info("=" * 80) - logger.info("🚀 启动飞书长连接服务(后台线程)") - logger.info("=" * 80) from src.integrations.feishu_longconn_service import get_feishu_longconn_service service = get_feishu_longconn_service() @@ -76,9 +73,6 @@ def check_database_connection(): def main(): """主函数""" - print("=" * 60) - print("TSP智能助手 - 综合管理平台") - print("=" * 60) start_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") print(f"启动时间: {start_time}") print() @@ -91,9 +85,6 @@ def main(): # 检查必要目录 os.makedirs("logs", exist_ok=True) os.makedirs("data", exist_ok=True) - - logger.info("正在启动TSP智能助手综合管理平台...") - # 检查数据库连接 if not check_database_connection(): logger.error("数据库连接失败,退出启动")