/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-05-08
 * 描述            ：物料属性配置表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Mes.Report.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import market.Com.mapper.PbModelDbMapper;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Mes.Report.mapper.ReportQmsUnplannedMapper;
import market.Mes.Report.service.ReportQmsUnplannedService;
import market.Mes.Report.vo.ReportQmsUnplanned;

import org.apache.commons.lang.StringUtils;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;

@SuppressWarnings("rawtypes")
@RemoteService(path="ReportQmsUnplannedService")
public class ReportQmsUnplannedServiceImpl extends BaseServiceImpl<ReportQmsUnplanned,Object> implements ReportQmsUnplannedService {

	/**
	 * 查询原料 和产量 和 非计划量
	 * 参数：[{"memo1":"M0001","startTime":"2020-03-07","endTime":"2020-03-09"}]
	 * @param oci
	 * @return
	 * @throws Exception 
	 */	
	public ResultModel doQueryMaterial(CommonPage<Object> cp) throws Exception{
		ResultModel rm = new ResultModel();
		String machine = cp.getMemo1();//机台信息
		String startTime = cp.getStartTime();//开始时间
		String endTime = cp.getEndTime();//结束时间
		
		List<HashMap> hmList = new ArrayList<HashMap>();
		if (machine == null) {
			throw new Exception("机组信息不能为空");
		}
		if ("M0001".equals(machine) || "M0002".equals(machine)) {
			//4mm 和12MM
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_4mm(machine,startTime,endTime);
		}else if ("M0003".equals(machine)) {
			//3mm
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_3mm(machine,startTime,endTime); 
		}else if ("M000T".equals(machine)) {
			//退火炉
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_th(machine,startTime,endTime); 
		}else if ("M0007".equals(machine)) {
			//平整
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_pz(machine,startTime,endTime); 
		}else if ("M0008".equals(machine)) {
			//轧机
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_zj(machine,startTime,endTime); 
		}else if ("M0010".equals(machine)) {
			//酸洗
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_sx(machine,startTime,endTime); 
		}
		rm.setState("200");
		rm.setData(hmList);
		return rm;
	}
	
	/**
	 * 查询原料 和产量 和 非计划量 合计
	 * 参数：[{"memo1":"M0001","startTime":"2020-03-07","endTime":"2020-03-09"}]
	 * @param oci
	 * @return
	 * @throws Exception 
	 */	
	public ResultModel doQueryMaterialSum(CommonPage<Object> cp) throws Exception{
		ResultModel rm = new ResultModel();
		String machine = cp.getMemo1();//机台信息
		String startTime = cp.getStartTime();//开始时间
		String endTime = cp.getEndTime();//结束时间
		
		List<HashMap> hmList = new ArrayList<HashMap>();
		if (machine == null) {
			throw new Exception("机组信息不能为空");
		}
		if ("M0001".equals(machine) || "M0002".equals(machine)) {
			//4mm 和12MM
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_4mmSum(machine,startTime,endTime);
		}else if ("M0003".equals(machine)) {
			//3mm
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_3mmSum(machine,startTime,endTime); 
		}else if ("M000T".equals(machine)) {
			//退火炉
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_thSum(machine,startTime,endTime); 
		}else if ("M0007".equals(machine)) {
			//平整
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_pzSum(machine,startTime,endTime); 
		}else if ("M0008".equals(machine)) {
			//轧机
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_zjSum(machine,startTime,endTime); 
		}else if ("M0010".equals(machine)) {
			//酸洗
			hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterial_sxSum(machine,startTime,endTime); 
		}
		rm.setState("200");
		rm.setData(hmList);
		return rm;
	}
	
