package nckd.jimin.jyyy.fi.plugin.form;

import kd.bos.bill.BillOperationStatus;
import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.ext.fi.plugin.ArApConvert.util.EmptyUtils;
import kd.bos.form.ShowType;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import java.util.EventObject;

/**
 * 列表插件，处理srm单点星瀚单据，由于直接单点的编辑界面会提示参数异常问题，通过单点到列表页面再打开编辑界面
 * @author wanghaiwu_kd
 * @date 2025/06/26
 */
public class PayBillSSOListPlugin extends AbstractListPlugin {
    @Override
    public void beforeBindData(EventObject e) {
        super.beforeBindData(e);

        String jypkId = this.getView().getFormShowParameter().getCustomParam("pkId");
        if(jypkId != null){
            Long billId = Long.valueOf(jypkId);
            String identifyFormId = (String)this.getView().getFormShowParameter().getIdentifyFormId();
            if(identifyFormId != null){
                //实体标识
                String entityName = identifyFormId.split("-")[1];
                //页面标识
                String formId = identifyFormId.split("-")[1];

                //跳转到指定PC布局
                BillShowParameter showParameter = new BillShowParameter();
                QFilter qf = new QFilter("id", QCP.equals, billId);
                //跳转到指定PC布局
                DynamicObject billDyn = BusinessDataServiceHelper.loadSingle(entityName, "nckd_pageid", new QFilter[]{qf});
                if(billDyn!=null){
                    if(EmptyUtils.isNotEmpty(billDyn.getString("nckd_pageid"))){
                        formId = billDyn.getString("nckd_pageid");
                    }

                }
                showParameter.setFormId(formId);
                showParameter.setPkId(billId);
                showParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage);

                showParameter.setStatus(OperationStatus.EDIT);
                showParameter.setBillStatus(BillOperationStatus.EDIT);

                this.getView().showForm(showParameter);
            }
        }
    }
}
