修改了从roller文件夹 #3

Closed
pav86znph wants to merge 0 commits from master into feature/lxh

23
.gitignore vendored

@ -1,23 +0,0 @@
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

8
.idea/.gitignore vendored

@ -1,8 +0,0 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="exam" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="exam" options="-parameters" />
</option>
</component>
</project>

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/backend/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8 (2)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/spring-boot-online-exam-master.iml" filepath="$PROJECT_DIR$/.idea/spring-boot-online-exam-master.iml" />
</modules>
</component>
</project>

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/web" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DdlMappings">
<mapping uuid="3f2269d9-40c7-4022-bc5b-913dfbbc6cdc" name="@localhost Mapping">
<data-sources db="52ce0e2c-1ca8-4087-a535-1632d84f6e81" ddl="7ee42c98-c0b3-46e7-9153-4802360edee6" />
</mapping>
</component>
</project>

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="PROJECT" dialect="MySQL" />
</component>
</project>

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -1,7 +0,0 @@
# build docker for project
FROM waterknife/centos-nginx-jdk8-mysql
WORKDIR /lsg/
COPY backend/target/*.jar ./app.jar
COPY entrypoint.sh ./
RUN chmod 777 entrypoint.sh
EXPOSE 9527

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2019 Liang Shan Guang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -1,18 +0,0 @@
ResultVO<RecordDetailVo> getExamRecordDetail(@PathVariable String recordId) {
// 定义返回结果
ResultVO<RecordDetailVo> resultVO;
try {
// 调用examService获取考试记录详情
RecordDetailVo recordDetailVo = examService.getRecordDetail(recordId);
// 返回成功结果
resultVO = new ResultVO<>(0, "获取考试记录详情成功", recordDetailVo);
} catch (Exception e) {
// 打印异常信息
e.printStackTrace();
// 返回失败结果
resultVO = new ResultVO<>(-1, "获取考试记录详情失败", null);
}
// 返回结果
return resultVO;
}
}

@ -1,6 +0,0 @@
.idea/
*.iml
src/main/resources/public
src/main/resources/static
target/
dist/

@ -1,52 +0,0 @@
# 在线考试系统的后端实现
## 拦截器注入application.yml中的属性
> 拦截器执行在自动bean初始化之前会导致拦截器中无法注入配置属性按照下面的步骤即可正常注入
+ 给拦截器加`@Component`注解
![拦截器注入配置文件属性](images/拦截器注入配置文件属性.png)
+ 在配置类中用`@Autowired`注入
![拦截器注入配置文件属性2](images/拦截器注入配置文件属性2.png)
## 代码调试的时候如何打印完整的SQL语句和参数
> 主要是指application.yml的配置
参考博客[JPA打印SQL参数](https://mp.weixin.qq.com/s/zyTOdTwFhi2CwxCI9P1kQw)
+ 打印SQL语句
```yaml
spring:
jpa:
# 调试的时候用用于打印完成SQL语句(但是不打印参数),联合下面的logging.level一同打印最完整的SQL信息(语句+参数)
show-sql: true
```
+ 不打印SQL语句
```yaml
spring:
jpa:
# 调试的时候用用于打印完成SQL语句(但是不打印参数),联合下面的logging.level一同打印最完整的SQL信息(语句+参数)
show-sql: false
```
+ 打印SQL参数
```yaml
# SQL语句打印(能打印参数设置为trace是打印完整语句默认我们就关掉吧)
logging:
level:
org.hibernate.type.descriptor.sql.BasicBinder: trace
```
+ 不打印SQL参数
```yaml
# SQL语句打印(能打印参数设置为trace是打印完整语句默认我们就关掉吧)
logging:
level:
org.hibernate.type.descriptor.sql.BasicBinder: off
```
## SpringBoot整合vue工程到static目录中遇到的问题
+ [Spring Boot整合Vue解决静态资源映射页面刷新失效路径配置等问题](https://blog.csdn.net/godelgnis/article/details/89683760)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

@ -1,96 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.huawei.l00379880</groupId>
<artifactId>exam</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>exam</name>
<description>基于SpringBoot的在线考试系统</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<!-- 常用Java工具类 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.5.10</version>
</dependency>
<!-- FastDFS文件服务器的客户端 -->
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.26.5</version>
</dependency>
<!-- FastDFS文件传输需要 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<!-- JWT相关 -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -1,12 +0,0 @@
package lsgwr.exam;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ExamApplication {
public static void main(String[] args) {
SpringApplication.run(ExamApplication.class, args);
}
}

@ -1,32 +0,0 @@
/***********************************************************
* @Description : 访
* @author : 广(Laing Shan Guang)
* @date : 2019-05-17 00:11
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@Slf4j
public class CORSConf {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
log.info("初始化 CORSConfiguration 配置");
registry.addMapping("/**")
.allowedHeaders("*")
.allowedMethods("*")
.allowedOrigins("*");
}
};
}
}

@ -1,27 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-22 08:21
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.config;
import lsgwr.exam.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class IntercepterConfig implements WebMvcConfigurer {
@Autowired
private LoginInterceptor loginInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 拦截user下的api
registry.addInterceptor(loginInterceptor).addPathPatterns("/api/**");
}
}

@ -1,19 +0,0 @@
package lsgwr.exam.config;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
@Configuration
public class ServletConfig {
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
return factory -> {
ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/");
factory.addErrorPages(error404Page);
};
}
}

@ -1,60 +0,0 @@
/***********************************************************
* @Description : Swagger2
* @author : 广(Laing Shan Guang)
* @date : 2019-05-15 07:39
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket api() {
ParameterBuilder ticketPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<>();
ticketPar.name("Access-Token").description("Rest接口权限认证token,无需鉴权可为空")
.modelRef(new ModelRef("string")).parameterType("header")
//header中的ticket参数非必填传空也可以
.required(false).build();
//根据每个方法名也知道当前方法在设置什么参数
pars.add(ticketPar.build());
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
// 自行修改为自己的包路径
.apis(RequestHandlerSelectors.basePackage("lsgwr"))
.paths(PathSelectors.any())
.build()
.globalOperationParameters(pars);
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("online exam by springboot")
.description("在线考试系统 by 梁山广 at 2021")
.termsOfServiceUrl("https://github.com/19920625lsg/spring-boot-online-exam")
.version("2.0")
.contact(new Contact("liangshanguang", "https://github.com/lsgwr/spring-boot-online-exam", "liangshanguang2@gmail.com"))
.build();
}
}

@ -1,5 +0,0 @@
/*
* Created By Liang Shan Guang at 2019-05-14 08:20
* Description :
*/
package lsgwr.exam.config;

