|
|
|
@ -2,25 +2,34 @@ package com.hnac.hzims.operational.main.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
import com.hnac.hzims.EquipmentConstants; |
|
|
|
|
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; |
|
|
|
|
import com.hnac.hzims.operational.main.service.IHomePageService; |
|
|
|
|
import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; |
|
|
|
|
import com.hnac.hzims.operational.main.service.ISideHustleService; |
|
|
|
|
import com.hnac.hzims.operational.main.service.PhotovoltaicService; |
|
|
|
|
import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; |
|
|
|
|
import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherNowResponse; |
|
|
|
|
import com.hnac.hzims.operational.main.constant.HomePageConstant; |
|
|
|
|
import com.hnac.hzims.operational.main.service.*; |
|
|
|
|
import com.hnac.hzims.operational.main.vo.*; |
|
|
|
|
import com.hnac.hzims.operational.maintenance.constants.HomePageConstant; |
|
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
|
import com.hnac.hzims.operational.station.service.IStationService; |
|
|
|
|
import io.swagger.annotations.ApiModelProperty; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springblade.system.entity.Dept; |
|
|
|
|
import org.springblade.system.entity.Region; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -38,19 +47,33 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
|
|
|
|
|
private final IMainSystemMonitoringService deviceService; |
|
|
|
|
|
|
|
|
|
private final ISideHustleService sideHustleService; |
|
|
|
|
|
|
|
|
|
private final IHomePageService homePageService; |
|
|
|
|
|
|
|
|
|
private final IWeatherService weatherService; |
|
|
|
|
|
|
|
|
|
private final IWaterService waterService; |
|
|
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
|
|
private final static String load_photovoltaic_real_key = "hzims:operation:photovoltaic:real:key"; |
|
|
|
|
|
|
|
|
|
private final static String load_photovoltaic_target_key = "hzims:operation:photovoltaic:target:key"; |
|
|
|
|
|
|
|
|
|
private final static String RECENT_YEAR_POWER_DATA = "hzims:operation:key:power:data"; |
|
|
|
|
|
|
|
|
|
@Value("${hzims.operation.realIdKey}") |
|
|
|
|
public String real_id_key; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 光伏站-逆变器指标加载 |
|
|
|
|
* 光伏站-逆变器实时加载 |
|
|
|
|
* @param param |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void loadPhotovoltaicTarget(String param) { |
|
|
|
|
public void loadPhotovoltaicReal(String param) { |
|
|
|
|
// 查询设备
|
|
|
|
|
List<EminfoAndEmParamVo> devices = this.getPhotovoltaicDevice(); |
|
|
|
|
if(CollectionUtil.isEmpty(devices)){ |
|
|
|
@ -65,6 +88,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
real.setDeptId(device.getCreateDept()); |
|
|
|
|
real.setDeviceCode(device.getEmCode()); |
|
|
|
|
real.setDeviceName(device.getName()); |
|
|
|
|
real.setState(random.nextInt(2)-1); |
|
|
|
|
// 容量
|
|
|
|
|
real.setCapacity(device.getInstalledCapacity()); |
|
|
|
|
// 年发电量
|
|
|
|
@ -79,20 +103,226 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
real.setVoltage(random.nextDouble() * 300); |
|
|
|
|
// 电流
|
|
|
|
|
real.setCurrent(random.nextDouble() * 300); |
|
|
|
|
// 节约标准煤 tec
|
|
|
|
|
// 节约标准煤
|
|
|
|
|
real.setTec(real.getGenerationMon() * 0.0001229); |
|
|
|
|
// 二氧化碳减排 co2
|
|
|
|
|
// 二氧化碳减排
|
|
|
|
|
real.setCo2(real.getGenerationMon() * 0.997); |
|
|
|
|
// 减少森林砍伐 deforest
|
|
|
|
|
// 减少森林砍伐
|
|
|
|
|
real.setDeforest(real.getGenerationMon() * 0.000553); |
|
|
|
|
// 功率 power
|
|
|
|
|
real.setPower(random.nextDouble() * 300); |
|
|
|
|
// 收益 income
|
|
|
|
|
// 功率
|
|
|
|
|
real.setLoad(random.nextDouble() * 300); |
|
|
|
|
// 收益
|
|
|
|
|
real.setIncome(random.nextDouble() * 0.34); |
|
|
|
|
list.add(real); |
|
|
|
|
}); |
|
|
|
|
redisTemplate.opsForValue().set(load_photovoltaic_real_key,list); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 光伏站-逆变器指标加载 |
|
|
|
|
* @param param |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void loadPhotovoltaicTarget(String param) { |
|
|
|
|
// 有效设备
|
|
|
|
|
List<EminfoAndEmParamVo> devices = this.getPhotovoltaicDevice(); |
|
|
|
|
if(CollectionUtil.isEmpty(devices)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
List<PhotovoltaicTargetVo> list = new ArrayList<>(); |
|
|
|
|
devices.forEach(device->{ |
|
|
|
|
PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); |
|
|
|
|
target.setDeptId(device.getCreateDept()); |
|
|
|
|
target.setDeviceCode(device.getEmCode()); |
|
|
|
|
target.setDeviceName(device.getName()); |
|
|
|
|
target.setDeptName(device.getName()); |
|
|
|
|
// 当年发电量
|
|
|
|
|
float powerYear = this.getGenerationPower(device,0); |
|
|
|
|
target.setPowerYear(powerYear); |
|
|
|
|
// 当月发电量
|
|
|
|
|
float powerMon = this.getGenerationPower(device,1); |
|
|
|
|
target.setPowerMon(powerMon); |
|
|
|
|
// 当日发电量
|
|
|
|
|
float powerDay = this.getGenerationPower(device,2); |
|
|
|
|
// 当天有功功率
|
|
|
|
|
// List<ActivePowerVo> activePowerVoList = waterService.getActivePowerVoList(device);
|
|
|
|
|
// FIXME 测试模拟数据
|
|
|
|
|
List<PhotovoltaicPowerVo> photovoltaicPowers = this.activePowerVoList(device); |
|
|
|
|
target.setActivePowerVoList(photovoltaicPowers); |
|
|
|
|
// 30天发电量
|
|
|
|
|
List<GenerationPowerVo> generationPowerVoList = this.getGenerationPowerList(device); |
|
|
|
|
target.setGenerationPowerVoList(generationPowerVoList); |
|
|
|
|
target.setPowerDay(powerDay); |
|
|
|
|
list.add(target); |
|
|
|
|
}); |
|
|
|
|
redisTemplate.opsForValue().set(load_photovoltaic_target_key,list); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// FIXME 测试模拟
|
|
|
|
|
private List<PhotovoltaicPowerVo> activePowerVoList(EminfoAndEmParamVo device) { |
|
|
|
|
List<String> hours = getTestDay(); |
|
|
|
|
Random random = new Random(); |
|
|
|
|
return hours.stream().map(hour -> { |
|
|
|
|
PhotovoltaicPowerVo power = new PhotovoltaicPowerVo(); |
|
|
|
|
power.setHour(hour); |
|
|
|
|
power.setActivePower(String.valueOf(random.nextDouble() * 500)); |
|
|
|
|
return power; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取年、月、日发电量 |
|
|
|
|
* @param device |
|
|
|
|
* @param scope |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private float getGenerationPower(EminfoAndEmParamVo device,int scope) { |
|
|
|
|
// 日期格式化yyyy-mm-dd
|
|
|
|
|
SimpleDateFormat df = new SimpleDateFormat(DateUtil.PATTERN_DATE); |
|
|
|
|
// 日期格式化yyyy-mm-dd
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATETIME); |
|
|
|
|
String startTime,endTime; |
|
|
|
|
int cycle; |
|
|
|
|
switch (scope){ |
|
|
|
|
// 年
|
|
|
|
|
case 0: |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
endTime = sdf.format(calendar.getTime()); |
|
|
|
|
calendar.setTime(new Date()); |
|
|
|
|
calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); |
|
|
|
|
calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); |
|
|
|
|
startTime = df.format(calendar.getTime()) + " 00:00:00"; |
|
|
|
|
cycle = EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(); |
|
|
|
|
break; |
|
|
|
|
// 月
|
|
|
|
|
case 1: |
|
|
|
|
startTime = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; |
|
|
|
|
endTime = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); |
|
|
|
|
cycle = EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(); |
|
|
|
|
break; |
|
|
|
|
// 日
|
|
|
|
|
case 2: |
|
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
|
String time = df.format(cal.getTime()); |
|
|
|
|
startTime = time + " 00:00:00"; |
|
|
|
|
endTime = time + " 23:59:59"; |
|
|
|
|
cycle = EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
throw new IllegalStateException("Unexpected value: " + scope); |
|
|
|
|
} |
|
|
|
|
return homePageService.getAnalyzeCodeAndSignages(device,startTime,endTime,cycle,HomePageConstant.PHOTOVOLTAIC_GENERATE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 近30天发电量 |
|
|
|
|
* @param device |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<GenerationPowerVo> getGenerationPowerList(EminfoAndEmParamVo device) { |
|
|
|
|
List<GenerationPowerVo> generationPowerVoList = new ArrayList<>(); |
|
|
|
|
// 近30天日期集合
|
|
|
|
|
List<String> dayList = this.getRecent30Day(); |
|
|
|
|
for (int i = 0; i < dayList.size() - 1; i++) { |
|
|
|
|
GenerationPowerVo generationPowerVo = new GenerationPowerVo(); |
|
|
|
|
generationPowerVo.setDate(dayList.get(i)); |
|
|
|
|
// 某天发电量
|
|
|
|
|
float power = homePageService.getAnalyzeCodeAndSignages(device, dayList.get(i) + " 00:00:00", dayList.get(i + 1) + " 00:00:00",EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),HomePageConstant.PHOTOVOLTAIC_GENERATE); |
|
|
|
|
generationPowerVo.setGenerationPower(power); |
|
|
|
|
generationPowerVoList.add(generationPowerVo); |
|
|
|
|
} |
|
|
|
|
return generationPowerVoList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 近7天发电量 |
|
|
|
|
* @param device |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<GenerationPowerVo> getGenerationPowerWeek(EminfoAndEmParamVo device) { |
|
|
|
|
List<GenerationPowerVo> generationPowerVoList = new ArrayList<>(); |
|
|
|
|
// 近一周日期集合
|
|
|
|
|
List<String> dayList = this.getRecentWeek(); |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("EEEE"); |
|
|
|
|
for (int i = 0; i < dayList.size() - 1; i++) { |
|
|
|
|
GenerationPowerVo generationPowerVo = new GenerationPowerVo(); |
|
|
|
|
generationPowerVo.setDate(sdf.format(DateUtil.parse(dayList.get(i),DateUtil.PATTERN_DATE))); |
|
|
|
|
// 某天发电量
|
|
|
|
|
float power = homePageService.getAnalyzeCodeAndSignages(device, dayList.get(i) + " 00:00:00", dayList.get(i + 1) + " 00:00:00",EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),HomePageConstant.PHOTOVOLTAIC_GENERATE); |
|
|
|
|
generationPowerVo.setGenerationPower(power); |
|
|
|
|
generationPowerVoList.add(generationPowerVo); |
|
|
|
|
} |
|
|
|
|
return generationPowerVoList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 当天功率 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<String> getTestDay() { |
|
|
|
|
// 日期格式化yyyy-mm-dd
|
|
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH"); |
|
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
|
// 开始日期
|
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.setTime(new Date()); |
|
|
|
|
calendar.add(Calendar.HOUR_OF_DAY, - calendar.get(Calendar.HOUR_OF_DAY)); |
|
|
|
|
calendar.add(Calendar.HOUR_OF_DAY, + 1); |
|
|
|
|
list.add(df.format(calendar.getTime())); |
|
|
|
|
// 获取时间
|
|
|
|
|
while (calendar.getTime().compareTo(new Date()) <= 0) { |
|
|
|
|
calendar.add(Calendar.HOUR_OF_DAY, + 1); |
|
|
|
|
list.add(df.format(calendar.getTime())); |
|
|
|
|
} |
|
|
|
|
return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取近30天集合 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<String> getRecentWeek() { |
|
|
|
|
// 日期格式化yyyy-mm-dd
|
|
|
|
|
SimpleDateFormat df = new SimpleDateFormat(DateUtil.PATTERN_DATE); |
|
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
|
// 开始日期
|
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.setTime(new Date()); |
|
|
|
|
calendar.add(Calendar.DATE, + 1); |
|
|
|
|
list.add(df.format(calendar.getTime())); |
|
|
|
|
// 获取日期之间的月
|
|
|
|
|
int i = 0; |
|
|
|
|
while (i < 7) { |
|
|
|
|
calendar.add(Calendar.DATE, - 1); |
|
|
|
|
list.add(df.format(calendar.getTime())); |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取近30天集合 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<String> getRecent30Day() { |
|
|
|
|
// 日期格式化yyyy-mm-dd
|
|
|
|
|
SimpleDateFormat df = new SimpleDateFormat(DateUtil.PATTERN_DATE); |
|
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
|
// 开始日期
|
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.setTime(new Date()); |
|
|
|
|
calendar.add(Calendar.DATE, + 1); |
|
|
|
|
list.add(df.format(calendar.getTime())); |
|
|
|
|
// 获取日期之间的月
|
|
|
|
|
int i = 0; |
|
|
|
|
while (i < 30) { |
|
|
|
|
calendar.add(Calendar.DATE, - 1); |
|
|
|
|
list.add(df.format(calendar.getTime())); |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -128,15 +358,6 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 光伏站-逆变器实时加载 |
|
|
|
|
* @param param |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void loadPhotovoltaicReal(String param) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 集团/区域关键指标 |
|
|
|
|
* @param deptId |
|
|
|
|
* @return |
|
|
|
@ -146,7 +367,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
// 查询光伏站点
|
|
|
|
|
List<StationEntity> stations = stationService.getHomeStationList(deptId,Collections.singletonList(HomePageConstant.PHOTOVOLTAIC),HomePageConstant.HYDROPOWER_SERVETYPE); |
|
|
|
|
if(CollectionUtil.isEmpty(stations)){ |
|
|
|
|
return null; |
|
|
|
|
return new PhotovoltaicKPIsVo(); |
|
|
|
|
} |
|
|
|
|
// redis实时数据
|
|
|
|
|
List<PhotovoltaicRealVo> photovoltaics = (List<PhotovoltaicRealVo>) redisTemplate.opsForValue().get(load_photovoltaic_real_key); |
|
|
|
@ -163,27 +384,273 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
kpi.setCount(stations.size()); |
|
|
|
|
// 容量
|
|
|
|
|
kpi.setInstalledCapacity(devices.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); |
|
|
|
|
// 负荷
|
|
|
|
|
kpi.setLoad(devices.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); |
|
|
|
|
// 年发电量
|
|
|
|
|
kpi.setPowerYear(devices.stream().mapToDouble(PhotovoltaicRealVo::getGenerationYear).sum()); |
|
|
|
|
// 月发电量
|
|
|
|
|
kpi.setPowerMon(devices.stream().mapToDouble(PhotovoltaicRealVo::getGenerationMon).sum()); |
|
|
|
|
// 日发电量
|
|
|
|
|
kpi.setPowerDay(devices.stream().mapToDouble(PhotovoltaicRealVo::getGenerationDay).sum()); |
|
|
|
|
// 节约标准煤
|
|
|
|
|
kpi.setTec(devices.stream().mapToDouble(PhotovoltaicRealVo::getTec).sum()); |
|
|
|
|
// CO2减排
|
|
|
|
|
kpi.setCo2(devices.stream().mapToDouble(PhotovoltaicRealVo::getCo2).sum()); |
|
|
|
|
// 减少森林砍伐
|
|
|
|
|
kpi.setDeforest(devices.stream().mapToDouble(PhotovoltaicRealVo::getDeforest).sum()); |
|
|
|
|
// 近3年发电量
|
|
|
|
|
kpi.setPowerYearVoList(this.getPowerList(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()))); |
|
|
|
|
return kpi; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取近3年发电量 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<PowerYearVo> getPowerList(List<String> stations) { |
|
|
|
|
// 站点近年发电数据 key - stationCode value - 月份,发电量
|
|
|
|
|
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<>(); |
|
|
|
|
} |
|
|
|
|
List<Map<String, Float>> filter = map.entrySet().stream().filter(e -> stations.contains(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); |
|
|
|
|
if (CollectionUtil.isEmpty(filter)) { |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// 根据月份分组
|
|
|
|
|
List<PowerMonthVo> powerMonthVos = new ArrayList<>(); |
|
|
|
|
filter.forEach(item -> { |
|
|
|
|
item.forEach((key, value) -> { |
|
|
|
|
PowerMonthVo powerMonthVo = new PowerMonthVo(); |
|
|
|
|
powerMonthVo.setStrMonth(key); |
|
|
|
|
powerMonthVo.setPower(value); |
|
|
|
|
powerMonthVos.add(powerMonthVo); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
Map<String,List<PowerMonthVo>> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); |
|
|
|
|
// 总和所有相同月份的发电量
|
|
|
|
|
List<PowerMonthVo> powerMonthVoList = months.entrySet().stream().map(entry -> { |
|
|
|
|
PowerMonthVo powerMonth = new PowerMonthVo(); |
|
|
|
|
powerMonth.setStrMonth(entry.getKey()); |
|
|
|
|
LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), entry.getKey()), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); |
|
|
|
|
powerMonth.setYear(localDate.getYear()); |
|
|
|
|
powerMonth.setMonth(localDate.getMonthValue()); |
|
|
|
|
powerMonth.setPower((float) entry.getValue().stream().mapToDouble(PowerMonthVo::getPower).sum()); |
|
|
|
|
return powerMonth; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
if (CollectionUtil.isEmpty(powerMonthVoList)) { |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// 根据年份分组
|
|
|
|
|
Map<Integer, List<PowerMonthVo>> year = powerMonthVoList.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()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 集团/区域发电量 |
|
|
|
|
* @param deptId |
|
|
|
|
* @param type |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<GenerationVo> generation(Long deptId, Long type) { |
|
|
|
|
return null; |
|
|
|
|
public List<GenerationVo> generation(Long deptId, String type) { |
|
|
|
|
// 查询光伏站点
|
|
|
|
|
List<StationEntity> stations = stationService.getHomeStationList(deptId,Collections.singletonList(HomePageConstant.PHOTOVOLTAIC),HomePageConstant.HYDROPOWER_SERVETYPE); |
|
|
|
|
if(CollectionUtil.isEmpty(stations)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
switch (type){ |
|
|
|
|
// 周
|
|
|
|
|
case "0": |
|
|
|
|
return this.getGeneration(stations.stream().map(StationEntity::getRefDept).distinct().collect(Collectors.toList()),true); |
|
|
|
|
// 月
|
|
|
|
|
case "1": |
|
|
|
|
return this.getGeneration(stations.stream().map(StationEntity::getRefDept).distinct().collect(Collectors.toList()),false); |
|
|
|
|
// 年
|
|
|
|
|
case "2": |
|
|
|
|
return this.getGenerationYear(stations.stream().map(StationEntity::getId).distinct().collect(Collectors.toList())); |
|
|
|
|
default: |
|
|
|
|
throw new ServiceException("无效查询类型!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取发电量(周/月) |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<GenerationVo> getGeneration(List<Long> stations,boolean flag) { |
|
|
|
|
// redis实时数据
|
|
|
|
|
List<PhotovoltaicTargetVo> photovoltaics = (List<PhotovoltaicTargetVo>) redisTemplate.opsForValue().get(load_photovoltaic_target_key); |
|
|
|
|
if(CollectionUtil.isEmpty(photovoltaics)){ |
|
|
|
|
return new ArrayList(); |
|
|
|
|
} |
|
|
|
|
// 过滤有效光伏设备
|
|
|
|
|
List<PhotovoltaicTargetVo> filters = photovoltaics.stream().filter(photovoltaic -> stations.contains(photovoltaic.getDeptId())).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isEmpty(filters)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// 数据集合
|
|
|
|
|
List<GenerationPowerVo> generations = new ArrayList<>(); |
|
|
|
|
for (PhotovoltaicTargetVo target : filters){ |
|
|
|
|
if(CollectionUtil.isEmpty(target.getGenerationPowerVoList())){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
generations.addAll(target.getGenerationPowerVoList()); |
|
|
|
|
} |
|
|
|
|
if(CollectionUtil.isEmpty(generations)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
List<String> weeks = this.getRecentWeek(); |
|
|
|
|
// 周
|
|
|
|
|
if(flag){ |
|
|
|
|
// 根据日期分组
|
|
|
|
|
return generations.stream().filter(generation -> weeks.contains(generation.getDate())).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry->{ |
|
|
|
|
GenerationVo generation = new GenerationVo(); |
|
|
|
|
generation.setPeriod(entry.getKey()); |
|
|
|
|
generation.setPower((float)entry.getValue().stream().mapToDouble(GenerationPowerVo::getGenerationPower).sum()); |
|
|
|
|
return generation; |
|
|
|
|
}).sorted(Comparator.comparing(GenerationVo::getPeriod)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
// 月
|
|
|
|
|
return generations.stream().collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry->{ |
|
|
|
|
GenerationVo generation = new GenerationVo(); |
|
|
|
|
generation.setPeriod(entry.getKey()); |
|
|
|
|
generation.setPower((float)entry.getValue().stream().mapToDouble(GenerationPowerVo::getGenerationPower).sum()); |
|
|
|
|
return generation; |
|
|
|
|
}).sorted(Comparator.comparing(GenerationVo::getPeriod)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取发电量(年) |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<GenerationVo> getGenerationYear(List<Long> stations) { |
|
|
|
|
// 站点近年发电数据 key - stationCode value - 月份,发电量
|
|
|
|
|
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<>(); |
|
|
|
|
} |
|
|
|
|
List<Map<String, Float>> filter = map.entrySet().stream().filter(e -> stations.contains(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); |
|
|
|
|
if (CollectionUtil.isEmpty(filter)) { |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// 根据月份分组
|
|
|
|
|
List<PowerMonthVo> powerMonthVos = new ArrayList<>(); |
|
|
|
|
filter.forEach(item -> { |
|
|
|
|
item.forEach((key, value) -> { |
|
|
|
|
PowerMonthVo powerMonthVo = new PowerMonthVo(); |
|
|
|
|
powerMonthVo.setStrMonth(key); |
|
|
|
|
powerMonthVo.setPower(value); |
|
|
|
|
powerMonthVos.add(powerMonthVo); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
Map<String,List<PowerMonthVo>> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); |
|
|
|
|
// 总和所有相同月份的发电量
|
|
|
|
|
String year = String.valueOf(LocalDate.now().getYear()); |
|
|
|
|
return months.entrySet().stream().filter(entry -> entry.getKey().contains(year)).map(entry -> { |
|
|
|
|
GenerationVo generation = new GenerationVo(); |
|
|
|
|
generation.setPeriod(entry.getKey()); |
|
|
|
|
generation.setPower((float) entry.getValue().stream().mapToDouble(PowerMonthVo::getPower).sum()); |
|
|
|
|
return generation; |
|
|
|
|
}).sorted(Comparator.comparing(GenerationVo::getPeriod)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 集团/区域下属数据占比 |
|
|
|
|
* @param deptId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<SubordinateVo> subordinate(Long deptId) { |
|
|
|
|
return null; |
|
|
|
|
// 获取区域或者站点map结构
|
|
|
|
|
Map<Dept,List<StationEntity>> map = sideHustleService.getAreaOrStaion(deptId,Collections.singletonList(HomePageConstant.PHOTOVOLTAIC)); |
|
|
|
|
if(MapUtils.isEmpty(map)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// redis实时数据
|
|
|
|
|
List<PhotovoltaicRealVo> photovoltaics = (List<PhotovoltaicRealVo>) redisTemplate.opsForValue().get(load_photovoltaic_real_key); |
|
|
|
|
if(CollectionUtil.isEmpty(photovoltaics)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// 遍历数据
|
|
|
|
|
List<SubordinateVo> list = new ArrayList<>(); |
|
|
|
|
for (Map.Entry<Dept,List<StationEntity>> entry : map.entrySet()) { |
|
|
|
|
SubordinateVo subordinate = new SubordinateVo(); |
|
|
|
|
if(ObjectUtil.isEmpty(entry.getValue())){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
subordinate.setDeptId(entry.getKey().getId()); |
|
|
|
|
subordinate.setDeptName(entry.getKey().getDeptName()); |
|
|
|
|
subordinate.setSort(entry.getKey().getSort()); |
|
|
|
|
// 获取第一个站点经纬度、行政编码信息
|
|
|
|
|
StationEntity station = entry.getValue().get(0); |
|
|
|
|
subordinate.setLttd(station.getLttd()); |
|
|
|
|
subordinate.setLgtd(station.getLgtd()); |
|
|
|
|
String areaCode = station.getAreaCode(); |
|
|
|
|
subordinate.setAreaCode(areaCode); |
|
|
|
|
if(StringUtil.isEmpty(areaCode)){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String[] arrCode = areaCode.split(","); |
|
|
|
|
R<Region> R = sysClient.getRegion(arrCode[1]); |
|
|
|
|
if (R.isSuccess() && ObjectUtil.isNotEmpty(R.getData())) { |
|
|
|
|
subordinate.setAreaName(R.getData().getName()); |
|
|
|
|
} |
|
|
|
|
// 获取实时天气
|
|
|
|
|
Map<String, HeWeatherWeatherNowResponse> nowWeather = this.weatherService.getNowWeather(Collections.singletonList(station.getCode())); |
|
|
|
|
if(MapUtils.isNotEmpty(nowWeather)){ |
|
|
|
|
subordinate.setTemp(nowWeather.get(station.getCode()).getNow().getTemp()); |
|
|
|
|
} |
|
|
|
|
// 获取七天天气
|
|
|
|
|
Map<String, HeWeatherWeatherDailyResponse> weekWeather = weatherService.getWeekWeather(Collections.singletonList(station.getCode())); |
|
|
|
|
if(MapUtils.isNotEmpty(weekWeather)){ |
|
|
|
|
subordinate.setTemp(nowWeather.get(station.getCode()).getNow().getTemp()); |
|
|
|
|
} |
|
|
|
|
subordinate.setWeather(weekWeather.get(station.getCode()).getDaily()); |
|
|
|
|
// 区域/站点 设备集合
|
|
|
|
|
List<PhotovoltaicRealVo> devices = photovoltaics.stream().filter(photovoltaic -> entry.getValue().stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(photovoltaic.getDeptId())).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isNotEmpty(devices)){ |
|
|
|
|
subordinate.setGeneration(devices.stream().mapToDouble(PhotovoltaicRealVo::getGenerationYear).sum()); |
|
|
|
|
subordinate.setStationCount(Long.valueOf(entry.getValue().size())); |
|
|
|
|
subordinate.setStationUseCount(devices.stream().filter(device -> HomePageConstant.OFF.equals(device.getState())).map(PhotovoltaicRealVo::getDeptId).distinct().count()); |
|
|
|
|
subordinate.setCapacity(devices.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); |
|
|
|
|
subordinate.setLoad(devices.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); |
|
|
|
|
} |
|
|
|
|
list.add(subordinate); |
|
|
|
|
} |
|
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
// 总数据 : 发电量 、 容量 、 电站数
|
|
|
|
|
Double sumGeneration = list.stream().mapToDouble(SubordinateVo::getGeneration).sum(); |
|
|
|
|
Double sumLoad = list.stream().mapToDouble(SubordinateVo::getCapacity).sum(); |
|
|
|
|
Double sumStationCount = list.stream().mapToDouble(SubordinateVo::getStationCount).sum(); |
|
|
|
|
// 计算 :集团发电占比 电站利用率 容量利用率
|
|
|
|
|
return list.stream().map(subordinate ->{ |
|
|
|
|
if (Math.abs(sumGeneration) <= 0) { |
|
|
|
|
subordinate.setGenerationRate(0.0); |
|
|
|
|
} else { |
|
|
|
|
subordinate.setGenerationRate(BigDecimal.valueOf(subordinate.getGeneration() / sumGeneration * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); |
|
|
|
|
} |
|
|
|
|
if (Math.abs(sumLoad) <= 0) { |
|
|
|
|
subordinate.setCapacityUse(0.0); |
|
|
|
|
} else { |
|
|
|
|
subordinate.setCapacityUse(BigDecimal.valueOf(subordinate.getLoad() / sumLoad * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); |
|
|
|
|
} |
|
|
|
|
if (Math.abs(sumStationCount) <= 0) { |
|
|
|
|
subordinate.setStationUse(0.0); |
|
|
|
|
} else { |
|
|
|
|
subordinate.setStationUse(BigDecimal.valueOf(subordinate.getStationUseCount() / sumStationCount * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); |
|
|
|
|
} |
|
|
|
|
return subordinate; |
|
|
|
|
}).sorted(Comparator.comparing(SubordinateVo::getCapacity)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|