-- =====================================================================
-- FIGS 教育管理模块 - 升级脚本 v5 (奖惩记录)
-- 增量脚本, 在 schema_upgrade_v4_score.sql 之后执行
-- 功能: 学生的奖励/表扬/违纪/惩罚记录
-- =====================================================================

SET NAMES utf8mb4;

-- -----------------------------------------------------------------
-- 1. 奖惩记录表 edu_reward_punish
-- -----------------------------------------------------------------
DROP TABLE IF EXISTS `edu_reward_punish`;
CREATE TABLE `edu_reward_punish` (
  `id`            bigint        NOT NULL                COMMENT '主键',
  `tenant_id`     varchar(20)   DEFAULT '000000'        COMMENT '租户ID',
  `student_id`    bigint        NOT NULL                COMMENT '学生ID',
  `type`          varchar(8)    NOT NULL                COMMENT '类型 REWARD=奖励 PUNISH=惩罚',
  `category`      varchar(32)   DEFAULT NULL            COMMENT '类别(表扬/进步奖/违纪/迟到/缺交作业等)',
  `title`         varchar(255)  NOT NULL                COMMENT '标题',
  `occur_time`    datetime      DEFAULT NULL            COMMENT '发生时间',
  `score_change`  decimal(8,2)  DEFAULT NULL            COMMENT '分值变动(加分/扣分, 可空)',
  `handler_id`    bigint        DEFAULT NULL            COMMENT '处理人(系统登录用户ID)',
  `description`   varchar(2000) DEFAULT NULL            COMMENT '详细说明',
  `attachments`   varchar(500)  DEFAULT NULL            COMMENT '附件 ossId 串(逗号分隔)',
  `status`        char(1)       DEFAULT '0'             COMMENT '状态 0=生效 1=已撤销',
  `del_flag`      char(1)       DEFAULT '0'             COMMENT '删除标志 0=存在 1=删除',
  `remark`        varchar(500)  DEFAULT NULL            COMMENT '备注',
  `create_dept`   bigint        DEFAULT NULL            COMMENT '创建部门',
  `create_by`     bigint        DEFAULT NULL            COMMENT '创建者',
  `create_time`   datetime      DEFAULT NULL            COMMENT '创建时间',
  `update_by`     bigint        DEFAULT NULL            COMMENT '更新者',
  `update_time`   datetime      DEFAULT NULL            COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_tenant_student_time` (`tenant_id`,`student_id`,`occur_time`) USING BTREE,
  KEY `idx_tenant_type` (`tenant_id`,`type`,`status`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='学生奖惩记录';

-- -----------------------------------------------------------------
-- 2. 字典: 奖惩类型 / 奖惩类别 (edu_dict.id 从 153 起)
-- -----------------------------------------------------------------
DELETE FROM `edu_dict` WHERE id BETWEEN 153 AND 165;
INSERT INTO `edu_dict`(`id`,`tenant_id`,`dict_type`,`dict_label`,`dict_value`,`sort_order`,`color`,`status`,`remark`,`create_by`,`create_time`) VALUES
(153,'000000','edu_rp_type','奖励','REWARD',1,'success','0',NULL,1,NOW()),
(154,'000000','edu_rp_type','惩罚','PUNISH',2,'danger','0',NULL,1,NOW()),
(155,'000000','edu_rp_category_reward','表扬','PRAISE',1,'success','0',NULL,1,NOW()),
(156,'000000','edu_rp_category_reward','进步奖','PROGRESS',2,'success','0',NULL,1,NOW()),
(157,'000000','edu_rp_category_reward','全勤奖','ATTENDANCE',3,'success','0',NULL,1,NOW()),
(158,'000000','edu_rp_category_reward','竞赛获奖','COMPETITION',4,'success','0',NULL,1,NOW()),
(159,'000000','edu_rp_category_punish','违纪','DISCIPLINE',1,'danger','0',NULL,1,NOW()),
(160,'000000','edu_rp_category_punish','迟到','LATE',2,'warning','0',NULL,1,NOW()),
(161,'000000','edu_rp_category_punish','旷课','ABSENT',3,'danger','0',NULL,1,NOW()),
(162,'000000','edu_rp_category_punish','缺交作业','NO_HOMEWORK',4,'warning','0',NULL,1,NOW()),
(163,'000000','edu_rp_category_punish','其他','OTHER',5,'info','0',NULL,1,NOW());

-- -----------------------------------------------------------------
-- 3. 菜单: 奖惩记录 (教务管理2000下, 菜单2300)
-- -----------------------------------------------------------------
DELETE FROM `sys_menu` WHERE menu_id IN (2300, 2310, 2311, 2312, 2313, 2314);
INSERT INTO `sys_menu`(`menu_id`,`menu_name`,`parent_id`,`order_num`,`path`,`component`,`query_param`,`is_frame`,`is_cache`,`menu_type`,`visible`,`status`,`perms`,`icon`,`create_dept`,`create_by`,`create_time`,`remark`) VALUES
(2300,'奖惩记录',2000,9,'reward','edu/reward/index',NULL,1,0,'C','0','0','edu:reward:list','star',NULL,1,NOW(),'学生奖惩记录管理'),
(2310,'奖惩查询',2300,1,'#','',NULL,1,0,'F','0','0','edu:reward:query','#',NULL,1,NOW(),''),
(2311,'奖惩新增',2300,2,'#','',NULL,1,0,'F','0','0','edu:reward:add','#',NULL,1,NOW(),''),
(2312,'奖惩修改',2300,3,'#','',NULL,1,0,'F','0','0','edu:reward:edit','#',NULL,1,NOW(),''),
(2313,'奖惩删除',2300,4,'#','',NULL,1,0,'F','0','0','edu:reward:remove','#',NULL,1,NOW(),''),
(2314,'奖惩导出',2300,5,'#','',NULL,1,0,'F','0','0','edu:reward:export','#',NULL,1,NOW(),'');
