From 8f2292b6f3050a5840f5456375a2f93ac7f46504 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 8 May 2026 11:41:55 +0800 Subject: [PATCH] fix: DBPools() not in __init__, sqlorContext uses module name not default --- customer_management/core.py | 16 ++++++++-------- json/customers_list.json | 13 +++++++++---- json/handover_list.json | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/customer_management/core.py b/customer_management/core.py index 92a6abe..daa16f9 100644 --- a/customer_management/core.py +++ b/customer_management/core.py @@ -22,7 +22,7 @@ async def create_customer( ) -> Dict: """创建客户档案""" db = DBPools() - async with db.sqlorContext('default') as sor: + async with db.sqlorContext('customer_management') as sor: customer_id = str(uuid.uuid4()).replace('-', '') # 数据校验 @@ -74,7 +74,7 @@ async def initiate_handover( ) -> Dict: """发起客户交接流程""" db = DBPools() - async with db.sqlorContext('default') as sor: + async with db.sqlorContext('customer_management') as sor: # 获取客户信息 customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]}) if not customer_records or len(customer_records) == 0: @@ -204,7 +204,7 @@ async def generate_handover_items(sor, handover_id: str, customer_id: str): async def complete_handover_preparation(handover_id: str) -> Dict: """完成交接准备阶段""" db = DBPools() - async with db.sqlorContext('default') as sor: + async with db.sqlorContext('customer_management') as sor: handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]}) if not handover_records or len(handover_records) == 0: raise ValueError("交接记录不存在") @@ -230,7 +230,7 @@ async def complete_handover_preparation(handover_id: str) -> Dict: async def approve_handover(handover_id: str, approver_id: str = None) -> Dict: """审核交接清单""" db = DBPools() - async with db.sqlorContext('default') as sor: + async with db.sqlorContext('customer_management') as sor: approver_id = approver_id or get_current_user_id() handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]}) @@ -258,7 +258,7 @@ async def approve_handover(handover_id: str, approver_id: str = None) -> Dict: async def confirm_handover(handover_id: str, confirm_by: str = None) -> Dict: """确认接收客户""" db = DBPools() - async with db.sqlorContext('default') as sor: + async with db.sqlorContext('customer_management') as sor: confirm_by = confirm_by or get_current_user_id() handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]}) @@ -317,7 +317,7 @@ async def send_customer_notification(sor, customer_id: str, new_owner_id: str): async def recycle_to_pool(customer_id: str, inactive_days: int = None, reason: str = "inactive_days"): """回收客户到公海池""" db = DBPools() - async with db.sqlorContext('default') as sor: + async with db.sqlorContext('customer_management') as sor: customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]}) if not customer_records or len(customer_records) == 0: raise ValueError("客户不存在") @@ -358,7 +358,7 @@ async def recycle_to_pool(customer_id: str, inactive_days: int = None, reason: s async def claim_from_pool(pool_id: str, new_owner_id: str = None): """从公海池认领客户""" db = DBPools() - async with db.sqlorContext('default') as sor: + async with db.sqlorContext('customer_management') as sor: new_owner_id = new_owner_id or get_current_user_id() pool_records = await sor.R("customer_pool", {"filters": [{"field": "id", "op": "=", "value": pool_id}]}) @@ -399,7 +399,7 @@ async def claim_from_pool(pool_id: str, new_owner_id: str = None): async def get_customer_360_view(customer_id: str) -> Dict: """获取客户360度视图""" db = DBPools() - async with db.sqlorContext('default') as sor: + async with db.sqlorContext('customer_management') as sor: # 客户基本信息 customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]}) if not customer_records or len(customer_records) == 0: diff --git a/json/customers_list.json b/json/customers_list.json index 065555a..85b45f7 100644 --- a/json/customers_list.json +++ b/json/customers_list.json @@ -78,21 +78,26 @@ { "field": "customer_id", "title": "客户360度视图", - "url": "{{entire_url('customers')}}", + "url": "{{entire_url('../customers')}}", "subtable": "customers" }, { "field": "customer_id", "title": "交接记录", - "url": "{{entire_url('handover_list')}}", + "url": "{{entire_url('../handover_list')}}", "subtable": "customer_handover" }, { "field": "customer_id", "title": "公海记录", - "url": "{{entire_url('customer_pool_list')}}", + "url": "{{entire_url('../customer_pool_list')}}", "subtable": "customer_pool" } - ] + ], + "editable": { + "new_data_url": "{{entire_url('../api/customers_create.dspy')}}", + "update_data_url": "{{entire_url('../api/customers_update.dspy')}}", + "delete_data_url": "{{entire_url('../api/customers_delete.dspy')}}" + } } } \ No newline at end of file diff --git a/json/handover_list.json b/json/handover_list.json index 7c0d93f..325348e 100644 --- a/json/handover_list.json +++ b/json/handover_list.json @@ -55,7 +55,7 @@ { "field": "handover_id", "title": "交接项目明细", - "url": "{{entire_url('handover_items_list')}}", + "url": "{{entire_url('../handover_items_list')}}", "subtable": "customer_handover_items" } ]