欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java Online Exam在線考試系統(tǒng)的實現(xiàn)

 更新時間:2021年11月23日 15:48:23   作者:qq_1334611189  
讀萬卷書不如行萬里路,只學書上的理論是遠遠不夠的,只有在實戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+springboot+vue+jsp+mysql+maven實現(xiàn)Online Exam在線考試系統(tǒng),大家可以在過程中查缺補漏,提升水平

一、項目簡述

本系統(tǒng)主要實現(xiàn)的功能有: 學生以及老師的注冊登錄,在線考試,錯題查詢,學生管理,問題管理,錯題管理,錯題查詢,分數(shù)查詢,試卷管 理,人工組卷。自動組卷,教師,班級,統(tǒng)計等等管理功能。

二、項目運行

環(huán)境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

項目技術: VUE+Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等

課程信息控制器:

 
/**
 * yy
 */
@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 = "根據(jù)名字獲取科目信息", notes = "根據(jù)科目名稱獲取科目詳細信息")
    @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 = "根據(jù)課程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 = "創(chuàng)建課程", notes = "創(chuàng)建課程")
    @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 = "根據(jù)課程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 = "根據(jù)課程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 = "根據(jù)課程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);
    }
}
 

題目信息控制器:

/**
 * yy
 */
 
@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 = "獲取試卷題目數(shù)量", 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 = "創(chuàng)建題目", notes = "創(chuàng)建題目")
    @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 = "根據(jù)題目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 = "根據(jù)試卷id和題目編號獲取題目信息", notes = "根據(jù)題目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("根據(jù)答卷id獲取答卷失敗");
            }
        }
        return questionService.getQuestionByPaperIdAndQuestionNumber(paperId, number);
    }
 
    @ApiOperation(value = "獲取題目信息", notes = "根據(jù)題目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 = "根據(jù)試卷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 = "根據(jù)試卷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 = "根據(jù)題目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 = "根據(jù)題目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 = "根據(jù)試卷id和題目編號獲取題目信息", notes = "根據(jù)題目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) {
        /**
         * 更改試卷狀態(tài),finished:true
         */
        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")) {
            /**
             * 1.接收提交的試卷
             * 2.計算成績
             * 3.記錄考試記錄
             * 4.返回計算結果
             */
            int score = 0;
 
            //正確題目數(shù)
            double right = 0.0;
 
            //錯誤題目數(shù)
            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) {
                    /**
                     * 1.題目序號相同
                     * 2.結果與答案相同
                     */
                    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());
            //更新參與人數(shù)
            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());
        //更新參與人數(shù)
        paper1.setPeoples(String.valueOf(Integer.parseInt(paper1.getPeoples() + 1)));
        paperService.updatePaper(paper1);
        return new ResponseEntity<Object>(HttpStatus.OK);
    }
 
    /**
     * 提交題目
     * @param username
     * @param dtoAnswerPaper
     * @return
     */
    @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();
        //判斷數(shù)據(jù)庫是否保存了這次答卷
        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();
        //答卷為空,則執(zhí)行保存
        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 {
                    //記錄存在,則執(zhí)行更新
                    // TODO: 2017/3/30
                    //更新當前存在的記錄
                    existAnswerQuestion.setAnswer(question.getAnswer());
 
                    answerQuestionService.updateAnswerQuestion(existAnswerQuestion);
                }
            }
        }
        return new ResponseEntity<Object>(answerPaper, HttpStatus.OK);
    }
}

答卷控制層,用于獲取已經(jīng)提交的答卷:

/**
 * 答卷控制層,用于獲取已經(jīng)提交的答卷
 */
@RestController
@RequestMapping("/v1/answer-papers")
public class AnswerPaperController {
 
    @Autowired
    AnswerPaperService answerPaperService;
 
    @Autowired
    AnswerQuestionService answerQuestionService;
 
