Browse Source

Merge branch 'dev-xym-alert' of Server/long-article-recommend into master

xueyiming 8 months ago
parent
commit
7087bdc21b

+ 14 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/constant/TimeConstant.java

@@ -0,0 +1,14 @@
+package com.tzld.longarticle.recommend.server.common.constant;
+
+public interface TimeConstant {
+
+    Integer MINUTE = 60;
+    Integer HOUR = 60 * 60;
+    Integer DAY = 60 * 60 * 24;
+
+    Long MILLISECOND_HOUR = (long) HOUR * 1000;
+
+    Long MILLISECOND_DAY = (long) DAY * 1000;
+
+
+}

+ 2 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/StaffEnum.java

@@ -7,7 +7,8 @@ public enum StaffEnum {
     STAFF_ENUM_1("XinYi", "精彩内容分享官"),
     STAFF_ENUM_2("SongYi", "精彩内容推荐官"),
     STAFF_ENUM_3("17512006748", "精彩视频福利官"),
-    STAFF_ENUM_4("18810931977", "精彩内容发送官");
+    STAFF_ENUM_4("18810931977", "精彩内容发送官"),
+    STAFF_ENUM_5("15146364945", "史趣探秘—分享官");
 
     StaffEnum(String userId, String name) {
         this.userId = userId;

+ 36 - 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,10 @@ 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.repository.model.PushMessageCallbackExample;
 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;
@@ -36,10 +40,14 @@ import org.springframework.util.StringUtils;
 
 import java.time.LocalTime;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
+import static com.tzld.longarticle.recommend.server.common.constant.TimeConstant.MILLISECOND_DAY;
+import static com.tzld.longarticle.recommend.server.common.constant.TimeConstant.MILLISECOND_HOUR;
+
 @Service
 @Slf4j
 public class XxlJobService {
@@ -60,6 +68,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 +302,30 @@ public class XxlJobService {
         }
     }
 
+    @XxlJob("alertPushMessageJob")
+    public ReturnT<String> alertPushMessageJob(String param) {
+        long endTimestamp = System.currentTimeMillis();
+        long startTimestamp = endTimestamp - MILLISECOND_HOUR;
+        long ytdStartTimestamp = startTimestamp - MILLISECOND_DAY;
+        long ytdEndTimestamp = endTimestamp - MILLISECOND_DAY;
+        PushMessageCallbackExample example = new PushMessageCallbackExample();
+        example.createCriteria().andCreateTimeBetween(new Date(startTimestamp), new Date(endTimestamp));
+        long nowCount = pushMessageCallbackMapper.countByExample(example);
+        if (nowCount == 0) {
+            LarkRobotUtil.sendMessage("最近一小时回调消息为0");
+        }
+        PushMessageCallbackExample ytdExample = new PushMessageCallbackExample();
+        ytdExample.createCriteria().andCreateTimeBetween(new Date(ytdStartTimestamp), new Date(ytdEndTimestamp));
+        long ydtCount = pushMessageCallbackMapper.countByExample(example);
+        if (nowCount + 1000 < ydtCount) {
+            if (ydtCount == 0) {
+                ydtCount = 1L;
+            }
+            double res = ((double) nowCount - ydtCount) * 100 / ydtCount;
+            LarkRobotUtil.sendMessage("最近一小时回调消息量:" + nowCount + "\n"
+                    + "昨日消息回调量:" + ydtCount + "\n"
+                    + "百分比为:" + String.format("%.2f", res) + "%");
+        }
+        return ReturnT.SUCCESS;
+    }
 }

+ 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);
+    }
 }