he2802 1 year ago
parent
commit
91f0527099

+ 9 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/bank/QuestionController.java

@@ -298,4 +298,13 @@ public class QuestionController extends BaseController {
         Map<String,Object> result = iQuestionService.importXueJianWordQuestionList(file,  eduId,  projectId,  businessId, subjectId);
         return AjaxResult.success(result);
     }
+
+    @ApiOperation("导入二建精选题目Word模板列表")
+    @PreAuthorize("@ss.hasPermi('system:question:import')")
+    @PostMapping("/importErJianWordQuestionList")
+    public AjaxResult<Map<String,Object>> importErJianWordQuestionList(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId) throws Exception
+    {
+        Map<String,Object> result = iQuestionService.importErJianWordQuestionList(file,  eduId,  projectId,  businessId, subjectId);
+        return AjaxResult.success(result);
+    }
 }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/IQuestionService.java

@@ -90,6 +90,9 @@ public interface IQuestionService extends IService<Question> {
 
 	Map<String,Object> importXueJianWordQuestionList(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId);
 
+	Map<String,Object> importErJianWordQuestionList(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId);
+
+
     boolean batchDelQuestion(QuestionBatchDelBo bo);
 
     List<BankGoodsExamVo> getBankGoodsExamList(Long goodsId);

+ 486 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionServiceImpl.java

@@ -73,8 +73,7 @@ import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.math.BigDecimal;
 import java.text.NumberFormat;
 import java.util.*;
@@ -1129,9 +1128,18 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         if (content.startsWith("二、多项选择题")) {
             return true;
         }
+        if (content.indexOf("多项选择题")>-1) {
+            return true;
+        }
         if (content.startsWith("三、实务操作和案例分析题")) {
             return true;
         }
+        if (content.indexOf("案例分析题")>-1) {
+            return true;
+        }
+        if (content.startsWith("参考答案")) {
+            return true;
+        }
         if (Validator.isNotEmpty(content)) {
             if(type==5){
                 if(alKeyList.contains(content)){
@@ -1195,6 +1203,16 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         return false;
     }
 
+    private boolean isNumStart(String content) {
+        for(int i=1;i<40;i++){
+            String num = i+".";
+            if(content.startsWith(num)){
+                return true;
+            }
+        }
+        return false;
+    }
+
     private boolean isNotOptionStart(String content) {
         if (Validator.isNotEmpty(content)) {
             if(isQuestionStart(content)||content.startsWith("正确答案")||content.startsWith("解题思路")||content.startsWith("考查考点")||content.startsWith("老师解答")
@@ -2436,6 +2454,472 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         return result;
     }
 
+    @Override
+    public Map<String, Object> importErJianWordQuestionList(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId) {
+        Map<String,Object> result = new HashMap<>();
+        List<QuestionAddBo> list = new ArrayList<>();
+        String errorLog = ""; //错误提示
+        String examName = "";
+        String importNo = ServletUtils.getEncoded("IMPORT");
+        Long sort = 1L;
+        if(Validator.isEmpty(file)){
+            throw new CustomException("请选择文件");
+        }
+        try {
+            Long nowTime = DateUtils.getNowTime();
+            String path = file.getOriginalFilename();
+            if (path.endsWith(".doc")) {
+                throw new CustomException("不支持doc格式");
+            } else if (path.endsWith("docx")) {
+                InputStream is = file.getInputStream();
+                XWPFDocument doc = new XWPFDocument(is);
+                List<XWPFParagraph> paragraphList = doc.getParagraphs();
+                int type = -1;  //题目类型
+                int aType = -1;  //答案题目类型
+                boolean isOption = false; //是否判断题
+                List<QuestionChildAddBo> optionsList = new ArrayList<>(); //题目选项
+                String content = ""; //每行正文
+                String qContent = ""; //题目正文
+                String answerQuestion = null; //答案
+                String analysisContent = ""; //解析文本
+                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);
+
+                List<QuestionAddBo> list1 = new ArrayList<>(); //单选列表
+                List<QuestionAddBo> list2 = new ArrayList<>(); //多选列表
+                List<QuestionAddBo> list3 = new ArrayList<>(); //简答列表
+                List<QuestionAddBo> list4 = new ArrayList<>(); //判断列表
+                Map<String,QuestionAddBo> allQues = new LinkedHashMap<>();
+                Integer nowPart = -1;//0正文 1选项A 2选项B 3选项C 4选项D 5选项E 6选项F
+                String strContent = "";
+                String imgUrl = "";
+                boolean hasQuestion = false;
+                boolean hasRightTag = false;
+                boolean hasError = false;
+                boolean answerStatus = false;
+                int cIndex = 1;
+                int nIndex = 2;
+                List<String> alKeyList  = new ArrayList<>();
+                alKeyList.add("案例(一)");
+                alKeyList.add("案例(二)");
+                alKeyList.add("案例(三)");
+                alKeyList.add("案例(四)");
+                alKeyList.add("案例(五)");
+                alKeyList.add("案例(六)");
+                alKeyList.add("案例(七)");
+                alKeyList.add("案例(八)");
+                alKeyList.add("案例(九)");
+                alKeyList.add("案例(十)");
+                String indexKey = null;
+                for (XWPFParagraph paragraph : paragraphList) {
+                    content = paragraph.getText();
+                    content = dealTxt(content);
+                    if(content.equals("")){
+                        continue;
+                    }
+                    System.out.println(content);
+                    List<XWPFRun> runs = paragraph.getRuns();
+                    imgUrl = null;
+                    //    System.out.println(content);
+                    for (XWPFRun run : runs) {
+                        Node node = run.getCTR().getDomNode();
+
+                        // drawing 一个绘画的图片
+                        Node drawingNode = getChildNode(node, "w:drawing");
+                        if (drawingNode == null && content == null) {
+                            imgUrl = null;
+                            continue;
+                        }
+
+                        //上传图片
+                        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");
+                            if(Validator.isNotEmpty(blipNode)){
+                                NamedNodeMap blipAttrs = blipNode.getAttributes();
+                                String rid = blipAttrs.getNamedItem("r:embed").getNodeValue();
+                                //            System.out.println("word中图片ID:".concat(rid));
+
+                                // 获取图片信息
+                                PackagePart part = doc.getPartById(rid);
+
+                                String ossPath = null;
+                                try {
+                                   /* ossPath = ossService.uploadInputStream(part.getInputStream(), 8);
+                                    System.out.println(part.getSize()+"图片大小");
+                                    System.out.println(ossPath);*/
+                                } catch (Exception e) {
+                                    e.printStackTrace();
+                                }
+                               /* imgUrl =  ossPath + "?x-oss-process=image/resize,w_" + wPx + ",h_" + HPx;
+                                if(type==5){
+                                    //正文图片
+                                    QuestionAddBo cAddBo = allQues.get(indexKey);
+                                    cAddBo.setContent(cAddBo.getContent()+"<br />" +"<p><img src=\"" + ossHost + "/" + imgUrl + "\"></p>");
+                                }*/
+                            }
+                        }
+                    }
+                    if(content.indexOf("参考答案")>-1){
+                        System.out.println(content);
+                    }
+                    if (content.startsWith("###")||isXueJianQuestionStart(content,type,alKeyList)) {
+
+                        if(hasQuestion&&!answerStatus){
+                            index++;
+                            hasQuestion = false;
+                            //插入上一条
+                            QuestionAddBo addBo = new QuestionAddBo();
+                            qContent = removeXueJianNo(qContent,type);
+                            if (Validator.isEmpty(qContent)) {
+                                hasError = true;
+                                errorLog += "第" + index + "条题目内容错误\n";
+                                continue;
+                            }
+                            QuestionAddBo bo = new QuestionAddBo();
+                            if (type == -1) {
+                                hasError = true;
+                                errorLog += "第" + index + "条题目选项错误\n";
+                                continue;
+
+                            }
+                            if(!hasError){
+                               /* if (Validator.isEmpty(answerQuestion)) {
+                                    errorLog += "第" + index + "正确答案错误\n";
+                                    continue;
+
+                                }*/
+                                if(type==5){
+                                    answerQuestion = null;
+                                }
+                                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++;
+                            hasError = false;
+                            //清空数据
+                            isOption = false;
+                            qContent = "";
+                            analysisContent = "";
+                            optionsList.clear();
+                            nowPart = -1;
+                            hasRightTag= false;
+                        }
+                    }
+
+                    if(nowPart==8){
+                        if(isNumStart((content))||content.indexOf("###")>-1||content.indexOf("章标题")>-1){
+                            if(Validator.isNotEmpty(qContent)&&!qContent.equals("")){
+                                String[] sList = qContent.split("【解析】");
+                                if (sList.length>1) {
+                                    String jiexi = sList[1];
+                                    String[] daList = sList[0].split("\\.");
+                                    int num = Integer.valueOf(daList[0]);
+                                    String daan = daList[1];
+                                    QuestionAddBo  addBo = list1.get(num-1);
+                                    addBo.setAnalysisContent(jiexi);
+                                    addBo.setAnswerQuestion(dealImportAnswer(daan));
+                                }
+                            }
+                        }
+                        qContent = qContent +   content +"<br />";
+                    }
+                   /* if (content.indexOf("-Reference")>0){
+                        answerStatus = true;
+                    }*/
+    //                System.out.println(content);
+                    if (content.indexOf("章标题:")>-1){
+                        examName = content.substring(4);
+
+                        answerStatus = false;
+    //                    System.out.println("试卷名"+examName);
+                    }
+                    if (content.indexOf("章标题:")>-1||content.startsWith("###")) { //插入章
+                        list1.clear();
+                        list2.clear();
+                        list3.clear();
+                        list4.clear();
+
+                        continue;
+                    }
+                    if(content.indexOf("单项选择题")>-1&&!answerStatus){
+                        type = 1;
+                        continue;
+                    }
+                    if(content.indexOf("多项选择题")>-1&&!answerStatus){
+                        type = 2;
+                        continue;
+                    }
+                    if(content.indexOf("案例分析题")>-1&&!answerStatus){
+                        type = 5;
+                        continue;
+                    }
+
+                    //第一个选项
+                    if(content.startsWith("А.")||content.startsWith("A.")||(nowPart==1&&!isXueJianLineStart(content,type,alKeyList))) {
+                        hasQuestion = true;
+                        if(nowPart!=1){
+                            strContent = "";
+                        }
+                        isOption = true; //是选择题
+                        nowPart = 1;
+                        if(content.indexOf("B.")>0){
+                            //带B
+                            int len = content.indexOf("B.");
+                            strContent = content.substring(0,len) ;
+                            System.out.println("A选项"+strContent);
+                        }else{
+                            strContent = strContent +   content ;
+                        }
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<1){
+                            bo1 = new QuestionChildAddBo();
+                            bo1.setOptionsId(1L);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("A.", "").replace("А.", "").trim());
+                            optionsList.add(bo1);
+                        }else{
+                            bo1 = optionsList.get(0);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("A.", "").replace("А.", "").trim());
+                        }
+
+
+                    }
+                    //第二个选项
+                    if (content.indexOf("B.")>0||content.startsWith("B.")||(nowPart==2&&!isXueJianLineStart(content,type,alKeyList))) {
+                        if (optionsList.size()<1) {
+                            errorLog += "第" + index + "条题目选项A错误\n";
+                            continue;
+                        }
+                        if(nowPart!=2){
+                            strContent = "";
+                        }
+                        nowPart = 2;
+                        if(content.indexOf("B.")>0){
+                            //带B
+                            int len = content.indexOf("B.");
+                            strContent = content.substring(len,content.length()) ;
+                        }else{
+                            strContent = strContent +  content ;
+                        }
+
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<2){
+                            bo1 = new QuestionChildAddBo();
+                            bo1.setOptionsId(2L);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("B.", "").trim());
+                            optionsList.add(bo1);
+                        }else{
+                            bo1 = optionsList.get(1);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("B.", "").trim());
+                        }
+                        continue;
+                    }
+                    //第三个选项
+                    if (content.startsWith("C.")||(nowPart==3&&!isXueJianLineStart(content,type,alKeyList))) {
+                        if(nowPart!=3){
+                            strContent = "";
+                        }
+                        nowPart = 3;
+                        if(content.indexOf("D.")>0){
+                            //带B
+                            int len = content.indexOf("D.");
+                            strContent = content.substring(0,len) ;
+                            System.out.println("C选项"+strContent);
+                        }else{
+                            strContent = strContent +   content ;
+                        }
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<3){
+                            bo1 = new QuestionChildAddBo();
+                            bo1.setOptionsId(3L);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("C.", "").trim());
+                            optionsList.add(bo1);
+                        }else{
+                            bo1 = optionsList.get(2);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("C.", "").trim());
+                        }
+
+                    }
+                    //第四个选项
+                    if (content.indexOf("D.")>0||content.startsWith("D.")||(nowPart==4&&!isXueJianLineStart(content,type,alKeyList))) {
+                        if(nowPart!=4){
+                            strContent = "";
+                        }
+                        nowPart = 4;
+                        if(content.indexOf("D.")>0){
+                            //带B
+                            int len = content.indexOf("D.");
+                            strContent = content.substring(len,content.length()) ;
+                            System.out.println("D选项"+strContent);
+                        }else{
+                            strContent = strContent +   content ;
+                        }
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<4){
+                            bo1 = new QuestionChildAddBo();
+                            bo1.setOptionsId(4L);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("D.", "").trim());
+                            optionsList.add(bo1);
+                        }else{
+                            bo1 = optionsList.get(3);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("D.", "").trim());
+                        }
+                        continue;
+                    }
+                    //第五个选项
+                    if (content.startsWith("E.")||(nowPart==5&&!isXueJianLineStart(content,type,alKeyList))) {
+                        if(nowPart!=5){
+                            strContent = "";
+                        }
+                        nowPart = 5;
+                        if(content.indexOf("F.")>0){
+                            //带B
+                            int len = content.indexOf("F.");
+                            strContent = content.substring(0,len) ;
+                            System.out.println("E选项"+strContent);
+                        }else{
+                            strContent = strContent +   content ;
+                        }
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<5){
+                            bo1 = new QuestionChildAddBo();
+                            bo1.setOptionsId(5L);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("E.", "").trim());
+                            optionsList.add(bo1);
+                        }else{
+                            bo1 = optionsList.get(4);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("E.", "").trim());
+                        }
+                        continue;
+                    }
+                    //第六个选项
+                    if (content.indexOf("F.")>0||content.startsWith("F.")||(nowPart==6&&!isXueJianLineStart(content,type,alKeyList))) {
+                        if(nowPart!=6){
+                            strContent = "";
+                        }
+                        nowPart = 6;
+                        if(content.indexOf("F.")>0){
+                            //带B
+                            int len = content.indexOf("F.");
+                            strContent = content.substring(len,content.length()) ;
+                            System.out.println("F选项"+strContent);
+                        }else{
+                            strContent = strContent +   content ;
+                        }
+                        QuestionChildAddBo bo1;
+                        if(optionsList.size()<6){
+                            bo1 = new QuestionChildAddBo();
+                            bo1.setOptionsId(6L);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("F.", "").trim());
+                            optionsList.add(bo1);
+                        }else{
+                            bo1 = optionsList.get(5);
+                            bo1.setImgUrl(imgUrl);
+                            bo1.setContent(strContent.replace("F.", "").trim());
+                        }
+                        continue;
+                    }
+                    //答案和题型
+                    if (content.indexOf("参考答案")>-1) {
+                        answerStatus = true;
+                        continue;
+                    }
+
+                    if(answerStatus&&content.indexOf("单项选择题")>0){
+                        nowPart = 8;
+                        qContent = "";
+                        continue;
+                    }
+                    if(answerStatus&&content.indexOf("多项选择题")>0){
+                        nowPart = 9;
+                        qContent = "";
+                        continue;
+                    }
+                    if(answerStatus&&content.indexOf("案例分析题")>0){
+                        nowPart = 10;
+                        qContent = "";
+                        continue;
+                    }
+
+                    if (isXueJianQuestionStart(content,type,alKeyList)||(nowPart==0&&!isXueJianLineStart(content,type,alKeyList))) {
+                        hasQuestion = true;
+                        if(nowPart!=0){
+                            qContent = "";
+                        }
+                        nowPart = 0;
+                        //新题开头
+                        if(!alKeyList.contains(content)){
+                            qContent = qContent +   content +"<br />";
+                        }
+                        continue;
+                    }
+
+                }
+                //遍历正文
+                if(true){
+                    System.out.println(list1);
+                }
+
+
+            } else {
+                throw new CustomException("请导入word文件!");
+            }
+        } catch (IOException e) {
+            System.out.println("此文件不是word文件!" + e.getMessage() + e.toString() + e.getLocalizedMessage());
+        }
+        result.put("list",list);
+        result.put("errorLog",errorLog);
+        return result;
+    }
+
+
     @Override
     public Map<String, Object> importJJWordQuestionList(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId) {
         Map<String,Object> result = new HashMap<>();