jbpm各种用法和spring整合

晨曦之光 发布于 2012/04/11 18:10
阅读 4K+
收藏 1

登陆

主页


部署流程
 

流程管理
 

添加申请
 


 流程定义文件

Loan.jpdl.xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <process name="loan" xmlns="http://jbpm.org/4.0/jpdl">  
  4.    <start g="376,61,65,48" name="start">  
  5.       <transition g="-52,-15" name="to fill in applycation" to="fill in application">  
  6.       </transition>  
  7.    </start>  
  8.      
  9.    <task g="335,204,132,60" assignee="anyone" name="fill in application">  
  10.       <transition name="submit applicaton" to="副总经理审核" g="-55,-14"/>  
  11.    </task>  
  12.      
  13.    <task candidate-groups="副总经理" g="279,361,244,81" name="副总经理审核">  
  14.       <transition g="-29,-25" name="accept" to="exclusive amount"/>  
  15.       <transition g="-20,-25" name="reject" to="end"/>  
  16.    </task>  
  17.      
  18.    <decision expr="#{content}" g="80,377,60,48" name="exclusive amount">  
  19.       <transition g="-50,-23" name="amount larger than 5000" to="总经理审核">     
  20.       </transition>  
  21.       <transition g="-94,-22" name="amount less than 5000" to="give money">       
  22.       </transition>   
  23.    </decision>  
  24.      
  25.    <task assignee="#{manager.incumbent}" g="4,645,199,65" name="总经理审核">  
  26.       <transition g="-79,-30" name="accept" to="give money"/>  
  27.       <transition g="415,712:-45,-22" name="reject" to="end"/>  
  28.    </task>  
  29.      
  30.    <task candidate-groups="服务员" g="327,601,144,66" name="give money">  
  31.       <transition g="-45,-22" name="send Email" to="end">  
  32.          <mail>  
  33.             <to addresses="#{appEmail}"/>  
  34.             <subject>success to load money!</subject>  
  35.             <text>dear ${appName},you have pass through examine!please goto the bank before ${deadline}</text>  
  36.          </mail>  
  37.       </transition>  
  38.    </task>  
  39.    <end g="649,647,48,48" name="end"/>  
  40. </process>  

 spring 与jbpm4.4结合的配置文件

Applicationcontext.xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <beans xmlns="http://www.springframework.org/schema/beans"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"  
  5.     xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"  
  6.     xsi:schemaLocation="  
  7.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  8.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  9.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  10.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
  11.   
  12.     <bean id="sessionFactory"  
  13.         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  14.         <property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />  
  15.         <property name="dataSource" ref="dataSource" />  
  16.     </bean>  
  17.   
  18.   
  19.     <bean id="transactionManager"  
  20.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  21.         <property name="sessionFactory" ref="sessionFactory" />  
  22.         <property name="dataSource" ref="dataSource" />  
  23.     </bean>  
  24.   
  25.     <!-- 定义事务拦截器 -->  
  26.     <bean id="transactionInterceptor"  
  27.         class="org.springframework.transaction.interceptor.TransactionInterceptor">  
  28.         <!-- 注入事务管理 -->  
  29.         <property name="transactionManager" ref="transactionManager" />  
  30.         <property name="transactionAttributes">  
  31.             <!-- 定义事务传播属性 -->  
  32.             <props><!-- <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop>   
  33.                     <prop key="del*">PROPAGATION_REQUIRED</prop> -->  
  34.                 <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>  
  35.   
  36.                 <prop key="*">PROPAGATION_REQUIRED</prop>  
  37.             </props>  
  38.         </property>  
  39.     </bean>  
  40.   
  41.   
  42.     <!-- 定义BeanNameAutoProxyCreator -->  
  43.     <bean  
  44.         class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">  
  45.         <!-- 指定对满足哪些bean name的bean自动生成业务代理 -->  
  46.         <property name="beanNames">  
  47.             <!-- 下面是所有需要自动创建事务代理的bean -->  
  48.             <list>  
  49.                 <value>roleService</value>  
  50.                 <value>staffService</value>  
  51.                 <value>applicationService</value>  
  52.                 <value>leaveServlet</value>  
  53.             </list>  
  54.             <!-- 此处可增加其他需要自动创建事务代理的bean -->  
  55.         </property>  
  56.         <!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器 -->  
  57.         <property name="interceptorNames">  
  58.             <list>  
  59.                 <!-- 此处可增加其他新的Interceptor -->  
  60.                 <value>transactionInterceptor</value>  
  61.             </list>  
  62.         </property>  
  63.     </bean>  
  64.   
  65.     <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">  
  66.         <property name="jbpmCfg" value="jbpm.cfg.xml" />  
  67.     </bean>  
  68.     <bean id="processEngine" factory-bean="springHelper"  
  69.         factory-method="createProcessEngine" />  
  70.     <bean id="jBPMUtil" class="hust.loan.dao.util.JBPMUtil">  
  71.         <property name="processEngine" ref="processEngine"></property>  
  72.     </bean>  
  73.   
  74.     <bean id="dataSource"  
  75.         class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
  76.         <property name="driverClassName" value="com.mysql.jdbc.Driver" />  
  77.         <property name="url" value="jdbc:mysql://localhost:3306/loandb" />  
  78.         <property name="username" value="root" />  
  79.         <property name="password" value="root" />  
  80.     </bean>  
  81. </beans>  

 jbpm配置文件:

Jbpm.cfg.xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <jbpm-configuration>  
  4.   
  5.     <import resource="jbpm.default.cfg.xml" />  
  6.     <import resource="jbpm.tx.hibernate.cfg.xml" />  
  7.     <import resource="jbpm.tx.spring.cfg.xml" />  
  8.     <import resource="jbpm.jpdl.cfg.xml" />  
  9.     <import resource="jbpm.bpmn.cfg.xml" />  
  10.     <import resource="jbpm.identity.cfg.xml" />  
  11.     <import resource="jbpm.businesscalendar.cfg.xml" />  
  12.     <import resource="jbpm.console.cfg.xml" />  
  13.     <!-- <import resource="jbpm.jobexecutor.cfg.xml" /> -->  
  14.   
  15.     <hibernate-session-factory />  
  16.   
  17. </jbpm-configuration>  

 
 hibernate 配置文件:

Jbpm.hibernate.cfg.xml代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <!DOCTYPE hibernate-configuration PUBLIC  
  4.           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
  5.           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  
  6.   
  7. <hibernate-configuration>  
  8.     <session-factory>  
  9.         <!-- mysql database -->  
  10.         <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>  
  11.         <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>  
  12.         <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/loandb</property>  
  13.         <property name="hibernate.connection.username">root</property>  
  14.         <property name="hibernate.connection.password">root</property>  
  15.         <property name="hibernate.hbm2ddl.auto">update</property>  
  16.         <property name="hibernate.format_sql">true</property>  
  17.         <property name="show_sql">true</property>  
  18.         <property name="hibernate.current_session_context_class">  
  19.             thread  
  20.     </property>  
  21.   
  22.   
  23.         <mapping resource="jbpm.repository.hbm.xml" />  
  24.         <mapping resource="jbpm.execution.hbm.xml" />  
  25.         <mapping resource="jbpm.history.hbm.xml" />  
  26.         <mapping resource="jbpm.task.hbm.xml" />  
  27.         <mapping resource="jbpm.identity.hbm.xml" />  
  28.   
  29.         <mapping resource="hust/loan/po/xml/Role.hbm.xml" />  
  30.         <mapping resource="hust/loan/po/xml/Staff.hbm.xml" />  
  31.         <mapping resource="hust/loan/po/xml/ApplicationForm.hbm.xml" />  
  32.   
  33.     </session-factory>  
  34. </hibernate-configuration>  

处理贷款的类:

Loanservlet.java代码   收藏代码
  1. package hust.loan.servlet;  
  2.   
  3. import hust.loan.dao.util.JBPMUtil;  
  4. import hust.loan.dao.util.Page;  
  5. import hust.loan.po.ApplicationForm;  
  6. import hust.loan.po.Role;  
  7. import hust.loan.po.Staff;  
  8. import hust.loan.service.ApplicationService;  
  9. import hust.loan.service.RoleService;  
  10. import hust.loan.service.StaffService;  
  11.   
  12. import java.io.IOException;  
  13. import java.util.ArrayList;  
  14. import java.util.Date;  
  15. import java.util.HashMap;  
  16. import java.util.List;  
  17. import java.util.Map;  
  18.   
  19. import net.sf.json.*;  
  20. import javax.servlet.ServletConfig;  
  21. import javax.servlet.ServletException;  
  22. import javax.servlet.http.HttpServlet;  
  23. import javax.servlet.http.HttpServletRequest;  
  24. import javax.servlet.http.HttpServletResponse;  
  25.   
  26. import org.jbpm.api.ExecutionService;  
  27. import org.jbpm.api.ProcessEngine;  
  28. import org.jbpm.api.ProcessInstance;  
  29. import org.jbpm.api.RepositoryService;  
  30. import org.jbpm.api.TaskService;  
  31. import org.jbpm.api.task.Task;  
  32.   
  33. /**  
  34.  * 贷款例子处理servlet的  
  35.  *   
  36.  * @author seven  
  37.  */  
  38. public class LoanServlet extends HttpServlet {  
  39.     private static final long serialVersionUID = 1L;  
  40.     private JBPMUtil jBPMUtil;  
  41.   
  42.     public JBPMUtil getjBPMUtil() {  
  43.         return jBPMUtil;  
  44.     }  
  45.   
  46.     public void setjBPMUtil(JBPMUtil jBPMUtil) {  
  47.         this.jBPMUtil = jBPMUtil;  
  48.         processEngine=jBPMUtil.getProcessEngine();  
  49.         repositoryService=jBPMUtil.getRepositoryService();  
  50.         executionService = jBPMUtil.getExecutionService();  
  51.         taskService= jBPMUtil.getTaskService();  
  52.           
  53.           
  54.     }  
  55.   
  56.     private ProcessEngine processEngine;  
  57.     private RepositoryService repositoryService;  
  58.     private ExecutionService executionService;  
  59.     private TaskService taskService;  
  60.     private RoleService roleService;  
  61.     private StaffService staffService;  
  62.     private ApplicationService applicationService;  
  63.   
  64.     private ProcessInstance processInstance;// 流程实例  
  65.   
  66.     // get/set方法  
  67.     public StaffService getStaffService() {  
  68.         return staffService;  
  69.     }  
  70.   
  71.     public void setStaffService(StaffService staffService) {  
  72.         this.staffService = staffService;  
  73.     }  
  74.   
  75.     public ApplicationService getApplicationService() {  
  76.         return applicationService;  
  77.     }  
  78.   
  79.     public void setApplicationService(ApplicationService applicationService) {  
  80.         this.applicationService = applicationService;  
  81.     }  
  82.   
  83.     public RoleService getRoleService() {  
  84.         return roleService;  
  85.     }  
  86.   
  87.     public void setRoleService(RoleService roleService) {  
  88.         this.roleService = roleService;  
  89.     }  
  90.   
  91.     public ProcessEngine getProcessEngine() {  
  92.         return processEngine;  
  93.     }  
  94.   
  95.     public void setProcessEngine(ProcessEngine processEngine) {  
  96.         this.processEngine = processEngine;  
  97.     }  
  98.   
  99.     public RepositoryService getRepositoryService() {  
  100.         return repositoryService;  
  101.     }  
  102.   
  103.     public void setRepositoryService(RepositoryService repositoryService) {  
  104.         this.repositoryService = repositoryService;  
  105.     }  
  106.   
  107.     public ExecutionService getExecutionService() {  
  108.         return executionService;  
  109.     }  
  110.   
  111.     public void setExecutionService(ExecutionService executionService) {  
  112.         this.executionService = executionService;  
  113.     }  
  114.   
  115.     public TaskService getTaskService() {  
  116.         return taskService;  
  117.     }  
  118.   
  119.     public void setTaskService(TaskService taskService) {  
  120.         this.taskService = taskService;  
  121.     }  
  122.   
  123.     // end-get/set  
  124.   
  125.     public void init(ServletConfig config) throws ServletException {  
  126.         super.init(config);  
  127.     }  
  128.   
  129.     protected void doGet(HttpServletRequest request,  
  130.             HttpServletResponse response) throws ServletException, IOException {  
  131.         process(request, response);  
  132.         // TODO Auto-generated method stub  
  133.     }  
  134.   
  135.     protected void doPost(HttpServletRequest request,  
  136.             HttpServletResponse response) throws ServletException, IOException {  
  137.         process(request, response);  
  138.     }  
  139.   
  140.     /**  
  141.      * 处理分发类  
  142.      *   
  143.      * @throws IOException  
  144.      * @throws ServletException  
  145.      * */  
  146.     private void process(HttpServletRequest request,  
  147.             HttpServletResponse response) throws ServletException, IOException {  
  148.         // 设置字符请求编码  
  149.         request.setCharacterEncoding("UTF-8");  
  150.         response.setCharacterEncoding("utf-8");  
  151.         String action = request.getParameter("action");  
  152.         if (action.equals("addRole")) {  
  153.             if (addRole(request, response)) {  
  154.                 response.getWriter().write("{success:true}");  
  155.             } else {  
  156.                 response.getWriter().write("{failure:true}");  
  157.             }  
  158.         } else if (action.equals("toAddRole")) {  
  159.             // 转移到添加角色页面  
  160.   
  161.             request.getRequestDispatcher("/loan/loan_addRole.jsp").forward(  
  162.                     request, response);  
  163.   
  164.         } else if (action.equals("toAddStaff")) {  
  165.             // 转移到添加员工页面  
  166.             request.getRequestDispatcher("/loan/loan_addStaff.jsp").forward(  
  167.                     request, response);  
  168.   
  169.         } else if (action.equals("getAllRole")) {  
  170.             // 查找所有角色  
  171.             List<Role> roles = roleService.getRoles();  
  172.             // 转换为json格式数据  
  173.             response.getWriter().write(beanToJsonString(roles, false));  
  174.         } else if (action.equals("addStaff")) {  
  175.             // 添加员工  
  176.             if (addStaff(request, response)) {  
  177.                 response.getWriter().write("{success:true}");  
  178.             } else {  
  179.                 response.getWriter().write("{failure:true}");  
  180.             }  
  181.         } else if (action.equals("addApply")) {  
  182.             String validateCode = request.getSession().getAttribute("rand")  
  183.                     .toString();  
  184.             System.out.println("validate:"  
  185.                     + request.getParameter("validateCode"));  
  186.             System.out.println("randCode:" + validateCode);  
  187.             if (validateCode.equals(request.getParameter("validateCode"))) {  
  188.                 int applyId = addApply(request, response);  
  189.                 if (applyId > 0) {  
  190.   
  191.                     response.getWriter().write(  
  192.                             "{success:true,applyId:" + applyId + "}");  
  193.                 } else {  
  194.                     response.getWriter().write("{failure:true,mes:'申请失败'}");  
  195.                 }  
  196.             } else {  
  197.                 response.getWriter().write("{failure:true,mes:'验证码错误'}");  
  198.             }  
  199.   
  200.         } else if (action.equals("toAddApply")) {  
  201.             // 转移到填写申请单页面  
  202.             request.getRequestDispatcher("/loan/loan_addApply.jsp").forward(  
  203.                     request, response);  
  204.         } else if (action.equals("getAllStaff")) {  
  205.             String start = request.getParameter("start");  
  206.             String limit = request.getParameter("limit");  
  207.             Page page = new Page();  
  208.             page.setStartIndex(Integer.valueOf(start));  
  209.             page.setLastIndex(Integer.valueOf(limit));  
  210.             String json = this.getStaffs(page);  
  211.             response.getWriter().write(json);  
  212.         } else if (action.equals("toStaffGrid")) {  
  213.   
  214.             request.getRequestDispatcher("/loan/loan_staffgrid.jsp").forward(  
  215.                     request, response);  
  216.         } else if (action.equals("saveStaff")) {  
  217.             // 保存职员  
  218.             String data = request.getParameter("data");  
  219.             List<Staff> staffs = this.getStaffFromJson(data);  
  220.             if (!staffs.isEmpty()) {  
  221.                 for (Staff staff : staffs) {  
  222.                     staffService.updateStaff(staff);  
  223.                 }  
  224.                 response.getWriter().write("保存成功!");  
  225.             }  
  226.             // response.getWriter().write("保存成功!");  
  227.         } else if (action.equals("delStaff")) {  
  228.             // 删除员工  
  229.             String data = request.getParameter("data");  
  230.             List<Staff> staffs = this.getStaffFromJson(data);  
  231.             if (!staffs.isEmpty()) {  
  232.                 for (Staff staff : staffs) {  
  233.                     staffService.delStaff(staff);  
  234.                 }  
  235.                 response.getWriter().write("删除成功!");  
  236.             }  
  237.         } else if (action.equals("toManagerTree")) {  
  238.             // 跳转到树形页面  
  239.             request.getRequestDispatcher("/loan/loan_managerTree.jsp").forward(  
  240.                     request, response);  
  241.   
  242.         } else if (action.equals("toLogin")) {  
  243.             // 登入首页  
  244.             request.getRequestDispatcher("/loan/loan_index.jsp").forward(  
  245.                     request, response);  
  246.         } else if (action.equals("logout")) {  
  247.             // 退出系统  
  248.             request.getSession().removeAttribute("name");  
  249.             request.getSession().removeAttribute("roleType");  
  250.             request.getSession().invalidate();  
  251.             response.getWriter().write("{success:true}");  
  252.         } else if (action.equals("login")) {  
  253.             // 登入  
  254.             String name = (String) request.getParameter("name");  
  255.             String password = (String) request.getParameter("password");  
  256.             Staff staff = staffService  
  257.                     .getStaffByNameAndPassword(name, password);  
  258.             if (staff != null) {  
  259.                 request.getSession().setAttribute("user", staff.getName());  
  260.                 request.getSession().setAttribute("userType",  
  261.                         staff.getRole().getRoleType());  
  262.                 request.getSession().setAttribute("userId", staff.getStaffId());  
  263.                 response.getWriter().write("{success:true}");  
  264.   
  265.             } else {  
  266.                 response.getWriter().write("{failure:true}");  
  267.             }  
  268.   
  269.         } else if (action.equals("ds_getAllRole")) {  
  270.             // 获取所有角色详细信息  
  271.             List<Role> roles = roleService.getRoles();  
  272.             // 装换成json格式数据  
  273.             String jsonString = this.beanToJsonString(roles, true);  
  274.             response.getWriter().write(jsonString);  
  275.         } else if (action.equals("delRole")) {  
  276.             // 删除角色  
  277.             String roleId = request.getParameter("roleId");  
  278.             if (roleService.delRole(roleService.getRoleById(Integer  
  279.                     .valueOf(roleId)))) {  
  280.                 response.getWriter().flush();  
  281.                 response.getWriter().write("{success:true}");  
  282.             } else {  
  283.                 response.getWriter().write("{failure:true}");  
  284.             }  
  285.   
  286.         } else if (action.equals("updateRole")) {  
  287.             // 更新角色  
  288.             Role role = new Role();  
  289.             role.setRoleId(Integer.valueOf(request.getParameter("roleId")));  
  290.             role.setRoleName(request.getParameter("roleName"));  
  291.             role.setRoleType(request.getParameter("roleType"));  
  292.             role.setDescription(request.getParameter("description"));  
  293.   
  294.             try {  
  295.                 roleService.updateRole(role);  
  296.                 response.getWriter().write("{success:true}");  
  297.             } catch (Exception e) {  
  298.                 response.getWriter().write("{failure:true}");  
  299.             }  
  300.   
  301.         } else {  
  302.             request.getRequestDispatcher("/loan/index.jsp").forward(request,  
  303.                     response);  
  304.         }  
  305.   
  306.     }  
  307.   
  308.     /**  
  309.      * 添加申请单  
  310.      * */  
  311.     private int addApply(HttpServletRequest request,  
  312.             HttpServletResponse response) {  
  313.         // 根据流程定义的KEY值启动一个新的流程实例  
  314.         processInstance = executionService.startProcessInstanceByKey("loan");  
  315.   
  316.         // 判断流程定义的活动是否是“填写表单”的活动  
  317.         if (processInstance.isActive("fill in application")) {  
  318.   
  319.             ApplicationForm applyform = new ApplicationForm();  
  320.             applyform.setAppUserId(request.getParameter("appUserId"));  
  321.             applyform.setAppName(request.getParameter("appName"));  
  322.             applyform.setAppDate(new Date());  
  323.             applyform.setAddress(request.getParameter("address"));  
  324.             applyform  
  325.                     .setAmount(Integer.valueOf(request.getParameter("amount")));  
  326.             applyform.setReason(request.getParameter("reason"));  
  327.             applyform.setEmail(request.getParameter("email"));  
  328.             int appid = applicationService.addApplicationForm(applyform);  
  329.             // 流程变量  
  330.             Map<String, Object> variables = new HashMap<String, Object>();  
  331.             variables.put("applyId", appid);  
  332.             List<Task> tasks = taskService.findPersonalTasks("anyone");  
  333.             // 根据任务列表获取任务  
  334.             Task task = tasks.get(0);  
  335.             // 把设置好的变量放到任务服务里面并根据任务ID结束任务  
  336.             taskService.setVariables(task.getId(), variables);  
  337.             taskService.completeTask(task.getId()); // 进入到副总经理审核阶段  
  338.             // List<Task> list=taskService.findGroupTasks("man");  
  339.             return appid;  
  340.         } else {  
  341.             return 0;  
  342.         }  
  343.     }  
  344.   
  345.     /**  
  346.      * 添加角色  
  347.      * */  
  348.     private boolean addRole(HttpServletRequest request,  
  349.             HttpServletResponse response) {  
  350.         // 添加角色  
  351.         String roleName = (String) request.getParameter("roleName");  
  352.         String roleType = (String) request.getParameter("roleType");  
  353.         String description = (String) request.getParameter("description");  
  354.   
  355.         Role role = new Role();  
  356.         role.setRoleName(roleName);  
  357.         role.setRoleType(roleType);  
  358.         role.setDescription(description);  
  359.         // 添加角色到数据库中  
  360.         return roleService.addRole(role);  
  361.     }  
  362.   
  363.     /**  
  364.      * 添加员工  
  365.      * @throws IOException   
  366.      * */  
  367.     public boolean addStaff(HttpServletRequest request,  
  368.             HttpServletResponse response) throws IOException {  
  369.   
  370.         Staff staff = new Staff();  
  371.         staff.setName(request.getParameter("name"));  
  372.         staff.setEmail(request.getParameter("email"));  
  373.         staff.setPassword(request.getParameter("password"));  
  374.         staff.setAddress(request.getParameter("address"));  
  375.         System.out.println("roleid" + request.getParameter("roleId"));  
  376.         Role role = roleService.getRoleById(Integer.valueOf(request  
  377.                 .getParameter("roleId")));  
  378.         staff.setRole(role);  
  379.         try {  
  380.             staffService.addStaff(staff);  
  381.             return true;  
  382.         } catch (Exception e) {  
  383.             e.printStackTrace();  
  384.             return false;  
  385.         }  
  386.     }  
  387.   
  388.     /**  
  389.      * 将角色类型数据返回json数据格式  
  390.      * */  
  391.     private String beanToJsonString(List<Role> roles, boolean all) {  
  392.         StringBuffer jsonString = new StringBuffer();  
  393.   
  394.         jsonString.append("{root:[");  
  395.         // 返回全部  
  396.         if (all) {  
  397.             for (Role role : roles) {  
  398.                 jsonString.append("{roleId:" + role.getRoleId() + ",roleName:'"  
  399.                         + role.getRoleName() + "'," + "roleType:'"  
  400.                         + role.getRoleType() + "',description:'"  
  401.                         + role.getDescription() + "'},");  
  402.             }  
  403.         } else {  
  404.             for (Role role : roles) {  
  405.                 jsonString.append("{roleName:'" + role.getRoleName()  
  406.                         + "',roleId:'" + role.getRoleId() + "'},");  
  407.             }  
  408.         }  
  409.   
  410.         jsonString.append("]}");  
  411.         return jsonString.substring(0, jsonString.lastIndexOf(","))  
  412.                 + jsonString.substring(jsonString.lastIndexOf(",") + 1);  
  413.   
  414.     }  
  415.   
  416.     /**  
  417.      * 分页返回员工信息列表  
  418.      * */  
  419.     @SuppressWarnings("unchecked")  
  420.     private String getStaffs(Page page) {  
  421.         StringBuffer jsonString = new StringBuffer();  
  422.         page = staffService.getStaffs(page);  
  423.         List<Staff> staffs = page.getList();  
  424.         jsonString.append("{totalProperty:");  
  425.         jsonString.append(page.getTotalCount());  
  426.         jsonString.append(",root:[");  
  427.         for (Staff staff : staffs) {  
  428.             jsonString.append("{staffId:" + staff.getStaffId());  
  429.             jsonString.append(",name:'" + staff.getName());  
  430.             jsonString.append("',address:'" + staff.getAddress());  
  431.             jsonString.append("',email:'" + staff.getEmail());  
  432.             jsonString.append("',roleId:'" + staff.getRole().getRoleId());  
  433.             jsonString.append("',roleName:'" + staff.getRole().getRoleName()  
  434.                     + "'},");  
  435.         }  
  436.         jsonString.append("]}");  
  437.         return jsonString.substring(0, jsonString.lastIndexOf(","))  
  438.                 + jsonString.substring(jsonString.lastIndexOf(",") + 1);  
  439.   
  440.     }  
  441.   
  442.     /**  
  443.      * 把json转换成bean  
  444.      * */  
  445.     private List<Staff> getStaffFromJson(String jsonData) {  
  446.   
  447.         List<Staff> list = new ArrayList<Staff>();  
  448.   
  449.         try {  
  450.   
  451.             JSONArray array = JSONArray.fromObject(jsonData);  
  452.             Staff staff = new Staff();  
  453.             Role role = new Role();  
  454.             for (int i = 0; i < array.size(); i++) {  
  455.                 JSONObject jo = array.getJSONObject(i);  
  456.                 staff.setStaffId(jo.getInt("staffId"));  
  457.                 staff = staffService.getStaffById(jo.getInt("staffId"));  
  458.                 /*  
  459.                  * staff.setAddress(jo.getString("address"));  
  460.                  * staff.setEmail(jo.getString("email"));  
  461.                  * staff.setName(jo.getString("name")); role =  
  462.                  * roleService.getRoleById(Integer.parseInt(jo  
  463.                  * .getString("roleId"))); staff.setRole(role);  
  464.                  */  
  465.                 list.add(staff);  
  466.             }  
  467.         } catch (JSONException e) {  
  468.             e.printStackTrace();  
  469.         }  
  470.         return list;  
  471.     }  
  472. }  

 流程处理工具类:

Jbpmutil.java代码   收藏代码
  1. package hust.loan.dao.util;  
  2.   
  3. import java.util.HashMap;  
  4. import java.util.List;  
  5. import java.util.Map;  
  6. import java.util.zip.ZipInputStream;  
  7.   
  8. import javax.servlet.http.HttpSession;  
  9.   
  10. import org.jbpm.api.Execution;  
  11. import org.jbpm.api.ExecutionService;  
  12. import org.jbpm.api.HistoryService;  
  13. import org.jbpm.api.IdentityService;  
  14. import org.jbpm.api.ManagementService;  
  15. import org.jbpm.api.ProcessDefinition;  
  16. import org.jbpm.api.ProcessEngine;  
  17. import org.jbpm.api.ProcessInstance;  
  18. import org.jbpm.api.RepositoryService;  
  19. import org.jbpm.api.TaskService;  
  20. import org.jbpm.api.task.Task;  
  21.   
  22. /**  
  23.  * jbpm工具类  
  24.  *   
  25.  * @author ht  
  26.  *   
  27.  */  
  28. public class JBPMUtil {  
  29.   
  30.     private ProcessEngine processEngine;  
  31.     private RepositoryService repositoryService = null;  
  32.     private ExecutionService executionService = null;  
  33.     private TaskService taskService = null;  
  34.     private HistoryService historyService = null;  
  35.     private ManagementService managementService = null;  
  36.     private IdentityService identityService = null;  
  37.   
  38.     public JBPMUtil() {  
  39.   
  40.     }  
  41.   
  42.     public JBPMUtil(ProcessEngine processEngine) {  
  43.         this.processEngine = processEngine;  
  44.         repositoryService = processEngine.getRepositoryService();  
  45.         executionService = processEngine.getExecutionService();  
  46.         taskService = processEngine.getTaskService();  
  47.         historyService = processEngine.getHistoryService();  
  48.         managementService = processEngine.getManagementService();  
  49.         identityService = processEngine.getIdentityService();  
  50.   
  51.     }  
  52.   
  53.     public ProcessEngine getProcessEngine() {  
  54.         return processEngine;  
  55.     }  
  56.   
  57.     public void setProcessEngine(ProcessEngine processEngine) {  
  58.         this.processEngine = processEngine;  
  59.         System.out.println("processEngine=" + processEngine);  
  60.         repositoryService = processEngine.getRepositoryService();  
  61.         executionService = processEngine.getExecutionService();  
  62.         taskService = processEngine.getTaskService();  
  63.         historyService = processEngine.getHistoryService();  
  64.         managementService = processEngine.getManagementService();  
  65.         identityService = processEngine.getIdentityService();  
  66.     }  
  67.   
  68.     public IdentityService getIdentityService() {  
  69.         return identityService;  
  70.     }  
  71.   
  72.     public void setIdentityService(IdentityService identityService) {  
  73.         this.identityService = identityService;  
  74.     }  
  75.   
  76.     public RepositoryService getRepositoryService() {  
  77.         return repositoryService;  
  78.     }  
  79.   
  80.     public void setRepositoryService(RepositoryService repositoryService) {  
  81.         this.repositoryService = repositoryService;  
  82.     }  
  83.   
  84.     public ExecutionService getExecutionService() {  
  85.         return executionService;  
  86.     }  
  87.   
  88.     public void setExecutionService(ExecutionService executionService) {  
  89.         this.executionService = executionService;  
  90.     }  
  91.   
  92.     public TaskService getTaskService() {  
  93.         return taskService;  
  94.     }  
  95.   
  96.     public void setTaskService(TaskService taskService) {  
  97.         this.taskService = taskService;  
  98.     }  
  99.   
  100.     public HistoryService getHistoryService() {  
  101.         return historyService;  
  102.     }  
  103.   
  104.     public void setHistoryService(HistoryService historyService) {  
  105.         this.historyService = historyService;  
  106.     }  
  107.   
  108.     public ManagementService getManagementService() {  
  109.         return managementService;  
  110.     }  
  111.   
  112.     public void setManagementService(ManagementService managementService) {  
  113.         this.managementService = managementService;  
  114.     }  
  115.   
  116.     /**  
  117.      * 部署新流程定义  
  118.      *   
  119.      * @param resourceName  
  120.      * @return 返回流程定义id  
  121.      */  
  122.     public String deployNew(String resourceName) {  
  123.         return repositoryService.createDeployment()  
  124.                 .addResourceFromClasspath(resourceName).deploy();  
  125.     }  
  126.   
  127.     /**  
  128.      * 部署新流程定义(zip)  
  129.      *   
  130.      * @param resourceName  
  131.      * @return 返回流程定义id  
  132.      */  
  133.     public String deployZipNew(String resourceZipName) {  
  134.         ZipInputStream zis = new ZipInputStream(this.getClass()  
  135.                 .getResourceAsStream(resourceZipName));  
  136.   
  137.         return repositoryService.createDeployment()  
  138.                 .addResourcesFromZipInputStream(zis).deploy();  
  139.   
  140.     }  
  141.   
  142.     /**  
  143.      * 开始一个流程实例  
  144.      *   
  145.      * @param id  
  146.      * @param map  
  147.      * @return  
  148.      */  
  149.   
  150.     public ProcessInstance startPIById(String id, Map<String, ?> map) {  
  151.   
  152.         return executionService.startProcessInstanceById(id, map);  
  153.   
  154.     }  
  155.   
  156.     /**  
  157.      * 完成任务  
  158.      *   
  159.      * @param taskId  
  160.      * @param map  
  161.      */  
  162.   
  163.     public void completeTask(String taskId, Map map) {  
  164.   
  165.         taskService.completeTask(taskId, map);  
  166.     }  
  167.   
  168.     /**  
  169.      * 完成任务  
  170.      *   
  171.      * @param taskId  
  172.      */  
  173.     public void completeTask(String taskId) {  
  174.         taskService.completeTask(taskId);  
  175.     }  
  176.   
  177.     /**  
  178.      * 将任务流转到指定名字的流程outcome中去  
  179.      *   
  180.      * @param taskId  
  181.      * @param outcome  
  182.      */  
  183.     public void completeTask(String taskId, String outcome) {  
  184.         taskService.completeTask(taskId, outcome);  
  185.     }  
  186.   
  187.     public void completeTask(String taskId, String outcome, Map variables) {  
  188.         taskService.completeTask(taskId, outcome, variables);  
  189.     }  
  190.   
  191.     /**  
  192.      * 获得所有发布了的流程  
  193.      *   
  194.      * @return  
  195.      */  
  196.     public List<ProcessDefinition> getAllPdList() {  
  197.         return repositoryService.createProcessDefinitionQuery().list();  
  198.     }  
  199.   
  200.     /**  
  201.      * 获得所有流程实例  
  202.      *   
  203.      * @return  
  204.      */  
  205.     public List<ProcessInstance> getAllPiList() {  
  206.         return executionService.createProcessInstanceQuery().list();  
  207.     }  
  208.   
  209.     /**  
  210.      * 根据流程实例Id,即executionId获取指定的变量值  
  211.      *   
  212.      * @param executionId  
  213.      * @param variableName  
  214.      * @return  
  215.      */  
  216.     public Object getVariableByexecutionId(String executionId,  
  217.             String variableName) {  
  218.         return executionService.getVariable(executionId, variableName);  
  219.     }  
  220.   
  221.     /**  
  222.      * 根据任务id,即taskId获取指定变量值  
  223.      *   
  224.      * @param taskId  
  225.      * @param variableName  
  226.      * @return  
  227.      */  
  228.     public Object getVariableByTaskId(String taskId, String variableName) {  
  229.         return taskService.getVariable(taskId, variableName);  
  230.     }  
  231.   
  232.     /**  
  233.      * 获取指定用户名字的任务  
  234.      *   
  235.      * @param userName  
  236.      * @return  
  237.      */  
  238.     public List<Task> findPersonalTasks(String userName) {  
  239.         return taskService.findPersonalTasks(userName);  
  240.     }  
  241.   
  242.     /**  
  243.      * 根据任务id获取任务  
  244.      *   
  245.      * @param taskId  
  246.      * @return  
  247.      */  
  248.     public Task getTask(String taskId) {  
  249.         return taskService.getTask(taskId);  
  250.   
  251.     }  
  252.   
  253.     /**  
  254.      * 级联删除流程定义,直接删除该流程定义下的所有实例  
  255.      *   
  256.      * @param deploymentId流程定义id  
  257.      */  
  258.     public void deleteDeploymentCascade(String deploymentId) {  
  259.         repositoryService.deleteDeploymentCascade(deploymentId);  
  260.     }  
  261.   
  262. }  

 流程管理类

