|
@@ -5,19 +5,25 @@ import cn.com.ctop.job.kuaishou.data.entity.KuaishouVideoList;
|
|
|
import cn.com.ctop.job.kuaishou.data.enums.MaterialEnum;
|
|
|
import cn.com.ctop.job.kuaishou.data.mapper.KuaishouVideoListMapper;
|
|
|
import cn.com.ctop.job.kuaishou.data.service.IKuaishouVideoListService;
|
|
|
+import cn.com.ctop.job.kuaishou.data.service.IOauthTokenService;
|
|
|
import cn.com.ctop.job.kuaishou.data.utils.Check;
|
|
|
import cn.com.ctop.job.kuaishou.data.utils.HttpUtils;
|
|
|
import cn.com.ctop.job.kuaishou.utils.RedisUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
@@ -33,6 +39,8 @@ public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListM
|
|
|
@Value("${api.kuaishou.postUrl}")
|
|
|
private String postUrl;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IOauthTokenService tokenService;
|
|
|
@Resource
|
|
|
private KuaishouVideoListMapper videoListMapper;
|
|
|
|
|
@@ -46,7 +54,7 @@ public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListM
|
|
|
|
|
|
log.info("开始获取所有视频信息 accountID:{},page:{}", advertiserId, page);
|
|
|
|
|
|
- List<Object> adAccountList = redisUtil.getList("kuaiShou:allVideo:list",null);
|
|
|
+ List<Object> adAccountList = redisUtil.getList("kuaiShou:allVideo:list", null);
|
|
|
|
|
|
String url = postUrl + KuaishouConstant.VIDEO_LIST;
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
@@ -71,19 +79,19 @@ public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListM
|
|
|
log.error("获取快手视频列表数据异常:{},accountId:{}", message, advertiserId);
|
|
|
|
|
|
//请求过于频繁
|
|
|
- if (400001 == code){
|
|
|
- log.info("定时任务-->>allVideoList<<<<----获取所有快手视频请求频繁,code:{},准备重试,accountId:{},错误消息:{}",code,advertiserId,message);
|
|
|
+ if (400001 == code) {
|
|
|
+ log.info("定时任务-->>allVideoList<<<<----获取所有快手视频请求频繁,code:{},准备重试,accountId:{},错误消息:{}", code, advertiserId, message);
|
|
|
//添加重试
|
|
|
- if (Check.isNull(adAccountList)){
|
|
|
+ if (Check.isNull(adAccountList)) {
|
|
|
redisUtil.add("kuaiShou:allVideo:list", Arrays.asList(advertiserId), 1, TimeUnit.HOURS);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
adAccountList.add(advertiserId);
|
|
|
- redisUtil.add("kuaiShou:allVideo:list",adAccountList, 1, TimeUnit.HOURS);
|
|
|
+ redisUtil.add("kuaiShou:allVideo:list", adAccountList, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
- }else {
|
|
|
- if (adAccountList.contains(advertiserId)){
|
|
|
+ } else {
|
|
|
+ if (adAccountList.contains(advertiserId)) {
|
|
|
adAccountList.remove(advertiserId);
|
|
|
- redisUtil.add("kuaiShou:allVideo:list",advertiserId, 1, TimeUnit.HOURS);
|
|
|
+ redisUtil.add("kuaiShou:allVideo:list", advertiserId, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
}
|
|
|
return;
|
|
@@ -146,22 +154,19 @@ public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListM
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- *
|
|
|
- * @description: 根据账户获取视频素材-账户下全部视频素材
|
|
|
- *
|
|
|
* @param advertiserId
|
|
|
* @param accessToken
|
|
|
* @param page
|
|
|
- * @return: java.util.Map<java.lang.String,java.lang.String>
|
|
|
+ * @description: 根据账户获取视频素材-账户下全部视频素材
|
|
|
+ * @return: java.util.Map<java.lang.String, java.lang.String>
|
|
|
* @author: zianY
|
|
|
* @time: 2022/2/9
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map<String,String> getKuaishouVideoByAccountId(Long advertiserId, String accessToken,List<String> materialIds, int page) {
|
|
|
- log.info("调用接口------getKuaishouVideoByAccountId----根据账户获取视频素材---账户--{}===第{}页===》》》",advertiserId,page);
|
|
|
- Map<String,String> resultMap = new HashMap<>();
|
|
|
+ public Map<String, String> getKuaishouVideoByAccountId(Long advertiserId, String accessToken, List<String> materialIds, int page) {
|
|
|
+ log.info("调用接口------getKuaishouVideoByAccountId----根据账户获取视频素材---账户--{}===第{}页===》》》", advertiserId, page);
|
|
|
+ Map<String, String> resultMap = new HashMap<>();
|
|
|
String url = postUrl + KuaishouConstant.VIDEO_LIST;
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("Access-Token", accessToken);
|
|
@@ -175,29 +180,29 @@ public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListM
|
|
|
param.put("end_date", endDate);
|
|
|
}*/
|
|
|
|
|
|
- if (!Check.isNull(materialIds)){
|
|
|
+ if (!Check.isNull(materialIds)) {
|
|
|
param.put("photo_ids", materialIds);
|
|
|
}
|
|
|
String result = HttpUtils.httpPostRequest(url, param, headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
if (Check.isNull(resultJson)) {
|
|
|
- resultMap.put("code","0");
|
|
|
- resultMap.put("message","获取快手视频素材数据为空");
|
|
|
+ resultMap.put("code", "0");
|
|
|
+ resultMap.put("message", "获取快手视频素材数据为空");
|
|
|
return resultMap;
|
|
|
}
|
|
|
Integer code = resultJson.getInteger("code");
|
|
|
String message = resultJson.getString("message");
|
|
|
if (null == code || code != 0) {
|
|
|
log.error("获取快手视频列表数据异常:{},accountId:{}", message, advertiserId);
|
|
|
- resultMap.put("code","500");
|
|
|
- resultMap.put("message","账户id:"+advertiserId+"---获取快手视频列表数据异常:"+message);
|
|
|
+ resultMap.put("code", "500");
|
|
|
+ resultMap.put("message", "账户id:" + advertiserId + "---获取快手视频列表数据异常:" + message);
|
|
|
return resultMap;
|
|
|
}
|
|
|
JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
if (null == details || details.size() <= 0) {
|
|
|
log.info("快手视频列表信息为空=》accountId:{}", advertiserId);
|
|
|
- resultMap.put("code","0");
|
|
|
- resultMap.put("message","获取快手视频素材列表信息为空");
|
|
|
+ resultMap.put("code", "0");
|
|
|
+ resultMap.put("message", "获取快手视频素材列表信息为空");
|
|
|
return resultMap;
|
|
|
}
|
|
|
Boolean toGet = true;
|
|
@@ -246,13 +251,69 @@ public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListM
|
|
|
videoListMapper.replaceBatch(videoGetList);
|
|
|
}
|
|
|
if (toGet) {
|
|
|
- getKuaishouVideoByAccountId(advertiserId, accessToken, materialIds,page + 1);
|
|
|
+ getKuaishouVideoByAccountId(advertiserId, accessToken, materialIds, page + 1);
|
|
|
} else {
|
|
|
log.info("视频列表数据获取完成:accountId:{}", advertiserId);
|
|
|
}
|
|
|
- resultMap.put("code","0");
|
|
|
- resultMap.put("message","success");
|
|
|
+ resultMap.put("code", "0");
|
|
|
+ resultMap.put("message", "success");
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Long> getAccountIds(Long projectId) {
|
|
|
+ return videoListMapper.getAccountIds(projectId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getVideosByAccountId(Long accountId, String startTime, String endTime) {
|
|
|
+ String token = tokenService.getByAccountId(accountId);
|
|
|
+ List<String> allPhotos = videoListMapper.getPhototIdsByAccountId(accountId, startTime, endTime);
|
|
|
+ if (!Check.isNull(allPhotos)) {
|
|
|
+ List<List<String>> photoIdList = Lists.partition(allPhotos, 20);
|
|
|
+ System.out.println(photoIdList);
|
|
|
+ for (List<String> photoIds : photoIdList) {
|
|
|
+ getVideoRelateCreatives(token, photoIds, accountId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getVideoRelateCreatives(String accessToken, List<String> photoIds, Long accountId) {
|
|
|
+ log.info("调用接口------getVideoRelateCreatives----视频关联创意数查询---账户:{} ", accountId);
|
|
|
+ String url = postUrl + KuaishouConstant.VIDEO_RELATE_CREATIVES;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("advertiser_id", accountId);
|
|
|
+ param.put("photo_ids", photoIds);
|
|
|
+ String result = HttpUtils.httpPostRequest(url, param, headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ String message = resultJson.getString("message");
|
|
|
+ if (null == code || code != 0) {
|
|
|
+ log.error("调用接口---getVideoRelateCreatives----视频关联创意数查询 返回结果为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray list = resultJson.getJSONObject("data").getJSONArray("related_creatives");
|
|
|
+ if (null == list || list.size() <= 0) {
|
|
|
+ log.info("视频关联创意数查询为空=》accountId:{}", accountId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ JSONObject obj = list.getJSONObject(i);
|
|
|
+ obj.put("account_id", accountId);
|
|
|
+ KuaishouVideoList vo = videoListMapper.getByPhotoId(obj.getString("photo_id"), accountId);
|
|
|
+ if (!Check.isNull(vo)) {
|
|
|
+ obj.put("signature", vo.getSignature());
|
|
|
+ obj.put("photo_name", vo.getPhotoName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
+ videoListMapper.replaceBatchVideoRelateCreatives(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|