|
|
@@ -1,68 +1,93 @@
|
|
|
from pathlib import Path
|
|
|
from typing import Dict, List
|
|
|
from enum import Enum
|
|
|
+from typing import ClassVar
|
|
|
import json
|
|
|
+from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
|
|
|
-class Settings:
|
|
|
- BASE_PATH = Path(__file__).parent.parent.parent.absolute()
|
|
|
+class Settings(BaseSettings):
|
|
|
+ BASE_PATH: ClassVar[Path] = Path(__file__).parent.parent.parent.absolute()
|
|
|
+
|
|
|
+ TEST_DATA: str = '环境变量读取测试, 目前使用本地字段'
|
|
|
+
|
|
|
+ @property
|
|
|
+ def TEST_DATA_END(self) -> str:
|
|
|
+ return f'{self.TEST_DATA}/end'
|
|
|
|
|
|
# 用户系统重要的KEY
|
|
|
- ADMIN_GRANT_KEY = "CardScoreAdminKey2026_aaabbbccc"
|
|
|
- TOKEN_SECRET_KEY = "CardScoreDataServerTokenSecret2026"
|
|
|
+ ADMIN_GRANT_KEY: str = "CardScoreAdminKey2026_aaabbbccc"
|
|
|
+ TOKEN_SECRET_KEY: str = "CardScoreDataServerTokenSecret2026"
|
|
|
|
|
|
# --- MinIO 配置 ---
|
|
|
- MINIO_ENDPOINT = "192.168.77.249:9000"
|
|
|
- MINIO_ACCESS_KEY = "pZEwCGnpNN05KPnmC2Yh"
|
|
|
- MINIO_SECRET_KEY = "KfJRuWiv9pVxhIMcFqbkv8hZT9SnNTZ6LPx592D4" # 替换为你的 Secret Key
|
|
|
- MINIO_SECURE = False # 是否使用 https
|
|
|
- MINIO_BUCKET = "grading"
|
|
|
- MINIO_BASE_PREFIX = "score_server_data"
|
|
|
+ MINIO_ENDPOINT: str = "192.168.77.249:9000"
|
|
|
+ MINIO_ACCESS_KEY: str = "pZEwCGnpNN05KPnmC2Yh"
|
|
|
+ MINIO_SECRET_KEY: str = "KfJRuWiv9pVxhIMcFqbkv8hZT9SnNTZ6LPx592D4"
|
|
|
+ MINIO_SECURE: bool = False # 是否使用 https
|
|
|
+ MINIO_BUCKET: str = "grading"
|
|
|
+ MINIO_BASE_PREFIX: str = "score_server_data"
|
|
|
|
|
|
# DATA_HOST_URL 现在直接指向 MinIO 的前缀路径
|
|
|
# (注意: 需要在 MinIO 后台将 grading 存储桶的访问权限配置为 Public 或开启特定读策略)
|
|
|
- DATA_HOST_URL = f"http://{MINIO_ENDPOINT}/{MINIO_BUCKET}/{MINIO_BASE_PREFIX}"
|
|
|
+ @property
|
|
|
+ def DATA_HOST_URL(self) -> str:
|
|
|
+ return f"http://{self.MINIO_ENDPOINT}/{self.MINIO_BUCKET}/{self.MINIO_BASE_PREFIX}"
|
|
|
|
|
|
- CONFIG_PATH = BASE_PATH / 'Config.json'
|
|
|
+ # CONFIG_PATH: str = BASE_PATH / 'Config.json'
|
|
|
API_PREFIX: str = "/api" # 通用前缀
|
|
|
- SCORE_CONFIG_PATH = BASE_PATH / "app/core/scoring_config.json"
|
|
|
+ SCORE_CONFIG_PATH: Path = BASE_PATH / "app/core/scoring_config.json"
|
|
|
|
|
|
# 分数计算接口url
|
|
|
- SCORE_UPDATE_SERVER_URL = "http://127.0.0.1:7754"
|
|
|
- SCORE_RECALCULATE_ENDPOINT = f"{SCORE_UPDATE_SERVER_URL}/api/card_score/score_recalculate"
|
|
|
+ SCORE_UPDATE_SERVER_URL: str = "http://127.0.0.1:7754"
|
|
|
+
|
|
|
+ @property
|
|
|
+ def SCORE_RECALCULATE_ENDPOINT(self) -> str:
|
|
|
+ return f"{self.SCORE_UPDATE_SERVER_URL}/api/card_score/score_recalculate"
|
|
|
+
|
|
|
# 分数计算配置接口
|
|
|
- SCORE_SERVER_CONFIG_URL = f"{SCORE_UPDATE_SERVER_URL}/api/config/scoring_config"
|
|
|
+ @property
|
|
|
+ def SCORE_SERVER_CONFIG_URL(self) -> str:
|
|
|
+ return f"{self.SCORE_UPDATE_SERVER_URL}/api/config/scoring_config"
|
|
|
|
|
|
# 评级后台接口url
|
|
|
- RATING_SERVER_URL = "http://192.168.77.89:8090"
|
|
|
- RATING_REPORT_SAVE_API = f"{RATING_SERVER_URL}/rating/card/ratingReport/save"
|
|
|
+ RATING_SERVER_URL: str = "http://192.168.77.89:8090"
|
|
|
+
|
|
|
+ @property
|
|
|
+ def RATING_REPORT_SAVE_API(self) -> str:
|
|
|
+ return f"{self.RATING_SERVER_URL}/rating/card/ratingReport/save"
|
|
|
|
|
|
# --- 数据库配置 ---
|
|
|
- DB_NAME = 'card_score_gray_database'
|
|
|
- DB_CARD_TABLE_NAME = 'cards'
|
|
|
- DB_IMAGE_TABLE_NAME = 'card_images'
|
|
|
- DB_GRAY_IMAGE_TABLE_NAME = 'card_gray_images' # 灰度图表名
|
|
|
- DB_USER_TABLE_NAME = 'users'
|
|
|
- DB_USER_CARD_TABLE_NAME = 'user_card_bindings'
|
|
|
- RATING_REPORT_HISTORY_TABLE_NAME = "rating_report_history"
|
|
|
-
|
|
|
- DATABASE_CONFIG: Dict[str, str] = {
|
|
|
- 'user': 'root',
|
|
|
- 'password': '123456',
|
|
|
- 'host': '127.0.0.1',
|
|
|
- }
|
|
|
- # 连接到指定数据库的配置
|
|
|
- DATABASE_CONFIG_WITH_DB: Dict[str, str] = {
|
|
|
- **DATABASE_CONFIG,
|
|
|
- 'database': DB_NAME
|
|
|
- }
|
|
|
+ DB_NAME: str = 'card_score_gray_database'
|
|
|
+ DB_CARD_TABLE_NAME: str = 'cards'
|
|
|
+ DB_IMAGE_TABLE_NAME: str = 'card_images'
|
|
|
+ DB_GRAY_IMAGE_TABLE_NAME: str = 'card_gray_images' # 灰度图表名
|
|
|
+ DB_USER_TABLE_NAME: str = 'users'
|
|
|
+ DB_USER_CARD_TABLE_NAME: str = 'user_card_bindings'
|
|
|
+ RATING_REPORT_HISTORY_TABLE_NAME: str = "rating_report_history"
|
|
|
+
|
|
|
+ DB_USER: str = 'root'
|
|
|
+ DB_PASSWORD: str = '123456'
|
|
|
+ DB_HOST: str = '127.0.0.1'
|
|
|
|
|
|
- def set_config(self):
|
|
|
- with open(self.CONFIG_PATH, 'r') as f:
|
|
|
- config_json = json.load(f)
|
|
|
+ @property
|
|
|
+ def DATABASE_CONFIG(self) -> Dict[str, str]:
|
|
|
+ return {
|
|
|
+ 'user': self.DB_USER,
|
|
|
+ 'password': self.DB_PASSWORD,
|
|
|
+ 'host': self.DB_HOST,
|
|
|
+ }
|
|
|
+
|
|
|
+ # 连接到指定数据库的配置
|
|
|
+ @property
|
|
|
+ def DATABASE_CONFIG_WITH_DB(self) -> Dict[str, str]:
|
|
|
+ return {
|
|
|
+ **self.DATABASE_CONFIG,
|
|
|
+ 'database': self.DB_NAME
|
|
|
+ }
|
|
|
|
|
|
- self.DATABASE_CONFIG = config_json["mysql_config"]
|
|
|
- self.DB_NAME = config_json["database_name"]
|
|
|
+ # 优先级:系统环境变量 > .env 文件
|
|
|
+ model_config = SettingsConfigDict(env_file=".env",
|
|
|
+ env_file_encoding='utf-8')
|
|
|
|
|
|
def get_full_url(self, path: str) -> str:
|
|
|
"""将相对路径转换为可以直接打开的 MinIO 绝对 URL"""
|
|
|
@@ -76,3 +101,5 @@ class Settings:
|
|
|
|
|
|
|
|
|
settings = Settings()
|
|
|
+print("测试读取env", settings.TEST_DATA)
|
|
|
+print("测试拼接env", settings.TEST_DATA_END)
|