Selaa lähdekoodia

重新匹配小程序

wangyunpeng 6 kuukautta sitten
vanhempi
commit
1e3b6f78f6

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

@@ -0,0 +1,35 @@
+package com.tzld.longarticle.recommend.server.common.enums.recommend;
+
+import lombok.Getter;
+
+@Getter
+public enum ArticleMatchContentStatusEnum {
+    PROCESSING_STATUS(101, "任务处理中"),
+    INIT_STATUS(0, "任务初始化状态"),
+    KIMI_FINISHED_STATUS(1, "Kimi 执行完成状态"),
+    SPIDER_FINISHED_STATUS(2, "爬虫执行完成状态"),
+    ETL_COMPLETE_STATUS(3, "任务视频ETL 完成状态"),
+    PUBLISHED_STATUS(4, "任务发布完成状态"),
+    MISMATCH_STATUS(96, "文章品类不匹配"),
+    EXIT_STATUS(97, "文章已经退场 or 晋级"),
+    FAIL_STATUS(99, "失败"),
+    ;
+
+    private Integer code;
+    private String desc;
+
+    ArticleMatchContentStatusEnum(Integer code, String desc) {
+        this.code = code;
+        this.desc = desc;
+    }
+
+    public static ArticleMatchContentStatusEnum from(Integer code) {
+        for (ArticleMatchContentStatusEnum status : ArticleMatchContentStatusEnum.values()) {
+            if (status.getCode().equals(code)) {
+                return status;
+            }
+        }
+        return null;
+    }
+
+}

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

@@ -69,4 +69,6 @@ public interface LongArticleBaseMapper {
     List<String> getFilterColdLongArticleTitle();
 
     List<String> getExistsOssPath();
+
+    void batchInsertArticleReMatchRecord(List<ArticleReMatchRecord> list);
 }

+ 38 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/entity/longArticle/ArticleReMatchRecord.java

@@ -0,0 +1,38 @@
+package com.tzld.longarticle.recommend.server.model.entity.longArticle;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Entity
+@Table(name = "article_title_his_cache")
+public class ArticleReMatchRecord {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private Integer id;
+
+    @Column(name = "trace_id")
+    private String traceId;
+
+    @Column(name = "status")
+    private Integer status;
+
+    @Column(name = "old_response")
+    private String oldResponse;
+
+    @Column(name = "new_response")
+    private String newResponse;
+
+    @Column(name = "create_timestamp")
+    private Long createTimestamp;
+
+    @Column(name = "finish_timestamp")
+    private Long finishTimestamp;
+}

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

@@ -9,6 +9,7 @@ import com.tzld.longarticle.recommend.server.common.enums.aigc.PushTypeEnum;
 import com.tzld.longarticle.recommend.server.common.enums.cgi.PQVideoAuditResultEnum;
 import com.tzld.longarticle.recommend.server.common.enums.cgi.PQVideoSensitiveLevelEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleDeleteStatusEnum;
+import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleMatchContentStatusEnum;
 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.mapper.longArticle.LongArticleBaseMapper;
@@ -210,14 +211,61 @@ public class ArticleAuditService {
         if (CollectionUtils.isEmpty(crawlerVideoList)) {
             return;
         }
+        for (LongArticleCrawlerVideo longArticleCrawlerVideo : crawlerVideoList) {
+            longArticleCrawlerVideo.setIsIllegal(1);
+            longArticleCrawlerVideoRepository.save(longArticleCrawlerVideo);
+        }
         List<String> contentIds = crawlerVideoList.stream().map(LongArticleCrawlerVideo::getContentId).collect(Collectors.toList());
         List<LongArticlesMatchVideo> matchVideoList = longArticlesMatchVideoRepository.getByContentIdIn(contentIds);
+        Map<String, LongArticlesMatchVideo> matchVideoMap = matchVideoList.stream()
+               .collect(Collectors.toMap(LongArticlesMatchVideo::getTraceId, Function.identity()));
         List<String> traceIds = matchVideoList.stream().map(LongArticlesMatchVideo::getTraceId).collect(Collectors.toList());
-        List<PublishContentMiniprogramDTO> publishContentList = aigcBaseMapper.getPublishContentByTraceIdIn(traceIds);
-        List<String> publishContentIds = publishContentList.stream().map(PublishContentMiniprogramDTO::getPublishContentId).collect(Collectors.toList());
+        List<PublishContentMiniprogramDTO> publishContentMiniprogramList = aigcBaseMapper.getPublishContentByTraceIdIn(traceIds);
+        List<String> publishContentIds = publishContentMiniprogramList.stream()
+                .map(PublishContentMiniprogramDTO::getPublishContentId).collect(Collectors.toList());
+        Map<String, String> PublishTraceIdMap = publishContentMiniprogramList.stream()
+               .collect(Collectors.toMap(PublishContentMiniprogramDTO::getPublishContentId, PublishContentMiniprogramDTO::getTraceId));
+        // 过滤状态非已发布内容
+        List<PublishContent> publishContentList = publishContentRepository.getByIdIn(publishContentIds);
+        List<String> publishedIds = publishContentList.stream()
+                .filter(o -> Objects.equals(o.getStatus(), PublishContentStatusEnum.published.getVal()))
+                .map(PublishContent::getId).collect(Collectors.toList());
+        publishContentIds = publishContentIds.stream().filter(publishedIds::contains).collect(Collectors.toList());
+        List<String> deleteTraceIds = publishContentIds.stream().map(PublishTraceIdMap::get).collect(Collectors.toList());
+        // 重新匹配小程序
+        List<String> reMatchTraceIds = traceIds.stream().filter(o -> !deleteTraceIds.contains(o)).collect(Collectors.toList());
+        buildReMatchRecord(reMatchTraceIds, matchVideoMap);
+        // 文章删除
         buildArticleAuditDelete(publishContentIds);
     }
 
