|
@@ -0,0 +1,123 @@
|
|
|
|
+package cn.com.ctop.job.kuaishou.handler;
|
|
|
|
+
|
|
|
|
+import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
|
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService2;
|
|
|
|
+import com.xxl.job.core.biz.model.ReturnT;
|
|
|
|
+import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
|
+import com.xxl.job.core.log.XxlJobLogger;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 快手操作记录,将前一天绑定的账户的近6个月的数据统一跑出来
|
|
|
|
+ */
|
|
|
|
+@Component
|
|
|
|
+public class KuaishouNewAccountOperationRecordJob {
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaishouInterfaceService2 kuaishouInterfaceService2;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICtopOauthTokenService tokenService;
|
|
|
|
+
|
|
|
|
+ static ExecutorService executorService = Executors.newFixedThreadPool(4);
|
|
|
|
+
|
|
|
|
+ @XxlJob("kuaishouNewAccountOperationRecord")
|
|
|
|
+ public ReturnT<String> execute(String param) throws Exception {
|
|
|
|
+ Date getDate = DateUtils.addDay(new Date(), -1);
|
|
|
|
+ if(StringUtils.isNotBlank(param)){
|
|
|
|
+ getDate = DateUtils.addDay(new Date(), Integer.parseInt(param));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String date = DateUtils.formatDate(getDate);
|
|
|
|
+ String startDate = DateUtils.getMonthBefore("yyyy-MM-dd", date, -6);
|
|
|
|
+
|
|
|
|
+ //1:查询当日数据
|
|
|
|
+ List<CtopOauthToken> tokens = tokenService.selectKuaiShouTokenBefore();
|
|
|
|
+ if (null == tokens || tokens.size() <= 0) {
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据异常:未获取到可用的token");
|
|
|
|
+ return ReturnT.FAIL;
|
|
|
|
+ }
|
|
|
|
+ tokens.forEach(token -> {
|
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 1 + "时间:" + date + "~" + date);
|
|
|
|
+ //kuaishouInterfaceService2.getOperationRecord(token.getAccountId(), token.getAccessToken(), 1, date, date);
|
|
|
|
+ month(token.getAccountId(), token.getAccessToken(), 1, startDate, date);
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 1 + "时间:" + date + "~" + date);
|
|
|
|
+
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 2+ "时间:" + date + "~" + date);
|
|
|
|
+ //kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),2, date, date);
|
|
|
|
+ month(token.getAccountId(), token.getAccessToken(), 2, startDate, date);
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 2+ "时间:" + date + "~" + date);
|
|
|
|
+
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 3+ "时间:" + date + "~" + date);
|
|
|
|
+ //kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),3, date, date);
|
|
|
|
+ month(token.getAccountId(), token.getAccessToken(), 3, startDate, date);
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 3+ "时间:" + date + "~" + date);
|
|
|
|
+
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 4+ "时间:" + date + "~" + date);
|
|
|
|
+ //kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),4, date, date);
|
|
|
|
+ month(token.getAccountId(), token.getAccessToken(), 4, startDate, date);
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 4+ "时间:" + date + "~" + date);
|
|
|
|
+
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 5+ "时间:" + date + "~" + date);
|
|
|
|
+ //kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),5, date, date);
|
|
|
|
+ month(token.getAccountId(), token.getAccessToken(), 5, startDate, date);
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 5+ "时间:" + date + "~" + date);
|
|
|
|
+
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 6+ "时间:" + date + "~" + date);
|
|
|
|
+ //kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),6, date, date);
|
|
|
|
+ month(token.getAccountId(), token.getAccessToken(), 6, startDate, date);
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 6+ "时间:" + date + "~" + date);
|
|
|
|
+
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据开始,accountId:" + token.getAccountId() + "操作目标为:" + 7+ "时间:" + date + "~" + date);
|
|
|
|
+ //kuaishouInterfaceService2.getOperationRecord(token.getAccountId(),token.getAccessToken(),7, date, date);
|
|
|
|
+ month(token.getAccountId(), token.getAccessToken(), 7, startDate, date);
|
|
|
|
+ XxlJobLogger.log("定时获取快手操作记录数据结束,accountId:" + token.getAccountId() + "操作目标为:" + 7+ "时间:" + date + "~" + date);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void month(Long token, String accessToken, Integer operationTarget, String startDate, String endDate){
|
|
|
|
+ int diffMonths = DateUtils.calDiffMonth(DateUtils.parseDate(startDate, "yyyy-MM-dd"), DateUtils.parseDate(endDate, "yyyy-MM-dd"));
|
|
|
|
+ if (diffMonths == 0) {
|
|
|
|
+ kuaishouInterfaceService2.getOperationRecord(token, accessToken, operationTarget, startDate, endDate);
|
|
|
|
+ } else {
|
|
|
|
+ for (int i = 0; i <= diffMonths; i++) {
|
|
|
|
+ if (i == 0) {
|
|
|
|
+ Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
|
|
|
|
+ String end = dateMap.get("endDate");
|
|
|
|
+ kuaishouInterfaceService2.getOperationRecord(token, accessToken, operationTarget, startDate, end);
|
|
|
|
+ //ytedanceAsyncTaskCreateByMonth(startDate, end, token, type);
|
|
|
|
+ } else if (i == diffMonths) {
|
|
|
|
+ Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
|
|
|
|
+ String start = dateMap.get("startDate");
|
|
|
|
+ kuaishouInterfaceService2.getOperationRecord(token, accessToken, operationTarget, start, endDate);
|
|
|
|
+ //bytedanceAsyncTaskCreateByMonth(start, endDate, token, type);
|
|
|
|
+ } else {
|
|
|
|
+ Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
|
|
|
|
+ String start = dateMap.get("startDate");
|
|
|
|
+ String end = dateMap.get("endDate");
|
|
|
|
+ kuaishouInterfaceService2.getOperationRecord(token, accessToken, operationTarget, start, end);
|
|
|
|
+ //bytedanceAsyncTaskCreateByMonth(start, end, token, type);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|