更多ruoyi-nbcio功能请看演示系统
gitee源代码地址
前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio
演示地址:RuoYi-Nbcio后台管理系统
接上一个文章。
1、设置多实例等相关参数
//设置单用户下一节点流程数据 private void setAssigneeFlowNetDto(FlowNextDto flowNextDto,List<SysUser> list,UserTask userTask) { flowNextDto.setVars(ProcessConstants.PROCESS_APPROVAL); flowNextDto.setType(ProcessConstants.USER_TYPE_ASSIGNEE); flowNextDto.setUserList(list); flowNextDto.setUserTask(userTask); } //设置多用户下一节点流程数据 private void setUsersFlowNetDto(FlowNextDto flowNextDto,List<SysUser> list,UserTask userTask) { flowNextDto.setVars(ProcessConstants.PROCESS_APPROVAL); flowNextDto.setType(ProcessConstants.USER_TYPE_USERS); flowNextDto.setUserList(list); flowNextDto.setUserTask(userTask); } //设置多实例结束标志 private void setMultiFinishFlag(Task task,FlowNextDto flowNextDto,List<SysUser> list) { String definitionld = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult().getProcessDefinitionId(); //获取bpm(模型)对象 BpmnModel bpmnModel = repositoryService.getBpmnModel(definitionld); //通过节点定义key获取当前节点 FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey()); if(flowNode instanceof UserTask ){ UserTask curuserTask = (UserTask) flowNode; MultiInstanceLoopCharacteristics curmultiInstance = curuserTask.getLoopCharacteristics(); if (Objects.nonNull(curmultiInstance)) { if(list.size()>1) {//多人选择的时候,从redis获取之前监听器写入的会签结束信息 String smutinstance_next_finish = Constants.MUTIINSTANCE_NEXT_FINISH + task.getProcessInstanceId(); if(Objects.nonNull(RedisUtils.getCacheObject(smutinstance_next_finish))) { flowNextDto.setBmutiInstanceFinish(true); } } } } } //设置多实例流程表达式 private void setMultiFlowExp(FlowNextDto flowNextDto,UserTask newUserTask,MultiInstanceLoopCharacteristics multiInstance,String methodname,Object[] argsPara) { List<SysUser> list = new ArrayList<SysUser>(); flowExp flowexp = SpringContextUtils.getBean(flowExp.class); //Object[] argsPara=new Object[]{}; List<String> templist = new ArrayList<String>(); try { templist = (List<String>) flowexp.invokeMethod(flowexp, methodname,argsPara); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } for(String sysuser : templist) { SysUser sysUserTemp = sysUserService.selectUserByUserName(sysuser); list.add(sysUserTemp); } newUserTask.setAssignee("${assignee}"); newUserTask.setCandidateUsers(templist); setMultiFlowNetDto(flowNextDto,list,newUserTask,multiInstance); } //设置多实例流程数据 private void setMultiFlowNetDto(FlowNextDto flowNextDto,List<SysUser> list,UserTask userTask,MultiInstanceLoopCharacteristics multiInstance) { flowNextDto.setVars(ProcessConstants.PROCESS_MULTI_INSTANCE_USER); flowNextDto.setType(ProcessConstants.PROCESS_MULTI_INSTANCE); flowNextDto.setUserList(list); flowNextDto.setUserTask(userTask); if(multiInstance.isSequential()) { flowNextDto.setBisSequential(true); } else { flowNextDto.setBisSequential(false); } }
2、校验el表达示例
/** * 校验el表达示例 * * @param map * @param expression * @return */ public static Object result(Map<String, Object> map, String expression) { Object result = null; try { FelEngine fel = new FelEngineImpl(); FelContext ctx = fel.getContext(); for (Map.Entry<String, Object> entry : map.entrySet()) { ctx.set(entry.getKey(), entry.getValue()); System.out.print(entry.getKey() + "-"+ entry.getValue()); } String exp = ""; if (expression.indexOf("<") >0) { exp = expression.substring(0, expression.indexOf("<")); } else if (expression.indexOf(">") >0) { int index =expression.indexOf(">"); exp = expression.substring(0, index); } else if (expression.indexOf("==") >0) { exp = expression.substring(0, expression.indexOf("==")); } exp =expression.replace(exp, ctx.get(exp).toString()); result = fel.eval(exp); //result = fel.eval(expression); } catch (Exception e) { result = null; } return result; }
3、获取排他网关分支名称、分支表达式是否存在
/** * 获取排他网关分支名称、分支表达式是否存在${approved} * @param flowElement * @param * add by nbacheng */ public static boolean GetExclusiveGatewayExpression(FlowElement flowElement) { // 获取所有网关分支 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.contains("${approved}")) { return true; } } } return false; }
4、工作流任务工具类主要是增加username
/** * 工作流任务工具类 * * @author konbai * @createTime 2022/4/24 12:42 */ public class TaskUtils { public static String getUserId() { return String.valueOf(LoginHelper.getUserId()); } public static String getUserName() { return LoginHelper.getUserName(); } /** * 获取用户组信息 * * @return candidateGroup */ public static List<String> getCandidateGroup() { List<String> list = new ArrayList<>(); LoginUser user = LoginHelper.getLoginUser(); if (ObjectUtil.isNotNull(user)) { if (ObjectUtil.isNotEmpty(user.getRoles())) { user.getRoles().forEach(role -> list.add(TaskConstants.ROLE_GROUP_PREFIX + role.getRoleId())); } if (ObjectUtil.isNotNull(user.getDeptId())) { list.add(TaskConstants.DEPT_GROUP_PREFIX + user.getDeptId()); } } return list; } }
5、效果图如下: