更多ruoyi-nbcio功能请看演示系统
gitee源代码地址
前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio
演示地址:RuoYi-Nbcio后台管理系统
相应的后端也要做一些调整
1、启动流程修改如下:
/** * 启动流程实例 */ private R startProcess(ProcessDefinition procDef, Map<String, Object> variables) { if (ObjectUtil.isNotNull(procDef) && procDef.isSuspended()) { throw new ServiceException("流程已被挂起,请先激活流程"); } // 设置流程发起人Id到流程中,包括变量 String userStr = TaskUtils.getUserName(); SysUser sysUsr = sysUserService.selectUserByUserName(userStr); setFlowVariables(sysUsr,variables); Map<String, Object> variablesnew = variables; Map<String, Object> usermap = new HashMap<String, Object>(); List<String> userlist = new ArrayList<String>(); boolean bparallelGateway = false; boolean bapprovedEG = false; //业务数据id String dataId = variables.get("dataId").toString(); if(StringUtils.isNotEmpty(dataId)) {//自定义业务表单 //设置自定义表单dataid的数据 WfMyBusiness flowmybusiness = wfMyBusinessServiceImpl.getByDataId(variables.get("dataId").toString()); String serviceImplName = flowmybusiness.getServiceImplName(); WfCallBackServiceI flowCallBackService = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplName); if (flowCallBackService!=null){ Object businessDataById = flowCallBackService.getBusinessDataById(variables.get("dataId").toString()); variables.put("formData",businessDataById); } } //获取下个节点信息 getNextFlowInfo(procDef, variablesnew, usermap, variables, userlist); //取出两个特殊的变量 if(variablesnew.containsKey("bparallelGateway")) {//并行网关 bparallelGateway = (boolean) variablesnew.get("bparallelGateway"); variablesnew.remove("bparallelGateway"); } if(variablesnew.containsKey("bapprovedEG")) {//通用拒绝同意排它网关 bapprovedEG = (boolean) variablesnew.get("bapprovedEG"); variablesnew.remove("bapprovedEG"); } // 发起流程实例 ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDef.getId(), variables); // 第一个用户任务为发起人,则自动完成任务 //wfTaskService.startFirstTask(processInstance, variables); R<Void> result = setNextAssignee(processInstance, usermap, userlist, sysUsr, variables, bparallelGateway, bapprovedEG); if(StringUtils.isNotEmpty(dataId)) {//自定义业务表单 // 流程发起后的自定义业务更新-需要考虑两种情况,第一个发起人审批或跳过 List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).active().list(); /*======================todo 启动之后 回调以及关键数据保存======================*/ //如果保存数据前未调用必调的FlowCommonService.initActBusiness方法,就会有问题 LoginUser sysUser = commonService.getLoginUser(); if(tasks!=null) { SysUser sysTaskUser = new SysUser(); List <String> listUser = new ArrayList<String>(); List <String> listId = new ArrayList<String>(); List <String> listName = new ArrayList<String>(); String taskUser = ""; String taskid = ""; String taskName = ""; int taskPriority = 0; for(Task task : tasks) { if(task.getAssignee() != null) { sysTaskUser = commonService.getSysUserByUserName(task.getAssignee()); listUser.add(sysTaskUser.getNickName()); } listId.add(task.getId()); listName.add(task.getName()); taskPriority = task.getPriority(); } taskUser = listUser.stream().map(String::valueOf).collect(Collectors.joining(",")); taskid = listId.stream().map(String::valueOf).collect(Collectors.joining(",")); taskName = listName.stream().map(String::valueOf).collect(Collectors.joining(",")); WfMyBusiness business = wfMyBusinessServiceImpl.getByDataId(dataId); business.setProcessDefinitionId(procDef.getId()); business.setProcessInstanceId(processInstance.getProcessInstanceId()); business.setActStatus(ActStatus.doing); business.setProposer(sysUser.getUsername()); business.setTaskId(taskid); business.setTaskName(taskName); business.setTaskNameId(taskid); business.setPriority(String.valueOf(taskPriority)); business.setDoneUsers(""); business.setTodoUsers(taskUser); wfMyBusinessService.updateById(business); //spring容器类名 String serviceImplNameafter = business.getServiceImplName(); WfCallBackServiceI flowCallBackServiceafter = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplNameafter); // 流程处理完后,进行回调业务层 business.setValues(variables); if (flowCallBackServiceafter!=null)flowCallBackServiceafter.afterFlowHandle(business); } else { WfMyBusiness business = wfMyBusinessServiceImpl.getByDataId(dataId); business.setProcessDefinitionId(procDef.getId()); business.setProcessInstanceId(processInstance.getProcessInstanceId()); business.setActStatus(ActStatus.pass); business.setProposer(sysUser.getUsername()); business.setTaskId(""); business.setTaskName(""); business.setTaskNameId(""); business.setDoneUsers(""); business.setTodoUsers(""); wfMyBusinessService.updateById(business); //spring容器类名 String serviceImplNameafter = business.getServiceImplName(); WfCallBackServiceI flowCallBackServiceafter = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplNameafter); // 流程处理完后,进行回调业务层 business.setValues(variables); if (flowCallBackServiceafter!=null)flowCallBackServiceafter.afterFlowHandle(business); } } return result; }
2、获取表单列表修改如下:
/** * 获取历史流程表单信息 */ private List<FormConf> processFormList(BpmnModel bpmnModel, HistoricProcessInstance historicProcIns, String dataId) { List<FormConf> procFormList = new ArrayList<>(); List<HistoricActivityInstance> activityInstanceList = historyService.createHistoricActivityInstanceQuery() .processInstanceId(historicProcIns.getId()).finished() .activityTypes(CollUtil.newHashSet(BpmnXMLConstants.ELEMENT_EVENT_START, BpmnXMLConstants.ELEMENT_TASK_USER)) .orderByHistoricActivityInstanceStartTime().asc() .list(); List<String> processFormKeys = new ArrayList<>(); for (HistoricActivityInstance activityInstance : activityInstanceList) { // 获取当前节点流程元素信息 FlowElement flowElement = ModelUtils.getFlowElementById(bpmnModel, activityInstance.getActivityId()); // 获取当前节点表单Key String formKey = ModelUtils.getFormKey(flowElement); if (formKey == null) { continue; } boolean localScope = Convert.toBool(ModelUtils.getElementAttributeValue(flowElement, ProcessConstants.PROCESS_FORM_LOCAL_SCOPE), false); Map<String, Object> variables; if (localScope) { // 查询任务节点参数,并转换成Map variables = historyService.createHistoricVariableInstanceQuery() .processInstanceId(historicProcIns.getId()) .taskId(activityInstance.getTaskId()) .list() .stream() .collect(Collectors.toMap(HistoricVariableInstance::getVariableName, HistoricVariableInstance::getValue)); } else { if (processFormKeys.contains(formKey)) { continue; } variables = historicProcIns.getProcessVariables(); processFormKeys.add(formKey); } Map<String, Object> formvariables = new HashedMap<String, Object>(); //遍历Map if(variables.containsKey("variables")) { formvariables = (Map<String, Object>)((Map<String, Object>) variables.get("variables")).get("formValue"); } // 非节点表单此处查询结果可能有多条,只获取第一条信息 List<WfDeployFormVo> formInfoList = deployFormMapper.selectVoList(new LambdaQueryWrapper<WfDeployForm>() .eq(WfDeployForm::getDeployId, historicProcIns.getDeploymentId()) .eq(WfDeployForm::getFormKey, formKey) .eq(localScope, WfDeployForm::getNodeKey, flowElement.getId())); //@update by Brath:避免空集合导致的NULL空指针 WfDeployFormVo formInfo = formInfoList.stream().findFirst().orElse(null); if (ObjectUtil.isNotNull(formInfo)) { // 旧数据 formInfo.getFormName() 为 null String formName = Optional.ofNullable(formInfo.getFormName()).orElse(StringUtils.EMPTY); String title = localScope ? formName.concat("(" + flowElement.getName() + ")") : formName; FormConf formConf = JsonUtils.parseObject(formInfo.getContent(), FormConf.class); if (null != formConf) { //ProcessFormUtils.fillFormData(formConf, variables); formConf.setTitle(title); formConf.setFormValues(formvariables); procFormList.add(formConf); } } } if(StringUtils.isNoneEmpty(dataId)) { WfMyBusiness business = wfMyBusinessServiceImpl.getByDataId(dataId); String serviceImplName = business.getServiceImplName(); WfCallBackServiceI flowCallBackService = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplName); // 流程处理完后,进行回调业务层 if (flowCallBackService!=null){ Map<String, Object> customMap = new HashMap<String, Object>(); FormConf formConf = new FormConf(); Object businessDataById = flowCallBackService.getBusinessDataById(dataId); customMap.put("formData",businessDataById); customMap.put("routeName", business.getRouteName()); formConf.setFormValues(customMap); procFormList.add(formConf); } } return procFormList; }
3、效果图如下: