增加批量操作接口

This commit is contained in:
zhou-hao 2020-04-15 12:48:23 +08:00
parent db5fa69e03
commit b4b666d913
2 changed files with 48 additions and 4 deletions

View File

@ -214,6 +214,21 @@ public class LocalDeviceInstanceService extends GenericReactiveCrudService<Devic
.execute()));
}
/**
* 批量注销设备
* @param ids 设备ID
* @return 注销结果
*/
public Mono<Integer> unregisterDevice(Publisher<String> ids) {
return Flux.from(ids)
.flatMap(id -> registry.unregisterDevice(id).thenReturn(id))
.collectList()
.flatMap(list -> createUpdate()
.set(DeviceInstanceEntity::getState, DeviceState.notActive.getValue())
.where().in(DeviceInstanceEntity::getId, list)
.execute());
}
public Mono<DeviceDetail> getDeviceDetail(String deviceId) {
return this.findById(deviceId)
.zipWhen(

View File

@ -17,10 +17,7 @@ import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.Dimension;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.QueryAction;
import org.hswebframework.web.authorization.annotation.Resource;
import org.hswebframework.web.authorization.annotation.SaveAction;
import org.hswebframework.web.authorization.annotation.*;
import org.hswebframework.web.bean.FastBeanCopier;
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
import org.hswebframework.web.exception.BusinessException;
@ -291,6 +288,38 @@ public class DeviceInstanceController implements
.thenMany(getDeviceTags(deviceId));
}
/**
* 批量删除设备,只会删除未激活的设备.
*
* @param idList ID列表
* @return 被删除数量
* @since 1.1
*/
@PutMapping("/batch/_delete")
@DeleteAction
public Mono<Integer> deleteBatch(@RequestBody Flux<String> idList) {
return idList
.collectList()
.flatMap(list -> service.createDelete()
.where()
.in(DeviceInstanceEntity::getId, list)
.and(DeviceInstanceEntity::getState, DeviceState.notActive)
.execute());
}
/**
* 批量注销设备
*
* @param idList ID列表
* @return 被注销的数量
* @since 1.1
*/
@PutMapping("/batch/_unDeploy")
@SaveAction
public Mono<Integer> unDeployBatch(@RequestBody Flux<String> idList) {
return service.unregisterDevice(idList);
}
@GetMapping(value = "/import", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@ApiOperation("批量导入数据")