Bläddra i källkod

从 maxCompute查改成从 ck查

wcc 3 år sedan
förälder
incheckning
0511f90815
20 ändrade filer med 1513 tillägg och 1078 borttagningar
  1. 104 0
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/AdDayStreamJob.java
  2. 3 173
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/AdStatJob.java
  3. 14 32
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/PlanDayStreamJob.java
  4. 3 19
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/Test.java
  5. 4 1
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/dao/mapper/AdStatOfDayDWDMapper.java
  6. 12 2
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/dao/mapper/AdStatOfDayDWDMapper.xml
  7. 18 0
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/dao/mapper/PlanStatOfDayDWDMapper.java
  8. 263 0
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/dao/mapper/PlanStatOfDayDWDMapper.xml
  9. 418 289
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/pojo/entity/AdStatOfHourDWD.java
  10. 245 308
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/pojo/entity/PlanStatOfHourDWD.java
  11. 46 38
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/AdDayDWDRollMonthProcess.java
  12. 8 9
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/AdDayDWDRollYearProcess.java
  13. 53 38
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/AdHourDWDProcess.java
  14. 32 35
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/AdMinuteDWDProcess.java
  15. 97 0
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/PlanDayDWDRollMonthProcess.java
  16. 31 0
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/PlanDayDWDRollYearProcess.java
  17. 52 41
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/PlanHourDWDProcess.java
  18. 32 34
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/PlanMinuteDWDProcess.java
  19. 3 59
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/sink/AdDWDToCkBatchSink.java
  20. 75 0
      flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/sink/PlanDWDToCkBatchSink.java

+ 104 - 0
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/AdDayStreamJob.java

@@ -0,0 +1,104 @@
+package flink.zanxiangnet.ad.monitoring;
+
+import flink.zanxiangnet.ad.monitoring.kafka.KafkaComponent;
+import flink.zanxiangnet.ad.monitoring.pojo.dto.AdStatOfDayODSDTO;
+import flink.zanxiangnet.ad.monitoring.pojo.entity.AdDataOfDayODS;
+import flink.zanxiangnet.ad.monitoring.pojo.entity.AdStatOfDayDWD;
+import flink.zanxiangnet.ad.monitoring.process.AdDayDWDRollMonthProcess;
+import flink.zanxiangnet.ad.monitoring.process.AdDayDWDRollYearProcess;
+import flink.zanxiangnet.ad.monitoring.sink.AdDWDToCkBatchSink;
+import flink.zanxiangnet.ad.monitoring.sink.TunnelBatchStreamSink;
+import flink.zanxiangnet.ad.monitoring.stream.BatchStream;
+import flink.zanxiangnet.ad.monitoring.stream.KeyedBatchStream;
+import flink.zanxiangnet.ad.monitoring.util.DateUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connector.kafka.source.KafkaSource;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.ProcessFunction;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.OutputTag;
+
+import java.time.LocalDate;
+import java.util.Properties;
+
+@Slf4j
+public class AdDayStreamJob {
+
+    public static void main(String[] args) throws Exception {
+        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+
+        // 加载配置文件到 flink的全局配置中
+        Properties props = new Properties();
+        props.load(AdStatJob.class.getResourceAsStream("/application.properties"));
+        Configuration configuration = new Configuration();
+        props.stringPropertyNames().forEach(key -> {
+            String value = props.getProperty(key);
+            configuration.setString(key.trim(), StringUtils.isBlank(value) ? "" : value.trim());
+        });
+        env.getConfig().setGlobalJobParameters(configuration);
+
+        KafkaSource<String> adStreamOfDaySource = KafkaComponent.buildKafkaSource(props, KafkaComponent.KafkaTopic.adDayTopic, KafkaComponent.KafkaTopic.KafkaGroupId.adDayConsumerGroup);
+
+        DataStreamSource<String> adStreamOfDayIn = env.fromSource(adStreamOfDaySource, WatermarkStrategy.noWatermarks(), "adDaySource_kafka");
+
+        // 广告日数据。往前回滚 10天
+        final OutputTag<AdDataOfDayODS> adDayStreamRollDayTag = new OutputTag<AdDataOfDayODS>("adDayStreamRollDayTag") {
+        };
+        // 广告日数据。往前回滚 1年
+        final OutputTag<AdDataOfDayODS> adDayStreamRollYearTag = new OutputTag<AdDataOfDayODS>("adDayStreamRollYearTag") {
+        };
+        SingleOutputStreamOperator<AdStatOfDayODSDTO> adDayODSStream = adStreamOfDayIn.filter(StringUtils::isNotBlank)
+                .map(AdStatOfDayODSDTO::byJson);
+
+        // 写入原始表
+        new KeyedBatchStream<>("adDayODSStream", adDayODSStream.map(AdStatOfDayODSDTO::getAdDataOfDayODS).keyBy(AdDataOfDayODS::getStatDay), 4000L, 60 * 1000L)
+                .toBatch()
+                .addSink(new TunnelBatchStreamSink<>(AdDataOfDayODS.class))
+                .name("sink_ad_day_ods");
+
+        // 拆分流
+        SingleOutputStreamOperator<AdStatOfDayODSDTO> adDayODSStreamSplit = adDayODSStream.process(new ProcessFunction<AdStatOfDayODSDTO, AdStatOfDayODSDTO>() {
+            @Override
+            public void processElement(AdStatOfDayODSDTO adDataDTO, ProcessFunction<AdStatOfDayODSDTO, AdStatOfDayODSDTO>.Context context, Collector<AdStatOfDayODSDTO> collector) throws Exception {
+                LocalDate startDate = adDataDTO.getStartDate();
+                LocalDate endDate = adDataDTO.getEndDate();
+                AdDataOfDayODS adODS = adDataDTO.getAdDataOfDayODS();
+                if (DateUtil.intervalOfDays(startDate, endDate) > 31L) {
+                    // 拉取时间间隔超过 1个月,账号回滚 365天的数据
+                    context.output(adDayStreamRollYearTag, adODS);
+                } else {
+                    // 每日往前回滚 10天的数据
+                    context.output(adDayStreamRollDayTag, adODS);
+                }
+            }
+        });
+
+        // 回滚 30天的数据计算
+        SingleOutputStreamOperator<AdStatOfDayDWD> adDayDWDMonthStream = adDayODSStreamSplit.getSideOutput(adDayStreamRollDayTag)
+                .keyBy(AdDataOfDayODS::getAdId)
+                .countWindow(1)
+                .process(new AdDayDWDRollMonthProcess());
+
+        // 单个账号回滚一年
+        SingleOutputStreamOperator<AdStatOfDayDWD> adDayDWDYearStream = adDayODSStreamSplit.getSideOutput(adDayStreamRollYearTag)
+                .keyBy(AdDataOfDayODS::getAdId)
+                .countWindow(1).process(new AdDayDWDRollYearProcess());
+
+        DataStream<AdStatOfDayDWD> adDayStream = adDayDWDMonthStream.union(adDayDWDYearStream);
+        // 写入 maxCompute
+        new KeyedBatchStream<>("adDayStream", adDayStream.keyBy(AdStatOfDayDWD::getStatDay), 4000L, 60 * 1000L)
+                .toBatch()
+                .addSink(new TunnelBatchStreamSink<>(AdStatOfDayDWD.class))
+                .name("sink_ad_year_dwd");
+        // 写入 ck
+        new BatchStream<>("adDWDToCkStream", adDayStream, 1000L, 60 * 1000L).toBatch().addSink(new AdDWDToCkBatchSink());
+
+        env.execute("ad_day_stream_job");
+    }
+}

+ 3 - 173
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/AdStatJob.java

@@ -15,7 +15,9 @@ import flink.zanxiangnet.ad.monitoring.pojo.dto.AdStatOfDayODSDTO;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.*;
 import flink.zanxiangnet.ad.monitoring.pojo.properties.ApplicationProperties;
 import flink.zanxiangnet.ad.monitoring.process.*;
+import flink.zanxiangnet.ad.monitoring.sink.AdDWDToCkBatchSink;
 import flink.zanxiangnet.ad.monitoring.sink.TunnelBatchStreamSink;
+import flink.zanxiangnet.ad.monitoring.stream.BatchStream;
 import flink.zanxiangnet.ad.monitoring.stream.KeyedBatchStream;
 import flink.zanxiangnet.ad.monitoring.trigger.AdMinuteODSStreamTrigger;
 import flink.zanxiangnet.ad.monitoring.trigger.CostMinuteDMStreamTrigger;
@@ -163,182 +165,10 @@ public class AdStatJob {
                         .process(new CostHourProcess())
                         .name("sink_ad_hour_dm_clickhouse");
 
-//        clickhouseHourDmStream.print();
         BatchSinkHour batchSinkhour = new BatchSinkHour();
         clickhouseHourDmStream.addSink(batchSinkhour);
 
 
-        // ------------------------------------------------------- 处理广告的天数据 -----------------------------------------
-        KafkaSource<String> adStreamOfDaySource = KafkaComponent.buildKafkaSource(props, KafkaComponent.KafkaTopic.adDayTopic, KafkaComponent.KafkaTopic.KafkaGroupId.adDayConsumerGroup);
-
-        DataStreamSource<String> adStreamOfDayIn = env.fromSource(adStreamOfDaySource, WatermarkStrategy.noWatermarks(), "adDaySource_kafka");
-
-        // 广告日数据。往前回滚 10天
-        final OutputTag<AdDataOfDayODS> adDayStreamRollDayTag = new OutputTag<AdDataOfDayODS>("adDayStreamRollDayTag") {
-        };
-        // 广告日数据。往前回滚 1年
-        final OutputTag<AdDataOfDayODS> adDayStreamRollYearTag = new OutputTag<AdDataOfDayODS>("adDayStreamRollYearTag") {
-        };
-        SingleOutputStreamOperator<AdStatOfDayODSDTO> adDayODSStream = adStreamOfDayIn.filter(StringUtils::isNotBlank)
-                .map(str -> {
-                    AdDataOfDayDTO dto = JsonUtil.toObj(str, AdDataOfDayDTO.class);
-                    Date createTime = new Date(dto.getCreateTime());
-                    DailyReportsGetListStruct struct = dto.getDailyReportsGetListStruct();
-                    AdDataOfDayODS adODS = new AdDataOfDayODS();
-                    BeanUtils.copyProperties(struct, adODS);
-                    adODS.setStatDay(struct.getDate());
-                    adODS.setAccountId(dto.getAccountId());
-                    adODS.setCampaignId(struct.getCampaignId());
-                    adODS.setAgencyAccountId(struct.getAccountId());
-                    adODS.setWechatAccountId(struct.getWechatAccountId());
-                    adODS.setAdgroupId(struct.getAdgroupId());
-                    adODS.setAdId(struct.getAdId());
-                    adODS.setCreateTime(createTime);
-                    adODS.removeNull();
-                    return AdStatOfDayODSDTO.builder()
-                            .startDate(dto.getStartDate())
-                            .endDate(dto.getEndDate())
-                            .adDataOfDayODS(adODS)
-                            .build();
-                });
-        new KeyedBatchStream<>("adDayODSStream", adDayODSStream.map(AdStatOfDayODSDTO::getAdDataOfDayODS).keyBy(AdDataOfDayODS::getStatDay), 4000L, 60 * 1000L)
-                .toBatch()
-                .addSink(new TunnelBatchStreamSink<>(AdDataOfDayODS.class))
-                .name("sink_ad_day_ods");
-
-        // 拆分流
-        SingleOutputStreamOperator<AdStatOfDayODSDTO> adDayODSStreamSplit = adDayODSStream.process(new ProcessFunction<AdStatOfDayODSDTO, AdStatOfDayODSDTO>() {
-            @Override
-            public void processElement(AdStatOfDayODSDTO adDataDTO, ProcessFunction<AdStatOfDayODSDTO, AdStatOfDayODSDTO>.Context context, Collector<AdStatOfDayODSDTO> collector) throws Exception {
-                LocalDate startDate = adDataDTO.getStartDate();
-                LocalDate endDate = adDataDTO.getEndDate();
-                AdDataOfDayODS adODS = adDataDTO.getAdDataOfDayODS();
-                if (DateUtil.intervalOfDays(startDate, endDate) > 31L) {
-                    // 拉取时间间隔超过 1个月,账号回滚 365天的数据
-                    context.output(adDayStreamRollYearTag, adODS);
-                } else {
-                    // 每日往前回滚 10天的数据
-                    context.output(adDayStreamRollDayTag, adODS);
-                }
-            }
-        });
-
-        SingleOutputStreamOperator<AdStatOfDayDWD> adDayDWDStream = adDayODSStreamSplit.getSideOutput(adDayStreamRollDayTag)
-                .keyBy(AdDataOfDayODS::getAdId)
-                .countWindow(1).process(new ProcessWindowFunction<AdDataOfDayODS, AdStatOfDayDWD, Long, GlobalWindow>() {
-                    private Odps odps;
-                    // 上次查询的时间
-                    private ValueState<String> lastQueryDayState;
-                    // 之前聚合的昨天的数据
-                    private MapState<String, AdStatOfDayDWD> historyReduceState;
-
-                    @Override
-                    public void open(Configuration conf) {
-                        Map<String, String> params = getRuntimeContext()
-                                .getExecutionConfig()
-                                .getGlobalJobParameters()
-                                .toMap();
-                        Account account = new AliyunAccount(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ID),
-                                params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_KEY));
-                        odps = new Odps(account);
-                        odps.getRestClient().setRetryLogger(new MaxComputeLog());
-                        odps.setEndpoint(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ENDPOINT));
-                        odps.setDefaultProject(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_PROJECT_NAME));
-
-                        lastQueryDayState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastQueryDayState", String.class));
-                        historyReduceState = getRuntimeContext().getMapState(new MapStateDescriptor<>("historyReduceState", String.class, AdStatOfDayDWD.class));
-                    }
-
-                    @Override
-                    public void process(Long elementsCount, ProcessWindowFunction<AdDataOfDayODS, AdStatOfDayDWD, Long, GlobalWindow>.Context context, Iterable<AdDataOfDayODS> iterable, Collector<AdStatOfDayDWD> collector) throws Exception {
-                        AdDataOfDayODS element = iterable.iterator().next();
-                        LocalDate statDay = DateUtil.parseLocalDate(element.getStatDay());
-                        long now = System.currentTimeMillis();
-
-                        String lastQueryDay = lastQueryDayState.value();
-                        // 从 maxCompute查找广告的历史数据
-                        if (lastQueryDay == null || !lastQueryDay.equals(DateUtil.formatLocalDate(LocalDate.now()))) {
-                            LocalDate endTime = LocalDate.now(), beginTime = statDay.minusDays(60);
-                            String sql = "SELECT * FROM ad_stat_of_day_dwd WHERE stat_day >= \"" + DateUtil.formatLocalDate(beginTime) + "\" AND stat_day <= \"" + DateUtil.formatLocalDate(endTime) + "\" AND ad_id = " + element.getAdId() + ";";
-                            Instance instance = SQLTask.run(odps, sql);
-                            // log.error("sql: " + sql + ", odps日志: " + odps.logview().generateLogView(instance, 7 * 24));
-                            instance.waitForSuccess();
-                            List<Record> records = SQLTask.getResult(instance);
-                            Map<String, AdStatOfDayDWD> historyData = records.stream()
-                                    .map(AdStatOfDayDWD::byMaxCompute)
-                                    .sorted((o1, o2) -> new Long(o1.getCreateTime().getTime() - o2.getCreateTime().getTime()).intValue())
-                                    .collect(Collectors.toMap(AdStatOfDayDWD::getStatDay, data -> data, (val1, val2) -> val2));
-                            historyReduceState.clear();
-                            historyReduceState.putAll(historyData);
-                            lastQueryDayState.update(DateUtil.formatLocalDate(LocalDate.now()));
-                        }
-                        AdStatOfDayDWD lastReduceData = null;
-                        for (int i = 1; i <= 60; i++) {
-                            lastReduceData = historyReduceState.get(DateUtil.formatLocalDate(statDay.minusDays(i)));
-                            if (lastReduceData != null) {
-                                break;
-                            }
-                        }
-                        AdStatOfDayDWD newStatData = AdStatOfDayDWD.reduce(lastReduceData, element, now);
-                        historyReduceState.put(DateUtil.formatLocalDate(statDay), newStatData);
-                        collector.collect(newStatData);
-                    }
-                });
-        //.addSink(new TunnelBatchSink<>(AdStatOfDayDWD.class, 30000L, 365L, 6));
-        new KeyedBatchStream<>("adDayDWDStream", adDayDWDStream.keyBy(AdStatOfDayDWD::getStatDay), 4000L, 60 * 1000L)
-                .toBatch()
-                .addSink(new TunnelBatchStreamSink<>(AdStatOfDayDWD.class))
-                .name("sink_ad_day_dwd");
-
-//        //小时数据-----天
-//        SingleOutputStreamOperator<CostHourDM> clickhouseHourDayDmStream =
-//                adDayDWDStream
-//                        .keyBy(AdStatOfDayDWD::getAdId)
-//                        .countWindow(1)
-//                        .process(new CostHourDayProcess())
-//                        .name("sink_ad_hour_day_dm_clickhouse");
-//
-////        clickhouseHourDayDmStream.print();
-//        BatchSinkHour batchSinkHourDay = new BatchSinkHour();
-//        clickhouseHourDayDmStream.addSink(batchSinkHourDay);
-
-
-        SingleOutputStreamOperator<AdStatOfDayDWD> adDayDWDYearStream = adDayODSStreamSplit.getSideOutput(adDayStreamRollYearTag)
-                .keyBy(AdDataOfDayODS::getAdId)
-                .countWindow(1).process(new ProcessWindowFunction<AdDataOfDayODS, AdStatOfDayDWD, Long, GlobalWindow>() {
-                    // 上次聚合的结果
-                    private ValueState<AdStatOfDayDWD> lastReduceState;
-
-                    public void open(Configuration conf) {
-                        lastReduceState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastReduceState", AdStatOfDayDWD.class));
-                    }
-
-                    @Override
-                    public void process(Long elementsCount, ProcessWindowFunction<AdDataOfDayODS, AdStatOfDayDWD, Long, GlobalWindow>.Context context,
-                                        Iterable<AdDataOfDayODS> elements, Collector<AdStatOfDayDWD> out) throws Exception {
-                        AdDataOfDayODS element = elements.iterator().next();
-                        AdStatOfDayDWD newStatDWD = AdStatOfDayDWD.reduce(lastReduceState.value(), element, System.currentTimeMillis());
-                        lastReduceState.update(newStatDWD);
-                        out.collect(newStatDWD);
-                    }
-                });
-        new KeyedBatchStream<>("adDayDWDYearStream", adDayDWDYearStream.keyBy(AdStatOfDayDWD::getStatDay), 4000L, 60 * 1000L)
-                .toBatch()
-                .addSink(new TunnelBatchStreamSink<>(AdStatOfDayDWD.class))
-                .name("sink_ad_year_dwd");
-//        //小时数据----年
-//        SingleOutputStreamOperator<CostHourDM> clickhouseHourYearDmStream =
-//                adDayDWDYearStream
-//                        .keyBy(AdStatOfDayDWD::getAdId)
-//                        .countWindow(1)
-//                        .process(new CostHourDayProcess())
-//                        .name("sink_ad_hour_year_dm_clickhouse");
-//
-////        clickhouseHourYearDmStream.print();
-//        BatchSinkHour batchSinkHourYear = new BatchSinkHour();
-//        clickhouseHourYearDmStream.addSink(batchSinkHourYear);
-
-        //TODO:jobname----后面应该带个时间以此来区分log以及job
-        env.execute("job_ad");
+        env.execute("ad_hour_stream_job");
     }
 }

+ 14 - 32
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/PlanDayStreamJob.java

@@ -1,50 +1,31 @@
 package flink.zanxiangnet.ad.monitoring;
 
-import com.aliyun.odps.Instance;
-import com.aliyun.odps.Odps;
-import com.aliyun.odps.account.Account;
-import com.aliyun.odps.account.AliyunAccount;
-import com.aliyun.odps.data.Record;
-import com.aliyun.odps.task.SQLTask;
-import com.tencent.ads.model.DailyReportsGetListStruct;
 import flink.zanxiangnet.ad.monitoring.kafka.KafkaComponent;
-import flink.zanxiangnet.ad.monitoring.maxcompute.MaxComputeLog;
-import flink.zanxiangnet.ad.monitoring.pojo.dto.AdDataOfDayDTO;
 import flink.zanxiangnet.ad.monitoring.pojo.dto.AdStatOfDayODSDTO;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.AdDataOfDayODS;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.PlanStatOfDayDWD;
-import flink.zanxiangnet.ad.monitoring.pojo.properties.ApplicationProperties;
-import flink.zanxiangnet.ad.monitoring.process.AdDayDWDRollMonthProcess;
-import flink.zanxiangnet.ad.monitoring.process.AdDayDWDRollYearProcess;
+import flink.zanxiangnet.ad.monitoring.process.PlanDayDWDRollMonthProcess;
+import flink.zanxiangnet.ad.monitoring.process.PlanDayDWDRollYearProcess;
+import flink.zanxiangnet.ad.monitoring.sink.PlanDWDToCkBatchSink;
 import flink.zanxiangnet.ad.monitoring.sink.TunnelBatchStreamSink;
+import flink.zanxiangnet.ad.monitoring.stream.BatchStream;
 import flink.zanxiangnet.ad.monitoring.stream.KeyedBatchStream;
 import flink.zanxiangnet.ad.monitoring.util.DateUtil;
-import flink.zanxiangnet.ad.monitoring.util.JsonUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.flink.api.common.eventtime.WatermarkStrategy;
-import org.apache.flink.api.common.state.MapState;
-import org.apache.flink.api.common.state.MapStateDescriptor;
-import org.apache.flink.api.common.state.ValueState;
-import org.apache.flink.api.common.state.ValueStateDescriptor;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.connector.kafka.source.KafkaSource;
+import org.apache.flink.streaming.api.datastream.DataStream;
 import org.apache.flink.streaming.api.datastream.DataStreamSource;
 import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
 import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
 import org.apache.flink.streaming.api.functions.ProcessFunction;
-import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
-import org.apache.flink.streaming.api.windowing.windows.GlobalWindow;
 import org.apache.flink.util.Collector;
 import org.apache.flink.util.OutputTag;
-import org.springframework.beans.BeanUtils;
 
 import java.time.LocalDate;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
 import java.util.Properties;
-import java.util.stream.Collectors;
 
 @Slf4j
 public class PlanDayStreamJob {
@@ -93,24 +74,25 @@ public class PlanDayStreamJob {
         });
 
         // 每日回滚 30天
-        SingleOutputStreamOperator<PlanStatOfDayDWD> planDayDWDStream = adDayODSStreamSplit.getSideOutput(adDayStreamRollDayTag)
+        SingleOutputStreamOperator<PlanStatOfDayDWD> planDayDWDMonthStream = adDayODSStreamSplit.getSideOutput(adDayStreamRollDayTag)
                 .keyBy(AdDataOfDayODS::getCampaignId)
                 .countWindow(1)
-                .process(new AdDayDWDRollMonthProcess());
-        new KeyedBatchStream<>("planDayDWDStream", planDayDWDStream.keyBy(PlanStatOfDayDWD::getStatDay), 4000L, 60 * 1000L)
-                .toBatch()
-                .addSink(new TunnelBatchStreamSink<>(PlanStatOfDayDWD.class))
-                .name("sink_plan_day_dwd");
+                .process(new PlanDayDWDRollMonthProcess());
 
         // 往前回滚 365天
         SingleOutputStreamOperator<PlanStatOfDayDWD> planDayDWDYearStream = adDayODSStreamSplit.getSideOutput(adDayStreamRollYearTag)
                 .keyBy(AdDataOfDayODS::getCampaignId)
                 .countWindow(1)
-                .process(new AdDayDWDRollYearProcess());
-        new KeyedBatchStream<>("planDayDWDYearStream", planDayDWDYearStream.keyBy(PlanStatOfDayDWD::getStatDay), 4000L, 60 * 1000L)
+                .process(new PlanDayDWDRollYearProcess());
+
+        DataStream<PlanStatOfDayDWD> planDayDWDStream = planDayDWDMonthStream.union(planDayDWDYearStream);
+        // 写入 maxCompute
+        new KeyedBatchStream<>("planDayDWDStream", planDayDWDStream.keyBy(PlanStatOfDayDWD::getStatDay), 4000L, 60 * 1000L)
                 .toBatch()
                 .addSink(new TunnelBatchStreamSink<>(PlanStatOfDayDWD.class))
                 .name("sink_plan_year_dwd");
+        // 写入 ck
+        new BatchStream<>("planDWDToCkStream", planDayDWDStream, 1000L, 60 * 1000L).toBatch().addSink(new PlanDWDToCkBatchSink());
 
         env.execute("plan_day_stream_job");
     }

+ 3 - 19
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/Test.java

@@ -1,9 +1,8 @@
 package flink.zanxiangnet.ad.monitoring;
 
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import flink.zanxiangnet.ad.monitoring.sink.ClickhouseBatchStreamSink;
+import flink.zanxiangnet.ad.monitoring.sink.AdDWDToCkBatchSink;
 import flink.zanxiangnet.ad.monitoring.stream.BatchStream;
-import flink.zanxiangnet.ad.monitoring.stream.KeyedBatchStream;
 import flink.zanxiangnet.ad.monitoring.util.DateUtil;
 import flink.zanxiangnet.ad.monitoring.util.JsonUtil;
 import lombok.AllArgsConstructor;
@@ -14,13 +13,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.flink.api.common.eventtime.SerializableTimestampAssigner;
 import org.apache.flink.api.common.eventtime.WatermarkStrategy;
-import org.apache.flink.api.common.state.MapState;
-import org.apache.flink.api.common.state.MapStateDescriptor;
-import org.apache.flink.api.common.typeinfo.Types;
-import org.apache.flink.api.java.functions.KeySelector;
-import org.apache.flink.api.java.tuple.Tuple2;
-import org.apache.flink.api.java.tuple.Tuple3;
-import org.apache.flink.api.java.tuple.Tuple5;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.streaming.api.datastream.DataStreamSource;
 import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
@@ -31,22 +23,15 @@ import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindo
 import org.apache.flink.streaming.api.windowing.time.Time;
 import org.apache.flink.streaming.api.windowing.triggers.Trigger;
 import org.apache.flink.streaming.api.windowing.triggers.TriggerResult;
-import org.apache.flink.streaming.api.windowing.windows.GlobalWindow;
 import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
 import org.apache.flink.util.Collector;
 
 import java.time.Duration;
-import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
 import java.util.Properties;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
