package com.tzld.piaoquan.api.component; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.tzld.piaoquan.api.common.enums.ExceptionEnum; import com.tzld.piaoquan.api.common.exception.CommonException; 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; import java.util.Objects; @Slf4j @Component public class ManagerApiService { @Autowired private HttpPoolClient httpPoolClient; @Value("${manager.api.host:https://testadmin.piaoquantv.com/manager}") private String managerApiHost; public JSONObject videoMultiTitleSave(Long videoId, String title) { String url = managerApiHost + "/video/multiTitleV2/saveNoAuth"; JSONObject res = null; try { JSONObject param = new JSONObject(); param.put("videoId", videoId); param.put("title", title); param.put("source", 1); String post = httpPoolClient.post(url, param.toJSONString()); res = JSONObject.parseObject(post); } catch (Exception e) { log.error("ManagerApiService videoMultiTitleSave error, videoId={} title={}", videoId, title, e); } if (Objects.isNull(res)) { throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_SAVE_FAILED); } if (res.getInteger("code") != 0) { log.error("ManagerApiService videoMultiTitleSave error, videoId={} title={} res={}", videoId, title, res); throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_SAVE_FAILED.getCode(), ExceptionEnum.VIDEO_MULTI_TITLE_SAVE_FAILED.getMsg() + "," + res.getString("msg")); } return res.getJSONObject("content"); } public JSONObject videoMultiCoverSave(Long videoId, String coverUrl) { String url = managerApiHost + "/video/multiCover/saveNoAuth"; JSONObject res = null; try { JSONObject param = new JSONObject(); param.put("videoId", videoId); param.put("coverUrl", coverUrl); param.put("source", 1); String post = httpPoolClient.post(url, param.toJSONString()); res = JSONObject.parseObject(post); } catch (Exception e) { log.error("ManagerApiService videoMultiCoverSave error, videoId={} coverUrl={}", videoId, coverUrl, e); } if (Objects.isNull(res)) { throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_SAVE_FAILED); } if (res.getInteger("code") != 0) { log.error("ManagerApiService videoMultiCoverSave error, videoId={} coverUrl={} res={}", videoId, coverUrl, res); throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_SAVE_FAILED.getCode(), ExceptionEnum.VIDEO_MULTI_COVER_SAVE_FAILED.getMsg() + "," + res.getString("msg")); } return res.getJSONObject("content"); } public JSONArray videoMultiCoverListV2(Long videoId) { String url = managerApiHost + "/video/multiCover/listV2"; JSONObject res = null; try { JSONObject param = new JSONObject(); param.put("videoId", videoId); param.put("range", "2h"); String post = httpPoolClient.post(url, param.toJSONString()); res = JSONObject.parseObject(post); } catch (Exception e) { log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}", videoId, "2h", e); } if (Objects.isNull(res)) { throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_LIST_FAILED); } if (res.getInteger("code") != 0) { log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={} res={}", videoId, "2h", res); throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_LIST_FAILED.getCode(), ExceptionEnum.VIDEO_MULTI_COVER_LIST_FAILED.getMsg() + "," + res.getString("msg")); } return res.getJSONArray("content"); } public JSONArray videoMultiTitleListV2(Long videoId) { String url = managerApiHost + "/video/multiTitleV2/listV2"; JSONObject res = null; try { JSONObject param = new JSONObject(); param.put("videoId", videoId); param.put("range", "4h"); String post = httpPoolClient.post(url, param.toJSONString()); res = JSONObject.parseObject(post); } catch (Exception e) { log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}", videoId, "4h", e); } if (Objects.isNull(res)) { throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED); } if (res.getInteger("code") != 0) { log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={} res={}", videoId, "4h", res); throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED.getCode(), ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED.getMsg() + "," + res.getString("msg")); } return res.getJSONArray("content"); } }