feat(rohs-check): 新增 RoHS 检核工具 API 及相关功能

This commit is contained in:
hugo committed 2026-06-10 15:17:09 +08:00
1 parent 8a541211b7
commit 24551e9a9a
39 files changed
+3128 -189

No files matched your search

@@ -211,6 +211,11 @@ def update_task(task: ScheduleTask, *, payload: dict[str, Any], actor_id: int |
task.platform_api_path = normalize_platform_api_path(payload.get("platform_api_path")) or None
if "notify_user_ids_json" in payload and isinstance(payload.get("notify_user_ids_json"), list):
task.notify_user_ids_json = payload.get("notify_user_ids_json")
if "kb_sync_enabled" in payload:
task.kb_sync_enabled = bool(payload.get("kb_sync_enabled"))
if "kb_group_id" in payload:
raw_group_id = payload.get("kb_group_id")
task.kb_group_id = int(raw_group_id) if raw_group_id not in (None, "", 0, "0") else None
if not normalize_platform_api_path(task.platform_api_path):
raise ValueError("platform_api_path is required for platform_app")
@@ -343,6 +348,25 @@ def run_task_now(task: ScheduleTask, *, trigger_type: str, triggered_by_user_id:
run.excel_file_data = file_data
run.excel_file_name = file_name
run.excel_file_size = file_size or 0
task.last_run_at = datetime.utcnow()
db.session.commit()
try:
from app.services.schedule.kb_sync import sync_schedule_run_excel_to_kb
db.session.refresh(task)
db.session.refresh(run)
sync_schedule_run_excel_to_kb(task, run, process_inline=True)
db.session.refresh(run)
except Exception as kb_exc:
db.session.rollback()
db.session.refresh(run)
if current_app:
current_app.logger.error("[schedule-run] kb sync failed: %s", kb_exc, exc_info=True)
run.kb_sync_status = "failed"
run.kb_group_id = getattr(task, "kb_group_id", None)
run.kb_sync_error = str(kb_exc)
db.session.commit()
try:
if task.notify_enabled:
@@ -351,8 +375,6 @@ def run_task_now(task: ScheduleTask, *, trigger_type: str, triggered_by_user_id:
if current_app:
current_app.logger.error("[schedule-run] wecom notify failed: %s", wecom_exc)
task.last_run_at = datetime.utcnow()
db.session.commit()
return run