Browse Source

导入word

he2802 3 years ago
parent
commit
a09a2b2027

+ 280 - 299
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionServiceImpl.java

@@ -235,7 +235,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         }
         String errorLog = "";
         String importNo = ServletUtils.getEncoded("IMPORT");
-        int i = 10;
+        int i = 1;
         Long nowTime = DateUtils.getNowTime();
         List<QuestionImport> errorList = new ArrayList<>();
         for (QuestionImport question : questionList) {
@@ -419,13 +419,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
             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")) {
-                String htmlContent = "";
-
                 InputStream is = file.getInputStream();
                 XWPFDocument doc = new XWPFDocument(is);
                 List<XWPFParagraph> paragraphList = doc.getParagraphs();
@@ -436,7 +430,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                 String qContent = ""; //题目正文
                 String answerQuestion = null; //答案
                 String analysisContent = ""; //解析文本
-                int i = 0;
                 int index = 1; //题目序列号
                 List<QuestionBusinessAddBo> businessList = new ArrayList<>();
                 QuestionBusinessAddBo questionBusinessAddBo = new QuestionBusinessAddBo();
@@ -453,10 +446,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
 
                 Integer nowPart = -1;//0正文 1选项A 2选项B 3选项C 4选项D 5选项E 6选项F
                 String strContent = "";
-                String jtslTxt = "";
-                String lsjdTxt = "";
-                String kckdTxt = "";
-
                 for (XWPFParagraph paragraph : paragraphList) {
                     content = paragraph.getText();
                     List<XWPFRun> runs = paragraph.getRuns();
@@ -501,8 +490,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                         }
                     }
                     content = dealTxt(content);
-                    System.out.println(content);
-                    System.out.println(nowPart);
                     if (content.startsWith("#")||isQuestionStart(content)) {
                         if(nowPart>0){
                             //插入上一条
@@ -510,24 +497,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             qContent = removeNo(qContent);
                             if (Validator.isEmpty(qContent)) {
                                 errorLog += "第" + index + "条题目内容空白\n";
-                                i++;
                                 continue;
                             }
                             QuestionAddBo bo = new QuestionAddBo();
                             if (type == -1) {
                                 errorLog += "第" + index + "条题目选项错误\n";
-                                i++;
                                 continue;
                             }
-                            if(jtslTxt!=""){
-                                analysisContent = analysisContent + jtslTxt +"<br />";
-                            }
-                            if(lsjdTxt!=""){
-                                analysisContent = analysisContent + lsjdTxt +"<br />";
-                            }
-                            if(kckdTxt!=""){
-                                analysisContent = analysisContent + kckdTxt +"<br />";
-                            }
                             bo.setType(type);
 
                             bo.setStatus(1);
@@ -539,7 +515,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             bo.setImportNo(importNo);
                             bo.setPublishStatus(1);
                             bo.setBusinessList(businessList);
-                            bo.setImportSort(sort + nowTime);
                             bo.setCreateTime(nowTime);
                             if(type==1){
                                 list1.add(bo);
@@ -562,9 +537,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             index++;
                             answerQuestion = null;
                             analysisContent = "";
-                            jtslTxt = "";
-                            lsjdTxt = "";
-                            kckdTxt = "";
                             optionsList.clear();
                             nowPart = -1;
                         }
@@ -584,8 +556,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                         nowPart = 0;
                         //新题开头
                         qContent = qContent +   content +"<br />";
-                        System.out.println(qContent);
-                        System.out.println("题目内容");
                     }
                     //第一个选项
                     if(content.startsWith("A.")||(nowPart==1&&!isLineStart(content))) {
@@ -731,36 +701,36 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                     }
                     else if (content.startsWith("解题思路")||(nowPart==8&&!isLineStart(content))) {
                         nowPart = 8;
-                        jtslTxt = jtslTxt +   content +"<br />";
+                        analysisContent = analysisContent +   content +"<br />";
                     }
                     else if (content.startsWith("考查考点")||(nowPart==9&&!isLineStart(content))) {
                         nowPart = 9;
-                        kckdTxt = kckdTxt +   content +"<br />";
+                        analysisContent = analysisContent +   content +"<br />";
                     }
                     else if (content.startsWith("老师解答")||(nowPart==10&&!isLineStart(content))) {
                         nowPart = 10;
-                        lsjdTxt = lsjdTxt +   content +"<br />";
+                        analysisContent = analysisContent +   content +"<br />";
                     }
                 }
                 //遍历正文
-                System.out.println(list1);
-                System.out.println(list2);
-                System.out.println(list3);
-                System.out.println(list4);
                 int importSort = 10;
                 for(QuestionAddBo addBo : list4){
+                    addBo.setImportSort(importSort + addBo.getCreateTime());
                     insertByAddBoImport(addBo,importSort);
                     importSort++;
                 }
                 for(QuestionAddBo addBo : list3){
+                    addBo.setImportSort(importSort + addBo.getCreateTime());
                     insertByAddBoImport(addBo,importSort);
                     importSort++;
                 }
                 for(QuestionAddBo addBo : list2){
+                    addBo.setImportSort(importSort + addBo.getCreateTime());
                     insertByAddBoImport(addBo,importSort);
                     importSort++;
                 }
                 for(QuestionAddBo addBo : list1){
+                    addBo.setImportSort(importSort + addBo.getCreateTime());
                     insertByAddBoImport(addBo,importSort);
                     importSort++;
                 }
@@ -771,7 +741,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                 throw new CustomException("请导入word文件!");
             }
         } catch (IOException e) {
-            System.out.println("此文件不是word文件!A" + e.getMessage() + e.toString() + e.getLocalizedMessage());
+            System.out.println("此文件不是word文件!" + e.getMessage() + e.toString() + e.getLocalizedMessage());
         }
         return errorLog;
     }
@@ -789,14 +759,9 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
             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; //是否判断题
@@ -805,7 +770,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                 String qContent = ""; //题目正文
                 String answerQuestion = null; //答案
                 String analysisContent = ""; //解析文本
-                int i = 0;
                 int index = 1; //题目序列号
                 List<QuestionBusinessAddBo> businessList = new ArrayList<>();
                 QuestionBusinessAddBo questionBusinessAddBo = new QuestionBusinessAddBo();
@@ -814,285 +778,301 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                 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;
+
+                List<QuestionAddBo> list1 = new ArrayList<>(); //单选列表
+                List<QuestionAddBo> list2 = new ArrayList<>(); //多选列表
+                List<QuestionAddBo> list3 = new ArrayList<>(); //简答列表
+                List<QuestionAddBo> list4 = new ArrayList<>(); //判断列表
+
+                Integer nowPart = -1;//0正文 1选项A 2选项B 3选项C 4选项D 5选项E 6选项F
+                String strContent = "";
+                for (XWPFParagraph paragraph : paragraphList) {
+                    content = paragraph.getText();
+                    List<XWPFRun> runs = paragraph.getRuns();
+                    for (XWPFRun run : runs) {
+                        Node node = run.getCTR().getDomNode();
+
+                        // drawing 一个绘画的图片
+                        Node drawingNode = getChildNode(node, "w:drawing");
+                        if (drawingNode == null && content == null) {
+                            continue;
                         }
-                        //第一个选项
-                        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 + "<br />";
-                                j++;
+                        //上传图片
+                        if (Validator.isNotEmpty(drawingNode)) {
+                            // 绘画图片的宽和高
+                            Node extentNode = getChildNode(drawingNode, "wp:extent");
+                            NamedNodeMap extentAttrs = extentNode.getAttributes();
+                            int wPx = ToolsUtils.emuToPx(Double.valueOf(extentAttrs.getNamedItem("cx").getNodeValue()));
+                            //            System.out.println("宽:".concat(extentAttrs.getNamedItem("cx").getNodeValue()).concat("emu"));
+                            //            System.out.println("高:".concat(extentAttrs.getNamedItem("cy").getNodeValue()).concat("emu"));
+                            int HPx = ToolsUtils.emuToPx(Double.valueOf(extentAttrs.getNamedItem("cy").getNodeValue()));
+
+                            // 绘画图片具体引用
+                            Node blipNode = getChildNode(drawingNode, "a:blip");
+                            NamedNodeMap blipAttrs = blipNode.getAttributes();
+                            String rid = blipAttrs.getNamedItem("r:embed").getNodeValue();
+                            //            System.out.println("word中图片ID:".concat(rid));
+
+                            // 获取图片信息
+                            PackagePart part = doc.getPartById(rid);
+                          /*  System.out.println(part.getContentType());
+                            System.out.println(part.getPartName().getName());
+                            System.out.println(part.getInputStream());
+                            System.out.println("------ run ------");*/
+                            String ossPath = null;
+                            try {
+                                ossPath = ossService.uploadInputStream(part.getInputStream(), 8);
+                            } catch (Exception e) {
+                                e.printStackTrace();
                             }
+                            String imgUrl = ossHost + "/" + ossPath + "?x-oss-process=image/resize,w_" + wPx + ",h_" + HPx;
+                            content = "<p><img src=\"" + imgUrl + "\"></p>";
+                        }
+                    }
+                    content = dealTxt(content);
+                    if (content.startsWith("#")||isQuestionStart(content)) {
+                        if(nowPart>0){
+                            //插入上一条
+                            QuestionAddBo addBo = new QuestionAddBo();
+                            qContent = removeNo(qContent);
+                            if (Validator.isEmpty(qContent)) {
+                                errorLog += "第" + index + "条题目内容空白\n";
+                                continue;
+                            }
+                            QuestionAddBo bo = new QuestionAddBo();
+                            if (type == -1) {
+                                errorLog += "第" + index + "条题目选项错误\n";
+                                continue;
+                            }
+                            bo.setType(type);
+
+                            bo.setStatus(1);
+                            bo.setContent(qContent);
+                            bo.setAnswerQuestion(answerQuestion);
+                            bo.setAnalysisContent(analysisContent);
+                            bo.setOptionsList(copyList(optionsList));
+                            bo.setCreateBy(SecurityUtils.getUsername());
+                            bo.setImportNo(importNo);
+                            bo.setPublishStatus(1);
+                            bo.setBusinessList(businessList);
+                            bo.setCreateTime(nowTime);
+                            if(type==1){
+                                list1.add(bo);
+                            }
+                            if(type==2){
+                                list2.add(bo);
+                            }
+                            if(type==3){
+                                list4.add(bo);
+                            }
+                            if(type==5){
+                                list3.add(bo);
+                            }
+                            sort++;
+
+                            //清空数据
+                            isOption = false;
+                            type = -1;
+                            qContent = "";
+                            index++;
+                            answerQuestion = null;
+                            analysisContent = "";
+                            optionsList.clear();
+                            nowPart = -1;
+                        }
+                    }
+
+                    if (content.startsWith("#")) { //导入结束
+                        break;
+                    }
+                    if(Validator.isEmpty(content)||content.equals("")){
+                        continue;
+                    }
+
+                    if (isQuestionStart(content)||(nowPart==0&&!isLineStart(content))) {
+                        if(nowPart!=0){
+                            qContent = "";
+                        }
+                        nowPart = 0;
+                        //新题开头
+                        qContent = qContent +   content +"<br />";
+                    }
+                    //第一个选项
+                    if(content.startsWith("A.")||(nowPart==1&&!isLineStart(content))) {
+                        if(nowPart!=1){
+                            strContent = "";
+                        }
+                        isOption = true; //是选择题
+                        nowPart = 1;
+                        strContent = strContent +   content ;
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<1){
+                            bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(1L);
-                            bo1.setContent(q_content.replace("A.", ""));
+                            bo1.setContent(strContent.replace("A.", ""));
                             optionsList.add(bo1);
-                            i = j - 1; //底部会再执行加回来
+                        }else{
+                            bo1 = optionsList.get(0);
+                            bo1.setContent(strContent.replace("A.", ""));
                         }
-                        //第二个选项
-                        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 + "<br />";
-                                j++;
-                            }
+                    }
+                    //第二个选项
+                    if (content.startsWith("B.")||(nowPart==2&&!isLineStart(content))) {
+                        if(nowPart!=2){
+                            strContent = "";
+                        }
+                        nowPart = 2;
+                        strContent = strContent +  content ;
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<2){
+                            bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(2L);
-                            bo1.setContent(q_content.replace("B.", ""));
+                            bo1.setContent(strContent.replace("B.", ""));
                             optionsList.add(bo1);
-                            i = j - 1; //底部会再执行加回来
+                        }else{
+                            bo1 = optionsList.get(1);
+                            bo1.setContent(strContent.replace("B.", ""));
                         }
-                        //第三个选项
-                        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 + "<br />";
-                                j++;
-                            }
+                    }
+                    //第三个选项
+                    if (content.startsWith("C.")||(nowPart==3&&!isLineStart(content))) {
+                        if(nowPart!=3){
+                            strContent = "";
+                        }
+                        nowPart = 3;
+                        strContent = strContent +   content;
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<3){
+                            bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(3L);
-                            bo1.setContent(q_content.replace("C.", ""));
+                            bo1.setContent(strContent.replace("C.", ""));
                             optionsList.add(bo1);
-                            i = j - 1; //底部会再执行加回来
+                        }else{
+                            bo1 = optionsList.get(2);
+                            bo1.setContent(strContent.replace("C.", ""));
                         }
-                        //第四个选项
-                        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 + "<br />";
-                                j++;
-                            }
+                    }
+                    //第四个选项
+                    if (content.startsWith("D.")||(nowPart==4&&!isLineStart(content))) {
+                        if(nowPart!=4){
+                            strContent = "";
+                        }
+                        nowPart = 4;
+                        strContent = strContent +   content ;
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<4){
+                            bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(4L);
-                            bo1.setContent(q_content.replace("D.", ""));
+                            bo1.setContent(strContent.replace("D.", ""));
                             optionsList.add(bo1);
-                            i = j - 1; //底部会再执行加回来
+                        }else{
+                            bo1 = optionsList.get(3);
+                            bo1.setContent(strContent.replace("D.", ""));
                         }
-                        //第五个选项
-                        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 + "<br />";
-                                j++;
-                            }
+                    }
+                    //第五个选项
+                    if (content.startsWith("E.")||(nowPart==5&&!isLineStart(content))) {
+                        if(nowPart!=5){
+                            strContent = "";
+                        }
+                        nowPart = 5;
+                        strContent = strContent +   content ;
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<5){
+                            bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(5L);
-                            bo1.setContent(q_content.replace("E.", ""));
+                            bo1.setContent(strContent.replace("E.", ""));
                             optionsList.add(bo1);
-                            i = j - 1; //底部会再执行加回来
+                        }else{
+                            bo1 = optionsList.get(4);
+                            bo1.setContent(strContent.replace("E.", ""));
                         }
-                        //第六个选项
-                        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 + "<br />";
-                                j++;
-                            }
+                    }
+                    //第六个选项
+                    if (content.startsWith("F.")||(nowPart==6&&!isLineStart(content))) {
+                        if(nowPart!=6){
+                            strContent = "";
+                        }
+                        nowPart = 6;
+                        strContent = strContent +   content ;
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<6){
+                            bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(6L);
-                            bo1.setContent(q_content.replace("F.", ""));
+                            bo1.setContent(strContent.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 + "<br />";
-                                        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);*/
-                                    analysisContent += q_content + "<br />";
-                                    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 + "<br />";
-                                j++;
-                            }
-                            analysisContent += q_content;
-                            i = j - 1; //底部会再执行加回来
+                        }else{
+                            bo1 = optionsList.get(5);
+                            bo1.setContent(strContent.replace("F.", ""));
                         }