@ -1,296 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-28 08:04
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.controller;
import lsgwr.exam.entity.Exam;
import lsgwr.exam.entity.ExamRecord;
import lsgwr.exam.service.ExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lsgwr.exam.vo.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
@RestController
@Api(tags = "Exam APIs")
@RequestMapping("/api/exam")
public class ExamController {
@Autowired
private ExamService examService;
@GetMapping("/question/all")
@ApiOperation("获取所有问题的列表")
// 获取全部问题列表
ResultVO<List<QuestionVo>> getQuestionAll() {
// 定义返回值
ResultVO<List<QuestionVo>> resultVO;
try {
// 调用examService获取全部问题列表
List<QuestionVo> questionAll = examService.getQuestionAll();
// 返回成功结果
resultVO = new ResultVO<>(0, "获取全部问题列表成功", questionAll);
} catch (Exception e) {
// 打印异常信息
e.printStackTrace();
// 返回失败结果
resultVO = new ResultVO<>(-1, "获取全部问题列表失败", null);
}
// 返回结果
return resultVO;
}
@PostMapping("/question/update")
@ApiOperation("更新问题")
ResultVO<QuestionVo> questionUpdate(@RequestBody QuestionVo questionVo) {
// 完成问题的更新
System.out.println(questionVo);
try {
// 调用examService的updateQuestion方法更新问题
QuestionVo questionVoResult = examService.updateQuestion(questionVo);
// 返回更新成功的结果
return new ResultVO<>(0, "更新问题成功", questionVoResult);
} catch (Exception e) {
// 打印异常信息
e.printStackTrace();
// 返回更新失败的结果
return new ResultVO<>(-1, "更新问题失败", null);
}
}
@PostMapping("/question/create")
@ApiOperation("创建问题")
ResultVO<String> questionCreate(@RequestBody QuestionCreateSimplifyVo questionCreateSimplifyVo, HttpServletRequest request) {
// 创建一个QuestionCreateVo对象
QuestionCreateVo questionCreateVo = new QuestionCreateVo();
// 把能拷贝过来的属性都拷贝过来
BeanUtils.copyProperties(questionCreateSimplifyVo, questionCreateVo);
// 设置创建者信息
String userId = (String) request.getAttribute("user_id");
questionCreateVo.setQuestionCreatorId(userId);
System.out.println(questionCreateVo);
try {
// 调用examService的questionCreate方法创建问题
examService.questionCreate(questionCreateVo);
// 返回问题创建成功的ResultVO
return new ResultVO<>(0, "问题创建成功", null);
} catch (Exception e) {
// 打印异常信息
e.printStackTrace();
// 返回创建问题失败的ResultVO
return new ResultVO<>(-1, "创建问题失败", null);
}
}
@GetMapping("/question/selection")
@ApiOperation("获取问题分类的相关选项")
// 获取问题分类选项
ResultVO<QuestionSelectionVo> getSelections() {
// 调用examService的getSelections方法获取问题分类选项
QuestionSelectionVo questionSelectionVo = examService.getSelections();
// 如果获取成功
if (questionSelectionVo != null) {
// 返回成功的结果
return new ResultVO<>(0, "获取问题分类选项成功", questionSelectionVo);
} else {
// 否则返回失败的结果
return new ResultVO<>(-1, "获取问题分类选项失败", null);
}
}
@GetMapping("/question/detail/{id}")
@ApiOperation("根据问题的id获取问题的详细信息")
ResultVO<QuestionDetailVo> getQuestionDetail(@PathVariable String id) {
// 根据问题id获取问题的详细信息
System.out.println(id);
ResultVO<QuestionDetailVo> resultVO;
try {
// 调用examService的getQuestionDetail方法根据问题id获取问题的详细信息
QuestionDetailVo questionDetailVo = examService.getQuestionDetail(id);
// 如果获取成功则返回ResultVO对象状态码为0提示信息为"获取问题详情成功"数据为questionDetailVo
resultVO = new ResultVO<>(0, "获取问题详情成功", questionDetailVo);
} catch (Exception e) {
// 如果获取失败则打印异常信息并返回ResultVO对象状态码为-1提示信息为"获取问题详情失败"数据为null
e.printStackTrace();
resultVO = new ResultVO<>(-1, "获取问题详情失败", null);
}
// 返回ResultVO对象
return resultVO;
}
@GetMapping("/all")
@ApiOperation("获取全部考试的列表")
ResultVO<List<ExamVo>> getExamAll() {
// 需要拼接前端需要的考试列表对象
ResultVO<List<ExamVo>> resultVO;
try {
// 调用examService的getExamAll方法获取全部考试的列表
List<ExamVo> examVos = examService.getExamAll();
// 将获取到的考试列表封装到ResultVO对象中并返回
resultVO = new ResultVO<>(0, "获取全部考试的列表成功", examVos);
} catch (Exception e) {
// 捕获异常,并打印异常信息
e.printStackTrace();
// 将异常信息封装到ResultVO对象中并返回
resultVO = new ResultVO<>(-1, "获取全部考试的列表失败", null);
}
return resultVO;
}
@GetMapping("/question/type/list")
@ApiOperation("获取问题列表,按照单选、多选和判断题分类返回")
ResultVO<ExamQuestionTypeVo> getExamQuestionTypeList() {
// 获取问题的分类列表
ResultVO<ExamQuestionTypeVo> resultVO;
try {
// 调用examService的getExamQuestionType方法获取问题分类列表
ExamQuestionTypeVo examQuestionTypeVo = examService.getExamQuestionType();
// 如果获取成功,则返回成功的结果
resultVO = new ResultVO<>(0, "获取问题列表成功", examQuestionTypeVo);
} catch (Exception e) {
// 如果获取失败,则打印异常信息,并返回失败的结果
e.printStackTrace();
resultVO = new ResultVO<>(-1, "获取问题列表失败", null);
}
// 返回结果
return resultVO;
}
@PostMapping("/create")
@ApiOperation("创建考试")
ResultVO<Exam> createExam(@RequestBody ExamCreateVo examCreateVo, HttpServletRequest request) {
// 从前端传参数过来,在这里完成考试的入库
ResultVO<Exam> resultVO;
// 获取当前用户的id
String userId = (String) request.getAttribute("user_id");
try {
// 调用examService的create方法将examCreateVo和userId作为参数传入创建考试
Exam exam = examService.create(examCreateVo, userId);
// 创建一个ResultVO对象将创建成功的考试信息返回
resultVO = new ResultVO<>(0, "创建考试成功", exam);
} catch (Exception e) {
// 捕获异常打印异常信息并创建一个ResultVO对象将创建失败的考试信息返回
e.printStackTrace();
resultVO = new ResultVO<>(-1, "创建考试失败", null);
}
// 返回ResultVO对象
return resultVO;
}
@PostMapping("/update")
@ApiOperation("更新考试")
ResultVO<Exam> updateExam(@RequestBody ExamVo examVo, HttpServletRequest request) {
// 从前端传参数过来,在这里完成考试的入库
ResultVO<Exam> resultVO;
// 获取当前用户id
String userId = (String) request.getAttribute("user_id");
try {
// 调用service层更新考试
Exam exam = examService.update(examVo, userId);
// 返回更新成功的resultVO
resultVO = new ResultVO<>(0, "更新考试成功", exam);
} catch (Exception e) {
// 打印异常信息
e.printStackTrace();
// 返回更新失败的resultVO
resultVO = new ResultVO<>(-1, "更新考试失败", null);
}
return resultVO;
}
@GetMapping("/card/list")
@ApiOperation("获取考试列表,适配前端卡片列表")
ResultVO<List<ExamCardVo>> getExamCardList() {
// 获取考试列表卡片
ResultVO<List<ExamCardVo>> resultVO;
try {
// 调用examService的getExamCardList方法获取考试列表卡片
List<ExamCardVo> examCardVoList = examService.getExamCardList();
// 如果获取成功,则返回成功的结果
resultVO = new ResultVO<>(0, "获取考试列表卡片成功", examCardVoList);
} catch (Exception e) {
// 如果获取失败,则打印异常信息,并返回失败的结果
e.printStackTrace();
resultVO = new ResultVO<>(-1, "获取考试列表卡片失败", null);
}
// 返回结果
return resultVO;
}
@GetMapping("/detail/{id}")
@ApiOperation("根据考试的id获取考试详情")
ResultVO<ExamDetailVo> getExamDetail(@PathVariable String id) {
// 根据id获取考试详情
ResultVO<ExamDetailVo> resultVO;
try {
ExamDetailVo examDetail = examService.getExamDetail(id);
resultVO = new ResultVO<>(0, "获取考试详情成功", examDetail);
} catch (Exception e) {
resultVO = new ResultVO<>(-1, "获取考试详情失败", null);
}
return resultVO;
}
@PostMapping("/finish/{examId}")
@ApiOperation("根据用户提交的答案对指定id的考试判分")
// 完成考试
ResultVO<ExamRecord> finishExam(@PathVariable String examId, @RequestBody HashMap<String, List<String>> answersMap, HttpServletRequest request) {
// 定义返回结果
ResultVO<ExamRecord> resultVO;
try {
// 拦截器里设置上的用户id
String userId = (String) request.getAttribute("user_id");
// 下面根据用户提交的信息进行判分,返回用户的得分情况
ExamRecord examRecord = examService.judge(userId, examId, answersMap);
// 返回结果
resultVO = new ResultVO<>(0, "考卷提交成功", examRecord);
} catch (Exception e) {
e.printStackTrace();
// 返回错误结果
resultVO = new ResultVO<>(-1, "考卷提交失败", null);
}
return resultVO;
}
@GetMapping("/record/list")
@ApiOperation("获取当前用户的考试记录")
// 获取考试记录列表
ResultVO<List<ExamRecordVo>> getExamRecordList(HttpServletRequest request) {
ResultVO<List<ExamRecordVo>> resultVO;
try {
// 拦截器里设置上的用户id
String userId = (String) request.getAttribute("user_id");
// 下面根据用户账号拿到他(她所有的考试信息)注意要用VO封装下
List<ExamRecordVo> examRecordVoList = examService.getExamRecordList(userId);
resultVO = new ResultVO<>(0, "获取考试记录成功", examRecordVoList);
} catch (Exception e) {
e.printStackTrace();
resultVO = new ResultVO<>(-1, "获取考试记录失败", null);
}
return resultVO;
}
@GetMapping("/record/detail/{recordId}")
@ApiOperation("根据考试记录id获取考试记录详情")
ResultVO<RecordDetailVo> getExamRecordDetail(@PathVariable String recordId) {
// 定义返回结果
ResultVO<RecordDetailVo> resultVO;
try {
// 调用examService获取考试记录详情
RecordDetailVo recordDetailVo = examService.getRecordDetail(recordId);
// 返回成功结果
resultVO = new ResultVO<>(0, "获取考试记录详情成功", recordDetailVo);
} catch (Exception e) {
// 打印异常信息
e.printStackTrace();
// 返回失败结果
resultVO = new ResultVO<>(-1, "获取考试记录详情失败", null);
}
// 返回结果
return resultVO;
}
}

@ -1,90 +0,0 @@
package lsgwr.exam.controller;
import lsgwr.exam.qo.DownloadQo;
import lsgwr.exam.qo.UploadModel;
import lsgwr.exam.qo.UploadModel2;
import lsgwr.exam.utils.FileTransUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
/***********************************************************
* @note : ,SwaggerSwaggerUI
*
* @author : 广
* * AjaxResponseEntity
* *
* * 1. - `MultipartFile`
* * 2. - `MultipartFile []`
* * 3. - `@ModelAttribute`
* @version : V1.0 at 2018/7/16 20:43
***********************************************************/
@RestController
@Api(tags = "Upload And Download APIs")
@RequestMapping("/api/file")
@Slf4j
public class UploadDownloadController {
// @Autowired
// AITestConfig aiTestConfig;
//
// @PostMapping("/upload/single")
// @ApiOperation("单文件上传")
// public String uploadFile(@RequestParam("file") MultipartFile uploadfile) {
// return FileTransUtil.uploadFile(uploadfile, "/root/" + File.separator + uploadfile.getOriginalFilename());
// }
@ApiOperation("单文件上传,支持同时传入参数")
@PostMapping("/api/upload/singleAndparas")
// 单文件上传
public String uploadFileSingle(@RequestParam("dir") String dir, @RequestParam("file") MultipartFile uploadfile) {
// 调用FileTransUtil工具类中的uploadFile方法将上传的文件和目录作为参数传入
return FileTransUtil.uploadFile(uploadfile, dir);
}
// 单文件上传支持同时传入参数Model
@ApiOperation("单文件上传,支持同时传入参数,Model")
@PostMapping("/upload/single/model")
public String singleUploadFileModel(@ModelAttribute("model") UploadModel2 model) {
// 调用FileTransUtil工具类中的uploadFile方法将上传的文件和目录作为参数传入
return FileTransUtil.uploadFile(model.getFile(), model.getDir());
}
// 多文件上传,支持同时传入参数
@ApiOperation("多文件上传,支持同时传入参数")
@PostMapping("upload/multiAndparas")
public String uploadFileMulti(@RequestParam("dir") String dir, @RequestParam("files") MultipartFile[] uploadfiles) {
// 调用FileTransUtil工具类中的uploadFiles方法将上传的文件数组和目录作为参数传入
return FileTransUtil.uploadFiles(uploadfiles, dir);
}
// 多文件上传,支持同时传入参数
@ApiOperation("多文件上传,支持同时传入参数")
@PostMapping(value = "/upload/multi/model")
public String multiUploadFileModel(@ModelAttribute(("model")) UploadModel model) {
// 调用FileTransUtil工具类中的uploadFiles方法将上传的文件数组和目录作为参数传入
return FileTransUtil.uploadFiles(model.getFiles(), model.getDir());
}
// Get下载文件
@ApiOperation("Get下载文件")
@GetMapping(value = "/download/get")
public ResponseEntity<InputStreamResource> downloadFileGet(@RequestParam String filePath) throws IOException {
// 调用FileTransUtil工具类中的downloadFile方法将文件路径作为参数传入
return FileTransUtil.downloadFile(filePath);
}
// Post下载文件
@ApiOperation("Post下载文件")
@PostMapping(value = "/download/post")
public ResponseEntity<InputStreamResource> downloadFilePost(@RequestBody DownloadQo downloadQo) throws IOException {
// 调用FileTransUtil工具类中的downloadFile方法将文件路径作为参数传入
return FileTransUtil.downloadFile(downloadQo.getPath());
}
}

@ -1,10 +0,0 @@
// 使用Spring Boot框架
@SpringBootApplication
public class ExamApplication {
// 主方法
public static void main(String[] args) {
// 运行Spring Boot应用程序
SpringApplication.run(ExamApplication.class, args);
}
}

@ -1,5 +0,0 @@
/*
* Created By Liang Shan Guang at 2019-05-14 08:20
* Description : REST
*/
package lsgwr.exam.controller;

@ -1,21 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-16 23:40
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.dto;
import lombok.Data;
@Data
public class RegisterDTO {
private String email;
private String password;
private String password2;
private String mobile;
/**
*
*/
private String captcha;
}

@ -1,5 +0,0 @@
/*
* Created By Liang Shan Guang at 2019-05-16 23:38
* Description :
*/
package lsgwr.exam.dto;

@ -1,27 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-26 12:31
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Data
@Entity
public class Action {
@Id
@GeneratedValue
private Integer actionId;
private String actionName;
private String actionDescription;
private Boolean defaultCheck;
}

@ -1,55 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:42
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;
@Entity
@Data
@DynamicUpdate
public class Exam {
@Id
private String examId;
private String examName;
private String examAvatar;
private String examDescription;
private String examQuestionIds;
private String examQuestionIdsRadio;
private String examQuestionIdsCheck;
private String examQuestionIdsJudge;
private Integer examScore;
private Integer examScoreRadio;
private Integer examScoreCheck;
private Integer examScoreJudge;
private String examCreatorId;
private Integer examTimeLimit;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date examStartDate;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date examEndDate;
/**
* , Java
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**
* Java
* @DynamicUpdate
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}

@ -1,56 +0,0 @@
/***********************************************************
* @Description : id()
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:43
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;
@Data
@Entity
public class ExamRecord {
/**
*
*/
@Id
private String examRecordId;
/**
* id
*/
private String examId;
/**
* (_-),
*/
private String answerOptionIds;
/**
* userid
*/
private String examJoinerId;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date examJoinDate;
/**
* ()
*/
private Integer examTimeCost;
/**
*
*/
private Integer examJoinScore;
/**
*
*/
private Integer examResultLevel;
}

@ -1,24 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:44
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Data
@Entity
public class ExamRecordLevel {
@Id
@GeneratedValue
private Integer examRecordLevelId;
private String examRecordLevelName;
private String examRecordLevelDescription;
}

@ -1,27 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-26 12:30
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Data
@Entity
public class Page {
@Id
@GeneratedValue
private Integer pageId;
private String pageName;
private String pageDescription;
private String actionIds;
}

