flowable中動態顯示節點的審批人信息


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM