activiti 流程傻瓜式教学,看了必回,详细教程
工具 eclipse IDEA 均可
第一步:eclipse 设置和插件配置流程
1、eclipse安装activiti插件方法:https://blog.****.net/qq_33547950/article/details/54926435 不在多说。
2.设置创建流程时生成图片
3.创建流程:
4.连线设置,节点设置
2点直接只有一条线的时候 默认不用设置 多条线时设置如下
名字 ID 不要重复
在main_config配置里面 的condition中配置连接条件,类似EL 表达式 里面返回的是 true 或者false PS: ${message=='小于三天'}
5.
此时流程图 配置完成,代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 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" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="Start" name="Start"></startEvent>
<endEvent id="End" name="End"></endEvent>
<userTask id="usertask1" name="经理" activiti:assignee="张三"></userTask>
<userTask id="usertask2" name="总监" activiti:assignee="李四"></userTask>
<userTask id="usertask3" name="人事" activiti:assignee="王五"></userTask>
<sequenceFlow id="flow1" name="to 经理" sourceRef="Start" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" name="请假三天以上" sourceRef="usertask1" targetRef="usertask2">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${message=='大于三天'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow3" name="请假三天内" sourceRef="usertask1" targetRef="usertask3">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${message=='小于三天'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow4" name="to 人事" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
<sequenceFlow id="flow5" name="to End" sourceRef="usertask3" targetRef="End"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="Start" id="BPMNShape_Start">
<omgdc:Bounds height="35.0" width="35.0" x="470.0" y="120.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="End" id="BPMNShape_End">
<omgdc:Bounds height="35.0" width="35.0" x="470.0" y="620.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="435.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="660.0" y="350.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="435.0" y="450.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="487.0" y="155.0"></omgdi:waypoint>
<omgdi:waypoint x="487.0" y="260.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="487.0" y="199.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="487.0" y="315.0"></omgdi:waypoint>
<omgdi:waypoint x="712.0" y="350.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="527.0" y="320.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="487.0" y="315.0"></omgdi:waypoint>
<omgdi:waypoint x="487.0" y="450.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="487.0" y="370.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="712.0" y="405.0"></omgdi:waypoint>
<omgdi:waypoint x="487.0" y="450.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="643.0" y="441.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="487.0" y="505.0"></omgdi:waypoint>
<omgdi:waypoint x="487.0" y="620.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="491.0" y="539.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
同时生成图片
.png 文件
6.创建流程部署类:
ProcessDeploymentTest
diagrams/MyProcess.bpmn 这个是对应刚才新建的流程文件地址 以及流程名字 注意一点要保持一致 //部署流程 @Test public void testDeploy(){ RepositoryService repositoryService = processEngine.getRepositoryService(); Deployment deployment = repositoryService.createDeployment().addClasspathResource("diagrams/MyProcess.bpmn").deploy(); System.out.println(deployment); System.out.println("部署ID:"+deployment.getId()); }
//启动流程 @Test public void testStart(){ //启动流程实例 ProcessInstance pi = processEngine.getRuntimeService()// .startProcessInstanceByKey("myProcess");//使用流程定义的key的最新版本启动流程 System.out.println("流程实例ID:"+pi.getId()); System.out.println("流程定义的ID:"+pi.getProcessDefinitionId()); }
/**查询我的个人任务 查出此时流程 审核所在节点的 审核节点TD taskId */ @Test public void findPersonalTaskList(){ //任务办理人 王五 张三 李四 String assignee = "王五"; List<Task> list = processEngine.getTaskService()// .createTaskQuery()// .taskAssignee(assignee)//个人任务的查询 .list(); if(list!=null && list.size()>0){ for(Task task:list){ System.out.println("任务ID:"+task.getId()); System.out.println("任务的办理人:"+task.getAssignee()); System.out.println("任务名称:"+task.getName()); System.out.println("任务的创建时间:"+task.getCreateTime()); System.out.println("流程实例ID:"+task.getProcessInstanceId()); System.out.println("#######################################"); } } }
重点介绍此时完成任务: /**完成任务*/ @Test public void completeTask(){ //任务ID 这个ID 是上面的查询任务查询出来的 不要出错了 String taskId = "2165003"; //完成任务的同时,设置流程变量,让流程变量判断连线该如何执行 Map<String, Object> variables = new HashMap<String, Object>(); //其中message对应sequenceFlow.bpmn中的${message=='大于三天'} variables.put("message", "大于三天");//这个流程变量值 会控制流程的走向 processEngine.getTaskService()// .complete(taskId,variables); System.out.println("完成任务:"+taskId); }
//删除部署的流程 @Test public void delete(){ // 这个是流程部署成功后 生成的 String deploymentId = "2150002"; RepositoryService repositoryService = processEngine.getRepositoryService(); repositoryService.deleteDeployment(deploymentId, true); }
//查询部署的流程 @Test public void query(){ // 这个是流程部署成功后 生成的 String deploymentId = "1290923"; RepositoryService repositoryService = processEngine.getRepositoryService(); List<Deployment> list = repositoryService.createDeploymentQuery().deploymentId(deploymentId).list(); System.out.println(list.size()); }
/** * 获得png文件的输入流 * * @throws Exception */ @Test public void test2() throws Exception { // 这个是流程部署成功后 生成的 String processDefinitionId = "myProcess:1:1937505"; InputStream pngInputStream = processEngine.getRepositoryService() .getProcessDiagram(processDefinitionId); FileUtils.copyInputStreamToFile(pngInputStream, new File("d:\\vehicleCN_A.png")); }
PS: 不知道流程表信息的 请查看我的另一篇文章,里面非常详细
https://blog.****.net/du18637795957/article/details/82656906
如若转载 请说明出处: