Activiti7工作流引擎:挂起状态和任务组

Posted vbirdbest

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activiti7工作流引擎:挂起状态和任务组相关的知识,希望对你有一定的参考价值。

挂起和激活流程实例

某些情况可能由于流程变更需要将当前运行的流程暂停而不是直接删除,流程暂停后将不会继续执行。

全部流程实例挂起

操作流程定义为挂起状态,该流程定义下边所有的流程实例全部暂停:流程定义为挂起状态该流程定义将不允许启动新的流程实例,同时该流程定义下所有的流程实例将全部挂起暂停执行。

@Test
public void testProcessSuspended() 
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey("offwork")
            .singleResult();
    if (processDefinition.isSuspended()) 
        repositoryService.activateProcessDefinitionById(processDefinition.getId());
     else 
        repositoryService.suspendProcessDefinitionById(processDefinition.getId());
    

ACT_RE_PROCDEF.SUSPENSION_STATE_ 挂起状态 2:挂起,1:激活

update ACT_RE_PROCDEF 
set 
	REV_ = 2, 
	SUSPENSION_STATE_ = 2, 
	CATEGORY_ = 'http://www.activiti.org/test'
WHERE ID_ = 'offwork:1:3' and REV_ = 1;

挂起单个流程实例。将ACT_RU_TASK和ACT_RU_EXECUTION的SUSPENSION_STATE_修改为2

@Test
public void testSuspendedProcessInstance() 
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
            .processInstanceId("2501")
            .singleResult();
    boolean suspended = processInstance.isSuspended();
    if (suspended) 
        runtimeService.activateProcessInstanceById(processInstance.getId());
     else 
        runtimeService.suspendProcessInstanceById(processInstance.getId());
    

-- ACT_RU_TASK.SUSPENSION_STATE_ = 2
update ACT_RU_TASK 
SET 
REV_ = 2, NAME_ = '项目经理', PARENT_TASK_ID_ = null, PRIORITY_ = 50, CREATE_TIME_ = '2021-12-11 16:41:26.558', OWNER_ = null, ASSIGNEE_ = '傻经理', DELEGATION_ = null, EXECUTION_ID_ = '2505', PROC_DEF_ID_ = 'offwork:1:3', DESCRIPTION_ = null, DUE_DATE_ = null, CATEGORY_ = null, 
SUSPENSION_STATE_ = 2, 
FORM_KEY_ = null, CLAIM_TIME_ = null
WHERE ID_= '5002' and REV_ = 1;

-- ACT_RU_EXECUTION.SUSPENSION_STATE_ = 2
update ACT_RU_EXECUTION 
set 
	REV_ = 2, BUSINESS_KEY_ = '1', PROC_DEF_ID_ = 'offwork:1:3', ACT_ID_ = null, IS_ACTIVE_ = true, IS_CONCURRENT_ = false, IS_SCOPE_ = true, IS_EVENT_SCOPE_ = false, IS_MI_ROOT_ = false, PARENT_ID_ = null, SUPER_EXEC_ = null, ROOT_PROC_INST_ID_ = '2501', 
	SUSPENSION_STATE_ = 2, 
	NAME_ = null, IS_COUNT_ENABLED_ = false, EVT_SUBSCR_COUNT_ = 0, TASK_COUNT_ = 0, JOB_COUNT_ = 0, TIMER_JOB_COUNT_ = 0, SUSP_JOB_COUNT_ = 0, DEADLETTER_JOB_COUNT_ = 0, VAR_COUNT_ = 0, ID_LINK_COUNT_ = 0
WHERE ID_ = '2501' and REV_ = 1;

候选人CandidateUsers

在流程定义中在任务结点的 assignee 固定设置任务负责人,在流程定义时将参与者固定设置在.bpmn 文件中,如果临时任务负责人变更则需要修改流程定义,系统可扩展性差。

针对这种情况可以给任务设置多个候选人,可以从候选人中选择参与者来完成任务。

步骤:

  1. 查询组任务
  2. 拾取任务:将任务的负责人设置为自己
  3. 查询个人任务
  4. 办理任务
@Test
public void test() 
    // 1. 查询组任务 TODO SQL
    String currentUserId = "lisipm";
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    TaskService taskService = processEngine.getTaskService();
    List<Task> taskList = taskService.createTaskQuery()
            .processDefinitionKey("candidateUsers")
            .taskCandidateUser(currentUserId)
            .list();
    for (Task task : taskList) 
        // 拾取任务,将自己设为任务的负责人
        taskService.claim(task.getId(), currentUserId);
        // 归还任务,将任务负责人设置为null
        taskService.setAssignee(task.getId(), null);
        // 任务交接,将自己的任务交给给候选人中的其它人
        taskService.setAssignee(task.getId(), "wangwupm");
    

以上是关于Activiti7工作流引擎:挂起状态和任务组的主要内容,如果未能解决你的问题,请参考以下文章

Activiti7工作流引擎:高阶篇 ReceiveTask

Activiti7工作流引擎:进阶篇 ReceiveTask

Activiti7工作流引擎:高阶篇 前进和后退任务

Activiti7工作流引擎:高阶篇 前进和后退任务

Activiti7工作流引擎:基础篇 任务监听器和流程监听器

Activiti7工作流引擎:任务监听器TaskListener