wangyunpeng hai 11 meses
pai
achega
4b1cd28652

+ 39 - 6
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/AIGCRemoteService.java

@@ -1,12 +1,19 @@
 package com.tzld.longarticle.recommend.server.remote;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.tzld.longarticle.recommend.server.common.HttpPoolFactory;
 import com.tzld.longarticle.recommend.server.model.Content;
+import com.tzld.longarticle.recommend.server.service.recall.RecallParam;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.http.StatusLine;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.springframework.stereotype.Service;
 
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -16,14 +23,40 @@ import java.util.List;
 @Slf4j
 public class AIGCRemoteService {
     private final CloseableHttpClient client = HttpPoolFactory.defaultPool();
-    private String aigcGetAllContentUrl;
+    private static final String aigcGetAllContentUrl = "http://aigc-api.cybertogether.net/aigc/publish/content/gzhWaitingPublishContent";
 
 
     // TODO 如果过滤失败,那么认为所有视频都被过滤掉
-    public List<Content> getAllContent() {
-
-        // 调用AIGC
-        return Collections.emptyList();
+    public List<Content> getAllContent(RecallParam param) {
+        long start = System.currentTimeMillis();
+        List<Content> result = new ArrayList<>();
+        JSONObject bodyParam = new JSONObject();
+        JSONObject bodyParamParams = new JSONObject();
+        bodyParamParams.put("accountId", param.getAccountId());
+        bodyParamParams.put("planId", param.getPlanId());
+        bodyParam.put("params", bodyParamParams);
+        try {
+            HttpPost httpPost = new HttpPost(aigcGetAllContentUrl);
+            StringEntity stringEntity = new StringEntity(bodyParam.toJSONString());
+            stringEntity.setContentType("application/json");
+            stringEntity.setContentEncoding("UTF-8");
+            httpPost.setEntity(stringEntity);
+            CloseableHttpResponse response22 = client.execute(httpPost);
+            StatusLine statusLine = response22.getStatusLine();
+            if (statusLine.getStatusCode() == 200) {
+                String responseBody = response22.getEntity().getContent().toString();
+                log.info("getAllContent AIGC返回的数据:{}", responseBody);
+                JSONObject jsonObject = JSONObject.parseObject(responseBody);
+                if (jsonObject.getInteger("code") == 0) {
+                    JSONArray data = jsonObject.getJSONArray("data");
+                    result.addAll(JSONArray.parseArray(data.toJSONString(), Content.class));
+                }
+            }
+        } catch (Exception e) {
+            log.error("getAllContent error", e);
+        }
+        log.info("getAllContent耗时:{}", System.currentTimeMillis() - start);
+        return result;
     }
 
 }

+ 6 - 6
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/RecommendParam.java

@@ -1,14 +1,9 @@
 package com.tzld.longarticle.recommend.server.service;
 
-import com.alibaba.fastjson.annotation.JSONField;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
 
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 /**
  * @author dyp
  */
@@ -17,6 +12,11 @@ import java.util.Set;
 @Getter
 @Setter
 public class RecommendParam {
-
+    private String accountId;
+    private String accountName;
+    private String ghId;
+    private String strategy;
+    private Integer publishNum;
+    private String planId;
 }
 

+ 3 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/RecommendService.java

@@ -9,6 +9,7 @@ import com.tzld.longarticle.recommend.server.service.recall.RecallParam;
 import com.tzld.longarticle.recommend.server.service.recall.RecallResult;
 import com.tzld.longarticle.recommend.server.service.recall.RecallService;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -19,15 +20,12 @@ import org.springframework.stereotype.Service;
 @Slf4j
 public class RecommendService {
 
-
     @Autowired
     private RecallService recallService;
     @Autowired
     private RankService rankService;
 
 
-
-
     public RecommendResponse recommend(RecommendRequest request) {
 
         RecommendParam param = genRecommendParam(request);
@@ -43,11 +41,13 @@ public class RecommendService {
 
     public RecommendParam genRecommendParam(RecommendRequest request) {
         RecommendParam param = new RecommendParam();
+        BeanUtils.copyProperties(request, param);
         return param;
     }
 
     public RecallParam convertToRecallParam(RecommendParam param) {
         RecallParam recallParam = new RecallParam();
+        BeanUtils.copyProperties(param, recallParam);
         return recallParam;
     }
 

+ 3 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/RecallParam.java

@@ -7,5 +7,7 @@ import lombok.Data;
  */
 @Data
 public class RecallParam {
-
+    private String accountId;
+    private Integer publishNum;
+    private String planId;
 }

+ 4 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/strategy/DefaultRecallStrategy.java

@@ -11,8 +11,8 @@ import com.tzld.longarticle.recommend.server.service.recall.RecallStrategy;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author dyp
@@ -28,14 +28,14 @@ public class DefaultRecallStrategy implements RecallStrategy {
     @Override
     public List<Content> recall(RecallParam param) {
 
-        List<Content> content = aigcRemoteService.getAllContent();
+        List<Content> content = aigcRemoteService.getAllContent(param);
         // 处理 content
         FilterParam filterParam = FilterParamFactory.create(param, content);
         FilterResult filterResult = filterService.filter(filterParam);
         // 处理 content
 
-        List<Content> videosResult = new ArrayList<>();
-        return videosResult;
+        return content.stream().filter(o -> !filterResult.getContentIds().contains(o.getId()))
+                .collect(Collectors.toList());
     }
 
 }

+ 0 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/RecommendV2Controller.java

@@ -21,7 +21,6 @@ public class RecommendV2Controller {
 
     @RequestMapping("/recommend")
     public String homepageRecommend(@RequestBody RecommendRequest httpRequest) {
-        // API写这里,给AIGC提供
         RecommendResponse response = recommendService.recommend(httpRequest);
 
         return JSONUtils.toJson(response);

+ 31 - 0
long-article-recommend-service/src/test/java/com/tzld/longarticle/recommend/server/RecommendTest.java

@@ -0,0 +1,31 @@
+package com.tzld.longarticle.recommend.server;
+
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.longarticle.recommend.server.service.RecommendService;
+import com.tzld.longarticle.recommend.server.service.recall.RecallParam;
+import com.tzld.longarticle.recommend.server.service.recall.RecallResult;
+import com.tzld.longarticle.recommend.server.service.recall.RecallService;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import javax.annotation.Resource;
+
+@SpringBootTest(classes = RecommendTest.class)
+public class RecommendTest {
+
+    @Resource
+    private RecommendService recommendService;
+    @Resource
+    private RecallService recallService;
+
+
+    @Test
+    void recall() {
+        RecallParam param = new RecallParam();
+        param.setAccountId("20231213123536190184852");
+        param.setPlanId("20240718181730864154902");
+        RecallResult recallResult = recallService.recall(param);
+        System.out.println(JSONObject.toJSONString(recallResult));
+    }
+
+}