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;

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

    /**
     * 查询主表
     */
    public CoreReturnObject QueryP(String applyTimeBegin, String applyTimeEnd, String proOrderNo, String stoveNo, String isJudge){
        SqlBuilder b = new SqlBuilder("QcmGpJugdeApplyDAL.QueryP");
        b.AppendLn("AND APPLY_TIME BETWEEN TO_DATE({0}, 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE({1}, 'YYYY-MM-DD HH24:MI:SS')",
        		!applyTimeBegin.equals(""));
        b.AppendLn("AND PRO_ORDER_NO LIKE '%'|| {2} ||'%'", !proOrderNo.equals(""));
        b.AppendLn("AND STOVE_NO LIKE '%'|| {3} ||'%'", !stoveNo.equals(""));
        b.AppendLn("AND CHEM_RESULT_CODE IS NOT NULL", isJudge.equals("1"));
        b.AppendLn("AND CHEM_RESULT_CODE IS NULL", isJudge.equals("0"));
        b.AppendLn("GROUP BY T.JUGDE_APPLY_CODE, T.JUDGE_STOVE_NO, T.STOVE_NO, T.ACT_COUNT,T.GRADECODE, T.GRADENAME,");
        b.AppendLn("T.ACT_DIMATER, T.LEN_GP_SINGLE, T.CHEM_RESULT_CODE, A.BASENAME, T.PHY_RESULT_CODE, T.JUDGE_RESULT,");
        b.AppendLn("T.JUDGE_RESULT_CODE, B.BASENAME, T.PRO_ORDER_ID, T.PRO_ORDER_NO, T.PLINE_CODE, T.PLINE_NAME");
        b.Fill(new String[]{applyTimeBegin, applyTimeEnd, proOrderNo, stoveNo, isJudge});
        return this.getData(b.toString());
    }
    
    /**
     * 查询主表
     */
    public CoreReturnObject QueryP(String stoveNo){
        SqlBuilder b = new SqlBuilder("QcmGpJugdeApplyDAL.QueryP");
        b.AppendLn("AND STOVE_NO = {0}");
        b.AppendLn("GROUP BY T.JUGDE_APPLY_CODE, T.JUDGE_STOVE_NO, T.STOVE_NO, T.ACT_COUNT,T.GRADECODE, T.GRADENAME,");
        b.AppendLn("T.ACT_DIMATER, T.LEN_GP_SINGLE, T.CHEM_RESULT_CODE, A.BASENAME, T.PHY_RESULT_CODE, T.JUDGE_RESULT,");
        b.AppendLn("T.JUDGE_RESULT_CODE, B.BASENAME, T.PRO_ORDER_ID, T.PRO_ORDER_NO, T.PLINE_CODE, T.FACE_RESULT_CODE, ");
        b.Fill(new String[]{stoveNo});
        return this.getData(b.toString());
    }
    
    public CoreReturnObject QueryC(String judgeApplyCode){
    	SqlBuilder b = new SqlBuilder("QcmGpJugdeApplyDAL.QueryC");
        b.AppendLn("AND JUGDE_APPLY_CODE = {0}", !judgeApplyCode.equals(""));
        b.Fill(new String[]{judgeApplyCode});
        return this.getData(b.toString());
    }
    
    /**
     * 查询主表
     */
    public CoreReturnObject QuerySteelMakingP(String applyTimeBegin, String applyTimeEnd,
    		String proOrderNo, String stoveNo, String isJudge, String plineCode){
        SqlBuilder b = new SqlBuilder("QcmGpJugdeApplyDAL.QuerySteelMakingP");
        b.AppendLn("AND APPLY_TIME BETWEEN TO_DATE({0}, 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE({1}, 'YYYY-MM-DD HH24:MI:SS')",
        		!applyTimeBegin.equals(""));
        b.AppendLn("AND PRO_ORDER_NO LIKE '%'|| {2} ||'%'", !proOrderNo.equals(""));
        b.AppendLn("AND STOVE_NO LIKE '%'|| {3} ||'%'", !stoveNo.equals(""));
        b.AppendLn("AND CHEM_RESULT_CODE IS NOT NULL", isJudge.equals("1"));
        b.AppendLn("AND CHEM_RESULT_CODE IS NULL", isJudge.equals("0"));
        b.AppendLn("AND CHEM_RESULT_CODE IS NULL", isJudge.equals("0"));
        b.AppendLn("AND T.PLINE_CODE = {4}", !plineCode.equals(""));
//        b.AppendLn("GROUP BY T.JUGDE_APPLY_CODE, T.JUDGE_STOVE_NO, T.STOVE_NO, T.ACT_COUNT,T.GRADECODE, T.GRADENAME,");
//        b.AppendLn("T.ACT_DIMATER, T.LEN_GP_SINGLE, T.CHEM_RESULT_CODE, A.BASENAME, T.PHY_RESULT_CODE, T.JUDGE_RESULT,");
//        b.AppendLn("T.JUDGE_RESULT_CODE, B.BASENAME, T.PRO_ORDER_NO, T.PLINE_CODE, T.PLINE_NAME,");
//        b.AppendLn("T.FACE_RESULT_CODE, T.PRO_PLAN_ID, T.GX_PLAN_NO");
        b.Fill(new String[]{applyTimeBegin, applyTimeEnd, proOrderNo, stoveNo, plineCode});
        return this.getData(b.toString());
    }

    /**
     * 通过主键查询
     */
    public CoreReturnObject QueryByPk(String jugdeApplyCode, String jugdeApplySqe){
        String sqlQuery = CoreXmlSqlParsersFactory.getSql("QcmGpJugdeApplyDAL.QueryByPk");
        return this.getData(sqlQuery);
    }
    
    /**
     * 查询工艺评审信息
     * @param proPlanId
     * @return
     */
    public CoreReturnObject QueryCraftInfo(String proPlanId){
    	SqlBuilder b = new SqlBuilder("QcmGpJugdeApplyDAL.queryCraftDesignKey");
    	b.Fill(new String[]{ proPlanId });
    	
    	return this.getData(b.toString());
    }
    
    /**
     * 查询表面检验文件
     * @param judgeApplyCode
     * @param judgeApplySeq
     * @param multipleNum
     * @param judgeStoveNo
     * @return
     */
    public CoreReturnObject queryFaceFile(String judgeApplyCode, String judgeApplySeq,
    		String multipleNum, String judgeStoveNo){
    	SqlBuilder b = new SqlBuilder("QcmGpJugdeApplyDAL.queryFaceFile");
    	b.Fill(new String[]{ judgeApplyCode, judgeApplySeq, multipleNum, judgeStoveNo });
    	
    	return this.getData(b.toString());
    }
}
