|  |  |  | @ -1,12 +1,16 @@ | 
			
		
	
		
			
				
					|  |  |  |  | package com.hnac.hzims.operational.data.service.impl; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import com.alibaba.fastjson.JSONObject; | 
			
		
	
		
			
				
					|  |  |  |  | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.equipment.entity.PlanGenerationEntity; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.equipment.feign.IPlanGenertionClient; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.data.service.HzimsDataService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.data.vo.AreaVo; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.main.constant.HomePageConstant; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.main.service.AreaService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.main.constant.HomePageConstant; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.main.vo.*; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.station.entity.StationEntity; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.station.service.IStationService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.station.vo.HzimsStationCountVo; | 
			
		
	
	
		
			
				
					|  |  |  | @ -16,19 +20,26 @@ 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.feign.ISysClient; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.beans.factory.annotation.Value; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import javax.validation.constraints.NotNull; | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.InputStream; | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.OutputStream; | 
			
		
	
		
			
				
					|  |  |  |  | import java.math.BigDecimal; | 
			
		
	
		
			
				
					|  |  |  |  | import java.math.RoundingMode; | 
			
		
	
		
			
				
					|  |  |  |  | import java.net.HttpURLConnection; | 
			
		
	
		
			
				
					|  |  |  |  | import java.net.URL; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.Arrays; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.List; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.Map; | 
			
		
	
		
			
				
					|  |  |  |  | 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; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -40,20 +51,33 @@ import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  |  | @RequiredArgsConstructor | 
			
		
	
		
			
				
					|  |  |  |  | public class HzimsDataServiceImpl implements HzimsDataService { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	@NotNull | 
			
		
	
		
			
				
					|  |  |  |  | 	private final AreaService areaService; | 
			
		
	
		
			
				
					|  |  |  |  | 	@NotNull | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final IMainSystemMonitoringService emService; | 
			
		
	
		
			
				
					|  |  |  |  | 	@NotNull | 
			
		
	
		
			
				
					|  |  |  |  | 	private final ISysClient sysClient; | 
			
		
	
		
			
				
					|  |  |  |  | 	@NotNull | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final IStationService stationService; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final IMainSystemMonitoringService maintenanceTaskService; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final ISysClient sysClient; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final IPlanGenertionClient planGenertionClient; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final RedisTemplate redisTemplate; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	@Value("${hzims.operation.save.area.url}") | 
			
		
	
		
			
				
					|  |  |  |  | 	public String AREA_URL; | 
			
		
	
		
			
				
					|  |  |  |  | 	@Value("${hzims.operation.save.station.url}") | 
			
		
	
		
			
				
					|  |  |  |  | 	public String STATION_URL; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final static String recent_year_power_data = "hzims:operation:key:power:data"; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	@Override | 
			
		
	
		
			
				
					|  |  |  |  | 	public boolean saveArea() { | 
			
		
	
		
			
				
					|  |  |  |  | 		R<List<Dept>> result = sysClient.getDeptList(); | 
			
		
	
	
		
			
				
					|  |  |  | @ -103,6 +127,7 @@ public class HzimsDataServiceImpl implements HzimsDataService { | 
			
		
	
		
			
				
					|  |  |  |  | 		return this.sendMessage(JSONObject.toJSONBytes(list),STATION_URL); | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  |  | 	 * 发送请求 | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param params | 
			
		
	
	
		
			
				
					|  |  |  | @ -135,4 +160,256 @@ public class HzimsDataServiceImpl implements HzimsDataService { | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		return true; | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  |  | 	 * 水电站-站点信息 | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param stationCode | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @return | 
			
		
	
		
			
				
					|  |  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  |  | 	@Override | 
			
		
	
		
			
				
					|  |  |  |  | 	public HydropowerStationVo station(String stationCode) { | 
			
		
	
		
			
				
					|  |  |  |  | 		if(StringUtil.isEmpty(stationCode)){ | 
			
		
	
		
			
				
					|  |  |  |  | 			return new HydropowerStationVo(); | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		// 站点
 | 
			
		
	
		
			
				
					|  |  |  |  | 		StationEntity station = stationService.getOne(Wrappers.<StationEntity>lambdaQuery() | 
			
		
	
		
			
				
					|  |  |  |  | 				.eq(StationEntity::getCode,stationCode) | 
			
		
	
		
			
				
					|  |  |  |  | 				.eq(StationEntity::getDataOrigin,"0") | 
			
		
	
		
			
				
					|  |  |  |  | 				.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) | 
			
		
	
		
			
				
					|  |  |  |  | 				.eq(StationEntity::getType,HomePageConstant.HYDROPOWER) | 
			
		
	
		
			
				
					|  |  |  |  | 		); | 
			
		
	
		
			
				
					|  |  |  |  | 		if(ObjectUtil.isEmpty(station)){ | 
			
		
	
		
			
				
					|  |  |  |  | 			return new HydropowerStationVo(); | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		// 实时监测点数据
 | 
			
		
	
		
			
				
					|  |  |  |  | 		List<HydropowerUnitRealVo> realList = (List<HydropowerUnitRealVo>) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 获取站点机组指标数据
 | 
			
		
	
		
			
				
					|  |  |  |  | 		List<HydropowerUnitTargetVo> targetList = (List<HydropowerUnitTargetVo>) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 所有设备
 | 
			
		
	
		
			
				
					|  |  |  |  | 		List<EminfoAndEmParamVo> deviceList = maintenanceTaskService.getEmInfoList(); | 
			
		
	
		
			
				
					|  |  |  |  | 		HydropowerStationVo response = new HydropowerStationVo(); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 近年发电量数据
 | 
			
		
	
		
			
				
					|  |  |  |  | 		Map<Long, Map<String, Float>> map = (Map<Long, Map<String, Float>>) redisTemplate.opsForValue().get(recent_year_power_data); | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setDeptId(station.getRefDept()); | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setDeptName(station.getName()); | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setStationCode(station.getCode()); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 限制水位
 | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setLimitWaterLevel(station.getLimitWaterLevel()); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 运行天数
 | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setRunDay(this.getRunDay(station)); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 装机容量
 | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setInstalledCapacity(this.getInstalledCapacity(deviceList,station.getRefDept())); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 总有功功率(总发电负荷)
 | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setPowerSum(this.getPowerSum(realList,station.getRefDept())); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 总有功单位
 | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setPowerUnit("kW"); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 月计划发电量
 | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setPlanPowerMon(this.getPlanPowerrMon(station.getCode())); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 年计划发电量
 | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setPlanPowerYear(this.getPlanPowerYear(station.getCode())); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 月发电量、年发电量、年发电完成率
 | 
			
		
	
		
			
				
					|  |  |  |  | 		this.handleStationInfo(station.getRefDept(),response); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 水位、水位曲线
 | 
			
		
	
		
			
				
					|  |  |  |  | 		this.handleWaterLeve(station.getCode(),response); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 年发电量完成百分比
 | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setPowerYearMap(this.handlePowerFinish(Collections.singletonList(station),map)); | 
			
		
	
		
			
				
					|  |  |  |  | 		return response; | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  |  | 	 * 获取站点运行天数 | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param station | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @return | 
			
		
	
		
			
				
					|  |  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  |  | 	private int getRunDay(StationEntity station) { | 
			
		
	
		
			
				
					|  |  |  |  | 		if (ObjectUtil.isEmpty(station.getCommissionTime())) { | 
			
		
	
		
			
				
					|  |  |  |  | 			return 0; | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		// 计算投运时间与当前时间相隔天数
 | 
			
		
	
		
			
				
					|  |  |  |  | 		Duration dur = Duration.between(station.getCommissionTime(), LocalDateTime.now()); | 
			
		
	
		
			
				
					|  |  |  |  | 		return (int) dur.toDays(); | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  |  | 	 * 获取设备装机容量 | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param list | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param refDept | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @return | 
			
		
	
		
			
				
					|  |  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  |  | 	private double getInstalledCapacity(List<EminfoAndEmParamVo> list, Long refDept) { | 
			
		
	
		
			
				
					|  |  |  |  | 		if(CollectionUtil.isEmpty(list) || ObjectUtil.isEmpty(refDept)){ | 
			
		
	
		
			
				
					|  |  |  |  | 			return 0.0; | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		return list.stream().filter(o -> refDept.equals(o.getCreateDept())).mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum(); | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  |  | 	 * 获取总发电负荷 | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param deptId | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @return | 
			
		
	
		
			
				
					|  |  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  |  | 	private Double getPowerSum(List<HydropowerUnitRealVo> realList,Long deptId) { | 
			
		
	
		
			
				
					|  |  |  |  | 		if(ObjectUtil.isEmpty(deptId)){ | 
			
		
	
		
			
				
					|  |  |  |  | 			return 0.0; | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		// 获取站点机组实时数据
 | 
			
		
	
		
			
				
					|  |  |  |  | 		if(CollectionUtil.isEmpty(realList)){ | 
			
		
	
		
			
				
					|  |  |  |  | 			return 0.0; | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		return realList.stream().filter(o->deptId.equals(o.getDeptId())).mapToDouble(o->{ | 
			
		
	
		
			
				
					|  |  |  |  | 			if("MW".equalsIgnoreCase(o.getPowerUnit())){ | 
			
		
	
		
			
				
					|  |  |  |  | 				return o.getActivePower() * 1000; | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			return o.getActivePower(); | 
			
		
	
		
			
				
					|  |  |  |  | 		}).sum(); | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  |  | 	 * 获取月计划发电量 | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param code | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @return | 
			
		
	
		
			
				
					|  |  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  |  | 	private float getPlanPowerrMon(String code) { | 
			
		
	
		
			
				
					|  |  |  |  | 		R<Float> R = planGenertionClient.planGenerationMonthCount(code, DateUtil.format(new Date(), "yyyy-MM")); | 
			
		
	
		
			
				
					|  |  |  |  | 		if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ | 
			
		
	
		
			
				
					|  |  |  |  | 			return 0f; | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		return R.getData(); | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  |  | 	 * 获取年计划发电量 | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param code | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @return | 
			
		
	
		
			
				
					|  |  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  |  | 	private float getPlanPowerYear(String code) { | 
			
		
	
		
			
				
					|  |  |  |  | 		R<Float> R = planGenertionClient.planGenerationYearCount(code); | 
			
		
	
		
			
				
					|  |  |  |  | 		if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ | 
			
		
	
		
			
				
					|  |  |  |  | 			return 0f; | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		// 查询年计划发电量
 | 
			
		
	
		
			
				
					|  |  |  |  | 		return R.getData(); | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  |  | 	 * 站点信息处理 | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param deptId | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param response | 
			
		
	
		
			
				
					|  |  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  |  | 	private void handleStationInfo(Long deptId, HydropowerStationVo response) { | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setPowerMon(0f); | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setPowerYear(0f); | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setPowerRateYear(0.0); | 
			
		
	
		
			
				
					|  |  |  |  | 		List<HydropowerUnitTargetVo> targetList = (List<HydropowerUnitTargetVo>) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); | 
			
		
	
		
			
				
					|  |  |  |  | 		if(CollectionUtil.isEmpty(targetList)){ | 
			
		
	
		
			
				
					|  |  |  |  | 			return; | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		// 月发电量
 | 
			
		
	
		
			
				
					|  |  |  |  | 		float powerMont = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerMon).sum(); | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setPowerMon(powerMont); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 年发电量
 | 
			
		
	
		
			
				
					|  |  |  |  | 		float powerYear = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setPowerYear(powerYear); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 年发电完成率
 | 
			
		
	
		
			
				
					|  |  |  |  | 		float planPowerYear = response.getPlanPowerYear(); | 
			
		
	
		
			
				
					|  |  |  |  | 		if(Math.abs(planPowerYear) <= 0){ | 
			
		
	
		
			
				
					|  |  |  |  | 			response.setPowerRateYear(0.0); | 
			
		
	
		
			
				
					|  |  |  |  | 		} else { | 
			
		
	
		
			
				
					|  |  |  |  | 			double powerRateYear = BigDecimal.valueOf(powerYear / planPowerYear * 100).setScale(2, RoundingMode.HALF_UP).doubleValue(); | 
			
		
	
		
			
				
					|  |  |  |  | 			response.setPowerRateYear(powerRateYear); | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  |  | 	 * 站点水位数据处理 | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param code | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param response | 
			
		
	
		
			
				
					|  |  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  |  | 	private void handleWaterLeve(String code, HydropowerStationVo response) { | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setFrontWaterLevel(0.0); | 
			
		
	
		
			
				
					|  |  |  |  | 		List<WaterLevelVo> levelList = (List<WaterLevelVo>) redisTemplate.opsForValue().get(loadwater_level_key); | 
			
		
	
		
			
				
					|  |  |  |  | 		if(CollectionUtil.isEmpty(levelList)){ | 
			
		
	
		
			
				
					|  |  |  |  | 			return; | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		List<WaterLevelVo> validList = levelList.stream().filter(o-> code.equals(o.getStationCode())).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |  | 		if(CollectionUtil.isEmpty(validList)){ | 
			
		
	
		
			
				
					|  |  |  |  | 			return; | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		WaterLevelVo level = validList.get(0); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 前池水位、当日水位曲线
 | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setFrontWaterLevel(level.getFrontWaterLevel()); | 
			
		
	
		
			
				
					|  |  |  |  | 		response.setFrontCurveMap(level.getFrontCurveMap()); | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  |  | 	 * 年发电量完成百分比 | 
			
		
	
		
			
				
					|  |  |  |  | 	 * @param stations | 
			
		
	
		
			
				
					|  |  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  |  | 	private List<PowerMonthVo> handlePowerFinish(List<StationEntity> stations, Map<Long, Map<String, Float>> map) { | 
			
		
	
		
			
				
					|  |  |  |  | 		if (CollectionUtil.isEmpty(stations)) { | 
			
		
	
		
			
				
					|  |  |  |  | 			return null; | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		// 查询计划发电量
 | 
			
		
	
		
			
				
					|  |  |  |  | 		Calendar calendar = Calendar.getInstance(); | 
			
		
	
		
			
				
					|  |  |  |  | 		calendar.setTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  |  | 		List<PlanGenerationEntity> plans = planGenertionClient.getPlanGenerationByParam(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()), null, String.valueOf(calendar.get(Calendar.YEAR))); | 
			
		
	
		
			
				
					|  |  |  |  | 		// 获取月份集合
 | 
			
		
	
		
			
				
					|  |  |  |  | 		List<String> monList = this.mons(0, 12, false); | 
			
		
	
		
			
				
					|  |  |  |  | 		return monList.stream().map(o -> { | 
			
		
	
		
			
				
					|  |  |  |  | 			PowerMonthVo vo = new PowerMonthVo(); | 
			
		
	
		
			
				
					|  |  |  |  | 			LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), o), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); | 
			
		
	
		
			
				
					|  |  |  |  | 			vo.setStrMonth(o); | 
			
		
	
		
			
				
					|  |  |  |  | 			vo.setYear(localDate.getYear()); | 
			
		
	
		
			
				
					|  |  |  |  | 			vo.setMonth(localDate.getMonthValue()); | 
			
		
	
		
			
				
					|  |  |  |  | 			// 实际发电量
 | 
			
		
	
		
			
				
					|  |  |  |  | 			if (CollectionUtil.isEmpty(map)) { | 
			
		
	
		
			
				
					|  |  |  |  | 				vo.setPower(0f); | 
			
		
	
		
			
				
					|  |  |  |  | 			} else { | 
			
		
	
		
			
				
					|  |  |  |  | 				float generate = (float) map.entrySet().stream(). | 
			
		
	
		
			
				
					|  |  |  |  | 						filter(entry -> stations.stream().map(StationEntity::getId).collect(Collectors.toList()).contains(entry.getKey())). | 
			
		
	
		
			
				
					|  |  |  |  | 						mapToDouble(valueMap -> valueMap.getValue().entrySet().stream().filter(entry -> entry.getKey().equals(o)) | 
			
		
	
		
			
				
					|  |  |  |  | 								.mapToDouble(Map.Entry::getValue).sum()).sum(); | 
			
		
	
		
			
				
					|  |  |  |  | 				vo.setPower(generate); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			// 计划发电量
 | 
			
		
	
		
			
				
					|  |  |  |  | 			if (CollectionUtil.isEmpty(plans)) { | 
			
		
	
		
			
				
					|  |  |  |  | 				vo.setPlanPower(0f); | 
			
		
	
		
			
				
					|  |  |  |  | 			} else { | 
			
		
	
		
			
				
					|  |  |  |  | 				String mon = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM")); | 
			
		
	
		
			
				
					|  |  |  |  | 				vo.setPlanPower((float) plans.stream().filter(plan -> mon.equals(plan.getDateTime())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum()); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			return vo; | 
			
		
	
		
			
				
					|  |  |  |  | 		}).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; | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |