package com.steering.mes.zgmil.report;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

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

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.common.EntityTool;
import com.steering.mes.zgmil.entity.FeedSawResultEntity;
import com.steering.mes.zgmil.entity.MilCheckDeatilSimpleEntity;
import com.steering.mes.zgmil.entity.MilProcessesEntity;

/**
 * 
 * @author Administrator
 * 
 */
public class FrmMilDateStatistics extends DBCommon {

	/***
	 * 查询各工序实际数据 轧管生产数据统计 FrmMilDateStatistics
	 * 
	 * @param date
	 * @param endDate
	 * @param judgeStoveNo
	 * @param lotNo
	 * @param pline
	 * @param contractNo
	 * @return
	 */
	public CoreReturnObject getMilDateStatisticsActual(String date,
			String endDate, String judgeStoveNo, String lotNo,
			String contractNo, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilDateStatisticsActual");
		if (!date.equals("")) {
			sql += " AND T.START_TIME BETWEEN TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!judgeStoveNo.equals("")) {
			sql += "  AND REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '') = '"
					+ judgeStoveNo + "' ";
		}
		if (!lotNo.equals("")) {
			sql += " AND T1.LOT_NO = '" + lotNo + "' ";
		}
		if (!contractNo.equals("")) {
			sql += " AND T1.CONTRACT_NO = '" + contractNo + "' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql += " ORDER BY T.START_TIME ASC";
		return this.getData(sql);
	}

	/**
	 * 轧管生产按炉跟踪判定情况查询
	 * 
	 * @param date
	 * @param endDate
	 * @param judgeStoveNo
	 * @param lotNo
	 * @param contractNo
	 * @param pline
	 * @return
	 */
	public CoreReturnObject getFrmMilDateWaitingDecision(String date,
			String endDate, String judgeStoveNo, String lotNo,
			String contractNo, String pline, String validFlag, String IsVisible) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getFrmMilDateWaitingDecision");
		if (!date.equals("")) {
			sql += " AND T.COL_TIME BETWEEN TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!judgeStoveNo.equals("")) {
			sql += "  AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = '"
					+ judgeStoveNo + "' ";
		}
		if (!lotNo.equals("")) {
			sql += " AND T.LOT_NO = '" + lotNo + "' ";
		}
		if (!contractNo.equals("")) {
			sql += " AND T.CONTRACT_NO LIKE '%" + contractNo + "%' ";
		}
		if (!pline.equals("")) {
			sql += " AND T.PLINE_CODE = '" + pline + "' ";
		}
		if (!IsVisible.equals("")) {
			sql += " AND T.IS_VISIBLE = '" + IsVisible + "' ";
		}
		if (!validFlag.equals("")) {
			if (validFlag.equals("20")) {
				sql += " AND T2.JUDGE_RESULT_CODE IN('40740701','407407019')  ";
			} else {
				sql += " AND (T2.JUDGE_RESULT_CODE NOT IN('40740701','407407019') OR T2.JUDGE_RESULT_CODE IS NULL) ";
			}
		}
		sql += " GROUP BY T.PLINE_CODE,T.JUDGE_STOVE_NO,T.SAW_NUM,T.LOT_NO,T.IF_MONITOR,T.COL_TIME";
		sql += " ORDER BY T.COL_TIME";
		return this.getData(sql);
	}

	/***
	 * 统计表PORT_MIL_BATCH_SAMPLE_RESULT中的数据 轧管生产数据汇总 FrmMilDateStatistics2
	 * 
	 * @param date
	 * @param endDate
	 * @param judgeStoveNo
	 * @param lotNo
	 * @param pline
	 * @param contractNo
	 * @return
	 */
	public CoreReturnObject getMilDateStatisticsBatchSample(String date,
			String endDate, String judgeStoveNo, String lotNo,
			String contractNo, String[] plineCodes, String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilDateStatisticsBatchSample");
		String sql1 = "";
		if (!date.equals("")) {
			sql1 += " AND T1.START_TIME BETWEEN TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!judgeStoveNo.equals("")) {
			// sql1 += "  AND SUBSTR(T1.JUDGE_STOVE_NO, 1, 6) = '" +
			// judgeStoveNo + "' ";
			sql1 += " AND T1.JUDGE_STOVE_NO like '" + judgeStoveNo + "%' ";
		}
		if (!lotNo.equals("")) {
			sql1 += " AND T1.LOT_NO like '" + lotNo + "%' ";
		}
		if (!contractNo.equals("")) {
			sql1 += " AND T1.CONTRACT_NO like  '" + contractNo + "%' ";
		}
		if (!plineCode.equals("")) {
			sql1 += " AND T.PLINE_CODE =  '" + plineCode + "' ";
		}
		sql1 += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql = sql.replace("#something#", sql1);
		return this.getData(sql);
	}

	public CoreReturnObject getMilDateStatisticsBatchSampleNew(String date,
			String endDate, String judgeStoveNo, String lotNo,
			String contractNo, String[] plineCodes, String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilDateStatisticsBatchSampleNew");
		if (!date.equals("")) {
			sql += " AND T.FEED_TIME BETWEEN TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!judgeStoveNo.equals("")) {
			sql += "  AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "' ";
		}
		if (!lotNo.equals("")) {
			sql += " AND T.LOT_NO = '" + lotNo + "' ";
		}
		if (!contractNo.equals("")) {
			sql += " AND T.CONTRACT_NO = '" + contractNo + "' ";
		}
		if (!plineCode.equals("")) {
			sql += " AND T.PLINE_CODE =  '" + plineCode + "' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql += " ORDER BY T.FEED_TIME ASC";
		return this.getData(sql);
	}

	/***
	 * 轧管产出统计 FrmMilOutputStatistics 界面名称
	 * 
	 * @param date
	 * @param endDate
	 * @param judgeStoveNo
	 * @param lotNo
	 * @param pline
	 * @return
	 */
	public CoreReturnObject getMilOutputStatistics(String date, String endDate,
			String judgeStoveNo, String lotNo, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilOutputStatistics");
		if (!date.equals("")) {
			sql += " AND T.FEED_TIME BETWEEN TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!judgeStoveNo.equals("")) {
			sql += "  AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = '"
					+ judgeStoveNo + "' ";
		}
		if (!lotNo.equals("")) {
			sql += " AND T.LOT_NO = '" + lotNo + "' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql += " GROUP BY T.LOT_NO,T.VARIETIES,T.CONTRACT_NO,T.ID,T.PIPE_SIZE,T.BUCKLE_TYPE,T.STEELNAME,T.GRADENAME,T.PLINE_CODE,T.NODE_STATUS,T.TARGET,T.SAW_NUM,REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', ''),T.FEED_TIME ORDER BY T.FEED_TIME ASC";
		return this.getData(sql);
	}

	/**
	 * 轧管废品统计 FrmMilScrapStatistics 界面名称
	 * 
	 * @param date
	 * @param endDate
	 * @param judgeStoveNo
	 * @param lotNo
	 * @param pline
	 * @return
	 */
	public CoreReturnObject getMilScrapStatistics(String date, String endDate,
			String judgeStoveNo, String lotNo, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilScrapStatistics");
		if (!date.equals("")) {
			sql += " AND T.FEED_TIME BETWEEN TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!judgeStoveNo.equals("")) {
			sql += "  AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = '"
					+ judgeStoveNo + "' ";
		}
		if (!lotNo.equals("")) {
			sql += " AND T.LOT_NO = '" + lotNo + "' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql += " GROUP BY T.LOT_NO,T.VARIETIES,T.CONTRACT_NO,T.ID,T.PIPE_SIZE,T.BUCKLE_TYPE,T.STEELNAME,T.GRADENAME,T.PLINE_CODE,T.NODE_STATUS,T.TARGET,T.SAW_NUM,REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', ''),T.FEED_TIME ORDER BY T.FEED_TIME ASC";
		return this.getData(sql);
	}

	/***
	 * 调 度 统 计 FrmMilControlLog 界面名称
	 * 
	 * @param date
	 * @param bc
	 * @param bz
	 * @param judgeStoveNo
	 * @param pline
	 * @return
	 */
	public CoreReturnObject getMilControlLog(String date, String endDate,
			String judgeStoveNo, String bc, String bz, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilControlLog");

		if (!date.equals("")) {
			sql += " AND T.PROC_DATE between '" + date + "' and '" + endDate
					+ "'";
		}
		if (!judgeStoveNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "-01' ";
		}
		if (!bc.equals("")) {
			sql += " AND T.PRO_BC = '" + bc + "' ";
		}
		if (!bz.equals("")) {
			sql += " AND T.PRO_BZ = '" + bz + "' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql += " ORDER BY T.PLINE_CODE,t.logs_beg ";
		return this.getData(sql);
	}

	/**
	 * 调度停机统计
	 * 
	 * @param date
	 * @param endDate
	 * @param pline
	 * @return
	 */
	public CoreReturnObject getMilControlLogStop(String date, String endDate,
			String pline, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilControlLogStop");

		if (!date.equals("")) {
			sql += " AND T.LOGS_BEG between '" + date + "' and '" + endDate
					+ "'";
		}
		if (!pline.equals("")) {
			sql += " AND T.PLINE_CODE = '" + pline + "' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql += " ORDER BY T.PLINE_CODE,t.logs_beg ";
		return this.getData(sql);
	}

	/**
	 * 调 度 统 计(小时能力)
	 * 
	 * @param time
	 * @return
	 */
	public CoreReturnObject getMilControlLog2(String time, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilControlLog2");
		String sql1 = "";
		if (!time.equals("")) {
			sql1 += " AND T.BAL_YEAR_MONTH = '" + time + "' ";
		}
		sql1 += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql = sql.replace("#something#", sql1);

		return this.getData(sql);
	}

	/**
	 * 调 度 统 计(停机汇总)
	 * 
	 * @param time
	 * @return
	 */
	public CoreReturnObject getMilControlLog3(String time, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilControlLog3");
		String sql1 = "";
		if (!time.equals("")) {
			sql1 += " AND T.BAL_YEAR_MONTH = '" + time + "' ";
		}
		sql1 += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql = sql.replace("#something#", sql1);

		return this.getData(sql);
	}

	/**
	 * 回报小时能力
	 * 
	 * @param listAll
	 * @return
	 */
	public CoreReturnObject updateMilControlLog(ArrayList<ArrayList> listAll) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sql1 = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.updateMilControlLog");
			PreparedStatement updateMilControlLog = connection
					.prepareStatement(sql1);
			for (ArrayList<String> list : listAll) {
				updateMilControlLog.setString(1, list.get(0));
				updateMilControlLog.setString(2, list.get(1));
				updateMilControlLog.setString(3, list.get(2));
				updateMilControlLog.setString(4, list.get(3));
				updateMilControlLog.setString(5, list.get(4));
				updateMilControlLog.addBatch();
			}
			updateMilControlLog.executeBatch();
			connection.commit();
			cro.setV_errMsg("回报成功!");
		} 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 date
	 * @param endDate
	 * @param judgeStoveNo
	 * @param lotNo
	 * @param pline
	 * @return
	 */
	public CoreReturnObject getQcmZgJugdeApply(String date, String endDate,
			String judgeStoveNo, String lotNo, String applyCode, String state,
			String[] plineCodes) {
		// 查全部
		if (state.equals("")) {
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.getQcmZgJugdeApply");
			if (!date.equals("")) {
				sql += " AND T.JUDGE_RESULT_TIME BETWEEN TO_DATE('" + date
						+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
						+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
			}
			if (!judgeStoveNo.equals("")) {
				sql += "  AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = '"
						+ judgeStoveNo + "' ";
			}
			if (!lotNo.equals("")) {
				sql += " AND T.LOT_NO = '" + lotNo + "' ";
			}
			sql += CoreConverter.toSqlConditionString("T.PLINE_CODE",
					plineCodes);

			if (!applyCode.equals("")) {
				sql += " AND T.JUGDE_APPLY_CODE = '" + applyCode + "' ";
			}
			sql += " union all ";
			sql += CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.getNoQcmZgJugdeApply");
			if (!date.equals("")) {
				sql += " AND P.FEED_TIME BETWEEN TO_DATE('" + date
						+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
						+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
			}
			if (!judgeStoveNo.equals("")) {
				sql += "  AND T1.JUDGE_STOVE_NO = '" + judgeStoveNo + "' ";
			}
			if (!lotNo.equals("")) {
				sql += " AND P.LOT_NO = '" + lotNo + "' ";
			}
			sql += CoreConverter.toSqlConditionString("p.PLINE_CODE",
					plineCodes);
			return this.getData(sql);
		} else if (state.equals("30")) { // 查待送判断的
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.getNoQcmZgJugdeApply");
			if (!date.equals("")) {
				sql += " AND P.FEED_TIME BETWEEN TO_DATE('" + date
						+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
						+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
			}
			if (!judgeStoveNo.equals("")) {
				sql += "  AND T1.JUDGE_STOVE_NO = '" + judgeStoveNo + "' ";
			}
			if (!lotNo.equals("")) {
				sql += " AND P.LOT_NO = '" + lotNo + "' ";
			}
			sql += CoreConverter.toSqlConditionString("p.PLINE_CODE",
					plineCodes);
			return this.getData(sql);
		} else { // 查已送判的
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.getQcmZgJugdeApply");
			if (!date.equals("")) {
				sql += " AND T.JUDGE_RESULT_TIME BETWEEN TO_DATE('" + date
						+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
						+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
			}
			if (!judgeStoveNo.equals("")) {
				sql += "  AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = '"
						+ judgeStoveNo + "' ";
			}
			if (!lotNo.equals("")) {
				sql += " AND T.LOT_NO = '" + lotNo + "' ";
			}
			sql += CoreConverter.toSqlConditionString("T.PLINE_CODE",
					plineCodes);
			if (!applyCode.equals("")) {
				sql += " AND T.JUGDE_APPLY_CODE = '" + applyCode + "' ";
			}
			if (!state.equals("")) {
				sql += " AND T.VALIDFLAG = '" + state + "' ";
			}
			return this.getData(sql);
		}

	}

	/**
	 * 申请判定表综合
	 * 
	 * @param barYearMonth
	 *            结转年月
	 * @param pline
	 *            产线
	 * @return
	 */
	public CoreReturnObject getQcmZgJugdeApplyAll(String barYearMonth,
			String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getQcmZgJugdeApplyAll");
		if (!barYearMonth.equals("")) {
			sql += " AND t.bal_year_month = '" + barYearMonth + "'";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql += " group by t.plan_id,t.lot_no,t.bal_year_month,t.BATCH_NO,"
				+ "t.judge_stove_no,t.pline_code,t.act_count,t.act_theory_weight,"
				+ "p.varieties,p.STD_STYLE_DESC,p.steelname,p.pipe_size,p.BUCKLE_TYPE,p.TARGET";

		return this.getData(sql);
	}

	/**
	 * 申请判定表
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject getQcmZgJugdeApplyTest(ArrayList<String> parm) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getQcmZgJugdeApplyTest");

		return this.getData(sql, parm.toArray());
	}

	/**
	 * 入库单数据查询 RepMilGodownData 界面名称
	 * 
	 * @param barYearMonth
	 * @param judgeStoveNo
	 * @param pline
	 * @return
	 */
	public CoreReturnObject getMilGodownData(String date, String endDate,
			String judgeStoveNo, String lotNo, String contractNo,
			String[] plineCodes, String deptid) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilGodownData");
		String sql1 = "";
		if (!date.equals("")) {
			sql1 += " AND T3.INSTOCK_TIME BETWEEN TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!judgeStoveNo.equals("")) {
			sql1 += "  AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "' ";
		}
		if (!lotNo.equals("")) {
			sql1 += " AND T.LOT_NO = '" + lotNo + "' ";
		}
		if (!contractNo.equals("")) {
			sql1 += " AND T.ORDER_NO LIKE '%" + contractNo + "%'";
		}
		sql1 += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql = sql.replace("#something#", sql1);
		return this.getData(sql);
	}

	/***
	 * 在线品库存台账查询 FrmOnlineInventory 界面名称
	 * 
	 * @param judgeStoveNo
	 * @param lotNo
	 * @param pline
	 * @return
	 */
	public CoreReturnObject getOnlineInventory(String judgeStoveNo,
			String lotNo, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getOnlineInventory");
		String sql1 = "";
		if (!judgeStoveNo.equals("")) {
			sql1 = " AND A.JUDGE_STOVE_NO = '" + judgeStoveNo + "' ";
		}
		if (!lotNo.equals("")) {
			sql1 += " AND A.LOT_NO = '" + lotNo + "' ";
		}
		sql1 += CoreConverter.toSqlConditionString("A.PLINE_CODE", plineCodes);
		sql = sql.replace("#JUDGE_STOVE_NO#", sql1);
		return this.getData(sql);
	}

	/***
	 * 轧管投入产出报表
	 * 
	 * @param judgeStoveNo
	 * @param lotNo
	 * @param pline
	 * @param balYearMonth
	 * @return
	 */
	public CoreReturnObject getInputOutputStatement(String judgeStoveNo,
			String lotNo, String[] plineCodes, String balYearMonth) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getInputOutputStatement");
		String sql1 = "";
		if (!balYearMonth.equals("")) {
			sql1 += " AND M.BAL_YEAR_MONTH = '" + balYearMonth + "'";
		}
		if (!judgeStoveNo.equals("")) {
			sql1 = " AND M.JUDGE_STOVE_NO = '" + judgeStoveNo + "' ";
		}
		if (!lotNo.equals("")) {
			sql1 += " AND M.LOT_NO = '" + lotNo + "' ";
		}
		sql1 += CoreConverter.toSqlConditionString("M.PLINE_CODE", plineCodes);
		sql = sql.replace("#BAL_YEAR_MONTH#", sql1);
		return this.getData(sql);
	}

	/***
	 * 查询组炉数据
	 * 
	 * @param zpjudgeStoveNo
	 *            组批炉号
	 * @param zplotNo
	 *            组批批号
	 * @param pline
	 *            产线代码
	 * @param judgeStoveNo
	 *            原炉号
	 * @param ph
	 *            平衡验证
	 * @return
	 */
	public CoreReturnObject getMilOfflineGroup(String date, String endDate,
			String zpjudgeStoveNo, String zplotNo, String[] plineCodes,
			String judgeStoveNo, String ph) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilOfflineGroup");
		String sql1 = "";
		String sql2 = "";
		String sql3 = "";
		String sql4 = "";

		if (!zpjudgeStoveNo.equals("")) {
			sql1 += " AND T.ZP_JUDGE_STOVE_NO LIKE '%" + zpjudgeStoveNo + "%'";
			sql2 += " AND T.ZP_JUDGE_STOVE_NO LIKE '%" + zpjudgeStoveNo + "%'";
			sql3 += " AND T.NEW_HEAT_NO LIKE '%" + zpjudgeStoveNo + "%'";
		}
		if (!zplotNo.equals("")) {
			sql1 = " AND T.ZP_LOT_NO LIKE '%" + zplotNo + "%' ";
			sql2 = " AND T.ZP_LOT_NO LIKE '%" + zplotNo + "%' ";
			sql3 = " AND T.NEW_LOT_NO LIKE '%" + zplotNo + "%' ";
		}
		if (!judgeStoveNo.equals("")) {
			sql1 += " AND T.ZP_M_LH LIKE '%" + judgeStoveNo + "%' ";
			sql2 += " AND T.JUDGE_STOVE_NO LIKE '%" + judgeStoveNo + "%' ";
			sql3 += " AND T.JUDGE_STOVE_NO LIKE '%" + judgeStoveNo + "%' ";
		}
		sql1 += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql2 += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql3 += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);

		if (ph.equals("OK")) {
			sql4 += " AND F.ZP_COUNT2 - F.FPZ - F.PDZ = 0 ";
		} else if (ph.equals("清线不齐")) {
			sql4 += " AND F.ZP_COUNT2 - F.FPZ - F.PDZ <> 0 ";
		}
		if (!date.equals("")) {
			sql4 += " AND F.TOM BETWEEN  TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql = sql.replace("#something1#", sql1).replace("#something2#", sql2)
				.replace("#something3#", sql3).replace("#something4#", sql4);
		return this.getData(sql);
	}

	/***
	 * 加工排产一级与接箍订单查询
	 * 
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject getProductionSchedulingAndCoupling(String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getProductionSchedulingAndCoupling");
		String sql1 = "";
		if (!plineCode.equals("")) {
			sql1 += " AND T.PLINE_CODE = '" + plineCode + "' ";
		}

		sql = sql.replace("#something#", sql1);
		return this.getData(sql);
	}

	/**
	 * 查询加工产线
	 * 
	 * @return
	 */
	public CoreReturnObject getPlineName() {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getPlineName");
		return this.getData(sql);
	}

	/**
	 * 查询轧管产线
	 * 
	 * @return
	 */
	public CoreReturnObject getPlineNameZG(String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getPlineNameZG");
		sql += CoreConverter.toSqlConditionString("A.PLINE_CODE", plineCodes);
		return this.getData(sql);
	}

	/***
	 * 查询产量报表
	 * 
	 * @param date
	 * @param endDate
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject getMilStaOutput(String date, String endDate,
			String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilStaOutput");
		String sql1 = "";
		if (!plineCode.equals("")) {
			sql1 += " AND T.PLINE_CODE = '" + plineCode + "' ";
		}
		if (!date.equals("")) {
			sql1 += " AND TO_CHAR(T.JUDGE_RESULT_TIME,'YYYY-MM-DD HH:MI:SS') BETWEEN  '"
					+ date + "' AND '" + endDate + "'";
		}
		sql = sql.replace("#something#", sql1);
		return this.getData(sql);
	}

	/***
	 * 查询探伤、表检报告
	 * 
	 * @param contractNO
	 * @param judgeStoveNo
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject getMilTestReport(String contractNO,
			String judgeStoveNo, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilTestReport");
		String sql1 = "";
		if (!contractNO.equals("")) {
			sql1 += " AND A.PRO_ORDER_NO LIKE '%" + contractNO + "%' ";
		}
		if (!judgeStoveNo.equals("")) {
			sql1 += " AND A.judge_stove_no LIKE '%" + judgeStoveNo + "%' ";
		}
		sql1 += CoreConverter.toSqlConditionString("A.PLINE_CODE", plineCodes);
		sql = sql.replace("#something#", sql1);
		return this.getData(sql);
	}

	/***
	 * 
	 * 关闭炉计划
	 * 
	 * @param parm
	 * @return
	 * @throws SQLException
	 */
	public CoreReturnObject closeMilPlan(ArrayList<String> parm)
			throws SQLException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String isClose = "";// 炉计划状态
		ArrayList<String> sqllist = new ArrayList<String>();
		int qx = 0;
		String takeNum = "";// 脱单支数
		for (String str : parm) {
			MilProcessesEntity milProcessTity = EntityTool.getEntityByJSONStr(
					str, MilProcessesEntity.class);
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.getMilPlanIsClose");
			sql = EntityTool.fillSqlByEntity(sql, milProcessTity);
			psta = connection.prepareStatement(sql);
			rs = psta.executeQuery();
			if (rs.next()) {
				isClose = rs.getString("ISCLOSE");
			}
			rs.close();
			psta.close();
			if (isClose.equals("1")) {
				cro.setV_errMsg("炉计划信息已关闭,不允许重复关闭!");
				return cro;
			}

			// 预计产出支 - 热轧剔除支 - 精整剔除支 - 委外废品支 - 离线支 + 返线支 - 下线支【结炉】-脱单支

			// 查询进程数据
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.getMilPlanProcessData");
			sql = EntityTool.fillSqlByEntity(sql, milProcessTity);
			psta = connection.prepareStatement(sql);
			rs = psta.executeQuery();
			List<MilProcessesEntity> milProTity = EntityTool.getEntitysByRs(rs,
					MilProcessesEntity.class);
			rs.close();
			psta.close();
			// 查询脱单支数
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.getTakeNum");
			sql = EntityTool.fillSqlByEntity(sql, milProcessTity);
			psta = connection.prepareStatement(sql);
			rs = psta.executeQuery();
			if (rs.next()) {
				takeNum = rs.getString("TAKE_NUM");
			}
			rs.close();
			psta.close();

			if (milProTity != null) {
				qx = Integer.parseInt(milProTity.get(0).getYjz())
						- Integer.parseInt(milProTity.get(0)
								.getUndeterminednum())
						- Integer.parseInt(milProTity.get(0).getScrapnum())
						- Integer.parseInt(milProTity.get(0).getWwfpz())
						- Integer.parseInt(milProTity.get(0).getLxz())
						+ Integer.parseInt(milProTity.get(0).getFxz())
						- Integer.parseInt(milProTity.get(0).getHgz12())
						- Integer.parseInt(takeNum);
				if (qx != 0) {
					cro.setV_errMsg("该炉'" + milProcessTity.getJudgeStoveNo()
							+ "'支数不平衡，不能关闭炉计划!");
					return cro;
				}
			}
			milProcessTity.setIsclose("1");
			String updateCloseSql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.updateIsClose");
			updateCloseSql = EntityTool.fillSqlByEntity(updateCloseSql,
					milProcessTity);
			sqllist.add(updateCloseSql);

		}
		this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
		cro.setV_errMsg("关闭炉计划成功!");
		return cro;
	}

	/**
	 * 查询加工线前工序紧急放行数据
	 * 
	 * @param PROCESS_CODE
	 *            工序代码
	 * @return
	 */
	public CoreReturnObject doQueryQcmZgApplyData(String judgeNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.doQueryQcmZgApplyData");
		return this.getData(sql, new Object[] { judgeNo });
	}

	/***
	 * 撤销关闭炉计划
	 * 
	 * @param parm
	 * @return
	 * @throws SQLException
	 */
	public CoreReturnObject cancelCloseMilPlan(ArrayList<String> parm)
			throws SQLException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String isClose = "";// 炉计划状态
		ArrayList<String> sqllist = new ArrayList<String>();
		for (String str : parm) {
			MilProcessesEntity milProcessTity = EntityTool.getEntityByJSONStr(
					str, MilProcessesEntity.class);
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.getMilPlanIsClose");
			sql = EntityTool.fillSqlByEntity(sql, milProcessTity);
			psta = connection.prepareStatement(sql);
			rs = psta.executeQuery();
			if (rs.next()) {
				isClose = rs.getString("ISCLOSE");
			}
			rs.close();
			psta.close();
			if (isClose.equals("0")) {
				cro.setV_errMsg("炉计划信息未关闭,不允许撤销!");
				return cro;
			}
			milProcessTity.setIsclose("0");
			String updateCloseSql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.updateIsClose");
			updateCloseSql = EntityTool.fillSqlByEntity(updateCloseSql,
					milProcessTity);
			sqllist.add(updateCloseSql);
		}
		this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
		cro.setV_errMsg("撤销成功!");
		return cro;
	}

