Pārlūkot izejas kodu

预过滤内容废弃同步aigc

wangyunpeng 3 dienas atpakaļ
vecāks
revīzija
e53c298a3f

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

@@ -119,4 +119,6 @@ public interface LongArticleBaseMapper {
     List<Content> getPublishContentGzhWaiting(String planId, String accountId);
 
     void updateContentStatusBySourceId(String sourceId);
+
+    void deleteGzhWaitingByPlanIdAccountId(String planId, String accountId);
 }

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

@@ -0,0 +1,9 @@
+package com.tzld.longarticle.recommend.server.model.param;
+
+import lombok.Data;
+
+@Data
+public class LongArticleSystemFilterSortContentParam {
+    private String publishContentId;
+    private String filterReason;
+}

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

@@ -0,0 +1,10 @@
+package com.tzld.longarticle.recommend.server.model.param;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class LongArticleSystemFilterSortParam {
+    private List<LongArticleSystemFilterSortContentParam> filterSortContentList;
+}

+ 68 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/aigc/AIGCPublishContentDiscardService.java

@@ -0,0 +1,68 @@
+package com.tzld.longarticle.recommend.server.remote.aigc;
+
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.longarticle.recommend.server.model.param.LongArticleSystemFilterSortParam;
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.*;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.util.concurrent.TimeUnit;
+
+@Service
+@Slf4j
+public class AIGCPublishContentDiscardService {
+
+    private OkHttpClient client;
+
+    @PostConstruct
+    public void init() {
+        client = new OkHttpClient().newBuilder()
+                .connectionPool(new ConnectionPool(20, 5, TimeUnit.MINUTES))
+                .connectTimeout(5, TimeUnit.MINUTES)
+                .readTimeout(5, TimeUnit.MINUTES)
+                .writeTimeout(5, TimeUnit.MINUTES)
+                .build();
+    }
+
+    private static final String filterSortContentsUrl = "http://aigc-api.cybertogether.net/aigc/publish/LongArticleSystem/filterSortContents";
+
+
+    public Boolean filterSortContents(LongArticleSystemFilterSortParam param) {
+        int retryTimes = 2;
+        while (retryTimes > 0) {
+            Boolean result = post(param);
+            if (result) {
+                return true;
+            }
+            retryTimes--;
+        }
+        return false;
+    }
+
+    public Boolean post(LongArticleSystemFilterSortParam param) {
+        Boolean result = false;
+        JSONObject bodyParam = new JSONObject();
+        bodyParam.put("params", param);
+        try {
+            MediaType mediaType = MediaType.parse("application/json");
+            RequestBody body = RequestBody.create(mediaType, JSONObject.toJSONString(bodyParam));
+            Request request = new Request.Builder()
+                    .url(filterSortContentsUrl)
+                    .method("POST", body)
+                    .addHeader("Content-Type", "application/json;charset=UTF-8")
+                    .build();
+            Response response = client.newCall(request).execute();
+            if (response.isSuccessful()) {
+                String responseContent = response.body().string();
+                JSONObject jsonObject = JSONObject.parseObject(responseContent);
+                if (jsonObject.getInteger("code") == 0) {
+                    result = true;
+                }
+            }
+        } catch (Exception e) {
+            log.error("getAllContent error", e);
+        }
+        return result;
+    }
+}

+ 22 - 15
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/XxlJobService.java

@@ -33,14 +33,12 @@ import com.tzld.longarticle.recommend.server.model.entity.crawler.AccountAvgInfo
 import com.tzld.longarticle.recommend.server.model.entity.crawler.GetOffVideoCrawler;
 import com.tzld.longarticle.recommend.server.model.entity.crawler.LongArticlesVideo;
 import com.tzld.longarticle.recommend.server.model.entity.longArticle.*;
-import com.tzld.longarticle.recommend.server.model.param.ArticleFindSourceParam;
-import com.tzld.longarticle.recommend.server.model.param.RecommendParam;
-import com.tzld.longarticle.recommend.server.model.param.RecommendRequest;
-import com.tzld.longarticle.recommend.server.model.param.TitleHisCacheParam;
+import com.tzld.longarticle.recommend.server.model.param.*;
 import com.tzld.longarticle.recommend.server.model.vo.ArticleSortResponseDataItem;
 import com.tzld.longarticle.recommend.server.model.vo.FeishuTableDTO;
 import com.tzld.longarticle.recommend.server.remote.ODPSManager;
 import com.tzld.longarticle.recommend.server.remote.aigc.AIGCProduceContentAuditService;
