Activiti 根据模型ID,或者流程定义ID获取节点列表

public void viewProgress(){
		String modelId = "150019";//模型ID
		logger.info("[开始]-获取流程节点");
		try {
//			byte[] bytes = repositoryService.getModelEditorSource(modelId);
//			if (null == bytes){
//				System.out.println("模型数据为空,模型不存在");
//			}
//			JsonNode modelNode = new ObjectMapper().readTree(bytes);
//			BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
			
			//根据流程定义id来获取BpmnModel对象
			String processDefinitionId="level-2:16:150077";
			BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
			if (null == bpmnModel){
				System.out.println("模型数据为空,模型不存在");
			}
			List<Process> processList = bpmnModel.getProcesses();
			if (CollectionUtil.isNotEmpty(processList)){
				List<Element> list = new ArrayList<>();
				processList.forEach(process -> {
					Collection<FlowElement> elementList = process.getFlowElements();
					for (FlowElement flowElement : elementList) {
						if (StrUtil.isBlank(flowElement.getName())){
							continue;
						}
						Element element = new Element();
						element.setId(flowElement.getId());
						element.setName(flowElement.getName());
						if (flowElement instanceof StartEvent){
							element.setType("Start");
						}else if (flowElement instanceof UserTask){
							element.setType("Task");
						}else if (flowElement instanceof EndEvent){
							element.setType("End");
						}else if (flowElement instanceof SequenceFlow){
							// 流程连接线
							continue;
						}else if (flowElement instanceof ExclusiveGateway){
							// 流程网关
							continue;
						}
						list.add(element);
						System.out.println("ID:"+flowElement.getId()+",Name:"+flowElement.getName());
					}
				});
			}
			logger.info("[完成]-获取流程节点");
		} catch (Exception e) {
			logger.error("【异常】-获取流节点失败!" + e.getMessage());
		}
	}

返回结果:

{
  "code": 0,
  "msg": null,
  "data": [
    {
      "id": "sid-9C08BB63-9E1A-4A7F-8B32-C01D3C11B8AA",
      "name": "start",
      "type": "Start"
    },
    {
      "id": "sid-3187B379-E85F-4EAC-8958-2A7952CBA551",
      "name": "HR",
      "type": "Task"
    },
    {
      "id": "sid-6133B0EC-C24F-4CBF-BB0D-9629B37FA42B",
      "name": "CEO",
      "type": "Task"
    },
    {
      "id": "sid-B7AC198D-E5C2-4240-B26F-ADFE8705360A",
      "name": "End",
      "type": "End"
    }
  ]
}

猜你喜欢

转载自blog.csdn.net/JavaAlpha/article/details/108867659