Initial commit
This commit is contained in:
		| @@ -44,6 +44,19 @@ | |||||||
|             <artifactId>velocity-engine-core</artifactId> |             <artifactId>velocity-engine-core</artifactId> | ||||||
|             <version>2.0</version> |             <version>2.0</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|  |  | ||||||
|  |         <!--引入activiti的springboot启动器 --> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>org.activiti</groupId> | ||||||
|  |             <artifactId>activiti-spring-boot-starter</artifactId> | ||||||
|  |             <version>7.1.0.M6</version> | ||||||
|  |             <exclusions> | ||||||
|  |                 <exclusion> | ||||||
|  |                     <artifactId>mybatis</artifactId> | ||||||
|  |                     <groupId>org.mybatis</groupId> | ||||||
|  |                 </exclusion> | ||||||
|  |             </exclusions> | ||||||
|  |         </dependency> | ||||||
|     </dependencies> |     </dependencies> | ||||||
|  |  | ||||||
|     <build> |     <build> | ||||||
| @@ -70,6 +83,7 @@ | |||||||
|                     <include>**/*.yml</include> |                     <include>**/*.yml</include> | ||||||
|                     <include>**/*.properties</include> |                     <include>**/*.properties</include> | ||||||
|                     <include>**/*.xml</include> |                     <include>**/*.xml</include> | ||||||
|  |                     <include>**/*.png</include> | ||||||
|                 </includes> |                 </includes> | ||||||
|                 <filtering>false</filtering> |                 <filtering>false</filtering> | ||||||
|             </resource> |             </resource> | ||||||
|   | |||||||
| @@ -10,9 +10,9 @@ spring: | |||||||
|   datasource: |   datasource: | ||||||
|     type: com.zaxxer.hikari.HikariDataSource |     type: com.zaxxer.hikari.HikariDataSource | ||||||
|     driver-class-name: com.mysql.cj.jdbc.Driver |     driver-class-name: com.mysql.cj.jdbc.Driver | ||||||
|     url: jdbc:mysql://localhost:3306/guigu-oa?useSSL=false&useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true |     url: jdbc:mysql://43.143.164.194:3306/guigu-oa?useSSL=false&useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true | ||||||
|     username: root |     username: admin | ||||||
|     password: root |     password: admin | ||||||
|   jackson: |   jackson: | ||||||
|     date-format: yyyy-MM-dd HH:mm:ss |     date-format: yyyy-MM-dd HH:mm:ss | ||||||
|     time-zone: GMT+8 |     time-zone: GMT+8 | ||||||
| @@ -28,3 +28,18 @@ spring: | |||||||
|         max-wait: -1    #最大阻塞等待时间(负数表示没限制) |         max-wait: -1    #最大阻塞等待时间(负数表示没限制) | ||||||
|         max-idle: 5    #最大空闲 |         max-idle: 5    #最大空闲 | ||||||
|         min-idle: 0     #最小空闲 |         min-idle: 0     #最小空闲 | ||||||
|  |   activiti: | ||||||
|  |     #    false:默认,数据库表不变,但是如果版本不对或者缺失表会抛出异常(生产使用) | ||||||
|  |     #    true:表不存在,自动创建(开发使用) | ||||||
|  |     #    create_drop: 启动时创建,关闭时删除表(测试使用) | ||||||
|  |     #    drop_create: 启动时删除表,在创建表 (不需要手动关闭引擎) | ||||||
|  |     database-schema-update: true | ||||||
|  |     #监测历史表是否存在,activities7默认不开启历史表 | ||||||
|  |     db-history-used: true | ||||||
|  |     #none:不保存任何历史数据,流程中这是最高效的 | ||||||
|  |     #activity:只保存流程实例和流程行为 | ||||||
|  |     #audit:除了activity,还保存全部的流程任务以及其属性,audit为history默认值 | ||||||
|  |     #full:除了audit、还保存其他全部流程相关的细节数据,包括一些流程参数 | ||||||
|  |     history-level: full | ||||||
|  |     #校验流程文件,默认校验resources下的process 文件夹的流程文件 | ||||||
|  |     check-process-definitions: true | ||||||
|   | |||||||
							
								
								
									
										40
									
								
								service-oa/src/main/resources/process/qingjia.bpmn20.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								service-oa/src/main/resources/process/qingjia.bpmn20.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | |||||||
|  | <?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/processdef"> | ||||||
|  |   <process id="qingjia" isExecutable="true"> | ||||||
|  |     <startEvent id="sid-AE120E1B-25EC-43C0-B703-8EE13CB13835"></startEvent> | ||||||
|  |     <userTask id="sid-30AE99C3-6055-4472-B3A3-9C4B0BB3975A" name="张三审批" activiti:assignee="zhangsan"></userTask> | ||||||
|  |     <userTask id="sid-A8361321-1F0D-429F-8E5D-5F0D3FE7B764" name="李四审批" activiti:assignee="lisi"></userTask> | ||||||
|  |     <endEvent id="sid-18403A14-DABE-48F8-B43F-16BCAFC66CE7"></endEvent> | ||||||
|  |     <sequenceFlow id="sid-E88CBC13-6950-4428-8A88-721850823A32" sourceRef="sid-AE120E1B-25EC-43C0-B703-8EE13CB13835" targetRef="sid-30AE99C3-6055-4472-B3A3-9C4B0BB3975A"></sequenceFlow> | ||||||
|  |     <sequenceFlow id="sid-8D62AC0F-C742-4738-A61A-5FC81916ACC1" sourceRef="sid-30AE99C3-6055-4472-B3A3-9C4B0BB3975A" targetRef="sid-A8361321-1F0D-429F-8E5D-5F0D3FE7B764"></sequenceFlow> | ||||||
|  |     <sequenceFlow id="sid-4546D057-D5C4-467E-8BCC-AED3DF110B13" sourceRef="sid-A8361321-1F0D-429F-8E5D-5F0D3FE7B764" targetRef="sid-18403A14-DABE-48F8-B43F-16BCAFC66CE7"></sequenceFlow> | ||||||
|  |   </process> | ||||||
|  |   <bpmndi:BPMNDiagram id="BPMNDiagram_qingjia"> | ||||||
|  |     <bpmndi:BPMNPlane bpmnElement="qingjia" id="BPMNPlane_qingjia"> | ||||||
|  |       <bpmndi:BPMNShape bpmnElement="sid-AE120E1B-25EC-43C0-B703-8EE13CB13835" id="BPMNShape_sid-AE120E1B-25EC-43C0-B703-8EE13CB13835"> | ||||||
|  |         <omgdc:Bounds height="30.0" width="30.0" x="214.43284560541542" y="142.0231410855287"></omgdc:Bounds> | ||||||
|  |       </bpmndi:BPMNShape> | ||||||
|  |       <bpmndi:BPMNShape bpmnElement="sid-30AE99C3-6055-4472-B3A3-9C4B0BB3975A" id="BPMNShape_sid-30AE99C3-6055-4472-B3A3-9C4B0BB3975A"> | ||||||
|  |         <omgdc:Bounds height="80.0" width="100.0" x="330.0" y="120.0"></omgdc:Bounds> | ||||||
|  |       </bpmndi:BPMNShape> | ||||||
|  |       <bpmndi:BPMNShape bpmnElement="sid-A8361321-1F0D-429F-8E5D-5F0D3FE7B764" id="BPMNShape_sid-A8361321-1F0D-429F-8E5D-5F0D3FE7B764"> | ||||||
|  |         <omgdc:Bounds height="80.0" width="100.0" x="525.0" y="117.02314108552869"></omgdc:Bounds> | ||||||
|  |       </bpmndi:BPMNShape> | ||||||
|  |       <bpmndi:BPMNShape bpmnElement="sid-18403A14-DABE-48F8-B43F-16BCAFC66CE7" id="BPMNShape_sid-18403A14-DABE-48F8-B43F-16BCAFC66CE7"> | ||||||
|  |         <omgdc:Bounds height="28.0" width="28.0" x="735.0" y="143.0231410855287"></omgdc:Bounds> | ||||||
|  |       </bpmndi:BPMNShape> | ||||||
|  |       <bpmndi:BPMNEdge bpmnElement="sid-8D62AC0F-C742-4738-A61A-5FC81916ACC1" id="BPMNEdge_sid-8D62AC0F-C742-4738-A61A-5FC81916ACC1"> | ||||||
|  |         <omgdi:waypoint x="430.0" y="159.23670284244326"></omgdi:waypoint> | ||||||
|  |         <omgdi:waypoint x="525.0" y="157.78643824308546"></omgdi:waypoint> | ||||||
|  |       </bpmndi:BPMNEdge> | ||||||
|  |       <bpmndi:BPMNEdge bpmnElement="sid-E88CBC13-6950-4428-8A88-721850823A32" id="BPMNEdge_sid-E88CBC13-6950-4428-8A88-721850823A32"> | ||||||
|  |         <omgdi:waypoint x="244.42991477976543" y="157.31964771236983"></omgdi:waypoint> | ||||||
|  |         <omgdi:waypoint x="330.0" y="159.01145142629514"></omgdi:waypoint> | ||||||
|  |       </bpmndi:BPMNEdge> | ||||||
|  |       <bpmndi:BPMNEdge bpmnElement="sid-4546D057-D5C4-467E-8BCC-AED3DF110B13" id="BPMNEdge_sid-4546D057-D5C4-467E-8BCC-AED3DF110B13"> | ||||||
|  |         <omgdi:waypoint x="625.0" y="157.0231410855287"></omgdi:waypoint> | ||||||
|  |         <omgdi:waypoint x="735.0" y="157.0231410855287"></omgdi:waypoint> | ||||||
|  |       </bpmndi:BPMNEdge> | ||||||
|  |     </bpmndi:BPMNPlane> | ||||||
|  |   </bpmndi:BPMNDiagram> | ||||||
|  | </definitions> | ||||||
							
								
								
									
										
											BIN
										
									
								
								service-oa/src/main/resources/process/qingjia.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								service-oa/src/main/resources/process/qingjia.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 7.5 KiB | 
| @@ -0,0 +1,195 @@ | |||||||
|  | package com.atguigu.auth.activti; | ||||||
|  |  | ||||||
|  | import org.activiti.engine.HistoryService; | ||||||
|  | import org.activiti.engine.RepositoryService; | ||||||
|  | import org.activiti.engine.RuntimeService; | ||||||
|  | import org.activiti.engine.TaskService; | ||||||
|  | import org.activiti.engine.history.HistoricTaskInstance; | ||||||
|  | import org.activiti.engine.repository.Deployment; | ||||||
|  | import org.activiti.engine.repository.ProcessDefinition; | ||||||
|  | import org.activiti.engine.runtime.ProcessInstance; | ||||||
|  | import org.activiti.engine.task.Task; | ||||||
|  | import org.junit.Test; | ||||||
|  | import org.junit.runner.RunWith; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.boot.test.context.SpringBootTest; | ||||||
|  | import org.springframework.test.context.junit4.SpringRunner; | ||||||
|  |  | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * ClassName: ProcessTest | ||||||
|  |  * Package: com.atguigu.auth.activti | ||||||
|  |  * | ||||||
|  |  * @author yovinchen | ||||||
|  |  * @Create 2023/6/11 20:03 | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | @RunWith(SpringRunner.class) | ||||||
|  | @SpringBootTest | ||||||
|  | public class ProcessTest { | ||||||
|  |  | ||||||
|  |     @Autowired | ||||||
|  |     private RepositoryService repositoryService; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     @Autowired | ||||||
|  |     private RuntimeService runtimeService; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     @Autowired | ||||||
|  |     private TaskService taskService; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     @Autowired | ||||||
|  |     private HistoryService historyService; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 单个流程挂起 | ||||||
|  |      */ | ||||||
|  |     @Test | ||||||
|  |     public void SingleSuspendProcessInstance() { | ||||||
|  |         String processInstanceId = "8bdff984-ab53-11ed-9b17-f8e43b734677"; | ||||||
|  |         ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); | ||||||
|  |         //获取到当前流程定义是否为暂停状态   suspended方法为true代表为暂停   false就是运行的 | ||||||
|  |         boolean suspended = processInstance.isSuspended(); | ||||||
|  |         if (suspended) { | ||||||
|  |             runtimeService.activateProcessInstanceById(processInstanceId); | ||||||
|  |             System.out.println("流程实例:" + processInstanceId + "激活"); | ||||||
|  |         } else { | ||||||
|  |             runtimeService.suspendProcessInstanceById(processInstanceId); | ||||||
|  |             System.out.println("流程实例:" + processInstanceId + "挂起"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 全部流程实例挂起 | ||||||
|  |      */ | ||||||
|  |     @Test | ||||||
|  |     public void suspendProcessInstance() { | ||||||
|  |         ProcessDefinition qingjia = repositoryService.createProcessDefinitionQuery().processDefinitionKey("qingjia").singleResult(); | ||||||
|  |         // 获取到当前流程定义是否为暂停状态 suspended方法为true是暂停的,suspended方法为false是运行的 | ||||||
|  |         boolean suspended = qingjia.isSuspended(); | ||||||
|  |         if (suspended) { | ||||||
|  |             // 暂定,那就可以激活 | ||||||
|  |             // 参数1:流程定义的id  参数2:是否激活    参数3:时间点 | ||||||
|  |             repositoryService.activateProcessDefinitionById(qingjia.getId(), true, null); | ||||||
|  |             System.out.println("流程定义:" + qingjia.getId() + "激活"); | ||||||
|  |         } else { | ||||||
|  |             repositoryService.suspendProcessDefinitionById(qingjia.getId(), true, null); | ||||||
|  |             System.out.println("流程定义:" + qingjia.getId() + "挂起"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 启动流程实例,添加businessKey | ||||||
|  |      */ | ||||||
|  |     @Test | ||||||
|  |     public void startUpProcessAddBusinessKey() { | ||||||
|  |         String businessKey = "1"; | ||||||
|  |         // 启动流程实例,指定业务标识businessKey,也就是请假申请单id | ||||||
|  |         ProcessInstance processInstance = runtimeService. | ||||||
|  |                 startProcessInstanceByKey("qingjia", businessKey); | ||||||
|  |         // 输出 | ||||||
|  |         System.out.println("业务id:" + processInstance.getBusinessKey()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 删除流程定义 | ||||||
|  |      */ | ||||||
|  |     public void deleteDeployment() { | ||||||
|  |         //部署id | ||||||
|  |         String deploymentId = "5b997a98-0868-11ee-9ba7-6294623ad4e1"; | ||||||
|  |         //删除流程定义,如果该流程定义已有流程实例启动则删除时出错 | ||||||
|  |         repositoryService.deleteDeployment(deploymentId); | ||||||
|  |         //设置true 级联删除流程定义,即使该流程有流程实例启动也可以删除,设置为false非级别删除方式 | ||||||
|  |         repositoryService.deleteDeployment(deploymentId, true); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 查询流程定义 | ||||||
|  |      */ | ||||||
|  |     @Test | ||||||
|  |     public void findProcessDefinitionList() { | ||||||
|  |         List<ProcessDefinition> definitionList = repositoryService.createProcessDefinitionQuery() | ||||||
|  |                 .orderByProcessDefinitionVersion() | ||||||
|  |                 .desc() | ||||||
|  |                 .list(); | ||||||
|  |         //输出流程定义信息 | ||||||
|  |         for (ProcessDefinition processDefinition : definitionList) { | ||||||
|  |             System.out.println("流程定义 id=" + processDefinition.getId()); | ||||||
|  |             System.out.println("流程定义 name=" + processDefinition.getName()); | ||||||
|  |             System.out.println("流程定义 key=" + processDefinition.getKey()); | ||||||
|  |             System.out.println("流程定义 Version=" + processDefinition.getVersion()); | ||||||
|  |             System.out.println("流程部署ID =" + processDefinition.getDeploymentId()); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 查询已处理历史任务 | ||||||
|  |      */ | ||||||
|  |     @Test | ||||||
|  |     public void findProcessedTaskList() { | ||||||
|  |         //张三已处理过的历史任务 | ||||||
|  |         List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().taskAssignee("zhangsan").finished().list(); | ||||||
|  |         for (HistoricTaskInstance historicTaskInstance : list) { | ||||||
|  |             System.out.println("流程实例id:" + historicTaskInstance.getProcessInstanceId()); | ||||||
|  |             System.out.println("任务id:" + historicTaskInstance.getId()); | ||||||
|  |             System.out.println("任务负责人:" + historicTaskInstance.getAssignee()); | ||||||
|  |             System.out.println("任务名称:" + historicTaskInstance.getName()); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 完成任务 | ||||||
|  |      */ | ||||||
|  |     @Test | ||||||
|  |     public void completTask() { | ||||||
|  |         Task task = taskService.createTaskQuery().taskAssignee("zhangsan")  //要查询的负责人 | ||||||
|  |                 .singleResult();//返回一条 | ||||||
|  |  | ||||||
|  |         //完成任务,参数:任务id | ||||||
|  |         taskService.complete(task.getId()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 查询当前个人待执行的任务 zhangsan | ||||||
|  |      */ | ||||||
|  |     @Test | ||||||
|  |     public void findPendingTaskList() { | ||||||
|  |         //任务负责人 | ||||||
|  |         String assignee = "zhangsan"; | ||||||
|  |         List<Task> list = taskService.createTaskQuery().taskAssignee(assignee)//只查询该任务负责人的任务 | ||||||
|  |                 .list(); | ||||||
|  |         for (Task task : list) { | ||||||
|  |             System.out.println("流程实例id:" + task.getProcessInstanceId()); | ||||||
|  |             System.out.println("任务id:" + task.getId()); | ||||||
|  |             System.out.println("任务负责人:" + task.getAssignee()); | ||||||
|  |             System.out.println("任务名称:" + task.getName()); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 启动流程实例 | ||||||
|  |      */ | ||||||
|  |     @Test | ||||||
|  |     public void startUpProcess() { | ||||||
|  |         //创建流程实例,我们需要知道流程定义的key | ||||||
|  |         ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("qingjia"); | ||||||
|  |         //输出实例的相关信息 | ||||||
|  |         System.out.println("流程定义id:" + processInstance.getProcessDefinitionId()); | ||||||
|  |         System.out.println("流程实例id:" + processInstance.getId()); | ||||||
|  |         System.out.println("当前活动Id:" + processInstance.getActivityId()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 单个文件部署 | ||||||
|  |      */ | ||||||
|  |     @Test | ||||||
|  |     public void deployProcess() { | ||||||
|  |         // 流程部署 | ||||||
|  |         Deployment deploy = repositoryService.createDeployment().addClasspathResource("process/qingjia.bpmn20.xml").addClasspathResource("process/qingjia.png").name("请假申请流程").deploy(); | ||||||
|  |         System.out.println(deploy.getId()); | ||||||
|  |         System.out.println(deploy.getName()); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user