SpringBoot整合Activiti7——实战之加班流程(驳回)

2024-04-07 11:36

本文主要是介绍SpringBoot整合Activiti7——实战之加班流程(驳回),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

    • 代码实现
      • 部署流程
      • 启动流程
      • 部门领导拾取任务
      • HR审批
      • 完成任务增加意见
      • 记录加班时长
      • xml文件


  • 提交申请 - 部门审批通过 - HR审批通过 - 记录加班时长 - 结束流程
  • 提交申请 - 部门审批通过 - HR审批不通过 - 用户选择重新申请 - 部门审批通过 - HR审批通过 - 记录加班时长 - 结束流程
  • 提交申请 - 部门审批通过 - HR审批不通过 - 用户选择重新申请 - 部门审批通过 - HR审批不通过 - 用户选择放弃申请 - 结束流程
  • 提交申请 - 部门审批通过 - HR审批不通过 - 用户选择重新申请 - 部门审批通过 - HR审批不通过 - 用户选择重新申请 - 。。。

代码实现

在这里插入图片描述

部署流程

	@Testpublic void deployProcess() throws IOException {ClassPathResource classPathResource = new ClassPathResource("/processes/overtime.bpmn20.xml");// 部署流程 act_re_procdef act_re_deploymentDeployment deploy = repositoryService.createDeployment().addInputStream(classPathResource.getPath(), classPathResource.getInputStream()).deploy();System.out.println("deploy = " + deploy);}

启动流程

	@Testpublic void startProcess() {// 设置流程变量Map<String, Object> variables = new HashMap<>();// 提交申请办理人variables.put("applyUserId", APPLY_USER_ID);// 部门审批候选人variables.put("candidateUsers", String.join(",", CollectionUtil.newArrayList("depLeader1", "depLeader2", "depLeader3")));// HR审批候选组variables.put("candidateGroups", CollectionUtil.newArrayList("hrGroup1", "hrGroup2", "hrGroup3"));String processDefinitionKey = "overtime";String businessKey = processDefinitionKey + ":" + BUSINESS_ID; // 假设模拟业务id为1001// 启动流程 act_hi_procinst act_ru_variable act_ru_task act_hi_identitylink(候选组,候选人)ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables);System.out.println("processInstance = " + processInstance);// 获取流程变量 act_ru_variableSystem.out.println("===================流程变量===================");runtimeService.getVariables(processInstance.getId()).forEach((key, value) -> System.out.println("key: " + key + ",value:" + value));// 输出当前任务列表this.printTaskList(processInstance.getId());}

部门领导拾取任务

将启动流程后的流程实例ID更换到下面

	@Testpublic void departLeaderClaimTaskAndCompleteTask() {// 如果当前任务没有指派人,需要先使用 claim() 方法领取任务,拾取完成后 act_ru_task 的 ASSIGNEE_ 字段则为该用户的值,下一步完成该任务// 如果没写实activiti:candidateUsers,则需要传入候选人来拾取任务(获取直接分配人员完成该任务:task.setAssignee("depLeader1");)// 有一个候选人拾取了该任务,其他人就看不到任务// 查询任务Task task = taskService.createTaskQuery().processInstanceId(PROCESS_INSTANCE_ID).singleResult();// 拾取任务taskService.claim(task.getId(), "depLeader1");// 增加意见 act_hi_commenttaskService.addComment(task.getId(), task.getProcessInstanceId(), "部门领导建议加班");// 完成任务Map<String, Object> hashMap = new HashMap<>();hashMap.put("departPass", true);taskService.complete(task.getId(), hashMap, true);// 输出当前任务列表this.printTaskList(task.getProcessInstanceId());}

HR审批

将启动流程后的流程实例ID更换到下面

	@Testpublic void hrAudit() {// 查询任务Task task = taskService.createTaskQuery().processInstanceId(PROCESS_INSTANCE_ID).taskCandidateGroup("hrGroup1").singleResult();// 拾取任务taskService.claim(task.getId(), "hr1");// 增加意见taskService.addComment(task.getId(), task.getProcessInstanceId(), "hr支持加班");// 完成任务Map<String, Object> hashMap = new HashMap<>();hashMap.put("hrPass", true);taskService.complete(task.getId(), hashMap, true);// 输出当前任务列表this.printTaskList(task.getProcessInstanceId());}

完成任务增加意见

将启动流程后的流程实例ID更换到下面

	@Testpublic void adjustmentApply() {// 查询任务Task task = taskService.createTaskQuery().processInstanceId(PROCESS_INSTANCE_ID).taskAssignee(APPLY_USER_ID).singleResult();// 增加意见taskService.addComment(task.getId(), task.getProcessInstanceId(), "我要加班!!!");// 完成任务Map<String, Object> hashMap = new HashMap<>();hashMap.put("reapply", true);taskService.complete(task.getId(), hashMap, true);// 输出当前任务列表this.printTaskList(task.getProcessInstanceId());}

记录加班时长

	@Testpublic void overtimeRecord() {// 查询任务Task task = taskService.createTaskQuery().processInstanceId(PROCESS_INSTANCE_ID).taskAssignee(APPLY_USER_ID).singleResult();// 增加意见taskService.addComment(task.getId(), task.getProcessInstanceId(), "可以加班");// 完成任务Map<String, Object> hashMap = new HashMap<>();hashMap.put("remark", "记录加班时长");taskService.complete(task.getId(), hashMap);// 输出当前任务列表this.printTaskList(task.getProcessInstanceId());}

xml文件

<?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="overtime" name="加班申请流程" isExecutable="true"><documentation>模拟加班申请流程</documentation><startEvent id="sid-44149b62-6b70-4150-8340-89d915c60046" name="提交申请" activiti:initiator="applyUserId"><!--  动态表单,可以获取对应的属性名称与id  --><!--      <extensionElements>--><!--        <activiti:formProperty id="reason" name="加班原因" type="string" required="true"/>--><!--        <activiti:formProperty id="submitTime" name="提交时间" type="date" datePattern="yyyy-MM-dd HH:mm:ss" required="true"/>--><!--      </extensionElements>--></startEvent><userTask id="sid-09325abe-9494-46ab-9e03-cf4483a70c28" name="部门主管审批" activiti:exclusive="true" activiti:candidateUsers="${candidateUsers}"/><sequenceFlow id="sid-8198060f-610c-4abb-9256-cc1ef7f08a0b" sourceRef="sid-44149b62-6b70-4150-8340-89d915c60046" targetRef="sid-09325abe-9494-46ab-9e03-cf4483a70c28"/><exclusiveGateway id="sid-8bdc7d37-85b5-48c7-a6e8-72fb1faf34d6"/><sequenceFlow id="sid-2e71f5ae-e987-476a-ae54-87a4c192eb65" sourceRef="sid-09325abe-9494-46ab-9e03-cf4483a70c28" targetRef="sid-8bdc7d37-85b5-48c7-a6e8-72fb1faf34d6"/><userTask id="sid-7584bcec-5f4b-49d0-a431-0bbb1e32128e" name="用户选择" activiti:assignee="${applyUserId}">
<!--      <extensionElements>--><!--   可以允许任务的发起者也能完成任务。     --><!--        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>-->
<!--      </extensionElements>--></userTask><userTask id="sid-d1248bf0-33d2-4f70-bd6a-fccb816d192b" name="人事审批" activiti:exclusive="true" activiti:candidateGroups="${candidateGroups}"/><exclusiveGateway id="sid-55d28295-3ad0-45a2-b90d-3594c81a5b43"/><sequenceFlow id="sid-816b4e26-95e9-4d03-80a3-79882efc0b3c" sourceRef="sid-7584bcec-5f4b-49d0-a431-0bbb1e32128e" targetRef="sid-55d28295-3ad0-45a2-b90d-3594c81a5b43"/><endEvent id="sid-a8e23c5a-8ca2-41fe-8fd1-1c6f5ea72b37" name="结束"/><exclusiveGateway id="sid-d09ec75d-0d6b-4def-9152-ffc23d42c206"/><sequenceFlow id="sid-0173be85-fcd6-40fe-8bdb-8d589e383532" sourceRef="sid-d1248bf0-33d2-4f70-bd6a-fccb816d192b" targetRef="sid-d09ec75d-0d6b-4def-9152-ffc23d42c206"/><sequenceFlow id="sid-2c40f63c-832a-4bdc-9326-09327f697c52" sourceRef="sid-8bdc7d37-85b5-48c7-a6e8-72fb1faf34d6" targetRef="sid-7584bcec-5f4b-49d0-a431-0bbb1e32128e" name="不同意"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${!departPass}]]></conditionExpression></sequenceFlow><sequenceFlow id="sid-c948563c-8965-4c6c-bf31-6374a0185374" sourceRef="sid-8bdc7d37-85b5-48c7-a6e8-72fb1faf34d6" targetRef="sid-d1248bf0-33d2-4f70-bd6a-fccb816d192b" name="同意"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${departPass}]]></conditionExpression></sequenceFlow><sequenceFlow id="sid-0932d9fe-e117-4aba-8297-afd5eca5bd3c" sourceRef="sid-55d28295-3ad0-45a2-b90d-3594c81a5b43" targetRef="sid-a8e23c5a-8ca2-41fe-8fd1-1c6f5ea72b37" name="放弃申请"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${!reapply}]]></conditionExpression></sequenceFlow><sequenceFlow id="sid-5c319add-6d76-42ec-98e2-ed40a2614c54" sourceRef="sid-d09ec75d-0d6b-4def-9152-ffc23d42c206" targetRef="sid-7584bcec-5f4b-49d0-a431-0bbb1e32128e" name="不同意"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${!hrPass}]]></conditionExpression></sequenceFlow><sequenceFlow id="sid-92a890d9-889a-4782-b8e4-9ccf00c3a594" sourceRef="sid-55d28295-3ad0-45a2-b90d-3594c81a5b43" targetRef="sid-09325abe-9494-46ab-9e03-cf4483a70c28" name="重新申请"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${reapply}]]></conditionExpression></sequenceFlow><userTask id="sid-0e9f1f2c-2e22-4ccb-8452-d70075d7e916" name="记录加班信息" activiti:assignee="${applyUserId}"/><sequenceFlow id="sid-8f45254a-6b30-43e1-bfde-8ad56685810d" sourceRef="sid-d09ec75d-0d6b-4def-9152-ffc23d42c206" targetRef="sid-0e9f1f2c-2e22-4ccb-8452-d70075d7e916" name="同意"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrPass}]]></conditionExpression></sequenceFlow><sequenceFlow id="sid-0f7d04bd-703b-424e-b3c9-d5068471a2a1" sourceRef="sid-0e9f1f2c-2e22-4ccb-8452-d70075d7e916" targetRef="sid-a8e23c5a-8ca2-41fe-8fd1-1c6f5ea72b37"/></process><bpmndi:BPMNDiagram id="BPMNDiagram_overtime"><bpmndi:BPMNPlane bpmnElement="overtime" id="BPMNPlane_overtime"><bpmndi:BPMNShape id="shape-0a378108-a067-4c18-80ef-2a66be33004b" bpmnElement="sid-44149b62-6b70-4150-8340-89d915c60046"><omgdc:Bounds x="-347.48718" y="-32.0" width="30.0" height="30.0"/></bpmndi:BPMNShape><bpmndi:BPMNShape id="shape-34fa08de-0f39-46ff-8f2b-1c178a09e014" bpmnElement="sid-09325abe-9494-46ab-9e03-cf4483a70c28"><omgdc:Bounds x="-256.3096" y="-57.0" width="100.0" height="80.0"/></bpmndi:BPMNShape><bpmndi:BPMNEdge id="edge-fa710db2-6f5b-4fae-aa83-4803c731e53b" bpmnElement="sid-8198060f-610c-4abb-9256-cc1ef7f08a0b"><omgdi:waypoint x="-317.48718" y="-17.0"/><omgdi:waypoint x="-256.3096" y="-17.0"/></bpmndi:BPMNEdge><bpmndi:BPMNShape id="shape-2dbc7c0a-7239-4881-8f36-b29ba7f58a55" bpmnElement="sid-8bdc7d37-85b5-48c7-a6e8-72fb1faf34d6"><omgdc:Bounds x="-100.81601" y="-37.0" width="40.0" height="40.0"/></bpmndi:BPMNShape><bpmndi:BPMNEdge id="edge-99d94a01-654f-4464-9ef6-99dcdfedad9e" bpmnElement="sid-2e71f5ae-e987-476a-ae54-87a4c192eb65"><omgdi:waypoint x="-156.3096" y="-17.0"/><omgdi:waypoint x="-130.81601" y="-17.0"/><omgdi:waypoint x="-130.81601" y="-17.0"/><omgdi:waypoint x="-100.81601" y="-17.000002"/></bpmndi:BPMNEdge><bpmndi:BPMNShape id="shape-d5e7f930-d919-488a-85b4-f3ae7b1d03a7" bpmnElement="sid-7584bcec-5f4b-49d0-a431-0bbb1e32128e"><omgdc:Bounds x="-130.81601" y="65.104866" width="100.0" height="80.0"/></bpmndi:BPMNShape><bpmndi:BPMNShape id="shape-a46040af-15a0-4b24-9b3d-12654cd43ee9" bpmnElement="sid-d1248bf0-33d2-4f70-bd6a-fccb816d192b"><omgdc:Bounds x="-8.434828" y="-57.0" width="100.0" height="80.0"/></bpmndi:BPMNShape><bpmndi:BPMNShape id="shape-4b526101-8378-4716-af5e-20f03d84d240" bpmnElement="sid-55d28295-3ad0-45a2-b90d-3594c81a5b43"><omgdc:Bounds x="-100.81601" y="190.64401" width="40.0" height="40.0"/></bpmndi:BPMNShape><bpmndi:BPMNEdge id="edge-15b9f9e2-b5d9-44d1-8e97-430fc23b8a90" bpmnElement="sid-816b4e26-95e9-4d03-80a3-79882efc0b3c"><omgdi:waypoint x="-80.81601" y="145.10487"/><omgdi:waypoint x="-80.81601" y="190.64401"/></bpmndi:BPMNEdge><bpmndi:BPMNShape id="shape-f3ebc8d0-f12f-4975-bc91-b29ea7053076" bpmnElement="sid-a8e23c5a-8ca2-41fe-8fd1-1c6f5ea72b37"><omgdc:Bounds x="303.155" y="195.644" width="30.0" height="30.0"/></bpmndi:BPMNShape><bpmndi:BPMNShape id="shape-f5c350bb-1c21-4dec-b934-731de679a6e6" bpmnElement="sid-d09ec75d-0d6b-4def-9152-ffc23d42c206"><omgdc:Bounds x="159.75972" y="-37.0" width="40.0" height="40.0"/></bpmndi:BPMNShape><bpmndi:BPMNEdge id="edge-ed4f77cf-f186-4928-bfab-6307460049a9" bpmnElement="sid-0173be85-fcd6-40fe-8bdb-8d589e383532"><omgdi:waypoint x="91.56517" y="-17.0"/><omgdi:waypoint x="159.75972" y="-17.0"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="edge-3b00c46b-8d1a-4169-9a17-d3b1927d46ee" bpmnElement="sid-2c40f63c-832a-4bdc-9326-09327f697c52"><omgdi:waypoint x="-80.81601" y="3.0"/><omgdi:waypoint x="-80.81601" y="65.104866"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="edge-e1efb223-0c01-4c1e-8469-ae2e1346b4fb" bpmnElement="sid-c948563c-8965-4c6c-bf31-6374a0185374"><omgdi:waypoint x="-60.81601" y="-17.0"/><omgdi:waypoint x="-8.43483" y="-17.0"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="edge-7957c22d-4c7c-4152-93fd-ebe7d47ab473" bpmnElement="sid-0932d9fe-e117-4aba-8297-afd5eca5bd3c"><omgdi:waypoint x="-60.81601" y="210.64401"/><omgdi:waypoint x="303.155" y="210.644"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="edge-0ad4e001-f310-43c4-9d4a-168e0edd69b3" bpmnElement="sid-5c319add-6d76-42ec-98e2-ed40a2614c54"><omgdi:waypoint x="179.75972" y="3.0"/><omgdi:waypoint x="179.75974" y="54.81092"/><omgdi:waypoint x="179.75974" y="105.10486"/><omgdi:waypoint x="-30.816011" y="105.10487"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="edge-0e958a63-0aaf-4438-a655-b4be18f6ae83" bpmnElement="sid-92a890d9-889a-4782-b8e4-9ccf00c3a594"><omgdi:waypoint x="-100.81602" y="210.64401"/><omgdi:waypoint x="-148.5628" y="210.64401"/><omgdi:waypoint x="-206.30959" y="210.64401"/><omgdi:waypoint x="-206.30959" y="23.0"/></bpmndi:BPMNEdge><bpmndi:BPMNShape id="shape-28b2c212-cddf-480d-bb67-9d296bf7112b" bpmnElement="sid-0e9f1f2c-2e22-4ccb-8452-d70075d7e916"><omgdc:Bounds x="268.15497" y="-57.0" width="100.0" height="80.0"/></bpmndi:BPMNShape><bpmndi:BPMNEdge id="edge-19d7ae2e-7ad2-48c0-9ba6-884d9b56135f" bpmnElement="sid-8f45254a-6b30-43e1-bfde-8ad56685810d"><omgdi:waypoint x="199.75972" y="-17.0"/><omgdi:waypoint x="268.15497" y="-17.0"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="edge-a894eebb-9801-4535-8713-b5eafac433a7" bpmnElement="sid-0f7d04bd-703b-424e-b3c9-d5068471a2a1"><omgdi:waypoint x="318.15497" y="23.0"/><omgdi:waypoint x="318.155" y="195.644"/></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

这篇关于SpringBoot整合Activiti7——实战之加班流程(驳回)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/882488

相关文章

Java实现检查多个时间段是否有重合

《Java实现检查多个时间段是否有重合》这篇文章主要为大家详细介绍了如何使用Java实现检查多个时间段是否有重合,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录流程概述步骤详解China编程步骤1:定义时间段类步骤2:添加时间段步骤3:检查时间段是否有重合步骤4:输出结果示例代码结语作

Java中String字符串使用避坑指南

《Java中String字符串使用避坑指南》Java中的String字符串是我们日常编程中用得最多的类之一,看似简单的String使用,却隐藏着不少“坑”,如果不注意,可能会导致性能问题、意外的错误容... 目录8个避坑点如下:1. 字符串的不可变性:每次修改都创建新对象2. 使用 == 比较字符串,陷阱满

Java判断多个时间段是否重合的方法小结

《Java判断多个时间段是否重合的方法小结》这篇文章主要为大家详细介绍了Java中判断多个时间段是否重合的方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录判断多个时间段是否有间隔判断时间段集合是否与某时间段重合判断多个时间段是否有间隔实体类内容public class D

IDEA编译报错“java: 常量字符串过长”的原因及解决方法

《IDEA编译报错“java:常量字符串过长”的原因及解决方法》今天在开发过程中,由于尝试将一个文件的Base64字符串设置为常量,结果导致IDEA编译的时候出现了如下报错java:常量字符串过长,... 目录一、问题描述二、问题原因2.1 理论角度2.2 源码角度三、解决方案解决方案①:StringBui

