|
@@ -13,19 +13,33 @@ 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.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
|
|
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.*;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class ArticleListRemoteService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ NamedParameterJdbcTemplate piaoquanCrawlerJdbcTemplate;
|
|
|
+
|
|
|
private final CloseableHttpClient client = HttpPoolFactory.aigcPool();
|
|
|
private static final String articleListUrl = "http://61.48.133.26:8179/artlce_list";
|
|
|
|
|
|
public List<Article> articleList(String accountName, List<Integer> indexList) {
|
|
|
+ return getArticleListByDB(accountName, indexList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Article> getArticleListByApi(String accountName, List<Integer> indexList) {
|
|
|
long start = System.currentTimeMillis();
|
|
|
List<String> keys = Arrays.asList("Title",
|
|
|
"ItemIndex",
|
|
@@ -78,4 +92,16 @@ public class ArticleListRemoteService {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private List<Article> getArticleListByDB(String accountName, List<Integer> indexList) {
|
|
|
+ MapSqlParameterSource parameters = new MapSqlParameterSource();
|
|
|
+ parameters.addValue("accountName", accountName);
|
|
|
+ parameters.addValue("indexList", indexList);
|
|
|
+ List<Article> result = piaoquanCrawlerJdbcTemplate.query(
|
|
|
+ "select title from official_articles where accountName = :accountName and itemIndex in (:indexList) and type = 9",
|
|
|
+ parameters,
|
|
|
+ new BeanPropertyRowMapper<>(Article.class));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|