Bladeren bron

fix 导入

he2802 3 jaren geleden
bovenliggende
commit
c48adb369e

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

@@ -179,7 +179,7 @@ public class QuestionController extends BaseController {
     @ApiOperation("导入题目Word模板")
     @PreAuthorize("@ss.hasPermi('system:question:import')")
     @PostMapping("/importWordData")
-    public AjaxResult importWordData(MultipartFile file, boolean updateSupport) throws Exception
+    public AjaxResult importWordData(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId) throws Exception
     {
         iQuestionService.importWordQuestion(file);
         return AjaxResult.success();

+ 20 - 6
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionServiceImpl.java

@@ -51,6 +51,7 @@ import com.github.pagehelper.Page;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
@@ -380,6 +381,9 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                     System.out.println(content);
     //                content = trimFirstAndLastChar(content, "\t");
                    if(Validator.isNotEmpty(content)){
+                       if(content.startsWith("注意事项")){
+                           break;
+                       }
                         //第一个选项
                         if(content.startsWith("A.")){
                             isOption = true;
@@ -516,7 +520,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                                     type = 5; //简答题
                                     int j = i;
                                     String q_content = ""; //简答题
-                                    QuestionChildAddBo bo1 = new QuestionChildAddBo();
+
                                     while (j<paragraphList.size())
                                     {
                                         String tempTxt = paragraphList.get(j).getText();
@@ -527,9 +531,14 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                                         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);
-                                    optionsList.add(bo1);
                                 }
                             }
                         }
@@ -596,7 +605,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                                 j++;
                             }
                             q_content = q_content.replace("【问题】", "");
-                            QuestionChildAddBo bo1 = optionsList.get(0);
+                            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;
                         }
@@ -632,7 +647,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                        answerQuestion = null;
                        analysisContent = "";
                        optionsList.clear();
-
                     }
                     i++;
                 }
@@ -642,8 +656,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
             } else {
                 throw new CustomException("请导入word文件!");
             }
-        }catch (Exception e){
-            System.out.println("此文件不是word文件!A"+e.getMessage());
+       }catch (IOException e){
+            System.out.println("此文件不是word文件!A"+e.getMessage()+e.toString()+e.getLocalizedMessage());
         }
     }