|
|
@@ -0,0 +1,91 @@
|
|
|
+package com.ufo.project.forecast.processor;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+
|
|
|
+import com.ufo.project.config.domain.ConfigStation;
|
|
|
+import com.ufo.project.config.service.IConfigStationService;
|
|
|
+import com.ufo.project.forecast.fileupload.domain.DataPowerForecastReportBatch;
|
|
|
+import com.ufo.project.forecast.fileupload.service.IDataPowerForecastReportBatchService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 功率预测上报处理器抽象基类(模板方法:窗口计算 + 批次行遍历,单场站异常隔离)
|
|
|
+ *
|
|
|
+ * @author ufo
|
|
|
+ * @date 2026-10-19
|
|
|
+ */
|
|
|
+public abstract class AbstractForecastProcessor implements ForecastProcessor
|
|
|
+{
|
|
|
+ protected static final ZoneId ZONE_SH = ZoneId.of("Asia/Shanghai");
|
|
|
+
|
|
|
+ protected static final int INSERT_CHUNK = 500;
|
|
|
+
|
|
|
+ protected static final Logger log = LoggerFactory.getLogger(AbstractForecastProcessor.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ protected IDataPowerForecastReportBatchService reportBatchService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ protected IConfigStationService configStationService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData(int day, String time)
|
|
|
+ {
|
|
|
+ LocalDate d = LocalDate.parse(String.valueOf(day), DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
+ long windowStart = d.atStartOfDay().atZone(ZONE_SH).toEpochSecond();
|
|
|
+ long windowEnd = d.atTime(LocalTime.parse(time)).atZone(ZONE_SH).toEpochSecond();
|
|
|
+ List<DataPowerForecastReportBatch> batches = reportBatchService.selectByTypeDayTime(getType(), day, time);
|
|
|
+ if (batches == null || batches.isEmpty())
|
|
|
+ {
|
|
|
+ log.info("[PowerForecastReportBatch] 无上报批次可处理, type={}, day={}, time={}", getType(), day, time);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (DataPowerForecastReportBatch batch : batches)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ initStation(batch, windowStart, windowEnd);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ log.error("[PowerForecastReportBatch] 单场站初始化失败, type={}, stationCode={}, batchNo={}",
|
|
|
+ getType(), batch.getStationCode(), batch.getBatchNo(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化单场站上报数据(窗口内源表取数合并写入 report 表)
|
|
|
+ *
|
|
|
+ * @param batch 上报批次行
|
|
|
+ * @param windowStart 窗口起点(unix秒, 不含)
|
|
|
+ * @param windowEnd 窗口终点(unix秒, 含)
|
|
|
+ */
|
|
|
+ protected abstract void initStation(DataPowerForecastReportBatch batch, long windowStart, long windowEnd);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按场站编码解析 entityId
|
|
|
+ *
|
|
|
+ * @param stationCode 场站编码
|
|
|
+ * @return entityId, 场站查无时返回 null
|
|
|
+ */
|
|
|
+ protected String resolveEntityId(String stationCode)
|
|
|
+ {
|
|
|
+ ConfigStation q = new ConfigStation();
|
|
|
+ q.setStationCode(stationCode);
|
|
|
+ List<ConfigStation> list = configStationService.selectConfigStationList(q);
|
|
|
+ if (list == null || list.isEmpty())
|
|
|
+ {
|
|
|
+ log.error("[PowerForecastReportBatch] 未找到场站, stationCode={}", stationCode);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return String.valueOf(list.get(0).getId());
|
|
|
+ }
|
|
|
+}
|