|
@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -32,7 +33,8 @@ import java.util.Map;
|
|
|
public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListMapper, KuaishouVideoList> implements IKuaishouVideoListService {
|
|
public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListMapper, KuaishouVideoList> implements IKuaishouVideoListService {
|
|
|
@Value("${api.kuaishou.postUrl}")
|
|
@Value("${api.kuaishou.postUrl}")
|
|
|
private String postUrl;
|
|
private String postUrl;
|
|
|
- @Autowired
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
private KuaishouVideoListMapper videoListMapper;
|
|
private KuaishouVideoListMapper videoListMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -117,4 +119,110 @@ public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListM
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ *
|
|
|
|
|
+ * @description: 根据账户获取视频素材-账户下全部视频素材
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param advertiserId
|
|
|
|
|
+ * @param accessToken
|
|
|
|
|
+ * @param page
|
|
|
|
|
+ * @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, 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);
|
|
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
|
|
+ param.put("advertiser_id", advertiserId);
|
|
|
|
|
+ Integer page_size = 500;
|
|
|
|
|
+ param.put("page_size", page_size);
|
|
|
|
|
+ param.put("page", page);
|
|
|
|
|
+ /* if (!Check.isNull(startDate) && !Check.isNull(endDate)) {
|
|
|
|
|
+ param.put("start_date", startDate);
|
|
|
|
|
+ param.put("end_date", endDate);
|
|
|
|
|
+ }*/
|
|
|
|
|
+ String result = HttpUtils.httpPostRequest(url, param, headers);
|
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
|
+ if (Check.isNull(resultJson)) {
|
|
|
|
|
+ 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);
|
|
|
|
|
+ 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","获取快手视频素材列表信息为空");
|
|
|
|
|
+ return resultMap;
|
|
|
|
|
+ }
|
|
|
|
|
+ Boolean toGet = true;
|
|
|
|
|
+ if (details.size() < page_size) {
|
|
|
|
|
+ toGet = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<KuaishouVideoList> videoGetList = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
|
|
+ JSONObject detailJson = details.getJSONObject(i);
|
|
|
|
|
+ if (Check.isNull(detailJson)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ KuaishouVideoList videoList = new KuaishouVideoList();
|
|
|
|
|
+ String photo_id = detailJson.getString("photo_id");
|
|
|
|
|
+ videoList.setAccountId(advertiserId);
|
|
|
|
|
+ videoList.setCoverUrl(detailJson.getString("cover_url"));
|
|
|
|
|
+ videoList.setPhotoId(photo_id);
|
|
|
|
|
+ videoList.setPhotoName(detailJson.getString("photo_name"));
|
|
|
|
|
+ videoList.setStatDate(detailJson.getDate("upload_time"));
|
|
|
|
|
+ String signature = detailJson.getString("signature");
|
|
|
|
|
+ videoList.setSignature(signature);
|
|
|
|
|
+ Integer source = detailJson.getInteger("source");
|
|
|
|
|
+ if (source == 2) {
|
|
|
|
|
+ videoList.setChannelType(1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ videoList.setChannelType(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer new_status = detailJson.getInteger("new_status");
|
|
|
|
|
+ if (new_status == 1) {
|
|
|
|
|
+ videoList.setStatus(0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ videoList.setStatus(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ videoList.setUrl(detailJson.getString("url"));
|
|
|
|
|
+ Integer width = detailJson.getInteger("width");
|
|
|
|
|
+ videoList.setWidth(width);
|
|
|
|
|
+ Integer height = detailJson.getInteger("height");
|
|
|
|
|
+ videoList.setHeight(height);
|
|
|
|
|
+ Integer type = MaterialEnum.getTypeBySize(width, height);
|
|
|
|
|
+ if (!Check.isNull(type)) {
|
|
|
|
|
+ videoList.setMaterialType(type);
|
|
|
|
|
+ }
|
|
|
|
|
+ videoGetList.add(videoList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Check.isNull(videoGetList)) {
|
|
|
|
|
+ videoListMapper.replaceBatch(videoGetList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (toGet) {
|
|
|
|
|
+ getKuaishouVideoByAccountId(advertiserId, accessToken, page + 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("视频列表数据获取完成:accountId:{}", advertiserId);
|
|
|
|
|
+ }
|
|
|
|
|
+ resultMap.put("code","0");
|
|
|
|
|
+ resultMap.put("message","success");
|
|
|
|
|
+ return resultMap;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|