    /**
     * 根據(jù)ID查找
     * @param id
     * @return
     */
    @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);
    }
 
    /**
     * 根據(jù)name查找
     * @param name
     * @return
     */
    @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);
    }
 
    /**
     * 根據(jù)答卷id和題目編號獲取題目信息
     * @param paperId
     * @param number
     * @return
     */
    @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;
    }
 
    /**
     * 已分頁方式獲取數(shù)據(jù)
     * @param username
     * @param pageIndex
     * @param pageSize
     * @param limit
     * @param offset
     * @return
     */
    @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;
    }
 
    /**
     * 獲取未批改或已批改的答卷數(shù)量,
     * @return
     */
    @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;
    }
 
    /**
     * 以分頁方式獲取數(shù)據(jù)
     * @param pageIndex
     * @param pageSize
     * @param limit
     * @param offset
     * @return
     */
    @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;
    }
 
    /**
     * 更新
     * @param answerPaper
     * @return
     */
    @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);
    }
 
    /**
     * 計算考試成績
     * @param id
     * @return
     */
    @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在線考試系統(tǒng)的實現(xiàn)的詳細內容,更多關于Java 在線考試系統(tǒng)的資料請關注腳本之家其它相關文章!

相關文章

  • 詳解JAVA 設計模式之狀態(tài)模式

    詳解JAVA 設計模式之狀態(tài)模式

    這篇文章主要介紹了JAVA 狀態(tài)模式的的相關資料,文中講解的非常細致,幫助大家更好的學習理解JAVA 設計模式,感興趣的朋友可以了解下
    2020-06-06
  • Java實現(xiàn)操作JSON的便捷工具類完整實例【重寫Google的Gson】

    Java實現(xiàn)操作JSON的便捷工具類完整實例【重寫Google的Gson】

    這篇文章主要介紹了Java實現(xiàn)操作JSON的便捷工具類,基于重寫Google的Gson實現(xiàn),涉及java針對json數(shù)據(jù)的各種常見轉換操作實現(xiàn)技巧,需要的朋友可以參考下
    2017-10-10
  • SpringCloudAlibaba整合Feign實現(xiàn)遠程HTTP調用的簡單示例

    SpringCloudAlibaba整合Feign實現(xiàn)遠程HTTP調用的簡單示例

    這篇文章主要介紹了SpringCloudAlibaba 整合 Feign 實現(xiàn)遠程 HTTP 調用,文章中使用的是OpenFeign,是Spring社區(qū)開發(fā)的組件,需要的朋友可以參考下
    2021-09-09
  • 教你用Java實現(xiàn)一個簡單的代碼生成器

    教你用Java實現(xiàn)一個簡單的代碼生成器

    今天給大家?guī)淼氖顷P于Java的相關知識,文章圍繞著如何用Java實現(xiàn)一個簡單的代碼生成器展開,文中有非常詳細的介紹及代碼示例,需要的朋友可以參考下
    2021-06-06
  • 在Intellij IDEA中使用Debug(圖文教程)

    在Intellij IDEA中使用Debug(圖文教程)

    下面小編就為大家?guī)硪黄贗ntellij IDEA中使用Debug(圖文教程)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • Java實現(xiàn)定時任務的方法詳解

    Java實現(xiàn)定時任務的方法詳解

    大家都用過鬧鐘,鬧鐘可以說是一種定時任務。那么,在?Java?中,如何實現(xiàn)這樣的功能呢?即如何實現(xiàn)定時任務呢?本文就來詳細和大家聊聊
    2022-10-10
  • Java動態(tài)數(shù)組ArrayList實現(xiàn)動態(tài)原理

    Java動態(tài)數(shù)組ArrayList實現(xiàn)動態(tài)原理

    ArrayList是一種動態(tài)數(shù)組,它可以在運行時自動調整大小以適應元素的添加和刪除,在Java中,你可以使用ArrayList類來實現(xiàn)動態(tài)數(shù)組,本文將給大家介紹一下ArrayList動態(tài)數(shù)組,是怎么實現(xiàn)動態(tài)的
    2023-08-08
  • Java png圖片修改像素rgba值的操作

    Java png圖片修改像素rgba值的操作

    這篇文章主要介紹了Java png圖片修改像素rgba值的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • Spring為singleton?bean注入prototype?bean

    Spring為singleton?bean注入prototype?bean

    這篇文章主要介紹了Spring為singleton?bean注入prototype?bean,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-07-07
  • Java實戰(zhàn)寵物醫(yī)院預約掛號系統(tǒng)的實現(xiàn)流程

    Java實戰(zhàn)寵物醫(yī)院預約掛號系統(tǒng)的實現(xiàn)流程

    只學書上的理論是遠遠不夠的,只有在實戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+JSP+Spring+SpringBoot+MyBatis+html+layui+maven+Mysql實現(xiàn)一個寵物醫(yī)院預約掛號系統(tǒng),大家可以在過程中查缺補漏,提升水平
    2022-01-01

最新評論