|
|
|
@ -2,8 +2,10 @@ package com.hnac.hzims.operational.main.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.hnac.hzims.EquipmentConstants; |
|
|
|
|
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; |
|
|
|
|
import com.hnac.hzims.hzimsweather.response.weather.Daily; |
|
|
|
|
import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; |
|
|
|
|
import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherNowResponse; |
|
|
|
|
import com.hnac.hzims.operational.main.constant.HomePageConstant; |
|
|
|
@ -28,7 +30,9 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.time.Duration; |
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
@ -653,4 +657,224 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
return subordinate; |
|
|
|
|
}).sorted(Comparator.comparing(SubordinateVo::getCapacity)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 站点数据 |
|
|
|
|
* @param deptId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public PhotovoltaicStationVo station(Long deptId) { |
|
|
|
|
// 参数检查
|
|
|
|
|
if(ObjectUtil.isEmpty(deptId)){ |
|
|
|
|
return new PhotovoltaicStationVo(); |
|
|
|
|
} |
|
|
|
|
// 查询站点
|
|
|
|
|
StationEntity station = stationService.getOne(Wrappers.<StationEntity>lambdaQuery().eq(StationEntity::getRefDept,deptId)); |
|
|
|
|
if(ObjectUtil.isEmpty(station)){ |
|
|
|
|
return new PhotovoltaicStationVo(); |
|
|
|
|
} |
|
|
|
|
// 实时监测点数据
|
|
|
|
|
List<PhotovoltaicRealVo> reals = (List<PhotovoltaicRealVo>) redisTemplate.opsForValue().get(load_photovoltaic_real_key); |
|
|
|
|
// 获取站点机组指标数据
|
|
|
|
|
List<PhotovoltaicTargetVo> targets = (List<PhotovoltaicTargetVo>) redisTemplate.opsForValue().get(load_photovoltaic_target_key); |
|
|
|
|
// 站点设备
|
|
|
|
|
List<EminfoAndEmParamVo> devices = deviceService.getEmInfoList().stream().filter(o-> o.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); |
|
|
|
|
// 实时天气
|
|
|
|
|
Map<String, HeWeatherWeatherNowResponse> weather = weatherService.getNowWeather(Collections.singletonList(station.getCode())); |
|
|
|
|
// 七天天气
|
|
|
|
|
Map<String, HeWeatherWeatherDailyResponse> weekWeather = weatherService.getWeekWeather(Collections.singletonList(station.getCode())); |
|
|
|
|
PhotovoltaicStationVo photovoltaic = new PhotovoltaicStationVo(); |
|
|
|
|
photovoltaic.setDeptId(station.getRefDept()); |
|
|
|
|
photovoltaic.setDeptName(station.getName()); |
|
|
|
|
photovoltaic.setStationCode(station.getCode()); |
|
|
|
|
// 站点实时天气
|
|
|
|
|
photovoltaic.setTemp(this.temp(weather,station.getCode())); |
|
|
|
|
// 站点七天天气
|
|
|
|
|
photovoltaic.setWeather(this.week(weekWeather,station.getCode())); |
|
|
|
|
// 运行天数
|
|
|
|
|
photovoltaic.setRunDay(this.run_day(station)); |
|
|
|
|
// 实时数据: 装机容量、功率、总发电量、年发电量、月发电、日发电量
|
|
|
|
|
this.real_data(photovoltaic,devices,reals); |
|
|
|
|
// 设备实时数据、指标数据: 容量、发电量、实时功率、电流、co2、节约标准煤、30日发电量、当日功率
|
|
|
|
|
photovoltaic.setDevices(this.deviceRealTarget(devices,reals,targets)); |
|
|
|
|
// 设备排行榜
|
|
|
|
|
photovoltaic.setCharts(this.deviceCharts(photovoltaic.getDevices())); |
|
|
|
|
// 年发电量比较概括
|
|
|
|
|
photovoltaic.setGenerateSurvey(this.generateSurvey(station.getId())); |
|
|
|
|
return photovoltaic; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取实时温度 |
|
|
|
|
* @param weather |
|
|
|
|
* @param code |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private String temp(Map<String, HeWeatherWeatherNowResponse> weather, String code) { |
|
|
|
|
if(MapUtils.isEmpty(weather)){ |
|
|
|
|
return "21"; |
|
|
|
|
} |
|
|
|
|
HeWeatherWeatherNowResponse now = weather.get(code); |
|
|
|
|
if(ObjectUtil.isEmpty(now) || ObjectUtil.isEmpty(now.getNow())){ |
|
|
|
|
return "21"; |
|
|
|
|
} |
|
|
|
|
return now.getNow().getTemp(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取七天天气 |
|
|
|
|
* @param weekWeather |
|
|
|
|
* @param code |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<Daily> week(Map<String, HeWeatherWeatherDailyResponse> weekWeather, String code) { |
|
|
|
|
if(MapUtils.isEmpty(weekWeather)){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
HeWeatherWeatherDailyResponse week = weekWeather.get(code); |
|
|
|
|
if(ObjectUtil.isEmpty(week)){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return week.getDaily(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取站点运行天数 |
|
|
|
|
* @param station |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private int run_day(StationEntity station) { |
|
|
|
|
if (ObjectUtil.isEmpty(station.getCommissionTime())) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
// 计算投运时间与当前时间相隔天数
|
|
|
|
|
Duration dur = Duration.between(station.getCommissionTime(), LocalDateTime.now()); |
|
|
|
|
return (int) dur.toDays(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 指标数据 |
|
|
|
|
* @param devices |
|
|
|
|
* @param reals |
|
|
|
|
*/ |
|
|
|
|
private void real_data(PhotovoltaicStationVo photovoltaic, List<EminfoAndEmParamVo> devices, List<PhotovoltaicRealVo> reals) { |
|
|
|
|
// 站点设备检查
|
|
|
|
|
if(CollectionUtil.isEmpty(devices)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
photovoltaic.setCapacity(devices.stream().mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum()); |
|
|
|
|
if(CollectionUtil.isEmpty(reals)){ |
|
|
|
|
} |
|
|
|
|
// 设备指标数据匹配
|
|
|
|
|
List<PhotovoltaicRealVo> deviceReals = reals.stream().filter(o-> devices.stream().map(EminfoAndEmParamVo::getCreateDept).collect(Collectors.toList()).contains(o.getDeptId())).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isEmpty(deviceReals)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 日发电量
|
|
|
|
|
photovoltaic.setGenerateDay(deviceReals.stream().mapToDouble(PhotovoltaicRealVo::getGenerationDay).sum()); |
|
|
|
|
// 月发电量
|
|
|
|
|
photovoltaic.setGenerateMon(deviceReals.stream().mapToDouble(PhotovoltaicRealVo::getGenerationMon).sum()); |
|
|
|
|
// 年发电量
|
|
|
|
|
photovoltaic.setGenerateYear(deviceReals.stream().mapToDouble(PhotovoltaicRealVo::getGenerationYear).sum()); |
|
|
|
|
// 总发电量
|
|
|
|
|
photovoltaic.setGenerate(deviceReals.stream().mapToDouble(PhotovoltaicRealVo::getGeneration).sum()); |
|
|
|
|
// 功率
|
|
|
|
|
photovoltaic.setLoad(deviceReals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 光伏设备实时、指标数据 |
|
|
|
|
* @param devices |
|
|
|
|
* @param reals |
|
|
|
|
* @param targets |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<PhotovoltaicDeviceVo> deviceRealTarget(List<EminfoAndEmParamVo> devices, List<PhotovoltaicRealVo> reals, List<PhotovoltaicTargetVo> targets) { |
|
|
|
|
if(CollectionUtil.isEmpty(devices)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
return devices.stream().map(device->{ |
|
|
|
|
PhotovoltaicDeviceVo item = new PhotovoltaicDeviceVo(); |
|
|
|
|
item.setDeviceCode(device.getEmCode()); |
|
|
|
|
item.setDeviceName(device.getName()); |
|
|
|
|
item.setDeptId(item.getDeptId()); |
|
|
|
|
// 装机容量
|
|
|
|
|
item.setCapacity(device.getInstalledCapacity()); |
|
|
|
|
// 实时数据
|
|
|
|
|
List<PhotovoltaicRealVo> mateReals = reals.stream().filter(o->o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isNotEmpty(mateReals)){ |
|
|
|
|
// 发电量、实时功率、电流、co2减排、节约标准煤
|
|
|
|
|
item.setGenerate(mateReals.get(0).getGenerationDay()); |
|
|
|
|
item.setLoad(mateReals.get(0).getLoad()); |
|
|
|
|
item.setCurrent(mateReals.get(0).getCurrent()); |
|
|
|
|
item.setCo2(mateReals.get(0).getCo2()); |
|
|
|
|
item.setTec(mateReals.get(0).getTec()); |
|
|
|
|
} |
|
|
|
|
// 指标数据
|
|
|
|
|
List<PhotovoltaicTargetVo> mateTargets = targets.stream().filter(o->o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isNotEmpty(mateReals)){ |
|
|
|
|
// 30天发电量、当日功率
|
|
|
|
|
item.setActivePowerVoList(mateTargets.get(0).getActivePowerVoList()); |
|
|
|
|
item.setGenerationPowerVoList(mateTargets.get(0).getGenerationPowerVoList()); |
|
|
|
|
} |
|
|
|
|
return item; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设备排行榜 |
|
|
|
|
* @param devices |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<PhotovoltaicDeviceChartsVo> deviceCharts(List<PhotovoltaicDeviceVo> devices) { |
|
|
|
|
if(CollectionUtil.isEmpty(devices)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
return devices.stream().map(device->{ |
|
|
|
|
PhotovoltaicDeviceChartsVo chart = new PhotovoltaicDeviceChartsVo(); |
|
|
|
|
chart.setDeptId(device.getDeptId()); |
|
|
|
|
chart.setDeviceCode(device.getDeviceCode()); |
|
|
|
|
chart.setDeviceName(device.getDeviceName()); |
|
|
|
|
chart.setLoad(device.getLoad()); |
|
|
|
|
chart.setGenerate(device.getGenerate()); |
|
|
|
|
return chart; |
|
|
|
|
}).sorted(Comparator.comparing(PhotovoltaicDeviceChartsVo::getGenerate)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 年发电量比较概括 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<PowerYearVo> generateSurvey(Long station) { |
|
|
|
|
Map<Long, Map<String, Float>> map = (Map<Long, Map<String, Float>>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); |
|
|
|
|
if(MapUtils.isEmpty(map)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// 站点发电数据
|
|
|
|
|
if(!map.containsKey(station)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// 转换成集合
|
|
|
|
|
List<PowerMonthVo> generates = new ArrayList<>(); |
|
|
|
|
map.get(station).forEach((key,value) -> { |
|
|
|
|
PowerMonthVo generate = new PowerMonthVo(); |
|
|
|
|
LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), key), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); |
|
|
|
|
generate.setYear(localDate.getYear()); |
|
|
|
|
generate.setMonth(localDate.getMonthValue()); |
|
|
|
|
generate.setStrMonth(key); |
|
|
|
|
generate.setPower(value); |
|
|
|
|
generates.add(generate); |
|
|
|
|
}); |
|
|
|
|
// 根据年份分组
|
|
|
|
|
Map<Integer, List<PowerMonthVo>> year = generates.stream().collect(Collectors.groupingBy(PowerMonthVo::getYear)); |
|
|
|
|
// 返回结果集
|
|
|
|
|
return year.entrySet().stream().map(entry -> { |
|
|
|
|
PowerYearVo powerYearVo = new PowerYearVo(); |
|
|
|
|
powerYearVo.setYear(entry.getKey()); |
|
|
|
|
List<PowerMonthVo> sortValue = entry.getValue().stream().sorted(Comparator.comparing(PowerMonthVo::getMonth)).collect(Collectors.toList()); |
|
|
|
|
powerYearVo.setPowerMonthVoList(sortValue); |
|
|
|
|
return powerYearVo; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|