education.sql 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. Navicat MySQL Data Transfer
  3. Source Server : localhost_3306
  4. Source Server Version : 80021
  5. Source Host : localhost:3306
  6. Source Database : education
  7. Target Server Type : MYSQL
  8. Target Server Version : 80021
  9. File Encoding : 65001
  10. Date: 2021-06-28 16:19:55
  11. */
  12. SET FOREIGN_KEY_CHECKS=0;
  13. -- ----------------------------
  14. -- Table structure for choose_course
  15. -- ----------------------------
  16. DROP TABLE IF EXISTS `choose_course`;
  17. CREATE TABLE `choose_course` (
  18. `user_id` int NOT NULL,
  19. `course_id` int NOT NULL,
  20. `usual_grade` double(4,1) DEFAULT NULL,
  21. `end_grade` double(4,1) DEFAULT NULL,
  22. `total_grade` double(4,1) DEFAULT NULL,
  23. `choose_status` int NOT NULL DEFAULT '0',
  24. `is_pass` varchar(10) DEFAULT NULL,
  25. PRIMARY KEY (`user_id`,`course_id`),
  26. KEY `fk_course` (`course_id`) USING BTREE,
  27. CONSTRAINT `fk_course` FOREIGN KEY (`course_id`) REFERENCES `course` (`course_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  28. CONSTRAINT `fk_student` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
  29. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  30. -- ----------------------------
  31. -- Records of choose_course
  32. -- ----------------------------
  33. INSERT INTO `choose_course` VALUES ('1', '3', '80.0', '96.0', '89.6', '1', '是');
  34. INSERT INTO `choose_course` VALUES ('1', '4', '85.0', '92.0', '89.2', '1', '是');
  35. INSERT INTO `choose_course` VALUES ('1', '5', null, null, null, '0', null);
  36. -- ----------------------------
  37. -- Table structure for course
  38. -- ----------------------------
  39. DROP TABLE IF EXISTS `course`;
  40. CREATE TABLE `course` (
  41. `course_id` int NOT NULL AUTO_INCREMENT,
  42. `course_code` varchar(255) NOT NULL,
  43. `course_name` varchar(255) NOT NULL,
  44. `course_type` varchar(255) NOT NULL,
  45. `school_id` int NOT NULL,
  46. `teacher_id` int NOT NULL,
  47. `course_status` int NOT NULL DEFAULT '0',
  48. `course_term_id` int NOT NULL,
  49. `course_term` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  50. `course_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  51. `course_place` varchar(255) NOT NULL,
  52. `course_class` int NOT NULL,
  53. `course_credit` int NOT NULL,
  54. `usual_weight` double NOT NULL DEFAULT '0.4',
  55. `end_weight` double NOT NULL DEFAULT '0.6',
  56. PRIMARY KEY (`course_id`),
  57. KEY `fk_school` (`school_id`),
  58. KEY `fk_teacher` (`teacher_id`),
  59. KEY `fk_item` (`course_term_id`),
  60. CONSTRAINT `fk_item` FOREIGN KEY (`course_term_id`) REFERENCES `term` (`term_id`) ON UPDATE CASCADE,
  61. CONSTRAINT `fk_school` FOREIGN KEY (`school_id`) REFERENCES `school` (`school_id`) ON UPDATE CASCADE,
  62. CONSTRAINT `fk_teacher` FOREIGN KEY (`teacher_id`) REFERENCES `user` (`user_id`) ON UPDATE CASCADE
  63. ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;
  64. -- ----------------------------
  65. -- Records of course
  66. -- ----------------------------
  67. INSERT INTO `course` VALUES ('3', '10003', '数据结构', '必修', '1', '2', '1', '10', '2020-2021学年第二学期', '1-17周 周一6-7节', 'X1203', '1', '2', '0.4', '0.6');
  68. INSERT INTO `course` VALUES ('4', '1004', 'c语言', '必修', '1', '6', '1', '10', '2020-2021学年第二学期', '1-17周 周四8-9节', 'X9306', '1', '2', '0.4', '0.6');
  69. INSERT INTO `course` VALUES ('5', '1005', '英语', '限选', '1', '6', '1', '10', '2020-2021学年第二学期', '1-17周 周四8-9节', 'X1206', '1', '1', '0.4', '0.6');
  70. INSERT INTO `course` VALUES ('17', '1234', '线性代数', '必修', '1', '2', '1', '10', '2020-2021学年第二学期', '1-17周 周四1-2节', 'X9605', '1', '2', '0.3', '0.7');
  71. INSERT INTO `course` VALUES ('18', '26565', '概率论', '必修', '1', '2', '1', '10', '2020-2021学年第二学期', '1-17周 周午3-5节', 'X2132', '1', '3', '0.4', '0.6');
  72. INSERT INTO `course` VALUES ('19', '2312', '离散数学', '必修', '1', '2', '0', '8', '2019-2020学年第二学期', '1-17周 周三1-2节', 'X3620', '1', '2', '0.3', '0.7');
  73. -- ----------------------------
  74. -- Table structure for permission
  75. -- ----------------------------
  76. DROP TABLE IF EXISTS `permission`;
  77. CREATE TABLE `permission` (
  78. `permission_id` int NOT NULL AUTO_INCREMENT,
  79. `permission_code` varchar(20) NOT NULL,
  80. `permission_name` varchar(20) NOT NULL,
  81. `father_id` int NOT NULL,
  82. `path` varchar(255) NOT NULL,
  83. `is_menu` int NOT NULL,
  84. PRIMARY KEY (`permission_id`),
  85. UNIQUE KEY `permission_code` (`permission_code`),
  86. UNIQUE KEY `permission_name` (`permission_name`)
  87. ) ENGINE=InnoDB AUTO_INCREMENT=135 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  88. -- ----------------------------
  89. -- Records of permission
  90. -- ----------------------------
  91. INSERT INTO `permission` VALUES ('1', 'course', '选课相关', '0', '/course', '1');
  92. INSERT INTO `permission` VALUES ('2', 'course:choose', '选课', '1', '/course/choose', '1');
  93. INSERT INTO `permission` VALUES ('3', 'course:drop', '退课', '1', '/course/drop', '0');
  94. INSERT INTO `permission` VALUES ('4', 'course:result', '选课结果', '1', '/course/result', '1');
  95. INSERT INTO `permission` VALUES ('5', 'course:history', '历史课程', '1', '/course/history', '1');
  96. INSERT INTO `permission` VALUES ('6', 'grade', '成绩相关', '0', '/grade', '1');
  97. INSERT INTO `permission` VALUES ('7', 'grade:this', '本学期成绩', '6', '/grade/this', '1');
  98. INSERT INTO `permission` VALUES ('8', 'grade:history', '历史成绩', '6', '/grade/history', '1');
  99. INSERT INTO `permission` VALUES ('9', 'grade_manage', '成绩管理', '0', '/grade_manage', '0');
  100. INSERT INTO `permission` VALUES ('10', 'grade_manage:in', '录入成绩', '9', '/grade_manage/in', '0');
  101. INSERT INTO `permission` VALUES ('11', 'course_start', '查看开课', '0', '/course_start', '1');
  102. INSERT INTO `permission` VALUES ('12', 'course_start:history', '历史开课', '11', '/course_start/history', '1');
  103. INSERT INTO `permission` VALUES ('13', 'course_start:this', '本学期开课', '11', '/course_start/this', '1');
  104. INSERT INTO `permission` VALUES ('14', 'showCourseStudent', '查看课程学生名单', '11', '/showCourseStudent', '0');
  105. INSERT INTO `permission` VALUES ('15', 'course_manage', '课程管理', '0', '/course_manage', '1');
  106. INSERT INTO `permission` VALUES ('16', 'course_manage:add', '增加课程', '15', '/course_manage/add', '1');
  107. INSERT INTO `permission` VALUES ('17', 'course_manage:look', '查看课程', '15', '/course_manage/look', '1');
  108. INSERT INTO `permission` VALUES ('18', 'course_manage:delete', '删除课程', '15', '/course_manage/delete', '0');
  109. INSERT INTO `permission` VALUES ('19', 'course_manage:update', '修改课程', '15', '/course_manage/update', '0');
  110. INSERT INTO `permission` VALUES ('20', 'term', '学期管理', '0', '/term', '1');
  111. INSERT INTO `permission` VALUES ('21', 'term:set', '设置当前学期', '20', '/term/set', '1');
  112. INSERT INTO `permission` VALUES ('22', 'choose_manage', '选课管理', '0', '/choose_manage', '1');
  113. INSERT INTO `permission` VALUES ('23', 'choose_manage:open', '开放选课', '22', '/choose_manage/open', '1');
  114. INSERT INTO `permission` VALUES ('24', 'choose_manage:close', '关闭选课', '22', '/choose_manage/close', '0');
  115. -- ----------------------------
  116. -- Table structure for role
  117. -- ----------------------------
  118. DROP TABLE IF EXISTS `role`;
  119. CREATE TABLE `role` (
  120. `role_id` int NOT NULL AUTO_INCREMENT,
  121. `role_name` varchar(20) NOT NULL,
  122. PRIMARY KEY (`role_id`),
  123. UNIQUE KEY `role_name` (`role_name`)
  124. ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  125. -- ----------------------------
  126. -- Records of role
  127. -- ----------------------------
  128. INSERT INTO `role` VALUES ('1', '学生');
  129. INSERT INTO `role` VALUES ('3', '教务');
  130. INSERT INTO `role` VALUES ('2', '教师');
  131. INSERT INTO `role` VALUES ('4', '系统管理员');
  132. -- ----------------------------
  133. -- Table structure for role_permission
  134. -- ----------------------------
  135. DROP TABLE IF EXISTS `role_permission`;
  136. CREATE TABLE `role_permission` (
  137. `role_id` int NOT NULL,
  138. `permission_id` int NOT NULL,
  139. PRIMARY KEY (`role_id`,`permission_id`),
  140. KEY `fk_permission` (`permission_id`),
  141. CONSTRAINT `fk_permission` FOREIGN KEY (`permission_id`) REFERENCES `permission` (`permission_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  142. CONSTRAINT `fk_role_p` FOREIGN KEY (`role_id`) REFERENCES `role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE
  143. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  144. -- ----------------------------
  145. -- Records of role_permission
  146. -- ----------------------------
  147. INSERT INTO `role_permission` VALUES ('1', '1');
  148. INSERT INTO `role_permission` VALUES ('1', '2');
  149. INSERT INTO `role_permission` VALUES ('1', '3');
  150. INSERT INTO `role_permission` VALUES ('1', '4');
  151. INSERT INTO `role_permission` VALUES ('1', '5');
  152. INSERT INTO `role_permission` VALUES ('1', '6');
  153. INSERT INTO `role_permission` VALUES ('1', '7');
  154. INSERT INTO `role_permission` VALUES ('1', '8');
  155. INSERT INTO `role_permission` VALUES ('2', '9');
  156. INSERT INTO `role_permission` VALUES ('2', '10');
  157. INSERT INTO `role_permission` VALUES ('2', '11');
  158. INSERT INTO `role_permission` VALUES ('2', '12');
  159. INSERT INTO `role_permission` VALUES ('2', '13');
  160. INSERT INTO `role_permission` VALUES ('2', '14');
  161. INSERT INTO `role_permission` VALUES ('3', '14');
  162. INSERT INTO `role_permission` VALUES ('3', '15');
  163. INSERT INTO `role_permission` VALUES ('3', '16');
  164. INSERT INTO `role_permission` VALUES ('3', '17');
  165. INSERT INTO `role_permission` VALUES ('3', '18');
  166. INSERT INTO `role_permission` VALUES ('3', '19');
  167. INSERT INTO `role_permission` VALUES ('4', '20');
  168. INSERT INTO `role_permission` VALUES ('4', '21');
  169. INSERT INTO `role_permission` VALUES ('4', '22');
  170. INSERT INTO `role_permission` VALUES ('4', '23');
  171. INSERT INTO `role_permission` VALUES ('4', '24');
  172. -- ----------------------------
  173. -- Table structure for school
  174. -- ----------------------------
  175. DROP TABLE IF EXISTS `school`;
  176. CREATE TABLE `school` (
  177. `school_id` int NOT NULL AUTO_INCREMENT,
  178. `school_name` varchar(255) NOT NULL,
  179. PRIMARY KEY (`school_id`)
  180. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
  181. -- ----------------------------
  182. -- Records of school
  183. -- ----------------------------
  184. INSERT INTO `school` VALUES ('1', '计算机学院');
  185. -- ----------------------------
  186. -- Table structure for term
  187. -- ----------------------------
  188. DROP TABLE IF EXISTS `term`;
  189. CREATE TABLE `term` (
  190. `term_id` int NOT NULL AUTO_INCREMENT,
  191. `term_name` varchar(255) NOT NULL,
  192. `term_status` int NOT NULL DEFAULT '0',
  193. PRIMARY KEY (`term_id`)
  194. ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;
  195. -- ----------------------------
  196. -- Records of term
  197. -- ----------------------------
  198. INSERT INTO `term` VALUES ('1', '2016-2017学年第一学期', '0');
  199. INSERT INTO `term` VALUES ('2', '2016-2017学年第二学期', '0');
  200. INSERT INTO `term` VALUES ('3', '2017-2018学年第一学期', '0');
  201. INSERT INTO `term` VALUES ('4', '2017-2018学年第二学期', '0');
  202. INSERT INTO `term` VALUES ('5', '2018-2019学年第一学期', '0');
  203. INSERT INTO `term` VALUES ('6', '2018-2019学年第二学期', '0');
  204. INSERT INTO `term` VALUES ('7', '2019-2020学年第一学期', '0');
  205. INSERT INTO `term` VALUES ('8', '2019-2020学年第二学期', '0');
  206. INSERT INTO `term` VALUES ('9', '2020-2021学年第一学期', '0');
  207. INSERT INTO `term` VALUES ('10', '2020-2021学年第二学期', '1');
  208. INSERT INTO `term` VALUES ('11', '2021-2022学年第一学期', '0');
  209. INSERT INTO `term` VALUES ('12', '2021-2022学年第二学期', '0');
  210. INSERT INTO `term` VALUES ('13', '2022-2023学年第一学期', '0');
  211. INSERT INTO `term` VALUES ('14', '2022-2023学年第二学期', '0');
  212. INSERT INTO `term` VALUES ('15', '2023-2024学年第一学期', '0');
  213. INSERT INTO `term` VALUES ('16', '2023-2024学年第二学期', '0');
  214. INSERT INTO `term` VALUES ('17', '2024-2025学年第一学期', '0');
  215. INSERT INTO `term` VALUES ('18', '2024-2025学年第二学期', '0');
  216. -- ----------------------------
  217. -- Table structure for user
  218. -- ----------------------------
  219. DROP TABLE IF EXISTS `user`;
  220. CREATE TABLE `user` (
  221. `user_id` int NOT NULL AUTO_INCREMENT,
  222. `username` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  223. `password` varchar(255) NOT NULL,
  224. `salt` varchar(255) NOT NULL,
  225. `nickname` varchar(255) NOT NULL,
  226. `school_id` int NOT NULL,
  227. `sex` varchar(255) NOT NULL,
  228. `tel` varchar(100) NOT NULL,
  229. `student_class` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  230. PRIMARY KEY (`user_id`),
  231. UNIQUE KEY `username` (`username`) USING BTREE,
  232. KEY `fk_sch` (`school_id`),
  233. CONSTRAINT `fk_sch` FOREIGN KEY (`school_id`) REFERENCES `school` (`school_id`) ON DELETE RESTRICT ON UPDATE CASCADE
  234. ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  235. -- ----------------------------
  236. -- Records of user
  237. -- ----------------------------
  238. INSERT INTO `user` VALUES ('1', '20201001', '4d3d7008836ee74feebc32a43ed24181', 'wcwad12', '张三', '1', '男', '12135', '计算机2018-01班');
  239. INSERT INTO `user` VALUES ('2', '20201002', '4d3d7008836ee74feebc32a43ed24181', 'wcwad12', '李四', '1', '女', '215454', null);
  240. INSERT INTO `user` VALUES ('3', '20201003', '4d3d7008836ee74feebc32a43ed24181', 'wcwad12', '王五', '1', '男', '1548', null);
  241. INSERT INTO `user` VALUES ('4', '20201004', '4d3d7008836ee74feebc32a43ed24181', 'wcwad12', '管理员', '1', '男', '1558', null);
  242. INSERT INTO `user` VALUES ('5', '20201005', '4d3d7008836ee74feebc32a43ed24181', 'wcwad12', '丽丽', '1', '女', '2166', '计算机2018-02班');
  243. INSERT INTO `user` VALUES ('6', '20201006', '4d3d7008836ee74feebc32a43ed24181', 'wcwad12', '呜呜', '1', '男', '1158', null);
  244. -- ----------------------------
  245. -- Table structure for user_role
  246. -- ----------------------------
  247. DROP TABLE IF EXISTS `user_role`;
  248. CREATE TABLE `user_role` (
  249. `user_id` int NOT NULL,
  250. `role_id` int NOT NULL,
  251. PRIMARY KEY (`user_id`,`role_id`),
  252. KEY `fk_role` (`role_id`),
  253. CONSTRAINT `fk_role` FOREIGN KEY (`role_id`) REFERENCES `role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  254. CONSTRAINT `fk_user` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
  255. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  256. -- ----------------------------
  257. -- Records of user_role
  258. -- ----------------------------
  259. INSERT INTO `user_role` VALUES ('1', '1');
  260. INSERT INTO `user_role` VALUES ('5', '1');
  261. INSERT INTO `user_role` VALUES ('2', '2');
  262. INSERT INTO `user_role` VALUES ('6', '2');
  263. INSERT INTO `user_role` VALUES ('3', '3');
  264. INSERT INTO `user_role` VALUES ('4', '4');
  265. DROP TRIGGER IF EXISTS `tri_choose_course_update`;
  266. DELIMITER ;;
  267. CREATE TRIGGER `tri_choose_course_update` BEFORE UPDATE ON `choose_course` FOR EACH ROW BEGIN
  268. DECLARE endWe DOUBLE;
  269. DECLARE usualWe DOUBLE;
  270. SET endWe = (SELECT end_weight FROM course WHERE course_id = new.course_id);
  271. SET usualWe = (SELECT usual_weight FROM course WHERE course_id = new.course_id);
  272. SET new.total_grade = new.usual_grade*usualWe + new.end_grade*endWe;
  273. IF (new.total_grade>=60) THEN
  274. SET new.is_pass = '是' ;
  275. END IF;
  276. IF (new.total_grade<60) THEN
  277. SET new.is_pass = '否' ;
  278. END IF;
  279. END
  280. ;;
  281. DELIMITER ;
  282. DROP TRIGGER IF EXISTS `tri_course_insert`;
  283. DELIMITER ;;
  284. CREATE TRIGGER `tri_course_insert` BEFORE INSERT ON `course` FOR EACH ROW BEGIN
  285. declare c int;
  286. declare b VARCHAR(255);
  287. SET c = NEW.course_term_id;
  288. SET b = (SELECT term_name FROM term WHERE term_id = c);
  289. SET new.course_term = b;
  290. IF((SELECT term_status FROM term WHERE term_id = c)=1) THEN
  291. SET NEW.course_status = 1;
  292. END IF;
  293. END
  294. ;;
  295. DELIMITER ;