123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897 |
- package com.cpp.web.controller.largeScreen;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.ReflectUtil;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.cpp.common.core.cache.LocalCache;
- import com.cpp.common.core.domain.R;
- import com.cpp.common.core.domain.entity.SysDictData;
- import com.cpp.system.service.ISysConfigService;
- import com.cpp.system.service.ISysDictDataService;
- import com.cpp.web.domain.accuracy.AccuracyPassRate;
- import com.cpp.web.domain.cloud.NwpCloud;
- import com.cpp.web.domain.enums.DataSourcesEnum;
- import com.cpp.web.domain.powerGeneration.DayPowerGeneration;
- import com.cpp.web.domain.regulation.TempShortUsual;
- import com.cpp.web.domain.station.*;
- import com.cpp.web.domain.station.enums.ElectricFieldTypeEnum;
- import com.cpp.web.dto.largeScreen.*;
- import com.cpp.web.service.accuracy.AccuracyPassRateService;
- import com.cpp.web.service.cloud.NwpCloudService;
- import com.cpp.web.service.powerGeneation.DayPowerGenerationService;
- import com.cpp.web.service.station.*;
- import com.cpp.web.utils.DateTimeUtil;
- import com.cpp.web.utils.LatestDataUtil;
- import lombok.RequiredArgsConstructor;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.lang.reflect.Field;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.text.SimpleDateFormat;
- import java.time.LocalDate;
- import java.time.temporal.ChronoUnit;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 大屏模块
- *
- * @author whc
- * @date 2022-03-18 15:49:14
- */
- @RestController
- @RequiredArgsConstructor
- @RequestMapping("/largeScreenController")
- public class LargeScreenController {
- @Autowired
- PowerStationStatusDataService powerStationStatusDataService;
- @Autowired
- ISysConfigService configService;
- @Autowired
- ForecastPowerUltraShortTermStationService forecastPowerUltraShortTermStationService;
- @Autowired
- ForecastPowerUltraShortTermRegulationService forecastPowerUltraShortTermRegulationService;
- @Autowired
- ForecastPowerShortTermRegulationService forecastPowerShortTermRegulationService;
- @Autowired
- ElectricFieldService electricFieldService;
- @Autowired
- WindTowerStatusDataService windTowerStatusDataService;
- @Autowired
- WeatherStationStatusDataService weatherStationStatusDataService;
- @Autowired
- DayPowerGenerationService dayPowerGenerationService;
- @Autowired
- ISysDictDataService iSysDictDataService;
- @Autowired
- NwpCloudService nwpCloudService;
- @Autowired
- AccuracyPassRateService accuracyPassRateService;
- @GetMapping("/getBizData")
- public R getBizData(String forecastDay, String forecastType, String accuracyType) {
- // 获取所有场站
- List<ElectricField> electricFieldList = electricFieldService.list();
- // 首页左上角场站数据统计
- // 统计开机容量累计值
- BigDecimal gfOpenCapacitySum = BigDecimal.ZERO;
- BigDecimal fdOpenCapacitySum = BigDecimal.ZERO;
- // 辐照度累计值
- BigDecimal fzdSum = BigDecimal.ZERO;
- BigDecimal wsSum = BigDecimal.ZERO;
- int wsSumCount = 0;
- int fzdSumCount = 0;
- for (ElectricField electricField : electricFieldList) {
- Boolean b = LatestDataUtil.getCommunicationStatus(electricField.getStationCode());
- PowerStationStatusData powerStationStatusData = LatestDataUtil.getData(electricField.getStationCode(), PowerStationStatusData.class);
- if (ElectricFieldTypeEnum.E1.name().equals(electricField.getElectricFieldTypeEnum())) {
- // 获取气象站辐照度
- WeatherStationStatusData weatherStationStatusData = LatestDataUtil.getData(electricField.getStationCode(), WeatherStationStatusData.class);
- if (weatherStationStatusData != null) {
- fzdSum = fzdSum.add(weatherStationStatusData.getGlobalR());
- fzdSumCount++;
- }
- // 累计开机容量
- if (powerStationStatusData != null) {
- gfOpenCapacitySum = gfOpenCapacitySum.add(powerStationStatusData.getOpenCapacity());
- }
- } else {
- // 获取测风塔风速
- WindTowerStatusData windTowerStatusData = LatestDataUtil.getData(electricField.getStationCode(), WindTowerStatusData.class);
- if (windTowerStatusData != null) {
- wsSum = wsSum.add(windTowerStatusData.getWsHubHeight());
- wsSumCount++;
- }
- // 累计开机容量
- if (powerStationStatusData != null) {
- fdOpenCapacitySum = fdOpenCapacitySum.add(powerStationStatusData.getOpenCapacity());
- }
- }
- }
- // 封装首页场站数据统计
- ElectricFieldDataTotalDto electricFieldDataTotalDto = new ElectricFieldDataTotalDto();
- electricFieldDataTotalDto.setGfOpenCapcitySum(gfOpenCapacitySum);
- BigDecimal fzdAvg = BigDecimal.ZERO;
- if (fzdSum.compareTo(BigDecimal.ZERO) == 1) {
- fzdAvg = fzdSum.divide(new BigDecimal(fzdSumCount), 2, BigDecimal.ROUND_HALF_UP);
- }
- electricFieldDataTotalDto.setFzdAvg(fzdAvg);
- electricFieldDataTotalDto.setFdOpenCapcitySum(fdOpenCapacitySum);
- BigDecimal wsAvg = BigDecimal.ZERO;
- if (wsSum.compareTo(BigDecimal.ZERO) == 1) {
- wsAvg = wsSum.divide(new BigDecimal(wsSumCount), 2, BigDecimal.ROUND_HALF_UP);
- }
- electricFieldDataTotalDto.setWsAvg(wsAvg);
- Map bizDataMap = new HashMap();
- bizDataMap.put("electricFieldDataTotalDto", electricFieldDataTotalDto);
- // 计算生成数据
- ProductionDataTotalDto productionDataTotalDto = calGenerating();
- bizDataMap.put("productionDataTotalDto", productionDataTotalDto);
- // 获取预测发电量
- Map forecastGeneratingMap = calForecastGenerating();
- bizDataMap.put("forecastGeneratingMap", forecastGeneratingMap);
- // 获取首页中心侧nwp气象
- Map<String, List> forecastNwpMap = centerForecastNwpAvgTotal(electricFieldList);
- bizDataMap.put("forecastNwpMap", forecastNwpMap);
- //////////////// 获取首页预测对比数据 ///////////////
- Map<String, List> curveMap = getForecastContrast(forecastDay, forecastType);
- bizDataMap.put("curveMap", curveMap);
- /////////////// 获取首页准确率排名 ///////////////
- Map<String, List<AccuracyRankingDto>> accuracyRankingMap = accuracyRanking(electricFieldList);
- bizDataMap.put("accuracyRankingMap", accuracyRankingMap);
- ////////////// 获取首页地图数据 //////////////
- Map mapDataMap = mapData(electricFieldList);
- bizDataMap.put("mapDataMap", mapDataMap);
- return R.ok(bizDataMap);
- }
- /**
- * 统计首页生成数据
- *
- * @return
- */
- private ProductionDataTotalDto calGenerating() {
- // 当日零点
- Date dayStartTime = new Date(DateTimeUtil.getMillisecondsSubDay());
- // 获取当前时刻5分钟
- Date dayEndTimeFor5 = DateTimeUtil.getMomentTimeFor5Minute(System.currentTimeMillis());
- // 获取当日所有实际功率
- QueryWrapper<PowerStationStatusData> powerStationStatusDataQueryWrapper = new QueryWrapper<>();
- powerStationStatusDataQueryWrapper.between("time", dayStartTime, dayEndTimeFor5);
- List<PowerStationStatusData> powerStationStatusDataList = powerStationStatusDataService.list(powerStationStatusDataQueryWrapper);
- // 实际功率总和
- BigDecimal realPowerSum = BigDecimal.ZERO;
- // 理论功率总和
- BigDecimal theoryPowerSum = BigDecimal.ZERO;
- // 计算实际发电量
- BigDecimal realGeneratingSum = BigDecimal.ZERO;
- for (PowerStationStatusData powerStationStatusData : powerStationStatusDataList) {
- // 统计实际功率总和
- if (powerStationStatusData.getRealValue() != null) {
- realPowerSum = realPowerSum.add(powerStationStatusData.getRealValue());
- // 发电量(万kWh) = 实际 * 0.08 * 0.1
- realGeneratingSum = realGeneratingSum.add(powerStationStatusData.getRealValue().multiply(new BigDecimal("0.08")).multiply(new BigDecimal("0.1")).setScale(2, RoundingMode.HALF_UP));
- }
- // 统计理论功率总和
- if (powerStationStatusData.getTheoryValue() != null) {
- theoryPowerSum = theoryPowerSum.add(powerStationStatusData.getTheoryValue());
- }
- }
- // 获取中心侧预测的当日所有短期预测功率
- int counts = -4;
- // 定义日期格式
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
- // 定义开始日期和结束日期(使用Calendar对象)
- Calendar yesterdayDate = Calendar.getInstance();
- //得到前一天
- yesterdayDate.add(Calendar.DATE, -1);
- //得到前三天天
- Calendar endDate = Calendar.getInstance();
- endDate.add(Calendar.DAY_OF_MONTH, counts);
- List<DayPowerGeneration> dayPowerGenerationList = new ArrayList<>();
- for (; !yesterdayDate.before(endDate); yesterdayDate.add(Calendar.DATE, -1)) {
- QueryWrapper<DayPowerGeneration> generationWrapper = new QueryWrapper<>();
- generationWrapper.eq("gen_date", formatter.format(yesterdayDate.getTime()));
- generationWrapper.eq("prediction_data_source", "云端下发");
- dayPowerGenerationList = dayPowerGenerationService.list(generationWrapper);
- if (!dayPowerGenerationList.isEmpty()) {
- // 查出数据,并且有今日的预测数据,就退出当前循环。
- dayPowerGenerationList = dayPowerGenerationList.stream().filter(f -> f.getTime().equals(formatter.format(new Date()))).collect(Collectors.toList());
- if (dayPowerGenerationList.size() > 0) {
- break;
- }
- } else {
- // 否则,日期往前推一天,再查
- }
- }
- // 累加中心侧预测发电量
- BigDecimal forecastGeneratingSum = BigDecimal.ZERO;
- for (DayPowerGeneration dayPowerGeneration : dayPowerGenerationList) {
- forecastGeneratingSum = forecastGeneratingSum.add(dayPowerGeneration.getForecastPowerGeneration());
- }
- ProductionDataTotalDto productionDataTotalDto = new ProductionDataTotalDto();
- productionDataTotalDto.setRealGeneratingSum(realGeneratingSum);
- productionDataTotalDto.setForecastGeneratingSum(forecastGeneratingSum);
- productionDataTotalDto.setRealPowerSum(realPowerSum);
- productionDataTotalDto.setTheoryPowerSum(theoryPowerSum);
- return productionDataTotalDto;
- }
- /**
- * 统计首页未来10天预测总发电量
- *
- * @return
- */
- private Map calForecastGenerating() {
- // 获取未来10天的中心侧模型预测发电量
- int counts = -3;
- // 定义日期格式
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
- // 定义开始日期和结束日期(使用Calendar对象)
- Calendar currentDate = Calendar.getInstance();
- Calendar endDate = Calendar.getInstance();
- endDate.add(Calendar.DAY_OF_MONTH, counts);
- List<DayPowerGeneration> dayPowerGenerationList = new ArrayList<>();
- for (; !currentDate.before(endDate); currentDate.add(Calendar.DATE, -1)) {
- QueryWrapper<DayPowerGeneration> generationWrapper = new QueryWrapper<>();
- generationWrapper.eq("gen_date", formatter.format(currentDate.getTime()));
- generationWrapper.eq("prediction_data_source", "云端下发");
- dayPowerGenerationList = dayPowerGenerationService.list(generationWrapper);
- if (!dayPowerGenerationList.isEmpty()) {
- // 查出数据就退出当前循环
- break;
- } else {
- // 否则,日期往前推一天,再查
- }
- }
- // 按场时间分组
- Map<String, List<DayPowerGeneration>> shortTermDataGroup = dayPowerGenerationList.stream().collect(Collectors.groupingBy(s -> s.getTime()));
- Map<String, List> forecastGeneratingMap = new HashMap<>();
- // 图表x轴时间数据
- List<String> xDataList = new ArrayList<>();
- // 图表y轴发电量数据
- List<BigDecimal> pDataList = new ArrayList<>();
- // 统计每天里所有电站发电量总和
- if (shortTermDataGroup != null) {
- // 第二天
- Calendar nextDate = Calendar.getInstance();
- nextDate.add(Calendar.DAY_OF_MONTH, 1);
- Calendar end10Date = Calendar.getInstance();
- end10Date.add(Calendar.DAY_OF_MONTH, 10);
- for (; nextDate.before(end10Date); nextDate.add(Calendar.DATE, 1)) {
- String dateFormat = DateUtil.format(nextDate.getTime(), "yyyy-MM-dd");
- xDataList.add(dateFormat.substring(5));
- if (shortTermDataGroup.get(dateFormat) != null) {
- List<DayPowerGeneration> dayPowerGenerations = shortTermDataGroup.get(dateFormat);
- BigDecimal sum = BigDecimal.ZERO;
- for (DayPowerGeneration dayPowerGeneration : dayPowerGenerations) {
- sum = sum.add(dayPowerGeneration.getForecastPowerGeneration());
- }
- pDataList.add(sum);
- } else {
- pDataList.add(BigDecimal.ZERO);
- }
- }
- forecastGeneratingMap.put("xData", xDataList);
- forecastGeneratingMap.put("pData", pDataList);
- }
- return forecastGeneratingMap;
- }
- /**
- * 首页中心预测nwp气象站数据总体平均值
- *
- * @return
- */
- private Map<String, List> centerForecastNwpAvgTotal(List<ElectricField> list) {
- // 根据类型获取所有场站
- Map<String, List> stationMap = new HashMap();
- List<String> windStationCodeList = new ArrayList<>();
- List<String> gfStationCodeList = new ArrayList<>();
- for (ElectricField electricField : list) {
- if (electricField.getElectricFieldTypeEnum().equals("E1")) {
- gfStationCodeList.add(electricField.getStationCode());
- } else {
- windStationCodeList.add(electricField.getStationCode());
- }
- }
- stationMap.put("gf", gfStationCodeList);
- stationMap.put("wind", windStationCodeList);
- Map<String, List> forecastWeatherAvgDataMap = new HashMap<>();
- // 循环光和风
- Iterator<Map.Entry<String, List>> stationIterator = stationMap.entrySet().iterator();
- while (stationIterator.hasNext()) {
- Map.Entry<String, List> entry = stationIterator.next();
- List<String> stationCodeList = entry.getValue();
- Date dayStartTime = DateTimeUtil.getDayStartTime(System.currentTimeMillis());
- Date dayEndTime = DateTimeUtil.getDayLastTime(System.currentTimeMillis());
- Map<Long, List<NwpCloud>> nwpCloudMap = new HashMap<>();
- Map<String, String> nwpWshubheightMap = new HashMap<>();
- if (entry.getKey().equals("wind")) {
- // 获取字典中nwp风速轮毂设置
- SysDictData sysDictData = new SysDictData();
- sysDictData.setDictType("nwp_wshubheight");
- List<SysDictData> nwpWshubheightList = iSysDictDataService.selectDictDataList(sysDictData);
- nwpWshubheightMap = nwpWshubheightList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
- }
- if (!stationCodeList.isEmpty()) {
- int counts = 10;
- for (int i = 1; i <= counts; i++) {
- QueryWrapper<NwpCloud> nwpCloudQueryWrapper = new QueryWrapper<>();
- nwpCloudQueryWrapper.eq("forecast_how_long_ago", i);
- nwpCloudQueryWrapper.between("time", dayStartTime, dayEndTime);
- nwpCloudQueryWrapper.in("station_code", stationCodeList);
- List<NwpCloud> nwpCloudList = nwpCloudService.list(nwpCloudQueryWrapper);
- if (!nwpCloudList.isEmpty()) {
- nwpCloudMap = nwpCloudList.stream().collect(Collectors.groupingBy(n -> n.getTime().getTime(), Collectors.toList()));
- // 查出数据,并且有今日的预测数据,就退出当前循环。
- break;
- } else {
- // 否则,日期往前推一天,再查
- }
- }
- }
- Long momentTime = 15 * 60 * 1000L;
- List<ForecastNwpDto> forecastNwpDtoList = new ArrayList<>();
- for (Long tempTime = dayStartTime.getTime(); tempTime <= dayEndTime.getTime(); tempTime = tempTime + momentTime) {
- ForecastNwpDto totalForecastNwpDto = new ForecastNwpDto();
- totalForecastNwpDto.setTime(DateUtil.format(new Date(tempTime), "HH:mm"));
- if ("wind".equals(entry.getKey())) {
- totalForecastNwpDto.setName("平均轮毂风速");
- } else {
- totalForecastNwpDto.setName("平均总辐射");
- }
- if (nwpCloudMap.get(tempTime) != null) {
- // 当前时间点所有站点数据
- List<NwpCloud> nwpCloudList = nwpCloudMap.get(tempTime);
- BigDecimal sum = BigDecimal.ZERO;
- // 循环每个站封装点位以及统计总和
- for (NwpCloud nwpCloud : nwpCloudList) {
- if ("wind".equals(entry.getKey())) {
- if (nwpWshubheightMap.get(nwpCloud.getStationCode()) != null) {
- // 场站配置了轮毂高度,根据轮毂高度反射获取字段值
- Field field = ReflectUtil.getField(NwpCloud.class, "ws" + nwpWshubheightMap.get(nwpCloud.getStationCode()));
- // 设置为可访问,私有字段也可以访问
- field.setAccessible(true);
- try {
- // 获取字段值
- Object fieldValue = field.get(nwpCloud);
- sum = sum.add(new BigDecimal(fieldValue.toString()));
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- } else {
- sum = sum.add(nwpCloud.getSwr());
- }
- }
- totalForecastNwpDto.setValue(sum);
- } else {
- // 时间点位为空
- totalForecastNwpDto.setValue(BigDecimal.ZERO);
- }
- forecastNwpDtoList.add(totalForecastNwpDto);
- }
- forecastWeatherAvgDataMap.put(entry.getKey(), forecastNwpDtoList);
- }
- return forecastWeatherAvgDataMap;
- }
- /**
- * 预测气象放大窗口获取每个站的数据
- *
- * @param weatherType
- * @return
- */
- @GetMapping("/forecastNwpFull")
- public R forecastNwpFull(String weatherType) {
- Map<String, String> nwpWshubheightMap = new HashMap<>();
- QueryWrapper wrapper = new QueryWrapper<>();
- if ("wind".equals(weatherType)) {
- // 过滤出风场站
- wrapper.eq("electric_field_type_enum", "E2");
- // 获取字典中nwp风速轮毂设置
- SysDictData sysDictData = new SysDictData();
- sysDictData.setDictType("nwp_wshubheight");
- List<SysDictData> nwpWshubheightList = iSysDictDataService.selectDictDataList(sysDictData);
- nwpWshubheightMap = nwpWshubheightList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
- } else {
- // 过滤出光场站
- wrapper.eq("electric_field_type_enum", "E1");
- }
- List<ElectricField> list = electricFieldService.list(wrapper);
- // 遍历获取场站nwp数据
- List<String> stationCodeList = new ArrayList<>();
- for (ElectricField electricField : list) {
- stationCodeList.add(electricField.getStationCode());
- }
- // 查询当日所有站的nwp数据
- Date dayStartTime = DateTimeUtil.getDayStartTime(System.currentTimeMillis());
- Date dayEndTime = DateTimeUtil.getDayLastTime(System.currentTimeMillis());
- Map<String, List<NwpCloud>> nwpCloudMap = new HashMap<>();
- if (!stationCodeList.isEmpty()) {
- int counts = 10;
- for (int i = 1; i <= counts; i++) {
- QueryWrapper<NwpCloud> nwpCloudQueryWrapper = new QueryWrapper<>();
- nwpCloudQueryWrapper.eq("forecast_how_long_ago", i);
- nwpCloudQueryWrapper.between("time", dayStartTime, dayEndTime);
- nwpCloudQueryWrapper.in("station_code", stationCodeList);
- List<NwpCloud> nwpCloudList = nwpCloudService.list(nwpCloudQueryWrapper);
- if (!nwpCloudList.isEmpty()) {
- nwpCloudMap = nwpCloudList.stream().collect(Collectors.groupingBy(n -> n.getStationCode(), Collectors.toList()));
- // 查出数据,并且有今日的预测数据,就退出当前循环。
- break;
- } else {
- // 否则,日期往前推一天,再查
- }
- }
- }
- Map<String, List<BigDecimal>> forecastWeatherDataMap = new HashMap<>();
- Long momentTime = 15 * 60 * 1000L;
- for (ElectricField electricField : list) {
- List<BigDecimal> nwpList = new ArrayList<>();
- // 获取场站nwp
- if (nwpCloudMap.get(electricField.getStationCode()) != null) {
- List<NwpCloud> nwpCloudList = nwpCloudMap.get(electricField.getStationCode());
- Map<Long, NwpCloud> tempMap = nwpCloudList.stream().collect(Collectors.toMap(s -> s.getTime().getTime(), s -> s));
- for (Long tempTime = dayStartTime.getTime(); tempTime <= dayEndTime.getTime(); tempTime = tempTime + momentTime) {
- BigDecimal value = BigDecimal.ZERO;
- if (tempMap.get(tempTime) != null) {
- NwpCloud nwpCloud = tempMap.get(tempTime);
- if ("wind".equals(weatherType)) {
- if (nwpWshubheightMap.get(nwpCloud.getStationCode()) != null) {
- // 场站配置了轮毂高度,根据轮毂高度反射获取字段值
- Field field = ReflectUtil.getField(NwpCloud.class, "ws" + nwpWshubheightMap.get(nwpCloud.getStationCode()));
- // 设置为可访问,私有字段也可以访问
- field.setAccessible(true);
- try {
- // 获取字段值
- Object fieldValue = field.get(nwpCloud);
- value = new BigDecimal(fieldValue.toString());
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- } else {
- value = nwpCloud.getSwr();
- }
- }
- nwpList.add(value);
- }
- } else {
- for (Long tempTime = dayStartTime.getTime(); tempTime <= dayEndTime.getTime(); tempTime = tempTime + momentTime) {
- nwpList.add(BigDecimal.ZERO);
- }
- }
- forecastWeatherDataMap.put(electricField.getName(), nwpList);
- }
- return R.ok(forecastWeatherDataMap);
- }
- /**
- * 首页功率曲线对比
- *
- * @param forecastDay
- * @param forecastType
- * @return
- */
- @GetMapping("/forecastContrast")
- public R forecastContrast(String forecastDay, String forecastType) {
- Map<String, List> map = getForecastContrast(forecastDay, forecastType);
- return R.ok(map);
- }
- /**
- * 获取预测对比数据公共方法
- *
- * @param forecastDay
- * @param forecastType
- */
- private Map<String, List> getForecastContrast(String forecastDay, String forecastType) {
- Date dayStartTime = DateTimeUtil.getDayStartTime(System.currentTimeMillis());
- Date dayEndTime = null;
- if ("day".equals(forecastDay)) {
- // 当日
- dayEndTime = DateTimeUtil.getDayLastTime(System.currentTimeMillis());
- } else {
- // 包含当天的才是10天
- dayEndTime = DateUtil.offsetDay(new Date(), 9);
- }
- QueryWrapper wrapper = new QueryWrapper<>();
- if ("wind".equals(forecastType)) {
- // 过滤出风场站
- wrapper.eq("electric_field_type_enum", "E2");
- } else {
- // 过滤出光场站
- wrapper.eq("electric_field_type_enum", "E1");
- }
- List<ElectricField> list = electricFieldService.list(wrapper);
- // 遍历获取场站nwp数据
- List<String> stationCodeList = new ArrayList<>();
- for (ElectricField electricField : list) {
- stationCodeList.add(electricField.getStationCode());
- }
- // 首页实际、可用、理论曲线图数组
- List<Object> realList = new ArrayList<>();
- List<Object> ableList = new ArrayList<>();
- List<Object> theoryList = new ArrayList<>();
- List<Object> cdqList = new ArrayList<>();
- List<Object> dqList = new ArrayList<>();
- List<Object> timeList = new ArrayList<>();
- if (!stationCodeList.isEmpty()) {
- // 查询实际功率、可用、理论
- QueryWrapper<PowerStationStatusData> realQueryWrapper = new QueryWrapper<>();
- realQueryWrapper.between("time", dayStartTime, dayEndTime);
- realQueryWrapper.in("station_code", stationCodeList);
- List<PowerStationStatusData> powerStationStatusDataList = powerStationStatusDataService.list(realQueryWrapper);
- // 按场时间分组
- Map<Long, List<PowerStationStatusData>> powerStationStatusDataGroup = powerStationStatusDataList.stream().collect(Collectors.groupingBy(s -> s.getTime().getTime()));
- // 获取超短期
- String cdqHowLongAgo = configService.selectConfigByKey("cdqHowLongAgo");
- QueryWrapper cdqysWrapper = new QueryWrapper<>();
- cdqysWrapper.eq("forecast_how_long_ago", Integer.parseInt(cdqHowLongAgo));
- cdqysWrapper.between("time", dayStartTime, dayEndTime);
- cdqysWrapper.in("station_code", stationCodeList);
- List<ForecastPowerUltraShortTermRegulation> forecastPowerUltraShortTermStationList = forecastPowerUltraShortTermRegulationService.list(cdqysWrapper);
- // 按场时间分组
- Map<Long, List<ForecastPowerUltraShortTermRegulation>> utraShortTermStationDataGroup = forecastPowerUltraShortTermStationList.stream().collect(Collectors.groupingBy(s -> s.getTime().getTime()));
- // 获取短期上报
- String dqHowLongAgo = configService.selectConfigByKey("dqHowLongAgo");
- QueryWrapper dqsbWrapper = new QueryWrapper<>();
- dqsbWrapper.eq("forecast_how_long_ago", Integer.parseInt(dqHowLongAgo));
- dqsbWrapper.between("time", dayStartTime, dayEndTime);
- dqsbWrapper.in("station_code", stationCodeList);
- List<ForecastPowerShortTermRegulation> forecastPowerShortTermRegulationList = forecastPowerShortTermRegulationService.list(dqsbWrapper);
- // 按场时间分组
- Map<Long, List<ForecastPowerShortTermRegulation>> shortTermDataGroup = forecastPowerShortTermRegulationList.stream().collect(Collectors.groupingBy(s -> s.getTime().getTime()));
- Long momentTime = 15 * 60 * 1000L;
- for (Long tempTime = dayStartTime.getTime(); tempTime <= dayEndTime.getTime(); tempTime = tempTime + momentTime) {
- if ("day".equals(forecastDay)) {
- timeList.add(DateUtil.format(new Date(tempTime), "HH:mm"));
- } else {
- timeList.add(DateUtil.format(new Date(tempTime), "yyyy-MM-dd HH:mm"));
- }
- // 统计实际功率、可用、理论曲线
- if (powerStationStatusDataGroup.get(tempTime) != null) {
- // 对每个时间点的所有场站数据进行求和
- List<PowerStationStatusData> everyDataList = powerStationStatusDataGroup.get(tempTime);
- BigDecimal tempRealSum = BigDecimal.ZERO;
- BigDecimal tempAbleSum = BigDecimal.ZERO;
- BigDecimal tempTheorySum = BigDecimal.ZERO;
- for (PowerStationStatusData powerStationStatusData : everyDataList) {
- BigDecimal realValue = powerStationStatusData.getRealValue();
- tempRealSum = tempRealSum.add(realValue);
- BigDecimal ableValue = powerStationStatusData.getAbleValue();
- tempAbleSum = tempAbleSum.add(ableValue);
- BigDecimal theoryValue = powerStationStatusData.getTheoryValue();
- tempTheorySum = tempTheorySum.add(theoryValue);
- }
- realList.add(tempRealSum);
- ableList.add(tempAbleSum);
- theoryList.add(tempTheorySum);
- } else {
- realList.add(null);
- ableList.add(null);
- theoryList.add(null);
- }
- // 统计超短期曲线
- if (utraShortTermStationDataGroup.get(tempTime) != null) {
- // 对每个时间点的所有场站数据进行求和
- List<ForecastPowerUltraShortTermRegulation> everyDataList = utraShortTermStationDataGroup.get(tempTime);
- BigDecimal tempCdqSum = BigDecimal.ZERO;
- for (ForecastPowerUltraShortTermRegulation forecastPowerUltraShortTermStation : everyDataList) {
- BigDecimal cdqValue = forecastPowerUltraShortTermStation.getFpValue();
- tempCdqSum = tempCdqSum.add(cdqValue);
- }
- cdqList.add(tempCdqSum);
- } else {
- cdqList.add(null);
- }
- // 统计短期上报曲线
- if (shortTermDataGroup.get(tempTime) != null) {
- // 对每个时间点的所有场站数据进行求和
- List<ForecastPowerShortTermRegulation> everyDataList = shortTermDataGroup.get(tempTime);
- BigDecimal tempDqSum = BigDecimal.ZERO;
- for (ForecastPowerShortTermRegulation forecastPowerShortTermRegulation : everyDataList) {
- BigDecimal dqValue = forecastPowerShortTermRegulation.getFpValue();
- tempDqSum = tempDqSum.add(dqValue);
- }
- dqList.add(tempDqSum);
- } else {
- dqList.add(null);
- }
- }
- }
- // 定义曲线map
- Map<String, List> curveMap = new HashMap();
- curveMap.put("timeList", timeList);
- curveMap.put("realList", realList);
- curveMap.put("ableList", ableList);
- curveMap.put("theoryList", theoryList);
- curveMap.put("cdqList", cdqList);
- curveMap.put("dqList", dqList);
- return curveMap;
- }
- /**
- * 首页准确率排名
- *
- * @return
- */
- private Map<String, List<AccuracyRankingDto>> accuracyRanking(List<ElectricField> list) {
- Map<String, List<AccuracyRankingDto>> accuracyMap = new HashMap();
- // 昨日时间段
- Date startTime = DateTimeUtil.getDayStartTime(DateUtil.yesterday().getTime());
- Date endTime = DateTimeUtil.getDayLastTime(DateUtil.yesterday().getTime());
- // 上个月时间段
- Date lastMonthStartTime = DateTimeUtil.getMonthStartTime(System.currentTimeMillis());
- Date lastMonthEndTime = DateTimeUtil.getMonthLastTime(System.currentTimeMillis());
- // 先查询昨日的准确率
- String dqHowLongAgo = configService.selectConfigByKey("dqHowLongAgo");
- QueryWrapper<AccuracyPassRate> accuracyPassRateQueryWrapper = new QueryWrapper<>();
- accuracyPassRateQueryWrapper.eq("forecast_how_long_ago", dqHowLongAgo);
- accuracyPassRateQueryWrapper.eq("data_sources", DataSourcesEnum.E4.name());
- accuracyPassRateQueryWrapper.between("time", startTime, endTime);
- List<AccuracyPassRate> accuracyPassRateList = accuracyPassRateService.list(accuracyPassRateQueryWrapper);
- // 按场站编号分组
- Map<String, List<AccuracyPassRate>> groupByStationCode = accuracyPassRateList.stream().collect(Collectors.groupingBy(AccuracyPassRate::getStationCode));
- List<AccuracyRankingDto> dayRankingList = new ArrayList();
- for (ElectricField electricField : list) {
- AccuracyRankingDto accuracyRankingDto = new AccuracyRankingDto();
- accuracyRankingDto.setName(electricField.getName());
- if (groupByStationCode.get(electricField.getStationCode()) != null) {
- List<AccuracyPassRate> accuracyPassRateList1 = groupByStationCode.get(electricField.getStationCode());
- if ("无可用数据计算".equals(accuracyPassRateList1.get(0).getAccuracy())) {
- accuracyRankingDto.setAccuracy("0%");
- } else {
- accuracyRankingDto.setAccuracy(accuracyPassRateList1.get(0).getAccuracy());
- }
- } else {
- // 昨日没有此场站的准确率
- accuracyRankingDto.setAccuracy("0%");
- }
- dayRankingList.add(accuracyRankingDto);
- }
- dayRankingList.sort(Comparator.comparing(AccuracyRankingDto::getAccuracy).reversed().thenComparing(AccuracyRankingDto::getName));
- // 分配排名,允许并列
- int currentRank = 1;
- for (int i = 0; i < dayRankingList.size(); i++) {
- AccuracyRankingDto dto = dayRankingList.get(i);
- dto.setSort(currentRank + "");
- if (i + 1 <= dayRankingList.size() - 1) {
- AccuracyRankingDto nextDto = dayRankingList.get(i + 1);
- if (!dto.getAccuracy().equals(nextDto.getAccuracy())) {
- currentRank++;
- }
- }
- }
- // 查询上个月的准确率
- QueryWrapper<AccuracyPassRate> lastMonthQueryWrapper = new QueryWrapper<>();
- lastMonthQueryWrapper.eq("forecast_how_long_ago", dqHowLongAgo);
- lastMonthQueryWrapper.eq("data_sources", DataSourcesEnum.E4.name());
- lastMonthQueryWrapper.between("time", lastMonthStartTime, lastMonthEndTime);
- List<AccuracyPassRate> lastMonthAccuracyPassRateList = accuracyPassRateService.list(lastMonthQueryWrapper);
- // 按场站编号分组
- Map<String, List<AccuracyPassRate>> lastMonthGroupByStationCode = lastMonthAccuracyPassRateList.stream().collect(Collectors.groupingBy(AccuracyPassRate::getStationCode));
- List<AccuracyRankingDto> lastMonthRankingList = new ArrayList();
- for (ElectricField electricField : list) {
- AccuracyRankingDto accuracyRankingDto = new AccuracyRankingDto();
- accuracyRankingDto.setName(electricField.getName());
- if (lastMonthGroupByStationCode.get(electricField.getStationCode()) != null) {
- List<AccuracyPassRate> accuracyPassRateList1 = lastMonthGroupByStationCode.get(electricField.getStationCode());
- if ("无可用数据计算".equals(accuracyPassRateList1.get(0).getAccuracy())) {
- accuracyRankingDto.setAccuracy("0%");
- } else {
- accuracyRankingDto.setAccuracy(accuracyPassRateList1.get(0).getAccuracy());
- }
- } else {
- // 上个月没有此场站的准确率
- accuracyRankingDto.setAccuracy("0%");
- }
- lastMonthRankingList.add(accuracyRankingDto);
- }
- lastMonthRankingList.sort(Comparator.comparing(AccuracyRankingDto::getAccuracy).reversed().thenComparing(AccuracyRankingDto::getName));
- // 分配排名,允许并列
- int lastMonthCurrentRank = 1;
- for (int i = 0; i < lastMonthRankingList.size(); i++) {
- AccuracyRankingDto dto = lastMonthRankingList.get(i);
- dto.setSort(lastMonthCurrentRank + "");
- if (i + 1 <= lastMonthRankingList.size() - 1) {
- AccuracyRankingDto nextDto = lastMonthRankingList.get(i + 1);
- if (!dto.getAccuracy().equals(nextDto.getAccuracy())) {
- lastMonthCurrentRank++;
- }
- }
- }
- accuracyMap.put("dayRankingList", dayRankingList);
- accuracyMap.put("lastMonthRankingList", lastMonthRankingList);
- return accuracyMap;
- }
- /**
- * 首页地图数据展示
- *
- * @return
- */
- private Map mapData(List<ElectricField> list) {
- List<String> stationCodeList = list.stream().map(ElectricField::getStationCode).collect(Collectors.toList());
- // 获取当前时刻所有场站短期数据
- Date dqMomentDate = DateTimeUtil.getMomentTimeFor15Minute(System.currentTimeMillis());
- QueryWrapper dqsbWrapper = new QueryWrapper<>();
- dqsbWrapper.eq("time", dqMomentDate);
- dqsbWrapper.in("station_code", stationCodeList);
- List<ForecastPowerShortTermRegulation> forecastPowerShortTermRegulationList = forecastPowerShortTermRegulationService.list(dqsbWrapper);
- // 按场站分组
- Map<String, List<ForecastPowerShortTermRegulation>> shortTermDataGroupByStationCode = forecastPowerShortTermRegulationList.stream().collect(Collectors.groupingBy(ForecastPowerShortTermRegulation::getStationCode));
- // 超短期
- QueryWrapper cdqsbWrapper = new QueryWrapper<>();
- cdqsbWrapper.eq("time", dqMomentDate);
- cdqsbWrapper.in("station_code", stationCodeList);
- List<ForecastPowerUltraShortTermRegulation> forecastPowerUltraShortTermRegulationList = forecastPowerUltraShortTermRegulationService.list(cdqsbWrapper);
- // 按场站分组
- Map<String, List<ForecastPowerUltraShortTermRegulation>> ultraShortTermDataGroupByStationCode = forecastPowerUltraShortTermRegulationList.stream().collect(Collectors.groupingBy(ForecastPowerUltraShortTermRegulation::getStationCode));
- List<MapDtaDto> mapDataDtoList = new ArrayList();
- // 首页地图限电场站统计
- int xdcoutns = 0;
- // 通讯状态个数
- int txcoutns = 0;
- // 检修状态个数
- int jxcoutns = 0;
- // 运行状态个数
- int yxcoutns = 0;
- // 遍历所有场站封装地图展示的数据
- for (ElectricField electricField : list) {
- MapDtaDto mapDtaDto = new MapDtaDto();
- mapDtaDto.setName(electricField.getName());
- mapDtaDto.setStationCode(electricField.getStationCode());
- mapDtaDto.setStationType(electricField.getElectricFieldTypeEnum());
- mapDtaDto.setCapacity(electricField.getCapacity().setScale(2, RoundingMode.HALF_UP).toString());
- mapDtaDto.setLeft(electricField.getMapLeft());
- mapDtaDto.setTop(electricField.getMapTop());
- if (shortTermDataGroupByStationCode.get(electricField.getStationCode())!=null){
- List<ForecastPowerShortTermRegulation> forecastPowerShortTermRegulationList1 = shortTermDataGroupByStationCode.get(electricField.getStationCode());
- // 再对场站多条预测记录,按howlongago排序,先获取数值小的。
- forecastPowerShortTermRegulationList1.sort(Comparator.comparing(ForecastPowerShortTermRegulation::getForecastHowLongAgo));
- mapDtaDto.setDq(forecastPowerShortTermRegulationList1.get(0).getFpValue().toString());
- }
- else{
- mapDtaDto.setDq("0.00");
- }
- if (ultraShortTermDataGroupByStationCode.get(electricField.getStationCode())!=null){
- List<ForecastPowerUltraShortTermRegulation> forecastPowerShortTermRegulationList1 = ultraShortTermDataGroupByStationCode.get(electricField.getStationCode());
- // 再对场站多条预测记录,按howlongago排序,先获取数值小的。
- forecastPowerShortTermRegulationList1.sort(Comparator.comparing(ForecastPowerUltraShortTermRegulation::getForecastHowLongAgo));
- mapDtaDto.setCdq(forecastPowerShortTermRegulationList1.get(0).getFpValue().toString());
- }
- else{
- mapDtaDto.setCdq("0.00");
- }
- // 实际、可用、理论
- PowerStationStatusData powerStationStatusData = LatestDataUtil.getData(electricField.getStationCode(), PowerStationStatusData.class);
- if (powerStationStatusData != null) {
- mapDtaDto.setSjgl(powerStationStatusData.getRealValue().toString());
- mapDtaDto.setKygl(powerStationStatusData.getAbleValue().toString());
- mapDtaDto.setLlgl(powerStationStatusData.getTheoryValue().toString());
- }
- else{
- mapDtaDto.setSjgl("0.00");
- mapDtaDto.setKygl("0.00");
- mapDtaDto.setLlgl("0.00");
- }
- if (electricField.getElectricFieldTypeEnum().equals("E2")){
- // 风
- WindTowerStatusData windTowerStatusData = LatestDataUtil.getData(electricField.getStationCode(), WindTowerStatusData.class);
- if (windTowerStatusData != null) {
- mapDtaDto.setHj(windTowerStatusData.getWsHubHeight().toString());
- }
- else{
- mapDtaDto.setHj("0.00");
- }
- }
- else{
- // 光
- WeatherStationStatusData weatherStationStatusData = LatestDataUtil.getData(electricField.getStationCode(), WeatherStationStatusData.class);
- if (weatherStationStatusData != null) {
- mapDtaDto.setHj(weatherStationStatusData.getGlobalR().toString());
- }
- else{
- mapDtaDto.setHj("0.00");
- }
- }
- // 判断场站状态,先获取是否通讯
- boolean isCommunication = false;
- if (!isCommunication){
- // 无通讯
- mapDtaDto.setStatus("无通讯");
- txcoutns++;
- }
- else{
- // 判断是否检修
- if (powerStationStatusData != null) {
- // 获取站内受阻容量
- BigDecimal blockedCapacity = powerStationStatusData.getBlockedCapacity();
- if (blockedCapacity.compareTo(electricField.getCapacity().multiply(new BigDecimal(0.5)))>0){
- // 超出装机50%容量,认为检修
- mapDtaDto.setStatus("检修");
- jxcoutns++;
- }
- else{
- // 未超过50%,判断是否限电
- if (powerStationStatusData.getPowerRationing().intValue()==1){
- // 限电
- mapDtaDto.setStatus("限电");
- xdcoutns++;
- }
- else{
- mapDtaDto.setStatus("运行");
- yxcoutns++;
- }
- }
- }
- else{
- // 没找到实际功率记录,认为场站正常状态
- mapDtaDto.setStatus("运行");
- yxcoutns++;
- }
- }
- mapDataDtoList.add(mapDtaDto);
- }
- Map mapDataMap = new HashMap();
- mapDataMap.put("mapDataDtoList",mapDataDtoList);
- mapDataMap.put("xdcoutns",xdcoutns);
- mapDataMap.put("txcoutns",txcoutns);
- mapDataMap.put("jxcoutns",jxcoutns);
- mapDataMap.put("yxcoutns",yxcoutns);
- // 获取系统运行开始日期(yyyy-MM-dd)
- int runDays = 66;
- String systemRunDate = configService.selectConfigByKey("systemRunDate");
- try{
- // 计算系统运行天数
- LocalDate date1 = LocalDate.parse(systemRunDate);
- LocalDate date2 = LocalDate.parse(DateUtil.today());
- long days = ChronoUnit.DAYS.between(date1, date2);
- runDays = (int)(days+1);
- }
- catch (Exception e){
- e.printStackTrace();
- }
- mapDataMap.put("runDays",runDays);
- return mapDataMap;
- }
- }
|