AdApiService.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package com.tzld.piaoquan.api.component;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.tzld.piaoquan.api.model.bo.AdPutCreativeComponentCostData;
  5. import com.tzld.piaoquan.api.model.bo.AdPutFlowRecordTencent;
  6. import com.tzld.piaoquan.api.model.bo.AdPutTencentCreative;
  7. import com.tzld.piaoquan.api.model.bo.AdPutTencentCreativeAnalysis;
  8. import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.beans.factory.annotation.Value;
  12. import org.springframework.stereotype.Component;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. import java.util.Objects;
  16. @Component
  17. @Slf4j
  18. public class AdApiService {
  19. @Autowired
  20. private HttpPoolClient httpPoolClient;
  21. @Value("${ad.api.host:https://testapi.piaoquantv.com/ad}")
  22. private String adApiHost;
  23. public Integer getPutFlowListTencentCount(String channel, Integer pageNum, Integer pageSize) {
  24. String url = adApiHost + "/put/flow/list/tencent?videoId=&putScene=&channel="
  25. + channel + "&currentPage=" + pageNum + "&pageSize=" + pageSize;
  26. try {
  27. String post = httpPoolClient.get(url);
  28. JSONObject res = JSONObject.parseObject(post);
  29. return res.getJSONObject("data").getInteger("totalSize");
  30. } catch (Exception e) {
  31. log.error("getPutFlowListTencentCount error", e);
  32. }
  33. return 0;
  34. }
  35. public List<AdPutFlowRecordTencent> getPutFlowListTencent(String channel, Integer pageNum, Integer pageSize) {
  36. String url = adApiHost + "/put/flow/list/tencent?videoId=&putScene=&channel="
  37. + channel + "&currentPage=" + pageNum + "&pageSize=" + pageSize;
  38. try {
  39. String post = httpPoolClient.get(url);
  40. JSONObject res = JSONObject.parseObject(post);
  41. JSONArray data = res.getJSONObject("data").getJSONArray("objs");
  42. if (Objects.nonNull(data) && !data.isEmpty()) {
  43. return data.toJavaList(AdPutFlowRecordTencent.class);
  44. }
  45. } catch (Exception e) {
  46. log.error("getPutFlowListTencent error", e);
  47. }
  48. return new ArrayList<>();
  49. }
  50. /**
  51. * 获取投放广告创意花费
  52. * @param dt 2025-12-23
  53. * @return
  54. */
  55. public List<AdPutCreativeComponentCostData> getCreativeComponentsCost(String dt) {
  56. String url = "https://api.piaoquantv.com/ad" + "/put/tencent/getCreativeComponentsCost?dt=" + dt;
  57. try {
  58. String post = httpPoolClient.get(url);
  59. JSONObject res = JSONObject.parseObject(post);
  60. JSONArray data = res.getJSONArray("data");
  61. if (Objects.nonNull(data) && !data.isEmpty()) {
  62. return data.toJavaList(AdPutCreativeComponentCostData.class);
  63. }
  64. } catch (Exception e) {
  65. log.error("getPutFlowListTencent error", e);
  66. }
  67. return new ArrayList<>();
  68. }
  69. /**
  70. * 根据rootSourceId获取创意信息
  71. */
  72. public AdPutTencentCreative getCreativeByRootSourceId(String rootSourceId) {
  73. try {
  74. String url = adApiHost + "/put/tencent/getCreativeByRootSourceId?rootSourceId=" + rootSourceId;
  75. String response = httpPoolClient.get(url);
  76. JSONObject res = JSONObject.parseObject(response);
  77. if (res.getInteger("code") == 0 && res.getJSONObject("data") != null) {
  78. return res.getJSONObject("data").toJavaObject(AdPutTencentCreative.class);
  79. }
  80. } catch (Exception e) {
  81. log.error("获取创意信息失败, rootSourceId={}", rootSourceId, e);
  82. }
  83. return null;
  84. }
  85. /**
  86. * 根据创意ID获取素材分析信息
  87. */
  88. public AdPutTencentCreativeAnalysis getCreativeAnalysis(Long creativeId) {
  89. try {
  90. String url = adApiHost + "/put/tencent/getCreativeAnalysis?creativeId=" + creativeId;
  91. String response = httpPoolClient.get(url);
  92. JSONObject res = JSONObject.parseObject(response);
  93. if (res.getInteger("code") == 0 && res.getJSONObject("data") != null) {
  94. return res.getJSONObject("data").toJavaObject(AdPutTencentCreativeAnalysis.class);
  95. }
  96. } catch (Exception e) {
  97. log.error("获取素材分析信息失败, creativeId={}", creativeId, e);
  98. }
  99. return null;
  100. }
  101. /**
  102. * 根据创意ID获取人群包ID
  103. */
  104. public List<Long> getPackageIdByAdId(Long adId) {
  105. try {
  106. String url = adApiHost + "/put/tencent/getPackageIdByAdId?adId=" + adId;
  107. String response = httpPoolClient.get(url);
  108. JSONObject res = JSONObject.parseObject(response);
  109. if (res.getInteger("code") == 0 && res.getJSONObject("data") != null) {
  110. return res.getJSONObject("data").getJSONArray("packageId").toJavaList(Long.class);
  111. }
  112. } catch (Exception e) {
  113. log.error("获取人群包信息失败, adId={}", adId, e);
  114. }
  115. return null;
  116. }
  117. }