fix: add env.get_module_dbname() for dynamic database lookup
This commit is contained in:
parent
248a0fa979
commit
aa5c2c58df
@ -22,12 +22,17 @@ async def create_customer(
|
|||||||
region: str = None
|
region: str = None
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
"""创建客户档案"""
|
"""创建客户档案"""
|
||||||
|
env = ServerEnv()
|
||||||
|
|
||||||
|
dbname = env.get_module_dbname('customer_management')
|
||||||
|
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
|
|
||||||
db.databases = config.databases
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('customer_management') as sor:
|
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
customer_id = str(uuid.uuid4()).replace('-', '')
|
customer_id = str(uuid.uuid4()).replace('-', '')
|
||||||
|
|
||||||
# 数据校验
|
# 数据校验
|
||||||
@ -78,12 +83,17 @@ async def initiate_handover(
|
|||||||
reviewer_id: str = None
|
reviewer_id: str = None
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
"""发起客户交接流程"""
|
"""发起客户交接流程"""
|
||||||
|
env = ServerEnv()
|
||||||
|
|
||||||
|
dbname = env.get_module_dbname('customer_management')
|
||||||
|
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
|
|
||||||
db.databases = config.databases
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('customer_management') as sor:
|
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
# 获取客户信息
|
# 获取客户信息
|
||||||
customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]})
|
customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]})
|
||||||
if not customer_records or len(customer_records) == 0:
|
if not customer_records or len(customer_records) == 0:
|
||||||
@ -212,12 +222,17 @@ async def generate_handover_items(sor, handover_id: str, customer_id: str):
|
|||||||
|
|
||||||
async def complete_handover_preparation(handover_id: str) -> Dict:
|
async def complete_handover_preparation(handover_id: str) -> Dict:
|
||||||
"""完成交接准备阶段"""
|
"""完成交接准备阶段"""
|
||||||
|
env = ServerEnv()
|
||||||
|
|
||||||
|
dbname = env.get_module_dbname('customer_management')
|
||||||
|
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
|
|
||||||
db.databases = config.databases
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('customer_management') as sor:
|
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]})
|
handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]})
|
||||||
if not handover_records or len(handover_records) == 0:
|
if not handover_records or len(handover_records) == 0:
|
||||||
raise ValueError("交接记录不存在")
|
raise ValueError("交接记录不存在")
|
||||||
@ -242,12 +257,17 @@ async def complete_handover_preparation(handover_id: str) -> Dict:
|
|||||||
|
|
||||||
async def approve_handover(handover_id: str, approver_id: str = None) -> Dict:
|
async def approve_handover(handover_id: str, approver_id: str = None) -> Dict:
|
||||||
"""审核交接清单"""
|
"""审核交接清单"""
|
||||||
|
env = ServerEnv()
|
||||||
|
|
||||||
|
dbname = env.get_module_dbname('customer_management')
|
||||||
|
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
|
|
||||||
db.databases = config.databases
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('customer_management') as sor:
|
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
approver_id = approver_id or get_current_user_id()
|
approver_id = approver_id or get_current_user_id()
|
||||||
|
|
||||||
handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]})
|
handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]})
|
||||||
@ -274,12 +294,17 @@ async def approve_handover(handover_id: str, approver_id: str = None) -> Dict:
|
|||||||
|
|
||||||
async def confirm_handover(handover_id: str, confirm_by: str = None) -> Dict:
|
async def confirm_handover(handover_id: str, confirm_by: str = None) -> Dict:
|
||||||
"""确认接收客户"""
|
"""确认接收客户"""
|
||||||
|
env = ServerEnv()
|
||||||
|
|
||||||
|
dbname = env.get_module_dbname('customer_management')
|
||||||
|
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
|
|
||||||
db.databases = config.databases
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('customer_management') as sor:
|
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
confirm_by = confirm_by or get_current_user_id()
|
confirm_by = confirm_by or get_current_user_id()
|
||||||
|
|
||||||
handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]})
|
handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]})
|
||||||
@ -337,12 +362,17 @@ 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"):
|
async def recycle_to_pool(customer_id: str, inactive_days: int = None, reason: str = "inactive_days"):
|
||||||
"""回收客户到公海池"""
|
"""回收客户到公海池"""
|
||||||
|
env = ServerEnv()
|
||||||
|
|
||||||
|
dbname = env.get_module_dbname('customer_management')
|
||||||
|
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
|
|
||||||
db.databases = config.databases
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('customer_management') as sor:
|
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]})
|
customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]})
|
||||||
if not customer_records or len(customer_records) == 0:
|
if not customer_records or len(customer_records) == 0:
|
||||||
raise ValueError("客户不存在")
|
raise ValueError("客户不存在")
|
||||||
@ -382,12 +412,17 @@ 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):
|
async def claim_from_pool(pool_id: str, new_owner_id: str = None):
|
||||||
"""从公海池认领客户"""
|
"""从公海池认领客户"""
|
||||||
|
env = ServerEnv()
|
||||||
|
|
||||||
|
dbname = env.get_module_dbname('customer_management')
|
||||||
|
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
|
|
||||||
db.databases = config.databases
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('customer_management') as sor:
|
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
new_owner_id = new_owner_id or get_current_user_id()
|
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}]})
|
pool_records = await sor.R("customer_pool", {"filters": [{"field": "id", "op": "=", "value": pool_id}]})
|
||||||
@ -427,12 +462,17 @@ async def claim_from_pool(pool_id: str, new_owner_id: str = None):
|
|||||||
|
|
||||||
async def get_customer_360_view(customer_id: str) -> Dict:
|
async def get_customer_360_view(customer_id: str) -> Dict:
|
||||||
"""获取客户360度视图"""
|
"""获取客户360度视图"""
|
||||||
|
env = ServerEnv()
|
||||||
|
|
||||||
|
dbname = env.get_module_dbname('customer_management')
|
||||||
|
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
|
|
||||||
db.databases = config.databases
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('customer_management') as sor:
|
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
# 客户基本信息
|
# 客户基本信息
|
||||||
customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]})
|
customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]})
|
||||||
if not customer_records or len(customer_records) == 0:
|
if not customer_records or len(customer_records) == 0:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user