package com.pusong.workflow.listening;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;

import java.util.HashMap;
import java.util.Map;

public class leaveWorkFlowOutcome {

    private void leaveWorkFlowOutcome(){

        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        Deployment deploy = processEngine.getRepositoryService()
                .createDeployment()
                .addClasspathResource("bpmn/leaveInclusiveGateway.bpmn")
                .name("请假流程")
                .deploy();
        Map<String, Object> assignees = new HashMap<>();
        assignees.put("type", 5);
        String businessKey = "1";
        ProcessInstance processInstance = processEngine.getRuntimeService()
                .startProcessInstanceByKey("leaveInclusiveGateway", businessKey, assignees);
        TaskService taskService = processEngine.getTaskService();
        Task task = taskService
                .createTaskQuery()
                .processDefinitionKey("leaveInclusiveGateway")
                .taskAssignee("张三")
                .singleResult();
        if (task != null) {
            taskService.complete(task.getId());
        }
    }
}
