基于若依的ruoyi-nbcio流程管理系统增加读取节点扩展属性的方法

简介: 基于若依的ruoyi-nbcio流程管理系统增加读取节点扩展属性的方法

更多ruoyi-nbcio功能请看演示系统

gitee源代码地址

前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio

演示地址:RuoYi-Nbcio后台管理系统

       我们的在流程设计器里会根据需要再不同的节点增加扩展属性,如何动态读取这些扩展属性,下面提供一种方法。

      1、比如设计里,在这个节点增加属性test2,值是属性2

2、可以在流程启动的时候读取发起人节点的扩展属性或在complete里增加读取扩展属性

下面是在complete读取当前节点的扩展属性

Map<String, Object> flowProperties = getFlowProperties(taskBo.getProcInsId());

/**
     * 完成任务
     *
     * @param taskBo 请求实体参数
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void complete(WfTaskBo taskBo) {
        Task task = taskService.createTaskQuery().taskId(taskBo.getTaskId()).singleResult();
        if (Objects.isNull(task)) {
            throw new ServiceException("任务不存在");
        }
        //获取流程当前节点设置的扩展属性值,需要的时候可以使用
        //Map<String, Object> flowProperties = getFlowProperties(taskBo.getProcInsId());

3、其中相应的方法如下:

@Override
  public Map<String, Object> getFlowProperties(String procInsId) {
    try {
            Task task = taskService.createTaskQuery().processInstanceId(procInsId).active().singleResult();
            ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
            BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
            List<FlowViewerDto> flowViewerList = (List<FlowViewerDto>) getFlowViewer(task.getProcessInstanceId()).getData();
            FlowViewerDto dto = flowViewerList.stream().filter(flowViewerDto -> !flowViewerDto.isCompleted()).findFirst().orElse(null);
            String actId;
            if (ObjectUtils.isNotEmpty(dto)) {
                actId = dto.getKey();
            } else {
                return null;
            }
            FlowElement element = bpmnModel.getFlowElement(actId);
            List<ExtensionElement> extensionElements = element
                    .getExtensionElements().get("properties");
            List<ExtensionElement> child = null;
            for (ExtensionElement extensionElement : extensionElements) {
                child = extensionElement.getChildElements().get("property");
            }
            List<Map<String, List<ExtensionAttribute>>> list = new ArrayList<>();
            child.stream().forEach(o -> {
                Map<String, List<ExtensionAttribute>> attributeMap = o.getAttributes();
                list.add(attributeMap);
            });
            Map<String, Object> result = new HashMap();
            list.stream().forEach(a -> {
                result.put(a.get("name").get(0).getValue(), a.get("value").get(0).getValue());
            });
            return result;
        } catch (NullPointerException nullExcption) {
            return null;
        }
  }
    /**
     * 获取流程执行过程
     *
     * @param procInsId
     * @return
     */
    @Override
    public R getFlowViewer(String procInsId) {
        List<FlowViewerDto> flowViewerList = new ArrayList<>();
        FlowViewerDto flowViewerDto;
        // 获得活动的节点
        List<HistoricActivityInstance> hisActIns = historyService.createHistoricActivityInstanceQuery()
                .processInstanceId(procInsId)
                .orderByHistoricActivityInstanceStartTime()
                .asc().list();
        for (HistoricActivityInstance activityInstance : hisActIns) {
            if (!"sequenceFlow".equals(activityInstance.getActivityType())) {
                flowViewerDto = new FlowViewerDto();
                flowViewerDto.setKey(activityInstance.getActivityId());
                flowViewerDto.setCompleted(!Objects.isNull(activityInstance.getEndTime()));
                flowViewerList.add(flowViewerDto);
            }
        }
        return R.ok(flowViewerList);
    }

4、其中FlowViewerDto如下:

/**
 */
@Data
public class FlowViewerDto implements Serializable {
    private String key;
    private boolean completed;
}


相关文章
|
5月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统修复自定义业务表单的收回功能
基于若依的ruoyi-nbcio流程管理系统修复自定义业务表单的收回功能
56 1
|
2月前
|
数据库连接 数据库
实现加载驱动、得到数据库对象、关闭资源的代码复用,将代码提取到相应的工具包里边。优化程序
该博客文章展示了如何通过创建工具类`Connectiontools`实现数据库连接、语句执行以及资源关闭的代码复用,以优化程序并提高数据库操作的效率和安全性。
|
5月前
|
前端开发 数据库
基于若依的ruoyi-nbcio流程管理系统增加流程节点配置(二)
基于若依的ruoyi-nbcio流程管理系统增加流程节点配置(二)
66 1
|
5月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务回写状态的一种新方法(二)
基于若依的ruoyi-nbcio流程管理系统自定义业务回写状态的一种新方法(二)
53 2
|
5月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务回写状态的一种新方法(一)
基于若依的ruoyi-nbcio流程管理系统自定义业务回写状态的一种新方法(一)
60 1
|
5月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(三)
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(三)
50 2
|
5月前
|
JSON 移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(二)
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(二)
74 2
|
5月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统修复自定义业务表单的取消终止功能
基于若依的ruoyi-nbcio流程管理系统修复自定义业务表单的取消终止功能
58 3
|
5月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题(续)
基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题(续)
43 1
|
5月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题需求
基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题需求
72 1
下一篇
无影云桌面