JBPM4—请假流程

1、流程图

2、流程配置文件

---------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>

<process name="leave" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="300,72,48,48" name="start1">
      <transition to="申请"/>
   </start>
   <end g="300,468,48,48" name="end1"/>
   <task assignee="#{owner}" g="276,156,92,52" name="申请" form="request.jsp">
      <transition g="-71,-17" name="经理审批" to="经理审批"/>
   </task>
   <task assignee="manager" g="276,264,92,52" name="经理审批" form="manager.jsp">
      <transition g="-23,-6" name="批准" to="exclusive1"/>
      <transition name="驳回" to="申请" g="492,290;493,181:-30,-1"/>
   </task>
   <decision expr="#{day > 3 ? '老板审批':'结束'}" g="300,360,48,48" name="exclusive1">
      <transition g="492,384:-71,-17" name="老板审批" to="老板审批"/>
      <transition g="-24,-16" name="结束" to="end1"/>
   </decision>
   <task assignee="boss" g="444,468,92,52" name="老板审批" form="boss.jsp">
      <transition g="-22,-15" name="结束" to="end1"/>
   </task>
</process>

---------------------------------------------------------------------------------------------------------------


3、登陆页面(login.jsp)

---------------------------------------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登陆</title>
</head>
<body>
<fieldset>
    <legend>登陆</legend>
    <form action="doLogin.jsp" method="post">
    用户名:
    <input type="text" name="username" value=""/>
    <input type="submit" value="登陆">
    </form>
</fieldset>
</body>
</html>

---------------------------------------------------------------------------------------------------------------

4、登陆处理页面(doLogin.jsp)

---------------------------------------------------------------------------------------------------------------

<%
    String username=request.getParameter("username");
    session.setAttribute("username", username);
    response.sendRedirect("index.jsp");
%>

---------------------------------------------------------------------------------------------------------------


5、流程定义列表、流程实例列表、任务列表页面(index.jsp)

---------------------------------------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,org.jbpm.api.*,org.jbpm.api.task.*" %>
<%@ include file="/checklogin.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JBPM请假流程</title>
</head>
<body>
<a href="index.jsp?action=deploy">发布流程</a>|<a href="login.jsp">登陆</a><br/>
<%
    /**
    *流程引擎采用单例模式实现,每次调用的都是一个流程引擎,提高程序效率
    */
    ProcessEngine processEngine=Configuration.getProcessEngine();

    /**
    *发布服务:
    *1、流程发布
    *2、管理流程、删除流程、查看流程
    */
    RepositoryService repositoryService = processEngine.getRepositoryService();
    
    /**
    *执行服务
    *1、获取流程实例
    */
    ExecutionService executionService=processEngine.getExecutionService();

    /**
    *任务服务
    */
    TaskService taskService=processEngine.getTaskService();
    
    String action=request.getParameter("action");
    if("deploy".equals(action))
    {
        repositoryService.createDeployment().addResourceFromClasspath("leave.jpdl.xml").deploy();
    }
    else if("remove".equals(action))
    {
        repositoryService.deleteDeploymentCascade(request.getParameter("id"));
    }
    
    /**
    *获取流程定义列表,可以看到本工程都发布了哪些流程
    */
    List<ProcessDefinition> processDefitionList=repositoryService.createProcessDefinitionQuery().list();
    
    /**
    *获取流程实例列表,可以查看本工程中启动了哪些流程实例
    */
    List<ProcessInstance> piList=executionService.createProcessInstanceQuery().list();
    
    /**
    *获取任务列表,可以查看某人所有代表任务
    */
    String username1=(String)session.getAttribute("username");
    List<Task> taskList=taskService.findPersonalTasks(username1);
%>
<table border=1 width="100%">
    <caption>流程定义</caption>
    <thead>
        <tr>
            <th>id</th>
            <th>name</th>
            <th>version</th>
            <th>option</th>
        </tr>
    </thead>
    <tbody>
<%
    /**
    *循环输入发布的流程定义
    */
    for(ProcessDefinition pd : processDefitionList){
%>
        <tr>
            <td><%=pd.getId() %></td>
            <td><%=pd.getName() %></td>
            <td><%=pd.getVersion() %></td>
            <td>
            <a href="index.jsp?action=remove&id=<%=pd.getDeploymentId() %>">remove</a>|
            <a href="start.jsp?id=<%=pd.getId() %>">start</a>
            </td>
        </tr>
<%} %>
    </tbody>
</table>
<br/>
<table border="1" width="100%">
    <caption>流程实例</caption>
    <thead>
        <tr>
            <th>id</th>
            <th>action</th>
            <th>state</th>
            <th>option</th>
        </tr>
    </thead>
    <tbody>
<%
    /**
    *循环输入流程实例
    */
    for(ProcessInstance pi : piList)
    {
%>
        <tr>
            <td><%=pi.getId() %></td>
            <td><%=pi.findActiveActivityNames() %></td>
            <td><%=pi.getState() %></td>
            <td>
                <a href="view.jsp?id=<%=pi.getId() %>">view</a>
            </td>
        </tr>
<%} %>
    </tbody>
