接口 ProcessEngine 工作流引擎 可以通过spring和 Configuration.getProcessEngine(); ExecutionService 执行 ProcessInstance 流程实例 ProcessDefinition 流程定义 TaskService 任务 IdentityService 自动增长 HistoryService 历史记录 ManagementService 管理 RepositoryService 仓库 方法: 1.ProcessEngine processEngine.setAuthenticatedUserId(String ); processEngine.setHibernateSession(Object); processEngine.setJdbcConnection(Connection); Object get(String); ExecutionService getExecutionService(); HistoryService getHistoryService(); IdentityService getIdentityService(); ManagementService getManagementService(); RepositoryService getRepositoryService(); TaskService getTaskService(); 1.查询流程实例:new Instance List<ProcessInstance> instances = executionService.createProcessInstanceQuery().list(); 2.查询流程进度 1)得到当前流程中相匹配的活动 (可以得到活动的长高宽..) <%String id = request.getParameter("id"); ProcessEngine processEngine = Configuration.getProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); ExecutionService executionService = processEngine.getExecutionService(); ProcessInstance processInstance = executionService.findProcessInstanceById(id); Set<String> activityNames = processInstance.findActiveActivityNames(); ActivityCoordinates ac = repositoryService.getActivityCoordinates(processInstance.getProcessDefinitionId(),activityNames.iterator().next());%> <div style="position:absolute;border:1px solid red;left:<%=ac.getX()%>px;top:<%=ac.getY()%>px;width:<%=ac.getWidth()%>px;height:<%=ac.getHeight()%>px;"></div> 2)生成图片 <img src="Definition_definitionImage.action?id=<%=id %>" style="position:absolute;left:0px;top:0px;" align="middle"> RepositoryService repositoryService = this.getProcessEngine().getRepositoryService(); ExecutionService executionService = this.getProcessEngine().getExecutionService(); String id = this.getRequest().getParameter("id"); ProcessInstance processInstance = executionService.findProcessInstanceById(id); String processDefinitionId = processInstance .getProcessDefinitionId(); // processDefinitionId 方法表示去 JBPM4_DEPLOYPROP 中按 processDefinitionId和 STRINGVAL_ 字段去找 DEPLOYMENT // 简单说就是通过 流程部署的小项id 去找 流程对象 ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() .processDefinitionId(processDefinitionId).uniqueResult(); System.out.println(processDefinition.getImageResourceName()+"-----"+processDefinition.getDeploymentId()); // 图片输入流 InputStream inputStream = null; // 如果是上传的是 xml 文件 , processDefinition.getImageResourceName() 就会是null . if(processDefinition.getImageResourceName()==null){ String did = processDefinition.getDeploymentId(); DefinitionImage definitionImage = this.getJbpmService().findImageByDefinitionId(did); //自己写的Service不是JBPM的API if(definitionImage!=null){ // 通过 这个 xml 的 流程id 找到它在数据库 definitionImage表中的记录 ,中间也有他的 图片名称 // 从而构造出 inputStream 对象 String uploadRoot = super.getRequest().getRealPath("/upload/jpdl/"+definitionImage.getImageName()); try { inputStream = new FileInputStream(uploadRoot); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }else{ // 从数据库读到的输入流 . inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),processDefinition.getImageResourceName()); } byte[] b = new byte[1024]; int len = -1; try { ServletOutputStream sos = this.getResponse().getOutputStream(); while ((len = inputStream.read(b, 0, 1024)) != -1) { sos.write(b, 0, len); } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } 3.查询流程定义 (相当于Class,流程实例相当于new 的类) List<ProcessDefinition> definitionList = this.getProcessEngine().getRepositoryService().createProcessDefinitionQuery().list(); 4.开启流程,已经有动态表单了。 String id=reuqest.getParameter("id"); //得到流程定义ID // 得到当前用户 UserInfo userInfo = super.getLoginUser(); //为了方便测试 , 先写死 Map<String, Object> map = new HashMap<String, Object>(); map.put(Definition_Action.USER_INFO, userInfo.getUserId()); // 为什么这里不能有多个参数 map.put(Definition_Action.FORM_ID, formId); // form 表单 id // 得到专门操作流程实例的 执行对象 System.out.println(map); ExecutionService executionService = this.getProcessEngine() .getExecutionService(); // 开启实例 , ProcessInstance 对象好像对应的就是 ExecutionService 的表 ProcessInstance pi = executionService.startProcessInstanceById(id,map); 5.上传流程定义 /* * 上传方法 (non-Javadoc) , 方法名写错了 , 应该是 uploadDefinition * 难点 * 1. 上传的 zip 格式就很好处理 * 2. 上传的是 xml , 要复杂一点 , 因为 xml 文件是不带 png 流程图的 , 这样的话就实现不了流程跟踪了 , * 所有要去网上找了个 根据 xml 生成流程图 png 的工具 (这个方法中没实现 ) , * 3. 把 xml的 流程id 和 生成的流程图名写到数据库中,当然前提是,把 xml要上传到 tomcat 先. */ File src = this.getUpload(); // 得到 "知识库" service RepositoryService rService = this.getProcessEngine().getRepositoryService(); String fileName = this.getUploadFileName(); String ext = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length()); if(ext.equals("zip")){ try { ZipInputStream zis = new ZipInputStream(new FileInputStream(src)); rService.createDeployment().addResourcesFromZipInputStream(zis) .deploy(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } }else if(ext.equals("xml")){ //如果上传成功后就要放到自己的表中保存起来。 //流程定义对象 id String definitionId = rService.createDeployment().addResourceFromInputStream(this.getUploadFileName(),new FileInputStream(src)).deploy(); } 6.删除流程定义 RepositoryService repositoryService = this.getProcessEngine().getRepositoryService(); //删除要流程部署ID repositoryService.deleteDeploymentCascade("depolymentId"); 7.查询我的任务 TaskService taskService = this.getProcessEngine().getTaskService(); //得到用户任务 List<Task> taskList = taskService.findPersonalTasks(userInfo.getUserId()); //SQL:select * from JBPM4_TASK where assignee=?; // 得到任务变量 formId ?? var这里是不是在上面(开启流程)已经定义好了的。 Object formId = taskService.getVariable(task.getId(), Definition_Action.FORM_ID);