-                        //考查考点
-                        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 + "<br />";
-                                j++;
-                            }
-                            analysisContent = analysisContent + "\r\n" + q_content;
-                            i = j - 1; //底部会再执行加回来
+                    }
+                    //答案和题型
+                    if (content.startsWith("正确答案:")||(nowPart==7&&!isLineStart(content))) {
+                        if(nowPart!=7){
+                            strContent = "";
                         }
-                        //老师解答
-                        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; //底部会再执行加回来
+                        answerQuestion = content.replace("正确答案:", "");
+                        if (Validator.isEmpty(answerQuestion)) {
+                            throw new CustomException("正确答案错误");
                         }
-                        //问答题问题
-                        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 + "<br />";
-                                j++;
+                        nowPart = 7;
+                        if (isOption) {
+                            //选择题
+                            answerQuestion = dealImportAnswer(answerQuestion);
+                            if (answerQuestion.length() > 1) {
+                                type = 2; //多选
+                            } else {
+                                type = 1; //单选
                             }
-                            q_content = q_content.replace("【问题】", "");
-                            QuestionChildAddBo bo1 = null;
-                            if (optionsList.size() == 0) {
-                                bo1 = new QuestionChildAddBo();
-                                optionsList.add(bo1);
+                        } else {
+                            if ("正确".equals(answerQuestion)) {
+                                answerQuestion = "1";
+                                type = 3; //判断
+                            } else if ("错误".equals(answerQuestion)) {
+                                answerQuestion = "0";
+                                type = 3;
+                            } else {
+                                answerQuestion = null;
+                                type = 5; //简答题
+                                strContent = strContent +  "<br />" + content; //答案文本
                             }
-                            bo1 = optionsList.get(0);
-                            bo1.setOptionsId(1L);
-                            bo1.setContent(q_content);
-                            i = j - 1; //底部会再执行加回来
-                        }
-                        //题目正文
-                        else {
-                            qContent += content + "<br />";
-                        }
-                    } 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);
-                        List<QuestionChildAddBo> optionsListBak = new ArrayList<>();
-                        optionsListBak.addAll(optionsList);
-                        bo.setOptionsList(optionsListBak);
-                        bo.setCreateBy(SecurityUtils.getUsername());
-                        bo.setImportNo(importNo);
-                        bo.setPublishStatus(1);
-                        bo.setBusinessList(businessList);
-                        bo.setImportSort(sort + nowTime);
-                        bo.setCreateTime(nowTime);
-                        list.add(bo);
-                        //清空数据
-                        isOption = false;
-                        type = -1;
-                        qContent = "";
-                        index++;
-                        sort++;
-                        answerQuestion = null;
-                        analysisContent = "";
-                        optionsList.clear();
+
                     }
-                    i++;
+                    else if (content.startsWith("解题思路")||(nowPart==8&&!isLineStart(content))) {
+                        nowPart = 8;
+                        analysisContent = analysisContent +   content +"<br />";
+                    }
+                    else if (content.startsWith("考查考点")||(nowPart==9&&!isLineStart(content))) {
+                        nowPart = 9;
+                        analysisContent = analysisContent +   content +"<br />";
+                    }
+                    else if (content.startsWith("老师解答")||(nowPart==10&&!isLineStart(content))) {
+                        nowPart = 10;
+                        analysisContent = analysisContent +   content +"<br />";
+                    }
+                }
+                //遍历正文
+                int importSort = 1;
+                for(QuestionAddBo addBo : list4){
+                    addBo.setImportSort(importSort + addBo.getCreateTime());
+                    list.add(addBo);
+                    importSort++;
+                }
+                for(QuestionAddBo addBo : list3){
+                    addBo.setImportSort(importSort + addBo.getCreateTime());
+                    list.add(addBo);
+                    importSort++;
+                }
+                for(QuestionAddBo addBo : list2){
+                    addBo.setImportSort(importSort + addBo.getCreateTime());
+                    list.add(addBo);
+                    importSort++;
+                }
+                for(QuestionAddBo addBo : list1){
+                    addBo.setImportSort(importSort + addBo.getCreateTime());
+                    list.add(addBo);
+                    importSort++;
                 }
                 //    buffer = extractor.getText();
                 //extractor.close();
@@ -1103,11 +1083,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         } catch (IOException e) {
             System.out.println("此文件不是word文件!" + e.getMessage() + e.toString() + e.getLocalizedMessage());
         }
+        Collections.reverse(list);
         return list;
     }
 
     private String removeNo(String txt) {
-        int intIndex = txt.indexOf(".");
+        int intIndex = txt.indexOf("");
         if (intIndex != -1) {
             txt = txt.substring(intIndex + 1);
         }

+ 1 - 1
zhongzheng-system/src/main/resources/mapper/modules/bank/QuestionMapper.xml

@@ -207,7 +207,7 @@
         </if>
         GROUP BY
         q.question_id
-        ORDER BY q.create_time DESC,q.import_sort
+        ORDER BY q.question_id DESC
     </select>
 
     <select id="selectList_COUNT" resultType="Long">