流程引擎及服务
- RepositoryService 流程仓库Service,可以管理流程仓库例如部署删除读取流程资源
- RuntimeService 运行时Service可以处理所有运行状态的流程实例流程控制(开始,暂停,挂起等)
- TaskService 任务Service用于管理、查询任务,例如签收、办理、指派等
- IdentitiServicec 身份Service可以管理查询用户、组之间的关系
- FormService 表单Service用于读取和流程、任务相关的表单数据
- HistoryService 历史Service用于查询所有的历史数据
- ManagementService 引擎管理Service,和具体业务无关,主要查询引擎配置,数据库作业
- DynamicBpmService 动态bpm服务
流程存储服务
RepositoryService
- 管理流程定义文件xml及静态资源服务
- 对流程定义文件对暂停激活
- 流程定义启动权限管理
- 部署文件构造器DeploymentBuilder
- 部署文件查询器DeploymentQuery
- 流程定义文件查询对象ProcessDefinitionQuery
API文档
序号 | 方法 | 含义 | 描述 | 库表字段 |
---|---|---|---|---|
1 | repositoryService.createDeployment().addClasspathResource("参数") .deploy() | 部署流程 | resources文件下面的xml流程文件 | 省略 |
2 | repositoryService.createDeploymentQuery().list() | 查询所有部署 | 省略 | 省略 |
3 | repositoryService.createProcessDefinitionQuery().list() | 查询所有部署流程 | 省略 | 省略 |
4 | repositoryService.suspendProcessDefinitionById(id)或ByKey | 挂起流程 | 根据流程id挂起流程 | 修改表ACT_RE_PROCDEF字段SUSPENSION_STATE_:1激活 2挂起 |
5 | repositoryService.activateProcessDefinitionById(id)或ByKey | 启动流程 | 根据流程id激活流程 | 修改表ACT_RE_PROCDEF字段SUSPENSION_STATE_:1激活 2挂起 |
6 | repositoryService.addCandidateStarterUser(流程id,用户id) | 流程与用户对应关系 | 添加流程与用户关系 | 操作ACT_RU_IDENTITYLINK表 |
7 | repositoryService.deleteCandidateStarterGroup(流程id,用户组id) | 流程与用户组对应关系 | 添加流程与用户组关系 | 操作ACT_RU_IDENTITYLINK表 |
8 | repositoryService.deleteCandidateStarterUser(流程id,用户id) | 流程与用户对应关系 | 删除流程与用户关系 | 操作ACT_RU_IDENTITYLINK表 |
9 | repositoryService.deleteCandidateStarterGroup(流程id,用户组id) | 流程与用户对应关系 | 删除流程与用户组关系 | 操作ACT_RU_IDENTITYLINK表 |
10 | repositoryService.getIdentityLinksForProcessDefinition(流程id) | 查询流程对应关系 | 查询流程对应用户跟组关系 | 查询ACT_RU_IDENTITYLINK表 |
测试代码
package com.guosh.activiti.coreapi;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.repository.DeploymentQuery;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.test.ActivitiRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
/**
* 流程存储服务
* @Author: Guosh
* @Date: 2019-07-19 11:33
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:activiti-context.xml"})
public class RepostoryServiceTest {
private static final Logger logger = LoggerFactory.getLogger(RepostoryServiceTest.class);
@Rule
@Autowired
public ActivitiRule activitiRule;
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
@Test
public void testRepository(){
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
//classpath方式
Deployment deploy = deploymentBuilder.name("测试部署资源1")
.addClasspathResource("my-process.bpmn20.xml")
.addClasspathResource("second_approve.bpmn20.xml")
.deploy();
//多次部署
//classpath方式
DeploymentBuilder deploymentBuilder2 = repositoryService.createDeployment();
Deployment deploy2 = deploymentBuilder2.name("测试部署资源2")
.addClasspathResource("my-process.bpmn20.xml")
.addClasspathResource("second_approve.bpmn20.xml")
.deploy();
//查询部署
List<Deployment> deployments = repositoryService.createDeploymentQuery()
.orderByDeploymenTime().asc()
.list();
for (Deployment deployment:deployments){
logger.info("deployment = {}",deployment);
}
logger.info("deployments.size = {}",deployments.size());
//查询已经部署流程
List<ProcessDefinition> processDefinitions = repositoryService
.createProcessDefinitionQuery()
.list();
for (ProcessDefinition processDefinition:processDefinitions) {
logger.info("processDefinition = {}, version = {}, key = {}, id = {}",
processDefinition,
processDefinition.getVersion(),
processDefinition.getKey(),
processDefinition.getId());
}
}
//测试流程挂起启动
@Test
public void testSuspend(){
//流程挂起
repositoryService.suspendProcessDefinitionById("my-process:1:7506");
//如果流程挂起启动流程会报错
try{
logger.info("启动流程");
runtimeService.startProcessInstanceById("my-process:1:7506");
logger.info("启动成功");
}catch (Exception e){
logger.info("启动失败");
logger.info(e.getMessage(),e);
}
//流程激活
repositoryService.activateProcessDefinitionById("my-process:1:7506");
logger.info("启动流程");
runtimeService.startProcessInstanceById("my-process:1:7506");
logger.info("启动成功");
}
//测试指定用户或者用户组与流程的关系
@Test
public void testCandidateStarter(){
//给流程指定用户参数流程id与用户id
repositoryService.addCandidateStarterUser("my-process:1:7506","user");
//给流程指定用户组
repositoryService.addCandidateStarterGroup("my-process:1:7506","groupM");
//查询流程对应关系的所有用户
List<IdentityLink> identityLinks = repositoryService.getIdentityLinksForProcessDefinition("my-process:1:7506");
for (IdentityLink identityLink:identityLinks) {
logger.info("identityLink = {}",identityLink);
}
//删除关系
repositoryService.deleteCandidateStarterUser("my-process:1:7506","user");
repositoryService.deleteCandidateStarterGroup("my-process:1:7506","groupM");
}
}
流程运行控制服务
RuntimeService
- 启动流程及对流程数据对控制
- 流程实例(ProcessInstance)与执行流(Execution)查询
- 触发流程操作、接收消息和信号
RuntimeService启动流程变量管理
- 启动流程的常用方式(id,key,message)
- 启动流程可选参数(businesskey,variables,tenantId)
- 变量(variables)的设置和获取
流程实例与执行流
- 流程实例(ProcessInstance)表示一次工作流业务的数据实体
- 执行流(Execution)表示流程实例中具体的执行路径
- 流程实例接口继承与执行流
流程触发
- 使用trigger触发ReceiveTask节点
- 触发信号捕获事件signalEvenReceived
- 触发消息捕获事件messageEventReceived
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | runtimeService.startProcessInstanceByKey(String processDefinitionKey, Map<String, Object> variables) | 根据部署流程key启动一个流程 | 省略 |
2 | runtimeService.startProcessInstanceById(String processDefinitionId, Map<String, Object> variables) | 根据部署流程id启动一个流程 | 省略 |
3 | runtimeService.createProcessInstanceBuilder().businessKey("businessKey001") .processDefinitionKey(String processDefinitionKey).variables( Map<String, Object> variables) .start() | 根据processInstanceBuilder启动流程 | 省略 |
4 | runtimeService.getVariables(processInstance.getId()) | 根据流程实例id获取传参 | 省略 |
5 | runtimeService.setVariable(processInstance.getId(),"key3","value3") | 新增或修改参数 | 省略 |
6 | runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()) | 查询流程实例 | 根据流程id获取流程实例 |
7 | runtimeService.createExecutionQuery() | 获取流程执行对象 | 省略 |
测试代码
/**
* 流程运行控制服务
* @Author: Guosh
* @Date: 2019-07-19 11:33
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:activiti-context.xml"})
public class RuntimeServiceTest {
private static final Logger logger = LoggerFactory.getLogger(RuntimeServiceTest.class);
@Rule
@Autowired
public ActivitiRule activitiRule;
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
//部署流流程
@Test
public void testRepository(){
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
//classpath方式
Deployment deploy = deploymentBuilder.name("测试部署资源1")
.addClasspathResource("my-process-signal-received.bpmn20.xml")
.deploy();
}
//根据key启动流程
@Test
public void testStartProcess(){
Map<String,Object> variables=new HashMap<String,Object>();
//传入参数
variables.put("key1","value1");
//启动流程根据key默认使用的流程的最新版本
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
}
//根据id启动流程
@Test
public void testStartProcessById(){
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
Map<String,Object> variables=new HashMap<String,Object>();
//传入参数
variables.put("key1","value1");
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), variables);
logger.info("processInstance = {}",processInstance);
}
//根据processInstanceBuilder启动流程
@Test
public void testProcessInstanceBuilder(){
Map<String,Object> variables=new HashMap<String,Object>();
//传入参数
variables.put("key1","value1");
//启动流程
ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
ProcessInstance processInstance = processInstanceBuilder.businessKey("businessKey001")
.processDefinitionKey("my-process")
.variables(variables)
.start();
logger.info("processInstance = {}",processInstance);
}
//根据其流程实例id获取参数
@Test
public void testVariables(){
Map<String,Object> variables=new HashMap<String,Object>();
//传入参数
variables.put("key1","value1");
variables.put("key2","value2");
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
//新增一个参数
runtimeService.setVariable(processInstance.getId(),"key3","value3");
//修改一个参数
runtimeService.setVariable(processInstance.getId(),"key2","value2_1");
//获取流程实例传过来的参数
Map<String, Object> variables1 = runtimeService.getVariables(processInstance.getId());
logger.info("variables1 = {}",variables1);
}
//根据其流程实例id获取
@Test
public void testProcessInstanceQuery(){
Map<String,Object> variables=new HashMap<String,Object>();
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
ProcessInstance processInstance1 = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstance.getId()).singleResult();
}
//流程执行对象查询操作
@Test
public void testExecutionQuery(){
Map<String,Object> variables=new HashMap<String,Object>();
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process", variables);
logger.info("processInstance = {}",processInstance);
//流程执行对象
List<Execution> executions = runtimeService.createExecutionQuery().list();
for (Execution execution:executions){
logger.info("execution = {}",execution);
}
}
}
流程触发
image.png //流程触发
@Test
public void testTrigger(){
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
logger.info("processInstance = {}",processInstance);
//流程执行对象
Execution executions = runtimeService.createExecutionQuery().activityId("someTask").singleResult();
logger.info("executions = {}",executions);
//触发执行
runtimeService.trigger(executions.getId());
executions = runtimeService.createExecutionQuery().activityId("someTask").singleResult();
logger.info("executions = {}",executions);
}
流程文件xml
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<receiveTask id="someTask"/>
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
信号捕获节点触发
image.png //信号流程节点触发
@Test
public void testSignalEventReceived(){
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
logger.info("processInstance = {}",processInstance);
//查询触发信号
Execution executions = runtimeService.createExecutionQuery().signalEventSubscriptionName("my-signal").singleResult();
logger.info("executions = {}",executions);
//触发执行
runtimeService.signalEventReceived("my-signal");
}
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<!--信号-->
<signal id="signalStart" name="my-signal"/>
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="signal-received" />
<!--捕获事件-->
<intermediateCatchEvent id="signal-received">
<signalEventDefinition signalRef="signalStart"/>
</intermediateCatchEvent>
<sequenceFlow id="flow2" sourceRef="signal-received" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
消息触发
//消息流程节点触发
@Test
public void testMessageEventReceived(){
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
logger.info("processInstance = {}",processInstance);
//查询触发信号
Execution executions = runtimeService.createExecutionQuery().messageEventSubscriptionName("my-message").singleResult();
logger.info("executions = {}",executions);
//触发执行
runtimeService.messageEventReceived("my-message",executions.getId());
}
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<!--信号-->
<message id="messageStart" name="my-message"/>
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="message-received" />
<!--捕获事件-->
<intermediateCatchEvent id="message-received">
<messageEventDefinition messageRef="messageStart"/>
</intermediateCatchEvent>
<sequenceFlow id="flow2" sourceRef="message-received" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
流程基于message启动
@Test
public void testMessageStart(){
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByMessage("my-message");
logger.info("processInstance = {}",processInstance);
}
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<!--信号-->
<message id="messageStart" name="my-message"/>
<process id="my-process">
<startEvent id="start" >
<messageEventDefinition messageRef="messageStart"/>
</startEvent>
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<userTask id="someTask" name="Activiti is awesome!" />
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
任务管理服务
- TaskService
- 对用户任务(UserTask)管理和流程控制
- 设置用户任务(UserTask)对权限信息(拥有者,候选人,办理人)
- 针对用户任务添加任务附件、任务;评价和事件记录
- TaskService对Task管理与流程控制
- Task对象对创建,删除
- 查询Task,并驱动Task节点完成执行
- Task相关参数变量(variable)设置
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | taskService.createTaskQuery().list() | 查询所有任务 | 省略 |
2 | taskService.setVariable("任务id","键","值") | 设置普通变量 | 省略 |
3 | taskService.setVariableLocal("任务id","键","值") | 设置本地变量 | 省略 |
4 | taskService.getVariables("任务id") | 获取普通变量 | 省略 |
5 | taskService.getVariablesLocal(("任务id") | 获取本地变量 | 省略 |
6 | runtimeService.getVariables(task.getExecutionId()) | 通过流获取变量 | 省略 |
7 | taskService.complete("任务id","传值Map") | 到下一个节点 | 省略 |
@Test
public void testTaskService(){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message","my test message !!");
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
//获取task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
//描述信息
logger.info("task.description = {}",task.getDescription());
//设置普通变量
taskService.setVariable(task.getId(),"key1","value1");
//设置本地变量
taskService.setVariableLocal(task.getId(),"localkey1","localval1");
//获取普通变量
Map<String, Object> taskServiceVariables = taskService.getVariables(task.getId());
//获取本地变量
Map<String, Object> taskServiceVariablesLocal = taskService.getVariablesLocal(task.getId());
//通过执行流获取
Map<String, Object> variables1 = runtimeService.getVariables(task.getExecutionId());
//{key1=value1, localkey1=localval1, message=my test message !!}
logger.info("taskServiceVariables = {}",taskServiceVariables);
//{localkey1=localval1}
logger.info("taskServiceVariablesLocal = {}",taskServiceVariablesLocal);
//{key1=value1, message=my test message !!}
logger.info("variables1 = {}",variables1);
Map<String,Object> completeVar=new HashMap<String, Object>();
completeVar.put("ckey1","cvalue1");
//执行下一个节点
taskService.complete(task.getId(),completeVar);
- TaskService设置Task权限信息
- 候选用户(candidateUser)和候选组(candidateGroup)
- 指定拥有人(Owner)和办理人(Assignee)
- 通过claim设置办理人
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | taskService.setOwner("taskId","user") | 设置流程发起人 | 省略 |
2 | taskService.claim(""taskId"","user") | 指定代办人 | 省略 |
3 | taskService.addCandidateUser("user") | 添加候选人 | 省略 |
4 | taskService.addCandidateGroup("group") | 添加候选组 | 省略 |
5 | taskService.createTaskQuery().taskCandidateUser("user").taskUnassigned().list() | 查询候选人列表有user但是没指定代办人任务 | 省略 |
6 | taskService.createTaskQuery().taskCandidateUser("user").taskUnassigned().list() | 查询候选人列表有我但是没指定代办人任务 | 省略 |
7 | taskService.createTaskQuery().taskAssignee("user").list() | 查询代办人为user的任务 | 省略 |
8 | taskService.getIdentityLinksForTask("taskId") | 查询任务与人员之间的关系 | 省略 |
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="my-process">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" />
<!--activiti:candidateStarterUsers指定候选人-->
<userTask id="someTask" name="Activiti is awesome!" activiti:candidateUsers="jimmy,user1,user2">
<!--添加描述-->
<documentation>some task ${message}</documentation>
</userTask>
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
//用户权限测试
@Test
public void testTaskServiceUser(){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message","my test message !!");
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
//获取task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
//描述信息
logger.info("task.description = {}",task.getDescription());
//设置流程到发起人
taskService.setOwner(task.getId(),"user1");
//指定办理人
//taskService.setAssignee(task.getId(),"jimmy");
//查询候选人列表有我但是没指定代办人任务
List<Task> taskList = taskService.createTaskQuery()
.taskCandidateUser("jimmy")
.taskUnassigned().list();
//指定办理人claim会检查该任务是否已经被认领,如果被认领则会抛出ActivitiTaskAlreadyClaimedException
for (Task task1:taskList){
taskService.claim(task1.getId(),"jimmy");
}
//查询task与多少用户相关数据
List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(task.getId());
for(IdentityLink identityLink:identityLinksForTask){
logger.info("identityLink = {}",identityLink);
}
//查询代办人为jimmy的任务
List<Task> taskList1 = taskService.createTaskQuery().taskAssignee("jimmy").list();
for (Task task1:taskList1){
Map<String,Object> completeVar=new HashMap<String, Object>();
completeVar.put("ckey1","cvalue1");
taskService.complete(task.getId(),completeVar);
}
}
- TaskService设置Task附加信息
- 任务附件(Attachment)创建与查询
- 任务评价(Comment)创建与查询
序号 | 方法 | 含义 | 描述 |
---|---|---|---|
1 | taskService.createAttachment("类型","任务id","流程Id","附件名称","附件描述","流或者url) | 上传附件 | 省略 |
2 | taskService.getTaskAttachments("任务id") | 上传附件 | 省略 |
3 | taskService.addComment("任务id","流程id","批注1") | 添加审批批注 | 省略 |
4 | taskService.getTaskComments("任务id") | 查询审批批注 | 省略 |
5 | taskService.getTaskEvents("任务id") | 查询任务日志记录 | 省略 |
//文件附件测试
@Test
public void testTaskServiceAttachment(){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message","my test message !!");
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
//获取task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
//描述信息
logger.info("task.description = {}",task.getDescription());
//上传附件
taskService.createAttachment("url",task.getId(),
task.getProcessInstanceId(),"附件名称","附件描述","/url/test.png");
//查询附件
List<Attachment> taskAttachments = taskService.getTaskAttachments(task.getId());
for (Attachment attachment:taskAttachments){
logger.info("attachment = {}",attachment);
}
}
//批注测试
@Test
public void testTaskServiceComment(){
Map<String,Object> variables=new HashMap<String,Object>();
variables.put("message","my test message !!");
//启动流程
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("my-process",variables);
//获取task
Task task = taskService.createTaskQuery().singleResult();
logger.info("task = {}",task.toString());
//描述信息
logger.info("task.description = {}",task.getDescription());
//添加审批批注
taskService.addComment(task.getId(),task.getProcessInstanceId(),"recourd note 1");
taskService.addComment(task.getId(),task.getProcessInstanceId(),"recourd note 2");
//查询审批批注
List<Comment> taskComments = taskService.getTaskComments(task.getId());
for (Comment comment:taskComments){
logger.info("comment = {}",comment);
}
//查询所有task日志记录
List<Event> taskEvents = taskService.getTaskEvents(task.getId());
for (Event event:taskEvents){
logger.info("event = {}",event);
}
}
网友评论