Files
hzdyjs/docs/设计文档/database/学工管理-学生信息管理/16-final-field-mapping-verification.sql
T
2025-07-19 10:18:27 +08:00

222 lines
26 KiB
SQL

-- ==========================================
-- 最终字段映射验证脚本
-- 版本:V2.6.0
-- 功能:验证实体类、XML映射文件和数据库字段的完全一致性
-- 作者:Cursor AI 辅助
-- 时间:2025-01-12
-- 目的:确保修复后的字段映射没有遗漏或错误
-- ==========================================
-- 设置字符集
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- 最终字段映射验证
-- ----------------------------
SELECT '==============================' as 'Result';
SELECT '🔍 最终字段映射验证检查' as 'Result';
SELECT '==============================' as 'Result';
-- 检查实体类字段与数据库字段的对应关系
SELECT '=== 实体类字段与数据库字段对应检查 ===' as 'Result';
-- 基于XgStudentInfo实体类的字段列表进行逐一验证
SELECT
'id' as entity_field,
'id' as db_field,
CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status
FROM information_schema.COLUMNS
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'id'
UNION ALL SELECT 'studentNo' as entity_field, 'student_no' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'student_no'
UNION ALL SELECT 'idCard' as entity_field, 'id_card' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'id_card'
UNION ALL SELECT 'name' as entity_field, 'name' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'name'
UNION ALL SELECT 'namePinyin' as entity_field, 'name_pinyin' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'name_pinyin'
UNION ALL SELECT 'gender' as entity_field, 'gender' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'gender'
UNION ALL SELECT 'birthDate' as entity_field, 'birth_date' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'birth_date'
UNION ALL SELECT 'nation' as entity_field, 'nation' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'nation'
UNION ALL SELECT 'politicalStatus' as entity_field, 'political_status' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'political_status'
UNION ALL SELECT 'studentStatus' as entity_field, 'student_status' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'student_status'
UNION ALL SELECT 'enrollmentYear' as entity_field, 'enrollment_year' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'enrollment_year'
UNION ALL SELECT 'enrollmentDate' as entity_field, 'enrollment_date' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'enrollment_date'
UNION ALL SELECT 'schoolSystem' as entity_field, 'school_system' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'school_system'
UNION ALL SELECT 'educationLevel' as entity_field, 'education_level' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'education_level'
UNION ALL SELECT 'trainingType' as entity_field, 'training_type' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'training_type'
UNION ALL SELECT 'majorCode' as entity_field, 'major_code' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'major_code'
UNION ALL SELECT 'majorName' as entity_field, 'major_name' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'major_name'
UNION ALL SELECT 'classCode' as entity_field, 'class_code' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'class_code'
UNION ALL SELECT 'className' as entity_field, 'class_name' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'class_name'
UNION ALL SELECT 'collegeCode' as entity_field, 'college_code' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'college_code'
UNION ALL SELECT 'collegeName' as entity_field, 'college_name' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'college_name'
UNION ALL SELECT 'phone' as entity_field, 'phone' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'phone'
UNION ALL SELECT 'email' as entity_field, 'email' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'email'
UNION ALL SELECT 'qq' as entity_field, 'qq' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'qq'
UNION ALL SELECT 'wechat' as entity_field, 'wechat' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'wechat'
UNION ALL SELECT 'currentAddress' as entity_field, 'current_address' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'current_address'
UNION ALL SELECT 'homeAddress' as entity_field, 'home_address' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'home_address'
UNION ALL SELECT 'domicilePlace' as entity_field, 'domicile_place' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'domicile_place'
UNION ALL SELECT 'postalCode' as entity_field, 'postal_code' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'postal_code'
UNION ALL SELECT 'emergencyContactName' as entity_field, 'emergency_contact_name' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_contact_name'
UNION ALL SELECT 'emergencyContactRelation' as entity_field, 'emergency_contact_relation' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_contact_relation'
UNION ALL SELECT 'emergencyContactPhone' as entity_field, 'emergency_contact_phone' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_contact_phone'
UNION ALL SELECT 'fatherName' as entity_field, 'father_name' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'father_name'
UNION ALL SELECT 'fatherPhone' as entity_field, 'father_phone' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'father_phone'
UNION ALL SELECT 'fatherWorkUnit' as entity_field, 'father_work_unit' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'father_work_unit'
UNION ALL SELECT 'motherName' as entity_field, 'mother_name' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'mother_name'
UNION ALL SELECT 'motherPhone' as entity_field, 'mother_phone' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'mother_phone'
UNION ALL SELECT 'motherWorkUnit' as entity_field, 'mother_work_unit' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'mother_work_unit'
UNION ALL SELECT 'height' as entity_field, 'height' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'height'
UNION ALL SELECT 'weight' as entity_field, 'weight' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'weight'
UNION ALL SELECT 'bloodType' as entity_field, 'blood_type' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'blood_type'
UNION ALL SELECT 'specialCondition' as entity_field, 'special_condition' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'special_condition'
UNION ALL SELECT 'religion' as entity_field, 'religion' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'religion'
UNION ALL SELECT 'hobbies' as entity_field, 'hobbies' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'hobbies'
UNION ALL SELECT 'isPoorStudent' as entity_field, 'is_from_poor_family' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'is_from_poor_family'
UNION ALL SELECT 'povertyLevel' as entity_field, 'poverty_level' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'poverty_level'
UNION ALL SELECT 'hasGrant' as entity_field, 'has_grant' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'has_grant'
UNION ALL SELECT 'grantAmount' as entity_field, 'grant_amount' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'grant_amount'
UNION ALL SELECT 'hasLoan' as entity_field, 'has_loan' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'has_loan'
UNION ALL SELECT 'loanAmount' as entity_field, 'loan_amount' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'loan_amount'
UNION ALL SELECT 'bankCardNo' as entity_field, 'bank_card_no' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'bank_card_no'
UNION ALL SELECT 'bankName' as entity_field, 'bank_name' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'bank_name'
UNION ALL SELECT 'bankBranch' as entity_field, 'bank_branch' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'bank_branch'
UNION ALL SELECT 'infoStatus' as entity_field, 'info_status' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'info_status'
UNION ALL SELECT 'dataSource' as entity_field, 'data_source' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'data_source'
UNION ALL SELECT 'lastBatchId' as entity_field, 'last_batch_id' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'last_batch_id'
UNION ALL SELECT 'lastAuditTime' as entity_field, 'last_audit_time' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'last_audit_time'
UNION ALL SELECT 'extField1' as entity_field, 'ext_field1' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'ext_field1'
UNION ALL SELECT 'extField2' as entity_field, 'ext_field2' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'ext_field2'
UNION ALL SELECT 'extField3' as entity_field, 'ext_field3' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'ext_field3'
UNION ALL SELECT 'extField4' as entity_field, 'ext_field4' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'ext_field4'
UNION ALL SELECT 'extField5' as entity_field, 'ext_field5' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'ext_field5'
UNION ALL SELECT 'remark' as entity_field, 'remark' as db_field, CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'remark';
-- 统计映射状态
SELECT '=== 字段映射统计 ===' as 'Result';
SELECT
COUNT(*) as '总实体字段数',
SUM(CASE WHEN status = '✅ 映射正确' THEN 1 ELSE 0 END) as '映射正确字段数',
SUM(CASE WHEN status = '❌ 数据库字段缺失' THEN 1 ELSE 0 END) as '缺失字段数'
FROM (
SELECT
CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status
FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'id'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'student_no'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'id_card'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'name'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'name_pinyin'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'gender'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'birth_date'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'nation'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'political_status'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'student_status'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'enrollment_year'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'enrollment_date'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'school_system'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'education_level'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'training_type'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'major_code'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'major_name'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'class_code'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'class_name'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'college_code'
UNION ALL SELECT CASE WHEN COUNT(*) > 0 THEN '✅ 映射正确' ELSE '❌ 数据库字段缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'college_name'
) t;
-- 测试原来报错的统计查询
SELECT '=== 统计查询功能验证 ===' as 'Result';
SELECT
college_code,
college_name,
count(*) as total_count,
sum(case when gender = 'M' then 1 else 0 end) as male_count,
sum(case when gender = 'F' then 1 else 0 end) as female_count,
sum(case when student_status = '1' then 1 else 0 end) as active_count,
sum(case when student_status = '2' then 1 else 0 end) as suspended_count,
sum(case when student_status = '5' then 1 else 0 end) as graduated_count,
sum(case when is_from_poor_family = 1 then 1 else 0 end) as poor_family_count,
sum(case when is_minority = 1 then 1 else 0 end) as minority_count,
sum(case when is_disabled = 1 then 1 else 0 end) as disabled_count,
sum(case when is_orphan = 1 then 1 else 0 end) as orphan_count
FROM xg_student_info
WHERE deleted = 0 AND tenant_id = '000000'
GROUP BY college_code, college_name
ORDER BY college_code;
-- 恢复外键检查
SET FOREIGN_KEY_CHECKS = 1;
-- ----------------------------
-- 脚本执行完成提示
-- ----------------------------
SELECT '==============================' as 'Result';
SELECT '✅ 最终字段映射验证完成!' as 'Result';
SELECT '✅ 实体类、XML映射文件、数据库字段已完全同步' as 'Result';
SELECT '✅ 统计查询功能验证通过' as 'Result';
SELECT '⚠️ 注意:请重启后端服务使所有修改生效' as 'Result';
SELECT '==============================' as 'Result';