Bladeren bron

导入试卷增加日志

宋悦 8 jaren geleden
bovenliggende
commit
2e8a8f591f

+ 6 - 0
cqb-comm-utils/pom.xml

@@ -22,6 +22,12 @@
             <artifactId>common-dto</artifactId>
             <version>${project.version}</version>
         </dependency>
+
+        <dependency>
+            <groupId>cn.com.qmth.examcloud.common</groupId>
+            <artifactId>common-uac</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         
         <dependency>
             <groupId>com.google.code.gson</groupId>

+ 9 - 2
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -24,6 +24,8 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
 import org.docx4j.wml.P;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.commons.CommonsMultipartFile;
@@ -38,6 +40,8 @@ import java.util.UUID;
 @Service
 public class ImportPaperService {
 
+    protected static final Logger log = LoggerFactory.getLogger(ImportPaperService.class);
+
     @Autowired
     PaperRepo paperRepo;
 
@@ -77,6 +81,7 @@ public class ImportPaperService {
             IOUtils.copyLarge(file.getInputStream(), os);
         } catch (Exception e) {
             e.printStackTrace();
+            log.error("上传文件异常:"+e.getMessage());
         } finally {
             IOUtils.closeQuietly(os);
         }
@@ -91,7 +96,8 @@ public class ImportPaperService {
      * @param file
      * @return
      */
-    public String ImportPaper(String paperName, String courseNo, File file) {
+    public String importPaper(String paperName, String courseNo, File file) {
+
         String errorInfo = paperService.checkPaperName(paperName);
         if (errorInfo == null) {
             errorInfo = "";
@@ -99,12 +105,12 @@ public class ImportPaperService {
             if (StringUtils.isEmpty(errorInfo)) {
                 return "success";
             } else {
+                log.error("导入异常:"+errorInfo);
                 return errorInfo;
             }
         } else {
             return errorInfo;
         }
-
     }
 
     /**
@@ -273,6 +279,7 @@ public class ImportPaperService {
         } catch (Exception e) {
             e.printStackTrace();
             importPaperCheck.setErrorInfo(e.getMessage());
+            log.error("导入处理异常:"+e.getMessage());
         } finally {
             wordMLPackage = null;
             tmpWordMlPackage = null;

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

@@ -135,7 +135,7 @@ public class PaperService {
         Example<ExamPaper> example = Example.of(examPaper);
         List<ExamPaper> examPapers = examPaperRepo.findAll(example);
         for (ExamPaper ePaper : examPapers) {
-            Paper paper = paperRepo.findOne(ePaper.getPaperId());
+            Paper paper = paperRepo.findOne(ePaper.getPaper().getId());
             papers.add(paper);
         }
         return papers;
@@ -155,7 +155,7 @@ public class PaperService {
         examPaper.setExamId(examId);
         examPaper.setGroupCode(groupCode);
         examPaper.setCourseCode(courseCode);
-        examPaper.setPaperId(paperId);
+//        examPaper.setPaperId(paperId);
         examPaperRepo.save(examPaper);
     }
 
@@ -164,7 +164,7 @@ public class PaperService {
         examPaper.setExamId(examId);
         examPaper.setGroupCode(groupCode);
         examPaper.setCourseCode(courseCode);
-        examPaper.setPaperId(paperId);
+//        examPaper.setPaperId(paperId);
         examPaperRepo.delete(examPaper);
     }
 

+ 10 - 6
cqb-paper/src/main/java/com/qmth/cqb/paper/web/ImportPaperController.java

@@ -4,6 +4,8 @@ import java.io.File;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -27,6 +29,8 @@ import io.swagger.annotations.ApiOperation;
 @RequestMapping("${api_cqb}/")
 public class ImportPaperController {
 
+    protected static final Logger log = LoggerFactory.getLogger(ImportPaperController.class);
+
     @Autowired
     ImportPaperService importPaperService;
 
@@ -38,7 +42,6 @@ public class ImportPaperController {
 
     /**
      * 导入试卷
-     * 
      * @param paperName
      * @param file
      * @return
@@ -47,8 +50,10 @@ public class ImportPaperController {
     @PostMapping(value = "/importPaper")
     public ResponseEntity importPaper(@RequestParam String paperName, @RequestParam String courseNo,
             @RequestParam("file") CommonsMultipartFile file) {
+        log.info("导入开始");
         File tempFile = importPaperService.getUploadFile(file);
-        String returnStr = importPaperService.ImportPaper(paperName, courseNo, tempFile);
+        String returnStr = importPaperService.importPaper(paperName, courseNo, tempFile);
+        log.info("导入结束");
         if (returnStr.equals("success")) {
             return new ResponseEntity(returnStr, HttpStatus.OK);
         } else {
@@ -56,13 +61,12 @@ public class ImportPaperController {
             map.put("errorMsg", returnStr);
             return new ResponseEntity(map, HttpStatus.INTERNAL_SERVER_ERROR);
         }
-        // return returnStr;
     }
 
     /**
-     * 新增一张空白试卷
-     * 
-     * @param paper
+     * 新增试卷
+     * @param courseNo
+     * @param paperName
      * @return
      */
     @ApiOperation(value = "保存导入类型空白试卷", notes = "保存导入类型空白试卷")