如下代码可以实现流程实例的挂起和激活
但是里面有一个坑
activateProcessDefinitionById和suspendProcessDefinitionById方法中的第三个参数是要填写时间
我填写了new Date()
然后就修改不成功
只能写null才能过去
这个坑先留着
//对流程定义来进行全部流程实例的挂起和激活
//假如到月底我不做处理出差申请了,那么就把所有的出差审批都给挂起,月初了我再全部激活
@Test
public void suspendAllProcessInstance() {
//1.获取引擎
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//2.获取repositoryService
RepositoryService repositoryService = processEngine.getRepositoryService();
//3.查询流程定义, 获取流程定义的查询对象来查询
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("myEvection")
.singleResult();
//4.查询当前流程定义的实例是否都是挂起状态
//获取当前实例是否是挂起状态,对应的表中字段1为true,2位false
boolean suspended = processDefinition.isSuspended();
//5.获取流程定义id
String definitionId = processDefinition.getId();
//6.如果是挂起状态,改为激活状态
if (suspended) {
repositoryService.activateProcessDefinitionById(definitionId, true, null);
System.out.println(definitionId + "已激活");
} else {
//7.如果是激活状态,则改为挂起状态
//参数1是流程定义的id,参数2是是否要激活,参数3是激活时间
repositoryService.suspendProcessDefinitionById(definitionId, true, null);
System.out.println(definitionId + "已挂起");
}
}
//单人的流程实例的挂起和激活
@Test
public void suspendOneProcessInstance(){
//1.获取引擎
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//2.获取runtimeService
RuntimeService runtimeService = processEngine.getRuntimeService();
//3.获取流程实例的id
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
.processInstanceId("10001")
.singleResult();
//4.获取流程实例的状态
boolean suspended = processInstance.isSuspended();
//5.获取流程实例id
String id = processInstance.getId();
System.out.println("流程实例id:" + id);
if (suspended){
runtimeService.activateProcessInstanceById(id);
System.out.println("流程实例id:" + id +"激活");
}else{
runtimeService.suspendProcessInstanceById(id);
System.out.println("流程实例id:" + id +"挂起");
}
}