|
@@ -10,6 +10,7 @@ import com.zhongzheng.common.core.domain.entity.SysUser;
|
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.common.utils.SecurityUtils;
|
|
|
import com.zhongzheng.common.utils.ServletUtils;
|
|
|
import com.zhongzheng.modules.bank.bo.*;
|
|
|
import com.zhongzheng.modules.bank.domain.ExamQuestion;
|
|
@@ -336,6 +337,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
@Override
|
|
|
public void importWordQuestion(MultipartFile file) {
|
|
|
String buffer = "";
|
|
|
+ String importNo = ServletUtils.getEncoded("IMPORT");
|
|
|
try{
|
|
|
String path = file.getOriginalFilename();
|
|
|
if (path.endsWith(".doc")) {
|
|
@@ -351,22 +353,28 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
List<XWPFParagraph> paragraphList = doc.getParagraphs();
|
|
|
int type = -1; //题目类型
|
|
|
boolean isOption = false; //是否判断题
|
|
|
- String knowledge = ""; //知识点
|
|
|
List<QuestionChildAddBo> optionsList =new ArrayList<>(); //题目选项
|
|
|
- String content = "";
|
|
|
+ String content = ""; //每行正文
|
|
|
+ String qContent = ""; //题目正文
|
|
|
+ String errorLog = ""; //错误提示
|
|
|
+ String answerQuestion = null; //答案
|
|
|
+ String analysisContent = ""; //解析文本
|
|
|
int i = 0;
|
|
|
+ int index = 1; //题目序列号
|
|
|
//遍历正文
|
|
|
while (i<paragraphList.size())
|
|
|
{
|
|
|
XWPFParagraph paragraph = paragraphList.get(i);
|
|
|
content = paragraph.getText().trim();
|
|
|
- System.out.println(content);
|
|
|
+ if(content.startsWith("\\t")){
|
|
|
+ content = content.replace("\\t", "");
|
|
|
+ }
|
|
|
+ // content = trimFirstAndLastChar(content, "\t");
|
|
|
if(Validator.isNotEmpty(content)){
|
|
|
//第一个选项
|
|
|
if(content.startsWith("A.")){
|
|
|
isOption = true;
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- bo1.setOptionsId(1L);
|
|
|
int j = i;
|
|
|
String q_content = ""; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
@@ -378,13 +386,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
q_content+=tempTxt;
|
|
|
j++;
|
|
|
}
|
|
|
- bo1.setContent(q_content);
|
|
|
- optionsList.add(bo1);
|
|
|
+ bo1.setOptionsId(1L);
|
|
|
+ bo1.setContent(q_content.replace("A.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
}
|
|
|
//第二个选项
|
|
|
else if(content.startsWith("B.")){
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- bo1.setOptionsId(1L);
|
|
|
int j = i;
|
|
|
String q_content = ""; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
@@ -396,13 +404,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
q_content+=tempTxt;
|
|
|
j++;
|
|
|
}
|
|
|
- bo1.setContent(q_content);
|
|
|
+ bo1.setOptionsId(2L);
|
|
|
+ bo1.setContent(q_content.replace("B.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
}
|
|
|
//第三个选项
|
|
|
else if(content.startsWith("C.")){
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- bo1.setOptionsId(1L);
|
|
|
int j = i;
|
|
|
String q_content = ""; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
@@ -414,13 +422,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
q_content+=tempTxt;
|
|
|
j++;
|
|
|
}
|
|
|
- bo1.setContent(q_content);
|
|
|
+ bo1.setOptionsId(3L);
|
|
|
+ bo1.setContent(q_content.replace("C.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
}
|
|
|
//第四个选项
|
|
|
else if(content.startsWith("D.")){
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- bo1.setOptionsId(1L);
|
|
|
int j = i;
|
|
|
String q_content = ""; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
@@ -432,13 +440,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
q_content+=tempTxt;
|
|
|
j++;
|
|
|
}
|
|
|
- bo1.setContent(q_content);
|
|
|
+ bo1.setOptionsId(4L);
|
|
|
+ bo1.setContent(q_content.replace("D.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
}
|
|
|
//第五个选项
|
|
|
else if(content.startsWith("E.")){
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- bo1.setOptionsId(1L);
|
|
|
int j = i;
|
|
|
String q_content = ""; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
@@ -450,13 +458,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
q_content+=tempTxt;
|
|
|
j++;
|
|
|
}
|
|
|
- bo1.setContent(q_content);
|
|
|
+ bo1.setOptionsId(5L);
|
|
|
+ bo1.setContent(q_content.replace("E.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
}
|
|
|
//第六个选项
|
|
|
else if(content.startsWith("F.")){
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- bo1.setOptionsId(1L);
|
|
|
int j = i;
|
|
|
String q_content = ""; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
@@ -468,12 +476,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
q_content+=tempTxt;
|
|
|
j++;
|
|
|
}
|
|
|
- bo1.setContent(q_content);
|
|
|
+ bo1.setOptionsId(6L);
|
|
|
+ bo1.setContent(q_content.replace("F.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
}
|
|
|
//答案和题型
|
|
|
else if(content.startsWith("正确答案")){
|
|
|
- String answerQuestion = content.replace("正确答案:", ";");
|
|
|
+ answerQuestion = content.replace("正确答案:", ";");
|
|
|
if(Validator.isEmpty(answerQuestion)){
|
|
|
throw new CustomException("正确答案错误");
|
|
|
}
|
|
@@ -494,9 +503,11 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
answerQuestion = "0";
|
|
|
type = 3;
|
|
|
}else{
|
|
|
+ answerQuestion = null;
|
|
|
type = 5; //简答题
|
|
|
int j = i;
|
|
|
String q_content = ""; //简答题
|
|
|
+ QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = paragraphList.get(j).getText();
|
|
@@ -507,6 +518,9 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
j++;
|
|
|
}
|
|
|
q_content = q_content.replace("解题思路:", "");
|
|
|
+ bo1.setOptionsId(1L);
|
|
|
+ bo1.setAnalysisContent(q_content);
|
|
|
+ optionsList.add(bo1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -523,8 +537,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
q_content+=tempTxt;
|
|
|
j++;
|
|
|
}
|
|
|
- q_content = q_content.replace("解题思路:", "");
|
|
|
-
|
|
|
+ analysisContent+=q_content;
|
|
|
}
|
|
|
//考查考点
|
|
|
else if(content.startsWith("考查考点:")){
|
|
@@ -539,10 +552,11 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
q_content+=tempTxt;
|
|
|
j++;
|
|
|
}
|
|
|
- q_content = q_content.replace("考查考点:", "");
|
|
|
+ analysisContent = analysisContent + "\r\n" +q_content;
|
|
|
+
|
|
|
}
|
|
|
- //考查考点
|
|
|
- else if(content.startsWith("考查考点:")){
|
|
|
+ //老师解答
|
|
|
+ else if(content.startsWith("老师解答:")){
|
|
|
int j = i;
|
|
|
String q_content = ""; //考查考点
|
|
|
while (j<paragraphList.size())
|
|
@@ -554,12 +568,70 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
q_content+=tempTxt;
|
|
|
j++;
|
|
|
}
|
|
|
+ analysisContent = analysisContent + "\r\n" +q_content;
|
|
|
+ }
|
|
|
+ //问答题问题
|
|
|
+ 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("【问题】", "");
|
|
|
+ QuestionChildAddBo bo1 = optionsList.get(0);
|
|
|
+ bo1.setContent(q_content);
|
|
|
+ }
|
|
|
+ //题目正文
|
|
|
+ else{
|
|
|
+ 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("考查考点:", "");
|
|
|
+ qContent = q_content;
|
|
|
}
|
|
|
}else{
|
|
|
- System.out.println("换行");
|
|
|
- //清空数据
|
|
|
+ System.out.println("换行");
|
|
|
+ QuestionAddBo bo = new QuestionAddBo();
|
|
|
+ if(type==-1){
|
|
|
+ errorLog+="第"+index+"条题目选项错误\n";
|
|
|
+ }
|
|
|
+ bo.setType(type);
|
|
|
+ if(Validator.isEmpty(qContent)){
|
|
|
+ errorLog+="第"+index+"条题目内容空白\n";
|
|
|
+ }
|
|
|
+ bo.setStatus(1);
|
|
|
+ bo.setContent(qContent);
|
|
|
+ bo.setAnswerQuestion(answerQuestion);
|
|
|
+ bo.setAnalysisContent(analysisContent);
|
|
|
+ bo.setOptionsList(optionsList);
|
|
|
+ bo.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ bo.setImportNo(importNo);
|
|
|
+ bo.setPublishStatus(1);
|
|
|
+ errorLog = insertByAddBoImport(bo,i);
|
|
|
+
|
|
|
+ //清空数据
|
|
|
isOption = false;
|
|
|
+ type = -1;
|
|
|
+ qContent = null;
|
|
|
+ index++;
|
|
|
+ answerQuestion = null;
|
|
|
+ analysisContent = "";
|
|
|
+ optionsList.clear();
|
|
|
|
|
|
}
|
|
|
i++;
|
|
@@ -577,7 +649,7 @@ 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)){
|
|
|
+ if(Validator.isEmpty(key)||"解题思路:".equals(key)||"考查考点:".equals(key)||"老师解答:".equals(key)||"正确答案:".equals(key)||"A.".equals(key)||"【问题】".equals(key)){
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
@@ -589,7 +661,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
String errorLog = null;
|
|
|
Question add = BeanUtil.toBean(bo, Question.class);
|
|
|
add.setCode(ServletUtils.getImportEncoded("TM")+no);
|
|
|
- if(bo.getOptionsList()!=null){
|
|
|
+ if(bo.getOptionsList()!=null&&bo.getOptionsList().size()>0){
|
|
|
add.setJsonStr(JSON.toJSONString(bo.getOptionsList()));
|
|
|
}
|
|
|
/*if(checkNameUnique(add)){
|