package com.steering.mes.mcp.Report;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

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

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.mes.mcp.entity.CouplingMatButtressEntity;
import com.steering.mes.mcp.entity.CouplingMatMEntity;

/**
 * 库存报表查询
 * 
 * @author siy 2015/05/28
 * @version v1.0
 */
public class FrmJGMatNoReport extends DBCommon {

	/**
	 * 查询接箍库存信息
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doQueryInfoResult(ArrayList<String> list) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.doQueryInfoResult");
		sql += " AND T1.STORAGE_NO LIKE '%' || '" + list.get(0) + "' || '%'";
		// sql += " AND T1.KEP_NO LIKE '%' || '" + list.get(1) + "' || '%'";
		sql += " AND T.judge_stove_no LIKE '%' || '" + list.get(2) + "' || '%'";
		sql += " AND DECODE('" + list.get(3)
				+ "', NULL, '1', T.CREATE_TIME) BETWEEN";
		sql += " DECODE('" + list.get(4) + "', NULL, '1', to_date('"
				+ list.get(5) + "', 'YYYY-MM-DD HH24:MI:SS'))";
		sql += " AND DECODE('" + list.get(6) + "', NULL, '1', to_date('"
				+ list.get(7) + "', 'YYYY-MM-DD HH24:MI:SS'))";
		sql += " AND T.BATCH_NO LIKE '%' || '" + list.get(8) + "' || '%'";
		sql += " AND T.WO_ID LIKE '%' || '" + list.get(9) + "' || '%'";
		sql += " ORDER BY T.CREATE_TIME DESC";
		return this.getData(sql);
	}

	/***
	 * 获取所有接箍框号
	 * 
	 * @param storeNo
	 * @return
	 */
	public CoreReturnObject getKepNo() {
		return this.getDataBySqlID("FrmJGMatNoReport.getKepNo");
		// String sql = CoreXmlSqlParsersFactory
		// .getSql("WarehousePermissions.getKepNo");
		// return this.getData(sql);
	}

	/**
	 * 查询库位框号
	 */
	public CoreReturnObject getQueryLocation(String matNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.getQueryLocation");
		sql += " AND T.MAT_NO = '" + matNo + "'";
		return this.getData(sql);
	}

	/**
	 * 查询合同相关信息
	 */
	public CoreReturnObject getQueryOrder(String woid, String judgeNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.getQueryOrder");
		sql += " AND T.WO_ID = '" + woid + "'";
		sql += " AND T.JUDGE_STOVE_NO = '" + judgeNo + "'";
		return this.getData(sql);
	}

