[Flowable]用戶任務UserTask

import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

[@Service](https://my.oschina.net/service)
public class FlowableService {

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private RuntimeService runtimeService;

    private final Logger logger = LoggerFactory.getLogger(getClass());

    public int service() {
        logger.debug("開始工做流。");

        System.out.println("Number of process definitions : "
                + repositoryService.createProcessDefinitionQuery().count());
        System.out.println("Number of tasks : " + taskService.createTaskQuery().count());
        runtimeService.startProcessInstanceByKey("oneTaskProcess");
        System.out.println("Number of tasks after process start: "
                + taskService.createTaskQuery().count());

        return 0;
    }

    /**
     * 查詢分配給Kermit的待處理的任務。
     */
    public int listTask() {
        logger.debug("開始工做流。");
        List<Task> tasks = taskService.createTaskQuery().taskAssignee("kermit").list();
//        taskService.createTaskQuery().taskCandidateGroup("managers").list();

        return tasks.size();
    }

    /**
     * 完成第一個任務。
     */
    public int complete() {
        logger.debug("開始工做流。");

        List<Task> tasks = taskService.createTaskQuery().list();
        if (tasks.size() > 0) {
            Task task = tasks.get(0);
            Map<String, Object> variables = new HashMap<>();
            variables.put("是否贊成", "是");
            taskService.complete(task.getId(), variables);
            logger.info("完成任務名稱:{}", task.getName());
            return 1;
        }

        return 0;
    }

}
相關文章
相關標籤/搜索