package com.steering.pss.plnsaleord.planStove;

import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.springframework.util.LinkedCaseInsensitiveMap;

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.StringTool;
import com.steering.pss.plnsaleord.planStove.entity.MatBcTrackEntity;
import com.steering.pss.plnsaleord.planStove.entity.MilFeedPlanEntity;
import com.steering.pss.plnsaleord.planStove.entity.MilPlanEntity;
import com.steering.pss.plnsaleord.planStove.entity.QcmBcJudgeChangeEntity;
import com.steering.pss.plnsaleord.planStove.entity.YdmBcOutlistEntity;
import com.steering.pss.plnsaleord.planStove.entity.MatBcMEntity;
import com.steering.pss.plnsaleord.processOrder.entity.PlnGxJgPropSEntity;
import com.steering.pss.plnsaleord.steelMarkingPlan.FrmSteelMakingPlanChange;
import com.steering.pss.plnsaleord.stove.ComPlanFurnace;
import com.steering.pss.plnsaleord.stove.PlanFurnProduction;
import com.steering.pss.plnsaleord.stove.corePlanFurnProM;
import com.steering.pss.plnsaleord.stove.corePlnZyFurnM;
import com.steering.pss.plnsaleord.stove.entity.*;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignStdBiasCEntity;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import com.steering.pss.judge.Bll.BllCreateGroupStoveInfo;
import com.steering.pss.judge.DAL.QcmJhyElementsDAL;
import com.steering.pss.judge.comm.ChemJudgeHelper;
import com.steering.pss.judge.comm.JudgeHelper;
import com.steering.pss.judge.comm.RoundGBT81702008;
import com.steering.pss.judge.model.ComBaseChemEntity;
import com.steering.pss.judge.model.CraftOrdDesignStdCicEntity;
import com.steering.pss.judge.model.QcmJhyElementsEntity;

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

import com.sun.xml.bind.v2.runtime.unmarshaller.XsiNilLoader;

/**
 * 精整利库
 * 
 * @author teng 2018.7.23
 */
public class FrmEndLibrary extends DBCommon {
	private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
	/**
	 * 查询管坯库存信息
	 * 
	 * @return
	 */
	public CoreReturnObject queryMaterial(String belongCode, String gradeCode,
			String judgeNo, String[] belongCodeAll, String proessCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.queryMaterial");
		if (!gradeCode.equals("")) {
			sql += "  AND T.GRADECODE='" + gradeCode + "'";
		}
		if (!judgeNo.equals("")) {
			sql += "  AND T.JUDGE_STOVE_NO='" + judgeNo + "'";
		}
		if (!belongCode.equals("")) {
			sql += "  AND T.PLINE_CODE='" + belongCode + "'";
		} else {
			sql += CoreConverter.toSqlConditionString("T.PLINE_CODE",
					belongCodeAll);
		}
		if (!proessCode.equals("")) {
			sql += "  AND T.PROCESS_CDOE='" + proessCode + "'";
		}
		// sql +=
		// "   AND T.JUGDE_APPLY_CODE IS  NULL AND T.MAT_STATUS='80150101' ";//
		// AND
		// (T.JUDGE_RESULT_CODE
		// =
		// '40740701'
		// OR
		// T.JUDGE_RESULT_CODE
		// IS
		// NULL
	
		sql += "GROUP BY T.MATERIAL_NO, T.MATERIAL_NAME, T.JUDGE_STOVE_NO, T.BATCH_NO,T.GRADECODE,T.JUDGE_ID,"
				+ "T.BATCH_GROUD_NO, T.STOVE_NO, T.PRO_ORDER_ID, T.GX_PLAN_NO, T.HEAT_PLAN_NO, "
				+ "T.PRO_PLAN_ID_NEXT, T.GX_PLAN_NO_NEXT, T.PRODUCNAME, T.GRADENAME, T.STEELNAME, T.PLINE_CODE,"
				+ "T.SPEC_NAME, T.MODEL_DESC, T.STD_NAME, T.STD_STYLE_DESC, T.NEXT_PROCESS_CDOE, "
				+ "T.PLINE_NAME, T.ACT_DIMATER, T.ACT_HEIGHT, T.ACT_LEN_MIN, "
				+ "T.ACT_LEN_MAX, T.PRODUCT_FLAG, T.MAT_STATUS, T.BELONG_NAME, T.ORDER_NO, "
				+ "T.ORDER_SEQ, T.PRO_ORDER_NO,T.ORD_LN_DLY_PK, T.CIC, T.PROCESS_CDOE, T.JUGDE_APPLY_CODE, "
				+ "T.JUDGE_RESULT_CODE, T.BELONG_NAME,T.HEAT_PLAN_NO_NEXT,T.HEAT_PLAN_NO_OLD,t.ORDER_SEQ_NO ";
		return this.getData(sql);
	}

	/**
	 * 库存长度参与分组
	 * 
	 * @return
	 */
	public CoreReturnObject queryMaterial1(String belongCode, String gradeCode,
			String judgeNo, String[] belongCodeAll, String proessCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.queryMaterial1");
		if (!gradeCode.equals("")) {
			sql += "  AND T.GRADECODE='" + gradeCode + "'";
		}
		if (!judgeNo.equals("")) {
			sql += "  AND T.JUDGE_STOVE_NO='" + judgeNo + "'";
		}
		if (!belongCode.equals("")) {
			sql += "  AND T.PLINE_CODE='" + belongCode + "'";
		} else {
			sql += CoreConverter.toSqlConditionString("T.PLINE_CODE",
					belongCodeAll);
		}
		if (!proessCode.equals("")) {
			sql += "  AND T.PROCESS_CDOE='" + proessCode + "'";
		}
		// sql +=
		// "   AND T.JUGDE_APPLY_CODE IS  NULL AND T.MAT_STATUS='80150101' ";//
		// AND
		// (T.JUDGE_RESULT_CODE
		// =
		// '40740701'
		// OR
		// T.JUDGE_RESULT_CODE
		// IS
		// NULL
		sql += "GROUP BY T.MATERIAL_NO, T.MATERIAL_NAME, T.JUDGE_STOVE_NO, T.BATCH_NO,T.GRADECODE,T.JUDGE_ID,"
				+ "T.BATCH_GROUD_NO, T.STOVE_NO, T.PRO_ORDER_ID, T.GX_PLAN_NO, T.HEAT_PLAN_NO, "
				+ "T.PRO_PLAN_ID_NEXT, T.GX_PLAN_NO_NEXT, T.PRODUCNAME, T.GRADENAME, T.STEELNAME,T.PLINE_CODE, "
				+ "T.SPEC_NAME, T.MODEL_DESC, T.STD_NAME, T.STD_STYLE_DESC, T.NEXT_PROCESS_CDOE, "
				+ "T.PLINE_NAME, T.ACT_DIMATER, T.ACT_HEIGHT, T.ACT_LEN_MIN, "
				+ "T.ACT_LEN_MAX, T.PRODUCT_FLAG, T.MAT_STATUS, T.BELONG_NAME, T.ORDER_NO, "
				+ "T.ORDER_SEQ, T.PRO_ORDER_NO,T.ORD_LN_DLY_PK, T.ACT_LEN,T.CIC, T.PROCESS_CDOE, T.JUGDE_APPLY_CODE, "
				+ "T.JUDGE_RESULT_CODE, T.BELONG_NAME,T.HEAT_PLAN_NO_NEXT,T.HEAT_PLAN_NO_OLD,T.ORDER_SEQ_NO ";
		return this.getData(sql);
	}

	/**
	 * 查询脱单利库记录
	 * 
	 * @param
	 * @param
	 * @return
	 */
	public CoreReturnObject queryMatGpTrack(String belongCode,
			String gradeCode, String judgeNo, String[] belongCodeAll,
			String proessCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.queryMatGpTrack");
		if (!gradeCode.equals("")) {
			sql += "  AND T.GRADECODE='" + gradeCode + "'";
		}
		if (!judgeNo.equals("")) {
			sql += "  AND T.JUDGE_STOVE_NO='" + judgeNo + "'";
		}
		 //if (!belongCode.equals("")) {
		// sql += "  AND T.PLINE_CODE='" + belongCode + "'";
		// } 
		 //else {
		// sql += CoreConverter.toSqlConditionString("T.PLINE_CODE",
		// belongCodeAll);
		// }
		if (!proessCode.equals("")) {
			sql += "  AND T.PROCESS_CDOE='" + proessCode + "'";
		}
		sql += " AND T.EVENT_DESC IN ('精整利库','精整脱单') ORDER BY T.CREATE_NAME DESC";

		return this.getData(sql);
	}

	/**
	 * 查询脱单利库记录
	 * 
	 * @param
	 * @param
	 * @return
	 */
	public CoreReturnObject queryQcmBcJude(String judgeNo, String proessCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.queryQcmBcJude");
		// if (!gradeCode.equals("")) {
		// sql += "  AND T.GRADECODE='" + gradeCode + "'";
		// }
		if (!judgeNo.equals("")) {
			sql += "  AND T.JUDGE_STOVE_NO_OLD='" + judgeNo + "'";
		}
		if (!proessCode.equals("")) {
			sql += "  AND T.PROCESS_CDOE='" + proessCode + "'";
		}
		sql += " ORDER BY T.CREATE_NAME DESC";

		return this.getData(sql);
	}

	/**
	 * 查询排产信息
	 * 
	 * @param con
	 * @param proPlanId
	 *            订单编号
	 * @param gxPlanNo
	 *            排产序号
	 * @return PlnOrderCastSEntity
	 * @throws SQLException
	 */
	public static <T> T getPlanOrderS(Connection con, String proPlanId,
			String gxPlanNo, Class<T> cls, String processCode)
			throws SQLException {
		String sql = "";
		if (processCode.equals("D")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ComPlanFurnace.queryPlnOrderZgS");
		} else if (processCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryPlnOrderDbk");
		} else if (processCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryPlnOrdeRcl");
		} else if (processCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryPlnOrderJgx");
		}
		sql += " AND T.PRO_PLAN_ID = ?  AND T.GX_PLAN_NO = ?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, proPlanId);
		ps.setObject(2, gxPlanNo);
		ResultSet rs = ps.executeQuery();
		T t = EntityTool.getEntityByRs(rs, cls);
		rs.close();
		ps.close();
		return t;
	}

	/**
	 * 查詢改判信息
	 * 
	 * @param con
	 * @throws SQLException
	 */
	public static <T> T getQcmBcJudgeChan(Connection con, String judgeID,
			Class<T> cls) throws SQLException {
		String sql = " SELECT T.* FROM QCM_BC_JUDGE_CHANGE T WHERE T.JUDGE_ID=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeID);
		ResultSet rs = ps.executeQuery();
		T t = EntityTool.getEntityByRs(rs, cls);
		rs.close();
		ps.close();
		return t;
	}
	


	/**
	 * 查询轧管
	 * 
	 * @param
	 *            　
	 * @param
	 *            　
	 * @return CoreReturnObject
	 */
	public CoreReturnObject getPlnOrderZgS(String materialNo, String stoveNo,
			String proessCode) {
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		if (proessCode.equals("D")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.queryPlanOrderD");
			// sql += " AND T.OUTWL_ID ='" + materialNo + "'";
			sql += ")T, (select distinct stove_no, pro_order_no, proess_code from ZG_ORD_STD_CIC a) C\r\n" + 
					"   WHERE T.PRO_ORDER_NO = C.PRO_ORDER_NO\r\n" + 
					"   AND C.STOVE_NO = '"+stoveNo+"'";
		} else if (proessCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.queryPlanOrderE");
			// sql += " AND T.OUTWL_ID ='" + materialNo + "') DBK";
			sql += ")DBK, (select distinct stove_no, pro_order_no, proess_code from ZG_ORD_STD_CIC a) C\r\n" + 
					"   WHERE DBK.PRO_ORDER_NO = C.PRO_ORDER_NO\r\n" + 
					"   AND C.STOVE_NO = '"+stoveNo+"'";
		} else if (proessCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.queryPlanOrderF");
			// sql += " AND T.OUTWL_ID ='" + materialNo + "') RCL";
			sql += ")RCL, (select distinct stove_no, pro_order_no, proess_code from ZG_ORD_STD_CIC a) C\r\n" + 
					"   WHERE RCL.PRO_ORDER_NO = C.PRO_ORDER_NO\r\n" + 
					"   AND C.STOVE_NO = '"+stoveNo+"'";
		} else if (proessCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.queryPlanOrderG");
			// sql += " AND T.OUTWL_ID ='" + materialNo + "') JGX";
			sql += ")JGX, (select distinct stove_no, pro_order_no, proess_code from ZG_ORD_STD_CIC a) C\r\n" + 
					"   WHERE JGX.PRO_ORDER_NO = C.PRO_ORDER_NO\r\n" + 
					"   AND C.STOVE_NO = '"+stoveNo+"'";
		}
		return this.getData(sql);
	}
	
	public CoreReturnObject CheckGaiPan(final String proessCode) throws Exception{
		final ExecutorService executorService = Executors.newFixedThreadPool(20);
		CoreReturnObject cro = new CoreReturnObject();
    	final Connection conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		// 异步处理其他业务
        Future<?> future = executorService.submit(new Runnable() {
            @Override
            public void run() {
                try {
                	//Thread.sleep(5000); // 模拟耗时操作
                	GaiPanOptimizer gp= new GaiPanOptimizer();
                	gp.optimizedGaiPan(proessCode,conn);
					// gaiPan(proessCode);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                } catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} finally {
					try {
						if (conn != null && !conn.isClosed()) {
							conn.close();
						}
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
            }
        });
		cro.setV_errCode(0);
		cro.setV_errMsg("初始化数据正在刷新，请耐心等待.... 不影响其他业务操作");
		return cro;
	}
	
	/**
	 * 改判异步处理
	 * @param custInfo
	 * @return
	 * @throws Exception
	 */
	public void gaiPan(String proessCode) throws Exception{
		Connection conn = null;
		PreparedStatement addZgOrdCicPs = null;

		try {
		conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		conn.setAutoCommit(false);
		PreparedStatement ps = null;
		ResultSet rs = null;
		String dSql = "";
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.queryMaterial");
		sql += "GROUP BY T.MATERIAL_NO, T.MATERIAL_NAME, T.JUDGE_STOVE_NO, T.BATCH_NO,T.GRADECODE,T.JUDGE_ID,"
				+ "T.BATCH_GROUD_NO, T.STOVE_NO, T.PRO_ORDER_ID, T.GX_PLAN_NO, T.HEAT_PLAN_NO, "
				+ "T.PRO_PLAN_ID_NEXT, T.GX_PLAN_NO_NEXT, T.PRODUCNAME, T.GRADENAME, T.STEELNAME, T.PLINE_CODE,"
				+ "T.SPEC_NAME, T.MODEL_DESC, T.STD_NAME, T.STD_STYLE_DESC, T.NEXT_PROCESS_CDOE, "
				+ "T.PLINE_NAME, T.ACT_DIMATER, T.ACT_HEIGHT, T.ACT_LEN_MIN, "
				+ "T.ACT_LEN_MAX, T.PRODUCT_FLAG, T.MAT_STATUS, T.BELONG_NAME, T.ORDER_NO, "
				+ "T.ORDER_SEQ, T.PRO_ORDER_NO,T.ORD_LN_DLY_PK, T.CIC, T.PROCESS_CDOE, T.JUGDE_APPLY_CODE, "
				+ "T.JUDGE_RESULT_CODE, T.BELONG_NAME,T.HEAT_PLAN_NO_NEXT,T.HEAT_PLAN_NO_OLD,t.ORDER_SEQ_NO ";
		String queryElments = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.queryelments");
		String queryStdCic = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.queryeStdCic");
		//查询订单信息
		if (proessCode.equals("D")) {
			dSql = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.queryPlanOrderD");
			dSql += ")";
		} else if (proessCode.equals("E")) {
			dSql = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.queryPlanOrderE");
		} else if (proessCode.equals("F")) {
			dSql = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.queryPlanOrderF");
		} else if (proessCode.equals("G")) {
			dSql = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.queryPlanOrderG");
		}
		//先清除表
		PreparedStatement delZgOrderCic = conn.prepareStatement("delete from zg_ord_std_cic");
		delZgOrderCic.addBatch();
		String addZgOrdCicSql =  CoreXmlSqlParsersFactory.getSql("FrmEndLibrary.addZgOrderCic");
		ps = conn.prepareStatement(sql);
		rs = ps.executeQuery();
			while(rs.next()) {
				String stoveNo = rs.getString("STOVE_NO");
				ResultSet elemnets = getRs(conn,queryElments,stoveNo);
				QcmJhyElementsEntity elementsEntity = EntityTool.getEntityByRs(elemnets, QcmJhyElementsEntity.class);
				if(elementsEntity.getAssayno() != null) {
					PreparedStatement ps2 = conn.prepareStatement(dSql);
					ResultSet dRs = ps2.executeQuery();
					while(dRs.next()) {
						String ordLnPk =  dRs.getString("ORD_LN_DLY_PK").toString();
						ordLnPk = ordLnPk.substring(0,ordLnPk.length()-3);
						ResultSet rs3 = getRs(conn,queryStdCic,ordLnPk);
						//成分标准
						ArrayList<CraftOrdDesignStdCicEntity> craftOrdDesignStdCicEntities = EntityTool.getEntitysByRs(rs3, CraftOrdDesignStdCicEntity.class);
						//成分判定
						Object[] results =  ChemJudgeHelper.Judge(elementsEntity, craftOrdDesignStdCicEntities, null, true);
						if(results[0].toString().equals("")) {
							//存入查询表
							addZgOrdCicPs = conn.prepareStatement(addZgOrdCicSql);
							addZgOrdCicPs.setString(1, stoveNo);
							addZgOrdCicPs.setString(2, dRs.getString("PRO_ORDER_NO"));
							addZgOrdCicPs.addBatch();
						}
						
					}
				}
			}
			delZgOrderCic.executeBatch();
			addZgOrdCicPs.executeBatch();
			conn.commit();
		}catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	public ResultSet getRs (Connection conn,String sql,String str) throws Exception{
		 PreparedStatement psta = conn.prepareStatement(sql);
		 psta.setObject(1, str);
		 ResultSet rs = psta.executeQuery();
		 return rs;
	 }
	
	
	
	/**
	 * 查询坯子库存信息
	 * 
	 * @param con
	 * @param
	 *
	 * @param judgeStoveNo
	 *            判定炉号
	 * @throws SQLException
	 */
	public static List<MatBcMEntityPln> getQureyMatGpM(Connection con,
			String judgeStoveNo, String batchNo, String batchGroupBy,
			int takeCount, String heatPlanNoNext, String proessCode,
			String jugdeApplyCode, String proOrderNo, String actLen,
			String lenFalg,String materialNo) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.QueryMatGp");
		if (!heatPlanNoNext.equals("")) {
			sql += " AND T.HEAT_PLAN_NO_NEXT ='" + heatPlanNoNext + "'";
		} else {
			//sql += " AND T.HEAT_PLAN_NO_NEXT IS NULL";
		}
		if (!jugdeApplyCode.equals("")) {
			sql += " AND T.JUGDE_APPLY_CODE ='" + jugdeApplyCode + "'";
		}
		sql += " AND NVL(T.PRO_ORDER_NO,'/')=NVL('" + proOrderNo + "','/')";
		if (lenFalg.equals("1")) {
			sql += " AND NVL(T.ACT_LEN,'0')=NVL('" + actLen + "','0')";
		}
		if(!materialNo.equals(""))
		{
			sql += " AND T.MATERIAL_NO = '"+materialNo+"'";
		}

		sql += "  ORDER BY T.MAT_NO ASC) where rownum<=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, batchNo);
		ps.setObject(3, batchGroupBy);
		// ps.setObject(4, proessCode);
		ps.setObject(4, takeCount);
		ResultSet rs = ps.executeQuery();
		List<MatBcMEntityPln> list = EntityTool.getEntitysByRs(rs,
				MatBcMEntityPln.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (MatBcMEntityPln listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}


	/**
	 * 按支查询半成品库存信息
	 *
	 * @param con
	 * @param
	 *
	 * @param judgeStoveNo
	 *            判定炉号
	 * @throws SQLException
	 */
	public static List<MatBcMEntityPln> getQureyMatGpMPay(Connection con,
													   String judgeStoveNo, String batchNo, String batchGroupBy,
													   String alist, String heatPlanNoNext, String proessCode,
													   String jugdeApplyCode, String proOrderNo, String actLen,
													   String lenFalg,String materialNo) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.QueryMatGpPay");
		String[] matNoAr = alist.split(",");
		if (!heatPlanNoNext.equals("")) {
			sql += " AND T.HEAT_PLAN_NO_NEXT ='" + heatPlanNoNext + "'";
		} else {
			sql += " AND T.HEAT_PLAN_NO_NEXT IS NULL";
		}
		if (!jugdeApplyCode.equals("")) {
			sql += " AND T.JUGDE_APPLY_CODE ='" + jugdeApplyCode + "'";
		}
		sql += " AND NVL(T.PRO_ORDER_NO,'/')=NVL('" + proOrderNo + "','/')";
		if (lenFalg.equals("1")) {
			sql += " AND NVL(T.ACT_LEN,'0')=NVL('" + actLen + "','0')";
		}
		if(!materialNo.equals(""))
		{
			sql += " AND T.MATERIAL_NO = '"+materialNo+"'";
		}

		sql += CoreConverter.toSqlConditionString("T.MAT_NO",matNoAr);

		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, batchNo);
		ps.setObject(3, batchGroupBy);
		ResultSet rs = ps.executeQuery();
		List<MatBcMEntityPln> list = EntityTool.getEntitysByRs(rs,
				MatBcMEntityPln.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (MatBcMEntityPln listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}

	// 查询库存信息赋值履历表
	public static <T> T getQureyMatTrack(Connection con, String judgeStoveNo,
			String batchNo, String batchGroupBy, int takeCount,
			String hangingflag, String heatPlanNoNext, Class<T> cls)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.getQureyMatTrack");
		if (!heatPlanNoNext.equals("")) {
			sql += " AND HEAT_PLAN_NO_NEXT ='" + heatPlanNoNext + "'";
		} else {
			sql += " AND HEAT_PLAN_NO_NEXT IS NULL";
		}

		// sql += " AND HANGING_FLAG = '" + hangingflag + "'";
		sql += " AND rownum<=?";
		sql += " GROUP BY T.PRODUCT_FLAG,T.MAT_STATUS,T.LOT_NO,T.STOVE_NO,T.JUDGE_STOVE_NO,T.BATCH_NO,T.BATCH_GROUD_NO,"
				+ "T.MATERIAL_NO, T.MATERIAL_NAME,T.PRODUCCODE,T.PRODUCNAME,T.STEELCODE,T.STEELNAME,T.STD_CODE,T.STD_NAME,"
				+ "T.STD_STYLE,T.STD_STYLE_DESC,T.SPEC_CODE,T.SPEC_NAME,T.MODEL_CODE,T.MODEL_DESC,T.ACT_LEN_MIN,"
				+ "T.ACT_LEN_MAX,T.PRO_ORDER_NO,T.PRO_ORDER_ID,T.ORD_PK,T.ORD_LN_PK,T.ORD_LN_DLY_PK,T.ORDER_NO,T.ORDER_SEQ,"
				+ "T.ORDER_SEQ_NO, T.BELONG_CODE,T.BELONG_NAME, T.PROCESS_CDOE, T.GRADECODE, T.GRADENAME,T.ACT_DIMATER,"
				+ "T.ACT_HEIGHT,T.HEAT_PLAN_NO,T.GX_PLAN_NO,T.PRO_ORDER_ID,T.CIC,T.HEAT_PLAN_NO_OLD,T.TARGET,T.PLINE_CODE,S.STORAGE_NO";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, batchNo);
		ps.setObject(3, batchGroupBy);
		ps.setObject(4, takeCount);
		ResultSet rs = ps.executeQuery();
		T t = EntityTool.getEntityByRs(rs, cls);
		rs.close();
		ps.close();
		return t;
	}

	// 返线查询库存信息赋值履历表
	public static <T> T getQureyReturnMatTrack(Connection con,
			String judgeStoveNo, String batchNo, String batchGroupBy,
			int takeCount, String proOrdeIdNo, String heatPlanNo, Class<T> cls,
			String lenFalg, String actLen) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.getQureyMatTrack");
		sql += " AND HEAT_PLAN_NO ='" + heatPlanNo + "'";
		sql += " AND PRO_ORDER_ID||'/'||GX_PLAN_NO='" + proOrdeIdNo + "'";
		if (lenFalg.equals("1")) {
			sql += " AND NVL(T.ACT_LEN,'0')=NVL('" + actLen + "','0')";
		}
		sql += " AND rownum<=?";

		sql += " GROUP BY T.PRODUCT_FLAG,T.MAT_STATUS,T.LOT_NO,T.STOVE_NO,T.JUDGE_STOVE_NO,T.BATCH_NO,T.BATCH_GROUD_NO,"
				+ "T.MATERIAL_NO, T.MATERIAL_NAME,T.PRODUCCODE,T.PRODUCNAME,T.STEELCODE,T.STEELNAME,T.STD_CODE,T.STD_NAME,"
				+ "T.STD_STYLE,T.STD_STYLE_DESC,T.SPEC_CODE,T.SPEC_NAME,T.MODEL_CODE,T.MODEL_DESC,T.ACT_LEN_MIN,"
				+ "T.ACT_LEN_MAX,T.PRO_ORDER_NO,T.PRO_ORDER_ID,T.ORD_PK,T.ORD_LN_PK,T.ORD_LN_DLY_PK,T.ORDER_NO,T.ORDER_SEQ,"
				+ "T.ORDER_SEQ_NO, T.BELONG_CODE,T.BELONG_NAME, T.PROCESS_CDOE, T.GRADECODE, T.GRADENAME,T.ACT_DIMATER,T.ACT_HEIGHT,"
				+ " T.HEAT_PLAN_NO,T.GX_PLAN_NO,T.PRO_ORDER_ID,T.CIC,T.HEAT_PLAN_NO_OLD,T.TARGET,S.STORAGE_NO,T.PLINE_CODE";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, batchNo);
		ps.setObject(3, batchGroupBy);
		ps.setObject(4, takeCount);
		ResultSet rs = ps.executeQuery();
		T t = EntityTool.getEntityByRs(rs, cls);
		rs.close();
		ps.close();
		return t;
	}

	/**
	 * 轧管,镦拔扩,热处理,加工线精整利库
	 * 
	 * @param proPlanId
	 *            订单号
	 * @param gxPlanNo
	 *            排产序号
	 * @throws Exception
	 */
	public CoreReturnObject doAddLibrary(ArrayList<String> list,
			String proPlanId, String gxPlanNo, String userName,
			String planstatus, String falg, String lenFalg) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		Connection jhyCon = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			jhyCon = this.getDao("JhyDao").getConnection();
			jhyCon.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			SimpleDateFormat dFormat = new SimpleDateFormat("yyyyMMdd");
			SimpleDateFormat dfMonth = new SimpleDateFormat("yyyyMM");
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			String judgeStoveNo = list.get(0);
			String batchNo = list.get(1);
			String batchGroupBy = list.get(2);
			int takeCount = Integer.parseInt(list.get(3));// 利库支
			String processCdoe = list.get(5);
			String materialNo = list.get(6);
			String cic = list.get(7);
			String proOrderNo = list.get(8);
			String actLen = list.get(9);
			// 循环库存信息
			int seq = 1;
			Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			DecimalFormat df = new DecimalFormat("0000000000");

			MatBcTrackEntity matTrack = getQureyMatTrack(conn, judgeStoveNo,
					batchNo, batchGroupBy, takeCount, "0", "",
					MatBcTrackEntity.class);
			if (matTrack == null) {
				cro.setV_errMsg("管坯物料已发生改变,请刷新!");
				return cro;
			}
			String orderOld = matTrack.getOldOrdLnDlyPk();
			// String heatPlanNo = matTrack.getHeatPlanNo();
			String nextProcessCdeo = "";
			String nextProcessName = "";
			String decision = "";
			String wholeDesc = "";
			String ordLnDlyPk = "";
			String orderNoSeq = "";
			String orderNo = "";
			String orderSeq = "";
			String deliveryNo = "";
			String plnDivideId = "";
			String orderSource = "";
			int outnumCut = 0;
			String materialNoD = "";
			String craftNo = "";
			String craftSeq = "";
			String ifProduct = "0";
			String pic = "";
			String sic = "";
			String dic = "";
			String judStdDes = "";
			String indexSeq = "";
			String lotNo = matTrack.getLotNo();
			String heatPlanNoOld = matTrack.getHeatPlanNoOld();
			String flag = "0";
			ArrayList<String> list1 = new ArrayList<String>();
			PlnOrderZgSEntityL plnOrderSZg = new PlnOrderZgSEntityL();
			PlnOrderDbkSEntity plnOrderSDbk = new PlnOrderDbkSEntity();
			PlnOrderRclSEntity plnOrderSRcl = new PlnOrderRclSEntity();
			PlnOrderJgxSEntity plnOrderSJgx = new PlnOrderJgxSEntity();
			if (processCdoe.equals("D")) {
				// 查询轧管信息
				plnOrderSZg = getPlanOrderS(conn, proPlanId, gxPlanNo,
						PlnOrderZgSEntityL.class, "D");
				if (plnOrderSZg == null) {
					cro.setV_errMsg("未找到轧管订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				if (!plnOrderSZg.getGpreqId().equals("")) {
					cro.setV_errMsg("勾选订单已生成管坯需求，不能利库！");
					return cro;
				}
				decision = plnOrderSZg.getDecision();
				wholeDesc = plnOrderSZg.getWholeBacklogDesc();
				ordLnDlyPk = plnOrderSZg.getOrdLnDlyPk();
				orderNoSeq = plnOrderSZg.getOrderNo() + "/"
						+ plnOrderSZg.getOrderSeq();
				orderNo = plnOrderSZg.getOrderNo();
				orderSeq = plnOrderSZg.getOrderSeq();
				deliveryNo = plnOrderSZg.getDeliveryNo();
				plnDivideId = plnOrderSZg.getPlnDivideId();
				orderSource = plnOrderSZg.getOrderSource();
				outnumCut = Integer.parseInt(plnOrderSZg.getOutnumCut());
				materialNoD = plnOrderSZg.getOutwlId();
				craftNo = plnOrderSZg.getCraftFileNo();
				craftSeq = plnOrderSZg.getCraftSeq();
				indexSeq = plnOrderSZg.getIndexSeq();
				int counnum = StoveHelper.getQueryStation(conn, proPlanId,
						gxPlanNo, "D");
				if (counnum > 0) {
					ifProduct = "1";
				}
				pic = plnOrderSZg.getPic().split(",")[0];
				sic = plnOrderSZg.getSic().split(",")[0];
				dic = plnOrderSZg.getDic().split(",")[0];
				String cic1 = cic;
				if (ifProduct.equals("0")) {
					cic1 = "";
				}
				judStdDes = cic1 + "+" + pic + "+" + sic + "+" + dic;
			} else if (processCdoe.equals("E")) {
				// 查询镦拔扩信息
				plnOrderSDbk = getPlanOrderS(conn, proPlanId, gxPlanNo,
						PlnOrderDbkSEntity.class, "E");
				if (plnOrderSDbk == null) {
					cro.setV_errMsg("未找到镦拔扩订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				decision = plnOrderSDbk.getDecision();
				wholeDesc = plnOrderSDbk.getWholeBacklogDesc();
				ordLnDlyPk = plnOrderSDbk.getOrdLnDlyPk();
				orderNoSeq = plnOrderSDbk.getOrderNo() + "/"
						+ plnOrderSDbk.getOrderSeq();
				orderNo = plnOrderSDbk.getOrderNo();
				orderSeq = plnOrderSDbk.getOrderSeq();
				deliveryNo = plnOrderSDbk.getDeliveryNo();
				plnDivideId = plnOrderSDbk.getPlnDivideId();
				orderSource = plnOrderSDbk.getOrderSource();
				materialNoD = plnOrderSDbk.getOutwlId();
				craftNo = plnOrderSDbk.getCraftFileNo();
				craftSeq = plnOrderSDbk.getCraftSeq();
				indexSeq = plnOrderSDbk.getIndexSeq();
				int counnum = StoveHelper.getQueryStation(conn, proPlanId,
						gxPlanNo, "E");
				if (counnum > 0) {
					ifProduct = "1";
				}
				pic = plnOrderSDbk.getPic().split(",")[0];
				sic = plnOrderSDbk.getSic().split(",")[0];
				dic = plnOrderSDbk.getDic().split(",")[0];
				String cic1 = cic;
				if (ifProduct.equals("0")) {
					cic1 = "";
				}
				judStdDes = cic1 + "+" + pic + "+" + sic + "+" + dic;

			} else if (processCdoe.equals("F")) {
				// 查询热处理信息
				plnOrderSRcl = getPlanOrderS(conn, proPlanId, gxPlanNo,
						PlnOrderRclSEntity.class, "F");
				if (plnOrderSRcl == null) {
					cro.setV_errMsg("未找到热处理订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				decision = plnOrderSRcl.getDecision();
				wholeDesc = plnOrderSRcl.getWholeBacklogDesc();
				ordLnDlyPk = plnOrderSRcl.getOrdLnDlyPk();
				orderNoSeq = plnOrderSRcl.getOrderNo() + "/"
						+ plnOrderSRcl.getOrderSeq();
				orderNo = plnOrderSRcl.getOrderNo();
				orderSeq = plnOrderSRcl.getOrderSeq();
				deliveryNo = plnOrderSRcl.getDeliveryNo();
				plnDivideId = plnOrderSRcl.getPlnDivideId();
				orderSource = plnOrderSRcl.getOrderSource();
				materialNoD = plnOrderSRcl.getOutwlId();
				craftNo = plnOrderSRcl.getCraftFileNo();
				craftSeq = plnOrderSRcl.getCraftSeq();
				indexSeq = plnOrderSRcl.getIndexSeq();
				int counnum = StoveHelper.getQueryStation(conn, proPlanId,
						gxPlanNo, "F");
				if (counnum > 0) {
					ifProduct = "1";
				}
				pic = plnOrderSRcl.getPic().split(",")[0];
				sic = plnOrderSRcl.getSic().split(",")[0];
				dic = plnOrderSRcl.getDic().split(",")[0];
				String cic1 = cic;
				if (ifProduct.equals("0")) {
					cic1 = "";
				}
				judStdDes = cic1 + "+" + pic + "+" + sic + "+" + dic;
			} else if (processCdoe.equals("G")) {
				// 查询加工线信息
				plnOrderSJgx = getPlanOrderS(conn, proPlanId, gxPlanNo,
						PlnOrderJgxSEntity.class, "G");
				if (plnOrderSJgx == null) {
					cro.setV_errMsg("未找到加工线订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				decision = plnOrderSJgx.getDecision();
				wholeDesc = plnOrderSJgx.getWholeBacklogDesc();
				ordLnDlyPk = plnOrderSJgx.getOrdLnDlyPk();
				orderNoSeq = plnOrderSJgx.getOrderNo() + "/"
						+ plnOrderSJgx.getOrderSeq();
				orderNo = plnOrderSJgx.getOrderNo();
				orderSeq = plnOrderSJgx.getOrderSeq();
				deliveryNo = plnOrderSJgx.getDeliveryNo();
				plnDivideId = plnOrderSJgx.getPlnDivideId();
				orderSource = plnOrderSJgx.getOrderSource();
				outnumCut = Integer.parseInt(plnOrderSJgx.getOutnumCut());
				materialNoD = plnOrderSJgx.getOutwlId();
				craftNo = plnOrderSJgx.getCraftFileNo();
				craftSeq = plnOrderSJgx.getCraftSeq();
				indexSeq = plnOrderSJgx.getIndexSeq();
				int counnum = StoveHelper.getQueryStation(conn, proPlanId,
						gxPlanNo, "G");
				if (counnum > 0) {
					ifProduct = "1";
				}
				if (orderNo.contains("ZZBY-D")) {
					flag = "1";
				}
				pic = plnOrderSJgx.getPic().split(",")[0];
				sic = plnOrderSJgx.getSic().split(",")[0];
				dic = plnOrderSJgx.getDic().split(",")[0];
				String cic1 = cic;
				if (ifProduct.equals("0")) {
					cic1 = "";
				}
				judStdDes = cic1 + "+" + pic + "+" + sic + "+" + dic;
			}
			list1.add(craftNo);
			list1.add(craftNo);
			list1.add(cic);
			list1.add(pic);
			list1.add(indexSeq);
			if (!decision.equals("A")) {
				if (wholeDesc.contains("镦拔扩") && processCdoe.equals("D")) {
					nextProcessCdeo = "E";
					nextProcessName = "镦拔扩";
				} else if (wholeDesc.contains("热处理") && processCdoe.equals("D")
						|| processCdoe.equals("E")) {
					nextProcessCdeo = "F";
					nextProcessName = "热处理";
				} else if (wholeDesc.contains("加工") && processCdoe.equals("D")
						|| processCdoe.equals("E") || processCdoe.equals("F")) {
					nextProcessCdeo = "G";
					nextProcessName = "加工";
				} else {
					if (ordLnDlyPk.contains("ZZBY-J")) {
						nextProcessCdeo = "H";
						nextProcessName = "接箍";
					} else if (ordLnDlyPk.contains("ZZBY-D")) {
						// nextProcessCdeo = "G";
						// nextProcessName = "加工";
					}
				}
			}
			String yOrderNo = "0";
			String orderNoOld = "";
			// 查询是否利给同一合同
			String sqlMatTrack = "SELECT T.OLD_ORD_LN_DLY_PK ORDER_NO_SEQ FROM MAT_BC_TRACK T "
					+ "WHERE T.EVENT_DESC='精整脱单' AND T.JUDGE_STOVE_NO=? AND T.BATCH_NO=? AND T.BATCH_GROUD_NO=? AND T.PROCESS_CDOE=? ORDER BY T.CREATE_TIME ASC";
			ps = conn.prepareStatement(sqlMatTrack);
			ps.setObject(1, judgeStoveNo);
			ps.setObject(2, batchNo);
			ps.setObject(3, batchGroupBy);
			ps.setObject(4, processCdoe);
			rs = ps.executeQuery();
			if (rs.next()) {
				orderNoOld = rs.getString("ORDER_NO_SEQ");
			}
			rs.close();
			ps.close();
			if (!orderNoOld.equals("")) {
				if (orderNoOld.equals(ordLnDlyPk)) {
					// cro.setV_errMsg("不能利原合同,请重新选择!");
					// return cro;
					yOrderNo = "1";
				}
			} else {
				if (orderOld.equals(ordLnDlyPk)) {
					// cro.setV_errMsg("不能利原合同,请重新选择!");
					// return cro;
					yOrderNo = "1";
				}
			}

			List<MatBcMEntityPln> matGpMlist = null;
			if(list.get(10).equals(""))
			{
				matGpMlist = getQureyMatGpM(conn,
						judgeStoveNo, batchNo, batchGroupBy, takeCount, "",
						processCdoe, "", proOrderNo, actLen, lenFalg,materialNo);
			}else
			{
				matGpMlist = getQureyMatGpMPay(conn,
						judgeStoveNo, batchNo, batchGroupBy, list.get(10), "",
						processCdoe, "", proOrderNo, actLen, lenFalg,materialNo);
			}

			if (matGpMlist == null) {
				cro.setV_errMsg("管坯物料已发生改变,请刷新!");
				return cro;
			}
			double actWt = 0;
			int countAppCode = 0;
			String heatPlanNo = "";
			String stoveNo = "";
			String flagStoveNo = "";
			String outwlId = "";
			String outwlDesc = "";
			String matOrigin = "";
			String lengthIn = "";
			String lengthmaxIn = "";
			String lengthminIn = "";
			String outdiameterIn = "";
			String wallthickIn = "";
			String zyBatchId = "";
			String processCdoeBgx = "";
			String target = "";
			String herdOLD = "";
			for (MatBcMEntityPln matGpM : matGpMlist) {
				countAppCode++;
				actWt += Double.parseDouble(matGpM.getActWeight());
				stoveNo = matGpM.getStoveNo();
				flagStoveNo = matGpM.getFlagStoveNoZg();
				outwlId = matGpM.getMaterialNo();
				outwlDesc = matGpM.getMaterialName();
				matOrigin = matGpM.getMatOriginCode();
				lengthIn = matGpM.getActLen();
				lengthmaxIn = matGpM.getActLenMax();
				lengthminIn = matGpM.getActLenMin();
				outdiameterIn = matGpM.getActDimater();
				wallthickIn = matGpM.getActHeight();
				zyBatchId = matGpM.getLotNo();
				processCdoeBgx = matGpM.getProcessCdoe();
				target = matGpM.getTarget();
				herdOLD = matGpM.getHeatPlanNoOld();
				// if (!materialNoD.equals(matGpM.getMaterialNo())) {
				// cro.setV_errMsg("选中炉号的物料与选中订单产出物料不相同,不能利库,请物料改判！");
				// return cro;
				// }
				if (!matGpM.getProOrderNo().equals("")) {
					cro.setV_errMsg("选中炉号已挂生产合同,不能利库!");
					return cro;
				}
				// if (!matGpM.getProductFlag().equals("801401")) {
				// cro.setV_errMsg("材料类别不是在制品,不能利库!");
				// return cro;
				// }
				if (!matGpM.getJugdeApplyCode().equals("")
						&& matGpM.getJudgeResultCode().equals("40740701")
						|| matGpM.getJudgeResultCode().equals("40740709")) {
					cro.setV_errMsg("该炉已送判,但未判定或判定合格,不能利库");
					return cro;
				}
				if (!matGpM.getQcmStaus().equals("00")) {
					cro.setV_errMsg("交库状态不是合格状态,不能利库!");
					return cro;
				}
				// String judgeStdDes = "";
				// if (!matGpM.getJudgeStdDes().equals("")) {
				// judgeStdDes = cic
				// + matGpM.getJudgeStdDes().substring(
				// matGpM.getJudgeStdDes().indexOf("+"),
				// matGpM.getJudgeStdDes().length());
				// }
				heatPlanNo = matGpM.getHeatPlanNo();
				String productFlag = "801401";
				String matStatus = "80150101";
				if (decision.equals("A")) {
					productFlag = "801402";
					matStatus = "80150201";
				}
				if (!target.equals(decision) && flag.equals("1")) {
					flag = "1";
				} else {
					flag = "0";
				}
				String proPlanIdOld = proPlanId;
				String gxPlanNoOlD = gxPlanNo;
//				if (falg.equals("1")) {// 跨工序利库
//					proPlanIdOld = matGpM.getProOrderId();
//					gxPlanNoOlD = matGpM.getGxPlanNo();
//				}
				// 利库时修改库存信息
				String sqlUpdateMat = CoreXmlSqlParsersFactory
						.getSql("FrmEndLibrary.UpdateMatGpLibrary");
				if (!processCdoe.equals(processCdoeBgx)) {
					sqlUpdateMat += " ,t.LIKU_PROCESS_CODE ='D'";
				}
				sqlUpdateMat += ",T.ZZB_FLAG='" + flag
						+ "'  WHERE T.MAT_NO = ?";
				ps = conn.prepareStatement(sqlUpdateMat);
				ps.setObject(1, matStatus);
				ps.setObject(2,proPlanIdOld);
				ps.setObject(3, gxPlanNoOlD);
				ps.setObject(4, nextProcessCdeo);
				ps.setObject(5, nextProcessName);
				ps.setObject(6, orderNoSeq);
				ps.setObject(7, cic);
				ps.setObject(8, judStdDes);
				ps.setObject(9, craftNo);
				ps.setObject(10, craftSeq);
				ps.setObject(11, decision);
				ps.setObject(12, productFlag);
				if (orderSource.equals("备料需求")) {
					ps.setObject(13, "");
					ps.setObject(14, "");
				} else {
					ps.setObject(13,
							ordLnDlyPk.substring(0, ordLnDlyPk.length() - 6));
					ps.setObject(14,
							ordLnDlyPk.substring(0, ordLnDlyPk.length() - 3));
				}
				ps.setObject(15, ordLnDlyPk);
				ps.setObject(16, orderNo);
			    ps.setObject(17, orderSeq);
				ps.setObject(18, deliveryNo);
				ps.setObject(19, matGpM.getMatNo());
				ps.executeUpdate();
				ps.close();

				//利库备料需求订单时修改管好队列
				if(processCdoe.equals("G") && plnOrderSJgx.getOrderSource().equals("备料需求"))
				{
					String sqlUpdatePortMch = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdatePortMch");
					ps = conn.prepareStatement(sqlUpdatePortMch);
					ps.setString(1,matGpM.getHeatPlanNo());
					ps.setString(2,matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();
				}
			}
			if (outnumCut == 0) {
				outnumCut = 1;
			}
			String heatPlanNoNew = "";
			// 修改排产订单表利库量
			if (processCdoe.equals("D")) {
				if (yOrderNo.equals("0")) {
					String updateZgS = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdateZgLk");
					ps = conn.prepareStatement(updateZgS);
					ps.setObject(1, actWt);
					ps.setObject(2, takeCount / outnumCut);
					ps.setObject(3, proPlanId);
					ps.setObject(4, gxPlanNo);
					ps.executeUpdate();
					ps.close();

					// 生产本工序炉计划
					PlnZyZgMEntity plnZgM = new PlnZyZgMEntity();
					// 算预计成品吨
					double aimOutdiam = Double.parseDouble(plnOrderSZg
							.getAimoutdiameter());
					double aimwallthick = Double.parseDouble(plnOrderSZg
							.getAimwallthick());
					double weightOne = (0.02466 * aimwallthick * (aimOutdiam - aimwallthick)) / 1000;


					heatPlanNoNew = corePlnZyFurnM.getMaxHeatPlanNo(conn,
							proPlanId + "6", proPlanId, "D");
					// 获取炉计划顺序号
					int gxProSeq = corePlnZyFurnM.getMaxGxPlnSeq(conn,
							plnOrderSZg.getPlineCode(), "D");
					plnZgM.setHeatPlanNo(heatPlanNoNew);
					plnZgM.setJudgeStoveNo(judgeStoveNo);
					plnZgM.setStoveNo(stoveNo);
					plnZgM.setFlagStoveNo(flagStoveNo);
					plnZgM.setFeedHeatNo(judgeStoveNo);
					plnZgM.setGxProSeq(String.valueOf(gxProSeq));
					String sqlupper = "SELECT T.UPPER_HEATPLAN_ID,T.UPPER_PROCESS_CODE FROM PLN_ZY_ZG_M T WHERE T.HEAT_PLAN_NO='"
							+ heatPlanNoOld + "'";
					ps = conn.prepareStatement(sqlupper);
					rs = ps.executeQuery();
					if (rs.next()) {
						plnZgM.setUpperHeatplanId(rs
								.getString("UPPER_HEATPLAN_ID"));
						plnZgM.setUpperProcessCode(rs
								.getString("UPPER_PROCESS_CODE"));
					}
					rs.close();
					ps.close();

					plnZgM.setZyBatchId(zyBatchId);
					plnZgM.setPlanstatus("40");
					plnZgM.setPlineCode(plnOrderSZg.getPlineCode());
					plnZgM.setPlineName(plnOrderSZg.getPlineName());
					if (!plnOrderSZg.getDecision().equals("A")) {
						// 通过制程判定轧管是否末工序
						if (plnOrderSZg.getWholeBacklogDesc().contains("镦拔扩")) {
							plnZgM.setNextProcessCode("E");
						} else if (plnOrderSZg.getWholeBacklogDesc().contains(
								"热处理")) {
							plnZgM.setNextProcessCode("F");
						} else if (plnOrderSZg.getWholeBacklogDesc().contains(
								"加工")) {
							plnZgM.setNextProcessCode("G");
						} else {
							if (plnOrderSZg.getOrdLnDlyPk().contains("ZZBY-J")) {
								plnZgM.setNextProcessCode("H");
							} else if (plnOrderSZg.getOrdLnDlyPk().contains(
									"ZZBY-D")) {
								plnZgM.setNextProcessCode("G");
							} else {
								plnZgM.setNextProcessCode("");
							}
						}
						plnZgM.setIsendgx("0");
					} else {
						plnZgM.setNextProcessCode("");
						plnZgM.setIsendgx("1");
					}
					// 末工序获取去向
					String gowWhere = ComPlanFurnace.getPlineCodeGroup(conn,
							plnOrderSZg.getPlineCode(),
							plnOrderSZg.getProPlanId(),
							plnOrderSZg.getGxPlanNo());
					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 = conn.prepareStatement(sqlGroup);
						ps.setObject(1, plnOrderSZg.getPlineCode());
						ps.setObject(2, gowWhere);
						rs = ps.executeQuery();
						if (rs.next()) {
							plnZgM.setGowhereName(rs.getString("STORAGE_NAME"));
							plnZgM.setGowhereCode(rs.getString("STORAGE_NO"));
						}
						rs.close();
						ps.close();
					}
					plnZgM.setIfMatchOdd("6");
					plnZgM.setIfDoHeatPlan("1");
					plnZgM.setProPlanId(plnOrderSZg.getProPlanId());
					plnZgM.setGxPlanNo(plnOrderSZg.getGxPlanNo());
					plnZgM.setCcmProPlanId("");
					plnZgM.setCcmGxPlanNo("");
					plnZgM.setGradecode(matTrack.getGradecode());
					plnZgM.setGradename(matTrack.getGradename());
					plnZgM.setSteelcode(matTrack.getSteelcode());
					plnZgM.setSteelname(matTrack.getSteelname());

					// 查询产出物料
					String sqlBom = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.queryBaseMaterialDPl");
					sqlBom += " AND T.D_OUT_MATERIAL_NO=?  AND T.SPEC_CODE_R=?";
					ps = conn.prepareStatement(sqlBom);
					ps.setObject(1, plnOrderSZg.getOrdLnDlyPk());
					ps.setObject(2, plnOrderSZg.getIndexSeq());
					ps.setObject(3, plnOrderSZg.getCraftSeq());
					ps.setObject(4, outwlId);
					ps.setObject(5, plnOrderSZg.getSpecCode());
					rs = ps.executeQuery();
					if (rs.next()) {
						plnZgM.setInwlId(rs.getString("IN_MATERIAL_NO"));
						plnZgM.setInwlDesc(rs.getString("IN_MATERIAL_DESC"));
					} else {
						plnZgM.setInwlId(plnOrderSZg.getInwlId());
						plnZgM.setInwlDesc(plnOrderSZg.getInwlDesc());
					}
					rs.close();
					ps.close();
					plnZgM.setOutwlId(plnOrderSZg.getOutwlId());
					plnZgM.setOutwlDesc(plnOrderSZg.getOutwlDesc());
					plnZgM.setBom(plnOrderSZg.getBom());

					plnZgM.setWholeBacklog(plnOrderSZg.getWholeBacklog());
					plnZgM.setPassCode(plnOrderSZg.getPassCode());
					plnZgM.setPassName(plnOrderSZg.getPassName());
					plnZgM.setPlnInsingleNum(String.valueOf(takeCount));
					plnZgM.setPlnInsingleWt(String.valueOf(actWt));

					plnZgM.setProcessCodeC(plnOrderSZg.getProcessCodeC());
					plnZgM.setProcessDescC(plnOrderSZg.getProcessDescC());
					plnZgM.setOrderSource(plnOrderSZg.getOrderSource());
					plnZgM.setOrderNo(plnOrderSZg.getOrderNo());
					plnZgM.setOrderSeq(plnOrderSZg.getOrderSeq());
					plnZgM.setDeliveryNo(plnOrderSZg.getDeliveryNo());
					plnZgM.setOrdLnDlyPk(plnOrderSZg.getOrdLnDlyPk());
					plnZgM.setReqBlId(plnOrderSZg.getReqBlId());
					plnZgM.setIfExport(plnOrderSZg.getIfExport());
					plnZgM.setPriority(plnOrderSZg.getPriority());
					plnZgM.setPriorityMemo(plnOrderSZg.getPriorityMemo());
					plnZgM.setProMonth(plnOrderSZg.getProMonth());
					plnZgM.setIfLenControl(plnOrderSZg.getIfLenControl());
					plnZgM.setIfMinusSicRoll(plnOrderSZg.getIfMinusSicRoll());
					plnZgM.setProdStandard(plnOrderSZg.getProdStandard());
					plnZgM.setOutputStandard(plnOrderSZg.getOutputStandard());
					plnZgM.setDecision(plnOrderSZg.getDecision());
					plnZgM.setProgyMemo(plnOrderSZg.getProgyMemo());
					plnZgM.setProduccode(plnOrderSZg.getProduccode());
					plnZgM.setProducname(plnOrderSZg.getProducname());
					plnZgM.setModelCode(plnOrderSZg.getModelCode());
					plnZgM.setModelDesc(plnOrderSZg.getModelDesc());
					plnZgM.setOutdiameter(plnOrderSZg.getOutdiameter());
					plnZgM.setWallthick(plnOrderSZg.getWallthick());
					plnZgM.setAimoutdiameter(plnOrderSZg.getAimoutdiameter());
					plnZgM.setAimwallthick(plnOrderSZg.getAimwallthick());
					plnZgM.setThicknessWall(plnOrderSZg.getThicknessWall());
					plnZgM.setLenCutend(plnOrderSZg.getLenCutend());
					plnZgM.setLenCuthead(plnOrderSZg.getLenCuthead());
					plnZgM.setHeatPlanNoOld(heatPlanNoOld);
					if (!plnOrderSZg.getSiglLen().equals("")) {
						double lenMin = Double.parseDouble(plnOrderSZg
								.getAimlength())
								- Double.parseDouble(plnOrderSZg
										.getEndlenSpecstd());

						lenMin = (int) (Double.parseDouble(plnOrderSZg
								.getAimlength()) / Double
								.parseDouble(plnOrderSZg.getSiglLen()))
								* Double.parseDouble(plnOrderSZg.getSiglLen());
						if (lenMin
								- Double.parseDouble(plnOrderSZg
										.getLenRollMin()) < 0) {
							lenMin = Double.parseDouble(plnOrderSZg
									.getLenRollMin());
						}

						double lenMax = lenMin
								+ Double.parseDouble(plnOrderSZg
										.getEndlenSpecstd());
						// 判定是否除以单倍尺长可以整除
						plnZgM.setLenRollMax(String.valueOf(lenMax));
						plnZgM.setLenRollMin(String.valueOf(lenMin));
					} else {
						plnZgM.setLenRollMax(plnOrderSZg.getLenRollMax());
						plnZgM.setLenRollMin(plnOrderSZg.getLenRollMin());
					}

					plnZgM.setOutnumCut("1");
					plnZgM.setAimlength(plnOrderSZg.getAimlength());
					plnZgM.setRollLength(plnOrderSZg.getRollLength());

					plnZgM.setPlnOutsingleNum(String.valueOf(takeCount));
					plnZgM.setPlnOutsingleW(String.valueOf(actWt));
					plnZgM.setReducedWt(String.valueOf(actWt));
					plnZgM.setLenGpSingle(String.valueOf(plnOrderSZg
							.getLenGpSingle()));
					plnZgM.setDiameter(plnOrderSZg.getDiameterGp());
					plnZgM.setWtGpSingle(String.valueOf(weightOne));
					plnZgM.setCic(cic);
					plnZgM.setSic(sic);
					plnZgM.setDic(dic);
					plnZgM.setPic(pic);

					plnZgM.setProDay(dFormat.format(dFormat.parse(dateTime)));
					plnZgM.setBalYearMonth(dfMonth.format(dfMonth
							.parse(dateTime)));
					plnZgM.setCreateName(userName);
					plnZgM.setCreateTime(dateTime);
					plnZgM.setCutType(plnOrderSZg.getPassive());
					plnZgM.setIfMonitor(plnOrderSZg.getIfMonitorZg());
					plnZgM.setDiameterMandrel(plnOrderSZg.getDiameterMandrel());
					plnZgM.setPrdcrNo(plnOrderSZg.getPrdcrNo());
					plnZgM.setMonitorPoint(plnOrderSZg.getMonitorPoint());
					plnZgM.setWholeBacklog(plnOrderSZg.getWholeBacklog());
					plnZgM.setWholeBacklogDesc(plnOrderSZg
							.getWholeBacklogDesc());
					plnZgM.setCraftFileMan(plnOrderSZg.getCraftFileMan());
					plnZgM.setCraftFileNo(plnOrderSZg.getCraftFileNo());
					plnZgM.setCraftSeq(plnOrderSZg.getCraftSeq());
					plnZgM.setSecCraftFileNo(plnOrderSZg.getSecCraftFileNo());
					plnZgM.setStationRoad(plnOrderSZg.getStationRoad());
					plnZgM.setIndexSeq(plnOrderSZg.getIndexSeq());
					plnZgM.setGptype("1");
					if (matOrigin.equals("801301")) {
						plnZgM.setOutsBilletFl("1");// 外购
					} else {
						plnZgM.setOutsBilletFl("0");// 自炼
					}
					plnZgM.setPlnType("0");
					// 新增轧管虚拟炉计划
					String sqlZgM = EntityTool.fillSqlByEntity(
							CoreXmlSqlParsersFactory
									.getSql("FrmEndLibrary.addPlnZyZgM"),
							plnZgM);
					ps = conn.prepareStatement(sqlZgM);
					ps.executeUpdate();
					ps.close();

					String feedSeq = FrmPlanStoveD.getMaxFeedSeq(conn,
							dFormat.format(dFormat.parse(dateTime)),
							plnOrderSZg.getPlineCode());
					String lotSeq = FrmPlanStoveD.getMaxLotSeq(
							conn,
							plnOrderSZg.getProPlanId() + "-"
									+ plnOrderSZg.getGxPlanNo(),
							plnOrderSZg.getZyBatchId());
					MilPlanEntity milPln = new MilPlanEntity();
					milPln.setPrdcrNo(plnZgM.getPrdcrNo());
					milPln.setIfMonitor(plnZgM.getIfMonitor());
					milPln.setIfProduct(ifProduct);
					milPln.setCraftSeq(plnZgM.getCraftSeq());
					milPln.setCic(cic);
					milPln.setIndexSeq(plnZgM.getIndexSeq());
					milPln.setPic(pic);
					milPln.setId(heatPlanNoNew);
					milPln.setSeq(plnOrderSZg.getProPlanId() + "-"
							+ plnOrderSZg.getGxPlanNo());
					milPln.setStoveNo(stoveNo);
					milPln.setJudgeStoveNo(judgeStoveNo + "-" + "01");
					milPln.setLotNo(zyBatchId);
					milPln.setContractNo(plnZgM.getOrderNo() + "/"
							+ plnZgM.getOrderSeq());
					milPln.setImpProcess(plnZgM.getCraftFileNo());
					milPln.setPlineCode(plnZgM.getPlineCode());
					milPln.setProducer(plnZgM.getMonitordemand());
					milPln.setProcessStatus(plnZgM.getProcessDescC());
					milPln.setDbLength(plnZgM.getLenGpSingle());
					milPln.setDbHeight(plnZgM.getWtGpSingle());
					milPln.setRollLength(plnZgM.getRollLength());
					milPln.setSawNum("1");
					milPln.setTargetLength(plnZgM.getAimlength());
					milPln.setFinishUser(plnZgM.getFinalUserDesc());
					milPln.setTargetLiabrary("");
					milPln.setVarieties(plnZgM.getProducname());
					milPln.setVarietiesCode(plnZgM.getProduccode());
					milPln.setBackSlabFlag("2");
					String outdiameZg = new BigDecimal(
							plnOrderSZg.getOutdiameterZg()).setScale(2,
							RoundingMode.HALF_UP).toString();
					String wallthZg = new BigDecimal(
							plnOrderSZg.getWallthickZg()).setScale(2,
							RoundingMode.HALF_UP).toString();
					milPln.setPipeSize(outdiameZg + "*" + wallthZg);
					// milPln.setPipeSize(plnOrderSZg.getSpecName());
					String sql = "SELECT T.Spec_Code FROM COM_BASE_SPEC T WHERE T.SPEC_NAME=? AND T.VALIDFLAG='1'";
					ps = conn.prepareStatement(sql);
					ps.setObject(1, outdiameZg + "x" + wallthZg);
					rs = ps.executeQuery();
					if (rs.next()) {
						milPln.setPipeSizeCode(rs.getString("Spec_Code"));
					}
					rs.close();
					ps.close();
					milPln.setBuckleType(plnZgM.getModelDesc());
					milPln.setBuckleTypeCode(plnZgM.getModelCode());
					milPln.setLengthRange(plnZgM.getLenRollMin() + "-"
							+ plnZgM.getLenRollMax());
					milPln.setRollStandrad(plnZgM.getStdName());
					milPln.setPipeSection(plnOrderSZg.getDiameterGp());
					milPln.setSteelcode(plnZgM.getSteelcode());
					milPln.setSteelname(plnZgM.getSteelname());
					milPln.setGradecode(plnZgM.getGradecode());
					milPln.setGradename(plnZgM.getGradename());
					String steelStandrad = "";
					if (ifProduct.equals("1")) {
						steelStandrad = cic + "+" + pic + "+" + sic + "+" + dic;
					} else {
						steelStandrad = cic + "+" + sic + "+" + dic;
					}

					if (steelStandrad.replace("+", "").equals("")) {
						steelStandrad = plnZgM.getCraftFileNo();
					}
					milPln.setSteelStandrad(steelStandrad);
					milPln.setTarget(plnZgM.getDecision());
					milPln.setBranch(plnZgM.getPlnInsingleNum());
					milPln.setTon(plnZgM.getPlnInsingleWt());
					milPln.setDbNum(plnZgM.getPlnInsingleNum());
					milPln.setTom(dateTime);
					milPln.setCutHeadLengthp(plnZgM.getLenCuthead());
					milPln.setCutTrailLengthp(plnZgM.getLenCutend());
					milPln.setControlThickp(plnZgM.getAimwallthick());
					milPln.setProduceStandrad(plnZgM.getOutputStandard());
					milPln.setFeedSeq(feedSeq);
					milPln.setLotSeq(lotSeq);
					milPln.setFeedHeatNo(judgeStoveNo);
					milPln.setLengthcp(plnZgM.getLengthdisc());
					milPln.setCodeSampleFlag("0");
					milPln.setRollStandradCode(plnZgM.getStdCode());
					milPln.setStdStyle(plnZgM.getStdStyle());
					milPln.setStdStyleDesc(plnZgM.getStdStyleDesc());
					milPln.setCheckNo("");
					milPln.setOrdLnDlyPk(plnZgM.getOrdLnDlyPk() + "-"
							+ plnZgM.getPlnDivideId());
					if (plnZgM.getDecision().contains("A")) {
						milPln.setPrtFlag("1");
					} else {
						milPln.setPrtFlag("0");
					}
					milPln.setProPlanId(plnOrderSZg.getProPlanId());
					milPln.setGxPlanNo(plnOrderSZg.getGxPlanNo());
					String gpType = "铸坯";
					if (plnZgM.getGptype().equals("2")) {
						gpType = "锻坯";
					}
					milPln.setTubeType(gpType);
					String tubSour = "自炼";
					if (plnZgM.getOutsBilletFl().equals("1")) {
						tubSour = "外购";
					}
					milPln.setTubeSuorce(tubSour);
					milPln.setType(plnZgM.getPlnType());
					milPln.setStatus("99");
					milPln.setNodeStatus("99");
					milPln.setIsLoad("1");
					// 新增炉计划接收表
					String addSqlPln = EntityTool
							.fillSqlByEntity(CoreXmlSqlParsersFactory
									.getSql("FrmEndLibrary.AddMilPlan"), milPln);
					ps = conn.prepareStatement(addSqlPln);
					ps.executeUpdate();
					ps.close();
					// }
					String heatPlanSqe = "";
					PlnZyZgCEntity plnZgC = new PlnZyZgCEntity();
					plnZgC.setHeatPlanNo(heatPlanNoNew);
					plnZgC.setJugdeApplyCode("");
					plnZgC.setStoveNo(stoveNo);
					plnZgC.setZyBatchId(zyBatchId);
					plnZgC.setJudgeStoveNo(judgeStoveNo);
					plnZgC.setFlagStoveNo(flagStoveNo);
					plnZgC.setFeedHeatNo(judgeStoveNo);
					plnZgC.setProPlanId(plnOrderSZg.getProPlanId());
					plnZgC.setGxPlanNo(plnOrderSZg.getGxPlanNo());
					plnZgC.setPlineCode(plnOrderSZg.getPlineCode());
					plnZgC.setPlineName(plnOrderSZg.getPlineName());
					plnZgC.setLenGpSingle(plnOrderSZg.getLenGpSingle());
					plnZgC.setDiameter(plnOrderSZg.getDiameterGp());
					plnZgC.setWtGpSingle(String.valueOf(weightOne));
					plnZgC.setCutNumGp("1");
					plnZgC.setLengthM("");
					plnZgC.setWeightM("");
					plnZgC.setPlanIndoubleNum(String.valueOf(takeCount));
					plnZgC.setPlanIndoubleWt(String.valueOf(actWt));
					plnZgC.setCreateName(userName);
					plnZgC.setCreateTime(dateTime);
					plnZgC.setCutNumOld("");
					plnZgC.setLenGpSingleOld(plnOrderSZg.getLenGpSingle());

					plnZgC.setCutLength("");
					plnZgC.setCutWeight("");
					plnZgC.setCutTarget("");

					plnZgC.setLengthMOld("");
					plnZgC.setPlanWeigth(String.valueOf(weightOne));
					// 获取炉计划顺序号
					heatPlanSqe = corePlnZyFurnM.getHeatPlanSeq(conn,
							heatPlanNoNew, "D");
					plnZgC.setHeatPlanSqe(heatPlanSqe);
					// 新增轧管实际炉计划
					String sqlZgC = EntityTool.fillSqlByEntity(
							CoreXmlSqlParsersFactory
									.getSql("FrmEndLibrary.addPlnZyZgC"),
							plnZgC);
					ps = conn.prepareStatement(sqlZgC);
					ps.executeUpdate();
					ps.close();

					MilFeedPlanEntity milFeed = new MilFeedPlanEntity();
					milFeed.setFeedRowNo(heatPlanSqe);
					milFeed.setSeq("");
					milFeed.setLotNo(zyBatchId);
					milFeed.setStoveNo(stoveNo);
					milFeed.setJudgeStoveNo(judgeStoveNo + "-" + "01");
					milFeed.setPlineCode(plnZgM.getPlineCode());
					milFeed.setDbNum("1");
					milFeed.setMatHeight(String.valueOf("0"));
					milFeed.setMatTotalHeight(plnZgC.getPlanIndoubleWt());
					milFeed.setFeedNum(plnZgC.getPlanIndoubleNum());
					milFeed.setFeedLength(plnZgC.getLengthMOld());
					milFeed.setUseLength(plnZgC.getLengthM());
					milFeed.setCutTarget(plnZgC.getCutTarget());
					milFeed.setCutLength(plnZgC.getCutLength());
					milFeed.setCutWeight(plnZgC.getCutWeight());
					milFeed.setRemark("");
					milFeed.setDbLength(plnZgC.getLenGpSingle());
					milFeed.setNonUseLength(plnZgC.getCutLength());
					milFeed.setPipeSection(plnZgC.getDiameter());
					milFeed.setDbHeight(plnZgC.getWtGpSingle());
					milFeed.setProPlanId(plnZgC.getProPlanId());
					milFeed.setGxPlanNo(plnZgC.getGxPlanNo());
					milFeed.setFeedNumPlan(plnZgC.getPlanIndoubleNum());
					milFeed.setCreateName(userName);
					milFeed.setCreateTime(dateTime);
					// 新增上料行表
					String addSqlPls = EntityTool.fillSqlByEntity(
							CoreXmlSqlParsersFactory
									.getSql("FrmPlanStoveD.AddMilFeedPlan"),
							milFeed);
					ps = conn.prepareStatement(addSqlPls);
					ps.executeUpdate();
					ps.close();
					// 修改庫存本工序炉计划ID
					String updateMat = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updatePressBgx");
					updateMat += " WHERE T.JUDGE_STOVE_NO = ?    AND T.BATCH_NO = ?   "
							+ "AND T.BATCH_GROUD_NO = ?   AND T.PROCESS_CDOE = ?  "
							+ " AND T.PRO_ORDER_ID = ?   AND T.GX_PLAN_NO = ?   AND T.QCM_STAUS = '00'";
					ps = conn.prepareStatement(updateMat);
					if (falg.equals("1")) {
						ps.setObject(1, heatPlanNo);
					} else {
						ps.setObject(1, heatPlanNoNew);
					}
					ps.setObject(2, matTrack.getJudgeStoveNo());
					ps.setObject(3, matTrack.getBatchNo());
					ps.setObject(4, matTrack.getBatchGroudNo());
					ps.setObject(5, processCdoeBgx);
					ps.setObject(6, proPlanId);
					ps.setObject(7, gxPlanNo);
					ps.executeUpdate();
					ps.close();

					int countColse = 0;
					// 查询进程表量 （预计支-废品-判定支=0）
					String sqlMil = "SELECT NVL(T.YJZ - T.UNDETERMINEDNUM - T.SCRAPNUM - T.WWFPZ,0) -"
							+ "(SELECT NVL(SUM(T1.ACT_COUNT), 0) ACT_COUNT FROM QCM_ZG_JUGDE_APPLY T1 WHERE T1.PROCESS_CODE = 'D' "
							+ " AND (T1.JUDGE_RESULT_CODE IN ('40740701','40740709','40740707') OR T1.INSTANCY_FLAG = '1') AND T1.IS_FLAG='0' AND T1.HEAT_PLAN_NO = T.ID) ACOUNT FROM MIL_PROCESSES T WHERE T.ID = ?";
					ps = conn.prepareStatement(sqlMil);
					ps.setObject(1, heatPlanNoOld);
					rs = ps.executeQuery();
					if (rs.next()) {
						countColse = rs.getInt("ACOUNT");
					}
					rs.close();
					ps.close();
					if (countColse == 0) {
						// 修改本工序炉计划状态--关闭
						String updateZgM = "UPDATE PLN_ZY_ZG_M T SET T.PLANSTATUS='40',T.IS_CLOSE='0' WHERE T.HEAT_PLAN_NO=?";
						ps = conn.prepareStatement(updateZgM);
						ps.setObject(1, heatPlanNoOld);
						ps.executeUpdate();
						ps.close();
					}
				} else {
					// 修改庫存本工序炉计划ID
					String updateMat = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updatePressBgx");
					updateMat += " WHERE T.JUDGE_STOVE_NO = ?    AND T.BATCH_NO = ?   "
							+ "AND T.BATCH_GROUD_NO = ?   AND T.PROCESS_CDOE = ?  "
							+ " AND T.PRO_ORDER_ID = ?   AND T.GX_PLAN_NO = ?   AND T.QCM_STAUS = '00'";
					ps = conn.prepareStatement(updateMat);
					ps.setObject(1, herdOLD);
					ps.setObject(2, matTrack.getJudgeStoveNo());
					ps.setObject(3, matTrack.getBatchNo());
					ps.setObject(4, matTrack.getBatchGroudNo());
					ps.setObject(5, processCdoeBgx);
					ps.setObject(6, proPlanId);
					ps.setObject(7, gxPlanNo);
					ps.executeUpdate();
					ps.close();
				}

			} else if (processCdoe.equals("E")) {
				if (yOrderNo.equals("0")) {
					String updateZgS = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdateDbkLk");
					ps = conn.prepareStatement(updateZgS);
					ps.setObject(1, actWt);
					ps.setObject(2, takeCount);
					ps.setObject(3, proPlanId);
					ps.setObject(4, gxPlanNo);
					ps.executeUpdate();
					ps.close();


					PlnZyDbkMEntity plnDbkM = new PlnZyDbkMEntity();
					heatPlanNoNew = corePlanFurnProM.getMaxHeatPlanNo(conn,
							plnOrderSDbk.getProPlanId(),
							plnOrderSDbk.getProPlanId(), "E");
					// 获取炉计划顺序号
					int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(conn,
							plnDbkM.getPlineCode(), "E");
					plnDbkM.setHeatPlanNoOld(heatPlanNoOld);
					plnDbkM.setPassCode(plnOrderSDbk.getPassCode());
					plnDbkM.setPassName(plnOrderSDbk.getPassName());
					plnDbkM.setDecision(plnOrderSDbk.getDecision());
					plnDbkM.setStoveNo(stoveNo);
					plnDbkM.setFeedHeatNo(judgeStoveNo);
					plnDbkM.setJudgeStoveNo(judgeStoveNo);
					plnDbkM.setFlagStoveNo(flagStoveNo);
					plnDbkM.setPlanstatus("40");
					String sqlupper = "SELECT T.UPPER_HEATPLAN_ID,T.UPPER_PROCESS_CODE FROM PLN_ZY_DBK_M T WHERE T.HEAT_PLAN_NO='"
							+ heatPlanNoOld + "'";
					ps = conn.prepareStatement(sqlupper);
					rs = ps.executeQuery();
					if (rs.next()) {
						plnDbkM.setUpperHeatplanId(rs
								.getString("UPPER_HEATPLAN_ID"));
						plnDbkM.setUpperProcessCode(rs
								.getString("UPPER_PROCESS_CODE"));
					}
					rs.close();
					ps.close();
					plnDbkM.setPlineCode(plnOrderSDbk.getPlineCode());
					plnDbkM.setPlineName(plnOrderSDbk.getPlineName());
					plnDbkM.setProcessCodeC(plnOrderSDbk.getProcessCodeC());
					plnDbkM.setProcessDescC(plnOrderSDbk.getProcessDescC());

					// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
					String sqlBom = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.queryBaseMaterialEPl");
					sqlBom += " AND T.E_OUT_MATERIAL_NO=?  AND T.SPEC_CODE_R=?";
					ps = conn.prepareStatement(sqlBom);
					ps.setObject(1, plnOrderSDbk.getOrdLnDlyPk());
					ps.setObject(2, plnOrderSDbk.getIndexSeq());
					ps.setObject(3, plnOrderSDbk.getCraftSeq());
					ps.setObject(4, outwlId);
					ps.setObject(5, plnOrderSDbk.getSpecCode());
					rs = ps.executeQuery();
					if (rs.next()) {
						plnDbkM.setInwlId(rs.getString("IN_MATERIAL_NO"));
						plnDbkM.setInwlDesc(rs.getString("IN_MATERIAL_DESC"));
						plnDbkM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));

					} else {
						plnDbkM.setInwlId(plnOrderSDbk.getOutwlId());
						plnDbkM.setInwlDesc(plnOrderSDbk.getOutwlDesc());
					}
					rs.close();
					ps.close();
					plnDbkM.setBom(plnOrderSDbk.getBom());
					plnDbkM.setOutwlId(plnOrderSDbk.getOutwlId());
					plnDbkM.setOutwlDesc(plnOrderSDbk.getOutwlDesc());
					// 通过制程判定镦拔扩是否末工序
					if (!plnOrderSDbk.getDecision().equals("A")) {
						if (plnOrderSDbk.getWholeBacklogDesc().contains("热处理")) {
							plnDbkM.setNextProcessCode("F");
						} else if (plnOrderSDbk.getWholeBacklogDesc().contains(
								"加工")) {
							plnDbkM.setNextProcessCode("G");
						} else if (plnOrderSDbk.getWholeBacklogDesc().contains(
								"接箍")) {
							plnDbkM.setNextProcessCode("H");
						} else {
							if (plnOrderSDbk.getOrdLnDlyPk().contains("ZZBY-J")) {
								plnDbkM.setNextProcessCode("H");
							} else if (plnOrderSDbk.getOrdLnDlyPk().contains(
									"ZZBY-D")) {
								plnDbkM.setNextProcessCode("G");
							} else {
								plnDbkM.setNextProcessCode("");
							}
						}
						plnDbkM.setIsendgx("0");
					} else {
						plnDbkM.setNextProcessCode("");
						plnDbkM.setIsendgx("1");
					}
					String gowWhere = corePlanFurnProM.getPlineCodeGroup(conn,
							plnOrderSDbk.getPlineCode(),
							plnOrderSDbk.getProPlanId(),
							plnOrderSDbk.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 = conn.prepareStatement(sqlGroup);
						ps.setObject(1, plnOrderSDbk.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("6");
					plnDbkM.setIfDoHeatPlan("1");
					plnDbkM.setProPlanId(plnOrderSDbk.getProPlanId());
					plnDbkM.setGxPlanNo(plnOrderSDbk.getGxPlanNo());
					plnDbkM.setSpecCode(plnOrderSDbk.getSpecCode());
					plnDbkM.setSpecName(plnOrderSDbk.getSpecName());
					plnDbkM.setGradecode(matTrack.getGradecode());
					plnDbkM.setGradename(matTrack.getGradename());
					plnDbkM.setSteelcode(plnOrderSDbk.getSteelcode());
					plnDbkM.setSteelname(plnOrderSDbk.getSteelname());
					plnDbkM.setProduccode(plnOrderSDbk.getProduccode());
					plnDbkM.setProducname(plnOrderSDbk.getProducname());

					plnDbkM.setModelCode(plnOrderSDbk.getModelCode());
					plnDbkM.setModelDesc(plnOrderSDbk.getModelDesc());
					// 单倍支吨
					plnDbkM.setPlnInsingleNum(String.valueOf(takeCount));
					plnDbkM.setPlnInsingleWt(String.valueOf(actWt));
					plnDbkM.setPlnOutsingleNum(String.valueOf(takeCount));
					double burnoutRate = 0;
					// 查询产线烧损
					String sql = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
							+ plnOrderSDbk.getPlineCode() + "'";
					ps = conn.prepareStatement(sql);
					rs = ps.executeQuery();
					if (rs.next()) {
						burnoutRate = rs.getDouble("BURNOUT_RATE");
					}
					rs.close();
					ps.close();
					double cLenCut = Double.parseDouble(plnOrderSDbk
							.getLenCuthead())
							+ Double.parseDouble(plnOrderSDbk.getLenCutend());
					double yjWt = actWt - actWt * burnoutRate - cLenCut / 1000;
					plnDbkM.setPlnOutsingleW(String.valueOf(yjWt));
					// 查询轧管排产信息
					String sqlZg = CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.QueryWgZg");
					ps = conn.prepareStatement(sqlZg);
					ps.setObject(1, plnOrderSDbk.getOrdLnDlyPk());
					// ps.setObject(2, plnOrderSDbk.getPlnDivideId());
					rs = ps.executeQuery();
					if (rs.next()) {
						plnDbkM.setProdStandard(rs.getString("PROD_STANDARD"));
						plnDbkM.setOutputStandard(rs
								.getString("Output_Standard"));
						plnDbkM.setSecCraftFileNo(rs
								.getString("SEC_CRAFT_FILE_NO"));
						plnDbkM.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
					}
					rs.close();
					ps.close();
					plnDbkM.setLengthIn(lengthIn);
					plnDbkM.setLengthmaxIn(lengthmaxIn);
					plnDbkM.setLengthminIn(lengthminIn);

					plnDbkM.setStdCode(plnOrderSDbk.getStdCode());
					plnDbkM.setStdName(plnOrderSDbk.getStdName());
					plnDbkM.setStdStyle(plnOrderSDbk.getStdStyle());
					plnDbkM.setStdStyleDesc(plnOrderSDbk.getStdStyleDesc());
					plnDbkM.setOrderSource(plnOrderSDbk.getOrderSource());
					plnDbkM.setOrderNo(plnOrderSDbk.getOrderNo());
					plnDbkM.setOrderSeq(plnOrderSDbk.getOrderSeq());
					plnDbkM.setDeliveryNo(plnOrderSDbk.getDeliveryNo());
					plnDbkM.setOrdLnDlyPk(plnOrderSDbk.getOrdLnDlyPk());
					plnDbkM.setReqBlId(plnOrderSDbk.getReqBlId());
					plnDbkM.setIfExport(plnOrderSDbk.getIfExport());
					plnDbkM.setPriority(plnOrderSDbk.getPriority());
					plnDbkM.setPriorityMemo(plnOrderSDbk.getPriorityMemo());
					plnDbkM.setProMonth(plnOrderSDbk.getProMonth());
					plnDbkM.setIfMonitor(plnOrderSDbk.getIfMonitorDbk());
					plnDbkM.setPrdcrNo(plnOrderSDbk.getPrdcrNo());
					plnDbkM.setMonitorPoint(plnOrderSDbk.getMonitorPoint());
					plnDbkM.setWholeBacklogDesc(plnOrderSDbk
							.getWholeBacklogDesc());
					plnDbkM.setStationRoad(plnOrderSDbk.getStationRoad());

					plnDbkM.setCic(cic);
					plnDbkM.setSic(sic);
					plnDbkM.setDic(dic);
					plnDbkM.setPic(pic);
					plnDbkM.setZyBatchId(zyBatchId);
					plnDbkM.setCraftFileMan(plnOrderSDbk.getCraftFileMan());
					plnDbkM.setCraftFileNo(plnOrderSDbk.getCraftFileNo());
					plnDbkM.setCraftSeq(plnOrderSDbk.getCraftSeq());
					plnDbkM.setOutdiameterIn(outdiameterIn);
					plnDbkM.setWallthickIn(wallthickIn);
					plnDbkM.setAimlength(plnOrderSDbk.getAimlength());
					plnDbkM.setAimoutdiameter(plnOrderSDbk.getAimoutdiameter());
					plnDbkM.setAimwallthick(plnOrderSDbk.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 = conn.prepareStatement(ordLen);
					ps.setObject(1, plnOrderSDbk.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(plnOrderSDbk.getLenCutend());
					plnDbkM.setLenCuthead(plnOrderSDbk.getLenCuthead());
					plnDbkM.setCreateName(userName);
					plnDbkM.setCreateTime(dateTime);
					plnDbkM.setProDay(dateTime.substring(0, 10)
							.replace("-", ""));
					plnDbkM.setBalYearMonth(dateTime.substring(0, 7).replace(
							"-", ""));
					plnDbkM.setIndexSeq(plnOrderSDbk.getIndexSeq());
					plnDbkM.setHeatPlanNo(heatPlanNoNew);
					plnDbkM.setGxProSeq(String.valueOf(gxProSeq));

					// 新增
					String addPlnGxDbk = EntityTool.fillSqlByEntity(
							CoreXmlSqlParsersFactory
									.getSql("FrmEndLibrary.addPlnZyDbkZB"),
							plnDbkM);
					ps = conn.prepareStatement(addPlnGxDbk);
					ps.executeUpdate();
					ps.close();

					PlnZyDbkCEntity plnDbkC = new PlnZyDbkCEntity();
					// 获取炉计划顺序号
					String heatPlanSqe = corePlanFurnProM.getHeatPlanSeq(conn,
							heatPlanNoNew, "E");
					plnDbkC.setHeatPlanNo(heatPlanNoNew);
					plnDbkC.setJugdeApplyCode("");
					plnDbkC.setZyBatchId(zyBatchId);
					plnDbkC.setFeedHeatNo(judgeStoveNo);
					plnDbkC.setJudgeStoveNo(judgeStoveNo);
					plnDbkC.setFlagStoveNo(flagStoveNo);
					plnDbkC.setBatchNo(batchNo);
					plnDbkC.setBatchGroudNo(batchGroupBy);
					plnDbkC.setStoveNo(stoveNo);
					plnDbkC.setProPlanId(plnOrderSDbk.getProPlanId());
					plnDbkC.setGxPlanNo(plnOrderSDbk.getGxPlanNo());
					plnDbkC.setPlineCode(plnOrderSDbk.getPlineCode());
					plnDbkC.setPlineName(plnOrderSDbk.getPlineName());
					plnDbkC.setOutdiameterIn(plnOrderSDbk.getOutdiameterIn());
					plnDbkC.setWallthickIn(plnOrderSDbk.getWallthickIn());
					plnDbkC.setLengthIn(lengthIn);
					plnDbkC.setLengthmaxIn(lengthmaxIn);
					plnDbkC.setLengthminIn(lengthminIn);
					plnDbkC.setPlanIndoubleNum(String.valueOf(takeCount));
					plnDbkC.setPlanIndoubleWt(String.valueOf(actWt));
					plnDbkC.setOutnumCut("1");
					plnDbkC.setHeatPlanSqe(heatPlanSqe);
					// 新增
					String addPlnGxdbkC = EntityTool.fillSqlByEntity(
							CoreXmlSqlParsersFactory
									.getSql("FrmEndLibrary.addPlnZyDbkC"),
							plnDbkC);
					ps = conn.prepareStatement(addPlnGxdbkC);
					ps.executeUpdate();
					ps.close();

					// 修改庫存本工序炉计划ID
					String updateMat = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updatePressBgx");
					updateMat += " WHERE T.JUDGE_STOVE_NO = ?    AND T.BATCH_NO = ?   "
							+ "AND T.BATCH_GROUD_NO = ?   AND T.PROCESS_CDOE = ?  "
							+ " AND T.PRO_ORDER_ID = ?   AND T.GX_PLAN_NO = ?   AND T.QCM_STAUS = '00'";
					ps = conn.prepareStatement(updateMat);
					ps.setObject(1, heatPlanNoNew);
					ps.setObject(2, matTrack.getJudgeStoveNo());
					ps.setObject(3, matTrack.getBatchNo());
					ps.setObject(4, matTrack.getBatchGroudNo());
					ps.setObject(5, processCdoe);
					ps.setObject(6, proPlanId);
					ps.setObject(7, gxPlanNo);
					ps.executeUpdate();
					ps.close();

					// 关闭原炉计划
					String updateMOld = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updateMOldE");
					ps = conn.prepareStatement(updateMOld);
					ps.setObject(1, heatPlanNoOld);
					ps.executeUpdate();
					ps.close();
				} else {
					// 修改庫存本工序炉计划ID
					String updateMat = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updatePressBgx");
					updateMat += " WHERE T.JUDGE_STOVE_NO = ?    AND T.BATCH_NO = ?   "
							+ "AND T.BATCH_GROUD_NO = ?   AND T.PROCESS_CDOE = ?  "
							+ " AND T.PRO_ORDER_ID = ?   AND T.GX_PLAN_NO = ?   AND T.QCM_STAUS = '00'";
					ps = conn.prepareStatement(updateMat);
					ps.setObject(1, herdOLD);
					ps.setObject(2, matTrack.getJudgeStoveNo());
					ps.setObject(3, matTrack.getBatchNo());
					ps.setObject(4, matTrack.getBatchGroudNo());
					ps.setObject(5, processCdoeBgx);
					ps.setObject(6, proPlanId);
					ps.setObject(7, gxPlanNo);
					ps.executeUpdate();
					ps.close();
				}
			} else if (processCdoe.equals("F")) {
				String realRclNum = "";//热处理次数
				if (yOrderNo.equals("0")) {
					String updateZgS = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdateRclLk");
					ps = conn.prepareStatement(updateZgS);
					ps.setObject(1, actWt);
					ps.setObject(2, takeCount);
					ps.setObject(3, proPlanId);
					ps.setObject(4, gxPlanNo);
					ps.executeUpdate();
					ps.close();


					PlnZyRclMEntity plnRclM = new PlnZyRclMEntity();
					heatPlanNoNew = corePlanFurnProM.getMaxHeatPlanNo(conn,
							plnOrderSRcl.getProPlanId(),
							plnOrderSRcl.getProPlanId(), "F");
					// 获取炉计划顺序号
					int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(conn,
							plnOrderSRcl.getPlineCode(), "F");

					// 订单内炉顺序号
					int lotNoR = corePlanFurnProM.getMaxLotNoSqe(conn,
							plnOrderSRcl.getProPlanId(),
							plnOrderSRcl.getGxPlanNo(), "F");
					plnRclM.setHeatPlanNoOld(heatPlanNoOld);
					plnRclM.setLotNoSqe(String.valueOf(lotNoR));
					plnRclM.setDecision(plnOrderSRcl.getDecision());
					plnRclM.setStoveNo(stoveNo);
					plnRclM.setFlagStoveNo(flagStoveNo);
					plnRclM.setFeedHeatNo(judgeStoveNo);
					plnRclM.setJudgeStoveNo(judgeStoveNo);
					plnRclM.setZyBatchId(zyBatchId);
					plnRclM.setPlanstatus(planstatus);
					String sqlupper = "SELECT T.UPPER_HEATPLAN_ID,T.UPPER_PROCESS_CODE FROM PLN_ZY_RCL_M T WHERE T.HEAT_PLAN_NO='"
							+ heatPlanNoOld + "'";
					ps = conn.prepareStatement(sqlupper);
					rs = ps.executeQuery();
					if (rs.next()) {
						plnRclM.setUpperHeatplanId(rs
								.getString("UPPER_HEATPLAN_ID"));
						plnRclM.setUpperProcessCode(rs
								.getString("UPPER_PROCESS_CODE"));
					}
					rs.close();
					ps.close();
					plnRclM.setPlineCode(plnOrderSRcl.getPlineCode());
					plnRclM.setPlineName(plnOrderSRcl.getPlineName());
					plnRclM.setProcessCodeC(plnOrderSRcl.getProcessCodeC());
					plnRclM.setProcessDescC(plnOrderSRcl.getProcessDescC());

					// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
					String sqlBom = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.queryBaseMaterialFPl");
					sqlBom += " AND T.F_OUT_MATERIAL_NO=?  AND T.SPEC_CODE_R=?";
					ps = conn.prepareStatement(sqlBom);
					ps.setObject(1, plnOrderSRcl.getOrdLnDlyPk());
					ps.setObject(2, plnOrderSRcl.getIndexSeq());
					ps.setObject(3, plnOrderSRcl.getCraftSeq());
					ps.setObject(4, outwlId);
					ps.setObject(5, plnOrderSRcl.getSpecCode());
					rs = ps.executeQuery();
					if (rs.next()) {
						plnRclM.setInwlId(rs.getString("IN_MATERIAL_NO"));
						plnRclM.setInwlDesc(rs.getString("IN_MATERIAL_DESC"));
						plnRclM.setBom(rs.getString("BOM"));
						plnRclM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));
					} else {
						plnRclM.setInwlId(plnOrderSRcl.getInwlId());
						plnRclM.setInwlDesc(plnOrderSRcl.getInwlDesc());
						plnRclM.setBom(plnOrderSRcl.getBom());
						// cro.setV_errMsg("未找到判定炉号(" + judgeStoveNo
						// + ")在热处理的产出物料!");
						// return cro;
					}
					rs.close();
					ps.close();
					plnRclM.setOutwlId(plnOrderSRcl.getOutwlId());
					plnRclM.setOutwlDesc(plnOrderSRcl.getOutwlDesc());
					if (!plnOrderSRcl.getDecision().equals("A")) {
						// 通过制程判定是否末工序
						if (plnOrderSRcl.getWholeBacklogDesc().contains("加工")) {
							plnRclM.setNextProcessCode("G");
						} else if (plnOrderSRcl.getWholeBacklogDesc().contains(
								"接箍")) {
							plnRclM.setNextProcessCode("H");
						} else {
							if (plnOrderSRcl.getOrdLnDlyPk().contains("ZZBY-J")) {
								plnRclM.setNextProcessCode("H");
							} else if (plnOrderSRcl.getOrdLnDlyPk().contains(
									"ZZBY-D")) {
								plnRclM.setNextProcessCode("G");
							} else {
								plnRclM.setNextProcessCode("");
							}
						}
						plnRclM.setIsendgx("0");
					} else {
						plnRclM.setNextProcessCode("");
						plnRclM.setIsendgx("1");
					}
					String gowWhere = corePlanFurnProM.getPlineCodeGroup(conn,
							plnOrderSRcl.getPlineCode(),
							plnOrderSRcl.getProPlanId(),
							plnOrderSRcl.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 = conn.prepareStatement(sqlGroup);
						ps.setObject(1, plnOrderSRcl.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("6");
					plnRclM.setIfDoHeatPlan("1");
					plnRclM.setProPlanId(plnOrderSRcl.getProPlanId());
					plnRclM.setGxPlanNo(plnOrderSRcl.getGxPlanNo());
					plnRclM.setGradecode(matTrack.getGradecode());
					plnRclM.setGradename(matTrack.getGradename());
					plnRclM.setSteelcode(plnOrderSRcl.getSteelcode());
					plnRclM.setSteelname(plnOrderSRcl.getSteelname());
					plnRclM.setProduccode(plnOrderSRcl.getProduccode());
					plnRclM.setProducname(plnOrderSRcl.getProducname());
					plnRclM.setSpecCode(plnOrderSRcl.getSpecCode());
					plnRclM.setSpecName(plnOrderSRcl.getSpecName());

					plnRclM.setModelCode(plnOrderSRcl.getModelCode());
					plnRclM.setModelDesc(plnOrderSRcl.getModelDesc());
					// 单倍支吨
					plnRclM.setPlnInsingleNum(String.valueOf(takeCount));
					plnRclM.setPlnInsingleWt(String.valueOf(actWt));
					plnRclM.setPlnOutsingleNum(String.valueOf(takeCount));
					double burnoutRate = 0;
					// 查询产线烧损
					String sql = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
							+ plnOrderSRcl.getPlineCode() + "'";
					ps = conn.prepareStatement(sql);
					rs = ps.executeQuery();
					if (rs.next()) {
						burnoutRate = rs.getDouble("BURNOUT_RATE");
					}
					rs.close();
					ps.close();
					double yjWt = actWt - actWt * burnoutRate;
					plnRclM.setPlnOutsingleW(String.valueOf(yjWt));

					// 查询轧管排产信息
					String sqlZg = CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.QueryWgZg");
					ps = conn.prepareStatement(sqlZg);
					ps.setObject(1, plnOrderSRcl.getOrdLnDlyPk());
					// ps.setObject(2, plnOrderSRcl.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.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
					}
					rs.close();
					ps.close();
					plnRclM.setStdCode(plnOrderSRcl.getStdCode());
					plnRclM.setStdName(plnOrderSRcl.getStdName());
					plnRclM.setStdStyle(plnOrderSRcl.getStdStyle());
					plnRclM.setStdStyleDesc(plnOrderSRcl.getStdStyleDesc());
					plnRclM.setOutdiameterIn(outdiameterIn);
					plnRclM.setWallthickIn(wallthickIn);
					plnRclM.setLengthIn(lengthIn);
					plnRclM.setLengthmaxIn(lengthmaxIn);
					plnRclM.setLengthminIn(lengthminIn);
					plnRclM.setOrderSource(plnOrderSRcl.getOrderSource());
					plnRclM.setOrderNo(plnOrderSRcl.getOrderNo());
					plnRclM.setOrderSeq(plnOrderSRcl.getOrderSeq());
					plnRclM.setDeliveryNo(plnOrderSRcl.getDeliveryNo());
					plnRclM.setOrdLnDlyPk(plnOrderSRcl.getOrdLnDlyPk());
					plnRclM.setReqBlId(plnOrderSRcl.getReqBlId());
					plnRclM.setIfExport(plnOrderSRcl.getIfExport());
					plnRclM.setPriority(plnOrderSRcl.getPriority());
					plnRclM.setPriorityMemo(plnOrderSRcl.getPriorityMemo());
					plnRclM.setProMonth(plnOrderSRcl.getProMonth());
					plnRclM.setIfMonitor(plnOrderSRcl.getIfMonitorRcl());
					plnRclM.setPrdcrNo(plnOrderSRcl.getPrdcrNo());
					plnRclM.setMonitorPoint(plnOrderSRcl.getMonitorPoint());
					plnRclM.setWholeBacklogDesc(plnOrderSRcl
							.getWholeBacklogDesc());
					plnRclM.setStationRoad(plnOrderSRcl.getStationRoad());

					plnRclM.setCic(cic);
					plnRclM.setSic(sic);
					plnRclM.setDic(pic);
					plnRclM.setPic(pic);

					plnRclM.setCraftFileMan(plnOrderSRcl.getCraftFileMan());
					plnRclM.setCraftFileNo(plnOrderSRcl.getCraftFileNo());
					plnRclM.setCraftSeq(plnOrderSRcl.getCraftSeq());
					plnRclM.setOutdiameter(plnOrderSRcl.getOutdiameter());
					plnRclM.setWallthick(plnOrderSRcl.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 = conn.prepareStatement(ordLen);
					ps.setObject(1, plnOrderSRcl.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(userName);
					plnRclM.setCreateTime(dateTime);
					plnRclM.setProDay(dateTime.substring(0, 10)
							.replace("-", ""));
					plnRclM.setBalYearMonth(dateTime.substring(0, 7).replace(
							"-", ""));
					plnRclM.setIndexSeq(plnOrderSRcl.getIndexSeq());
					plnRclM.setHeatPlanNo(heatPlanNoNew);
					plnRclM.setGxProSeq(String.valueOf(gxProSeq));
					// 获取热处理循环次数
					String sqlSeq = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialRcl.QueryProcessSeq1");
					ps = conn.prepareStatement(sqlSeq);
					ps.setObject(1, plnOrderSRcl.getProPlanId());
					ps.setObject(2, plnOrderSRcl.getGxPlanNo());
					ps.setObject(3,heatPlanNoOld);
					rs = ps.executeQuery();
					if (rs.next()) {
						plnRclM.setProcessSeq(rs.getString("PROCESS_SEQ"));
						plnRclM.setRealProcessSeq(rs.getString("REAL_PROCESS_SEQ"));
						realRclNum = rs.getString("REAL_PROCESS_SEQ");
					} else {
						plnRclM.setProcessSeq("1");
						plnRclM.setRealProcessSeq("1");
					}
					rs.close();
					ps.close();
					plnRclM.setIfProduct(ifProduct);
					// 新增热处理虚拟炉计划
					String addPlnGxZg = EntityTool.fillSqlByEntity(
							CoreXmlSqlParsersFactory
									.getSql("FrmEndLibrary.addPlnZyRclBGX"),
							plnRclM);
					ps = conn.prepareStatement(addPlnGxZg);
					ps.executeUpdate();
					ps.close();
					// 新增生产批号
					StoveHelper.updatePlnRclGroup(conn, plnRclM.getProPlanId(),
							plnRclM.getGxPlanNo(), plnRclM.getPic());

					PlnZyRclCEntity plnC = new PlnZyRclCEntity();
					// 获取炉计划顺序号
					String heatPlanSqe = corePlanFurnProM.getHeatPlanSeq(conn,
							heatPlanNoNew, "F");
					plnC.setHeatPlanNo(heatPlanNoNew);
					plnC.setJugdeApplyCode("");
					plnC.setJudgeStoveNo(judgeStoveNo);
					plnC.setFeedHeatNo(judgeStoveNo);
					plnC.setFlagStoveNo(flagStoveNo);
					plnC.setBatchNo(batchNo);
					plnC.setBatchGroudNo(batchGroupBy);
					plnC.setZyBatchId(zyBatchId);
					plnC.setStoveNo(stoveNo);
					plnC.setProPlanId(plnOrderSRcl.getProPlanId());
					plnC.setGxPlanNo(plnOrderSRcl.getGxPlanNo());
					plnC.setPlineCode(plnOrderSRcl.getPlineCode());
					plnC.setPlineName(plnOrderSRcl.getPlineName());
					plnC.setOutdiameterIn(outdiameterIn);
					plnC.setWallthickIn(wallthickIn);
					plnC.setLengthIn(lengthIn);
					plnC.setLengthmaxIn(lengthmaxIn);
					plnC.setLengthminIn(lengthminIn);
					plnC.setPlanIndoubleNum(String.valueOf(takeCount));
					plnC.setPlanIndoubleWt(String.valueOf(actWt));

					plnC.setHeatPlanSqe(heatPlanSqe);
					// 新增
					String addPlnGxRclc = EntityTool
							.fillSqlByEntity(CoreXmlSqlParsersFactory
									.getSql("FrmEndLibrary.addPlnZyRclC"), plnC);
					ps = conn.prepareStatement(addPlnGxRclc);
					ps.executeUpdate();
					ps.close();

					// 修改庫存本工序炉计划ID
					String updateMat = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updatePressBgx");
					if (planstatus.equals("10")) {
						updateMat += " ,T.PRODUCT_FLAG='801401',T.MAT_STATUS='80150103',T.HANGING_FLAG='1',T.PRO_PLAN_ID_NEXT='"
								+ proPlanId
								+ "',T.GX_PLAN_NO_NEXT='"
								+ gxPlanNo
								+ "',T.HEAT_PLAN_NO_NEXT='"
								+ heatPlanNoNew + "'";
						// if (nextProcessCdeo.equals("")) {
						updateMat += ",T.NEXT_PROCESS_CDOE='F',T.NEXT_PROCESS_DESC='热处理'";
						// }
					}
					updateMat += " WHERE T.JUDGE_STOVE_NO = ?    AND T.BATCH_NO = ?   "
							+ "AND T.BATCH_GROUD_NO = ?   AND T.PROCESS_CDOE = ?  "
							+ " AND T.PRO_ORDER_ID = ?   AND T.GX_PLAN_NO = ?   AND T.QCM_STAUS = '00'";
					ps = conn.prepareStatement(updateMat);
					ps.setObject(1, heatPlanNoNew);
					ps.setObject(2, matTrack.getJudgeStoveNo());
					ps.setObject(3, matTrack.getBatchNo());
					ps.setObject(4, matTrack.getBatchGroudNo());
					ps.setObject(5, processCdoe);
					ps.setObject(6, proPlanId);
					ps.setObject(7, gxPlanNo);
					ps.executeUpdate();
					ps.close();


					//修改管号队列炉计划ID
					for(MatBcMEntityPln ms : matGpMlist)
					{
						String updatePortSql = CoreXmlSqlParsersFactory.getSql("FrmEndLibrary.updatePortHtt");
						ps = conn.prepareStatement(updatePortSql);
						ps.setObject(1,heatPlanNoNew);
						ps.setObject(2,ms.getHeatPlanNo());
						ps.setObject(3,ms.getMatNo());
						ps.setObject(4,realRclNum);
						ps.executeUpdate();
						ps.close();
					}

					// 关闭原炉计划
					String updateMOld = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updateMOldF");
					ps = conn.prepareStatement(updateMOld);
					ps.setObject(1, heatPlanNoOld);
					ps.executeUpdate();
					ps.close();
				} else {
					// 修改庫存本工序炉计划ID
					String updateMat = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updatePressBgx");
					updateMat += " WHERE T.JUDGE_STOVE_NO = ?    AND T.BATCH_NO = ?   "
							+ "AND T.BATCH_GROUD_NO = ?   AND T.PROCESS_CDOE = ?  "
							+ " AND T.PRO_ORDER_ID = ?   AND T.GX_PLAN_NO = ?   AND T.QCM_STAUS = '00'";
					ps = conn.prepareStatement(updateMat);
					ps.setObject(1, herdOLD);
					ps.setObject(2, matTrack.getJudgeStoveNo());
					ps.setObject(3, matTrack.getBatchNo());
					ps.setObject(4, matTrack.getBatchGroudNo());
					ps.setObject(5, processCdoeBgx);
					ps.setObject(6, proPlanId);
					ps.setObject(7, gxPlanNo);
					ps.executeUpdate();
					ps.close();
				}

			} else if (processCdoe.equals("G")) {
				if (yOrderNo.equals("0")) {
					String updateZgS = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdateJgxLk");
					ps = conn.prepareStatement(updateZgS);
					ps.setObject(1, actWt);
					ps.setObject(2, takeCount / outnumCut);
					ps.setObject(3, proPlanId);
					ps.setObject(4, gxPlanNo);
					ps.executeUpdate();
					ps.close();


					PlnZyJgxMEntity plnJgxM = new PlnZyJgxMEntity();
					heatPlanNoNew = corePlanFurnProM.getMaxHeatPlanNo(conn,
							plnOrderSJgx.getProPlanId(),
							plnOrderSJgx.getProPlanId(), "G");
					// 获取炉计划顺序号
					// int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(conn,
					// plnOrderSJgx.getPlineCode(), "G");
					plnJgxM.setHeatPlanNoOld(heatPlanNoOld);
					plnJgxM.setDecision(plnOrderSJgx.getDecision());
					plnJgxM.setStoveNo(stoveNo);
					plnJgxM.setZyBatchId(zyBatchId);
					plnJgxM.setFlagStoveNo(flagStoveNo);
					plnJgxM.setFeedHeatNo(judgeStoveNo);
					plnJgxM.setJudgeStoveNo(judgeStoveNo);
					String sqlupper = "SELECT T.UPPER_HEATPLAN_ID,T.UPPER_PROCESS_CODE FROM PLN_ZY_JGX_M T WHERE T.HEAT_PLAN_NO='"
							+ heatPlanNoOld + "'";
					ps = conn.prepareStatement(sqlupper);
					rs = ps.executeQuery();
					if (rs.next()) {
						plnJgxM.setUpperHeatplanId(rs
								.getString("UPPER_HEATPLAN_ID"));
						plnJgxM.setUpperProcessCode(rs
								.getString("UPPER_PROCESS_CODE"));
					}
					rs.close();
					ps.close();
					plnJgxM.setPlanstatus(planstatus);

					plnJgxM.setPlineCode(plnOrderSJgx.getPlineCode());
					plnJgxM.setPlineName(plnOrderSJgx.getPlineName());
					plnJgxM.setProcessCodeC(plnOrderSJgx.getProcessCodeC());
					plnJgxM.setProcessDescC(plnOrderSJgx.getProcessDescC());

					if (plnOrderSJgx.getOrdLnDlyPk().contains("ZZBY-J")) {
						plnJgxM.setNextProcessCode("H");
					} else if (plnOrderSJgx.getOrdLnDlyPk().contains("ZZBY-D")) {
						plnJgxM.setNextProcessCode("G");
					} else {
						plnJgxM.setNextProcessCode("");
					}
					if (plnOrderSJgx.getOrderSource().equals("备料需求")) {
						plnJgxM.setIsendgx("0");
					} else {
						plnJgxM.setIsendgx("1");
					}

					plnJgxM.setInwlId(plnOrderSJgx.getInwlId());
					plnJgxM.setInwlDesc(plnOrderSJgx.getInwlDesc());
					plnJgxM.setBom(plnOrderSJgx.getBom());
					// cro.setV_errMsg("未找到判定炉号(" + judgeStoveNo
					// + ")在加工的产出物料!");
					// return cro;
					// }
					rs.close();
					ps.close();
					plnJgxM.setOutwlId(plnOrderSJgx.getOutwlId());
					plnJgxM.setOutwlDesc(plnOrderSJgx.getOutwlDesc());
					String gowWhere = corePlanFurnProM.getPlineCodeGroup(conn,
							plnOrderSJgx.getPlineCode(),
							plnOrderSJgx.getProPlanId(),
							plnOrderSJgx.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 = conn.prepareStatement(sqlGroup);
						ps.setObject(1, plnOrderSJgx.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("6");
					plnJgxM.setIfDoHeatPlan("1");
					plnJgxM.setProPlanId(plnOrderSJgx.getProPlanId());
					plnJgxM.setGxPlanNo(plnOrderSJgx.getGxPlanNo());
					plnJgxM.setSpecCode(plnOrderSJgx.getSpecCode());
					plnJgxM.setSpecName(plnOrderSJgx.getSpecName());
					plnJgxM.setGradecode(matTrack.getGradecode());
					plnJgxM.setGradename(matTrack.getGradename());
					plnJgxM.setSteelcode(plnOrderSJgx.getSteelcode());
					plnJgxM.setSteelname(plnOrderSJgx.getSteelname());
					plnJgxM.setProduccode(plnOrderSJgx.getProduccode());
					plnJgxM.setProducname(plnOrderSJgx.getProducname());

					plnJgxM.setModelCode(plnOrderSJgx.getModelCode());
					plnJgxM.setModelDesc(plnOrderSJgx.getModelDesc());
					// 单倍支吨
					plnJgxM.setPlnInsingleNum(String.valueOf(takeCount));
					plnJgxM.setPlnInsingleWt(String.valueOf(actWt));

					// 查询轧管排产信息
					String sqlZg = CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.QueryWgZg");
					ps = conn.prepareStatement(sqlZg);
					ps.setObject(1, plnOrderSJgx.getOrdLnDlyPk());
					// ps.setObject(2, plnOrderSJgx.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.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
					}
					rs.close();
					ps.close();
					plnJgxM.setStdCode(plnOrderSJgx.getStdCode());
					plnJgxM.setStdName(plnOrderSJgx.getStdName());
					plnJgxM.setStdStyle(plnOrderSJgx.getStdStyle());
					plnJgxM.setStdStyleDesc(plnOrderSJgx.getStdStyleDesc());
					plnJgxM.setOutdiameterIn(outdiameterIn);
					plnJgxM.setWallthickIn(wallthickIn);
					plnJgxM.setLengthIn(lengthIn);
					plnJgxM.setLengthmaxIn(lengthmaxIn);
					plnJgxM.setLengthminIn(lengthminIn);
					plnJgxM.setOrderSource(plnOrderSJgx.getOrderSource());
					plnJgxM.setOrderNo(plnOrderSJgx.getOrderNo());
					plnJgxM.setOrderSeq(plnOrderSJgx.getOrderSeq());
					plnJgxM.setDeliveryNo(plnOrderSJgx.getDeliveryNo());
					plnJgxM.setOrdLnDlyPk(plnOrderSJgx.getOrdLnDlyPk());
					plnJgxM.setReqBlId(plnOrderSJgx.getReqBlId());
					plnJgxM.setIfExport(plnOrderSJgx.getIfExport());
					plnJgxM.setPriority(plnOrderSJgx.getPriority());
					plnJgxM.setPriorityMemo(plnOrderSJgx.getPriorityMemo());
					plnJgxM.setProMonth(plnOrderSJgx.getProMonth());
					plnJgxM.setIfMonitor(plnOrderSJgx.getIfMonitorJgx());
					plnJgxM.setPrdcrNo(plnOrderSJgx.getPrdcrNo());
					plnJgxM.setMonitorPoint(plnOrderSJgx.getMonitorPoint());
					plnJgxM.setWholeBacklogDesc(plnOrderSJgx
							.getWholeBacklogDesc());
					plnJgxM.setStationRoad(plnOrderSJgx.getStationRoad());

					plnJgxM.setCic(cic);
					plnJgxM.setSic(sic);
					plnJgxM.setDic(dic);
					plnJgxM.setPic(pic);
					plnJgxM.setCraftFileMan(plnOrderSJgx.getCraftFileMan());
					plnJgxM.setCraftFileNo(plnOrderSJgx.getCraftFileNo());
					plnJgxM.setCraftSeq(plnOrderSJgx.getCraftSeq());
					plnJgxM.setOutdiameter(plnOrderSJgx.getOutdiameter());
					plnJgxM.setWallthick(plnOrderSJgx.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 = conn.prepareStatement(ordLen);
					ps.setObject(1, plnOrderSJgx.getOrdLnDlyPk());
					rs = ps.executeQuery();
					if (rs.next()) {
						lenMax = rs.getDouble("LENGTHMAX");
						lenMin = rs.getDouble("LENGTHMIN");
					}
					rs.close();
					ps.close();

					if (!lengthmaxIn.equals("") && lenMin>0.0) {
						outnumCut = (int) (Double.parseDouble(lengthmaxIn) / 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(takeCount
							* outnumCut));
					double burnoutRate = 0;
					// 查询产线烧损
					String sql = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
							+ plnOrderSJgx.getPlineCode() + "'";
					ps = conn.prepareStatement(sql);
					rs = ps.executeQuery();
					if (rs.next()) {
						burnoutRate = rs.getDouble("BURNOUT_RATE");
					}
					rs.close();
					ps.close();
					double yjWt = actWt - actWt * burnoutRate;
					plnJgxM.setPlnOutsingleW(String.valueOf(yjWt));
					plnJgxM.setCreateName(userName);
					plnJgxM.setCreateTime(dateTime);
					plnJgxM.setProDay(dateTime.substring(0, 10)
							.replace("-", ""));
					plnJgxM.setBalYearMonth(dateTime.substring(0, 7).replace(
							"-", ""));
					plnJgxM.setIndexSeq(plnOrderSJgx.getIndexSeq());
					plnJgxM.setHeatPlanNo(heatPlanNoNew);
					// plnJgxM.setGxProSeq(String.valueOf(gxProSeq));
					// 订单内炉顺序号
					int lotNoJg = corePlanFurnProM.getMaxLotNoSqe(conn,
							plnJgxM.getProPlanId(), plnJgxM.getGxPlanNo(), "G");
					plnJgxM.setLotNoSqe(String.valueOf(lotNoJg));

					plnJgxM.setZzbFlag(flag);
					// 新增加工线虚拟炉计划
					String addPlnGxZg = EntityTool.fillSqlByEntity(
							CoreXmlSqlParsersFactory
									.getSql("FrmEndLibrary.addPlnZyJgxbGX"),
							plnJgxM);
					ps = conn.prepareStatement(addPlnGxZg);
					ps.executeUpdate();
					ps.close();
					// 新增生产批号
					StoveHelper.updatePlnJgxGroup(conn, plnJgxM.getProPlanId(),
							plnJgxM.getGxPlanNo(), plnJgxM.getPic());

					PlnZyJgxCEntity plnC = new PlnZyJgxCEntity();
					// 获取炉计划顺序号
					String heatPlanSqe = corePlanFurnProM.getHeatPlanSeq(conn,
							heatPlanNoNew, "G");
					plnC.setHeatPlanNo(heatPlanNoNew);
					plnC.setJugdeApplyCode("");
					plnC.setJudgeStoveNo(judgeStoveNo);
					plnC.setFeedHeatNo(judgeStoveNo);
					plnC.setFlagStoveNo(flagStoveNo);
					plnC.setBatchNo(batchNo);
					plnC.setBatchGroudNo(batchGroupBy);
					plnC.setStoveNo(stoveNo);
					plnC.setProPlanId(plnOrderSJgx.getProPlanId());
					plnC.setGxPlanNo(plnOrderSJgx.getGxPlanNo());
					plnC.setPlineCode(plnOrderSJgx.getPlineCode());
					plnC.setPlineName(plnOrderSJgx.getPlineName());
					plnC.setOutdiameterIn(outdiameterIn);
					plnC.setWallthickIn(wallthickIn);
					plnC.setOutnumCut(String.valueOf(outnumCut));
					plnC.setLengthIn(lengthIn);
					plnC.setLengthmaxIn(lengthmaxIn);
					plnC.setLengthminIn(lengthminIn);
					plnC.setPlanIndoubleNum(String.valueOf(takeCount));
					plnC.setPlanIndoubleWt(String.valueOf(actWt));

					plnC.setHeatPlanSqe(heatPlanSqe);
					// 新增
					String addPlnGxJgxC = EntityTool
							.fillSqlByEntity(CoreXmlSqlParsersFactory
									.getSql("FrmEndLibrary.addPlnZyJgxC"), plnC);
					ps = conn.prepareStatement(addPlnGxJgxC);
					ps.executeUpdate();
					ps.close();

					// 修改庫存本工序炉计划ID
					String updateMat = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updatePressBgx");
					if (planstatus.equals("10")) {
						updateMat += " ,T.PRODUCT_FLAG='801401',T.MAT_STATUS='80150103',T.PRO_PLAN_ID_NEXT='"
								+ proPlanId
								+ "',T.GX_PLAN_NO_NEXT='"
								+ gxPlanNo
								+ "',T.HANGING_FLAG='1',T.HEAT_PLAN_NO_NEXT='"
								+ heatPlanNoNew + "'";
						if (nextProcessCdeo.equals("")) {
							updateMat += ",T.NEXT_PROCESS_CDOE='G',T.NEXT_PROCESS_DESC='加工线'";
						}
					}
					updateMat += " WHERE T.JUDGE_STOVE_NO = ?    AND T.BATCH_NO = ?   "
							+ "AND T.BATCH_GROUD_NO = ?   AND T.PROCESS_CDOE = ?  "
							+ " AND T.PRO_ORDER_ID = ?   AND T.GX_PLAN_NO = ?   AND T.QCM_STAUS = '00'";
					ps = conn.prepareStatement(updateMat);
					ps.setObject(1, heatPlanNoNew);
					ps.setObject(2, matTrack.getJudgeStoveNo());
					ps.setObject(3, matTrack.getBatchNo());
					ps.setObject(4, matTrack.getBatchGroudNo());
					ps.setObject(5, processCdoe);
					ps.setObject(6, proPlanId);
					ps.setObject(7, gxPlanNo);
					ps.executeUpdate();
					ps.close();

					//修改管号队列炉计划ID
					for(MatBcMEntityPln ms : matGpMlist)
					{
						String updatePortSql = CoreXmlSqlParsersFactory.getSql("FrmEndLibrary.updatePortMch");
						ps = conn.prepareStatement(updatePortSql);
						ps.setObject(1,heatPlanNoNew);
						ps.setObject(2,ms.getHeatPlanNo());
						ps.setObject(3,ms.getMatNo());
						ps.executeUpdate();
						ps.close();
					}
					// 关闭原炉计划
					String updateMOld = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updateMOldG");
					ps = conn.prepareStatement(updateMOld);
					ps.setObject(1, heatPlanNoOld);
					ps.executeUpdate();
					ps.close();
				} else {
					// 修改庫存本工序炉计划ID
					String updateMat = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.updatePressBgx");
					updateMat += " WHERE T.JUDGE_STOVE_NO = ?    AND T.BATCH_NO = ?   "
							+ "AND T.BATCH_GROUD_NO = ?   AND T.PROCESS_CDOE = ?  "
							+ " AND T.PRO_ORDER_ID = ?   AND T.GX_PLAN_NO = ?   AND T.QCM_STAUS = '00'";
					ps = conn.prepareStatement(updateMat);
					ps.setObject(1, herdOLD);
					ps.setObject(2, matTrack.getJudgeStoveNo());
					ps.setObject(3, matTrack.getBatchNo());
					ps.setObject(4, matTrack.getBatchGroudNo());
					ps.setObject(5, processCdoeBgx);
					ps.setObject(6, proPlanId);
					ps.setObject(7, gxPlanNo);
					ps.executeUpdate();
					ps.close();
				}
			}

			if (nextProcessCdeo.equals("E")) {
				List<PlnOrderDbkSEntity> plnOrder = PlanFurnProduction
						.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "E",
								PlnOrderDbkSEntity.class);
				if (plnOrder.size() > 0) {
					// 生成镦拔扩虚拟炉计划
					if (addPlnZyDbkM(conn, matTrack, takeCount, actWt,
							plnOrder, userName, dateTime, nextProcessCdeo,
							processCdoe, cic, heatPlanNoNew)) {
						// continue;
					}
				}

			} else if (nextProcessCdeo.equals("F")) {
				List<PlnOrderRclSEntity> plnOrder = PlanFurnProduction
						.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "F",
								PlnOrderRclSEntity.class);
				if (plnOrder.size() > 0) {
					// 生成镦拔扩虚拟炉计划
					if (addPlnZyRclM(conn, matTrack, takeCount, actWt,
							plnOrder, userName, dateTime, nextProcessCdeo,
							processCdoe, cic, heatPlanNoNew)) {
						// continue;
					}
				}
			} else if (nextProcessCdeo.equals("G")) {
				if (wholeDesc.contains("加工") && orderSource.equals("备料需求")) {
					// 查询备料需求与成品对应关系
					String sqlBL = "SELECT T.ORD_LN_DLY_PK FROM PLN_PORDER_BL_REQ T WHERE T.REQ_BL_ID=?";
					ps = conn.prepareStatement(sqlBL);
					ps.setObject(1, ordLnDlyPk);
					rs = ps.executeQuery();
					if (rs.next()) {
						ordLnDlyPk = rs.getString("ORD_LN_DLY_PK");
						plnDivideId = "01";
					}
					rs.close();
					ps.close();
				}
				List<PlnOrderJgxSEntity> plnOrder = PlanFurnProduction
						.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "G",
								PlnOrderJgxSEntity.class);
				if (plnOrder.size() > 0) {
					// 生成镦拔扩虚拟炉计划
					if (addPlnZyJgxM(conn, matTrack, takeCount, actWt,
							plnOrder, userName, dateTime, nextProcessCdeo,
							processCdoe, cic, heatPlanNoNew)) {
						// continue;
					}
				}
			} else if (nextProcessCdeo.equals("H")) {
				List<PlnGxJgPropSEntity> plnOrder = PlanFurnProduction
						.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "H",
								PlnGxJgPropSEntity.class);
				if (plnOrder.size() > 0) {
					// 生成镦拔扩虚拟炉计划
					if (addPlnZyJgM(conn, matTrack, takeCount, actWt, plnOrder,
							userName, dateTime, nextProcessCdeo, processCdoe,
							heatPlanNoNew)) {
						// continue;
					}
				}
			}

			String resumeSeq = dateFormat.format(now) + df.format(seq);
			// 生成利库日志
			matTrack.setResumeSeq(resumeSeq);
			matTrack.setEventId("900102");
			matTrack.setEventDesc("精整利库");
			matTrack.setFormName("com.steering.pss.plnsaleord.planStove.FrmEndLibrary");
			matTrack.setCallFuncCoding("doAddLibrary");
			matTrack.setKeyvalue1("List<MatBcMEntityPln> matGpMlist");
			matTrack.setKeyvalue1Desc("物料主表关键字实体类集合");
			matTrack.setKeyvalue2("String userName");
			matTrack.setKeyvalue2Desc2("操作人");
			matTrack.setKeyvalue3("doAddLibrary");
			matTrack.setKeyvalue3Desc3("生成下工序炉计划");
			matTrack.setProcessCdoe(processCdoe);
			matTrack.setMemo("");
			matTrack.setCreateName(userName);
			matTrack.setCreateTime(dateTime);
			matTrack.setOrderNo(orderNo);
			matTrack.setOrderSeq(orderSeq);
			matTrack.setOrderSeqNo(deliveryNo);
			matTrack.setProOrderNo(orderNo + '/' + orderSeq);
			if (orderSource.equals("备料需求")) {
				matTrack.setOrdPk("");
				matTrack.setOrdLnPk("");
			} else {
				matTrack.setOrdPk(ordLnDlyPk.substring(0,
						ordLnDlyPk.length() - 6));
				matTrack.setOrdLnPk(ordLnDlyPk.substring(0,
						ordLnDlyPk.length() - 3));
			}
			matTrack.setOrdLnDlyPk(ordLnDlyPk);
			// 新增利库记录
			String sqlAddTrack = EntityTool.fillSqlByEntity(
					CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.addMatBcTrack"), matTrack);
			ps = conn.prepareStatement(sqlAddTrack);
			ps.executeUpdate();
			ps.close();
			if (yOrderNo.equals("0")) {
				// 调用生成组炉炉号的检验委托、检验实绩信息。
				BllCreateGroupStoveInfo info = new BllCreateGroupStoveInfo();
				info.Create(processCdoeBgx, lotNo, judgeStoveNo, batchNo,
						proPlanId, gxPlanNo, conn, jhyCon, heatPlanNo,
						processCdoe);// list1,
			}
			cro.setV_errMsg("利库成功!");
			conn.commit();
			jhyCon.commit();
		} catch (Exception sqle) {
			try {
				conn.rollback();
				jhyCon.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
					jhyCon.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 轧管,镦拔扩,热处理,加工线精整脱单
	 * 
	 * @param jslist
	 * @param userName
	 *            脱单人
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doDeleteMonomerLg(
			ArrayList<ArrayList<String>> jslist, String userName, String lenFalg)
			throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			DecimalFormat df = new DecimalFormat("0000000000");
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			// 循环库存信息
			int seq = 1;
			for (int i = 0; i < jslist.size(); i++) {

				Date now = new Date();
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String judgeStoveNo = list.get(0);
				String batchNo = list.get(1);
				String batchGroupBy = list.get(2);
				int takeCount = Integer.parseInt(list.get(3));// 脱单
				String heatPlanNoNext = list.get(4);
				String processCdoe = list.get(5);
				String jugdeApplyCode = list.get(6);
				String proOrderNo = list.get(7);
				String actLen = list.get(8);
				String materialNo = list.get(10);
				List<MatBcMEntityPln> matGpMlist = null;
				if(list.get(9).equals(""))
				{
					 matGpMlist = getQureyMatGpM(conn,
							judgeStoveNo, batchNo, batchGroupBy, takeCount,
							heatPlanNoNext, processCdoe, jugdeApplyCode,
							proOrderNo, actLen, lenFalg,materialNo);
				}else
				{
					matGpMlist = getQureyMatGpMPay(conn,
							judgeStoveNo, batchNo, batchGroupBy, list.get(9),
							heatPlanNoNext, processCdoe, jugdeApplyCode,
							proOrderNo, actLen, lenFalg,materialNo);
				}

				if (matGpMlist == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				MatBcTrackEntity matTrack = getQureyMatTrack(conn,
						judgeStoveNo, batchNo, batchGroupBy, takeCount, "0",
						heatPlanNoNext, MatBcTrackEntity.class);
				String nextprocessCdoe = "";
				double actWt = 0;
				String proPlanId = "";
				String gxPlanNo = "";
				String heatPlanNo = "";
				for (MatBcMEntityPln matGpM : matGpMlist) {
					// proPlanZg = matGpM.getHeatPlanNoNext();
					nextprocessCdoe = matGpM.getNextProcessCdoe();
					actWt += Double.parseDouble(matGpM.getActWeight());
					proPlanId = matGpM.getProOrderId();
					gxPlanNo = matGpM.getGxPlanNo();
					heatPlanNo = matGpM.getHeatPlanNo();
					// if (heatPlanNoNext.equals("")) {
					// cro.setV_errMsg("你选择的半成品物料未分配其他订单,不能脱单!");
					// return cro;
					// }
					if (!matGpM.getLikuProcessCode().equals("")) {
						processCdoe = matGpM.getLikuProcessCode();
					}
					if (!matGpM.getJugdeApplyCode().equals("")
							&& matGpM.getJudgeResultCode().equals("40740701")
							|| matGpM.getJudgeResultCode().equals("40740709")) {
						cro.setV_errMsg("你选择的半成品物料已送且已判定合格,不能脱单!");
						return cro;
					}
					String sqlUpdateMat = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdateMatGp");
					sqlUpdateMat += " ,T.PRO_ORDER_ID='',T.GX_PLAN_NO='',"
							+ "T.JUGDE_APPLY_FLAG='0',T.JUGDE_APPLY_CODE='',T.JUGDE_APPLY_TIME='',"
							+ "T.JUDGE_RESULT_CODE='',T.JUDGE_RESULT_TIME='',T.JUDGE_MAKER='',"
							+  "T.PRO_ORDER_NO='', T.ZZB_FLAG='0',"
							+ "T.ORD_PK='',T.ORD_LN_PK='',T.ORD_LN_DLY_PK='',T.ORDER_NO='',T.ORDER_SEQ='',T.ORDER_SEQ_NO=''";
					sqlUpdateMat += " WHERE T.MAT_NO = ?";
					ps = conn.prepareStatement(sqlUpdateMat);
					if(matGpM.getTarget().equals("A"))
					{
						ps.setObject(1, "80150201");
					}else
					{
						ps.setObject(1, "80150101");
					}

					ps.setObject(2, "");
					ps.setObject(3, "");
					ps.setObject(4, "0");
					ps.setObject(5, "0");
					ps.setObject(6, "");
					ps.setObject(7, "");
					ps.setObject(8, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();

					//脱单时修改管好队列
					if(processCdoe.equals("G") && matGpM.getProOrderNo().equals("ZZBY"))
					{
						String sqlUpdatePortMch = CoreXmlSqlParsersFactory
								.getSql("FrmEndLibrary.UpdatePortMchCancel");
						ps = conn.prepareStatement(sqlUpdatePortMch);
						ps.setString(1,matGpM.getHeatPlanNo());
						ps.setString(2,matGpM.getMatNo());
						ps.executeUpdate();
						ps.close();
					}
				}
				String resumeSeq = dateFormat.format(now) + df.format(seq);
				// 生成利库日志
				matTrack.setResumeSeq(resumeSeq);
				matTrack.setEventId("900101");
				matTrack.setEventDesc("精整脱单");
				matTrack.setFormName("com.steering.pss.plnsaleord.planStove.FrmEndLibrary");
				matTrack.setCallFuncCoding("doDeleteMonomerLg");
				matTrack.setKeyvalue1("List<MatBcMEntityPln> matGpMlist");
				matTrack.setKeyvalue1Desc("物料主表关键字实体类集合");
				matTrack.setKeyvalue2("String userName");
				matTrack.setKeyvalue2Desc2("操作人");
				matTrack.setKeyvalue3("doDeleteMonomerLg");
				matTrack.setKeyvalue3Desc3("删除下工序炉计划");
				matTrack.setProcessCdoe(processCdoe);
				matTrack.setMemo("");
				matTrack.setCreateName(userName);
				matTrack.setCreateTime(dateTime);
				seq++;
				String sqlAddTrack = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("FrmEndLibrary.addMatBcTrack"),
						matTrack);
				ps = conn.prepareStatement(sqlAddTrack);
				ps.executeUpdate();
				ps.close();

				// 修改判定表有效标志 2025-06-17 炉号变了 没必要改了
				String updateQcmZg = "UPDATE QCM_ZG_JUGDE_APPLY T SET T.IS_FLAG='1' WHERE T.JUDGE_STOVE_NO=? AND T.JUGDE_APPLY_CODE=?";
				ps = conn.prepareStatement(updateQcmZg);
				ps.setObject(1, judgeStoveNo);
				ps.setObject(2, jugdeApplyCode);
				ps.executeUpdate();
				ps.close();

				int outnumCut = 1;
				// 修改排产订单表利库量
				if (processCdoe.equals("D")) {
					String queryCut = "SELECT T.OUTNUM_CUT FROM PLN_ORDER_ZG_S T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					ps = conn.prepareStatement(queryCut);
					ps.setObject(1, proPlanId);
					ps.setObject(2, gxPlanNo);
					rs = ps.executeQuery();
					if (rs.next()) {
						outnumCut = rs.getInt("OUTNUM_CUT");
					}
					rs.close();
					ps.close();
					if (outnumCut == 0) {
						outnumCut = 1;
					}

					String updateZgS = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdateZgLk");
					ps = conn.prepareStatement(updateZgS);
					ps.setObject(1, -actWt);
					ps.setObject(2, -takeCount / outnumCut);
					ps.setObject(3, proPlanId);
					ps.setObject(4, gxPlanNo);
					ps.executeUpdate();
					ps.close();

					// 删除本工序炉计划
					String deleteMil = "DELETE MIL_PLAN WHERE ID = ? AND BACK_SLAB_FLAG='2' ";
					ps = conn.prepareStatement(deleteMil);
					ps.setObject(1, heatPlanNo);
					ps.executeUpdate();
					ps.close();
					String sql = "SELECT T.HEAT_PLAN_SQE FROM PLN_ZY_ZG_C T WHERE T.HEAT_PLAN_NO =? AND IF_FLAG='1'";
					PreparedStatement ps1 = conn.prepareStatement(sql);
					ps1.setObject(1, heatPlanNo);
					rs = ps1.executeQuery();
					while (rs.next()) {
						String deleteFeed = "DELETE MIL_FEED_PLAN WHERE FEED_ROW_NO = ?";
						ps = conn.prepareStatement(deleteFeed);
						ps.setObject(1, rs.getString("HEAT_PLAN_SQE"));
						ps.executeUpdate();
						ps.close();
					}
					rs.close();
					ps1.close();
					// 删除本工序炉计划
					String deleteM = "DELETE PLN_ZY_ZG_M WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteM);
					ps.setObject(1, heatPlanNo);
					ps.executeUpdate();
					ps.close();

					String deleteC = "DELETE PLN_ZY_ZG_C WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteC);
					ps.setObject(1, heatPlanNo);
					ps.executeUpdate();
					ps.close();

				} else if (processCdoe.equals("E")) {
					String updateZgS = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdateDbkLk");
					ps = conn.prepareStatement(updateZgS);
					ps.setObject(1, -actWt);
					ps.setObject(2, -takeCount);
					ps.setObject(3, proPlanId);
					ps.setObject(4, gxPlanNo);
					ps.executeUpdate();
					ps.close();
					// 删除本工序炉计划
					String deleteM = "DELETE PLN_ZY_DBK_M WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteM);
					ps.setObject(1, heatPlanNo);
					ps.executeUpdate();
					ps.close();

					String deleteC = "DELETE PLN_ZY_DBK_C WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteC);
					ps.setObject(1, heatPlanNo);
					ps.executeUpdate();
					ps.close();
				} else if (processCdoe.equals("F")) {
					String updateZgS = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdateRclLk");
					ps = conn.prepareStatement(updateZgS);
					ps.setObject(1, -actWt);
					ps.setObject(2, -takeCount);
					ps.setObject(3, proPlanId);
					ps.setObject(4, gxPlanNo);
					ps.executeUpdate();
					ps.close();

					// 删除本工序炉计划
					String deleteM = "DELETE PLN_ZY_RCL_M WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1'  AND IF_MATCH_ODD IN('1','6') ";
					ps = conn.prepareStatement(deleteM);
					ps.setObject(1, heatPlanNo);
					ps.executeUpdate();
					ps.close();

					String deleteC = "DELETE PLN_ZY_RCL_C WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' AND JUGDE_APPLY_CODE IS NULL ";
					ps = conn.prepareStatement(deleteC);
					ps.setObject(1, heatPlanNo);
					ps.executeUpdate();
					ps.close();
				} else if (processCdoe.equals("G")) {
					String queryCut = "SELECT NVL(T.OUTNUM_CUT,1) OUTNUM_CUT FROM PLN_ORDER_ZG_S T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					ps = conn.prepareStatement(queryCut);
					ps.setObject(1, proPlanId);
					ps.setObject(2, gxPlanNo);
					rs = ps.executeQuery();
					if (rs.next()) {
						outnumCut = rs.getInt("OUTNUM_CUT");
					}
					rs.close();
					ps.close();
					if (outnumCut == 0) {
						outnumCut = 1;
					}

					String updateZgS = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdateJgxLk");
					ps = conn.prepareStatement(updateZgS);
					ps.setObject(1, -actWt);
					ps.setObject(2, -takeCount / outnumCut);
					ps.setObject(3, proPlanId);
					ps.setObject(4, gxPlanNo);
					ps.executeUpdate();
					ps.close();

					// 删除本工序炉计划
					String deleteM = "DELETE PLN_ZY_JGX_M WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteM);
					ps.setObject(1, heatPlanNo);
					ps.executeUpdate();
					ps.close();

					String deleteC = "DELETE PLN_ZY_JGX_C WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteC);
					ps.setObject(1, heatPlanNo);
					ps.executeUpdate();
					ps.close();
				}

				String deleteM = "";
				String deleteC = "";
				// 删除炉计划
				if (nextprocessCdoe.equals("E")) {
					// 查询下工序炉计划是否下发
					String sql = "SELECT T.PLANSTATUS FROM PLN_ZY_DBK_M  T "
							+ " WHERE T.JUDGE_STOVE_NO=? AND NVL(T.HEAT_PLAN_NO,'/')=NVL(?,'/')  AND T.IF_MATCH_ODD='3' ";
					ps = conn.prepareStatement(sql);
					ps.setObject(1, judgeStoveNo);
					ps.setObject(2, heatPlanNoNext);
					rs = ps.executeQuery();
					if (rs.next()) {
						if (!rs.getString("PLANSTATUS").equals("00")) {
							cro.setV_errMsg("您选中的数据,下工序镦拔扩精整利库炉计划已下发,不能脱单!");
							return cro;
						}
					}
					rs.close();
					ps.close();
					deleteM = "DELETE PLN_ZY_DBK_M WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteM);
					ps.setObject(1, heatPlanNoNext);
					ps.executeUpdate();
					ps.close();

					deleteC = "DELETE PLN_ZY_DBK_C WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteC);
					ps.setObject(1, heatPlanNoNext);
					ps.executeUpdate();
					ps.close();

				} else if (nextprocessCdoe.equals("F")) {
					int lotNo = 0;
					// 查询下工序炉计划是否下发
					String sql = "SELECT T.PLANSTATUS,T.LOT_NO_SQE FROM PLN_ZY_RCL_M  T "
							+ " WHERE T.JUDGE_STOVE_NO=? AND NVL(T.HEAT_PLAN_NO,'/')=NVL(?,'/')  AND T.IF_MATCH_ODD='3' ";
					ps = conn.prepareStatement(sql);
					ps.setObject(1, judgeStoveNo);
					ps.setObject(2, heatPlanNoNext);
					rs = ps.executeQuery();
					if (rs.next()) {
						if (!rs.getString("PLANSTATUS").equals("00")) {
							cro.setV_errMsg("您选中的数据,下工序精整利库热处理炉计划已下发,不能脱单!");
							return cro;
						}
						lotNo = rs.getInt("LOT_NO_SQE");
					}
					rs.close();
					ps.close();
					deleteM = "DELETE PLN_ZY_RCL_M WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteM);
					ps.setObject(1, heatPlanNoNext);
					ps.executeUpdate();
					ps.close();
					// 删除修改炉内顺序号
					String updateSql = "UPDATE PLN_ZY_RCL_M T SET T.LOT_NO_SQE = TO_NUMBER(T.LOT_NO_SQE) + TO_NUMBER(-1)"
							+ " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >= TO_NUMBER(?)";
					ps = conn.prepareStatement(updateSql);
					ps.setObject(1, proPlanId);
					ps.setObject(2, gxPlanNo);
					ps.setObject(3, lotNo);
					ps.executeUpdate();
					ps.close();
					deleteC = "DELETE PLN_ZY_RCL_C WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteC);
					ps.setObject(1, heatPlanNoNext);
					ps.executeUpdate();
					ps.close();
				} else if (nextprocessCdoe.equals("G")) {
					int lotNo = 0;
					// 查询下工序炉计划是否下发
					String sql = "SELECT T.PLANSTATUS,T.LOT_NO_SQE  FROM PLN_ZY_JGX_M  T "
							+ " WHERE T.JUDGE_STOVE_NO=? AND NVL(T.HEAT_PLAN_NO,'/')=NVL(?,'/')  AND T.IF_MATCH_ODD='3' ";
					ps = conn.prepareStatement(sql);
					ps.setObject(1, judgeStoveNo);
					ps.setObject(2, heatPlanNoNext);
					rs = ps.executeQuery();
					if (rs.next()) {
						if (!rs.getString("PLANSTATUS").equals("00")) {
							cro.setV_errMsg("您选中的数据,下工序精整利库加工线炉计划已下发,不能脱单!");
							return cro;
						}
						lotNo = rs.getInt("LOT_NO_SQE");
					}
					rs.close();
					ps.close();
					deleteM = "DELETE PLN_ZY_JGX_M WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteM);
					ps.setObject(1, heatPlanNoNext);
					ps.executeUpdate();
					ps.close();
					// 删除修改炉内顺序号
					String updateSql = "UPDATE PLN_ZY_JGX_M T SET T.LOT_NO_SQE = TO_NUMBER(T.LOT_NO_SQE) + TO_NUMBER(-1)"
							+ " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >= TO_NUMBER(?)";
					ps = conn.prepareStatement(updateSql);
					ps.setObject(1, proPlanId);
					ps.setObject(2, gxPlanNo);
					ps.setObject(3, lotNo);
					ps.executeUpdate();
					ps.close();
					deleteC = "DELETE PLN_ZY_JGX_C WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteC);
					ps.setObject(1, heatPlanNoNext);
					ps.executeUpdate();
					ps.close();
				} else if (nextprocessCdoe.equals("H")) {
					// 查询下工序炉计划是否下发
					String sql = "SELECT T.PLANSTATUS FROM PLN_ZY_JG_M  T "
							+ " WHERE T.JUDGE_STOVE_NO=? AND NVL(T.HEAT_PLAN_NO,'/')=NVL(?,'/') AND T.IF_MATCH_ODD='3' ";
					ps = conn.prepareStatement(sql);
					ps.setObject(1, judgeStoveNo);
					ps.setObject(2, heatPlanNoNext);
					rs = ps.executeQuery();
					if (rs.next()) {
						if (!rs.getString("PLANSTATUS").equals("00")) {
							cro.setV_errMsg("您选中的数据,下工序精整利库接箍炉计划已下发,不能脱单!");
							return cro;
						}
					}
					rs.close();
					ps.close();
					deleteM = "DELETE PLN_ZY_JG_M WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteM);
					ps.setObject(1, heatPlanNoNext);
					ps.executeUpdate();
					ps.close();

					deleteC = "DELETE PLN_ZY_JG_C WHERE HEAT_PLAN_NO = ? AND IF_FLAG='1' ";
					ps = conn.prepareStatement(deleteC);
					ps.setObject(1, heatPlanNoNext);
					ps.executeUpdate();
					ps.close();
				}
			}
			cro.setV_errMsg("脱单成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 每支材料对应的倒库倒库单号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public static String querySendOut(Connection conn, String strlist)
			throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.queryOutList");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strlist);
		psta.setString(2, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("OUTSTOCK_DOC");
		}
		rs.close();
		psta.close();
		return seq;
	}

	/**
	 * 每支材料对应的倒库（出库）流水号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public static String querySendOutList(Connection conn, String strlist,
			String strType) throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmEndLibrary.queryOut");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strlist);
		psta.setString(2, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("OUTSTOCK_SQE");
		}
		rs.close();
		psta.close();
		return seq;
	}
	/**
	 * 获取新的判定炉号（半成品）
	 * @param conn
	 * @param prefix
	 * @return
	 * @throws Exception
	 */
	public static String getNewJudgeStoveNo(Connection conn, String prefix) throws Exception {
	    String newJudgeStoveNo = "";
	    PreparedStatement pstmt = null;
	    ResultSet rs = null;
	    try {
	        // SQL查询语句，使用参数化查询
	        String sql = "SELECT ? || TO_CHAR(SYSDATE, 'YYMM') || " +
	                     "       LPAD(NVL( " +
	                     "         (SELECT MAX(TO_NUMBER(SUBSTR(judge_stove_no, 6, 4))) " +
	                     "         FROM mat_bc_m " +
	                     "         WHERE judge_stove_no LIKE ? || TO_CHAR(SYSDATE, 'YYMM') || '%' " +
	                     "       ), 0) + 1, 4, '0') AS new_judge_stove_no " +
	                     "FROM dual";
	        
	        pstmt = conn.prepareStatement(sql);
	        pstmt.setString(1, prefix);
	        pstmt.setString(2, prefix);
	        rs = pstmt.executeQuery();
	        
	        if (rs.next()) {
	            newJudgeStoveNo = rs.getString("new_judge_stove_no");
	        }
	        
	        return newJudgeStoveNo;
	    } finally {
	        // 关闭资源
	        if (rs != null) {
	            try { rs.close(); } catch (Exception e) { /* 忽略 */ }
	        }
	        if (pstmt != null) {
	            try { pstmt.close(); } catch (Exception e) { /* 忽略 */ }
	        }
	    }
	}

	/**
	 * 轧管,镦拔扩,热处理,加工线改判
	 * 
	 * @param proPlanId
	 *            订单号
	 * @param gxPlanNo
	 *            排产序号
	 * @throws Exception
	 */
	public CoreReturnObject doSentence(ArrayList<String> list,
			String proPlanId, String gxPlanNo, String userName, String lenFalg)
			throws Exception {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			String judgeStoveNo = list.get(0);
			String batchNo = list.get(1);
			String batchGroupBy = list.get(2);
			int takeCount = Integer.parseInt(list.get(3));// 利库支
			String processCdoe = list.get(5);
			String materialNo = list.get(6);
			// String cic = list.get(7);
			String proOrderNo = list.get(7);
			String actLen = list.get(8);
			// 循环库存信息
			int seq = 1;
			Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
			DecimalFormat df = new DecimalFormat("00000");

			QcmBcJudgeChangeEntity matTrack = new QcmBcJudgeChangeEntity();

			String materialNoNew = "";
			String materialNameNew = "";
			String produccodeNew = "";
			String producnameNew = "";
			String steelcodeNew = "";
			String steelnameNew = "";
			String specCodeNew = "";
			String specNameNew = "";
			String modelCodeNew = "";
			String modelDescNew = "";
			String stdStyleNew = "";
			String stdStyleDescNew = "";
			String outdiameZg = "";
			String wallthZg = "";
			String stdCodeNew = "";
			String stdNameNew = "";
			String actLenMin = "";
			String actLenMax = "";
			if (processCdoe.equals("D")) {
				// 查询轧管信息
				PlnOrderZgSEntityL plnOrderS = getPlanOrderS(conn, proPlanId,
						gxPlanNo, PlnOrderZgSEntityL.class, "D");
				if (plnOrderS == null) {
					cro.setV_errMsg("未找到轧管订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				outdiameZg = plnOrderS.getOutdiameterZg();
				wallthZg = plnOrderS.getWallthickZg();
				materialNoNew = plnOrderS.getOutwlId();
				materialNameNew = plnOrderS.getOutwlDesc();
				produccodeNew = plnOrderS.getProduccode();
				producnameNew = plnOrderS.getProducname();
				steelcodeNew = plnOrderS.getSteelcode();
				steelnameNew = plnOrderS.getSteelname();

				specNameNew = new BigDecimal(
						plnOrderS.getOutdiameterZg()).setScale(2,
						RoundingMode.HALF_UP).toString() + "x" + new BigDecimal(
						plnOrderS.getWallthickZg()).setScale(2,
						RoundingMode.HALF_UP).toString();
				stdCodeNew = plnOrderS.getStdCode();
				stdNameNew = plnOrderS.getStdName();
				//actLenMin = plnOrderS.getLenRollMin();
				//actLenMax = plnOrderS.getLenRollMax();
				// milPln.setPipeSize(plnZgC.getSpecName());
				String sql = "SELECT T.SPEC_CODE  FROM COM_BASE_SPEC t WHERE T.SPEC_NAME=? AND T.VALIDFLAG='1'";
				ps = conn.prepareStatement(sql);
				ps.setObject(1, specNameNew);
				rs = ps.executeQuery();
				if (rs.next()) {
					specCodeNew = rs.getString("SPEC_CODE");
				}
				rs.close();
				ps.close();



				modelCodeNew = plnOrderS.getModelCode();
				modelDescNew = plnOrderS.getModelDesc();
				stdStyleNew = plnOrderS.getStdStyle();
				stdStyleDescNew = plnOrderS.getStdStyleDesc();

			} else if (processCdoe.equals("E")) {
				// 查询镦拔扩信息
				PlnOrderDbkSEntity plnOrderS = getPlanOrderS(conn, proPlanId,
						gxPlanNo, PlnOrderDbkSEntity.class, "E");
				if (plnOrderS == null) {
					cro.setV_errMsg("未找到镦拔扩订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				outdiameZg = plnOrderS.getOutdiameter();
				wallthZg = plnOrderS.getWallthick();
				materialNoNew = plnOrderS.getOutwlId();
				materialNameNew = plnOrderS.getOutwlDesc();
				produccodeNew = plnOrderS.getProduccode();
				producnameNew = plnOrderS.getProducname();
				steelcodeNew = plnOrderS.getSteelcode();
				steelnameNew = plnOrderS.getSteelname();
				specNameNew = outdiameZg+".00" + "x" + wallthZg+".00";
				stdCodeNew = plnOrderS.getStdCode();
				stdNameNew = plnOrderS.getStdName();
				// milPln.setPipeSize(plnZgC.getSpecName());
				String sql = "SELECT T.SPEC_CODE  FROM COM_BASE_SPEC t WHERE T.SPEC_NAME=? AND T.VALIDFLAG='1'";
				ps = conn.prepareStatement(sql);
				ps.setObject(1, specNameNew);
				rs = ps.executeQuery();
				if (rs.next()) {
					specCodeNew = rs.getString("SPEC_CODE");
				}
				rs.close();
				ps.close();
				modelCodeNew = plnOrderS.getModelCode();
				modelDescNew = plnOrderS.getModelDesc();
				stdStyleNew = plnOrderS.getStdStyle();
				stdStyleDescNew = plnOrderS.getStdStyleDesc();
			} else if (processCdoe.equals("F")) {
				// 查询热处理信息
				PlnOrderRclSEntity plnOrderS = getPlanOrderS(conn, proPlanId,
						gxPlanNo, PlnOrderRclSEntity.class, "F");
				if (plnOrderS == null) {
					cro.setV_errMsg("未找到热处理订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				outdiameZg = plnOrderS.getOutdiameter();
				wallthZg = plnOrderS.getWallthick();
				materialNoNew = plnOrderS.getOutwlId();
				materialNameNew = plnOrderS.getOutwlDesc();
				produccodeNew = plnOrderS.getProduccode();
				producnameNew = plnOrderS.getProducname();
				steelcodeNew = plnOrderS.getSteelcode();
				steelnameNew = plnOrderS.getSteelname();
				specNameNew = outdiameZg+".00" + "x" + wallthZg+".00";
				stdCodeNew = plnOrderS.getStdCode();
				stdNameNew = plnOrderS.getStdName();
				// milPln.setPipeSize(plnZgC.getSpecName());
				String sql = "SELECT T.SPEC_CODE  FROM COM_BASE_SPEC t WHERE T.SPEC_NAME=? AND T.VALIDFLAG='1'";
				ps = conn.prepareStatement(sql);
				ps.setObject(1, specNameNew);
				rs = ps.executeQuery();
				if (rs.next()) {
					specCodeNew = rs.getString("SPEC_CODE");
				}
				rs.close();
				ps.close();
				modelCodeNew = plnOrderS.getModelCode();
				modelDescNew = plnOrderS.getModelDesc();
				stdStyleNew = plnOrderS.getStdStyle();
				stdStyleDescNew = plnOrderS.getStdStyleDesc();
			} else if (processCdoe.equals("G")) {
				// 查询加工线信息
				PlnOrderJgxSEntity plnOrderS = getPlanOrderS(conn, proPlanId,
						gxPlanNo, PlnOrderJgxSEntity.class, "G");
				if (plnOrderS == null) {
					cro.setV_errMsg("未找到加工线订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				outdiameZg = plnOrderS.getOutdiameter();
				wallthZg = plnOrderS.getWallthick();
				materialNoNew = plnOrderS.getOutwlId();
				materialNameNew = plnOrderS.getOutwlDesc();
				produccodeNew = plnOrderS.getProduccode();
				producnameNew = plnOrderS.getProducname();
				steelcodeNew = plnOrderS.getSteelcode();
				steelnameNew = plnOrderS.getSteelname();
				specNameNew = outdiameZg+".00" + "x" + wallthZg+".00";
				stdCodeNew = plnOrderS.getStdCode();
				stdNameNew = plnOrderS.getStdName();
				// milPln.setPipeSize(plnZgC.getSpecName());
				String sql = "SELECT T.SPEC_CODE  FROM COM_BASE_SPEC t WHERE T.SPEC_NAME=? AND T.VALIDFLAG='1'";
				ps = conn.prepareStatement(sql);
				ps.setObject(1, specNameNew);
				rs = ps.executeQuery();
				if (rs.next()) {
					specCodeNew = rs.getString("SPEC_CODE");
				}
				rs.close();
				ps.close();
				modelCodeNew = plnOrderS.getModelCode();
				modelDescNew = plnOrderS.getModelDesc();
				stdStyleNew = plnOrderS.getStdStyle();
				stdStyleDescNew = plnOrderS.getStdStyleDesc();
			}
			List<MatBcMEntityPln> matGpMlist = getQureyMatGpM(conn,
					judgeStoveNo, batchNo, batchGroupBy, takeCount, "",
					processCdoe, "", proOrderNo, actLen, lenFalg,"");
			if (matGpMlist == null) {
				cro.setV_errMsg("管坯物料已发生改变,请刷新!");
				return cro;
			}
			double actWt = 0;
			String materialNoOld = "";
			String materialNameOld = "";
			String produccodeOld = "";
			String producnameOld = "";
			String steelcodeOld = "";
			String steelnameOld = "";
			String specCodeOld = "";
			String specNameOld = "";
			String modelCodeOld = "";
			String modelDescOld = "";
			String stdStyleOld = "";
			String stdStyleDescOld = "";

			String judgeID = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.QueryMaxId");// 获取最大改判ID
			ps = conn.prepareStatement(sqlloading);
			ps.setObject(1, dateFormat.format(now));
			ps.setObject(2, dateFormat.format(now));
			rs = ps.executeQuery();
			if (rs.next()) {
				judgeID = rs.getString("JUDGE_ID");
			}
			rs.close();
			ps.close();
			String sendOut = querySendOut(conn, "800808");
			// 获取出库流水号
			String butessMatNo = querySendOutList(conn, sendOut, "800808");
			int outNo = Integer.parseInt(butessMatNo.substring(
					butessMatNo.length() - 4, butessMatNo.length()));
			for (MatBcMEntityPln matGpM : matGpMlist) {
				actWt += Double.parseDouble(matGpM.getActWeight());
				YdmBcOutlistEntity outBc = new YdmBcOutlistEntity();
				// if(!matGpM.getMaterialNo()){
				// cro.setV_errMsg("选中炉号的物料与选中订单产出物料不相同,不能利库,请物料改判！");
				// return cro;
				// }
				// if (!matGpM.getProOrderNo().equals("")) {
				// cro.setV_errMsg("选中炉号已挂生产合同,不能利库!");
				// return cro;
				// }
				if (!matGpM.getHeatPlanNoNext().equals("")) {
					cro.setV_errMsg("选中炉已挂下工序订单,不能改判!");
					return cro;
				}
				// if (!matGpM.getProductFlag().equals("801401")) {
				// cro.setV_errMsg("材料类别不是在制品,不能改判!");
				// return cro;
				// }
				if (!matGpM.getJugdeApplyCode().equals("")
						&& matGpM.getJudgeResultCode().equals("40740701")
						|| matGpM.getJudgeResultCode().equals("40740709")) {
					cro.setV_errMsg("该炉已送判,但未判定或判定合格,不能改判");
					return cro;
				}
				if (!matGpM.getQcmStaus().equals("00")) {
					cro.setV_errMsg("交库状态不是合格状态,不能改判!");
					return cro;
				}
				materialNoOld = matGpM.getMaterialNo();
				materialNameOld = matGpM.getMaterialName();
				produccodeOld = matGpM.getProduccode();
				producnameOld = matGpM.getProducname();
				steelcodeOld = matGpM.getSteelcode();
				steelnameOld = matGpM.getSteelname();
				specCodeOld = matGpM.getSpecCode();
				specNameOld = matGpM.getSpecName();
				modelCodeOld = matGpM.getModelCode();
				modelDescOld = matGpM.getModelDesc();
				stdStyleOld = matGpM.getStdStyle();
				stdStyleDescOld = matGpM.getStdStyleDesc();

				// 新增出库
				outBc.setOutstockSqe(sendOut
						+ StringTool.formatDecimal(outNo, "0000"));
				outBc.setOutstockPlanNo("");
				outBc.setOutstockDoc(sendOut);
				outBc.setMatNo(matGpM.getMatNo());
				outBc.setStoveNo(matGpM.getStoveNo());
				outBc.setJudgeStoveNo(matGpM.getJudgeStoveNo());
				outBc.setBatchNo(matGpM.getBatchNo());
				outBc.setBatchGroudNo(matGpM.getBatchGroudNo());
				outBc.setMaterialNo(matGpM.getMaterialNo());
				outBc.setMaterialName(matGpM.getMaterialName());
				outBc.setProduccode(matGpM.getProduccode());
				outBc.setProducname(matGpM.getProducname());
				outBc.setStdCode(matGpM.getStdCode());
				outBc.setStdName(matGpM.getStdName());
				outBc.setStdStyle(matGpM.getStdStyle());
				outBc.setStdStyleDesc(matGpM.getStdStyleDesc());
				outBc.setGradecode(matGpM.getGradecode());
				outBc.setGradename(matGpM.getGradename());
				outBc.setSteelcode(matGpM.getSteelcode());
				outBc.setSteelname(matGpM.getSteelname());
				outBc.setSpecCode(matGpM.getSpecCode());
				outBc.setSpecName(matGpM.getSpecName());
				outBc.setModelCode(matGpM.getModelCode());
				outBc.setModelDesc(matGpM.getModelDesc());
				outBc.setProOrderNo(matGpM.getProOrderNo());
				outBc.setPlineCode(matGpM.getPlineCode());
				outBc.setPlineName(matGpM.getPlineName());
				outBc.setActCount(matGpM.getActCount());
				outBc.setActWeight(matGpM.getActWeight());
				outBc.setActTheoryWeight(matGpM.getActTheoryWeight());
				outBc.setActDimater(matGpM.getActDimater());
				outBc.setActHeight(matGpM.getActHeight());
				outBc.setActLen(matGpM.getActLen());
				outBc.setActLenMax(matGpM.getActLenMax());
				outBc.setActLenMin(matGpM.getActLenMin());
				outBc.setBelongCode(matGpM.getBelongCode());
				outBc.setBelongName(matGpM.getBelongName());
				outBc.setBarCode(matGpM.getBarCode());
				outBc.setStorageNo(matGpM.getStorageNo());
				outBc.setLocNo(matGpM.getLocNo());
				outBc.setLaryNo(matGpM.getLaryNo());
				outBc.setLocationNo(matGpM.getLocationNo());
				outBc.setStorageAttr(matGpM.getStorageAttr());
				outBc.setStorageAttrName(matGpM.getStorageAttrName());
				outBc.setStorageTypeNo(matGpM.getStorageTypeNo());
				outBc.setStorageTypeName(matGpM.getStorageTypeName());
				outBc.setManagementNo(matGpM.getManagementNo());
				outBc.setManagementName(matGpM.getManagementName());
				outBc.setRpoTime(dateTime);
				outBc.setProBc(matGpM.getProBc());
				outBc.setProBz(matGpM.getProBz());
				outBc.setInstockTime(dateTime);
				outBc.setInBc(matGpM.getProBc());
				outBc.setInBz(matGpM.getProBz());
				outBc.setOutstockTime(dateTime);
				// outBc.setOutBc(bc);
				// outBc.setOutBz(bz);
				outBc.setCreateName(userName);
				outBc.setCreateTime(dateTime);
				outBc.setOrdPk(matGpM.getOrdPk());
				outBc.setOrdLnPk(matGpM.getOrdLnPk());
				outBc.setOrdLnDlyPk(matGpM.getOrdLnDlyPk());
				outBc.setDepartmentCode(matGpM.getDepartmentCode());
				outBc.setDepartmentDesc(matGpM.getDepartmentDesc());
				outBc.setOrderNo(matGpM.getOrderNo());
				outBc.setOrderSeq(matGpM.getOrderSeq());
				outBc.setDeliveryNo(matGpM.getOrderSeqNo());
				outBc.setProductFlag("801401");
				outBc.setMatStatus("80150101");
				outBc.setJudgeStdCode(matGpM.getJudgeStdCode());
				outBc.setJudgeStdName(matGpM.getJudgeStdDes());
				outBc.setPonderNo(matGpM.getPonderNo());
				outBc.setPonderGrossWt(matGpM.getPonderGrossWt());
				outBc.setLoadPlineCode("");
				outBc.setLoadPlineName("");
				outBc.setOutstockTypeCode("800808");
				outBc.setOutstockTypeName("改判出库");

				// 新增出库表记录 投料出库
				String addOut = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("FrmEndLibrary.AddOutList"), outBc);
				ps = conn.prepareStatement(addOut);
				ps.executeUpdate();
				ps.close();
				outNo++;
				// 改判时修改库存信息
				String sqlUpdateMat = CoreXmlSqlParsersFactory
						.getSql("FrmEndLibrary.UpdateSentence");
				ps = conn.prepareStatement(sqlUpdateMat);
				ps.setObject(1, materialNoNew);
				ps.setObject(2, materialNameNew);
				ps.setObject(3, produccodeNew);
				ps.setObject(4, producnameNew);
				ps.setObject(5, steelcodeNew);
				ps.setObject(6, steelnameNew);
				ps.setObject(7, specCodeNew);
				ps.setObject(8, specNameNew);
				ps.setObject(9, modelCodeNew);
				ps.setObject(10, modelDescNew);
				ps.setObject(11, stdStyleNew);
				ps.setObject(12, stdStyleDescNew);
				ps.setObject(13, judgeID);
				ps.setObject(14, outdiameZg);
				ps.setObject(15, wallthZg);
				ps.setObject(16,stdCodeNew);
				ps.setObject(17,stdNameNew);

				ps.setObject(18, matGpM.getMatNo());
				ps.setObject(19, processCdoe);
				ps.executeUpdate();
				ps.close();
			}
			// 新增入库记录
			String sqlAddint = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.AddInList");
			ps = conn.prepareStatement(sqlAddint);
			ps.setObject(1, judgeID);
			ps.setObject(2, userName);
			ps.executeUpdate();
			ps.close();

			// 生成改判记录表
			matTrack.setJudgeId(judgeID);
			matTrack.setJudgeStoveNoOld(judgeStoveNo);
			matTrack.setBatchNoOld(batchNo);
			matTrack.setBatchGroudNoOld(batchGroupBy);
			matTrack.setActCount(String.valueOf(takeCount));
			matTrack.setActWeight(String.valueOf(actWt));
			matTrack.setJudgeStoveNo(judgeStoveNo);
			matTrack.setBatchNo(batchNo);
			matTrack.setBatchGroudNo(batchGroupBy);
			matTrack.setMaterialNoOld(materialNoOld);
			matTrack.setMaterialNameOld(materialNameOld);
			matTrack.setProduccodeOld(produccodeOld);
			matTrack.setProducnameOld(producnameOld);
			matTrack.setSteelcodeOld(steelcodeOld);
			matTrack.setSteelnameOld(steelnameOld);
			matTrack.setSpecCodeOld(specCodeOld);
			matTrack.setSpecNameOld(specNameOld);
			matTrack.setModelCodeOld(modelCodeOld);
			matTrack.setModelDescOld(modelDescOld);
			matTrack.setStdStyleOld(stdStyleOld);
			matTrack.setStdStyleDescOld(stdStyleDescOld);
			matTrack.setMaterialNo(materialNoNew);
			matTrack.setMaterialName(materialNameNew);
			matTrack.setProduccode(produccodeNew);
			matTrack.setProducname(producnameNew);
			matTrack.setSteelcode(steelcodeNew);
			matTrack.setSteelname(steelnameNew);
			matTrack.setSpecCode(specCodeNew);
			matTrack.setSpecName(specNameNew);
			matTrack.setModelCode(modelCodeNew);
			matTrack.setModelDesc(modelDescNew);
			matTrack.setStdStyle(stdStyleNew);
			matTrack.setStdStyleDesc(stdStyleDescNew);
			matTrack.setCreateName(userName);
			matTrack.setBelongCode("");
			matTrack.setBelongName("");
			matTrack.setCreateMemo("");
			matTrack.setProcessCdoe(processCdoe);
			// 新增改判记录
			String sqlAddTrack = EntityTool.fillSqlByEntity(
					CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.AddSentence"), matTrack);
			ps = conn.prepareStatement(sqlAddTrack);
			ps.executeUpdate();
			ps.close();

			cro.setV_errMsg("改判成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}
	/***
	 * 无合同改判
	 * @return
	 */
	public CoreReturnObject doFrim(String matTity)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			ArrayList<String> sqllist = new ArrayList<String>();
			MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(matTity,MatBcMEntity.class);
			String updateSql = CoreXmlSqlParsersFactory.getSql("FrmEndLibrary.doFrim");
			updateSql  = EntityTool.fillSqlByEntity(updateSql,matBcEntity);
			sqllist.add(updateSql);
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("改判成功!");
			}

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


	/**
	 * 轧管,镦拔扩,热处理,加工线撤銷改判
	 * 
	 * @param jslist
	 * @param userName
	 *            改判
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doUnSentence(ArrayList<ArrayList<String>> jslist,
			String userName, String lenFalg) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			// 获取数据库当前时间
			// String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			// 循环库存信息
			for (int i = 0; i < jslist.size(); i++) {

				Date now = new Date();
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String judgeStoveNo = list.get(0);
				String batchNo = list.get(1);
				String batchGroupBy = list.get(2);
				int takeCount = Integer.parseInt(list.get(3));// 脱单
				String heatPlanNoNext = list.get(4);
				String processCdoe = list.get(5);
				String jugdeApplyCode = list.get(6);
				String judgeId = list.get(7);
				String proOrderNo = list.get(8);
				String actLen = list.get(9);
				String materialNo = list.get(10);
				List<MatBcMEntityPln> matGpMlist = getQureyMatGpM(conn,
						judgeStoveNo, batchNo, batchGroupBy, takeCount,
						heatPlanNoNext, processCdoe, jugdeApplyCode,
						proOrderNo, actLen, lenFalg,materialNo);
				if (matGpMlist == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				QcmBcJudgeChangeEntity qcmBc = getQcmBcJudgeChan(conn, judgeId,
						QcmBcJudgeChangeEntity.class);
				if (qcmBc == null) {
					cro.setV_errMsg("未查到改判记录!");
					return cro;
				}
				String actDimater = "";
				String actHeight = "";
				if (!qcmBc.getSpecNameOld().equals("")) {
					String[] splitstr = qcmBc.getSpecNameOld().split("x");
					actDimater = splitstr[0].toString();
					actHeight = splitstr[1].toString();
				}
				for (MatBcMEntityPln matGpM : matGpMlist) {
					/*if (!matGpM.getHeatPlanNoNext().equals("")) {
						cro.setV_errMsg("选中炉已挂下工序订单,不能撤銷改判!");
						return cro;
					}*/
					// if (!matGpM.getProductFlag().equals("801401")) {
					// cro.setV_errMsg("材料类别不是在制品,不能撤銷改判!");
					// return cro;
					// }
					if (!matGpM.getJugdeApplyCode().equals("")
							&& matGpM.getJudgeResultCode().equals("40740701")
							|| matGpM.getJudgeResultCode().equals("40740709")) {
						cro.setV_errMsg("该炉已送判,但未判定或判定合格,不能撤銷改判");
						return cro;
					}
					// 改判时修改库存信息
					String sqlUpdateMat = CoreXmlSqlParsersFactory
							.getSql("FrmEndLibrary.UpdateSentence");
					ps = conn.prepareStatement(sqlUpdateMat);
					ps.setObject(1, qcmBc.getMaterialNoOld());
					ps.setObject(2, qcmBc.getMaterialNameOld());
					ps.setObject(3, qcmBc.getProduccodeOld());
					ps.setObject(4, qcmBc.getProducnameOld());
					ps.setObject(5, qcmBc.getSteelcodeOld());
					ps.setObject(6, qcmBc.getSteelnameOld());
					ps.setObject(7, qcmBc.getSpecCodeOld());
					ps.setObject(8, qcmBc.getSpecNameOld());
					ps.setObject(9, qcmBc.getModelCodeOld());
					ps.setObject(10, qcmBc.getModelDescOld());
					ps.setObject(11, qcmBc.getStdStyleOld());
					ps.setObject(12, qcmBc.getStdStyleDescOld());
					ps.setObject(13, "");
					ps.setObject(14, actDimater);
					ps.setObject(15, actHeight);
					ps.setObject(16, "");//标准代码
					ps.setObject(17, "");//标准名称
					ps.setObject(18, qcmBc.getJudgeStoveNoOld());
					ps.setObject(19, matGpM.getMatNo().replaceAll(matGpM.getJudgeStoveNo(), qcmBc.getJudgeStoveNoOld()));
					ps.setObject(20, matGpM.getMatNo());
					ps.setObject(21, processCdoe);
					ps.executeUpdate();
					ps.close();
					// 改判时修改库存位置信息
					String sqlUpdatebs = "update YDM_BC_BUTTRESS t set t.judge_stove_no = ?,t.mat_no = ? where t.mat_no = ?";
					ps = conn.prepareStatement(sqlUpdatebs);
					ps.setObject(1,qcmBc.getJudgeStoveNoOld());//旧炉号
					ps.setObject(2,matGpM.getMatNo().replaceAll(matGpM.getJudgeStoveNo(), qcmBc.getJudgeStoveNoOld()));//旧管号
					ps.setObject(3, matGpM.getMatNo());//新管号
					ps.executeUpdate();
					ps.close();

					// 刪除改判入庫
					String deleteIn = "DELETE YDM_BC_INLIST WHERE JUDGE_STOVE_NO = ? AND  INSTOCK_TYPE_CODE='800706' AND BATCH_NO=? AND BATCH_GROUD_NO=?";
					ps = conn.prepareStatement(deleteIn);
					ps.setObject(1, judgeStoveNo);
					ps.setObject(2, batchNo);
					ps.setObject(3, batchGroupBy);
					ps.executeUpdate();
					ps.close();
					// 刪除改判出庫
					String deleteOut = "DELETE YDM_BC_OUTLIST WHERE JUDGE_STOVE_NO = ? AND OUTSTOCK_TYPE_CODE='800808' AND BATCH_NO=? AND BATCH_GROUD_NO=?";
					ps = conn.prepareStatement(deleteOut);
					ps.setObject(1, qcmBc.getJudgeStoveNoOld());
					ps.setObject(2, batchNo);
					ps.setObject(3, batchGroupBy);
					ps.executeUpdate();
					ps.close();

				}

				// 刪除改判記錄
				String updateQcmZg = "DELETE QCM_BC_JUDGE_CHANGE WHERE JUDGE_ID = ?";
				ps = conn.prepareStatement(updateQcmZg);
				ps.setObject(1, judgeId);
				ps.executeUpdate();
				ps.close();

			}
			cro.setV_errMsg("撤销改判成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 新增镦拔扩虚拟炉计划
	 * 
	 * @return
	 */
	public boolean addPlnZyDbkM(Connection con, MatBcTrackEntity matTrack,
			int takeCount, double actWt, List<PlnOrderDbkSEntity> plnDbk,
			String createName, String createTime, String nextProcessCdeo,
			String processCdoe, String cic, String heatPlanNoNew)
			throws SQLException {
		PlnZyDbkMEntity plnDbkM = new PlnZyDbkMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 轧管单倍支
		int zgNum = takeCount;
		double totWeightM = actWt;
		int contZgM = 0;
		int countZg = plnDbk.size();
		for (PlnOrderDbkSEntity plnDbkS : plnDbk) {
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnDbkS.getExeStatus()) > 1) {
				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'";
			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_JGX_C T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
			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();
			// 判断计划支吨是否大于轧管需坯支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM
						- (Double.parseDouble(plnDbkS.getWeigthS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					oldWt = Double.parseDouble(plnDbkS.getWeigthS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnDbkM.setPassCode(plnDbkS.getPassCode());
			plnDbkM.setPassName(plnDbkS.getPassName());
			plnDbkM.setDecision(plnDbkS.getDecision());
			plnDbkM.setStoveNo(matTrack.getStoveNo());
			plnDbkM.setFeedHeatNo(matTrack.getJudgeStoveNo());
			plnDbkM.setJudgeStoveNo(matTrack.getJudgeStoveNo());
			plnDbkM.setFlagStoveNo(matTrack.getJudgeStoveNo());
			plnDbkM.setBatchNo("");
			plnDbkM.setUpperHeatplanId(heatPlanNoNew);
			plnDbkM.setPlanstatus("00");
			plnDbkM.setUpperProcessCode(processCdoe);
			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");
			}
			plnDbkM.setIfMatchOdd("3");
			plnDbkM.setIfDoHeatPlan("0");
			plnDbkM.setProPlanId(plnDbkS.getProPlanId());
			plnDbkM.setGxPlanNo(plnDbkS.getGxPlanNo());
			plnDbkM.setGradecode(matTrack.getGradecode());
			plnDbkM.setGradename(matTrack.getGradename());
			plnDbkM.setSteelcode(plnDbkS.getSteelcode());
			plnDbkM.setSteelname(plnDbkS.getSteelname());
			plnDbkM.setProduccode(plnDbkS.getProduccode());
			plnDbkM.setProducname(plnDbkS.getProducname());
			// 通过BOM查询投入产出
			String[] bomMat = PlanFurnProduction.getQueryBom(con,
					plnDbkS.getBom(), plnDbkS.getIndexSeq(),
					plnDbkS.getOrdLnDlyPk(), "E", matTrack.getGradecode());
			plnDbkM.setInwlId(bomMat[0]);
			plnDbkM.setInwlDesc(bomMat[1]);
			plnDbkM.setOutwlId(bomMat[2]);
			plnDbkM.setOutwlDesc(bomMat[3]);
			plnDbkM.setBom(bomMat[4]);
			plnDbkM.setModelCode(plnDbkS.getModelCode());
			plnDbkM.setModelDesc(plnDbkS.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));
			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());
			// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
			String sqlBom = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialDbk.queryBaseMaterialEPl");
			sqlBom += " AND T.E_IN_MATERIAL_NO=?";
			ps = con.prepareStatement(sqlBom);
			ps.setObject(1, plnDbkS.getOrdLnDlyPk());
			ps.setObject(2, plnDbkS.getIndexSeq());
			ps.setObject(3, plnDbkS.getCraftSeq());
			ps.setObject(4, plnDbkS.getInwlId());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnDbkM.setBom(rs.getString("BOM"));
				plnDbkM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));
			}
			rs.close();
			ps.close();
			plnDbkM.setWholeBacklogDesc(plnDbkS.getWholeBacklogDesc());
			plnDbkM.setStationRoad(plnDbkS.getStationRoad());
			plnDbkM.setCic(cic);
			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());

			// 查询轧管排产信息
			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.setProdStandard(rs.getString("PROD_STANDARD"));
				plnDbkM.setOutputStandard(rs.getString("Output_Standard"));
				plnDbkM.setSecCraftFileNo(rs.getString("SEC_CRAFT_FILE_NO"));
				plnDbkM.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
			}
			rs.close();
			ps.close();
			plnDbkM.setLengthIn(matTrack.getActLen());
			plnDbkM.setLengthmaxIn(matTrack.getActLenMax());
			plnDbkM.setLengthminIn(matTrack.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 = corePlanFurnProM.getMaxHeatPlanNo(con,
					plnDbkM.getProPlanId(), plnDbkM.getProPlanId(), "E");
			// 获取炉计划顺序号
			int gxProSeq = corePlanFurnProM.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();
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;

			// 修改库存下工序订单，炉计划ID
			String updateMat = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.updateNext");
			ps = con.prepareStatement(updateMat);
			ps.setObject(1, matTrack.getJudgeStoveNo());
			ps.setObject(2, matTrack.getBatchNo());
			ps.setObject(3, matTrack.getBatchGroudNo());
			ps.setObject(4, nextProcessCdeo);
			ps.setObject(5, takeCount);
			ps.setObject(6, plnDbkS.getProPlanId());
			ps.setObject(7, plnDbkS.getGxPlanNo());
			ps.setObject(8, heatPlanNo);
			ps.executeUpdate();
			ps.close();
		}
		return true;
	}

	/**
	 * 新增热处理虚拟炉计划
	 * 
	 * @return
	 */
	public boolean addPlnZyRclM(Connection con, MatBcTrackEntity matTrack,
			int takeCount, double actWt, List<PlnOrderRclSEntity> plnOrder,
			String createName, String createTime, String nextProcessCdeo,
			String processCdoe, String cic, String heatPlanNoNew)
			throws SQLException {
		PlnZyRclMEntity plnM = new PlnZyRclMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		int zgNum = takeCount;
		double totWeightM = actWt;
		int contZgM = 0;
		int countZg = plnOrder.size();
		for (PlnOrderRclSEntity plnS : plnOrder) {
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnS.getExeStatus()) > 1) {
				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'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnS.getProPlanId());
			ps.setObject(2, plnS.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=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnS.getProPlanId());
			ps.setObject(2, plnS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("PLAN_INDOUBLE_WT");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于排产支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM - (Double.parseDouble(plnS.getWeigthS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					oldWt = Double.parseDouble(plnS.getWeigthS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnM.setDecision(plnS.getDecision());
			plnM.setStoveNo(matTrack.getStoveNo());
			plnM.setFeedHeatNo(matTrack.getJudgeStoveNo());
			plnM.setJudgeStoveNo(matTrack.getJudgeStoveNo());
			plnM.setFlagStoveNo(matTrack.getJudgeStoveNo());
			plnM.setBatchNo("");
			plnM.setUpperHeatplanId(heatPlanNoNew);
			plnM.setPlanstatus("00");
			plnM.setUpperProcessCode(processCdoe);
			plnM.setPlineCode(plnS.getPlineCode());
			plnM.setPlineName(plnS.getPlineName());
			plnM.setProcessCodeC(plnS.getProcessCodeC());
			plnM.setProcessDescC(plnS.getProcessDescC());
			if (!plnS.getDecision().equals("A")) {
				// 通过制程判定镦拔扩是否末工序
				if (plnS.getWholeBacklogDesc().contains("加工")) {
					plnM.setNextProcessCode("G");
				} else {
					if (plnS.getOrdLnDlyPk().contains("ZZBY-J")) {
						plnM.setNextProcessCode("H");
					} else if (plnS.getOrdLnDlyPk().contains("ZZBY-D")) {
						plnM.setNextProcessCode("G");
					} else {
						plnM.setNextProcessCode("");
					}
				}
				plnM.setIsendgx("0");
			} else {
				plnM.setNextProcessCode("");
				plnM.setIsendgx("1");
			}
			plnM.setIfMatchOdd("3");
			plnM.setIfDoHeatPlan("0");
			plnM.setProPlanId(plnS.getProPlanId());
			plnM.setGxPlanNo(plnS.getGxPlanNo());
			plnM.setGradecode(matTrack.getGradecode());
			plnM.setGradename(matTrack.getGradename());
			plnM.setSteelcode(plnS.getSteelcode());
			plnM.setSteelname(plnS.getSteelname());
			plnM.setProduccode(plnS.getProduccode());
			plnM.setProducname(plnS.getProducname());
			// 通过BOM查询投入产出
			String[] bomMat = PlanFurnProduction.getQueryBom(con,
					plnS.getBom(), plnS.getIndexSeq(), plnS.getOrdLnDlyPk(),
					"F", matTrack.getGradecode());
			plnM.setInwlId(bomMat[0]);
			plnM.setInwlDesc(bomMat[1]);
			plnM.setOutwlId(bomMat[2]);
			plnM.setOutwlDesc(bomMat[3]);
			plnM.setBom(bomMat[4]);
			plnM.setModelCode(plnS.getModelCode());
			plnM.setModelDesc(plnS.getModelDesc());
			// 单倍支吨
			plnM.setPlnInsingleNum(String.valueOf(oldNum));
			plnM.setPlnInsingleWt(String.valueOf(oldWt));
			plnM.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='"
					+ plnS.getPlineCode() + "'";
			ps = con.prepareStatement(sqlRate);
			rs = ps.executeQuery();
			if (rs.next()) {
				burnoutRate = rs.getDouble("BURNOUT_RATE");
			}
			rs.close();
			ps.close();
			double yjWt = actWt - actWt * burnoutRate;
			plnM.setPlnOutsingleW(String.valueOf(yjWt));
			plnM.setOrderSource(plnS.getOrderSource());
			plnM.setOrderNo(plnS.getOrderNo());
			plnM.setOrderSeq(plnS.getOrderSeq());
			plnM.setDeliveryNo(plnS.getDeliveryNo());
			plnM.setOrdLnDlyPk(plnS.getOrdLnDlyPk());
			plnM.setReqBlId(plnS.getReqBlId());
			plnM.setIfExport(plnS.getIfExport());
			plnM.setPriority(plnS.getPriority());
			plnM.setPriorityMemo(plnS.getPriorityMemo());
			plnM.setProMonth(plnS.getProMonth());
			plnM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnM.setIfMonitor(plnS.getIfMonitorRcl());
			plnM.setPrdcrNo(plnS.getPrdcrNo());
			plnM.setMonitorPoint(plnS.getMonitorPoint());
			// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
			String sqlBom = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialDbk.queryBaseMaterialFPl");
			sqlBom += " AND T.F_IN_MATERIAL_NO=?";
			ps = con.prepareStatement(sqlBom);
			ps.setObject(1, plnS.getOrdLnDlyPk());
			ps.setObject(2, plnS.getIndexSeq());
			ps.setObject(3, plnS.getCraftSeq());
			ps.setObject(4, plnS.getInwlId());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnM.setBom(rs.getString("BOM"));
				plnM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));
			}
			rs.close();
			ps.close();
			plnM.setWholeBacklogDesc(plnS.getWholeBacklogDesc());
			plnM.setStationRoad(plnS.getStationRoad());
			plnM.setCic(cic);
			if (plnS.getSic() == null || plnS.getSic().equals("")) {
				plnM.setSic(plnS.getSic());
			} else {
				plnM.setSic(plnS.getSic().split(",")[0]);
			}
			if (plnS.getDic() == null || plnS.getDic().equals("")) {
				plnM.setDic(plnS.getDic());
			} else {
				plnM.setDic(plnS.getDic().split(",")[0]);
			}
			if (plnS.getPic() == null || plnS.getPic().equals("")) {
				plnM.setPic(plnS.getPic());
			} else {
				plnM.setPic(plnS.getPic().split(",")[0]);
			}
			plnM.setCraftFileMan(plnS.getCraftFileMan());
			plnM.setCraftFileNo(plnS.getCraftFileNo());
			plnM.setCraftSeq(plnS.getCraftSeq());
			plnM.setOutdiameter(plnS.getOutdiameter());
			plnM.setWallthick(plnS.getWallthick());

			// 查询轧管排产信息
			String sqlZg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.QueryWgZg");
			ps = con.prepareStatement(sqlZg);
			ps.setObject(1, plnS.getOrdLnDlyPk());
			// ps.setObject(2, plnS.getPlnDivideId());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnM.setProdStandard(rs.getString("PROD_STANDARD"));
				plnM.setOutputStandard(rs.getString("Output_Standard"));
				plnM.setSecCraftFileNo(rs.getString("SEC_CRAFT_FILE_NO"));
				plnM.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
			}
			rs.close();
			ps.close();
			plnM.setLengthIn(matTrack.getActLen());
			plnM.setLengthmaxIn(matTrack.getActLenMax());
			plnM.setLengthminIn(matTrack.getActLenMin());
			plnM.setOutdiameterIn(matTrack.getActDimater());
			plnM.setWallthickIn(matTrack.getActHeight());
			// 查询合同最大最小长度
			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, plnS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();
			plnM.setLengthmax(String.valueOf(lenMax));
			plnM.setLengthmin(String.valueOf(lenMin));
			plnM.setCreateName(createName);
			plnM.setCreateTime(createTime);
			plnM.setIndexSeq(plnS.getIndexSeq());
			plnM.setSpecCode(plnS.getSpecCode());
			plnM.setSpecName(plnS.getSpecName());
			plnM.setStdCode(plnS.getStdCode());
			plnM.setStdName(plnS.getStdName());
			plnM.setStdStyle(plnS.getStdStyle());
			plnM.setStdStyleDesc(plnS.getStdStyleDesc());
			// 获取热处理循环次数
			String sqlSeq = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialRcl.QueryProcessSeq");
			ps = con.prepareStatement(sqlSeq);
			ps.setObject(1, plnS.getProPlanId());
			ps.setObject(2, plnS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnM.setProcessSeq(rs.getString("PROCESS_SEQ"));
			} else {
				plnM.setProcessSeq("1");
			}
			rs.close();
			ps.close();
			// 新增
			heatPlanNo = corePlanFurnProM.getMaxHeatPlanNo(con,
					plnS.getProPlanId(), plnS.getProPlanId(), "F");
			// 获取炉计划顺序号
			int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(con,
					plnS.getPlineCode(), "F");
			// 订单内炉顺序号
			int lotNo = corePlanFurnProM.getMaxLotNoSqe(con,
					plnS.getProPlanId(), plnS.getGxPlanNo(), "F");

			String ifProduct = "0";
			int counnum = StoveHelper.getQueryStation(con, plnS.getProPlanId(),
					plnS.getGxPlanNo(), "F");
			if (counnum > 0) {
				ifProduct = "1";
			}
			plnM.setIfProduct(ifProduct);
			plnM.setLotNoSqe(String.valueOf(lotNo));
			plnM.setHeatPlanNo(heatPlanNo);
			plnM.setGxProSeq(String.valueOf(gxProSeq));
			plnM.setRealProcessSeq("1");
			String addPlnGxZg = EntityTool.fillSqlByEntity(
					CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.addPlnZyRcl"), plnM);
			ps = con.prepareStatement(addPlnGxZg);
			ps.executeUpdate();
			ps.close();

			// 新增生产批号
			StoveHelper.updatePlnRclGroup(con, plnM.getProPlanId(),
					plnM.getGxPlanNo(), plnM.getPic());

			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;

			// 修改库存下工序订单，炉计划ID
			String updateMat = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.updateNext");
			ps = con.prepareStatement(updateMat);
			ps.setObject(1, matTrack.getJudgeStoveNo());
			ps.setObject(2, matTrack.getBatchNo());
			ps.setObject(3, matTrack.getBatchGroudNo());
			ps.setObject(4, nextProcessCdeo);
			ps.setObject(5, takeCount);
			ps.setObject(6, plnS.getProPlanId());
			ps.setObject(7, plnS.getGxPlanNo());
			ps.setObject(8, heatPlanNo);
			ps.executeUpdate();
			ps.close();
		}
		return true;
	}

	/**
	 * 新增加工线虚拟炉计划
	 * 
	 * @return
	 */
	public boolean addPlnZyJgxM(Connection con, MatBcTrackEntity matTrack,
			int takeCount, double actWt, List<PlnOrderJgxSEntity> plnOrder,
			String createName, String createTime, String nextProcessCdeo,
			String processCdoe, String cic, String heatPlanNoNew)
			throws SQLException {
		PlnZyJgxMEntity plnM = new PlnZyJgxMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		int zgNum = takeCount;
		double totWeightM = actWt;
		int contZgM = 0;
		int countZg = plnOrder.size();
		for (PlnOrderJgxSEntity plnS : plnOrder) {
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnS.getExeStatus()) > 1) {
				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'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnS.getProPlanId());
			ps.setObject(2, plnS.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=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnS.getProPlanId());
			ps.setObject(2, plnS.getGxPlanNo());
			rs = ps.executeQuery();
			if (rs.next()) {
				wtIn += rs.getDouble("PLAN_INDOUBLE_WT");
			}
			rs.close();
			ps.close();
			// 判断计划支吨是否大于排产支吨
			if (countZg == 1) {
				oldWt = totWeightM;
				oldNum = zgNum;
			} else {
				if (totWeightM - (Double.parseDouble(plnS.getWeigthS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					oldWt = Double.parseDouble(plnS.getWeigthS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnM.setDecision(plnS.getDecision());
			plnM.setStoveNo(matTrack.getStoveNo());
			plnM.setFeedHeatNo(matTrack.getJudgeStoveNo());
			plnM.setJudgeStoveNo(matTrack.getJudgeStoveNo());
			plnM.setFlagStoveNo(matTrack.getJudgeStoveNo());
			plnM.setBatchNo("");
			plnM.setUpperHeatplanId(heatPlanNoNew);
			plnM.setPlanstatus("00");
			plnM.setUpperProcessCode(processCdoe);
			plnM.setPlineCode(plnS.getPlineCode());
			plnM.setPlineName(plnS.getPlineName());
			plnM.setProcessCodeC(plnS.getProcessCodeC());
			plnM.setProcessDescC(plnS.getProcessDescC());

			if (plnS.getOrdLnDlyPk().contains("ZZBY-J")) {
				plnM.setNextProcessCode("H");
				plnM.setIsendgx("0");
			} else if (plnS.getOrdLnDlyPk().contains("ZZBY-D")) {
				plnM.setNextProcessCode("G");
				plnM.setIsendgx("0");
			} else {
				plnM.setNextProcessCode("");
				plnM.setIsendgx("1");
			}

			plnM.setIfMatchOdd("3");
			plnM.setIfDoHeatPlan("0");
			plnM.setProPlanId(plnS.getProPlanId());
			plnM.setGxPlanNo(plnS.getGxPlanNo());
			plnM.setGradecode(matTrack.getGradecode());
			plnM.setGradename(matTrack.getGradename());
			plnM.setSteelcode(plnS.getSteelcode());
			plnM.setSteelname(plnS.getSteelname());
			plnM.setProduccode(plnS.getProduccode());
			plnM.setProducname(plnS.getProducname());
			// 通过BOM查询投入产出
			String[] bomMat = null;
			if (plnS.getWholeBacklog().equals("G")) {
				bomMat = PlanFurnProduction.getQueryBomJgx(con,
						plnS.getOrdLnDlyPk(), matTrack.getMaterialNo());
			} else {
				bomMat = PlanFurnProduction.getQueryBom(con, plnS.getBom(),
						plnS.getIndexSeq(), plnS.getOrdLnDlyPk(), "G",
						matTrack.getGradecode());
			}
			plnM.setInwlId(bomMat[0]);
			plnM.setInwlDesc(bomMat[1]);
			plnM.setOutwlId(bomMat[2]);
			plnM.setOutwlDesc(bomMat[3]);
			plnM.setBom(bomMat[4]);
			plnM.setModelCode(plnS.getModelCode());
			plnM.setModelDesc(plnS.getModelDesc());
			// 单倍支吨
			plnM.setPlnInsingleNum(String.valueOf(oldNum));
			plnM.setPlnInsingleWt(String.valueOf(oldWt));
			plnM.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='"
					+ plnS.getPlineCode() + "'";
			ps = con.prepareStatement(sqlRate);
			rs = ps.executeQuery();
			if (rs.next()) {
				burnoutRate = rs.getDouble("BURNOUT_RATE");
			}
			rs.close();
			ps.close();
			double yjWt = actWt - actWt * burnoutRate;
			plnM.setPlnOutsingleW(String.valueOf(yjWt));
			plnM.setOrderSource(plnS.getOrderSource());
			plnM.setOrderNo(plnS.getOrderNo());
			plnM.setOrderSeq(plnS.getOrderSeq());
			plnM.setDeliveryNo(plnS.getDeliveryNo());
			plnM.setOrdLnDlyPk(plnS.getOrdLnDlyPk());
			plnM.setReqBlId(plnS.getReqBlId());
			plnM.setIfExport(plnS.getIfExport());
			plnM.setPriority(plnS.getPriority());
			plnM.setPriorityMemo(plnS.getPriorityMemo());
			plnM.setProMonth(plnS.getProMonth());
			plnM.setProDay(createTime.substring(0, 10).replace("-", ""));
			plnM.setBalYearMonth(createTime.substring(0, 7).replace("-", ""));
			plnM.setIfMonitor(plnS.getIfMonitorJgx());
			plnM.setPrdcrNo(plnS.getPrdcrNo());
			plnM.setMonitorPoint(plnS.getMonitorPoint());
			// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
			String sqlBom = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialDbk.queryBaseMaterialGPl");
			sqlBom += " AND T.I_IN_MATERIAL_NO=?";
			ps = con.prepareStatement(sqlBom);
			ps.setObject(1, plnS.getOrdLnDlyPk());
			ps.setObject(2, plnS.getIndexSeq());
			ps.setObject(3, plnS.getCraftSeq());
			ps.setObject(4, plnS.getInwlId());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnM.setBom(rs.getString("BOM"));
				plnM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));
			}
			rs.close();
			ps.close();
			plnM.setWholeBacklogDesc(plnS.getWholeBacklogDesc());
			plnM.setStationRoad(plnS.getStationRoad());
			plnM.setCic(cic);
			if (plnS.getSic() == null || plnS.getSic().equals("")) {
				plnM.setSic(plnS.getSic());
			} else {
				plnM.setSic(plnS.getSic().split(",")[0]);
			}
			if (plnS.getDic() == null || plnS.getDic().equals("")) {
				plnM.setDic(plnS.getDic());
			} else {
				plnM.setDic(plnS.getDic().split(",")[0]);
			}
			if (plnS.getPic() == null || plnS.getPic().equals("")) {
				plnM.setPic(plnS.getPic());
			} else {
				plnM.setPic(plnS.getPic().split(",")[0]);
			}
			plnM.setCraftFileMan(plnS.getCraftFileMan());
			plnM.setCraftFileNo(plnS.getCraftFileNo());
			plnM.setCraftSeq(plnS.getCraftSeq());
			plnM.setOutdiameter(plnS.getOutdiameter());
			plnM.setWallthick(plnS.getWallthick());

			// 查询轧管排产信息
			String sqlZg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.QueryWgZg");
			ps = con.prepareStatement(sqlZg);
			ps.setObject(1, plnS.getOrdLnDlyPk());
			// ps.setObject(2, plnS.getPlnDivideId());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnM.setProdStandard(rs.getString("PROD_STANDARD"));
				plnM.setOutputStandard(rs.getString("Output_Standard"));
				plnM.setSecCraftFileNo(rs.getString("SEC_CRAFT_FILE_NO"));
				plnM.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
			}
			rs.close();
			ps.close();
			plnM.setLengthIn(matTrack.getActLen());
			plnM.setLengthmaxIn(matTrack.getActLenMax());
			plnM.setLengthminIn(matTrack.getActLenMin());
			plnM.setOutdiameterIn(matTrack.getActDimater());
			plnM.setWallthickIn(matTrack.getActHeight());
			// 查询合同最大最小长度
			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, plnS.getOrdLnDlyPk());
			rs = ps.executeQuery();
			if (rs.next()) {
				lenMax = rs.getDouble("LENGTHMAX");
				lenMin = rs.getDouble("LENGTHMIN");
			}
			rs.close();
			ps.close();
			int outnumCut = 1;
			if (!matTrack.getActLenMax().equals("")) {
				outnumCut = (int) (Double.parseDouble(matTrack.getActLenMax()) / lenMin);
			}
			if (outnumCut <= 0) {
				outnumCut = 1;
			}
			plnM.setLengthmax(String.valueOf(lenMax));
			plnM.setLengthmin(String.valueOf(lenMin));
			plnM.setOutnumCut(String.valueOf(outnumCut));

			plnM.setCreateName(createName);
			plnM.setCreateTime(createTime);
			plnM.setIndexSeq(plnS.getIndexSeq());
			plnM.setSpecCode(plnS.getSpecCode());
			plnM.setSpecName(plnS.getSpecName());
			plnM.setStdCode(plnS.getStdCode());
			plnM.setStdName(plnS.getStdName());
			plnM.setStdStyle(plnS.getStdStyle());
			plnM.setStdStyleDesc(plnS.getStdStyleDesc());

			// 新增
			heatPlanNo = corePlanFurnProM.getMaxHeatPlanNo(con,
					plnS.getProPlanId(), plnS.getProPlanId(), "G");
			// 获取炉计划顺序号
			int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(con,
					plnS.getPlineCode(), "G");
			// 订单内炉顺序号
			int lotNo = corePlanFurnProM.getMaxLotNoSqe(con,
					plnM.getProPlanId(), plnM.getGxPlanNo(), "G");
			plnM.setLotNoSqe(String.valueOf(lotNo));
			plnM.setHeatPlanNo(heatPlanNo);
			plnM.setGxProSeq(String.valueOf(gxProSeq));
			String addPlnGxZg = EntityTool.fillSqlByEntity(
					CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.addPlnZyJgx"), plnM);
			ps = con.prepareStatement(addPlnGxZg);
			ps.executeUpdate();
			ps.close();

			// 新增生产批号
			StoveHelper.updatePlnJgxGroup(con, plnM.getProPlanId(),
					plnM.getGxPlanNo(), plnM.getPic());
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;

			// 修改库存下工序订单，炉计划ID
			String updateMat = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.updateNext");
			ps = con.prepareStatement(updateMat);
			ps.setObject(1, matTrack.getJudgeStoveNo());
			ps.setObject(2, matTrack.getBatchNo());
			ps.setObject(3, matTrack.getBatchGroudNo());
			ps.setObject(4, nextProcessCdeo);
			ps.setObject(5, takeCount);
			ps.setObject(6, plnS.getProPlanId());
			ps.setObject(7, plnS.getGxPlanNo());
			ps.setObject(8, heatPlanNo);
			ps.executeUpdate();
			ps.close();
		}
		return true;
	}

	/**
	 * 新增接箍虚拟炉计划
	 * 
	 * @return
	 */
	public boolean addPlnZyJgM(Connection con, MatBcTrackEntity matTrack,
			int takeCount, double actWt, List<PlnGxJgPropSEntity> plnOrder,
			String createName, String createTime, String nextProcessCdeo,
			String processCdoe, String heatPlanNoNew) throws SQLException {
		PlnZyJgMEntity plnJgM = new PlnZyJgMEntity();
		String sql = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		double oldWt = 0;// 原料计划吨
		int oldNum = 0;// 原料计划支
		String heatPlanNo = "";
		// 排产支
		int zgNum = takeCount;
		double totWeightM = actWt;
		int contZgM = 0;
		int countZg = plnOrder.size();
		for (PlnGxJgPropSEntity plnS : plnOrder) {
			// int cutNum = Integer.parseInt(plnS.getOutnumCut());
			contZgM++;
			if (totWeightM <= 0) {
				continue;
			}
			if (Integer.parseInt(plnS.getExeStatus()) > 1) {
				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_MATCH_ODD='0'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnS.getProPlanId());
			ps.setObject(2, plnS.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=?";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plnS.getProPlanId());
			ps.setObject(2, plnS.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, plnS.getProPlanId() + "/" + plnS.getGxPlanNo());
			// ps.setObject(2, matTrack.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(plnS.getGroupBlWtS()) - wtIn) < 0.00002) {
					oldWt = totWeightM;
					oldNum = zgNum;
				} else {
					oldWt = Double.parseDouble(plnS.getGroupBlWtS()) - wtIn;
					oldNum = (int) Math.ceil(oldWt / (totWeightM / zgNum));
				}
			}
			if (oldNum <= 0) {
				continue;
			}
			plnJgM.setUpperHeatplanId(heatPlanNoNew);
			plnJgM.setStoveNo(matTrack.getStoveNo());
			plnJgM.setJudgeStoveNo(matTrack.getJudgeStoveNo());
			plnJgM.setFlagStoveNo(matTrack.getJudgeStoveNo());
			plnJgM.setPlanstatus("00");
			plnJgM.setPlineCode(plnS.getPlineCode());
			plnJgM.setPlineName(plnS.getPlineName());
			plnJgM.setIfMatchOdd("3");
			plnJgM.setIfDoHeatPlan("0");
			plnJgM.setUpperProcessCode(processCdoe);
			plnJgM.setProPlanId(plnS.getProPlanId());
			plnJgM.setGxPlanNo(plnS.getGxPlanNo());
			plnJgM.setJgGroupId(plnS.getJgGroupId());
			plnJgM.setCodeJg(plnS.getCodeJg());
			plnJgM.setMinD(plnS.getMinD());
			plnJgM.setMinH(plnS.getMinH());
			plnJgM.setAimCutLen(plnS.getAimCutLen());
			plnJgM.setAimlengthBl(plnS.getAimlengthBl());
			plnJgM.setGradecode(plnS.getGradecode());
			plnJgM.setGradename(plnS.getGradename());
			plnJgM.setSteelcode(plnS.getSteelcode());
			plnJgM.setSteelname(plnS.getSteelname());
			// 查询轧管排产信息
			String sqlZg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.QueryWgZg");
			ps = con.prepareStatement(sqlZg);
			ps.setObject(1, plnS.getOrdLnDlyPk());
			// ps.setObject(2, plnS.getPlnDivideId());
			rs = ps.executeQuery();
			if (rs.next()) {
				plnJgM.setProdStandard(rs.getString("PROD_STANDARD"));
				plnJgM.setOutputStandard(rs.getString("Output_Standard"));
			}
			rs.close();
			ps.close();

			plnJgM.setBlWlId(plnS.getBlWlId());
			plnJgM.setBlWlDesc(plnS.getBlWlDesc());
			plnJgM.setOutwlId(plnS.getOutwlId());
			plnJgM.setOutwlDesc(plnS.getOutwlDesc());
			plnJgM.setModelCode(plnS.getModelCode());
			plnJgM.setModelDesc(plnS.getModelDesc());
			plnJgM.setLengthMax(plnS.getLengthMax());
			plnJgM.setLengthMin(plnS.getLengthMin());
			plnJgM.setTaper(plnS.getTaper());
			plnJgM.setCodeJgBl(plnS.getCodeJgBl());
			plnJgM.setSpecJg(plnS.getSpecJg());
			plnJgM.setSpecJgDesc(plnS.getSpecJgDesc());
			plnJgM.setSingleCutNun(plnS.getSingleCutNun());
			// 查询接箍信息
			String sqlCodeJg = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryCodeJg");
			ps = con.prepareStatement(sqlCodeJg);
			ps.setObject(1, plnS.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(plnS.getDemandCopper());
			// 计划支吨
			plnJgM.setPlanJgNum(String.valueOf(oldNum
					* Integer.parseInt(plnS.getSingleCutNun())));
			plnJgM.setPlanBlNum(String.valueOf(oldNum));
			plnJgM.setPlanBlWt(String.valueOf(oldWt));

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

			plnJgM.setCreateName(createName);
			plnJgM.setCreateTime(createTime);
			// if (fl == 0) {
			// 新增
			heatPlanNo = corePlanFurnProM.getMaxHeatPlanNo(con,
					plnJgM.getProPlanId(), plnJgM.getProPlanId(), "H");
			// 获取炉计划顺序号
			int gxProSeq = corePlanFurnProM.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(plnS.getSingleCutNun()));
			// ps.setObject(2, oldNum);
			// ps.setObject(3, oldWt);
			// ps.setObject(4, heatPlanNo);
			// ps.executeUpdate();
			// ps.close();
			// }
			totWeightM = totWeightM - oldWt;
			zgNum = zgNum - oldNum;

			// 修改库存下工序订单，炉计划ID
			String updateMat = CoreXmlSqlParsersFactory
					.getSql("FrmEndLibrary.updateNext");
			ps = con.prepareStatement(updateMat);
			ps.setObject(1, matTrack.getJudgeStoveNo());
			ps.setObject(2, matTrack.getBatchNo());
			ps.setObject(3, matTrack.getBatchGroudNo());
			ps.setObject(4, nextProcessCdeo);
			ps.setObject(5, takeCount);
			ps.setObject(6, plnS.getProPlanId());
			ps.setObject(7, plnS.getGxPlanNo());
			ps.setObject(8, heatPlanNo);
			ps.executeUpdate();
			ps.close();
		}
		return true;
	}

	/**
	 * 返线
	 * 
	 * @throws Exception
	 */
	public CoreReturnObject doReturnLine(ArrayList<String> list,
			String userName, String proPlanId, String gxPlanNo, String lenFalg) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		Connection jhyCon = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			jhyCon = this.getDao("JhyDao").getConnection();
			jhyCon.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			String judgeStoveNo = list.get(0);
			String batchNo = list.get(1);
			String batchGroupBy = list.get(2);
			int takeCount = Integer.parseInt(list.get(3));// 利库支
			// Double.parseDouble(list.get(4));
			String processCdoe = list.get(5);
			String OnProOrderId = list.get(6);// 本工序订单+排产序号
			String heatPlanNoOld = list.get(7);//
			String heatPlanNoOldQ = list.get(8);//
			String proOrderNo = list.get(9);
			String actLen = list.get(10);
			String mateialNo = list.get(11);
			String pointGx = list.get(12);// 返线工序点
			String bc = list.get(13);//
			String bz = list.get(14);//
			String heatPlanNoNext = list.get(15);//

			// 循环库存信息
			MatBcTrackEntity matTrack = getQureyReturnMatTrack(conn,
					judgeStoveNo, batchNo, batchGroupBy, takeCount,
					OnProOrderId, heatPlanNoOldQ, MatBcTrackEntity.class,
					lenFalg, actLen);
			if (matTrack == null) {
				cro.setV_errMsg("管坯物料已发生改变,请刷新!");
				return cro;
			}
			if(!matTrack.getStorageNo().equals(matTrack.getOutRepository()))
			{
				cro.setV_errMsg("物料不在当前产线产出库,不允许精整返线!");
				return  cro;
			}
			double weight = Double.parseDouble(matTrack.getActWeight());
			int outnumCut = 0;
			String ifProduct = "0";
			String pic = "";
			String sic = "";
			String dic = "";
			String cic = matTrack.getCic();
			// String proPlanId = matTrack.getProOrderId();
			// String gxPlanNo = matTrack.getGxPlanNo();
			String outwlId = matTrack.getMaterialNo();
			String heatPlanNo = "";
			String wholeDesc = "";
			String orderSource = "";
			String ordLnDlyPk = "";
			String plnDivideId = "";
			if (processCdoe.equals("F")) {
				// 查询原炉炉计划
				PlnZyRclMEntity listM = FrmPlanStoveE.getQureyZyM(conn,
						heatPlanNoOld, "F", PlnZyRclMEntity.class);
				if (listM == null) {
					cro.setV_errMsg("原炉计划已发生变化,请重新查询!");
					return cro;
				}
				// 查询热处理信息
				PlnOrderRclSEntity plnOrderS = getPlanOrderS(conn, proPlanId,
						gxPlanNo, PlnOrderRclSEntity.class, "F");
				if (plnOrderS == null) {
					cro.setV_errMsg("未找到热处理订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				wholeDesc = plnOrderS.getWholeBacklogDesc();
				orderSource = plnOrderS.getOrderSource();
				ordLnDlyPk = plnOrderS.getOrdLnDlyPk();
				plnDivideId = plnOrderS.getPlnDivideId();
				int counnum = StoveHelper.getQueryStation(conn, proPlanId,
						gxPlanNo, "F");
				if (counnum > 0) {
					ifProduct = "1";
				}
				pic = plnOrderS.getPic().split(",")[0];
				sic = plnOrderS.getSic().split(",")[0];
				dic = plnOrderS.getDic().split(",")[0];
				PlnZyRclMEntity plnRclM = new PlnZyRclMEntity();
				heatPlanNo = corePlanFurnProM
						.getMaxHeatPlanNo(conn, plnOrderS.getProPlanId(),
								plnOrderS.getProPlanId(), "F");
				// 获取炉计划顺序号
				int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(conn,
						plnOrderS.getPlineCode(), "F");

				// 订单内炉顺序号
				int lotNosx = corePlanFurnProM.getMaxLotNoSqe(conn,
						plnOrderS.getProPlanId(), plnOrderS.getGxPlanNo(), "F");
				plnRclM.setLotNoSqe(String.valueOf(lotNosx));
				plnRclM.setDecision(plnOrderS.getDecision());
				plnRclM.setStoveNo(matTrack.getStoveNo());
				plnRclM.setFlagStoveNo(listM.getFlagStoveNo());
				plnRclM.setFeedHeatNo(listM.getFeedHeatNo());
				plnRclM.setJudgeStoveNo(listM.getJudgeStoveNo());
				plnRclM.setUpperHeatplanId(listM.getUpperHeatplanId());
				plnRclM.setPlanstatus("20");
				plnRclM.setUpperProcessCode(listM.getUpperProcessCode());
				plnRclM.setPlineCode(plnOrderS.getPlineCode());
				plnRclM.setPlineName(plnOrderS.getPlineName());
				plnRclM.setProcessCodeC(plnOrderS.getProcessCodeC());
				plnRclM.setProcessDescC(plnOrderS.getProcessDescC());
				String inwlId = "";
				String inwlDesc = "";
				String materialNocp = "";
				String materialdesccp = "";
				// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
				String sqlBom = CoreXmlSqlParsersFactory
						.getSql("FrmPlanMaterialDbk.queryBaseMaterialFPl");
				sqlBom += " AND T.F_OUT_MATERIAL_NO=?  AND T.SPEC_CODE_R=?";
				ps = conn.prepareStatement(sqlBom);
				ps.setObject(1, plnOrderS.getOrdLnDlyPk());
				ps.setObject(2, plnOrderS.getIndexSeq());
				ps.setObject(3, plnOrderS.getCraftSeq());
				ps.setObject(4, outwlId);
				ps.setObject(5, plnOrderS.getSpecCode());
				rs = ps.executeQuery();
				if (rs.next()) {
					inwlId = rs.getString("IN_MATERIAL_NO");
					inwlDesc = rs.getString("IN_MATERIAL_DESC");
					materialNocp = rs.getString("MATERIAL_NO");
					materialdesccp = rs.getString("MATERIAL_DESC");
					// plnRclM.setSpecCode(rs.getString("SPEC_CODE_C"));
					// plnRclM.setSpecName(rs.getString("SPEC_NAME_C"));
					plnRclM.setBom(rs.getString("BOM"));
					plnRclM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));
				} else {
					inwlId = plnOrderS.getInwlId();
					inwlDesc = plnOrderS.getInwlDesc();

					plnRclM.setBom(plnOrderS.getBom());
					// cro.setV_errMsg("未找到判定炉号(" + judgeStoveNo
					// + ")在热处理的产出物料!");
					// return cro;
				}
				rs.close();
				ps.close();

				String nextProcessCdeo = "";
				String nextProcessName = "";
				if (!plnOrderS.getDecision().equals("A")) {
					// 通过制程判定是否末工序
					if (plnOrderS.getWholeBacklogDesc().contains("加工")) {
						plnRclM.setNextProcessCode("G");
						nextProcessCdeo = "G";
						nextProcessName = "加工";
					} else if (plnOrderS.getWholeBacklogDesc().contains("接箍")) {
						plnRclM.setNextProcessCode("H");
						nextProcessCdeo = "H";
						nextProcessName = "接箍加工";
					} else {
						if (plnOrderS.getOrdLnDlyPk().contains("ZZBY-J")) {
							plnRclM.setNextProcessCode("H");
							nextProcessCdeo = "H";
							nextProcessName = "接箍加工";
						} else if (plnOrderS.getOrdLnDlyPk().contains("ZZBY-D")) {
							plnRclM.setNextProcessCode("G");
							nextProcessCdeo = "G";
							nextProcessName = "加工";
						} else {
							plnRclM.setNextProcessCode("");
						}
					}
					plnRclM.setIsendgx("0");
					plnRclM.setOutwlId(outwlId);
					plnRclM.setOutwlDesc(matTrack.getMaterialName());
				} else {
					plnRclM.setNextProcessCode("");
					plnRclM.setIsendgx("1");
					plnRclM.setOutwlId(materialNocp);
					plnRclM.setOutwlDesc(materialdesccp);
				}
				plnRclM.setInwlId(inwlId);
				plnRclM.setInwlDesc(inwlDesc);
				String gowWhere = corePlanFurnProM.getPlineCodeGroup(conn,
						plnOrderS.getPlineCode(), plnOrderS.getProPlanId(),
						plnOrderS.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 = conn.prepareStatement(sqlGroup);
					ps.setObject(1, plnOrderS.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("4");
				plnRclM.setIfDoHeatPlan("1");
				plnRclM.setProPlanId(plnOrderS.getProPlanId());
				plnRclM.setGxPlanNo(plnOrderS.getGxPlanNo());
				plnRclM.setGradecode(matTrack.getGradecode());
				plnRclM.setGradename(matTrack.getGradename());
				plnRclM.setSteelcode(plnOrderS.getSteelcode());
				plnRclM.setSteelname(plnOrderS.getSteelname());
				plnRclM.setProduccode(plnOrderS.getProduccode());
				plnRclM.setProducname(plnOrderS.getProducname());
				plnRclM.setSpecCode(plnOrderS.getSpecCode());
				plnRclM.setSpecName(plnOrderS.getSpecName());
				plnRclM.setModelCode(plnOrderS.getModelCode());
				plnRclM.setModelDesc(plnOrderS.getModelDesc());
				// 单倍支吨
				plnRclM.setPlnInsingleNum(String.valueOf(takeCount));
				plnRclM.setPlnInsingleWt(String.valueOf(weight));
				plnRclM.setPlnOutsingleNum(String.valueOf(takeCount));
				double burnoutRate = 0;
				// 查询产线烧损
				String sql = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
						+ plnOrderS.getPlineCode() + "'";
				ps = conn.prepareStatement(sql);
				rs = ps.executeQuery();
				if (rs.next()) {
					burnoutRate = rs.getDouble("BURNOUT_RATE");
				}
				rs.close();
				ps.close();
				double yjWt = weight - weight * burnoutRate;
				plnRclM.setPlnOutsingleW(String.valueOf(yjWt));
				// 查询轧管排产信息
				String sqlZg = CoreXmlSqlParsersFactory
						.getSql("PlanFurnProduction.QueryWgZg");
				ps = conn.prepareStatement(sqlZg);
				ps.setObject(1, plnOrderS.getOrdLnDlyPk());
				// ps.setObject(2, plnOrderS.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.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
				}
				rs.close();
				ps.close();
				plnRclM.setZyBatchId(plnOrderS.getZyBatchId());
				plnRclM.setStdCode(plnOrderS.getStdCode());
				plnRclM.setStdName(plnOrderS.getStdName());
				plnRclM.setStdStyle(plnOrderS.getStdStyle());
				plnRclM.setStdStyleDesc(plnOrderS.getStdStyleDesc());
				plnRclM.setOutdiameterIn(listM.getOutdiameterIn());
				plnRclM.setWallthickIn(listM.getWallthickIn());
				plnRclM.setLengthIn(listM.getLengthIn());
				plnRclM.setLengthmaxIn(listM.getLengthmaxIn());
				plnRclM.setLengthminIn(listM.getLengthminIn());
				plnRclM.setOrderSource(plnOrderS.getOrderSource());
				plnRclM.setOrderNo(plnOrderS.getOrderNo());
				plnRclM.setOrderSeq(plnOrderS.getOrderSeq());
				plnRclM.setDeliveryNo(plnOrderS.getDeliveryNo());
				plnRclM.setOrdLnDlyPk(plnOrderS.getOrdLnDlyPk());
				plnRclM.setReqBlId(plnOrderS.getReqBlId());
				plnRclM.setIfExport(plnOrderS.getIfExport());
				plnRclM.setPriority(plnOrderS.getPriority());
				plnRclM.setPriorityMemo(plnOrderS.getPriorityMemo());
				plnRclM.setProMonth(plnOrderS.getProMonth());
				plnRclM.setIfMonitor(plnOrderS.getIfMonitorRcl());
				plnRclM.setPrdcrNo(plnOrderS.getPrdcrNo());
				plnRclM.setMonitorPoint(plnOrderS.getMonitorPoint());
				plnRclM.setWholeBacklogDesc(plnOrderS.getWholeBacklogDesc());
				plnRclM.setStationRoad(plnOrderS.getStationRoad());
				plnRclM.setCic(cic);
				plnRclM.setSic(sic);
				plnRclM.setDic(dic);
				plnRclM.setPic(pic);
				plnRclM.setCraftFileMan(plnOrderS.getCraftFileMan());
				plnRclM.setCraftFileNo(plnOrderS.getCraftFileNo());
				plnRclM.setCraftSeq(plnOrderS.getCraftSeq());
				plnRclM.setOutdiameter(plnOrderS.getOutdiameter());
				plnRclM.setWallthick(plnOrderS.getWallthick());

				if (pointGx.equals("600202") || pointGx.equals("600203")
						|| pointGx.equals("600204")) {
					plnRclM.setPerStatus("00");
					plnRclM.setBesideStatus("00");
				} else if (pointGx.equals("600205") || pointGx.equals("600206")
						|| pointGx.equals("600207")) {
					plnRclM.setPerStatus("30");
					plnRclM.setBesideStatus("30");
				} else if (pointGx.equals("600208")) {
					plnRclM.setPerStatus("60");
					plnRclM.setBesideStatus("60");
				} else if (pointGx.equals("600209")) {
					plnRclM.setPerStatus("70");
					plnRclM.setBesideStatus("70");
				} else if (pointGx.equals("600211")) {
					plnRclM.setPerStatus("80");
					plnRclM.setBesideStatus("80");
				}

				// 查询合同最大最小长度
				double lenMax = 0;
				double lenMin = 0;
				String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
				ps = conn.prepareStatement(ordLen);
				ps.setObject(1, plnOrderS.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(userName);
				plnRclM.setCreateTime(dateTime);
				plnRclM.setDownman(userName);
				plnRclM.setDowntime(dateTime);
				plnRclM.setProDay(dateTime.substring(0, 10).replace("-", ""));
				plnRclM.setBalYearMonth(dateTime.substring(0, 7).replace("-",
						""));
				plnRclM.setIndexSeq(plnOrderS.getIndexSeq());
				plnRclM.setHeatPlanNo(heatPlanNo);
				plnRclM.setGxProSeq(String.valueOf(gxProSeq));
				// 获取热处理循环次数
				String sqlSeq = CoreXmlSqlParsersFactory
						.getSql("FrmPlanMaterialRcl.QueryProcessSeq1");
				ps = conn.prepareStatement(sqlSeq);
				ps.setObject(1, plnOrderS.getProPlanId());
				ps.setObject(2, plnOrderS.getGxPlanNo());
				ps.setObject(3, heatPlanNoOld);
				rs = ps.executeQuery();
				if (rs.next()) {
					plnRclM.setProcessSeq(rs.getString("PROCESS_SEQ"));
					plnRclM.setRealProcessSeq(rs.getString("REAL_PROCESS_SEQ"));
				} else {
					plnRclM.setProcessSeq("1");
					plnRclM.setRealProcessSeq("1");
				}
				rs.close();
				ps.close();
				plnRclM.setIfProduct(ifProduct);
				// 新增热处理虚拟炉计划
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyRcl"),
						plnRclM);
				ps = conn.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();
				// 新增生产批号
				StoveHelper.updatePlnRclGroup(conn, plnRclM.getProPlanId(),
						plnRclM.getGxPlanNo(), plnRclM.getPic());
				String jugdeApplyCode = "";
				String batchNoOld = "";
				String batchGroupNoOld = "";
				String sqlApp = "SELECT MAX(T.JUGDE_APPLY_CODE) JUGDE_APPLY_CODE,T.BATCH_NO,T.BATCH_GROUD_NO  FROM PLN_ZY_RCL_C T WHERE T.HEAT_PLAN_NO=? GROUP BY T.BATCH_NO,T.BATCH_GROUD_NO";
				ps = conn.prepareStatement(sqlApp);
				ps.setObject(1, heatPlanNoOld);
				rs = ps.executeQuery();
				if (rs.next()) {
					jugdeApplyCode = rs.getString("JUGDE_APPLY_CODE");
					batchNoOld = rs.getString("BATCH_NO");
					batchGroupNoOld = rs.getString("BATCH_GROUD_NO");
				}
				rs.close();
				ps.close();
				String heatPlanSqe = "";
				PlnZyRclCEntity plnC = new PlnZyRclCEntity();
				// 获取炉计划顺序号
				heatPlanSqe = corePlanFurnProM.getHeatPlanSeq(conn, heatPlanNo,
						"F");
				plnC.setHeatPlanNo(heatPlanNo);
				plnC.setJugdeApplyCode(jugdeApplyCode);
				plnC.setJudgeStoveNo(listM.getJudgeStoveNo());
				plnC.setFeedHeatNo(listM.getFeedHeatNo());
				plnC.setFlagStoveNo(listM.getFlagStoveNo());
				plnC.setBatchNo(batchNoOld);
				plnC.setBatchGroudNo(batchGroupNoOld);
				plnC.setStoveNo(listM.getStoveNo());
				plnC.setProPlanId(plnOrderS.getProPlanId());
				plnC.setGxPlanNo(plnOrderS.getGxPlanNo());
				plnC.setPlineCode(plnOrderS.getPlineCode());
				plnC.setPlineName(plnOrderS.getPlineName());
				plnC.setOutdiameterIn(listM.getOutdiameterIn());
				plnC.setWallthickIn(listM.getWallthickIn());
				plnC.setLengthIn(listM.getLengthIn());
				plnC.setLengthmaxIn(listM.getLengthmaxIn());
				plnC.setLengthminIn(listM.getLengthminIn());
				plnC.setPlanIndoubleNum(String.valueOf(takeCount));
				plnC.setPlanIndoubleWt(String.valueOf(weight));

				plnC.setHeatPlanSqe(heatPlanSqe);
				// 新增
				String addPlnGxC = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("PlanFurnProduction.addPlnZyRclC"),
						plnC);
				ps = conn.prepareStatement(addPlnGxC);
				ps.executeUpdate();
				ps.close();

				List<MatBcMEntityPln> matGpMlist = getQureyMatGpM(conn,
						judgeStoveNo, batchNo, batchGroupBy, takeCount,
						heatPlanNoNext, processCdoe, "", proOrderNo, actLen,
						lenFalg,mateialNo);
				if (matGpMlist == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				for (MatBcMEntityPln matGpM : matGpMlist) {
					if (!matGpM.getProOrderNo().equals("")) {
						cro.setV_errMsg("选中炉号已挂生产合同,不能返线!");
						return cro;
					}
					if (!matGpM.getJugdeApplyCode().equals("")) {
						cro.setV_errMsg("该炉已送判,不能返线");
						return cro;
					}
					String batchNoPhy = batchNo;
					if (Integer.parseInt(pointGx) <= 600204) {
						batchNoPhy = "";
					}
					// // 生成热处理管号队列表
					// String addSamp = CoreXmlSqlParsersFactory
					// .getSql("FrmEndLibrary.addHttSamp");
					// ps = conn.prepareStatement(addSamp);
					// ps.setObject(1, heatPlanNo);
					// ps.setObject(2, plnOrderS.getZyBatchId());
					// ps.setObject(3, plnOrderS.getPlineCode());
					// ps.setObject(4, plnOrderS.getPlineName());
					// ps.setObject(5, pointGx);
					// ps.setObject(6, batchNoPhy);// 性能批号
					// ps.setObject(7, userName);
					// ps.setObject(8, bc);
					// ps.setObject(9, bz);
					// ps.setObject(10, dateTime);
					// ps.setObject(11, heatPlanSqe);
					// ps.setObject(12, heatPlanNoOld);
					// ps.setObject(13, matGpM.getMatNo());
					// ps.executeUpdate();
					// ps.close();
					String update = "UPDATE PORT_HTT_BATCH_SAMPLE_RESULT T SET T.HEAT_PLAN_NO=?,"
							+ "T.PHY_BATCH_NO=?,T.LOT_NO=?,T.PLINE_CODE=?,T.PLINE_NAME=?,T.HEAT_PLAN_SQE=?,"
							+ "T.INSTORE_FLAG='0',T.RETURN_PROCESS=? WHERE T.HEAT_PLAN_NO=? AND T.MAT_NO=?";
					ps = conn.prepareStatement(update);
					ps.setObject(1, heatPlanNo);
					ps.setObject(2, batchNoPhy);// 性能批号
					ps.setObject(3, plnOrderS.getZyBatchId());
					ps.setObject(4, plnOrderS.getPlineCode());
					ps.setObject(5, plnOrderS.getPlineName());
					ps.setObject(6, heatPlanSqe);
					ps.setObject(7, pointGx);
					ps.setObject(8, heatPlanNoOld);
					ps.setObject(9, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();
					// // 生成材料备份表
					// String allBackMat =
					// "INSERT INTO MAT_BC_BACKUP SELECT * FROM MAT_BC_M WHERE MAT_NO=?";
					// ps = conn.prepareStatement(allBackMat);
					// ps.setObject(1, matGpM.getMatNo());
					// ps.executeUpdate();
					// ps.close();

					// 删除入库记录(产出入库)
					String deleteIn = "DELETE YDM_BC_INLIST  WHERE MAT_NO = ?  AND PLINE_CODE = ?  AND INSTOCK_TYPE_CODE = '"
							+ 800701 + "'";
					ps = conn.prepareStatement(deleteIn);
					ps.setObject(1, matGpM.getMatNo());
					ps.setObject(2, matGpM.getPlineCode());
					ps.executeUpdate();
					ps.close();

					// // 删除入库记录(产权入库)
					// deleteIn =
					// "DELETE YDM_BC_INLIST  WHERE MAT_NO = ?  AND PLINE_CODE = ?  AND INSTOCK_TYPE_CODE = '"
					// + 800709 + "'";
					// ps = conn.prepareStatement(deleteIn);
					// ps.setObject(1, matGpM.getMatNo());
					// ps.setObject(2, matGpM.getPlineCode());
					// ps.executeUpdate();
					// ps.close();

					// 删除材料表
					String deleteMat = "DELETE MAT_BC_M WHERE MAT_NO=?";
					ps = conn.prepareStatement(deleteMat);
					ps.setObject(1, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();
					// 删除位置表
					String deleteMatB = "DELETE YDM_BC_BUTTRESS WHERE MAT_NO=?";
					ps = conn.prepareStatement(deleteMatB);
					ps.setObject(1, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();

				}

				if (nextProcessCdeo.equals("G")) {
					if (wholeDesc.contains("加工") && orderSource.equals("备料需求")) {
						// 查询备料需求与成品对应关系
						String sqlBL = "SELECT T.ORD_LN_DLY_PK FROM PLN_PORDER_BL_REQ T WHERE T.REQ_BL_ID=?";
						ps = conn.prepareStatement(sqlBL);
						ps.setObject(1, ordLnDlyPk);
						rs = ps.executeQuery();
						if (rs.next()) {
							ordLnDlyPk = rs.getString("ORD_LN_DLY_PK");
							plnDivideId = "01";
						}
						rs.close();
						ps.close();
					}
					List<PlnOrderJgxSEntity> plnOrder = PlanFurnProduction
							.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "G",
									PlnOrderJgxSEntity.class);
					if (plnOrder.size() > 0) {
						// 生成镦拔扩虚拟炉计划
						if (addPlnZyJgxM(conn, matTrack, takeCount, weight,
								plnOrder, userName, dateTime, nextProcessCdeo,
								processCdoe, cic, heatPlanNo)) {
							// continue;
						}
					}
				} else if (nextProcessCdeo.equals("H")) {
					List<PlnGxJgPropSEntity> plnOrder = PlanFurnProduction
							.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "H",
									PlnGxJgPropSEntity.class);
					if (plnOrder.size() > 0) {
						// 生成镦虚拟炉计划
						if (addPlnZyJgM(conn, matTrack, takeCount, weight,
								plnOrder, userName, dateTime, nextProcessCdeo,
								processCdoe, heatPlanNo)) {
							// continue;
						}
					}
				}
			} else if (processCdoe.equals("G")) {//加工

				// 查询原炉炉计划
				PlnZyJgxMEntity listM = FrmPlanStoveE.getQureyZyM(conn,
						heatPlanNoOld, "G", PlnZyJgxMEntity.class);
				if (listM == null) {
					cro.setV_errMsg("原炉计划已发生变化,请重新查询!");
					return cro;
				}
				// 查询加工信息
				PlnOrderJgxSEntity plnOrderS = getPlanOrderS(conn, proPlanId,
						gxPlanNo, PlnOrderJgxSEntity.class, "G");
				if (plnOrderS == null) {
					cro.setV_errMsg("未找到加工订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				wholeDesc = plnOrderS.getWholeBacklogDesc();
				orderSource = plnOrderS.getOrderSource();
				ordLnDlyPk = plnOrderS.getOrdLnDlyPk();
				plnDivideId = plnOrderS.getPlnDivideId();
				int counnum = StoveHelper.getQueryStation(conn, proPlanId,
						gxPlanNo, "F");
				if (counnum > 0) {
					ifProduct = "1";
				}
				pic = plnOrderS.getPic().split(",")[0];
				sic = plnOrderS.getSic().split(",")[0];
				dic = plnOrderS.getDic().split(",")[0];

				PlnZyJgxMEntity plnJgxM = new PlnZyJgxMEntity();
				heatPlanNo = corePlanFurnProM
						.getMaxHeatPlanNo(conn, plnOrderS.getProPlanId(),
								plnOrderS.getProPlanId(), "G");
				// 获取炉计划顺序号
				// int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(conn,
				// plnOrderS.getPlineCode(), "G");
				plnJgxM.setHeatPlanNoOld(heatPlanNoOld);
				plnJgxM.setDecision(plnOrderS.getDecision());
				plnJgxM.setStoveNo(listM.getStoveNo());
				plnJgxM.setZyBatchId(plnOrderS.getZyBatchId());
				plnJgxM.setFlagStoveNo(listM.getFlagStoveNo());
				plnJgxM.setFeedHeatNo(judgeStoveNo);
				plnJgxM.setJudgeStoveNo(judgeStoveNo);
				String sqlupper = "SELECT T.UPPER_HEATPLAN_ID,T.UPPER_PROCESS_CODE FROM PLN_ZY_JGX_M T WHERE T.HEAT_PLAN_NO='"
						+ heatPlanNoOld + "'";
				ps = conn.prepareStatement(sqlupper);
				rs = ps.executeQuery();
				if (rs.next()) {
					plnJgxM.setUpperHeatplanId(rs
							.getString("UPPER_HEATPLAN_ID"));
					plnJgxM.setUpperProcessCode(rs
							.getString("UPPER_PROCESS_CODE"));
				}
				rs.close();
				ps.close();
				plnJgxM.setPlanstatus("20");

				plnJgxM.setPlineCode(plnOrderS.getPlineCode());
				plnJgxM.setPlineName(plnOrderS.getPlineName());
				plnJgxM.setProcessCodeC(plnOrderS.getProcessCodeC());
				plnJgxM.setProcessDescC(plnOrderS.getProcessDescC());
				// 通过制程判定是否末工序
				// if (plnOrderS.getWholeBacklogDesc().contains("接箍")) {
				// plnJgxM.setNextProcessCode("H");
				// plnJgxM.setIsendgx("0");
				// } else {
				String nextProcessCdeo = "";
				String nextProcessName = "";
				if (plnOrderS.getOrdLnDlyPk().contains("ZZBY-J")) {
					plnJgxM.setNextProcessCode("H");
					nextProcessCdeo = "H";
					nextProcessName = "接箍加工";
				} else if (plnOrderS.getOrdLnDlyPk().contains("ZZBY-D")) {
					plnJgxM.setNextProcessCode("G");
					nextProcessCdeo = "G";
					nextProcessName = "加工";
				} else {
					plnJgxM.setNextProcessCode("");
				}
				if (plnOrderS.getOrderSource().equals("备料需求")) {
					plnJgxM.setIsendgx("0");
				} else {
					plnJgxM.setIsendgx("1");
				}
				// // 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
				// String sqlBom = CoreXmlSqlParsersFactory
				// .getSql("FrmPlanMaterialDbk.queryBaseMaterialGPl");
				// sqlBom +=
				// " AND T.I_OUT_MATERIAL_NO=?  AND (CASE WHEN T.SPEC_CODE_C IS NULL THEN";
				// ps = conn.prepareStatement(sqlBom);
				// ps.setObject(1, plnOrderS.getOrdLnDlyPk());
				// ps.setObject(2, plnOrderS.getIndexSeq());
				// ps.setObject(3, plnOrderS.getCraftSeq());
				// ps.setObject(4, outwlId);
				// ps.setObject(5, plnOrderS.getSpecCode());
				// rs = ps.executeQuery();
				// if (rs.next()) {
				// plnJgxM.setInwlId(rs.getString("I_IN_MATERIAL_NO"));
				// plnJgxM.setInwlDesc(rs.getString("IN_MATERIAL_DESC"));
				// plnJgxM.setBom(rs.getString("BOM"));
				// plnJgxM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));
				// } else {
				plnJgxM.setInwlId(plnOrderS.getInwlId());
				plnJgxM.setInwlDesc(plnOrderS.getInwlDesc());
				plnJgxM.setBom(plnOrderS.getBom());
				// cro.setV_errMsg("未找到判定炉号(" + judgeStoveNo
				// + ")在加工的产出物料!");
				// return cro;
				// }
				rs.close();
				ps.close();
				plnJgxM.setOutwlId(plnOrderS.getOutwlId());
				plnJgxM.setOutwlDesc(plnOrderS.getOutwlDesc());

				String gowWhere = corePlanFurnProM.getPlineCodeGroup(conn,
						plnOrderS.getPlineCode(), plnOrderS.getProPlanId(),
						plnOrderS.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 = conn.prepareStatement(sqlGroup);
					ps.setObject(1, plnOrderS.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("4");
				plnJgxM.setIfDoHeatPlan("1");
				plnJgxM.setProPlanId(plnOrderS.getProPlanId());
				plnJgxM.setGxPlanNo(plnOrderS.getGxPlanNo());
				plnJgxM.setSpecCode(plnOrderS.getSpecCode());
				plnJgxM.setSpecName(plnOrderS.getSpecName());
				plnJgxM.setGradecode(matTrack.getGradecode());
				plnJgxM.setGradename(matTrack.getGradename());
				plnJgxM.setSteelcode(plnOrderS.getSteelcode());
				plnJgxM.setSteelname(plnOrderS.getSteelname());
				plnJgxM.setProduccode(plnOrderS.getProduccode());
				plnJgxM.setProducname(plnOrderS.getProducname());

				plnJgxM.setModelCode(plnOrderS.getModelCode());
				plnJgxM.setModelDesc(plnOrderS.getModelDesc());
				// 单倍支吨
				plnJgxM.setPlnInsingleNum(String.valueOf(takeCount));
				plnJgxM.setPlnInsingleWt(String.valueOf(weight));

				// 查询轧管排产信息
				String sqlZg = CoreXmlSqlParsersFactory
						.getSql("PlanFurnProduction.QueryWgZg");
				ps = conn.prepareStatement(sqlZg);
				ps.setObject(1, plnOrderS.getOrdLnDlyPk());
				// ps.setObject(2, plnOrderS.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.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
				}
				rs.close();
				ps.close();
				plnJgxM.setStdCode(plnOrderS.getStdCode());
				plnJgxM.setStdName(plnOrderS.getStdName());
				plnJgxM.setStdStyle(plnOrderS.getStdStyle());
				plnJgxM.setStdStyleDesc(plnOrderS.getStdStyleDesc());
				plnJgxM.setOutdiameterIn(plnOrderS.getOutdiameter());

				plnJgxM.setWallthickIn(listM.getWallthickIn());
				plnJgxM.setLengthIn(listM.getLengthIn());
				plnJgxM.setLengthmaxIn(listM.getLengthmaxIn());
				plnJgxM.setLengthminIn(listM.getLengthminIn());
				plnJgxM.setOrderSource(plnOrderS.getOrderSource());
				plnJgxM.setOrderNo(plnOrderS.getOrderNo());
				plnJgxM.setOrderSeq(plnOrderS.getOrderSeq());
				plnJgxM.setDeliveryNo(plnOrderS.getDeliveryNo());
				plnJgxM.setOrdLnDlyPk(plnOrderS.getOrdLnDlyPk());
				plnJgxM.setReqBlId(plnOrderS.getReqBlId());
				plnJgxM.setIfExport(plnOrderS.getIfExport());
				plnJgxM.setPriority(plnOrderS.getPriority());
				plnJgxM.setPriorityMemo(plnOrderS.getPriorityMemo());
				plnJgxM.setProMonth(plnOrderS.getProMonth());
				plnJgxM.setIfMonitor(plnOrderS.getIfMonitorJgx());
				plnJgxM.setPrdcrNo(plnOrderS.getPrdcrNo());
				plnJgxM.setMonitorPoint(plnOrderS.getMonitorPoint());
				plnJgxM.setWholeBacklogDesc(plnOrderS.getWholeBacklogDesc());
				plnJgxM.setStationRoad(plnOrderS.getStationRoad());

				plnJgxM.setCic(cic);
				plnJgxM.setSic(sic);
				plnJgxM.setDic(dic);
				plnJgxM.setPic(pic);
				plnJgxM.setCraftFileMan(plnOrderS.getCraftFileMan());
				plnJgxM.setCraftFileNo(plnOrderS.getCraftFileNo());
				plnJgxM.setCraftSeq(plnOrderS.getCraftSeq());
				plnJgxM.setOutdiameter(plnOrderS.getOutdiameter());
				plnJgxM.setWallthick(plnOrderS.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 = conn.prepareStatement(ordLen);
				ps.setObject(1, plnOrderS.getOrdLnDlyPk());
				rs = ps.executeQuery();
				if (rs.next()) {
					lenMax = rs.getDouble("LENGTHMAX");
					lenMin = rs.getDouble("LENGTHMIN");
				}
				rs.close();
				ps.close();

				if (!listM.getLengthmaxIn().equals("")) {
					outnumCut = (int) (Double.parseDouble(listM
							.getLengthmaxIn()) / 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(takeCount * outnumCut));
				double burnoutRate = 0;
				// 查询产线烧损
				String sql = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
						+ plnOrderS.getPlineCode() + "'";
				ps = conn.prepareStatement(sql);
				rs = ps.executeQuery();
				if (rs.next()) {
					burnoutRate = rs.getDouble("BURNOUT_RATE");
				}
				rs.close();
				ps.close();
				double yjWt = weight - weight * burnoutRate;
				plnJgxM.setPlnOutsingleW(String.valueOf(yjWt));
				plnJgxM.setCreateName(userName);
				plnJgxM.setCreateTime(dateTime);
				plnJgxM.setProDay(dateTime.substring(0, 10).replace("-", ""));
				plnJgxM.setBalYearMonth(dateTime.substring(0, 7).replace("-",
						""));
				plnJgxM.setIndexSeq(plnOrderS.getIndexSeq());
				plnJgxM.setHeatPlanNo(heatPlanNo);
				// plnJgxM.setGxProSeq(String.valueOf(gxProSeq));
				// 订单内炉顺序号
				int lotNoJg = corePlanFurnProM.getMaxLotNoSqe(conn,
						plnJgxM.getProPlanId(), plnJgxM.getGxPlanNo(), "G");
				plnJgxM.setLotNoSqe(String.valueOf(lotNoJg));
				String flag = "0";
				if (plnOrderS.getOrdLnDlyPk().contains("ZZBY-D")) {
					flag = "1";
				}
				if (!matTrack.getTarget().equals(plnOrderS.getDecision())
						&& flag.equals("1")) {
					flag = "1";
				} else {
					flag = "0";
				}
				plnJgxM.setZzbFlag(flag);

				// 新增加工线虚拟炉计划
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("FrmEndLibrary.addPlnZyJgxbGX"),
						plnJgxM);
				ps = conn.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();
				// 新增生产批号
				StoveHelper.updatePlnJgxGroup(conn, plnJgxM.getProPlanId(),
						plnJgxM.getGxPlanNo(), plnJgxM.getPic());

				PlnZyJgxCEntity plnC = new PlnZyJgxCEntity();
				// 获取炉计划顺序号
				String heatPlanSqe = corePlanFurnProM.getHeatPlanSeq(conn,
						heatPlanNo, "G");
				plnC.setHeatPlanNo(heatPlanNo);
				plnC.setJugdeApplyCode("");
				plnC.setJudgeStoveNo(judgeStoveNo);
				plnC.setFeedHeatNo(judgeStoveNo);
				plnC.setFlagStoveNo(listM.getFlagStoveNo());
				plnC.setBatchNo(batchNo);
				plnC.setBatchGroudNo(batchGroupBy);
				plnC.setStoveNo(listM.getStoveNo());
				plnC.setProPlanId(plnOrderS.getProPlanId());
				plnC.setGxPlanNo(plnOrderS.getGxPlanNo());
				plnC.setPlineCode(plnOrderS.getPlineCode());
				plnC.setPlineName(plnOrderS.getPlineName());
				plnC.setOutdiameterIn(listM.getOutdiameterIn());
				plnC.setWallthickIn(listM.getWallthickIn());
				plnC.setOutnumCut(String.valueOf(outnumCut));
				plnC.setLengthIn(listM.getLengthIn());
				plnC.setLengthmaxIn(listM.getLengthmaxIn());
				plnC.setLengthminIn(listM.getLengthminIn());
				plnC.setPlanIndoubleNum(String.valueOf(takeCount));
				plnC.setPlanIndoubleWt(String.valueOf(weight));

				plnC.setHeatPlanSqe(heatPlanSqe);
				// 新增
				String addPlnGxJgxC = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("FrmEndLibrary.addPlnZyJgxC"), plnC);
				ps = conn.prepareStatement(addPlnGxJgxC);
				ps.executeUpdate();
				ps.close();

				List<MatBcMEntityPln> matGpMlist = getQureyMatGpM(conn,
						judgeStoveNo, batchNo, batchGroupBy, takeCount,
						heatPlanNoNext, processCdoe, "", proOrderNo, actLen,
						lenFalg,mateialNo);
				if (matGpMlist == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				for (MatBcMEntityPln matGpM : matGpMlist) {
					if (!matGpM.getProOrderNo().equals("")) {
						cro.setV_errMsg("选中炉号已挂生产合同,不能返线!");
						return cro;
					}
					if (!matGpM.getJugdeApplyCode().equals("")) {
						cro.setV_errMsg("该炉已送判,不能返线");
						return cro;
					}
					String batchNoPhy = batchNo;
					// // 生成热处理管号队列表
					// String addSamp = CoreXmlSqlParsersFactory
					// .getSql("FrmEndLibrary.addHttSamp");
					// ps = conn.prepareStatement(addSamp);
					// ps.setObject(1, heatPlanNo);
					// ps.setObject(2, plnOrderS.getZyBatchId());
					// ps.setObject(3, plnOrderS.getPlineCode());
					// ps.setObject(4, plnOrderS.getPlineName());
					// ps.setObject(5, pointGx);
					// ps.setObject(6, batchNoPhy);// 性能批号
					// ps.setObject(7, userName);
					// ps.setObject(8, bc);
					// ps.setObject(9, bz);
					// ps.setObject(10, dateTime);
					// ps.setObject(11, heatPlanSqe);
					// ps.setObject(12, heatPlanNoOld);
					// ps.setObject(13, matGpM.getMatNo());
					// ps.executeUpdate();
					// ps.close();
					String update = "UPDATE PORT_MCH_BATCH_SAMPLE_RESULT T SET T.HEAT_PLAN_NO=?,"
							+ "T.PHY_BATCH_NO=?,T.LOT_NO=?,T.PLINE_CODE=?,T.PLINE_NAME=?,T.HEAT_PLAN_SQE=?,"
							+ "T.INSTORE_FLAG='0',T.RETURN_PROCESS=? WHERE T.HEAT_PLAN_NO=? AND T.MAT_NO=?";
					ps = conn.prepareStatement(update);
					ps.setObject(1, heatPlanNo);
					ps.setObject(2, batchNoPhy);// 性能批号
					ps.setObject(3, plnOrderS.getZyBatchId());
					ps.setObject(4, plnOrderS.getPlineCode());
					ps.setObject(5, plnOrderS.getPlineName());
					ps.setObject(6, heatPlanSqe);
					ps.setObject(7, pointGx);
					ps.setObject(8, heatPlanNoOld);
					ps.setObject(9, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();
					// // 生成材料备份表
					// String allBackMat =
					// "INSERT INTO MAT_BC_BACKUP SELECT * FROM MAT_BC_M WHERE MAT_NO=?";
					// ps = conn.prepareStatement(allBackMat);
					// ps.setObject(1, matGpM.getMatNo());
					// ps.executeUpdate();
					// ps.close();

					// 删除入库记录(产出入库)
					String deleteIn = "DELETE YDM_BC_INLIST  WHERE MAT_NO = ?  AND PLINE_CODE = ?  AND INSTOCK_TYPE_CODE = '"
							+ 800701 + "'";
					ps = conn.prepareStatement(deleteIn);
					ps.setObject(1, matGpM.getMatNo());
					ps.setObject(2, matGpM.getPlineCode());
					ps.executeUpdate();
					ps.close();

					// // 删除入库记录(产权入库)
					// deleteIn =
					// "DELETE YDM_BC_INLIST  WHERE MAT_NO = ?  AND PLINE_CODE = ?  AND INSTOCK_TYPE_CODE = '"
					// + 800709 + "'";
					// ps = conn.prepareStatement(deleteIn);
					// ps.setObject(1, matGpM.getMatNo());
					// ps.setObject(2, matGpM.getPlineCode());
					// ps.executeUpdate();
					// ps.close();

					// 删除材料表
					String deleteMat = "DELETE MAT_BC_M WHERE MAT_NO=?";
					ps = conn.prepareStatement(deleteMat);
					ps.setObject(1, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();
					// 删除位置表
					String deleteMatB = "DELETE YDM_BC_BUTTRESS WHERE MAT_NO=?";
					ps = conn.prepareStatement(deleteMatB);
					ps.setObject(1, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();

				}

				if (nextProcessCdeo.equals("G")) {
					if (wholeDesc.contains("加工") && orderSource.equals("备料需求")) {
						// 查询备料需求与成品对应关系
						String sqlBL = "SELECT T.ORD_LN_DLY_PK FROM PLN_PORDER_BL_REQ T WHERE T.REQ_BL_ID=?";
						ps = conn.prepareStatement(sqlBL);
						ps.setObject(1, ordLnDlyPk);
						rs = ps.executeQuery();
						if (rs.next()) {
							ordLnDlyPk = rs.getString("ORD_LN_DLY_PK");
							plnDivideId = "01";
						}
						rs.close();
						ps.close();
					}
					List<PlnOrderJgxSEntity> plnOrder = PlanFurnProduction
							.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "G",
									PlnOrderJgxSEntity.class);
					if (plnOrder.size() > 0) {
						// 生成镦拔扩虚拟炉计划
						if (addPlnZyJgxM(conn, matTrack, takeCount, weight,
								plnOrder, userName, dateTime, nextProcessCdeo,
								processCdoe, cic, heatPlanNo)) {
							// continue;
						}
					}
				} else if (nextProcessCdeo.equals("H")) {
					List<PlnGxJgPropSEntity> plnOrder = PlanFurnProduction
							.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "H",
									PlnGxJgPropSEntity.class);
					if (plnOrder.size() > 0) {
						// 生成镦虚拟炉计划
						if (addPlnZyJgM(conn, matTrack, takeCount, weight,
								plnOrder, userName, dateTime, nextProcessCdeo,
								processCdoe, heatPlanNo)) {
							// continue;
						}
					}
				}

			} else if (processCdoe.equals("E")) {//镦拔扩

				// 查询原炉炉计划
				PlnZyDbkMEntity listM = FrmPlanStoveE.getQureyZyM(conn,
						heatPlanNoOld, "E", PlnZyDbkMEntity.class);
				if (listM == null) {
					cro.setV_errMsg("原炉计划已发生变化,请重新查询!");
					return cro;
				}
				// 查询镦拔扩信息
				PlnOrderDbkSEntity plnOrderS = getPlanOrderS(conn, proPlanId,
						gxPlanNo, PlnOrderDbkSEntity.class, "E");
				if (plnOrderS == null) {
					cro.setV_errMsg("未找到镦拔扩订单(" + proPlanId + "/" + gxPlanNo
							+ ")信息!");
					return cro;
				}
				wholeDesc = plnOrderS.getWholeBacklogDesc();
				orderSource = plnOrderS.getOrderSource();
				ordLnDlyPk = plnOrderS.getOrdLnDlyPk();
				plnDivideId = plnOrderS.getPlnDivideId();
				int counnum = StoveHelper.getQueryStation(conn, proPlanId,
						gxPlanNo, "F");
				if (counnum > 0) {
					ifProduct = "1";
				}
				pic = plnOrderS.getPic().split(",")[0];
				sic = plnOrderS.getSic().split(",")[0];
				dic = plnOrderS.getDic().split(",")[0];

				PlnZyDbkMEntity plnJgxM = new PlnZyDbkMEntity();
				heatPlanNo = corePlanFurnProM
						.getMaxHeatPlanNo(conn, plnOrderS.getProPlanId(),
								plnOrderS.getProPlanId(), "E");
				// 获取炉计划顺序号
				// int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(conn,
				// plnOrderS.getPlineCode(), "G");
				plnJgxM.setHeatPlanNoOld(heatPlanNoOld);
				plnJgxM.setDecision(plnOrderS.getDecision());
				plnJgxM.setStoveNo(listM.getStoveNo());
				plnJgxM.setZyBatchId(plnOrderS.getZyBatchId());
				plnJgxM.setFlagStoveNo(listM.getFlagStoveNo());
				plnJgxM.setFeedHeatNo(judgeStoveNo);
				plnJgxM.setJudgeStoveNo(judgeStoveNo);
				String sqlupper = "SELECT T.UPPER_HEATPLAN_ID,T.UPPER_PROCESS_CODE FROM PLN_ZY_JGX_M T WHERE T.HEAT_PLAN_NO='"
						+ heatPlanNoOld + "'";
				ps = conn.prepareStatement(sqlupper);
				rs = ps.executeQuery();
				if (rs.next()) {
					plnJgxM.setUpperHeatplanId(rs
							.getString("UPPER_HEATPLAN_ID"));
					plnJgxM.setUpperProcessCode(rs
							.getString("UPPER_PROCESS_CODE"));
				}
				rs.close();
				ps.close();
				plnJgxM.setPlanstatus("20");

				plnJgxM.setPlineCode(plnOrderS.getPlineCode());
				plnJgxM.setPlineName(plnOrderS.getPlineName());
				plnJgxM.setProcessCodeC(plnOrderS.getProcessCodeC());
				plnJgxM.setProcessDescC(plnOrderS.getProcessDescC());
				// 通过制程判定是否末工序
				// if (plnOrderS.getWholeBacklogDesc().contains("接箍")) {
				// plnJgxM.setNextProcessCode("H");
				// plnJgxM.setIsendgx("0");
				// } else {
				String nextProcessCdeo = "";
				String nextProcessName = "";
				if (plnOrderS.getOrdLnDlyPk().contains("ZZBY-J")) {
					plnJgxM.setNextProcessCode("H");
					nextProcessCdeo = "H";
					nextProcessName = "接箍加工";
				} else if (plnOrderS.getOrdLnDlyPk().contains("ZZBY-D")) {
					plnJgxM.setNextProcessCode("G");
					nextProcessCdeo = "G";
					nextProcessName = "加工";
				} else {
					plnJgxM.setNextProcessCode("");
				}
				if (plnOrderS.getOrderSource().equals("备料需求")) {
					plnJgxM.setIsendgx("0");
				} else {
					plnJgxM.setIsendgx("1");
				}
				// // 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
				// String sqlBom = CoreXmlSqlParsersFactory
				// .getSql("FrmPlanMaterialDbk.queryBaseMaterialGPl");
				// sqlBom +=
				// " AND T.I_OUT_MATERIAL_NO=?  AND (CASE WHEN T.SPEC_CODE_C IS NULL THEN";
				// ps = conn.prepareStatement(sqlBom);
				// ps.setObject(1, plnOrderS.getOrdLnDlyPk());
				// ps.setObject(2, plnOrderS.getIndexSeq());
				// ps.setObject(3, plnOrderS.getCraftSeq());
				// ps.setObject(4, outwlId);
				// ps.setObject(5, plnOrderS.getSpecCode());
				// rs = ps.executeQuery();
				// if (rs.next()) {
				// plnJgxM.setInwlId(rs.getString("I_IN_MATERIAL_NO"));
				// plnJgxM.setInwlDesc(rs.getString("IN_MATERIAL_DESC"));
				// plnJgxM.setBom(rs.getString("BOM"));
				// plnJgxM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));
				// } else {
				plnJgxM.setInwlId(plnOrderS.getInwlId());
				plnJgxM.setInwlDesc(plnOrderS.getInwlDesc());
				plnJgxM.setBom(plnOrderS.getBom());
				// cro.setV_errMsg("未找到判定炉号(" + judgeStoveNo
				// + ")在加工的产出物料!");
				// return cro;
				// }
				rs.close();
				ps.close();
				plnJgxM.setOutwlId(plnOrderS.getOutwlId());
				plnJgxM.setOutwlDesc(plnOrderS.getOutwlDesc());

				String gowWhere = corePlanFurnProM.getPlineCodeGroup(conn,
						plnOrderS.getPlineCode(), plnOrderS.getProPlanId(),
						plnOrderS.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 = conn.prepareStatement(sqlGroup);
					ps.setObject(1, plnOrderS.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("4");
				plnJgxM.setIfDoHeatPlan("1");
				plnJgxM.setProPlanId(plnOrderS.getProPlanId());
				plnJgxM.setGxPlanNo(plnOrderS.getGxPlanNo());
				plnJgxM.setSpecCode(plnOrderS.getSpecCode());
				plnJgxM.setSpecName(plnOrderS.getSpecName());
				plnJgxM.setGradecode(matTrack.getGradecode());
				plnJgxM.setGradename(matTrack.getGradename());
				plnJgxM.setSteelcode(plnOrderS.getSteelcode());
				plnJgxM.setSteelname(plnOrderS.getSteelname());
				plnJgxM.setProduccode(plnOrderS.getProduccode());
				plnJgxM.setProducname(plnOrderS.getProducname());

				plnJgxM.setModelCode(plnOrderS.getModelCode());
				plnJgxM.setModelDesc(plnOrderS.getModelDesc());
				// 单倍支吨
				plnJgxM.setPlnInsingleNum(String.valueOf(takeCount));
				plnJgxM.setPlnInsingleWt(String.valueOf(weight));

				// 查询轧管排产信息
				String sqlZg = CoreXmlSqlParsersFactory
						.getSql("PlanFurnProduction.QueryWgZg");
				ps = conn.prepareStatement(sqlZg);
				ps.setObject(1, plnOrderS.getOrdLnDlyPk());
				// ps.setObject(2, plnOrderS.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.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
				}
				rs.close();
				ps.close();
				plnJgxM.setStdCode(plnOrderS.getStdCode());
				plnJgxM.setStdName(plnOrderS.getStdName());
				plnJgxM.setStdStyle(plnOrderS.getStdStyle());
				plnJgxM.setStdStyleDesc(plnOrderS.getStdStyleDesc());
				plnJgxM.setOutdiameterIn(plnOrderS.getOutdiameter());

				plnJgxM.setWallthickIn(listM.getWallthickIn());
				plnJgxM.setLengthIn(listM.getLengthIn());
				plnJgxM.setLengthmaxIn(listM.getLengthmaxIn());
				plnJgxM.setLengthminIn(listM.getLengthminIn());
				plnJgxM.setOrderSource(plnOrderS.getOrderSource());
				plnJgxM.setOrderNo(plnOrderS.getOrderNo());
				plnJgxM.setOrderSeq(plnOrderS.getOrderSeq());
				plnJgxM.setDeliveryNo(plnOrderS.getDeliveryNo());
				plnJgxM.setOrdLnDlyPk(plnOrderS.getOrdLnDlyPk());
				plnJgxM.setReqBlId(plnOrderS.getReqBlId());
				plnJgxM.setIfExport(plnOrderS.getIfExport());
				plnJgxM.setPriority(plnOrderS.getPriority());
				plnJgxM.setPriorityMemo(plnOrderS.getPriorityMemo());
				plnJgxM.setProMonth(plnOrderS.getProMonth());
				plnJgxM.setIfMonitor(plnOrderS.getIfMonitorDbk());
				plnJgxM.setPrdcrNo(plnOrderS.getPrdcrNo());
				plnJgxM.setMonitorPoint(plnOrderS.getMonitorPoint());
				plnJgxM.setWholeBacklogDesc(plnOrderS.getWholeBacklogDesc());
				plnJgxM.setStationRoad(plnOrderS.getStationRoad());

				plnJgxM.setCic(cic);
				plnJgxM.setSic(sic);
				plnJgxM.setDic(dic);
				plnJgxM.setPic(pic);
				plnJgxM.setCraftFileMan(plnOrderS.getCraftFileMan());
				plnJgxM.setCraftFileNo(plnOrderS.getCraftFileNo());
				plnJgxM.setCraftSeq(plnOrderS.getCraftSeq());
				plnJgxM.setOutdiameter(plnOrderS.getOutdiameter());
				plnJgxM.setWallthick(plnOrderS.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 = conn.prepareStatement(ordLen);
				ps.setObject(1, plnOrderS.getOrdLnDlyPk());
				rs = ps.executeQuery();
				if (rs.next()) {
					lenMax = rs.getDouble("LENGTHMAX");
					lenMin = rs.getDouble("LENGTHMIN");
				}
				rs.close();
				ps.close();

				if (!listM.getLengthmaxIn().equals("")) {
					outnumCut = (int) (Double.parseDouble(listM
							.getLengthmaxIn()) / 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(takeCount * outnumCut));
				double burnoutRate = 0;
				// 查询产线烧损
				String sql = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
						+ plnOrderS.getPlineCode() + "'";
				ps = conn.prepareStatement(sql);
				rs = ps.executeQuery();
				if (rs.next()) {
					burnoutRate = rs.getDouble("BURNOUT_RATE");
				}
				rs.close();
				ps.close();
				double yjWt = weight - weight * burnoutRate;
				plnJgxM.setPlnOutsingleW(String.valueOf(yjWt));
				plnJgxM.setCreateName(userName);
				plnJgxM.setCreateTime(dateTime);
				plnJgxM.setProDay(dateTime.substring(0, 10).replace("-", ""));
				plnJgxM.setBalYearMonth(dateTime.substring(0, 7).replace("-",
						""));
				plnJgxM.setIndexSeq(plnOrderS.getIndexSeq());
				plnJgxM.setHeatPlanNo(heatPlanNo);
				// plnJgxM.setGxProSeq(String.valueOf(gxProSeq));
				// 订单内炉顺序号
				int lotNoJg = corePlanFurnProM.getMaxLotNoSqe(conn,
						plnJgxM.getProPlanId(), plnJgxM.getGxPlanNo(), "E");
				plnJgxM.setLotNoSqe(String.valueOf(lotNoJg));
				String flag = "0";
				if (plnOrderS.getOrdLnDlyPk().contains("ZZBY-D")) {
					flag = "1";
				}
				if (!matTrack.getTarget().equals(plnOrderS.getDecision())
						&& flag.equals("1")) {
					flag = "1";
				} else {
					flag = "0";
				}
				plnJgxM.setZzbFlag(flag);

				// 新增镦拔扩虚拟炉计划
				String addPlnGxZg = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("FrmEndLibrary.addPlnZyDbkbGX"),
						plnJgxM);
				ps = conn.prepareStatement(addPlnGxZg);
				ps.executeUpdate();
				ps.close();
				// 新增生产批号
				//StoveHelper.updatePlnJgxGroup(conn, plnJgxM.getProPlanId(),
						//plnJgxM.getGxPlanNo(), plnJgxM.getPic());

				PlnZyDbkCEntity plnC = new PlnZyDbkCEntity();
				// 获取炉计划顺序号
				String heatPlanSqe = corePlanFurnProM.getHeatPlanSeq(conn,
						heatPlanNo, "E");
				plnC.setHeatPlanNo(heatPlanNo);
				plnC.setJugdeApplyCode("");
				plnC.setJudgeStoveNo(judgeStoveNo);
				plnC.setFeedHeatNo(judgeStoveNo);
				plnC.setFlagStoveNo(listM.getFlagStoveNo());
				plnC.setBatchNo(batchNo);
				plnC.setBatchGroudNo(batchGroupBy);
				plnC.setStoveNo(listM.getStoveNo());
				plnC.setProPlanId(plnOrderS.getProPlanId());
				plnC.setGxPlanNo(plnOrderS.getGxPlanNo());
				plnC.setPlineCode(plnOrderS.getPlineCode());
				plnC.setPlineName(plnOrderS.getPlineName());
				plnC.setOutdiameterIn(listM.getOutdiameterIn());
				plnC.setWallthickIn(listM.getWallthickIn());
				plnC.setOutnumCut(String.valueOf(outnumCut));
				plnC.setLengthIn(listM.getLengthIn());
				plnC.setLengthmaxIn(listM.getLengthmaxIn());
				plnC.setLengthminIn(listM.getLengthminIn());
				plnC.setPlanIndoubleNum(String.valueOf(takeCount));
				plnC.setPlanIndoubleWt(String.valueOf(weight));

				plnC.setHeatPlanSqe(heatPlanSqe);
				// 新增
				String addPlnGxJgxC = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("FrmEndLibrary.addPlnZyDbkC"), plnC);
				ps = conn.prepareStatement(addPlnGxJgxC);
				ps.executeUpdate();
				ps.close();

				List<MatBcMEntityPln> matGpMlist = getQureyMatGpM(conn,
						judgeStoveNo, batchNo, batchGroupBy, takeCount,
						heatPlanNoNext, processCdoe, "", proOrderNo, actLen,
						lenFalg,mateialNo);
				if (matGpMlist == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				for (MatBcMEntityPln matGpM : matGpMlist) {
					if (!matGpM.getProOrderNo().equals("")) {
						cro.setV_errMsg("选中炉号已挂生产合同,不能返线!");
						return cro;
					}
					if (!matGpM.getJugdeApplyCode().equals("")) {
						cro.setV_errMsg("该炉已送判,不能返线");
						return cro;
					}
					String batchNoPhy = batchNo;
					// // 生成热处理管号队列表
					// String addSamp = CoreXmlSqlParsersFactory
					// .getSql("FrmEndLibrary.addHttSamp");
					// ps = conn.prepareStatement(addSamp);
					// ps.setObject(1, heatPlanNo);
					// ps.setObject(2, plnOrderS.getZyBatchId());
					// ps.setObject(3, plnOrderS.getPlineCode());
					// ps.setObject(4, plnOrderS.getPlineName());
					// ps.setObject(5, pointGx);
					// ps.setObject(6, batchNoPhy);// 性能批号
					// ps.setObject(7, userName);
					// ps.setObject(8, bc);
					// ps.setObject(9, bz);
					// ps.setObject(10, dateTime);
					// ps.setObject(11, heatPlanSqe);
					// ps.setObject(12, heatPlanNoOld);
					// ps.setObject(13, matGpM.getMatNo());
					// ps.executeUpdate();
					// ps.close();
					String update = "UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T SET T.HEAT_PLAN_NO=?,"
							+ "T.PHY_BATCH_NO=?,T.LOT_NO=?,T.PLINE_CODE=?,T.PLINE_NAME=?,T.HEAT_PLAN_SQE=?,"
							+ "T.INSTORE_FLAG='0',T.RETURN_PROCESS=? WHERE T.HEAT_PLAN_NO=? AND T.MAT_NO=?";
					ps = conn.prepareStatement(update);
					ps.setObject(1, heatPlanNo);
					ps.setObject(2, batchNoPhy);// 性能批号
					ps.setObject(3, plnOrderS.getZyBatchId());
					ps.setObject(4, plnOrderS.getPlineCode());
					ps.setObject(5, plnOrderS.getPlineName());
					ps.setObject(6, heatPlanSqe);
					ps.setObject(7, pointGx);
					ps.setObject(8, heatPlanNoOld);
					ps.setObject(9, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();
					// // 生成材料备份表
					// String allBackMat =
					// "INSERT INTO MAT_BC_BACKUP SELECT * FROM MAT_BC_M WHERE MAT_NO=?";
					// ps = conn.prepareStatement(allBackMat);
					// ps.setObject(1, matGpM.getMatNo());
					// ps.executeUpdate();
					// ps.close();

					// 删除入库记录(产出入库)
					String deleteIn = "DELETE YDM_BC_INLIST  WHERE MAT_NO = ?  AND PLINE_CODE = ?  AND INSTOCK_TYPE_CODE = '"
							+ 800701 + "'";
					ps = conn.prepareStatement(deleteIn);
					ps.setObject(1, matGpM.getMatNo());
					ps.setObject(2, matGpM.getPlineCode());
					ps.executeUpdate();
					ps.close();

					// // 删除入库记录(产权入库)
					// deleteIn =
					// "DELETE YDM_BC_INLIST  WHERE MAT_NO = ?  AND PLINE_CODE = ?  AND INSTOCK_TYPE_CODE = '"
					// + 800709 + "'";
					// ps = conn.prepareStatement(deleteIn);
					// ps.setObject(1, matGpM.getMatNo());
					// ps.setObject(2, matGpM.getPlineCode());
					// ps.executeUpdate();
					// ps.close();

					// 删除材料表
					String deleteMat = "DELETE MAT_BC_M WHERE MAT_NO=?";
					ps = conn.prepareStatement(deleteMat);
					ps.setObject(1, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();
					// 删除位置表
					String deleteMatB = "DELETE YDM_BC_BUTTRESS WHERE MAT_NO=?";
					ps = conn.prepareStatement(deleteMatB);
					ps.setObject(1, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();

				}

				if (nextProcessCdeo.equals("G")) {
					if (wholeDesc.contains("加工") && orderSource.equals("备料需求")) {
						// 查询备料需求与成品对应关系
						String sqlBL = "SELECT T.ORD_LN_DLY_PK FROM PLN_PORDER_BL_REQ T WHERE T.REQ_BL_ID=?";
						ps = conn.prepareStatement(sqlBL);
						ps.setObject(1, ordLnDlyPk);
						rs = ps.executeQuery();
						if (rs.next()) {
							ordLnDlyPk = rs.getString("ORD_LN_DLY_PK");
							plnDivideId = "01";
						}
						rs.close();
						ps.close();
					}
					List<PlnOrderJgxSEntity> plnOrder = PlanFurnProduction
							.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "G",
									PlnOrderJgxSEntity.class);
					if (plnOrder.size() > 0) {
						// 生成镦拔扩虚拟炉计划
						if (addPlnZyJgxM(conn, matTrack, takeCount, weight,
								plnOrder, userName, dateTime, nextProcessCdeo,
								processCdoe, cic, heatPlanNo)) {
							// continue;
						}
					}
				} else if (nextProcessCdeo.equals("H")) {
					List<PlnGxJgPropSEntity> plnOrder = PlanFurnProduction
							.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "H",
									PlnGxJgPropSEntity.class);
					if (plnOrder.size() > 0) {
						// 生成镦虚拟炉计划
						if (addPlnZyJgM(conn, matTrack, takeCount, weight,
								plnOrder, userName, dateTime, nextProcessCdeo,
								processCdoe, heatPlanNo)) {
							// continue;
						}
					}
				}else if (nextProcessCdeo.equals("F")) {
					List<PlnOrderRclSEntity> plnOrder = PlanFurnProduction
							.getPlanOrder(conn, ordLnDlyPk, plnDivideId, "F",
									PlnOrderRclSEntity.class);
					if (plnOrder.size() > 0) {
						// 生成镦拔扩虚拟炉计划
						if (addPlnZyRclM(conn, matTrack, takeCount, weight,
								plnOrder, userName, dateTime, nextProcessCdeo,
								processCdoe, cic, heatPlanNo)) {
							// continue;
						}
					}
				}

			}

			cro.setV_errMsg("返线成功!");
			conn.commit();
			jhyCon.commit();
		} catch (Exception sqle) {
			try {
				conn.rollback();
				jhyCon.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
					jhyCon.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}


	/***
	 * 按材料号查询
	 * @return
	 */
	public CoreReturnObject doQueryDataMat(String matBcTity)
	{
		String sql = "";
		MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(matBcTity, MatBcMEntity.class);
		if (matBcEntity.getQcmStaus().equals("合格")) {
			matBcEntity.setQcmStaus("00");
		} else if (matBcEntity.getQcmStaus().equals("待处理")) {
			matBcEntity.setQcmStaus("11");
		} else if (matBcEntity.getQcmStaus().equals("废品")) {
			matBcEntity.setQcmStaus("22");
		}

		if (matBcEntity.getProductFlag().equals("在制品")) {
			matBcEntity.setProductFlag("801401");
		} else if (matBcEntity.getProductFlag().equals("成品")) {
			matBcEntity.setProductFlag("801402");
		} else if (matBcEntity.getProductFlag().equals("商品")) {
			matBcEntity.setProductFlag("801403");
		}
		sql = CoreXmlSqlParsersFactory.getSql("FrmEndLibrary.getBcMatNo");

		sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
		return this.getData(sql);
	}
}
