48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from django.urls import reverse
|
|
|
|
from review_agent.models import Message
|
|
|
|
from ..services.export_excel import generate_excel_export
|
|
from ..services.report import generate_markdown_report
|
|
from .base import BaseSkill, SkillResult, WorkflowContext
|
|
|
|
|
|
logger = logging.getLogger("review_agent.file_summary.skills.summary_report")
|
|
|
|
|
|
class SummaryReportSkill(BaseSkill):
|
|
name = "summary_report"
|
|
|
|
def run(self, context: WorkflowContext) -> SkillResult:
|
|
logger.info("Summary report started", extra={"batch_id": context.batch.pk})
|
|
markdown_export, summary_table = generate_markdown_report(context.batch)
|
|
excel_export = generate_excel_export(context.batch)
|
|
markdown_url = reverse("file_summary_export_download", args=[markdown_export.pk])
|
|
excel_url = reverse("file_summary_export_download", args=[excel_export.pk])
|
|
content = (
|
|
"文件目录与页数汇总已完成。\n\n"
|
|
f"{summary_table}\n\n"
|
|
f"[下载 Markdown 报告]({markdown_url}) | [下载 Excel 明细]({excel_url})"
|
|
)
|
|
Message.objects.create(
|
|
conversation=context.batch.conversation,
|
|
role=Message.Role.ASSISTANT,
|
|
content=content,
|
|
)
|
|
logger.info(
|
|
"Summary report finished",
|
|
extra={
|
|
"batch_id": context.batch.pk,
|
|
"markdown_export_id": markdown_export.pk,
|
|
"excel_export_id": excel_export.pk,
|
|
},
|
|
)
|
|
return SkillResult(
|
|
success=True,
|
|
data={"markdown_export_id": markdown_export.pk, "excel_export_id": excel_export.pk},
|
|
)
|