|
@@ -2,12 +2,11 @@ package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
|
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
-import cn.com.ctop.common.module.utils.Check;
|
|
|
|
-import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
|
-import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
|
|
|
|
-import cn.com.ctop.common.module.utils.PropertiesUtils;
|
|
|
|
|
|
+import cn.com.ctop.common.module.utils.*;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouDailyReportTask;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouHistoryReportTask;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouHistoryReportTask;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouHistoryReportTaskMapper;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouHistoryReportTaskMapper;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyCampaignMapper;
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyCampaignMapper;
|
|
@@ -42,7 +41,8 @@ import java.util.concurrent.Executors;
|
|
public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHistoryReportTaskMapper, KuaiShouHistoryReportTask> implements IKuaiShouHistoryReportTaskService {
|
|
public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHistoryReportTaskMapper, KuaiShouHistoryReportTask> implements IKuaiShouHistoryReportTaskService {
|
|
@Value("${jeecg.path.reportDownload}")
|
|
@Value("${jeecg.path.reportDownload}")
|
|
private static String downloadPath;
|
|
private static String downloadPath;
|
|
- static List<Integer> typeList;
|
|
|
|
|
|
+ static List<Integer> historyTypeList;
|
|
|
|
+ static List<Integer> dailyTypeList;
|
|
static ExecutorService executorService = Executors.newFixedThreadPool(3);
|
|
static ExecutorService executorService = Executors.newFixedThreadPool(3);
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -59,9 +59,11 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private KuaishouReportDailyCreativeMapper reportDailyCreativeMapper;
|
|
private KuaishouReportDailyCreativeMapper reportDailyCreativeMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouDailyReportTaskService dailyReportTaskService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void createTask(Long accountId, String token, String date) {
|
|
|
|
|
|
+ public void createTask(Long accountId, String token, String startDate, String endDate, String taskType) {
|
|
if (Check.isNull(accountId) || Check.isNull(token)) {
|
|
if (Check.isNull(accountId) || Check.isNull(token)) {
|
|
log.error("token或accountId为空");
|
|
log.error("token或accountId为空");
|
|
return;
|
|
return;
|
|
@@ -74,35 +76,67 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
|
|
JSONObject param = new JSONObject();
|
|
JSONObject param = new JSONObject();
|
|
param.put("advertiser_id", accountId);
|
|
param.put("advertiser_id", accountId);
|
|
JSONObject taskParams = new JSONObject();
|
|
JSONObject taskParams = new JSONObject();
|
|
- taskParams.put("start_date", date);
|
|
|
|
- taskParams.put("end_date", date);
|
|
|
|
-
|
|
|
|
- if (Check.isNull(typeList)) {
|
|
|
|
- getTypeList();
|
|
|
|
- }
|
|
|
|
- for (int i = 0; i < typeList.size(); i++) {
|
|
|
|
- Integer type = typeList.get(i);
|
|
|
|
- String taskName = accountId + "_" + type;
|
|
|
|
- param.put("task_name", taskName);
|
|
|
|
- taskParams.put("view_type", type);
|
|
|
|
- param.put("task_params", taskParams);
|
|
|
|
- String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
|
- JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
- if (!Check.isNull(resultJson)) {
|
|
|
|
- Integer code = resultJson.getInteger("code");
|
|
|
|
- if (code == 0) {
|
|
|
|
- JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
|
- KuaiShouHistoryReportTask reportTask = new KuaiShouHistoryReportTask();
|
|
|
|
- reportTask.setAccountId(accountId);
|
|
|
|
- reportTask.setStartDate(date);
|
|
|
|
- reportTask.setEndDate(date);
|
|
|
|
- reportTask.setTaskId(dataJson.getString("task_id"));
|
|
|
|
- reportTask.setViewType(type);
|
|
|
|
- reportTask.setTaskStatus(0);
|
|
|
|
- reportTask.setTaskName(taskName);
|
|
|
|
- this.save(reportTask);
|
|
|
|
- } else {
|
|
|
|
- log.error("快手历史报表请求失败,accountId:{},返回数据:{}", accountId, resultJson);
|
|
|
|
|
|
+ taskParams.put("start_date", startDate);
|
|
|
|
+ taskParams.put("end_date", endDate);
|
|
|
|
+ if (null != taskType && taskType.equals(CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY)) {
|
|
|
|
+ if (Check.isNull(dailyTypeList)) {
|
|
|
|
+ getDailyTypeList();
|
|
|
|
+ }
|
|
|
|
+ for (int i = 0; i < dailyTypeList.size(); i++) {
|
|
|
|
+ Integer type = dailyTypeList.get(i);
|
|
|
|
+ String taskName = accountId + "_" + type + "_" + System.currentTimeMillis();
|
|
|
|
+ log.info("任务名称:{}", taskName);
|
|
|
|
+ param.put("task_name", taskName);
|
|
|
|
+ taskParams.put("view_type", type);
|
|
|
|
+ param.put("task_params", taskParams);
|
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
|
+ if (code == 0) {
|
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
|
+ KuaiShouDailyReportTask dailyReportTask = new KuaiShouDailyReportTask();
|
|
|
|
+ dailyReportTask.setAccountId(accountId);
|
|
|
|
+ dailyReportTask.setStatDate(startDate);
|
|
|
|
+ dailyReportTask.setTaskId(dataJson.getString("task_id"));
|
|
|
|
+ dailyReportTask.setViewType(type);
|
|
|
|
+ dailyReportTask.setTaskStatus(0);
|
|
|
|
+ dailyReportTask.setTaskName(taskName);
|
|
|
|
+ dailyReportTaskService.save(dailyReportTask);
|
|
|
|
+ } else {
|
|
|
|
+ log.error("快手历史报表请求失败,accountId:{},返回数据:{}", accountId, resultJson);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (Check.isNull(historyTypeList)) {
|
|
|
|
+ getHistoryTypeList();
|
|
|
|
+ }
|
|
|
|
+ for (int i = 0; i < historyTypeList.size(); i++) {
|
|
|
|
+ Integer type = historyTypeList.get(i);
|
|
|
|
+ String taskName = accountId + "_" + type + "_" + System.currentTimeMillis();
|
|
|
|
+ log.info("任务名称:{}", taskName);
|
|
|
|
+ param.put("task_name", taskName);
|
|
|
|
+ taskParams.put("view_type", type);
|
|
|
|
+ param.put("task_params", taskParams);
|
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
|
+ if (code == 0) {
|
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
|
+ KuaiShouHistoryReportTask reportTask = new KuaiShouHistoryReportTask();
|
|
|
|
+ reportTask.setAccountId(accountId);
|
|
|
|
+ reportTask.setStartDate(startDate);
|
|
|
|
+ reportTask.setEndDate(endDate);
|
|
|
|
+ reportTask.setTaskId(dataJson.getString("task_id"));
|
|
|
|
+ reportTask.setViewType(type);
|
|
|
|
+ reportTask.setTaskStatus(0);
|
|
|
|
+ reportTask.setTaskName(taskName);
|
|
|
|
+ this.save(reportTask);
|
|
|
|
+ } else {
|
|
|
|
+ log.error("快手历史报表请求失败,accountId:{},返回数据:{}", accountId, resultJson);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -203,13 +237,20 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- private void getTypeList() {
|
|
|
|
- typeList = new ArrayList<>();
|
|
|
|
-// typeList.add(1);
|
|
|
|
- typeList.add(2);
|
|
|
|
- typeList.add(3);
|
|
|
|
- typeList.add(4);
|
|
|
|
|
|
+ private void getHistoryTypeList() {
|
|
|
|
+ historyTypeList = new ArrayList<>();
|
|
|
|
+ historyTypeList.add(1);
|
|
|
|
+ historyTypeList.add(2);
|
|
|
|
+ historyTypeList.add(3);
|
|
|
|
+ historyTypeList.add(4);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ private void getDailyTypeList() {
|
|
|
|
+ dailyTypeList = new ArrayList<>();
|
|
|
|
+ dailyTypeList.add(1);
|
|
|
|
+ dailyTypeList.add(2);
|
|
|
|
+ dailyTypeList.add(3);
|
|
|
|
+ dailyTypeList.add(4);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|