|
|
@@ -0,0 +1,65 @@
|
|
|
+package com.tzld.videoVector.job;
|
|
|
+
|
|
|
+import com.tzld.videoVector.dao.mapper.pgVector.ChannelDemandMatchResultMapper;
|
|
|
+import com.tzld.videoVector.model.po.pgVector.ChannelDemandMatchResultExample;
|
|
|
+import com.tzld.videoVector.util.feishu.FeishuMessageSender;
|
|
|
+import com.xxl.job.core.biz.model.ReturnT;
|
|
|
+import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 渠道需求匹配结果每日数据检查Job
|
|
|
+ * 检查 channel_demand_match_result 表当日数据量,无数据或数量不足时飞书报警
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class ChannelDemandMatchCheckJob {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ChannelDemandMatchResultMapper resultMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 飞书机器人webhook ID
|
|
|
+ */
|
|
|
+ private static final String FEISHU_ROBOT_ID = "ca881b01-180f-40a6-bd33-05e64c06194f";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查 channel_demand_match_result 表当日数据
|
|
|
+ * 如果当日无数据,发送飞书报警
|
|
|
+ */
|
|
|
+ @XxlJob("checkChannelDemandMatchDataJob")
|
|
|
+ public ReturnT<String> checkChannelDemandMatchDataJob(String param) {
|
|
|
+ String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
+ log.info("开始检查 channel_demand_match_result 表当日数据, dt={}", today);
|
|
|
+
|
|
|
+ try {
|
|
|
+ ChannelDemandMatchResultExample example = new ChannelDemandMatchResultExample();
|
|
|
+ example.createCriteria().andDtEqualTo(today);
|
|
|
+ long count = resultMapper.countByExample(example);
|
|
|
+
|
|
|
+ log.info("channel_demand_match_result 表当日数据量, dt={}, count={}", today, count);
|
|
|
+
|
|
|
+ if (count == 0) {
|
|
|
+ String alertMsg = String.format(
|
|
|
+ "【渠道需求匹配告警】channel_demand_match_result 表当日(%s)暂无数据,请检查 channelDemandMatchJob 执行状态。", today);
|
|
|
+ FeishuMessageSender.sendWebHookMessage(FEISHU_ROBOT_ID, alertMsg);
|
|
|
+ log.warn("channel_demand_match_result 表当日无数据,已发送飞书报警, dt={}", today);
|
|
|
+ } else if (count < 100000) {
|
|
|
+ String alertMsg = String.format(
|
|
|
+ "【渠道需求匹配告警】channel_demand_match_result 表当日(%s)数据量不足,当前仅 %d 条(阈值 100000),请关注。", today, count);
|
|
|
+ FeishuMessageSender.sendWebHookMessage(FEISHU_ROBOT_ID, alertMsg);
|
|
|
+ log.warn("channel_demand_match_result 表当日数据量不足,已发送飞书报警, dt={}, count={}", today, count);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("检查 channel_demand_match_result 表数据失败: {}", e.getMessage(), e);
|
|
|
+ return new ReturnT<>(ReturnT.FAIL_CODE, "检查失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|