From ddbc0860e75525cf51dd65a96316ea8d2084abf1 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 29 Aug 2024 11:43:08 +0800 Subject: [PATCH] =?UTF-8?q?#=E6=97=A0=E5=8A=9F=E7=94=B5=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../equipment/entity/ThirtyGenerationEntity.java | 3 + .../scheduled/GenerationScheduledTask.java | 2 + .../home/impl/ObtainGenerationServiceImpl.java | 154 ++++++++++++++------- 3 files changed, 107 insertions(+), 52 deletions(-) diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/ThirtyGenerationEntity.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/ThirtyGenerationEntity.java index 7e38d5d..a5be934 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/ThirtyGenerationEntity.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/ThirtyGenerationEntity.java @@ -40,4 +40,7 @@ public class ThirtyGenerationEntity extends TenantEntity { @ApiModelProperty(value = "发电量") private BigDecimal generate; + + @ApiModelProperty(value = "无功电量") + private BigDecimal reactiveGenerate; } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java index b574b22..80be76b 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java @@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Arrays; @@ -33,6 +34,7 @@ public class GenerationScheduledTask { * @return */ @XxlJob(THREE_YEAR_POWER_GENERATION) + //@Scheduled(cron = "0/40 * * * * ? ") public ReturnT threeYearPowerGeneration(String param) { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java index ff44095..f304eaf 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java @@ -146,13 +146,24 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { if(CollectionUtil.isEmpty(records)){ return; } + List reactives = dataService.periodTargetData(start,end,5,3,device.getEmCode(),HomePageConstant.HYDROPOWER_REACTIVE_GENERATE); // 是否包含今日累计发电量数据 Optional optional = generations.stream().filter(o->o.getStationId().equals(station.getCode()) && o.getDeviceCode().equals(device.getEmCode())).findFirst(); if(optional.isPresent()){ if(StringUtil.isEmpty(records.get(0).getVal())){ optional.get().setGenerate(BigDecimal.ZERO); }else{ - optional.get().setGenerate(BigDecimal.valueOf(Double.parseDouble(records.get(0).getVal()) * device.getRideCount())); + optional.get().setGenerate(BigDecimal.valueOf(Double.parseDouble(records.get(0).getVal()) * device.getRideCount()).setScale(2, RoundingMode.HALF_UP)); + } + // 无功电量 + if(CollectionUtil.isEmpty(reactives)){ + optional.get().setReactiveGenerate(BigDecimal.ZERO); + }else{ + if(StringUtil.isEmpty(reactives.get(0).getVal())){ + optional.get().setReactiveGenerate(BigDecimal.ZERO); + }else{ + optional.get().setReactiveGenerate(BigDecimal.valueOf(Double.parseDouble(reactives.get(0).getVal()))); + } } saves.add(optional.get()); }else{ @@ -178,6 +189,16 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { }else{ generate.setGenerate(BigDecimal.valueOf(Double.parseDouble(records.get(0).getVal()) * device.getRideCount())); } + // 无功电量 + if(CollectionUtil.isEmpty(reactives)){ + generate.setReactiveGenerate(BigDecimal.ZERO); + }else{ + if(StringUtil.isEmpty(reactives.get(0).getVal())){ + generate.setReactiveGenerate(BigDecimal.ZERO); + }else{ + generate.setReactiveGenerate(BigDecimal.valueOf(Double.parseDouble(reactives.get(0).getVal()))); + } + } saves.add(generate); } }); @@ -287,6 +308,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { if(CollectionUtil.isEmpty(records)){ return; } + List reactives = dataService.periodTargetData(start,end,5,3,device.getEmCode(),HomePageConstant.HYDROPOWER_REACTIVE_GENERATE); // 保存设备发电量 thirtyGenerateService.saveBatch(records.stream().map(record -> { ThirtyGenerationEntity generate = new ThirtyGenerationEntity(); @@ -309,7 +331,22 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { if(StringUtil.isEmpty(record.getVal())){ generate.setGenerate(BigDecimal.ZERO); }else{ - generate.setGenerate(BigDecimal.valueOf(Double.parseDouble(record.getVal()) * device.getRideCount())); + generate.setGenerate(BigDecimal.valueOf(Double.parseDouble(record.getVal()) * device.getRideCount()).setScale(2, RoundingMode.HALF_UP)); + } + // 无功电量 + if(CollectionUtil.isEmpty(reactives)){ + generate.setReactiveGenerate(BigDecimal.ZERO); + }else{ + Optional optional = reactives.stream().filter(reactive-> record.getTs().equals(reactive.getTs())).findFirst(); + if(optional.isPresent()){ + if(StringUtil.isEmpty(optional.get().getVal())){ + generate.setReactiveGenerate(BigDecimal.ZERO); + }else{ + generate.setReactiveGenerate(BigDecimal.valueOf(Double.parseDouble(optional.get().getVal()))); + } + }else{ + generate.setReactiveGenerate(BigDecimal.ZERO); + } } return generate; }).collect(Collectors.toList())); @@ -352,60 +389,70 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { List> limits = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stations.stream().skip((long) a * 3).limit(3).parallel().collect(Collectors.toList())).collect(Collectors.toList()); CountDownLatch countDownLatch = new CountDownLatch(limits.size()); for(List item : limits){ - try{ pool.submit(()->{ - item.forEach(station->{ - // 站点设备集合 - List eminfos = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - // 遍历查询发电量 - eminfos.forEach(device->{ - List records = dataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - if(CollectionUtil.isEmpty(records)){ - return; - } - List reactives = dataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_REACTIVE_GENERATE); - // 保存设备发电量 - threeGenerateService.saveBatch(records.stream().map(record -> { - ThreeGenerationEntity generate = new ThreeGenerationEntity(); - generate.setStationId(station.getCode()); - generate.setStationName(station.getName()); - generate.setDeviceCode(device.getEmCode()); - generate.setDeviceName(device.getName()); - generate.setTenantId(station.getTenantId()); - generate.setCreateDept(station.getRefDept()); - generate.setCreateUser(station.getCreateUser()); - generate.setUpdateUser(station.getUpdateUser()); - Date time; - if(record.getTs().contains(".0")){ - time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - }else{ - time = DateUtil.parse(record.getTs() + ".0", "yyyy-MM-dd HH:mm:ss.s"); - } - generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE)); - generate.setMonth(time.getMonth() + 1); - if(StringUtil.isEmpty(record.getVal())){ - generate.setGenerate(BigDecimal.ZERO); - }else{ - generate.setGenerate(BigDecimal.valueOf(Double.parseDouble(record.getVal()) * device.getRideCount())); - } - // 无功电量 - if(CollectionUtil.isEmpty(reactives)){ - generate.setReactiveGenerate(BigDecimal.ZERO); + try{ + item.forEach(station->{ + // 站点设备集合 + List eminfos = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + // 遍历查询发电量 + eminfos.forEach(device->{ + List records = dataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return; } - - return generate; - }).collect(Collectors.toList())); + List reactives = dataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_REACTIVE_GENERATE); + // 保存设备发电量 + threeGenerateService.saveBatch(records.stream().map(record -> { + ThreeGenerationEntity generate = new ThreeGenerationEntity(); + generate.setStationId(station.getCode()); + generate.setStationName(station.getName()); + generate.setDeviceCode(device.getEmCode()); + generate.setDeviceName(device.getName()); + generate.setTenantId(station.getTenantId()); + generate.setCreateDept(station.getRefDept()); + generate.setCreateUser(station.getCreateUser()); + generate.setUpdateUser(station.getUpdateUser()); + Date time; + if(record.getTs().contains(".0")){ + time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + }else{ + time = DateUtil.parse(record.getTs() + ".0", "yyyy-MM-dd HH:mm:ss.s"); + } + generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE)); + generate.setMonth(time.getMonth() + 1); + if(StringUtil.isEmpty(record.getVal())){ + generate.setGenerate(BigDecimal.ZERO); + }else{ + generate.setGenerate(BigDecimal.valueOf(Double.parseDouble(record.getVal()) * device.getRideCount()).setScale(2, RoundingMode.HALF_UP)); + } + // 无功电量 + if(CollectionUtil.isEmpty(reactives)){ + generate.setReactiveGenerate(BigDecimal.ZERO); + }else{ + Optional optional = reactives.stream().filter(reactive-> record.getTs().equals(reactive.getTs())).findFirst(); + if(optional.isPresent()){ + if(StringUtil.isEmpty(optional.get().getVal())){ + generate.setReactiveGenerate(BigDecimal.ZERO); + }else{ + generate.setReactiveGenerate(BigDecimal.valueOf(Double.parseDouble(optional.get().getVal()))); + } + }else{ + generate.setReactiveGenerate(BigDecimal.ZERO); + } + } + return generate; + }).collect(Collectors.toList())); + }); + // 填报发电量保存 + threeGenerateService.saveBatch(this.saveFillGenerate(station,start,end)); }); - // 填报发电量保存 - threeGenerateService.saveBatch(this.saveFillGenerate(station,start,end)); - }); - countDownLatch.countDown(); - log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); + countDownLatch.countDown(); + log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); + }catch (Exception e){ + countDownLatch.countDown(); + log.error("save_generation_execute_complete_error : {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); + } }); - }catch (Exception e){ - countDownLatch.countDown(); - log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); - } } // 等待所有线程执行完成 try { @@ -453,6 +500,9 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { }else{ generation.setGenerate(BigDecimal.valueOf(Double.parseDouble(power.getPower().toString())).setScale(2, RoundingMode.HALF_UP)); } + generation.setReactiveGenerate(BigDecimal.ZERO + + ); return generation; }).collect(Collectors.toList()); }