package com.steering.pss.judge.DAL;

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.StringTool;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

public class MatZcMDAL extends DBCommon{
	/**
	 * 查询炉号数据
	 * @param instockTimeBegin
	 * @param instockTimeEnd
	 * @return
	 */
	public CoreReturnObject queryStoveNoTable(String instockTimeBegin, String instockTimeEnd,
			String judgeState, String stoveNo, String proOrdId, Integer judgeType){
		SqlBuilder b = new SqlBuilder("MatZcMDAL.queryStoveNoTable");
		b.AppendLn("AND T.INSTOCK_TIME >= TO_DATE({0}, 'YYYY-MM-DD HH24:MI:SS')", !instockTimeBegin.equals(""));
		b.AppendLn("AND T.INSTOCK_TIME <= TO_DATE({1}, 'YYYY-MM-DD HH24:MI:SS')", !instockTimeBegin.equals(""));
		if(judgeType.toString().endsWith("1")){
			b.AppendLn("AND T.CHEM_RESULT_CODE IS NULL", judgeState.equals("0"));
			b.AppendLn("AND T.CHEM_RESULT_CODE IS NOT NULL", judgeState.equals("1"));
		}else if(judgeType.toString().endsWith("2")){
			b.AppendLn("AND T.PHY_RESULT_CODE IS NULL", judgeState.equals("0"));
			b.AppendLn("AND T.PHY_RESULT_CODE IS NOT NULL", judgeState.equals("1"));
		}
		
		b.AppendLn("AND T.STOVE_NO = {2}", !stoveNo.equals("") && stoveNo.length() == 6);
		b.AppendLn("AND INSTR(T.STOVE_NO, {2}) > 0", !stoveNo.equals("") && stoveNo.length() != 6);
		b.AppendLn("AND T.PRO_ORDER_ID = {3}", !proOrdId.equals("") && proOrdId.length() == 15);
		b.AppendLn("AND T.PRO_ORDER_ID LIKE '%'||{3}||'%'", !proOrdId.equals("") && proOrdId.length() != 15);
		b.AppendLn("GROUP BY STOVE_NO, JUDGE_STOVE_NO, LOT_NO, STEELCODE, STEELNAME, GRADECODE,");
		b.AppendLn("GRADENAME, PRO_ORDER_ID, PRO_ORDER_ID1, PLINE_CODE, PLINE_NAME, JUGDE_APPLY_CODE,");
		b.AppendLn("A.BASENAME, B.BASENAME, JUDGE_STD_NAME, JUDGE_STD_CODE, PLN_STEELCODE, PLN_STEELNAME");
		b.Fill(new String[]{instockTimeBegin, instockTimeEnd, stoveNo, proOrdId});
		
		return this.getData(b.toString());
	}
	
	/**
	 * 查询材料号数据
	 * @param instockTimeBegin
	 * @param instockTimeEnd
	 * @return
	 */
	public CoreReturnObject queryMatNoTable(String judgeStoveNo){
		String sql = CoreXmlSqlParsersFactory.getSql("MatZcMDAL.queryMatNoTable");
		sql = StringTool.ReplaceAll(sql, "#JUDGE_STOVE_NO#", judgeStoveNo);
		return this.getData(sql);
	}
}
