package com.codvision.workflow.listener.task;


import com.codvision.workflow.job.WorkFlowTaskClaimTimeOutJob;
import com.codvision.workflow.job.WorkFlowTaskCompleteTimeOutJob;
import com.codvision.workflow.service.WorkFlowService;
import lombok.RequiredArgsConstructor;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;

import static com.codvision.workflow.constant.WorkFlowConstant.WORK_FLOW_TIME_OUT_CLAIM_TASK_ID;
import static com.codvision.workflow.constant.WorkFlowConstant.WORK_FLOW_TIME_OUT_COMPLETE_TASK_ID;

/**
 * 用户任务超时监听器（任务监听器 事件类型 -> create）
 * @author hxl
 */
@RequiredArgsConstructor
@Component(value = "workFlowTaskTimeOutListener")
public class WorkFlowTaskTimeOutListener {

    private final WorkFlowService workFlowService;

    /**
     * 用户任务签收超时
     * @param delegateTask 当前任务
     * @param minutes 分钟
     */
    public void claim(DelegateTask delegateTask, Integer minutes) {
        workFlowService.taskJob(delegateTask, WORK_FLOW_TIME_OUT_CLAIM_TASK_ID, minutes, WorkFlowTaskClaimTimeOutJob.class, null);
    }

    /**
     * 用户任务完成超时
     * @param delegateTask 当前任务
     * @param minutes 分钟
     */
    public void complete(DelegateTask delegateTask, Integer minutes) {
        workFlowService.taskJob(delegateTask, WORK_FLOW_TIME_OUT_COMPLETE_TASK_ID, minutes, WorkFlowTaskCompleteTimeOutJob.class, null);
    }
}
