|
|
|
|
@ -10,10 +10,18 @@ from typing import Optional
|
|
|
|
|
|
|
|
|
|
from app.models import AppConfig
|
|
|
|
|
from app.storage_manager import get_storage_manager
|
|
|
|
|
from app.mysql_database import MySQLSessionLocal
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_mysql_session_local():
|
|
|
|
|
"""动态读取 app.mysql_database.MySQLSessionLocal,避免模块导入顺序问题。"""
|
|
|
|
|
import sys
|
|
|
|
|
module = sys.modules.get("app.mysql_database")
|
|
|
|
|
if module is None:
|
|
|
|
|
return None
|
|
|
|
|
return getattr(module, "MySQLSessionLocal", None)
|
|
|
|
|
|
|
|
|
|
CONFIG_DIR = Path(__file__).resolve().parent.parent / "config"
|
|
|
|
|
CONFIG_FILES = {
|
|
|
|
|
"symbols": CONFIG_DIR / "symbols_config.json",
|
|
|
|
|
@ -47,12 +55,19 @@ class ConfigStore:
|
|
|
|
|
):
|
|
|
|
|
self.storage_manager = storage_manager or get_storage_manager()
|
|
|
|
|
self.config_dir = config_dir
|
|
|
|
|
self.session_maker = session_maker or MySQLSessionLocal
|
|
|
|
|
self._session_maker_override = session_maker
|
|
|
|
|
self.config_files = {
|
|
|
|
|
"symbols": self.config_dir / "symbols_config.json",
|
|
|
|
|
"ai": self.config_dir / "ai_config.json",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def session_maker(self):
|
|
|
|
|
"""动态读取 MySQLSessionLocal,避免初始化顺序问题。"""
|
|
|
|
|
if self._session_maker_override is not None:
|
|
|
|
|
return self._session_maker_override
|
|
|
|
|
return _get_mysql_session_local()
|
|
|
|
|
|
|
|
|
|
def get_config(self, key: str, fallback: Optional[dict] = None) -> dict:
|
|
|
|
|
"""读取配置,优先从 MySQL,其次 JSON 文件。"""
|
|
|
|
|
if key not in self.config_files:
|
|
|
|
|
|