Browse Source

fix previewPDF

deason 6 years ago
parent
commit
b68f9729d3

+ 24 - 10
examcloud-core-questions-api-provider/src/main/java/cn/com/qmth/examcloud/core/questions/api/PaperController.java

@@ -592,17 +592,24 @@ public class PaperController extends ControllerSupport {
     @GetMapping(value = "/paper/pdf/{paperId}")
     public String viewPaper(Model model, @PathVariable String paperId) {
         Paper paperBase = cn.com.qmth.examcloud.core.questions.base.Model.of(paperRepo.findById(paperId));
-        ExportServiceManage esm = exportServiceManageRepo.findByOrgId(paperBase.getOrgId());
-        if (esm == null) {
-            esm = exportServiceManageRepo.findByOrgName("山东大学");
+        if (paperBase == null) {
+            throw new StatusException("500", "试卷信息不存在!");
         }
-        ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById(esm.getExportServiceName());
+
+        ExportServiceManage manager = exportServiceManageRepo.findByOrgId(paperBase.getOrgId());
+        if (manager == null) {
+            manager = exportServiceManageRepo.findByOrgName("山东大学");
+        }
+        ExportPaperAbstractService exportPaperAbstractService = SpringContextUtils.getBean(ExportPaperAbstractService.class, manager.getExportServiceName());
+
         PaperExp paper = exportPaperAbstractService.previewPDF(paperId);
         model.addAttribute("htmlList", JsonUtil.toJson(ParsePaper.convertPaperHtml(paper)));
         model.addAttribute("courseName", paper.getCourseName());
         model.addAttribute("courseNo", paper.getCourseNo());
         model.addAttribute("courseLevel", paper.getCourseLevel());
-        String html = esm.getExportServiceName() + "_paper";
+
+        //String html = esm.getExportServiceName() + "_paper";
+        String html = "sddxExportPaperService_paper";
         return html;
     }
 
@@ -611,17 +618,24 @@ public class PaperController extends ControllerSupport {
     @GetMapping(value = "/paper/answer/pdf/{paperId}")
     public String viewPaperAnswer(Model model, @PathVariable String paperId) {
         Paper paperBase = cn.com.qmth.examcloud.core.questions.base.Model.of(paperRepo.findById(paperId));
-        ExportServiceManage esm = exportServiceManageRepo.findByOrgId(paperBase.getOrgId());
-        if (esm == null) {
-            esm = exportServiceManageRepo.findByOrgName("山东大学");
+        if (paperBase == null) {
+            throw new StatusException("500", "试卷答案信息不存在!");
         }
-        ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById(esm.getExportServiceName());
+
+        ExportServiceManage manager = exportServiceManageRepo.findByOrgId(paperBase.getOrgId());
+        if (manager == null) {
+            manager = exportServiceManageRepo.findByOrgName("山东大学");
+        }
+        ExportPaperAbstractService exportPaperAbstractService = SpringContextUtils.getBean(ExportPaperAbstractService.class, manager.getExportServiceName());
+
         PaperExp paper = exportPaperAbstractService.previewPDF(paperId);
         model.addAttribute("htmlList", JsonUtil.toJson(ParsePaper.convertAnswerHtml(paper)));
         model.addAttribute("courseNo", paper.getCourseNo());
         model.addAttribute("courseName", paper.getCourseName());
         model.addAttribute("courseLevel", paper.getCourseLevel());
-        String html = esm.getExportServiceName() + "_answer";
+
+        //String html = esm.getExportServiceName() + "_answer";
+        String html = "sddxExportPaperService_answer";
         return html;
     }
 

+ 12 - 17
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/SpringContextUtils.java

@@ -1,12 +1,12 @@
 package cn.com.qmth.examcloud.core.questions.base;
 
-import java.util.Map;
-
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 import org.springframework.stereotype.Component;
 
+import java.util.Map;
+
 /**
  * 获取ApplicationContext和Object的工具类
  */
@@ -14,35 +14,33 @@ import org.springframework.stereotype.Component;
 public class SpringContextUtils implements ApplicationContextAware {
     private static ApplicationContext applicationContext;
 
-    public void setApplicationContext(ApplicationContext arg0)
-            throws BeansException {
+    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
         applicationContext = arg0;
     }
 
     /**
      * 获取applicationContext对象
-     *
-     * @return
      */
     public static ApplicationContext getApplicationContext() {
         return applicationContext;
     }
 
     /**
-     * 根据bean的id来查找对象
-     *
-     * @param id
-     * @return
+     * 获取Bean
      */
     public static Object getBeanById(String id) {
         return applicationContext.getBean(id);
     }
 
+    /**
+     * 获取Bean
+     */
+    public static <T> T getBean(Class<T> clazz, String beanName) {
+        return (T) applicationContext.getBean(beanName);
+    }
+
     /**
      * 根据bean的class来查找对象
-     *
-     * @param c
-     * @return
      */
     @SuppressWarnings({"unchecked", "rawtypes"})
     public static Object getBeanByClass(Class c) {
@@ -51,13 +49,10 @@ public class SpringContextUtils implements ApplicationContextAware {
 
     /**
      * 根据bean的class来查找所有的对象(包括子类)
-     *
-     * @param c
-     * @return
      */
     @SuppressWarnings({"unchecked", "rawtypes"})
     public static Map getBeansByClass(Class c) {
         return applicationContext.getBeansOfType(c);
     }
-}
 
+}