@ -1,46 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:46
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;
@Data
@Entity
@DynamicUpdate
public class Question {
@Id
private String questionId;
private String questionName;
private Integer questionScore;
private String questionCreatorId;
private Integer questionLevelId;
private Integer questionTypeId;
private Integer questionCategoryId;
private String questionDescription;
private String questionOptionIds;
private String questionAnswerOptionIds;
/**
* , Java
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**
* Java
* @DynamicUpdate
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}

@ -1,31 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:46
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Data
@Entity
public class QuestionCategory {
@Id
@GeneratedValue
@JsonProperty("id")
private Integer questionCategoryId;
@JsonProperty("name")
private String questionCategoryName;
@JsonProperty("description")
private String questionCategoryDescription;
}

@ -1,30 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:47
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
@Data
public class QuestionLevel {
@Id
@GeneratedValue
@JsonProperty("id")
private Integer questionLevelId;
@JsonProperty("name")
private String questionLevelName;
@JsonProperty("description")
private String questionLevelDescription;
}

@ -1,22 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:48
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.Id;
@Data
@Entity
public class QuestionOption {
@Id
private String questionOptionId;
private String questionOptionContent;
private String questionOptionDescription;
}

@ -1,30 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:48
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Data
@Entity
public class QuestionType {
@Id
@GeneratedValue
@JsonProperty("id")
private Integer questionTypeId;
@JsonProperty("name")
private String questionTypeName;
@JsonProperty("description")
private String questionTypeDescription;
}

@ -1,29 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:49
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Data
@Entity
public class Role {
@Id
@GeneratedValue
private Integer roleId;
private String roleName;
private String roleDescription;
private String roleDetail;
/**
* 访(-)
*/
private String rolePageIds;
}

@ -1,45 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:49
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;
@Data
@Entity
@DynamicUpdate
public class User {
@Id
private String userId;
private String userUsername;
private String userNickname;
private String userPassword;
private Integer userRoleId;
private String userAvatar;
private String userDescription;
private String userEmail;
private String userPhone;
/**
* , Java
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**
* Java
* @DynamicUpdate
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}

@ -1,5 +0,0 @@
/*
* Created By Liang Shan Guang at 2019-05-14 00:34
* Description :
*/
package lsgwr.exam.entity;

@ -1,25 +0,0 @@
package lsgwr.exam.enums;
import lombok.Getter;
/**
*
* @author liangshanguang
*/
@Getter
public enum LoginTypeEnum {
/**
* 12
*/
USERNAME(1, "用户名"),
EMAIL(2, "邮箱");
LoginTypeEnum(Integer type, String name) {
this.type = type;
this.name = name;
}
private Integer type;
private String name;
}

@ -1,29 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-18 12:00
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.enums;
import lombok.Getter;
@Getter
public enum QuestionEnum {
/**
*
*/
RADIO(1, "单选题"),
CHECK(2, "多选题"),
JUDGE(3, "判断题");
QuestionEnum(Integer id, String role) {
this.id = id;
this.role = role;
}
private Integer id;
private String role;
}

@ -1,27 +0,0 @@
package lsgwr.exam.enums;
import lombok.Getter;
@Getter
public enum ResultEnum {
// 下面是本项目用到的所有错误码
REGISTER_SUCCESS(0, "注册成功"),
REGISTER_FAILED(-2, "注册失败"),
LOGIN_SUCCESS(0, "登录成功"),
LOGIN_FAILED(-1, "用户名或者密码错误"),
GET_INFO_SUCCESS(0, "获取用户信息成功"),
PARAM_ERR(1, "参数不正确"),
PRODUCT_NOT_EXIST(10, "用户不存在"),
PRODUCT_STOCK_ERR(11, "考试信息异常"),
ORDER_STATUS_ERR(14, "考试状态异常"),
ORDER_UPDATE_ERR(15, "考试更新异常"),
ORDER_DETAIL_EMPTY(16, "用户详情为空");
ResultEnum(Integer code, String message) {
this.code = code;
this.message = message;
}
private Integer code;
private String message;
}

@ -1,29 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-18 12:00
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.enums;
import lombok.Getter;
@Getter
public enum RoleEnum {
/**
* role
*/
ADMIN(1, "管理员"),
TEACHER(2, "教师"),
STUDENT(3, "学生");
RoleEnum(Integer id, String role) {
this.id = id;
this.role = role;
}
private Integer id;
private String role;
}

@ -1,25 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-17 07:50
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.exception;
import lsgwr.exam.enums.ResultEnum;
import lombok.Getter;
@Getter
public class ExamException extends RuntimeException {
private Integer code;
public ExamException(ResultEnum resultEnum) {
super(resultEnum.getMessage());
this.code = resultEnum.getCode();
}
public ExamException( Integer code, String message) {
super(message);
this.code = code;
}
}

@ -1,5 +0,0 @@
/*
* Created By Liang Shan Guang at 2019-05-17 07:51
* Description :
*/
package lsgwr.exam.exception;

@ -1,99 +0,0 @@
/***********************************************************
* @Description : Token
* @author : 广(Laing Shan Guang)
* @date : 2019-05-22 07:35
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.interceptor;
import com.google.gson.Gson;
import lsgwr.exam.utils.JwtUtils;
import lsgwr.exam.vo.JsonData;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
/**
* https://stackoverflow.com/questions/43591582/application-properties-value-in-spring-boot-interceptor
*
* @author liangshanguang
*/
@Component
public class LoginInterceptor implements HandlerInterceptor {
/**
* @Component使pplication.yml
*/
@Value("${interceptors.auth-ignore-uris}")
private String authIgnoreUris;
/**
* controller
*
* @param request
* @param response
* @param handler
* @return
* @throws Exception
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("进入拦截器啦!");
String uri = request.getRequestURI();
System.out.println(uri);
System.out.println("无需拦截的接口路径:" + authIgnoreUris);
String[] authIgnoreUriArr = authIgnoreUris.split(",");
// 登录和注册接口不需要进行token拦截和校验
for (String authIgnoreUri : authIgnoreUriArr) {
if (authIgnoreUri.equals(uri)) {
return true;
}
}
// 注意要和前端适配Access-Token属性前端会在登陆后的每个接口请求头加Access-Token属性
String token = request.getHeader("Access-Token");
if (token == null) {
// token不在header中时也可能在参数中(RequestParam)
token = request.getParameter("token");
}
if (token != null) {
// 请求中是携带参数的
Claims claims = JwtUtils.checkJWT(token);
if (claims == null) {
// 返回null说明用户篡改了token导致校验失败
sendJsonMessage(response, JsonData.buildError("token无效请重新登录"));
return false;
}
// 用户的的主键id
String id = (String) claims.get("id");
// 用户名
String username = (String) claims.get("username");
// 把这两个参数放到请求中从而可以在controller中获取到不需要在controller中在用Jwt解密了,request.getAttribute("属性名")即可获取
request.setAttribute("user_id", id);
request.setAttribute("username", username);
return true;
}
sendJsonMessage(response, JsonData.buildError("token为null,请先登录!"));
return false;
}
/**
*
*
* @param response
* @param obj
* @throws Exception
*/
public static void sendJsonMessage(HttpServletResponse response, Object obj) throws Exception {
Gson g = new Gson();
response.setContentType("application/json; charset=utf-8");
PrintWriter writer = response.getWriter();
writer.print(g.toJson(obj));
writer.close();
response.flushBuffer();
}
}

@ -1,17 +0,0 @@
package lsgwr.exam.qo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/***********************************************************
* @note :
* @author : 广
* @version : V1.0 at 2019/5/19 20:10
***********************************************************/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DownloadQo {
String path;
}

@ -1,29 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-19 20:18
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.qo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LoginQo {
/**
* 12
*/
private Integer loginType;
/**
* /
*/
private String userInfo;
/**
*
*/
private String password;
}

@ -1,27 +0,0 @@
package lsgwr.exam.qo;
/***********************************************************
* @Description :
* @author : 广
* @date : 2017/8/19 15:51
* @version : V1.0
***********************************************************/
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.web.multipart.MultipartFile;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UploadModel {
/**
*
*/
private MultipartFile[] files;
/**
*
*/
private String dir;
}

@ -1,27 +0,0 @@
package lsgwr.exam.qo;
/***********************************************************
* @Description :
* @author : 广
* @date : 2018/5/19 15:51
* @version : V1.0
***********************************************************/
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.web.multipart.MultipartFile;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UploadModel2 {
/**
*
*/
private MultipartFile file;
/**
*
*/
private String dir;
}

@ -1,6 +0,0 @@
/***********************************************************
* @note : (Query Object)
* @author : 广
* @version : V1.0 at 2018/7/18 17:32
***********************************************************/
package lsgwr.exam.qo;

@ -1,13 +0,0 @@
/***********************************************************
* @Description : Action
* @author : 广(Laing Shan Guang)
* @date : 2019-05-26 12:39
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.Action;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ActionRepository extends JpaRepository<Action, Integer> {
}

@ -1,13 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-14 08:24
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.ExamRecordLevel;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ExamRecordLevelRepository extends JpaRepository<ExamRecordLevel, Integer> {
}

@ -1,22 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-14 08:23
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.ExamRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface ExamRecordRepository extends JpaRepository<ExamRecord, String> {
/**
*
*
* @param userId id
* @return
*/
List<ExamRecord> findByExamJoinerIdOrderByExamJoinDateDesc(String userId);
}

