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 10:22
 * @Description 根据物料编码获取仓库库区结果集（List<Map<String,Object>>）
 **/
public class MaterialWarehouse {

    public final static String materialCode = "mater_code";
    public final static String warehouseCode = "wh_code";
    public final static String warehouseAreaCode = "area_code";

    public static List<Map> materialWarehouse(Map<String,Object> map,Long id){
//        String sql = "select mater_code,wh_code,area_code,position_code from VIEW_WH_MATER_WM ";//测试
        String sql = "select mater_code,wh_code,area_code,position_code,stocker_code from "+ViewInterfaceDocking.MATERIAL_WAREHOUSE+" ";//正式
        long orgId = RequestContext.get().getOrgId();
        String material = (String)map.get(materialCode);//物料编码
        String warehouse = (String)map.get(warehouseCode);//仓库编码
        String warehouseArea = (String)map.get(warehouseAreaCode);//库区
        if(YEM.isEmpty(material)){
            return new ArrayList<>();
        }
        StringBuffer where = new StringBuffer(String.format("where %s = '%s'",materialCode,material));
        if(YEM.isNotEmpty(warehouse)){
            where.append(String.format(" and %s = '%s'",warehouseCode,warehouse));
        }
        if(YEM.isNotEmpty(warehouseArea)){
            where.append(String.format(" and %s = '%s'",warehouseAreaCode,warehouseArea));
        }
        sql = sql + where;
        List<Map> fromCmmp = RequestCmmp.getFromCmmp(orgId, sql,id);
        return fromCmmp;
    }
}
