|
@@ -0,0 +1,248 @@
|
|
|
+package com.jiayue.ipp.idp.controller;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.jiayue.ipp.common.data.entity.*;
|
|
|
+import com.jiayue.ipp.common.data.entity.an.ReportingRateRecords;
|
|
|
+import com.jiayue.ipp.idp.dto.ForecastReportDto;
|
|
|
+import com.jiayue.ipp.idp.service.*;
|
|
|
+import com.jiayue.ipp.idp.util.DateTimeUtil;
|
|
|
+import com.jiayue.ipp.idp.util.R;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.commons.lang.time.DateFormatUtils;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * idp_wind_tower_status_data
|
|
|
+ *
|
|
|
+ * @author whc
|
|
|
+ * @date 2022-03-18 15:50:05
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RequestMapping("/forecastReportController")
|
|
|
+@Api(value = "forecastReportController", tags = "forecastReportController管理")
|
|
|
+public class ForecastReportController {
|
|
|
+ private final SysParameterService sysParameterService;
|
|
|
+ private final ElectricFieldService electricFieldService;
|
|
|
+ private final ForecastPowerShortTermService forecastPowerShortTermService;
|
|
|
+ private final NwpService nwpService;
|
|
|
+ private final ForecastPowerUltraShortTermService forecastPowerUltraShortTermService;
|
|
|
+ private final PowerStationStatusDataService powerStationStatusDataService;
|
|
|
+ private final GridApCommandValueService gridApCommandValueService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "通过条件查询", notes = "通过条件查询")
|
|
|
+ @GetMapping("/queryReport")
|
|
|
+ public R queryReport(Long ycDate,Long cdqDate,Long sjDate,Long agcDate) throws Exception {
|
|
|
+ Date ycStartTime = new Date(ycDate+1000*60*15);
|
|
|
+ Date ycEndTime = new Date(ycDate+1000*60*1440);
|
|
|
+ // 获取场站短期实时
|
|
|
+ QueryWrapper<ForecastPowerShortTerm> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.between("forecast_time", ycStartTime, ycEndTime);
|
|
|
+ List<ForecastPowerShortTerm> forecastPowerShortTermList = forecastPowerShortTermService.list(queryWrapper);
|
|
|
+ // 按照场站编号进行分组
|
|
|
+ Map<String, List<ForecastPowerShortTerm>> stListByStationCodeMap = forecastPowerShortTermList.stream().collect(Collectors.groupingBy(r -> r.getStationCode()));
|
|
|
+
|
|
|
+ // 获取nwp实时
|
|
|
+ QueryWrapper<Nwp> nwpWrapper = new QueryWrapper<>();
|
|
|
+ nwpWrapper.between("pre_time", ycStartTime, ycEndTime);
|
|
|
+ List<Nwp> nwpList = nwpService.list(nwpWrapper);
|
|
|
+ // 按照场站编号进行分组
|
|
|
+ Map<String, List<Nwp>> nwpListByStationCodeMap = nwpList.stream().collect(Collectors.groupingBy(r -> r.getStationCode()));
|
|
|
+
|
|
|
+ // 获取场站超短期实时
|
|
|
+ Date cdqStartTime = new Date(cdqDate+1000*60*15);
|
|
|
+ Date cdqEndTime = new Date(cdqDate+1000*60*1440);
|
|
|
+ QueryWrapper<ForecastPowerUltraShortTerm> cdqWrapper = new QueryWrapper<>();
|
|
|
+ cdqWrapper.between("forecast_time", cdqStartTime, cdqEndTime);
|
|
|
+ List<ForecastPowerUltraShortTerm> cdqList = forecastPowerUltraShortTermService.list(cdqWrapper);
|
|
|
+ // 按照场站编号进行分组
|
|
|
+ Map<String, List<ForecastPowerUltraShortTerm>> cdqListByStationCodeMap = cdqList.stream().collect(Collectors.groupingBy(r -> r.getStationCode()));
|
|
|
+
|
|
|
+ // 获取场站实际功率
|
|
|
+ Date sjStartTime = new Date(sjDate+1000*60*15);
|
|
|
+ Date sjEndTime = new Date(sjDate+1000*60*1440);
|
|
|
+ QueryWrapper<PowerStationStatusData> sjWrapper = new QueryWrapper<>();
|
|
|
+ sjWrapper.between("time", sjStartTime, sjEndTime);
|
|
|
+ List<PowerStationStatusData> sjList = powerStationStatusDataService.list(sjWrapper);
|
|
|
+ // 按照场站编号进行分组
|
|
|
+ Map<String, List<PowerStationStatusData>> sjListByStationCodeMap = sjList.stream().collect(Collectors.groupingBy(r -> r.getStationCode()));
|
|
|
+
|
|
|
+ // 获取agc
|
|
|
+ Date agcStartTime = new Date(agcDate+1000*60*15);
|
|
|
+ Date agcEndTime = new Date(agcDate+1000*60*1440);
|
|
|
+ QueryWrapper<GridApCommandValue> agcWrapper = new QueryWrapper<>();
|
|
|
+ agcWrapper.between("time", agcStartTime, agcEndTime);
|
|
|
+ List<GridApCommandValue> agcList = gridApCommandValueService.list(agcWrapper);
|
|
|
+ // 按照场站编号进行分组
|
|
|
+ Map<String, List<GridApCommandValue>> agcListByStationCodeMap = agcList.stream().collect(Collectors.groupingBy(r -> r.getStationId()));
|
|
|
+
|
|
|
+ List<ElectricField> list = electricFieldService.list();
|
|
|
+ list.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
|
|
|
+ Map<String,List<ForecastReportDto>> resultMap = new HashMap<>();
|
|
|
+ Long momentTime = 15 * 60 * 1000L;
|
|
|
+ for (int i=0;i<list.size();i++){
|
|
|
+ ElectricField electricField = list.get(i);
|
|
|
+ // 提取短期map
|
|
|
+ Map<String, ForecastPowerShortTerm> stListByTimeMap = new HashMap<>();
|
|
|
+ if (stListByStationCodeMap.get(electricField.getStationCode())!=null){
|
|
|
+ List<ForecastPowerShortTerm> forecastPowerShortTerms = stListByStationCodeMap.get(electricField.getStationCode());
|
|
|
+ stListByTimeMap = forecastPowerShortTerms.stream()
|
|
|
+ .filter(forecast -> electricField.getBelongForecastManufactor().equals(forecast.getForecastManufactor()))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ myObject -> DateUtil.format(myObject.getForecastTime(),"HH:mm"), // keyMapper,将Date转换为long
|
|
|
+ myObject -> myObject, // valueMapper,保持原对象
|
|
|
+ (existing, replacement) -> existing // mergeFunction,处理重复key的情况,这里简单地保留现有的value
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ // 提取nwp风速
|
|
|
+ Map<String, Nwp> nwpListByTimeMap = new HashMap<>();
|
|
|
+ if (nwpListByStationCodeMap.get(electricField.getStationCode())!=null){
|
|
|
+ List<Nwp> forecastPowerShortTerms = nwpListByStationCodeMap.get(electricField.getStationCode());
|
|
|
+ nwpListByTimeMap = forecastPowerShortTerms.stream()
|
|
|
+ .filter(forecast -> "SYJY".equals(forecast.getForecastManufactor()))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ myObject -> DateUtil.format(myObject.getPreTime(),"HH:mm"), // keyMapper,将Date转换为long
|
|
|
+ myObject -> myObject, // valueMapper,保持原对象
|
|
|
+ (existing, replacement) -> existing // mergeFunction,处理重复key的情况,这里简单地保留现有的value
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ // 获取nwp轮毂高度
|
|
|
+ int nwpHubHeight = Integer.parseInt(sysParameterService.getSysParameterAndStationCode("NWP_HubHeight", "100", electricField.getStationCode()));
|
|
|
+ // 提取超短期map
|
|
|
+ Map<String, ForecastPowerUltraShortTerm> cdqListByTimeMap = new HashMap<>();
|
|
|
+ if (cdqListByStationCodeMap.get(electricField.getStationCode())!=null){
|
|
|
+ List<ForecastPowerUltraShortTerm> cdqTerms = cdqListByStationCodeMap.get(electricField.getStationCode());
|
|
|
+ cdqListByTimeMap = cdqTerms.stream()
|
|
|
+ .filter(forecast -> electricField.getBelongForecastManufactor().equals(forecast.getForecastManufactor()))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ myObject -> DateUtil.format(myObject.getForecastTime(),"HH:mm"), // keyMapper,将Date转换为long
|
|
|
+ myObject -> myObject, // valueMapper,保持原对象
|
|
|
+ (existing, replacement) -> existing // mergeFunction,处理重复key的情况,这里简单地保留现有的value
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ // 提取实际功率
|
|
|
+ Map<String, PowerStationStatusData> sjListByTimeMap = new HashMap<>();
|
|
|
+ if (sjListByStationCodeMap.get(electricField.getStationCode())!=null){
|
|
|
+ List<PowerStationStatusData> sjTerms = sjListByStationCodeMap.get(electricField.getStationCode());
|
|
|
+ sjListByTimeMap = sjTerms.stream()
|
|
|
+ .filter(forecast -> electricField.getStationCode().equals(forecast.getStationCode()))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ myObject -> DateUtil.format(new Date(myObject.getTime().toInstant(ZoneOffset.of("+8")).toEpochMilli()),"HH:mm"), // keyMapper,将Date转换为long
|
|
|
+ myObject -> myObject, // valueMapper,保持原对象
|
|
|
+ (existing, replacement) -> existing // mergeFunction,处理重复key的情况,这里简单地保留现有的value
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ // 提取agc
|
|
|
+ Map<String, GridApCommandValue> agcListByTimeMap = new HashMap<>();
|
|
|
+ if (agcListByStationCodeMap.get(electricField.getStationCode())!=null){
|
|
|
+ List<GridApCommandValue> agcTerms = agcListByStationCodeMap.get(electricField.getStationCode());
|
|
|
+ agcListByTimeMap = agcTerms.stream()
|
|
|
+ .filter(forecast -> electricField.getStationCode().equals(forecast.getStationId()))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ myObject -> DateUtil.format(myObject.getTime(),"HH:mm"), // keyMapper,将Date转换为long
|
|
|
+ myObject -> myObject, // valueMapper,保持原对象
|
|
|
+ (existing, replacement) -> existing // mergeFunction,处理重复key的情况,这里简单地保留现有的value
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ForecastReportDto> forecastReportDtoList = new ArrayList<>();
|
|
|
+ for (Long tempTime = ycStartTime.getTime(); tempTime <= ycEndTime.getTime(); tempTime = tempTime + momentTime) {
|
|
|
+ ForecastReportDto forecastReportDto = new ForecastReportDto();
|
|
|
+ String timeStr = DateUtil.format(new Date(tempTime),"HH:mm");
|
|
|
+ if (timeStr.equals("00:00")){
|
|
|
+ forecastReportDto.setTime("24:00");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ forecastReportDto.setTime(timeStr);
|
|
|
+ }
|
|
|
+ // 短期
|
|
|
+ if (stListByTimeMap.get(timeStr)!=null){
|
|
|
+ ForecastPowerShortTerm forecastPowerShortTerm = stListByTimeMap.get(timeStr);
|
|
|
+ forecastReportDto.setShortTerm(forecastPowerShortTerm.getFpValue());
|
|
|
+ }
|
|
|
+ // 超短期
|
|
|
+ if (cdqListByTimeMap.get(timeStr)!=null){
|
|
|
+ ForecastPowerUltraShortTerm forecastPowerUltraShortTerm = cdqListByTimeMap.get(timeStr);
|
|
|
+ forecastReportDto.setUltraShortTerm(forecastPowerUltraShortTerm.getFpValue());
|
|
|
+ }
|
|
|
+ // 实际功率
|
|
|
+ if (sjListByTimeMap.get(timeStr)!=null){
|
|
|
+ PowerStationStatusData powerStationStatusData = sjListByTimeMap.get(timeStr);
|
|
|
+ forecastReportDto.setActualPower(powerStationStatusData.getRealValue());
|
|
|
+ }
|
|
|
+ // agc
|
|
|
+ if (agcListByTimeMap.get(timeStr)!=null){
|
|
|
+ GridApCommandValue gridApCommandValue = agcListByTimeMap.get(timeStr);
|
|
|
+ forecastReportDto.setAgc(gridApCommandValue.getCommandValue());
|
|
|
+ }
|
|
|
+ // nwp轮毂风速
|
|
|
+ if (nwpListByTimeMap.get(timeStr)!=null){
|
|
|
+ Nwp nwp = nwpListByTimeMap.get(timeStr);
|
|
|
+ // 获取nwp轮毂风速
|
|
|
+ if (nwpHubHeight==170){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs170());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==150){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs150());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==140){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs140());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==130){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs130());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==120){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs120());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==110){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs110());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==100){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs100());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==90){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs90());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==80){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs80());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==70){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs70());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==50){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs50());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==30){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs30());
|
|
|
+ }
|
|
|
+ else if (nwpHubHeight==10){
|
|
|
+ forecastReportDto.setWindSpeed(nwp.getWs10());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ forecastReportDtoList.add(forecastReportDto);
|
|
|
+ }
|
|
|
+ resultMap.put(list.get(i).getName(),forecastReportDtoList);
|
|
|
+ }
|
|
|
+ return R.ok(resultMap);
|
|
|
+ }
|
|
|
+}
|