+import com.tzld.longarticle.recommend.server.remote.aigc.AIGCPublishContentDiscardService;
 import com.tzld.longarticle.recommend.server.remote.aigc.AIGCWaitingPublishContentService;
 import com.tzld.longarticle.recommend.server.repository.aigc.ProducePlanRepository;
 import com.tzld.longarticle.recommend.server.repository.aigc.PublishPlanRepository;
@@ -152,6 +150,8 @@ public class XxlJobService {
     private RecommendService recommendService;
     @Autowired
     private PublishPlanSettingRepository publishPlanSettingRepository;
+    @Autowired
+    private AIGCPublishContentDiscardService aigcPublishContentDiscardService;
 
     @Autowired
     private RedisUtil redisUtil;
@@ -1131,9 +1131,9 @@ public class XxlJobService {
             return;
         }
         List<String> contentIds = contentList.stream().map(Content::getId).collect(Collectors.toList());
-        // 不存在状态置0
+        // 全量更新删除历史所有
         if (findAll) {
-            longArticleBaseMapper.updatePublishContentGzhWaitingStatus(planId, accountId, contentIds, 0, now);
+            longArticleBaseMapper.deleteGzhWaitingByPlanIdAccountId(planId, accountId);
         }
         List<PublishContentGzhWaiting> existList = publishContentGzhWaitingRepository.getByIdIn(contentIds);
         List<String> existContentIds = existList.stream().map(PublishContentGzhWaiting::getId).collect(Collectors.toList());
@@ -1141,16 +1141,8 @@ public class XxlJobService {
                 Collectors.toMap(PublishContentGzhWaiting::getId, Function.identity()));
         List<PublishContentGzhWaiting> saveList = new ArrayList<>();
         for (Content content : contentList) {
-            // 已存在更新
+            // 已存在跳过
             if (existContentIds.contains(content.getId())) {
-                PublishContentGzhWaiting existItem = existMap.get(content.getId());
-                if (existItem.getStatus().equals(0)) {
-                    existItem.setStatus(1);
-                    existItem.setUpdateTimestamp(now);
-                    publishContentGzhWaitingRepository.save(existItem);
-                }
-//                setPublishContentValue(existItem, content, planId, accountId, now);
-//                publishContentGzhWaitingRepository.save(existItem);
                 continue;
             }
             // 新增
@@ -1224,6 +1216,10 @@ public class XxlJobService {
                         log.info("ContentPreFilterJob success index:{} planId: {} accountId: {} filterContent: {}",
                                 finalIndex, item.getPlanId(), item.getAccountId(), filterContentList.size());
                         recommendService.updateWaitingContentFilter(filterContentList);
+                        // 调用aigc publish_content待发布内容状态废弃
+                        LongArticleSystemFilterSortParam param = new LongArticleSystemFilterSortParam();
+                        param.setFilterSortContentList(buildFilterSortContentList(filterResult));
+                        aigcPublishContentDiscardService.filterSortContents(param);
                         success = true;
                     }
                 } catch (Exception e) {
@@ -1247,6 +1243,17 @@ public class XxlJobService {
         return ReturnT.SUCCESS;
     }
 
+    private List<LongArticleSystemFilterSortContentParam> buildFilterSortContentList(FilterResult filterResult) {
+        List<LongArticleSystemFilterSortContentParam> contentList = new ArrayList<>();
+        for (Content filterContent : filterResult.getFilterContent()) {
+            LongArticleSystemFilterSortContentParam item = new LongArticleSystemFilterSortContentParam();
+            item.setPublishContentId(filterContent.getId());
+            item.setFilterReason(filterContent.getFilterReason());
+            contentList.add(item);
+        }
+        return contentList;
+    }
+
     /**
      * 计算长字符串数字余数
      * @param numberStr 长字符串数字

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

@@ -486,4 +486,8 @@
         update publish_content_gzh_waiting set status = 0 where source_id = #{sourceId}
     </update>
 
+    <delete id="deleteGzhWaitingByPlanIdAccountId">
+        delete from publish_content_gzh_waiting where plan_id = #{planId} and publish_account_id = #{accountId}
+    </delete>
+
 </mapper>