浏览代码

增加报警

xueyiming 8 月之前
父节点
当前提交
6d27c43e65

+ 8 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/XxlJobService.java

@@ -8,6 +8,7 @@ import com.tzld.longarticle.recommend.server.common.enums.AccountBusinessTypeEnu
 import com.tzld.longarticle.recommend.server.common.enums.FeishuRobotIdEnum;
 import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 import com.tzld.longarticle.recommend.server.mapper.crawler.CrawlerBaseMapper;
+import com.tzld.longarticle.recommend.server.mapper.crawler.PushMessageCallbackMapper;
 import com.tzld.longarticle.recommend.server.model.dto.AccountTypeFansDTO;
 import com.tzld.longarticle.recommend.server.model.dto.NotPublishPlan;
 import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
@@ -24,7 +25,9 @@ import com.tzld.longarticle.recommend.server.repository.crawler.LongArticlesVide
 import com.tzld.longarticle.recommend.server.repository.longArticle.GetOffVideoArticleRepository;
 import com.tzld.longarticle.recommend.server.repository.longArticle.LongArticlesMatchVideoRepository;
 import com.tzld.longarticle.recommend.server.repository.longArticle.LongArticlesReadRateRepository;
+import com.tzld.longarticle.recommend.server.repository.model.PushMessageCallback;
 import com.tzld.longarticle.recommend.server.util.DateUtils;
+import com.tzld.longarticle.recommend.server.util.LarkRobotUtil;
 import com.tzld.longarticle.recommend.server.util.feishu.FeishuMessageSender;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
@@ -60,6 +63,8 @@ public class XxlJobService {
     private LongArticlesReadRateRepository longArticlesReadRateRepository;
     @Autowired
     private LongArticlesRootSourceIdRepository longArticlesRootSourceIdRepository;
+    @Autowired
+    private PushMessageCallbackMapper pushMessageCallbackMapper;
 
     @ApolloJsonValue("${touliu.account.ghIds:[\"gh_93e00e187787\", \"gh_ac43e43b253b\", \"gh_68e7fdc09fe4\",\"gh_77f36c109fb1\", \"gh_b181786a6c8c\", \"gh_1ee2e1b39ccf\"]}")
     private List<String> touliuAccountGhIds;
@@ -292,4 +297,7 @@ public class XxlJobService {
         }
     }
 
+    public void alertPushMessageJob(String dateStr) {
+        LarkRobotUtil.sendMessage("测试报警");
+    }
 }

+ 53 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/util/LarkRobotUtil.java

@@ -0,0 +1,53 @@
+package com.tzld.longarticle.recommend.server.util;
+
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.longarticle.recommend.server.common.HttpPoolFactory;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+@Slf4j
+public class LarkRobotUtil {
+
+
+    private static final CloseableHttpClient client = HttpPoolFactory.defaultPool();
+    private static final String URL = "https://open.feishu.cn/open-apis/bot/v2/hook/93787b70-33d3-42c1-beae-c09310c9b38b";
+
+
+    public static void sendMessage(String msg) {
+        sendMessage("text", "公众号自动回复报警:" + msg);
+    }
+
+    public static void sendMessage(String type, String msg) {
+        try {
+            JSONObject param = new JSONObject();
+            param.put("msg_type", type);
+            JSONObject content = new JSONObject();
+            content.put("text", msg);
+            param.put("content", content);
+            HttpPost httpPost = new HttpPost(URL);
+            StringEntity entity = new StringEntity(param.toJSONString(), StandardCharsets.UTF_8);
+            entity.setContentEncoding("UTF-8");
+            entity.setContentType("application/json");
+            httpPost.setEntity(entity);
+            client.execute(httpPost);
+        } catch (Exception e) {
+            log.error("Lark sendMessage error", e);
+        }
+    }
+
+
+
+}

+ 5 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/XxlJobController.java

@@ -33,4 +33,9 @@ public class XxlJobController {
     public void accountAvgInfoV3Job(String dateStr) {
         service.accountAvgInfoV3Job(dateStr);
     }
+
+    @GetMapping("/alertPushMessageJob")
+    public void alertPushMessageJob(String dateStr) {
+        service.alertPushMessageJob(dateStr);
+    }
 }