deason 6 年之前
父節點
當前提交
83975f219c

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

@@ -145,9 +145,14 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         //获取尚未转换过PDF的所有试卷
         Specification<CoursePaper> spec = SearchBuilder.EQ("converted", false);
         List<CoursePaper> coursePapers = coursePaperRepository.findAll(spec);
-        log.debug("待转换PDF的试卷数:" + coursePapers.size());
+        if (coursePapers == null || coursePapers.size() == 0) {
+            return;
+        }
 
+        log.debug("待转换PDF的试卷数:" + coursePapers.size());
         for (CoursePaper coursePaper : coursePapers) {
+            Date start = new Date();
+
             //将试卷和答案页面转换为PDF文件
             //final String rootDir = Constants.rootFileDir();
             final String rootDir = systemProperty.getTempDir();
@@ -195,6 +200,8 @@ public class CoursePaperServiceImpl implements CoursePaperService {
 
             //转换成功后,依据特定情况分配默认试卷
             this.allotDefaultCoursePaper(coursePaper);
+
+            log.debug(String.format("转换PDF耗时:%s!paperId = %s", DateUtils.diff(start, new Date()), coursePaper.getPaperId()));
         }
     }
 

+ 13 - 1
examcloud-core-print-starter/src/main/java/cn/com/qmth/examcloud/core/print/config/StatisticScheduler.java

@@ -8,12 +8,14 @@
 package cn.com.qmth.examcloud.core.print.config;
 
 import cn.com.qmth.examcloud.core.print.common.utils.DateUtils;
+import cn.com.qmth.examcloud.core.print.service.CoursePaperService;
 import cn.com.qmth.examcloud.core.print.service.CourseStatisticService;
 import cn.com.qmth.examcloud.core.print.service.PrintingProjectService;
 import cn.com.qmth.examcloud.core.print.service.PrintingProjectStatisticService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import java.io.Serializable;
@@ -29,12 +31,14 @@ public class StatisticScheduler implements Serializable {
     private PrintingProjectService printingProjectService;
     @Autowired
     private PrintingProjectStatisticService printingProjectStatisticService;
+    @Autowired
+    private CoursePaperService coursePaperService;
 
     /**
      * 定时统计数据(每N分钟执行)
      */
     //@Scheduled(cron = "0 1/1 * * * ?")
-    public void execute() throws Exception {
+    public void statistic() throws Exception {
         Date start = new Date();
 
         //初始所有印刷项目的基本信息
@@ -49,4 +53,12 @@ public class StatisticScheduler implements Serializable {
         log.info("统计耗时:" + DateUtils.diff(start, new Date()));
     }
 
+    /**
+     * 定时执行转换PDF(每N分钟执行)
+     */
+    @Scheduled(cron = "0 3/3 * * * ?")
+    public void convert() throws Exception {
+        coursePaperService.convertCoursePapers();
+    }
+
 }

+ 1 - 1
examcloud-core-print-starter/src/main/resources/logback-spring.xml

@@ -54,7 +54,7 @@
     <logger name="cn.afterturn.easypoi" level="WARN"/>
     <logger name="com.netflix" level="WARN"/>
     <logger name="cn.com.qmth.examcloud.commons" level="WARN"/>
-    <logger name="cn.com.qmth.examcloud.core.print.service.impl" level="DEBUG"/>
+    <logger name="cn.com.qmth.examcloud.core.print" level="DEBUG"/>
 
     <root level="WARN">
         <appender-ref ref="DEBUG_APPENDER"/>