Flowable6.x导出/查看/跟踪流程图
Flowable诞生于Activiti,是一个使用Java编写的轻量级业务流程引擎。Flowable流程引擎可用于部署BPMN 2.0流程定义,可以十分灵活地加入你的应用/服务/构架。
本文介绍4种绘制流程图的方式,前3种是在后台绘制静态图(image/png格式),以Stream形式返回前端显示。最后1种是后端生成JSON形式的结构化数据,由前端使用Snap.svg绘制的交互式SVG动画流程图。
导入Maven依赖
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-basic</artifactId>
<version>6.4.1</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-json-converter</artifactId>
<version>6.4.1</version>
</dependency>
导出流程定义图
适用于流程管理或启动流程时查看已经部署的流程图,流程图不包括任务办理实际流转信息。
使用流程定义(ProcessDefinition.id),通过调用flowable 的RepositoryService来导出其流程定义的图片资源。
源码:
@RestController
@Slf4j
public class ProcessController {
@Autowired
private MyProcessService processService;
/**
* 通过processDefinition.id和resType导出流程XML或图片资源
* @param id processDefinition.id
* @param resType 取值 “image/png”或“text/xml”
* @param response
* @throws Exception
*/
@GetMapping(value = "/res/exp")
@ApiOperation("通过processDefinition.id和resType导出流程XML或图片资源")
public void resourceRead(@RequestParam("id") String id,@RequestParam("resType") String resType, HttpServletResponse response) throws Exception {
/** resType取值 “image/png”或“text/xml” **/
InputStream resourceAsStream = processService.resourceRead(id,resType);
byte[] b = new byte[1024];
int len = -1;
while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
}
}
@Service
public class MyProcessServiceImpl implements MyProcessService {
@Autowired
private RepositoryService repositoryService;
@Override
public InputStream resourceRead(String id,