activiti 工作流关键表分析

0. 前置条件

activiti 工作流关键表分析_第1张图片

其中步骤一和步骤二分别包含变量step1_user和step2_user

1. 流程部署
代码
ProcessEngineConfiguration configuration
				= ProcessEngineConfiguration
				.createProcessEngineConfigurationFromResource("activiti.cfg.xml");

ProcessEngine processEngine = configuration.buildProcessEngine();

RepositoryService repositoryService = processEngine.getRepositoryService();
DeploymentBuilder builder = repositoryService.createDeployment();
builder.addClasspathResource("test.bpmn");
builder.deploy();
涉及表
  1. 执行buildProcessEngine,根据配置可创建activiti的全部23张表;
  2. 执行builder.deploy()后,test.bpmn所代表的流程定义被创建,主要涉及以下两张表:
    2.1 ACT_RE_PROCDEF: 这里存储流程定义名称、版本、关键字、以及对应的资源文件,也就是test.bpmn;
    2.2 ACT_RE_DEPLOYMENT: 存储这一次的部署记录

备注: 这里的RE是Repository的缩写,相关命名规范下的表存储静态资源信息

2. 实例化一个新流程
代码
RuntimeService runtimeService =processEngine.getRuntimeService();
Map variables=new HashMap();
variables.put("step1_user", "fred05");
runtimeService.startProcessInstanceByKey("test_process", variables);

涉及表
  1. ACT_RU_TASK:当前跑的流程实例所执行到的任务;
  2. ACT_RU_VARIABLE: 当前跑的流程实例所用到的变量,即代码中用map传入的参数
  3. ACT_RU_EXECUTION:当前跑的流程实例,上述ACT_RU_TASK、ACT_RU_VARIABLE都会关联到ACT_RU_EXECUTION的主键
  4. ACT_HI_ACTINST: 记录历史流转的节点
  5. ACT_HI_TASKINST: 记录历史流转的task,应该说ACT_HI_ACTINST包含了ACT_HI_TASKINST,后者只记录usertask类型的节点;
  6. ACT_HI_PROCINST: 整个流程实例的历史信息
3. 走到下一步任务
代码
TaskService taskService = processEngine.getTaskService();
List tasks = taskService.createTaskQuery().taskCandidateOrAssigned("fred05").list();

for (Task task : tasks) {
	System.out.println("taskId:" + task.getId() +
			",taskName:" + task.getName() +
			",assignee:" + task.getOwner() +
			",createTime:" + task.getCreateTime() +
			", processInstanceId " + task.getProcessInstanceId());
}
涉及表
  1. RU相关表切换task至最新状态
  2. HI相关表新增一条新记录,注意的是记录中ENDTIME会赋值
4. 流程结束
代码

涉及表
  1. RU 相关的表中无相关记录
  2. ACT_HI_PROCINST表中将有这条流程实例的完整记录
5. 其他场景
并行网关 ParallelGateWay

activiti 工作流关键表分析_第2张图片

代码
ProcessEngineConfiguration configuration
				= ProcessEngineConfiguration
				.createProcessEngineConfigurationFromResource("activiti.cfg.xml");

ProcessEngine processEngine = configuration.buildProcessEngine();

RepositoryService repositoryService = processEngine.getRepositoryService();
DeploymentBuilder builder = repositoryService.createDeployment();
builder.addClasspathResource("test05.bpmn");
builder.deploy();

RuntimeService runtimeService =processEngine.getRuntimeService();
runtimeService.startProcessInstanceByKey("test_process_02", (Map) null);

TaskService taskService = processEngine.getTaskService();
List fred_task = taskService.createTaskQuery().taskCandidateOrAssigned("fred").list();
List sinny_task = taskService.createTaskQuery().taskCandidateOrAssigned("sinny").list();

for (Task task : fred_task) {
	System.out.println("taskId:" + task.getId() +
			",taskName:" + task.getName() +
			",assignee:" + task.getOwner() +
			",createTime:" + task.getCreateTime() +
			", processInstanceId " + task.getProcessInstanceId());

	processEngine.getTaskService().complete(task.getId(), null);
}

for (Task task : sinny_task) {
	System.out.println("taskId:" + task.getId() +
			",taskName:" + task.getName() +
			",assignee:" + task.getOwner() +
			",createTime:" + task.getCreateTime() +
			", processInstanceId " + task.getProcessInstanceId());

	processEngine.getTaskService().complete(task.getId(), null);
}
涉及表
  1. 此时在任务启动后,ACT_RU_TASK会有两个task;
  2. 同时ACT_RU_EXECUTION也会有多条记录,每个待执行的task都是一条记录,其中IS_CONCURRENT_ 是否并行字段为true
  3. 当两个task都结束后,工作流实例才结束,ACT_HI_PROCINST的END_TIME_才被赋值

你可能感兴趣的:(其他,java)