1. 画出流程图

使用之前安装的Eclipse的流程设计器,画出如下流程图:

1.1 设置开始节点


在properties中选中Main config;设置如下:

然后选中Form,设置如下:

具体操作方式是:点击右边New,
设置请假开始日期:

设置请假结束日期:

设置请假原因:

开始节点对应的XML代码:

 <startEvent id="startevent" name="开始" activiti:initiator="applUserId"><extensionElements><activiti:formProperty id="startDate" name="请假开始日期" type="date" datePattern="yyy-MM-dd" required="true"></activiti:formProperty><activiti:formProperty id="endDate" name="请假结束日期" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty><activiti:formProperty id="reason" name="请假原因" type="string" required="true"></activiti:formProperty></extensionElements></startEvent>

1.2 设置部门领导审批任务

具体操作如下:

在properties中选中General;设置如下:

选中Main config;设置如下:

选中Form设置如下:

具体设置如下:
设置请假开始日期:

设置请假结束日期:

设置请假原因:

设置审核意见:

审核节点对应XML代码如下:

    <userTask id="deptLeaderAudit" name="部门领导审批" activiti:assignee="wangwu"><extensionElements><activiti:formProperty id="startDate" name="请假开始日期" type="date" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty><activiti:formProperty id="endDate" name="请假结束日期" type="date" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty><activiti:formProperty id="reason" name="请假原因" type="string" writable="false"></activiti:formProperty><activiti:formProperty id="deptLeaderApprove" name="审核意见" type="enum" required="true"><activiti:value id="true" name="同意"></activiti:value><activiti:value id="false" name="不同意"></activiti:value></activiti:formProperty></extensionElements></userTask>

需要注意的是Eclipse的流程设计器页面上没有Value属性的设置,所以只能在XML中进行修改配置:

    <userTask id="deptLeaderAudit" name="部门领导审批" activiti:assignee="wangwu"><extensionElements><activiti:formProperty id="startDate" name="请假开始日期" type="date" value="${startDate}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty><activiti:formProperty id="endDate" name="请假结束日期" type="date" value="${endDate}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty><activiti:formProperty id="reason" name="请假原因" type="string" value="${reason}" writable="false"></activiti:formProperty><activiti:formProperty id="deptLeaderApprove" name="审核意见" type="enum" required="true"><activiti:value id="true" name="同意"></activiti:value><activiti:value id="false" name="不同意"></activiti:value></activiti:formProperty></extensionElements></userTask>

1.3 设置排他网关流出连线的设置

选中一条连线(同意)设置如下:

设置Main Config如下:

设置不同意连线如下:

调整申请任务节点和部门经理审核节点类似。

点击流程图空处,设置如下:

