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

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.ObjectUtils;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.workflow.api.AgentExecution;
import kd.bos.workflow.engine.extitf.IWorkflowPlugin;
import kd.hrmp.hrpi.business.infrastructure.utils.QFilterUtil;
import kd.sdk.plugin.Plugin;
import nckd.jimin.jyyy.hr.hrmp.hbpm.task.SyncPositionTask;

import java.util.HashSet;
import java.util.Set;

/**
 * 通用工作流插件 Tyx 2025-05-26
 * 获取人员职等
 */
public class GetJobLevelWorkflowPlugin implements IWorkflowPlugin {

    private static final Log log = LogFactory.getLog(GetJobLevelWorkflowPlugin.class);

    @Override
    public void notify(AgentExecution execution) {
        String personId = execution.getVariable("personId").toString();

        QFilter filter = QFilterUtil.getCurrentQf();
        filter.and(QFilterUtil.getDataStatusFilter());
        filter.and("person.id", QCP.equals, Long.valueOf(personId));
        DynamicObject bill = QueryServiceHelper.queryOne("hrpi_empjobrel", "jobgrade.number", new QFilter[]{filter});
        if(!ObjectUtils.isEmpty(bill)) {
            execution.setVariable("jobGradeNo", bill.getString("jobgrade.number"));
        }
        log.info("GetJobLevelWorkflowPlugin 职等编码 : {}", execution.getVariable("jobGradeNo"));
    }
}