Browse Source

违规文章关联删除

wangyunpeng 7 months ago
parent
commit
35e40f0a9f

+ 29 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/recommend/ArticleDeleteStatusEnum.java

@@ -0,0 +1,29 @@
+package com.tzld.longarticle.recommend.server.common.enums.recommend;
+
+import lombok.Getter;
+
+@Getter
+public enum ArticleDeleteStatusEnum {
+
+    WAITING(0, "WAITING"),
+    SUCCESS(1, "SUCCESS"),
+    FAIL(2, "FAIL"),
+    ;
+
+    private int code;
+    private String msg;
+
+    ArticleDeleteStatusEnum(int code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    public static ArticleDeleteStatusEnum getByCode(int code) {
+        for (ArticleDeleteStatusEnum statusEnum : ArticleDeleteStatusEnum.values()) {
+            if (statusEnum.getCode() == code) {
+                return statusEnum;
+            }
+        }
+        return null;
+    }
+}

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

@@ -54,4 +54,6 @@ public interface AigcBaseMapper {
     List<PublishGzhPushContentRelDTO> getGroupPushRelByPushIdIn(List<String> pushIds);
 
     PublishContentDTO getPublishContentById(String publishContentId);
+
+    List<PublishContentDTO> getPublishContentBySourceIdIn(List<String> sourceIds);
 }

+ 3 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/entity/longArticle/LongArticleAuditDelete.java

@@ -10,8 +10,9 @@ import javax.persistence.*;
 @AllArgsConstructor
 @NoArgsConstructor
 @Entity
-@Table(name = "long_articles_audit_delete")
+@Table(name = "long_article_audit_delete")
 public class LongArticleAuditDelete {
+
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     @Column(name = "id")
@@ -23,7 +24,7 @@ public class LongArticleAuditDelete {
     @Column(name = "msg_id")
     private String msgId;
 
-    @Column(name = "index")
+    @Column(name = "`index`")
     private Integer index;
 
     @Column(name = "push_id")

+ 13 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/param/ArticleDangerFindDeleteParam.java

@@ -0,0 +1,13 @@
+package com.tzld.longarticle.recommend.server.model.param;
+
+import lombok.Data;
+
+@Data
+public class ArticleDangerFindDeleteParam {
+
+    private String ghId;
+    private String accountName;
+    private String title;
+    private String wxSn;
+
+}

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

@@ -36,4 +36,6 @@ public interface ArticleRepository extends JpaRepository<Article, String> {
     int countByGhIdAndTypeAndItemIndex(String ghId, String val, Integer itemIndex);
 
     List<Article> getByGhIdInAndUpdateTimeGreaterThanAndTypeEquals(List<String> ghIds, long l, String number);
+
+    List<Article> getByTitleMd5(String titleMd5);
 }

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

@@ -2,27 +2,36 @@ package com.tzld.longarticle.recommend.server.service.recommend;
 
 import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSONArray;
+import com.google.common.collect.Lists;
 import com.tzld.longarticle.recommend.server.common.enums.StatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.aigc.PushTypeEnum;
+import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleDeleteStatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.FeishuRobotIdEnum;
 import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 import com.tzld.longarticle.recommend.server.model.dto.*;
 import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
+import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
 import com.tzld.longarticle.recommend.server.model.entity.longArticle.*;
+import com.tzld.longarticle.recommend.server.model.param.ArticleDangerFindDeleteParam;
 import com.tzld.longarticle.recommend.server.model.param.ArticleVideoAuditResultParam;
+import com.tzld.longarticle.recommend.server.model.param.PublishContentParam;
 import com.tzld.longarticle.recommend.server.remote.WxAccessTokenRemoteService;
 import com.tzld.longarticle.recommend.server.remote.WxArticleDeleteService;
 import com.tzld.longarticle.recommend.server.repository.aigc.PublishAccountRepository;
+import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
 import com.tzld.longarticle.recommend.server.repository.longArticle.*;
 import com.tzld.longarticle.recommend.server.util.DateUtils;
+import com.tzld.longarticle.recommend.server.util.Md5Util;
 import com.tzld.longarticle.recommend.server.util.feishu.FeishuMessageSender;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -51,9 +60,11 @@ public class ArticleAuditService {
     private AigcBaseMapper aigcBaseMapper;
     @Autowired
     private PublishAccountRepository publishAccountRepository;
+    @Autowired
+    private ArticleRepository articleRepository;
 
 
-    @XxlJob("articleVideoAudit")
+//    @XxlJob("articleVideoAudit")
     public ReturnT<String> articleVideoAudit(String param) {
         long publishTime = DateUtils.getTodayStart();
         if (StringUtils.hasText(param)) {
@@ -118,8 +129,10 @@ public class ArticleAuditService {
         List<String> traceIds = crawlerVideoList.stream().map(LongArticleCrawlerVideo::getTraceId).collect(Collectors.toList());
         List<PublishContentMiniprogramDTO> publishContentList = aigcBaseMapper.getPublishContentByTraceIdIn(traceIds);
         List<String> publishContentIds = publishContentList.stream().map(PublishContentMiniprogramDTO::getPublishContentId).collect(Collectors.toList());
-        Map<String, String> publishContentIdMap = publishContentList.stream()
-                .collect(Collectors.toMap(PublishContentMiniprogramDTO::getTraceId, PublishContentMiniprogramDTO::getPublishContentId));
+        buildArticleAuditDelete(publishContentIds);
+    }
+
+    private void buildArticleAuditDelete(List<String> publishContentIds) {
         List<PublishGzhPushContentRelDTO> pushContentRelList = aigcBaseMapper.getPushContentRelByPublishContentIdIn(publishContentIds);
         List<String> pushIds = pushContentRelList.stream().map(PublishGzhPushContentRelDTO::getPushId).collect(Collectors.toList());
         Map<String, String> publishPushIdMap = pushContentRelList.stream()
@@ -138,14 +151,16 @@ public class ArticleAuditService {
         List<PublishGzhPushContentRelDTO> groupPushRelList = aigcBaseMapper.getGroupPushRelByPushIdIn(pushIds);
         Map<String, List<PublishGzhPushContentRelDTO>> groupPushRelMap = groupPushRelList.stream()
                 .collect(Collectors.groupingBy(PublishGzhPushContentRelDTO::getPushId));
-        for (String traceId : traceIds) {
-            String publishContentId = publishContentIdMap.get(traceId);
+        // 删除文章
+        for (String publishContentId : publishContentIds) {
             String pushId = publishPushIdMap.get(publishContentId);
             if (!StringUtils.hasText(pushId)) {
-                // todo 未发布文章如何进行小程序替换
                 continue;
             }
             PublishGzhPushDTO publishGzhPushDTO = pushDTOMap.get(pushId);
+            if (Objects.isNull(publishGzhPushDTO)) {
+                continue;
+            }
             String groupPushMsgId = pushIdMap.get(pushId);
             String publishAccountId = pushAccountMap.get(pushId);
             String ghId = publishAccountMap.get(publishAccountId);
@@ -175,7 +190,7 @@ public class ArticleAuditService {
      */
     @XxlJob("articleVideoDelete")
     public ReturnT<String> articleVideoDelete(String param) {
-        List<LongArticleAuditDelete> dealList = longArticleAuditDeleteRepository.getByStatus(StatusEnum.ZERO.getCode());
+        List<LongArticleAuditDelete> dealList = longArticleAuditDeleteRepository.getByStatus(ArticleDeleteStatusEnum.WAITING.getCode());
         for (LongArticleAuditDelete delete : dealList) {
             if (Objects.equals(delete.getPushType(), PushTypeEnum.AUTO_GROUP_PUBLISH.getVal())) {
                 // 获取token
@@ -183,9 +198,10 @@ public class ArticleAuditService {
                 // 删除文章
                 RequestResult<String> result = wxArticleDeleteService.deleteArticle(token, delete.getMsgId(), delete.getIndex());
                 if (result.isSuccess()) {
-                    delete.setStatus(StatusEnum.ONE.getCode());
+                    delete.setStatus(ArticleDeleteStatusEnum.SUCCESS.getCode());
                 } else {
-                    delete.setStatus(StatusEnum.TWO.getCode());
+                    delete.setStatus(ArticleDeleteStatusEnum.FAIL.getCode());
+                    delete.setFailReason(result.getFailReason());
                     delete.setFinishTimestamp(System.currentTimeMillis());
                 }
                 longArticleAuditDeleteRepository.save(delete);
@@ -201,10 +217,38 @@ public class ArticleAuditService {
                                 + "位置: " + delete.getIndex() + "\n"
                                 + "标题: " + publishContent.getTitle());
 
-                delete.setStatus(StatusEnum.ONE.getCode());
+                delete.setStatus(ArticleDeleteStatusEnum.SUCCESS.getCode());
                 longArticleAuditDeleteRepository.save(delete);
             }
         }
         return ReturnT.SUCCESS;
     }
+
+    public void titleDangerFindDelete(ArticleDangerFindDeleteParam param) {
+        String titleMd5 = Md5Util.encoderByMd5(param.getTitle());
+        // 根据标题查找已发布文章
+        List<Article> articleList = articleRepository.getByTitleMd5(titleMd5);
+        List<String> ghIds = articleList.stream().map(Article::getGhId).distinct().collect(Collectors.toList());
+        List<PublishAccount> publishAccountList = publishAccountRepository.getAllByGhIdIn(ghIds);
+        List<PublishContentParam> publishContentParamList = publishAccountList.stream().map(account -> {
+            PublishContentParam item = new PublishContentParam();
+            item.setTitle(param.getTitle());
+            item.setPublishAccountId(account.getId());
+            return item;
+        }).collect(Collectors.toList());
+        List<PublishContentDTO> publishContents = new ArrayList<>();
+        for (List<PublishContentParam> partitions : Lists.partition(publishContentParamList, 100)) {
+            publishContents.addAll(aigcBaseMapper.getPublishContentByTitle(partitions));
+        }
+        if (CollectionUtils.isEmpty(publishContents)) {
+            return;
+        }
+        // 查找该生成内容下所有已发布内容
+        List<String> sourceIds = publishContents.stream().map(PublishContentDTO::getSourceId).distinct().collect(Collectors.toList());
+        publishContents = aigcBaseMapper.getPublishContentBySourceIdIn(sourceIds);
+
+        // 根据已发布文章查找推送id 并删除
+        List<String> publishContentIds = publishContents.stream().map(PublishContentDTO::getId).collect(Collectors.toList());
+        buildArticleAuditDelete(publishContentIds);
+    }
 }

+ 14 - 8
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/recommend/ArticleAuditController.java

@@ -1,7 +1,7 @@
 package com.tzld.longarticle.recommend.server.web.recommend;
 
 import com.tzld.longarticle.recommend.server.common.response.CommonResponse;
-import com.tzld.longarticle.recommend.server.model.param.ArticleVideoAuditResultParam;
+import com.tzld.longarticle.recommend.server.model.param.ArticleDangerFindDeleteParam;
 import com.tzld.longarticle.recommend.server.service.recommend.ArticleAuditService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,14 +16,20 @@ public class ArticleAuditController {
     private ArticleAuditService service;
 
 
-    @GetMapping("/articleVideoAudit")
-    public void articleVideoAudit(String dateStr) {
-        service.articleVideoAudit(dateStr);
-    }
+//    @GetMapping("/articleVideoAudit")
+//    public void articleVideoAudit(String dateStr) {
+//        service.articleVideoAudit(dateStr);
+//    }
+//
+//    @PostMapping("/articleVideoAuditResult")
+//    public CommonResponse<Void> articleVideoAuditResult(@RequestBody ArticleVideoAuditResultParam param) {
+//        service.articleVideoAuditResult(param);
+//        return CommonResponse.success();
+//    }
 
-    @PostMapping("/articleVideoAuditResult")
-    public CommonResponse<Void> articleVideoAuditResult(@RequestBody ArticleVideoAuditResultParam param) {
-        service.articleVideoAuditResult(param);
+    @PostMapping("/titleDangerFindDelete")
+    public CommonResponse<Void> titleDangerFindDelete(@RequestBody ArticleDangerFindDeleteParam param) {
+        service.titleDangerFindDelete(param);
         return CommonResponse.success();
     }
 

+ 17 - 7
long-article-recommend-service/src/main/resources/mapper/aigc/AigcBaseMapper.xml

@@ -9,7 +9,8 @@
 
     <select id="getPublishContentByTitle"
             resultType="com.tzld.longarticle.recommend.server.model.dto.PublishContentDTO">
-        select content.*, output.output as title
+        select content.id, content.plan_id, content.source_type, content.source_id, content.crawler_channel_content_id,
+               content.publish_account_id, content.publish_timestamp, 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
@@ -20,11 +21,6 @@
         </foreach>
     </select>
 
-    <select id="getPublishPlanById"
-            resultType="com.tzld.longarticle.recommend.server.model.entity.aigc.PublishPlan">
-        select * from publish_plan where id = #{planId}
-    </select>
-
     <select id="getMiniProgramTask"
             resultType="com.tzld.longarticle.recommend.server.model.entity.aigc.PublishPlanMiniprogramTask">
         select * from publish_plan_miniprogram_task where
@@ -230,7 +226,10 @@
 
     <select id="getPushContentRelByPublishContentIdIn"
             resultType="com.tzld.longarticle.recommend.server.model.dto.PublishGzhPushContentRelDTO">
-        select * from publish_gzh_push_content_rel where publish_content_id in
+        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
+        where pgpcr.publish_content_id in
         <foreach collection="publishContentIds" item="item" open="(" close=")" separator=",">
             #{item}
         </foreach>
@@ -242,6 +241,7 @@
         <foreach collection="pushIds" item="item" open="(" close=")" separator=",">
             #{item}
         </foreach>
+        and group_push_msg_id is not null
     </select>
 
     <select id="getGroupPushRelByPushIdIn"
@@ -262,4 +262,14 @@
         where content.id = #{publishContentId}
     </select>
 
+    <select id="getPublishContentBySourceIdIn"
+            resultType="com.tzld.longarticle.recommend.server.model.dto.PublishContentDTO">
+        select id, plan_id, source_type, source_id, crawler_channel_content_id, publish_account_id, publish_timestamp
+        from publish_content
+        where status = 2 and source_id in
+        <foreach collection="sourceIds" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+    </select>
+
 </mapper>