137 lines
4.1 KiB
Python
137 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
学生信息分页查询调试脚本
|
|
用于验证数据库连接和数据查询
|
|
"""
|
|
|
|
import pymysql
|
|
import requests
|
|
import json
|
|
from datetime import datetime
|
|
|
|
# 数据库连接配置
|
|
DB_CONFIG = {
|
|
'host': '47.99.164.66',
|
|
'port': 3306,
|
|
'user': 'root',
|
|
'password': 'Lemon123456',
|
|
'database': 'hzdyjs_xg',
|
|
'charset': 'utf8mb4'
|
|
}
|
|
|
|
# API配置
|
|
API_BASE_URL = 'http://localhost:8080'
|
|
|
|
def test_database_connection():
|
|
"""测试数据库连接和查询"""
|
|
try:
|
|
print("=== 数据库连接测试 ===")
|
|
connection = pymysql.connect(**DB_CONFIG)
|
|
cursor = connection.cursor()
|
|
|
|
# 查询学生信息表数据
|
|
sql = """
|
|
SELECT
|
|
id, student_no, name, gender, major, class_name, grade, college,
|
|
status, deleted, tenant_id, create_time
|
|
FROM xg_student_info
|
|
WHERE deleted = 0 AND tenant_id = '000000'
|
|
ORDER BY create_time DESC
|
|
"""
|
|
|
|
cursor.execute(sql)
|
|
results = cursor.fetchall()
|
|
|
|
print(f"数据库查询结果总数: {len(results)}")
|
|
|
|
if results:
|
|
print("\n数据库中的学生信息:")
|
|
for i, row in enumerate(results, 1):
|
|
print(f"{i}. ID: {row[0]}, 学号: {row[1]}, 姓名: {row[2]}, 性别: {row[3]}")
|
|
print(f" 专业: {row[4]}, 班级: {row[5]}, 年级: {row[6]}, 学院: {row[7]}")
|
|
print(f" 状态: {row[8]}, 删除标志: {row[9]}, 租户ID: {row[10]}")
|
|
print(f" 创建时间: {row[11]}")
|
|
print("-" * 50)
|
|
else:
|
|
print("数据库中没有找到学生信息数据!")
|
|
|
|
cursor.close()
|
|
connection.close()
|
|
return len(results) > 0
|
|
|
|
except Exception as e:
|
|
print(f"数据库连接测试失败: {e}")
|
|
return False
|
|
|
|
def test_api_request():
|
|
"""测试API请求"""
|
|
try:
|
|
print("\n=== API请求测试 ===")
|
|
|
|
# 测试分页查询API
|
|
url = f"{API_BASE_URL}/xg/studentInfo/list"
|
|
params = {
|
|
'pageNum': 1,
|
|
'pageSize': 10
|
|
}
|
|
|
|
headers = {
|
|
'Content-Type': 'application/json',
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
|
}
|
|
|
|
print(f"请求URL: {url}")
|
|
print(f"请求参数: {params}")
|
|
|
|
response = requests.get(url, params=params, headers=headers, timeout=30)
|
|
|
|
print(f"响应状态码: {response.status_code}")
|
|
print(f"响应头: {dict(response.headers)}")
|
|
|
|
if response.status_code == 200:
|
|
try:
|
|
data = response.json()
|
|
print(f"响应数据: {json.dumps(data, indent=2, ensure_ascii=False)}")
|
|
|
|
if 'rows' in data:
|
|
print(f"API返回记录数: {len(data['rows'])}")
|
|
print(f"API返回总数: {data.get('total', 0)}")
|
|
else:
|
|
print("API响应中没有rows字段")
|
|
|
|
except json.JSONDecodeError as e:
|
|
print(f"JSON解析失败: {e}")
|
|
print(f"原始响应内容: {response.text}")
|
|
else:
|
|
print(f"API请求失败,状态码: {response.status_code}")
|
|
print(f"错误内容: {response.text}")
|
|
|
|
except Exception as e:
|
|
print(f"API请求测试失败: {e}")
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print(f"开始调试学生信息分页查询问题 - {datetime.now()}")
|
|
print("=" * 60)
|
|
|
|
# 1. 测试数据库连接
|
|
db_ok = test_database_connection()
|
|
|
|
# 2. 测试API请求
|
|
if db_ok:
|
|
test_api_request()
|
|
else:
|
|
print("数据库连接失败,跳过API测试")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("调试完成")
|
|
|
|
print("\n调试建议:")
|
|
print("1. 检查后端服务是否正常启动")
|
|
print("2. 查看后端日志中的详细调试信息")
|
|
print("3. 确认多租户配置是否正确")
|
|
print("4. 检查MyBatis映射配置")
|
|
|
|
if __name__ == "__main__":
|
|
main() |