""" 缓存管理Schema """ from datetime import date, datetime from typing import List, Optional from pydantic import BaseModel, Field class CacheTaskCreate(BaseModel): """创建缓存任务""" task_name: str task_type: str = Field(..., description="detect_missing, cache_data, sync_data") security_type: str = Field(..., description="stock, future, index") period_type: Optional[str] = Field(default="daily", description="daily, min1, min5, etc.") start_date: str end_date: str code_list: Optional[List[str]] = None class MissingDateInfo(BaseModel): """缺失日期信息""" date: str expected: int actual: int missing_ratio: float class MissingCodeInfo(BaseModel): """缺失代码信息""" code: str missing_dates: List[MissingDateInfo] class CacheTaskResponse(BaseModel): """缓存任务响应""" id: int task_name: str task_type: str security_type: str period_type: Optional[str] start_date: date end_date: date status: str progress: float total_count: int success_count: int error_count: int error_message: Optional[str] created_at: datetime started_at: Optional[datetime] completed_at: Optional[datetime] class Config: from_attributes = True class CacheTaskDetailResponse(BaseModel): """缓存任务详情响应""" id: int code: str trade_date: date expected_count: int actual_count: int is_missing: bool status: str error_message: Optional[str] processed_at: Optional[datetime] class CacheTaskWithDetailsResponse(CacheTaskResponse): """带详情的缓存任务响应""" details: List[CacheTaskDetailResponse] class CacheStatusResponse(BaseModel): """代码缓存状态响应""" code: str security_type: str period_type: str record_count: int min_date: Optional[str] max_date: Optional[str] missing_ratio: float class DetectMissingRequest(BaseModel): """检测缺失数据请求""" security_type: str period_type: str = "daily" start_date: str end_date: str code_list: List[str] class DetectMissingResponse(BaseModel): """检测缺失数据响应""" task_id: int total_codes: int missing_codes: List[MissingCodeInfo] class BatchCacheRequest(BaseModel): """批量缓存请求""" security_type: str period_type: str = "daily" start_date: str end_date: str code_list: List[str]