fix: 新绑定设备,偶尔出现设备名称重复情况,问题修复。
This commit is contained in:
@@ -978,12 +978,23 @@ public class IotController extends BaseController {
|
||||
warnCode |= DefineDeviceWarnCode.DeviceOffline;
|
||||
}
|
||||
|
||||
// 计算设备数量,用于生成设备名称
|
||||
long deviceCount = deviceMapper.selectCount(
|
||||
// 查询该用户已有测控一体机的名称,找到第一个不冲突的序号
|
||||
java.util.List<Device> existControllers = deviceMapper.selectList(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getUserId, userId)
|
||||
.eq(Device::getDeviceType, 2)
|
||||
.select(Device::getDeviceName)
|
||||
);
|
||||
java.util.Set<String> 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<Device> existDevices = deviceMapper.selectList(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getUserId, rootUserId)
|
||||
.eq(Device::getDeviceType, 1)
|
||||
.select(Device::getDeviceName)
|
||||
);
|
||||
java.util.Set<String> 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<String, Object> deviceProperties = iotDeviceService.queryDeviceProperties(iotId);
|
||||
|
||||
// 计算设备数量,用于生成设备名称
|
||||
long deviceCount = deviceMapper.selectCount(
|
||||
// 查询该用户已有太阳能网控的名称,找到第一个不冲突的序号
|
||||
java.util.List<Device> existSolars = deviceMapper.selectList(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getUserId, rootUserId)
|
||||
.eq(Device::getDeviceType, 3)
|
||||
.select(Device::getDeviceName)
|
||||
);
|
||||
java.util.Set<String> 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());
|
||||
|
||||
Reference in New Issue
Block a user