Forráskód Böngészése

feat: 增加短期预测报表(日报/月报/年报)

- 新增 API: shortTermForecastReport.js (query/export)
- 新增 3 个报表页面: 日报、月报、年报
- 后端 parseLong 支持日期字符串格式 (yyyy-MM-dd, yyyy-MM-dd HH:mm:ss, yyyy-MM)
- 新增 sys_menu 菜单项 (2079-2081)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
taosj 2 hónapja
szülő
commit
3db79cd119

+ 38 - 3
forecast-backend-server/src/main/java/com/ufo/project/data/service/impl/ShortTermPowerForecastReportServiceImpl.java

@@ -6,7 +6,9 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.YearMonth;
 import java.time.ZoneId;
+import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedHashMap;
@@ -610,18 +612,51 @@ public class ShortTermPowerForecastReportServiceImpl implements IShortTermPowerF
     }
 
     /**
-     * 安全解析Long
+     * 安全解析Long,支持纯数字时间戳或日期字符串(yyyy-MM-dd、yyyy-MM-dd HH:mm:ss、yyyy-MM)
      */
     private Long parseLong(String value)
     {
         if (value == null || value.isEmpty()) return 0L;
+        String trimmed = value.trim();
+        // 先尝试直接解析为数字时间戳
         try
         {
-            return Long.parseLong(value.trim());
+            return Long.parseLong(trimmed);
         }
         catch (NumberFormatException e)
         {
-            return 0L;
+            // 尝试作为日期字符串解析为秒级时间戳
+            try
+            {
+                // yyyy-MM-dd HH:mm:ss
+                ZonedDateTime zdt = LocalDateTime.parse(trimmed, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+                        .atZone(ZONE_SHANGHAI);
+                return zdt.toEpochSecond();
+            }
+            catch (DateTimeParseException e2)
+            {
+                // yyyy-MM-dd
+                try
+                {
+                    ZonedDateTime zdt = LocalDate.parse(trimmed, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
+                            .atStartOfDay(ZONE_SHANGHAI);
+                    return zdt.toEpochSecond();
+                }
+                catch (DateTimeParseException e3)
+                {
+                    // yyyy-MM(月末)
+                    try
+                    {
+                        YearMonth ym = YearMonth.parse(trimmed, DateTimeFormatter.ofPattern("yyyy-MM"));
+                        ZonedDateTime zdt = ym.atDay(ym.lengthOfMonth()).atTime(23, 59, 59).atZone(ZONE_SHANGHAI);
+                        return zdt.toEpochSecond();
+                    }
+                    catch (DateTimeParseException e4)
+                    {
+                        return 0L;
+                    }
+                }
+            }
         }
     }
 

+ 21 - 0
forecast-backend-vue/src/api/power/shortTermForecastReport.js

@@ -0,0 +1,21 @@
+import request from '@/utils/request'
+
+// 查询短期预测报表
+export function queryShortTermForecastReport(query) {
+  return request({
+    url: '/data/shortTermPowerForecastReport',
+    method: 'post',
+    data: query
+  })
+}
+
+// 导出短期预测报表
+export function exportShortTermForecastReport(data) {
+  return request({
+    url: '/data/shortTermPowerForecastReport/export',
+    method: 'post',
+    data: data,
+    responseType: 'blob',
+    timeout: 120000
+  })
+}

+ 167 - 0
forecast-backend-vue/src/views/ufo/datareport/shorTermForecastDailyReport.vue

@@ -0,0 +1,167 @@
+<template>
+  <div class="shor-term-forecast-daily-page">
+    <a-card :bordered="false">
+      <a-row :gutter="[12, 12]" align="middle">
+        <a-col :xs="24" :md="6">
+          <StationSelector v-model:value="query.stationId" :options="stationOptions" :multiple="false" />
+        </a-col>
+        <a-col :xs="24" :md="5">
+          <a-date-picker
+            v-model:value="query.startTime"
+            format="YYYY-MM-DD"
+            value-format="YYYY-MM-DD"
+            placeholder="起始时间"
+            class="full-control"
+          />
+        </a-col>
+        <a-col :xs="24" :md="5">
+          <a-date-picker
+            v-model:value="query.endTime"
+            format="YYYY-MM-DD"
+            value-format="YYYY-MM-DD"
+            placeholder="截止时间"
+            class="full-control"
+          />
+        </a-col>
+        <a-col :xs="24" :md="8">
+          <a-space>
+            <a-button type="primary" :loading="loading" :disabled="!queryValid" @click="handleQuery">确认</a-button>
+            <a-button :loading="exporting" :disabled="!queryValid" @click="handleExport">导出</a-button>
+          </a-space>
+        </a-col>
+      </a-row>
+    </a-card>
+
+    <a-card title="数据详情" :bordered="false" style="margin-top: 16px">
+      <BusinessDataTable
+        :columns="tableColumns"
+        :data-source="tableRows"
+        :pagination="{ pageSize: 10 }"
+        :scroll-x="'max-content'"
+      />
+    </a-card>
+  </div>
+</template>
+
+<script setup name="shorTermForecastDailyReport">
+import { computed, onMounted, reactive, ref } from 'vue';
+import { message } from 'ant-design-vue';
+import dayjs from 'dayjs';
+import { saveAs } from 'file-saver';
+import { blobValidate } from '@/utils/bearjia';
+import { listStation } from '@/api/config/station';
+import { queryShortTermForecastReport, exportShortTermForecastReport } from '@/api/power/shortTermForecastReport';
+import BusinessDataTable from '../components/BusinessDataTable.vue';
+import StationSelector from '../components/StationSelector.vue';
+import { normalizeRows } from '../components/dataAdapter';
+
+const loading = ref(false);
+const exporting = ref(false);
+const stationOptions = ref([]);
+const tableRows = ref([]);
+
+const query = reactive({
+  stationId: undefined,
+  startTime: dayjs(),
+  endTime: dayjs(),
+});
+
+const tableColumns = [
+  { title: '时间', dataIndex: 'time' },
+  { title: '开机容量(MW)', dataIndex: 'operatingCapacity' },
+  { title: '实发功率(MW)', dataIndex: 'actualPower' },
+  { title: '预测功率(MW)', dataIndex: 'forecastPower' },
+  { title: '均方根差', dataIndex: 'rootMeanSquareError' },
+  { title: '平均绝对误差', dataIndex: 'meanAbsoluteError' },
+  { title: '相关性系数', dataIndex: 'correlationCoefficientR' },
+  { title: '最大误差合格率(%)', dataIndex: 'maximumErrorPassRate' },
+];
+
+const queryValid = computed(() => {
+  if (!query.stationId) return false;
+  if (!query.startTime || !query.endTime) return false;
+  return true;
+});
+
+const buildParams = () => ({
+  type: 'daily',
+  entityId: String(query.stationId),
+  startTime: dayjs(query.startTime).format('YYYY-MM-DD'),
+  endTime: dayjs(query.endTime).format('YYYY-MM-DD'),
+});
+
+const handleQuery = async () => {
+  if (!query.stationId) {
+    message.warning('请先选择场站');
+    return;
+  }
+  if (!queryValid.value) {
+    return;
+  }
+  loading.value = true;
+  try {
+    const res = await queryShortTermForecastReport(buildParams());
+    tableRows.value = normalizeRows(res);
+  } finally {
+    loading.value = false;
+  }
+};
+
+const handleExport = async () => {
+  if (!query.stationId) {
+    message.warning('请先选择场站');
+    return;
+  }
+  if (!queryValid.value) {
+    return;
+  }
+  exporting.value = true;
+  try {
+    const res = await exportShortTermForecastReport(buildParams());
+    const isFile = await blobValidate(res);
+    if (isFile) {
+      const start = dayjs(query.startTime).format('YYYYMMDD');
+      const end = dayjs(query.endTime).format('YYYYMMDD');
+      saveAs(new Blob([res]), `短期预测日报-${start}-${end}.xlsx`);
+      message.success('导出成功');
+    } else {
+      const text = await res.text();
+      let msg = '导出失败';
+      try { msg = JSON.parse(text)?.msg || msg; } catch (e) { /* ignore */ }
+      message.error(msg);
+    }
+  } finally {
+    exporting.value = false;
+  }
+};
+
+async function loadStationOptions() {
+  try {
+    const res = await listStation({ pageNum: 1, pageSize: 500 });
+    const rows = normalizeRows(res);
+    stationOptions.value = rows.map((item, index) => ({
+      label: item.stationName || item.name || item.entityName || item.siteName || '未知场站',
+      value: item.id || item.stationId || item.entityId || `station-${index + 1}`,
+    }));
+    if (!query.stationId && stationOptions.value.length) {
+      query.stationId = stationOptions.value[0].value;
+    }
+  } catch (e) {
+    /* ignore */
+  }
+}
+
+onMounted(async () => {
+  await loadStationOptions();
+  await handleQuery();
+});
+</script>
+
+<style lang="less" scoped>
+.shor-term-forecast-daily-page {
+  padding: 16px;
+}
+.full-control {
+  width: 100%;
+}
+</style>

+ 169 - 0
forecast-backend-vue/src/views/ufo/datareport/shorTermForecastMonthlyReport.vue

@@ -0,0 +1,169 @@
+<template>
+  <div class="shor-term-forecast-monthly-page">
+    <a-card :bordered="false">
+      <a-row :gutter="[12, 12]" align="middle">
+        <a-col :xs="24" :md="6">
+          <StationSelector v-model:value="query.stationId" :options="stationOptions" :multiple="false" />
+        </a-col>
+        <a-col :xs="24" :md="5">
+          <a-month-picker
+            v-model:value="query.startTime"
+            format="YYYY-MM"
+            placeholder="起始时间"
+            class="full-control"
+          />
+        </a-col>
+        <a-col :xs="24" :md="5">
+          <a-month-picker
+            v-model:value="query.endTime"
+            format="YYYY-MM"
+            placeholder="截止时间"
+            class="full-control"
+          />
+        </a-col>
+        <a-col :xs="24" :md="8">
+          <a-space>
+            <a-button type="primary" :loading="loading" :disabled="!queryValid" @click="handleQuery">确认</a-button>
+            <a-button :loading="exporting" :disabled="!queryValid" @click="handleExport">导出</a-button>
+          </a-space>
+        </a-col>
+      </a-row>
+    </a-card>
+
+    <a-card title="数据详情" :bordered="false" style="margin-top: 16px">
+      <BusinessDataTable
+        :columns="tableColumns"
+        :data-source="tableRows"
+        :pagination="{ pageSize: 10 }"
+        :scroll-x="'max-content'"
+      />
+    </a-card>
+  </div>
+</template>
+
+<script setup name="shorTermForecastMonthlyReport">
+import { computed, onMounted, reactive, ref } from 'vue';
+import { message } from 'ant-design-vue';
+import dayjs from 'dayjs';
+import { saveAs } from 'file-saver';
+import { blobValidate } from '@/utils/bearjia';
+import { listStation } from '@/api/config/station';
+import { queryShortTermForecastReport, exportShortTermForecastReport } from '@/api/power/shortTermForecastReport';
+import BusinessDataTable from '../components/BusinessDataTable.vue';
+import StationSelector from '../components/StationSelector.vue';
+import { normalizeRows } from '../components/dataAdapter';
+
+const loading = ref(false);
+const exporting = ref(false);
+const stationOptions = ref([]);
+const tableRows = ref([]);
+
+const query = reactive({
+  stationId: undefined,
+  startTime: dayjs(),
+  endTime: dayjs(),
+});
+
+const tableColumns = [
+  { title: '时间', dataIndex: 'time' },
+  { title: '开机容量(MW)', dataIndex: 'operatingCapacity' },
+  { title: '实发功率(MW)', dataIndex: 'actualPower' },
+  { title: '预测功率(MW)', dataIndex: 'forecastPower' },
+  { title: '均方根差', dataIndex: 'rootMeanSquareError' },
+  { title: '平均绝对误差', dataIndex: 'meanAbsoluteError' },
+  { title: '相关性系数', dataIndex: 'correlationCoefficientR' },
+  { title: '最大误差合格率(%)', dataIndex: 'maximumErrorPassRate' },
+];
+
+const queryValid = computed(() => {
+  if (!query.stationId) return false;
+  if (!query.startTime || !query.endTime) return false;
+  return true;
+});
+
+const buildParams = () => {
+  const start = dayjs(query.startTime);
+  const end = dayjs(query.endTime);
+  return {
+    type: 'monthly',
+    entityId: String(query.stationId),
+    startTime: start.format('YYYY-MM') + '-01 00:00:00',
+    endTime: end.endOf('month').format('YYYY-MM-DD HH:mm:ss'),
+  };
+};
+
+const handleQuery = async () => {
+  if (!query.stationId) {
+    message.warning('请先选择场站');
+    return;
+  }
+  if (!queryValid.value) {
+    return;
+  }
+  loading.value = true;
+  try {
+    const res = await queryShortTermForecastReport(buildParams());
+    tableRows.value = normalizeRows(res);
+  } finally {
+    loading.value = false;
+  }
+};
+
+const handleExport = async () => {
+  if (!query.stationId) {
+    message.warning('请先选择场站');
+    return;
+  }
+  if (!queryValid.value) {
+    return;
+  }
+  exporting.value = true;
+  try {
+    const res = await exportShortTermForecastReport(buildParams());
+    const isFile = await blobValidate(res);
+    if (isFile) {
+      const start = dayjs(query.startTime).format('YYYYMM');
+      const end = dayjs(query.endTime).format('YYYYMM');
+      saveAs(new Blob([res]), `短期预测月报-${start}-${end}.xlsx`);
+      message.success('导出成功');
+    } else {
+      const text = await res.text();
+      let msg = '导出失败';
+      try { msg = JSON.parse(text)?.msg || msg; } catch (e) { /* ignore */ }
+      message.error(msg);
+    }
+  } finally {
+    exporting.value = false;
+  }
+};
+
+async function loadStationOptions() {
+  try {
+    const res = await listStation({ pageNum: 1, pageSize: 500 });
+    const rows = normalizeRows(res);
+    stationOptions.value = rows.map((item, index) => ({
+      label: item.stationName || item.name || item.entityName || item.siteName || '未知场站',
+      value: item.id || item.stationId || item.entityId || `station-${index + 1}`,
+    }));
+    if (!query.stationId && stationOptions.value.length) {
+      query.stationId = stationOptions.value[0].value;
+    }
+  } catch (e) {
+    /* ignore */
+  }
+}
+
+onMounted(async () => {
+  await loadStationOptions();
+  await handleQuery();
+});
+</script>
+
+<style lang="less" scoped>
+.shor-term-forecast-monthly-page {
+  padding: 16px;
+}
+.full-control {
+  width: 100%;
+}
+</style>

+ 169 - 0
forecast-backend-vue/src/views/ufo/datareport/shorTermForecastYearlyReport.vue

@@ -0,0 +1,169 @@
+<template>
+  <div class="shor-term-forecast-yearly-page">
+    <a-card :bordered="false">
+      <a-row :gutter="[12, 12]" align="middle">
+        <a-col :xs="24" :md="6">
+          <StationSelector v-model:value="query.stationId" :options="stationOptions" :multiple="false" />
+        </a-col>
+        <a-col :xs="24" :md="5">
+          <a-year-picker
+            v-model:value="query.startTime"
+            format="YYYY"
+            placeholder="起始时间"
+            class="full-control"
+          />
+        </a-col>
+        <a-col :xs="24" :md="5">
+          <a-year-picker
+            v-model:value="query.endTime"
+            format="YYYY"
+            placeholder="截止时间"
+            class="full-control"
+          />
+        </a-col>
+        <a-col :xs="24" :md="8">
+          <a-space>
+            <a-button type="primary" :loading="loading" :disabled="!queryValid" @click="handleQuery">确认</a-button>
+            <a-button :loading="exporting" :disabled="!queryValid" @click="handleExport">导出</a-button>
+          </a-space>
+        </a-col>
+      </a-row>
+    </a-card>
+
+    <a-card title="数据详情" :bordered="false" style="margin-top: 16px">
+      <BusinessDataTable
+        :columns="tableColumns"
+        :data-source="tableRows"
+        :pagination="{ pageSize: 10 }"
+        :scroll-x="'max-content'"
+      />
+    </a-card>
+  </div>
+</template>
+
+<script setup name="shorTermForecastYearlyReport">
+import { computed, onMounted, reactive, ref } from 'vue';
+import { message } from 'ant-design-vue';
+import dayjs from 'dayjs';
+import { saveAs } from 'file-saver';
+import { blobValidate } from '@/utils/bearjia';
+import { listStation } from '@/api/config/station';
+import { queryShortTermForecastReport, exportShortTermForecastReport } from '@/api/power/shortTermForecastReport';
+import BusinessDataTable from '../components/BusinessDataTable.vue';
+import StationSelector from '../components/StationSelector.vue';
+import { normalizeRows } from '../components/dataAdapter';
+
+const loading = ref(false);
+const exporting = ref(false);
+const stationOptions = ref([]);
+const tableRows = ref([]);
+
+const query = reactive({
+  stationId: undefined,
+  startTime: dayjs(),
+  endTime: dayjs(),
+});
+
+const tableColumns = [
+  { title: '时间', dataIndex: 'time' },
+  { title: '开机容量(MW)', dataIndex: 'operatingCapacity' },
+  { title: '实发功率(MW)', dataIndex: 'actualPower' },
+  { title: '预测功率(MW)', dataIndex: 'forecastPower' },
+  { title: '均方根差', dataIndex: 'rootMeanSquareError' },
+  { title: '平均绝对误差', dataIndex: 'meanAbsoluteError' },
+  { title: '相关性系数', dataIndex: 'correlationCoefficientR' },
+  { title: '最大误差合格率(%)', dataIndex: 'maximumErrorPassRate' },
+];
+
+const queryValid = computed(() => {
+  if (!query.stationId) return false;
+  if (!query.startTime || !query.endTime) return false;
+  return true;
+});
+
+const buildParams = () => {
+  const start = dayjs(query.startTime);
+  const end = dayjs(query.endTime);
+  return {
+    type: 'yearly',
+    entityId: String(query.stationId),
+    startTime: start.startOf('year').format('YYYY-MM-DD HH:mm:ss'),
+    endTime: end.endOf('year').format('YYYY-MM-DD HH:mm:ss'),
+  };
+};
+
+const handleQuery = async () => {
+  if (!query.stationId) {
+    message.warning('请先选择场站');
+    return;
+  }
+  if (!queryValid.value) {
+    return;
+  }
+  loading.value = true;
+  try {
+    const res = await queryShortTermForecastReport(buildParams());
+    tableRows.value = normalizeRows(res);
+  } finally {
+    loading.value = false;
+  }
+};
+
+const handleExport = async () => {
+  if (!query.stationId) {
+    message.warning('请先选择场站');
+    return;
+  }
+  if (!queryValid.value) {
+    return;
+  }
+  exporting.value = true;
+  try {
+    const res = await exportShortTermForecastReport(buildParams());
+    const isFile = await blobValidate(res);
+    if (isFile) {
+      const start = dayjs(query.startTime).format('YYYY');
+      const end = dayjs(query.endTime).format('YYYY');
+      saveAs(new Blob([res]), `短期预测年报-${start}-${end}.xlsx`);
+      message.success('导出成功');
+    } else {
+      const text = await res.text();
+      let msg = '导出失败';
+      try { msg = JSON.parse(text)?.msg || msg; } catch (e) { /* ignore */ }
+      message.error(msg);
+    }
+  } finally {
+    exporting.value = false;
+  }
+};
+
+async function loadStationOptions() {
+  try {
+    const res = await listStation({ pageNum: 1, pageSize: 500 });
+    const rows = normalizeRows(res);
+    stationOptions.value = rows.map((item, index) => ({
+      label: item.stationName || item.name || item.entityName || item.siteName || '未知场站',
+      value: item.id || item.stationId || item.entityId || `station-${index + 1}`,
+    }));
+    if (!query.stationId && stationOptions.value.length) {
+      query.stationId = stationOptions.value[0].value;
+    }
+  } catch (e) {
+    /* ignore */
+  }
+}
+
+onMounted(async () => {
+  await loadStationOptions();
+  await handleQuery();
+});
+</script>
+
+<style lang="less" scoped>
+.shor-term-forecast-yearly-page {
+  padding: 16px;
+}
+.full-control {
+  width: 100%;
+}
+</style>

+ 22 - 1
release_note/2026.09.17/20260917_dp.sql

@@ -3,4 +3,25 @@ UPDATE "public"."sys_menu" set status = 1 where menu_name in ('多源多模型
 
 -- data_weather_local 斜面辐照度字段 -> 总辐照度
 ALTER TABLE "public"."data_weather_local" RENAME COLUMN "inclined_irradiance" TO "irradiance";
-COMMENT ON COLUMN "public"."data_weather_local"."irradiance" IS '总辐照度,单位 W/m²';
+COMMENT ON COLUMN "public"."data_weather_local"."irradiance" IS '总辐照度,单位 W/m²';
+
+-- =============================================================================
+-- 任务编号 2026090805  增加"短期预测报表"功能
+-- =============================================================================
+
+-- 1. sys_menu 增加菜单: 短期预测日报 (id=2079, parent_id=2007)
+INSERT INTO "sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "route_name", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark")
+VALUES (2079, '短期预测日报', 2007, 5, 'short-term-forecast-daily', 'ufo/datareport/shorTermForecastDailyReport', '', 'shorTermForecastDailyReport', 1, 0, 'C', '0', '0', 'data:shortTermPowerForecastReport:list', 'file-text', 'admin', now(), '', NULL, '短期预测日报菜单');
+
+-- 2. sys_menu 增加菜单: 短期预测月报 (id=2080, parent_id=2007)
+INSERT INTO "sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "route_name", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark")
+VALUES (2080, '短期预测月报', 2007, 6, 'short-term-forecast-monthly', 'ufo/datareport/shorTermForecastMonthlyReport', '', 'shorTermForecastMonthlyReport', 1, 0, 'C', '0', '0', 'data:shortTermPowerForecastReport:list', 'file-text', 'admin', now(), '', NULL, '短期预测月报菜单');
+
+-- 3. sys_menu 增加菜单: 短期预测年报 (id=2081, parent_id=2007)
+INSERT INTO "sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "route_name", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark")
+VALUES (2081, '短期预测年报', 2007, 7, 'short-term-forecast-yearly', 'ufo/datareport/shorTermForecastYearlyReport', '', 'shorTermForecastYearlyReport', 1, 0, 'C', '0', '0', 'data:shortTermPowerForecastReport:list', 'file-text', 'admin', now(), '', NULL, '短期预测年报菜单');
+
+-- 4. sys_role_menu 增加角色-菜单关联 (role_id=1)
+INSERT INTO sys_role_menu (role_id, menu_id) VALUES (1, 2079);
+INSERT INTO sys_role_menu (role_id, menu_id) VALUES (1, 2080);
+INSERT INTO sys_role_menu (role_id, menu_id) VALUES (1, 2081);