答题结果获取比分计算过程

public BigDecimal updateExamPerson(ExamPerson examPerson) {
        examPerson.setEndTime(new Date());
        Long userId = SecurityUtils.getExamLoginUser().getExamUser().getUserId();
        examPerson.setUserId(userId);
        ExamPerson quExamPerson = new ExamPerson();
        quExamPerson.setUserId(userId);
        quExamPerson.setIdExam(examPerson.getIdExam());
        ExamPerson nowExamPerson = examPersonMapper.selectExamPerson(quExamPerson);
        //其他时间进入答题
        //单选问题列表,随机抽取的单选题目(逗号,拼接)
        String oneQuestions = nowExamPerson.getOneQuestions();
        //多选问题列表,随机抽取的多选题目(逗号,拼接)
        String twoQuestions = nowExamPerson.getTwoQuestions();
        //判断问题列表,随机抽取的判断题目(逗号,拼接)
        String judgeQuestions = nowExamPerson.getJudgeQuestions();
        //计算答卷得分
        ExamQuestionManager manager = managerMapper.selectExamQuestionManagerById(examPerson.getIdExam());
        String[] split = manager.getChoseScore().split(",");
        BigDecimal one = new BigDecimal(0);
        BigDecimal twO = new BigDecimal(0);
        BigDecimal twT = twO.multiply(new BigDecimal(0));
        BigDecimal ju = new BigDecimal(0);
        if (null != split[0]){
            one = new BigDecimal(split[0]);
        }
        if (null != split[0]){
            twO = new BigDecimal(split[1]);
            twT = twO.multiply(new BigDecimal(0.5));
        }
        if (null != split[0]){
            ju = new BigDecimal(split[2]);
        }
//        Double twO = Integer.valueOf(split[1]).doubleValue();
//        Double twT = twO * 0.5;

//        Double ju = Integer.valueOf(split[2]).doubleValue();

        BigDecimal i = new BigDecimal(0.0);
        BigDecimal j = new BigDecimal(0.0);
        BigDecimal k = new BigDecimal(0.0);
        if (StringUtils.isNotNull(examPerson.getAnswerOne())) {
            //单选的答案
            String[] answerOne = examPerson.getAnswerOne().split(",");
            //计算单选题分数
            String[] questionOne = oneQuestions.split(",");
            for (int o = 0; o < answerOne.length; o++) {
                if (StringUtils.isNotNull(answerOne[o])&&!(answerOne[o]).equals("")) {
                    ExamQuestion examQuestion = questionMapper.selectExamQuestionById(questionOne[o]);
                    if (null != examQuestion && answerOne[o].equals(examQuestion.getAnswerIndex())) {
                        //答案正确
                        i = i.add(one);
                    }
                }
            }
        }

        if (StringUtils.isNotNull(examPerson.getAnswerTwo())) {
            //多选答案
            String[] answerTwo = examPerson.getAnswerTwo().split("#");
            //计算多选题分数
            String[] questionTwo = twoQuestions.split(",");
            for (int o = 0; o < answerTwo.length; o++) {
                if (StringUtils.isNotNull(answerTwo[o])&&!(answerTwo[o]).equals("")) {
                    String[] split1 = answerTwo[o].split(",");
                    ExamQuestion examQuestion = questionMapper.selectExamQuestionById(questionTwo[o]);
                    if (null != examQuestion){
                        String splitTwo = examQuestion.getAnswerIndex();
                        String[] split2 = splitTwo.split(",");
                        //比较结果,得出分数
                        boolean isTrue = true;
                        for (int m = 0; m < split1.length; m++) {
                            if (!splitTwo.contains(split1[m])) {
                                //不包含,答案错误
                                j = j.add(new BigDecimal(0.0));
                                isTrue = false;
                                break;
                            }
                        }
                        if (isTrue) {
                            //没有进入错误选项
                            if (split1.length == split2.length) {
                                //全对
                                j = j.add(twO);
                            } else {
                                //对一部分
                                j = j.add(twT);
                            }
                        }
                    }


                }
            }
        }

        if (StringUtils.isNotNull(examPerson.getJudge())) {
            //判断答案
            String[] answerJu = examPerson.getJudge().split(",");
            //计算判断题分数
            String[] questionJu = judgeQuestions.split(",");
            for (int o = 0; o < answerJu.length; o++) {
                if (StringUtils.isNotNull(answerJu[o])&&!(answerJu[o]).equals("")) {
                    ExamQuestion examQuestion = questionMapper.selectExamQuestionById(questionJu[o]);
                    if (null != examQuestion &&answerJu[o].equals(examQuestion.getAnswerIndex())) {
                        //答案正确
                        k = k.add(ju);
                    }
                }
            }
        }
        BigDecimal score = i.add(j).add(k);
        examPerson.setScore(score);
        examPersonMapper.updateExamPerson(examPerson);
        return score;

    }

针对于单选,多选,判断题目的分数计算,最后得出试卷答题的最终分数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值