213 lines
8.9 KiB
Python
213 lines
8.9 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
学生信息分页查询修复验证脚本
|
|
验证重写selectVoPage方法后的分页查询功能
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
from datetime import datetime
|
|
|
|
class StudentInfoPageQueryFixTest:
|
|
def __init__(self):
|
|
self.base_url = "http://localhost:8080"
|
|
self.headers = {
|
|
'Content-Type': 'application/json',
|
|
'clientid': 'e5cd7e4891bf95d1d19206ce24a7b32e',
|
|
'referer': 'http://localhost'
|
|
}
|
|
self.token = None
|
|
|
|
def login(self):
|
|
"""登录获取token"""
|
|
login_url = f"{self.base_url}/auth/login"
|
|
login_data = {
|
|
"username": "admin",
|
|
"password": "admin123"
|
|
}
|
|
|
|
try:
|
|
response = requests.post(login_url, json=login_data, headers=self.headers)
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
if result.get('code') == 200:
|
|
self.token = result['data']['access_token']
|
|
self.headers['Authorization'] = f'Bearer {self.token}'
|
|
print("✅ 登录成功")
|
|
return True
|
|
else:
|
|
print(f"❌ 登录失败: {result.get('msg', '未知错误')}")
|
|
return False
|
|
else:
|
|
print(f"❌ 登录请求失败: HTTP {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ 登录异常: {str(e)}")
|
|
return False
|
|
|
|
def test_page_query_fix(self):
|
|
"""测试修复后的分页查询功能"""
|
|
print("\n🔍 开始测试修复后的学生信息分页查询...")
|
|
|
|
query_url = f"{self.base_url}/xg/studentInfo/list"
|
|
query_params = {
|
|
"pageNum": 1,
|
|
"pageSize": 10
|
|
}
|
|
|
|
try:
|
|
response = requests.get(query_url, params=query_params, headers=self.headers)
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
if result.get('code') == 200:
|
|
data = result.get('data', {})
|
|
rows = data.get('rows', [])
|
|
total = data.get('total', 0)
|
|
|
|
print(f"✅ 分页查询成功")
|
|
print(f"📊 查询结果: 总记录数 {total}, 当前页记录数 {len(rows)}")
|
|
|
|
if len(rows) > 0:
|
|
# 详细检查第一条记录
|
|
first_record = rows[0]
|
|
print(f"\n📋 第一条记录详细信息:")
|
|
print(f" ID: {first_record.get('id')}")
|
|
print(f" 学号: {first_record.get('studentNo')}")
|
|
print(f" 姓名: {first_record.get('name')}")
|
|
|
|
# 检查关键修复字段
|
|
critical_fields = {
|
|
'photoPath': '照片路径',
|
|
'counselorId': '辅导员ID',
|
|
'classTeacherId': '班主任ID',
|
|
'emergencyContactName': '紧急联系人',
|
|
'guardianName': '监护人姓名',
|
|
'specialCondition': '特殊情况',
|
|
'bankBranch': '银行支行',
|
|
'createBy': '创建者',
|
|
'createTime': '创建时间',
|
|
'updateBy': '更新者',
|
|
'updateTime': '更新时间'
|
|
}
|
|
|
|
print(f"\n🔍 关键字段检查:")
|
|
all_fields_present = True
|
|
for field, desc in critical_fields.items():
|
|
if field in first_record:
|
|
value = first_record[field]
|
|
if value is not None:
|
|
print(f" ✅ {desc}({field}): {value}")
|
|
else:
|
|
print(f" ⚠️ {desc}({field}): NULL")
|
|
else:
|
|
print(f" ❌ {desc}({field}): 字段缺失")
|
|
all_fields_present = False
|
|
|
|
# 检查字段总数
|
|
field_count = len(first_record)
|
|
print(f"\n📊 字段统计:")
|
|
print(f" 总字段数: {field_count}")
|
|
print(f" 预期字段数: 60+ (包含所有扩展字段)")
|
|
|
|
if field_count >= 60:
|
|
print(f" ✅ 字段数量正常")
|
|
else:
|
|
print(f" ⚠️ 字段数量可能不足")
|
|
|
|
# 总体评估
|
|
if all_fields_present and field_count >= 60:
|
|
print(f"\n🎉 修复验证成功!")
|
|
print(f" ✅ 所有关键字段都已正确映射")
|
|
print(f" ✅ 字段数量符合预期")
|
|
print(f" ✅ 分页查询功能正常")
|
|
return True
|
|
else:
|
|
print(f"\n⚠️ 修复可能不完全")
|
|
return False
|
|
else:
|
|
print("⚠️ 查询结果为空")
|
|
return False
|
|
else:
|
|
print(f"❌ 分页查询失败: {result.get('msg', '未知错误')}")
|
|
return False
|
|
else:
|
|
print(f"❌ 分页查询请求失败: HTTP {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ 分页查询异常: {str(e)}")
|
|
return False
|
|
|
|
def test_single_record_query(self):
|
|
"""测试单条记录查询验证修复"""
|
|
print("\n🔍 开始测试单条记录查询...")
|
|
|
|
query_url = f"{self.base_url}/xg/studentInfo/studentNo/202101001"
|
|
|
|
try:
|
|
response = requests.get(query_url, headers=self.headers)
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
if result.get('code') == 200:
|
|
data = result.get('data')
|
|
if data:
|
|
print(f"✅ 单条记录查询成功")
|
|
print(f" 学号: {data.get('studentNo')}")
|
|
print(f" 姓名: {data.get('name')}")
|
|
print(f" 字段数量: {len(data)}")
|
|
|
|
# 检查关键字段
|
|
if 'photoPath' in data and 'createBy' in data:
|
|
print(f" ✅ 关键字段存在")
|
|
return True
|
|
else:
|
|
print(f" ❌ 关键字段缺失")
|
|
return False
|
|
else:
|
|
print("❌ 查询结果为空")
|
|
return False
|
|
else:
|
|
print(f"❌ 单条记录查询失败: {result.get('msg', '未知错误')}")
|
|
return False
|
|
else:
|
|
print(f"❌ 单条记录查询请求失败: HTTP {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ 单条记录查询异常: {str(e)}")
|
|
return False
|
|
|
|
def run_tests(self):
|
|
"""运行所有测试"""
|
|
print("🚀 学生信息分页查询修复验证开始")
|
|
print("=" * 60)
|
|
|
|
# 登录
|
|
if not self.login():
|
|
print("❌ 测试终止: 登录失败")
|
|
return False
|
|
|
|
# 测试分页查询
|
|
page_test_result = self.test_page_query_fix()
|
|
|
|
# 测试单条记录查询
|
|
single_test_result = self.test_single_record_query()
|
|
|
|
# 总结
|
|
print("\n" + "=" * 60)
|
|
print("📊 修复验证结果总结:")
|
|
print(f" 分页查询修复: {'✅ 成功' if page_test_result else '❌ 失败'}")
|
|
print(f" 单条记录查询: {'✅ 成功' if single_test_result else '❌ 失败'}")
|
|
|
|
if page_test_result and single_test_result:
|
|
print("\n🎉 修复验证完全成功!")
|
|
print("🔧 重写selectVoPage方法已生效")
|
|
print("📋 所有字段都能正确映射")
|
|
print("🚀 分页查询功能已恢复正常")
|
|
return True
|
|
else:
|
|
print("\n❌ 修复验证失败,需要进一步检查")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
test = StudentInfoPageQueryFixTest()
|
|
test.run_tests() |