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

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.sdk.plugin.Plugin;
import nckd.jxccl.base.common.constant.FormConstant;
import nckd.jxccl.base.common.utils.ConvertUtil;
import nckd.jxccl.hr.hstu.common.HonorStudentConstant;
import nckd.jxccl.hr.psms.common.PositionStructureConstant;

import java.util.Objects;

/**
* 职级
* 实体标识：hbjm_joblevelhr
* @author W.Y.C
* @date 2025/12/22 18:47
* @version 1.0
*/
public class JobLevelHrFormPlugin extends AbstractFormPlugin implements Plugin {

    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        String fieldKey = e.getProperty().getName();
        ChangeData[] changeSet = e.getChangeSet();

        if ("nckd_joblevelscm".equalsIgnoreCase(fieldKey)) {
            if (changeSet != null && changeSet.length > 0) {
                Object oldValue = changeSet[0].getOldValue();
                Object newValue = changeSet[0].getNewValue();
                if (!Objects.equals(oldValue, newValue)) {
                    if(newValue != null) {
                        Object[] mulSelectOrgIds = new Object[1];
                        mulSelectOrgIds[0] = ConvertUtil.toDynamicObjectOrNull(newValue).getLong(FormConstant.ID_KEY);
                        this.getModel().setValue("joblevelscm", mulSelectOrgIds);
                    }else{
                        this.getModel().setValue("joblevelscm", null);
                    }

                }
            }
        }
    }
}