252 lines
9.5 KiB
SQL
252 lines
9.5 KiB
SQL
-- ==========================================
|
|
-- XML映射文件字段不一致问题修复脚本
|
|
-- 版本:V2.5.0
|
|
-- 功能:检查XML映射文件与实体类字段映射的一致性
|
|
-- 作者:Cursor AI 辅助
|
|
-- 时间:2025-01-12
|
|
-- 问题:XML映射文件中存在字段名不一致、缺失字段、过时字段等问题
|
|
-- 解决方案:提供完整的字段映射关系对照表
|
|
-- ==========================================
|
|
|
|
-- 设置字符集
|
|
SET NAMES utf8mb4;
|
|
SET FOREIGN_KEY_CHECKS = 0;
|
|
|
|
-- ----------------------------
|
|
-- 检查XML映射文件字段问题
|
|
-- ----------------------------
|
|
|
|
SELECT '==============================' as 'Result';
|
|
SELECT '🔍 XML映射文件字段一致性检查' as 'Result';
|
|
SELECT '==============================' as 'Result';
|
|
|
|
-- 检查实体类字段在数据库中是否存在
|
|
SELECT '=== 实体类字段在数据库中的存在性检查 ===' as 'Result';
|
|
|
|
-- 检查缺失的字段映射
|
|
SELECT '=== 缺失字段映射检查 ===' as 'Result';
|
|
|
|
SELECT
|
|
'current_address' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 数据库字段存在' ELSE '❌ 数据库字段缺失' END as db_status,
|
|
'currentAddress' as entity_field,
|
|
'缺少XML映射' as xml_status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'current_address'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'domicile_place' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 数据库字段存在' ELSE '❌ 数据库字段缺失' END as db_status,
|
|
'domicilePlace' as entity_field,
|
|
'缺少XML映射' as xml_status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'domicile_place'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'emergency_contact_name' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 数据库字段存在' ELSE '❌ 数据库字段缺失' END as db_status,
|
|
'emergencyContactName' as entity_field,
|
|
'缺少XML映射' as xml_status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_contact_name'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'emergency_contact_relation' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 数据库字段存在' ELSE '❌ 数据库字段缺失' END as db_status,
|
|
'emergencyContactRelation' as entity_field,
|
|
'缺少XML映射' as xml_status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_contact_relation'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'emergency_contact_phone' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 数据库字段存在' ELSE '❌ 数据库字段缺失' END as db_status,
|
|
'emergencyContactPhone' as entity_field,
|
|
'缺少XML映射' as xml_status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_contact_phone'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'father_work_unit' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 数据库字段存在' ELSE '❌ 数据库字段缺失' END as db_status,
|
|
'fatherWorkUnit' as entity_field,
|
|
'缺少XML映射' as xml_status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'father_work_unit'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'mother_work_unit' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 数据库字段存在' ELSE '❌ 数据库字段缺失' END as db_status,
|
|
'motherWorkUnit' as entity_field,
|
|
'缺少XML映射' as xml_status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'mother_work_unit'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'postal_code' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 数据库字段存在' ELSE '❌ 数据库字段缺失' END as db_status,
|
|
'postalCode' as entity_field,
|
|
'缺少XML映射' as xml_status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'postal_code'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'special_condition' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 数据库字段存在' ELSE '❌ 数据库字段缺失' END as db_status,
|
|
'specialCondition' as entity_field,
|
|
'缺少XML映射' as xml_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 field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 数据库字段存在' ELSE '❌ 数据库字段缺失' END as db_status,
|
|
'religion' as entity_field,
|
|
'缺少XML映射' as xml_status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'religion';
|
|
|
|
-- 检查过时的字段映射
|
|
SELECT '=== 过时字段映射检查 ===' as 'Result';
|
|
|
|
SELECT
|
|
'emergency_contact' as xml_field,
|
|
CASE WHEN COUNT(*) > 0 THEN '❌ 数据库字段仍存在' ELSE '✅ 数据库字段已移除' END as db_status,
|
|
'emergencyContact' as xml_property,
|
|
'应改为emergency_contact_name' as correct_field
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_contact'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'emergency_phone' as xml_field,
|
|
CASE WHEN COUNT(*) > 0 THEN '❌ 数据库字段仍存在' ELSE '✅ 数据库字段已移除' END as db_status,
|
|
'emergencyPhone' as xml_property,
|
|
'应改为emergency_contact_phone' as correct_field
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_phone'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'emergency_relation' as xml_field,
|
|
CASE WHEN COUNT(*) > 0 THEN '❌ 数据库字段仍存在' ELSE '✅ 数据库字段已移除' END as db_status,
|
|
'emergencyRelation' as xml_property,
|
|
'应改为emergency_contact_relation' as correct_field
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_relation'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'father_job' as xml_field,
|
|
CASE WHEN COUNT(*) > 0 THEN '❌ 数据库字段仍存在' ELSE '✅ 数据库字段已移除' END as db_status,
|
|
'fatherJob' as xml_property,
|
|
'应改为father_work_unit' as correct_field
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'father_job'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'mother_job' as xml_field,
|
|
CASE WHEN COUNT(*) > 0 THEN '❌ 数据库字段仍存在' ELSE '✅ 数据库字段已移除' END as db_status,
|
|
'motherJob' as xml_property,
|
|
'应改为mother_work_unit' as correct_field
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'mother_job'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'home_zip_code' as xml_field,
|
|
CASE WHEN COUNT(*) > 0 THEN '❌ 数据库字段仍存在' ELSE '✅ 数据库字段已移除' END as db_status,
|
|
'homeZipCode' as xml_property,
|
|
'应改为postal_code' as correct_field
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'home_zip_code';
|
|
|
|
-- 检查XML映射文件中不存在的字段
|
|
SELECT '=== XML映射文件中不存在的字段 ===' as 'Result';
|
|
|
|
SELECT
|
|
'dorm_building' as xml_field,
|
|
CASE WHEN COUNT(*) > 0 THEN '❌ 数据库字段存在但实体类中无对应字段' ELSE '✅ 数据库字段不存在' END as db_status,
|
|
'dormBuilding' as xml_property,
|
|
'实体类中不存在此字段' as issue
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'dorm_building'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'dorm_room' as xml_field,
|
|
CASE WHEN COUNT(*) > 0 THEN '❌ 数据库字段存在但实体类中无对应字段' ELSE '✅ 数据库字段不存在' END as db_status,
|
|
'dormRoom' as xml_property,
|
|
'实体类中不存在此字段' as issue
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'dorm_room'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'family_address' as xml_field,
|
|
CASE WHEN COUNT(*) > 0 THEN '❌ 数据库字段存在但实体类中无对应字段' ELSE '✅ 数据库字段不存在' END as db_status,
|
|
'familyAddress' as xml_property,
|
|
'实体类中不存在此字段' as issue
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'family_address'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'family_zip_code' as xml_field,
|
|
CASE WHEN COUNT(*) > 0 THEN '❌ 数据库字段存在但实体类中无对应字段' ELSE '✅ 数据库字段不存在' END as db_status,
|
|
'familyZipCode' as xml_property,
|
|
'实体类中不存在此字段' as issue
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'family_zip_code';
|
|
|
|
-- 显示当前数据库表的完整字段列表
|
|
SELECT '=== 当前数据库表字段列表 ===' as 'Result';
|
|
|
|
SELECT
|
|
COLUMN_NAME as '数据库字段名',
|
|
DATA_TYPE as '数据类型',
|
|
IS_NULLABLE as '是否可空',
|
|
COLUMN_DEFAULT as '默认值',
|
|
COLUMN_COMMENT as '字段注释'
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info'
|
|
ORDER BY ORDINAL_POSITION;
|
|
|
|
-- 恢复外键检查
|
|
SET FOREIGN_KEY_CHECKS = 1;
|
|
|
|
-- ----------------------------
|
|
-- 脚本执行完成提示
|
|
-- ----------------------------
|
|
SELECT '==============================' as 'Result';
|
|
SELECT '✅ XML映射文件字段一致性检查完成!' as 'Result';
|
|
SELECT '📋 请根据检查结果修复XML映射文件' as 'Result';
|
|
SELECT '⚠️ 下一步:修复XgStudentInfoMapper.xml文件' as 'Result';
|
|
SELECT '==============================' as 'Result'; |