	/**
	 * 刷新
	 * @param parm
	 * @return
	 * @throws SQLException
	 */
	public CoreReturnObject doRefresh(ArrayList<String> parm)
			throws SQLException {
		CoreReturnObject cro = new CoreReturnObject();
		ArrayList<String> sqllist = new ArrayList<String>();
		String updateCloseSql = CoreXmlSqlParsersFactory
		.getSql("FrmMilDateStatistics.doRefresh");
		String sql = "";
		for (String str : parm) {
			MilProcessesEntity milProcessTity = EntityTool.getEntityByJSONStr(
					str, MilProcessesEntity.class);
			sql += milProcessTity.getJudgeStoveNo() + "','";
		}
		updateCloseSql = updateCloseSql.replace("#JUDGE_STOVE_NO#", sql);
		//this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
		this.setData(updateCloseSql);
		cro.setV_errMsg("刷新成功!");
		return cro;
	}

	/**
	 * 保存轧管待判原因
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject saveMilDateWaitingDecision(ArrayList<ArrayList> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		ArrayList<String> sqlIdList = new ArrayList<String>();// 存放执行语句
		ArrayList<Object[]> params = new ArrayList<Object[]>();// 存放参数

		for (ArrayList<String> aList : parm) {
			sqlIdList.add("FrmMilDateStatistics.saveMilDateWaitingDecision");
			params.add(aList.toArray());
		}
		cro = this.setDataById(sqlIdList, params);
		return cro;
	}

	/**
	 * 查加工部的厂
	 * 
	 * @return
	 */
	public CoreReturnObject doQueryFactory() {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.doQueryFactory");
		return this.getData(sql, new Object[] {});
	}

	/**
	 * 查产线
	 * 
	 * @param PROCESS_CODE
	 *            工序代码
	 * @return
	 */
	public CoreReturnObject doQueryPlineCode(String PROCESS_CODE) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.doQueryPlineCode");
		return this.getData(sql, new Object[] { PROCESS_CODE });
	}

	/**
	 * 查产线
	 * 
	 * @param PROCESS_CODE
	 * @return
	 */
	public CoreReturnObject JudgeBaseInfo(String PROCESS_CODE) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.JudgeBaseInfo");
		return this.getData(sql, new Object[] { PROCESS_CODE });
	}

	/**
	 * 查产线
	 * 
	 * @param PROCESS_CODE
	 *            工序代码
	 * @param arr
	 *            数据权限
	 * @return
	 */
	public CoreReturnObject doQueryPlineCode(String PROCESS_CODE, String[] arr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.doQueryPlineCode");
		for (int i = 0; i < arr.length; i++) {
			if (arr.length > 1) {
				if (i == 0) {
					sql += " AND (DEPARTMENT_CODE LIKE '%" + arr[i] + "%'";
				} else if (i == arr.length - 1) {
					sql += " OR DEPARTMENT_CODE LIKE '%" + arr[i] + "%')";
				} else {
					sql += " OR DEPARTMENT_CODE LIKE '%" + arr[i] + "%'";
				}
			} else {
				sql += " AND DEPARTMENT_CODE LIKE '%" + arr[i] + "%'";
			}
		}
		return this.getData(sql, new Object[] { PROCESS_CODE });
	}

	/**
	 * 查询各工序按炉跟踪数据
	 * 
	 * @param date
	 * @param endDate
	 * @param judgeStoveNo
	 * @param lotNo
	 * @param contractNo
	 * @param pline
	 * @param process
	 *            工序代码
	 * @return
	 */
	public CoreReturnObject getFrmBcDateWaitingDecision(String date,
			String endDate, String judgeStoveNo, String lotNo,
			String contractNo, String pline, String process, String validFlag,
			String IsVisible, String Factory) {

		String sql = "";
		String sql1 = "";
		String sql2 = "";
		String sql3 = "";
		if (process.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.SelectVrpWaitingDecision");
		} else if (process.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.SelectHttWaitingDecision");
		} else if (process.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.SelectMchWaitingDecision");
		}

		if (!date.equals("")) {
			sql1 = " AND T1.LOAD_TIME BETWEEN TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
			sql = sql.replace("#LOAD_TIME#", sql1);
		} else {
			sql = sql.replace("#LOAD_TIME#", "");
		}
		if (!judgeStoveNo.equals("")) {
			sql2 += "  AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "' ";
		}
		if (!lotNo.equals("")) {
			sql2 += " AND T.ZY_BATCH_ID = '" + lotNo + "' ";
		}
		if (!contractNo.equals("")) {
			sql2 += " AND T.ORDER_NO || '/' || T.ORDER_SEQ LIKE '%"
					+ contractNo + "%' ";
		}
		if (!pline.equals("")) {
			sql2 += " AND T.PLINE_CODE IN ('" + pline + "') ";
		}
		if (!IsVisible.equals("")) {
			sql2 += " AND T.IS_VISIBLE = '" + IsVisible + "' ";
		}
		if (!Factory.equals("")) {
			sql2 += " AND T.PLINE_CODE IN (select C.PLINE_CODE from COM_BASE_PLINE C WHERE C.FACTORY_CODE IN ('"
					+ Factory + "')) ";
		}
		sql = sql.replace("#SOMETHING#", sql2);
		if (!validFlag.equals("")) {
			if (validFlag.equals("20")) {
				sql3 += " AND VALIDFLAG = '通过' ";
			} else {
				sql3 += " AND VALIDFLAG IS NULL ";
			}
		}
		sql3 += " ORDER BY TIME_C DESC ";
		sql = sql.replace("#VALIDFLAG#", sql3);
		return this.getData(sql);
	}

	/**
	 * 保存各工序待判原因
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject saveFrmBcDateWaitingDecision(
			ArrayList<ArrayList> parm, String process) {
		CoreReturnObject cro = new CoreReturnObject();
		ArrayList<String> sqlIdList = new ArrayList<String>();// 存放执行语句
		ArrayList<Object[]> params = new ArrayList<Object[]>();// 存放参数
		for (ArrayList<String> aList : parm) {
			if (process.equals("E")) {
				sqlIdList.add("FrmMilDateStatistics.saveVrpWaitingDecision");
				params.add(aList.toArray());
			} else if (process.equals("F")) {
				sqlIdList.add("FrmMilDateStatistics.saveHttWaitingDecision");
				params.add(aList.toArray());
			} else if (process.equals("G")) {
				sqlIdList.add("FrmMilDateStatistics.saveMchWaitingDecision");
				params.add(aList.toArray());
			}
		}
		cro = this.setDataById(sqlIdList, params);
		return cro;
	}

	/**
	 * 查询各工序成材率
	 * 
	 * @param BAL_YEAR_MONTH
	 * @param judgeStoveNo
	 * @param pline
	 * @param process
	 * @return
	 */
	public CoreReturnObject getMilStaProductRate(String BAL_YEAR_MONTH,
			String judgeStoveNo, String plineCode, String[] plineCodes,
			String process) {

		String sql = "";
		String sql2 = "";
		if (process.equals("D")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.getMilStaProductRateZG");
			/*
			 * } else if(process.equals("E")) { sql = CoreXmlSqlParsersFactory
			 * .getSql("FrmMilDateStatistics.getMilStaProductRateDBK");
			 */
		} else {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.getMilStaProductRateBCNew2");
			if (process.equals("E")) {
				sql = sql.replace("#TABLE#", "PLN_ZY_DBK_M").replace(
						"#TABLE2#", "PORT_VRP_BATCH_SAMPLE_RESULT").replace(
						"#SOMETHING1#", " AND T3.VALIDFLAG = '1'");
			} else if (process.equals("F")) {
				sql = sql.replace("#TABLE#", "PLN_ZY_RCL_M").replace(
						"#TABLE2#", "PORT_HTT_BATCH_SAMPLE_RESULT").replace(
						"#SOMETHING1#", " ");
			} else if (process.equals("G")) {
				sql = sql.replace("#TABLE#", "PLN_ZY_JGX_M").replace(
						"#TABLE2#", "PORT_MCH_BATCH_SAMPLE_RESULT").replace(
						"#SOMETHING1#", " AND T3.VALIDFLAG = '1'");
			}
		}
		if (!BAL_YEAR_MONTH.equals("")) {
			sql2 = " AND T.BAL_YEAR_MONTH >= '" + BAL_YEAR_MONTH + "' ";
		}
		if (!judgeStoveNo.equals("")) {
			sql2 += "  AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "' ";
		}
		if (!process.equals("")) {
			sql2 += "  AND T.PROCESS_CODE = '" + process + "' ";
		}
		if (!plineCode.equals("")) {
			sql2 += "  AND T.PLINE_CODE = '" + plineCode + "' ";
		}
		sql2 += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql = sql.replace("#SOMETHING#", sql2);
		return this.getData(sql);
	}

	/**
	 * 回报成材率
	 * 
	 * @param listAll
	 * @return
	 */
	public CoreReturnObject updateMilStaProductRate(
			ArrayList<ArrayList> listAll, String process) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sql1 = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.updateMilStaProductRate");
			if (process.equals("D")) {
				sql1 = sql1.replace("#TABLE#", "SLM_BASE_MATERIAL_D_PL");
			} else if (process.equals("E")) {
				sql1 = sql1.replace("#TABLE#", "SLM_BASE_MATERIAL_E_PL");
			} else if (process.equals("F")) {
				sql1 = sql1.replace("#TABLE#", "SLM_BASE_MATERIAL_F_PL");
			} else if (process.equals("G")) {
				sql1 = sql1.replace("#TABLE#", "SLM_BASE_MATERIAL_K_PL");
			}
			PreparedStatement updateMilControlLog = connection
					.prepareStatement(sql1);
			for (ArrayList<String> list : listAll) {
				updateMilControlLog.setString(1, list.get(0));
				updateMilControlLog.setString(2, list.get(1));
				updateMilControlLog.setString(3, list.get(2));
				updateMilControlLog.setString(4, list.get(3));
				updateMilControlLog.setString(5, list.get(4));
				updateMilControlLog.addBatch();
			}
			updateMilControlLog.executeBatch();
			connection.commit();
			cro.setV_errMsg("回报成功!");
		} 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 JudgeStoveNo
	 * @param LotNo
	 * @param ContractNo
	 * @return
	 */
	public CoreReturnObject InspectionReportGoDown(String judgeStoveNo,
			String lotNo, String contractNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.InspectionReportGoDown");
		if (!judgeStoveNo.equals("")) {
			sql += "  AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "' ";
		}
		if (!lotNo.equals("")) {
			sql += " AND T.LOT_NO = '" + lotNo + "' ";
		}
		if (!contractNo.equals("")) {
			sql += " AND T.ORDER_NO LIKE '%" + contractNo + "%' ";
		}
		sql += " ORDER BY T.CREATE_TIME";
		return this.getData(sql);
	}

	/**
	 * 查询小时能力（镦拔扩、热处理、加工）
	 * 
	 * @param BAL_YEAR_MONTH
	 * @param pline
	 * @param process
	 * @return
	 */
	public CoreReturnObject getBcControlLog(String BAL_YEAR_MONTH,
			String pline, String process) {

		String sql = "";
		String sql2 = "";

		sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getBcControlLog");
		if (process.equals("E")) {
			sql = sql.replace("#TABLE#", "PLN_ZY_DBK_M");
		} else if (process.equals("F")) {
			sql = sql.replace("#TABLE#", "PLN_ZY_RCL_M");
		} else if (process.equals("G")) {
			sql = sql.replace("#TABLE#", "PLN_ZY_JGX_M");
		}
		if (!BAL_YEAR_MONTH.equals("")) {
			sql2 = " AND T.BAL_YEAR_MONTH >= '" + BAL_YEAR_MONTH + "' ";
		}
		if (!pline.equals("")) {
			sql2 += " AND T.PLINE_CODE IN ('" + pline + "') ";
		}
		sql = sql.replace("#SOMETHING#", sql2);
		return this.getData(sql);
	}

	/**
	 * 回报小时能力（镦拔扩、热处理、加工）
	 * 
	 * @param listAll
	 * @param process
	 * @return
	 */
	public CoreReturnObject updateBcControlLog(ArrayList<ArrayList> listAll,
			String process) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sql1 = CoreXmlSqlParsersFactory
					.getSql("FrmMilDateStatistics.updateBcControlLog");
			if (process.equals("D")) {
				sql1 = sql1.replace("#TABLE#", "SLM_BASE_MATERIAL_D_PL");
			} else if (process.equals("E")) {
				sql1 = sql1.replace("#TABLE#", "SLM_BASE_MATERIAL_E_PL");
			} else if (process.equals("F")) {
				sql1 = sql1.replace("#TABLE#", "SLM_BASE_MATERIAL_F_PL");
			} else if (process.equals("G")) {
				sql1 = sql1.replace("#TABLE#", "SLM_BASE_MATERIAL_K_PL");
			}
			PreparedStatement updateMilControlLog = connection
					.prepareStatement(sql1);
			for (ArrayList<String> list : listAll) {
				updateMilControlLog.setString(1, list.get(0));
				updateMilControlLog.setString(2, list.get(1));
				updateMilControlLog.setString(3, list.get(2));
				updateMilControlLog.setString(4, list.get(3));
				updateMilControlLog.setString(5, list.get(4));
				updateMilControlLog.addBatch();
			}
			updateMilControlLog.executeBatch();
			connection.commit();
			cro.setV_errMsg("回报成功!");
		} 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 date
	 * @param endDate
	 * @param pline
	 * @return
	 */
	public CoreReturnObject getMilInitalZg(String date, String endDate,
			String pline, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilInitalZg");
		if (!date.equals("")) {
			sql += " AND T.BAL_YEAR_MONTH BETWEEN'" + date + "' and '"
					+ endDate + "'";
		}
		if (!pline.equals("")) {
			sql += " AND T.PLINE_CODE = '" + pline + "' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql += " ORDER BY T.BAL_YEAR_MONTH DESC,T.PLINE_CODE,t.judge_stove_no ";
		return this.getData(sql);
	}

	/**
	 * 查询加工线计划
	 * 
	 * @param date
	 * @param endDate
	 * @param judgeStoveNo
	 * @return
	 */
	public CoreReturnObject doQueryZyJgxM(String date, String endDate,
			String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.doQueryZyJgxM");
		if (!date.equals("")) {
			sql += " AND T1.CREATE_TIME BETWEEN TO_DATE('" + date
					+ "' ,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('" + endDate
					+ "' ,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!judgeStoveNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "' ";
		}
		sql += " ORDER BY T.PLINE_CODE,T1.CREATE_TIME ";
		return this.getData(sql);
	}

	/**
	 * 查询加工线进程表
	 * 
	 * @param heatPlanNo
	 * @return
	 */
	public CoreReturnObject doQueryPortMchBatchSampleResult(String heatPlanNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.doQueryPortMchBatchSampleResult");
		sql += " AND T.HEAT_PLAN_NO = '" + heatPlanNo + "' ";
		return this.getData(sql);
	}
	
	/**
	 * 查询天淮表检缺项数据
	 * @param date
	 * @param endDate
	 * @return
	 */
	public CoreReturnObject getMilCheckDeatilSimple(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmMilDateStatistics.getMilCheckDeatilSimple");
		if (!judgeStoveNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO LIKE  '" + judgeStoveNo + "%' ";
		}
		return this.getData(sql);
	}
	
	/**
	 * 修改天淮表检缺项数据
	 * @param list
	 * @return
	 */
	public CoreReturnObject doUpdateMilCheckDeatilSimple(ArrayList<String> list)
    {
    	CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            ArrayList<String> sqllist = new ArrayList<String>();
         for(String str:list)   
         {
        	 MilCheckDeatilSimpleEntity httEntity = EntityTool.getEntityByJSONStr(str, MilCheckDeatilSimpleEntity.class);
        	 String insertBcSql = CoreXmlSqlParsersFactory.getSql("FrmMilDateStatistics.doUpdateMilCheckDeatilSimple");
			    insertBcSql = EntityTool.fillSqlByEntity(insertBcSql, httEntity);
			    sqllist.add(insertBcSql);
         }
         core = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
         if(core.getV_errMsg().equals(""))
         {
            core.setV_errMsg("修改成功！");
         }
        }
        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;
    }

}
