deason 6 anos atrás
pai
commit
af78fadc8e

+ 3 - 2
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/upyun/UpYunClient.java

@@ -20,6 +20,7 @@ import org.springframework.stereotype.Component;
 import java.io.File;
 
 import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_400;
+import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
 
 /**
  * @author: fengdesheng
@@ -48,7 +49,7 @@ public class UpYunClient {
             return upYunProperty.getFileUrl() + newFilePath;
         } catch (Exception e) {
             log.error(e.getMessage(), e);
-            return null;
+            throw new StatusException(PRT_CODE_500, "上传文件异常!");
         }
     }
 
@@ -65,7 +66,7 @@ public class UpYunClient {
             return upYunProperty.getFileUrl() + newFilePath;
         } catch (Exception e) {
             log.error(e.getMessage(), e);
-            return null;
+            throw new StatusException(PRT_CODE_500, "上传文件异常!");
         }
     }
 

+ 5 - 1
examcloud-core-print-provider/src/main/java/cn/com/qmth/examcloud/core/print/api/controller/CommonController.java

@@ -7,6 +7,7 @@
 
 package cn.com.qmth.examcloud.core.print.api.controller;
 
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.print.common.Result;
 import cn.com.qmth.examcloud.core.print.common.upyun.UpYunClient;
@@ -25,6 +26,8 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 
+import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
+
 /**
  * 常用相关接口
  *
@@ -57,7 +60,8 @@ public class CommonController extends ControllerSupport {
         if (StringUtils.isNotEmpty(fileUrl)) {
             return Result.success(fileUrl);
         }
-        return Result.error();
+
+        throw new StatusException(PRT_CODE_500, "上传失败!");
     }
 
     @GetMapping("/download")

+ 6 - 3
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/CoursePaperServiceImpl.java

@@ -108,8 +108,11 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         final String paperPdfPath = rootDir + "/" + FileUtils.randomUUID() + SUFFIX_PDF;
         final String answerPdfPath = rootDir + "/" + FileUtils.randomUUID() + SUFFIX_PDF;
         FileUtils.makeDirs(rootDir);
-        ElectronUtils.toPdf(systemProperty.getDir(), paperHtmlUrl, paperPdfPath);
-        ElectronUtils.toPdf(systemProperty.getDir(), answerHtmlUrl, answerPdfPath);
+        boolean paperResult = ElectronUtils.toPdf(systemProperty.getDir(), paperHtmlUrl, paperPdfPath);
+        boolean answerResult = ElectronUtils.toPdf(systemProperty.getDir(), answerHtmlUrl, answerPdfPath);
+        if (!paperResult || !answerResult) {
+            throw new StatusException(PRT_CODE_500, "转换PDF文件失败!");
+        }
 
         //上传PDF至又拍云
         String paperPdfUrl = upYunClient.upload(new File(paperPdfPath));
@@ -124,7 +127,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
             log.error(e.getMessage());
         }
         if (paperP == 0) {
-            throw new StatusException(PRT_CODE_400, "试卷页数不能为空!");
+            throw new StatusException(PRT_CODE_500, "试卷页数不能为0!");
         }
 
         CoursePaper oldCoursePaper = coursePaperRepository.findByExamIdAndPaperId(coursePaper.getExamId(), coursePaper.getPaperId());