package com.steering.mes.mcp.common;

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.comm.tools.StringTool;
import com.steering.common.EntityTool;
import com.steering.mes.mcp.Mch.FrmMcpLoading;
import com.steering.mes.mcp.entity.MatBcMEntity;
import com.steering.mes.mcp.entity.OfflineResultEntity;
import com.steering.mes.mcp.entity.YdmOverstockpipeApplyEntity;

import com.steering.mes.mcp.entity.YdmOverstockpipeResultEntity;
import org.hsqldb.lib.StringUtil;

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.Date;
import java.util.HashMap;
import java.util.List;

/**
 * Created by 朱少波 on 2021/5/18.
 */
public class OverstockPipe extends DBCommon {

	public static String GetId(Connection con, String plineCode)
			throws SQLException {

		String resultNo = "";
		String sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.GetId");
		PreparedStatement pst = con.prepareStatement(sql);
		pst.setObject(1, plineCode);
		pst.setObject(2, plineCode);
		ResultSet rs = pst.executeQuery();
		if (rs.next()) {
			resultNo = rs.getString("RESULT_NO");

		}
		rs.close();
		pst.close();

		return resultNo;
	}

	/**
	 * 查询离线数据
	 * 
	 * @param para
	 * @return
	 */
	public CoreReturnObject doQuery(HashMap<String, Object> para)
			throws Exception {
		String sql = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.doQueryOffline");
		if (para.containsKey("start") && para.get("start") != null
				&& !StringUtil.isEmpty(para.get("start").toString())) {
			sql += " AND M.PRO_TIME >=TO_DATE('" + para.get("start")
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND M.PRO_TIME <=TO_DATE('"
					+ para.get("end") + "', 'YYYY-MM-DD HH24:MI:SS') ";

		}
		if (para.containsKey("plineCodes") && para.get("plineCodes") != null
				&& para.get("plineCodes") instanceof String[]) {

			sql += CoreConverter.toSqlConditionString("M.PLINE_CODE",
					(String[]) para.get("plineCodes"));

		} else {

			throw new Exception("无权限");
		}

		if (para.containsKey("judgeNo") && para.get("judgeNo") != null
				&& !StringUtil.isEmpty(para.get("judgeNo").toString())) {
			sql += " AND M.JUDGE_STOVE_NO LIKE  '" + para.get("judgeNo") + "%'";
		}

		if (para.containsKey("process") && para.get("process") != null
				&& !StringUtil.isEmpty(para.get("process").toString())) {
			sql += " AND M.PROCESS ='" + para.get("process") + "' ";

		}

		if (para.containsKey("resultNo") && para.get("resultNo") != null
				&& !StringUtil.isEmpty(para.get("resultNo").toString())) {
			sql += " AND M.RESULT_NO ='" + para.get("resultNo") + "' ";

		}
		sql += " ORDER BY M.PLINE_CODE, M.PRO_TIME, M.JUDGE_STOVE_NO, M.BATCH_NO, M.APPLY_RESULT_NO";
		return this.getData(sql);
	}

	/**
	 * 查询余材数据
	 * 
	 * @param para
	 * @return
	 * @throws Exception
	 */
	public CoreReturnObject doQueryYC(HashMap<String, Object> para)
			throws Exception {
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.doQueryYC");
		String sql = "";
		if (para.containsKey("start") && para.get("start") != null
				&& !StringUtil.isEmpty(para.get("start").toString())) {
			sql += " AND T.CREATE_TIME >=TO_DATE('"
					+ para.get("start")
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
					+ para.get("end") + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}

		if (para.containsKey("plineCodes") && para.get("plineCodes") != null
				&& para.get("plineCodes") instanceof String[]) {

			sql += CoreConverter.toSqlConditionString("T.PLINE_CODE",
					(String[]) para.get("plineCodes"));

		} else {

			throw new Exception("无权限");
		}

		if (para.containsKey("judgeNo") && para.get("judgeNo") != null
				&& !StringUtil.isEmpty(para.get("judgeNo").toString())) {
			sql += " AND T.JUDGE_STOVE_NO LIKE  '" + para.get("judgeNo") + "%'";
		}

		sql1 = sql1.replace("#someThing#", sql);

		sql1 += " ORDER BY T.APPLY_RESULT_NO";

		return this.getData(sql1);
	}

	public OfflineResultEntity getData(Connection con, String ResultNo)
			throws SQLException {

		String sql = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.doQueryOffline");
		sql += " AND M.RESULT_NO ='" + ResultNo + "'";
		PreparedStatement ps = con.prepareStatement(sql);

		ResultSet rs = ps.executeQuery();
		List<OfflineResultEntity> resultEntities = EntityTool.getEntitysByRs(
				rs, OfflineResultEntity.class);
		rs.close();
		ps.close();

		if (resultEntities == null || resultEntities.size() <= 0) {
			return null;
		}
		return resultEntities.get(0);
	}

	/**
	 * 查询压库存送判记录
	 * 
	 * @param para
	 * @return
	 */
	public CoreReturnObject doQueryResult(HashMap<String, Object> para)
			throws Exception {

		String sql = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.doQueryResult");

		if (para.containsKey("start") && para.get("start") != null
				&& !StringUtil.isEmpty(para.get("start").toString())) {
			sql += " AND T.PRO_TIME >=TO_DATE('" + para.get("start")
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.PRO_TIME <=TO_DATE('"
					+ para.get("end") + "', 'YYYY-MM-DD HH24:MI:SS') ";

		}

		if (para.containsKey("plineCodes") && para.get("plineCodes") != null
				&& para.get("plineCodes") instanceof String[]) {

			sql += CoreConverter.toSqlConditionString("T.PLINE_CODE",
					(String[]) para.get("plineCodes"));
		} else {

			throw new Exception("无权限");
		}

		if (para.containsKey("judgeNo") && para.get("judgeNo") != null
				&& !StringUtil.isEmpty(para.get("judgeNo").toString())) {
			sql += " AND T.JUDGE_STOVE_NO LIKE  '" + para.get("judgeNo") + "%'";
		}

		if (para.containsKey("validflag") && para.get("validflag") != null
				&& !StringUtil.isEmpty(para.get("validflag").toString())) {
			sql += " AND T.VALIDFLAG =  '" + para.get("validflag") + "'";
		}
		if (para.containsKey("flag") && para.get("flag") != null
				&& !StringUtil.isEmpty(para.get("flag").toString())) {
			sql += " AND T.FLAG =  '" + para.get("flag") + "'";
		}

		sql += " ORDER BY T.PRO_TIME  DESC";

		return this.getData(sql);
	}


	/**
	 * 查询压库申请信息
	 * @param para
	 * @return
	 * @throws Exception
	 */
	public CoreReturnObject doQueryApply(HashMap<String,Object> para)throws Exception{
		String sql = "";
		String sql1 = "";
		if(para.containsKey("applytype") && para.get("applytype") != null
				&& !StringUtil.isEmpty(para.get("applytype").toString())){
			if(para.get("applytype").equals("0")){
				sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.doQueryApplyOffline");
			}else if(para.get("applytype").equals("1")){
				sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.doQueryApplyYC");
			}
		}


		if (para.containsKey("start") && para.get("start") != null
				&& !StringUtil.isEmpty(para.get("start").toString())) {
			sql1 += " AND M.APPLY_FLAG_TIME >=TO_DATE('" + para.get("start")
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND M.APPLY_FLAG_TIME <=TO_DATE('"
					+ para.get("end") + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}

		if(para.containsKey("applyno") && para.get("applyno") !=null
				&& !StringUtil.isEmpty(para.get("applyno").toString())){
			sql1 += " AND M.APPLY_RESULT_NO = '"+para.get("applyno")+"'";
		}

		if(para.containsKey("judgeno") && para.get("judgeno") !=null
				&& !StringUtil.isEmpty(para.get("judgeno").toString())){
			sql1 += " AND M.JUDGE_STOVE_NO = '"+para.get("judgeno")+"'";
		}

		if(para.containsKey("validChk") && para.get("validChk") !=null
				&& !StringUtil.isEmpty(para.get("validChk").toString())){
			if (para.get("validChk").equals("不包含无效")){
				if(para.get("applytype").equals("0")){
					sql1 += " AND M.VALIDFLAG = '有效'";
				}else{
					sql1 += " AND M.VALIDFLAG = '1'";
				}
			}
		}

		if (para.containsKey("plineCodes") && para.get("plineCodes") != null
				&& para.get("plineCodes") instanceof String[]) {

			sql1 += CoreConverter.toSqlConditionString("M.PLINE_CODE",
					(String[]) para.get("plineCodes"));

		} else {

			throw new Exception("无权限");
		}

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




	public YdmOverstockpipeResultEntity getResult(Connection con,
			String ResultNo) throws SQLException {

		String sql = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.doQueryResult");
		sql += " AND T.RESULT_NO ='" + ResultNo + "'";
		PreparedStatement ps = con.prepareStatement(sql);

		ResultSet rs = ps.executeQuery();
		List<YdmOverstockpipeResultEntity> resultEntities = EntityTool
				.getEntitysByRs(rs, YdmOverstockpipeResultEntity.class);
		rs.close();
		ps.close();

		if (resultEntities == null || resultEntities.size() <= 0) {
			return null;
		}
		return resultEntities.get(0);
	}

	/**
	 * 离线转压库
	 * 
	 * @param offlines
	 * @param userName
	 * @return
	 * @throws Exception
	 */
	public CoreReturnObject DoHandle(ArrayList<String> offlines, String userName)
			throws Exception {
		return DoHandle(offlines,userName,"120501");
	}
	public CoreReturnObject DoHandle(ArrayList<String> offlines, String userName, String supp)
			throws Exception {

		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();

		try {
			connection.setAutoCommit(false); //

			if (offlines == null || offlines.size() <= 0)
				throw new Exception("请选择压库管！");

			for (String offline : offlines) {
				OfflineResultEntity data = EntityTool.getEntityByJSONStr(
						offline, OfflineResultEntity.class);
				if (StringUtil.isEmpty(data.getResultNo()))
					throw new Exception("炉号【" + data.getJudgeStoveNo()
							+ "】数据异常！");

				OfflineResultEntity oldData = getData(connection, data
						.getResultNo());

				if (oldData == null) {
					throw new Exception("炉号【" + data.getJudgeStoveNo()
							+ "】数据异常, 找不到离线数据，请刷新数据");
				}

				// 生成送判单号
				String jugdeApplyNo = getJugdeApplyNo(data.getPlineCode(),
						"801402", connection);

				// 生成入库单号
				String InNo = FrmMcpLoading.querySendIn(connection, "800701");

				// 处理离线表
				HandleOffline(connection, oldData, userName);

				// 处理库存数据
				HandleMatData(connection, oldData, jugdeApplyNo);

				// 增加入库记录
				AddInstoreRecord(connection, oldData, InNo);

				// 申请判定
				ApplyJudge(connection, oldData, userName, supp);

				// 处理个工序点管号队列
				HandlePort(connection, oldData, jugdeApplyNo, InNo);

				// 增加压库送判记录
				YdmOverstockpipeResultEntity newEntity = new YdmOverstockpipeResultEntity();
				newEntity.setResultNo(GetId(connection, oldData.getPlineCode()));
				newEntity.setResultNoLx(oldData.getResultNo());
				newEntity.setOutstockDoc(InNo);
				newEntity.setJugdeApplyCode(jugdeApplyNo);
				newEntity.setProUser(userName);
				newEntity.setJudgeStoveNo(oldData.getJudgeStoveNo());
				newEntity.setBatchNo(oldData.getBatchNo());
				newEntity.setActCount(oldData.getOfflineNum());
				newEntity.setActWeight(oldData.getOfflineWt());
				newEntity.setProcessCode(oldData.getProcess());
				newEntity.setPlineCode(oldData.getPlineCode());
				newEntity.setPlineName(oldData.getPlineName());
				newEntity.setHeatPlanNo(oldData.getHeatPlanNo());
				newEntity.setFlag("1"); // 离线转压库
				newEntity.setOutstockDoc1("");
				newEntity.setOutstockDoc2("");
				String sqlAdd = CoreXmlSqlParsersFactory
						.getSql("OverstockPipe.doAdd");
				sqlAdd = EntityTool.fillSqlByEntity(sqlAdd, newEntity);
				PreparedStatement pst = connection.prepareStatement(sqlAdd);
				int count = pst.executeUpdate();
				pst.close();

			}

			core.setV_errMsg("操作成功！");
			core.setResult(1);
			connection.commit();

		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;

	}

	/**
	 * 余材转压库
	 * 
	 * @param offlines
	 * @param userName
	 * @return
	 * @throws Exception
	 */
	public CoreReturnObject DoHandle2(ArrayList<String> offlines,
									  String userName) throws Exception {
		return DoHandle2(offlines,userName,"120501");
	}
	public CoreReturnObject DoHandle2(ArrayList<String> offlines,
			String userName,String supp) throws Exception {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); //
			if (offlines == null || offlines.size() <= 0)
				throw new Exception("请选择压库管！");
			Date now = new Date();
			String yearMoth = "";//改25号结转
			for (String offline : offlines) {
				MatBcMEntity data = EntityTool.getEntityByJSONStr(offline,
						MatBcMEntity.class);
				yearMoth = com.steering.common.StringTool.GetBalYear(now,com.steering.common.StringTool.GetSupplyUnit(data.getPlineCode()));//改25号结转

				// 生成送判单号
				String jugdeApplyNo = getJugdeApplyNo(data.getPlineCode(),
						"801402", connection);

				// 生成改判入库单号
				String InNo = FrmMcpLoading.querySendIn(connection, "800706");
				
				// 生成产权出库单号
				String outCqNO = FrmMcpLoading.querySendOut(connection, "800809","");
				// 生成改判出库单号
				String outGpNO = FrmMcpLoading.querySendOut(connection, "800808","");

				// 处理库存数据
				HandleMatData2(connection, data, jugdeApplyNo,userName,InNo,outCqNO,outGpNO,yearMoth,supp);

				// 申请判定
				ApplyJudge2(connection, data, userName,jugdeApplyNo,supp);

				// 增加压库送判记录
				YdmOverstockpipeResultEntity newEntity = new YdmOverstockpipeResultEntity();
				newEntity.setResultNo(GetId(connection, data.getPlineCode()));
				newEntity.setResultNoLx(data.getProcessCdoe()
						+ data.getJudgeStoveNo() + data.getBatchNo());
				newEntity.setOutstockDoc(InNo);
				newEntity.setJugdeApplyCode(jugdeApplyNo);
				newEntity.setProUser(userName);
				newEntity.setJudgeStoveNo(data.getJudgeStoveNo());
				newEntity.setBatchNo(data.getBatchNo());
				newEntity.setActCount(data.getActCount());
				newEntity.setActWeight(data.getActWeight());
				newEntity.setProcessCode(data.getProcessCdoe());
				newEntity.setPlineCode(data.getPlineCode());
				newEntity.setPlineName(data.getPlineName());
				newEntity.setHeatPlanNo(data.getHeatPlanNo());
				newEntity.setFlag("2"); // 余材转压库
				newEntity.setOutstockDoc1(outCqNO);
				newEntity.setOutstockDoc2(outGpNO);
				String sqlAdd = CoreXmlSqlParsersFactory
						.getSql("OverstockPipe.doAdd");
				sqlAdd = EntityTool.fillSqlByEntity(sqlAdd, newEntity);
				PreparedStatement pst = connection.prepareStatement(sqlAdd);
				int count = pst.executeUpdate();
				pst.close();

			}

			core.setV_errMsg("操作成功！");
			core.setResult(1);
			connection.commit();

		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;

	}

	/**
	 * 撤销转压库
	 * 
	 * @param results
	 * @param userName
	 * @return
	 * @throws Exception
	 */
	public CoreReturnObject CancelHandle(ArrayList<String> results,
			String userName) throws Exception {

		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();

		try {
			connection.setAutoCommit(false); //

			if (results == null || results.size() <= 0)
				throw new Exception("请选择送判记录！");
			Date now = new Date();
			SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
			String yearMoth = df.format(now);

			for (String result : results) {
				YdmOverstockpipeResultEntity data = EntityTool
						.getEntityByJSONStr(result,
								YdmOverstockpipeResultEntity.class);

				YdmOverstockpipeResultEntity oldData = getResult(connection,
						data.getResultNo());

				if (oldData == null) {
					throw new Exception("炉号【" + data.getJudgeStoveNo()
							+ "】数据异常, 找不到送判记录，请刷新数据");
				}
				
				String result1 = "";
				String yearMoth1 = "";
				String sql = CoreXmlSqlParsersFactory
						.getSql("OverstockPipe.getJudgeResult");

				PreparedStatement pst1 = connection.prepareStatement(sql);
				pst1.setObject(1, data.getJugdeApplyCode());
				ResultSet rs = pst1.executeQuery();
				if (rs.next()) {
					result1 = rs.getString("JUDGE_TOLRESULT_CODE");
					yearMoth1 = rs.getString("BAL_YEAR_MONTH");
				}
				rs.close();
				pst1.close();
				
				if (!StringUtil.isEmpty(result1))
					throw new Exception("炉号【" + data.getJudgeStoveNo()
							+ "】已成品综合判定,请先撤销成品综合判定！！");
				/*if(!yearMoth.equals(yearMoth1)){
					core.setV_errMsg("已跨月数据，不能撤销!");
					return core;
				}*/
					
				if (oldData.getFlag().equals("离线转压库")) {
					// 还原离线表
					RecoverOffline(connection, oldData);

					// 还原库存数据
					RecoverMatData(connection, oldData);

					// 删除入库记录
					DeleteInstoreRecord(connection, oldData);

					// 删除送判记录
					CancelApplyJudge(connection, oldData);

					// 处理个工序点管号队列
					RecoverPort(connection, oldData);

					// 作废送判实绩
					String sqlAdd = CoreXmlSqlParsersFactory
							.getSql("OverstockPipe.doDelete");
					PreparedStatement pst = connection.prepareStatement(sqlAdd);
					pst.setObject(1, userName);
					pst.setObject(2, oldData.getResultNo());
					int count = pst.executeUpdate();
					pst.close();
				} else if (oldData.getFlag().equals("余材转压库")) {
					// 还原库存数据
					RecoverMatData3(connection, oldData);

					// 删除入库记录
					//DeleteInstoreRecord(connection, oldData);
					
					// 删除出库记录
					//DeleteOutRecord(connection, oldData);

					// 删除送判记录
					CancelApplyJudge(connection, oldData);
					// 作废送判实绩
					String sqlAdd = CoreXmlSqlParsersFactory
							.getSql("OverstockPipe.doDelete");
					PreparedStatement pst = connection.prepareStatement(sqlAdd);
					pst.setObject(1, userName);
					pst.setObject(2, oldData.getResultNo());
					int count = pst.executeUpdate();
					pst.close();
				}

			}

			core.setV_errMsg("操作成功！");
			core.setResult(1);
			connection.commit();

		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;

	}

	/**
	 * 处理离线表
	 * 
	 * @param con
	 * @param data
	 */
	public void HandleOffline(Connection con, OfflineResultEntity data,
			String userName) throws Exception {

		if (StringUtil.isEmpty(data.getOfflineNum())
				|| !StringTool.isInteger(data.getOfflineNum())
				|| Integer.parseInt(data.getOfflineNum()) <= 0) {
			throw new Exception("炉号【" + data.getJudgeStoveNo()
					+ "】离线支数必须大于0, 请确认！！");
		}

		int UpdateNum = 0;

		if (data.getProcess().equals("E")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.HandleOfflineE");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getOfflineNum());
			pst.setObject(2, data.getOfflineWt());
			pst.setObject(3, userName);
			pst.setObject(4, data.getResultNo());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != 1) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 更新离线数据失败！！");
			}

		} else if (data.getProcess().equals("F")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.HandleOfflineF");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getOfflineNum());
			pst.setObject(2, data.getOfflineWt());
			pst.setObject(3, userName);
			pst.setObject(4, data.getResultNo());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != 1) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 更新离线数据失败！！");
			}

		} else if (data.getProcess().equals("G")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.HandleOfflineG");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getOfflineNum());
			pst.setObject(2, data.getOfflineWt());
			pst.setObject(3, userName);
			pst.setObject(4, data.getResultNo());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != 1) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 更新离线数据失败！！");
			}
		} else if (data.getProcess().equals("D")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.HandleOfflineD");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getOfflineNum());
			pst.setObject(2, data.getJudgeStoveNo());
			pst.setObject(3, data.getResultNo());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != 1) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 更新离线数据失败！！");
			}
		} else {
			throw new Exception("炉号【" + data.getJudgeStoveNo()
					+ "】送判失败, 不支持该工序压库管送判！");

		}

	}

	/**
	 * 还原离线表
	 * 
	 * @param con
	 * @param data
	 */
	public void RecoverOffline(Connection con, YdmOverstockpipeResultEntity data)
			throws Exception {

		int UpdateNum = 0;

		if (data.getProcessCode().equals("E")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverOfflineE");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getActCount());
			pst.setObject(2, data.getActWeight());
			pst.setObject(3, data.getResultNoLx());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != 1) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】,  还原离线数据失败！！");
			}

		} else if (data.getProcessCode().equals("F")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverOfflineF");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getActCount());
			pst.setObject(2, data.getActWeight());
			pst.setObject(3, data.getResultNoLx());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != 1) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】,  还原离线数据失败！！");
			}

		} else if (data.getProcessCode().equals("G")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverOfflineG");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getActCount());
			pst.setObject(2, data.getActWeight());
			pst.setObject(3, data.getResultNoLx());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != 1) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 还原离线数据失败！！");
			}
		} else if (data.getProcessCode().equals("D")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverOfflineD");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getActCount());
			pst.setObject(2, data.getJudgeStoveNo());
			pst.setObject(3, data.getResultNoLx());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != 1) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】,  还原离线数据失败！！");
			}

		} else {
			throw new Exception("炉号【" + data.getJudgeStoveNo()
					+ "】撤销送判失败, 不支持该工序压库管撤销送判！");

		}

	}

	/**
	 * 处理各工序点数据
	 * 
	 * @param con
	 * @param data
	 */
	public void HandlePort(Connection con, OfflineResultEntity data,
			String jugdeApplyNo, String inNo) throws Exception {
		int UpdateNum = 0;

		if (data.getProcess().equals("E")) {
			// 更新管号队列 入库标志 送判单号 材料状态
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.HandlePortE");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, jugdeApplyNo);
			pst.setObject(2, data.getResultNo());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getOfflineNum())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 更新管号队列信息失败！");
			}

			// 管号全部送判 直接做下线结炉操作。
			int count = 0;

			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpInStore.QueryVrpPortFailPiece");
			sql = EntityTool.fillSqlByEntity(sql, data);
			pst = con.prepareStatement(sql);
			ResultSet rs = pst.executeQuery();
			if (rs.next()) {
				count = Integer.parseInt(rs.getString("ACT_COUNT"));
			}
			rs.close();
			pst.close();

			if (count == 0) {

				String updateSql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpInStore.UpdateNodeFlag");
				updateSql = EntityTool.fillSqlByEntity(updateSql, data);
				pst = con.prepareStatement(updateSql);
				pst.executeUpdate();
			}

		} else if (data.getProcess().equals("F")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.HandlePortF");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, jugdeApplyNo);
			pst.setObject(2, data.getResultNo());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getOfflineNum())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】,更新管号队列信息失败！");
			}

			// 管号全部送判 直接做下线结炉操作。
			int count = 0;

			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpApplyNew.QueryVrpPortPiece");
			sql = EntityTool.fillSqlByEntity(sql, data);
			pst = con.prepareStatement(sql);
			ResultSet rs = pst.executeQuery();
			if (rs.next()) {
				count = Integer.parseInt(rs.getString("ACT_COUNT"));
			}
			rs.close();
			pst.close();

			if (count == 0) {

				String updateSql = CoreXmlSqlParsersFactory
						.getSql("FrmHttInStore.UpdateNodeFlag");
				updateSql = EntityTool.fillSqlByEntity(updateSql, data);
				pst = con.prepareStatement(updateSql);
				pst.executeUpdate();
			}

		} else if (data.getProcess().equals("G")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.HandlePortG");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, jugdeApplyNo);
			pst.setObject(2, data.getResultNo());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getOfflineNum())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 更新管号队列信息失败！");
			}

			// 管号全部送判 直接做下线结炉操作。
			int count = 0;

			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpApplyNew.QueryMchPortPiece");
			sql = sql.replace("#HEAT_PLAN_NO_OLD#", data.getHeatPlanNo())
					.replace("#JUDGE_STOVE_NO#", data.getJudgeStoveNo());

			pst = con.prepareStatement(sql);
			ResultSet rs = pst.executeQuery();
			if (rs.next()) {
				count = Integer.parseInt(rs.getString("ACT_COUNT"));
			}
			rs.close();
			pst.close();

			if (count == 0) {

				String updateSql = CoreXmlSqlParsersFactory
						.getSql("FrmMchInStore.UpdateNodeFlag");
				updateSql = EntityTool.fillSqlByEntity(updateSql, data);
				pst = con.prepareStatement(updateSql);
				pst.executeUpdate();
			}
		} else if (data.getProcess().equals("D")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.HandlePortD");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, jugdeApplyNo);
			pst.setObject(2, data.getJudgeStoveNo());
			pst.setObject(3, data.getStationCode());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getOfflineNum())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】,更新管号队列信息失败！");
			}

		}
	}

	public void RecoverPort(Connection con, YdmOverstockpipeResultEntity data)
			throws Exception {
		int UpdateNum = 0;

		if (data.getProcessCode().equals("E")) {

			// 管号全部送判 直接撤销下线结炉
			int count = 0;

			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpInStore.QueryVrpPortFailPiece");
			sql = EntityTool.fillSqlByEntity(sql, data);
			PreparedStatement pst = con.prepareStatement(sql);
			ResultSet rs = pst.executeQuery();
			if (rs.next()) {
				count = Integer.parseInt(rs.getString("ACT_COUNT"));
			}
			rs.close();
			pst.close();

			if (count == 0) {

				String updateSql = CoreXmlSqlParsersFactory
						.getSql("FrmMchInStore.CancelupdateNodeFlag");
				updateSql = com.steering.comm.converter.EntityTool
						.fillSqlByEntity(updateSql, data);
				pst = con.prepareStatement(updateSql);
				pst.executeUpdate();
			}

			// 更新管号队列 入库标志 送判单号 材料状态
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverPortE");
			pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getResultNoLx());
			pst.setObject(2, data.getJugdeApplyCode());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 更新管号队列信息失败！");
			}

		} else if (data.getProcessCode().equals("F")) {
			// 管号全部送判 直接做下线结炉操作。
			int count = 0;

			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpApplyNew.QueryVrpPortPiece");
			sql = EntityTool.fillSqlByEntity(sql, data);
			PreparedStatement pst = con.prepareStatement(sql);
			ResultSet rs = pst.executeQuery();
			if (rs.next()) {
				count = Integer.parseInt(rs.getString("ACT_COUNT"));
			}
			rs.close();
			pst.close();

			if (count == 0) {

				String updateSql = CoreXmlSqlParsersFactory
						.getSql("FrmHttInStore.CancelupdateNodeFlag");
				updateSql = EntityTool.fillSqlByEntity(updateSql, data)
						.replace("#REAL_PROCESS_SEQ#", "1");
				pst = con.prepareStatement(updateSql);
				pst.executeUpdate();
			}

			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverPortF");
			pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getResultNoLx());
			pst.setObject(2, data.getJugdeApplyCode());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】,更新管号队列信息失败！");
			}

		} else if (data.getProcessCode().equals("G")) {
			// 管号全部送判 直接做下线结炉操作。
			int count = 0;

			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpApplyNew.QueryMchPortPiece");
			sql = sql.replace("#HEAT_PLAN_NO_OLD#", data.getHeatPlanNo())
					.replace("#JUDGE_STOVE_NO#", data.getJudgeStoveNo());

			PreparedStatement pst = con.prepareStatement(sql);
			ResultSet rs = pst.executeQuery();
			if (rs.next()) {
				count = Integer.parseInt(rs.getString("ACT_COUNT"));
			}
			rs.close();
			pst.close();

			if (count == 0) {

				String updateSql = CoreXmlSqlParsersFactory
						.getSql("FrmMchInStore.CancelupdateNodeFlag");
				updateSql = EntityTool.fillSqlByEntity(updateSql, data);
				pst = con.prepareStatement(updateSql);
				pst.executeUpdate();
			}

			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverPortG");
			pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getResultNoLx());
			pst.setObject(2, data.getJugdeApplyCode());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 更新管号队列信息失败！");
			}

		} else if (data.getProcessCode().equals("D")) {

			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverPortD");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getJudgeStoveNo());
			pst.setObject(2, data.getJugdeApplyCode());
			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】,更新管号队列信息失败！");
			}

		}
	}

	/**
	 * 增加产出入库记录(离线)
	 * 
	 * @param con
	 * @param data
	 */
	public void AddInstoreRecord(Connection con, OfflineResultEntity data,
			String inDoc) throws Exception {
		int UpdateNum = 0;

		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.AddInstoreRecord");
		PreparedStatement pst = con.prepareStatement(sqlAdd);
		pst.setObject(1, inDoc);
		pst.setObject(2, inDoc);
		pst.setObject(3, data.getResultNo());
		UpdateNum = pst.executeUpdate();
		pst.close();

		if (UpdateNum != Integer.parseInt(data.getOfflineNum())) {
			throw new Exception("炉号【" + data.getJudgeStoveNo() + "】, 库存不足！！");
		}
	}

	/**
	 * 增加产出入库记录（余材）
	 * 
	 * @param con
	 * @param data
	 * @param inDoc
	 * @throws Exception
	 */
	public void AddInstoreRecord2(Connection con, MatBcMEntity data,
			String inDoc) throws Exception {
		int UpdateNum = 0;

		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.AddInstoreRecord2");
		PreparedStatement pst = con.prepareStatement(sqlAdd);
		pst.setObject(1, inDoc);
		pst.setObject(2, inDoc);
		pst.setObject(3, data.getJudgeStoveNo());
		pst.setObject(4, data.getPlineCode());
		pst.setObject(5, data.getProcessCdoe() + data.getJudgeStoveNo()
				+ data.getBatchNo());
		UpdateNum = pst.executeUpdate();
		pst.close();
	}

	/**
	 * 删除入库记录
	 * 
	 * @param con
	 * @param data
	 * @throws Exception
	 */
	public void DeleteInstoreRecord(Connection con,
			YdmOverstockpipeResultEntity data) throws Exception {
		int UpdateNum = 0;

		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.DeleteInstoreRecord");
		PreparedStatement pst = con.prepareStatement(sqlAdd);
		pst.setObject(1, data.getOutstockDoc());
		UpdateNum = pst.executeUpdate();
		pst.close();

		if (UpdateNum != Integer.parseInt(data.getActCount())) {
			throw new Exception("炉号【" + data.getJudgeStoveNo()
					+ "】,  无足够的入库记录！！");
		}
	}
	
	/**
	 * 删除出库记录
	 * @param con
	 * @param data
	 * @throws Exception
	 */
	public void DeleteOutRecord(Connection con,
			YdmOverstockpipeResultEntity data) throws Exception {
		int UpdateNum = 0;

		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.DeleteOutRecord");
		PreparedStatement pst = con.prepareStatement(sqlAdd);
		pst.setObject(1, data.getOutstockDoc1());
		pst.setObject(2, data.getOutstockDoc2());
		UpdateNum = pst.executeUpdate();
		pst.close();

		if (UpdateNum != Integer.parseInt(data.getActCount())) {
			throw new Exception("炉号【" + data.getJudgeStoveNo()
					+ "】,  无足够的入库记录！！");
		}
	}

	/**
	 * 处理库存数据（离线）
	 * 
	 * @param con
	 * @param data
	 */
	public void HandleMatData(Connection con, OfflineResultEntity data,
			String jugdeApplyNo) throws Exception {

		int UpdateNum = 0;

		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.HandleMatData");
		PreparedStatement pst = con.prepareStatement(sqlAdd);
		pst.setObject(1, jugdeApplyNo);
		pst.setObject(2, data.getResultNo());

		UpdateNum = pst.executeUpdate();
		pst.close();

		if (UpdateNum != Integer.parseInt(data.getOfflineNum())) {
			throw new Exception("炉号【" + data.getJudgeStoveNo() + "】, 库存不足！！");
		}

	}

	/**
	 * 处理库存数据(余材)
	 * 
	 * @param con
	 * @param data
	 * @param jugdeApplyNo
	 * @throws Exception
	 */
	public void HandleMatData2(Connection con, MatBcMEntity data,
			String jugdeApplyNo,String userName,String InNo,String outCqNO,String outGpNO,String yearMoth,String supp) throws Exception {
		int UpdateNum = 0;
		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.HandleMatData2");
		PreparedStatement pst = con.prepareStatement(sqlAdd);
		pst.setObject(1, jugdeApplyNo);
		pst.setObject(2, data.getJudgeStoveNo());
		pst.setObject(3, data.getPlineCode());
		pst.setObject(4, data.getBatchNo());
		pst.setObject(5, userName);
		pst.setObject(6, yearMoth);
		pst.setObject(7, outGpNO);
		pst.setObject(8, outCqNO);
		pst.setObject(9, InNo);
		pst.setObject(10, data.getActCount());
		pst.setObject(11, supp);

		UpdateNum = pst.executeUpdate();
		pst.close();
	}

	/**
	 * 还原库存数据（离线）
	 * 
	 * @param con
	 * @param data
	 * @throws Exception
	 */
	public void RecoverMatData(Connection con, YdmOverstockpipeResultEntity data)
			throws Exception {

		int UpdateNum = 0;

		if (data.getProcessCode().equals("E")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverMatDataE");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getResultNoLx());
			pst.setObject(2, data.getOutstockDoc());

			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 库存不足！！");
			}

		} else if (data.getProcessCode().equals("F")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverMatDataF");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getResultNoLx());
			pst.setObject(2, data.getOutstockDoc());

			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 库存不足！！");
			}

		} else if (data.getProcessCode().equals("G")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverMatDataG");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getResultNoLx());
			pst.setObject(2, data.getOutstockDoc());

			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 库存不足！！");
			}
		} else if (data.getProcessCode().equals("D")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverMatDataD");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getResultNoLx());
			pst.setObject(2, data.getOutstockDoc());

			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 库存不足！！");
			}
		} else {
			throw new Exception("炉号【" + data.getJudgeStoveNo()
					+ "】撤销送判失败, 不支持该工序压库管撤销送判！");

		}

	}

	/**
	 * 还原库存数据（余材）
	 * 
	 * @param con
	 * @param data
	 * @throws Exception
	 */
	public void RecoverMatData2(Connection con,
			YdmOverstockpipeResultEntity data) throws Exception {

		int UpdateNum = 0;

		if (data.getProcessCode().equals("E")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverMatDataE2");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getHeatPlanNo());
			pst.setObject(2, data.getOutstockDoc());

			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 库存不足！！");
			}

		} else if (data.getProcessCode().equals("F")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverMatDataF2");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getHeatPlanNo());
			pst.setObject(2, data.getOutstockDoc());

			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 库存不足！！");
			}

		} else if (data.getProcessCode().equals("G")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverMatDataG2");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getHeatPlanNo());
			pst.setObject(2, data.getOutstockDoc());

			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 库存不足！！");
			}
		} else if (data.getProcessCode().equals("D")) {
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverMatDataD2");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getHeatPlanNo());
			pst.setObject(2, data.getOutstockDoc());

			UpdateNum = pst.executeUpdate();
			pst.close();

			if (UpdateNum != Integer.parseInt(data.getActCount())) {
				throw new Exception("炉号【" + data.getJudgeStoveNo()
						+ "】, 库存不足！！");
			}
		} else {
			throw new Exception("炉号【" + data.getJudgeStoveNo()
					+ "】撤销送判失败, 不支持该工序压库管撤销送判！");

		}

	}
	
	/**
	 * 还原库存数据（余材）
	 * 
	 * @param con
	 * @param data
	 * @throws Exception
	 */
	public void RecoverMatData3(Connection con,
			YdmOverstockpipeResultEntity data) throws Exception {

		int UpdateNum = 0;


			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("OverstockPipe.RecoverMatData3");
			PreparedStatement pst = con.prepareStatement(sqlAdd);
			pst.setObject(1, data.getJugdeApplyCode());
			pst.setObject(2, data.getJudgeStoveNo());
			pst.setObject(3, data.getBatchNo());
			//pst.setObject(4, data.getPlineCode());
			pst.setObject(4, data.getOutstockDoc1());

			UpdateNum = pst.executeUpdate();
			pst.close();

			

	}

	/**
	 * 压库管送判（离线）
	 * 
	 * @param con
	 * @param data
	 * @return
	 */
	public void ApplyJudge(Connection con, OfflineResultEntity data,
			String userName,String supp) throws Exception {
		int UpdateNum = 0;

		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.ApplyJudge");
		PreparedStatement pst = con.prepareStatement(sqlAdd);
		pst.setObject(1, userName);
		pst.setObject(2, supp);
		pst.setObject(3, supp);
		pst.setObject(4, data.getResultNo());

		UpdateNum = pst.executeUpdate();
		pst.close();

		if (UpdateNum != 1) {
			throw new Exception("炉号【" + data.getJudgeStoveNo() + "】, 送判失败！！");
		}

	}

	/**
	 * 压库管送判（余材）
	 * 
	 * @param con
	 * @param data
	 * @param userName
	 * @throws Exception
	 */
	public void ApplyJudge2(Connection con, MatBcMEntity data, String userName,String jugdeApplyNo)
			throws Exception {
		ApplyJudge2(con, data, userName, jugdeApplyNo, "120501");
	}
	public void ApplyJudge2(Connection con, MatBcMEntity data, String userName,String jugdeApplyNo,String supp)
			throws Exception {
		int UpdateNum = 0;

		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.ApplyJudge2");
		PreparedStatement pst = con.prepareStatement(sqlAdd);
		pst.setObject(1, supp);
		pst.setObject(2, userName);
		pst.setObject(3, supp);
		pst.setObject(4, supp);
		pst.setObject(5, supp);
		pst.setObject(6, data.getJudgeStoveNo());
		//pst.setObject(3, data.getPlineCode());
		pst.setObject(7, data.getProcessCdoe() + data.getJudgeStoveNo()
				+ data.getBatchNo());
		pst.setObject(8, jugdeApplyNo);

		UpdateNum = pst.executeUpdate();
		pst.close();

		if (UpdateNum != 1) {
			throw new Exception("炉号【" + data.getJudgeStoveNo() + "】, 送判失败！！");
		}

	}

	/**
	 * 删除送判记录
	 * 
	 * @param con
	 * @param data
	 * @throws Exception
	 */
	public void CancelApplyJudge(Connection con,
			YdmOverstockpipeResultEntity data) throws Exception {
		String result = "";
		String sql = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.getJudgeResult");

		PreparedStatement pst = con.prepareStatement(sql);
		pst.setObject(1, data.getJugdeApplyCode());
		ResultSet rs = pst.executeQuery();
		if (rs.next()) {
			result = rs.getString("JUDGE_TOLRESULT_CODE");
		}
		rs.close();
		pst.close();

		if (!StringUtil.isEmpty(result))
			throw new Exception("炉号【" + data.getJudgeStoveNo()
					+ "】已成品综合判定,请先撤销成品综合判定！！");

		int UpdateNum = 0;

		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.CancelApplyJudge");
		pst = con.prepareStatement(sqlAdd);
		pst.setObject(1, data.getJugdeApplyCode());

		UpdateNum = pst.executeUpdate();
		pst.close();

		if (UpdateNum != 1) {
			throw new Exception("炉号【" + data.getJudgeStoveNo() + "】, 撤销送判失败！！");
		}

	}

	/**
	 * 生成判定单号
	 * @param plineCode
	 * @param flag
	 * @param conn
	 * @return
	 * @throws Exception
	 */
	public String getJugdeApplyNo(String plineCode, String flag, Connection conn)
			throws Exception {
		String jugdeApplyNo = "";
		PreparedStatement psta = null;

		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("OverstockPipe.jugdeApplyNo");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, plineCode);
		psta.setString(2, flag);
		psta.setString(3, plineCode);
		psta.setString(4, flag);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			jugdeApplyNo = rs.getString("JUGDE_APPLY_CODE");
		}
		rs.close();
		psta.close();
		return jugdeApplyNo;

	}

	/**
	 * 获取转压库申请编号
	 * @param conn
	 * @return
	 * @throws Exception
	 */
	public String getApplyResultNo(Connection conn)throws Exception{
		String ApplyResultNo = "";
		PreparedStatement ps = null;
		String sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.ApplyResultNo");
		ps = conn.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		if(rs.next()){
			ApplyResultNo = rs.getString("APPLY_RESULT_NO");
		}
		rs.close();
		ps.close();
		return ApplyResultNo;
	}


	/**
	 * 离线压库申请
	 * @param applylists
	 * @param userName
	 * @return
	 */
	public CoreReturnObject ApplyOfflineYK(ArrayList<String> applylists,String userName){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			connection.setAutoCommit(false);

			if(applylists == null || applylists.size() <=0)
				throw new Exception("请选择压库管!");

			for(String applylist : applylists){
				OfflineResultEntity reusltEntity = EntityTool.getEntityByJSONStr(
						applylist,OfflineResultEntity.class
				);
				YdmOverstockpipeApplyEntity applyEntity = new YdmOverstockpipeApplyEntity();

				//生成转压库申请编号
				String ApplyResultNo = getApplyResultNo(connection);


				applyEntity.setApplyResultNo(ApplyResultNo);
				applyEntity.setJudgeStoveNo(reusltEntity.getJudgeStoveNo());
				applyEntity.setBatchNo(reusltEntity.getBatchNo());
				applyEntity.setPlineCode(reusltEntity.getPlineCode());
				applyEntity.setPlineName(reusltEntity.getPlineName());
				applyEntity.setProcessCode(reusltEntity.getProcess());
				applyEntity.setActCount(reusltEntity.getOfflineNum());
				applyEntity.setActWeight(reusltEntity.getOfflineWt());
				applyEntity.setApplyFlag("1");
				applyEntity.setApplyFlagName(userName);
				applyEntity.setHeatPlanNo(reusltEntity.getHeatPlanNo());
				applyEntity.setValidflag("1");
				applyEntity.setProduccode(reusltEntity.getProduccode());
				applyEntity.setProducname(reusltEntity.getProducname());
				applyEntity.setSteelcode(reusltEntity.getSteelcode());
				applyEntity.setSteelname(reusltEntity.getSteelname());
				applyEntity.setGradecode(reusltEntity.getGradecode());
				applyEntity.setGradename(reusltEntity.getGradename());
				applyEntity.setSpecCode(reusltEntity.getSpecCode());
				applyEntity.setSpecName(reusltEntity.getSpecName());
				applyEntity.setModelCode(reusltEntity.getModelCode());
				applyEntity.setModelDesc(reusltEntity.getModelDesc());
				applyEntity.setStdCode(reusltEntity.getStdCode());
				applyEntity.setStdName(reusltEntity.getStdName());
				applyEntity.setStdStyle(reusltEntity.getStdStyle());
				applyEntity.setStdStyleDesc(reusltEntity.getStdStyleDesc());
				applyEntity.setOrderNo(reusltEntity.getOrderNo());
				applyEntity.setOrderSeq(reusltEntity.getOrderSeq());
				applyEntity.setMemo(reusltEntity.getycmemo());

				String sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.ApplyOfflineYK");
				sql = EntityTool.fillSqlByEntity(sql,applyEntity);
				PreparedStatement ps = connection.prepareStatement(sql);
				ps.executeUpdate();

				if(reusltEntity.getProcess().equals("D")){
					String sqladd = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessD");
					sqladd += "AND T.LOT_NO = '"+reusltEntity.getLotNo()+"'";
					sqladd += "AND T.JUDGE_STOVE_NO = '"+reusltEntity.getJudgeStoveNo()+"'";
					sqladd += "AND T.OFFLINE_PRO = '"+reusltEntity.getStationCode()+"'";
					PreparedStatement psadd = connection.prepareStatement(sqladd);
					psadd.setObject(1,ApplyResultNo);
					psadd.addBatch();
					psadd.executeBatch();
				}else if(reusltEntity.getProcess().equals("F")){
					String sqladd = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessF");
					sqladd += "AND T.RESULT_NO = '"+reusltEntity.getResultNo()+"'";
					PreparedStatement psadd = connection.prepareStatement(sqladd);
					psadd.setObject(1,ApplyResultNo);
					psadd.addBatch();
					psadd.executeBatch();
				}else if (reusltEntity.getProcess().equals("G")){
					String sqladd = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessG");
					sqladd += "AND T.RESULT_NO = '"+reusltEntity.getResultNo()+"'";
					PreparedStatement psadd = connection.prepareStatement(sqladd);
					psadd.setObject(1,ApplyResultNo);
					psadd.addBatch();
					psadd.executeBatch();
				}else if (reusltEntity.getProcess().equals("E")){
					String sqladd = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessE");
					sqladd += "AND T.RESULT_NO = '"+reusltEntity.getResultNo()+"'";
					PreparedStatement psadd = connection.prepareStatement(sqladd);
					psadd.setObject(1,ApplyResultNo);
					psadd.addBatch();
					psadd.executeBatch();
				}else if (reusltEntity.getProcess().equals("H")){
					String sqladd = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessH");
					sqladd += "AND T.RESULT_NO = '"+reusltEntity.getResultNo()+"'";
					PreparedStatement psadd = connection.prepareStatement(sqladd);
					psadd.setObject(1,ApplyResultNo);
					psadd.addBatch();
					psadd.executeBatch();
				}

			}
			cro.setV_errMsg("申请成功!");
			connection.commit();

		} catch (Exception e) {
			cro.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 cro;
	}


	/**
	 * 离线转压库审核
	 * @param arrayList
	 * @param userName
	 * @return
	 */
	public CoreReturnObject AuditOfflineYK(ArrayList<String> arrayList,String userName){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			connection.setAutoCommit(false);

			if(arrayList == null || arrayList.size()<=0){
				throw new Exception("请选择压库管!");
			}

			for (String auditlist:arrayList){
				YdmOverstockpipeApplyEntity resultEntity = EntityTool.getEntityByJSONStr(auditlist,YdmOverstockpipeApplyEntity.class);
				String applyno = resultEntity.getApplyResultNo();
				String sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.AuditOfflineYK");
				sql += " AND APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"'";
				PreparedStatement ps = connection.prepareStatement(sql);
				ps.setObject(1,userName);
				ps.addBatch();
				ps.executeBatch();
			}

			cro.setV_errMsg("审核通过!");
			connection.commit();
		} catch (Exception e) {
			cro.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 cro;
	}


	/**
	 * 余材压库申请
	 * @param arrayLists
	 * @param userName
	 * @return
	 */
	public CoreReturnObject ApplyYucaiYK(ArrayList<String> arrayLists,String userName){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			connection.setAutoCommit(false);

			if(arrayLists == null || arrayLists.size() <=0)
				throw new Exception("请选择压库管!");

			for(String auditlist : arrayLists){
				MatBcMEntity reusltEntity = EntityTool.getEntityByJSONStr(
						auditlist,MatBcMEntity.class
				);
				YdmOverstockpipeApplyEntity applyEntity = new YdmOverstockpipeApplyEntity();

				//生成转压库申请编号
				String ApplyResultNo = getApplyResultNo(connection);


				applyEntity.setApplyResultNo(ApplyResultNo);
				applyEntity.setJudgeStoveNo(reusltEntity.getJudgeStoveNo());
				applyEntity.setBatchNo(reusltEntity.getBatchNo());
				applyEntity.setPlineCode(reusltEntity.getPlineCode());
				applyEntity.setPlineName(reusltEntity.getPlineName());
				applyEntity.setProcessCode(reusltEntity.getProcessCdoe());
				applyEntity.setActCount(reusltEntity.getActCount());
				applyEntity.setActWeight(reusltEntity.getActWeight());
				applyEntity.setApplyFlag("1");
				applyEntity.setApplyFlagName(userName);
				applyEntity.setHeatPlanNo(reusltEntity.getHeatPlanNo());
				applyEntity.setValidflag("1");

				applyEntity.setProduccode(reusltEntity.getProduccode());
				applyEntity.setProducname(reusltEntity.getProducname());
				applyEntity.setSteelcode(reusltEntity.getSteelcode());
				applyEntity.setSteelname(reusltEntity.getSteelname());
				applyEntity.setGradecode(reusltEntity.getGradecode());
				applyEntity.setGradename(reusltEntity.getGradename());
				applyEntity.setSpecCode(reusltEntity.getSpecCode());
				applyEntity.setSpecName(reusltEntity.getSpecName());
				applyEntity.setModelCode(reusltEntity.getModelCode());
				applyEntity.setModelDesc(reusltEntity.getModelDesc());
				applyEntity.setStdCode(reusltEntity.getStdCode());
				applyEntity.setStdName(reusltEntity.getStdName());
				applyEntity.setStdStyle(reusltEntity.getStdStyle());
				applyEntity.setStdStyleDesc(reusltEntity.getStdStyleDesc());
				applyEntity.setOrderNo(reusltEntity.getOrderNo());
				applyEntity.setOrderSeq(reusltEntity.getOrderSeq());
				applyEntity.setMemo(reusltEntity.getMemo());

				String sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.ApplyYucaiYK");
				sql = EntityTool.fillSqlByEntity(sql,applyEntity);
				PreparedStatement ps = connection.prepareStatement(sql);
				ps.executeUpdate();

				String sqladd = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyYucai");
				if(!reusltEntity.getJudgeStoveNo().equals("") && reusltEntity.getJudgeStoveNo() != null){
					sqladd += " AND T.JUDGE_STOVE_NO = '"+reusltEntity.getJudgeStoveNo()+"'";
				}
				if(!reusltEntity.getBatchNo().equals("") && reusltEntity.getBatchNo() != null){
					sqladd += " AND T.BATCH_NO = '"+reusltEntity.getBatchNo()+"'";
				}
				if(!reusltEntity.getBatchGroudNo().equals("") && reusltEntity.getBatchGroudNo() != null){
					sqladd += " AND T.BATCH_GROUD_NO = '"+reusltEntity.getBatchGroudNo()+"'";
				}
				if(!reusltEntity.getPlineCode().equals("") && reusltEntity.getPlineCode() != null){
					sqladd += " AND T.PLINE_CODE = '"+reusltEntity.getPlineCode()+"'";
				}
				if(!reusltEntity.getHeatPlanNo().equals("") && reusltEntity.getHeatPlanNo() != null){
					sqladd += " AND T.HEAT_PLAN_NO = '"+reusltEntity.getHeatPlanNo()+"'";
				}
				if(!reusltEntity.getMemo().equals("") && reusltEntity.getMemo() != null){
					sqladd += " AND T.MEMO = '"+reusltEntity.getMemo()+"'";
				}
				if(!reusltEntity.getMatStatus().equals("") && reusltEntity.getMatStatus() != null){
					sqladd += " AND T.MAT_STATUS = '"+reusltEntity.getMatStatus()+"'";
				}
				if(!reusltEntity.getActCount().equals("") && reusltEntity.getActCount() != null){
					sqladd += "  AND ROWNUM <= '"+reusltEntity.getActCount()+"'";
				}
				if(!reusltEntity.getSampleFlag().equals("") && reusltEntity.getSampleFlag() != null){
					sqladd += " AND T.SAMPLE_FLAG = '"+reusltEntity.getSampleFlag()+"'";
				}
				sqladd += "AND T.APPLY_RESULT_NO IS NULL";
				PreparedStatement psadd = connection.prepareStatement(sqladd);
				psadd.setObject(1,ApplyResultNo);
				psadd.addBatch();
				psadd.executeBatch();

			}
			cro.setV_errMsg("申请成功!");
			connection.commit();

		} catch (Exception e) {
			cro.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 cro;
	}


	/**
	 * 余材压库审核
	 * @param arrayList
	 * @param userName
	 * @return
	 */
	public CoreReturnObject AuditYucaiYK(ArrayList<String> arrayList,String userName){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			if(arrayList == null || arrayList.size()<=0){
				throw new Exception("请选择压库管!");
			}

			for (String auditlist:arrayList){
				YdmOverstockpipeApplyEntity resultEntity = EntityTool.getEntityByJSONStr(auditlist,YdmOverstockpipeApplyEntity.class);
				String sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.AuditOfflineYK");
				sql += " AND APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"'";
				PreparedStatement ps = connection.prepareStatement(sql);
				ps.setObject(1,userName);
				ps.addBatch();
				ps.executeBatch();
			}

			cro.setV_errMsg("审核通过!");
			connection.commit();
		} catch (Exception e) {
			cro.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 cro;
	}


	/**
	 * 送判界面撤销离线压库申请
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject CancelApplyOffline(ArrayList<String> arrayList){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			connection.setAutoCommit(false);
			if(arrayList == null || arrayList.size()<=0){
				throw new Exception("请选择压库管!");
			}

			for (String applylist:arrayList){
				OfflineResultEntity resultEntity = EntityTool.getEntityByJSONStr(applylist,OfflineResultEntity.class);
				String sqlcancelapply = CoreXmlSqlParsersFactory.getSql("OverstockPipe.CancelApply");
				PreparedStatement pscancel = connection.prepareStatement(sqlcancelapply);
				pscancel.setObject(1,resultEntity.getApplyResultNo());
				pscancel.addBatch();
				pscancel.executeBatch();

				if(resultEntity.getProcess().equals("D")){
					String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessD");
					sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
					PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
					psupdate.setObject(1,"");
					psupdate.addBatch();
					psupdate.executeBatch();
				}else if(resultEntity.getProcess().equals("F")){
					String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessF");
					sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
					PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
					psupdate.setObject(1,"");
					psupdate.addBatch();
					psupdate.executeBatch();
				}else if(resultEntity.getProcess().equals("G")){
					String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessG");
					sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
					PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
					psupdate.setObject(1,"");
					psupdate.addBatch();
					psupdate.executeBatch();
				}else if(resultEntity.getProcess().equals("E")){
					String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessE");
					sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
					PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
					psupdate.setObject(1,"");
					psupdate.addBatch();
					psupdate.executeBatch();
				}else if(resultEntity.getProcess().equals("H")){
					String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessH");
					sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
					PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
					psupdate.setObject(1,"");
					psupdate.addBatch();
					psupdate.executeBatch();
				}
			}

			cro.setV_errMsg("撤销成功!");
			connection.commit();

		} catch (Exception e) {
			cro.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 cro;
	}


	/**
	 * 申请记录界面撤销离线压库申请
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject CancelApplyOffline1(ArrayList<String> arrayList){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			connection.setAutoCommit(false);
			if(arrayList == null || arrayList.size()<=0){
				throw new Exception("请选择压库管!");
			}

			for (String applylist:arrayList){
				YdmOverstockpipeApplyEntity resultEntity = EntityTool.getEntityByJSONStr(applylist,YdmOverstockpipeApplyEntity.class);
				String sqlcancelapply = CoreXmlSqlParsersFactory.getSql("OverstockPipe.CancelApply");
				PreparedStatement pscancel = connection.prepareStatement(sqlcancelapply);
				pscancel.setObject(1,resultEntity.getApplyResultNo());
				pscancel.addBatch();
				pscancel.executeBatch();

				if(resultEntity.getProcessCode().equals("D")){
					String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessD");
					sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
					PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
					psupdate.setObject(1,"");
					psupdate.addBatch();
					psupdate.executeBatch();
				}else if(resultEntity.getProcessCode().equals("F")){
					String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessF");
					sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
					PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
					psupdate.setObject(1,"");
					psupdate.addBatch();
					psupdate.executeBatch();
				}else if(resultEntity.getProcessCode().equals("G")){
					String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessG");
					sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
					PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
					psupdate.setObject(1,"");
					psupdate.addBatch();
					psupdate.executeBatch();
				}else if(resultEntity.getProcessCode().equals("E")){
					String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessE");
					sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
					PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
					psupdate.setObject(1,"");
					psupdate.addBatch();
					psupdate.executeBatch();
				}else if(resultEntity.getProcessCode().equals("H")){
					String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyProcessH");
					sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
					PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
					psupdate.setObject(1,"");
					psupdate.addBatch();
					psupdate.executeBatch();
				}
			}

			cro.setV_errMsg("撤销成功!");
			connection.commit();

		} catch (Exception e) {
			cro.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 cro;
	}


	/**
	 * 送判界面撤销余材压库申请
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject CancelApplyYC(ArrayList<String> arrayList){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			connection.setAutoCommit(false);
			if(arrayList == null || arrayList.size()<=0){
				throw new Exception("请选择压库管!");
			}

			for (String applylist:arrayList){
				MatBcMEntity resultEntity = EntityTool.getEntityByJSONStr(applylist,MatBcMEntity.class);
				String sqlcancelapply = CoreXmlSqlParsersFactory.getSql("OverstockPipe.CancelApply");
				PreparedStatement pscancel = connection.prepareStatement(sqlcancelapply);
				pscancel.setObject(1,resultEntity.getApplyResultNo());
				pscancel.addBatch();
				pscancel.executeBatch();

				String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyYucai");
				sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
				PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
				psupdate.setObject(1,"");
				psupdate.addBatch();
				psupdate.executeBatch();

			}

			cro.setV_errMsg("撤销成功!");
			connection.commit();

		} catch (Exception e) {
			cro.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 cro;
	}


	/**
	 * 申请记录界面撤销余材压库申请
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject CancelApplyYC1(ArrayList<String> arrayList){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			connection.setAutoCommit(false);
			if(arrayList == null || arrayList.size()<=0){
				throw new Exception("请选择压库管!");
			}

			for (String applylist:arrayList){
				YdmOverstockpipeApplyEntity resultEntity = EntityTool.getEntityByJSONStr(applylist,YdmOverstockpipeApplyEntity.class);
				String sqlcancelapply = CoreXmlSqlParsersFactory.getSql("OverstockPipe.CancelApply");
				PreparedStatement pscancel = connection.prepareStatement(sqlcancelapply);
				pscancel.setObject(1,resultEntity.getApplyResultNo());
				pscancel.addBatch();
				pscancel.executeBatch();

				String sqlupdate = CoreXmlSqlParsersFactory.getSql("OverstockPipe.UpdateApplynobyYucai");
				sqlupdate += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"' ";
				PreparedStatement psupdate = connection.prepareStatement(sqlupdate);
				psupdate.setObject(1,"");
				psupdate.addBatch();
				psupdate.executeBatch();

			}

			cro.setV_errMsg("撤销成功!");
			connection.commit();

		} catch (Exception e) {
			cro.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 cro;
	}


	/**
	 * 查询送判记录
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject doQueryYDMResult(String arrayList){
		YdmOverstockpipeApplyEntity ydmentity = EntityTool.getEntityByJSONStr(arrayList,YdmOverstockpipeApplyEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.doQueryYDMResult");
		if(ydmentity.getJudgeStoveNo() != null && !ydmentity.getJudgeStoveNo().equals("")){
			sql += " AND T.JUDGE_STOVE_NO = '"+ydmentity.getJudgeStoveNo()+"'";
		}
		if(ydmentity.getBatchNo() != null && !ydmentity.getBatchNo().equals("")){
			sql += " AND T.BATCH_NO = '"+ydmentity.getBatchNo()+"'";
		}
		if(ydmentity.getPlineCode() != null && !ydmentity.getPlineCode().equals("")){
			sql += " AND T.PLINE_CODE = '"+ydmentity.getPlineCode()+"'";
		}
		if(ydmentity.getHeatPlanNo() != null && !ydmentity.getHeatPlanNo().equals("")){
			sql += " AND T.HEAT_PLAN_NO = '"+ydmentity.getHeatPlanNo()+"'";
		}
		sql += " AND VALIDFLAG = '1'";
		return this.getData(sql);
	}

	/**
	 * 压库审核撤销
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject CancelAudit(ArrayList<String> arrayList){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			connection.setAutoCommit(false);
			if(arrayList == null || arrayList.size()<=0){
				throw new Exception("请选择压库管!");
			}

			for (String auditlist:arrayList){
				YdmOverstockpipeApplyEntity resultEntity = EntityTool.getEntityByJSONStr(auditlist,YdmOverstockpipeApplyEntity.class);
				if(resultEntity.getValidflag().equals("无效")){
					cro.setV_errMsg("无效数据,无法撤销!");
					return cro;
				}
				String sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.CancelAudit");
				sql += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"'";
				PreparedStatement ps = connection.prepareStatement(sql);
				ps.addBatch();
				ps.executeBatch();

			}

			cro.setV_errMsg("撤销成功!");
			connection.commit();

		} catch (Exception e) {
			cro.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 cro;
	}


	/**
	 * 压库申请废除
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject Del(ArrayList<String> arrayList){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			connection.setAutoCommit(false);
			if(arrayList == null || arrayList.size()<=0){
				throw new Exception("请选择压库管!");
			}

			for (String list:arrayList){
				YdmOverstockpipeApplyEntity resultEntity = EntityTool.getEntityByJSONStr(list,YdmOverstockpipeApplyEntity.class);
				String sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.Del");
				sql += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"'";
				PreparedStatement ps = connection.prepareStatement(sql);
				ps.addBatch();
				ps.executeBatch();
			}

			cro.setV_errMsg("废除成功!");
			connection.commit();

		} catch (Exception e) {
			cro.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 cro;
	}


	/**
	 * 压库申请撤销废除
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject CancelDel(ArrayList<String> arrayList){
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();

		try {
			connection.setAutoCommit(false);
			if(arrayList == null || arrayList.size()<=0){
				throw new Exception("请选择压库管!");
			}

			for (String list:arrayList){
				YdmOverstockpipeApplyEntity resultEntity = EntityTool.getEntityByJSONStr(list,YdmOverstockpipeApplyEntity.class);
				String sql = CoreXmlSqlParsersFactory.getSql("OverstockPipe.CancelDel");
				sql += " AND T.APPLY_RESULT_NO = '"+resultEntity.getApplyResultNo()+"'";
				PreparedStatement ps = connection.prepareStatement(sql);
				ps.addBatch();
				ps.executeBatch();
			}

			cro.setV_errMsg("撤销成功!");
			connection.commit();

		} catch (Exception e) {
			cro.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 cro;
	}
}
