Browse Source

git commit -m 设备导入增加分组

master
review512jwy@163.com 2 days ago
parent
commit
8258a1326a
  1. 29
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceGroupServiceImpl.java

29
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<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();

Loading…
Cancel
Save