工作流activiti 6 学习笔记十八 流进度追踪--图

举报
lu_zhishen 发表于 2021/11/16 11:15:19 2021/11/16
【摘要】 本文代码记录的是activiti 6 和 activiti7 生成流程图,activiti6// 部署流程 Deployment deploye = rs.createDeployment().addClasspathResource("proptest.bpmn").deploy(); ProcessDefinition pdf = rs.createProcessDefinit...

本文代码记录的是activiti 6 和 activiti7 生成流程图,

activiti6

// 部署流程
		Deployment deploye = rs.createDeployment().addClasspathResource("proptest.bpmn").deploy();
		
		ProcessDefinition  pdf = rs.createProcessDefinitionQuery().deploymentId(deploye.getId()).singleResult();
		
		ProcessInstance  pi = runS.startProcessInstanceById(pdf.getId());
		System.out.println(pi.getId());
		String processInstanceId = pi.getId();
		Task currenttask = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
		ts.complete(currenttask.getId());
		currenttask = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
		ts.complete(currenttask.getId());
		List<Task> currenttasks = ts.createTaskQuery().processInstanceId(pi.getId()).list();
		
        try {
        	OutputStream outputStream =  new FileOutputStream(new File("111.png"));
            // 获取历史流程实例
            HistoricProcessInstance historicProcessInstance = hs.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
            // 获取流程中已经执行的节点,按照执行先后顺序排序
            List<HistoricActivityInstance> historicActivityInstances = hs.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId)
                    .orderByHistoricActivityInstanceId().asc().list();
            // 高亮已经执行流程节点ID集合
            List<String> highLightedActivitiIds = new ArrayList<>();
            for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
                highLightedActivitiIds.add(historicActivityInstance.getActivityId());
            }

            ProcessDiagramGenerator processDiagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();

            BpmnModel bpmnModel = rs.getBpmnModel(historicProcessInstance.getProcessDefinitionId());
            // 高亮流程已发生流转的线id集合
            List<String> highLightedFlowIds = getHighLightedFlows(bpmnModel, historicActivityInstances);

            // 使用默认配置获得流程图表生成器,并生成追踪图片字符流
            InputStream imageStream = processDiagramGenerator.generateDiagram(bpmnModel, "png", highLightedActivitiIds, highLightedFlowIds, "宋体", "微软雅黑", "黑体", null, 2.0);

            // 输出图片内容
            byte[] b = new byte[1024];
            int len;
            while ((len = imageStream.read(b, 0, 1024)) != -1) {
                outputStream.write(b, 0, len);
            }
        } catch (Exception e) {
            System.out.println("processInstanceId" + processInstanceId + "生成流程图失败,原因:" + e.getMessage());
            e.printStackTrace();
        }

activiti 7 实现与6差别较大,不能直接写入流,他的类型是image/svg+xml,

public InputStream genDiagram(String taskId) {
		try {
			
			HistoricTaskInstance task = hs
	                .createHistoricTaskInstanceQuery()
	                .taskId(taskId)
	                .singleResult();
	        // 流程定义
	        BpmnModel bpmnModel = rs.getBpmnModel(task.getProcessDefinitionId());
	        ProcessDiagramGenerator ge = new DefaultProcessDiagramGenerator();
            
	        InputStream resource = 
	        		ge.generateDiagram(bpmnModel,
	                runS.getActiveActivityIds(task.getExecutionId()),
	                new ArrayList<String>(), "宋体", "宋体", null, true);
	        
	        return resource;
        } catch (Exception e) {
            e.printStackTrace();
        }
		return null;
	}

流程图返回

@GetMapping("/getProcessPlan/{taskId}")
    public void getProcessPlan(@PathVariable String taskId,HttpServletResponse httpServletResponse) throws Exception
    {
    	System.out.println(taskId+"-----taskId");
    	
    	// 使用默认配置获得流程图表生成器,并生成追踪图片字符流
        InputStream imageStream = workflowConfigService.genDiagram(taskId);
    	 // 输出图片内容
        byte[] bytes = IOUtils.toByteArray(imageStream);
        httpServletResponse.setContentType("image/svg+xml");
        OutputStream outputStream = httpServletResponse.getOutputStream();
        outputStream.write(bytes);
        outputStream.flush();
        outputStream.close();
         
    }
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。