Java覆盖第三方jar包中的某一个类的实现方法

《Java覆盖第三方jar包中的某一个类的实现方法》在我们日常的开发中,经常需要使用第三方的jar包,有时候我们会发现第三方的jar包中的某一个类有问题,或者我们需要定制化修改其中的逻辑,那么应该如何... 目录一、需求描述二、示例描述三、操作步骤四、验证结果五、实现原理一、需求描述需求描述如下:需要在

Java中ArrayList和LinkedList有什么区别举例详解

《Java中ArrayList和LinkedList有什么区别举例详解》:本文主要介绍Java中ArrayList和LinkedList区别的相关资料,包括数据结构特性、核心操作性能、内存与GC影... 目录一、底层数据结构二、核心操作性能对比三、内存与 GC 影响四、扩容机制五、线程安全与并发方案六、工程

JavaScript中的reduce方法执行过程、使用场景及进阶用法

《JavaScript中的reduce方法执行过程、使用场景及进阶用法》:本文主要介绍JavaScript中的reduce方法执行过程、使用场景及进阶用法的相关资料,reduce是JavaScri... 目录1. 什么是reduce2. reduce语法2.1 语法2.2 参数说明3. reduce执行过程

如何使用Java实现请求deepseek

《如何使用Java实现请求deepseek》这篇文章主要为大家详细介绍了如何使用Java实现请求deepseek功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1.deepseek的api创建2.Java实现请求deepseek2.1 pom文件2.2 json转化文件2.2

Java调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.

Spring AI集成DeepSeek的详细步骤

《SpringAI集成DeepSeek的详细步骤》DeepSeek作为一款卓越的国产AI模型,越来越多的公司考虑在自己的应用中集成,对于Java应用来说,我们可以借助SpringAI集成DeepSe... 目录DeepSeek 介绍Spring AI 是什么?1、环境准备2、构建项目2.1、pom依赖2.2