更多ruoyi-nbcio功能请看演示系统
gitee源代码地址
前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio
演示地址:RuoYi-Nbcio后台管理系统 http://218.75.87.38:9666/
更多nbcio-boot功能请看演示系统
gitee源代码地址
后端代码: https://gitee.com/nbacheng/nbcio-boot
前端代码:https://gitee.com/nbacheng/nbcio-vue.git
在线演示(包括H5) : http://218.75.87.38:9888
作为系统流程维护,所有任务就比较有好处,以便对一些特殊任务或流程做一些特殊处理
1、后端增加所有任务列表包括导出,代码如下:
@Overridepublic TableDataInfo<WfTaskVo> selectPageAllProcessList(ProcessQuery processQuery, PageQuery pageQuery) {Page<WfTaskVo> page = new Page<>();HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().orderByProcessInstanceStartTime().desc();// 构建搜索条件ProcessUtils.buildProcessSearch(historicProcessInstanceQuery, processQuery);int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);List<HistoricProcessInstance> historicProcessInstances = historicProcessInstanceQuery.listPage(offset, pageQuery.getPageSize());page.setTotal(historicProcessInstanceQuery.count());List<WfTaskVo> taskVoList = new ArrayList<>();for (HistoricProcessInstance hisIns : historicProcessInstances) {WfTaskVo taskVo = new WfTaskVo();// 获取流程状态HistoricVariableInstance processStatusVariable = historyService.createHistoricVariableInstanceQuery().processInstanceId(hisIns.getId()).variableName(ProcessConstants.PROCESS_STATUS_KEY).singleResult();String processStatus = null;if (ObjectUtil.isNotNull(processStatusVariable)) {processStatus = Convert.toStr(processStatusVariable.getValue());}// 兼容旧流程if (processStatus == null) {processStatus = ObjectUtil.isNull(hisIns.getEndTime()) ? ProcessStatus.RUNNING.getStatus() : ProcessStatus.COMPLETED.getStatus();}Map<String, Object> processVariables = hisIns.getProcessVariables();if(processVariables.containsKey("dataId")) {taskVo.setDataId(processVariables.get("dataId").toString());}taskVo.setProcessStatus(processStatus);taskVo.setCreateTime(hisIns.getStartTime());taskVo.setFinishTime(hisIns.getEndTime());taskVo.setProcInsId(hisIns.getId());// 计算耗时if (Objects.nonNull(hisIns.getEndTime())) {taskVo.setDuration(DateUtils.getDatePoor(hisIns.getEndTime(), hisIns.getStartTime()));} else {taskVo.setDuration(DateUtils.getDatePoor(DateUtils.getNowDate(), hisIns.getStartTime()));}// 流程部署实例信息Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(hisIns.getDeploymentId()).singleResult();taskVo.setDeployId(hisIns.getDeploymentId());taskVo.setProcDefId(hisIns.getProcessDefinitionId());taskVo.setProcDefName(hisIns.getProcessDefinitionName());taskVo.setProcDefVersion(hisIns.getProcessDefinitionVersion());taskVo.setCategory(deployment.getCategory());// 当前所处流程List<Task> taskList = taskService.createTaskQuery().processInstanceId(hisIns.getId()).includeIdentityLinks().list();// 任务列表if (CollUtil.isNotEmpty(taskList)) {taskVo.setTaskName(taskList.stream().map(Task::getName).filter(StringUtils::isNotEmpty).collect(Collectors.joining(",")));taskVo.setTaskId(taskList.get(0).getId());} else {List<HistoricTaskInstance> historicTaskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(hisIns.getId()).orderByHistoricTaskInstanceEndTime().desc().list();taskVo.setTaskId(historicTaskInstance.get(0).getId());}taskVoList.add(taskVo);}page.setRecords(taskVoList);return TableDataInfo.build(page);}@Overridepublic List<WfTaskVo> selectAllProcessList(ProcessQuery processQuery) {HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceStartTime().desc();// 构建搜索条件ProcessUtils.buildProcessSearch(historicProcessInstanceQuery, processQuery);List<HistoricProcessInstance> historicProcessInstances = historicProcessInstanceQuery.list();List<WfTaskVo> taskVoList = new ArrayList<>();for (HistoricProcessInstance hisIns : historicProcessInstances) {WfTaskVo taskVo = new WfTaskVo();taskVo.setCreateTime(hisIns.getStartTime());taskVo.setFinishTime(hisIns.getEndTime());taskVo.setProcInsId(hisIns.getId());// 计算耗时if (Objects.nonNull(hisIns.getEndTime())) {taskVo.setDuration(DateUtils.getDatePoor(hisIns.getEndTime(), hisIns.getStartTime()));} else {taskVo.setDuration(DateUtils.getDatePoor(DateUtils.getNowDate(), hisIns.getStartTime()));}// 流程部署实例信息Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(hisIns.getDeploymentId()).singleResult();taskVo.setDeployId(hisIns.getDeploymentId());taskVo.setProcDefId(hisIns.getProcessDefinitionId());taskVo.setProcDefName(hisIns.getProcessDefinitionName());taskVo.setProcDefVersion(hisIns.getProcessDefinitionVersion());taskVo.setCategory(deployment.getCategory());// 当前所处流程List<Task> taskList = taskService.createTaskQuery().processInstanceId(hisIns.getId()).includeIdentityLinks().list();if (CollUtil.isNotEmpty(taskList)) {taskVo.setTaskName(taskList.stream().map(Task::getName).filter(StringUtils::isNotEmpty).collect(Collectors.joining(",")));}taskVoList.add(taskVo);}return taskVoList;}
2、接口部分
/*** 所有的流程*/@SaCheckPermission("workflow:process:allList")@GetMapping(value = "/allList")public TableDataInfo<WfTaskVo> allProcessList(ProcessQuery processQuery, PageQuery pageQuery) {return processService.selectPageAllProcessList(processQuery, pageQuery);}/*** 导出所有流程列表*/@SaCheckPermission("workflow:process:allExport")@Log(title = "所有流程", businessType = BusinessType.EXPORT)@PostMapping("/allExport")public void allExport(@Validated ProcessQuery processQuery, HttpServletResponse response) {List<WfTaskVo> list = processService.selectAllProcessList(processQuery);List<WfOwnTaskExportVo> listVo = BeanUtil.copyToList(list, WfOwnTaskExportVo.class);for (WfOwnTaskExportVo exportVo : listVo) {exportVo.setStatus(ObjectUtil.isNull(exportVo.getFinishTime()) ? "进行中" : "已完成");}ExcelUtil.exportExcel(listVo, "所有流程", WfOwnTaskExportVo.class, response);}
3、效果图如下:
下一节讲前端部分。