flowable学习笔记(⼀)发现⼀个学习flowable很好的教程,分享给⼤家。
并附上完整代码及⽬录(已经成功运⾏)
⽬录:
在 l 中添加依赖:
<dependencies>
<!--Flowable流程引擎-->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-engine</artifactId>
<version>6.3.0</version>
</dependency>
<!--MySQL驱动,这⾥采⽤MySQL数据库,如果采⽤其它数据库,需要引⼊对应的依赖。-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
</dependencies>
HolidayRequest.java
import ine.*;
import ine.history.HistoricActivityInstance;
import ine.impl.cfg.StandaloneProcessEngineConfiguration;
import pository.Deployment;
import pository.ProcessDefinition;
import ine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class HolidayRequest {
public static void main( String[] args ) {
//1、创建ProcessEngineConfiguration实例,该实例可以配置与调整流程引擎的设置
ProcessEngineConfiguration cfg=new StandaloneProcessEngineConfiguration()
//2、通常采⽤xml配置⽂件创建ProcessEngineConfiguration,这⾥直接采⽤代码的⽅式
//3、配置数据库相关参数
.setJdbcUrl("jdbc:mysql://localhost:3306/flowable?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2b8&nullCatalogMeansCurrent=t .setJdbcUsername("root")
.setJdbcPassword("123456")
.setJdbcDriver("sql.cj.jdbc.Driver")
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//4、初始化ProcessEngine流程引擎实例
ProcessEngine processEngine=cfg.buildProcessEngine();
//创建RepositoryService实例
RepositoryService RepositoryService();
//加载流程
Deployment ateDeployment()
.addClasspathResource("l")
.deploy();
//查询流程定义
ProcessDefinition ateProcessDefinitionQuery()
.Id())
.singleResult();
System.out.println("Found process definition : "+Name());
//1、获取流程初始化变量
Scanner scanner = new Scanner(System.in);
System.out.println("Who are you?");
String employee = Line();
System.out.println("How many holidays do you want to request?");
Integer nrOfHolidays = Integer.Line());
System.out.println("Why do you need them?");
String description = Line();
//2、使⽤RuntimeService启动⼀个流程实例
RuntimeService RuntimeService();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("employee", employee);
variables.put("nrOfHolidays", nrOfHolidays);
variables.put("description", description);
ProcessInstance processInstance=runtimeService.startProcessInstanceByKey("holiday-request",variables);
//通过TaskService查询 manager 组的任务
TaskService TaskService();
List<Task> ateTaskQuery().taskCandidateGroup("managers").list();
System.out.println("You have " + tasks.size() + " tasks:");
for (int i=0; i<tasks.size(); i++) {
System.out.println((i+1) + ") " + (i).getName());
}
//使⽤集合下标获取特定流程实例的变量,在控制台输出
System.out.println("Which task would you like to complete?");
int taskIndex = Integer.Line());
Task (taskIndex-1);
Map<String,Object> Id());
System.out.("employee") + " wants " +
<("nrOfHolidays") + " of holidays. Do you approve this?");
/
/经理完成任务
boolean Line().toLowerCase().equals("y");createprocessa
variables = new HashMap<String, Object>();
variables.put("approved", approved);
//任务完成,并会在离开排他⽹关的两条路径中,基于’approved ’流程变量选择⼀条 Id(),variables);
//获取HistoryService实例
HistoryService HistoryService();
//添加查询条件
List<HistoricActivityInstance> activities =
//选择特定实例
.Id())
//选择已完成的
.finished()
//根据实例完成时间升序排列
.orderByHistoricActivityInstanceEndTime().asc()
.list();
for (HistoricActivityInstance activity : activities) {
System.out.ActivityId() + " took "
+ DurationInMillis() + " milliseconds");
}
}
}
SendRejectionMail.java
import ine.delegate.DelegateExecution;
import ine.delegate.JavaDelegate;
public class SendRejectionMail implements JavaDelegate {
@Override
public void execute(DelegateExecution delegateExecution) {
System.out.println("send e-mail to employee "
+ Variable("employee"));
}
}
CallExternalSystemDelegate.java
import ine.delegate.DelegateExecution;
import ine.delegate.JavaDelegate;
public class CallExternalSystemDelegate implements JavaDelegate {
public void execute( DelegateExecution delegateExecution) {
System.out.println("Calling the external system for employee "
+ Variable("employee"));
}
}
运⾏截图:
有什么问题可以在评论区讨论哦!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论