Activiti6.0实战-常用功能实战二(6)

Activiti6.0实战-常用功能实战二(6)

Activiti6.0实战-目录 一整套哦

目录

背景

记录项目需求中常用的功能以及其实现方式,这是第二篇后面还有会继续记录。
本文都是基于Activiti6.0.0
原则:业务数据一定要与审批流程数据隔离开来,例如备注,文件等。

【流程跟踪】获取流程定义图

获取代码如下:

ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
        .processDefinitionKey("leave")
        .singleResult();
 String diagramResourceName = processDefinition.getDiagramResourceName();
 InputStream imageStream = repositoryService.getResourceAsStream(
                            processDefinition.getDeploymentId(), diagramResourceName);

1.自动生成流程定义图

           如果部署的时候只有xml定义,没有定义图片的话, Activiti流程引擎竟会自动生成一个图像,生成的可能乱码。

Activiti6.0实战-常用功能实战二(6)

生成原理图如下,来自官网
Activiti6.0实战-常用功能实战二(6)

乱码问题解决:

@Configuration
public class ActivitiConfig implements ProcessEngineConfigurationConfigurer {

    /**
     * 解決工作流生成图片乱码问题
     *
     * @param processEngineConfiguration processEngineConfiguration
     */
    @Override
    public void configure(SpringProcessEngineConfiguration processEngineConfiguration) {
        processEngineConfiguration.setActivityFontName("宋体");
        processEngineConfiguration.setAnnotationFontName("宋体");
        processEngineConfiguration.setLabelFontName("宋体");
    }
}

Activiti6.0实战-常用功能实战二(6)

参考:
https://blog.csdn.net/qq_27291799/article/details/88658607
关闭自动生成:
如果,因为某种原因,在部署的时候,并不需要或者不必要生成流程定义图片,那么就需要在流程引擎配置的属性中使用isCreateDiagramOnDeploy:

<property name="createDiagramOnDeploy" value="false" />

现在就不会生成流程定义图片。

2.部署的时候提供自定义的图片

Activiti6.0实战-常用功能实战二(6)

部署方式:

repositoryService.createDeployment()
.key("leave")
.name("请假流程")
.addClasspathResource("processes/leave.bpmn20.xml")
.addClasspathResource("processes/leave.png")
  .deploy();
 接下来,可以通过API来获取流程定义图片资源:
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                                                         .processDefinitionKey("leave")
                                                         .singleResult();

【流程跟踪】获取高亮活动流程图

1.高亮正在进行中的节点

注意设置字体,否则会乱码

ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
        .processDefinitionKey("leave")
        .singleResult();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());// 模型
List<String> highLightedActivities  = runtimeService.getActiveActivityIds("2501");// 高亮节点
List<String> highLightedFlows = new ArrayList<>(); // 高亮连接线
ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
InputStream png = processDiagramGenerator.generateDiagram
                                    (bpmnModel, "png",highLightedActivities,
                                             highLightedFlows, "宋体", "微软雅黑", "黑体", null, 2.0);

官网的例子默认只高亮了正在进行中的节点
Activiti6.0实战-常用功能实战二(6)

2.高亮正在进行中的节点+处理过的连接线

我们来加上连接线的高亮以及所有处理过的节点

List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
    .processInstanceId(processInstanceId)
        .orderByHistoricActivityInstanceId().asc().list();
List<String> highLightedFlows = getHighLightedFlows(bpmnModel, historicActivityInstances);// 获取处理过的连接线

Activiti6.0实战-常用功能实战二(6)

参考:http://791202.com/2020/03/30/java/721/

/**
 * 获取已经流转的线
 *
 * @param bpmnModel
 * @param historicActivityInstances
 * @return
 */
