flowable中動態顯示節點的審批人資訊
阿新 • • 發佈:2018-12-25
1、上面的流程圖當任務還沒有到的節點,使用者想看看節點的人的資訊,如果我們常規的是不能實現的。
2、思路就是我們取出節點的表示式,然後用我們流程例項的變數來給他翻譯出來即可,如何做呢?
2.1、通過流程例項id查出歷史表中的所有的變數列表
List<HistoricVariableInstance> hvis = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstanceId).list();
2.2、通過流程例項id獲取所有的節點資訊
List<Process> processes = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId()).getProcesses(); if (CollectionUtils.isNotEmpty(processes)) { for (Process process : processes) { Collection<FlowElement> flowElements = process.getFlowElements();if (CollectionUtils.isNotEmpty(flowElements)) { for (FlowElement flowElement : flowElements) { if (flowElement instanceof UserTask) {
.......... } } } } }
2.3、取出節點的表示式
if (StringUtils.isNotBlank(userTask.getAssignee())) { //處理多例項的顯示 MultiInstanceLoopCharacteristics loopCharacteristics = userTask.getLoopCharacteristics(); if(loopCharacteristics == null) { String expressionValue = null; if (userTask.getName().equals(FlowConstant.FLOW_SUBMITTER)) { expressionValue = processInstance.getStartUserId(); }else { expressionValue = juelExpression.getValue(hvis, userTask.getAssignee()); } if(StringUtils.isNotBlank(expressionValue)) { List<UserVo> userVos = userVoService.getUserByCodeOrGroupId(expressionValue); } }else { String inputDataItem = loopCharacteristics.getInputDataItem(); List<String> values = (List)juelExpression.getValue(hvis, inputDataItem, List.class); if (CollectionUtils.isNotEmpty(values)) { List<UserVo> users = new ArrayList<>(); values.forEach(code->{ List<UserVo> userVos = userVoService.getUserByCodeOrGroupId(code); users.addAll(userVos); }); } } }
2.4、工具類
public Object getValue(List<HistoricVariableInstance> hvis, String exp, Class<?> clazz) { ExpressionFactory factory = new ExpressionFactoryImpl(); SimpleContext context = new SimpleContext(); for (HistoricVariableInstance entry : hvis) { context.setVariable(entry.getVariableName(), factory.createValueExpression(entry.getValue(), Object.class)); } ValueExpression e = factory.createValueExpression(context, exp, clazz); return e.getValue(context); } public String getValue(List<HistoricVariableInstance> hvis, String exp) { return (String) getValue(hvis, exp, String.class); }