fix: 塘口控制器列表和溶解氧列表,自测问题修复。
This commit is contained in:
@@ -212,8 +212,8 @@ public class PondController extends BaseController {
|
||||
result.setPondName(pond.getPondName());
|
||||
result.setKeepNightOpen(pond.getKeepNightOpen());
|
||||
|
||||
// 2. 查询塘口下的所有设备(device.pondId == pondId,用于检测仪和挂了塘口的控制器)
|
||||
List<Device> devices = deviceMapper.selectList(
|
||||
// 2. 查询塘口下的所有设备(device.pondId == pondId,仅用于探测器列表)
|
||||
List<Device> pondDevices = deviceMapper.selectList(
|
||||
new LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getPondId, pondId)
|
||||
.orderByAsc(Device::getDeviceType)
|
||||
@@ -227,38 +227,39 @@ public class PondController extends BaseController {
|
||||
.orderByAsc(DeviceSwitch::getIndex)
|
||||
);
|
||||
|
||||
// 4. 从开关中收集所有 deviceId,补全那些本体未挂塘口的控制器
|
||||
// 4. 从开关中收集所有 deviceId
|
||||
Set<Long> switchDeviceIds = allSwitches.stream()
|
||||
.map(DeviceSwitch::getDeviceId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 5. 查询开关关联的控制器设备(排除已经在 devices 中的)
|
||||
Set<Long> existDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toSet());
|
||||
// 5. 查询开关关联的控制器设备(与 pondDevices 合并作为控制器查询来源,但不加入探测器列表)
|
||||
Set<Long> pondDeviceIds = pondDevices.stream().map(Device::getId).collect(Collectors.toSet());
|
||||
List<Long> extraDeviceIds = switchDeviceIds.stream()
|
||||
.filter(id -> !existDeviceIds.contains(id))
|
||||
.filter(id -> !pondDeviceIds.contains(id))
|
||||
.collect(Collectors.toList());
|
||||
// controllerDevices 包含所有控制器:塘口内的 + 开关关联的
|
||||
List<Device> controllerDevices = new ArrayList<>(pondDevices);
|
||||
if (!extraDeviceIds.isEmpty()) {
|
||||
List<Device> 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<Long> deviceIds = devices.stream()
|
||||
// 6. 收集所有控制器设备ID(用于查联动控制、故障码)
|
||||
List<Long> deviceIds = controllerDevices.stream()
|
||||
.map(Device::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 7. 批量查询所有设备的联动控制
|
||||
List<LinkedCtrl> allLinkedCtrls = linkedCtrlMapper.selectList(
|
||||
// 7. 批量查询所有设备的联动控制(探测器用)
|
||||
List<Long> pondDeviceIdList = new ArrayList<>(pondDeviceIds);
|
||||
List<LinkedCtrl> allLinkedCtrls = !pondDeviceIdList.isEmpty() ? linkedCtrlMapper.selectList(
|
||||
new LambdaQueryWrapper<LinkedCtrl>()
|
||||
.in(LinkedCtrl::getDeviceId, deviceIds)
|
||||
);
|
||||
.in(LinkedCtrl::getDeviceId, pondDeviceIdList)
|
||||
) : new ArrayList<>();
|
||||
java.util.Map<Long, List<LinkedCtrl>> 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<Long, List<DeviceSwitch>> switchesByDevice = allSwitches.stream()
|
||||
.collect(Collectors.groupingBy(DeviceSwitch::getDeviceId));
|
||||
|
||||
// 10. 批量查询故障码(合并 devices + 开关关联设备 的所有 deviceId)
|
||||
Set<Long> allControllerIds = devices.stream()
|
||||
// 9. 批量查询故障码(所有控制器 deviceId)
|
||||
Set<Long> 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<DeviceErrorCode> 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<DeviceVo> 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<Long, Device> deviceById = devices.stream()
|
||||
// 10. 处理控制器列表(与 C# 一致:以 allSwitches 为主线聚合,从 controllerDevices 取设备信息)
|
||||
java.util.Map<Long, Device> deviceById = controllerDevices.stream()
|
||||
.collect(Collectors.toMap(Device::getId, d -> d, (a, b) -> a));
|
||||
|
||||
List<DeviceWithSwitchVo> controllerList = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user