我们可以看到flowable里面有很多命令模式,那么我们如何定义自己的命令呢?
学无止境,每天在睡觉前都问一下自己今天的时间有没有挥霍。
1.实现Command接口 泛型里面是我们的返回值的类型,这里用Void是无返回值的
重写execute方法
2.使用ManagementService来执行命令
3.实例
public class NotifyTaskCompleteCmd implements Command<Void> {
private String taskId;
private TaskService taskService;
public NotifyTaskCompleteCmd(TaskService taskService, String taskId) {
this.taskService = taskService;
this.taskId = taskId;
}
@Override
public Void execute(CommandContext commandContext) {
TaskEntity task = CommandContextUtil.getTaskService().getTask(taskId);
if (task != null) {
taskService.complete(taskId);
}
return null;
}
}
执行
managementService.executeCommand(new NotifyTaskCompleteCmd(taskService, taskVo.getTaskId()));