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);}