weiwenhai 7 anni fa
parent
commit
1c1cc61ab3

+ 78 - 51
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/temp/DdCollegeUtilService.java

@@ -89,14 +89,7 @@ public class DdCollegeUtilService {
 		//查询课程
 		Course course = courseRepo.findFirstByCodeAndOrgId(courseCode,orgId);
 		//查询试卷集合
-		//List<TestPaper> papers = queryByCourse(courseCode);
-		TestPaper testPaper1 = new TestPaper();
-		testPaper1.setId("FCE63B16D006FE488C44A03ADF270DDC");
-		testPaper1.setName("地大所有题型");
-		testPaper1.setScore(100.0);
-		testPaper1.setTestPaperContentId("AFF665B0F5AB5840B1179D08AE3895D8");//EBE6752BCE3A360D1F50BE9FBA4ADCE7,F61A67F4898249767CB0A31A3BD2616B
-		List<TestPaper> papers = new ArrayList<TestPaper>();
-		papers.add(testPaper1);
+		List<TestPaper> papers = queryByCourse(courseCode);
 		if(papers != null && papers.size()>0){
 			for(TestPaper testPaper:papers){
 				//查询试题详情
@@ -192,13 +185,21 @@ public class DdCollegeUtilService {
      */
     @SuppressWarnings({"unchecked","rawtypes"})
     public List<TestQuestion> queryByTestPaper(String testPaperContentId){
-    	String sql = "SELECT q.ID id,d.dNumber,d.`name` dName,d.number number,d.score score,q.PARENT_ID parent_id,q.QUESTION_TYPE_ENUM type,q.JSON "
-    			+ "FROM QUESTION_CONTENT q ,(SELECT b.QUESTION_CONTENT_ID question_id, b.SCORE score, b.SEQUENCE number, c.name name, c.dNumber dNumber "
-    			+ "FROM TEST_PAPER_QUESTION b ,(SELECT a.ID id, a.`NAME` name,a.SEQUENCE dNumber,a.TEST_PAPER_CONTENT_ID "
-    			+ "FROM TEST_PAPER_QUESTION_GROUP a WHERE a.TEST_PAPER_CONTENT_ID = '"+ testPaperContentId + "' ORDER BY a.sequence) c "
-    			+ "WHERE b.TEST_PAPER_QUESTION_GROUP_ID = c.id ORDER BY c.dNumber,b.SEQUENCE) d WHERE q.ID = d.question_id ORDER BY d.dNumber,d.number;";
+    	List<TestQuestion> dquestions = new ArrayList<TestQuestion>();
+    	String sql = "SELECT q.ID id,d.dNumber,d.NAME dName,d.number1 number1,d.score score,q.PARENT_ID parent_id,q.QUESTION_TYPE_ENUM type,q.JSON "
+    			+ "FROM QUESTION_CONTENT q ,(SELECT b.QUESTION_CONTENT_ID question_id, b.SCORE score, b.SEQUENCE number1, c.NAME name, c.dNumber dNumber "
+    			+ "FROM TEST_PAPER_QUESTION b ,(SELECT a.ID id, a.NAME name,a.SEQUENCE dNumber,a.TEST_PAPER_CONTENT_ID "
+    			+ "FROM TEST_PAPER_QUESTION_GROUP a WHERE a.TEST_PAPER_CONTENT_ID = '"+ testPaperContentId + "' ORDER BY a.SEQUENCE) c "
+    			+ "WHERE b.TEST_PAPER_QUESTION_GROUP_ID = c.id ORDER BY c.dNumber,b.SEQUENCE) d WHERE q.ID = d.question_id ORDER BY d.dNumber,d.number1";
     	List<TestQuestion> questions = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper(TestQuestion.class));
-    	return questions;
+    	if(questions != null && questions.size()>0){
+    		for(TestQuestion testQuestion:questions){
+    			if(testQuestion.getParentId().equals("00000000000000000000000000000000")){
+    				dquestions.add(testQuestion);
+    			}
+    		}
+    	}
+    	return dquestions;
     }
     
     //测试oracle的连接
@@ -215,7 +216,7 @@ public class DdCollegeUtilService {
      */
     @SuppressWarnings({"unchecked","rawtypes"})
     public List<TestQuestion> querySubQuestions(String parentId){
-    	String sql = "SELECT q.question_type_enum type, q.json json from dd_question_content_temp q WHERE q.parent_id = '" + parentId +"'";
+    	String sql = "SELECT q.question_type_enum type, q.json json from QUESTION_CONTENT q WHERE q.parent_id = '" + parentId +"' order by q.sequence";
     	List<TestQuestion> questions = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper(TestQuestion.class));
     	return questions;
     }
@@ -309,46 +310,27 @@ public class DdCollegeUtilService {
     	WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
     	//选词填空
     	if(testQuestionInfo.getQuestionType() == 14){
-    		question.setQuestionType(QuesStructType.TEXT_ANSWER_QUESTION);
-    		//定义答案集合
-    		List<String> answers = new ArrayList<String>();
-    		//定义答案ID集合
-    		List<String> answerIds = new ArrayList<String>();
-    		List<TestFillAnswer> blanks = testQuestionInfo.getBlanks();
-    		if(blanks != null && blanks.size()>0){
-    			for(TestFillAnswer answer : blanks){
-    				answerIds.add(answer.getAnswerId());
-    			}
-    		}
-    		StringBuffer quesBody = new StringBuffer();
-    		quesBody.append("<p>"+testQuestionInfo.getQuestionHTML()+"</p>");
-    		//获取选项,添加到题干
-    		TestOptionGroup optionGroup = testQuestionInfo.getOptionGroup();
-    		if(optionGroup!=null){
-    			List<TestOption> options =  optionGroup.getOptions();
-    			if(options != null && options.size()>0){
-    				int number = 1;
-    				for(TestOption option:options){
-    					char c1=(char) (number+64);
-    					quesBody.append("<p>"+"("+String.valueOf(c1)+")"+option.getOptionHTML()+"</p>");
-    					if(answerIds.contains(option.getID())){
-    						answers.add(String.valueOf(c1));
-    					}
+    		String quesBody = testQuestionInfo.getQuestionHTML();
+    		//去掉<span>标签中的lang
+    		quesBody = replaceLang(quesBody);
+    		//获取img标签
+    		LinkedHashMap<String, String> bodyImgList = imgList(quesBody);
+    		if(bodyImgList != null && bodyImgList.size()>0){
+    			int number = 1;
+    			for(Map.Entry<String, String> entry:bodyImgList.entrySet()){
+    				if(StringUtils.isBlank(entry.getValue())){
+    					quesBody = quesBody.replace(entry.getKey(),"##"+number+"##");
     					number++;
+    				}else {
+    					quesBody = quesBody.replace(entry.getKey(),entry.getValue());
     				}
-    				//去掉<span>标签中的lang
-    	    		String quesBodys = replaceLang(quesBody.toString());
-    	    		//获取img标签
-    	    		LinkedHashMap<String, String> bodyImgList = imgList(quesBodys);
-    	    		//替换、补全Img标签
-    	    		quesBodys = replaceImg(bodyImgList, quesBodys);
-    				question.setQuesBody(quesBodys);
-    				question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
-    				question.setQuesAnswer(StringUtils.join(answers,","));
-    				String answerWord = "<p>" +question.getQuesAnswer() +"</p>";
-    				question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(answerWord)));
     			}
     		}
+    		question.setQuesBody("<p>"+quesBody+"</p>");
+    		question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
+    		question.setQuestionType(QuesStructType.NESTED_ANSWER_QUESTION);
+    		List<Question> subQuestions = initSubQuestionsByOther(testQuestionInfo, wordMLPackage);
+    		question.setSubQuestions(subQuestions);
     	}
     	//阅读理解题
     	if(testQuestionInfo.getQuestionType() == 42){
@@ -654,6 +636,51 @@ public class DdCollegeUtilService {
     	}
     	return subQuestions;
     }
+    
+    public List<Question> initSubQuestionsByOther(TestQuestionInfo testQuestionInfo,WordprocessingMLPackage wordMLPackage) throws Exception{
+    	List<Question> subQuestions = new ArrayList<Question>();
+    	if(testQuestionInfo.getBlanks()!=null && testQuestionInfo.getBlanks().size()>0){
+    		List<TestFillAnswer> blanks = testQuestionInfo.getBlanks();
+    		for(TestFillAnswer testFillAnswer:blanks){
+    			Question subQuestion = new Question();
+    			subQuestion.setId(UUID.randomUUID().toString());
+    			subQuestion.setQuestionType(QuesStructType.SINGLE_ANSWER_QUESTION);
+    			subQuestion.setDifficulty("中");
+    			subQuestion.setDifficultyDegree(0.5);
+    			subQuestion.setPublicity(true);
+    			subQuestion.setQuesBody("______");
+    			subQuestion.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>"+subQuestion.getQuesBody()+"</p>")));
+    			List<QuesOption> quesOptions = new ArrayList<QuesOption>();
+    			TestOptionGroup optionGroup = testQuestionInfo.getOptionGroup();
+    			List<TestOption> options = optionGroup.getOptions();
+    			Integer answerNumber = null;
+    			if(options != null && options.size()>0){
+    				for(TestOption subOption:options){
+    					int subNumber = 1;
+        				short isCorrect = 0;
+        				if(testFillAnswer.getAnswerId().equals(subOption.getID())){
+        					isCorrect = 1;
+        					answerNumber = subNumber;
+        				}else {
+							isCorrect = 0;
+						}
+        				QuesOption quesOption = initQuesOption(subOption,subNumber,isCorrect,wordMLPackage);
+    					quesOptions.add(quesOption);
+    					subNumber++;
+    				}
+    			}
+    			subQuestion.setQuesOptions(quesOptions);
+    			if(answerNumber != null){
+        			char c1=(char) (answerNumber+64);
+        			subQuestion.setQuesAnswer(String.valueOf(c1));
+        			subQuestion.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>"+subQuestion.getQuesAnswer()+"</p>")));
+        		}
+    			subQuestions.add(subQuestion);
+    		}
+    	}
+    	return subQuestions;
+    }
+    
     /**
      * 初始化小题对象
      * @param question

+ 4 - 4
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/temp/vo/TestQuestion.java

@@ -26,7 +26,7 @@ public class TestQuestion {
 	/**
 	 * 小题序号
 	 */
-	private Integer number;
+	private Integer number1;
 	
 	/**
 	 * 小题分数
@@ -74,11 +74,11 @@ public class TestQuestion {
 	}
 
 	public Integer getNumber() {
-		return number;
+		return number1;
 	}
 
-	public void setNumber(Integer number) {
-		this.number = number;
+	public void setNumber(Integer number1) {
+		this.number1 = number1;
 	}
 
 	public Double getScore() {

+ 3 - 3
examcloud-core-questions-starter/src/test/java/cn/com/qmth/examcloud/core/questions/starter/DdCollegeUtilTest.java

@@ -34,12 +34,12 @@ public class DdCollegeUtilTest {
 			System.out.println(testPaper.toString());
 		}*/
 		try {
-			ddCollegeUtilService.importPaper("109", "000001");
+			ddCollegeUtilService.importPaper("1627", "D28020027");
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
-		List<TestQuestion> list = ddCollegeUtilService.querySubQuestions("24AE438A37B67D7F0430D434A9D0C929");
-		System.out.println(list);
+		/*List<TestQuestion> list = ddCollegeUtilService.querySubQuestions("24AE438A37B67D7F0430D434A9D0C929");
+		System.out.println(list);*/
 		int count = ddCollegeUtilService.testCount();
 		System.out.println(count);
 	}