Files
hzdyjs/docs/设计文档/database/学工管理-学生信息管理/11-class-cadre-management.sql
T
2025-07-19 10:18:27 +08:00

382 lines
18 KiB
SQL

-- ========================================
-- 班干部管理模块数据库设计
-- 文件:11-class-cadre-management.sql
-- 创建时间:2025-01-09
-- 说明:班级干部管理功能的完整数据表设计
-- ========================================
-- ----------------------------
-- 1. 班级干部信息表 (xg_class_cadre)
-- ----------------------------
DROP TABLE IF EXISTS `xg_class_cadre`;
CREATE TABLE `xg_class_cadre` (
-- 标准基础字段(必须)
`id` bigint(20) NOT NULL COMMENT '主键ID',
`tenant_id` varchar(20) NOT NULL DEFAULT '000000' COMMENT '租户编号',
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`deleted` tinyint(1) DEFAULT 0 COMMENT '删除标志(0代表存在 1代表删除)',
-- 基础关联信息
`class_id` bigint(20) NOT NULL COMMENT '班级ID,关联xg_class_info.id',
`student_id` bigint(20) NOT NULL COMMENT '学生ID,关联xg_student_info.id',
`student_no` varchar(32) NOT NULL COMMENT '学号',
`student_name` varchar(50) NOT NULL COMMENT '学生姓名(冗余字段)',
-- 职务信息
`position_code` varchar(20) NOT NULL COMMENT '职务编码:monitor-班长,deputy-副班长,secretary-学习委员等',
`position_name` varchar(50) NOT NULL COMMENT '职务名称',
`position_level` tinyint(1) NOT NULL DEFAULT 9 COMMENT '职务级别:1-班长,2-副班长,3-委员,9-普通成员',
`position_category` varchar(20) DEFAULT 'class' COMMENT '职务类别:class-班级干部,party-党团干部,other-其他',
-- 任期信息
`appointment_date` date NOT NULL COMMENT '任职日期',
`term_start_date` date NOT NULL COMMENT '任期开始日期',
`term_end_date` date DEFAULT NULL COMMENT '任期结束日期',
`term_duration` int(11) DEFAULT 12 COMMENT '任期时长(月)',
`is_current` tinyint(1) DEFAULT 1 COMMENT '是否现任:0-否,1-是',
-- 任职状态
`cadre_status` char(1) DEFAULT '1' COMMENT '任职状态:1-在任,2-到期,3-辞职,4-免职,5-调任',
`is_concurrent` tinyint(1) DEFAULT 0 COMMENT '是否兼职:0-否,1-是',
`concurrent_positions` varchar(200) DEFAULT NULL COMMENT '兼任职务列表(逗号分隔)',
-- 任免信息
`appointer_id` bigint(20) DEFAULT NULL COMMENT '任命人ID,关联sys_user.id',
`appointer_name` varchar(50) DEFAULT NULL COMMENT '任命人姓名',
`appointment_reason` varchar(200) DEFAULT NULL COMMENT '任命原因',
`appointment_document` varchar(200) DEFAULT NULL COMMENT '任命文件号',
-- 离任信息
`dismissal_date` date DEFAULT NULL COMMENT '离任日期',
`dismissal_reason` varchar(200) DEFAULT NULL COMMENT '离任原因',
`dismisser_id` bigint(20) DEFAULT NULL COMMENT '免职人ID,关联sys_user.id',
`dismisser_name` varchar(50) DEFAULT NULL COMMENT '免职人姓名',
`dismissal_document` varchar(200) DEFAULT NULL COMMENT '免职文件号',
-- 工作评价
`work_performance` varchar(20) DEFAULT NULL COMMENT '工作表现:excellent-优秀,good-良好,average-一般,poor-较差',
`performance_score` decimal(3,1) DEFAULT NULL COMMENT '表现评分(0-10分)',
`work_summary` text DEFAULT NULL COMMENT '工作总结',
`evaluation_comments` text DEFAULT NULL COMMENT '评价意见',
-- 权限配置
`permissions` text DEFAULT NULL COMMENT '权限配置(JSON格式)',
`system_roles` varchar(200) DEFAULT NULL COMMENT '系统角色列表(逗号分隔)',
`access_level` tinyint(1) DEFAULT 1 COMMENT '访问级别:1-基础,2-中级,3-高级',
-- 联系信息
`contact_phone` varchar(20) DEFAULT NULL COMMENT '联系电话',
`contact_email` varchar(100) DEFAULT NULL COMMENT '联系邮箱',
`emergency_contact` varchar(50) DEFAULT NULL COMMENT '紧急联系人',
`emergency_phone` varchar(20) DEFAULT NULL COMMENT '紧急联系电话',
-- 扩展信息
`work_plan` text DEFAULT NULL COMMENT '工作计划',
`achievements` text DEFAULT NULL COMMENT '主要成就',
`training_records` text DEFAULT NULL COMMENT '培训记录(JSON格式)',
`meeting_attendance` text DEFAULT NULL COMMENT '会议出席记录(JSON格式)',
-- 其他字段
`sort_order` int(11) DEFAULT 0 COMMENT '排序顺序',
`remark` varchar(500) DEFAULT NULL COMMENT '备注信息',
-- 主键和索引
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uk_class_student_position` (`class_id`, `student_id`, `position_code`, `tenant_id`),
KEY `idx_tenant_id` (`tenant_id`),
KEY `idx_deleted` (`deleted`),
KEY `idx_class_id` (`class_id`),
KEY `idx_student_id` (`student_id`),
KEY `idx_position_code` (`position_code`),
KEY `idx_position_level` (`position_level`),
KEY `idx_cadre_status` (`cadre_status`),
KEY `idx_is_current` (`is_current`),
KEY `idx_appointment_date` (`appointment_date`),
KEY `idx_term_dates` (`term_start_date`, `term_end_date`),
KEY `idx_class_position` (`class_id`, `position_code`, `is_current`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='班级干部信息表';
-- ----------------------------
-- 2. 班干部变更记录表 (xg_cadre_change_log)
-- ----------------------------
DROP TABLE IF EXISTS `xg_cadre_change_log`;
CREATE TABLE `xg_cadre_change_log` (
-- 标准基础字段(必须)
`id` bigint(20) NOT NULL COMMENT '主键ID',
`tenant_id` varchar(20) NOT NULL DEFAULT '000000' COMMENT '租户编号',
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`deleted` tinyint(1) DEFAULT 0 COMMENT '删除标志(0代表存在 1代表删除)',
-- 变更基础信息
`cadre_id` bigint(20) NOT NULL COMMENT '班干部ID,关联xg_class_cadre.id',
`class_id` bigint(20) NOT NULL COMMENT '班级ID,关联xg_class_info.id',
`student_id` bigint(20) NOT NULL COMMENT '学生ID,关联xg_student_info.id',
`student_no` varchar(32) NOT NULL COMMENT '学号',
`student_name` varchar(50) NOT NULL COMMENT '学生姓名',
-- 变更类型
`change_type` varchar(20) NOT NULL COMMENT '变更类型:appointment-任命,dismissal-免职,transfer-调任,renewal-续任,resignation-辞职',
`change_date` date NOT NULL COMMENT '变更日期',
`effective_date` date NOT NULL COMMENT '生效日期',
-- 职务变更信息
`old_position_code` varchar(20) DEFAULT NULL COMMENT '原职务编码',
`old_position_name` varchar(50) DEFAULT NULL COMMENT '原职务名称',
`new_position_code` varchar(20) DEFAULT NULL COMMENT '新职务编码',
`new_position_name` varchar(50) DEFAULT NULL COMMENT '新职务名称',
`position_change_reason` varchar(200) DEFAULT NULL COMMENT '职务变更原因',
-- 操作人信息
`operator_id` bigint(20) NOT NULL COMMENT '操作人ID,关联sys_user.id',
`operator_name` varchar(50) NOT NULL COMMENT '操作人姓名',
`operator_role` varchar(20) NOT NULL COMMENT '操作人角色:counselor-辅导员,teacher-班主任,admin-管理员',
`operator_dept` varchar(100) DEFAULT NULL COMMENT '操作人部门',
-- 审批信息
`need_approval` tinyint(1) DEFAULT 0 COMMENT '是否需要审批:0-否,1-是',
`approval_status` char(1) DEFAULT '1' COMMENT '审批状态:1-待审批,2-已通过,3-已驳回',
`approver_id` bigint(20) DEFAULT NULL COMMENT '审批人ID,关联sys_user.id',
`approver_name` varchar(50) DEFAULT NULL COMMENT '审批人姓名',
`approval_time` datetime DEFAULT NULL COMMENT '审批时间',
`approval_comments` varchar(500) DEFAULT NULL COMMENT '审批意见',
-- 变更详情
`change_reason` varchar(500) NOT NULL COMMENT '变更原因',
`change_description` text DEFAULT NULL COMMENT '变更描述',
`document_number` varchar(100) DEFAULT NULL COMMENT '文件编号',
`reference_documents` varchar(500) DEFAULT NULL COMMENT '参考文件',
-- 影响分析
`impact_analysis` text DEFAULT NULL COMMENT '影响分析',
`successor_id` bigint(20) DEFAULT NULL COMMENT '继任者ID,关联xg_student_info.id',
`successor_name` varchar(50) DEFAULT NULL COMMENT '继任者姓名',
`handover_status` char(1) DEFAULT '1' COMMENT '交接状态:1-未交接,2-交接中,3-已完成',
`handover_date` date DEFAULT NULL COMMENT '交接日期',
-- 其他信息
`is_emergency` tinyint(1) DEFAULT 0 COMMENT '是否紧急变更:0-否,1-是',
`notification_sent` tinyint(1) DEFAULT 0 COMMENT '是否已发送通知:0-否,1-是',
`attachment_ids` varchar(500) DEFAULT NULL COMMENT '附件ID列表(逗号分隔)',
`remark` varchar(500) DEFAULT NULL COMMENT '备注信息',
-- 主键和索引
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_tenant_id` (`tenant_id`),
KEY `idx_deleted` (`deleted`),
KEY `idx_cadre_id` (`cadre_id`),
KEY `idx_class_id` (`class_id`),
KEY `idx_student_id` (`student_id`),
KEY `idx_change_type` (`change_type`),
KEY `idx_change_date` (`change_date`),
KEY `idx_operator_id` (`operator_id`),
KEY `idx_approval_status` (`approval_status`),
KEY `idx_class_change` (`class_id`, `change_type`, `change_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='班干部变更记录表';
-- ----------------------------
-- 3. 班干部职务配置表 (xg_cadre_position_config)
-- ----------------------------
DROP TABLE IF EXISTS `xg_cadre_position_config`;
CREATE TABLE `xg_cadre_position_config` (
-- 标准基础字段(必须)
`id` bigint(20) NOT NULL COMMENT '主键ID',
`tenant_id` varchar(20) NOT NULL DEFAULT '000000' COMMENT '租户编号',
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`deleted` tinyint(1) DEFAULT 0 COMMENT '删除标志(0代表存在 1代表删除)',
-- 职务基础信息
`position_code` varchar(20) NOT NULL COMMENT '职务编码',
`position_name` varchar(50) NOT NULL COMMENT '职务名称',
`position_name_en` varchar(100) DEFAULT NULL COMMENT '职务英文名称',
`position_level` tinyint(1) NOT NULL COMMENT '职务级别:1-班长,2-副班长,3-委员,9-普通成员',
`position_category` varchar(20) DEFAULT 'class' COMMENT '职务类别:class-班级干部,party-党团干部,other-其他',
-- 职务配置
`max_count_per_class` int(11) DEFAULT 1 COMMENT '每班最大人数',
`min_count_per_class` int(11) DEFAULT 0 COMMENT '每班最小人数',
`is_required` tinyint(1) DEFAULT 0 COMMENT '是否必设:0-否,1-是',
`is_concurrent_allowed` tinyint(1) DEFAULT 0 COMMENT '是否允许兼职:0-否,1-是',
`default_term_months` int(11) DEFAULT 12 COMMENT '默认任期(月)',
-- 任职要求
`min_grade_requirement` varchar(10) DEFAULT NULL COMMENT '最低年级要求',
`academic_requirements` varchar(200) DEFAULT NULL COMMENT '学业要求',
`skill_requirements` text DEFAULT NULL COMMENT '技能要求',
`experience_requirements` text DEFAULT NULL COMMENT '经验要求',
-- 权限配置
`default_permissions` text DEFAULT NULL COMMENT '默认权限(JSON格式)',
`system_roles` varchar(200) DEFAULT NULL COMMENT '系统角色列表(逗号分隔)',
`access_level` tinyint(1) DEFAULT 1 COMMENT '访问级别:1-基础,2-中级,3-高级',
-- 职责描述
`responsibilities` text DEFAULT NULL COMMENT '职责描述',
`duties` text DEFAULT NULL COMMENT '具体职务',
`kpi_indicators` text DEFAULT NULL COMMENT 'KPI指标(JSON格式)',
`work_standards` text DEFAULT NULL COMMENT '工作标准',
-- 状态信息
`config_status` char(1) DEFAULT '1' COMMENT '配置状态:1-启用,2-禁用',
`is_system_position` tinyint(1) DEFAULT 0 COMMENT '是否系统职务:0-否,1-是',
`sort_order` int(11) DEFAULT 0 COMMENT '排序顺序',
-- 其他信息
`icon` varchar(100) DEFAULT NULL COMMENT '职务图标',
`color` varchar(20) DEFAULT NULL COMMENT '显示颜色',
`description` varchar(500) DEFAULT NULL COMMENT '职务描述',
`remark` varchar(500) DEFAULT NULL COMMENT '备注信息',
-- 主键和索引
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uk_position_code` (`position_code`, `tenant_id`),
KEY `idx_tenant_id` (`tenant_id`),
KEY `idx_deleted` (`deleted`),
KEY `idx_position_level` (`position_level`),
KEY `idx_position_category` (`position_category`),
KEY `idx_config_status` (`config_status`),
KEY `idx_sort_order` (`sort_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='班干部职务配置表';
-- ----------------------------
-- 4. 初始化职务配置数据
-- ----------------------------
INSERT INTO `xg_cadre_position_config` (
`id`, `tenant_id`, `position_code`, `position_name`, `position_level`, `position_category`,
`max_count_per_class`, `min_count_per_class`, `is_required`, `default_term_months`,
`responsibilities`, `duties`, `config_status`, `sort_order`,
`create_by`, `create_time`, `update_by`, `update_time`
) VALUES
-- 班级核心干部
(1200001, '000000', 'monitor', '班长', 1, 'class', 1, 1, 1, 12,
'负责班级全面工作,协调各项事务,组织班级活动',
'1.主持班会;2.协调班级事务;3.与老师沟通;4.组织班级活动;5.维护班级秩序',
'1', 1, 1, NOW(), 1, NOW()),
(1200002, '000000', 'deputy', '副班长', 2, 'class', 1, 0, 0, 12,
'协助班长工作,分担班级管理责任',
'1.协助班长工作;2.班长不在时代理工作;3.负责特定事务;4.维护班级纪律',
'1', 2, 1, NOW(), 1, NOW()),
(1200003, '000000', 'secretary', '学习委员', 3, 'class', 1, 0, 0, 12,
'负责班级学习相关事务,组织学习活动',
'1.收发作业;2.统计成绩;3.组织学习小组;4.联系任课老师;5.学习资料管理',
'1', 3, 1, NOW(), 1, NOW()),
(1200004, '000000', 'organizer', '组织委员', 3, 'class', 1, 0, 0, 12,
'负责班级组织建设和团队活动',
'1.组织班级活动;2.团队建设;3.党团工作;4.志愿服务组织',
'1', 4, 1, NOW(), 1, NOW()),
(1200005, '000000', 'publicity', '宣传委员', 3, 'class', 1, 0, 0, 12,
'负责班级宣传工作和文化建设',
'1.班级宣传;2.文化墙维护;3.新媒体运营;4.活动宣传;5.班级形象建设',
'1', 5, 1, NOW(), 1, NOW()),
(1200006, '000000', 'sports', '体育委员', 3, 'class', 1, 0, 0, 12,
'负责班级体育活动和健身锻炼',
'1.组织体育活动;2.体育器材管理;3.比赛报名;4.早操组织;5.健康促进',
'1', 6, 1, NOW(), 1, NOW()),
(1200007, '000000', 'life', '生活委员', 3, 'class', 1, 0, 0, 12,
'负责班级生活服务和后勤保障',
'1.生活用品采购;2.班费管理;3.卫生监督;4.生活问题解决;5.后勤协调',
'1', 7, 1, NOW(), 1, NOW()),
(1200008, '000000', 'culture', '文艺委员', 3, 'class', 1, 0, 0, 12,
'负责班级文艺活动和文化建设',
'1.文艺活动组织;2.节目策划;3.才艺展示;4.文化活动;5.艺术熏陶',
'1', 8, 1, NOW(), 1, NOW()),
(1200009, '000000', 'discipline', '纪律委员', 3, 'class', 1, 0, 0, 12,
'负责班级纪律管理和秩序维护',
'1.纪律监督;2.考勤统计;3.秩序维护;4.违纪处理;5.行为规范',
'1', 9, 1, NOW(), 1, NOW()),
(1200010, '000000', 'psychology', '心理委员', 3, 'class', 1, 0, 0, 12,
'负责班级心理健康和情感关怀',
'1.心理健康关注;2.情感疏导;3.危机预警;4.心理活动;5.同学关爱',
'1', 10, 1, NOW(), 1, NOW());
-- ----------------------------
-- 5. 创建相关索引优化
-- ----------------------------
-- 为班级干部表创建复合索引
CREATE INDEX `idx_class_cadre_active` ON `xg_class_cadre` (`class_id`, `is_current`, `cadre_status`, `position_level`);
CREATE INDEX `idx_class_cadre_term` ON `xg_class_cadre` (`term_start_date`, `term_end_date`, `is_current`);
CREATE INDEX `idx_class_cadre_student` ON `xg_class_cadre` (`student_id`, `is_current`, `cadre_status`);
-- 为变更记录表创建复合索引
CREATE INDEX `idx_change_log_timeline` ON `xg_cadre_change_log` (`change_date`, `change_type`, `approval_status`);
CREATE INDEX `idx_change_log_operator` ON `xg_cadre_change_log` (`operator_id`, `change_date`, `change_type`);
-- ----------------------------
-- 6. 创建视图简化查询
-- ----------------------------
-- 当前班干部视图
CREATE OR REPLACE VIEW `v_current_class_cadres` AS
SELECT
cc.id,
cc.class_id,
cc.student_id,
cc.student_no,
cc.student_name,
cc.position_code,
cc.position_name,
cc.position_level,
cc.appointment_date,
cc.term_start_date,
cc.term_end_date,
cc.cadre_status,
ci.class_code,
ci.class_name,
ci.college_name,
ci.grade,
pconfig.responsibilities,
pconfig.duties,
DATEDIFF(IFNULL(cc.term_end_date, DATE_ADD(cc.term_start_date, INTERVAL cc.term_duration MONTH)), CURDATE()) AS days_remaining
FROM xg_class_cadre cc
LEFT JOIN xg_class_info ci ON cc.class_id = ci.id
LEFT JOIN xg_cadre_position_config pconfig ON cc.position_code = pconfig.position_code
WHERE cc.is_current = 1
AND cc.cadre_status = '1'
AND cc.deleted = 0;
-- 班干部统计视图
CREATE OR REPLACE VIEW `v_class_cadre_statistics` AS
SELECT
ci.id AS class_id,
ci.class_code,
ci.class_name,
ci.college_name,
ci.grade,
COUNT(cc.id) AS total_cadres,
COUNT(CASE WHEN cc.position_level = 1 THEN 1 END) AS monitor_count,
COUNT(CASE WHEN cc.position_level = 2 THEN 1 END) AS deputy_count,
COUNT(CASE WHEN cc.position_level = 3 THEN 1 END) AS committee_count,
COUNT(CASE WHEN cc.cadre_status = '1' THEN 1 END) AS active_count,
COUNT(CASE WHEN cc.term_end_date < CURDATE() THEN 1 END) AS expired_count
FROM xg_class_info ci
LEFT JOIN xg_class_cadre cc ON ci.id = cc.class_id AND cc.is_current = 1 AND cc.deleted = 0
WHERE ci.deleted = 0
GROUP BY ci.id, ci.class_code, ci.class_name, ci.college_name, ci.grade;
-- ----------------------------
-- 执行完成提示
-- ----------------------------
SELECT '班干部管理模块数据表创建完成!' AS message,
'包含: 班级干部信息表、变更记录表、职务配置表' AS tables,
'包含: 10个预设职务配置、2个查询视图' AS features;