@ -1,18 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-14 08:22
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.Exam;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface ExamRepository extends JpaRepository<Exam, String> {
@Query("select e from Exam e order by e.updateTime desc")
List<Exam> findAll();
}

@ -1,13 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-26 12:41
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.Page;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PageRepository extends JpaRepository<Page, Integer> {
}

@ -1,13 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-14 08:25
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.QuestionCategory;
import org.springframework.data.jpa.repository.JpaRepository;
public interface QuestionCategoryRepository extends JpaRepository<QuestionCategory, Integer> {
}

@ -1,13 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-14 08:26
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.QuestionLevel;
import org.springframework.data.jpa.repository.JpaRepository;
public interface QuestionLevelRepository extends JpaRepository<QuestionLevel, Integer> {
}

@ -1,13 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-14 08:27
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.QuestionOption;
import org.springframework.data.jpa.repository.JpaRepository;
public interface QuestionOptionRepository extends JpaRepository<QuestionOption, String> {
}

@ -1,19 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-14 08:25
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.Question;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface QuestionRepository extends JpaRepository<Question, String> {
List<Question> findByQuestionTypeId(Integer id);
@Query("select q from Question q order by q.updateTime desc")
List<Question> findAll();
}

@ -1,13 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-14 08:28
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.QuestionType;
import org.springframework.data.jpa.repository.JpaRepository;
public interface QuestionTypeRepository extends JpaRepository<QuestionType, Integer> {
}

@ -1,13 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-14 08:29
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
public interface RoleRepository extends JpaRepository<Role, Integer> {
}

@ -1,28 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-14 08:30
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.repository;
import lsgwr.exam.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, String> {
/**
*
*
* @param username
* @return (unique 1)
*/
User findByUserUsername(String username);
/**
*
*
* @param email
* @return (unique 1)
*/
User findByUserEmail(String email);
}

@ -1,5 +0,0 @@
/*
* Created By Liang Shan Guang at 2019-05-14 08:20
* Description :
*/
package lsgwr.exam.repository;

@ -1,122 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-28 08:05
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.service;
import lsgwr.exam.entity.Exam;
import lsgwr.exam.entity.ExamRecord;
import lsgwr.exam.vo.*;
import java.util.HashMap;
import java.util.List;
public interface ExamService {
/**
*
*/
List<QuestionVo> getQuestionAll();
/**
*
*
* @param questionVo
*/
QuestionVo updateQuestion(QuestionVo questionVo);
/**
*
*
* @param questionCreateVo
*/
void questionCreate(QuestionCreateVo questionCreateVo);
/**
*
*
* @return
*/
QuestionSelectionVo getSelections();
/**
*
*
* @param id id
* @return VO
*/
QuestionDetailVo getQuestionDetail(String id);
/**
*
*/
List<ExamVo> getExamAll();
/**
* 便
*
* @return
*/
ExamQuestionTypeVo getExamQuestionType();
/**
*
*
* @param examCreateVo
* @param userId id
* @return
*/
Exam create(ExamCreateVo examCreateVo, String userId);
/**
*
*
* @return
*/
List<ExamCardVo> getExamCardList();
/**
* id
*
* @param id exam
* @return VO
*/
ExamDetailVo getExamDetail(String id);
/**
*
*
* @param userId
* @param examId
* @param answersMap
* @return
*/
ExamRecord judge(String userId, String examId, HashMap<String, List<String>> answersMap);
/**
* id
*
* @param userId id
* @return
*/
List<ExamRecordVo> getExamRecordList(String userId);
/**
*
*
* @param recordId id
* @return
*/
RecordDetailVo getRecordDetail(String recordId);
/**
*
*
* @param examVo
* @param userId
* @return
*/
Exam update(ExamVo examVo, String userId);
}

@ -1,45 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-17 08:02
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.service;
import lsgwr.exam.dto.RegisterDTO;
import lsgwr.exam.entity.User;
import lsgwr.exam.qo.LoginQo;
import lsgwr.exam.vo.UserInfoVo;
import lsgwr.exam.vo.UserVo;
public interface UserService {
/**
*
*
* @param registerDTO
* @return
*/
User register(RegisterDTO registerDTO);
/**
* token
*
* @param loginQo
* @return tokennull
*/
String login(LoginQo loginQo);
/**
* id
*
* @return
*/
UserVo getUserInfo(String userId);
/**
* ()
* @param userId id
* @return
*/
UserInfoVo getInfo(String userId);
}

@ -1,13 +0,0 @@
public class ActionVo {
// 使用@JsonProperty注解将actionName属性映射到JSON中的action字段
@JsonProperty("action")
private String actionName;
// 使用@JsonProperty注解将actionDescription属性映射到JSON中的describe字段
@JsonProperty("describe")
private String actionDescription;
// 使用@JsonProperty注解将defaultCheck属性映射到JSON中的defaultCheck字段
@JsonProperty("defaultCheck")
private Boolean defaultCheck;
}

