From b2885326b1941d915dfc145b71ee21ef2efcc084 Mon Sep 17 00:00:00 2001 From: "Mr.Wang" Date: Mon, 25 Mar 2024 16:53:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=83=85=E6=8A=A5=E6=9D=BF?= =?UTF-8?q?=E5=9B=9E=E6=98=BE=E5=8E=9F=E5=A7=8B=E5=86=85=E5=AE=B9=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DcEmergencyPlansServiceImpl.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java index c570691e..7f0a614a 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java @@ -30,6 +30,7 @@ import javax.annotation.Resource; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.CountDownLatch; import java.util.stream.Collectors; @Service @@ -225,12 +226,11 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { */ public Map> getBoardTemplate(List dcDevices) { Map> map = new HashMap<>(); + CountDownLatch latch = new CountDownLatch(dcDevices.size()); dcDevices.forEach(dcDevice -> { threadPoolTaskExecutor.execute(() -> { try { - if (StringUtils.isEmpty(dcDevice.getIotDeviceId())) { - return; - } + if (StringUtils.isNotEmpty(dcDevice.getIotDeviceId())){ AjaxResult ajaxResult = dcDeviceController.getDeviceRealtimeProperty(dcDevice.getIotDeviceId(), "3A", new HashMap<>()); if (ajaxResult.get("code").equals(200)) { JSONObject properties = JSON.parseObject(JSON.parseObject(ajaxResult.get("data").toString()).get("3A").toString()); @@ -263,12 +263,19 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { }); map.put(dcDevice.getDeviceName(), list); } + } } catch (Exception e) { e.printStackTrace(); + } finally { + latch.countDown(); // 确保在异常情况下也能减少CountDownLatch计数 } }); }); - + try { + latch.await(); // 等待所有线程执行完毕 + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } return map; } @@ -301,7 +308,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { } else if (searchRule.equals(2)) { // 事件上游最近 - if (direction.equals("1")) { + if (direction.equals("菏泽方向")) { // 上行 取最大的几个 start.add("55"); start.add("379"); @@ -341,7 +348,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { } else if (searchRule.equals(3)) { // 事件下游最近 - if (direction.equals("1")) { + if (direction.equals("菏泽方向")) { // 上行 取最大的几个 start.add(markArray[0]); start.add(markArray[1]);