yang_shj
4 months ago
18 changed files with 641 additions and 63 deletions
@ -0,0 +1,26 @@
|
||||
package com.hnac.hzims.operational.homePage.Hydroelectric.vo; |
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
||||
import com.fasterxml.jackson.databind.ser.std.NullSerializer; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "站点首页-设备近30天发电量") |
||||
public class HydroelectricDeviceGenerateVo { |
||||
|
||||
@ApiModelProperty(value = "日期") |
||||
private String date; |
||||
|
||||
@ApiModelProperty(value = "发电量") |
||||
@JsonSerialize(nullsUsing = NullSerializer.class) |
||||
private Float generate; |
||||
|
||||
@ApiModelProperty(value = "功率") |
||||
@JsonSerialize(nullsUsing = NullSerializer.class) |
||||
private Float load; |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.hnac.hzims.operational.homePage.Hydroelectric.vo; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "站点首页-设备近24小时功率曲线") |
||||
public class HydroelectricDevicePowerVo { |
||||
|
||||
@ApiModelProperty(value = "字符串时间") |
||||
private String strHour; |
||||
|
||||
@ApiModelProperty(value = "小时") |
||||
private Integer hour; |
||||
|
||||
@ApiModelProperty(value = "有功功率") |
||||
private String activePower; |
||||
} |
@ -0,0 +1,72 @@
|
||||
package com.hnac.hzims.operational.homePage.Hydroelectric.vo; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "站点首页-设备信息") |
||||
public class HydroelectricDeviceVo { |
||||
|
||||
@ApiModelProperty(value = "设备编号") |
||||
private String deivceCode; |
||||
|
||||
@ApiModelProperty(value = "设备名称") |
||||
private String deivceName; |
||||
|
||||
@ApiModelProperty(value = "开关机状态: 0 - 关机 1 - 开机") |
||||
private Boolean state; |
||||
|
||||
@ApiModelProperty(value = "总装机容量") |
||||
private Double installedCapacity; |
||||
|
||||
@ApiModelProperty(value = "有功功率") |
||||
private Double activePower; |
||||
|
||||
@ApiModelProperty(value = "容量利用率") |
||||
private Double capacityRate; |
||||
|
||||
@ApiModelProperty(value = "无功功率") |
||||
private Double reactivePower; |
||||
|
||||
@ApiModelProperty(value = "导叶开度") |
||||
private Double guideOpen; |
||||
|
||||
@ApiModelProperty(value = "今日发电量") |
||||
private Float powerDay; |
||||
|
||||
@ApiModelProperty(value = "昨日发电量") |
||||
private Float powerYesterDay; |
||||
|
||||
@ApiModelProperty(value = "当年发电量") |
||||
private Float powerYear; |
||||
|
||||
@ApiModelProperty(value = "去年发电量") |
||||
private Float powerYesterYear; |
||||
|
||||
@ApiModelProperty(value = "当月发电量") |
||||
private Float powerMon; |
||||
|
||||
@ApiModelProperty(value = "本次开机时间") |
||||
private String startDownTime; |
||||
|
||||
@ApiModelProperty(value = "本次开机时长") |
||||
private Double startupDownDuration; |
||||
|
||||
@ApiModelProperty(value = "年停机时长") |
||||
private Double shutDownDurationYear; |
||||
|
||||
@ApiModelProperty(value = "年开机时长") |
||||
private Double startupDurationYear; |
||||
|
||||
@ApiModelProperty(value = "设备近24小时有功功率") |
||||
private List<HydroelectricDevicePowerVo> powers; |
||||
|
||||
@ApiModelProperty(value = "设备近30日发电量") |
||||
private List<HydroelectricDeviceGenerateVo> generates; |
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.hnac.hzims.operational.homePage.Hydroelectric.vo; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "月发电对象") |
||||
public class HydroelectricGenerateMonVo { |
||||
|
||||
@ApiModelProperty(value = "年份") |
||||
private Integer year; |
||||
|
||||
@ApiModelProperty(value = "月份") |
||||
private Integer month; |
||||
|
||||
@ApiModelProperty(value = "字符串格式月份") |
||||
private String strMonth; |
||||
|
||||
@ApiModelProperty(value = "月发电量") |
||||
private Double power; |
||||
|
||||
@ApiModelProperty(value = "计划发电量") |
||||
private Double planPower; |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.hnac.hzims.operational.homePage.Hydroelectric.vo; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "站点首页-最近30日发电量/降雨量") |
||||
public class HydroelectricPowerRainVo { |
||||
|
||||
@ApiModelProperty(value = "日期") |
||||
private String date; |
||||
|
||||
@ApiModelProperty(value = "发电量") |
||||
private Double generate; |
||||
|
||||
@ApiModelProperty(value = "降雨") |
||||
private Double rain; |
||||
} |
@ -0,0 +1,68 @@
|
||||
package com.hnac.hzims.operational.homePage.Hydroelectric.vo; |
||||
|
||||
import com.hnac.hzims.hzimsweather.response.weather.Daily; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "水电站首页-站点") |
||||
public class HydroelectricStationVo { |
||||
|
||||
|
||||
@ApiModelProperty(value = "站点编号") |
||||
private String stationCode; |
||||
|
||||
@ApiModelProperty(value = "站点名称") |
||||
private String stationName; |
||||
|
||||
@ApiModelProperty(value = "总装机容量") |
||||
private Double installedCapacity; |
||||
|
||||
@ApiModelProperty(value = "总发电负荷") |
||||
private Double powerSum; |
||||
|
||||
@ApiModelProperty(value = "容量利用率") |
||||
private Double capacityRate; |
||||
|
||||
@ApiModelProperty(value = "月计划发电量") |
||||
private Double powerMonPlan; |
||||
|
||||
@ApiModelProperty(value = "月发电量") |
||||
private Double powerMon; |
||||
|
||||
@ApiModelProperty(value = "月发电量完成率") |
||||
private Double powerRateMon; |
||||
|
||||
@ApiModelProperty(value = "年计划发电量") |
||||
private Double powerYearPlan; |
||||
|
||||
@ApiModelProperty(value = "年发电量") |
||||
private Double powerYear; |
||||
|
||||
@ApiModelProperty(value = "年发电完成率") |
||||
private Double powerRateYear; |
||||
|
||||
@ApiModelProperty(value = "今日发电量") |
||||
private Double powerDay; |
||||
|
||||
@ApiModelProperty(value = "昨日发电量") |
||||
private Double powerYesterDay; |
||||
|
||||
@ApiModelProperty(value = "七日内天气") |
||||
private List<Daily> weather; |
||||
|
||||
@ApiModelProperty(value = "设备集合") |
||||
private List<HydroelectricDeviceVo> devices; |
||||
|
||||
@ApiModelProperty(value = "降雨/发电量曲线") |
||||
private List<HydroelectricPowerRainVo> powerRains; |
||||
|
||||
@ApiModelProperty(value = "降雨/发电量曲线") |
||||
private List<HydroelectricGenerateMonVo> generateMons; |
||||
} |
@ -1,4 +1,4 @@
|
||||
package com.hnac.hzims.operational.home.wind; |
||||
package com.hnac.hzims.operational.homePage.wind.vo; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
@ -1,26 +0,0 @@
|
||||
package com.hnac.hzims.operational.main.vo.pv; |
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
||||
import com.fasterxml.jackson.databind.ser.std.NullSerializer; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "当日机组有功功率") |
||||
public class PowerRainVo { |
||||
|
||||
@ApiModelProperty(value = "日期") |
||||
private String date; |
||||
|
||||
@ApiModelProperty(value = "发电量") |
||||
@JsonSerialize(nullsUsing = NullSerializer.class) |
||||
private Double generate; |
||||
|
||||
@ApiModelProperty(value = "降雨") |
||||
@JsonSerialize(nullsUsing = NullSerializer.class) |
||||
private Double rain; |
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.hnac.hzims.operational.homePage.controller; |
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import com.hnac.hzims.operational.homePage.Hydroelectric.vo.HydroelectricStationVo; |
||||
import com.hnac.hzims.operational.homePage.service.HydroelectricService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/hydroelectric") |
||||
@Api(value = "水电站-首页", tags = "水电站-首页") |
||||
@AllArgsConstructor |
||||
public class HydroelectricController extends BladeController { |
||||
|
||||
|
||||
private final HydroelectricService hydroelectricService; |
||||
|
||||
@ApiOperation("水电站站点指标") |
||||
@GetMapping("/station") |
||||
@ApiOperationSupport(order = 1) |
||||
public R<HydroelectricStationVo> station(@RequestParam("deptId") Long deptId) { |
||||
return R.data(hydroelectricService.station(deptId)); |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.hnac.hzims.operational.homePage.service; |
||||
|
||||
import com.hnac.hzims.operational.homePage.Hydroelectric.vo.HydroelectricStationVo; |
||||
|
||||
/** |
||||
* 水电站-首页接口 |
||||
* @author ysj |
||||
*/ |
||||
public interface HydroelectricService { |
||||
|
||||
HydroelectricStationVo station(Long deptId); |
||||
} |
@ -0,0 +1,315 @@
|
||||
package com.hnac.hzims.operational.homePage.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.alibaba.fastjson.TypeReference; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.hnac.hzims.equipment.feign.IPlanGenertionClient; |
||||
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; |
||||
import com.hnac.hzims.equipment.vo.PlanPowerYearVo; |
||||
import com.hnac.hzims.hzimsweather.feign.IRainfallClient; |
||||
import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; |
||||
import com.hnac.hzims.operational.homePage.Hydroelectric.vo.*; |
||||
import com.hnac.hzims.operational.homePage.service.HydroelectricService; |
||||
import com.hnac.hzims.operational.main.service.IWeatherService; |
||||
import com.hnac.hzims.operational.main.vo.HydropowerUnitRealVo; |
||||
import com.hnac.hzims.operational.main.vo.HydropowerUnitTargetVo; |
||||
import com.hnac.hzims.operational.station.entity.StationEntity; |
||||
import com.hnac.hzims.operational.station.service.IStationService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.BeanUtil; |
||||
import org.springblade.core.tool.utils.CollectionUtil; |
||||
import org.springblade.core.tool.utils.DateUtil; |
||||
import org.springblade.core.tool.utils.ObjectUtil; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.math.RoundingMode; |
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* 水电站-首页接口实现类 |
||||
* @author ysj |
||||
*/ |
||||
@Service |
||||
@RequiredArgsConstructor |
||||
@Slf4j |
||||
public class HydroelectricServiceImpl implements HydroelectricService { |
||||
|
||||
|
||||
private final IStationService stationService; |
||||
|
||||
private final IWeatherService weatherService; |
||||
|
||||
private final IRainfallClient rainClient; |
||||
|
||||
private final IPlanGenertionClient planClient; |
||||
|
||||
private final RedisTemplate redisTemplate; |
||||
|
||||
private final static String RECENT_YEAR_POWER_DATA = "hzims:operation:key:power:data"; |
||||
private final static String LOAD_HYDROPOWER_REAL_KEY = "hzims:operation:loadhydropowerunit:real:key"; |
||||
private final static String LOAD_HYDROPOWER_TARGET_KEY = "hzims:operation:loadhydropowerunit:target:key"; |
||||
private final static String DEVICE_CACHE_COFIG_FINAL = "hzims:equipment:emInfo:deviceCode.emInfoList"; |
||||
|
||||
/** |
||||
* 水电站首页-站点首页 |
||||
* @param deptId |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public HydroelectricStationVo station(Long deptId) { |
||||
// 步骤1.查询站点
|
||||
StationEntity station = stationService.getOne(Wrappers.<StationEntity>lambdaQuery().eq(StationEntity::getRefDept,deptId)); |
||||
if(ObjectUtil.isEmpty(station)){ |
||||
return new HydroelectricStationVo(); |
||||
} |
||||
// 步骤2.数据准备
|
||||
// 设备
|
||||
List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(DEVICE_CACHE_COFIG_FINAL).toString(),new TypeReference<List<EminfoAndEmParamVo>>() {}); |
||||
// 实时数据
|
||||
List<HydropowerUnitRealVo> reals = (List<HydropowerUnitRealVo>) redisTemplate.opsForValue().get(LOAD_HYDROPOWER_REAL_KEY); |
||||
// 指标数据
|
||||
List<HydropowerUnitTargetVo> targets = (List<HydropowerUnitTargetVo>) redisTemplate.opsForValue().get(LOAD_HYDROPOWER_TARGET_KEY); |
||||
// 降雨数据
|
||||
List<Map<String, Object>> rains = this.nearThirtyRains(station.getCode()); |
||||
// 七日天气
|
||||
Map<String, HeWeatherWeatherDailyResponse> weathers = this.weekWeather(Collections.singletonList(station.getCode())); |
||||
// 近3年发电量
|
||||
Map<String, Map<String, Float>> map = (Map<String, Map<String, Float>>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); |
||||
// 计划发电量
|
||||
List<PlanPowerYearVo> plans = planClient.getPlanPowerByYear(station.getCode(), Integer.parseInt(DateUtil.format(new Date(),"yyyy"))); |
||||
|
||||
// 步骤3.数据处理、赋值
|
||||
HydroelectricStationVo result = new HydroelectricStationVo(); |
||||
result.setStationCode(station.getCode()); |
||||
result.setStationName(station.getName()); |
||||
// 天气
|
||||
if(MapUtils.isNotEmpty(weathers) && weathers.containsKey(station.getCode())){ |
||||
HeWeatherWeatherDailyResponse week = weathers.get(station.getCode()); |
||||
if(ObjectUtil.isNotEmpty(week) && CollectionUtil.isNotEmpty(week.getDaily())){ |
||||
result.setWeather(week.getDaily()); |
||||
} |
||||
} |
||||
// 设备
|
||||
if(CollectionUtil.isNotEmpty(devices)){ |
||||
result.setDevices(devices.stream().map(iter->{ |
||||
HydroelectricDeviceVo device = new HydroelectricDeviceVo(); |
||||
Optional<HydropowerUnitRealVo> real = reals.stream().filter(o-> iter.getEmCode().equals(o.getDeviceCode())).findFirst(); |
||||
// 实时数据
|
||||
if(real.isPresent()){ |
||||
device.setState(real.get().getState()); |
||||
device.setInstalledCapacity(real.get().getInstalledCapacity()); |
||||
device.setActivePower(real.get().getActivePower()); |
||||
device.setReactivePower(real.get().getReactivePower()); |
||||
device.setGuideOpen(real.get().getGuideOpen()); |
||||
if(device.getActivePower() > 0 && device.getReactivePower() > 0){ |
||||
device.setCapacityRate(BigDecimal.valueOf(device.getActivePower() / device.getInstalledCapacity() * 100).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
||||
}else{ |
||||
device.setCapacityRate(0.0); |
||||
} |
||||
} |
||||
// 指标数据
|
||||
Optional<HydropowerUnitTargetVo> target = targets.stream().filter(o-> iter.getEmCode().equals(o.getDeviceCode())).findFirst(); |
||||
if(target.isPresent()){ |
||||
device.setPowerDay(target.get().getPowerDay()); |
||||
device.setPowerYesterDay(target.get().getPowerYesterDay()); |
||||
device.setPowerYear(target.get().getPowerYear()); |
||||
device.setPowerYesterYear(target.get().getPowerYesterYear()); |
||||
device.setPowerMon(target.get().getPowerMon()); |
||||
device.setStartDownTime(target.get().getStartDownTime()); |
||||
device.setStartupDownDuration(target.get().getStartupDownDuration()); |
||||
device.setStartupDurationYear(target.get().getStartupDurationYear()); |
||||
device.setShutDownDurationYear(target.get().getShutDownDurationYear()); |
||||
if(CollectionUtil.isNotEmpty(target.get().getActivePowerVoList())){ |
||||
device.setPowers(target.get().getActivePowerVoList().stream().map(o-> BeanUtil.copy(o, HydroelectricDevicePowerVo.class)).collect(Collectors.toList())); |
||||
} |
||||
if(CollectionUtil.isNotEmpty(target.get().getActivePowerVoList())){ |
||||
device.setGenerates(target.get().getGenerationPowerVoList().stream().map(o-> BeanUtil.copy(o, HydroelectricDeviceGenerateVo.class)).collect(Collectors.toList())); |
||||
} |
||||
} |
||||
return device; |
||||
}).collect(Collectors.toList())); |
||||
} |
||||
// 站点指标数据
|
||||
if(CollectionUtil.isNotEmpty(result.getDevices())){ |
||||
// 装机容量、发电负荷
|
||||
result.setInstalledCapacity(result.getDevices().stream().mapToDouble(HydroelectricDeviceVo::getInstalledCapacity).sum()); |
||||
result.setPowerSum(result.getDevices().stream().mapToDouble(HydroelectricDeviceVo::getActivePower).sum()); |
||||
if(result.getInstalledCapacity() > 0 && result.getPowerSum() > 0 ){ |
||||
result.setCapacityRate(BigDecimal.valueOf(result.getPowerSum() / result.getInstalledCapacity() * 100).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
||||
}else{ |
||||
result.setCapacityRate(0.0); |
||||
} |
||||
// 月计划发电量、月已发电量
|
||||
if(CollectionUtil.isNotEmpty(plans)){ |
||||
result.setPowerMonPlan(plans.stream().filter(plan -> plan.getMon().contains(DateUtil.format(new Date(),"yyyy-NM"))).mapToDouble(PlanPowerYearVo::getPlanPower).sum()); |
||||
}else{ |
||||
result.setPowerMonPlan(0.0); |
||||
} |
||||
result.setPowerMon(result.getDevices().stream().mapToDouble(HydroelectricDeviceVo::getPowerMon).sum()); |
||||
|
||||
// 年计划发电量、年已发电量
|
||||
if(CollectionUtil.isNotEmpty(plans)){ |
||||
result.setPowerYearPlan(plans.stream().mapToDouble(PlanPowerYearVo::getPlanPower).sum()); |
||||
}else{ |
||||
result.setPowerYearPlan(0.0); |
||||
} |
||||
result.setPowerYear(result.getDevices().stream().mapToDouble(HydroelectricDeviceVo::getPowerYear).sum()); |
||||
|
||||
// 今日发电量、昨日发电量
|
||||
result.setPowerDay(result.getDevices().stream().mapToDouble(HydroelectricDeviceVo::getPowerDay).sum()); |
||||
result.setPowerYesterDay(result.getDevices().stream().mapToDouble(HydroelectricDeviceVo::getPowerYesterDay).sum()); |
||||
|
||||
// 近30日降雨量/发电量
|
||||
result.setPowerRains(this.stationPowerRains(result.getDevices(),rains)); |
||||
// 电站月发电/计划发电
|
||||
result.setGenerateMons(this.stationGenerateMons(plans,map.get(station.getCode()))); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 站点近30天降雨数据 |
||||
* @param station |
||||
* @return |
||||
*/ |
||||
private List<Map<String, Object>> nearThirtyRains(String station) { |
||||
Calendar calendar = Calendar.getInstance(); |
||||
calendar.add(Calendar.DAY_OF_MONTH,-1); |
||||
String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); |
||||
calendar.add(Calendar.DAY_OF_MONTH,-29); |
||||
String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); |
||||
R<List<Map<String, Object>>> rains = rainClient.getDurationRainFall(station,start,end); |
||||
if(!rains.isSuccess() || CollectionUtil.isEmpty(rains.getData())){ |
||||
return new ArrayList<>(); |
||||
} |
||||
return rains.getData(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 站点七天天气 |
||||
* @param stations |
||||
*/ |
||||
private Map<String, HeWeatherWeatherDailyResponse> weekWeather(List stations) { |
||||
if(CollectionUtil.isEmpty(stations)){ |
||||
return new HashMap<>(); |
||||
} |
||||
// 实时天气
|
||||
return weatherService.getWeekWeather(stations); |
||||
} |
||||
|
||||
/** |
||||
* 站点近30天降雨量/发电量 |
||||
* @param devices |
||||
* @return |
||||
*/ |
||||
private List<HydroelectricPowerRainVo> stationPowerRains(List<HydroelectricDeviceVo> devices,List<Map<String, Object>> rains) { |
||||
List<HydroelectricDeviceGenerateVo> generates = new ArrayList<>(); |
||||
devices.forEach(device->{ |
||||
generates.addAll(device.getGenerates()); |
||||
}); |
||||
Calendar calendar = Calendar.getInstance(); |
||||
Date end = calendar.getTime(); |
||||
calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); |
||||
calendar.add(Calendar.MINUTE,-calendar.get(Calendar.MINUTE)); |
||||
calendar.add(Calendar.SECOND,-calendar.get(Calendar.SECOND)); |
||||
calendar.add(Calendar.DAY_OF_MONTH,-29); |
||||
Date start = calendar.getTime(); |
||||
List<HydroelectricPowerRainVo> powerRains = new ArrayList<>(); |
||||
while (start.compareTo(end) < 0) { |
||||
HydroelectricPowerRainVo powerRain = new HydroelectricPowerRainVo(); |
||||
// 日期
|
||||
powerRain.setDate(DateUtil.format(calendar.getTime(),"yyyy-MM-dd")); |
||||
// 发电量
|
||||
powerRain.setGenerate(generates.stream().filter(o-> powerRain.getDate().equals(o.getDate())).mapToDouble(HydroelectricDeviceGenerateVo::getGenerate).sum()); |
||||
// 降雨量
|
||||
if(CollectionUtil.isNotEmpty(rains)){ |
||||
powerRain.setRain(rains.stream().mapToDouble(map->{ |
||||
if (map.get("fx_date").equals(powerRain.getDate())) { |
||||
Object object = map.get("precip"); |
||||
if(ObjectUtil.isEmpty(object)){ |
||||
return 0.0; |
||||
}else{ |
||||
return Double.parseDouble(object.toString()); |
||||
} |
||||
} |
||||
return 0.0; |
||||
}).sum()); |
||||
}else{ |
||||
powerRain.setRain(0.0); |
||||
} |
||||
powerRains.add(powerRain); |
||||
calendar.add(Calendar.DAY_OF_MONTH,1); |
||||
start = calendar.getTime(); |
||||
} |
||||
return powerRains; |
||||
} |
||||
|
||||
/** |
||||
* 站点电站月发电/计划发电 |
||||
* @param plans |
||||
* @param map |
||||
* @return |
||||
*/ |
||||
private List<HydroelectricGenerateMonVo> stationGenerateMons(List<PlanPowerYearVo> plans, Map<String, Float> map) { |
||||
// 获取月份集合
|
||||
List<String> mons = this.mons(0,12,false); |
||||
return mons.stream().map(mon->{ |
||||
Date date = DateUtil.parse(mon,DateUtil.PATTERN_DATE); |
||||
HydroelectricGenerateMonVo generateMon = new HydroelectricGenerateMonVo(); |
||||
generateMon.setStrMonth(mon); |
||||
generateMon.setYear(date.getYear()); |
||||
generateMon.setMonth(date.getMonth() + 1); |
||||
// 计划发电量
|
||||
if(CollectionUtil.isNotEmpty(plans)){ |
||||
generateMon.setPlanPower(plans.stream().filter(plan -> plan.getMon().contains(DateUtil.format(date,"yyyy-MM"))).mapToDouble(PlanPowerYearVo::getPlanPower).sum()); |
||||
}else{ |
||||
generateMon.setPlanPower(0.0); |
||||
} |
||||
// 实际发电
|
||||
if(MapUtils.isNotEmpty(map)){ |
||||
generateMon.setPower(map.entrySet().stream().filter(entry->entry.getKey().equals(mon)).mapToDouble(Map.Entry::getValue).sum()); |
||||
}else{ |
||||
generateMon.setPlanPower(0.0); |
||||
} |
||||
return generateMon; |
||||
}).collect(Collectors.toList()); |
||||
} |
||||
|
||||
/** |
||||
* 获取近年月份集合 |
||||
* @param year |
||||
* @return |
||||
*/ |
||||
public List<String> mons(int year, int endMoth, boolean nextMon) { |
||||
List<String> list = new ArrayList<>(); |
||||
// 开始日期
|
||||
Calendar endCal = Calendar.getInstance(); |
||||
endCal.setTime(new Date()); |
||||
endCal.add(Calendar.MONTH, -endCal.get(Calendar.MONTH) + endMoth); |
||||
endCal.add(Calendar.DATE, -endCal.get(Calendar.DATE) + 1); |
||||
|
||||
// 结束日期
|
||||
Calendar startCal = Calendar.getInstance(); |
||||
startCal.setTime(new Date()); |
||||
startCal.set(Calendar.YEAR, startCal.get(Calendar.YEAR) - year); |
||||
startCal.add(Calendar.MONTH, -startCal.get(Calendar.MONTH)); |
||||
startCal.add(Calendar.DATE, -startCal.get(Calendar.DATE) + 1); |
||||
// 获取日期之间的月份
|
||||
while (endCal.after(startCal)) { |
||||
list.add(DateUtil.format(startCal.getTime(),DateUtil.PATTERN_DATE)); |
||||
startCal.add(Calendar.MONTH, 1); |
||||
} |
||||
if(nextMon){ |
||||
list.add(DateUtil.format(endCal.getTime(),DateUtil.PATTERN_DATE)); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue