From af340206a5628728c44671072942633c58f51290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=B8=85?= Date: Fri, 28 Aug 2026 17:21:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9C=8B=E6=9D=BF=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E6=A8=A1=E5=BC=8F=EF=BC=9A=E6=96=B0=E5=A2=9E=20series?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3=E3=80=81=E5=85=8D=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E3=80=81=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 /api/v1/data-dashboard/ocr/series 路由(按采集轮次序列) - ocr_dashboard_service 新增 get_series 透传 - /api/v1/data-dashboard/ 加入免登录 open_paths - summary/comparison 路由透传 start_date/end_date - evidences 放宽必填校验(支持时间范围替代批次) --- app.py | 15 ++++++++++++++- ocr_dashboard_service.py | 24 ++++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 60c9ebb..07d28e4 100644 --- a/app.py +++ b/app.py @@ -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"]) diff --git a/ocr_dashboard_service.py b/ocr_dashboard_service.py index c1a64ac..31107dd 100644 --- a/ocr_dashboard_service.py +++ b/ocr_dashboard_service.py @@ -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)