@ -1,174 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-17 08:03
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.service.impl;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.IdUtil;
import lsgwr.exam.dto.RegisterDTO;
import lsgwr.exam.entity.Action;
import lsgwr.exam.entity.Page;
import lsgwr.exam.entity.Role;
import lsgwr.exam.entity.User;
import lsgwr.exam.enums.LoginTypeEnum;
import lsgwr.exam.enums.RoleEnum;
import lsgwr.exam.qo.LoginQo;
import lsgwr.exam.repository.ActionRepository;
import lsgwr.exam.repository.PageRepository;
import lsgwr.exam.repository.RoleRepository;
import lsgwr.exam.repository.UserRepository;
import lsgwr.exam.service.UserService;
import lsgwr.exam.utils.JwtUtils;
import lsgwr.exam.vo.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service
@Transactional
public class UserServiceImpl implements UserService {
@Autowired
UserRepository userRepository;
@Autowired
RoleRepository roleRepository;
@Autowired
PageRepository pageRepository;
@Autowired
ActionRepository actionRepository;
@Override
public User register(RegisterDTO registerDTO) {
try {
User user = new User();
user.setUserId(IdUtil.simpleUUID());
// 好像还缺少个用户名,用"exam_user_手机号"来注册需要校验唯一性数据字段已经设置unique了失败会异常地
String defaultUsername = "user";
user.setUserUsername(defaultUsername + "_" + registerDTO.getMobile());
// 初始化昵称和用户名相同
user.setUserNickname(user.getUserUsername());
// 这里还需要进行加密处理后续解密用Base64.decode()
user.setUserPassword(Base64.encode(registerDTO.getPassword()));
// 默认设置为学生身份,需要老师和学生身份地话需要管理员修改
user.setUserRoleId(RoleEnum.STUDENT.getId());
// 设置头像图片地址, 先默认一个地址,后面用户可以自己再改
String defaultAvatar = "http://d.lanrentuku.com/down/png/1904/business_avatar/8_avatar_2754583.png";
user.setUserAvatar(defaultAvatar);
// 设置描述信息,随便设置段默认的
user.setUserDescription("welcome to online exam system");
// 需要验证这个邮箱是不是已经存在数据字段已经设置unique了失败会异常地
user.setUserEmail(registerDTO.getEmail());
// 需要验证手机号是否已经存在数据字段已经设置unique了失败会异常地
user.setUserPhone(registerDTO.getMobile());
userRepository.save(user);
System.out.println(user);
return user;
} catch (Exception e) {
e.printStackTrace(); // 用户已经存在
// 出异常返回null表示注册失败
return null;
}
}
@Override
public String login(LoginQo loginQo) {
User user;
if (LoginTypeEnum.USERNAME.getType().equals(loginQo.getLoginType())) {
// 登陆者用地是用户名
user = userRepository.findByUserUsername(loginQo.getUserInfo());
} else {
// 登陆者用地是邮箱
user = userRepository.findByUserEmail(loginQo.getUserInfo());
}
if (user != null) {
// 如果user不是null即能找到才能验证用户名和密码
// 数据库存的密码
String passwordDb = Base64.decodeStr(user.getUserPassword());
// 用户请求参数中的密码
String passwordQo = loginQo.getPassword();
System.out.println(passwordDb);
System.out.println(passwordQo);
if (passwordQo.equals(passwordDb)) {
// 如果密码相等地话说明认证成功,返回生成的token有效期为一天
return JwtUtils.genJsonWebToken(user);
}
}
return null;
}
@Override
public UserVo getUserInfo(String userId) {
User user = userRepository.findById(userId).orElse(null);
UserVo userVo = new UserVo();
assert user != null;
BeanUtils.copyProperties(user, userVo);
return userVo;
}
@Override
public UserInfoVo getInfo(String userId) {
User user = userRepository.findById(userId).orElse(null);
assert user != null;
UserInfoVo userInfoVo = new UserInfoVo();
// 1.尽可能的拷贝属性
BeanUtils.copyProperties(user, userInfoVo);
Integer roleId = user.getUserRoleId();
Role role = roleRepository.findById(roleId).orElse(null);
assert role != null;
String roleName = role.getRoleName();
// 2.设置角色名称
userInfoVo.setRoleName(roleName);
// 3.设置当前用户的角色细节
RoleVo roleVo = new RoleVo();
BeanUtils.copyProperties(role, roleVo);
// 4.设置角色的可访问页面
String rolePageIds = role.getRolePageIds();
String[] pageIdArr = rolePageIds.split("-");
List<PageVo> pageVoList = new ArrayList<>();
for (String pageIdStr : pageIdArr) {
// 获取页面的id
Integer pageId = Integer.parseInt(pageIdStr);
// 4.1 向Role中添加Page
Page page = pageRepository.findById(pageId).orElse(null);
PageVo pageVo = new PageVo();
BeanUtils.copyProperties(page, pageVo);
// 4.2 向Page中添加action
List<ActionVo> actionVoList = new ArrayList<>();
String actionIdsStr = page.getActionIds();
String[] actionIdArr = actionIdsStr.split("-");
for (String actionIdStr : actionIdArr) {
Integer actionId = Integer.parseInt(actionIdStr);
Action action = actionRepository.findById(actionId).orElse(null);
ActionVo actionVo = new ActionVo();
assert action != null;
BeanUtils.copyProperties(action, actionVo);
actionVoList.add(actionVo);
}
// 设置actionVoList到pageVo中然后把pageVo加到pageVoList中
pageVo.setActionVoList(actionVoList);
// 设置pageVoList下面再设置到RoleVo中
pageVoList.add(pageVo);
}
// 设置PageVo的集合到RoleVo中
roleVo.setPageVoList(pageVoList);
// 最终把PageVo设置到UserInfoVo中这样就完成了拼接
userInfoVo.setRoleVo(roleVo);
return userInfoVo;
}
}

@ -1,5 +0,0 @@
/*
* Created By Liang Shan Guang at 2019-05-14 08:20
* Description :
*/
package lsgwr.exam.service;

@ -1,126 +0,0 @@
package lsgwr.exam.utils;
import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/***********************************************************
* @note :
* @author : 广
* @version : V1.0 at 2019/5/19 16:15
***********************************************************/
@Slf4j
public class FileTransUtil {
/**
*
*
* @param uploadfile
* @param dir
* @return
*/
public static String uploadFile(MultipartFile uploadfile, String dir) {
log.info("Single file upload!");
if (uploadfile.isEmpty()) {
return "文件名不能为空";
}
try {
saveUploadedFiles(Arrays.asList(uploadfile), dir);
} catch (IOException e) {
e.printStackTrace();
return "后台服务异常";
}
log.info("file upload successfully! " + dir);
return "文件上传成功";
}
/**
*
*
* @param uploadfiles
* @param dir
* @return
*/
public static String uploadFiles(MultipartFile[] uploadfiles, String dir) {
log.debug("Multiple file upload!");
String uploadedFileName = Arrays.stream(uploadfiles).map(x -> x.getOriginalFilename()).filter(x -> !StringUtils.isEmpty(x)).collect(Collectors.joining(" , "));
if (StringUtils.isEmpty(uploadedFileName)) {
return "文件名不能为空";
}
try {
FileTransUtil.saveUploadedFiles(Arrays.asList(uploadfiles), dir);
} catch (IOException e) {
return "后台服务异常";
}
log.info("file upload successfully! " + uploadedFileName);
return "文件上传成功";
}
/**
*
*
* @param files
* @throws IOException
*/
public static void saveUploadedFiles(List<MultipartFile> files, String dir) throws IOException {
for (MultipartFile file : files) {
if (file.isEmpty()) {
continue;
}
if (!FileUtil.exist(dir)) {
// 文件夹不存在就创建
FileUtil.mkdir(dir);
}
byte[] bytes = file.getBytes();
String fileName = file.getOriginalFilename().replace("\\", "/");
if (fileName.lastIndexOf('/')>0){
// 上传文件夹的时候会有这种情况
String fileDir = dir + "/" + fileName.substring(0, fileName.lastIndexOf('/'));
if (!FileUtil.exist(fileDir)) {
// 文件夹不存在就创建,创建文件夹的时候会用到
FileUtil.mkdir(fileDir);
}
}
Path path = Paths.get(dir + "/" + fileName);
Files.write(path, bytes);
}
}
/**
*
*
* @param filePath
* @return
* @throws IOException
*/
public static ResponseEntity<InputStreamResource> downloadFile(String filePath) throws IOException {
log.info("downloading file : " + filePath);
FileSystemResource file = new FileSystemResource(filePath);
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", String.format("attachment; filename=\"%s\"", new String(file.getFilename().getBytes("gbk"), "iso-8859-1")));
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
System.out.println(file.getFilename());
return ResponseEntity
.ok()
.headers(headers)
.contentLength(file.contentLength())
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(file.getInputStream()));
}
}

