|
|
@@ -0,0 +1,121 @@
|
|
|
+package com.ufo.project.forecast.processor;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import com.ufo.project.forecast.fileupload.domain.DataPowerForecastReportBatch;
|
|
|
+import com.ufo.project.forecast.shortterm.power.domain.DataShortTermPowerForecastCorrect;
|
|
|
+import com.ufo.project.forecast.shortterm.power.domain.DataShortTermPowerForecastIssued;
|
|
|
+import com.ufo.project.forecast.shortterm.power.domain.DataShortTermPowerForecastReport;
|
|
|
+import com.ufo.project.forecast.shortterm.power.mapper.DataShortTermPowerForecastCorrectMapper;
|
|
|
+import com.ufo.project.forecast.shortterm.power.mapper.DataShortTermPowerForecastIssuedMapper;
|
|
|
+import com.ufo.project.forecast.shortterm.power.mapper.DataShortTermPowerForecastReportMapper;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 短期功率预测上报处理器(窗口内取 issued/correct 最新数据按预测时刻合并写入 report 表)
|
|
|
+ *
|
|
|
+ * @author ufo
|
|
|
+ * @date 2026-10-19
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class ShortForecastProcessorImpl extends AbstractForecastProcessor
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private DataShortTermPowerForecastIssuedMapper issuedMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DataShortTermPowerForecastCorrectMapper correctMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DataShortTermPowerForecastReportMapper reportMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getType()
|
|
|
+ {
|
|
|
+ return DataPowerForecastReportBatch.TYPE_SHORT;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initStation(DataPowerForecastReportBatch batch, long windowStart, long windowEnd)
|
|
|
+ {
|
|
|
+ String entityId = resolveEntityId(batch.getStationCode());
|
|
|
+ if (entityId == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (reportMapper.countByBatchNo(batch.getBatchNo()) > 0)
|
|
|
+ {
|
|
|
+ log.info("[PowerForecastReportBatch] 批次已存在, 跳过, batchNo={}", batch.getBatchNo());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<DataShortTermPowerForecastIssued> issuedRows = issuedMapper.selectLatestByWindow(entityId, windowStart, windowEnd);
|
|
|
+ List<DataShortTermPowerForecastCorrect> correctRows = correctMapper.selectLatestByWindow(entityId, windowStart, windowEnd);
|
|
|
+ Map<Long, DataShortTermPowerForecastReport> merged = new LinkedHashMap<>();
|
|
|
+ for (DataShortTermPowerForecastIssued r : issuedRows)
|
|
|
+ {
|
|
|
+ merged.put(r.getForecastTime(), toReport(r));
|
|
|
+ }
|
|
|
+ for (DataShortTermPowerForecastCorrect r : correctRows)
|
|
|
+ {
|
|
|
+ merged.put(r.getForecastTime(), toReport(r));
|
|
|
+ }
|
|
|
+ List<DataShortTermPowerForecastReport> rows = new ArrayList<>(merged.values());
|
|
|
+ rows.sort(Comparator.comparingLong(DataShortTermPowerForecastReport::getForecastTime));
|
|
|
+ if (rows.isEmpty())
|
|
|
+ {
|
|
|
+ log.info("[PowerForecastReportBatch] 窗口内无源数据, 跳过, batchNo={}", batch.getBatchNo());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (DataShortTermPowerForecastReport r : rows)
|
|
|
+ {
|
|
|
+ r.setBatchNo(batch.getBatchNo());
|
|
|
+ if (r.getCreateTime() != null)
|
|
|
+ {
|
|
|
+ r.setCreateTimeEpoch(r.getCreateTime().getTime() / 1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 0; i < rows.size(); i += INSERT_CHUNK)
|
|
|
+ {
|
|
|
+ reportMapper.insertBatch(rows.subList(i, Math.min(i + INSERT_CHUNK, rows.size())));
|
|
|
+ }
|
|
|
+ log.info("[PowerForecastReportBatch] 上报数据写入完成, batchNo={}, rows={}", batch.getBatchNo(), rows.size());
|
|
|
+ }
|
|
|
+
|
|
|
+ private DataShortTermPowerForecastReport toReport(DataShortTermPowerForecastIssued src)
|
|
|
+ {
|
|
|
+ DataShortTermPowerForecastReport r = new DataShortTermPowerForecastReport();
|
|
|
+ r.setDataSourcegrabId(src.getDataSourcegrabId());
|
|
|
+ r.setDataSourcegrabPatternName(src.getDataSourcegrabPatternName());
|
|
|
+ r.setEntityId(src.getEntityId());
|
|
|
+ r.setEntityType(src.getEntityType());
|
|
|
+ r.setEntityName(src.getEntityName());
|
|
|
+ r.setCreateTime(src.getCreateTime());
|
|
|
+ r.setStartTime(src.getStartTime());
|
|
|
+ r.setForecastTime(src.getForecastTime());
|
|
|
+ r.setPredays(src.getPredays());
|
|
|
+ r.setPower(src.getPower());
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ private DataShortTermPowerForecastReport toReport(DataShortTermPowerForecastCorrect src)
|
|
|
+ {
|
|
|
+ DataShortTermPowerForecastReport r = new DataShortTermPowerForecastReport();
|
|
|
+ r.setDataSourcegrabId(src.getDataSourcegrabId());
|
|
|
+ r.setDataSourcegrabPatternName(src.getDataSourcegrabPatternName());
|
|
|
+ r.setEntityId(src.getEntityId());
|
|
|
+ r.setEntityType(src.getEntityType());
|
|
|
+ r.setEntityName(src.getEntityName());
|
|
|
+ r.setCreateTime(src.getCreateTime());
|
|
|
+ r.setStartTime(src.getStartTime());
|
|
|
+ r.setForecastTime(src.getForecastTime());
|
|
|
+ r.setPredays(src.getPredays());
|
|
|
+ r.setPower(src.getPower());
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+}
|