|
@@ -680,6 +680,340 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
return errorLog;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<QuestionAddBo> importWordQuestionList(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId) {
|
|
|
+ List<QuestionAddBo> list = new ArrayList<>();
|
|
|
+ String errorLog = ""; //错误提示
|
|
|
+ String buffer = "";
|
|
|
+ String importNo = ServletUtils.getEncoded("IMPORT");
|
|
|
+ try{
|
|
|
+ String path = file.getOriginalFilename();
|
|
|
+ if (path.endsWith(".doc")) {
|
|
|
+ throw new CustomException("不支持doc格式");
|
|
|
+ /*InputStream is = file.getInputStream();
|
|
|
+ WordExtractor wordExtractor = new WordExtractor(is);
|
|
|
+ buffer = wordExtractor.getText();
|
|
|
+ wordExtractor.close();*/
|
|
|
+ } else if (path.endsWith("docx")) {
|
|
|
+ InputStream is = file.getInputStream();
|
|
|
+ XWPFDocument doc = new XWPFDocument(is);
|
|
|
+ // XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
|
|
|
+ List<XWPFParagraph> paragraphList = doc.getParagraphs();
|
|
|
+ int type = -1; //题目类型
|
|
|
+ boolean isOption = false; //是否判断题
|
|
|
+ List<QuestionChildAddBo> optionsList =new ArrayList<>(); //题目选项
|
|
|
+ String content = ""; //每行正文
|
|
|
+ String qContent = ""; //题目正文
|
|
|
+ String answerQuestion = null; //答案
|
|
|
+ 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())
|
|
|
+ {
|
|
|
+ content = paragraphList.get(i).getText();
|
|
|
+ if(Validator.isNotEmpty(content)){
|
|
|
+ content =dealTxt(content);
|
|
|
+ if(content.startsWith("注意事项")){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //第一个选项
|
|
|
+ if(content.startsWith("A.")){
|
|
|
+ isOption = true;
|
|
|
+ QuestionChildAddBo bo1 = new QuestionChildAddBo();
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //题目正文
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
|
+ if(Validator.isEmpty(tempTxt)||tempTxt.startsWith("B.")){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ 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+1;
|
|
|
+ String q_content =content; //题目正文
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
|
+ if(Validator.isEmpty(tempTxt)||tempTxt.startsWith("C.")){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ 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+1;
|
|
|
+ String q_content = content; //题目正文
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
|
+ if(Validator.isEmpty(tempTxt)||tempTxt.startsWith("D.")){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ 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+1;
|
|
|
+ String q_content = content; //题目正文
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
|
+ if(Validator.isEmpty(tempTxt)||tempTxt.startsWith("E.")||tempTxt.startsWith("正确答案")){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ 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+1;
|
|
|
+ String q_content = content; //题目正文
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
|
+ if(Validator.isEmpty(tempTxt)||tempTxt.startsWith("F.")||tempTxt.startsWith("正确答案")){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ 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+1;
|
|
|
+ String q_content = content; //题目正文
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
|
+ if(Validator.isEmpty(tempTxt)||tempTxt.startsWith("G.")||tempTxt.startsWith("正确答案")){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ bo1.setOptionsId(6L);
|
|
|
+ bo1.setContent(q_content.replace("F.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
+ }
|
|
|
+ //答案和题型
|
|
|
+ else if(content.startsWith("正确答案")){
|
|
|
+ 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{
|
|
|
+ answerQuestion = null;
|
|
|
+ type = 5; //简答题
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = 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 = null;
|
|
|
+ if(optionsList.size()==0){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }
|
|
|
+ bo1 = optionsList.get(0);
|
|
|
+ bo1.setOptionsId(1L);
|
|
|
+ bo1.setAnalysisContent(q_content);
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //解题思路
|
|
|
+ else if(content.startsWith("解题思路:")){
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //解题思路
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
|
+ if(checkKey(tempTxt)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ analysisContent+=q_content;
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
+ }
|
|
|
+ //考查考点
|
|
|
+ else if(content.startsWith("考查考点:")){
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //考查考点
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
|
+ if(checkKey(tempTxt)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ analysisContent = analysisContent + "\r\n" +q_content;
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
+ }
|
|
|
+ //老师解答
|
|
|
+ else if(content.startsWith("老师解答:")){
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //考查考点
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
|
+ if(checkKey(tempTxt)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ analysisContent = analysisContent + "\r\n" +q_content;
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
+ }
|
|
|
+ //问答题问题
|
|
|
+ else if(content.startsWith("【问题】")){
|
|
|
+ //多个问题合在一起
|
|
|
+ int j = i+1;
|
|
|
+ String q_content = content; //问题
|
|
|
+ while (j<paragraphList.size())
|
|
|
+ {
|
|
|
+ String tempTxt = dealTxt(paragraphList.get(j).getText());
|
|
|
+ if(checkKey(tempTxt)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ q_content+=tempTxt;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ q_content = q_content.replace("【问题】", "");
|
|
|
+ QuestionChildAddBo bo1 = null;
|
|
|
+ if(optionsList.size()==0){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }
|
|
|
+ bo1 = optionsList.get(0);
|
|
|
+ bo1.setOptionsId(1L);
|
|
|
+ bo1.setContent(q_content);
|
|
|
+ i = j-1; //底部会再执行加回来
|
|
|
+ }
|
|
|
+ //题目正文
|
|
|
+ else{
|
|
|
+ qContent += content;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ qContent = removeNo(qContent);
|
|
|
+ if(Validator.isEmpty(qContent)){
|
|
|
+ errorLog+="第"+index+"条题目内容空白\n";
|
|
|
+ i++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ QuestionAddBo bo = new QuestionAddBo();
|
|
|
+ if(type==-1){
|
|
|
+ errorLog+="第"+index+"条题目选项错误\n";
|
|
|
+ i++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ bo.setType(type);
|
|
|
+
|
|
|
+ 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);
|
|
|
+ bo.setBusinessList(businessList);
|
|
|
+ list.add(bo);
|
|
|
+ //清空数据
|
|
|
+ isOption = false;
|
|
|
+ type = -1;
|
|
|
+ qContent = "";
|
|
|
+ index++;
|
|
|
+ answerQuestion = null;
|
|
|
+ analysisContent = "";
|
|
|
+ optionsList.clear();
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ // buffer = extractor.getText();
|
|
|
+ //extractor.close();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new CustomException("请导入word文件!");
|
|
|
+ }
|
|
|
+ }catch (IOException e){
|
|
|
+ System.out.println("此文件不是word文件!A"+e.getMessage()+e.toString()+e.getLocalizedMessage());
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
private String removeNo(String txt){
|
|
|
int intIndex = txt.indexOf(".");
|
|
|
if(intIndex != -1){
|