From a937f06dbf7451b66301fb8525cd285163ddb631 Mon Sep 17 00:00:00 2001 From: tianyongbao Date: Wed, 6 May 2026 23:04:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=96=B0=E7=BB=91=E5=AE=9A=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=EF=BC=8C=E5=81=B6=E5=B0=94=E5=87=BA=E7=8E=B0=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=90=8D=E7=A7=B0=E9=87=8D=E5=A4=8D=E6=83=85=E5=86=B5?= =?UTF-8?q?=EF=BC=8C=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intc/iot/controller/IotController.java | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/intc-modules/intc-iot/src/main/java/com/intc/iot/controller/IotController.java b/intc-modules/intc-iot/src/main/java/com/intc/iot/controller/IotController.java index 7a2f77b..cc6c855 100644 --- a/intc-modules/intc-iot/src/main/java/com/intc/iot/controller/IotController.java +++ b/intc-modules/intc-iot/src/main/java/com/intc/iot/controller/IotController.java @@ -978,12 +978,23 @@ public class IotController extends BaseController { warnCode |= DefineDeviceWarnCode.DeviceOffline; } - // 计算设备数量,用于生成设备名称 - long deviceCount = deviceMapper.selectCount( + // 查询该用户已有测控一体机的名称,找到第一个不冲突的序号 + java.util.List existControllers = deviceMapper.selectList( new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() .eq(Device::getUserId, userId) .eq(Device::getDeviceType, 2) + .select(Device::getDeviceName) ); + java.util.Set existingControllerNames = new java.util.HashSet<>(); + for (Device d : existControllers) { + if (d.getDeviceName() != null) { + existingControllerNames.add(d.getDeviceName()); + } + } + int nextControllerNum = 1; + while (existingControllerNames.contains("控制器" + nextControllerNum)) { + nextControllerNum++; + } // 创建或更新设备信息 Date now = new Date(); @@ -1004,7 +1015,7 @@ public class IotController extends BaseController { // 设置基本信息 device.setUserId(userId); - device.setDeviceName("控制器" + (deviceCount + 1)); + device.setDeviceName("控制器" + nextControllerNum); device.setBindTime(now); device.setInputVoltage(bo.getInputVoltage()); device.setVoltageWarnOpen(0); @@ -1392,12 +1403,23 @@ public class IotController extends BaseController { // 初始化警告码:默认探头未校准 (0x0001) int warnCode = 0x0001; - // 计算设备数量,用于生成设备名称 - long deviceCount = deviceMapper.selectCount( + // 查询该用户已有水质检测仪的名称,找到第一个不冲突的序号 + java.util.List existDevices = deviceMapper.selectList( new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() .eq(Device::getUserId, rootUserId) .eq(Device::getDeviceType, 1) + .select(Device::getDeviceName) ); + java.util.Set existingNames = new java.util.HashSet<>(); + for (Device d : existDevices) { + if (d.getDeviceName() != null) { + existingNames.add(d.getDeviceName()); + } + } + int nextNum = 1; + while (existingNames.contains("溶解氧" + nextNum)) { + nextNum++; + } // 创建或更新设备信息 Date now = new Date(); @@ -1419,7 +1441,7 @@ public class IotController extends BaseController { // 设置基本信息 device.setUserId(rootUserId); - device.setDeviceName("溶解氧" + (deviceCount + 1)); + device.setDeviceName("溶解氧" + nextNum); device.setBindTime(now); device.setPondId(bo.getPondId() != null && bo.getPondId() > 0 ? bo.getPondId() : null); device.setSalinityCompensation(bo.getSalinityCompensation()); @@ -1638,12 +1660,23 @@ public class IotController extends BaseController { // 获取设备属性 Map deviceProperties = iotDeviceService.queryDeviceProperties(iotId); - // 计算设备数量,用于生成设备名称 - long deviceCount = deviceMapper.selectCount( + // 查询该用户已有太阳能网控的名称,找到第一个不冲突的序号 + java.util.List existSolars = deviceMapper.selectList( new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() .eq(Device::getUserId, rootUserId) .eq(Device::getDeviceType, 3) + .select(Device::getDeviceName) ); + java.util.Set existingSolarNames = new java.util.HashSet<>(); + for (Device d : existSolars) { + if (d.getDeviceName() != null) { + existingSolarNames.add(d.getDeviceName()); + } + } + int nextSolarNum = 1; + while (existingSolarNames.contains("太阳能网控" + nextSolarNum)) { + nextSolarNum++; + } // 创建或更新设备信息 Date now = new Date(); @@ -1659,7 +1692,7 @@ public class IotController extends BaseController { // 设置基本信息 device.setUserId(rootUserId); - device.setDeviceName("太阳能网控" + (deviceCount + 1)); + device.setDeviceName("太阳能网控" + nextSolarNum); device.setBindTime(now); device.setPondId(bo.getPondId() != null && bo.getPondId() > 0 ? bo.getPondId() : null); device.setOxyWarnLower(bo.getOxyWarnLower());