|
|
@@ -128,6 +128,12 @@ public class ChannelDemandMatchJob {
|
|
|
new ThreadPoolExecutor.CallerRunsPolicy()
|
|
|
);
|
|
|
|
|
|
+ /**
|
|
|
+ * channel_demand_match_result 保留天数(默认14天)
|
|
|
+ */
|
|
|
+ @Value("${channel.demand.result.retention-days:14}")
|
|
|
+ private int resultRetentionDays;
|
|
|
+
|
|
|
/**
|
|
|
* 点类型 → 向量配置编码映射
|
|
|
*/
|
|
|
@@ -190,6 +196,54 @@ public class ChannelDemandMatchJob {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 渠道需求匹配结果滚动清理任务
|
|
|
+ * 删除 channel_demand_match_result 表中 dt 早于保留窗口(默认14天)的历史数据
|
|
|
+ * param 格式:retainDays=30 (可选,覆盖默认保留天数)
|
|
|
+ */
|
|
|
+ @XxlJob("channelDemandMatchResultCleanJob")
|
|
|
+ public ReturnT<String> channelDemandMatchResultCleanJob(String param) {
|
|
|
+ int retainDays = parseRetainDays(param);
|
|
|
+ // 保留最近 retainDays 天数据:删除 dt < (今天 - retainDays) 的记录
|
|
|
+ String threshold = LocalDate.now().minusDays(retainDays).format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
+ log.info("开始清理 channel_demand_match_result 历史数据, 保留天数: {}, 删除 dt < {} 的记录", retainDays, threshold);
|
|
|
+
|
|
|
+ try {
|
|
|
+ ChannelDemandMatchResultExample example = new ChannelDemandMatchResultExample();
|
|
|
+ example.createCriteria().andDtLessThan(threshold);
|
|
|
+ int deleted = resultMapper.deleteByExample(example);
|
|
|
+ log.info("channel_demand_match_result 历史清理完成, 删除 {} 条 (dt < {})", deleted, threshold);
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("channel_demand_match_result 历史清理失败: {}", e.getMessage(), e);
|
|
|
+ return new ReturnT<>(ReturnT.FAIL_CODE, "清理失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析保留天数参数,支持 retainDays=30 或纯数字;解析失败回退到配置默认值
|
|
|
+ */
|
|
|
+ private int parseRetainDays(String param) {
|
|
|
+ if (StringUtils.hasText(param)) {
|
|
|
+ String value = param.trim();
|
|
|
+ if (value.contains("=")) {
|
|
|
+ String[] parts = value.split("=");
|
|
|
+ if (parts.length == 2 && "retainDays".equals(parts[0].trim())) {
|
|
|
+ value = parts[1].trim();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ int days = Integer.parseInt(value);
|
|
|
+ if (days > 0) {
|
|
|
+ return days;
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException ignored) {
|
|
|
+ log.warn("无效的 retainDays 参数: {}, 使用默认值 {}", param, resultRetentionDays);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultRetentionDays > 0 ? resultRetentionDays : 14;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 处理单个渠道配置:查询ODPS需求数据 → 边查边匹配(流水线化)
|
|
|
* 优化:ODPS流式读取与向量匹配并行执行,减少总体等待时间
|