Просмотр исходного кода

Merge branch 'master' into dev-lqc

lqc 4 лет назад
Родитель
Сommit
3a4a10f237

+ 23 - 0
src/main/java/com/mokamrp/privates/config/ApiPanic.java

@@ -0,0 +1,23 @@
+package com.mokamrp.privates.config;
+
+import com.mokamrp.privates.utils.Cmd;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+@ControllerAdvice
+public class ApiPanic {
+    private final String feishu = "https://open.feishu.cn/open-apis/bot/v2/hook/538d8993-e23a-4836-863c-05515b41160e";
+    @Value("${spring.profiles.active}")
+    private String env;
+
+    @ExceptionHandler(value = Exception.class)
+    public String exceptionHandler(Exception e) {
+        if (env.equals("prod")) {
+            //.正式环境捕获API异常 推送到飞书
+            Cmd.sendFeishuMsg(feishu, "[moka-private]:api panic " + e.getMessage());
+        }
+        return e.getMessage();
+    }
+}

+ 19 - 0
src/main/java/com/mokamrp/privates/config/ScheduledPanic.java

@@ -0,0 +1,19 @@
+package com.mokamrp.privates.config;
+
+import com.mokamrp.privates.utils.Cmd;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ErrorHandler;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+import javax.annotation.Priority;
+import java.sql.SQLSyntaxErrorException;
+
+public class ScheduledPanic implements ErrorHandler {
+    private final String feishu = "https://open.feishu.cn/open-apis/bot/v2/hook/76b291fd-a9c1-4285-a3d8-7d7d8ed4ef73";
+
+    public void handleError(Throwable throwable) {
+        Cmd.sendFeishuMsg(feishu, "[moka-private]:cronjob panic " + throwable.getMessage());
+    }
+}
+

+ 14 - 0
src/main/java/com/mokamrp/privates/config/TaskConfig.java

@@ -1,6 +1,11 @@
 package com.mokamrp.privates.config;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.event.EventPublishingRunListener;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Conditional;
 import org.springframework.context.annotation.Configuration;
@@ -8,16 +13,23 @@ import org.springframework.scheduling.TaskScheduler;
 import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
 import org.springframework.stereotype.Component;
+import org.springframework.util.ErrorHandler;
 
 @Configuration
 @Component
 public class TaskConfig {
+    @Value("${spring.profiles.active}")
+    private String env;
 
     @Bean
     public TaskScheduler taskScheduler() {
         ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
         // 设置scheduler执行线程为10个
         scheduler.setPoolSize(10);
+        if (env.equals("prod")){
+            //.正式环境捕获定时任务异常 推送到飞书
+            scheduler.setErrorHandler(new ScheduledPanic());
+        }
         return scheduler;
     }
 
@@ -26,4 +38,6 @@ public class TaskConfig {
     public ScheduledAnnotationBeanPostProcessor processor() {
         return new ScheduledAnnotationBeanPostProcessor();
     }
+
 }
+

+ 1 - 1
src/main/java/com/mokamrp/privates/task/ContactJobTask.java

@@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
-@Component
+//@Component
 public class ContactJobTask {
 
     @Autowired

+ 1 - 1
src/main/java/com/mokamrp/privates/task/DatahubJobTask.java

@@ -22,7 +22,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
-@Component
+//@Component
 public class DatahubJobTask {
 
     @Autowired

+ 1 - 1
src/main/java/com/mokamrp/privates/task/ExportJobTask.java

@@ -18,7 +18,7 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.util.Date;
 
-@Component
+//@Component
 public class ExportJobTask {
 
     @Resource

+ 1 - 1
src/main/java/com/mokamrp/privates/task/SendFrendcircleTask.java

@@ -15,7 +15,7 @@ import org.springframework.stereotype.Component;
 import java.time.LocalDateTime;
 import java.util.List;
 
-@Component
+//@Component
 public class SendFrendcircleTask {
 
     @Autowired

+ 1 - 1
src/main/java/com/mokamrp/privates/task/SynTagTask.java

@@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.util.Date;
 
-@Component
+//@Component
 public class SynTagTask {
 
     @Autowired

+ 1 - 1
src/main/java/com/mokamrp/privates/task/WorkEmployeeForbiddenTask.java

@@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
-@Component
+//@Component
 public class WorkEmployeeForbiddenTask {
 
     @Autowired

+ 1 - 1
src/main/java/com/mokamrp/privates/task/datahub/DatahubCorpData.java

@@ -20,7 +20,7 @@ import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
-@Component
+//@Component
 public class DatahubCorpData {
 
     @Autowired

+ 1 - 1
src/main/java/com/mokamrp/privates/task/produce/ProduceDataHub.java

@@ -16,7 +16,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
-@Component
+//@Component
 public class ProduceDataHub{
 
     @Autowired