package com.steering.mes.mcp.Report;

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.converter.QualityDesignTool;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;
import com.steering.mes.mcp.entity.HttControlLogDetailEntity;
import com.steering.mes.mcp.entity.HttControlLogEntity;
import com.steering.mes.mcp.entity.HttControlShiftEntity;
import com.steering.mes.mcp.entity.SlmBaseMaterialFPlEntity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class FrmHttControlLog extends DBCommon {

	/***
	 * 查询镦拔扩日志表
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 *            当天
	 * @param endTim
	 *            前一天
	 * @return
	 */
	public CoreReturnObject doQueryPlan(String startTim, String endTim,
			String bc, String bz, String plineCode, String station) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryPlan");
		if (!bc.equals("")) {
			sql += "  AND T.PRO_BC ='" + bc + "'";
		}

		if (!startTim.equals("")) {
			sql += "  AND T.PROC_DATE ='" + startTim + "'";
		}

		if (!plineCode.equals("")) {
			sql += "  AND T.PLINE_CODE ='" + plineCode + "'";
		}
		if (!station.equals("")) {
			sql += " AND T.STATION ='" + station + "'";
		}
		sql += " ORDER BY T.LOGS_BEG,T.LOGS_END ASC";
		return this.getData(sql);
	}

	/***
	 * 查询镦拔扩日志表
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 *            当天
	 * @param endTim
	 *            前一天
	 * @return
	 */
	public CoreReturnObject doQueryPlanNew(String startTim,
			String BAL_YEAR_MONTH, String plineCode, String station) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryPlan");

		if (!startTim.equals("")) {
			sql += "  AND T.PROC_DATE ='" + startTim + "'";
		}

		if (!plineCode.equals("")) {
			sql += "  AND T.PLINE_CODE ='" + plineCode + "'";
		}
		if (!station.equals("")) {
			sql += "  AND T.STATION ='" + station + "'";
		}
		if (!BAL_YEAR_MONTH.equals("")) {
		sql += " AND ("+BAL_YEAR_MONTH+"-1||25 <T.PROC_DATE and T.PROC_DATE <"+BAL_YEAR_MONTH+"||26 ) ";
		}
		sql += " ORDER BY T.LOGS_BEG,T.LOGS_END ASC";
		return this.getData(sql);
	}

	/***
	 * 查询镦拔扩日志表
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 *            当天
	 * @param endTim
	 *            前一天
	 * @return
	 */
	public CoreReturnObject doQueryTotal(String balYearMonth, String day,
			String plineCode) {

		return this.getDataBySqlID("FrmHttControlLog.doQueryTotal",
				new Object[] { balYearMonth, plineCode, balYearMonth, day, day,
						plineCode, balYearMonth, day, day, plineCode });
	}

	/***
	 * 查询热处理调度生产数据汇总
	 */
	public CoreReturnObject doQueryControlLogProTotal(String startTim,
			String endTim, String[] plineCode, String CONTRACT_NO,
			String JUDGE_STOVE_NO, String bc, String bz) {
		return doQueryControlLogProTotal(startTim, endTim, plineCode,
				CONTRACT_NO, JUDGE_STOVE_NO, bc, bz, "");
	}

	/***
	 * 查询热处理调度生产数据汇总
	 */
	public CoreReturnObject doQueryControlLogProTotal(String startTim,
			String endTim, String[] plineCode, String CONTRACT_NO,
			String JUDGE_STOVE_NO, String bc, String bz, String ProStation) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryControlLogProTotal");
		if (!startTim.equals("")) {
			sql += " AND T.PROC_DATE >='" + startTim + "' ";
		}

		if (!endTim.equals("")) {
			sql += " AND T.PROC_DATE <='" + endTim + "' ";
		}

		if (!CONTRACT_NO.equals("")) {
			sql += "  AND T.CONTRACT_NO ='" + CONTRACT_NO + "'";
		}

		if (!JUDGE_STOVE_NO.equals("")) {
			sql += "  AND T.CONTRACT_NO ='" + JUDGE_STOVE_NO + "'";
		}

		if (!bc.equals("")) {
			sql += "  AND T.PRO_BC ='" + bc + "'";
		}

		if (!bz.equals("")) {
			sql += "  AND T.PRO_BZ ='" + bz + "'";
		}

		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);

		if (!ProStation.equals("")) {

			sql += " AND T.PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE FACTORY_CODE = '"
					+ ProStation + "')";
		}

		sql += " ORDER BY T.PLINE_CODE,t.LOGS_BEG";
		return this.getData(sql);
	}

	/***
	 * 查询热处理调度生产数据汇总
	 */
	public CoreReturnObject doQueryControlLogProTotal(String startTim,
			String endTim, String[] plineCode, String CONTRACT_NO,
			String JUDGE_STOVE_NO, String bc, String bz, String[] ProStation, String station) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryControlLogProTotal");
		if (!startTim.equals("")) {
			sql += " AND T.PROC_DATE >='" + startTim + "' ";
		}

		if (!endTim.equals("")) {
			sql += " AND T.PROC_DATE <='" + endTim + "' ";
		}

		if (!CONTRACT_NO.equals("")) {
			sql += "  AND T.CONTRACT_NO ='" + CONTRACT_NO + "'";
		}

		if (!JUDGE_STOVE_NO.equals("")) {
			sql += "  AND T.CONTRACT_NO ='" + JUDGE_STOVE_NO + "'";
		}

		if (!bc.equals("")) {
			sql += "  AND T.PRO_BC ='" + bc + "'";
		}

		if (!bz.equals("")) {
			sql += "  AND T.PRO_BZ ='" + bz + "'";
		}
		if (!station.equals("")) {
			sql += "  AND T.STATION ='" + station + "'";
		}

		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);

		if (ProStation.length > 0) {

			sql += " AND T.PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE 1=1  "
					+ CoreConverter.toSqlConditionString("FACTORY_CODE",
							ProStation) + ")";
		}

		sql += " ORDER BY T.PLINE_CODE,t.LOGS_BEG";
		return this.getData(sql);
	}

	/***
	 * 查询加工线调度生产数据汇总
	 * 
	 */
	public CoreReturnObject doQueryControlLogProTotalG(String startTim,
			String endTim, String[] plineCode, String CONTRACT_NO,
			String JUDGE_STOVE_NO, String bc, String bz, String station) {
		return doQueryControlLogProTotalG(startTim, endTim, plineCode,
				CONTRACT_NO, JUDGE_STOVE_NO, bc, bz, "",station);
	}

	/***
	 * 查询加工线调度生产数据汇总
	 * 
	 */
	public CoreReturnObject doQueryControlLogProTotalG(String startTim,
			String endTim, String[] plineCode, String CONTRACT_NO,
			String JUDGE_STOVE_NO, String bc, String bz, String ProStation, String station) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryControlLogProTotalG");
		if (!startTim.equals("")) {
			sql += " AND T.PROC_DATE >='" + startTim + "' ";
		}

		if (!endTim.equals("")) {
			sql += " AND T.PROC_DATE <='" + endTim + "' ";
		}

		if (!CONTRACT_NO.equals("")) {
			sql += "  AND T.CONTRACT_NO ='" + CONTRACT_NO + "'";
		}

		if (!JUDGE_STOVE_NO.equals("")) {
			sql += "  AND T.CONTRACT_NO ='" + JUDGE_STOVE_NO + "'";
		}

		if (!bc.equals("")) {
			sql += "  AND T.PRO_BC ='" + bc + "'";
		}

		if (!bz.equals("")) {
			sql += "  AND T.PRO_BZ ='" + bz + "'";
		}
		if (!station.equals("")) {
			sql += "  AND T.STATION ='" + station + "'";
		}

		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);

		if (!ProStation.equals("")) {

			sql += " AND T.PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE FACTORY_CODE = '"
					+ ProStation + "')";
		}

		sql += " ORDER BY T.PLINE_CODE,t.LOGS_BEG";
		return this.getData(sql);
	}

	/***
	 * 查询加工线调度生产数据汇总
	 * 
	 */
	public CoreReturnObject doQueryControlLogProTotalG(String startTim,
			String endTim, String[] plineCode, String CONTRACT_NO,
			String JUDGE_STOVE_NO, String bc, String bz, String[] ProStation, String station) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryControlLogProTotalG");
		if (!startTim.equals("")) {
			sql += " AND T.PROC_DATE >='" + startTim + "' ";
		}

		if (!endTim.equals("")) {
			sql += " AND T.PROC_DATE <='" + endTim + "' ";
		}

		if (!CONTRACT_NO.equals("")) {
			sql += "  AND T.CONTRACT_NO ='" + CONTRACT_NO + "'";
		}

		if (!JUDGE_STOVE_NO.equals("")) {
			sql += "  AND T.JUDGE_STOVE_NO ='" + JUDGE_STOVE_NO + "'";
		}

		if (!bc.equals("")) {
			sql += "  AND T.PRO_BC ='" + bc + "'";
		}

		if (!bz.equals("")) {
			sql += "  AND T.PRO_BZ ='" + bz + "'";
		}
		if (!station.equals("")) {
			sql += "  AND T.STATION ='" + station + "'";
		}

		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);

		if (ProStation.length > 0) {

			sql += " AND T.PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE 1=1  "
					+ CoreConverter.toSqlConditionString("FACTORY_CODE",
							ProStation) + ")";
		}

		sql += " ORDER BY T.PLINE_CODE,t.LOGS_BEG";
		return this.getData(sql);
	}

	/***
	 * 查询热处理调停机
	 * 
	 */
	public CoreReturnObject doQueryControlLogStopTotal(String startTim,
			String endTim, String[] plineCode, String bc, String bz, String station) {
		return doQueryControlLogStopTotal(startTim, endTim, plineCode, bc, bz,
				"",station);
	}

	/***
	 * 查询热处理调停机
	 * 
	 */
	public CoreReturnObject doQueryControlLogStopTotal(String startTim,
			String endTim, String[] plineCode, String bc, String bz,
			String ProStation, String station) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryControlLogStopTotal");
		if (!startTim.equals("")) {
			sql += " AND T.PROC_DATE >='" + startTim + "' ";
		}

		if (!endTim.equals("")) {
			sql += " AND T.PROC_DATE <='" + endTim + "' ";
		}

		if (!bc.equals("")) {
			sql += "  AND T.PRO_BC ='" + bc + "'";
		}

		if (!bz.equals("")) {
			sql += "  AND T.PRO_BZ ='" + bz + "'";
		}
		if (!station.equals("")) {
			sql += "  AND T.STATION ='" + station + "'";
		}

		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);

		if (!ProStation.equals("")) {

			sql += " AND T.PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE FACTORY_CODE = '"
					+ ProStation + "')";
		}

		sql += " ORDER BY T.PLINE_CODE,T.PROC_DATE, T.LOGS_BEG";
		return this.getData(sql);
	}

	/***
	 * 查询热处理调停机
	 * 
	 */
	public CoreReturnObject doQueryControlLogStopTotal(String startTim,
			String endTim, String[] plineCode, String bc, String bz,
			String[] ProStation, String station) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryControlLogStopTotal");
		if (!startTim.equals("")) {
			sql += " AND T.PROC_DATE >='" + startTim + "' ";
		}

		if (!endTim.equals("")) {
			sql += " AND T.PROC_DATE <='" + endTim + "' ";
		}

		if (!bc.equals("")) {
			sql += "  AND T.PRO_BC ='" + bc + "'";
		}

		if (!bz.equals("")) {
			sql += "  AND T.PRO_BZ ='" + bz + "'";
		}
		if (!station.equals("")) {
			sql += "  AND T.STATION ='" + station + "'";
		}

		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);

		if (ProStation.length > 0) {

			sql += " AND T.PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE 1=1  "
					+ CoreConverter.toSqlConditionString("FACTORY_CODE",
							ProStation) + ")";
		}

		sql += " ORDER BY T.PLINE_CODE,T.PROC_DATE, T.LOGS_BEG";
		return this.getData(sql);
	}

	/***
	 * 查询热处理调度生产数据汇总
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 *            当天
	 * @param endTim
	 *            前一天
	 * @return
	 */
	public CoreReturnObject doQueryShiftInfo(String PlineCode, String bc) {

		return this.getDataBySqlID("FrmHttControlLog.doQueryShiftInfo",
				new Object[] { PlineCode, bc });
	}

	/***
	 * 查询热处理调度生产数据汇总
	 */
	public CoreReturnObject doQueryControlHours(String ProDate,
			String[] plineCode) {
		return doQueryControlHours(ProDate, plineCode, "");
	}

	/***
	 * 查询热处理调度生产数据汇总
	 * 
	 */
	public CoreReturnObject doQueryControlHoursG(String ProDate,
			String[] plineCode) {
		return doQueryControlHoursG(ProDate, plineCode, "");
	}

	/***
	 * 查询热处理调度生产数据汇总
	 */
	public CoreReturnObject doQueryControlHours(String ProDate,
			String[] plineCode, String ProStation) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryControlHours");

		String where = "";

		if (!ProDate.equals("")) {
			where += " AND T.BAL_YEAR_MONTH ='" + ProDate + "' ";
		}

		where += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);

		if (!ProStation.equals("")) {

			where += " AND T.PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE FACTORY_CODE = '"
					+ ProStation + "')";
		}

		sql = sql.replace("#WHERE#", where);

		return this.getData(sql);
	}

	/***
	 * 查询热处理调度生产数据汇总
	 */
	public CoreReturnObject doQueryControlHours(String ProDate,
			String[] plineCode, String[] ProStation) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryControlHours");

		String where = "";

		if (!ProDate.equals("")) {
			where += " AND T.BAL_YEAR_MONTH ='" + ProDate + "' ";
		}

		where += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);

		if (ProStation.length > 0) {

			where += " AND T.PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE 1=1  "
					+ CoreConverter.toSqlConditionString("FACTORY_CODE",
							ProStation) + ")";
		}

		sql = sql.replace("#WHERE#", where);

		return this.getData(sql);
	}

	/***
	 * 查询热处理调度生产数据汇总
	 * 
	 */
	public CoreReturnObject doQueryControlHoursG(String ProDate,
			String[] plineCode, String ProStation) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryControlHoursG");

		String where = "";

		if (!ProDate.equals("")) {
			where += " AND T.BAL_YEAR_MONTH ='" + ProDate + "' ";
		}

		where += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);

		if (!ProStation.equals("")) {

			where += " AND T.PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE FACTORY_CODE = '"
					+ ProStation + "')";
		}

		sql = sql.replace("#WHERE#", where);

		return this.getData(sql);
	}

	public CoreReturnObject doQueryControlHoursG(String ProDate,
			String[] plineCode, String[] ProStation) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryControlHoursG");

		String where = "";

		if (!ProDate.equals("")) {
			where += " AND T.BAL_YEAR_MONTH ='" + ProDate + "' ";
		}

		where += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);

		if (ProStation.length > 0) {

			where += " AND T.PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE 1=1  "
					+ CoreConverter.toSqlConditionString("FACTORY_CODE",
							ProStation) + ")";
		}

		sql = sql.replace("#WHERE#", where);

		return this.getData(sql);
	}

	/**
	 * 查询镦拔扩日志表
	 * 
	 * @param ResultNo
	 *            实绩号
	 * @return
	 */
	public CoreReturnObject doQueryDetail(String ResultNo) {
		return this.getDataBySqlID("FrmHttControlLog.doQueryDetail",
				new Object[] { ResultNo });
	}

	/**
	 * 查询镦拔扩日志表
	 * 
	 * @param ResultNo
	 *            实绩号
	 * @return
	 */
	public CoreReturnObject doQueryDetail1(String ResultNo) {
		return this.getDataBySqlID("FrmHttControlLog.doQueryDetail1",
				new Object[] { ResultNo });
	}

	/**
	 * 查询镦拔扩日志表
	 * 
	 * @param con
	 * @param ControlID
	 * @return
	 * @throws SQLException
	 */
	public static HttControlLogEntity getHttControlByID(Connection con,
			String ControlID) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryPlanById");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, ControlID);
		ResultSet rs = ps.executeQuery();
		List<HttControlLogEntity> HttControlLogEntitys = EntityTool
				.getEntitysByRs(rs, HttControlLogEntity.class);
		rs.close();
		ps.close();
		if (HttControlLogEntitys == null || HttControlLogEntitys.size() == 0) {
			return null;
		} else {
			for (HttControlLogEntity HttControlLogEntity : HttControlLogEntitys) {
				QualityDesignTool.nullConverNullString(HttControlLogEntity);
			}
			return HttControlLogEntitys.get(0);
		}
	}

	/**
	 * 查询镦拔扩日志表
	 * 
	 * @param con
	 * @param ControlID
	 * @return
	 * @throws SQLException
	 */
	public static List<HttControlLogEntity> getHttControl(Connection con,
			String[] ControlID) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryPlan2");
		sql += CoreConverter.toSqlConditionString("T.CONTROL_ID", ControlID);
		sql += " ORDER  BY LOGS_BEG";
		PreparedStatement ps = con.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		List<HttControlLogEntity> HttControlLogEntitys = EntityTool
				.getEntitysByRs(rs, HttControlLogEntity.class);
		rs.close();
		ps.close();
		return HttControlLogEntitys;

	}

	public static HttControlShiftEntity getHttControlByID(Connection con,
			String PlineCode, String Bc) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryShiftInfo");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, PlineCode);
		ps.setObject(2, Bc);
		ResultSet rs = ps.executeQuery();
		List<HttControlShiftEntity> HttControlShiftEntitys = EntityTool
				.getEntitysByRs(rs, HttControlShiftEntity.class);
		rs.close();
		ps.close();
		if (HttControlShiftEntitys == null
				|| HttControlShiftEntitys.size() == 0) {
			return null;
		} else {
			for (HttControlShiftEntity HttControlShiftEntity : HttControlShiftEntitys) {
				QualityDesignTool.nullConverNullString(HttControlShiftEntity);
			}
			return HttControlShiftEntitys.get(0);
		}
	}

	/**
	 * 查询镦拔扩日志表
	 * 
	 * @param con
	 * @param ControlID
	 * @return
	 * @throws SQLException
	 */
	public static List<HttControlLogDetailEntity> getHttControlDetailByID(
			Connection con, String ControlID) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryDetail");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, ControlID);
		ResultSet rs = ps.executeQuery();
		List<HttControlLogDetailEntity> HttControlLogEntitys = EntityTool
				.getEntitysByRs(rs, HttControlLogDetailEntity.class);
		rs.close();
		ps.close();

		return HttControlLogEntitys;

	}

	public static List<HttControlLogEntity> getConflictHttContorlLog(
			Connection con, String plineCode, String Bc, String ProDate,
			String Beg, String End) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.getConflictHttContorlLog");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, plineCode);
		ps.setObject(2, Bc);
		ps.setObject(3, ProDate);
		ps.setObject(4, Beg);
		ps.setObject(5, End);
		ResultSet rs = ps.executeQuery();
		List<HttControlLogEntity> HttControlLogEntitys = EntityTool
				.getEntitysByRs(rs, HttControlLogEntity.class);
		rs.close();
		ps.close();

		return HttControlLogEntitys;

	}

	/***
	 * 查询镦拔扩日志表停机记录
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doStopQuery(String startTim, String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doStopQuery");
		if (!startTim.equals("")) {
			sql += " AND T.PROC_DATE='" + startTim + "'";
		}
		if (!plineCode.equals("")) {
			sql += "  AND T.PLINE_CODE ='" + plineCode + "'";
		}
		sql += " ORDER BY T.LOGS_BEG ASC";
		return this.getData(sql);
	}

	/***
	 * 查询调度生产运行停机时间
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doMinutesQuery(String startTim, String days) {
		String sql = "";
		try {
			int day = Integer.parseInt(days);
			sql += "SELECT";
			for (int i = 0; i < day; i++) {
				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
				Date strat;
				String systime = "";

				strat = dateFormat.parse(startTim + String.valueOf(i + 1));
				systime = dateFormat.format(strat);
				String dayd = "DAY" + String.valueOf(i + 1);
				sql += "  (SELECT NVL(SUM(CEIL((TO_DATE(T.LOGS_END, 'YYYY-MM-DD HH24:MI') - "
						+ "TO_DATE(T.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24*60)),0) SUMMINUTES "
						+ "FROM HTT_CONTROL_LOG T WHERE T.PROC_DATE = '"
						+ systime
						+ "'"
						+ " AND T.PLINE_CODE = T1.PLINE_CODE "
						+ " AND T.CONFIRM_FLAG = '1'  "
						+ " AND T.PRO_TYPE = '2') " + dayd + ",";
			}
			sql += " (SELECT T2.PLINE_NAME FROM COM_BASE_PLINE T2 "
					+ " WHERE T2.PLINE_CODE = T1.PLINE_CODE  "
					+ " AND T2.VALIDFLAG = '1') PLINE_NAME";
			sql += " FROM HTT_CONTROL_LOG T1  WHERE T1.BAL_YEAR_MONTH = '"
					+ startTim + "' "
					+ " AND T1.CONFIRM_FLAG = '1'  GROUP BY T1.PLINE_CODE";

			sql += " ORDER BY PLINE_NAME ASC";
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return this.getData(sql);
	}

	/***
	 * 查询调度生产运行停机时间
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doMinutesQueryNew(String startTim, String days,
			String[] PlineCode) {
		return doMinutesQueryNew(startTim, days, PlineCode, "");
	}

	/***
	 * 查询调度生产运行停机时间
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doMinutesQueryNew(String startTim, String days,
			String[] PlineCode, String ProStation) {
		String sql = "";
		try {
			int day = Integer.parseInt(days);

			String MTable = "SELECT * FROM COM_BASE_PLINE WHERE 1=1 ";
			MTable += CoreConverter.toSqlConditionString("PLINE_CODE",
					PlineCode);
			if (!ProStation.equals("")) {

				MTable += " AND PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE FACTORY_CODE = '"
						+ ProStation + "')";
			}

			sql += "SELECT";
			for (int i = 0; i < day; i++) {
				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
				Date strat;
				String systime = "";
				strat = dateFormat.parse(startTim + String.valueOf(i + 1));
				systime = dateFormat.format(strat);
				String dayd = "DAY" + String.valueOf(i + 1);
				sql += "  (SELECT NVL(SUM(CEIL((TO_DATE(T.LOGS_END, 'YYYY-MM-DD HH24:MI') - "
						+ "TO_DATE(T.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24*60)),0) SUMMINUTES "
						+ "FROM HTT_CONTROL_LOG T  WHERE 1=1 "
						+ "   AND T.PROC_DATE = '"
						+ systime
						+ "'"
						+ " AND T.PLINE_CODE = M.PLINE_CODE "
						+ " AND T.CONFIRM_FLAG = '1'  "
						+ " AND T.PRO_TYPE = '2') " + dayd + ",";

				sql += "  (SELECT  MIN(CONFIRM_FLAG) "
						+ "FROM HTT_CONTROL_LOG T  WHERE  1=1 "
						+ "   AND T.PROC_DATE = '" + systime + "'"
						+ " AND T.PLINE_CODE = M.PLINE_CODE) " + "FLAG" + dayd
						+ ",";
			}
			sql += " (SELECT T2.PLINE_NAME FROM COM_BASE_PLINE T2 "
					+ " WHERE T2.PLINE_CODE = M.PLINE_CODE  "
					+ " AND T2.VALIDFLAG = '1') PLINE_NAME,"
					+ " MAX(T3.TITLE) TITLE, "
					+ " MAX(T3.STOVE_NUM) STOVE_NUM, "
					+ " MAX(T3.PRO_NUM) PRO_NUM, " + " MAX(T3.PRO_WT) PRO_WT, "
					+ " MAX(T3.STOVE_STOP_TIME) STOVE_STOP_TIME, "
					+ " MAX(T3.STOP_TIME) STOP_TIME, "
					+ " MAX(T3.STOP_NORMAL) STOP_NORMAL, "
					+ " MAX(T3.STOP_ABNORMAL) STOP_ABNORMAL, "
					+ " MAX(T3.PRO_INCREMENT) PRO_INCREMENT, "
					+ " MAX(T3.TOTAL_TIME) TOTAL_TIME, " + "M.PLINE_CODE";

			sql += " FROM  ("
					+ MTable
					+ ") M LEFT JOIN  HTT_CONTROL_LOG T1  ON M.PLINE_CODE = T1.PLINE_CODE AND  T1.BAL_YEAR_MONTH = '"
					+ startTim + "' " + " AND T1.CONFIRM_FLAG = '1' ";

			sql += "LEFT JOIN (SELECT T.PLINE_CODE,  TO_CHAR(TO_DATE(T.BAL_YEAR_MONTH,'YYYYMM'),'MM') || '月--' || (SELECT PLINE_NAME FROM COM_BASE_PLINE WHERE PLINE_CODE =T.PLINE_CODE)  TITLE,\n"
					+ "       COUNT(DISTINCT JUDGE_STOVE_NO) STOVE_NUM,\n"
					+ "       NVL(SUM(QUALIFIED_NUM),0) PRO_NUM,\n"
					+ "       NVL(SUM(QUALIFIED_WT),0) PRO_WT,\n"
					+ "       NVL(SUM(DECODE(T.PROCESS_CODE_C,\n"
					+ "                      'B024',\n"
					+ "                      0,\n"
					+ "                      CEIL((TO_DATE(T.LOGS_END, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                           TO_DATE(T.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24 * 60))),\n"
					+ "           0) TOTAL_TIME,\n"
					+ "       NVL(SUM(DECODE(T.PRO_TYPE,\n"
					+ "                      '1',\n"
					+ "                      0,\n"
					+ "                      CEIL((TO_DATE(T.LOGS_END, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                           TO_DATE(T.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24 * 60))),\n"
					+ "           0) STOVE_STOP_TIME,\n"
					+ "       NVL(SUM(D.STOP_TIME),0) STOP_TIME,\n"
					+ "       NVL(SUM(D.STOP_NORMAL),0) STOP_NORMAL,\n"
					+ "       NVL(SUM(D.STOP_ABNORMAL),0) STOP_ABNORMAL,\n"
					+ "       \n"
					+ "       NVL((SELECT SUM(CEIL((TO_DATE(B.LOGS_END, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                           TO_DATE(B.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24 * 60) - CASE\n"
					+ "                        WHEN B.LOGS_BEG < S.LOGS_BEG THEN\n"
					+ "                         CEIL((TO_DATE(S.LOGS_BEG, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                              TO_DATE(B.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24 * 60)\n"
					+ "                        ELSE\n"
					+ "                         0\n"
					+ "                      END - CASE\n"
					+ "                        WHEN B.LOGS_END > S.LOGS_END THEN\n"
					+ "                         CEIL((TO_DATE(B.LOGS_END, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                              TO_DATE(S.LOGS_END, 'YYYY-MM-DD HH24:MI')) * 24 * 60)\n"
					+ "                        ELSE\n"
					+ "                         0\n"
					+ "                      END)\n"
					+ "             FROM HTT_CONTROL_LOG S, HTT_CONTROL_LOG B\n"
					+ "            WHERE 1 = 1\n"
					+ "              AND B.PLINE_CODE = S.PLINE_CODE\n"
					+ "              AND B.CONFIRM_FLAG = '1'\n"
					+ "              AND S.CONFIRM_FLAG = '1'\n"
					+ "              AND B.PROCESS_CODE_C = 'B024'\n"
					+ "              AND S.PRO_TYPE = '2'\n"
					+ "              AND B.BAL_YEAR_MONTH = T.BAL_YEAR_MONTH\n"
					+ "              AND S.BAL_YEAR_MONTH = T.BAL_YEAR_MONTH\n"
					+ "              AND B.PLINE_CODE = T.PLINE_CODE\n"
					+ "              AND ((S.LOGS_BEG > B.LOGS_BEG AND S.LOGS_BEG < B.LOGS_END) OR\n"
					+ "                  (S.LOGS_END > B.LOGS_BEG AND S.LOGS_END < B.LOGS_END) OR\n"
					+ "                  (S.LOGS_BEG <= B.LOGS_BEG AND S.LOGS_END >= B.LOGS_END))),\n"
					+ "           0) PRO_INCREMENT\n"
					+ "  FROM HTT_CONTROL_LOG T\n"
					+ "  LEFT JOIN (SELECT CONTROL_ID,\n"
					+ "                    NVL(SUM(CEIL((TO_DATE(LOGS_END, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                                 TO_DATE(LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24 * 60)),\n"
					+ "                        0) STOP_TIME,\n"
					+ "                    NVL(SUM(DECODE(STOP_TYPE,\n"
					+ "                                   '600602',\n"
					+ "                                   CEIL((TO_DATE(LOGS_END,\n"
					+ "                                                 'YYYY-MM-DD HH24:MI') -\n"
					+ "                                        TO_DATE(LOGS_BEG,\n"
					+ "                                                 'YYYY-MM-DD HH24:MI')) * 24 * 60),\n"
					+ "                                   0)),\n"
					+ "                        0) STOP_NORMAL,\n"
					+ "                    NVL(SUM(DECODE(STOP_TYPE,\n"
					+ "                                   '600603',\n"
					+ "                                   CEIL((TO_DATE(LOGS_END,\n"
					+ "                                                 'YYYY-MM-DD HH24:MI') -\n"
					+ "                                        TO_DATE(LOGS_BEG,\n"
					+ "                                                 'YYYY-MM-DD HH24:MI')) * 24 * 60),\n"
					+ "                                   0)),\n"
					+ "                        0) STOP_ABNORMAL\n"
					+ "               FROM HTT_CONTROL_LOG_DETAIL\n"
					+ "              GROUP BY CONTROL_ID) D\n"
					+ "    ON T.CONTROL_ID = D.CONTROL_ID\n"
					+ " WHERE T.BAL_YEAR_MONTH = '"
					+ startTim
					+ "'\n"
					+ "   AND T.CONFIRM_FLAG = '1'\n"
					+ " GROUP BY T.PLINE_CODE , T.BAL_YEAR_MONTH)  T3 ON T3.PLINE_CODE = M.PLINE_CODE   \n";

			sql += " GROUP BY M.PLINE_CODE";

			sql += " ORDER BY PLINE_NAME ASC";
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return this.getData(sql);
	}

	/**
	 * 查询调度生产运行停机时间
	 * @param startTim
	 * @param days
	 * @param PlineCode生产线
	 * @param ProStation生产区域
	 * @param station 工序点
	 * @return
	 */
	public CoreReturnObject doMinutesQueryNew(String startTim, String days,
			String[] PlineCode, String[] ProStation, String station) {
		String sql = "";
		try {
			int day = Integer.parseInt(days);

			String MTable = "SELECT * FROM COM_BASE_PLINE WHERE 1=1 ";
			MTable += CoreConverter.toSqlConditionString("PLINE_CODE",
					PlineCode);

			if (ProStation.length > 0) {

				MTable += " AND PLINE_CODE IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE 1=1  "
						+ CoreConverter.toSqlConditionString("FACTORY_CODE",
								ProStation) + ")";
			}

			sql += "SELECT";
			for (int i = 0; i < day; i++) {
				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
				Date strat;
				String systime = "";
				strat = dateFormat.parse(startTim + String.valueOf(i + 1));
				systime = dateFormat.format(strat);
				String dayd = "DAY" + String.valueOf(i + 1);
				sql += "  (SELECT NVL(SUM(CEIL((TO_DATE(T.LOGS_END, 'YYYY-MM-DD HH24:MI') - "
						+ "TO_DATE(T.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24*60)),0) SUMMINUTES "
						+ "FROM HTT_CONTROL_LOG T  WHERE 1=1 "
						+ "   AND T.PROC_DATE = '"
						+ systime
						+ "'"
						+ " AND T.PLINE_CODE = M.PLINE_CODE "
						+ " AND T.CONFIRM_FLAG <> '0'  "
						+ " AND T.STATION = '" + station + "'"
						+ " AND T.PRO_TYPE = '2') " + dayd + ",";

				sql += "  (SELECT  MIN(CONFIRM_FLAG) "
						+ "FROM HTT_CONTROL_LOG T  WHERE  1=1 "
						+ "   AND T.PROC_DATE = '" + systime + "'"
						+ " AND T.STATION = '" + station + "'"
						+ " AND T.PLINE_CODE = M.PLINE_CODE) " + "FLAG" + dayd
						+ ",";
			}
			sql += " (SELECT T2.PLINE_NAME FROM COM_BASE_PLINE T2 "
					+ " WHERE T2.PLINE_CODE = M.PLINE_CODE  "
					+ " AND T2.VALIDFLAG = '1') PLINE_NAME,"
					+ " MAX(T3.TITLE) TITLE, "
					+ " MAX(T3.STOVE_NUM) STOVE_NUM, "
					+ " MAX(T3.PRO_NUM) PRO_NUM, " + " MAX(T3.PRO_WT) PRO_WT, "
					+ " MAX(T3.STOVE_STOP_TIME) STOVE_STOP_TIME, "
					+ " MAX(T3.STOP_TIME) STOP_TIME, "
					+ " MAX(T3.STOP_NORMAL) STOP_NORMAL, "
					+ " MAX(T3.STOP_ABNORMAL) STOP_ABNORMAL, "
					+ " MAX(T3.PRO_INCREMENT) PRO_INCREMENT, "
					+ " MAX(T3.TOTAL_TIME) TOTAL_TIME, " + "M.PLINE_CODE";

			sql += " FROM  ("
					+ MTable
					+ ") M LEFT JOIN  HTT_CONTROL_LOG T1  ON M.PLINE_CODE = T1.PLINE_CODE AND  T1.BAL_YEAR_MONTH = '"
					+ startTim + "' " + " AND T1.CONFIRM_FLAG <> '0' AND T1.STATION = '"+ station + "' ";

			sql += "LEFT JOIN (SELECT T.PLINE_CODE,  TO_CHAR(TO_DATE(T.BAL_YEAR_MONTH,'YYYYMM'),'MM') || '月--' || (SELECT PLINE_NAME FROM COM_BASE_PLINE WHERE PLINE_CODE =T.PLINE_CODE)  TITLE,\n"
					+ "       COUNT(DISTINCT JUDGE_STOVE_NO) STOVE_NUM,\n"
					+ "       NVL(SUM(QUALIFIED_NUM),0) PRO_NUM,\n"
					+ "       NVL(SUM(QUALIFIED_WT),0) PRO_WT,\n"
					+ "       NVL(SUM(DECODE(T.PROCESS_CODE_C,\n"
					+ "                      'B024',\n"
					+ "                      0,\n"
					+ "                      CEIL((TO_DATE(T.LOGS_END, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                           TO_DATE(T.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24 * 60))),\n"
					+ "           0) TOTAL_TIME,\n"
					+ "       NVL(SUM(DECODE(T.PRO_TYPE,\n"
					+ "                      '1',\n"
					+ "                      0,\n"
					+ "                      CEIL((TO_DATE(T.LOGS_END, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                           TO_DATE(T.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24 * 60))),\n"
					+ "           0) STOVE_STOP_TIME,\n"
					+ "       NVL(SUM(CEIL((TO_DATE(LOGS_END, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                                 TO_DATE(LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24 * 60)),\n"
					+ "                        0) STOP_TIME,\n"

					+ "       NVL(SUM(DECODE(STOP_TYPE,\n"
					+ "                                   '600602',\n"
					+ "                                   CEIL((TO_DATE(LOGS_END,\n"
					+ "                                                 'YYYY-MM-DD HH24:MI') -\n"
					+ "                                        TO_DATE(LOGS_BEG,\n"
					+ "                                                 'YYYY-MM-DD HH24:MI')) * 24 * 60),\n"
					+ "                                   0)),\n"
					+ "                        0) STOP_NORMAL,\n"
					+ "       NVL(SUM(DECODE(STOP_TYPE,\n"
					+ "                                   '600603',\n"
					+ "                                   CEIL((TO_DATE(LOGS_END,\n"
					+ "                                                 'YYYY-MM-DD HH24:MI') -\n"
					+ "                                        TO_DATE(LOGS_BEG,\n"
					+ "                                                 'YYYY-MM-DD HH24:MI')) * 24 * 60),\n"
					+ "                                   0)),\n"
					+ "                        0) STOP_ABNORMAL,\n"
					+ "       \n"
					+ "       NVL((SELECT SUM(CEIL((TO_DATE(B.LOGS_END, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                           TO_DATE(B.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24 * 60) - CASE\n"
					+ "                        WHEN B.LOGS_BEG < S.LOGS_BEG THEN\n"
					+ "                         CEIL((TO_DATE(S.LOGS_BEG, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                              TO_DATE(B.LOGS_BEG, 'YYYY-MM-DD HH24:MI')) * 24 * 60)\n"
					+ "                        ELSE\n"
					+ "                         0\n"
					+ "                      END - CASE\n"
					+ "                        WHEN B.LOGS_END > S.LOGS_END THEN\n"
					+ "                         CEIL((TO_DATE(B.LOGS_END, 'YYYY-MM-DD HH24:MI') -\n"
					+ "                              TO_DATE(S.LOGS_END, 'YYYY-MM-DD HH24:MI')) * 24 * 60)\n"
					+ "                        ELSE\n"
					+ "                         0\n"
					+ "                      END)\n"
					+ "             FROM HTT_CONTROL_LOG S, HTT_CONTROL_LOG B\n"
					+ "            WHERE 1 = 1\n"
					+ "              AND B.PLINE_CODE = S.PLINE_CODE\n"
					+ "              AND B.CONFIRM_FLAG = '1'\n"
					+ "              AND S.CONFIRM_FLAG = '1'\n"
					+ "              AND B.PROCESS_CODE_C = 'B024'\n"
					+ "              AND S.PRO_TYPE = '2'\n"
					+ "              AND B.BAL_YEAR_MONTH = T.BAL_YEAR_MONTH\n"
					+ "              AND S.BAL_YEAR_MONTH = T.BAL_YEAR_MONTH\n"
					+ "              AND B.PLINE_CODE = T.PLINE_CODE\n"
					+ "              AND ((S.LOGS_BEG > B.LOGS_BEG AND S.LOGS_BEG < B.LOGS_END) OR\n"
					+ "                  (S.LOGS_END > B.LOGS_BEG AND S.LOGS_END < B.LOGS_END) OR\n"
					+ "                  (S.LOGS_BEG <= B.LOGS_BEG AND S.LOGS_END >= B.LOGS_END))),\n"
					+ "           0) PRO_INCREMENT\n"
					+ "  FROM HTT_CONTROL_LOG T\n"
					+ " WHERE T.BAL_YEAR_MONTH = '"
					+ startTim
					+ "'\n"
					+ " AND T.CONFIRM_FLAG <> '0'\n  "
					+ " AND T.STATION = '" + station + "'"
					+ " GROUP BY T.PLINE_CODE , T.BAL_YEAR_MONTH)  T3 ON T3.PLINE_CODE = M.PLINE_CODE   \n";

			sql += " GROUP BY M.PLINE_CODE";

			sql += " ORDER BY PLINE_NAME ASC";
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return this.getData(sql);
	}

	/***
	 * 查询生产详情
	 * 
	 * @param startTim
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject doQueryPlanPro(String startTim, String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryPlanPro");
		if (!startTim.equals("")) {
			sql += "  AND T.PROC_DATE = '" + startTim + "'";
		}
		if (!plineCode.equals("")) {
			sql += "  AND T.PLINE_CODE ='" + plineCode + "'";
		}
		sql += " ORDER BY T.LOGS_BEG,T.LOGS_END ASC";
		return this.getData(sql);
	}

	/***
	 * 查询月生产详情
	 * 
	 * @param startTim
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject doMonthQueryPlanPro(String startTim,
			String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryPlanPro");
		if (!startTim.equals("")) {
			sql += "  AND T.BAL_YEAR_MONTH = '" + startTim + "'";
		}
		if (!plineCode.equals("")) {
			sql += "  AND T.PLINE_CODE ='" + plineCode + "'";
		}
		sql += " ORDER BY T.LOGS_BEG,T.LOGS_END ASC";
		return this.getData(sql);
	}

	/***
	 * 统计生产班实绩
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryActual(String startTim, String bc,
			String plineCode) {
		String sql = "";
		sql = CoreXmlSqlParsersFactory.getSql("FrmHttControlLog.doQueryActual");
		return this.getData(sql, new Object[] { startTim, bc, startTim, bc,
				plineCode, startTim, bc, plineCode, startTim, bc, plineCode,
				startTim, bc, plineCode, startTim, bc, plineCode });
	}

	/***
	 * 统计生产日实绩
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryDayActual(String startTim, String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryDayActual");
		return this.getData(sql, new Object[] { startTim, startTim, plineCode,
				startTim, plineCode, startTim, plineCode, startTim, plineCode,
				startTim, plineCode });
	}

	/***
	 * 统计生产月实绩
	 * 
	 * @param parm
	 * @param plineCode
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryMonthActual(String startTim, String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryMonthActual");
		return this.getData(sql, new Object[] { startTim, startTim, plineCode,
				startTim, plineCode, startTim, plineCode, startTim, plineCode,
				startTim, plineCode });
	}

	/**
	 * 查询停机分类
	 * 
	 * @param sortCode
	 * @return
	 */
	public CoreReturnObject getComBaseInfo(String sortCode) {
		return this.getDataBySqlID("FrmHttControlLog.getComBaseInfo",
				new Object[] { sortCode });
	}

	public CoreReturnObject addMilControlLog(String startime, String name,
			String bc, String bz, String ProDateStr, String PlineCode,
			String station) {
		return addMilControlLog(startime, "0", name, bc, bz, ProDateStr,
				PlineCode, station);
	}

	/***
	 * 新增镦拔扩日志
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject addMilControlLog(String startime, String time,
			String name, String bc, String bz, String ProDateStr,
			String PlineCode, String station) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String systime = dateFormat.format(now);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String addsql = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.addMilControlLog");// 新增日志
			PreparedStatement pstaControl = connection.prepareStatement(addsql);

			/*String addDetailsql = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.addMilControlLogDetail");// 新增日志
			PreparedStatement pstaDetailControl = connection
					.prepareStatement(addDetailsql);*/

			Date ProDate = dateFormat.parse(ProDateStr);

			SimpleDateFormat matter3 = new SimpleDateFormat("yyyyMM");
			SimpleDateFormat matter4 = new SimpleDateFormat("yyyyMMdd");

			String ControlId = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.QueryMaxID");// 查询最大高温炉实绩编号
			PreparedStatement psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, matter4.format(ProDate));
			psta.setObject(2, matter4.format(ProDate));
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				ControlId = rs1.getString("CONTROL_ID");
			}
			rs1.close();
			psta.close();

			Integer Int = 0;
			if (StringTool.isInteger(time)) {
				Int = Integer.parseInt(time);

			}

			pstaControl.setObject(1, startime);
			pstaControl.setObject(2, startime);
			pstaControl.setObject(3, Int);
			pstaControl.setObject(4, systime);
			pstaControl.setObject(5, name);
			pstaControl.setObject(6, bc);
			pstaControl.setObject(7, bz);
			pstaControl.setObject(8, PlineCode);
			pstaControl.setObject(9, matter3.format(ProDate));
			pstaControl.setObject(10, matter4.format(ProDate));
			pstaControl.setObject(11, ControlId);
			pstaControl.setObject(12, station);

			pstaControl.addBatch();
			pstaControl.executeBatch();
			pstaControl.close();

			/*pstaDetailControl.setObject(1, ControlId);
			pstaDetailControl.setObject(2, startime);
			pstaDetailControl.setObject(3, startime);
			pstaDetailControl.setObject(4, Int);
			pstaDetailControl.setObject(5, ControlId);

			pstaDetailControl.addBatch();
			pstaDetailControl.executeBatch();
			pstaDetailControl.close();*/

			cro.setV_errMsg("新增成功!");
			connection.commit();
		} catch (Exception e) {
			cro.setV_errMsg(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
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject oneKeyProcesMilControlLog(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String systime = dateFormat.format(now);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String addsql = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.OneKeyProcesMilControlLog");// 一键处理新增镦拔扩日志
			PreparedStatement pstaControl = connection.prepareStatement(addsql);
			for (int i = 0; i < parm.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) parm.get(i);
				String stratime = list.get(0);
				String endtime = list.get(1);
				String name = list.get(2);
				String bc = list.get(3);
				String bz = list.get(4);
				// int count = 0;
				// String sqlloading = CoreXmlSqlParsersFactory
				// .getSql("FrmHttControlLog.queryPlanJg");
				// PreparedStatement psta = connection
				// .prepareStatement(sqlloading);
				// psta.setObject(1, stratime);
				// // psta.setObject(1, endtime);
				// ResultSet rs = psta.executeQuery();
				// if (rs.next()) {
				// count = Integer.parseInt(rs.getString("COUNTS"));
				// }
				// rs.close();
				// psta.close();
				// if (count != 0) {
				// cro.setV_errMsg("该新增的记录已存在！");
				// return cro;
				// }
				pstaControl.setObject(1, stratime);
				pstaControl.setObject(2, endtime);
				pstaControl.setObject(3, systime);
				pstaControl.setObject(4, name);
				pstaControl.setObject(5, bc);
				pstaControl.setObject(6, bz);
				pstaControl.setObject(7, list.get(5));
				pstaControl.setObject(8, "2");
				pstaControl.setObject(9, "500603");
				pstaControl.setObject(10, "50060302");
				pstaControl.setObject(11, "5006030201");
				pstaControl.addBatch();
			}
			pstaControl.executeBatch();
			pstaControl.close();

			// 修改MIL_CONTROL_LOG :Proc_Date
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.UpdataPROCDATE");
			PreparedStatement ps = connection.prepareStatement(updateSql);
			ps.executeUpdate();
			ps.close();

			cro.setV_errMsg("一键处理成功!");
			connection.commit();
		} catch (Exception e) {
			cro.setV_errMsg(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
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject oneKeyUpdateMilControlLog(ArrayList<String> Controls) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.updateControlLog2");// 修改调度日志
			PreparedStatement updatePsta = connection
					.prepareStatement(updateSql);

			for (String control : Controls) {
				HttControlLogEntity HttControlLogEntity = EntityTool
						.getEntityByJSONStr(control, HttControlLogEntity.class);
				updatePsta.setObject(1, HttControlLogEntity.getLogsBeg());
				updatePsta.setObject(2, HttControlLogEntity.getControlId());

				updatePsta.addBatch();
				updatePsta.executeBatch();
			}

			cro.setV_errMsg("一键处理成功!");
			connection.commit();
		} catch (Exception e) {
			cro.setV_errMsg(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 logsEnd
	 * @param ControlId
	 * @return
	 */
	public CoreReturnObject updateOneDate(String logsEnd, String ControlId) {
		String sql = "";
		sql = "UPDATE HTT_CONTROL_LOG T SET T.LOGS_BEG = '" + logsEnd
				+ "' WHERE T.CONTROL_ID = '" + ControlId + "'";
		return this.setData(sql);
	}

	/***
	 * 修改调度日志
	 * 
	 * @return
	 */
	public CoreReturnObject updateMilControlLog(ArrayList<String> List1Str,
			ArrayList<String> List2Str) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();

		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.updateControlLog");// 修改调度日志
			PreparedStatement updatePsta = connection
					.prepareStatement(updateSql);

			/*String DeleteDetail = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.DeleteControlLogDetail");// 删除调度日志字表
			PreparedStatement DeleteDetailPsta = connection
					.prepareStatement(DeleteDetail);*/

			for (int i = 0; i < List1Str.size(); i++) {
				HttControlLogEntity Entity = EntityTool.getEntityByJSONStr(
						List1Str.get(i), HttControlLogEntity.class);

				String OrgBeg = "";
				String OrgEnd = "";
				String CanTime = "";

				// 查询确认状态
				String confiem = "";
				String sqlloading = CoreXmlSqlParsersFactory
						.getSql("FrmHttControlLog.queryContfirm");
				PreparedStatement psta = connection
						.prepareStatement(sqlloading);
				psta.setObject(1, Entity.getControlId());
				ResultSet rs = psta.executeQuery();
				if (rs.next()) {
					confiem = rs.getString("CONFIRM_FLAG");
					OrgBeg = rs.getString("BEGIN_DATE");
					OrgEnd = rs.getString("END_DATE");
					CanTime = rs.getString("CAN_TIME");
				}
				rs.close();
				psta.close();

				if (confiem.equals("1")) {
					cro.setV_errMsg("已确认不能进行此操作!");
					return cro;
				}

				if (Entity.getLogsBeg().length() < 12) {
					cro.setV_errMsg("请输入正确的开始时间!");
					return cro;
				}

				SimpleDateFormat dateFormat = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
				SimpleDateFormat matter2 = new SimpleDateFormat("yyyyMMddHHmm");
				SimpleDateFormat matter3 = new SimpleDateFormat("yyyyMM");
				SimpleDateFormat matter4 = new SimpleDateFormat("yyyyMMdd");

				Date colDate = matter2.parse(Entity.getLogsBeg());
				Date procDate = colDate;
				if (Entity.getProBc().equals("3")) {
					Calendar date = Calendar.getInstance();
					date.setTime(colDate);
					date.set(Calendar.HOUR_OF_DAY, date
							.get(Calendar.HOUR_OF_DAY) + 12);
					procDate = dateFormat.parse(dateFormat.format(date
							.getTime()));
				}

				if (CanTime != null && StringTool.isInteger(CanTime)) {
					if (OrgBeg != null && OrgBeg.length() == 12
							&& Entity.getLogsBeg().length() == 12) {
						Date OrgBegDate = matter2.parse(OrgBeg);
						if (Math.abs((OrgBegDate.getTime() - matter2.parse(
								Entity.getLogsBeg()).getTime())
								/ (1000 * 60)) > Integer.parseInt(CanTime)) {
							cro.setV_errMsg("炉号" + Entity.getJudgeStoveNo()
									+ "现场维护的开始时间为"
									+ dateFormat.format(OrgBegDate)
									+ ", 不能调整超过 " + CanTime + "分钟");
							return cro;
						}

					}
					if (OrgBeg != null && OrgEnd.length() == 12
							&& Entity.getLogsEnd().length() == 12) {
						Date OrgEndDate = matter2.parse(OrgEnd);
						if (Math.abs((OrgEndDate.getTime() - matter2.parse(
								Entity.getLogsEnd()).getTime())
								/ (1000 * 60)) > Integer.parseInt(CanTime)) {
							cro.setV_errMsg("炉号" + Entity.getJudgeStoveNo()
									+ "现场维护的结束时间为"
									+ dateFormat.format(OrgEndDate)
									+ ", 不能调整超过 " + CanTime + "分钟");
							return cro;
						}

					}

				}

				updatePsta.setObject(1, Entity.getLogsBeg());
				updatePsta.setObject(2, Entity.getLogsEnd());
				updatePsta.setObject(3, Entity.getMemo());
				updatePsta.setObject(4, matter3.format(procDate));
				updatePsta.setObject(5, matter4.format(procDate));
				updatePsta.setObject(6, Entity.getProBc());
				if(Entity.getProType().equals("1")){
					updatePsta.setObject(7, "");
					updatePsta.setObject(8, "");
					updatePsta.setObject(9, "");
				}else{
					updatePsta.setObject(7, Entity.getStopType());
					updatePsta.setObject(8, Entity.getStopSmall());
					updatePsta.setObject(9, Entity.getStopReason());
				}
				updatePsta.setObject(10, Entity.getControlId());

				updatePsta.addBatch();
				updatePsta.executeBatch();
			}

			/*for (int i = 0; i < List2Str.size(); i++) {

				HttControlLogDetailEntity Entity = EntityTool
						.getEntityByJSONStr(List2Str.get(i),
								HttControlLogDetailEntity.class);

				if (i == 0) {
					DeleteDetailPsta.setObject(1, Entity.getControlId());
					DeleteDetailPsta.addBatch();
					DeleteDetailPsta.executeBatch();
				}

				String sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttControlLog.AddControlDetail");
				sql = EntityTool.fillSqlByEntity(sql, Entity);
				PreparedStatement psta = connection.prepareStatement(sql);
				psta.addBatch();
				psta.executeBatch();
				psta.close();
			}*/

			cro.setV_errMsg("修改成功!");
			connection.commit();
		} catch (Exception e) {
			cro.setV_errMsg(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
	 * @param stationId
	 * @param colGroup
	 * @param colOrder
	 * @return
	 */
	public CoreReturnObject deleteMilControlLog(ArrayList<String> ControlID) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.DeleteControlLog");// 删除调度日志
			PreparedStatement updatePsta = connection
					.prepareStatement(updateSql);

			String deleteSql = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.DeleteControlLogDetail");// 删除调度日志
			PreparedStatement deleteSqlPsta = connection
					.prepareStatement(deleteSql);

			for (int i = 0; i < ControlID.size(); i++) {

				String userId = ControlID.get(0);

				// 查询确认状态
				String confiem = "";
				String sqlloading = CoreXmlSqlParsersFactory
						.getSql("FrmHttControlLog.queryContfirm");
				PreparedStatement psta = connection
						.prepareStatement(sqlloading);
				psta.setObject(1, userId);
				ResultSet rs = psta.executeQuery();
				if (rs.next()) {
					confiem = rs.getString("CONFIRM_FLAG");
				}
				rs.close();
				psta.close();

				if (confiem.equals("1")) {
					cro.setV_errMsg("已确认不能进行此操作!");
					return cro;
				}
				updatePsta.setObject(1, userId);
				updatePsta.addBatch();

				deleteSqlPsta.setObject(1, userId);
				deleteSqlPsta.addBatch();

			}
			updatePsta.executeBatch();
			deleteSqlPsta.executeBatch();
			cro.setV_errMsg("删除成功!");
			connection.commit();
		} catch (Exception e) {
			cro.setV_errMsg(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 list1
	 * @return
	 */
	public CoreReturnObject confirmMilControlLog(ArrayList<String> list1,
			String Name, String ProDate, String PlineCode, String Bc,
			String confirmFlag) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm", Locale.CHINA);

			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.confirmMilControlLog");// 修改确认
			PreparedStatement updatePsta = connection
					.prepareStatement(updateSql);

			HttControlShiftEntity ShiftEntity = getHttControlByID(connection,
					PlineCode, Bc);

			if (ShiftEntity == null) {
				cro.setV_errMsg("未维护当前班次的上班时间");
				return cro;
			}

			SimpleDateFormat matter2 = new SimpleDateFormat("yyyyMMddHHmm");

			Date BegDate = matter2.parse(ProDate + ShiftEntity.getShiftBeg());
			Date EndDate = matter2.parse(ProDate + ShiftEntity.getShiftEnd());

			if (BegDate.after(EndDate)) {
				BegDate = new Date(BegDate.getTime() - 24 * 60 * 60 * 1000);
			}

			// List<HttControlLogEntity> Entitys = getHttControl(connection,
			// list1);

			String BegDateStr = matter2.format(BegDate);
			String EndDataStr = matter2.format(EndDate);

			String NeedBegDateStr = BegDateStr;

			for (int i = 0; i < list1.size(); i++) {
				// HttControlLogEntity Entity = Entitys.get(i);
				HttControlLogEntity httControlLogTity = EntityTool
						.getEntityByJSONStr(list1.get(i),
								HttControlLogEntity.class);
				HttControlLogEntity Entity = getHttControlByID(connection,
						httControlLogTity.getControlId());

				if (Entity.getLogsBeg().equals("")
						|| Entity.getLogsEnd().equals("")) {
					cro.setV_errMsg("没有开始时间或结束时间,无法确认！");
					return cro;
				}

				if (Entity.getLogsBeg().compareTo(Entity.getLogsEnd()) > 0) {
					cro.setV_errMsg("开始时间晚于结束时间,无法确认！");
					return cro;
				}
				if (confirmFlag.equals("1")) {
					if (!Entity.getConfirmFlag().equals("0")) {
						cro.setV_errMsg("不是未确认数据,无法确认！");
						return cro;
					}
				}
				if (confirmFlag.equals("2")) {
					if (!Entity.getConfirmFlag().equals("1")) {
						cro.setV_errMsg("不是确认数据,无法审核！");
						return cro;
					}
				}

				if (/*
					 * !Entity.getProcessCodeC().equals("B024") &&
					 */!(Entity.getProType().equals("2") && Entity.getLogsEnd()
						.equals(Entity.getLogsBeg()))) {
					if (!NeedBegDateStr.equals(Entity.getLogsBeg())) {
						if (NeedBegDateStr.equals(BegDateStr)) {
							/*
							 * cro.setV_errMsg("请从上班时间" +
							 * dateFormat.format(BegDate) + "开始维护数据！"); return
							 * cro;
							 */
						}

						if (Entity.getLogsBeg().compareTo(NeedBegDateStr) > 0) {
							cro.setV_errMsg(dateFormat.format(matter2
									.parse(NeedBegDateStr))
									+ "到"
									+ dateFormat.format(matter2.parse(Entity
											.getLogsBeg())) + "没有数据,请确认");
							return cro;
						} else {
							cro
									.setV_errMsg(dateFormat.format(matter2
											.parse(Entity.getLogsBeg()))
											+ "到"
											+ dateFormat.format(matter2
													.parse(NeedBegDateStr))
											+ "有重复,请确认");
							return cro;
						}

					} else {
						NeedBegDateStr = Entity.getLogsEnd();
					}

					if (i == list1.size() - 1
							&& !EndDataStr.equals(Entity.getLogsEnd())) {
						if (Entity.getLogsEnd().compareTo(EndDataStr) > 0) {
							cro.setV_errMsg("结束时间超出下班时间"
									+ dateFormat.format(EndDate) + ",请确认");
							return cro;
						} else {
							cro.setV_errMsg(dateFormat.format(matter2
									.parse(Entity.getLogsEnd()))
									+ "到下班时间"
									+ dateFormat.format(EndDate)
									+ "未维护数据,请确认");
							return cro;
						}
					}
				} else {

					if (Entity.getLogsBeg().compareTo(BegDateStr) < 0) {
						cro.setV_errMsg("时间早于当班的上班时间,请先调整数据！");
						return cro;
					}

					if (Entity.getLogsEnd().compareTo(EndDataStr) > 0) {
						cro.setV_errMsg("时间晚于当班的下班时间,请先调整数据！");
						return cro;
					}
				}
				
				if(Entity.getProType().equals("2")){
					String stopReason = "";
					String sql4 = CoreXmlSqlParsersFactory
							.getSql("FrmHttControlLog.doQueryPlanById");
					PreparedStatement psta = connection
							.prepareStatement(sql4);
					psta.setObject(1, Entity.getControlId());
					ResultSet rs = psta.executeQuery();
					if (rs.next()) {
						stopReason = rs.getString("STOP_REASON");
					}
					rs.close();
					psta.close();
					if (stopReason == null || "".equals(stopReason)) {
						cro.setV_errMsg("停机原因为空或者没有保存,不能确认!");
						return cro;
					}
					
					if (!StringTool.isNumeric(Entity.getStopReason().toString())) {
						cro.setV_errMsg("停机原因为空,不能确认!");
						return cro;
					}
				}
				

				/*if (Entity.getProType().equals("2")) {
					List<HttControlLogDetailEntity> listDetails = getHttControlDetailByID(
							connection, Entity.getControlId());
					if (listDetails == null || listDetails.size() <= 0) {
						cro.setV_errMsg("未维护停机详细记录,无法确认！");
						return cro;
					}

					for (HttControlLogDetailEntity listDetail : listDetails) {

						if (listDetail.getLogsBeg().equals("")
								|| listDetail.getLogsEnd().equals("")) {
							cro.setV_errMsg("停机详细没有开始时间或结束时间,无法确认！");
							return cro;
						}

						if (listDetail.getLogsBeg().compareTo(
								listDetail.getLogsEnd()) > 0) {
							cro.setV_errMsg("停机详细开始时间晚于结束时间,无法确认！");
							return cro;
						}

						if (listDetail.getStopType().equals("")
								|| listDetail.getStopSmall().equals("")
								|| listDetail.getStopReason().equals("")) {
							cro.setV_errMsg("停机详细中停机大类,停机小类,停机原因不能为空,无法确认！");
							return cro;
						}

					}

				}*/

				updatePsta.setObject(1, confirmFlag);
				updatePsta.setObject(2, Name);
				updatePsta.setObject(3, Entity.getControlId());
				updatePsta.addBatch();
				updatePsta.executeBatch();

			}

			if (confirmFlag.equals("1")) {
				cro.setV_errMsg("确认成功!");
			}
			if (confirmFlag.equals("2")) {
				cro.setV_errMsg("审核成功!");
			}
			connection.commit();
		} catch (Exception e) {
			cro.setV_errMsg(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 list1
	 * @return
	 */
	public CoreReturnObject upConfirmMilControlLog(ArrayList<String> list1,
			String confirmFlag) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.UpConfirmMilControlLog");// 取消确认
			PreparedStatement updatePsta = connection
					.prepareStatement(updateSql);

			// 查询确认状态
			String CanDay = "";

			// List<HttControlLogEntity> Entitys = getHttControl(connection,
			// list1);
			for (int i = 0; i < list1.size(); i++) {
				HttControlLogEntity httControlLogTity = EntityTool
						.getEntityByJSONStr(list1.get(i),
								HttControlLogEntity.class);
				HttControlLogEntity Entity = getHttControlByID(connection,
						httControlLogTity.getControlId());
				if (Entity == null) {
					cro.setV_errMsg("数据发生改变,请重新查询数据！");
					return cro;
				}

				if (confirmFlag.equals("0")) {
					if (!Entity.getConfirmFlag().equals("1")) {
						cro.setV_errMsg("不是已确认数据,无法取消确认！");
						return cro;
					}
				}
				if (confirmFlag.equals("1")) {
					if (!Entity.getConfirmFlag().equals("2")) {
						cro.setV_errMsg("不是已审核数据,无法取消审核！");
						return cro;
					}
				}

				if (CanDay.equals("")) {
					String sqlloading = CoreXmlSqlParsersFactory
							.getSql("FrmHttControlLog.queryContfirm2");
					PreparedStatement psta = connection
							.prepareStatement(sqlloading);
					ResultSet rs = psta.executeQuery();
					if (rs.next()) {
						CanDay = rs.getString("BASENAME");
					}
					rs.close();
					psta.close();
				}

				if (CanDay != null && StringTool.isInteger(CanDay)) {
					SimpleDateFormat matter2 = new SimpleDateFormat(
							"yyyyMMddHHmm");
					if ((new Date().getTime() - matter2.parse(
							Entity.getLogsBeg()).getTime()) / 24 / 3600 / 1000 > Integer
							.parseInt(CanDay)) {
						cro.setV_errMsg("不能取消超过" + CanDay + "天的数据");
						return cro;
					}

				}

				/*
				 * String sql = CoreXmlSqlParsersFactory
				 * .getSql("FrmHttControlLog.queryCountLoag1");
				 * PreparedStatement ps = connection.prepareStatement(sql);
				 * ps.setObject(1, Entity.getLogsBeg()); ps.setObject(2,
				 * Entity.getLogsBeg()); ps.setObject(3, Entity.getLogsEnd());
				 * ps.setObject(4, Entity.getPlineCode()); ps.setObject(5,
				 * Entity.getProBc()); ps.setObject(6, Entity.getProBz());
				 * ResultSet rs = ps.executeQuery();
				 * 
				 * if(rs.next()){ cro.setV_errMsg("所选择数据前后有确认数据,请先取消确认后面数据！");
				 * return cro; }
				 */

				updatePsta.setObject(1, confirmFlag);
				updatePsta.setObject(2, Entity.getControlId());
				updatePsta.addBatch();
				updatePsta.executeBatch();
			}

			if (confirmFlag.equals("0")) {
				cro.setV_errMsg("取消确认成功!");
			}
			if (confirmFlag.equals("1")) {
				cro.setV_errMsg("取消审核成功!");
			}
			connection.commit();
		} catch (Exception e) {
			cro.setV_errMsg(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 beginTime
	 * @param day
	 * @param hours
	 * @param minutes
	 * @return
	 */
	public static Date dateAddSecond(Date beginTime, int day, int hours,
			int minutes) {
		Calendar rightNow = Calendar.getInstance();
		rightNow.setTime(beginTime);
		rightNow.add(Calendar.DAY_OF_YEAR, day);
		rightNow.add(Calendar.HOUR, hours);
		rightNow.add(Calendar.MINUTE, minutes);
		Date dt = rightNow.getTime();
		return dt;
	}

	/**
	 * 两个时间相差距离多少天多少小时多少分
	 * 
	 * @param str1
	 *            时间参数 1 格式：1990-01-01 12:00
	 * @param str2
	 *            时间参数 2 格式：2009-01-01 12:00
	 * @return long[] 返回值为：{天, 时, 分}
	 */
	public static long[] getDistanceTimes(String str1, String str2) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Date one;
		Date two;
		long day = 0;
		long hour = 0;
		long min = 0;
		// long sec = 0;
		try {
			one = df.parse(str1);
			two = df.parse(str2);
			long time1 = one.getTime();
			long time2 = two.getTime();
			long diff;
			// if (time1 < time2) {
			// diff = time2 - time1;
			// }
			// else {
			diff = time2 - time1;
			// }
			day = diff / (24 * 60 * 60 * 1000);
			hour = (diff / (60 * 60 * 1000) - day * 24);
			min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
			// sec = (diff/1000-day*24*60*60-hour*60*60-min*60);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		long[] times = { day, hour, min };
		return times;
	}

	/**
	 * 查询连轧待上料信息
	 * 
	 * @param MilPlan
	 *            作业计划实体类
	 * @param ProcessNo
	 *            工序号 1-锯切 2-环形加热炉 3-穿孔 4-连轧 5-再加热炉 6-定径 7-管排锯 8-矫直 9-ET探伤...
	 *            11-涡流探伤 12-人工质检
	 * @return CoreReturnObject
	 * @Return 0-未开始 1-工序已开始
	 */
	public CoreReturnObject getSingleMainPlan(String plineCode) {

		// String Judge_Stove_No = "Judge_Stove_No"; MIL_ROLLING_Result

		String Sql = "SELECT b.CUT_NUM,a.ID,a.SEQ,a.STOVE_NO,a.JUDGE_STOVE_NO,substr(a.JUDGE_STOVE_NO，0,6) as JUDGE_NO,a.LOT_NO,a.CONTRACT_NO,a.IMP_PROCESS,a.PLINE_CODE,a.BACK_PLAN_FLAG,";
		Sql += "CASE a.STATUS WHEN ";
		Sql += "'00' THEN '上料' WHEN '05' THEN '开始锯切' WHEN  '10'	THEN '锯切完成' WHEN  '15' THEN '入炉' WHEN '20'	THEN '出炉' WHEN '25' THEN '开始穿孔' WHEN '30'	THEN '穿孔完成' WHEN ";
		Sql += " '35' THEN '开始连轧' WHEN  '40'	THEN '连轧完成' WHEN '45' THEN '入再加热炉' WHEN '50'	THEN '出再加热炉' WHEN '55' THEN '开始定径' WHEN '60'	THEN '定径完成' WHEN ";
		Sql += " '65' THEN '开始分切' WHEN '70'	THEN '分切完成' WHEN '75' THEN '开始矫直' WHEN '80'	THEN '矫直完成 ' WHEN '85' THEN '开始探伤' WHEN '90'	THEN '探伤完成' WHEN	 '95' THEN '人工质检开始' WHEN ";
		Sql += "  '99'	THEN '入库' END AS STATUS,";
		Sql += " a.PRODUCER, a.PROCESS_STATUS, a.DB_LENGTH, a.DB_HEIGHT, a.ROLL_LENGTH, a.SAW_NUM, a.TARGET_LENGTH, a.FINISH_USER, a.TARGET_LIABRARY, a.VARIETIES, a.PIPE_SIZE, ";
		Sql += " a.BUCKLE_TYPE, a.LENGTH_RANGE, a.ROLL_STANDRAD,a.PIPE_SECTION, a.STEELCODE, a.STEELNAME, a.GRADECODE,  a.GRADENAME, a.STEEL_STANDRAD, a.TARGET, BRANCH,";
		Sql += "a.TON, a.CUT_TARGET,a.CUT_LENGTH, a.CUT_WEIGHT, a.DB_NUM, CASE a.NODE_STATUS WHEN  '00' THEN '' WHEN '10'	THEN '锯切完成' WHEN '15' THEN '入炉' WHEN '20'	THEN '出炉' WHEN ";
		Sql += " '25' THEN '开始穿孔' WHEN '30'	THEN '穿孔完成' WHEN '35' THEN '开始连轧' WHEN '40'	THEN '连轧完成' WHEN '45' THEN '入再加热炉' WHEN '50'	THEN '出再加热炉' WHEN '55' THEN '开始定径' WHEN ";
		Sql += " '60'	THEN '定径完成' WHEN '65' THEN '开始分切' WHEN '70'	THEN '分切完成' WHEN '75' THEN '开始矫直' WHEN '80'	THEN '矫直完成 ' WHEN '85' THEN '开始探伤' WHEN '90'	THEN '探伤完成' WHEN	 '96' THEN '人工质检完成' WHEN '99' THEN '交库'";
		Sql += " END AS NODE_STATUS,";
		Sql += " Nvl((select  b.NODE_FUR_FLAG from MIL_ROLLING_Result b where b.judge_stove_no = a.judge_Stove_no) ,3)AS IS_START ,";

		Sql += " TO_CHAR(a.START_TIME, 'YYYY-MM-DD HH24:MI:SS') START_TIME, TO_CHAR(a.END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME, TO_CHAR(a.TOM, 'YYYY-MM-DD HH24:MI:SS') TOM, TO_CHAR(a.TOC, 'YYYY-MM-DD HH24:MI:SS') TOC ";
		Sql += "   FROM MIL_PLAN   a  ,MIL_FEEDSAW_RESULT b";

		Sql += "  WHERE 1=1  ";
		Sql += "  and  a.NODE_STATUS between '00' and '30' ";
		Sql += " AND a.PLINE_CODE = '" + plineCode + "'";

		Sql += " and a.judge_stove_no = b.judge_stove_no(+)";
		Sql += " and a.id = b.Result_NO(+)";
		Sql += " AND STATUS>'00'   ";
		Sql += " AND Nvl((select b.NODE_FUR_FLAG from MIL_ROLLING_Result b where b.judge_stove_no = a.judge_Stove_no),3) = '3' ";
		Sql += " AND a.rolling_status in ('0','1')";
		Sql += "  order by   a.FEED_TIME  ,a.START_TIME";
		return this.getData(Sql);
	}

	public CoreReturnObject UpdateHours(ArrayList<String> listEntitysStr) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {

			String sqlupdate = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.UpdateHours");// 修改热处理计划表
			PreparedStatement patupdate = connection
					.prepareStatement(sqlupdate);

			for (String listEntityStr : listEntitysStr) {

				SlmBaseMaterialFPlEntity Entity = EntityTool
						.getEntityByJSONStr(listEntityStr,
								SlmBaseMaterialFPlEntity.class);
				patupdate.setObject(1, Entity.getHrRhythm());
				patupdate.setObject(2, Entity.getQualifiedNum());
				patupdate.setObject(3, Entity.getQualifiedNum());
				patupdate.setObject(4, Entity.getInMaterialNo());
				patupdate.setObject(5, Entity.getOutMaterialNo());
				patupdate.setObject(6, Entity.getPlineCode());
				patupdate.addBatch();

			}
			patupdate.executeBatch();

			cro.setV_errMsg("回报成功！");
			connection.commit();
		} catch (Exception e) {
			cro.setV_errMsg(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;
	}

	public CoreReturnObject UpdateHoursG(ArrayList<String> listEntitysStr) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {

			String sqlupdate = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.UpdateHoursG");// 修改热处理计划表
			PreparedStatement patupdate = connection
					.prepareStatement(sqlupdate);

			for (String listEntityStr : listEntitysStr) {

				SlmBaseMaterialFPlEntity Entity = EntityTool
						.getEntityByJSONStr(listEntityStr,
								SlmBaseMaterialFPlEntity.class);
				patupdate.setObject(1, Entity.getHrRhythm());
				patupdate.setObject(2, Entity.getQualifiedNum());
				patupdate.setObject(3, Entity.getQualifiedNum());
				patupdate.setObject(4, Entity.getInMaterialNo());
				patupdate.setObject(5, Entity.getOutMaterialNo());
				patupdate.setObject(6, Entity.getPlineCode());
				patupdate.addBatch();

			}
			patupdate.executeBatch();

			cro.setV_errMsg("回报成功！");
			connection.commit();
		} catch (Exception e) {
			cro.setV_errMsg(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 startTim
	 * @param endTim
	 * @param plineCode
	 * @param station
	 * @return
	 */
	public CoreReturnObject doQueryStop(String startTim, String endTim,
			String plineCode, String station) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttControlLog.doQueryStop");
		sql += " AND T.PROC_DATE BETWEEN  '" + startTim + "' AND '" + endTim
				+ "'";
		if (!plineCode.equals("")) {
			sql += "  AND T.PLINE_CODE ='" + plineCode + "'";
		}
		if (!station.equals("")) {
			sql += "  AND T.STATION ='" + station + "'";
		}
		sql += " ORDER BY T.PLINE_CODE,T.LOGS_BEG,T.LOGS_END ASC";
		return this.getData(sql);
	}

	/**
	 * 调度停机修改
	 * 
	 * @param List1Str
	 * @return
	 */
	public CoreReturnObject updateMilControlLogStop(ArrayList<String> List1Str) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			for (int i = 0; i < List1Str.size(); i++) {
				HttControlLogEntity Entity = EntityTool.getEntityByJSONStr(
						List1Str.get(i), HttControlLogEntity.class);
				
				if (!StringTool.isNumeric(Entity.getStopReason().toString())) {
					cro.setV_errMsg("停机原因为空,不能修改!");
					return cro;
				}

				String sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttControlLog.updateMilControlLogStop");// 修改调度日志
				sql = EntityTool.fillSqlByEntity(sql, Entity);
				PreparedStatement psta = connection.prepareStatement(sql);
				psta.addBatch();
				psta.executeBatch();
				psta.close();
			}
			cro.setV_errMsg("修改成功!");
			connection.commit();
		} catch (Exception e) {
			cro.setV_errMsg(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;
	}
}
