主页
流程定义文件
<?xml version="1.0" encoding="UTF-8"?> <process name="loan" xmlns="http://jbpm.org/4.0/jpdl"> <start g="376,61,65,48" name="start"> <transition g="-52,-15" name="to fill in applycation" to="fill in application"> </transition> </start> <task g="335,204,132,60" assignee="anyone" name="fill in application"> <transition name="submit applicaton" to="副总经理审核" g="-55,-14"/> </task> <task candidate-groups="副总经理" g="279,361,244,81" name="副总经理审核"> <transition g="-29,-25" name="accept" to="exclusive amount"/> <transition g="-20,-25" name="reject" to="end"/> </task> <decision expr="#{content}" g="80,377,60,48" name="exclusive amount"> <transition g="-50,-23" name="amount larger than 5000" to="总经理审核"> </transition> <transition g="-94,-22" name="amount less than 5000" to="give money"> </transition> </decision> <task assignee="#{manager.incumbent}" g="4,645,199,65" name="总经理审核"> <transition g="-79,-30" name="accept" to="give money"/> <transition g="415,712:-45,-22" name="reject" to="end"/> </task> <task candidate-groups="服务员" g="327,601,144,66" name="give money"> <transition g="-45,-22" name="send Email" to="end"> <mail> <to addresses="#{appEmail}"/> <subject>success to load money!</subject> <text>dear ${appName},you have pass through examine!please goto the bank before ${deadline}</text> </mail> </transition> </task> <end g="649,647,48,48" name="end"/> </process>
spring 与jbpm4.4结合的配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" /> <property name="dataSource" ref="dataSource" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> <property name="dataSource" ref="dataSource" /> </bean> <!-- 定义事务拦截器 --> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <!-- 注入事务管理 --> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <!-- 定义事务传播属性 --> <props><!-- <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="del*">PROPAGATION_REQUIRED</prop> --> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- 定义BeanNameAutoProxyCreator --> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <!-- 指定对满足哪些bean name的bean自动生成业务代理 --> <property name="beanNames"> <!-- 下面是所有需要自动创建事务代理的bean --> <list> <value>roleService</value> <value>staffService</value> <value>applicationService</value> <value>leaveServlet</value> </list> <!-- 此处可增加其他需要自动创建事务代理的bean --> </property> <!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器 --> <property name="interceptorNames"> <list> <!-- 此处可增加其他新的Interceptor --> <value>transactionInterceptor</value> </list> </property> </bean> <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper"> <property name="jbpmCfg" value="jbpm.cfg.xml" /> </bean> <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" /> <bean id="jBPMUtil" class="hust.loan.dao.util.JBPMUtil"> <property name="processEngine" ref="processEngine"></property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/loandb" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> </beans>
jbpm配置文件:
<?xml version="1.0" encoding="UTF-8"?> <jbpm-configuration> <import resource="jbpm.default.cfg.xml" /> <import resource="jbpm.tx.hibernate.cfg.xml" /> <import resource="jbpm.tx.spring.cfg.xml" /> <import resource="jbpm.jpdl.cfg.xml" /> <import resource="jbpm.bpmn.cfg.xml" /> <import resource="jbpm.identity.cfg.xml" /> <import resource="jbpm.businesscalendar.cfg.xml" /> <import resource="jbpm.console.cfg.xml" /> <!-- <import resource="jbpm.jobexecutor.cfg.xml" /> --> <hibernate-session-factory /> </jbpm-configuration>
hibernate 配置文件:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- mysql database --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/loandb</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.format_sql">true</property> <property name="show_sql">true</property> <property name="hibernate.current_session_context_class"> thread </property> <mapping resource="jbpm.repository.hbm.xml" /> <mapping resource="jbpm.execution.hbm.xml" /> <mapping resource="jbpm.history.hbm.xml" /> <mapping resource="jbpm.task.hbm.xml" /> <mapping resource="jbpm.identity.hbm.xml" /> <mapping resource="hust/loan/po/xml/Role.hbm.xml" /> <mapping resource="hust/loan/po/xml/Staff.hbm.xml" /> <mapping resource="hust/loan/po/xml/ApplicationForm.hbm.xml" /> </session-factory> </hibernate-configuration>
处理贷款的类:
package hust.loan.servlet; import hust.loan.dao.util.JBPMUtil; import hust.loan.dao.util.Page; import hust.loan.po.ApplicationForm; import hust.loan.po.Role; import hust.loan.po.Staff; import hust.loan.service.ApplicationService; import hust.loan.service.RoleService; import hust.loan.service.StaffService; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import net.sf.json.*; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jbpm.api.ExecutionService; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.RepositoryService; import org.jbpm.api.TaskService; import org.jbpm.api.task.Task; /** * 贷款例子处理servlet的 * * @author seven */ public class LoanServlet extends HttpServlet { private static final long serialVersionUID = 1L; private JBPMUtil jBPMUtil; public JBPMUtil getjBPMUtil() { return jBPMUtil; } public void setjBPMUtil(JBPMUtil jBPMUtil) { this.jBPMUtil = jBPMUtil; processEngine=jBPMUtil.getProcessEngine(); repositoryService=jBPMUtil.getRepositoryService(); executionService = jBPMUtil.getExecutionService(); taskService= jBPMUtil.getTaskService(); } private ProcessEngine processEngine; private RepositoryService repositoryService; private ExecutionService executionService; private TaskService taskService; private RoleService roleService; private StaffService staffService; private ApplicationService applicationService; private ProcessInstance processInstance;// 流程实例 // get/set方法 public StaffService getStaffService() { return staffService; } public void setStaffService(StaffService staffService) { this.staffService = staffService; } public ApplicationService getApplicationService() { return applicationService; } public void setApplicationService(ApplicationService applicationService) { this.applicationService = applicationService; } public RoleService getRoleService() { return roleService; } public void setRoleService(RoleService roleService) { this.roleService = roleService; } public ProcessEngine getProcessEngine() { return processEngine; } public void setProcessEngine(ProcessEngine processEngine) { this.processEngine = processEngine; } public RepositoryService getRepositoryService() { return repositoryService; } public void setRepositoryService(RepositoryService repositoryService) { this.repositoryService = repositoryService; } public ExecutionService getExecutionService() { return executionService; } public void setExecutionService(ExecutionService executionService) { this.executionService = executionService; } public TaskService getTaskService() { return taskService; } public void setTaskService(TaskService taskService) { this.taskService = taskService; } // end-get/set public void init(ServletConfig config) throws ServletException { super.init(config); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { process(request, response); // TODO Auto-generated method stub } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { process(request, response); } /** * 处理分发类 * * @throws IOException * @throws ServletException * */ private void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 设置字符请求编码 request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("utf-8"); String action = request.getParameter("action"); if (action.equals("addRole")) { if (addRole(request, response)) { response.getWriter().write("{success:true}"); } else { response.getWriter().write("{failure:true}"); } } else if (action.equals("toAddRole")) { // 转移到添加角色页面 request.getRequestDispatcher("/loan/loan_addRole.jsp").forward( request, response); } else if (action.equals("toAddStaff")) { // 转移到添加员工页面 request.getRequestDispatcher("/loan/loan_addStaff.jsp").forward( request, response); } else if (action.equals("getAllRole")) { // 查找所有角色 List<Role> roles = roleService.getRoles(); // 转换为json格式数据 response.getWriter().write(beanToJsonString(roles, false)); } else if (action.equals("addStaff")) { // 添加员工 if (addStaff(request, response)) { response.getWriter().write("{success:true}"); } else { response.getWriter().write("{failure:true}"); } } else if (action.equals("addApply")) { String validateCode = request.getSession().getAttribute("rand") .toString(); System.out.println("validate:" + request.getParameter("validateCode")); System.out.println("randCode:" + validateCode); if (validateCode.equals(request.getParameter("validateCode"))) { int applyId = addApply(request, response); if (applyId > 0) { response.getWriter().write( "{success:true,applyId:" + applyId + "}"); } else { response.getWriter().write("{failure:true,mes:'申请失败'}"); } } else { response.getWriter().write("{failure:true,mes:'验证码错误'}"); } } else if (action.equals("toAddApply")) { // 转移到填写申请单页面 request.getRequestDispatcher("/loan/loan_addApply.jsp").forward( request, response); } else if (action.equals("getAllStaff")) { String start = request.getParameter("start"); String limit = request.getParameter("limit"); Page page = new Page(); page.setStartIndex(Integer.valueOf(start)); page.setLastIndex(Integer.valueOf(limit)); String json = this.getStaffs(page); response.getWriter().write(json); } else if (action.equals("toStaffGrid")) { request.getRequestDispatcher("/loan/loan_staffgrid.jsp").forward( request, response); } else if (action.equals("saveStaff")) { // 保存职员 String data = request.getParameter("data"); List<Staff> staffs = this.getStaffFromJson(data); if (!staffs.isEmpty()) { for (Staff staff : staffs) { staffService.updateStaff(staff); } response.getWriter().write("保存成功!"); } // response.getWriter().write("保存成功!"); } else if (action.equals("delStaff")) { // 删除员工 String data = request.getParameter("data"); List<Staff> staffs = this.getStaffFromJson(data); if (!staffs.isEmpty()) { for (Staff staff : staffs) { staffService.delStaff(staff); } response.getWriter().write("删除成功!"); } } else if (action.equals("toManagerTree")) { // 跳转到树形页面 request.getRequestDispatcher("/loan/loan_managerTree.jsp").forward( request, response); } else if (action.equals("toLogin")) { // 登入首页 request.getRequestDispatcher("/loan/loan_index.jsp").forward( request, response); } else if (action.equals("logout")) { // 退出系统 request.getSession().removeAttribute("name"); request.getSession().removeAttribute("roleType"); request.getSession().invalidate(); response.getWriter().write("{success:true}"); } else if (action.equals("login")) { // 登入 String name = (String) request.getParameter("name"); String password = (String) request.getParameter("password"); Staff staff = staffService .getStaffByNameAndPassword(name, password); if (staff != null) { request.getSession().setAttribute("user", staff.getName()); request.getSession().setAttribute("userType", staff.getRole().getRoleType()); request.getSession().setAttribute("userId", staff.getStaffId()); response.getWriter().write("{success:true}"); } else { response.getWriter().write("{failure:true}"); } } else if (action.equals("ds_getAllRole")) { // 获取所有角色详细信息 List<Role> roles = roleService.getRoles(); // 装换成json格式数据 String jsonString = this.beanToJsonString(roles, true); response.getWriter().write(jsonString); } else if (action.equals("delRole")) { // 删除角色 String roleId = request.getParameter("roleId"); if (roleService.delRole(roleService.getRoleById(Integer .valueOf(roleId)))) { response.getWriter().flush(); response.getWriter().write("{success:true}"); } else { response.getWriter().write("{failure:true}"); } } else if (action.equals("updateRole")) { // 更新角色 Role role = new Role(); role.setRoleId(Integer.valueOf(request.getParameter("roleId"))); role.setRoleName(request.getParameter("roleName")); role.setRoleType(request.getParameter("roleType")); role.setDescription(request.getParameter("description")); try { roleService.updateRole(role); response.getWriter().write("{success:true}"); } catch (Exception e) { response.getWriter().write("{failure:true}"); } } else { request.getRequestDispatcher("/loan/index.jsp").forward(request, response); } } /** * 添加申请单 * */ private int addApply(HttpServletRequest request, HttpServletResponse response) { // 根据流程定义的KEY值启动一个新的流程实例 processInstance = executionService.startProcessInstanceByKey("loan"); // 判断流程定义的活动是否是“填写表单”的活动 if (processInstance.isActive("fill in application")) { ApplicationForm applyform = new ApplicationForm(); applyform.setAppUserId(request.getParameter("appUserId")); applyform.setAppName(request.getParameter("appName")); applyform.setAppDate(new Date()); applyform.setAddress(request.getParameter("address")); applyform .setAmount(Integer.valueOf(request.getParameter("amount"))); applyform.setReason(request.getParameter("reason")); applyform.setEmail(request.getParameter("email")); int appid = applicationService.addApplicationForm(applyform); // 流程变量 Map<String, Object> variables = new HashMap<String, Object>(); variables.put("applyId", appid); List<Task> tasks = taskService.findPersonalTasks("anyone"); // 根据任务列表获取任务 Task task = tasks.get(0); // 把设置好的变量放到任务服务里面并根据任务ID结束任务 taskService.setVariables(task.getId(), variables); taskService.completeTask(task.getId()); // 进入到副总经理审核阶段 // List<Task> list=taskService.findGroupTasks("man"); return appid; } else { return 0; } } /** * 添加角色 * */ private boolean addRole(HttpServletRequest request, HttpServletResponse response) { // 添加角色 String roleName = (String) request.getParameter("roleName"); String roleType = (String) request.getParameter("roleType"); String description = (String) request.getParameter("description"); Role role = new Role(); role.setRoleName(roleName); role.setRoleType(roleType); role.setDescription(description); // 添加角色到数据库中 return roleService.addRole(role); } /** * 添加员工 * @throws IOException * */ public boolean addStaff(HttpServletRequest request, HttpServletResponse response) throws IOException { Staff staff = new Staff(); staff.setName(request.getParameter("name")); staff.setEmail(request.getParameter("email")); staff.setPassword(request.getParameter("password")); staff.setAddress(request.getParameter("address")); System.out.println("roleid" + request.getParameter("roleId")); Role role = roleService.getRoleById(Integer.valueOf(request .getParameter("roleId"))); staff.setRole(role); try { staffService.addStaff(staff); return true; } catch (Exception e) { e.printStackTrace(); return false; } } /** * 将角色类型数据返回json数据格式 * */ private String beanToJsonString(List<Role> roles, boolean all) { StringBuffer jsonString = new StringBuffer(); jsonString.append("{root:["); // 返回全部 if (all) { for (Role role : roles) { jsonString.append("{roleId:" + role.getRoleId() + ",roleName:'" + role.getRoleName() + "'," + "roleType:'" + role.getRoleType() + "',description:'" + role.getDescription() + "'},"); } } else { for (Role role : roles) { jsonString.append("{roleName:'" + role.getRoleName() + "',roleId:'" + role.getRoleId() + "'},"); } } jsonString.append("]}"); return jsonString.substring(0, jsonString.lastIndexOf(",")) + jsonString.substring(jsonString.lastIndexOf(",") + 1); } /** * 分页返回员工信息列表 * */ @SuppressWarnings("unchecked") private String getStaffs(Page page) { StringBuffer jsonString = new StringBuffer(); page = staffService.getStaffs(page); List<Staff> staffs = page.getList(); jsonString.append("{totalProperty:"); jsonString.append(page.getTotalCount()); jsonString.append(",root:["); for (Staff staff : staffs) { jsonString.append("{staffId:" + staff.getStaffId()); jsonString.append(",name:'" + staff.getName()); jsonString.append("',address:'" + staff.getAddress()); jsonString.append("',email:'" + staff.getEmail()); jsonString.append("',roleId:'" + staff.getRole().getRoleId()); jsonString.append("',roleName:'" + staff.getRole().getRoleName() + "'},"); } jsonString.append("]}"); return jsonString.substring(0, jsonString.lastIndexOf(",")) + jsonString.substring(jsonString.lastIndexOf(",") + 1); } /** * 把json转换成bean * */ private List<Staff> getStaffFromJson(String jsonData) { List<Staff> list = new ArrayList<Staff>(); try { JSONArray array = JSONArray.fromObject(jsonData); Staff staff = new Staff(); Role role = new Role(); for (int i = 0; i < array.size(); i++) { JSONObject jo = array.getJSONObject(i); staff.setStaffId(jo.getInt("staffId")); staff = staffService.getStaffById(jo.getInt("staffId")); /* * staff.setAddress(jo.getString("address")); * staff.setEmail(jo.getString("email")); * staff.setName(jo.getString("name")); role = * roleService.getRoleById(Integer.parseInt(jo * .getString("roleId"))); staff.setRole(role); */ list.add(staff); } } catch (JSONException e) { e.printStackTrace(); } return list; } }
流程处理工具类:
package hust.loan.dao.util; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.zip.ZipInputStream; import javax.servlet.http.HttpSession; import org.jbpm.api.Execution; import org.jbpm.api.ExecutionService; import org.jbpm.api.HistoryService; import org.jbpm.api.IdentityService; import org.jbpm.api.ManagementService; import org.jbpm.api.ProcessDefinition; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.RepositoryService; import org.jbpm.api.TaskService; import org.jbpm.api.task.Task; /** * jbpm工具类 * * @author ht * */ public class JBPMUtil { private ProcessEngine processEngine; private RepositoryService repositoryService = null; private ExecutionService executionService = null; private TaskService taskService = null; private HistoryService historyService = null; private ManagementService managementService = null; private IdentityService identityService = null; public JBPMUtil() { } public JBPMUtil(ProcessEngine processEngine) { this.processEngine = processEngine; repositoryService = processEngine.getRepositoryService(); executionService = processEngine.getExecutionService(); taskService = processEngine.getTaskService(); historyService = processEngine.getHistoryService(); managementService = processEngine.getManagementService(); identityService = processEngine.getIdentityService(); } public ProcessEngine getProcessEngine() { return processEngine; } public void setProcessEngine(ProcessEngine processEngine) { this.processEngine = processEngine; System.out.println("processEngine=" + processEngine); repositoryService = processEngine.getRepositoryService(); executionService = processEngine.getExecutionService(); taskService = processEngine.getTaskService(); historyService = processEngine.getHistoryService(); managementService = processEngine.getManagementService(); identityService = processEngine.getIdentityService(); } public IdentityService getIdentityService() { return identityService; } public void setIdentityService(IdentityService identityService) { this.identityService = identityService; } public RepositoryService getRepositoryService() { return repositoryService; } public void setRepositoryService(RepositoryService repositoryService) { this.repositoryService = repositoryService; } public ExecutionService getExecutionService() { return executionService; } public void setExecutionService(ExecutionService executionService) { this.executionService = executionService; } public TaskService getTaskService() { return taskService; } public void setTaskService(TaskService taskService) { this.taskService = taskService; } public HistoryService getHistoryService() { return historyService; } public void setHistoryService(HistoryService historyService) { this.historyService = historyService; } public ManagementService getManagementService() { return managementService; } public void setManagementService(ManagementService managementService) { this.managementService = managementService; } /** * 部署新流程定义 * * @param resourceName * @return 返回流程定义id */ public String deployNew(String resourceName) { return repositoryService.createDeployment() .addResourceFromClasspath(resourceName).deploy(); } /** * 部署新流程定义(zip) * * @param resourceName * @return 返回流程定义id */ public String deployZipNew(String resourceZipName) { ZipInputStream zis = new ZipInputStream(this.getClass() .getResourceAsStream(resourceZipName)); return repositoryService.createDeployment() .addResourcesFromZipInputStream(zis).deploy(); } /** * 开始一个流程实例 * * @param id * @param map * @return */ public ProcessInstance startPIById(String id, Map<String, ?> map) { return executionService.startProcessInstanceById(id, map); } /** * 完成任务 * * @param taskId * @param map */ public void completeTask(String taskId, Map map) { taskService.completeTask(taskId, map); } /** * 完成任务 * * @param taskId */ public void completeTask(String taskId) { taskService.completeTask(taskId); } /** * 将任务流转到指定名字的流程outcome中去 * * @param taskId * @param outcome */ public void completeTask(String taskId, String outcome) { taskService.completeTask(taskId, outcome); } public void completeTask(String taskId, String outcome, Map variables) { taskService.completeTask(taskId, outcome, variables); } /** * 获得所有发布了的流程 * * @return */ public List<ProcessDefinition> getAllPdList() { return repositoryService.createProcessDefinitionQuery().list(); } /** * 获得所有流程实例 * * @return */ public List<ProcessInstance> getAllPiList() { return executionService.createProcessInstanceQuery().list(); } /** * 根据流程实例Id,即executionId获取指定的变量值 * * @param executionId * @param variableName * @return */ public Object getVariableByexecutionId(String executionId, String variableName) { return executionService.getVariable(executionId, variableName); } /** * 根据任务id,即taskId获取指定变量值 * * @param taskId * @param variableName * @return */ public Object getVariableByTaskId(String taskId, String variableName) { return taskService.getVariable(taskId, variableName); } /** * 获取指定用户名字的任务 * * @param userName * @return */ public List<Task> findPersonalTasks(String userName) { return taskService.findPersonalTasks(userName); } /** * 根据任务id获取任务 * * @param taskId * @return */ public Task getTask(String taskId) { return taskService.getTask(taskId); } /** * 级联删除流程定义,直接删除该流程定义下的所有实例 * * @param deploymentId流程定义id */ public void deleteDeploymentCascade(String deploymentId) { repositoryService.deleteDeploymentCascade(deploymentId); } }
流程管理类
package hust.loan.servlet; import hust.loan.dao.StaffDao; import hust.loan.dao.util.JBPMUtil; import hust.loan.po.ApplicationForm; import hust.loan.po.Manager; import hust.loan.po.Role; import hust.loan.po.Staff; import hust.loan.service.ApplicationService; import hust.loan.service.RoleService; import hust.loan.service.StaffService; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.zip.ZipInputStream; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.DiskFileUpload; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadException; import org.jbpm.api.Deployment; import org.jbpm.api.Execution; import org.jbpm.api.ExecutionService; import org.jbpm.api.HistoryService; import org.jbpm.api.ProcessDefinition; import org.jbpm.api.ProcessDefinitionQuery; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.ProcessInstanceQuery; import org.jbpm.api.RepositoryService; import org.jbpm.api.TaskService; import org.jbpm.api.history.HistoryProcessInstance; import org.jbpm.api.history.HistoryTask; import org.jbpm.api.task.Task; import org.subethamail.wiser.Wiser; /** * Servlet implementation class ProcessServlet */ public class ProcessServlet extends HttpServlet { private static final long serialVersionUID = 1L; private JBPMUtil jBPMUtil; public JBPMUtil getjBPMUtil() { return jBPMUtil; } public void setjBPMUtil(JBPMUtil jBPMUtil) { this.jBPMUtil = jBPMUtil; this.processEngine = jBPMUtil.getProcessEngine(); this.repositoryService = jBPMUtil.getRepositoryService(); this.executionService = jBPMUtil.getExecutionService(); this.taskService = jBPMUtil.getTaskService(); this.historyService = jBPMUtil.getHistoryService(); } private ProcessEngine processEngine; private RepositoryService repositoryService; private ExecutionService executionService; private TaskService taskService; private StaffService staffService; private ApplicationService applicationService; private HistoryService historyService; public HistoryService getHistoryService() { return historyService; } public void setHistoryService(HistoryService historyService) { this.historyService = historyService; } // get/set public ProcessEngine getProcessEngine() { return processEngine; } public void setProcessEngine(ProcessEngine processEngine) { this.processEngine = processEngine; } public RepositoryService getRepositoryService() { return repositoryService; } public void setRepositoryService(RepositoryService repositoryService) { this.repositoryService = repositoryService; } public ExecutionService getExecutionService() { return executionService; } public void setExecutionService(ExecutionService executionService) { this.executionService = executionService; } public TaskService getTaskService() { return taskService; } public void setTaskService(TaskService taskService) { this.taskService = taskService; } public StaffService getStaffService() { return staffService; } public void setStaffService(StaffService staffService) { this.staffService = staffService; } public ApplicationService getApplicationService() { return applicationService; } public void setApplicationService(ApplicationService applicationService) { this.applicationService = applicationService; } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { process(request, response); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); response.getWriter().write("{success:false,errors:'操作失败!'}"); } // TODO Auto-generated method stub } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { process(request, response); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); response.getWriter().write("{success:false,errors:'操作失败!'}"); } } /** * @throws Exception * 处理分发类 * @throws * */ private void process(HttpServletRequest request, HttpServletResponse response) throws Exception { // 设置字符请求编码 request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("utf-8"); String action = request.getParameter("action"); if (action.equals("ds_getAllProcessDefinition")) { // 查询流程定义 String json = findProDefintion(request, response); response.getWriter().write(json); } else if (action.equals("deploy")) { // 部署流程 deploy(request, response); } else if (action.equals("getAllDeployment")) { // 查询流程部署 String json = getDeployment(request, response); response.getWriter().write(json); } else if (action.equals("delDeployment")) { // 删除部署 delDeployment(request, response); } else if (action.equals("suspendDeployment")) { // 暂停该部署 repositoryService.suspendDeployment(request .getParameter("deployId")); response.getWriter().write("{success:true}"); } else if (action.equals("resumeDeployment")) { // 重启该部署 repositoryService .resumeDeployment(request.getParameter("deployId")); response.getWriter().write("{success:false}"); } else if (action.equals("getProcessInstance")) { // 查询流程实例 getPorcessInstances(request, response); } else if (action.equals("delProcessInstance")) { // 删除流程实例 delProcessInstance(request, response); } else if (action.equals("getHistoryProcessInstance")) { // 查询历史流程实例 getHistoryProcessInstance(request, response); } else if (action.equals("delHistoryProcessInstance")) { // 删除历史流程实例 delProcessInstance(request, response); } else if (action.equals("getGroupTask")) { // 获取小组任务 getGroupTask(request, response); } else if (action.equals("delTask")) { delTask(request, response); // 删除任务 } else if (action.equals("getPersonalTask")) { // 获取私人任务 getPersionalTask(request, response); } else if (action.equals("getHistoryTask")) { // 获取历史任务信息 getHistoryTask(request, response); } else if (action.equals("getApplyForm")) { getApplyForm(request, response); } else if (action.equals("accept")) { // 同意申请 accept(request, response); } else if (action.equals("reject")) { // 回绝申请 reject(request, response); } } private void reject(HttpServletRequest request, HttpServletResponse response) throws Exception { int appId = Integer.valueOf(request.getParameter("appId")); String executionId = request.getParameter("executionId"); String bmComment = request.getParameter("bmComment"); String gmComment = request.getParameter("gmComment"); String remark = request.getParameter("remark"); String taskId = request.getParameter("taskId"); ApplicationForm applyform = applicationService .getApplicationFormById(appId); int userId = (Integer) request.getSession().getAttribute("userId");// 登入用户id Staff staff = staffService.getStaffById(userId);// 当前登入用户 applyform.setRemark(remark); Execution execution = executionService.findExecutionById(executionId); if (execution.getProcessInstance().isActive("副总经理审核")) { applyform.setBranchManager(staff); applyform.setBrMComment(bmComment); executionService.signalExecutionById(executionId, "reject"); } else if (execution.getProcessInstance().isActive("总经理审核")) { // 总经理拒绝申请 applyform.setGeMComment(gmComment); applyform.setGeneralManager(staff); executionService.signalExecutionById(executionId, "reject"); } else if (execution.getProcessInstance().isActive("give money")) { // 普通员工 applyform.setDealStaff(staff); applyform.setCompleteDate(new Date()); } applicationService.updateApplicationForm(applyform);// 更新表单 response.getWriter().write("{success:true}"); } private void accept(HttpServletRequest request, HttpServletResponse response) throws Exception { int appId = Integer.valueOf(request.getParameter("appId")); String executionId = request.getParameter("executionId"); String bmComment = request.getParameter("bmComment"); String gmComment = request.getParameter("gmComment"); String remark = request.getParameter("remark"); String taskId = request.getParameter("taskId"); ApplicationForm applyform = applicationService .getApplicationFormById(appId); int userId = (Integer) request.getSession().getAttribute("userId");// 副经理id Staff staff = staffService.getStaffById(userId); applyform.setRemark(remark); Execution execution = executionService.findExecutionById(executionId); // 流程变量 Map<String, Object> variables = new HashMap<String, Object>(); if (execution.getProcessInstance().isActive("副总经理审核")) { applyform.setBranchManager(staff); applyform.setBrMComment(bmComment); String content = ""; if (applyform.getAmount() > 5000) { content = "amount larger than 5000"; variables.put("manager", staffService.findManager()); } else { content = "amount less than 5000"; // Role role =roleService.getRoleById(1); } variables.put("content", content); executionService.signalExecutionById(executionId, "accept", variables); } else if (execution.getProcessInstance().isActive("总经理审核")) { // 总经理审核同意 applyform.setGeMComment(gmComment); applyform.setGeneralManager(staff); executionService.signalExecutionById(executionId, "accept"); } else if (execution.getProcessInstance().isActive("give money")) { // 普通员工 applyform.setDealStaff(staff); applyform.setCompleteDate(new Date()); variables.put("appEmail", applyform.getEmail()); variables.put("appName", applyform.getAppName()); Calendar deadline = Calendar.getInstance(); deadline.add(Calendar.DAY_OF_MONTH, 1);// 期限为一个月 variables.put("deadline", deadline.getTime().toString()); taskService.setVariables(taskId, variables); // start mail server Wiser wiser = new Wiser(); wiser.setPort(2525); wiser.start(); taskService.completeTask(taskId); } // 更新表单 applicationService.updateApplicationForm(applyform); // executionService.signalExecutionById(executionId, "accept"); response.getWriter().write("{success:true}"); } /** * 获取表单 * * @throws Exception * */ private void getApplyForm(HttpServletRequest request, HttpServletResponse response) throws Exception { String taskId = request.getParameter("taskId"); String type = request.getParameter("etype"); int applyId = (Integer) taskService.getVariable(taskId, "applyId"); String userId = String.valueOf(request.getSession().getAttribute( "userId")); if (type.equals("group")) { taskService.takeTask(taskId, userId); } ApplicationForm apply = applicationService .getApplicationFormById(applyId); response.getWriter().write(ApplyToJson(apply)); } /** * 将ApplicationForm 数据转换为json格式 * */ private String ApplyToJson(ApplicationForm apply) { StringBuffer sb = new StringBuffer(); sb.append("{apply:[{"); sb.append("appId:'" + apply.getAppId() + "',appDate:'" + apply.getAppDate() + "',appName:'" + apply.getAppName() + "',appUserId:'" + apply.getAppUserId() + "',email:'" + apply.getEmail() + "',address:'" + apply.getAddress() + "',reason:'" + apply.getReason() + "',amount:" + apply.getAmount() + ",bmComment:'" + (apply.getBrMComment() == null ? "" : apply.getBrMComment()) + "',gmComment:'" + (apply.getGeMComment() == null ? "" : apply.getGeMComment()) + "'}]}"); return sb.toString(); } /** * 获取历史任务信息 * * @throws Exception * */ private void getHistoryTask(HttpServletRequest request, HttpServletResponse response) throws Exception { String condition = request.getParameter("conditions"); int start = Integer.valueOf(request.getParameter("start")); int limit = Integer.valueOf(request.getParameter("limit")); String searchType = request.getParameter("searchType"); List<HistoryTask> list = new ArrayList(); int count = 0; if (searchType.equals("all")) { list = historyService.createHistoryTaskQuery().page(start, limit) .list(); count = historyService.createHistoryTaskQuery().list().size(); } else if (condition != "" && condition != null) { if (searchType.endsWith("taskId")) { list = historyService.createHistoryTaskQuery() .taskId(condition).page(start, limit).list(); count = historyService.createHistoryTaskQuery() .taskId(condition).list().size(); } else if (searchType.equals("executionId")) { list = historyService.createHistoryTaskQuery() .executionId(condition).page(start, limit).list(); count = historyService.createHistoryTaskQuery() .executionId(condition).list().size(); } else if (searchType.equals("startAfter")) { list = historyService.createHistoryTaskQuery() .startedAfter(stingToDate(condition)) .page(start, limit).list(); count = historyService.createHistoryTaskQuery() .startedAfter(stingToDate(condition)).list().size(); } else if (searchType.equals("startBefore")) { list = historyService.createHistoryTaskQuery() .startedBefore(stingToDate(condition)) .page(start, limit).list(); count = historyService.createHistoryTaskQuery() .startedBefore(stingToDate(condition)).list().size(); } else if (searchType.equals("state")) { list = historyService.createHistoryTaskQuery().state(condition) .page(start, limit).list(); count = historyService.createHistoryTaskQuery() .state(condition).list().size(); } else if (searchType.equals("lessThan")) { list = historyService.createHistoryTaskQuery() .tookLessThen(Integer.valueOf(condition)) .page(start, limit).list(); count = historyService.createHistoryTaskQuery() .tookLessThen(Integer.valueOf(condition)).list().size(); } else if (searchType.equals("longerThan")) { list = historyService.createHistoryTaskQuery() .tookLongerThen(Integer.valueOf(condition)) .page(start, limit).list(); count = historyService.createHistoryTaskQuery() .tookLongerThen(Integer.valueOf(condition)).list() .size(); } else if (searchType.equals("assignee")) { list = historyService.createHistoryTaskQuery() .assignee(condition).page(start, limit).list(); count = historyService.createHistoryTaskQuery() .assignee(condition).list().size(); } else if (searchType.equals("outcome")) { list = historyService.createHistoryTaskQuery() .outcome(condition).page(start, limit).list(); count = historyService.createHistoryTaskQuery() .outcome(condition).list().size(); } } else if ((condition == "" || condition == null) && searchType.equals("assignee")) { list = historyService .createHistoryTaskQuery() .assignee( (String) request.getSession().getAttribute("user")) .page(start, limit).list(); count = historyService .createHistoryTaskQuery() .assignee( (String) request.getSession().getAttribute("user")) .list().size(); } response.getWriter().write(historyTaskToJson(list, count)); } /** * HistoryTask装换成json数据格式 * */ private String historyTaskToJson(List<HistoryTask> list, int count) { StringBuffer sb = new StringBuffer(); sb.append("{totalProperty:" + count); sb.append(",root:["); for (HistoryTask task : list) { sb.append("{id:'" + task.getId() + "',executionId:'" + task.getExecutionId() + "',assignee:'" + task.getAssignee() + "',createTime:'" + task.getCreateTime() + "',endTime:'" + task.getEndTime() + "',duration:" + task.getDuration() + ",state:'" + task.getState() + "',outcome:'" + task.getOutcome() + "'},"); } sb.append("]}"); if (count != 0) { return sb.substring(0, sb.lastIndexOf(",")) + sb.substring(sb.lastIndexOf(",") + 1); } else { return sb.toString(); } } /** * 时间类型转换 * * @throws Exception * */ private Date stingToDate(String str) throws Exception { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); return df.parse(str); } /** * 查询个人任务 * * @throws Exception * */ private void getPersionalTask(HttpServletRequest request, HttpServletResponse response) throws Exception { int start = Integer.valueOf(request.getParameter("start")); int limit = Integer.valueOf(request.getParameter("limit")); String searchType = request.getParameter("searchType"); String searchState = request.getParameter("searchState"); String condition = request.getParameter("conditions"); List<Task> list = new ArrayList(); int count = 0; // 当前登入用户id String userId = String.valueOf(request.getSession().getAttribute( "userId")); // 查询所有 if (searchType.equals("all")) { if (searchState.equals("all")) { list = taskService.createTaskQuery().page(start, limit).list(); count = taskService.createTaskQuery().list().size(); } else if (searchState.equals("suspend")) { list = taskService.createTaskQuery().suspended() .page(start, limit).list(); count = taskService.createTaskQuery().suspended().list().size(); } else if (searchState.equals("unassigned")) { list = taskService.createTaskQuery().unassigned() .page(start, limit).list(); count = taskService.createTaskQuery().unassigned().list() .size(); } else { list = taskService.createTaskQuery().notSuspended() .page(start, limit).list(); count = taskService.createTaskQuery().notSuspended().list() .size(); } } else if (searchType.equals("assignee")) { // 默认查询当前用户任务类表 if (condition == "" || condition == null) { // 默认查询当前用户任务类表 if (searchState.equals("all")) { list = taskService.createTaskQuery().assignee(userId) .page(start, limit).list(); count = taskService.createTaskQuery().assignee(userId) .list().size(); } else if (searchState.equals("suspend")) { list = taskService.createTaskQuery().assignee(userId) .suspended().page(start, limit).list(); count = taskService.createTaskQuery().assignee(userId) .suspended().list().size(); } else if (searchState.equals("unassigned")) { list = taskService.createTaskQuery().assignee(userId) .unassigned().page(start, limit).list(); count = taskService.createTaskQuery().assignee(userId) .unassigned().list().size(); } else { list = taskService.createTaskQuery().assignee(userId) .notSuspended().page(start, limit).list(); count = taskService.createTaskQuery().assignee(userId) .notSuspended().list().size(); } } else { // 查询非当前用户 if (searchState.equals("all")) { list = taskService.createTaskQuery().assignee(condition) .page(start, limit).list(); count = taskService.createTaskQuery().assignee(condition) .list().size(); } else if (searchState.equals("suspend")) { list = taskService.createTaskQuery().assignee(condition) .suspended().page(start, limit).list(); count = taskService.createTaskQuery().assignee(condition) .suspended().list().size(); } else if (searchState.equals("unassigned")) { list = taskService.createTaskQuery().assignee(condition) .unassigned().page(start, limit).list(); count = taskService.createTaskQuery().assignee(condition) .unassigned().list().size(); } else { list = taskService.createTaskQuery().assignee(condition) .notSuspended().page(start, limit).list(); count = taskService.createTaskQuery().assignee(condition) .notSuspended().list().size(); } } } else if (searchType.equals("taskId")) { if (condition != "" && condition != null) { if (taskService.getTask(condition) != null) { list.add(taskService.getTask(condition)); count = 1; } } } else if (searchType.equals("activityName")) { if (condition != "" && condition != null) { if (searchState.equals("all")) { list = taskService.createTaskQuery() .activityName(condition).page(start, limit).list(); count = taskService.createTaskQuery() .activityName(condition).list().size(); } else if (searchState.equals("suspend")) { list = taskService.createTaskQuery() .activityName(condition).suspended() .page(start, limit).list(); count = taskService.createTaskQuery() .activityName(condition).suspended().list().size(); } else if (searchState.equals("unassigned")) { list = taskService.createTaskQuery() .activityName(condition).unassigned() .page(start, limit).list(); count = taskService.createTaskQuery() .activityName(condition).unassigned().list().size(); } else { list = taskService.createTaskQuery() .activityName(condition).notSuspended() .page(start, limit).list(); count = taskService.createTaskQuery() .activityName(condition).notSuspended().list() .size(); } } } else if (searchType.equals("candidate")) { if (condition != "" && condition != null) { if (searchState.equals("all")) { list = taskService.createTaskQuery().candidate(condition) .page(start, limit).list(); count = taskService.createTaskQuery().candidate(condition) .list().size(); } else if (searchState.equals("suspend")) { list = taskService.createTaskQuery().candidate(condition) .suspended().page(start, limit).list(); count = taskService.createTaskQuery().candidate(condition) .suspended().list().size(); } else if (searchState.equals("unassigned")) { list = taskService.createTaskQuery().candidate(condition) .unassigned().page(start, limit).list(); count = taskService.createTaskQuery().candidate(condition) .unassigned().list().size(); } else { list = taskService.createTaskQuery().candidate(condition) .notSuspended().page(start, limit).list(); count = taskService.createTaskQuery().candidate(condition) .notSuspended().list().size(); } } } else if (searchType.equals("processDefinitionId")) { if (condition != "" || condition != null) { // 默认查询当前用户任务类表 if (searchState.equals("all")) { list = taskService.createTaskQuery() .processDefinitionId(condition).page(start, limit) .list(); count = taskService.createTaskQuery() .processDefinitionId(condition).list().size(); } else if (searchState.equals("suspend")) { list = taskService.createTaskQuery() .processDefinitionId(condition).suspended() .page(start, limit).list(); count = taskService.createTaskQuery() .processDefinitionId(condition).suspended().list() .size(); } else if (searchState.equals("unassigned")) { list = taskService.createTaskQuery() .processDefinitionId(condition).unassigned() .page(start, limit).list(); count = taskService.createTaskQuery() .processDefinitionId(condition).unassigned().list() .size(); } else { list = taskService.createTaskQuery() .processDefinitionId(condition).notSuspended() .page(start, limit).list(); count = taskService.createTaskQuery() .processDefinitionId(condition).notSuspended() .list().size(); } } } else if (searchType.equals("processInstanceId")) { if (condition != "" || condition != null) { // 默认查询当前用户任务类表 if (searchState.equals("all")) { list = taskService.createTaskQuery() .processInstanceId(condition).page(start, limit) .list(); count = taskService.createTaskQuery() .processInstanceId(condition).list().size(); } else if (searchState.equals("suspend")) { list = taskService.createTaskQuery() .processInstanceId(condition).suspended() .page(start, limit).list(); count = taskService.createTaskQuery() .processInstanceId(condition).suspended().list() .size(); } else if (searchState.equals("unassigned")) { list = taskService.createTaskQuery() .processInstanceId(condition).unassigned() .page(start, limit).list(); count = taskService.createTaskQuery() .processInstanceId(condition).unassigned().list() .size(); } else { list = taskService.createTaskQuery() .processInstanceId(condition).notSuspended() .page(start, limit).list(); count = taskService.createTaskQuery() .processInstanceId(condition).notSuspended().list() .size(); } } } response.getWriter().write(TaskToJson(list, count)); } /** * 删除任务 * * @throws Exception * */ private void delTask(HttpServletRequest request, HttpServletResponse response) throws Exception { String id = request.getParameter("id"); String type = request.getParameter("type"); if (type.equals("normal")) { taskService.deleteTask(id); } else { taskService.deleteTaskCascade(id); } response.getWriter().write("{success:true}"); } /** * 根据userid获取小组任务 * * @throws Exception * */ private void getGroupTask(HttpServletRequest request, HttpServletResponse response) throws Exception { List<Task> list = new ArrayList(); // 默认为登入用户id String userId = String.valueOf(request.getSession().getAttribute( "userId")); String userName = (String) request.getSession().getAttribute("user"); // 查询用户id String searchId = (String) request.getParameter("conditions"); int start = Integer.parseInt((String) request.getParameter("start")); int limit = Integer.parseInt((String) request.getParameter("limit")); if (searchId == "" || searchId == null) { list = taskService.findGroupTasks(userId); } else { list = taskService.findGroupTasks(searchId); } // 记录总数 int count = list.size(); if (list.size() <= limit) { // 分页 list = list.subList(start, list.size()); } else { list = list.subList(start, limit); } response.getWriter().write(TaskToJson(list, count)); } /** * 将Task装换为Json数据格式 * */ private String TaskToJson(List<Task> list, int count) { StringBuffer sb = new StringBuffer(); sb.append("{totalProperty:" + count); sb.append(",root:["); for (Task task : list) { sb.append("{id:'" + task.getId() + "',name:'" + task.getName() + "',executionId:'" + task.getExecutionId() + "',activityName:'" + task.getActivityName() + "',assignee:'" + task.getAssignee() + "',createTime:'" + task.getCreateTime() + "',dueDate:'" + task.getDuedate() + "',formResourceName:'" + task.getFormResourceName() + "',priority:" + task.getPriority() + ",description:'" + task.getDescription() + "'},"); } sb.append("]}"); if (count != 0) { return sb.substring(0, sb.lastIndexOf(",")) + sb.substring(sb.lastIndexOf(",") + 1); } else { return sb.toString(); } } /** * 查询历史流程实例 * * @throws Exception * */ private void getHistoryProcessInstance(HttpServletRequest request, HttpServletResponse response) throws Exception { String id = request.getParameter("conditions"); String type = request.getParameter("searchType"); int start = Integer.valueOf(request.getParameter("start")); int limit = Integer.valueOf(request.getParameter("limit")); List<HistoryProcessInstance> list = new ArrayList(); int count = 0; if (type.equals("all")) { list = historyService.createHistoryProcessInstanceQuery() .page(start, limit).list(); count = historyService.createHistoryProcessInstanceQuery().list() .size(); } else if (type.equals("processInstanceId")) { list = historyService.createHistoryProcessInstanceQuery() .processInstanceId(id).page(start, limit).list(); count = historyService.createHistoryProcessInstanceQuery() .processInstanceId(id).list().size(); } else { list = historyService.createHistoryProcessInstanceQuery() .processDefinitionId(id).page(start, limit).list(); count = historyService.createHistoryProcessInstanceQuery() .processDefinitionId(id).list().size(); } response.getWriter().write(historyProcessInstanceToJson(list, count)); } /** * List<HistoryProcessInstance>装换成json数据格式 * */ private String historyProcessInstanceToJson( List<HistoryProcessInstance> list, int count) { StringBuffer sb = new StringBuffer(); sb.append("{totalProperty:" + count); sb.append(",root:["); for (HistoryProcessInstance hpi : list) { sb.append("{processInstanceId:'" + hpi.getProcessInstanceId() + "',processDefinitionId:'" + hpi.getProcessDefinitionId() + "',key:'" + hpi.getKey() + "',duration:" + hpi.getDuration() + ",startTime:'" + hpi.getStartTime() + "',endTime:'" + hpi.getEndTime() + "',state:'" + hpi.getState() + "'},"); } sb.append("]}"); if (count != 0) { return sb.substring(0, sb.lastIndexOf(",")) + sb.substring(sb.lastIndexOf(",") + 1); } else { return sb.toString(); } } /** * 删除流程实例 * * @throws Exception * */ private void delProcessInstance(HttpServletRequest request, HttpServletResponse response) throws Exception { String id = request.getParameter("id"); String type = request.getParameter("type"); if (type.equals("normal")) { // 删除流程实例 executionService.deleteProcessInstance(id); } else { // 级联删除 executionService.deleteProcessInstanceCascade(id); } response.getWriter().write("{success:true}"); } /** * 流程实例查询 * * @throws Exception * */ private void getPorcessInstances(HttpServletRequest request, HttpServletResponse response) throws Exception { String searchType = request.getParameter("searchType"); String value = request.getParameter("conditions"); int start = Integer.valueOf(request.getParameter("start")); int limit = Integer.valueOf(request.getParameter("limit")); String searchStateType = request.getParameter("searchStateType"); int count = 0; List<ProcessInstance> pis = new ArrayList(); if (searchType.equals("all")) { if (searchStateType.equals("all")) { pis = executionService.createProcessInstanceQuery() .page(start, limit).list(); count = executionService.createProcessInstanceQuery().list() .size(); } else if (searchStateType.equals("suspend")) { // select only suspended process definitions pis = executionService.createProcessInstanceQuery().suspended() .page(start, limit).list(); count = executionService.createProcessInstanceQuery() .suspended().list().size(); } else { // select only process definitions that are not suspended pis = executionService.createProcessInstanceQuery() .notSuspended().page(start, limit).list(); count = executionService.createProcessInstanceQuery() .notSuspended().list().size(); } } else if (value != "" && value != null) { if (searchType.equals("processDefinitionId")) { if (searchStateType.equals("all")) { pis = executionService.createProcessInstanceQuery() .processDefinitionId(value).page(start, limit) .list(); count = executionService.createProcessInstanceQuery() .processDefinitionId(value).list().size(); } else if (searchStateType.equals("suspend")) { // pis = executionService.createProcessInstanceQuery() .suspended().processDefinitionId(value) .page(start, limit).list(); count = executionService.createProcessInstanceQuery() .suspended().processDefinitionId(value).list() .size(); } else { // pis = executionService.createProcessInstanceQuery() .notSuspended().processDefinitionId(value) .page(start, limit).list(); count = executionService.createProcessInstanceQuery() .notSuspended().processDefinitionId(value).list() .size(); } } else if (searchType.equals("processInstanceId")) { // if (searchStateType.equals("all")) { pis = executionService.createProcessInstanceQuery() .processInstanceId(value).page(start, limit).list(); count = executionService.createProcessInstanceQuery() .processInstanceId(value).list().size(); } else if (searchStateType.equals("suspend")) { pis = executionService.createProcessInstanceQuery() .suspended().processInstanceId(value) .page(start, limit).list(); count = executionService.createProcessInstanceQuery() .suspended().processInstanceId(value).list().size(); } else { pis = executionService.createProcessInstanceQuery() .notSuspended().processInstanceId(value) .page(start, limit).list(); count = executionService.createProcessInstanceQuery() .notSuspended().processInstanceId(value).list() .size(); } }