fix: user
This commit is contained in:
@@ -102,6 +102,27 @@ def _mask_text(value: str, keep: int = 12) -> str:
|
||||
return f"{text[:keep]}..."
|
||||
|
||||
|
||||
def _build_record_qa_draft(transactions: list[TransactionRecord], assessment_by_tx: dict) -> str:
|
||||
candidates = [tx for tx in transactions if not tx.is_duplicate]
|
||||
if not candidates:
|
||||
return "问:具体的转账信息?\n答:目前暂无可确认的转账信息。"
|
||||
|
||||
candidates = sorted(candidates, key=lambda x: x.trade_time or datetime.min)
|
||||
lines: list[str] = []
|
||||
for idx, tx in enumerate(candidates, 1):
|
||||
fa = assessment_by_tx.get(tx.id)
|
||||
status = fa.review_status.value if fa else "pending"
|
||||
cp_account = f",对方账号{tx.counterparty_account}" if tx.counterparty_account else ""
|
||||
order_no = f",订单号{tx.order_no}" if tx.order_no else ""
|
||||
remark = f",备注“{tx.remark}”" if tx.remark else ""
|
||||
lines.append(
|
||||
f"第{idx}笔是{_fmt_dt(tx.trade_time, with_seconds=True)}通过{tx.source_app.value}"
|
||||
f"{'转出' if tx.direction.value == 'out' else '转入'}人民币{float(tx.amount):,.2f}元至{tx.counterparty_name}"
|
||||
f"{cp_account}{order_no}{remark},当前认定状态为{status}。"
|
||||
)
|
||||
return "问:具体的转账信息?\n答:" + "".join(lines)
|
||||
|
||||
|
||||
async def _build_report_dataset(case_id: UUID, db: AsyncSession) -> dict:
|
||||
case_obj = await db.get(Case, case_id)
|
||||
transactions = await _get_all_transactions(case_id, db)
|
||||
@@ -245,6 +266,14 @@ async def _gen_excel(case_id: UUID, report_dir: Path, body: ReportCreate, db: As
|
||||
ws4.append([i, s])
|
||||
sheet_created = True
|
||||
|
||||
if body.include_record_qa:
|
||||
ws5 = wb.active if not sheet_created else wb.create_sheet()
|
||||
ws5.title = "笔录问答草稿"
|
||||
ws5.append(["问答内容"])
|
||||
dataset = await _build_report_dataset(case_id, db)
|
||||
ws5.append([_build_record_qa_draft(dataset["transactions"], dataset["assessment_by_tx"])])
|
||||
sheet_created = True
|
||||
|
||||
if not sheet_created:
|
||||
ws = wb.active
|
||||
ws.title = "报告"
|
||||
@@ -482,6 +511,15 @@ async def _gen_pdf(case_id: UUID, report_dir: Path, body: ReportCreate, db: Asyn
|
||||
elements.append(Paragraph(f"{i}. {s}", normal_style))
|
||||
elements.append(Spacer(1, 8 * mm))
|
||||
|
||||
# Section 9: record QA draft
|
||||
if body.include_record_qa:
|
||||
elements.append(Paragraph("笔录问答草稿", h2_style))
|
||||
elements.append(Spacer(1, 4 * mm))
|
||||
qa_text = _build_record_qa_draft(transactions, assessment_by_tx)
|
||||
for line in qa_text.split("\n"):
|
||||
elements.append(Paragraph(line, normal_style))
|
||||
elements.append(Spacer(1, 8 * mm))
|
||||
|
||||
if not elements or len(elements) <= 2:
|
||||
elements.append(Paragraph("未选择任何报告内容。", normal_style))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user