流程部署
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deployMent = repositoryService.createDeployment().name("流程名").addClasspathResource("bpmn所在地址和名字,如(bpmn/evection.bpmn)").addClasspathResource("png所在地址和名字,如(bpmn/evection.png)").deploy();
启动流程实例
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance instance = runtimeService.startProcessInstanceByKey("流程的key值");
查询个人待执行任务
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
List<Task> taskList = taskService.createTaskQuery().processDefinitionKey("流程的key").taskAssignee("负责人名").list();
完成个人任务
ProcessEngine processEngint = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService;
Task task = taskService.createTaskQuery().processDefinitionKey("流程Key").taskAssignee("某人").singleResult();
taskService.complete(task.getId());
查询流程定义
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ProcessDefinitionQuery difinitionQuery = repositoryService.createProcessDefinitionQuery();
List<ProcessDefinition> definitionList = definitionQuery.processDefinitionKey("流程key").orderByProcessDefinitionVersion().desc().list();
删除流程部署信息
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
String deploymentId = 'id';
repositoryService.deleteDeployment(deploymentId);
下载资源文件
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("流程key").seingleResult();
String deploymentId = processDefinition.getDeploymentId();
String pngName = processDefinition.getDiagramResourceName();
repositoryService.getResourceAsStream(deploymentId,pngName);
String bpmnName = processDefinition.getResourceName();
File pngFile = new File("存放路径");
File bpmnFile = new File("存放路径");
FileOutputStream pngOutStream = new FileOutPutStream(pngFile);
FileOutputStream bpmnOutStream = new FileOutPutStream(bpmnFile);
IOUtils.copy(pngInput,pngOutStream);
IOUtils.copy(bpmnInput,bpmnOutStream);
pngOutStream.close();
bpmnOutStream.close();
pngInput.close();
bpmnInput.close();
查看历史信息
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
HistoryService historyService = processEngine.getHistoryService();
HistoryActivityInstanceQuery instanceQuery = historyService.createHistorcActivityInstanceQuery();
instanceQuery.processInsranceId("流程ID");
instanceQuery.orderByHistoricActivityInstanceStartTime().asc();
List<HistoricActivityInstance> activityInstanceList = instanceQuery.list();
添加业务key到Activiti的表
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance instance = runtimeService.startProcessInstanceByKey("流程key","bussinessKey")
全部流程实例的挂起与激活
ProcessEngine processEngine = processEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processENgine.getRepositoryService();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("流程key").singleResult();
boolean suspended = processDefinition.isSuspended();
String definitionId = processDefinition.getId();
if(suspended){
repositoryService.activateProcessDefinitionById(definitionId,true,null);
}else{
repositoryService.suspendProcessDefinitionById(definitionId,true,null);
}
单个流程实例的挂起与激活
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance instance = runtimeService.createProcessInstanceQuery().processInstanceId("流程ID").singleResult();
boolean suspended = instance.isSuspended();
String instanceId = instance.getId();
if(suspended){
runtimeService.activateProcessInstanceById(instanceId);
}else{
runtimeService.suspendProcessInstanceById(instanceId);
}