浏览 7329 次
锁定老帖子 主题:jBPM4.3 历史查询
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-01-28
最后修改:2010-01-28
一种方法是通过jBPM HistoryService历史服务进行操作(参照用户手册5.8. HistoryService历史服务), 另一种方法是自己编写HQL语句实现历史表的查询。 2.自己设计历史记录表,在需要记录的节点使用event-listener进行监听,实现记录。 这里以经典的请假为例子。请假成功,人事可以入库查询。具体流程如下图所示 leaveListener是一个事件监听,配置在app-service.xml中,方便leave.jpdl.xml进行调用 <bean id="leaveListener" class="com.javaeye.oa.web.listener.LeaveListener" > <property name="leaveService" ref="leaveService"/> </bean> <bean id="leaveService" class="com.javaeye.oa.service.task.impl.LeaveServiceImpl"> </bean> <?xml version="1.0" encoding="UTF-8"?> <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测试时候使用,实际应用中可以删除 当经理批准申请或老板批准申请的时候,事件响应,进行请假申请入库。 package com.javaeye.oa.web.listener; import org.jbpm.api.listener.EventListener; import org.jbpm.api.listener.EventListenerExecution; import com.javaeye.oa.entity.task.Leave; import com.javaeye.oa.service.task.LeaveService; public class LeaveListener implements EventListener { private static final long serialVersionUID = 7098294717133900660L; private String endMsg;//endMsg测试时候使用,实际应用中可以删除 private LeaveService leaveService; public void setEndMsg(String endMsg) { this.endMsg = endMsg; } //leaveService进行set注入 public void setLeaveService(LeaveService leaveService) { this.leaveService = leaveService; } public void notify(EventListenerExecution execution) throws Exception { System.out.println("==============leaveListener:endMsg="+endMsg); String applyName = (String) execution.getVariable("applyName"); String leaveDay = (String) execution.getVariable("leaveDay"); String applyTime = (String) execution.getVariable("applyTime"); String position = (String) execution.getVariable("position"); String content = (String) execution.getVariable("content"); String approvingOfficer = (String) execution.getVariable("approvingOfficer"); Leave leave = new Leave(); leave.setApplyName(applyName); leave.setApplyTime(applyTime); leave.setApprovingOfficer(approvingOfficer); leave.setContent(content); leave.setPosition(position); leave.setLeaveDay(leaveDay); leaveService.addLeave(leave); } } package com.javaeye.oa.entity.task; public class Leave implements java.io.Serializable { private static final long serialVersionUID = -3289821345085237147L; private Long id; private String applyName; private String leaveDay; private String position; private String applyTime; private String content; private String approvingOfficer; // Constructors /** default constructor */ public Leave() { } ... 当一切就绪,我们便开始进行实际操作。 一。员工dylan点击请假链接 public String leave() { Map<String, Object> variables = new HashMap<String, Object>(); //applyName对应leave.jpdl.xml中相应变量,这里applyName为dylan variables.put("applyName", "dylan"); ExecutionService executionService = processEngine.getExecutionService(); ProcessInstance processInstance = executionService.startProcessInstanceByKey("leave",variables); if (processInstance.isActive("填写请假单")) { url = "apply"; } return url; } 二。dylan在请假页面填写请假申请单 <%@page contentType="text/html;charset=UTF-8" %> <!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填写完成,提交请假单 public String apply() { 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天,职位为员工,直接经理进行审批,审批通过,即入库 public String confirm() { 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; } 入库之后,人事即可对请假情况进行查看考核=。= 本文在family168的请假例子上进行简单修改,基于SSH+jBPM4.3,实现自定义历史表查询。 关于历史事件中,variable的具体情况可参考 http://www.family168.com/jbpm4/history.html http://phoenix-clt.iteye.com/blog/426714 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |