|
|
@@ -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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|