package com.codvision.workflow.listener.execution;

import lombok.RequiredArgsConstructor;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static com.codvision.base.support.BaseConst.COMMA_SYMBOL;

/**
 * 多实例执行监听器
 * @author hxl
 */
@RequiredArgsConstructor
@Component(value = "workFlowMultiInstanceListener")
public class WorkFlowMultiInstanceListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution execution) {

    }

    /**
     * 获取用户ID集合
     * @param variable 变量名称，支持表单变量、自定义变量
     * @return 用户ID集合
     */
    public List<Integer> execute(String variable) {
        return Arrays.stream(variable.split(COMMA_SYMBOL)).map(s -> Integer.parseInt(s.trim())).collect(Collectors.toList());
    }
}
