wangliang 4 жил өмнө
parent
commit
24c1b4949f

+ 35 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/MessageEnum.java

@@ -7,18 +7,50 @@ package com.qmth.distributed.print.business.enums;
  */
 public enum MessageEnum {
 
-    NOTICE_OF_AUDIT_PASS("审核通过通知"),
-    NOTICE_OF_AUDIT_NOT_PASS("审核不通过通知"),
+    /**
+     * 审核结果通知(考务老师审核触发,业务id为命题任务id,短信发送给命题老师 examTask.getUserId())
+     */
+    NOTICE_OF_AUDIT_PASS("审核通过通知", "${userName}您好,${courseName}课程、${paperNumber}试卷入库申请已通过,您可在卷库里进行查看已审核通过的试卷!"),
+    NOTICE_OF_AUDIT_NOT_PASS("审核不通过通知", "${userName}您好,${courseName}课程、${paperNumber}试卷入库申请未通过,您可查看审核意见后重新提交入库申请!"),
+
+    /**
+     * 命题任务待办提醒
+     */
+    NOTICE_OF_EXAM_TASK_CREATED("命题任务待办生成通知","${userName}您好,您有${count}条新命题待办生成,请您处理!"),
+    // 定时任务查询触发,业务id为命题老师id,短信发送给命题老师
+    NOTICE_OF_EXAM_TASK_WILL_EXPIRE("命题任务待办到期预警通知","${userName}您好,您还有${count}条命题待办即将逾期,请您尽快处理!"),
+    NOTICE_OF_EXAM_TASK_OVERDUE("命题任务待办逾期通知","${userName}您好,您有${count}条命题待办已逾期!"),
+
+    /**
+     * 命题分配待办提醒(定时任务查询触发,业务id为考务老师id,短信发送给考务老师)
+     */
+    NOTICE_OF_ALLOCATION_WILL_EXPIRE("命题分配待办到期预警通知","${userName}您好,您还有${count}条命题任务尚未分配命题老师,任务即将逾期,请您尽快处理!"),
+    NOTICE_OF_ALLOCATION_OVERDUE("命题分配待办逾期通知","${userName}您好,您有${count}条命题分配待办已逾期!"),
+
+    /**
+     * 审核待办提醒
+     */
+    // 命题任务被命题老师提交后触发,业务id为命题任务id,短信发送给考务老师 examTask.getCreateId()
+    NOTICE_OF_AUDIT_CREATED("审核待办生成通知","${userName}您好,${courseName}课程、${paperNumber}试卷已提交入库,请您尽快审核!"),
+    NOTICE_OF_AUDIT_REVIEW("审核待办修改申请通知","${userName}您好,${courseName}课程、${paperNumber}试卷重新提交修改申请,请您尽快审核!"),
+    // 定时任务查询触发,业务id为考务老师id,短信发送给考务老师
+    NOTICE_OF_AUDIT_WILL_EXPIRE("审核待办到期预警通知","${userName}您好,您还有${count}条审核待办即将逾期,请您尽快处理!"),
+    NOTICE_OF_AUDIT_OVERDUE("审核待办逾期通知","${userName}您好,您有${count}条审核待办已逾期!"),
     ;
 
-    MessageEnum(String name) {
+    MessageEnum(String name, String template) {
         this.name = name;
+        this.template = template;
     }
 
     private final String name;
+    private final String template;
 
     public String getName() {
         return name;
     }
 
+    public String getTemplate() {
+        return template;
+    }
 }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/OrgCenterDataDisposeService.java

@@ -11,6 +11,6 @@ import java.io.IOException;
  */
 public interface OrgCenterDataDisposeService {
 
-    @Async("arbitrateThreadPool")
+    @Async("taskThreadPool")
     void updateSchoolInfo() throws IOException;
 }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TBTaskService.java

@@ -145,7 +145,7 @@ public interface TBTaskService extends IService<TBTask> {
     /**
      * 更新任务状态
      */
-    @Async("arbitrateThreadPool")
+    @Async("taskThreadPool")
     public void updateStatus();
 
     /**

+ 2 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicMessageServiceImpl.java

@@ -5,7 +5,6 @@ import com.aliyuncs.DefaultAcsClient;
 import com.aliyuncs.IAcsClient;
 import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
 import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
-import com.aliyuncs.exceptions.ClientException;
 import com.aliyuncs.http.MethodType;
 import com.aliyuncs.profile.DefaultProfile;
 import com.aliyuncs.profile.IClientProfile;
@@ -190,13 +189,12 @@ public class BasicMessageServiceImpl extends ServiceImpl<BasicMessageMapper, Bas
         String templateCode;
         switch (messageEnum){
             case NOTICE_OF_AUDIT_PASS:
-                // ${userName}您好,${courseName}、${paperNumber}试卷入库申请已通过,您可在卷库里进行查看已审核通过的试卷!
                 templateCode = dictionaryConfig.smsDomain().getAliyunSMSAuditPassCode();
-                templateContent = "${userName}您好,${courseName}、${paperNumber}试卷入库申请已通过,您可在卷库里进行查看已审核通过的试卷!";
+                templateContent = messageEnum.getTemplate();
                 break;
             case NOTICE_OF_AUDIT_NOT_PASS:
                 templateCode = dictionaryConfig.smsDomain().getAliyunSMSAuditNotPassCode();
-                templateContent = "${userName}您好,${courseName}、${paperNumber}试卷入库申请未通过,您可查看审核意见后重新提交入库申请";
+                templateContent = messageEnum.getTemplate();
                 break;
             default:
                 throw new IllegalStateException("Unexpected value: " + messageEnum);

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/create/AsyncCreateTaskTemplete.java

@@ -30,7 +30,7 @@ public abstract class AsyncCreateTaskTemplete extends AsyncImportTaskTemplete {
      * @return
      * @throws IOException
      */
-    @Async("arbitrateThreadPool")
+    @Async("taskThreadPool")
     public Result createPdf(Map<String, Object> map, CallbackCreatePdf callbackCreatePdf) throws IOException {
         return null;
     }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/export/AsyncExportTaskTemplete.java

@@ -51,7 +51,7 @@ public abstract class AsyncExportTaskTemplete {
      * @param map
      * @return
      */
-    @Async("arbitrateThreadPool")
+    @Async("taskThreadPool")
     public abstract Result exportTask(Map<String, Object> map) throws Exception;
 
     /**

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/importData/AsyncImportTaskTemplete.java

@@ -54,7 +54,7 @@ public abstract class AsyncImportTaskTemplete {
      * @return
      * @throws IOException
      */
-    @Async("arbitrateThreadPool")
+    @Async("taskThreadPool")
     public abstract Result importTask(Map<String, Object> map) throws IOException, Exception;
 
     /**

+ 24 - 14
distributed-print-business/src/main/java/com/qmth/distributed/print/business/threadPool/MyThreadPool.java

@@ -1,6 +1,8 @@
 package com.qmth.distributed.print.business.threadPool;//package com.qmth.themis.business.threadPool;
 
 import com.qmth.distributed.print.common.contant.SystemConstant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -20,15 +22,17 @@ import java.util.concurrent.ThreadPoolExecutor;
  */
 @Configuration
 public class MyThreadPool extends ThreadPoolTaskExecutor {
+    private final static Logger log = LoggerFactory.getLogger(MyThreadPool.class);
 
-    public MyThreadPool arbitratePoolTaskExecutor = null;
+    public MyThreadPool threadPoolTaskExecutor = null;
+    static final int cpuNum = Runtime.getRuntime().availableProcessors();
 
     @Value("${sys.config.threadPoolCoreSize}")
     Integer threadPoolCoreSize;
 
     @PostConstruct
     public void init() {
-        arbitrateThreadPool();
+        taskThreadPool();
     }
 
     /**
@@ -37,20 +41,26 @@ public class MyThreadPool extends ThreadPoolTaskExecutor {
      * @return
      */
     @Bean
-    public Executor arbitrateThreadPool() {
-        if (Objects.isNull(arbitratePoolTaskExecutor)) {
-            arbitratePoolTaskExecutor = new MyThreadPool();
-            arbitratePoolTaskExecutor.setCorePoolSize(threadPoolCoreSize);//核心线程数
-            arbitratePoolTaskExecutor.setMaxPoolSize(threadPoolCoreSize);//最大线程数
-            arbitratePoolTaskExecutor.setKeepAliveSeconds(SystemConstant.THREAD_POOL_KEEP_ALIVE_SECONDS);//线程空闲时间
-            arbitratePoolTaskExecutor.setQueueCapacity(SystemConstant.THREAD_POOL_QUEUE_CAPACITY);//队列容量
-            arbitratePoolTaskExecutor.setThreadNamePrefix(SystemConstant.THREAD_POOL_NAME);
-
+    public Executor taskThreadPool() {
+        if (Objects.isNull(threadPoolTaskExecutor)) {
+            log.info("cpuNum:{}", cpuNum);
+            threadPoolTaskExecutor = new MyThreadPool();
+            if (cpuNum > 0) {
+                threadPoolTaskExecutor.setCorePoolSize(cpuNum);//核心线程数
+                threadPoolTaskExecutor.setMaxPoolSize(cpuNum * 2);//最大线程数
+            } else {
+                threadPoolTaskExecutor.setCorePoolSize(threadPoolCoreSize);//核心线程数
+                threadPoolTaskExecutor.setMaxPoolSize(threadPoolCoreSize * 2);//最大线程数
+            }
+            threadPoolTaskExecutor.setKeepAliveSeconds(SystemConstant.THREAD_POOL_KEEP_ALIVE_SECONDS);//线程空闲时间
+            threadPoolTaskExecutor.setQueueCapacity(SystemConstant.THREAD_POOL_QUEUE_CAPACITY);//队列容量
+            threadPoolTaskExecutor.setThreadNamePrefix(SystemConstant.THREAD_POOL_NAME);
+            threadPoolTaskExecutor.setAllowCoreThreadTimeOut(true);
             // rejection-policy:当pool已经达到max size的时候,如何处理新任务
             // CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行
-            arbitratePoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
-            arbitratePoolTaskExecutor.initialize();
+            threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+            threadPoolTaskExecutor.initialize();
         }
-        return arbitratePoolTaskExecutor;
+        return threadPoolTaskExecutor;
     }
 }

+ 2 - 5
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/PdfUtil.java

@@ -43,7 +43,6 @@ public class PdfUtil {
         }
         Document document = null;
         PdfCopy copy = null;
-        PdfReader reader = null;
         StringJoiner dirName = null;
         try {
             if (Objects.nonNull(files) && files.length > 0) {
@@ -62,13 +61,14 @@ public class PdfUtil {
                 copy = new PdfSmartCopy(document, new FileOutputStream(outputPath));
                 document.open();
                 for (int i = 0; i < files.length; i++) {
-                    reader = new PdfReader(files[i]);
+                    PdfReader reader = new PdfReader(files[i]);
                     int numberOfPages = reader.getNumberOfPages();
                     for (int j = 1; j <= numberOfPages; j++) {
                         document.newPage();
                         PdfImportedPage page = copy.getImportedPage(reader, j);
                         copy.addPage(page);
                     }
+                    reader.close();
                 }
             }
         } catch (Exception e) {
@@ -77,9 +77,6 @@ public class PdfUtil {
             if (Objects.nonNull(document)) {
                 document.close();
             }
-            if (Objects.nonNull(reader)) {
-                reader.close();
-            }
             if (Objects.nonNull(copy)) {
                 copy.flush();
                 copy.close();

+ 1 - 1
distributed-print-common/src/main/java/com/qmth/distributed/print/common/contant/SystemConstant.java

@@ -125,7 +125,7 @@ public class SystemConstant {
     /**
      * 线程池配置
      */
-    public static final String THREAD_POOL_NAME = "arbitrateThreadPool";
+    public static final String THREAD_POOL_NAME = "taskThreadPool";
 //    public static final int THREAD_POOL_CORE_POOL_SIZE = 5;
 //    public static final int THREAD_POOL_MAX_POOL_SIZE = 100;
     public static final int THREAD_POOL_KEEP_ALIVE_SECONDS = 10;