获取资源信息

/**
* 获取资源信息
*
* @throws IOException
*/
@Test
public void getProcessResources() throws IOException { // 1:流程定义ID
String processDefinitionId = "holiday:1:7504"; // 2:获取RepositoryService
RepositoryService repositoryService = defaultProcessEngine.getRepositoryService(); // 3:创建查询对象
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery(); // 4:查询流程定义
ProcessDefinition processDefinition = processDefinitionQuery.processDefinitionId(processDefinitionId).singleResult(); // 5:获取资源名称
String resourceName = processDefinition.getResourceName(); System.out.println("bpmn名称:" + resourceName); // 6:获取图片名称
String diagramResourceName = processDefinition.getDiagramResourceName(); System.out.println("png名称:" + diagramResourceName); File bpmnFile = new File("E:\\dance\\activiti7\\src\\main\\resources\\cp\\holiday.bpmn");
File pngFile = new File("E:\\dance\\activiti7\\src\\main\\resources\\cp\\holiday.png"); // 7:根据部署ID和资源名称获取资源流
InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName); // 8:创建输出流
FileOutputStream fileOutputStream = new FileOutputStream(bpmnFile); // 写文件
writeByte(resourceAsStream, fileOutputStream); // 获取图片
resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName); fileOutputStream = new FileOutputStream(pngFile); // 写文件
writeByte(resourceAsStream, fileOutputStream); System.out.println("获取资源成功!"); }

写出流方法

private void writeByte(InputStream resourceAsStream, OutputStream fileOutputStream) throws IOException {
int i = -1;
byte[] content = new byte[1024];
while ((i = resourceAsStream.read(content)) != -1) {
fileOutputStream.write(content, 0, i);
}
// 释放资源
fileOutputStream.flush();
fileOutputStream.close();
resourceAsStream.close();
}

查询流程历史信息

/**
* 获取历史信息
*/
@Test
public void testHistoric01() { // 获取历史信息Service
HistoryService historyService = defaultProcessEngine.getHistoryService(); // 启动的流程实例的ID
String processInstanceId = "10001"; // 根据流程实例ID查询 历史记录
List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime().asc().list(); // 输出信息
list.forEach(historicActivityInstance -> {
System.out.println("---------------------------------------------------");
System.out.println("当前激活ID:" + historicActivityInstance.getActivityId());
System.out.println("当前激活名称:" + historicActivityInstance.getActivityName());
System.out.println("流程定义ID:" + historicActivityInstance.getProcessDefinitionId());
System.out.println("流程实例ID:" + historicActivityInstance.getProcessInstanceId());
System.out.println("---------------------------------------------------");
}); }

作者:彼岸舞

时间:2020\08\31

内容关于:Activiti工作流

本文来源于网络,只做技术分享,一概不负任何责任

05-28 21:05