瀏覽代碼

Merge branch 'wyp/1209-articleDelete' of Server/long-article-recommend into master

wangyunpeng 7 月之前
父節點
當前提交
927fae6c10

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/aigc/PublishAccountRepository.java

@@ -14,4 +14,6 @@ public interface PublishAccountRepository extends JpaRepository<PublishAccount,
     PublishAccount getByGhId(String ghId);
 
     List<PublishAccount> getByIdIn(List<String> publishAccountIds);
+
+    PublishAccount getById(String publishAccountId);
 }

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/LongArticleAuditDeleteRepository.java

@@ -9,4 +9,6 @@ import java.util.List;
 @Repository
 public interface LongArticleAuditDeleteRepository extends JpaRepository<LongArticleAuditDelete, Long> {
     List<LongArticleAuditDelete> getByStatus(Integer status);
+
+    List<LongArticleAuditDelete> getByPublishContentIdIn(List<String> publishContentIds);
 }

+ 45 - 16
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/ArticleAuditService.java

@@ -133,14 +133,28 @@ public class ArticleAuditService {
     }
 
     private void buildArticleAuditDelete(List<String> publishContentIds) {
+        if (CollectionUtils.isEmpty(publishContentIds)) {
+            return;
+        }
+        List<LongArticleAuditDelete> existList = longArticleAuditDeleteRepository.getByPublishContentIdIn(publishContentIds);
+        List<String> existContentIds = existList.stream().map(LongArticleAuditDelete::getPublishContentId).collect(Collectors.toList());
+        publishContentIds = publishContentIds.stream().filter(id -> !existContentIds.contains(id)).collect(Collectors.toList());
+        if (CollectionUtils.isEmpty(publishContentIds)) {
+            return;
+        }
         List<PublishGzhPushContentRelDTO> pushContentRelList = aigcBaseMapper.getPushContentRelByPublishContentIdIn(publishContentIds);
+        if (CollectionUtils.isEmpty(pushContentRelList)) {
+            return;
+        }
         List<String> pushIds = pushContentRelList.stream().map(PublishGzhPushContentRelDTO::getPushId).collect(Collectors.toList());
         Map<String, String> publishPushIdMap = pushContentRelList.stream()
-                .collect(Collectors.toMap(PublishGzhPushContentRelDTO::getPublishContentId, PublishGzhPushContentRelDTO::getPushId));
+                .collect(Collectors.toMap(PublishGzhPushContentRelDTO::getPublishContentId,
+                        PublishGzhPushContentRelDTO::getPushId,
+                         (o1, o2) -> o2));
         List<PublishGzhPushDTO> pushList = aigcBaseMapper.getPushByPushIdIn(pushIds);
         Map<String, PublishGzhPushDTO> pushDTOMap = pushList.stream()
                 .collect(Collectors.toMap(PublishGzhPushDTO::getPushId, Function.identity()));
-        Map<String, String> pushIdMap = pushList.stream()
+        Map<String, String> pushIdMap = pushList.stream().filter(o -> StringUtils.hasText(o.getGroupPushMsgId()))
                 .collect(Collectors.toMap(PublishGzhPushDTO::getPushId, PublishGzhPushDTO::getGroupPushMsgId));
         List<String> publishAccountIds = pushList.stream().map(PublishGzhPushDTO::getPublishAccountId).collect(Collectors.toList());
         Map<String, String> pushAccountMap = pushList.stream()
@@ -155,13 +169,24 @@ public class ArticleAuditService {
         for (String publishContentId : publishContentIds) {
             String pushId = publishPushIdMap.get(publishContentId);
             if (!StringUtils.hasText(pushId)) {
+                deleteFailAlarm(publishContentId, "无推送记录", 0);
                 continue;
             }
             PublishGzhPushDTO publishGzhPushDTO = pushDTOMap.get(pushId);
             if (Objects.isNull(publishGzhPushDTO)) {
+                deleteFailAlarm(publishContentId, "无推送记录", 0);
+                continue;
+            }
+            if (!publishGzhPushDTO.getPushType().equals(PushTypeEnum.AUTO_GROUP_PUBLISH.getVal())) {
+                PushTypeEnum pushTypeEnum = PushTypeEnum.from(publishGzhPushDTO.getPushType());
+                deleteFailAlarm(publishContentId, "推送类型为" + pushTypeEnum.getDescription(), 0);
                 continue;
             }
             String groupPushMsgId = pushIdMap.get(pushId);
+            if (!StringUtils.hasText(groupPushMsgId)) {
+                deleteFailAlarm(publishContentId, "无推送MsgId", 0);
+                continue;
+            }
             String publishAccountId = pushAccountMap.get(pushId);
             String ghId = publishAccountMap.get(publishAccountId);
             List<PublishGzhPushContentRelDTO> relList = groupPushRelMap.get(pushId).stream()
@@ -203,28 +228,32 @@ public class ArticleAuditService {
                 } else {
                     delete.setStatus(ArticleDeleteStatusEnum.FAIL.getCode());
                     delete.setFailReason(result.getFailReason());
-                    delete.setFinishTimestamp(System.currentTimeMillis());
                 }
-                longArticleAuditDeleteRepository.save(delete);
             } else {
-                PublishAccount publishAccount = publishAccountRepository.getByGhId(delete.getGhId());
-                PublishContentDTO publishContent = aigcBaseMapper.getPublishContentById(delete.getPublishContentId());
-                String publishTime = DateUtils.timestampToYMDStr(publishContent.getPublishTimestamp() / 1000, "yyyyMMdd");
-                // 无法自动删除 发送飞书通知 人工删除
-                FeishuMessageSender.sendWebHookMessage(FeishuRobotIdEnum.ARTICLE_DELETE.getRobotId(),
-                        "视频审核不通过文章删除\n"
-                                + "账号名称: " + publishAccount.getName() + "\n"
-                                + "发布日期: " + publishTime + "\n"
-                                + "位置: " + delete.getIndex() + "\n"
-                                + "标题: " + publishContent.getTitle());
-
+                deleteFailAlarm(delete.getPublishContentId(), "非自动群发", delete.getIndex());
                 delete.setStatus(ArticleDeleteStatusEnum.SUCCESS.getCode());
-                longArticleAuditDeleteRepository.save(delete);
             }
+            delete.setFinishTimestamp(System.currentTimeMillis());
+            longArticleAuditDeleteRepository.save(delete);
         }
         return ReturnT.SUCCESS;
     }
 
