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

import kd.bos.common.enums.EnableEnum;
import kd.bos.form.CloseCallBack;
import kd.bos.form.FormShowParameter;
import kd.bos.form.ShowType;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.ClosedCallBackEvent;
import kd.bos.form.events.SetFilterEvent;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.sdk.plugin.Plugin;
import nckd.jxccl.base.common.constant.FormConstant;
import nckd.jxccl.base.common.enums.psms.TypeStateEnum;
import nckd.jxccl.hr.psms.common.PositionStructureConstant;
import org.apache.commons.lang3.StringUtils;

/**
* 管理人员任命
* 实体标识：nckd_mgrappointmgmt
* @author W.Y.C
* @date 2025/12/4 18:23
* @version 1.0
*/
public class MgrAppointMgmtListPlugin extends AbstractListPlugin implements Plugin {

    @Override
    public void setFilter(SetFilterEvent e) {
        //只查询类型状态
        QFilter filter = new QFilter(PositionStructureConstant.NCKD_TYPESTATE, QCP.equals, TypeStateEnum.MANAGEMENT_SEQUENCE_EMPLOYMENT.getCode());
        e.addCustomQFilter(filter);
    }

    @Override
    public void afterDoOperation(AfterDoOperationEventArgs e) {
        String operateKey = e.getOperateKey();
        if(e.getOperationResult() != null && e.getOperationResult().isSuccess()){
            if("newappointment".equalsIgnoreCase(operateKey)) {
                FormShowParameter showParameter = new FormShowParameter();
                showParameter.setFormId(PositionStructureConstant.NEWAPPTPOPUP_ENTITYID);
                showParameter.getOpenStyle().setShowType(ShowType.Modal);
                showParameter.setCaption("新建任命");
                showParameter.setCloseCallBack(new CloseCallBack(this, PositionStructureConstant.NEWAPPTPOPUP_ENTITYID));
                this.getView().showForm(showParameter);
            }
            this.getView().invokeOperation(FormConstant.REFRESH_OP);
        }
    }

    @Override
    public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
        String actionId = closedCallBackEvent.getActionId();
        if(PositionStructureConstant.NEWAPPTPOPUP_ENTITYID.equalsIgnoreCase(actionId)){
            Object returnData = closedCallBackEvent.getReturnData();
            if(returnData != null) {
                //刷新列表
                this.getView().invokeOperation(FormConstant.REFRESH_OP);
            }
        }
    }
}