from __future__ import annotations from django.contrib.auth import get_user_model from django.core.management.base import BaseCommand, CommandError from review_agent.feishu_questions.service import answer_question class Command(BaseCommand): help = "Simulate a reserved Feishu question against local workflow data." def add_arguments(self, parser): parser.add_argument("--username", required=True, help="System username used as asker.") parser.add_argument("question", help="Question text, for example: 查最新法规核查") def handle(self, *args, **options): user = get_user_model().objects.filter(username=options["username"]).first() if not user: raise CommandError(f"用户不存在:{options['username']}") result = answer_question(user, options["question"]) self.stdout.write(result.get("answer_summary") or "无可返回摘要。")