package com.yem.wm.es.storagetrans.list;

import kd.bos.dataentity.entity.DynamicObject;
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.bos.servicehelper.BusinessDataServiceHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 订舱通知单——信保回填列表过滤，只显示信保合同
 * @Date 2024/3/4 15:46
 * @Created by ZZSLL
 */

public class StorageTransXBSListFilter extends AbstractListPlugin
{
    @Override
    public void setFilter(SetFilterEvent e)
    {
        super.setFilter(e);
        DynamicObject[] saleOrder = BusinessDataServiceHelper.load("yem_es_salesorder", "billno", new QFilter("yem_issinosurecon", QCP.equals, true).toArray());
        List<String> saleOrderNo = new ArrayList<>();
        for (DynamicObject dynamicObject : saleOrder) {
            saleOrderNo.add(dynamicObject.getString("billno"));
        }
        QFilter qFilter = new QFilter("yem_es_storagetrans.yem_es_materialinfo.yem_contractnumbers_m", QCP.in, saleOrderNo);
        DynamicObject[] load = BusinessDataServiceHelper.load("yem_es_storagetrans", "id", qFilter.toArray());
        List<Long> ids = new ArrayList<>();
        for (DynamicObject dynamicObject : load) {
            ids.add(dynamicObject.getLong("id"));
        }
        e.addCustomQFilter(new QFilter("id", QFilter.in, ids.toArray()));
    }
}
