121 lines
6.0 KiB
SQL
121 lines
6.0 KiB
SQL
-- ==========================================
|
||
-- 学生宿舍申请单数据库脚本(调宿+退宿)
|
||
-- 创建时间:2025-01-15
|
||
-- 设计目标:统一的调宿和退宿申请单表
|
||
-- ==========================================
|
||
|
||
-- ----------------------------
|
||
-- 1. 主表:学生宿舍申请单表
|
||
-- ----------------------------
|
||
|
||
DROP TABLE IF EXISTS `xg_dorm_application`;
|
||
CREATE TABLE `xg_dorm_application` (
|
||
`id` bigint(20) NOT NULL COMMENT '主键ID(雪花ID)',
|
||
|
||
-- 申请基本信息
|
||
`application_name` varchar(50) NOT NULL COMMENT '申请名称',
|
||
`application_type` char(1) NOT NULL COMMENT '申请类型(1:调宿申请 2:退宿申请)',
|
||
`application_status` char(20) DEFAULT 'waiting' COMMENT '审批状态:cancel-已撤销 , draft-草稿, waiting-待审核, finish-已完成, invalid-已作废, back-已退回, termination-已终止"',
|
||
|
||
-- 学生信息
|
||
`student_id` bigint(20) NOT NULL COMMENT '申请学生ID',
|
||
`student_no` varchar(20) NOT NULL COMMENT '学号',
|
||
`student_name` varchar(50) NOT NULL COMMENT '学生姓名',
|
||
`student_phone` varchar(20) DEFAULT NULL COMMENT '学生联系电话',
|
||
`college_id` bigint(20) NOT NULL COMMENT '学院ID',
|
||
`college_name` varchar(100) DEFAULT NULL COMMENT '学院名称',
|
||
`major_id` bigint(20) DEFAULT NULL COMMENT '专业ID',
|
||
`major_name` varchar(100) DEFAULT NULL COMMENT '专业名称',
|
||
`class_id` bigint(20) DEFAULT NULL COMMENT '班级ID',
|
||
`class_name` varchar(100) DEFAULT NULL COMMENT '班级名称',
|
||
|
||
-- 当前宿舍信息(原宿舍/退宿的宿舍)
|
||
`current_campus_id` bigint(20) DEFAULT NULL COMMENT '当前校区ID',
|
||
`current_campus_name` varchar(100) DEFAULT NULL COMMENT '当前校区名称',
|
||
`current_building_id` bigint(20) DEFAULT NULL COMMENT '当前宿舍楼ID',
|
||
`current_building_name` varchar(100) DEFAULT NULL COMMENT '当前宿舍楼名称',
|
||
`current_room_id` bigint(20) DEFAULT NULL COMMENT '当前房间ID',
|
||
`current_room_no` varchar(20) DEFAULT NULL COMMENT '当前房间号',
|
||
`current_bed_id` bigint(20) DEFAULT NULL COMMENT '当前床位ID',
|
||
`current_bed_no` varchar(10) DEFAULT NULL COMMENT '当前床位号',
|
||
|
||
-- 目标宿舍信息(仅调宿申请使用,退宿申请为空)
|
||
`target_campus_id` bigint(20) DEFAULT NULL COMMENT '目标校区ID',
|
||
`target_campus_name` varchar(100) DEFAULT NULL COMMENT '目标校区名称',
|
||
`target_building_id` bigint(20) DEFAULT NULL COMMENT '目标宿舍楼ID',
|
||
`target_building_name` varchar(100) DEFAULT NULL COMMENT '目标宿舍楼名称',
|
||
`target_room_id` bigint(20) DEFAULT NULL COMMENT '目标房间ID',
|
||
`target_room_no` varchar(20) DEFAULT NULL COMMENT '目标房间号',
|
||
`target_bed_id` bigint(20) DEFAULT NULL COMMENT '目标床位ID',
|
||
`target_bed_no` varchar(10) DEFAULT NULL COMMENT '目标床位号',
|
||
|
||
-- 申请原因和说明
|
||
`reason_detail` text DEFAULT NULL COMMENT '详细原因说明',
|
||
|
||
-- 时间相关
|
||
`apply_time` datetime NOT NULL COMMENT '申请时间',
|
||
|
||
-- 附件和备注
|
||
`attachment_oss_ids` varchar(1000) DEFAULT NULL COMMENT '附件OSS文件ID,多个用逗号分隔',
|
||
`remark` varchar(500) DEFAULT NULL COMMENT '备注信息',
|
||
|
||
-- 扩展字段
|
||
`ext_field1` varchar(200) DEFAULT NULL COMMENT '扩展字段1',
|
||
`ext_field2` varchar(200) DEFAULT NULL COMMENT '扩展字段2',
|
||
`ext_field3` varchar(500) DEFAULT NULL COMMENT '扩展字段3',
|
||
|
||
-- 系统字段(符合项目规范)
|
||
`deleted` char(1) DEFAULT '0' COMMENT '删除标志(0代表存在 1代表删除)',
|
||
`tenant_id` bigint(20) DEFAULT '0' COMMENT '租户编号',
|
||
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
|
||
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
|
||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
|
||
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
KEY `idx_tenant_id` (`tenant_id`),
|
||
KEY `idx_deleted` (`deleted`),
|
||
KEY `idx_student_id` (`student_id`),
|
||
KEY `idx_student_no` (`student_no`),
|
||
KEY `idx_application_type` (`application_type`),
|
||
KEY `idx_application_status` (`application_status`),
|
||
KEY `idx_apply_time` (`apply_time`),
|
||
KEY `idx_college_id` (`college_id`),
|
||
KEY `idx_current_building_id` (`current_building_id`),
|
||
KEY `idx_target_building_id` (`target_building_id`),
|
||
KEY `idx_tenant_deleted_status` (`tenant_id`, `deleted`, `application_status`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学生宿舍申请单表(调宿+退宿)';
|
||
|
||
-- ----------------------------
|
||
-- 2. 字典类型配置
|
||
-- ----------------------------
|
||
|
||
-- 申请类型字典
|
||
INSERT INTO sys_dict_type (dict_id, dict_name, dict_type, status, create_by, create_time, remark) VALUES
|
||
(nextval('sys_dict_type_seq'), '宿舍申请类型', 'dorm_application_type', '0', 1, NOW(), '学生宿舍申请类型');
|
||
|
||
-- 申请类型字典数据
|
||
INSERT INTO sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark) VALUES
|
||
(nextval('sys_dict_data_seq'), 1, '调宿申请', '1', 'dorm_application_type', '', 'primary', 'N', '0', 1, NOW(), '学生调宿申请'),
|
||
(nextval('sys_dict_data_seq'), 2, '退宿申请', '2', 'dorm_application_type', '', 'warning', 'N', '0', 1, NOW(), '学生退宿申请');
|
||
|
||
|
||
|
||
-- ----------------------------
|
||
-- 脚本说明
|
||
-- ----------------------------
|
||
/*
|
||
使用说明:
|
||
1. 执行前需要确认学工管理菜单的实际ID,替换脚本中的占位符
|
||
2. 根据项目实际情况调整字典数据的dict_code值
|
||
3. 测试数据仅供参考,实际使用时可删除
|
||
4. 表设计遵循项目规范:雪花ID、逻辑删除、多租户支持
|
||
5. 支持调宿和退宿两种申请类型,通过application_type字段区分
|
||
|
||
设计特点:
|
||
- 统一表结构:一个表同时支持调宿和退宿申请
|
||
- 灵活字段:退宿申请时目标宿舍信息为空
|
||
- 完整流程:支持从草稿到生效的完整状态流转
|
||
- 性能优化:冗余存储宿舍名称,避免关联查询
|
||
- 权限控制:完整的菜单和功能权限配置
|
||
*/ |