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;
import java.util.Set;

/**
 * @author xwudd
 * @date 16:26
 * @Description
 **/
public class PlanJobCMMP {
    public final static String planPin = "plan_pin";//整机编号
    public final static String stockBatch = "stock_batch";//发动机号
    public final static String specification = "specification";//发动机型号
    public final static String supCode = "sup_code";//发动机供应商编码
    public final static String supName = "sup_name";//发动机供应商名称
    public final static String productCode = "product_code";//资源号
    public final static String planCode = "plan_code";//计划编码
    public final static String instructionCode = "instruction_code";//指令编码
    public final static String instructionName = "instruction_name";//指令名称
    public final static String jobTime = "job_time";//指令时间
    public final static String jobUser = "job_user";//指令执行人

    public static List<Map> planJob(Map<String,Object> map,Long id){
        String sql = "select plan_pin,stock_batch,specification,sup_code,sup_name,product_code,plan_code,instruction_code,instruction_name,job_time,job_user from VIEW_PLAN_JOB_WM ";
        long orgId = RequestContext.get().getOrgId();
        Set<String> plans = (Set<String>)map.get(planPin);//整机编号
        Set<String> products = (Set<String>)map.get(productCode);//资源号
        if(YEM.isEmpty(products) || YEM.isEmpty(plans)){
            return new ArrayList<>();
        }
        StringBuffer where = new StringBuffer(String.format("where %s in %s and %s in %s",planPin,"('" + String.join("','", plans) + "')",productCode,"('" + String.join("','",products) + "')"));
        sql = sql + where.toString();
        List<Map> fromCmmp = RequestCmmp.getFromCmmp(orgId, sql,id);
        return fromCmmp;
    }
}