	/**
	 * 非计划报表查询
	 * @param cp
	 * @return
	 * @throws Exception
	 */
	public ResultModel doQueryDetailMaterial(CommonPage<Object> cp) throws Exception{
		ResultModel rm = new ResultModel();
		String machine = cp.getMemo1();//机台信息
		String opr = cp.getMemo2();//
		String wrk_grp = cp.getMemo3();//班组
		String startTime = cp.getStartTime();//开始时间
		String endTime = cp.getEndTime();//结束时间
		List<HashMap> hmList = new ArrayList<HashMap>();
		if (machine == null) {
			throw new Exception("机组信息不能为空");
		}
		
		if ("非计划总量".equals(opr)) {
			if ("M0001".equals(machine) || "M0002".equals(machine)) {
				//4mm 和12MM
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialF_4mm(machine,startTime,endTime,wrk_grp);
			}else if ("M0003".equals(machine)) {
				//3mm
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialF_3mm(machine,startTime,endTime,wrk_grp); 
			}else if ("M000T".equals(machine)) {
				//退火炉
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialF_th(machine,startTime,endTime,wrk_grp); 
			}else if ("M0007".equals(machine)) {
				//平整
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialF_pz(machine,startTime,endTime,wrk_grp); 
			}else if ("M0008".equals(machine)) {
				//轧机
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialF_zj(machine,startTime,endTime,wrk_grp); 
			}else if ("M0010".equals(machine)) {
				//酸洗
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialF_sx(machine,startTime,endTime,wrk_grp); 
			}
		}else if ("外观非计划".equals(opr)||"原料类".equals(opr)||"加工类".equals(opr)) {
			String flaw_type = "";
			if ("原料类".equals(opr)) {
				flaw_type = "408301";
			}else if ("加工类".equals(opr)) {
				flaw_type = "408302";
			}
			
			if ("M0001".equals(machine) || "M0002".equals(machine)) {
				//4mm 和12MM
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialWF_4mm(machine,startTime,endTime,wrk_grp,flaw_type);
			}else if ("M0003".equals(machine)) {
				//3mm
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialWF_3mm(machine,startTime,endTime,wrk_grp,flaw_type); 
			}else if ("M000T".equals(machine)) {
				//退火炉
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialWF_th(machine,startTime,endTime,wrk_grp,flaw_type); 
			}else if ("M0007".equals(machine)) {
				//平整
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialWF_pz(machine,startTime,endTime,wrk_grp,flaw_type); 
			}else if ("M0008".equals(machine)) {
				//轧机
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialWF_zj(machine,startTime,endTime,wrk_grp,flaw_type); 
			}else if ("M0010".equals(machine)) {
				//酸洗
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialWF_sx(machine,startTime,endTime,wrk_grp,flaw_type); 
			}
		}else if ("公差非计划".equals(opr) || "性能非计划".equals(opr)) {
			String gORx = "";
			if ("公差非计划".equals(opr)) {
				gORx = "1";
			}else if ("性能非计划".equals(opr)) {
				gORx = "2";
			}
			
			if ("M0001".equals(machine) || "M0002".equals(machine)) {
				//4mm 和12MM
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialGXF_4mm(machine,startTime,endTime,wrk_grp,gORx);
			}else if ("M0003".equals(machine)) {
				//3mm
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialGXF_3mm(machine,startTime,endTime,wrk_grp,gORx); 
			}else if ("M000T".equals(machine)) {
				//退火炉
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialGXF_th(machine,startTime,endTime,wrk_grp,gORx); 
			}else if ("M0007".equals(machine)) {
				//平整
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialGXF_pz(machine,startTime,endTime,wrk_grp,gORx); 
			}else if ("M0008".equals(machine)) {
				//轧机
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialGXF_zj(machine,startTime,endTime,wrk_grp,gORx); 
			}else if ("M0010".equals(machine)) {
				//酸洗
				hmList = this.getMapper(ReportQmsUnplannedMapper.class).doQueryMaterialGXF_sx(machine,startTime,endTime,wrk_grp,gORx); 
			}
		}						
		rm.setState("200");
		rm.setData(hmList);
		return rm;
	}
	
