From 8258a1326a2df9dd41d202f11a5812ed15b13a7e Mon Sep 17 00:00:00 2001 From: "review512jwy@163.com" <“review512jwy@163.com”> Date: Tue, 25 Nov 2025 09:24:29 +0800 Subject: [PATCH] =?UTF-8?q?git=20commit=20-m=20=E8=AE=BE=E5=A4=87=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=A2=9E=E5=8A=A0=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DeviceGroupServiceImpl.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceGroupServiceImpl.java b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceGroupServiceImpl.java index c4c053b..234c100 100644 --- a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceGroupServiceImpl.java +++ b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceGroupServiceImpl.java @@ -357,29 +357,28 @@ public class DeviceGroupServiceImpl implements DeviceGroupService { } List deviceInfoIdList = CommonUtil.commaStr2LongList(bindDeviceForGroupParams.getDeviceInfoIds()); - if (CollectionUtils.isEmpty(deviceInfoIdList)) { return SimpleDataResponse.success(); } Long groupId = bindDeviceForGroupParams.getDeviceGroupId(); - List existedIds = deviceGroupRelationMapperExt.selectDeviceInfoIdsByGroupId(groupId); - Set existedSet = new HashSet<>(existedIds); - - // 过滤掉已绑定的 - List filteredList = deviceInfoIdList.stream() - .filter(id -> !existedSet.contains(id.intValue())) + // 转换为 Integer 列表用于删除 + List deviceInfoIds = deviceInfoIdList.stream() + .map(Long::intValue) .collect(Collectors.toList()); - // 插入新绑定关系 - if (CollectionUtils.isNotEmpty(filteredList)) { - for (Long deviceInfoId : filteredList){ - DeviceGroupRelation deviceGroupRelation = new DeviceGroupRelation(); - deviceGroupRelation.setDeviceGroupId(bindDeviceForGroupParams.getDeviceGroupId()); - deviceGroupRelation.setDeviceInfoId(deviceInfoId.intValue()); - deviceGroupRelationMapperExt.insertSelective(deviceGroupRelation); - } + // 2. 使用 Example 删除指定设备ID的所有绑定记录 + DeviceGroupRelationExample example = new DeviceGroupRelationExample(); + example.createCriteria().andDeviceInfoIdIn(deviceInfoIds); + deviceGroupRelationMapperExt.deleteByExample(example); + + // 3. 插入新绑定关系 + for (Long deviceInfoId : deviceInfoIdList) { + DeviceGroupRelation deviceGroupRelation = new DeviceGroupRelation(); + deviceGroupRelation.setDeviceGroupId(groupId); + deviceGroupRelation.setDeviceInfoId(deviceInfoId.intValue()); + deviceGroupRelationMapperExt.insertSelective(deviceGroupRelation); } return SimpleDataResponse.success();