删除设备类型
This commit is contained in:
@ -177,7 +177,24 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(List<Long> ids) {
|
||||
deviceTypeMapper.deleteBatchIds(ids);
|
||||
// 查询所有与 device 关联的 deviceType IDs
|
||||
List<Device> deviceList = deviceMapper.selectList(new QueryWrapper<Device>().in("device_type", ids));
|
||||
// 提取与 device 关联的 deviceType IDs
|
||||
List<Long> filteredIds = deviceList.stream()
|
||||
.map(Device::getDeviceType)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
// 从原始 ids 中移除已关联 device 的 id(即过滤掉能查到结果的 id)
|
||||
List<Long> idsToBeDeleted = ids.stream()
|
||||
.filter(id -> !filteredIds.contains(id))
|
||||
.collect(Collectors.toList());
|
||||
if (idsToBeDeleted.isEmpty()) {
|
||||
throw new BadRequestException("选中设备类型已绑定设备,请先解绑设备!!!");
|
||||
}
|
||||
// 删除过滤后的 id 列表
|
||||
deviceTypeMapper.deleteBatchIds(idsToBeDeleted);
|
||||
deviceTypeGrantsMapper.delete(new QueryWrapper<DeviceTypeGrants>().in("device_type_id", idsToBeDeleted));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user