/** * 查看流程定义图 * * @param request * @param processDefId 流程定义id * @return */ @RequestMapping(value = "/viewprocessDefImage.do") public String viewprocessDefImage( HttpServletRequest request, HttpServletResponse response, @RequestParam("processDefId") String processDefId) throws Exception { // 根据流程定义id查询流程定义 ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery() .processDefinitionId(processDefId) .singleResult(); InputStream inputStream = repositoryService.getResourceAsStream( processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName()); // // 输出资源内容到相应对象 // byte[] b = new byte[1024]; // int len; // while ((len = inputStream.read(b, 0, 1024)) != -1) { // response.getOutputStream().write(b, 0, len); // } response.getOutputStream().write(IoUtil.readInputStream(inputStream, "processDefInputStream")); return null; }
/** * 删除执行流程 * * @param request * @param processDefId * @return */ @RequestMapping(value = "/remove.do") public String remove( HttpServletRequest request, @RequestParam("processDefId") String processDefId) { repositoryService.deleteDeployment(processDefId); return "redirect:/simple/index.do"; }
/** * 部署 * * @param file * @return */ @RequestMapping(value = "/deploy.do") public String deploy(@RequestParam(value = "file", required = false) MultipartFile file) { String fileName = file.getOriginalFilename(); try { InputStream fileInputStream = file.getInputStream(); repositoryService.createDeployment().addInputStream(fileName, fileInputStream).deploy(); } catch (Exception e) { } return "redirect:/simple/index.do"; }
/** * 个人任务首页 * * @return */ @RequestMapping("/index.do") public String index(HttpServletRequest request, HttpServletResponse response, Model model) { User user = request.getSession(true).getAttribute("user") == null ? null : (User) request.getSession(true).getAttribute("user"); List<Group> groups = request.getSession(true).getAttribute("groups") == null ? null : (List<Group>) request.getSession(true).getAttribute("groups"); if (null == user) { return "redirect:/simple/login.do"; } else { model.addAttribute("user", user); model.addAttribute("groups", groups); /** */ List<ProcessDefinition> pdList = repositoryService.createProcessDefinitionQuery().list(); model.addAttribute("pdList", pdList); /** 该用户所有可以认领的任务 */ List<Task> groupTasks = taskService.createTaskQuery().taskCandidateUser(user.getId()).list(); List<Task> userTasks = taskService.createTaskQuery().taskAssignee(user.getId()).list(); model.addAttribute("userTasks", userTasks); model.addAttribute("groupTasks", groupTasks); /** 查看任务实例 */ List<Task> taskList = taskService.createTaskQuery().list(); model.addAttribute("taskList", taskList); /** 历史流程 */ List<HistoricProcessInstance> hpiList = historyService.createHistoricProcessInstanceQuery().finished().list(); model.addAttribute("hpiList", hpiList); } return "/simple/index"; }
/** * 显示图片 * * @return */ @RequestMapping(value = "/viewPic.do") public void viewPic( HttpServletRequest request, HttpServletResponse response, @RequestParam("executionId") String executionId) throws Exception { ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(executionId).singleResult(); BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId()); List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId); // 使用spring注入引擎请使用下面的这行代码 Context.setProcessEngineConfiguration(processEngine.getProcessEngineConfiguration()); InputStream imageStream = ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", activeActivityIds); // 输出资源内容到相应对象 byte[] b = new byte[1024]; int len; while ((len = imageStream.read(b, 0, 1024)) != -1) { response.getOutputStream().write(b, 0, len); } }