From cde35aee96acdf8e53dd5d8707257dd6866b6305 Mon Sep 17 00:00:00 2001 From: tianyongbao Date: Fri, 27 Mar 2026 22:28:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A1=98=E5=8F=A3=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=99=A8=E5=88=97=E8=A1=A8=E5=92=8C=E6=BA=B6=E8=A7=A3=E6=B0=A7?= =?UTF-8?q?=E5=88=97=E8=A1=A8=EF=BC=8C=E8=87=AA=E6=B5=8B=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fishery/controller/PondController.java | 54 +++++++++---------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/intc-modules/intc-fishery/src/main/java/com/intc/fishery/controller/PondController.java b/intc-modules/intc-fishery/src/main/java/com/intc/fishery/controller/PondController.java index 778f2a8..2b208d7 100644 --- a/intc-modules/intc-fishery/src/main/java/com/intc/fishery/controller/PondController.java +++ b/intc-modules/intc-fishery/src/main/java/com/intc/fishery/controller/PondController.java @@ -212,8 +212,8 @@ public class PondController extends BaseController { result.setPondName(pond.getPondName()); result.setKeepNightOpen(pond.getKeepNightOpen()); - // 2. 查询塘口下的所有设备(device.pondId == pondId,用于检测仪和挂了塘口的控制器) - List devices = deviceMapper.selectList( + // 2. 查询塘口下的所有设备(device.pondId == pondId,仅用于探测器列表) + List pondDevices = deviceMapper.selectList( new LambdaQueryWrapper() .eq(Device::getPondId, pondId) .orderByAsc(Device::getDeviceType) @@ -227,38 +227,39 @@ public class PondController extends BaseController { .orderByAsc(DeviceSwitch::getIndex) ); - // 4. 从开关中收集所有 deviceId,补全那些本体未挂塘口的控制器 + // 4. 从开关中收集所有 deviceId Set switchDeviceIds = allSwitches.stream() .map(DeviceSwitch::getDeviceId) .collect(Collectors.toSet()); - // 5. 查询开关关联的控制器设备(排除已经在 devices 中的) - Set existDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toSet()); + // 5. 查询开关关联的控制器设备(与 pondDevices 合并作为控制器查询来源,但不加入探测器列表) + Set pondDeviceIds = pondDevices.stream().map(Device::getId).collect(Collectors.toSet()); List extraDeviceIds = switchDeviceIds.stream() - .filter(id -> !existDeviceIds.contains(id)) + .filter(id -> !pondDeviceIds.contains(id)) .collect(Collectors.toList()); + // controllerDevices 包含所有控制器:塘口内的 + 开关关联的 + List controllerDevices = new ArrayList<>(pondDevices); if (!extraDeviceIds.isEmpty()) { - List extraDevices = deviceMapper.selectBatchIds(extraDeviceIds); - devices = new ArrayList<>(devices); - devices.addAll(extraDevices); + controllerDevices.addAll(deviceMapper.selectBatchIds(extraDeviceIds)); } - if (devices == null || devices.isEmpty()) { + if (pondDevices.isEmpty() && allSwitches.isEmpty()) { result.setListDetector(List.of()); result.setListController(List.of()); return R.ok(result); } - // 6. 收集所有设备ID - List deviceIds = devices.stream() + // 6. 收集所有控制器设备ID(用于查联动控制、故障码) + List deviceIds = controllerDevices.stream() .map(Device::getId) .collect(Collectors.toList()); - // 7. 批量查询所有设备的联动控制 - List allLinkedCtrls = linkedCtrlMapper.selectList( + // 7. 批量查询所有设备的联动控制(探测器用) + List pondDeviceIdList = new ArrayList<>(pondDeviceIds); + List allLinkedCtrls = !pondDeviceIdList.isEmpty() ? linkedCtrlMapper.selectList( new LambdaQueryWrapper() - .in(LinkedCtrl::getDeviceId, deviceIds) - ); + .in(LinkedCtrl::getDeviceId, pondDeviceIdList) + ) : new ArrayList<>(); java.util.Map> linkedCtrlsByDevice = allLinkedCtrls.stream() .collect(Collectors.groupingBy(LinkedCtrl::getDeviceId)); @@ -276,16 +277,12 @@ public class PondController extends BaseController { .collect(Collectors.groupingBy(TimingCtrl::getSwitchId)); } - // 9. 按设备ID分组开关 - java.util.Map> switchesByDevice = allSwitches.stream() - .collect(Collectors.groupingBy(DeviceSwitch::getDeviceId)); - - // 10. 批量查询故障码(合并 devices + 开关关联设备 的所有 deviceId) - Set allControllerIds = devices.stream() + // 9. 批量查询故障码(所有控制器 deviceId) + Set allControllerIds = new HashSet<>(switchDeviceIds); + controllerDevices.stream() .filter(d -> d.getDeviceType() != null && d.getDeviceType() == 2) .map(Device::getId) - .collect(Collectors.toSet()); - allControllerIds.addAll(switchDeviceIds); + .forEach(allControllerIds::add); List errorCodes = new ArrayList<>(); if (!allControllerIds.isEmpty()) { errorCodes = deviceErrorCodeMapper.selectList( @@ -294,9 +291,9 @@ public class PondController extends BaseController { ); } - // 9. 处理探测器列表 (包含: deviceType=1 + deviceType=2且isOxygenUsed=1) + // 9. 处理探测器列表(严格从 pondDevices 取,与 C# pond.ListDevice 保持一致,不包含仅开关挂塘口的设备) List detectorList = new ArrayList<>(); - for (Device device : devices) { + for (Device device : pondDevices) { // 水质检测仪 或 开启溶氧检测的测控一体机 if ((device.getDeviceType() != null && device.getDeviceType() == 1) || (device.getDeviceType() != null && device.getDeviceType() == 2 @@ -333,9 +330,8 @@ public class PondController extends BaseController { } } - // 12. 处理控制器列表(与 C# 一致:以 allSwitches 为主线聚合,确保只挂开关到塘口的控制器也能被找到) - // 构建设备ID -> Device 的映射,便于下面按 deviceId 查询 - java.util.Map deviceById = devices.stream() + // 10. 处理控制器列表(与 C# 一致:以 allSwitches 为主线聚合,从 controllerDevices 取设备信息) + java.util.Map deviceById = controllerDevices.stream() .collect(Collectors.toMap(Device::getId, d -> d, (a, b) -> a)); List controllerList = new ArrayList<>();