Processservlet.java代码   收藏代码
  1. package hust.loan.servlet;  
  2.   
  3. import hust.loan.dao.StaffDao;  
  4. import hust.loan.dao.util.JBPMUtil;  
  5. import hust.loan.po.ApplicationForm;  
  6. import hust.loan.po.Manager;  
  7. import hust.loan.po.Role;  
  8. import hust.loan.po.Staff;  
  9. import hust.loan.service.ApplicationService;  
  10. import hust.loan.service.RoleService;  
  11. import hust.loan.service.StaffService;  
  12.   
  13. import java.io.IOException;  
  14. import java.io.UnsupportedEncodingException;  
  15. import java.text.DateFormat;  
  16. import java.text.ParseException;  
  17. import java.text.SimpleDateFormat;  
  18. import java.util.ArrayList;  
  19. import java.util.Calendar;  
  20. import java.util.Date;  
  21. import java.util.HashMap;  
  22. import java.util.Iterator;  
  23. import java.util.List;  
  24. import java.util.Map;  
  25. import java.util.zip.ZipInputStream;  
  26.   
  27. import javax.servlet.ServletException;  
  28. import javax.servlet.http.HttpServlet;  
  29. import javax.servlet.http.HttpServletRequest;  
  30. import javax.servlet.http.HttpServletResponse;  
  31.   
  32. import org.apache.commons.fileupload.DiskFileUpload;  
  33. import org.apache.commons.fileupload.FileItem;  
  34. import org.apache.commons.fileupload.FileUploadException;  
  35. import org.jbpm.api.Deployment;  
  36. import org.jbpm.api.Execution;  
  37. import org.jbpm.api.ExecutionService;  
  38. import org.jbpm.api.HistoryService;  
  39. import org.jbpm.api.ProcessDefinition;  
  40. import org.jbpm.api.ProcessDefinitionQuery;  
  41. import org.jbpm.api.ProcessEngine;  
  42. import org.jbpm.api.ProcessInstance;  
  43. import org.jbpm.api.ProcessInstanceQuery;  
  44. import org.jbpm.api.RepositoryService;  
  45. import org.jbpm.api.TaskService;  
  46. import org.jbpm.api.history.HistoryProcessInstance;  
  47. import org.jbpm.api.history.HistoryTask;  
  48. import org.jbpm.api.task.Task;  
  49. import org.subethamail.wiser.Wiser;  
  50.   
  51. /**  
  52.  * Servlet implementation class ProcessServlet  
  53.  */  
  54. public class ProcessServlet extends HttpServlet {  
  55.     private static final long serialVersionUID = 1L;  
  56.     private JBPMUtil jBPMUtil;  
  57.   
  58.   
  59.     public JBPMUtil getjBPMUtil() {  
  60.         return jBPMUtil;  
  61.     }  
  62.   
  63.     public void setjBPMUtil(JBPMUtil jBPMUtil) {  
  64.         this.jBPMUtil = jBPMUtil;  
  65.         this.processEngine = jBPMUtil.getProcessEngine();  
  66.         this.repositoryService = jBPMUtil.getRepositoryService();  
  67.         this.executionService = jBPMUtil.getExecutionService();  
  68.         this.taskService = jBPMUtil.getTaskService();  
  69.         this.historyService = jBPMUtil.getHistoryService();  
  70.     }  
  71.   
  72.     private ProcessEngine processEngine;  
  73.     private RepositoryService repositoryService;  
  74.     private ExecutionService executionService;  
  75.     private TaskService taskService;  
  76.     private StaffService staffService;  
  77.     private ApplicationService applicationService;  
  78.     private HistoryService historyService;  
  79.   
  80.     public HistoryService getHistoryService() {  
  81.         return historyService;  
  82.     }  
  83.   
  84.     public void setHistoryService(HistoryService historyService) {  
  85.         this.historyService = historyService;  
  86.     }  
  87.   
  88.     // get/set  
  89.     public ProcessEngine getProcessEngine() {  
  90.         return processEngine;  
  91.     }  
  92.   
  93.     public void setProcessEngine(ProcessEngine processEngine) {  
  94.         this.processEngine = processEngine;  
  95.     }  
  96.   
  97.     public RepositoryService getRepositoryService() {  
  98.         return repositoryService;  
  99.     }  
  100.   
  101.     public void setRepositoryService(RepositoryService repositoryService) {  
  102.         this.repositoryService = repositoryService;  
  103.     }  
  104.   
  105.     public ExecutionService getExecutionService() {  
  106.         return executionService;  
  107.     }  
  108.   
  109.     public void setExecutionService(ExecutionService executionService) {  
  110.         this.executionService = executionService;  
  111.     }  
  112.   
  113.     public TaskService getTaskService() {  
  114.         return taskService;  
  115.     }  
  116.   
  117.     public void setTaskService(TaskService taskService) {  
  118.         this.taskService = taskService;  
  119.     }  
  120.   
  121.     public StaffService getStaffService() {  
  122.         return staffService;  
  123.     }  
  124.   
  125.     public void setStaffService(StaffService staffService) {  
  126.         this.staffService = staffService;  
  127.     }  
  128.   
  129.     public ApplicationService getApplicationService() {  
  130.         return applicationService;  
  131.     }  
  132.   
  133.     public void setApplicationService(ApplicationService applicationService) {  
  134.         this.applicationService = applicationService;  
  135.     }  
  136.   
  137.     protected void doGet(HttpServletRequest request,  
  138.             HttpServletResponse response) throws ServletException, IOException {  
  139.         try {  
  140.             process(request, response);  
  141.         } catch (Exception e) {  
  142.             // TODO Auto-generated catch block  
  143.             e.printStackTrace();  
  144.             response.getWriter().write("{success:false,errors:'操作失败!'}");  
  145.         }  
  146.         // TODO Auto-generated method stub  
  147.     }  
  148.   
  149.     protected void doPost(HttpServletRequest request,  
  150.             HttpServletResponse response) throws ServletException, IOException {  
  151.         try {  
  152.             process(request, response);  
  153.         } catch (Exception e) {  
  154.             // TODO Auto-generated catch block  
  155.             e.printStackTrace();  
  156.             response.getWriter().write("{success:false,errors:'操作失败!'}");  
  157.         }  
  158.     }  
  159.   
  160.     /**  
  161.      * @throws Exception  
  162.      *             处理分发类  
  163.      * @throws  
  164.      * */  
  165.     private void process(HttpServletRequest request,  
  166.             HttpServletResponse response) throws Exception {  
  167.         // 设置字符请求编码  
  168.         request.setCharacterEncoding("UTF-8");  
  169.         response.setCharacterEncoding("utf-8");  
  170.         String action = request.getParameter("action");  
  171.         if (action.equals("ds_getAllProcessDefinition")) {  
  172.             // 查询流程定义  
  173.             String json = findProDefintion(request, response);  
  174.             response.getWriter().write(json);  
  175.         } else if (action.equals("deploy")) {  
  176.             // 部署流程  
  177.             deploy(request, response);  
  178.         } else if (action.equals("getAllDeployment")) {  
  179.             // 查询流程部署  
  180.             String json = getDeployment(request, response);  
  181.             response.getWriter().write(json);  
  182.         } else if (action.equals("delDeployment")) {  
  183.             // 删除部署  
  184.             delDeployment(request, response);  
  185.         } else if (action.equals("suspendDeployment")) {  
  186.             // 暂停该部署  
  187.             repositoryService.suspendDeployment(request  
  188.                     .getParameter("deployId"));  
  189.             response.getWriter().write("{success:true}");  
  190.         } else if (action.equals("resumeDeployment")) {  
  191.             // 重启该部署  
  192.             repositoryService  
  193.                     .resumeDeployment(request.getParameter("deployId"));  
  194.             response.getWriter().write("{success:false}");  
  195.         } else if (action.equals("getProcessInstance")) {  
  196.             // 查询流程实例  
  197.             getPorcessInstances(request, response);  
  198.         } else if (action.equals("delProcessInstance")) {  
  199.             // 删除流程实例  
  200.             delProcessInstance(request, response);  
  201.         } else if (action.equals("getHistoryProcessInstance")) {  
  202.             // 查询历史流程实例  
  203.             getHistoryProcessInstance(request, response);  
  204.         } else if (action.equals("delHistoryProcessInstance")) {  
  205.             // 删除历史流程实例  
  206.             delProcessInstance(request, response);  
  207.         } else if (action.equals("getGroupTask")) {  
  208.             // 获取小组任务  
  209.             getGroupTask(request, response);  
  210.         } else if (action.equals("delTask")) {  
  211.             delTask(request, response);  
  212.             // 删除任务  
  213.         } else if (action.equals("getPersonalTask")) {  
  214.             // 获取私人任务  
  215.             getPersionalTask(request, response);  
  216.   
  217.         } else if (action.equals("getHistoryTask")) {  
  218.             // 获取历史任务信息  
  219.             getHistoryTask(request, response);  
  220.         } else if (action.equals("getApplyForm")) {  
  221.             getApplyForm(request, response);  
  222.         } else if (action.equals("accept")) {  
  223.             // 同意申请  
  224.             accept(request, response);  
  225.         } else if (action.equals("reject")) {  
  226.             // 回绝申请  
  227.             reject(request, response);  
  228.         }  
  229.     }  
  230.   
  231.     private void reject(HttpServletRequest request, HttpServletResponse response)  
  232.             throws Exception {  
  233.         int appId = Integer.valueOf(request.getParameter("appId"));  
  234.         String executionId = request.getParameter("executionId");  
  235.         String bmComment = request.getParameter("bmComment");  
  236.         String gmComment = request.getParameter("gmComment");  
  237.         String remark = request.getParameter("remark");  
  238.         String taskId = request.getParameter("taskId");  
  239.   
  240.         ApplicationForm applyform = applicationService  
  241.                 .getApplicationFormById(appId);  
  242.         int userId = (Integer) request.getSession().getAttribute("userId");// 登入用户id  
  243.         Staff staff = staffService.getStaffById(userId);// 当前登入用户  
  244.   
  245.         applyform.setRemark(remark);  
  246.         Execution execution = executionService.findExecutionById(executionId);  
  247.   
  248.         if (execution.getProcessInstance().isActive("副总经理审核")) {  
  249.             applyform.setBranchManager(staff);  
  250.             applyform.setBrMComment(bmComment);  
  251.             executionService.signalExecutionById(executionId, "reject");  
  252.   
  253.         } else if (execution.getProcessInstance().isActive("总经理审核")) {  
  254.             // 总经理拒绝申请  
  255.             applyform.setGeMComment(gmComment);  
  256.             applyform.setGeneralManager(staff);  
  257.             executionService.signalExecutionById(executionId, "reject");  
  258.   
  259.         } else if (execution.getProcessInstance().isActive("give money")) {  
  260.             // 普通员工  
  261.             applyform.setDealStaff(staff);  
  262.             applyform.setCompleteDate(new Date());  
  263.         }  
  264.   
  265.         applicationService.updateApplicationForm(applyform);// 更新表单  
  266.         response.getWriter().write("{success:true}");  
  267.   
  268.     }  
  269.   
  270.     private void accept(HttpServletRequest request, HttpServletResponse response)  
  271.             throws Exception {  
  272.         int appId = Integer.valueOf(request.getParameter("appId"));  
  273.         String executionId = request.getParameter("executionId");  
  274.         String bmComment = request.getParameter("bmComment");  
  275.         String gmComment = request.getParameter("gmComment");  
  276.         String remark = request.getParameter("remark");  
  277.         String taskId = request.getParameter("taskId");  
  278.   
  279.         ApplicationForm applyform = applicationService  
  280.                 .getApplicationFormById(appId);  
  281.         int userId = (Integer) request.getSession().getAttribute("userId");// 副经理id  
  282.         Staff staff = staffService.getStaffById(userId);  
  283.         applyform.setRemark(remark);  
  284.         Execution execution = executionService.findExecutionById(executionId);  
  285.         // 流程变量  
  286.         Map<String, Object> variables = new HashMap<String, Object>();  
  287.         if (execution.getProcessInstance().isActive("副总经理审核")) {  
  288.             applyform.setBranchManager(staff);  
  289.             applyform.setBrMComment(bmComment);  
  290.   
  291.             String content = "";  
  292.             if (applyform.getAmount() > 5000) {  
  293.                 content = "amount larger than 5000";  
  294.                 variables.put("manager", staffService.findManager());  
  295.             } else {  
  296.                 content = "amount less than 5000";  
  297.                 // Role role =roleService.getRoleById(1);  
  298.             }  
  299.             variables.put("content", content);  
  300.             executionService.signalExecutionById(executionId, "accept",  
  301.                     variables);  
  302.   
  303.         } else if (execution.getProcessInstance().isActive("总经理审核")) {  
  304.             // 总经理审核同意  
  305.             applyform.setGeMComment(gmComment);  
  306.             applyform.setGeneralManager(staff);  
  307.   
  308.             executionService.signalExecutionById(executionId, "accept");  
  309.         } else if (execution.getProcessInstance().isActive("give money")) {  
  310.             // 普通员工  
  311.             applyform.setDealStaff(staff);  
  312.             applyform.setCompleteDate(new Date());  
  313.             variables.put("appEmail", applyform.getEmail());  
  314.             variables.put("appName", applyform.getAppName());  
  315.             Calendar deadline = Calendar.getInstance();  
  316.             deadline.add(Calendar.DAY_OF_MONTH, 1);// 期限为一个月  
  317.             variables.put("deadline", deadline.getTime().toString());  
  318.             taskService.setVariables(taskId, variables);  
  319.   
  320.             // start mail server  
  321.             Wiser wiser = new Wiser();  
  322.             wiser.setPort(2525);  
  323.             wiser.start();  
  324.             taskService.completeTask(taskId);  
  325.         }  
  326.         // 更新表单  
  327.         applicationService.updateApplicationForm(applyform);  
  328.           
  329.         // executionService.signalExecutionById(executionId, "accept");  
  330.         response.getWriter().write("{success:true}");  
  331.   
  332.     }  
  333.   
  334.     /**  
  335.      * 获取表单  
  336.      *   
  337.      * @throws Exception  
  338.      * */  
  339.     private void getApplyForm(HttpServletRequest request,  
  340.             HttpServletResponse response) throws Exception {  
  341.         String taskId = request.getParameter("taskId");  
  342.         String type = request.getParameter("etype");  
  343.         int applyId = (Integer) taskService.getVariable(taskId, "applyId");  
  344.         String userId = String.valueOf(request.getSession().getAttribute(  
  345.                 "userId"));  
  346.         if (type.equals("group")) {  
  347.             taskService.takeTask(taskId, userId);  
  348.         }  
  349.         ApplicationForm apply = applicationService  
  350.                 .getApplicationFormById(applyId);  
  351.         response.getWriter().write(ApplyToJson(apply));  
  352.     }  
  353.   
  354.     /**  
  355.      * 将ApplicationForm 数据转换为json格式  
  356.      * */  
  357.     private String ApplyToJson(ApplicationForm apply) {  
  358.         StringBuffer sb = new StringBuffer();  
  359.         sb.append("{apply:[{");  
  360.         sb.append("appId:'" + apply.getAppId() + "',appDate:'"  
  361.                 + apply.getAppDate() + "',appName:'" + apply.getAppName()  
  362.                 + "',appUserId:'" + apply.getAppUserId() + "',email:'"  
  363.                 + apply.getEmail() + "',address:'" + apply.getAddress()  
  364.                 + "',reason:'" + apply.getReason() + "',amount:"  
  365.                 + apply.getAmount() + ",bmComment:'"  
  366.                 + (apply.getBrMComment() == null ? "" : apply.getBrMComment())  
  367.                 + "',gmComment:'"  
  368.                 + (apply.getGeMComment() == null ? "" : apply.getGeMComment())  
  369.                 + "'}]}");  
  370.         return sb.toString();  
  371.     }  
  372.   
  373.     /**  
  374.      * 获取历史任务信息  
  375.      *   
  376.      * @throws Exception  
  377.      * */  
  378.     private void getHistoryTask(HttpServletRequest request,  
  379.             HttpServletResponse response) throws Exception {  
  380.         String condition = request.getParameter("conditions");  
  381.         int start = Integer.valueOf(request.getParameter("start"));  
  382.         int limit = Integer.valueOf(request.getParameter("limit"));  
  383.         String searchType = request.getParameter("searchType");  
  384.         List<HistoryTask> list = new ArrayList();  
  385.         int count = 0;  
  386.         if (searchType.equals("all")) {  
  387.             list = historyService.createHistoryTaskQuery().page(start, limit)  
  388.                     .list();  
  389.             count = historyService.createHistoryTaskQuery().list().size();  
  390.         } else if (condition != "" && condition != null) {  
  391.             if (searchType.endsWith("taskId")) {  
  392.                 list = historyService.createHistoryTaskQuery()  
  393.                         .taskId(condition).page(start, limit).list();  
  394.                 count = historyService.createHistoryTaskQuery()  
  395.                         .taskId(condition).list().size();  
  396.             } else if (searchType.equals("executionId")) {  
  397.                 list = historyService.createHistoryTaskQuery()  
  398.                         .executionId(condition).page(start, limit).list();  
  399.                 count = historyService.createHistoryTaskQuery()  
  400.                         .executionId(condition).list().size();  
  401.             } else if (searchType.equals("startAfter")) {  
  402.                 list = historyService.createHistoryTaskQuery()  
  403.                         .startedAfter(stingToDate(condition))  
  404.                         .page(start, limit).list();  
  405.                 count = historyService.createHistoryTaskQuery()  
  406.                         .startedAfter(stingToDate(condition)).list().size();  
  407.             } else if (searchType.equals("startBefore")) {  
  408.                 list = historyService.createHistoryTaskQuery()  
  409.                         .startedBefore(stingToDate(condition))  
  410.                         .page(start, limit).list();  
  411.                 count = historyService.createHistoryTaskQuery()  
  412.                         .startedBefore(stingToDate(condition)).list().size();  
  413.             } else if (searchType.equals("state")) {  
  414.                 list = historyService.createHistoryTaskQuery().state(condition)  
  415.                         .page(start, limit).list();  
  416.                 count = historyService.createHistoryTaskQuery()  
  417.                         .state(condition).list().size();  
  418.             } else if (searchType.equals("lessThan")) {  
  419.                 list = historyService.createHistoryTaskQuery()  
  420.                         .tookLessThen(Integer.valueOf(condition))  
  421.                         .page(start, limit).list();  
  422.                 count = historyService.createHistoryTaskQuery()  
  423.                         .tookLessThen(Integer.valueOf(condition)).list().size();  
  424.             } else if (searchType.equals("longerThan")) {  
  425.                 list = historyService.createHistoryTaskQuery()  
  426.                         .tookLongerThen(Integer.valueOf(condition))  
  427.                         .page(start, limit).list();  
  428.                 count = historyService.createHistoryTaskQuery()  
  429.                         .tookLongerThen(Integer.valueOf(condition)).list()  
  430.                         .size();  
  431.             } else if (searchType.equals("assignee")) {  
  432.                 list = historyService.createHistoryTaskQuery()  
  433.                         .assignee(condition).page(start, limit).list();  
  434.                 count = historyService.createHistoryTaskQuery()  
  435.                         .assignee(condition).list().size();  
  436.             } else if (searchType.equals("outcome")) {  
  437.                 list = historyService.createHistoryTaskQuery()  
  438.                         .outcome(condition).page(start, limit).list();  
  439.                 count = historyService.createHistoryTaskQuery()  
  440.                         .outcome(condition).list().size();  
  441.             }  
  442.   
  443.         } else if ((condition == "" || condition == null)  
  444.                 && searchType.equals("assignee")) {  
  445.             list = historyService  
  446.                     .createHistoryTaskQuery()  
  447.                     .assignee(  
  448.                             (String) request.getSession().getAttribute("user"))  
  449.                     .page(start, limit).list();  
  450.             count = historyService  
  451.                     .createHistoryTaskQuery()  
  452.                     .assignee(  
  453.                             (String) request.getSession().getAttribute("user"))  
  454.                     .list().size();  
  455.         }  
  456.         response.getWriter().write(historyTaskToJson(list, count));  
  457.     }  
  458.   
  459.     /**  
  460.      * HistoryTask装换成json数据格式  
  461.      * */  
  462.     private String historyTaskToJson(List<HistoryTask> list, int count) {  
  463.         StringBuffer sb = new StringBuffer();  
  464.         sb.append("{totalProperty:" + count);  
  465.         sb.append(",root:[");  
  466.         for (HistoryTask task : list) {  
  467.             sb.append("{id:'" + task.getId() + "',executionId:'"  
  468.                     + task.getExecutionId() + "',assignee:'"  
  469.                     + task.getAssignee() + "',createTime:'"  
  470.                     + task.getCreateTime() + "',endTime:'" + task.getEndTime()  
  471.                     + "',duration:" + task.getDuration() + ",state:'"  
  472.                     + task.getState() + "',outcome:'" + task.getOutcome()  
  473.                     + "'},");  
  474.         }  
  475.         sb.append("]}");  
  476.         if (count != 0) {  
  477.             return sb.substring(0, sb.lastIndexOf(","))  
  478.                     + sb.substring(sb.lastIndexOf(",") + 1);  
  479.         } else {  
  480.             return sb.toString();  
  481.         }  
  482.   
  483.     }  
  484.   
  485.     /**  
  486.      * 时间类型转换  
  487.      *   
  488.      * @throws Exception  
  489.      * */  
  490.     private Date stingToDate(String str) throws Exception {  
  491.         DateFormat df = new SimpleDateFormat("yyyy-MM-dd");  
  492.         return df.parse(str);  
  493.     }  
  494.   
  495.     /**  
  496.      * 查询个人任务  
  497.      *   
  498.      * @throws Exception  
  499.      * */  
  500.     private void getPersionalTask(HttpServletRequest request,  
  501.             HttpServletResponse response) throws Exception {  
  502.         int start = Integer.valueOf(request.getParameter("start"));  
  503.         int limit = Integer.valueOf(request.getParameter("limit"));  
  504.         String searchType = request.getParameter("searchType");  
  505.         String searchState = request.getParameter("searchState");  
  506.         String condition = request.getParameter("conditions");  
  507.   
  508.         List<Task> list = new ArrayList();  
  509.         int count = 0;  
  510.         // 当前登入用户id  
  511.         String userId = String.valueOf(request.getSession().getAttribute(  
  512.                 "userId"));  
  513.         // 查询所有  
  514.         if (searchType.equals("all")) {  
  515.             if (searchState.equals("all")) {  
  516.                 list = taskService.createTaskQuery().page(start, limit).list();  
  517.                 count = taskService.createTaskQuery().list().size();  
  518.             } else if (searchState.equals("suspend")) {  
  519.                 list = taskService.createTaskQuery().suspended()  
  520.                         .page(start, limit).list();  
  521.                 count = taskService.createTaskQuery().suspended().list().size();  
  522.             } else if (searchState.equals("unassigned")) {  
  523.                 list = taskService.createTaskQuery().unassigned()  
  524.                         .page(start, limit).list();  
  525.                 count = taskService.createTaskQuery().unassigned().list()  
  526.                         .size();  
  527.             } else {  
  528.                 list = taskService.createTaskQuery().notSuspended()  
  529.                         .page(start, limit).list();  
  530.                 count = taskService.createTaskQuery().notSuspended().list()  
  531.                         .size();  
  532.             }  
  533.   
  534.         } else if (searchType.equals("assignee")) {  
  535.             // 默认查询当前用户任务类表  
  536.             if (condition == "" || condition == null) {  
  537.                 // 默认查询当前用户任务类表  
  538.                 if (searchState.equals("all")) {  
  539.                     list = taskService.createTaskQuery().assignee(userId)  
  540.                             .page(start, limit).list();  
  541.                     count = taskService.createTaskQuery().assignee(userId)  
  542.                             .list().size();  
  543.                 } else if (searchState.equals("suspend")) {  
  544.                     list = taskService.createTaskQuery().assignee(userId)  
  545.                             .suspended().page(start, limit).list();  
  546.                     count = taskService.createTaskQuery().assignee(userId)  
  547.                             .suspended().list().size();  
  548.                 } else if (searchState.equals("unassigned")) {  
  549.                     list = taskService.createTaskQuery().assignee(userId)  
  550.                             .unassigned().page(start, limit).list();  
  551.                     count = taskService.createTaskQuery().assignee(userId)  
  552.                             .unassigned().list().size();  
  553.                 } else {  
  554.                     list = taskService.createTaskQuery().assignee(userId)  
  555.                             .notSuspended().page(start, limit).list();  
  556.                     count = taskService.createTaskQuery().assignee(userId)  
  557.                             .notSuspended().list().size();  
  558.                 }  
  559.             } else {  
  560.                 // 查询非当前用户  
  561.                 if (searchState.equals("all")) {  
  562.                     list = taskService.createTaskQuery().assignee(condition)  
  563.                             .page(start, limit).list();  
  564.                     count = taskService.createTaskQuery().assignee(condition)  
  565.                             .list().size();  
  566.                 } else if (searchState.equals("suspend")) {  
  567.                     list = taskService.createTaskQuery().assignee(condition)  
  568.                             .suspended().page(start, limit).list();  
  569.                     count = taskService.createTaskQuery().assignee(condition)  
  570.                             .suspended().list().size();  
  571.                 } else if (searchState.equals("unassigned")) {  
  572.                     list = taskService.createTaskQuery().assignee(condition)  
  573.                             .unassigned().page(start, limit).list();  
  574.                     count = taskService.createTaskQuery().assignee(condition)  
  575.                             .unassigned().list().size();  
  576.                 } else {  
  577.                     list = taskService.createTaskQuery().assignee(condition)  
  578.                             .notSuspended().page(start, limit).list();  
  579.                     count = taskService.createTaskQuery().assignee(condition)  
  580.                             .notSuspended().list().size();  
  581.                 }  
  582.             }  
  583.         } else if (searchType.equals("taskId")) {  
  584.             if (condition != "" && condition != null) {  
  585.                 if (taskService.getTask(condition) != null) {  
  586.                     list.add(taskService.getTask(condition));  
  587.                     count = 1;  
  588.                 }  
  589.             }  
  590.         } else if (searchType.equals("activityName")) {  
  591.   
  592.             if (condition != "" && condition != null) {  
  593.   
  594.                 if (searchState.equals("all")) {  
  595.                     list = taskService.createTaskQuery()  
  596.                             .activityName(condition).page(start, limit).list();  
  597.                     count = taskService.createTaskQuery()  
  598.                             .activityName(condition).list().size();  
  599.                 } else if (searchState.equals("suspend")) {  
  600.                     list = taskService.createTaskQuery()  
  601.                             .activityName(condition).suspended()  
  602.                             .page(start, limit).list();  
  603.                     count = taskService.createTaskQuery()  
  604.                             .activityName(condition).suspended().list().size();  
  605.                 } else if (searchState.equals("unassigned")) {  
  606.                     list = taskService.createTaskQuery()  
  607.                             .activityName(condition).unassigned()  
  608.                             .page(start, limit).list();  
  609.                     count = taskService.createTaskQuery()  
  610.                             .activityName(condition).unassigned().list().size();  
  611.                 } else {  
  612.                     list = taskService.createTaskQuery()  
  613.                             .activityName(condition).notSuspended()  
  614.                             .page(start, limit).list();  
  615.                     count = taskService.createTaskQuery()  
  616.                             .activityName(condition).notSuspended().list()  
  617.                             .size();  
  618.                 }  
  619.             }  
  620.         } else if (searchType.equals("candidate")) {  
  621.   
  622.             if (condition != "" && condition != null) {  
  623.                 if (searchState.equals("all")) {  
  624.                     list = taskService.createTaskQuery().candidate(condition)  
  625.                             .page(start, limit).list();  
  626.                     count = taskService.createTaskQuery().candidate(condition)  
  627.                             .list().size();  
  628.                 } else if (searchState.equals("suspend")) {  
  629.                     list = taskService.createTaskQuery().candidate(condition)  
  630.                             .suspended().page(start, limit).list();  
  631.                     count = taskService.createTaskQuery().candidate(condition)  
  632.                             .suspended().list().size();  
  633.                 } else if (searchState.equals("unassigned")) {  
  634.                     list = taskService.createTaskQuery().candidate(condition)  
  635.                             .unassigned().page(start, limit).list();  
  636.                     count = taskService.createTaskQuery().candidate(condition)  
  637.                             .unassigned().list().size();  
  638.                 } else {  
  639.                     list = taskService.createTaskQuery().candidate(condition)  
  640.                             .notSuspended().page(start, limit).list();  
  641.                     count = taskService.createTaskQuery().candidate(condition)  
  642.                             .notSuspended().list().size();  
  643.                 }  
  644.             }  
  645.         } else if (searchType.equals("processDefinitionId")) {  
  646.   
  647.             if (condition != "" || condition != null) {  
  648.                 // 默认查询当前用户任务类表  
  649.                 if (searchState.equals("all")) {  
  650.                     list = taskService.createTaskQuery()  
  651.                             .processDefinitionId(condition).page(start, limit)  
  652.                             .list();  
  653.                     count = taskService.createTaskQuery()  
  654.                             .processDefinitionId(condition).list().size();  
  655.                 } else if (searchState.equals("suspend")) {  
  656.                     list = taskService.createTaskQuery()  
  657.                             .processDefinitionId(condition).suspended()  
  658.                             .page(start, limit).list();  
  659.                     count = taskService.createTaskQuery()  
  660.                             .processDefinitionId(condition).suspended().list()  
  661.                             .size();  
  662.                 } else if (searchState.equals("unassigned")) {  
  663.                     list = taskService.createTaskQuery()  
  664.                             .processDefinitionId(condition).unassigned()  
  665.                             .page(start, limit).list();  
  666.                     count = taskService.createTaskQuery()  
  667.                             .processDefinitionId(condition).unassigned().list()  
  668.                             .size();  
  669.                 } else {  
  670.                     list = taskService.createTaskQuery()  
  671.                             .processDefinitionId(condition).notSuspended()  
  672.                             .page(start, limit).list();  
  673.                     count = taskService.createTaskQuery()  
  674.                             .processDefinitionId(condition).notSuspended()  
  675.                             .list().size();  
  676.                 }  
  677.             }  
  678.         } else if (searchType.equals("processInstanceId")) {  
  679.             if (condition != "" || condition != null) {  
  680.                 // 默认查询当前用户任务类表  
  681.                 if (searchState.equals("all")) {  
  682.                     list = taskService.createTaskQuery()  
  683.                             .processInstanceId(condition).page(start, limit)  
  684.                             .list();  
  685.                     count = taskService.createTaskQuery()  
  686.                             .processInstanceId(condition).list().size();  
  687.                 } else if (searchState.equals("suspend")) {  
  688.                     list = taskService.createTaskQuery()  
  689.                             .processInstanceId(condition).suspended()  
  690.                             .page(start, limit).list();  
  691.                     count = taskService.createTaskQuery()  
  692.                             .processInstanceId(condition).suspended().list()  
  693.                             .size();  
  694.                 } else if (searchState.equals("unassigned")) {  
  695.                     list = taskService.createTaskQuery()  
  696.                             .processInstanceId(condition).unassigned()  
  697.                             .page(start, limit).list();  
  698.                     count = taskService.createTaskQuery()  
  699.                             .processInstanceId(condition).unassigned().list()  
  700.                             .size();  
  701.                 } else {  
  702.                     list = taskService.createTaskQuery()  
  703.                             .processInstanceId(condition).notSuspended()  
  704.                             .page(start, limit).list();  
  705.                     count = taskService.createTaskQuery()  
  706.                             .processInstanceId(condition).notSuspended().list()  
  707.                             .size();  
  708.                 }  
  709.             }  
  710.         }  
  711.   
  712.         response.getWriter().write(TaskToJson(list, count));  
  713.   
  714.     }  
  715.   
  716.     /**  
  717.      * 删除任务  
  718.      *   
  719.      * @throws Exception  
  720.      * */  
  721.     private void delTask(HttpServletRequest request,  
  722.             HttpServletResponse response) throws Exception {  
  723.         String id = request.getParameter("id");  
  724.         String type = request.getParameter("type");  
  725.         if (type.equals("normal")) {  
  726.             taskService.deleteTask(id);  
  727.         } else {  
  728.             taskService.deleteTaskCascade(id);  
  729.         }  
  730.         response.getWriter().write("{success:true}");  
  731.     }  
  732.   
  733.     /**  
  734.      * 根据userid获取小组任务  
  735.      *   
  736.      * @throws Exception  
  737.      * */  
  738.     private void getGroupTask(HttpServletRequest request,  
  739.             HttpServletResponse response) throws Exception {  
  740.         List<Task> list = new ArrayList();  
  741.         // 默认为登入用户id  
  742.         String userId = String.valueOf(request.getSession().getAttribute(  
  743.                 "userId"));  
  744.         String userName = (String) request.getSession().getAttribute("user");  
  745.         // 查询用户id  
  746.         String searchId = (String) request.getParameter("conditions");  
  747.         int start = Integer.parseInt((String) request.getParameter("start"));  
  748.         int limit = Integer.parseInt((String) request.getParameter("limit"));  
  749.         if (searchId == "" || searchId == null) {  
  750.             list = taskService.findGroupTasks(userId);  
  751.         } else {  
  752.             list = taskService.findGroupTasks(searchId);  
  753.         }  
  754.         // 记录总数  
  755.         int count = list.size();  
  756.         if (list.size() <= limit) {  
  757.             // 分页  
  758.             list = list.subList(start, list.size());  
  759.         } else {  
  760.             list = list.subList(start, limit);  
  761.         }  
  762.   
  763.         response.getWriter().write(TaskToJson(list, count));  
  764.     }  
  765.   
  766.     /**  
  767.      * 将Task装换为Json数据格式  
  768.      * */  
  769.     private String TaskToJson(List<Task> list, int count) {  
  770.         StringBuffer sb = new StringBuffer();  
  771.         sb.append("{totalProperty:" + count);  
  772.         sb.append(",root:[");  
  773.         for (Task task : list) {  
  774.             sb.append("{id:'" + task.getId() + "',name:'" + task.getName()  
  775.                     + "',executionId:'" + task.getExecutionId()  
  776.                     + "',activityName:'" + task.getActivityName()  
  777.                     + "',assignee:'" + task.getAssignee() + "',createTime:'"  
  778.                     + task.getCreateTime() + "',dueDate:'" + task.getDuedate()  
  779.                     + "',formResourceName:'" + task.getFormResourceName()  
  780.                     + "',priority:" + task.getPriority() + ",description:'"  
  781.                     + task.getDescription() + "'},");  
  782.         }  
  783.         sb.append("]}");  
  784.         if (count != 0) {  
  785.             return sb.substring(0, sb.lastIndexOf(","))  
  786.                     + sb.substring(sb.lastIndexOf(",") + 1);  
  787.         } else {  
  788.             return sb.toString();  
  789.         }  
  790.     }  
  791.   
  792.     /**  
  793.      * 查询历史流程实例  
  794.      *   
  795.      * @throws Exception  
  796.      * */  
  797.     private void getHistoryProcessInstance(HttpServletRequest request,  
  798.             HttpServletResponse response) throws Exception {  
  799.         String id = request.getParameter("conditions");  
  800.         String type = request.getParameter("searchType");  
  801.         int start = Integer.valueOf(request.getParameter("start"));  
  802.         int limit = Integer.valueOf(request.getParameter("limit"));  
  803.         List<HistoryProcessInstance> list = new ArrayList();  
  804.         int count = 0;  
  805.         if (type.equals("all")) {  
  806.             list = historyService.createHistoryProcessInstanceQuery()  
  807.                     .page(start, limit).list();  
  808.             count = historyService.createHistoryProcessInstanceQuery().list()  
  809.                     .size();  
  810.         } else if (type.equals("processInstanceId")) {  
  811.             list = historyService.createHistoryProcessInstanceQuery()  
  812.                     .processInstanceId(id).page(start, limit).list();  
  813.             count = historyService.createHistoryProcessInstanceQuery()  
  814.                     .processInstanceId(id).list().size();  
  815.         } else {  
  816.             list = historyService.createHistoryProcessInstanceQuery()  
  817.                     .processDefinitionId(id).page(start, limit).list();  
  818.             count = historyService.createHistoryProcessInstanceQuery()  
  819.                     .processDefinitionId(id).list().size();  
  820.         }  
  821.         response.getWriter().write(historyProcessInstanceToJson(list, count));  
  822.     }  
  823.   
  824.     /**  
  825.      * List<HistoryProcessInstance>装换成json数据格式  
  826.      * */  
  827.     private String historyProcessInstanceToJson(  
  828.             List<HistoryProcessInstance> list, int count) {  
  829.         StringBuffer sb = new StringBuffer();  
  830.         sb.append("{totalProperty:" + count);  
  831.         sb.append(",root:[");  
  832.         for (HistoryProcessInstance hpi : list) {  
  833.             sb.append("{processInstanceId:'" + hpi.getProcessInstanceId()  
  834.                     + "',processDefinitionId:'" + hpi.getProcessDefinitionId()  
  835.                     + "',key:'" + hpi.getKey() + "',duration:"  
  836.                     + hpi.getDuration() + ",startTime:'" + hpi.getStartTime()  
  837.                     + "',endTime:'" + hpi.getEndTime() + "',state:'"  
  838.                     + hpi.getState() + "'},");  
  839.         }  
  840.         sb.append("]}");  
  841.         if (count != 0) {  
  842.             return sb.substring(0, sb.lastIndexOf(","))  
  843.                     + sb.substring(sb.lastIndexOf(",") + 1);  
  844.         } else {  
  845.             return sb.toString();  
  846.         }  
  847.     }  
  848.   
  849.     /**  
  850.      * 删除流程实例  
  851.      *   
  852.      * @throws Exception  
  853.      * */  
  854.     private void delProcessInstance(HttpServletRequest request,  
  855.             HttpServletResponse response) throws Exception {  
  856.         String id = request.getParameter("id");  
  857.         String type = request.getParameter("type");  
  858.         if (type.equals("normal")) {  
  859.             // 删除流程实例  
  860.             executionService.deleteProcessInstance(id);  
  861.         } else {  
  862.             // 级联删除  
  863.             executionService.deleteProcessInstanceCascade(id);  
  864.         }  
  865.         response.getWriter().write("{success:true}");  
  866.     }  
  867.   
  868.     /**  
  869.      * 流程实例查询  
  870.      *   
  871.      * @throws Exception  
  872.      * */  
  873.     private void getPorcessInstances(HttpServletRequest request,  
  874.             HttpServletResponse response) throws Exception {  
  875.         String searchType = request.getParameter("searchType");  
  876.         String value = request.getParameter("conditions");  
  877.         int start = Integer.valueOf(request.getParameter("start"));  
  878.         int limit = Integer.valueOf(request.getParameter("limit"));  
  879.         String searchStateType = request.getParameter("searchStateType");  
  880.         int count = 0;  
  881.         List<ProcessInstance> pis = new ArrayList();  
  882.         if (searchType.equals("all")) {  
  883.             if (searchStateType.equals("all")) {  
  884.                 pis = executionService.createProcessInstanceQuery()  
  885.                         .page(start, limit).list();  
  886.                 count = executionService.createProcessInstanceQuery().list()  
  887.                         .size();  
  888.             } else if (searchStateType.equals("suspend")) {  
  889.                 // select only suspended process definitions  
  890.                 pis = executionService.createProcessInstanceQuery().suspended()  
  891.                         .page(start, limit).list();  
  892.                 count = executionService.createProcessInstanceQuery()  
  893.                         .suspended().list().size();  
  894.             } else {  
  895.                 // select only process definitions that are not suspended  
  896.                 pis = executionService.createProcessInstanceQuery()  
  897.                         .notSuspended().page(start, limit).list();  
  898.                 count = executionService.createProcessInstanceQuery()  
  899.                         .notSuspended().list().size();  
  900.             }  
  901.   
  902.         } else if (value != "" && value != null) {  
  903.   
  904.             if (searchType.equals("processDefinitionId")) {  
  905.                 if (searchStateType.equals("all")) {  
  906.                     pis = executionService.createProcessInstanceQuery()  
  907.                             .processDefinitionId(value).page(start, limit)  
  908.                             .list();  
  909.                     count = executionService.createProcessInstanceQuery()  
  910.                             .processDefinitionId(value).list().size();  
  911.                 } else if (searchStateType.equals("suspend")) {  
  912.                     //  
  913.                     pis = executionService.createProcessInstanceQuery()  
  914.                             .suspended().processDefinitionId(value)  
  915.                             .page(start, limit).list();  
  916.                     count = executionService.createProcessInstanceQuery()  
  917.                             .suspended().processDefinitionId(value).list()  
  918.                             .size();  
  919.   
  920.                 } else {  
  921.                     //  
  922.                     pis = executionService.createProcessInstanceQuery()  
  923.                             .notSuspended().processDefinitionId(value)  
  924.                             .page(start, limit).list();  
  925.                     count = executionService.createProcessInstanceQuery()  
  926.                             .notSuspended().processDefinitionId(value).list()  
  927.                             .size();  
  928.                 }  
  929.   
  930.             } else if (searchType.equals("processInstanceId")) {  
  931.                 //  
  932.                 if (searchStateType.equals("all")) {  
  933.                     pis = executionService.createProcessInstanceQuery()  
  934.                             .processInstanceId(value).page(start, limit).list();  
  935.                     count = executionService.createProcessInstanceQuery()  
  936.                             .processInstanceId(value).list().size();  
  937.   
  938.                 } else if (searchStateType.equals("suspend")) {  
  939.                     pis = executionService.createProcessInstanceQuery()  
  940.                             .suspended().processInstanceId(value)  
  941.                             .page(start, limit).list();  
  942.                     count = executionService.createProcessInstanceQuery()  
  943.                             .suspended().processInstanceId(value).list().size();  
  944.   
  945.                 } else {  
  946.                     pis = executionService.createProcessInstanceQuery()  
  947.                             .notSuspended().processInstanceId(value)  
  948.                             .page(start, limit).list();  
  949.                     count = executionService.createProcessInstanceQuery()  
  950.                             .notSuspended().processInstanceId(value).list()  
  951.                             .size();  
  952.                 }  
  953.   
  954.             } 


原文链接:http://blog.csdn.net/wangxiaojing123/article/details/7070877
加载中
返回顶部
顶部