package com.steering.mes.mcp.Report;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;

import java.util.ArrayList;

/**
 *rcl查询
 * @author siy 2015/05/28
 * @version v1.0
 */
public class FrmRCLPerformance extends DBCommon {

    /**
     * 查询DBK实绩查询
     * @param list
     * @return
     */
    public CoreReturnObject doQuery(ArrayList<String> list, String[]  plinCodes,String stationCode) {

        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmRCLPerformance.doQuery");
        if (!list.get(0).equals("")) {
            sql += " AND T1.LOAD_TIME BETWEEN TO_DATE('" + list.get(0)
                    + "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + list.get(1)
                    + "' ,'YYYY-MM-DD HH24:MI:SS') ";
        }
        if (!list.get(2).equals("")) {
            sql += " AND M.JUDGE_STOVE_NO LIKE'%'||'" + list.get(2) + "'||'%'";
        }
        if (!list.get(3).equals("")) {
            sql += " AND M.ZY_BATCH_ID LIKE'%'||'" + list.get(3) + "'||'%'";
        }
        if (!list.get(4).equals("")) {
            sql += " AND  M.ORDER_NO || '/' || M.ORDER_SEQ  LIKE'%'||'" + list.get(4) + "'||'%'";
        }
/*
        if (!plineCode.equals("")) {
            sql += " AND M.PLINE_CODE='" + plineCode + "'";
        }
*/

        sql += CoreConverter.toSqlConditionString("M.PLINE_CODE", plinCodes);

        if(!stationCode.equals("")){
        	sql += " AND T.STATION_CODE='" + stationCode +"'";
        }
        sql += " GROUP BY M.PLINE_CODE,M.HEAT_PLAN_NO, M.PLINE_NAME, C.PLAN_INDOUBLE_NUM,C.PLAN_INDOUBLE_WT,M.ZY_BATCH_ID, M.PRO_PLAN_ID,  M.GX_PLAN_NO, "
                + "M.CRAFT_FILE_NO, M.CRAFT_FILE_MAN, M.CRAFT_SEQ, M.JUDGE_STOVE_NO,  C.BATCH_NO, "
                + "C.BATCH_GROUD_NO, M.GRADENAME, M1.STEELNAME,M.ORDER_NO, M.ORDER_SEQ,"
                + " M.DELIVERY_NO, M.OUTWL_DESC,  M1.SPEC_NAME, M1.STD_NAME,"
                + " M1.PRODUCNAME, M1.MODEL_DESC";
        return this.getData(sql);
    }

    /**
     * 查询进程数据统计
     * @param list
     * @return
     */
    public CoreReturnObject doQueryPort(ArrayList<String> list, String[] plinCodes,String stationCode) {

        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmRCLPerformance.doQueryPort");
        if (!list.get(0).equals("")) {
            sql += " AND M.LOADTIME BETWEEN TO_DATE('" + list.get(0)
                    + "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + list.get(1)
                    + "' ,'YYYY-MM-DD HH24:MI:SS') ";
        }
        if (!list.get(2).equals("")) {
            sql += " AND M.JUDGE_STOVE_NO LIKE'%'||'" + list.get(2) + "'||'%'";
        }
        if (!list.get(3).equals("")) {
            sql += " AND M.ZY_BATCH_ID LIKE " + list.get(3) + "'||'%'";
        }
        if (!list.get(4).equals("")) {
            sql += " AND M.ORDER_NO || '/' || M.ORDER_SEQ || '/' || M.DELIVERY_NO LIKE'%'||'" + list.get(4) + "'||'%'";
        }

        sql += CoreConverter.toSqlConditionString("M.PLINE_CODE", plinCodes);

        if(list.size()>5 && !list.get(5).equals("")){
            if(list.get(5).equals("1")){
                sql += " AND T.FLAG1 >0 AND T.BAL_YEAR_MONTH > '201900'";
            }else  if(list.get(5).equals("2")){
                sql += " AND T.FLAG >0 AND T.BAL_YEAR_MONTH > '201900'";
            } if(list.get(5).equals("3")){
                sql += " AND t.FLAG1<=0 AND T.FLAG<=0 AND  T.FLAG2 >0 AND T.BAL_YEAR_MONTH > '201900'";
            } if(list.get(5).equals("4")){
                sql += " AND T.FLAG3 >0 AND T.BAL_YEAR_MONTH > '201900'";
            }


        }

        sql+= "   ORDER BY  T.PLINE_CODE, M.LOADTIME,T.PROCESS_SEQ";
        return this.getData(sql);
    }
}
