wangyunpeng vor 11 Monaten
Ursprung
Commit
3e4844228d

+ 15 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/remote/Article.java

@@ -0,0 +1,15 @@
+package com.tzld.longarticle.recommend.server.model.remote;
+
+import lombok.Data;
+
+@Data
+public class Article {
+
+    private String title;
+    private Integer itemIndex;
+    private Integer showViewCount;
+    private String contentURL;
+    private String msgTime;
+
+}
+

+ 77 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/ArticleListRemoteService.java

@@ -0,0 +1,77 @@
+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.remote.Article;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.http.HttpEntity;
+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.apache.http.util.EntityUtils;
+import org.springframework.stereotype.Service;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+
+@Service
+@Slf4j
+public class ArticleListRemoteService {
+
+    private final CloseableHttpClient client = HttpPoolFactory.defaultPool();
+    private static final String articleListUrl = "http://192.168.100.31:8179/artlce_list";
+
+    public List<Article> articleList(String accountName, List<Integer> indexList) {
+        long start = System.currentTimeMillis();
+        List<String> keys = Arrays.asList("Title",
+                "ItemIndex",
+                "show_view_count",
+                "ContentUrl",
+                "msg_time");
+        JSONObject bodyParam = new JSONObject();
+        bodyParam.put("account_nickname", accountName);
+        bodyParam.put("filter_same", false);
+        bodyParam.put("filter_sensitive", false);
+        bodyParam.put("index_list", indexList);
+        bodyParam.put("keys", keys);
+        bodyParam.put("msg_type", 9);
+        bodyParam.put("rate", 0.1);
+        bodyParam.put("reverse", true);
+        bodyParam.put("top_n", 10000);
+        bodyParam.put("use_max_time", true);
+        bodyParam.put("use_min_time", true);
+        try {
+            HttpPost httpPost = new HttpPost(articleListUrl);
+            StringEntity stringEntity = new StringEntity(bodyParam.toJSONString(), StandardCharsets.UTF_8);
+            httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
+            httpPost.setEntity(stringEntity);
+            CloseableHttpResponse response = client.execute(httpPost);
+            StatusLine statusLine = response.getStatusLine();
+            if (statusLine.getStatusCode() == 200) {
+                HttpEntity responseEntity = response.getEntity();
+                if (Objects.nonNull(responseEntity)) {
+                    String responseBody = EntityUtils.toString(responseEntity, "UTF-8");
+                    log.info("articleList 返回的数据:{}", responseBody);
+                    JSONObject articleListResponse = JSONObject.parseObject(responseBody);
+                    if (Objects.nonNull(articleListResponse)) {
+                        JSONArray articleList = articleListResponse.getJSONArray("article_list");
+                        if (CollectionUtils.isNotEmpty(articleList)) {
+                            return articleList.toJavaList(Article.class);
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("articleList error", e);
+        }
+        log.info("articleList耗时:{}", System.currentTimeMillis() - start);
+        return null;
+    }
+
+}

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

@@ -10,5 +10,6 @@ import java.util.List;
  */
 @Data
 public class FilterParam {
+    private String accountName;
     private List<Content> contents;
 }

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/FilterParamFactory.java

@@ -11,6 +11,8 @@ import java.util.List;
 public class FilterParamFactory {
     public static FilterParam create(RecallParam param, List<Content> contents) {
         FilterParam filterParam = new FilterParam();
+        filterParam.setAccountName(param.getAccountName());
+        filterParam.setContents(contents);
         return filterParam;
     }
 }

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

@@ -8,6 +8,7 @@ import lombok.Data;
 @Data
 public class RecallParam {
     private String accountId;
+    private String accountName;
     private Integer publishNum;
     private String planId;
 }