fix(file-check): 查询最近记录展示进度

This commit is contained in:
hugo committed 2026-08-17 20:24:53 +08:00
1 parent 4ec4e57005
commit 8cde79e0ce
6 files changed
+191 -4

No files matched your search

+34
View File
@@ -301,6 +301,34 @@ def _record_run_bind(run: ScheduleRun, data: dict) -> None:
attach_run_to_turn(turn_id, int(run.id))
def _bind_queried_run_to_turn(run: ScheduleRun, data: dict) -> None:
"""
将已有检核批次关联到本轮查询对话,不改写批次原始执行上下文。
查询最近批次时触发;仅更新 chat_tool_runs 与内存 turn registry,
使 message_end 可以把既有 ScheduleRun.id 写入当前 ChatLog.run_id。
"""
from app.services.file_check_tools.chat_tool_run_binding import bind_schedule_run
from app.services.file_check_tools.chat_turn_registry import attach_run_to_turn
turn_id = str(data.get("hxops_turn_id") or "").strip()
session_id = str(data.get("conversation_id") or "").strip() or None
user_message = str(data.get("user_message") or "").strip() or None
if not turn_id:
return
bound = bind_schedule_run(
schedule_run_id=int(run.id),
turn_id=turn_id,
session_id=session_id,
user_message=user_message,
schedule_task_id=int(run.schedule_task_id),
bind_source="tool_query_latest",
)
if bound:
attach_run_to_turn(turn_id, int(run.id))
def _build_no_data_response(task: ScheduleTask) -> dict:
"""无待检资料时直接返回提示,不创建批次也不绑定 run_id。"""
return {
@@ -534,10 +562,16 @@ def download_file_check_run_excel(run_id: int):
@file_check_bp.route("/tools/tasks/<int:task_id>/latest-run", methods=["GET"])
def get_latest_file_check_run(task_id: int):
"""查询任务最近批次;可绑定本轮对话以展示该批次进度。"""
task = _resolve_check_task(task_id=task_id)
run = ScheduleRun.query.filter_by(schedule_task_id=task.id).order_by(ScheduleRun.id.desc()).first()
if not run:
raise NotFoundError("run_not_found")
_bind_queried_run_to_turn(run, {
"hxops_turn_id": request.args.get("hxops_turn_id"),
"conversation_id": request.args.get("conversation_id"),
"user_message": request.args.get("user_message"),
})
return jsonify({"ok": True, "run": _serialize_tool_run(run)})
+7 -2
View File
@@ -89,7 +89,12 @@ def _serialize_progress_run(run: ScheduleRun) -> dict:
failed = int(payload.get('failed_count') or 0)
skipped = int(payload.get('skipped_count') or 0)
processed = success + failed + skipped
percent = int(round(processed / total * 100)) if total > 0 else 0
if total > 0:
percent = int(round(processed / total * 100))
elif payload.get('status') == 'success':
percent = 100
else:
percent = 0
percent = max(0, min(percent, 100))
return {
'run_id': payload['id'],
@@ -180,4 +185,4 @@ def workspace_file_check_run_excel(run_id: int):
raise NotFoundError('run_not_found')
if not run.excel_file_data:
raise NotFoundError('excel_not_found')
return send_file(BytesIO(run.excel_file_data), as_attachment=True, download_name=run.excel_file_name or f'{run.run_no}.xlsx', mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
return send_file(BytesIO(run.excel_file_data), as_attachment=True, download_name=run.excel_file_name or f'{run.run_no}.xlsx', mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')