activiti7 『生成流程图』+『流程追踪』+『高亮显示』+『当前节点』红色+『其余途径节点』绿色+『剩余节点』正常显示

开局出源码,简单且直接:

https://github.com/Tezzxamo/demo_activiti/tree/master/src/main/java/org/example/service

注意:

①是activiti7,不是activiti6或者5。

②7.1.0-M6是jdk8的最后一个版本,之后的版本就都是11了。详情查看SpringBoot与activiti7版本间的粗略对应关系icon-default.png?t=M666https://blog.csdn.net/qq_40109075/article/details/123642788


部分问题统一回复:

一、画图相关问题:

画图相关部分的代码请查看:CustomProcessDiagramCanvas.class,这里有很多地方可以自定义修改,相关问题请查阅本类代码中的参数。(基本上都是官方原本的类中的参数,各种参数都可以自己修改,试试如何修改更符合自身流程图的展示,此处的参数并不是最好的,只是一个展示用的demo,根据个人需求,可以将部分参数更改为可配置项进行管理,以便供不同的流程图使用)

【注:本部分内容『画图相关问题』添加于:2022-08-16,用于统一回答『部分』关于流程图生成的问题】

public class CustomProcessDiagramCanvas {
    /**
     * 矩形、菱形、椭圆形
     */
    public enum SHAPE_TYPE {
        Rectangle, Rhombus, Ellipse;
        SHAPE_TYPE() {
        }
    }

    // 参数太多了,我自己都忘了好多参数是干啥的了,根据命名和实际使用大家伙自己查阅调试吧

    protected static final int ARROW_WIDTH = 5;
    protected static final int CONDITIONAL_INDICATOR_WIDTH = 16;
    protected static final int DEFAULT_INDICATOR_WIDTH = 10;
    protected static final int MARKER_WIDTH = 12;
    protected static final int FONT_SIZE = 12;
    protected static final int FONT_SPACING = 2;
    protected static final int TEXT_PADDING = 3;
    protected static final int ANNOTATION_TEXT_PADDING = 7;
    protected static final int LINE_HEIGHT = FONT_SIZE + FONT_SPACING;

    /**
     * Colors
     */
    protected static Color TASK_BOX_COLOR = new Color(249, 249, 249);
    protected static Color SUBPROCESS_BOX_COLOR = new Color(255, 255, 255);
    protected static Color EVENT_COLOR = Color.WHITE;
    protected static Color CONNECTION_COLOR = new Color(128, 128, 128);
    protected static Color CONDITIONAL_INDICATOR_COLOR = new Color(255, 255, 255);
    protected static Color RUNNING_HIGHLIGHT_COLOR = Color.RED;
    protected static Color LAST_HIGHLIGHT_COLOR = new Color(252, 75, 52);
    protected static Color HIGHLIGHT_COLOR = Color.GREEN;
    protected static Color LABEL_COLOR = new Color(67, 150, 246);
    //	protected static Color			LABEL_COLOR						= Color.blue;
    protected static Color TASK_BORDER_COLOR = new Color(149, 148, 148);
    protected static Color EVENT_BORDER_COLOR = new Color(76, 76, 76);
    protected static Color SUBPROCESS_BORDER_COLOR = Color.BLACK;

    // Fonts
    protected static Font LABEL_FONT = new Font("微软雅黑", Font.ITALIC, 14);
    protected static Font ANNOTATION_FONT = new Font("微软雅黑", Font.PLAIN, FONT_SIZE);
    protected static Font TASK_FONT = new Font("微软雅黑", Font.PLAIN, FONT_SIZE);

    // Strokes笔画
    //TODO 边框宽度修改
    //protected static Stroke THICK_TASK_BORDER_STROKE = new BasicStroke(3.0f);
    protected static Stroke THICK_TASK_BORDER_STROKE = new BasicStroke(2.0f);
    protected static Stroke GATEWAY_TYPE_STROKE = new BasicStroke(3.0f);
    protected static Stroke END_EVENT_STROKE = new BasicStroke(3.0f);
    protected static Stroke MULTI_INSTANCE_STROKE = new BasicStroke(1.3f);
    protected static Stroke EVENT_SUBPROCESS_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, new float[]{1.0f}, 0.0f);
    protected static Stroke NON_INTERRUPTING_EVENT_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, new float[]{4.0f, 3.0f}, 0.0f);
    protected static Stroke HIGHLIGHT_FLOW_STROKE = new BasicStroke(1.3f);
    protected static Stroke ANNOTATION_STROKE = new BasicStroke(2.0f);
    protected static Stroke ASSOCIATION_STROKE = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, new float[]{2.0f, 2.0f}, 0.0f);

    // icons
    protected static int ICON_PADDING = 5;
    protected static TaskIconType USERTASK_IMAGE;
    protected static TaskIconType SCRIPTTASK_IMAGE;
    protected static TaskIconType SERVICETASK_IMAGE;
    protected static TaskIconType RECEIVETASK_IMAGE;
    protected static TaskIconType SENDTASK_IMAGE;
    protected static TaskIconType MANUALTASK_IMAGE;
    protected static TaskIconType BUSINESS_RULE_TASK_IMAGE;

    protected static IconType TIMER_IMAGE;
    protected static IconType COMPENSATE_THROW_IMAGE;
    protected static IconType COMPENSATE_CATCH_IMAGE;
    protected static IconType ERROR_THROW_IMAGE;
    protected static IconType ERROR_CATCH_IMAGE;
    protected static IconType MESSAGE_CATCH_IMAGE;
    protected static IconType SIGNAL_CATCH_IMAGE;
    protected static IconType SIGNAL_THROW_IMAGE;

    protected int canvasWidth = -1;
    protected int canvasHeight = -1;
    protected int minX = -1;
    protected int minY = -1;
    protected ProcessDiagramSVGGraphics2D g;
    protected FontMetrics fontMetrics;
    protected boolean closed;
    protected String activityFontName = "微软雅黑";
    protected String labelFontName = "微软雅黑";
    protected String annotationFontName = "微软雅黑";

    // 忽略其他内容
}

下面这个是主要的实现类Impl,追踪代码可以查看到具体的类和相关实现内容(请忽略层级设计,manager层根据个人需要考虑是否添加即可,此处只是演示demo,不是一定需要有的分层设计。具体的分层设计根据实际情况来定):

package org.example.service.impl;

import org.example.manager.ProcessImageManager;
import org.example.service.ProcessImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.InputStream;

/**
 * 流程图service实现类
 *
 * @author Tethamo_zzx
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ProcessImageServiceImpl implements ProcessImageService {

    ProcessImageManager processImageManager;

    @Autowired
    public ProcessImageServiceImpl(ProcessImageManager processImageManager) {
        this.processImageManager = processImageManager;
    }

    /**
     * 根据流程实例Id获取流程图
     *
     * @param procInstId 流程实例id
     * @return inputStream
     * @throws Exception exception
     */
    @Override
    public InputStream getFlowImgByProcInstId(String procInstId) throws Exception {
        return processImageManager.getFlowImgByProcInstId(procInstId);
    }
}

再次声明:是activiti7,不是activiti6或者5,是否兼容5和6我没有试过,不过5和6网上应该有相关教程,此处就不赘述了。

自动生成的流程图效果图如下:

activiti7 『生成流程图』+『流程追踪』+『高亮显示』+『当前节点』红色+『其余途径节点』绿色+『剩余节点』正常显示_第1张图片

你可能感兴趣的:(activiti,activiti,java,工作流)