在准备环境前提交次全部更改。
This commit is contained in:
30
apps/backend/app/schemas/auth.py
Normal file
30
apps/backend/app/schemas/auth.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
认证相关 Pydantic 模型。
|
||||
|
||||
- LoginRequest:登录请求体
|
||||
- TokenResponse:令牌响应体
|
||||
- RefreshRequest:刷新令牌请求体
|
||||
"""
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
"""登录请求。"""
|
||||
|
||||
username: str = Field(..., min_length=1, max_length=64, description="用户名")
|
||||
password: str = Field(..., min_length=1, description="密码")
|
||||
|
||||
|
||||
class RefreshRequest(BaseModel):
|
||||
"""刷新令牌请求。"""
|
||||
|
||||
refresh_token: str = Field(..., min_length=1, description="刷新令牌")
|
||||
|
||||
|
||||
class TokenResponse(BaseModel):
|
||||
"""令牌响应。"""
|
||||
|
||||
access_token: str
|
||||
refresh_token: str
|
||||
token_type: str = "bearer"
|
||||
42
apps/backend/app/schemas/db_viewer.py
Normal file
42
apps/backend/app/schemas/db_viewer.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""数据库查看器 Pydantic 模型
|
||||
|
||||
定义 Schema 浏览、表结构查看、SQL 查询的请求/响应模型。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class SchemaInfo(BaseModel):
|
||||
"""Schema 信息。"""
|
||||
name: str
|
||||
|
||||
|
||||
class TableInfo(BaseModel):
|
||||
"""表信息(含行数统计)。"""
|
||||
name: str
|
||||
row_count: int | None = None
|
||||
|
||||
|
||||
class ColumnInfo(BaseModel):
|
||||
"""列定义。"""
|
||||
name: str
|
||||
data_type: str
|
||||
is_nullable: bool
|
||||
column_default: str | None = None
|
||||
|
||||
|
||||
class QueryRequest(BaseModel):
|
||||
"""SQL 查询请求。"""
|
||||
sql: str
|
||||
|
||||
|
||||
class QueryResponse(BaseModel):
|
||||
"""SQL 查询响应。"""
|
||||
columns: list[str]
|
||||
rows: list[list[Any]]
|
||||
row_count: int
|
||||
27
apps/backend/app/schemas/etl_status.py
Normal file
27
apps/backend/app/schemas/etl_status.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""ETL 状态监控 Pydantic 模型
|
||||
|
||||
定义游标信息和最近执行记录的响应模型。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class CursorInfo(BaseModel):
|
||||
"""ETL 游标信息(单条任务的最后抓取状态)。"""
|
||||
task_code: str
|
||||
last_fetch_time: str | None = None
|
||||
record_count: int | None = None
|
||||
|
||||
|
||||
class RecentRun(BaseModel):
|
||||
"""最近执行记录。"""
|
||||
id: str
|
||||
task_codes: list[str]
|
||||
status: str
|
||||
started_at: str
|
||||
finished_at: str | None = None
|
||||
duration_ms: int | None = None
|
||||
exit_code: int | None = None
|
||||
59
apps/backend/app/schemas/execution.py
Normal file
59
apps/backend/app/schemas/execution.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""执行与队列相关的 Pydantic 模型
|
||||
|
||||
用于 execution 路由的请求/响应序列化。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class ReorderRequest(BaseModel):
|
||||
"""队列重排请求"""
|
||||
task_id: str
|
||||
new_position: int
|
||||
|
||||
|
||||
class QueueTaskResponse(BaseModel):
|
||||
"""队列任务响应"""
|
||||
id: str
|
||||
site_id: int
|
||||
config: dict[str, Any]
|
||||
status: str
|
||||
position: int
|
||||
created_at: datetime | None = None
|
||||
started_at: datetime | None = None
|
||||
finished_at: datetime | None = None
|
||||
exit_code: int | None = None
|
||||
error_message: str | None = None
|
||||
|
||||
|
||||
class ExecutionRunResponse(BaseModel):
|
||||
"""直接执行任务的响应"""
|
||||
execution_id: str
|
||||
message: str
|
||||
|
||||
|
||||
class ExecutionHistoryItem(BaseModel):
|
||||
"""执行历史记录"""
|
||||
id: str
|
||||
site_id: int
|
||||
task_codes: list[str]
|
||||
status: str
|
||||
started_at: datetime
|
||||
finished_at: datetime | None = None
|
||||
exit_code: int | None = None
|
||||
duration_ms: int | None = None
|
||||
command: str | None = None
|
||||
summary: dict[str, Any] | None = None
|
||||
|
||||
|
||||
class ExecutionLogsResponse(BaseModel):
|
||||
"""执行日志响应"""
|
||||
execution_id: str
|
||||
output_log: str | None = None
|
||||
error_log: str | None = None
|
||||
61
apps/backend/app/schemas/schedules.py
Normal file
61
apps/backend/app/schemas/schedules.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""调度配置 Pydantic 模型
|
||||
|
||||
定义 ScheduleConfigSchema 及相关模型,供调度服务和路由使用。
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class ScheduleConfigSchema(BaseModel):
|
||||
"""调度配置 — 支持 5 种调度类型"""
|
||||
|
||||
schedule_type: Literal["once", "interval", "daily", "weekly", "cron"]
|
||||
interval_value: int = 1
|
||||
interval_unit: Literal["minutes", "hours", "days"] = "hours"
|
||||
daily_time: str = "04:00"
|
||||
weekly_days: list[int] = [1]
|
||||
weekly_time: str = "04:00"
|
||||
cron_expression: str = "0 4 * * *"
|
||||
enabled: bool = True
|
||||
start_date: str | None = None
|
||||
end_date: str | None = None
|
||||
|
||||
|
||||
class CreateScheduleRequest(BaseModel):
|
||||
"""创建调度任务请求"""
|
||||
|
||||
name: str
|
||||
task_codes: list[str]
|
||||
task_config: dict[str, Any]
|
||||
schedule_config: ScheduleConfigSchema
|
||||
|
||||
|
||||
class UpdateScheduleRequest(BaseModel):
|
||||
"""更新调度任务请求(所有字段可选)"""
|
||||
|
||||
name: str | None = None
|
||||
task_codes: list[str] | None = None
|
||||
task_config: dict[str, Any] | None = None
|
||||
schedule_config: ScheduleConfigSchema | None = None
|
||||
|
||||
|
||||
class ScheduleResponse(BaseModel):
|
||||
"""调度任务响应"""
|
||||
|
||||
id: str
|
||||
site_id: int
|
||||
name: str
|
||||
task_codes: list[str]
|
||||
task_config: dict[str, Any]
|
||||
schedule_config: dict[str, Any]
|
||||
enabled: bool
|
||||
last_run_at: datetime | None = None
|
||||
next_run_at: datetime | None = None
|
||||
run_count: int
|
||||
last_status: str | None = None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
73
apps/backend/app/schemas/tasks.py
Normal file
73
apps/backend/app/schemas/tasks.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""任务配置 Pydantic 模型
|
||||
|
||||
定义 TaskConfigSchema 及相关模型,用于前后端传输和 CLIBuilder 消费。
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, model_validator
|
||||
|
||||
|
||||
class TaskConfigSchema(BaseModel):
|
||||
"""任务配置 — 前后端传输格式
|
||||
|
||||
字段与 CLI 参数的映射关系:
|
||||
- pipeline → --pipeline(Flow ID,7 种之一)
|
||||
- processing_mode → --processing-mode(3 种处理模式)
|
||||
- tasks → --tasks(逗号分隔)
|
||||
- dry_run → --dry-run(布尔标志)
|
||||
- window_mode → 决定使用 lookback 还是 custom 时间窗口(仅前端逻辑,不直接映射 CLI 参数)
|
||||
- window_start → --window-start
|
||||
- window_end → --window-end
|
||||
- window_split → --window-split
|
||||
- window_split_days → --window-split-days
|
||||
- lookback_hours → --lookback-hours
|
||||
- overlap_seconds → --overlap-seconds
|
||||
- fetch_before_verify → --fetch-before-verify(布尔标志)
|
||||
- store_id → --store-id(由后端从 JWT 注入,前端不传)
|
||||
- dwd_only_tables → 传入 extra_args 或未来扩展
|
||||
"""
|
||||
|
||||
tasks: list[str]
|
||||
pipeline: str = "api_ods_dwd"
|
||||
processing_mode: str = "increment_only"
|
||||
dry_run: bool = False
|
||||
window_mode: str = "lookback"
|
||||
window_start: str | None = None
|
||||
window_end: str | None = None
|
||||
window_split: str | None = None
|
||||
window_split_days: int | None = None
|
||||
lookback_hours: int = 24
|
||||
overlap_seconds: int = 600
|
||||
fetch_before_verify: bool = False
|
||||
skip_ods_when_fetch_before_verify: bool = False
|
||||
ods_use_local_json: bool = False
|
||||
store_id: int | None = None
|
||||
dwd_only_tables: list[str] | None = None
|
||||
force_full: bool = False
|
||||
extra_args: dict[str, Any] = {}
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_window(self) -> "TaskConfigSchema":
|
||||
"""验证时间窗口:结束日期不早于开始日期"""
|
||||
if self.window_start and self.window_end:
|
||||
if self.window_end < self.window_start:
|
||||
raise ValueError("window_end 不能早于 window_start")
|
||||
return self
|
||||
|
||||
|
||||
class FlowDefinition(BaseModel):
|
||||
"""执行流程(Flow)定义"""
|
||||
|
||||
id: str
|
||||
name: str
|
||||
layers: list[str]
|
||||
|
||||
|
||||
class ProcessingModeDefinition(BaseModel):
|
||||
"""处理模式定义"""
|
||||
|
||||
id: str
|
||||
name: str
|
||||
description: str
|
||||
Reference in New Issue
Block a user