丁云鹏 1 week ago
parent
commit
87a53188c7

+ 5 - 0
recommend-feature-produce/pom.xml

@@ -113,6 +113,11 @@
             <artifactId>snappy-java</artifactId>
             <version>1.1.8.4</version>
         </dependency>
+        <dependency>
+            <groupId>com.squareup.okhttp3</groupId>
+            <artifactId>okhttp</artifactId>
+            <version>3.14.9</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

+ 24 - 1
recommend-feature-produce/src/main/java/com/tzld/piaoquan/recommend/feature/produce/ODPSToRedis.java

@@ -1,5 +1,6 @@
 package com.tzld.piaoquan.recommend.feature.produce;
 
+import com.alibaba.fastjson.JSONObject;
 import com.tzld.piaoquan.recommend.feature.produce.model.DTSConfig;
 import com.tzld.piaoquan.recommend.feature.produce.service.CMDService;
 import com.tzld.piaoquan.recommend.feature.produce.service.DTSConfigService;
@@ -7,12 +8,14 @@ import com.tzld.piaoquan.recommend.feature.produce.service.ODPSService;
 import com.tzld.piaoquan.recommend.feature.produce.service.RedisService;
 import com.tzld.piaoquan.recommend.feature.produce.util.JSONUtils;
 import lombok.extern.slf4j.Slf4j;
+import okhttp3.*;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.apache.spark.SparkConf;
 import org.apache.spark.api.java.JavaRDD;
 import org.apache.spark.api.java.JavaSparkContext;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -66,7 +69,27 @@ public class ODPSToRedis {
             count = odpsService.count(config, argMap);
             if (count <= 0) {
                 if (retry <= 0) {
-                    // TODO 报警
+                    try {
+                        // TODO 报警
+                        String feishuWebhook = "https://open.feishu.cn/open-apis/bot/v2/hook/540d4098-367a-4068-9a44" +
+                                "-b8109652f07c";
+                        MediaType mediaType = MediaType.parse("application/json");
+                        JSONObject param = new JSONObject();
+                        param.put("msg_type", "text");
+                        Map<String, String> map = new HashMap<>();
+                        map.put("text", argMap.get("table") + " 使用兜底数据");
+                        param.put("content", map);
+                        RequestBody body = RequestBody.create(mediaType, param.toJSONString());
+                        Request request = new Request.Builder()
+                                .url(feishuWebhook)
+                                .method("POST", body)
+                                .addHeader("Content-Type", "application/json")
+                                .build();
+                        OkHttpClient client = new OkHttpClient();
+                        client.newCall(request).execute();
+                    } catch (Exception e) {
+
+                    }
                     Map<String, String> partitionMap = odpsService.getLastestPartition(config, argMap);
                     argMap.putAll(partitionMap);
                     log.info("partitionMap {} argMap {}", JSONUtils.toJson(partitionMap), JSONUtils.toJson(argMap));