add
2
.gitignore
vendored
@ -24,3 +24,5 @@
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
.idea
|
||||
target
|
271
db/xm_examination.sql
Normal file
@ -0,0 +1,271 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : localhost_3306
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 80013
|
||||
Source Host : localhost:3306
|
||||
Source Schema : xm_examination
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 80013
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 12/10/2024 22:52:44
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for admin
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `admin`;
|
||||
CREATE TABLE `admin` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '账号',
|
||||
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '密码',
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '姓名',
|
||||
`avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '头像',
|
||||
`role` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '角色',
|
||||
`phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '电话',
|
||||
`email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '邮箱',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '管理员表' ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of admin
|
||||
-- ----------------------------
|
||||
INSERT INTO `admin` VALUES (1, 'admin', 'admin', '管理员', 'http://localhost:9090/files/download/1721114905635-柴犬.jpeg', 'ADMIN', '18899990011', 'admin2@xm.com');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for article
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `article`;
|
||||
CREATE TABLE `article` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '帖子标题',
|
||||
`img` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '帖子主图',
|
||||
`content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '帖子内容',
|
||||
`time` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '发布时间',
|
||||
`student_id` int(10) NULL DEFAULT NULL COMMENT '学生ID',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '帖子信息表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of article
|
||||
-- ----------------------------
|
||||
INSERT INTO `article` VALUES (2, '关于学习Java枚举的笔记经验分享', 'http://localhost:9090/files/download/1728563732106-2.png', '<p><strong>基于Springboot3+Vue3的在线考试系统</strong></p><p>角色:管理员、教师、学生</p><p>功能模块:</p><p>登录注册:(已完成)</p><p>个人中心:(已完成)</p><p>修改密码:(已完成)</p><p>管理员信息:(已完成)</p><p>教师信息:(已完成)</p><p>学生信息:(已完成)</p><p>考试安排:(已完成)</p><p>题型管理:包括单选、多选、判断、填空、简答(已完成)</p><p>课程管理:(已完成)</p><p>学习交流管理:</p><p>题库管理:题库里的题目需要根据课程进行分类,不同的课程都得有对应的题库,教师可以给自己的课程题库里新增试题(已完成)</p><p>组卷:选择课程出卷时,支持随机和人工从题库里抽选题目,组成试卷</p><p>试卷预览:</p><p>成绩管理:</p><p>自动阅卷:客观题自动阅卷,主观题(简答)可以支持手动给分</p><p>前台学生:</p><p>查看考试安排、查看试卷</p><p>在线答题:试卷每种题型在线展示,供学生答题</p><p>学习交流:发布学习心得</p><p><img src=\"http://localhost:9090/files/download/1728566947212-柴犬.jpeg\" alt=\"\" data-href=\"\" style=\"\"/></p>', '2024-10-10 20:35:34', 1);
|
||||
INSERT INTO `article` VALUES (3, '武哥10万字Springboot经典教程学习笔记', 'http://localhost:9090/files/download/1728564558044-9.png', '66666', '2024-10-10 20:49:20', 2);
|
||||
INSERT INTO `article` VALUES (5, '在线考试系统功能点描述分享', 'http://localhost:9090/files/download/1728564833337-10.png', '<p>基于Springboot3+Vue3的在线考试系统</p><p>角色:管理员、教师、学生</p><p>功能模块:</p><p>登录注册:(已完成)</p><p>个人中心:(已完成)</p><p>修改密码:(已完成)</p><p>管理员信息:(已完成)</p><p>教师信息:(已完成)</p><p>学生信息:(已完成)</p><p>考试安排:(已完成)</p><p>题型管理:包括单选、多选、判断、填空、简答(已完成)</p><p>课程管理:(已完成)</p><p>学习交流管理:</p><p><br></p><p>题库管理:题库里的题目需要根据课程进行分类,不同的课程都得有对应的题库,教师可以给自己的课程题库里新增试题(已完成)</p><p>组卷:选择课程出卷时,支持随机和人工从题库里抽选题目,组成试卷</p><p>试卷预览:</p><p>成绩管理:</p><p>自动阅卷:客观题自动阅卷,主观题(简答)可以支持手动给分</p><p>前台学生:</p><p>查看考试安排、查看试卷</p><p>在线答题:试卷每种题型在线展示,供学生答题</p><p>学习交流:发布学习心得</p><p><br></p>', '2024-10-10 20:53:55', 1);
|
||||
INSERT INTO `article` VALUES (6, 'Vue3基础知识学习笔记', 'http://localhost:9090/files/download/1728568543079-7.png', '<p>哈哈哈</p><p>呵呵呵</p><p>嘿嘿嘿</p><p>嘎嘎嘎</p><p>啦啦啦</p>', '2024-10-10 21:55:52', 1);
|
||||
INSERT INTO `article` VALUES (7, '前端三件套html,css,js学习心得', 'http://localhost:9090/files/download/1728568566399-right.jpg', '<p>哈哈哈</p><p>哈哈哈</p><p>嘿嘿黑</p><p>呵呵呵</p><p>嘎嘎嘎</p>', '2024-10-10 21:56:13', 1);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for course
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `course`;
|
||||
CREATE TABLE `course` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '课程名称',
|
||||
`img` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '课程封面',
|
||||
`score` int(10) NULL DEFAULT NULL COMMENT '课程学分',
|
||||
`teacher_id` int(10) NULL DEFAULT NULL COMMENT '教师ID',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '课程信息表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of course
|
||||
-- ----------------------------
|
||||
INSERT INTO `course` VALUES (2, 'Java基础入门课', 'http://localhost:9090/files/download/1728545691210-Java基础入门课程.jpg', 3, 1);
|
||||
INSERT INTO `course` VALUES (3, 'Vue最新实战教程', 'http://localhost:9090/files/download/1728545950698-Vue最新教程.jpg', 3, 1);
|
||||
INSERT INTO `course` VALUES (4, 'Java入学课程', 'http://localhost:9090/files/download/1728545989297-Java入学课程.jpg', 3, 2);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for exam_plan
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `exam_plan`;
|
||||
CREATE TABLE `exam_plan` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '标题',
|
||||
`content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '内容',
|
||||
`time` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '发布时间',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '考试安排表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of exam_plan
|
||||
-- ----------------------------
|
||||
INSERT INTO `exam_plan` VALUES (1, '关于第一学期期末考试的安排', '考试时间:xxxx-xx-xx,考试地点:xxxx。注意事项:xxxx', '2024-10-10 14:21:13');
|
||||
INSERT INTO `exam_plan` VALUES (2, '关于考试考场纪律和作弊处罚措施', '本着公平公正原则,考试过程严禁作弊,请监考老师以及同学严格遵守,一旦发现,会取消该门课的考试资格,等待补考,如果补考作弊,该门课需要重修!', '2024-10-10 14:21:28');
|
||||
INSERT INTO `exam_plan` VALUES (3, '信息工程学院期末考试安排', '本着公平公正原则,考试过程严禁作弊,请监考老师以及同学严格遵守,一旦发现,会取消该门课的考试资格,等待补考,如果补考作弊,该门课需要重修!', '2024-10-10 14:21:40');
|
||||
INSERT INTO `exam_plan` VALUES (4, '软件学院期末考试安排', '考试时间:xxxx-xx-xx,考试地点:xxxx。注意事项:xxxx', '2024-10-10 14:21:51');
|
||||
INSERT INTO `exam_plan` VALUES (5, '经济管理学期末考试安排', '考试时间:xxxx-xx-xx,考试地点:xxxx。注意事项:xxxx', '2024-10-10 14:22:05');
|
||||
INSERT INTO `exam_plan` VALUES (6, '物流工程学院考试安排', '考试时间:xxxx-xx-xx,考试地点:xxxx。注意事项:xxxx', '2024-10-12 22:35:08');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for notice
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `notice`;
|
||||
CREATE TABLE `notice` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '公告标题',
|
||||
`content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '公告内容',
|
||||
`time` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '发布时间',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '系统公告表' ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of notice
|
||||
-- ----------------------------
|
||||
INSERT INTO `notice` VALUES (1, '今天天气真的不错', '今天好开心呀!因为天气很好,我又可以肆无忌惮的跟着武哥和青哥学习了!!真的好开心!', '2024-07-16 15:51:17');
|
||||
INSERT INTO `notice` VALUES (2, '项目所有功能开发完毕!', '我的项目所有的功能都开发完啦!真的很有成就感!', '2024-07-16 15:52:22');
|
||||
INSERT INTO `notice` VALUES (3, '项目功能都测试完成,准备上线!', '经过半个月的学习和练习,终于把这个项目完成了,可以打包上线了!', '2024-07-16 15:52:56');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for question
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `question`;
|
||||
CREATE TABLE `question` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '题目名称',
|
||||
`course_id` int(10) NULL DEFAULT NULL COMMENT '课程ID',
|
||||
`teacher_id` int(10) NULL DEFAULT NULL COMMENT '教师ID',
|
||||
`type_id` int(10) NULL DEFAULT NULL COMMENT '题型ID',
|
||||
`option_a` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '选项A',
|
||||
`option_b` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '选项B',
|
||||
`option_c` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '选项C',
|
||||
`option_d` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '选项D',
|
||||
`answer` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '题目答案',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '题目信息表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of question
|
||||
-- ----------------------------
|
||||
INSERT INTO `question` VALUES (2, 'Java是世界上最好的语言!', 2, 1, 3, NULL, NULL, NULL, NULL, '正确');
|
||||
INSERT INTO `question` VALUES (3, '下面哪一项不是Java基本数据类型?', 2, 1, 1, 'int', 'int', 'float', 'let', 'D');
|
||||
INSERT INTO `question` VALUES (4, '下面哪些选项是Java的特点?', 2, 1, 2, 'Java是后端语言', 'Java是前端语言', 'Java是强类型语言', 'Java是弱类型语言', 'A,C');
|
||||
INSERT INTO `question` VALUES (5, 'Java语言的创造者是______。', 2, 1, 4, NULL, NULL, NULL, NULL, 'James Gosling');
|
||||
INSERT INTO `question` VALUES (6, '请写一个冒泡排序算法。', 2, 1, 5, NULL, NULL, NULL, NULL, 'public void bubbleSort(int[] source) {\n for(int i = source.length - 1; i > 0; i--) {\n for(int j = 0; j < i; j++) {\n if(a[j] > a[j+1])\n swap(source, j, j+1); \n }\n }\n}');
|
||||
INSERT INTO `question` VALUES (7, '所有的Java项目里都有一个启动的______方法。', 4, 2, 4, NULL, NULL, NULL, NULL, 'main');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for question_type
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `question_type`;
|
||||
CREATE TABLE `question_type` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '题型名称',
|
||||
`score` int(10) NULL DEFAULT NULL COMMENT '题型分数',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '题型信息表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of question_type
|
||||
-- ----------------------------
|
||||
INSERT INTO `question_type` VALUES (1, '单选题', 4);
|
||||
INSERT INTO `question_type` VALUES (2, '多选题', 5);
|
||||
INSERT INTO `question_type` VALUES (3, '判断题', 2);
|
||||
INSERT INTO `question_type` VALUES (4, '填空题', 4);
|
||||
INSERT INTO `question_type` VALUES (5, '简答题', 20);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for score
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `score`;
|
||||
CREATE TABLE `score` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '试卷名称',
|
||||
`course_id` int(10) NULL DEFAULT NULL COMMENT '课程ID',
|
||||
`teacher_id` int(10) NULL DEFAULT NULL COMMENT '教师ID',
|
||||
`student_id` int(10) NULL DEFAULT NULL COMMENT '学生ID',
|
||||
`paper_id` int(10) NULL DEFAULT NULL COMMENT '试卷ID',
|
||||
`score` int(10) NULL DEFAULT NULL COMMENT '成绩得分',
|
||||
`status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '状态',
|
||||
`answer` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '提交结果',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '成绩信息表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of score
|
||||
-- ----------------------------
|
||||
INSERT INTO `score` VALUES (2, 'Java基础入门课小测验2', 2, 1, 1, 2, 13, '已阅卷', '[{\"typeName\":\"单选题\",\"questionId\":3,\"score\":4,\"answer\":\"D\",\"newAnswer\":\"D\"},{\"typeName\":\"多选题\",\"questionId\":4,\"score\":5,\"answer\":\"A,C\",\"newAnswer\":\"A,C\"},{\"typeName\":\"判断题\",\"questionId\":2,\"score\":2,\"answer\":\"正确\",\"newAnswer\":\"正确\"},{\"typeName\":\"填空题\",\"questionId\":5,\"score\":4,\"answer\":\"James Gosling\",\"newAnswer\":\"张三\"},{\"typeName\":\"简答题\",\"questionId\":6,\"score\":20,\"answer\":\"public void bubbleSort(int[] source) {\\n for(int i = source.length - 1; i > 0; i--) {\\n for(int j = 0; j < i; j++) {\\n if(a[j] > a[j+1])\\n swap(source, j, j+1); \\n }\\n }\\n}\",\"newAnswer\":\"public static void main() \"}]');
|
||||
INSERT INTO `score` VALUES (3, 'Java基础入门课小测验3', 2, 1, 1, 3, NULL, '待阅卷', '[{\"typeName\":\"单选题\",\"questionId\":3,\"score\":4,\"answer\":\"D\",\"newAnswer\":\"D\"},{\"typeName\":\"多选题\",\"questionId\":4,\"score\":5,\"answer\":\"A,C\",\"newAnswer\":\"A,C\"},{\"typeName\":\"简答题\",\"questionId\":6,\"score\":20,\"answer\":\"public void bubbleSort(int[] source) {\\n for(int i = source.length - 1; i > 0; i--) {\\n for(int j = 0; j < i; j++) {\\n if(a[j] > a[j+1])\\n swap(source, j, j+1); \\n }\\n }\\n}\",\"newAnswer\":\"public void bubbleSort(int[] source) {\\n for(int i = source.length - 1; i > 0; i--) {\\n for(int j = 0; j < i; j++) {\\n if(a[j] > a[j+1])\\n swap(source, j, j+1); \\n }\\n }\\n}\"}]');
|
||||
INSERT INTO `score` VALUES (4, 'Java基础入门课小测验1', 2, 1, 1, 1, 20, '已阅卷', '[{\"typeName\":\"判断题\",\"questionId\":2,\"score\":2,\"answer\":\"正确\",\"newAnswer\":\"正确\"},{\"typeName\":\"单选题\",\"questionId\":3,\"score\":4,\"answer\":\"D\",\"newAnswer\":\"D\"},{\"typeName\":\"多选题\",\"questionId\":4,\"score\":5,\"answer\":\"A,C\",\"newAnswer\":\"C,A\"},{\"typeName\":\"填空题\",\"questionId\":5,\"score\":4,\"answer\":\"James Gosling\",\"newAnswer\":\"James Gosling\"},{\"typeName\":\"简答题\",\"questionId\":6,\"score\":20,\"answer\":\"public void bubbleSort(int[] source) {\\n for(int i = source.length - 1; i > 0; i--) {\\n for(int j = 0; j < i; j++) {\\n if(a[j] > a[j+1])\\n swap(source, j, j+1); \\n }\\n }\\n}\",\"newAnswer\":\"public static void main( ) {\\n System.print......\\n 老师我不会了,给我点辛苦分吧~\\n}\"}]');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for student
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `student`;
|
||||
CREATE TABLE `student` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '账号',
|
||||
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '密码',
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '姓名',
|
||||
`avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '头像',
|
||||
`role` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '角色',
|
||||
`phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '电话',
|
||||
`email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '邮箱',
|
||||
`status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '状态',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '学生信息表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of student
|
||||
-- ----------------------------
|
||||
INSERT INTO `student` VALUES (1, 'zhangsan', '123456', '张三', 'http://localhost:9090/files/download/1728486694570-柴犬.jpeg', 'STUDENT', '18899990000', 'zhangsan@xm.com', '审核通过');
|
||||
INSERT INTO `student` VALUES (2, 'lisi', '123456', '李四', 'http://localhost:9090/files/download/1728486728196-拉布拉多.jpeg', 'STUDENT', '18899995555', 'lisi@xm.com', '审核通过');
|
||||
INSERT INTO `student` VALUES (3, 'wangwu', '123456', '王五', 'http://localhost:9090/files/download/1728486753434-柯基.jpeg', 'STUDENT', '18844445555', 'wangwu@xm.com', '审核通过');
|
||||
INSERT INTO `student` VALUES (4, 'zhaoliu', '123456', 'zhaoliu', NULL, 'STUDENT', NULL, NULL, '待审核');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for teacher
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `teacher`;
|
||||
CREATE TABLE `teacher` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '账号',
|
||||
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '密码',
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '姓名',
|
||||
`avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '头像',
|
||||
`role` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '角色',
|
||||
`phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '电话',
|
||||
`email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '邮箱',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '教师信息表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of teacher
|
||||
-- ----------------------------
|
||||
INSERT INTO `teacher` VALUES (1, 'zhang', '123456', '张老师', 'http://localhost:9090/files/download/1728484762449-柴犬.jpeg', 'TEACHER', '18800001111', 'zhang@xm.com');
|
||||
INSERT INTO `teacher` VALUES (2, 'li', '123456', '李老师', 'http://localhost:9090/files/download/1728484862680-柯基.jpeg', 'TEACHER', '18877776666', 'li@xm.com');
|
||||
INSERT INTO `teacher` VALUES (3, 'zhao', '123456', 'zhao', NULL, 'TEACHER', NULL, NULL);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for test_paper
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `test_paper`;
|
||||
CREATE TABLE `test_paper` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '试卷名称',
|
||||
`course_id` int(10) NULL DEFAULT NULL COMMENT '课程ID',
|
||||
`teacher_id` int(10) NULL DEFAULT NULL COMMENT '教师ID',
|
||||
`type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '类型',
|
||||
`start` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '开始时间',
|
||||
`end` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '结束时间',
|
||||
`time` int(10) NULL DEFAULT NULL COMMENT '考试时长',
|
||||
`question_ids` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '题目IDs',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '试卷信息表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of test_paper
|
||||
-- ----------------------------
|
||||
INSERT INTO `test_paper` VALUES (1, 'Java基础入门课小测验1', 2, 1, '手动选题', '2024-10-11', '2024-10-26', 60, '[2,3,4,5,6]');
|
||||
INSERT INTO `test_paper` VALUES (2, 'Java基础入门课小测验2', 2, 1, '自动组卷', '2024-10-11', '2024-10-26', 60, '[3,4,2,5,6]');
|
||||
INSERT INTO `test_paper` VALUES (3, 'Java基础入门课小测验3', 2, 1, '自动组卷', '2024-10-11', '2024-10-24', 60, '[3,4,6]');
|
||||
INSERT INTO `test_paper` VALUES (4, 'Java基础入门小测验4', 2, 1, '手动选题', '2024-10-12', '2025-11-13', 60, '[3,4,2,6]');
|
||||
INSERT INTO `test_paper` VALUES (5, 'Java基础入门小测验5', 2, 1, '自动组卷', '2024-10-12', '2025-10-09', 60, '[3,4,2,5,6]');
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
BIN
files/1721114905635-柴犬.jpeg
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
files/1728484762449-柴犬.jpeg
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
files/1728484862680-柯基.jpeg
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
files/1728486694570-柴犬.jpeg
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
files/1728486728196-拉布拉多.jpeg
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
files/1728486753434-柯基.jpeg
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
files/1728545484737-Java基础入门课程.jpg
Normal file
After Width: | Height: | Size: 338 KiB |
BIN
files/1728545691210-Java基础入门课程.jpg
Normal file
After Width: | Height: | Size: 338 KiB |
BIN
files/1728545950698-Vue最新教程.jpg
Normal file
After Width: | Height: | Size: 154 KiB |
BIN
files/1728545989297-Java入学课程.jpg
Normal file
After Width: | Height: | Size: 273 KiB |
BIN
files/1728563597926-2.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
files/1728563732106-2.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
files/1728564558044-9.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
files/1728564626540-10.png
Normal file
After Width: | Height: | Size: 39 KiB |
BIN
files/1728564833337-10.png
Normal file
After Width: | Height: | Size: 39 KiB |
BIN
files/1728566947212-柴犬.jpeg
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
files/1728568543079-7.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
files/1728568566399-right.jpg
Normal file
After Width: | Height: | Size: 15 KiB |
78
pom.xml
Normal file
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>java-experiment</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>springboot</name>
|
||||
<description>springboot</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.25</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 分页插件pagehelper -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.4.6</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- JWT -->
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>4.3.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
13
src/main/java/com/example/SpringbootApplication.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.example;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.example.mapper")
|
||||
public class SpringbootApplication { public static void main(String[] args) {
|
||||
SpringApplication.run(SpringbootApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
7
src/main/java/com/example/common/Constants.java
Normal file
@ -0,0 +1,7 @@
|
||||
package com.example.common;
|
||||
|
||||
public interface Constants {
|
||||
|
||||
String TOKEN = "token";
|
||||
String USER_DEFAULT_PASSWORD = "123456";
|
||||
}
|
70
src/main/java/com/example/common/Result.java
Normal file
@ -0,0 +1,70 @@
|
||||
package com.example.common;
|
||||
|
||||
public class Result {
|
||||
|
||||
private String code;
|
||||
private String msg;
|
||||
private Object data;
|
||||
|
||||
public Result() {
|
||||
|
||||
}
|
||||
|
||||
public static Result success() {
|
||||
Result result = new Result();
|
||||
result.setCode("200");
|
||||
result.setMsg("请求成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result success(Object data) {
|
||||
Result result = success();
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error() {
|
||||
Result result = new Result();
|
||||
result.setCode("500");
|
||||
result.setMsg("系统异常");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error(String code, String msg) {
|
||||
Result result = new Result();
|
||||
result.setCode(code);
|
||||
result.setMsg(msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error(String msg) {
|
||||
Result result = new Result();
|
||||
result.setCode("500");
|
||||
result.setMsg(msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
25
src/main/java/com/example/common/config/CorsConfig.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.example.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* 跨域配置
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址
|
||||
corsConfiguration.addAllowedHeader("*"); // 2 设置访问源请求头
|
||||
corsConfiguration.addAllowedMethod("*"); // 3 设置访问源请求方法
|
||||
source.registerCorsConfiguration("/**", corsConfiguration); // 4 对接口配置跨域设置
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
81
src/main/java/com/example/common/config/JWTInterceptor.java
Normal file
@ -0,0 +1,81 @@
|
||||
package com.example.common.config;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.JWTVerifier;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.exceptions.JWTVerificationException;
|
||||
import com.example.common.Constants;
|
||||
import com.example.common.enums.ResultCodeEnum;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.exception.CustomException;
|
||||
import com.example.service.AdminService;
|
||||
import com.example.service.StudentService;
|
||||
import com.example.service.TeacherService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
/**
|
||||
* JWT拦截器
|
||||
*/
|
||||
@Component
|
||||
public class JWTInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Resource
|
||||
private AdminService adminService;
|
||||
@Resource
|
||||
private TeacherService teacherService;
|
||||
@Resource
|
||||
private StudentService studentService;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
// 1. 从http请求标头里面拿到token
|
||||
String token = request.getHeader(Constants.TOKEN);
|
||||
if (ObjectUtil.isNull(token)) {
|
||||
// 如果没拿到,那么再从请求参数里拿一次
|
||||
request.getParameter(Constants.TOKEN);
|
||||
}
|
||||
// 2. 开始执行认证
|
||||
if (ObjectUtil.isNull(token)) {
|
||||
throw new CustomException(ResultCodeEnum.TOKEN_INVALID_ERROR);
|
||||
}
|
||||
Account account = null;
|
||||
try {
|
||||
String audience = JWT.decode(token).getAudience().get(0);
|
||||
String userId = audience.split("-")[0];
|
||||
String role = audience.split("-")[1];
|
||||
// 根据用户角色判断用户属于哪个数据库表 然后查询用户数据
|
||||
if (RoleEnum.ADMIN.name().equals(role)) {
|
||||
account = adminService.selectById(Integer.valueOf(userId));
|
||||
}
|
||||
if (RoleEnum.TEACHER.name().equals(role)) {
|
||||
account = teacherService.selectById(Integer.valueOf(userId));
|
||||
}
|
||||
if (RoleEnum.STUDENT.name().equals(role)) {
|
||||
account = studentService.selectById(Integer.valueOf(userId));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new CustomException(ResultCodeEnum.TOKEN_CHECK_ERROR);
|
||||
}
|
||||
// 根据token里面携带的用户ID去对应的角色表查询 没查到 所有报了这个“用户不存在”错误
|
||||
if (ObjectUtil.isNull(account)) {
|
||||
// 用户不存在
|
||||
throw new CustomException(ResultCodeEnum.TOKEN_CHECK_ERROR);
|
||||
}
|
||||
try {
|
||||
// 通过用户的密码作为密钥再次验证token的合法性
|
||||
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(account.getPassword())).build();
|
||||
jwtVerifier.verify(token); // 验证token
|
||||
} catch (JWTVerificationException e) {
|
||||
// 用户不存在
|
||||
throw new CustomException(ResultCodeEnum.TOKEN_CHECK_ERROR);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
21
src/main/java/com/example/common/config/WebConfig.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.example.common.config;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Resource
|
||||
private JWTInterceptor jwtInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(jwtInterceptor).addPathPatterns("/**")
|
||||
.excludePathPatterns("/")
|
||||
.excludePathPatterns("/login", "/register", "/files/**");
|
||||
}
|
||||
|
||||
}
|
26
src/main/java/com/example/common/enums/ResultCodeEnum.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.example.common.enums;
|
||||
|
||||
public enum ResultCodeEnum {
|
||||
|
||||
SUCCESS("200", "成功"),
|
||||
PARAM_ERROR("400", "参数异常"),
|
||||
TOKEN_INVALID_ERROR("401", "无效的token"),
|
||||
TOKEN_CHECK_ERROR("401", "token验证失败,请重新登录"),
|
||||
PARAM_LOST_ERROR("4001", "参数缺失"),
|
||||
|
||||
SYSTEM_ERROR("500", "系统异常"),
|
||||
USER_EXIST_ERROR("5001", "用户名已存在"),
|
||||
USER_NOT_LOGIN("5002", "用户未登录"),
|
||||
USER_ACCOUNT_ERROR("5003", "账号或密码错误"),
|
||||
USER_NOT_EXIST_ERROR("5004", "用户不存在"),
|
||||
PARAM_PASSWORD_ERROR("5005", "原密码输入错误"),
|
||||
;
|
||||
|
||||
public String code;
|
||||
public String msg;
|
||||
|
||||
ResultCodeEnum(String code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
10
src/main/java/com/example/common/enums/RoleEnum.java
Normal file
@ -0,0 +1,10 @@
|
||||
package com.example.common.enums;
|
||||
|
||||
public enum RoleEnum {
|
||||
// 管理员
|
||||
ADMIN,
|
||||
// 教师
|
||||
TEACHER,
|
||||
// 学生
|
||||
STUDENT
|
||||
}
|
87
src/main/java/com/example/controller/AdminController.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Admin;
|
||||
import com.example.service.AdminService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin")
|
||||
public class AdminController {
|
||||
|
||||
@Resource
|
||||
private AdminService adminService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Admin admin) {
|
||||
adminService.add(admin);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody Admin admin) {
|
||||
adminService.updateById(admin);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
adminService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
adminService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Admin admin = adminService.selectById(id);
|
||||
return Result.success(admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Admin admin) {
|
||||
List<Admin> list = adminService.selectAll(admin);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Admin admin,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Admin> pageInfo = adminService.selectPage(admin, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
}
|
93
src/main/java/com/example/controller/ArticleController.java
Normal file
@ -0,0 +1,93 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Article;
|
||||
import com.example.service.ArticleService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 帖子信息前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/article")
|
||||
public class ArticleController {
|
||||
|
||||
@Resource
|
||||
private ArticleService articleService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Article article) {
|
||||
articleService.add(article);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody Article article) {
|
||||
articleService.updateById(article);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
articleService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
articleService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Article article = articleService.selectById(id);
|
||||
return Result.success(article);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Article article) {
|
||||
List<Article> list = articleService.selectAll(article);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Article article,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Article> pageInfo = articleService.selectPage(article, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@GetMapping("/selectRandom")
|
||||
public Result selectRandom() {
|
||||
List<Article> list = articleService.selectRandom();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
}
|
87
src/main/java/com/example/controller/CourseController.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Course;
|
||||
import com.example.service.CourseService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 课程信息前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/course")
|
||||
public class CourseController {
|
||||
|
||||
@Resource
|
||||
private CourseService courseService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Course course) {
|
||||
courseService.add(course);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody Course course) {
|
||||
courseService.updateById(course);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
courseService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
courseService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Course course = courseService.selectById(id);
|
||||
return Result.success(course);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Course course) {
|
||||
List<Course> list = courseService.selectAll(course);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Course course,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Course> pageInfo = courseService.selectPage(course, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
}
|
87
src/main/java/com/example/controller/ExamPlanController.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.ExamPlan;
|
||||
import com.example.service.ExamPlanService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 考试安排前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/examPlan")
|
||||
public class ExamPlanController {
|
||||
|
||||
@Resource
|
||||
private ExamPlanService examPlanService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody ExamPlan examPlan) {
|
||||
examPlanService.add(examPlan);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody ExamPlan examPlan) {
|
||||
examPlanService.updateById(examPlan);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
examPlanService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
examPlanService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
ExamPlan examPlan = examPlanService.selectById(id);
|
||||
return Result.success(examPlan);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(ExamPlan examPlan) {
|
||||
List<ExamPlan> list = examPlanService.selectAll(examPlan);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(ExamPlan examPlan,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<ExamPlan> pageInfo = examPlanService.selectPage(examPlan, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
}
|
96
src/main/java/com/example/controller/FileController.java
Normal file
@ -0,0 +1,96 @@
|
||||
package com.example.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.example.common.Result;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/files")
|
||||
public class FileController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(FileController.class);
|
||||
|
||||
private static final String filePath = System.getProperty("user.dir") + "/files/";
|
||||
|
||||
@Value("${fileBaseUrl:}")
|
||||
private String fileBaseUrl;
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
public Result upload(MultipartFile file) {
|
||||
String fileName = file.getOriginalFilename();
|
||||
try {
|
||||
if (!FileUtil.isDirectory(filePath)) {
|
||||
FileUtil.mkdir(filePath);
|
||||
}
|
||||
fileName = System.currentTimeMillis() + "-" + fileName;
|
||||
String realFilePath = filePath + fileName;
|
||||
// 文件存储形式:时间戳-文件名
|
||||
FileUtil.writeBytes(file.getBytes(), realFilePath);
|
||||
} catch (Exception e) {
|
||||
log.error(fileName + "--文件上传失败", e);
|
||||
}
|
||||
String url = fileBaseUrl + "/files/download/" + fileName;
|
||||
return Result.success(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件
|
||||
*/
|
||||
@GetMapping("/download/{fileName}")
|
||||
public void download(@PathVariable String fileName, HttpServletResponse response) {
|
||||
OutputStream os;
|
||||
try {
|
||||
if (StrUtil.isNotEmpty(fileName)) {
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8));
|
||||
response.setContentType("application/octet-stream");
|
||||
byte[] bytes = FileUtil.readBytes(filePath + fileName);
|
||||
os = response.getOutputStream();
|
||||
os.write(bytes);
|
||||
os.flush();
|
||||
os.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("文件下载失败:" + fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* wang-editor编辑器文件上传接口
|
||||
*/
|
||||
@PostMapping("/wang/upload")
|
||||
public Map<String, Object> wangEditorUpload(MultipartFile file) {
|
||||
String flag = System.currentTimeMillis() + "";
|
||||
String fileName = file.getOriginalFilename();
|
||||
try {
|
||||
// 文件存储形式:时间戳-文件名
|
||||
FileUtil.writeBytes(file.getBytes(), filePath + flag + "-" + fileName);
|
||||
System.out.println(fileName + "--上传成功");
|
||||
Thread.sleep(1L);
|
||||
} catch (Exception e) {
|
||||
System.err.println(fileName + "--文件上传失败");
|
||||
}
|
||||
String http = fileBaseUrl + "/files/download/";
|
||||
Map<String, Object> resMap = new HashMap<>();
|
||||
// wangEditor上传图片成功后, 需要返回的参数
|
||||
resMap.put("errno", 0);
|
||||
resMap.put("data", CollUtil.newArrayList(Dict.create().set("url", http + flag + "-" + fileName)));
|
||||
return resMap;
|
||||
}
|
||||
}
|
87
src/main/java/com/example/controller/NoticeController.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Notice;
|
||||
import com.example.service.NoticeService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/notice")
|
||||
public class NoticeController {
|
||||
|
||||
@Resource
|
||||
private NoticeService noticeService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Notice notice) {
|
||||
noticeService.add(notice);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody Notice notice) {
|
||||
noticeService.updateById(notice);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
noticeService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
noticeService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Notice notice = noticeService.selectById(id);
|
||||
return Result.success(notice);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Notice notice) {
|
||||
List<Notice> list = noticeService.selectAll(notice);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Notice notice,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Notice> pageInfo = noticeService.selectPage(notice, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
}
|
87
src/main/java/com/example/controller/QuestionController.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Question;
|
||||
import com.example.service.QuestionService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 题目信息前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/question")
|
||||
public class QuestionController {
|
||||
|
||||
@Resource
|
||||
private QuestionService questionService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Question question) {
|
||||
questionService.add(question);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody Question question) {
|
||||
questionService.updateById(question);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
questionService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
questionService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Question question = questionService.selectById(id);
|
||||
return Result.success(question);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Question question) {
|
||||
List<Question> list = questionService.selectAll(question);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Question question,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Question> pageInfo = questionService.selectPage(question, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.QuestionType;
|
||||
import com.example.service.QuestionTypeService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 题型信息前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/questionType")
|
||||
public class QuestionTypeController {
|
||||
|
||||
@Resource
|
||||
private QuestionTypeService questionTypeService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody QuestionType questionType) {
|
||||
questionTypeService.add(questionType);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody QuestionType questionType) {
|
||||
questionTypeService.updateById(questionType);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
questionTypeService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
questionTypeService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
QuestionType questionType = questionTypeService.selectById(id);
|
||||
return Result.success(questionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(QuestionType questionType) {
|
||||
List<QuestionType> list = questionTypeService.selectAll(questionType);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(QuestionType questionType,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<QuestionType> pageInfo = questionTypeService.selectPage(questionType, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
}
|
94
src/main/java/com/example/controller/ScoreController.java
Normal file
@ -0,0 +1,94 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Answer;
|
||||
import com.example.entity.Score;
|
||||
import com.example.entity.TestPaper;
|
||||
import com.example.service.ScoreService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 试卷信息前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/score")
|
||||
public class ScoreController {
|
||||
|
||||
@Resource
|
||||
private ScoreService scoreService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody TestPaper testPaper) {
|
||||
scoreService.add(testPaper);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody Score score) {
|
||||
scoreService.updateById(score);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
scoreService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
scoreService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Score score = scoreService.selectById(id);
|
||||
return Result.success(score);
|
||||
}
|
||||
@GetMapping("/selectAnswer/{id}")
|
||||
public Result selectAnswer(@PathVariable Integer id) {
|
||||
List<Answer> list = scoreService.selectAnswer(id);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Score score) {
|
||||
List<Score> list = scoreService.selectAll(score);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Score score,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Score> pageInfo = scoreService.selectPage(score, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
}
|
87
src/main/java/com/example/controller/StudentController.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Student;
|
||||
import com.example.service.StudentService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学生信息前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/student")
|
||||
public class StudentController {
|
||||
|
||||
@Resource
|
||||
private StudentService studentService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Student student) {
|
||||
studentService.add(student);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody Student student) {
|
||||
studentService.updateById(student);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
studentService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
studentService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Student student = studentService.selectById(id);
|
||||
return Result.success(student);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Student student) {
|
||||
List<Student> list = studentService.selectAll(student);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Student student,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Student> pageInfo = studentService.selectPage(student, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
}
|
87
src/main/java/com/example/controller/TeacherController.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Teacher;
|
||||
import com.example.service.TeacherService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 教师信息前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/teacher")
|
||||
public class TeacherController {
|
||||
|
||||
@Resource
|
||||
private TeacherService teacherService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Teacher teacher) {
|
||||
teacherService.add(teacher);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody Teacher teacher) {
|
||||
teacherService.updateById(teacher);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
teacherService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
teacherService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Teacher teacher = teacherService.selectById(id);
|
||||
return Result.success(teacher);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Teacher teacher) {
|
||||
List<Teacher> list = teacherService.selectAll(teacher);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Teacher teacher,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Teacher> pageInfo = teacherService.selectPage(teacher, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
}
|
100
src/main/java/com/example/controller/TestPaperController.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.TestPaper;
|
||||
import com.example.service.TestPaperService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 试卷信息前端请求接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/testPaper")
|
||||
public class TestPaperController {
|
||||
|
||||
@Resource
|
||||
private TestPaperService testPaperService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody TestPaper testPaper) throws ParseException {
|
||||
testPaperService.add(testPaper);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result update(@RequestBody TestPaper testPaper) {
|
||||
testPaperService.updateById(testPaper);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result delete(@PathVariable Integer id) {
|
||||
testPaperService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result delete(@RequestBody List<Integer> ids) {
|
||||
testPaperService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
TestPaper testPaper = testPaperService.selectById(id);
|
||||
return Result.success(testPaper);
|
||||
}
|
||||
|
||||
@GetMapping("/check/{id}")
|
||||
public Result check(@PathVariable Integer id) {
|
||||
testPaperService.checkTestPaper(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(TestPaper testPaper) {
|
||||
List<TestPaper> list = testPaperService.selectAll(testPaper);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(TestPaper testPaper,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) throws ParseException {
|
||||
PageInfo<TestPaper> pageInfo = testPaperService.selectPage(testPaper, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@GetMapping("/selectRandom")
|
||||
public Result selectRandom() throws ParseException {
|
||||
List<TestPaper> list = testPaperService.selectRandom();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
}
|
79
src/main/java/com/example/controller/WebController.java
Normal file
@ -0,0 +1,79 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.service.AdminService;
|
||||
import com.example.service.StudentService;
|
||||
import com.example.service.TeacherService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
public class WebController {
|
||||
|
||||
@Resource
|
||||
private AdminService adminService;
|
||||
@Resource
|
||||
private TeacherService teacherService;
|
||||
@Resource
|
||||
private StudentService studentService;
|
||||
|
||||
/**
|
||||
* 默认请求接口
|
||||
*/
|
||||
@GetMapping("/")
|
||||
public Result hello () {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public Result login(@RequestBody Account account) {
|
||||
Account loginAccount = null;
|
||||
if (RoleEnum.ADMIN.name().equals(account.getRole())) {
|
||||
loginAccount = adminService.login(account);
|
||||
}
|
||||
if (RoleEnum.TEACHER.name().equals(account.getRole())) {
|
||||
loginAccount = teacherService.login(account);
|
||||
}
|
||||
if (RoleEnum.STUDENT.name().equals(account.getRole())) {
|
||||
loginAccount = studentService.login(account);
|
||||
}
|
||||
return Result.success(loginAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
@PostMapping("/register")
|
||||
public Result register(@RequestBody Account account) {
|
||||
if (RoleEnum.TEACHER.name().equals(account.getRole())) {
|
||||
teacherService.register(account);
|
||||
}
|
||||
if (RoleEnum.STUDENT.name().equals(account.getRole())) {
|
||||
studentService.register(account);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
@PutMapping("/updatePassword")
|
||||
public Result updatePassword(@RequestBody Account account) {
|
||||
if (RoleEnum.ADMIN.name().equals(account.getRole())) {
|
||||
adminService.updatePassword(account);
|
||||
}
|
||||
if (RoleEnum.TEACHER.name().equals(account.getRole())) {
|
||||
teacherService.updatePassword(account);
|
||||
}
|
||||
if (RoleEnum.STUDENT.name().equals(account.getRole())) {
|
||||
studentService.updatePassword(account);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
59
src/main/java/com/example/entity/Account.java
Normal file
@ -0,0 +1,59 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class Account {
|
||||
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String password;
|
||||
private String role;
|
||||
private String newPassword;
|
||||
private String token;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getNewPassword() {
|
||||
return newPassword;
|
||||
}
|
||||
|
||||
public void setNewPassword(String newPassword) {
|
||||
this.newPassword = newPassword;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
79
src/main/java/com/example/entity/Admin.java
Normal file
@ -0,0 +1,79 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class Admin extends Account {
|
||||
|
||||
/** 主键ID */
|
||||
private Integer id;
|
||||
/** 账号 */
|
||||
private String username;
|
||||
private String password;
|
||||
private String name;
|
||||
private String avatar;
|
||||
private String role;
|
||||
private String phone;
|
||||
private String email;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
70
src/main/java/com/example/entity/Answer.java
Normal file
@ -0,0 +1,70 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class Answer {
|
||||
|
||||
private String typeName;
|
||||
private Integer questionId;
|
||||
private Integer score;
|
||||
private String answer;
|
||||
private String newAnswer;
|
||||
private Integer result;
|
||||
|
||||
private String questionName;
|
||||
|
||||
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public void setTypeName(String typeName) {
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
public Integer getQuestionId() {
|
||||
return questionId;
|
||||
}
|
||||
|
||||
public void setQuestionId(Integer questionId) {
|
||||
this.questionId = questionId;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(Integer score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public String getAnswer() {
|
||||
return answer;
|
||||
}
|
||||
|
||||
public void setAnswer(String answer) {
|
||||
this.answer = answer;
|
||||
}
|
||||
|
||||
public String getNewAnswer() {
|
||||
return newAnswer;
|
||||
}
|
||||
|
||||
public void setNewAnswer(String newAnswer) {
|
||||
this.newAnswer = newAnswer;
|
||||
}
|
||||
|
||||
public Integer getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(Integer result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getQuestionName() {
|
||||
return questionName;
|
||||
}
|
||||
|
||||
public void setQuestionName(String questionName) {
|
||||
this.questionName = questionName;
|
||||
}
|
||||
}
|
77
src/main/java/com/example/entity/Article.java
Normal file
@ -0,0 +1,77 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class Article {
|
||||
private Integer id;
|
||||
private String title;
|
||||
private String img;
|
||||
private String content;
|
||||
private String time;
|
||||
private Integer studentId;
|
||||
|
||||
private String studentName;
|
||||
private String studentAvatar;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public void setImg(String img) {
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Integer getStudentId() {
|
||||
return studentId;
|
||||
}
|
||||
|
||||
public void setStudentId(Integer studentId) {
|
||||
this.studentId = studentId;
|
||||
}
|
||||
|
||||
public String getStudentName() {
|
||||
return studentName;
|
||||
}
|
||||
|
||||
public void setStudentName(String studentName) {
|
||||
this.studentName = studentName;
|
||||
}
|
||||
|
||||
public String getStudentAvatar() {
|
||||
return studentAvatar;
|
||||
}
|
||||
|
||||
public void setStudentAvatar(String studentAvatar) {
|
||||
this.studentAvatar = studentAvatar;
|
||||
}
|
||||
}
|
58
src/main/java/com/example/entity/Course.java
Normal file
@ -0,0 +1,58 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class Course {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String img;
|
||||
private Integer score;
|
||||
private Integer teacherId;
|
||||
private String teacherName;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public void setImg(String img) {
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(Integer score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Integer getTeacherId() {
|
||||
return teacherId;
|
||||
}
|
||||
|
||||
public void setTeacherId(Integer teacherId) {
|
||||
this.teacherId = teacherId;
|
||||
}
|
||||
|
||||
public String getTeacherName() {
|
||||
return teacherName;
|
||||
}
|
||||
|
||||
public void setTeacherName(String teacherName) {
|
||||
this.teacherName = teacherName;
|
||||
}
|
||||
}
|
40
src/main/java/com/example/entity/ExamPlan.java
Normal file
@ -0,0 +1,40 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class ExamPlan {
|
||||
private Integer id;
|
||||
private String title;
|
||||
private String content;
|
||||
private String time;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
}
|
40
src/main/java/com/example/entity/Notice.java
Normal file
@ -0,0 +1,40 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class Notice {
|
||||
private Integer id;
|
||||
private String title;
|
||||
private String content;
|
||||
private String time;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
}
|
153
src/main/java/com/example/entity/Question.java
Normal file
@ -0,0 +1,153 @@
|
||||
package com.example.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Question {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Integer courseId;
|
||||
private Integer teacherId;
|
||||
private Integer typeId;
|
||||
private String optionA;
|
||||
private String optionB;
|
||||
private String optionC;
|
||||
private String optionD;
|
||||
private String answer;
|
||||
|
||||
private String courseName;
|
||||
private String teacherName;
|
||||
private String typeName;
|
||||
private Integer typeScore;
|
||||
|
||||
private String newAnswer;
|
||||
private List<String> checkList = new ArrayList<>();
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getCourseId() {
|
||||
return courseId;
|
||||
}
|
||||
|
||||
public void setCourseId(Integer courseId) {
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public Integer getTeacherId() {
|
||||
return teacherId;
|
||||
}
|
||||
|
||||
public void setTeacherId(Integer teacherId) {
|
||||
this.teacherId = teacherId;
|
||||
}
|
||||
|
||||
public Integer getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public void setTypeId(Integer typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public String getOptionA() {
|
||||
return optionA;
|
||||
}
|
||||
|
||||
public void setOptionA(String optionA) {
|
||||
this.optionA = optionA;
|
||||
}
|
||||
|
||||
public String getOptionB() {
|
||||
return optionB;
|
||||
}
|
||||
|
||||
public void setOptionB(String optionB) {
|
||||
this.optionB = optionB;
|
||||
}
|
||||
|
||||
public String getOptionC() {
|
||||
return optionC;
|
||||
}
|
||||
|
||||
public void setOptionC(String optionC) {
|
||||
this.optionC = optionC;
|
||||
}
|
||||
|
||||
public String getOptionD() {
|
||||
return optionD;
|
||||
}
|
||||
|
||||
public void setOptionD(String optionD) {
|
||||
this.optionD = optionD;
|
||||
}
|
||||
|
||||
public String getAnswer() {
|
||||
return answer;
|
||||
}
|
||||
|
||||
public void setAnswer(String answer) {
|
||||
this.answer = answer;
|
||||
}
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public String getTeacherName() {
|
||||
return teacherName;
|
||||
}
|
||||
|
||||
public void setTeacherName(String teacherName) {
|
||||
this.teacherName = teacherName;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public void setTypeName(String typeName) {
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
public Integer getTypeScore() {
|
||||
return typeScore;
|
||||
}
|
||||
|
||||
public void setTypeScore(Integer typeScore) {
|
||||
this.typeScore = typeScore;
|
||||
}
|
||||
|
||||
public String getNewAnswer() {
|
||||
return newAnswer;
|
||||
}
|
||||
|
||||
public void setNewAnswer(String newAnswer) {
|
||||
this.newAnswer = newAnswer;
|
||||
}
|
||||
|
||||
public List<String> getCheckList() {
|
||||
return checkList;
|
||||
}
|
||||
|
||||
public void setCheckList(List<String> checkList) {
|
||||
this.checkList = checkList;
|
||||
}
|
||||
}
|
31
src/main/java/com/example/entity/QuestionType.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class QuestionType {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Integer score;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(Integer score) {
|
||||
this.score = score;
|
||||
}
|
||||
}
|
135
src/main/java/com/example/entity/Score.java
Normal file
@ -0,0 +1,135 @@
|
||||
package com.example.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Score {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Integer courseId;
|
||||
private Integer teacherId;
|
||||
private Integer studentId;
|
||||
private Integer paperId;
|
||||
private Integer score;
|
||||
private String status;
|
||||
private String answer;
|
||||
|
||||
private String courseName;
|
||||
private String teacherName;
|
||||
private String studentName;
|
||||
|
||||
private List<Question> questions;
|
||||
private List<Answer> answerData;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getCourseId() {
|
||||
return courseId;
|
||||
}
|
||||
|
||||
public void setCourseId(Integer courseId) {
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public Integer getTeacherId() {
|
||||
return teacherId;
|
||||
}
|
||||
|
||||
public void setTeacherId(Integer teacherId) {
|
||||
this.teacherId = teacherId;
|
||||
}
|
||||
|
||||
public Integer getStudentId() {
|
||||
return studentId;
|
||||
}
|
||||
|
||||
public void setStudentId(Integer studentId) {
|
||||
this.studentId = studentId;
|
||||
}
|
||||
|
||||
public Integer getPaperId() {
|
||||
return paperId;
|
||||
}
|
||||
|
||||
public void setPaperId(Integer paperId) {
|
||||
this.paperId = paperId;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(Integer score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getAnswer() {
|
||||
return answer;
|
||||
}
|
||||
|
||||
public void setAnswer(String answer) {
|
||||
this.answer = answer;
|
||||
}
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public String getTeacherName() {
|
||||
return teacherName;
|
||||
}
|
||||
|
||||
public void setTeacherName(String teacherName) {
|
||||
this.teacherName = teacherName;
|
||||
}
|
||||
|
||||
public String getStudentName() {
|
||||
return studentName;
|
||||
}
|
||||
|
||||
public void setStudentName(String studentName) {
|
||||
this.studentName = studentName;
|
||||
}
|
||||
|
||||
public List<Question> getQuestions() {
|
||||
return questions;
|
||||
}
|
||||
|
||||
public void setQuestions(List<Question> questions) {
|
||||
this.questions = questions;
|
||||
}
|
||||
|
||||
public List<Answer> getAnswerData() {
|
||||
return answerData;
|
||||
}
|
||||
|
||||
public void setAnswerData(List<Answer> answerData) {
|
||||
this.answerData = answerData;
|
||||
}
|
||||
}
|
88
src/main/java/com/example/entity/Student.java
Normal file
@ -0,0 +1,88 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class Student extends Account {
|
||||
|
||||
/** 主键ID */
|
||||
private Integer id;
|
||||
/** 账号 */
|
||||
private String username;
|
||||
private String password;
|
||||
private String name;
|
||||
private String avatar;
|
||||
private String role;
|
||||
private String phone;
|
||||
private String email;
|
||||
private String status;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
79
src/main/java/com/example/entity/Teacher.java
Normal file
@ -0,0 +1,79 @@
|
||||
package com.example.entity;
|
||||
|
||||
public class Teacher extends Account {
|
||||
|
||||
/** 主键ID */
|
||||
private Integer id;
|
||||
/** 账号 */
|
||||
private String username;
|
||||
private String password;
|
||||
private String name;
|
||||
private String avatar;
|
||||
private String role;
|
||||
private String phone;
|
||||
private String email;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
210
src/main/java/com/example/entity/TestPaper.java
Normal file
@ -0,0 +1,210 @@
|
||||
package com.example.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestPaper {
|
||||
// 数据库的基本字段
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Integer courseId;
|
||||
private Integer teacherId;
|
||||
private String type;
|
||||
private String start;
|
||||
private String end;
|
||||
private Integer time;
|
||||
private String questionIds; // 保存该试卷所有的题目的id的json字符串: "[1,2,3,4,5]"
|
||||
|
||||
// 关联课程信息表和教师信息表查询的额外的字段信息
|
||||
private String courseName;
|
||||
private String courseImg;
|
||||
private String teacherName;
|
||||
private String teacherAvatar;
|
||||
private String status;
|
||||
|
||||
// 用来接收前台那边传过来的业务字段
|
||||
private List<Integer> idList; // 接收前台那边手动选题选中的所有的题目的id
|
||||
private Integer choiceNum; // 接收前台那边自动组卷填写的单选题的数量
|
||||
private Integer multiChoiceNum; // 接收前台那边自动组卷填写的多选题的数量
|
||||
private Integer fillInNum; // 接收前台那边自动组卷填写的填空题的数量
|
||||
private Integer checkNum; // 接收前台那边自动组卷填写的判断题的数量
|
||||
private Integer answerNum; // 接收前台那边自动组卷填写的简答题的数量
|
||||
|
||||
private List<Question> questions;
|
||||
private Integer maxTime; // 存储时长(秒)
|
||||
|
||||
public List<Question> getQuestions() {
|
||||
return questions;
|
||||
}
|
||||
|
||||
public void setQuestions(List<Question> questions) {
|
||||
this.questions = questions;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getCourseId() {
|
||||
return courseId;
|
||||
}
|
||||
|
||||
public void setCourseId(Integer courseId) {
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public Integer getTeacherId() {
|
||||
return teacherId;
|
||||
}
|
||||
|
||||
public void setTeacherId(Integer teacherId) {
|
||||
this.teacherId = teacherId;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(String start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public String getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(String end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public Integer getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(Integer time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getQuestionIds() {
|
||||
return questionIds;
|
||||
}
|
||||
|
||||
public void setQuestionIds(String questionIds) {
|
||||
this.questionIds = questionIds;
|
||||
}
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public String getCourseImg() {
|
||||
return courseImg;
|
||||
}
|
||||
|
||||
public void setCourseImg(String courseImg) {
|
||||
this.courseImg = courseImg;
|
||||
}
|
||||
|
||||
public String getTeacherName() {
|
||||
return teacherName;
|
||||
}
|
||||
|
||||
public void setTeacherName(String teacherName) {
|
||||
this.teacherName = teacherName;
|
||||
}
|
||||
|
||||
public String getTeacherAvatar() {
|
||||
return teacherAvatar;
|
||||
}
|
||||
|
||||
public void setTeacherAvatar(String teacherAvatar) {
|
||||
this.teacherAvatar = teacherAvatar;
|
||||
}
|
||||
|
||||
public List<Integer> getIdList() {
|
||||
return idList;
|
||||
}
|
||||
|
||||
public void setIdList(List<Integer> idList) {
|
||||
this.idList = idList;
|
||||
}
|
||||
|
||||
public Integer getChoiceNum() {
|
||||
return choiceNum;
|
||||
}
|
||||
|
||||
public void setChoiceNum(Integer choiceNum) {
|
||||
this.choiceNum = choiceNum;
|
||||
}
|
||||
|
||||
public Integer getMultiChoiceNum() {
|
||||
return multiChoiceNum;
|
||||
}
|
||||
|
||||
public void setMultiChoiceNum(Integer multiChoiceNum) {
|
||||
this.multiChoiceNum = multiChoiceNum;
|
||||
}
|
||||
|
||||
public Integer getFillInNum() {
|
||||
return fillInNum;
|
||||
}
|
||||
|
||||
public void setFillInNum(Integer fillInNum) {
|
||||
this.fillInNum = fillInNum;
|
||||
}
|
||||
|
||||
public Integer getCheckNum() {
|
||||
return checkNum;
|
||||
}
|
||||
|
||||
public void setCheckNum(Integer checkNum) {
|
||||
this.checkNum = checkNum;
|
||||
}
|
||||
|
||||
public Integer getAnswerNum() {
|
||||
return answerNum;
|
||||
}
|
||||
|
||||
public void setAnswerNum(Integer answerNum) {
|
||||
this.answerNum = answerNum;
|
||||
}
|
||||
|
||||
public Integer getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
public void setMaxTime(Integer maxTime) {
|
||||
this.maxTime = maxTime;
|
||||
}
|
||||
}
|
35
src/main/java/com/example/exception/CustomException.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.example.exception;
|
||||
|
||||
import com.example.common.enums.ResultCodeEnum;
|
||||
|
||||
public class CustomException extends RuntimeException {
|
||||
|
||||
private String code;
|
||||
private String msg;
|
||||
|
||||
public CustomException(String code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public CustomException(ResultCodeEnum resultCodeEnum) {
|
||||
this.code = resultCodeEnum.code;
|
||||
this.msg = resultCodeEnum.msg;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.example.exception;
|
||||
|
||||
import cn.hutool.log.Log;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.example.common.Result;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@ControllerAdvice("com.example.controller")
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
private static final Log log = LogFactory.get();
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody // 返回json串
|
||||
public Result error(Exception e) {
|
||||
log.error("异常信息:", e);
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@ExceptionHandler(CustomException.class)
|
||||
@ResponseBody // 返回json串
|
||||
public Result error(CustomException e) {
|
||||
// log.error("异常信息:", e);
|
||||
return Result.error(e.getCode(), e.getMsg());
|
||||
}
|
||||
}
|
24
src/main/java/com/example/mapper/AdminMapper.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Admin;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AdminMapper {
|
||||
|
||||
int insert(Admin admin);
|
||||
|
||||
void updateById(Admin admin);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select * from `admin` where id = #{id}")
|
||||
Admin selectById(Integer id);
|
||||
|
||||
@Select("select * from `admin` where username = #{username}")
|
||||
Admin selectByUsername(String username);
|
||||
|
||||
List<Admin> selectAll(Admin admin);
|
||||
|
||||
}
|
23
src/main/java/com/example/mapper/ArticleMapper.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Article;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ArticleMapper {
|
||||
|
||||
int insert(Article article);
|
||||
|
||||
void updateById(Article article);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select article.*, student.name as studentName from `article` " +
|
||||
"left join student on article.student_id = student.id " +
|
||||
"where article.id = #{id}")
|
||||
Article selectById(Integer id);
|
||||
|
||||
List<Article> selectAll(Article article);
|
||||
|
||||
}
|
21
src/main/java/com/example/mapper/CourseMapper.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Course;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CourseMapper {
|
||||
|
||||
int insert(Course course);
|
||||
|
||||
void updateById(Course course);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select * from `course` where id = #{id}")
|
||||
Course selectById(Integer id);
|
||||
|
||||
List<Course> selectAll(Course course);
|
||||
|
||||
}
|
21
src/main/java/com/example/mapper/ExamPlanMapper.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.ExamPlan;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExamPlanMapper {
|
||||
|
||||
int insert(ExamPlan examPlan);
|
||||
|
||||
void updateById(ExamPlan examPlan);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select * from `examPlan` where id = #{id}")
|
||||
ExamPlan selectById(Integer id);
|
||||
|
||||
List<ExamPlan> selectAll(ExamPlan examPlan);
|
||||
|
||||
}
|
21
src/main/java/com/example/mapper/NoticeMapper.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Notice;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface NoticeMapper {
|
||||
|
||||
int insert(Notice notice);
|
||||
|
||||
void updateById(Notice notice);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select * from `notice` where id = #{id}")
|
||||
Notice selectById(Integer id);
|
||||
|
||||
List<Notice> selectAll(Notice notice);
|
||||
|
||||
}
|
26
src/main/java/com/example/mapper/QuestionMapper.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Question;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface QuestionMapper {
|
||||
|
||||
int insert(Question question);
|
||||
|
||||
void updateById(Question question);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select question.*, question_type.score as typeScore, question_type.name as typeName from `question` " +
|
||||
"left join question_type on question.type_id = question_type.id " +
|
||||
"where question.id = #{id}")
|
||||
Question selectById(Integer id);
|
||||
|
||||
List<Question> selectAll(Question question);
|
||||
|
||||
@Select("select * from question where course_id = #{courseId} and type_id = #{typeId}")
|
||||
List<Question> selectByCouserIdAndTypeId(@Param("courseId") Integer courseId, @Param("typeId") Integer typeId);
|
||||
}
|
23
src/main/java/com/example/mapper/QuestionTypeMapper.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.QuestionType;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface QuestionTypeMapper {
|
||||
|
||||
int insert(QuestionType questionType);
|
||||
|
||||
void updateById(QuestionType questionType);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select * from `question_type` where id = #{id}")
|
||||
QuestionType selectById(Integer id);
|
||||
|
||||
List<QuestionType> selectAll(QuestionType questionType);
|
||||
|
||||
@Select("select * from question_type where name = #{name}")
|
||||
List<QuestionType> selectByName(String name);
|
||||
}
|
21
src/main/java/com/example/mapper/ScoreMapper.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Score;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ScoreMapper {
|
||||
|
||||
int insert(Score score);
|
||||
|
||||
void updateById(Score score);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select * from `score` where id = #{id}")
|
||||
Score selectById(Integer id);
|
||||
|
||||
List<Score> selectAll(Score score);
|
||||
|
||||
}
|
24
src/main/java/com/example/mapper/StudentMapper.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Student;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface StudentMapper {
|
||||
|
||||
int insert(Student student);
|
||||
|
||||
void updateById(Student student);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select * from `student` where id = #{id}")
|
||||
Student selectById(Integer id);
|
||||
|
||||
@Select("select * from `student` where username = #{username}")
|
||||
Student selectByUsername(String username);
|
||||
|
||||
List<Student> selectAll(Student student);
|
||||
|
||||
}
|
24
src/main/java/com/example/mapper/TeacherMapper.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Teacher;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TeacherMapper {
|
||||
|
||||
int insert(Teacher teacher);
|
||||
|
||||
void updateById(Teacher teacher);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select * from `teacher` where id = #{id}")
|
||||
Teacher selectById(Integer id);
|
||||
|
||||
@Select("select * from `teacher` where username = #{username}")
|
||||
Teacher selectByUsername(String username);
|
||||
|
||||
List<Teacher> selectAll(Teacher teacher);
|
||||
|
||||
}
|
21
src/main/java/com/example/mapper/TestPaperMapper.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.TestPaper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TestPaperMapper {
|
||||
|
||||
int insert(TestPaper testPaper);
|
||||
|
||||
void updateById(TestPaper testPaper);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
@Select("select * from `test_paper` where id = #{id}")
|
||||
TestPaper selectById(Integer id);
|
||||
|
||||
List<TestPaper> selectAll(TestPaper testPaper);
|
||||
|
||||
}
|
103
src/main/java/com/example/service/AdminService.java
Normal file
@ -0,0 +1,103 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.example.common.Constants;
|
||||
import com.example.common.enums.ResultCodeEnum;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.entity.Admin;
|
||||
import com.example.exception.CustomException;
|
||||
import com.example.mapper.AdminMapper;
|
||||
import com.example.utils.TokenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class AdminService {
|
||||
|
||||
@Resource
|
||||
private AdminMapper adminMapper;
|
||||
|
||||
public void add(Admin admin) {
|
||||
Admin dbAdmin = adminMapper.selectByUsername(admin.getUsername());
|
||||
if (ObjectUtil.isNotNull(dbAdmin)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_EXIST_ERROR);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(admin.getPassword())) {
|
||||
admin.setPassword(Constants.USER_DEFAULT_PASSWORD);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(admin.getName())) {
|
||||
admin.setName(admin.getUsername());
|
||||
}
|
||||
admin.setRole(RoleEnum.ADMIN.name());
|
||||
adminMapper.insert(admin);
|
||||
}
|
||||
|
||||
public void updateById(Admin admin) {
|
||||
adminMapper.updateById(admin);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
adminMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
adminMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public Admin selectById(Integer id) {
|
||||
return adminMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<Admin> selectAll(Admin admin) {
|
||||
return adminMapper.selectAll(admin);
|
||||
}
|
||||
|
||||
public PageInfo<Admin> selectPage(Admin admin, Integer pageNum, Integer pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Admin> list = adminMapper.selectAll(admin);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public Admin login(Account account) {
|
||||
Admin dbAdmin = adminMapper.selectByUsername(account.getUsername());
|
||||
if (ObjectUtil.isNull(dbAdmin)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
|
||||
}
|
||||
if (!dbAdmin.getPassword().equals(account.getPassword())) {
|
||||
throw new CustomException(ResultCodeEnum.USER_ACCOUNT_ERROR);
|
||||
}
|
||||
// 生成token
|
||||
String token = TokenUtils.createToken(dbAdmin.getId() + "-" + dbAdmin.getRole(), dbAdmin.getPassword());
|
||||
dbAdmin.setToken(token);
|
||||
return dbAdmin;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public void updatePassword(Account account) {
|
||||
Admin dbAdmin = adminMapper.selectByUsername(account.getUsername());
|
||||
if (ObjectUtil.isNull(dbAdmin)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
|
||||
}
|
||||
if (!account.getPassword().equals(dbAdmin.getPassword())) {
|
||||
throw new CustomException(ResultCodeEnum.PARAM_PASSWORD_ERROR);
|
||||
}
|
||||
dbAdmin.setPassword(account.getNewPassword());
|
||||
adminMapper.updateById(dbAdmin);
|
||||
}
|
||||
|
||||
}
|
68
src/main/java/com/example/service/ArticleService.java
Normal file
@ -0,0 +1,68 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.example.entity.Account;
|
||||
import com.example.entity.Article;
|
||||
import com.example.mapper.ArticleMapper;
|
||||
import com.example.utils.TokenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 帖子信息业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class ArticleService {
|
||||
|
||||
@Resource
|
||||
private ArticleMapper articleMapper;
|
||||
|
||||
public void add(Article article) {
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
article.setStudentId(currentUser.getId());
|
||||
article.setTime(DateUtil.now());
|
||||
articleMapper.insert(article);
|
||||
}
|
||||
|
||||
public void updateById(Article article) {
|
||||
articleMapper.updateById(article);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
articleMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
articleMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public Article selectById(Integer id) {
|
||||
return articleMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<Article> selectAll(Article article) {
|
||||
return articleMapper.selectAll(article);
|
||||
}
|
||||
|
||||
public PageInfo<Article> selectPage(Article article, Integer pageNum, Integer pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Article> list = articleMapper.selectAll(article);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
public List<Article> selectRandom() {
|
||||
List<Article> list = articleMapper.selectAll(new Article());
|
||||
Collections.shuffle(list);
|
||||
if (list.size() > 3) {
|
||||
return list.subList(0, 3);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
63
src/main/java/com/example/service/CourseService.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.entity.Course;
|
||||
import com.example.mapper.CourseMapper;
|
||||
import com.example.utils.TokenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 课程信息业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class CourseService {
|
||||
|
||||
@Resource
|
||||
private CourseMapper courseMapper;
|
||||
|
||||
public void add(Course course) {
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
course.setTeacherId(currentUser.getId());
|
||||
courseMapper.insert(course);
|
||||
}
|
||||
|
||||
public void updateById(Course course) {
|
||||
courseMapper.updateById(course);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
courseMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
courseMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public Course selectById(Integer id) {
|
||||
return courseMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<Course> selectAll(Course course) {
|
||||
return courseMapper.selectAll(course);
|
||||
}
|
||||
|
||||
public PageInfo<Course> selectPage(Course course, Integer pageNum, Integer pageSize) {
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
if (RoleEnum.TEACHER.name().equals(currentUser.getRole())) {
|
||||
course.setTeacherId(currentUser.getId());
|
||||
}
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Course> list = courseMapper.selectAll(course);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
}
|
55
src/main/java/com/example/service/ExamPlanService.java
Normal file
@ -0,0 +1,55 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.example.entity.ExamPlan;
|
||||
import com.example.mapper.ExamPlanMapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 考试安排业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class ExamPlanService {
|
||||
|
||||
@Resource
|
||||
private ExamPlanMapper examPlanMapper;
|
||||
|
||||
public void add(ExamPlan examPlan) {
|
||||
examPlan.setTime(DateUtil.now());
|
||||
examPlanMapper.insert(examPlan);
|
||||
}
|
||||
|
||||
public void updateById(ExamPlan examPlan) {
|
||||
examPlanMapper.updateById(examPlan);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
examPlanMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
examPlanMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public ExamPlan selectById(Integer id) {
|
||||
return examPlanMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<ExamPlan> selectAll(ExamPlan examPlan) {
|
||||
return examPlanMapper.selectAll(examPlan);
|
||||
}
|
||||
|
||||
public PageInfo<ExamPlan> selectPage(ExamPlan examPlan, Integer pageNum, Integer pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<ExamPlan> list = examPlanMapper.selectAll(examPlan);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
}
|
55
src/main/java/com/example/service/NoticeService.java
Normal file
@ -0,0 +1,55 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.example.entity.Notice;
|
||||
import com.example.mapper.NoticeMapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class NoticeService {
|
||||
|
||||
@Resource
|
||||
private NoticeMapper noticeMapper;
|
||||
|
||||
public void add(Notice notice) {
|
||||
notice.setTime(DateUtil.now());
|
||||
noticeMapper.insert(notice);
|
||||
}
|
||||
|
||||
public void updateById(Notice notice) {
|
||||
noticeMapper.updateById(notice);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
noticeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
noticeMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public Notice selectById(Integer id) {
|
||||
return noticeMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<Notice> selectAll(Notice notice) {
|
||||
return noticeMapper.selectAll(notice);
|
||||
}
|
||||
|
||||
public PageInfo<Notice> selectPage(Notice notice, Integer pageNum, Integer pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Notice> list = noticeMapper.selectAll(notice);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
}
|
63
src/main/java/com/example/service/QuestionService.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.entity.Question;
|
||||
import com.example.mapper.QuestionMapper;
|
||||
import com.example.utils.TokenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 题目信息业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class QuestionService {
|
||||
|
||||
@Resource
|
||||
private QuestionMapper questionMapper;
|
||||
|
||||
public void add(Question question) {
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
question.setTeacherId(currentUser.getId());
|
||||
questionMapper.insert(question);
|
||||
}
|
||||
|
||||
public void updateById(Question question) {
|
||||
questionMapper.updateById(question);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
questionMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
questionMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public Question selectById(Integer id) {
|
||||
return questionMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<Question> selectAll(Question question) {
|
||||
return questionMapper.selectAll(question);
|
||||
}
|
||||
|
||||
public PageInfo<Question> selectPage(Question question, Integer pageNum, Integer pageSize) {
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
if (RoleEnum.TEACHER.name().equals(currentUser.getRole())) {
|
||||
question.setTeacherId(currentUser.getId());
|
||||
}
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Question> list = questionMapper.selectAll(question);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
}
|
66
src/main/java/com/example/service/QuestionTypeService.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.example.entity.QuestionType;
|
||||
import com.example.exception.CustomException;
|
||||
import com.example.mapper.QuestionTypeMapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 题型信息业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class QuestionTypeService {
|
||||
|
||||
@Resource
|
||||
private QuestionTypeMapper questionTypeMapper;
|
||||
|
||||
public void add(QuestionType questionType) {
|
||||
// 同一题型不能被重复添加
|
||||
List<QuestionType> list = questionTypeMapper.selectByName(questionType.getName());
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
throw new CustomException("-1", "题型名称不能重复");
|
||||
}
|
||||
questionTypeMapper.insert(questionType);
|
||||
}
|
||||
|
||||
public void updateById(QuestionType questionType) {
|
||||
// 同一题型不能被重复添加
|
||||
List<QuestionType> list = questionTypeMapper.selectByName(questionType.getName());
|
||||
if (CollectionUtil.isNotEmpty(list) && !questionType.getId().equals(list.get(0).getId())) {
|
||||
throw new CustomException("-1", "题型名称不能重复");
|
||||
}
|
||||
questionTypeMapper.updateById(questionType);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
questionTypeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
questionTypeMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public QuestionType selectById(Integer id) {
|
||||
return questionTypeMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<QuestionType> selectAll(QuestionType questionType) {
|
||||
return questionTypeMapper.selectAll(questionType);
|
||||
}
|
||||
|
||||
public PageInfo<QuestionType> selectPage(QuestionType questionType, Integer pageNum, Integer pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<QuestionType> list = questionTypeMapper.selectAll(questionType);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
}
|
165
src/main/java/com/example/service/ScoreService.java
Normal file
@ -0,0 +1,165 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.*;
|
||||
import com.example.mapper.QuestionMapper;
|
||||
import com.example.mapper.ScoreMapper;
|
||||
import com.example.utils.TokenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 成绩信息业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class ScoreService {
|
||||
|
||||
@Resource
|
||||
private ScoreMapper scoreMapper;
|
||||
@Resource
|
||||
private QuestionMapper questionMapper;
|
||||
|
||||
public void add(TestPaper testPaper) {
|
||||
|
||||
// 封装一下用户提交的试卷信息
|
||||
List<Answer> list = new ArrayList<>();
|
||||
for (Question question : testPaper.getQuestions()) {
|
||||
Answer answer = new Answer();
|
||||
answer.setTypeName(question.getTypeName());
|
||||
answer.setScore(question.getTypeScore());
|
||||
answer.setQuestionId(question.getId());
|
||||
if ("多选题".equals(question.getTypeName())) {
|
||||
List<String> checkList = question.getCheckList();
|
||||
answer.setNewAnswer(String.join(",", checkList));
|
||||
} else {
|
||||
answer.setNewAnswer(question.getNewAnswer());
|
||||
}
|
||||
answer.setAnswer(question.getAnswer());
|
||||
list.add(answer);
|
||||
}
|
||||
|
||||
Score score = new Score();
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
score.setStudentId(currentUser.getId());
|
||||
score.setTeacherId(testPaper.getTeacherId());
|
||||
score.setCourseId(testPaper.getCourseId());
|
||||
score.setName(testPaper.getName());
|
||||
score.setPaperId(testPaper.getId());
|
||||
score.setStatus("待阅卷");
|
||||
score.setAnswer(JSONUtil.toJsonStr(list));
|
||||
scoreMapper.insert(score);
|
||||
}
|
||||
|
||||
public void updateById(Score score) {
|
||||
List<Answer> answerData = score.getAnswerData();
|
||||
int total = 0;
|
||||
for (Answer answer : answerData) {
|
||||
if (ObjectUtil.isNotEmpty(answer.getResult())) {
|
||||
total += answer.getResult();
|
||||
}
|
||||
}
|
||||
score.setScore(total);
|
||||
score.setAnswer(JSONUtil.toJsonStr(answerData));
|
||||
score.setStatus("已阅卷");
|
||||
scoreMapper.updateById(score);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
scoreMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
scoreMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public Score selectById(Integer id) {
|
||||
List<Score> scores = scoreMapper.selectAll(new Score());
|
||||
Score score = scores.stream().filter(x -> x.getId().equals(id)).findFirst().get();
|
||||
String answer = score.getAnswer();
|
||||
List<Answer> list = JSONUtil.toList(answer, Answer.class);
|
||||
|
||||
List<Question> questions = new ArrayList<>();
|
||||
for (Answer ans : list) {
|
||||
Question question = questionMapper.selectById(ans.getQuestionId());
|
||||
if (ObjectUtil.isNotEmpty(question)) {
|
||||
if ("多选题".equals(ans.getTypeName())) {
|
||||
String newAnswer = ans.getNewAnswer(); // A,B,C
|
||||
List<String> checkList = Arrays.asList(newAnswer.split(","));
|
||||
question.setCheckList(checkList);
|
||||
} else {
|
||||
question.setNewAnswer(ans.getNewAnswer());
|
||||
}
|
||||
questions.add(question);
|
||||
}
|
||||
}
|
||||
score.setQuestions(questions);
|
||||
return score;
|
||||
}
|
||||
|
||||
public List<Score> selectAll(Score score) {
|
||||
return scoreMapper.selectAll(score);
|
||||
}
|
||||
|
||||
public PageInfo<Score> selectPage(Score score, Integer pageNum, Integer pageSize) {
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
if (RoleEnum.STUDENT.name().equals(currentUser.getRole())) {
|
||||
score.setStudentId(currentUser.getId());
|
||||
}
|
||||
if (RoleEnum.TEACHER.name().equals(currentUser.getRole())) {
|
||||
score.setTeacherId(currentUser.getId());
|
||||
}
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Score> list = scoreMapper.selectAll(score);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
public List<Answer> selectAnswer(Integer id) {
|
||||
Score score = scoreMapper.selectById(id);
|
||||
List<Answer> list = JSONUtil.toList(score.getAnswer(), Answer.class);
|
||||
// 客观题自动阅卷功能
|
||||
for (Answer answer : list) {
|
||||
Question question = questionMapper.selectById(answer.getQuestionId());
|
||||
answer.setQuestionName(question.getName());
|
||||
// 客观题自动打分
|
||||
if (!"简答题".equals(answer.getTypeName())) {
|
||||
if (!"多选题".equals(answer.getTypeName())) {
|
||||
if (answer.getAnswer().equals(answer.getNewAnswer())) {
|
||||
answer.setResult(answer.getScore());
|
||||
} else {
|
||||
answer.setResult(0);
|
||||
}
|
||||
} else {
|
||||
// 多选题 只要选项都对就行 顺序没有关系: A,B,C 和 B,A,C 是一样的
|
||||
List<String> standardList = Arrays.asList(answer.getAnswer().split(",")); // [A, B, C]
|
||||
List<String> studentList = Arrays.asList(answer.getNewAnswer().split(",")); // [B, A, C]
|
||||
for (String s : standardList) {
|
||||
if (!studentList.contains(s)) {
|
||||
answer.setResult(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isEmpty(answer.getResult())) {
|
||||
if (studentList.size() == standardList.size()) {
|
||||
answer.setResult(answer.getScore());
|
||||
} else {
|
||||
answer.setResult(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
113
src/main/java/com/example/service/StudentService.java
Normal file
@ -0,0 +1,113 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.example.common.Constants;
|
||||
import com.example.common.enums.ResultCodeEnum;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.entity.Student;
|
||||
import com.example.exception.CustomException;
|
||||
import com.example.mapper.StudentMapper;
|
||||
import com.example.utils.TokenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学生信息业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class StudentService {
|
||||
|
||||
@Resource
|
||||
private StudentMapper studentMapper;
|
||||
|
||||
public void add(Student student) {
|
||||
Student dbStudent = studentMapper.selectByUsername(student.getUsername());
|
||||
if (ObjectUtil.isNotNull(dbStudent)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_EXIST_ERROR);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(student.getPassword())) {
|
||||
student.setPassword(Constants.USER_DEFAULT_PASSWORD);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(student.getName())) {
|
||||
student.setName(student.getUsername());
|
||||
}
|
||||
student.setRole(RoleEnum.STUDENT.name());
|
||||
student.setStatus("待审核");
|
||||
studentMapper.insert(student);
|
||||
}
|
||||
|
||||
public void updateById(Student student) {
|
||||
studentMapper.updateById(student);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
studentMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
studentMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public Student selectById(Integer id) {
|
||||
return studentMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<Student> selectAll(Student student) {
|
||||
return studentMapper.selectAll(student);
|
||||
}
|
||||
|
||||
public PageInfo<Student> selectPage(Student student, Integer pageNum, Integer pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Student> list = studentMapper.selectAll(student);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public Student login(Account account) {
|
||||
Student dbStudent = studentMapper.selectByUsername(account.getUsername());
|
||||
if (ObjectUtil.isNull(dbStudent)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
|
||||
}
|
||||
if (!dbStudent.getPassword().equals(account.getPassword())) {
|
||||
throw new CustomException(ResultCodeEnum.USER_ACCOUNT_ERROR);
|
||||
}
|
||||
if (!"审核通过".equals(dbStudent.getStatus())) {
|
||||
throw new CustomException("-1", "您的注册信息尚未审核通过,暂不允许登录,请耐心等待管理员审核");
|
||||
}
|
||||
// 生成token
|
||||
String token = TokenUtils.createToken(dbStudent.getId() + "-" + dbStudent.getRole(), dbStudent.getPassword());
|
||||
dbStudent.setToken(token);
|
||||
return dbStudent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public void updatePassword(Account account) {
|
||||
Student dbStudent = studentMapper.selectByUsername(account.getUsername());
|
||||
if (ObjectUtil.isNull(dbStudent)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
|
||||
}
|
||||
if (!account.getPassword().equals(dbStudent.getPassword())) {
|
||||
throw new CustomException(ResultCodeEnum.PARAM_PASSWORD_ERROR);
|
||||
}
|
||||
dbStudent.setPassword(account.getNewPassword());
|
||||
studentMapper.updateById(dbStudent);
|
||||
}
|
||||
|
||||
public void register(Account account) {
|
||||
Student student = new Student();
|
||||
BeanUtils.copyProperties(account, student);
|
||||
add(student);
|
||||
}
|
||||
}
|
109
src/main/java/com/example/service/TeacherService.java
Normal file
@ -0,0 +1,109 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.example.common.Constants;
|
||||
import com.example.common.enums.ResultCodeEnum;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.entity.Teacher;
|
||||
import com.example.exception.CustomException;
|
||||
import com.example.mapper.TeacherMapper;
|
||||
import com.example.utils.TokenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 教师信息业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class TeacherService {
|
||||
|
||||
@Resource
|
||||
private TeacherMapper teacherMapper;
|
||||
|
||||
public void add(Teacher teacher) {
|
||||
Teacher dbTeacher = teacherMapper.selectByUsername(teacher.getUsername());
|
||||
if (ObjectUtil.isNotNull(dbTeacher)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_EXIST_ERROR);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(teacher.getPassword())) {
|
||||
teacher.setPassword(Constants.USER_DEFAULT_PASSWORD);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(teacher.getName())) {
|
||||
teacher.setName(teacher.getUsername());
|
||||
}
|
||||
teacher.setRole(RoleEnum.TEACHER.name());
|
||||
teacherMapper.insert(teacher);
|
||||
}
|
||||
|
||||
public void updateById(Teacher teacher) {
|
||||
teacherMapper.updateById(teacher);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
teacherMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
teacherMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public Teacher selectById(Integer id) {
|
||||
return teacherMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<Teacher> selectAll(Teacher teacher) {
|
||||
return teacherMapper.selectAll(teacher);
|
||||
}
|
||||
|
||||
public PageInfo<Teacher> selectPage(Teacher teacher, Integer pageNum, Integer pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Teacher> list = teacherMapper.selectAll(teacher);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public Teacher login(Account account) {
|
||||
Teacher dbTeacher = teacherMapper.selectByUsername(account.getUsername());
|
||||
if (ObjectUtil.isNull(dbTeacher)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
|
||||
}
|
||||
if (!dbTeacher.getPassword().equals(account.getPassword())) {
|
||||
throw new CustomException(ResultCodeEnum.USER_ACCOUNT_ERROR);
|
||||
}
|
||||
// 生成token
|
||||
String token = TokenUtils.createToken(dbTeacher.getId() + "-" + dbTeacher.getRole(), dbTeacher.getPassword());
|
||||
dbTeacher.setToken(token);
|
||||
return dbTeacher;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public void updatePassword(Account account) {
|
||||
Teacher dbTeacher = teacherMapper.selectByUsername(account.getUsername());
|
||||
if (ObjectUtil.isNull(dbTeacher)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
|
||||
}
|
||||
if (!account.getPassword().equals(dbTeacher.getPassword())) {
|
||||
throw new CustomException(ResultCodeEnum.PARAM_PASSWORD_ERROR);
|
||||
}
|
||||
dbTeacher.setPassword(account.getNewPassword());
|
||||
teacherMapper.updateById(dbTeacher);
|
||||
}
|
||||
|
||||
public void register(Account account) {
|
||||
Teacher teacher = new Teacher();
|
||||
BeanUtils.copyProperties(account, teacher);
|
||||
add(teacher);
|
||||
}
|
||||
}
|
209
src/main/java/com/example/service/TestPaperService.java
Normal file
@ -0,0 +1,209 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.*;
|
||||
import com.example.exception.CustomException;
|
||||
import com.example.mapper.*;
|
||||
import com.example.utils.TokenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 试卷信息业务层方法
|
||||
*/
|
||||
@Service
|
||||
public class TestPaperService {
|
||||
|
||||
@Resource
|
||||
private TestPaperMapper testPaperMapper;
|
||||
@Resource
|
||||
private QuestionMapper questionMapper;
|
||||
@Resource
|
||||
private CourseMapper courseMapper;
|
||||
@Resource
|
||||
private TeacherMapper teacherMapper;
|
||||
@Resource
|
||||
private ScoreMapper scoreMapper;
|
||||
|
||||
public void add(TestPaper testPaper) throws ParseException {
|
||||
// 先要校验前台传过来的数据
|
||||
check(testPaper);
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
testPaper.setTeacherId(currentUser.getId());
|
||||
// 手动选题
|
||||
if ("手动选题".equals(testPaper.getType())) {
|
||||
List<Integer> idList = testPaper.getIdList();
|
||||
testPaper.setQuestionIds(JSONUtil.toJsonStr(idList));
|
||||
}
|
||||
if ("自动组卷".equals(testPaper.getType())) {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
// 自动选取每个题型的题目
|
||||
randomQuestionIds(testPaper, testPaper.getChoiceNum(), list, 1, "单选题");
|
||||
randomQuestionIds(testPaper, testPaper.getMultiChoiceNum(), list, 2, "多选题");
|
||||
randomQuestionIds(testPaper, testPaper.getCheckNum(), list, 3, "判断题");
|
||||
randomQuestionIds(testPaper, testPaper.getFillInNum(), list, 4, "填空题");
|
||||
randomQuestionIds(testPaper, testPaper.getAnswerNum(), list, 5, "简答题");
|
||||
|
||||
testPaper.setQuestionIds(JSONUtil.toJsonStr(list));
|
||||
}
|
||||
|
||||
testPaperMapper.insert(testPaper);
|
||||
}
|
||||
|
||||
private void randomQuestionIds(TestPaper testPaper, Integer choiceNum, List<Integer> list, Integer typeId, String typeName) {
|
||||
List<Question> choiceList = questionMapper.selectByCouserIdAndTypeId(testPaper.getCourseId(), typeId);
|
||||
if (choiceList.size() < choiceNum) {
|
||||
throw new CustomException("-1", "您的题库里该课程的" + typeName + "数量不足,请减少出题的" + typeName + "数量或者增加题库里该课程的" + typeName + "数量");
|
||||
}
|
||||
Collections.shuffle(choiceList); // 打乱
|
||||
List<Integer> questions = choiceList.subList(0, choiceNum).stream().map(Question::getId).toList();
|
||||
list.addAll(questions);
|
||||
}
|
||||
|
||||
public void check (TestPaper testPaper) throws ParseException {
|
||||
if (ObjectUtil.isEmpty(testPaper.getName())
|
||||
|| ObjectUtil.isEmpty(testPaper.getCourseId())
|
||||
|| ObjectUtil.isEmpty(testPaper.getStart())
|
||||
|| ObjectUtil.isEmpty(testPaper.getEnd())
|
||||
|| ObjectUtil.isEmpty(testPaper.getTime())
|
||||
|| ObjectUtil.isEmpty(testPaper.getType())
|
||||
) {
|
||||
throw new CustomException("-1", "请填写完整您要提交的试卷信息");
|
||||
}
|
||||
// 开始时间要早于结束时间
|
||||
long start = new SimpleDateFormat("yyyy-MM-dd").parse(testPaper.getStart()).getTime();
|
||||
long end = new SimpleDateFormat("yyyy-MM-dd").parse(testPaper.getEnd()).getTime();
|
||||
if (start >= end) {
|
||||
throw new CustomException("-1", "开始时间必须早于结束时间");
|
||||
}
|
||||
// 校验手动选题
|
||||
if ("手动选题".equals(testPaper.getType())) {
|
||||
if (CollectionUtil.isEmpty(testPaper.getIdList())) {
|
||||
throw new CustomException("-1", "手动选题方式,您需要选择具体的题目");
|
||||
}
|
||||
}
|
||||
// 自动组卷校验
|
||||
if ("自动组卷".equals(testPaper.getType())) {
|
||||
if (ObjectUtil.isEmpty(testPaper.getChoiceNum())
|
||||
|| ObjectUtil.isEmpty(testPaper.getMultiChoiceNum())
|
||||
|| ObjectUtil.isEmpty(testPaper.getFillInNum())
|
||||
|| ObjectUtil.isEmpty(testPaper.getCheckNum())
|
||||
|| ObjectUtil.isEmpty(testPaper.getAnswerNum())
|
||||
) {
|
||||
throw new CustomException("-1", "请填写题型的数量,如果不需要某个题型,请输入0");
|
||||
}
|
||||
if (testPaper.getChoiceNum() < 0
|
||||
|| testPaper.getMultiChoiceNum() < 0
|
||||
|| testPaper.getFillInNum() < 0
|
||||
|| testPaper.getCheckNum() < 0
|
||||
|| testPaper.getAnswerNum() < 0
|
||||
) {
|
||||
throw new CustomException("-1", "题型的数量不能小于0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateById(TestPaper testPaper) {
|
||||
testPaperMapper.updateById(testPaper);
|
||||
}
|
||||
|
||||
public void deleteById(Integer id) {
|
||||
testPaperMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
testPaperMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public TestPaper selectById(Integer id) {
|
||||
TestPaper testPaper = testPaperMapper.selectById(id);
|
||||
Course course = courseMapper.selectById(testPaper.getCourseId());
|
||||
if (ObjectUtil.isNotEmpty(course)) {
|
||||
testPaper.setCourseName(course.getName());
|
||||
}
|
||||
Teacher teacher = teacherMapper.selectById(testPaper.getTeacherId());
|
||||
if (ObjectUtil.isNotEmpty(teacher)) {
|
||||
testPaper.setTeacherName(teacher.getName());
|
||||
}
|
||||
// 开始组装该试卷里所有的题目数据
|
||||
String questionIds = testPaper.getQuestionIds();
|
||||
List<Integer> idList = JSONUtil.toList(questionIds, Integer.class);
|
||||
List<Question> questions = new ArrayList<>();
|
||||
for (Integer questionId : idList) {
|
||||
Question question = questionMapper.selectById(questionId);
|
||||
questions.add(question);
|
||||
}
|
||||
testPaper.setQuestions(questions);
|
||||
testPaper.setMaxTime(testPaper.getTime() * 60);
|
||||
return testPaper;
|
||||
}
|
||||
|
||||
public List<TestPaper> selectAll(TestPaper testPaper) {
|
||||
return testPaperMapper.selectAll(testPaper);
|
||||
}
|
||||
|
||||
public PageInfo<TestPaper> selectPage(TestPaper testPaper, Integer pageNum, Integer pageSize) throws ParseException {
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
if (RoleEnum.TEACHER.name().equals(currentUser.getRole())) {
|
||||
testPaper.setTeacherId(currentUser.getId());
|
||||
}
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<TestPaper> list = testPaperMapper.selectAll(testPaper);
|
||||
// 初始化每个考试的状态
|
||||
initStatus(list);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
private static void initStatus(List<TestPaper> list) throws ParseException {
|
||||
for (TestPaper paper : list) {
|
||||
long now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(DateUtil.now()).getTime();
|
||||
long start = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(paper.getStart() + " 00:00:00").getTime();
|
||||
long end = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(paper.getEnd() + " 23:59:59").getTime();
|
||||
if (now < start) {
|
||||
paper.setStatus("未开始");
|
||||
} else if (now > end) {
|
||||
paper.setStatus("已结束");
|
||||
} else {
|
||||
paper.setStatus("进行中");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkTestPaper(Integer id) {
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
Score score = new Score();
|
||||
score.setPaperId(id);
|
||||
score.setStudentId(currentUser.getId());
|
||||
List<Score> scores = scoreMapper.selectAll(score);
|
||||
if (CollectionUtil.isNotEmpty(scores)) {
|
||||
throw new CustomException("-1", "该门考试您已经提交过试卷了,入口已关闭");
|
||||
}
|
||||
}
|
||||
|
||||
public List<TestPaper> selectRandom() throws ParseException {
|
||||
List<TestPaper> list = testPaperMapper.selectAll(new TestPaper());
|
||||
Collections.shuffle(list);
|
||||
// 初始化每个考试的状态
|
||||
initStatus(list);
|
||||
if (list.size() > 4) {
|
||||
return list.subList(0, 4);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
84
src/main/java/com/example/utils/TokenUtils.java
Normal file
@ -0,0 +1,84 @@
|
||||
package com.example.utils;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.example.common.Constants;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.service.AdminService;
|
||||
import com.example.service.StudentService;
|
||||
import com.example.service.TeacherService;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Token工具类
|
||||
*/
|
||||
@Component
|
||||
public class TokenUtils {
|
||||
private static final Logger log = LoggerFactory.getLogger(TokenUtils.class);
|
||||
|
||||
@Resource
|
||||
private AdminService adminService;
|
||||
@Resource
|
||||
private TeacherService teacherService;
|
||||
@Resource
|
||||
private StudentService studentService;
|
||||
|
||||
private static AdminService staticAdminService;
|
||||
private static TeacherService staticTeacherService;
|
||||
private static StudentService staticStudentService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
staticAdminService = adminService;
|
||||
staticTeacherService = teacherService;
|
||||
staticStudentService = studentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成JWT token
|
||||
*/
|
||||
public static String createToken(String data, String sign) {
|
||||
// audience是存储数据的一个媒介 存储用户ID和用户的角色 1-ADMIN
|
||||
return JWT.create().withAudience(data)
|
||||
.withExpiresAt(DateUtil.offsetDay(new Date(), 1)) // 设置过期时间1天后
|
||||
.sign(Algorithm.HMAC256(sign));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户
|
||||
*/
|
||||
public static Account getCurrentUser() {
|
||||
try {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
String token = request.getHeader(Constants.TOKEN);
|
||||
String audience = JWT.decode(token).getAudience().get(0);
|
||||
String[] userRole = audience.split("-");
|
||||
Integer userId = Integer.valueOf(userRole[0]);
|
||||
String role = userRole[1];
|
||||
if (RoleEnum.ADMIN.name().equals(role)) {
|
||||
return staticAdminService.selectById(userId);
|
||||
}
|
||||
if (RoleEnum.TEACHER.name().equals(role)) {
|
||||
return staticTeacherService.selectById(userId);
|
||||
}
|
||||
if (RoleEnum.STUDENT.name().equals(role)) {
|
||||
return staticStudentService.selectById(userId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取当前登录用户出错", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
19
src/main/resources/application.yml
Normal file
@ -0,0 +1,19 @@
|
||||
server:
|
||||
port: 9090
|
||||
|
||||
# 数据库配置
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
username: root
|
||||
password: 123456
|
||||
url: jdbc:mysql://localhost:33060/java-experiment?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8&allowPublicKeyRetrieval=true
|
||||
|
||||
# 配置mybatis实体和xml映射
|
||||
mybatis:
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
map-underscore-to-camel-case: true
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
|
||||
fileBaseUrl: http://localhost:${server.port}
|
71
src/main/resources/mapper/AdminMapper.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.AdminMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.Admin">
|
||||
select * from `admin`
|
||||
<where>
|
||||
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `admin`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into admin (username, password, ...) values ('admin', 'admin', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.Admin" useGeneratedKeys="true">
|
||||
insert into `admin`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="username != null">username,</if>
|
||||
<if test="password != null">password,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="phone != null">phone,</if>
|
||||
<if test="email != null">email,</if>
|
||||
<if test="avatar != null">avatar,</if>
|
||||
<if test="role != null">role,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="username != null">#{username},</if>
|
||||
<if test="password != null">#{password},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="phone != null">#{phone},</if>
|
||||
<if test="email != null">#{email},</if>
|
||||
<if test="avatar != null">#{avatar},</if>
|
||||
<if test="role != null">#{role},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.Admin">
|
||||
update `admin`
|
||||
<set>
|
||||
<if test="username != null">
|
||||
username = #{username},
|
||||
</if>
|
||||
<if test="password != null">
|
||||
password = #{password},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="phone != null">
|
||||
phone = #{phone},
|
||||
</if>
|
||||
<if test="email != null">
|
||||
email = #{email},
|
||||
</if>
|
||||
<if test="avatar != null">
|
||||
avatar = #{avatar},
|
||||
</if>
|
||||
<if test="role != null">
|
||||
role = #{role},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
60
src/main/resources/mapper/ArticleMapper.xml
Normal file
@ -0,0 +1,60 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.ArticleMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.Article">
|
||||
select article.*, student.name as studentName, student.avatar as studentAvatar from `article`
|
||||
left join student on article.student_id = student.id
|
||||
<where>
|
||||
<if test="title != null"> and title like concat('%', #{title}, '%')</if>
|
||||
<if test="studentId != null"> and student_id = #{studentId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `article`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into article (username, password, ...) values ('article', 'article', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.Article" useGeneratedKeys="true">
|
||||
insert into `article`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="title != null">title,</if>
|
||||
<if test="content != null">content,</if>
|
||||
<if test="time != null">time,</if>
|
||||
<if test="img != null">img,</if>
|
||||
<if test="studentId != null">student_id,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="title != null">#{title},</if>
|
||||
<if test="content != null">#{content},</if>
|
||||
<if test="time != null">#{time},</if>
|
||||
<if test="img != null">#{img},</if>
|
||||
<if test="studentId != null">#{studentId},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.Article">
|
||||
update `article`
|
||||
<set>
|
||||
<if test="title != null">
|
||||
title = #{title},
|
||||
</if>
|
||||
<if test="content != null">
|
||||
content = #{content},
|
||||
</if>
|
||||
<if test="time != null">
|
||||
time = #{time},
|
||||
</if>
|
||||
<if test="img != null">
|
||||
img = #{img},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
55
src/main/resources/mapper/CourseMapper.xml
Normal file
@ -0,0 +1,55 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.CourseMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.Course">
|
||||
select course.*, teacher.name as teacherName from `course`
|
||||
left join teacher on course.teacher_id = teacher.id
|
||||
<where>
|
||||
<if test="name != null"> and course.name like concat('%', #{name}, '%')</if>
|
||||
<if test="teacherId != null"> and teacher_id = #{teacherId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `course`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into course (username, password, ...) values ('course', 'course', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.Course" useGeneratedKeys="true">
|
||||
insert into `course`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="img != null">img,</if>
|
||||
<if test="score != null">score,</if>
|
||||
<if test="teacherId != null">teacher_id,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="img != null">#{img},</if>
|
||||
<if test="score != null">#{score},</if>
|
||||
<if test="teacherId != null">#{teacherId},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.Course">
|
||||
update `course`
|
||||
<set>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="img != null">
|
||||
img = #{img},
|
||||
</if>
|
||||
<if test="score != null">
|
||||
score = #{score},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
51
src/main/resources/mapper/ExamPlanMapper.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.ExamPlanMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.ExamPlan">
|
||||
select * from `exam_plan`
|
||||
<where>
|
||||
<if test="title != null"> and title like concat('%', #{title}, '%')</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `exam_plan`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into exam_plan (username, password, ...) values ('exam_plan', 'exam_plan', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.ExamPlan" useGeneratedKeys="true">
|
||||
insert into `exam_plan`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="title != null">title,</if>
|
||||
<if test="content != null">content,</if>
|
||||
<if test="time != null">time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="title != null">#{title},</if>
|
||||
<if test="content != null">#{content},</if>
|
||||
<if test="time != null">#{time},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.ExamPlan">
|
||||
update `exam_plan`
|
||||
<set>
|
||||
<if test="title != null">
|
||||
title = #{title},
|
||||
</if>
|
||||
<if test="content != null">
|
||||
content = #{content},
|
||||
</if>
|
||||
<if test="time != null">
|
||||
time = #{time},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
51
src/main/resources/mapper/NoticeMapper.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.NoticeMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.Notice">
|
||||
select * from `notice`
|
||||
<where>
|
||||
<if test="title != null"> and title like concat('%', #{title}, '%')</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `notice`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into notice (username, password, ...) values ('notice', 'notice', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.Notice" useGeneratedKeys="true">
|
||||
insert into `notice`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="title != null">title,</if>
|
||||
<if test="content != null">content,</if>
|
||||
<if test="time != null">time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="title != null">#{title},</if>
|
||||
<if test="content != null">#{content},</if>
|
||||
<if test="time != null">#{time},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.Notice">
|
||||
update `notice`
|
||||
<set>
|
||||
<if test="title != null">
|
||||
title = #{title},
|
||||
</if>
|
||||
<if test="content != null">
|
||||
content = #{content},
|
||||
</if>
|
||||
<if test="time != null">
|
||||
time = #{time},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
86
src/main/resources/mapper/QuestionMapper.xml
Normal file
@ -0,0 +1,86 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.QuestionMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.Question">
|
||||
select
|
||||
question.*, course.name as courseName, teacher.name as teacherName,
|
||||
question_type.name as typeName, question_type.score as typeScore
|
||||
from `question`
|
||||
left join course on question.course_id = course.id
|
||||
left join teacher on question.teacher_id = teacher.id
|
||||
left join question_type on question.type_id = question_type.id
|
||||
<where>
|
||||
<if test="name != null"> and question.name like concat('%', #{name}, '%')</if>
|
||||
<if test="teacherId != null"> and question.teacher_id = #{teacherId}</if>
|
||||
<if test="courseId != null"> and question.course_id = #{courseId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `question`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into question (username, password, ...) values ('question', 'question', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.Question" useGeneratedKeys="true">
|
||||
insert into `question`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="courseId != null">course_id,</if>
|
||||
<if test="teacherId != null">teacher_id,</if>
|
||||
<if test="typeId != null">type_id,</if>
|
||||
<if test="optionA != null">option_a,</if>
|
||||
<if test="optionB != null">option_b,</if>
|
||||
<if test="optionC != null">option_c,</if>
|
||||
<if test="optionD != null">option_d,</if>
|
||||
<if test="answer != null">answer,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="courseId != null">#{courseId},</if>
|
||||
<if test="teacherId != null">#{teacherId},</if>
|
||||
<if test="typeId != null">#{typeId},</if>
|
||||
<if test="optionA != null">#{optionA},</if>
|
||||
<if test="optionB != null">#{optionB},</if>
|
||||
<if test="optionC != null">#{optionC},</if>
|
||||
<if test="optionD != null">#{optionD},</if>
|
||||
<if test="answer != null">#{answer},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.Question">
|
||||
update `question`
|
||||
<set>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="courseId != null">
|
||||
course_id = #{courseId},
|
||||
</if>
|
||||
<if test="typeId != null">
|
||||
type_id = #{typeId},
|
||||
</if>
|
||||
<if test="optionA != null">
|
||||
option_a = #{optionA},
|
||||
</if>
|
||||
<if test="optionB != null">
|
||||
option_b = #{optionB},
|
||||
</if>
|
||||
<if test="optionC != null">
|
||||
option_c = #{optionC},
|
||||
</if>
|
||||
<if test="optionD != null">
|
||||
option_d = #{optionD},
|
||||
</if>
|
||||
<if test="answer != null">
|
||||
answer = #{answer},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
46
src/main/resources/mapper/QuestionTypeMapper.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.QuestionTypeMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.QuestionType">
|
||||
select * from `question_type`
|
||||
<where>
|
||||
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `question_type`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into question_type (username, password, ...) values ('question_type', 'question_type', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.QuestionType" useGeneratedKeys="true">
|
||||
insert into `question_type`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="score != null">score,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="score != null">#{score},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.QuestionType">
|
||||
update `question_type`
|
||||
<set>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="score != null">
|
||||
score = #{score},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
66
src/main/resources/mapper/ScoreMapper.xml
Normal file
@ -0,0 +1,66 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.ScoreMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.Score">
|
||||
select score.*, course.name as courseName, teacher.name as teacherName, student.name as studentName from `score`
|
||||
left join course on score.course_id = course.id
|
||||
left join teacher on score.teacher_id = teacher.id
|
||||
left join student on score.student_id = student.id
|
||||
<where>
|
||||
<if test="name != null"> and score.name like concat('%', #{name}, '%')</if>
|
||||
<if test="studentId != null"> and score.student_id = #{studentId}</if>
|
||||
<if test="teacherId != null"> and score.teacher_id = #{teacherId}</if>
|
||||
<if test="paperId != null"> and score.paper_id = #{paperId}</if>
|
||||
<if test="courseName != null"> and course.name like concat('%', #{courseName}, '%')</if>
|
||||
<if test="status != null"> and score.status = #{status}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `score`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into score (username, password, ...) values ('score', 'score', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.Score" useGeneratedKeys="true">
|
||||
insert into `score`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="courseId != null">course_id,</if>
|
||||
<if test="teacherId != null">teacher_id,</if>
|
||||
<if test="studentId != null">student_id,</if>
|
||||
<if test="paperId != null">paper_id,</if>
|
||||
<if test="score != null">score,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="answer != null">answer,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="courseId != null">#{courseId},</if>
|
||||
<if test="teacherId != null">#{teacherId},</if>
|
||||
<if test="studentId != null">#{studentId},</if>
|
||||
<if test="paperId != null">#{paperId},</if>
|
||||
<if test="score != null">#{score},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="answer != null">#{answer},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.Score">
|
||||
update `score`
|
||||
<set>
|
||||
<if test="score != null">
|
||||
score = #{score},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
76
src/main/resources/mapper/StudentMapper.xml
Normal file
@ -0,0 +1,76 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.StudentMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.Student">
|
||||
select * from `student`
|
||||
<where>
|
||||
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `student`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into student (username, password, ...) values ('student', 'student', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.Student" useGeneratedKeys="true">
|
||||
insert into `student`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="username != null">username,</if>
|
||||
<if test="password != null">password,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="phone != null">phone,</if>
|
||||
<if test="email != null">email,</if>
|
||||
<if test="avatar != null">avatar,</if>
|
||||
<if test="role != null">role,</if>
|
||||
<if test="status != null">status,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="username != null">#{username},</if>
|
||||
<if test="password != null">#{password},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="phone != null">#{phone},</if>
|
||||
<if test="email != null">#{email},</if>
|
||||
<if test="avatar != null">#{avatar},</if>
|
||||
<if test="role != null">#{role},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.Student">
|
||||
update `student`
|
||||
<set>
|
||||
<if test="username != null">
|
||||
username = #{username},
|
||||
</if>
|
||||
<if test="password != null">
|
||||
password = #{password},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="phone != null">
|
||||
phone = #{phone},
|
||||
</if>
|
||||
<if test="email != null">
|
||||
email = #{email},
|
||||
</if>
|
||||
<if test="avatar != null">
|
||||
avatar = #{avatar},
|
||||
</if>
|
||||
<if test="role != null">
|
||||
role = #{role},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
71
src/main/resources/mapper/TeacherMapper.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.TeacherMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.Teacher">
|
||||
select * from `teacher`
|
||||
<where>
|
||||
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `teacher`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into teacher (username, password, ...) values ('teacher', 'teacher', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.Teacher" useGeneratedKeys="true">
|
||||
insert into `teacher`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="username != null">username,</if>
|
||||
<if test="password != null">password,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="phone != null">phone,</if>
|
||||
<if test="email != null">email,</if>
|
||||
<if test="avatar != null">avatar,</if>
|
||||
<if test="role != null">role,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="username != null">#{username},</if>
|
||||
<if test="password != null">#{password},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="phone != null">#{phone},</if>
|
||||
<if test="email != null">#{email},</if>
|
||||
<if test="avatar != null">#{avatar},</if>
|
||||
<if test="role != null">#{role},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.Teacher">
|
||||
update `teacher`
|
||||
<set>
|
||||
<if test="username != null">
|
||||
username = #{username},
|
||||
</if>
|
||||
<if test="password != null">
|
||||
password = #{password},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="phone != null">
|
||||
phone = #{phone},
|
||||
</if>
|
||||
<if test="email != null">
|
||||
email = #{email},
|
||||
</if>
|
||||
<if test="avatar != null">
|
||||
avatar = #{avatar},
|
||||
</if>
|
||||
<if test="role != null">
|
||||
role = #{role},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
61
src/main/resources/mapper/TestPaperMapper.xml
Normal file
@ -0,0 +1,61 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.TestPaperMapper">
|
||||
|
||||
<select id="selectAll" resultType="com.example.entity.TestPaper">
|
||||
select test_paper.*, course.name as courseName, course.img as courseImg,
|
||||
teacher.name as teacherName, teacher.avatar as teacherAvatar
|
||||
from `test_paper`
|
||||
left join course on test_paper.course_id = course.id
|
||||
left join teacher on test_paper.teacher_id = teacher.id
|
||||
<where>
|
||||
<if test="name != null"> and test_paper.name like concat('%', #{name}, '%')</if>
|
||||
<if test="teacherId != null"> and test_paper.teacher_id = #{teacherId}</if>
|
||||
<if test="courseName != null"> and course.name like concat('%', #{courseName}, '%')</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from `test_paper`
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- insert into test_paper (username, password, ...) values ('test_paper', 'test_paper', ...) -->
|
||||
<insert id="insert" parameterType="com.example.entity.TestPaper" useGeneratedKeys="true">
|
||||
insert into `test_paper`
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="courseId != null">course_id,</if>
|
||||
<if test="teacherId != null">teacher_id,</if>
|
||||
<if test="type != null">type,</if>
|
||||
<if test="start != null">start,</if>
|
||||
<if test="end != null">end,</if>
|
||||
<if test="time != null">time,</if>
|
||||
<if test="questionIds != null">question_ids,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="courseId != null">#{courseId},</if>
|
||||
<if test="teacherId != null">#{teacherId},</if>
|
||||
<if test="type != null">#{type},</if>
|
||||
<if test="start != null">#{start},</if>
|
||||
<if test="end != null">#{end},</if>
|
||||
<if test="time != null">#{time},</if>
|
||||
<if test="questionIds != null">#{questionIds},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.example.entity.TestPaper">
|
||||
update `test_paper`
|
||||
<set>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
1
ui/.env.development
Normal file
@ -0,0 +1 @@
|
||||
VITE_BASE_URL='http://localhost:9090'
|
1
ui/.env.production
Normal file
@ -0,0 +1 @@
|
||||
VITE_BASE_URL='http://:9090'
|
28
ui/.gitignore
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
.idea
|
||||
node_modules
|
13
ui/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>在线考试系统</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
8
ui/jsconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
28
ui/package.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "vue",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
"@wangeditor/editor": "^5.1.23",
|
||||
"@wangeditor/editor-for-vue": "^5.1.12",
|
||||
"axios": "^1.7.2",
|
||||
"element-plus": "^2.7.6",
|
||||
"vue": "^3.4.29",
|
||||
"vue-router": "^4.3.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.0.5",
|
||||
"sass": "^1.89.0",
|
||||
"unplugin-auto-import": "^0.17.6",
|
||||
"unplugin-element-plus": "^0.8.0",
|
||||
"unplugin-vue-components": "^0.27.2",
|
||||
"vite": "^5.3.1"
|
||||
}
|
||||
}
|
BIN
ui/public/favicon.ico
Normal file
After Width: | Height: | Size: 11 KiB |
3
ui/src/App.vue
Normal file
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<RouterView />
|
||||
</template>
|