打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
任务历史查询
1.分析几张历史表,查询某用户涉及的所有已办流程实例列表,通过对每个流程实例进行分析。
一种方法是通过jBPM HistoryService历史服务进行操作(参照用户手册5.8. HistoryService历史服务),
另一种方法是自己编写HQL语句实现历史表的查询。

2.自己设计历史记录表,在需要记录的节点使用event-listener进行监听,实现记录。

这里以经典的请假为例子。请假成功,人事可以入库查询。具体流程如下图所示
 
leaveListener是一个事件监听,配置在app-service.xml中,方便leave.jpdl.xml进行调用
App-service.xml代码
  1. <bean id="leaveListener" class="com.javaeye.oa.web.listener.LeaveListener" >   
  2.         <property name="leaveService" ref="leaveService"/>   
  3. </bean>   
  4. <bean id="leaveService" class="com.javaeye.oa.service.task.impl.LeaveServiceImpl">   
  5. </bean>  
Leave.jpdl.xml代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2.   
  3. <process name="leave" xmlns="http://jbpm.org/4.3/jpdl">   
  •    <start g="201,14,48,48" name="开始">   
  •       <transition g="-42,-10" name="请假" to="填写请假单"/>   
  •    </start>   
  •    <task assignee="#{applyName}" g="178,87,92,52" name="填写请假单">   
  •       <transition g="-97,2" name="判断是不是经理" to="是不是经理"/>   
  •    </task>   
  •    <decision expr="#{manager}" g="204,158,48,48" name="是不是经理">   
  •       <transition g="-23,-11" name="否" to="经理审核"/>   
  •       <transition g="14,-11" name="是" to="老板审批"/>   
  •    </decision>   
  •    <task assignee="#{approvingOfficer}" g="103,252,92,52" name="经理审核">   
  •       <transition g="150,450:10,-21" name="经理批准" to="结束">   
  •             <event-listener expr="#{leaveListener}">   
  •                 <field name="endMsg">   
  •                     <string value="批准请假,人事入库" />   
  •                 </field>   
  •             </event-listener>   
  •       </transition>   
  •       <transition g="-22,-22" name="请假天数>3" to="老板审批"/>   
  •       <transition g="-61,-1" name="经理不批准" to="终止"/>   
  •       <transition g="149,114:-55,82" name="经理驳回" to="填写请假单"/>   
  •    </task>   
  •    <task assignee="#{approvingOfficer}" g="278,251,92,52" name="老板审批">   
  •       <transition g="326,450:-58,-24" name="老板批准" to="结束">   
  •             <event-listener expr="#{leaveListener}">   
  •                 <field name="endMsg">   
  •                     <string value="批准请假,人事入库" />   
  •                 </field>   
  •             </event-listener>   
  •       </transition>   
  •       <transition g="7,0" name="老板不批准" to="终止"/>   
  •       <transition g="323,114:13,61" name="老板驳回" to="填写请假单"/>   
  •    </task>   
  •    <end g="219,429,48,48" name="结束" state="confirm"/>   
  •    <end g="220,360,48,48" name="终止" state="dissent"/>   
  • </process>  

  • applyName、manager、approvingOfficer几个变量在实际操作中进行设置
    endMsg测试时候使用,实际应用中可以删除

    当经理批准申请或老板批准申请的时候,事件响应,进行请假申请入库。
    Leavelistener.java代码

    1. package com.javaeye.oa.web.listener;   
    2.   
    3. import org.jbpm.api.listener.EventListener;   
    4. import org.jbpm.api.listener.EventListenerExecution;   
    5.   
    6. import com.javaeye.oa.entity.task.Leave;   
    7. import com.javaeye.oa.service.task.LeaveService;   
    8.   
    9. public class LeaveListener implements EventListener {   
    10.   
    11.     private static final long serialVersionUID = 7098294717133900660L;   
    12.     private String endMsg;//endMsg测试时候使用,实际应用中可以删除   
    13.     private LeaveService leaveService;   
    14.        
    15.     public void setEndMsg(String endMsg) {   
    16.         this.endMsg = endMsg;   
    17.     }   
    18.     //leaveService进行set注入   
    19.     public void setLeaveService(LeaveService leaveService) {   
    20.         this.leaveService = leaveService;   
    21.     }   
    22.        
    23.     public void notify(EventListenerExecution execution) throws Exception {   
    24.   
    25.         System.out.println("==============leaveListener:endMsg="+endMsg);   
    26.         String applyName = (String) execution.getVariable("applyName");   
    27.         String leaveDay = (String) execution.getVariable("leaveDay");   
    28.         String applyTime = (String) execution.getVariable("applyTime");   
    29.         String position = (String) execution.getVariable("position");   
    30.         String content = (String) execution.getVariable("content");   
    31.         String approvingOfficer = (String) execution.getVariable("approvingOfficer");   
    32.            
    33.         Leave leave = new Leave();   
    34.         leave.setApplyName(applyName);   
    35.         leave.setApplyTime(applyTime);   
    36.         leave.setApprovingOfficer(approvingOfficer);   
    37.         leave.setContent(content);   
    38.         leave.setPosition(position);   
    39.         leave.setLeaveDay(leaveDay);   
    40.            
    41.         leaveService.addLeave(leave);   
    42.     }   
    43. }  

    Leave.java代码

    1. package com.javaeye.oa.entity.task;   
    2.   
    3. public class Leave implements java.io.Serializable {   
    4.   
    5.     private static final long serialVersionUID = -3289821345085237147L;   
    6.     private Long id;   
    7.     private String applyName;   
    8.     private String leaveDay;   
    9.     private String position;   
    10.     private String applyTime;   
    11.     private String content;   
    12.     private String approvingOfficer;   
    13.   
    14.     // Constructors   
    15.   
    16.     /** default constructor */   
    17.     public Leave() {   
    18.     }   
    19. ...  

    当一切就绪,我们便开始进行实际操作。
     
     
     
    --------------------------------------------------------------------------------------------------------
    一。员工dylan点击请假链接
    Java代码
    1. public String leave() {   
    2.   
    3.      Map<String, Object> variables = new HashMap<String, Object>();   
    4.      //applyName对应leave.jpdl.xml中相应变量,这里applyName为dylan   
    5.      variables.put("applyName""dylan");   
    6.      ExecutionService executionService = processEngine.getExecutionService();   
    7.      ProcessInstance processInstance = executionService.startProcessInstanceByKey("leave",variables);   
    8.            
    9.      if (processInstance.isActive("填写请假单")) {   
    10.          url = "apply";   
    11.      }   
    12.      return url;   
    13. }  

    二。dylan在请假页面填写请假申请单

    Apply.jsp代码
    1. <%@page contentType="text/html;charset=UTF-8" %>   
    2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
  • <html xmlns="http://www.w3.org/1999/xhtml">   
  •     <head>   
  •         <title>填写申请单</title>   
  •     </head>   
  •     <body>   
  •         <form action="apply.action" method="POST">   
  •           <table width="300" border=1>   
  •             <tr>   
  •               <td><label>申请人</label></td>   
  •               <td><input type="text" value="dylan" name="applyName"></td>   
  •             </tr>   
  •             <tr>   
  •               <td><label>职位</label></td>   
  •               <td><input type="text" value="员工" name="position"></td>   
  •             </tr>   
  •             <tr>   
  •               <td><label>申请时间</label></td>   
  •               <td><input type="text" value="2010-01-10" name="applyTime"></td>   
  •             </tr>   
  •             <tr>   
  •               <td><label>请假天数</label></td>   
  •               <td><input type="text" value="1" name="leaveDay"></td>   
  •             </tr>   
  •             <tr>   
  •               <td><label>请假原因</label></td>   
  •               <td><textarea name="content" rows=3 cols=200>病假</textarea></td>   
  •             </tr>   
  •             <tr>   
  •               <td><input type="submit" value="申请"></td>   
  •               <td><input type="reset" value="取消"></td>   
  •             </tr>   
  •           </table>   
  •         </form>   
  •     </body>   
  • </html>  
  • 三。dylan填写完成,提交请假单

    Java代码
    1. public String apply() {   
    2.         Map<String,Object> variables = new HashMap<String,Object>();   
  •     String applyName = getRequest().getParameter("applyName");   
  •     String applyTime = getRequest().getParameter("applyTime");   
  •     String leaveDay = getRequest().getParameter("leaveDay");   
  •     String content = getRequest().getParameter("content");   
  •     String position = getRequest().getParameter("position");   
  •   
  •     variables.put("applyName", applyName);   
  •     variables.put("applyTime", applyTime);   
  •     variables.put("leaveDay", leaveDay);   
  •     variables.put("content", content);   
  •     variables.put("position", position);   
  •     if (position.trim().equals("经理")) {   
  •         variables.put("manager""是");   
  •                 variables.put("approvingOfficer""S老板");   
  •     } else {   
  •         variables.put("manager""否");   
  •                 variables.put("approvingOfficer""T经理");   
  •     }   
  •         TaskService taskService = processEngine.getTaskService();   
  •         //dylan即请假启动的时候applyName的值   
  •     taskList = taskService.findPersonalTasks("dylan");   
  •     task = taskList.get(0);   
  •     taskService.setVariables(task.getId(), variables);   
  •     taskService.completeTask(task.getId());   
  •         return SUCCESS;   
  • }  
  •  四。请假1天,职位为员工,直接经理进行审批,审批通过,即入库
    Java代码
    1. public String confirm() {   
    2.         Map<String, Object> variables = new HashMap<String, Object>();   
  •         TaskService taskService = processEngine.getTaskService();   
  •         ExecutionService executionService = processEngine   
  •         .getExecutionService();   
  •         task = taskService.getTask(taskId);   
  •         execution = executionService.findExecutionById(task.getExecutionId());   
  •         if (execution.getProcessInstance().isActive("老板审批")) {   
  •             //approvingOfficer如果已存在值,则把之前值覆盖   
  •             variables.put("approvingOfficer""S老板");   
  •         taskService.completeTask(taskId, "老板批准");   
  •     } else if (execution.getProcessInstance().isActive("经理审核")) {   
  •     String variable = (String) taskService.getVariable(taskId, "leaveDay");   
  •          if (Integer.valueOf(variable) > 3) {   
  •             taskService.completeTask(taskId, "请假天数>3");   
  •          } else {   
  •         taskService.completeTask(taskId, "经理批准");   
  •              }   
  •     }   
  •         return SUCCESS;   
  • }  

  • 入库之后,人事即可对请假情况进行查看考核=。=

     
    本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
    打开APP,阅读全文并永久保存 查看更多类似文章
    猜你喜欢
    类似文章
    【热】打开小程序,算一算2024你的财运
    Activiti流程变量
    CAS自定义客户端登录界面
    jbpm - jPDL
    工作流学习---Activiti流程变量五步曲
    SpringBoot整合Flowable快速实现工作流,so easy!
    史上最全的工作流引擎 Activiti 进阶学习教程(值得收藏)
    更多类似文章 >>
    生活服务
    热点新闻
    分享 收藏 导长图 关注 下载文章
    绑定账号成功
    后续可登录账号畅享VIP特权!
    如果VIP功能使用有故障,
    可点击这里联系客服!

    联系客服