123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import requests
- import json
- def debug_goalid_issue():
- print("=== 调试goalId问题 ===")
-
- # 先查询detail_id为10的题目,看看数据库中实际存储的goalId
- print("检查最新保存的题目(detail_id=10)的goalId...")
-
- # 由于没有直接的数据库查询接口,我们需要通过其他方式验证
- # 让我们创建一个新的测试,使用不同的goalId
-
- test_data = {
- "userId": 1,
- "goalId": 7, # 使用新的goalId
- "subject": "数学",
- "type": "选择题",
- "difficulty": "简单",
- "totalQuantity": 1,
- "knowledgePoint": "基础运算"
- }
-
- print(f"使用测试数据: {json.dumps(test_data, indent=2, ensure_ascii=False)}")
- print()
-
- try:
- # 调用API
- print("调用Coze API...")
- response = requests.post(
- "http://localhost:8080/api/coze/generate-questions",
- json=test_data,
- timeout=60
- )
-
- if response.status_code == 200:
- result = response.json()
- print(f"API响应: success={result.get('success')}, questions_count={len(result.get('questions', []))}")
-
- # 立即查询数据库
- print(f"\n查询goalId={test_data['goalId']}的题目...")
- db_response = requests.get(f"http://localhost:8080/api/ai/questions/{test_data['goalId']}")
-
- if db_response.status_code == 200:
- db_result = db_response.json()
- questions = db_result.get('data', [])
-
- print(f"数据库中找到 {len(questions)} 道题目")
-
- for question in questions:
- detail_id = question.get('detailId')
- goal_id = question.get('goalId')
- content = question.get('content', '')[:50] + '...' if question.get('content') else 'No content'
-
- print(f" - detail_id: {detail_id}, goalId: {goal_id}, content: {content}")
-
- if goal_id is None:
- print(f" ❌ 发现goalId为None的题目!detail_id={detail_id}")
- elif goal_id == test_data['goalId']:
- print(f" ✅ goalId一致: {goal_id}")
- else:
- print(f" ❌ goalId不一致: 预期={test_data['goalId']}, 实际={goal_id}")
- else:
- print(f"数据库查询失败: {db_response.status_code}")
- else:
- print(f"API调用失败: {response.status_code}")
- print(response.text)
-
- except Exception as e:
- print(f"错误: {e}")
- if __name__ == "__main__":
- debug_goalid_issue()
|