private static List<String> getHighLightedFlows(BpmnModel bpmnModel, List<HistoricActivityInstance> historicActivityInstances) {
    // 高亮流程已发生流转的线id集合
    List<String> highLightedFlowIds = new ArrayList<>();
    // 全部活动节点
    List<FlowNode> historicActivityNodes = new ArrayList<>();
    // 已完成的历史活动节点
    List<HistoricActivityInstance> finishedActivityInstances = new ArrayList<>();

    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        FlowNode flowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(historicActivityInstance.getActivityId(), true);
        historicActivityNodes.add(flowNode);
        if (historicActivityInstance.getEndTime() != null) {
            finishedActivityInstances.add(historicActivityInstance);
        }
    }

    FlowNode currentFlowNode = null;
    FlowNode targetFlowNode = null;
    // 遍历已完成的活动实例,从每个实例的outgoingFlows中找到已执行的
    for (HistoricActivityInstance currentActivityInstance : finishedActivityInstances) {
        // 获得当前活动对应的节点信息及outgoingFlows信息
        currentFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(currentActivityInstance.getActivityId(), true);
        List<SequenceFlow> sequenceFlows = currentFlowNode.getOutgoingFlows();

        /**
         * 遍历outgoingFlows并找到已已流转的 满足如下条件认为已已流转: 1.当前节点是并行网关或兼容网关,则通过outgoingFlows能够在历史活动中找到的全部节点均为已流转 2.当前节点是以上两种类型之外的,通过outgoingFlows查找到的时间最早的流转节点视为有效流转
         */
        if ("parallelGateway".equals(currentActivityInstance.getActivityType()) || "inclusiveGateway".equals(currentActivityInstance.getActivityType())) {
            // 遍历历史活动节点,找到匹配流程目标节点的
            for (SequenceFlow sequenceFlow : sequenceFlows) {
                targetFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(sequenceFlow.getTargetRef(), true);
                if (historicActivityNodes.contains(targetFlowNode)) {
                    highLightedFlowIds.add(targetFlowNode.getId());
                }
            }
        } else {
            List<Map<String, Object>> tempMapList = new ArrayList<>();
            for (SequenceFlow sequenceFlow : sequenceFlows) {
                for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
                    if (historicActivityInstance.getActivityId().equals(sequenceFlow.getTargetRef())) {
                        Map<String, Object> map = new HashMap<>();
                        map.put("highLightedFlowId", sequenceFlow.getId());
                        map.put("highLightedFlowStartTime", historicActivityInstance.getStartTime().getTime());
                        tempMapList.add(map);
                    }
                }
            }

            if (!CollectionUtils.isEmpty(tempMapList)) {
                // 遍历匹配的集合,取得开始时间最早的一个
                long earliestStamp = 0L;
                String highLightedFlowId = null;
                for (Map<String, Object> map : tempMapList) {
                    long highLightedFlowStartTime = Long.valueOf(map.get("highLightedFlowStartTime").toString());
                    if (earliestStamp == 0 || earliestStamp >= highLightedFlowStartTime) {
                        highLightedFlowId = map.get("highLightedFlowId").toString();
                        earliestStamp = highLightedFlowStartTime;
                    }
                }

                highLightedFlowIds.add(highLightedFlowId);
            }

        }

    }
    return highLightedFlowIds;
}

3.高亮正在进行中的节点+处理过的连接线+处理过的节点

Activiti6.0实战-常用功能实战二(6)

  // 获取流程中已经执行的节点,按照执行先后顺序排序
		List<HistoricActivityInstance> historicActivityInstances = historyService.
                              createHistoricActivityInstanceQuery()
                                  .processInstanceId(processInstanceId) 
                                  .orderByHistoricActivityInstanceId().asc().list();
		// 高亮已经执行流程节点ID集合
		List<String> highLightedActivitiIds = new ArrayList<>();
		for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
			highLightedActivitiIds.add(historicActivityInstance.getActivityId());
		}                 

4.自定义商务范配色

绘图原理是调用下面的方法,扩展一波即可。

ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
processDiagramGenerator.generateDiagram()

核心方法是,DefaultProcessDiagramGenerator.drawActivity 重写它吧

protected void drawActivity(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, 
    FlowNode flowNode, List<String> highLightedActivities, List<String> highLightedFlows, double scaleFactor) {

Activiti6.0实战-常用功能实战二(6)

全部代码如下:
涉及到2个类:

LakerProcessDiagramCanvas

继承了DefaultProcessDiagramCanvas

  • 重写定义了这2个值
HIGHLIGHT_COLOR = Color.cyan;// 默认颜色,之前是红色
THICK_TASK_BORDER_STROKE = new BasicStroke(6.0f);// 边框宽度 之前是3.0
  • 新定义了可以传入颜色的方法
public void drawHighLightColor(int x, int y, int width, int height, Color color) {
    Paint originalPaint = g.getPaint();
    Stroke originalStroke = g.getStroke();

    g.setPaint(color);
    g.setStroke(THICK_TASK_BORDER_STROKE);

    RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, 20, 20);
    g.draw(rect);

    g.setPaint(originalPaint);
    g.setStroke(originalStroke);
}

LakerProcessDiagramGenerator

继承了DefaultProcessDiagramGenerator

  • 重写了initProcessDiagramCanvas让其返回我们扩展的LakerProcessDiagramCanvas
return new LakerProcessDiagramCanvas((int) maxX + 10, (int) maxY + 10, (int) minX, (int) minY,
        imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);
  • 重写了drawActivity,最后一个节点自定义颜色显示
// 画高亮的节点 TODO
if (highLightedActivities.contains(flowNode.getId())) {
    if (highLightedActivities.get(highLightedActivities.size() - 1).equalsIgnoreCase(flowNode.getId())) {

        LakerProcessDiagramCanvas lakerProcessDiagramCanvas = ((LakerProcessDiagramCanvas) processDiagramCanvas);
        lakerProcessDiagramCanvas.drawHighLightColor((int) graphicInfo.getX(), (int) graphicInfo.getY(), (int) graphicInfo.getWidth(), (int) graphicInfo.getHeight(), Color.YELLOW);
    } else {
        processDiagramCanvas.drawHighLight((int) graphicInfo.getX(), (int) graphicInfo.getY(), (int) graphicInfo.getWidth(), (int) graphicInfo.getHeight());
    }
}

全部源码

  • 继承DefaultProcessDiagramCanvas
package com.laker.workflow.controller;

import org.activiti.image.impl.DefaultProcessDiagramCanvas;

import java.awt.*;
import java.awt.geom.RoundRectangle2D;

public class LakerProcessDiagramCanvas extends DefaultProcessDiagramCanvas {
    public LakerProcessDiagramCanvas(int width, int height, int minX, int minY, String imageType, String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader) {
        super(width, height, minX, minY, imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);
        HIGHLIGHT_COLOR = Color.cyan;
        THICK_TASK_BORDER_STROKE = new BasicStroke(6.0f);
    }

    public LakerProcessDiagramCanvas(int width, int height, int minX, int minY, String imageType) {
        super(width, height, minX, minY, imageType);
        HIGHLIGHT_COLOR = Color.cyan;
        THICK_TASK_BORDER_STROKE = new BasicStroke(6.0f);
    }

    public void drawHighLightColor(int x, int y, int width, int height, Color color) {
        Paint originalPaint = g.getPaint();
        Stroke originalStroke = g.getStroke();

        g.setPaint(color);
        g.setStroke(THICK_TASK_BORDER_STROKE);

        RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, 20, 20);
        g.draw(rect);

        g.setPaint(originalPaint);
        g.setStroke(originalStroke);
    }

}
  • 继承DefaultProcessDiagramGenerator
package com.laker.workflow.controller;

import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.*;
import org.activiti.image.impl.DefaultProcessDiagramCanvas;
import org.activiti.image.impl.DefaultProcessDiagramGenerator;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.List;

public class LakerProcessDiagramGenerator extends DefaultProcessDiagramGenerator {
    private BufferedImage processDiagram;

