|
|
|
@ -357,29 +357,28 @@ public class DeviceGroupServiceImpl implements DeviceGroupService { |
|
|
|
} |
|
|
|
|
|
|
|
List<Long> deviceInfoIdList = CommonUtil.commaStr2LongList(bindDeviceForGroupParams.getDeviceInfoIds()); |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(deviceInfoIdList)) { |
|
|
|
return SimpleDataResponse.success(); |
|
|
|
} |
|
|
|
|
|
|
|
Long groupId = bindDeviceForGroupParams.getDeviceGroupId(); |
|
|
|
|
|
|
|
List<Integer> existedIds = deviceGroupRelationMapperExt.selectDeviceInfoIdsByGroupId(groupId); |
|
|
|
Set<Integer> existedSet = new HashSet<>(existedIds); |
|
|
|
|
|
|
|
// 过滤掉已绑定的
|
|
|
|
List<Long> filteredList = deviceInfoIdList.stream() |
|
|
|
.filter(id -> !existedSet.contains(id.intValue())) |
|
|
|
// 转换为 Integer 列表用于删除
|
|
|
|
List<Integer> 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(); |
|
|
|
|