@ -1,22 +1,42 @@
package com.hnac.hzims.operational.main.service.impl ;
import com.alibaba.fastjson.JSONObject ;
import com.alibaba.fastjson.TypeReference ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.toolkit.Wrappers ;
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.fill.entity.WindEntity ;
import com.hnac.hzims.operational.fill.service.WindService ;
import com.hnac.hzims.operational.main.constant.HomePageConstant ;
import com.hnac.hzims.operational.main.service.AreaService ;
import com.hnac.hzims.operational.main.service.IWeatherService ;
import com.hnac.hzims.operational.main.service.WindHomeService ;
import com.hnac.hzims.operational.main.vo.WindScoreVo ;
import com.hnac.hzims.operational.main.vo.* ;
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.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.data.redis.core.RedisTemplate ;
import org.springframework.stereotype.Service ;
import java.math.BigDecimal ;
import java.util.Date ;
import java.util.List ;
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 ;
/ * *
@ -27,10 +47,25 @@ import java.util.stream.Collectors;
@Slf4j
public class WindHomeServiceImpl implements WindHomeService {
private final WindService windService ;
private final AreaService areaService ;
private final IWeatherService weatherService ;
private final IStationService stationService ;
private final WindService windService ;
private final RedisTemplate redisTemplate ;
private final ISysClient sysClient ;
public final static String device_cache_final = "hzims:equipment:emInfo:deviceCode.emInfoList" ;
/ * *
* 集团 / 区域指标数据
* @param deptId
* @return
* /
@Override
public WindScoreVo KPIs ( Long deptId ) {
// 查询风电站
@ -38,74 +73,405 @@ public class WindHomeServiceImpl implements WindHomeService {
eq ( StationEntity : : getServeType , HomePageConstant . HYDROPOWER_SERVETYPE ) ;
eq ( StationEntity : : getType , HomePageConstant . WIND_POWER ) ;
} } ) ;
if ( CollectionUtil . isNot Empty ( stations ) ) {
if ( CollectionUtil . isEmpty ( stations ) ) {
return new WindScoreVo ( ) ;
}
// 查询站点年填报数据
List < WindEntity > years = windService . list ( new LambdaQueryWrapper < WindEntity > ( ) { {
like ( WindEntity : : getFillDate , DateUtil . format ( new Date ( ) , "yyyy" ) ) ;
in ( WindEntity : : getStationCode , stations . stream ( ) . map ( StationEntity : : getCode ) . collect ( Collectors . toList ( ) ) ) ;
} } ) ;
// 查询站点月填报数据
List < WindEntity > mons = windService . list ( new LambdaQueryWrapper < WindEntity > ( ) { {
like ( WindEntity : : getFillDate , DateUtil . format ( new Date ( ) , "yyyy-MM" ) ) ;
in ( WindEntity : : getStationCode , stations . stream ( ) . map ( StationEntity : : getCode ) . collect ( Collectors . toList ( ) ) ) ;
} } ) ;
// 查询站点日填报数据
List < WindEntity > days = windService . list ( new LambdaQueryWrapper < WindEntity > ( ) { {
like ( WindEntity : : getFillDate , DateUtil . format ( new Date ( ) , DateUtil . format ( new Date ( ) , DateUtil . PATTERN_DATE ) ) ) ;
// 查询站点填报数据
List < WindEntity > winds = windService . list ( new LambdaQueryWrapper < WindEntity > ( ) { {
in ( WindEntity : : getStationCode , stations . stream ( ) . map ( StationEntity : : getCode ) . collect ( Collectors . toList ( ) ) ) ;
} } ) ;
WindScoreVo score = new WindScoreVo ( ) ;
// 站点数量
score . setStationCount ( stations . size ( ) ) ;
this . year ( years , score ) ;
this . mon ( mons , score ) ;
this . days ( days , score ) ;
if ( CollectionUtil . isEmpty ( winds ) ) {
return score ;
}
// 装机容量
List < EminfoAndEmParamVo > devices = JSONObject . parseObject ( redisTemplate . opsForValue ( ) . get ( device_cache_final ) . toString ( ) , new TypeReference < List < EminfoAndEmParamVo > > ( ) { } ) ;
if ( CollectionUtil . isNotEmpty ( devices ) ) {
score . setInstalledCapacity ( devices . stream ( ) . filter ( o - > stations . stream ( ) . map ( StationEntity : : getRefDept ) . collect ( Collectors . toList ( ) ) . contains ( o . getCreateDept ( ) ) ) . mapToDouble ( EminfoAndEmParamVo : : getInstalledCapacity ) . sum ( ) ) ;
}
// 年发电量
score . setGenerateYear ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , "yyyy" ) ) ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
// 年计划发电量
score . setPlanYear ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , "yyyy" ) ) ) . mapToDouble ( WindEntity : : getPlan ) . sum ( ) ) ;
// 年发电完成率
if ( Math . abs ( score . getGenerateYear ( ) ) > 0 & & Math . abs ( score . getPlanYear ( ) ) > 0 ) {
score . setCompleteRate ( BigDecimal . valueOf ( score . getGenerateYear ( ) / score . getPlanYear ( ) * 100 ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ) ;
}
// 月发电量
score . setGenerateMon ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , "yyyy-MM" ) ) ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
// 月平均风速
score . setSpeedRate ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , "yyyy-MM" ) ) ) . mapToDouble ( WindEntity : : getSpeed ) . average ( ) . getAsDouble ( ) ) ;
// 月短期准确率
score . setAccuracy ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , "yyyy-MM" ) ) ) . mapToDouble ( WindEntity : : getAccuracy ) . average ( ) . getAsDouble ( ) ) ;
// 月超短期准确率
score . setUltraShortAccuracyRate ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , "yyyy-MM" ) ) ) . mapToDouble ( WindEntity : : getUltraShortAccuracy ) . average ( ) . getAsDouble ( ) ) ;
// 日发电量
score . setGenerateDay ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , DateUtil . PATTERN_DATE ) ) ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
// 近年发电量
score . setPowerYearVoList ( this . threeGenerateYear ( winds ) ) ;
// 计划发电完成率
score . setPowerMonthVoList ( this . currentGenerateCurve ( winds ) ) ;
return score ;
}
/ * *
* 风电数据 - 年
* @param years
* @param score
* 近3年发电量
* @param wind s
* @return
* /
private void year ( List < WindEntity > years , WindScoreVo score ) {
if ( CollectionUtil . isNotEmpty ( years ) ) {
return ;
private List < PowerYearVo > threeGenerateYear ( List < WindEntity > winds ) {
List < String > mons = this . mons ( 2 , 12 , false ) ;
// 月份发电量赋值
List < PowerMonthVo > list = mons . stream ( ) . map ( mon - > {
PowerMonthVo power = new PowerMonthVo ( ) ;
LocalDate localDate = LocalDate . parse ( DateUtil . format ( new Date ( ) , mon ) , DateTimeFormatter . ofPattern ( DateUtil . PATTERN_DATE ) ) ;
power . setYear ( localDate . getYear ( ) ) ;
power . setStrMonth ( localDate . getMonthValue ( ) > 9 ? String . valueOf ( localDate . getMonthValue ( ) ) : "0" + localDate . getMonthValue ( ) ) ;
power . setPower ( ( float ) winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( localDate . getYear ( ) + "-" + power . getStrMonth ( ) ) ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
return power ;
} ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtil . isEmpty ( list ) ) {
return new ArrayList < > ( ) ;
}
// 年发电量
score . setGenerateYear ( years . stream ( ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
// 年计划发电量
score . setPlanYear ( years . stream ( ) . mapToDouble ( WindEntity : : getPlan ) . sum ( ) ) ;
// 年发电完成率
if ( Math . abs ( score . getGenerateYear ( ) ) > 0 & & Math . abs ( score . getPlanYear ( ) ) > 0 ) {
score . setSpeedRate ( BigDecimal . valueOf ( score . getGenerateYear ( ) / score . getPlanYear ( ) * 100 ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ) ;
// 转换年份分组
return list . stream ( ) . collect ( Collectors . groupingBy ( PowerMonthVo : : getYear ) ) . entrySet ( ) . stream ( ) . map ( entry - > {
PowerYearVo year = new PowerYearVo ( ) ;
year . setYear ( entry . getKey ( ) ) ;
year . setPowerMonthVoList ( entry . getValue ( ) ) ;
return year ;
} ) . collect ( Collectors . toList ( ) ) ;
}
/ * *
* 年发电量趋势
* @param winds
* @return
* /
private List < PowerMonthVo > currentGenerateCurve ( List < WindEntity > winds ) {
List < String > mons = this . mons ( 0 , 12 , false ) ;
return mons . stream ( ) . map ( mon - > {
PowerMonthVo power = new PowerMonthVo ( ) ;
LocalDate localDate = LocalDate . parse ( DateUtil . format ( new Date ( ) , mon ) , DateTimeFormatter . ofPattern ( DateUtil . PATTERN_DATE ) ) ;
power . setYear ( localDate . getYear ( ) ) ;
power . setStrMonth ( localDate . getMonthValue ( ) > 9 ? String . valueOf ( localDate . getMonthValue ( ) ) : "0" + localDate . getMonthValue ( ) ) ;
power . setPlanPower ( ( float ) winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( localDate . getYear ( ) + "-" + power . getStrMonth ( ) ) ) . mapToDouble ( WindEntity : : getPlan ) . sum ( ) ) ;
power . setPower ( ( float ) winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( localDate . getYear ( ) + "-" + power . getStrMonth ( ) ) ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
return power ;
} ) . collect ( Collectors . toList ( ) ) ;
}
/ * *
* 风电站集团 / 区域占比
* @param deptId
* @return
* /
@Override
public List < WindSubordinateVo > subordinate ( Long deptId ) {
Map < Dept , List < StationEntity > > areas = areaService . areaOrStaion ( deptId , Collections . singletonList ( HomePageConstant . WIND_POWER ) ) ;
if ( MapUtils . isEmpty ( areas ) ) {
return new ArrayList < > ( ) ;
}
// 风电站填报数据查询
List < String > codes = new ArrayList < > ( ) ;
areas . forEach ( ( key , value ) - > codes . addAll ( value . stream ( ) . map ( StationEntity : : getCode ) . collect ( Collectors . toList ( ) ) ) ) ;
List < WindEntity > winds = windService . list ( new LambdaQueryWrapper < WindEntity > ( ) { {
in ( WindEntity : : getStationCode , codes )
. like ( WindEntity : : getFillDate , DateUtil . format ( new Date ( ) , "yyyy" ) ) ;
} } ) ;
// 获取站点编码集合
List < String > stations = areas . values ( ) . stream ( ) . map ( values - > values . get ( 0 ) . getCode ( ) ) . collect ( Collectors . toList ( ) ) ;
// 获取站点实时天气
Map < String , HeWeatherWeatherNowResponse > nowWeather = this . weatherService . getNowWeather ( stations ) ;
// 获取站点7日天气
Map < String , HeWeatherWeatherDailyResponse > weekWeather = this . weatherService . getWeekWeather ( stations ) ;
return areas . entrySet ( ) . stream ( ) . map ( entry - > {
WindSubordinateVo subordinate = new WindSubordinateVo ( ) ;
// 获取第一个站点经纬度、行政编码信息
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 ) ) {
String [ ] arrCode = areaCode . split ( "," ) ;
R < Region > R = sysClient . getRegion ( arrCode [ 1 ] ) ;
if ( R . isSuccess ( ) & & ObjectUtil . isNotEmpty ( R . getData ( ) ) ) {
subordinate . setAreaName ( R . getData ( ) . getName ( ) ) ;
}
}
// 机构Id
subordinate . setDepartId ( entry . getKey ( ) . getId ( ) ) ;
// 机构名称
subordinate . setDepartName ( entry . getKey ( ) . getDeptName ( ) ) ;
// 天气
this . getAreaWearther ( subordinate , nowWeather , weekWeather , entry . getValue ( ) . get ( 0 ) . getCode ( ) ) ;
if ( CollectionUtil . isNotEmpty ( winds ) ) {
List < WindEntity > piece = winds . stream ( ) . filter ( o - > entry . getValue ( ) . stream ( ) . map ( StationEntity : : getCode ) . collect ( Collectors . toList ( ) ) . contains ( o . getStationCode ( ) ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtil . isEmpty ( piece ) ) {
return subordinate ;
}
// 发电量
subordinate . setGeneration ( piece . stream ( ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
// 集团发电占比
if ( Math . abs ( subordinate . getGeneration ( ) ) > 0 & & Math . abs ( winds . stream ( ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) > 0 ) {
subordinate . setGenerationRate ( BigDecimal . valueOf ( subordinate . getGeneration ( ) / winds . stream ( ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) * 100 ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ) ;
}
// 发电完成率
double plan = piece . stream ( ) . mapToDouble ( WindEntity : : getPlan ) . sum ( ) ;
if ( Math . abs ( subordinate . getGeneration ( ) ) > 0 & & Math . abs ( plan ) > 0 ) {
subordinate . setGenerationComplete ( BigDecimal . valueOf ( subordinate . getGeneration ( ) / plan * 100 ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ) ;
}
// 风机利用率 : (总时间 - 故障时间) / 总时间
double fault = piece . stream ( ) . mapToDouble ( WindEntity : : getFaultHours ) . sum ( ) ;
if ( Math . abs ( fault ) > 0 ) {
subordinate . setFanUse ( BigDecimal . valueOf ( fault / ( 30 * 24 ) * 100 ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ) ;
}
// 厂用电率 : (发电量-上网电量+下网电量)/发电量
double surf = piece . stream ( ) . mapToDouble ( WindEntity : : getSurfPower ) . sum ( ) ;
double below = piece . stream ( ) . mapToDouble ( WindEntity : : getBelowPower ) . sum ( ) ;
if ( Math . abs ( subordinate . getGeneration ( ) ) > 0 & & Math . abs ( surf + below ) > 0 ) {
subordinate . setFactoryUse ( BigDecimal . valueOf ( subordinate . getGeneration ( ) - surf + below / subordinate . getGeneration ( ) * 100 ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ) ;
}
}
return subordinate ;
} ) . filter ( o - > Math . abs ( o . getGeneration ( ) ) > 0 | | Math . abs ( o . getGenerationRate ( ) ) > 0 | | Math . abs ( o . getGenerationComplete ( ) ) > 0
| | Math . abs ( o . getFactoryUse ( ) ) > 0 | | Math . abs ( o . getFanUse ( ) ) > 0 ) . sorted ( Comparator . comparing ( WindSubordinateVo : : getGeneration ) . reversed ( ) ) . collect ( Collectors . toList ( ) ) ;
}
/ * *
* 风电数据 - 月
* @param mons
* @param score
* 区域天气
* @param scale
* @param nowWeather
* @param weekWeather
* @param code
* /
private void mon ( List < WindEntity > mons , WindScoreVo score ) {
// 月发电量
score . setGenerateMon ( mons . stream ( ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
// 月平均风速
score . setSpeedRate ( mons . stream ( ) . mapToDouble ( WindEntity : : getSpeed ) . average ( ) . getAsDouble ( ) ) ;
// 月短期准确率
score . setAccuracy ( mons . stream ( ) . mapToDouble ( WindEntity : : getAccuracy ) . average ( ) . getAsDouble ( ) ) ;
// 月超短期准确率
score . setUltraShortAccuracyRate ( mons . stream ( ) . mapToDouble ( WindEntity : : getUltraShortAccuracy ) . average ( ) . getAsDouble ( ) ) ;
private void getAreaWearther ( WindSubordinateVo scale , Map < String , HeWeatherWeatherNowResponse > nowWeather , Map < String , HeWeatherWeatherDailyResponse > weekWeather , String code ) {
// 实时天气
if ( MapUtils . isNotEmpty ( nowWeather ) & & nowWeather . containsKey ( code ) ) {
HeWeatherWeatherNowResponse nowData = nowWeather . get ( code ) ;
if ( ObjectUtil . isNotEmpty ( nowData . getNow ( ) ) ) {
scale . setTemp ( nowData . getNow ( ) . getTemp ( ) ) ;
}
}
// 站点七日内天气
if ( MapUtils . isNotEmpty ( weekWeather ) & & weekWeather . containsKey ( code ) ) {
HeWeatherWeatherDailyResponse weekData = weekWeather . get ( code ) ;
List < Daily > dailyList = weekData . getDaily ( ) ;
if ( CollectionUtil . isNotEmpty ( dailyList ) ) {
scale . setWeather ( dailyList ) ;
}
}
}
/ * *
* 风电数据 - 日
* @param days
* @param score
* 站点指标数据
* @param deptId
* @return
* /
private void days ( List < WindEntity > days , WindScoreVo score ) {
// 日发电量
score . setGenerateDay ( days . stream ( ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
@Override
public WindStationVo station ( Long deptId ) {
StationEntity station = stationService . getOne ( Wrappers . < StationEntity > lambdaQuery ( )
. eq ( StationEntity : : getRefDept , deptId )
) ;
if ( ObjectUtil . isEmpty ( station ) ) {
return new WindStationVo ( ) ;
}
WindStationVo wind = new WindStationVo ( ) ;
// 机构编码
wind . setDepartId ( station . getRefDept ( ) ) ;
// 机构名称
wind . setDepartName ( station . getName ( ) ) ;
// 站点行政区域编码
if ( ! StringUtil . isEmpty ( station . getAreaCode ( ) ) ) {
String [ ] code = station . getAreaCode ( ) . split ( "," ) ;
wind . setAreaCode ( code [ code . length - 1 ] ) ;
}
// 站点七天天气
Map < String , HeWeatherWeatherDailyResponse > weekWeather = weatherService . getWeekWeather ( Collections . singletonList ( station . getCode ( ) ) ) ;
wind . setWeather ( this . getDailyList ( weekWeather , station . getCode ( ) ) ) ;
// 安全运行天数
if ( ObjectUtil . isNotEmpty ( station . getCommissionTime ( ) ) ) {
wind . setRunDay ( Duration . between ( station . getCommissionTime ( ) , LocalDateTime . now ( ) ) . toDays ( ) ) ;
}
// 设备
List < EminfoAndEmParamVo > devices = JSONObject . parseObject ( redisTemplate . opsForValue ( ) . get ( device_cache_final ) . toString ( ) , new TypeReference < List < EminfoAndEmParamVo > > ( ) { } ) ;
if ( CollectionUtil . isNotEmpty ( devices ) ) {
// 装机容量
wind . setCapacity ( devices . stream ( ) . filter ( device - > device . getCreateDept ( ) . equals ( station . getRefDept ( ) ) ) . mapToDouble ( EminfoAndEmParamVo : : getInstalledCapacity ) . sum ( ) ) ;
// 设备列表
wind . setDevices ( devices . stream ( ) . filter ( device - > device . getCreateDept ( ) . equals ( station . getRefDept ( ) ) ) . map ( item - > {
WindDeviceVo windDevice = new WindDeviceVo ( ) ;
windDevice . setDeptId ( item . getCreateDept ( ) ) ;
windDevice . setCode ( item . getEmCode ( ) ) ;
windDevice . setName ( item . getName ( ) ) ;
windDevice . setOrd ( item . getOrd ( ) ) ;
windDevice . setLgtd ( item . getLgtd ( ) ) ;
windDevice . setLttd ( item . getLttd ( ) ) ;
return windDevice ;
} ) . collect ( Collectors . toList ( ) ) ) ;
}
// 查询站点填报数据 - 全部
List < WindEntity > all = windService . list ( Wrappers . < WindEntity > lambdaQuery ( )
. eq ( WindEntity : : getStationCode , station . getCode ( ) )
) ;
if ( CollectionUtil . isNotEmpty ( all ) ) {
// 年计划发电量
wind . setPlanYear ( all . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , "yyyy" ) ) ) . mapToDouble ( WindEntity : : getPlan ) . sum ( ) ) ;
// 月计划发电量
wind . setPlanMon ( all . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , "yyyy-MM" ) ) ) . mapToDouble ( WindEntity : : getPlan ) . sum ( ) ) ;
// 总发电量
wind . setGeneration ( all . stream ( ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
// 日上网电量
wind . setGenerationDay ( all . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , DateUtil . PATTERN_DATE ) ) ) . mapToDouble ( WindEntity : : getSurfPower ) . sum ( ) ) ;
// 日平均风速
wind . setSpeed ( all . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , DateUtil . PATTERN_DATE ) ) ) . mapToDouble ( WindEntity : : getSpeed ) . sum ( ) ) ;
// 日峰值功率
wind . setPeak ( all . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , DateUtil . PATTERN_DATE ) ) ) . mapToDouble ( WindEntity : : getPeakPower ) . sum ( ) ) ;
// 日综合厂用电量
wind . setComprehensivePower ( all . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , DateUtil . PATTERN_DATE ) ) ) . mapToDouble ( WindEntity : : getComprehensivePower ) . sum ( ) ) ;
// 日可用时长
wind . setAvailable ( all . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( DateUtil . format ( new Date ( ) , DateUtil . PATTERN_DATE ) ) ) . mapToDouble ( WindEntity : : getAvailable ) . sum ( ) ) ;
}
return wind ;
}
/ * *
* 风电站点发电量柱状数据
* @param deptId
* @return
* /
@Override
public List < WindGenerationVo > generation ( Long deptId ) {
StationEntity station = stationService . getOne ( Wrappers . < StationEntity > lambdaQuery ( )
. eq ( StationEntity : : getRefDept , deptId )
) ;
if ( ObjectUtil . isEmpty ( station ) ) {
return new ArrayList < > ( ) ;
}
// 查询风电填报数据
List < WindEntity > winds = windService . list ( Wrappers . < WindEntity > lambdaQuery ( )
. eq ( WindEntity : : getStationCode , station . getCode ( ) )
) ;
if ( CollectionUtil . isEmpty ( winds ) ) {
return new ArrayList < > ( ) ;
}
List < String > monList = this . mons ( 1 , 12 , false ) ;
return monList . stream ( ) . map ( mon - > {
LocalDate localDate = LocalDate . parse ( DateUtil . format ( new Date ( ) , mon ) , DateTimeFormatter . ofPattern ( DateUtil . PATTERN_DATE ) ) ;
WindGenerationVo generation = new WindGenerationVo ( ) ;
generation . setYear ( localDate . getYear ( ) ) ;
generation . setMon ( localDate . getMonthValue ( ) > 9 ? String . valueOf ( localDate . getMonthValue ( ) ) : "0" + localDate . getMonthValue ( ) ) ;
generation . setPlan ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( generation . getYear ( ) + "-" + generation . getMon ( ) ) ) . mapToDouble ( WindEntity : : getPlan ) . sum ( ) ) ;
generation . setGeneration ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( generation . getYear ( ) + "-" + generation . getMon ( ) ) ) . mapToDouble ( WindEntity : : getPower ) . sum ( ) ) ;
return generation ;
} ) . collect ( Collectors . toList ( ) ) ;
}
/ * *
* 风电站点月份曲线数据
* @param deptId
* @return
* /
@Override
public List < WindTargetCurveVo > target_curve ( Long deptId ) {
StationEntity station = stationService . getOne ( Wrappers . < StationEntity > lambdaQuery ( )
. eq ( StationEntity : : getRefDept , deptId )
) ;
if ( ObjectUtil . isEmpty ( station ) ) {
return new ArrayList < > ( ) ;
}
// 查询风电填报数据
List < WindEntity > winds = windService . list ( Wrappers . < WindEntity > lambdaQuery ( )
. eq ( WindEntity : : getStationCode , station . getCode ( ) )
. like ( WindEntity : : getFillDate , DateUtil . format ( new Date ( ) , "yyyy-MM" ) )
) ;
if ( CollectionUtil . isEmpty ( winds ) ) {
return new ArrayList < > ( ) ;
}
List < String > days = this . getCurrentDayList ( ) ;
return days . stream ( ) . map ( day - > {
LocalDate localDate = LocalDate . parse ( DateUtil . format ( new Date ( ) , day ) , DateTimeFormatter . ofPattern ( DateUtil . PATTERN_DATE ) ) ;
WindTargetCurveVo curve = new WindTargetCurveVo ( ) ;
curve . setMon ( localDate . getMonthValue ( ) > 9 ? String . valueOf ( localDate . getMonthValue ( ) ) : "0" + localDate . getMonthValue ( ) ) ;
curve . setDay ( localDate . getDayOfMonth ( ) ) ;
curve . setPeak ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( day ) ) . mapToDouble ( WindEntity : : getPeakPower ) . sum ( ) ) ;
curve . setGenerationDay ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( day ) ) . mapToDouble ( WindEntity : : getSurfPower ) . sum ( ) ) ;
curve . setSpeed ( winds . stream ( ) . filter ( o - > o . getFillDate ( ) . contains ( day ) ) . mapToDouble ( WindEntity : : getSpeed ) . sum ( ) ) ;
return curve ;
} ) . collect ( Collectors . toList ( ) ) ;
}
/ * *
* 获取七天天气
* @param weekWeather
* @param code
* @return
* /
private List < Daily > getDailyList ( 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 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 ;
}
/ * *
* 获取当月日期List
* @return
* /
private List < String > getCurrentDayList ( ) {
List < String > list = new ArrayList < > ( ) ;
// 开始日期
Calendar startCal = Calendar . getInstance ( ) ;
startCal . setTime ( new Date ( ) ) ;
startCal . add ( Calendar . DATE , - startCal . get ( Calendar . DATE ) + 1 ) ;
// 结束日期
Calendar endCal = Calendar . getInstance ( ) ;
endCal . setTime ( new Date ( ) ) ;
endCal . add ( Calendar . DATE , - endCal . get ( Calendar . DATE ) + 1 ) ;
endCal . add ( Calendar . MONTH , 1 ) ;
// 获取日期之间日期
while ( endCal . after ( startCal ) ) {
list . add ( DateUtil . format ( startCal . getTime ( ) , DateUtil . PATTERN_DATE ) ) ;
startCal . add ( Calendar . DATE , 1 ) ;
}
return list ;
}
}