|
@@ -9,6 +9,7 @@ import cn.com.ctop.job.kuaishou.data.service.IKuaiShouErrorLogService;
|
|
|
import cn.com.ctop.job.kuaishou.data.utils.Check;
|
|
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.DateUtils;
|
|
|
import cn.com.ctop.job.kuaishou.data.utils.HttpUtils;
|
|
import cn.com.ctop.job.kuaishou.data.utils.HttpUtils;
|
|
|
|
|
+import cn.com.ctop.job.kuaishou.utils.doris.sink.DorisMultiTableStreamLoadManager;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -26,17 +27,12 @@ import java.util.*;
|
|
|
@EnableScheduling
|
|
@EnableScheduling
|
|
|
public class KuaiShouAccountReportServiceImpl implements IKuaiShouAccountReportService {
|
|
public class KuaiShouAccountReportServiceImpl implements IKuaiShouAccountReportService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
|
+ private DorisMultiTableStreamLoadManager dorisLoadManager;
|
|
|
|
|
+ @Autowired
|
|
|
private IKuaiShouErrorLogService errorLogService;
|
|
private IKuaiShouErrorLogService errorLogService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private KuaiShouAccountReportMapper accountReportMapper;
|
|
private KuaiShouAccountReportMapper accountReportMapper;
|
|
|
|
|
|
|
|
- /* private static final int MAX_BATCH_SIZE = 5000;
|
|
|
|
|
- private static final long MAX_WAIT_TIME_MS = 2 * 60 * 1000;
|
|
|
|
|
-
|
|
|
|
|
- private final List<KuaishouAccountReportHour> advertiserReportHourBuffer = Collections.synchronizedList(new ArrayList<>());
|
|
|
|
|
- private final List<KuaishouAccountReportDaily> advertiserReportDailyBuffer = Collections.synchronizedList(new ArrayList<>());
|
|
|
|
|
- private long advertiserReportHourLastFlushTime = System.currentTimeMillis();
|
|
|
|
|
- private long advertiserReportDailyLastFlushTime = System.currentTimeMillis();*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -81,12 +77,13 @@ public class KuaiShouAccountReportServiceImpl implements IKuaiShouAccountReportS
|
|
|
KuaishouAccountReportHour accountReportHour = JSONObject.toJavaObject(detailJson, KuaishouAccountReportHour.class);
|
|
KuaishouAccountReportHour accountReportHour = JSONObject.toJavaObject(detailJson, KuaishouAccountReportHour.class);
|
|
|
accountReportHour.setAdvertiserId(advertiserId);
|
|
accountReportHour.setAdvertiserId(advertiserId);
|
|
|
addList.add(accountReportHour);
|
|
addList.add(accountReportHour);
|
|
|
|
|
+
|
|
|
|
|
+ dorisLoadManager.add("media_api", "kuaishou_advertiser_report_hourly" , accountReportHour);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!Check.isNull(addList)) {
|
|
if (!Check.isNull(addList)) {
|
|
|
accountReportMapper.replaceBatcKuaiShouAccountReportHour(addList);
|
|
accountReportMapper.replaceBatcKuaiShouAccountReportHour(addList);
|
|
|
- accountReportMapper.replaceBatcKuaiShouAccountReportHourSD(addList);
|
|
|
|
|
- //advertiserReportHourBuffer.addAll(addList);
|
|
|
|
|
|
|
+ //accountReportMapper.replaceBatcKuaiShouAccountReportHourSD(addList);
|
|
|
}
|
|
}
|
|
|
if (details.size() >= 2000) {
|
|
if (details.size() >= 2000) {
|
|
|
queryAccountReportHourly(accessToken, advertiserId, startDate, endDate, page + 1);
|
|
queryAccountReportHourly(accessToken, advertiserId, startDate, endDate, page + 1);
|
|
@@ -136,12 +133,13 @@ public class KuaiShouAccountReportServiceImpl implements IKuaiShouAccountReportS
|
|
|
KuaishouAccountReportDaily accountReportDaily = JSONObject.toJavaObject(detailJson, KuaishouAccountReportDaily.class);
|
|
KuaishouAccountReportDaily accountReportDaily = JSONObject.toJavaObject(detailJson, KuaishouAccountReportDaily.class);
|
|
|
accountReportDaily.setAdvertiserId(advertiserId);
|
|
accountReportDaily.setAdvertiserId(advertiserId);
|
|
|
addList.add(accountReportDaily);
|
|
addList.add(accountReportDaily);
|
|
|
|
|
+
|
|
|
|
|
+ dorisLoadManager.add("media_api", "kuaishou_advertiser_report_daily", accountReportDaily);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!Check.isNull(addList)) {
|
|
if (!Check.isNull(addList)) {
|
|
|
accountReportMapper.replaceBatcKuaiShouAccountReportDaily(addList);
|
|
accountReportMapper.replaceBatcKuaiShouAccountReportDaily(addList);
|
|
|
- accountReportMapper.replaceBatcKuaiShouAccountReportDailySD(addList);
|
|
|
|
|
- //advertiserReportDailyBuffer.addAll(addList);
|
|
|
|
|
|
|
+ //accountReportMapper.replaceBatcKuaiShouAccountReportDailySD(addList);
|
|
|
}
|
|
}
|
|
|
if (details.size() >= 2000) {
|
|
if (details.size() >= 2000) {
|
|
|
queryAccountReportDaily(accessToken, advertiserId, startDate, endDate, page + 1);
|
|
queryAccountReportDaily(accessToken, advertiserId, startDate, endDate, page + 1);
|
|
@@ -197,11 +195,13 @@ public class KuaiShouAccountReportServiceImpl implements IKuaiShouAccountReportS
|
|
|
KuaishouDailyFlows accountReportDaily = JSONObject.toJavaObject(detailJson, KuaishouDailyFlows.class);
|
|
KuaishouDailyFlows accountReportDaily = JSONObject.toJavaObject(detailJson, KuaishouDailyFlows.class);
|
|
|
accountReportDaily.setAdvertiserId(advertiserId);
|
|
accountReportDaily.setAdvertiserId(advertiserId);
|
|
|
addList.add(accountReportDaily);
|
|
addList.add(accountReportDaily);
|
|
|
|
|
+
|
|
|
|
|
+ dorisLoadManager.add("media_api", "kuaishou_advertiser_daily_flows", accountReportDaily);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (!Check.isNull(addList)) {
|
|
|
|
|
- accountReportMapper.replaceKuaiShouDailyFlows(addList);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //if (!Check.isNull(addList)) {
|
|
|
|
|
+ // accountReportMapper.replaceKuaiShouDailyFlows(addList);
|
|
|
|
|
+ //}
|
|
|
if (page < totalPage) {
|
|
if (page < totalPage) {
|
|
|
queryAccountDailyFlows(accessToken, advertiserId, startDate, endDate, page + 1,isLog, errId, isSend);
|
|
queryAccountDailyFlows(accessToken, advertiserId, startDate, endDate, page + 1,isLog, errId, isSend);
|
|
|
} else {
|
|
} else {
|
|
@@ -221,85 +221,4 @@ public class KuaiShouAccountReportServiceImpl implements IKuaiShouAccountReportS
|
|
|
public void updateClAccountStatus() {
|
|
public void updateClAccountStatus() {
|
|
|
accountReportMapper.updateClAccountStatus();
|
|
accountReportMapper.updateClAccountStatus();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /*@Scheduled(fixedRate = 14000) // 每30秒检查一次
|
|
|
|
|
- public void flushIfNeeded() {
|
|
|
|
|
- log.info("开始执行账户报表定时批处理任务....");
|
|
|
|
|
- synchronized (advertiserReportHourBuffer) {
|
|
|
|
|
- long now = System.currentTimeMillis();
|
|
|
|
|
- // advertiserReportHourBuffer.size() >= MAX_BATCH_SIZE || (now - advertiserReportHourLastFlushTime) >= MAX_WAIT_TIME_MS &&
|
|
|
|
|
- if ( !advertiserReportHourBuffer.isEmpty()) {
|
|
|
|
|
- try {
|
|
|
|
|
- long startTime = System.currentTimeMillis();
|
|
|
|
|
- accountReportMapper.replaceBatcKuaiShouAccountReportHourSD(new ArrayList<>(advertiserReportHourBuffer));
|
|
|
|
|
- long endTime = System.currentTimeMillis();
|
|
|
|
|
- long diffInMilliseconds = endTime - startTime;
|
|
|
|
|
- double diffInSeconds = diffInMilliseconds / 1000.0;
|
|
|
|
|
- DecimalFormat df = new DecimalFormat("#.00");
|
|
|
|
|
- String seconds = df.format(diffInSeconds);
|
|
|
|
|
- log.info("Flushed advertiserReportHour batch size: {},执行时间:{}", advertiserReportHourBuffer.size(),seconds);
|
|
|
|
|
-
|
|
|
|
|
- advertiserReportHourBuffer.clear();
|
|
|
|
|
- advertiserReportHourLastFlushTime = now;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("Error flushing advertiserReportHour batch", e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- synchronized (advertiserReportDailyBuffer) {
|
|
|
|
|
- long now = System.currentTimeMillis();
|
|
|
|
|
- // advertiserReportDailyBuffer.size() >= MAX_BATCH_SIZE || (now - advertiserReportDailyLastFlushTime) >= MAX_WAIT_TIME_MS &&
|
|
|
|
|
- if ( !advertiserReportDailyBuffer.isEmpty()) {
|
|
|
|
|
- try {
|
|
|
|
|
- long startTime = System.currentTimeMillis();
|
|
|
|
|
- accountReportMapper.replaceBatcKuaiShouAccountReportDailySD(new ArrayList<>(advertiserReportDailyBuffer));
|
|
|
|
|
- long endTime = System.currentTimeMillis();
|
|
|
|
|
- long diffInMilliseconds = endTime - startTime;
|
|
|
|
|
- double diffInSeconds = diffInMilliseconds / 1000.0;
|
|
|
|
|
- DecimalFormat df = new DecimalFormat("#.00");
|
|
|
|
|
- String seconds = df.format(diffInSeconds);
|
|
|
|
|
- log.info("Flushed advertiserReportDaily batch size: {},执行时间:{}", advertiserReportDailyBuffer.size(),seconds);
|
|
|
|
|
-
|
|
|
|
|
- advertiserReportDailyBuffer.clear();
|
|
|
|
|
- advertiserReportDailyLastFlushTime = now;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("Error flushing advertiserReportDaily batch", e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- @PreDestroy
|
|
|
|
|
- public void flushPreDestroy() {
|
|
|
|
|
- log.info("项目重启,开始执行账户报表批处理任务....");
|
|
|
|
|
- synchronized (advertiserReportHourBuffer) {
|
|
|
|
|
- if (!advertiserReportHourBuffer.isEmpty()) {
|
|
|
|
|
- try {
|
|
|
|
|
- log.info("Flushed advertiserReportHour batch size: {}", advertiserReportHourBuffer.size());
|
|
|
|
|
- accountReportMapper.replaceBatcKuaiShouAccountReportHourSD(new ArrayList<>(advertiserReportHourBuffer));
|
|
|
|
|
- advertiserReportHourBuffer.clear();
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("Error flushing advertiserReportHour batch", e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- synchronized (advertiserReportDailyBuffer) {
|
|
|
|
|
- if (!advertiserReportDailyBuffer.isEmpty()) {
|
|
|
|
|
- try {
|
|
|
|
|
- log.info("Flushed advertiserReportDaily batch size: {}", advertiserReportDailyBuffer.size());
|
|
|
|
|
- accountReportMapper.replaceBatcKuaiShouAccountReportDailySD(new ArrayList<>(advertiserReportDailyBuffer));
|
|
|
|
|
- advertiserReportDailyBuffer.clear();
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("Error flushing advertiserReportDaily batch", e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }*/
|
|
|
|
|
}
|
|
}
|