|
@@ -2,6 +2,7 @@ package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
|
|
|
import cn.com.ctop.job.bytedance.data.constant.BytedanceConstant;
|
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedanceFileVideoGet;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.BytedanceMaterialAttributes;
|
|
|
import cn.com.ctop.job.bytedance.data.entity.OauthToken;
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedanceFileVideoGetMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceFileVideoGetService;
|
|
@@ -35,7 +36,7 @@ public class BytedanceFileVideoGetServiceImpl implements IBytedanceFileVideoGetS
|
|
|
BytedanceFileVideoGetMapper bytedanceFileVideoGetMapper;
|
|
|
|
|
|
@Override
|
|
|
- public void getFileVideoData(OauthToken oauthToken, String startDate,String endDate,int page, int pageSize) {
|
|
|
+ public void getFileVideoData(OauthToken oauthToken, String startDate, String endDate, int page, int pageSize) {
|
|
|
log.info("开始获取视频素材 accountID:{},page:{}", oauthToken.getAccountId(), page);
|
|
|
// 请求地址
|
|
|
String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_FILE_VIDEO_GET;
|
|
@@ -45,13 +46,13 @@ public class BytedanceFileVideoGetServiceImpl implements IBytedanceFileVideoGetS
|
|
|
param.put("page", page);
|
|
|
param.put("page_size", pageSize);
|
|
|
JSONObject param2 = new JSONObject();
|
|
|
- if (!Check.isNull(startDate)){
|
|
|
- param2.put("start_time",startDate);
|
|
|
+ if (!Check.isNull(startDate)) {
|
|
|
+ param2.put("start_time", startDate);
|
|
|
}
|
|
|
- if (!Check.isNull(endDate)){
|
|
|
- param2.put("end_time",endDate);
|
|
|
+ if (!Check.isNull(endDate)) {
|
|
|
+ param2.put("end_time", endDate);
|
|
|
}
|
|
|
- param.put("filtering",param2);
|
|
|
+ param.put("filtering", param2);
|
|
|
JSONObject resultObject = HttpUtils.bytedanceGetRequest(oauthToken.getAccessToken(), url, param);
|
|
|
|
|
|
Integer code = resultObject.getInteger("code");
|
|
@@ -80,26 +81,24 @@ public class BytedanceFileVideoGetServiceImpl implements IBytedanceFileVideoGetS
|
|
|
page++;
|
|
|
int totalPage = resultObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
if (page <= totalPage) {
|
|
|
- getFileVideoData(oauthToken,startDate, endDate,page, 100);
|
|
|
+ getFileVideoData(oauthToken, startDate, endDate, page, 100);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
- * @description: 根据账户获取视频素材-账户/素材id 下全部视频素材
|
|
|
- *
|
|
|
* @param oauthToken
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
- * @return: java.util.Map<java.lang.String,java.lang.String>
|
|
|
+ * @description: 根据账户获取视频素材-账户/素材id 下全部视频素材
|
|
|
+ * @return: java.util.Map<java.lang.String, java.lang.String>
|
|
|
* @author: zianY
|
|
|
* @time: 2022/2/9
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map<String,String> getBytedanceVideoByAccountId(OauthToken oauthToken,List<Long> materialIds,int page, int pageSize) {
|
|
|
- Map<String,String> resultMap = new HashMap<>();
|
|
|
- log.info("调用接口------getBytedanceVideoByAccountId----根据账户获取视频素材---账户--{}===第{}页===》》》",oauthToken.getAccountId(),page);
|
|
|
+ public Map<String, String> getBytedanceVideoByAccountId(OauthToken oauthToken, List<Long> materialIds, int page, int pageSize) {
|
|
|
+ Map<String, String> resultMap = new HashMap<>();
|
|
|
+ log.info("调用接口------getBytedanceVideoByAccountId----根据账户获取视频素材---账户--{}===第{}页===》》》", oauthToken.getAccountId(), page);
|
|
|
// 请求地址
|
|
|
String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_FILE_VIDEO_GET;
|
|
|
JSONObject param = new JSONObject();
|
|
@@ -108,8 +107,8 @@ public class BytedanceFileVideoGetServiceImpl implements IBytedanceFileVideoGetS
|
|
|
param.put("page_size", pageSize);
|
|
|
|
|
|
JSONObject param2 = new JSONObject();
|
|
|
- if (!Check.isNull(materialIds)){
|
|
|
- param2.put("material_ids",materialIds);
|
|
|
+ if (!Check.isNull(materialIds)) {
|
|
|
+ param2.put("material_ids", materialIds);
|
|
|
}
|
|
|
/* if (!Check.isNull(startDate)){
|
|
|
param2.put("start_time",startDate);
|
|
@@ -118,20 +117,20 @@ public class BytedanceFileVideoGetServiceImpl implements IBytedanceFileVideoGetS
|
|
|
param2.put("end_time",endDate);
|
|
|
}
|
|
|
*/
|
|
|
- param.put("filtering",param2);
|
|
|
+ param.put("filtering", param2);
|
|
|
|
|
|
JSONObject resultObject = HttpUtils.bytedanceGetRequest(oauthToken.getAccessToken(), url, param);
|
|
|
Integer code = resultObject.getInteger("code");
|
|
|
if (null == code || !code.equals(0)) {
|
|
|
log.error("获取视频素材接口异常==》accountId:{},message:{}", oauthToken.getAccountId(), resultObject.getString("message"));
|
|
|
- resultMap.put("code","1");
|
|
|
- resultMap.put("message","获取视频素材接口异常!账户:"+oauthToken.getAccountId()+"-----error:"+resultObject.getString("message"));
|
|
|
+ resultMap.put("code", "1");
|
|
|
+ resultMap.put("message", "获取视频素材接口异常!账户:" + oauthToken.getAccountId() + "-----error:" + resultObject.getString("message"));
|
|
|
return resultMap;
|
|
|
}
|
|
|
JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
|
|
|
if (null == data || data.isEmpty()) {
|
|
|
- resultMap.put("code","0");
|
|
|
- resultMap.put("message","获取视频素材数据为空");
|
|
|
+ resultMap.put("code", "0");
|
|
|
+ resultMap.put("message", "获取视频素材数据为空");
|
|
|
return resultMap;
|
|
|
}
|
|
|
List<BytedanceFileVideoGet> list = new ArrayList<>();
|
|
@@ -144,8 +143,8 @@ public class BytedanceFileVideoGetServiceImpl implements IBytedanceFileVideoGetS
|
|
|
list.add(report);
|
|
|
} catch (Exception e) {
|
|
|
log.info("错误:{}", e.toString());
|
|
|
- resultMap.put("code","500");
|
|
|
- resultMap.put("message","哎呀,网络不给力。"+e.toString());
|
|
|
+ resultMap.put("code", "500");
|
|
|
+ resultMap.put("message", "哎呀,网络不给力。" + e.toString());
|
|
|
return resultMap;
|
|
|
}
|
|
|
}
|
|
@@ -153,11 +152,61 @@ public class BytedanceFileVideoGetServiceImpl implements IBytedanceFileVideoGetS
|
|
|
page++;
|
|
|
int totalPage = resultObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
if (page <= totalPage) {
|
|
|
- getBytedanceVideoByAccountId(oauthToken,materialIds,page, 100);
|
|
|
+ getBytedanceVideoByAccountId(oauthToken, materialIds, page, 100);
|
|
|
}
|
|
|
- resultMap.put("code","0");
|
|
|
- resultMap.put("message","success");
|
|
|
+ resultMap.put("code", "0");
|
|
|
+ resultMap.put("message", "success");
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getMaterialAttributesData(OauthToken oauthToken, String startDate, String endDate, int page) {
|
|
|
+ log.info("获取视频素材评估标签(新版) accountID:{},page:{}", oauthToken.getAccountId(), page);
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_MATERIAL_ATTRIBUTES;
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+
|
|
|
+ param.put("account_id", oauthToken.getAccountId());
|
|
|
+ param.put("account_type", "AD");
|
|
|
+ param.put("page", page);
|
|
|
+ param.put("page_size", 100);
|
|
|
+ JSONObject filtering = new JSONObject();
|
|
|
+ if (!Check.isNull(startDate)) {
|
|
|
+ filtering.put("start_time", startDate + " 00:00:00");
|
|
|
+ }
|
|
|
+ if (!Check.isNull(endDate)) {
|
|
|
+ filtering.put("end_time", endDate + " 23:59:59");
|
|
|
+ }
|
|
|
+ List<String> material_properties = new ArrayList<>();
|
|
|
+ material_properties.add("FIRST_PUBLISH_MATERIAL");
|
|
|
+ material_properties.add("AD_HIGH_QUALITY_MATERIAL");
|
|
|
+ filtering.put("material_properties", material_properties);
|
|
|
+ param.put("filtering", filtering);
|
|
|
+ JSONObject resultObject = HttpUtils.bytedanceGetRequest(oauthToken.getAccessToken(), url, param);
|
|
|
+// System.out.println(resultObject);
|
|
|
+ Integer code = resultObject.getInteger("code");
|
|
|
+ if (null == code || !code.equals(0)) {
|
|
|
+ log.error("获取视频素材评估标签(新版)接口异常==》accountId:{},message:{}", oauthToken.getAccountId(), resultObject);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray materials = resultObject.getJSONObject("data").getJSONArray("materials");
|
|
|
+ if (null == materials || materials.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<BytedanceMaterialAttributes> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < materials.size(); i++) {
|
|
|
+ JSONObject dataObject = materials.getJSONObject(i);
|
|
|
+ BytedanceMaterialAttributes report = JSONObject.parseObject(dataObject.toJSONString(), BytedanceMaterialAttributes.class);
|
|
|
+ list.add(report);
|
|
|
+ }
|
|
|
+ bytedanceFileVideoGetMapper.insertMaterialAttributesData(list);
|
|
|
+ page++;
|
|
|
+ int totalPage = resultObject.getJSONObject("data").getJSONObject("page").getInteger("total_page");
|
|
|
+ if (page <= totalPage) {
|
|
|
+ getMaterialAttributesData(oauthToken, startDate, endDate, page);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|