Quellcode durchsuchen

[101904] 上报批次 list/confirm/create 接口及批次表 DDL/字典

taosj vor 2 Wochen
Ursprung
Commit
7278fb1b65

+ 149 - 0
forecast-backend-server/src/main/java/com/ufo/project/forecast/fileupload/controller/DataPowerForecastReportBatchController.java

@@ -0,0 +1,149 @@
+package com.ufo.project.forecast.fileupload.controller;
+
+import java.text.SimpleDateFormat;
+import java.util.List;
+import com.alibaba.fastjson2.JSONObject;
+import com.github.pagehelper.PageHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ufo.base.common.utils.StringUtils;
+import com.ufo.base.framework.aspectj.lang.annotation.Log;
+import com.ufo.base.framework.aspectj.lang.enums.BusinessType;
+import com.ufo.base.framework.web.controller.BaseController;
+import com.ufo.base.framework.web.domain.AjaxResult;
+import com.ufo.base.framework.web.page.TableDataInfo;
+import com.ufo.project.forecast.fileupload.domain.DataPowerForecastReportBatch;
+import com.ufo.project.forecast.fileupload.service.IDataPowerForecastReportBatchService;
+import com.ufo.project.forecast.processor.ForecastProcessorFactory;
+
+/**
+ * 功率预测上报批次Controller
+ *
+ * @author ufo
+ * @date 2026-10-20
+ */
+@RestController
+@RequestMapping("/power/forecastReportBatch")
+public class DataPowerForecastReportBatchController extends BaseController
+{
+    @Autowired
+    private IDataPowerForecastReportBatchService dataPowerForecastReportBatchService;
+
+    @Autowired
+    private ForecastProcessorFactory forecastProcessorFactory;
+
+    /**
+     * 查询功率预测上报批次列表(分页)
+     */
+    @PreAuthorize("@ss.hasPermi('power:forecastReportBatch:list')")
+    @PostMapping("/list")
+    public TableDataInfo list(@RequestBody JSONObject params)
+    {
+        DataPowerForecastReportBatch query = new DataPowerForecastReportBatch();
+        query.setStationCode(params.getString("stationCode"));
+        query.setType(params.getString("type"));
+        query.setStartDay(parseDay(params.getString("startTime")));
+        query.setEndDay(parseDay(params.getString("endTime")));
+        PageHelper.startPage(params.getIntValue("pageNum", 1), params.getIntValue("pageSize", 10));
+        List<DataPowerForecastReportBatch> list = dataPowerForecastReportBatchService.selectDataPowerForecastReportBatchList(query);
+        return getDataTable(list);
+    }
+
+    /**
+     * 确认功率预测上报批次
+     */
+    @PreAuthorize("@ss.hasPermi('power:forecastReportBatch:edit')")
+    @Log(title = "功率预测上报批次", businessType = BusinessType.UPDATE)
+    @PostMapping("/confirm/{batchNo}")
+    public AjaxResult confirm(@PathVariable("batchNo") String batchNo)
+    {
+        DataPowerForecastReportBatch batch = dataPowerForecastReportBatchService.selectByBatchNo(batchNo);
+        if (batch == null)
+        {
+            return AjaxResult.error("上报批次不存在");
+        }
+        if (!Integer.valueOf(DataPowerForecastReportBatch.STATUS_PENDING).equals(batch.getStatus()))
+        {
+            return AjaxResult.error("上报批次已确认, 请勿重复操作");
+        }
+        DataPowerForecastReportBatch update = new DataPowerForecastReportBatch();
+        update.setId(batch.getId());
+        update.setStatus(DataPowerForecastReportBatch.STATUS_CONFIRMED);
+        dataPowerForecastReportBatchService.updateDataPowerForecastReportBatch(update);
+        return AjaxResult.success();
+    }
+
+    /**
+     * 新增功率预测上报批次并初始化上报数据
+     */
+    @PreAuthorize("@ss.hasPermi('power:forecastReportBatch:add')")
+    @Log(title = "功率预测上报批次", businessType = BusinessType.INSERT)
+    @PostMapping("/create")
+    public AjaxResult create(@RequestBody JSONObject params)
+    {
+        String stationCode = params.getString("stationCode");
+        String stationName = params.getString("stationName");
+        String batchNo = params.getString("batchNo");
+        String type = params.getString("type");
+        String reportTime = params.getString("reportTime");
+        if (StringUtils.isEmpty(stationCode) || StringUtils.isEmpty(batchNo)
+                || StringUtils.isEmpty(type) || StringUtils.isEmpty(reportTime))
+        {
+            return AjaxResult.error("参数不完整");
+        }
+        try
+        {
+            SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            fmt.setLenient(false);
+            fmt.parse(reportTime);
+        }
+        catch (Exception e)
+        {
+            return AjaxResult.error("上报时间格式错误, 应为 yyyy-MM-dd HH:mm:ss");
+        }
+        int reportDay = Integer.parseInt(reportTime.substring(0, 10).replace("-", ""));
+        String estReportTime = reportTime.substring(11, 19);
+        boolean exists = dataPowerForecastReportBatchService.selectByTypeDayTime(type, reportDay, estReportTime)
+                .stream().anyMatch(b -> stationCode.equals(b.getStationCode()));
+        if (exists)
+        {
+            return AjaxResult.error("该时点批次已存在");
+        }
+        DataPowerForecastReportBatch batch = new DataPowerForecastReportBatch();
+        batch.setStationCode(stationCode);
+        batch.setStationName(stationName);
+        batch.setBatchNo(batchNo);
+        batch.setType(type);
+        batch.setReportDay(reportDay);
+        batch.setEstReportTime(estReportTime);
+        batch.setStatus(DataPowerForecastReportBatch.STATUS_PENDING);
+        batch.setGenerateSource("manually");
+        dataPowerForecastReportBatchService.insertDataPowerForecastReportBatch(batch);
+        forecastProcessorFactory.getInstant(type).initData(reportDay, estReportTime);
+        return AjaxResult.success();
+    }
+
+    /**
+     * 将 yyyy-MM-dd 解析为 yyyyMMdd, 空值或非法值返回 null
+     */
+    private Integer parseDay(String date)
+    {
+        if (StringUtils.isEmpty(date))
+        {
+            return null;
+        }
+        try
+        {
+            return Integer.parseInt(date.replace("-", ""));
+        }
+        catch (NumberFormatException e)
+        {
+            return null;
+        }
+    }
+}

+ 24 - 0
forecast-backend-server/src/main/java/com/ufo/project/forecast/fileupload/domain/DataPowerForecastReportBatch.java

@@ -60,6 +60,12 @@ public class DataPowerForecastReportBatch
     /** 备注 */
     private String remark;
 
+    /** 上报日起始(查询用, yyyyMMdd) */
+    private Integer startDay;
+
+    /** 上报日截止(查询用, yyyyMMdd) */
+    private Integer endDay;
+
     public void setId(Long id)
     {
         this.id = id;
@@ -168,6 +174,24 @@ public class DataPowerForecastReportBatch
     {
         return remark;
     }
+    public void setStartDay(Integer startDay)
+    {
+        this.startDay = startDay;
+    }
+
+    public Integer getStartDay()
+    {
+        return startDay;
+    }
+    public void setEndDay(Integer endDay)
+    {
+        this.endDay = endDay;
+    }
+
+    public Integer getEndDay()
+    {
+        return endDay;
+    }
 
     @Override
     public String toString() {

+ 16 - 0
forecast-backend-server/src/main/java/com/ufo/project/forecast/fileupload/mapper/DataPowerForecastReportBatchMapper.java

@@ -46,6 +46,22 @@ public interface DataPowerForecastReportBatchMapper
      */
     public int insertDataPowerForecastReportBatch(DataPowerForecastReportBatch dataPowerForecastReportBatch);
 
+    /**
+     * 按上报批次号查询功率预测上报批次
+     *
+     * @param batchNo 上报批次号
+     * @return 功率预测上报批次
+     */
+    public DataPowerForecastReportBatch selectByBatchNo(String batchNo);
+
+    /**
+     * 修改功率预测上报批次
+     *
+     * @param dataPowerForecastReportBatch 功率预测上报批次
+     * @return 结果
+     */
+    public int updateDataPowerForecastReportBatch(DataPowerForecastReportBatch dataPowerForecastReportBatch);
+
     /**
      * 批量删除功率预测上报批次
      *

+ 16 - 0
forecast-backend-server/src/main/java/com/ufo/project/forecast/fileupload/service/IDataPowerForecastReportBatchService.java

@@ -36,4 +36,20 @@ public interface IDataPowerForecastReportBatchService
      * @return 结果
      */
     public int insertDataPowerForecastReportBatch(DataPowerForecastReportBatch dataPowerForecastReportBatch);
+
+    /**
+     * 按上报批次号查询功率预测上报批次
+     *
+     * @param batchNo 上报批次号
+     * @return 功率预测上报批次
+     */
+    public DataPowerForecastReportBatch selectByBatchNo(String batchNo);
+
+    /**
+     * 修改功率预测上报批次
+     *
+     * @param dataPowerForecastReportBatch 功率预测上报批次
+     * @return 结果
+     */
+    public int updateDataPowerForecastReportBatch(DataPowerForecastReportBatch dataPowerForecastReportBatch);
 }

+ 24 - 0
forecast-backend-server/src/main/java/com/ufo/project/forecast/fileupload/service/impl/DataPowerForecastReportBatchServiceImpl.java

@@ -56,4 +56,28 @@ public class DataPowerForecastReportBatchServiceImpl implements IDataPowerForeca
     {
         return dataPowerForecastReportBatchMapper.insertDataPowerForecastReportBatch(dataPowerForecastReportBatch);
     }
+
+    /**
+     * 按上报批次号查询功率预测上报批次
+     *
+     * @param batchNo 上报批次号
+     * @return 功率预测上报批次
+     */
+    @Override
+    public DataPowerForecastReportBatch selectByBatchNo(String batchNo)
+    {
+        return dataPowerForecastReportBatchMapper.selectByBatchNo(batchNo);
+    }
+
+    /**
+     * 修改功率预测上报批次
+     *
+     * @param dataPowerForecastReportBatch 功率预测上报批次
+     * @return 结果
+     */
+    @Override
+    public int updateDataPowerForecastReportBatch(DataPowerForecastReportBatch dataPowerForecastReportBatch)
+    {
+        return dataPowerForecastReportBatchMapper.updateDataPowerForecastReportBatch(dataPowerForecastReportBatch);
+    }
 }

