package nckd.jimin.jyyy.hr.tsc.tso.formplugin.web.offer.infopage;

import com.kingdee.util.ObjectUtils;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.drp.mdr.common.util.ObjectUtil;
import kd.sdk.plugin.Plugin;
import nckd.jimin.jyyy.hr.swc.hcdm.formplugin.web.AdjustJobBillEffectOp;
import nckd.jimin.jyyy.hr.tsrsc.plugin.util.RecUtils;

import java.util.EventObject;

/**
 * Offer携带招聘需求的部门和岗位
 * 招聘需求负责人也携带过去，用于后面Offer过滤
 * @author ：Tyx
 * @since ：2025-06-30
 */
public class WaitOfferBaseFormPluginEx extends AbstractFormPlugin implements Plugin {

    private static final Log log = LogFactory.getLog(WaitOfferBaseFormPluginEx.class);
    private static String appFile_entity = "tspr_appfile";  //应聘档案/候选人
    private static String arfrsm_entity = "tstpm_arfrsm";   //应聘登记表
    private static String casApply_entity = "nckd_casrecrapply";    //临时招聘申请



    @Override
    public void afterCreateNewData(EventObject e) {
        super.afterCreateNewData(e);
//        IDataModel model = this.getModel();
//        //根据应聘档案字段获取候选人档案-应聘登记表上的Moka招聘需求HC
//        DynamicObject bill = model.getDataEntity();
//        Long appFileId = bill.getLong("appfile.id");
//        DynamicObject applyEntry = RecUtils.getCasApplyEntryDyn(appFileId);
//        if(!ObjectUtil.isEmpty(applyEntry)) {
//            model.setValue("peadminorg", applyEntry.getLong("entryentity.nckd_recruitorg.id"));
//            model.setValue("peposition", applyEntry.getLong("entryentity.nckd_recruitpost.id"));
//        }
    }

    @Override
    public void beforeBindData(EventObject e) {
        super.beforeBindData(e);
    }

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
        IDataModel model = this.getModel();
        if(model.getDataEntity().getBoolean("nckd_isuseapply"))
            return;
        //根据应聘档案字段获取候选人档案-应聘登记表上的Moka招聘需求HC
        DynamicObject bill = model.getDataEntity();
        Long appFileId = bill.getLong("appfile.id");
        DynamicObject applyEntry = RecUtils.getCasApplyEntryDyn(appFileId);
        if(!ObjectUtil.isEmpty(applyEntry)) {
            model.setValue("peadminorg", applyEntry.getLong("entryentity.nckd_recruitorg.id"));
            model.setValue("peposition", applyEntry.getLong("entryentity.nckd_recruitpost.id"));
            model.setValue("nckd_manager", applyEntry.getLong("nckd_person.id"));
            model.setValue("nckd_isuseapply", true);
        }
    }
}