1、流程定義內(nèi)容為:
<?xml version="1.0" encoding="UTF-8"?> <process name="leave" xmlns="http:///4.3/jpdl"> <start g="196,25,48,48" name="start1"> <transition to="申請"/> </start> <task form="qhrequest.jsp" g="172,118,92,52" name="申請" candidate-groups="#{dev}"> //*****candidate-groups="#{dev}" 采用JBPM用戶組進行處理任務 //*****assignee="manager" 采用指定manager用戶進行處理任務 <transition to="經(jīng)理審批"/> </task> <task assignee="manager" form="qhmanager.jsp" g="175,217,92,52" name="經(jīng)理審批"> <transition g="-32,-8" name="批準" to="exclusive1"/> <transition g="128,221;124,165:-42,-18" name="駁回" to="申請"/> </task> <decision expr="#{day > 3 ? '老板審批' : '結(jié)束'}" g="200,308,48,48" name="exclusive1"> <transition g="-39,-10" name="結(jié)束" to="end1"/> <transition g="339,342:-71,-17" name="老板審批" to="老板審批"/> </decision> <task assignee="boss" form="qhboss.jsp" g="294,375,92,52" name="老板審批"> <transition g="339,457:" to="end1"/> </task> <end g="199,445,48,48" name="end1"/> </process> 2、qhlogin.jsp: HttpSession session = request.getSession(); session.setAttribute("username", request.getParameter("username")); response.sendRedirect("qhindex.jsp"); 登錄頁面,,驗證用戶登錄,,登錄成功返回qhindex.jsp 3、qhindex.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"%> <%@page import="java.util.*,org.jbpm.api.*,org.jbpm.api.task.*" %> <% ProcessEngine processEngine = Configuration.getProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); ExecutionService executionService = processEngine.getExecutionService(); TaskService taskService = processEngine.getTaskService(); String username = (String) session.getAttribute("username"); List<ProcessDefinition> pdList = repositoryService.createProcessDefinitionQuery().list(); List<ProcessInstance> piList = executionService.createProcessInstanceQuery().list(); //***指對指定用戶處理任務列表 List<Task> taskList = taskService.findPersonalTasks(username); //***指對指定用戶組處理任務列表 List<Task> groupTaskList = taskService.findGroupTasks(username); %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www./TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>index</title> </head> <body> <a href="qhdeploy.jsp">發(fā)布新流程</a> [username: <%=username %>]<a href="qhlogin.jsp">登陸</a> <table border="1" width="100%"> <table border="1" width="100%"> <table border="1" width="100%"> //repositoryService.createDeployment().addResourceFromClasspath("leave.jpdl.xml").deploy(); //***********用JPBM用戶組啟動流程
Map map = new HashMap(); IdentityService identityService = processEngine.getIdentityService(); identityService.createGroup("dev"); identityService.createUser("user1", "user1", "user1"); identityService.createUser("user2", "user2", "user2"); identityService.createMembership("user1", "dev"); identityService.createMembership("user2", "dev"); map.put("dev",identityService.findGroupById("dev").getId()); executionService.startProcessInstanceById(request .getParameter("id"), map); response.sendRedirect("qhindex.jsp"); %> 3-3、qhview.jsp查看流程視圖執(zhí)行節(jié)點: 3-3-1qhview.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="org.jbpm.api.*,java.util.*,org.jbpm.api.model.*" %> <% String id = request.getParameter("id"); ProcessEngine processEngine = Configuration.getProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); ExecutionService executionService = processEngine.getExecutionService(); ProcessInstance processInstance = executionService.findProcessInstanceById(id); Set<String> activityNames = processInstance.findActiveActivityNames(); ActivityCoordinates ac = repositoryService.getActivityCoordinates(processInstance.getProcessDefinitionId(),activityNames.iterator().next()); %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www./TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <img src="qhpic.jsp?id=<%=id %>" style="position:absolute;left:0px;top:0px;"> <div style="position:absolute;border:1px solid red;left:<%=ac.getX()%>px;top:<%=ac.getY()%>px;width:<%=ac.getWidth()%>px;height:<%=ac.getHeight()%>px;"></div> </body> </html> 3-3-2,、qhpic.jsp 畫出流程圖 <%@page import="org.jbpm.api.*,java.io.*"%> <% ProcessEngine processEngine = Configuration.getProcessEngine(); RepositoryService repositoryService = processEngine .getRepositoryService(); ExecutionService executionService = processEngine .getExecutionService(); String id = request.getParameter("id"); ProcessInstance processInstance = executionService .findProcessInstanceById(id); String processDefinitionId = processInstance .getProcessDefinitionId(); ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery().processDefinitionId( processDefinitionId).uniqueResult(); InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),"leave.png"); byte[] b = new byte[1024]; int len = -1; while ((len = inputStream.read(b, 0, 1024)) != -1) { response.getOutputStream().write(b, 0, len); } %> 3-4,、進入表單處理任務<a href="<%=task.getFormResourceName() %>?id=<%=task.getId() %>">view</a> 表單定義: leave.jpdl.xml <task form="qhrequest.jsp" g="172,118,92,52" name="申請" candidate-groups="#{dev}"http://指定用戶組辦理任務 ||assignee="manager" //指定用戶辦理任務> <transition to="經(jīng)理審批"/> </task> ------------------------------------------------
qhrequest.jsp: <fieldset> <legend>申請</legend> <form action="qhsubmit.jsp" method="post"> <input type="hidden" name="taskId" value="${param.id}"> 申請人:<input type="text" name="owner" value="${sessionScope['username']}"/><br/> 請假時間:<input type="text" name="day" value=""/><br/> 請假原因:<textarea name="reason"></textarea><br/> <input type="submit"/> </form> </fieldset> 3-5、qhsubmit.jsp處理表單任務: String taskId = request.getParameter("taskId"); 4,、經(jīng)理對請假進行審批:
index.jsp---進入表單處理任務<a href="<%=task.getFormResourceName() %>?id=<%=task.getId() %>">view</a>
---------------------------------------
manager.jsp
<%
ProcessEngine processEngine = Configuration.getProcessEngine(); TaskService taskService = processEngine.getTaskService(); String taskId = request.getParameter("id"); Task task = taskService.getTask(taskId); %> <body>
<fieldset> <legend>經(jīng)理審核</legend> <form action="qhsubmit_manager.jsp" method="post"> <input type="hidden" name="taskId" value="${param.id}"> 申請人:<%=taskService.getVariable(taskId, "owner") %><br/> 請假時間:<%=taskService.getVariable(taskId, "day") %><br/> 請假原因:<%=taskService.getVariable(taskId, "reason") %><br/> <input name="result" type="submit" value="批準"/><input name="result" type="submit" value="駁回"/> </form> </fieldset> ----------------------------------------------
qhsubmit_manager.jsp 處理經(jīng)理審批結(jié)果
<%@page contentType="text/html;charset=UTF-8" %>
<%@page import="java.util.*,org.jbpm.api.*"%> <% ProcessEngine processEngine = Configuration.getProcessEngine(); TaskService taskService = processEngine.getTaskService(); String taskId = request.getParameter("taskId"); String result = request.getParameter("result"); result = new String(result.getBytes("ISO-8859-1"), "UTF-8"); taskService.completeTask(taskId, result); response.sendRedirect("qhindex.jsp"); %> 5,、老板對請假天數(shù)大于三天的流程進行審批:
index.jsp---進入表單處理任務<a href="<%=task.getFormResourceName() %>?id=<%=task.getId() %>">view</a>
--------------------------------------------------
<%@page import="org.jbpm.api.*,org.jbpm.api.task.*" %> <% ProcessEngine processEngine = Configuration.getProcessEngine(); TaskService taskService = processEngine.getTaskService(); String taskId = request.getParameter("id"); Task task = taskService.getTask(taskId); %> <fieldset>
<legend>老板審核</legend> <form action="qhsubmit_boss.jsp" method="post"> <input type="hidden" name="taskId" value="${param.id}"> 申請人:<%=taskService.getVariable(taskId, "owner") %><br/> 請假時間:<%=taskService.getVariable(taskId, "day") %><br/> 請假原因:<%=taskService.getVariable(taskId, "reason") %><br/> <input type="submit" value="批準"/> </form> </fieldset> ----------------------------------------------
<%@page import="java.util.*,org.jbpm.api.*"%>
<% ProcessEngine processEngine = Configuration.getProcessEngine(); TaskService taskService = processEngine.getTaskService(); String taskId = request.getParameter("taskId"); taskService.completeTask(taskId); response.sendRedirect("qhindex.jsp"); %> |
|