+ 25 - 0
forecast-backend-server/src/main/resources/mybatis/fileupload/DataPowerForecastReportBatchMapper.xml

@@ -31,6 +31,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="batchNo != null  and batchNo != ''"> and batch_no = #{batchNo}</if>
             <if test="type != null  and type != ''"> and type = #{type}</if>
             <if test="reportDay != null "> and report_day = #{reportDay}</if>
+            <if test="estReportTime != null  and estReportTime != ''"> and est_report_time = #{estReportTime}</if>
+            <if test="startDay != null "> and report_day &gt;= #{startDay}</if>
+            <if test="endDay != null "> and report_day &lt;= #{endDay}</if>
             <if test="status != null "> and status = #{status}</if>
         </where>
         order by id desc
@@ -46,6 +49,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where type = #{type} and report_day = #{reportDay} and est_report_time = #{estReportTime}
     </select>
 
+    <select id="selectByBatchNo" resultMap="DataPowerForecastReportBatchResult">
+        <include refid="selectDataPowerForecastReportBatchVo"/>
+        where batch_no = #{batchNo}
+    </select>
+
+    <update id="updateDataPowerForecastReportBatch" parameterType="DataPowerForecastReportBatch">
+        update data_power_forecast_report_batch
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="stationCode != null and stationCode != ''">station_code = #{stationCode},</if>
+            <if test="stationName != null">station_name = #{stationName},</if>
+            <if test="batchNo != null and batchNo != ''">batch_no = #{batchNo},</if>
+            <if test="type != null and type != ''">type = #{type},</if>
+            <if test="reportDay != null ">report_day = #{reportDay},</if>
+            <if test="estReportTime != null and estReportTime != ''">est_report_time = #{estReportTime},</if>
+            <if test="status != null ">status = #{status},</if>
+            <if test="generateSource != null and generateSource != ''">generate_source = #{generateSource},</if>
+            <if test="remark != null">remark = #{remark},</if>
+            update_time = now()
+        </trim>
+        where id = #{id}
+    </update>
+
     <insert id="insertDataPowerForecastReportBatch" parameterType="DataPowerForecastReportBatch" useGeneratedKeys="true" keyProperty="id">
         insert into data_power_forecast_report_batch
             (station_code, station_name, batch_no, type, report_day, est_report_time, status, generate_source, create_time, update_time, remark)

+ 61 - 5
release_note/20261015/20261015_power_forecast_report_batch.sql

@@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS data_power_forecast_report_batch (
 );
 
 -- 单场站幂等保险(任务按 station_code + report_day + est_report_time + type 查重)
-CREATE UNIQUE INDEX IF NOT EXISTS uk_data_power_forecast_report_batch
+CREATE INDEX IF NOT EXISTS uk_data_power_forecast_report_batch
     ON data_power_forecast_report_batch (station_code, report_day, est_report_time, type);
 
 COMMENT ON TABLE data_power_forecast_report_batch IS '功率预测上报批次';
@@ -41,11 +41,67 @@ COMMENT ON COLUMN data_power_forecast_report_batch.remark IS '备注';
 -- -----------------------------------------------------
 -- 2. report 表加 batch_no 列(101901 统计查询按 batch_no is null 隔离)
 -- -----------------------------------------------------
-ALTER TABLE data_short_term_power_forecast_report ADD COLUMN IF NOT EXISTS batch_no VARCHAR(128);
-COMMENT ON COLUMN data_short_term_power_forecast_report.batch_no IS '上报批次号';
+-- 字段说明:batch_no VARCHAR(128) 上报批次号
 
-ALTER TABLE data_super_short_term_forecast_report ADD COLUMN IF NOT EXISTS batch_no VARCHAR(128);
-COMMENT ON COLUMN data_super_short_term_forecast_report.batch_no IS '上报批次号';
+DO $$
+BEGIN
+    -- 1. 添加字段(若不存在)
+    IF NOT EXISTS (
+        SELECT 1
+        FROM information_schema.columns
+        WHERE table_schema = current_schema()
+          AND table_name   = 'data_short_term_power_forecast_report'
+          AND column_name  = 'batch_no'
+    ) THEN
+        ALTER TABLE data_short_term_power_forecast_report
+            ADD COLUMN batch_no VARCHAR(128);
+
+        COMMENT ON COLUMN data_short_term_power_forecast_report.batch_no IS '上报批次号';
+    END IF;
+
+    -- 2. 创建索引(若不存在)
+    IF NOT EXISTS (
+        SELECT 1
+        FROM pg_indexes
+        WHERE schemaname = current_schema()
+          AND tablename  = 'data_short_term_power_forecast_report'
+          AND indexname  = 'idx_dstpfr_batch_no'
+    ) THEN
+        CREATE INDEX idx_dstpfr_batch_no
+            ON data_short_term_power_forecast_report (batch_no);
+    END IF;
+END
+$$;
+
+DO $$
+BEGIN
+    -- 1. 添加字段(若不存在)
+    IF NOT EXISTS (
+        SELECT 1
+        FROM information_schema.columns
+        WHERE table_schema = current_schema()
+          AND table_name   = 'data_super_short_term_forecast_report'
+          AND column_name  = 'batch_no'
+    ) THEN
+        ALTER TABLE data_super_short_term_forecast_report
+            ADD COLUMN batch_no VARCHAR(128);
+
+        COMMENT ON COLUMN data_super_short_term_forecast_report.batch_no IS '上报批次号';
+    END IF;
+
+    -- 2. 创建索引(若不存在)
+    IF NOT EXISTS (
+        SELECT 1
+        FROM pg_indexes
+        WHERE schemaname = current_schema()
+          AND tablename  = 'data_super_short_term_forecast_report'
+          AND indexname  = 'idx_dssstfr_batch_no'
+    ) THEN
+        CREATE INDEX idx_dssstfr_batch_no
+            ON data_super_short_term_forecast_report (batch_no);
+    END IF;
+END
+$$;
 
 -- -----------------------------------------------------
 -- 3. 字典配置项 power_forecast_report_batch_config