From 75be1bf2db998e52d38bfbfdc5ab7eb7fbaac1df Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Mon, 1 Jul 2024 16:41:52 +0800 Subject: [PATCH] =?UTF-8?q?#=E6=8C=87=E6=A0=87=E6=95=B0=E6=8D=AE=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0try/catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alarm/show/service/impl/AlarmServiceImpl.java | 6 +- .../operation/home/impl/RealTargetServiceImpl.java | 76 +++++++++++++--------- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java index 1758414..10aa732 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java @@ -524,7 +524,7 @@ public class AlarmServiceImpl extends BaseServiceImpl Map param = new HashMap<>(); param.put("faultId", faultId); String result = HttpRequestUtil.postCall(param, FAULTGRAPH_INFO_PATH, "POST"); - if (StringUtil.isNotBlank(result)) { + if (StringUtil.isBlank(result)) { throw new ServiceException("未查询到智能预警设备信息!"); } HashMap map = JSONObject.parseObject(result, new TypeReference>() { @@ -538,7 +538,7 @@ public class AlarmServiceImpl extends BaseServiceImpl throw new ServiceException("未查询到智能预警设备信息!"); } String deviceCode = (String) data.get(0).get("TAOS_INSTANCE"); - if(StringUtil.isNotBlank(deviceCode)){ + if(StringUtil.isBlank(deviceCode)){ throw new ServiceException("未查询到智能预警设备信息!"); } return this.deviceVideos(stationCode,deviceCode); @@ -573,7 +573,7 @@ public class AlarmServiceImpl extends BaseServiceImpl } // 查询设备绑定视频点位 R> videos = emVideoClient.getEmBandingVideos(deviceCodes); - if(videos.isSuccess() && CollectionUtil.isEmpty(videos.getData())){ + if(!videos.isSuccess() || CollectionUtil.isEmpty(videos.getData())){ throw new ServiceException("请在设备信息菜单绑定" + station.getData().getName() + "的设备视频绑定信息!"); } return videos.getData().stream().distinct().map(video->{ 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 dfca1da..834ec1c 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 @@ -127,7 +127,7 @@ public class RealTargetServiceImpl implements RealTargetService { private final static String load_photovoltaic_target_key = "hzims:operation:photovoltaic:target:key"; // 创建线程池 - private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("load-power-data-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); + private static final ExecutorService pool = new ThreadPoolExecutor(20, 20, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("load-power-data-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); @Override public void loadEmInfo(String param) { @@ -281,24 +281,38 @@ public class RealTargetServiceImpl implements RealTargetService { // 水电站设备 List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); if(CollectionUtil.isNotEmpty(devices)){ - targets.addAll(devices.stream().map(device->{ - HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); - target.setDeptId(device.getCreateDept()); - target.setDeviceCode(device.getEmCode()); - target.setDeviceName(device.getName()); - target.setDeptName(device.getName()); - // 当年发电量 - target.setPowerYear(this.getGenerationPower(device,0)); - // 当月发电量 - target.setPowerMon(this.getGenerationPower(device,1)); - // 当日发电量 - target.setPowerDay(this.getGenerationPower(device,2)); - // 当天有功功率 - target.setActivePowerVoList(this.getLoadsByDay(device)); - // 30天发电量 - target.setGenerationPowerVoList(this.getGenerationPowerList(device)); - return target; - }).collect(Collectors.toList())); + CountDownLatch countDownLatch = new CountDownLatch(devices.size()); + for(EminfoAndEmParamVo device : devices) { + pool.submit(() -> { + try{ + HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); + target.setDeptId(device.getCreateDept()); + target.setDeviceCode(device.getEmCode()); + target.setDeviceName(device.getName()); + target.setDeptName(device.getName()); + // 当年发电量 + target.setPowerYear(this.getGenerationPower(device, 0)); + // 当月发电量 + target.setPowerMon(this.getGenerationPower(device, 1)); + // 当日发电量 + target.setPowerDay(this.getGenerationPower(device, 2)); + // 当天有功功率 + target.setActivePowerVoList(this.getLoadsByDay(device)); + // 30天发电量 + target.setGenerationPowerVoList(this.getGenerationPowerList(device)); + targets.add(target); + countDownLatch.countDown(); + }catch (Exception exception){ + countDownLatch.countDown(); + } + }); + } + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } } // 站点指标数据为空 if(CollectionUtil.isEmpty(targets)){ @@ -1253,16 +1267,20 @@ public class RealTargetServiceImpl implements RealTargetService { CountDownLatch countDownLatch = new CountDownLatch(limits.size()); for(List item : limits){ pool.submit(()->{ - item.forEach(station->{ - // 站点设备集合 - List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - Map generateMap = this.getGenerateYear(station,stationDevices,start,end); - if(MapUtils.isEmpty(generateMap)){ - return; - } - powerMap.put(station.getId(),generateMap); - }); - countDownLatch.countDown(); + try{ + item.forEach(station->{ + // 站点设备集合 + List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + Map generateMap = this.getGenerateYear(station,stationDevices,start,end); + if(MapUtils.isEmpty(generateMap)){ + return; + } + powerMap.put(station.getId(),generateMap); + }); + countDownLatch.countDown(); + }catch (Exception exception){ + countDownLatch.countDown(); + } log.error("pool_item_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); });