更多ruoyi-nbcio功能请看演示系统
gitee源代码地址
前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio
演示地址:RuoYi-Nbcio后台管理系统
接上面文章。
1、获取排他网关分支名称、分支表达式、下一级任务节点
/** * 获取排他网关分支名称、分支表达式、下一级任务节点 * @param flowElement * @param data * add by nbacheng */ private Map<String, Object> GetExclusiveGatewayUser(FlowElement flowElement,Map<String, Object> variables){ // 获取所有网关分支 List<SequenceFlow> targetFlows=((ExclusiveGateway)flowElement).getOutgoingFlows(); // 循环每个网关分支 for(SequenceFlow sequenceFlow : targetFlows){ // 获取下一个网关和节点数据 FlowElement targetFlowElement=sequenceFlow.getTargetFlowElement(); // 网关数据不为空 if (StringUtils.isNotBlank(sequenceFlow.getConditionExpression())) { // 获取网关判断条件 String expression = sequenceFlow.getConditionExpression(); if (expression == null ||Boolean.parseBoolean( String.valueOf( FindNextNodeUtil.result(variables, expression.substring(expression.lastIndexOf("{") + 1, expression.lastIndexOf("}")))))) { // 网关出线的下个节点是用户节点 if(targetFlowElement instanceof UserTask){ // 判断是否是会签 UserTask userTask = (UserTask) targetFlowElement; MultiInstanceLoopCharacteristics multiInstance = userTask.getLoopCharacteristics(); if (Objects.nonNull(multiInstance)) {//下个节点是会签节点 Map<String, Object> approvalmap = new HashMap<>(); List<String> getuserlist = getmultiInstanceUsers(multiInstance,userTask); approvalmap.put("approval", getuserlist); if(multiInstance.isSequential()) { approvalmap.put("isSequential", true); } else { approvalmap.put("isSequential", false); } return approvalmap; } } } } } return null; }
2、获取多实例会签用户信息
/** * 获取多实例会签用户信息 * @param userTask * @param multiInstance * **/ List<String> getmultiInstanceUsers(MultiInstanceLoopCharacteristics multiInstance,UserTask userTask) { List<String> sysuserlist = new ArrayList<>(); List<String> rolelist = new ArrayList<>(); rolelist = userTask.getCandidateGroups(); List<String> userlist = new ArrayList<>(); userlist = userTask.getCandidateUsers(); if(rolelist.size() > 0) { List<SysUser> list = new ArrayList<SysUser>(); for(String roleId : rolelist ){ List<SysUser> templist = commonService.getUserListByRoleId(roleId); for(SysUser sysuser : templist) { SysUser sysUserTemp = sysUserService.selectUserById(sysuser.getUserId()); list.add(sysUserTemp); } } sysuserlist = list.stream().map(obj-> (String) obj.getUserName()).collect(Collectors.toList()); } else if(userlist.size() > 0) { List<SysUser> list = new ArrayList<SysUser>(); for(String username : userlist) { SysUser sysUser = sysUserService.selectUserByUserName(username); list.add(sysUser); } sysuserlist = list.stream().map(obj-> (String) obj.getUserName()).collect(Collectors.toList()); } return sysuserlist; }
3、获取下一个节点信息
/** * 获取下一节点 * * @param flowTaskVo 任务 * @return */ @Override public R getNextFlowNode(WfTaskBo flowTaskVo) { // todo 目前只支持部分功能 FlowNextDto flowNextDto = this.getNextFlowNode(flowTaskVo.getTaskId(), flowTaskVo.getVariables()); if (flowNextDto==null) { return R.ok(null); } return R.ok(flowNextDto); } /** modify by nbacheng * 获取下一个节点信息,流程定义上的节点信息 * @param taskId 当前节点id * @param values 流程变量 * @return 如果返回null,表示没有下一个节点,流程结束 */ public FlowNextDto getNextFlowNode(String taskId, Map<String, Object> values) { //当前节点 Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); FlowNextDto flowNextDto = new FlowNextDto(); if (Objects.nonNull(task)) { // 下个任务节点 if (DelegationState.PENDING.equals(task.getDelegationState())) { //对于委派的处理 List<UserTask> nextUserTask = FindNextNodeUtil.getNextUserTasks(repositoryService, task, values); if (CollectionUtils.isNotEmpty(nextUserTask)) { flowNextDto.setType(ProcessConstants.FIXED);//委派是按原来流程执行,所以直接赋值返回 return flowNextDto; } else { return null; } } List<UserTask> nextUserTask = FindNextNodeUtil.getNextUserTasks(repositoryService, task, values); List<SysUser> list = new ArrayList<SysUser>(); if (CollectionUtils.isNotEmpty(nextUserTask)) { for (UserTask userTask : nextUserTask) { MultiInstanceLoopCharacteristics multiInstance = userTask.getLoopCharacteristics(); // 会签节点 if (Objects.nonNull(multiInstance)) { List<String> rolelist = new ArrayList<>(); rolelist = userTask.getCandidateGroups(); List<String> userlist = new ArrayList<>(); userlist = userTask.getCandidateUsers(); UserTask newUserTask = userTask; if(rolelist.size() != 0 && StringUtils.contains(rolelist.get(0), "${flowExp.getDynamic")) {//对表达式多个动态角色做特殊处理 String methodname = StringUtils.substringBetween(rolelist.get(0), ".", "("); Object[] argsPara=new Object[]{}; setMultiFlowExp(flowNextDto,newUserTask,multiInstance,methodname,argsPara); } else if(userlist.size() != 0 && StringUtils.contains(userlist.get(0), "${flowExp.getDynamic")) {//对表达式多个动态用户做特殊处理 String methodname = StringUtils.substringBetween(userlist.get(0), ".", "("); Object[] argsPara=new Object[]{}; setMultiFlowExp(flowNextDto,newUserTask,multiInstance,methodname,argsPara); } else if(userlist.size() != 0 && StringUtils.contains(userlist.get(0), "DepManagerHandler")) {//对部门经理做特殊处理 String methodname = "getInitiatorDepManagers"; // 获取流程发起人 ProcessInstance processInstance = runtimeService .createProcessInstanceQuery() .processInstanceId(task.getProcessInstanceId()) .singleResult(); String startUserId = processInstance.getStartUserId(); Object[] argsPara=new Object[]{}; argsPara=new Object[]{startUserId}; setMultiFlowExp(flowNextDto,newUserTask,multiInstance,methodname,argsPara); } else if(rolelist.size() > 0) { for(String roleId : rolelist ){ List<SysUser> templist = commonService.getUserListByRoleId(roleId); for(SysUser sysuser : templist) { SysUser sysUserTemp = sysUserService.selectUserById(sysuser.getUserId()); list.add(sysUserTemp); } } setMultiFlowNetDto(flowNextDto,list,userTask,multiInstance); } else if(userlist.size() > 0) { for(String username : userlist) { SysUser sysUser = sysUserService.selectUserByUserName(username); list.add(sysUser); } setMultiFlowNetDto(flowNextDto,list,userTask,multiInstance); } else { flowNextDto.setType(ProcessConstants.FIXED); } } else { // 读取自定义节点属性 判断是否是否需要动态指定任务接收人员、组,目前只支持用户角色或多用户,还不支持子流程和变量 //String dataType = userTask.getAttributeValue(ProcessConstants.NAMASPASE, ProcessConstants.PROCESS_CUSTOM_DATA_TYPE); //String userType = userTask.getAttributeValue(ProcessConstants.NAMASPASE, ProcessConstants.PROCESS_CUSTOM_USER_TYPE); List<String> rolelist = new ArrayList<>(); rolelist = userTask.getCandidateGroups(); List<String> userlist = new ArrayList<>(); userlist = userTask.getCandidateUsers(); String assignee = userTask.getAssignee(); // 处理加载动态指定下一节点接收人员信息 if(assignee !=null) { if(StringUtils.equalsAnyIgnoreCase(assignee, "${INITIATOR}")) {//对发起人做特殊处理 SysUser sysUser = new SysUser(); sysUser.setUserName("${INITIATOR}"); list.add(sysUser); setAssigneeFlowNetDto(flowNextDto,list,userTask); } else if(StringUtils.contains(assignee, "${flowExp.getDynamicAssignee")) {//对表达式单个动态用户做特殊处理 String methodname = StringUtils.substringBetween(assignee, ".", "("); SysUser sysUser = new SysUser(); flowExp flowexp = SpringContextUtils.getBean(flowExp.class); Object[] argsPara=new Object[]{}; String username = null; try { username = (String) flowexp.invokeMethod(flowexp, methodname,argsPara); } catch (Exception e) { e.printStackTrace(); } sysUser.setUserName(username); list.add(sysUser); setAssigneeFlowNetDto(flowNextDto,list,userTask); } else if(StringUtils.contains(assignee, "${flowExp.getDynamicList")) {//对表达式多个动态用户做特殊处理 String methodname = StringUtils.substringBetween(assignee, ".", "("); flowExp flowexp = SpringContextUtils.getBean(flowExp.class); Object[] argsPara=new Object[]{}; try { list = (List<SysUser>) flowexp.invokeMethod(flowexp, methodname,argsPara); } catch (Exception e) { e.printStackTrace(); } setUsersFlowNetDto(flowNextDto,list,userTask); } else if(StringUtils.contains(assignee, "${DepManagerHandler")) {//对部门经理多用户做特殊处理 String methodname = "getInitiatorDepManagers"; // 获取流程发起人 ProcessInstance processInstance = runtimeService .createProcessInstanceQuery() .processInstanceId(task.getProcessInstanceId()) .singleResult(); String startUserId = processInstance.getStartUserId(); flowExp flowexp = SpringContextUtils.getBean(flowExp.class); Object[] argsPara=new Object[]{}; argsPara[0] = startUserId; try { list = (List<SysUser>) flowexp.invokeMethod(flowexp, methodname,argsPara); } catch (Exception e) { e.printStackTrace(); } setUsersFlowNetDto(flowNextDto,list,userTask); } else { SysUser sysUser = sysUserService.selectUserByUserName(assignee); list.add(sysUser); setAssigneeFlowNetDto(flowNextDto,list,userTask); } } else if(userlist.size()>0 && StringUtils.equalsAnyIgnoreCase(userlist.get(0), "${DepManagerHandler.getUsers(execution)}")) {//对部门经理做特殊处理 // 获取流程发起人 ProcessInstance processInstance = runtimeService .createProcessInstanceQuery() .processInstanceId(task.getProcessInstanceId()) .singleResult(); String startUserId = processInstance.getStartUserId(); flowExp flowexp = SpringContextUtils.getBean(flowExp.class); String manager = flowexp.getDynamicManager(startUserId); SysUser sysUser = sysUserService.selectUserByUserName(manager); list.add(sysUser); setUsersFlowNetDto(flowNextDto,list,userTask); } else if(userlist.size() > 0) { for(String username : userlist) { SysUser sysUser = sysUserService.selectUserByUserName(username); list.add(sysUser); } setUsersFlowNetDto(flowNextDto,list,userTask); setMultiFinishFlag(task,flowNextDto,list); } else if(rolelist.size() > 0) { for(String roleId : rolelist ){ List<SysUser> templist = commonService.getUserListByRoleId(roleId); for(SysUser sysuser : templist) { SysUser sysUserTemp = sysUserService.selectUserByUserName(sysuser.getUserName()); list.add(sysUserTemp); } } setUsersFlowNetDto(flowNextDto,list,userTask); setMultiFinishFlag(task,flowNextDto,list); } else { flowNextDto.setType(ProcessConstants.FIXED); } } } return flowNextDto; } else { return null; } } return null; }