在正常的flowable就是显示当前节点,路径需要我们自己获取,特别是来回的驳回会导致节点混乱,这里主要就是如何正确的显示流程图
效果:
已经结束的流程
正在执行的流程
代码:1、生成图片
-
// 源码 1b23.com
-
public byte[] createimage2(string processinstanceid) {
-
//1.获取当前的流程实例
-
processinstance processinstance = runtimeservice.createprocessinstancequery().processinstanceid(processinstanceid).singleresult();
-
string processdefinitionid = null;
-
list<string> activeactivityids = null;
-
//2.获取所有的历史轨迹对象
-
list<historicactivityinstance> list = historyservice.createhistoricactivityinstancequery()
-
.processinstanceid(processinstanceid).list();
-
map<string, historicactivityinstance> hisactivitymap = new hashmap<>();
-
list.foreach(historicactivityinstance -> {
-
if (!hisactivitymap.containskey(historicactivityinstance.getactivityid())) {
-
hisactivitymap.put(historicactivityinstance.getactivityid(), historicactivityinstance);
-
}
-
});
-
//3. 获取流程定义id和高亮的节点id
-
if (processinstance != null) {
-
//3.1. 正在运行的流程实例
-
processdefinitionid = processinstance.getprocessdefinitionid();
-
activeactivityids = runtimeservice.getactiveactivityids(processinstanceid);
-
} else {
-
//3.2. 已经结束的流程实例
-
historicprocessinstance historicprocessinstance = historyservice.createhistoricprocessinstancequery().processinstanceid(processinstanceid).singleresult();
-
processdefinitionid = historicprocessinstance.getprocessdefinitionid();
-
activeactivityids = new arraylist<>();
-
list<endevent> endevents = bpmnmodelservice.findendflowelement(processdefinitionid);
-
list<string> finalactiveactivityids = activeactivityids;
-
endevents.foreach(endevent -> {
-
if (hisactivitymap.containskey(endevent.getid())) {
-
finalactiveactivityids.add(endevent.getid());
-
}
-
});
-
}
-
//4. 获取流程定义的所有节点信息
-
list<flownode> flownodes = bpmnmodelservice.findflownodes(processdefinitionid);
-
map<string, flownode> activitymap = flownodes.stream().collect(collectors.tomap(flownode::getid, flownode -> flownode));
-
list<string> highlightedflows = new arraylist<>();
-
//5. 递归得到高亮线
-
activeactivityids.foreach(activeactivityid -> this.gethighlightedflows(activitymap, hisactivitymap, activeactivityid, highlightedflows, activeactivityid));
-
//6. 获取bpmnmodel对象
-
bpmnmodel bpmnmodel = bpmnmodelservice.getbpmnmodelbyprocessdefid(processdefinitionid);
-
//7. 生成图片流
-
inputstream inputstream = flowprocessdiagramgenerator.generatediagram(bpmnmodel, activeactivityids, highlightedflows);
-
//8. 转化成byte便于网络传输
-
byte[] datas = ioutil.readinputstream(inputstream, "image inputstream name");
-
return datas;
-
}
递归获取高
-
//from fhadmin.cn
-
private void gethighlightedflows(map<string, flownode> flownodemap,
-
map<string, historicactivityinstance> hisactivitymap,
-
string activeactivityid,
-
list<string> highlightedflows,
-
string oldactivityid) {
-
flownode flownode = flownodemap.get(activeactivityid);
-
list<sequenceflow> incomingflows = flownode.getincomingflows();
-
for (sequenceflow sequenceflow : incomingflows) {
-
string sourcerefid = sequenceflow.getsourceref();
-
if (hisactivitymap.containskey(sourcerefid) && !oldactivityid.equals(sourcerefid)) {
-
highlightedflows.add(sequenceflow.getid());
-
this.gethighlightedflows(flownodemap, hisactivitymap, sourcerefid, highlightedflows, oldactivityid);
-
} else {
-
-
if (hisactivitymap.containskey(sourcerefid)){
-
highlightedflows.add(sequenceflow.getid());
-
}
-
break;
-
} } }
阅读(5453) | 评论(0) | 转发(0) |