1、导入pom依赖,因为我项目中集成的是mybatisplus,所以要排除activiti自带的mybatis
<!--activiti基础包-->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>6.0.0</version>
<exclusions>
<exclusion>
<artifactId>mybatis</artifactId>
<groupId>org.mybatis</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-json-converter</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-codec</artifactId>
<version>1.7</version>
</dependency>
2、排除activiti自带的安全谁
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@EnableScheduling
@Slf4j
public class RenrenApplication {
public static void main(String[] args) {
//SpringApplication.
SpringApplication.run(RenrenApplication.class, args);
}
}
3、设置流程定义,bpmn,这个是xml文件,可以直接该后缀名为bpmn
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1588045161726" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
<error id="ERR_1"/>
<process id="leave" isClosed="false" isExecutable="true" name="My process" processType="None">
<userTask activiti:async="true" activiti:candidateGroups="部门经理" activiti:exclusive="true" id="deptleaderaudit" name="部门领导审批"/>
<exclusiveGateway gatewayDirection="Unspecified" id="exclusivegateway1" name="Exclusive Gateway"/>
<userTask activiti:candidateGroups="人事" activiti:exclusive="true" id="hraudit" name="人事审批"/>
<sequenceFlow id="flow3" name="同意" sourceRef="exclusivegateway1" targetRef="hraudit">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${deptleaderapprove=='true'}]]></conditionExpression>
</sequenceFlow>
<userTask activiti:assignee="${applyuserid}" activiti:exclusive="true" id="modifyapply" name="调整申请"/>
<sequenceFlow id="flow4" name="拒绝" sourceRef="exclusivegateway1" targetRef="modifyapply">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${deptleaderapprove=='false'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow6" sourceRef="deptleaderaudit" targetRef="exclusivegateway1"/>
<exclusiveGateway gatewayDirection="Unspecified" id="exclusivegateway2" name="Exclusive Gateway"/>
<sequenceFlow id="flow7" sourceRef="modifyapply" targetRef="exclusivegateway2"/>
<sequenceFlow id="flow8" name="重新申请" sourceRef="exclusivegateway2" targetRef="deptleaderaudit">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${reapply=='true'}]]></conditionExpression>
</sequenceFlow>
<endEvent id="endevent1" name="End"/>
<sequenceFlow id="flow9" name="结束流程" sourceRef="exclusivegateway2" targetRef="endevent1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${reapply=='false'}]]></conditionExpression>
</sequenceFlow>
<exclusiveGateway gatewayDirection="Unspecified" id="exclusivegateway3" name="Exclusive Gateway"/>
<sequenceFlow id="flow10" sourceRef="hraudit" targetRef="exclusivegateway3"/>
<sequenceFlow id="flow11" name="拒绝" sourceRef="exclusivegateway3" targetRef="modifyapply">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrapprove=='false'}]]></conditionExpression>
</sequenceFlow>
<userTask activiti:assignee="${applyuserid}" activiti:exclusive="true" id="reportback" name="销假"/>
<sequenceFlow id="flow12" name="同意" sourceRef="exclusivegateway3" targetRef="reportback">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrapprove=='true'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow13" sourceRef="reportback" targetRef="endevent1"/>
<startEvent activiti:initiator="${applyuserid}" id="startevent1" name="Start"/>
<sequenceFlow id="flow14" sourceRef="startevent1" targetRef="deptleaderaudit"/>
</process>
<bpmndi:BPMNDiagram documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
<bpmndi:BPMNPlane bpmnElement="leave">
<bpmndi:BPMNShape bpmnElement="deptleaderaudit" id="Shape-deptleaderaudit">
<omgdc:Bounds height="55.0" width="105.0" x="250.0" y="220.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="105.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="Shape-exclusivegateway1" isMarkerVisible="false">
<omgdc:Bounds height="32.0" width="32.0" x="535.0" y="227.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="hraudit" id="Shape-hraudit">
<omgdc:Bounds height="55.0" width="105.0" x="625.0" y="220.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="105.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="modifyapply" id="Shape-modifyapply">
<omgdc:Bounds height="55.0" width="105.0" x="503.0" y="310.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="105.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="Shape-exclusivegateway2" isMarkerVisible="false">
<omgdc:Bounds height="32.0" width="32.0" x="535.0" y="410.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="Shape-endevent1">
<omgdc:Bounds height="32.0" width="32.0" x="890.0" y="413.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway3" id="Shape-exclusivegateway3" isMarkerVisible="false">
<omgdc:Bounds height="32.0" width="32.0" x="770.0" y="228.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="reportback" id="Shape-reportback">
<omgdc:Bounds height="55.0" width="105.0" x="855.0" y="221.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="105.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="startevent1" id="Shape-startevent1">
<omgdc:Bounds height="32.0" width="32.0" x="140.0" y="230.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13" sourceElement="reportback" targetElement="endevent1">
<omgdi:waypoint x="906.0" y="276.0"/>
<omgdi:waypoint x="906.0" y="413.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="-1.0" width="-1.0" x="-1.0" y="-1.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14" sourceElement="startevent1" targetElement="deptleaderaudit">
<omgdi:waypoint x="172.0" y="246.0"/>
<omgdi:waypoint x="250.0" y="247.5"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="-1.0" width="-1.0" x="-1.0" y="-1.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3" sourceElement="exclusivegateway1" targetElement="hraudit">
<omgdi:waypoint x="567.0" y="243.0"/>
<omgdi:waypoint x="625.0" y="247.5"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="24.0" x="575.0" y="247.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4" sourceElement="exclusivegateway1" targetElement="modifyapply">
<omgdi:waypoint x="551.0" y="259.0"/>
<omgdi:waypoint x="551.0" y="310.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="24.0" x="555.0" y="267.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6" sourceElement="deptleaderaudit" targetElement="exclusivegateway1">
<omgdi:waypoint x="355.0" y="247.5"/>
<omgdi:waypoint x="535.0" y="243.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="-1.0" width="-1.0" x="-1.0" y="-1.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7" sourceElement="modifyapply" targetElement="exclusivegateway2">
<omgdi:waypoint x="551.0" y="365.0"/>
<omgdi:waypoint x="551.0" y="410.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="-1.0" width="-1.0" x="-1.0" y="-1.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10" sourceElement="hraudit" targetElement="exclusivegateway3">
<omgdi:waypoint x="730.0" y="247.5"/>
<omgdi:waypoint x="770.0" y="244.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="-1.0" width="-1.0" x="-1.0" y="-1.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8" sourceElement="exclusivegateway2" targetElement="deptleaderaudit">
<omgdi:waypoint x="538.0" y="429.0"/>
<omgdi:waypoint x="302.0" y="429.0"/>
<omgdi:waypoint x="302.0" y="275.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="48.0" x="361.0" y="438.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11" sourceElement="exclusivegateway3" targetElement="modifyapply">
<omgdi:waypoint x="789.0" y="257.0"/>
<omgdi:waypoint x="789.0" y="337.0"/>
<omgdi:waypoint x="608.0" y="337.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="24.0" x="672.0" y="319.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9" sourceElement="exclusivegateway2" targetElement="endevent1">
<omgdi:waypoint x="567.0" y="426.0"/>
<omgdi:waypoint x="890.0" y="429.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="48.0" x="659.0" y="437.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12" sourceElement="exclusivegateway3" targetElement="reportback">
<omgdi:waypoint x="802.0" y="244.0"/>
<omgdi:waypoint x="855.0" y="248.5"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="24.0" x="810.0" y="248.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
4、代码测试
LeaveApplyServiceImpl 类
package io.renren.modules.activiti.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.exception.RRException;
import io.renren.modules.activiti.config.MyProcessDiagramGenerator;
import io.renren.modules.activiti.dao.LeaveApplyDao;
import io.renren.modules.activiti.entity.LeaveApplyEntity;
import io.renren.modules.activiti.service.LeaveApplyService;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.FlowNode;
import org.activiti.bpmn.model.SequenceFlow;
import org.activiti.engine.*;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricTaskInstanceQuery;
import org.activiti.engine.impl.RepositoryServiceImpl;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.image.ProcessDiagramGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("leaveApplyService")
public class LeaveApplyServiceImpl extends ServiceImpl<LeaveApplyDao, LeaveApplyEntity> implements LeaveApplyService {
@Autowired
private ProcessEngine processEngine;
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
private HistoryService historyService;
/**
* 开始请假,启动实例
* @param
*/
@Override
public void startleave(){
String leaveApplyId = "8888";
HashMap<String, Object> hashMap2 = new HashMap<>();
//${applyuserid}
hashMap2.put("applyuserid","110");
//identityservice.setAuthenticatedUserId(userid);
ProcessInstance leave = runtimeService.startProcessInstanceByKey("leave", leaveApplyId, hashMap2);
System.out.println("流程实例id:" + leave.getId());
System.out.println("当前活动Id:" + leave.getActivityId());
}
/**
* 查看部门经理任务
*
*/
@Override
public void departmentApproval() {
List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("部门经理").list();
System.out.println("部门经理任务有多少:" + tasks.size());
for (Task task : tasks) {
//流程实例id
String instanceid = task.getProcessInstanceId();
//查出具体的流程
ProcessInstance ins = runtimeService.createProcessInstanceQuery().processInstanceId(instanceid).singleResult();
//获取业务主健
String businesskey = ins.getBusinessKey();
System.out.println("业务的id:" + businesskey);
System.out.println("任务的id:" + task.getId());
System.out.println("实例的id:" + instanceid);
//同意
// HashMap<String, Object> hashMap = new HashMap<>();
// hashMap.put("deptleaderapprove", true);
// taskService.claim(task.getId(), "112");
// taskService.complete(task.getId(), hashMap);
}
}
/**
* 执行部门经理拾取任务
* 因为部门经理是在候选人组,所以要先拾取任务claim
* 如果是设置了主要负责人,那么就可以直接完成任务,用complete
*/
@Override
public void claim() {
//同意,根据上一步获取的任务id
taskService.claim("14", "112");
System.out.println("任务拾取成功");
}
/**
* 部门经理完成任务,同意
*
*
*/
@Override
public void completeTask(){
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("deptleaderapprove", true);
taskService.complete("14",hashMap);
System.out.println("部门经理完成任务,同意");
}
/**
* 人事处置任务
*
*/
@Override
public void hrCompleteTask(){
//暂时取一个任务
//Task task = taskService.createTaskQuery().taskCandidateGroup("人事").singleResult();
//taskService.setAssignee("666");
Task task=taskService.createTaskQuery().taskAssignee("666").singleResult();
System.out.println("人事的任务:"+task);
//流程实例id
//String instanceid = task.getProcessInstanceId();
//查出任务实例
//ProcessInstance ins = runtimeService.createProcessInstanceQuery().processInstanceId(instanceid).singleResult();
//获取业务主健
//String businesskey = ins.getBusinessKey();
//同意,根据上一步获取的任务id,拾取任务
//taskService.claim(task.getId(), "666");
//完成任务
//HashMap<String, Object> hashMap = new HashMap<>();
//hashMap.put("hrapprove", true);
Map<String, Object> variables = new HashMap<String, Object>();
//variables.put("hrapprove", true);
variables.put("content","这是人事666填写的内容哦");
//设置local变量,作用域为该任务
taskService.setVariablesLocal(task.getId(), variables);
Map<String, Object> variables2 = new HashMap<String, Object>();
variables2.put("hrapprove", true);
taskService.complete(task.getId(),variables2);
}
/**
* 时间线
*
*/
@Override
public void taskHistory(){
// 创建历史任务查询对象,根据某实例id
HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService
.createHistoricTaskInstanceQuery().processInstanceId("5")
.orderByTaskCreateTime()
.asc();
// 查询结果包括 local变量
HistoricTaskInstanceQuery instanceQuery = historicTaskInstanceQuery.includeTaskLocalVariables();
List<HistoricTaskInstance> list = instanceQuery.list();
int index = 1;
for (HistoricTaskInstance historicTaskInstance : list) {
System.out.println("==============================");
System.out.println(" 任务id : " +
historicTaskInstance.getId());
System.out.println(" 任务名称 : " +
historicTaskInstance.getName());
System.out.println(" 任务负责人 : " +
historicTaskInstance.getAssignee());
System.out.println(" 任务local变量 : "+
historicTaskInstance.getTaskLocalVariables());
//System.out.println("第[" + index + "]个已执行节点=" + historicTaskInstance.getActivityId() + " : " + historicTaskInstance.getActivityName());
index++;
}
}
public void activityTaskHistory(HttpServletResponse response){
String processInstanceId = "5";
try {
// 获取历史流程实例
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult();
if (historicProcessInstance == null) {
throw new RRException("获取流程实例ID[" + processInstanceId + "]对应的历史流程实例失败!");
} else {
// 获取流程定义
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
.getDeployedProcessDefinition(historicProcessInstance.getProcessDefinitionId());
// 获取流程历史中已执行节点,并按照节点在流程中执行先后顺序排序
List<HistoricActivityInstance> historicActivityInstanceList = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(processInstanceId).orderByHistoricActivityInstanceId().asc().list();
// 已执行的节点ID集合
List<String> executedActivityIdList = new ArrayList<String>();
int index = 1;
System.out.println("获取已经执行的节点ID");
for (HistoricActivityInstance activityInstance : historicActivityInstanceList) {
executedActivityIdList.add(activityInstance.getActivityId());
System.out.println("第[" + index + "]个已执行节点=" + activityInstance.getActivityId() + " : " + activityInstance.getActivityName());
index++;
}
BpmnModel bpmnModel = repositoryService.getBpmnModel(historicProcessInstance.getProcessDefinitionId());
// 已执行的线集合
List<String> flowIds = new ArrayList<String>();
// 获取流程走过的线 (getHighLightedFlows是下面的方法)
flowIds = getHighLightedFlows(bpmnModel, processDefinition, historicActivityInstanceList);
// 获取流程图图像字符流
processEngine.getProcessEngineConfiguration().setProcessDiagramGenerator(new MyProcessDiagramGenerator());
ProcessDiagramGenerator pec = processEngine.getProcessEngineConfiguration().getProcessDiagramGenerator();
//配置字体
InputStream imageStream = pec.generateDiagram(bpmnModel, "png", executedActivityIdList, flowIds, "宋体", "微软雅黑", "黑体", null, 2.0);
response.setContentType("image/png");
OutputStream os = response.getOutputStream();
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = imageStream.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
imageStream.close();
}
System.out.println("[完成]-获取流程图图像");
} catch (Exception e) {
System.out.println(e.getMessage());
log.error("【异常】-获取流程图失败!" + e.getMessage());
throw new RRException("获取流程图失败!" + e.getMessage());
}
}
public List<String> getHighLightedFlows(BpmnModel bpmnModel, ProcessDefinitionEntity processDefinitionEntity, List<HistoricActivityInstance> historicActivityInstances) {
//24小时制
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 用以保存高亮的线flowId
List<String> highFlows = new ArrayList<>();
for (int i = 0; i < historicActivityInstances.size() - 1; i++) {
// 对历史流程节点进行遍历
// 得到节点定义的详细信息
FlowNode activityImpl = (FlowNode) bpmnModel.getMainProcess().getFlowElement(historicActivityInstances.get(i).getActivityId());
// 用以保存后续开始时间相同的节点
List<FlowNode> sameStartTimeNodes = new ArrayList<>();
FlowNode sameActivityImpl1 = null;
// 第一个节点
HistoricActivityInstance activityImpl_ = historicActivityInstances.get(i);
HistoricActivityInstance activityImp2_;
for (int k = i + 1; k <= historicActivityInstances.size() - 1; k++) {
// 后续第1个节点
activityImp2_ = historicActivityInstances.get(k);
//都是usertask,且主节点与后续节点的开始时间相同,说明不是真实的后继节点
if (activityImpl_.getActivityType().equals("userTask") && activityImp2_.getActivityType().equals("userTask") &&
df.format(activityImpl_.getStartTime()).equals(df.format(activityImp2_.getStartTime())))
{
} else {//找到紧跟在后面的一个节点
sameActivityImpl1 = (FlowNode) bpmnModel.getMainProcess().getFlowElement(historicActivityInstances.get(k).getActivityId());
break;
}
}
// 将后面第一个节点放在时间相同节点的集合里
sameStartTimeNodes.add(sameActivityImpl1);
for (int j = i + 1; j < historicActivityInstances.size() - 1; j++) {
// 后续第一个节点
HistoricActivityInstance activityImpl1 = historicActivityInstances.get(j);
// 后续第二个节点
HistoricActivityInstance activityImpl2 = historicActivityInstances.get(j + 1);
// 如果第一个节点和第二个节点开始时间相同保存
if (df.format(activityImpl1.getStartTime()).equals(df.format(activityImpl2.getStartTime()))) {
FlowNode sameActivityImpl2 = (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityImpl2.getActivityId());
sameStartTimeNodes.add(sameActivityImpl2);
} else {// 有不相同跳出循环
break;
}
}
// 取出节点的所有出去的线
List<SequenceFlow> pvmTransitions = activityImpl.getOutgoingFlows();
// 对所有的线进行遍历
for (SequenceFlow pvmTransition : pvmTransitions) {
// 如果取出的线的目标节点存在时间相同的节点里,保存该线的id,进行高亮显示
FlowNode pvmActivityImpl = (FlowNode) bpmnModel.getMainProcess().getFlowElement(pvmTransition.getTargetRef());
if (sameStartTimeNodes.contains(pvmActivityImpl)) {
highFlows.add(pvmTransition.getId());
}
}
}
return highFlows;
}
}
LeaveApplyService 接口
package io.renren.modules.activiti.service;
import com.baomidou.mybatisplus.extension.service.IService;
import io.renren.common.utils.PageUtils;
import io.renren.modules.activiti.entity.LeaveApplyEntity;
import io.renren.modules.sys.entity.SysRoleEntity;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 请假
*
*/
public interface LeaveApplyService extends IService<LeaveApplyEntity> {
void startleave();
void departmentApproval();
void claim();
void completeTask();
void hrCompleteTask();
void taskHistory();
void activityTaskHistory(HttpServletResponse response);
}
dao层
package io.renren.modules.activiti.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.activiti.entity.LeaveApplyEntity;
import io.renren.modules.sys.entity.SysLogEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 请假
*
*
*/
@Mapper
public interface LeaveApplyDao extends BaseMapper<LeaveApplyEntity> {
}
controller层
package io.renren.modules.activiti.controller;
import io.renren.modules.activiti.service.LeaveApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
@RestController
@RequestMapping("/leaveApply")
public class LeaveApplyController {
@Autowired
private LeaveApplyService leaveApplyService;
/**
* 开始请假,启动实例
* @param
*/
@RequestMapping("/test1")
public void startleave(){
leaveApplyService.startleave();
}
/**
* 部门领导审批,同意
*
*/
@RequestMapping("/test2")
public void departmentApproval(){
leaveApplyService.departmentApproval();
}
/**
* 部门领导拾取任务成功
*
*/
@RequestMapping("/test3")
public void claim(){
leaveApplyService.claim();
}
/**
* 部门领导完成任务,同意
*
*/
@RequestMapping("/test4")
public void completeTask(){
leaveApplyService.completeTask();
}
/**
* 人事处置,并设置一些自定义变量
*
*/
@RequestMapping("/test5")
public void hrCompleteTask(){
leaveApplyService.hrCompleteTask();
}
/**
* 通过实例id,查看改实例处置流程,时间线
*
*/
@RequestMapping("/test6")
public void taskHistory(){
leaveApplyService.taskHistory();
}
/**
* 已经执行的历史记录,通过图片方式来查看实例执行到哪一步
*
*/
@RequestMapping("/test7")
public void activityTaskHistory(HttpServletResponse response){
leaveApplyService.activityTaskHistory(response);
}
}
其中最重要的是实现类
其中test6、test7执行的效果图如下
/**
* 通过实例id,查看改实例处置流程,时间线
*
*/
@RequestMapping("/test6")
public void taskHistory(){
leaveApplyService.taskHistory();
}
/**
* 已经执行的历史记录,通过图片方式来查看实例执行到哪一步
*
*/
@RequestMapping("/test7")
public void activityTaskHistory(HttpServletResponse response){
leaveApplyService.activityTaskHistory(response);
}
test6: 查看实例执行历史记录
test7: 查看实例执行的节点,目前是执行到销假的步骤