创建flowble制定流程图
登录flowalbe
制定流程图
进入建模器应用程序
创建流程图
分配用户
下载流程图
使用springboot 调用flowable
java
/**
* 导入流程图老师流程
*/
@Test
void startTeacherApprover(){
Deployment deploy = repositoryService.createDeployment()
.addClasspathResource("process01-基础/老师审批流程.bpmn20.xml")
.name("teackerApprover02")
.deploy();
System.out.println(deploy.getId());
}
/**
* 启动流程
* 查看是否成功 act_re_task 表
*/
@Test
void startRu(){
HashMap<String, Object> map = new HashMap<>();
map.put("student01","zhangsan");
map.put("student02","lisi");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("teacker_approver", map);
System.out.println(processInstance.getProcessDefinitionId()+"流程定义id");
System.out.println(processInstance.getId()+"实力id");
}
/**
* 通过候选人查询任务
* 查询act_id_user
*/
@Test
void queryTaskService(){
List<Task> list = taskService.createTaskQuery().processInstanceId("47a4ff8f-ced7-11ee-a74f-30d04231d1ff")
.taskCandidateUser("lisi")
.list();
for (Task task : list) {
System.out.println(task.getId()+"id");
System.out.println(task.getName()+"名称");
}
}
/**
* 获取任务的方式
* 查询 act_re_task
*/
@Test
void gainTask(){
Task task = taskService.createTaskQuery().processInstanceId("47a4ff8f-ced7-11ee-a74f-30d04231d1ff")
.taskCandidateUser("zhangsan")
.singleResult();
if (task != null) {
taskService.claim(task.getId(),"zhangsan");
}
}
/**
* 任务交接
*/
@Test
void connectTask(){
Task task = taskService.createTaskQuery()
.processInstanceId("47a4ff8f-ced7-11ee-a74f-30d04231d1ff")
.singleResult();
if (task != null) {
taskService.setAssignee(task.getId(),"lisi");
}
}
/**
* 完成任务
*/
@Test
void accomplish(){
Task task = taskService.createTaskQuery()
.processInstanceId("47a4ff8f-ced7-11ee-a74f-30d04231d1ff")
.singleResult();
if (task != null) {
HashMap<String, Object> map = new HashMap<>();
map.put("teacher01","lilaoshi");
map.put("teacher02","wanglaoshi");
taskService.complete(task.getId(),map);
}
}
/**
* 候选人比较多可以放到一个组中方便维护
*/
@Test
void createUser(){
User user = null;
for (int i = 0; i < 3; i++) {
user= identityService.newUser("student" + i);
user.setFirstName(i+"");
user.setEmail(i+"qq.com");
identityService.saveUser(user);
}
}
/**
* 创建研发组信息
* 查询 act_id_group
*/
@Test
void createGroup(){
Group group1 = identityService.newGroup("group1");
group1.setName("研发部");
group1.setType("1");
identityService.saveGroup(group1);
}
/**
* 分配用户到用户组
* 查询 act_id_member
*/
@Test
void allocationUser(){
Group group1 = identityService.createGroupQuery().groupId("group1").singleResult();
List<User> list = identityService.createUserQuery().list();
for (User user : list) {
identityService.createMembership(user.getId(),group1.getId());
}
}
flowable 组件
RepositoryService
负责流程图 从flowable ui 导入到 mysql中
RuntimeService
启动开始任务
TaskService
操作流程实力信息