返回顶部
首页 > 资讯 > 后端开发 > Python >JavaOnlineExam在线考试系统的实现
  • 808
分享到

JavaOnlineExam在线考试系统的实现

2024-04-02 19:04:59 808人浏览 泡泡鱼

Python 官方文档:入门教程 => 点击学习

摘要

一、项目简述 本系统主要实现的功能有: 学生以及老师的注册登录,在线考试,错题查询,学生管理,问题管理,错题管理,错题查询,分数查询,试卷管 理,人工组卷。自动组卷,教师,班级,统计

一、项目简述

本系统主要实现的功能有: 学生以及老师的注册登录,在线考试,错题查询,学生管理,问题管理,错题管理,错题查询,分数查询,试卷管 理,人工组卷。自动组卷,教师,班级,统计等等管理功能。

二、项目运行

环境配置: jdk1.8 + Tomcat8.5 + Mysql + Eclispe (IntelliJ idea,Eclispe,MyEclispe,Sts 都支持)

项目技术: Vue+SpringBoot+ springMVC + mybatis + ThymeLeaf + javascript + Jquery + ajax + Maven等等

课程信息控制器:


 

@RestController
@RequestMapping(value = "/v1/subjects")
public class SubjectController {
 
    private static Logger logger = LoggerFactory.getLogger(SubjectController.class);
 
    @Autowired
    SubjectService subjectService;
 
