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:07
 * @Description 根据物料编码获取物料属性结果集（List<Map<String,Object>>
 **/
public class MaterialProperty {
    public final static String materialcode = "mater_code";
    public final static String materialProperty = "property";

    public static List<Map> materialWarehouse(Map<String,Object> map,Long id){
        String sql = "select mater_code,property from VIEW_MATER_PRO_WM ";
        long orgId = RequestContext.get().getOrgId();
        String material = (String)map.get(materialcode);//物料编码
        String property = (String)map.get(materialProperty);//物料属性
        if(YEM.isEmpty(material)){
            return new ArrayList<>();
        }
        StringBuffer where = new StringBuffer(String.format("where %s = '%s' ",materialcode,material));
        if(YEM.isNotEmpty(property)){
            where.append(String.format("and %s = '%s'",materialProperty,property));
        }
        sql = sql + where.toString();
        List<Map> fromCmmp = RequestCmmp.getFromCmmp(orgId, sql,id);
        return fromCmmp;
    }
}