+    private void buildReMatchRecord(List<String> reMatchTraceIds, Map<String, LongArticlesMatchVideo> matchVideoMap) {
+        if (CollectionUtils.isEmpty(reMatchTraceIds)) {
+            return;
+        }
+        Long now = System.currentTimeMillis() / 1000;
+        List<ArticleReMatchRecord> reMatchRecordList = new ArrayList<>();
+        for (String traceId : reMatchTraceIds) {
+            LongArticlesMatchVideo matchVideo = matchVideoMap.get(traceId);
+            if (Objects.isNull(matchVideo)
+                    || ArticleMatchContentStatusEnum.ETL_COMPLETE_STATUS.getCode().equals(matchVideo.getContentStatus())
+                    || ArticleMatchContentStatusEnum.MISMATCH_STATUS.getCode().equals(matchVideo.getContentStatus())
+                    || ArticleMatchContentStatusEnum.EXIT_STATUS.getCode().equals(matchVideo.getContentStatus())
+                    || ArticleMatchContentStatusEnum.FAIL_STATUS.getCode().equals(matchVideo.getContentStatus())) {
+                continue;
+            }
+            ArticleReMatchRecord record = new ArticleReMatchRecord();
+            record.setTraceId(traceId);
+            record.setStatus(0);
+            if (StringUtils.hasText(matchVideo.getResponse())) {
+                record.setOldResponse(matchVideo.getResponse());
+            }
+            record.setCreateTimestamp(now);
+            reMatchRecordList.add(record);
+        }
+        longArticleBaseMapper.batchInsertArticleReMatchRecord(reMatchRecordList);
+    }
+
     private void buildArticleAuditDelete(List<String> publishContentIds) {
         if (CollectionUtils.isEmpty(publishContentIds)) {
             return;
@@ -229,15 +277,6 @@ public class ArticleAuditService {
         if (CollectionUtils.isEmpty(publishContentIds)) {
             return;
         }
-        // 过滤状态非已发布内容
-        List<PublishContent> publishContentList = publishContentRepository.getByIdIn(publishContentIds);
-        List<String> publishedIds = publishContentList.stream()
-                .filter(o -> Objects.equals(o.getStatus(), PublishContentStatusEnum.published.getVal()))
-                .map(PublishContent::getId).collect(Collectors.toList());
-        publishContentIds = publishContentIds.stream().filter(publishedIds::contains).collect(Collectors.toList());
-        if (CollectionUtils.isEmpty(publishContentIds)) {
-            return;
-        }
         List<PublishGzhPushContentRelDTO> pushContentRelList = aigcBaseMapper.getPushContentRelByPublishContentIdIn(publishContentIds);
         if (CollectionUtils.isEmpty(pushContentRelList)) {
             return;

+ 9 - 0
long-article-recommend-service/src/main/resources/mapper/longArticle/LongArticleBaseMapper.xml

@@ -260,4 +260,13 @@
         select distinct oss_path from long_articles_video_audit
     </select>
 
+    <insert id="batchInsertArticleReMatchRecord">
+        insert into article_re_match_record
+        (trace_id, status, old_response, create_timestamp)
+        values
+        <foreach collection="list" item="item" separator=",">
+            (#{item.traceId}, #{item.status}, #{item.oldResponse}, #{item.createTimestamp})
+        </foreach>
+    </insert>
+
 </mapper>