@ -1,156 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-19 10:27
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.utils;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.util.Base64Utils;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
@Service
public class FileUtils {
/**
* urlfile
*
* @param url
* @param suffix
*/
public static File createFileByUrl(String url, String suffix) {
byte[] byteFile = getImageFromNetByUrl(url);
if (byteFile != null) {
File file = getFileFromBytes(byteFile, suffix);
return file;
} else {
return null;
}
}
/**
*
*
* @param strUrl
* @return
*/
private static byte[] getImageFromNetByUrl(String strUrl) {
try {
URL url = new URL(strUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
// 通过输入流获取图片数据
InputStream inStream = conn.getInputStream();
// 得到图片的二进制数据
byte[] btImg = readInputStream(inStream);
return btImg;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
*
*
* @param inStream
* @return
* @throws Exception
*/
private static byte[] readInputStream(InputStream inStream) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
inStream.close();
return outStream.toByteArray();
}
// 创建临时文件
private static File getFileFromBytes(byte[] b, String suffix) {
BufferedOutputStream stream = null;
File file = null;
try {
file = File.createTempFile("pattern", "." + suffix);
System.out.println("临时文件位置:" + file.getCanonicalPath());
FileOutputStream fstream = new FileOutputStream(file);
stream = new BufferedOutputStream(fstream);
stream.write(b);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return file;
}
public static MultipartFile createImg(String url) {
try {
// File转换成MutipartFile
File file = FileUtils.createFileByUrl(url, "jpg");
FileInputStream inputStream = new FileInputStream(file);
MultipartFile multipartFile = new MockMultipartFile(file.getName(), inputStream);
return multipartFile;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static MultipartFile fileToMultipart(String filePath) {
try {
// File转换成MutipartFile
File file = new File(filePath);
FileInputStream inputStream = new FileInputStream(file);
MultipartFile multipartFile = new MockMultipartFile(file.getName(), "png", "image/png", inputStream);
return multipartFile;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
FileUtils.createFileByUrl("http://122.112.151.149:8888/group1/M00/00/00/wKgAkF0HyPeAAisRAADs167VCfA155.png", "png");
FileUtils.createImg("http://122.112.151.149:8888/group1/M00/00/00/wKgAkF0HyPeAAisRAADs167VCfA155.png");
}
public static boolean base64ToFile(String filePath, String base64Data) throws Exception {
String dataPrix = "";
String data = "";
if (base64Data == null || "".equals(base64Data)) {
return false;
} else {
String[] d = base64Data.split("base64,");
if (d != null && d.length == 2) {
dataPrix = d[0];
data = d[1];
} else {
return false;
}
}
// 因为BASE64Decoder的jar问题此处使用spring框架提供的工具包
byte[] bs = Base64Utils.decodeFromString(data);
// 使用apache提供的工具类操作流
org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(filePath), bs);
return true;
}
}

@ -1,59 +0,0 @@
/***********************************************************
* @Description : JWTJWTtokentoken
* @author : 广(Laing Shan Guang)
* @date : 2019-05-21 08:15
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.utils;
import lsgwr.exam.entity.User;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Date;
public class JwtUtils {
/**
* token
*/
private static final String SUBJECT = "lsg_exam";
/**
* 1
*/
private static final long EXPIRE = 1000 * 60 * 60 * 24;
private static final String APP_SECRET = "liangshanguang";
public static String genJsonWebToken(User user) {
if (user == null || user.getUserId() == null || user.getUserUsername() == null || user.getUserAvatar() == null) {
return null;
}
return Jwts.builder().setSubject(SUBJECT)
// 下面3行设置token中间字段携带用户的信息
.claim("id", user.getUserId())
.claim("username", user.getUserUsername())
.claim("avatar", user.getUserAvatar())
.setIssuedAt(new Date())
// 设置过期时间
.setExpiration(new Date(System.currentTimeMillis() + EXPIRE))
.signWith(SignatureAlgorithm.HS256, APP_SECRET)
// 生成的结果字符串太长,这里压缩下
.compact();
}
/**
* token
*
* @param token token
* @return
*/
public static Claims checkJWT(String token) {
try {
return Jwts.parser().setSigningKey(APP_SECRET).parseClaimsJws(token).getBody();
} catch (Exception e) {
// 篡改token会导致校验失败走到异常分支这里返回null
return null;
}
}
}

@ -1,29 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-17 07:43
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.utils;
import lsgwr.exam.vo.ResultVO;
public class ResultVOUtil {
public static ResultVO success(Integer code, String msg, Object object) {
return new ResultVO(code, msg, object);
}
public static ResultVO success(Object object) {
return new ResultVO(0, "成功", object);
}
public static ResultVO success() {
return new ResultVO(0, "成功", null);
}
public static ResultVO error(Integer code, String msg) {
return new ResultVO(code, msg, null);
}
}

@ -1,5 +0,0 @@
/*
* Created By Liang Shan Guang at 2019-05-14 08:19
* Description : , Hutool
*/
package lsgwr.exam.utils;

@ -1,22 +0,0 @@
/***********************************************************
* @Description : Action
* @author : 广(Laing Shan Guang)
* @date : 2019-05-26 13:50
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class ActionVo {
@JsonProperty("action")
private String actionName;
@JsonProperty("describe")
private String actionDescription;
@JsonProperty("defaultCheck")
private Boolean defaultCheck;
}

@ -1,29 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-06-23 19:30
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class ExamCardVo {
@JsonProperty("id")
private String examId;
@JsonProperty("title")
private String examName;
@JsonProperty("avatar")
private String examAvatar;
@JsonProperty("content")
private String examDescription;
@JsonProperty("score")
private Integer examScore;
/**
*
*/
@JsonProperty("elapse")
private Integer examTimeLimit;
}

@ -1,65 +0,0 @@
/***********************************************************
* @Description : examCreatorIdtoken
* @author : 广(Laing Shan Guang)
* @date : 2019-06-17 08:14
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
@Data
public class ExamCreateVo {
@JsonProperty("name")
private String examName;
@JsonProperty("avatar")
private String examAvatar;
@JsonProperty("desc")
private String examDescription;
/**
*
*/
@JsonProperty("elapse")
private Integer examTimeLimit;
/**
*
*/
private List<ExamQuestionSelectVo> radios;
/**
*
*/
private List<ExamQuestionSelectVo> checks;
/**
*
*/
private List<ExamQuestionSelectVo> judges;
/**
*
*/
@JsonProperty("radioScore")
private Integer examScoreRadio;
/**
*
*/
@JsonProperty("checkScore")
private Integer examScoreCheck;
/**
*
*/
@JsonProperty("judgeScore")
private Integer examScoreJudge;
}

@ -1,34 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-06-24 08:14
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import lsgwr.exam.entity.Exam;
import lombok.Data;
@Data
public class ExamDetailVo {
/**
*
*/
private Exam exam;
/**
* id
*/
private String[] radioIds;
/**
* id
*/
private String[] checkIds;
/**
* id
*/
private String[] judgeIds;
}

@ -1,41 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-06-22 17:00
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
@Data
public class ExamPageVo {
/**
*
*/
private Integer pageSize;
/**
* 1
*/
private Integer pageNo;
/**
*
*/
private Long totalCount;
/**
*
*/
private Integer totalPage;
/**
*
*/
@JsonProperty("data")
private List<ExamVo> examVoList;
}

@ -1,26 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-06-17 23:10
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class ExamQuestionSelectVo {
@JsonProperty("id")
private String questionId;
@JsonProperty("name")
private String questionName;
/**
* .falsetrue
*
*/
@JsonProperty("checked")
private Boolean checked = false;
}

@ -1,24 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-06-23 11:00
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
@Data
public class ExamQuestionTypeVo {
@JsonProperty("radios")
private List<ExamQuestionSelectVo> examQuestionSelectVoRadioList;
@JsonProperty("checks")
private List<ExamQuestionSelectVo> examQuestionSelectVoCheckList;
@JsonProperty("judges")
private List<ExamQuestionSelectVo> examQuestionSelectVoJudgeList;
}

@ -1,30 +0,0 @@
/***********************************************************
* @Description : VO
* @author : 广(Liang Shan Guang)
* @date : 2019/10/25 7:42
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import lsgwr.exam.entity.Exam;
import lsgwr.exam.entity.ExamRecord;
import lsgwr.exam.entity.User;
import lombok.Data;
@Data
public class ExamRecordVo {
/**
*
*/
private Exam exam;
/**
*
*/
private ExamRecord examRecord;
/**
*
*/
private User user;
}

@ -1,89 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019/5/14 07:42
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class ExamVo {
@JsonProperty("id")
private String examId;
@JsonProperty("name")
private String examName;
@JsonProperty("avatar")
private String examAvatar;
@JsonProperty("desc")
private String examDescription;
@JsonProperty("radios")
private List<ExamQuestionSelectVo> examQuestionSelectVoRadioList;
@JsonProperty("checks")
private List<ExamQuestionSelectVo> examQuestionSelectVoCheckList;
@JsonProperty("judges")
private List<ExamQuestionSelectVo> examQuestionSelectVoJudgeList;
@JsonProperty("score")
private Integer examScore;
@JsonProperty("radioScore")
private Integer examScoreRadio;
@JsonProperty("checkScore")
private Integer examScoreCheck;
@JsonProperty("judgeScore")
private Integer examScoreJudge;
/**
* id
*/
@JsonProperty("creator")
private String examCreator;
/**
*
*/
@JsonProperty("elapse")
private Integer examTimeLimit;
/**
*
*/
@JsonProperty("startDate")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date examStartDate;
/**
*
*/
@JsonProperty("endDate")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date examEndDate;
/**
*
*/
@JsonProperty("createTime")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**
*
*/
@JsonProperty("updateTime")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}

@ -1,81 +0,0 @@
package lsgwr.exam.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
*
*
* @author liangshanguang
* @date 2019-05-22 08:11
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonData implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 0 1-1
*/
private Integer code;
/**
*
*/
private Object data;
/**
*
*/
private String msg;
/**
*
*/
public static JsonData buildSuccess() {
return new JsonData(0, null, null);
}
/**
*
*/
public static JsonData buildSuccess(Object data) {
return new JsonData(0, data, null);
}
/**
*
*/
public static JsonData buildError(String msg) {
return new JsonData(-1, null, msg);
}
/**
* ,
*/
public static JsonData buildError(String msg, Integer code) {
return new JsonData(code, null, msg);
}
/**
* ,
*
* @param data
* @param msg
* @return
*/
public static JsonData buildSuccess(Object data, String msg) {
return new JsonData(0, data, msg);
}
/**
* ,
*/
public static JsonData buildSuccess(Object data, int code) {
return new JsonData(code, data, null);
}
}

