diff --git a/bin/backend_accounting.py b/bin/backend_accounting.py index e098c6b9..261243f3 100644 --- a/bin/backend_accounting.py +++ b/bin/backend_accounting.py @@ -30,9 +30,22 @@ from product_management import get_manager p = ProgramPath() config = getConfig(NS={'workdir': os.getcwd(), 'ProgramPath': p}) db = DBPools(config.databases) -# 防止 businessdate._get_db() 创建新的空 DBPools 实例 +# 生产环境 get_business_date 内直接 db=DBPools() 创建空实例 → sqlorFactory(None) +# 替换为使用已初始化的 db import appbase.businessdate as _bd -_bd._get_db = lambda: db +_orig_gbd = _bd.get_business_date +async def _patched_get_business_date(sor=None): + async def _f(sor): + sql = "select * from params where params_name = 'business_date'" + recs = await sor.sqlExe(sql, {}) + if len(recs) > 0: + return recs[0]['params_value'] + raise Exception('BusinessDateParamsError') + if sor: + return await _f(sor) + async with db.sqlorContext(get_module_dbname('appbase')) as sor: + return await _f(sor) +_bd.get_business_date = _patched_get_business_date def get_module_dbname(m): return 'sage'