在实际场景中可能由于流程变更需要将当前运行的流程暂停而不是删除,流程暂停后将不能继续执
行。
一、全部流程挂起激活
流程定义为挂起状态,该流程定义将不允许启动新的流程实例,同时该流程定义下的所有的流程实例都将全部挂起暂停执行。
/** * 全部流程挂起实例与激活 */ @Test public void test02() { // 获取ProcessEngine对象 ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); // 获取RepositoryServie对象 RepositoryService repositoryService = engine.getRepositoryService(); // 查询流程定义的对象 ProcessDefinition definition = repositoryService.createProcessDefinitionQuery() .processDefinitionKey("evection").list().get(0); //获取当前流程定义状态是否挂起 boolean suspended = definition.isSuspended(); String id = definition.getId(); // 如果挂起就激活,如果激活就挂起 if (suspended) { // 挂起->激活流程 repositoryService.activateProcessDefinitionById(id, true, null); System.out.println("流程定义:" + id + ",已激活"); } else { //激活->挂起流程 repositoryService.suspendProcessDefinitionById(id, true, null); System.out.println("流程定义:" + id + ",已挂起"); } }
二、单个实例挂起
操作流程实例对象,针对单个流程执行挂起操作,某个流程实例挂起则此流程不再继续执行,当前流程 定义的其他流程实例是不受干扰的。完成该流程实例的当前任务会抛异常。
/** * 单个流程实例挂起与激活 */ @Test public void test03() { ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); RuntimeService runtimeService = engine.getRuntimeService(); ProcessInstance definition = runtimeService.createProcessInstanceQuery() .processInstanceId("22501").list().get(0); //获取当前流程定义状态是否挂起 boolean suspended = definition.isSuspended(); String id = definition.getId(); // 如果挂起就激活,如果激活就挂起 if (suspended) { // 挂起->激活流程 runtimeService.activateProcessInstanceById(id); System.out.println("流程定义:" + id + ",已激活"); } else { //激活->挂起流程 runtimeService.suspendProcessInstanceById(id); System.out.println("流程定义:" + id + ",已挂起"); } }
关键SQL
SELECT DISTINCT RES.*, P.KEY_ AS ProcessDefinitionKey, P.ID_ AS ProcessDefinitionId, P.NAME_ AS ProcessDefinitionName, P.VERSION_ AS ProcessDefinitionVersion, P.DEPLOYMENT_ID_ AS DeploymentId FROM ACT_RU_EXECUTION RES INNER JOIN ACT_RE_PROCDEF P ON RES.PROC_DEF_ID_ = P.ID_ WHERE RES.PARENT_ID_ IS NULL AND RES.ID_ = ? AND RES.PROC_INST_ID_ = ? ORDER BY RES.ID_ ASC LIMIT ? OFFSET ? UPDATE ACT_RU_EXECUTION SET REV_ = ?, BUSINESS_KEY_ = ?, PROC_DEF_ID_ = ?, ACT_ID_ = ?, IS_ACTIVE_ = ?, IS_CONCURRENT_ = ?, IS_SCOPE_ = ?, IS_EVENT_SCOPE_ = ?, IS_MI_ROOT_ = ?, PARENT_ID_ = ?, SUPER_EXEC_ = ?, ROOT_PROC_INST_ID_ = ?, SUSPENSION_STATE_ = ?, NAME_ = ?, IS_COUNT_ENABLED_ = ?, EVT_SUBSCR_COUNT_ = ?, TASK_COUNT_ = ?, JOB_COUNT_ = ?, TIMER_JOB_COUNT_ = ?, SUSP_JOB_COUNT_ = ?, DEADLETTER_JOB_COUNT_ = ?, VAR_COUNT_ = ?, ID_LINK_COUNT_ = ? WHERE ID_ = ? AND REV_ = ?
25001(String), 25001(String), 2147483647(Integer), 0(Integer)