+    private void deleteFailAlarm(String publishContentId, String typeMsg, Integer index) {
+        PublishContentDTO publishContent = aigcBaseMapper.getPublishContentById(publishContentId);
+        PublishAccount publishAccount = publishAccountRepository.getById(publishContent.getPublishAccountId());
+        String publishTime = DateUtils.timestampToYMDStr(publishContent.getPublishTimestamp() / 1000, "yyyyMMdd");
+        // 无法自动删除 发送飞书通知 人工删除
+        FeishuMessageSender.sendWebHookMessage(FeishuRobotIdEnum.ARTICLE_DELETE.getRobotId(),
+                "【文章删除失败】\n"
+                        + "账号名称: " + publishAccount.getName() + "\n"
+                        + "账号ghId: " + publishAccount.getGhId() + "\n"
+                        + "发布日期: " + publishTime + "\n"
+                        + "位置: " + index + "\n"
+                        + "标题: " + publishContent.getTitle() + "\n"
+                        + "原因: " + typeMsg);
+    }
+
     public void titleDangerFindDelete(ArticleDangerFindDeleteParam param) {
         String titleMd5 = Md5Util.encoderByMd5(param.getTitle());
         // 根据标题查找已发布文章

+ 2 - 3
long-article-recommend-service/src/main/resources/mapper/aigc/AigcBaseMapper.xml

@@ -228,7 +228,7 @@
             resultType="com.tzld.longarticle.recommend.server.model.dto.PublishGzhPushContentRelDTO">
         select pgpcr.*
         from publish_gzh_push_content_rel pgpcr
-        join publish_gzh_push pgp on pgpcr.push_id = pgp.push_id and pgp.push_status = 2 and pgp.publish_status = 2
+        join publish_gzh_push pgp on pgpcr.push_id = pgp.push_id
         where pgpcr.publish_content_id in
         <foreach collection="publishContentIds" item="item" open="(" close=")" separator=",">
             #{item}
@@ -241,7 +241,6 @@
         <foreach collection="pushIds" item="item" open="(" close=")" separator=",">
             #{item}
         </foreach>
-        and group_push_msg_id is not null
     </select>
 
     <select id="getGroupPushRelByPushIdIn"
@@ -255,7 +254,7 @@
 
     <select id="getPublishContentById"
             resultType="com.tzld.longarticle.recommend.server.model.dto.PublishContentDTO">
-        select content.id, content.publish_timestamp, output.output as title
+        select content.id, content.publish_timestamp, content.publish_account_id, output.output as title
         from publish_content content
          join publish_content_output output
           on content.id = output.publish_content_id and output.content_type = 3 AND output.select_status = 1