|
|
@@ -4,8 +4,9 @@ import cn.com.ctop.job.kuaishou.data.constant.KuaishouLinkConstants;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaishouAdgroupReportDaily;
|
|
|
import cn.com.ctop.job.kuaishou.data.entity.KuaishouAdgroupReportHourly;
|
|
|
import cn.com.ctop.job.kuaishou.data.mapper.KuaiShouGroupReportMapper;
|
|
|
-import cn.com.ctop.job.kuaishou.data.service.IKuaiShouGroupReportService;
|
|
|
import cn.com.ctop.job.kuaishou.data.service.IKuaiShouErrorLogService;
|
|
|
+import cn.com.ctop.job.kuaishou.data.service.IKuaiShouGroupReportService;
|
|
|
+import cn.com.ctop.job.kuaishou.data.utils.AlertUtils;
|
|
|
import cn.com.ctop.job.kuaishou.data.utils.Check;
|
|
|
import cn.com.ctop.job.kuaishou.data.utils.DateUtils;
|
|
|
import cn.com.ctop.job.kuaishou.data.utils.HttpUtils;
|
|
|
@@ -15,12 +16,12 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.annotation.PreDestroy;
|
|
|
-import java.text.DecimalFormat;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@@ -36,7 +37,6 @@ public class KuaiShouGroupReportServiceImpl implements IKuaiShouGroupReportServi
|
|
|
private DorisMultiTableStreamLoadManager dorisLoadManager;
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void queryGroupReportHourly(String accessToken, Long advertiserId, String startDate, String endDate, int page) {
|
|
|
try {
|
|
|
@@ -168,4 +168,57 @@ public class KuaiShouGroupReportServiceImpl implements IKuaiShouGroupReportServi
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void queryGroupList(String accessToken, Long advertiserId, String startDate, String endDate, int page, Integer isLog, Long errId, Integer isSend) {
|
|
|
+ String url = KuaishouLinkConstants.KS_PREFIX + KuaishouLinkConstants.GROUP_LIST;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ if (!Check.isNull(startDate)) {
|
|
|
+ param.put("start_date", startDate);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(endDate)) {
|
|
|
+ param.put("end_date", endDate);
|
|
|
+ }
|
|
|
+ int pageSize = 500;
|
|
|
+ param.put("advertiser_id", advertiserId);
|
|
|
+ param.put("page_size", pageSize);
|
|
|
+ param.put("page", page);
|
|
|
+ param.put("status", -2);
|
|
|
+ String result = HttpUtils.httpPostRequest(url, param, headers);
|
|
|
+ if (Check.isNull(result)) {
|
|
|
+ log.error("获取快手广告组异常,返回为空, accountId:{}", advertiserId);
|
|
|
+ errorLogService.addError(advertiserId, startDate, endDate, "group_list", "daily", "返回为空", 2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ String message = resultJson.getString("message");
|
|
|
+ if (null == code || code != 0) {
|
|
|
+ log.error("获取快手广告组异常:{},accountId:{}", message, advertiserId);
|
|
|
+ errorLogService.addError(advertiserId, startDate, endDate, "group_list", "daily", message, 2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
|
|
|
+ if (!Check.isNull(details)) {
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ JSONObject detailJson = details.getJSONObject(i);
|
|
|
+ detailJson.put("advertiser_id", advertiserId);
|
|
|
+ dorisLoadManager.add("media_api", "kuaishou_adgroup_list", detailJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (details.size() >= pageSize) {
|
|
|
+ queryGroupList(accessToken, advertiserId, startDate, endDate, page + 1, isLog, errId, isSend);
|
|
|
+ } else {
|
|
|
+ log.info("【{}】录入广告组完成 startDate:{}, endDate:{}", advertiserId, startDate, endDate);
|
|
|
+ if (errId != null) {
|
|
|
+ errorLogService.deleteInfoByErrorId(errId);
|
|
|
+ }
|
|
|
+ if (isSend != null && isSend == 1) {
|
|
|
+ AlertUtils.sendMessage(advertiserId, startDate, endDate, 2, "daily", 1, "group_list");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|