	/***
	 * 查询接箍库存信息
	 */
	public CoreReturnObject getQueryCouplingMat(ArrayList<String> list) {
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.getQueryCouplingMat");
		String sql = "";
		sql += " AND T1.STORAGE_NO LIKE '%' || '" + list.get(0) + "' || '%'";
		sql += " AND T.judge_stove_no LIKE '%' || '" + list.get(2) + "' || '%'";
		if (!list.get(3).equals("1")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ list.get(3)
					+ "','YYYY-MM-DD HH24:MI:SS') AND T.CREATE_TIME <=TO_DATE('"
					+ list.get(6) + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		sql += " AND T.BATCH_NO LIKE '%' || '" + list.get(8) + "' || '%'";
		if (!list.get(9).equals("")) {
			if (list.get(9).equals("合格")) {
				sql += " AND T.QCM_STAUS NOT IN('22','12')";
			}else if(list.get(9).equals("判废")){
				sql += " AND T.QCM_STAUS  IN('22','12')";
			}
		}
		sql1 = sql1.replace("#someThing#", sql);
		return this.getData(sql1);
	}
	
	/**
	 * 查询接箍库存信息(汇总)
	 * @param list
	 * @return
	 */
	public CoreReturnObject getQueryCouplingMatTogether(ArrayList<String> list) {
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.getQueryCouplingMatTogether");
		String sql = "";
		//sql += " AND T1.STORAGE_NO LIKE '%' || '" + list.get(0) + "' || '%'";
		sql += " AND T.judge_stove_no LIKE '%' || '" + list.get(2) + "' || '%'";
		if (!list.get(3).equals("1")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ list.get(3)
					+ "','YYYY-MM-DD HH24:MI:SS') AND T.CREATE_TIME <=TO_DATE('"
					+ list.get(6) + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		sql += " AND T.BATCH_NO LIKE '%' || '" + list.get(8) + "' || '%'";
		if (!list.get(9).equals("")) {
			if (list.get(9).equals("合格")) {
				sql += " AND T.QCM_STAUS NOT IN('22','12')";
			}else if(list.get(9).equals("判废")){
				sql += " AND T.QCM_STAUS  IN('22','12')";
			}
		}
		sql1 = sql1.replace("#someThing#", sql);
		return this.getData(sql1);
	}
	
	/**
	 * 查询接箍库存信息
	 * @param list
	 * @return
	 */
	public CoreReturnObject getQueryCouplingMat2(ArrayList<String> list) {
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.getQueryCouplingMat2");
		String sql = "";
		//sql += " AND T1.STORAGE_NO LIKE '%' || '" + list.get(0) + "' || '%'";
		sql += " AND T.judge_stove_no LIKE '%' || '" + list.get(2) + "' || '%'";
		if (!list.get(3).equals("1")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ list.get(3)
					+ "','YYYY-MM-DD HH24:MI:SS') AND T.CREATE_TIME <=TO_DATE('"
					+ list.get(6) + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		sql += " AND T.BATCH_NO LIKE '%' || '" + list.get(8) + "' || '%'";
		if (!list.get(9).equals("")) {
			if (list.get(9).equals("合格")) {
				sql += " AND T.QCM_STAUS NOT IN('22','12')";
			}else if(list.get(9).equals("判废")){
				sql += " AND T.QCM_STAUS  IN('22','12')";
			}
		}
		sql1 = sql1.replace("#someThing#", sql);
		return this.getData(sql1);
	}
    /**
	 * 查询接箍
	 * 
	 * @return
	 */
	public CoreReturnObject getBaseMaterialForChoose() {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.getBaseMaterialForChoose");
		sql += "   ORDER BY  A.OUT_MATERIAL_DESC";
		return this.getData(sql);
	}

	/***
	 * 查询接箍库存信息
	 */
	public CoreReturnObject getQueryCouplingMatLiku(ArrayList<String> list) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.getQueryCouplingMatLiku");
		sql += " AND T1.STORAGE_NO LIKE '%' || '" + list.get(0) + "' || '%'";
		// sql += " AND T1.KEP_NO LIKE '%' || '" + list.get(1) + "' || '%'";

		sql += " AND T.judge_stove_no LIKE '%' || '" + list.get(2) + "' || '%'";
		if (!list.get(3).equals("1")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ list.get(3)
					+ "','YYYY-MM-DD HH24:MI:SS') AND T.CREATE_TIME <=TO_DATE('"
					+ list.get(6) + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		sql += " AND T.BATCH_NO LIKE '%' || '" + list.get(8) + "' || '%'";
		sql += " group by T.MAT_NO,T.RESULT_NO,T.ZY_PLAN_ID,T.WO_ID,T1.PRO_PLAN_ID,T.PLINE_CODE,T.PLINE_NAME,T.JUDGE_STOVE_NO,"
				+ "T.BATCH_NO,T.BL_WL_ID,T.BL_WL_DESC,T.MIN_D,T.MIN_H,T.CODE_JG,T.GRADECODE,T.GRADENAME,T.STEELCODE,T.STEELNAME,T.MODEL_CODE,"
				+ "T.MODEL_DESC,T.OUTDIAMETER,T.WALLTHICK,T.SPEC_JG,T.SPEC_JG_DESC,T.STYLE_JG,T.DIAMETER,T.CHECK_J_VAL,T.AIMLENGTH,T.SINGLEWEIGHT,"
				+ "T.MONITORDEMAND,T.IF_MONITOR_JG,T.PRDCR_NO,T.PRODUCER,T1.MACH_NO,T1.MACH_NM,T.PRO_NUM,T.PRO_WT,T.RRO_TIME,T.PRO_GROUP,"
				+ "T.PRO_SHIFT,T1.CUST_ALPHA_NO,T1.ORDER_SPECIAL_DESC,T.COL_OPERATOR,T.CREATE_NAME,T.CREATE_TIME,T.UPDATE_NAME,T.UPDATE_TIME";
		sql += " ORDER BY T.CREATE_TIME DESC";
		return this.getData(sql);
	}

	/***
	 * 查询入库信息
	 */
	public CoreReturnObject getQueryCouplingInlist(ArrayList<String> list) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.getQueryCouplingInlist");
		// sql += " AND T1.KEP_NO LIKE '%' || '" + list.get(1) + "' || '%'";
		sql += " AND judge_stove_no LIKE '%' || '" + list.get(0) + "' || '%'";
		if (!list.get(1).equals("1")) {
			sql += " AND CREATE_TIME >=TO_DATE('" + list.get(1)
					+ "','YYYY-MM-DD HH24:MI:SS') AND CREATE_TIME <=TO_DATE('"
					+ list.get(2) + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		sql += " AND WO_ID LIKE '%' || '" + list.get(3) + "' || '%'";
		sql += " ORDER BY CREATE_TIME DESC";
		return this.getData(sql);
	}

	/***
	 * 查询出库信息
	 */
	public CoreReturnObject getQueryCouplingOutlist(ArrayList<String> list) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.getQueryCouplingOutlist");
		// sql += " AND T1.KEP_NO LIKE '%' || '" + list.get(1) + "' || '%'";
		sql += " AND judge_stove_no LIKE '%' || '" + list.get(0) + "' || '%'";
		if (!list.get(3).equals("1")) {
			sql += " AND CREATE_TIME >=TO_DATE('" + list.get(3)
					+ "','YYYY-MM-DD HH24:MI:SS') AND CREATE_TIME <=TO_DATE('"
					+ list.get(4) + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		sql += " AND WO_ID LIKE '%' || '" + list.get(3) + "' || '%'";
		sql += " ORDER BY CREATE_TIME DESC";
		return this.getData(sql);
	}

	/**
	 * 查询接箍上料台账
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doQueryLoadResult(String judgeNo, String batchNo,
			String specNo, String steelNo, String modelNo, String bc,
			String bz, String[] plinCodes, String start, String end) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.doQueryLoadResult");
		if (!start.equals("")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ start
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
					+ end + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);
		if (!bc.equals("")) {
			sql += " AND T.LOAD_SHIFT ='" + bc + "'";
		}
		if (!bz.equals("")) {
			sql += " AND T.LOAD_GROUP ='" + bz + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO ='" + judgeNo + "'";
		}
		if (!batchNo.equals("")) {
			sql += " AND T.BATCH_NO ='" + batchNo + "'";
		}
		if (!specNo.equals("")) {
			sql += " AND T.SPEC_JG_DESC ='" + specNo + "'";
		}
		if (!steelNo.equals("")) {
			sql += " AND T.STEELNAME ='" + steelNo + "'";
		}
		if (!modelNo.equals("")) {
			sql += " AND T.MODEL_DESC ='" + modelNo + "'";
		}
		sql += " GROUP BY T.CONFIRM,T.CONFIRM_NAME,T.CONFIRM_TIME,T.IS_AUDITE,T.BATCH_NO,M.BUYER_NAME,M.MIN_D,M.MIN_H,T.GRADENAME,T.STEELNAME,T.SPEC_JG_DESC,T.STD_NAME,T.STD_STYLE_DESC,T.PRODUCCODE_JG_DESC,T.MODEL_DESC,M.ORDER_NO,M.ORDER_SEQ,T.RESULT_NO,T.PLINE_CODE,T.PLINE_NAME,M.JUDGE_STOVE_NO,M.PRDCR_NO,T.WO_ID,T.LOAD_SHIFT,T.LOAD_GROUP,T.LOAD_USER,M.IF_MONITOR_JG";
		return this.getData(sql);
	}

	/**
	 * 查询接箍锯切台账
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doQueryCutResult(String judgeNo, String batchNo,
			String specNo, String steelNo, String modelNo, String machon,
			String bc, String bz, String[] plinCodes, String start, String end) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.doQueryCutResult");
		if (!start.equals("")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ start
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
					+ end + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);
		if (!bc.equals("")) {
			sql += " AND T.COL_SHIFT ='" + bc + "'";
		}
		if (!bz.equals("")) {
			sql += " AND T.COL_GROUP ='" + bz + "'";
		}
		if (!machon.equals("")) {
			sql += " AND T.MACHINE_NO ='" + machon + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO ='" + judgeNo + "'";
		}
		if (!batchNo.equals("")) {
			sql += " AND T.BATCH_NO ='" + batchNo + "'";
		}
		if (!specNo.equals("")) {
			sql += " AND T.SPEC_JG_DESC ='" + specNo + "'";
		}
		if (!steelNo.equals("")) {
			sql += " AND T.STEELNAME ='" + steelNo + "'";
		}
		if (!modelNo.equals("")) {
			sql += " AND T.MODEL_DESC ='" + modelNo + "'";
		}
		sql += " GROUP BY T.CONFIRM_NAME,T.COL_OPERATOR,T.CONFIRM_TIME,T.CONFIRM,T.IS_AUDITE,M.BUYER_NAME,M.MIN_D,M.MIN_H,M.MODEL_DESC,M.SPEC_JG_DESC,M.GRADENAME,M.STEELNAME,M.STD_NAME,M.STD_STYLE_DESC,M.PRODUCCODE_JG_DESC,T.BATCH_NO,M.ORDER_NO,M.ORDER_SEQ,T.REJECTED_REASON,T.MACHINE_NO,T.RESULT_NO,T.PLINE_CODE,T.PLINE_NAME,T.JUDGE_STOVE_NO,M.PRDCR_NO,T.WO_ID,T.COL_SHIFT,T.COL_GROUP,T.COL_USER,M.IF_MONITOR_JG order by to_number(regexp_substr(T.MACHINE_NO,'[0-9]*[0-9]',1))";
		return this.getData(sql);
	}

	/**
	 * 查询接箍车丝台账
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doQueryThreaResult(String judgeNo, String batchNo,
			String specNo, String steelNo, String modelNo, String machon,
			String bc, String bz, String[] plinCodes, String start, String end) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.doQueryThreaResult");
		if (!start.equals("")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ start
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
					+ end + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);
		if (!bc.equals("")) {
			sql += " AND T.COL_SHIFT ='" + bc + "'";
		}
		if (!bz.equals("")) {
			sql += " AND T.COL_GROUP ='" + bz + "'";
		}
		if (!machon.equals("")) {
			sql += " AND T.MACHINE_NO ='" + machon + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO ='" + judgeNo + "'";
		}
		if (!batchNo.equals("")) {
			sql += " AND T.BATCH_NO ='" + batchNo + "'";
		}
		if (!specNo.equals("")) {
			sql += " AND T.SPEC_JG_DESC ='" + specNo + "'";
		}
		if (!steelNo.equals("")) {
			sql += " AND T.STEELNAME ='" + steelNo + "'";
		}
		if (!modelNo.equals("")) {
			sql += " AND T.MODEL_DESC ='" + modelNo + "'";
		}
		sql += " GROUP BY T.BATCH_NO,T.CONFIRM_NAME,T.COL_OPERATOR1,T.COL_OPERATOR2,M.MODEL_DESC,T.CONFIRM_TIME,T.CONFIRM,T.IS_AUDITE,M.MIN_D,M.MIN_H,M.STEELNAME,M.GRADENAME,M.SPEC_JG_DESC,M.STD_NAME,M.STD_STYLE_DESC,M.PRODUCCODE_JG_DESC,M.BUYER_NAME,M.ORDER_NO,M.ORDER_SEQ,T.REJECTED_REASON,T.MACHINE_NO,T.RESULT_NO,T.PLINE_CODE,T.PLINE_NAME,M.JUDGE_STOVE_NO,M.PRDCR_NO,T.WO_ID,T.COL_SHIFT,T.COL_GROUP,T.COL_USER,M.IF_MONITOR_JG  order by to_number(regexp_substr(T.MACHINE_NO,'[0-9]*[0-9]',1))";
		return this.getData(sql);
	}

	/**
	 * 查询接箍车丝不合格品台账
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doQueryFailResult(String judgeNo, String batchNo,
			String specNo, String steelNo, String modelNo, String machon,
			String bc, String bz, String[] plinCodes, String start, String end) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.doQueryFailResult");
		if (!start.equals("")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ start
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
					+ end + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);
		if (!bc.equals("")) {
			sql += " AND T.COL_SHIFT ='" + bc + "'";
		}
		if (!bz.equals("")) {
			sql += " AND T.COL_GROUP ='" + bz + "'";
		}
		if (!machon.equals("")) {
			sql += " AND T.MACHINE_NO ='" + machon + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO ='" + judgeNo + "'";
		}
		if (!batchNo.equals("")) {
			sql += " AND T.BATCH_NO ='" + batchNo + "'";
		}
		if (!specNo.equals("")) {
			sql += " AND T.SPEC_JG_DESC ='" + specNo + "'";
		}
		if (!steelNo.equals("")) {
			sql += " AND T.STEELNAME ='" + steelNo + "'";
		}
		if (!modelNo.equals("")) {
			sql += " AND T.MODEL_DESC ='" + modelNo + "'";
		}
		sql += " GROUP BY M.MIN_D,M.MIN_H,M.STEELNAME,M.GRADENAME,M.PRODUCCODE_JG_DESC,T.REJECTED_REASON,T.PLINE_NAME,T.JUDGE_STOVE_NO,T.COL_USER,t.BATCH_NO,M.MODEL_DESC,T.REJECTED_PCS,M.SINGLEWEIGHT,T.MEMO";
		return this.getData(sql);
	}

	/**
	 * 查询接箍磷化台账
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doQueryPhosphResult(String judgeNo, String batchNo,
			String specNo, String steelNo, String modelNo, String bc,
			String bz, String[] plinCodes, String start, String end) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.doQueryPhosphResult");
		if (!start.equals("")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ start
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
					+ end + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);
		if (!bc.equals("")) {
			sql += " AND T.COL_SHIFT ='" + bc + "'";
		}
		if (!bz.equals("")) {
			sql += " AND T.COL_GROUP ='" + bz + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO ='" + judgeNo + "'";
		}
		if (!batchNo.equals("")) {
			sql += " AND T.BATCH_NO ='" + batchNo + "'";
		}
		if (!specNo.equals("")) {
			sql += " AND T.SPEC_JG_DESC ='" + specNo + "'";
		}
		if (!steelNo.equals("")) {
			sql += " AND T.STEELNAME ='" + steelNo + "'";
		}
		if (!modelNo.equals("")) {
			sql += " AND T.MODEL_DESC ='" + modelNo + "'";
		}
		sql += " GROUP BY T.CREATE_TIME,T.BATCH_NO,T.MATCONFIRM_TIME,T.MATCONFIRM_NAME,T.CONFIRM_NAME,M.SINGLEWEIGHT,M.MODEL_DESC,T.CONFIRM_TIME,T.CONFIRM,T.COL_OPERATOR,T.IS_AUDITE,M.MIN_D,M.MIN_H,M.STEELNAME,M.GRADENAME,M.SPEC_JG_DESC,M.STD_NAME,M.STD_STYLE_DESC,M.PRODUCCODE_JG_DESC,M.BUYER_NAME,M.ORDER_NO,M.ORDER_SEQ,T.RESULT_NO,T.PLINE_CODE,T.PLINE_NAME,M.JUDGE_STOVE_NO,M.PRDCR_NO,T.WO_ID,T.COL_SHIFT,T.COL_GROUP,T.COL_USER,M.IF_MONITOR_JG";
		return this.getData(sql);
	}

	/**
	 * 查询接箍螺纹台账
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doQueryThreadInResult(String judgeNo,
			String batchNo, String specNo, String steelNo, String modelNo,
			String bc, String bz, String[] plinCodes, String start, String end) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.doQueryThreadInResult");
		if (!start.equals("")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ start
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
					+ end + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);
		if (!bc.equals("")) {
			sql += " AND T.COL_SHIFT ='" + bc + "'";
		}
		if (!bz.equals("")) {
			sql += " AND T.COL_GROUP ='" + bz + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO ='" + judgeNo + "'";
		}
		if (!batchNo.equals("")) {
			sql += " AND T.BATCH_NO ='" + batchNo + "'";
		}
		if (!specNo.equals("")) {
			sql += " AND T.SPEC_JG_DESC ='" + specNo + "'";
		}
		if (!steelNo.equals("")) {
			sql += " AND T.STEELNAME ='" + steelNo + "'";
		}
		if (!modelNo.equals("")) {
			sql += " AND T.MODEL_DESC ='" + modelNo + "'";
		}
		sql += " GROUP BY T.BATCH_NO,T.CONFIRM_NAME,M.MODEL_DESC,T.CONFIRM_TIME,T.CONFIRM,T.IS_AUDITE,M.MIN_D,M.MIN_H,M.STEELNAME,M.GRADENAME,M.SPEC_JG_DESC,M.STD_NAME,M.STD_STYLE_DESC,M.PRODUCCODE_JG_DESC,M.BUYER_NAME,M.ORDER_NO,M.ORDER_SEQ,T.RESULT_NO,T.PLINE_CODE,T.PLINE_NAME,M.JUDGE_STOVE_NO,M.PRDCR_NO,T.WO_ID,T.COL_SHIFT,T.COL_GROUP,T.COL_USER,M.IF_MONITOR_JG";
		return this.getData(sql);
	}

	/**
	 * 查询接箍喷砂台账
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doQuerySandBlastResult(String judgeNo,
			String batchNo, String specNo, String steelNo, String modelNo,
			String bc, String bz, String[] plinCodes, String start, String end) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.doQuerySandBlastResult");
		if (!start.equals("")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ start
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
					+ end + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);
		if (!bc.equals("")) {
			sql += " AND T.COL_SHIFT ='" + bc + "'";
		}
		if (!bz.equals("")) {
			sql += " AND T.COL_GROUP ='" + bz + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO ='" + judgeNo + "'";
		}
		if (!batchNo.equals("")) {
			sql += " AND T.BATCH_NO ='" + batchNo + "'";
		}
		if (!specNo.equals("")) {
			sql += " AND T.SPEC_JG_DESC ='" + specNo + "'";
		}
		if (!steelNo.equals("")) {
			sql += " AND T.STEELNAME ='" + steelNo + "'";
		}
		if (!modelNo.equals("")) {
			sql += " AND T.MODEL_DESC ='" + modelNo + "'";
		}
		sql += " GROUP BY T.BATCH_NO,T.CONFIRM_NAME,M.MODEL_DESC,T.CONFIRM_TIME,T.CONFIRM,T.IS_AUDITE,M.MIN_D,M.MIN_H,M.STEELNAME,M.GRADENAME,M.SPEC_JG_DESC,M.STD_NAME,M.STD_STYLE_DESC,M.PRODUCCODE_JG_DESC,M.BUYER_NAME,M.ORDER_NO,M.ORDER_SEQ,T.RESULT_NO,T.PLINE_CODE,T.PLINE_NAME,M.JUDGE_STOVE_NO,M.PRDCR_NO,T.WO_ID,T.COL_SHIFT,T.COL_GROUP,T.COL_USER,M.IF_MONITOR_JG";
		return this.getData(sql);
	}

	/**
	 * 查询接箍探伤台账
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doQueryInspectResult(String judgeNo,
			String batchNo, String specNo, String steelNo, String modelNo,
			String bc, String bz, String[] plinCodes, String start, String end) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.doQueryInspectResult");
		if (!start.equals("")) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ start
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
					+ end + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);
		if (!bc.equals("")) {
			sql += " AND T.COL_SHIFT ='" + bc + "'";
		}
		if (!bz.equals("")) {
			sql += " AND T.COL_GROUP ='" + bz + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO ='" + judgeNo + "'";
		}
		if (!batchNo.equals("")) {
			sql += " AND T.BATCH_NO ='" + batchNo + "'";
		}
		if (!specNo.equals("")) {
			sql += " AND T.SPEC_JG_DESC ='" + specNo + "'";
		}
		if (!steelNo.equals("")) {
			sql += " AND T.STEELNAME ='" + steelNo + "'";
		}
		if (!modelNo.equals("")) {
			sql += " AND T.MODEL_DESC ='" + modelNo + "'";
		}
		sql += " GROUP BY T.BATCH_NO,T.CONFIRM_NAME,T.CONFIRM_TIME,T.CONFIRM,T.IS_AUDITE,M.MIN_D,M.MIN_H,M.STEELNAME,M.GRADENAME,M.SPEC_JG_DESC,M.STD_NAME,M.STD_STYLE_DESC,M.PRODUCCODE_JG_DESC,M.BUYER_NAME,M.ORDER_NO,M.ORDER_SEQ,T.RESULT_NO,T.PLINE_CODE,T.PLINE_NAME,M.JUDGE_STOVE_NO,M.PRDCR_NO,T.WO_ID,T.COL_SHIFT,T.COL_GROUP,T.COL_USER,M.IF_MONITOR_JG";
		return this.getData(sql);
	}

	/**
	 * 查询接箍实绩统计
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doQueryPerformance(ArrayList<String> list,
			String[] plinCodes, String stationCode) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmJGMatNoReport.doQueryPerformance");
		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.WO_ID LIKE'%'||'" + list.get(3) + "'||'%'";
		}
		if (!list.get(4).equals("")) {
			sql += " AND  M.ORDER_NO || '/' || M.ORDER_SEQ LIKE'%'||'"
					+ list.get(4) + "'||'%'";
		}
		sql += CoreConverter.toSqlConditionString("M.PLINE_CODE", plinCodes);
		// if (!plinCodes.equals("")) {
		// sql += " AND M.PLINE_CODE='" + plinCodes + "'";
		// }
		if (!stationCode.equals("")) {
			sql += " AND T.STATION_CODE='" + stationCode + "'";
		}
		sql += " GROUP BY M.PLAN_BL_NUM,M.PLAN_BL_WT,M.PLAN_JG_NUM,M.BATCH_NO,M.WO_ID,M.PLINE_CODE,M.HEAT_PLAN_NO,M.PLINE_NAME, "
				+ "M.CRAFT_FILE_NO,M.CRAFT_SEQ, M.JUDGE_STOVE_NO,"
				+ " T.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 ORDER BY  M.JUDGE_STOVE_NO";
		return this.getData(sql);
	}

	/**
	 * 台账核对
	 * 
	 * @param result
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject doAudite(ArrayList<Object> list1, String gx) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqldelete = "";
			PreparedStatement patdelete = null;
			if (gx.equals("700301")) {
				sqldelete = CoreXmlSqlParsersFactory
						.getSql("FrmJGMatNoReport.updateCouplingIsAduite");// 修改实绩标志位
				patdelete = connection.prepareStatement(sqldelete);
			} else if (gx.equals("700302")) {
				sqldelete = CoreXmlSqlParsersFactory
						.getSql("FrmJGMatNoReport.updateCouplingIsAduiteCut");// 修改实绩标志位
				patdelete = connection.prepareStatement(sqldelete);
			} else if (gx.equals("700305")) {
				sqldelete = CoreXmlSqlParsersFactory
						.getSql("FrmJGMatNoReport.updateCouplingIsAduiteThrea");// 修改实绩标志位
				patdelete = connection.prepareStatement(sqldelete);
			} else if (gx.equals("700306")) {
				sqldelete = CoreXmlSqlParsersFactory
						.getSql("FrmJGMatNoReport.updateCouplingIsAduiteThin");// 修改实绩标志位
				patdelete = connection.prepareStatement(sqldelete);
			} else if (gx.equals("700307")) {
				sqldelete = CoreXmlSqlParsersFactory
						.getSql("FrmJGMatNoReport.updateCouplingIsAduiteInsp");// 修改实绩标志位
				patdelete = connection.prepareStatement(sqldelete);
			} else if (gx.equals("700308")) {
				sqldelete = CoreXmlSqlParsersFactory
						.getSql("FrmJGMatNoReport.updateCouplingIsAduiteSand");// 修改实绩标志位
				patdelete = connection.prepareStatement(sqldelete);
			} else if (gx.equals("700310")) {
				sqldelete = CoreXmlSqlParsersFactory
						.getSql("FrmJGMatNoReport.updateCouplingIsAduitePhos");// 修改实绩标志位
				patdelete = connection.prepareStatement(sqldelete);
			}

			// 判断删除限制
			for (int i = 0; i < list1.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) list1.get(i);
				String resultNo = list.get(0);
				String woid = list.get(1);
				// 删除磷化实绩
				patdelete.setObject(1, woid);
				patdelete.setObject(2, resultNo);
				patdelete.addBatch();
			}
			patdelete.executeBatch();

			core.setV_errMsg("核对成功!");
			core.setResult(1);
			connection.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 消亡
	 * @param parm
	 * @return
	 */
	public CoreReturnObject Extinction(ArrayList<String> parm,String user) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String deleteMatSql = CoreXmlSqlParsersFactory
					.getSql("FrmJGMatNoReport.extinction");
			PreparedStatement deleteMatPsta = connection
					.prepareStatement(deleteMatSql);
			
			for (String str : parm) {
				CouplingMatButtressEntity milOfflineGroup = EntityTool
						.getEntityByJSONStr(str,
								CouplingMatButtressEntity.class);
				deleteMatPsta.setString(1, milOfflineGroup.getMatNo());
				deleteMatPsta.setString(2, milOfflineGroup.getProNum());
				deleteMatPsta.setString(3, user);
				deleteMatPsta.addBatch();

			}
			deleteMatPsta.executeBatch();
			cro.setV_errMsg("消亡成功!");
			connection.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	
	/**
	 * 消亡
	 * @param parm
	 * @return
	 */
	public CoreReturnObject doUpdate(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateMatSql = CoreXmlSqlParsersFactory
					.getSql("FrmJGMatNoReport.doUpdate");
			PreparedStatement updateMatPsta = connection
					.prepareStatement(updateMatSql);
			
			for (String str : parm) {
				CouplingMatMEntity milOfflineGroup = EntityTool
						.getEntityByJSONStr(str,
								CouplingMatMEntity.class);
				updateMatPsta.setString(1, milOfflineGroup.getBlWlId());
				updateMatPsta.setString(2, milOfflineGroup.getBlWlDesc());
				updateMatPsta.setString(3, milOfflineGroup.getMatNo());
				updateMatPsta.addBatch();

			}
			updateMatPsta.executeBatch();
			cro.setV_errMsg("修改成功!");
			connection.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
}
