fix: DBPools(config.databases) instead of DBPools() for subprocess context
This commit is contained in:
parent
fd0c9f4aeb
commit
2f68b617c7
@ -6,6 +6,7 @@ import uuid
|
||||
from ahserver.serverenv import ServerEnv
|
||||
from appPublic.worker import awaitify
|
||||
from sqlor.dbpools import DBPools
|
||||
from appPublic.jsonConfig import getConfig
|
||||
|
||||
|
||||
async def create_opportunity(
|
||||
@ -18,7 +19,9 @@ async def create_opportunity(
|
||||
region: str = None
|
||||
) -> Dict:
|
||||
"""创建商机"""
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_id = str(uuid.uuid4()).replace('-', '')
|
||||
|
||||
@ -70,7 +73,9 @@ async def update_opportunity_stage(
|
||||
notes: str = None
|
||||
) -> Dict:
|
||||
"""更新商机阶段"""
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||
if not opportunity_records or len(opportunity_records) == 0:
|
||||
@ -122,7 +127,9 @@ async def assign_opportunity(
|
||||
new_owner_id: str
|
||||
) -> Dict:
|
||||
"""分配商机给销售人员"""
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||
if not opportunity_records or len(opportunity_records) == 0:
|
||||
@ -163,7 +170,9 @@ async def get_opportunity_funnel(
|
||||
region: str = None
|
||||
) -> Dict:
|
||||
"""获取销售漏斗数据"""
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
filters = []
|
||||
if start_date and end_date:
|
||||
@ -210,7 +219,9 @@ async def get_sales_performance(
|
||||
owner_id: str = None
|
||||
) -> Dict:
|
||||
"""获取销售业绩数据"""
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
# 查询已关闭的商机(赢单)
|
||||
won_filters = [
|
||||
|
||||
@ -23,7 +23,9 @@ async def create_opportunity(
|
||||
region: str = None
|
||||
) -> Dict:
|
||||
"""创建商机"""
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_id = str(uuid.uuid4()).replace('-', '')
|
||||
|
||||
@ -75,7 +77,9 @@ async def update_opportunity_stage(
|
||||
notes: str = None
|
||||
) -> Dict:
|
||||
"""更新商机阶段"""
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||
if not opportunity_records or len(opportunity_records) == 0:
|
||||
@ -127,7 +131,9 @@ async def assign_opportunity(
|
||||
new_owner_id: str
|
||||
) -> Dict:
|
||||
"""分配商机给销售人员"""
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||
if not opportunity_records or len(opportunity_records) == 0:
|
||||
@ -168,7 +174,9 @@ async def get_opportunity_funnel(
|
||||
region: str = None
|
||||
) -> Dict:
|
||||
"""获取销售漏斗数据"""
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
filters = []
|
||||
if start_date and end_date:
|
||||
@ -215,7 +223,9 @@ async def get_sales_performance(
|
||||
owner_id: str = None
|
||||
) -> Dict:
|
||||
"""获取销售业绩数据"""
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
# 查询已关闭的商机(赢单)
|
||||
won_filters = [
|
||||
@ -272,7 +282,9 @@ async def predict_revenue(start_date: str, end_date: str):
|
||||
return {"predicted_revenue": performance["weighted_pipeline_value"]}
|
||||
|
||||
async def update_opportunity(opportunity_id: str, **updates):
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
updates["updated_at"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
await sor.U(
|
||||
@ -283,7 +295,9 @@ async def update_opportunity(opportunity_id: str, **updates):
|
||||
return {"opportunity_id": opportunity_id, "updated": True}
|
||||
|
||||
async def delete_opportunity(opportunity_id: str):
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
await sor.D(
|
||||
"opportunities",
|
||||
@ -292,13 +306,17 @@ async def delete_opportunity(opportunity_id: str):
|
||||
return {"opportunity_id": opportunity_id, "deleted": True}
|
||||
|
||||
async def get_opportunity_by_id(opportunity_id: str):
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||
return records[0] if records else None
|
||||
|
||||
async def list_opportunities(**filters):
|
||||
db = DBPools()
|
||||
config = getConfig()
|
||||
|
||||
db = DBPools(config.databases)
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
filter_list = []
|
||||
for field, value in filters.items():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user