    @apiOperation(value = "获取科目列表", notes = "")
    @RequestMapping(value = "", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public PageInfo<Subject> getSubjectList(@RequestParam(required = false) Integer pageIndex,
                                        @RequestParam(required = false) Integer pageSize,
                                        @RequestParam(required = false) Integer limit,
                                        @RequestParam(required = false) Integer offset) {
        if(pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<Subject> subjects = subjectService.getSubjectList();
        PageInfo pageInfo = new PageInfo(subjects);
        return pageInfo;
    }
 
    @ApiOperation(value = "根据名字获取科目信息", notes = "根据科目名称获取科目详细信息")
    @ApiImplicitParam(name = "name", value = "科目名称", required = true, dataType = "String", paramType = "path")
    @RequestMapping(value = "/{name}/name", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public List<Subject> getSubjectByName(@PathVariable String name) {
        return subjectService.getSubjectFuzzy(name);
    }
 
 
    @ApiOperation(value = "获取课程信息", notes = "根据课程id获取课程详细信息")
    @ApiImplicitParam(name = "idOrName", value = "课程ID或名称", required = true, dataType = "String", paramType = "path")
    @RequestMapping(value = "/search/{idOrName}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public List<Subject> getSubjectForSearch(@PathVariable String idOrName) {
        List<Subject> subjects = new ArrayList<Subject>();
        Subject subject = subjectService.getSubjectByName(idOrName);
        if (subject == null) {
            try {
                subject = subjectService.getSubjectById(idOrName);
            } catch (Exception e) {
 
            }
        }
        if (subject != null) {
            subjects.add(subject);
        }
        return subjects;
    }
 
    @ApiOperation(value = "创建课程", notes = "创建课程")
    @ApiImplicitParam(name = "subject", value = "课程实体Subject", required = true, dataType = "Subject")
    @RequestMapping(value = "", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public ResponseEntity<?> postSubject(@RequestBody Subject subject) {
        if(subjectService.getSubjectByName(subject.getName()) != null) {
            return new ResponseEntity<Object>(new Dto("课程已存在!"), httpstatus.INTERNAL_SERVER_ERROR);
        }
        subjectService.saveSubject(subject);
        return new ResponseEntity(HttpStatus.CREATED);
    }
 
    @ApiOperation(value = "获取课程信息", notes = "根据课程id获取课程详细信息")
    @ApiImplicitParam(name = "id", value = "课程ID", required = true, dataType = "String", paramType = "path")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public Subject getSubject(@PathVariable String id) {
        return subjectService.getSubjectById(id);
    }
 
    @ApiOperation(value = "更新课程信息", notes = "根据课程id更新用户信息")
    @ApiImplicitParam(name = "subject", value = "课程实体", required = true, dataType = "Subject")
    @RequestMapping(value = "", method = RequestMethod.PUT)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public ResponseEntity<?> putSubject(@RequestBody Subject subject) {
        subjectService.updateSubject(subject);
        return new ResponseEntity(HttpStatus.OK);
    }
 
    @ApiOperation(value = "删除课程", notes = "根据课程id删除课程")
    @ApiImplicitParam(name = "id", value = "课程ID", required = true, dataType = "Long", paramType = "path")
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public ResponseEntity<?> deleteSubject(@PathVariable String id) {
        try {
            subjectService.deleteSubject(id);
        }catch (RuntimeException e) {
            return new ResponseEntity(new Dto("该课程包含有考试,不能删除"), HttpStatus.INTERNAL_SERVER_ERROR);
        }
        return new ResponseEntity(HttpStatus.OK);
    }
}
 

题目信息控制器:



 
@RestController
@RequestMapping(value = "/v1/questions")
public class QuestionController {
 
    private static Logger logger = LoggerFactory.getLogger(QuestionController.class);
 
    @Autowired
    QuestionService questionService;
 
    @Autowired
    PaperAnswerPaperService paperAnswerPaperService;
 
    @ApiOperation(value = "获取题目分页列表", notes = "")
    @RequestMapping(value = "", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public PageInfo<Question> getQuestionListByPage(@RequestParam(required = false) Integer pageIndex,
                                                    @RequestParam(required = false) Integer pageSize,
                                                    @RequestParam(required = false) Integer limit,
                                                    @RequestParam(required = false) Integer offset) {
        if(pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<Question> questions = questionService.getQuestionList();
        PageInfo pageInfo = new PageInfo(questions);
        return pageInfo;
    }
 
    @ApiOperation(value = "获取试卷题目分页列表", notes = "")
    @RequestMapping(value = "/papers/{paperId}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public PageInfo<Question> getQuestionListByPaper(@PathVariable String paperId,
                                                     @RequestParam(required = false) Integer pageIndex,
                                                     @RequestParam(required = false) Integer pageSize,
                                                     @RequestParam(required = false) Integer limit,
                                                     @RequestParam(required = false) Integer offset) {
        if(pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<Question> questions = questionService.getQuestionListByPaper(paperId);
        PageInfo pageInfo = new PageInfo(questions);
        return pageInfo;
    }
 
    @ApiOperation(value = "获取试卷题目数量", notes = "")
    @RequestMapping(value = "/papers/{paperId}/count", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public ResponseEntity<?> getQuestionCountByPaper(@PathVariable String paperId) {
        Integer count = questionService.countByPaperId(paperId);
        return new ResponseEntity<Object>(count, HttpStatus.OK);
    }
 
    @ApiOperation(value = "创建题目", notes = "创建题目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "question", value = "题目实体Question", required = true, dataType = "Question"),
            @ApiImplicitParam(name = "id", value = "试卷id", required = true, dataType = "String", paramType = "path")
    })
    @RequestMapping(value = "/{id}", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public ResponseEntity<?> postQuestion(@PathVariable("id") String id, @RequestBody Question question) {
        questionService.saveQuestion(id, question);
        return new ResponseEntity(HttpStatus.CREATED);
    }
 
    @ApiOperation(value = "获取题目信息", notes = "根据题目id获取题目详细信息")
    @ApiImplicitParam(name = "id", value = "题目ID", required = true, dataType = "String", paramType = "path")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public Question getQuestion(@PathVariable String id) {
        return questionService.getQuestion(id);
    }
 
    @ApiOperation(value = "根据试卷id和题目编号获取题目信息", notes = "根据题目id获取题目详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paperId", value = "试卷ID", required = true, dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "number", value = "题目编号", required = true, dataType = "String", paramType = "path")
    })
    @RequestMapping(value = "/papers/{paperId}/questions/{number}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public Question getQuestionByPaperIdAndQuestionId(@PathVariable String paperId,
                                                      @PathVariable Integer number,
                                                      @RequestParam(required = false) String answerPaperId) {
        PaperAnswerPaper paperAnswerPaper = null;
        //传入的是答卷Id
        if(answerPaperId != null) {
            // TODO: 2017-04-17
            paperAnswerPaper = paperAnswerPaperService.getByAnswerPaperId(answerPaperId);
            if(paperAnswerPaper != null) {
                return questionService.getQuestionByPaperIdAndQuestionNumber(paperAnswerPaper.getPaperId(), number);
            }else {
                logger.error("根据答卷id获取答卷失败");
            }
        }
        return questionService.getQuestionByPaperIdAndQuestionNumber(paperId, number);
    }
 
    @ApiOperation(value = "获取题目信息", notes = "根据题目name获取题目详细信息")
    @ApiImplicitParam(name = "name", value = "试卷name", required = true, dataType = "String", paramType = "path")
    @RequestMapping(value = "/name/{name}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public List<Question> getQuestionByName(@PathVariable String name) {
        //模糊查询
        return questionService.getQuestionFuzzy(name);
    }
 
    @ApiOperation(value = "获取题目信息", notes = "根据试卷id获取所有题目")
    @ApiImplicitParam(name = "paperId", value = "试卷ID", required = true, dataType = "String", paramType = "path")
    @RequestMapping(value = "/papers/{paperId}/questions", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public List<Question> getQuestionByPaperId(@PathVariable String paperId) {
        return questionService.getQuestionByPaperId(paperId);
    }
 
    @ApiOperation(value = "获取题目信息", notes = "根据试卷id获取所有题目,但不返回答案")
    @ApiImplicitParam(name = "paperId", value = "试卷ID", required = true, dataType = "String", paramType = "path")
    @RequestMapping(value = "/papers/{paperId}/ignore", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public List<Question> getQuestionByPaperIdIgnoreAnswer(@PathVariable String paperId) {
        return questionService.getQuestionByPaperIdIgnoreAnswer(paperId);
    }
 
    @ApiOperation(value = "更新题目信息", notes = "根据题目id更新题目信息")
    @ApiImplicitParam(name = "question", value = "题目实体", required = true, dataType = "Question")
    @RequestMapping(value = "", method = RequestMethod.PUT)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public ResponseEntity<?> putQuestion(@RequestBody Question question) {
        questionService.updateQuestion(question);
        return new ResponseEntity(HttpStatus.OK);
    }
 
    @ApiOperation(value = "删除题目", notes = "根据题目id删除试卷")
    @ApiImplicitParam(name = "id", value = "题目ID", required = true, dataType = "String", paramType = "path")
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public ResponseEntity<?> deleteQuestion(@PathVariable String id) {
        questionService.deleteQuestion(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}

考试控制层,负责试卷提交等:



@RestController
@RequestMapping("/v1/exam")
public class ExamController {
 
    @Autowired
    ExamService examService;
 
    @Autowired
    AnswerPaperService answerPaperService;
 
    @Autowired
    AnswerQuestionService answerQuestionService;
 
    @Autowired
    AnswerPaperQuestionService answerPaperQuestionService;
 
    @Autowired
    QuestionService questionService;
 
    @Autowired
    PaperService paperService;
 
    @Autowired
    WrongQuestionService wrongQuestionService;
 
    @Autowired
    PaperAnswerPaperService paperAnswerPaperService;
 
    @ApiOperation(value = "根据试卷id和题目编号获取题目信息", notes = "根据题目id获取题目详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paperId", value = "试卷ID", required = true, dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "number", value = "题目编号", required = true, dataType = "String", paramType = "path")
    })
    @RequestMapping(value = "/questions/{number}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public Question getQuestionByPaperIdAndQuestionId(@RequestParam String paperId,
                                                      @RequestParam String username,
                                                      @RequestParam(required = false) String answerPaperId,
                                                      @PathVariable Integer number) {
        Question question = null;
        AnswerQuestion answerQuestion = null;
        if(answerPaperId == null) {
            Paper paper = paperService.getPaperById(paperId);
            if(paper != null) {
                AnswerPaper answerPaper = answerPaperService.findByAnswerUserAndPaperName(username, paper.getName());
                if(answerPaper != null) {
                    answerQuestion = answerQuestionService.getAnswerQuestionByPaperIdAndQuestionNumber(answerPaper.getId(), number);
                }
            }
        }else {
            answerQuestion = answerQuestionService.getAnswerQuestionByPaperIdAndQuestionNumber(answerPaperId, number);
        }
 
        if(answerQuestion == null) {
            question = questionService.getQuestionByPaperIdAndQuestionNumber(paperId, number);
            if(question != null) {
                //答案不返回
                question.setAnswer("");
            }
        } else {
            question = new Question();
            question.setId(answerQuestion.getId());
            question.setNumber(answerQuestion.getNumber());
            question.setTitle(answerQuestion.getTitle());
            question.setScore(answerQuestion.getScore());
            question.setType(answerQuestion.getType());
            question.setOptionA(answerQuestion.getOptionA());
            question.setOptionB(answerQuestion.getOptionB());
            question.setOptionC(answerQuestion.getOptionC());
            question.setOptionD(answerQuestion.getOptionD());
            question.setAnswer(answerQuestion.getAnswer());
        }
        return question;
    }
 
    @RequestMapping(value = "/submit/{type}/{username}", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public ResponseEntity<?> submit(@RequestBody Paper paper, @PathVariable String type,
                                    @PathVariable String username,
                                    @RequestParam(required = false) String answerPaperId) {
        
        if(type.equals("official")) {
            
            AnswerPaper answerPaper = new AnswerPaper();
            if(answerPaperId != null) {
                answerPaper.setId(answerPaperId);
            }else {
                return new ResponseEntity<Object>(HttpStatus.INTERNAL_SERVER_ERROR);
            }
            answerPaper.setAnswerTime(new SimpleDateFORMat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            answerPaper.setPaperName(paper.getName());
            answerPaper.setAnswerUser(username);
            answerPaper.setChecked("false");
            answerPaper.setFinished("true");
            answerPaper.setType("official");
            examService.updateAnswerPaper(answerPaper);
        } else if(type.equals("simulate")) {
            
            AnswerPaper answerPaper = new AnswerPaper();
            if(answerPaperId != null) {
                answerPaper.setId(answerPaperId);
            }else {
                return new ResponseEntity<Object>(HttpStatus.INTERNAL_SERVER_ERROR);
            }
            answerPaper.setAnswerTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            answerPaper.setPaperName(paper.getName());
            answerPaper.setAnswerUser(username);
            answerPaper.setChecked("false");
            answerPaper.setFinished("true");
            answerPaper.setType("simulate");
            examService.updateAnswerPaper(answerPaper);
        }else if(type.equals("practice")) {
            
            int score = 0;
 
            //正确题目数
            double right = 0.0;
 
            //错误题目数
            double wrong = 0.0;
 
            double correctRate = 0.0;
 
            List<Question> questions = questionService.getQuestionByPaperId(paper.getId());
 
            AnswerPaper answerPaper = answerPaperService.findByAnswerUserAndPaperName(username, paper.getName());
 
            List<AnswerQuestion> answerQuestions = answerQuestionService.findByAnswerPaperId(answerPaper.getId());
 
            
            List<DtoRightAndWrong> results = new ArrayList<DtoRightAndWrong>();
 
            DtoRightAndWrong dtoRightAndWrong = null;
 
            //遍历提交的试卷的题目
            for(AnswerQuestion answerQuestion : answerQuestions) {
 
                //遍历包含正确答案的题目
                for(Question question : questions) {
                    
                    if(answerQuestion.getNumber().equals(question.getNumber())) {
                        if(answerQuestion.getAnswer().equals(question.getAnswer())) {
                            
                            score += Integer.parseInt(question.getScore());
                            right ++;
                        }else {
                            wrong ++;
                            //记录错题
                            dtoRightAndWrong = new DtoRightAndWrong();
                            dtoRightAndWrong.setQuestion(question);
                            dtoRightAndWrong.setAnswerQuestion(answerQuestion);
                            results.add(dtoRightAndWrong);
 
                            //保存错题
                            WrongQuestion wrongQuestion = new WrongQuestion();
                            try{
                                BeanUtils.copyProperties(wrongQuestion, answerQuestion);
                                wrongQuestion.setUsername(username);
                                wrongQuestion.setRightAnswer(question.getAnswer());
                                wrongQuestion.setAnalysis(question.getAnalysis());
                                if(wrongQuestionService.getWrongQuestion(wrongQuestion.getId()) == null) {
                                    wrongQuestionService.saveQuestion(wrongQuestion);
                                }
                            }catch (Exception e) {
                                System.out.println(wrongQuestion.toString());
                            }
 
                        }
                    }
                }
            }
            //计算正确率
            correctRate = (right/(right + wrong)) * 100;
 
            DtoResult result = new DtoResult();
            result.setScore(score);
            result.setRight(right);
            result.setWrong(wrong);
            result.setCorrectRate(correctRate);
            result.setResults(results);
 
            Paper paper1 = paperService.getPaperById(paper.getId());
            //更新参与人数
            paper1.setPeoples(String.valueOf(Integer.parseInt(paper1.getPeoples()) + 1));
            paperService.updatePaper(paper1);
 
            return new ResponseEntity<Object>(result, HttpStatus.OK);
        }
        Paper paper1 = paperService.getPaperById(paper.getId());
        //更新参与人数
        paper1.setPeoples(String.valueOf(Integer.parseInt(paper1.getPeoples() + 1)));
        paperService.updatePaper(paper1);
        return new ResponseEntity<Object>(HttpStatus.OK);
    }
 
    
    @RequestMapping(value = "/submit/one/{username}", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public ResponseEntity<?> submitOne(@PathVariable String username, @RequestBody DtoAnswerPaper dtoAnswerPaper) {
        Paper paper = dtoAnswerPaper.getPaper();
        Question question = dtoAnswerPaper.getQuestion();
        //判断数据库是否保存了这次答卷
        AnswerPaper answerPaper = answerPaperService.getAnswerPaperByNameAndUser(paper.getName(), username);
        AnswerQuestion answerQuestion = null;
        AnswerPaperQuestion answerPaperQuestion = null;
        List<AnswerQuestion> answerQuestions = null;
        //重新生成id
        String answerPaperId = IdGen.uuid();
        String answerQuestionId = IdGen.uuid();
        //答卷为空,则执行保存
        if(answerPaper == null) {
            answerPaper = new AnswerPaper();
            answerPaper.setId(answerPaperId);
            answerPaper.setAnswerTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            answerPaper.setPaperName(paper.getName());
            answerPaper.setType(paper.getType());
            answerPaper.setAnswerUser(username);
            answerPaper.setChecked("false");
            answerPaper.setFinished("false");
 
            //保存答卷
            answerPaperService.saveAnswerPaper(answerPaper);
 
            // TODO: 2017-04-17 保存试卷答卷
            PaperAnswerPaper paperAnswerPaper = new PaperAnswerPaper();
            paperAnswerPaper.setPaperId(paper.getId());
            paperAnswerPaper.setAnswerPaperId(answerPaperId);
            paperAnswerPaperService.save(paperAnswerPaper);
 
            //新记录
            answerQuestion = new AnswerQuestion();
            //初始化信息
            answerQuestion.setId(answerQuestionId);
            answerQuestion.setTitle(question.getTitle());
            answerQuestion.setType(question.getType());
            answerQuestion.setNumber(question.getNumber());
            answerQuestion.setOptionA(question.getOptionA());
            answerQuestion.setOptionB(question.getOptionB());
            answerQuestion.setOptionC(question.getOptionC());
            answerQuestion.setOptionD(question.getOptionD());
            answerQuestion.setContent(question.getContent());
            answerQuestion.setScore(question.getScore());
            answerQuestion.setAnalysis(question.getAnalysis());
            answerQuestion.setAnswer(question.getAnswer());
 
 
            answerPaperQuestion = new AnswerPaperQuestion();
            answerPaperQuestion.setAnswerPaperId(answerPaper.getId());
            answerPaperQuestion.setAnswerQuestionId(answerQuestionId);
 
            //保存
            answerQuestionService.saveAnswerQuestion(answerQuestion);
            answerPaperQuestionService.saveAnswerPaperQuestion(answerPaperQuestion);
 
            return new ResponseEntity<Object>(answerPaper, HttpStatus.OK);
        } else {
            answerQuestions = answerQuestionService.findByAnswerPaperId(answerPaper.getId());
            if(answerQuestions != null && answerQuestions.size() > 0) {
                int count = 0;
                AnswerQuestion existAnswerQuestion = null;
                for(AnswerQuestion question1 : answerQuestions) {
                    if (question1.getNumber().equals(question.getNumber())) {
                        count++;
                        existAnswerQuestion = question1;//保存当前存在的记录
                    }
                }
                //记录不存在
                if(count == 0) {
                    //新记录
                    answerQuestion = new AnswerQuestion();
                    answerPaperQuestion = new AnswerPaperQuestion();
 
 
                    answerQuestion = new AnswerQuestion();
                    //初始化信息
                    answerQuestion.setId(answerQuestionId);
                    answerQuestion.setTitle(question.getTitle());
                    answerQuestion.setType(question.getType());
                    answerQuestion.setNumber(question.getNumber());
                    answerQuestion.setOptionA(question.getOptionA());
                    answerQuestion.setOptionB(question.getOptionB());
                    answerQuestion.setOptionC(question.getOptionC());
                    answerQuestion.setOptionD(question.getOptionD());
                    answerQuestion.setContent(question.getContent());
                    answerQuestion.setScore(question.getScore());
                    answerQuestion.setAnalysis(question.getAnalysis());
                    answerQuestion.setAnswer(question.getAnswer());
 
 
                    answerPaperQuestion = new AnswerPaperQuestion();
                    answerPaperQuestion.setAnswerPaperId(answerPaper.getId());
                    answerPaperQuestion.setAnswerQuestionId(answerQuestionId);
 
                    //保存
                    answerQuestionService.saveAnswerQuestion(answerQuestion);
                    answerPaperQuestionService.saveAnswerPaperQuestion(answerPaperQuestion);
                } else {
                    //记录存在,则执行更新
                    // TODO: 2017/3/30
                    //更新当前存在的记录
                    existAnswerQuestion.setAnswer(question.getAnswer());
 
                    answerQuestionService.updateAnswerQuestion(existAnswerQuestion);
                }
            }
        }
        return new ResponseEntity<Object>(answerPaper, HttpStatus.OK);
    }
}

答卷控制层,用于获取已经提交的答卷:



@RestController
@RequestMapping("/v1/answer-papers")
public class AnswerPaperController {
 
    @Autowired
    AnswerPaperService answerPaperService;
 
    @Autowired
    AnswerQuestionService answerQuestionService;
 
    
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public AnswerPaper getAnswerPaper(@PathVariable String id) {
        return answerPaperService.getAnswerPaperById(id);
    }
 
    
    @RequestMapping(value = "/name/{name}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public List<AnswerPaper> getAnswerPaperByName(@PathVariable String name) {
        return answerPaperService.getAnswerPaperFuzzy(name);
    }
 
    
    @RequestMapping(value = "/papers/{paperId}/questions/{number}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public AnswerQuestion getQuestionByPaperIdAndQuestionId(@PathVariable String paperId, @PathVariable Integer number) {
        AnswerQuestion answerQuestion = answerQuestionService.getAnswerQuestionByPaperIdAndQuestionNumber(paperId, number);
        return answerQuestion;
    }
 
    
    @RequestMapping(value = "/users/{username}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public PageInfo<AnswerPaper> getListByUser(@PathVariable("username") String username,
                                               @RequestParam(required = false) Integer pageIndex,
                                               @RequestParam(required = false) Integer pageSize,
                                               @RequestParam(required = false) Integer limit,
                                               @RequestParam(required = false) Integer offset) {
        if(pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<AnswerPaper> answerPapers = answerPaperService.getAnswerPaperListByAnswerUser(username);
        PageInfo pageInfo = new PageInfo(answerPapers);
        return pageInfo;
    }
 
    @RequestMapping(value = "/users/{username}/type/{type}", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public PageInfo<AnswerPaper> getListByUserAndType(@PathVariable("username") String username,
                                                @PathVariable("type") String type,
                                                @RequestParam(required = false) Integer pageIndex,
                                                @RequestParam(required = false) Integer pageSize,
                                                @RequestParam(required = false) Integer limit,
                                                @RequestParam(required = false) Integer offset) {
        if(pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<AnswerPaper> answerPapers = answerPaperService.getAnswerPaperListByAnswerUserAndType(username, type);
        PageInfo pageInfo = new PageInfo(answerPapers);
        return pageInfo;
    }
 
    
    @RequestMapping("/check")
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public DtoTask countUnCheckAnswerPaper() {
        DtoTask dtoTask = new DtoTask();
        Integer checked = answerPaperService.countCheck("true");
        Integer unChecked = answerPaperService.countCheck("false");
        dtoTask.setChecked(checked);
        dtoTask.setUnChecked(unChecked);
        return dtoTask;
    }
 
    
    @RequestMapping(value = "", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public PageInfo<AnswerPaper> getListByUser(@RequestParam(required = false) Integer pageIndex,
                                               @RequestParam(required = false) Integer pageSize,
                                               @RequestParam(required = false) Integer limit,
                                               @RequestParam(required = false) Integer offset) {
        if(pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<AnswerPaper> answerPapers = answerPaperService.getAnswerPaperList();
        PageInfo pageInfo = new PageInfo(answerPapers);
        return pageInfo;
    }
 
    
    @RequestMapping(value = "", method = RequestMethod.PUT)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public ResponseEntity<?> putPaper(@RequestBody AnswerPaper answerPaper) {
        answerPaperService.updatePaper(answerPaper);
        return new ResponseEntity(HttpStatus.OK);
    }
 
    
    @RequestMapping(value = "/{id}/calculate", method = RequestMethod.PUT)
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
    public ResponseEntity<?> CalculationScore(@PathVariable String id) {
        
        List<AnswerQuestion> questions = answerQuestionService.findByAnswerPaperId(id);
        if(questions != null && questions.size() > 0) {
 
            int score = 0;
            try {
                for(AnswerQuestion question : questions) {
                    score += Integer.parseInt(question.getMarkScore());
                }
            } catch (Exception e) {
                // TODO: 2017/4/1
            }
 
            
 
            AnswerPaper answerPaper = new AnswerPaper();
            answerPaper.setId(id);
            answerPaper.setScore(Integer.toString(score));
            answerPaper.setChecked("true");
            answerPaperService.updatePaper(answerPaper);
        } else {
            // TODO: 2017/4/1
        }
        return new ResponseEntity<Object>(HttpStatus.OK);
    }
 
    @RequestMapping(value = "/analysis/paper")
    @PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
    public List<PaperAnalysis> analysisPaper() {
        return answerPaperService.analysisPaper();
    }
}

以上就是Java Online Exam在线考试系统的实现的详细内容,更多关于Java 在线考试系统的资料请关注编程网其它相关文章!

--结束END--

本文标题: JavaOnlineExam在线考试系统的实现

本文链接: https://lsjlt.com/news/158150.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • JavaOnlineExam在线考试系统的实现
    一、项目简述 本系统主要实现的功能有: 学生以及老师的注册登录,在线考试,错题查询,学生管理,问题管理,错题管理,错题查询,分数查询,试卷管 理,人工组卷。自动组卷,教师,班级,统计...
    99+
    2024-04-02
  • Java Online Exam在线考试系统怎么实现
    这篇文章主要介绍“Java Online Exam在线考试系统怎么实现”,在日常操作中,相信很多人在Java Online Exam在线考试系统怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好...
    99+
    2023-06-21
  • Java如何实现在线高中考试系统
    这篇文章主要介绍了Java如何实现在线高中考试系统,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。项目分为前台和后台,前台主要为学生角色、后台主要为管理员角色。管理员添加试题和...
    99+
    2023-06-29
  • 基于python在线考试系统设计与实现
    主要讲解本系统设计到的文件和所存在路径等 系统发布和使用   系统访问 默认访问系统页面:http://127.0.0.1:8000/ 后台管理登录页面:http://127.0.0.1:8000//ht/ 默认账号admin 密码123...
    99+
    2023-09-12
    python 前端 爬虫
  • Java实现考试系统
    本文实例为大家分享了Java实现考试系统的具体代码,供大家参考,具体内容如下 说明 这里的考试系统是指由学生,老师以及考试机构成的,学生通过用户名,密码登录考试机,考试机从题库中随机...
    99+
    2024-04-02
  • Java毕业设计实战之在线高中考试系统的实现
    项目分为前台和后台,前台主要为学生角色、后台主要为管理员角色。 管理员添加试题和发布试卷,学生负责在线考试、在线查看成绩和错题记录列表等。 管理员功能有:年级管理、课程管理、试题管理...
    99+
    2024-04-02
  • 如何利用C++实现一个简单的在线考试系统?
    如何利用C++实现一个简单的在线考试系统?随着网络技术和计算机科学的快速发展,在线教育和远程学习越来越受到人们的重视。而在线考试系统则成为了教育机构和企业用于评估学生和员工能力的重要工具。本文将介绍如何利用C++编程语言实现一个简单的在线考...
    99+
    2023-11-03
    C++ 系统实现 在线考试
  • 如何使用Go语言和Redis实现在线考试系统
    如何使用Go语言和Redis实现在线考试系统概述:在线考试系统是一种实现在线考试的应用程序。通过使用Go语言和Redis数据库,我们可以构建一个高效、可扩展和可靠的在线考试系统。本文将介绍如何使用Go语言和Redis来设计和实现一个基本的在...
    99+
    2023-10-26
    Go语言 redis 在线考试系统
  • Java在线考试云平台的实现
    考试流程: 用户前台注册成为学生 管理员后台添加老师,系统将该用户角色上升为老师 老师登录,添加考试,添加题目,发布考试 考生登录前台参加考试,交卷...
    99+
    2024-04-02
  • 【计算机毕业设计】在线考试系统
    一、系统截图(需要演示视频可以私聊) 摘 要 本论文主要论述了如何使用JAVA语言开发一个在线考试系统,本系统将严格按照软件开发流程进行各个阶段的工作,采用B/S架构,面向对象编程思想进行项目开发。在引言中,作者将论述...
    99+
    2023-09-12
    java 数据库 前端 计算机毕业设计 mysql
  • 利用php和Websocket开发在线考试系统
    标题:利用PHP和Websocket开发在线考试系统引言:随着互联网的快速发展,传统的教育方式逐渐被在线教育所取代。在线考试系统作为在线教育的一大重要组成部分,其方便、快捷、实时性等特点受到了广大教育工作者和学生的青睐。本文将介绍如何利用P...
    99+
    2023-12-09
    websocket PHP编程 在线考试系统
  • 如何设计MySQL表结构来支持在线考试系统的考试成绩统计?
    如何设计MySQL表结构来支持在线考试系统的考试成绩统计?简介在线考试系统是现代教育的重要组成部分之一。为了对学生的考试成绩进行统计和分析,需要设计适合的数据库表结构来存储考试信息。本文将介绍如何设计MySQL表结构来支持在线考试系统的考试...
    99+
    2023-10-31
    MySQL 表结构 考试成绩统计
  • 在线考试系统从Windows系统迁移到Linux系统的整个过程
    原运行环境:操作系统:Windows Server 2003数据库系统:MySQL Server 5.0Web服务器软件:Apache2编程语言:PHP现运行环境:操作系统:CentOS release 6...
    99+
    2024-04-02
  • 在线考试系统的MySQL表结构设计指南
    在线考试系统的MySQL表结构设计指南一、引言随着互联网技术的发展,越来越多的教育培训机构和学校开始采用在线考试系统来进行教学评估和学生考核。而一个高效、稳定、安全的在线考试系统的核心基础就是数据库的设计。本文将介绍一个简单但完整的在线考试...
    99+
    2023-10-31
    指南 在线考试系统 MySQL表结构设计
  • 在线考试系统的MySQL表结构设计中的考试安排管理方法
    在线考试系统的MySQL表结构设计中的考试安排管理方法随着互联网的普及和发展,在线考试系统成为了目前教育领域中广泛使用的一种教学和考试工具。而在线考试系统的MySQL表结构设计对于系统的稳定运行和考试安排管理起着至关重要的作用。本文将详细介...
    99+
    2023-10-31
    在线考试系统 MySQL表结构设计 考试安排管理方法
  • 在线考试系统的MySQL表结构设计中的考试时间管理技巧
    在线考试系统的MySQL表设计及考试时间管理技巧随着互联网的普及和技术的进步,越来越多的教育机构和企业开始采用在线考试系统来进行考试。在设计和开发在线考试系统的过程中,合理的数据库表结构设计和考试时间管理技巧是非常重要的。本文将介绍如何设计...
    99+
    2023-10-31
    MySQL 在线考试系统 技巧 编程关键词:技巧
  • 在线考试系统的MySQL表结构设计中的考试题库管理技巧
    在线考试系统的MySQL表结构设计中的考试题库管理技巧一、引言随着互联网的迅猛发展,教育领域也开始借助网络平台进行在线教学和考试。在线考试系统作为一种方便快捷的考试形式,受到了广大教育工作者和学生群体的青睐。而在线考试系统的核心组成部分之一...
    99+
    2023-10-31
    MySQL 表结构设计 考试题库管理
  • 如何使用MySQL创建在线考试系统的考试状态管理表结构?
    如何使用MySQL创建在线考试系统的考试状态管理表结构?在线考试系统是现代教育领域广泛应用的一种教育方式,它方便学生在任何时间和地点进行考试。在一个完整的在线考试系统中,一个关键的组成部分是考试状态管理。通过对考试状态进行合理的管理,可以确...
    99+
    2023-10-31
    MySQL 在线考试系统 考试状态管理
  • 如何使用MySQL创建在线考试系统的考试结果查询表结构?
    如何使用MySQL创建在线考试系统的考试结果查询表结构?在线考试系统是一种越来越受欢迎的教育工具,能够方便地为学生提供考试机会,并且快速准确地反馈考试结果。考试结果查询功能是在线考试系统的重要组成部分之一,用户可以通过输入相关信息,查询自己...
    99+
    2023-10-31
    MySQL 在线考试系统 考试结果查询
  • Java怎么实现在线考试云平台
    这篇文章主要讲解了“Java怎么实现在线考试云平台”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Java怎么实现在线考试云平台”吧!考试流程:用户前台注册成为学生管理员后台添加老师,系统将该...
    99+
    2023-06-25
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作