debug_goalid.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import requests
  2. import json
  3. def debug_goalid_issue():
  4. print("=== 调试goalId问题 ===")
  5. # 先查询detail_id为10的题目,看看数据库中实际存储的goalId
  6. print("检查最新保存的题目(detail_id=10)的goalId...")
  7. # 由于没有直接的数据库查询接口,我们需要通过其他方式验证
  8. # 让我们创建一个新的测试,使用不同的goalId
  9. test_data = {
  10. "userId": 1,
  11. "goalId": 7, # 使用新的goalId
  12. "subject": "数学",
  13. "type": "选择题",
  14. "difficulty": "简单",
  15. "totalQuantity": 1,
  16. "knowledgePoint": "基础运算"
  17. }
  18. print(f"使用测试数据: {json.dumps(test_data, indent=2, ensure_ascii=False)}")
  19. print()
  20. try:
  21. # 调用API
  22. print("调用Coze API...")
  23. response = requests.post(
  24. "http://localhost:8080/api/coze/generate-questions",
  25. json=test_data,
  26. timeout=60
  27. )
  28. if response.status_code == 200:
  29. result = response.json()
  30. print(f"API响应: success={result.get('success')}, questions_count={len(result.get('questions', []))}")
  31. # 立即查询数据库
  32. print(f"\n查询goalId={test_data['goalId']}的题目...")
  33. db_response = requests.get(f"http://localhost:8080/api/ai/questions/{test_data['goalId']}")
  34. if db_response.status_code == 200:
  35. db_result = db_response.json()
  36. questions = db_result.get('data', [])
  37. print(f"数据库中找到 {len(questions)} 道题目")
  38. for question in questions:
  39. detail_id = question.get('detailId')
  40. goal_id = question.get('goalId')
  41. content = question.get('content', '')[:50] + '...' if question.get('content') else 'No content'
  42. print(f" - detail_id: {detail_id}, goalId: {goal_id}, content: {content}")
  43. if goal_id is None:
  44. print(f" ❌ 发现goalId为None的题目!detail_id={detail_id}")
  45. elif goal_id == test_data['goalId']:
  46. print(f" ✅ goalId一致: {goal_id}")
  47. else:
  48. print(f" ❌ goalId不一致: 预期={test_data['goalId']}, 实际={goal_id}")
  49. else:
  50. print(f"数据库查询失败: {db_response.status_code}")
  51. else:
  52. print(f"API调用失败: {response.status_code}")
  53. print(response.text)
  54. except Exception as e:
  55. print(f"错误: {e}")
  56. if __name__ == "__main__":
  57. debug_goalid_issue()