|
@@ -1,10 +1,7 @@
|
|
|
package cn.com.ctop.job.kuaishou.data.service.impl;
|
|
package cn.com.ctop.job.kuaishou.data.service.impl;
|
|
|
|
|
|
|
|
import cn.com.ctop.job.kuaishou.data.constant.KuaishouConstant;
|
|
import cn.com.ctop.job.kuaishou.data.constant.KuaishouConstant;
|
|
|
-import cn.com.ctop.job.kuaishou.data.entity.KuaishouAccountReportDaily;
|
|
|
|
|
-import cn.com.ctop.job.kuaishou.data.entity.KuaishouAdUnitList;
|
|
|
|
|
-import cn.com.ctop.job.kuaishou.data.entity.KuaishouVideoList;
|
|
|
|
|
-import cn.com.ctop.job.kuaishou.data.entity.OauthToken;
|
|
|
|
|
|
|
+import cn.com.ctop.job.kuaishou.data.entity.*;
|
|
|
import cn.com.ctop.job.kuaishou.data.mapper.AdUnitReportMapper;
|
|
import cn.com.ctop.job.kuaishou.data.mapper.AdUnitReportMapper;
|
|
|
import cn.com.ctop.job.kuaishou.data.mapper.OauthTokenMapper;
|
|
import cn.com.ctop.job.kuaishou.data.mapper.OauthTokenMapper;
|
|
|
import cn.com.ctop.job.kuaishou.data.service.IAdUnitReportService;
|
|
import cn.com.ctop.job.kuaishou.data.service.IAdUnitReportService;
|
|
@@ -14,6 +11,7 @@ import cn.com.ctop.job.kuaishou.data.utils.HttpUtils;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.xxl.job.core.context.XxlJobHelper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -33,7 +31,7 @@ import java.util.Map;
|
|
|
*/
|
|
*/
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
-public class AdUnitReportServiceImpl extends ServiceImpl<AdUnitReportMapper, KuaishouAdUnitList> implements IAdUnitReportService {
|
|
|
|
|
|
|
+public class AdUnitReportServiceImpl implements IAdUnitReportService {
|
|
|
|
|
|
|
|
@Value("${api.kuaishou.postUrl}")
|
|
@Value("${api.kuaishou.postUrl}")
|
|
|
private String postUrl;
|
|
private String postUrl;
|
|
@@ -114,5 +112,70 @@ public class AdUnitReportServiceImpl extends ServiceImpl<AdUnitReportMapper, Kua
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 快手广告计划信息
|
|
|
|
|
+ * @param advertiserId
|
|
|
|
|
+ * @param accessToken
|
|
|
|
|
+ * @param startDate
|
|
|
|
|
+ * @param endDate
|
|
|
|
|
+ * @param page
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getAdPlanReport(Long advertiserId, String accessToken, String startDate, String endDate, int page) {
|
|
|
|
|
+
|
|
|
|
|
+ log.info("accountId:=={}=====获取广告计划数据信息====page--{}===》》》》",advertiserId,page);
|
|
|
|
|
+ Integer page_size = 500;
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
|
|
+ param.put("advertiser_id", advertiserId);
|
|
|
|
|
+ param.put("page_size", 500);
|
|
|
|
|
+ param.put("page", page);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
|
+
|
|
|
|
|
+ String result = HttpUtils.httpPostRequest(postUrl + KuaishouConstant.CAMPAIGN_LIST, param, headers);
|
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
|
+ if (Check.isNull(resultJson)) {
|
|
|
|
|
+ XxlJobHelper.log("获取广告计划接口异常,advertiserId:{}", advertiserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
|
|
+ if (null == code || code != 0) {
|
|
|
|
|
+ XxlJobHelper.log("获取广告计划返回结果异常,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
|
|
+ if (Check.isNull(details)) {
|
|
|
|
|
+ log.info("快手广告计划数据为空=》accountId:{}", advertiserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<KuaishouCampaignList> kscampaignList = new ArrayList<>();
|
|
|
|
|
+ for (Object detail : details) {
|
|
|
|
|
+ JSONObject unitDetail = (JSONObject) detail;
|
|
|
|
|
+ unitDetail.put("advertiser_id",advertiserId);
|
|
|
|
|
+ KuaishouCampaignList ksAdunit = KuaishouCampaignList.getKuaishouCampaignListInfo(unitDetail);
|
|
|
|
|
+ kscampaignList.add(ksAdunit);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Check.isNull(kscampaignList)) {
|
|
|
|
|
+ adUnitReportMapper.replaceBatchKsCampaign(kscampaignList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //是否有下一页
|
|
|
|
|
+ Boolean toGet = true;
|
|
|
|
|
+ if (details.size() < page_size) {
|
|
|
|
|
+ toGet = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (toGet) {
|
|
|
|
|
+ getAdPlanReport(advertiserId, accessToken, startDate, endDate, page + 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("快手广告计划数据获取完成:accountId:{}", advertiserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|