    @Override
    protected DefaultProcessDiagramCanvas generateProcessDiagram(BpmnModel bpmnModel, String imageType,
                                                                 List<String> highLightedActivities, List<String> highLightedFlows,
                                                                 String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader, double scaleFactor) {

        {

            prepareBpmnModel(bpmnModel);

            DefaultProcessDiagramCanvas processDiagramCanvas = initProcessDiagramCanvas(bpmnModel, imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);

            // Draw pool shape, if process is participant in collaboration
            for (Pool pool : bpmnModel.getPools()) {
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
                processDiagramCanvas.drawPoolOrLane(pool.getName(), graphicInfo);
            }

            // Draw lanes
            for (Process process : bpmnModel.getProcesses()) {
                for (Lane lane : process.getLanes()) {
                    GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(lane.getId());
                    processDiagramCanvas.drawPoolOrLane(lane.getName(), graphicInfo);
                }
            }

            // Draw activities and their sequence-flows
            for (FlowNode flowNode : bpmnModel.getProcesses().get(0).findFlowElementsOfType(FlowNode.class)) {
                drawActivity(processDiagramCanvas, bpmnModel, flowNode, highLightedActivities, highLightedFlows, scaleFactor);
            }

            for (Process process : bpmnModel.getProcesses()) {
                for (FlowNode flowNode : process.findFlowElementsOfType(FlowNode.class)) {
                    drawActivity(processDiagramCanvas, bpmnModel, flowNode, highLightedActivities, highLightedFlows, scaleFactor);
                }
            }

            // Draw artifacts
            for (Process process : bpmnModel.getProcesses()) {

                for (Artifact artifact : process.getArtifacts()) {
                    drawArtifact(processDiagramCanvas, bpmnModel, artifact);
                }

                List<SubProcess> subProcesses = process.findFlowElementsOfType(SubProcess.class, true);
                if (subProcesses != null) {
                    for (SubProcess subProcess : subProcesses) {
                        for (Artifact subProcessArtifact : subProcess.getArtifacts()) {
                            drawArtifact(processDiagramCanvas, bpmnModel, subProcessArtifact);
                        }
                    }
                }
            }

            return processDiagramCanvas;
        }
    }

