|
@@ -1,17 +1,32 @@
|
|
|
package com.cpp.web.controller.regulation;
|
|
|
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.cpp.common.core.domain.R;
|
|
|
+import com.cpp.common.utils.DateUtils;
|
|
|
+import com.cpp.web.domain.accuracy.AccuracyPassRate;
|
|
|
+import com.cpp.web.domain.enums.DataSourcesEnum;
|
|
|
+import com.cpp.web.domain.enums.ForecastTypeEnum;
|
|
|
+import com.cpp.web.domain.regulation.TempShortRegulation;
|
|
|
+import com.cpp.web.domain.station.ElectricField;
|
|
|
import com.cpp.web.domain.station.ForecastPowerShortTermStation;
|
|
|
import com.cpp.web.domain.station.WeatherStationStatusData;
|
|
|
+import com.cpp.web.dto.TempShortRegulationDto;
|
|
|
+import com.cpp.web.service.accuracy.AccuracyPassRateService;
|
|
|
+import com.cpp.web.service.regulation.TempShortRegulationService;
|
|
|
+import com.cpp.web.service.station.ElectricFieldService;
|
|
|
import com.cpp.web.service.station.ForecastPowerShortTermStationService;
|
|
|
import com.cpp.web.utils.DateTimeUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@@ -27,24 +42,123 @@ import java.util.*;
|
|
|
public class DqRegulationController {
|
|
|
@Autowired
|
|
|
ForecastPowerShortTermStationService forecastPowerShortTermStationService;
|
|
|
+ @Autowired
|
|
|
+ AccuracyPassRateService accuracyPassRateService;
|
|
|
+ @Autowired
|
|
|
+ TempShortRegulationService tempShortRegulationService;
|
|
|
+ @Autowired
|
|
|
+ ElectricFieldService electricFieldService;
|
|
|
|
|
|
|
|
|
@GetMapping("/queryData")
|
|
|
public R queryData(String stationCode, Long time) {
|
|
|
int howLongAgo = DateTimeUtil.getDaysBetweenTwoDate(System.currentTimeMillis(),time);
|
|
|
// 获取要调整的短期那天的最后时间
|
|
|
- long eneTime = DateTimeUtil.getDayLastTime(time).getTime();
|
|
|
+ long endTime = DateTimeUtil.getDayLastTime(time).getTime();
|
|
|
|
|
|
// 获取短期上报数据(原始数据)
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- List<ForecastPowerShortTermStation> forecastPowerShortTermStationList = forecastPowerShortTermStationService.findByForecastTimeBetweenAndForecastHowLongAgoAndStationCode(time, eneTime, howLongAgo, stationCode);
|
|
|
+ List<ForecastPowerShortTermStation> forecastPowerShortTermStationList = forecastPowerShortTermStationService.findByForecastTimeBetweenAndForecastHowLongAgoAndStationCode(time, endTime, howLongAgo, stationCode);
|
|
|
if (forecastPowerShortTermStationList.size()>0){
|
|
|
- forecastPowerShortTermStationList.sort(Comparator.comparing(ForecastPowerShortTermStation::getTime));
|
|
|
- List list = new ArrayList();
|
|
|
- for (ForecastPowerShortTermStation forecastPowerShortTermStation:forecastPowerShortTermStationList){
|
|
|
- list.add(forecastPowerShortTermStation.getFpValue());
|
|
|
+ Map<Long, BigDecimal> ysShortMap = new HashMap<>();
|
|
|
+ for (ForecastPowerShortTermStation forecastPowerShortTermStation:forecastPowerShortTermStationList) {
|
|
|
+ ysShortMap.putIfAbsent(forecastPowerShortTermStation.getTime().getTime(), forecastPowerShortTermStation.getFpValue());
|
|
|
}
|
|
|
- map.put("ysData",list);
|
|
|
+ // 获取前30天的准确率生成参考值
|
|
|
+ Date accuracyEndDate = DateUtil.offsetDay(new Date(), -1);
|
|
|
+ Date accuracyStartDate = DateUtil.offsetDay(new Date(), -30);
|
|
|
+
|
|
|
+ List<AccuracyPassRate> accuracyPassRateList = accuracyPassRateService.findByTimeBetweenAndForecastTypeAndDataSourcesAndAgoAndForecastModelAndStationCode(DateTimeUtil.getDayStartTime(accuracyStartDate.getTime()), DateTimeUtil.getDayLastTime(accuracyEndDate.getTime()), ForecastTypeEnum.dq, DataSourcesEnum.E1, howLongAgo, null, stationCode);
|
|
|
+ double accuracySum = 0;
|
|
|
+ if (accuracyPassRateList.size()>0){
|
|
|
+ for (AccuracyPassRate accuracyPassRate:accuracyPassRateList){
|
|
|
+ accuracySum = accuracySum + Double.parseDouble(accuracyPassRate.getAccuracy().replaceAll("%", ""));
|
|
|
+ }
|
|
|
+ // 计算获取偏差率
|
|
|
+ accuracySum = 100 - accuracySum / accuracyPassRateList.size();
|
|
|
+ }
|
|
|
+ // 获取调控数据
|
|
|
+ QueryWrapper<TempShortRegulation> tempShortRegulationQueryWrapper = new QueryWrapper<>();
|
|
|
+ tempShortRegulationQueryWrapper.eq("station_code", stationCode);
|
|
|
+ tempShortRegulationQueryWrapper.eq("tk_date", new Date(time));
|
|
|
+ tempShortRegulationQueryWrapper.between("time", new Date(time), new Date(endTime));
|
|
|
+ List<TempShortRegulation> tempShortRegulationList = tempShortRegulationService.list(tempShortRegulationQueryWrapper);
|
|
|
+ List<TempShortRegulationDto> tempList = new ArrayList<>();
|
|
|
+ if (tempShortRegulationList.size()==96){
|
|
|
+ for (TempShortRegulation tempShortRegulation:tempShortRegulationList){
|
|
|
+ TempShortRegulationDto tempShortRegulationDto = new TempShortRegulationDto();
|
|
|
+ tempShortRegulationDto.setTime(DateUtils.parseDateToStr("HH:mm",tempShortRegulation.getTime()));
|
|
|
+ tempShortRegulationDto.setTkDate(tempShortRegulation.getTkDate());
|
|
|
+ tempShortRegulationDto.setYsValue(tempShortRegulation.getYsValue());
|
|
|
+ tempShortRegulationDto.setTkValue(tempShortRegulation.getTkValue());
|
|
|
+ tempShortRegulationDto.setSz(tempShortRegulation.getSz());
|
|
|
+ tempShortRegulationDto.setXs(tempShortRegulation.getXs());
|
|
|
+ tempList.add(tempShortRegulationDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 调控数据
|
|
|
+ List<List<Object>> tkDataList = new ArrayList<>();
|
|
|
+ // 原始短期数据
|
|
|
+ List<BigDecimal> ysList = new ArrayList<>();
|
|
|
+ // 参考上限短期
|
|
|
+ List<BigDecimal> refUpList = new ArrayList<>();
|
|
|
+ // 参考下限短期
|
|
|
+ List<BigDecimal> refDownList = new ArrayList<>();
|
|
|
+ ElectricField electricField = electricFieldService.findByStationCode(stationCode);
|
|
|
+ Long momentTime = 15 * 60 * 1000L;
|
|
|
+ for (Long tempTime = time; tempTime <= endTime; tempTime = tempTime + momentTime) {
|
|
|
+ List<Object> listAfter = new ArrayList<>();
|
|
|
+ listAfter.add(DateUtils.parseDateToStr("HH:mm",new Date(tempTime)));
|
|
|
+ listAfter.add(ysShortMap.get(tempTime));
|
|
|
+ tkDataList.add(listAfter);
|
|
|
+
|
|
|
+ if (ysShortMap.get(tempTime)!=null){
|
|
|
+ ysList.add(ysShortMap.get(tempTime));
|
|
|
+ if (accuracySum>0){
|
|
|
+ // 计算出偏差量
|
|
|
+ BigDecimal baseValue = ysShortMap.get(tempTime).multiply(new BigDecimal(accuracySum).multiply(new BigDecimal("0.01"))).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ // 在原始数据基础上,生成上下限值。
|
|
|
+ BigDecimal sx = ysShortMap.get(tempTime).add(baseValue).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if (sx.compareTo(electricField.getCapacity())==1){
|
|
|
+ sx = electricField.getCapacity();
|
|
|
+ }
|
|
|
+ BigDecimal xx = ysShortMap.get(tempTime).subtract(baseValue).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if (xx.compareTo(new BigDecimal("0"))==-1){
|
|
|
+ xx = new BigDecimal("0");
|
|
|
+ }
|
|
|
+ refUpList.add(sx);
|
|
|
+ refDownList.add(xx);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tempShortRegulationList.isEmpty()){
|
|
|
+ // 使用原始值
|
|
|
+ TempShortRegulationDto tempShortRegulationDto = new TempShortRegulationDto();
|
|
|
+ tempShortRegulationDto.setTime(DateUtils.parseDateToStr("HH:mm",new Date(tempTime)));
|
|
|
+ tempShortRegulationDto.setTkDate(new Date(time));
|
|
|
+ tempShortRegulationDto.setYsValue(ysShortMap.get(tempTime));
|
|
|
+ tempShortRegulationDto.setTkValue(ysShortMap.get(tempTime));
|
|
|
+ tempShortRegulationDto.setSz(new BigDecimal("0"));
|
|
|
+ tempShortRegulationDto.setXs(new BigDecimal("1"));
|
|
|
+ tempList.add(tempShortRegulationDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ ysList.add(null);
|
|
|
+ refUpList.add(null);
|
|
|
+ refDownList.add(null);
|
|
|
+ listAfter.add(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("ysData",ysList);
|
|
|
+ map.put("refUpData",refUpList);
|
|
|
+ map.put("refDownData",refDownList);
|
|
|
+ map.put("tempShortRegulationList",tempList);
|
|
|
+ map.put("tkDataList",tkDataList);
|
|
|
+
|
|
|
+
|
|
|
+ map.put("electricField",electricField);
|
|
|
+
|
|
|
return R.ok(map);
|
|
|
}
|
|
|
else{
|