| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package com.tzld.piaoquan.api.component;
- import com.alibaba.fastjson.JSONObject;
- import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Component;
- /**
- * 推荐API服务
- */
- @Component
- @Slf4j
- public class RecommendApiService {
- @Autowired
- private HttpPoolClient httpPoolClient;
- @Value("${recommend.api.host:http://101.37.174.139:80}")
- private String recommendApiHost;
- /**
- * 根据rootSourceId获取文章信息
- */
- public JSONObject getArticleByRootSourceId(String rootSourceId) {
- try {
- String url = recommendApiHost + "/article/getArticleByRootSourceId?rootSourceId=" + rootSourceId;
- String response = httpPoolClient.get(url);
- JSONObject res = JSONObject.parseObject(response);
- if (res.getInteger("code") == 0 && res.getJSONObject("data") != null) {
- return res.getJSONObject("data");
- }
- } catch (Exception e) {
- log.error("获取文章信息失败, rootSourceId={}", rootSourceId, e);
- }
- return null;
- }
- /**
- * 根据rootSourceId获取合作方文章信息
- */
- public String getCooperateArticleIdByRootSourceId(String rootSourceId) {
- try {
- String url = recommendApiHost + "/article/cooperate/getArticleIdByRootSourceId?rootSourceId=" + rootSourceId;
- String response = httpPoolClient.get(url);
- JSONObject res = JSONObject.parseObject(response);
- if (res.getInteger("code") == 0 && res.getString("data") != null) {
- return res.getString("data");
- }
- } catch (Exception e) {
- log.error("获取文章信息失败, rootSourceId={}", rootSourceId, e);
- }
- return null;
- }
- /**
- * 检查rootSourceId是否存在
- */
- public Boolean checkExistRootSourceId(String rootSourceId) {
- try {
- String url = recommendApiHost + "/api/checkExistRootSourceId?rootSourceId=" + rootSourceId;
- String response = httpPoolClient.get(url);
- JSONObject res = JSONObject.parseObject(response);
- if (res != null && res.getInteger("code") == 0) {
- return res.getBoolean("data");
- }
- } catch (Exception e) {
- log.error("检查rootSourceId是否存在失败, rootSourceId={}", rootSourceId, e);
- }
- return false;
- }
- }
|