|
|
@@ -350,6 +350,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
|
|
|
List<XWPFParagraph> paragraphList = doc.getParagraphs();
|
|
|
int type = -1; //题目类型
|
|
|
+ boolean isOption = false; //是否判断题
|
|
|
+ String knowledge = ""; //知识点
|
|
|
List<QuestionChildAddBo> optionsList =new ArrayList<>(); //题目选项
|
|
|
String content = "";
|
|
|
int i = 0;
|
|
|
@@ -359,23 +361,10 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
XWPFParagraph paragraph = paragraphList.get(i);
|
|
|
content = paragraph.getText().trim();
|
|
|
System.out.println(content);
|
|
|
- if(Validator.isEmpty(content)){
|
|
|
- System.out.println("换行");
|
|
|
- }else{
|
|
|
- if(content.equals("单选题格式")){
|
|
|
- type = 1;
|
|
|
- }
|
|
|
- else if(content.equals("多选题格式")){
|
|
|
- type = 2;
|
|
|
- }
|
|
|
- else if(content.equals("判断题格式")){
|
|
|
- type = 3;
|
|
|
- }
|
|
|
- else if(content.equals("简答题格式")){
|
|
|
- type = 5;
|
|
|
- }
|
|
|
+ if(Validator.isNotEmpty(content)){
|
|
|
//第一个选项
|
|
|
- else if(content.startsWith("A.")){
|
|
|
+ if(content.startsWith("A.")){
|
|
|
+ isOption = true;
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
bo1.setOptionsId(1L);
|
|
|
int j = i;
|
|
|
@@ -482,10 +471,96 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
bo1.setContent(q_content);
|
|
|
optionsList.add(bo1);
|
|
|
}
|
|
|
+ //答案和题型
|
|
|
else if(content.startsWith("正确答案")){
|
|
|
String answerQuestion = content.replace("正确答案:", ";");
|
|
|
+ if(Validator.isEmpty(answerQuestion)){
|
|
|
+ throw new CustomException("正确答案错误");
|
|
|
+ }
|
|
|
+ if(isOption){
|
|
|
+ //选择题
|
|
|
+ answerQuestion = dealImportAnswer(answerQuestion);
|
|
|
+ if(answerQuestion.length()>1){
|
|
|
+ type = 2; //多选
|
|
|
+ }else{
|
|
|
+ type = 1; //单选
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if("正确".equals(answerQuestion)){
|
|
|
+ answerQuestion = "1";
|
|
|
+ type = 3; //判断
|
|
|
+ }
|
|
|
+ else if("错误".equals(answerQuestion)){
|
|
|
+ answerQuestion = "0";
|
|
|
+ type = 3;
|
|
|
+ }else{
|
|
|
+ type = 5; //简答题
|
|
|
+ int j = i;
|
|
|
+ String q_content = ""; //简答题
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = paragraphList.get(j).getText();
|
|
|
+ if(checkKey(tempTxt)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ q_content = q_content.replace("解题思路:", "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //解题思路
|
|
|
+ else if(content.startsWith("解题思路:")){
|
|
|
+ int j = i;
|
|
|
+ String q_content = ""; //解题思路
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = paragraphList.get(j).getText();
|
|
|
+ if(checkKey(tempTxt)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ q_content = q_content.replace("解题思路:", "");
|
|
|
+
|
|
|
}
|
|
|
- paragraph.getText();
|
|
|
+ //考查考点
|
|
|
+ else if(content.startsWith("考查考点:")){
|
|
|
+ int j = i;
|
|
|
+ String q_content = ""; //考查考点
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = paragraphList.get(j).getText();
|
|
|
+ if(checkKey(tempTxt)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ q_content = q_content.replace("考查考点:", "");
|
|
|
+ }
|
|
|
+ //考查考点
|
|
|
+ else if(content.startsWith("考查考点:")){
|
|
|
+ int j = i;
|
|
|
+ String q_content = ""; //考查考点
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = paragraphList.get(j).getText();
|
|
|
+ if(checkKey(tempTxt)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ q_content = q_content.replace("考查考点:", "");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ System.out.println("换行");
|
|
|
+ //清空数据
|
|
|
+ isOption = false;
|
|
|
+
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
|
@@ -501,6 +576,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private boolean checkKey(String key){
|
|
|
+ if(Validator.isEmpty(key)||"解题思路:".equals(key)||"考查考点:".equals(key)||"老师解答:".equals(key)||"正确答案:".equals(key)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String insertByAddBoImport(QuestionAddBo bo,Integer no) {
|
|
|
@@ -731,4 +813,31 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
}
|
|
|
return sb.toString();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private String dealImportAnswer(String Answer){
|
|
|
+ String[] itemArray = Answer.split("");
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (String v:itemArray) {
|
|
|
+ if("A".equals(v)){
|
|
|
+ list.add("1");
|
|
|
+ }
|
|
|
+ else if("B".equals(v)){
|
|
|
+ list.add("2");
|
|
|
+ }
|
|
|
+ else if("C".equals(v)){
|
|
|
+ list.add("3");
|
|
|
+ }
|
|
|
+ else if("D".equals(v)){
|
|
|
+ list.add("4");
|
|
|
+ }
|
|
|
+ else if("E".equals(v)){
|
|
|
+ list.add("5");
|
|
|
+ }
|
|
|
+ else if("F".equals(v)){
|
|
|
+ list.add("6");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return String.join(",", list);
|
|
|
+ }
|
|
|
}
|