Commit 06b5e8c3 by yangyang

考试后台初始化提交

parents
<?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.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.exam</groupId>
<artifactId>exam</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>examsystem</name>
<description>online examsystem project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- MyBatisX插件 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.mybatis.spring.boot</groupId>-->
<!--<artifactId>mybatis-spring-boot-starter</artifactId>-->
<!--<version>1.3.2</version>-->
<!--</dependency>-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.8</version>
</dependency>
<!-- 热部署模块 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>exam</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.exam;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication()
public class ExamsystemApplication {
public static void main(String[] args) {
SpringApplication.run(ExamsystemApplication.class, args);
}
}
package com.exam;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement
@Configuration
@MapperScan("com.exam.service.*.mapper*")
public class MybatisPlusConfig {
/**
* 分页插件
* @return
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
package com.exam.controller;
import com.exam.entity.Admin;
import com.exam.entity.ApiResult;
import com.exam.serviceimpl.AdminServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class AdminController {
private AdminServiceImpl adminService;
@Autowired
public AdminController(AdminServiceImpl adminService){
this.adminService = adminService;
}
@GetMapping("/admins")
public ApiResult findAll(){
System.out.println("查询全部");
return ApiResultHandler.success(adminService.findAll());
}
@GetMapping("/admin/{adminId}")
public ApiResult findById(@PathVariable("adminId") Integer adminId){
System.out.println("根据ID查找");
return ApiResultHandler.success(adminService.findById(adminId));
}
@DeleteMapping("/admin/{adminId}")
public ApiResult deleteById(@PathVariable("adminId") Integer adminId){
adminService.deleteById(adminId);
return ApiResultHandler.success();
}
@PutMapping("/admin/{adminId}")
public ApiResult update(@PathVariable("adminId") Integer adminId, Admin admin){
return ApiResultHandler.success(adminService.update(admin));
}
@PostMapping("/admin")
public ApiResult add(Admin admin){
return ApiResultHandler.success(adminService.add(admin));
}
}
package com.exam.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ApiResult;
import com.exam.serviceimpl.AnswerServiceImpl;
import com.exam.util.ApiResultHandler;
import com.exam.vo.AnswerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class AnswerController {
@Autowired
private AnswerServiceImpl answerService;
@GetMapping("/answers/{page}/{size}")
public ApiResult findAllQuestion(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
Page<AnswerVO> answerVOPage = new Page<>(page,size);
IPage<AnswerVO> answerVOIPage = answerService.findAll(answerVOPage);
return ApiResultHandler.buildApiResult(200,"查询所有题库",answerVOIPage);
}
}
package com.exam.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ApiResult;
import com.exam.entity.ExamManage;
import com.exam.serviceimpl.ExamManageServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class ExamManageController {
@Autowired
private ExamManageServiceImpl examManageService;
@GetMapping("/exams")
public ApiResult findAll(){
System.out.println("不分页查询所有试卷");
ApiResult apiResult;
apiResult = ApiResultHandler.buildApiResult(200, "请求成功!", examManageService.findAll());
return apiResult;
}
@GetMapping("/exams/{page}/{size}")
public ApiResult findAll(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
System.out.println("分页查询所有试卷");
ApiResult apiResult;
Page<ExamManage> examManage = new Page<>(page,size);
IPage<ExamManage> all = examManageService.findAll(examManage);
apiResult = ApiResultHandler.buildApiResult(200, "请求成功!", all);
return apiResult;
}
@GetMapping("/exam/{examCode}")
public ApiResult findById(@PathVariable("examCode") Integer examCode){
System.out.println("根据ID查找");
ExamManage res = examManageService.findById(examCode);
if(res == null) {
return ApiResultHandler.buildApiResult(10000,"考试编号不存在",null);
}
return ApiResultHandler.buildApiResult(200,"请求成功!",res);
}
@DeleteMapping("/exam/{examCode}")
public ApiResult deleteById(@PathVariable("examCode") Integer examCode){
int res = examManageService.delete(examCode);
return ApiResultHandler.buildApiResult(200,"删除成功",res);
}
@PutMapping("/exam")
public ApiResult update(@RequestBody ExamManage exammanage){
int res = examManageService.update(exammanage);
// if (res == 0) {
// return ApiResultHandler.buildApiResult(20000,"请求参数错误");
// }
System.out.print("更新操作执行---");
return ApiResultHandler.buildApiResult(200,"更新成功",res);
}
@PostMapping("/exam")
public ApiResult add(@RequestBody ExamManage exammanage){
int res = examManageService.add(exammanage);
if (res ==1) {
return ApiResultHandler.buildApiResult(200, "添加成功", res);
} else {
return ApiResultHandler.buildApiResult(400,"添加失败",res);
}
}
@GetMapping("/examManagePaperId")
public ApiResult findOnlyPaperId() {
ExamManage res = examManageService.findOnlyPaperId();
if (res != null) {
return ApiResultHandler.buildApiResult(200,"请求成功",res);
}
return ApiResultHandler.buildApiResult(400,"请求失败",res);
}
}
package com.exam.controller;
import com.exam.entity.ApiResult;
import com.exam.entity.FillQuestion;
import com.exam.serviceimpl.FillQuestionServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class FillQuestionController {
@Autowired
private FillQuestionServiceImpl fillQuestionService;
@PostMapping("/fillQuestion")
public ApiResult add(@RequestBody FillQuestion fillQuestion) {
int res = fillQuestionService.add(fillQuestion);
if (res != 0) {
return ApiResultHandler.buildApiResult(200,"添加成功",res);
}
return ApiResultHandler.buildApiResult(400,"添加失败",res);
}
@GetMapping("/fillQuestionId")
public ApiResult findOnlyQuestionId() {
FillQuestion res = fillQuestionService.findOnlyQuestionId();
return ApiResultHandler.buildApiResult(200,"查询成功",res);
}
}
package com.exam.controller;
import com.exam.entity.ApiResult;
import com.exam.entity.PaperManage;
import com.exam.service.PaperService;
import com.exam.serviceimpl.FillQuestionServiceImpl;
import com.exam.serviceimpl.JudgeQuestionServiceImpl;
import com.exam.serviceimpl.MultiQuestionServiceImpl;
import com.exam.util.ApiResultHandler;
import com.exam.vo.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class ItemController {
@Autowired
MultiQuestionServiceImpl multiQuestionService;
@Autowired
FillQuestionServiceImpl fillQuestionService;
@Autowired
JudgeQuestionServiceImpl judgeQuestionService;
@Autowired
PaperService paperService;
@PostMapping("/item")
public ApiResult ItemController(@RequestBody Item item) {
// 选择题
Integer changeNumber = item.getChangeNumber();
// 填空题
Integer fillNumber = item.getFillNumber();
// 判断题
Integer judgeNumber = item.getJudgeNumber();
//出卷id
Integer paperId = item.getPaperId();
// 选择题数据库获取
List<Integer> changeNumbers = multiQuestionService.findBySubject(item.getSubject(), changeNumber);
if(changeNumbers==null){
return ApiResultHandler.buildApiResult(400,"选择题数据库获取失败",null);
}
for (Integer number : changeNumbers) {
PaperManage paperManage = new PaperManage(paperId,1,number);
int index = paperService.add(paperManage);
if(index==0)
return ApiResultHandler.buildApiResult(400,"选择题组卷保存失败",null);
}
// 填空题
List<Integer> fills = fillQuestionService.findBySubject(item.getSubject(), fillNumber);
if(fills==null)
return ApiResultHandler.buildApiResult(400,"填空题数据库获取失败",null);
for (Integer fillNum : fills) {
PaperManage paperManage = new PaperManage(paperId,2,fillNum);
int index = paperService.add(paperManage);
if(index==0)
return ApiResultHandler.buildApiResult(400,"填空题题组卷保存失败",null);
}
// 判断题
List<Integer> judges = judgeQuestionService.findBySubject(item.getSubject(), judgeNumber);
if(fills==null)
return ApiResultHandler.buildApiResult(400,"判断题数据库获取失败",null);
for (Integer judge : judges) {
PaperManage paperManage = new PaperManage(paperId,3,judge);
int index = paperService.add(paperManage);
if(index==0)
return ApiResultHandler.buildApiResult(400,"判断题题组卷保存失败",null);
}
return ApiResultHandler.buildApiResult(200,"试卷组卷成功",null);
}
}
package com.exam.controller;
import com.exam.entity.ApiResult;
import com.exam.entity.JudgeQuestion;
import com.exam.serviceimpl.JudgeQuestionServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class JudgeQuestionController {
@Autowired
private JudgeQuestionServiceImpl judgeQuestionService;
@PostMapping("/judgeQuestion")
public ApiResult add(@RequestBody JudgeQuestion judgeQuestion) {
int res = judgeQuestionService.add(judgeQuestion);
if (res != 0) {
return ApiResultHandler.buildApiResult(200,"添加成功",res);
}
return ApiResultHandler.buildApiResult(400,"添加失败",res);
}
@GetMapping("/judgeQuestionId")
public ApiResult findOnlyQuestionId() {
JudgeQuestion res = judgeQuestionService.findOnlyQuestionId();
return ApiResultHandler.buildApiResult(200,"查询成功",res);
}
}
package com.exam.controller;
import com.exam.entity.*;
import com.exam.serviceimpl.LoginServiceImpl;
import com.exam.util.ApiResultHandler;
import com.exam.util.NetworkUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
public class LoginController {
@Autowired
private LoginServiceImpl loginService;
@PostMapping("/login")
public ApiResult login(@RequestBody Login login) {
Integer username = login.getUsername();
String password = login.getPassword();
Admin adminRes = loginService.adminLogin(username, password);
if (adminRes != null) {
return ApiResultHandler.buildApiResult(200, "请求成功", adminRes);
}
Teacher teacherRes = loginService.teacherLogin(username,password);
if (teacherRes != null) {
return ApiResultHandler.buildApiResult(200, "请求成功", teacherRes);
}
String usernameStu = login.getUsername().toString();
Student studentRes = loginService.studentLogin(usernameStu,password);
if (studentRes != null) {
return ApiResultHandler.buildApiResult(200, "请求成功", studentRes);
}
return ApiResultHandler.buildApiResult(400, "请求失败", null);
}
@PostMapping("/loginYh")
public ApiResult login(HttpServletRequest request) {
String ip = NetworkUtil.getIpAddr(request);
System.out.println("ip....."+ip);
Student studentRes = loginService.LoginYh(ip,ip);
if (studentRes != null) {
return ApiResultHandler.buildApiResult(200, "请求成功", studentRes);
}else{
Student student = new Student();
student.setStudentId(ip);
student.setStudentName("匿名");
student.setRole("2");
return ApiResultHandler.buildApiResult(200, "请求成功", student);
}
}
}
package com.exam.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ApiResult;
import com.exam.entity.Message;
import com.exam.serviceimpl.MessageServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class MessageController {
@Autowired
private MessageServiceImpl messageService;
@GetMapping("/messages/{page}/{size}")
public ApiResult<Message> findAll(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
Page<Message> messagePage = new Page<>(page,size);
IPage<Message> all = messageService.findAll(messagePage);
return ApiResultHandler.buildApiResult(200,"查询所有留言",all);
}
@GetMapping("/message/{id}")
public ApiResult findById(@PathVariable("id") Integer id) {
Message res = messageService.findById(id);
return ApiResultHandler.buildApiResult(200,"根据Id查询",res);
}
@DeleteMapping("/message/{id}")
public int delete(@PathVariable("id") Integer id) {
int res = messageService.delete(id);
return res;
}
@PostMapping("/message")
public ApiResult add(@RequestBody Message message) {
int res = messageService.add(message);
if (res == 0) {
return ApiResultHandler.buildApiResult(400,"添加失败",res);
} else {
return ApiResultHandler.buildApiResult(200,"添加成功",res);
}
}
}
package com.exam.controller;
import com.exam.entity.ApiResult;
import com.exam.entity.MultiQuestion;
import com.exam.serviceimpl.MultiQuestionServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MultiQuestionController {
@Autowired
private MultiQuestionServiceImpl multiQuestionService;
@GetMapping("/multiQuestionId")
public ApiResult findOnlyQuestion() {
MultiQuestion res = multiQuestionService.findOnlyQuestionId();
return ApiResultHandler.buildApiResult(200,"查询成功",res);
}
@PostMapping("/MultiQuestion")
public ApiResult add(@RequestBody MultiQuestion multiQuestion) {
int res = multiQuestionService.add(multiQuestion);
if (res != 0) {
return ApiResultHandler.buildApiResult(200,"添加成功",res);
}
return ApiResultHandler.buildApiResult(400,"添加失败",res);
}
}
package com.exam.controller;
import com.exam.entity.*;
import com.exam.serviceimpl.FillQuestionServiceImpl;
import com.exam.serviceimpl.JudgeQuestionServiceImpl;
import com.exam.serviceimpl.MultiQuestionServiceImpl;
import com.exam.serviceimpl.PaperServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@RestController
public class PaperController {
@Autowired
private PaperServiceImpl paperService;
@Autowired
private JudgeQuestionServiceImpl judgeQuestionService;
@Autowired
private MultiQuestionServiceImpl multiQuestionService;
@Autowired
private FillQuestionServiceImpl fillQuestionService;
@GetMapping("/papers")
public ApiResult<PaperManage> findAll() {
ApiResult res = ApiResultHandler.buildApiResult(200,"请求成功",paperService.findAll());
return res;
}
@GetMapping("/paper/{paperId}")
public Map<Integer, List<?>> findById(@PathVariable("paperId") Integer paperId) {
List<MultiQuestion> multiQuestionRes = multiQuestionService.findByIdAndType(paperId); //选择题题库 1
//List<FillQuestion> fillQuestionsRes = fillQuestionService.findByIdAndType(paperId); //填空题题库 2
//List<JudgeQuestion> judgeQuestionRes = judgeQuestionService.findByIdAndType(paperId); //判断题题库 3
List<FillQuestion> fillQuestionsRes = new ArrayList<>(); //填空题题库 2
List<JudgeQuestion> judgeQuestionRes = new ArrayList<>(); //判断题题库 3
Map<Integer, List<?>> map = new HashMap<>();
map.put(1,multiQuestionRes);
map.put(2,fillQuestionsRes);
map.put(3,judgeQuestionRes);
return map;
}
@PostMapping("/paperManage")
public ApiResult add(@RequestBody PaperManage paperManage) {
int res = paperService.add(paperManage);
if (res != 0) {
return ApiResultHandler.buildApiResult(200,"添加成功",res);
}
return ApiResultHandler.buildApiResult(400,"添加失败",res);
}
public List GetRandomList(List list, int count) {
List olist = new ArrayList<>();
if (list.size() <= count) {
return list;
} else {
Random random = new Random();
for (int i = 0 ;i<count;i++){
int intRandom = random.nextInt(list.size() - 1);
olist.add(list.get(intRandom));
list.remove(list.get(intRandom));
}
return olist;
}
}
}
package com.exam.controller;
import com.exam.entity.ApiResult;
import com.exam.entity.Replay;
import com.exam.serviceimpl.ReplayServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class ReplayController {
@Autowired
private ReplayServiceImpl replayService;
@PostMapping("/replay")
public ApiResult add(@RequestBody Replay replay) {
int data = replayService.add(replay);
if (data != 0) {
return ApiResultHandler.buildApiResult(200,"添加成功!",data);
} else {
return ApiResultHandler.buildApiResult(400,"添加失败!",null);
}
}
@GetMapping("/replay/{messageId}")
public ApiResult findAllById(@PathVariable("messageId") Integer messageId) {
List<Replay> res = replayService.findAllById(messageId);
return ApiResultHandler.buildApiResult(200,"根据messageId查询",res);
}
}
package com.exam.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.*;
import com.exam.serviceimpl.ScoreServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
public class ScoreController {
@Autowired
private ScoreServiceImpl scoreService;
@GetMapping("/scores")
public ApiResult findAll() {
List<Score> res = scoreService.findAll();
return ApiResultHandler.buildApiResult(200,"查询所有学生成绩",res);
}
// 分页
@GetMapping("/score/{page}/{size}/{studentId}")
public ApiResult findById(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @PathVariable("studentId") String studentId) {
Page<Score> scorePage = new Page<>(page, size);
IPage<Score> res = scoreService.findById(scorePage, studentId);
return ApiResultHandler.buildApiResult(200, "根据ID查询成绩", res);
}
// 不分页
@GetMapping("/score/{studentId}")
public ApiResult findById(@PathVariable("studentId") String studentId) {
List<Score> res = scoreService.findById(studentId);
if (!res.isEmpty()) {
return ApiResultHandler.buildApiResult(200, "根据ID查询成绩", res);
} else {
return ApiResultHandler.buildApiResult(400, "ID不存在", res);
}
}
// 个人统计
@GetMapping("/scoreTj/{studentId}")
public ApiResult findTjById(@PathVariable("studentId") String studentId) {
List<StudentScoreTj> listResult = new ArrayList<>();
StudentScoreTj res = scoreService.findTjById(studentId);
if (null != res) {
listResult.add(res);
return ApiResultHandler.buildApiResult(200, "根据统计成绩", listResult);
} else {
return ApiResultHandler.buildApiResult(400, "ID不存在", listResult);
}
}
// 单位统计
@GetMapping("/scoreDwTj")
public ApiResult findTjDw() {
List<DwScoreTj> listResult = scoreService.findTjDw();
return ApiResultHandler.buildApiResult(200, "根据统计成绩", listResult);
}
// 单位统计透视
@GetMapping("/scoreDwTsTj/{page}/{size}/{clazz}")
public ApiResult findTjTsDw(@PathVariable("page") Integer page, @PathVariable("size") Integer size,@PathVariable("clazz") String clazz) {
Page<StudentScoreTj> scorePage = new Page<>(page, size);
IPage<StudentScoreTj> listResult = scoreService.findTjTsDw(scorePage, clazz);
return ApiResultHandler.buildApiResult(200, "根据单位查询每个人统计成绩", listResult);
}
@PostMapping("/score")
public ApiResult add(@RequestBody Score score) {
int res = scoreService.add(score);
if (res == 0) {
return ApiResultHandler.buildApiResult(400,"成绩添加失败",res);
}else {
return ApiResultHandler.buildApiResult(200,"成绩添加成功",res);
}
}
@GetMapping("/scores/{examCode}")
public ApiResult findByExamCode(@PathVariable("examCode") Integer examCode) {
List<Score> scores = scoreService.findByExamCode(examCode);
return ApiResultHandler.buildApiResult(200,"查询成功",scores);
}
}
package com.exam.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ApiResult;
import com.exam.entity.Student;
import com.exam.serviceimpl.StudentServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class StudentController {
@Autowired
private StudentServiceImpl studentService;
@GetMapping("/students/{page}/{size}")
public ApiResult findAll(@PathVariable Integer page, @PathVariable Integer size) {
Page<Student> studentPage = new Page<>(page,size);
IPage<Student> res = studentService.findAll(studentPage);
return ApiResultHandler.buildApiResult(200,"分页查询所有学生",res);
}
@GetMapping("/student/{studentId}")
public ApiResult findById(@PathVariable("studentId") String studentId) {
Student res = studentService.findById(studentId);
if (res != null) {
return ApiResultHandler.buildApiResult(200,"请求成功",res);
} else {
return ApiResultHandler.buildApiResult(404,"查询的用户不存在",null);
}
}
@DeleteMapping("/student/{studentId}")
public ApiResult deleteById(@PathVariable("studentId") String studentId) {
return ApiResultHandler.buildApiResult(200,"删除成功",studentService.deleteById(studentId));
}
@PutMapping("/studentPWD")
public ApiResult updatePwd(@RequestBody Student student) {
studentService.updatePwd(student);
return ApiResultHandler.buildApiResult(200,"密码更新成功",null);
}
@PutMapping("/student")
public ApiResult update(@RequestBody Student student) {
int res = studentService.update(student);
if (res != 0) {
return ApiResultHandler.buildApiResult(200,"更新成功",res);
}
return ApiResultHandler.buildApiResult(400,"更新失败",res);
}
@PostMapping("/student")
public ApiResult add(@RequestBody Student student) {
int res = studentService.add(student);
if (res == 1) {
return ApiResultHandler.buildApiResult(200,"添加成功",null);
}else {
return ApiResultHandler.buildApiResult(400,"添加失败",null);
}
}
}
package com.exam.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ApiResult;
import com.exam.entity.Teacher;
import com.exam.serviceimpl.TeacherServiceImpl;
import com.exam.util.ApiResultHandler;
import com.exam.vo.AnswerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class TeacherController {
private TeacherServiceImpl teacherService;
@Autowired
public TeacherController(TeacherServiceImpl teacherService){
this.teacherService = teacherService;
}
@GetMapping("/teachers/{page}/{size}")
public ApiResult findAll(@PathVariable Integer page, @PathVariable Integer size){
Page<Teacher> teacherPage = new Page<>(page,size);
IPage<Teacher> teacherIPage = teacherService.findAll(teacherPage);
return ApiResultHandler.buildApiResult(200,"查询所有教师",teacherIPage);
}
@GetMapping("/teacher/{teacherId}")
public ApiResult findById(@PathVariable("teacherId") Integer teacherId){
return ApiResultHandler.success(teacherService.findById(teacherId));
}
@DeleteMapping("/teacher/{teacherId}")
public ApiResult deleteById(@PathVariable("teacherId") Integer teacherId){
return ApiResultHandler.success(teacherService.deleteById(teacherId));
}
@PutMapping("/teacher")
public ApiResult update(@RequestBody Teacher teacher){
return ApiResultHandler.success(teacherService.update(teacher));
}
@PostMapping("/teacher")
public ApiResult add(@RequestBody Teacher teacher){
return ApiResultHandler.success(teacherService.add(teacher));
}
}
package com.exam.entity;
public class Admin {
private Integer adminId;
private String adminName;
private String sex;
private String tel;
private String email;
private String pwd;
private String cardId;
private String role;
public Integer getAdminId() {
return adminId;
}
public void setAdminId(Integer adminId) {
this.adminId = adminId;
}
public String getAdminName() {
return adminName;
}
public void setAdminName(String adminName) {
this.adminName = adminName == null ? null : adminName.trim();
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex == null ? null : sex.trim();
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel == null ? null : tel.trim();
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email == null ? null : email.trim();
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd == null ? null : pwd.trim();
}
public String getCardId() {
return cardId;
}
public void setCardId(String cardId) {
this.cardId = cardId == null ? null : cardId.trim();
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role == null ? null : role.trim();
}
}
\ No newline at end of file
package com.exam.entity;
public class ApiResult<T> {
/**
* 错误码,表示一种错误类型
* 请求成功,状态码为200
*/
private int code;
/**
* 对错误代码的详细解释
*/
private String message;
/**
* 返回的结果包装在value中,value可以是单个对象
*/
private T data;
public ApiResult() {
}
public ApiResult(int code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
package com.exam.entity;
import lombok.Data;
@Data
public class DwScoreTj {
private String clazz;
private Integer count;
private Integer rycount;
private Integer countsum;
private Integer dtcount;
private String right;
}
\ No newline at end of file
package com.exam.entity;
import lombok.Data;
import java.util.Date;
@Data
public class ExamManage {
private Integer examCode;
private String description;
private String source;
private Integer paperId;
private String examDate;
private Integer totalTime;
private String grade;
private String term;
private String major;
private String institute;
private Integer totalScore;
private String type;
private String tips;
}
\ No newline at end of file
package com.exam.entity;
import lombok.Data;
//填空题实体类
@Data
public class FillQuestion {
private Integer questionId;
private String subject;
private String question;
private String answer;
private Integer score;
private String level;
private String section;
private String analysis; //题目解析
}
package com.exam.entity;
import lombok.Data;
//判断题实体类
@Data
public class JudgeQuestion {
private Integer questionId;
private String subject;
private String question;
private String answer;
private String level;
private String section;
private Integer score;
private String analysis; //题目解析
}
\ No newline at end of file
package com.exam.entity;
public class Login {
private Integer username;
private String password;
public Integer getUsername() {
return username;
}
public void setUsername(Integer username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.exam.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class Message {
private Integer id;
private Integer temp_id;//解决id为null创建的一个临时id
private String title;
private String content;
@JsonFormat(pattern = "yyyy-MM-dd", timezone="GMT+8")
private Date time;
List<Replay> replays; //一对多关系,评论信息
}
\ No newline at end of file
package com.exam.entity;
import lombok.Data;
// 选择题实体
@Data
public class MultiQuestion {
private Integer questionId;
private String subject;
private String section;
private String answerA;
private String answerB;
private String answerC;
private String answerD;
private String question;
private String level;
private String rightAnswer;
private String analysis; //题目解析
private Integer score;
}
\ No newline at end of file
package com.exam.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PaperManage {
private Integer paperId;
private Integer questionType;
private Integer questionId;
}
\ No newline at end of file
package com.exam.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
@Data
public class Replay {
private Integer messageId;
private Integer replayId;
private String replay;
@JsonFormat(pattern = "yyyy-MM-dd", timezone="GMT+8")
private Date replayTime;
}
\ No newline at end of file
package com.exam.entity;
import lombok.Data;
import java.util.Date;
@Data
public class Score {
private Integer examCode;
private String studentId;
private String subject;
private Integer ptScore;
private Integer etScore;
private Integer score;
private Integer scoreId;
private String answerDate;
}
\ No newline at end of file
package com.exam.entity;
public class Student {
private String studentId;
private String studentName;
private String grade;
private String major;
private String clazz;
private String institute;
private String tel;
private String email;
private String pwd;
private String cardId;
private String sex;
private String role;
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName == null ? null : studentName.trim();
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade == null ? null : grade.trim();
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major == null ? null : major.trim();
}
public String getClazz() {
return clazz;
}
public void setClazz(String clazz) {
this.clazz = clazz == null ? null : clazz.trim();
}
public String getInstitute() {
return institute;
}
public void setInstitute(String institute) {
this.institute = institute == null ? null : institute.trim();
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel == null ? null : tel.trim();
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email == null ? null : email.trim();
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd == null ? null : pwd.trim();
}
public String getCardId() {
return cardId;
}
public void setCardId(String cardId) {
this.cardId = cardId == null ? null : cardId.trim();
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex == null ? null : sex.trim();
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role == null ? null : role.trim();
}
}
\ No newline at end of file
package com.exam.entity;
import lombok.Data;
@Data
public class StudentScoreTj {
private String studentId;
private String studentName;
private Integer count;
private Integer countsum;
private Integer dtcount;
private String right;
}
\ No newline at end of file
package com.exam.entity;
import lombok.Data;
@Data
public class Teacher {
private Integer teacherId;
private String teacherName;
private String institute;
private String sex;
private String tel;
private String email;
private String pwd;
private String cardId;
private String type;
private String role;
}
\ No newline at end of file
package com.exam.mapper;
import com.exam.entity.Admin;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface AdminMapper {
@Select("select adminName,sex,tel,email,cardId,role from admin")
public List<Admin> findAll();
@Select("select adminName,sex,tel,email,cardId,role from admin where adminId = #{adminId}")
public Admin findById(Integer adminId);
@Delete("delete from admin where adminId = #{adminId}")
public int deleteById(int adminId);
@Update("update admin set adminName = #{adminName},sex = #{sex}," +
"tel = #{tel}, email = #{email},pwd = #{pwd},cardId = #{cardId},role = #{role} where adminId = #{adminId}")
public int update(Admin admin);
@Options(useGeneratedKeys = true,keyProperty = "adminId")
@Insert("insert into admin(adminName,sex,tel,email,pwd,cardId,role) " +
"values(#{adminName},#{sex},#{tel},#{email},#{pwd},#{cardId},#{role})")
public int add(Admin admin);
}
package com.exam.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.vo.AnswerVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface AnswerMapper {
@Select("select question, subject, score, section,level, \"选择题\" as type from multi_question " +
"union select question, subject, score, section,level, \"判断题\" as type from judge_question " +
"union select question, subject, score, section,level, \"填空题\" as type from fill_question")
IPage<AnswerVO> findAll(Page page);
}
package com.exam.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ExamManage;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface ExamManageMapper {
@Select("select * from exam_manage")
List<ExamManage> findAll();
@Select("select * from exam_manage")
IPage<ExamManage> findAll(Page page);
@Select("select * from exam_manage where examCode = #{examCode}")
ExamManage findById(Integer examCode);
@Delete("delete from exam_manage where examCode = #{examCode}")
int delete(Integer examCode);
@Update("update exam_manage set description = #{description},source = #{source},paperId = #{paperId}," +
"examDate = #{examDate},totalTime = #{totalTime},grade = #{grade},term = #{term}," +
"major = #{major},institute = #{institute},totalScore = #{totalScore}," +
"type = #{type},tips = #{tips} where examCode = #{examCode}")
int update(ExamManage exammanage);
@Options(useGeneratedKeys = true,keyProperty = "examCode")
@Insert("insert into exam_manage(description,source,paperId,examDate,totalTime,grade,term,major,institute,totalScore,type,tips)" +
" values(#{description},#{source},#{paperId},#{examDate},#{totalTime},#{grade},#{term},#{major},#{institute},#{totalScore},#{type},#{tips})")
int add(ExamManage exammanage);
/**
* 查询最后一条记录的paperId,返回给前端达到自增效果
* @return paperId
*/
@Select("select paperId from exam_manage order by paperId desc limit 1")
ExamManage findOnlyPaperId();
}
package com.exam.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.FillQuestion;
import org.apache.ibatis.annotations.*;
import java.util.List;
//填空题
@Mapper
public interface FillQuestionMapper {
@Select("select * from fill_question where questionId in (select questionId from paper_manage where questionType = 2 and paperId = #{paperId})")
List<FillQuestion> findByIdAndType(Integer paperId);
@Select("select * from fill_question")
IPage<FillQuestion> findAll(Page page);
/**
* 查询最后一条questionId
* @return FillQuestion
*/
@Select("select questionId from fill_question order by questionId desc limit 1")
FillQuestion findOnlyQuestionId();
@Options(useGeneratedKeys = true,keyProperty ="questionId" )
@Insert("insert into fill_question(subject,question,answer,analysis,level,section) values " +
"(#{subject,},#{question},#{answer},#{analysis},#{level},#{section})")
int add(FillQuestion fillQuestion);
@Select("select questionId from fill_question where subject = #{subject} order by rand() desc limit #{pageNo}")
List<Integer> findBySubject(@Param("subject") String subject,@Param("pageNo") Integer pageNo);
}
package com.exam.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.JudgeQuestion;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
//判断题
@Mapper
public interface JudgeQuestionMapper {
@Select("select * from judge_question where questionId in (select questionId from paper_manage where questionType = 3 and paperId = #{paperId})")
List<JudgeQuestion> findByIdAndType(Integer paperId);
@Select("select * from judge_question")
IPage<JudgeQuestion> findAll(Page page);
/**
* 查询最后一条记录的questionId
* @return JudgeQuestion
*/
@Select("select questionId from judge_question order by questionId desc limit 1")
JudgeQuestion findOnlyQuestionId();
@Insert("insert into judge_question(subject,question,answer,analysis,level,section) values " +
"(#{subject},#{question},#{answer},#{analysis},#{level},#{section})")
int add(JudgeQuestion judgeQuestion);
@Select("select questionId from judge_question where subject=#{subject} order by rand() desc limit #{pageNo}")
List<Integer> findBySubject(@Param("subject") String subject,@Param("pageNo") Integer pageNo);
}
package com.exam.mapper;
import com.exam.entity.Admin;
import com.exam.entity.Student;
import com.exam.entity.Teacher;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface LoginMapper {
@Select("select adminId,adminName,sex,tel,email,cardId,role from admin where adminId = #{username} and pwd = #{password}")
public Admin adminLogin(@Param("username")Integer username,@Param("password") String password);
@Select("select teacherId,teacherName,institute,sex,tel,email,cardId," +
"type,role from teacher where teacherId = #{username} and pwd = #{password}")
public Teacher teacherLogin(@Param("username")Integer username,@Param("password") String password);
@Select("select studentId,studentName,grade,major,clazz,institute,tel," +
"email,cardId,sex,role from student where studentId = #{username} and pwd = #{password}")
public Student studentLogin(@Param("username")String username,@Param("password") String password);
@Select("select studentId,studentName,grade,major,clazz,institute,tel," +
"email,cardId,sex,role from student where studentId = #{username} and pwd = #{password}")
public Student loginYh(@Param("username")String username,@Param("password") String password);
}
package com.exam.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.Message;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface MessageMapper {
@Select("select id,id as temp_id,title,content,time from message order by id desc")
@Results({
@Result(property = "replays", column = "temp_id",many = @Many(select = "com.exam.mapper.ReplayMapper.findAllById"))
})
IPage<Message> findAll(Page page);
@Select("select id,title,content,time from message where id = #{id}")
@Results({
@Result(property = "replays", column = "id",many = @Many(select = "com.exam.mapper.ReplayMapper.findAllById"))
})
Message findById(Integer id);
@Delete("delete from message where id = #{id}")
int delete(Integer id);
@Update("update message set title = #{title}, content = #{content}, time = #{time} where " +
"id = #{id}")
int update(Message message);
@Options(useGeneratedKeys = true,keyProperty = "id")
@Insert("insert into message(title, content, time) values(#{title},#{content},#{time})")
int add(Message message);
}
package com.exam.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.MultiQuestion;
import org.apache.ibatis.annotations.*;
import java.util.List;
//选择题
@Mapper
public interface MultiQuestionMapper {
/**
* select * from multiquestions where questionId in (
* select questionId from papermanage where questionType = 1 and paperId = 1001
* )
*/
@Select("select * from multi_question where questionId in (select questionId from paper_manage where questionType = 1 and paperId = #{paperId}) order by rand() limit 1")
List<MultiQuestion> findByIdAndType(Integer PaperId);
@Select("select * from multi_question")
IPage<MultiQuestion> findAll(Page page);
/**
* 查询最后一条记录的questionId
* @return MultiQuestion
*/
@Select("select questionId from multi_question order by questionId desc limit 1")
MultiQuestion findOnlyQuestionId();
@Options(useGeneratedKeys = true,keyProperty = "questionId")
@Insert("insert into multi_question(subject,question,answerA,answerB,answerC,answerD,rightAnswer,analysis,section,level) " +
"values(#{subject},#{question},#{answerA},#{answerB},#{answerC},#{answerD},#{rightAnswer},#{analysis},#{section},#{level})")
int add(MultiQuestion multiQuestion);
@Select("select questionId from multi_question where subject =#{subject} order by rand() desc limit #{pageNo}")
List<Integer> findBySubject(@Param("subject") String subject,@Param("pageNo") Integer pageNo);
}
package com.exam.mapper;
import com.exam.entity.PaperManage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface PaperMapper {
@Select("select paperId, questionType,questionId from paper_manage")
List<PaperManage> findAll();
@Select("select paperId, questionType,questionId from paper_manage where paperId = #{paperId}")
List<PaperManage> findById(Integer paperId);
@Insert("insert into paper_manage(paperId,questionType,questionId) values " +
"(#{paperId},#{questionType},#{questionId})")
int add(PaperManage paperManage);
}
package com.exam.mapper;
import com.exam.entity.Replay;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface ReplayMapper {
@Select("select messageId,replayId,replay,replayTime from replay")
List<Replay> findAll();
@Select("select messageId,replayId,replay,replayTime from replay where messageId = #{messageId}")
List<Replay> findAllById(Integer messageId);
@Select("select messageId,replayId,replay,replayTime from replay where messageId = #{messageId}")
Replay findById(Integer messageId);
@Delete("delete from replay where replayId = #{replayId}")
int delete(Integer replayId);
@Update("update replay set title = #{title}, replay = #{replay}, replayTime = #{replayTime} where replayId = #{replayId}")
int update(Replay replay);
@Options(useGeneratedKeys = true,keyProperty = "replayId")
@Insert("insert into replay(messageId,replay,replayTime) values(#{messageId}, #{replay},#{replayTime})")
int add(Replay replay);
}
package com.exam.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.DwScoreTj;
import com.exam.entity.Score;
import com.exam.entity.StudentScoreTj;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface ScoreMapper {
/**
* @param score 添加一条成绩记录
* @return
*/
@Options(useGeneratedKeys = true,keyProperty = "scoreId")
@Insert("insert into score(examCode,studentId,subject,ptScore,etScore,score,answerDate) values(#{examCode},#{studentId},#{subject},#{ptScore},#{etScore},#{score},#{answerDate})")
int add(Score score);
@Select("select scoreId,examCode,studentId,subject,ptScore,etScore,score,answerDate from score order by scoreId desc")
List<Score> findAll();
// 分页
@Select("select scoreId,examCode,studentId,subject,ptScore,etScore,score,answerDate from score where studentId = #{studentId} order by scoreId desc")
IPage<Score> findById(Page<?> page,@Param("studentId") String studentId);
// 不分页
@Select("select scoreId,examCode,studentId,subject,ptScore,etScore,score,answerDate from score where studentId = #{studentId}")
List<Score> findById(String studentId);
/**
*
* @return 查询每位学生的学科分数。 max其实是假的,为了迷惑老师,达到一次考试考生只参加了一次的效果
*/
@Select("select max(etScore) as etScore from score where examCode = #{examCode} group by studentId")
List<Score> findByExamCode(Integer examCode);
// 学生统计
@Select("select count(*) as count,IFNULL(sum(etScore),0) as countsum from score where studentId = #{studentId}")
StudentScoreTj findTjById(String studentId);
// 单位统计
@Select("select clazz,count(s.studentId) as count,IFNULL(sum(etScore),0) as countsum,count(distinct s.studentId) as rycount from student t left join score s on s.studentId = t.studentId GROUP BY clazz")
List<DwScoreTj> findTjDw();
// 单位统计数据透视
@Select("select t.studentId,t.studentName,count(s.studentId) as count,IFNULL(sum(etScore),0) as countsum from student t left join score s on s.studentId = t.studentId where t.clazz=#{clazz} GROUP BY t.studentId order by sum(etScore) desc")
IPage<StudentScoreTj> findTjTsDw(Page<?> page,@Param("clazz") String clazz);
}
package com.exam.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.Student;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface StudentMapper {
/**
* 分页查询所有学生
* @param page
* @return List<Student>
*/
@Select("select * from student")
IPage<Student> findAll(Page page);
@Select("select * from student where studentId = #{studentId}")
Student findById(String studentId);
@Delete("delete from student where studentId = #{studentId}")
int deleteById(String studentId);
/**
*更新所有学生信息
* @param student 传递一个对象
* @return 受影响的记录条数
*/
@Update("update student set studentName = #{studentName},grade = #{grade},major = #{major},clazz = #{clazz}," +
"institute = #{institute},tel = #{tel},email = #{email},pwd = #{pwd},cardId = #{cardId},sex = #{sex},role = #{role} " +
"where studentId = #{studentId}")
int update(Student student);
/**
* 更新密码
* @param student
* @return 受影响的记录条数
*/
@Update("update student set pwd = #{pwd} where studentId = #{studentId}")
int updatePwd(Student student);
@Options(useGeneratedKeys = true,keyProperty = "studentId")
@Insert("insert into student(studentName,grade,major,clazz,institute,tel,email,pwd,cardId,sex,role) values " +
"(#{studentName},#{grade},#{major},#{clazz},#{institute},#{tel},#{email},#{pwd},#{cardId},#{sex},#{role})")
int add(Student student);
}
package com.exam.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.Teacher;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface TeacherMapper {
@Select("select * from teacher")
IPage<Teacher> findAll(Page page);
@Select("select * from teacher")
public List<Teacher> findAll();
@Select("select * from teacher where teacherId = #{teacherId}")
public Teacher findById(Integer teacherId);
@Delete("delete from teacher where teacherId = #{teacherId}")
public int deleteById(Integer teacherId);
@Update("update teacher set teacherName = #{teacherName},sex = #{sex}," +
"tel = #{tel}, email = #{email},pwd = #{pwd},cardId = #{cardId}," +
"role = #{role},institute = #{institute},type = #{type} where teacherId = #{teacherId}")
public int update(Teacher teacher);
@Options(useGeneratedKeys = true,keyProperty = "teacherId")
@Insert("insert into teacher(teacherName,sex,tel,email,pwd,cardId,role,type,institute) " +
"values(#{teacherName},#{sex},#{tel},#{email},#{pwd},#{cardId},#{role},#{type},#{institute})")
public int add(Teacher teacher);
}
package com.exam.service;
import com.exam.entity.Admin;
import java.util.List;
public interface AdminService{
public List<Admin> findAll();
public Admin findById(Integer adminId);
public int deleteById(int adminId);
public int update(Admin admin);
public int add(Admin admin);
}
package com.exam.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.vo.AnswerVO;
public interface AnswerService {
IPage<AnswerVO> findAll(Page<AnswerVO> page);
}
package com.exam.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ExamManage;
import java.util.List;
public interface ExamManageService {
/**
* 不分页查询所有考试信息
*/
List<ExamManage> findAll();
IPage<ExamManage> findAll(Page<ExamManage> page);
ExamManage findById(Integer examCode);
int delete(Integer examCode);
int update(ExamManage exammanage);
int add(ExamManage exammanage);
ExamManage findOnlyPaperId();
}
package com.exam.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.FillQuestion;
import java.util.List;
public interface FillQuestionService {
List<FillQuestion> findByIdAndType(Integer paperId);
IPage<FillQuestion> findAll(Page<FillQuestion> page);
FillQuestion findOnlyQuestionId();
int add(FillQuestion fillQuestion);
List<Integer> findBySubject(String subject,Integer pageNo);
}
package com.exam.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.JudgeQuestion;
import java.util.List;
public interface JudgeQuestionService {
List<JudgeQuestion> findByIdAndType(Integer paperId);
IPage<JudgeQuestion> findAll(Page<JudgeQuestion> page);
JudgeQuestion findOnlyQuestionId();
int add(JudgeQuestion judgeQuestion);
List<Integer> findBySubject(String subject,Integer pageNo);
}
package com.exam.service;
import com.exam.entity.Admin;
import com.exam.entity.Student;
import com.exam.entity.Teacher;
public interface LoginService {
public Admin adminLogin(Integer username, String password);
public Teacher teacherLogin(Integer username, String password);
public Student studentLogin(String username, String password);
public Student LoginYh(String username, String password);
}
package com.exam.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.Message;
public interface MessageService {
IPage<Message> findAll(Page page);
Message findById(Integer id);
int delete(Integer id);
int update(Message message);
int add(Message message);
}
package com.exam.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.MultiQuestion;
import java.util.List;
public interface MultiQuestionService {
List<MultiQuestion> findByIdAndType(Integer PaperId);
IPage<MultiQuestion> findAll(Page<MultiQuestion> page);
MultiQuestion findOnlyQuestionId();
int add(MultiQuestion multiQuestion);
List<Integer> findBySubject(String subject,Integer pageNo);
}
package com.exam.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.PaperManage;
import java.util.List;
public interface PaperService {
List<PaperManage> findAll();
List<PaperManage> findById(Integer paperId);
int add(PaperManage paperManage);
}
package com.exam.service;
import com.exam.entity.Replay;
import java.util.List;
public interface ReplayService {
List<Replay> findAll();
List<Replay> findAllById(Integer messageId);
Replay findById(Integer replayId);
int delete(Integer replayId);
int update(Replay replay);
int add(Replay replay);
}
package com.exam.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.DwScoreTj;
import com.exam.entity.Score;
import com.exam.entity.StudentScoreTj;
import java.util.List;
public interface ScoreService {
int add(Score score);
List<Score> findAll();
IPage<Score> findById(Page page, String studentId);
List<Score> findById(String studentId);
List<Score> findByExamCode(Integer examCode);
StudentScoreTj findTjById(String studentId);
List<DwScoreTj> findTjDw();
IPage<StudentScoreTj> findTjTsDw(Page<StudentScoreTj> page,String clazz);
}
package com.exam.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.Student;
import java.util.List;
public interface StudentService {
IPage<Student> findAll(Page<Student> page);
Student findById(String studentId);
int deleteById(String studentId);
int update(Student student);
int updatePwd(Student student);
int add(Student student);
}
package com.exam.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.Teacher;
import java.util.List;
public interface TeacherService {
IPage<Teacher> findAll(Page<Teacher> page);
public List<Teacher> findAll();
public Teacher findById(Integer teacherId);
public int deleteById(Integer teacherId);
public int update(Teacher teacher);
public int add(Teacher teacher);
}
package com.exam.serviceimpl;
import com.exam.entity.Admin;
import com.exam.mapper.AdminMapper;
import com.exam.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class AdminServiceImpl implements AdminService {
@Autowired
private AdminMapper adminMapper;
@Override
public List<Admin> findAll() {
return adminMapper.findAll();
}
@Override
public Admin findById(Integer adminId) {
return adminMapper.findById(adminId);
}
@Override
public int deleteById(int adminId) {
return adminMapper.deleteById(adminId);
}
@Override
public int update(Admin admin) {
return adminMapper.update(admin);
}
@Override
public int add(Admin admin) {
return 0;
}
}
package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.mapper.AnswerMapper;
import com.exam.service.AnswerService;
import com.exam.vo.AnswerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AnswerServiceImpl implements AnswerService {
@Autowired
private AnswerMapper answerMapper;
@Override
public IPage<AnswerVO> findAll(Page<AnswerVO> page) {
return answerMapper.findAll(page);
}
}
package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ExamManage;
import com.exam.mapper.ExamManageMapper;
import com.exam.service.ExamManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ExamManageServiceImpl implements ExamManageService {
@Autowired
private ExamManageMapper examManageMapper;
@Override
public List<ExamManage> findAll() {
return examManageMapper.findAll();
}
@Override
public IPage<ExamManage> findAll(Page<ExamManage> page) {
return examManageMapper.findAll(page);
}
@Override
public ExamManage findById(Integer examCode) {
return examManageMapper.findById(examCode);
}
@Override
public int delete(Integer examCode) {
return examManageMapper.delete(examCode);
}
@Override
public int update(ExamManage exammanage) {
return examManageMapper.update(exammanage);
}
@Override
public int add(ExamManage exammanage) {
return examManageMapper.add(exammanage);
}
@Override
public ExamManage findOnlyPaperId() {
return examManageMapper.findOnlyPaperId();
}
}
package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.FillQuestion;
import com.exam.mapper.FillQuestionMapper;
import com.exam.service.FillQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class FillQuestionServiceImpl implements FillQuestionService {
@Autowired
private FillQuestionMapper fillQuestionMapper;
@Override
public List<FillQuestion> findByIdAndType(Integer paperId) {
return fillQuestionMapper.findByIdAndType(paperId);
}
@Override
public IPage<FillQuestion> findAll(Page<FillQuestion> page) {
return fillQuestionMapper.findAll(page);
}
@Override
public FillQuestion findOnlyQuestionId() {
return fillQuestionMapper.findOnlyQuestionId();
}
@Override
public int add(FillQuestion fillQuestion) {
return fillQuestionMapper.add(fillQuestion);
}
@Override
public List<Integer> findBySubject(String subject, Integer pageNo) {
return fillQuestionMapper.findBySubject(subject,pageNo);
}
}
package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.JudgeQuestion;
import com.exam.mapper.JudgeQuestionMapper;
import com.exam.service.JudgeQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class JudgeQuestionServiceImpl implements JudgeQuestionService {
@Autowired
private JudgeQuestionMapper judgeQuestionMapper;
@Override
public List<JudgeQuestion> findByIdAndType(Integer paperId) {
return judgeQuestionMapper.findByIdAndType(paperId);
}
@Override
public IPage<JudgeQuestion> findAll(Page<JudgeQuestion> page) {
return judgeQuestionMapper.findAll(page);
}
@Override
public JudgeQuestion findOnlyQuestionId() {
return judgeQuestionMapper.findOnlyQuestionId();
}
@Override
public int add(JudgeQuestion judgeQuestion) {
return judgeQuestionMapper.add(judgeQuestion);
}
@Override
public List<Integer> findBySubject(String subject, Integer pageNo) {
return judgeQuestionMapper.findBySubject(subject,pageNo);
}
}
package com.exam.serviceimpl;
import com.exam.entity.Admin;
import com.exam.entity.Student;
import com.exam.entity.Teacher;
import com.exam.mapper.LoginMapper;
import com.exam.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class LoginServiceImpl implements LoginService {
@Autowired
private LoginMapper loginMapper;
@Override
public Admin adminLogin(Integer username, String password) {
return loginMapper.adminLogin(username,password);
}
@Override
public Teacher teacherLogin(Integer username, String password) {
return loginMapper.teacherLogin(username,password);
}
@Override
public Student studentLogin(String username, String password) {
return loginMapper.studentLogin(username,password);
}
@Override
public Student LoginYh(String username, String password) {
return loginMapper.loginYh(username,password);
}
}
package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.Message;
import com.exam.mapper.MessageMapper;
import com.exam.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MessageServiceImpl implements MessageService {
@Autowired
private MessageMapper messageMapper;
@Override
public IPage<Message> findAll(Page page) {
return messageMapper.findAll(page);
}
@Override
public Message findById(Integer id) {
return messageMapper.findById(id);
}
@Override
public int delete(Integer id) {
return messageMapper.delete(id);
}
@Override
public int update(Message message) {
return messageMapper.update(message);
}
@Override
public int add(Message message) {
return messageMapper.add(message);
}
}
package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.MultiQuestion;
import com.exam.mapper.MultiQuestionMapper;
import com.exam.service.MultiQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MultiQuestionServiceImpl implements MultiQuestionService {
@Autowired
private MultiQuestionMapper multiQuestionMapper;
@Override
public List<MultiQuestion> findByIdAndType(Integer PaperId) {
return multiQuestionMapper.findByIdAndType(PaperId);
}
@Override
public IPage<MultiQuestion> findAll(Page<MultiQuestion> page) {
return multiQuestionMapper.findAll(page);
}
@Override
public MultiQuestion findOnlyQuestionId() {
return multiQuestionMapper.findOnlyQuestionId();
}
@Override
public int add(MultiQuestion multiQuestion) {
return multiQuestionMapper.add(multiQuestion);
}
@Override
public List<Integer> findBySubject(String subject, Integer pageNo) {
return multiQuestionMapper.findBySubject(subject,pageNo);
}
}
package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.PaperManage;
import com.exam.mapper.PaperMapper;
import com.exam.service.PaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class PaperServiceImpl implements PaperService {
@Autowired
private PaperMapper paperMapper;
@Override
public List<PaperManage> findAll() {
return paperMapper.findAll();
}
@Override
public List<PaperManage> findById(Integer paperId) {
return paperMapper.findById(paperId);
}
@Override
public int add(PaperManage paperManage) {
return paperMapper.add(paperManage);
}
}
package com.exam.serviceimpl;
import com.exam.entity.Replay;
import com.exam.mapper.ReplayMapper;
import com.exam.service.ReplayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ReplayServiceImpl implements ReplayService {
@Autowired
private ReplayMapper replayMapper;
@Override
public List<Replay> findAll() {
return replayMapper.findAll();
}
@Override
public List<Replay> findAllById(Integer messageId) {
return replayMapper.findAllById(messageId);
}
@Override
public Replay findById(Integer replayId) {
return replayMapper.findById(replayId);
}
@Override
public int delete(Integer replayId) {
return replayMapper.delete(replayId);
}
@Override
public int update(Replay replay) {
return replayMapper.update(replay);
}
@Override
public int add(Replay replay) {
return replayMapper.add(replay);
}
}
package com.exam.serviceimpl;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.DwScoreTj;
import com.exam.entity.Score;
import com.exam.entity.StudentScoreTj;
import com.exam.mapper.ScoreMapper;
import com.exam.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class ScoreServiceImpl implements ScoreService {
NumberFormat percentInstance = NumberFormat.getPercentInstance();
@Autowired
private ScoreMapper scoreMapper;
@Override
public int add(Score score) {
return scoreMapper.add(score);
}
@Override
public List<Score> findAll() {
return scoreMapper.findAll();
}
@Override
public IPage<Score> findById(Page page, String studentId) {
return scoreMapper.findById(page, studentId);
}
@Override
public List<Score> findById(String studentId) {
return scoreMapper.findById(studentId);
}
@Override
public StudentScoreTj findTjById(String studentId) {
// 个人的:答题次数,答题量,答题正确率,总成绩
percentInstance.setMinimumFractionDigits(2);
StudentScoreTj studentScoreTj = scoreMapper.findTjById(studentId);
int dtcount = 0;
String bfs = "0%" ;
studentScoreTj.setRight(bfs);
studentScoreTj.setDtcount(dtcount);
if(null != studentScoreTj){
dtcount = studentScoreTj.getCount() * 1;
studentScoreTj.setDtcount(dtcount);
if(dtcount!=0&studentScoreTj.getCountsum()!=0){
String bfsRight = percentInstance.format((double) (studentScoreTj.getCountsum())/(dtcount));
studentScoreTj.setRight(bfsRight);
}
}
studentScoreTj.setStudentId(studentId);
return studentScoreTj;
}
@Override
public List<DwScoreTj> findTjDw() {
// 管理员:单位,答题人数,答题次数,答题正确率,总成绩
percentInstance.setMinimumFractionDigits(2);
List<DwScoreTj> findTjDw = scoreMapper.findTjDw();
findTjDw.stream().forEach(p->{
int dtcount = 0;
String right = "0%";
dtcount = p.getCount() * 1;
if(p.getCountsum()!=0&&dtcount!=0){
right = percentInstance.format((double) (p.getCountsum())/(dtcount));
}
p.setDtcount(dtcount);
p.setRight(right);
});
findTjDw = findTjDw.stream() .filter(d -> !StringUtils.isEmpty(d.getClazz())).collect(Collectors.toList()).stream().sorted(Comparator.comparing(DwScoreTj::getCountsum).reversed()).collect(Collectors.toList());
return findTjDw;
}
@Override
public IPage<StudentScoreTj> findTjTsDw(Page<StudentScoreTj> page,String clazz) {
percentInstance.setMinimumFractionDigits(2);
IPage<StudentScoreTj> listPage = scoreMapper.findTjTsDw(page,clazz);
listPage.getRecords().stream().forEach(p->{
int dtcount = 0;
String right = "0%";
dtcount = p.getCount() * 1;
if(p.getCountsum()!=0&&dtcount!=0){
right = percentInstance.format((double) (p.getCountsum())/(dtcount));
}
p.setDtcount(dtcount);
p.setRight(right);
});
return listPage;
}
@Override
public List<Score> findByExamCode(Integer examCode) {
return scoreMapper.findByExamCode(examCode);
}
}
package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.Student;
import com.exam.mapper.StudentMapper;
import com.exam.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;
@Override
public IPage<Student> findAll(Page<Student> page) {
return studentMapper.findAll(page);
}
@Override
public Student findById(String studentId) {
return studentMapper.findById(studentId);
}
@Override
public int deleteById(String studentId) {
return studentMapper.deleteById(studentId);
}
@Override
public int update(Student student) {
return studentMapper.update(student);
}
@Override
public int updatePwd(Student student) {
return studentMapper.updatePwd(student);
}
@Override
public int add(Student student) {
return studentMapper.add(student);
}
}
package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.Teacher;
import com.exam.mapper.TeacherMapper;
import com.exam.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TeacherServiceImpl implements TeacherService {
@Autowired
private TeacherMapper teacherMapper;
@Override
public IPage<Teacher> findAll(Page<Teacher> page) {
return teacherMapper.findAll(page);
}
@Override
public List<Teacher> findAll() {
return teacherMapper.findAll();
}
@Override
public Teacher findById(Integer teacherId) {
return teacherMapper.findById(teacherId);
}
@Override
public int deleteById(Integer teacherId) {
return teacherMapper.deleteById(teacherId);
}
@Override
public int update(Teacher teacher) {
return teacherMapper.update(teacher);
}
@Override
public int add(Teacher teacher) {
return teacherMapper.add(teacher);
}
}
package com.exam.util;
import com.exam.entity.ApiResult;
public class ApiResultHandler {
public static ApiResult success(Object object) {
ApiResult apiResult = new ApiResult();
apiResult.setData(object);
apiResult.setCode(200);
apiResult.setMessage("请求成功");
return apiResult;
}
public static ApiResult success() {
return success(null);
}
public static <T> ApiResult buildApiResult(Integer code, String message, T data) {
ApiResult apiResult = new ApiResult();
apiResult.setCode(code);
apiResult.setMessage(message);
apiResult.setData(data);
return apiResult;
}
}
package com.exam.util;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* @Description 常用获取客户端信息的工具
*/
public class NetworkUtil {
/**
* 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址;
*
* @param request
* @return
* @throws
*/
/**
* 获取当前网络ip
* @param request
* @return
*/
public static String getIpAddr(HttpServletRequest request){
String ipAddress = request.getHeader("X-Real-IP");
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
if("127.0.0.1".equals(ipAddress) ||
"0:0:0:0:0:0:0:1".equals(ipAddress)){
//根据网卡取本机配置的IP
InetAddress inet=null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
ipAddress= inet.getHostAddress();
}
}
//对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
if(ipAddress!=null && ipAddress.length()>15){
//"***.***.***.***".length() = 15
if(ipAddress.indexOf(",")>0){
ipAddress = ipAddress.substring(0,ipAddress.indexOf(","));
}
}
return ipAddress;
}
}
package com.exam.vo;
import lombok.Data;
@Data
public class AnswerVO {
private String question;
private String subject;
private String score;
private String section;
private String level;
private String type;
}
package com.exam.vo;
import lombok.Data;
//题目模型
@Data
public class Item {
private String subject;
private Integer paperId;
private Integer changeNumber;
private Integer fillNumber;
private Integer judgeNumber;
}
spring.datasource.username=root
spring.datasource.password=gkptCcYy123
spring.datasource.url=jdbc:mysql://47.92.48.137:3900/gkpt?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
mybatis.configuration.mapUnderscoreToCamelCase=true
\ No newline at end of file
spring.datasource.username=root
spring.datasource.password=founder123
spring.datasource.url=jdbc:mysql://77.1.24.51:3306/test?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
mybatis.configuration.mapUnderscoreToCamelCase=true
spring.profiles.active=dev
server.port=8080
logging.level.com.exam.mapper=debug
/*
package com.exam;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ExamsystemApplicationTests {
@Test
public void contextLoads() {
}
}
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment