package nckd.jxccl.hr.psms.plugin.form.other;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.EntityMetadataCache;
import kd.bos.entity.MainEntityType;
import kd.bos.form.FormShowParameter;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import nckd.jxccl.base.common.constant.FormConstant;
import nckd.jxccl.base.common.utils.ConvertUtil;
import nckd.jxccl.hr.psms.common.PerfRankMgmtConstant;
import nckd.jxccl.hr.psms.common.PositionStructureConstant;

import java.util.EventObject;

/**
* 高级人才新建聘任
* 实体标识：nckd_newseniorappoint
* @author W.Y.C
* @date 2025/12/25 19:17
* @version 1.0
*/
public class NewSeniorAppointFormPlugin extends AbstractFormPlugin implements Plugin {

    @Override
    public void afterBindData(EventObject e) {
        // 获取当前页面的FormShowParameter对象
        FormShowParameter showParameter = this.getView().getFormShowParameter();
        //获取列表选择的人员
        Long selectRowId = ConvertUtil.toLong(showParameter.getCustomParam("selectRow"));
        if(selectRowId != null && selectRowId > 0){
            MainEntityType keyBeHavEvalEntityType = EntityMetadataCache.getDataEntityType(PositionStructureConstant.KEYBEHAVEVAL_ENTITYID);
            DynamicObject[] load = BusinessDataServiceHelper.load(new Long[]{selectRowId}, keyBeHavEvalEntityType);
            if(load != null && load.length > 0){
                DynamicObject dynamicObject = load[0].getDynamicObject(PositionStructureConstant.NCKD_PERSON);
                this.getModel().setValue(PositionStructureConstant.NCKD_PERSON, dynamicObject);
                this.getView().updateView(PositionStructureConstant.NCKD_PERSON);
                this.getView().updateView("nckd_querypropfield");
            }
        }
    }

    @Override
    public void afterDoOperation(AfterDoOperationEventArgs e) {
        if(e.getOperationResult() != null && e.getOperationResult().isSuccess()){
            String operateKey = e.getOperateKey();
            if("newseniorappoint".equalsIgnoreCase(operateKey)){
                this.getView().returnDataToParent(Boolean.TRUE);
                this.getView().close();
            }
        }
    }
}