    @Override
    protected void drawActivity(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel,
                                FlowNode flowNode, List<String> highLightedActivities, List<String> highLightedFlows, double scaleFactor) {

        {

            ActivityDrawInstruction drawInstruction = activityDrawInstructions.get(flowNode.getClass());
            if (drawInstruction != null) {

                drawInstruction.draw(processDiagramCanvas, bpmnModel, flowNode);

                // Gather info on the multi instance marker
                boolean multiInstanceSequential = false, multiInstanceParallel = false, collapsed = false;
                if (flowNode instanceof Activity) {
                    Activity activity = (Activity) flowNode;
                    MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = activity.getLoopCharacteristics();
                    if (multiInstanceLoopCharacteristics != null) {
                        multiInstanceSequential = multiInstanceLoopCharacteristics.isSequential();
                        multiInstanceParallel = !multiInstanceSequential;
                    }
                }

                // Gather info on the collapsed marker
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                if (flowNode instanceof SubProcess) {
                    collapsed = graphicInfo.getExpanded() != null && !graphicInfo.getExpanded();
                } else if (flowNode instanceof CallActivity) {
                    collapsed = true;
                }

                if (scaleFactor == 1.0) {
                    // Actually draw the markers
                    processDiagramCanvas.drawActivityMarkers((int) graphicInfo.getX(), (int) graphicInfo.getY(), (int) graphicInfo.getWidth(), (int) graphicInfo.getHeight(),
                            multiInstanceSequential, multiInstanceParallel, collapsed);
                }

                // 画高亮的节点 TODO
                if (highLightedActivities.contains(flowNode.getId())) {
                    if (highLightedActivities.get(highLightedActivities.size() - 1).equalsIgnoreCase(flowNode.getId())) {

                        LakerProcessDiagramCanvas lakerProcessDiagramCanvas = ((LakerProcessDiagramCanvas) processDiagramCanvas);
                        lakerProcessDiagramCanvas.drawHighLightColor((int) graphicInfo.getX(), (int) graphicInfo.getY(), (int) graphicInfo.getWidth(), (int) graphicInfo.getHeight(), Color.YELLOW);
                    } else {
                        processDiagramCanvas.drawHighLight((int) graphicInfo.getX(), (int) graphicInfo.getY(), (int) graphicInfo.getWidth(), (int) graphicInfo.getHeight());
                    }


                }

            }

            // Outgoing transitions of activity
            for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
                boolean highLighted = (highLightedFlows.contains(sequenceFlow.getId()));
                String defaultFlow = null;
                if (flowNode instanceof Activity) {
                    defaultFlow = ((Activity) flowNode).getDefaultFlow();
                } else if (flowNode instanceof Gateway) {
                    defaultFlow = ((Gateway) flowNode).getDefaultFlow();
                }

                boolean isDefault = false;
                if (defaultFlow != null && defaultFlow.equalsIgnoreCase(sequenceFlow.getId())) {
                    isDefault = true;
                }
                boolean drawConditionalIndicator = sequenceFlow.getConditionExpression() != null && !(flowNode instanceof Gateway);

                String sourceRef = sequenceFlow.getSourceRef();
                String targetRef = sequenceFlow.getTargetRef();
                FlowElement sourceElement = bpmnModel.getFlowElement(sourceRef);
                FlowElement targetElement = bpmnModel.getFlowElement(targetRef);
                List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(sequenceFlow.getId());
                if (graphicInfoList != null && graphicInfoList.size() > 0) {
                    graphicInfoList = connectionPerfectionizer(processDiagramCanvas, bpmnModel, sourceElement, targetElement, graphicInfoList);
                    int xPoints[] = new int[graphicInfoList.size()];
                    int yPoints[] = new int[graphicInfoList.size()];

                    for (int i = 1; i < graphicInfoList.size(); i++) {
                        GraphicInfo graphicInfo = graphicInfoList.get(i);
                        GraphicInfo previousGraphicInfo = graphicInfoList.get(i - 1);

                        if (i == 1) {
                            xPoints[0] = (int) previousGraphicInfo.getX();
                            yPoints[0] = (int) previousGraphicInfo.getY();
                        }
                        xPoints[i] = (int) graphicInfo.getX();
                        yPoints[i] = (int) graphicInfo.getY();

                    }

                    processDiagramCanvas.drawSequenceflow(xPoints, yPoints, drawConditionalIndicator, isDefault, highLighted, scaleFactor);

                    // Draw sequenceflow label
                    GraphicInfo labelGraphicInfo = bpmnModel.getLabelGraphicInfo(sequenceFlow.getId());
                    if (labelGraphicInfo != null) {
                        processDiagramCanvas.drawLabel(sequenceFlow.getName(), labelGraphicInfo, false);
                    }
                }
            }

            // Nested elements
            if (flowNode instanceof FlowElementsContainer) {
                for (FlowElement nestedFlowElement : ((FlowElementsContainer) flowNode).getFlowElements()) {
                    if (nestedFlowElement instanceof FlowNode) {
                        drawActivity(processDiagramCanvas, bpmnModel, (FlowNode) nestedFlowElement,
                                highLightedActivities, highLightedFlows, scaleFactor);
                    }
                }
            }
        }
    }

    protected static DefaultProcessDiagramCanvas initProcessDiagramCanvas(BpmnModel bpmnModel, String imageType,
                                                                          String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader) {

        // We need to calculate maximum values to know how big the image will be in its entirety
        double minX = Double.MAX_VALUE;
        double maxX = 0;
        double minY = Double.MAX_VALUE;
        double maxY = 0;

        for (Pool pool : bpmnModel.getPools()) {
            GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
            minX = graphicInfo.getX();
            maxX = graphicInfo.getX() + graphicInfo.getWidth();
            minY = graphicInfo.getY();
            maxY = graphicInfo.getY() + graphicInfo.getHeight();
        }

        List<FlowNode> flowNodes = gatherAllFlowNodes(bpmnModel);
        for (FlowNode flowNode : flowNodes) {

            GraphicInfo flowNodeGraphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());

            // width
            if (flowNodeGraphicInfo.getX() + flowNodeGraphicInfo.getWidth() > maxX) {
                maxX = flowNodeGraphicInfo.getX() + flowNodeGraphicInfo.getWidth();
            }
            if (flowNodeGraphicInfo.getX() < minX) {
                minX = flowNodeGraphicInfo.getX();
            }
            // height
            if (flowNodeGraphicInfo.getY() + flowNodeGraphicInfo.getHeight() > maxY) {
                maxY = flowNodeGraphicInfo.getY() + flowNodeGraphicInfo.getHeight();
            }
            if (flowNodeGraphicInfo.getY() < minY) {
                minY = flowNodeGraphicInfo.getY();
            }

            for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
                List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(sequenceFlow.getId());
                if (graphicInfoList != null) {
                    for (GraphicInfo graphicInfo : graphicInfoList) {
                        // width
                        if (graphicInfo.getX() > maxX) {
                            maxX = graphicInfo.getX();
                        }
                        if (graphicInfo.getX() < minX) {
                            minX = graphicInfo.getX();
                        }
                        // height
                        if (graphicInfo.getY() > maxY) {
                            maxY = graphicInfo.getY();
                        }
                        if (graphicInfo.getY() < minY) {
                            minY = graphicInfo.getY();
                        }
                    }
                }
            }
        }

        List<Artifact> artifacts = gatherAllArtifacts(bpmnModel);
        for (Artifact artifact : artifacts) {

            GraphicInfo artifactGraphicInfo = bpmnModel.getGraphicInfo(artifact.getId());

            if (artifactGraphicInfo != null) {
                // width
                if (artifactGraphicInfo.getX() + artifactGraphicInfo.getWidth() > maxX) {
                    maxX = artifactGraphicInfo.getX() + artifactGraphicInfo.getWidth();
                }
                if (artifactGraphicInfo.getX() < minX) {
                    minX = artifactGraphicInfo.getX();
                }
                // height
                if (artifactGraphicInfo.getY() + artifactGraphicInfo.getHeight() > maxY) {
                    maxY = artifactGraphicInfo.getY() + artifactGraphicInfo.getHeight();
                }
                if (artifactGraphicInfo.getY() < minY) {
                    minY = artifactGraphicInfo.getY();
                }
            }

            List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(artifact.getId());
            if (graphicInfoList != null) {
                for (GraphicInfo graphicInfo : graphicInfoList) {
                    // width
                    if (graphicInfo.getX() > maxX) {
                        maxX = graphicInfo.getX();
                    }
                    if (graphicInfo.getX() < minX) {
                        minX = graphicInfo.getX();
                    }
                    // height
                    if (graphicInfo.getY() > maxY) {
                        maxY = graphicInfo.getY();
                    }
                    if (graphicInfo.getY() < minY) {
                        minY = graphicInfo.getY();
                    }
                }
            }
        }

        int nrOfLanes = 0;
        for (Process process : bpmnModel.getProcesses()) {
            for (Lane l : process.getLanes()) {

                nrOfLanes++;

                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(l.getId());
                // // width
                if (graphicInfo.getX() + graphicInfo.getWidth() > maxX) {
                    maxX = graphicInfo.getX() + graphicInfo.getWidth();
                }
                if (graphicInfo.getX() < minX) {
                    minX = graphicInfo.getX();
                }
                // height
                if (graphicInfo.getY() + graphicInfo.getHeight() > maxY) {
                    maxY = graphicInfo.getY() + graphicInfo.getHeight();
                }
                if (graphicInfo.getY() < minY) {
                    minY = graphicInfo.getY();
                }
            }
        }

        // Special case, see https://activiti.atlassian.net/browse/ACT-1431
        if (flowNodes.isEmpty() && bpmnModel.getPools().isEmpty() && nrOfLanes == 0) {
            // Nothing to show
            minX = 0;
            minY = 0;
        }

        return new LakerProcessDiagramCanvas((int) maxX + 10, (int) maxY + 10, (int) minX, (int) minY,
                imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);
    }

}

参考:https://blog.csdn.net/u010740917/article/details/101671154

【流程跟踪】流程的任务流转路径

List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery()
        .processInstanceId("2515")
        .orderByHistoricTaskInstanceEndTime().asc().list();
SELECT DISTINCT RES.*
FROM ACT_HI_TASKINST RES
WHERE RES.PROC_INST_ID_ = '2515'
ORDER BY  RES.END_TIME_ ASC LIMIT '2147483647' OFFSET '0' 

【流程跟踪】设置流程标题

例如流程标题为“张三的请假单”

runtimeService.setProcessInstanceName(processInstance.getId(),"张三的请假条");
查询的时候
runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();

act_ru_executionact_hi_procinstname_】字段

Activiti6.0实战-常用功能实战二(6)


QQ群【837324215
关注我的公众号【Java大厂面试官】,回复:架构资源等关键词(更多关键词,关注后注意提示信息)获取更多免费资料。

公众号也会持续输出高质量文章,和大家共同进步。

Activiti6.0实战-常用功能实战二(6)

上一篇:Android多点触控技术


下一篇:贪吃蛇小游戏