一 部署设计器
1. 将flowable-idm.war, flowable-modeler.war放到tomcat的webapps目录下,然后启动tomcat
2. 在浏览器中访问http://localhost:8080/flowable-modeler,用户名/密码:admin/test 登陆,设计流程后,保存并导出文件。
二 代码
1 创建流程引擎,并且部署一个流程定义
ProcessEngine processEngine = null;
Map userMap = new HashMap<>();
@Before
public void Before() {
userMap.put("11", "周六");
userMap.put("22", "周六大佬");
userMap.put("33", "管周六大佬");
userMap.put("44", "周天大佬");
userMap.put("55", "管周天大佬");
userMap.put("66", "大佬");
ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
.setJdbcUrl("jdbc:mysql://localhost:3306/flowable?useSSL=true&serverTimezone=UTC&nullCatalogMeansCurrent=true")
.setJdbcUsername("xxxx")
.setJdbcPassword("xxxx")
.setJdbcDriver("com.mysql.cj.jdbc.Driver")
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
processEngine = cfg.buildProcessEngine();
}
@Test
public void Test01(){
// 获取Flowable服务
RepositoryService repositoryService = processEngine.getRepositoryService();
// 部署流程定义
Deployment deployment = repositoryService.createDeployment().addClasspathResource("bing_xing_wang_guan.bpmn20.xml").deploy();
//查找部署流程定义
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
System.out.println(processDefinition.getName() + " " + processDefinition.getDeploymentId() + " " + processDefinition.getId());
}
2 一个完整的流程
@Test
public void test02() {
String processDefinitionId = "bing_xing_wang_guan_key:1:4";
RuntimeService runtimeService = processEngine.getRuntimeService();
TaskService taskService = processEngine.getTaskService();
Map variables = new HashMap<>();
variables.put("user", "11");
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, variables);
System.out.println("processInstanceId = " + processInstance.getProcessInstanceId());
//查询周六下的任务
List tasks = taskService.createTaskQuery().taskAssignee("11").list();
queryTask();
//第一个并行网关
variables = new HashMap<>();
variables.put("oneManager", "22");
variables.put("twoManager", "44");
taskService.complete(tasks.get(0).getId(), variables);
System.out.println("-----周六 结束了任务-----");
queryTask();
tasks = taskService.createTaskQuery().taskAssignee("22").list();
variables.put("oneNextManager", "33");
taskService.complete(tasks.get(0).getId(), variables);
System.out.println("-----周六大佬 结束了任务-----");
queryTask();
tasks = taskService.createTaskQuery().taskAssignee("44").list();
variables.put("twoNextManager", "55");
taskService.complete(tasks.get(0).getId(), variables);
System.out.println("-----周天大佬 结束了任务-----");
queryTask();
tasks = taskService.createTaskQuery().taskAssignee("33").list();
variables.put("nextManager", "66");
taskService.complete(tasks.get(0).getId(), variables);
System.out.println("-----管周六大佬 结束了任务-----");
queryTask();
tasks = taskService.createTaskQuery().taskAssignee("55").list();
taskServ