瀏覽代碼

BUG修改

gaoxing 8 年之前
父節點
當前提交
094ddc14a3

+ 24 - 21
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -11,7 +11,6 @@ import java.util.UUID;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import com.qmth.cqb.utils.exception.PaperException;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.ArrayUtils;
@@ -40,6 +39,7 @@ import com.qmth.cqb.utils.CommonUtils;
 import com.qmth.cqb.utils.enums.PaperStatus;
 import com.qmth.cqb.utils.enums.PaperType;
 import com.qmth.cqb.utils.enums.QuesUnit;
+import com.qmth.cqb.utils.exception.PaperException;
 import com.qmth.cqb.utils.word.DocxProcessUtil;
 
 import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
@@ -77,7 +77,7 @@ public class ImportPaperService {
      * @param file
      * @return
      */
-    public File getUploadFile(CommonsMultipartFile file) throws Exception{
+    public File getUploadFile(CommonsMultipartFile file) throws Exception {
         String fileName = file.getOriginalFilename();
         File tempFile = new File(DocxProcessUtil.TEMP_FILE_IMP + fileName);
         OutputStream os = null;
@@ -95,23 +95,22 @@ public class ImportPaperService {
      * @param file
      * @return
      */
-    public String ImportPaper(String paperName,
-                              String courseNo,
-                              String courseName,
-                              AccessUser user,
-                              File file) throws Exception{
+    public Map<String, Object> ImportPaper(String paperName, String courseNo, String courseName, AccessUser user,
+            File file) throws Exception {
+        Map<String, Object> msgMap = new HashMap<String, Object>();
         String errorInfo = paperService.checkPaperName(paperName, user.getOrgId().toString());
         if (errorInfo == null) {
-            errorInfo = "";
-            errorInfo += processImportPaper(paperName, courseNo, courseName, user, file);
-            if (StringUtils.isEmpty(errorInfo)) {
-                return "success";
+            msgMap = processImportPaper(paperName, courseNo, courseName, user, file);
+            if (StringUtils.isEmpty((String) msgMap.get("msg"))) {
+                msgMap.put("msg", "success");
+                return msgMap;
             } else {
-                log.error("导入异常:" + errorInfo);
-                return errorInfo;
+                log.error("导入异常:" + (String) msgMap.get("msg"));
+                return msgMap;
             }
         } else {
-            return errorInfo;
+            msgMap.put("msg", errorInfo);
+            return msgMap;
         }
     }
 
@@ -123,13 +122,13 @@ public class ImportPaperService {
      * @param paperDetailUnits
      * @param importPaperCheck
      */
-    public void savePaper(Paper paper, List paperDetails, List paperDetailUnits, List questions,
+    public Paper savePaper(Paper paper, List paperDetails, List paperDetailUnits, List questions,
             ImportPaperCheck importPaperCheck) {
 
         Paper tempPaper = null;
 
         if (!StringUtils.isEmpty(importPaperCheck.errorInfo))
-            return;
+            return null;
 
         if (paper != null) {
             tempPaper = paperRepo.save(paper);
@@ -148,6 +147,8 @@ public class ImportPaperService {
         }
 
         paperService.formatPaper(tempPaper, null);
+
+        return tempPaper;
     }
 
     /**
@@ -160,8 +161,9 @@ public class ImportPaperService {
      * @param file
      * @return
      */
-    public String processImportPaper(String paperName, String courseNo, String courseName, AccessUser user, File file) throws Exception {
-
+    public Map<String, Object> processImportPaper(String paperName, String courseNo, String courseName, AccessUser user,
+            File file) throws Exception {
+        Map<String, Object> msgMap = new HashMap<String, Object>();
         WordprocessingMLPackage wordMLPackage;
         WordprocessingMLPackage tmpWordMlPackage;
         WordprocessingMLPackage writePkg;
@@ -213,7 +215,6 @@ public class ImportPaperService {
             P p = (P) pList.get(i);
             String pText = DocxProcessUtil.getPText(p);
 
-
             if (StringUtils.isEmpty(pText)) {
                 // 跳过空白段落
                 continue;
@@ -289,12 +290,14 @@ public class ImportPaperService {
         }
         paper.setPaperDetailCount(mainQuesNum);
         // 保存导入试卷信息
-        savePaper(paper, paperDetails, paperDetailUnits, questions, importPaperCheck);
+        paper = savePaper(paper, paperDetails, paperDetailUnits, questions, importPaperCheck);
         wordMLPackage = null;
         tmpWordMlPackage = null;
         writePkg = null;
         FileUtils.deleteQuietly(file);
-        return importPaperCheck.errorInfo;
+        msgMap.put("msg", importPaperCheck.errorInfo);
+        msgMap.put("paper", paper);
+        return msgMap;
     }
 
     /**

+ 1 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperService.java

@@ -416,8 +416,8 @@ public class PaperService {
         List<PaperDetailExp> paperDetailExpList = paperExp.getPaperDetails();
         for (PaperDetailExp paperDetail : paperDetailExpList) {
             // 大题序号
-            paperDetail.setCnNum(CommonUtils.toCHNum(paperDetail.getNumber()));
             paperDetail.setNumber(++mainNum);
+            paperDetail.setCnNum(CommonUtils.toCHNum(paperDetail.getNumber()));
             // 小题序号
             if (paperDetail != null && paperDetail.getPaperDetailUnits() != null
                     && paperDetail.getPaperDetailUnits().size() > 0) {

+ 20 - 17
cqb-paper/src/main/java/com/qmth/cqb/paper/web/ImportPaperController.java

@@ -18,8 +18,6 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
-import com.qmth.cqb.flow.model.DataMapModel;
-import com.qmth.cqb.flow.model.WorkFlowModel;
 import com.qmth.cqb.flow.service.ComProcessService;
 import com.qmth.cqb.flow.service.DataMapModelService;
 import com.qmth.cqb.paper.dao.PaperRepo;
@@ -46,12 +44,13 @@ public class ImportPaperController {
 
     @Autowired
     PaperService paperService;
-    
+
     @Autowired
     ComProcessService comProcessService;
-    
+
     @Autowired
     DataMapModelService dataMapModelService;
+
     /**
      * 导入试卷
      * 
@@ -61,30 +60,32 @@ public class ImportPaperController {
      */
     @ApiOperation(value = "导入试卷", notes = "导入试卷")
     @PostMapping(value = "/importPaper")
-    public ResponseEntity importPaper(HttpServletRequest request, @RequestParam String paperName,
-            @RequestParam String courseNo, @RequestParam String courseName,
-            @RequestParam("file") CommonsMultipartFile file) {
+    public ResponseEntity importPaper(HttpServletRequest request, 
+                                        @RequestParam String paperName,
+                                        @RequestParam String courseNo, 
+                                        @RequestParam String courseName,
+                                        @RequestParam("file") CommonsMultipartFile file) {
         AccessUser user = (AccessUser) request.getAttribute("accessUser");
         log.info("导入开始");
         File tempFile = null;
-        String returnStr = "";
+        Map<String, Object> msgMap = new HashMap<String, Object>();
         Map map = new HashMap();
         try {
             tempFile = importPaperService.getUploadFile(file);
-            returnStr  = importPaperService.ImportPaper(paperName, courseNo, courseName, user, tempFile);
-            if (returnStr.equals("success")) {
-                return new ResponseEntity(returnStr, HttpStatus.OK);
+            msgMap = importPaperService.ImportPaper(paperName, courseNo, courseName, user, tempFile);
+            if (("success").equals(msgMap.get("msg"))) {
+                return new ResponseEntity(msgMap, HttpStatus.OK);
             } else {
-                map.put("errorMsg", returnStr);
-                log.info("导入异常:"+returnStr);
+                map.put("errorMsg", msgMap.get("msg"));
+                log.info("导入异常:" + msgMap.get("msg"));
                 return new ResponseEntity(map, HttpStatus.INTERNAL_SERVER_ERROR);
             }
         } catch (Exception e) {
             e.printStackTrace();
             map.put("errorMsg", e.getMessage());
-            log.info("导入异常:"+e.getMessage());
+            log.info("导入异常:" + e.getMessage());
             return new ResponseEntity(map, HttpStatus.INTERNAL_SERVER_ERROR);
-        }finally {
+        } finally {
             log.info("导入结束");
         }
     }
@@ -98,8 +99,10 @@ public class ImportPaperController {
      */
     @ApiOperation(value = "保存导入类型空白试卷", notes = "保存导入类型空白试卷")
     @PostMapping(value = "/importPaper/saveBlankPaper/{courseNo}/{courseName}/{paperName}")
-    public ResponseEntity saveBlankPaper(HttpServletRequest request, @PathVariable String courseNo,
-            @PathVariable String courseName, @PathVariable String paperName) {
+    public ResponseEntity saveBlankPaper(HttpServletRequest request, 
+                                        @PathVariable String courseNo,
+                                        @PathVariable String courseName, 
+                                        @PathVariable String paperName) {
         AccessUser user = (AccessUser) request.getAttribute("accessUser");
         Map<String, Object> returnMap = importPaperService.saveBlankPaper(courseNo, courseName, paperName, user);
         if (returnMap.get("msg").equals("success")) {