-import java.util.stream.Collectors;
 
 @Slf4j
 public class Test {
@@ -69,7 +54,7 @@ public class Test {
         SingleOutputStreamOperator<Pojo> pojoStream = source.assignTimestampsAndWatermarks(WatermarkStrategy.<Pojo>forBoundedOutOfOrderness(Duration.ofHours(2))
                 .withTimestampAssigner((SerializableTimestampAssigner<Pojo>) (pojo, l) -> pojo.getCreateTime())
         );
-        SingleOutputStreamOperator<String> stringStream = pojoStream.keyBy(Pojo::getUserId)
+        pojoStream.keyBy(Pojo::getUserId)
                 .window(TumblingEventTimeWindows.of(Time.days(1L), Time.hours(-8)))
                 .trigger(new Trigger<Pojo, TimeWindow>() {
                     /**
@@ -149,8 +134,7 @@ public class Test {
                             collector.collect(pojo);
                         }
                     }
-                }).map(Pojo::toString);
-        new BatchStream<>("", stringStream, 10L, 60 * 1000L).toBatch().addSink(new ClickhouseBatchStreamSink<>());
+                }).print();
                 /*.aggregate(new AggregateFunction<Pojo, Tuple5<Integer, Long, Long, Integer, List<Long>>, String>() {
 
                     @Override

+ 4 - 1
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/dao/mapper/AdStatOfDayDWDMapper.java

@@ -7,7 +7,10 @@ import java.util.List;
 
 public interface AdStatOfDayDWDMapper {
 
-    List<AdStatOfDayDWD> selectAll();
+    List<AdStatOfDayDWD> lastReduceResult(@Param("adId") Long adId,
+                                          @Param("beginDay") String beginDay,
+                                          @Param("endDay") String endDay,
+                                          @Param("queryCount") int queryCount);
 
     int add(@Param("item") AdStatOfDayDWD adStatOfDayDWD);
 

+ 12 - 2
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/dao/mapper/AdStatOfDayDWDMapper.xml

@@ -83,8 +83,18 @@
         no_interest_count_total, no_interest_count_day
     </sql>
 
-    <select id="selectAll" resultType="AdStatOfDayDWD">
-        select * from ad_stat_of_day
+    <select id="lastReduceResult" resultType="AdStatOfDayDWD">
+        select
+        <include refid="Base_Column_List"/>
+        from ad_stat_of_day
+        where ad_id = #{adId}
+        <if test="beginDay != null and beginDay != ''">
+            and stat_day >= #{beginDay}
+        </if>
+        <if test="endDay != null and endDay != ''">
+            and endDay <![CDATA[ <= ]]> #{endDay}
+        </if>
+        order by stat_day desc, create_time desc limit ${queryCount}};
     </select>
 
     <insert id="add">

+ 18 - 0
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/dao/mapper/PlanStatOfDayDWDMapper.java

@@ -0,0 +1,18 @@
+package flink.zanxiangnet.ad.monitoring.dao.mapper;
+
+import flink.zanxiangnet.ad.monitoring.pojo.entity.PlanStatOfDayDWD;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface PlanStatOfDayDWDMapper {
+
+    List<PlanStatOfDayDWD> lastReduceResult(@Param("campaignId") Long campaignId,
+                                     @Param("beginDay") String beginDay,
+                                     @Param("endDay") String endDay,
+                                     @Param("queryCount") int queryCount);
+
+    int add(@Param("item") PlanStatOfDayDWD adStatOfDayDWD);
+
+    int addBatch(@Param("list") List<PlanStatOfDayDWD> list);
+}

+ 263 - 0
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/dao/mapper/PlanStatOfDayDWDMapper.xml

@@ -0,0 +1,263 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="flink.zanxiangnet.ad.monitoring.dao.mapper.PlanStatOfDayDWDMapper">
+
+    <sql id="Base_Column_List">
+        stat_day, account_id,
+        campaign_id, agency_account_id,
+        wechat_account_id, wechat_agency_id,
+        ad_group_map_str, ad_ids_str, create_time,
+        cost_deviation_rate_total, cost_deviation_rate_day,
+        cost_total, cost_day,
+        compensation_amount_total, compensation_amount_day,
+        view_count_total, view_count_day,
+        thousand_display_price_all, thousand_display_price_day,
+        view_user_count_total, view_user_count_day,
+        avg_view_per_user_all, avg_view_per_user_day,
+        valid_click_count_total, valid_click_count_day,
+        click_user_count_total, click_user_count_day,
+        ctr_all, ctr_day,
+        cpc_all, cpc_day,
+        valuable_click_count_total, valuable_click_count_day,
+        valuable_click_rate_all, valuable_click_rate_day,
+        valuable_click_cost_all, valuable_click_cost_day,
+        conversions_count_total, conversions_count_day,
+        conversions_cost_all, conversions_cost_day,
+        conversions_rate_all, conversions_rate_day,
+        deep_conversions_count_total, deep_conversions_count_day,
+        deep_conversions_cost_all, deep_conversions_cost_day,
+        deep_conversions_rate_all, deep_conversions_rate_day,
+        key_page_uv_total, key_page_uv_day,
+        order_count_total, order_count_day,
+        first_day_order_count_total, first_day_order_count_day,
+        web_order_cost_all, web_order_cost_day,
+        order_rate_all, order_rate_day,
+        order_amount_total, order_amount_day,
+        first_day_order_amount_total, first_day_order_amount_day,
+        order_unit_price_all, order_unit_price_day,
+        order_roi_all, order_roi_day,
+        sign_in_count_total, sign_in_count_day,
+        add_wishlist_count_total, add_wishlist_count_day,
+        view_commodity_page_uv_total, view_commodity_page_uv_day,
+        page_reservation_count_total, page_reservation_count_day,
+        leads_purchase_uv_total, leads_purchase_uv_day,
+        leads_purchase_cost_all, leads_purchase_cost_day,
+        leads_purchase_rate_all, leads_purchase_rate_day,
+        scan_follow_count_total, scan_follow_count_day,
+        wechat_app_register_uv_total, wechat_app_register_uv_day,
+        wechat_minigame_register_cost_all, wechat_minigame_register_cost_day,
+        wechat_minigame_register_rate_all, wechat_minigame_register_rate_day,
+        wechat_minigame_arpu_all, wechat_minigame_arpu_day,
+        wechat_minigame_retention_count_total, wechat_minigame_retention_count_day,
+        wechat_minigame_checkout_count_total, wechat_minigame_checkout_count_day,
+        wechat_minigame_checkout_amount_total, wechat_minigame_checkout_amount_day,
+        official_account_follow_count_total, official_account_follow_count_day,
+        official_account_follow_cost_all, official_account_follow_cost_day,
+        official_account_follow_rate_all, official_account_follow_rate_day,
+        official_account_register_user_count_total, official_account_register_user_count_day,
+        official_account_register_rate_all, official_account_register_rate_day,
+        official_account_register_cost_all, official_account_register_cost_day,
+        official_account_register_amount_total, official_account_register_amount_day,
+        official_account_register_roi_all, official_account_register_roi_day,
+        official_account_apply_count_total, official_account_apply_count_day,
+        official_account_apply_user_count_total, official_account_apply_user_count_day,
+        official_account_apply_rate_all, official_account_apply_rate_day,
+        official_account_apply_cost_all, official_account_apply_cost_day,
+        official_account_apply_amount_total, official_account_apply_amount_day,
+        official_account_apply_roi_all, official_account_apply_roi_day,
+        official_account_order_count_total, official_account_order_count_day,
+        official_account_first_day_order_count_total, official_account_first_day_order_count_day,
+        official_account_order_user_count_total, official_account_order_user_count_day,
+        official_account_order_rate_all, official_account_order_rate_day,
+        official_account_order_cost_all, official_account_order_cost_day,
+        official_account_order_amount_total, official_account_order_amount_day,
+        official_account_first_day_order_amount_total, official_account_first_day_order_amount_day,
+        official_account_order_roi_all, official_account_order_roi_day,
+        official_account_consult_count_total, official_account_consult_count_day,
+        official_account_reader_count_total, official_account_reader_count_day,
+        official_account_credit_apply_user_count_total, official_account_credit_apply_user_count_day,
+        official_account_credit_user_count_total, official_account_credit_user_count_day,
+        forward_count_total, forward_count_day,
+        forward_user_count_total, forward_user_count_day,
+        no_interest_count_total, no_interest_count_day
+    </sql>
+
+    <select id="lastReduceResult" resultType="PlanStatOfDayDWD">
+        select <include refid="Base_Column_List"/>
+        from plan_stat_of_day where campaign_id = #{campaignId}
+        <if test="beginDay != null and beginDay != ''">
+            and stat_day >= #{beginDay}
+        </if>
+        <if test="endDay != null and endDay != ''">
+            and endDay <![CDATA[ <= ]]> #{endDay}
+        </if>
+        order by stat_day desc, create_time desc limit ${queryCount}};
+    </select>
+
+    <insert id="add">
+        INSERT INTO plan_stat_of_day(<include refid="Base_Column_List"/>)
+        VALUES
+        ( #{item.statDay}, #{item.accountId},
+        #{item.campaignId}, #{item.agencyAccountId},
+        #{item.wechatAccountId}, #{item.wechatAgencyId},
+        #{item.adGroupMapStr}, #{item.adIdsStr}, #{item.createTime},
+        #{item.costDeviationRateTotal}, #{item.costDeviationRateDay},
+        #{item.costTotal}, #{item.costDay},
+        #{item.compensationAmountTotal}, #{item.compensationAmountDay},
+        #{item.viewCountTotal}, #{item.viewCountDay},
+        #{item.thousandDisplayPriceAll}, #{item.thousandDisplayPriceDay},
+        #{item.viewUserCountTotal}, #{item.viewUserCountDay},
+        #{item.avgViewPerUserAll}, #{item.avgViewPerUserDay},
+        #{item.validClickCountTotal}, #{item.validClickCountDay},
+        #{item.clickUserCountTotal}, #{item.clickUserCountDay},
+        #{item.ctrAll}, #{item.ctrDay},
+        #{item.cpcAll}, #{item.cpcDay},
+        #{item.valuableClickCountTotal}, #{item.valuableClickCountDay},
+        #{item.valuableClickRateAll}, #{item.valuableClickRateDay},
+        #{item.valuableClickCostAll}, #{item.valuableClickCostDay},
+        #{item.conversionsCountTotal}, #{item.conversionsCountDay},
+        #{item.conversionsCostAll}, #{item.conversionsCostDay},
+        #{item.conversionsRateAll}, #{item.conversionsRateDay},
+        #{item.deepConversionsCountTotal}, #{item.deepConversionsCountDay},
+        #{item.deepConversionsCostAll}, #{item.deepConversionsCostDay},
+        #{item.deepConversionsRateAll}, #{item.deepConversionsRateDay},
+        #{item.keyPageUvTotal}, #{item.keyPageUvDay},
+        #{item.orderCountTotal}, #{item.orderCountDay},
+        #{item.firstDayOrderCountTotal}, #{item.firstDayOrderCountDay},
+        #{item.webOrderCostAll}, #{item.webOrderCostDay},
+        #{item.orderRateAll}, #{item.orderRateDay},
+        #{item.orderAmountTotal}, #{item.orderAmountDay},
+        #{item.firstDayOrderAmountTotal}, #{item.firstDayOrderAmountDay},
+        #{item.orderUnitPriceAll}, #{item.orderUnitPriceDay},
+        #{item.orderRoiAll}, #{item.orderRoiDay},
+        #{item.signInCountTotal}, #{item.signInCountDay},
+        #{item.addWishlistCountTotal}, #{item.addWishlistCountDay},
+        #{item.viewCommodityPageUvTotal}, #{item.viewCommodityPageUvDay},
+        #{item.pageReservationCountTotal}, #{item.pageReservationCountDay},
+        #{item.leadsPurchaseUvTotal}, #{item.leadsPurchaseUvDay},
+        #{item.leadsPurchaseCostAll}, #{item.leadsPurchaseCostDay},
+        #{item.leadsPurchaseRateAll}, #{item.leadsPurchaseRateDay},
+        #{item.scanFollowCountTotal}, #{item.scanFollowCountDay},
+        #{item.wechatAppRegisterUvTotal}, #{item.wechatAppRegisterUvDay},
+        #{item.wechatMinigameRegisterCostAll}, #{item.wechatMinigameRegisterCostDay},
+        #{item.wechatMinigameRegisterRateAll}, #{item.wechatMinigameRegisterRateDay},
+        #{item.wechatMinigameArpuAll}, #{item.wechatMinigameArpuDay},
+        #{item.wechatMinigameRetentionCountTotal}, #{item.wechatMinigameRetentionCountDay},
+        #{item.wechatMinigameCheckoutCountTotal}, #{item.wechatMinigameCheckoutCountDay},
+        #{item.wechatMinigameCheckoutAmountTotal}, #{item.wechatMinigameCheckoutAmountDay},
+        #{item.officialAccountFollowCountTotal}, #{item.officialAccountFollowCountDay},
+        #{item.officialAccountFollowCostAll}, #{item.officialAccountFollowCostDay},
+        #{item.officialAccountFollowRateAll}, #{item.officialAccountFollowRateDay},
+        #{item.officialAccountRegisterUserCountTotal}, #{item.officialAccountRegisterUserCountDay},
+        #{item.officialAccountRegisterRateAll}, #{item.officialAccountRegisterRateDay},
+        #{item.officialAccountRegisterCostAll}, #{item.officialAccountRegisterCostDay},
+        #{item.officialAccountRegisterAmountTotal}, #{item.officialAccountRegisterAmountDay},
+        #{item.officialAccountRegisterRoiAll}, #{item.officialAccountRegisterRoiDay},
+        #{item.officialAccountApplyCountTotal}, #{item.officialAccountApplyCountDay},
+        #{item.officialAccountApplyUserCountTotal}, #{item.officialAccountApplyUserCountDay},
+        #{item.officialAccountApplyRateAll}, #{item.officialAccountApplyRateDay},
+        #{item.officialAccountApplyCostAll}, #{item.officialAccountApplyCostDay},
+        #{item.officialAccountApplyAmountTotal}, #{item.officialAccountApplyAmountDay},
+        #{item.officialAccountApplyRoiAll}, #{item.officialAccountApplyRoiDay},
+        #{item.officialAccountOrderCountTotal}, #{item.officialAccountOrderCountDay},
+        #{item.officialAccountFirstDayOrderCountTotal}, #{item.officialAccountFirstDayOrderCountDay},
+        #{item.officialAccountOrderUserCountTotal}, #{item.officialAccountOrderUserCountDay},
+        #{item.officialAccountOrderRateAll}, #{item.officialAccountOrderRateDay},
+        #{item.officialAccountOrderCostAll}, #{item.officialAccountOrderCostDay},
+        #{item.officialAccountOrderAmountTotal}, #{item.officialAccountOrderAmountDay},
+        #{item.officialAccountFirstDayOrderAmountTotal}, #{item.officialAccountFirstDayOrderAmountDay},
+        #{item.officialAccountOrderRoiAll}, #{item.officialAccountOrderRoiDay},
+        #{item.officialAccountConsultCountTotal}, #{item.officialAccountConsultCountDay},
+        #{item.officialAccountReaderCountTotal}, #{item.officialAccountReaderCountDay},
+        #{item.officialAccountCreditApplyUserCountTotal}, #{item.officialAccountCreditApplyUserCountDay},
+        #{item.officialAccountCreditUserCountTotal}, #{item.officialAccountCreditUserCountDay},
+        #{item.forwardCountTotal}, #{item.forwardCountDay},
+        #{item.forwardUserCountTotal}, #{item.forwardUserCountDay},
+        #{item.noInterestCountTotal}, #{item.noInterestCountDay})
+    </insert>
+
+    <insert id="addBatch">
+        INSERT INTO ad_stat_of_day(<include refid="Base_Column_List"/>)
+        VALUES
+        <foreach collection="list" index="index" item="item" separator=",">
+            ( #{item.statDay}, #{item.accountId},
+            #{item.campaignId}, #{item.agencyAccountId},
+            #{item.wechatAccountId}, #{item.wechatAgencyId},
+            #{item.adGroupMapStr}, #{item.adIdsStr}, #{item.createTime},
+            #{item.costDeviationRateTotal}, #{item.costDeviationRateDay},
+            #{item.costTotal}, #{item.costDay},
+            #{item.compensationAmountTotal}, #{item.compensationAmountDay},
+            #{item.viewCountTotal}, #{item.viewCountDay},
+            #{item.thousandDisplayPriceAll}, #{item.thousandDisplayPriceDay},
+            #{item.viewUserCountTotal}, #{item.viewUserCountDay},
+            #{item.avgViewPerUserAll}, #{item.avgViewPerUserDay},
+            #{item.validClickCountTotal}, #{item.validClickCountDay},
+            #{item.clickUserCountTotal}, #{item.clickUserCountDay},
+            #{item.ctrAll}, #{item.ctrDay},
+            #{item.cpcAll}, #{item.cpcDay},
+            #{item.valuableClickCountTotal}, #{item.valuableClickCountDay},
+            #{item.valuableClickRateAll}, #{item.valuableClickRateDay},
+            #{item.valuableClickCostAll}, #{item.valuableClickCostDay},
+            #{item.conversionsCountTotal}, #{item.conversionsCountDay},
+            #{item.conversionsCostAll}, #{item.conversionsCostDay},
+            #{item.conversionsRateAll}, #{item.conversionsRateDay},
+            #{item.deepConversionsCountTotal}, #{item.deepConversionsCountDay},
+            #{item.deepConversionsCostAll}, #{item.deepConversionsCostDay},
+            #{item.deepConversionsRateAll}, #{item.deepConversionsRateDay},
+            #{item.keyPageUvTotal}, #{item.keyPageUvDay},
+            #{item.orderCountTotal}, #{item.orderCountDay},
+            #{item.firstDayOrderCountTotal}, #{item.firstDayOrderCountDay},
+            #{item.webOrderCostAll}, #{item.webOrderCostDay},
+            #{item.orderRateAll}, #{item.orderRateDay},
+            #{item.orderAmountTotal}, #{item.orderAmountDay},
+            #{item.firstDayOrderAmountTotal}, #{item.firstDayOrderAmountDay},
+            #{item.orderUnitPriceAll}, #{item.orderUnitPriceDay},
+            #{item.orderRoiAll}, #{item.orderRoiDay},
+            #{item.signInCountTotal}, #{item.signInCountDay},
+            #{item.addWishlistCountTotal}, #{item.addWishlistCountDay},
+            #{item.viewCommodityPageUvTotal}, #{item.viewCommodityPageUvDay},
+            #{item.pageReservationCountTotal}, #{item.pageReservationCountDay},
+            #{item.leadsPurchaseUvTotal}, #{item.leadsPurchaseUvDay},
+            #{item.leadsPurchaseCostAll}, #{item.leadsPurchaseCostDay},
+            #{item.leadsPurchaseRateAll}, #{item.leadsPurchaseRateDay},
+            #{item.scanFollowCountTotal}, #{item.scanFollowCountDay},
+            #{item.wechatAppRegisterUvTotal}, #{item.wechatAppRegisterUvDay},
+            #{item.wechatMinigameRegisterCostAll}, #{item.wechatMinigameRegisterCostDay},
+            #{item.wechatMinigameRegisterRateAll}, #{item.wechatMinigameRegisterRateDay},
+            #{item.wechatMinigameArpuAll}, #{item.wechatMinigameArpuDay},
+            #{item.wechatMinigameRetentionCountTotal}, #{item.wechatMinigameRetentionCountDay},
+            #{item.wechatMinigameCheckoutCountTotal}, #{item.wechatMinigameCheckoutCountDay},
+            #{item.wechatMinigameCheckoutAmountTotal}, #{item.wechatMinigameCheckoutAmountDay},
+            #{item.officialAccountFollowCountTotal}, #{item.officialAccountFollowCountDay},
+            #{item.officialAccountFollowCostAll}, #{item.officialAccountFollowCostDay},
+            #{item.officialAccountFollowRateAll}, #{item.officialAccountFollowRateDay},
+            #{item.officialAccountRegisterUserCountTotal}, #{item.officialAccountRegisterUserCountDay},
+            #{item.officialAccountRegisterRateAll}, #{item.officialAccountRegisterRateDay},
+            #{item.officialAccountRegisterCostAll}, #{item.officialAccountRegisterCostDay},
+            #{item.officialAccountRegisterAmountTotal}, #{item.officialAccountRegisterAmountDay},
+            #{item.officialAccountRegisterRoiAll}, #{item.officialAccountRegisterRoiDay},
+            #{item.officialAccountApplyCountTotal}, #{item.officialAccountApplyCountDay},
+            #{item.officialAccountApplyUserCountTotal}, #{item.officialAccountApplyUserCountDay},
+            #{item.officialAccountApplyRateAll}, #{item.officialAccountApplyRateDay},
+            #{item.officialAccountApplyCostAll}, #{item.officialAccountApplyCostDay},
+            #{item.officialAccountApplyAmountTotal}, #{item.officialAccountApplyAmountDay},
+            #{item.officialAccountApplyRoiAll}, #{item.officialAccountApplyRoiDay},
+            #{item.officialAccountOrderCountTotal}, #{item.officialAccountOrderCountDay},
+            #{item.officialAccountFirstDayOrderCountTotal}, #{item.officialAccountFirstDayOrderCountDay},
+            #{item.officialAccountOrderUserCountTotal}, #{item.officialAccountOrderUserCountDay},
+            #{item.officialAccountOrderRateAll}, #{item.officialAccountOrderRateDay},
+            #{item.officialAccountOrderCostAll}, #{item.officialAccountOrderCostDay},
+            #{item.officialAccountOrderAmountTotal}, #{item.officialAccountOrderAmountDay},
+            #{item.officialAccountFirstDayOrderAmountTotal}, #{item.officialAccountFirstDayOrderAmountDay},
+            #{item.officialAccountOrderRoiAll}, #{item.officialAccountOrderRoiDay},
+            #{item.officialAccountConsultCountTotal}, #{item.officialAccountConsultCountDay},
+            #{item.officialAccountReaderCountTotal}, #{item.officialAccountReaderCountDay},
+            #{item.officialAccountCreditApplyUserCountTotal}, #{item.officialAccountCreditApplyUserCountDay},
+            #{item.officialAccountCreditUserCountTotal}, #{item.officialAccountCreditUserCountDay},
+            #{item.forwardCountTotal}, #{item.forwardCountDay},
+            #{item.forwardUserCountTotal}, #{item.forwardUserCountDay},
+            #{item.noInterestCountTotal}, #{item.noInterestCountDay})
+        </foreach>
+    </insert>
+</mapper>

+ 418 - 289
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/pojo/entity/AdStatOfHourDWD.java

@@ -1284,415 +1284,354 @@ public class AdStatOfHourDWD {
         return adStatOfHour;
     }
 
-    public static AdStatOfHourDWD reduce(AdStatOfHourDWD value1, AdDataOfHourODS value2, long createTime) {
+    public static AdStatOfHourDWD reduce(AdStatOfDayDWD yesterdayDWD, AdStatOfHourDWD value1, AdDataOfHourODS value2, long createTime) {
         AdStatOfHourDWD result = new AdStatOfHourDWD();
         BeanUtils.copyProperties(value2, result);
         result.setCreateTime(new Date(createTime));
+
+        result.setCostDeviationRateHour(value2.getCostDeviationRate());
+        result.setCostHour(value2.getCost());
+        result.setCompensationAmountHour(value2.getCompensationAmount());
+        result.setViewCountHour(value2.getViewCount());
+        result.setThousandDisplayPriceHour(value2.getThousandDisplayPrice());
+        result.setAvgViewPerUserHour(value2.getAvgViewPerUser());
+        result.setValidClickCountHour(value2.getValidClickCount());
+        result.setCtrHour(value2.getCtr());
+        result.setCpcHour(value2.getCpc());
+        result.setValuableClickCountHour(value2.getValuableClickCount());
+        result.setValuableClickRateHour(value2.getValuableClickRate());
+        result.setValuableClickCostHour(value2.getValuableClickCost());
+        result.setConversionsCountHour(value2.getConversionsCount());
+        result.setConversionsCostHour(value2.getConversionsCost());
+        result.setConversionsRateHour(value2.getConversionsRate());
+        result.setDeepConversionsCountHour(value2.getDeepConversionsCount());
+        result.setDeepConversionsCostHour(value2.getDeepConversionsCost());
+        result.setDeepConversionsRateHour(value2.getDeepConversionsRate());
+        result.setOrderCountHour(value2.getOrderCount());
+        result.setFirstDayOrderCountHour(value2.getFirstDayOrderCount());
+        result.setWebOrderCostHour(value2.getWebOrderCost());
+        result.setOrderRateHour(value2.getOrderRate());
+        result.setOrderAmountHour(value2.getOrderAmount());
+        result.setFirstDayOrderAmountHour(value2.getFirstDayOrderAmount());
+        result.setOrderUnitPriceHour(value2.getOrderUnitPrice());
+        result.setOrderRoiHour(value2.getOrderRoi());
+        result.setSignInCountHour(value2.getSignInCount());
+        result.setScanFollowCountHour(value2.getScanFollowCount());
+        result.setWechatAppRegisterUvHour(value2.getWechatAppRegisterUv());
+        result.setWechatMinigameRegisterCostHour(value2.getWechatMinigameRegisterCost());
+        result.setWechatMinigameRegisterRateHour(value2.getWechatMinigameRegisterRate());
+        result.setWechatMinigameArpuHour(value2.getWechatMinigameArpu());
+        result.setWechatMinigameRetentionCountHour(value2.getWechatMinigameRetentionCount());
+        result.setWechatMinigameCheckoutCountHour(value2.getWechatMinigameCheckoutCount());
+        result.setWechatMinigameCheckoutAmountHour(value2.getWechatMinigameCheckoutAmount());
+        result.setOfficialAccountFollowCountHour(value2.getOfficialAccountFollowCount());
+        result.setOfficialAccountFollowRateHour(value2.getOfficialAccountFollowRate());
+        result.setOfficialAccountRegisterUserCountHour(value2.getOfficialAccountRegisterUserCount());
+        result.setOfficialAccountRegisterRateHour(value2.getOfficialAccountRegisterRate());
+        result.setOfficialAccountRegisterCostHour(value2.getOfficialAccountRegisterCost());
+        result.setOfficialAccountRegisterAmountHour(value2.getOfficialAccountRegisterAmount());
+        result.setOfficialAccountRegisterRoiHour(value2.getOfficialAccountRegisterRoi());
+        result.setOfficialAccountApplyCountHour(value2.getOfficialAccountApplyCount());
+        result.setOfficialAccountApplyUserCountHour(value2.getOfficialAccountApplyUserCount());
+        result.setOfficialAccountApplyRateHour(value2.getOfficialAccountApplyRate());
+        result.setOfficialAccountApplyCostHour(value2.getOfficialAccountApplyCost());
+        result.setOfficialAccountApplyAmountHour(value2.getOfficialAccountApplyAmount());
+        result.setOfficialAccountApplyRoiHour(value2.getOfficialAccountApplyRoi());
+        result.setOfficialAccountOrderCountHour(value2.getOfficialAccountOrderCount());
+        result.setOfficialAccountFirstDayOrderCountHour(value2.getOfficialAccountFirstDayOrderCount());
+        result.setOfficialAccountOrderUserCountHour(value2.getOfficialAccountOrderUserCount());
+        result.setOfficialAccountOrderRateHour(value2.getOfficialAccountOrderRate());
+        result.setOfficialAccountOrderCostHour(value2.getOfficialAccountOrderCost());
+        result.setOfficialAccountOrderAmountHour(value2.getOfficialAccountOrderAmount());
+        result.setOfficialAccountFirstDayOrderAmountHour(value2.getOfficialAccountFirstDayOrderAmount());
+        result.setOfficialAccountOrderRoiHour(value2.getOfficialAccountOrderRoi());
+        result.setOfficialAccountConsultCountHour(value2.getOfficialAccountConsultCount());
+        result.setOfficialAccountReaderCountHour(value2.getOfficialAccountReaderCount());
+        result.setOfficialAccountCreditApplyUserCountHour(value2.getOfficialAccountCreditApplyUserCount());
+        result.setOfficialAccountCreditUserCountHour(value2.getOfficialAccountCreditUserCount());
+        result.setForwardCountHour(value2.getForwardCount());
+        result.setForwardUserCountHour(value2.getForwardUserCount());
+        result.setNoInterestCountHour(value2.getNoInterestCount());
         if (value1 == null) {
-            result.setCostDeviationRateTotal(value2.getCostDeviationRate());
             result.setCostDeviationRateDay(value2.getCostDeviationRate());
-            result.setCostDeviationRateHour(value2.getCostDeviationRate());
-            result.setCostTotal(value2.getCost());
             result.setCostDay(value2.getCost());
-            result.setCostHour(value2.getCost());
-            result.setCompensationAmountTotal(value2.getCompensationAmount());
             result.setCompensationAmountDay(value2.getCompensationAmount());
-            result.setCompensationAmountHour(value2.getCompensationAmount());
-            result.setViewCountTotal(value2.getViewCount());
             result.setViewCountDay(value2.getViewCount());
-            result.setViewCountHour(value2.getViewCount());
-            result.setThousandDisplayPriceAll(value2.getThousandDisplayPrice());
             result.setThousandDisplayPriceDay(value2.getThousandDisplayPrice());
-            result.setThousandDisplayPriceHour(value2.getThousandDisplayPrice());
-            result.setAvgViewPerUserHour(value2.getAvgViewPerUser());
-            result.setValidClickCountTotal(value2.getValidClickCount());
             result.setValidClickCountDay(value2.getValidClickCount());
-            result.setValidClickCountHour(value2.getValidClickCount());
-            result.setCtrAll(value2.getCtr());
             result.setCtrDay(value2.getCtr());
-            result.setCtrHour(value2.getCtr());
-            result.setCpcAll(value2.getCpc());
             result.setCpcDay(value2.getCpc());
-            result.setCpcHour(value2.getCpc());
-            result.setValuableClickCountTotal(value2.getValuableClickCount());
             result.setValuableClickCountDay(value2.getValuableClickCount());
-            result.setValuableClickCountHour(value2.getValuableClickCount());
-            result.setValuableClickRateAll(value2.getValuableClickRate());
             result.setValuableClickRateDay(value2.getValuableClickRate());
-            result.setValuableClickRateHour(value2.getValuableClickRate());
-            result.setValuableClickCostAll(value2.getValuableClickCost());
             result.setValuableClickCostDay(value2.getValuableClickCost());
-            result.setValuableClickCostHour(value2.getValuableClickCost());
-            result.setConversionsCountTotal(value2.getConversionsCount());
             result.setConversionsCountDay(value2.getConversionsCount());
-            result.setConversionsCountHour(value2.getConversionsCount());
-            result.setConversionsCostAll(value2.getConversionsCost());
             result.setConversionsCostDay(value2.getConversionsCost());
-            result.setConversionsCostHour(value2.getConversionsCost());
-            result.setConversionsRateAll(value2.getConversionsRate());
             result.setConversionsRateDay(value2.getConversionsRate());
-            result.setConversionsRateHour(value2.getConversionsRate());
-            result.setDeepConversionsCountTotal(value2.getDeepConversionsCount());
             result.setDeepConversionsCountDay(value2.getDeepConversionsCount());
-            result.setDeepConversionsCountHour(value2.getDeepConversionsCount());
-            result.setDeepConversionsCostAll(value2.getDeepConversionsCost());
             result.setDeepConversionsCostDay(value2.getDeepConversionsCost());
-            result.setDeepConversionsCostHour(value2.getDeepConversionsCost());
-            result.setDeepConversionsRateAll(value2.getDeepConversionsRate());
             result.setDeepConversionsRateDay(value2.getDeepConversionsRate());
-            result.setDeepConversionsRateHour(value2.getDeepConversionsRate());
-            result.setOrderCountTotal(value2.getOrderCount());
             result.setOrderCountDay(value2.getOrderCount());
-            result.setOrderCountHour(value2.getOrderCount());
-            result.setFirstDayOrderCountTotal(value2.getFirstDayOrderCount());
             result.setFirstDayOrderCountDay(value2.getFirstDayOrderCount());
-            result.setFirstDayOrderCountHour(value2.getFirstDayOrderCount());
-            result.setWebOrderCostAll(value2.getWebOrderCost());
             result.setWebOrderCostDay(value2.getWebOrderCost());
-            result.setWebOrderCostHour(value2.getWebOrderCost());
-            result.setOrderRateAll(value2.getOrderRate());
             result.setOrderRateDay(value2.getOrderRate());
-            result.setOrderRateHour(value2.getOrderRate());
-            result.setOrderAmountTotal(value2.getOrderAmount());
             result.setOrderAmountDay(value2.getOrderAmount());
-            result.setOrderAmountHour(value2.getOrderAmount());
-            result.setFirstDayOrderAmountTotal(value2.getFirstDayOrderAmount());
             result.setFirstDayOrderAmountDay(value2.getFirstDayOrderAmount());
-            result.setFirstDayOrderAmountHour(value2.getFirstDayOrderAmount());
-            result.setOrderUnitPriceAll(value2.getOrderUnitPrice());
             result.setOrderUnitPriceDay(value2.getOrderUnitPrice());
-            result.setOrderUnitPriceHour(value2.getOrderUnitPrice());
-            result.setOrderRoiAll(value2.getOrderRoi());
             result.setOrderRoiDay(value2.getOrderRoi());
-            result.setOrderRoiHour(value2.getOrderRoi());
-            result.setSignInCountTotal(value2.getSignInCount());
             result.setSignInCountDay(value2.getSignInCount());
-            result.setSignInCountHour(value2.getSignInCount());
-            result.setScanFollowCountTotal(value2.getScanFollowCount());
             result.setScanFollowCountDay(value2.getScanFollowCount());
-            result.setScanFollowCountHour(value2.getScanFollowCount());
-            result.setWechatAppRegisterUvTotal(value2.getWechatAppRegisterUv());
             result.setWechatAppRegisterUvDay(value2.getWechatAppRegisterUv());
-            result.setWechatAppRegisterUvHour(value2.getWechatAppRegisterUv());
-            result.setWechatMinigameRegisterCostAll(value2.getWechatMinigameRegisterCost());
             result.setWechatMinigameRegisterCostDay(value2.getWechatMinigameRegisterCost());
-            result.setWechatMinigameRegisterCostHour(value2.getWechatMinigameRegisterCost());
-            result.setWechatMinigameRegisterRateAll(value2.getWechatMinigameRegisterRate());
             result.setWechatMinigameRegisterRateDay(value2.getWechatMinigameRegisterRate());
-            result.setWechatMinigameRegisterRateHour(value2.getWechatMinigameRegisterRate());
-            result.setWechatMinigameArpuAll(value2.getWechatMinigameArpu());
             result.setWechatMinigameArpuDay(value2.getWechatMinigameArpu());
-            result.setWechatMinigameArpuHour(value2.getWechatMinigameArpu());
-            result.setWechatMinigameRetentionCountTotal(value2.getWechatMinigameRetentionCount());
             result.setWechatMinigameRetentionCountDay(value2.getWechatMinigameRetentionCount());
-            result.setWechatMinigameRetentionCountHour(value2.getWechatMinigameRetentionCount());
-            result.setWechatMinigameCheckoutCountTotal(value2.getWechatMinigameCheckoutCount());
             result.setWechatMinigameCheckoutCountDay(value2.getWechatMinigameCheckoutCount());
-            result.setWechatMinigameCheckoutCountHour(value2.getWechatMinigameCheckoutCount());
-            result.setWechatMinigameCheckoutAmountTotal(value2.getWechatMinigameCheckoutAmount());
             result.setWechatMinigameCheckoutAmountDay(value2.getWechatMinigameCheckoutAmount());
-            result.setWechatMinigameCheckoutAmountHour(value2.getWechatMinigameCheckoutAmount());
-            result.setOfficialAccountFollowCountTotal(value2.getOfficialAccountFollowCount());
             result.setOfficialAccountFollowCountDay(value2.getOfficialAccountFollowCount());
-            result.setOfficialAccountFollowCountHour(value2.getOfficialAccountFollowCount());
-            result.setOfficialAccountFollowRateAll(value2.getOfficialAccountFollowRate());
             result.setOfficialAccountFollowRateDay(value2.getOfficialAccountFollowRate());
-            result.setOfficialAccountFollowRateHour(value2.getOfficialAccountFollowRate());
-            result.setOfficialAccountRegisterUserCountTotal(value2.getOfficialAccountRegisterUserCount());
             result.setOfficialAccountRegisterUserCountDay(value2.getOfficialAccountRegisterUserCount());
-            result.setOfficialAccountRegisterUserCountHour(value2.getOfficialAccountRegisterUserCount());
-            result.setOfficialAccountRegisterRateAll(value2.getOfficialAccountRegisterRate());
             result.setOfficialAccountRegisterRateDay(value2.getOfficialAccountRegisterRate());
-            result.setOfficialAccountRegisterRateHour(value2.getOfficialAccountRegisterRate());
-            result.setOfficialAccountRegisterCostAll(value2.getOfficialAccountRegisterCost());
             result.setOfficialAccountRegisterCostDay(value2.getOfficialAccountRegisterCost());
-            result.setOfficialAccountRegisterCostHour(value2.getOfficialAccountRegisterCost());
-            result.setOfficialAccountRegisterAmountTotal(value2.getOfficialAccountRegisterAmount());
             result.setOfficialAccountRegisterAmountDay(value2.getOfficialAccountRegisterAmount());
-            result.setOfficialAccountRegisterAmountHour(value2.getOfficialAccountRegisterAmount());
-            result.setOfficialAccountRegisterRoiAll(value2.getOfficialAccountRegisterRoi());
             result.setOfficialAccountRegisterRoiDay(value2.getOfficialAccountRegisterRoi());
-            result.setOfficialAccountRegisterRoiHour(value2.getOfficialAccountRegisterRoi());
-            result.setOfficialAccountApplyCountTotal(value2.getOfficialAccountApplyCount());
             result.setOfficialAccountApplyCountDay(value2.getOfficialAccountApplyCount());
-            result.setOfficialAccountApplyCountHour(value2.getOfficialAccountApplyCount());
-            result.setOfficialAccountApplyUserCountTotal(value2.getOfficialAccountApplyUserCount());
             result.setOfficialAccountApplyUserCountDay(value2.getOfficialAccountApplyUserCount());
-            result.setOfficialAccountApplyUserCountHour(value2.getOfficialAccountApplyUserCount());
-            result.setOfficialAccountApplyRateAll(value2.getOfficialAccountApplyRate());
             result.setOfficialAccountApplyRateDay(value2.getOfficialAccountApplyRate());
-            result.setOfficialAccountApplyRateHour(value2.getOfficialAccountApplyRate());
-            result.setOfficialAccountApplyCostAll(value2.getOfficialAccountApplyCost());
             result.setOfficialAccountApplyCostDay(value2.getOfficialAccountApplyCost());
-            result.setOfficialAccountApplyCostHour(value2.getOfficialAccountApplyCost());
-            result.setOfficialAccountApplyAmountTotal(value2.getOfficialAccountApplyAmount());
             result.setOfficialAccountApplyAmountDay(value2.getOfficialAccountApplyAmount());
-            result.setOfficialAccountApplyAmountHour(value2.getOfficialAccountApplyAmount());
-            result.setOfficialAccountApplyRoiAll(value2.getOfficialAccountApplyRoi());
             result.setOfficialAccountApplyRoiDay(value2.getOfficialAccountApplyRoi());
-            result.setOfficialAccountApplyRoiHour(value2.getOfficialAccountApplyRoi());
-            result.setOfficialAccountOrderCountTotal(value2.getOfficialAccountOrderCount());
             result.setOfficialAccountOrderCountDay(value2.getOfficialAccountOrderCount());
-            result.setOfficialAccountOrderCountHour(value2.getOfficialAccountOrderCount());
-            result.setOfficialAccountFirstDayOrderCountTotal(value2.getOfficialAccountFirstDayOrderCount());
             result.setOfficialAccountFirstDayOrderCountDay(value2.getOfficialAccountFirstDayOrderCount());
-            result.setOfficialAccountFirstDayOrderCountHour(value2.getOfficialAccountFirstDayOrderCount());
-            result.setOfficialAccountOrderUserCountTotal(value2.getOfficialAccountOrderUserCount());
             result.setOfficialAccountOrderUserCountDay(value2.getOfficialAccountOrderUserCount());
-            result.setOfficialAccountOrderUserCountHour(value2.getOfficialAccountOrderUserCount());
-            result.setOfficialAccountOrderRateAll(value2.getOfficialAccountOrderRate());
             result.setOfficialAccountOrderRateDay(value2.getOfficialAccountOrderRate());
-            result.setOfficialAccountOrderRateHour(value2.getOfficialAccountOrderRate());
-            result.setOfficialAccountOrderCostAll(value2.getOfficialAccountOrderCost());
             result.setOfficialAccountOrderCostDay(value2.getOfficialAccountOrderCost());
-            result.setOfficialAccountOrderCostHour(value2.getOfficialAccountOrderCost());
-            result.setOfficialAccountOrderAmountTotal(value2.getOfficialAccountOrderAmount());
             result.setOfficialAccountOrderAmountDay(value2.getOfficialAccountOrderAmount());
-            result.setOfficialAccountOrderAmountHour(value2.getOfficialAccountOrderAmount());
-            result.setOfficialAccountFirstDayOrderAmountTotal(value2.getOfficialAccountFirstDayOrderAmount());
             result.setOfficialAccountFirstDayOrderAmountDay(value2.getOfficialAccountFirstDayOrderAmount());
-            result.setOfficialAccountFirstDayOrderAmountHour(value2.getOfficialAccountFirstDayOrderAmount());
-            result.setOfficialAccountOrderRoiAll(value2.getOfficialAccountOrderRoi());
             result.setOfficialAccountOrderRoiDay(value2.getOfficialAccountOrderRoi());
-            result.setOfficialAccountOrderRoiHour(value2.getOfficialAccountOrderRoi());
-            result.setOfficialAccountConsultCountTotal(value2.getOfficialAccountConsultCount());
             result.setOfficialAccountConsultCountDay(value2.getOfficialAccountConsultCount());
-            result.setOfficialAccountConsultCountHour(value2.getOfficialAccountConsultCount());
-            result.setOfficialAccountReaderCountTotal(value2.getOfficialAccountReaderCount());
             result.setOfficialAccountReaderCountDay(value2.getOfficialAccountReaderCount());
-            result.setOfficialAccountReaderCountHour(value2.getOfficialAccountReaderCount());
-            result.setOfficialAccountCreditApplyUserCountTotal(value2.getOfficialAccountCreditApplyUserCount());
             result.setOfficialAccountCreditApplyUserCountDay(value2.getOfficialAccountCreditApplyUserCount());
-            result.setOfficialAccountCreditApplyUserCountHour(value2.getOfficialAccountCreditApplyUserCount());
-            result.setOfficialAccountCreditUserCountTotal(value2.getOfficialAccountCreditUserCount());
             result.setOfficialAccountCreditUserCountDay(value2.getOfficialAccountCreditUserCount());
-            result.setOfficialAccountCreditUserCountHour(value2.getOfficialAccountCreditUserCount());
-            result.setForwardCountTotal(value2.getForwardCount());
             result.setForwardCountDay(value2.getForwardCount());
-            result.setForwardCountHour(value2.getForwardCount());
-            result.setForwardUserCountTotal(value2.getForwardUserCount());
             result.setForwardUserCountDay(value2.getForwardUserCount());
-            result.setForwardUserCountHour(value2.getForwardUserCount());
-            result.setNoInterestCountTotal(value2.getNoInterestCount());
             result.setNoInterestCountDay(value2.getNoInterestCount());
-            result.setNoInterestCountHour(value2.getNoInterestCount());
         } else {
-            // 是否是同一天
-            boolean isUnSameDay = !value1.getStatDay().equals(value2.getStatDay());
-            result.setCostDeviationRateTotal(value1.getCostDeviationRateTotal() + value2.getCostDeviationRate());
-            result.setCostDeviationRateDay(isUnSameDay ? 0: value1.getCostDeviationRateDay() + value2.getCostDeviationRate());
-            result.setCostDeviationRateHour(value2.getCostDeviationRate());
-            result.setCostTotal(value1.getCostTotal() + value2.getCost());
-            result.setCostDay(isUnSameDay ? 0: value1.getCostDay() + value2.getCost());
-            result.setCostHour(value2.getCost());
-            result.setCompensationAmountTotal(value1.getCompensationAmountTotal() + value2.getCompensationAmount());
-            result.setCompensationAmountDay(isUnSameDay ? 0: value1.getCompensationAmountDay() + value2.getCompensationAmount());
-            result.setCompensationAmountHour(value2.getCompensationAmount());
-            result.setViewCountTotal(value1.getViewCountTotal() + value2.getViewCount());
-            result.setViewCountDay(isUnSameDay ? 0: value1.getViewCountDay() + value2.getViewCount());
-            result.setViewCountHour(value2.getViewCount());
+            result.setCostDeviationRateDay(value1.getCostDeviationRateDay() + value2.getCostDeviationRate());
+            result.setCostDay(value1.getCostDay() + value2.getCost());
+            result.setCompensationAmountDay(value1.getCompensationAmountDay() + value2.getCompensationAmount());
+            result.setViewCountDay(value1.getViewCountDay() + value2.getViewCount());
+            result.setThousandDisplayPriceDay(result.getViewCountDay() == 0 ? 0 : (result.getCostDay() / result.getViewCountDay() * 1000));
+            result.setValidClickCountDay(value1.getValidClickCountDay() + value2.getValidClickCount());
+            result.setCtrDay(result.getViewCountDay() == 0 ? 0.0 : result.getValidClickCountDay() / result.getViewCountDay());
+            result.setCpcDay(result.getValidClickCountDay() == 0 ? 0 : result.getCostDay() / result.getValidClickCountDay());
+            result.setValuableClickCountDay(value1.getValuableClickCountDay() + value2.getValuableClickCount());
+            result.setValuableClickRateDay(result.getViewCountDay() == 0 ? 0.0 : result.getValuableClickCountDay() / result.getViewCountDay());
+            result.setValuableClickCostDay(result.getValuableClickCountDay() == 0 ? 0 : result.getCostDay() / result.getValuableClickCountDay());
+            result.setConversionsCountDay(value1.getConversionsCountDay() + value2.getConversionsCount());
+            result.setConversionsCostDay(result.getConversionsCountDay() == 0 ? 0 : result.getCostDay() / result.getConversionsCountDay());
+            result.setConversionsRateDay(result.getValidClickCountDay() == 0 ? 0.0 : result.getConversionsCountDay() / result.getValidClickCountDay());
+            result.setDeepConversionsCountDay(value1.getDeepConversionsCountDay() + value2.getDeepConversionsCount());
+            result.setDeepConversionsCostDay(result.getDeepConversionsCountDay() == 0 ? 0 : result.getCostDay() / result.getDeepConversionsCountDay());
+            result.setDeepConversionsRateDay(result.getValuableClickCountDay() == 0 ? 0.0 : result.getDeepConversionsCountDay() / result.getValuableClickCountDay());
+            result.setOrderCountDay(value1.getOrderCountDay() + value2.getOrderCount());
+            result.setFirstDayOrderCountDay(value1.getFirstDayOrderCountDay() + value2.getFirstDayOrderCount());
+            result.setWebOrderCostDay(result.getOrderCountDay() == 0 ? 0 : result.getCostDay() / result.getOrderCountDay());
+            result.setOrderRateDay(result.getValidClickCountDay() == 0 ? 0.0 : result.getOrderCountDay() / result.getValidClickCountDay());
+            result.setOrderAmountDay(value1.getOrderAmountDay() + value2.getOrderAmount());
+            result.setFirstDayOrderAmountDay(value1.getFirstDayOrderAmountDay() + value2.getFirstDayOrderAmount());
+            result.setOrderUnitPriceDay(result.getOrderCountDay() == 0 ? 0 : result.getOrderAmountDay() / result.getOrderCountDay());
+            result.setOrderRoiDay(result.getCostDay() == 0 ? 0.0 : result.getOrderAmountDay() / result.getCostDay());
+            result.setSignInCountDay(value1.getSignInCountDay() + value2.getSignInCount());
+            result.setScanFollowCountDay(value1.getScanFollowCountDay() + value2.getScanFollowCount());
+            result.setWechatAppRegisterUvDay(value1.getWechatAppRegisterUvDay() + value2.getWechatAppRegisterUv());
+            result.setWechatMinigameRegisterCostDay(result.getWechatAppRegisterUvDay() == 0 ? 0 : result.getCostDay() / result.getWechatAppRegisterUvDay());
+            result.setWechatMinigameRegisterRateDay(result.getValidClickCountDay() == 0 ? 0.0 : result.getWechatAppRegisterUvDay() / result.getValidClickCountDay());
+            result.setWechatMinigameArpuDay(result.getWechatAppRegisterUvDay() == 0 ? 0.0 : result.getOrderAmountDay() / result.getWechatAppRegisterUvDay());
+            result.setWechatMinigameRetentionCountDay(value1.getWechatMinigameRetentionCountDay() + value2.getWechatMinigameRetentionCount());
+            result.setWechatMinigameCheckoutCountDay(value1.getWechatMinigameCheckoutCountDay() + value2.getWechatMinigameCheckoutCount());
+            result.setWechatMinigameCheckoutAmountDay(value1.getWechatMinigameCheckoutAmountDay() + value2.getWechatMinigameCheckoutAmount());
+            result.setOfficialAccountFollowCountDay(value1.getOfficialAccountFollowCountDay() + value2.getOfficialAccountFollowCount());
+            result.setOfficialAccountFollowRateDay(result.getValidClickCountDay() == 0 ? 0.0 : result.getOfficialAccountFollowCountDay() / result.getValidClickCountDay());
+            result.setOfficialAccountRegisterUserCountDay(value1.getOfficialAccountRegisterUserCountDay() + value2.getOfficialAccountRegisterUserCount());
+            result.setOfficialAccountRegisterRateDay(result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountRegisterUserCountDay() / result.getOfficialAccountFollowCountDay());
+            result.setOfficialAccountRegisterCostDay(result.getOfficialAccountRegisterUserCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountRegisterUserCountDay());
+            result.setOfficialAccountRegisterAmountDay(value1.getOfficialAccountRegisterAmountDay() + value2.getOfficialAccountRegisterAmount());
+            result.setOfficialAccountRegisterRoiDay(result.getCostDay() == 0 ? 0 : result.getOfficialAccountRegisterAmountDay() / result.getCostDay());
+            result.setOfficialAccountApplyCountDay(value1.getOfficialAccountApplyCountDay() + value2.getOfficialAccountApplyCount());
+            result.setOfficialAccountApplyUserCountDay(value1.getOfficialAccountApplyUserCountDay() + value2.getOfficialAccountApplyUserCount());
+            result.setOfficialAccountApplyRateDay(result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountApplyUserCountDay() / result.getOfficialAccountFollowCountDay());
+            result.setOfficialAccountApplyCostDay(result.getOfficialAccountApplyUserCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountApplyUserCountDay());
+            result.setOfficialAccountApplyAmountDay(value1.getOfficialAccountApplyAmountDay() + value2.getOfficialAccountApplyAmount());
+            result.setOfficialAccountApplyRoiDay(result.getCostDay() == 0 ? 0 : result.getOfficialAccountApplyAmountDay() / result.getCostDay());
+            result.setOfficialAccountOrderCountDay(value1.getOfficialAccountOrderCountDay() + value2.getOfficialAccountOrderCount());
+            result.setOfficialAccountFirstDayOrderCountDay(value1.getOfficialAccountFirstDayOrderCountDay() + value2.getOfficialAccountFirstDayOrderCount());
+            result.setOfficialAccountOrderUserCountDay(value1.getOfficialAccountOrderUserCountDay() + value2.getOfficialAccountOrderUserCount());
+            result.setOfficialAccountOrderRateDay(result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountOrderUserCountDay() / result.getOfficialAccountFollowCountDay());
+            result.setOfficialAccountOrderCostDay(result.getOfficialAccountOrderCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountOrderCountDay());
+            result.setOfficialAccountOrderAmountDay(value1.getOfficialAccountOrderAmountDay() + value2.getOfficialAccountOrderAmount());
+            result.setOfficialAccountFirstDayOrderAmountDay(value1.getOfficialAccountFirstDayOrderAmountDay() + value2.getOfficialAccountFirstDayOrderAmount());
+            result.setOfficialAccountOrderRoiDay(result.getCostDay() == 0 ? 0 : result.getOfficialAccountOrderAmountDay() / result.getCostDay());
+            result.setOfficialAccountConsultCountDay(value1.getOfficialAccountConsultCountDay() + value2.getOfficialAccountConsultCount());
+            result.setOfficialAccountReaderCountDay(value1.getOfficialAccountReaderCountDay() + value2.getOfficialAccountReaderCount());
+            result.setOfficialAccountCreditApplyUserCountDay(value1.getOfficialAccountCreditApplyUserCountDay() + value2.getOfficialAccountCreditApplyUserCount());
+            result.setOfficialAccountCreditUserCountDay(value1.getOfficialAccountCreditUserCountDay() + value2.getOfficialAccountCreditUserCount());
+            result.setForwardCountDay(value1.getForwardCountDay() + value2.getForwardCount());
+            result.setForwardUserCountDay(value1.getForwardUserCountDay() + value2.getForwardUserCount());
+            result.setNoInterestCountDay(value1.getNoInterestCountDay() + value2.getNoInterestCount());
+        }
+        if (yesterdayDWD == null) {
+            result.setCostDeviationRateTotal(result.getCostDeviationRateDay());
+            result.setCostTotal(result.getCostDay());
+            result.setCompensationAmountTotal(result.getCompensationAmountDay());
+            result.setViewCountTotal(result.getViewCountDay());
+            result.setThousandDisplayPriceAll(result.getThousandDisplayPriceDay());
+            result.setValidClickCountTotal(result.getValidClickCountDay());
+            result.setCtrAll(result.getCtrDay());
+            result.setCpcAll(result.getCpcDay());
+            result.setValuableClickCountTotal(result.getValuableClickCountDay());
+            result.setValuableClickRateAll(result.getValuableClickRateDay());
+            result.setValuableClickCostAll(result.getValuableClickCostDay());
+            result.setConversionsCountTotal(result.getConversionsCountDay());
+            result.setConversionsCostAll(result.getConversionsCostDay());
+            result.setConversionsRateAll(result.getConversionsRateDay());
+            result.setDeepConversionsCountTotal(result.getDeepConversionsCountDay());
+            result.setDeepConversionsCostAll(result.getDeepConversionsCostDay());
+            result.setDeepConversionsRateAll(result.getDeepConversionsRateDay());
+            result.setOrderCountTotal(result.getOrderCountDay());
+            result.setFirstDayOrderCountTotal(result.getFirstDayOrderCountDay());
+            result.setWebOrderCostAll(result.getWebOrderCostDay());
+            result.setOrderRateAll(result.getOrderRateDay());
+            result.setOrderAmountTotal(result.getOrderAmountDay());
+            result.setFirstDayOrderAmountTotal(result.getFirstDayOrderAmountDay());
+            result.setOrderUnitPriceAll(result.getOrderUnitPriceDay());
+            result.setOrderRoiAll(result.getOrderRoiDay());
+            result.setSignInCountTotal(result.getSignInCountDay());
+            result.setScanFollowCountTotal(result.getScanFollowCountDay());
+            result.setWechatAppRegisterUvTotal(result.getWechatAppRegisterUvDay());
+            result.setWechatMinigameRegisterCostAll(result.getWechatMinigameRegisterCostDay());
+            result.setWechatMinigameRegisterRateAll(result.getWechatMinigameRegisterRateDay());
+            result.setWechatMinigameArpuAll(result.getWechatMinigameArpuDay());
+            result.setWechatMinigameRetentionCountTotal(result.getWechatMinigameRetentionCountDay());
+            result.setWechatMinigameCheckoutCountTotal(result.getWechatMinigameCheckoutCountDay());
+            result.setWechatMinigameCheckoutAmountTotal(result.getWechatMinigameCheckoutAmountDay());
+            result.setOfficialAccountFollowCountTotal(result.getOfficialAccountFollowCountDay());
+            result.setOfficialAccountFollowRateAll(result.getOfficialAccountFollowRateDay());
+            result.setOfficialAccountRegisterUserCountTotal(result.getOfficialAccountRegisterUserCountDay());
+            result.setOfficialAccountRegisterRateAll(result.getOfficialAccountRegisterRateDay());
+            result.setOfficialAccountRegisterCostAll(result.getOfficialAccountRegisterCostDay());
+            result.setOfficialAccountRegisterAmountTotal(result.getOfficialAccountRegisterAmountDay());
+            result.setOfficialAccountRegisterRoiAll(result.getOfficialAccountRegisterRoiDay());
+            result.setOfficialAccountApplyCountTotal(result.getOfficialAccountApplyCountDay());
+            result.setOfficialAccountApplyUserCountTotal(result.getOfficialAccountApplyUserCountDay());
+            result.setOfficialAccountApplyRateAll(result.getOfficialAccountApplyRateDay());
+            result.setOfficialAccountApplyCostAll(result.getOfficialAccountApplyCostDay());
+            result.setOfficialAccountApplyAmountTotal(result.getOfficialAccountApplyAmountDay());
+            result.setOfficialAccountApplyRoiAll(result.getOfficialAccountApplyRoiDay());
+            result.setOfficialAccountOrderCountTotal(result.getOfficialAccountOrderCountDay());
+            result.setOfficialAccountFirstDayOrderCountTotal(result.getOfficialAccountFirstDayOrderCountDay());
+            result.setOfficialAccountOrderUserCountTotal(result.getOfficialAccountOrderUserCountDay());
+            result.setOfficialAccountOrderRateAll(result.getOfficialAccountOrderRateDay());
+            result.setOfficialAccountOrderCostAll(result.getOfficialAccountOrderCostDay());
+            result.setOfficialAccountOrderAmountTotal(result.getOfficialAccountOrderAmountDay());
+            result.setOfficialAccountFirstDayOrderAmountTotal(result.getOfficialAccountFirstDayOrderAmountDay());
+            result.setOfficialAccountOrderRoiAll(result.getOfficialAccountOrderRoiDay());
+            result.setOfficialAccountConsultCountTotal(result.getOfficialAccountConsultCountDay());
+            result.setOfficialAccountReaderCountTotal(result.getOfficialAccountReaderCountDay());
+            result.setOfficialAccountCreditApplyUserCountTotal(result.getOfficialAccountCreditApplyUserCountDay());
+            result.setOfficialAccountCreditUserCountTotal(result.getOfficialAccountCreditUserCountDay());
+            result.setForwardCountTotal(result.getForwardCountDay());
+            result.setForwardUserCountTotal(result.getForwardUserCountDay());
+            result.setNoInterestCountTotal(result.getNoInterestCountDay());
+        } else {
+            result.setCostDeviationRateTotal(yesterdayDWD.getCostDeviationRateTotal() + result.getCostDeviationRateDay());
+            result.setCostTotal(yesterdayDWD.getCostTotal() + result.getCostDay());
+            result.setCompensationAmountTotal(yesterdayDWD.getCompensationAmountTotal() + result.getCompensationAmountDay());
+            result.setViewCountTotal(yesterdayDWD.getViewCountTotal() + result.getViewCountDay());
             // 总消耗 / 总曝光
             result.setThousandDisplayPriceAll(result.getViewCountTotal() == 0 ? 0 : (result.getCostTotal() / result.getViewCountTotal() * 1000));
-            result.setThousandDisplayPriceDay(isUnSameDay ? 0: result.getViewCountDay() == 0 ? 0 : (result.getCostDay() / result.getViewCountDay() * 1000));
-            result.setThousandDisplayPriceHour(value2.getThousandDisplayPrice());
             // 曝光次数 / 曝光人数(拿不到曝光人数)
-            result.setAvgViewPerUserHour(value2.getAvgViewPerUser());
-            result.setValidClickCountTotal(value1.getValidClickCountTotal() + value2.getValidClickCount());
-            result.setValidClickCountDay(isUnSameDay ? 0: value1.getValidClickCountDay() + value2.getValidClickCount());
-            result.setValidClickCountHour(value2.getValidClickCount());
+            result.setValidClickCountTotal(yesterdayDWD.getValidClickCountTotal() + result.getValidClickCountDay());
             // 广告点击次数 / 广告曝光次数
             result.setCtrAll(result.getViewCountTotal() == 0 ? 0.0 : result.getValidClickCountTotal() / result.getViewCountTotal());
-            result.setCtrDay(isUnSameDay ? 0: result.getViewCountDay() == 0 ? 0.0 : result.getValidClickCountDay() / result.getViewCountDay());
-            result.setCtrHour(value2.getCtr());
             // 广告花费/广告点击次数
             result.setCpcAll(result.getValidClickCountTotal() == 0 ? 0 : result.getCostTotal() / result.getValidClickCountTotal());
-            result.setCpcDay(isUnSameDay ? 0: result.getValidClickCountDay() == 0 ? 0 : result.getCostDay() / result.getValidClickCountDay());
-            result.setCpcHour(value2.getCpc());
-            result.setValuableClickCountTotal(value1.getValuableClickCountTotal() + value2.getValuableClickCount());
-            result.setValuableClickCountDay(isUnSameDay ? 0: value1.getValuableClickCountDay() + value2.getValuableClickCount());
-            result.setValuableClickCountHour(value2.getValuableClickCount());
+            result.setValuableClickCountTotal(yesterdayDWD.getValuableClickCountTotal() + result.getValuableClickCountDay());
             // 广告可转化点击次数/广告曝光次数
             result.setValuableClickRateAll(result.getViewCountTotal() == 0 ? 0.0 : result.getValuableClickCountTotal() / result.getViewCountTotal());
-            result.setValuableClickRateDay(isUnSameDay ? 0: result.getViewCountDay() == 0 ? 0.0 : result.getValuableClickCountDay() / result.getViewCountDay());
-            result.setValuableClickRateHour(value2.getValuableClickRate());
             // 广告花费/可转化点击次数
             result.setValuableClickCostAll(result.getValuableClickCountTotal() == 0 ? 0 : result.getCostTotal() / result.getValuableClickCountTotal());
-            result.setValuableClickCostDay(isUnSameDay ? 0: result.getValuableClickCountDay() == 0 ? 0 : result.getCostDay() / result.getValuableClickCountDay());
-            result.setValuableClickCostHour(value2.getValuableClickCost());
-            result.setConversionsCountTotal(value1.getConversionsCountTotal() + value2.getConversionsCount());
-            result.setConversionsCountDay(isUnSameDay ? 0: value1.getConversionsCountDay() + value2.getConversionsCount());
-            result.setConversionsCountHour(value2.getConversionsCount());
+            result.setConversionsCountTotal(yesterdayDWD.getConversionsCountTotal() + result.getConversionsCountDay());
             // 广告花费/转化目标量
             result.setConversionsCostAll(result.getConversionsCountTotal() == 0 ? 0 : result.getCostTotal() / result.getConversionsCountTotal());
-            result.setConversionsCostDay(isUnSameDay ? 0: result.getConversionsCountDay() == 0 ? 0 : result.getCostDay() / result.getConversionsCountDay());
-            result.setConversionsCostHour(value2.getConversionsCost());
             // 公众号:转化目标量/点击次数。
             result.setConversionsRateAll(result.getValidClickCountTotal() == 0 ? 0.0 : result.getConversionsCountTotal() / result.getValidClickCountTotal());
-            result.setConversionsRateDay(isUnSameDay ? 0: result.getValidClickCountDay() == 0 ? 0.0 : result.getConversionsCountDay() / result.getValidClickCountDay());
-            result.setConversionsRateHour(value2.getConversionsRate());
-            result.setDeepConversionsCountTotal(value1.getDeepConversionsCountTotal() + value2.getDeepConversionsCount());
-            result.setDeepConversionsCountDay(isUnSameDay ? 0: value1.getDeepConversionsCountDay() + value2.getDeepConversionsCount());
-            result.setDeepConversionsCountHour(value2.getDeepConversionsCount());
+            result.setDeepConversionsCountTotal(yesterdayDWD.getDeepConversionsCountTotal() + result.getDeepConversionsCountDay());
             // 广告花费/深度转化目标量
             result.setDeepConversionsCostAll(result.getDeepConversionsCountTotal() == 0 ? 0 : result.getCostTotal() / result.getDeepConversionsCountTotal());
-            result.setDeepConversionsCostDay(isUnSameDay ? 0: result.getDeepConversionsCountDay() == 0 ? 0 : result.getCostDay() / result.getDeepConversionsCountDay());
-            result.setDeepConversionsCostHour(value2.getDeepConversionsCost());
             // 深度转化目标量/可转化点击次数
             result.setDeepConversionsRateAll(result.getValuableClickCountTotal() == 0 ? 0.0 : result.getDeepConversionsCountTotal() / result.getValuableClickCountTotal());
-            result.setDeepConversionsRateDay(isUnSameDay ? 0: result.getValuableClickCountDay() == 0 ? 0.0 : result.getDeepConversionsCountDay() / result.getValuableClickCountDay());
-            result.setDeepConversionsRateHour(value2.getDeepConversionsRate());
-            result.setOrderCountTotal(value1.getOrderCountTotal() + value2.getOrderCount());
-            result.setOrderCountDay(isUnSameDay ? 0: value1.getOrderCountDay() + value2.getOrderCount());
-            result.setOrderCountHour(value2.getOrderCount());
-            result.setFirstDayOrderCountTotal(value1.getFirstDayOrderCountTotal() + value2.getFirstDayOrderCount());
-            result.setFirstDayOrderCountDay(isUnSameDay ? 0: value1.getFirstDayOrderCountDay() + value2.getFirstDayOrderCount());
-            result.setFirstDayOrderCountHour(value2.getFirstDayOrderCount());
+            result.setOrderCountTotal(yesterdayDWD.getOrderCountTotal() + result.getOrderCountDay());
+            result.setFirstDayOrderCountTotal(yesterdayDWD.getFirstDayOrderCountTotal() + result.getFirstDayOrderCountDay());
             // 广告花费/下单量
             result.setWebOrderCostAll(result.getOrderCountTotal() == 0 ? 0 : result.getCostTotal() / result.getOrderCountTotal());
-            result.setWebOrderCostDay(isUnSameDay ? 0: result.getOrderCountDay() == 0 ? 0 : result.getCostDay() / result.getOrderCountDay());
-            result.setWebOrderCostHour(value2.getWebOrderCost());
             // 下单量/点击次数
             result.setOrderRateAll(result.getValidClickCountTotal() == 0 ? 0.0 : result.getOrderCountTotal() / result.getValidClickCountTotal());
-            result.setOrderRateDay(isUnSameDay ? 0: result.getValidClickCountDay() == 0 ? 0.0 : result.getOrderCountDay() / result.getValidClickCountDay());
-            result.setOrderRateHour(value2.getOrderRate());
-            result.setOrderAmountTotal(value1.getOrderAmountTotal() + value2.getOrderAmount());
-            result.setOrderAmountDay(isUnSameDay ? 0: value1.getOrderAmountDay() + value2.getOrderAmount());
-            result.setOrderAmountHour(value2.getOrderAmount());
-            result.setFirstDayOrderAmountTotal(value1.getFirstDayOrderAmountTotal() + value2.getFirstDayOrderAmount());
-            result.setFirstDayOrderAmountDay(isUnSameDay ? 0: value1.getFirstDayOrderAmountDay() + value2.getFirstDayOrderAmount());
-            result.setFirstDayOrderAmountHour(value2.getFirstDayOrderAmount());
+            result.setOrderAmountTotal(yesterdayDWD.getOrderAmountTotal() + result.getOrderAmountDay());
+            result.setFirstDayOrderAmountTotal(yesterdayDWD.getFirstDayOrderAmountTotal() + result.getFirstDayOrderAmountDay());
             // 下单金额/下单量
             result.setOrderUnitPriceAll(result.getOrderCountTotal() == 0 ? 0 : result.getOrderAmountTotal() / result.getOrderCountTotal());
-            result.setOrderUnitPriceDay(isUnSameDay ? 0: result.getOrderCountDay() == 0 ? 0 : result.getOrderAmountDay() / result.getOrderCountDay());
-            result.setOrderUnitPriceHour(value2.getOrderUnitPrice());
             // 下单金额/广告花费
             result.setOrderRoiAll(result.getCostTotal() == 0 ? 0.0 : result.getOrderAmountTotal() / result.getCostTotal());
-            result.setOrderRoiDay(isUnSameDay ? 0: result.getCostDay() == 0 ? 0.0 : result.getOrderAmountDay() / result.getCostDay());
-            result.setOrderRoiHour(value2.getOrderRoi());
-            result.setSignInCountTotal(value1.getSignInCountTotal() + value2.getSignInCount());
-            result.setSignInCountDay(value1.getSignInCountDay() + value2.getSignInCount());
-            result.setSignInCountHour(value2.getSignInCount());
-            result.setScanFollowCountTotal(value1.getScanFollowCountTotal() + value2.getScanFollowCount());
-            result.setScanFollowCountDay(isUnSameDay ? 0: value1.getScanFollowCountDay() + value2.getScanFollowCount());
-            result.setScanFollowCountHour(value2.getScanFollowCount());
-            result.setWechatAppRegisterUvTotal(value1.getWechatAppRegisterUvTotal() + value2.getWechatAppRegisterUv());
-            result.setWechatAppRegisterUvDay(isUnSameDay ? 0: value1.getWechatAppRegisterUvDay() + value2.getWechatAppRegisterUv());
-            result.setWechatAppRegisterUvHour(value2.getWechatAppRegisterUv());
+            result.setSignInCountTotal(yesterdayDWD.getSignInCountTotal() + result.getSignInCountDay());
+            result.setScanFollowCountTotal(yesterdayDWD.getScanFollowCountTotal() + result.getScanFollowCountDay());
+            result.setWechatAppRegisterUvTotal(yesterdayDWD.getWechatAppRegisterUvTotal() + result.getWechatAppRegisterUvDay());
             // 广告消耗 / 小游戏注册人数
             result.setWechatMinigameRegisterCostAll(result.getWechatAppRegisterUvTotal() == 0 ? 0 : result.getCostTotal() / result.getWechatAppRegisterUvTotal());
-            result.setWechatMinigameRegisterCostDay(isUnSameDay ? 0: result.getWechatAppRegisterUvDay() == 0 ? 0 : result.getCostDay() / result.getWechatAppRegisterUvDay());
-            result.setWechatMinigameRegisterCostHour(value2.getWechatMinigameRegisterCost());
             // 小游戏注册人数 / 广告点击次数
             result.setWechatMinigameRegisterRateAll(result.getValidClickCountTotal() == 0 ? 0.0 : result.getWechatAppRegisterUvTotal() / result.getValidClickCountTotal());
-            result.setWechatMinigameRegisterRateDay(isUnSameDay ? 0: result.getValidClickCountDay() == 0 ? 0.0 : result.getWechatAppRegisterUvDay() / result.getValidClickCountDay());
-            result.setWechatMinigameRegisterRateHour(value2.getWechatMinigameRegisterRate());
             // 总收益 / 总人数
             result.setWechatMinigameArpuAll(result.getWechatAppRegisterUvTotal() == 0 ? 0.0 : result.getOrderAmountTotal() / result.getWechatAppRegisterUvTotal());
-            result.setWechatMinigameArpuDay(isUnSameDay ? 0: result.getWechatAppRegisterUvDay() == 0 ? 0.0 : result.getOrderAmountDay() / result.getWechatAppRegisterUvDay());
-            result.setWechatMinigameArpuHour(value2.getWechatMinigameArpu());
-            result.setWechatMinigameRetentionCountTotal(value1.getWechatMinigameRetentionCountTotal() + value2.getWechatMinigameRetentionCount());
-            result.setWechatMinigameRetentionCountDay(isUnSameDay ? 0: value1.getWechatMinigameRetentionCountDay() + value2.getWechatMinigameRetentionCount());
-            result.setWechatMinigameRetentionCountHour(value2.getWechatMinigameRetentionCount());
-            result.setWechatMinigameCheckoutCountTotal(value1.getWechatMinigameCheckoutCountTotal() + value2.getWechatMinigameCheckoutCount());
-            result.setWechatMinigameCheckoutCountDay(isUnSameDay ? 0: value1.getWechatMinigameCheckoutCountDay() + value2.getWechatMinigameCheckoutCount());
-            result.setWechatMinigameCheckoutCountHour(value2.getWechatMinigameCheckoutCount());
-            result.setWechatMinigameCheckoutAmountTotal(value1.getWechatMinigameCheckoutAmountTotal() + value2.getWechatMinigameCheckoutAmount());
-            result.setWechatMinigameCheckoutAmountDay(isUnSameDay ? 0: value1.getWechatMinigameCheckoutAmountDay() + value2.getWechatMinigameCheckoutAmount());
-            result.setWechatMinigameCheckoutAmountHour(value2.getWechatMinigameCheckoutAmount());
-            result.setOfficialAccountFollowCountTotal(value1.getOfficialAccountFollowCountTotal() + value2.getOfficialAccountFollowCount());
-            result.setOfficialAccountFollowCountDay(isUnSameDay ? 0: value1.getOfficialAccountFollowCountDay() + value2.getOfficialAccountFollowCount());
-            result.setOfficialAccountFollowCountHour(value2.getOfficialAccountFollowCount());
+            result.setWechatMinigameRetentionCountTotal(yesterdayDWD.getWechatMinigameRetentionCountTotal() + result.getWechatMinigameRetentionCountDay());
+            result.setWechatMinigameCheckoutCountTotal(yesterdayDWD.getWechatMinigameCheckoutCountTotal() + result.getWechatMinigameCheckoutCountDay());
+            result.setWechatMinigameCheckoutAmountTotal(yesterdayDWD.getWechatMinigameCheckoutAmountTotal() + result.getWechatMinigameCheckoutAmountDay());
+            result.setOfficialAccountFollowCountTotal(yesterdayDWD.getOfficialAccountFollowCountTotal() + result.getOfficialAccountFollowCountDay());
             // 关注次数 / 点击次数
             result.setOfficialAccountFollowRateAll(result.getValidClickCountTotal() == 0 ? 0.0 : result.getOfficialAccountFollowCountTotal() / result.getValidClickCountTotal());
-            result.setOfficialAccountFollowRateDay(isUnSameDay ? 0: result.getValidClickCountDay() == 0 ? 0.0 : result.getOfficialAccountFollowCountDay() / result.getValidClickCountDay());
-            result.setOfficialAccountFollowRateHour(value2.getOfficialAccountFollowRate());
-            result.setOfficialAccountRegisterUserCountTotal(value1.getOfficialAccountRegisterUserCountTotal() + value2.getOfficialAccountRegisterUserCount());
-            result.setOfficialAccountRegisterUserCountDay(isUnSameDay ? 0: value1.getOfficialAccountRegisterUserCountDay() + value2.getOfficialAccountRegisterUserCount());
-            result.setOfficialAccountRegisterUserCountHour(value2.getOfficialAccountRegisterUserCount());
+            result.setOfficialAccountRegisterUserCountTotal(yesterdayDWD.getOfficialAccountRegisterUserCountTotal() + result.getOfficialAccountRegisterUserCountDay());
             // 公众号内注册人数 / 公众号关注次数
             result.setOfficialAccountRegisterRateAll(result.getOfficialAccountFollowCountTotal() == 0 ? 0.0 : result.getOfficialAccountRegisterUserCountTotal() / result.getOfficialAccountFollowCountTotal());
-            result.setOfficialAccountRegisterRateDay(isUnSameDay ? 0: result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountRegisterUserCountDay() / result.getOfficialAccountFollowCountDay());
-            result.setOfficialAccountRegisterRateHour(value2.getOfficialAccountRegisterRate());
             // 广告消耗 / 广告注册人数
             result.setOfficialAccountRegisterCostAll(result.getOfficialAccountRegisterUserCountTotal() == 0 ? 0 : result.getCostTotal() / result.getOfficialAccountRegisterUserCountTotal());
-            result.setOfficialAccountRegisterCostDay(isUnSameDay ? 0: result.getOfficialAccountRegisterUserCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountRegisterUserCountDay());
-            result.setOfficialAccountRegisterCostHour(value2.getOfficialAccountRegisterCost());
-            result.setOfficialAccountRegisterAmountTotal(value1.getOfficialAccountRegisterAmountTotal() + value2.getOfficialAccountRegisterAmount());
-            result.setOfficialAccountRegisterAmountDay(isUnSameDay ? 0: value1.getOfficialAccountRegisterAmountDay() + value2.getOfficialAccountRegisterAmount());
-            result.setOfficialAccountRegisterAmountHour(value2.getOfficialAccountRegisterAmount());
+            result.setOfficialAccountRegisterAmountTotal(yesterdayDWD.getOfficialAccountRegisterAmountTotal() + result.getOfficialAccountRegisterAmountDay());
             // 注册产生的订单金额累计/广告花费
             result.setOfficialAccountRegisterRoiAll(result.getCostTotal() == 0 ? 0 : result.getOfficialAccountRegisterAmountTotal() / result.getCostTotal());
-            result.setOfficialAccountRegisterRoiDay(isUnSameDay ? 0: result.getCostDay() == 0 ? 0 : result.getOfficialAccountRegisterAmountDay() / result.getCostDay());
-            result.setOfficialAccountRegisterRoiHour(value2.getOfficialAccountRegisterRoi());
-            result.setOfficialAccountApplyCountTotal(value1.getOfficialAccountApplyCountTotal() + value2.getOfficialAccountApplyCount());
-            result.setOfficialAccountApplyCountDay(isUnSameDay ? 0: value1.getOfficialAccountApplyCountDay() + value2.getOfficialAccountApplyCount());
-            result.setOfficialAccountApplyCountHour(value2.getOfficialAccountApplyCount());
-            result.setOfficialAccountApplyUserCountTotal(value1.getOfficialAccountApplyUserCountTotal() + value2.getOfficialAccountApplyUserCount());
-            result.setOfficialAccountApplyUserCountDay(isUnSameDay ? 0: value1.getOfficialAccountApplyUserCountDay() + value2.getOfficialAccountApplyUserCount());
-            result.setOfficialAccountApplyUserCountHour(value2.getOfficialAccountApplyUserCount());
+            result.setOfficialAccountApplyCountTotal(yesterdayDWD.getOfficialAccountApplyCountTotal() + result.getOfficialAccountApplyCountDay());
+            result.setOfficialAccountApplyUserCountTotal(yesterdayDWD.getOfficialAccountApplyUserCountTotal() + result.getOfficialAccountApplyUserCountDay());
             // 公众号内填单的独立用户数/公众号关注次数
             result.setOfficialAccountApplyRateAll(result.getOfficialAccountFollowCountTotal() == 0 ? 0.0 : result.getOfficialAccountApplyUserCountTotal() / result.getOfficialAccountFollowCountTotal());
-            result.setOfficialAccountApplyRateDay(isUnSameDay ? 0: result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountApplyUserCountDay() / result.getOfficialAccountFollowCountDay());
-            result.setOfficialAccountApplyRateHour(value2.getOfficialAccountApplyRate());
             // 广告花费/广告产生的填单行为数量
             result.setOfficialAccountApplyCostAll(result.getOfficialAccountApplyUserCountTotal() == 0 ? 0 : result.getCostTotal() / result.getOfficialAccountApplyUserCountTotal());
-            result.setOfficialAccountApplyCostDay(isUnSameDay ? 0: result.getOfficialAccountApplyUserCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountApplyUserCountDay());
-            result.setOfficialAccountApplyCostHour(value2.getOfficialAccountApplyCost());
-            result.setOfficialAccountApplyAmountTotal(value1.getOfficialAccountApplyAmountTotal() + value2.getOfficialAccountApplyAmount());
-            result.setOfficialAccountApplyAmountDay(isUnSameDay ? 0: value1.getOfficialAccountApplyAmountDay() + value2.getOfficialAccountApplyAmount());
-            result.setOfficialAccountApplyAmountHour(value2.getOfficialAccountApplyAmount());
+            result.setOfficialAccountApplyAmountTotal(yesterdayDWD.getOfficialAccountApplyAmountTotal() + result.getOfficialAccountApplyAmountDay());
             // 填单产生的订单金额累计/广告花费
             result.setOfficialAccountApplyRoiAll(result.getCostTotal() == 0 ? 0 : result.getOfficialAccountApplyAmountTotal() / result.getCostTotal());
-            result.setOfficialAccountApplyRoiDay(isUnSameDay ? 0: result.getCostDay() == 0 ? 0 : result.getOfficialAccountApplyAmountDay() / result.getCostDay());
-            result.setOfficialAccountApplyRoiHour(value2.getOfficialAccountApplyRoi());
-            result.setOfficialAccountOrderCountTotal(value1.getOfficialAccountOrderCountTotal() + value2.getOfficialAccountOrderCount());
-            result.setOfficialAccountOrderCountDay(isUnSameDay ? 0: value1.getOfficialAccountOrderCountDay() + value2.getOfficialAccountOrderCount());
-            result.setOfficialAccountOrderCountHour(value2.getOfficialAccountOrderCount());
-            result.setOfficialAccountFirstDayOrderCountTotal(value1.getOfficialAccountFirstDayOrderCountTotal() + value2.getOfficialAccountFirstDayOrderCount());
-            result.setOfficialAccountFirstDayOrderCountDay(isUnSameDay ? 0: value1.getOfficialAccountFirstDayOrderCountDay() + value2.getOfficialAccountFirstDayOrderCount());
-            result.setOfficialAccountFirstDayOrderCountHour(value2.getOfficialAccountFirstDayOrderCount());
-            result.setOfficialAccountOrderUserCountTotal(value1.getOfficialAccountOrderUserCountTotal() + value2.getOfficialAccountOrderUserCount());
-            result.setOfficialAccountOrderUserCountDay(isUnSameDay ? 0: value1.getOfficialAccountOrderUserCountDay() + value2.getOfficialAccountOrderUserCount());
-            result.setOfficialAccountOrderUserCountHour(value2.getOfficialAccountOrderUserCount());
+            result.setOfficialAccountOrderCountTotal(yesterdayDWD.getOfficialAccountOrderCountTotal() + result.getOfficialAccountOrderCountDay());
+            result.setOfficialAccountFirstDayOrderCountTotal(yesterdayDWD.getOfficialAccountFirstDayOrderCountTotal() + result.getOfficialAccountFirstDayOrderCountDay());
+            result.setOfficialAccountOrderUserCountTotal(yesterdayDWD.getOfficialAccountOrderUserCountTotal() + result.getOfficialAccountOrderUserCountDay());
             // 公众号内下单独立用户数(UV)/公众号关注次数
             result.setOfficialAccountOrderRateAll(result.getOfficialAccountFollowCountTotal() == 0 ? 0.0 : result.getOfficialAccountOrderUserCountTotal() / result.getOfficialAccountFollowCountTotal());
-            result.setOfficialAccountOrderRateDay(isUnSameDay ? 0: result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountOrderUserCountDay() / result.getOfficialAccountFollowCountDay());
-            result.setOfficialAccountOrderRateHour(value2.getOfficialAccountOrderRate());
             // 广告花费/广告产生的下单行为数量
             result.setOfficialAccountOrderCostAll(result.getOfficialAccountOrderCountTotal() == 0 ? 0 : result.getCostTotal() / result.getOfficialAccountOrderCountTotal());
-            result.setOfficialAccountOrderCostDay(isUnSameDay ? 0: result.getOfficialAccountOrderCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountOrderCountDay());
-            result.setOfficialAccountOrderCostHour(value2.getOfficialAccountOrderCost());
-            result.setOfficialAccountOrderAmountTotal(value1.getOfficialAccountOrderAmountTotal() + value2.getOfficialAccountOrderAmount());
-            result.setOfficialAccountOrderAmountDay(isUnSameDay ? 0: value1.getOfficialAccountOrderAmountDay() + value2.getOfficialAccountOrderAmount());
-            result.setOfficialAccountOrderAmountHour(value2.getOfficialAccountOrderAmount());
-            result.setOfficialAccountFirstDayOrderAmountTotal(value1.getOfficialAccountFirstDayOrderAmountTotal() + value2.getOfficialAccountFirstDayOrderAmount());
-            result.setOfficialAccountFirstDayOrderAmountDay(isUnSameDay ? 0: value1.getOfficialAccountFirstDayOrderAmountDay() + value2.getOfficialAccountFirstDayOrderAmount());
-            result.setOfficialAccountFirstDayOrderAmountHour(value2.getOfficialAccountFirstDayOrderAmount());
+            result.setOfficialAccountOrderAmountTotal(yesterdayDWD.getOfficialAccountOrderAmountTotal() + result.getOfficialAccountOrderAmountDay());
+            result.setOfficialAccountFirstDayOrderAmountTotal(yesterdayDWD.getOfficialAccountFirstDayOrderAmountTotal() + result.getOfficialAccountFirstDayOrderAmountDay());
             // 下单产生的订单金额累计/广告花费
             result.setOfficialAccountOrderRoiAll(result.getCostTotal() == 0 ? 0 : result.getOfficialAccountOrderAmountTotal() / result.getCostTotal());
-            result.setOfficialAccountOrderRoiDay(isUnSameDay ? 0: result.getCostDay() == 0 ? 0 : result.getOfficialAccountOrderAmountDay() / result.getCostDay());
-            result.setOfficialAccountOrderRoiHour(value2.getOfficialAccountOrderRoi());
-            result.setOfficialAccountConsultCountTotal(value1.getOfficialAccountConsultCountTotal() + value2.getOfficialAccountConsultCount());
-            result.setOfficialAccountConsultCountDay(isUnSameDay ? 0: value1.getOfficialAccountConsultCountDay() + value2.getOfficialAccountConsultCount());
-            result.setOfficialAccountConsultCountHour(value2.getOfficialAccountConsultCount());
-            result.setOfficialAccountReaderCountTotal(value1.getOfficialAccountReaderCountTotal() + value2.getOfficialAccountReaderCount());
-            result.setOfficialAccountReaderCountDay(isUnSameDay ? 0: value1.getOfficialAccountReaderCountDay() + value2.getOfficialAccountReaderCount());
-            result.setOfficialAccountReaderCountHour(value2.getOfficialAccountReaderCount());
-            result.setOfficialAccountCreditApplyUserCountTotal(value1.getOfficialAccountCreditApplyUserCountTotal() + value2.getOfficialAccountCreditApplyUserCount());
-            result.setOfficialAccountCreditApplyUserCountDay(isUnSameDay ? 0: value1.getOfficialAccountCreditApplyUserCountDay() + value2.getOfficialAccountCreditApplyUserCount());
-            result.setOfficialAccountCreditApplyUserCountHour(value2.getOfficialAccountCreditApplyUserCount());
-            result.setOfficialAccountCreditUserCountTotal(value1.getOfficialAccountCreditUserCountTotal() + value2.getOfficialAccountCreditUserCount());
-            result.setOfficialAccountCreditUserCountDay(isUnSameDay ? 0: value1.getOfficialAccountCreditUserCountDay() + value2.getOfficialAccountCreditUserCount());
-            result.setOfficialAccountCreditUserCountHour(value2.getOfficialAccountCreditUserCount());
-            result.setForwardCountTotal(value1.getForwardCountTotal() + value2.getForwardCount());
-            result.setForwardCountDay(isUnSameDay ? 0: value1.getForwardCountDay() + value2.getForwardCount());
-            result.setForwardCountHour(value2.getForwardCount());
-            result.setForwardUserCountTotal(value1.getForwardUserCountTotal() + value2.getForwardUserCount());
-            result.setForwardUserCountDay(isUnSameDay ? 0: value1.getForwardUserCountDay() + value2.getForwardUserCount());
-            result.setForwardUserCountHour(value2.getForwardUserCount());
-            result.setNoInterestCountTotal(value1.getNoInterestCountTotal() + value2.getNoInterestCount());
-            result.setNoInterestCountDay(isUnSameDay ? 0: value1.getNoInterestCountDay() + value2.getNoInterestCount());
-            result.setNoInterestCountHour(value2.getNoInterestCount());
+            result.setOfficialAccountConsultCountTotal(yesterdayDWD.getOfficialAccountConsultCountTotal() + result.getOfficialAccountConsultCountDay());
+            result.setOfficialAccountReaderCountTotal(yesterdayDWD.getOfficialAccountReaderCountTotal() + result.getOfficialAccountReaderCountDay());
+            result.setOfficialAccountCreditApplyUserCountTotal(yesterdayDWD.getOfficialAccountCreditApplyUserCountTotal() + result.getOfficialAccountCreditApplyUserCountDay());
+            result.setOfficialAccountCreditUserCountTotal(yesterdayDWD.getOfficialAccountCreditUserCountTotal() + result.getOfficialAccountCreditUserCountDay());
+            result.setForwardCountTotal(yesterdayDWD.getForwardCountTotal() + result.getForwardCountDay());
+            result.setForwardUserCountTotal(yesterdayDWD.getForwardUserCountTotal() + result.getForwardUserCountDay());
+            result.setNoInterestCountTotal(yesterdayDWD.getNoInterestCountTotal() + result.getNoInterestCountDay());
         }
         return result;
     }
@@ -1898,4 +1837,194 @@ public class AdStatOfHourDWD {
         result.setNoInterestCountHour(ObjectUtil.toLong(record.get("no_interest_count_hour")));
         return result;
     }
+
+    public static void initValue(AdStatOfHourDWD bean) {
+        bean.setCostDeviationRateTotal(0.0);
+        bean.setCostDeviationRateDay(0.0);
+        bean.setCostDeviationRateHour(0.0);
+        bean.setCostTotal(0L);
+        bean.setCostDay(0L);
+        bean.setCostHour(0L);
+        bean.setCompensationAmountTotal(0L);
+        bean.setCompensationAmountDay(0L);
+        bean.setCompensationAmountHour(0L);
+        bean.setViewCountTotal(0L);
+        bean.setViewCountDay(0L);
+        bean.setViewCountHour(0L);
+        bean.setThousandDisplayPriceAll(0L);
+        bean.setThousandDisplayPriceDay(0L);
+        bean.setThousandDisplayPriceHour(0L);
+        bean.setAvgViewPerUserHour(0.0);
+        bean.setValidClickCountTotal(0L);
+        bean.setValidClickCountDay(0L);
+        bean.setValidClickCountHour(0L);
+        bean.setCtrAll(0.0);
+        bean.setCtrDay(0.0);
+        bean.setCtrHour(0.0);
+        bean.setCpcAll(0L);
+        bean.setCpcDay(0L);
+        bean.setCpcHour(0L);
+        bean.setValuableClickCountTotal(0L);
+        bean.setValuableClickCountDay(0L);
+        bean.setValuableClickCountHour(0L);
+        bean.setValuableClickRateAll(0.0);
+        bean.setValuableClickRateDay(0.0);
+        bean.setValuableClickRateHour(0.0);
+        bean.setValuableClickCostAll(0L);
+        bean.setValuableClickCostDay(0L);
+        bean.setValuableClickCostHour(0L);
+        bean.setConversionsCountTotal(0L);
+        bean.setConversionsCountDay(0L);
+        bean.setConversionsCountHour(0L);
+        bean.setConversionsCostAll(0L);
+        bean.setConversionsCostDay(0L);
+        bean.setConversionsCostHour(0L);
+        bean.setConversionsRateAll(0.0);
+        bean.setConversionsRateDay(0.0);
+        bean.setConversionsRateHour(0.0);
+        bean.setDeepConversionsCountTotal(0L);
+        bean.setDeepConversionsCountDay(0L);
+        bean.setDeepConversionsCountHour(0L);
+        bean.setDeepConversionsCostAll(0L);
+        bean.setDeepConversionsCostDay(0L);
+        bean.setDeepConversionsCostHour(0L);
+        bean.setDeepConversionsRateAll(0.0);
+        bean.setDeepConversionsRateDay(0.0);
+        bean.setDeepConversionsRateHour(0.0);
+        bean.setOrderCountTotal(0L);
+        bean.setOrderCountDay(0L);
+        bean.setOrderCountHour(0L);
+        bean.setFirstDayOrderCountTotal(0L);
+        bean.setFirstDayOrderCountDay(0L);
+        bean.setFirstDayOrderCountHour(0L);
+        bean.setWebOrderCostAll(0L);
+        bean.setWebOrderCostDay(0L);
+        bean.setWebOrderCostHour(0L);
+        bean.setOrderRateAll(0.0);
+        bean.setOrderRateDay(0.0);
+        bean.setOrderRateHour(0.0);
+        bean.setOrderAmountTotal(0L);
+        bean.setOrderAmountDay(0L);
+        bean.setOrderAmountHour(0L);
+        bean.setFirstDayOrderAmountTotal(0L);
+        bean.setFirstDayOrderAmountDay(0L);
+        bean.setFirstDayOrderAmountHour(0L);
+        bean.setOrderUnitPriceAll(0L);
+        bean.setOrderUnitPriceDay(0L);
+        bean.setOrderUnitPriceHour(0L);
+        bean.setOrderRoiAll(0.0);
+        bean.setOrderRoiDay(0.0);
+        bean.setOrderRoiHour(0.0);
+        bean.setSignInCountTotal(0L);
+        bean.setSignInCountDay(0L);
+        bean.setSignInCountHour(0L);
+        bean.setScanFollowCountTotal(0L);
+        bean.setScanFollowCountDay(0L);
+        bean.setScanFollowCountHour(0L);
+        bean.setWechatAppRegisterUvTotal(0L);
+        bean.setWechatAppRegisterUvDay(0L);
+        bean.setWechatAppRegisterUvHour(0L);
+        bean.setWechatMinigameRegisterCostAll(0L);
+        bean.setWechatMinigameRegisterCostDay(0L);
+        bean.setWechatMinigameRegisterCostHour(0L);
+        bean.setWechatMinigameRegisterRateAll(0.0);
+        bean.setWechatMinigameRegisterRateDay(0.0);
+        bean.setWechatMinigameRegisterRateHour(0.0);
+        bean.setWechatMinigameArpuAll(0.0);
+        bean.setWechatMinigameArpuDay(0.0);
+        bean.setWechatMinigameArpuHour(0.0);
+        bean.setWechatMinigameRetentionCountTotal(0L);
+        bean.setWechatMinigameRetentionCountDay(0L);
+        bean.setWechatMinigameRetentionCountHour(0L);
+        bean.setWechatMinigameCheckoutCountTotal(0L);
+        bean.setWechatMinigameCheckoutCountDay(0L);
+        bean.setWechatMinigameCheckoutCountHour(0L);
+        bean.setWechatMinigameCheckoutAmountTotal(0L);
+        bean.setWechatMinigameCheckoutAmountDay(0L);
+        bean.setWechatMinigameCheckoutAmountHour(0L);
+        bean.setOfficialAccountFollowCountTotal(0L);
+        bean.setOfficialAccountFollowCountDay(0L);
+        bean.setOfficialAccountFollowCountHour(0L);
+        bean.setOfficialAccountFollowRateAll(0.0);
+        bean.setOfficialAccountFollowRateDay(0.0);
+        bean.setOfficialAccountFollowRateHour(0.0);
+        bean.setOfficialAccountRegisterUserCountTotal(0L);
+        bean.setOfficialAccountRegisterUserCountDay(0L);
+        bean.setOfficialAccountRegisterUserCountHour(0L);
+        bean.setOfficialAccountRegisterRateAll(0.0);
+        bean.setOfficialAccountRegisterRateDay(0.0);
+        bean.setOfficialAccountRegisterRateHour(0.0);
+        bean.setOfficialAccountRegisterCostAll(0L);
+        bean.setOfficialAccountRegisterCostDay(0L);
+        bean.setOfficialAccountRegisterCostHour(0L);
+        bean.setOfficialAccountRegisterAmountTotal(0L);
+        bean.setOfficialAccountRegisterAmountDay(0L);
+        bean.setOfficialAccountRegisterAmountHour(0L);
+        bean.setOfficialAccountRegisterRoiAll(0L);
+        bean.setOfficialAccountRegisterRoiDay(0L);
+        bean.setOfficialAccountRegisterRoiHour(0L);
+        bean.setOfficialAccountApplyCountTotal(0L);
+        bean.setOfficialAccountApplyCountDay(0L);
+        bean.setOfficialAccountApplyCountHour(0L);
+        bean.setOfficialAccountApplyUserCountTotal(0L);
+        bean.setOfficialAccountApplyUserCountDay(0L);
+        bean.setOfficialAccountApplyUserCountHour(0L);
+        bean.setOfficialAccountApplyRateAll(0.0);
+        bean.setOfficialAccountApplyRateDay(0.0);
+        bean.setOfficialAccountApplyRateHour(0.0);
+        bean.setOfficialAccountApplyCostAll(0L);
+        bean.setOfficialAccountApplyCostDay(0L);
+        bean.setOfficialAccountApplyCostHour(0L);
+        bean.setOfficialAccountApplyAmountTotal(0L);
+        bean.setOfficialAccountApplyAmountDay(0L);
+        bean.setOfficialAccountApplyAmountHour(0L);
+        bean.setOfficialAccountApplyRoiAll(0L);
+        bean.setOfficialAccountApplyRoiDay(0L);
+        bean.setOfficialAccountApplyRoiHour(0L);
+        bean.setOfficialAccountOrderCountTotal(0L);
+        bean.setOfficialAccountOrderCountDay(0L);
+        bean.setOfficialAccountOrderCountHour(0L);
+        bean.setOfficialAccountFirstDayOrderCountTotal(0L);
+        bean.setOfficialAccountFirstDayOrderCountDay(0L);
+        bean.setOfficialAccountFirstDayOrderCountHour(0L);
+        bean.setOfficialAccountOrderUserCountTotal(0L);
+        bean.setOfficialAccountOrderUserCountDay(0L);
+        bean.setOfficialAccountOrderUserCountHour(0L);
+        bean.setOfficialAccountOrderRateAll(0.0);
+        bean.setOfficialAccountOrderRateDay(0.0);
+        bean.setOfficialAccountOrderRateHour(0.0);
+        bean.setOfficialAccountOrderCostAll(0L);
+        bean.setOfficialAccountOrderCostDay(0L);
+        bean.setOfficialAccountOrderCostHour(0L);
+        bean.setOfficialAccountOrderAmountTotal(0L);
+        bean.setOfficialAccountOrderAmountDay(0L);
+        bean.setOfficialAccountOrderAmountHour(0L);
+        bean.setOfficialAccountFirstDayOrderAmountTotal(0L);
+        bean.setOfficialAccountFirstDayOrderAmountDay(0L);
+        bean.setOfficialAccountFirstDayOrderAmountHour(0L);
+        bean.setOfficialAccountOrderRoiAll(0L);
+        bean.setOfficialAccountOrderRoiDay(0L);
+        bean.setOfficialAccountOrderRoiHour(0L);
+        bean.setOfficialAccountConsultCountTotal(0L);
+        bean.setOfficialAccountConsultCountDay(0L);
+        bean.setOfficialAccountConsultCountHour(0L);
+        bean.setOfficialAccountReaderCountTotal(0L);
+        bean.setOfficialAccountReaderCountDay(0L);
+        bean.setOfficialAccountReaderCountHour(0L);
+        bean.setOfficialAccountCreditApplyUserCountTotal(0L);
+        bean.setOfficialAccountCreditApplyUserCountDay(0L);
+        bean.setOfficialAccountCreditApplyUserCountHour(0L);
+        bean.setOfficialAccountCreditUserCountTotal(0L);
+        bean.setOfficialAccountCreditUserCountDay(0L);
+        bean.setOfficialAccountCreditUserCountHour(0L);
+        bean.setForwardCountTotal(0L);
+        bean.setForwardCountDay(0L);
+        bean.setForwardCountHour(0L);
+        bean.setForwardUserCountTotal(0L);
+        bean.setForwardUserCountDay(0L);
+        bean.setForwardUserCountHour(0L);
+        bean.setNoInterestCountTotal(0L);
+        bean.setNoInterestCountDay(0L);
+        bean.setNoInterestCountHour(0L);
+    }
 }

+ 245 - 308
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/pojo/entity/PlanStatOfHourDWD.java

@@ -1221,435 +1221,372 @@ public class PlanStatOfHourDWD {
         return result;
     }
 
-    public static PlanStatOfHourDWD reduce(PlanStatOfHourDWD value1, AdDataOfHourODS value2, long createTime) {
+    public static PlanStatOfHourDWD reduce(PlanStatOfDayDWD yesterdayDWD, PlanStatOfHourDWD value1, AdDataOfHourODS value2, long createTime) {
         PlanStatOfHourDWD result = new PlanStatOfHourDWD();
         BeanUtils.copyProperties(value2, result);
         result.setCreateTime(new Date(createTime));
+
+        Map<Long, Set<Long>> adGroupMap = new HashMap<>();
+        Set<Long> adIdsTemp = new HashSet<>(16);
+        adIdsTemp.add(value2.getAdId());
+        adGroupMap.put(value2.getAdgroupId(), adIdsTemp);
+        result.setAdGroupMap(adGroupMap);
+
+        Set<Long> adIds = new HashSet<>(16);
+        adIds.add(value2.getAdId());
+        result.setAdIds(adIds);
+        result.setCostDeviationRateHour(value2.getCostDeviationRate());
+        result.setCostHour(value2.getCost());
+        result.setCompensationAmountHour(value2.getCompensationAmount());
+        result.setViewCountHour(value2.getViewCount());
+        result.setThousandDisplayPriceHour(value2.getThousandDisplayPrice());
+        result.setAvgViewPerUserHour(value2.getAvgViewPerUser());
+        result.setValidClickCountHour(value2.getValidClickCount());
+        result.setCtrHour(value2.getCtr());
+        result.setCpcHour(value2.getCpc());
+        result.setValuableClickCountHour(value2.getValuableClickCount());
+        result.setValuableClickRateHour(value2.getValuableClickRate());
+        result.setValuableClickCostHour(value2.getValuableClickCost());
+        result.setConversionsCountHour(value2.getConversionsCount());
+        result.setConversionsCostHour(value2.getConversionsCost());
+        result.setConversionsRateHour(value2.getConversionsRate());
+        result.setDeepConversionsCountHour(value2.getDeepConversionsCount());
+        result.setDeepConversionsCostHour(value2.getDeepConversionsCost());
+        result.setDeepConversionsRateHour(value2.getDeepConversionsRate());
+        result.setOrderCountHour(value2.getOrderCount());
+        result.setFirstDayOrderCountHour(value2.getFirstDayOrderCount());
+        result.setWebOrderCostHour(value2.getWebOrderCost());
+        result.setOrderRateHour(value2.getOrderRate());
+        result.setOrderAmountHour(value2.getOrderAmount());
+        result.setFirstDayOrderAmountHour(value2.getFirstDayOrderAmount());
+        result.setOrderUnitPriceHour(value2.getOrderUnitPrice());
+        result.setOrderRoiHour(value2.getOrderRoi());
+        result.setSignInCountHour(value2.getSignInCount());
+        result.setScanFollowCountHour(value2.getScanFollowCount());
+        result.setWechatAppRegisterUvHour(value2.getWechatAppRegisterUv());
+        result.setWechatMinigameRegisterCostHour(value2.getWechatMinigameRegisterCost());
+        result.setWechatMinigameRegisterRateHour(value2.getWechatMinigameRegisterRate());
+        result.setWechatMinigameArpuHour(value2.getWechatMinigameArpu());
+        result.setWechatMinigameRetentionCountHour(value2.getWechatMinigameRetentionCount());
+        result.setWechatMinigameCheckoutCountHour(value2.getWechatMinigameCheckoutCount());
+        result.setWechatMinigameCheckoutAmountHour(value2.getWechatMinigameCheckoutAmount());
+        result.setOfficialAccountFollowCountHour(value2.getOfficialAccountFollowCount());
+        result.setOfficialAccountFollowRateHour(value2.getOfficialAccountFollowRate());
+        result.setOfficialAccountRegisterUserCountHour(value2.getOfficialAccountRegisterUserCount());
+        result.setOfficialAccountRegisterRateHour(value2.getOfficialAccountRegisterRate());
+        result.setOfficialAccountRegisterCostHour(value2.getOfficialAccountRegisterCost());
+        result.setOfficialAccountRegisterAmountHour(value2.getOfficialAccountRegisterAmount());
+        result.setOfficialAccountRegisterRoiHour(value2.getOfficialAccountRegisterRoi());
+        result.setOfficialAccountApplyCountHour(value2.getOfficialAccountApplyCount());
+        result.setOfficialAccountApplyUserCountHour(value2.getOfficialAccountApplyUserCount());
+        result.setOfficialAccountApplyRateHour(value2.getOfficialAccountApplyRate());
+        result.setOfficialAccountApplyCostHour(value2.getOfficialAccountApplyCost());
+        result.setOfficialAccountApplyAmountHour(value2.getOfficialAccountApplyAmount());
+        result.setOfficialAccountApplyRoiHour(value2.getOfficialAccountApplyRoi());
+        result.setOfficialAccountOrderCountHour(value2.getOfficialAccountOrderCount());
+        result.setOfficialAccountFirstDayOrderCountHour(value2.getOfficialAccountFirstDayOrderCount());
+        result.setOfficialAccountOrderUserCountHour(value2.getOfficialAccountOrderUserCount());
+        result.setOfficialAccountOrderRateHour(value2.getOfficialAccountOrderRate());
+        result.setOfficialAccountOrderCostHour(value2.getOfficialAccountOrderCost());
+        result.setOfficialAccountOrderAmountHour(value2.getOfficialAccountOrderAmount());
+        result.setOfficialAccountFirstDayOrderAmountHour(value2.getOfficialAccountFirstDayOrderAmount());
+        result.setOfficialAccountOrderRoiHour(value2.getOfficialAccountOrderRoi());
+        result.setOfficialAccountConsultCountHour(value2.getOfficialAccountConsultCount());
+        result.setOfficialAccountReaderCountHour(value2.getOfficialAccountReaderCount());
+        result.setOfficialAccountCreditApplyUserCountHour(value2.getOfficialAccountCreditApplyUserCount());
+        result.setOfficialAccountCreditUserCountHour(value2.getOfficialAccountCreditUserCount());
+        result.setForwardCountHour(value2.getForwardCount());
+        result.setForwardUserCountHour(value2.getForwardUserCount());
+        result.setNoInterestCountHour(value2.getNoInterestCount());
         if (value1 == null) {
-            Map<Long, Set<Long>> adGroupMap = new HashMap<>();
-            Set<Long> adIdsTemp = new HashSet<>(3);
-            adIdsTemp.add(value2.getAdId());
-            adGroupMap.put(value2.getAdgroupId(), adIdsTemp);
-            result.setAdGroupMap(adGroupMap);
-            result.setAdGroupMapStr(PlanUtil.adGroupMapStr(adGroupMap));
-
-            Set<Long> adIds = new HashSet<>(3);
-            adIds.add(value2.getAdId());
-            result.setAdIds(adIds);
-            result.setAdIdsStr(PlanUtil.adIdsStr(value2.getAdId()));
-
-            result.setCostDeviationRateTotal(value2.getCostDeviationRate());
             result.setCostDeviationRateDay(value2.getCostDeviationRate());
-            result.setCostDeviationRateHour(value2.getCostDeviationRate());
-            result.setCostTotal(value2.getCost());
             result.setCostDay(value2.getCost());
-            result.setCostHour(value2.getCost());
-            result.setCompensationAmountTotal(value2.getCompensationAmount());
             result.setCompensationAmountDay(value2.getCompensationAmount());
-            result.setCompensationAmountHour(value2.getCompensationAmount());
-            result.setViewCountTotal(value2.getViewCount());
             result.setViewCountDay(value2.getViewCount());
-            result.setViewCountHour(value2.getViewCount());
-            result.setThousandDisplayPriceAll(value2.getThousandDisplayPrice());
             result.setThousandDisplayPriceDay(value2.getThousandDisplayPrice());
-            result.setThousandDisplayPriceHour(value2.getThousandDisplayPrice());
-            result.setAvgViewPerUserHour(value2.getAvgViewPerUser());
-            result.setValidClickCountTotal(value2.getValidClickCount());
             result.setValidClickCountDay(value2.getValidClickCount());
-            result.setValidClickCountHour(value2.getValidClickCount());
-            result.setCtrAll(value2.getCtr());
             result.setCtrDay(value2.getCtr());
-            result.setCtrHour(value2.getCtr());
-            result.setCpcAll(value2.getCpc());
             result.setCpcDay(value2.getCpc());
-            result.setCpcHour(value2.getCpc());
-            result.setValuableClickCountTotal(value2.getValuableClickCount());
             result.setValuableClickCountDay(value2.getValuableClickCount());
-            result.setValuableClickCountHour(value2.getValuableClickCount());
-            result.setValuableClickRateAll(value2.getValuableClickRate());
             result.setValuableClickRateDay(value2.getValuableClickRate());
-            result.setValuableClickRateHour(value2.getValuableClickRate());
-            result.setValuableClickCostAll(value2.getValuableClickCost());
             result.setValuableClickCostDay(value2.getValuableClickCost());
-            result.setValuableClickCostHour(value2.getValuableClickCost());
-            result.setConversionsCountTotal(value2.getConversionsCount());
             result.setConversionsCountDay(value2.getConversionsCount());
-            result.setConversionsCountHour(value2.getConversionsCount());
-            result.setConversionsCostAll(value2.getConversionsCost());
             result.setConversionsCostDay(value2.getConversionsCost());
-            result.setConversionsCostHour(value2.getConversionsCost());
-            result.setConversionsRateAll(value2.getConversionsRate());
             result.setConversionsRateDay(value2.getConversionsRate());
-            result.setConversionsRateHour(value2.getConversionsRate());
-            result.setDeepConversionsCountTotal(value2.getDeepConversionsCount());
             result.setDeepConversionsCountDay(value2.getDeepConversionsCount());
-            result.setDeepConversionsCountHour(value2.getDeepConversionsCount());
-            result.setDeepConversionsCostAll(value2.getDeepConversionsCost());
             result.setDeepConversionsCostDay(value2.getDeepConversionsCost());
-            result.setDeepConversionsCostHour(value2.getDeepConversionsCost());
-            result.setDeepConversionsRateAll(value2.getDeepConversionsRate());
             result.setDeepConversionsRateDay(value2.getDeepConversionsRate());
-            result.setDeepConversionsRateHour(value2.getDeepConversionsRate());
-            result.setOrderCountTotal(value2.getOrderCount());
             result.setOrderCountDay(value2.getOrderCount());
-            result.setOrderCountHour(value2.getOrderCount());
-            result.setFirstDayOrderCountTotal(value2.getFirstDayOrderCount());
             result.setFirstDayOrderCountDay(value2.getFirstDayOrderCount());
-            result.setFirstDayOrderCountHour(value2.getFirstDayOrderCount());
-            result.setWebOrderCostAll(value2.getWebOrderCost());
             result.setWebOrderCostDay(value2.getWebOrderCost());
-            result.setWebOrderCostHour(value2.getWebOrderCost());
-            result.setOrderRateAll(value2.getOrderRate());
             result.setOrderRateDay(value2.getOrderRate());
-            result.setOrderRateHour(value2.getOrderRate());
-            result.setOrderAmountTotal(value2.getOrderAmount());
             result.setOrderAmountDay(value2.getOrderAmount());
-            result.setOrderAmountHour(value2.getOrderAmount());
-            result.setFirstDayOrderAmountTotal(value2.getFirstDayOrderAmount());
             result.setFirstDayOrderAmountDay(value2.getFirstDayOrderAmount());
-            result.setFirstDayOrderAmountHour(value2.getFirstDayOrderAmount());
-            result.setOrderUnitPriceAll(value2.getOrderUnitPrice());
             result.setOrderUnitPriceDay(value2.getOrderUnitPrice());
-            result.setOrderUnitPriceHour(value2.getOrderUnitPrice());
-            result.setOrderRoiAll(value2.getOrderRoi());
             result.setOrderRoiDay(value2.getOrderRoi());
-            result.setOrderRoiHour(value2.getOrderRoi());
-            result.setSignInCountTotal(value2.getSignInCount());
             result.setSignInCountDay(value2.getSignInCount());
-            result.setSignInCountHour(value2.getSignInCount());
-            result.setScanFollowCountTotal(value2.getScanFollowCount());
             result.setScanFollowCountDay(value2.getScanFollowCount());
-            result.setScanFollowCountHour(value2.getScanFollowCount());
-            result.setWechatAppRegisterUvTotal(value2.getWechatAppRegisterUv());
             result.setWechatAppRegisterUvDay(value2.getWechatAppRegisterUv());
-            result.setWechatAppRegisterUvHour(value2.getWechatAppRegisterUv());
-            result.setWechatMinigameRegisterCostAll(value2.getWechatMinigameRegisterCost());
             result.setWechatMinigameRegisterCostDay(value2.getWechatMinigameRegisterCost());
-            result.setWechatMinigameRegisterCostHour(value2.getWechatMinigameRegisterCost());
-            result.setWechatMinigameRegisterRateAll(value2.getWechatMinigameRegisterRate());
             result.setWechatMinigameRegisterRateDay(value2.getWechatMinigameRegisterRate());
-            result.setWechatMinigameRegisterRateHour(value2.getWechatMinigameRegisterRate());
-            result.setWechatMinigameArpuAll(value2.getWechatMinigameArpu());
             result.setWechatMinigameArpuDay(value2.getWechatMinigameArpu());
-            result.setWechatMinigameArpuHour(value2.getWechatMinigameArpu());
-            result.setWechatMinigameRetentionCountTotal(value2.getWechatMinigameRetentionCount());
             result.setWechatMinigameRetentionCountDay(value2.getWechatMinigameRetentionCount());
-            result.setWechatMinigameRetentionCountHour(value2.getWechatMinigameRetentionCount());
-            result.setWechatMinigameCheckoutCountTotal(value2.getWechatMinigameCheckoutCount());
             result.setWechatMinigameCheckoutCountDay(value2.getWechatMinigameCheckoutCount());
-            result.setWechatMinigameCheckoutCountHour(value2.getWechatMinigameCheckoutCount());
-            result.setWechatMinigameCheckoutAmountTotal(value2.getWechatMinigameCheckoutAmount());
             result.setWechatMinigameCheckoutAmountDay(value2.getWechatMinigameCheckoutAmount());
-            result.setWechatMinigameCheckoutAmountHour(value2.getWechatMinigameCheckoutAmount());
-            result.setOfficialAccountFollowCountTotal(value2.getOfficialAccountFollowCount());
             result.setOfficialAccountFollowCountDay(value2.getOfficialAccountFollowCount());
-            result.setOfficialAccountFollowCountHour(value2.getOfficialAccountFollowCount());
-            result.setOfficialAccountFollowRateAll(value2.getOfficialAccountFollowRate());
             result.setOfficialAccountFollowRateDay(value2.getOfficialAccountFollowRate());
-            result.setOfficialAccountFollowRateHour(value2.getOfficialAccountFollowRate());
-            result.setOfficialAccountRegisterUserCountTotal(value2.getOfficialAccountRegisterUserCount());
             result.setOfficialAccountRegisterUserCountDay(value2.getOfficialAccountRegisterUserCount());
-            result.setOfficialAccountRegisterUserCountHour(value2.getOfficialAccountRegisterUserCount());
-            result.setOfficialAccountRegisterRateAll(value2.getOfficialAccountRegisterRate());
             result.setOfficialAccountRegisterRateDay(value2.getOfficialAccountRegisterRate());
-            result.setOfficialAccountRegisterRateHour(value2.getOfficialAccountRegisterRate());
-            result.setOfficialAccountRegisterCostAll(value2.getOfficialAccountRegisterCost());
             result.setOfficialAccountRegisterCostDay(value2.getOfficialAccountRegisterCost());
-            result.setOfficialAccountRegisterCostHour(value2.getOfficialAccountRegisterCost());
-            result.setOfficialAccountRegisterAmountTotal(value2.getOfficialAccountRegisterAmount());
             result.setOfficialAccountRegisterAmountDay(value2.getOfficialAccountRegisterAmount());
-            result.setOfficialAccountRegisterAmountHour(value2.getOfficialAccountRegisterAmount());
-            result.setOfficialAccountRegisterRoiAll(value2.getOfficialAccountRegisterRoi());
             result.setOfficialAccountRegisterRoiDay(value2.getOfficialAccountRegisterRoi());
-            result.setOfficialAccountRegisterRoiHour(value2.getOfficialAccountRegisterRoi());
-            result.setOfficialAccountApplyCountTotal(value2.getOfficialAccountApplyCount());
             result.setOfficialAccountApplyCountDay(value2.getOfficialAccountApplyCount());
-            result.setOfficialAccountApplyCountHour(value2.getOfficialAccountApplyCount());
-            result.setOfficialAccountApplyUserCountTotal(value2.getOfficialAccountApplyUserCount());
             result.setOfficialAccountApplyUserCountDay(value2.getOfficialAccountApplyUserCount());
-            result.setOfficialAccountApplyUserCountHour(value2.getOfficialAccountApplyUserCount());
-            result.setOfficialAccountApplyRateAll(value2.getOfficialAccountApplyRate());
             result.setOfficialAccountApplyRateDay(value2.getOfficialAccountApplyRate());
-            result.setOfficialAccountApplyRateHour(value2.getOfficialAccountApplyRate());
-            result.setOfficialAccountApplyCostAll(value2.getOfficialAccountApplyCost());
             result.setOfficialAccountApplyCostDay(value2.getOfficialAccountApplyCost());
-            result.setOfficialAccountApplyCostHour(value2.getOfficialAccountApplyCost());
-            result.setOfficialAccountApplyAmountTotal(value2.getOfficialAccountApplyAmount());
             result.setOfficialAccountApplyAmountDay(value2.getOfficialAccountApplyAmount());
-            result.setOfficialAccountApplyAmountHour(value2.getOfficialAccountApplyAmount());
-            result.setOfficialAccountApplyRoiAll(value2.getOfficialAccountApplyRoi());
             result.setOfficialAccountApplyRoiDay(value2.getOfficialAccountApplyRoi());
-            result.setOfficialAccountApplyRoiHour(value2.getOfficialAccountApplyRoi());
-            result.setOfficialAccountOrderCountTotal(value2.getOfficialAccountOrderCount());
             result.setOfficialAccountOrderCountDay(value2.getOfficialAccountOrderCount());
-            result.setOfficialAccountOrderCountHour(value2.getOfficialAccountOrderCount());
-            result.setOfficialAccountFirstDayOrderCountTotal(value2.getOfficialAccountFirstDayOrderCount());
             result.setOfficialAccountFirstDayOrderCountDay(value2.getOfficialAccountFirstDayOrderCount());
-            result.setOfficialAccountFirstDayOrderCountHour(value2.getOfficialAccountFirstDayOrderCount());
-            result.setOfficialAccountOrderUserCountTotal(value2.getOfficialAccountOrderUserCount());
             result.setOfficialAccountOrderUserCountDay(value2.getOfficialAccountOrderUserCount());
-            result.setOfficialAccountOrderUserCountHour(value2.getOfficialAccountOrderUserCount());
-            result.setOfficialAccountOrderRateAll(value2.getOfficialAccountOrderRate());
             result.setOfficialAccountOrderRateDay(value2.getOfficialAccountOrderRate());
-            result.setOfficialAccountOrderRateHour(value2.getOfficialAccountOrderRate());
-            result.setOfficialAccountOrderCostAll(value2.getOfficialAccountOrderCost());
             result.setOfficialAccountOrderCostDay(value2.getOfficialAccountOrderCost());
-            result.setOfficialAccountOrderCostHour(value2.getOfficialAccountOrderCost());
-            result.setOfficialAccountOrderAmountTotal(value2.getOfficialAccountOrderAmount());
             result.setOfficialAccountOrderAmountDay(value2.getOfficialAccountOrderAmount());
-            result.setOfficialAccountOrderAmountHour(value2.getOfficialAccountOrderAmount());
-            result.setOfficialAccountFirstDayOrderAmountTotal(value2.getOfficialAccountFirstDayOrderAmount());
             result.setOfficialAccountFirstDayOrderAmountDay(value2.getOfficialAccountFirstDayOrderAmount());
-            result.setOfficialAccountFirstDayOrderAmountHour(value2.getOfficialAccountFirstDayOrderAmount());
-            result.setOfficialAccountOrderRoiAll(value2.getOfficialAccountOrderRoi());
             result.setOfficialAccountOrderRoiDay(value2.getOfficialAccountOrderRoi());
-            result.setOfficialAccountOrderRoiHour(value2.getOfficialAccountOrderRoi());
-            result.setOfficialAccountConsultCountTotal(value2.getOfficialAccountConsultCount());
             result.setOfficialAccountConsultCountDay(value2.getOfficialAccountConsultCount());
-            result.setOfficialAccountConsultCountHour(value2.getOfficialAccountConsultCount());
-            result.setOfficialAccountReaderCountTotal(value2.getOfficialAccountReaderCount());
             result.setOfficialAccountReaderCountDay(value2.getOfficialAccountReaderCount());
-            result.setOfficialAccountReaderCountHour(value2.getOfficialAccountReaderCount());
-            result.setOfficialAccountCreditApplyUserCountTotal(value2.getOfficialAccountCreditApplyUserCount());
             result.setOfficialAccountCreditApplyUserCountDay(value2.getOfficialAccountCreditApplyUserCount());
-            result.setOfficialAccountCreditApplyUserCountHour(value2.getOfficialAccountCreditApplyUserCount());
-            result.setOfficialAccountCreditUserCountTotal(value2.getOfficialAccountCreditUserCount());
             result.setOfficialAccountCreditUserCountDay(value2.getOfficialAccountCreditUserCount());
-            result.setOfficialAccountCreditUserCountHour(value2.getOfficialAccountCreditUserCount());
-            result.setForwardCountTotal(value2.getForwardCount());
             result.setForwardCountDay(value2.getForwardCount());
-            result.setForwardCountHour(value2.getForwardCount());
-            result.setForwardUserCountTotal(value2.getForwardUserCount());
             result.setForwardUserCountDay(value2.getForwardUserCount());
-            result.setForwardUserCountHour(value2.getForwardUserCount());
-            result.setNoInterestCountTotal(value2.getNoInterestCount());
             result.setNoInterestCountDay(value2.getNoInterestCount());
-            result.setNoInterestCountHour(value2.getNoInterestCount());
         } else {
-            result.setAdGroupMap(value1.getAdGroupMap());
-            result.setAdIds(value1.getAdIds());
-            result.getAdGroupMap().computeIfAbsent(value2.getAdgroupId(), key -> new HashSet<>(3)).add(value2.getAdId());
-            result.setAdGroupMapStr(PlanUtil.adGroupMapStr(result.getAdGroupMap()));
-            result.getAdIds().add(value2.getAdId());
-            result.setAdIdsStr(PlanUtil.adIdsStr(result.getAdIds()));
-
-            // 是否是同一天
-            boolean isUnSameDay = !value1.getStatDay().equals(value2.getStatDay());
-            result.setCostDeviationRateTotal(value1.getCostDeviationRateTotal() + value2.getCostDeviationRate());
-            result.setCostDeviationRateDay(isUnSameDay ? 0: value1.getCostDeviationRateDay() + value2.getCostDeviationRate());
-            result.setCostDeviationRateHour(value2.getCostDeviationRate());
-            result.setCostTotal(value1.getCostTotal() + value2.getCost());
-            result.setCostDay(isUnSameDay ? 0: value1.getCostDay() + value2.getCost());
-            result.setCostHour(value2.getCost());
-            result.setCompensationAmountTotal(value1.getCompensationAmountTotal() + value2.getCompensationAmount());
-            result.setCompensationAmountDay(isUnSameDay ? 0: value1.getCompensationAmountDay() + value2.getCompensationAmount());
-            result.setCompensationAmountHour(value2.getCompensationAmount());
-            result.setViewCountTotal(value1.getViewCountTotal() + value2.getViewCount());
-            result.setViewCountDay(isUnSameDay ? 0: value1.getViewCountDay() + value2.getViewCount());
-            result.setViewCountHour(value2.getViewCount());
+            result.getAdIds().addAll(value1.getAdIds());
+            PlanUtil.reduceAdGroup(result.getAdGroupMap(), value1.getAdGroupMap());
+
+            result.setCostDeviationRateDay(value1.getCostDeviationRateDay() + value2.getCostDeviationRate());
+            result.setCostDay(value1.getCostDay() + value2.getCost());
+            result.setCompensationAmountDay(value1.getCompensationAmountDay() + value2.getCompensationAmount());
+            result.setViewCountDay(value1.getViewCountDay() + value2.getViewCount());
+            result.setThousandDisplayPriceDay(result.getViewCountDay() == 0 ? 0 : (result.getCostDay() / result.getViewCountDay() * 1000));
+            result.setValidClickCountDay(value1.getValidClickCountDay() + value2.getValidClickCount());
+            result.setCtrDay(result.getViewCountDay() == 0 ? 0.0 : result.getValidClickCountDay() / result.getViewCountDay());
+            result.setCpcDay(result.getValidClickCountDay() == 0 ? 0 : result.getCostDay() / result.getValidClickCountDay());
+            result.setValuableClickCountDay(value1.getValuableClickCountDay() + value2.getValuableClickCount());
+            result.setValuableClickRateDay(result.getViewCountDay() == 0 ? 0.0 : result.getValuableClickCountDay() / result.getViewCountDay());
+            result.setValuableClickCostDay(result.getValuableClickCountDay() == 0 ? 0 : result.getCostDay() / result.getValuableClickCountDay());
+            result.setConversionsCountDay(value1.getConversionsCountDay() + value2.getConversionsCount());
+            result.setConversionsCostDay(result.getConversionsCountDay() == 0 ? 0 : result.getCostDay() / result.getConversionsCountDay());
+            result.setConversionsRateDay(result.getValidClickCountDay() == 0 ? 0.0 : result.getConversionsCountDay() / result.getValidClickCountDay());
+            result.setDeepConversionsCountDay(value1.getDeepConversionsCountDay() + value2.getDeepConversionsCount());
+            result.setDeepConversionsCostDay(result.getDeepConversionsCountDay() == 0 ? 0 : result.getCostDay() / result.getDeepConversionsCountDay());
+            result.setDeepConversionsRateDay(result.getValuableClickCountDay() == 0 ? 0.0 : result.getDeepConversionsCountDay() / result.getValuableClickCountDay());
+            result.setOrderCountDay(value1.getOrderCountDay() + value2.getOrderCount());
+            result.setFirstDayOrderCountDay(value1.getFirstDayOrderCountDay() + value2.getFirstDayOrderCount());
+            result.setWebOrderCostDay(result.getOrderCountDay() == 0 ? 0 : result.getCostDay() / result.getOrderCountDay());
+            result.setOrderRateDay(result.getValidClickCountDay() == 0 ? 0.0 : result.getOrderCountDay() / result.getValidClickCountDay());
+            result.setOrderAmountDay(value1.getOrderAmountDay() + value2.getOrderAmount());
+            result.setFirstDayOrderAmountDay(value1.getFirstDayOrderAmountDay() + value2.getFirstDayOrderAmount());
+            result.setOrderUnitPriceDay(result.getOrderCountDay() == 0 ? 0 : result.getOrderAmountDay() / result.getOrderCountDay());
+            result.setOrderRoiDay(result.getCostDay() == 0 ? 0.0 : result.getOrderAmountDay() / result.getCostDay());
+            result.setSignInCountDay(value1.getSignInCountDay() + value2.getSignInCount());
+            result.setScanFollowCountDay(value1.getScanFollowCountDay() + value2.getScanFollowCount());
+            result.setWechatAppRegisterUvDay(value1.getWechatAppRegisterUvDay() + value2.getWechatAppRegisterUv());
+            result.setWechatMinigameRegisterCostDay(result.getWechatAppRegisterUvDay() == 0 ? 0 : result.getCostDay() / result.getWechatAppRegisterUvDay());
+            result.setWechatMinigameRegisterRateDay(result.getValidClickCountDay() == 0 ? 0.0 : result.getWechatAppRegisterUvDay() / result.getValidClickCountDay());
+            result.setWechatMinigameArpuDay(result.getWechatAppRegisterUvDay() == 0 ? 0.0 : result.getOrderAmountDay() / result.getWechatAppRegisterUvDay());
+            result.setWechatMinigameRetentionCountDay(value1.getWechatMinigameRetentionCountDay() + value2.getWechatMinigameRetentionCount());
+            result.setWechatMinigameCheckoutCountDay(value1.getWechatMinigameCheckoutCountDay() + value2.getWechatMinigameCheckoutCount());
+            result.setWechatMinigameCheckoutAmountDay(value1.getWechatMinigameCheckoutAmountDay() + value2.getWechatMinigameCheckoutAmount());
+            result.setOfficialAccountFollowCountDay(value1.getOfficialAccountFollowCountDay() + value2.getOfficialAccountFollowCount());
+            result.setOfficialAccountFollowRateDay(result.getValidClickCountDay() == 0 ? 0.0 : result.getOfficialAccountFollowCountDay() / result.getValidClickCountDay());
+            result.setOfficialAccountRegisterUserCountDay(value1.getOfficialAccountRegisterUserCountDay() + value2.getOfficialAccountRegisterUserCount());
+            result.setOfficialAccountRegisterRateDay(result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountRegisterUserCountDay() / result.getOfficialAccountFollowCountDay());
+            result.setOfficialAccountRegisterCostDay(result.getOfficialAccountRegisterUserCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountRegisterUserCountDay());
+            result.setOfficialAccountRegisterAmountDay(value1.getOfficialAccountRegisterAmountDay() + value2.getOfficialAccountRegisterAmount());
+            result.setOfficialAccountRegisterRoiDay(result.getCostDay() == 0 ? 0 : result.getOfficialAccountRegisterAmountDay() / result.getCostDay());
+            result.setOfficialAccountApplyCountDay(value1.getOfficialAccountApplyCountDay() + value2.getOfficialAccountApplyCount());
+            result.setOfficialAccountApplyUserCountDay(value1.getOfficialAccountApplyUserCountDay() + value2.getOfficialAccountApplyUserCount());
+            result.setOfficialAccountApplyRateDay(result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountApplyUserCountDay() / result.getOfficialAccountFollowCountDay());
+            result.setOfficialAccountApplyCostDay(result.getOfficialAccountApplyUserCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountApplyUserCountDay());
+            result.setOfficialAccountApplyAmountDay(value1.getOfficialAccountApplyAmountDay() + value2.getOfficialAccountApplyAmount());
+            result.setOfficialAccountApplyRoiDay(result.getCostDay() == 0 ? 0 : result.getOfficialAccountApplyAmountDay() / result.getCostDay());
+            result.setOfficialAccountOrderCountDay(value1.getOfficialAccountOrderCountDay() + value2.getOfficialAccountOrderCount());
+            result.setOfficialAccountFirstDayOrderCountDay(value1.getOfficialAccountFirstDayOrderCountDay() + value2.getOfficialAccountFirstDayOrderCount());
+            result.setOfficialAccountOrderUserCountDay(value1.getOfficialAccountOrderUserCountDay() + value2.getOfficialAccountOrderUserCount());
+            result.setOfficialAccountOrderRateDay(result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountOrderUserCountDay() / result.getOfficialAccountFollowCountDay());
+            result.setOfficialAccountOrderCostDay(result.getOfficialAccountOrderCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountOrderCountDay());
+            result.setOfficialAccountOrderAmountDay(value1.getOfficialAccountOrderAmountDay() + value2.getOfficialAccountOrderAmount());
+            result.setOfficialAccountFirstDayOrderAmountDay(value1.getOfficialAccountFirstDayOrderAmountDay() + value2.getOfficialAccountFirstDayOrderAmount());
+            result.setOfficialAccountOrderRoiDay(result.getCostDay() == 0 ? 0 : result.getOfficialAccountOrderAmountDay() / result.getCostDay());
+            result.setOfficialAccountConsultCountDay(value1.getOfficialAccountConsultCountDay() + value2.getOfficialAccountConsultCount());
+            result.setOfficialAccountReaderCountDay(value1.getOfficialAccountReaderCountDay() + value2.getOfficialAccountReaderCount());
+            result.setOfficialAccountCreditApplyUserCountDay(value1.getOfficialAccountCreditApplyUserCountDay() + value2.getOfficialAccountCreditApplyUserCount());
+            result.setOfficialAccountCreditUserCountDay(value1.getOfficialAccountCreditUserCountDay() + value2.getOfficialAccountCreditUserCount());
+            result.setForwardCountDay(value1.getForwardCountDay() + value2.getForwardCount());
+            result.setForwardUserCountDay(value1.getForwardUserCountDay() + value2.getForwardUserCount());
+            result.setNoInterestCountDay(value1.getNoInterestCountDay() + value2.getNoInterestCount());
+        }
+        if (yesterdayDWD == null) {
+            result.setCostDeviationRateTotal(result.getCostDeviationRateDay());
+            result.setCostTotal(result.getCostDay());
+            result.setCompensationAmountTotal(result.getCompensationAmountDay());
+            result.setViewCountTotal(result.getViewCountDay());
+            result.setThousandDisplayPriceAll(result.getThousandDisplayPriceDay());
+            result.setValidClickCountTotal(result.getValidClickCountDay());
+            result.setCtrAll(result.getCtrDay());
+            result.setCpcAll(result.getCpcDay());
+            result.setValuableClickCountTotal(result.getValuableClickCountDay());
+            result.setValuableClickRateAll(result.getValuableClickRateDay());
+            result.setValuableClickCostAll(result.getValuableClickCostDay());
+            result.setConversionsCountTotal(result.getConversionsCountDay());
+            result.setConversionsCostAll(result.getConversionsCostDay());
+            result.setConversionsRateAll(result.getConversionsRateDay());
+            result.setDeepConversionsCountTotal(result.getDeepConversionsCountDay());
+            result.setDeepConversionsCostAll(result.getDeepConversionsCostDay());
+            result.setDeepConversionsRateAll(result.getDeepConversionsRateDay());
+            result.setOrderCountTotal(result.getOrderCountDay());
+            result.setFirstDayOrderCountTotal(result.getFirstDayOrderCountDay());
+            result.setWebOrderCostAll(result.getWebOrderCostDay());
+            result.setOrderRateAll(result.getOrderRateDay());
+            result.setOrderAmountTotal(result.getOrderAmountDay());
+            result.setFirstDayOrderAmountTotal(result.getFirstDayOrderAmountDay());
+            result.setOrderUnitPriceAll(result.getOrderUnitPriceDay());
+            result.setOrderRoiAll(result.getOrderRoiDay());
+            result.setSignInCountTotal(result.getSignInCountDay());
+            result.setScanFollowCountTotal(result.getScanFollowCountDay());
+            result.setWechatAppRegisterUvTotal(result.getWechatAppRegisterUvDay());
+            result.setWechatMinigameRegisterCostAll(result.getWechatMinigameRegisterCostDay());
+            result.setWechatMinigameRegisterRateAll(result.getWechatMinigameRegisterRateDay());
+            result.setWechatMinigameArpuAll(result.getWechatMinigameArpuDay());
+            result.setWechatMinigameRetentionCountTotal(result.getWechatMinigameRetentionCountDay());
+            result.setWechatMinigameCheckoutCountTotal(result.getWechatMinigameCheckoutCountDay());
+            result.setWechatMinigameCheckoutAmountTotal(result.getWechatMinigameCheckoutAmountDay());
+            result.setOfficialAccountFollowCountTotal(result.getOfficialAccountFollowCountDay());
+            result.setOfficialAccountFollowRateAll(result.getOfficialAccountFollowRateDay());
+            result.setOfficialAccountRegisterUserCountTotal(result.getOfficialAccountRegisterUserCountDay());
+            result.setOfficialAccountRegisterRateAll(result.getOfficialAccountRegisterRateDay());
+            result.setOfficialAccountRegisterCostAll(result.getOfficialAccountRegisterCostDay());
+            result.setOfficialAccountRegisterAmountTotal(result.getOfficialAccountRegisterAmountDay());
+            result.setOfficialAccountRegisterRoiAll(result.getOfficialAccountRegisterRoiDay());
+            result.setOfficialAccountApplyCountTotal(result.getOfficialAccountApplyCountDay());
+            result.setOfficialAccountApplyUserCountTotal(result.getOfficialAccountApplyUserCountDay());
+            result.setOfficialAccountApplyRateAll(result.getOfficialAccountApplyRateDay());
+            result.setOfficialAccountApplyCostAll(result.getOfficialAccountApplyCostDay());
+            result.setOfficialAccountApplyAmountTotal(result.getOfficialAccountApplyAmountDay());
+            result.setOfficialAccountApplyRoiAll(result.getOfficialAccountApplyRoiDay());
+            result.setOfficialAccountOrderCountTotal(result.getOfficialAccountOrderCountDay());
+            result.setOfficialAccountFirstDayOrderCountTotal(result.getOfficialAccountFirstDayOrderCountDay());
+            result.setOfficialAccountOrderUserCountTotal(result.getOfficialAccountOrderUserCountDay());
+            result.setOfficialAccountOrderRateAll(result.getOfficialAccountOrderRateDay());
+            result.setOfficialAccountOrderCostAll(result.getOfficialAccountOrderCostDay());
+            result.setOfficialAccountOrderAmountTotal(result.getOfficialAccountOrderAmountDay());
+            result.setOfficialAccountFirstDayOrderAmountTotal(result.getOfficialAccountFirstDayOrderAmountDay());
+            result.setOfficialAccountOrderRoiAll(result.getOfficialAccountOrderRoiDay());
+            result.setOfficialAccountConsultCountTotal(result.getOfficialAccountConsultCountDay());
+            result.setOfficialAccountReaderCountTotal(result.getOfficialAccountReaderCountDay());
+            result.setOfficialAccountCreditApplyUserCountTotal(result.getOfficialAccountCreditApplyUserCountDay());
+            result.setOfficialAccountCreditUserCountTotal(result.getOfficialAccountCreditUserCountDay());
+            result.setForwardCountTotal(result.getForwardCountDay());
+            result.setForwardUserCountTotal(result.getForwardUserCountDay());
+            result.setNoInterestCountTotal(result.getNoInterestCountDay());
+        } else {
+            result.getAdIds().addAll(yesterdayDWD.getAdIds());
+            PlanUtil.reduceAdGroup(result.getAdGroupMap(), yesterdayDWD.getAdGroupMap());
+
+            result.setCostDeviationRateTotal(yesterdayDWD.getCostDeviationRateTotal() + result.getCostDeviationRateDay());
+            result.setCostTotal(yesterdayDWD.getCostTotal() + result.getCostDay());
+            result.setCompensationAmountTotal(yesterdayDWD.getCompensationAmountTotal() + result.getCompensationAmountDay());
+            result.setViewCountTotal(yesterdayDWD.getViewCountTotal() + result.getViewCountDay());
             // 总消耗 / 总曝光
             result.setThousandDisplayPriceAll(result.getViewCountTotal() == 0 ? 0 : (result.getCostTotal() / result.getViewCountTotal() * 1000));
-            result.setThousandDisplayPriceDay(isUnSameDay ? 0: result.getViewCountDay() == 0 ? 0 : (result.getCostDay() / result.getViewCountDay() * 1000));
-            result.setThousandDisplayPriceHour(value2.getThousandDisplayPrice());
             // 曝光次数 / 曝光人数(拿不到曝光人数)
-            result.setAvgViewPerUserHour(value2.getAvgViewPerUser());
-            result.setValidClickCountTotal(value1.getValidClickCountTotal() + value2.getValidClickCount());
-            result.setValidClickCountDay(isUnSameDay ? 0: value1.getValidClickCountDay() + value2.getValidClickCount());
-            result.setValidClickCountHour(value2.getValidClickCount());
+            result.setValidClickCountTotal(yesterdayDWD.getValidClickCountTotal() + result.getValidClickCountDay());
             // 广告点击次数 / 广告曝光次数
             result.setCtrAll(result.getViewCountTotal() == 0 ? 0.0 : result.getValidClickCountTotal() / result.getViewCountTotal());
-            result.setCtrDay(isUnSameDay ? 0: result.getViewCountDay() == 0 ? 0.0 : result.getValidClickCountDay() / result.getViewCountDay());
-            result.setCtrHour(value2.getCtr());
             // 广告花费/广告点击次数
             result.setCpcAll(result.getValidClickCountTotal() == 0 ? 0 : result.getCostTotal() / result.getValidClickCountTotal());
-            result.setCpcDay(isUnSameDay ? 0: result.getValidClickCountDay() == 0 ? 0 : result.getCostDay() / result.getValidClickCountDay());
-            result.setCpcHour(value2.getCpc());
-            result.setValuableClickCountTotal(value1.getValuableClickCountTotal() + value2.getValuableClickCount());
-            result.setValuableClickCountDay(isUnSameDay ? 0: value1.getValuableClickCountDay() + value2.getValuableClickCount());
-            result.setValuableClickCountHour(value2.getValuableClickCount());
+            result.setValuableClickCountTotal(yesterdayDWD.getValuableClickCountTotal() + result.getValuableClickCountDay());
             // 广告可转化点击次数/广告曝光次数
             result.setValuableClickRateAll(result.getViewCountTotal() == 0 ? 0.0 : result.getValuableClickCountTotal() / result.getViewCountTotal());
-            result.setValuableClickRateDay(isUnSameDay ? 0: result.getViewCountDay() == 0 ? 0.0 : result.getValuableClickCountDay() / result.getViewCountDay());
-            result.setValuableClickRateHour(value2.getValuableClickRate());
             // 广告花费/可转化点击次数
             result.setValuableClickCostAll(result.getValuableClickCountTotal() == 0 ? 0 : result.getCostTotal() / result.getValuableClickCountTotal());
-            result.setValuableClickCostDay(isUnSameDay ? 0: result.getValuableClickCountDay() == 0 ? 0 : result.getCostDay() / result.getValuableClickCountDay());
-            result.setValuableClickCostHour(value2.getValuableClickCost());
-            result.setConversionsCountTotal(value1.getConversionsCountTotal() + value2.getConversionsCount());
-            result.setConversionsCountDay(isUnSameDay ? 0: value1.getConversionsCountDay() + value2.getConversionsCount());
-            result.setConversionsCountHour(value2.getConversionsCount());
+            result.setConversionsCountTotal(yesterdayDWD.getConversionsCountTotal() + result.getConversionsCountDay());
             // 广告花费/转化目标量
             result.setConversionsCostAll(result.getConversionsCountTotal() == 0 ? 0 : result.getCostTotal() / result.getConversionsCountTotal());
-            result.setConversionsCostDay(isUnSameDay ? 0: result.getConversionsCountDay() == 0 ? 0 : result.getCostDay() / result.getConversionsCountDay());
-            result.setConversionsCostHour(value2.getConversionsCost());
             // 公众号:转化目标量/点击次数。
             result.setConversionsRateAll(result.getValidClickCountTotal() == 0 ? 0.0 : result.getConversionsCountTotal() / result.getValidClickCountTotal());
-            result.setConversionsRateDay(isUnSameDay ? 0: result.getValidClickCountDay() == 0 ? 0.0 : result.getConversionsCountDay() / result.getValidClickCountDay());
-            result.setConversionsRateHour(value2.getConversionsRate());
-            result.setDeepConversionsCountTotal(value1.getDeepConversionsCountTotal() + value2.getDeepConversionsCount());
-            result.setDeepConversionsCountDay(isUnSameDay ? 0: value1.getDeepConversionsCountDay() + value2.getDeepConversionsCount());
-            result.setDeepConversionsCountHour(value2.getDeepConversionsCount());
+            result.setDeepConversionsCountTotal(yesterdayDWD.getDeepConversionsCountTotal() + result.getDeepConversionsCountDay());
             // 广告花费/深度转化目标量
             result.setDeepConversionsCostAll(result.getDeepConversionsCountTotal() == 0 ? 0 : result.getCostTotal() / result.getDeepConversionsCountTotal());
-            result.setDeepConversionsCostDay(isUnSameDay ? 0: result.getDeepConversionsCountDay() == 0 ? 0 : result.getCostDay() / result.getDeepConversionsCountDay());
-            result.setDeepConversionsCostHour(value2.getDeepConversionsCost());
             // 深度转化目标量/可转化点击次数
             result.setDeepConversionsRateAll(result.getValuableClickCountTotal() == 0 ? 0.0 : result.getDeepConversionsCountTotal() / result.getValuableClickCountTotal());
-            result.setDeepConversionsRateDay(isUnSameDay ? 0: result.getValuableClickCountDay() == 0 ? 0.0 : result.getDeepConversionsCountDay() / result.getValuableClickCountDay());
-            result.setDeepConversionsRateHour(value2.getDeepConversionsRate());
-            result.setOrderCountTotal(value1.getOrderCountTotal() + value2.getOrderCount());
-            result.setOrderCountDay(isUnSameDay ? 0: value1.getOrderCountDay() + value2.getOrderCount());
-            result.setOrderCountHour(value2.getOrderCount());
-            result.setFirstDayOrderCountTotal(value1.getFirstDayOrderCountTotal() + value2.getFirstDayOrderCount());
-            result.setFirstDayOrderCountDay(isUnSameDay ? 0: value1.getFirstDayOrderCountDay() + value2.getFirstDayOrderCount());
-            result.setFirstDayOrderCountHour(value2.getFirstDayOrderCount());
+            result.setOrderCountTotal(yesterdayDWD.getOrderCountTotal() + result.getOrderCountDay());
+            result.setFirstDayOrderCountTotal(yesterdayDWD.getFirstDayOrderCountTotal() + result.getFirstDayOrderCountDay());
             // 广告花费/下单量
             result.setWebOrderCostAll(result.getOrderCountTotal() == 0 ? 0 : result.getCostTotal() / result.getOrderCountTotal());
-            result.setWebOrderCostDay(isUnSameDay ? 0: result.getOrderCountDay() == 0 ? 0 : result.getCostDay() / result.getOrderCountDay());
-            result.setWebOrderCostHour(value2.getWebOrderCost());
             // 下单量/点击次数
             result.setOrderRateAll(result.getValidClickCountTotal() == 0 ? 0.0 : result.getOrderCountTotal() / result.getValidClickCountTotal());
-            result.setOrderRateDay(isUnSameDay ? 0: result.getValidClickCountDay() == 0 ? 0.0 : result.getOrderCountDay() / result.getValidClickCountDay());
-            result.setOrderRateHour(value2.getOrderRate());
-            result.setOrderAmountTotal(value1.getOrderAmountTotal() + value2.getOrderAmount());
-            result.setOrderAmountDay(isUnSameDay ? 0: value1.getOrderAmountDay() + value2.getOrderAmount());
-            result.setOrderAmountHour(value2.getOrderAmount());
-            result.setFirstDayOrderAmountTotal(value1.getFirstDayOrderAmountTotal() + value2.getFirstDayOrderAmount());
-            result.setFirstDayOrderAmountDay(isUnSameDay ? 0: value1.getFirstDayOrderAmountDay() + value2.getFirstDayOrderAmount());
-            result.setFirstDayOrderAmountHour(value2.getFirstDayOrderAmount());
+            result.setOrderAmountTotal(yesterdayDWD.getOrderAmountTotal() + result.getOrderAmountDay());
+            result.setFirstDayOrderAmountTotal(yesterdayDWD.getFirstDayOrderAmountTotal() + result.getFirstDayOrderAmountDay());
             // 下单金额/下单量
             result.setOrderUnitPriceAll(result.getOrderCountTotal() == 0 ? 0 : result.getOrderAmountTotal() / result.getOrderCountTotal());
-            result.setOrderUnitPriceDay(isUnSameDay ? 0: result.getOrderCountDay() == 0 ? 0 : result.getOrderAmountDay() / result.getOrderCountDay());
-            result.setOrderUnitPriceHour(value2.getOrderUnitPrice());
             // 下单金额/广告花费
             result.setOrderRoiAll(result.getCostTotal() == 0 ? 0.0 : result.getOrderAmountTotal() / result.getCostTotal());
-            result.setOrderRoiDay(isUnSameDay ? 0: result.getCostDay() == 0 ? 0.0 : result.getOrderAmountDay() / result.getCostDay());
-            result.setOrderRoiHour(value2.getOrderRoi());
-            result.setSignInCountTotal(value1.getSignInCountTotal() + value2.getSignInCount());
-            result.setSignInCountDay(value1.getSignInCountDay() + value2.getSignInCount());
-            result.setSignInCountHour(value2.getSignInCount());
-            result.setScanFollowCountTotal(value1.getScanFollowCountTotal() + value2.getScanFollowCount());
-            result.setScanFollowCountDay(isUnSameDay ? 0: value1.getScanFollowCountDay() + value2.getScanFollowCount());
-            result.setScanFollowCountHour(value2.getScanFollowCount());
-            result.setWechatAppRegisterUvTotal(value1.getWechatAppRegisterUvTotal() + value2.getWechatAppRegisterUv());
-            result.setWechatAppRegisterUvDay(isUnSameDay ? 0: value1.getWechatAppRegisterUvDay() + value2.getWechatAppRegisterUv());
-            result.setWechatAppRegisterUvHour(value2.getWechatAppRegisterUv());
+            result.setSignInCountTotal(yesterdayDWD.getSignInCountTotal() + result.getSignInCountDay());
+            result.setScanFollowCountTotal(yesterdayDWD.getScanFollowCountTotal() + result.getScanFollowCountDay());
+            result.setWechatAppRegisterUvTotal(yesterdayDWD.getWechatAppRegisterUvTotal() + result.getWechatAppRegisterUvDay());
             // 广告消耗 / 小游戏注册人数
             result.setWechatMinigameRegisterCostAll(result.getWechatAppRegisterUvTotal() == 0 ? 0 : result.getCostTotal() / result.getWechatAppRegisterUvTotal());
-            result.setWechatMinigameRegisterCostDay(isUnSameDay ? 0: result.getWechatAppRegisterUvDay() == 0 ? 0 : result.getCostDay() / result.getWechatAppRegisterUvDay());
-            result.setWechatMinigameRegisterCostHour(value2.getWechatMinigameRegisterCost());
             // 小游戏注册人数 / 广告点击次数
             result.setWechatMinigameRegisterRateAll(result.getValidClickCountTotal() == 0 ? 0.0 : result.getWechatAppRegisterUvTotal() / result.getValidClickCountTotal());
-            result.setWechatMinigameRegisterRateDay(isUnSameDay ? 0: result.getValidClickCountDay() == 0 ? 0.0 : result.getWechatAppRegisterUvDay() / result.getValidClickCountDay());
-            result.setWechatMinigameRegisterRateHour(value2.getWechatMinigameRegisterRate());
             // 总收益 / 总人数
             result.setWechatMinigameArpuAll(result.getWechatAppRegisterUvTotal() == 0 ? 0.0 : result.getOrderAmountTotal() / result.getWechatAppRegisterUvTotal());
-            result.setWechatMinigameArpuDay(isUnSameDay ? 0: result.getWechatAppRegisterUvDay() == 0 ? 0.0 : result.getOrderAmountDay() / result.getWechatAppRegisterUvDay());
-            result.setWechatMinigameArpuHour(value2.getWechatMinigameArpu());
-            result.setWechatMinigameRetentionCountTotal(value1.getWechatMinigameRetentionCountTotal() + value2.getWechatMinigameRetentionCount());
-            result.setWechatMinigameRetentionCountDay(isUnSameDay ? 0: value1.getWechatMinigameRetentionCountDay() + value2.getWechatMinigameRetentionCount());
-            result.setWechatMinigameRetentionCountHour(value2.getWechatMinigameRetentionCount());
-            result.setWechatMinigameCheckoutCountTotal(value1.getWechatMinigameCheckoutCountTotal() + value2.getWechatMinigameCheckoutCount());
-            result.setWechatMinigameCheckoutCountDay(isUnSameDay ? 0: value1.getWechatMinigameCheckoutCountDay() + value2.getWechatMinigameCheckoutCount());
-            result.setWechatMinigameCheckoutCountHour(value2.getWechatMinigameCheckoutCount());
-            result.setWechatMinigameCheckoutAmountTotal(value1.getWechatMinigameCheckoutAmountTotal() + value2.getWechatMinigameCheckoutAmount());
-            result.setWechatMinigameCheckoutAmountDay(isUnSameDay ? 0: value1.getWechatMinigameCheckoutAmountDay() + value2.getWechatMinigameCheckoutAmount());
-            result.setWechatMinigameCheckoutAmountHour(value2.getWechatMinigameCheckoutAmount());
-            result.setOfficialAccountFollowCountTotal(value1.getOfficialAccountFollowCountTotal() + value2.getOfficialAccountFollowCount());
-            result.setOfficialAccountFollowCountDay(isUnSameDay ? 0: value1.getOfficialAccountFollowCountDay() + value2.getOfficialAccountFollowCount());
-            result.setOfficialAccountFollowCountHour(value2.getOfficialAccountFollowCount());
+            result.setWechatMinigameRetentionCountTotal(yesterdayDWD.getWechatMinigameRetentionCountTotal() + result.getWechatMinigameRetentionCountDay());
+            result.setWechatMinigameCheckoutCountTotal(yesterdayDWD.getWechatMinigameCheckoutCountTotal() + result.getWechatMinigameCheckoutCountDay());
+            result.setWechatMinigameCheckoutAmountTotal(yesterdayDWD.getWechatMinigameCheckoutAmountTotal() + result.getWechatMinigameCheckoutAmountDay());
+            result.setOfficialAccountFollowCountTotal(yesterdayDWD.getOfficialAccountFollowCountTotal() + result.getOfficialAccountFollowCountDay());
             // 关注次数 / 点击次数
             result.setOfficialAccountFollowRateAll(result.getValidClickCountTotal() == 0 ? 0.0 : result.getOfficialAccountFollowCountTotal() / result.getValidClickCountTotal());
-            result.setOfficialAccountFollowRateDay(isUnSameDay ? 0: result.getValidClickCountDay() == 0 ? 0.0 : result.getOfficialAccountFollowCountDay() / result.getValidClickCountDay());
-            result.setOfficialAccountFollowRateHour(value2.getOfficialAccountFollowRate());
-            result.setOfficialAccountRegisterUserCountTotal(value1.getOfficialAccountRegisterUserCountTotal() + value2.getOfficialAccountRegisterUserCount());
-            result.setOfficialAccountRegisterUserCountDay(isUnSameDay ? 0: value1.getOfficialAccountRegisterUserCountDay() + value2.getOfficialAccountRegisterUserCount());
-            result.setOfficialAccountRegisterUserCountHour(value2.getOfficialAccountRegisterUserCount());
+            result.setOfficialAccountRegisterUserCountTotal(yesterdayDWD.getOfficialAccountRegisterUserCountTotal() + result.getOfficialAccountRegisterUserCountDay());
             // 公众号内注册人数 / 公众号关注次数
             result.setOfficialAccountRegisterRateAll(result.getOfficialAccountFollowCountTotal() == 0 ? 0.0 : result.getOfficialAccountRegisterUserCountTotal() / result.getOfficialAccountFollowCountTotal());
-            result.setOfficialAccountRegisterRateDay(isUnSameDay ? 0: result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountRegisterUserCountDay() / result.getOfficialAccountFollowCountDay());
-            result.setOfficialAccountRegisterRateHour(value2.getOfficialAccountRegisterRate());
             // 广告消耗 / 广告注册人数
             result.setOfficialAccountRegisterCostAll(result.getOfficialAccountRegisterUserCountTotal() == 0 ? 0 : result.getCostTotal() / result.getOfficialAccountRegisterUserCountTotal());
-            result.setOfficialAccountRegisterCostDay(isUnSameDay ? 0: result.getOfficialAccountRegisterUserCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountRegisterUserCountDay());
-            result.setOfficialAccountRegisterCostHour(value2.getOfficialAccountRegisterCost());
-            result.setOfficialAccountRegisterAmountTotal(value1.getOfficialAccountRegisterAmountTotal() + value2.getOfficialAccountRegisterAmount());
-            result.setOfficialAccountRegisterAmountDay(isUnSameDay ? 0: value1.getOfficialAccountRegisterAmountDay() + value2.getOfficialAccountRegisterAmount());
-            result.setOfficialAccountRegisterAmountHour(value2.getOfficialAccountRegisterAmount());
+            result.setOfficialAccountRegisterAmountTotal(yesterdayDWD.getOfficialAccountRegisterAmountTotal() + result.getOfficialAccountRegisterAmountDay());
             // 注册产生的订单金额累计/广告花费
             result.setOfficialAccountRegisterRoiAll(result.getCostTotal() == 0 ? 0 : result.getOfficialAccountRegisterAmountTotal() / result.getCostTotal());
-            result.setOfficialAccountRegisterRoiDay(isUnSameDay ? 0: result.getCostDay() == 0 ? 0 : result.getOfficialAccountRegisterAmountDay() / result.getCostDay());
-            result.setOfficialAccountRegisterRoiHour(value2.getOfficialAccountRegisterRoi());
-            result.setOfficialAccountApplyCountTotal(value1.getOfficialAccountApplyCountTotal() + value2.getOfficialAccountApplyCount());
-            result.setOfficialAccountApplyCountDay(isUnSameDay ? 0: value1.getOfficialAccountApplyCountDay() + value2.getOfficialAccountApplyCount());
-            result.setOfficialAccountApplyCountHour(value2.getOfficialAccountApplyCount());
-            result.setOfficialAccountApplyUserCountTotal(value1.getOfficialAccountApplyUserCountTotal() + value2.getOfficialAccountApplyUserCount());
-            result.setOfficialAccountApplyUserCountDay(isUnSameDay ? 0: value1.getOfficialAccountApplyUserCountDay() + value2.getOfficialAccountApplyUserCount());
-            result.setOfficialAccountApplyUserCountHour(value2.getOfficialAccountApplyUserCount());
+            result.setOfficialAccountApplyCountTotal(yesterdayDWD.getOfficialAccountApplyCountTotal() + result.getOfficialAccountApplyCountDay());
+            result.setOfficialAccountApplyUserCountTotal(yesterdayDWD.getOfficialAccountApplyUserCountTotal() + result.getOfficialAccountApplyUserCountDay());
             // 公众号内填单的独立用户数/公众号关注次数
             result.setOfficialAccountApplyRateAll(result.getOfficialAccountFollowCountTotal() == 0 ? 0.0 : result.getOfficialAccountApplyUserCountTotal() / result.getOfficialAccountFollowCountTotal());
-            result.setOfficialAccountApplyRateDay(isUnSameDay ? 0: result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountApplyUserCountDay() / result.getOfficialAccountFollowCountDay());
-            result.setOfficialAccountApplyRateHour(value2.getOfficialAccountApplyRate());
             // 广告花费/广告产生的填单行为数量
             result.setOfficialAccountApplyCostAll(result.getOfficialAccountApplyUserCountTotal() == 0 ? 0 : result.getCostTotal() / result.getOfficialAccountApplyUserCountTotal());
-            result.setOfficialAccountApplyCostDay(isUnSameDay ? 0: result.getOfficialAccountApplyUserCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountApplyUserCountDay());
-            result.setOfficialAccountApplyCostHour(value2.getOfficialAccountApplyCost());
-            result.setOfficialAccountApplyAmountTotal(value1.getOfficialAccountApplyAmountTotal() + value2.getOfficialAccountApplyAmount());
-            result.setOfficialAccountApplyAmountDay(isUnSameDay ? 0: value1.getOfficialAccountApplyAmountDay() + value2.getOfficialAccountApplyAmount());
-            result.setOfficialAccountApplyAmountHour(value2.getOfficialAccountApplyAmount());
+            result.setOfficialAccountApplyAmountTotal(yesterdayDWD.getOfficialAccountApplyAmountTotal() + result.getOfficialAccountApplyAmountDay());
             // 填单产生的订单金额累计/广告花费
             result.setOfficialAccountApplyRoiAll(result.getCostTotal() == 0 ? 0 : result.getOfficialAccountApplyAmountTotal() / result.getCostTotal());
-            result.setOfficialAccountApplyRoiDay(isUnSameDay ? 0: result.getCostDay() == 0 ? 0 : result.getOfficialAccountApplyAmountDay() / result.getCostDay());
-            result.setOfficialAccountApplyRoiHour(value2.getOfficialAccountApplyRoi());
-            result.setOfficialAccountOrderCountTotal(value1.getOfficialAccountOrderCountTotal() + value2.getOfficialAccountOrderCount());
-            result.setOfficialAccountOrderCountDay(isUnSameDay ? 0: value1.getOfficialAccountOrderCountDay() + value2.getOfficialAccountOrderCount());
-            result.setOfficialAccountOrderCountHour(value2.getOfficialAccountOrderCount());
-            result.setOfficialAccountFirstDayOrderCountTotal(value1.getOfficialAccountFirstDayOrderCountTotal() + value2.getOfficialAccountFirstDayOrderCount());
-            result.setOfficialAccountFirstDayOrderCountDay(isUnSameDay ? 0: value1.getOfficialAccountFirstDayOrderCountDay() + value2.getOfficialAccountFirstDayOrderCount());
-            result.setOfficialAccountFirstDayOrderCountHour(value2.getOfficialAccountFirstDayOrderCount());
-            result.setOfficialAccountOrderUserCountTotal(value1.getOfficialAccountOrderUserCountTotal() + value2.getOfficialAccountOrderUserCount());
-            result.setOfficialAccountOrderUserCountDay(isUnSameDay ? 0: value1.getOfficialAccountOrderUserCountDay() + value2.getOfficialAccountOrderUserCount());
-            result.setOfficialAccountOrderUserCountHour(value2.getOfficialAccountOrderUserCount());
+            result.setOfficialAccountOrderCountTotal(yesterdayDWD.getOfficialAccountOrderCountTotal() + result.getOfficialAccountOrderCountDay());
+            result.setOfficialAccountFirstDayOrderCountTotal(yesterdayDWD.getOfficialAccountFirstDayOrderCountTotal() + result.getOfficialAccountFirstDayOrderCountDay());
+            result.setOfficialAccountOrderUserCountTotal(yesterdayDWD.getOfficialAccountOrderUserCountTotal() + result.getOfficialAccountOrderUserCountDay());
             // 公众号内下单独立用户数(UV)/公众号关注次数
             result.setOfficialAccountOrderRateAll(result.getOfficialAccountFollowCountTotal() == 0 ? 0.0 : result.getOfficialAccountOrderUserCountTotal() / result.getOfficialAccountFollowCountTotal());
-            result.setOfficialAccountOrderRateDay(isUnSameDay ? 0: result.getOfficialAccountFollowCountDay() == 0 ? 0.0 : result.getOfficialAccountOrderUserCountDay() / result.getOfficialAccountFollowCountDay());
-            result.setOfficialAccountOrderRateHour(value2.getOfficialAccountOrderRate());
             // 广告花费/广告产生的下单行为数量
             result.setOfficialAccountOrderCostAll(result.getOfficialAccountOrderCountTotal() == 0 ? 0 : result.getCostTotal() / result.getOfficialAccountOrderCountTotal());
-            result.setOfficialAccountOrderCostDay(isUnSameDay ? 0: result.getOfficialAccountOrderCountDay() == 0 ? 0 : result.getCostDay() / result.getOfficialAccountOrderCountDay());
-            result.setOfficialAccountOrderCostHour(value2.getOfficialAccountOrderCost());
-            result.setOfficialAccountOrderAmountTotal(value1.getOfficialAccountOrderAmountTotal() + value2.getOfficialAccountOrderAmount());
-            result.setOfficialAccountOrderAmountDay(isUnSameDay ? 0: value1.getOfficialAccountOrderAmountDay() + value2.getOfficialAccountOrderAmount());
-            result.setOfficialAccountOrderAmountHour(value2.getOfficialAccountOrderAmount());
-            result.setOfficialAccountFirstDayOrderAmountTotal(value1.getOfficialAccountFirstDayOrderAmountTotal() + value2.getOfficialAccountFirstDayOrderAmount());
-            result.setOfficialAccountFirstDayOrderAmountDay(isUnSameDay ? 0: value1.getOfficialAccountFirstDayOrderAmountDay() + value2.getOfficialAccountFirstDayOrderAmount());
-            result.setOfficialAccountFirstDayOrderAmountHour(value2.getOfficialAccountFirstDayOrderAmount());
+            result.setOfficialAccountOrderAmountTotal(yesterdayDWD.getOfficialAccountOrderAmountTotal() + result.getOfficialAccountOrderAmountDay());
+            result.setOfficialAccountFirstDayOrderAmountTotal(yesterdayDWD.getOfficialAccountFirstDayOrderAmountTotal() + result.getOfficialAccountFirstDayOrderAmountDay());
             // 下单产生的订单金额累计/广告花费
             result.setOfficialAccountOrderRoiAll(result.getCostTotal() == 0 ? 0 : result.getOfficialAccountOrderAmountTotal() / result.getCostTotal());
-            result.setOfficialAccountOrderRoiDay(isUnSameDay ? 0: result.getCostDay() == 0 ? 0 : result.getOfficialAccountOrderAmountDay() / result.getCostDay());
-            result.setOfficialAccountOrderRoiHour(value2.getOfficialAccountOrderRoi());
-            result.setOfficialAccountConsultCountTotal(value1.getOfficialAccountConsultCountTotal() + value2.getOfficialAccountConsultCount());
-            result.setOfficialAccountConsultCountDay(isUnSameDay ? 0: value1.getOfficialAccountConsultCountDay() + value2.getOfficialAccountConsultCount());
-            result.setOfficialAccountConsultCountHour(value2.getOfficialAccountConsultCount());
-            result.setOfficialAccountReaderCountTotal(value1.getOfficialAccountReaderCountTotal() + value2.getOfficialAccountReaderCount());
-            result.setOfficialAccountReaderCountDay(isUnSameDay ? 0: value1.getOfficialAccountReaderCountDay() + value2.getOfficialAccountReaderCount());
-            result.setOfficialAccountReaderCountHour(value2.getOfficialAccountReaderCount());
-            result.setOfficialAccountCreditApplyUserCountTotal(value1.getOfficialAccountCreditApplyUserCountTotal() + value2.getOfficialAccountCreditApplyUserCount());
-            result.setOfficialAccountCreditApplyUserCountDay(isUnSameDay ? 0: value1.getOfficialAccountCreditApplyUserCountDay() + value2.getOfficialAccountCreditApplyUserCount());
-            result.setOfficialAccountCreditApplyUserCountHour(value2.getOfficialAccountCreditApplyUserCount());
-            result.setOfficialAccountCreditUserCountTotal(value1.getOfficialAccountCreditUserCountTotal() + value2.getOfficialAccountCreditUserCount());
-            result.setOfficialAccountCreditUserCountDay(isUnSameDay ? 0: value1.getOfficialAccountCreditUserCountDay() + value2.getOfficialAccountCreditUserCount());
-            result.setOfficialAccountCreditUserCountHour(value2.getOfficialAccountCreditUserCount());
-            result.setForwardCountTotal(value1.getForwardCountTotal() + value2.getForwardCount());
-            result.setForwardCountDay(isUnSameDay ? 0: value1.getForwardCountDay() + value2.getForwardCount());
-            result.setForwardCountHour(value2.getForwardCount());
-            result.setForwardUserCountTotal(value1.getForwardUserCountTotal() + value2.getForwardUserCount());
-            result.setForwardUserCountDay(isUnSameDay ? 0: value1.getForwardUserCountDay() + value2.getForwardUserCount());
-            result.setForwardUserCountHour(value2.getForwardUserCount());
-            result.setNoInterestCountTotal(value1.getNoInterestCountTotal() + value2.getNoInterestCount());
-            result.setNoInterestCountDay(isUnSameDay ? 0: value1.getNoInterestCountDay() + value2.getNoInterestCount());
-            result.setNoInterestCountHour(value2.getNoInterestCount());
+            result.setOfficialAccountConsultCountTotal(yesterdayDWD.getOfficialAccountConsultCountTotal() + result.getOfficialAccountConsultCountDay());
+            result.setOfficialAccountReaderCountTotal(yesterdayDWD.getOfficialAccountReaderCountTotal() + result.getOfficialAccountReaderCountDay());
+            result.setOfficialAccountCreditApplyUserCountTotal(yesterdayDWD.getOfficialAccountCreditApplyUserCountTotal() + result.getOfficialAccountCreditApplyUserCountDay());
+            result.setOfficialAccountCreditUserCountTotal(yesterdayDWD.getOfficialAccountCreditUserCountTotal() + result.getOfficialAccountCreditUserCountDay());
+            result.setForwardCountTotal(yesterdayDWD.getForwardCountTotal() + result.getForwardCountDay());
+            result.setForwardUserCountTotal(yesterdayDWD.getForwardUserCountTotal() + result.getForwardUserCountDay());
+            result.setNoInterestCountTotal(yesterdayDWD.getNoInterestCountTotal() + result.getNoInterestCountDay());
         }
+        result.setAdGroupMapStr(PlanUtil.adGroupMapStr(adGroupMap));
+        result.setAdIdsStr(PlanUtil.adIdsStr(value2.getAdId()));
         return result;
     }
 

+ 46 - 38
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/AdDayDWDRollMonthProcess.java

@@ -1,14 +1,9 @@
 package flink.zanxiangnet.ad.monitoring.process;
 
-import com.aliyun.odps.Instance;
-import com.aliyun.odps.Odps;
-import com.aliyun.odps.account.Account;
-import com.aliyun.odps.account.AliyunAccount;
-import com.aliyun.odps.data.Record;
-import com.aliyun.odps.task.SQLTask;
-import flink.zanxiangnet.ad.monitoring.maxcompute.MaxComputeLog;
+import flink.zanxiangnet.ad.monitoring.config.ClickhouseDataSourceFactory;
+import flink.zanxiangnet.ad.monitoring.dao.mapper.AdStatOfDayDWDMapper;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.AdDataOfDayODS;
-import flink.zanxiangnet.ad.monitoring.pojo.entity.PlanStatOfDayDWD;
+import flink.zanxiangnet.ad.monitoring.pojo.entity.AdStatOfDayDWD;
 import flink.zanxiangnet.ad.monitoring.pojo.properties.ApplicationProperties;
 import flink.zanxiangnet.ad.monitoring.util.DateUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -20,69 +15,82 @@ import org.apache.flink.configuration.Configuration;
 import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
 import org.apache.flink.streaming.api.windowing.windows.GlobalWindow;
 import org.apache.flink.util.Collector;
+import org.apache.ibatis.datasource.DataSourceFactory;
+import org.apache.ibatis.mapping.Environment;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
 
 import java.time.LocalDate;
-import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.stream.Collectors;
 
 @Slf4j
-public class AdDayDWDRollMonthProcess extends ProcessWindowFunction<AdDataOfDayODS, PlanStatOfDayDWD, Long, GlobalWindow> {
-    private Odps odps;
+public class AdDayDWDRollMonthProcess extends ProcessWindowFunction<AdDataOfDayODS, AdStatOfDayDWD, Long, GlobalWindow> {
+    private SqlSessionFactory sqlSessionFactory;
     // 上次查询的时间
     private ValueState<String> lastQueryDayState;
     // 之前聚合的昨天的数据
-    private MapState<String, PlanStatOfDayDWD> historyReduceState;
+    private MapState<String, AdStatOfDayDWD> historyReduceState;
 
     @Override
-    public void open(Configuration conf) throws Exception {
+    public void open(Configuration conf) {
         Map<String, String> params = getRuntimeContext()
                 .getExecutionConfig()
                 .getGlobalJobParameters()
                 .toMap();
-        Account account = new AliyunAccount(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ID),
-                params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_KEY));
-        odps = new Odps(account);
-        odps.getRestClient().setRetryLogger(new MaxComputeLog());
-        odps.setEndpoint(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ENDPOINT));
-        odps.setDefaultProject(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_PROJECT_NAME));
+
+        Properties ckProps = new Properties();
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_URL, params.get(ApplicationProperties.CK_URL));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_USER, params.get(ApplicationProperties.CK_USERNAME));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_PASSWORD, params.get(ApplicationProperties.CK_PASSWORD));
+
+        DataSourceFactory dataSourceFactory = new ClickhouseDataSourceFactory();
+        dataSourceFactory.setProperties(ckProps);
+        Environment environment = new Environment("clickhouse", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
+        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(environment);
+        // 开启驼峰规则
+        configuration.setMapUnderscoreToCamelCase(true);
+        configuration.getTypeAliasRegistry().registerAlias(AdStatOfDayDWD.class);
+        // addMapper一定要放到 alias的后面!!!!!
+        configuration.addMapper(AdStatOfDayDWDMapper.class);
+        sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
 
         lastQueryDayState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastQueryDayState", String.class));
-        historyReduceState = getRuntimeContext().getMapState(new MapStateDescriptor<>("historyReduceState", String.class, PlanStatOfDayDWD.class));
+        historyReduceState = getRuntimeContext().getMapState(new MapStateDescriptor<>("historyReduceState", String.class, AdStatOfDayDWD.class));
     }
 
     @Override
-    public void process(Long elementsCount, ProcessWindowFunction<AdDataOfDayODS, PlanStatOfDayDWD, Long, GlobalWindow>.Context context,
-                        Iterable<AdDataOfDayODS> iterable, Collector<PlanStatOfDayDWD> collector) throws Exception {
+    public void process(Long elementsCount, ProcessWindowFunction<AdDataOfDayODS, AdStatOfDayDWD, Long, GlobalWindow>.Context context,
+                        Iterable<AdDataOfDayODS> iterable, Collector<AdStatOfDayDWD> collector) throws Exception {
         AdDataOfDayODS element = iterable.iterator().next();
         LocalDate statDay = DateUtil.parseLocalDate(element.getStatDay());
-        long now = System.currentTimeMillis();
+        long now = context.currentProcessingTime();
+        long adId = element.getAdId();
 
         String lastQueryDay = lastQueryDayState.value();
         // 从 maxCompute查找广告的历史数据
         if (lastQueryDay == null || !lastQueryDay.equals(DateUtil.formatLocalDate(LocalDate.now()))) {
-            LocalDate endTime = LocalDate.now(), beginTime = statDay.minusDays(60);
-            String sql = "SELECT * FROM plan_stat_of_day_dwd WHERE stat_day >= \"" + DateUtil.formatLocalDate(beginTime) + "\" AND stat_day <= \"" + DateUtil.formatLocalDate(endTime) + "\" AND campaign_id = " + element.getCampaignId() + ";";
-            Instance instance = SQLTask.run(odps, sql);
-            // log.error("sql: " + sql + ", odps日志: " + odps.logview().generateLogView(instance, 7 * 24));
-            instance.waitForSuccess();
-            List<Record> records = SQLTask.getResult(instance);
-            Map<String, PlanStatOfDayDWD> historyData = records.stream()
-                    .map(PlanStatOfDayDWD::byMaxCompute)
-                    .sorted((o1, o2) -> new Long(o1.getCreateTime().getTime() - o2.getCreateTime().getTime()).intValue())
-                    .collect(Collectors.toMap(PlanStatOfDayDWD::getStatDay, data -> data, (val1, val2) -> val2));
-            historyReduceState.clear();
-            historyReduceState.putAll(historyData);
-            lastQueryDayState.update(DateUtil.formatLocalDate(LocalDate.now()));
+            try (SqlSession session = sqlSessionFactory.openSession()) {
+                AdStatOfDayDWDMapper mapper = session.getMapper(AdStatOfDayDWDMapper.class);
+                Map<String, AdStatOfDayDWD> historyData = mapper.lastReduceResult(adId, null, DateUtil.formatLocalDate(LocalDate.now().minusDays(1L)), 60).stream()
+                        .sorted((o1, o2) -> new Long(o1.getCreateTime().getTime() - o2.getCreateTime().getTime()).intValue())
+                        .collect(Collectors.toMap(AdStatOfDayDWD::getStatDay, data -> data, (val1, val2) -> val2));
+                historyReduceState.clear();
+                historyReduceState.putAll(historyData);
+                lastQueryDayState.update(DateUtil.formatLocalDate(LocalDate.now()));
+            }
         }
-        PlanStatOfDayDWD lastReduceData = null;
+        AdStatOfDayDWD lastReduceData = null;
         for (int i = 1; i <= 60; i++) {
             lastReduceData = historyReduceState.get(DateUtil.formatLocalDate(statDay.minusDays(i)));
             if (lastReduceData != null) {
                 break;
             }
         }
-        PlanStatOfDayDWD newStatData = PlanStatOfDayDWD.reduce(lastReduceData, element, now);
+        AdStatOfDayDWD newStatData = AdStatOfDayDWD.reduce(lastReduceData, element, now);
         historyReduceState.put(DateUtil.formatLocalDate(statDay), newStatData);
         collector.collect(newStatData);
     }

+ 8 - 9
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/AdDayDWDRollYearProcess.java

@@ -1,7 +1,7 @@
 package flink.zanxiangnet.ad.monitoring.process;
 
 import flink.zanxiangnet.ad.monitoring.pojo.entity.AdDataOfDayODS;
-import flink.zanxiangnet.ad.monitoring.pojo.entity.PlanStatOfDayDWD;
+import flink.zanxiangnet.ad.monitoring.pojo.entity.AdStatOfDayDWD;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.flink.api.common.state.ValueState;
 import org.apache.flink.api.common.state.ValueStateDescriptor;
@@ -11,21 +11,20 @@ import org.apache.flink.streaming.api.windowing.windows.GlobalWindow;
 import org.apache.flink.util.Collector;
 
 @Slf4j
-public class AdDayDWDRollYearProcess extends ProcessWindowFunction<AdDataOfDayODS, PlanStatOfDayDWD, Long, GlobalWindow> {
-    
+public class AdDayDWDRollYearProcess extends ProcessWindowFunction<AdDataOfDayODS, AdStatOfDayDWD, Long, GlobalWindow> {
     // 上次聚合的结果
-    private ValueState<PlanStatOfDayDWD> lastReduceState;
+    private ValueState<AdStatOfDayDWD> lastReduceState;
 
     public void open(Configuration conf) {
-        lastReduceState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastReduceState", PlanStatOfDayDWD.class));
+        lastReduceState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastReduceState", AdStatOfDayDWD.class));
     }
 
     @Override
-    public void process(Long elementsCount, ProcessWindowFunction<AdDataOfDayODS, PlanStatOfDayDWD, Long, GlobalWindow>.Context context,
-                        Iterable<AdDataOfDayODS> elements, Collector<PlanStatOfDayDWD> out) throws Exception {
+    public void process(Long elementsCount, ProcessWindowFunction<AdDataOfDayODS, AdStatOfDayDWD, Long, GlobalWindow>.Context context,
+                        Iterable<AdDataOfDayODS> elements, Collector<AdStatOfDayDWD> out) throws Exception {
         AdDataOfDayODS element = elements.iterator().next();
-        PlanStatOfDayDWD newStatDWD = PlanStatOfDayDWD.reduce(lastReduceState.value(), element, System.currentTimeMillis());
-        out.collect(newStatDWD);
+        AdStatOfDayDWD newStatDWD = AdStatOfDayDWD.reduce(lastReduceState.value(), element, System.currentTimeMillis());
         lastReduceState.update(newStatDWD);
+        out.collect(newStatDWD);
     }
 }

+ 53 - 38
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/AdHourDWDProcess.java

@@ -1,13 +1,9 @@
 package flink.zanxiangnet.ad.monitoring.process;
 
-import com.aliyun.odps.Instance;
-import com.aliyun.odps.Odps;
-import com.aliyun.odps.account.Account;
-import com.aliyun.odps.account.AliyunAccount;
-import com.aliyun.odps.data.Record;
-import com.aliyun.odps.task.SQLTask;
-import flink.zanxiangnet.ad.monitoring.maxcompute.MaxComputeLog;
+import flink.zanxiangnet.ad.monitoring.config.ClickhouseDataSourceFactory;
+import flink.zanxiangnet.ad.monitoring.dao.mapper.AdStatOfDayDWDMapper;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.AdDataOfHourODS;
+import flink.zanxiangnet.ad.monitoring.pojo.entity.AdStatOfDayDWD;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.AdStatOfHourDWD;
 import flink.zanxiangnet.ad.monitoring.pojo.properties.ApplicationProperties;
 import flink.zanxiangnet.ad.monitoring.util.DateUtil;
@@ -21,21 +17,32 @@ import org.apache.flink.configuration.Configuration;
 import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
 import org.apache.flink.streaming.api.windowing.windows.GlobalWindow;
 import org.apache.flink.util.Collector;
+import org.apache.ibatis.datasource.DataSourceFactory;
+import org.apache.ibatis.mapping.Environment;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
-import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.stream.Collectors;
 
+/**
+ * 往前回滚 10天的小时数据(警告,此数据依赖小时数据必定在天数据之后拉取来实现的。不然会拉下昨天的数据没有统计进来)
+ */
 @Slf4j
 public class AdHourDWDProcess extends ProcessWindowFunction<AdDataOfHourODS, AdStatOfHourDWD, Long, GlobalWindow> {
-    private Odps odps;
+    private SqlSessionFactory sqlSessionFactory;
     // 上次查询的天数据
     private ValueState<String> lastQueryDayState;
     // 聚合的天的数据
-    private MapState<String, AdStatOfHourDWD> historyReduceState;
+    private MapState<String, AdStatOfDayDWD> historyReduceState;
+    // 上小时聚合的结果
+    private MapState<String, AdStatOfHourDWD> lastReduceState;
 
     @Override
     public void open(Configuration conf) {
@@ -43,15 +50,26 @@ public class AdHourDWDProcess extends ProcessWindowFunction<AdDataOfHourODS, AdS
                 .getExecutionConfig()
                 .getGlobalJobParameters()
                 .toMap();
-        Account account = new AliyunAccount(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ID),
-                params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_KEY));
-        odps = new Odps(account);
-        odps.getRestClient().setRetryLogger(new MaxComputeLog());
-        odps.setEndpoint(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ENDPOINT));
-        odps.setDefaultProject(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_PROJECT_NAME));
+
+        Properties ckProps = new Properties();
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_URL, params.get(ApplicationProperties.CK_URL));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_USER, params.get(ApplicationProperties.CK_USERNAME));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_PASSWORD, params.get(ApplicationProperties.CK_PASSWORD));
+
+        DataSourceFactory dataSourceFactory = new ClickhouseDataSourceFactory();
+        dataSourceFactory.setProperties(ckProps);
+        Environment environment = new Environment("clickhouse", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
+        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(environment);
+        // 开启驼峰规则
+        configuration.setMapUnderscoreToCamelCase(true);
+        configuration.getTypeAliasRegistry().registerAlias(AdStatOfDayDWD.class);
+        // addMapper一定要放到 alias的后面!!!!!
+        configuration.addMapper(AdStatOfDayDWDMapper.class);
+        sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
 
         lastQueryDayState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastQueryDayState", String.class));
-        historyReduceState = getRuntimeContext().getMapState(new MapStateDescriptor<>("historyReduceState", Types.STRING, Types.POJO(AdStatOfHourDWD.class)));
+        historyReduceState = getRuntimeContext().getMapState(new MapStateDescriptor<>("historyReduceState", Types.STRING, Types.POJO(AdStatOfDayDWD.class)));
+        lastReduceState = getRuntimeContext().getMapState(new MapStateDescriptor<>("lastReduceState", Types.STRING, Types.POJO(AdStatOfHourDWD.class)));
     }
 
     @Override
@@ -59,38 +77,35 @@ public class AdHourDWDProcess extends ProcessWindowFunction<AdDataOfHourODS, AdS
                         Iterable<AdDataOfHourODS> iterable, Collector<AdStatOfHourDWD> collector) throws Exception {
         AdDataOfHourODS element = iterable.iterator().next();
         LocalDate statDay = DateUtil.parseLocalDate(element.getStatDay());
-        LocalDateTime statTime = LocalDateTime.of(statDay, LocalTime.of(element.getHour(), 0, 0));
         long now = context.currentProcessingTime();
         LocalDate today = LocalDate.now();
+        long adId = element.getAdId();
 
         String lastQueryDay = lastQueryDayState.value();
         // 从 maxCompute拉取指定 广告的历史数据
         if (lastQueryDay == null || !lastQueryDay.equals(DateUtil.formatLocalDate(today))) {
-            LocalDate endDay = today, beginDay = statDay.minusDays(60);
-            String sql = "SELECT * FROM ad_stat_of_hour_dwd WHERE stat_day >= \"" + DateUtil.formatLocalDate(beginDay) + "\" AND stat_day <= \"" + DateUtil.formatLocalDate(endDay) + "\" AND ad_id = " + element.getAdId() + ";";
-            Instance instance = SQLTask.run(odps, sql);
-            // log.error("sql: " + sql + ", odps日志: " + odps.logview().generateLogView(instance, 7 * 24));
-            instance.waitForSuccess();
-            List<Record> records = SQLTask.getResult(instance);
-            Map<String, AdStatOfHourDWD> historyHourMap = records.stream()
-                    .map(AdStatOfHourDWD::byMaxCompute)
-                    .sorted((o1, o2) -> new Long(o1.getCreateTime().getTime() - o2.getCreateTime().getTime()).intValue())
-                    .collect(Collectors.toMap(data -> data.getStatDay() + data.getHour(), data -> data, (val1, val2) -> val2));
-            historyReduceState.clear();
-            historyReduceState.putAll(historyHourMap);
-            lastQueryDayState.update(DateUtil.formatLocalDate(today));
+            try (SqlSession session = sqlSessionFactory.openSession()) {
+                AdStatOfDayDWDMapper mapper = session.getMapper(AdStatOfDayDWDMapper.class);
+                Map<String, AdStatOfDayDWD> historyData = mapper.lastReduceResult(adId, null,  DateUtil.formatLocalDate(LocalDate.now().minusDays(1L)), 60).stream()
+                        .collect(Collectors.toMap(AdStatOfDayDWD::getStatDay, data -> data, (val1, val2) -> val2));
+                historyReduceState.clear();
+                historyReduceState.putAll(historyData);
+                lastQueryDayState.update(DateUtil.formatLocalDate(today));
+            }
         }
-        AdStatOfHourDWD lastReduceData = null;
-        for (int i = 1; i < 60 * 24; i++) {
-            LocalDateTime time = statTime.minusHours(i);
-            lastReduceData = historyReduceState.get(DateUtil.formatLocalDate(time.toLocalDate()) + time.getHour());
-            if (lastReduceData != null) {
+        AdStatOfDayDWD yesterdayReduceData = null;
+        for (int i = 1; i < 60; i++) {
+            LocalDate day = statDay.minusDays(i);
+            yesterdayReduceData = historyReduceState.get(DateUtil.formatLocalDate(day));
+            if (yesterdayReduceData != null) {
                 break;
             }
         }
 
-        AdStatOfHourDWD newStatData = AdStatOfHourDWD.reduce(lastReduceData, element, now);
-        historyReduceState.put(newStatData.getStatDay(), newStatData);
+        AdStatOfHourDWD lastReduce = lastReduceState.get(element.getStatDay());
+
+        AdStatOfHourDWD newStatData = AdStatOfHourDWD.reduce(yesterdayReduceData, lastReduce, element, now);
+        lastReduceState.put(newStatData.getStatDay(), newStatData);
         collector.collect(newStatData);
     }
 }

+ 32 - 35
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/AdMinuteDWDProcess.java

@@ -1,16 +1,10 @@
 package flink.zanxiangnet.ad.monitoring.process;
 
-import com.aliyun.odps.Instance;
-import com.aliyun.odps.Odps;
-import com.aliyun.odps.account.Account;
-import com.aliyun.odps.account.AliyunAccount;
-import com.aliyun.odps.data.Record;
-import com.aliyun.odps.task.SQLTask;
-import flink.zanxiangnet.ad.monitoring.maxcompute.MaxComputeLog;
+import flink.zanxiangnet.ad.monitoring.config.ClickhouseDataSourceFactory;
+import flink.zanxiangnet.ad.monitoring.dao.mapper.AdStatOfDayDWDMapper;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.*;
 import flink.zanxiangnet.ad.monitoring.pojo.properties.ApplicationProperties;
 import flink.zanxiangnet.ad.monitoring.util.DateUtil;
-import flink.zanxiangnet.ad.monitoring.util.JsonUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.flink.api.common.state.MapState;
 import org.apache.flink.api.common.state.MapStateDescriptor;
@@ -21,15 +15,17 @@ import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
 import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
 import org.apache.flink.util.Collector;
 import org.apache.flink.util.OutputTag;
+import org.apache.ibatis.datasource.DataSourceFactory;
+import org.apache.ibatis.mapping.Environment;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
+import java.util.*;
 
 @Slf4j
 public class AdMinuteDWDProcess extends ProcessWindowFunction<AdDataOfMinuteODS, AdStatOfMinuteDWD, Long, TimeWindow> {
@@ -37,7 +33,7 @@ public class AdMinuteDWDProcess extends ProcessWindowFunction<AdDataOfMinuteODS,
 
     private final OutputTag<AdStatOfHourDWD> adHourFromMinuteStreamTag;
 
-    private Odps odps;
+    private SqlSessionFactory sqlSessionFactory;
     // 历史的天数据
     private ValueState<AdStatOfDayDWD> historyDayState;
     // 上次查询的天数据
@@ -57,12 +53,22 @@ public class AdMinuteDWDProcess extends ProcessWindowFunction<AdDataOfMinuteODS,
                 .getExecutionConfig()
                 .getGlobalJobParameters()
                 .toMap();
-        Account account = new AliyunAccount(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ID),
-                params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_KEY));
-        odps = new Odps(account);
-        odps.getRestClient().setRetryLogger(new MaxComputeLog());
-        odps.setEndpoint(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ENDPOINT));
-        odps.setDefaultProject(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_PROJECT_NAME));
+
+        Properties ckProps = new Properties();
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_URL, params.get(ApplicationProperties.CK_URL));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_USER, params.get(ApplicationProperties.CK_USERNAME));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_PASSWORD, params.get(ApplicationProperties.CK_PASSWORD));
+
+        DataSourceFactory dataSourceFactory = new ClickhouseDataSourceFactory();
+        dataSourceFactory.setProperties(ckProps);
+        Environment environment = new Environment("clickhouse", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
+        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(environment);
+        // 开启驼峰规则
+        configuration.setMapUnderscoreToCamelCase(true);
+        configuration.getTypeAliasRegistry().registerAlias(AdStatOfDayDWD.class);
+        // addMapper一定要放到 alias的后面!!!!!
+        configuration.addMapper(AdStatOfDayDWDMapper.class);
+        sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
 
         historyDayState = getRuntimeContext().getState(new ValueStateDescriptor<>("historyDayState", AdStatOfDayDWD.class));
         lastQueryDayState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastQueryDayState", String.class));
@@ -99,23 +105,14 @@ public class AdMinuteDWDProcess extends ProcessWindowFunction<AdDataOfMinuteODS,
         // 之前的数据
         String lastQueryDay = lastQueryDayState.value();
         if (lastQueryDay == null || !lastQueryDay.equals(statDay)) {
-            // 往前找 30天
-            LocalDate endDay = beginDate.minusDays(2L), beginDay = endDay.minusDays(30L);
-            String sql = "SELECT * FROM ad_stat_of_day_dwd WHERE stat_day >= \"" + DateUtil.formatLocalDate(beginDay) + "\" AND stat_day <= \"" + endDay + "\" AND ad_id = " + adId + ";";
-            Instance instance = SQLTask.run(odps, sql);
-            // log.error("sql: " + sql + ", odps日志: " + odps.logview().generateLogView(instance, 7 * 24));
-            instance.waitForSuccess();
-            List<Record> records = SQLTask.getResult(instance);
-            List<AdStatOfDayDWD> historyDayData = records.stream().map(AdStatOfDayDWD::byMaxCompute).sorted((val1, val2) -> {
-                if (val1.getStatDay().equals(val2.getStatDay())) {
-                    return new Long(val1.getCreateTime().getTime() - val2.getCreateTime().getTime()).intValue();
+            try (SqlSession session = sqlSessionFactory.openSession()) {
+                AdStatOfDayDWDMapper mapper = session.getMapper(AdStatOfDayDWDMapper.class);
+                List<AdStatOfDayDWD> historyDayData = mapper.lastReduceResult(adId, null, DateUtil.formatLocalDate(beginDate.minusDays(2L)), 1);
+                if (!historyDayData.isEmpty()) {
+                    historyDayState.update(historyDayData.get(historyDayData.size() - 1));
                 }
-                return DateUtil.parseLocalDate(val1.getStatDay()).compareTo(DateUtil.parseLocalDate(val2.getStatDay()));
-            }).collect(Collectors.toList());
-            if (!historyDayData.isEmpty()) {
-                historyDayState.update(historyDayData.get(historyDayData.size() - 1));
+                lastQueryDayState.update(statDay);
             }
-            lastQueryDayState.update(statDay);
         }
         AdStatOfDayDWD beforeYesterdayDayDWD = historyDayState.value();
 

+ 97 - 0
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/PlanDayDWDRollMonthProcess.java

@@ -0,0 +1,97 @@
+package flink.zanxiangnet.ad.monitoring.process;
+
+import flink.zanxiangnet.ad.monitoring.config.ClickhouseDataSourceFactory;
+import flink.zanxiangnet.ad.monitoring.dao.mapper.PlanStatOfDayDWDMapper;
+import flink.zanxiangnet.ad.monitoring.pojo.entity.AdDataOfDayODS;
+import flink.zanxiangnet.ad.monitoring.pojo.entity.PlanStatOfDayDWD;
+import flink.zanxiangnet.ad.monitoring.pojo.properties.ApplicationProperties;
+import flink.zanxiangnet.ad.monitoring.util.DateUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.flink.api.common.state.MapState;
+import org.apache.flink.api.common.state.MapStateDescriptor;
+import org.apache.flink.api.common.state.ValueState;
+import org.apache.flink.api.common.state.ValueStateDescriptor;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
+import org.apache.flink.streaming.api.windowing.windows.GlobalWindow;
+import org.apache.flink.util.Collector;
+import org.apache.ibatis.datasource.DataSourceFactory;
+import org.apache.ibatis.mapping.Environment;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
+
+import java.time.LocalDate;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+@Slf4j
+public class PlanDayDWDRollMonthProcess extends ProcessWindowFunction<AdDataOfDayODS, PlanStatOfDayDWD, Long, GlobalWindow> {
+    private SqlSessionFactory sqlSessionFactory;
+    // 上次查询的时间
+    private ValueState<String> lastQueryDayState;
+    // 之前聚合的昨天的数据
+    private MapState<String, PlanStatOfDayDWD> historyReduceState;
+
+    @Override
+    public void open(Configuration conf) throws Exception {
+        Map<String, String> params = getRuntimeContext()
+                .getExecutionConfig()
+                .getGlobalJobParameters()
+                .toMap();
+
+        Properties ckProps = new Properties();
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_URL, params.get(ApplicationProperties.CK_URL));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_USER, params.get(ApplicationProperties.CK_USERNAME));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_PASSWORD, params.get(ApplicationProperties.CK_PASSWORD));
+
+        DataSourceFactory dataSourceFactory = new ClickhouseDataSourceFactory();
+        dataSourceFactory.setProperties(ckProps);
+        Environment environment = new Environment("clickhouse", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
+        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(environment);
+        // 开启驼峰规则
+        configuration.setMapUnderscoreToCamelCase(true);
+        configuration.getTypeAliasRegistry().registerAlias(PlanStatOfDayDWD.class);
+        // addMapper一定要放到 alias的后面!!!!!
+        configuration.addMapper(PlanStatOfDayDWDMapper.class);
+        sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
+
+        lastQueryDayState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastQueryDayState", String.class));
+        historyReduceState = getRuntimeContext().getMapState(new MapStateDescriptor<>("historyReduceState", String.class, PlanStatOfDayDWD.class));
+    }
+
+    @Override
+    public void process(Long elementsCount, ProcessWindowFunction<AdDataOfDayODS, PlanStatOfDayDWD, Long, GlobalWindow>.Context context,
+                        Iterable<AdDataOfDayODS> iterable, Collector<PlanStatOfDayDWD> collector) throws Exception {
+        AdDataOfDayODS element = iterable.iterator().next();
+        LocalDate statDay = DateUtil.parseLocalDate(element.getStatDay());
+        long now = System.currentTimeMillis();
+        long adId = element.getAdId();
+
+        String lastQueryDay = lastQueryDayState.value();
+        // 从 maxCompute查找广告的历史数据
+        if (lastQueryDay == null || !lastQueryDay.equals(DateUtil.formatLocalDate(LocalDate.now()))) {
+            try (SqlSession session = sqlSessionFactory.openSession()) {
+                PlanStatOfDayDWDMapper mapper = session.getMapper(PlanStatOfDayDWDMapper.class);
+                Map<String, PlanStatOfDayDWD> historyData = mapper.lastReduceResult(adId, null, DateUtil.formatLocalDate(LocalDate.now().minusDays(1L)), 60)
+                        .stream()
+                        .collect(Collectors.toMap(PlanStatOfDayDWD::getStatDay, data -> data, (val1, val2) -> val2));
+                historyReduceState.clear();
+                historyReduceState.putAll(historyData);
+                lastQueryDayState.update(DateUtil.formatLocalDate(LocalDate.now()));
+            }
+        }
+        PlanStatOfDayDWD lastReduceData = null;
+        for (int i = 1; i <= 60; i++) {
+            lastReduceData = historyReduceState.get(DateUtil.formatLocalDate(statDay.minusDays(i)));
+            if (lastReduceData != null) {
+                break;
+            }
+        }
+        PlanStatOfDayDWD newStatData = PlanStatOfDayDWD.reduce(lastReduceData, element, now);
+        historyReduceState.put(DateUtil.formatLocalDate(statDay), newStatData);
+        collector.collect(newStatData);
+    }
+}

+ 31 - 0
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/PlanDayDWDRollYearProcess.java

@@ -0,0 +1,31 @@
+package flink.zanxiangnet.ad.monitoring.process;
+
+import flink.zanxiangnet.ad.monitoring.pojo.entity.AdDataOfDayODS;
+import flink.zanxiangnet.ad.monitoring.pojo.entity.PlanStatOfDayDWD;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.flink.api.common.state.ValueState;
+import org.apache.flink.api.common.state.ValueStateDescriptor;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
+import org.apache.flink.streaming.api.windowing.windows.GlobalWindow;
+import org.apache.flink.util.Collector;
+
+@Slf4j
+public class PlanDayDWDRollYearProcess extends ProcessWindowFunction<AdDataOfDayODS, PlanStatOfDayDWD, Long, GlobalWindow> {
+    
+    // 上次聚合的结果
+    private ValueState<PlanStatOfDayDWD> lastReduceState;
+
+    public void open(Configuration conf) {
+        lastReduceState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastReduceState", PlanStatOfDayDWD.class));
+    }
+
+    @Override
+    public void process(Long elementsCount, ProcessWindowFunction<AdDataOfDayODS, PlanStatOfDayDWD, Long, GlobalWindow>.Context context,
+                        Iterable<AdDataOfDayODS> elements, Collector<PlanStatOfDayDWD> out) throws Exception {
+        AdDataOfDayODS element = elements.iterator().next();
+        PlanStatOfDayDWD newStatDWD = PlanStatOfDayDWD.reduce(lastReduceState.value(), element, System.currentTimeMillis());
+        out.collect(newStatDWD);
+        lastReduceState.update(newStatDWD);
+    }
+}

+ 52 - 41
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/PlanHourDWDProcess.java

@@ -1,13 +1,9 @@
 package flink.zanxiangnet.ad.monitoring.process;
 
-import com.aliyun.odps.Instance;
-import com.aliyun.odps.Odps;
-import com.aliyun.odps.account.Account;
-import com.aliyun.odps.account.AliyunAccount;
-import com.aliyun.odps.data.Record;
-import com.aliyun.odps.task.SQLTask;
-import flink.zanxiangnet.ad.monitoring.maxcompute.MaxComputeLog;
+import flink.zanxiangnet.ad.monitoring.config.ClickhouseDataSourceFactory;
+import flink.zanxiangnet.ad.monitoring.dao.mapper.PlanStatOfDayDWDMapper;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.AdDataOfHourODS;
+import flink.zanxiangnet.ad.monitoring.pojo.entity.PlanStatOfDayDWD;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.PlanStatOfHourDWD;
 import flink.zanxiangnet.ad.monitoring.pojo.properties.ApplicationProperties;
 import flink.zanxiangnet.ad.monitoring.util.DateUtil;
@@ -21,22 +17,28 @@ import org.apache.flink.configuration.Configuration;
 import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
 import org.apache.flink.streaming.api.windowing.windows.GlobalWindow;
 import org.apache.flink.util.Collector;
+import org.apache.ibatis.datasource.DataSourceFactory;
+import org.apache.ibatis.mapping.Environment;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
 
 import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.stream.Collectors;
 
 @Slf4j
 public class PlanHourDWDProcess extends ProcessWindowFunction<AdDataOfHourODS, PlanStatOfHourDWD, Long, GlobalWindow> {
-    
-    private Odps odps;
+
+    private SqlSessionFactory sqlSessionFactory;
     // 上次查询的天数据
     private ValueState<String> lastQueryDayState;
     // 聚合的天的数据
-    private MapState<String, PlanStatOfHourDWD> historyReduceState;
+    private MapState<String, PlanStatOfDayDWD> historyReduceState;
+    // 昨天集合的最后一次数据
+    private MapState<String, PlanStatOfHourDWD> lastReduceState;
 
     @Override
     public void open(Configuration conf) {
@@ -44,15 +46,26 @@ public class PlanHourDWDProcess extends ProcessWindowFunction<AdDataOfHourODS, P
                 .getExecutionConfig()
                 .getGlobalJobParameters()
                 .toMap();
-        Account account = new AliyunAccount(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ID),
-                params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_KEY));
-        odps = new Odps(account);
-        odps.getRestClient().setRetryLogger(new MaxComputeLog());
-        odps.setEndpoint(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ENDPOINT));
-        odps.setDefaultProject(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_PROJECT_NAME));
+
+        Properties ckProps = new Properties();
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_URL, params.get(ApplicationProperties.CK_URL));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_USER, params.get(ApplicationProperties.CK_USERNAME));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_PASSWORD, params.get(ApplicationProperties.CK_PASSWORD));
+
+        DataSourceFactory dataSourceFactory = new ClickhouseDataSourceFactory();
+        dataSourceFactory.setProperties(ckProps);
+        Environment environment = new Environment("clickhouse", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
+        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(environment);
+        // 开启驼峰规则
+        configuration.setMapUnderscoreToCamelCase(true);
+        configuration.getTypeAliasRegistry().registerAlias(PlanStatOfDayDWD.class);
+        // addMapper一定要放到 alias的后面!!!!!
+        configuration.addMapper(PlanStatOfDayDWDMapper.class);
+        sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
 
         lastQueryDayState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastQueryDayState", String.class));
-        historyReduceState = getRuntimeContext().getMapState(new MapStateDescriptor<>("historyReduceState", Types.STRING, Types.POJO(PlanStatOfHourDWD.class)));
+        historyReduceState = getRuntimeContext().getMapState(new MapStateDescriptor<>("historyReduceState", Types.STRING, Types.POJO(PlanStatOfDayDWD.class)));
+        lastReduceState = getRuntimeContext().getMapState(new MapStateDescriptor<>("lastReduceState", Types.STRING, Types.POJO(PlanStatOfHourDWD.class)));
     }
 
     @Override
@@ -60,38 +73,36 @@ public class PlanHourDWDProcess extends ProcessWindowFunction<AdDataOfHourODS, P
                         Iterable<AdDataOfHourODS> iterable, Collector<PlanStatOfHourDWD> collector) throws Exception {
         AdDataOfHourODS element = iterable.iterator().next();
         LocalDate statDay = DateUtil.parseLocalDate(element.getStatDay());
-        LocalDateTime statTime = LocalDateTime.of(statDay, LocalTime.of(element.getHour(), 0, 0));
         long now = System.currentTimeMillis();
+        long adId = element.getAdId();
         LocalDate today = LocalDate.now();
 
         String lastQueryDay = lastQueryDayState.value();
         // 从 maxCompute拉取指定 广告的历史数据
         if (lastQueryDay == null || !lastQueryDay.equals(DateUtil.formatLocalDate(today))) {
-            LocalDate endDay = today, beginDay = statDay.minusDays(60);
-            String sql = "SELECT * FROM plan_stat_of_hour_dwd WHERE stat_day >= \"" + DateUtil.formatLocalDate(beginDay) + "\" AND stat_day <= \"" + DateUtil.formatLocalDate(endDay) + "\" AND campaign_id = " + element.getCampaignId() + ";";
-            Instance instance = SQLTask.run(odps, sql);
-            System.out.println("178===>sql: " + sql + ", odps日志: " + odps.logview().generateLogView(instance, 7 * 24));
-            instance.waitForSuccess();
-            List<Record> records = SQLTask.getResult(instance);
-            Map<String, PlanStatOfHourDWD> historyHourMap = records.stream()
-                    .map(PlanStatOfHourDWD::byMaxCompute)
-                    .sorted((o1, o2) -> new Long(o1.getCreateTime().getTime() - o2.getCreateTime().getTime()).intValue())
-                    .collect(Collectors.toMap(data -> data.getStatDay() + data.getHour(), data -> data, (val1, val2) -> val2));
-            historyReduceState.clear();
-            historyReduceState.putAll(historyHourMap);
-            lastQueryDayState.update(DateUtil.formatLocalDate(today));
+            try (SqlSession session = sqlSessionFactory.openSession()) {
+                PlanStatOfDayDWDMapper mapper = session.getMapper(PlanStatOfDayDWDMapper.class);
+                Map<String, PlanStatOfDayDWD> historyData = mapper.lastReduceResult(adId, null, DateUtil.formatLocalDate(today.minusDays(1L)), 60)
+                        .stream()
+                        .collect(Collectors.toMap(PlanStatOfDayDWD::getStatDay, data -> data, (val1, val2) -> val2));
+                historyReduceState.clear();
+                historyReduceState.putAll(historyData);
+                lastQueryDayState.update(DateUtil.formatLocalDate(today));
+            }
         }
-        PlanStatOfHourDWD lastReduceData = null;
-        for (int i = 1; i < 60 * 24; i++) {
-            LocalDateTime time = statTime.minusHours(i);
-            lastReduceData = historyReduceState.get(DateUtil.formatLocalDate(time.toLocalDate()) + time.getHour());
-            if (lastReduceData != null) {
+        PlanStatOfDayDWD yesterdayReduceData = null;
+        for (int i = 1; i < 60; i++) {
+            LocalDate day = statDay.minusDays(i);
+            yesterdayReduceData = historyReduceState.get(DateUtil.formatLocalDate(day));
+            if (yesterdayReduceData != null) {
                 break;
             }
         }
 
-        PlanStatOfHourDWD newStatData = PlanStatOfHourDWD.reduce(lastReduceData, element, now);
-        historyReduceState.put(newStatData.getStatDay(), newStatData);
+        PlanStatOfHourDWD lastReduceData = lastReduceState.get(element.getStatDay());
+
+        PlanStatOfHourDWD newStatData = PlanStatOfHourDWD.reduce(yesterdayReduceData, lastReduceData, element, now);
+        lastReduceState.put(newStatData.getStatDay(), newStatData);
         collector.collect(newStatData);
     }
 }

+ 32 - 34
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/process/PlanMinuteDWDProcess.java

@@ -1,12 +1,7 @@
 package flink.zanxiangnet.ad.monitoring.process;
 
-import com.aliyun.odps.Instance;
-import com.aliyun.odps.Odps;
-import com.aliyun.odps.account.Account;
-import com.aliyun.odps.account.AliyunAccount;
-import com.aliyun.odps.data.Record;
-import com.aliyun.odps.task.SQLTask;
-import flink.zanxiangnet.ad.monitoring.maxcompute.MaxComputeLog;
+import flink.zanxiangnet.ad.monitoring.config.ClickhouseDataSourceFactory;
+import flink.zanxiangnet.ad.monitoring.dao.mapper.PlanStatOfDayDWDMapper;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.*;
 import flink.zanxiangnet.ad.monitoring.pojo.properties.ApplicationProperties;
 import flink.zanxiangnet.ad.monitoring.util.DateUtil;
@@ -20,15 +15,17 @@ import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
 import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
 import org.apache.flink.util.Collector;
 import org.apache.flink.util.OutputTag;
+import org.apache.ibatis.datasource.DataSourceFactory;
+import org.apache.ibatis.mapping.Environment;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
+import java.util.*;
 
 @Slf4j
 public class PlanMinuteDWDProcess extends ProcessWindowFunction<AdDataOfMinuteODS, PlanStatOfMinuteDWD, Long, TimeWindow> {
@@ -36,7 +33,7 @@ public class PlanMinuteDWDProcess extends ProcessWindowFunction<AdDataOfMinuteOD
 
     private final OutputTag<PlanStatOfHourDWD> planHourFromMinuteStreamTag;
 
-    private Odps odps;
+    private SqlSessionFactory sqlSessionFactory;
 
     // 历史的天数据
     private ValueState<PlanStatOfDayDWD> historyDayState;
@@ -57,12 +54,22 @@ public class PlanMinuteDWDProcess extends ProcessWindowFunction<AdDataOfMinuteOD
                 .getExecutionConfig()
                 .getGlobalJobParameters()
                 .toMap();
-        Account account = new AliyunAccount(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ID),
-                params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_KEY));
-        odps = new Odps(account);
-        odps.getRestClient().setRetryLogger(new MaxComputeLog());
-        odps.setEndpoint(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_ENDPOINT));
-        odps.setDefaultProject(params.get(ApplicationProperties.MAX_COMPUTE_ACCOUNT_PROJECT_NAME));
+
+        Properties ckProps = new Properties();
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_URL, params.get(ApplicationProperties.CK_URL));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_USER, params.get(ApplicationProperties.CK_USERNAME));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_PASSWORD, params.get(ApplicationProperties.CK_PASSWORD));
+
+        DataSourceFactory dataSourceFactory = new ClickhouseDataSourceFactory();
+        dataSourceFactory.setProperties(ckProps);
+        Environment environment = new Environment("clickhouse", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
+        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(environment);
+        // 开启驼峰规则
+        configuration.setMapUnderscoreToCamelCase(true);
+        configuration.getTypeAliasRegistry().registerAlias(PlanStatOfDayDWD.class);
+        // addMapper一定要放到 alias的后面!!!!!
+        configuration.addMapper(PlanStatOfDayDWDMapper.class);
+        sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
 
         historyDayState = getRuntimeContext().getState(new ValueStateDescriptor<>("historyDayState", PlanStatOfDayDWD.class));
         lastQueryDayState = getRuntimeContext().getState(new ValueStateDescriptor<>("lastQueryDayState", String.class));
@@ -99,23 +106,14 @@ public class PlanMinuteDWDProcess extends ProcessWindowFunction<AdDataOfMinuteOD
         // 之前的数据
         String lastQueryDay = lastQueryDayState.value();
         if (lastQueryDay == null || !lastQueryDay.equals(statDay)) {
-            // 往前找 30天
-            LocalDate endDay = beginDate.minusDays(2L), beginDay = endDay.minusDays(30L);
-            String sql = "SELECT * FROM plan_stat_of_day_dwd WHERE stat_day >= \"" + DateUtil.formatLocalDate(beginDay) + "\" AND stat_day <= \"" + endDay + "\" AND campaign_id = " + campaignId + ";";
-            Instance instance = SQLTask.run(odps, sql);
-            // log.error("sql: " + sql + ", odps日志: " + odps.logview().generateLogView(instance, 7 * 24));
-            instance.waitForSuccess();
-            List<Record> records = SQLTask.getResult(instance);
-            List<PlanStatOfDayDWD> historyDayData = records.stream().map(PlanStatOfDayDWD::byMaxCompute).sorted((val1, val2) -> {
-                if (val1.getStatDay().equals(val2.getStatDay())) {
-                    return new Long(val1.getCreateTime().getTime() - val2.getCreateTime().getTime()).intValue();
+            try (SqlSession session = sqlSessionFactory.openSession()) {
+                PlanStatOfDayDWDMapper mapper = session.getMapper(PlanStatOfDayDWDMapper.class);
+                List<PlanStatOfDayDWD> historyDayData = mapper.lastReduceResult(campaignId, null, DateUtil.formatLocalDate(beginDate.minusDays(2L)), 1);
+                if (!historyDayData.isEmpty()) {
+                    historyDayState.update(historyDayData.get(historyDayData.size() - 1));
                 }
-                return DateUtil.parseLocalDate(val1.getStatDay()).compareTo(DateUtil.parseLocalDate(val2.getStatDay()));
-            }).collect(Collectors.toList());
-            if (!historyDayData.isEmpty()) {
-                historyDayState.update(historyDayData.get(historyDayData.size() - 1));
+                lastQueryDayState.update(statDay);
             }
-            lastQueryDayState.update(statDay);
         }
         PlanStatOfDayDWD beforeYesterdayDayDWD = historyDayState.value();
 

+ 3 - 59
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/sink/ClickhouseBatchStreamSink.java → flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/sink/AdDWDToCkBatchSink.java

@@ -1,13 +1,10 @@
 package flink.zanxiangnet.ad.monitoring.sink;
 
-import com.aliyun.odps.tunnel.TableTunnel;
 import com.aliyun.odps.tunnel.TunnelException;
 import flink.zanxiangnet.ad.monitoring.config.ClickhouseDataSourceFactory;
 import flink.zanxiangnet.ad.monitoring.dao.mapper.AdStatOfDayDWDMapper;
-import flink.zanxiangnet.ad.monitoring.maxcompute.bean.BeanUtil;
 import flink.zanxiangnet.ad.monitoring.pojo.entity.AdStatOfDayDWD;
 import flink.zanxiangnet.ad.monitoring.pojo.properties.ApplicationProperties;
-import flink.zanxiangnet.ad.monitoring.util.JsonUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
@@ -17,31 +14,17 @@ import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
 import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
-import org.springframework.beans.BeanUtils;
-import org.springframework.util.CollectionUtils;
 
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.*;
 
 /**
  * 批量数据写出
- *
- * @param <IN>
  */
 @Slf4j
-public class ClickhouseBatchStreamSink<T, IN extends List<T>> extends RichSinkFunction<IN> {
+public class AdDWDToCkBatchSink extends RichSinkFunction<List<AdStatOfDayDWD>> {
 
-    // 对象锁,防止MaxCompute的 Tunnel对象多次初始化
-    private static final Object DUMMY_LOCK = new Object();
-
-    private String projectName;
-    private String tableName;
-
-    private volatile transient TableTunnel tunnel;
-    private volatile transient List<BeanUtil.FieldInfo> fieldInfoList;
-    private volatile transient Map<String, Method> partitionFieldMethods;
     private SqlSessionFactory sqlSessionFactory;
 
 
@@ -76,29 +59,10 @@ public class ClickhouseBatchStreamSink<T, IN extends List<T>> extends RichSinkFu
      * @param context
      */
     @Override
-    public void invoke(IN value, Context context) throws TunnelException, IOException, InvocationTargetException, IllegalAccessException {
-        AdStatOfDayDWD adStatOfDayDWD = new AdStatOfDayDWD();
-        adStatOfDayDWD.setStatDay("2021-12-01");
-        adStatOfDayDWD.setAccountId(100L);
-        adStatOfDayDWD.setCreateTime(new Date());
-        adStatOfDayDWD.setCostDeviationRateTotal(39.5);
-        adStatOfDayDWD.removeNull();
-
-        List<AdStatOfDayDWD> list = new ArrayList<>(6);
-        for (int i = 0; i < 3; i ++) {
-            AdStatOfDayDWD temp = new AdStatOfDayDWD();
-            BeanUtils.copyProperties(adStatOfDayDWD, temp);
-            temp.setAdId((long) i);
-            list.add(temp);
-        }
-        list.add(adStatOfDayDWD);
-        log.error("准备写入:{}", value.size());
+    public void invoke(List<AdStatOfDayDWD> value, Context context) throws TunnelException, IOException, InvocationTargetException, IllegalAccessException {
         try (SqlSession session = sqlSessionFactory.openSession()) {
             AdStatOfDayDWDMapper mapper = session.getMapper(AdStatOfDayDWDMapper.class);
-            mapper.add(adStatOfDayDWD);
-            mapper.addBatch(list);
-            List<AdStatOfDayDWD> all = mapper.selectAll();
-            log.error("查询结果:{} | {}", all.size(), JsonUtil.toString(list));
+            mapper.addBatch(value);
         }
     }
 
@@ -106,24 +70,4 @@ public class ClickhouseBatchStreamSink<T, IN extends List<T>> extends RichSinkFu
     public void close() throws Exception {
         super.close();
     }
-
-    private String generateSQL(T t) {
-        if (CollectionUtils.isEmpty(partitionFieldMethods)) {
-            return null;
-        }
-        StringBuilder partition = new StringBuilder();
-        for (Map.Entry<String, Method> entry : partitionFieldMethods.entrySet()) {
-            partition.append(entry.getKey()).append("=");
-            try {
-                partition.append(entry.getValue().invoke(t));
-            } catch (InvocationTargetException | IllegalAccessException e) {
-                // 获取分区字段的值失败
-                log.error(e.getMessage(), e);
-                throw new RuntimeException("Failed get partition field value!");
-            }
-            partition.append(",");
-        }
-        partition = new StringBuilder(partition.substring(0, partition.length() - 1));
-        return partition.toString();
-    }
 }

+ 75 - 0
flink-ad-monitoring/src/main/java/flink/zanxiangnet/ad/monitoring/sink/PlanDWDToCkBatchSink.java

@@ -0,0 +1,75 @@
+package flink.zanxiangnet.ad.monitoring.sink;
+
+import com.aliyun.odps.tunnel.TunnelException;
+import flink.zanxiangnet.ad.monitoring.config.ClickhouseDataSourceFactory;
+import flink.zanxiangnet.ad.monitoring.dao.mapper.PlanStatOfDayDWDMapper;
+import flink.zanxiangnet.ad.monitoring.pojo.entity.PlanStatOfDayDWD;
+import flink.zanxiangnet.ad.monitoring.pojo.properties.ApplicationProperties;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
+import org.apache.ibatis.datasource.DataSourceFactory;
+import org.apache.ibatis.mapping.Environment;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * 批量数据写出
+ */
+@Slf4j
+public class PlanDWDToCkBatchSink extends RichSinkFunction<List<PlanStatOfDayDWD>> {
+
+    private SqlSessionFactory sqlSessionFactory;
+
+
+    @Override
+    public void open(Configuration config) throws Exception {
+        Map<String, String> params = getRuntimeContext()
+                .getExecutionConfig()
+                .getGlobalJobParameters()
+                .toMap();
+
+        Properties ckProps = new Properties();
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_URL, params.get(ApplicationProperties.CK_URL));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_USER, params.get(ApplicationProperties.CK_USERNAME));
+        ckProps.setProperty(ClickhouseDataSourceFactory.PROP_PASSWORD, params.get(ApplicationProperties.CK_PASSWORD));
+
+        DataSourceFactory dataSourceFactory = new ClickhouseDataSourceFactory();
+        dataSourceFactory.setProperties(ckProps);
+        Environment environment = new Environment("clickhouse", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
+        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(environment);
+        // 开启驼峰规则
+        configuration.setMapUnderscoreToCamelCase(true);
+        configuration.getTypeAliasRegistry().registerAlias(PlanStatOfDayDWD.class);
+        // addMapper一定要放到 alias的后面!!!!!
+        configuration.addMapper(PlanStatOfDayDWDMapper.class);
+        sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
+    }
+
+    /**
+     * 将值写入到 Sink。每个值都会调用此函数
+     *
+     * @param value
+     * @param context
+     */
+    @Override
+    public void invoke(List<PlanStatOfDayDWD> value, Context context) throws TunnelException, IOException, InvocationTargetException, IllegalAccessException {
+        try (SqlSession session = sqlSessionFactory.openSession()) {
+            PlanStatOfDayDWDMapper mapper = session.getMapper(PlanStatOfDayDWDMapper.class);
+            mapper.addBatch(value);
+        }
+    }
+
+    @Override
+    public void close() throws Exception {
+        super.close();
+    }
+}