调整部分前端布局和后端增删改逻辑

This commit is contained in:
焦龙言
2026-09-20 10:38:10 +08:00
parent acddc8a237
commit 3edba99d2d
227 changed files with 122871 additions and 839 deletions
@@ -0,0 +1,3 @@
from .service import APP_RUNTIME, AppRuntimeService
__all__ = ['APP_RUNTIME', 'AppRuntimeService']
@@ -0,0 +1,29 @@
from importlib import import_module
from types import ModuleType
class AppInfrastructureGateway:
"""
应用基础设施网关。
该对象负责延迟加载应用实例构建和环境配置模块,
供应用运行时 facade 与其协作对象统一复用。
"""
@staticmethod
def get_server_module() -> ModuleType:
"""
获取应用 server 模块。
:return: server 模块
"""
return import_module('server')
@staticmethod
def get_env_module() -> ModuleType:
"""
获取环境配置模块。
:return: 环境配置模块
"""
return import_module('config.env')
@@ -0,0 +1,69 @@
from typing import Any
from cli.runtime.base import RUNTIME_ENVIRONMENT, RuntimeEnvironmentService
from .gateway import AppInfrastructureGateway
from .support import AppSnapshotSupport
class AppRuntimeService:
"""
应用运行时服务。
该服务作为应用运行时 facade,对外统一暴露应用实例构建、
应用配置快照与环境信息快照入口。
:param runtime_environment: 运行时环境服务
:param infrastructure_gateway: 应用基础设施网关
:param snapshot_support: 应用快照支持对象
"""
def __init__(
self,
*,
runtime_environment: RuntimeEnvironmentService | None = None,
infrastructure_gateway: AppInfrastructureGateway | None = None,
snapshot_support: AppSnapshotSupport | None = None,
) -> None:
"""
初始化应用运行时服务。
:param runtime_environment: 运行时环境服务
:param infrastructure_gateway: 应用基础设施网关
:param snapshot_support: 应用快照支持对象
:return: None
"""
self.runtime_environment = runtime_environment or RUNTIME_ENVIRONMENT
self.infrastructure_gateway = infrastructure_gateway or AppInfrastructureGateway()
self.snapshot_support = snapshot_support or AppSnapshotSupport(
self.infrastructure_gateway,
self.runtime_environment,
)
def build_app_instance(self) -> Any:
"""
构建当前环境下的 FastAPI 应用实例。
:return: FastAPI 应用实例
"""
server_module = self.infrastructure_gateway.get_server_module()
return server_module.create_app()
def get_app_config_snapshot(self) -> dict[str, Any]:
"""
读取当前运行环境的应用配置快照。
:return: 应用配置快照
"""
return self.snapshot_support.build_app_config_snapshot()
def get_app_env_snapshot(self) -> dict[str, Any]:
"""
读取当前 CLI 进程的环境解析结果快照。
:return: 环境解析结果快照
"""
return self.snapshot_support.build_app_env_snapshot()
APP_RUNTIME = AppRuntimeService()
@@ -0,0 +1,90 @@
import os
from pathlib import Path
from typing import Any
from cli.runtime.base import RuntimeEnvironmentService
from .gateway import AppInfrastructureGateway
class AppSnapshotSupport:
"""
应用快照支持对象。
该对象负责应用配置快照和环境快照的构建,
避免主运行时服务继续承载快照字段拼装细节。
:param infrastructure_gateway: 应用基础设施网关
:param runtime_environment: 运行时环境服务
"""
def __init__(
self,
infrastructure_gateway: AppInfrastructureGateway,
runtime_environment: RuntimeEnvironmentService,
) -> None:
"""
初始化应用快照支持对象。
:param infrastructure_gateway: 应用基础设施网关
:param runtime_environment: 运行时环境服务
:return: None
"""
self.infrastructure_gateway = infrastructure_gateway
self.runtime_environment = runtime_environment
def build_app_config_snapshot(self) -> dict[str, Any]:
"""
读取当前运行环境的应用配置快照。
:return: 应用配置快照
"""
env_module = self.infrastructure_gateway.get_env_module()
app_config = env_module.AppConfig
database_config = env_module.DataBaseConfig
log_config = env_module.LogConfig
redis_config = env_module.RedisConfig
transport_crypto_config = env_module.TransportCryptoConfig
return {
'env': app_config.app_env,
'name': app_config.app_name,
'host': app_config.app_host,
'port': app_config.app_port,
'rootPath': app_config.app_root_path,
'reload': app_config.app_reload,
'workers': app_config.app_workers,
'disableSwagger': app_config.app_disable_swagger,
'disableRedoc': app_config.app_disable_redoc,
'dbType': database_config.db_type,
'dbHost': database_config.db_host,
'dbPort': database_config.db_port,
'dbDatabase': database_config.db_database,
'redisHost': redis_config.redis_host,
'redisPort': redis_config.redis_port,
'logLevel': log_config.loguru_level,
'transportCryptoEnabled': transport_crypto_config.transport_crypto_enabled,
'transportCryptoMode': transport_crypto_config.transport_crypto_mode,
}
def build_app_env_snapshot(self) -> dict[str, Any]:
"""
读取当前 CLI 进程的环境解析结果快照。
:return: 环境解析结果快照
"""
env_module = self.infrastructure_gateway.get_env_module()
app_config = env_module.AppConfig
backend_dir = Path(self.runtime_environment.get_backend_dir())
resolved_env = os.environ.get('APP_ENV', '') or 'dev'
env_file_name = f'.env.{resolved_env}'
env_file_path = backend_dir / env_file_name
return {
'cliEnv': resolved_env,
'configEnv': app_config.app_env,
'appEnv': os.environ.get('APP_ENV', ''),
'envFile': env_file_name,
'envFilePath': str(env_file_path),
'envFileExists': env_file_path.exists(),
'backendDir': str(backend_dir),
'pythonExecutable': self.runtime_environment.get_python_executable(),
}