"""Check and handle draft confirmation.""" import asyncio async def main(): from app.core.database import AsyncSessionLocal from sqlalchemy import select, and_ from app.models import WorkItem, IngestEvent tenant_id = 1 async with AsyncSessionLocal() as db: # Check for pending drafts stmt = ( select(WorkItem, IngestEvent) .join(IngestEvent, IngestEvent.id == WorkItem.ingest_event_id) .where( and_( WorkItem.tenant_id == tenant_id, WorkItem.state == "draft_pending_confirm", ) ) .order_by(WorkItem.id.desc()) .limit(5) ) result = await db.execute(stmt) rows = result.all() if not rows: print("✅ 当前没有待确认的草稿") print("\n最近处理的工作项:") # Show recent work items recent_stmt = ( select(WorkItem) .where(WorkItem.tenant_id == tenant_id) .order_by(WorkItem.id.desc()) .limit(3) ) recent_result = await db.execute(recent_stmt) recent_items = recent_result.scalars().all() for item in recent_items: print(f" - ID: {item.id}, State: {item.state}, Intent: {item.intent}") else: print(f"找到 {len(rows)} 个待确认草稿:\n") for work_item, ingest_event in rows: print(f"Work Item ID: {work_item.id}") print(f"Intent: {work_item.intent}") print(f"Draft Content: {work_item.draft_content}") print(f"Created: {work_item.created_at}") print("-" * 50) if __name__ == "__main__": asyncio.run(main())