package com.yem.wm.es.Util;

import com.yem.wm.utils.RequestCmmp;
import com.yem.wm.utils.YEM;
import kd.bos.context.RequestContext;

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

/**
 * @author xwudd
 * @date 11:15
 * @Description 根据物料编码获取制造商，供应商结果集（List<Map<String,Object>>
 **/
public class MaterialInfo {

    public final static String materialCode = "mater_code";
    public final static String producerCode = "supplier_code";//制造商编码
    public final static String producerName = "supplier_name";//制造商名称
    public final static String supplierCode = "sup_code";//供应商编码
    public final static String supplierEASId = "supplier_fid";//供应商EAS唯一值

    public static List<Map> materialWarehouse(Map<String,Object> map,Long id){
        String sql = "select mater_code,supplier_code,supplier_name,sup_code from "+ViewInterfaceDocking.MATERIAL_INFO+" ";
        long orgId = RequestContext.get().getOrgId();
        String material = (String)map.get(materialCode);//物料编码
        String producerNumber = (String)map.get(producerCode);//制造商编码
        if(YEM.isEmpty(material)){
            return new ArrayList<>();
        }
        StringBuffer where = new StringBuffer(String.format("where %s = '%s'",materialCode,material));
        if(YEM.isNotEmpty(producerNumber)){
            where.append(String.format(" and %s = '%s'",producerCode,producerNumber));
        }
        sql = sql + where.toString();
        List<Map> fromCmmp = RequestCmmp.getFromCmmp(orgId, sql,id);
        return fromCmmp;
    }
}