	/**
	 * 产量品种结构报表：按钢种划分
	 * @param cp
	 * @return
	 * @throws Exception
	 */
	public ResultModel doQueryMachineWeightBySteelType(CommonPage<Object> cp) throws Exception{
		ResultModel rm = new ResultModel();
		String startTime = cp.getStartTime();	//开始时间
		String endTime = cp.getEndTime();		//结束时间
		String wrk_grp = cp.getMemo1();			//班组
		String machine = cp.getMemo2();     	//机组[酸洗、轧机、平整、退火、小纵剪、大纵剪、横剪]
		if (StringUtils.isEmpty(machine)) {
			rm.setErrorInfo("请选择机组");
			rm.setState("500");
			return rm;
		}
		
		List<HashMap> hmList = null;
		String sql = "";
		if ("酸洗".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";			
			sql = "select '酸洗' machine,cbs.steel_type,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_plm_d d"
					+ " left join mes_plm_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type"
					+ " order by cbs.steel_type";
		}else if ("轧机".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select '轧机' machine,cbs.steel_type,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_rcm_d d"
					+ " left join mes_rcm_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type"
					+ " order by cbs.steel_type";
		}else if ("平整".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select '平整' machine,cbs.steel_type,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_tpm_d d"
					+ " left join mes_tpm_m m on d.schedule_no = m.schedule_no and d.material_no = m.material_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type"
					+ " order by cbs.steel_type";			
		}else if ("退火".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(m.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.discharge_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.discharge_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.discharge_date <= '"+endTime+"'";
			sql = "select '退火' machine,cbs.steel_type,sum(m.coil_act_wgt)/1000 weight"
					+ " from mes_cr_anneal_m m"
					+ " left join com_base_steel cbs on m.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on m.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type"
					+ " order by cbs.steel_type";
		}else if ("小纵剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H') and m.machine_code = 'M0001'";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select '小纵剪' machine,cbs.steel_type,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_cr_slitting_d d"
					+ " left join mes_cr_slitting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type"
					+ " order by cbs.steel_type";
		}else if ("大纵剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H') and m.machine_code = 'M0002'";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select '大纵剪' machine,cbs.steel_type,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_cr_slitting_d d"
					+ " left join mes_cr_slitting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type"
					+ " order by cbs.steel_type";
		}else if ("横剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.packing_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select '横剪' machine,cbs.steel_type,sum(d.packing_net_wgt)/1000 weight"
					+ " from mes_cr_cross_cutting_d d"
					+ " left join mes_cr_cross_cutting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type"
					+ " order by cbs.steel_type";
		}
		hmList = this.getMapper(PbModelDbMapper.class).doQueryHashMap(sql);	
		rm.setData(hmList);
		rm.setState("200");
		return rm;
	}
	
	/**
	 * 产量品种结构报表：按牌号划分
	 * @param cp
	 * @return
	 * @throws Exception
	 */
	public ResultModel doQueryMachineWeightBySteelName(CommonPage<Object> cp) throws Exception{
		ResultModel rm = new ResultModel();
		String startTime = cp.getStartTime();	//开始时间
		String endTime = cp.getEndTime();		//结束时间
		String wrk_grp = cp.getMemo1();			//班组
		String machine = cp.getMemo2();     	//机组[酸洗、轧机、平整、退火、小纵剪、大纵剪、横剪]
		String steelType = cp.getMemo3();		//钢种
		if (StringUtils.isEmpty(machine)) {
			rm.setErrorInfo("请选择机组");
			rm.setState("500");
			return rm;
		}
		
		List<HashMap> hmList = null;
		String sql = "";
		if ("酸洗".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			sql = "select '酸洗' machine,cbs.steel_type,cbs.steel_name,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_plm_d d"
					+ " left join mes_plm_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name"
					+ " order by cbs.steel_type,cbs.steel_name";
		}else if ("轧机".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			sql = "select '轧机' machine,cbs.steel_type,cbs.steel_name,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_rcm_d d"
					+ " left join mes_rcm_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name"
					+ " order by cbs.steel_type,cbs.steel_name";
		}else if ("平整".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			sql = "select '平整' machine,cbs.steel_type,cbs.steel_name,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_tpm_d d"
					+ " left join mes_tpm_m m on d.schedule_no = m.schedule_no and d.material_no = m.material_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name"
					+ " order by cbs.steel_type,cbs.steel_name";			
		}else if ("退火".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(m.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.discharge_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.discharge_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.discharge_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			sql = "select '退火' machine,cbs.steel_type,cbs.steel_name,sum(m.coil_act_wgt)/1000 weight"
					+ " from mes_cr_anneal_m m"
					+ " left join com_base_steel cbs on m.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on m.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name"
					+ " order by cbs.steel_type,cbs.steel_name";
		}else if ("小纵剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H') and m.machine_code = 'M0001'";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			sql = "select '小纵剪' machine,cbs.steel_type,cbs.steel_name,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_cr_slitting_d d"
					+ " left join mes_cr_slitting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name"
					+ " order by cbs.steel_type,cbs.steel_name";
		}else if ("大纵剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H') and m.machine_code = 'M0002'";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			sql = "select '大纵剪' machine,cbs.steel_type,cbs.steel_name,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_cr_slitting_d d"
					+ " left join mes_cr_slitting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name"
					+ " order by cbs.steel_type,cbs.steel_name";
		}else if ("横剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.packing_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			sql = "select '横剪' machine,cbs.steel_type,cbs.steel_name,sum(d.packing_net_wgt)/1000 weight"
					+ " from mes_cr_cross_cutting_d d"
					+ " left join mes_cr_cross_cutting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name"
					+ " order by cbs.steel_type,cbs.steel_name";
		}
		hmList = this.getMapper(PbModelDbMapper.class).doQueryHashMap(sql);	
		rm.setData(hmList);
		rm.setState("200");
		return rm;
	}
	
	/**
	 * 产量品种结构报表：按规格划分
	 * @param cp
	 * @return
	 * @throws Exception
	 */
	public ResultModel doQueryMachineWeightBySpec(CommonPage<Object> cp) throws Exception{
		ResultModel rm = new ResultModel();
		String startTime = cp.getStartTime();	//开始时间
		String endTime = cp.getEndTime();		//结束时间
		String wrk_grp = cp.getMemo1();			//班组
		String machine = cp.getMemo2();     	//机组[酸洗、轧机、平整、退火、小纵剪、大纵剪、横剪]
		String steelType = cp.getMemo3();		//钢种
		String steelName = cp.getMemo4();		//牌号
		if (StringUtils.isEmpty(machine)) {
			rm.setErrorInfo("请选择机组");
			rm.setState("500");
			return rm;
		}
		
		List<HashMap> hmList = null;
		String sql = "";
		if ("酸洗".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			if (StringUtils.isNotEmpty(steelName)) 
				condition += " and cbs.steel_name = '"+steelName+"'";
			sql = "select '酸洗' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_plm_d d"
					+ " left join mes_plm_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width";
		}else if ("轧机".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			if (StringUtils.isNotEmpty(steelName)) 
				condition += " and cbs.steel_name = '"+steelName+"'";
			sql = "select '轧机' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_rcm_d d"
					+ " left join mes_rcm_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width";
		}else if ("平整".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			if (StringUtils.isNotEmpty(steelName)) 
				condition += " and cbs.steel_name = '"+steelName+"'";
			sql = "select '平整' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_tpm_d d"
					+ " left join mes_tpm_m m on d.schedule_no = m.schedule_no and d.material_no = m.material_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width";			
		}else if ("退火".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(m.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.discharge_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.discharge_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.discharge_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			if (StringUtils.isNotEmpty(steelName)) 
				condition += " and cbs.steel_name = '"+steelName+"'";
			sql = "select '退火' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(m.coil_act_wgt)/1000 weight"
					+ " from mes_cr_anneal_m m"
					+ " left join com_base_steel cbs on m.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on m.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width";
		}else if ("小纵剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H') and m.machine_code = 'M0001'";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			if (StringUtils.isNotEmpty(steelName)) 
				condition += " and cbs.steel_name = '"+steelName+"'";
			sql = "select '小纵剪' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_cr_slitting_d d"
					+ " left join mes_cr_slitting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width";
		}else if ("大纵剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H') and m.machine_code = 'M0002'";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			if (StringUtils.isNotEmpty(steelName)) 
				condition += " and cbs.steel_name = '"+steelName+"'";
			sql = "select '大纵剪' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_cr_slitting_d d"
					+ " left join mes_cr_slitting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width";
		}else if ("横剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.packing_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			if (StringUtils.isNotEmpty(steelType)) 
				condition += " and cbs.steel_type = '"+steelType+"'";
			if (StringUtils.isNotEmpty(steelName)) 
				condition += " and cbs.steel_name = '"+steelName+"'";
			sql = "select '横剪' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.packing_net_wgt)/1000 weight"
					+ " from mes_cr_cross_cutting_d d"
					+ " left join mes_cr_cross_cutting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width";
		}
		hmList = this.getMapper(PbModelDbMapper.class).doQueryHashMap(sql);	
		rm.setData(hmList);
		rm.setState("200");
		return rm;
	}
	
	public ResultModel doQueryMachineWeightDetail(CommonPage<Object> cp) throws Exception{
		ResultModel rm = new ResultModel();
		String startTime = cp.getStartTime();	//开始时间
		String endTime = cp.getEndTime();		//结束时间
		String wrk_grp = cp.getMemo1();			//班组
		String machine = cp.getMemo2();     	//机组[酸洗、轧机、平整、退火、小纵剪、大纵剪、横剪]
		if (StringUtils.isEmpty(machine)) {
			rm.setErrorInfo("请选择机组");
			rm.setState("500");
			return rm;
		}
		
		List<HashMap> hmList = null;
		String sql = "";		
		
		if ("酸洗".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select s.*,sum(weight) over(partition by steel_type, steel_name) weight_steel,"
					+ " sum(weight) over(partition by steel_type) weight_type"
					+ " from (select '酸洗' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_plm_d d"
					+ " left join mes_plm_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by m.wrk_date,m.wrk_grp,cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by m.wrk_date,m.wrk_grp,cbs.steel_type,cbs.steel_name,scli.thick,scli.width)s";
		}else if ("轧机".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select s.*,sum(weight) over(partition by steel_type, steel_name) weight_steel,"
					+ " sum(weight) over(partition by steel_type) weight_type"
					+ " from (select '轧机' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_rcm_d d"
					+ " left join mes_rcm_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width)s";
		}else if ("平整".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select s.*,sum(weight) over(partition by steel_type, steel_name) weight_steel,"
					+ " sum(weight) over(partition by steel_type) weight_type"
					+ " from (select '平整' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_tpm_d d"
					+ " left join mes_tpm_m m on d.schedule_no = m.schedule_no and d.material_no = m.material_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width)s";			
		}else if ("退火".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(m.coil_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.discharge_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.discharge_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.discharge_date <= '"+endTime+"'";
			sql = "select s.*,sum(weight) over(partition by steel_type, steel_name) weight_steel,"
					+ " sum(weight) over(partition by steel_type) weight_type"
					+ " from (select '退火' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(m.coil_act_wgt)/1000 weight"
					+ " from mes_cr_anneal_m m"
					+ " left join com_base_steel cbs on m.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on m.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width)s";
		}else if ("小纵剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H') and m.machine_code = 'M0001'";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select s.*,sum(weight) over(partition by steel_type, steel_name) weight_steel,"
					+ " sum(weight) over(partition by steel_type) weight_type"
					+ " from (select '小纵剪' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_cr_slitting_d d"
					+ " left join mes_cr_slitting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width)s";
		}else if ("大纵剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.coil_no,-1,1) not in ('B','H') and m.machine_code = 'M0002'";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select s.*,sum(weight) over(partition by steel_type, steel_name) weight_steel,"
					+ " sum(weight) over(partition by steel_type) weight_type"
					+ " from (select '大纵剪' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.coil_act_wgt)/1000 weight"
					+ " from mes_cr_slitting_d d"
					+ " left join mes_cr_slitting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width)s";
		}else if ("横剪".equals(machine)) {
			String condition = " and m.hand_over_status = '1' and substr(d.packing_no,-1,1) not in ('B','H')";
			if (StringUtils.isNotEmpty(wrk_grp)) 
				condition += " and m.wrk_grp = '"+wrk_grp+"'";
			if (StringUtils.isNotEmpty(startTime)) 
				condition += " and m.wrk_date >= '"+startTime+"'";
			if (StringUtils.isNotEmpty(endTime)) 
				condition += " and m.wrk_date <= '"+endTime+"'";
			sql = "select s.*,sum(weight) over(partition by steel_type, steel_name) weight_steel,"
					+ " sum(weight) over(partition by steel_type) weight_type"
					+ " from (select '横剪' machine,cbs.steel_type,cbs.steel_name,scli.thick,scli.width,to_char(scli.thick,'fm0.000')||'*'||scli.width spec,sum(d.packing_net_wgt)/1000 weight"
					+ " from mes_cr_cross_cutting_d d"
					+ " left join mes_cr_cross_cutting_m m on d.process_no = m.process_no"
					+ " left join com_base_steel cbs on d.steel_code = cbs.steel_code"
					+ " left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1'"
					+ " left join slm_contract_line_info scli on soi.contract_line_no = scli.contract_line_no"
					+ " where 1=1" + condition
					+ " group by cbs.steel_type,cbs.steel_name,scli.thick,scli.width"
					+ " order by cbs.steel_type,cbs.steel_name,scli.thick,scli.width)s";
		}
		hmList = this.getMapper(PbModelDbMapper.class).doQueryHashMap(sql);	
		rm.setData(hmList);
		rm.setState("200");
		return rm;
	}
	
}
