/** * 封装材料和材料下小题 * * @param questionsMap 含有试卷所有小题的map */ private void fixArtAndQuestions(Map<Integer, List<Question>> questionsMap) { for (Iterator<List<Question>> iterator = questionsMap.values().iterator(); iterator.hasNext(); ) { List<Question> questions = iterator.next(); List<Integer> needRemovedQues = null; for (Iterator<Question> iterator2 = questions.iterator(); iterator2.hasNext(); ) { Question question = iterator2.next(); if (question.getQuestionType() == 6) { // 当前小题是材料时,才进行添加孩子小题的操作 int quesIndex = questions.indexOf(question); // 得到当前小题的索引 String referIds = question.getReferIds(); if (!referIds.equals("")) { // 由于查出的数据是按照顺序排列的,所以材料下的小题的索引是紧接着材料的索引号的 for (int i = 1; i <= referIds.split(",").length; i++) { question.addChildQuestion(questions.get(quesIndex + i)); if (needRemovedQues == null) needRemovedQues = new ArrayList<Integer>(); needRemovedQues.add(quesIndex + i); // 将小题存到需删除小题列表中 } } } } if (needRemovedQues != null) { for (int i = 0; i < needRemovedQues.size(); i++) // 删除材料下小题 questions.remove(needRemovedQues.get(i)); } } }
/** * 得到试卷所有小题,将同一大题的小题存到同一个list中,并且以大题Id为键名,将list存到map中 * * @param examId 试卷编号 */ private Map<Integer, List<Question>> getQuestionsOfExam(int examId, Map<String, Image> images) { List<LStrMap<Object>> list = nwd.getQuestionsOfExam(examId); if (list.size() > 0) { Map<Integer, List<Question>> resultMap = new LinkedHashMap<Integer, List<Question>>(); for (Iterator<LStrMap<Object>> iterator = list.iterator(); iterator.hasNext(); ) { LStrMap<Object> tempMap = iterator.next(); // 组合小题信息到小题对象 Question question = new Question(); images.putAll(question.setContents(tempMap.get("ques_content").toString())); question.setDifficulty(Double.parseDouble(tempMap.get("difficulty").toString())); question.setIndexNo(tempMap.get("m_topic").toString()); Object keyword = tempMap.get("keyword"); images.putAll(question.setParses(keyword == null ? "" : keyword.toString())); question.setQuestionId(Integer.parseInt(tempMap.get("ques_id").toString())); question.setQuestionType(Integer.parseInt(tempMap.get("ques_type").toString())); question.setScore(Double.parseDouble(tempMap.get("score").toString())); question.setShareFlag(Integer.parseInt(tempMap.get("share_flag").toString())); Object quesRefer = tempMap.get("ques_refer"); String answer = quesRefer == null ? "" : quesRefer.toString(); if (question.getQuestionType() == 2) // 多选题要去除@@ answer.replace("@@", ""); else if (question.getQuestionType() == 4) // 填空题要去除选项号之前的## answer.replaceAll("##", ""); Object referIds = tempMap.get("remark"); if (referIds == null) question.setReferIds(""); else question.setReferIds(referIds.toString()); images.putAll(question.setAnswers(answer)); int typeId = Integer.parseInt(tempMap.get("type_id").toString()); if (resultMap.containsKey(typeId)) { resultMap.get(typeId).add(question); } else { ArrayList<Question> tempList = new ArrayList<Question>(); tempList.add(question); resultMap.put(typeId, tempList); } } fixArtAndQuestions(resultMap); // 封装材料和材料下小题 return resultMap; } return null; }