guoyu/Study-Vue-redis/log/Sql/update_student_status_add_out_parole.sql
2025-12-03 18:58:36 +08:00

77 lines
3.2 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ============================================
-- 学生管理状态更新SQL
-- 功能1. 更新"已释放"为"释放"
-- 2. 添加两个新的学生状态(外出、假释)
-- 3. 更新student_status字段注释
-- 日期2025-01-XX
-- ============================================
-- 0. 更新"已释放"为"释放"
UPDATE `sys_dict_data`
SET `dict_label` = '释放',
`remark` = '释放状态'
WHERE `dict_type` = 'study_student_status'
AND `dict_value` = 'released';
-- 1. 添加"外出"状态到学员状态字典
INSERT INTO `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `remark`)
VALUES (3, '外出', 'out', 'study_student_status', '', 'warning', 'N', '0', 'admin', NOW(), '外出状态')
ON DUPLICATE KEY UPDATE
`dict_label` = '外出',
`dict_sort` = 3,
`is_default` = 'N',
`status` = '0',
`remark` = '外出状态';
-- 2. 添加"假释"状态到学员状态字典
INSERT INTO `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `remark`)
VALUES (4, '假释', 'parole', 'study_student_status', '', 'info', 'N', '0', 'admin', NOW(), '假释状态')
ON DUPLICATE KEY UPDATE
`dict_label` = '假释',
`dict_sort` = 4,
`is_default` = 'N',
`status` = '0',
`remark` = '假释状态';
-- 3. 更新sys_user表中student_status字段的注释如果字段存在
SET @exist := (SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'sys_user'
AND COLUMN_NAME = 'student_status');
SET @sqlstmt := IF(@exist > 0,
'ALTER TABLE `sys_user` MODIFY COLUMN `student_status` VARCHAR(50) DEFAULT NULL COMMENT ''学员状态incarcerated-在押, released-释放, out-外出, parole-假释等)''',
'SELECT ''student_status字段不存在请先执行database_update_student_status.sql'' as result');
PREPARE stmt FROM @sqlstmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 4. 更新字典类型备注
UPDATE `sys_dict_type`
SET `remark` = '学员状态列表(在押、释放、外出、假释等)'
WHERE `dict_type` = 'study_student_status';
-- 验证:查询所有学员状态字典数据
SELECT `dict_sort`, `dict_label`, `dict_value`, `dict_type`, `status`, `remark`
FROM `sys_dict_data`
WHERE `dict_type` = 'study_student_status'
ORDER BY `dict_sort`;
-- ============================================
-- 可选删除sys_user表中的phonenumber字段
-- 注意:删除字段是危险操作,请先备份数据!
-- 如果确定要删除,请取消下面的注释并执行
-- ============================================
-- 检查phonenumber字段是否存在
-- SET @exist := (SELECT COUNT(*) FROM information_schema.COLUMNS
-- WHERE TABLE_SCHEMA = DATABASE()
-- AND TABLE_NAME = 'sys_user'
-- AND COLUMN_NAME = 'phonenumber');
-- SET @sqlstmt := IF(@exist > 0,
-- 'ALTER TABLE `sys_user` DROP COLUMN `phonenumber`',
-- 'SELECT ''phonenumber字段不存在'' as result');
-- PREPARE stmt FROM @sqlstmt;
-- EXECUTE stmt;
-- DEALLOCATE PREPARE stmt;