Activiti技术中获取流程图片

在使用Activiti技术时,我们经常需要查看当前流程所属节点。针对流程图片获取,我使用一下方法:
1、在流程生成时,生成的流程id记为processId

/**
 * 获取流程图片方法
 * @param processId 
 * @return
 */
public InputStream getDiagramImageForAcivitiFlowsActiviti(String processId) {

    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processId).singleResult();

    if(historicProcessInstance == null) {
        throw new RuntimeException("获取流程图异常");
    }else {

        BpmnModel bpmnModel = repositoryService.getBpmnModel(historicProcessInstance.getProcessDefinitionId());
        // 获取流程走过的节点
        List<HistoricActivityInstance> activitiyInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processId).orderByHistoricActivityInstanceId().asc().list();

        InputStream is = processEngine.getProcessEngineConfiguration().getProcessDiagramGenerator().generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processId),getHightedFlows(processId),
                processEngine.getProcessEngineConfiguration().getActivityFontName(), 
                processEngine.getProcessEngineConfiguration().getLabelFontName(), 
                processEngine.getProcessEngineConfiguration().getClassLoader(),1.0);            

        return is;  
    }   
}

2、Controller 获取图片路径(../image/processId = ?)

/**
 * 获取流程图片 
 * @param processId 
 * @return
 */
@RequestMapping("/image")
@ResponseBody
public void getImageTest(HttpServletResponse response,ActionValueAssistant actionValueAssistant) {
    try {
        String processId = actionValueAssistant.getString("processId");
        response.setContentType("image/jpeg");

        if(StringUtils.isNotBlank(processId)) {
//          response.setCharacterEncoding("GBK");
            InputStream inputstream = wTWorkFlowGetDiagram.getDiagramImageForAcivitiFlowsActiviti(processId);
            byte[] b = new byte[1024];
            int len = -1;
            while ((len = inputstream.read(b, 0, 1024)) != -1) {
                response.getOutputStream().write(b, 0, len);
            }
        }else {
            throw new RuntimeException("输出参数有误");
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值