宋悦 8 лет назад
Родитель
Сommit
a23825044e

+ 25 - 13
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -101,17 +101,14 @@ public class ImportPaperService {
         String errorInfo = paperService.checkPaperName(paperName, user.getRootOrgId().toString());
         if (errorInfo == null) {
             msgMap = processImportPaper(paperName, courseNo, courseName, user, file);
-            if (StringUtils.isEmpty((String) msgMap.get("msg"))) {
-                msgMap.put("msg", "success");
-                return msgMap;
-            } else {
-                log.error("导入异常:" + (String) msgMap.get("msg"));
-                return msgMap;
+            String errorMsg = (String)msgMap.get("msg");
+            if(StringUtils.isNotEmpty(errorMsg)){
+                throw new PaperException(errorMsg);
             }
         } else {
-            msgMap.put("msg", errorInfo);
-            return msgMap;
+            throw new PaperException(errorInfo);
         }
+        return msgMap;
     }
 
     /**
@@ -283,12 +280,14 @@ public class ImportPaperService {
                 i = importPaperCheck.index - 1;
             }
             if (!StringUtils.isEmpty(importPaperCheck.errorInfo)) {
-                throw new PaperException(importPaperCheck.errorInfo);
+                msgMap.put("msg", importPaperCheck.errorInfo);
+                return msgMap;
             }
         }
         if (paperDetails.size() == 0) {
             importPaperCheck.setErrorInfo("导入文件格式有误!");
-            throw new PaperException("导入文件格式有误!");
+            msgMap.put("msg", importPaperCheck.errorInfo);
+            return msgMap;
         }
         paper.setPaperDetailCount(mainQuesNum);
         // 保存导入试卷信息
@@ -684,6 +683,8 @@ public class ImportPaperService {
 
         int beginNum = importPaperCheck.index;
 
+        int tempNum = 0;
+
         int subQuesNum = 0;
         for (int i = beginNum; i < pList.size(); i++) {
             P pSubQues = (P) pList.get(i);
@@ -696,14 +697,15 @@ public class ImportPaperService {
 
                 nestedQuesType = tmpText.replaceAll("\\[小题型\\]", "").replaceAll("[:|:]", "").trim();
                 importPaperCheck.index++;
+                tempNum = i;
 
             } else if (tmpText.matches("^\\d\\.[\\s\\S]*")) {
 
                 ++subQuesNum;
 
                 if (StringUtils.isEmpty(nestedQuesType)) {
-                    importPaperCheck
-                            .setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum) + "小题型为空或格式不正确\n");
+                    importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)
+                            + "小题型为空或格式不正确\n");
                     return;
                 }
 
@@ -740,8 +742,18 @@ public class ImportPaperService {
                 subQuesList.add(subQues);
                 i = importPaperCheck.index - 1;
                 nestedQuesType = "";
-            } else {
+            }else if(tmpText.startsWith("[")){
                 break;
+            }else{
+                if(i == tempNum + 1){
+                    importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum + 1)
+                            +"小题型后面只能为小题题干,且必须以数字开头,不能以其他格式开头\n");
+                    return;
+                }else if (StringUtils.isEmpty(nestedQuesType)) {
+                    importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum + 1)
+                            + "小题型为空或格式不正确\n");
+                    return;
+                }
             }
             if (!StringUtils.isEmpty(importPaperCheck.errorInfo)) {
                 return;

+ 3 - 11
cqb-paper/src/main/java/com/qmth/cqb/paper/web/ImportPaperController.java

@@ -6,6 +6,7 @@ import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -66,22 +67,13 @@ public class ImportPaperController {
         log.info("导入开始");
         File tempFile = null;
         Map<String, Object> msgMap = new HashMap<String, Object>();
-        Map map = new HashMap();
         try {
             tempFile = importPaperService.getUploadFile(file);
             msgMap = importPaperService.ImportPaper(paperName, courseNo, courseName, user, tempFile);
-            if (("success").equals(msgMap.get("msg"))) {
-                return new ResponseEntity(msgMap, HttpStatus.OK);
-            } else {
-                map.put("errorMsg", msgMap.get("msg"));
-                log.info("导入异常:" + msgMap.get("msg"));
-                return new ResponseEntity(map, HttpStatus.INTERNAL_SERVER_ERROR);
-            }
+            return new ResponseEntity(msgMap, HttpStatus.OK);
         } catch (Exception e) {
-            e.printStackTrace();
-            map.put("errorMsg", e.getMessage());
             log.info("导入异常:" + e.getMessage());
-            return new ResponseEntity(map, HttpStatus.INTERNAL_SERVER_ERROR);
+            return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
         } finally {
             log.info("导入结束");
         }