/** * 获取当前的流程追踪图 * @param processInstanceId * @param response * @return */ @RequestMapping("getWorkflowTrace") @ResponseBody public String getWorkflowTrace(String processInstanceId,HttpServletResponse response){ InputStream in = workFlowFacade.getTaskTraceDiagram(processInstanceId); try { OutputStream out = response.getOutputStream(); // 把图片的输入流程写入response的输出流中 byte[] b = new byte[1024]; for (int len = -1; (len= in.read(b))!=-1; ) { out.write(b, 0, len); } // 关闭流 out.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } return null; }
public InputStream getTaskTraceDiagram(String processInstanceId) { //获取历史流程实例 HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); //获取流程图 BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId()); processEngineConfiguration = processEngine.getProcessEngineConfiguration(); Context.setProcessEngineConfiguration((ProcessEngineConfigurationImpl) processEngineConfiguration); ProcessDefinitionEntity definitionEntity = (ProcessDefinitionEntity)repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId()); List<HistoricActivityInstance> highLightedActivitList = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list(); //高亮环节id集合 List<String> highLightedActivitis = new ArrayList<String>(); //高亮线路id集合 List<String> highLightedFlows = getHighLightedFlows(definitionEntity,highLightedActivitList); for(HistoricActivityInstance tempActivity : highLightedActivitList){ String activityId = tempActivity.getActivityId(); highLightedActivitis.add(activityId); } InputStream inputStream = ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", highLightedActivitis, highLightedFlows); return inputStream; }
/** * 获取需要高亮的线 * @param processDefinitionEntity * @param historicActivityInstances * @return */ private List<String> getHighLightedFlows( ProcessDefinitionEntity processDefinitionEntity, List<HistoricActivityInstance> historicActivityInstances) { List<String> highFlows = new ArrayList<String>();// 用以保存高亮的线flowId for (int i = 0; i < historicActivityInstances.size() - 1; i++) {// 对历史流程节点进行遍历 ActivityImpl activityImpl = processDefinitionEntity .findActivity(historicActivityInstances.get(i) .getActivityId());// 得到节点定义的详细信息 List<ActivityImpl> sameStartTimeNodes = new ArrayList<ActivityImpl>();// 用以保存后需开始时间相同的节点 ActivityImpl sameActivityImpl1 = processDefinitionEntity .findActivity(historicActivityInstances.get(i + 1) .getActivityId()); // 将后面第一个节点放在时间相同节点的集合里 sameStartTimeNodes.add(sameActivityImpl1); for (int j = i + 1; j < historicActivityInstances.size() - 1; j++) { HistoricActivityInstance activityImpl1 = historicActivityInstances .get(j);// 后续第一个节点 HistoricActivityInstance activityImpl2 = historicActivityInstances .get(j + 1);// 后续第二个节点 if (activityImpl1.getStartTime().equals( activityImpl2.getStartTime())) { // 如果第一个节点和第二个节点开始时间相同保存 ActivityImpl sameActivityImpl2 = processDefinitionEntity .findActivity(activityImpl2.getActivityId()); sameStartTimeNodes.add(sameActivityImpl2); } else { // 有不相同跳出循环 break; } } List<PvmTransition> pvmTransitions = activityImpl .getOutgoingTransitions();// 取出节点的所有出去的线 for (PvmTransition pvmTransition : pvmTransitions) { // 对所有的线进行遍历 ActivityImpl pvmActivityImpl = (ActivityImpl) pvmTransition .getDestination(); // 如果取出的线的目标节点存在时间相同的节点里,保存该线的id,进行高亮显示 if (sameStartTimeNodes.contains(pvmActivityImpl)) { highFlows.add(pvmTransition.getId()); } } } return highFlows; }
Activity流程图跟踪
最新推荐文章于 2024-07-14 16:42:13 发布