|
@@ -347,7 +347,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void importWordQuestion(MultipartFile file) {
|
|
|
+ public void importWordQuestion(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId) {
|
|
|
String buffer = "";
|
|
|
String importNo = ServletUtils.getEncoded("IMPORT");
|
|
|
try{
|
|
@@ -361,7 +361,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
} else if (path.endsWith("docx")) {
|
|
|
InputStream is = file.getInputStream();
|
|
|
XWPFDocument doc = new XWPFDocument(is);
|
|
|
- XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
|
|
|
+ // XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
|
|
|
List<XWPFParagraph> paragraphList = doc.getParagraphs();
|
|
|
int type = -1; //题目类型
|
|
|
boolean isOption = false; //是否判断题
|
|
@@ -373,14 +373,19 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
String analysisContent = ""; //解析文本
|
|
|
int i = 0;
|
|
|
int index = 1; //题目序列号
|
|
|
+ List<QuestionBusinessAddBo> businessList = new ArrayList<>();
|
|
|
+ QuestionBusinessAddBo questionBusinessAddBo = new QuestionBusinessAddBo();
|
|
|
+ questionBusinessAddBo.setEducationTypeId(eduId);
|
|
|
+ questionBusinessAddBo.setProjectId(projectId);
|
|
|
+ questionBusinessAddBo.setBusinessId(businessId);
|
|
|
+ questionBusinessAddBo.setSubjectId(subjectId);
|
|
|
+ businessList.add(questionBusinessAddBo);
|
|
|
//遍历正文
|
|
|
while (i<paragraphList.size())
|
|
|
{
|
|
|
- XWPFParagraph paragraph = paragraphList.get(i);
|
|
|
- content =dealTxt(paragraph.getText());
|
|
|
- System.out.println(content);
|
|
|
- // content = trimFirstAndLastChar(content, "\t");
|
|
|
+ content = paragraphList.get(i).getText();
|
|
|
if(Validator.isNotEmpty(content)){
|
|
|
+ content =dealTxt(content);
|
|
|
if(content.startsWith("注意事项")){
|
|
|
break;
|
|
|
}
|
|
@@ -388,8 +393,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
if(content.startsWith("A.")){
|
|
|
isOption = true;
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //题目正文
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
@@ -402,12 +407,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
bo1.setOptionsId(1L);
|
|
|
bo1.setContent(q_content.replace("A.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
//第二个选项
|
|
|
else if(content.startsWith("B.")){
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //题目正文
|
|
|
+ int j = i+1;
|
|
|
+ String q_content =content; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
@@ -420,12 +426,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
bo1.setOptionsId(2L);
|
|
|
bo1.setContent(q_content.replace("B.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
//第三个选项
|
|
|
else if(content.startsWith("C.")){
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //题目正文
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
@@ -438,12 +445,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
bo1.setOptionsId(3L);
|
|
|
bo1.setContent(q_content.replace("C.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
//第四个选项
|
|
|
else if(content.startsWith("D.")){
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //题目正文
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
@@ -456,12 +464,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
bo1.setOptionsId(4L);
|
|
|
bo1.setContent(q_content.replace("D.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
//第五个选项
|
|
|
else if(content.startsWith("E.")){
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //题目正文
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
@@ -474,12 +483,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
bo1.setOptionsId(5L);
|
|
|
bo1.setContent(q_content.replace("E.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
//第六个选项
|
|
|
else if(content.startsWith("F.")){
|
|
|
QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //题目正文
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //题目正文
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
@@ -492,10 +502,11 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
bo1.setOptionsId(6L);
|
|
|
bo1.setContent(q_content.replace("F.", ""));
|
|
|
optionsList.add(bo1);
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
//答案和题型
|
|
|
else if(content.startsWith("正确答案")){
|
|
|
- answerQuestion = content.replace("正确答案:", ";");
|
|
|
+ answerQuestion = content.replace("正确答案:", "");
|
|
|
if(Validator.isEmpty(answerQuestion)){
|
|
|
throw new CustomException("正确答案错误");
|
|
|
}
|
|
@@ -508,6 +519,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
type = 1; //单选
|
|
|
}
|
|
|
}else{
|
|
|
+ System.out.println(answerQuestion+"我的大大问题A");
|
|
|
if("正确".equals(answerQuestion)){
|
|
|
answerQuestion = "1";
|
|
|
type = 3; //判断
|
|
@@ -518,8 +530,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
}else{
|
|
|
answerQuestion = null;
|
|
|
type = 5; //简答题
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //简答题
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //简答题
|
|
|
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
@@ -530,7 +542,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
q_content+=tempTxt;
|
|
|
j++;
|
|
|
}
|
|
|
- q_content = q_content.replace("解题思路:", "");
|
|
|
+ q_content = q_content.replace("正确答案:", "");
|
|
|
QuestionChildAddBo bo1 = null;
|
|
|
if(optionsList.size()==0){
|
|
|
bo1 = new QuestionChildAddBo();
|
|
@@ -539,13 +551,14 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
bo1 = optionsList.get(0);
|
|
|
bo1.setOptionsId(1L);
|
|
|
bo1.setAnalysisContent(q_content);
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//解题思路
|
|
|
else if(content.startsWith("解题思路:")){
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //解题思路
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //解题思路
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
@@ -556,12 +569,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
j++;
|
|
|
}
|
|
|
analysisContent+=q_content;
|
|
|
- i = j;
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
//考查考点
|
|
|
else if(content.startsWith("考查考点:")){
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //考查考点
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //考查考点
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
@@ -572,12 +585,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
j++;
|
|
|
}
|
|
|
analysisContent = analysisContent + "\r\n" +q_content;
|
|
|
- i = j;
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
//老师解答
|
|
|
else if(content.startsWith("老师解答:")){
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //考查考点
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //考查考点
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
@@ -588,13 +601,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
j++;
|
|
|
}
|
|
|
analysisContent = analysisContent + "\r\n" +q_content;
|
|
|
- i = j;
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
//问答题问题
|
|
|
else if(content.startsWith("【问题】")){
|
|
|
//多个问题合在一起
|
|
|
- int j = i;
|
|
|
- String q_content = ""; //问题
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //问题
|
|
|
while (j<paragraphList.size())
|
|
|
{
|
|
|
String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
@@ -613,7 +626,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
bo1 = optionsList.get(0);
|
|
|
bo1.setOptionsId(1L);
|
|
|
bo1.setContent(q_content);
|
|
|
- i = j;
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
}
|
|
|
//题目正文
|
|
|
else{
|
|
@@ -624,10 +637,14 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
QuestionAddBo bo = new QuestionAddBo();
|
|
|
if(type==-1){
|
|
|
errorLog+="第"+index+"条题目选项错误\n";
|
|
|
+ i++;
|
|
|
+ continue;
|
|
|
}
|
|
|
bo.setType(type);
|
|
|
if(Validator.isEmpty(qContent)){
|
|
|
errorLog+="第"+index+"条题目内容空白\n";
|
|
|
+ i++;
|
|
|
+ continue;
|
|
|
}
|
|
|
bo.setStatus(1);
|
|
|
bo.setContent(removeNo(qContent));
|
|
@@ -637,12 +654,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
bo.setCreateBy(SecurityUtils.getUsername());
|
|
|
bo.setImportNo(importNo);
|
|
|
bo.setPublishStatus(1);
|
|
|
+ bo.setBusinessList(businessList);
|
|
|
errorLog = insertByAddBoImport(bo,i);
|
|
|
|
|
|
//清空数据
|
|
|
isOption = false;
|
|
|
type = -1;
|
|
|
- qContent = null;
|
|
|
+ qContent = "";
|
|
|
index++;
|
|
|
answerQuestion = null;
|
|
|
analysisContent = "";
|
|
@@ -651,7 +669,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
i++;
|
|
|
}
|
|
|
// buffer = extractor.getText();
|
|
|
- extractor.close();
|
|
|
+ //extractor.close();
|
|
|
|
|
|
} else {
|
|
|
throw new CustomException("请导入word文件!");
|