activiti5学习资料11(流程任务高亮显示)
所谓实例流程图的显示,就是显示流程图的同时,高亮显示正在执行的节点。有两种方法
直接生成带老亮节点的图片:
try{ // ProcessDefinitionEntity pde = (ProcessDefinitionEntity) RepositoryService // .getDeployedProcessDefinition(procDefId); InputStream imageStream = ProcessDiagramGenerator.generateDiagram( def, "png", runtimeService.getActiveActivityIds(executionId)); List<Task> list = taskService.createTaskQuery().processInstanceId(executionId).orderByTaskId().desc().list(); int size = list.size(); getRequest().setAttribute("inputStream", imageStream); }catch(RasterFormatException e){ e.printStackTrace(); }img.jsp
<%@page import="java.io.InputStream"%> <%@page import="org.activiti.engine.impl.*"%> <%@page import="org.activiti.engine.impl.pvm.*"%> <%@page import="org.activiti.engine.impl.pvm.process.*"%> <%@page import="org.activiti.engine.repository.*"%> <%@page import="org.activiti.engine.*"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% InputStream is = (InputStream)request.getAttribute("inputStream"); byte[] b = new byte[1024]; int len = -1; while((len = is.read(b, 0, 1024)) != -1) { response.getOutputStream().write(b, 0, len); // 防止异常:getOutputStream() has already been called for this response out.clear(); out = pageContext.pushBody(); } %>
/** * 显示流程图 * @return * @throws Exception */ public String getProcessPic() throws Exception { // String taskId = // "2901";//getRequest().getParameter("taskId");3016,552,3020 String procDefId = getRequest().getParameter("procDefId"); ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult(); String diagramResourceName = procDef.getDiagramResourceName(); InputStream imageStream = repositoryService.getResourceAsStream( procDef.getDeploymentId(), diagramResourceName); getRequest().setAttribute("inputStream", imageStream); return SUCCESS; } /** * 获取跟踪信息 * @return * @throws Exception */ public String getProcessMap() throws Exception { String procDefId = getRequest().getParameter("procDefId"); String executionId = getRequest().getParameter("executionId"); ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult(); ProcessDefinitionImpl pdImpl = (ProcessDefinitionImpl) processDefinition; String processDefinitionId = pdImpl.getId();// 流程标识 ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) .getDeployedProcessDefinition(processDefinitionId); ActivityImpl actImpl = null; ExecutionEntity execution = (ExecutionEntity) runtimeService .createExecutionQuery().executionId(executionId).singleResult();// 执行实例 String activitiId = execution.getActivityId();// 当前实例的执行到哪个节点 // List<String>activitiIds = runtimeService.getActiveActivityIds(executionId); List<ActivityImpl> activitiList = def.getActivities();// 获得当前任务的所有节点 // for(String activitiId : activitiIds){ for (ActivityImpl activityImpl : activitiList) { String id = activityImpl.getId(); if (id.equals(activitiId)) {// 获得执行到那个节点 actImpl = activityImpl; break; } } // } getRequest().setAttribute("coordinateObj", actImpl); getRequest().setAttribute("procDefId",procDefId ); return SUCCESS; }
<%@page import="java.io.InputStream"%> <%@page import="org.activiti.engine.impl.*"%> <%@page import="org.activiti.engine.impl.pvm.*"%> <%@page import="org.activiti.engine.impl.pvm.process.*"%> <%@page import="org.activiti.engine.repository.*"%> <%@page import="org.activiti.engine.*"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% InputStream is = (InputStream)request.getAttribute("inputStream"); byte[] b = new byte[1024]; int len = -1; while((len = is.read(b, 0, 1024)) != -1) { response.getOutputStream().write(b, 0, len); // 防止异常:getOutputStream() has already been called for this response out.clear(); out = pageContext.pushBody(); } %>
<%@page import="java.io.InputStream"%> <%@page import="org.activiti.engine.impl.*"%> <%@page import="org.activiti.engine.impl.pvm.*"%> <%@page import="org.activiti.engine.impl.pvm.process.*"%> <%@page import="org.activiti.engine.repository.*"%> <%@page import="org.activiti.engine.*"%> <%@ page language="java" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> </head> <body> <div > <img src="getProcessPic.action?procDefId=${procDefId}" style="position:absolute; left:0px; top:0px;"> <!-- 给执行的节点加框 --> <div style="position:absolute; border:2px solid red;left:${coordinateObj.x-1 }px;top:${coordinateObj.y-1 }px;width:${coordinateObj.width }px;height:${coordinateObj.height }px;"></div> </div> </body> </html>
<action name="getProcessPic" class="processInstanceAction" method="getProcessPic"> <result name = "success" >/incident/pic.jsp</result> </action> <action name="getProcessMap" class="processInstanceAction" method="getProcessMap"> <result name = "success" >/incident/showImg.jsp</result> </action>
activiti-explorer源码下载地址:https://github.com/HSSC/activiti-explorer