xueyiming 8 miesięcy temu
rodzic
commit
7ebaf93465

+ 8 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/PlanAccountService.java

@@ -0,0 +1,8 @@
+package com.tzld.piaoquan.longarticle.service.local;
+
+public interface PlanAccountService {
+
+    void updateMatchStatus(Integer status, Long id);
+
+    void updateStatus(Integer status, Long id);
+}

+ 1 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/ContentServiceImpl.java

@@ -3,6 +3,7 @@ package com.tzld.piaoquan.longarticle.service.local.impl;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.piaoquan.longarticle.dao.mapper.CrawlerVideoMapper;
 import com.tzld.piaoquan.longarticle.dao.mapper.MatchVideoMapper;
+import com.tzld.piaoquan.longarticle.dao.mapper.PublishContentMapper;
 import com.tzld.piaoquan.longarticle.model.po.CrawlerVideo;
 import com.tzld.piaoquan.longarticle.model.po.CrawlerVideoExample;
 import com.tzld.piaoquan.longarticle.model.po.MatchVideo;

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

@@ -69,6 +69,9 @@ public class CoreServiceImpl implements CoreService {
     @Autowired
     private RootSourceMapper rootSourceMapper;
 
+    @Autowired
+    private PublicContentServiceImpl publicContentService;
+
     @Override
     public void initPlanAccount() {
         List<LongArticleSystemPlan> allLongArticleSystemPlans = aigcService.getAllLongArticleSystemPlan();
@@ -214,6 +217,9 @@ public class CoreServiceImpl implements CoreService {
     }
 
     private boolean checkPlanAccount(PlanAccount planAccount) {
+        boolean isGzhGroupPushPlan = Objects.nonNull(planAccount.getPushType())
+                && (PublishGzhPushTypeEnum.auto_group_publish.getVal().equals(planAccount.getPushType())
+                || PublishGzhPushTypeEnum.batch_group_publish.getVal().equals(planAccount.getPushType()));
         boolean flag = true;
         // 固定日期
         if (planAccount.getPublishRate() == 1) {
@@ -225,7 +231,7 @@ public class CoreServiceImpl implements CoreService {
             }
         }
         // 指定时间
-        if (StringUtils.isNotEmpty(planAccount.getPublishPushTime())) {
+        if (isGzhGroupPushPlan && StringUtils.isNotEmpty(planAccount.getPublishPushTime())) {
             LocalTime currentTime = TimeZoneUtil.currentTime(TimeZoneUtil.Timezone.china);
             LocalTime pushTime = LocalTime.parse(planAccount.getPublishPushTime());
             if (currentTime.isBefore(pushTime.minusMinutes(20))) {
@@ -243,7 +249,9 @@ public class CoreServiceImpl implements CoreService {
             if (planAccount.getPublishTimeInterval() != null) {
                 // 找到该账号最近发布的内容,判断时间间隔
                 PublishContentExample example = new PublishContentExample();
-                example.createCriteria().andStatusIn(Arrays.asList(1, 2)).andCreateTimeGreaterThan(DateUtil.getThatDayDate());
+                example.createCriteria().andStatusIn(Arrays.asList(1, 2))
+                        .andCreateTimeGreaterThan(DateUtil.getThatDayDate())
+                        .andPlanAccountIdEqualTo(planAccount.getId());
                 example.setOrderByClause("create_time desc");
                 List<PublishContent> publishContents = publishContentMapper.selectByExample(example);
                 if (!CollectionUtils.isEmpty(publishContents)) {
@@ -254,23 +262,53 @@ public class CoreServiceImpl implements CoreService {
                 }
             }
         }
-        PublishContentExample example = new PublishContentExample();
-        example.createCriteria().andStatusIn(Arrays.asList(1, 2)).andCreateTimeGreaterThan(DateUtil.getThatDayDate());
-        long sendCount = publishContentMapper.countByExample(example);
+        int sendCount = publicContentService.getSendCount(planAccount.getId());
+        if (isGzhGroupPushPlan) {
+            //公众号群发每天只能成功发布一次
+            if (sendCount >= 1) {
+                return false;
+            }
+            //公众号群发每天最多尝试3次
+            if (planAccount.getRetryCount() >= 3) {
+                planAccount.setStatus(3);
+                planAccountMapper.updateByPrimaryKeySelective(planAccount);
+                LarkRobotUtil.sendMessage("计划发布失败3次,请查看 账号计划id为" + planAccount.getPlanId());
+                return false;
+            }
+        }
         Integer publishNum = planAccount.getPublishNum();
         if (publishNum == null || publishNum == 0) {
+            LarkRobotUtil.sendMessage("发布数量设置为0 planAccountId=" + planAccount.getId());
             return false;
         }
         if (sendCount >= publishNum) {
             return false;
         }
-        if (planAccount.getRetryCount() >= 3) {
-            planAccount.setStatus(3);
-            planAccountMapper.updateByPrimaryKeySelective(planAccount);
-            LarkRobotUtil.sendMessage("计划发布失败3次,请查看 账号计划id为" + planAccount.getPlanId());
-            return false;
-        }
 
+        int todayNeedSendCount = publishNum - sendCount;
+        // 本次推送数量
+        Integer prePushNum = planAccount.getPublishPreNum();
+        if (Objects.isNull(prePushNum)) {
+            prePushNum = 1;
+        }
+        //如果预计推送数量大于剩余推送数量  本次数量设置为剩余推送数量
+        if (prePushNum > todayNeedSendCount) {
+            prePushNum = todayNeedSendCount;
+        }
+        // 自动发布消息,每次暂时限定发布一条
+        if (PublishGzhPushTypeEnum.robopost.getVal().equals(planAccount.getPushType())) {
+            prePushNum = 1;
+        }
+        // 本次最少推送数量
+        Integer preMinPushNum = planAccount.getPublishPreMinNum();
+        if (Objects.isNull(preMinPushNum)) {
+            preMinPushNum = prePushNum;
+        }
+        if (preMinPushNum > prePushNum) {
+            preMinPushNum = prePushNum;
+        }
+        planAccount.setPublishPreNum(prePushNum);
+        planAccount.setPublishPreMinNum(preMinPushNum);
         return flag;
     }
 
@@ -293,16 +331,7 @@ public class CoreServiceImpl implements CoreService {
 //            articleSortRequest.setStrategy("ArticleRankRandom");
 //            articleSortRequest.setExcludeLog(true);
             articleSortRequest.setStrategy(planAccount.getSortStrategy());
-            if (Objects.equals(planAccount.getPushType(), PublishGzhPushTypeEnum.manual_push.getVal())) {
-                PublishContentExample publishContentExample = new PublishContentExample();
-                publishContentExample.createCriteria().andStatusIn(Arrays.asList(1, 2)).andCreateTimeGreaterThan(DateUtil.getThatDayDate());
-                long sendCount = publishContentMapper.countByExample(publishContentExample);
-                if (planAccount.getPublishPreNum() <= (planAccount.getPublishNum() - sendCount)) {
-                    articleSortRequest.setPublishNum(planAccount.getPublishPreNum());
-                } else {
-                    articleSortRequest.setPublishNum((int) (planAccount.getPublishNum() - sendCount));
-                }
-            }
+            articleSortRequest.setPublishNum(planAccount.getPublishPreNum());
             if (Objects.equals(PublishGzhPushTypeEnum.auto_group_publish.getVal(), planAccount.getPushType())) {
                 articleSortRequest.setPublishNum(planAccount.getPublishNum());
             }

+ 13 - 1
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/PlanAccountServiceImpl.java

@@ -2,19 +2,31 @@ package com.tzld.piaoquan.longarticle.service.local.impl;
 
 import com.tzld.piaoquan.longarticle.dao.mapper.PlanAccountMapper;
 import com.tzld.piaoquan.longarticle.model.po.PlanAccount;
+import com.tzld.piaoquan.longarticle.service.local.PlanAccountService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 @Service
-public class PlanAccountServiceImpl {
+public class PlanAccountServiceImpl implements PlanAccountService {
 
     @Autowired
     private PlanAccountMapper planAccountMapper;
 
+
+    @Override
     public void updateMatchStatus(Integer status, Long id) {
         PlanAccount updatePlanAccount = new PlanAccount();
         updatePlanAccount.setId(id);
         updatePlanAccount.setMatchStatus(status);
         planAccountMapper.updateByPrimaryKey(updatePlanAccount);
     }
+
+    @Override
+    public void updateStatus(Integer status, Long id) {
+        PlanAccount updatePlanAccount = new PlanAccount();
+        updatePlanAccount.setId(id);
+        updatePlanAccount.setStatus(status);
+        planAccountMapper.updateByPrimaryKey(updatePlanAccount);
+    }
+
 }

+ 25 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/PublicContentServiceImpl.java

@@ -0,0 +1,25 @@
+package com.tzld.piaoquan.longarticle.service.local.impl;
+
+import com.tzld.piaoquan.longarticle.dao.mapper.PublishContentMapper;
+import com.tzld.piaoquan.longarticle.model.po.PublishContentExample;
+import com.tzld.piaoquan.longarticle.utils.DateUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+
+@Service
+public class PublicContentServiceImpl {
+
+    @Autowired
+    private PublishContentMapper publishContentMapper;
+
+    public int getSendCount(Long planAccountId) {
+        PublishContentExample example = new PublishContentExample();
+        example.createCriteria().andStatusIn(Arrays.asList(1, 2))
+                .andCreateTimeGreaterThan(DateUtil.getThatDayDate())
+                .andPlanAccountIdEqualTo(planAccountId);
+        long sendCount = publishContentMapper.countByExample(example);
+        return (int) sendCount;
+    }
+}