package nckd.jimin.jyyy.hr.hom.formplugin;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;

import java.util.EventObject;

/**
 * Module           :核心人力云-入职管理-入职人员管理-入职申请
 * Description      :入职申请/办理表单插件，处理offer字段
 * @author Tyx
 * @date  2025/6/23
 * 标识 hom_onbrdinfo
 */
public class OnbrdOfferInfoEditEx extends AbstractFormPlugin implements Plugin {

    private static String OFFER_ENTITY = "tso_somk_offerbase";

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
        IDataModel model = this.getModel();
    }

    @Override
    public void beforeBindData(EventObject e) {
        super.beforeBindData(e);
        IDataModel model = this.getModel();
        DynamicObject bill = model.getDataEntity();
        if(bill.getBoolean("nckd_isuseoffer")) {
            return;
        }
        //查询offer数据
        Long offerId = bill.getLong("offerid");
        if(offerId == 0L)
            return;
        DynamicObject offerDyn = BusinessDataServiceHelper.loadSingle(offerId, OFFER_ENTITY);
        //赋值
        bill.set("nckd_isgrrz", false);
        bill.set("nckd_sxqxs", offerDyn.getBigDecimal("nckd_sxqxs"));
        bill.set("nckd_sxqyx", offerDyn.getBigDecimal("nckd_sxqyx"));
        bill.set("nckd_syqxs", offerDyn.getBigDecimal("nckd_syqxs"));
        bill.set("nckd_zzhnx", offerDyn.getBigDecimal("nckd_zzhnx"));
        bill.set("nckd_ncoefficient", offerDyn.getBigDecimal("nckd_ncoefficient"));
        bill.set("nckd_isuseoffer",true);
    }
}