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

import com.google.common.collect.Lists;
import kd.bos.dataentity.OperateOption;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.hr.hbp.formplugin.web.HRDataBaseList;
import kd.hr.impt.common.dto.ImportBillData;
import kd.hr.impt.common.plugin.BeforeCallOperationEventArgs;
import kd.hr.impt.common.plugin.BeforeShowTemplateSelectListEventArgs;
import kd.hr.impt.common.plugin.HRImportPlugin;
import nckd.jxccl.base.common.constant.FormConstant;
import nckd.jxccl.base.common.enums.psms.TypeStateEnum;
import nckd.jxccl.hr.psms.common.PositionStructureConstant;

import java.util.List;
import java.util.Map;

/**
* 管理人员任命导入插件
* @author W.Y.C
* @date 2025/12/4 22:10
* @version 1.0
*/
public class MgrAppointMgmtImportPlugin extends HRDataBaseList implements HRImportPlugin {

    private static String MGRAPPOINTMGMT_IMPT = "mgrappointmgmt_IMPT";

    @Override
    public void beforeShowTemplateSelectList(BeforeShowTemplateSelectListEventArgs args) {
        List<QFilter> fileter = args.getqFilterList();
        if(fileter == null){
            fileter = Lists.newArrayList();
        }
        fileter.add(new QFilter(FormConstant.NUMBER_KEY, QCP.in, new String[]{MGRAPPOINTMGMT_IMPT}));
        args.setqFilterList(fileter);
    }

    @Override
    public void beforeCallOperation(BeforeCallOperationEventArgs args) {
        String mainEntityId = ((ImportBillData)args.getImportBillDatas().get(0)).getMainEntityId();
        OperateOption operateOption = (OperateOption)args.getOperateOptions().get(mainEntityId);
        operateOption.setVariableValue(PositionStructureConstant.NCKD_TYPESTATE, TypeStateEnum.MANAGEMENT_SEQUENCE_EMPLOYMENT.getCode());
        Map<String, String> submitOPs = args.getSubmitOPs();
        String targetKey = PositionStructureConstant.NCKD_PERSONPOSFILE.toLowerCase();
        //删除默认save方法
        submitOPs.entrySet().removeIf(entry -> entry.getKey().toLowerCase().equals(targetKey));
        submitOPs.put(PositionStructureConstant.NCKD_PERSONPOSFILE.toLowerCase(),"savenewappointment");
    }
}