完整流程图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/test"><process id="LeaveProcess" name="LeaveProcess" isExecutable="true"><startEvent id="startevent" name="开始" activiti:initiator="applUserId"><extensionElements><activiti:formProperty id="startDate" name="请假开始日期" type="date" datePattern="yyy-MM-dd" required="true"></activiti:formProperty><activiti:formProperty id="endDate" name="请假结束日期" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty><activiti:formProperty id="reason" name="请假原因" type="string" required="true"></activiti:formProperty></extensionElements></startEvent><userTask id="deptLeaderAudit" name="部门领导审批" activiti:assignee="wangwu"><extensionElements><activiti:formProperty id="startDate" name="请假开始日期" type="date" value="${startDate}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty><activiti:formProperty id="endDate" name="请假结束日期" type="date" value="${endDate}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty><activiti:formProperty id="reason" name="请假原因" type="string" value="${reason}" writable="false"></activiti:formProperty><activiti:formProperty id="deptLeaderApprove" name="审核意见" type="enum" required="true"><activiti:value id="true" name="同意"></activiti:value><activiti:value id="false" name="不同意"></activiti:value></activiti:formProperty></extensionElements></userTask><endEvent id="endevent" name="结束"></endEvent><sequenceFlow id="flow1" sourceRef="startevent" targetRef="deptLeaderAudit"></sequenceFlow><exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway><sequenceFlow id="flow2" sourceRef="deptLeaderAudit" targetRef="exclusivegateway1"></sequenceFlow><sequenceFlow id="flow3" name="同意" sourceRef="exclusivegateway1" targetRef="endevent"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${deptLeaderApprove=='true'}]]></conditionExpression></sequenceFlow><userTask id="modifyAppl" name="调整申请" activiti:assignee="${applUserId}"><extensionElements><activiti:formProperty id="startDate" name="请假开始日期" type="date" value="${startDate}" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty><activiti:formProperty id="endDate" name="请假结束日期" type="date" value="${endDate}" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty><activiti:formProperty id="reason" name="请假原因" type="string" value="${reason}" required="true"></activiti:formProperty><activiti:formProperty id="reAppl" name="重新申请" type="enum" required="true"><activiti:value id="true" name="重新申请"></activiti:value><activiti:value id="false" name="取消申请"></activiti:value></activiti:formProperty></extensionElements></userTask><sequenceFlow id="flow4" name="不同意" sourceRef="exclusivegateway1" targetRef="modifyAppl"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${deptLeaderApprove=='false'}]]></conditionExpression></sequenceFlow><exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway><sequenceFlow id="flow5" sourceRef="modifyAppl" targetRef="exclusivegateway2"></sequenceFlow><sequenceFlow id="flow6" name="取消申请" sourceRef="exclusivegateway2" targetRef="endevent"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${reAppl=='false'}]]></conditionExpression></sequenceFlow><sequenceFlow id="flow7" name="重新申请" sourceRef="exclusivegateway2" targetRef="deptLeaderAudit"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${reAppl=='true'}]]></conditionExpression></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_LeaveProcess"><bpmndi:BPMNPlane bpmnElement="LeaveProcess" id="BPMNPlane_LeaveProcess"><bpmndi:BPMNShape bpmnElement="startevent" id="BPMNShape_startevent"><omgdc:Bounds height="35.0" width="35.0" x="215.0" y="41.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="deptLeaderAudit" id="BPMNShape_deptLeaderAudit"><omgdc:Bounds height="55.0" width="105.0" x="180.0" y="130.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="endevent" id="BPMNShape_endevent"><omgdc:Bounds height="35.0" width="35.0" x="217.0" y="370.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1"><omgdc:Bounds height="40.0" width="40.0" x="214.0" y="250.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="modifyAppl" id="BPMNShape_modifyAppl"><omgdc:Bounds height="55.0" width="105.0" x="350.0" y="243.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2"><omgdc:Bounds height="40.0" width="40.0" x="550.0" y="250.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"><omgdi:waypoint x="232.0" y="76.0"></omgdi:waypoint><omgdi:waypoint x="232.0" y="130.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"><omgdi:waypoint x="232.0" y="185.0"></omgdi:waypoint><omgdi:waypoint x="234.0" y="250.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"><omgdi:waypoint x="234.0" y="290.0"></omgdi:waypoint><omgdi:waypoint x="234.0" y="370.0"></omgdi:waypoint><bpmndi:BPMNLabel><omgdc:Bounds height="14.0" width="24.0" x="241.0" y="320.0"></omgdc:Bounds></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4"><omgdi:waypoint x="254.0" y="270.0"></omgdi:waypoint><omgdi:waypoint x="350.0" y="270.0"></omgdi:waypoint><bpmndi:BPMNLabel><omgdc:Bounds height="14.0" width="36.0" x="269.0" y="278.0"></omgdc:Bounds></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5"><omgdi:waypoint x="455.0" y="270.0"></omgdi:waypoint><omgdi:waypoint x="550.0" y="270.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6"><omgdi:waypoint x="570.0" y="290.0"></omgdi:waypoint><omgdi:waypoint x="570.0" y="387.0"></omgdi:waypoint><omgdi:waypoint x="252.0" y="387.0"></omgdi:waypoint><bpmndi:BPMNLabel><omgdc:Bounds height="14.0" width="48.0" x="580.0" y="332.0"></omgdc:Bounds></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7"><omgdi:waypoint x="570.0" y="250.0"></omgdi:waypoint><omgdi:waypoint x="569.0" y="157.0"></omgdi:waypoint><omgdi:waypoint x="285.0" y="157.0"></omgdi:waypoint><bpmndi:BPMNLabel><omgdc:Bounds height="14.0" width="48.0" x="581.0" y="211.0"></omgdc:Bounds></bpmndi:BPMNLabel></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

2. 测试流程

2.1 部署流程图

流程图所在的目录如下:

部署流程图代码如下:

package com.activiti;import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import org.activiti.engine.FormService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.form.FormProperty;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;public class LeaveTest {ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();/**部署流程定义*/  @Test  public void deploymentProcessDefinition(){  RepositoryService repositoryService = processEngine.getRepositoryService();  DeploymentBuilder deploymentBuilder=repositoryService.createDeployment(); deploymentBuilder.name("请假流程");deploymentBuilder.addClasspathResource("diagrams/LeaveProcess.bpmn");deploymentBuilder.addClasspathResource("diagrams/LeaveProcess.png");Deployment deployment = deploymentBuilder.deploy();//打印我们的流程信息  System.out.println("流程Id:"+deployment.getId());  System.out.println("流程Name:"+deployment.getName());  System.out.println("——————————————————————————————————————————————————"); }
}

测试结果如下:

流程Id:1
流程Name:请假流程
——————————————————————————————————————————————————

2.2 启动流程图

    /**启动流程引擎*/  @Test  public void startProcessInstance(){RepositoryService repositoryService = processEngine.getRepositoryService();  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("LeaveProcess").singleResult();//设置动态表单processEngine.getIdentityService().setAuthenticatedUserId("zhaoliu");Map<String , String > params = new HashMap<String , String  >();SimpleDateFormat  sdt  = new SimpleDateFormat("yyyy-MM-dd");Calendar calendar = Calendar.getInstance();String startDate = sdt.format(calendar.getTime());calendar.add(Calendar.DAY_OF_MONTH, 2);String endDate = sdt.format(calendar.getTime());params.put("startDate", startDate);params.put("endDate", endDate);params.put("reason", "我要休息");FormService formService = processEngine.getFormService();ProcessInstance processInstance = formService.submitStartFormData(processDefinition.getId(), params);System.out.println("流程实例ID:"+processInstance.getId());  System.out.println("流程定义ID:"+processInstance.getProcessDefinitionId());System.out.println("——————————————————————————————————————————————————"); } 

测试结果如下:

流程实例ID:2501
流程定义ID:LeaveProcess:1:4
——————————————————————————————————————————————————

2.3 部门经理审核

审核通过: params.put(“deptLeaderApprove”, “true”);
审核拒绝: params.put(“deptLeaderApprove”, “false”);

 /**部门领导审批通过**/ @Test  public void deptLeaderAuditPass(){  String assignee="wangwu";  FormService formService = processEngine.getFormService();TaskService taskService = processEngine.getTaskService();  Task deptLeaderTask = taskService.createTaskQuery().taskAssignee(assignee).singleResult(); //打印请假人提交的表单信息List<FormProperty> formProperties = formService.getTaskFormData(deptLeaderTask.getId()).getFormProperties();for (FormProperty formProperty : formProperties) {if(!"enum".equals(formProperty.getType().getName())) {System.out.println(  " id : " + formProperty.getId() +" | name : "+ formProperty.getName() +"| value : "+ formProperty.getValue());}}//审核通过Map<String , String > params = new HashMap<String , String  >();params.put("deptLeaderApprove", "true");formService.submitTaskFormData(deptLeaderTask.getId(), params);System.out.println("部门经理审核通过");boolean isFlag = isEnded(deptLeaderTask.getProcessInstanceId());if(isFlag) {System.out.println("流程结束");System.out.println("——————————————————————————————————————————————————"); }}  public boolean isEnded(String processInstanceId) {RuntimeService runtimeService = processEngine.getRuntimeService();ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();if(processInstance == null){return true;}else{return false;}}

测试结果如下:

 id : startDate | name : 请假开始日期| value : 2018-06-07id : endDate | name : 请假结束日期| value : 2018-06-09id : reason | name : 请假原因| value : 我要休息
部门经理审核通过
流程结束
——————————————————————————————————————————————————

调整申请代码与审核代码类似。

代码下载:请假流程代码

【Activiti工作流】5. 简单请假流程相关推荐

  1. 初识flowable工作流-实现简单请假流程SpringBoot+VUE

    一.前言 大家好,因为目前手里需要用到flowable工作流,之前没有接触过,所以在这里记录一下学习的进度,开始后台使用SpringCloud分布式框架和前端Vue框架实现一个简单的请假流程. 二.代 ...

  2. Activiti(二)简单请假流程实现

    在SpringBoot2集成Activiti6的环境中,实现简单的请假流程.编写请假业务流程.流程业务为: 1,员工请假,先创建请假流程 2,员工填写请假申请,也可以不填写,直接结束流程 3,提交给直 ...

  3. (六)Activiti之实现学生请假流程

    Activiti之第一个程序以及Activiti插件的使用和Activiti表的解释 目录 概 述 流程定义ZIp部署:`在这里插入代码片` 相关流程如下: 分析: 小结: 参考资料和推荐阅读 LD ...

  4. activiti+testng批量测试用例-请假流程

    介绍 本文以请假流程为例,演示一个activiti流程的流转.从而熟悉activiti核心的api调用 请假流程定义 待测试的流程路径 流程定义xml <?xml version="1 ...

  5. flowable工作流简单请假流程,自定义完成的流程图表颜色字体以及连接线的颜色字体。

    效果图 代码 1.bpmn文件ExpenseProcess.bpmn20.xml(通过可视化工具生成[非常熟悉也可以手动编写]) <?xml version="1.0" en ...

  6. Activiti工作流(三)——流程变量

    流程变量可以是流程中一系列参数,比如办理人(Assignee),消息(message)等.这些流程变量使得activiti能够应用于更为复杂的业务中,使得流程变得更加灵活可控. 场景(一) 图一:没有 ...

  7. Activiti工作流的简单介绍

    1.概念 工作流(Workflow)就是"业务过程的部分或整体在计算机应用环境下的自动化",它主要解决的是"使在多个参与者之间按照某种预定义的规则传递文档.信息 或任务的 ...

  8. activiti工作流项目中显示流程进度(流程图高亮显示)

    1.flowList.jsp页面使用img标签,processInstanceId为后台传来的值 <img src="testController.do?queryProPlan&am ...

  9. Activiti 工作流引擎 springmvc SSM 流程审批 后台框架 源码 shiro权

    工作流模块----------------------------------------------------------------------------------------------- ...

最新文章

  1. 解决oracle11g安装导致数据库无法自动搜集统计信息-转
  2. 一个Java对象到底有多大?
  3. python编码规范utf8还是gbk还是ask_彻底搞懂 Python 编码
  4. 最具戏剧性的分析诊断案例——十分钟锁定数据库性能“元凶”
  5. 嵌入式Linux入门4:版本控制git的使用
  6. MATLAB 2017a 中文破解版安装教程
  7. 问题解决之——未知usb设备设备描述符请求失败(Jlink驱动)
  8. 安装Pillow指定版本出错
  9. 下拉框 切换一个下拉框 另一个下拉框做相应的改变
  10. 计算机屏幕的显示分辨率与什么有关,计算机屏幕分辨率高低主要跟什么有关?...
  11. 【win10专业版】win10系统下Office2013无法激活的解决方法
  12. 2022 互联网中秋月饼大赏,腾讯送火腿,字节寓意圆满,你最钟爱哪款呢?(文末有抽奖)...
  13. 国标GB28181安防摄像头如何通过视频流媒体服务器建设阳光考场?
  14. .Net Framework 0x800b0109 -已处理证书链,但是在不受信任提供程序信任的根证书中终止。
  15. 静态路由的配置,实现全网可达
  16. oracle begin exception end,Oracle Exception异常处理
  17. 美国俚语:down-to-earth踏实谦逊
  18. 主题:Django资源大全
  19. 现实迷途 第二十六章 陷入情网
  20. Android文件格式

热门文章

  1. 五子棋游戏程序记录和复盘功能设置
  2. 计算机与机器人论文参考文献,机器人论文参考文献(2016年10月21日)
  3. nginx配置文件及说明
  4. 矩阵分析:Kronecker积,Hadamard积
  5. Battery_MSCCC:基于MATLAB/Simulink的具有多级(5级)恒流控制的电池充放电仿真模型
  6. SqlServer 汉字转换拼音首字母函数
  7. uniapp获取当前的地理位置
  8. [Solved] Pycharm 提示Unresolved reference
  9. Oracle提取中文字符串拼音首字母函数
  10. CVE-2018-6794一把梭