|
@@ -9,6 +9,7 @@ import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.FieldsConfig;
|
|
import cn.com.ctop.job.bytedance.data.utils.FieldsConfig;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.AlertUtils;
|
|
import cn.com.ctop.job.bytedance.data.utils.AlertUtils;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.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,14 +27,10 @@ import java.util.*;
|
|
|
@EnableScheduling
|
|
@EnableScheduling
|
|
|
public class BytedancePromoterReportServiceImpl implements IBytedancePromoterReportService {
|
|
public class BytedancePromoterReportServiceImpl implements IBytedancePromoterReportService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private BytedancePromoterReportMapper promoterReportMapper;
|
|
|
|
|
- /*private static final int MAX_BATCH_SIZE = 10000;
|
|
|
|
|
- private static final long MAX_WAIT_TIME_MS = 2 * 60 * 1000;
|
|
|
|
|
- private final List<BytedancePromoterReportHour> promoterReportHourBuffer = Collections.synchronizedList(new ArrayList<>());
|
|
|
|
|
- private final List<BytedancePromoterReportDaily> promoterReportDailyBuffer = Collections.synchronizedList(new ArrayList<>());
|
|
|
|
|
- private long promoterReportHourLastFlushTime = System.currentTimeMillis();
|
|
|
|
|
- private long promoterReportDailyLastFlushTime = System.currentTimeMillis();*/
|
|
|
|
|
|
|
+ private DorisMultiTableStreamLoadManager dorisLoadManager;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BytedancePromoterReportMapper promoterReportMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<JSONObject> getAccountList() {
|
|
public List<JSONObject> getAccountList() {
|
|
@@ -90,6 +87,8 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
bytedancePromoterReportHour.setStatTimeDay(statTimeDay);
|
|
bytedancePromoterReportHour.setStatTimeDay(statTimeDay);
|
|
|
bytedancePromoterReportHour.setHour(hour);
|
|
bytedancePromoterReportHour.setHour(hour);
|
|
|
hours.add(bytedancePromoterReportHour);
|
|
hours.add(bytedancePromoterReportHour);
|
|
|
|
|
+
|
|
|
|
|
+ dorisLoadManager.add("media_api","bytedance_promoter_report_hour", bytedancePromoterReportHour);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -100,8 +99,7 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
}
|
|
}
|
|
|
if (!Check.isNull(hours)) {
|
|
if (!Check.isNull(hours)) {
|
|
|
promoterReportMapper.replacePromoterReportHour(hours);
|
|
promoterReportMapper.replacePromoterReportHour(hours);
|
|
|
- promoterReportMapper.replacePromoterReportHourSD(hours);
|
|
|
|
|
- //promoterReportHourBuffer.addAll(hours);
|
|
|
|
|
|
|
+ //promoterReportMapper.replacePromoterReportHourSD(hours);
|
|
|
}
|
|
}
|
|
|
if (hours.size() >= 100) {
|
|
if (hours.size() >= 100) {
|
|
|
try {
|
|
try {
|
|
@@ -171,6 +169,7 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
promoterReportDaily.setCdpPromotionName(cdpPromotionName);
|
|
promoterReportDaily.setCdpPromotionName(cdpPromotionName);
|
|
|
promoterReportDaily.setStatTimeDay(statTimeDay);
|
|
promoterReportDaily.setStatTimeDay(statTimeDay);
|
|
|
promoterReportDailies.add(promoterReportDaily);
|
|
promoterReportDailies.add(promoterReportDaily);
|
|
|
|
|
+ dorisLoadManager.add("media_api", "bytedance_promoter_report_daily", promoterReportDaily);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -181,8 +180,7 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
}
|
|
}
|
|
|
if (!Check.isNull(promoterReportDailies)) {
|
|
if (!Check.isNull(promoterReportDailies)) {
|
|
|
promoterReportMapper.replacePromoterReportDailies(promoterReportDailies);
|
|
promoterReportMapper.replacePromoterReportDailies(promoterReportDailies);
|
|
|
- promoterReportMapper.replacePromoterReportDailiesSD(promoterReportDailies);
|
|
|
|
|
- //promoterReportDailyBuffer.addAll(promoterReportDailies);
|
|
|
|
|
|
|
+ //promoterReportMapper.replacePromoterReportDailiesSD(promoterReportDailies);
|
|
|
log.info("账户ID:{},广告日报(最细粒度)数据请求成功", advertiserId);
|
|
log.info("账户ID:{},广告日报(最细粒度)数据请求成功", advertiserId);
|
|
|
}
|
|
}
|
|
|
if (promoterReportDailies.size() >= 100) {
|
|
if (promoterReportDailies.size() >= 100) {
|
|
@@ -265,6 +263,8 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
bytedancePromoterReportHour.setStatTimeDay(statTimeDay);
|
|
bytedancePromoterReportHour.setStatTimeDay(statTimeDay);
|
|
|
bytedancePromoterReportHour.setHour(hour);
|
|
bytedancePromoterReportHour.setHour(hour);
|
|
|
hours.add(bytedancePromoterReportHour);
|
|
hours.add(bytedancePromoterReportHour);
|
|
|
|
|
+
|
|
|
|
|
+ dorisLoadManager.add("media_api","bytedance_promoter_report_hour", bytedancePromoterReportHour);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -284,8 +284,7 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
}
|
|
}
|
|
|
if (!Check.isNull(hours)) {
|
|
if (!Check.isNull(hours)) {
|
|
|
promoterReportMapper.replacePromoterReportHour(hours);
|
|
promoterReportMapper.replacePromoterReportHour(hours);
|
|
|
- promoterReportMapper.replacePromoterReportHourSD(hours);
|
|
|
|
|
- //promoterReportHourBuffer.addAll(hours);
|
|
|
|
|
|
|
+ //promoterReportMapper.replacePromoterReportHourSD(hours);
|
|
|
}
|
|
}
|
|
|
if (hours.size() >= 100) {
|
|
if (hours.size() >= 100) {
|
|
|
try {
|
|
try {
|
|
@@ -359,6 +358,8 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
promoterReportDaily.setCdpPromotionName(cdpPromotionName);
|
|
promoterReportDaily.setCdpPromotionName(cdpPromotionName);
|
|
|
promoterReportDaily.setStatTimeDay(statTimeDay);
|
|
promoterReportDaily.setStatTimeDay(statTimeDay);
|
|
|
promoterReportDailies.add(promoterReportDaily);
|
|
promoterReportDailies.add(promoterReportDaily);
|
|
|
|
|
+
|
|
|
|
|
+ dorisLoadManager.add("media_api", "bytedance_promoter_report_daily", promoterReportDaily);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -378,8 +379,7 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
}
|
|
}
|
|
|
if (!Check.isNull(promoterReportDailies)) {
|
|
if (!Check.isNull(promoterReportDailies)) {
|
|
|
promoterReportMapper.replacePromoterReportDailies(promoterReportDailies);
|
|
promoterReportMapper.replacePromoterReportDailies(promoterReportDailies);
|
|
|
- promoterReportMapper.replacePromoterReportDailiesSD(promoterReportDailies);
|
|
|
|
|
- //promoterReportDailyBuffer.addAll(promoterReportDailies);
|
|
|
|
|
|
|
+ //promoterReportMapper.replacePromoterReportDailiesSD(promoterReportDailies);
|
|
|
log.info("账户ID:{},广告日报(最细粒度)数据请求成功", advertiserId);
|
|
log.info("账户ID:{},广告日报(最细粒度)数据请求成功", advertiserId);
|
|
|
}
|
|
}
|
|
|
if (promoterReportDailies.size() >= 100) {
|
|
if (promoterReportDailies.size() >= 100) {
|
|
@@ -406,86 +406,4 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
|
|
|
return promoterReportMapper.getAllList();
|
|
return promoterReportMapper.getAllList();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*@Scheduled(fixedRate = 11000) // 每30秒检查一次
|
|
|
|
|
- public void flushIfNeeded() {
|
|
|
|
|
- log.info("开始执行广告报表定时批处理任务....");
|
|
|
|
|
- synchronized (promoterReportHourBuffer) {
|
|
|
|
|
- long now = System.currentTimeMillis();
|
|
|
|
|
- // promoterReportHourBuffer.size() >= MAX_BATCH_SIZE || (now - promoterReportHourLastFlushTime) >= MAX_WAIT_TIME_MS &&
|
|
|
|
|
- if ( !promoterReportHourBuffer.isEmpty()) {
|
|
|
|
|
- try {
|
|
|
|
|
- long startTime = System.currentTimeMillis();
|
|
|
|
|
- promoterReportMapper.replacePromoterReportHourSD(new ArrayList<>(promoterReportHourBuffer));
|
|
|
|
|
- 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 PromoterReportHour batch size: {},执行时间:{}", promoterReportHourBuffer.size(),seconds);
|
|
|
|
|
-
|
|
|
|
|
- promoterReportHourBuffer.clear();
|
|
|
|
|
- promoterReportHourLastFlushTime = now;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("Error flushing PromoterReportHour batch", e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- synchronized (promoterReportDailyBuffer) {
|
|
|
|
|
- long now = System.currentTimeMillis();
|
|
|
|
|
- // promoterReportDailyBuffer.size() >= MAX_BATCH_SIZE || (now - promoterReportDailyLastFlushTime) >= MAX_WAIT_TIME_MS &&
|
|
|
|
|
- if ( !promoterReportDailyBuffer.isEmpty()) {
|
|
|
|
|
- try {
|
|
|
|
|
- long startTime = System.currentTimeMillis();
|
|
|
|
|
- promoterReportMapper.replacePromoterReportDailiesSD(new ArrayList<>(promoterReportDailyBuffer));
|
|
|
|
|
- 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 PromoterReportDaily batch size: {},执行时间:{}", promoterReportDailyBuffer.size(),seconds);
|
|
|
|
|
-
|
|
|
|
|
- promoterReportDailyBuffer.clear();
|
|
|
|
|
- promoterReportDailyLastFlushTime = now;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("Error flushing PromoterReportDaily batch", e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- @PreDestroy
|
|
|
|
|
- public void flushPreDestroy() {
|
|
|
|
|
- log.info("项目重启,开始执行广告报表批处理任务....");
|
|
|
|
|
- synchronized (promoterReportHourBuffer) {
|
|
|
|
|
- if (!promoterReportHourBuffer.isEmpty()) {
|
|
|
|
|
- try {
|
|
|
|
|
- log.info("Flushed PromoterReportHour batch size: {}", promoterReportHourBuffer.size());
|
|
|
|
|
- promoterReportMapper.replacePromoterReportHourSD(new ArrayList<>(promoterReportHourBuffer));
|
|
|
|
|
- promoterReportHourBuffer.clear();
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("Error flushing PromoterReportHour batch", e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- synchronized (promoterReportDailyBuffer) {
|
|
|
|
|
- if (!promoterReportDailyBuffer.isEmpty()) {
|
|
|
|
|
- try {
|
|
|
|
|
- log.info("Flushed promoterReportDaily batch size: {}", promoterReportDailyBuffer.size());
|
|
|
|
|
- promoterReportMapper.replacePromoterReportDailiesSD(new ArrayList<>(promoterReportDailyBuffer));
|
|
|
|
|
- promoterReportDailyBuffer.clear();
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("Error flushing promoterReportDaily batch", e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }*/
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|