package nckd.jimin.jyyy.hr.tsrsc.plugin.form;

import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.servicehelper.user.UserServiceHelper;
import kd.hrmp.hrpi.business.domian.service.impl.PersonServiceImpl;
import kd.sdk.plugin.Plugin;

import java.util.EventObject;
import java.util.Map;

/**
 * 通用复制当前人员插件
 * 默认人员标识- nckd_curperson
 * @author ：Tyx
 * @since ：2025-06-30
 */
public class CommonSetCurrentPersonPlugin extends AbstractFormPlugin implements Plugin {

    @Override
    public void afterCreateNewData(EventObject e) {
        super.afterCreateNewData(e);
        Long userId = UserServiceHelper.getCurrentUserId();
        Map<String, Object> map = PersonServiceImpl.getInstance().getPersonModelIdByUserId(userId);
        if(Boolean.valueOf(map.get("success").toString())) {
            IDataModel model = this.getModel();
            Long personId = Long.valueOf(((Map) map.get("data")).get("person").toString());
            model.setValue("nckd_curperson", personId);
        }
    }
}