guoyu/Study-Vue-redis/log/Sql/完整更新学员状态.sql
2025-12-03 18:58:36 +08:00

112 lines
4.3 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. 确保所有4个状态都存在且正确
-- 状态值对应关系:
-- - incarcerated - 在押
-- - released - 释放
-- - out - 外出
-- - parole - 假释
-- 日期2025-01-XX
-- ============================================
-- 1. 更新"已释放"为"释放"
UPDATE `sys_dict_data`
SET `dict_label` = '释放',
`remark` = '释放状态'
WHERE `dict_type` = 'study_student_status'
AND `dict_value` = 'released';
-- 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 (1, '在押', 'incarcerated', 'study_student_status', '', 'primary', 'Y', '0', 'admin', NOW(), '在押状态')
ON DUPLICATE KEY UPDATE
`dict_label` = '在押',
`dict_sort` = 1,
`is_default` = 'Y',
`status` = '0',
`remark` = '在押状态';
-- 3. 确保"释放"状态存在且正确
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 (2, '释放', 'released', 'study_student_status', '', 'success', 'N', '0', 'admin', NOW(), '释放状态')
ON DUPLICATE KEY UPDATE
`dict_label` = '释放',
`dict_sort` = 2,
`is_default` = 'N',
`status` = '0',
`remark` = '释放状态';
-- 4. 添加"外出"状态到学员状态字典
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` = '外出状态';
-- 5. 添加"假释"状态到学员状态字典
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` = '假释状态';
-- 6. 更新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;
-- 7. 更新字典类型备注
UPDATE `sys_dict_type`
SET `remark` = '学员状态列表(在押、释放、外出、假释等)'
WHERE `dict_type` = 'study_student_status';
-- 8. 确保所有字典数据的status字段为'0'(启用状态)
UPDATE `sys_dict_data`
SET `status` = '0'
WHERE `dict_type` = 'study_student_status'
AND `status` != '0';
-- 9. 验证:查询所有学员状态字典数据
SELECT
`dict_sort`,
`dict_label`,
`dict_value`,
`dict_type`,
`status`,
`remark`,
CASE
WHEN `status` = '0' THEN '✅ 启用'
WHEN `status` = '1' THEN '❌ 停用'
ELSE '⚠️ 未知状态'
END AS ``
FROM `sys_dict_data`
WHERE `dict_type` = 'study_student_status'
ORDER BY `dict_sort`;
-- ============================================
-- 执行说明:
-- 1. 执行此SQL后应该看到4条记录
-- - 在押 (incarcerated)
-- - 释放 (released)
-- - 外出 (out)
-- - 假释 (parole)
-- 2. 所有记录的status字段应该为'0'(启用状态)
-- 3. 执行后需要刷新前端字典缓存(重新登录或清除缓存)
-- ============================================