@ -1,24 +0,0 @@
/***********************************************************
* @Description : Action
* @author : 广(Laing Shan Guang)
* @date : 2019-05-26 13:46
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
@Data
public class PageVo {
@JsonProperty("actionEntitySet")
private List<ActionVo> actionVoList;
@JsonProperty("permissionId")
private String pageName;
@JsonProperty("permissionName")
private String pageDescription;
}

@ -1,54 +0,0 @@
/***********************************************************
* @Description : ,
* @author : 广(Laing Shan Guang)
* @date : 2019-06-02 13:26
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
@Data
public class QuestionCreateSimplifyVo {
/**
*
*/
@JsonProperty("name")
private String questionName;
@JsonProperty("desc")
private String questionDescription;
/**
* id
*/
@JsonProperty("level")
private Integer questionLevelId;
/**
* ()
*/
@JsonProperty("type")
private Integer questionTypeId;
/**
*
*/
@JsonProperty("category")
private Integer questionCategoryId;
/**
*
*/
@JsonProperty("option")
private String option;
/**
* truefalse
*/
@JsonProperty("options")
private List<QuestionOptionCreateVo> questionOptionCreateVoList;
}

@ -1,60 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-06-02 13:26
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
@Data
public class QuestionCreateVo {
/**
*
*/
@JsonProperty("name")
private String questionName;
@JsonProperty("desc")
private String questionDescription;
/**
* ,5
*/
@JsonProperty("score")
private Integer questionScore = 5;
/**
* idtoken
*/
@JsonProperty("creator")
private String questionCreatorId;
/**
* id
*/
@JsonProperty("level")
private Integer questionLevelId;
/**
* ()
*/
@JsonProperty("type")
private Integer questionTypeId;
/**
*
*/
@JsonProperty("category")
private Integer questionCategoryId;
/**
* truefalse
*/
@JsonProperty("options")
private List<QuestionOptionCreateVo> questionOptionCreateVoList;
}

@ -1,43 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-10-20 09:51
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import lsgwr.exam.entity.QuestionOption;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class QuestionDetailVo {
/**
* id
*/
private String id;
/**
*
*/
private String name;
/**
*
*/
private String description;
/**
*
*/
private String type;
/**
*
*/
private List<QuestionOption> options;
/**
* ,id
*/
private List<String> answers = new ArrayList<>();
}

@ -1,27 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-06-02 20:23
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class QuestionOptionCreateVo {
/**
*
*/
@JsonProperty("content")
private String questionOptionContent;
/**
*
*/
@JsonProperty("answer")
private Boolean answer = false;
}

@ -1,25 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-06-01 09:45
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class QuestionOptionVo {
@JsonProperty("id")
private String questionOptionId;
@JsonProperty("content")
private String questionOptionContent;
@JsonProperty("answer")
private Boolean answer = false;
@JsonProperty("description")
private String questionOptionDescription;
}

@ -1,42 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-28 22:09
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
@Data
public class QuestionPageVo {
/**
*
*/
private Integer pageSize;
/**
* 1
*/
private Integer pageNo;
/**
*
*/
private Long totalCount;
/**
*
*/
private Integer totalPage;
/**
*
*/
@JsonProperty("data")
private List<QuestionVo> questionVoList;
}

@ -1,27 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-06-03 07:35
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lsgwr.exam.entity.QuestionCategory;
import lsgwr.exam.entity.QuestionLevel;
import lsgwr.exam.entity.QuestionType;
import lombok.Data;
import java.util.List;
@Data
public class QuestionSelectionVo {
@JsonProperty("types")
private List<QuestionType> questionTypeList;
@JsonProperty("categories")
private List<QuestionCategory> questionCategoryList;
@JsonProperty("levels")
private List<QuestionLevel> questionLevelList;
}

@ -1,86 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-28 08:17
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class QuestionVo {
@JsonProperty("id")
private String questionId;
@JsonProperty("name")
private String questionName;
@JsonProperty("score")
private Integer questionScore;
/**
* questionCreatorId
*/
@JsonProperty("creator")
private String questionCreator;
/**
* questionLevelId
*/
@JsonProperty("level")
private String questionLevel;
/**
* question_levelid
*/
@JsonProperty("levelId")
private int questionLevelId;
/**
* questionTypeId
*/
@JsonProperty("type")
private String questionType;
/**
* question_typeid
*/
@JsonProperty("typeId")
private int questionTypeId;
/**
* questionCategoryId
*/
@JsonProperty("category")
private String questionCategory;
/**
* question_categoryid
*/
@JsonProperty("categoryId")
private int questionCategoryId;
@JsonProperty("description")
private String questionDescription;
/**
* questionOptionIds,isAnswer
*/
@JsonProperty("options")
private List<QuestionOptionVo> questionOptionVoList;
/**
* Java
* @DynamicUpdate
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}

@ -1,35 +0,0 @@
/***********************************************************
* @Description : VO
* @author : 广(Liang Shan Guang)
* @date : 2019/10/27 15:37
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import lsgwr.exam.entity.ExamRecord;
import lombok.Data;
import java.util.HashMap;
import java.util.List;
@Data
public class RecordDetailVo {
/**
*
*/
private ExamRecord examRecord;
/**
* , idid
*/
private HashMap<String, List<String>> answersMap;
/**
* MapidTrue or False
*/
private HashMap<String, String> resultsMap;
/**
* idid
*/
private HashMap<String, List<String>> answersRightMap;
}

@ -1,40 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-17 07:42
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
@Data
@JsonInclude(JsonInclude.Include.NON_NULL) // 避免返回NULL的字段
public class ResultVO<T> {
public ResultVO(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public ResultVO() {
}
/**
*
*/
private Integer code;
/**
*
*/
private String msg = "";
/**
*
*/
private T data;
}

@ -1,27 +0,0 @@
/***********************************************************
* @Description :
* @author : 广(Laing Shan Guang)
* @date : 2019-05-26 13:27
* @email : liangshanguang2@gmail.com
***********************************************************/
package lsgwr.exam.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
@Data
public class RoleVo {
@JsonProperty("id")
private String roleName;
@JsonProperty("name")
private String roleDescription;
@JsonProperty("describe")
private String roleDetail;
@JsonProperty("permissions")
private List<PageVo> pageVoList;
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save