├── pic ├── a.png ├── b.png ├── c.png ├── d.png └── e.png ├── src ├── main │ ├── resources │ │ ├── application.properties │ │ └── mappers │ │ │ ├── RoleMapper.xml │ │ │ ├── StudentMapper.xml │ │ │ ├── AnnouncementMapper.xml │ │ │ ├── LogMapper.xml │ │ │ ├── ExaminationMapper.xml │ │ │ ├── SubjectMapper.xml │ │ │ ├── AttendanceMapper.xml │ │ │ └── TeacherMapper.xml │ └── java │ │ └── com │ │ └── project │ │ └── selflearningplatformserver │ │ ├── exception │ │ ├── TokenException.java │ │ ├── SecurityServerException.java │ │ ├── IdNotFoundException.java │ │ ├── NullFiledException.java │ │ ├── IllegalFiledException.java │ │ ├── BaseException.java │ │ ├── ErrorHandler.java │ │ └── ExceptionResolver.java │ │ ├── security │ │ ├── MustAdminLogin.java │ │ ├── MustStudentLogin.java │ │ ├── MustTeacherLogin.java │ │ ├── SecurityArgumentResolversWebMvcConfig.java │ │ ├── MustLogin.java │ │ └── SecurityHandlerMethodArgumentResolver.java │ │ ├── service │ │ ├── LogService.java │ │ ├── AnnouncementService.java │ │ ├── SecurityService.java │ │ ├── impl │ │ │ ├── LogServiceImpl.java │ │ │ ├── AnnouncementServiceImpl.java │ │ │ ├── SubjectServiceImpl.java │ │ │ ├── ExaminationServiceImpl.java │ │ │ ├── TeacherServiceImpl.java │ │ │ ├── SecurityServiceImpl.java │ │ │ ├── StudentLearningServiceImpl.java │ │ │ ├── StudentClassServerImpl.java │ │ │ └── AttendanceServiceImpl.java │ │ ├── SubjectService.java │ │ ├── UserService.java │ │ ├── ExaminationService.java │ │ ├── TeacherService.java │ │ ├── AttendanceService.java │ │ ├── StudentLearningService.java │ │ ├── ExaminationScoreService.java │ │ ├── StudentWorkService.java │ │ ├── StudentClassServer.java │ │ └── LearningContentService.java │ │ ├── log │ │ ├── Log.java │ │ └── LogAspect.java │ │ ├── entity │ │ ├── Role.java │ │ ├── Attendance.java │ │ ├── Announcement.java │ │ ├── Student.java │ │ ├── Log.java │ │ ├── Subject.java │ │ ├── Examination.java │ │ ├── StudentClass.java │ │ ├── StudentLearning.java │ │ ├── Teacher.java │ │ ├── ExaminationScore.java │ │ ├── StudentWork.java │ │ ├── User.java │ │ └── LearningContent.java │ │ ├── dto │ │ ├── AttendanceDTO.java │ │ ├── UserDTO.java │ │ ├── ExaminationScoreDTO.java │ │ ├── StudentClassDTO.java │ │ ├── ExaminationScoreWithExamName.java │ │ ├── LoginUser.java │ │ ├── LearningContentDTO.java │ │ ├── StudentLearningDTO.java │ │ └── RestModel.java │ │ ├── mapper │ │ ├── RoleMapper.java │ │ ├── StudentMapper.java │ │ ├── LogMapper.java │ │ ├── ExaminationMapper.java │ │ ├── SubjectMapper.java │ │ ├── AnnouncementMapper.java │ │ ├── UserMapper.java │ │ ├── LearningContentMapper.java │ │ ├── TeacherMapper.java │ │ ├── StudentWorkMapper.java │ │ ├── ExaminationScoreMapper.java │ │ ├── AttendanceMapper.java │ │ ├── StudentLearningMapper.java │ │ └── StudentClassMapper.java │ │ ├── util │ │ ├── Tuple2.java │ │ ├── CommandUtils.java │ │ ├── Md5Utils.java │ │ ├── OrikaUtils.java │ │ ├── JwtUtils.java │ │ └── FileUtils.java │ │ ├── SelfLearningPlatformServerApplication.java │ │ ├── config │ │ ├── BeansConfig.java │ │ ├── CustomWebMvcConfig.java │ │ ├── EnvironmentCheckConfig.java │ │ ├── AppTomcatConnectorCustomizer.java │ │ └── AppProperties.java │ │ ├── controller │ │ ├── LogController.java │ │ ├── SecurityController.java │ │ ├── SubjectController.java │ │ ├── ExaminationController.java │ │ ├── AnnouncementController.java │ │ ├── TeacherController.java │ │ ├── StudentLearningController.java │ │ ├── UserController.java │ │ ├── ExaminationScoreController.java │ │ ├── AttendanceController.java │ │ ├── StudentWorkController.java │ │ ├── StudentClassController.java │ │ └── LearningContentController.java │ │ └── video │ │ └── VideoTransformHandler.java └── test │ └── java │ └── com │ └── project │ └── selflearningplatformserver │ └── SelfLearningPlatformServerApplicationTests.java ├── .gitignore └── README.md /pic/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/self-learning-platform-server/master/pic/a.png -------------------------------------------------------------------------------- /pic/b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/self-learning-platform-server/master/pic/b.png -------------------------------------------------------------------------------- /pic/c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/self-learning-platform-server/master/pic/c.png -------------------------------------------------------------------------------- /pic/d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/self-learning-platform-server/master/pic/d.png -------------------------------------------------------------------------------- /pic/e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/self-learning-platform-server/master/pic/e.png -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/self-learning-platform-server/master/src/main/resources/application.properties -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/exception/TokenException.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * @author itning 7 | */ 8 | public class TokenException extends BaseException { 9 | public TokenException(String msg, HttpStatus code) { 10 | super(msg, code); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/security/MustAdminLogin.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.security; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 必须是管理员登录 7 | * 8 | * @author itning 9 | */ 10 | @Target(ElementType.PARAMETER) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | @MustLogin(role = MustLogin.ROLE.ADMIN) 14 | public @interface MustAdminLogin { 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/security/MustStudentLogin.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.security; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 必须是学生登录 7 | * 8 | * @author itning 9 | */ 10 | @Target(ElementType.PARAMETER) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | @MustLogin(role = MustLogin.ROLE.STUDENT) 14 | public @interface MustStudentLogin { 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/security/MustTeacherLogin.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.security; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 必须是教师登录 7 | * 8 | * @author itning 9 | */ 10 | @Target(ElementType.PARAMETER) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | @MustLogin(role = MustLogin.ROLE.TEACHER) 14 | public @interface MustTeacherLogin { 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .mvn/ 3 | !**/src/main/** 4 | !**/src/test/** 5 | 6 | ### STS ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | 15 | ### IntelliJ IDEA ### 16 | .idea 17 | *.iws 18 | *.iml 19 | *.ipr 20 | 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ 27 | build/ 28 | 29 | ### VS Code ### 30 | .vscode/ 31 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/exception/SecurityServerException.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * @author itning 7 | * @date 2020/2/12 11:18 8 | */ 9 | public class SecurityServerException extends BaseException { 10 | public SecurityServerException(String msg, HttpStatus code) { 11 | super(msg, code); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/LogService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.entity.Log; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author itning 9 | * @date 2020/5/2 17:03 10 | */ 11 | public interface LogService { 12 | /** 13 | * 获取系统日志 14 | * 15 | * @return 日志集合 16 | */ 17 | List getSystemLog(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/exception/IdNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * 主键不存在 7 | * 8 | * @author itning 9 | * @date 2020/2/12 11:34 10 | */ 11 | public class IdNotFoundException extends BaseException { 12 | public IdNotFoundException(String msg) { 13 | super(msg, HttpStatus.NOT_FOUND); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/exception/NullFiledException.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * 传入的参数为空 7 | * 8 | * @author itning 9 | * @date 2020/2/12 11:34 10 | */ 11 | public class NullFiledException extends BaseException { 12 | public NullFiledException(String msg) { 13 | super(msg, HttpStatus.BAD_REQUEST); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/exception/IllegalFiledException.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * 非法参数 7 | * 8 | * @author itning 9 | * @date 2020/2/12 11:34 10 | */ 11 | public class IllegalFiledException extends BaseException { 12 | public IllegalFiledException(String msg) { 13 | super(msg, HttpStatus.BAD_REQUEST); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/log/Log.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.log; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * @author itning 7 | * @date 2020/5/1 16:18 8 | * @see LogAspect 9 | */ 10 | @Target({ElementType.METHOD}) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | public @interface Log { 14 | /** 15 | * 方法作用 16 | * 17 | * @return 方法作用 18 | */ 19 | String value(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Role { 13 | private String id; 14 | 15 | private String name; 16 | 17 | private Date gmtCreate; 18 | 19 | private Date gmtModified; 20 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/dto/AttendanceDTO.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * @author itning 9 | * @date 2020/5/1 22:40 10 | */ 11 | @Data 12 | public class AttendanceDTO { 13 | private String id; 14 | 15 | private String userId; 16 | 17 | private Date gmtCreate; 18 | 19 | private Date gmtModified; 20 | 21 | private UserDTO user; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/Attendance.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Attendance { 13 | private String id; 14 | 15 | private String userId; 16 | 17 | private Date gmtCreate; 18 | 19 | private Date gmtModified; 20 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/Announcement.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Announcement { 13 | private String id; 14 | 15 | private String content; 16 | 17 | private Date gmtCreate; 18 | 19 | private Date gmtModified; 20 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/Student.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Student { 13 | private String userId; 14 | 15 | private String studentClassId; 16 | 17 | private Date gmtCreate; 18 | 19 | private Date gmtModified; 20 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/Log.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Log { 13 | private String id; 14 | 15 | private String content; 16 | 17 | private String userId; 18 | 19 | private Date gmtCreate; 20 | 21 | private Date gmtModified; 22 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/RoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.Role; 4 | 5 | public interface RoleMapper { 6 | int deleteByPrimaryKey(String id); 7 | 8 | int insert(Role record); 9 | 10 | int insertSelective(Role record); 11 | 12 | Role selectByPrimaryKey(String id); 13 | 14 | int updateByPrimaryKeySelective(Role record); 15 | 16 | int updateByPrimaryKey(Role record); 17 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/Subject.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Subject { 13 | private String id; 14 | 15 | private String userId; 16 | 17 | private String name; 18 | 19 | private Date gmtCreate; 20 | 21 | private Date gmtModified; 22 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/util/Tuple2.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.util; 2 | 3 | /** 4 | * @author itning 5 | * @date 2020/5/1 15:16 6 | */ 7 | public class Tuple2 { 8 | private final T1 t1; 9 | private final T2 t2; 10 | 11 | public Tuple2(T1 t1, T2 t2) { 12 | this.t1 = t1; 13 | this.t2 = t2; 14 | } 15 | 16 | public T1 getT1() { 17 | return t1; 18 | } 19 | 20 | public T2 getT2() { 21 | return t2; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/Examination.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Examination { 13 | private String id; 14 | 15 | private String userId; 16 | 17 | private String name; 18 | 19 | private Date gmtCreate; 20 | 21 | private Date gmtModified; 22 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/StudentClass.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class StudentClass { 13 | private String id; 14 | 15 | private String name; 16 | 17 | private String userId; 18 | 19 | private Date gmtCreate; 20 | 21 | private Date gmtModified; 22 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/dto/UserDTO.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * @author itning 9 | * @date 2020/5/1 15:04 10 | */ 11 | @Data 12 | public class UserDTO { 13 | private String id; 14 | 15 | private String name; 16 | 17 | private String username; 18 | 19 | private Boolean freeze; 20 | 21 | private String roleId; 22 | 23 | private Date gmtCreate; 24 | 25 | private Date gmtModified; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/StudentMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.Student; 4 | 5 | public interface StudentMapper { 6 | int deleteByPrimaryKey(String userId); 7 | 8 | int insert(Student record); 9 | 10 | int insertSelective(Student record); 11 | 12 | Student selectByPrimaryKey(String userId); 13 | 14 | int updateByPrimaryKeySelective(Student record); 15 | 16 | int updateByPrimaryKey(Student record); 17 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/StudentLearning.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class StudentLearning { 13 | private String id; 14 | 15 | private String learningContentId; 16 | 17 | private String studentId; 18 | 19 | private Date gmtCreate; 20 | 21 | private Date gmtModified; 22 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/Teacher.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Teacher { 13 | private String id; 14 | 15 | private String userId; 16 | 17 | private String attributeKey; 18 | 19 | private String attributeValue; 20 | 21 | private Date gmtCreate; 22 | 23 | private Date gmtModified; 24 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/LogMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.Log; 4 | 5 | import java.util.List; 6 | 7 | public interface LogMapper { 8 | int deleteByPrimaryKey(String id); 9 | 10 | int insert(Log record); 11 | 12 | int insertSelective(Log record); 13 | 14 | Log selectByPrimaryKey(String id); 15 | 16 | int updateByPrimaryKeySelective(Log record); 17 | 18 | int updateByPrimaryKey(Log record); 19 | 20 | List selectAll(); 21 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/dto/ExaminationScoreDTO.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.math.BigDecimal; 6 | import java.util.Date; 7 | 8 | /** 9 | * @author itning 10 | * @date 2020/5/1 21:33 11 | */ 12 | @Data 13 | public class ExaminationScoreDTO { 14 | private String id; 15 | 16 | private String studentId; 17 | 18 | private String subject; 19 | 20 | private BigDecimal score; 21 | 22 | private String examId; 23 | 24 | private Date gmtCreate; 25 | 26 | private Date gmtModified; 27 | 28 | private UserDTO user; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/dto/StudentClassDTO.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * @author itning 11 | * @date 2020/5/2 20:07 12 | */ 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class StudentClassDTO { 17 | private String id; 18 | 19 | private String name; 20 | 21 | private String userId; 22 | 23 | private Date gmtCreate; 24 | 25 | private Date gmtModified; 26 | 27 | private String teacherName; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/ExaminationScore.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.math.BigDecimal; 8 | import java.util.Date; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | public class ExaminationScore { 14 | private String id; 15 | 16 | private String studentId; 17 | 18 | private String subject; 19 | 20 | private BigDecimal score; 21 | 22 | private String examId; 23 | 24 | private Date gmtCreate; 25 | 26 | private Date gmtModified; 27 | } -------------------------------------------------------------------------------- /src/test/java/com/project/selflearningplatformserver/SelfLearningPlatformServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver; 2 | 3 | import com.project.selflearningplatformserver.mapper.UserMapper; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | @SpringBootTest 9 | class SelfLearningPlatformServerApplicationTests { 10 | @Autowired 11 | private UserMapper userMapper; 12 | 13 | @Test 14 | void contextLoads() { 15 | System.out.println(userMapper.selectByPrimaryKey("aaaa")); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/ExaminationMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.Examination; 4 | 5 | import java.util.List; 6 | 7 | public interface ExaminationMapper { 8 | int deleteByPrimaryKey(String id); 9 | 10 | int insert(Examination record); 11 | 12 | int insertSelective(Examination record); 13 | 14 | Examination selectByPrimaryKey(String id); 15 | 16 | int updateByPrimaryKeySelective(Examination record); 17 | 18 | int updateByPrimaryKey(Examination record); 19 | 20 | List selectAllByUserId(String userId); 21 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/SelfLearningPlatformServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author itning 9 | */ 10 | @SpringBootApplication 11 | @MapperScan("com.project.selflearningplatformserver.mapper") 12 | public class SelfLearningPlatformServerApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SelfLearningPlatformServerApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/SubjectMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.Subject; 4 | 5 | import java.util.List; 6 | 7 | public interface SubjectMapper { 8 | int deleteByPrimaryKey(String id); 9 | 10 | int insert(Subject record); 11 | 12 | int insertSelective(Subject record); 13 | 14 | Subject selectByPrimaryKey(String id); 15 | 16 | int updateByPrimaryKeySelective(Subject record); 17 | 18 | int updateByPrimaryKey(Subject record); 19 | 20 | List selectByUserId(String userId); 21 | 22 | long countByPrimaryKey(String id); 23 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/StudentWork.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class StudentWork { 13 | private String id; 14 | 15 | private String fileUri; 16 | 17 | private String mime; 18 | 19 | private String extensionName; 20 | 21 | private Integer score; 22 | 23 | private Long size; 24 | 25 | private String suggest; 26 | 27 | private Date gmtCreate; 28 | 29 | private Date gmtModified; 30 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/AnnouncementMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.Announcement; 4 | 5 | import java.util.List; 6 | 7 | public interface AnnouncementMapper { 8 | int deleteByPrimaryKey(String id); 9 | 10 | int insert(Announcement record); 11 | 12 | int insertSelective(Announcement record); 13 | 14 | Announcement selectByPrimaryKey(String id); 15 | 16 | int updateByPrimaryKeySelective(Announcement record); 17 | 18 | int updateByPrimaryKey(Announcement record); 19 | 20 | List selectAll(); 21 | 22 | long countByPrimaryKey(String id); 23 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | import java.util.Date; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | public class User { 14 | private String id; 15 | 16 | private String name; 17 | 18 | private String username; 19 | @ToString.Exclude 20 | private String password; 21 | 22 | private Boolean freeze; 23 | 24 | private String salt; 25 | 26 | private String roleId; 27 | 28 | private Date gmtCreate; 29 | 30 | private Date gmtModified; 31 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.User; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface UserMapper { 9 | int deleteByPrimaryKey(String id); 10 | 11 | int insert(User record); 12 | 13 | int insertSelective(User record); 14 | 15 | User selectByPrimaryKey(String id); 16 | 17 | int updateByPrimaryKeySelective(User record); 18 | 19 | int updateByPrimaryKey(User record); 20 | 21 | Optional selectByUserName(String username); 22 | 23 | List selectAllByRoleId(String roleId); 24 | 25 | long countByUserName(String username); 26 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/dto/ExaminationScoreWithExamName.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.math.BigDecimal; 8 | import java.util.Date; 9 | 10 | /** 11 | * 考试分数(带考试信息) 12 | * 13 | * @author itning 14 | * @date 2020/5/6 5:25 15 | */ 16 | @Data 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class ExaminationScoreWithExamName { 20 | private String id; 21 | 22 | private String studentId; 23 | 24 | private String subject; 25 | 26 | private BigDecimal score; 27 | 28 | private String examId; 29 | 30 | private Date gmtCreate; 31 | 32 | private Date gmtModified; 33 | 34 | private String name; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/dto/LoginUser.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * @author itning 9 | * @date 2020/5/1 13:34 10 | */ 11 | @Data 12 | public class LoginUser { 13 | /** 14 | * 管理员ID 15 | */ 16 | public static final String ROLE_ADMIN_ID = "a"; 17 | /** 18 | * 教师ID 19 | */ 20 | public static final String ROLE_TEACHER_ID = "b"; 21 | /** 22 | * 学生ID 23 | */ 24 | public static final String ROLE_STUDENT_ID = "c"; 25 | 26 | private String id; 27 | 28 | private String name; 29 | 30 | private String username; 31 | 32 | private String roleId; 33 | 34 | private Date gmtCreate; 35 | 36 | private Date gmtModified; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/LearningContentMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.LearningContent; 4 | 5 | import java.util.List; 6 | 7 | public interface LearningContentMapper { 8 | int deleteByPrimaryKey(String id); 9 | 10 | int insert(LearningContent record); 11 | 12 | int insertSelective(LearningContent record); 13 | 14 | LearningContent selectByPrimaryKey(String id); 15 | 16 | int updateByPrimaryKeySelective(LearningContent record); 17 | 18 | int updateByPrimaryKey(LearningContent record); 19 | 20 | List selectAllBySubjectId(String subjectId); 21 | 22 | long countByPrimaryKey(String id); 23 | 24 | List selectAllCanStudy(String studentId); 25 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/entity/LearningContent.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class LearningContent { 13 | private String id; 14 | 15 | private String subjectId; 16 | 17 | private String contentUri; 18 | 19 | private String aidUri; 20 | 21 | private Long aidSize; 22 | 23 | private String aidExtensionName; 24 | 25 | private String aidMime; 26 | 27 | private String extensionName; 28 | 29 | private Long size; 30 | 31 | private String mime; 32 | 33 | private String name; 34 | 35 | private Date gmtCreate; 36 | 37 | private Date gmtModified; 38 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/TeacherMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.Teacher; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import java.util.List; 7 | 8 | public interface TeacherMapper { 9 | int deleteByPrimaryKey(String id); 10 | 11 | int insert(Teacher record); 12 | 13 | int insertSelective(Teacher record); 14 | 15 | Teacher selectByPrimaryKey(String id); 16 | 17 | int updateByPrimaryKeySelective(Teacher record); 18 | 19 | int updateByPrimaryKey(Teacher record); 20 | 21 | List selectAllByUserId(String userId); 22 | 23 | long countByPrimaryKey(String id); 24 | 25 | long countByAttributeKeyAndUserId(@Param("attributeKey") String attributeKey, @Param("userId") String userId); 26 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/exception/BaseException.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * 异常基类 7 | * 8 | * @author itning 9 | */ 10 | public abstract class BaseException extends RuntimeException { 11 | private String msg; 12 | private HttpStatus code; 13 | 14 | public BaseException(String msg, HttpStatus code) { 15 | super(msg); 16 | this.msg = msg; 17 | this.code = code; 18 | } 19 | 20 | public String getMsg() { 21 | return msg; 22 | } 23 | 24 | public void setMsg(String msg) { 25 | this.msg = msg; 26 | } 27 | 28 | public HttpStatus getCode() { 29 | return code; 30 | } 31 | 32 | public void setCode(HttpStatus code) { 33 | this.code = code; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/StudentWorkMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.StudentWork; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | public interface StudentWorkMapper { 7 | int deleteByPrimaryKey(String id); 8 | 9 | int insert(StudentWork record); 10 | 11 | int insertSelective(StudentWork record); 12 | 13 | StudentWork selectByPrimaryKey(String id); 14 | 15 | int updateByPrimaryKeySelective(StudentWork record); 16 | 17 | int updateByPrimaryKey(StudentWork record); 18 | 19 | long countByPrimaryKey(String id); 20 | 21 | StudentWork selectByLearningContentIdAndStudentId(@Param("learningContentId") String learningContentId, 22 | @Param("studentId") String studentId); 23 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/ExaminationScoreMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.dto.ExaminationScoreWithExamName; 4 | import com.project.selflearningplatformserver.entity.ExaminationScore; 5 | 6 | import java.util.List; 7 | 8 | public interface ExaminationScoreMapper { 9 | int deleteByPrimaryKey(String id); 10 | 11 | int insert(ExaminationScore record); 12 | 13 | int insertSelective(ExaminationScore record); 14 | 15 | ExaminationScore selectByPrimaryKey(String id); 16 | 17 | int updateByPrimaryKeySelective(ExaminationScore record); 18 | 19 | int updateByPrimaryKey(ExaminationScore record); 20 | 21 | List selectAllByExaminationId(String examinationId); 22 | 23 | List selectStudentOwnExaminationScore(String studentId); 24 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/AttendanceMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.entity.Attendance; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import java.time.LocalDate; 7 | import java.util.List; 8 | 9 | public interface AttendanceMapper { 10 | int deleteByPrimaryKey(String id); 11 | 12 | int insert(Attendance record); 13 | 14 | int insertSelective(Attendance record); 15 | 16 | Attendance selectByPrimaryKey(String id); 17 | 18 | int updateByPrimaryKeySelective(Attendance record); 19 | 20 | int updateByPrimaryKey(Attendance record); 21 | 22 | List selectAll(); 23 | 24 | List selectAllByUserRoleId(String roleId); 25 | 26 | long countByPrimaryKey(String id); 27 | 28 | long countUserAttendanceInDate(@Param("userId") String userId, @Param("date") LocalDate date); 29 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/AnnouncementService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.entity.Announcement; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 公告服务 9 | * 10 | * @author itning 11 | * @date 2020/5/1 18:52 12 | */ 13 | public interface AnnouncementService { 14 | /** 15 | * 获取所有公告 16 | * 17 | * @return 公告集合 18 | */ 19 | List getAll(); 20 | 21 | /** 22 | * 删除公告 23 | * 24 | * @param id 公告ID 25 | */ 26 | void del(String id); 27 | 28 | /** 29 | * 更新公告 30 | * 31 | * @param id 公告ID 32 | * @param content 公告内容 33 | * @return 更新的公告 34 | */ 35 | Announcement update(String id, String content); 36 | 37 | /** 38 | * 新增公告 39 | * 40 | * @param content 内容 41 | * @return 新增的公告 42 | */ 43 | Announcement newAnnouncement(String content); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/StudentLearningMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.dto.LearningContentDTO; 4 | import com.project.selflearningplatformserver.dto.StudentLearningDTO; 5 | import com.project.selflearningplatformserver.entity.StudentLearning; 6 | 7 | import java.util.List; 8 | 9 | public interface StudentLearningMapper { 10 | int deleteByPrimaryKey(String id); 11 | 12 | int insert(StudentLearning record); 13 | 14 | int insertSelective(StudentLearning record); 15 | 16 | StudentLearning selectByPrimaryKey(String id); 17 | 18 | int updateByPrimaryKeySelective(StudentLearning record); 19 | 20 | int updateByPrimaryKey(StudentLearning record); 21 | 22 | List selectAllByStudentId(String studentId); 23 | 24 | long countByPrimaryKey(String id); 25 | 26 | List selectAllWithStudentName(String learningContentId); 27 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/dto/LearningContentDTO.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * @author itning 11 | * @date 2020/5/3 19:45 12 | */ 13 | @Data 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | public class LearningContentDTO { 17 | private String id; 18 | 19 | private String subjectId; 20 | 21 | private String contentUri; 22 | 23 | private String aidUri; 24 | 25 | private Long aidSize; 26 | 27 | private String aidExtensionName; 28 | 29 | private String aidMime; 30 | 31 | private String extensionName; 32 | 33 | private Long size; 34 | 35 | private String mime; 36 | 37 | private String name; 38 | 39 | private Date gmtCreate; 40 | 41 | private Date gmtModified; 42 | 43 | private String studentLearningId; 44 | 45 | private Date chooseDate; 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/mapper/StudentClassMapper.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.mapper; 2 | 3 | import com.project.selflearningplatformserver.dto.StudentClassDTO; 4 | import com.project.selflearningplatformserver.dto.UserDTO; 5 | import com.project.selflearningplatformserver.entity.StudentClass; 6 | 7 | import java.util.List; 8 | 9 | public interface StudentClassMapper { 10 | int deleteByPrimaryKey(String id); 11 | 12 | int insert(StudentClass record); 13 | 14 | int insertSelective(StudentClass record); 15 | 16 | StudentClass selectByPrimaryKey(String id); 17 | 18 | int updateByPrimaryKeySelective(StudentClass record); 19 | 20 | int updateByPrimaryKey(StudentClass record); 21 | 22 | long countByPrimaryKey(String id); 23 | 24 | List selectByUserId(String userId); 25 | 26 | List selectAllWithTeacherName(); 27 | 28 | List selectAllStudentInClass(String userId); 29 | 30 | StudentClassDTO selectOwnClass(String studentId); 31 | } -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/SecurityService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.project.selflearningplatformserver.dto.UserDTO; 5 | 6 | /** 7 | * @author itning 8 | * @date 2020/5/1 13:58 9 | */ 10 | public interface SecurityService { 11 | /** 12 | * 登录 13 | * 14 | * @param username 用户名 15 | * @param password 密码 16 | * @return 登录成功后会返回TOKEN 17 | * @throws JsonProcessingException 实体转成JSON失败抛出该异常 18 | * @see com.project.selflearningplatformserver.util.JwtUtils#buildJwt 19 | */ 20 | String login(String username, String password) throws JsonProcessingException; 21 | 22 | /** 23 | * 学生注册 24 | * 25 | * @param username 用户名 26 | * @param password 密码 27 | * @param name 姓名 28 | * @param studentClassId 所属班级 29 | * @return 注册成功的学生信息 30 | */ 31 | UserDTO reg(String username, String password, String name, String studentClassId); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/dto/StudentLearningDTO.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.dto; 2 | 3 | import com.project.selflearningplatformserver.entity.StudentWork; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * @author itning 11 | * @date 2020/5/3 14:04 12 | */ 13 | @Data 14 | @NoArgsConstructor 15 | public class StudentLearningDTO { 16 | private String id; 17 | 18 | private String learningContentId; 19 | 20 | private String studentId; 21 | 22 | private Date gmtCreate; 23 | 24 | private Date gmtModified; 25 | 26 | private String studentName; 27 | 28 | private StudentWork studentWork; 29 | 30 | public StudentLearningDTO(String id, String learningContentId, String studentId, Date gmtCreate, Date gmtModified, String studentName) { 31 | this.id = id; 32 | this.learningContentId = learningContentId; 33 | this.studentId = studentId; 34 | this.gmtCreate = gmtCreate; 35 | this.gmtModified = gmtModified; 36 | this.studentName = studentName; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/security/SecurityArgumentResolversWebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.security; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * MVC参数配置 12 | * 13 | * @author itning 14 | */ 15 | @Configuration 16 | public class SecurityArgumentResolversWebMvcConfig implements WebMvcConfigurer { 17 | private final SecurityHandlerMethodArgumentResolver securityHandlerMethodArgumentResolver; 18 | 19 | @Autowired 20 | public SecurityArgumentResolversWebMvcConfig(SecurityHandlerMethodArgumentResolver securityHandlerMethodArgumentResolver) { 21 | this.securityHandlerMethodArgumentResolver = securityHandlerMethodArgumentResolver; 22 | } 23 | 24 | @Override 25 | public void addArgumentResolvers(List resolvers) { 26 | resolvers.add(securityHandlerMethodArgumentResolver); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/impl/LogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service.impl; 2 | 3 | import com.project.selflearningplatformserver.entity.Log; 4 | import com.project.selflearningplatformserver.mapper.LogMapper; 5 | import com.project.selflearningplatformserver.service.LogService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import java.util.Comparator; 11 | import java.util.List; 12 | 13 | /** 14 | * @author itning 15 | * @date 2020/5/2 17:04 16 | */ 17 | @Transactional(rollbackFor = Exception.class) 18 | @Service 19 | public class LogServiceImpl implements LogService { 20 | private final LogMapper logMapper; 21 | 22 | @Autowired 23 | public LogServiceImpl(LogMapper logMapper) { 24 | this.logMapper = logMapper; 25 | } 26 | 27 | @Override 28 | public List getSystemLog() { 29 | List logList = logMapper.selectAll(); 30 | logList.sort(Comparator.comparing(Log::getGmtModified).reversed()); 31 | return logList; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/SubjectService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.entity.Subject; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 科目分类 10 | * 11 | * @author itning 12 | * @date 2020/5/1 19:33 13 | */ 14 | public interface SubjectService { 15 | /** 16 | * 根据登录用户(教师)获取科目 17 | * 18 | * @param loginUser 登录用户 19 | * @return 科目集合 20 | */ 21 | List getAllSubject(LoginUser loginUser); 22 | 23 | /** 24 | * 删除科目 25 | * 26 | * @param loginUser 登录用户 27 | * @param subjectId 科目ID 28 | */ 29 | void delSubject(LoginUser loginUser, String subjectId); 30 | 31 | /** 32 | * 新增科目 33 | * 34 | * @param loginUser 登录用户 35 | * @param name 科目名 36 | * @return 新增的科目 37 | */ 38 | Subject newSubject(LoginUser loginUser, String name); 39 | 40 | /** 41 | * 更新科目 42 | * 43 | * @param loginUser 登录用户 44 | * @param subject 更新的科目 45 | * @return 更新的科目 46 | */ 47 | Subject updateSubject(LoginUser loginUser, Subject subject); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/util/CommandUtils.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.util; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.util.List; 8 | import java.util.function.Consumer; 9 | 10 | /** 11 | * @author itning 12 | * @date 2019/7/17 20:56 13 | */ 14 | public class CommandUtils { 15 | /** 16 | * 执行命令 17 | * 18 | * @param command 命令 19 | * @param commandInfo 输出信息 20 | * @throws IOException IOException 21 | */ 22 | public static void process(List command, Consumer commandInfo) throws IOException { 23 | ProcessBuilder builder = new ProcessBuilder(command); 24 | builder.redirectErrorStream(true); 25 | Process process = builder.start(); 26 | try (InputStream inputStream = process.getInputStream(); 27 | InputStreamReader isr = new InputStreamReader(inputStream); 28 | BufferedReader br = new BufferedReader(isr)) { 29 | String line; 30 | while ((line = br.readLine()) != null) { 31 | commandInfo.accept(line); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.UserDTO; 5 | import com.project.selflearningplatformserver.entity.User; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author itning 11 | * @date 2020/5/1 14:27 12 | */ 13 | public interface UserService { 14 | /** 15 | * 获取教师信息 16 | * 17 | * @return 分页后的教师信息 18 | */ 19 | List getAllTeacherUser(); 20 | 21 | /** 22 | * 分页获取学生信息 23 | * 24 | * @return 分页后的学生信息 25 | */ 26 | List getAllStudentUser(); 27 | 28 | /** 29 | * 新增教师 30 | * 31 | * @param name 教师名 32 | * @param username 教师用户名 33 | * @return 新增的教师信息 34 | */ 35 | UserDTO newTeacher(String name, String username); 36 | 37 | /** 38 | *

修改用户 39 | * 40 | * @param loginUser 登录用户 41 | * @param user 修改的信息 42 | */ 43 | void updateUserInfo(LoginUser loginUser, User user); 44 | 45 | /** 46 | * 删除用户信息 47 | * 48 | * @param userId 用户ID 49 | */ 50 | void delUserInfo(String userId); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/config/BeansConfig.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.config; 2 | 3 | import com.project.selflearningplatformserver.video.Video2M3u8Helper; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.web.servlet.MultipartConfigFactory; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import javax.servlet.MultipartConfigElement; 10 | 11 | /** 12 | * @author itning 13 | * @date 2020/5/3 12:05 14 | */ 15 | @Configuration 16 | public class BeansConfig { 17 | private final AppProperties appProperties; 18 | 19 | @Autowired 20 | public BeansConfig(AppProperties appProperties) { 21 | this.appProperties = appProperties; 22 | } 23 | 24 | @Bean 25 | MultipartConfigElement multipartConfigElement() { 26 | MultipartConfigFactory factory = new MultipartConfigFactory(); 27 | factory.setLocation(System.getProperty("java.io.tmpdir")); 28 | return factory.createMultipartConfig(); 29 | } 30 | 31 | @Bean 32 | public Video2M3u8Helper video2M3u8Helper() { 33 | return new Video2M3u8Helper(appProperties.getFfmpegBinDir()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/LogController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.security.MustAdminLogin; 6 | import com.project.selflearningplatformserver.service.LogService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | /** 13 | * @author itning 14 | * @date 2020/5/2 17:03 15 | */ 16 | @RestController 17 | public class LogController { 18 | private final LogService logService; 19 | 20 | @Autowired 21 | public LogController(LogService logService) { 22 | this.logService = logService; 23 | } 24 | 25 | /** 26 | * 管理员获取系统日志 27 | * 28 | * @param loginUser 登陆用户 29 | * @return ResponseEntity 30 | */ 31 | @GetMapping("/system_log") 32 | public ResponseEntity getLogs(@MustAdminLogin LoginUser loginUser) { 33 | return RestModel.ok(logService.getSystemLog()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/ExaminationService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.entity.Examination; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 考试信息 10 | * 11 | * @author itning 12 | * @date 2020/5/1 21:03 13 | */ 14 | public interface ExaminationService { 15 | /** 16 | * 教师获取考试信息 17 | * 18 | * @param loginUser 登录用户 19 | * @return 分页的考试信息集合 20 | */ 21 | List getAllExamination(LoginUser loginUser); 22 | 23 | /** 24 | * 教师删除考试信息 25 | * 26 | * @param loginUser 登录用户 27 | * @param id 考试信息ID 28 | */ 29 | void delExamination(LoginUser loginUser, String id); 30 | 31 | /** 32 | * 教师新增考试信息 33 | * 34 | * @param loginUser 登录用户 35 | * @param name 考试名 36 | * @return 新增的考试信息 37 | */ 38 | Examination newExamination(LoginUser loginUser, String name); 39 | 40 | /** 41 | * 教师更新考试信息 42 | * 43 | * @param loginUser 登录用户 44 | * @param examination 更新的考试信息 45 | * @return 更新的考试信息 46 | */ 47 | Examination updateExamination(LoginUser loginUser, Examination examination); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/TeacherService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.entity.Teacher; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author itning 10 | * @date 2020/5/6 5:54 11 | */ 12 | public interface TeacherService { 13 | /** 14 | * 获取所有教师信息 15 | * 16 | * @param loginUser 登录信息 17 | * @return 教师信息集合 18 | */ 19 | List getAllTeacherInfo(LoginUser loginUser); 20 | 21 | /** 22 | * 根据KEY删除教师信息 23 | * 24 | * @param loginUser 登录用户 25 | * @param id 教师信息ID 26 | */ 27 | void delTeacherInfo(LoginUser loginUser, String id); 28 | 29 | /** 30 | * 新增教师用户信息 31 | * 32 | * @param loginUser 登录用户 33 | * @param attributeKey 属性KEY 34 | * @param attributeValue 属性VALUE 35 | * @return 新教师信息 36 | */ 37 | Teacher newTeacherInfo(LoginUser loginUser, String attributeKey, String attributeValue); 38 | 39 | /** 40 | * 更新用户信息 41 | * 42 | * @param loginUser 登录用户 43 | * @param teacher 修改的教师信息 44 | * @return 教师信息 45 | */ 46 | Teacher updateTeacherInfo(LoginUser loginUser, Teacher teacher); 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/AttendanceService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.dto.AttendanceDTO; 4 | import com.project.selflearningplatformserver.dto.LoginUser; 5 | 6 | import java.time.LocalDateTime; 7 | import java.util.List; 8 | 9 | /** 10 | * 出勤 11 | * 12 | * @author itning 13 | * @date 2020/5/1 22:30 14 | */ 15 | public interface AttendanceService { 16 | /** 17 | * 管理员获取出勤记录 18 | * 19 | * @param roleId 角色 20 | * @return 出勤记录 21 | */ 22 | List getAllAttendances(String roleId); 23 | 24 | /** 25 | * 教师/学生新增出勤记录 26 | * 27 | * @param loginUser 登录用户 28 | * @return 出勤记录 29 | */ 30 | AttendanceDTO newAttendance(LoginUser loginUser); 31 | 32 | /** 33 | * 管理员新增出勤记录 34 | * 35 | * @param userId 用户ID 36 | * @param localDateTime 时间 37 | * @return 出勤记录 38 | */ 39 | AttendanceDTO newAttendance(String userId, LocalDateTime localDateTime); 40 | 41 | /** 42 | * 删除出勤记录 43 | * 44 | * @param id 出勤记录ID 45 | */ 46 | void delAttendance(String id); 47 | 48 | /** 49 | * 修改出勤记录 50 | * 51 | * @param id 记录ID 52 | * @param localDateTime 新时间 53 | * @return 出勤记录 54 | */ 55 | AttendanceDTO updateAttendance(String id, LocalDateTime localDateTime); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/config/CustomWebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 6 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | 9 | /** 10 | * MVC参数配置 11 | * 12 | * @author itning 13 | */ 14 | @Configuration 15 | public class CustomWebMvcConfig implements WebMvcConfigurer { 16 | private final AppProperties appProperties; 17 | 18 | @Autowired 19 | public CustomWebMvcConfig(AppProperties appProperties) { 20 | this.appProperties = appProperties; 21 | } 22 | 23 | @Override 24 | public void addCorsMappings(CorsRegistry registry) { 25 | registry.addMapping("/**") 26 | .allowedOrigins("*") 27 | .allowCredentials(true) 28 | .allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH") 29 | .maxAge(86400); 30 | } 31 | 32 | @Override 33 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 34 | registry.addResourceHandler("/video/**") 35 | .addResourceLocations("file:" + appProperties.getLearningContentTranscodingDir()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/security/MustLogin.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.security; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 表示登录后才可以进行访问 7 | * 8 | * @author itning 9 | */ 10 | @Target({ElementType.PARAMETER, ElementType.TYPE}) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | @Inherited 14 | public @interface MustLogin { 15 | /** 16 | * 登录角色 17 | * 18 | * @return 角色数组 19 | */ 20 | ROLE[] role() default {ROLE.ADMIN, ROLE.STUDENT, ROLE.TEACHER}; 21 | 22 | enum ROLE { 23 | /** 24 | * 管理员 25 | */ 26 | ADMIN("a", "管理员"), 27 | /** 28 | * 教师 29 | */ 30 | TEACHER("b", "教师"), 31 | /** 32 | * 学生 33 | */ 34 | STUDENT("c", "学生"); 35 | 36 | private final String id; 37 | private final String name; 38 | 39 | ROLE(String id, String name) { 40 | this.id = id; 41 | this.name = name; 42 | } 43 | 44 | public String getId() { 45 | return id; 46 | } 47 | 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "ROLE{" + 55 | "id='" + id + '\'' + 56 | ", name='" + name + '\'' + 57 | '}'; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/StudentLearningService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.dto.LearningContentDTO; 4 | import com.project.selflearningplatformserver.dto.LoginUser; 5 | import com.project.selflearningplatformserver.dto.StudentLearningDTO; 6 | import com.project.selflearningplatformserver.entity.StudentLearning; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author itning 12 | * @date 2020/5/2 11:24 13 | */ 14 | public interface StudentLearningService { 15 | /** 16 | * 学生选择学习内容进行学习 17 | * 18 | * @param loginUser 登录用户 19 | * @param learningContentId 学习内容ID 20 | * @return 选择 21 | */ 22 | StudentLearning switchLearningContent(LoginUser loginUser, String learningContentId); 23 | 24 | /** 25 | * 学生获取自己的学习内容 26 | * 27 | * @param loginUser 登录用户 28 | * @return 分页的学习内容 29 | */ 30 | List getMyLearning(LoginUser loginUser); 31 | 32 | /** 33 | * 学生取消学习该内容 34 | * 35 | * @param loginUser 登录用户 36 | * @param studentLearningId 学生学习ID 37 | */ 38 | void delMyLearning(LoginUser loginUser, String studentLearningId); 39 | 40 | /** 41 | * 教师获取学生学习情况 42 | * 43 | * @param loginUser 登录用户 44 | * @param learningContentId 学习内容ID 45 | * @return 学生学习情况 46 | */ 47 | List getAllStudentInLearning(LoginUser loginUser, String learningContentId); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/util/Md5Utils.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.util; 2 | 3 | import org.apache.commons.codec.binary.Base64; 4 | import org.apache.commons.codec.digest.DigestUtils; 5 | 6 | import java.security.SecureRandom; 7 | 8 | /** 9 | * @author itning 10 | * @date 2020/5/1 14:02 11 | */ 12 | public class Md5Utils { 13 | /** 14 | * 字符串转MD5 15 | * 16 | * @param src 字符串 17 | * @param salt 盐 18 | * @return MD5 19 | */ 20 | public static String string2Md5(String src, String salt) { 21 | return DigestUtils.md5Hex(src + salt); 22 | } 23 | 24 | /** 25 | * 字符串转MD5 26 | * 27 | * @param src 字符串 28 | * @return Tuple2<MD5,SALT> 29 | */ 30 | public static Tuple2 string2Md5(String src) { 31 | SecureRandom random = new SecureRandom(); 32 | byte[] bytes = new byte[15]; 33 | random.nextBytes(bytes); 34 | String salt = Base64.encodeBase64String(bytes); 35 | return new Tuple2<>(string2Md5(src, salt), salt); 36 | } 37 | 38 | /** 39 | * 检查MD5是否匹配 40 | * 41 | * @param src 源字符串 42 | * @param srcSalt 源字符串盐 43 | * @param md5 要比较的值 44 | * @return 相同返回true 45 | */ 46 | public static boolean checkEquals(String src, String srcSalt, String md5) { 47 | return string2Md5(src, srcSalt).equals(md5); 48 | } 49 | 50 | public static void main(String[] args) { 51 | System.out.println(string2Md5("admin", "a")); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/exception/ErrorHandler.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.exception; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.web.servlet.error.ErrorAttributes; 5 | import org.springframework.boot.web.servlet.error.ErrorController; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | import org.springframework.web.context.request.ServletWebRequest; 10 | import org.springframework.web.context.request.WebRequest; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import java.util.Map; 14 | 15 | /** 16 | * 错误处理器 17 | * 18 | * @author itning 19 | */ 20 | @RestController 21 | public class ErrorHandler implements ErrorController { 22 | private final ErrorAttributes errorAttributes; 23 | 24 | @Autowired 25 | public ErrorHandler(ErrorAttributes errorAttributes) { 26 | this.errorAttributes = errorAttributes; 27 | } 28 | 29 | @Override 30 | public String getErrorPath() { 31 | return "/error"; 32 | } 33 | 34 | @RequestMapping(value = "/error", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) 35 | public String error(HttpServletRequest request) { 36 | WebRequest webRequest = new ServletWebRequest(request); 37 | Map errorAttributes = this.errorAttributes.getErrorAttributes(webRequest, true); 38 | String msg = errorAttributes.getOrDefault("error", "not found").toString(); 39 | String code = errorAttributes.getOrDefault("status", 404).toString(); 40 | return "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"data\":\"\"}"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/util/OrikaUtils.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.util; 2 | 3 | import ma.glasnost.orika.MapperFactory; 4 | import ma.glasnost.orika.impl.DefaultMapperFactory; 5 | import org.springframework.lang.NonNull; 6 | import org.springframework.lang.Nullable; 7 | 8 | /** 9 | * 实体映射工具类 10 | * 11 | * @author itning 12 | */ 13 | public class OrikaUtils { 14 | private static final MapperFactory MAPPER_FACTORY = new DefaultMapperFactory.Builder().build(); 15 | 16 | /** 17 | * 将两个实体合并为一个DTO 18 | * input1,input2 不能全为 {@code null} 19 | * 20 | * @param input1 第一个输入实体 21 | * @param input2 第二个输入实体 22 | * @param result DTO类型 23 | * @param DTO 24 | * @param ENTITY 25 | * @param ENTITY 26 | * @return DTO类型 27 | */ 28 | @NonNull 29 | public static R doubleEntity2Dto(@Nullable A input1, @Nullable B input2, @NonNull Class result) { 30 | if (input1 != null && input2 != null) { 31 | R r = MAPPER_FACTORY.getMapperFacade().map(input1, result); 32 | MAPPER_FACTORY.getMapperFacade().map(input2, r); 33 | return r; 34 | } else if (input1 != null) { 35 | return MAPPER_FACTORY.getMapperFacade().map(input1, result); 36 | } else { 37 | return MAPPER_FACTORY.getMapperFacade().map(input2, result); 38 | } 39 | } 40 | 41 | /** 42 | * A 实体 转换 B 实体 43 | * 44 | * @param a A实例 45 | * @param bClass B类型 46 | * @param A 47 | * @param B 48 | * @return B 实例 49 | */ 50 | public static B a2b(A a, Class bClass) { 51 | return MAPPER_FACTORY.getMapperFacade().map(a, bClass); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/config/EnvironmentCheckConfig.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.EnvironmentAware; 5 | import org.springframework.core.env.Environment; 6 | import org.springframework.lang.NonNull; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.io.File; 10 | 11 | /** 12 | * @author itning 13 | * @date 2020/5/10 15:54 14 | */ 15 | @Slf4j 16 | @Component 17 | public class EnvironmentCheckConfig implements EnvironmentAware { 18 | 19 | @Override 20 | public void setEnvironment(@NonNull Environment environment) { 21 | checkDirExist(environment.getRequiredProperty("app.learning-content-dir", File.class)); 22 | checkDirExist(environment.getRequiredProperty("app.learning-content-aid-dir", File.class)); 23 | checkDirExist(environment.getRequiredProperty("app.learning-content-transcoding-dir", File.class)); 24 | checkDirExist(environment.getRequiredProperty("app.student-work-dir", File.class)); 25 | checkDirExist(environment.getRequiredProperty("app.ffmpeg-bin-dir", File.class)); 26 | } 27 | 28 | private void checkDirExist(File dir) { 29 | if (!dir.exists()) { 30 | if (dir.mkdirs()) { 31 | if (log.isInfoEnabled()) { 32 | log.info("Created Dir From Path {}", dir); 33 | } 34 | checkDirExist(dir); 35 | } else { 36 | throw new RuntimeException("Create Dir Failed And Path " + dir); 37 | } 38 | } else { 39 | if (!dir.isDirectory()) { 40 | throw new RuntimeException("Path " + dir + " Not Dir"); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/ExaminationScoreService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.dto.ExaminationScoreDTO; 4 | import com.project.selflearningplatformserver.dto.ExaminationScoreWithExamName; 5 | import com.project.selflearningplatformserver.dto.LoginUser; 6 | import com.project.selflearningplatformserver.entity.ExaminationScore; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * 某考试信息所有分数 12 | * 13 | * @author itning 14 | * @date 2020/5/1 21:29 15 | */ 16 | public interface ExaminationScoreService { 17 | /** 18 | * 教师分页考取考试分数信息 19 | * 20 | * @param loginUser 登录用户 21 | * @param examinationId 考试信息ID 22 | * @return 分页的考试分数信息 23 | */ 24 | List getAllByExaminationId(LoginUser loginUser, String examinationId); 25 | 26 | /** 27 | * 教师删除考试分数信息 28 | * 29 | * @param loginUser 登录用户 30 | * @param id 考试分数信息ID 31 | */ 32 | void del(LoginUser loginUser, String id); 33 | 34 | /** 35 | * 教师新增考试信息 36 | * 37 | * @param loginUser 登录用户 38 | * @param examinationScore 考试信息 39 | * @return 新增的考试信息 40 | */ 41 | ExaminationScoreDTO newExaminationScore(LoginUser loginUser, ExaminationScore examinationScore); 42 | 43 | /** 44 | * 教师更新考试信息 45 | * 46 | * @param loginUser 登录用户 47 | * @param examinationScore 考试信息 48 | * @return 更新的考试信息 49 | */ 50 | ExaminationScoreDTO updateExaminationScore(LoginUser loginUser, ExaminationScore examinationScore); 51 | 52 | /** 53 | * 获取学生自己的成绩 54 | * 55 | * @param loginUser 登录用户 56 | * @return 成绩集合 57 | */ 58 | List getStudentOwnExaminationScore(LoginUser loginUser); 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/StudentWorkService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.entity.StudentWork; 5 | import org.springframework.http.HttpHeaders; 6 | import org.springframework.web.multipart.MultipartFile; 7 | 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | /** 11 | * @author itning 12 | * @date 2020/5/2 11:45 13 | */ 14 | public interface StudentWorkService { 15 | /** 16 | * 教师批改作业 17 | * 18 | * @param loginUser 登录用户 19 | * @param studentWorkId 学生作业ID 20 | * @param suggest 建议 21 | * @param score 分数 22 | * @return 批改完的学生作业 23 | */ 24 | StudentWork teacherReview(LoginUser loginUser, String studentWorkId, String suggest, int score); 25 | 26 | /** 27 | * 学生删除作业 28 | * 29 | * @param loginUser 登录用户 30 | * @param studentWorkId 学生作业ID 31 | */ 32 | void delWork(LoginUser loginUser, String studentWorkId); 33 | 34 | /** 35 | * 下载作业 36 | * 37 | * @param loginUser 登录用户 38 | * @param id 作业ID 39 | * @param response {@link HttpServletResponse} 40 | * @param range {@link HttpHeaders#RANGE} 41 | */ 42 | void downloadWorkFile(LoginUser loginUser, String id, HttpServletResponse response, String range); 43 | 44 | /** 45 | * 学生上传作业 46 | * 47 | * @param loginUser 登录用户 48 | * @param studentLearningId 学生学习ID 49 | * @param file 文件 50 | * @return 作业信息 51 | */ 52 | StudentWork upload(LoginUser loginUser, String studentLearningId, MultipartFile file); 53 | 54 | /** 55 | * 学生获取自己的作业 56 | * @param loginUser 登录用户 57 | * @param learningContentId 学习内容ID 58 | * @return 作业信息 59 | */ 60 | StudentWork getOwnWork(LoginUser loginUser, String learningContentId); 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/dto/RestModel.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.dto; 2 | 3 | import lombok.ToString; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * Rest 返回消息 11 | * 12 | * @author itning 13 | */ 14 | @ToString 15 | public class RestModel implements Serializable { 16 | private int code; 17 | private String msg; 18 | private T data; 19 | 20 | public RestModel() { 21 | 22 | } 23 | 24 | private RestModel(HttpStatus status, String msg, T data) { 25 | this(status.value(), msg, data); 26 | } 27 | 28 | private RestModel(int code, String msg, T data) { 29 | this.code = code; 30 | this.msg = msg; 31 | this.data = data; 32 | } 33 | 34 | public static ResponseEntity> ok(T data) { 35 | return ResponseEntity.ok(new RestModel<>(HttpStatus.OK, "查询成功", data)); 36 | } 37 | 38 | public static ResponseEntity> created() { 39 | return ResponseEntity.status(HttpStatus.CREATED).build(); 40 | } 41 | 42 | public static ResponseEntity> created(T data) { 43 | return ResponseEntity.status(HttpStatus.CREATED).body(new RestModel<>(HttpStatus.CREATED, "创建成功", data)); 44 | } 45 | 46 | public static ResponseEntity noContent() { 47 | return ResponseEntity.noContent().build(); 48 | } 49 | 50 | public int getCode() { 51 | return code; 52 | } 53 | 54 | public void setCode(int code) { 55 | this.code = code; 56 | } 57 | 58 | public String getMsg() { 59 | return msg; 60 | } 61 | 62 | public void setMsg(String msg) { 63 | this.msg = msg; 64 | } 65 | 66 | public T getData() { 67 | return data; 68 | } 69 | 70 | public void setData(T data) { 71 | this.data = data; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/config/AppTomcatConnectorCustomizer.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.config; 2 | 3 | import org.apache.coyote.ProtocolHandler; 4 | import org.apache.coyote.http11.AbstractHttp11Protocol; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; 8 | import org.springframework.boot.web.server.WebServerFactoryCustomizer; 9 | import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; 10 | import org.springframework.stereotype.Component; 11 | 12 | /** 13 | * @author itning 14 | * @date 2020/4/9 18:03 15 | */ 16 | @Component 17 | public class AppTomcatConnectorCustomizer implements WebServerFactoryCustomizer { 18 | private static final Logger log = LoggerFactory.getLogger(AppTomcatConnectorCustomizer.class); 19 | 20 | @Override 21 | public void customize(ConfigurableServletWebServerFactory factory) { 22 | if (factory instanceof TomcatServletWebServerFactory) { 23 | TomcatServletWebServerFactory f = (TomcatServletWebServerFactory) factory; 24 | f.setProtocol("org.apache.coyote.http11.Http11Nio2Protocol"); 25 | if (log.isDebugEnabled()) { 26 | f.addConnectorCustomizers(connector -> { 27 | ProtocolHandler protocol = connector.getProtocolHandler(); 28 | 29 | log.debug("Tomcat({}) -- MaxConnection:{};MaxThreads:{};MinSpareThreads:{}", 30 | protocol.getClass().getName(), 31 | ((AbstractHttp11Protocol) protocol).getMaxConnections(), 32 | ((AbstractHttp11Protocol) protocol).getMaxThreads(), 33 | ((AbstractHttp11Protocol) protocol).getMinSpareThreads()); 34 | }); 35 | } 36 | } else { 37 | log.warn("ConfigurableServletWebServerFactory is not instanceof TomcatServletWebServerFactory and is: {}", factory.getClass().getName()); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/StudentClassServer.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.StudentClassDTO; 5 | import com.project.selflearningplatformserver.dto.UserDTO; 6 | import com.project.selflearningplatformserver.entity.Student; 7 | import com.project.selflearningplatformserver.entity.StudentClass; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 教师创建的班级 13 | * 14 | * @author itning 15 | * @date 2020/5/1 20:02 16 | */ 17 | public interface StudentClassServer { 18 | /** 19 | * 获取教师所有班级 20 | * 21 | * @param loginUser 登录用户 22 | * @return 班级集合 23 | */ 24 | List getAll(LoginUser loginUser); 25 | 26 | /** 27 | * 删除班级 28 | * 29 | * @param loginUser 登录用户 30 | * @param id 班级ID 31 | */ 32 | void del(LoginUser loginUser, String id); 33 | 34 | /** 35 | * 教师新增班级 36 | * 37 | * @param loginUser 登录用户 38 | * @param name 班级名 39 | * @return 新增的班级 40 | */ 41 | StudentClass newStudentClass(LoginUser loginUser, String name); 42 | 43 | /** 44 | * 教师修改班级 45 | * 46 | * @param loginUser 登录用户 47 | * @param studentClass 修改的班级信息 48 | * @return 修改的班级 49 | */ 50 | StudentClass updateStudentClass(LoginUser loginUser, StudentClass studentClass); 51 | 52 | /** 53 | * 获取所有班级信息 54 | * 55 | * @return 班级集合 56 | */ 57 | List getAll(); 58 | 59 | /** 60 | * 获取某教师的所有班级学生 61 | * 62 | * @param loginUser 登录用户 63 | * @return 所有班级学生 64 | */ 65 | List getAllStudentInClass(LoginUser loginUser); 66 | 67 | /** 68 | * 学生获取自己的班级 69 | * 70 | * @param loginUser 登录用户 71 | * @return 班级信息 72 | */ 73 | StudentClassDTO getStudentOwnClass(LoginUser loginUser); 74 | 75 | /** 76 | * 学生加入班级(覆盖) 77 | * 78 | * @param loginUser 登录用户 79 | * @param classId 班级ID 80 | * @return 学生信息 81 | */ 82 | Student joinClass(LoginUser loginUser, String classId); 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/LearningContentService.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.entity.LearningContent; 5 | import org.springframework.web.multipart.MultipartFile; 6 | 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.util.List; 9 | 10 | /** 11 | * 学习内容 12 | * 13 | * @author itning 14 | * @date 2020/5/1 20:32 15 | */ 16 | public interface LearningContentService { 17 | /** 18 | * 分页获取学习内容 19 | * 20 | * @param subjectId 科目ID 21 | * @return 分页学习内容集合 22 | */ 23 | List getAllBySubjectId(String subjectId); 24 | 25 | /** 26 | * 教师删除学习内容 27 | * 28 | * @param loginUser 登录用户 29 | * @param id 学习内容ID 30 | */ 31 | void delLearningContent(LoginUser loginUser, String id); 32 | 33 | /** 34 | * 教师新增学习内容 35 | * 36 | * @param loginUser 登录用户 37 | * @param file 文件 38 | * @param aidFile 其他文件 39 | * @param subjectId 科目ID 40 | * @param name 名称 41 | * @return 新增的学习内容 42 | */ 43 | LearningContent newLearningContent(LoginUser loginUser, MultipartFile file, MultipartFile aidFile, String subjectId, String name); 44 | 45 | /** 46 | * 教师更新学习内容 47 | * 48 | * @param loginUser 登录用户 49 | * @return 修改的学习内容 50 | */ 51 | LearningContent updateLearningContent(LoginUser loginUser, String id, String name); 52 | 53 | /** 54 | * 学生获取所有可以学习的内容(排除已经选择的) 55 | * 56 | * @param loginUser 登录用户 57 | * @return 学习内容集合 58 | */ 59 | List getAllCanLearningContent(LoginUser loginUser); 60 | 61 | /** 62 | * 下载学习内容文件 63 | * 64 | * @param loginUser 登录用户 65 | * @param learningContentId 学习内容ID 66 | * @param range {@link org.springframework.http.HttpHeaders#RANGE} 67 | * @param response {@link HttpServletResponse} 68 | * @param type aid or video 69 | */ 70 | void downloadLearningContent(LoginUser loginUser, String learningContentId, String range, HttpServletResponse response, String type); 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/SecurityController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.service.SecurityService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | /** 14 | * 安全相关,登录注册等功能 15 | * 16 | * @author itning 17 | * @date 2020/5/1 13:58 18 | */ 19 | @RestController 20 | @RequestMapping("/security") 21 | public class SecurityController { 22 | private final SecurityService securityService; 23 | 24 | @Autowired 25 | public SecurityController(SecurityService securityService) { 26 | this.securityService = securityService; 27 | } 28 | 29 | /** 30 | * 登录 31 | * 32 | * @param username 用户名 33 | * @param password 密码 34 | * @return ResponseEntity 35 | * @throws JsonProcessingException see {@link SecurityService#login} 36 | */ 37 | @PostMapping("/login") 38 | public ResponseEntity login(@RequestParam String username, 39 | @RequestParam String password) throws JsonProcessingException { 40 | return RestModel.ok(securityService.login(username, password)); 41 | } 42 | 43 | /** 44 | * 学生注册 45 | * 46 | * @param username 用户名 47 | * @param password 密码 48 | * @param name 姓名 49 | * @param studentClassId 所属班级ID 50 | * @return ResponseEntity 51 | */ 52 | @PostMapping("/reg") 53 | public ResponseEntity registration(@RequestParam String username, 54 | @RequestParam String password, 55 | @RequestParam String name, 56 | @RequestParam String studentClassId) { 57 | return RestModel.created(securityService.reg(username, password, name, studentClassId)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/config/AppProperties.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.config; 2 | 3 | import lombok.Getter; 4 | import lombok.ToString; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.validation.annotation.Validated; 8 | 9 | import javax.validation.constraints.NotBlank; 10 | import java.io.File; 11 | 12 | /** 13 | * @author itning 14 | * @date 2020/5/3 11:20 15 | */ 16 | @ToString 17 | @Getter 18 | @Component 19 | @Validated 20 | @ConfigurationProperties("app") 21 | public class AppProperties { 22 | /** 23 | * 学习内容文件存放目录 24 | */ 25 | @NotBlank(message = "请配置学习内容文件存放目录") 26 | private String learningContentDir; 27 | 28 | /** 29 | * 学习内容额外文件存放目录 30 | */ 31 | @NotBlank(message = "请配置学习内容额外文件存放目录") 32 | private String learningContentAidDir; 33 | 34 | /** 35 | * 学习内容文件转码后存放的目录 36 | */ 37 | @NotBlank(message = "请配置学习内容文件转码后存放的目录") 38 | private String learningContentTranscodingDir; 39 | 40 | /** 41 | * 学生作业文件存放目录 42 | */ 43 | @NotBlank(message = "请配置学生作业文件存放目录") 44 | private String studentWorkDir; 45 | 46 | /** 47 | * FFmpeg Bin 目录 48 | */ 49 | @NotBlank(message = "请配置 FFmpeg Bin 目录") 50 | private String ffmpegBinDir; 51 | 52 | public void setLearningContentDir(String learningContentDir) { 53 | this.learningContentDir = addDirSeparator(learningContentDir); 54 | } 55 | 56 | public void setLearningContentTranscodingDir(String learningContentTranscodingDir) { 57 | this.learningContentTranscodingDir = addDirSeparator(learningContentTranscodingDir); 58 | } 59 | 60 | public void setFfmpegBinDir(String ffmpegBinDir) { 61 | this.ffmpegBinDir = addDirSeparator(ffmpegBinDir); 62 | } 63 | 64 | public void setStudentWorkDir(String studentWorkDir) { 65 | this.studentWorkDir = addDirSeparator(studentWorkDir); 66 | } 67 | 68 | public void setLearningContentAidDir(String learningContentAidDir) { 69 | this.learningContentAidDir = addDirSeparator(learningContentAidDir); 70 | } 71 | 72 | /** 73 | * 添加斜杠 74 | * 75 | * @param dirPath 目录路径 76 | * @return 目录路径 77 | * @see File#separator 78 | */ 79 | private String addDirSeparator(String dirPath) { 80 | if (!dirPath.endsWith(File.separator)) { 81 | dirPath += File.separator; 82 | } 83 | return dirPath; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/SubjectController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.entity.Subject; 6 | import com.project.selflearningplatformserver.log.Log; 7 | import com.project.selflearningplatformserver.security.MustTeacherLogin; 8 | import com.project.selflearningplatformserver.service.SubjectService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | /** 14 | * @author itning 15 | * @date 2020/5/1 19:46 16 | */ 17 | @RestController 18 | public class SubjectController { 19 | private final SubjectService subjectService; 20 | 21 | @Autowired 22 | public SubjectController(SubjectService subjectService) { 23 | this.subjectService = subjectService; 24 | } 25 | 26 | /** 27 | * 根据教师信息获取科目集合 28 | * 29 | * @param loginUser 登录用户 30 | * @return ResponseEntity 31 | */ 32 | @GetMapping("/subjects") 33 | public ResponseEntity getAllSubjects(@MustTeacherLogin LoginUser loginUser) { 34 | return RestModel.ok(subjectService.getAllSubject(loginUser)); 35 | } 36 | 37 | /** 38 | * 教师新增科目 39 | * 40 | * @param loginUser 登录用户 41 | * @param name 科目名 42 | * @return ResponseEntity 43 | */ 44 | @Log("新增科目") 45 | @PostMapping("/subject") 46 | public ResponseEntity newSubject(@MustTeacherLogin LoginUser loginUser, 47 | @RequestParam String name) { 48 | return RestModel.created(subjectService.newSubject(loginUser, name)); 49 | } 50 | 51 | /** 52 | * 教师修改科目 53 | * 54 | * @param loginUser 登录用户 55 | * @param subject 科目信息 56 | * @return ResponseEntity 57 | */ 58 | @Log("修改科目") 59 | @PatchMapping("/subject") 60 | public ResponseEntity updateSubject(@MustTeacherLogin LoginUser loginUser, 61 | @RequestBody Subject subject) { 62 | subjectService.updateSubject(loginUser, subject); 63 | return RestModel.noContent(); 64 | } 65 | 66 | /** 67 | * 教师删除科目 68 | * 69 | * @param loginUser 登录用户 70 | * @param subjectId 科目ID 71 | * @return ResponseEntity 72 | */ 73 | @Log("删除科目") 74 | @DeleteMapping("/subject/{subjectId}") 75 | public ResponseEntity delSubject(@MustTeacherLogin LoginUser loginUser, 76 | @PathVariable String subjectId) { 77 | subjectService.delSubject(loginUser, subjectId); 78 | return RestModel.noContent(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/util/JwtUtils.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.util; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.project.selflearningplatformserver.dto.LoginUser; 6 | import com.project.selflearningplatformserver.exception.TokenException; 7 | import io.jsonwebtoken.*; 8 | import org.springframework.http.HttpStatus; 9 | 10 | import java.util.Date; 11 | 12 | /** 13 | * Jwt 工具类 14 | * 15 | * @author itning 16 | */ 17 | public final class JwtUtils { 18 | private static final String PRIVATE_KEY = "itning"; 19 | private static final String LOGIN_USER = "loginUser"; 20 | private static final String DEFAULT_STR = "null"; 21 | private static final ObjectMapper MAPPER = new ObjectMapper(); 22 | 23 | private JwtUtils() { 24 | 25 | } 26 | 27 | public static String buildJwt(Object o) throws JsonProcessingException { 28 | return Jwts.builder() 29 | //SECRET_KEY是加密算法对应的密钥,这里使用额是HS256加密算法 30 | .signWith(SignatureAlgorithm.HS256, PRIVATE_KEY) 31 | //expTime是过期时间 32 | .setExpiration(new Date(System.currentTimeMillis() + 240 * 60 * 1000)) 33 | .claim(LOGIN_USER, MAPPER.writeValueAsString(o)) 34 | //令牌的发行者 35 | .setIssuer("itning") 36 | .compact(); 37 | } 38 | 39 | public static LoginUser getLoginUser(String jwt) { 40 | if (DEFAULT_STR.equals(jwt)) { 41 | throw new TokenException("请先登陆", HttpStatus.UNAUTHORIZED); 42 | } 43 | try { 44 | //解析JWT字符串中的数据,并进行最基础的验证 45 | Claims claims = Jwts.parser() 46 | //SECRET_KEY是加密算法对应的密钥,jjwt可以自动判断机密算法 47 | .setSigningKey(PRIVATE_KEY) 48 | //jwt是JWT字符串 49 | .parseClaimsJws(jwt) 50 | .getBody(); 51 | //获取自定义字段key 52 | String loginUserJson = claims.get(LOGIN_USER, String.class); 53 | LoginUser loginUser = MAPPER.readValue(loginUserJson, LoginUser.class); 54 | //判断自定义字段是否正确 55 | if (loginUser == null) { 56 | throw new TokenException("登陆失败", HttpStatus.UNAUTHORIZED); 57 | } else { 58 | return loginUser; 59 | } 60 | //在解析JWT字符串时,如果密钥不正确,将会解析失败,抛出SignatureException异常,说明该JWT字符串是伪造的 61 | //在解析JWT字符串时,如果‘过期时间字段’已经早于当前时间,将会抛出ExpiredJwtException异常,说明本次请求已经失效 62 | } catch (ExpiredJwtException e) { 63 | throw new TokenException("登陆超时", HttpStatus.UNAUTHORIZED); 64 | } catch (SignatureException e) { 65 | throw new TokenException("凭据错误", HttpStatus.BAD_REQUEST); 66 | } catch (Exception e) { 67 | throw new TokenException("登陆失败", HttpStatus.UNAUTHORIZED); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/ExaminationController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.entity.Examination; 6 | import com.project.selflearningplatformserver.log.Log; 7 | import com.project.selflearningplatformserver.security.MustTeacherLogin; 8 | import com.project.selflearningplatformserver.service.ExaminationService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | /** 14 | * @author itning 15 | * @date 2020/5/1 22:14 16 | */ 17 | @RestController 18 | public class ExaminationController { 19 | private final ExaminationService examinationService; 20 | 21 | @Autowired 22 | public ExaminationController(ExaminationService examinationService) { 23 | this.examinationService = examinationService; 24 | } 25 | 26 | /** 27 | * 教师分页获取所有考试信息 28 | * 29 | * @param loginUser 登录用户 30 | * @return ResponseEntity 31 | */ 32 | @GetMapping("/examinations") 33 | public ResponseEntity allExaminationInfo(@MustTeacherLogin LoginUser loginUser) { 34 | return RestModel.ok(examinationService.getAllExamination(loginUser)); 35 | } 36 | 37 | /** 38 | * 教师删除考试信息 39 | * 40 | * @param loginUser 登录用户 41 | * @param id 要删除的考试信息ID 42 | * @return ResponseEntity 43 | */ 44 | @Log("删除考试信息") 45 | @DeleteMapping("/examination/{id}") 46 | public ResponseEntity delExamination(@MustTeacherLogin LoginUser loginUser, 47 | @PathVariable String id) { 48 | examinationService.delExamination(loginUser, id); 49 | return RestModel.noContent(); 50 | } 51 | 52 | /** 53 | * 教师新增考试信息 54 | * 55 | * @param loginUser 登录用户 56 | * @param name 考试信息名 57 | * @return ResponseEntity 58 | */ 59 | @Log("新增考试信息") 60 | @PostMapping("/examination") 61 | public ResponseEntity newExamination(@MustTeacherLogin LoginUser loginUser, 62 | @RequestParam String name) { 63 | return RestModel.created(examinationService.newExamination(loginUser, name)); 64 | } 65 | 66 | /** 67 | * 教师修改考试信息 68 | * 69 | * @param loginUser 登录用户 70 | * @param examination 修改的考试信息 71 | * @return ResponseEntity 72 | */ 73 | @Log("修改考试信息") 74 | @PatchMapping("/examination") 75 | public ResponseEntity updateExamination(@MustTeacherLogin LoginUser loginUser, 76 | @RequestBody Examination examination) { 77 | examinationService.updateExamination(loginUser, examination); 78 | return RestModel.noContent(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/AnnouncementController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.entity.Announcement; 6 | import com.project.selflearningplatformserver.log.Log; 7 | import com.project.selflearningplatformserver.security.MustAdminLogin; 8 | import com.project.selflearningplatformserver.security.MustLogin; 9 | import com.project.selflearningplatformserver.service.AnnouncementService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | /** 15 | * 公告 16 | * 17 | * @author itning 18 | * @date 2020/5/1 19:04 19 | */ 20 | @RestController 21 | public class AnnouncementController { 22 | private final AnnouncementService announcementService; 23 | 24 | @Autowired 25 | public AnnouncementController(AnnouncementService announcementService) { 26 | this.announcementService = announcementService; 27 | } 28 | 29 | /** 30 | * 获取公告信息 31 | * 32 | * @param loginUser 登录用户 33 | * @return ResponseEntity 34 | */ 35 | @GetMapping("/announcements") 36 | public ResponseEntity getAllAnnouncement(@MustLogin LoginUser loginUser) { 37 | return RestModel.ok(announcementService.getAll()); 38 | } 39 | 40 | /** 41 | * 管理员新增公告 42 | * 43 | * @param loginUser 登录用户 44 | * @param content 内容 45 | * @return ResponseEntity 46 | */ 47 | @Log("新增公告") 48 | @PostMapping("/announcement") 49 | public ResponseEntity newAnnouncement(@MustAdminLogin LoginUser loginUser, 50 | @RequestParam String content) { 51 | return RestModel.created(announcementService.newAnnouncement(content)); 52 | } 53 | 54 | /** 55 | * 管理员删除公告 56 | * 57 | * @param loginUser 登录用户 58 | * @param id 公告ID 59 | * @return ResponseEntity 60 | */ 61 | @Log("删除公告") 62 | @DeleteMapping("/announcement/{id}") 63 | public ResponseEntity delAnnouncement(@MustAdminLogin LoginUser loginUser, 64 | @PathVariable String id) { 65 | announcementService.del(id); 66 | return RestModel.noContent(); 67 | } 68 | 69 | /** 70 | * 管理员修改公告 71 | * 72 | * @param loginUser 登录用户 73 | * @param announcement 修改的公告信息 74 | * @return ResponseEntity 75 | */ 76 | @Log("修改公告") 77 | @PatchMapping("/announcement") 78 | public ResponseEntity updateAnnouncement(@MustAdminLogin LoginUser loginUser, 79 | @RequestBody Announcement announcement) { 80 | announcementService.update(announcement.getId(), announcement.getContent()); 81 | return RestModel.noContent(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/impl/AnnouncementServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service.impl; 2 | 3 | import java.util.Date; 4 | 5 | import com.project.selflearningplatformserver.entity.Announcement; 6 | import com.project.selflearningplatformserver.exception.IdNotFoundException; 7 | import com.project.selflearningplatformserver.exception.NullFiledException; 8 | import com.project.selflearningplatformserver.mapper.AnnouncementMapper; 9 | import com.project.selflearningplatformserver.service.AnnouncementService; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Service; 13 | import org.springframework.transaction.annotation.Transactional; 14 | 15 | import java.util.List; 16 | import java.util.UUID; 17 | 18 | /** 19 | * @author itning 20 | * @date 2020/5/1 18:57 21 | */ 22 | @Transactional(rollbackFor = Exception.class) 23 | @Service 24 | public class AnnouncementServiceImpl implements AnnouncementService { 25 | private final AnnouncementMapper announcementMapper; 26 | 27 | @Autowired 28 | public AnnouncementServiceImpl(AnnouncementMapper announcementMapper) { 29 | this.announcementMapper = announcementMapper; 30 | } 31 | 32 | @Override 33 | public List getAll() { 34 | return announcementMapper.selectAll(); 35 | } 36 | 37 | @Override 38 | public void del(String id) { 39 | if (StringUtils.isBlank(id)) { 40 | throw new NullFiledException("公告ID为空"); 41 | } 42 | if (announcementMapper.countByPrimaryKey(id) == 0L) { 43 | throw new IdNotFoundException("公告ID不存在"); 44 | } 45 | announcementMapper.deleteByPrimaryKey(id); 46 | } 47 | 48 | @Override 49 | public Announcement update(String id, String content) { 50 | if (StringUtils.isBlank(content)) { 51 | throw new NullFiledException("公告为空"); 52 | } 53 | if (announcementMapper.countByPrimaryKey(id) == 0L) { 54 | throw new IdNotFoundException("公告ID不存在"); 55 | } 56 | Announcement announcement = new Announcement(); 57 | announcement.setId(id); 58 | announcement.setGmtModified(new Date()); 59 | announcement.setContent(content); 60 | announcementMapper.updateByPrimaryKeySelective(announcement); 61 | return announcement; 62 | } 63 | 64 | @Override 65 | public Announcement newAnnouncement(String content) { 66 | if (StringUtils.isBlank(content)) { 67 | throw new NullFiledException("公告为空"); 68 | } 69 | Date date = new Date(); 70 | Announcement announcement = new Announcement(); 71 | announcement.setId(UUID.randomUUID().toString()); 72 | announcement.setContent(content); 73 | announcement.setGmtCreate(date); 74 | announcement.setGmtModified(date); 75 | announcementMapper.insert(announcement); 76 | return announcement; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/TeacherController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.entity.Teacher; 6 | import com.project.selflearningplatformserver.log.Log; 7 | import com.project.selflearningplatformserver.security.MustTeacherLogin; 8 | import com.project.selflearningplatformserver.service.TeacherService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | /** 14 | * 新增/修改教师信息 15 | * 16 | * @author itning 17 | * @date 2020/5/6 5:53 18 | */ 19 | @RestController 20 | public class TeacherController { 21 | private final TeacherService teacherService; 22 | 23 | @Autowired 24 | public TeacherController(TeacherService teacherService) { 25 | this.teacherService = teacherService; 26 | } 27 | 28 | /** 29 | * 获取教师所有信息 30 | * 31 | * @param loginUser 登录用户 32 | * @return ResponseEntity 33 | */ 34 | @GetMapping("/teacher_infos") 35 | public ResponseEntity getAllTeacherInfo(@MustTeacherLogin LoginUser loginUser) { 36 | return RestModel.ok(teacherService.getAllTeacherInfo(loginUser)); 37 | } 38 | 39 | /** 40 | * 教师删除信息 41 | * 42 | * @param loginUser 登录用户 43 | * @param id 信息ID 44 | * @return ResponseEntity 45 | */ 46 | @Log("教师删除信息") 47 | @DeleteMapping("/teacher_info/{id}") 48 | public ResponseEntity delTeacherInfo(@MustTeacherLogin LoginUser loginUser, 49 | @PathVariable String id) { 50 | teacherService.delTeacherInfo(loginUser, id); 51 | return RestModel.noContent(); 52 | } 53 | 54 | /** 55 | * 教师新增信息 56 | * 57 | * @param loginUser 登录用户 58 | * @param attributeKey 属性KEY 59 | * @param attributeValue 属性值 60 | * @return ResponseEntity 61 | */ 62 | @Log("教师新增信息") 63 | @PostMapping("/teacher_info") 64 | public ResponseEntity newTeacherInfo(@MustTeacherLogin LoginUser loginUser, 65 | @RequestParam String attributeKey, 66 | @RequestParam String attributeValue) { 67 | return RestModel.created(teacherService.newTeacherInfo(loginUser, attributeKey, attributeValue)); 68 | } 69 | 70 | /** 71 | * 教师修改信息 72 | * 73 | * @param loginUser 登录用户 74 | * @param teacher 修改的教师信息 75 | * @return ResponseEntity 76 | */ 77 | @Log("教师修改信息") 78 | @PatchMapping("/teacher_info") 79 | public ResponseEntity updateTeacherInfo(@MustTeacherLogin LoginUser loginUser, 80 | @RequestBody Teacher teacher) { 81 | teacherService.updateTeacherInfo(loginUser, teacher); 82 | return RestModel.noContent(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/StudentLearningController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.log.Log; 6 | import com.project.selflearningplatformserver.security.MustStudentLogin; 7 | import com.project.selflearningplatformserver.security.MustTeacherLogin; 8 | import com.project.selflearningplatformserver.service.StudentLearningService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | /** 14 | * 学生学习 15 | * 16 | * @author itning 17 | * @date 2020/5/2 11:22 18 | */ 19 | @RestController 20 | public class StudentLearningController { 21 | private final StudentLearningService studentLearningService; 22 | 23 | @Autowired 24 | public StudentLearningController(StudentLearningService studentLearningService) { 25 | this.studentLearningService = studentLearningService; 26 | } 27 | 28 | /** 29 | * 学生选择学习内容 30 | * 31 | * @param loginUser 登录用户 32 | * @param learningContentId 学习内容ID 33 | * @return ResponseEntity 34 | */ 35 | @Log("学生选择学习内容") 36 | @PostMapping("/student_learning") 37 | public ResponseEntity switchLearningContent(@MustStudentLogin LoginUser loginUser, 38 | @RequestParam String learningContentId) { 39 | return RestModel.created(studentLearningService.switchLearningContent(loginUser, learningContentId)); 40 | } 41 | 42 | /** 43 | * 学生获取学习内容带学生学习ID 44 | * 45 | * @param loginUser 登录用户 46 | * @return ResponseEntity 47 | */ 48 | @GetMapping("/student_learning") 49 | public ResponseEntity getMyStudy(@MustStudentLogin LoginUser loginUser) { 50 | return RestModel.ok(studentLearningService.getMyLearning(loginUser)); 51 | } 52 | 53 | /** 54 | * 教师获取所有学生信息(带作业) 55 | * 56 | * @param loginUser 登录用户 57 | * @param learningContentId 学习内容ID 58 | * @return ResponseEntity 59 | */ 60 | @GetMapping("/student_learning_teacher") 61 | public ResponseEntity getAllStudentInLearning(@MustTeacherLogin LoginUser loginUser, 62 | @RequestParam String learningContentId) { 63 | return RestModel.ok(studentLearningService.getAllStudentInLearning(loginUser, learningContentId)); 64 | } 65 | 66 | /** 67 | * 学生取消学习 68 | * 69 | * @param loginUser 登录用户 70 | * @param id 学生学习ID 71 | * @return ResponseEntity 72 | */ 73 | @Log("学生取消学习内容") 74 | @DeleteMapping("/student_learning/{id}") 75 | public ResponseEntity delMyStudy(@MustStudentLogin LoginUser loginUser, 76 | @PathVariable String id) { 77 | studentLearningService.delMyLearning(loginUser, id); 78 | return RestModel.noContent(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/impl/SubjectServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service.impl; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.entity.Subject; 5 | import com.project.selflearningplatformserver.exception.IdNotFoundException; 6 | import com.project.selflearningplatformserver.exception.NullFiledException; 7 | import com.project.selflearningplatformserver.mapper.SubjectMapper; 8 | import com.project.selflearningplatformserver.service.SubjectService; 9 | import org.apache.commons.lang3.StringUtils; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | import java.util.Date; 15 | import java.util.List; 16 | import java.util.UUID; 17 | 18 | /** 19 | * @author itning 20 | * @date 2020/5/1 19:38 21 | */ 22 | @Transactional(rollbackFor = Exception.class) 23 | @Service 24 | public class SubjectServiceImpl implements SubjectService { 25 | private final SubjectMapper subjectMapper; 26 | 27 | @Autowired 28 | public SubjectServiceImpl(SubjectMapper subjectMapper) { 29 | this.subjectMapper = subjectMapper; 30 | } 31 | 32 | @Override 33 | public List getAllSubject(LoginUser loginUser) { 34 | return subjectMapper.selectByUserId(loginUser.getId()); 35 | } 36 | 37 | @Override 38 | public void delSubject(LoginUser loginUser, String subjectId) { 39 | if (StringUtils.isBlank(subjectId)) { 40 | throw new NullFiledException("科目ID为空"); 41 | } 42 | if (subjectMapper.countByPrimaryKey(subjectId) == 0L) { 43 | throw new IdNotFoundException("科目ID不存在"); 44 | } 45 | subjectMapper.deleteByPrimaryKey(subjectId); 46 | } 47 | 48 | @Override 49 | public Subject newSubject(LoginUser loginUser, String name) { 50 | if (StringUtils.isBlank(name)) { 51 | throw new NullFiledException("科目名为空"); 52 | } 53 | Date date = new Date(); 54 | Subject subject = new Subject(); 55 | subject.setId(UUID.randomUUID().toString()); 56 | subject.setUserId(loginUser.getId()); 57 | subject.setName(name); 58 | subject.setGmtCreate(date); 59 | subject.setGmtModified(date); 60 | subjectMapper.insert(subject); 61 | return subject; 62 | } 63 | 64 | @Override 65 | public Subject updateSubject(LoginUser loginUser, Subject subject) { 66 | if (StringUtils.isBlank(subject.getId())) { 67 | throw new NullFiledException("科目ID为空"); 68 | } 69 | if (subjectMapper.countByPrimaryKey(subject.getId()) == 0L) { 70 | throw new IdNotFoundException("科目ID不存在"); 71 | } 72 | if (StringUtils.isBlank(subject.getName())) { 73 | throw new NullFiledException("科目名为空"); 74 | } 75 | subject.setGmtCreate(null); 76 | subject.setGmtModified(new Date()); 77 | subject.setUserId(null); 78 | subjectMapper.updateByPrimaryKeySelective(subject); 79 | return subject; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.entity.User; 6 | import com.project.selflearningplatformserver.log.Log; 7 | import com.project.selflearningplatformserver.security.MustAdminLogin; 8 | import com.project.selflearningplatformserver.security.MustLogin; 9 | import com.project.selflearningplatformserver.service.UserService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | /** 15 | * @author itning 16 | * @date 2020/5/1 14:27 17 | */ 18 | @RestController 19 | public class UserController { 20 | private final UserService userService; 21 | 22 | @Autowired 23 | public UserController(UserService userService) { 24 | this.userService = userService; 25 | } 26 | 27 | /** 28 | * 管理员获取所有教师信息 29 | * 30 | * @param loginUser 登录用户 31 | * @return ResponseEntity 32 | */ 33 | @GetMapping("/teachers") 34 | public ResponseEntity getAllTeachers(@MustAdminLogin LoginUser loginUser) { 35 | return RestModel.ok(userService.getAllTeacherUser()); 36 | } 37 | 38 | 39 | /** 40 | * 管理员获取所有学生信息 41 | * 42 | * @param loginUser 登录用户 43 | * @return ResponseEntity 44 | */ 45 | @GetMapping("/students") 46 | public ResponseEntity getAllStudents(@MustAdminLogin LoginUser loginUser) { 47 | return RestModel.ok(userService.getAllStudentUser()); 48 | } 49 | 50 | /** 51 | * 管理员新增教师 52 | * 53 | * @param loginUser 登录用户 54 | * @param name 新增的教师名 55 | * @param username 新增的教师用户名 56 | * @return ResponseEntity 57 | */ 58 | @Log("新增教师") 59 | @PostMapping("/teacher") 60 | public ResponseEntity newTeacher(@MustAdminLogin LoginUser loginUser, 61 | @RequestParam String name, 62 | @RequestParam String username) { 63 | return RestModel.created(userService.newTeacher(name, username)); 64 | } 65 | 66 | /** 67 | *

用户修改信息(修改姓名,密码) 68 | *

管理员冻结账户,修改用户信息 69 | * 70 | * @param loginUser 登录用户 71 | * @param user 修改载体 72 | * @return ResponseEntity 73 | */ 74 | @Log("更新用户信息") 75 | @PatchMapping("/user") 76 | public ResponseEntity updateUserInfo(@MustLogin LoginUser loginUser, 77 | @RequestBody User user) { 78 | userService.updateUserInfo(loginUser, user); 79 | return RestModel.noContent(); 80 | } 81 | 82 | /** 83 | *

管理员删除账户 84 | *

无法删除自己,即管理员无法删除管理员 85 | * 86 | * @param loginUser 登录用户 87 | * @param userId 要删除的用户ID 88 | * @return ResponseEntity 89 | */ 90 | @Log("删除用户信息") 91 | @DeleteMapping("/user/{userId}") 92 | public ResponseEntity delUserInfo(@MustAdminLogin LoginUser loginUser, 93 | @PathVariable String userId) { 94 | userService.delUserInfo(userId); 95 | return RestModel.noContent(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/resources/mappers/RoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | id, name, gmt_create, gmt_modified 14 | 15 | 21 | 22 | delete from role 23 | where id = #{id,jdbcType=CHAR} 24 | 25 | 26 | insert into role (id, name, gmt_create, 27 | gmt_modified) 28 | values (#{id,jdbcType=CHAR}, #{name,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, 29 | #{gmtModified,jdbcType=TIMESTAMP}) 30 | 31 | 32 | insert into role 33 | 34 | 35 | id, 36 | 37 | 38 | name, 39 | 40 | 41 | gmt_create, 42 | 43 | 44 | gmt_modified, 45 | 46 | 47 | 48 | 49 | #{id,jdbcType=CHAR}, 50 | 51 | 52 | #{name,jdbcType=VARCHAR}, 53 | 54 | 55 | #{gmtCreate,jdbcType=TIMESTAMP}, 56 | 57 | 58 | #{gmtModified,jdbcType=TIMESTAMP}, 59 | 60 | 61 | 62 | 63 | update role 64 | 65 | 66 | name = #{name,jdbcType=VARCHAR}, 67 | 68 | 69 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 70 | 71 | 72 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, 73 | 74 | 75 | where id = #{id,jdbcType=CHAR} 76 | 77 | 78 | update role 79 | set name = #{name,jdbcType=VARCHAR}, 80 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 81 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} 82 | where id = #{id,jdbcType=CHAR} 83 | 84 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/impl/ExaminationServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service.impl; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.entity.Examination; 5 | import com.project.selflearningplatformserver.exception.IdNotFoundException; 6 | import com.project.selflearningplatformserver.exception.NullFiledException; 7 | import com.project.selflearningplatformserver.exception.SecurityServerException; 8 | import com.project.selflearningplatformserver.mapper.ExaminationMapper; 9 | import com.project.selflearningplatformserver.service.ExaminationService; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.http.HttpStatus; 13 | import org.springframework.stereotype.Service; 14 | import org.springframework.transaction.annotation.Transactional; 15 | 16 | import java.util.Date; 17 | import java.util.List; 18 | import java.util.Objects; 19 | import java.util.UUID; 20 | 21 | /** 22 | * @author itning 23 | * @date 2020/5/1 21:13 24 | */ 25 | @Transactional(rollbackFor = Exception.class) 26 | @Service 27 | public class ExaminationServiceImpl implements ExaminationService { 28 | private final ExaminationMapper examinationMapper; 29 | 30 | @Autowired 31 | public ExaminationServiceImpl(ExaminationMapper examinationMapper) { 32 | this.examinationMapper = examinationMapper; 33 | } 34 | 35 | @Override 36 | public List getAllExamination(LoginUser loginUser) { 37 | return examinationMapper.selectAllByUserId(loginUser.getId()); 38 | } 39 | 40 | @Override 41 | public void delExamination(LoginUser loginUser, String id) { 42 | Examination examination = examinationMapper.selectByPrimaryKey(id); 43 | if (Objects.isNull(examination)) { 44 | throw new IdNotFoundException("考试信息ID不存在"); 45 | } 46 | if (!examination.getUserId().equals(loginUser.getId())) { 47 | throw new SecurityServerException("删除失败", HttpStatus.FORBIDDEN); 48 | } 49 | examinationMapper.deleteByPrimaryKey(id); 50 | } 51 | 52 | @Override 53 | public Examination newExamination(LoginUser loginUser, String name) { 54 | if (StringUtils.isBlank(name)) { 55 | throw new NullFiledException("考试信息名为空"); 56 | } 57 | Date date = new Date(); 58 | Examination examination = new Examination(); 59 | examination.setId(UUID.randomUUID().toString()); 60 | examination.setUserId(loginUser.getId()); 61 | examination.setName(name); 62 | examination.setGmtCreate(date); 63 | examination.setGmtModified(date); 64 | examinationMapper.insert(examination); 65 | return examination; 66 | } 67 | 68 | @Override 69 | public Examination updateExamination(LoginUser loginUser, Examination examination) { 70 | if (StringUtils.isAnyBlank(examination.getId(), examination.getName())) { 71 | throw new NullFiledException("考试信息为空"); 72 | } 73 | Examination saved = examinationMapper.selectByPrimaryKey(examination.getId()); 74 | if (!saved.getUserId().equals(loginUser.getId())) { 75 | throw new SecurityServerException("更新失败", HttpStatus.FORBIDDEN); 76 | } 77 | examination.setGmtCreate(null); 78 | examination.setGmtModified(new Date()); 79 | examination.setUserId(null); 80 | examinationMapper.updateByPrimaryKeySelective(examination); 81 | return examination; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/resources/mappers/StudentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | user_id, student_class_id, gmt_create, gmt_modified 14 | 15 | 21 | 22 | delete from student 23 | where user_id = #{userId,jdbcType=CHAR} 24 | 25 | 26 | insert into student (user_id, student_class_id, gmt_create, 27 | gmt_modified) 28 | values (#{userId,jdbcType=CHAR}, #{studentClassId,jdbcType=CHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, 29 | #{gmtModified,jdbcType=TIMESTAMP}) 30 | 31 | 32 | insert into student 33 | 34 | 35 | user_id, 36 | 37 | 38 | student_class_id, 39 | 40 | 41 | gmt_create, 42 | 43 | 44 | gmt_modified, 45 | 46 | 47 | 48 | 49 | #{userId,jdbcType=CHAR}, 50 | 51 | 52 | #{studentClassId,jdbcType=CHAR}, 53 | 54 | 55 | #{gmtCreate,jdbcType=TIMESTAMP}, 56 | 57 | 58 | #{gmtModified,jdbcType=TIMESTAMP}, 59 | 60 | 61 | 62 | 63 | update student 64 | 65 | 66 | student_class_id = #{studentClassId,jdbcType=CHAR}, 67 | 68 | 69 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 70 | 71 | 72 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, 73 | 74 | 75 | where user_id = #{userId,jdbcType=CHAR} 76 | 77 | 78 | update student 79 | set student_class_id = #{studentClassId,jdbcType=CHAR}, 80 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 81 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} 82 | where user_id = #{userId,jdbcType=CHAR} 83 | 84 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/impl/TeacherServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service.impl; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.entity.Teacher; 5 | import com.project.selflearningplatformserver.exception.IdNotFoundException; 6 | import com.project.selflearningplatformserver.exception.NullFiledException; 7 | import com.project.selflearningplatformserver.exception.SecurityServerException; 8 | import com.project.selflearningplatformserver.mapper.TeacherMapper; 9 | import com.project.selflearningplatformserver.service.TeacherService; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.http.HttpStatus; 13 | import org.springframework.stereotype.Service; 14 | import org.springframework.transaction.annotation.Transactional; 15 | 16 | import java.util.Date; 17 | import java.util.List; 18 | import java.util.UUID; 19 | 20 | /** 21 | * @author itning 22 | * @date 2020/5/6 6:04 23 | */ 24 | @Transactional(rollbackFor = Exception.class) 25 | @Service 26 | public class TeacherServiceImpl implements TeacherService { 27 | private final TeacherMapper teacherMapper; 28 | 29 | @Autowired 30 | public TeacherServiceImpl(TeacherMapper teacherMapper) { 31 | this.teacherMapper = teacherMapper; 32 | } 33 | 34 | @Override 35 | public List getAllTeacherInfo(LoginUser loginUser) { 36 | return teacherMapper.selectAllByUserId(loginUser.getId()); 37 | } 38 | 39 | @Override 40 | public void delTeacherInfo(LoginUser loginUser, String id) { 41 | if (StringUtils.isBlank(id)) { 42 | throw new NullFiledException("教师信息ID为空"); 43 | } 44 | if (teacherMapper.countByPrimaryKey(id) == 0L) { 45 | throw new IdNotFoundException("教师信息未找到"); 46 | } 47 | teacherMapper.deleteByPrimaryKey(id); 48 | } 49 | 50 | @Override 51 | public Teacher newTeacherInfo(LoginUser loginUser, String attributeKey, String attributeValue) { 52 | if (StringUtils.isAnyBlank(attributeKey, attributeValue)) { 53 | throw new NullFiledException("参数为空"); 54 | } 55 | if (teacherMapper.countByAttributeKeyAndUserId(attributeKey, loginUser.getId()) > 0L) { 56 | throw new SecurityServerException("该属性已存在", HttpStatus.BAD_REQUEST); 57 | } 58 | Date date = new Date(); 59 | Teacher teacher = new Teacher(); 60 | teacher.setId(UUID.randomUUID().toString()); 61 | teacher.setUserId(loginUser.getId()); 62 | teacher.setAttributeKey(attributeKey); 63 | teacher.setAttributeValue(attributeValue); 64 | teacher.setGmtCreate(date); 65 | teacher.setGmtModified(date); 66 | teacherMapper.insert(teacher); 67 | return teacher; 68 | } 69 | 70 | @Override 71 | public Teacher updateTeacherInfo(LoginUser loginUser, Teacher teacher) { 72 | if (StringUtils.isAnyBlank(teacher.getId(), teacher.getAttributeKey(), teacher.getAttributeValue())) { 73 | throw new NullFiledException("参数为空"); 74 | } 75 | if (teacherMapper.countByAttributeKeyAndUserId(teacher.getAttributeKey(), loginUser.getId()) == 0L) { 76 | throw new IdNotFoundException("该属性未找到"); 77 | } 78 | if (teacherMapper.countByPrimaryKey(teacher.getId()) == 0L) { 79 | throw new IdNotFoundException("教师属性未找到"); 80 | } 81 | teacher.setGmtCreate(null); 82 | teacher.setGmtModified(new Date()); 83 | teacher.setUserId(null); 84 | teacherMapper.updateByPrimaryKeySelective(teacher); 85 | return teacher; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/ExaminationScoreController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.entity.ExaminationScore; 6 | import com.project.selflearningplatformserver.log.Log; 7 | import com.project.selflearningplatformserver.security.MustStudentLogin; 8 | import com.project.selflearningplatformserver.security.MustTeacherLogin; 9 | import com.project.selflearningplatformserver.service.ExaminationScoreService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | /** 15 | * @author itning 16 | * @date 2020/5/1 22:24 17 | */ 18 | @RestController 19 | public class ExaminationScoreController { 20 | private final ExaminationScoreService examinationScoreService; 21 | 22 | @Autowired 23 | public ExaminationScoreController(ExaminationScoreService examinationScoreService) { 24 | this.examinationScoreService = examinationScoreService; 25 | } 26 | 27 | 28 | /** 29 | * 教师分页获取所有考试分数 30 | * 31 | * @param loginUser 登录用户 32 | * @param examinationId 考试信息ID 33 | * @return ResponseEntity 34 | */ 35 | @GetMapping("/examination_scores") 36 | public ResponseEntity allExaminationScoreInfo(@MustTeacherLogin LoginUser loginUser, 37 | @RequestParam String examinationId) { 38 | return RestModel.ok(examinationScoreService.getAllByExaminationId(loginUser, examinationId)); 39 | } 40 | 41 | /** 42 | * 教师删除考试分数 43 | * 44 | * @param loginUser 登录用户 45 | * @param id 要删除的考试分数ID 46 | * @return ResponseEntity 47 | */ 48 | @Log("删除考试分数") 49 | @DeleteMapping("/examination_score/{id}") 50 | public ResponseEntity delExamination(@MustTeacherLogin LoginUser loginUser, 51 | @PathVariable String id) { 52 | examinationScoreService.del(loginUser, id); 53 | return RestModel.noContent(); 54 | } 55 | 56 | /** 57 | * 教师新增考试分数 58 | * 59 | * @param loginUser 登录用户 60 | * @param examinationScore 考试分数 61 | * @return ResponseEntity 62 | */ 63 | @Log("新增考试分数") 64 | @PostMapping("/examination_score") 65 | public ResponseEntity newExaminationScore(@MustTeacherLogin LoginUser loginUser, 66 | ExaminationScore examinationScore) { 67 | return RestModel.created(examinationScoreService.newExaminationScore(loginUser, examinationScore)); 68 | } 69 | 70 | /** 71 | * 教师修改考试分数 72 | * 73 | * @param loginUser 登录用户 74 | * @param examinationScore 修改的考试分数 75 | * @return ResponseEntity 76 | */ 77 | @Log("修改考试分数") 78 | @PatchMapping("/examination_score") 79 | public ResponseEntity updateExaminationScore(@MustTeacherLogin LoginUser loginUser, 80 | @RequestBody ExaminationScore examinationScore) { 81 | examinationScoreService.updateExaminationScore(loginUser, examinationScore); 82 | return RestModel.noContent(); 83 | } 84 | 85 | /** 86 | * 学生获取自己的考试信息 87 | * 88 | * @param loginUser 登录用户 89 | * @return ResponseEntity 90 | */ 91 | @GetMapping("/examination_score_student") 92 | public ResponseEntity getStudentOwnExaminationScore(@MustStudentLogin LoginUser loginUser) { 93 | return RestModel.ok(examinationScoreService.getStudentOwnExaminationScore(loginUser)); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/exception/ExceptionResolver.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.exception; 2 | 3 | import com.project.selflearningplatformserver.dto.RestModel; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.web.bind.MissingServletRequestParameterException; 8 | import org.springframework.web.bind.annotation.ControllerAdvice; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | import org.springframework.web.servlet.NoHandlerFoundException; 12 | 13 | import javax.servlet.http.HttpServletResponse; 14 | 15 | /** 16 | * 异常处理 17 | * 18 | * @author itning 19 | */ 20 | @ControllerAdvice 21 | public class ExceptionResolver { 22 | private static final Logger logger = LoggerFactory.getLogger(ExceptionResolver.class); 23 | 24 | /** 25 | * json 格式错误消息 26 | * 27 | * @param response HttpServletResponse 28 | * @param e Exception 29 | * @return 异常消息 30 | */ 31 | @ExceptionHandler(value = Exception.class) 32 | @ResponseBody 33 | public RestModel jsonErrorHandler(HttpServletResponse response, Exception e) { 34 | logger.error("jsonErrorHandler->{}:{} {}", e.getClass().getSimpleName(), e.getMessage(), e); 35 | RestModel restModel = new RestModel<>(); 36 | restModel.setCode(HttpStatus.SERVICE_UNAVAILABLE.value()); 37 | restModel.setMsg(e.getMessage()); 38 | response.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); 39 | return restModel; 40 | } 41 | 42 | /** 43 | * BaseException 错误 44 | * 45 | * @param response HttpServletResponse 46 | * @param e BaseException 47 | * @return 异常消息 48 | */ 49 | @ExceptionHandler(value = BaseException.class) 50 | @ResponseBody 51 | public RestModel baseErrorHandler(HttpServletResponse response, BaseException e) { 52 | logger.info("baseErrorHandler->{}:{}", e.getClass().getSimpleName(), e.getMessage()); 53 | RestModel restModel = new RestModel<>(); 54 | restModel.setCode(e.getCode().value()); 55 | restModel.setMsg(e.getMessage()); 56 | response.setStatus(e.getCode().value()); 57 | return restModel; 58 | } 59 | 60 | /** 61 | * MissingServletRequestParameterException 错误 62 | * 63 | * @param response HttpServletResponse 64 | * @param e MissingServletRequestParameterException 65 | * @return 异常消息 66 | */ 67 | @ExceptionHandler(value = MissingServletRequestParameterException.class) 68 | @ResponseBody 69 | public RestModel missingServletRequestParameterExceptionHandler(HttpServletResponse response, MissingServletRequestParameterException e) { 70 | logger.info("missingServletRequestParameterExceptionHandler->{}", e.getMessage()); 71 | RestModel restModel = new RestModel<>(); 72 | restModel.setCode(HttpServletResponse.SC_BAD_REQUEST); 73 | restModel.setMsg(e.getMessage()); 74 | response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 75 | return restModel; 76 | } 77 | 78 | /** 79 | * BaseException 错误 80 | * 81 | * @param response HttpServletResponse 82 | * @param e BaseException 83 | * @return 异常消息 84 | */ 85 | @ExceptionHandler(value = NoHandlerFoundException.class) 86 | @ResponseBody 87 | public RestModel noHandlerFoundErrorHandler(HttpServletResponse response, NoHandlerFoundException e) { 88 | logger.info("noHandlerFoundErrorHandler->{}:{}", e.getClass().getSimpleName(), e.getMessage()); 89 | RestModel restModel = new RestModel<>(); 90 | restModel.setCode(HttpStatus.NOT_FOUND.value()); 91 | restModel.setMsg(e.getMessage()); 92 | response.setStatus(HttpStatus.NOT_FOUND.value()); 93 | return restModel; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/AttendanceController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.log.Log; 6 | import com.project.selflearningplatformserver.security.MustAdminLogin; 7 | import com.project.selflearningplatformserver.security.MustLogin; 8 | import com.project.selflearningplatformserver.service.AttendanceService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.format.annotation.DateTimeFormat; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import java.time.LocalDateTime; 15 | 16 | /** 17 | * 教师/学生出勤 18 | * 19 | * @author itning 20 | * @date 2020/5/1 22:30 21 | */ 22 | @RestController 23 | public class AttendanceController { 24 | private final AttendanceService attendanceService; 25 | 26 | @Autowired 27 | public AttendanceController(AttendanceService attendanceService) { 28 | this.attendanceService = attendanceService; 29 | } 30 | 31 | /** 32 | * 管理员获取所有出勤信息 33 | * 34 | * @param loginUser 登录用户 35 | * @param roleId 要获取的角色ID 36 | * @return ResponseEntity 37 | */ 38 | @GetMapping("/attendances") 39 | public ResponseEntity getAllAttendance(@MustAdminLogin LoginUser loginUser, 40 | @RequestParam String roleId) { 41 | return RestModel.ok(attendanceService.getAllAttendances(roleId)); 42 | } 43 | 44 | /** 45 | * 管理员删除出勤信息 46 | * 47 | * @param loginUser 登录用户 48 | * @param id 出勤信息ID 49 | * @return ResponseEntity 50 | */ 51 | @Log("删除出勤") 52 | @DeleteMapping("/attendance/{id}") 53 | public ResponseEntity delAttendance(@MustAdminLogin LoginUser loginUser, 54 | @PathVariable String id) { 55 | attendanceService.delAttendance(id); 56 | return RestModel.noContent(); 57 | } 58 | 59 | /** 60 | * 管理员新增出勤信息 61 | * 62 | * @param loginUser 登录用户 63 | * @param userId 新增出勤的用户ID 64 | * @param date 出勤时间 65 | * @return ResponseEntity 66 | */ 67 | @Log("管理员新增出勤") 68 | @PostMapping("/attendance_admin") 69 | public ResponseEntity newAttendance(@MustAdminLogin LoginUser loginUser, 70 | @RequestParam String userId, 71 | @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime date) { 72 | return RestModel.created(attendanceService.newAttendance(userId, date)); 73 | } 74 | 75 | /** 76 | * 学生/教师新增出勤 77 | * 78 | * @param loginUser 登录用户 79 | * @return ResponseEntity 80 | */ 81 | @Log("新增出勤") 82 | @PostMapping("/attendance") 83 | public ResponseEntity newAttendance(@MustLogin(role = {MustLogin.ROLE.STUDENT, MustLogin.ROLE.TEACHER}) LoginUser loginUser) { 84 | return RestModel.created(attendanceService.newAttendance(loginUser)); 85 | } 86 | 87 | /** 88 | * 管理员修改出勤 89 | * 90 | * @param loginUser 登录用户 91 | * @param id 出勤ID 92 | * @param date 出勤日期 93 | * @return ResponseEntity 94 | */ 95 | @Log("修改出勤") 96 | @PostMapping("/attendance_change") 97 | public ResponseEntity updateAttendance(@MustAdminLogin LoginUser loginUser, 98 | @RequestParam String id, 99 | @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime date) { 100 | attendanceService.updateAttendance(id, date); 101 | return RestModel.noContent(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/security/SecurityHandlerMethodArgumentResolver.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.security; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.exception.SecurityServerException; 5 | import com.project.selflearningplatformserver.exception.TokenException; 6 | import com.project.selflearningplatformserver.util.JwtUtils; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.core.MethodParameter; 10 | import org.springframework.http.HttpHeaders; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.lang.NonNull; 13 | import org.springframework.stereotype.Component; 14 | import org.springframework.web.bind.support.WebDataBinderFactory; 15 | import org.springframework.web.context.request.NativeWebRequest; 16 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 17 | import org.springframework.web.method.support.ModelAndViewContainer; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | import java.util.Arrays; 21 | 22 | /** 23 | * @author itning 24 | */ 25 | @Component 26 | public class SecurityHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { 27 | private static final Logger logger = LoggerFactory.getLogger(SecurityHandlerMethodArgumentResolver.class); 28 | 29 | @Override 30 | public boolean supportsParameter(@NonNull MethodParameter parameter) { 31 | return parameter.hasParameterAnnotation(MustLogin.class) || 32 | parameter.hasParameterAnnotation(MustAdminLogin.class) || 33 | parameter.hasParameterAnnotation(MustTeacherLogin.class) || 34 | parameter.hasParameterAnnotation(MustStudentLogin.class); 35 | } 36 | 37 | @Override 38 | public Object resolveArgument(@NonNull MethodParameter parameter, ModelAndViewContainer mavContainer, @NonNull NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { 39 | HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); 40 | assert request != null; 41 | String authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION); 42 | if (null == authorizationHeader) { 43 | throw new TokenException("凭据错误", HttpStatus.BAD_REQUEST); 44 | } 45 | LoginUser loginUser = JwtUtils.getLoginUser(authorizationHeader); 46 | checkLoginPermission(parameter, loginUser.getRoleId()); 47 | return loginUser; 48 | } 49 | 50 | private void checkLoginPermission(@NonNull MethodParameter parameter, String roleId) { 51 | if (parameter.hasParameterAnnotation(MustStudentLogin.class) && 52 | !LoginUser.ROLE_STUDENT_ID.equals(roleId)) { 53 | logger.debug("MustStudentLogin role id {}", roleId); 54 | throw new SecurityServerException("权限不足", HttpStatus.FORBIDDEN); 55 | } 56 | if (parameter.hasParameterAnnotation(MustTeacherLogin.class) && 57 | !LoginUser.ROLE_TEACHER_ID.equals(roleId)) { 58 | logger.debug("MustTeacherLogin role id {}", roleId); 59 | throw new SecurityServerException("权限不足", HttpStatus.FORBIDDEN); 60 | } 61 | if (parameter.hasParameterAnnotation(MustAdminLogin.class) && 62 | !LoginUser.ROLE_ADMIN_ID.equals(roleId)) { 63 | logger.debug("MustAdminLogin role id {}", roleId); 64 | throw new SecurityServerException("权限不足", HttpStatus.FORBIDDEN); 65 | } 66 | if (parameter.hasParameterAnnotation(MustLogin.class)) { 67 | MustLogin mustLogin = parameter.getParameterAnnotation(MustLogin.class); 68 | if (mustLogin != null) { 69 | if (Arrays.stream(mustLogin.role()).noneMatch(role -> role.getId().equals(roleId))) { 70 | logger.debug("MustLogin role id {} and set role array {}", roleId, Arrays.toString(mustLogin.role())); 71 | throw new SecurityServerException("权限不足", HttpStatus.FORBIDDEN); 72 | } 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 自学平台系统 2 | 3 | [![GitHub stars](https://img.shields.io/github/stars/itning/self-learning-platform-server.svg?style=social&label=Stars)](https://github.com/itning/self-learning-platform-server/stargazers) 4 | [![GitHub forks](https://img.shields.io/github/forks/itning/self-learning-platform-server.svg?style=social&label=Fork)](https://github.com/itning/self-learning-platform-server/network/members) 5 | [![GitHub watchers](https://img.shields.io/github/watchers/itning/self-learning-platform-server.svg?style=social&label=Watch)](https://github.com/itning/self-learning-platform-server/watchers) 6 | [![GitHub followers](https://img.shields.io/github/followers/itning.svg?style=social&label=Follow)](https://github.com/itning?tab=followers) 7 | 8 | [![GitHub issues](https://img.shields.io/github/issues/itning/self-learning-platform-server.svg)](https://github.com/itning/self-learning-platform-server/issues) 9 | [![GitHub license](https://img.shields.io/github/license/itning/self-learning-platform-server.svg)](https://github.com/itning/self-learning-platform-server/blob/master/LICENSE) 10 | [![GitHub last commit](https://img.shields.io/github/last-commit/itning/self-learning-platform-server.svg)](https://github.com/itning/self-learning-platform-server/commits) 11 | [![GitHub release](https://img.shields.io/github/release/itning/self-learning-platform-server.svg)](https://github.com/itning/self-learning-platform-server/releases) 12 | [![GitHub repo size in bytes](https://img.shields.io/github/repo-size/itning/self-learning-platform-server.svg)](https://github.com/itning/self-learning-platform-server) 13 | [![HitCount](http://hits.dwyl.com/itning/self-learning-platform-server.svg)](http://hits.dwyl.com/itning/self-learning-platform-server) 14 | [![language](https://img.shields.io/badge/language-JAVA-green.svg)](https://github.com/itning/self-learning-platform-server) 15 | 16 | **前后端分离项目**,前端地址:[https://github.com/itning/self-learning-platform-client](https://github.com/itning/self-learning-platform-client) 17 | 18 | ## 功能大纲 19 | 20 | 1. 用户管理模块分为三个小模块: 21 | 22 | - [x] (1)用户注册:用户注册个人信息,填写信息资料并提交后,可以登陆该系统 23 | 24 | - [x] (2)用户信息修改:对系统中已经注册完毕的用户信息,进行修改操作 25 | 26 | - [x] (3)用户信息删除:对系统中已经注册完毕的用户信息,进行删除操作 27 | 28 | 29 | 2. 系统设置模块分为二个小模块: 30 | 31 | - [x] (1)权限设置:设定权限,不同权限具有不同操作功能 32 | 33 | - [x] (2)系统操作日志:人员登陆后,对系统进行了何种的功能操作生成日志。 34 | 3. 教师管理模块分为三个小模块: 35 | 36 | - [x] (1)科目分类:对科目分类操作,添加科目,删除科目,修改科目,查询科目。 37 | 38 | - [x] (2)教师信息:对教师信息操作,添加教师信息,修改教师信息,删除教师信息,查询教师信息。 39 | 40 | - [x] (3)班级管辖模块:老师在平台上对班级的管辖,添加班级,修改班级,删除班级,查询班级。 41 | 4. 学考模块分为四个小模块: 42 | 43 | - [x] (1)学习内容种类:学生选择需要学习的内容种类,添加学习内容,修改学习内容,删除学习内容,查询学习内容。 44 | 45 | - [x] (2)学生名单:考试的学生名单添加,修改学生名单,删除学生名单,查询学生名单。 46 | 47 | - [x] (3)考试成绩:老师对学生的成绩登记,添加学生成绩,修改学生成绩,删除学生成绩,查询学生成绩。 48 | 49 | - [x] (4)教师建议:教师对学生提出建议,添加建议,修改建议,删除建议,查询建议。 50 | 5. 出勤模块分为三个小模块: 51 | 52 | - [x] (1)教师出勤记录:添加教师出勤,修改教师出勤,删除教师出勤,查询教师出勤。 53 | 54 | - [x] (2)学生出勤记录:添加学生出勤,修改学生出勤,删除学生出勤,查询学生出勤。 55 | 56 | - [x] (3)考试成绩:老师对学生的成绩登记,添加学生成绩,修改学生成绩,删除学生成绩,查询学生成绩 57 | 6. 公告模块分为四个小模块: 58 | 59 | - [x] (1)添加公告信息:在系统中添加公告信息,学生和老师可以查看。 60 | 61 | - [x] (2)删除公告信息:对系统中存在的公告信息删除。 62 | 63 | - [x] (3)修改公告信息:对系统中存在的公告信息修改。 64 | 65 | - [x] (4)查询公告信息:对系统中存在的公告信息查询。 66 | 7. 安全管理分为三个小模块: 67 | 68 | - [x] (1)账号冻结:对不明身份的账号进行冻结。 69 | 70 | - [x] (2)账号解冻:对系统中冻结的账号解冻。 71 | 72 | - [x] (3)密码保护:为密码加入md5加密状态。 73 | --- 74 | - [x] 1.管理员或教师上传科目视频及ppt。 75 | - [x] 2.将管理员添加的科目与教师和学生关联。 76 | - [x] 3.学生登陆后可以观看视频,上传文件。 77 | - [x] 4.学生用户登录以后不要与管理员登陆功能相同 78 | - [x] 5.学生界面能打卡,管理端能查看打卡 79 | - [x] 6.老师能查看到学生上传的文档进行评分,再给建议 80 | --- 81 | - [x] 1.老师上传考试分数后,学生可查看自己的考试成绩。 82 | - [x] 2.管理员为教师注册账号后,教师可添加、修改自己的信息(如性别、年龄、学历、电话、邮箱) 83 | - [x] 3.学习内容管理增加上传文件(任意)学生可以下载 84 | 85 | ## 运行环境 86 | - JDK 11 87 | - MySQL 8 88 | - Vue.JS 89 | 90 | ## 截图 91 | 92 | ![a](https://raw.githubusercontent.com/itning/self-learning-platform-server/master/pic/a.png) 93 | 94 | ![b](https://raw.githubusercontent.com/itning/self-learning-platform-server/master/pic/b.png) 95 | 96 | ![c](https://raw.githubusercontent.com/itning/self-learning-platform-server/master/pic/c.png) 97 | 98 | ![d](https://raw.githubusercontent.com/itning/self-learning-platform-server/master/pic/d.png) 99 | 100 | ![e](https://raw.githubusercontent.com/itning/self-learning-platform-server/master/pic/e.png) 101 | -------------------------------------------------------------------------------- /src/main/resources/mappers/AnnouncementMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | id, content, gmt_create, gmt_modified 14 | 15 | 21 | 22 | delete 23 | from announcement 24 | where id = #{id,jdbcType=CHAR} 25 | 26 | 27 | insert into announcement (id, content, gmt_create, 28 | gmt_modified) 29 | values (#{id,jdbcType=CHAR}, #{content,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, 30 | #{gmtModified,jdbcType=TIMESTAMP}) 31 | 32 | 33 | insert into announcement 34 | 35 | 36 | id, 37 | 38 | 39 | content, 40 | 41 | 42 | gmt_create, 43 | 44 | 45 | gmt_modified, 46 | 47 | 48 | 49 | 50 | #{id,jdbcType=CHAR}, 51 | 52 | 53 | #{content,jdbcType=VARCHAR}, 54 | 55 | 56 | #{gmtCreate,jdbcType=TIMESTAMP}, 57 | 58 | 59 | #{gmtModified,jdbcType=TIMESTAMP}, 60 | 61 | 62 | 63 | 64 | update announcement 65 | 66 | 67 | content = #{content,jdbcType=VARCHAR}, 68 | 69 | 70 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 71 | 72 | 73 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, 74 | 75 | 76 | where id = #{id,jdbcType=CHAR} 77 | 78 | 79 | update announcement 80 | set content = #{content,jdbcType=VARCHAR}, 81 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 82 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} 83 | where id = #{id,jdbcType=CHAR} 84 | 85 | 90 | 95 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/video/VideoTransformHandler.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.video; 2 | 3 | import com.google.common.util.concurrent.ThreadFactoryBuilder; 4 | import com.project.selflearningplatformserver.config.AppProperties; 5 | import lombok.ToString; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.util.DigestUtils; 10 | 11 | import java.io.File; 12 | import java.util.concurrent.LinkedBlockingQueue; 13 | import java.util.concurrent.ThreadPoolExecutor; 14 | import java.util.concurrent.TimeUnit; 15 | 16 | /** 17 | * @author itning 18 | * @date 2020/5/3 12:07 19 | */ 20 | @Slf4j 21 | @Component 22 | public class VideoTransformHandler { 23 | private final Video2M3u8Helper video2M3u8Helper; 24 | private final LinkedBlockingQueue taskLinkedBlockingQueue; 25 | private final ThreadPoolExecutor transformExecutorService; 26 | private final ThreadPoolExecutor synchronousBlockingSingleService; 27 | private final File learningContentTranscodingDir; 28 | 29 | @Autowired 30 | public VideoTransformHandler(Video2M3u8Helper video2M3u8Helper, AppProperties appProperties) { 31 | this.video2M3u8Helper = video2M3u8Helper; 32 | 33 | this.taskLinkedBlockingQueue = new LinkedBlockingQueue<>(); 34 | 35 | int processors = Runtime.getRuntime().availableProcessors(); 36 | this.transformExecutorService = new ThreadPoolExecutor(processors, 37 | processors, 38 | 0L, 39 | TimeUnit.MILLISECONDS, 40 | new LinkedBlockingQueue<>(), 41 | new ThreadFactoryBuilder().setNameFormat("trans-pool-%d").build()); 42 | this.synchronousBlockingSingleService = new ThreadPoolExecutor(1, 43 | 1, 44 | 0L, 45 | TimeUnit.MILLISECONDS, 46 | new LinkedBlockingQueue<>(), 47 | new ThreadFactoryBuilder().setNameFormat("single-pool-%d").build()); 48 | this.learningContentTranscodingDir = new File(appProperties.getLearningContentTranscodingDir()); 49 | start(); 50 | } 51 | 52 | private void start() { 53 | synchronousBlockingSingleService.submit(() -> { 54 | //noinspection InfiniteLoopStatement 55 | while (true) { 56 | try { 57 | final Task take = taskLinkedBlockingQueue.take(); 58 | transformExecutorService.submit(() -> video2M3u8Helper.videoConvert(take.getSrc().getPath(), take.getToPath().getPath(), take.getFileName())); 59 | } catch (Exception e) { 60 | log.error("Submit Video Transform Failed {}", e.getMessage()); 61 | } 62 | } 63 | }); 64 | } 65 | 66 | public void addTask(File videoFile) throws Exception { 67 | Task task = new Task(videoFile, learningContentTranscodingDir); 68 | try { 69 | taskLinkedBlockingQueue.put(task); 70 | } catch (Exception e) { 71 | log.error("Put Task({}) TO Queue Failed {}", task, e.getMessage()); 72 | throw new Exception("转码任务添加失败"); 73 | } 74 | } 75 | 76 | public boolean isNowTranscoding(File videoFile) { 77 | return new File(learningContentTranscodingDir + File.separator + DigestUtils.md5DigestAsHex(videoFile.getPath().getBytes()) + ".mp4").exists(); 78 | } 79 | 80 | @ToString 81 | static class Task { 82 | private final File src; 83 | private final File toPath; 84 | private final String fileName; 85 | 86 | public Task(File src, File toPath) { 87 | this(src, toPath, src.getName().substring(0, src.getName().lastIndexOf("."))); 88 | } 89 | 90 | public Task(File src, File toPath, String fileName) { 91 | this.src = src; 92 | this.toPath = toPath; 93 | this.fileName = fileName; 94 | } 95 | 96 | public File getSrc() { 97 | return src; 98 | } 99 | 100 | public File getToPath() { 101 | return toPath; 102 | } 103 | 104 | public String getFileName() { 105 | return fileName; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/impl/SecurityServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service.impl; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.project.selflearningplatformserver.dto.LoginUser; 5 | import com.project.selflearningplatformserver.dto.UserDTO; 6 | import com.project.selflearningplatformserver.entity.Student; 7 | import com.project.selflearningplatformserver.entity.User; 8 | import com.project.selflearningplatformserver.exception.IdNotFoundException; 9 | import com.project.selflearningplatformserver.exception.IllegalFiledException; 10 | import com.project.selflearningplatformserver.exception.NullFiledException; 11 | import com.project.selflearningplatformserver.exception.SecurityServerException; 12 | import com.project.selflearningplatformserver.mapper.StudentClassMapper; 13 | import com.project.selflearningplatformserver.mapper.StudentMapper; 14 | import com.project.selflearningplatformserver.mapper.UserMapper; 15 | import com.project.selflearningplatformserver.service.SecurityService; 16 | import com.project.selflearningplatformserver.util.JwtUtils; 17 | import com.project.selflearningplatformserver.util.Md5Utils; 18 | import com.project.selflearningplatformserver.util.OrikaUtils; 19 | import com.project.selflearningplatformserver.util.Tuple2; 20 | import org.apache.commons.lang3.StringUtils; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.http.HttpStatus; 23 | import org.springframework.stereotype.Service; 24 | import org.springframework.transaction.annotation.Transactional; 25 | 26 | import java.util.Date; 27 | import java.util.UUID; 28 | 29 | /** 30 | * @author itning 31 | * @date 2020/5/1 14:01 32 | */ 33 | @Service 34 | @Transactional(rollbackFor = Exception.class) 35 | public class SecurityServiceImpl implements SecurityService { 36 | private final UserMapper userMapper; 37 | private final StudentMapper studentMapper; 38 | private final StudentClassMapper studentClassMapper; 39 | 40 | @Autowired 41 | public SecurityServiceImpl(UserMapper userMapper, StudentMapper studentMapper, StudentClassMapper studentClassMapper) { 42 | this.userMapper = userMapper; 43 | this.studentMapper = studentMapper; 44 | this.studentClassMapper = studentClassMapper; 45 | } 46 | 47 | @Override 48 | public String login(String username, String password) throws JsonProcessingException { 49 | User user = userMapper.selectByUserName(username).orElseThrow(() -> new SecurityServerException("用户名不存在", HttpStatus.NOT_FOUND)); 50 | if (user.getFreeze()) { 51 | throw new SecurityServerException("账户被冻结", HttpStatus.FORBIDDEN); 52 | } 53 | if (!Md5Utils.checkEquals(password, user.getSalt(), user.getPassword())) { 54 | throw new SecurityServerException("密码错误", HttpStatus.BAD_REQUEST); 55 | } 56 | return JwtUtils.buildJwt(OrikaUtils.a2b(user, LoginUser.class)); 57 | } 58 | 59 | @Override 60 | public UserDTO reg(String username, String password, String name, String studentClassId) { 61 | if (StringUtils.isBlank(studentClassId) || studentClassMapper.countByPrimaryKey(studentClassId) == 0L) { 62 | throw new IdNotFoundException("班级ID不存在"); 63 | } 64 | if (StringUtils.isAnyBlank(username, password, name)) { 65 | throw new NullFiledException("传入参数为空"); 66 | } 67 | if (userMapper.countByUserName(username) != 0L) { 68 | throw new IllegalFiledException("用户名已存在"); 69 | } 70 | 71 | Tuple2 md5 = Md5Utils.string2Md5(password); 72 | Date date = new Date(); 73 | User user = new User(); 74 | user.setId(UUID.randomUUID().toString()); 75 | user.setName(name); 76 | user.setUsername(username); 77 | user.setPassword(md5.getT1()); 78 | user.setFreeze(false); 79 | user.setSalt(md5.getT2()); 80 | user.setRoleId(LoginUser.ROLE_STUDENT_ID); 81 | user.setGmtCreate(date); 82 | user.setGmtModified(date); 83 | userMapper.insert(user); 84 | 85 | Student student = new Student(); 86 | student.setUserId(user.getId()); 87 | student.setStudentClassId(studentClassId); 88 | student.setGmtCreate(date); 89 | student.setGmtModified(date); 90 | studentMapper.insert(student); 91 | 92 | return OrikaUtils.a2b(user, UserDTO.class); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/StudentWorkController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.log.Log; 6 | import com.project.selflearningplatformserver.security.MustLogin; 7 | import com.project.selflearningplatformserver.security.MustStudentLogin; 8 | import com.project.selflearningplatformserver.security.MustTeacherLogin; 9 | import com.project.selflearningplatformserver.service.StudentWorkService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.HttpHeaders; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.web.bind.annotation.*; 14 | import org.springframework.web.multipart.MultipartFile; 15 | 16 | import javax.servlet.http.HttpServletResponse; 17 | 18 | /** 19 | * @author itning 20 | * @date 2020/5/2 11:45 21 | */ 22 | @RestController 23 | public class StudentWorkController { 24 | private final StudentWorkService studentWorkService; 25 | 26 | @Autowired 27 | public StudentWorkController(StudentWorkService studentWorkService) { 28 | this.studentWorkService = studentWorkService; 29 | } 30 | 31 | /** 32 | * 教师批改作业 33 | * 34 | * @param loginUser 登陆用户 35 | * @param studentWorkId 学生作业ID 36 | * @param suggest 建议 37 | * @param score 分数 38 | * @return ResponseEntity 39 | */ 40 | @Log("教师批改作业") 41 | @PostMapping("/student_work_review") 42 | public ResponseEntity teacherReview(@MustTeacherLogin LoginUser loginUser, 43 | @RequestParam String studentWorkId, 44 | @RequestParam String suggest, 45 | @RequestParam int score) { 46 | return RestModel.created(studentWorkService.teacherReview(loginUser, studentWorkId, suggest, score)); 47 | } 48 | 49 | /** 50 | * 教师或学生下载作业 51 | * 52 | * @param loginUser 登录用户 53 | * @param id 作业ID 54 | * @param response {@link HttpServletResponse} 55 | */ 56 | @GetMapping("/download_student_work/{id}") 57 | public void downloadStudentWork(@MustLogin(role = {MustLogin.ROLE.STUDENT, MustLogin.ROLE.TEACHER}) LoginUser loginUser, 58 | @RequestHeader(name = HttpHeaders.RANGE, required = false) String range, 59 | @PathVariable String id, 60 | HttpServletResponse response) { 61 | studentWorkService.downloadWorkFile(loginUser, id, response, range); 62 | } 63 | 64 | /** 65 | * 学生删除作业 66 | * 67 | * @param loginUser 登录用户 68 | * @param id 作业ID 69 | * @return ResponseEntity 70 | */ 71 | @Log("学生删除作业") 72 | @DeleteMapping("/student_work/{id}") 73 | public ResponseEntity studentDelWork(@MustStudentLogin LoginUser loginUser, 74 | @PathVariable String id) { 75 | studentWorkService.delWork(loginUser, id); 76 | return RestModel.noContent(); 77 | } 78 | 79 | /** 80 | * 学生上传作业 81 | * 82 | * @param loginUser 登录用户 83 | * @param file 文件 84 | * @param studentLearningId 学生学习ID 85 | * @return ResponseEntity 86 | */ 87 | @Log("学生上传作业") 88 | @PostMapping("/student_work") 89 | public ResponseEntity studentUploadWork(@MustStudentLogin LoginUser loginUser, 90 | @RequestParam("file") MultipartFile file, 91 | @RequestParam String studentLearningId) { 92 | return RestModel.created(studentWorkService.upload(loginUser, studentLearningId, file)); 93 | } 94 | 95 | /** 96 | * 学生获取自己的作业 97 | * 98 | * @param loginUser 登录用户 99 | * @param learningContentId 学习内容ID 100 | * @return ResponseEntity 101 | */ 102 | @GetMapping("/student_work") 103 | public ResponseEntity getOwnWork(@MustStudentLogin LoginUser loginUser, 104 | @RequestParam String learningContentId) { 105 | return RestModel.ok(studentWorkService.getOwnWork(loginUser, learningContentId)); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/resources/mappers/LogMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | id, content, user_id, gmt_create, gmt_modified 15 | 16 | 22 | 23 | delete 24 | from log 25 | where id = #{id,jdbcType=CHAR} 26 | 27 | 28 | insert into log (id, content, user_id, 29 | gmt_create, gmt_modified) 30 | values (#{id,jdbcType=CHAR}, #{content,jdbcType=VARCHAR}, #{userId,jdbcType=CHAR}, 31 | #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}) 32 | 33 | 34 | insert into log 35 | 36 | 37 | id, 38 | 39 | 40 | content, 41 | 42 | 43 | user_id, 44 | 45 | 46 | gmt_create, 47 | 48 | 49 | gmt_modified, 50 | 51 | 52 | 53 | 54 | #{id,jdbcType=CHAR}, 55 | 56 | 57 | #{content,jdbcType=VARCHAR}, 58 | 59 | 60 | #{userId,jdbcType=CHAR}, 61 | 62 | 63 | #{gmtCreate,jdbcType=TIMESTAMP}, 64 | 65 | 66 | #{gmtModified,jdbcType=TIMESTAMP}, 67 | 68 | 69 | 70 | 71 | update log 72 | 73 | 74 | content = #{content,jdbcType=VARCHAR}, 75 | 76 | 77 | user_id = #{userId,jdbcType=CHAR}, 78 | 79 | 80 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 81 | 82 | 83 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, 84 | 85 | 86 | where id = #{id,jdbcType=CHAR} 87 | 88 | 89 | update log 90 | set content = #{content,jdbcType=VARCHAR}, 91 | user_id = #{userId,jdbcType=CHAR}, 92 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 93 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} 94 | where id = #{id,jdbcType=CHAR} 95 | 96 | 101 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/log/LogAspect.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.log; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.mapper.LogMapper; 5 | import org.apache.commons.lang3.StringUtils; 6 | import org.aspectj.lang.ProceedingJoinPoint; 7 | import org.aspectj.lang.annotation.Around; 8 | import org.aspectj.lang.annotation.Aspect; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.lang.NonNull; 12 | import org.springframework.lang.Nullable; 13 | import org.springframework.stereotype.Component; 14 | 15 | import java.util.*; 16 | 17 | /** 18 | * @author itning 19 | * @date 2020/5/1 16:17 20 | * @see Log 21 | */ 22 | @Aspect 23 | @Component 24 | public class LogAspect { 25 | private final LogMapper logMapper; 26 | 27 | @Autowired 28 | public LogAspect(LogMapper logMapper) { 29 | this.logMapper = logMapper; 30 | } 31 | 32 | @Around("@annotation(log)") 33 | public Object advice(ProceedingJoinPoint joinPoint, Log log) throws Throwable { 34 | final Object[] methodArgs = joinPoint.getArgs(); 35 | Optional loginUserOptional = Arrays.stream(methodArgs) 36 | .filter(o -> o instanceof LoginUser) 37 | .map(o -> (LoginUser) o) 38 | .findAny(); 39 | 40 | String result = null; 41 | Throwable th = null; 42 | Object proceed; 43 | try { 44 | proceed = joinPoint.proceed(); 45 | if (proceed instanceof ResponseEntity) { 46 | ResponseEntity responseEntity = (ResponseEntity) proceed; 47 | result = log(responseEntity); 48 | } 49 | } catch (Throwable throwable) { 50 | th = throwable; 51 | throw throwable; 52 | } finally { 53 | log(loginUserOptional.orElse(null), log.value(), methodArgs, th, result); 54 | } 55 | return proceed; 56 | } 57 | 58 | private void log(@Nullable LoginUser loginUser, 59 | @NonNull String methodEffect, 60 | @Nullable Object[] methodArgs, 61 | @Nullable Throwable th, 62 | @Nullable String result) { 63 | if (Objects.isNull(loginUser)) { 64 | return; 65 | } 66 | StringBuilder sb = new StringBuilder() 67 | .append("╔═══════════════════════════════════") 68 | .append("\n") 69 | .append("║") 70 | .append(loginUser.getName()) 71 | .append("(ID:") 72 | .append(loginUser.getId()) 73 | .append(")") 74 | .append("\t") 75 | .append(methodEffect) 76 | .append("\t"); 77 | if (Objects.nonNull(methodArgs)) { 78 | sb.append("\n").append("║").append("调用参数:"); 79 | Arrays.stream(methodArgs) 80 | .filter(o -> !(o instanceof LoginUser)) 81 | .forEach(itemArg -> sb.append("[").append(itemArg.toString()).append("]")); 82 | } 83 | sb.append("\n"); 84 | if (Objects.nonNull(th)) { 85 | sb.append("║").append("捕获异常:").append(th.getMessage()); 86 | } 87 | if (StringUtils.isNotBlank(result)) { 88 | sb.append("║").append("返回参数:").append(result); 89 | } 90 | sb.append("\n").append("╚═══════════════════════════════════"); 91 | persistence(sb.toString(), loginUser.getId()); 92 | } 93 | 94 | private String log(@NonNull ResponseEntity responseEntity) { 95 | return "状态码:" + 96 | responseEntity.getStatusCode().value() + 97 | " " + 98 | "响应体:" + 99 | responseEntity.getBody(); 100 | } 101 | 102 | private void persistence(@NonNull String content, @NonNull String userId) { 103 | Date date = new Date(); 104 | com.project.selflearningplatformserver.entity.Log log = new com.project.selflearningplatformserver.entity.Log(); 105 | log.setId(UUID.randomUUID().toString()); 106 | log.setContent(content); 107 | log.setUserId(userId); 108 | log.setGmtCreate(date); 109 | log.setGmtModified(date); 110 | try { 111 | logMapper.insert(log); 112 | } catch (Exception e) { 113 | // ignore 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/StudentClassController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.entity.StudentClass; 6 | import com.project.selflearningplatformserver.log.Log; 7 | import com.project.selflearningplatformserver.security.MustStudentLogin; 8 | import com.project.selflearningplatformserver.security.MustTeacherLogin; 9 | import com.project.selflearningplatformserver.service.StudentClassServer; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | /** 15 | * @author itning 16 | * @date 2020/5/1 20:21 17 | */ 18 | @RestController 19 | public class StudentClassController { 20 | private final StudentClassServer studentClassServer; 21 | 22 | @Autowired 23 | public StudentClassController(StudentClassServer studentClassServer) { 24 | this.studentClassServer = studentClassServer; 25 | } 26 | 27 | /** 28 | * 获取所有班级带教师名 29 | * 30 | * @return ResponseEntity 31 | */ 32 | @GetMapping("/classes") 33 | public ResponseEntity getAllClass() { 34 | return RestModel.ok(studentClassServer.getAll()); 35 | } 36 | 37 | /** 38 | * 学生获取自己所在的班级 39 | * 40 | * @param loginUser 登录用户 41 | * @return ResponseEntity 42 | */ 43 | @GetMapping("/my_classes") 44 | public ResponseEntity getStudentClass(@MustStudentLogin LoginUser loginUser) { 45 | return RestModel.ok(studentClassServer.getStudentOwnClass(loginUser)); 46 | } 47 | 48 | /** 49 | * 学生加入班级 50 | * 51 | * @param loginUser 登录用户 52 | * @param classId 班级ID 53 | * @return ResponseEntity 54 | */ 55 | @Log("学生加入班级") 56 | @PostMapping("/join_class") 57 | public ResponseEntity joinClass(@MustStudentLogin LoginUser loginUser, 58 | @RequestParam String classId) { 59 | return RestModel.created(studentClassServer.joinClass(loginUser, classId)); 60 | } 61 | 62 | 63 | /** 64 | * 教师获取自己的班级 65 | * 66 | * @param loginUser 登录用户 67 | * @return ResponseEntity 68 | */ 69 | @GetMapping("/student_classes") 70 | public ResponseEntity getAllStudentClass(@MustTeacherLogin LoginUser loginUser) { 71 | return RestModel.ok(studentClassServer.getAll(loginUser)); 72 | } 73 | 74 | /** 75 | * 教师获取自己的学生(自己所有班级的所有学生) 76 | * 77 | * @param loginUser 登录用户 78 | * @return ResponseEntity 79 | */ 80 | @GetMapping("/student_in_class") 81 | public ResponseEntity getAllStudentInClass(@MustTeacherLogin LoginUser loginUser) { 82 | return RestModel.ok(studentClassServer.getAllStudentInClass(loginUser)); 83 | } 84 | 85 | /** 86 | * 教师新增班级 87 | * 88 | * @param loginUser 登录用户 89 | * @param name 班级名 90 | * @return ResponseEntity 91 | */ 92 | @Log("新增班级") 93 | @PostMapping("/student_class") 94 | public ResponseEntity newStudentClass(@MustTeacherLogin LoginUser loginUser, 95 | @RequestParam String name) { 96 | return RestModel.created(studentClassServer.newStudentClass(loginUser, name)); 97 | } 98 | 99 | /** 100 | * 教师修改班级 101 | * 102 | * @param loginUser 登录用户 103 | * @param studentClass 班级信息 104 | * @return ResponseEntity 105 | */ 106 | @Log("修改班级") 107 | @PatchMapping("/student_class") 108 | public ResponseEntity updateStudentClass(@MustTeacherLogin LoginUser loginUser, 109 | @RequestBody StudentClass studentClass) { 110 | studentClassServer.updateStudentClass(loginUser, studentClass); 111 | return RestModel.noContent(); 112 | } 113 | 114 | /** 115 | * 教师删除班级 116 | * 117 | * @param loginUser 登录用户 118 | * @param studentClassId 班级ID 119 | * @return ResponseEntity 120 | */ 121 | @Log("删除班级") 122 | @DeleteMapping("/student_class/{studentClassId}") 123 | public ResponseEntity delStudentClass(@MustTeacherLogin LoginUser loginUser, 124 | @PathVariable String studentClassId) { 125 | studentClassServer.del(loginUser, studentClassId); 126 | return RestModel.noContent(); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/resources/mappers/ExaminationMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | id, user_id, name, gmt_create, gmt_modified 15 | 16 | 22 | 23 | delete 24 | from examination 25 | where id = #{id,jdbcType=CHAR} 26 | 27 | 28 | insert into examination (id, user_id, name, gmt_create, 29 | gmt_modified) 30 | values (#{id,jdbcType=CHAR}, #{userId,jdbcType=CHAR}, #{name,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, 31 | #{gmtModified,jdbcType=TIMESTAMP}) 32 | 33 | 34 | insert into examination 35 | 36 | 37 | id, 38 | 39 | 40 | user_id, 41 | 42 | 43 | name, 44 | 45 | 46 | gmt_create, 47 | 48 | 49 | gmt_modified, 50 | 51 | 52 | 53 | 54 | #{id,jdbcType=CHAR}, 55 | 56 | 57 | #{userId,jdbcType=CHAR}, 58 | 59 | 60 | #{name,jdbcType=VARCHAR}, 61 | 62 | 63 | #{gmtCreate,jdbcType=TIMESTAMP}, 64 | 65 | 66 | #{gmtModified,jdbcType=TIMESTAMP}, 67 | 68 | 69 | 70 | 71 | update examination 72 | 73 | 74 | user_id = #{userId,jdbcType=CHAR}, 75 | 76 | 77 | name = #{name,jdbcType=VARCHAR}, 78 | 79 | 80 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 81 | 82 | 83 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, 84 | 85 | 86 | where id = #{id,jdbcType=CHAR} 87 | 88 | 89 | update examination 90 | set user_id = #{userId,jdbcType=CHAR}, 91 | name = #{name,jdbcType=VARCHAR}, 92 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 93 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} 94 | where id = #{id,jdbcType=CHAR} 95 | 96 | 101 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/util/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.util; 2 | 3 | import com.project.selflearningplatformserver.exception.SecurityServerException; 4 | import org.apache.catalina.connector.ClientAbortException; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.http.HttpHeaders; 8 | import org.springframework.http.HttpStatus; 9 | 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.BufferedOutputStream; 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.io.RandomAccessFile; 15 | import java.nio.charset.StandardCharsets; 16 | 17 | /** 18 | * 文件工具类 19 | * 20 | * @author itning 21 | */ 22 | public final class FileUtils { 23 | private static final Logger logger = LoggerFactory.getLogger(FileUtils.class); 24 | private static final String RANGE_SEPARATOR = "-"; 25 | private static final String RANGE_CONTAINS = "bytes="; 26 | private static final int RANGE_BYTES_ALL = 2; 27 | private static final int RANGE_BYTES_ONE = 1; 28 | 29 | /** 30 | * 断点续传 31 | * 32 | * @param file 所需要下载的文件 33 | * @param contentType MIME类型 34 | * @param range 请求头 35 | * @param response {@link HttpServletResponse} 36 | */ 37 | public static void breakpointResume(File file, String contentType, String range, HttpServletResponse response) { 38 | long startByte = 0; 39 | long endByte = file.length() - 1; 40 | if (range != null && range.contains(RANGE_CONTAINS) && range.contains(RANGE_SEPARATOR)) { 41 | range = range.substring(range.lastIndexOf("=") + 1).trim(); 42 | String[] ranges = range.split(RANGE_SEPARATOR); 43 | try { 44 | //判断range的类型 45 | if (ranges.length == RANGE_BYTES_ONE) { 46 | if (range.startsWith(RANGE_SEPARATOR)) { 47 | //类型一:bytes=-2343 48 | endByte = Long.parseLong(ranges[0]); 49 | } else if (range.endsWith(RANGE_SEPARATOR)) { 50 | //类型二:bytes=2343- 51 | startByte = Long.parseLong(ranges[0]); 52 | } 53 | } else if (ranges.length == RANGE_BYTES_ALL) { 54 | //类型三:bytes=22-2343 55 | startByte = Long.parseLong(ranges[0]); 56 | endByte = Long.parseLong(ranges[1]); 57 | } 58 | 59 | } catch (NumberFormatException e) { 60 | startByte = 0; 61 | endByte = file.length() - 1; 62 | } 63 | } 64 | long contentLength = endByte - startByte + 1; 65 | response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes"); 66 | if (range == null) { 67 | response.setStatus(HttpServletResponse.SC_OK); 68 | } else { 69 | response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); 70 | response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes " + startByte + "-" + endByte + "/" + file.length()); 71 | } 72 | response.setContentType(contentType); 73 | response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + new String(file.getName().getBytes(), StandardCharsets.ISO_8859_1)); 74 | response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(contentLength)); 75 | long transmitted = 0; 76 | try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); 77 | BufferedOutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) { 78 | byte[] buff = new byte[4096]; 79 | int len = 0; 80 | randomAccessFile.seek(startByte); 81 | while ((transmitted + len) <= contentLength && (len = randomAccessFile.read(buff)) != -1) { 82 | outputStream.write(buff, 0, len); 83 | transmitted += len; 84 | } 85 | if (transmitted < contentLength) { 86 | len = randomAccessFile.read(buff, 0, (int) (contentLength - transmitted)); 87 | outputStream.write(buff, 0, len); 88 | transmitted += len; 89 | } 90 | outputStream.flush(); 91 | response.flushBuffer(); 92 | randomAccessFile.close(); 93 | logger.debug("下载完毕:{}-{}: {}", startByte, endByte, transmitted); 94 | } catch (ClientAbortException e) { 95 | logger.debug("用户停止下载:{}-{}: {}", startByte, endByte, transmitted); 96 | } catch (IOException e) { 97 | throw new SecurityServerException(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/resources/mappers/SubjectMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | id, user_id, name, gmt_create, gmt_modified 15 | 16 | 22 | 23 | delete 24 | from subject 25 | where id = #{id,jdbcType=CHAR} 26 | 27 | 28 | insert into subject (id, user_id, name, gmt_create, 29 | gmt_modified) 30 | values (#{id,jdbcType=CHAR}, #{userId,jdbcType=CHAR}, #{name,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, 31 | #{gmtModified,jdbcType=TIMESTAMP}) 32 | 33 | 34 | insert into subject 35 | 36 | 37 | id, 38 | 39 | 40 | user_id, 41 | 42 | 43 | name, 44 | 45 | 46 | gmt_create, 47 | 48 | 49 | gmt_modified, 50 | 51 | 52 | 53 | 54 | #{id,jdbcType=CHAR}, 55 | 56 | 57 | #{userId,jdbcType=CHAR}, 58 | 59 | 60 | #{name,jdbcType=VARCHAR}, 61 | 62 | 63 | #{gmtCreate,jdbcType=TIMESTAMP}, 64 | 65 | 66 | #{gmtModified,jdbcType=TIMESTAMP}, 67 | 68 | 69 | 70 | 71 | update subject 72 | 73 | 74 | user_id = #{userId,jdbcType=CHAR}, 75 | 76 | 77 | name = #{name,jdbcType=VARCHAR}, 78 | 79 | 80 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 81 | 82 | 83 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, 84 | 85 | 86 | where id = #{id,jdbcType=CHAR} 87 | 88 | 89 | update subject 90 | set user_id = #{userId,jdbcType=CHAR}, 91 | name = #{name,jdbcType=VARCHAR}, 92 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 93 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} 94 | where id = #{id,jdbcType=CHAR} 95 | 96 | 101 | 106 | -------------------------------------------------------------------------------- /src/main/resources/mappers/AttendanceMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | id, user_id, gmt_create, gmt_modified 14 | 15 | 21 | 22 | delete 23 | from attendance 24 | where id = #{id,jdbcType=CHAR} 25 | 26 | 27 | insert into attendance (id, user_id, gmt_create, 28 | gmt_modified) 29 | values (#{id,jdbcType=CHAR}, #{userId,jdbcType=CHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, 30 | #{gmtModified,jdbcType=TIMESTAMP}) 31 | 32 | 33 | insert into attendance 34 | 35 | 36 | id, 37 | 38 | 39 | user_id, 40 | 41 | 42 | gmt_create, 43 | 44 | 45 | gmt_modified, 46 | 47 | 48 | 49 | 50 | #{id,jdbcType=CHAR}, 51 | 52 | 53 | #{userId,jdbcType=CHAR}, 54 | 55 | 56 | #{gmtCreate,jdbcType=TIMESTAMP}, 57 | 58 | 59 | #{gmtModified,jdbcType=TIMESTAMP}, 60 | 61 | 62 | 63 | 64 | update attendance 65 | 66 | 67 | user_id = #{userId,jdbcType=CHAR}, 68 | 69 | 70 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 71 | 72 | 73 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, 74 | 75 | 76 | where id = #{id,jdbcType=CHAR} 77 | 78 | 79 | update attendance 80 | set user_id = #{userId,jdbcType=CHAR}, 81 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 82 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} 83 | where id = #{id,jdbcType=CHAR} 84 | 85 | 90 | 95 | 102 | 108 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/impl/StudentLearningServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service.impl; 2 | 3 | import com.project.selflearningplatformserver.config.AppProperties; 4 | import com.project.selflearningplatformserver.dto.LearningContentDTO; 5 | import com.project.selflearningplatformserver.dto.LoginUser; 6 | import com.project.selflearningplatformserver.dto.StudentLearningDTO; 7 | import com.project.selflearningplatformserver.entity.StudentLearning; 8 | import com.project.selflearningplatformserver.exception.IdNotFoundException; 9 | import com.project.selflearningplatformserver.exception.NullFiledException; 10 | import com.project.selflearningplatformserver.mapper.LearningContentMapper; 11 | import com.project.selflearningplatformserver.mapper.StudentLearningMapper; 12 | import com.project.selflearningplatformserver.mapper.StudentWorkMapper; 13 | import com.project.selflearningplatformserver.service.StudentLearningService; 14 | import com.project.selflearningplatformserver.video.VideoTransformHandler; 15 | import org.apache.commons.lang3.StringUtils; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.stereotype.Service; 18 | import org.springframework.transaction.annotation.Transactional; 19 | 20 | import java.io.File; 21 | import java.util.Date; 22 | import java.util.List; 23 | import java.util.UUID; 24 | import java.util.stream.Collectors; 25 | 26 | /** 27 | * @author itning 28 | * @date 2020/5/2 11:29 29 | */ 30 | @Transactional(rollbackFor = Exception.class) 31 | @Service 32 | public class StudentLearningServiceImpl implements StudentLearningService { 33 | private final StudentLearningMapper studentLearningMapper; 34 | private final LearningContentMapper learningContentMapper; 35 | private final StudentWorkMapper studentWorkMapper; 36 | private final VideoTransformHandler videoTransformHandler; 37 | private final AppProperties appProperties; 38 | 39 | @Autowired 40 | public StudentLearningServiceImpl(StudentLearningMapper studentLearningMapper, LearningContentMapper learningContentMapper, StudentWorkMapper studentWorkMapper, VideoTransformHandler videoTransformHandler, AppProperties appProperties) { 41 | this.studentLearningMapper = studentLearningMapper; 42 | this.learningContentMapper = learningContentMapper; 43 | this.studentWorkMapper = studentWorkMapper; 44 | this.videoTransformHandler = videoTransformHandler; 45 | this.appProperties = appProperties; 46 | } 47 | 48 | @Override 49 | public StudentLearning switchLearningContent(LoginUser loginUser, String learningContentId) { 50 | if (StringUtils.isBlank(learningContentId)) { 51 | throw new NullFiledException("学习内容ID为空"); 52 | } 53 | if (learningContentMapper.countByPrimaryKey(learningContentId) == 0L) { 54 | throw new IdNotFoundException("学习内容ID不存在"); 55 | } 56 | Date date = new Date(); 57 | StudentLearning studentLearning = new StudentLearning(); 58 | studentLearning.setId(UUID.randomUUID().toString()); 59 | studentLearning.setLearningContentId(learningContentId); 60 | studentLearning.setStudentId(loginUser.getId()); 61 | studentLearning.setGmtCreate(date); 62 | studentLearning.setGmtModified(date); 63 | studentLearningMapper.insert(studentLearning); 64 | return studentLearning; 65 | } 66 | 67 | @Override 68 | public List getMyLearning(LoginUser loginUser) { 69 | return studentLearningMapper.selectAllByStudentId(loginUser.getId()) 70 | .parallelStream() 71 | .filter(learningContent -> !videoTransformHandler.isNowTranscoding(new File(appProperties.getLearningContentDir() + learningContent.getContentUri()))) 72 | .collect(Collectors.toList()); 73 | } 74 | 75 | @Override 76 | public void delMyLearning(LoginUser loginUser, String studentLearningId) { 77 | if (StringUtils.isBlank(studentLearningId)) { 78 | throw new NullFiledException("学生学习ID为空"); 79 | } 80 | if (studentLearningMapper.countByPrimaryKey(studentLearningId) == 0L) { 81 | throw new IdNotFoundException("学生学习不存在"); 82 | } 83 | studentLearningMapper.deleteByPrimaryKey(studentLearningId); 84 | } 85 | 86 | @Override 87 | public List getAllStudentInLearning(LoginUser loginUser, String learningContentId) { 88 | if (StringUtils.isBlank(learningContentId)) { 89 | throw new NullFiledException("学习内容ID为空"); 90 | } 91 | if (learningContentMapper.countByPrimaryKey(learningContentId) == 0L) { 92 | throw new IdNotFoundException("学习内容不存在"); 93 | } 94 | return studentLearningMapper.selectAllWithStudentName(learningContentId) 95 | .stream() 96 | .peek(studentLearningDTO -> studentLearningDTO.setStudentWork(studentWorkMapper.selectByPrimaryKey(studentLearningDTO.getId()))) 97 | .collect(Collectors.toList()); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/controller/LearningContentController.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.controller; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.RestModel; 5 | import com.project.selflearningplatformserver.entity.LearningContent; 6 | import com.project.selflearningplatformserver.log.Log; 7 | import com.project.selflearningplatformserver.security.MustLogin; 8 | import com.project.selflearningplatformserver.security.MustStudentLogin; 9 | import com.project.selflearningplatformserver.security.MustTeacherLogin; 10 | import com.project.selflearningplatformserver.service.LearningContentService; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.http.HttpHeaders; 13 | import org.springframework.http.ResponseEntity; 14 | import org.springframework.web.bind.annotation.*; 15 | import org.springframework.web.multipart.MultipartFile; 16 | 17 | import javax.servlet.http.HttpServletResponse; 18 | 19 | /** 20 | * @author itning 21 | * @date 2020/5/1 20:53 22 | */ 23 | @RestController 24 | public class LearningContentController { 25 | private final LearningContentService learningContentService; 26 | 27 | @Autowired 28 | public LearningContentController(LearningContentService learningContentService) { 29 | this.learningContentService = learningContentService; 30 | } 31 | 32 | /** 33 | * 根据科目获取学习内容 34 | * 35 | * @param loginUser 登录用户 36 | * @param subjectId 科目ID 37 | * @return ResponseEntity 38 | */ 39 | @GetMapping("/learning_contents") 40 | public ResponseEntity allLearningContent(@MustLogin LoginUser loginUser, 41 | @RequestParam String subjectId) { 42 | return RestModel.ok(learningContentService.getAllBySubjectId(subjectId)); 43 | } 44 | 45 | /** 46 | * 新增学习内容 47 | * 48 | * @param loginUser 登录用户 49 | * @param file 文件 50 | * @param aidFile 其他文件 51 | * @param name 名称 52 | * @param subjectId 科目ID 53 | * @return ResponseEntity 54 | */ 55 | @Log("新增学习内容") 56 | @PostMapping("/learning_content") 57 | public ResponseEntity uploadLearningContent(@MustTeacherLogin LoginUser loginUser, 58 | @RequestParam("file") MultipartFile file, 59 | @RequestParam("aid") MultipartFile aidFile, 60 | @RequestParam String name, 61 | @RequestParam String subjectId) { 62 | return RestModel.created(learningContentService.newLearningContent(loginUser, file, aidFile, subjectId, name)); 63 | } 64 | 65 | /** 66 | * 教师删除学习内容 67 | * 68 | * @param loginUser 登录用户 69 | * @param id 学习内容ID 70 | * @return ResponseEntity 71 | */ 72 | @Log("删除学习内容") 73 | @DeleteMapping("/learning_content/{id}") 74 | public ResponseEntity delLearningContent(@MustTeacherLogin LoginUser loginUser, 75 | @PathVariable String id) { 76 | learningContentService.delLearningContent(loginUser, id); 77 | return RestModel.noContent(); 78 | } 79 | 80 | /** 81 | * 教师修改学习内容 82 | * 83 | * @param loginUser 登录用户 84 | * @param learningContent 学习内容 85 | * @return ResponseEntity 86 | */ 87 | @Log("修改学习内容") 88 | @PatchMapping("/learning_content") 89 | public ResponseEntity updateLearningContent(@MustTeacherLogin LoginUser loginUser, 90 | @RequestBody LearningContent learningContent) { 91 | learningContentService.updateLearningContent(loginUser, learningContent.getId(), learningContent.getName()); 92 | return RestModel.noContent(); 93 | } 94 | 95 | /** 96 | * 学生获取所有可以学习的内容(排除已经选择的) 97 | * 98 | * @return ResponseEntity 99 | */ 100 | @GetMapping("/learning_content_of_student") 101 | public ResponseEntity getAllCanLearningContent(@MustStudentLogin LoginUser loginUser) { 102 | return RestModel.ok(learningContentService.getAllCanLearningContent(loginUser)); 103 | } 104 | 105 | /** 106 | * 下载学习内容文件 107 | * 108 | * @param loginUser 登录用户 109 | * @param type 哪种文件(video/aid) 110 | * @param learningContentId 学习内容ID 111 | * @param range {@link HttpHeaders#RANGE} 112 | * @param response {@link HttpServletResponse} 113 | */ 114 | @GetMapping("/download_learning_content/{type}/{learningContentId}") 115 | public void downloadLearningContentAid(@MustLogin(role = {MustLogin.ROLE.STUDENT, MustLogin.ROLE.TEACHER}) LoginUser loginUser, 116 | @PathVariable String type, 117 | @PathVariable String learningContentId, 118 | @RequestHeader(name = HttpHeaders.RANGE, required = false) String range, 119 | HttpServletResponse response) { 120 | learningContentService.downloadLearningContent(loginUser, learningContentId, range, response, type); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/impl/StudentClassServerImpl.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service.impl; 2 | 3 | import com.project.selflearningplatformserver.dto.LoginUser; 4 | import com.project.selflearningplatformserver.dto.StudentClassDTO; 5 | import com.project.selflearningplatformserver.dto.UserDTO; 6 | import com.project.selflearningplatformserver.entity.Student; 7 | import com.project.selflearningplatformserver.entity.StudentClass; 8 | import com.project.selflearningplatformserver.exception.IdNotFoundException; 9 | import com.project.selflearningplatformserver.exception.NullFiledException; 10 | import com.project.selflearningplatformserver.mapper.StudentClassMapper; 11 | import com.project.selflearningplatformserver.mapper.StudentMapper; 12 | import com.project.selflearningplatformserver.service.StudentClassServer; 13 | import org.apache.commons.lang3.StringUtils; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.transaction.annotation.Transactional; 17 | 18 | import java.util.Date; 19 | import java.util.List; 20 | import java.util.Objects; 21 | import java.util.UUID; 22 | 23 | /** 24 | * @author itning 25 | * @date 2020/5/1 20:15 26 | */ 27 | @Transactional(rollbackFor = Exception.class) 28 | @Service 29 | public class StudentClassServerImpl implements StudentClassServer { 30 | private final StudentClassMapper studentClassMapper; 31 | private final StudentMapper studentMapper; 32 | 33 | @Autowired 34 | public StudentClassServerImpl(StudentClassMapper studentClassMapper, StudentMapper studentMapper) { 35 | this.studentClassMapper = studentClassMapper; 36 | this.studentMapper = studentMapper; 37 | } 38 | 39 | @Override 40 | public List getAll(LoginUser loginUser) { 41 | return studentClassMapper.selectByUserId(loginUser.getId()); 42 | } 43 | 44 | @Override 45 | public void del(LoginUser loginUser, String id) { 46 | if (StringUtils.isBlank(id)) { 47 | throw new NullFiledException("班级ID为空"); 48 | } 49 | if (studentClassMapper.countByPrimaryKey(id) == 0L) { 50 | throw new IdNotFoundException("班级ID不存在"); 51 | } 52 | studentClassMapper.deleteByPrimaryKey(id); 53 | } 54 | 55 | @Override 56 | public StudentClass newStudentClass(LoginUser loginUser, String name) { 57 | if (StringUtils.isBlank(name)) { 58 | throw new NullFiledException("班级名为空"); 59 | } 60 | Date date = new Date(); 61 | StudentClass studentClass = new StudentClass(); 62 | studentClass.setId(UUID.randomUUID().toString()); 63 | studentClass.setName(name); 64 | studentClass.setUserId(loginUser.getId()); 65 | studentClass.setGmtCreate(date); 66 | studentClass.setGmtModified(date); 67 | studentClassMapper.insert(studentClass); 68 | return studentClass; 69 | } 70 | 71 | @Override 72 | public StudentClass updateStudentClass(LoginUser loginUser, StudentClass studentClass) { 73 | if (StringUtils.isBlank(studentClass.getId())) { 74 | throw new NullFiledException("班级ID为空"); 75 | } 76 | if (studentClassMapper.countByPrimaryKey(studentClass.getId()) == 0L) { 77 | throw new IdNotFoundException("班级ID不存在"); 78 | } 79 | if (StringUtils.isBlank(studentClass.getName())) { 80 | throw new NullFiledException("班级名为空"); 81 | } 82 | studentClass.setGmtCreate(null); 83 | studentClass.setGmtModified(new Date()); 84 | studentClass.setUserId(null); 85 | studentClassMapper.updateByPrimaryKeySelective(studentClass); 86 | return studentClass; 87 | } 88 | 89 | @Override 90 | public List getAll() { 91 | return studentClassMapper.selectAllWithTeacherName(); 92 | } 93 | 94 | @Override 95 | public List getAllStudentInClass(LoginUser loginUser) { 96 | return studentClassMapper.selectAllStudentInClass(loginUser.getId()); 97 | } 98 | 99 | @Override 100 | public StudentClassDTO getStudentOwnClass(LoginUser loginUser) { 101 | return studentClassMapper.selectOwnClass(loginUser.getId()); 102 | } 103 | 104 | @Override 105 | public Student joinClass(LoginUser loginUser, String classId) { 106 | if (StringUtils.isBlank(classId)) { 107 | throw new NullFiledException("班级ID为空"); 108 | } 109 | if (studentClassMapper.countByPrimaryKey(classId) == 0L) { 110 | throw new IdNotFoundException("班级ID不存在"); 111 | } 112 | Student student = studentMapper.selectByPrimaryKey(loginUser.getId()); 113 | if (Objects.isNull(student)) { 114 | // 新增 115 | Date date = new Date(); 116 | Student s = new Student(); 117 | s.setUserId(loginUser.getId()); 118 | s.setStudentClassId(classId); 119 | s.setGmtCreate(date); 120 | s.setGmtModified(date); 121 | studentMapper.insert(s); 122 | return s; 123 | } else { 124 | // 覆盖 125 | student.setGmtCreate(null); 126 | student.setStudentClassId(classId); 127 | student.setGmtModified(new Date()); 128 | studentMapper.updateByPrimaryKeySelective(student); 129 | return student; 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/com/project/selflearningplatformserver/service/impl/AttendanceServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.project.selflearningplatformserver.service.impl; 2 | 3 | import com.project.selflearningplatformserver.dto.AttendanceDTO; 4 | import com.project.selflearningplatformserver.dto.LoginUser; 5 | import com.project.selflearningplatformserver.dto.UserDTO; 6 | import com.project.selflearningplatformserver.entity.Attendance; 7 | import com.project.selflearningplatformserver.exception.IdNotFoundException; 8 | import com.project.selflearningplatformserver.exception.NullFiledException; 9 | import com.project.selflearningplatformserver.exception.SecurityServerException; 10 | import com.project.selflearningplatformserver.mapper.AttendanceMapper; 11 | import com.project.selflearningplatformserver.mapper.UserMapper; 12 | import com.project.selflearningplatformserver.service.AttendanceService; 13 | import com.project.selflearningplatformserver.util.OrikaUtils; 14 | import org.apache.commons.lang3.StringUtils; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.http.HttpStatus; 17 | import org.springframework.stereotype.Service; 18 | import org.springframework.transaction.annotation.Transactional; 19 | 20 | import java.time.LocalDate; 21 | import java.time.LocalDateTime; 22 | import java.time.ZoneId; 23 | import java.util.Date; 24 | import java.util.List; 25 | import java.util.Objects; 26 | import java.util.UUID; 27 | import java.util.stream.Collectors; 28 | 29 | /** 30 | * @author itning 31 | * @date 2020/5/1 22:38 32 | */ 33 | @Transactional(rollbackFor = Exception.class) 34 | @Service 35 | public class AttendanceServiceImpl implements AttendanceService { 36 | private final AttendanceMapper attendanceMapper; 37 | private final UserMapper userMapper; 38 | 39 | @Autowired 40 | public AttendanceServiceImpl(AttendanceMapper attendanceMapper, UserMapper userMapper) { 41 | this.attendanceMapper = attendanceMapper; 42 | this.userMapper = userMapper; 43 | } 44 | 45 | @Override 46 | public List getAllAttendances(String roleId) { 47 | return attendanceMapper.selectAllByUserRoleId(roleId) 48 | .stream() 49 | .map(attendance -> { 50 | AttendanceDTO attendanceDTO = OrikaUtils.a2b(attendance, AttendanceDTO.class); 51 | attendanceDTO.setUser(OrikaUtils.a2b(userMapper.selectByPrimaryKey(attendance.getUserId()), UserDTO.class)); 52 | return attendanceDTO; 53 | }) 54 | .collect(Collectors.toList()); 55 | } 56 | 57 | @Override 58 | public AttendanceDTO newAttendance(LoginUser loginUser) { 59 | if (attendanceMapper.countUserAttendanceInDate(loginUser.getId(), LocalDate.now()) != 0L) { 60 | throw new SecurityServerException("已经出勤", HttpStatus.BAD_REQUEST); 61 | } 62 | Date date = new Date(); 63 | Attendance attendance = new Attendance(); 64 | attendance.setId(UUID.randomUUID().toString()); 65 | attendance.setUserId(loginUser.getId()); 66 | attendance.setGmtCreate(date); 67 | attendance.setGmtModified(date); 68 | attendanceMapper.insert(attendance); 69 | AttendanceDTO attendanceDTO = OrikaUtils.a2b(attendance, AttendanceDTO.class); 70 | attendanceDTO.setUser(OrikaUtils.a2b(userMapper.selectByPrimaryKey(attendance.getUserId()), UserDTO.class)); 71 | return attendanceDTO; 72 | } 73 | 74 | @Override 75 | public AttendanceDTO newAttendance(String userId, LocalDateTime localDateTime) { 76 | if (attendanceMapper.countUserAttendanceInDate(userId, localDateTime.toLocalDate()) != 0L) { 77 | throw new SecurityServerException("该用户这天已经出勤了", HttpStatus.BAD_REQUEST); 78 | } 79 | Attendance attendance = new Attendance(); 80 | attendance.setId(UUID.randomUUID().toString()); 81 | attendance.setUserId(userId); 82 | attendance.setGmtCreate(new Date()); 83 | attendance.setGmtModified(Date.from(localDateTime.atZone(ZoneId.of("Asia/Shanghai")).toInstant())); 84 | attendanceMapper.insert(attendance); 85 | AttendanceDTO attendanceDTO = OrikaUtils.a2b(attendance, AttendanceDTO.class); 86 | attendanceDTO.setUser(OrikaUtils.a2b(userMapper.selectByPrimaryKey(attendance.getUserId()), UserDTO.class)); 87 | return attendanceDTO; 88 | } 89 | 90 | @Override 91 | public void delAttendance(String id) { 92 | if (StringUtils.isBlank(id)) { 93 | throw new NullFiledException("出勤ID为空"); 94 | } 95 | if (attendanceMapper.countByPrimaryKey(id) == 0L) { 96 | throw new IdNotFoundException("出勤ID不存在"); 97 | } 98 | attendanceMapper.deleteByPrimaryKey(id); 99 | } 100 | 101 | @Override 102 | public AttendanceDTO updateAttendance(String id, LocalDateTime localDateTime) { 103 | if (StringUtils.isBlank(id)) { 104 | throw new NullFiledException("出勤ID为空"); 105 | } 106 | Attendance attendance = attendanceMapper.selectByPrimaryKey(id); 107 | if (Objects.isNull(attendance)) { 108 | throw new IdNotFoundException("出勤ID不存在"); 109 | } 110 | Attendance att = new Attendance(); 111 | att.setId(id); 112 | att.setGmtModified(Date.from(localDateTime.atZone(ZoneId.of("Asia/Shanghai")).toInstant())); 113 | attendanceMapper.updateByPrimaryKeySelective(att); 114 | AttendanceDTO attendanceDTO = OrikaUtils.a2b(att, AttendanceDTO.class); 115 | attendanceDTO.setUser(OrikaUtils.a2b(userMapper.selectByPrimaryKey(attendance.getUserId()), UserDTO.class)); 116 | return attendanceDTO; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/resources/mappers/TeacherMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | id, user_id, attribute_key, attribute_value, gmt_create, gmt_modified 16 | 17 | 23 | 24 | delete 25 | from teacher 26 | where id = #{id,jdbcType=CHAR} 27 | 28 | 29 | insert into teacher (id, user_id, attribute_key, 30 | attribute_value, gmt_create, gmt_modified) 31 | values (#{id,jdbcType=CHAR}, #{userId,jdbcType=CHAR}, #{attributeKey,jdbcType=VARCHAR}, 32 | #{attributeValue,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}) 33 | 34 | 35 | insert into teacher 36 | 37 | 38 | id, 39 | 40 | 41 | user_id, 42 | 43 | 44 | attribute_key, 45 | 46 | 47 | attribute_value, 48 | 49 | 50 | gmt_create, 51 | 52 | 53 | gmt_modified, 54 | 55 | 56 | 57 | 58 | #{id,jdbcType=CHAR}, 59 | 60 | 61 | #{userId,jdbcType=CHAR}, 62 | 63 | 64 | #{attributeKey,jdbcType=VARCHAR}, 65 | 66 | 67 | #{attributeValue,jdbcType=VARCHAR}, 68 | 69 | 70 | #{gmtCreate,jdbcType=TIMESTAMP}, 71 | 72 | 73 | #{gmtModified,jdbcType=TIMESTAMP}, 74 | 75 | 76 | 77 | 78 | update teacher 79 | 80 | 81 | user_id = #{userId,jdbcType=CHAR}, 82 | 83 | 84 | attribute_key = #{attributeKey,jdbcType=VARCHAR}, 85 | 86 | 87 | attribute_value = #{attributeValue,jdbcType=VARCHAR}, 88 | 89 | 90 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 91 | 92 | 93 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, 94 | 95 | 96 | where id = #{id,jdbcType=CHAR} 97 | 98 | 99 | update teacher 100 | set user_id = #{userId,jdbcType=CHAR}, 101 | attribute_key = #{attributeKey,jdbcType=VARCHAR}, 102 | attribute_value = #{attributeValue,jdbcType=VARCHAR}, 103 | gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 104 | gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} 105 | where id = #{id,jdbcType=CHAR} 106 | 107 | 112 | 117 | 123 | --------------------------------------------------------------------------------