Browse Source

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

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

23
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceGroupServiceImpl.java

@ -357,30 +357,29 @@ public class DeviceGroupServiceImpl implements DeviceGroupService {
} }
List<Long> deviceInfoIdList = CommonUtil.commaStr2LongList(bindDeviceForGroupParams.getDeviceInfoIds()); List<Long> deviceInfoIdList = CommonUtil.commaStr2LongList(bindDeviceForGroupParams.getDeviceInfoIds());
if (CollectionUtils.isEmpty(deviceInfoIdList)) { if (CollectionUtils.isEmpty(deviceInfoIdList)) {
return SimpleDataResponse.success(); return SimpleDataResponse.success();
} }
Long groupId = bindDeviceForGroupParams.getDeviceGroupId(); Long groupId = bindDeviceForGroupParams.getDeviceGroupId();
List<Integer> existedIds = deviceGroupRelationMapperExt.selectDeviceInfoIdsByGroupId(groupId); // 转换为 Integer 列表用于删除
Set<Integer> existedSet = new HashSet<>(existedIds); List<Integer> deviceInfoIds = deviceInfoIdList.stream()
.map(Long::intValue)
// 过滤掉已绑定的
List<Long> filteredList = deviceInfoIdList.stream()
.filter(id -> !existedSet.contains(id.intValue()))
.collect(Collectors.toList()); .collect(Collectors.toList());
// 插入新绑定关系 // 2. 使用 Example 删除指定设备ID的所有绑定记录
if (CollectionUtils.isNotEmpty(filteredList)) { DeviceGroupRelationExample example = new DeviceGroupRelationExample();
for (Long deviceInfoId : filteredList){ example.createCriteria().andDeviceInfoIdIn(deviceInfoIds);
deviceGroupRelationMapperExt.deleteByExample(example);
// 3. 插入新绑定关系
for (Long deviceInfoId : deviceInfoIdList) {
DeviceGroupRelation deviceGroupRelation = new DeviceGroupRelation(); DeviceGroupRelation deviceGroupRelation = new DeviceGroupRelation();
deviceGroupRelation.setDeviceGroupId(bindDeviceForGroupParams.getDeviceGroupId()); deviceGroupRelation.setDeviceGroupId(groupId);
deviceGroupRelation.setDeviceInfoId(deviceInfoId.intValue()); deviceGroupRelation.setDeviceInfoId(deviceInfoId.intValue());
deviceGroupRelationMapperExt.insertSelective(deviceGroupRelation); deviceGroupRelationMapperExt.insertSelective(deviceGroupRelation);
} }
}
return SimpleDataResponse.success(); return SimpleDataResponse.success();
} catch (Exception e) { } catch (Exception e) {

Loading…
Cancel
Save