更多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)@Overridepublic 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、其中相应的方法如下:
@Overridepublic 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*/@Overridepublic 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;
}