fix: DBPools Singleton - manually set db.databases after getting instance
This commit is contained in:
parent
2f68b617c7
commit
bc7cb9676f
@ -21,7 +21,9 @@ async def create_opportunity(
|
|||||||
"""创建商机"""
|
"""创建商机"""
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
opportunity_id = str(uuid.uuid4()).replace('-', '')
|
opportunity_id = str(uuid.uuid4()).replace('-', '')
|
||||||
|
|
||||||
@ -75,7 +77,9 @@ async def update_opportunity_stage(
|
|||||||
"""更新商机阶段"""
|
"""更新商机阶段"""
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||||
if not opportunity_records or len(opportunity_records) == 0:
|
if not opportunity_records or len(opportunity_records) == 0:
|
||||||
@ -129,7 +133,9 @@ async def assign_opportunity(
|
|||||||
"""分配商机给销售人员"""
|
"""分配商机给销售人员"""
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||||
if not opportunity_records or len(opportunity_records) == 0:
|
if not opportunity_records or len(opportunity_records) == 0:
|
||||||
@ -172,7 +178,9 @@ async def get_opportunity_funnel(
|
|||||||
"""获取销售漏斗数据"""
|
"""获取销售漏斗数据"""
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
filters = []
|
filters = []
|
||||||
if start_date and end_date:
|
if start_date and end_date:
|
||||||
@ -221,7 +229,9 @@ async def get_sales_performance(
|
|||||||
"""获取销售业绩数据"""
|
"""获取销售业绩数据"""
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
# 查询已关闭的商机(赢单)
|
# 查询已关闭的商机(赢单)
|
||||||
won_filters = [
|
won_filters = [
|
||||||
|
|||||||
@ -25,7 +25,9 @@ async def create_opportunity(
|
|||||||
"""创建商机"""
|
"""创建商机"""
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
opportunity_id = str(uuid.uuid4()).replace('-', '')
|
opportunity_id = str(uuid.uuid4()).replace('-', '')
|
||||||
|
|
||||||
@ -79,7 +81,9 @@ async def update_opportunity_stage(
|
|||||||
"""更新商机阶段"""
|
"""更新商机阶段"""
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||||
if not opportunity_records or len(opportunity_records) == 0:
|
if not opportunity_records or len(opportunity_records) == 0:
|
||||||
@ -133,7 +137,9 @@ async def assign_opportunity(
|
|||||||
"""分配商机给销售人员"""
|
"""分配商机给销售人员"""
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||||
if not opportunity_records or len(opportunity_records) == 0:
|
if not opportunity_records or len(opportunity_records) == 0:
|
||||||
@ -176,7 +182,9 @@ async def get_opportunity_funnel(
|
|||||||
"""获取销售漏斗数据"""
|
"""获取销售漏斗数据"""
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
filters = []
|
filters = []
|
||||||
if start_date and end_date:
|
if start_date and end_date:
|
||||||
@ -225,7 +233,9 @@ async def get_sales_performance(
|
|||||||
"""获取销售业绩数据"""
|
"""获取销售业绩数据"""
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
# 查询已关闭的商机(赢单)
|
# 查询已关闭的商机(赢单)
|
||||||
won_filters = [
|
won_filters = [
|
||||||
@ -284,7 +294,9 @@ async def predict_revenue(start_date: str, end_date: str):
|
|||||||
async def update_opportunity(opportunity_id: str, **updates):
|
async def update_opportunity(opportunity_id: str, **updates):
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
updates["updated_at"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
updates["updated_at"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
await sor.U(
|
await sor.U(
|
||||||
@ -297,7 +309,9 @@ async def update_opportunity(opportunity_id: str, **updates):
|
|||||||
async def delete_opportunity(opportunity_id: str):
|
async def delete_opportunity(opportunity_id: str):
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
await sor.D(
|
await sor.D(
|
||||||
"opportunities",
|
"opportunities",
|
||||||
@ -308,7 +322,9 @@ async def delete_opportunity(opportunity_id: str):
|
|||||||
async def get_opportunity_by_id(opportunity_id: str):
|
async def get_opportunity_by_id(opportunity_id: str):
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||||
return records[0] if records else None
|
return records[0] if records else None
|
||||||
@ -316,7 +332,9 @@ async def get_opportunity_by_id(opportunity_id: str):
|
|||||||
async def list_opportunities(**filters):
|
async def list_opportunities(**filters):
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
db = DBPools(config.databases)
|
db = DBPools()
|
||||||
|
|
||||||
|
db.databases = config.databases
|
||||||
async with db.sqlorContext('opportunity_management') as sor:
|
async with db.sqlorContext('opportunity_management') as sor:
|
||||||
filter_list = []
|
filter_list = []
|
||||||
for field, value in filters.items():
|
for field, value in filters.items():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user