package com.steering.pss.judge.DAL;

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

/**
 * 数据库表PLN_STEELFORFURNACE所对应的Java类（生成工具：代码生成工具4.0   访问地址：http://172.16.2.128/tool/）
 * @author tgcx-test   date 2016-08-31
 */
public class PlnSteelforfurnaceDAL extends DBCommon{

 /**
     * 通用查询
     */
    public CoreReturnObject Query(String realBeginTime, String realEndTime, String judgeState, 
    		String stoveNo, String proPlanId, String queryType){
    	SqlBuilder b;
    	if(queryType.equals("Cic"))
    		b = new SqlBuilder("PlnSteelforfurnaceDAL.QueryCic");
    	else{
    		b = new SqlBuilder("PlnSteelforfurnaceDAL.QueryPic");
    	}
    	//b.AppendLn("AND REAL_BEGIN_TIME >= TO_DATE({0}, 'YYYY-MM-DD HH24:MI:SS')", !realBeginTime.equals(""));
    	//b.AppendLn("AND REAL_BEGIN_TIME <= TO_DATE({1}, 'YYYY-MM-DD HH24:MI:SS')", !realEndTime.equals(""));
    	b.AppendLn("AND T.CHEM_JUDGE_ID IS NULL", judgeState.equals("0"));
    	b.AppendLn("AND T.CHEM_JUDGE_ID IS NOT NULL", judgeState.equals("1"));
    	b.AppendLn("AND UPPER(T.STOVE_NO) LIKE '%' || UPPER({2}) || '%'", !stoveNo.equals(""));
    	b.AppendLn("AND UPPER(T.PRO_PLAN_ID) LIKE '%' || UPPER({3}) || '%'", !proPlanId.equals(""));
    	b.Fill(new String[]{realBeginTime, realEndTime, stoveNo, proPlanId});

    	return this.getData(b.toString());
    }
    
    /**
     * 通用查询
     */
    public CoreReturnObject QueryStoveNo(String realBeginTime, String realEndTime, String judgeState, 
    		String stoveNo, String proPlanId, String queryType){
    	SqlBuilder b = new SqlBuilder("PlnSteelforfurnaceDAL.QueryStoveNo");
//    	b.AppendLn("AND REAL_BEGIN_TIME >= TO_DATE({0}, 'YYYY-MM-DD HH24:MI:SS')", !realBeginTime.equals(""));
//    	b.AppendLn("AND REAL_BEGIN_TIME <= TO_DATE({1}, 'YYYY-MM-DD HH24:MI:SS')", !realEndTime.equals(""));
    	b.AppendLn("AND T.CHEM_JUDGE_ID IS NULL", judgeState.equals("0"));
    	b.AppendLn("AND T.CHEM_JUDGE_ID IS NOT NULL", judgeState.equals("1"));
    	b.AppendLn("AND UPPER(T.STOVE_NO) LIKE '%' || UPPER({2}) || '%'", !stoveNo.equals(""));
    	b.AppendLn("AND UPPER(T.PRO_PLAN_ID) LIKE '%' || UPPER({3}) || '%'", !proPlanId.equals(""));
    	b.Fill(new String[]{realBeginTime, realEndTime, stoveNo, proPlanId});

    	return this.getData(b.toString());
    }

    /**
     * 通过主键查询
     */
    public CoreReturnObject QueryByPk(String furnaceno){
        String sqlQuery = CoreXmlSqlParsersFactory.getSql("PlnSteelforfurnaceDAL.QueryByPk");
        return this.getData(sqlQuery);
    }
    
    /**
     * 查询熔炼炉号
     * @return
     */
    public CoreReturnObject QueryMeltingStoveNo(String[] states, String stoveNo, String plineCode){
    	SqlBuilder b = new SqlBuilder("PlnSteelforfurnaceDAL.QueryMeltingStoveNo");
    	b.AppendLn("AND T.STOVE_NO LIKE '%' || {0} || '%'", !stoveNo.equals(""));
    	b.AppendLn(" AND T.EF_PLINE_CODE = {1} ", !plineCode.equals(""));
    	String strStates = "''";
    	for(String state : states){
    		strStates += strStates + ",'" + state + "'";
    	}
    	b.AppendLn("AND T.STATUS IN ("+ strStates +")", states.length > 0);
    	b.Fill(new String[]{ stoveNo, plineCode });
    	
    	return this.getData(b.toString());
    }
}
