java版学生试题错题本的功能实现

错题本功能实现

 /**
     * 判断答案对错
     */

    @GetMapping("/judge")
    public void selectjudge(HttpServletResponse response, Integer pageNum, Integer pageSize, String djUserid) throws IOException {

        PageHelper.startPage(pageNum, pageSize);
        //查询所有试卷对应的课程
        List<Catalog> catalogs = catalogService.selectbyPaper();

        //根据userid和paperid查出用户做过的题属于的课程
        for (int j = 0; j < catalogs.size(); j++) {
            JrAnswers jrAnswers1 = new JrAnswers();
            jrAnswers1.setDjUserid(djUserid);
            jrAnswers1.setDjPaperid(catalogs.get(j).getPaperId());
            List<JrAnswers> jrAnswers = jrAnswersService.selectJrAnswersList(jrAnswers1);


            //错题列表
            ArrayList<JrQuestions> list1 = new ArrayList<>();


//        for (int a = 0; a < jrAnswers.size(); a++) {
//
//            //分类
//            JrCatalogPaperRelation jrCatalogPaperRelation = jrCatalogPaperRelationService.selectJrCatalogPaperRelationById1(jrAnswers.get(a).getDjPaperid());
//            Integer catalogId = jrCatalogPaperRelation.getCatalogId();
//            Catalog catalog = catalogService.selectCatalogById(catalogId);
//            String name = catalog.getName();
//           // writeJSON(name, response, "200","success");


            //获取答过的题
            for (JrAnswers jrAnswer : jrAnswers) {


                //根据课程名字分类
                Integer djPaperid = jrAnswer.getDjPaperid();
                JrCatalogPaperRelation jrCatalogPaperRelation1 = jrCatalogPaperRelationService.selectJrCatalogPaperRelationById1(djPaperid);
                Integer catalogId1 = jrCatalogPaperRelation1.getCatalogId();
                Catalog catalog1 = catalogService.selectCatalogById(catalogId1);
                String name = catalog1.getName();


                String questionsids = jrAnswer.getDjQuestionsids();
                ArrayList<JrQuestions> list = new ArrayList<>();

                if (questionsids.contains(",")) {
                    String[] split = questionsids.split(",");
                    for (String s : split) {//将试题信息装入
                        JrQuestions questions = jrQuestionsService.selectJrQuestionsById(Integer.valueOf(s));
                        list.add(questions);
                    }
                } else {
                    JrQuestions questions = jrQuestionsService.selectJrQuestionsById(Integer.valueOf(questionsids));
                    list.add(questions);
                }

                if (jrAnswer.getDjContent().contains(",")) {
                    String[] split = jrAnswer.getDjContent().split(",");
                    for (int i = 0; i < list.size(); i++) {
                        list.get(i).setTrueAnsw(split[i]);
                    }
                } else {
                    list.get(0).setTrueAnsw(jrAnswer.getDjContent());
                }

                for (int i = 0; i < list.size(); i++) {
                    if (!list.get(i).getStAnswer().equals(list.get(i).getTrueAnsw())) {
                        list.get(i).setName(name);
                        list1.add(list.get(i));

                    }
                }
            }
            catalogs.get(j).setList1(list1);

        }

        //删除空课程列表
        for (int i = 0; i < catalogs.size(); i++) {

            if (StringUtils.isEmpty(catalogs.get(i).getList1())) {
                catalogs.remove(i);
                i--;
            }
        }
        writeJSON(catalogs, response, "200", "success");

    }
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值