Browse Source

邮件模板

zhangheng 3 years ago
parent
commit
655aecfccf

+ 5 - 1
server/src/main/java/edp/davinci/core/common/ResultMap.java

@@ -71,7 +71,11 @@ public class ResultMap extends HashMap<String, Object> {
         this.code = HttpCodeEnum.OK.getCode();
         this.header.put("code", this.code);
         this.header.put("msg", "Success");
-        this.header.put("token", this.tokenUtils.refreshToken(token));
+
+        if (!StringUtils.isEmpty(token)) {
+            this.header.put("token", this.tokenUtils.refreshToken(token));
+        }
+
         this.put("header", header);
         this.put("payload", EMPTY);
         return this;

+ 2 - 0
server/src/main/java/edp/davinci/schedule/SystemSchedule.java

@@ -77,6 +77,7 @@ public class SystemSchedule {
 
     @Scheduled(cron = "0 0/2 * * * *")
     public void stopCronJob() {
+        log.info("start每两分钟执行一次....");
         List<CronJob> jobs = cronJobMapper.getStoppedJob();
         if (!CollectionUtils.isEmpty(jobs)) {
             for (CronJob job : jobs) {
@@ -87,6 +88,7 @@ public class SystemSchedule {
                 }
             }
         }
+        log.info("end每两分钟执行一次....");
     }
 
     @Scheduled(cron = "0 0 1 * * *")

+ 4 - 1
server/src/main/java/edp/davinci/service/impl/CronJobMessageHandler.java

@@ -32,14 +32,17 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.io.Serializable;
 import java.util.Date;
 
 @Slf4j
 @Component
-public class CronJobMessageHandler implements RedisMessageHandler {
+public class CronJobMessageHandler implements Serializable,RedisMessageHandler {
 
 	private static final Logger scheduleLogger = LoggerFactory.getLogger(LogNameEnum.BUSINESS_SCHEDULE.getName());
 
+	private static final long serialVersionUID = -6164416250269765727L;
+
 	@Autowired
 	private CronJobMapper cronJobMapper;
 

+ 4 - 6
server/src/main/java/edp/davinci/service/impl/CronJobServiceImpl.java

@@ -261,10 +261,8 @@ public class CronJobServiceImpl extends BaseEntityService implements CronJobServ
 	@Override
 	@Transactional
 	public CronJob startCronJob(Long id, User user) throws NotFoundException, UnAuthorizedException, ServerException {
-
 		CronJob cronJob = getCronJob(id);
-
-		checkWritePermission(entity, cronJob.getProjectId(), user, "start");
+//		checkWritePermission(entity, cronJob.getProjectId(), user, "start");
 
 		try {
 			quartzHandler.addJob(cronJob);
@@ -340,9 +338,9 @@ public class CronJobServiceImpl extends BaseEntityService implements CronJobServ
 	public boolean executeCronJob(Long id, User user) throws NotFoundException, UnAuthorizedException, ServerException {
 
 		CronJob cronJob = getCronJob(id);
-
-		checkWritePermission(entity, cronJob.getProjectId(), user, "execute");
-
+		System.out.println("执行任务....."+ cronJob.getName());
+//		checkWritePermission(entity, cronJob.getProjectId(), user, "execute");
+		System.out.println("执行任务.....正在执行!"+ cronJob.getName());
 		ExecutorService executorService = ExecutorUtils.getJobWorkers();
 		ExecutorUtils.printThreadPoolStatus(executorService, "JOB_WORKERS", scheduleLogger);
 		executorService.submit(() -> {

+ 0 - 1
server/src/main/java/edp/davinci/service/impl/EmailScheduleServiceImpl.java

@@ -160,7 +160,6 @@ public class EmailScheduleServiceImpl extends BaseScheduleService implements Sch
         }
 
         scheduleLogger.info("CronJob({}) is ready to send email", cronJob.getId());
-
         MailContent mailContent = null;
         try {
             mailContent = MailContent.MailContentBuilder.builder()

+ 26 - 9
server/src/main/java/edp/davinci/service/screenshot/ScreenshotUtil.java

@@ -87,20 +87,16 @@ public class ScreenshotUtil {
     private FileUtils fileUtils;
 
     public void screenshot(long jobId, List<ImageContent> imageContents, Integer imageWidth) {
-        System.out.println(">>>>>>>>>>>>>>imageContents>>>>>>>>>>>>>>>>"+imageContents.size());
     	scheduleLogger.info("Start screenshot for job({})", jobId);
         try {
         	int contentsSize = imageContents.size();
             List<Future> futures = new ArrayList<>(contentsSize);
             final AtomicInteger index = new AtomicInteger(1);
             imageContents.forEach(content -> futures.add(executorService.submit(() -> {
-                System.out.println(">>>>>>>>>>>>>>content>>>>>>>>>>>>>>>>"+content.getUrl());
             	scheduleLogger.info("Cronjob({}) thread({}) for screenshot start, type:{}, id:{}, total:{}", jobId, index.get(), content.getDesc(), content.getCId(), contentsSize);
                 try {
-                    System.out.println(">>>>>>>>>>>>>>生成图片>>>>>>>>>>>>>>>>");
                     File image = doScreenshot(jobId, content.getUrl(), imageWidth);
                     content.setContent(image);
-                    System.out.println(">>>>>>>>>>>>>>设置文件>>>>>>>>>>>>>>>>");
                 } catch (Exception e) {
                 	scheduleLogger.error("Cronjob({}) thread( {}) screenshot error", jobId, index.get());
                 	scheduleLogger.error(e.getMessage(), e);
@@ -128,9 +124,7 @@ public class ScreenshotUtil {
     }
 
     private File doScreenshot(long jobId, String url, Integer imageWidth) throws Exception {
-        System.out.println(">>>>>>>jobId>>>>>>>>"+ jobId);
         WebDriver driver = generateWebDriver(jobId, imageWidth);
-        System.out.println(">>>>>>>url>>>>>>>>"+ url);
         driver.get(url);
         scheduleLogger.info("Cronjob({}) do screenshot url={}, timeout={} start", jobId, url, timeOutSecond);
         try {
@@ -225,14 +219,15 @@ public class ScreenshotUtil {
         }
 
         if(isLinux()){
-            CHROME_DRIVER_PATH += "/linux";
+            CHROME_DRIVER_PATH += "/linux/chromedriver";
         }
         if(isWindows()){
             CHROME_DRIVER_PATH += "/window";
         }
-        System.out.println("CHROME_DRIVER_PATH >>>> " + CHROME_DRIVER_PATH);
+
 
         File file = new File(CHROME_DRIVER_PATH);
+
         if (!file.canExecute()) {
             if (!file.setExecutable(true)) {
                 throw new ExecutionException(new Exception(CHROME_DRIVER_PATH + " is not executable!"));
@@ -256,10 +251,32 @@ public class ScreenshotUtil {
         return new ChromeDriver(options);
     }
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws ExecutionException {
 
         String OS = System.getProperty("os.name").toLowerCase();
+        File file = new File("D:\\work\\data-analysis\\server\\src\\main\\resources\\chrome-driver\\linux\\chromedriver");
+
+        if (!file.canExecute()) {
+            if (!file.setExecutable(true)) {
+                throw new ExecutionException(new Exception("D:\\work\\data-analysis\\server\\src\\main\\resources\\chrome-driver\\linux\\chromedriver" + " is not executable!"));
+            }
+        }
 
+        System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "D:\\work\\data-analysis\\server\\src\\main\\resources\\chrome-driver\\linux\\chromedriver");
+        ChromeOptions options = new ChromeOptions();
+
+        options.addArguments("headless");
+        options.addArguments("no-sandbox");
+        options.addArguments("disable-gpu");
+        options.addArguments("disable-features=NetworkService");
+        options.addArguments("ignore-certificate-errors");
+        options.addArguments("silent-launch");
+        options.addArguments("disable-application-cache");
+        options.addArguments("disable-web-security");
+        options.addArguments("no-proxy-server");
+        options.addArguments("disable-dev-shm-usage");
+        WebDriver driver = new ChromeDriver(options);
+        System.out.println(driver.getTitle());
         System.out.println(OS);
 
     }

+ 3 - 3
server/src/main/resources/application.yml

@@ -70,8 +70,8 @@ spring:
     isEnable: true
 
       ## standalone config
-    host: ${REDIS_HOST:61.132.52.38}
-    port: ${REDIS_PORT:20003}
+    host: ${REDIS_HOST:127.0.0.1}
+    port: ${REDIS_PORT:6379}
 
       ## cluster config
       #  cluster:
@@ -194,7 +194,7 @@ source:
 screenshot:
   default_browser: CHROME
   timeout_second: 600
-  chromedriver_path: C:/Users/Administrator/Downloads/
+  chromedriver_path: classpath:/chrome-driver/
 #  remote_webdriver_url: http://localhost:4446/wd/hub
 
 data-auth-center: