package com.steering.pss.plnsaleord.stove;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.planStove.FrmPlanMaterialSelection;
import com.steering.pss.plnsaleord.steelMarkingPlan.FrmSteelMakingPlanChange;
import com.steering.pss.plnsaleord.stove.entity.*;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

/**
 * 炉计划公用方法
 * 
 * @author teng 2017.10.27
 */
public class ComPlanFurnace extends DBCommon {

	/**
	 * 炉次下发生成虚拟炉计划(自炼)
	 * 
	 * @param con
	 * @param furnaces
	 * @throws SQLException
	 */
	public CoreReturnObject queryPlnSteelOrd(String[] furnaces,
			String createName) throws SQLException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = null;
		List<String> messageErr = new ArrayList<String>();
		// Connection conServer = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(con);
			// 获取当前下发炉次订单信息
			List<PlnSteelforOrdEntityL> steOrd = getPlanSteOrdD(con, furnaces);
			if (steOrd == null) {
				cro.setV_errCode(-1);
				cro.setV_errMsg("连铸炉次订单数据异常,请刷新数据!");
				return cro;
			}
			String messageZg = "";
			String messageDz = "";
			String messageZgM = "";
			String messageZgM1 = "";
			String messageDzM = "";
			for (PlnSteelforOrdEntityL stord : steOrd) {
				if (stord.getSurplusflag().equals("1")) {// 余材执行下一循环
					continue;
				}
				// 判定铸造是否末工序 1.是，0.否
				if (stord.getIsendgx().equals("0")) {
					if (stord.getGptype().equals("2")) {// 经过锻坯
						// 通过铸造订单号PRO_PLAN_ID查询锻造订单个数
						List<PlnOrderDzSEntityL> plnDz = getPlanSteOrd(con,
								stord.getProPlanId(), "");
						if (plnDz == null) {
							if (messageDz.equals("")) {
								messageDz = stord.getProPlanId();
							}
							if (!messageDz.contains(stord.getProPlanId())) {
								messageDz = messageDz + ","
										+ stord.getProPlanId();
							}
							// messageErr.add("管坯需求号：" + messageDz +
							// "找不到锻造排产信息");
							continue;
						}
						corePlnZyFurnM furnPlan = new corePlnZyFurnM();
						// 生成锻造虚拟炉计划
						if (furnPlan.addPlnZyDzM(con, stord, plnDz, createName,
								dateTime)) {
							if (messageDzM.equals("")) {
								messageDzM = furnPlan.getErrMessageDz();
							}
							if (!messageDzM
									.contains(furnPlan.getErrMessageDz())) {
								messageDzM = messageDzM + ","
										+ furnPlan.getErrMessageDz();
							}
							if (messageZgM1.equals("")) {
								messageZgM1 = furnPlan.getErrMessageZg();
							}
							if (!messageZgM1.contains(furnPlan
									.getErrMessageZg())) {
								messageZgM1 = messageZgM1 + ","
										+ furnPlan.getErrMessageZg();
							}
							continue;
						}
					} else {
						// 通过铸造订单号PRO_PLAN_ID查询轧管订单个数
						List<PlnOrderZgSEntityL> plnZg = getPlanSteOrdZg(con,
								stord.getProPlanId(), stord.getGxPlanNo(), "1");
						if (plnZg == null) {
							if (messageZg.equals("")) {
								messageZg = stord.getProPlanId();
							}
							if (!messageZg.contains(stord.getProPlanId())) {
								messageZg = messageZg + ","
										+ stord.getProPlanId();
							}
							// messageErr.add("管坯需求号：" + messageZg +
							// "找不到轧管排产信息");
							continue;
						}
						int countZg = 0;
						for (PlnOrderZgSEntityL plnZgS : plnZg) {
							countZg++;
						}
						corePlnZyFurnM furnPlan = new corePlnZyFurnM();
						// 生成轧管虚拟炉计划
						if (furnPlan.addPlnZyZgM(con, stord, plnZg, createName,
								dateTime, "B", "", countZg)) {
							if (messageZgM.equals("")) {
								messageZgM = furnPlan.getErrMessageZg();
							}
							if (!messageZgM
									.contains(furnPlan.getErrMessageZg())) {
								messageZgM = messageZgM + ","
										+ furnPlan.getErrMessageZg();
							}
							continue;
						}
					}
				}
			}
			if (!messageZg.equals("")) {
				messageErr.add("管坯需求号：" + messageZg + "找不到轧管排产信息");
			}
			if (!messageDz.equals("")) {
				messageErr.add("管坯需求号：" + messageDz + "找不到锻造排产信息");
			}
			if (!messageZgM.equals("")) {
				messageErr.add("轧管订单号：" + messageZgM + "不是计划,生产中的状态");
			}
			if (!messageDzM.equals("") || !messageZgM1.equals("")) {
				if (messageDzM.equals("")) {
					messageErr.add("轧管订单号：" + messageZgM1 + "不是计划,生产中的状态");
				}
				if (messageZgM1.equals("")) {
					messageErr.add("锻造订单号：" + messageDzM + "不是计划状态");
				}
				if (!messageDzM.equals("") && !messageZgM1.equals("")) {
					messageErr.add("锻造订单号：" + messageDzM + "不是计划状态" + ";"
							+ "轧管订单号：" + messageZgM1 + "不是计划,生产中的状态");
				}
			}
			if (messageErr.size() > 0) {
				cro.setV_errMsg(messageErr.toString());
			} else {
				cro.setV_errMsg("成功");
			}
			con.commit();

		} catch (SQLException sqle) {
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 炉次取消下发删除虚拟炉计划(自炼)
	 * 
	 * @param con
	 * @param furnaces
	 * @param efplineCode
	 * @return
	 * @throws SQLException
	 */
	public CoreReturnObject deletePlnSteelOrd(String[] furnaces,
			String createName) throws SQLException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = null;
		List<String> messageErr = new ArrayList<String>();
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			String sql = "";

			// 获取当前下发炉次订单信息
			List<PlnSteelforOrdEntityL> steOrd = getPlanSteOrdD(con, furnaces);
			if (steOrd == null) {
				cro.setV_errCode(-1);
				cro.setV_errMsg("连铸炉次订单数据异常,请刷新数据!");
				return cro;
			}
			for (PlnSteelforOrdEntityL stord : steOrd) {
				if (stord.getSurplusflag().equals("1")) {// 余材执行下一循环
					continue;
				}
				// 判定铸造是否末工序 1.是，0.否
				if (stord.getIsendgx().equals("0")) {
					// result = this.getDao("MSSQL2Dao").CoreBeginTranscation();
					if (stord.getGptype().equals("2")) {// 经过锻坯
						// 通过虚拟炉号+炉次内顺序号查找锻造虚拟炉计划
						sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,"
								+ " T.PLN_INSINGLE_WT,T.PRO_PLAN_ID,T.GX_PLAN_NO,T.GX_PRO_SEQ,T.PLINE_CODE FROM PLN_ZY_DZ_M  T WHERE T.UPPER_HEATPLAN_ID=? AND T.PLANSTATUS='00'";
						ps = con.prepareStatement(sql);
						ps.setObject(1, stord.getFurnaceno() + "/"
								+ stord.getSequenceno());
						rs = ps.executeQuery();
						while (rs.next()) {
							PreparedStatement psC = null;
							ResultSet rsC = null;
							// // 通过虚拟炉号+炉次内顺序号查找轧管虚拟炉计划
							// sql =
							// "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,T.PLN_INSINGLE_WT,"
							// +
							// "T.PRO_PLAN_ID,T.GX_PLAN_NO,T.GX_PRO_SEQ,T.PLINE_CODE FROM PLN_ZY_ZG_M  T WHERE T.UPPER_HEATPLAN_ID=? AND T.PLANSTATUS='00'";
							// PreparedStatement ps1 =
							// con.prepareStatement(sql);
							// ps1.setObject(1, rs.getString("HEAT_PLAN_NO"));
							// ResultSet rs1 = ps1.executeQuery();
							// while (rs1.next()) {
							// int countNumZ = 0;
							// // 查询是否存在轧管实际炉计划
							// String sqlZgC =
							// "SELECT COUNT(*) COUNT FROM PLN_ZY_ZG_C T WHERE T.HEAT_PLAN_NO=?";
							// psC = con.prepareStatement(sqlZgC);
							// psC.setObject(1, rs1.getString("HEAT_PLAN_NO"));
							// rsC = psC.executeQuery();
							// if (rsC.next()) {
							// countNumZ = rsC.getInt("COUNT");
							// }
							// rsC.close();
							// psC.close();
							// if (countNumZ > 0) {
							// messageErr.add("虚拟炉次号:"
							// + stord.getFurnaceno() + "/"
							// + stord.getSequenceno()
							// + "的虚拟轧管炉计划存在轧管实际炉计划,不能撤销");
							// continue;
							// }
							// // 删除轧管虚拟炉计划
							// String sqlDeleteZg =
							// "DELETE PLN_ZY_ZG_M  WHERE HEAT_PLAN_NO = ? ";
							// psC = con.prepareStatement(sqlDeleteZg);
							// psC.setObject(1, rs1.getString("HEAT_PLAN_NO"));
							// psC.executeUpdate();
							// psC.close();
							// // 更新顺序号
							// // updateGxProSeq(con,
							// // rs1.getString("PLINE_CODE"),
							// // Integer.parseInt(rs1
							// // .getString("GX_PRO_SEQ")), -1,
							// // "D");
							//
							// }
							// rs1.close();
							// ps1.close();

							int countNumd = 0;
							// 查询是否存在锻造实际炉计划
							String sqlDzC = "SELECT COUNT(*) COUNT FROM PLN_ZY_DZ_C T WHERE T.HEAT_PLAN_NO=?";
							psC = con.prepareStatement(sqlDzC);
							psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
							rsC = psC.executeQuery();
							if (rsC.next()) {
								countNumd = rsC.getInt("COUNT");
							}
							rsC.close();
							psC.close();
							if (countNumd > 0) {
								messageErr.add("虚拟炉次号:" + stord.getFurnaceno()
										+ "/" + stord.getSequenceno()
										+ "的虚拟锻造炉计划存在锻造实际炉计划,不能撤销");
								continue;
							}
							// 删除锻造虚拟炉计划
							String sqlDeleteDz = "DELETE PLN_ZY_DZ_M  WHERE HEAT_PLAN_NO = ? ";
							psC = con.prepareStatement(sqlDeleteDz);
							psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
							psC.executeUpdate();
							psC.close();
							// 更新顺序号
							// updateGxProSeq(con, rs.getString("PLINE_CODE"),
							// Integer.parseInt(rs.getString("GX_PRO_SEQ")),-1,
							// "C");
						}
						rs.close();
						ps.close();
					} else {

						// 通过虚拟炉号+炉次内顺序号查找轧管虚拟炉计划
						sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,T.PLN_INSINGLE_WT,"
								+ "T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLINE_CODE,T.GX_PRO_SEQ FROM PLN_ZY_ZG_M  T WHERE T.UPPER_HEATPLAN_ID=? AND T.PLANSTATUS='00'";
						ps = con.prepareStatement(sql);
						ps.setObject(1, stord.getFurnaceno() + "/"
								+ stord.getSequenceno());
						rs = ps.executeQuery();
						while (rs.next()) {
							int countNum = 0;
							// 查询是否存在轧管实际炉计划
							String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_ZG_C T WHERE T.HEAT_PLAN_NO=?";
							PreparedStatement psC = con
									.prepareStatement(sqlZgC);
							psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
							ResultSet rsC = psC.executeQuery();
							if (rsC.next()) {
								countNum = rsC.getInt("COUNT");
							}
							rsC.close();
							psC.close();
							if (countNum > 0) {
								messageErr.add("虚拟炉次号+虚拟炉次内顺序号:"
										+ stord.getFurnaceno() + "/"
										+ stord.getSequenceno()
										+ "的虚拟轧管炉计划存在轧管实际炉计划,不能撤销");
								continue;
							}
							// 删除轧管虚拟炉计划
							String sqlDeleteZg = "DELETE PLN_ZY_ZG_M  WHERE HEAT_PLAN_NO = ? ";
							psC = con.prepareStatement(sqlDeleteZg);
							psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
							psC.executeUpdate();
							psC.close();
							// 更新顺序号
							// updateGxProSeq(con, rs.getString("PLINE_CODE"),
							// Integer
							// .parseInt(rs
							// .getString("GX_PRO_SEQ")),
							// -1, "D");

						}
						rs.close();
						ps.close();
					}
				}
			}
			if (messageErr.size() > 0) {
				cro.setV_errMsg(messageErr.toString());
			} else {
				cro.setV_errMsg("成功");
			}
			con.commit();
		} catch (SQLException sqle) {
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();

				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 浇次确认生成虚拟炉计划(自炼)
	 * 
	 * @param con
	 * @param furnaces
	 * @throws SQLException
	 */
	public static String queryPlnSteelCast(String[] furnaces,
			String createName, Connection con) throws SQLException {
		List<String> messageErr = new ArrayList<String>();
		String mess = "";
		// 获取数据库当前时间
		String dateTime = FrmSteelMakingPlanChange.getSystemTime(con);
		// 获取当前下发炉次订单信息
		List<PlnSteelforOrdEntityL> steOrd = getPlanSteOrdD(con, furnaces);
		if (steOrd == null) {
			mess = "连铸炉次订单数据异常,请刷新数据!";
			return mess;
		}
		String messageZg = "";
		String messageDz = "";
		String messageZgM = "";
		String messageZgM1 = "";
		String messageDzM = "";
		for (PlnSteelforOrdEntityL stord : steOrd) {
			if (stord.getSurplusflag().equals("1")) {// 余材执行下一循环
				continue;
			}
			// 判定铸造是否末工序 1.是，0.否
			if (stord.getIsendgx().equals("0")) {
				if (stord.getGptype().equals("2")) {// 经过锻坯
					// 通过铸造订单号PRO_PLAN_ID查询锻造订单个数
					List<PlnOrderDzSEntityL> plnDz = getPlanSteOrd(con, stord
							.getProPlanId(), "");
					if (plnDz == null) {
						if (messageDz.equals("")) {
							messageDz = stord.getProPlanId();
						}
						if (!messageDz.contains(stord.getProPlanId())) {
							messageDz = messageDz + "," + stord.getProPlanId();
						}
						continue;
					}
					corePlnZyFurnM furnPlan = new corePlnZyFurnM();
					// 生成锻造虚拟炉计划
					if (furnPlan.addPlnZyDzM(con, stord, plnDz, createName,
							dateTime)) {
						if (messageDzM.equals("")) {
							messageDzM = furnPlan.getErrMessageDz();
						}
						if (!messageDzM.contains(furnPlan.getErrMessageDz())) {
							messageDzM = messageDzM + ","
									+ furnPlan.getErrMessageDz();
						}
						if (messageZgM1.equals("")) {
							messageZgM1 = furnPlan.getErrMessageZg();
						}
						if (!messageZgM1.contains(furnPlan.getErrMessageZg())) {
							messageZgM1 = messageZgM1 + ","
									+ furnPlan.getErrMessageZg();
						}
						continue;
					}
				} else {
					// 通过铸造订单号PRO_PLAN_ID查询轧管订单个数
					List<PlnOrderZgSEntityL> plnZg = getPlanSteOrdZg(con, stord
							.getProPlanId(), stord.getGxPlanNo(), "1");
					if (plnZg == null) {
						// if (messageZg.equals("")) {
						// messageZg = stord.getProPlanId();
						// }
						// if (!messageZg.contains(stord.getProPlanId())) {
						// messageZg = messageZg + "," + stord.getProPlanId();
						// }
						continue;
					}
					int countZg = 0;
					for (PlnOrderZgSEntityL plnZgS : plnZg) {
						countZg++;
					}
					corePlnZyFurnM furnPlan = new corePlnZyFurnM();
					// 生成轧管虚拟炉计划
					if (furnPlan.addPlnZyZgM(con, stord, plnZg, createName,
							dateTime, "B", "", countZg)) {
						if (messageZgM.equals("")) {
							messageZgM = furnPlan.getErrMessageZg();
						}
						if (!messageZgM.contains(furnPlan.getErrMessageZg())) {
							messageZgM = messageZgM + ","
									+ furnPlan.getErrMessageZg();
						}
						continue;
					}
				}
			}
		}
		if (!messageZg.equals("")) {
			messageErr.add("管坯需求号：" + messageZg + "找不到轧管排产信息");
		}
		if (!messageDz.equals("")) {
			messageErr.add("管坯需求号：" + messageDz + "找不到锻造排产信息");
		}
		if (!messageZgM.equals("")) {
			messageErr.add("轧管订单号：" + messageZgM + "不是计划,生产中的状态");
		}
		if (!messageDzM.equals("") || !messageZgM1.equals("")) {
			if (messageDzM.equals("")) {
				messageErr.add("轧管订单号：" + messageZgM1 + "不是计划,生产中的状态");
			}
			if (messageZgM1.equals("")) {
				messageErr.add("锻造订单号：" + messageDzM + "不是计划状态");
			}
			if (!messageDzM.equals("") && !messageZgM1.equals("")) {
				messageErr.add("锻造订单号：" + messageDzM + "不是计划状态" + ";"
						+ "轧管订单号：" + messageZgM1 + "不是计划,生产中的状态");
			}
		}
		if (messageErr.size() > 0) {
			mess = messageErr.toString();
		}
		return mess;
	}

	/**
	 * 取消浇次确认删除虚拟炉计划(自炼)
	 * 
	 * @param con
	 * @param furnaces
	 * @param efplineCode
	 * @return
	 * @throws SQLException
	 */
	public static String deletePlnSteelCast(String[] furnaces,
			String createName, Connection con) throws SQLException {
		String mess = "";
		List<String> messageErr = new ArrayList<String>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "";

		// 获取当前下发炉次订单信息
		List<PlnSteelforOrdEntityL> steOrd = getPlanSteOrdD(con, furnaces);
		if (steOrd == null) {
			mess = "连铸炉次订单数据异常,请刷新数据!";
			return mess;
		}

		for (PlnSteelforOrdEntityL stord : steOrd) {
			if (stord.getSurplusflag().equals("1")) {// 余材执行下一循环
				continue;
			}
			// 判定铸造是否末工序 1.是，0.否
			if (stord.getIsendgx().equals("0")) {
				// result = this.getDao("MSSQL2Dao").CoreBeginTranscation();
				if (stord.getGptype().equals("2")) {// 经过锻坯
					// 通过虚拟炉号+炉次内顺序号查找锻造虚拟炉计划
					sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,"
							+ " T.PLN_INSINGLE_WT,T.PRO_PLAN_ID,T.GX_PLAN_NO,T.GX_PRO_SEQ,T.PLINE_CODE FROM PLN_ZY_DZ_M  T WHERE T.UPPER_HEATPLAN_ID=? AND T.PLANSTATUS='00'";
					ps = con.prepareStatement(sql);
					ps.setObject(1, stord.getFurnaceno() + "/"
							+ stord.getSequenceno());
					rs = ps.executeQuery();
					while (rs.next()) {
						PreparedStatement psC = null;
						ResultSet rsC = null;
						int countNumd = 0;
						// 查询是否存在锻造实际炉计划
						String sqlDzC = "SELECT COUNT(*) COUNT FROM PLN_ZY_DZ_C T WHERE T.HEAT_PLAN_NO=?";
						psC = con.prepareStatement(sqlDzC);
						psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
						rsC = psC.executeQuery();
						if (rsC.next()) {
							countNumd = rsC.getInt("COUNT");
						}
						rsC.close();
						psC.close();
						if (countNumd > 0) {
							messageErr.add("虚拟炉次号:" + stord.getFurnaceno()
									+ "/" + stord.getSequenceno()
									+ "的虚拟锻造炉计划存在锻造实际炉计划,不能撤销");
							continue;
						}
						// 删除锻造虚拟炉计划
						String sqlDeleteDz = "DELETE PLN_ZY_DZ_M  WHERE HEAT_PLAN_NO = ? ";
						psC = con.prepareStatement(sqlDeleteDz);
						psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
						psC.executeUpdate();
						psC.close();
						// 更新顺序号
						// updateGxProSeq(con, rs.getString("PLINE_CODE"),
						// Integer.parseInt(rs.getString("GX_PRO_SEQ")),-1,
						// "C");
					}
					rs.close();
					ps.close();
				} else {

					// 通过虚拟炉号+炉次内顺序号查找轧管虚拟炉计划
					sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,T.PLN_INSINGLE_WT,"
							+ "T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLINE_CODE,T.GX_PRO_SEQ FROM PLN_ZY_ZG_M  T WHERE T.UPPER_HEATPLAN_ID=? AND T.PLANSTATUS='00'";
					ps = con.prepareStatement(sql);
					ps.setObject(1, stord.getFurnaceno() + "/"
							+ stord.getSequenceno());
					rs = ps.executeQuery();
					while (rs.next()) {
						int countNum = 0;
						// 查询是否存在轧管实际炉计划
						String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_ZG_C T WHERE T.HEAT_PLAN_NO=?";
						PreparedStatement psC = con.prepareStatement(sqlZgC);
						psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
						ResultSet rsC = psC.executeQuery();
						if (rsC.next()) {
							countNum = rsC.getInt("COUNT");
						}
						rsC.close();
						psC.close();
						if (countNum > 0) {
							messageErr.add("虚拟炉次号+虚拟炉次内顺序号:"
									+ stord.getFurnaceno() + "/"
									+ stord.getSequenceno()
									+ "的虚拟轧管炉计划存在轧管实际炉计划,不能撤销");
							continue;
						}
						// 删除轧管虚拟炉计划
						String sqlDeleteZg = "DELETE PLN_ZY_ZG_M  WHERE HEAT_PLAN_NO = ? ";
						psC = con.prepareStatement(sqlDeleteZg);
						psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
						psC.executeUpdate();
						psC.close();
						// 更新顺序号
						// updateGxProSeq(con, rs.getString("PLINE_CODE"),
						// Integer
						// .parseInt(rs
						// .getString("GX_PRO_SEQ")),
						// -1, "D");

					}
					rs.close();
					ps.close();
				}
			}
		}
		if (messageErr.size() > 0) {
			mess = messageErr.toString();
		}
		return mess;
	}

	/**
	 * 更新轧管虚拟炉计划顺序号
	 * 
	 * @param con
	 * @param plineCode
	 * @param proSeqB
	 * @param num
	 * @throws SQLException
	 */
	public static void updateGxProSeq(Connection con, String plineCode,
			int proSeqB, int num, String processCode) throws SQLException {
		String sql = "";
		if (processCode.equals("C")) {
			sql = " UPDATE PLN_ZY_DZ_M T  SET T.GX_PRO_SEQ = T.GX_PRO_SEQ + ?  "
					+ " WHERE T.PLINE_CODE = ? AND T.GX_PRO_SEQ >=?";
		} else if (processCode.equals("D")) {
			sql = " UPDATE PLN_ZY_ZG_M T  SET T.GX_PRO_SEQ = T.GX_PRO_SEQ + ?  "
					+ " WHERE T.PLINE_CODE = ? AND T.GX_PRO_SEQ >=?";
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, num);
		ps.setObject(2, plineCode);
		ps.setObject(3, proSeqB);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 查询库存信息
	 * 
	 * @param con
	 * @throws SQLException
	 */
	public static List<MatGpMEntity> QueryMatGp(Connection con, String gpreqId,
			String judgeStoveNo) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.QueryMatGp");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		// ps.setObject(2, gpreqId);
		ResultSet rs = ps.executeQuery();
		List<MatGpMEntity> list = EntityTool.getEntitysByRs(rs,
				MatGpMEntity.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (MatGpMEntity listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	/**
	 * 炉次下发生成虚拟炉计划(外购)
	 * 
	 * @param con
	 * @param furnaces
	 * @throws SQLException
	 */
	public CoreReturnObject queryPlnOutsourc(String gpreqId,
			String judgeStoveNo, String createName) throws SQLException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = null;
		List<String> messageErr = new ArrayList<String>();
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(con);
			// 查询库存有多少轧管订单及重量
			List<MatGpMEntity> matGp = QueryMatGp(con, gpreqId, judgeStoveNo);
			if (matGp == null) {
				cro.setV_errMsg("未找到入库数据,请刷新数据!");
				return cro;
			}
			String messageZg = "";
			String messageZgM = "";
			for (MatGpMEntity stord : matGp) {
				// // 判定铸造是否末工序 1.是，0.否
				// if (stord.getIsendgx().equals("0")) {
				// 通过铸造订单号PRO_PLAN_ID查询轧管订单个数
				List<PlnOrderZgSEntityL> plnZg = getPlanSteOrdZg(con, stord
						.getProPlanIdZg(), stord.getGxPlanNoZg(), "0");
				if (plnZg == null) {
					if (messageZg.equals("")) {
						messageZg = stord.getProPlanId();
					}
					if (!messageZg.contains(stord.getProPlanId())) {
						messageZg = messageZg + "," + stord.getProPlanId();
					}
					continue;
				}
				corePlnZyFurnM furnPlan = new corePlnZyFurnM();
				for (PlnOrderZgSEntityL plnZgS : plnZg) {
					if (Integer.parseInt(plnZgS.getExeStatus()) > 1) {
						continue;
					}
					String processCode = "";
					if (plnZgS.getWholeBacklog().contains("B")) {
						if (plnZgS.getWholeBacklog().contains("C")) {
							processCode = "C";
						} else {
							processCode = "B";
						}
					}
					// 生成轧管虚拟炉计划
					if (furnPlan.addPlnZyZgMWg(con, stord, plnZgS, createName,
							dateTime, processCode, "")) {
						if (messageZgM.equals("")) {
							messageZgM = furnPlan.getErrMessageZg();
						}
						if (!messageZgM.contains(furnPlan.getErrMessageZg())) {
							messageZgM = messageZgM + ","
									+ furnPlan.getErrMessageZg();
						}
						continue;
					}
				}
			}
			// }
			if (!messageZg.equals("")) {
				messageErr.add("管坯需求号：" + messageZg + "找不到轧管排产信息");
			}
			if (!messageZgM.equals("")) {
				messageErr.add("轧管订单号：" + messageZgM + "不是计划,生产中的状态");
			}
			if (messageErr.size() > 0) {
				cro.setV_errMsg(messageErr.toString());
				// 异常新增
				addMessage(messageErr.toString());
			} else {
				cro.setV_errMsg("成功");
			}
			con.commit();
		} catch (SQLException sqle) {
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errMsg(sqle.getMessage());
			// 异常新增
			addMessage(sqle.getMessage());
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 查询库存信息
	 * 
	 * @param con
	 * @throws SQLException
	 */
	public static List<MatGpMEntity> QueryMatGpDelete(Connection con,
			String gpreqId, String judgeStoveNo, String instockDoc)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.QueryMatGpDelete");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, instockDoc);
		ps.setObject(3, instockDoc);
		ResultSet rs = ps.executeQuery();
		List<MatGpMEntity> list = EntityTool.getEntitysByRs(rs,
				MatGpMEntity.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (MatGpMEntity listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	/**
	 * 炉次取消下发删除虚拟炉计划(外购)
	 * 
	 * @param con
	 * @throws SQLException
	 */
	public CoreReturnObject deletePlnOutsourc(
			ArrayList<ArrayList<String>> jsonList, String createName)
			throws SQLException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			String sql = "";
			for (int i = 0; i < jsonList.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jsonList.get(i);
				String gpreqId = list.get(0);// 无值
				String judgeStoveNo = list.get(1);
				String instockDoc = list.get(2);
				// 查询库存有多少轧管订单及重量
				List<MatGpMEntity> matGp = QueryMatGpDelete(con, gpreqId,
						judgeStoveNo, instockDoc);
				if (matGp == null) {
					cro.setV_errMsg("未找到入库数据,请刷新数据!");
					return cro;
				}
				for (MatGpMEntity stord : matGp) {
					int actCount = Integer.parseInt(stord.getActCount());
					// // 判定铸造是否末工序 1.是，0.否
					// if (stord.getIsendgx().equals("0")) {
					// 通过虚拟炉号+炉次内顺序号查找轧管虚拟炉计划
					sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,NVL(T.PLN_INSINGLE_NUM,0) PLN_INSINGLE_NUM,T.PLN_INSINGLE_WT,nvl(T.OUTNUM_CUT,0) OUTNUM_CUT,"
							+ "T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLANSTATUS,T.PLINE_NAME FROM PLN_ZY_ZG_M  T WHERE T.JUDGE_STOVE_NO=? AND T.HEAT_PLAN_NO=? ";
					ps = con.prepareStatement(sql);
					ps.setObject(1, judgeStoveNo);
					ps.setObject(2, stord.getHeatPlanNoNext());
					rs = ps.executeQuery();
					while (rs.next()) {
						if (!rs.getString("PLANSTATUS").equals("00")) {
							cro
									.setV_errMsg("判定炉号(" + judgeStoveNo
											+ ")已下发,如需撤销,请联系"
											+ rs.getString("PLINE_NAME")
											+ "轧管计划员撤销下发!");
							return cro;
						}

						int countNum = 0;
						// 查询是否存在轧管实际炉计划
						String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_ZG_C T WHERE T.HEAT_PLAN_NO=?";
						PreparedStatement psC = con.prepareStatement(sqlZgC);
						psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
						ResultSet rsC = psC.executeQuery();
						if (rsC.next()) {
							countNum = rsC.getInt("COUNT");
						}
						rsC.close();
						psC.close();
						if (countNum > 0) {
							cro.setV_errMsg("虚拟轧管炉计划存在轧管实际炉计划,不能撤销");
							return cro;
						}

						if (rs.getInt("PLN_INSINGLE_NUM") - actCount <= 0) {
							// 删除轧管虚拟炉计划
							String sqlDeleteZg = "DELETE PLN_ZY_ZG_M  WHERE HEAT_PLAN_NO = ?";
							psC = con.prepareStatement(sqlDeleteZg);
							psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
							psC.executeUpdate();
							psC.close();
						} else {
							PlnOrderZgSEntityL plnZgS = FrmPlanMaterialSelection
									.getPlanOrderZg(con,
											stord.getProPlanIdZg(), stord
													.getGxPlanNoZg(),
											PlnOrderZgSEntityL.class);
							// 算预计成品吨
							double aimOutdiam = Double.parseDouble(plnZgS
									.getAimoutdiameter());
							double aimwallthick = Double.parseDouble(plnZgS
									.getAimwallthick());
							double weightOne = (0.02466 * aimwallthick * (aimOutdiam - aimwallthick)) / 1000;
							double cutHeadEnd = (Double.parseDouble(plnZgS
									.getLenCutend()) + Double
									.parseDouble(plnZgS.getLenCuthead())) / 1000;
							double cpWt = weightOne
									* (Double.parseDouble(plnZgS
											.getRollLength()) - cutHeadEnd)
									* actCount;
							// 折算吨
							double reducedWt = (Double.parseDouble(plnZgS
									.getGpreqWeight()) / Double
									.parseDouble(plnZgS.getWeigthS()))
									* cpWt;
							// 修改轧管虚拟炉计划
							String sqlUpdateZg = CoreXmlSqlParsersFactory
									.getSql("ComPlanFurnace.updateWgZgM");
							psC = con.prepareStatement(sqlUpdateZg);
							psC.setObject(1, actCount);
							psC.setObject(2, stord.getActWeight());
							psC
									.setObject(3, actCount
											* rs.getInt("OUTNUM_CUT"));
							psC.setObject(4, stord.getActWeight());
							psC.setObject(5, reducedWt);
							psC.setObject(6, rs.getString("HEAT_PLAN_NO"));
							psC.executeUpdate();
							psC.close();
						}

						// // 回写轧管已排产炉计划量
						// String updatePlnOrderZg =
						// "UPDATE PLN_ORDER_ZG_S T SET T.BATCHED_WT_G=TO_NUMBER(NVL(T.BATCHED_WT_G,0))-TO_NUMBER(?),"
						// +
						// "T.BATCHED_NUM_G=TO_NUMBER(NVL(T.BATCHED_NUM_G,0))-TO_NUMBER(?)"
						// + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? ";
						// psC = con.prepareStatement(updatePlnOrderZg);
						// psC.setObject(1, rs.getString("PLN_INSINGLE_WT"));
						// psC.setObject(2, rs.getString("PLN_INSINGLE_NUM"));
						// psC.setObject(3, rs.getString("PRO_PLAN_ID"));
						// psC.setObject(4, rs.getString("GX_PLAN_NO"));
						// psC.executeUpdate();
						// psC.close();
					}
					rs.close();
					ps.close();

				}
			}
			cro.setV_errMsg("成功");
			con.commit();
		} catch (SQLException sqle) {
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 查询炉次订单连铸信息
	 * 
	 * @param con
	 * @param furnaces
	 *            虚拟炉号
	 * @param efplineCode
	 *            电炉产线
	 * @throws SQLException
	 */
	public static List<PlnSteelforOrdEntityL> getPlanSteOrdD(Connection con,
			String[] furnaces) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.querySteOrdPln");
		sql += CoreConverter.toSqlConditionString("T.FURNACENO", furnaces);
		sql += " ORDER BY T.EF_PLINE_CODE ASC,T.CCM_SEQ ASC";
		PreparedStatement ps = con.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		List<PlnSteelforOrdEntityL> list = EntityTool.getEntitysByRs(rs,
				PlnSteelforOrdEntityL.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (PlnSteelforOrdEntityL listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	/**
	 * 单个查询炉次订单连铸信息
	 * 
	 * @param con
	 * @param furnaces
	 *            虚拟炉号
	 * @param efplineCode
	 *            电炉产线
	 * @throws SQLException
	 */
	public static List<PlnSteelforOrdEntityL> getPlanSteOrdSingle(
			Connection con, String furnaces, String sequenceno)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.querySteOrdPln");
		sql += " AND T.FURNACENO='" + furnaces + "' AND T.SEQUENCENO='"
				+ sequenceno + "'";
		sql += " ORDER BY T.EF_PLINE_CODE ASC,T.CCM_SEQ ASC";
		PreparedStatement ps = con.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		List<PlnSteelforOrdEntityL> list = EntityTool.getEntitysByRs(rs,
				PlnSteelforOrdEntityL.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (PlnSteelforOrdEntityL listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	/**
	 * 实际炉计划查询炉次订单连铸信息
	 * 
	 * @param con
	 * @param furnaces
	 *            虚拟炉号
	 * @param efplineCode
	 *            电炉产线
	 * @throws SQLException
	 */
	public static <T> T getPlanSteOrdC(Connection con, String furnaces,
			String sequenceNo, Class<T> cls) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.querySteOrdPlnFurn");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, furnaces);
		ps.setObject(2, sequenceNo);
		ResultSet rs = ps.executeQuery();
		T t = EntityTool.getEntityByRs(rs, cls);
		rs.close();
		ps.close();
		return t;
	}

	/**
	 * 实际炉计划查询管坯需求信息
	 * 
	 * @param con
	 * @param furnaces
	 *            虚拟炉号
	 * @param efplineCode
	 *            电炉产线
	 * @throws SQLException
	 */
	public static List<MatGpMEntity> getMatGpMEntity(Connection con,
			String furnaces, String sequenceNo, String judgeStoveNo,
			String dimater) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.getMatGpMEntity");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, furnaces);
		ps.setObject(3, sequenceNo);
		if (dimater.contains("t")) {
			ps.setObject(4, "2");
		} else {
			ps.setObject(4, "1");
		}
		ResultSet rs = ps.executeQuery();
		List<MatGpMEntity> list = EntityTool.getEntitysByRs(rs,
				MatGpMEntity.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (MatGpMEntity listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	/**
	 * 通过铸造订单号PRO_PLAN_ID查询锻造订单个数
	 * 
	 * @param con
	 * @param proPlanId
	 *            订单号
	 * @throws SQLException
	 */
	public static List<PlnOrderDzSEntityL> getPlanSteOrd(Connection con,
			String proPlanId, String gxPlanNo) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.queryPlnOrderDzS");
		if (!gxPlanNo.equals("")) {
			sql += "  AND T.GX_PLAN_NO='" + gxPlanNo + "'";
		}
		sql += "  ORDER BY T.PLAN_TIME_B ASC";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, proPlanId);
		ResultSet rs = ps.executeQuery();
		List<PlnOrderDzSEntityL> list = EntityTool.getEntitysByRs(rs,
				PlnOrderDzSEntityL.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (PlnOrderDzSEntityL listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	/**
	 * 通过铸造订单号PRO_PLAN_ID查询轧管订单个数
	 * 
	 * @param con
	 * @param proPlanId
	 *            订单号
	 * @throws SQLException
	 */
	public static List<PlnOrderZgSEntityL> getPlanSteOrdZg(Connection con,
			String proPlanId, String gxPlanNo, String outsBilletFl)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.queryPlnOrderZgS");
		sql += " AND T.EXE_STATUS='0'";// AND (T.IF_STOVE_ISSUED='0' or
		// T.IF_STOVE_ISSUED is null)
		if (outsBilletFl.equals("0")) {// 外购
			sql += " AND T.PRO_PLAN_ID='" + proPlanId + "'";
			sql += " AND T.GX_PLAN_NO='" + gxPlanNo + "'";
		} else {
			if (proPlanId.contains("ZG")) {
				sql += " AND T.PRO_PLAN_ID='" + proPlanId + "'";
				sql += " AND T.GX_PLAN_NO='" + gxPlanNo + "'";
			} else {
				sql += " AND T.GPREQ_ID='" + proPlanId + "'";
			}
		}
		sql += "  ORDER BY TO_NUMBER(T.GX_PRO_SEQ) ASC";
		PreparedStatement ps = con.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		List<PlnOrderZgSEntityL> list = EntityTool.getEntitysByRs(rs,
				PlnOrderZgSEntityL.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (PlnOrderZgSEntityL listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	/**
	 * 通过虚拟炉次号,顺序号,判定炉号查询锻造虚拟炉计划
	 * 
	 * @param con
	 * @param proPlanId
	 *            订单号
	 * @throws SQLException
	 */
	public static List<PlnZyDzMEntity> getPlanSteOrdM(Connection con,
			String furnaces, String sequenceNo, String judgeStoveNo,
			String proPlanId, String gxPlanId) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.queryPlnZyDzM");
		sql += " AND T.UPPER_HEATPLAN_ID=?";
		sql += "  ORDER BY T.GX_PRO_SEQ ASC";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, proPlanId);
		ps.setObject(3, gxPlanId);
		ps.setObject(4, furnaces + "/" + sequenceNo);
		ResultSet rs = ps.executeQuery();
		List<PlnZyDzMEntity> list = EntityTool.getEntitysByRs(rs,
				PlnZyDzMEntity.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (PlnZyDzMEntity listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	/**
	 * 通过虚拟炉次号,顺序号,判定炉号查询轧管虚拟炉计划
	 * 
	 * @param con
	 * @param proPlanId
	 *            订单号
	 * @throws SQLException
	 */
	public static List<PlnZyZgMEntity> getPlanSteOrdZgM(Connection con,
			String furnaces, String sequenceNo, String judgeStoveNo,
			String heatPlanNoDz, String outsBilletFl, String proPlanId,
			String gxPlanNo, String heatPlanNoNext) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.queryPlnZyZgM");
		if (outsBilletFl.equals("1")) {// 自炼
			if (heatPlanNoDz.equals("")) {
				// sql += " AND T.UPPER_HEATPLAN_ID='" + heatPlanNoDz + "'";
				// }
				// else {
				sql += " AND T.UPPER_HEATPLAN_ID='" + furnaces + "/"
						+ sequenceNo + "'";
			}
			if (heatPlanNoNext.equals("")) {
				sql += " AND T.PRO_PLAN_ID='" + proPlanId
						+ "' AND T.GX_PLAN_NO='" + gxPlanNo + "'";
			} else {
				sql += " AND T.HEAT_PLAN_NO='" + heatPlanNoNext + "'";
			}
		} else {
			if (heatPlanNoNext.equals("")) {
				sql += " AND T.PRO_PLAN_ID='" + proPlanId
						+ "' AND T.GX_PLAN_NO='" + gxPlanNo + "'";
			} else {
				sql += " AND T.HEAT_PLAN_NO='" + heatPlanNoNext + "'";
			}
		}

		sql += " ORDER BY T.GX_PRO_SEQ ASC";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		// ps.setObject(2, proPlanId);
		// ps.setObject(3, gxPlanNo);
		ResultSet rs = ps.executeQuery();
		List<PlnZyZgMEntity> list = EntityTool.getEntitysByRs(rs,
				PlnZyZgMEntity.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (PlnZyZgMEntity listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	/**
	 * 获取产线对应去向
	 * 
	 * @param con
	 * @throws SQLException
	 */
	public static String getPlineCodeGroup(Connection con, String plineCode,
			String proPlanId, String gxPlanNo) throws SQLException {
		String param = "";
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.queryPlinCodeGroup");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, plineCode);
		ps.setObject(2, proPlanId);
		ps.setObject(3, gxPlanNo);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			param = rs.getString("AF_INFO");
		}
		rs.close();
		ps.close();
		return param;
	}

	/**
	 * 新增异常信息
	 * 
	 * @param message
	 * @return
	 */
	public CoreReturnObject addMessage(String message) {
		String sql = " INSERT INTO PLN_ZY_EXECPTION_D (ID, SYS_TIME, MESSAGE) VALUES "
				+ "((SELECT MAX(ID) + 1 FROM PLN_ZY_EXECPTION_D), SYSDATE, '"
				+ message + "')";
		return this.setData(sql);
	}

	/**
	 * 新增修改轧管炉计划异常
	 * 
	 * @param message
	 * @return
	 */
	public CoreReturnObject addMessageU(String judgeNo, String createName,
			String message) {
		String sql = "  INSERT INTO PLN_ZY_ZG_MESSAGE(JUDGE_STOVE_NO, CREATE_NAME, CREATE_TIME, MEMO) VALUES('"
				+ judgeNo
				+ "', '"
				+ createName
				+ "', SYSDATE, '"
				+ message
				+ "')";
		return this.setData(sql);
	}

	/**
	 * 修改虚拟炉计划判定，生产，标识炉号
	 * 
	 * @param list
	 * @param createName
	 * @return
	 * @throws SQLException
	 */
	@SuppressWarnings("unused")
	public CoreReturnObject updatePlnZyM(String[] furnaceNoall,
			String createName, String flag) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = null;
		String furnNo = "";
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			String sql = "";
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(con);
			// 获取当前下发炉次订单信息
			List<PlnSteelforOrdEntityL> steOrd = getPlanSteOrdD(con,
					furnaceNoall);
			if (steOrd == null) {
				cro.setV_errCode(-1);
				cro.setV_errMsg("连铸炉次订单数据异常,请刷新数据!");
				return cro;
			}
			furnNo = Arrays.toString(furnaceNoall);
			for (PlnSteelforOrdEntityL stord : steOrd) {
				if (stord.getSurplusflag().equals("1")) {// 余材执行下一循环
					continue;
				}
				String furnaceNo = stord.getFurnaceno();
				String sequenceNo = stord.getSequenceno();
				String stoveNo = "";
				String judgeStoveNo = "";
				String flagStoveNo = "";
				String gptype = stord.getGptype();
				String isendgx = stord.getIsendgx();
				String plineCode = stord.getGowhereCode();
				if (flag.equals("1")) {// 切割
					stoveNo = stord.getStoveNo();
					judgeStoveNo = stord.getJudgeStoveNo();
					flagStoveNo = stord.getFlagStoveNo();
				}
				if (isendgx.equals("0")) {// 判定铸造是否末工序
					if (gptype.equals("2")) {// 经过锻造
						// 修改锻造炉号
						String sqlupdate = "UPDATE PLN_ZY_DZ_M T SET T.STOVE_NO=? ,T.JUDGE_STOVE_NO=?,"
								+ "T.FLAG_STOVE_NO=?,T.UPDATE_NAME=?,T.UPDATE_TIME=TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') WHERE T.UPPER_HEATPLAN_ID=?";
						ps = con.prepareStatement(sqlupdate);
						ps.setObject(1, stoveNo);
						ps.setObject(2, judgeStoveNo);
						ps.setObject(3, flagStoveNo);
						ps.setObject(4, createName);
						ps.setObject(5, dateTime);
						ps.setObject(6, furnaceNo + "/" + sequenceNo);
						ps.executeUpdate();
						ps.close();

						// 修改轧管炉号
						// String sqlupdateZg =
						// "UPDATE PLN_ZY_ZG_M  T SET  T.STOVE_NO=? ,T.JUDGE_STOVE_NO=?,"
						// +
						// "T.FLAG_STOVE_NO=?, T.UPDATE_NAME=?,T.UPDATE_TIME=TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') WHERE T.UPPER_HEATPLAN_ID="
						// +
						// "(SELECT T1.HEAT_PLAN_NO FROM PLN_ZY_DZ_M T1  WHERE T1.UPPER_HEATPLAN_ID=?)";
						// ps = con.prepareStatement(sqlupdateZg);
						// ps.setObject(1, stoveNo);
						// ps.setObject(2, judgeStoveNo);
						// ps.setObject(3, flagStoveNo);
						// ps.setObject(4, createName);
						// ps.setObject(5, dateTime);
						// ps.setObject(6, furnaceNo + "/" + sequenceNo);
						// ps.executeUpdate();
						// ps.close();

					} else {
						// 修改轧管炉号
						String sqlupdateZg = "UPDATE PLN_ZY_ZG_M  T SET  T.STOVE_NO=? ,T.JUDGE_STOVE_NO=?,"
								+ "T.FLAG_STOVE_NO=?,T.UPDATE_NAME=?,T.UPDATE_TIME=TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') WHERE T.UPPER_HEATPLAN_ID=?";
						ps = con.prepareStatement(sqlupdateZg);
						ps.setObject(1, stoveNo);
						ps.setObject(2, judgeStoveNo);
						ps.setObject(3, flagStoveNo);
						ps.setObject(4, createName);
						ps.setObject(5, dateTime);
						ps.setObject(6, furnaceNo + "/" + sequenceNo);
						ps.executeUpdate();
						ps.close();

						if (flag.equals("1")) {
							updateZyZgC(con, judgeStoveNo, furnaceNo,
									sequenceNo, plineCode, gptype);
						}
					}
				}
			}
			cro.setV_errMsg("修改成功");
			con.commit();
		} catch (SQLException sqle) {
			try {
				con.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
			addMessageU(furnNo, createName, sqle.getMessage());
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 更新轧管虚拟炉计划上料炉号，炉计划接收表信息
	 * 
	 * @param con
	 * @param judgeStoveNo
	 * @param furnaceNo
	 * @param sequenceNo
	 * @param plineCode
	 * @return
	 * @throws SQLException
	 */
	public String updateZyZgC(Connection con, String judgeStoveNo,
			String furnaceNo, String sequenceNo, String plineCode, String gptype)
			throws SQLException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		PreparedStatement ps1 = null;
		ResultSet rs1 = null;
		String mess = "";
		// String feedHeatNo = "";
		String sqlQuery = "";
		if (gptype.equals(2)) {
			// 查询轧管虚拟炉计划是否下发
			sqlQuery = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.STOVE_NO,T.JUDGE_STOVE_NO,T.FLAG_STOVE_NO,T.FEED_HEAT_NO,T.NEXT_PROCESS_CODE FROM PLN_ZY_ZG_M T WHERE T.UPPER_HEATPLAN_ID =(SELECT T1.HEAT_PLAN_NO FROM PLN_ZY_DZ_M T1  WHERE T1.UPPER_HEATPLAN_ID=?)";
		} else {
			sqlQuery = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.STOVE_NO,T.JUDGE_STOVE_NO,T.FLAG_STOVE_NO,T.FEED_HEAT_NO,T.NEXT_PROCESS_CODE FROM PLN_ZY_ZG_M T WHERE T.UPPER_HEATPLAN_ID =?";
		}
		ps1 = con.prepareStatement(sqlQuery);
		ps1.setObject(1, furnaceNo + "/" + sequenceNo);
		rs1 = ps1.executeQuery();
		if (rs1.next()) {
			PreparedStatement psU = null;
			ResultSet rsU = null;
			if (!rs1.getString("PLANSTATUS").equals("00")) {
				// 修改MIl_plan 上料炉号
				// String sqlupdateZg =
				// "UPDATE MIL_PLAN T SET T.STOVE_NO=? ,T.FEED_HEAT_NO=? WHERE T.ID=?";
				// psU = con.prepareStatement(sqlupdateZg);
				// psU.setObject(1, rs1.getString("STOVE_NO"));
				// psU.setObject(2, judgeStoveNo);
				// psU.setObject(3, rs1.getString("HEAT_PLAN_NO"));
				// psU.executeUpdate();
				// psU.close();

				// String milFeedHeadNo = "";
				// // 炉号是否发生变化
				// String sqlQueryPlan =
				// "SELECT T.FEED_HEAT_NO FROM MIL_PLAN T WHERE T.ID=? GROUP BY T.FEED_HEAT_NO";
				// psU = con.prepareStatement(sqlQueryPlan);
				// psU.setObject(1, rs1.getString("HEAT_PLAN_NO"));
				// rsU = psU.executeQuery();
				// if (rsU.next()) {
				// milFeedHeadNo = rsU.getString("FEED_HEAT_NO");
				// }
				// rsU.close();
				// psU.close();
				// if (!milFeedHeadNo.equals(judgeStoveNo)) {
				String plineCode2 = "";//获取轧管产线
				String sqlJueCount2 = CoreXmlSqlParsersFactory
						.getSql("FrmPlanStoveD.QueryHeatPlanNo2");
				ps = con.prepareStatement(sqlJueCount2);
				ps.setObject(1, judgeStoveNo);
				ps.setObject(2, judgeStoveNo);
				rs = ps.executeQuery();
				while (rs.next()) {
					plineCode2 = rs.getString("PLINE_CODE");
				}
				rs.close();
				ps.close();
				String maxFeed = "";
				String sqljend = "2000"; //2023年轧管系统用分炉坯:232000~239999
				// 2022年分炉炉号
				/*if (plineCode2.equals("C008")) {
					sqljend = "4000";// 250机组分炉炉号范围224000－225999
				} else if (plineCode2.equals("C009")) {
					sqljend = "6000";// 258机组分炉炉号范围226000－227999
				} else if (plineCode2.equals("C010")) {
					sqljend = "7500";// 168机组分炉炉号范围222000－223999,7500借500个炉号
				} else if (plineCode2.equals("C017")) {
					sqljend = "8000";// 460机组分炉炉号范围228000－229999
				} else {
					sqljend = "0000";
				}*/
				String sqlj = "SELECT T.BASENAME FROM COM_BASE_INFO T WHERE T.SORTCODE='5007'";
				ps = con.prepareStatement(sqlj);
				rs = ps.executeQuery();
				if (rs.next()) {
					maxFeed = rs.getString("BASENAME") + sqljend;
				} else {
					mess = "轧管起始判定炉号不能为空！";
					return mess;
				}
				rs.close();
				ps.close();
				int feedMaxNum = Integer.parseInt(maxFeed);
				// 查询当前所要用的上料炉号280000-289999区间最大
				String judMatQ = CoreXmlSqlParsersFactory
						.getSql("FrmPlanStoveD.QueryfeedJut");
				ps = con.prepareStatement(judMatQ);
				ps.setObject(1, maxFeed);
				ps.setObject(2, maxFeed.substring(0, 2));
				//ps.setObject(3, plineCode2);
				ps.setObject(3, maxFeed.substring(0, 2));
				rs = ps.executeQuery();
				if (rs.next()) {
					feedMaxNum = rs.getInt("FEED_HEAT_NO");
				}
				rs.close();
				ps.close();
				List<String> listFeed1 = new ArrayList<String>();
				for (int j = Integer.parseInt(maxFeed); j <= feedMaxNum; j++) {
					listFeed1.add(String.valueOf(j));
				}
				List<String> listFeed2 = new ArrayList<String>();
				// 查询已用上料炉号数组
				judMatQ = CoreXmlSqlParsersFactory
						.getSql("FrmPlanStoveD.QueryFeedAll");
				ps = con.prepareStatement(judMatQ);
				ps.setObject(1, maxFeed.substring(0, 2));
				ps.setObject(2, judgeStoveNo);
				ps.setObject(3, maxFeed.substring(0, 2));
				ps.setObject(4, judgeStoveNo);
				rs = ps.executeQuery();
				while (rs.next()) {
					listFeed2.add(rs.getString("FEED_HEAT_NO"));
				}
				rs.close();
				ps.close();
				// 下发时生成上料炉号
				int counHfeed = 0;
				// 1.查询该炉是否存在多个订单
				String sqlJueCount = CoreXmlSqlParsersFactory
						.getSql("FrmPlanStoveD.QueryHeatPlanNo");
				ps = con.prepareStatement(sqlJueCount);
				ps.setObject(1, judgeStoveNo);
				ps.setObject(2, judgeStoveNo);
				rs = ps.executeQuery();
				while (rs.next()) {
					// 判定是否存在 上料炉号
					counHfeed++;
					String feedMax = "";
					String fesNo = rs.getString("FEED_HEAT_NO");
					if (fesNo == null) {
						fesNo = "";
					}
					String heatCountNo = rs.getString("HEAT_PLAN_NO");
					if (counHfeed == 1) {
						feedMax = judgeStoveNo;
					} else {
						if (fesNo.equals("")
								|| !fesNo.contains(maxFeed.substring(0, 2))) {
							List<String> listMap = compareArry(listFeed1,
									listFeed2);
							if (null != listMap && listMap.size() > 0) {
								feedMaxNum = Integer.parseInt(listMap.get(0));
							}
							feedMax = String.valueOf(feedMaxNum);
							listFeed2.add(String.valueOf(feedMaxNum));
							feedMaxNum++;
						} else {
							feedMax = String.valueOf(fesNo);
						}
					}
					// 修改轧管炉计划上料炉号
					String update = "UPDATE PLN_ZY_ZG_M T SET T.FEED_HEAT_NO=? WHERE T.HEAT_PLAN_NO=?";
					psU = con.prepareStatement(update);
					psU.setObject(1, feedMax);
					psU.setObject(2, heatCountNo);
					psU.executeUpdate();
					psU.close();
					if (!rs1.getString("PLANSTATUS").equals("00")) {
						// 修改轧管炉计划上料炉号
						String update1 = "UPDATE MIL_PLAN T SET T.JUDGE_STOVE_NO=?,T.STOVE_NO=? ,T.FEED_HEAT_NO=? WHERE T.ID=?";
						psU = con.prepareStatement(update1);
						psU.setObject(1, feedMax + "-01");
						psU.setObject(2, rs1.getString("STOVE_NO"));
						psU.setObject(3, judgeStoveNo);
						psU.setObject(4, heatCountNo);
						psU.executeUpdate();
						psU.close();
						if (rs1.getString("NEXT_PROCESS_CODE") != null
								&& !rs1.getString("NEXT_PROCESS_CODE").equals(
										"")) {
							ResultSet rsZy = null;
							if (rs1.getString("NEXT_PROCESS_CODE").equals("E")) {
								update = "UPDATE PLN_ZY_DBK_M T SET T.JUDGE_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=? AND T.JUDGE_STOVE_NO=T.FEED_HEAT_NO";
								ps = con.prepareStatement(update);
								ps.setObject(1, feedMax);
								ps.setObject(2, heatCountNo);
								ps.executeUpdate();
								ps.close();
								update = "UPDATE PLN_ZY_DBK_M T SET T.FEED_HEAT_NO=?,T.STOVE_NO=?,T.FLAG_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=?";
								ps = con.prepareStatement(update);
								ps.setObject(1, feedMax);
								ps.setObject(2, rs1.getString("STOVE_NO"));
								ps.setObject(3, feedMax);
								ps.setObject(4, heatCountNo);
								ps.executeUpdate();
								ps.close();
								// 查询镦拔扩工序炉计划ID及下工代码
								String sql = "SELECT T.PLANSTATUS,T.HEAT_PLAN_NO,T.NEXT_PROCESS_CODE,T.JUDGE_STOVE_NO,T.STOVE_NO,T.FLAG_STOVE_NO,T.FEED_HEAT_NO FROM PLN_ZY_DBK_M T WHERE T.UPPER_HEATPLAN_ID=?";
								ps = con.prepareStatement(sql);
								ps.setObject(1, heatCountNo);
								rsZy = ps.executeQuery();
								if (rsZy.next()) {

									mess = updateZyNext(con, rsZy
											.getString("JUDGE_STOVE_NO"), rsZy
											.getString("STOVE_NO"), rsZy
											.getString("FLAG_STOVE_NO"), rsZy
											.getString("HEAT_PLAN_NO"), rsZy
											.getString("NEXT_PROCESS_CODE"),
											rsZy.getString("PLANSTATUS"));
									if (!mess.equals("")) {
										return mess;
									}
								}
								rsZy.close();
								ps.close();
							} else if (rs1.getString("NEXT_PROCESS_CODE")
									.equals("F")) {
								update = "UPDATE PLN_ZY_RCL_M T SET T.JUDGE_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=? AND T.JUDGE_STOVE_NO=T.FEED_HEAT_NO";
								ps = con.prepareStatement(update);
								ps.setObject(1, feedMax);
								ps.setObject(2, heatCountNo);
								ps.executeUpdate();
								ps.close();
								update = "UPDATE PLN_ZY_RCL_M T SET T.FEED_HEAT_NO=?,T.STOVE_NO=?,T.FLAG_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=?";
								ps = con.prepareStatement(update);
								ps.setObject(1, feedMax);
								ps.setObject(2, rs1.getString("STOVE_NO"));
								ps.setObject(3, feedMax);
								ps.setObject(4, heatCountNo);
								ps.executeUpdate();
								ps.close();
								// 查询热处理工序炉计划ID及下工代码
								String sql = "SELECT T.PLANSTATUS,T.HEAT_PLAN_NO,T.NEXT_PROCESS_CODE,T.JUDGE_STOVE_NO,T.STOVE_NO,T.FLAG_STOVE_NO,T.FEED_HEAT_NO FROM PLN_ZY_RCL_M T WHERE T.UPPER_HEATPLAN_ID=?";
								ps = con.prepareStatement(sql);
								ps.setObject(1, heatCountNo);
								rsZy = ps.executeQuery();
								if (rsZy.next()) {

									mess = updateZyNext(con, rsZy
											.getString("JUDGE_STOVE_NO"), rsZy
											.getString("STOVE_NO"), rsZy
											.getString("FLAG_STOVE_NO"), rsZy
											.getString("HEAT_PLAN_NO"), rsZy
											.getString("NEXT_PROCESS_CODE"),
											rsZy.getString("PLANSTATUS"));
									if (!mess.equals("")) {
										return mess;
									}
								}
								rsZy.close();
								ps.close();
							} else if (rs1.getString("NEXT_PROCESS_CODE")
									.equals("G")) {
								update = "UPDATE PLN_ZY_JGX_M T SET T.JUDGE_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=? AND T.JUDGE_STOVE_NO=T.FEED_HEAT_NO";
								ps = con.prepareStatement(update);
								ps.setObject(1, feedMax);
								ps.setObject(2, heatCountNo);
								ps.executeUpdate();
								ps.close();
								update = "UPDATE PLN_ZY_JGX_M T SET T.FEED_HEAT_NO=?,T.STOVE_NO=?,T.FLAG_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=?";
								ps = con.prepareStatement(update);
								ps.setObject(1, feedMax);
								ps.setObject(2, rs1.getString("STOVE_NO"));
								ps.setObject(3, feedMax);
								ps.setObject(4, heatCountNo);
								ps.executeUpdate();
								ps.close();
								// 查询加工线工序炉计划ID及下工代码
								String sql = "SELECT T.PLANSTATUS,T.HEAT_PLAN_NO,T.NEXT_PROCESS_CODE,T.JUDGE_STOVE_NO,T.STOVE_NO,T.FLAG_STOVE_NO,T.FEED_HEAT_NO FROM PLN_ZY_JGX_M T WHERE T.UPPER_HEATPLAN_ID=?";
								ps = con.prepareStatement(sql);
								ps.setObject(1, heatCountNo);
								rsZy = ps.executeQuery();
								if (rsZy.next()) {
									mess = updateZyNext(con, rsZy
											.getString("JUDGE_STOVE_NO"), rsZy
											.getString("STOVE_NO"), rsZy
											.getString("FLAG_STOVE_NO"), rsZy
											.getString("HEAT_PLAN_NO"), rsZy
											.getString("NEXT_PROCESS_CODE"),
											rsZy.getString("PLANSTATUS"));
									if (!mess.equals("")) {
										return mess;
									}
								}
								rsZy.close();
								ps.close();
							} else {
								update = "UPDATE PLN_ZY_JG_M T SET T.JUDGE_STOVE_NO=?,T.STOVE_NO=?,T.FLAG_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=?";
								ps = con.prepareStatement(update);
								ps.setObject(1, feedMax);
								ps.setObject(2, rs1.getString("STOVE_NO"));
								ps.setObject(3, feedMax);
								ps.setObject(4, heatCountNo);
								ps.executeUpdate();
								ps.close();
							}
						}
					}
				}

				rs.close();
				ps.close();
				// }
			} else {
				// 修改轧管炉计划上料炉号
				String update = "UPDATE PLN_ZY_ZG_M T SET T.FEED_HEAT_NO=? WHERE T.HEAT_PLAN_NO=?";
				psU = con.prepareStatement(update);
				psU.setObject(1, "");
				psU.setObject(2, rs1.getString("HEAT_PLAN_NO"));
				psU.executeUpdate();
				psU.close();
			}
		}
		rs1.close();
		ps1.close();
		return mess;
	}

	/**
	 * 修改后工序判定炉号
	 * 
	 * @param con
	 * @param judgeStoveNo
	 * @param heatPlanNo
	 * @param proessCode
	 * @return
	 * @throws SQLException
	 */
	public String updateZyNext(Connection con, String judgeStoveNo,
			String stoveNo, String flagStoveNo, String heatPlanNo,
			String proessCode, String planstatust) throws SQLException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		String mess = "";
		String update = "";
		if (planstatust.equals("00")) {
			return mess;
		}
		if (proessCode != null && !proessCode.equals("")) {
			if (proessCode.equals("F")) {
				// 热处理
				update = "UPDATE PLN_ZY_RCL_M T SET T.JUDGE_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=? AND T.JUDGE_STOVE_NO=T.FEED_HEAT_NO";
				ps = con.prepareStatement(update);
				ps.setObject(1, judgeStoveNo);
				ps.setObject(2, heatPlanNo);
				ps.executeUpdate();
				ps.close();
				update = "UPDATE PLN_ZY_RCL_M T SET T.FEED_HEAT_NO=?,T.STOVE_NO=?,T.FLAG_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=?";
				ps = con.prepareStatement(update);
				ps.setObject(1, judgeStoveNo);
				ps.setObject(2, stoveNo);
				ps.setObject(3, judgeStoveNo);
				ps.setObject(4, heatPlanNo);
				ps.executeUpdate();
				ps.close();
				// 查询热处理工序炉计划ID及下工代码
				String sql = "SELECT T.PLANSTATUS,T.HEAT_PLAN_NO,T.NEXT_PROCESS_CODE,T.JUDGE_STOVE_NO,T.STOVE_NO,T.FLAG_STOVE_NO,T.FEED_HEAT_NO FROM PLN_ZY_RCL_M T WHERE T.UPPER_HEATPLAN_ID=?";
				ps = con.prepareStatement(sql);
				ps.setObject(1, heatPlanNo);
				rs = ps.executeQuery();
				if (rs.next()) {
					mess = updateZyNext(con, rs.getString("JUDGE_STOVE_NO"), rs
							.getString("STOVE_NO"), rs
							.getString("FLAG_STOVE_NO"), rs
							.getString("HEAT_PLAN_NO"), rs
							.getString("NEXT_PROCESS_CODE"), rs
							.getString("PLANSTATUS"));
					if (!mess.equals("")) {
						return mess;
					}
				}
				rs.close();
				ps.close();
			} else if (proessCode.equals("G")) {
				// 加工线
				update = "UPDATE PLN_ZY_JGX_M T SET T.JUDGE_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=? AND T.JUDGE_STOVE_NO=T.FEED_HEAT_NO";
				ps = con.prepareStatement(update);
				ps.setObject(1, judgeStoveNo);
				ps.setObject(2, heatPlanNo);
				ps.executeUpdate();
				ps.close();
				update = "UPDATE PLN_ZY_JGX_M T SET T.FEED_HEAT_NO=?,T.STOVE_NO=?,T.FLAG_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=?";
				ps = con.prepareStatement(update);
				ps.setObject(1, judgeStoveNo);
				ps.setObject(2, stoveNo);
				ps.setObject(3, judgeStoveNo);
				ps.setObject(4, heatPlanNo);
				ps.executeUpdate();
				ps.close();
				// 查询加工线工序炉计划ID及下工代码
				String sql = "SELECT T.PLANSTATUS,T.HEAT_PLAN_NO,T.NEXT_PROCESS_CODE,T.JUDGE_STOVE_NO,T.STOVE_NO,T.FLAG_STOVE_NO,T.FEED_HEAT_NO FROM PLN_ZY_JGX_M T WHERE T.UPPER_HEATPLAN_ID=?";
				ps = con.prepareStatement(sql);
				ps.setObject(1, heatPlanNo);
				rs = ps.executeQuery();
				if (rs.next()) {
					mess = updateZyNext(con, rs.getString("JUDGE_STOVE_NO"), rs
							.getString("STOVE_NO"), rs
							.getString("FLAG_STOVE_NO"), rs
							.getString("HEAT_PLAN_NO"), rs
							.getString("NEXT_PROCESS_CODE"), rs
							.getString("PLANSTATUS"));
					if (!mess.equals("")) {
						return mess;
					}
				}
				rs.close();
				ps.close();
			} else if (proessCode.equals("H")) {
				// 接箍
				update = "UPDATE PLN_ZY_JG_M T SET T.JUDGE_STOVE_NO=?,T.STOVE_NO=?,T.FLAG_STOVE_NO=? WHERE T.UPPER_HEATPLAN_ID=?";
				ps = con.prepareStatement(update);
				ps.setObject(1, judgeStoveNo);
				ps.setObject(2, stoveNo);
				ps.setObject(3, judgeStoveNo);
				ps.setObject(4, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
		}
		return mess;
	}

	/**
	 * 比较2个数组，获取相对于数组1相同的元素、相对于数组2相同的元素，2个数组相同的元素
	 * 
	 * @param t1
	 * @param t2
	 * @return
	 */
	public static List<String> compareArry(List<String> t1, List<String> t2) {
		/**
		 * 集合A (新的数据有，旧的数据没有，即为要添加的数据)
		 */
		List<String> listA = new ArrayList<String>();
		for (String str1 : t1) {// 遍历新的数组元素
			if (!t2.contains(str1)) {// 旧的数组中不包含新的元素（即为要添加的元素）
				if (!listA.contains(str1)) {
					listA.add(String.valueOf(str1));
				}
			}
		}
		Collections.sort(listA);
		return listA;
	}

	/**
	 * 判定单信息查询
	 * 
	 * @param con
	 * @throws SQLException
	 */
	public static List<QcmGpJudgeApplyEntity> getQcmGpApp(Connection con,
			String jugdeApplyCode, String jugdeApplySqe, String judgeStoveNo)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.QueryQcmGpApply");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, jugdeApplyCode);
		ps.setObject(2, jugdeApplySqe);
		ps.setObject(3, judgeStoveNo);
		ResultSet rs = ps.executeQuery();
		List<QcmGpJudgeApplyEntity> list = EntityTool.getEntitysByRs(rs,
				QcmGpJudgeApplyEntity.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (QcmGpJudgeApplyEntity listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	/**
	 * 查询是否生成锻造,轧管实际炉计划
	 * 
	 * @param con
	 * @throws SQLException
	 */
	public static int queryFurnC(Connection con, String jugdeApplyCode,
			String judgeStoveNo, String stoveNo, String multipleNum,
			String proPlanId, String gxPlanNo, String processCode,
			String heatPlanNoNext) throws SQLException {
		int count = 0;
		String sql = "";
		if (processCode.equals("C")) {
			sql = "SELECT COUNT(*) COUNT FROM PLN_ZY_DZ_C T WHERE 1=1";
		} else {
			sql = "SELECT COUNT(*) COUNT FROM PLN_ZY_ZG_C T WHERE 1=1";
		}
		if (heatPlanNoNext.equals("")) {
			sql += " AND T.PRO_PLAN_ID='" + proPlanId + "' AND T.GX_PLAN_NO='"
					+ gxPlanNo + "'";
		} else {
			sql += " AND T.HEAT_PLAN_NO='" + heatPlanNoNext + "'";
		}
		// AND T.JUGDE_APPLY_CODE=?
		sql += " AND T.JUDGE_STOVE_NO=? AND T.STOVE_NO=? AND T.CUT_NUM_GP=?";
		PreparedStatement ps = con.prepareStatement(sql);
		// ps.setObject(1, jugdeApplyCode);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, stoveNo);
		ps.setObject(3, multipleNum);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		return count;
	}

	/**
	 * 炼钢判定生成实际炉计划
	 * 
	 * @param con
	 * @param furnaces
	 * @param efplineCode
	 * @return
	 * @throws SQLException
	 * @throws ParseException
	 */
	public static String addPlnZyC(ArrayList<ArrayList<String>> jsonList,
			String createName, Connection con) throws SQLException,
			ParseException {
		String message = "";
		List<String> messageErr = new ArrayList<String>();
		PreparedStatement ps = null;
		// 获取数据库当前时间
		String dateTime = FrmSteelMakingPlanChange.getSystemTime(con);
		String messageZg = "";
		String messageDz = "";
		String messagepd = "";
		for (int i = 0; i < jsonList.size(); i++) {
			ArrayList<String> list = (ArrayList<String>) jsonList.get(i);
			int countMess = 0;
			String jugdeApplyCode = list.get(0);
			String jugdeApplySqe = list.get(1);
			String judgeStoveNo = list.get(2);
			String jugdeApply = jugdeApplyCode + jugdeApplySqe;
			// 通过判定单号，判定炉号查询判定信息
			List<QcmGpJudgeApplyEntity> qcmApp = getQcmGpApp(con,
					jugdeApplyCode, jugdeApplySqe, judgeStoveNo);
			if (qcmApp == null) {
				message = "判定信息已改变,请刷新判定数据!";
				return message;
			}
			// 已实际炉计划生成支吨
			int numC = 0;
			double wtC = 0;
			double cutYuLong = 0;// 切余长度
			for (QcmGpJudgeApplyEntity qcmGp : qcmApp) {
				countMess = 1;
				String furnaces = qcmGp.getFurnaceno();
				String sequenceNo = qcmGp.getSequenceno();
				String multipleNum = qcmGp.getMultipleNum();// 倍尺数
				int planInNum = Integer.parseInt(qcmGp.getActCount());
				double planInWt = Double
						.parseDouble(qcmGp.getActTheoryWeight());// 实重
				String dimater = qcmGp.getActDimater();
				String proPlanId = qcmGp.getProPlanIdNext();
				String gxPlanNo = qcmGp.getGxPlanNoNext();
				// String stoveNo = qcmGp.getStoveNo();
				double actLen = Double.parseDouble(qcmGp.getActLen());// 倍尺坯长
				String isendgx = qcmGp.getIsendgx();
				String gptype = qcmGp.getGptype();
				numC = Integer.parseInt(multipleNum) * planInNum;
				wtC = planInWt;
				double cutLength = 0;
				String heatPlanNoNext = qcmGp.getHeatPlanNoNext();
				// 判断申请判定是外购，还是自炼坯
				if (qcmGp.getPlineCode().equals("C063")
						|| qcmGp.getPlineCode().equals("C064")) {
					corePlnZyFurnM furnPlan = new corePlnZyFurnM();
					List<PlnZyZgMEntity> plnZg = getPlanSteOrdZgM(con,
							furnaces, sequenceNo, judgeStoveNo, "", "0",
							proPlanId, gxPlanNo, heatPlanNoNext);
					if (plnZg == null) {
						message += "判定申请单号:" + jugdeApplyCode + ",判定炉号:"
								+ judgeStoveNo + "未生成轧管虚拟炉计划";
						continue;
					}
					for (PlnZyZgMEntity plnZgS : plnZg) {
						double lenSingle = Double.parseDouble(plnZgS
								.getLenGpSingle());// 轧管单倍
						int cutNum = (int) (actLen / lenSingle);// 新倍尺数
						double actSingLen = cutNum * lenSingle;// 新倍尺长度
						cutLength = actLen - actSingLen;// 切余长度
						// 是否已生成轧管实际炉计划
						int countZg = queryFurnC(con, jugdeApply, judgeStoveNo,
								qcmGp.getStoveNo(), String.valueOf(cutNum),
								proPlanId, gxPlanNo, "D", heatPlanNoNext);
						if (countZg != 0) {
							// message += "判定申请单号:" + jugdeApplyCode + ",判定炉号:"
							// + judgeStoveNo + ",倍尺数:" + multipleNum
							// + "已存在轧管实际炉计划";
							// continue;
							// 修改实际炉计划判定单号
							String sqlupdte = "UPDATE PLN_ZY_ZG_C T SET T.PLAN_INDOUBLE_NUM=TO_NUMBER(NVL(T.PLAN_INDOUBLE_NUM,0))+TO_NUMBER(?), T.PLAN_INDOUBLE_WT=TO_NUMBER(NVL(T.PLAN_INDOUBLE_WT,0))+TO_NUMBER(?)"
									+ " WHERE T.JUGDE_APPLY_CODE=? AND T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.CUT_NUM_GP=?";
							ps = con.prepareStatement(sqlupdte);
							ps.setObject(1, planInNum);
							ps.setObject(2, planInWt);
							ps.setObject(3, jugdeApply);
							ps.setObject(4, judgeStoveNo);
							ps.setObject(5, proPlanId);
							ps.setObject(6, gxPlanNo);
							ps.setObject(7, cutNum);
							ps.executeUpdate();
							ps.close();

							// 算预计成品吨
							double aimOutdiam = Double.parseDouble(plnZgS
									.getAimoutdiameter());
							double aimwallthick = Double.parseDouble(plnZgS
									.getAimwallthick());
							double weightOne = (0.02466 * aimwallthick * (aimOutdiam - aimwallthick)) / 1000;
							double cutHeadEnd = (Double.parseDouble(plnZgS
									.getLenCutend()) + Double
									.parseDouble(plnZgS.getLenCuthead())) / 1000;
							double singlCpWt = weightOne
									* (Double.parseDouble(plnZgS
											.getRollLength()) - cutHeadEnd);
							// 查询轧管信息
							PlnOrderZgSEntityL plnZgO = FrmPlanMaterialSelection
									.getPlanOrderZg(con, plnZgS.getProPlanId(),
											plnZgS.getGxPlanNo(),
											PlnOrderZgSEntityL.class);
							double singlReduWt = (Double.parseDouble(plnZgO
									.getGpreqWeight()) / Double
									.parseDouble(plnZgO.getWeigthS()))
									* singlCpWt;
							// 修改虚拟炉计划量
							String sqlUpdate = CoreXmlSqlParsersFactory
									.getSql("ComPlanFurnace.updatePlnZgM");
							ps = con.prepareStatement(sqlUpdate);
							ps.setObject(1, plnZgS.getHeatPlanNo());
							ps.setObject(2, singlCpWt);
							ps.setObject(3, singlReduWt);
							ps.setObject(4, plnZgS.getHeatPlanNo());
							ps.executeUpdate();
							ps.close();
							continue;
						}
						// 生成轧管实际炉计划
						if (furnPlan.addPlnZyZgC(con, plnZgS, createName,
								dateTime, planInNum, planInWt, jugdeApply,
								multipleNum, actLen, numC, wtC)) {
						}
					}
				} else {
					// 判定铸造是否末工序 1.是，0.否
					if (isendgx.equals("0")) {
						corePlnZyFurnM furnPlan = new corePlnZyFurnM();
						// 通过虚拟炉次号,顺序号,判定炉号查询轧管虚拟炉计划
						if (gptype.equals("2")) {// 经过锻坯
							if (dimater.contains("t")) {// 一判
								// 通过虚拟炉次号,顺序号,判定炉号查询锻造虚拟炉计划
								List<PlnZyDzMEntity> plnDz = getPlanSteOrdM(
										con, furnaces, sequenceNo,
										judgeStoveNo, proPlanId, gxPlanNo);
								if (plnDz == null) {
									if (messageDz.equals("")) {
										messageDz = furnaces + "/" + sequenceNo;
									}
									if (!messageDz.contains(furnaces + "/"
											+ sequenceNo)) {
										messageDz = messageDz + "," + furnaces
												+ "/" + sequenceNo;
									}
									continue;
								}
								// 判定是否生成锻造实际炉计划
								int countDz = queryFurnC(con, jugdeApply,
										judgeStoveNo, qcmGp.getStoveNo(),
										multipleNum, proPlanId, gxPlanNo, "C",
										"");
								if (countDz != 0) {
									message += "判定申请单号:" + jugdeApplyCode
											+ ",判定炉号:" + judgeStoveNo + ",倍尺数:"
											+ multipleNum + "已存在锻造炉计划";
									continue;
								}
								// 生成锻造实际炉计划
								if (furnPlan.addPlnZyDzC(con, plnDz,
										createName, dateTime, planInNum,
										planInWt, jugdeApply, qcmGp)) {
								}
							} else {
								int countZg = queryFurnC(con, jugdeApply,
										judgeStoveNo, qcmGp.getStoveNo(),
										multipleNum, proPlanId, gxPlanNo, "D",
										heatPlanNoNext);
								if (countZg != 0) {
									message += "判定申请单号:" + jugdeApplyCode
											+ ",判定炉号:" + judgeStoveNo + ",倍尺数:"
											+ multipleNum + "已存在轧管炉计划";
									continue;
								}
								// 委外锭子回来的判定1.同时生成虚拟炉计划和实际炉计划
								corePlnZyFurnM.addPlnDzOutZg(con, qcmGp,
										createName, dateTime);
							}
						} else {

							// 通过虚拟炉次号,顺序号,判定炉号查询轧管虚拟炉计划
							List<PlnZyZgMEntity> plnZg = getPlanSteOrdZgM(con,
									furnaces, sequenceNo, judgeStoveNo, "",
									"1", proPlanId, gxPlanNo, heatPlanNoNext);
							if (plnZg == null) {
								if (messageZg.equals("")) {
									messageZg = furnaces + "/" + sequenceNo;
								}
								if (!messageZg.contains(furnaces + "/"
										+ sequenceNo)) {
									messageZg = messageZg + "," + furnaces
											+ "/" + sequenceNo;
								}
								continue;
							}
							for (PlnZyZgMEntity plnZgS : plnZg) {
								double lenSingle = Double.parseDouble(plnZgS
										.getLenGpSingle());// 轧管单倍
								int cutNum = (int) (actLen / lenSingle);// 新倍尺数
								double actSingLen = cutNum * lenSingle;// 新倍尺长度
								cutLength = actLen - actSingLen;// 切余长度
								int countZg = queryFurnC(con, jugdeApply,
										judgeStoveNo, qcmGp.getStoveNo(),
										String.valueOf(cutNum), proPlanId,
										gxPlanNo, "D", heatPlanNoNext);
								if (countZg != 0) {
									// message += "判定申请单号:" + jugdeApplyCode
									// + ",判定炉号:" + judgeStoveNo + ",倍尺数:"
									// + multipleNum + "已存在轧管炉计划";
									// // 修改实际炉计划判定单号
									String sqlupdte = "UPDATE PLN_ZY_ZG_C T SET T.PLAN_INDOUBLE_NUM=TO_NUMBER(NVL(T.PLAN_INDOUBLE_NUM,0))+TO_NUMBER(?), T.PLAN_INDOUBLE_WT=TO_NUMBER(NVL(T.PLAN_INDOUBLE_WT,0))+TO_NUMBER(?) WHERE T.JUGDE_APPLY_CODE=? AND T.JUDGE_STOVE_NO=?  AND T.CUT_NUM_GP=?";
									if (heatPlanNoNext.equals("")) {
										sqlupdte += " AND T.PRO_PLAN_ID='"
												+ proPlanId
												+ "' AND T.GX_PLAN_NO='"
												+ gxPlanNo + "'";
									} else {
										sqlupdte += " AND T.HEAT_PLAN_NO='"
												+ heatPlanNoNext + "'";
									}
									ps = con.prepareStatement(sqlupdte);
									ps.setObject(1, planInNum);
									ps.setObject(2, planInWt);
									ps.setObject(3, jugdeApply);
									ps.setObject(4, judgeStoveNo);
									ps.setObject(5, cutNum);
									ps.executeUpdate();
									ps.close();

									// 算预计成品吨
									double aimOutdiam = Double
											.parseDouble(plnZgS
													.getAimoutdiameter());
									double aimwallthick = Double
											.parseDouble(plnZgS
													.getAimwallthick());
									double weightOne = (0.02466 * aimwallthick * (aimOutdiam - aimwallthick)) / 1000;
									double cutHeadEnd = (Double
											.parseDouble(plnZgS.getLenCutend()) + Double
											.parseDouble(plnZgS.getLenCuthead())) / 1000;
									double singlCpWt = weightOne
											* (Double.parseDouble(plnZgS
													.getRollLength()) - cutHeadEnd);
									// 查询轧管信息
									PlnOrderZgSEntityL plnZgO = FrmPlanMaterialSelection
											.getPlanOrderZg(con, plnZgS
													.getProPlanId(), plnZgS
													.getGxPlanNo(),
													PlnOrderZgSEntityL.class);
									double singlReduWt = (Double
											.parseDouble(plnZgO
													.getGpreqWeight()) / Double
											.parseDouble(plnZgO.getWeigthS()))
											* singlCpWt;
									// 修改虚拟炉计划量
									String sqlUpdate = CoreXmlSqlParsersFactory
											.getSql("ComPlanFurnace.updatePlnZgM");
									ps = con.prepareStatement(sqlUpdate);
									ps.setObject(1, plnZgS.getHeatPlanNo());
									ps.setObject(2, singlCpWt);
									ps.setObject(3, singlReduWt);
									ps.setObject(4, plnZgS.getHeatPlanNo());
									ps.executeUpdate();
									ps.close();
									continue;
								}
								// 生成轧管实际炉计划
								if (furnPlan.addPlnZyZgC(con, plnZgS,
										createName, dateTime, planInNum,
										planInWt, jugdeApply, multipleNum,
										actLen, numC, wtC)) {
								}
							}
						}
					}
				}
				// 修改管坯MAT_GP_M挂料状态
				String updatesql = CoreXmlSqlParsersFactory
						.getSql("ComPlanFurnace.updateMatGpMEntity");
				ps = con.prepareStatement(updatesql);
				ps.setObject(1, jugdeApplyCode + jugdeApplySqe);
				ps.setObject(2, judgeStoveNo);
				ps.setObject(3, multipleNum);
				ps.setObject(4, proPlanId);
				ps.setObject(5, gxPlanNo);
				ps.setObject(6, planInNum);
				ps.setObject(7, "1");
				ps.setObject(8, "80150103");
				ps.setObject(9, cutLength);
				ps.executeUpdate();
				ps.close();
			}

			if (countMess != 0) {
				if (messagepd.equals("")) {
					messagepd = "判定单号：" + jugdeApplyCode + "炉号:" + judgeStoveNo;
				}
				if (!messagepd.contains("判定单号：" + jugdeApplyCode + "炉号:"
						+ judgeStoveNo)) {
					messagepd = messagepd + ",判定单号：" + jugdeApplyCode + "炉号:"
							+ judgeStoveNo;
				}
			}
		}
		if (!messageZg.equals("")) {
			messageErr.add("虚拟炉次号：" + messageZg + "找不到轧管虚拟炉次计划");
		}
		if (!messageDz.equals("")) {
			messageErr.add("虚拟炉次号：" + messageDz + "找不到锻造虚拟炉次计划");
		}
		if (!messagepd.equals("")) {
			messageErr.add(messagepd);
		}
		if (messageErr.size() > 0) {
			message += messageErr.toString();
		}
		return message;
	}

	/**
	 * 判定回退，判定不合删除实际炉计划
	 * 
	 * @param con
	 * @throws SQLException
	 */
	public static String deletePlnSteelOrdC(
			ArrayList<ArrayList<String>> jsonList, String createName,
			Connection con) throws SQLException {
		String message = "";
		List<String> messageErr = new ArrayList<String>();
		PreparedStatement ps = null;
		String messageZg = "";
		String messageDz = "";
		String messagepd = "";
		ResultSet rs = null;
		for (int i = 0; i < jsonList.size(); i++) {
			ArrayList<String> list = (ArrayList<String>) jsonList.get(i);
			String jugdeApplyCode = list.get(0);
			String jugdeApplySqe = list.get(1);
			String judgeStoveNo = list.get(2);
			String jugdeApply = jugdeApplyCode + jugdeApplySqe;
			int countMess = 0;

			// 通过判定单号，判定炉号查询判定信息
			List<QcmGpJudgeApplyEntity> qcmApp = getQcmGpApp(con,
					jugdeApplyCode, jugdeApplySqe, judgeStoveNo);
			if (qcmApp == null) {
				message = "未查询到判定数据,请刷新判定记录!";
				return message;
			}
			for (QcmGpJudgeApplyEntity qcmGp : qcmApp) {
				countMess = 1;
				String furnaces = qcmGp.getFurnaceno();
				String sequenceNo = qcmGp.getSequenceno();
				int planInNum = Integer.parseInt(qcmGp.getActCount());
				String multipleNum = qcmGp.getMultipleNum();// 倍尺数
				// double planInWt =
				// Double.parseDouble(qcmGp.getActWeight());// 实重
				// String dimater = rs.getString("ACT_DIMATER");
				String proPlanId = qcmGp.getProPlanIdNext();
				String gxPlanNo = qcmGp.getGxPlanNoNext();
				String isendgx = qcmGp.getIsendgx();
				String gptype = qcmGp.getGptype();
				String heatPlanNoNext = qcmGp.getHeatPlanNoNext();
				// double actLen = Double.parseDouble(qcmGp.getActLen());
				// 判断申请判定是外购，还是自炼坯
				if (qcmGp.getPlineCode().equals("C063")
						|| qcmGp.getPlineCode().equals("C064")) {
					List<PlnZyZgMEntity> plnZg = getPlanSteOrdZgM(con,
							furnaces, sequenceNo, judgeStoveNo, "", "0",
							proPlanId, gxPlanNo, heatPlanNoNext);
					if (plnZg == null) {
						message += "判定申请单号:" + jugdeApplyCode + ",判定炉号:"
								+ judgeStoveNo + "未生成轧管虚拟炉计划";
						continue;
					}
					for (PlnZyZgMEntity plnZgS : plnZg) {
						if (!plnZgS.getPlanstatus().equals("00")
								&& !plnZgS.getPlanstatus().equals("10")) {
							message = "该判定炉号(" + judgeStoveNo
									+ "),轧管已生产,不能撤销判定!";
							return message;
						}

						if (plnZgS.getPlanstatus().equals("10")) {
							// 查询炉计划主表有多少记录
							String sql = "SELECT T.HEAT_PLAN_SQE,T.FEED_HEAT_NO FROM PLN_ZY_ZG_C T WHERE T.HEAT_PLAN_NO = ? AND T.JUGDE_APPLY_CODE=?";
							ps = con.prepareStatement(sql);
							ps.setObject(1, plnZgS.getHeatPlanNo());
							ps.setObject(2, jugdeApply);
							rs = ps.executeQuery();
							while (rs.next()) {
								// 删除炉计划接收表
								String deleteSqlPls = "DELETE MIL_FEED_PLAN  WHERE FEED_ROW_NO = ? AND JUDGE_STOVE_NO =?";
								PreparedStatement ps1 = con
										.prepareStatement(deleteSqlPls);
								ps1.setObject(1, rs.getString("HEAT_PLAN_SQE"));
								ps1.setObject(2, plnZgS.getFeedHeatNo() + "-"
										+ "01");
								ps1.executeUpdate();
								ps1.close();
							}
							rs.close();
							ps.close();
						}
						// 删除轧管实际炉计划
						String deletesqlZg = "DELETE PLN_ZY_ZG_C  WHERE HEAT_PLAN_NO = ? AND JUGDE_APPLY_CODE = ?";
						ps = con.prepareStatement(deletesqlZg);
						ps.setObject(1, plnZgS.getHeatPlanNo());
						ps.setObject(2, jugdeApply);
						ps.executeUpdate();
						ps.close();
					}

				} else {
					// 判定铸造是否末工序 1.是，0.否
					if (isendgx.equals("0")) {
						if (gptype.equals("2")) {// 经过锻坯
							if (qcmGp.getActDimater().contains("t")) {
								// 通过虚拟炉次号,顺序号,判定炉号查询锻造虚拟炉计划
								List<PlnZyDzMEntity> plnDz = getPlanSteOrdM(
										con, furnaces, sequenceNo,
										judgeStoveNo, proPlanId, gxPlanNo);
								if (plnDz == null) {
									if (messageDz.equals("")) {
										messageDz = furnaces + "/" + sequenceNo;
									}
									if (!messageDz.contains(furnaces + "/"
											+ sequenceNo)) {
										messageDz = messageDz + "," + furnaces
												+ "/" + sequenceNo;
									}
									continue;
								}
								for (PlnZyDzMEntity plnDzS : plnDz) {
									// 删除锻造实际炉计划
									String deletesqlDz = "DELETE PLN_ZY_DZ_C WHERE HEAT_PLAN_NO = ? AND JUGDE_APPLY_CODE = ?";
									ps = con.prepareStatement(deletesqlDz);
									ps.setObject(1, plnDzS.getHeatPlanNo());
									ps.setObject(2, jugdeApply);
									ps.executeUpdate();
									ps.close();
								}
							} else {
								List<PlnZyZgMEntity> plnZg = ComPlanFurnace
										.getPlanSteOrdZgM(con, furnaces,
												sequenceNo, judgeStoveNo, "",
												"1", proPlanId, gxPlanNo,
												heatPlanNoNext);
								if (plnZg == null) {
									if (messageZg.equals("")) {
										messageZg = furnaces + "/" + sequenceNo;
									}
									if (!messageZg.contains(furnaces + "/"
											+ sequenceNo)) {
										messageZg = messageZg + "," + furnaces
												+ "/" + sequenceNo;
									}
									continue;
								}
								for (PlnZyZgMEntity plnZgS : plnZg) {
									if (!plnZgS.getPlanstatus().equals("00")
											&& !plnZgS.getPlanstatus().equals(
													"10")) {
										message = "该判定炉号(" + judgeStoveNo
												+ "),轧管已生产,不能撤销判定!";
										return message;
									}
									if (plnZgS.getPlanstatus().equals("10")) {
										// 查询炉计划主表有多少记录
										String sql = "SELECT T.HEAT_PLAN_SQE,T.FEED_HEAT_NO FROM PLN_ZY_ZG_C T WHERE T.HEAT_PLAN_NO = ? AND T.JUGDE_APPLY_CODE=?";
										ps = con.prepareStatement(sql);
										ps.setObject(1, plnZgS.getHeatPlanNo());
										ps.setObject(2, jugdeApply);
										rs = ps.executeQuery();
										while (rs.next()) {
											PreparedStatement ps1 = null;
											String heatPlanSqe = rs
													.getString("HEAT_PLAN_SQE");
											// 删除炉计划接收表
											String delete = "DELETE MIL_FEED_PLAN  WHERE FEED_ROW_NO = ?";
											ps1 = con.prepareStatement(delete);
											ps1.setObject(1, heatPlanSqe);
											ps1.executeUpdate();
											ps1.close();
										}
										rs.close();
										ps.close();
										// 删除炉计划接收表
										String deleteMil = "DELETE MIL_PLAN WHERE ID = ?";
										ps = con.prepareStatement(deleteMil);
										ps.setObject(1, plnZgS.getHeatPlanNo());
										ps.executeUpdate();
										ps.close();
									}
									// 删除轧管实际炉计划
									String deletesqlZg = "DELETE PLN_ZY_ZG_C  WHERE HEAT_PLAN_NO = ? AND JUGDE_APPLY_CODE = ?";
									ps = con.prepareStatement(deletesqlZg);
									ps.setObject(1, plnZgS.getHeatPlanNo());
									ps.setObject(2, jugdeApply);
									ps.executeUpdate();
									ps.close();
									// 删除轧虚拟炉计划
									deletesqlZg = "DELETE PLN_ZY_ZG_M  WHERE HEAT_PLAN_NO = ?";
									ps = con.prepareStatement(deletesqlZg);
									ps.setObject(1, plnZgS.getHeatPlanNo());
									ps.executeUpdate();
									ps.close();

									// 回写库存下工序炉计划Id
									String sqlUpdate = "UPDATE MAT_GP_M T SET T.HEAT_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_ZG=? AND T.GX_PLAN_NO_ZG=?";
									ps = con.prepareStatement(sqlUpdate);
									ps.setObject(1, "");
									ps.setObject(2, qcmGp.getJudgeStoveNo());
									ps.setObject(3, plnZgS.getProPlanId());
									ps.setObject(4, plnZgS.getGxPlanNo());
									ps.executeUpdate();
									ps.close();
									// 回写申请判定下工序炉计划Id
									sqlUpdate = "UPDATE QCM_GP_JUDGE_APPLY T SET T.HEAT_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=?";
									ps = con.prepareStatement(sqlUpdate);
									ps.setObject(1, "");
									ps.setObject(2, qcmGp.getJudgeStoveNo());
									ps.setObject(3, plnZgS.getProPlanId());
									ps.setObject(4, plnZgS.getGxPlanNo());
									ps.executeUpdate();
									ps.close();
								}
							}
						} else {
							// 查询轧管虚拟实际炉计划
							List<PlnZyZgMEntity> plnZg = ComPlanFurnace
									.getPlanSteOrdZgM(con, furnaces,
											sequenceNo, judgeStoveNo, "", "1",
											proPlanId, gxPlanNo, heatPlanNoNext);
							if (plnZg == null) {
								if (messageZg.equals("")) {
									messageZg = furnaces + "/" + sequenceNo;
								}
								if (!messageZg.contains(furnaces + "/"
										+ sequenceNo)) {
									messageZg = messageZg + "," + furnaces
											+ "/" + sequenceNo;
								}
								continue;
							}
							for (PlnZyZgMEntity plnZgS : plnZg) {
								if (!plnZgS.getPlanstatus().equals("00")
										&& !plnZgS.getPlanstatus().equals("10")) {
									message = "该判定炉号(" + judgeStoveNo
											+ "),轧管已生产,不能撤销判定!";
									return message;
								}
								if (plnZgS.getPlanstatus().equals("10")) {
									// 查询炉计划主表有多少记录
									String sql = "SELECT T.HEAT_PLAN_SQE,T.FEED_HEAT_NO FROM PLN_ZY_ZG_C T WHERE T.HEAT_PLAN_NO = ? AND T.JUGDE_APPLY_CODE=?";
									ps = con.prepareStatement(sql);
									ps.setObject(1, plnZgS.getHeatPlanNo());
									ps.setObject(2, jugdeApply);
									rs = ps.executeQuery();
									while (rs.next()) {
										// 删除炉计划接收表
										String deleteSqlPls = "DELETE MIL_FEED_PLAN  WHERE FEED_ROW_NO = ? AND JUDGE_STOVE_NO =?";
										PreparedStatement ps1 = con
												.prepareStatement(deleteSqlPls);
										ps1.setObject(1, rs
												.getString("HEAT_PLAN_SQE"));
										ps1.setObject(2, plnZgS.getFeedHeatNo()
												+ "-" + "01");
										ps1.executeUpdate();
										ps1.close();
									}
									rs.close();
									ps.close();
								}
								// 删除轧管实际炉计划
								String deletesqlZg = "DELETE PLN_ZY_ZG_C  WHERE HEAT_PLAN_NO = ? AND JUGDE_APPLY_CODE = ?";
								ps = con.prepareStatement(deletesqlZg);
								ps.setObject(1, plnZgS.getHeatPlanNo());
								ps.setObject(2, jugdeApply);
								ps.executeUpdate();
								ps.close();
							}
						}
					}
				}
				// 修改管坯MAT_GP_M挂料状态
				String updatesql = CoreXmlSqlParsersFactory
						.getSql("ComPlanFurnace.updateMatGpNewEntity");
				ps = con.prepareStatement(updatesql);
				ps.setObject(1, jugdeApplyCode + jugdeApplySqe);
				ps.setObject(2, judgeStoveNo);
				ps.setObject(3, multipleNum);
				ps.setObject(4, proPlanId);
				ps.setObject(5, gxPlanNo);
				ps.setObject(6, planInNum);
				ps.setObject(7, "0");
				ps.setObject(8, "80150102");
				ps.setObject(9, "0");
				ps.executeUpdate();
				ps.close();
			}
			if (countMess != 0) {
				if (messagepd.equals("")) {
					messagepd = "判定单号：" + jugdeApplyCode + "炉号:" + judgeStoveNo;
				}
				if (!messagepd.contains("判定单号：" + jugdeApplyCode + "炉号:"
						+ judgeStoveNo)) {
					messagepd = messagepd + ",判定单号：" + jugdeApplyCode + "炉号:"
							+ judgeStoveNo;
				}
			}
		}
		if (!messageZg.equals("")) {
			messageErr.add("虚拟炉次号：" + messageZg + "找不到轧管虚拟炉次计划");
		}
		if (!messageDz.equals("")) {
			messageErr.add("虚拟炉次号：" + messageDz + "找不到锻造虚拟炉次计划");
		}
		if (!messagepd.equals("")) {
			messageErr.add(messagepd);
		}
		if (messageErr.size() > 0) {
			// 异常新增
			message += messageErr.toString();
		}
		return message;
	}

	/**
	 * 炼钢计划下发，生产中利库生成虚拟炉计划(自炼)
	 * 
	 * @param con
	 * @param furnaces
	 * @throws SQLException
	 */
	public static String addPlnSteelOrd(Connection con, String furnaces,
			String sequenceno, String createName) throws SQLException {
		String messag = "";
		// 获取数据库当前时间
		String dateTime = FrmSteelMakingPlanChange.getSystemTime(con);
		// 获取当前下发炉次订单信息
		List<PlnSteelforOrdEntityL> steOrd = getPlanSteOrdSingle(con, furnaces,
				sequenceno);
		if (steOrd == null) {
			messag = "连铸炉次订单数据异常,请刷新数据!";
			return messag;
		}
		for (PlnSteelforOrdEntityL stord : steOrd) {
			// 判定铸造是否末工序 1.是，0.否
			if (stord.getIsendgx().equals("0")) {
				if (stord.getGptype().equals("2")) {// 经过锻坯
					// 通过铸造订单号PRO_PLAN_ID查询锻造订单个数
					List<PlnOrderDzSEntityL> plnDz = getPlanSteOrd(con, stord
							.getProPlanId(), "");
					if (plnDz == null) {
						messag = "未找到锻造订单排产信息!";
						return messag;
					}
					corePlnZyFurnM furnPlan = new corePlnZyFurnM();
					// 生成锻造虚拟炉计划
					if (furnPlan.addPlnZyDzM(con, stord, plnDz, createName,
							dateTime)) {
						// messag = "锻造订单排产信息不是计划,生产中的状态!";
						// return messag;
					}
				} else {
					// 通过铸造订单号PRO_PLAN_ID查询轧管订单个数
					List<PlnOrderZgSEntityL> plnZg = getPlanSteOrdZg(con, stord
							.getProPlanId(), stord.getGxPlanNo(), "1");
					if (plnZg == null) {
						messag = "未找到轧管订单排产信息!";
						return messag;
					}
					int countZg = 0;
					for (PlnOrderZgSEntityL plnZgS : plnZg) {
						countZg++;
					}
					corePlnZyFurnM furnPlan = new corePlnZyFurnM();
					// 生成轧管虚拟炉计划
					if (furnPlan.addPlnZyZgM(con, stord, plnZg, createName,
							dateTime, "B", "", countZg)) {
						// messag = "轧管订单" + stord.getProPlanId() + "/"
						// + stord.getGxPlanNo() + "不是计划,生产中的状态!";
						// return messag;
					}
				}
			}
		}
		return messag;
	}

	/**
	 * 炼钢计划下发，生产中利库删除虚拟炉计划(自炼)
	 * 
	 * @param con
	 * @param furnaces
	 * @param efplineCode
	 * @return
	 * @throws SQLException
	 */
	public static String deleteSteelOrd(Connection con, String furnaces,
			String sequenceno) throws SQLException {
		String messag = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "";

		// 获取当前下发炉次订单信息
		List<PlnSteelforOrdEntityL> steOrd = getPlanSteOrdSingle(con, furnaces,
				sequenceno);
		if (steOrd == null) {
			messag = "连铸炉次订单数据异常,请刷新数据!";
			return messag;
		}
		for (PlnSteelforOrdEntityL stord : steOrd) {
			// 判定铸造是否末工序 1.是，0.否
			if (stord.getIsendgx().equals("0")) {
				if (stord.getGptype().equals("2")) {// 经过锻坯
					// 通过虚拟炉号+炉次内顺序号查找锻造虚拟炉计划
					sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,"
							+ " T.PLN_INSINGLE_WT,T.PRO_PLAN_ID,T.GX_PLAN_NO,T.GX_PRO_SEQ,T.PLINE_CODE FROM PLN_ZY_DZ_M  T WHERE T.UPPER_HEATPLAN_ID=? AND T.PLANSTATUS='00'";
					ps = con.prepareStatement(sql);
					ps.setObject(1, stord.getFurnaceno() + "/"
							+ stord.getSequenceno());
					rs = ps.executeQuery();
					while (rs.next()) {
						PreparedStatement psC = null;
						ResultSet rsC = null;
						int countNumd = 0;
						// 查询是否存在锻造实际炉计划
						String sqlDzC = "SELECT COUNT(*) COUNT FROM PLN_ZY_DZ_C T WHERE T.HEAT_PLAN_NO=?";
						psC = con.prepareStatement(sqlDzC);
						psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
						rsC = psC.executeQuery();
						if (rsC.next()) {
							countNumd = rsC.getInt("COUNT");
						}
						rsC.close();
						psC.close();
						if (countNumd > 0) {
							messag = "虚拟炉次号:" + stord.getFurnaceno() + "/"
									+ stord.getSequenceno()
									+ "的虚拟锻造炉计划存在锻造实际炉计划,不能撤销";
							return messag;
						}
						// 删除锻造虚拟炉计划
						String sqlDeleteDz = "DELETE PLN_ZY_DZ_M  WHERE HEAT_PLAN_NO = ? ";
						psC = con.prepareStatement(sqlDeleteDz);
						psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
						psC.executeUpdate();
						psC.close();
					}
					rs.close();
					ps.close();
				} else {

					// 通过虚拟炉号+炉次内顺序号查找轧管虚拟炉计划
					sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,T.PLN_INSINGLE_WT,"
							+ "T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLINE_CODE,T.GX_PRO_SEQ FROM PLN_ZY_ZG_M  T WHERE T.UPPER_HEATPLAN_ID=? AND T.PLANSTATUS='00'";
					ps = con.prepareStatement(sql);
					ps.setObject(1, stord.getFurnaceno() + "/"
							+ stord.getSequenceno());
					rs = ps.executeQuery();
					while (rs.next()) {
						int countNum = 0;
						// 查询是否存在轧管实际炉计划
						String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_ZG_C T WHERE T.HEAT_PLAN_NO=?";
						PreparedStatement psC = con.prepareStatement(sqlZgC);
						psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
						ResultSet rsC = psC.executeQuery();
						if (rsC.next()) {
							countNum = rsC.getInt("COUNT");
						}
						rsC.close();
						psC.close();
						if (countNum > 0) {
							messag = "虚拟炉次号+虚拟炉次内顺序号:" + stord.getFurnaceno()
									+ "/" + stord.getSequenceno()
									+ "的虚拟轧管炉计划存在轧管实际炉计划,不能撤销";
							return messag;
						}
						// 删除轧管虚拟炉计划
						String sqlDeleteZg = "DELETE PLN_ZY_ZG_M  WHERE HEAT_PLAN_NO = ? ";
						psC = con.prepareStatement(sqlDeleteZg);
						psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
						psC.executeUpdate();
						psC.close();
					}
					rs.close();
					ps.close();
				}
			}
		}
		return messag;
	}
}
