package nckd.jxccl.opmc.pm.plugin.form;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.events.PackageDataEvent;
import kd.bos.form.CloseCallBack;
import kd.bos.form.FormShowParameter;
import kd.bos.form.ShowType;
import kd.bos.form.events.BeforeCreateListColumnsArgs;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.events.ClosedCallBackEvent;
import kd.bos.form.operate.FormOperate;
import kd.bos.list.ListColumn;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * @ClassName: ExaminProjectResultListPlugin
 * @Description: 绩效结果列表插件
 * @Author: PJJ
 * @Date: 2026/1/7 上午9:41
 * @Version: 1.0
 */
public class ExaminProjectResultListPlugin extends AbstractListPlugin {
    @Override
    public void beforeDoOperation(BeforeDoOperationEventArgs args) {
            super.beforeDoOperation(args);
        FormOperate source = (FormOperate) args.getSource();
        String operateKey = source.getOperateKey();
        if (StringUtils.equals(operateKey, "import")) {
            //打开自定义导入模板选择界面
            FormShowParameter fsp = new FormShowParameter();
            fsp.setFormId("nckd_kpi_import_select");
            fsp.setShowTitle(false);
            fsp.getOpenStyle().setShowType(ShowType.Modal);
            fsp.setCustomParam("importplan", this.getView().getFormShowParameter().getCustomParam("importplan"));
            fsp.setCustomParam("template", this.getView().getFormShowParameter().getCustomParam("template"));
            fsp.setCloseCallBack(new CloseCallBack(this, "importData"));
            this.getView().showForm(fsp);
        }
    }

    @Override
    public void closedCallBack(ClosedCallBackEvent e) {
        super.closedCallBack(e);
        String actionId = e.getActionId();
        if( StringUtils.equals(actionId, "importData") ){
            Object returnData = e.getReturnData();
            if( ObjectUtils.isNotEmpty(returnData) ){
                this.getView().invokeOperation("refresh");
            }
        }
    }

    @Override
    public void beforeCreateListColumns(BeforeCreateListColumnsArgs args) {
        super.beforeCreateListColumns(args);
        //添加动态列
        FormShowParameter formShowParameter = this.getView().getFormShowParameter();
        Object customParam = formShowParameter.getCustomParam("");
        DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("", "", new QFilter[]{new QFilter("", QCP.equals, customParam)});
        DynamicObjectCollection dynamicObjectCollection = dynamicObject.getDynamicObjectCollection("");
        for (DynamicObject object : dynamicObjectCollection) {
//            DynamicObject dynamicObject1 = object.getDynamicObject("");
//            dynamicObject1.getString("");
//            ListColumn listColumn = new ListColumn();
//            listColumn.setListFieldKey("nckd_kpi_select");
//            listColumn.set
        }
    }

    @Override
    public void packageData(PackageDataEvent e) {
        super.packageData(e);
        //组装动态列数据
    }
}
