feat(rohs-check): 新增 RoHS 检核工具 API 及相关功能
This commit is contained in:
1 parent
8a541211b7
commit
24551e9a9a
39 files changed
+3128
-189
No files matched your search
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import func
|
||||
@@ -8,6 +8,15 @@ from sqlalchemy.orm import joinedload
|
||||
|
||||
from app import db
|
||||
from app.models import ScheduleRun, ScheduleTask
|
||||
from app.response_utils import utc_iso
|
||||
|
||||
|
||||
def _as_naive_utc(dt: datetime | None) -> datetime | None:
|
||||
if dt is None:
|
||||
return None
|
||||
if dt.tzinfo is not None:
|
||||
return dt.astimezone(timezone.utc).replace(tzinfo=None)
|
||||
return dt
|
||||
|
||||
|
||||
def serialize_task(task: ScheduleTask, *, last_status: str | None = None) -> dict:
|
||||
@@ -23,14 +32,16 @@ def serialize_task(task: ScheduleTask, *, last_status: str | None = None) -> dic
|
||||
'dify_agent_id': task.dify_agent_id,
|
||||
'platform_api_path': task.platform_api_path,
|
||||
'data_source_type': task.data_source_type,
|
||||
'kb_sync_enabled': bool(getattr(task, 'kb_sync_enabled', False)),
|
||||
'kb_group_id': getattr(task, 'kb_group_id', None),
|
||||
'notify_user_ids_json': task.notify_user_ids_json or [],
|
||||
'notify_enabled': bool(task.notify_enabled),
|
||||
'enabled': bool(task.enabled),
|
||||
'next_run_at': task.next_run_at.isoformat() if task.next_run_at else None,
|
||||
'last_run_at': task.last_run_at.isoformat() if task.last_run_at else None,
|
||||
'next_run_at': utc_iso(task.next_run_at),
|
||||
'last_run_at': utc_iso(task.last_run_at),
|
||||
'last_status': last_status,
|
||||
'created_at': task.created_at.isoformat() if task.created_at else None,
|
||||
'updated_at': task.updated_at.isoformat() if task.updated_at else None,
|
||||
'created_at': utc_iso(task.created_at),
|
||||
'updated_at': utc_iso(task.updated_at),
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +53,8 @@ def serialize_run(run: ScheduleRun) -> dict:
|
||||
'schedule_name': run.task.name if run.task else None,
|
||||
'trigger_type': run.trigger_type,
|
||||
'triggered_by_user_id': run.triggered_by_user_id,
|
||||
'started_at': run.started_at.isoformat() if run.started_at else None,
|
||||
'finished_at': run.finished_at.isoformat() if run.finished_at else None,
|
||||
'started_at': utc_iso(run.started_at),
|
||||
'finished_at': utc_iso(run.finished_at),
|
||||
'duration_ms': run.duration_ms,
|
||||
'status': run.status,
|
||||
'total_count': run.total_count,
|
||||
@@ -58,10 +69,16 @@ def serialize_run(run: ScheduleRun) -> dict:
|
||||
'error_message': run.error_message,
|
||||
'excel_file_name': run.excel_file_name,
|
||||
'excel_file_size': run.excel_file_size,
|
||||
'kb_sync_status': run.kb_sync_status,
|
||||
'kb_group_id': run.kb_group_id,
|
||||
'kb_document_id': run.kb_document_id,
|
||||
'kb_document_version_id': run.kb_document_version_id,
|
||||
'kb_sync_job_id': run.kb_sync_job_id,
|
||||
'kb_sync_error': run.kb_sync_error,
|
||||
'wecom_notified': bool(run.wecom_notified),
|
||||
'wecom_notified_at': run.wecom_notified_at.isoformat() if run.wecom_notified_at else None,
|
||||
'wecom_notified_at': utc_iso(run.wecom_notified_at),
|
||||
'wecom_notify_error': run.wecom_notify_error,
|
||||
'created_at': run.created_at.isoformat() if run.created_at else None,
|
||||
'created_at': utc_iso(run.created_at),
|
||||
}
|
||||
|
||||
|
||||
@@ -104,9 +121,9 @@ def list_runs(
|
||||
if status:
|
||||
query = query.filter(ScheduleRun.status == status)
|
||||
if started_after is not None:
|
||||
query = query.filter(ScheduleRun.started_at >= started_after)
|
||||
query = query.filter(ScheduleRun.started_at >= _as_naive_utc(started_after))
|
||||
if started_before is not None:
|
||||
query = query.filter(ScheduleRun.started_at < started_before)
|
||||
query = query.filter(ScheduleRun.started_at < _as_naive_utc(started_before))
|
||||
if owner_user_id is not None:
|
||||
query = query.filter(ScheduleTask.owner_user_id == owner_user_id)
|
||||
if notify_user_id is not None:
|
||||
|
||||
Reference in new issue
Block a user