717 lines
39 KiB
SQL
717 lines
39 KiB
SQL
-- =============================================
|
||
-- 学生信息管理系统数据库设计
|
||
-- 创建时间: 2025-01-12
|
||
-- 版本: v1.0
|
||
-- 说明: 学生信息管理系统完整数据库设计
|
||
-- =============================================
|
||
|
||
-- 1. 学年管理表
|
||
DROP TABLE IF EXISTS `xg_academic_year`;
|
||
CREATE TABLE `xg_academic_year` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`year_code` varchar(20) NOT NULL COMMENT '学年编码,如2024-2025',
|
||
`year_name` varchar(50) NOT NULL COMMENT '学年名称,如2024-2025学年',
|
||
`start_date` date NOT NULL COMMENT '学年开始日期',
|
||
`end_date` date NOT NULL COMMENT '学年结束日期',
|
||
`is_current` tinyint(1) DEFAULT 0 COMMENT '是否当前学年:0-否,1-是',
|
||
`status` varchar(20) DEFAULT 'active' COMMENT '状态:active-有效,inactive-无效',
|
||
`description` text COMMENT '学年描述',
|
||
`sort_order` int(11) DEFAULT 0 COMMENT '排序字段',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
UNIQUE KEY `uk_year_code` (`year_code`, `tenant_id`, `deleted`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE,
|
||
KEY `idx_is_current` (`is_current`) USING BTREE,
|
||
KEY `idx_status` (`status`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学年管理表';
|
||
|
||
-- 2. 学期管理表
|
||
DROP TABLE IF EXISTS `xg_semester`;
|
||
CREATE TABLE `xg_semester` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`academic_year_id` bigint(20) NOT NULL COMMENT '学年ID,关联xg_academic_year.id',
|
||
`semester_code` varchar(20) NOT NULL COMMENT '学期编码,如2024-2025-1',
|
||
`semester_name` varchar(50) NOT NULL COMMENT '学期名称,如2024-2025学年第一学期',
|
||
`semester_type` varchar(20) NOT NULL COMMENT '学期类型:first-第一学期,second-第二学期,summer-暑期',
|
||
`start_date` date NOT NULL COMMENT '学期开始日期',
|
||
`end_date` date NOT NULL COMMENT '学期结束日期',
|
||
`is_current` tinyint(1) DEFAULT 0 COMMENT '是否当前学期:0-否,1-是',
|
||
`status` varchar(20) DEFAULT 'active' COMMENT '状态:active-有效,inactive-无效',
|
||
`description` text COMMENT '学期描述',
|
||
`sort_order` int(11) DEFAULT 0 COMMENT '排序字段',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
UNIQUE KEY `uk_semester_code` (`semester_code`, `tenant_id`, `deleted`) USING BTREE,
|
||
KEY `idx_academic_year_id` (`academic_year_id`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE,
|
||
KEY `idx_is_current` (`is_current`) USING BTREE,
|
||
KEY `idx_status` (`status`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学期管理表';
|
||
|
||
-- 3. 业务期管理表
|
||
DROP TABLE IF EXISTS `xg_business_period`;
|
||
CREATE TABLE `xg_business_period` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`period_code` varchar(50) NOT NULL COMMENT '业务期编码',
|
||
`period_name` varchar(100) NOT NULL COMMENT '业务期名称',
|
||
`period_type` varchar(20) NOT NULL COMMENT '业务期类型:collection-信息采集期,audit-审核期,confirm-确认期',
|
||
`academic_year_id` bigint(20) DEFAULT NULL COMMENT '关联学年ID',
|
||
`semester_id` bigint(20) DEFAULT NULL COMMENT '关联学期ID',
|
||
`start_time` datetime NOT NULL COMMENT '业务期开始时间',
|
||
`end_time` datetime NOT NULL COMMENT '业务期结束时间',
|
||
`status` varchar(20) DEFAULT 'not_started' COMMENT '状态:not_started-未开始,in_progress-进行中,ended-已结束,suspended-已暂停',
|
||
`auto_start` tinyint(1) DEFAULT 0 COMMENT '是否自动开始:0-否,1-是',
|
||
`auto_end` tinyint(1) DEFAULT 0 COMMENT '是否自动结束:0-否,1-是',
|
||
`description` text COMMENT '业务期描述',
|
||
`notice_content` text COMMENT '通知内容',
|
||
`sort_order` int(11) DEFAULT 0 COMMENT '排序字段',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
UNIQUE KEY `uk_period_code` (`period_code`, `tenant_id`, `deleted`) USING BTREE,
|
||
KEY `idx_academic_year_id` (`academic_year_id`) USING BTREE,
|
||
KEY `idx_semester_id` (`semester_id`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE,
|
||
KEY `idx_status` (`status`) USING BTREE,
|
||
KEY `idx_period_type` (`period_type`) USING BTREE,
|
||
KEY `idx_time_range` (`start_time`, `end_time`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='业务期管理表';
|
||
|
||
-- 4. 信息采集批次表(完善版)
|
||
DROP TABLE IF EXISTS `xg_collection_batch`;
|
||
CREATE TABLE `xg_collection_batch` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`batch_code` varchar(50) NOT NULL COMMENT '批次编码',
|
||
`batch_name` varchar(100) NOT NULL COMMENT '批次名称',
|
||
`academic_year_id` bigint(20) NOT NULL COMMENT '关联学年ID',
|
||
`semester_id` bigint(20) DEFAULT NULL COMMENT '关联学期ID',
|
||
`business_period_id` bigint(20) DEFAULT NULL COMMENT '关联业务期ID',
|
||
`batch_type` varchar(20) DEFAULT 'regular' COMMENT '批次类型:regular-常规,special-专项,urgent-紧急',
|
||
`target_scope` varchar(20) DEFAULT 'all' COMMENT '目标范围:all-全部,college-学院,class-班级,student-个人',
|
||
`target_ids` text COMMENT '目标ID列表(JSON格式),当target_scope不为all时使用',
|
||
`start_time` datetime NOT NULL COMMENT '批次开始时间',
|
||
`end_time` datetime NOT NULL COMMENT '批次结束时间',
|
||
`status` varchar(20) DEFAULT 'draft' COMMENT '状态:draft-草稿,active-进行中,completed-已完成,cancelled-已取消',
|
||
`is_published` tinyint(1) DEFAULT 0 COMMENT '是否已发布:0-否,1-是',
|
||
`publish_time` datetime DEFAULT NULL COMMENT '发布时间',
|
||
`auto_remind` tinyint(1) DEFAULT 1 COMMENT '是否自动提醒:0-否,1-是',
|
||
`remind_days` int(11) DEFAULT 3 COMMENT '提醒天数(结束前几天提醒)',
|
||
`description` text COMMENT '批次描述',
|
||
`notice_content` text COMMENT '通知内容',
|
||
`completion_rate` decimal(5,2) DEFAULT 0.00 COMMENT '完成率',
|
||
`total_count` int(11) DEFAULT 0 COMMENT '总人数',
|
||
`completed_count` int(11) DEFAULT 0 COMMENT '已完成人数',
|
||
`sort_order` int(11) DEFAULT 0 COMMENT '排序字段',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
UNIQUE KEY `uk_batch_code` (`batch_code`, `tenant_id`, `deleted`) USING BTREE,
|
||
KEY `idx_academic_year_id` (`academic_year_id`) USING BTREE,
|
||
KEY `idx_semester_id` (`semester_id`) USING BTREE,
|
||
KEY `idx_business_period_id` (`business_period_id`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE,
|
||
KEY `idx_status` (`status`) USING BTREE,
|
||
KEY `idx_time_range` (`start_time`, `end_time`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='信息采集批次表';
|
||
|
||
-- 5. 批次权限配置表
|
||
DROP TABLE IF EXISTS `xg_batch_permission`;
|
||
CREATE TABLE `xg_batch_permission` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`batch_id` bigint(20) NOT NULL COMMENT '批次ID,关联xg_collection_batch.id',
|
||
`user_type` varchar(20) NOT NULL COMMENT '用户类型:student-学生,counselor-辅导员,head_teacher-班主任,college_admin-学院管理员,dept_admin-学生处管理员',
|
||
`permission_type` varchar(20) NOT NULL COMMENT '权限类型:read-查看,write-编辑,audit-审核,manage-管理',
|
||
`scope_type` varchar(20) DEFAULT 'all' COMMENT '权限范围:all-全部,college-学院,class-班级,self-本人',
|
||
`scope_ids` text COMMENT '权限范围ID列表(JSON格式)',
|
||
`start_time` datetime DEFAULT NULL COMMENT '权限开始时间',
|
||
`end_time` datetime DEFAULT NULL COMMENT '权限结束时间',
|
||
`is_active` tinyint(1) DEFAULT 1 COMMENT '是否激活:0-否,1-是',
|
||
`description` varchar(500) DEFAULT NULL COMMENT '权限描述',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
KEY `idx_batch_id` (`batch_id`) USING BTREE,
|
||
KEY `idx_user_type` (`user_type`) USING BTREE,
|
||
KEY `idx_permission_type` (`permission_type`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE,
|
||
KEY `idx_time_range` (`start_time`, `end_time`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='批次权限配置表';
|
||
|
||
-- 6. 学生信息表(完善版)
|
||
DROP TABLE IF EXISTS `xg_student_info`;
|
||
CREATE TABLE `xg_student_info` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`student_no` varchar(32) NOT NULL COMMENT '学号',
|
||
`name` varchar(50) NOT NULL COMMENT '姓名',
|
||
`gender` char(1) DEFAULT NULL COMMENT '性别:M-男,F-女',
|
||
`birth_date` date DEFAULT NULL COMMENT '出生日期',
|
||
`id_card` varchar(18) DEFAULT NULL COMMENT '身份证号',
|
||
`nation` varchar(20) DEFAULT NULL COMMENT '民族',
|
||
`political_status` varchar(20) DEFAULT NULL COMMENT '政治面貌',
|
||
`religion` varchar(20) DEFAULT NULL COMMENT '宗教信仰',
|
||
`phone` varchar(20) DEFAULT NULL COMMENT '手机号',
|
||
`email` varchar(100) DEFAULT NULL COMMENT '邮箱',
|
||
`home_address` varchar(200) DEFAULT NULL COMMENT '家庭地址',
|
||
`postal_code` varchar(10) DEFAULT NULL COMMENT '邮政编码',
|
||
`emergency_contact` varchar(50) DEFAULT NULL COMMENT '紧急联系人',
|
||
`emergency_phone` varchar(20) DEFAULT NULL COMMENT '紧急联系电话',
|
||
`height` decimal(5,2) DEFAULT NULL COMMENT '身高(厘米)',
|
||
`weight` decimal(5,2) DEFAULT NULL COMMENT '体重(公斤)',
|
||
`blood_type` varchar(10) DEFAULT NULL COMMENT '血型',
|
||
`health_status` varchar(20) DEFAULT NULL COMMENT '健康状况',
|
||
`bank_card` varchar(30) DEFAULT NULL COMMENT '银行卡号',
|
||
`bank_name` varchar(100) DEFAULT NULL COMMENT '开户行',
|
||
`card_holder` varchar(50) DEFAULT NULL COMMENT '持卡人姓名',
|
||
`photo_url` varchar(200) DEFAULT NULL COMMENT '照片URL',
|
||
`specialties` text COMMENT '特长',
|
||
`college_id` bigint(20) DEFAULT NULL COMMENT '学院ID',
|
||
`college_name` varchar(100) DEFAULT NULL COMMENT '学院名称',
|
||
`major` varchar(100) DEFAULT NULL COMMENT '专业',
|
||
`class_id` bigint(20) DEFAULT NULL COMMENT '班级ID',
|
||
`class_name` varchar(100) DEFAULT NULL COMMENT '班级名称',
|
||
`grade` varchar(10) DEFAULT NULL COMMENT '年级',
|
||
`enrollment_date` date DEFAULT NULL COMMENT '入学日期',
|
||
`education_length` int(11) DEFAULT NULL COMMENT '学制(年)',
|
||
`student_status` varchar(20) DEFAULT 'active' COMMENT '学籍状态:active-在读,graduated-已毕业,dropout-退学,suspended-休学',
|
||
`training_mode` varchar(20) DEFAULT NULL COMMENT '培养方式:full_time-全日制,part_time-非全日制',
|
||
`current_batch_id` bigint(20) DEFAULT NULL COMMENT '当前批次ID',
|
||
`info_status` varchar(20) DEFAULT 'draft' COMMENT '信息状态:draft-草稿,submitted-已提交,approved-已审核',
|
||
`last_submit_time` datetime DEFAULT NULL COMMENT '最后提交时间',
|
||
`last_audit_time` datetime DEFAULT NULL COMMENT '最后审核时间',
|
||
`audit_comment` text COMMENT '审核意见',
|
||
`version` int(11) DEFAULT 1 COMMENT '版本号',
|
||
`sort_order` int(11) DEFAULT 0 COMMENT '排序字段',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
UNIQUE KEY `uk_student_no` (`student_no`, `tenant_id`, `deleted`) USING BTREE,
|
||
KEY `idx_class_id` (`class_id`) USING BTREE,
|
||
KEY `idx_college_id` (`college_id`) USING BTREE,
|
||
KEY `idx_current_batch_id` (`current_batch_id`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE,
|
||
KEY `idx_info_status` (`info_status`) USING BTREE,
|
||
KEY `idx_student_status` (`student_status`) USING BTREE,
|
||
KEY `idx_name` (`name`) USING BTREE,
|
||
KEY `idx_id_card` (`id_card`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学生信息表';
|
||
|
||
-- 7. 学生信息变更记录表
|
||
DROP TABLE IF EXISTS `xg_student_info_history`;
|
||
CREATE TABLE `xg_student_info_history` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`student_id` bigint(20) NOT NULL COMMENT '学生ID,关联xg_student_info.id',
|
||
`batch_id` bigint(20) DEFAULT NULL COMMENT '批次ID',
|
||
`change_type` varchar(20) NOT NULL COMMENT '变更类型:create-新增,update-修改,delete-删除',
|
||
`change_fields` text COMMENT '变更字段列表(JSON格式)',
|
||
`old_values` text COMMENT '变更前数据(JSON格式)',
|
||
`new_values` text COMMENT '变更后数据(JSON格式)',
|
||
`change_reason` varchar(500) DEFAULT NULL COMMENT '变更原因',
|
||
`change_time` datetime NOT NULL COMMENT '变更时间',
|
||
`change_by` bigint(20) DEFAULT NULL COMMENT '变更人',
|
||
`change_by_name` varchar(50) DEFAULT NULL COMMENT '变更人姓名',
|
||
`ip_address` varchar(50) DEFAULT NULL COMMENT 'IP地址',
|
||
`user_agent` varchar(500) DEFAULT NULL COMMENT '用户代理',
|
||
`version` int(11) DEFAULT 1 COMMENT '版本号',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
KEY `idx_student_id` (`student_id`) USING BTREE,
|
||
KEY `idx_batch_id` (`batch_id`) USING BTREE,
|
||
KEY `idx_change_type` (`change_type`) USING BTREE,
|
||
KEY `idx_change_time` (`change_time`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学生信息变更记录表';
|
||
|
||
-- 8. 审核记录表(完善版)
|
||
DROP TABLE IF EXISTS `xg_audit_record`;
|
||
CREATE TABLE `xg_audit_record` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`student_id` bigint(20) NOT NULL COMMENT '学生ID,关联xg_student_info.id',
|
||
`batch_id` bigint(20) NOT NULL COMMENT '批次ID,关联xg_collection_batch.id',
|
||
`audit_level` int(11) NOT NULL COMMENT '审核级别:1-初审,2-复审,3-终审',
|
||
`audit_type` varchar(20) NOT NULL COMMENT '审核类型:submit-提交,approve-通过,reject-拒绝,return-退回',
|
||
`audit_status` varchar(20) NOT NULL COMMENT '审核状态:pending-待审核,approved-已通过,rejected-已拒绝',
|
||
`auditor_id` bigint(20) DEFAULT NULL COMMENT '审核人ID',
|
||
`auditor_name` varchar(50) DEFAULT NULL COMMENT '审核人姓名',
|
||
`auditor_role` varchar(20) DEFAULT NULL COMMENT '审核人角色',
|
||
`audit_time` datetime NOT NULL COMMENT '审核时间',
|
||
`audit_comment` text COMMENT '审核意见',
|
||
`changed_fields` text COMMENT '变更字段(JSON格式)',
|
||
`next_auditor_id` bigint(20) DEFAULT NULL COMMENT '下一审核人ID',
|
||
`next_auditor_name` varchar(50) DEFAULT NULL COMMENT '下一审核人姓名',
|
||
`is_final` tinyint(1) DEFAULT 0 COMMENT '是否最终审核:0-否,1-是',
|
||
`process_duration` int(11) DEFAULT NULL COMMENT '处理时长(分钟)',
|
||
`ip_address` varchar(50) DEFAULT NULL COMMENT 'IP地址',
|
||
`user_agent` varchar(500) DEFAULT NULL COMMENT '用户代理',
|
||
`attachment_urls` text COMMENT '附件URL列表(JSON格式)',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
KEY `idx_student_id` (`student_id`) USING BTREE,
|
||
KEY `idx_batch_id` (`batch_id`) USING BTREE,
|
||
KEY `idx_audit_level` (`audit_level`) USING BTREE,
|
||
KEY `idx_audit_status` (`audit_status`) USING BTREE,
|
||
KEY `idx_auditor_id` (`auditor_id`) USING BTREE,
|
||
KEY `idx_audit_time` (`audit_time`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审核记录表';
|
||
|
||
-- 9. 通知公告表
|
||
DROP TABLE IF EXISTS `xg_notice`;
|
||
CREATE TABLE `xg_notice` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`notice_code` varchar(50) DEFAULT NULL COMMENT '通知编码',
|
||
`title` varchar(200) NOT NULL COMMENT '通知标题',
|
||
`content` text NOT NULL COMMENT '通知内容',
|
||
`notice_type` varchar(20) NOT NULL COMMENT '通知类型:batch-批次通知,audit-审核通知,remind-提醒通知,system-系统通知',
|
||
`priority` varchar(20) DEFAULT 'normal' COMMENT '优先级:low-低,normal-普通,high-高,urgent-紧急',
|
||
`target_type` varchar(20) DEFAULT 'all' COMMENT '目标类型:all-全部,role-角色,user-用户,college-学院,class-班级',
|
||
`target_ids` text COMMENT '目标ID列表(JSON格式)',
|
||
`related_id` bigint(20) DEFAULT NULL COMMENT '关联ID(如批次ID、审核ID等)',
|
||
`related_type` varchar(20) DEFAULT NULL COMMENT '关联类型:batch-批次,audit-审核,student-学生',
|
||
`publish_time` datetime DEFAULT NULL COMMENT '发布时间',
|
||
`expire_time` datetime DEFAULT NULL COMMENT '过期时间',
|
||
`is_published` tinyint(1) DEFAULT 0 COMMENT '是否已发布:0-否,1-是',
|
||
`is_top` tinyint(1) DEFAULT 0 COMMENT '是否置顶:0-否,1-是',
|
||
`read_count` int(11) DEFAULT 0 COMMENT '阅读次数',
|
||
`attachment_urls` text COMMENT '附件URL列表(JSON格式)',
|
||
`auto_send` tinyint(1) DEFAULT 0 COMMENT '是否自动发送:0-否,1-是',
|
||
`send_channels` varchar(100) DEFAULT 'web' COMMENT '发送渠道:web-网页,email-邮件,sms-短信,wechat-微信',
|
||
`status` varchar(20) DEFAULT 'draft' COMMENT '状态:draft-草稿,published-已发布,expired-已过期,cancelled-已取消',
|
||
`sort_order` int(11) DEFAULT 0 COMMENT '排序字段',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
KEY `idx_notice_type` (`notice_type`) USING BTREE,
|
||
KEY `idx_target_type` (`target_type`) USING BTREE,
|
||
KEY `idx_related_id` (`related_id`) USING BTREE,
|
||
KEY `idx_related_type` (`related_type`) USING BTREE,
|
||
KEY `idx_publish_time` (`publish_time`) USING BTREE,
|
||
KEY `idx_status` (`status`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='通知公告表';
|
||
|
||
-- 10. 通知阅读记录表
|
||
DROP TABLE IF EXISTS `xg_notice_read`;
|
||
CREATE TABLE `xg_notice_read` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`notice_id` bigint(20) NOT NULL COMMENT '通知ID,关联xg_notice.id',
|
||
`user_id` bigint(20) NOT NULL COMMENT '用户ID',
|
||
`user_name` varchar(50) DEFAULT NULL COMMENT '用户姓名',
|
||
`user_type` varchar(20) DEFAULT NULL COMMENT '用户类型',
|
||
`read_time` datetime NOT NULL COMMENT '阅读时间',
|
||
`read_duration` int(11) DEFAULT NULL COMMENT '阅读时长(秒)',
|
||
`ip_address` varchar(50) DEFAULT NULL COMMENT 'IP地址',
|
||
`user_agent` varchar(500) DEFAULT NULL COMMENT '用户代理',
|
||
`device_type` varchar(20) DEFAULT NULL COMMENT '设备类型:pc-电脑,mobile-手机,tablet-平板',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
UNIQUE KEY `uk_notice_user` (`notice_id`, `user_id`, `tenant_id`, `deleted`) USING BTREE,
|
||
KEY `idx_user_id` (`user_id`) USING BTREE,
|
||
KEY `idx_read_time` (`read_time`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='通知阅读记录表';
|
||
|
||
-- 11. 系统配置表
|
||
DROP TABLE IF EXISTS `xg_system_config`;
|
||
CREATE TABLE `xg_system_config` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`config_key` varchar(100) NOT NULL COMMENT '配置键',
|
||
`config_value` text COMMENT '配置值',
|
||
`config_type` varchar(20) DEFAULT 'string' COMMENT '配置类型:string-字符串,number-数字,boolean-布尔,json-JSON',
|
||
`config_group` varchar(50) DEFAULT 'system' COMMENT '配置分组',
|
||
`config_desc` varchar(200) DEFAULT NULL COMMENT '配置描述',
|
||
`is_system` tinyint(1) DEFAULT 0 COMMENT '是否系统配置:0-否,1-是',
|
||
`is_readonly` tinyint(1) DEFAULT 0 COMMENT '是否只读:0-否,1-是',
|
||
`sort_order` int(11) DEFAULT 0 COMMENT '排序字段',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
UNIQUE KEY `uk_config_key` (`config_key`, `tenant_id`, `deleted`) USING BTREE,
|
||
KEY `idx_config_group` (`config_group`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统配置表';
|
||
|
||
-- 12. 数据字典表
|
||
DROP TABLE IF EXISTS `xg_dict_data`;
|
||
CREATE TABLE `xg_dict_data` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID',
|
||
`dict_type` varchar(100) NOT NULL COMMENT '字典类型',
|
||
`dict_label` varchar(100) NOT NULL COMMENT '字典标签',
|
||
`dict_value` varchar(100) NOT NULL COMMENT '字典键值',
|
||
`dict_sort` int(11) DEFAULT 0 COMMENT '字典排序',
|
||
`css_class` varchar(100) DEFAULT NULL COMMENT '样式属性',
|
||
`list_class` varchar(100) DEFAULT NULL COMMENT '表格回显样式',
|
||
`is_default` tinyint(1) DEFAULT 0 COMMENT '是否默认:0-否,1-是',
|
||
`status` char(1) DEFAULT '0' COMMENT '状态:0-正常,1-停用',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||
-- 基础字段
|
||
`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代表删除)',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
KEY `idx_dict_type` (`dict_type`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`) USING BTREE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='数据字典表';
|
||
|
||
-- =============================================
|
||
-- 初始化数据
|
||
-- =============================================
|
||
|
||
-- 1. 初始化学年数据
|
||
INSERT INTO `xg_academic_year` (`id`, `year_code`, `year_name`, `start_date`, `end_date`, `is_current`, `status`, `description`, `tenant_id`, `create_time`) VALUES
|
||
(1, '2024-2025', '2024-2025学年', '2024-09-01', '2025-08-31', 1, 'active', '2024-2025学年', '000000', NOW()),
|
||
(2, '2023-2024', '2023-2024学年', '2023-09-01', '2024-08-31', 0, 'inactive', '2023-2024学年', '000000', NOW()),
|
||
(3, '2025-2026', '2025-2026学年', '2025-09-01', '2026-08-31', 0, 'active', '2025-2026学年', '000000', NOW());
|
||
|
||
-- 2. 初始化学期数据
|
||
INSERT INTO `xg_semester` (`id`, `academic_year_id`, `semester_code`, `semester_name`, `semester_type`, `start_date`, `end_date`, `is_current`, `status`, `tenant_id`, `create_time`) VALUES
|
||
(1, 1, '2024-2025-1', '2024-2025学年第一学期', 'first', '2024-09-01', '2025-01-31', 0, 'active', '000000', NOW()),
|
||
(2, 1, '2024-2025-2', '2024-2025学年第二学期', 'second', '2025-02-01', '2025-08-31', 1, 'active', '000000', NOW()),
|
||
(3, 2, '2023-2024-1', '2023-2024学年第一学期', 'first', '2023-09-01', '2024-01-31', 0, 'inactive', '000000', NOW()),
|
||
(4, 2, '2023-2024-2', '2023-2024学年第二学期', 'second', '2024-02-01', '2024-08-31', 0, 'inactive', '000000', NOW());
|
||
|
||
-- 3. 初始化数据字典
|
||
INSERT INTO `xg_dict_data` (`id`, `dict_type`, `dict_label`, `dict_value`, `dict_sort`, `status`, `tenant_id`, `create_time`) VALUES
|
||
-- 性别
|
||
(1, 'xg_gender', '男', 'M', 1, '0', '000000', NOW()),
|
||
(2, 'xg_gender', '女', 'F', 2, '0', '000000', NOW()),
|
||
-- 政治面貌
|
||
(3, 'xg_political_status', '中共党员', 'party_member', 1, '0', '000000', NOW()),
|
||
(4, 'xg_political_status', '中共预备党员', 'party_probationary', 2, '0', '000000', NOW()),
|
||
(5, 'xg_political_status', '共青团员', 'youth_league', 3, '0', '000000', NOW()),
|
||
(6, 'xg_political_status', '群众', 'masses', 4, '0', '000000', NOW()),
|
||
-- 学籍状态
|
||
(7, 'xg_student_status', '在读', 'active', 1, '0', '000000', NOW()),
|
||
(8, 'xg_student_status', '已毕业', 'graduated', 2, '0', '000000', NOW()),
|
||
(9, 'xg_student_status', '退学', 'dropout', 3, '0', '000000', NOW()),
|
||
(10, 'xg_student_status', '休学', 'suspended', 4, '0', '000000', NOW()),
|
||
-- 信息状态
|
||
(11, 'xg_info_status', '草稿', 'draft', 1, '0', '000000', NOW()),
|
||
(12, 'xg_info_status', '已提交', 'submitted', 2, '0', '000000', NOW()),
|
||
(13, 'xg_info_status', '已审核', 'approved', 3, '0', '000000', NOW()),
|
||
-- 批次状态
|
||
(14, 'xg_batch_status', '草稿', 'draft', 1, '0', '000000', NOW()),
|
||
(15, 'xg_batch_status', '进行中', 'active', 2, '0', '000000', NOW()),
|
||
(16, 'xg_batch_status', '已完成', 'completed', 3, '0', '000000', NOW()),
|
||
(17, 'xg_batch_status', '已取消', 'cancelled', 4, '0', '000000', NOW()),
|
||
-- 用户类型
|
||
(18, 'xg_user_type', '学生', 'student', 1, '0', '000000', NOW()),
|
||
(19, 'xg_user_type', '辅导员', 'counselor', 2, '0', '000000', NOW()),
|
||
(20, 'xg_user_type', '班主任', 'head_teacher', 3, '0', '000000', NOW()),
|
||
(21, 'xg_user_type', '学院管理员', 'college_admin', 4, '0', '000000', NOW()),
|
||
(22, 'xg_user_type', '学生处管理员', 'dept_admin', 5, '0', '000000', NOW()),
|
||
-- 权限类型
|
||
(23, 'xg_permission_type', '查看', 'read', 1, '0', '000000', NOW()),
|
||
(24, 'xg_permission_type', '编辑', 'write', 2, '0', '000000', NOW()),
|
||
(25, 'xg_permission_type', '审核', 'audit', 3, '0', '000000', NOW()),
|
||
(26, 'xg_permission_type', '管理', 'manage', 4, '0', '000000', NOW()),
|
||
-- 业务期类型
|
||
(27, 'xg_period_type', '信息采集期', 'collection', 1, '0', '000000', NOW()),
|
||
(28, 'xg_period_type', '审核期', 'audit', 2, '0', '000000', NOW()),
|
||
(29, 'xg_period_type', '确认期', 'confirm', 3, '0', '000000', NOW()),
|
||
-- 通知类型
|
||
(30, 'xg_notice_type', '批次通知', 'batch', 1, '0', '000000', NOW()),
|
||
(31, 'xg_notice_type', '审核通知', 'audit', 2, '0', '000000', NOW()),
|
||
(32, 'xg_notice_type', '提醒通知', 'remind', 3, '0', '000000', NOW()),
|
||
(33, 'xg_notice_type', '系统通知', 'system', 4, '0', '000000', NOW());
|
||
|
||
-- 4. 初始化系统配置
|
||
INSERT INTO `xg_system_config` (`id`, `config_key`, `config_value`, `config_type`, `config_group`, `config_desc`, `tenant_id`, `create_time`) VALUES
|
||
(1, 'xg.batch.auto.remind.days', '3', 'number', 'batch', '批次自动提醒天数', '000000', NOW()),
|
||
(2, 'xg.audit.max.level', '3', 'number', 'audit', '最大审核级别', '000000', NOW()),
|
||
(3, 'xg.student.photo.max.size', '5', 'number', 'student', '学生照片最大尺寸(MB)', '000000', NOW()),
|
||
(4, 'xg.notice.auto.expire.days', '30', 'number', 'notice', '通知自动过期天数', '000000', NOW()),
|
||
(5, 'xg.system.name', '学生信息管理系统', 'string', 'system', '系统名称', '000000', NOW());
|
||
|
||
-- =============================================
|
||
-- 创建视图
|
||
-- =============================================
|
||
|
||
-- 1. 学生信息汇总视图
|
||
CREATE OR REPLACE VIEW `v_xg_student_summary` AS
|
||
SELECT
|
||
s.id,
|
||
s.student_no,
|
||
s.name,
|
||
s.gender,
|
||
s.phone,
|
||
s.email,
|
||
s.college_name,
|
||
s.major,
|
||
s.class_name,
|
||
s.grade,
|
||
s.student_status,
|
||
s.info_status,
|
||
s.last_submit_time,
|
||
s.last_audit_time,
|
||
b.batch_name AS current_batch_name,
|
||
b.status AS batch_status,
|
||
ay.year_name AS academic_year_name,
|
||
sem.semester_name AS semester_name,
|
||
s.create_time,
|
||
s.update_time
|
||
FROM xg_student_info s
|
||
LEFT JOIN xg_collection_batch b ON s.current_batch_id = b.id
|
||
LEFT JOIN xg_academic_year ay ON b.academic_year_id = ay.id
|
||
LEFT JOIN xg_semester sem ON b.semester_id = sem.id
|
||
WHERE s.deleted = 0;
|
||
|
||
-- 2. 批次统计视图
|
||
CREATE OR REPLACE VIEW `v_xg_batch_statistics` AS
|
||
SELECT
|
||
b.id,
|
||
b.batch_code,
|
||
b.batch_name,
|
||
b.start_time,
|
||
b.end_time,
|
||
b.status,
|
||
b.total_count,
|
||
b.completed_count,
|
||
b.completion_rate,
|
||
ay.year_name AS academic_year_name,
|
||
sem.semester_name AS semester_name,
|
||
COUNT(DISTINCT s.id) AS actual_student_count,
|
||
COUNT(DISTINCT CASE WHEN s.info_status = 'submitted' THEN s.id END) AS submitted_count,
|
||
COUNT(DISTINCT CASE WHEN s.info_status = 'approved' THEN s.id END) AS approved_count,
|
||
ROUND(COUNT(DISTINCT CASE WHEN s.info_status IN ('submitted', 'approved') THEN s.id END) * 100.0 / COUNT(DISTINCT s.id), 2) AS actual_completion_rate
|
||
FROM xg_collection_batch b
|
||
LEFT JOIN xg_academic_year ay ON b.academic_year_id = ay.id
|
||
LEFT JOIN xg_semester sem ON b.semester_id = sem.id
|
||
LEFT JOIN xg_student_info s ON s.current_batch_id = b.id AND s.deleted = 0
|
||
WHERE b.deleted = 0
|
||
GROUP BY b.id, b.batch_code, b.batch_name, b.start_time, b.end_time, b.status, b.total_count, b.completed_count, b.completion_rate, ay.year_name, sem.semester_name;
|
||
|
||
-- =============================================
|
||
-- 创建索引优化
|
||
-- =============================================
|
||
|
||
-- 复合索引优化
|
||
CREATE INDEX `idx_student_batch_status` ON `xg_student_info` (`current_batch_id`, `info_status`, `deleted`);
|
||
CREATE INDEX `idx_audit_student_batch` ON `xg_audit_record` (`student_id`, `batch_id`, `audit_level`, `deleted`);
|
||
CREATE INDEX `idx_notice_target_status` ON `xg_notice` (`target_type`, `status`, `publish_time`, `deleted`);
|
||
CREATE INDEX `idx_permission_batch_user` ON `xg_batch_permission` (`batch_id`, `user_type`, `is_active`, `deleted`);
|
||
|
||
-- =============================================
|
||
-- 创建触发器
|
||
-- =============================================
|
||
|
||
-- 1. 学生信息变更触发器
|
||
DELIMITER //
|
||
CREATE TRIGGER `tr_xg_student_info_history`
|
||
AFTER UPDATE ON `xg_student_info`
|
||
FOR EACH ROW
|
||
BEGIN
|
||
INSERT INTO xg_student_info_history (
|
||
id, student_id, change_type, change_time, change_by,
|
||
old_values, new_values, tenant_id, create_time
|
||
) VALUES (
|
||
FLOOR(RAND() * 9000000000000000000 + 1000000000000000000),
|
||
NEW.id,
|
||
'update',
|
||
NOW(),
|
||
NEW.update_by,
|
||
JSON_OBJECT('name', OLD.name, 'phone', OLD.phone, 'email', OLD.email),
|
||
JSON_OBJECT('name', NEW.name, 'phone', NEW.phone, 'email', NEW.email),
|
||
NEW.tenant_id,
|
||
NOW()
|
||
);
|
||
END//
|
||
DELIMITER ;
|
||
|
||
-- 2. 批次完成率更新触发器
|
||
DELIMITER //
|
||
CREATE TRIGGER `tr_xg_batch_completion_rate`
|
||
AFTER UPDATE ON `xg_student_info`
|
||
FOR EACH ROW
|
||
BEGIN
|
||
DECLARE batch_total INT DEFAULT 0;
|
||
DECLARE batch_completed INT DEFAULT 0;
|
||
DECLARE completion_rate DECIMAL(5,2) DEFAULT 0.00;
|
||
|
||
IF NEW.current_batch_id IS NOT NULL AND (OLD.info_status != NEW.info_status) THEN
|
||
SELECT COUNT(*) INTO batch_total
|
||
FROM xg_student_info
|
||
WHERE current_batch_id = NEW.current_batch_id AND deleted = 0;
|
||
|
||
SELECT COUNT(*) INTO batch_completed
|
||
FROM xg_student_info
|
||
WHERE current_batch_id = NEW.current_batch_id
|
||
AND info_status IN ('submitted', 'approved')
|
||
AND deleted = 0;
|
||
|
||
IF batch_total > 0 THEN
|
||
SET completion_rate = ROUND(batch_completed * 100.0 / batch_total, 2);
|
||
END IF;
|
||
|
||
UPDATE xg_collection_batch
|
||
SET total_count = batch_total,
|
||
completed_count = batch_completed,
|
||
completion_rate = completion_rate,
|
||
update_time = NOW()
|
||
WHERE id = NEW.current_batch_id;
|
||
END IF;
|
||
END//
|
||
DELIMITER ;
|
||
|
||
-- =============================================
|
||
-- 创建存储过程
|
||
-- =============================================
|
||
|
||
-- 1. 批次数据统计存储过程
|
||
DELIMITER //
|
||
CREATE PROCEDURE `sp_xg_batch_statistics`(IN batch_id BIGINT)
|
||
BEGIN
|
||
DECLARE total_count INT DEFAULT 0;
|
||
DECLARE completed_count INT DEFAULT 0;
|
||
DECLARE completion_rate DECIMAL(5,2) DEFAULT 0.00;
|
||
|
||
SELECT COUNT(*) INTO total_count
|
||
FROM xg_student_info
|
||
WHERE current_batch_id = batch_id AND deleted = 0;
|
||
|
||
SELECT COUNT(*) INTO completed_count
|
||
FROM xg_student_info
|
||
WHERE current_batch_id = batch_id
|
||
AND info_status IN ('submitted', 'approved')
|
||
AND deleted = 0;
|
||
|
||
IF total_count > 0 THEN
|
||
SET completion_rate = ROUND(completed_count * 100.0 / total_count, 2);
|
||
END IF;
|
||
|
||
UPDATE xg_collection_batch
|
||
SET total_count = total_count,
|
||
completed_count = completed_count,
|
||
completion_rate = completion_rate,
|
||
update_time = NOW()
|
||
WHERE id = batch_id;
|
||
|
||
SELECT total_count, completed_count, completion_rate;
|
||
END//
|
||
DELIMITER ;
|
||
|
||
-- 2. 自动过期通知存储过程
|
||
DELIMITER //
|
||
CREATE PROCEDURE `sp_xg_auto_expire_notices`()
|
||
BEGIN
|
||
UPDATE xg_notice
|
||
SET status = 'expired', update_time = NOW()
|
||
WHERE status = 'published'
|
||
AND expire_time IS NOT NULL
|
||
AND expire_time < NOW()
|
||
AND deleted = 0;
|
||
|
||
SELECT ROW_COUNT() AS expired_count;
|
||
END//
|
||
DELIMITER ;
|
||
|
||
-- =============================================
|
||
-- 权限配置SQL
|
||
-- =============================================
|
||
|
||
-- 菜单权限配置(需要在sys_menu表中添加)
|
||
-- 这里只是示例,实际需要根据系统的菜单管理来配置
|
||
|
||
-- 1. 学年管理菜单
|
||
-- INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) VALUES ('学年管理', 父菜单ID, 1, 'academic-year', 'xg/academicYear/index', 1, 0, 'C', '0', '0', 'xg:academicYear:list', 'date', 1, NOW(), 1, NOW(), '学年管理菜单');
|
||
|
||
-- 2. 批次管理菜单
|
||
-- INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) VALUES ('批次管理', 父菜单ID, 2, 'collection-batch', 'xg/collectionBatch/index', 1, 0, 'C', '0', '0', 'xg:collectionBatch:list', 'list', 1, NOW(), 1, NOW(), '批次管理菜单');
|
||
|
||
-- 3. 学生信息管理菜单
|
||
-- INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) VALUES ('学生信息管理', 父菜单ID, 3, 'student-info', 'xg/studentInfo/index', 1, 0, 'C', '0', '0', 'xg:studentInfo:list', 'user', 1, NOW(), 1, NOW(), '学生信息管理菜单');
|
||
|
||
-- 4. 审核管理菜单
|
||
-- INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) VALUES ('审核管理', 父菜单ID, 4, 'audit-record', 'xg/auditRecord/index', 1, 0, 'C', '0', '0', 'xg:auditRecord:list', 'check', 1, NOW(), 1, NOW(), '审核管理菜单');
|
||
|
||
-- 5. 通知公告菜单
|
||
-- INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) VALUES ('通知公告', 父菜单ID, 5, 'notice', 'xg/notice/index', 1, 0, 'C', '0', '0', 'xg:notice:list', 'message', 1, NOW(), 1, NOW(), '通知公告菜单');
|
||
|
||
-- =============================================
|
||
-- 结束
|
||
-- ============================================= |