add(场景联动): 增加批量启动、禁用场景的接口 (#539)
This commit is contained in:
parent
2dd0ef3c93
commit
19604d8328
|
|
@ -24,6 +24,7 @@ import reactor.core.publisher.Flux;
|
|||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -93,25 +94,35 @@ public class SceneService extends GenericReactiveCrudService<SceneEntity, String
|
|||
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
public Mono<Void> enable(String id) {
|
||||
Assert.hasText(id, "id can not be empty");
|
||||
return enable(Collections.singletonList(id));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
public Mono<Void> enable(Collection<String> id) {
|
||||
Assert.notEmpty(id, "id can not be empty");
|
||||
long now = System.currentTimeMillis();
|
||||
return this
|
||||
.createUpdate()
|
||||
.set(SceneEntity::getState, RuleInstanceState.started)
|
||||
.set(SceneEntity::getModifyTime, now)
|
||||
.set(SceneEntity::getStartTime, now)
|
||||
.where(SceneEntity::getId, id)
|
||||
.in(SceneEntity::getId, id)
|
||||
.execute()
|
||||
.then();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Mono<Void> disabled(String id) {
|
||||
Assert.hasText(id, "id can not be empty");
|
||||
return disabled(Collections.singletonList(id));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Mono<Void> disabled(Collection<String> id) {
|
||||
Assert.notEmpty(id, "id can not be empty");
|
||||
return this
|
||||
.createUpdate()
|
||||
.set(SceneEntity::getState, RuleInstanceState.disable)
|
||||
.where(SceneEntity::getId, id)
|
||||
.in(SceneEntity::getId, id)
|
||||
.execute()
|
||||
.then();
|
||||
}
|
||||
|
|
@ -148,7 +159,7 @@ public class SceneService extends GenericReactiveCrudService<SceneEntity, String
|
|||
//禁用时,停止规则
|
||||
if (scene.getState() == RuleInstanceState.disable) {
|
||||
return ruleEngine.shutdown(scene.getId());
|
||||
}else if (scene.getState() == RuleInstanceState.started){
|
||||
} else if (scene.getState() == RuleInstanceState.started) {
|
||||
scene.validate();
|
||||
return ruleEngine.startRule(scene.getId(), scene.toRule().getModel());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
|
@ -66,6 +67,13 @@ public class SceneController implements ReactiveServiceQueryController<SceneEnti
|
|||
return service.disabled(id);
|
||||
}
|
||||
|
||||
@PutMapping("/batch/_disable")
|
||||
@Operation(summary = "批量禁用场景")
|
||||
@SaveAction
|
||||
public Mono<Void> disableSceneBatch(@RequestBody Mono<List<String>> id) {
|
||||
return id.flatMap(service::disabled);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/_enable")
|
||||
@Operation(summary = "启用场景")
|
||||
@SaveAction
|
||||
|
|
@ -73,6 +81,13 @@ public class SceneController implements ReactiveServiceQueryController<SceneEnti
|
|||
return service.enable(id);
|
||||
}
|
||||
|
||||
@PutMapping("/batch/_enable")
|
||||
@Operation(summary = "批量启用场景")
|
||||
@SaveAction
|
||||
public Mono<Void> enabledSceneBatch(@RequestBody Mono<List<String>> id) {
|
||||
return id.flatMap(service::enable);
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/_execute")
|
||||
@Operation(summary = "手动执行场景")
|
||||
@SaveAction
|
||||
|
|
@ -124,7 +139,7 @@ public class SceneController implements ReactiveServiceQueryController<SceneEnti
|
|||
parseTermColumns(cache).collectList(),
|
||||
cache,
|
||||
(columns, rule) -> rule
|
||||
.createVariables(columns ,
|
||||
.createVariables(columns,
|
||||
branch,
|
||||
branchGroup,
|
||||
action))
|
||||
|
|
|
|||
Loading…
Reference in New Issue