From ffecf0ffdb5ea7d2304c62a540347edb04db1a5b Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 1 Aug 2024 10:26:55 +0800 Subject: [PATCH] =?UTF-8?q?#=E6=96=B0=E7=89=88=E7=94=B5=E7=AB=99=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operation/home/impl/RealTargetServiceImpl.java | 186 +++++++++++++++++---- 1 file changed, 152 insertions(+), 34 deletions(-) diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java index 0392d17..527d67a 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java @@ -1,6 +1,5 @@ package com.hnac.hzims.scheduled.service.operation.home.impl; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -8,6 +7,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.hnac.hzims.EquipmentConstants; import com.hnac.hzims.equipment.entity.EmParamEntity; +import com.hnac.hzims.equipment.entity.ThirtyGenerationEntity; +import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.hzimsweather.feign.IHeWeatherWeatherClient; import com.hnac.hzims.hzimsweather.vo.RainFallCountByMonthVo; @@ -20,6 +21,8 @@ import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.scheduled.service.equipment.DeviceParamService; import com.hnac.hzims.scheduled.service.equipment.DeviceService; +import com.hnac.hzims.scheduled.service.equipment.ThirtyGenerateService; +import com.hnac.hzims.scheduled.service.equipment.ThreeGenerateService; import com.hnac.hzims.scheduled.service.operation.fill.*; import com.hnac.hzims.scheduled.service.operation.home.ModelStationService; import com.hnac.hzims.scheduled.service.operation.home.RealTargetService; @@ -38,8 +41,6 @@ import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; -import com.hnac.hzinfo.sdk.v5.device.dto.ReductionDataDTO; -import com.hnac.hzinfo.sdk.v5.device.vo.ReductionDataVO; import com.xxl.job.core.log.XxlJobLogger; import io.undertow.util.CopyOnWriteMap; import lombok.RequiredArgsConstructor; @@ -58,7 +59,6 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.*; @@ -98,6 +98,10 @@ public class RealTargetServiceImpl implements RealTargetService { private final ModelStationService modelStationService; + private final ThreeGenerateService threeGenerateService; + + private final ThirtyGenerateService thirtyGenerateService; + private final RedisTemplate redisTemplate; private final IHeWeatherWeatherClient heWeatherWeatherClient; @@ -278,6 +282,10 @@ public class RealTargetServiceImpl implements RealTargetService { if(CollectionUtil.isEmpty(stations)){ return; } + // 设备30日发电量 + List generations = this.thirtyGenerations(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); + // 设备当年发电量 + List generationYears = this.threeGenerations(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); // 补充填补发电指标 List targets = this.generteFill(stations); // 水电站设备 @@ -289,19 +297,20 @@ public class RealTargetServiceImpl implements RealTargetService { try{ HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); target.setDeptId(device.getCreateDept()); + Optional station = stations.stream().filter(o->o.getRefDept().equals(device.getCreateDept())).findFirst(); + station.ifPresent(stationEntity -> target.setDeptName(stationEntity.getName())); target.setDeviceCode(device.getEmCode()); target.setDeviceName(device.getName()); - target.setDeptName(device.getName()); // 当年发电量 - target.setPowerYear(this.getGenerationPower(device, 0)); + target.setPowerYear(this.devicePowerYear(generationYears,device)); // 当月发电量 - target.setPowerMon(this.getGenerationPower(device, 1)); + target.setPowerMon(this.devicePowerMon(generationYears,device)); // 当日发电量 - target.setPowerDay(this.getGenerationPower(device, 2)); + target.setPowerDay(this.devicePowerDay(generations,device)); // 当天有功功率 target.setActivePowerVoList(this.getLoadsByDay(device)); // 30天发电量 - target.setGenerationPowerVoList(this.getGenerationPowerList(device)); + target.setGenerationPowerVoList(this.getGenerationPowerList(generations,device)); targets.add(target); countDownLatch.countDown(); }catch (Exception exception){ @@ -323,6 +332,75 @@ public class RealTargetServiceImpl implements RealTargetService { redisTemplate.opsForValue().set(load_hydropower_unit_target_key,targets); } + + /** + * 去年发电量 + * @param generations + * @param device + * @return + */ + private Float devicePowerYesterYear(List generations, EminfoAndEmParamVo device) { + if(CollectionUtil.isEmpty(generations)){ + return 0f; + } + return (float) generations.stream().filter(o -> StringUtil.isNotBlank(o.getDeviceCode()) && o.getDeviceCode().equals(device.getEmCode())).mapToDouble(o->o.getGenerate().doubleValue()).sum(); + } + + /** + * 当年发电量 + * @param generations + * @param device + * @return + */ + private Float devicePowerYear(List generations, EminfoAndEmParamVo device) { + if(CollectionUtil.isEmpty(generations)){ + return 0f; + } + return (float) generations.stream().filter(o -> StringUtil.isNotBlank(o.getDeviceCode()) && o.getDeviceCode().equals(device.getEmCode())).mapToDouble(o->o.getGenerate().doubleValue()).sum(); + } + + /** + * 当月发电量 + * @param generations + * @param device + * @return + */ + private Float devicePowerMon(List generations, EminfoAndEmParamVo device) { + if(CollectionUtil.isEmpty(generations)){ + return 0f; + } + return (float) generations.stream().filter(o-> StringUtil.isNotBlank(o.getDeviceCode()) && o.getDeviceCode().equals(device.getEmCode()) && o.getStrMonth().contains(DateUtil.format(new Date(),"yyyy-MM"))).mapToDouble(o->o.getGenerate().doubleValue()).sum(); + + } + + /** + * 设备当日发电量 + * @param generations + * @param device + * @return + */ + private Float devicePowerDay(List generations, EminfoAndEmParamVo device) { + if(CollectionUtil.isEmpty(generations)){ + return 0f; + } + return (float) generations.stream().filter(o->o.getDeviceCode().equals(device.getEmCode()) && o.getStrDay().contains(DateUtil.format(new Date(),DateUtil.PATTERN_DATE))).mapToDouble(o->o.getGenerate().doubleValue()).sum(); + } + + /** + * 设备昨日发电量 + * @param generations + * @param device + * @return + */ + private Float devicePowerYesterDay(List generations, EminfoAndEmParamVo device) { + if(CollectionUtil.isEmpty(generations)){ + return 0f; + } + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH,-1); + return (float) generations.stream().filter(o->o.getDeviceCode().equals(device.getEmCode()) && o.getStrDay().contains(DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE))).mapToDouble(o->o.getGenerate().doubleValue()).sum(); + } + /** * 水利-泵组实时加载 * @param param @@ -1365,9 +1443,6 @@ public class RealTargetServiceImpl implements RealTargetService { in(StationEntity::getType, types); } }}); - // 设备信息 -// List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() { -// }); // 开始时间 Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); @@ -1381,8 +1456,6 @@ public class RealTargetServiceImpl implements RealTargetService { Map> powerMap = new HashMap<>(); stationList.forEach(station -> { // 站点设备集合 -// List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); -// log.error("load_power_data station :" + station.getCode() + "==== device :" + stationDevices ); Map generateMap = this.getGenerateYearByWindEnergy(station,start,end); if(MapUtils.isEmpty(generateMap)){ return; @@ -1890,33 +1963,78 @@ public class RealTargetServiceImpl implements RealTargetService { return dataService.periodTargetFloat(start,end,5,accessRules,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); } + /** - * 近30天发电量 - * @param device + * 站点设备近30天发电量 + * @param stations * @return */ - private List getGenerationPowerList(EminfoAndEmParamVo device) { + private List thirtyGenerations(List stations) { Calendar calendar = Calendar.getInstance(); String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); calendar.add(Calendar.DAY_OF_MONTH,-29); - 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)); - String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); - List records = dataService.periodTargetData(start,end,5,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - if(CollectionUtil.isEmpty(records)){ - return new ArrayList<>(); - } - return records.stream().map(record -> { - GenerationPowerVo generate = new GenerationPowerVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - generate.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); - if(StringUtil.isEmpty(record.getVal())){ - generate.setGenerate(0f); + String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE); + return thirtyGenerateService.list(Wrappers.lambdaQuery() + .in(ThirtyGenerationEntity::getStationId,stations) + .ge(ThirtyGenerationEntity::getStrDay,start) + .le(ThirtyGenerationEntity::getStrDay,end) + ); + } + + /** + * 站点设备今年发电量 + * @param stations + * @return + */ + private List threeGenerations(List stations) { + return threeGenerateService.list(Wrappers.lambdaQuery() + .in(ThreeGenerationEntity::getStationId,stations) + .like(ThreeGenerationEntity::getStrMonth,DateUtil.format(new Date(),"yyyy")) + ); + } + + /** + * 查询设备去年发电量 + * @param stations + * @return + */ + private List threeYesterGenerations(List stations) { + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.YEAR,-1); + return threeGenerateService.list(Wrappers.lambdaQuery() + .in(ThreeGenerationEntity::getStationId,stations) + .like(ThreeGenerationEntity::getStrMonth,DateUtil.format(calendar.getTime(),"yyyy")) + ); + } + + + /** + * 设备近30天发电量组装 + * @param generations + * @param device + * @return + */ + private List getGenerationPowerList(List generations,EminfoAndEmParamVo device) { + Calendar calendar = Calendar.getInstance(); + Date end = calendar.getTime(); + calendar.add(Calendar.DAY_OF_MONTH,-29); + Date start = calendar.getTime(); + List powers = new ArrayList<>(); + while (end.compareTo(start) >= 0){ + GenerationPowerVo power = new GenerationPowerVo(); + if (CollectionUtil.isEmpty(generations)) { + power.setDate(DateUtil.format(start,DateUtil.PATTERN_DATE)); + power.setGenerate(0f); }else{ - generate.setGenerate(Float.parseFloat(String.valueOf(Double.parseDouble(record.getVal()) * device.getRideCount()))); + String date = DateUtil.format(start,DateUtil.PATTERN_DATE); + power.setDate(date); + power.setGenerate((float) generations.stream().filter(iter->iter.getDeviceCode().equals(device.getEmCode()) && iter.getStrDay().contains(date)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); } - return generate; - }).collect(Collectors.toList()); + calendar.add(Calendar.DAY_OF_MONTH,1); + powers.add(power); + start = calendar.getTime(); + } + return powers; } + } \ No newline at end of file