package org.springblade.flow.engine.custom.cmd.execution;

import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityManager;
import org.flowable.engine.impl.util.CommandContextUtil;

/**
 * @author LoveMyOrange
 * @create 2022-01-20 18:17
 * @desc 获取会签节点的 二级执行实例
 *  会签有三级
 *      第一级: processInstance级别
 *      第二级: 会签的一条执行实例
 *      第三集: 会签节点分配了多少人就生成多少条
 */
public class GetRootExecutionEntityCmd implements Command<ExecutionEntity> {

    protected String executionId;
    protected String currentTaskDefinitionKey;

    public GetRootExecutionEntityCmd(String executionId, String currentTaskDefinitionKey) {
        this.executionId = executionId;
        this.currentTaskDefinitionKey = currentTaskDefinitionKey;
    }

    @Override
    public ExecutionEntity execute(CommandContext commandContext) {
        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
        ExecutionEntity subP = executionEntityManager.findById(executionId);
        ExecutionEntity parent = subP.getParent();
        return parent;
    }
}
