Răsfoiți Sursa

[0924] 短期功率预测修正、超短期功率预测修正计算优化

taosj 1 lună în urmă
părinte
comite
18f27a0414

+ 31 - 3
forecast-backend-server/src/main/java/com/ufo/project/forecast/shortterm/power/controller/DataShortTermPowerForecastCorrectController.java

@@ -1,6 +1,10 @@
 package com.ufo.project.forecast.shortterm.power.controller;
 
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 import javax.servlet.http.HttpServletResponse;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -18,7 +22,6 @@ import com.ufo.project.forecast.shortterm.power.domain.DataShortTermPowerForecas
 import com.ufo.project.forecast.shortterm.power.service.IDataShortTermPowerForecastCorrectService;
 import com.ufo.base.framework.web.controller.BaseController;
 import com.ufo.base.framework.web.domain.AjaxResult;
-import com.ufo.base.common.utils.TimeUtils;
 import com.ufo.base.common.utils.poi.ExcelUtil;
 import com.ufo.base.framework.web.page.TableDataInfo;
 
@@ -51,7 +54,7 @@ public class DataShortTermPowerForecastCorrectController extends BaseController
     @GetMapping("/chart")
     public TableDataInfo chart(DataShortTermPowerForecastCorrect dataShortTermPowerForecastCorrect)
     {
-        List<DataShortTermPowerForecastCorrect> list = dataShortTermPowerForecastCorrectService.selectDataShortTermPowerForecastCorrectList(dataShortTermPowerForecastCorrect);
+        List<DataShortTermPowerForecastCorrect> list = this.queryList(dataShortTermPowerForecastCorrect);
         return getDataTable(list);
     }
 
@@ -63,11 +66,36 @@ public class DataShortTermPowerForecastCorrectController extends BaseController
     @PostMapping("/export/excel")
     public void export(HttpServletResponse response, DataShortTermPowerForecastCorrect dataShortTermPowerForecastCorrect)
     {
-        List<DataShortTermPowerForecastCorrect> list = dataShortTermPowerForecastCorrectService.selectDataShortTermPowerForecastCorrectList(dataShortTermPowerForecastCorrect);
+        List<DataShortTermPowerForecastCorrect> list = this.queryList(dataShortTermPowerForecastCorrect);
         ExcelUtil<DataShortTermPowerForecastCorrect> util = new ExcelUtil<DataShortTermPowerForecastCorrect>(DataShortTermPowerForecastCorrect.class);
         util.exportExcel(response, list, "短期功率修正数据数据");
     }
 
+    private List<DataShortTermPowerForecastCorrect> queryList(DataShortTermPowerForecastCorrect dataShortTermPowerForecastCorrect)
+    {
+        List<DataShortTermPowerForecastCorrect> list = dataShortTermPowerForecastCorrectService.selectDataShortTermPowerForecastCorrectList(dataShortTermPowerForecastCorrect);
+        if (list == null || list.isEmpty())
+        {
+            return list;
+        }
+
+        // 按 forecast_time 分组,每组按 start_time desc, id desc 取第一条(即同一时间点最新起报的数据)
+        Comparator<DataShortTermPowerForecastCorrect> latestFirst = Comparator
+                .comparing(DataShortTermPowerForecastCorrect::getStartTime, Comparator.nullsFirst(Comparator.<Long>naturalOrder()))
+                .thenComparing(DataShortTermPowerForecastCorrect::getId, Comparator.nullsFirst(Comparator.<Long>naturalOrder()));
+        Map<Long, DataShortTermPowerForecastCorrect> latestByForecastTime = new TreeMap<>();
+        for (DataShortTermPowerForecastCorrect item : list)
+        {
+            if (item.getForecastTime() == null)
+            {
+                continue;
+            }
+            latestByForecastTime.merge(item.getForecastTime(), item,
+                    (existing, candidate) -> latestFirst.compare(candidate, existing) > 0 ? candidate : existing);
+        }
+        return new ArrayList<>(latestByForecastTime.values());
+    }
+
     /**
      * 获取短期功率修正数据详细信息
      */

+ 31 - 2
forecast-backend-server/src/main/java/com/ufo/project/forecast/supershort/controller/DataSuperShortTermForecastCorrectController.java

@@ -1,6 +1,10 @@
 package com.ufo.project.forecast.supershort.controller;
 
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 import javax.servlet.http.HttpServletResponse;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -49,7 +53,7 @@ public class DataSuperShortTermForecastCorrectController extends BaseController
     @GetMapping("/chart")
     public TableDataInfo chart(DataSuperShortTermForecastCorrect dataSuperShortTermForecastCorrect)
     {
-        List<DataSuperShortTermForecastCorrect> list = dataSuperShortTermForecastCorrectService.selectDataSuperShortTermForecastCorrectList(dataSuperShortTermForecastCorrect);
+        List<DataSuperShortTermForecastCorrect> list = this.queryList(dataSuperShortTermForecastCorrect);
         return getDataTable(list);
     }
 
@@ -61,11 +65,36 @@ public class DataSuperShortTermForecastCorrectController extends BaseController
     @PostMapping("/export/excel")
     public void export(HttpServletResponse response, DataSuperShortTermForecastCorrect dataSuperShortTermForecastCorrect)
     {
-        List<DataSuperShortTermForecastCorrect> list = dataSuperShortTermForecastCorrectService.selectDataSuperShortTermForecastCorrectList(dataSuperShortTermForecastCorrect);
+        List<DataSuperShortTermForecastCorrect> list = this.queryList(dataSuperShortTermForecastCorrect);
         ExcelUtil<DataSuperShortTermForecastCorrect> util = new ExcelUtil<DataSuperShortTermForecastCorrect>(DataSuperShortTermForecastCorrect.class);
         util.exportExcel(response, list, "超短期功率修正数据数据");
     }
 
+    private List<DataSuperShortTermForecastCorrect> queryList(DataSuperShortTermForecastCorrect dataSuperShortTermForecastCorrect)
+    {
+        List<DataSuperShortTermForecastCorrect> list = dataSuperShortTermForecastCorrectService.selectDataSuperShortTermForecastCorrectList(dataSuperShortTermForecastCorrect);
+        if (list == null || list.isEmpty())
+        {
+            return list;
+        }
+
+        // 按 forecast_time 分组,每组按 start_time desc, id desc 取第一条(即同一时间点最新起报的数据)
+        Comparator<DataSuperShortTermForecastCorrect> latestFirst = Comparator
+                .comparing(DataSuperShortTermForecastCorrect::getStartTime, Comparator.nullsFirst(Comparator.<Long>naturalOrder()))
+                .thenComparing(DataSuperShortTermForecastCorrect::getId, Comparator.nullsFirst(Comparator.<Long>naturalOrder()));
+        Map<Long, DataSuperShortTermForecastCorrect> latestByForecastTime = new TreeMap<>();
+        for (DataSuperShortTermForecastCorrect item : list)
+        {
+            if (item.getForecastTime() == null)
+            {
+                continue;
+            }
+            latestByForecastTime.merge(item.getForecastTime(), item,
+                    (existing, candidate) -> latestFirst.compare(candidate, existing) > 0 ? candidate : existing);
+        }
+        return new ArrayList<>(latestByForecastTime.values());
+    }
+
     /**
      * 获取超短期功率修正数据详细信息
      */