ManagerApiService.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.common.enums.ExceptionEnum;
  5. import com.tzld.piaoquan.api.common.exception.CommonException;
  6. import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.beans.factory.annotation.Value;
  10. import org.springframework.stereotype.Component;
  11. import java.util.Objects;
  12. @Slf4j
  13. @Component
  14. public class ManagerApiService {
  15. @Autowired
  16. private HttpPoolClient httpPoolClient;
  17. @Value("${manager.api.host:https://testadmin.piaoquantv.com/manager}")
  18. private String managerApiHost;
  19. public JSONObject videoMultiTitleSave(Long videoId, String title) {
  20. String url = managerApiHost + "/video/multiTitleV2/saveNoAuth";
  21. JSONObject res = null;
  22. try {
  23. JSONObject param = new JSONObject();
  24. param.put("videoId", videoId);
  25. param.put("title", title);
  26. param.put("source", 1);
  27. String post = httpPoolClient.post(url, param.toJSONString());
  28. res = JSONObject.parseObject(post);
  29. } catch (Exception e) {
  30. log.error("ManagerApiService videoMultiTitleSave error, videoId={} title={}",
  31. videoId, title, e);
  32. }
  33. if (Objects.isNull(res)) {
  34. throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_SAVE_FAILED);
  35. }
  36. if (res.getInteger("code") != 0) {
  37. log.error("ManagerApiService videoMultiTitleSave error, videoId={} title={} res={}",
  38. videoId, title, res);
  39. throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_SAVE_FAILED.getCode(),
  40. ExceptionEnum.VIDEO_MULTI_TITLE_SAVE_FAILED.getMsg() + "," + res.getString("msg"));
  41. }
  42. return res.getJSONObject("content");
  43. }
  44. public JSONObject videoMultiCoverSave(Long videoId, String coverUrl) {
  45. String url = managerApiHost + "/video/multiCover/saveNoAuth";
  46. JSONObject res = null;
  47. try {
  48. JSONObject param = new JSONObject();
  49. param.put("videoId", videoId);
  50. param.put("coverUrl", coverUrl);
  51. param.put("source", 1);
  52. String post = httpPoolClient.post(url, param.toJSONString());
  53. res = JSONObject.parseObject(post);
  54. } catch (Exception e) {
  55. log.error("ManagerApiService videoMultiCoverSave error, videoId={} coverUrl={}",
  56. videoId, coverUrl, e);
  57. }
  58. if (Objects.isNull(res)) {
  59. throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_SAVE_FAILED);
  60. }
  61. if (res.getInteger("code") != 0) {
  62. log.error("ManagerApiService videoMultiCoverSave error, videoId={} coverUrl={} res={}",
  63. videoId, coverUrl, res);
  64. throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_SAVE_FAILED.getCode(),
  65. ExceptionEnum.VIDEO_MULTI_COVER_SAVE_FAILED.getMsg() + "," + res.getString("msg"));
  66. }
  67. return res.getJSONObject("content");
  68. }
  69. public JSONArray videoMultiCoverListV2(Long videoId) {
  70. String url = managerApiHost + "/video/multiCover/listV2";
  71. JSONObject res = null;
  72. try {
  73. JSONObject param = new JSONObject();
  74. param.put("videoId", videoId);
  75. param.put("range", "2h");
  76. String post = httpPoolClient.post(url, param.toJSONString());
  77. res = JSONObject.parseObject(post);
  78. } catch (Exception e) {
  79. log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}",
  80. videoId, "2h", e);
  81. }
  82. if (Objects.isNull(res)) {
  83. throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_LIST_FAILED);
  84. }
  85. if (res.getInteger("code") != 0) {
  86. log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={} res={}",
  87. videoId, "2h", res);
  88. throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_LIST_FAILED.getCode(),
  89. ExceptionEnum.VIDEO_MULTI_COVER_LIST_FAILED.getMsg() + "," + res.getString("msg"));
  90. }
  91. return res.getJSONArray("content");
  92. }
  93. public JSONArray videoMultiTitleListV2(Long videoId) {
  94. String url = managerApiHost + "/video/multiTitleV2/listV2";
  95. JSONObject res = null;
  96. try {
  97. JSONObject param = new JSONObject();
  98. param.put("videoId", videoId);
  99. param.put("range", "4h");
  100. String post = httpPoolClient.post(url, param.toJSONString());
  101. res = JSONObject.parseObject(post);
  102. } catch (Exception e) {
  103. log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}",
  104. videoId, "4h", e);
  105. }
  106. if (Objects.isNull(res)) {
  107. throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED);
  108. }
  109. if (res.getInteger("code") != 0) {
  110. log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={} res={}",
  111. videoId, "4h", res);
  112. throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED.getCode(),
  113. ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED.getMsg() + "," + res.getString("msg"));
  114. }
  115. return res.getJSONArray("content");
  116. }
  117. }