فهرست منبع

无限发表 push失败不重试

wangyunpeng 14 ساعت پیش
والد
کامیت
ab77c8a465

+ 28 - 2
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/CoreServiceImpl.java

@@ -624,6 +624,8 @@ public class CoreServiceImpl implements CoreService {
         boolean isGzhGroupPushPlan = Objects.nonNull(planAccount.getPushType())
                 && (Objects.equals(planAccount.getPushType(), PublishGzhPushTypeEnum.auto_group_publish.getVal())
                 || Objects.equals(planAccount.getPushType(), PublishGzhPushTypeEnum.batch_group_publish.getVal()));
+        boolean isInfinitePublishPlan = Objects.equals(planAccount.getPushType(),
+                PublishGzhPushTypeEnum.INFINITE_PUBLISH_PUSH_DRAFT.getVal());
         boolean flag = true;
         // 固定日期
         if (planAccount.getPublishRate() == 1) {
@@ -634,6 +636,11 @@ public class CoreServiceImpl implements CoreService {
                 return false;
             }
         }
+        // 无限发表的单次任务只推送一次,有 pushId 即代表已经提交过。
+        if (isInfinitePublishPlan && hasPushedContent(planAccount.getId())) {
+            planAccountService.updateStatus(2, planAccount.getId());
+            return false;
+        }
         // 指定时间
         if (isGzhGroupPushPlan && StringUtils.isNotEmpty(planAccount.getPublishPushTime())) {
             long pushTime = DateUtil.convertToTimestamp(planAccount.getPublishPushTime());
@@ -657,9 +664,15 @@ public class CoreServiceImpl implements CoreService {
                 List<Long> planAccountIds = planAccountList.stream().map(PlanAccount::getId).collect(Collectors.toList());
                 // 找到该账号最近发布的内容,判断时间间隔
                 PublishContentExample example = new PublishContentExample();
-                example.createCriteria().andStatusIn(Arrays.asList(1, 2))
+                PublishContentExample.Criteria criteria = example.createCriteria()
                         .andCreateTimeGreaterThan(DateUtil.getThatDayDate())
                         .andPlanAccountIdIn(planAccountIds);
+                if (isInfinitePublishPlan) {
+                    // 无限发表按实际提交时间计算间隔,不受最终成功或失败状态影响。
+                    criteria.andPushIdIsNotNull();
+                } else {
+                    criteria.andStatusIn(Arrays.asList(1, 2));
+                }
                 example.setOrderByClause("create_time desc");
                 List<PublishContent> publishContents = publishContentMapper.selectByExample(example);
                 if (!CollectionUtils.isEmpty(publishContents)) {
@@ -765,6 +778,15 @@ public class CoreServiceImpl implements CoreService {
         return flag;
     }
 
+    private boolean hasPushedContent(Long planAccountId) {
+        if (planAccountId == null) {
+            return false;
+        }
+        PublishContentExample example = new PublishContentExample();
+        example.createCriteria().andPlanAccountIdEqualTo(planAccountId).andPushIdIsNotNull();
+        return publishContentMapper.countByExample(example) > 0;
+    }
+
     private List<PlanAccount> getTodayPlanAccountList(String planId, String accountId) {
         PlanAccountExample example = new PlanAccountExample();
         example.createCriteria().andPlanIdEqualTo(planId).andAccountIdEqualTo(accountId)
@@ -1527,7 +1549,11 @@ public class CoreServiceImpl implements CoreService {
                 if (planAccount == null) {
                     continue;
                 }
-                if (!planAccountIdSet.contains(planAccountId)) {
+                if (Objects.equals(planAccount.getPushType(),
+                        PublishGzhPushTypeEnum.INFINITE_PUBLISH_PUSH_DRAFT.getVal())) {
+                    // 无限发表失败后结束当前次任务,下次由间隔时间后的新任务发送。
+                    planAccountService.updateStatus(2, planAccountId);
+                } else if (!planAccountIdSet.contains(planAccountId)) {
                     planAccountService.updateRetry(planAccount);
                 }
                 planAccountIdSet.add(planAccountId);