Camunda 整合SpringBoot基本Api

洞玄巅峰發表於2024-05-05

程式碼實現:需要介面

@Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private TaskService taskService;

釋出流程:

@GetMapping("/deploy")
    public Object deploy() {
        Deployment obj = repositoryService.createDeployment().name("first-test")
                .addClasspathResource("process.bpmn")
                .deploy();
        return obj.getId() + ":" + obj.getName();
    }

啟動流程:

@Test
    public void startFlow(){

        ProcessInstance instance = runtimeService.startProcessInstanceById("7fb602df-03a0-11ef-8636-ac74b1571bba");
        System.out.println(instance.getProcessInstanceId());
        System.out.println(instance.getProcessDefinitionId());

    }

查詢任務:

 @Test
    void queryTask(){
        List<Task> list = taskService.createTaskQuery().taskAssignee("demo").list();
        list.forEach(x ->{
            System.out.println(x.getAssignee());
            System.out.println(x.getCaseDefinitionId());
            System.out.println(x.getProcessInstanceId());
        });
    }

完成任務

@Test
    void completedTask(){

        Task task = taskService.createTaskQuery().processInstanceId("5fdc7d8d-03a4-11ef-be66-ac74b1571bba").singleResult();
        if(Objects.nonNull(task)){
            taskService.complete(task.getId());
            System.out.println("審批完成...........");
        }

    }

相關文章