本系统是一个现代化的在线教育平台,采用前后端分离架构,提供课程管理、用户管理、视频点播、直播互动等功能。
-- 用户表
CREATE TABLE `user` (
`id` bigint NOT NULL AUTO_INCREMENT,
`username` varchar(64) NOT NULL,
`password` varchar(128) NOT NULL,
`nickname` varchar(64),
`avatar` varchar(255),
`phone` varchar(11),
`email` varchar(64),
`status` tinyint DEFAULT 1,
`create_time` datetime,
`update_time` datetime,
PRIMARY KEY (`id`)
);
-- 角色表
CREATE TABLE `role` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
`code` varchar(64) NOT NULL,
`status` tinyint DEFAULT 1,
PRIMARY KEY (`id`)
);
-- 课程表
CREATE TABLE `course` (
`id` bigint NOT NULL AUTO_INCREMENT,
`title` varchar(128) NOT NULL,
`cover` varchar(255),
`price` decimal(10,2),
`teacher_id` bigint,
`description` text,
`status` tinyint DEFAULT 0,
`create_time` datetime,
`update_time` datetime,
PRIMARY KEY (`id`)
);
-- 课程章节表
CREATE TABLE `chapter` (
`id` bigint NOT NULL AUTO_INCREMENT,
`course_id` bigint NOT NULL,
`title` varchar(128) NOT NULL,
`sort` int DEFAULT 0,
PRIMARY KEY (`id`)
);
// 用户登录
POST /api/user/login
// 用户注册
POST /api/user/register
// 获取用户信息
GET /api/user/info
// 更新用户信息
PUT /api/user/info
// 课程列表
GET /api/course/list
// 课程详情
GET /api/course/{id}
// 创建课程
POST /api/course
// 更新课程
PUT /api/course/{id}
// 删除课程
DELETE /api/course/{id}
-- 订单表
CREATE TABLE `order` (
`id` bigint NOT NULL AUTO_INCREMENT,
`order_no` varchar(64) NOT NULL COMMENT '订单号',
`user_id` bigint NOT NULL,
`course_id` bigint NOT NULL,
`amount` decimal(10,2) NOT NULL,
`status` tinyint DEFAULT 0 COMMENT '0未支付 1已支付 2已取消',
`pay_type` tinyint COMMENT '1支付宝 2微信',
`create_time` datetime,
`pay_time` datetime,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_order_no` (`order_no`)
);
-- 支付记录表
CREATE TABLE `payment_log` (
`id` bigint NOT NULL AUTO_INCREMENT,
`order_no` varchar(64) NOT NULL,
`transaction_id` varchar(64) COMMENT '第三方支付流水号',
`pay_type` tinyint,
`amount` decimal(10,2),
`status` tinyint,
`create_time` datetime,
PRIMARY KEY (`id`)
);
Key: user:info:{userId}
TTL: 30分钟
Key: course:info:{courseId}
TTL: 1小时
Key: course:hot
Type: Sorted Set
TTL: 24小时
# 视频处理队列
video:
exchange: video.exchange
routing-key: video.process
queue: video.process.queue
# 订单超时队列
order:
exchange: order.exchange
routing-key: order.timeout
queue: order.timeout.queue
dlx: order.dlx
src/
├── api/ # API接口
├── assets/ # 静态资源
├── components/ # 公共组件
├── hooks/ # 自定义hooks
├── layouts/ # 布局组件
├── router/ # 路由配置
├── stores/ # 状态管理
├── styles/ # 样式文件
├── types/ # TS类型定义
├── utils/ # 工具函数
└── views/ # 页面组件
// 用户状态
interface UserState {
userInfo: UserInfo | null;
token: string | null;
permissions: string[];
}
// 课程状态
interface CourseState {
courseList: Course[];
currentCourse: Course | null;
loading: boolean;
}
-- 权限表
CREATE TABLE `permission` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL COMMENT '权限名称',
`code` varchar(64) NOT NULL COMMENT '权限标识',
`type` tinyint NOT NULL COMMENT '类型:1菜单 2按钮',
`parent_id` bigint COMMENT '父级ID',
`path` varchar(255) COMMENT '路由路径',
`status` tinyint DEFAULT 1,
PRIMARY KEY (`id`)
);
-- 角色权限关系表
CREATE TABLE `role_permission` (
`id` bigint NOT NULL AUTO_INCREMENT,
`role_id` bigint NOT NULL,
`permission_id` bigint NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_role_perm` (`role_id`,`permission_id`)
);
-- 讲师表
CREATE TABLE `teacher` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`title` varchar(64) COMMENT '职称',
`intro` text COMMENT '简介',
`star_level` tinyint DEFAULT 0 COMMENT '星级',
`status` tinyint DEFAULT 1,
PRIMARY KEY (`id`)
);
-- 学习记录表
CREATE TABLE `study_record` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`course_id` bigint NOT NULL,
`last_study_time` datetime COMMENT '最后学习时间',
`study_duration` int DEFAULT 0 COMMENT '学习时长(分钟)',
`progress` int DEFAULT 0 COMMENT '进度(1-100)',
PRIMARY KEY (`id`),
KEY `idx_user_course` (`user_id`, `course_id`)
);
-- 课程分类表
CREATE TABLE `course_category` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
`parent_id` bigint DEFAULT 0,
`sort` int DEFAULT 0,
`status` tinyint DEFAULT 1,
PRIMARY KEY (`id`)
);
-- 课程详情表
CREATE TABLE `course_detail` (
`id` bigint NOT NULL AUTO_INCREMENT,
`course_id` bigint NOT NULL,
`introduction` text COMMENT '课程介绍',
`outline` text COMMENT '课程大纲',
`teaching_method` text COMMENT '教学方式',
`assessment` text COMMENT '考核方式',
PRIMARY KEY (`id`)
);
-- 课程资源表
CREATE TABLE `course_resource` (
`id` bigint NOT NULL AUTO_INCREMENT,
`course_id` bigint NOT NULL,
`chapter_id` bigint,
`title` varchar(128) NOT NULL,
`type` tinyint COMMENT '1视频 2文档 3习题',
`url` varchar(255),
`size` bigint DEFAULT 0 COMMENT '文件大小',
`duration` int DEFAULT 0 COMMENT '视频时长',
PRIMARY KEY (`id`)
);
-- 购物车表
CREATE TABLE `shopping_cart` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`course_id` bigint NOT NULL,
`price` decimal(10,2) NOT NULL,
`create_time` datetime,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_user_course` (`user_id`,`course_id`)
);
-- 退款记录表
CREATE TABLE `refund_record` (
`id` bigint NOT NULL AUTO_INCREMENT,
`order_no` varchar(64) NOT NULL,
`refund_no` varchar(64) NOT NULL,
`amount` decimal(10,2) NOT NULL,
`reason` varchar(255),
`status` tinyint DEFAULT 0,
`create_time` datetime,
`success_time` datetime,
PRIMARY KEY (`id`)
);
-- 问答表
CREATE TABLE `question` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`course_id` bigint NOT NULL,
`title` varchar(255) NOT NULL,
`content` text NOT NULL,
`status` tinyint DEFAULT 0,
`view_count` int DEFAULT 0,
`create_time` datetime,
PRIMARY KEY (`id`)
);
-- 笔记表
CREATE TABLE `study_note` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`course_id` bigint NOT NULL,
`chapter_id` bigint,
`content` text NOT NULL,
`status` tinyint DEFAULT 1,
`create_time` datetime,
PRIMARY KEY (`id`)
);
-- 消息表
CREATE TABLE `message` (
`id` bigint NOT NULL AUTO_INCREMENT,
`type` tinyint NOT NULL COMMENT '消息类型',
`title` varchar(128) NOT NULL,
`content` text NOT NULL,
`sender_id` bigint,
`receiver_id` bigint,
`status` tinyint DEFAULT 0 COMMENT '0未读 1已读',
`create_time` datetime,
PRIMARY KEY (`id`)
);
-- 消息模板表
CREATE TABLE `message_template` (
`id` bigint NOT NULL AUTO_INCREMENT,
`code` varchar(64) NOT NULL COMMENT '模板编码',
`type` tinyint NOT NULL COMMENT '1邮件 2短信',
`title` varchar(128),
`content` text NOT NULL,
`params` varchar(255) COMMENT '参数列表',
`status` tinyint DEFAULT 1,
PRIMARY KEY (`id`)
);
-- 文件资源表
CREATE TABLE `file_resource` (
`id` bigint NOT NULL AUTO_INCREMENT,
`file_name` varchar(255) NOT NULL,
`file_type` varchar(32) NOT NULL,
`file_size` bigint DEFAULT 0,
`file_path` varchar(255) NOT NULL,
`md5` varchar(32) COMMENT '文件MD5',
`status` tinyint DEFAULT 1,
`create_time` datetime,
PRIMARY KEY (`id`),
KEY `idx_md5` (`md5`)
);
-- 转码任务表
CREATE TABLE `transcode_task` (
`id` bigint NOT NULL AUTO_INCREMENT,
`resource_id` bigint NOT NULL,
`status` tinyint DEFAULT 0,
`definition` varchar(32) COMMENT '清晰度',
`progress` int DEFAULT 0,
`create_time` datetime,
`complete_time` datetime,
PRIMARY KEY (`id`)
);
{
"course": {
"mappings": {
"properties": {
"id": { "type": "long" },
"title": {
"type": "text",
"analyzer": "ik_max_word"
},
"description": {
"type": "text",
"analyzer": "ik_smart"
},
"teacherName": { "type": "keyword" },
"category": { "type": "keyword" },
"price": { "type": "double" },
"studyCount": { "type": "integer" },
"rating": { "type": "float" },
"createTime": { "type": "date" }
}
}
}
}
-- 直播间表
CREATE TABLE `live_room` (
`id` bigint NOT NULL AUTO_INCREMENT,
`title` varchar(128) NOT NULL,
`cover` varchar(255),
`teacher_id` bigint NOT NULL,
`stream_key` varchar(64) NOT NULL,
`status` tinyint DEFAULT 0,
`start_time` datetime,
`end_time` datetime,
PRIMARY KEY (`id`)
);
-- 直播记录表
CREATE TABLE `live_record` (
`id` bigint NOT NULL AUTO_INCREMENT,
`room_id` bigint NOT NULL,
`record_url` varchar(255),
`duration` int DEFAULT 0,
`create_time` datetime,
PRIMARY KEY (`id`)
);
-- 试题表
CREATE TABLE `question_bank` (
`id` bigint NOT NULL AUTO_INCREMENT,
`type` tinyint NOT NULL COMMENT '1单选 2多选 3判断 4简答',
`content` text NOT NULL,
`options` json COMMENT '选项',
`answer` text NOT NULL,
`analysis` text,
`difficulty` tinyint DEFAULT 2 COMMENT '1易 2中 3难',
PRIMARY KEY (`id`)
);
-- 试卷表
CREATE TABLE `exam_paper` (
`id` bigint NOT NULL AUTO_INCREMENT,
`title` varchar(128) NOT NULL,
`course_id` bigint NOT NULL,
`total_score` int DEFAULT 100,
`pass_score` int DEFAULT 60,
`duration` int DEFAULT 60 COMMENT '考试时长(分钟)',
`start_time` datetime,
`end_time` datetime,
PRIMARY KEY (`id`)
);
-- 每日统计表
CREATE TABLE `daily_statistics` (
`id` bigint NOT NULL AUTO_INCREMENT,
`stat_date` date NOT NULL,
`new_user_count` int DEFAULT 0,
`active_user_count` int DEFAULT 0,
`order_count` int DEFAULT 0,
`order_amount` decimal(12,2) DEFAULT 0,
`paid_count` int DEFAULT 0,
`paid_amount` decimal(12,2) DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_date` (`stat_date`)
);
-- 课程统计表
CREATE TABLE `course_statistics` (
`id` bigint NOT NULL AUTO_INCREMENT,
`course_id` bigint NOT NULL,
`view_count` int DEFAULT 0,
`buy_count` int DEFAULT 0,
`study_count` int DEFAULT 0,
`complete_count` int DEFAULT 0,
`income_amount` decimal(12,2) DEFAULT 0,
`stat_date` date,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_course_date` (`course_id`, `stat_date`)
);
-- AI评分记录表
CREATE TABLE `ai_score_record` (
`id` bigint NOT NULL AUTO_INCREMENT,
`answer_id` bigint NOT NULL,
`question_id` bigint NOT NULL,
`original_text` text NOT NULL,
`score` decimal(5,2) NOT NULL,
`analysis` text COMMENT '分析结果',
`suggestions` text COMMENT '改进建议',
`knowledge_points` json COMMENT '关联知识点',
`create_time` datetime,
PRIMARY KEY (`id`)
);
-- 评分模型配置表
CREATE TABLE `score_model_config` (
`id` bigint NOT NULL AUTO_INCREMENT,
`model_name` varchar(64) NOT NULL COMMENT '模型名称',
`question_type` tinyint NOT NULL COMMENT '题目类型',
`parameters` json COMMENT '模型参数',
`version` varchar(32) COMMENT '模型版本',
`status` tinyint DEFAULT 1,
PRIMARY KEY (`id`)
);
-- 知识库表
CREATE TABLE `knowledge_base` (
`id` bigint NOT NULL AUTO_INCREMENT,
`course_id` bigint NOT NULL,
`title` varchar(255) NOT NULL,
`content` text NOT NULL,
`keywords` varchar(255) COMMENT '关键词',
`category` varchar(64) COMMENT '分类',
`vector` text COMMENT '向量数据',
`create_time` datetime,
PRIMARY KEY (`id`),
FULLTEXT KEY `idx_content` (`content`)
);
-- 问答记录表
CREATE TABLE `qa_record` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`question` text NOT NULL,
`answer` text NOT NULL,
`source_type` tinyint COMMENT '来源:1知识库 2模型生成',
`confidence` decimal(5,2) COMMENT '置信度',
`feedback` tinyint COMMENT '反馈:1有用 2无用',
`create_time` datetime,
PRIMARY KEY (`id`)
);
-- 学习行为记录表
CREATE TABLE `learning_behavior` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`course_id` bigint NOT NULL,
`resource_id` bigint NOT NULL,
`behavior_type` tinyint COMMENT '1浏览 2下载 3笔记 4提问',
`duration` int DEFAULT 0 COMMENT '停留时长(秒)',
`create_time` datetime,
PRIMARY KEY (`id`)
);
-- 知识图谱表
CREATE TABLE `knowledge_graph` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
`parent_id` bigint,
`level` tinyint COMMENT '层级',
`relations` json COMMENT '关联关系',
`weight` int DEFAULT 0 COMMENT '重要程度',
PRIMARY KEY (`id`)
);
# 批改模型服务
correction:
- 文本相似度分析
- 语法错误检测
- 内容逻辑分析
- 知识点覆盖评估
# 问答模型服务
qa:
- 问题理解
- 相关性匹配
- 答案生成
- 答案排序
# 推荐模型服务
recommendation:
- 协同过滤
- 内容推荐
- 实时推荐
- 冷启动处理
# API接口设计
api:
correction:
- POST /api/ai/correction/essay
- POST /api/ai/correction/question
- GET /api/ai/correction/analysis
qa:
- POST /api/ai/qa/ask
- POST /api/ai/qa/similar
- GET /api/ai/qa/recommend
recommendation:
- GET /api/ai/recommend/course
- GET /api/ai/recommend/resource
- POST /api/ai/recommend/feedback
-- 训练数据集表
CREATE TABLE `training_dataset` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
`type` tinyint COMMENT '1文本 2图像 3音频',
`size` int DEFAULT 0 COMMENT '数据量',
`status` tinyint DEFAULT 0,
`create_time` datetime,
PRIMARY KEY (`id`)
);
-- 模型训练记录表
CREATE TABLE `model_training` (
`id` bigint NOT NULL AUTO_INCREMENT,
`model_name` varchar(64) NOT NULL,
`dataset_id` bigint NOT NULL,
`parameters` json COMMENT '训练参数',
`metrics` json COMMENT '评估指标',
`status` tinyint DEFAULT 0,
`start_time` datetime,
`end_time` datetime,
PRIMARY KEY (`id`)
);