package nckd.jimin.jyyy.hr.plugin.workflow;

import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.workflow.api.AgentExecution;
import kd.bos.workflow.engine.extitf.IWorkflowPlugin;
import kd.sdk.plugin.Plugin;

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

/**
 * 离职流程使用工作流插件
 * 用于取员工是否存在未终止的其他附属协议
 * Tyx
 * 2025-08-18
 */
public class GetOtherContractWorkflowPlugin implements IWorkflowPlugin {
    private static final Log log = LogFactory.getLog(GetOtherContractWorkflowPlugin.class);

    @Override
    public void notify(AgentExecution execution) {
        IWorkflowPlugin.super.notify(execution);
        String personId = execution.getVariable("personId").toString();
        DynamicObjectCollection cols = HRWorkflowUtils.getOtherContractByPersonId(personId);
        if(cols.size() > 0) {
            execution.setVariable("isExistOtherCon", true);
            List<String> nameList = cols.stream().map(dyx -> dyx.getString("entryentity.contracttemplate.name")).collect(Collectors.toList());
            execution.setVariable("contractName", String.join("/", nameList));
        }
    }
}