|
|
@@ -0,0 +1,1040 @@
|
|
|
+package com.ufo.project.theoretical.service.impl;
|
|
|
+
|
|
|
+import java.time.Instant;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.YearMonth;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.ufo.base.common.exception.ServiceException;
|
|
|
+import com.ufo.base.common.utils.DateUtils;
|
|
|
+import com.ufo.base.common.utils.DictUtils;
|
|
|
+import com.ufo.base.common.utils.StringUtils;
|
|
|
+import com.ufo.project.config.domain.ConfigStation;
|
|
|
+import com.ufo.project.config.mapper.ConfigStationMapper;
|
|
|
+import com.ufo.project.model.domain.DataElectricityLocal;
|
|
|
+import com.ufo.project.model.mapper.DataElectricityLocalMapper;
|
|
|
+import com.ufo.project.model.service.IDataElectricityLocalService;
|
|
|
+import com.ufo.project.theoretical.calc.TheoreticalPowerCalc;
|
|
|
+import com.ufo.project.theoretical.domain.CurtailedEnergyQuery;
|
|
|
+import com.ufo.project.theoretical.domain.CurtailedEnergyRow;
|
|
|
+import com.ufo.project.theoretical.domain.DailyReportQuery;
|
|
|
+import com.ufo.project.theoretical.domain.IntraPlantCheckRow;
|
|
|
+import com.ufo.project.theoretical.domain.LatestPowerRow;
|
|
|
+import com.ufo.project.theoretical.domain.LatestQuery;
|
|
|
+import com.ufo.project.theoretical.domain.LogicCheckRow;
|
|
|
+import com.ufo.project.theoretical.domain.MonthlyReportQuery;
|
|
|
+import com.ufo.project.theoretical.domain.OffSiteCheckRow;
|
|
|
+import com.ufo.project.theoretical.domain.PowerCheckQuery;
|
|
|
+import com.ufo.project.theoretical.domain.ReportRow;
|
|
|
+import com.ufo.project.theoretical.domain.TheoreticalEnergyRow;
|
|
|
+import com.ufo.project.theoretical.domain.TheoreticalPowerQuery;
|
|
|
+import com.ufo.project.theoretical.domain.TheoreticalPowerRow;
|
|
|
+import com.ufo.project.theoretical.service.ITheoreticalPowerService;
|
|
|
+import com.ufo.project.weather.domain.DataWeatherLocal;
|
|
|
+import com.ufo.project.weather.mapper.DataWeatherLocalMapper;
|
|
|
+import com.ufo.project.weather.service.IDataWeatherLocalService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 光伏理论功率Service实现
|
|
|
+ * <p>口径来源:aicoding/26111301.md 与 docs/superpowers/specs/2026-11-16-theoretical-power-design.md</p>
|
|
|
+ *
|
|
|
+ * @author ufo
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class TheoreticalPowerServiceImpl implements ITheoreticalPowerService
|
|
|
+{
|
|
|
+ /** 时区(timestamptz +08:00) */
|
|
|
+ private static final ZoneOffset ZONE = ZoneOffset.ofHours(8);
|
|
|
+
|
|
|
+ /** 网格时间(HH:mm) */
|
|
|
+ private static final DateTimeFormatter HHMM = DateTimeFormatter.ofPattern("HH:mm");
|
|
|
+
|
|
|
+ /** 时间(yyyy-MM-dd HH:mm:ss) */
|
|
|
+ private static final DateTimeFormatter DATETIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ /** 测光法字典 */
|
|
|
+ private static final String DICT_ALGORITHM_CONFIG = "algorithm_config";
|
|
|
+ private static final String DICT_LABEL_PHOTOMETRIC = "测光法配置";
|
|
|
+
|
|
|
+ /** 校核阈值字典 */
|
|
|
+ private static final String DICT_POWER_CONFIG = "theoretical_power_config";
|
|
|
+ private static final String DICT_LABEL_POWER_CONFIG = "理论功率配置项";
|
|
|
+
|
|
|
+ /** dataType 取值 */
|
|
|
+ private static final String DATA_TYPE_SAMPLE = "sampleMachine";
|
|
|
+ private static final String DATA_TYPE_PHOTOMETRIC = "photometricMethod";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ConfigStationMapper configStationMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDataElectricityLocalService dataElectricityLocalService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDataWeatherLocalService dataWeatherLocalService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DataElectricityLocalMapper dataElectricityLocalMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DataWeatherLocalMapper dataWeatherLocalMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3.2.1/3.2.2 光伏理论功率列表(时间网格,双方法同构)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<TheoreticalPowerRow> selectPowerList(TheoreticalPowerQuery query)
|
|
|
+ {
|
|
|
+ ConfigStation station = loadStation(query.getStationCode());
|
|
|
+ String day = requireDay(query.getDay());
|
|
|
+ int freq = requireFrequency(query.getSamplingFrequency());
|
|
|
+ List<DataElectricityLocal> power = loadSingleDayPower(station, day);
|
|
|
+ List<DataWeatherLocal> weather = loadSingleDayWeather(station, day);
|
|
|
+ double a1 = getPhotometricA1();
|
|
|
+ double a2 = getPhotometricA2();
|
|
|
+ Integer n = station.getInverterQuantity();
|
|
|
+
|
|
|
+ List<double[]> actual = rawPoints(power, DataElectricityLocal::getActualPower);
|
|
|
+ List<double[]> availability = rawPoints(power, DataElectricityLocal::getAvailability);
|
|
|
+ List<double[]> irr = rawPoints(weather, DataWeatherLocal::getIrradiance);
|
|
|
+ List<double[]> inclined = rawPoints(weather, DataWeatherLocal::getInclinedIrradiance);
|
|
|
+ List<double[]> temp = rawPoints(weather, DataWeatherLocal::getTemperature);
|
|
|
+
|
|
|
+ List<TheoreticalPowerRow> rows = new ArrayList<>();
|
|
|
+ for (long sec = dayStartEpoch(day); sec < dayStartEpoch(day) + 86400L; sec += freq * 60L)
|
|
|
+ {
|
|
|
+ double avail = TheoreticalPowerCalc.samplePoint(availability, sec, freq);
|
|
|
+ if (avail == 0)
|
|
|
+ {
|
|
|
+ avail = 100;
|
|
|
+ }
|
|
|
+ double photometric = TheoreticalPowerCalc.photometricPower(n, a1, a2,
|
|
|
+ (double) TheoreticalPowerCalc.samplePoint(irr, sec, freq),
|
|
|
+ (double) TheoreticalPowerCalc.samplePoint(inclined, sec, freq),
|
|
|
+ (double) TheoreticalPowerCalc.samplePoint(temp, sec, freq));
|
|
|
+ TheoreticalPowerRow row = new TheoreticalPowerRow();
|
|
|
+ row.setTime(Instant.ofEpochSecond(sec).atOffset(ZONE).format(HHMM));
|
|
|
+ row.setPower(round3(TheoreticalPowerCalc.samplePoint(actual, sec, freq)));
|
|
|
+ row.setSampleMachineTheoreticalPower(0D);
|
|
|
+ row.setSampleMachineAvailablePower(0D);
|
|
|
+ row.setPhotometricMethodTheoreticalPower(round3(photometric));
|
|
|
+ row.setPhotometricMethodAvailablePower(round3(TheoreticalPowerCalc.availablePower(photometric, (double) avail)));
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3.2.3 光伏理论发电量列表(原始采集点逐行,双方法同构)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<TheoreticalEnergyRow> selectEnergyList(TheoreticalPowerQuery query)
|
|
|
+ {
|
|
|
+ ConfigStation station = loadStation(query.getStationCode());
|
|
|
+ String day = requireDay(query.getDay());
|
|
|
+ List<DataElectricityLocal> power = loadSingleDayPower(station, day);
|
|
|
+ if (power.isEmpty())
|
|
|
+ {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<DataWeatherLocal> weather = loadSingleDayWeather(station, day);
|
|
|
+ double a1 = getPhotometricA1();
|
|
|
+ double a2 = getPhotometricA2();
|
|
|
+ Integer n = station.getInverterQuantity();
|
|
|
+
|
|
|
+ long dayEnd = dayStartEpoch(day) + 86400L;
|
|
|
+ List<double[]> actual = rawPoints(power, DataElectricityLocal::getActualPower);
|
|
|
+ List<double[]> availability = rawPoints(power, DataElectricityLocal::getAvailability);
|
|
|
+ List<double[]> irr = rawPoints(weather, DataWeatherLocal::getIrradiance);
|
|
|
+ List<double[]> inclined = rawPoints(weather, DataWeatherLocal::getInclinedIrradiance);
|
|
|
+ List<double[]> temp = rawPoints(weather, DataWeatherLocal::getTemperature);
|
|
|
+
|
|
|
+ int size = power.size();
|
|
|
+ double[] photometricSeries = new double[size];
|
|
|
+ double[] photometricAvailableSeries = new double[size];
|
|
|
+ for (int i = 0; i < size; i++)
|
|
|
+ {
|
|
|
+ long sec = epochSec(power.get(i).getTm());
|
|
|
+ double avail = sampleAt(availability, sec, 5);
|
|
|
+ if (avail == 0)
|
|
|
+ {
|
|
|
+ avail = 100;
|
|
|
+ }
|
|
|
+ double p = TheoreticalPowerCalc.photometricPower(n, a1, a2,
|
|
|
+ (double) sampleAt(irr, sec, 5),
|
|
|
+ (double) sampleAt(inclined, sec, 5),
|
|
|
+ (double) sampleAt(temp, sec, 5));
|
|
|
+ photometricSeries[i] = p;
|
|
|
+ photometricAvailableSeries[i] = TheoreticalPowerCalc.availablePower(p, (double) avail);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 样板法理论功率本版本恒 0,累计电量恒 0;累计值逐点前缀求和
|
|
|
+ double[] actualEnergy = cumulative(actual, dayEnd);
|
|
|
+ double[] photometricEnergy = cumulative(photometricSeries, dayEnd, power);
|
|
|
+ double[] photometricAvailableEnergy = cumulative(photometricAvailableSeries, dayEnd, power);
|
|
|
+
|
|
|
+ List<TheoreticalEnergyRow> rows = new ArrayList<>();
|
|
|
+ for (int i = 0; i < size; i++)
|
|
|
+ {
|
|
|
+ TheoreticalEnergyRow row = new TheoreticalEnergyRow();
|
|
|
+ row.setTime(DATETIME.format(Instant.ofEpochSecond(epochSec(power.get(i).getTm())).atOffset(ZONE)));
|
|
|
+ row.setEnergy(round3(actualEnergy[i]));
|
|
|
+ row.setSampleMachineTheoreticalEnergy(0D);
|
|
|
+ row.setSampleMachineAvailableEnergy(0D);
|
|
|
+ row.setPhotometricMethodTheoreticalEnergy(round3(photometricEnergy[i]));
|
|
|
+ row.setPhotometricMethodAvailableEnergy(round3(photometricAvailableEnergy[i]));
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3.3.3 实时数据(该场站全库 tm 最大一条,双方法 + 开机容量)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public LatestPowerRow selectLatest(LatestQuery query)
|
|
|
+ {
|
|
|
+ ConfigStation station = loadStation(query.getStationCode());
|
|
|
+ List<DataElectricityLocal> power = dataElectricityLocalService.selectActualPowerRange(
|
|
|
+ station.getId(), "2000-01-01", "2099-12-31");
|
|
|
+ if (power.isEmpty())
|
|
|
+ {
|
|
|
+ throw new ServiceException("该场站暂无数据");
|
|
|
+ }
|
|
|
+ DataElectricityLocal last = power.get(power.size() - 1);
|
|
|
+ long sec = epochSec(last.getTm());
|
|
|
+ String day = DateUtils.parseDateToStr("yyyy-MM-dd", last.getTm());
|
|
|
+ List<DataWeatherLocal> weather = loadSingleDayWeather(station, day);
|
|
|
+
|
|
|
+ double a1 = getPhotometricA1();
|
|
|
+ double a2 = getPhotometricA2();
|
|
|
+ Integer n = station.getInverterQuantity();
|
|
|
+ double actualPower = last.getActualPower() == null ? 0 : last.getActualPower();
|
|
|
+ double availability = last.getAvailability() == null || last.getAvailability() == 0 ? 100
|
|
|
+ : last.getAvailability();
|
|
|
+ double photometric = TheoreticalPowerCalc.photometricPower(n, a1, a2,
|
|
|
+ (double) sampleAt(rawPoints(weather, DataWeatherLocal::getIrradiance), sec, 5),
|
|
|
+ (double) sampleAt(rawPoints(weather, DataWeatherLocal::getInclinedIrradiance), sec, 5),
|
|
|
+ (double) sampleAt(rawPoints(weather, DataWeatherLocal::getTemperature), sec, 5));
|
|
|
+
|
|
|
+ LatestPowerRow row = new LatestPowerRow();
|
|
|
+ row.setTime(DATETIME.format(Instant.ofEpochSecond(sec).atOffset(ZONE)));
|
|
|
+ row.setPower(round3(actualPower));
|
|
|
+ row.setSampleMachineTheoreticalPower(0D);
|
|
|
+ row.setSampleMachineAvailablePower(0D);
|
|
|
+ row.setPhotometricMethodTheoreticalPower(round3(photometric));
|
|
|
+ row.setPhotometricMethodAvailablePower(round3(TheoreticalPowerCalc.availablePower(photometric, availability)));
|
|
|
+ row.setInstalledCapacity(station.getInstalledCapacity() == null ? 0D : station.getInstalledCapacity().doubleValue());
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3.3.1/3.3.2 光伏受阻电量列表(原始采集点逐行,逐点累计;场内=理论−可用,场外=可用−实际,总=场内+场外)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CurtailedEnergyRow> selectCurtailedEnergyList(CurtailedEnergyQuery query)
|
|
|
+ {
|
|
|
+ ConfigStation station = loadStation(query.getStationCode());
|
|
|
+ String dataType = requireDataType(query.getDataType());
|
|
|
+ String day = requireDay(query.getDay());
|
|
|
+ List<DataElectricityLocal> power = loadSingleDayPower(station, day);
|
|
|
+ if (power.isEmpty())
|
|
|
+ {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<DataWeatherLocal> weather = loadSingleDayWeather(station, day);
|
|
|
+ double a1 = getPhotometricA1();
|
|
|
+ double a2 = getPhotometricA2();
|
|
|
+ Integer n = station.getInverterQuantity();
|
|
|
+
|
|
|
+ long dayEnd = dayStartEpoch(day) + 86400L;
|
|
|
+ List<double[]> actual = rawPoints(power, DataElectricityLocal::getActualPower);
|
|
|
+ List<double[]> availability = rawPoints(power, DataElectricityLocal::getAvailability);
|
|
|
+ List<double[]> irr = rawPoints(weather, DataWeatherLocal::getIrradiance);
|
|
|
+ List<double[]> inclined = rawPoints(weather, DataWeatherLocal::getInclinedIrradiance);
|
|
|
+ List<double[]> temp = rawPoints(weather, DataWeatherLocal::getTemperature);
|
|
|
+
|
|
|
+ int size = power.size();
|
|
|
+ double[] intraSeries = new double[size];
|
|
|
+ double[] offSiteSeries = new double[size];
|
|
|
+ for (int i = 0; i < size; i++)
|
|
|
+ {
|
|
|
+ long sec = epochSec(power.get(i).getTm());
|
|
|
+ double avail = sampleAt(availability, sec, 5);
|
|
|
+ if (avail == 0)
|
|
|
+ {
|
|
|
+ avail = 100;
|
|
|
+ }
|
|
|
+ double theoretical = methodTheoretical(dataType, TheoreticalPowerCalc.photometricPower(n, a1, a2,
|
|
|
+ (double) sampleAt(irr, sec, 5),
|
|
|
+ (double) sampleAt(inclined, sec, 5),
|
|
|
+ (double) sampleAt(temp, sec, 5)));
|
|
|
+ double available = TheoreticalPowerCalc.availablePower(theoretical, avail);
|
|
|
+ double actualPower = actual.get(i)[1];
|
|
|
+ intraSeries[i] = theoretical - available;
|
|
|
+ offSiteSeries[i] = available - actualPower;
|
|
|
+ }
|
|
|
+
|
|
|
+ double[] intraEnergy = cumulative(intraSeries, dayEnd, power);
|
|
|
+ double[] offSiteEnergy = cumulative(offSiteSeries, dayEnd, power);
|
|
|
+ List<CurtailedEnergyRow> rows = new ArrayList<>();
|
|
|
+ for (int i = 0; i < size; i++)
|
|
|
+ {
|
|
|
+ CurtailedEnergyRow row = new CurtailedEnergyRow();
|
|
|
+ row.setTime(DATETIME.format(Instant.ofEpochSecond(epochSec(power.get(i).getTm())).atOffset(ZONE)));
|
|
|
+ row.setIntraPlantCurtailedEnergy(round3(intraEnergy[i]));
|
|
|
+ row.setOffSiteCurtailedEnergy(round3(offSiteEnergy[i]));
|
|
|
+ row.setTotalCurtailedEnergy(round3(intraEnergy[i] + offSiteEnergy[i]));
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3.4.1/3.4.2 光伏场站逻辑校核列表(5 分钟网格 288 点,三比值 2 位小数,按字典阈值判定)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<LogicCheckRow> selectLogicCheckList(PowerCheckQuery query)
|
|
|
+ {
|
|
|
+ ConfigStation station = loadStation(query.getStationCode());
|
|
|
+ String dataType = requireDataType(query.getDataType());
|
|
|
+ String day = requireDay(query.getDay());
|
|
|
+ List<DataElectricityLocal> power = loadSingleDayPower(station, day);
|
|
|
+ List<DataWeatherLocal> weather = loadSingleDayWeather(station, day);
|
|
|
+ double a1 = getPhotometricA1();
|
|
|
+ double a2 = getPhotometricA2();
|
|
|
+ Integer n = station.getInverterQuantity();
|
|
|
+ JSONObject config = loadPowerConfig();
|
|
|
+ double installed = station.getInstalledCapacity() == null ? 0D : station.getInstalledCapacity().doubleValue();
|
|
|
+
|
|
|
+ List<double[]> actual = rawPoints(power, DataElectricityLocal::getActualPower);
|
|
|
+ List<double[]> availability = rawPoints(power, DataElectricityLocal::getAvailability);
|
|
|
+ List<double[]> irr = rawPoints(weather, DataWeatherLocal::getIrradiance);
|
|
|
+ List<double[]> inclined = rawPoints(weather, DataWeatherLocal::getInclinedIrradiance);
|
|
|
+ List<double[]> temp = rawPoints(weather, DataWeatherLocal::getTemperature);
|
|
|
+
|
|
|
+ List<LogicCheckRow> rows = new ArrayList<>();
|
|
|
+ for (long sec = dayStartEpoch(day); sec < dayStartEpoch(day) + 86400L; sec += 300L)
|
|
|
+ {
|
|
|
+ double avail = sampleAt(availability, sec, 5);
|
|
|
+ if (avail == 0)
|
|
|
+ {
|
|
|
+ avail = 100;
|
|
|
+ }
|
|
|
+ double theoretical = methodTheoretical(dataType, TheoreticalPowerCalc.photometricPower(n, a1, a2,
|
|
|
+ (double) sampleAt(irr, sec, 5),
|
|
|
+ (double) sampleAt(inclined, sec, 5),
|
|
|
+ (double) sampleAt(temp, sec, 5)));
|
|
|
+ double available = TheoreticalPowerCalc.availablePower(theoretical, avail);
|
|
|
+ double actualPower = sampleAt(actual, sec, 5);
|
|
|
+ double installed2Theoretical = round2(TheoreticalPowerCalc.ratio100(installed, theoretical));
|
|
|
+ double theoretical2Available = round2(TheoreticalPowerCalc.ratio100(theoretical, available));
|
|
|
+ double available2Actual = round2(TheoreticalPowerCalc.ratio100(available, actualPower));
|
|
|
+
|
|
|
+ LogicCheckRow row = new LogicCheckRow();
|
|
|
+ row.setTime(Instant.ofEpochSecond(sec).atOffset(ZONE).format(HHMM));
|
|
|
+ row.setInstalled2TheoreticalPercent(installed2Theoretical);
|
|
|
+ row.setInstalled2TheoreticalDesc(judge(installed2Theoretical, configPercent(config, "installed2TheoreticalPercent")));
|
|
|
+ row.setTheoretical2AvailablePercent(theoretical2Available);
|
|
|
+ row.setTheoretical2AvailableDesc(judge(theoretical2Available, configPercent(config, "theoretical2AvailablePercent")));
|
|
|
+ row.setAvailable2ActualPercent(available2Actual);
|
|
|
+ row.setAvailable2ActualDesc(judge(available2Actual, configPercent(config, "available2ActualPercent")));
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3.5.1/3.5.2 光伏场外受阻电力校核列表(5 分钟网格,MW 3 位小数,偏差=可用÷实发×100)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<OffSiteCheckRow> selectOffSiteCheckList(PowerCheckQuery query)
|
|
|
+ {
|
|
|
+ ConfigStation station = loadStation(query.getStationCode());
|
|
|
+ String dataType = requireDataType(query.getDataType());
|
|
|
+ String day = requireDay(query.getDay());
|
|
|
+ List<DataElectricityLocal> power = loadSingleDayPower(station, day);
|
|
|
+ List<DataWeatherLocal> weather = loadSingleDayWeather(station, day);
|
|
|
+ double a1 = getPhotometricA1();
|
|
|
+ double a2 = getPhotometricA2();
|
|
|
+ Integer n = station.getInverterQuantity();
|
|
|
+ JSONObject config = loadPowerConfig();
|
|
|
+
|
|
|
+ List<double[]> actual = rawPoints(power, DataElectricityLocal::getActualPower);
|
|
|
+ List<double[]> availability = rawPoints(power, DataElectricityLocal::getAvailability);
|
|
|
+ List<double[]> irr = rawPoints(weather, DataWeatherLocal::getIrradiance);
|
|
|
+ List<double[]> inclined = rawPoints(weather, DataWeatherLocal::getInclinedIrradiance);
|
|
|
+ List<double[]> temp = rawPoints(weather, DataWeatherLocal::getTemperature);
|
|
|
+
|
|
|
+ List<OffSiteCheckRow> rows = new ArrayList<>();
|
|
|
+ for (long sec = dayStartEpoch(day); sec < dayStartEpoch(day) + 86400L; sec += 300L)
|
|
|
+ {
|
|
|
+ double avail = sampleAt(availability, sec, 5);
|
|
|
+ if (avail == 0)
|
|
|
+ {
|
|
|
+ avail = 100;
|
|
|
+ }
|
|
|
+ double theoretical = methodTheoretical(dataType, TheoreticalPowerCalc.photometricPower(n, a1, a2,
|
|
|
+ (double) sampleAt(irr, sec, 5),
|
|
|
+ (double) sampleAt(inclined, sec, 5),
|
|
|
+ (double) sampleAt(temp, sec, 5)));
|
|
|
+ double available = TheoreticalPowerCalc.availablePower(theoretical, avail);
|
|
|
+ double actualPower = sampleAt(actual, sec, 5);
|
|
|
+ double deviation = round2(TheoreticalPowerCalc.ratio100(available, actualPower));
|
|
|
+
|
|
|
+ OffSiteCheckRow row = new OffSiteCheckRow();
|
|
|
+ row.setTime(Instant.ofEpochSecond(sec).atOffset(ZONE).format(HHMM));
|
|
|
+ row.setAvailablePower(round3(available / 1000));
|
|
|
+ row.setPower(round3(actualPower / 1000));
|
|
|
+ row.setDeviation(deviation);
|
|
|
+ row.setQualifiedDesc(judge(deviation, configPercent(config, "available2ActualPercent")));
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3.6.1/3.6.2 光伏场内受阻电力校核列表(5 分钟网格,MW 3 位小数,末行合计,偏差=理论÷可用×100)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<IntraPlantCheckRow> selectIntraPlantCheckList(PowerCheckQuery query)
|
|
|
+ {
|
|
|
+ ConfigStation station = loadStation(query.getStationCode());
|
|
|
+ String dataType = requireDataType(query.getDataType());
|
|
|
+ String day = requireDay(query.getDay());
|
|
|
+ List<DataElectricityLocal> power = loadSingleDayPower(station, day);
|
|
|
+ List<DataWeatherLocal> weather = loadSingleDayWeather(station, day);
|
|
|
+ double a1 = getPhotometricA1();
|
|
|
+ double a2 = getPhotometricA2();
|
|
|
+ Integer n = station.getInverterQuantity();
|
|
|
+ JSONObject config = loadPowerConfig();
|
|
|
+
|
|
|
+ List<double[]> availability = rawPoints(power, DataElectricityLocal::getAvailability);
|
|
|
+ List<double[]> irr = rawPoints(weather, DataWeatherLocal::getIrradiance);
|
|
|
+ List<double[]> inclined = rawPoints(weather, DataWeatherLocal::getInclinedIrradiance);
|
|
|
+ List<double[]> temp = rawPoints(weather, DataWeatherLocal::getTemperature);
|
|
|
+
|
|
|
+ List<IntraPlantCheckRow> rows = new ArrayList<>();
|
|
|
+ double sumTheoretical = 0;
|
|
|
+ double sumAvailable = 0;
|
|
|
+ for (long sec = dayStartEpoch(day); sec < dayStartEpoch(day) + 86400L; sec += 300L)
|
|
|
+ {
|
|
|
+ double avail = sampleAt(availability, sec, 5);
|
|
|
+ if (avail == 0)
|
|
|
+ {
|
|
|
+ avail = 100;
|
|
|
+ }
|
|
|
+ double theoretical = methodTheoretical(dataType, TheoreticalPowerCalc.photometricPower(n, a1, a2,
|
|
|
+ (double) sampleAt(irr, sec, 5),
|
|
|
+ (double) sampleAt(inclined, sec, 5),
|
|
|
+ (double) sampleAt(temp, sec, 5)));
|
|
|
+ double available = TheoreticalPowerCalc.availablePower(theoretical, avail);
|
|
|
+ sumTheoretical += theoretical;
|
|
|
+ sumAvailable += available;
|
|
|
+ double deviation = round2(TheoreticalPowerCalc.ratio100(theoretical, available));
|
|
|
+
|
|
|
+ IntraPlantCheckRow row = new IntraPlantCheckRow();
|
|
|
+ row.setTime(Instant.ofEpochSecond(sec).atOffset(ZONE).format(HHMM));
|
|
|
+ row.setTheoreticalPower(round3(theoretical / 1000));
|
|
|
+ row.setAvailablePower(round3(available / 1000));
|
|
|
+ row.setDeviation(deviation);
|
|
|
+ row.setQualifiedDesc(judge(deviation, configPercent(config, "theoretical2AvailablePercent")));
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合计行:偏差按合计值重算
|
|
|
+ double totalDeviation = round2(TheoreticalPowerCalc.ratio100(sumTheoretical, sumAvailable));
|
|
|
+ IntraPlantCheckRow total = new IntraPlantCheckRow();
|
|
|
+ total.setTime("合计");
|
|
|
+ total.setTheoreticalPower(round3(sumTheoretical / 1000));
|
|
|
+ total.setAvailablePower(round3(sumAvailable / 1000));
|
|
|
+ total.setDeviation(totalDeviation);
|
|
|
+ total.setQualifiedDesc(judge(totalDeviation, configPercent(config, "theoretical2AvailablePercent")));
|
|
|
+ rows.add(total);
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3.7.1/3.7.2 光伏受阻电量日报(startDay..endDay 逐日一行 + 末行合计,keyset 分页加载)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ReportRow> selectDailyReportList(DailyReportQuery query)
|
|
|
+ {
|
|
|
+ ConfigStation station = loadStation(query.getStationCode());
|
|
|
+ String dataType = requireDataType(query.getDataType());
|
|
|
+ LocalDate start = parseDay(query.getStartDay());
|
|
|
+ LocalDate end = parseDay(query.getEndDay());
|
|
|
+ if (end.isBefore(start))
|
|
|
+ {
|
|
|
+ throw new ServiceException("endDay 不能早于 startDay");
|
|
|
+ }
|
|
|
+ if (ChronoUnit.DAYS.between(start, end) > 90)
|
|
|
+ {
|
|
|
+ throw new ServiceException("日报时间范围不能超过 90 天");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<LocalDate> days = new ArrayList<>();
|
|
|
+ for (LocalDate d = start; !d.isAfter(end); d = d.plusDays(1))
|
|
|
+ {
|
|
|
+ days.add(d);
|
|
|
+ }
|
|
|
+ double[][] sums = computeDaySeriesSums(station, dataType, days);
|
|
|
+
|
|
|
+ List<ReportRow> rows = new ArrayList<>();
|
|
|
+ double sumTheoretical = 0, sumAvailable = 0, sumEnergy = 0, sumIntra = 0, sumOffSite = 0;
|
|
|
+ for (int i = 0; i < days.size(); i++)
|
|
|
+ {
|
|
|
+ sumTheoretical += sums[0][i];
|
|
|
+ sumAvailable += sums[1][i];
|
|
|
+ sumEnergy += sums[2][i];
|
|
|
+ sumIntra += sums[3][i];
|
|
|
+ sumOffSite += sums[4][i];
|
|
|
+ rows.add(buildReportRow(days.get(i).toString(), sums[0][i], sums[1][i], sums[2][i], sums[3][i], sums[4][i]));
|
|
|
+ }
|
|
|
+ rows.add(buildReportRow("合计", sumTheoretical, sumAvailable, sumEnergy, sumIntra, sumOffSite));
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3.8.1/3.8.2 光伏受阻电量月报(先计算日、再按月求和 + 末行合计,keyset 分页加载)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ReportRow> selectMonthlyReportList(MonthlyReportQuery query)
|
|
|
+ {
|
|
|
+ ConfigStation station = loadStation(query.getStationCode());
|
|
|
+ String dataType = requireDataType(query.getDataType());
|
|
|
+ YearMonth start = parseMonth(query.getStartMonth());
|
|
|
+ YearMonth end = parseMonth(query.getEndMonth());
|
|
|
+ if (end.isBefore(start))
|
|
|
+ {
|
|
|
+ throw new ServiceException("endMonth 不能早于 startMonth");
|
|
|
+ }
|
|
|
+ if (ChronoUnit.MONTHS.between(start, end) > 12)
|
|
|
+ {
|
|
|
+ throw new ServiceException("月报时间范围不能超过 12 个月");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<LocalDate> days = new ArrayList<>();
|
|
|
+ for (LocalDate d = start.atDay(1); !d.isAfter(end.atEndOfMonth()); d = d.plusDays(1))
|
|
|
+ {
|
|
|
+ days.add(d);
|
|
|
+ }
|
|
|
+ double[][] sums = computeDaySeriesSums(station, dataType, days);
|
|
|
+
|
|
|
+ List<ReportRow> rows = new ArrayList<>();
|
|
|
+ double sumTheoretical = 0, sumAvailable = 0, sumEnergy = 0, sumIntra = 0, sumOffSite = 0;
|
|
|
+ int idx = 0;
|
|
|
+ for (YearMonth m = start; !m.isAfter(end); m = m.plusMonths(1))
|
|
|
+ {
|
|
|
+ LocalDate nextMonthFirst = m.plusMonths(1).atDay(1);
|
|
|
+ double mTheoretical = 0, mAvailable = 0, mEnergy = 0, mIntra = 0, mOffSite = 0;
|
|
|
+ while (idx < days.size() && days.get(idx).isBefore(nextMonthFirst))
|
|
|
+ {
|
|
|
+ mTheoretical += sums[0][idx];
|
|
|
+ mAvailable += sums[1][idx];
|
|
|
+ mEnergy += sums[2][idx];
|
|
|
+ mIntra += sums[3][idx];
|
|
|
+ mOffSite += sums[4][idx];
|
|
|
+ idx++;
|
|
|
+ }
|
|
|
+ sumTheoretical += mTheoretical;
|
|
|
+ sumAvailable += mAvailable;
|
|
|
+ sumEnergy += mEnergy;
|
|
|
+ sumIntra += mIntra;
|
|
|
+ sumOffSite += mOffSite;
|
|
|
+ rows.add(buildReportRow(m.toString(), mTheoretical, mAvailable, mEnergy, mIntra, mOffSite));
|
|
|
+ }
|
|
|
+ rows.add(buildReportRow("合计", sumTheoretical, sumAvailable, sumEnergy, sumIntra, sumOffSite));
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 私有方法 ====================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按场站编码加载场站,查不到抛异常
|
|
|
+ */
|
|
|
+ private ConfigStation loadStation(String stationCode)
|
|
|
+ {
|
|
|
+ if (StringUtils.isEmpty(stationCode))
|
|
|
+ {
|
|
|
+ throw new ServiceException("场站编码不能为空");
|
|
|
+ }
|
|
|
+ ConfigStation station = configStationMapper.selectConfigStationByCode(stationCode);
|
|
|
+ if (station == null)
|
|
|
+ {
|
|
|
+ throw new ServiceException("场站不存在:" + stationCode);
|
|
|
+ }
|
|
|
+ return station;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询指定日期全天(含当天)实发功率
|
|
|
+ */
|
|
|
+ private List<DataElectricityLocal> loadSingleDayPower(ConfigStation station, String day)
|
|
|
+ {
|
|
|
+ return dataElectricityLocalService.selectActualPowerRange(station.getId(), day, day);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询指定日期全天(含当天)气象采样
|
|
|
+ */
|
|
|
+ private List<DataWeatherLocal> loadSingleDayWeather(ConfigStation station, String day)
|
|
|
+ {
|
|
|
+ return dataWeatherLocalService.selectIrradianceRange(station.getId(), day, day);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校核日期参数
|
|
|
+ */
|
|
|
+ private String requireDay(String day)
|
|
|
+ {
|
|
|
+ if (StringUtils.isEmpty(day))
|
|
|
+ {
|
|
|
+ throw new ServiceException("日期不能为空");
|
|
|
+ }
|
|
|
+ return day;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校核采样频率(5/15 分钟)
|
|
|
+ */
|
|
|
+ private int requireFrequency(Integer freq)
|
|
|
+ {
|
|
|
+ if (freq == null || (freq != 5 && freq != 15))
|
|
|
+ {
|
|
|
+ throw new ServiceException("采样频率仅支持 5 或 15 分钟");
|
|
|
+ }
|
|
|
+ return freq;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取测光法系数 a1(字典 algorithm_config/测光法配置,缺失按 0)
|
|
|
+ */
|
|
|
+ private double getPhotometricA1()
|
|
|
+ {
|
|
|
+ String json = DictUtils.getDictValue(DICT_ALGORITHM_CONFIG, DICT_LABEL_PHOTOMETRIC);
|
|
|
+ if (StringUtils.isEmpty(json))
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ JSONObject obj = JSON.parseObject(json);
|
|
|
+ return obj.getDoubleValue("a1");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取测光法系数 a2(字典 algorithm_config/测光法配置,缺失按 0)
|
|
|
+ */
|
|
|
+ private double getPhotometricA2()
|
|
|
+ {
|
|
|
+ String json = DictUtils.getDictValue(DICT_ALGORITHM_CONFIG, DICT_LABEL_PHOTOMETRIC);
|
|
|
+ if (StringUtils.isEmpty(json))
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ JSONObject obj = JSON.parseObject(json);
|
|
|
+ return obj.getDoubleValue("a2");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日期当天 00:00(+08:00)epoch 秒
|
|
|
+ */
|
|
|
+ private long dayStartEpoch(String day)
|
|
|
+ {
|
|
|
+ return LocalDate.parse(day).atStartOfDay(ZONE).toEpochSecond();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Date → epoch 秒(+08:00)
|
|
|
+ */
|
|
|
+ private long epochSec(java.util.Date date)
|
|
|
+ {
|
|
|
+ return date.toInstant().atOffset(ZONE).toEpochSecond();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 升序原始点索引(epoch 秒,值;null 值按 0)
|
|
|
+ */
|
|
|
+ private List<double[]> rawPoints(List<DataElectricityLocal> list,
|
|
|
+ java.util.function.Function<DataElectricityLocal, Double> getter)
|
|
|
+ {
|
|
|
+ List<double[]> points = new ArrayList<>();
|
|
|
+ if (list != null)
|
|
|
+ {
|
|
|
+ for (DataElectricityLocal item : list)
|
|
|
+ {
|
|
|
+ Double val = getter.apply(item);
|
|
|
+ points.add(new double[] { epochSec(item.getTm()), val == null ? 0 : val });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return points;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 升序原始点索引(气象)
|
|
|
+ */
|
|
|
+ private List<double[]> rawPoints(List<DataWeatherLocal> list,
|
|
|
+ java.util.function.Function<DataWeatherLocal, Double> getter)
|
|
|
+ {
|
|
|
+ List<double[]> points = new ArrayList<>();
|
|
|
+ if (list != null)
|
|
|
+ {
|
|
|
+ for (DataWeatherLocal item : list)
|
|
|
+ {
|
|
|
+ Double val = getter.apply(item);
|
|
|
+ points.add(new double[] { epochSec(item.getTm()), val == null ? 0 : val });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return points;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 原始点时刻采样对齐(设计 §3.3,原始点场景窗口固定 5 分钟)
|
|
|
+ */
|
|
|
+ private double sampleAt(List<double[]> points, long sec, int deltaMin)
|
|
|
+ {
|
|
|
+ return TheoreticalPowerCalc.samplePoint(points, sec, deltaMin);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 逐点累计电量(万千瓦时):与原始点时刻对齐的升序序列 (t_i, p_i),
|
|
|
+ * E_i=(p_i+p_{i+1})/2×Δt_i 小时 (i<n);E_n=p_n×(dayEndSec−t_n) 小时;Σ kWh ÷ 10000
|
|
|
+ */
|
|
|
+ private double[] cumulative(List<double[]> points, long dayEnd)
|
|
|
+ {
|
|
|
+ int n = points.size();
|
|
|
+ double[] result = new double[n];
|
|
|
+ double sum = 0;
|
|
|
+ for (int i = 0; i < n; i++)
|
|
|
+ {
|
|
|
+ double delta;
|
|
|
+ if (i < n - 1)
|
|
|
+ {
|
|
|
+ delta = (points.get(i + 1)[0] - points.get(i)[0]) / 3600.0
|
|
|
+ * (points.get(i)[1] + points.get(i + 1)[1]) / 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ delta = dayEnd > points.get(i)[0]
|
|
|
+ ? (dayEnd - points.get(i)[0]) / 3600.0 * points.get(i)[1] : 0;
|
|
|
+ }
|
|
|
+ sum += delta / 10000;
|
|
|
+ result[i] = sum;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 逐点累计电量(万千瓦时,功率序列与原始点时刻一一对应)
|
|
|
+ */
|
|
|
+ private double[] cumulative(double[] series, long dayEnd, List<DataElectricityLocal> power)
|
|
|
+ {
|
|
|
+ int n = power.size();
|
|
|
+ double[] result = new double[n];
|
|
|
+ double sum = 0;
|
|
|
+ for (int i = 0; i < n; i++)
|
|
|
+ {
|
|
|
+ double delta;
|
|
|
+ if (i < n - 1)
|
|
|
+ {
|
|
|
+ double dt = epochSec(power.get(i + 1).getTm()) - epochSec(power.get(i).getTm());
|
|
|
+ delta = dt / 3600.0 * (series[i] + series[i + 1]) / 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ double dt = dayEnd - epochSec(power.get(i).getTm());
|
|
|
+ delta = dt > 0 ? dt / 3600.0 * series[i] : 0;
|
|
|
+ }
|
|
|
+ sum += delta / 10000;
|
|
|
+ result[i] = sum;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校核理论功率算法参数 dataType
|
|
|
+ */
|
|
|
+ private String requireDataType(String dataType)
|
|
|
+ {
|
|
|
+ if (StringUtils.isEmpty(dataType)
|
|
|
+ || (!DATA_TYPE_SAMPLE.equals(dataType) && !DATA_TYPE_PHOTOMETRIC.equals(dataType)))
|
|
|
+ {
|
|
|
+ throw new ServiceException("理论功率算法仅支持 sampleMachine 或 photometricMethod");
|
|
|
+ }
|
|
|
+ return dataType;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取校核阈值配置(字典 theoretical_power_config/理论功率配置项,缺失返回 null)
|
|
|
+ */
|
|
|
+ private JSONObject loadPowerConfig()
|
|
|
+ {
|
|
|
+ String json = DictUtils.getDictValue(DICT_POWER_CONFIG, DICT_LABEL_POWER_CONFIG);
|
|
|
+ if (StringUtils.isEmpty(json))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return JSON.parseObject(json);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从配置 JSON 取阈值百分比(缺失返回 null,判定时按合格处理)
|
|
|
+ */
|
|
|
+ private Double configPercent(JSONObject config, String key)
|
|
|
+ {
|
|
|
+ return config == null ? null : config.getDouble(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按算法取理论功率:样板法本版本恒 0,测光法取计算值
|
|
|
+ */
|
|
|
+ private double methodTheoretical(String dataType, double photometric)
|
|
|
+ {
|
|
|
+ return DATA_TYPE_SAMPLE.equals(dataType) ? 0 : photometric;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 百分比保留 2 位小数
|
|
|
+ */
|
|
|
+ private double round2(double v)
|
|
|
+ {
|
|
|
+ return TheoreticalPowerCalc.round(v, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校核判定:值 0(含分母为 0)显示 0.00 且合格;否则 ≥ 阈值合格(阈值缺失按合格)
|
|
|
+ */
|
|
|
+ private String judge(double value, Double threshold)
|
|
|
+ {
|
|
|
+ if (value == 0)
|
|
|
+ {
|
|
|
+ return "合格";
|
|
|
+ }
|
|
|
+ return threshold == null || value >= threshold ? "合格" : "不合格";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并解析日期(yyyy-MM-dd)
|
|
|
+ */
|
|
|
+ private LocalDate parseDay(String day)
|
|
|
+ {
|
|
|
+ if (StringUtils.isEmpty(day))
|
|
|
+ {
|
|
|
+ throw new ServiceException("日期不能为空");
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return LocalDate.parse(day);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ throw new ServiceException("日期格式不正确:" + day);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并解析月份(yyyy-MM)
|
|
|
+ */
|
|
|
+ private YearMonth parseMonth(String month)
|
|
|
+ {
|
|
|
+ if (StringUtils.isEmpty(month))
|
|
|
+ {
|
|
|
+ throw new ServiceException("月份不能为空");
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return YearMonth.parse(month);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ throw new ServiceException("月份格式不正确:" + month);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页(keyset 游标)加载功率采样数据,每页 2000 条,区间左闭右开
|
|
|
+ */
|
|
|
+ private List<DataElectricityLocal> loadElectricityPaged(Long stationId, String startIso, String endIsoExcl)
|
|
|
+ {
|
|
|
+ List<DataElectricityLocal> all = new ArrayList<>();
|
|
|
+ String lastTm = null;
|
|
|
+ Long lastStationId = null;
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ List<DataElectricityLocal> page = dataElectricityLocalMapper.selectElectricityPaged(
|
|
|
+ stationId, startIso, endIsoExcl, lastTm, lastStationId);
|
|
|
+ if (page == null || page.isEmpty())
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ all.addAll(page);
|
|
|
+ if (page.size() < 2000)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ lastTm = isoInstant(page.get(page.size() - 1).getTm());
|
|
|
+ lastStationId = stationId;
|
|
|
+ }
|
|
|
+ return all;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页(keyset 游标)加载气象采样数据,每页 2000 条,区间左闭右开
|
|
|
+ */
|
|
|
+ private List<DataWeatherLocal> loadWeatherPaged(Long stationId, String startIso, String endIsoExcl)
|
|
|
+ {
|
|
|
+ List<DataWeatherLocal> all = new ArrayList<>();
|
|
|
+ String lastTm = null;
|
|
|
+ Long lastStationId = null;
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ List<DataWeatherLocal> page = dataWeatherLocalMapper.selectWeatherPaged(
|
|
|
+ stationId, startIso, endIsoExcl, lastTm, lastStationId);
|
|
|
+ if (page == null || page.isEmpty())
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ all.addAll(page);
|
|
|
+ if (page.size() < 2000)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ lastTm = isoInstant(page.get(page.size() - 1).getTm());
|
|
|
+ lastStationId = stationId;
|
|
|
+ }
|
|
|
+ return all;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Date → ISO 8601 带时区字符串(keyset 游标,保留精确 tm)
|
|
|
+ */
|
|
|
+ private String isoInstant(java.util.Date date)
|
|
|
+ {
|
|
|
+ return date.toInstant().atOffset(ZONE).format(DateTimeFormatter.ISO_INSTANT);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 逐日 5 序列求和(万千瓦时):[0]理论 [1]可用 [2]实际 [3]场内=理论−可用 [4]场外=可用−实际
|
|
|
+ * 逐点计算各序列值后按 3.3.1 规则按日归集:同日相邻点梯形、当日最末点矩形延至当日 24:00,跨日不回填
|
|
|
+ */
|
|
|
+ private double[][] computeDaySeriesSums(ConfigStation station, String dataType, List<LocalDate> days)
|
|
|
+ {
|
|
|
+ String startIso = days.get(0).toString() + "T00:00:00+08:00";
|
|
|
+ String endIsoExcl = days.get(days.size() - 1).plusDays(1).toString() + "T00:00:00+08:00";
|
|
|
+ List<DataElectricityLocal> power = loadElectricityPaged(station.getId(), startIso, endIsoExcl);
|
|
|
+ List<DataWeatherLocal> weather = loadWeatherPaged(station.getId(), startIso, endIsoExcl);
|
|
|
+ double a1 = getPhotometricA1();
|
|
|
+ double a2 = getPhotometricA2();
|
|
|
+ Integer n = station.getInverterQuantity();
|
|
|
+
|
|
|
+ int dayCount = days.size();
|
|
|
+ long firstDayStart = days.get(0).atStartOfDay(ZONE).toEpochSecond();
|
|
|
+ int size = power.size();
|
|
|
+ int[] dayIndex = new int[size];
|
|
|
+ double[][] series = new double[5][size];
|
|
|
+
|
|
|
+ List<double[]> actual = rawPoints(power, DataElectricityLocal::getActualPower);
|
|
|
+ List<double[]> availability = rawPoints(power, DataElectricityLocal::getAvailability);
|
|
|
+ List<double[]> irr = rawPoints(weather, DataWeatherLocal::getIrradiance);
|
|
|
+ List<double[]> inclined = rawPoints(weather, DataWeatherLocal::getInclinedIrradiance);
|
|
|
+ List<double[]> temp = rawPoints(weather, DataWeatherLocal::getTemperature);
|
|
|
+
|
|
|
+ for (int i = 0; i < size; i++)
|
|
|
+ {
|
|
|
+ long sec = epochSec(power.get(i).getTm());
|
|
|
+ int di = (int) ((sec - firstDayStart) / 86400L);
|
|
|
+ dayIndex[i] = di;
|
|
|
+ double avail = sampleAt(availability, sec, 5);
|
|
|
+ if (avail == 0)
|
|
|
+ {
|
|
|
+ avail = 100;
|
|
|
+ }
|
|
|
+ double theoretical = methodTheoretical(dataType, TheoreticalPowerCalc.photometricPower(n, a1, a2,
|
|
|
+ (double) sampleAt(irr, sec, 5),
|
|
|
+ (double) sampleAt(inclined, sec, 5),
|
|
|
+ (double) sampleAt(temp, sec, 5)));
|
|
|
+ double available = TheoreticalPowerCalc.availablePower(theoretical, avail);
|
|
|
+ double actualPower = actual.get(i)[1];
|
|
|
+ series[0][i] = theoretical;
|
|
|
+ series[1][i] = available;
|
|
|
+ series[2][i] = actualPower;
|
|
|
+ series[3][i] = theoretical - available;
|
|
|
+ series[4][i] = available - actualPower;
|
|
|
+ }
|
|
|
+
|
|
|
+ double[][] sums = new double[5][dayCount];
|
|
|
+ for (int s = 0; s < 5; s++)
|
|
|
+ {
|
|
|
+ sums[s] = seriesDaySum(series[s], dayIndex, power, firstDayStart, dayCount);
|
|
|
+ }
|
|
|
+ return sums;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单序列按日求和(万千瓦时):同日相邻点 (v_i+v_{i+1})/2×Δt 小时;
|
|
|
+ * 当日最末点 v×(当日 24:00 − t) 小时;Σ kWh ÷ 10000
|
|
|
+ */
|
|
|
+ private double[] seriesDaySum(double[] series, int[] dayIndex, List<DataElectricityLocal> power,
|
|
|
+ long firstDayStart, int dayCount)
|
|
|
+ {
|
|
|
+ double[] sum = new double[dayCount];
|
|
|
+ int size = power.size();
|
|
|
+ for (int i = 0; i < size; i++)
|
|
|
+ {
|
|
|
+ long t = epochSec(power.get(i).getTm());
|
|
|
+ int di = dayIndex[i];
|
|
|
+ if (i < size - 1 && dayIndex[i + 1] == di)
|
|
|
+ {
|
|
|
+ long t2 = epochSec(power.get(i + 1).getTm());
|
|
|
+ sum[di] += (t2 - t) / 3600.0 * (series[i] + series[i + 1]) / 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ long dayEnd = firstDayStart + (di + 1) * 86400L;
|
|
|
+ if (t < dayEnd)
|
|
|
+ {
|
|
|
+ sum[di] += (dayEnd - t) / 3600.0 * series[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int d = 0; d < dayCount; d++)
|
|
|
+ {
|
|
|
+ sum[d] /= 10000;
|
|
|
+ }
|
|
|
+ return sum;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建日报/月报行(万千瓦时 3 位小数;总受阻=场内+场外 按未取整值计算后取整)
|
|
|
+ */
|
|
|
+ private ReportRow buildReportRow(String time, double theoretical, double available, double energy,
|
|
|
+ double intra, double offSite)
|
|
|
+ {
|
|
|
+ ReportRow row = new ReportRow();
|
|
|
+ row.setTime(time);
|
|
|
+ row.setTheoreticalEnergy(round3(theoretical));
|
|
|
+ row.setAvailableEnergy(round3(available));
|
|
|
+ row.setEnergy(round3(energy));
|
|
|
+ row.setIntraPlantCurtailedEnergy(round3(intra));
|
|
|
+ row.setOffSiteCurtailedEnergy(round3(offSite));
|
|
|
+ row.setTotalCurtailedEnergy(round3(intra + offSite));
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功率(kW)保留 3 位小数
|
|
|
+ */
|
|
|
+ private double round3(double v)
|
|
|
+ {
|
|
|
+ return TheoreticalPowerCalc.round(v, 3);
|
|
|
+ }
|
|
|
+}
|