数据看板分享模式:新增 series 接口、免登录路径、时间范围查询

- 新增 /api/v1/data-dashboard/ocr/series 路由(按采集轮次序列)
- ocr_dashboard_service 新增 get_series 透传
- /api/v1/data-dashboard/ 加入免登录 open_paths
- summary/comparison 路由透传 start_date/end_date
- evidences 放宽必填校验(支持时间范围替代批次)
This commit is contained in:
2026-08-28 17:21:56 +08:00
parent e188c50fab
commit af340206a5
2 changed files with 32 additions and 7 deletions

15
app.py
View File

@@ -18,6 +18,7 @@ from config import Config
from database import init_database
from ocr_dashboard_service import (
get_comparison as get_ocr_dashboard_comparison,
get_series as get_ocr_dashboard_series,
get_result_matches as get_ocr_result_matches,
get_summary as get_ocr_dashboard_summary,
list_batches as list_ocr_batches,
@@ -79,7 +80,7 @@ def create_app() -> Flask:
g.request_id = request.headers.get("X-Request-Id") or f"req_{secrets.token_hex(10)}"
if request.method == "OPTIONS":
return None
open_paths = ("/health", "/api/v1/auth/", "/api/v1/skill/")
open_paths = ("/health", "/api/v1/auth/", "/api/v1/skill/", "/api/v1/data-dashboard/")
if request.path == "/health" or any(request.path.startswith(path) for path in open_paths):
return None
user = local_dev_user() or get_user_by_session_token(request.cookies.get(Config.SESSION_COOKIE_NAME))
@@ -342,6 +343,16 @@ def create_app() -> Flask:
return jsonify({"data": get_ocr_dashboard_summary(
request.args.get("batch_key", "").strip(),
request.args.get("collection_key", "").strip(),
request.args.get("start_date", "").strip(),
request.args.get("end_date", "").strip(),
), "request_id": g.request_id})
@app.route("/api/v1/data-dashboard/ocr/series", methods=["GET"])
def query_ocr_dashboard_series():
return jsonify({"data": get_ocr_dashboard_series(
request.args.get("batch_key", "").strip(),
request.args.get("start_date", "").strip(),
request.args.get("end_date", "").strip(),
), "request_id": g.request_id})
@app.route("/api/v1/data-dashboard/ocr/comparison", methods=["GET"])
@@ -349,6 +360,8 @@ def create_app() -> Flask:
return jsonify({"data": get_ocr_dashboard_comparison(
request.args.get("batch_key", "").strip(),
request.args.get("collection_key", "").strip(),
request.args.get("start_date", "").strip(),
request.args.get("end_date", "").strip(),
), "request_id": g.request_id})
@app.route("/api/v1/data-dashboard/ocr/results", methods=["GET"])

View File

@@ -46,21 +46,32 @@ def list_collections(batch_key: str) -> list[dict[str, Any]]:
return _get(f"/xhs/ocr/batches/{batch_key.strip()}/collections") or []
def get_summary(batch_key: str = "", collection_key: str = "") -> dict[str, Any]:
def get_summary(batch_key: str = "", collection_key: str = "",
start_date: str = "", end_date: str = "") -> dict[str, Any]:
return _get("/xhs/ocr/dashboard/summary", {
"batch_key": batch_key, "collection_key": collection_key,
"start_date": start_date, "end_date": end_date,
}) or {}
def get_comparison(batch_key: str = "", collection_key: str = "") -> dict[str, Any]:
def get_series(batch_key: str = "", start_date: str = "", end_date: str = "") -> dict[str, Any]:
return _get("/xhs/ocr/dashboard/series", {
"batch_key": batch_key, "start_date": start_date, "end_date": end_date,
}) or {"items": [], "subjects": []}
def get_comparison(batch_key: str = "", collection_key: str = "",
start_date: str = "", end_date: str = "") -> dict[str, Any]:
return _get("/xhs/ocr/dashboard/comparison", {
"batch_key": batch_key, "collection_key": collection_key,
"start_date": start_date, "end_date": end_date,
}) or {}
def list_results(params: dict[str, Any]) -> dict[str, Any]:
allowed = {
"batch_key", "collection_key", "question_code", "search_keyword", "city",
"batch_key", "collection_key", "start_date", "end_date",
"question_code", "search_keyword", "city",
"department_name", "minsheng_matched", "cobranded_matched", "is_valid",
"page", "page_size",
}
@@ -82,10 +93,11 @@ def get_result_matches(result_id: int) -> dict[str, Any]:
def list_evidences(params: dict[str, Any]) -> dict[str, Any]:
allowed = {"batch_key", "collection_key", "question_code", "evidence_type", "limit"}
allowed = {"batch_key", "collection_key", "start_date", "end_date", "question_code", "evidence_type", "limit"}
query = {key: value for key, value in params.items() if key in allowed}
if not str(query.get("batch_key") or "").strip() or not str(query.get("collection_key") or "").strip():
raise TaskError("OCR_EVIDENCE_SCOPE_REQUIRED", "batch_key 和 collection_key 不能为空", 422)
if not (str(query.get("batch_key") or "").strip() or str(query.get("collection_key") or "").strip()
or str(query.get("start_date") or "").strip() or str(query.get("end_date") or "").strip()):
raise TaskError("OCR_EVIDENCE_SCOPE_REQUIRED", "batch_key/collection_key 或 start_date/end_date 至少传入一种", 422)
limit = int(query.get("limit") or 10)
if not 1 <= limit <= 100:
raise TaskError("OCR_EVIDENCE_LIMIT_INVALID", "limit 必须在 1 到 100 之间", 422)