image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png

启动流程方式

直接启动

  1. ProcessInstance processInstance =
  2. runtimeService.startProcessInstanceByKey(processDefinitionKey);

任意节点启动

  1. /**
  2. * 任意节点
  3. */
  4. @Test
  5. public void createProcessInstanceByKey(){
  6. String processDefinitionKey = "Process_0ihs6z7";
  7. String activityId = "Task_1ojlhmg";
  8. ProcessInstantiationBuilder instantiationBuilder = runtimeService.createProcessInstanceByKey(processDefinitionKey);
  9. instantiationBuilder.businessKey("gjf")
  10. // .startBeforeActivity(activityId) //节点之前
  11. // .startBeforeActivity(activityId) //节点之后
  12. .startTransition("SequenceFlow_1ojnaaf") //线
  13. .execute();
  14. }

状态

image.png
image.png

历史记录

  • act_ru_execition : 正在执行的信息
  • act_hi_procinst : 已经执行完成的历史流程实例信息
  • act_hi_actinst : 存放历史所有完成的活动
  • act_ru_task : 正在执行的任务信息
  • act_hi_taskinst : 已经执行完成的历史任务信息

    历史活动信息查询

    image.png

    历史任务查询

    image.png

发起人设置

  1. @Test
  2. public void start(){
  3. String authenticatedUserId = "gjf";
  4. identityService.setAuthenticatedUserId(authenticatedUserId);
  5. runtimeService.startProcessInstanceById("Process_0ihs6z7:1:3");
  6. }

image.png
image.png

删除实例

删除单个

image.png

删除多个

  1. /**
  2. * 删除
  3. * delete from ACT_RU_TASK where ID_ = ? and REV_ = ?
  4. * delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
  5. * UPDATE ACT_HI_ACTINST SET EXECUTION_ID_ = ?, PROC_DEF_KEY_ = ?, PROC_DEF_ID_ = ?, ACT_ID_ = ?, ACT_NAME_ = ?, ACT_TYPE_ = ?, PARENT_ACT_INST_ID_ = ? , END_TIME_ = ? , DURATION_ = ? , ACT_INST_STATE_ = ? WHERE ID_ = ?
  6. * update ACT_HI_PROCINST set PROC_DEF_ID_ = ?, PROC_DEF_KEY_ = ?, BUSINESS_KEY_ = ?, END_ACT_ID_ = ?, DELETE_REASON_ = ?, SUPER_PROCESS_INSTANCE_ID_ = ?, STATE_ = ? , END_TIME_ = ? , DURATION_ = ? where ID_ = ?
  7. * update ACT_HI_TASKINST set EXECUTION_ID_ = ?, PROC_DEF_KEY_ = ?, PROC_DEF_ID_ = ?, NAME_ = ?, PARENT_TASK_ID_ = ?, DESCRIPTION_ = ?, OWNER_ = ?, ASSIGNEE_ = ?, DELETE_REASON_ = ?, TASK_DEF_KEY_ = ?, PRIORITY_ = ?, DUE_DATE_ = ?, FOLLOW_UP_DATE_ = ?, CASE_INST_ID_ = ? , END_TIME_ = ? , DURATION_ = ? where ID_ = ?
  8. */
  9. @Test
  10. public void deleteProcessInstance(){
  11. runtimeService.deleteProcessInstance("301","删除测试");
  12. }
  13. @Test
  14. public void deleteProcessInstance1(){
  15. List<String> processInstanceIds = Arrays.asList("401", "501");
  16. runtimeService.deleteProcessInstances(processInstanceIds,"批量删除",true,true);
  17. }

流程实例获取运行的活动节点

  1. /**
  2. * select * from ACT_RU_EXECUTION where PROC_INST_ID_ = ?
  3. */
  4. @Test
  5. public void getActiveActivityIds() {
  6. String executionId = "101";
  7. List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);
  8. activeActivityIds.stream().forEach(System.out::println);
  9. }
  10. @Test
  11. public void getActivityInstance() {
  12. String processInstanceId = "101";
  13. ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstanceId);
  14. System.out.println(activityInstance);
  15. }

源码

image.png

流程定义的挂起和激活操作

指定流程定义的挂起

  1. @Test
  2. public void suspendProcessDefinitionById(){
  3. //挂起
  4. // repositoryService.suspendProcessDefinitionById("Process_0ihs6z7:3:603");
  5. //测试 发起流程
  6. //org.camunda.bpm.engine.SuspendedEntityInteractionException:
  7. // ENGINE-03043 Process Definition with id 'Process_0ihs6z7:3:603' is suspended.
  8. // runtimeService.startProcessInstanceById("Process_0ihs6z7:3:603");
  9. //激活
  10. repositoryService.updateProcessDefinitionSuspensionState()
  11. .byProcessDefinitionId("Process_0ihs6z7:3:603")
  12. .activate();
  13. }

image.png

image.png