</table>
<br/>
<table border="1" width="100%">
    <caption>代办任务</caption>
    <thead>
        <tr>
            <th>id</th>
            <th>action</th>
            <th>option</th>
        </tr>
    </thead>
    <tbody>
<%
    /**
    *循环输出代办任务列表
    */
    for(Task task :taskList)
    {
%>
        <tr>
            <td><%=task.getId() %></td>
            <td><%=task.getActivityName() %></td>
            <td><a href="<%=task.getFormResourceName() %>?id=<%=task.getId() %>">view</a></td>
        </tr>
<%} %>
    </tbody>
</table>
</body>
</html>

---------------------------------------------------------------------------------------------------------------

JBPM4—请假流程_第1张图片

6、请假申请页面(request.jsp)

---------------------------------------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>填写申请单</title>
</head>
<body>
<fieldset>
    <legend>申请</legend>
    <form action="submit.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/>
    请假原因:<input type="text" name="reason" value=""/><br/>
    <input type="submit" value="提交">
    </form>
</fieldset>
</body>
</html>

---------------------------------------------------------------------------------------------------------------

7、请假申请处理页面(submit.jsp)

---------------------------------------------------------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.util.*,org.jbpm.api.*,org.jbpm.api.task.*" %>
<%
    ProcessEngine processEngine=Configuration.getProcessEngine();
    TaskService taskServace=processEngine.getTaskService();
    
    String taskId=request.getParameter("taskId");
    String owner=request.getParameter("owner");
    int day =Integer.parseInt(request.getParameter("day"));
    String reason=request.getParameter("reason");
    
    Map map=new HashMap();
    map.put("day", day);
    map.put("reason", reason);
    taskServace.setVariables(taskId, map);
    taskServace.completeTask(taskId);
    
    response.sendRedirect("index.jsp");
%>

---------------------------------------------------------------------------------------------------------------

JBPM4—请假流程_第2张图片

8、经理审批页面(manager.jsp)

---------------------------------------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,org.jbpm.api.*,org.jbpm.api.task.*" %>
<%@ include file="/checklogin.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>经理审批</title>
</head>
<body>
<%
    ProcessEngine processEngine=Configuration.getProcessEngine();
    TaskService taskService=processEngine.getTaskService();
    String taskId=request.getParameter("id");
    Task task=taskService.getTask(taskId);
%>
<fieldset>
    <legend>经理审批</legend>
    <form action="submit_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 type="submit" value="批准" name="result"/>
    <input type="submit" value="驳回" name="result"/>
    </form>
</fieldset>
</body>
</html>

---------------------------------------------------------------------------------------------------------------

9、经理审批处理页面(submit_manager.jsp)

---------------------------------------------------------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.util.*,org.jbpm.api.*,org.jbpm.api.task.*" %>
<%
    ProcessEngine processEngine=Configuration.getProcessEngine();
    TaskService taskServace=processEngine.getTaskService();
    
    String taskId=request.getParameter("taskId");
    String result=request.getParameter("result");
    result=new String(result.getBytes("ISO-8859-1"),"UTF-8");
    
    //Map map=new HashMap();
    //taskServace.setVariables(taskId, map);
    taskServace.completeTask(taskId,result);
    
    response.sendRedirect("index.jsp");
%>

---------------------------------------------------------------------------------------------------------------

JBPM4—请假流程_第3张图片

10、老板审批页面(boss.jsp)

---------------------------------------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,org.jbpm.api.*,org.jbpm.api.task.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>老板审批</title>
</head>
<body>
<%
    ProcessEngine processEngine=Configuration.getProcessEngine();
    TaskService taskService=processEngine.getTaskService();
    String taskId=request.getParameter("id");
    Task task=taskService.getTask(taskId);
%>
<fieldset>
    <legend>老板审批</legend>
    <form action="submit_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="批准" name="result"/>
    </form>
</fieldset>
</body>
</html>

---------------------------------------------------------------------------------------------------------------

11、老板审批处理页面(submit_boss.jsp)

---------------------------------------------------------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.util.*,org.jbpm.api.*,org.jbpm.api.task.*" %>
<%
    ProcessEngine processEngine=Configuration.getProcessEngine();
    TaskService taskServace=processEngine.getTaskService();
    
    String taskId=request.getParameter("taskId");
    taskServace.completeTask(taskId,"结束");
    
    response.sendRedirect("index.jsp");
%>

---------------------------------------------------------------------------------------------------------------

12、登陆检测页面(checklogin.jsp)

---------------------------------------------------------------------------------------------------------------

<%
    String username=(String)session.getAttribute("username");
    if("".equals(username)||null==username)
    {
        response.sendRedirect("login.jsp");
    }
%>

---------------------------------------------------------------------------------------------------------------

你可能感兴趣的:(JBPM4—请假流程)