Bladeren bron

doPreFilter

wangyunpeng 13 uur geleden
bovenliggende
commit
f64284a47c

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

@@ -1105,6 +1105,9 @@ public class XxlJobService {
                     List<Content> contentList;
                     contentList = aigcWaitingPublishContentService.getAllContent(account.getPlanId(), account.getAccountId(), null);
                     savePublishContentCache(contentList, account.getPlanId(), account.getAccountId(), true, now);
+                    String redisKey = "ContentPreFilterJob:" + DateUtils.getCurrentDateStr("yyyyMMdd") + ":"
+                            + account.getPlanId() + "-" + account.getAccountId();
+                    doPreFilter(account, redisKey, 0, null);
                 } finally {
                     cdl.countDown();
                 }
@@ -1213,21 +1216,7 @@ public class XxlJobService {
                 continue;
             }
             Integer finalIndex = index;
-            thread.submit(() -> {
-                boolean success = false;
-                try {
-                    preFilter(item, redisKey, finalIndex);
-                    success = true;
-                } catch (Exception e) {
-                    log.error("ContentPreFilterJob error index:{} planId: {} accountId: {}",
-                            finalIndex, item.getPlanId(), item.getAccountId(), e);
-                } finally {
-                    if (success) {
-                        redisTemplate.opsForValue().set(redisKey, "1", 1, TimeUnit.DAYS);
-                    }
-                    cdl.countDown();
-                }
-            });
+            thread.submit(() -> doPreFilter(item, redisKey, finalIndex, cdl));
         }
         try {
             cdl.await();
@@ -1238,6 +1227,24 @@ public class XxlJobService {
         }
     }
 
+    private void doPreFilter(PublishPlanAccountDTO item, String redisKey, Integer finalIndex, CountDownLatch cdl) {
+        boolean success = false;
+        try {
+            preFilter(item, redisKey, finalIndex);
+            success = true;
+        } catch (Exception e) {
+            log.error("ContentPreFilterJob error index:{} planId: {} accountId: {}",
+                    finalIndex, item.getPlanId(), item.getAccountId(), e);
+        } finally {
+            if (success) {
+                redisTemplate.opsForValue().set(redisKey, "1", 1, TimeUnit.DAYS);
+            }
+            if (Objects.nonNull(cdl)) {
+                cdl.countDown();
+            }
+        }
+    }
+
     public void preFilter(PublishPlanAccountDTO item, String redisKey, Integer finalIndex) {
         String value = redisTemplate.opsForValue().get(redisKey);
         if (StringUtils.hasText(value)) {