https://github.com/Tezzxamo/demo_activiti/tree/master/src/main/java/org/example/service
【注:本部分内容『画图相关问题』添加于: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);
}
}