Просмотр исходного кода

合作平台 需求视频池滚动删除

wangyunpeng 20 часов назад
Родитель
Сommit
b869b6ca30

+ 2 - 0
api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/contentplatform/ext/ContentPlatformDemandVideoMapperExt.java

@@ -31,6 +31,8 @@ public interface ContentPlatformDemandVideoMapperExt {
 
     String getMaxDt(@Param("channelName") String channelName);
 
+    List<String> selectDistinctDtsLessThan(@Param("dt") String dt);
+
     /**
      * 按 ghName(channel_level3) 反查所属 channel_name,取该 gh 最新分区的一行。
      * 业务约定一个公众号只归属一个 channel,故 ORDER BY dt DESC LIMIT 1。

+ 9 - 2
api-module/src/main/java/com/tzld/piaoquan/api/job/contentplatform/ContentPlatformDemandVideoJob.java

@@ -386,8 +386,15 @@ public class ContentPlatformDemandVideoJob {
         }
         log.info("cleanContentPlatformDemandVideoJob start, cutoffDt={}", cutoffDt);
         try {
-            int rows = demandVideoMapperExt.deleteByDtLessThan(cutoffDt);
-            log.info("cleanContentPlatformDemandVideoJob success, cutoffDt={}, deletedRows={}", cutoffDt, rows);
+            List<String> dts = demandVideoMapperExt.selectDistinctDtsLessThan(cutoffDt);
+            log.info("cleanContentPlatformDemandVideoJob found {} dts less than {}", dts.size(), cutoffDt);
+            int totalDeleted = 0;
+            for (String dt : dts) {
+                int rows = demandVideoMapperExt.deleteByDt(dt);
+                totalDeleted += rows;
+                log.info("cleanContentPlatformDemandVideoJob deleted dt={}, rows={}", dt, rows);
+            }
+            log.info("cleanContentPlatformDemandVideoJob success, cutoffDt={}, totalDeletedRows={}", cutoffDt, totalDeleted);
         } catch (Exception e) {
             log.error("cleanContentPlatformDemandVideoJob error, cutoffDt={}", cutoffDt, e);
             return ReturnT.FAIL;

+ 7 - 0
api-module/src/main/resources/mapper/contentplatform/ext/ContentPlatformDemandVideoMapperExt.xml

@@ -98,6 +98,13 @@
         </where>
     </select>
 
+    <select id="selectDistinctDtsLessThan" resultType="java.lang.String">
+        SELECT DISTINCT dt
+        FROM content_platform_demand_video
+        WHERE dt &lt; #{dt}
+        ORDER BY dt
+    </select>
+
     <select id="selectChannelNameByGh" resultType="java.lang.String">
         SELECT channel_name
         FROM content_platform_demand_video