-- ============================================
-- 国语教育平台 - 数据库字段更新SQL
-- ============================================

-- 1. 为 sys_user 表添加新字段
ALTER TABLE sys_user 
ADD COLUMN prison_name VARCHAR(50) COMMENT '监狱' AFTER remark,
ADD COLUMN prison_area VARCHAR(50) COMMENT '监区' AFTER prison_name,
ADD COLUMN ethnicity VARCHAR(20) COMMENT '民族' AFTER sex,
ADD COLUMN education_level VARCHAR(20) COMMENT '文化程度' AFTER ethnicity,
ADD COLUMN crime_name VARCHAR(50) COMMENT '罪名' AFTER education_level,
ADD COLUMN sentence_term INT COMMENT '刑期（年）' AFTER crime_name,
ADD COLUMN sentence_start_date DATE COMMENT '刑期起日' AFTER sentence_term,
ADD COLUMN sentence_end_date DATE COMMENT '刑期止日' AFTER sentence_start_date,
ADD COLUMN entry_date DATE COMMENT '入监时间' AFTER sentence_end_date;

-- 2. 插入测试数据 - 添加几个罪犯信息
-- 注意：这些SQL需要根据实际的用户角色ID来调整，确保用户能够正确分配角色

-- 插入罪犯1：张三
INSERT INTO sys_user (
    user_name, nick_name, password, sex, prison_name, prison_area, 
    ethnicity, education_level, crime_name, sentence_term, 
    sentence_start_date, sentence_end_date, entry_date, 
    status, del_flag, create_time, remark
) VALUES (
    'zhangsan', '张三', '$2a$10$7JB720yubVSOfvVaMaF0Oe5B.p.FKpDOOaQY4hqPFa8FmJkQvY.2m', 
    '0', '第一监狱', '一监区', '汉族', '初中', '盗窃罪', 3, 
    '2023-01-01', '2026-01-01', '2023-01-15', 
    '0', '0', NOW(), '注册类型:student'
);

-- 插入罪犯2：李四
INSERT INTO sys_user (
    user_name, nick_name, password, sex, prison_name, prison_area, 
    ethnicity, education_level, crime_name, sentence_term, 
    sentence_start_date, sentence_end_date, entry_date, 
    status, del_flag, create_time, remark
) VALUES (
    'lisi', '李四', '$2a$10$7JB720yubVSOfvVaMaF0Oe5B.p.FKpDOOaQY4hqPFa8FmJkQvY.2m', 
    '0', '第一监狱', '二监区', '汉族', '高中', '故意伤害罪', 5, 
    '2022-06-01', '2027-06-01', '2022-06-10', 
    '0', '0', NOW(), '注册类型:student'
);

-- 插入罪犯3：王五
INSERT INTO sys_user (
    user_name, nick_name, password, sex, prison_name, prison_area, 
    ethnicity, education_level, crime_name, sentence_term, 
    sentence_start_date, sentence_end_date, entry_date, 
    status, del_flag, create_time, remark
) VALUES (
    'wangwu', '王五', '$2a$10$7JB720yubVSOfvVaMaF0Oe5B.p.FKpDOOaQY4hqPFa8FmJkQvY.2m', 
    '0', '第二监狱', '一监区', '回族', '小学', '诈骗罪', 7, 
    '2021-03-15', '2028-03-15', '2021-03-20', 
    '0', '0', NOW(), '注册类型:student'
);

-- 插入罪犯4：赵六
INSERT INTO sys_user (
    user_name, nick_name, password, sex, prison_name, prison_area, 
    ethnicity, education_level, crime_name, sentence_term, 
    sentence_start_date, sentence_end_date, entry_date, 
    status, del_flag, create_time, remark
) VALUES (
    'zhaoliu', '赵六', '$2a$10$7JB720yubVSOfvVaMaF0Oe5B.p.FKpDOOaQY4hqPFa8FmJkQvY.2m', 
    '1', '第一监狱', '三监区', '汉族', '中专', '抢劫罪', 10, 
    '2020-05-10', '2030-05-10', '2020-05-15', 
    '0', '0', NOW(), '注册类型:student'
);

-- 插入罪犯5：钱七
INSERT INTO sys_user (
    user_name, nick_name, password, sex, prison_name, prison_area, 
    ethnicity, education_level, crime_name, sentence_term, 
    sentence_start_date, sentence_end_date, entry_date, 
    status, del_flag, create_time, remark
) VALUES (
    'qianqi', '钱七', '$2a$10$7JB720yubVSOfvVaMaF0Oe5B.p.FKpDOOaQY4hqPFa8FmJkQvY.2m', 
    '0', '第二监狱', '二监区', '满族', '大专', '贪污罪', 8, 
    '2022-09-01', '2030-09-01', '2022-09-05', 
    '0', '0', NOW(), '注册类型:student'
);

-- 注意：
-- 1. 密码 '$2a$10$7JB720yubVSOfvVaMaF0Oe5B.p.FKpDOOaQY4hqPFa8FmJkQvY.2m' 对应的明文密码通常是 '123456'
--    如果您的系统使用不同的加密方式，请相应调整
-- 2. 请根据实际的角色ID，为用户分配角色（通过 sys_user_role 表）
-- 3. 如果您的系统有默认密码配置，请使用系统配置的默认密码进行加密
-- 4. 日期格式为 'YYYY-MM-DD'
-- 5. 执行前请备份数据库

-- 3. 语音评测表补充提交状态字段
ALTER TABLE voice_evaluation 
    ADD COLUMN is_submitted TINYINT(1) DEFAULT 0 COMMENT '是否已提交（0-未提交，1-已提交）' AFTER evaluation_time,
    ADD COLUMN submit_time DATETIME DEFAULT NULL COMMENT '提交时间' AFTER is_submitted;

UPDATE voice_evaluation 
SET is_submitted = 0 
WHERE is_submitted IS NULL;

