【功能新增】IoT:设备管理界面增加批量删除功能
This commit is contained in:
parent
3450658159
commit
b02e396aff
|
@ -23,6 +23,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
@ -62,7 +63,7 @@ public class IotDeviceController {
|
|||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除设备")
|
||||
@Operation(summary = "删除单个设备")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('iot:device:delete')")
|
||||
public CommonResult<Boolean> deleteDevice(@RequestParam("id") Long id) {
|
||||
|
@ -70,6 +71,15 @@ public class IotDeviceController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Operation(summary = "删除多个设备")
|
||||
@Parameter(name = "ids", description = "编号数组", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('iot:device:delete')")
|
||||
public CommonResult<Boolean> deleteDeviceList(@RequestParam("ids") Collection<Long> ids) {
|
||||
deviceService.deleteDeviceList(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得设备")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
|
|
|
@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
|
|||
import jakarta.validation.Valid;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -33,12 +34,19 @@ public interface IotDeviceService {
|
|||
void updateDevice(@Valid IotDeviceSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除设备
|
||||
* 删除单个设备
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteDevice(Long id);
|
||||
|
||||
/**
|
||||
* 删除多个设备
|
||||
*
|
||||
* @param ids 编号数组
|
||||
*/
|
||||
void deleteDeviceList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得设备
|
||||
*
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.service.device;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
@ -18,10 +19,12 @@ import jakarta.annotation.Resource;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -117,6 +120,28 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|||
deviceMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDeviceList(Collection<Long> ids) {
|
||||
// 1.1 校验存在
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
List<IotDeviceDO> devices = deviceMapper.selectBatchIds(ids);
|
||||
if (CollUtil.isEmpty(devices)) {
|
||||
return;
|
||||
}
|
||||
// 1.2 校验网关设备是否存在
|
||||
for (IotDeviceDO device : devices) {
|
||||
if (device.getGatewayId() != null && deviceMapper.selectCountByGatewayId(device.getId()) > 0) {
|
||||
throw exception(DEVICE_HAS_CHILDREN);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 删除设备
|
||||
deviceMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验设备是否存在
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue