Переглянути джерело

Merge branch 'master' of http://139.224.213.4:3000/bigdata/DataWorks-flow-touch

晏永年 4 роки тому
батько
коміт
ed5247efb7

+ 4 - 3
src/main/java/com/winhc/dataworks/flow/touch/Main.java

@@ -10,6 +10,7 @@ import com.helospark.lightdi.annotation.Service;
 import com.winhc.dataworks.flow.touch.bean.*;
 import com.winhc.dataworks.flow.touch.configuration.SchemaInit;
 import com.winhc.dataworks.flow.touch.service.TouchService;
+import com.winhc.dataworks.flow.touch.utils.DateUtils;
 import com.winhc.dataworks.flow.touch.utils.DingUtils;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
@@ -39,7 +40,7 @@ public class Main {
 
     static {
         options.addOption("s", "singleJob", false, "选填,是否单独触发一个业务流程");
-        options.addOption("b", "bizDate", true, "必填,业务时间");
+        options.addOption("b", "bizDate", true, "选填,业务时间[2020-07-07],默认为昨天");
         options.addOption("f", "fileName", true, "必填,yaml文件");
 
         options.addOption("flow", "flow", true, "单任务必填,业务流程名");
@@ -48,7 +49,7 @@ public class Main {
 
     private static void verify(CommandLine commandLine) {
         try {
-            if (!commandLine.hasOption("b") || !commandLine.hasOption("f")) {
+            if (!commandLine.hasOption("f")) {
                 throw new RuntimeException();
             }
             if (commandLine.hasOption("s")) {
@@ -71,7 +72,7 @@ public class Main {
         try {
             CommandLine commandLine = parser.parse(options, args);
             verify(commandLine);
-            String bizDate = commandLine.getOptionValue("b");
+            String bizDate = commandLine.getOptionValue("b", DateUtils.getYesterday());
             String fileName = commandLine.getOptionValue("f");
             List<DataWorksFlowJob> jobs = SchemaInit.getJobs(fileName);
 

+ 6 - 0
src/main/java/com/winhc/dataworks/flow/touch/bean/DingMsg.java

@@ -22,6 +22,12 @@ import java.time.format.DateTimeFormatter;
 public class DingMsg {
     private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
+    public static String msg2Md(String msg) {
+        return "#### " + msg +
+                "\n\n" + "> 时间:" + LocalDateTime.now().format(dtf) +
+                "\n\n" + "> 系统信息:" + os();
+    }
+
     public DingMsg(String msgLevel, String project, String flow, String nodeName, String status) {
         this.msgLevel = msgLevel;
         this.project = project;

+ 19 - 0
src/main/java/com/winhc/dataworks/flow/touch/utils/DateUtils.java

@@ -0,0 +1,19 @@
+package com.winhc.dataworks.flow.touch.utils;
+
+import java.time.Instant;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+
+/**
+ * @Author: XuJiakai
+ * @Date: 2020/7/20 13:48
+ * @Description:
+ */
+public class DateUtils {
+    private static final DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
+    public static String getYesterday() {
+        Instant instant = Instant.now().minus(1, ChronoUnit.DAYS);
+        return df.format(instant);
+    }
+}

+ 5 - 1
src/main/java/com/winhc/dataworks/flow/touch/utils/DingUtils.java

@@ -36,7 +36,7 @@ public class DingUtils {
     }
 
     public boolean send(String msg) {
-        return sendByBody(getMsgBody(msg));
+        return sendByBody(getMdBody(msg));
     }
 
     private boolean sendByBody(String body) {
@@ -73,6 +73,10 @@ public class DingUtils {
         return response == null ? "" : response.isSuccessful() ? Objects.requireNonNull(response.body()).string() : "";
     }
 
+    private static String getMdBody(String msg) {
+        return String.format("{\"msgtype\":\"markdown\",\"markdown\":{\"title\":\"%s\",\"text\":\"%s\"}}", "任务通知", DingMsg.msg2Md(msg));
+    }
+
     private static String getMdBody(DingMsg msg) {
         return String.format("{\"msgtype\":\"markdown\",\"markdown\":{\"title\":\"%s\",\"text\":\"%s\"}}", msg.getMsgLevel(), msg.toMd());
     }