package com.steering.pss.plnsaleord.stove;

import CoreFS.SA08.CoreXmlSqlParsersFactory;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.planStove.StoveHelper;
import com.steering.pss.plnsaleord.processOrder.entity.PlnGxJgPropSEntity;
import com.steering.pss.plnsaleord.stove.entity.*;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * 炉计划公用方法
 * 
 * @author teng 2017.10.27
 */
public class corePlanFurnProM extends DBCommon {
	private String errMessage = "";// 返回错误信息

	/**
	 * 返回错误信息
	 * 
	 * @return
	 */
	public String getErrMessage() {
		return errMessage;
	}

	/**
	 * 返回错误信息
	 * 
	 * @return
	 */
	public void setErrMessage(String errMessage) {
		this.errMessage = errMessage;
	}

	/**
	 * 查询产线内炉计划最大生产序号
	 * 
	 * @param con
	 * @param
	 * @return
	 * @throws SQLException
	 */
	public static int getMaxGxPlnSeq(Connection con, String plineCode,
			String processCode) throws SQLException {
		int gxPlnSeq = 1;
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.getMaxGxPlnSeq");
		if (processCode.equals("E")) {
			sql += " FROM PLN_ZY_DBK_M T ";
		} else if (processCode.equals("F")) {
			sql += " FROM PLN_ZY_RCL_M T ";
		} else if (processCode.equals("G")) {
			sql += " FROM PLN_ZY_JGX_M T ";
		} else if (processCode.equals("H")) {
			sql += " FROM PLN_ZY_JG_M T ";
		}
		sql += " WHERE T.PLINE_CODE=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, plineCode);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			gxPlnSeq = rs.getInt("GX_PRO_SEQ");
		}
		rs.close();
		ps.close();
		return gxPlnSeq;
	}

	/**
	 * 查询订单内炉顺序号
	 * 
	 * @param con
	 * @return
	 * @throws SQLException
	 */
	public static int getMaxLotNoSqe(Connection con, String proPlanId,
			String gxPlanNo, String processCode) throws SQLException {
		int gxPlnSeq = 1;
		String sql = "";
		if (processCode.equals("F")) {
			sql = "SELECT TO_NUMBER(NVL(MAX(T.LOT_NO_SQE),0))+1 AS LOT_NO_SQE FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID='"
					+ proPlanId + "' AND T.GX_PLAN_NO='" + gxPlanNo + "'";
		} else if (processCode.equals("G")) {
			sql = "SELECT TO_NUMBER(NVL(MAX(T.LOT_NO_SQE),0))+1 AS LOT_NO_SQE FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID='"
					+ proPlanId + "' AND T.GX_PLAN_NO='" + gxPlanNo + "'";
		}else if (processCode.equals("E")) {
			sql = "SELECT TO_NUMBER(NVL(MAX(T.LOT_NO_SQE),0))+1 AS LOT_NO_SQE FROM PLN_ZY_DBK_M T WHERE T.PRO_PLAN_ID='"
					+ proPlanId + "' AND T.GX_PLAN_NO='" + gxPlanNo + "'";
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			gxPlnSeq = rs.getInt("LOT_NO_SQE");
		}
		rs.close();
		ps.close();
		return gxPlnSeq;
	}

	/**
	 * 获取实际炉计划上料行ID
	 * 
	 * @param con
	 * @param
	 * @return
	 * @throws SQLException
	 */
	public static String getHeatPlanSeq(Connection con, String heatPlanNo,
			String processCode) throws SQLException {
		String heatPlanSeq = "";
		String sql = CoreXmlSqlParsersFactory
				.getSql("ComPlanFurnace.getHeatPlanSeq");

		if (processCode.equals("E")) {
			sql += " FROM PLN_ZY_DBK_C T ";
		} else if (processCode.equals("F")) {
			sql += " FROM PLN_ZY_RCL_C T ";
		} else if (processCode.equals("G")) {
			sql += " FROM PLN_ZY_JGX_C T ";
		} else if (processCode.equals("H")) {
			sql += " FROM PLN_ZY_JG_C T ";
		}
		sql += " WHERE T.HEAT_PLAN_NO=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, heatPlanNo);
		ps.setObject(2, heatPlanNo);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			heatPlanSeq = rs.getString("HEAT_PLAN_SQE");
		}
		rs.close();
		ps.close();
		return heatPlanSeq;
	}

	/**
	 * 查询同订单/排产序号最大炉计划Id
	 * 
	 * @param con
	 * @param
	 * @return
	 * @throws SQLException
	 */
	public static String getMaxHeatPlanNo(Connection con, String proPlanNoSeq,
			String proPlanId, String processCode) throws SQLException {
		String heatPlanNo = "";
		String sql = "SELECT ? ||  LPAD(SUBSTR(NVL(MAX(T.HEAT_PLAN_NO),'000'),-3,3) + 1, 3, '0') AS HEAT_PLAN_NO";
		if (processCode.equals("E")) {
			sql += " FROM PLN_ZY_DBK_M T ";
		} else if (processCode.equals("F")) {
			sql += " FROM PLN_ZY_RCL_M T ";
		} else if (processCode.equals("G")) {
			sql += " FROM PLN_ZY_JGX_M T ";
		} else if (processCode.equals("H")) {
			sql += " FROM PLN_ZY_JG_M T ";
		}
		sql += " WHERE T.PRO_PLAN_ID=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, proPlanNoSeq);
		ps.setObject(2, proPlanId);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			heatPlanNo = rs.getString("HEAT_PLAN_NO");
		}
		rs.close();
		ps.close();
		return heatPlanNo;
	}

	/**
	 * 获取产线对应去向
	 * 
	 * @param con
	 * @throws SQLException
	 */
	public static String getPlineCodeGroup(Connection con, String plineCode,
			String proPlanId, String gxPlanNo, String processCode)
			throws SQLException {
		String param = "";
		String sql = "";
		if (processCode.equals("E")) {
			sql += CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.QueryDbkGroup");
		} else if (processCode.equals("F")) {
			sql += CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.QueryRclGroup");
		} else if (processCode.equals("G")) {
			sql += CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.QueryJgxGroup");
		}
		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;
	}

	/**
	 * 新增镦拔扩虚拟炉计划(自炼轧管炉计划下发)
	 * 
	 * @return
	 */
	public boolean addPlnZyDbkM(Connection con, PlnZyZgMEntity plnZgPln,
			List<PlnOrderDbkSEntity> plnDbk, String createName,
			String createTime) throws SQLException {
		PlnZyDbkMEntity plnDbkM = new PlnZyDbkMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 轧管单倍支
		int cutNum = Integer.parseInt(plnZgPln.getOutnumCut());
		int zgNum = Integer.parseInt(plnZgPln.getPlnOutsingleNum());
		double totWeightM = Double.parseDouble(plnZgPln.getPlnOutsingleW());
		int contZgM = 0;
		int countZg = plnDbk.size();
		String judgeStoveNo = "";
		for (PlnOrderDbkSEntity plnDbkS : plnDbk) {
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnDbkS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnDbkS.getProPlanId() + "/"
							+ plnDbkS.getGxPlanNo());
				} else {
					String message = plnDbkS.getProPlanId() + "/"
							+ plnDbkS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				continue;
			}
			double wtIn = 0;// 已生成炉计划原料吨(已装炉)
			// int numIn = 0;
			// 查询当前镦拔扩订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLN_INSINGLE_NUM),0) PLN_INSINGLE_NUM,NVL(SUM(T.PLN_INSINGLE_WT),0) PLN_INSINGLE_WT FROM PLN_ZY_DBK_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnDbkS.getProPlanId());
			ps.setObject(2, plnDbkS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLN_INSINGLE_WT");
				// numIn = rs.getInt("PLN_INSINGLE_NUM");
			}
			rs.close();
			ps.close();
			sql = "SELECT NVL(SUM(T.PLAN_INDOUBLE_WT),0) PLAN_INDOUBLE_WT FROM PLN_ZY_DBK_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnDbkS.getProPlanId());
			ps.setObject(2, plnDbkS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("PLAN_INDOUBLE_WT");
			}
			rs.close();
			ps.close();
			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_DBK_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1,
					plnDbkS.getProPlanId() + "/" + plnDbkS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getFeedHeatNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// if (judgeStoveNo.equals("")
			// && !judgeStoveNo.equals(plnZgPln.getFeedHeatNo())) {
			// judgeStoveNo = plnZgPln.getFeedHeatNo();
			// }
			// if (judgeStoveNo.equals(plnZgPln.getFeedHeatNo())) {
			// oldWt = totWeightM;
			// oldNum = zgNum;
			// } else {
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnDbkS.getWeigthS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnDbkS.getWeigthS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}
			// }
			if (oldNum <= 0) {
				continue;
			}
			plnDbkM.setPassCode(plnZgPln.getPassCode());
			plnDbkM.setPassName(plnZgPln.getPassName());
			plnDbkM.setDecision(plnDbkS.getDecision());
			plnDbkM.setZyBatchIdZg(plnZgPln.getZyBatchId());
			plnDbkM.setStoveNo(plnZgPln.getStoveNo());
			plnDbkM.setFeedHeatNo(plnZgPln.getFeedHeatNo());
			if(plnZgPln.getPlineCode().equals("C072"))
			{
				plnDbkM.setJudgeStoveNo("");
				plnDbkM.setFlagStoveNo("");
			}else
			{
				plnDbkM.setJudgeStoveNo(plnZgPln.getFeedHeatNo());
				plnDbkM.setFlagStoveNo(plnZgPln.getFeedHeatNo());
			}

			plnDbkM.setBatchNo("");
			plnDbkM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnDbkM.setPlanstatus("00");
			plnDbkM.setUpperProcessCode("D");
			plnDbkM.setPlineCode(plnDbkS.getPlineCode());
			plnDbkM.setPlineName(plnDbkS.getPlineName());
			plnDbkM.setProcessCodeC(plnDbkS.getProcessCodeC());
			plnDbkM.setProcessDescC(plnDbkS.getProcessDescC());
			if (!plnDbkS.getDecision().equals("A")) {
				// 通过制程判定镦拔扩是否末工序
				if (plnDbkS.getWholeBacklogDesc().contains("热处理")) {
					plnDbkM.setNextProcessCode("F");
				} else if (plnDbkS.getWholeBacklogDesc().contains("加工")) {
					plnDbkM.setNextProcessCode("G");
				} else if (plnDbkS.getWholeBacklogDesc().contains("接箍")) {
					plnDbkM.setNextProcessCode("H");
				} else {
					if (plnDbkS.getOrdLnDlyPk().contains("ZZBY-J")) {
						plnDbkM.setNextProcessCode("H");
					} else if (plnDbkS.getOrdLnDlyPk().contains("ZZBY-D")) {
						plnDbkM.setNextProcessCode("G");
					} else {
						plnDbkM.setNextProcessCode("");
					}
				}
				plnDbkM.setIsendgx("0");
			} else {
				plnDbkM.setNextProcessCode("");
				plnDbkM.setIsendgx("1");
			}
			// String gowWhere = getPlineCodeGroup(con, plnDbkS.getPlineCode(),
			// plnDbkS.getProPlanId(), plnDbkS.getGxPlanNo(), "E");
			// if (gowWhere != null) {
			// // 查询去向
			// String sqlGroup =
			// "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
			// ps = con.prepareStatement(sqlGroup);
			// ps.setObject(1, plnDbkS.getPlineCode());
			// ps.setObject(2, gowWhere);
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnDbkM.setGowhereName(rs.getString("STORAGE_NAME"));
			// plnDbkM.setGowhereCode(rs.getString("STORAGE_NO"));
			// }
			// rs.close();
			// ps.close();
			// }
			plnDbkM.setIfMatchOdd("0");
			plnDbkM.setIfDoHeatPlan("0");
			plnDbkM.setProPlanId(plnDbkS.getProPlanId());
			plnDbkM.setGxPlanNo(plnDbkS.getGxPlanNo());
			plnDbkM.setGradecode(plnZgPln.getGradecode());
			plnDbkM.setGradename(plnZgPln.getGradename());
			plnDbkM.setSteelcode(plnZgPln.getSteelcode());
			plnDbkM.setSteelname(plnZgPln.getSteelname());
			plnDbkM.setProduccode(plnZgPln.getProduccode());
			plnDbkM.setProducname(plnZgPln.getProducname());
			plnDbkM.setProdStandard(plnZgPln.getProdStandard());
			plnDbkM.setOutputStandard(plnZgPln.getOutputStandard());
			// 通过BOM查询投入产出
			String[] bomMat = PlanFurnProduction.getQueryBom(con,
					plnDbkS.getBom(), plnDbkS.getIndexSeq(),
					plnDbkS.getOrdLnDlyPk(), "E", plnZgPln.getGradecode());
			// if(bomMat[0]==null){
			// cro.setV_errMsg("判定炉号(" + judgeStoveNo
			// +")要利合同的投入物料不包含库存物料,不能利库,请先管坯改判物料!");
			// return cro;
			// }
			plnDbkM.setInwlId(bomMat[0]);
			plnDbkM.setInwlDesc(bomMat[1]);
			plnDbkM.setOutwlId(bomMat[2]);
			plnDbkM.setOutwlDesc(bomMat[3]);
			plnDbkM.setBom(bomMat[4]);
			plnDbkM.setModelCode(plnZgPln.getModelCode());
			plnDbkM.setModelDesc(plnZgPln.getModelDesc());
			// 单倍支吨
			plnDbkM.setPlnInsingleNum(String.valueOf(oldNum));
			plnDbkM.setPlnInsingleWt(String.valueOf(oldWt));
			plnDbkM.setPlnOutsingleNum(String.valueOf(oldNum));
			double burnoutRate = 0;
			// 查询产线烧损
			String sqlrate = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
					+ plnDbkS.getPlineCode() + "'";
			ps = con.prepareStatement(sqlrate);
			rs = ps.executeQuery();
			if (rs.next()) {
				burnoutRate = rs.getDouble("BURNOUT_RATE");
			}
			rs.close();
			ps.close();
			double cLenCut = Double.parseDouble(plnDbkS.getLenCuthead())
					+ Double.parseDouble(plnDbkS.getLenCutend());
			double yjWt = oldWt - oldWt * burnoutRate - cLenCut / 1000;
			plnDbkM.setPlnOutsingleW(String.valueOf(yjWt));
			// // 倍尺支吨
			// int plnIndoubNum = 0;
			// double plnIndoubWt = 0;
			// String sqlCl =
			// "SELECT SUM(NVL(T.PLAN_INDOUBLE_NUM,0)) PLAN_INDOUBLE_NUM,SUM(NVL(T.PLAN_INDOUBLE_WT,0)) PLAN_INDOUBLE_WT FROM PLN_ZY_ZG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			// ps = con.prepareStatement(sqlCl);
			// ps.setObject(1, plnZgPln.getProPlanId());
			// ps.setObject(2, plnZgPln.getGxPlanNo());
			// ps.setObject(3, plnZgPln.getJudgeStoveNo());
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnIndoubWt = rs.getDouble("PLAN_INDOUBLE_WT");
			// plnIndoubNum = rs.getInt("PLAN_INDOUBLE_NUM");
			// }
			// rs.close();
			// ps.close();
			// plnDbkM.setPlnIndoubleNum(String.valueOf(plnIndoubNum));
			// plnDbkM.setPlnIndoubleWt(String.valueOf(plnIndoubWt));
			// plnDbkM.setPlnOutdoubleNum(String.valueOf(plnIndoubNum));
			// plnDbkM.setPlnOutdoubleW(String.valueOf(plnIndoubWt));

			plnDbkM.setOrderSource(plnDbkS.getOrderSource());
			plnDbkM.setOrderNo(plnDbkS.getOrderNo());
			plnDbkM.setOrderSeq(plnDbkS.getOrderSeq());
			plnDbkM.setDeliveryNo(plnDbkS.getDeliveryNo());
			plnDbkM.setOrdLnDlyPk(plnDbkS.getOrdLnDlyPk());
			plnDbkM.setReqBlId(plnDbkS.getReqBlId());
			plnDbkM.setIfExport(plnDbkS.getIfExport());
			plnDbkM.setPriority(plnDbkS.getPriority());
			plnDbkM.setPriorityMemo(plnDbkS.getPriorityMemo());
			plnDbkM.setProMonth(plnDbkS.getProMonth());
			plnDbkM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnDbkM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnDbkM.setIfMonitor(plnDbkS.getIfMonitorDbk());
			plnDbkM.setPrdcrNo(plnDbkS.getPrdcrNo());
			plnDbkM.setMonitorPoint(plnDbkS.getMonitorPoint());

			plnDbkM.setWholeBacklog(plnZgPln.getWholeBacklog());
			plnDbkM.setWholeBacklogDesc(plnZgPln.getWholeBacklogDesc());
			plnDbkM.setStationRoad(plnDbkS.getStationRoad());
			plnDbkM.setCic(plnZgPln.getCic());
			if (plnDbkS.getSic() == null || plnDbkS.getSic().equals("")) {
				plnDbkM.setSic(plnDbkS.getSic());
			} else {
				plnDbkM.setSic(plnDbkS.getSic().split(",")[0]);
			}
			if (plnDbkS.getDic() == null || plnDbkS.getDic().equals("")) {
				plnDbkM.setDic(plnDbkS.getDic());
			} else {
				plnDbkM.setDic(plnDbkS.getDic().split(",")[0]);
			}
			if (plnDbkS.getPic() == null || plnDbkS.getPic().equals("")) {
				plnDbkM.setPic(plnDbkS.getPic());
			} else {
				plnDbkM.setPic(plnDbkS.getPic().split(",")[0]);
			}
			plnDbkM.setCraftFileMan(plnDbkS.getCraftFileMan());
			plnDbkM.setCraftFileNo(plnDbkS.getCraftFileNo());
			plnDbkM.setCraftSeq(plnDbkS.getCraftSeq());
			plnDbkM.setSecCraftFileNo(plnZgPln.getSecCraftFileNo());
			plnDbkM.setOutdiameterIn(plnDbkS.getOutdiameterIn());
			plnDbkM.setWallthickIn(plnDbkS.getWallthickIn());
			plnDbkM.setLengthIn(plnZgPln.getAimlength());
			plnDbkM.setLengthmaxIn(plnZgPln.getLenRollMax());
			plnDbkM.setLengthminIn(plnZgPln.getLenRollMin());
			plnDbkM.setAimlength(plnDbkS.getAimlength());
			plnDbkM.setAimoutdiameter(plnDbkS.getAimoutdiameter());
			plnDbkM.setAimwallthick(plnDbkS.getAimwallthick());
			// 查询合同最大最小长度
			double lenMax = 0;
			double lenMin = 0;
			String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
			ps = con.prepareStatement(ordLen);
			ps.setObject(1, plnDbkS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();
			plnDbkM.setAimlengthMax(String.valueOf(lenMax));
			plnDbkM.setAimlengthMin(String.valueOf(lenMin));
			plnDbkM.setLenCutend(plnDbkS.getLenCutend());
			plnDbkM.setLenCuthead(plnDbkS.getLenCuthead());
			plnDbkM.setCreateName(createName);
			plnDbkM.setCreateTime(createTime);
			plnDbkM.setIndexSeq(plnDbkS.getIndexSeq());
			plnDbkM.setSpecCode(plnZgPln.getSpecCode());
			plnDbkM.setSpecName(plnZgPln.getSpecName());
			plnDbkM.setStdCode(plnZgPln.getStdCode());
			plnDbkM.setStdName(plnZgPln.getStdName());
			plnDbkM.setStdStyle(plnZgPln.getStdStyle());
			plnDbkM.setStdStyleDesc(plnZgPln.getStdStyleDesc());
			if (fl == 0) {
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnDbkM.getProPlanId(),
						plnDbkM.getProPlanId(), "E");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnDbkM.getPlineCode(), "E");
				plnDbkM.setHeatPlanNo(heatPlanNo);
				plnDbkM.setGxProSeq(String.valueOf(gxProSeq));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyDbk"),
						plnDbkM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_DBK_M T"
						+ " SET T.PLN_INSINGLE_NUM  = TO_NUMBER(T.PLN_INSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_INSINGLE_WT   = TO_NUMBER(T.PLN_INSINGLE_WT) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_NUM = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_W   = TO_NUMBER(T.PLN_OUTSINGLE_W) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1, oldNum);
				ps.setObject(2, oldWt);
				ps.setObject(3, oldNum);
				ps.setObject(4, yjWt);
				ps.setObject(5, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
			// // 更新订单虚拟挂料量
			// String update =
			// "UPDATE PLN_ORDER_DBK_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))+TO_NUMBER(?),"
			// +
			// "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))+TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
			// ps = con.prepareStatement(update);
			// ps.setObject(1, oldNum);
			// ps.setObject(2, oldWt);
			// ps.setObject(3, plnDbkS.getProPlanId());
			// ps.setObject(4, plnDbkS.getGxPlanNo());
			// ps.executeUpdate();
			// ps.close();
		}
		return true;
	}

	/**
	 * 新增镦拔扩虚拟炉计划(外购)
	 * 
	 * @return
	 */
	public boolean addPlnZyDbkMWg(Connection con, MatBcMEntityPln matBc,
			PlnOrderDbkSEntity plnDbkS, String createName, String createTime)
			throws SQLException {
		PlnZyDbkMEntity plnDbkM = new PlnZyDbkMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		String heatPlanNo = "";
		// 轧管单倍支
		// int cutNum = Integer.parseInt(matBc.getCutNum());
		int oldNum = Integer.parseInt(matBc.getActCount());
		double oldWt = Double.parseDouble(matBc.getActWeight());
		int contZgM = 0;
		// 查询当前镦拔扩订单是否存在炉计划
		sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_DBK_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
		ps = con.prepareStatement(sql);
		ps.setObject(1, plnDbkS.getProPlanId());
		ps.setObject(2, plnDbkS.getGxPlanNo());
		ps.setObject(3, matBc.getJudgeStoveNo());
		rs = ps.executeQuery();
		if (rs.next()) {
			contZgM = 1;
			heatPlanNo = rs.getString("HEAT_PLAN_NO");
		}
		rs.close();
		ps.close();
		double burnoutRate = 0;
		// 查询产线烧损
		String sqlrate = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
				+ plnDbkS.getPlineCode() + "'";
		ps = con.prepareStatement(sqlrate);
		rs = ps.executeQuery();
		if (rs.next()) {
			burnoutRate = rs.getDouble("BURNOUT_RATE");
		}
		rs.close();
		ps.close();
		double cLenCut = Double.parseDouble(plnDbkS.getLenCuthead())
				+ Double.parseDouble(plnDbkS.getLenCutend());
		double yjWt = oldWt - oldWt * burnoutRate - cLenCut / 1000;
		if (contZgM == 0) {
			plnDbkM.setDecision(plnDbkS.getDecision());
			plnDbkM.setStoveNo(matBc.getStoveNo());
			plnDbkM.setFeedHeatNo(matBc.getJudgeStoveNo());
			plnDbkM.setJudgeStoveNo(matBc.getJudgeStoveNo());
			plnDbkM.setFlagStoveNo(matBc.getJudgeStoveNo());
			plnDbkM.setBatchNo("");
			plnDbkM.setUpperHeatplanId(matBc.getHeatPlanNo());
			plnDbkM.setPlanstatus("00");
			plnDbkM.setUpperProcessCode(matBc.getProcessCdoe());
			plnDbkM.setPlineCode(plnDbkS.getPlineCode());
			plnDbkM.setPlineName(plnDbkS.getPlineName());
			plnDbkM.setProcessCodeC(plnDbkS.getProcessCodeC());
			plnDbkM.setProcessDescC(plnDbkS.getProcessDescC());
			if (!plnDbkS.getDecision().equals("A")) {
				// 通过制程判定镦拔扩是否末工序
				if (plnDbkS.getWholeBacklogDesc().contains("热处理")) {
					plnDbkM.setNextProcessCode("F");
				} else if (plnDbkS.getWholeBacklogDesc().contains("加工")) {
					plnDbkM.setNextProcessCode("G");
				} else if (plnDbkS.getWholeBacklogDesc().contains("接箍")) {
					plnDbkM.setNextProcessCode("H");
				} else {
					if (plnDbkS.getOrdLnDlyPk().contains("ZZBY-J")) {
						plnDbkM.setNextProcessCode("H");
					} else if (plnDbkS.getOrdLnDlyPk().contains("ZZBY-D")) {
						plnDbkM.setNextProcessCode("G");
					} else {
						plnDbkM.setNextProcessCode("");
					}
				}
				plnDbkM.setIsendgx("0");
			} else {
				plnDbkM.setNextProcessCode("");
				plnDbkM.setIsendgx("1");
			}
			// String gowWhere = getPlineCodeGroup(con, plnDbkS.getPlineCode(),
			// plnDbkS.getProPlanId(), plnDbkS.getGxPlanNo(), "E");
			// if (gowWhere != null) {
			//
			// // 查询去向
			// String sqlGroup =
			// "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
			// ps = con.prepareStatement(sqlGroup);
			// ps.setObject(1, plnDbkS.getPlineCode());
			// ps.setObject(2, gowWhere);
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnDbkM.setGowhereName(rs.getString("STORAGE_NAME"));
			// plnDbkM.setGowhereCode(rs.getString("STORAGE_NO"));
			// }
			// rs.close();
			// ps.close();
			// }
			plnDbkM.setIfMatchOdd("0");
			plnDbkM.setIfDoHeatPlan("0");
			plnDbkM.setProPlanId(plnDbkS.getProPlanId());
			plnDbkM.setGxPlanNo(plnDbkS.getGxPlanNo());
			plnDbkM.setGradecode(plnDbkS.getGradecode());
			plnDbkM.setGradename(plnDbkS.getGradename());
			plnDbkM.setSteelcode(plnDbkS.getSteelcode());
			plnDbkM.setSteelname(plnDbkS.getSteelname());
			plnDbkM.setProduccode(plnDbkS.getProduccode());
			plnDbkM.setProducname(plnDbkS.getProducname());
			// 查询轧管排产信息
			String sqlZg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.QueryWgZg");
			ps = con.prepareStatement(sqlZg);
			ps.setObject(1, plnDbkS.getOrdLnDlyPk());
			// ps.setObject(2, plnDbkS.getPlnDivideId());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnDbkM.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
				plnDbkM.setProdStandard(rs.getString("PROD_STANDARD"));
				plnDbkM.setOutputStandard(rs.getString("Output_Standard"));
				plnDbkM.setSecCraftFileNo(rs.getString("SEC_CRAFT_FILE_NO"));
				plnDbkM.setWholeBacklog(rs.getString("PROCESS_SEQ"));
			}
			rs.close();
			ps.close();
			plnDbkM.setInwlId(plnDbkS.getInwlId());
			plnDbkM.setInwlDesc(plnDbkS.getInwlDesc());
			plnDbkM.setOutwlId(plnDbkS.getOutwlId());
			plnDbkM.setOutwlDesc(plnDbkS.getOutwlDesc());
			plnDbkM.setModelCode(plnDbkS.getModelCode());
			plnDbkM.setModelDesc(plnDbkS.getModelDesc());
			// 单倍支吨
			plnDbkM.setPlnInsingleNum(String.valueOf(oldNum));
			plnDbkM.setPlnInsingleWt(String.valueOf(oldWt));
			plnDbkM.setPlnOutsingleNum(String.valueOf(oldNum));
			plnDbkM.setPlnOutsingleW(String.valueOf(yjWt));

			plnDbkM.setOrderSource(plnDbkS.getOrderSource());
			plnDbkM.setOrderNo(plnDbkS.getOrderNo());
			plnDbkM.setOrderSeq(plnDbkS.getOrderSeq());
			plnDbkM.setDeliveryNo(plnDbkS.getDeliveryNo());
			plnDbkM.setOrdLnDlyPk(plnDbkS.getOrdLnDlyPk());
			plnDbkM.setReqBlId(plnDbkS.getReqBlId());
			plnDbkM.setIfExport(plnDbkS.getIfExport());
			plnDbkM.setPriority(plnDbkS.getPriority());
			plnDbkM.setPriorityMemo(plnDbkS.getPriorityMemo());
			plnDbkM.setProMonth(plnDbkS.getProMonth());
			plnDbkM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnDbkM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnDbkM.setIfMonitor(plnDbkS.getIfMonitorDbk());
			plnDbkM.setPrdcrNo(plnDbkS.getPrdcrNo());
			plnDbkM.setMonitorPoint(plnDbkS.getMonitorPoint());
			plnDbkM.setBom(plnDbkS.getBom());

			plnDbkM.setWholeBacklogDesc(plnDbkS.getWholeBacklogDesc());
			plnDbkM.setStationRoad(plnDbkS.getStationRoad());
			plnDbkM.setCic(matBc.getCic());
			if (plnDbkS.getSic() == null || plnDbkS.getSic().equals("")) {
				plnDbkM.setSic(plnDbkS.getSic());
			} else {
				plnDbkM.setSic(plnDbkS.getSic().split(",")[0]);
			}
			if (plnDbkS.getDic() == null || plnDbkS.getDic().equals("")) {
				plnDbkM.setDic(plnDbkS.getDic());
			} else {
				plnDbkM.setDic(plnDbkS.getDic().split(",")[0]);
			}
			if (plnDbkS.getPic() == null || plnDbkS.getPic().equals("")) {
				plnDbkM.setPic(plnDbkS.getPic());
			} else {
				plnDbkM.setPic(plnDbkS.getPic().split(",")[0]);
			}
			plnDbkM.setCraftFileMan(plnDbkS.getCraftFileMan());
			plnDbkM.setCraftFileNo(plnDbkS.getCraftFileNo());
			plnDbkM.setCraftSeq(plnDbkS.getCraftSeq());

			plnDbkM.setOutdiameterIn(plnDbkS.getOutdiameterIn());
			plnDbkM.setWallthickIn(plnDbkS.getWallthickIn());
			plnDbkM.setLengthIn(matBc.getActLen());
			plnDbkM.setLengthmaxIn(matBc.getActLenMax());
			plnDbkM.setLengthminIn(matBc.getActLenMin());
			plnDbkM.setAimlength(plnDbkS.getAimlength());
			plnDbkM.setAimoutdiameter(plnDbkS.getAimoutdiameter());
			plnDbkM.setAimwallthick(plnDbkS.getAimwallthick());
			// 查询合同最大最小长度
			double lenMax = 0;
			double lenMin = 0;
			String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
			ps = con.prepareStatement(ordLen);
			ps.setObject(1, plnDbkS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();
			plnDbkM.setAimlengthMax(String.valueOf(lenMax));
			plnDbkM.setAimlengthMin(String.valueOf(lenMin));
			plnDbkM.setLenCutend(plnDbkS.getLenCutend());
			plnDbkM.setLenCuthead(plnDbkS.getLenCuthead());
			plnDbkM.setCreateName(createName);
			plnDbkM.setCreateTime(createTime);
			plnDbkM.setIndexSeq(plnDbkS.getIndexSeq());
			plnDbkM.setSpecCode(plnDbkS.getSpecCode());
			plnDbkM.setSpecName(plnDbkS.getSpecName());
			plnDbkM.setStdCode(plnDbkS.getStdCode());
			plnDbkM.setStdName(plnDbkS.getStdName());
			plnDbkM.setStdStyle(plnDbkS.getStdStyle());
			plnDbkM.setStdStyleDesc(plnDbkS.getStdStyleDesc());
			// 新增
			heatPlanNo = getMaxHeatPlanNo(con, plnDbkM.getProPlanId(),
					plnDbkM.getProPlanId(), "E");
			// 获取炉计划顺序号
			int gxProSeq = getMaxGxPlnSeq(con, plnDbkM.getPlineCode(), "E");
			plnDbkM.setHeatPlanNo(heatPlanNo);
			plnDbkM.setGxProSeq(String.valueOf(gxProSeq));
			String addPlnGxZg = EntityTool.fillSqlByEntity(
					CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.addPlnZyDbk"), plnDbkM);
			ps = con.prepareStatement(addPlnGxZg);
			ps.executeUpdate();
			ps.close();
		} else {
			// 修改计划量
			String sqlUpdate = "UPDATE PLN_ZY_DBK_M T SET "
					+ " T.PLN_INSINGLE_NUM  = TO_NUMBER(T.PLN_INSINGLE_NUM) + TO_NUMBER(?), "
					+ "T.PLN_INSINGLE_WT   = TO_NUMBER(T.PLN_INSINGLE_WT) + TO_NUMBER(?), "
					+ "T.PLN_OUTSINGLE_NUM = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?),"
					+ " T.PLN_OUTSINGLE_W   = TO_NUMBER(T.PLN_OUTSINGLE_W) + TO_NUMBER(?) WHERE T.HEAT_PLAN_NO = ?";
			ps = con.prepareStatement(sqlUpdate);
			ps.setObject(1, oldNum);
			ps.setObject(2, oldWt);
			ps.setObject(3, oldNum);
			ps.setObject(4, yjWt);
			ps.setObject(5, heatPlanNo);
			ps.executeUpdate();
			ps.close();
		}

		// 修改库存本工序炉计划ID
		String upMat = "UPDATE MAT_BC_M T SET T.HEAT_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=? AND T.QCM_STAUS='00'";
		ps = con.prepareStatement(upMat);
		ps.setObject(1, heatPlanNo);
		ps.setObject(2, matBc.getJudgeStoveNo());
		ps.setObject(3, matBc.getProPlanIdNext());
		ps.setObject(4, matBc.getGxPlanNoNext());
		ps.setObject(5, "E");
		ps.executeUpdate();
		ps.close();
		return true;
	}

	/**
	 * 新增热处理虚拟炉计划(外购)
	 * 
	 * @return
	 */
	public boolean addPlnZyRclMWg(Connection con, MatBcMEntityPln matBc,
			PlnOrderRclSEntity plnRclS, String createName, String createTime)
			throws SQLException {
		PlnZyRclMEntity plnRclM = new PlnZyRclMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		String heatPlanNo = "";
		// 单倍支
		// int cutNum = Integer.parseInt(matBc.getCutNum());
		int oldNum = Integer.parseInt(matBc.getActCount());
		double oldWt = Double.parseDouble(matBc.getActWeight());
		int contZgM = 0;

		// 查询当前镦拔扩订单是否存在炉计划
		sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
		ps = con.prepareStatement(sql);
		ps.setObject(1, plnRclS.getProPlanId());
		ps.setObject(2, plnRclS.getGxPlanNo());
		ps.setObject(3, matBc.getJudgeStoveNo());
		rs = ps.executeQuery();
		if (rs.next()) {
			contZgM = 1;
			heatPlanNo = rs.getString("HEAT_PLAN_NO");
		}
		rs.close();
		ps.close();
		double burnoutRate = 0;
		// 查询产线烧损
		String sqlRate = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
				+ plnRclS.getPlineCode() + "'";
		ps = con.prepareStatement(sqlRate);
		rs = ps.executeQuery();
		if (rs.next()) {
			burnoutRate = rs.getDouble("BURNOUT_RATE");
		}
		rs.close();
		ps.close();
		double yjWt = oldWt - oldWt * burnoutRate;
		if (contZgM == 0) {
			plnRclM.setDecision(plnRclS.getDecision());
			plnRclM.setStoveNo(matBc.getStoveNo());
			plnRclM.setJudgeStoveNo(matBc.getJudgeStoveNo());
			plnRclM.setFeedHeatNo(matBc.getJudgeStoveNo());
			plnRclM.setFlagStoveNo(matBc.getJudgeStoveNo());
			plnRclM.setUpperHeatplanId(matBc.getHeatPlanNo());
			plnRclM.setPlanstatus("00");
			plnRclM.setUpperProcessCode(matBc.getProcessCdoe());
			plnRclM.setPlineCode(plnRclS.getPlineCode());
			plnRclM.setPlineName(plnRclS.getPlineName());
			plnRclM.setProcessCodeC(plnRclS.getProcessCodeC());
			plnRclM.setProcessDescC(plnRclS.getProcessDescC());
			if (!plnRclS.getDecision().equals("A")) {
				// 通过制程判定是否末工序
				if (plnRclS.getWholeBacklogDesc().contains("加工")) {
					plnRclM.setNextProcessCode("G");
				} else if (plnRclS.getWholeBacklogDesc().contains("接箍")) {
					plnRclM.setNextProcessCode("H");
				} else {
					if (plnRclS.getOrdLnDlyPk().contains("ZZBY-J")) {
						plnRclM.setNextProcessCode("H");
					} else if (plnRclS.getOrdLnDlyPk().contains("ZZBY-D")) {
						plnRclM.setNextProcessCode("G");
					} else {
						plnRclM.setNextProcessCode("");
					}
				}
				plnRclM.setIsendgx("0");
			} else {
				plnRclM.setNextProcessCode("");
				plnRclM.setIsendgx("1");
			}
			// String gowWhere = getPlineCodeGroup(con, plnRclS.getPlineCode(),
			// plnRclS.getProPlanId(), plnRclS.getGxPlanNo(), "F");
			// if (gowWhere != null) {
			// // 查询去向
			// String sqlGroup =
			// "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
			// ps = con.prepareStatement(sqlGroup);
			// ps.setObject(1, plnRclS.getPlineCode());
			// ps.setObject(2, gowWhere);
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnRclM.setGowhereName(rs.getString("STORAGE_NAME"));
			// plnRclM.setGowhereCode(rs.getString("STORAGE_NO"));
			// }
			// rs.close();
			// ps.close();
			// }
			plnRclM.setIfMatchOdd("0");
			plnRclM.setIfDoHeatPlan("0");
			plnRclM.setProPlanId(plnRclS.getProPlanId());
			plnRclM.setGxPlanNo(plnRclS.getGxPlanNo());
			plnRclM.setGradecode(plnRclS.getGradecode());
			plnRclM.setGradename(plnRclS.getGradename());
			plnRclM.setSteelcode(plnRclS.getSteelcode());
			plnRclM.setSteelname(plnRclS.getSteelname());
			plnRclM.setProduccode(plnRclS.getProduccode());
			plnRclM.setProducname(plnRclS.getProducname());
			// 查询轧管排产信息
			String sqlZg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.QueryWgZg");
			ps = con.prepareStatement(sqlZg);
			ps.setObject(1, plnRclS.getOrdLnDlyPk());
			// ps.setObject(2, plnRclS.getPlnDivideId());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnRclM.setProdStandard(rs.getString("PROD_STANDARD"));
				plnRclM.setOutputStandard(rs.getString("Output_Standard"));
				plnRclM.setSecCraftFileNo(rs.getString("SEC_CRAFT_FILE_NO"));
				plnRclM.setWholeBacklog(rs.getString("PROCESS_SEQ"));
			}
			rs.close();
			ps.close();
			plnRclM.setInwlId(plnRclS.getInwlId());
			plnRclM.setInwlDesc(plnRclS.getInwlDesc());
			plnRclM.setOutwlId(plnRclS.getOutwlId());
			plnRclM.setOutwlDesc(plnRclS.getOutwlDesc());
			plnRclM.setModelCode(plnRclS.getModelCode());
			plnRclM.setModelDesc(plnRclS.getModelDesc());
			// 单倍支吨
			plnRclM.setPlnInsingleNum(String.valueOf(oldNum));
			plnRclM.setPlnInsingleWt(String.valueOf(oldWt));
			plnRclM.setPlnOutsingleNum(String.valueOf(oldNum));
			plnRclM.setPlnOutsingleW(String.valueOf(yjWt));

			plnRclM.setOrderSource(plnRclS.getOrderSource());
			plnRclM.setOrderNo(plnRclS.getOrderNo());
			plnRclM.setOrderSeq(plnRclS.getOrderSeq());
			plnRclM.setDeliveryNo(plnRclS.getDeliveryNo());
			plnRclM.setOrdLnDlyPk(plnRclS.getOrdLnDlyPk());
			plnRclM.setReqBlId(plnRclS.getReqBlId());
			plnRclM.setIfExport(plnRclS.getIfExport());
			plnRclM.setPriority(plnRclS.getPriority());
			plnRclM.setPriorityMemo(plnRclS.getPriorityMemo());
			plnRclM.setProMonth(plnRclS.getProMonth());
			plnRclM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnRclM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnRclM.setIfMonitor(plnRclS.getIfMonitorRcl());
			plnRclM.setPrdcrNo(plnRclS.getPrdcrNo());
			plnRclM.setMonitorPoint(plnRclS.getMonitorPoint());
			plnRclM.setBom(plnRclS.getBom());

			plnRclM.setWholeBacklogDesc(plnRclS.getWholeBacklogDesc());
			plnRclM.setStationRoad(plnRclS.getStationRoad());
			plnRclM.setCic(matBc.getCic());
			if (plnRclS.getSic() == null || plnRclS.getSic().equals("")) {
				plnRclM.setSic(plnRclS.getSic());
			} else {
				plnRclM.setSic(plnRclS.getSic().split(",")[0]);
			}
			if (plnRclS.getDic() == null || plnRclS.getDic().equals("")) {
				plnRclM.setDic(plnRclS.getDic());
			} else {
				plnRclM.setDic(plnRclS.getDic().split(",")[0]);
			}
			if (plnRclS.getPic() == null || plnRclS.getPic().equals("")) {
				plnRclM.setPic(plnRclS.getPic());
			} else {
				plnRclM.setPic(plnRclS.getPic().split(",")[0]);
			}
			plnRclM.setCraftFileMan(plnRclS.getCraftFileMan());
			plnRclM.setCraftFileNo(plnRclS.getCraftFileNo());
			plnRclM.setCraftSeq(plnRclS.getCraftSeq());

			plnRclM.setOutdiameterIn(matBc.getActDimater());
			plnRclM.setWallthickIn(matBc.getActHeight());
			plnRclM.setLengthIn(matBc.getActLen());
			plnRclM.setLengthmaxIn(matBc.getActLenMax());
			plnRclM.setLengthminIn(matBc.getActLenMin());
			plnRclM.setOutdiameter(plnRclS.getOutdiameter());
			plnRclM.setWallthick(plnRclS.getWallthick());
			// 查询合同最大最小长度
			double lenMax = 0;
			double lenMin = 0;
			String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
			ps = con.prepareStatement(ordLen);
			ps.setObject(1, plnRclS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();
			plnRclM.setLengthmax(String.valueOf(lenMax));
			plnRclM.setLengthmin(String.valueOf(lenMin));
			plnRclM.setCreateName(createName);
			plnRclM.setCreateTime(createTime);
			plnRclM.setIndexSeq(plnRclS.getIndexSeq());
			plnRclM.setSpecCode(plnRclS.getSpecCode());
			plnRclM.setSpecName(plnRclS.getSpecName());
			plnRclM.setStdCode(plnRclS.getStdCode());
			plnRclM.setStdName(plnRclS.getStdName());
			plnRclM.setStdStyle(plnRclS.getStdStyle());
			plnRclM.setStdStyleDesc(plnRclS.getStdStyleDesc());
			// 获取热处理循环次数
			String sqlSeq = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialRcl.QueryProcessSeq");
			ps = con.prepareStatement(sqlSeq);
			ps.setObject(1, plnRclS.getProPlanId());
			ps.setObject(2, plnRclS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnRclM.setProcessSeq(rs.getString("PROCESS_SEQ"));
			} else {
				plnRclM.setProcessSeq("1");
			}
			rs.close();
			ps.close();
			String ifProduct = "0";
			int counnum = StoveHelper.getQueryStation(con,
					plnRclS.getProPlanId(), plnRclS.getGxPlanNo(), "F");
			if (counnum > 0) {
				ifProduct = "1";
			}
			plnRclM.setIfProduct(ifProduct);
			// 新增
			heatPlanNo = getMaxHeatPlanNo(con, plnRclM.getProPlanId(),
					plnRclM.getProPlanId(), "F");
			// 获取炉计划顺序号
			int gxProSeq = getMaxGxPlnSeq(con, plnRclM.getPlineCode(), "F");
			// 订单内炉顺序号
			int lotNo = getMaxLotNoSqe(con, plnRclM.getProPlanId(),
					plnRclM.getGxPlanNo(), "F");
			plnRclM.setLotNoSqe(String.valueOf(lotNo));
			plnRclM.setHeatPlanNo(heatPlanNo);
			plnRclM.setGxProSeq(String.valueOf(gxProSeq));
			plnRclM.setRealProcessSeq("1");

			String addPlnGxZg = EntityTool.fillSqlByEntity(
					CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.addPlnZyRcl"), plnRclM);
			ps = con.prepareStatement(addPlnGxZg);
			ps.executeUpdate();
			ps.close();

			// 新增生产批号
			StoveHelper.updatePlnRclGroup(con, plnRclM.getProPlanId(),
					plnRclM.getGxPlanNo(), plnRclM.getPic());
		} else {
			// 修改计划量
			String sqlUpdate = "UPDATE PLN_ZY_RCL_M T SET "
					+ " T.PLN_INSINGLE_NUM  = TO_NUMBER(T.PLN_INSINGLE_NUM) + TO_NUMBER(?), "
					+ "T.PLN_INSINGLE_WT   = TO_NUMBER(T.PLN_INSINGLE_WT) + TO_NUMBER(?), "
					+ "T.PLN_OUTSINGLE_NUM = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?),"
					+ " T.PLN_OUTSINGLE_W   = TO_NUMBER(T.PLN_OUTSINGLE_W) + TO_NUMBER(?) WHERE T.HEAT_PLAN_NO = ?";
			ps = con.prepareStatement(sqlUpdate);
			ps.setObject(1, oldNum);
			ps.setObject(2, oldWt);
			ps.setObject(3, oldNum);
			ps.setObject(4, yjWt);
			ps.setObject(5, heatPlanNo);
			ps.executeUpdate();
			ps.close();
		}
		// 修改库存本工序炉计划ID
		String upMat = "UPDATE MAT_BC_M T SET T.HEAT_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=? AND T.QCM_STAUS='00'";
		ps = con.prepareStatement(upMat);
		ps.setObject(1, heatPlanNo);
		ps.setObject(2, matBc.getJudgeStoveNo());
		ps.setObject(3, matBc.getProPlanIdNext());
		ps.setObject(4, matBc.getGxPlanNoNext());
		ps.setObject(5, "F");
		ps.executeUpdate();
		ps.close();
		return true;
	}

	/**
	 * 新增热处理虚拟炉计划(自炼轧管炉计划下发)
	 * 
	 * @return
	 */
	public boolean addPlnZyRclM(Connection con, PlnZyZgMEntity plnZgPln,
			List<PlnOrderRclSEntity> plnRcl, String createName,
			String createTime) throws SQLException {
		PlnZyRclMEntity plnRclM = new PlnZyRclMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 单倍支
		int cutNum = Integer.parseInt(plnZgPln.getOutnumCut());
		int zgNum = Integer.parseInt(plnZgPln.getPlnOutsingleNum());
		double totWeightM = Double.parseDouble(plnZgPln.getPlnOutsingleW());
		int contZgM = 0;
		int countZg = plnRcl.size();
		for (PlnOrderRclSEntity plnRclS : plnRcl) {
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnRclS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnRclS.getProPlanId() + "/"
							+ plnRclS.getGxPlanNo());
				} else {
					String message = plnRclS.getProPlanId() + "/"
							+ plnRclS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				continue;
			}
			double wtIn = 0;// 已生成炉计划原料吨(已装炉)
			// int numIn = 0;
			// 查询当前订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLN_INSINGLE_NUM),0) PLN_INSINGLE_NUM,NVL(SUM(T.PLN_INSINGLE_WT),0) PLN_INSINGLE_WT "
					+ "FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?    AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnRclS.getProPlanId());
			ps.setObject(2, plnRclS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLN_INSINGLE_WT");
				// numIn = rs.getInt("PLN_INSINGLE_NUM");
			}
			rs.close();
			ps.close();
			sql = "SELECT NVL(SUM(T.PLAN_INDOUBLE_WT),0) PLAN_INDOUBLE_WT FROM PLN_ZY_RCL_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnRclS.getProPlanId());
			ps.setObject(2, plnRclS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("PLAN_INDOUBLE_WT");
			}
			rs.close();
			ps.close();
			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1,
					plnRclS.getProPlanId() + "/" + plnRclS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getFeedHeatNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnRclS.getWeigthS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnRclS.getWeigthS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}

			if (oldNum <= 0) {
				continue;
			}
			plnRclM.setZyBatchIdZg(plnZgPln.getZyBatchId());
			plnRclM.setDecision(plnRclS.getDecision());
			plnRclM.setStoveNo(plnZgPln.getStoveNo());
			if(plnZgPln.getPlineCode().equals("C072") && !plnRclS.getPlineCode().equals("C091"))//天淮508机组轧制，但热处理不在天淮
			{
				plnRclM.setJudgeStoveNo("");
				plnRclM.setFlagStoveNo("");
			}else
			{
				plnRclM.setJudgeStoveNo(plnZgPln.getFeedHeatNo());
				plnRclM.setFlagStoveNo(plnZgPln.getFeedHeatNo());
			}

			plnRclM.setFeedHeatNo(plnZgPln.getFeedHeatNo());
			plnRclM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnRclM.setPlanstatus("00");
			plnRclM.setUpperProcessCode("D");
			plnRclM.setPlineCode(plnRclS.getPlineCode());
			plnRclM.setPlineName(plnRclS.getPlineName());
			plnRclM.setProcessCodeC(plnRclS.getProcessCodeC());
			plnRclM.setProcessDescC(plnRclS.getProcessDescC());
			if (!plnRclS.getDecision().equals("A")) {
				// 通过制程判定是否末工序
				if (plnRclS.getWholeBacklogDesc().contains("加工")) {
					plnRclM.setNextProcessCode("G");
				} else if (plnRclS.getWholeBacklogDesc().contains("接箍")) {
					plnRclM.setNextProcessCode("H");

				} else {
					if (plnRclS.getOrdLnDlyPk().contains("ZZBY-J")) {
						plnRclM.setNextProcessCode("H");
					} else if (plnRclS.getOrdLnDlyPk().contains("ZZBY-D")) {
						plnRclM.setNextProcessCode("G");
					} else {
						plnRclM.setNextProcessCode("");
					}
				}
				plnRclM.setIsendgx("0");
			} else {
				plnRclM.setNextProcessCode("");
				plnRclM.setIsendgx("1");
			}
			// String gowWhere = getPlineCodeGroup(con, plnRclS.getPlineCode(),
			// plnRclS.getProPlanId(), plnRclS.getGxPlanNo(), "F");
			// if (gowWhere != null) {
			//
			// // 查询去向
			// String sqlGroup =
			// "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
			// ps = con.prepareStatement(sqlGroup);
			// ps.setObject(1, plnRclS.getPlineCode());
			// ps.setObject(2, gowWhere);
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnRclM.setGowhereName(rs.getString("STORAGE_NAME"));
			// plnRclM.setGowhereCode(rs.getString("STORAGE_NO"));
			// }
			// rs.close();
			// ps.close();
			// }
			plnRclM.setIfMatchOdd("0");
			plnRclM.setIfDoHeatPlan("0");
			plnRclM.setProPlanId(plnRclS.getProPlanId());
			plnRclM.setGxPlanNo(plnRclS.getGxPlanNo());
			plnRclM.setGradecode(plnZgPln.getGradecode());
			plnRclM.setGradename(plnZgPln.getGradename());
			plnRclM.setSteelcode(plnZgPln.getSteelcode());
			plnRclM.setSteelname(plnZgPln.getSteelname());
			plnRclM.setProduccode(plnZgPln.getProduccode());
			plnRclM.setProducname(plnZgPln.getProducname());
			plnRclM.setProdStandard(plnZgPln.getProdStandard());
			plnRclM.setOutputStandard(plnZgPln.getOutputStandard());
			// 通过BOM查询投入产出
			String[] bomMat = PlanFurnProduction.getQueryBom(con,
					plnRclS.getBom(), plnRclS.getIndexSeq(),
					plnRclS.getOrdLnDlyPk(), "F", plnZgPln.getGradecode());
//			plnRclM.setInwlId(bomMat[0]);
//			plnRclM.setInwlDesc(bomMat[1]);
//			plnRclM.setOutwlId(bomMat[2]);
//			plnRclM.setOutwlDesc(bomMat[3]);
			plnRclM.setInwlId(plnRclS.getInwlId());
			plnRclM.setInwlDesc(plnRclS.getInwlDesc());
			plnRclM.setOutwlId(plnRclS.getOutwlId());
			plnRclM.setOutwlDesc(plnRclS.getOutwlDesc());
			plnRclM.setBom(bomMat[4]);
			plnRclM.setModelCode(plnZgPln.getModelCode());
			plnRclM.setModelDesc(plnZgPln.getModelDesc());
			// 单倍支吨
			plnRclM.setPlnInsingleNum(String.valueOf(oldNum));
			plnRclM.setPlnInsingleWt(String.valueOf(oldWt));
			plnRclM.setPlnOutsingleNum(String.valueOf(oldNum));
			double burnoutRate = 0;
			// 查询产线烧损
			String sqlRate = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
					+ plnRclS.getPlineCode() + "'";
			ps = con.prepareStatement(sqlRate);
			rs = ps.executeQuery();
			if (rs.next()) {
				burnoutRate = rs.getDouble("BURNOUT_RATE");
			}
			rs.close();
			ps.close();
			double yjWt = oldWt - oldWt * burnoutRate;
			plnRclM.setPlnOutsingleW(String.valueOf(yjWt));
			// // 倍尺支吨
			// int plnIndoubNum = 0;
			// double plnIndoubWt = 0;
			// String sqlCl =
			// "SELECT SUM(NVL(T.PLAN_INDOUBLE_NUM,0)) PLAN_INDOUBLE_NUM,SUM(NVL(T.PLAN_INDOUBLE_WT,0)) PLAN_INDOUBLE_WT FROM PLN_ZY_ZG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			// ps = con.prepareStatement(sqlCl);
			// ps.setObject(1, plnZgPln.getProPlanId());
			// ps.setObject(2, plnZgPln.getGxPlanNo());
			// ps.setObject(3, plnZgPln.getJudgeStoveNo());
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnIndoubWt = rs.getDouble("PLAN_INDOUBLE_WT");
			// plnIndoubNum = rs.getInt("PLAN_INDOUBLE_NUM");
			// }
			// rs.close();
			// ps.close();
			// plnRclM.setPlnIndoubleNum(String.valueOf(plnIndoubNum));
			// plnRclM.setPlnIndoubleWt(String.valueOf(plnIndoubWt));
			// plnRclM.setPlnOutdoubleNum(String.valueOf(plnIndoubNum));
			// plnRclM.setPlnOutdoubleW(String.valueOf(plnIndoubWt));

			plnRclM.setOrderSource(plnRclS.getOrderSource());
			plnRclM.setOrderNo(plnRclS.getOrderNo());
			plnRclM.setOrderSeq(plnRclS.getOrderSeq());
			plnRclM.setDeliveryNo(plnRclS.getDeliveryNo());
			plnRclM.setOrdLnDlyPk(plnRclS.getOrdLnDlyPk());
			plnRclM.setReqBlId(plnRclS.getReqBlId());
			plnRclM.setIfExport(plnRclS.getIfExport());
			plnRclM.setPriority(plnRclS.getPriority());
			plnRclM.setPriorityMemo(plnRclS.getPriorityMemo());
			plnRclM.setProMonth(plnRclS.getProMonth());
			plnRclM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnRclM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnRclM.setIfMonitor(plnRclS.getIfMonitorRcl());
			plnRclM.setPrdcrNo(plnRclS.getPrdcrNo());
			plnRclM.setMonitorPoint(plnRclS.getMonitorPoint());
			plnRclM.setWholeBacklog(plnZgPln.getWholeBacklog());
			plnRclM.setWholeBacklogDesc(plnZgPln.getWholeBacklogDesc());
			plnRclM.setStationRoad(plnRclS.getStationRoad());
//			plnRclM.setCic(plnZgPln.getCic());
			if(plnZgPln.getCic() == null || plnZgPln.getCic().equals("")){
				if (plnRclS.getCic() == null || plnRclS.getCic().equals("")) {
					plnRclM.setCic(plnRclS.getCic());
				} else {
					plnRclM.setCic(plnRclS.getCic().split(",")[0]);
				}
			}else{
				plnRclM.setCic(plnZgPln.getCic());
			}
			if (plnRclS.getSic() == null || plnRclS.getSic().equals("")) {
				plnRclM.setSic(plnRclS.getSic());
			} else {
				plnRclM.setSic(plnRclS.getSic().split(",")[0]);
			}
			if (plnRclS.getDic() == null || plnRclS.getDic().equals("")) {
				plnRclM.setDic(plnRclS.getDic());
			} else {
				plnRclM.setDic(plnRclS.getDic().split(",")[0]);
			}
			if (plnRclS.getPic() == null || plnRclS.getPic().equals("")) {
				plnRclM.setPic(plnRclS.getPic());
			} else {
				plnRclM.setPic(plnRclS.getPic().split(",")[0]);
			}
			plnRclM.setCraftFileMan(plnRclS.getCraftFileMan());
			plnRclM.setCraftFileNo(plnRclS.getCraftFileNo());
			plnRclM.setCraftSeq(plnRclS.getCraftSeq());
			plnRclM.setSecCraftFileNo(plnZgPln.getSecCraftFileNo());
			plnRclM.setOutdiameterIn(plnZgPln.getOutdiameterZg());
			plnRclM.setWallthickIn(plnZgPln.getWallthickZg());
			plnRclM.setLengthIn(plnZgPln.getAimlength());
			plnRclM.setLengthmaxIn(plnZgPln.getLenRollMax());
			plnRclM.setLengthminIn(plnZgPln.getLenRollMin());
			plnRclM.setOutdiameter(plnRclS.getOutdiameter());
			plnRclM.setWallthick(plnRclS.getWallthick());
			// 查询合同最大最小长度
			double lenMax = 0;
			double lenMin = 0;
			String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
			ps = con.prepareStatement(ordLen);
			ps.setObject(1, plnRclS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();
			plnRclM.setLengthmax(String.valueOf(lenMax));
			plnRclM.setLengthmin(String.valueOf(lenMin));
			plnRclM.setCreateName(createName);
			plnRclM.setCreateTime(createTime);
			plnRclM.setIndexSeq(plnRclS.getIndexSeq());
			plnRclM.setSpecCode(plnZgPln.getSpecCode());
			plnRclM.setSpecName(plnZgPln.getSpecName());
			plnRclM.setStdCode(plnZgPln.getStdCode());
			plnRclM.setStdName(plnZgPln.getStdName());
			plnRclM.setStdStyle(plnZgPln.getStdStyle());
			plnRclM.setStdStyleDesc(plnZgPln.getStdStyleDesc());
			// 获取热处理循环次数
			String sqlSeq = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialRcl.QueryProcessSeq");
			ps = con.prepareStatement(sqlSeq);
			ps.setObject(1, plnRclS.getProPlanId());
			ps.setObject(2, plnRclS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnRclM.setProcessSeq(rs.getString("PROCESS_SEQ"));
			} else {
				plnRclM.setProcessSeq("1");
			}
			rs.close();
			ps.close();
			plnRclM.setRealProcessSeq("1");

			if (fl == 0) {
				String ifProduct = "0";
				int counnum = StoveHelper.getQueryStation(con,
						plnRclS.getProPlanId(), plnRclS.getGxPlanNo(), "F");
				if (counnum > 0) {
					ifProduct = "1";
				}
				plnRclM.setIfProduct(ifProduct);
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnRclM.getProPlanId(),
						plnRclM.getProPlanId(), "F");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnRclM.getPlineCode(), "F");
				// 订单内炉顺序号
				int lotNo = getMaxLotNoSqe(con, plnRclM.getProPlanId(),
						plnRclM.getGxPlanNo(), "F");
				plnRclM.setLotNoSqe(String.valueOf(lotNo));
				plnRclM.setHeatPlanNo(heatPlanNo);
				plnRclM.setGxProSeq(String.valueOf(gxProSeq));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyRcl"),
						plnRclM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();
				// 新增生产批号
				StoveHelper.updatePlnRclGroup(con, plnRclM.getProPlanId(),
						plnRclM.getGxPlanNo(), plnRclM.getPic());
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_RCL_M T"
						+ " SET T.PLN_INSINGLE_NUM  = TO_NUMBER(T.PLN_INSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_INSINGLE_WT   = TO_NUMBER(T.PLN_INSINGLE_WT) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_NUM = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_W   = TO_NUMBER(T.PLN_OUTSINGLE_W) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1, oldNum);
				ps.setObject(2, oldWt);
				ps.setObject(3, oldNum);
				ps.setObject(4, yjWt);
				ps.setObject(5, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
			// 更新订单虚拟挂料量
			// String update =
			// "UPDATE PLN_ORDER_RCL_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))+TO_NUMBER(?),"
			// +
			// "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))+TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
			// ps = con.prepareStatement(update);
			// ps.setObject(1, oldNum);
			// ps.setObject(2, oldWt);
			// ps.setObject(3, plnRclS.getProPlanId());
			// ps.setObject(4, plnRclS.getGxPlanNo());
			// ps.executeUpdate();
			// ps.close();
		}
		return true;
	}

	/**
	 * 新增热处理虚拟炉计划(自炼镦拔扩炉计划下发)
	 * 
	 * @return
	 */
	public boolean addPlnZyRclMD(Connection con, PlnZyDbkMEntity plnZgPln,
			List<PlnOrderRclSEntity> plnRcl, String createName,
			String createTime) throws SQLException {
		PlnZyRclMEntity plnRclM = new PlnZyRclMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 单倍支
		int zgNum = Integer.parseInt(plnZgPln.getPlnInsingleNum());
		double totWeightM = Double.parseDouble(plnZgPln.getPlnInsingleWt());
		int contZgM = 0;
		int countZg = plnRcl.size();
		for (PlnOrderRclSEntity plnRclS : plnRcl) {
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnRclS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnRclS.getProPlanId() + "/"
							+ plnRclS.getGxPlanNo());
				} else {
					String message = plnRclS.getProPlanId() + "/"
							+ plnRclS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				continue;
			}
			double wtIn = 0;// 已生成炉计划原料吨(已装炉)
			// int numIn = 0;
			// 查询当前镦拔扩订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLN_INSINGLE_NUM),0) PLN_INSINGLE_NUM,NVL(SUM(T.PLN_INSINGLE_WT),0) PLN_INSINGLE_WT FROM PLN_ZY_RCL_M T "
					+ "WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?    AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnRclS.getProPlanId());
			ps.setObject(2, plnRclS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLN_INSINGLE_WT");
				// numIn = rs.getInt("PLN_INSINGLE_NUM");
			}
			rs.close();
			ps.close();
			sql = "SELECT NVL(SUM(T.PLAN_INDOUBLE_WT),0) PLAN_INDOUBLE_WT FROM PLN_ZY_RCL_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnRclS.getProPlanId());
			ps.setObject(2, plnRclS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("PLAN_INDOUBLE_WT");
			}
			rs.close();
			ps.close();

			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1,
					plnRclS.getProPlanId() + "/" + plnRclS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getJudgeStoveNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnRclS.getWeigthS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnRclS.getWeigthS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnRclM.setZyBatchIdZg(plnZgPln.getZyBatchIdZg());
			plnRclM.setDecision(plnRclS.getDecision());
			plnRclM.setStoveNo(plnZgPln.getStoveNo());
			plnRclM.setJudgeStoveNo(plnZgPln.getJudgeStoveNo());
			plnRclM.setFeedHeatNo(plnZgPln.getJudgeStoveNo());
			plnRclM.setFlagStoveNo(plnZgPln.getJudgeStoveNo());
			plnRclM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnRclM.setPlanstatus("00");
			plnRclM.setUpperProcessCode("E");
			plnRclM.setPlineCode(plnRclS.getPlineCode());
			plnRclM.setPlineName(plnRclS.getPlineName());
			plnRclM.setProcessCodeC(plnRclS.getProcessCodeC());
			plnRclM.setProcessDescC(plnRclS.getProcessDescC());
			if (!plnRclS.getDecision().equals("A")) {
				// 通过制程判定是否末工序
				if (plnRclS.getWholeBacklogDesc().contains("加工")) {
					plnRclM.setNextProcessCode("G");
				} else if (plnRclS.getWholeBacklogDesc().contains("接箍")) {
					plnRclM.setNextProcessCode("H");
				} else {
					if (plnRclS.getOrdLnDlyPk().contains("ZZBY-J")) {
						plnRclM.setNextProcessCode("H");
					} else if (plnRclS.getOrdLnDlyPk().contains("ZZBY-D")) {
						plnRclM.setNextProcessCode("G");
					} else {
						plnRclM.setNextProcessCode("");
					}
				}
				plnRclM.setIsendgx("0");
			} else {
				plnRclM.setNextProcessCode("");
				plnRclM.setIsendgx("1");
			}
			// String gowWhere = getPlineCodeGroup(con, plnRclS.getPlineCode(),
			// plnRclS.getProPlanId(), plnRclS.getGxPlanNo(), "F");
			// if (gowWhere != null) {
			// // 查询去向
			// String sqlGroup =
			// "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
			// ps = con.prepareStatement(sqlGroup);
			// ps.setObject(1, plnRclS.getPlineCode());
			// ps.setObject(2, gowWhere);
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnRclM.setGowhereName(rs.getString("STORAGE_NAME"));
			// plnRclM.setGowhereCode(rs.getString("STORAGE_NO"));
			// }
			// rs.close();
			// ps.close();
			// }
			plnRclM.setIfMatchOdd("0");
			plnRclM.setIfDoHeatPlan("0");
			plnRclM.setProPlanId(plnRclS.getProPlanId());
			plnRclM.setGxPlanNo(plnRclS.getGxPlanNo());
			plnRclM.setGradecode(plnZgPln.getGradecode());
			plnRclM.setGradename(plnZgPln.getGradename());
			plnRclM.setSteelcode(plnZgPln.getSteelcode());
			plnRclM.setSteelname(plnZgPln.getSteelname());
			plnRclM.setProduccode(plnZgPln.getProduccode());
			plnRclM.setProducname(plnZgPln.getProducname());
			plnRclM.setProdStandard(plnZgPln.getProdStandard());
			plnRclM.setOutputStandard(plnZgPln.getOutputStandard());
			// 通过BOM查询投入产出
			String[] bomMat = PlanFurnProduction.getQueryBom(con,
					plnRclS.getBom(), plnRclS.getIndexSeq(),
					plnRclS.getOrdLnDlyPk(), "F", plnZgPln.getGradecode());
			plnRclM.setInwlId(bomMat[0]);
			plnRclM.setInwlDesc(bomMat[1]);
			plnRclM.setOutwlId(bomMat[2]);
			plnRclM.setOutwlDesc(bomMat[3]);
			plnRclM.setBom(bomMat[4]);
			plnRclM.setModelCode(plnZgPln.getModelCode());
			plnRclM.setModelDesc(plnZgPln.getModelDesc());
			// 单倍支吨
			plnRclM.setPlnInsingleNum(String.valueOf(oldNum));
			plnRclM.setPlnInsingleWt(String.valueOf(oldWt));
			plnRclM.setPlnOutsingleNum(String.valueOf(oldNum));
			double burnoutRate = 0;
			// 查询产线烧损
			String sqlRate = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
					+ plnRclS.getPlineCode() + "'";
			ps = con.prepareStatement(sqlRate);
			rs = ps.executeQuery();
			if (rs.next()) {
				burnoutRate = rs.getDouble("BURNOUT_RATE");
			}
			rs.close();
			ps.close();
			double yjWt = oldWt - oldWt * burnoutRate;
			plnRclM.setPlnOutsingleW(String.valueOf(yjWt));
			// // 倍尺支吨
			// int plnIndoubNum = 0;
			// double plnIndoubWt = 0;
			// String sqlCl =
			// "SELECT SUM(NVL(T.PLAN_INDOUBLE_NUM,0)) PLAN_INDOUBLE_NUM,SUM(NVL(T.PLAN_INDOUBLE_WT,0)) PLAN_INDOUBLE_WT FROM PLN_ZY_ZG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			// ps = con.prepareStatement(sqlCl);
			// ps.setObject(1, plnZgPln.getProPlanId());
			// ps.setObject(2, plnZgPln.getGxPlanNo());
			// ps.setObject(3, plnZgPln.getJudgeStoveNo());
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnIndoubWt = rs.getDouble("PLAN_INDOUBLE_WT");
			// plnIndoubNum = rs.getInt("PLAN_INDOUBLE_NUM");
			// }
			// rs.close();
			// ps.close();
			// plnRclM.setPlnIndoubleNum(String.valueOf(plnIndoubNum));
			// plnRclM.setPlnIndoubleWt(String.valueOf(plnIndoubWt));
			// plnRclM.setPlnOutdoubleNum(String.valueOf(plnIndoubNum));
			// plnRclM.setPlnOutdoubleW(String.valueOf(plnIndoubWt));

			plnRclM.setOrderSource(plnRclS.getOrderSource());
			plnRclM.setOrderNo(plnRclS.getOrderNo());
			plnRclM.setOrderSeq(plnRclS.getOrderSeq());
			plnRclM.setDeliveryNo(plnRclS.getDeliveryNo());
			plnRclM.setOrdLnDlyPk(plnRclS.getOrdLnDlyPk());
			plnRclM.setReqBlId(plnRclS.getReqBlId());
			plnRclM.setIfExport(plnRclS.getIfExport());
			plnRclM.setPriority(plnRclS.getPriority());
			plnRclM.setPriorityMemo(plnRclS.getPriorityMemo());
			plnRclM.setProMonth(plnRclS.getProMonth());
			plnRclM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnRclM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnRclM.setIfMonitor(plnRclS.getIfMonitorRcl());
			plnRclM.setPrdcrNo(plnRclS.getPrdcrNo());
			plnRclM.setMonitorPoint(plnRclS.getMonitorPoint());
			plnRclM.setWholeBacklog(plnZgPln.getWholeBacklog());
			plnRclM.setWholeBacklogDesc(plnZgPln.getWholeBacklogDesc());
			plnRclM.setStationRoad(plnRclS.getStationRoad());
			//plnRclM.setCic(plnZgPln.getCic()); //外购管找不到轧管CIC
			if(plnZgPln.getCic() == null || plnZgPln.getCic().equals("")){
				if (plnRclS.getCic() == null || plnRclS.getCic().equals("")) {
					plnRclM.setCic(plnRclS.getCic());
				} else {
					plnRclM.setCic(plnRclS.getCic().split(",")[0]);
				}
			}else{
				plnRclM.setCic(plnZgPln.getCic());
			}
			
			if (plnRclS.getSic() == null || plnRclS.getSic().equals("")) {
				plnRclM.setSic(plnRclS.getSic());
			} else {
				plnRclM.setSic(plnRclS.getSic().split(",")[0]);
			}
			if (plnRclS.getDic() == null || plnRclS.getDic().equals("")) {
				plnRclM.setDic(plnRclS.getDic());
			} else {
				plnRclM.setDic(plnRclS.getDic().split(",")[0]);
			}
			if (plnRclS.getPic() == null || plnRclS.getPic().equals("")) {
				plnRclM.setPic(plnRclS.getPic());
			} else {
				plnRclM.setPic(plnRclS.getPic().split(",")[0]);
			}
			plnRclM.setCraftFileMan(plnRclS.getCraftFileMan());
			plnRclM.setCraftFileNo(plnRclS.getCraftFileNo());
			plnRclM.setCraftSeq(plnRclS.getCraftSeq());
			plnRclM.setSecCraftFileNo(plnZgPln.getSecCraftFileNo());
			plnRclM.setOutdiameterIn(plnZgPln.getOutdiameterIn());
			plnRclM.setWallthickIn(plnZgPln.getWallthickIn());
			plnRclM.setLengthIn(plnZgPln.getAimlength());
			plnRclM.setLengthmaxIn(plnZgPln.getLengthmaxIn());
			plnRclM.setLengthminIn(plnZgPln.getLengthminIn());
			plnRclM.setOutdiameter(plnRclS.getOutdiameter());
			plnRclM.setWallthick(plnRclS.getWallthick());
			// 查询合同最大最小长度
			double lenMax = 0;
			double lenMin = 0;
			String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
			ps = con.prepareStatement(ordLen);
			ps.setObject(1, plnRclS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();
			plnRclM.setLengthmax(String.valueOf(lenMax));
			plnRclM.setLengthmin(String.valueOf(lenMin));
			plnRclM.setCreateName(createName);
			plnRclM.setCreateTime(createTime);
			plnRclM.setIndexSeq(plnRclS.getIndexSeq());
			plnRclM.setSpecCode(plnZgPln.getSpecCode());
			plnRclM.setSpecName(plnZgPln.getSpecName());
			plnRclM.setStdCode(plnZgPln.getStdCode());
			plnRclM.setStdName(plnZgPln.getStdName());
			plnRclM.setStdStyle(plnZgPln.getStdStyle());
			plnRclM.setStdStyleDesc(plnZgPln.getStdStyleDesc());
			// 获取热处理循环次数
			String sqlSeq = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialRcl.QueryProcessSeq");
			ps = con.prepareStatement(sqlSeq);
			ps.setObject(1, plnRclS.getProPlanId());
			ps.setObject(2, plnRclS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnRclM.setProcessSeq(rs.getString("PROCESS_SEQ"));
			} else {
				plnRclM.setProcessSeq("1");
			}
			rs.close();
			ps.close();
			plnRclM.setRealProcessSeq("1");
			if (fl == 0) {
				String ifProduct = "0";
				int counnum = StoveHelper.getQueryStation(con,
						plnRclS.getProPlanId(), plnRclS.getGxPlanNo(), "F");
				if (counnum > 0) {
					ifProduct = "1";
				}
				plnRclM.setIfProduct(ifProduct);
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnRclM.getProPlanId(),
						plnRclM.getProPlanId(), "F");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnRclM.getPlineCode(), "F");
				plnRclM.setHeatPlanNo(heatPlanNo);
				plnRclM.setGxProSeq(String.valueOf(gxProSeq));
				// 订单内炉顺序号
				int lotNo = getMaxLotNoSqe(con, plnRclM.getProPlanId(),
						plnRclM.getGxPlanNo(), "F");
				plnRclM.setLotNoSqe(String.valueOf(lotNo));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyRcl"),
						plnRclM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();

				// 新增生产批号
				StoveHelper.updatePlnRclGroup(con, plnRclM.getProPlanId(),
						plnRclM.getGxPlanNo(), plnRclM.getPic());
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_RCL_M T"
						+ " SET T.PLN_INSINGLE_NUM  = TO_NUMBER(T.PLN_INSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_INSINGLE_WT   = TO_NUMBER(T.PLN_INSINGLE_WT) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_NUM = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_W   = TO_NUMBER(T.PLN_OUTSINGLE_W) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1, oldNum);
				ps.setObject(2, oldWt);
				ps.setObject(3, oldNum);
				ps.setObject(4, yjWt);
				ps.setObject(5, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
			// 更新订单虚拟挂料量
			// String update =
			// "UPDATE PLN_ORDER_RCL_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))+TO_NUMBER(?),"
			// +
			// "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))+TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
			// ps = con.prepareStatement(update);
			// ps.setObject(1, oldNum);
			// ps.setObject(2, oldWt);
			// ps.setObject(3, plnRclS.getProPlanId());
			// ps.setObject(4, plnRclS.getGxPlanNo());
			// ps.executeUpdate();
			// ps.close();
		}
		return true;
	}

	/**
	 * 新增加工线虚拟炉计划(自炼轧管炉计划下发)
	 * 
	 * @return
	 */
	public boolean addPlnZyJgxM(Connection con, PlnZyZgMEntity plnZgPln,
			List<PlnOrderJgxSEntity> plnJgx, String createName,
			String createTime,String delievStateCode,String delievStateName) throws SQLException {
		PlnZyJgxMEntity plnJgxM = new PlnZyJgxMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 轧管单倍支
		int cutNum = Integer.parseInt(plnZgPln.getOutnumCut());
		int zgNum = Integer.parseInt(plnZgPln.getPlnOutsingleNum());
		double totWeightM = Double.parseDouble(plnZgPln.getPlnOutsingleW());
		int contZgM = 0;
		int countZg = plnJgx.size();
		for (PlnOrderJgxSEntity plnJgxS : plnJgx) {
			// int cutNum = Integer.parseInt(plnJgxS.getOutnumCut());
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (plnJgxS.getOrdLnDlyPk().contains("ZZBY-J")) {
				continue;
			}
			if (Integer.parseInt(plnJgxS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnJgxS.getProPlanId() + "/"
							+ plnJgxS.getGxPlanNo());
				} else {
					String message = plnJgxS.getProPlanId() + "/"
							+ plnJgxS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				continue;
			}
			double wtIn = 0;// 已生成炉计划原料吨(已装炉)
			// int numIn = 0;
			// 查询当前镦拔扩订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLN_INSINGLE_NUM),0) PLN_INSINGLE_NUM,NVL(SUM(T.PLN_INSINGLE_WT),0) PLN_INSINGLE_WT FROM PLN_ZY_JGX_M T "
					+ " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?    AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgxS.getProPlanId());
			ps.setObject(2, plnJgxS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLN_INSINGLE_WT");
				// numIn = rs.getInt("PLN_INSINGLE_NUM");
			}
			rs.close();
			ps.close();
			sql = "SELECT NVL(SUM(T.PLAN_INDOUBLE_WT),0) PLAN_INDOUBLE_WT FROM PLN_ZY_JGX_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgxS.getProPlanId());
			ps.setObject(2, plnJgxS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("PLAN_INDOUBLE_WT");
			}
			rs.close();
			ps.close();

			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1,
					plnJgxS.getProPlanId() + "/" + plnJgxS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getFeedHeatNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnJgxS.getWeigthS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnJgxS.getWeigthS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}

			if (oldNum <= 0) {
				continue;
			}
			plnJgxM.setZyBatchIdZg(plnZgPln.getZyBatchId());
			plnJgxM.setDecision(plnJgxS.getDecision());
			plnJgxM.setStoveNo(plnZgPln.getStoveNo());
			if(plnZgPln.getPlineCode().equals("C072") && !plnJgxS.getPlineCode().equals("C092")&& !plnJgxS.getPlineCode().equals("C102")&& !plnJgxS.getPlineCode().equals("C107")&& !plnJgxS.getPlineCode().equals("C108")&& !plnJgxS.getPlineCode().equals("C109"))//天淮508轧制,但加工不在天淮
			{
				plnJgxM.setJudgeStoveNo("");
				plnJgxM.setFlagStoveNo("");
			}else
			{
				plnJgxM.setJudgeStoveNo(plnZgPln.getFeedHeatNo());
				plnJgxM.setFlagStoveNo(plnZgPln.getFeedHeatNo());
			}

			plnJgxM.setFeedHeatNo(plnZgPln.getFeedHeatNo());
			plnJgxM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnJgxM.setPlanstatus("00");
			plnJgxM.setUpperProcessCode("D");
			plnJgxM.setPlineCode(plnJgxS.getPlineCode());
			plnJgxM.setPlineName(plnJgxS.getPlineName());
			plnJgxM.setProcessCodeC(plnJgxS.getProcessCodeC());
			plnJgxM.setProcessDescC(plnJgxS.getProcessDescC());
			// 通过制程判定加工线是否末工序
			// if (plnJgxS.getWholeBacklogDesc().contains("接箍")) {
			// plnJgxM.setNextProcessCode("H");
			// plnJgxM.setIsendgx("0");
			// } else {
			if (plnJgxS.getOrdLnDlyPk().contains("ZZBY-J")) {
				plnJgxM.setNextProcessCode("H");
			} else if (plnJgxS.getOrdLnDlyPk().contains("ZZBY-D")) {
				plnJgxM.setNextProcessCode("G");
			} else {
				plnJgxM.setNextProcessCode("");
			}
			if (plnJgxS.getOrderSource().equals("备料需求")) {
				plnJgxM.setIsendgx("0");
			} else {
				plnJgxM.setIsendgx("1");
			}
			// }
			 String gowWhere = getPlineCodeGroup(con, plnJgxS.getPlineCode(),
			 plnJgxS.getProPlanId(), plnJgxS.getGxPlanNo(), "G");
			 if (gowWhere != null) {
				 // 查询去向
				 String sqlGroup =
						 "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
				 ps = con.prepareStatement(sqlGroup);
				 ps.setObject(1, plnJgxS.getPlineCode());
				 ps.setObject(2, gowWhere);
				 rs = ps.executeQuery();
				 if (rs.next()) {
					 plnJgxM.setGowhereName(rs.getString("STORAGE_NAME"));
					 plnJgxM.setGowhereCode(rs.getString("STORAGE_NO"));
				 }
				 rs.close();
				 ps.close();
			 }
			plnJgxM.setIfMatchOdd("0");
			plnJgxM.setIfDoHeatPlan("0");
			plnJgxM.setProPlanId(plnJgxS.getProPlanId());
			plnJgxM.setGxPlanNo(plnJgxS.getGxPlanNo());
			plnJgxM.setGradecode(plnZgPln.getGradecode());
			plnJgxM.setGradename(plnZgPln.getGradename());
			plnJgxM.setSteelcode(plnZgPln.getSteelcode());
			plnJgxM.setSteelname(plnZgPln.getSteelname());
			plnJgxM.setProduccode(plnZgPln.getProduccode());
			plnJgxM.setProducname(plnZgPln.getProducname());
			plnJgxM.setProdStandard(plnZgPln.getProdStandard());
			plnJgxM.setOutputStandard(plnZgPln.getOutputStandard());
			// 通过BOM查询投入产出
						String[] bomMat=null;
						if(plnJgxS.getWholeBacklog().equals("G")){
							bomMat= PlanFurnProduction.getQueryBomJgx(con,
									plnJgxS.getOrdLnDlyPk(),plnZgPln.getOutwlId());
						}else{
						 bomMat= PlanFurnProduction.getQueryBom(con,
								plnJgxS.getBom(), plnJgxS.getIndexSeq(),
								plnJgxS.getOrdLnDlyPk(), "G",plnZgPln.getGradecode());
						}
			plnJgxM.setInwlId(bomMat[0]);
			plnJgxM.setInwlDesc(bomMat[1]);
			plnJgxM.setOutwlId(bomMat[2]);
			plnJgxM.setOutwlDesc(bomMat[3]);
			plnJgxM.setBom(bomMat[4]);
			plnJgxM.setModelCode(plnZgPln.getModelCode());
			plnJgxM.setModelDesc(plnZgPln.getModelDesc());
			// 单倍支吨
			plnJgxM.setPlnInsingleNum(String.valueOf(oldNum));
			plnJgxM.setPlnInsingleWt(String.valueOf(oldWt));

			// // // 倍尺支吨
			// int plnIndoubNum = 0;
			// double plnIndoubWt = 0;
			// String sqlCl =
			// "SELECT SUM(NVL(T.PLAN_INDOUBLE_NUM,0)) PLAN_INDOUBLE_NUM,SUM(NVL(T.PLAN_INDOUBLE_WT,0)) PLAN_INDOUBLE_WT FROM PLN_ZY_ZG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			// ps = con.prepareStatement(sqlCl);
			// ps.setObject(1, plnZgPln.getProPlanId());
			// ps.setObject(2, plnZgPln.getGxPlanNo());
			// ps.setObject(3, plnZgPln.getJudgeStoveNo());
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnIndoubWt = rs.getDouble("PLAN_INDOUBLE_WT");
			// plnIndoubNum = rs.getInt("PLAN_INDOUBLE_NUM");
			// }
			// rs.close();
			// ps.close();
			// plnJgxM.setPlnIndoubleNum(String.valueOf(plnIndoubNum));
			// plnJgxM.setPlnIndoubleWt(String.valueOf(plnIndoubWt));
			// plnJgxM.setPlnOutdoubleNum(String.valueOf(plnIndoubNum));
			// plnJgxM.setPlnOutdoubleW(String.valueOf(plnIndoubWt));

			plnJgxM.setOrderSource(plnJgxS.getOrderSource());
			plnJgxM.setOrderNo(plnJgxS.getOrderNo());
			plnJgxM.setOrderSeq(plnJgxS.getOrderSeq());
			plnJgxM.setDeliveryNo(plnJgxS.getDeliveryNo());
			plnJgxM.setOrdLnDlyPk(plnJgxS.getOrdLnDlyPk());
			plnJgxM.setReqBlId(plnJgxS.getReqBlId());
			plnJgxM.setIfExport(plnJgxS.getIfExport());
			plnJgxM.setPriority(plnJgxS.getPriority());
			plnJgxM.setPriorityMemo(plnJgxS.getPriorityMemo());
			plnJgxM.setProMonth(plnJgxS.getProMonth());
			plnJgxM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnJgxM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnJgxM.setIfMonitor(plnJgxS.getIfMonitorJgx());
			plnJgxM.setPrdcrNo(plnJgxS.getPrdcrNo());
			plnJgxM.setMonitorPoint(plnJgxS.getMonitorPoint());
			plnJgxM.setWholeBacklog(plnJgxS.getWholeBacklog());
			plnJgxM.setWholeBacklogDesc(plnJgxS.getWholeBacklogDesc());
			plnJgxM.setStationRoad(plnJgxS.getStationRoad());
			plnJgxM.setCic(plnZgPln.getCic());
			if (plnJgxS.getSic() == null || plnJgxS.getSic().equals("")) {
				plnJgxM.setSic(plnJgxS.getSic());
			} else {
				plnJgxM.setSic(plnJgxS.getSic().split(",")[0]);
			}
			if (plnJgxS.getDic() == null || plnJgxS.getDic().equals("")) {
				plnJgxM.setDic(plnJgxS.getDic());
			} else {
				plnJgxM.setDic(plnJgxS.getDic().split(",")[0]);
			}
			if (plnJgxS.getPic() == null || plnJgxS.getPic().equals("")) {
				plnJgxM.setPic(plnJgxS.getPic());
			} else {
				plnJgxM.setPic(plnJgxS.getPic().split(",")[0]);
			}
			if (plnJgxS.getWic() == null || plnJgxS.getWic().equals("")) {
				plnJgxM.setWic(plnJgxS.getWic());
			} else {
				plnJgxM.setWic(plnJgxS.getWic().split(",")[0]);
			}
			plnJgxM.setCraftFileMan(plnJgxS.getCraftFileMan());
			plnJgxM.setCraftFileNo(plnJgxS.getCraftFileNo());
			plnJgxM.setCraftSeq(plnJgxS.getCraftSeq());
			plnJgxM.setSecCraftFileNo(plnZgPln.getSecCraftFileNo());
			plnJgxM.setOutdiameterIn(plnZgPln.getOutdiameterZg());
			plnJgxM.setWallthickIn(plnZgPln.getWallthickZg());
			plnJgxM.setLengthIn(plnZgPln.getAimlength());
			plnJgxM.setLengthmaxIn(plnZgPln.getLenRollMax());
			plnJgxM.setLengthminIn(plnZgPln.getLenRollMin());
			plnJgxM.setOutdiameter(plnJgxS.getOutdiameter());
			plnJgxM.setWallthick(plnJgxS.getWallthick());
			// 查询合同最大最小长度
			double lenMax = 0;
			double lenMin = 0;
			String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
			ps = con.prepareStatement(ordLen);
			ps.setObject(1, plnJgxS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();

			int outnumCut = 1;
			if (plnZgPln.getLenRollMin() != null
					| !plnZgPln.getLenRollMin().equals("")) {
				outnumCut = (int) (Double.parseDouble(plnZgPln.getLenRollMin()) / lenMin);
			}
			if (outnumCut <= 0) {
				outnumCut = 1;
			}
			plnJgxM.setLengthmax(String.valueOf(lenMax));
			plnJgxM.setLengthmin(String.valueOf(lenMin));
			plnJgxM.setOutnumCut(String.valueOf(outnumCut));

			plnJgxM.setPlnOutsingleNum(String.valueOf(oldNum * outnumCut));
			double burnoutRate = 0;
			// 查询产线烧损
			String sqlRate = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
					+ plnJgxS.getPlineCode() + "'";
			ps = con.prepareStatement(sqlRate);
			rs = ps.executeQuery();
			if (rs.next()) {
				burnoutRate = rs.getDouble("BURNOUT_RATE");
			}
			rs.close();
			ps.close();
			double yjWt = oldWt - oldWt * burnoutRate;
			plnJgxM.setPlnOutsingleW(String.valueOf(yjWt));
			plnJgxM.setCreateName(createName);
			plnJgxM.setCreateTime(createTime);
			plnJgxM.setIndexSeq(plnJgxS.getIndexSeq());
			plnJgxM.setSpecCode(plnZgPln.getSpecCode());
			plnJgxM.setSpecName(plnZgPln.getSpecName());
			plnJgxM.setStdCode(plnZgPln.getStdCode());
			plnJgxM.setStdName(plnZgPln.getStdName());
			plnJgxM.setStdStyle(plnZgPln.getStdStyle());
			plnJgxM.setStdStyleDesc(plnZgPln.getStdStyleDesc());
			plnJgxM.setDeliveryStateCode(delievStateCode);
			plnJgxM.setDeliveryStateName(delievStateName);
			if (fl == 0) {
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnJgxM.getProPlanId(),
						plnJgxM.getProPlanId(), "G");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnJgxM.getPlineCode(), "G");
				// 订单内炉顺序号
				int lotNo = getMaxLotNoSqe(con, plnJgxM.getProPlanId(),
						plnJgxM.getGxPlanNo(), "G");
				plnJgxM.setLotNoSqe(String.valueOf(lotNo));
				plnJgxM.setHeatPlanNo(heatPlanNo);
				plnJgxM.setGxProSeq(String.valueOf(gxProSeq));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyJgx"),
						plnJgxM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();

				// 新增生产批号
				StoveHelper.updatePlnJgxGroup(con, plnJgxM.getProPlanId(),
						plnJgxM.getGxPlanNo(), plnJgxM.getPic());
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_JGX_M T"
						+ " SET T.PLN_INSINGLE_NUM  = TO_NUMBER(T.PLN_INSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_INSINGLE_WT   = TO_NUMBER(T.PLN_INSINGLE_WT) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_NUM = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_W   = TO_NUMBER(T.PLN_OUTSINGLE_W) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1, oldNum);
				ps.setObject(2, oldWt);
				ps.setObject(3, oldNum);
				ps.setObject(4, yjWt);
				ps.setObject(5, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
			// 更新订单虚拟挂料量
			// String update =
			// "UPDATE PLN_ORDER_JGX_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))+TO_NUMBER(?),"
			// +
			// "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))+TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
			// ps = con.prepareStatement(update);
			// ps.setObject(1, oldNum);
			// ps.setObject(2, oldWt);
			// ps.setObject(3, plnJgxS.getProPlanId());
			// ps.setObject(4, plnJgxS.getGxPlanNo());
			// ps.executeUpdate();
			// ps.close();
		}
		return true;
	}

	/**
	 * 新增加工线虚拟炉计划(外购)
	 * 
	 * @return
	 */
	public boolean addPlnZyJgxMWg(Connection con, MatBcMEntityPln matBc,
			PlnOrderJgxSEntity plnJgxS, String createName, String createTime)
			throws SQLException {
		PlnZyJgxMEntity plnJgxM = new PlnZyJgxMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		String heatPlanNo = "";
		// 单倍支
		// int cutNum = Integer.parseInt(matBc.getCutNum());
		int oldNum = Integer.parseInt(matBc.getActCount());
		double oldWt = Double.parseDouble(matBc.getActWeight());
		int contZgM = 0;

		// 查询当前镦拔扩订单是否存在炉计划
		sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
		ps = con.prepareStatement(sql);
		ps.setObject(1, plnJgxS.getProPlanId());
		ps.setObject(2, plnJgxS.getGxPlanNo());
		ps.setObject(3, matBc.getJudgeStoveNo());
		rs = ps.executeQuery();
		if (rs.next()) {
			contZgM = 1;
			heatPlanNo = rs.getString("HEAT_PLAN_NO");
		}
		rs.close();
		ps.close();

		double burnoutRate = 0;
		// 查询产线烧损
		String sqlRate = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
				+ plnJgxS.getPlineCode() + "'";
		ps = con.prepareStatement(sqlRate);
		rs = ps.executeQuery();
		if (rs.next()) {
			burnoutRate = rs.getDouble("BURNOUT_RATE");
		}
		rs.close();
		ps.close();
		double yjWt = oldWt - oldWt * burnoutRate;
		if (contZgM == 0) {
			plnJgxM.setDecision(plnJgxS.getDecision());
			plnJgxM.setStoveNo(matBc.getStoveNo());
			plnJgxM.setJudgeStoveNo(matBc.getJudgeStoveNo());
			plnJgxM.setFeedHeatNo(matBc.getJudgeStoveNo());
			plnJgxM.setFlagStoveNo(matBc.getJudgeStoveNo());
			plnJgxM.setUpperHeatplanId(matBc.getHeatPlanNo());
			plnJgxM.setPlanstatus("00");
			plnJgxM.setUpperProcessCode(matBc.getProcessCdoe());
			plnJgxM.setPlineCode(plnJgxS.getPlineCode());
			plnJgxM.setPlineName(plnJgxS.getPlineName());
			plnJgxM.setProcessCodeC(plnJgxS.getProcessCodeC());
			plnJgxM.setProcessDescC(plnJgxS.getProcessDescC());
			// 通过制程判定加工线是否末工序
			// if (plnJgxS.getWholeBacklogDesc().contains("接箍")) {
			// plnJgxM.setNextProcessCode("H");
			// plnJgxM.setIsendgx("0");
			// } else {
			// 末工序获取去向
			if (plnJgxS.getOrdLnDlyPk().contains("ZZBY-J")) {
				plnJgxM.setNextProcessCode("H");
			} else if (plnJgxS.getOrdLnDlyPk().contains("ZZBY-D")) {
				plnJgxM.setNextProcessCode("G");
			} else {
				plnJgxM.setNextProcessCode("");
			}
			if (plnJgxS.getOrderSource().equals("备料需求")) {
				plnJgxM.setIsendgx("0");
			} else {
				plnJgxM.setIsendgx("1");
			}
			// }
			 String gowWhere = getPlineCodeGroup(con, plnJgxS.getPlineCode(),
			 plnJgxS.getProPlanId(), plnJgxS.getGxPlanNo(), "G");
			 if (gowWhere != null) {
				 // 查询去向
				 String sqlGroup =
						 "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
				 ps = con.prepareStatement(sqlGroup);
				 ps.setObject(1, plnJgxS.getPlineCode());
				 ps.setObject(2, gowWhere);
				 rs = ps.executeQuery();
				 if (rs.next()) {
					 plnJgxM.setGowhereName(rs.getString("STORAGE_NAME"));
					 plnJgxM.setGowhereCode(rs.getString("STORAGE_NO"));
				 }
				 rs.close();
				 ps.close();
			 }
			plnJgxM.setIfMatchOdd("0");
			plnJgxM.setIfDoHeatPlan("0");
			plnJgxM.setProPlanId(plnJgxS.getProPlanId());
			plnJgxM.setGxPlanNo(plnJgxS.getGxPlanNo());
			plnJgxM.setGradecode(matBc.getGradecode());
			plnJgxM.setGradename(matBc.getGradename());
			plnJgxM.setSteelcode(plnJgxS.getSteelcode());
			plnJgxM.setSteelname(plnJgxS.getSteelname());
			plnJgxM.setProduccode(plnJgxS.getProduccode());
			plnJgxM.setProducname(plnJgxS.getProducname());

			// 查询轧管排产信息
			String sqlZg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.QueryWgZg");
			ps = con.prepareStatement(sqlZg);
			ps.setObject(1, plnJgxS.getOrdLnDlyPk());
			// ps.setObject(2, plnJgxS.getPlnDivideId());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnJgxM.setProdStandard(rs.getString("PROD_STANDARD"));
				plnJgxM.setOutputStandard(rs.getString("Output_Standard"));
				plnJgxM.setSecCraftFileNo(rs.getString("SEC_CRAFT_FILE_NO"));
				plnJgxM.setWholeBacklog(rs.getString("PROCESS_SEQ"));
			}
			rs.close();
			ps.close();

			plnJgxM.setInwlId(plnJgxS.getInwlId());
			plnJgxM.setInwlDesc(plnJgxS.getInwlDesc());
			plnJgxM.setOutwlId(plnJgxS.getOutwlId());
			plnJgxM.setOutwlDesc(plnJgxS.getOutwlDesc());
			plnJgxM.setModelCode(matBc.getModelCode());
			plnJgxM.setModelDesc(matBc.getModelDesc());
			// 单倍支吨
			plnJgxM.setPlnInsingleNum(String.valueOf(oldNum));
			plnJgxM.setPlnInsingleWt(String.valueOf(oldWt));

			plnJgxM.setOrderSource(plnJgxS.getOrderSource());
			plnJgxM.setOrderNo(plnJgxS.getOrderNo());
			plnJgxM.setOrderSeq(plnJgxS.getOrderSeq());
			plnJgxM.setDeliveryNo(plnJgxS.getDeliveryNo());
			plnJgxM.setOrdLnDlyPk(plnJgxS.getOrdLnDlyPk());
			plnJgxM.setReqBlId(plnJgxS.getReqBlId());
			plnJgxM.setIfExport(plnJgxS.getIfExport());
			plnJgxM.setPriority(plnJgxS.getPriority());
			plnJgxM.setPriorityMemo(plnJgxS.getPriorityMemo());
			plnJgxM.setProMonth(plnJgxS.getProMonth());
			plnJgxM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnJgxM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnJgxM.setIfMonitor(plnJgxS.getIfMonitorJgx());
			plnJgxM.setPrdcrNo(plnJgxS.getPrdcrNo());
			plnJgxM.setMonitorPoint(plnJgxS.getMonitorPoint());
			plnJgxM.setBom(plnJgxS.getBom());

			plnJgxM.setWholeBacklogDesc(plnJgxS.getWholeBacklogDesc());
			plnJgxM.setStationRoad(plnJgxS.getStationRoad());
			plnJgxM.setCic(matBc.getCic());
			if (plnJgxS.getSic() == null || plnJgxS.getSic().equals("")) {
				plnJgxM.setSic(plnJgxS.getSic());
			} else {
				plnJgxM.setSic(plnJgxS.getSic().split(",")[0]);
			}
			if (plnJgxS.getDic() == null || plnJgxS.getDic().equals("")) {
				plnJgxM.setDic(plnJgxS.getDic());
			} else {
				plnJgxM.setDic(plnJgxS.getDic().split(",")[0]);
			}
			if (plnJgxS.getPic() == null || plnJgxS.getPic().equals("")) {
				plnJgxM.setPic(plnJgxS.getPic());
			} else {
				plnJgxM.setPic(plnJgxS.getPic().split(",")[0]);
			}
			if (plnJgxS.getWic() == null || plnJgxS.getWic().equals("")) {
				plnJgxM.setWic(plnJgxS.getWic());
			} else {
				plnJgxM.setWic(plnJgxS.getWic().split(",")[0]);
			}
			plnJgxM.setCraftFileMan(plnJgxS.getCraftFileMan());
			plnJgxM.setCraftFileNo(plnJgxS.getCraftFileNo());
			plnJgxM.setCraftSeq(plnJgxS.getCraftSeq());

			plnJgxM.setOutdiameterIn(matBc.getActDimater());
			plnJgxM.setWallthickIn(matBc.getActHeight());
			plnJgxM.setLengthIn(matBc.getActLen());
			plnJgxM.setLengthmaxIn(matBc.getActLenMax());
			plnJgxM.setLengthminIn(matBc.getActLenMin());
			plnJgxM.setOutdiameter(plnJgxS.getOutdiameter());
			plnJgxM.setWallthick(plnJgxS.getWallthick());
			// 查询合同最大最小长度
			double lenMax = 0;
			double lenMin = 0;
			String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
			ps = con.prepareStatement(ordLen);
			ps.setObject(1, plnJgxS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();

			int outnumCut = 1;
			if (matBc.getActLenMin() != null | !matBc.getActLenMin().equals("")) {
				outnumCut = (int) (Double.parseDouble(matBc.getActLenMin()) / lenMin);
			}
			if (outnumCut <= 0) {
				outnumCut = 1;
			}
			plnJgxM.setLengthmax(String.valueOf(lenMax));
			plnJgxM.setLengthmin(String.valueOf(lenMin));
			plnJgxM.setOutnumCut(String.valueOf(outnumCut));

			plnJgxM.setPlnOutsingleNum(String.valueOf(oldNum * outnumCut));

			plnJgxM.setPlnOutsingleW(String.valueOf(yjWt));
			plnJgxM.setCreateName(createName);
			plnJgxM.setCreateTime(createTime);
			plnJgxM.setIndexSeq(plnJgxS.getIndexSeq());
			plnJgxM.setSpecCode(plnJgxS.getSpecCode());
			plnJgxM.setSpecName(plnJgxS.getSpecName());
			plnJgxM.setStdCode(plnJgxS.getStdCode());
			plnJgxM.setStdName(plnJgxS.getStdName());
			plnJgxM.setStdStyle(plnJgxS.getStdStyle());
			plnJgxM.setStdStyleDesc(plnJgxS.getStdStyleDesc());
			// 新增
			heatPlanNo = getMaxHeatPlanNo(con, plnJgxM.getProPlanId(),
					plnJgxM.getProPlanId(), "G");
			// 获取炉计划顺序号
			int gxProSeq = getMaxGxPlnSeq(con, plnJgxM.getPlineCode(), "G");
			// 订单内炉顺序号
			int lotNo = getMaxLotNoSqe(con, plnJgxM.getProPlanId(),
					plnJgxM.getGxPlanNo(), "G");
			plnJgxM.setLotNoSqe(String.valueOf(lotNo));
			plnJgxM.setHeatPlanNo(heatPlanNo);
			plnJgxM.setGxProSeq(String.valueOf(gxProSeq));
			String addPlnGxZg = EntityTool.fillSqlByEntity(
					CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.addPlnZyJgx"), plnJgxM);
			ps = con.prepareStatement(addPlnGxZg);
			ps.executeUpdate();
			ps.close();

			// 新增生产批号
			StoveHelper.updatePlnJgxGroup(con, plnJgxM.getProPlanId(),
					plnJgxM.getGxPlanNo(), plnJgxM.getPic());
		} else {
			// 修改计划量
			String sqlUpdate = "UPDATE PLN_ZY_JGX_M T SET "
					+ " T.PLN_INSINGLE_NUM  = TO_NUMBER(T.PLN_INSINGLE_NUM) + TO_NUMBER(?), "
					+ "T.PLN_INSINGLE_WT   = TO_NUMBER(T.PLN_INSINGLE_WT) + TO_NUMBER(?), "
					+ "T.PLN_OUTSINGLE_NUM = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?),"
					+ " T.PLN_OUTSINGLE_W   = TO_NUMBER(T.PLN_OUTSINGLE_W) + TO_NUMBER(?) WHERE T.HEAT_PLAN_NO = ?";
			ps = con.prepareStatement(sqlUpdate);
			ps.setObject(1, oldNum);
			ps.setObject(2, oldWt);
			ps.setObject(3, oldNum);
			ps.setObject(4, yjWt);
			ps.setObject(5, heatPlanNo);
			ps.executeUpdate();
			ps.close();
		}
		// 修改库存本工序炉计划ID
		String upMat = "UPDATE MAT_BC_M T SET T.HEAT_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=? AND T.QCM_STAUS='00'";
		ps = con.prepareStatement(upMat);
		ps.setObject(1, heatPlanNo);
		ps.setObject(2, matBc.getJudgeStoveNo());
		ps.setObject(3, matBc.getProPlanIdNext());
		ps.setObject(4, matBc.getGxPlanNoNext());
		ps.setObject(5, "G");
		ps.executeUpdate();
		ps.close();
		return true;
	}

	/**
	 * 新增加工线虚拟炉计划(自炼镦拔扩炉计划下发)
	 * 
	 * @return
	 */
	public boolean addPlnZyJgxMD(Connection con, PlnZyDbkMEntity plnZgPln,
			List<PlnOrderJgxSEntity> plnJgx, String createName,
			String createTime) throws SQLException {
		PlnZyJgxMEntity plnJgxM = new PlnZyJgxMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 单倍支
		int zgNum = Integer.parseInt(plnZgPln.getPlnInsingleNum());
		double totWeightM = Double.parseDouble(plnZgPln.getPlnInsingleWt());
		int contZgM = 0;
		int countZg = plnJgx.size();
		for (PlnOrderJgxSEntity plnJgxS : plnJgx) {
			// int cutNum = Integer.parseInt(plnJgxS.getOutnumCut());
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (plnJgxS.getOrdLnDlyPk().contains("ZZBY-J")) {
				continue;
			}
			if (Integer.parseInt(plnJgxS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnJgxS.getProPlanId() + "/"
							+ plnJgxS.getGxPlanNo());
				} else {
					String message = plnJgxS.getProPlanId() + "/"
							+ plnJgxS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				continue;
			}
			double wtIn = 0;// 已生成炉计划原料吨(已装炉)
			// int numIn = 0;
			// 查询当前镦拔扩订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLN_INSINGLE_NUM),0) PLN_INSINGLE_NUM,NVL(SUM(T.PLN_INSINGLE_WT),0) PLN_INSINGLE_WT FROM PLN_ZY_JGX_M T "
					+ " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?    AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgxS.getProPlanId());
			ps.setObject(2, plnJgxS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLN_INSINGLE_WT");
				// numIn = rs.getInt("PLN_INSINGLE_NUM");
			}
			rs.close();
			ps.close();
			sql = "SELECT NVL(SUM(T.PLAN_INDOUBLE_WT),0) PLAN_INDOUBLE_WT FROM PLN_ZY_JGX_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgxS.getProPlanId());
			ps.setObject(2, plnJgxS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("PLAN_INDOUBLE_WT");
			}
			rs.close();
			ps.close();

			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1,
					plnJgxS.getProPlanId() + "/" + plnJgxS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getJudgeStoveNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnJgxS.getWeigthS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnJgxS.getWeigthS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnJgxM.setZyBatchIdZg(plnZgPln.getZyBatchIdZg());
			plnJgxM.setDecision(plnJgxS.getDecision());
			plnJgxM.setStoveNo(plnZgPln.getStoveNo());
			plnJgxM.setJudgeStoveNo(plnZgPln.getJudgeStoveNo());
			plnJgxM.setFeedHeatNo(plnZgPln.getJudgeStoveNo());
			plnJgxM.setFlagStoveNo(plnZgPln.getJudgeStoveNo());
			plnJgxM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnJgxM.setPlanstatus("00");
			plnJgxM.setUpperProcessCode("E");
			plnJgxM.setPlineCode(plnJgxS.getPlineCode());
			plnJgxM.setPlineName(plnJgxS.getPlineName());
			plnJgxM.setProcessCodeC(plnJgxS.getProcessCodeC());
			plnJgxM.setProcessDescC(plnJgxS.getProcessDescC());
			// 通过制程判定加工线是否末工序
			// if (plnJgxS.getWholeBacklogDesc().contains("接箍")) {
			// plnJgxM.setNextProcessCode("H");
			// plnJgxM.setIsendgx("0");
			// } else {
			// 末工序获取去向
			if (plnJgxS.getOrdLnDlyPk().contains("ZZBY-J")) {
				plnJgxM.setNextProcessCode("H");
			} else if (plnJgxS.getOrdLnDlyPk().contains("ZZBY-D")) {
				plnJgxM.setNextProcessCode("G");
			} else {
				plnJgxM.setNextProcessCode("");
			}
			if (plnJgxS.getOrderSource().equals("备料需求")) {
				plnJgxM.setIsendgx("0");
			} else {
				plnJgxM.setIsendgx("1");
			}
			// }
			// String gowWhere = getPlineCodeGroup(con, plnJgxS.getPlineCode(),
			// plnJgxS.getProPlanId(), plnJgxS.getGxPlanNo(), "G");
			// if (gowWhere != null) {
			// // 查询去向
			// String sqlGroup =
			// "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
			// ps = con.prepareStatement(sqlGroup);
			// ps.setObject(1, plnJgxS.getPlineCode());
			// ps.setObject(2, gowWhere);
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnJgxM.setGowhereName(rs.getString("STORAGE_NAME"));
			// plnJgxM.setGowhereCode(rs.getString("STORAGE_NO"));
			// }
			// rs.close();
			// ps.close();
			// }
			plnJgxM.setIfMatchOdd("0");
			plnJgxM.setIfDoHeatPlan("0");
			plnJgxM.setProPlanId(plnJgxS.getProPlanId());
			plnJgxM.setGxPlanNo(plnJgxS.getGxPlanNo());
			plnJgxM.setGradecode(plnZgPln.getGradecode());
			plnJgxM.setGradename(plnZgPln.getGradename());
			plnJgxM.setSteelcode(plnZgPln.getSteelcode());
			plnJgxM.setSteelname(plnZgPln.getSteelname());
			plnJgxM.setProduccode(plnZgPln.getProduccode());
			plnJgxM.setProducname(plnZgPln.getProducname());
			plnJgxM.setProdStandard(plnZgPln.getProdStandard());
			plnJgxM.setOutputStandard(plnZgPln.getOutputStandard());
			// 通过BOM查询投入产出
						String[] bomMat=null;
						if(plnJgxS.getWholeBacklog().equals("G")){
							bomMat= PlanFurnProduction.getQueryBomJgx(con,
									plnJgxS.getOrdLnDlyPk(),plnZgPln.getOutwlId());
						}else{
						 bomMat= PlanFurnProduction.getQueryBom(con,
								plnJgxS.getBom(), plnJgxS.getIndexSeq(),
								plnJgxS.getOrdLnDlyPk(), "G",plnZgPln.getGradecode());
						}
			plnJgxM.setInwlId(bomMat[0]);
			plnJgxM.setInwlDesc(bomMat[1]);
			plnJgxM.setOutwlId(bomMat[2]);
			plnJgxM.setOutwlDesc(bomMat[3]);
			plnJgxM.setBom(bomMat[4]);
			plnJgxM.setModelCode(plnZgPln.getModelCode());
			plnJgxM.setModelDesc(plnZgPln.getModelDesc());
			// 单倍支吨
			plnJgxM.setPlnInsingleNum(String.valueOf(oldNum));
			plnJgxM.setPlnInsingleWt(String.valueOf(oldWt));

			// // 倍尺支吨
			// int plnIndoubNum = 0;
			// double plnIndoubWt = 0;
			// String sqlCl =
			// "SELECT SUM(NVL(T.PLAN_INDOUBLE_NUM,0)) PLAN_INDOUBLE_NUM,SUM(NVL(T.PLAN_INDOUBLE_WT,0)) PLAN_INDOUBLE_WT FROM PLN_ZY_ZG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			// ps = con.prepareStatement(sqlCl);
			// ps.setObject(1, plnZgPln.getProPlanId());
			// ps.setObject(2, plnZgPln.getGxPlanNo());
			// ps.setObject(3, plnZgPln.getJudgeStoveNo());
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnIndoubWt = rs.getDouble("PLAN_INDOUBLE_WT");
			// plnIndoubNum = rs.getInt("PLAN_INDOUBLE_NUM");
			// }
			// rs.close();
			// ps.close();
			// plnJgxM.setPlnIndoubleNum(String.valueOf(plnIndoubNum));
			// plnJgxM.setPlnIndoubleWt(String.valueOf(plnIndoubWt));
			// plnJgxM.setPlnOutdoubleNum(String.valueOf(plnIndoubNum));
			// plnJgxM.setPlnOutdoubleW(String.valueOf(plnIndoubWt));

			plnJgxM.setOrderSource(plnJgxS.getOrderSource());
			plnJgxM.setOrderNo(plnJgxS.getOrderNo());
			plnJgxM.setOrderSeq(plnJgxS.getOrderSeq());
			plnJgxM.setDeliveryNo(plnJgxS.getDeliveryNo());
			plnJgxM.setOrdLnDlyPk(plnJgxS.getOrdLnDlyPk());
			plnJgxM.setReqBlId(plnJgxS.getReqBlId());
			plnJgxM.setIfExport(plnJgxS.getIfExport());
			plnJgxM.setPriority(plnJgxS.getPriority());
			plnJgxM.setPriorityMemo(plnJgxS.getPriorityMemo());
			plnJgxM.setProMonth(plnJgxS.getProMonth());
			plnJgxM.setIfMonitor(plnJgxS.getIfMonitorJgx());
			plnJgxM.setPrdcrNo(plnJgxS.getPrdcrNo());
			plnJgxM.setMonitorPoint(plnJgxS.getMonitorPoint());
			plnJgxM.setWholeBacklog(plnJgxS.getWholeBacklog());
			plnJgxM.setWholeBacklogDesc(plnJgxS.getWholeBacklogDesc());
			plnJgxM.setStationRoad(plnJgxS.getStationRoad());
			plnJgxM.setCic(plnZgPln.getCic());
			if (plnJgxS.getSic() == null || plnJgxS.getSic().equals("")) {
				plnJgxM.setSic(plnJgxS.getSic());
			} else {
				plnJgxM.setSic(plnJgxS.getSic().split(",")[0]);
			}
			if (plnJgxS.getDic() == null || plnJgxS.getDic().equals("")) {
				plnJgxM.setDic(plnJgxS.getDic());
			} else {
				plnJgxM.setDic(plnJgxS.getDic().split(",")[0]);
			}
			if (plnJgxS.getPic() == null || plnJgxS.getPic().equals("")) {
				plnJgxM.setPic(plnJgxS.getPic());
			} else {
				plnJgxM.setPic(plnJgxS.getPic().split(",")[0]);
			}
			if (plnJgxS.getWic() == null || plnJgxS.getWic().equals("")) {
				plnJgxM.setWic(plnJgxS.getWic());
			} else {
				plnJgxM.setWic(plnJgxS.getWic().split(",")[0]);
			}
			plnJgxM.setCraftFileMan(plnJgxS.getCraftFileMan());
			plnJgxM.setCraftFileNo(plnJgxS.getCraftFileNo());
			plnJgxM.setCraftSeq(plnJgxS.getCraftSeq());
			plnJgxM.setSecCraftFileNo(plnZgPln.getSecCraftFileNo());
			plnJgxM.setOutdiameterIn(plnZgPln.getOutdiameterIn());
			plnJgxM.setWallthickIn(plnZgPln.getWallthickIn());
			plnJgxM.setLengthIn(plnZgPln.getAimlength());
			plnJgxM.setLengthmaxIn(plnZgPln.getLengthmaxIn());
			plnJgxM.setLengthminIn(plnZgPln.getLengthminIn());
			plnJgxM.setOutdiameter(plnJgxS.getOutdiameter());
			plnJgxM.setWallthick(plnJgxS.getWallthick());
			// 查询合同最大最小长度
			double lenMax = 0;
			double lenMin = 0;
			String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
			ps = con.prepareStatement(ordLen);
			ps.setObject(1, plnJgxS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();
			int outnumCut = 1;
			if (plnZgPln.getLengthminIn() != null
					| !plnZgPln.getLengthminIn().equals("")) {
				outnumCut = (int) (Double
						.parseDouble(plnZgPln.getLengthminIn()) / lenMin);
			}
			if (outnumCut <= 0) {
				outnumCut = 1;
			}
			plnJgxM.setLengthmax(String.valueOf(lenMax));
			plnJgxM.setLengthmin(String.valueOf(lenMin));
			plnJgxM.setOutnumCut(String.valueOf(outnumCut));
			plnJgxM.setPlnOutsingleNum(String.valueOf(oldNum * outnumCut));
			double burnoutRate = 0;
			// 查询产线烧损
			String sqlRate = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
					+ plnJgxS.getPlineCode() + "'";
			ps = con.prepareStatement(sqlRate);
			rs = ps.executeQuery();
			if (rs.next()) {
				burnoutRate = rs.getDouble("BURNOUT_RATE");
			}
			rs.close();
			ps.close();
			double yjWt = oldWt - oldWt * burnoutRate;
			plnJgxM.setPlnOutsingleW(String.valueOf(yjWt));

			plnJgxM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnJgxM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnJgxM.setCreateName(createName);
			plnJgxM.setCreateTime(createTime);
			plnJgxM.setIndexSeq(plnJgxS.getIndexSeq());
			plnJgxM.setSpecCode(plnZgPln.getSpecCode());
			plnJgxM.setSpecName(plnZgPln.getSpecName());
			plnJgxM.setStdCode(plnZgPln.getStdCode());
			plnJgxM.setStdName(plnZgPln.getStdName());
			plnJgxM.setStdStyle(plnZgPln.getStdStyle());
			plnJgxM.setStdStyleDesc(plnZgPln.getStdStyleDesc());
			if (fl == 0) {
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnJgxM.getProPlanId(),
						plnJgxM.getProPlanId(), "G");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnJgxM.getPlineCode(), "G");

				// 订单内炉顺序号
				int lotNo = getMaxLotNoSqe(con, plnJgxM.getProPlanId(),
						plnJgxM.getGxPlanNo(), "G");
				plnJgxM.setLotNoSqe(String.valueOf(lotNo));
				plnJgxM.setHeatPlanNo(heatPlanNo);
				plnJgxM.setGxProSeq(String.valueOf(gxProSeq));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyJgx"),
						plnJgxM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();

				// 新增生产批号
				StoveHelper.updatePlnJgxGroup(con, plnJgxM.getProPlanId(),
						plnJgxM.getGxPlanNo(), plnJgxM.getPic());
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_JGX_M T"
						+ " SET T.PLN_INSINGLE_NUM  = TO_NUMBER(T.PLN_INSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_INSINGLE_WT   = TO_NUMBER(T.PLN_INSINGLE_WT) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_NUM = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_W   = TO_NUMBER(T.PLN_OUTSINGLE_W) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1, oldNum);
				ps.setObject(2, oldWt);
				ps.setObject(3, oldNum);
				ps.setObject(4, yjWt);
				ps.setObject(5, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
			// 更新订单虚拟挂料量
			// String update =
			// "UPDATE PLN_ORDER_JGX_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))+TO_NUMBER(?),"
			// +
			// "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))+TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
			// ps = con.prepareStatement(update);
			// ps.setObject(1, oldNum);
			// ps.setObject(2, oldWt);
			// ps.setObject(3, plnJgxS.getProPlanId());
			// ps.setObject(4, plnJgxS.getGxPlanNo());
			// ps.executeUpdate();
			// ps.close();
		}
		return true;
	}

	/**
	 * 新增加工线虚拟炉计划(自炼热处理炉计划下发)
	 * 
	 * @return
	 */
	public boolean addPlnZyJgxME(Connection con, PlnZyRclMEntity plnZgPln,
			List<PlnOrderJgxSEntity> plnJgx, String createName,
			String createTime,String delievStateCode,String delievStateName) throws SQLException {
		PlnZyJgxMEntity plnJgxM = new PlnZyJgxMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 单倍支
		int zgNum = Integer.parseInt(plnZgPln.getPlnInsingleNum());
		double totWeightM = Double.parseDouble(plnZgPln.getPlnInsingleWt());
		int contZgM = 0;
		int countZg = plnJgx.size();
		for (PlnOrderJgxSEntity plnJgxS : plnJgx) {
			// int cutNum = Integer.parseInt(plnJgxS.getOutnumCut());
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnJgxS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnJgxS.getProPlanId() + "/"
							+ plnJgxS.getGxPlanNo());
				} else {
					String message = plnJgxS.getProPlanId() + "/"
							+ plnJgxS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				//continue;
			}
			double wtIn = 0;// 已生成炉计划原料吨(已装炉)
			// int numIn = 0;
			// 查询当前镦拔扩订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLN_INSINGLE_NUM),0) PLN_INSINGLE_NUM,NVL(SUM(T.PLN_INSINGLE_WT),0) PLN_INSINGLE_WT FROM PLN_ZY_JGX_M T"
					+ "  WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?    AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgxS.getProPlanId());
			ps.setObject(2, plnJgxS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLN_INSINGLE_WT");
				// numIn = rs.getInt("PLN_INSINGLE_NUM");
			}
			rs.close();
			ps.close();
			sql = "SELECT NVL(SUM(T.PLAN_INDOUBLE_WT),0) PLAN_INDOUBLE_WT FROM PLN_ZY_JGX_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgxS.getProPlanId());
			ps.setObject(2, plnJgxS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("PLAN_INDOUBLE_WT");
			}
			rs.close();
			ps.close();

			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1,
					plnJgxS.getProPlanId() + "/" + plnJgxS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getJudgeStoveNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnJgxS.getWeigthS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnJgxS.getWeigthS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}
			if (oldNum <= 0 && contZgM != countZg) {
				continue;
			}
			plnJgxM.setZyBatchIdZg(plnZgPln.getZyBatchIdZg());
			plnJgxM.setDecision(plnJgxS.getDecision());
			plnJgxM.setStoveNo(plnZgPln.getStoveNo());

			if(plnZgPln.getPlineCode().equals("C091") && !plnJgxS.getPlineCode().equals("C092")&& !plnJgxS.getPlineCode().equals("C102")&& !plnJgxS.getPlineCode().equals("C107")&& !plnJgxS.getPlineCode().equals("C108")&& !plnJgxS.getPlineCode().equals("C109"))//天淮热处理，但加工不在天淮
			{
				plnJgxM.setJudgeStoveNo("");
				plnJgxM.setFlagStoveNo("");
			}else
			{
				plnJgxM.setJudgeStoveNo(plnZgPln.getJudgeStoveNo());
				plnJgxM.setFlagStoveNo(plnZgPln.getJudgeStoveNo());
			}


			plnJgxM.setFeedHeatNo(plnZgPln.getJudgeStoveNo());

			plnJgxM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnJgxM.setPlanstatus("00");
			plnJgxM.setUpperProcessCode("F");
			plnJgxM.setPlineCode(plnJgxS.getPlineCode());
			plnJgxM.setPlineName(plnJgxS.getPlineName());
			plnJgxM.setProcessCodeC(plnJgxS.getProcessCodeC());
			plnJgxM.setProcessDescC(plnJgxS.getProcessDescC());
			// 通过制程判定加工线是否末工序
			// if (plnJgxS.getWholeBacklogDesc().contains("接箍")) {
			// plnJgxM.setNextProcessCode("H");
			// plnJgxM.setIsendgx("0");
			// } else {
			// 末工序获取去向
			if (plnJgxS.getOrdLnDlyPk().contains("ZZBY-J")) {
				plnJgxM.setNextProcessCode("H");
			} else if (plnJgxS.getOrdLnDlyPk().contains("ZZBY-D")) {
				plnJgxM.setNextProcessCode("G");
			} else {
				plnJgxM.setNextProcessCode("");
			}
			if (plnJgxS.getOrderSource().equals("备料需求")) {
				plnJgxM.setIsendgx("0");
			} else {
				plnJgxM.setIsendgx("1");
			}
			// }
			 String gowWhere = getPlineCodeGroup(con, plnJgxS.getPlineCode(),
			 plnJgxS.getProPlanId(), plnJgxS.getGxPlanNo(), "G");
			 if (gowWhere != null) {
				 // 查询去向
				 String sqlGroup =
						 "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
				 ps = con.prepareStatement(sqlGroup);
				 ps.setObject(1, plnJgxS.getPlineCode());
				 ps.setObject(2, gowWhere);
				 rs = ps.executeQuery();
				 if (rs.next()) {
					 plnJgxM.setGowhereName(rs.getString("STORAGE_NAME"));
					 plnJgxM.setGowhereCode(rs.getString("STORAGE_NO"));
				 }
				 rs.close();
				 ps.close();
			 }
			// }
			plnJgxM.setIfMatchOdd("0");
			plnJgxM.setIfDoHeatPlan("0");
			plnJgxM.setProPlanId(plnJgxS.getProPlanId());
			plnJgxM.setGxPlanNo(plnJgxS.getGxPlanNo());
			plnJgxM.setGradecode(plnZgPln.getGradecode());
			plnJgxM.setGradename(plnZgPln.getGradename());
			plnJgxM.setSteelcode(plnZgPln.getSteelcode());
			plnJgxM.setSteelname(plnZgPln.getSteelname());
			plnJgxM.setProduccode(plnZgPln.getProduccode());
			plnJgxM.setProducname(plnZgPln.getProducname());
			plnJgxM.setProdStandard(plnZgPln.getProdStandard());
			plnJgxM.setOutputStandard(plnZgPln.getOutputStandard());
			// 通过BOM查询投入产出
						String[] bomMat=null;
						if(plnJgxS.getWholeBacklog().equals("G")){
							bomMat= PlanFurnProduction.getQueryBomJgx(con,
									plnJgxS.getOrdLnDlyPk(),plnZgPln.getOutwlId());
						}else{
						 bomMat= PlanFurnProduction.getQueryBom(con,
								plnJgxS.getBom(), plnJgxS.getIndexSeq(),
								plnJgxS.getOrdLnDlyPk(), "G",plnZgPln.getGradecode());
						}
			plnJgxM.setInwlId(bomMat[0]);
			plnJgxM.setInwlDesc(bomMat[1]);
			plnJgxM.setOutwlId(bomMat[2]);
			plnJgxM.setOutwlDesc(bomMat[3]);
			plnJgxM.setBom(bomMat[4]);
			plnJgxM.setModelCode(plnZgPln.getModelCode());
			plnJgxM.setModelDesc(plnZgPln.getModelDesc());
			// 单倍支吨
			plnJgxM.setPlnInsingleNum(String.valueOf(oldNum));
			plnJgxM.setPlnInsingleWt(String.valueOf(oldWt));

			// // 倍尺支吨
			// int plnIndoubNum = 0;
			// double plnIndoubWt = 0;
			// String sqlCl =
			// "SELECT SUM(NVL(T.PLAN_INDOUBLE_NUM,0)) PLAN_INDOUBLE_NUM,SUM(NVL(T.PLAN_INDOUBLE_WT,0)) PLAN_INDOUBLE_WT FROM PLN_ZY_ZG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			// ps = con.prepareStatement(sqlCl);
			// ps.setObject(1, plnZgPln.getProPlanId());
			// ps.setObject(2, plnZgPln.getGxPlanNo());
			// ps.setObject(3, plnZgPln.getJudgeStoveNo());
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnIndoubWt = rs.getDouble("PLAN_INDOUBLE_WT");
			// plnIndoubNum = rs.getInt("PLAN_INDOUBLE_NUM");
			// }
			// rs.close();
			// ps.close();
			// plnJgxM.setPlnIndoubleNum(String.valueOf(plnIndoubNum));
			// plnJgxM.setPlnIndoubleWt(String.valueOf(plnIndoubWt));
			// plnJgxM.setPlnOutdoubleNum(String.valueOf(plnIndoubNum));
			// plnJgxM.setPlnOutdoubleW(String.valueOf(plnIndoubWt));

			plnJgxM.setOrderSource(plnJgxS.getOrderSource());
			plnJgxM.setOrderNo(plnJgxS.getOrderNo());
			plnJgxM.setOrderSeq(plnJgxS.getOrderSeq());
			plnJgxM.setDeliveryNo(plnJgxS.getDeliveryNo());
			plnJgxM.setOrdLnDlyPk(plnJgxS.getOrdLnDlyPk());
			plnJgxM.setReqBlId(plnJgxS.getReqBlId());
			plnJgxM.setIfExport(plnJgxS.getIfExport());
			plnJgxM.setPriority(plnJgxS.getPriority());
			plnJgxM.setPriorityMemo(plnJgxS.getPriorityMemo());
			plnJgxM.setProMonth(plnJgxS.getProMonth());
			plnJgxM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnJgxM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnJgxM.setIfMonitor(plnJgxS.getIfMonitorJgx());
			plnJgxM.setPrdcrNo(plnJgxS.getPrdcrNo());
			plnJgxM.setMonitorPoint(plnJgxS.getMonitorPoint());
			plnJgxM.setWholeBacklog(plnJgxS.getWholeBacklog());
			plnJgxM.setWholeBacklogDesc(plnJgxS.getWholeBacklogDesc());
			plnJgxM.setStationRoad(plnJgxS.getStationRoad());
			plnJgxM.setCic(plnZgPln.getCic());
			if (plnJgxS.getSic() == null || plnJgxS.getSic().equals("")) {
				plnJgxM.setSic(plnJgxS.getSic());
			} else {
				plnJgxM.setSic(plnJgxS.getSic().split(",")[0]);
			}
			if (plnJgxS.getDic() == null || plnJgxS.getDic().equals("")) {
				plnJgxM.setDic(plnJgxS.getDic());
			} else {
				plnJgxM.setDic(plnJgxS.getDic().split(",")[0]);
			}
			if (plnJgxS.getPic() == null || plnJgxS.getPic().equals("")) {
				plnJgxM.setPic(plnJgxS.getPic());
			} else {
				plnJgxM.setPic(plnJgxS.getPic().split(",")[0]);
			}
			if (plnJgxS.getWic() == null || plnJgxS.getWic().equals("")) {
				plnJgxM.setWic(plnJgxS.getWic());
			} else {
				plnJgxM.setWic(plnJgxS.getWic().split(",")[0]);
			}
			plnJgxM.setCraftFileMan(plnJgxS.getCraftFileMan());
			plnJgxM.setCraftFileNo(plnJgxS.getCraftFileNo());
			plnJgxM.setCraftSeq(plnJgxS.getCraftSeq());
			plnJgxM.setSecCraftFileNo(plnZgPln.getSecCraftFileNo());
			plnJgxM.setOutdiameterIn(plnZgPln.getOutdiameterIn());
			plnJgxM.setWallthickIn(plnZgPln.getWallthickIn());
			plnJgxM.setLengthIn(plnZgPln.getLengthIn());
			plnJgxM.setLengthmaxIn(plnZgPln.getLengthmaxIn());
			plnJgxM.setLengthminIn(plnZgPln.getLengthminIn());
			plnJgxM.setOutdiameter(plnJgxS.getOutdiameter());
			plnJgxM.setWallthick(plnJgxS.getWallthick());
			// 查询合同最大最小长度
			double lenMax = 0;
			double lenMin = 0;
			String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
			ps = con.prepareStatement(ordLen);
			ps.setObject(1, plnJgxS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();
			plnJgxM.setLengthmax(String.valueOf(lenMax));
			plnJgxM.setLengthmin(String.valueOf(lenMin));
			int outnumCut = 1;
			if ((plnZgPln.getLengthminIn() != null 
					| !plnZgPln.getLengthminIn().equals("")) && lenMin > 0) {
				outnumCut = (int) (Double
						.parseDouble(plnZgPln.getLengthminIn()) / lenMin);
			}
			if (outnumCut <= 0) {
				outnumCut = 1;
			}
			plnJgxM.setOutnumCut(String.valueOf(outnumCut));
			plnJgxM.setPlnOutsingleNum(String.valueOf(oldNum * outnumCut));
			double burnoutRate = 0;
			// 查询产线烧损
			String sqlRate = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
					+ plnJgxS.getPlineCode() + "'";
			ps = con.prepareStatement(sqlRate);
			rs = ps.executeQuery();
			if (rs.next()) {
				burnoutRate = rs.getDouble("BURNOUT_RATE");
			}
			rs.close();
			ps.close();
			double yjWt = oldWt - oldWt * burnoutRate;
			plnJgxM.setPlnOutsingleW(String.valueOf(yjWt));

			plnJgxM.setCreateName(createName);
			plnJgxM.setCreateTime(createTime);
			plnJgxM.setIndexSeq(plnJgxS.getIndexSeq());
			plnJgxM.setSpecCode(plnZgPln.getSpecCode());
			plnJgxM.setSpecName(plnZgPln.getSpecName());
			plnJgxM.setStdCode(plnZgPln.getStdCode());
			plnJgxM.setStdName(plnZgPln.getStdName());
			plnJgxM.setStdStyle(plnZgPln.getStdStyle());
			plnJgxM.setStdStyleDesc(plnZgPln.getStdStyleDesc());
			plnJgxM.setDeliveryStateCode(delievStateCode);
			plnJgxM.setDeliveryStateName(delievStateName);
			if (fl == 0) {
				// 订单内炉顺序号
				int lotNo = getMaxLotNoSqe(con, plnJgxM.getProPlanId(),
						plnJgxM.getGxPlanNo(), "G");
				plnJgxM.setLotNoSqe(String.valueOf(lotNo));
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnJgxM.getProPlanId(),
						plnJgxM.getProPlanId(), "G");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnJgxM.getPlineCode(), "G");
				plnJgxM.setHeatPlanNo(heatPlanNo);
				plnJgxM.setGxProSeq(String.valueOf(gxProSeq));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyJgx"),
						plnJgxM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();

				// 新增生产批号
				StoveHelper.updatePlnJgxGroup(con, plnJgxM.getProPlanId(),
						plnJgxM.getGxPlanNo(), plnJgxM.getPic());
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_JGX_M T"
						+ " SET T.PLN_INSINGLE_NUM  = TO_NUMBER(T.PLN_INSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_INSINGLE_WT   = TO_NUMBER(T.PLN_INSINGLE_WT) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_NUM = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_W   = TO_NUMBER(T.PLN_OUTSINGLE_W) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1, oldNum);
				ps.setObject(2, oldWt);
				ps.setObject(3, oldNum);
				ps.setObject(4, yjWt);
				ps.setObject(5, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
			// 更新订单虚拟挂料量
			// String update =
			// "UPDATE PLN_ORDER_JGX_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))+TO_NUMBER(?),"
			// +
			// "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))+TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
			// ps = con.prepareStatement(update);
			// ps.setObject(1, oldNum);
			// ps.setObject(2, oldWt);
			// ps.setObject(3, plnJgxS.getProPlanId());
			// ps.setObject(4, plnJgxS.getGxPlanNo());
			// ps.executeUpdate();
			// ps.close();
		}
		return true;
	}

	/**
	 * 新增加工线虚拟炉计划(自炼加工线炉计划下发)备料需求短节
	 * 
	 * @return
	 */
	public boolean addPlnZyJgxMG(Connection con, PlnZyJgxMEntity plnZgPln,
			List<PlnOrderJgxSEntity> plnJgx, String createName,
			String createTime) throws SQLException {
		PlnZyJgxMEntity plnJgxM = new PlnZyJgxMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 单倍支
		int zgNum = Integer.parseInt(plnZgPln.getPlnInsingleNum());
		double totWeightM = Double.parseDouble(plnZgPln.getPlnInsingleWt());
		int contZgM = 0;
		int countZg = plnJgx.size();
		for (PlnOrderJgxSEntity plnJgxS : plnJgx) {
			// int cutNum = Integer.parseInt(plnJgxS.getOutnumCut());
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnJgxS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnJgxS.getProPlanId() + "/"
							+ plnJgxS.getGxPlanNo());
				} else {
					String message = plnJgxS.getProPlanId() + "/"
							+ plnJgxS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				continue;
			}
			double wtIn = 0;// 已生成炉计划原料吨(已装炉)
			// int numIn = 0;
			// 查询当前镦拔扩订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLN_INSINGLE_NUM),0) PLN_INSINGLE_NUM,NVL(SUM(T.PLN_INSINGLE_WT),0) PLN_INSINGLE_WT FROM PLN_ZY_JGX_M T " +
					" WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?    AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgxS.getProPlanId());
			ps.setObject(2, plnJgxS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLN_INSINGLE_WT");
				// numIn = rs.getInt("PLN_INSINGLE_NUM");
			}
			rs.close();
			ps.close();
			sql = "SELECT NVL(SUM(T.PLAN_INDOUBLE_WT),0) PLAN_INDOUBLE_WT FROM PLN_ZY_JGX_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgxS.getProPlanId());
			ps.setObject(2, plnJgxS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("PLAN_INDOUBLE_WT");
			}
			rs.close();
			ps.close();

			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1,
					plnJgxS.getProPlanId() + "/" + plnJgxS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getJudgeStoveNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnJgxS.getWeigthS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnJgxS.getWeigthS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnJgxM.setZyBatchIdZg(plnZgPln.getZyBatchIdZg());
			plnJgxM.setDecision(plnJgxS.getDecision());
			plnJgxM.setStoveNo(plnZgPln.getStoveNo());
			plnJgxM.setJudgeStoveNo(plnZgPln.getJudgeStoveNo());
			plnJgxM.setFeedHeatNo(plnZgPln.getJudgeStoveNo());
			plnJgxM.setFlagStoveNo(plnZgPln.getJudgeStoveNo());
			plnJgxM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnJgxM.setPlanstatus("00");
			plnJgxM.setUpperProcessCode("G");
			plnJgxM.setPlineCode(plnJgxS.getPlineCode());
			plnJgxM.setPlineName(plnJgxS.getPlineName());
			plnJgxM.setProcessCodeC(plnJgxS.getProcessCodeC());
			plnJgxM.setProcessDescC(plnJgxS.getProcessDescC());
			// 通过制程判定加工线是否末工序
			// if (plnJgxS.getWholeBacklogDesc().contains("接箍")) {
			// plnJgxM.setNextProcessCode("H");
			// plnJgxM.setIsendgx("0");
			// } else {
			// 末工序获取去向
			plnJgxM.setNextProcessCode("");
			plnJgxM.setIsendgx("1");
			// }
			// String gowWhere = getPlineCodeGroup(con, plnJgxS.getPlineCode(),
			// plnJgxS.getProPlanId(), plnJgxS.getGxPlanNo(), "G");
			// if (gowWhere != null) {
			// // 查询去向
			// String sqlGroup =
			// "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
			// ps = con.prepareStatement(sqlGroup);
			// ps.setObject(1, plnJgxS.getPlineCode());
			// ps.setObject(2, gowWhere);
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnJgxM.setGowhereName(rs.getString("STORAGE_NAME"));
			// plnJgxM.setGowhereCode(rs.getString("STORAGE_NO"));
			// }
			// rs.close();
			// ps.close();
			// }
			plnJgxM.setIfMatchOdd("0");
			plnJgxM.setIfDoHeatPlan("0");
			plnJgxM.setProPlanId(plnJgxS.getProPlanId());
			plnJgxM.setGxPlanNo(plnJgxS.getGxPlanNo());
			plnJgxM.setGradecode(plnZgPln.getGradecode());
			plnJgxM.setGradename(plnZgPln.getGradename());
			plnJgxM.setSteelcode(plnZgPln.getSteelcode());
			plnJgxM.setSteelname(plnZgPln.getSteelname());
			plnJgxM.setProduccode(plnZgPln.getProduccode());
			plnJgxM.setProducname(plnZgPln.getProducname());
			plnJgxM.setProdStandard(plnZgPln.getProdStandard());
			plnJgxM.setOutputStandard(plnZgPln.getOutputStandard());
			// 通过BOM查询投入产出
			String[] bomMat=null;
			if(plnJgxS.getWholeBacklog().equals("G")){
				bomMat= PlanFurnProduction.getQueryBomJgx(con,
						plnJgxS.getOrdLnDlyPk(),plnZgPln.getOutwlId());
			}else{
			 bomMat= PlanFurnProduction.getQueryBom(con,
					plnJgxS.getBom(), plnJgxS.getIndexSeq(),
					plnJgxS.getOrdLnDlyPk(), "G",plnZgPln.getGradecode());
			}
			plnJgxM.setInwlId(bomMat[0]);
			plnJgxM.setInwlDesc(bomMat[1]);
			plnJgxM.setOutwlId(bomMat[2]);
			plnJgxM.setOutwlDesc(bomMat[3]);
			plnJgxM.setBom(bomMat[4]);
			plnJgxM.setModelCode(plnZgPln.getModelCode());
			plnJgxM.setModelDesc(plnZgPln.getModelDesc());
			// 单倍支吨
			plnJgxM.setPlnInsingleNum(String.valueOf(oldNum));
			plnJgxM.setPlnInsingleWt(String.valueOf(oldWt));

			// // 倍尺支吨
			// int plnIndoubNum = 0;
			// double plnIndoubWt = 0;
			// String sqlCl =
			// "SELECT SUM(NVL(T.PLAN_INDOUBLE_NUM,0)) PLAN_INDOUBLE_NUM,SUM(NVL(T.PLAN_INDOUBLE_WT,0)) PLAN_INDOUBLE_WT FROM PLN_ZY_ZG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			// ps = con.prepareStatement(sqlCl);
			// ps.setObject(1, plnZgPln.getProPlanId());
			// ps.setObject(2, plnZgPln.getGxPlanNo());
			// ps.setObject(3, plnZgPln.getJudgeStoveNo());
			// rs = ps.executeQuery();
			// if (rs.next()) {
			// plnIndoubWt = rs.getDouble("PLAN_INDOUBLE_WT");
			// plnIndoubNum = rs.getInt("PLAN_INDOUBLE_NUM");
			// }
			// rs.close();
			// ps.close();
			// plnJgxM.setPlnIndoubleNum(String.valueOf(plnIndoubNum));
			// plnJgxM.setPlnIndoubleWt(String.valueOf(plnIndoubWt));
			// plnJgxM.setPlnOutdoubleNum(String.valueOf(plnIndoubNum));
			// plnJgxM.setPlnOutdoubleW(String.valueOf(plnIndoubWt));

			plnJgxM.setOrderSource(plnJgxS.getOrderSource());
			plnJgxM.setOrderNo(plnJgxS.getOrderNo());
			plnJgxM.setOrderSeq(plnJgxS.getOrderSeq());
			plnJgxM.setDeliveryNo(plnJgxS.getDeliveryNo());
			plnJgxM.setOrdLnDlyPk(plnJgxS.getOrdLnDlyPk());
			plnJgxM.setReqBlId(plnJgxS.getReqBlId());
			plnJgxM.setIfExport(plnJgxS.getIfExport());
			plnJgxM.setPriority(plnJgxS.getPriority());
			plnJgxM.setPriorityMemo(plnJgxS.getPriorityMemo());
			plnJgxM.setProMonth(plnJgxS.getProMonth());
			plnJgxM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnJgxM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnJgxM.setIfMonitor(plnJgxS.getIfMonitorJgx());
			plnJgxM.setPrdcrNo(plnJgxS.getPrdcrNo());
			plnJgxM.setMonitorPoint(plnJgxS.getMonitorPoint());
			plnJgxM.setWholeBacklog(plnJgxS.getWholeBacklog());
			plnJgxM.setWholeBacklogDesc(plnJgxS.getWholeBacklogDesc());
			plnJgxM.setStationRoad(plnJgxS.getStationRoad());
			plnJgxM.setCic(plnZgPln.getCic());
			if (plnJgxS.getSic() == null || plnJgxS.getSic().equals("")) {
				plnJgxM.setSic(plnJgxS.getSic());
			} else {
				plnJgxM.setSic(plnJgxS.getSic().split(",")[0]);
			}
			if (plnJgxS.getDic() == null || plnJgxS.getDic().equals("")) {
				plnJgxM.setDic(plnJgxS.getDic());
			} else {
				plnJgxM.setDic(plnJgxS.getDic().split(",")[0]);
			}
			if (plnJgxS.getPic() == null || plnJgxS.getPic().equals("")) {
				plnJgxM.setPic(plnJgxS.getPic());
			} else {
				plnJgxM.setPic(plnJgxS.getPic().split(",")[0]);
			}
			if (plnJgxS.getWic() == null || plnJgxS.getWic().equals("")) {
				plnJgxM.setWic(plnJgxS.getWic());
			} else {
				plnJgxM.setWic(plnJgxS.getWic().split(",")[0]);
			}
			plnJgxM.setCraftFileMan(plnJgxS.getCraftFileMan());
			plnJgxM.setCraftFileNo(plnJgxS.getCraftFileNo());
			plnJgxM.setCraftSeq(plnJgxS.getCraftSeq());
			plnJgxM.setSecCraftFileNo(plnZgPln.getSecCraftFileNo());
			plnJgxM.setOutdiameterIn(plnZgPln.getOutdiameterIn());
			plnJgxM.setWallthickIn(plnZgPln.getWallthickIn());
			plnJgxM.setLengthIn(plnZgPln.getLengthIn());
			plnJgxM.setLengthmaxIn(plnZgPln.getLengthmaxIn());
			plnJgxM.setLengthminIn(plnZgPln.getLengthminIn());
			plnJgxM.setOutdiameter(plnJgxS.getOutdiameter());
			plnJgxM.setWallthick(plnJgxS.getWallthick());
			// 查询合同最大最小长度
			double lenMax = 0;
			double lenMin = 0;
			String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
			ps = con.prepareStatement(ordLen);
			ps.setObject(1, plnJgxS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();
			plnJgxM.setLengthmax(String.valueOf(lenMax));
			plnJgxM.setLengthmin(String.valueOf(lenMin));
			int outnumCut = 1;
			if (plnZgPln.getLengthminIn() != null
					| !plnZgPln.getLengthminIn().equals("")) {
				outnumCut = (int) (Double
						.parseDouble(plnZgPln.getLengthminIn()) / lenMin);
			}
			if (outnumCut <= 0) {
				outnumCut = 1;
			}
			plnJgxM.setOutnumCut(String.valueOf(outnumCut));
			plnJgxM.setPlnOutsingleNum(String.valueOf(oldNum * outnumCut));
			double burnoutRate = 0;
			// 查询产线烧损
			String sqlRate = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
					+ plnJgxS.getPlineCode() + "'";
			ps = con.prepareStatement(sqlRate);
			rs = ps.executeQuery();
			if (rs.next()) {
				burnoutRate = rs.getDouble("BURNOUT_RATE");
			}
			rs.close();
			ps.close();
			double yjWt = oldWt - oldWt * burnoutRate;
			plnJgxM.setPlnOutsingleW(String.valueOf(yjWt));

			plnJgxM.setCreateName(createName);
			plnJgxM.setCreateTime(createTime);
			plnJgxM.setIndexSeq(plnJgxS.getIndexSeq());
			plnJgxM.setSpecCode(plnZgPln.getSpecCode());
			plnJgxM.setSpecName(plnZgPln.getSpecName());
			plnJgxM.setStdCode(plnZgPln.getStdCode());
			plnJgxM.setStdName(plnZgPln.getStdName());
			plnJgxM.setStdStyle(plnZgPln.getStdStyle());
			plnJgxM.setStdStyleDesc(plnZgPln.getStdStyleDesc());
			if (fl == 0) {
				// 订单内炉顺序号
				int lotNo = getMaxLotNoSqe(con, plnJgxM.getProPlanId(),
						plnJgxM.getGxPlanNo(), "G");
				plnJgxM.setLotNoSqe(String.valueOf(lotNo));
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnJgxM.getProPlanId(),
						plnJgxM.getProPlanId(), "G");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnJgxM.getPlineCode(), "G");
				plnJgxM.setHeatPlanNo(heatPlanNo);
				plnJgxM.setGxProSeq(String.valueOf(gxProSeq));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyJgx"),
						plnJgxM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();

				// 新增生产批号
				StoveHelper.updatePlnJgxGroup(con, plnJgxM.getProPlanId(),
						plnJgxM.getGxPlanNo(), plnJgxM.getPic());
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_JGX_M T"
						+ " SET T.PLN_INSINGLE_NUM  = TO_NUMBER(T.PLN_INSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_INSINGLE_WT   = TO_NUMBER(T.PLN_INSINGLE_WT) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_NUM = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?),"
						+ "  T.PLN_OUTSINGLE_W   = TO_NUMBER(T.PLN_OUTSINGLE_W) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1, oldNum);
				ps.setObject(2, oldWt);
				ps.setObject(3, oldNum);
				ps.setObject(4, yjWt);
				ps.setObject(5, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
			// 更新订单虚拟挂料量
			// String update =
			// "UPDATE PLN_ORDER_JGX_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))+TO_NUMBER(?),"
			// +
			// "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))+TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
			// ps = con.prepareStatement(update);
			// ps.setObject(1, oldNum);
			// ps.setObject(2, oldWt);
			// ps.setObject(3, plnJgxS.getProPlanId());
			// ps.setObject(4, plnJgxS.getGxPlanNo());
			// ps.executeUpdate();
			// ps.close();
		}
		return true;
	}

	/**
	 * 新增镦拔扩,热处理，加工线实际炉计划
	 */
	public boolean addPlnZyC(Connection con, PlnZyDbkMEntity plnDbk,
			PlnZyRclMEntity plnRcl, PlnZyJgxMEntity plnJgx,
			PlnZyJgMEntity plnJg, String createName, String createTime,
			MatBcMEntityPln qcmGp, String processCode) throws SQLException {

		PreparedStatement ps = null;
		if (processCode.equals("E")) {
			PlnZyDbkCEntity plnDbkC = new PlnZyDbkCEntity();
			plnDbkC.setHeatPlanNo(plnDbk.getHeatPlanNo());
			plnDbkC.setJugdeApplyCode(qcmGp.getJugdeApplyCode());

			plnDbkC.setJudgeStoveNo(plnDbk.getJudgeStoveNo());
			plnDbkC.setFlagStoveNo(plnDbk.getJudgeStoveNo());
			plnDbkC.setBatchNo(qcmGp.getBatchNo());
			plnDbkC.setBatchGroudNo(qcmGp.getBatchGroudNo());
			if (plnDbk.getPlanstatus().equals("00")) {
				plnDbkC.setZyBatchId("");
			} else {
				plnDbkC.setZyBatchId(plnDbk.getZyBatchId());
			}
			plnDbkC.setFeedHeatNo(plnDbk.getFeedHeatNo());

			plnDbkC.setStoveNo(plnDbk.getStoveNo());
			plnDbkC.setProPlanId(plnDbk.getProPlanId());
			plnDbkC.setGxPlanNo(plnDbk.getGxPlanNo());
			plnDbkC.setPlineCode(plnDbk.getPlineCode());
			plnDbkC.setPlineName(plnDbk.getPlineName());
			plnDbkC.setOutdiameterIn(plnDbk.getOutdiameterIn());
			plnDbkC.setWallthickIn(plnDbk.getWallthickIn());
			plnDbkC.setLengthIn(plnDbk.getLengthIn());
			plnDbkC.setLengthmaxIn(plnDbk.getLengthmaxIn());
			plnDbkC.setLengthminIn(plnDbk.getLengthminIn());
			plnDbkC.setPlanIndoubleNum(qcmGp.getActCount());
//			if (qcmGp.getActWeight().equals("0")) {
//				plnDbkC.setPlanIndoubleWt(qcmGp.getActTheoryWeight());
//			} else {
				plnDbkC.setPlanIndoubleWt(qcmGp.getActWeight());
			//}
			// 获取炉计划顺序号
			String heatPlanSqe = getHeatPlanSeq(con, plnDbk.getHeatPlanNo(),
					"E");
			plnDbkC.setHeatPlanSqe(heatPlanSqe);
			plnDbkC.setOutnumCut(plnDbk.getOutnumCut());
			// 新增
			String addPlnGxZg = EntityTool
					.fillSqlByEntity(CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.addPlnZyDbkC"), plnDbkC);
			ps = con.prepareStatement(addPlnGxZg);
			ps.executeUpdate();
			ps.close();
			// 修改虚拟炉计划状态
			String update = "UPDATE PLN_ZY_DBK_M T SET T.IF_DO_HEAT_PLAN='1'WHERE T.HEAT_PLAN_NO=?";
			ps = con.prepareStatement(update);
			ps.setObject(1, plnDbkC.getHeatPlanNo());
			ps.executeUpdate();
			ps.close();
		} else if (processCode.equals("F")) {
			PlnZyRclCEntity plnRclC = new PlnZyRclCEntity();
			plnRclC.setHeatPlanNo(plnRcl.getHeatPlanNo());
			plnRclC.setJugdeApplyCode(qcmGp.getJugdeApplyCode());
			plnRclC.setJudgeStoveNo(plnRcl.getJudgeStoveNo());
			plnRclC.setFlagStoveNo(plnRcl.getFlagStoveNo());
			plnRclC.setBatchNo(qcmGp.getBatchNo());
			plnRclC.setBatchGroudNo(qcmGp.getBatchGroudNo());
			if (plnRcl.getPlanstatus().equals("00")) {
				plnRclC.setZyBatchId("");
			} else {
				plnRclC.setZyBatchId(plnRcl.getZyBatchId());
			}
			plnRclC.setStoveNo(plnRcl.getStoveNo());
			plnRclC.setFeedHeatNo(plnRcl.getFeedHeatNo());

			plnRclC.setProPlanId(plnRcl.getProPlanId());
			plnRclC.setGxPlanNo(plnRcl.getGxPlanNo());
			plnRclC.setPlineCode(plnRcl.getPlineCode());
			plnRclC.setPlineName(plnRcl.getPlineName());
			plnRclC.setOutdiameterIn(plnRcl.getOutdiameterIn());
			plnRclC.setWallthickIn(plnRcl.getWallthickIn());
			plnRclC.setLengthIn(plnRcl.getLengthIn());
			plnRclC.setLengthmaxIn(plnRcl.getLengthmaxIn());
			plnRclC.setLengthminIn(plnRcl.getLengthminIn());
			plnRclC.setPlanIndoubleNum(qcmGp.getActCount());
//			if (qcmGp.getActWeight().equals("0")) {
//				plnRclC.setPlanIndoubleWt(qcmGp.getActTheoryWeight());
//			} else {
				plnRclC.setPlanIndoubleWt(qcmGp.getActWeight());
			//}
			// 获取炉计划顺序号
			String heatPlanSqe = getHeatPlanSeq(con, plnRcl.getHeatPlanNo(),
					"F");
			plnRclC.setHeatPlanSqe(heatPlanSqe);
			// 新增
			String addPlnGxZg = EntityTool
					.fillSqlByEntity(CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.addPlnZyRclC"), plnRclC);
			ps = con.prepareStatement(addPlnGxZg);
			ps.executeUpdate();
			ps.close();
			// 修改虚拟炉计划状态
			String update = "UPDATE PLN_ZY_RCL_M T SET T.IF_DO_HEAT_PLAN='1' ,T.JUDGE_STOVE_NO = '"+plnRclC.getJudgeStoveNo()+"',T.FLAG_STOVE_NO = '"+plnRclC.getJudgeStoveNo()+"'WHERE T.HEAT_PLAN_NO=?";
			ps = con.prepareStatement(update);
			ps.setObject(1, plnRcl.getHeatPlanNo());
			ps.executeUpdate();
			ps.close();
		} else if (processCode.equals("G")) {
			PlnZyJgxCEntity plnJgxC = new PlnZyJgxCEntity();
			plnJgxC.setHeatPlanNo(plnJgx.getHeatPlanNo());
			plnJgxC.setJugdeApplyCode(qcmGp.getJugdeApplyCode());

			plnJgxC.setJudgeStoveNo(plnJgx.getJudgeStoveNo());
			plnJgxC.setFlagStoveNo(plnJgx.getJudgeStoveNo());
			plnJgxC.setBatchNo(qcmGp.getBatchNo());
			plnJgxC.setBatchGroudNo(qcmGp.getBatchGroudNo());
			if (plnJgx.getPlanstatus().equals("00")) {
				plnJgxC.setZyBatchId("");
			} else {
				plnJgxC.setZyBatchId(plnJgx.getZyBatchId());
			}
			plnJgxC.setFeedHeatNo(plnJgx.getFeedHeatNo());

			plnJgxC.setStoveNo(plnJgx.getStoveNo());
			plnJgxC.setProPlanId(plnJgx.getProPlanId());
			plnJgxC.setGxPlanNo(plnJgx.getGxPlanNo());
			plnJgxC.setPlineCode(plnJgx.getPlineCode());
			plnJgxC.setPlineName(plnJgx.getPlineName());
			plnJgxC.setOutdiameterIn(plnJgx.getOutdiameterIn());
			plnJgxC.setWallthickIn(plnJgx.getWallthickIn());
			plnJgxC.setOutnumCut(plnJgx.getOutnumCut());
			plnJgxC.setLengthIn(plnJgx.getLengthIn());
			plnJgxC.setLengthmaxIn(plnJgx.getLengthmaxIn());
			plnJgxC.setLengthminIn(plnJgx.getLengthminIn());
			plnJgxC.setPlanIndoubleNum(qcmGp.getActCount());
//			if (qcmGp.getActWeight().equals("0")) {
//				plnJgxC.setPlanIndoubleWt(qcmGp.getActTheoryWeight());
//			} else {
				plnJgxC.setPlanIndoubleWt(qcmGp.getActWeight());
			//}
			// 获取炉计划顺序号
			String heatPlanSqe = getHeatPlanSeq(con, plnJgx.getHeatPlanNo(),
					"G");
			plnJgxC.setHeatPlanSqe(heatPlanSqe);
			// 新增
			String addPlnGxZg = EntityTool
					.fillSqlByEntity(CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.addPlnZyJgxC"), plnJgxC);
			ps = con.prepareStatement(addPlnGxZg);
			ps.executeUpdate();
			ps.close();
			// 修改虚拟炉计划状态
			String update = "UPDATE PLN_ZY_JGX_M T SET T.IF_DO_HEAT_PLAN='1',T.JUDGE_STOVE_NO = '"+plnJgxC.getJudgeStoveNo()+"',T.FLAG_STOVE_NO = '"+plnJgxC.getJudgeStoveNo()+"' WHERE T.HEAT_PLAN_NO=?";
			ps = con.prepareStatement(update);
			ps.setObject(1, plnJgx.getHeatPlanNo());
			ps.executeUpdate();
			ps.close();
		} else if (processCode.equals("H")) {
			PlnZyJgCEntity plnJgC = new PlnZyJgCEntity();
			plnJgC.setHeatPlanNo(plnJg.getHeatPlanNo());
			plnJgC.setJugdeApplyCode(qcmGp.getJugdeApplyCode());
			if(qcmGp.getPlineCode().equals("C072")||qcmGp.getPlineCode().equals("C091"))
			{
				plnJgC.setJudgeStoveNo("");
			}else
			{
				plnJgC.setJudgeStoveNo(qcmGp.getJudgeStoveNo());
			}

			plnJgC.setBatchNo(qcmGp.getBatchNo());
			plnJgC.setBatchGroudNo(qcmGp.getBatchGroudNo());
			// if (plnJg.getPlanstatus().equals("00")) {
			// plnJgC.setZyBatchId("");
			// } else {
			// plnJgC.setZyBatchId(plnJg.getZyBatchId());
			// }
			plnJgC.setFeedHeatNo(plnJg.getFeedHeatNo());
			plnJgC.setFlagStoveNo(plnJg.getJudgeStoveNo());
			plnJgC.setStoveNo(plnJg.getStoveNo());
			plnJgC.setProPlanId(plnJg.getProPlanId());
			plnJgC.setGxPlanNo(plnJg.getGxPlanNo());
			plnJgC.setPlineCode(plnJg.getPlineCode());
			plnJgC.setPlineName(plnJg.getPlineName());
			plnJgC.setUseBlNum(qcmGp.getActCount());
//			if (qcmGp.getActWeight().equals("0")) {
//				plnJgC.setUseBlWt(qcmGp.getActTheoryWeight());
//			} else {
				plnJgC.setUseBlWt(qcmGp.getActWeight());
			//}
			// 获取炉计划顺序号
			String heatPlanSqe = getHeatPlanSeq(con, plnJg.getHeatPlanNo(), "H");
			plnJgC.setHeatPlanSqe(heatPlanSqe);
			// 新增
			String addPlnGxZg = EntityTool.fillSqlByEntity(
					CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.addPlnZyJgC"), plnJgC);
			ps = con.prepareStatement(addPlnGxZg);
			ps.executeUpdate();
			ps.close();
			// 修改虚拟炉计划状态
			String update = "UPDATE PLN_ZY_JG_M T SET T.IF_DO_HEAT_PLAN='1',T.JUDGE_STOVE_NO = '"+plnJgC.getJudgeStoveNo()+"' WHERE T.HEAT_PLAN_NO=?";
			ps = con.prepareStatement(update);
			ps.setObject(1, plnJg.getHeatPlanNo());
			ps.executeUpdate();
			ps.close();
		}

		// // 修改虚拟炉计划量
		// String sqlUpdate = CoreXmlSqlParsersFactory
		// .getSql("ComPlanFurnace.updatePlnZgM");
		// ps = con.prepareStatement(sqlUpdate);
		// ps.executeUpdate();
		// ps.close();

		return true;
	}

	/**
	 * 新增接箍虚拟炉计划(自炼轧管炉计划下发)
	 * 
	 * @return
	 */
	public boolean addPlnZyJgZME(Connection con, PlnZyZgMEntity plnZgPln,
			List<PlnGxJgPropSEntity> plnJg, String createName, String createTime)
			throws SQLException {
		PlnZyJgMEntity plnJgM = new PlnZyJgMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 排产支
		int cutNum = Integer.parseInt(plnZgPln.getOutnumCut());
		int zgNum = Integer.parseInt(plnZgPln.getPlnOutsingleNum());
		double totWeightM = Double.parseDouble(plnZgPln.getPlnOutsingleW());
		int contZgM = 0;
		int countZg = plnJg.size();
		for (PlnGxJgPropSEntity plnJgS : plnJg) {
			// int cutNum = Integer.parseInt(plnJgS.getOutnumCut());
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnJgS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnJgS.getProPlanId() + "/"
							+ plnJgS.getGxPlanNo());
				} else {
					String message = plnJgS.getProPlanId() + "/"
							+ plnJgS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				continue;
			}
			double wtIn = 0;// 已生成炉计划计划吨
			// int numIn = 0;
			// 查询当前订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLAN_BL_NUM),0) PLAN_BL_NUM,NVL(SUM(T.PLAN_BL_WT),0) PLAN_BL_WT FROM PLN_ZY_JG_M T "
					+ " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId());
			ps.setObject(2, plnJgS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLAN_BL_WT");
				// numIn = rs.getInt("PLAN_BL_NUM");
			}
			rs.close();
			ps.close();

			sql = "SELECT NVL(SUM(T.USE_BL_WT),0) USE_BL_WT FROM PLN_ZY_JG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId());
			ps.setObject(2, plnJgS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("USE_BL_WT");
			}
			rs.close();
			ps.close();
			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_JG_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId() + "/" + plnJgS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getFeedHeatNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnJgS.getGroupBlWtS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnJgS.getGroupBlWtS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnJgM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnJgM.setStoveNo(plnZgPln.getStoveNo());
			plnJgM.setFeedHeatNo(plnZgPln.getJudgeStoveNo());
			if(plnZgPln.getPlineCode().equals("C072"))//天淮轧制，接箍不在天淮
			{
				plnJgM.setJudgeStoveNo("");
				plnJgM.setFlagStoveNo("");
			}else
			{
				plnJgM.setJudgeStoveNo(plnZgPln.getJudgeStoveNo());
				plnJgM.setFlagStoveNo(plnZgPln.getJudgeStoveNo());
			}

			plnJgM.setPlanstatus("00");
			plnJgM.setPlineCode(plnJgS.getPlineCode());
			plnJgM.setPlineName(plnJgS.getPlineName());
			plnJgM.setIfMatchOdd("0");
			plnJgM.setIfDoHeatPlan("0");
			plnJgM.setUpperProcessCode("D");
			plnJgM.setProPlanId(plnJgS.getProPlanId());
			plnJgM.setGxPlanNo(plnJgS.getGxPlanNo());
			plnJgM.setJgGroupId(plnJgS.getJgGroupId());
			plnJgM.setCodeJg(plnJgS.getCodeJg());
			plnJgM.setMinD(plnJgS.getMinD());
			plnJgM.setMinH(plnJgS.getMinH());
			plnJgM.setAimCutLen(plnJgS.getAimCutLen());
			plnJgM.setAimlengthBl(plnJgS.getAimlengthBl());
			plnJgM.setGradecode(plnZgPln.getGradecode());
			plnJgM.setGradename(plnZgPln.getGradename());
			plnJgM.setSteelcode(plnJgS.getSteelcode());
			plnJgM.setSteelname(plnJgS.getSteelname());
			plnJgM.setProdStandard(plnZgPln.getProdStandard());
			plnJgM.setOutputStandard(plnZgPln.getOutputStandard());
			plnJgM.setBlWlId(plnJgS.getBlWlId());
			plnJgM.setBlWlDesc(plnJgS.getBlWlDesc());
			plnJgM.setOutwlId(plnJgS.getOutwlId());
			plnJgM.setOutwlDesc(plnJgS.getOutwlDesc());
			plnJgM.setModelCode(plnJgS.getModelCode());
			plnJgM.setModelDesc(plnJgS.getModelDesc());
			plnJgM.setLengthMax(plnJgS.getLengthMax());
			plnJgM.setLengthMin(plnJgS.getLengthMin());
			plnJgM.setTaper(plnJgS.getTaper());
			plnJgM.setCodeJgBl(plnJgS.getCodeJgBl());
			plnJgM.setSpecJg(plnJgS.getSpecJg());
			plnJgM.setSpecJgDesc(plnJgS.getSpecJgDesc());
			plnJgM.setSingleCutNun(plnJgS.getSingleCutNun());
			// 查询接箍信息
			String sqlCodeJg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryCodeJg");
			ps = con.prepareStatement(sqlCodeJg);
			ps.setObject(1, plnJgS.getCodeJg());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnJgM.setOutdiameter(rs.getString("DIAMETER_JG"));
				plnJgM.setWallthick(rs.getString("HEIGHT_JG"));
				plnJgM.setStyleJg(rs.getString("STYLE_JG"));
				plnJgM.setDiameter(rs.getString("DIAMETER"));
				plnJgM.setCheckJVal(rs.getString("CHECK_J_VAL"));
				plnJgM.setSingleweight(rs.getString("WEIGHT_JG"));
				plnJgM.setAimlength(rs.getString("LENGTH_JG"));
				plnJgM.setProduccodeJg(rs.getString("PRODUCCODE_JG"));
				plnJgM.setProduccodeJgDesc(rs.getString("PRODUCCODE_JG_DESC"));
				plnJgM.setStdCode(rs.getString("STD_CODE"));
				plnJgM.setStdName(rs.getString("STD_NAME"));
				plnJgM.setStdStyle(rs.getString("STD_STYLE"));
				plnJgM.setStdStyleDesc(rs.getString("STD_STYLE_DESC"));
			}
			rs.close();
			ps.close();
			plnJgM.setDemandCopper(plnJgS.getDemandCopper());
			// 计划支吨
			plnJgM.setPlanJgNum(String.valueOf(oldNum
					* Integer.parseInt(plnJgS.getSingleCutNun())));
			plnJgM.setPlanBlNum(String.valueOf(oldNum));
			plnJgM.setPlanBlWt(String.valueOf(oldWt));

			plnJgM.setOrdLnDlyPk(plnJgS.getOrdLnDlyPk());
			plnJgM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnJgM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnJgM.setPrdcrNo(plnJgS.getPrdcrNo());
			plnJgM.setCraftFileNo(plnJgS.getCraftFileNo());
			plnJgM.setCraftSeq(plnJgS.getCraftSeq());

			plnJgM.setCreateName(createName);
			plnJgM.setCreateTime(createTime);

			if (!plnJgS.getIfMonitorJg().equals("")) {
				plnJgM.setMonitordemand("接箍监制。");
				plnJgM.setIfMonitorJg("1");
			} else if (!plnJgS.getIfMonitorBl().equals("")) {
				plnJgM.setMonitordemand("接箍料监制。");
				plnJgM.setIfMonitorJg("1");
			} else if (!plnJgS.getIfMonitorBl().equals("")
					&& !plnJgS.getIfMonitorJg().equals("")) {
				plnJgM.setMonitordemand("接箍、接箍料监制。");
				plnJgM.setIfMonitorJg("1");
			} else {
				plnJgM.setMonitordemand("");
				plnJgM.setIfMonitorJg("0");
			}
			if (fl == 0) {
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnJgM.getProPlanId(),
						plnJgM.getProPlanId(), "H");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnJgM.getPlineCode(), "H");
				plnJgM.setHeatPlanNo(heatPlanNo);
				plnJgM.setGxProSeq(String.valueOf(gxProSeq));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyJg"),
						plnJgM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_JGX_M T"
						+ " SET T.PLAN_JG_NUM  = TO_NUMBER(T.PLAN_JG_NUM) + TO_NUMBER(?),"
						+ "  T.PLAN_BL_NUM   = TO_NUMBER(T.PLAN_BL_NUM) + TO_NUMBER(?),"
						+ "  T.PLAN_BL_WT = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1,
						oldNum * Integer.parseInt(plnJgS.getSingleCutNun()));
				ps.setObject(2, oldNum);
				ps.setObject(3, oldWt);
				ps.setObject(4, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
		}
		return true;
	}

	/**
	 * 新增接箍虚拟炉计划(自炼镦拔扩炉计划下发)
	 * 
	 * @return
	 */
	public boolean addPlnZyJgDME(Connection con, PlnZyDbkMEntity plnZgPln,
			List<PlnGxJgPropSEntity> plnJg, String createName, String createTime)
			throws SQLException {
		PlnZyJgMEntity plnJgM = new PlnZyJgMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 排产支
		int zgNum = Integer.parseInt(plnZgPln.getPlnOutsingleNum());
		double totWeightM = Double.parseDouble(plnZgPln.getPlnOutsingleW());
		int contZgM = 0;
		int countZg = plnJg.size();
		for (PlnGxJgPropSEntity plnJgS : plnJg) {
			// int cutNum = Integer.parseInt(plnJgS.getOutnumCut());
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnJgS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnJgS.getProPlanId() + "/"
							+ plnJgS.getGxPlanNo());
				} else {
					String message = plnJgS.getProPlanId() + "/"
							+ plnJgS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				continue;
			}
			double wtIn = 0;// 已生成炉计划计划吨
			// int numIn = 0;
			// 查询当前订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLAN_BL_NUM),0) PLAN_BL_NUM,NVL(SUM(T.PLAN_BL_WT),0) PLAN_BL_WT FROM PLN_ZY_JG_M T "
					+ " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?    AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId());
			ps.setObject(2, plnJgS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLAN_BL_WT");
				// numIn = rs.getInt("PLAN_BL_NUM");
			}
			rs.close();
			ps.close();
			sql = "SELECT NVL(SUM(T.USE_BL_WT),0) USE_BL_WT FROM PLN_ZY_JG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId());
			ps.setObject(2, plnJgS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("USE_BL_WT");
			}
			rs.close();
			ps.close();
			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_JG_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId() + "/" + plnJgS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getJudgeStoveNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnJgS.getGroupBlWtS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnJgS.getGroupBlWtS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnJgM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnJgM.setStoveNo(plnZgPln.getStoveNo());
			plnJgM.setJudgeStoveNo(plnZgPln.getJudgeStoveNo());
			plnJgM.setFlagStoveNo(plnZgPln.getJudgeStoveNo());
			plnJgM.setPlanstatus("00");
			plnJgM.setPlineCode(plnJgS.getPlineCode());
			plnJgM.setPlineName(plnJgS.getPlineName());
			plnJgM.setIfMatchOdd("0");
			plnJgM.setIfDoHeatPlan("0");
			plnJgM.setUpperProcessCode("E");
			plnJgM.setProPlanId(plnJgS.getProPlanId());
			plnJgM.setGxPlanNo(plnJgS.getGxPlanNo());
			plnJgM.setJgGroupId(plnJgS.getJgGroupId());
			plnJgM.setCodeJg(plnJgS.getCodeJg());
			plnJgM.setMinD(plnJgS.getMinD());
			plnJgM.setMinH(plnJgS.getMinH());
			plnJgM.setAimCutLen(plnJgS.getAimCutLen());
			plnJgM.setAimlengthBl(plnJgS.getAimlengthBl());
			plnJgM.setGradecode(plnZgPln.getGradecode());
			plnJgM.setGradename(plnZgPln.getGradename());
			plnJgM.setSteelcode(plnJgS.getSteelcode());
			plnJgM.setSteelname(plnJgS.getSteelname());
			plnJgM.setProdStandard(plnZgPln.getProdStandard());
			plnJgM.setOutputStandard(plnZgPln.getOutputStandard());
			plnJgM.setBlWlId(plnJgS.getBlWlId());
			plnJgM.setBlWlDesc(plnJgS.getBlWlDesc());
			plnJgM.setOutwlId(plnJgS.getOutwlId());
			plnJgM.setOutwlDesc(plnJgS.getOutwlDesc());
			plnJgM.setModelCode(plnJgS.getModelCode());
			plnJgM.setModelDesc(plnJgS.getModelDesc());
			plnJgM.setLengthMax(plnJgS.getLengthMax());
			plnJgM.setLengthMin(plnJgS.getLengthMin());
			plnJgM.setTaper(plnJgS.getTaper());
			plnJgM.setCodeJgBl(plnJgS.getCodeJgBl());
			plnJgM.setSpecJg(plnJgS.getSpecJg());
			plnJgM.setSpecJgDesc(plnJgS.getSpecJgDesc());
			plnJgM.setSingleCutNun(plnJgS.getSingleCutNun());
			// 查询接箍信息
			String sqlCodeJg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryCodeJg");
			ps = con.prepareStatement(sqlCodeJg);
			ps.setObject(1, plnJgS.getCodeJg());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnJgM.setOutdiameter(rs.getString("DIAMETER_JG"));
				plnJgM.setWallthick(rs.getString("HEIGHT_JG"));
				plnJgM.setStyleJg(rs.getString("STYLE_JG"));
				plnJgM.setDiameter(rs.getString("DIAMETER"));
				plnJgM.setCheckJVal(rs.getString("CHECK_J_VAL"));
				plnJgM.setSingleweight(rs.getString("WEIGHT_JG"));
				plnJgM.setAimlength(rs.getString("LENGTH_JG"));
				plnJgM.setProduccodeJg(rs.getString("PRODUCCODE_JG"));
				plnJgM.setProduccodeJgDesc(rs.getString("PRODUCCODE_JG_DESC"));
				plnJgM.setStdCode(rs.getString("STD_CODE"));
				plnJgM.setStdName(rs.getString("STD_NAME"));
				plnJgM.setStdStyle(rs.getString("STD_STYLE"));
				plnJgM.setStdStyleDesc(rs.getString("STD_STYLE_DESC"));
			}
			rs.close();
			ps.close();
			plnJgM.setDemandCopper(plnJgS.getDemandCopper());
			// 计划支吨
			plnJgM.setPlanJgNum(String.valueOf(oldNum
					* Integer.parseInt(plnJgS.getSingleCutNun())));
			plnJgM.setPlanBlNum(String.valueOf(oldNum));
			plnJgM.setPlanBlWt(String.valueOf(oldWt));

			plnJgM.setOrdLnDlyPk(plnJgS.getOrdLnDlyPk());
			plnJgM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnJgM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnJgM.setPrdcrNo(plnJgS.getPrdcrNo());
			plnJgM.setCraftFileNo(plnJgS.getCraftFileNo());
			plnJgM.setCraftSeq(plnJgS.getCraftSeq());

			plnJgM.setCreateName(createName);
			plnJgM.setCreateTime(createTime);

			if (!plnJgS.getIfMonitorJg().equals("")) {
				plnJgM.setMonitordemand("接箍监制。");
				plnJgM.setIfMonitorJg("1");
			} else if (!plnJgS.getIfMonitorBl().equals("")) {
				plnJgM.setMonitordemand("接箍料监制。");
				plnJgM.setIfMonitorJg("1");
			} else if (!plnJgS.getIfMonitorBl().equals("")
					&& !plnJgS.getIfMonitorJg().equals("")) {
				plnJgM.setMonitordemand("接箍、接箍料监制。");
				plnJgM.setIfMonitorJg("1");
			} else {
				plnJgM.setMonitordemand("");
				plnJgM.setIfMonitorJg("0");
			}
			if (fl == 0) {
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnJgM.getProPlanId(),
						plnJgM.getProPlanId(), "H");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnJgM.getPlineCode(), "H");
				plnJgM.setHeatPlanNo(heatPlanNo);
				plnJgM.setGxProSeq(String.valueOf(gxProSeq));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyJg"),
						plnJgM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_JGX_M T"
						+ " SET T.PLAN_JG_NUM  = TO_NUMBER(T.PLAN_JG_NUM) + TO_NUMBER(?),"
						+ "  T.PLAN_BL_NUM   = TO_NUMBER(T.PLAN_BL_NUM) + TO_NUMBER(?),"
						+ "  T.PLAN_BL_WT = TO_NUMBER(T.PLN_OUTSINGLE_NUM) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1,
						oldNum * Integer.parseInt(plnJgS.getSingleCutNun()));
				ps.setObject(2, oldNum);
				ps.setObject(3, oldWt);
				ps.setObject(4, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
		}
		return true;
	}

	/**
	 * 新增接箍虚拟炉计划(自炼热处理炉计划下发)
	 * 
	 * @return
	 */
	public boolean addPlnZyJgRME(Connection con, PlnZyRclMEntity plnZgPln,
			List<PlnGxJgPropSEntity> plnJg, String createName, String createTime)
			throws SQLException {
		PlnZyJgMEntity plnJgM = new PlnZyJgMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 排产支
		int zgNum = Integer.parseInt(plnZgPln.getPlnOutsingleNum());
		double totWeightM = Double.parseDouble(plnZgPln.getPlnOutsingleW());
		int contZgM = 0;
		int countZg = plnJg.size();
		for (PlnGxJgPropSEntity plnJgS : plnJg) {
			// int cutNum = Integer.parseInt(plnJgS.getOutnumCut());
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnJgS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnJgS.getProPlanId() + "/"
							+ plnJgS.getGxPlanNo());
				} else {
					String message = plnJgS.getProPlanId() + "/"
							+ plnJgS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				continue;
			}
			double wtIn = 0;// 已生成炉计划计划吨
			// int numIn = 0;
			// 查询当前订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLAN_BL_NUM),0) PLAN_BL_NUM,NVL(SUM(T.PLAN_BL_WT),0) PLAN_BL_WT FROM PLN_ZY_JG_M T "
					+ " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?    AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId());
			ps.setObject(2, plnJgS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLAN_BL_WT");
				// numIn = rs.getInt("PLAN_BL_NUM");
			}
			rs.close();
			ps.close();
			sql = "SELECT NVL(SUM(T.USE_BL_WT),0) USE_BL_WT FROM PLN_ZY_JG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId());
			ps.setObject(2, plnJgS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("USE_BL_WT");
			}
			rs.close();
			ps.close();
			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_JG_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId() + "/" + plnJgS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getJudgeStoveNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnJgS.getGroupBlWtS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnJgS.getGroupBlWtS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnJgM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnJgM.setStoveNo(plnZgPln.getStoveNo());
			plnJgM.setFeedHeatNo(plnZgPln.getJudgeStoveNo());
			if(plnZgPln.getPlineCode().equals("C091"))//天淮热处理
			{
				plnJgM.setJudgeStoveNo("");
				plnJgM.setFlagStoveNo("");
			}else
			{
				plnJgM.setJudgeStoveNo(plnZgPln.getJudgeStoveNo());
				plnJgM.setFlagStoveNo(plnZgPln.getJudgeStoveNo());
			}

			plnJgM.setPlanstatus("00");
			plnJgM.setPlineCode(plnJgS.getPlineCode());
			plnJgM.setPlineName(plnJgS.getPlineName());
			plnJgM.setIfMatchOdd("0");
			plnJgM.setIfDoHeatPlan("0");
			plnJgM.setUpperProcessCode("F");
			plnJgM.setProPlanId(plnJgS.getProPlanId());
			plnJgM.setGxPlanNo(plnJgS.getGxPlanNo());
			plnJgM.setJgGroupId(plnJgS.getJgGroupId());
			plnJgM.setCodeJg(plnJgS.getCodeJg());
			plnJgM.setMinD(plnJgS.getMinD());
			plnJgM.setMinH(plnJgS.getMinH());
			plnJgM.setAimCutLen(plnJgS.getAimCutLen());
			plnJgM.setAimlengthBl(plnJgS.getAimlengthBl());
			plnJgM.setGradecode(plnZgPln.getGradecode());
			plnJgM.setGradename(plnZgPln.getGradename());
			plnJgM.setSteelcode(plnJgS.getSteelcode());
			plnJgM.setSteelname(plnJgS.getSteelname());
			plnJgM.setProdStandard(plnZgPln.getProdStandard());
			plnJgM.setOutputStandard(plnZgPln.getOutputStandard());
			plnJgM.setBlWlId(plnJgS.getBlWlId());
			plnJgM.setBlWlDesc(plnJgS.getBlWlDesc());
			plnJgM.setOutwlId(plnJgS.getOutwlId());
			plnJgM.setOutwlDesc(plnJgS.getOutwlDesc());
			plnJgM.setModelCode(plnJgS.getModelCode());
			plnJgM.setModelDesc(plnJgS.getModelDesc());
			plnJgM.setLengthMax(plnJgS.getLengthMax());
			plnJgM.setLengthMin(plnJgS.getLengthMin());
			plnJgM.setTaper(plnJgS.getTaper());
			plnJgM.setCodeJgBl(plnJgS.getCodeJgBl());
			plnJgM.setSpecJg(plnJgS.getSpecJg());
			plnJgM.setSpecJgDesc(plnJgS.getSpecJgDesc());
			plnJgM.setSingleCutNun(plnJgS.getSingleCutNun());
			// 查询接箍信息
			String sqlCodeJg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryCodeJg");
			ps = con.prepareStatement(sqlCodeJg);
			ps.setObject(1, plnJgS.getCodeJg());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnJgM.setOutdiameter(rs.getString("DIAMETER_JG"));
				plnJgM.setWallthick(rs.getString("HEIGHT_JG"));
				plnJgM.setStyleJg(rs.getString("STYLE_JG"));
				plnJgM.setDiameter(rs.getString("DIAMETER"));
				plnJgM.setCheckJVal(rs.getString("CHECK_J_VAL"));
				plnJgM.setSingleweight(rs.getString("WEIGHT_JG"));
				plnJgM.setAimlength(rs.getString("LENGTH_JG"));
				plnJgM.setProduccodeJg(rs.getString("PRODUCCODE_JG"));
				plnJgM.setProduccodeJgDesc(rs.getString("PRODUCCODE_JG_DESC"));
				plnJgM.setStdCode(rs.getString("STD_CODE"));
				plnJgM.setStdName(rs.getString("STD_NAME"));
				plnJgM.setStdStyle(rs.getString("STD_STYLE"));
				plnJgM.setStdStyleDesc(rs.getString("STD_STYLE_DESC"));
			}
			rs.close();
			ps.close();
			plnJgM.setDemandCopper(plnJgS.getDemandCopper());
			// 计划支吨
			plnJgM.setPlanJgNum(String.valueOf(oldNum
					* Integer.parseInt(plnJgS.getSingleCutNun())));
			plnJgM.setPlanBlNum(String.valueOf(oldNum));
			plnJgM.setPlanBlWt(String.valueOf(oldWt));

			plnJgM.setOrdLnDlyPk(plnJgS.getOrdLnDlyPk());
			plnJgM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnJgM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnJgM.setPrdcrNo(plnJgS.getPrdcrNo());
			plnJgM.setCraftFileNo(plnJgS.getCraftFileNo());
			plnJgM.setCraftSeq(plnJgS.getCraftSeq());

			plnJgM.setCreateName(createName);
			plnJgM.setCreateTime(createTime);
			if (!plnJgS.getIfMonitorJg().equals("")) {
				plnJgM.setMonitordemand("接箍监制。");
				plnJgM.setIfMonitorJg("1");
			} else if (!plnJgS.getIfMonitorBl().equals("")) {
				plnJgM.setMonitordemand("接箍料监制。");
				plnJgM.setIfMonitorJg("1");
			} else if (!plnJgS.getIfMonitorBl().equals("")
					&& !plnJgS.getIfMonitorJg().equals("")) {
				plnJgM.setMonitordemand("接箍、接箍料监制。");
				plnJgM.setIfMonitorJg("1");
			} else {
				plnJgM.setMonitordemand("");
				plnJgM.setIfMonitorJg("0");
			}
			if (fl == 0) {
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnJgM.getProPlanId(),
						plnJgM.getProPlanId(), "H");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnJgM.getPlineCode(), "H");
				plnJgM.setHeatPlanNo(heatPlanNo);
				plnJgM.setGxProSeq(String.valueOf(gxProSeq));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyJg"),
						plnJgM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_JG_M T"
						+ " SET T.PLAN_JG_NUM  = TO_NUMBER(T.PLAN_JG_NUM) + TO_NUMBER(?),"
						+ "  T.PLAN_BL_NUM   = TO_NUMBER(T.PLAN_BL_NUM) + TO_NUMBER(?),"
						+ "  T.PLAN_BL_WT = TO_NUMBER(T.PLAN_BL_WT) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1,
						oldNum * Integer.parseInt(plnJgS.getSingleCutNun()));
				ps.setObject(2, oldNum);
				ps.setObject(3, oldWt);
				ps.setObject(4, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
		}
		return true;
	}

	/**
	 * 新增接箍虚拟炉计划(自炼加工线炉计划下发)
	 * 
	 * @return
	 */
	public boolean addPlnZyJgJRME(Connection con, PlnZyJgxMEntity plnZgPln,
			List<PlnGxJgPropSEntity> plnJg, String createName, String createTime)
			throws SQLException {
		PlnZyJgMEntity plnJgM = new PlnZyJgMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 排产支
		int cutNum = Integer.parseInt(plnZgPln.getOutnumCut());
		int zgNum = Integer.parseInt(plnZgPln.getPlnOutsingleNum()) * cutNum;
		double totWeightM = Double.parseDouble(plnZgPln.getPlnOutsingleW());
		int contZgM = 0;
		int countZg = plnJg.size();
		for (PlnGxJgPropSEntity plnJgS : plnJg) {
			// int cutNum = Integer.parseInt(plnJgS.getOutnumCut());
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnJgS.getExeStatus()) > 1) {
				if (getErrMessage().equals("")) {
					setErrMessage(plnJgS.getProPlanId() + "/"
							+ plnJgS.getGxPlanNo());
				} else {
					String message = plnJgS.getProPlanId() + "/"
							+ plnJgS.getGxPlanNo();
					if (!getErrMessage().contains(message)) {
						setErrMessage(getErrMessage() + "," + message);
					}
				}
				continue;
			}
			double wtIn = 0;// 已生成炉计划计划吨
			// int numIn = 0;
			// 查询当前订单是否存在炉计划
			sql = "SELECT NVL(SUM(T.PLAN_BL_NUM),0) PLAN_BL_NUM,NVL(SUM(T.PLAN_BL_WT),0) PLAN_BL_WT FROM PLN_ZY_JG_M T "
					+ " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?   AND T.IF_DO_HEAT_PLAN='0'  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId());
			ps.setObject(2, plnJgS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn = rs.getDouble("PLAN_BL_WT");
				// numIn = rs.getInt("PLAN_BL_NUM");
			}
			rs.close();
			ps.close();
			sql = "SELECT NVL(SUM(T.USE_BL_WT),0) USE_BL_WT FROM PLN_ZY_JG_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?  AND T.IF_FLAG='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId());
			ps.setObject(2, plnJgS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("USE_BL_WT");
			}
			rs.close();
			ps.close();
			int fl = 0;
			sql = "SELECT T.HEAT_PLAN_NO FROM PLN_ZY_JG_M T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnJgS.getProPlanId() + "/" + plnJgS.getGxPlanNo());
			ps.setObject(2, plnZgPln.getJudgeStoveNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				fl = 1;
				heatPlanNo = rs.getString("HEAT_PLAN_NO");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnJgS.getGroupBlWtS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					// oldWt = totWeightM;
					// oldNum = zgNum;
					oldWt = Double.parseDouble(plnJgS.getGroupBlWtS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
					if (oldNum > 0) {
						oldWt = totWeightM;
						oldNum = zgNum;
					}
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnJgM.setUpperHeatplanId(plnZgPln.getHeatPlanNo());
			plnJgM.setStoveNo(plnZgPln.getStoveNo());
			plnJgM.setJudgeStoveNo(plnZgPln.getJudgeStoveNo());
			plnJgM.setFlagStoveNo(plnZgPln.getJudgeStoveNo());
			plnJgM.setPlanstatus("00");
			plnJgM.setPlineCode(plnJgS.getPlineCode());
			plnJgM.setPlineName(plnJgS.getPlineName());
			plnJgM.setIfMatchOdd("0");
			plnJgM.setIfDoHeatPlan("0");
			plnJgM.setUpperProcessCode("G");
			plnJgM.setProPlanId(plnJgS.getProPlanId());
			plnJgM.setGxPlanNo(plnJgS.getGxPlanNo());
			plnJgM.setJgGroupId(plnJgS.getJgGroupId());
			plnJgM.setCodeJg(plnJgS.getCodeJg());
			plnJgM.setMinD(plnJgS.getMinD());
			plnJgM.setMinH(plnJgS.getMinH());
			plnJgM.setAimCutLen(plnJgS.getAimCutLen());
			plnJgM.setAimlengthBl(plnJgS.getAimlengthBl());
			plnJgM.setGradecode(plnZgPln.getGradecode());
			plnJgM.setGradename(plnZgPln.getGradename());
			plnJgM.setSteelcode(plnJgS.getSteelcode());
			plnJgM.setSteelname(plnJgS.getSteelname());
			plnJgM.setProdStandard(plnZgPln.getProdStandard());
			plnJgM.setOutputStandard(plnZgPln.getOutputStandard());
			plnJgM.setBlWlId(plnJgS.getBlWlId());
			plnJgM.setBlWlDesc(plnJgS.getBlWlDesc());
			plnJgM.setOutwlId(plnJgS.getOutwlId());
			plnJgM.setOutwlDesc(plnJgS.getOutwlDesc());
			plnJgM.setModelCode(plnJgS.getModelCode());
			plnJgM.setModelDesc(plnJgS.getModelDesc());
			plnJgM.setLengthMax(plnJgS.getLengthMax());
			plnJgM.setLengthMin(plnJgS.getLengthMin());
			plnJgM.setTaper(plnJgS.getTaper());
			plnJgM.setCodeJgBl(plnJgS.getCodeJgBl());
			plnJgM.setSpecJg(plnJgS.getSpecJg());
			plnJgM.setSpecJgDesc(plnJgS.getSpecJgDesc());
			plnJgM.setSingleCutNun(plnJgS.getSingleCutNun());
			// 查询接箍信息
			String sqlCodeJg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryCodeJg");
			ps = con.prepareStatement(sqlCodeJg);
			ps.setObject(1, plnJgS.getCodeJg());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnJgM.setOutdiameter(rs.getString("DIAMETER_JG"));
				plnJgM.setWallthick(rs.getString("HEIGHT_JG"));
				plnJgM.setStyleJg(rs.getString("STYLE_JG"));
				plnJgM.setDiameter(rs.getString("DIAMETER"));
				plnJgM.setCheckJVal(rs.getString("CHECK_J_VAL"));
				plnJgM.setSingleweight(rs.getString("WEIGHT_JG"));
				plnJgM.setAimlength(rs.getString("LENGTH_JG"));
				plnJgM.setProduccodeJg(rs.getString("PRODUCCODE_JG"));
				plnJgM.setProduccodeJgDesc(rs.getString("PRODUCCODE_JG_DESC"));
				plnJgM.setStdCode(rs.getString("STD_CODE"));
				plnJgM.setStdName(rs.getString("STD_NAME"));
				plnJgM.setStdStyle(rs.getString("STD_STYLE"));
				plnJgM.setStdStyleDesc(rs.getString("STD_STYLE_DESC"));
			}
			rs.close();
			ps.close();
			plnJgM.setDemandCopper(plnJgS.getDemandCopper());
			// 计划支吨
			plnJgM.setPlanJgNum(String.valueOf(oldNum
					* Integer.parseInt(plnJgS.getSingleCutNun())));
			plnJgM.setPlanBlNum(String.valueOf(oldNum));
			plnJgM.setPlanBlWt(String.valueOf(oldWt));

			plnJgM.setOrdLnDlyPk(plnJgS.getOrdLnDlyPk());
			plnJgM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnJgM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnJgM.setPrdcrNo(plnJgS.getPrdcrNo());
			plnJgM.setCraftFileNo(plnJgS.getCraftFileNo());
			plnJgM.setCraftSeq(plnJgS.getCraftSeq());

			plnJgM.setCreateName(createName);
			plnJgM.setCreateTime(createTime);

			if (!plnJgS.getIfMonitorJg().equals("")) {
				plnJgM.setMonitordemand("接箍监制。");
				plnJgM.setIfMonitorJg("1");
			} else if (!plnJgS.getIfMonitorBl().equals("")) {
				plnJgM.setMonitordemand("接箍料监制。");
				plnJgM.setIfMonitorJg("1");
			} else if (!plnJgS.getIfMonitorBl().equals("")
					&& !plnJgS.getIfMonitorJg().equals("")) {
				plnJgM.setMonitordemand("接箍、接箍料监制。");
				plnJgM.setIfMonitorJg("1");
			} else {
				plnJgM.setMonitordemand("");
				plnJgM.setIfMonitorJg("0");
			}
			if (fl == 0) {
				// 新增
				heatPlanNo = getMaxHeatPlanNo(con, plnJgM.getProPlanId(),
						plnJgM.getProPlanId(), "H");
				// 获取炉计划顺序号
				int gxProSeq = getMaxGxPlnSeq(con, plnJgM.getPlineCode(), "H");
				plnJgM.setHeatPlanNo(heatPlanNo);
				plnJgM.setGxProSeq(String.valueOf(gxProSeq));
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyJg"),
						plnJgM);
				ps = con.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();
			} else {
				// 修改炉计划
				String updateM = "UPDATE PLN_ZY_JG_M T"
						+ " SET T.PLAN_JG_NUM  = TO_NUMBER(T.PLAN_JG_NUM) + TO_NUMBER(?),"
						+ "  T.PLAN_BL_NUM   = TO_NUMBER(T.PLAN_BL_NUM) + TO_NUMBER(?),"
						+ "  T.PLAN_BL_WT = TO_NUMBER(T.PLAN_BL_WT) + TO_NUMBER(?)"
						+ " WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(updateM);
				ps.setObject(1,
						oldNum * Integer.parseInt(plnJgS.getSingleCutNun()));
				ps.setObject(2, oldNum);
				ps.setObject(3, oldWt);
				ps.setObject(4, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;
		}
		return true;
	}
}
