package com.steering.pss.plnsaleord.planStove;

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

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.planStove.entity.MatBcTrackEntity;
import com.steering.pss.plnsaleord.processOrder.tmsDemand.writeDemand;
import com.steering.pss.plnsaleord.stove.PlanFurnProduction;
import com.steering.pss.plnsaleord.stove.corePlanFurnProM;
import com.steering.pss.plnsaleord.stove.entity.MatBcMEntityPln;
import com.steering.pss.plnsaleord.stove.entity.PlnOrderDbkSEntity;
import com.steering.pss.plnsaleord.stove.entity.PlnOrderRclSEntity;
import com.steering.pss.plnsaleord.stove.entity.PlnZyDbkMEntity;
import com.steering.pss.plnsaleord.stove.entity.PlnZyJgxMEntity;
import com.steering.pss.plnsaleord.stove.entity.PlnZyRclMEntity;
import com.steering.pss.plnsaleord.stove.entity.PlnZyRclCEntity;
import com.steering.pss.plnsaleord.steelMarkingPlan.FrmSteelMakingPlanChange;

/**
 * 热处理炉计划
 * 
 * @author 
 */
public class FrmPlanStoveF extends DBCommon {

	/**
	 * 查询虚拟炉计划
	 * 
	 * @return
	 */
	public CoreReturnObject queryPlanStoveYzF(String timeBegin, String timeEnd,
			String plineCode, String orderNo, String proPlanId, String heatId,
			String[] statusArr, String judgeNo, String feedNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanStoveF.queryPlanStoveME");
		List<String> param = new ArrayList<String>();
		if (!timeBegin.equals("") && !timeEnd.equals("")) {
			sql += " AND TO_DATE(T.PRO_DAY, 'YYYY-MM-DD') BETWEEN TO_DATE(?,'YYYY-MM-DD') AND TO_DATE(?,'YYYY-MM-DD')";
			param.add(timeBegin);
			param.add(timeEnd);
		}
		if (!plineCode.equals("")) {
			sql += " AND T.PLINE_CODE=? ";
			param.add(plineCode);
		}
		if (!orderNo.equals("")) {
			sql += " AND T.ORDER_NO||'/'||T.ORDER_SEQ LIKE '%'||?||'%'";
			param.add(orderNo);
		}
		if (!proPlanId.equals("")) {
			sql += " AND T.PRO_PLAN_ID=?";
			param.add(proPlanId);
		}
		if (!heatId.equals("")) {
			sql += " AND T.HEAT_PLAN_NO LIKE '%'||?||'%'";
			param.add(heatId);
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO=?";
			param.add(judgeNo);
		}
		if (!feedNo.equals("")) {
			sql += " AND T.FEED_HEAT_NO=?";
			param.add(feedNo);
		}
		sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", statusArr);
		sql += " ORDER BY S.GX_PRO_SEQ,T.PLINE_NAME  ASC";
		return this.getData(sql, param.toArray());
	}

	/**
	 * 查询热处理实际炉计划
	 * 
	 * @return
	 */
	public CoreReturnObject queryPlnZyDbkReadyById(String timeBegin,
			String timeEnd, String plineCode, String orderNo, String proPlanId,
			String heatId, String[] statusArr, String judgeNo, String feedNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanStoveF.queryPlanStoveReadyE");
		List<String> param = new ArrayList<String>();
		if (!timeBegin.equals("") && !timeEnd.equals("")) {
			sql += " AND TO_DATE(T.PRO_DAY, 'YYYY-MM-DD') BETWEEN TO_DATE(?,'YYYY-MM-DD') AND TO_DATE(?,'YYYY-MM-DD')";
			param.add(timeBegin);
			param.add(timeEnd);
		}
		if (!plineCode.equals("")) {
			sql += " AND T.PLINE_CODE=? ";
			param.add(plineCode);
		}
		if (!orderNo.equals("")) {
			sql += " AND T.ORDER_NO||'/'||T.ORDER_SEQ LIKE '%'||?||'%'";
			param.add(orderNo);
		}
		if (!proPlanId.equals("")) {
			sql += " AND T.PRO_PLAN_ID=?";
			param.add(proPlanId);
		}
		if (!heatId.equals("")) {
			sql += " AND T.HEAT_PLAN_NO LIKE '%'||?||'%'";
			param.add(heatId);
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO=?";
			param.add(judgeNo);
		}
		if (!feedNo.equals("")) {
			sql += " AND T.FEED_HEAT_NO=?";
			param.add(feedNo);
		}
		sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", statusArr);
		sql += " ORDER BY T.GX_PRO_SEQ,T.HEAT_PLAN_NO ASC";
		return this.getData(sql, param.toArray());
	}

	/**
	 * 根据炉计划号查询实际炉计划
	 * 
	 * @param heatPlanNo
	 * @return
	 */
	public CoreReturnObject queryPlanStoveRow(String heatPlanNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanStoveF.queryPlanStoveReadyE");
		sql += "  AND T.HEAT_PLAN_NO ='" + heatPlanNo + "' ";
		sql += " ORDER BY T.GX_PRO_SEQ,T.HEAT_PLAN_NO ASC";
		return this.getData(sql);
	}

	/**
	 * 根据订单号，排产序号查询炉计划
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject queryPlanStovePlanId(String proPlanId,
			String gxPlanNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanStoveF.queryPlanStoveReadyE");
		sql += "  AND T.PRO_PLAN_ID ='" + proPlanId + "' AND T.GX_PLAN_NO='"
				+ gxPlanNo + "' ";
		sql += " ORDER BY T.LOT_NO_SQE ASC";
		return this.getData(sql);
	}

	/***
	 * 回写打印次数，打印时间
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject updatePintFlag(ArrayList<ArrayList<String>> jslist) {

		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			// ResultSet rs = null;
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);

			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String heatPlanNo = list.get(0);
				String printTime = "";
				// 查询是否接箍料备料需求
				String sql = "SELECT T.PRINT_TIME FROM PLN_ZY_RCL_M T WHERE T.HEAT_PLAN_NO=?";
				ps = conn.prepareStatement(sql);
				ps.setObject(1, heatPlanNo);
				rs = ps.executeQuery();
				if (rs.next()) {
					printTime = rs.getString("PRINT_TIME");
				}
				rs.close();
				ps.close();
				// 修改打印时间，打印次数
				String updatePrin = "UPDATE PLN_ZY_RCL_M T SET T.PRINT_NUMBER = TO_NUMBER(NVL(T.PRINT_NUMBER, 0)) +'1'";
				if (printTime == null || printTime.equals("")) {
					updatePrin += ", T.PRINT_TIME  = TO_DATE('" + dateTime
							+ "','YYYY-MM-DD HH24:MI:SS') ";
				}
				updatePrin += "WHERE T.HEAT_PLAN_NO = ? ";
				ps = conn.prepareStatement(updatePrin);
				ps.setObject(1, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					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;
	}

	/**
	 * 选择炉计划下发，撤销下发
	 */
	public CoreReturnObject doFurnacePlan(ArrayList<ArrayList<String>> jslist,
			String userName, String flag, String proPlanId, String gxPlanNo,
			ArrayList<String> possList) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;

		// Connection tmsCon = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			// tmsCon = this.getDao("TmsDao").getConnection();注释生产物流 2024/4/24
			// 肖沅累
			conn.setAutoCommit(false);
			// tmsCon.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			String sql = "";
			String designKey = "";
			String delievStateCode = "";
			String delievStateName = "";
			String msg = "";
			// ResultSet rs = null;
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);

			String bltype = "";
			// 查询是否接箍料备料需求
			sql = "SELECT T1.BLTYPE FROM PLN_ORDER_RCL_S T ,PLN_PORDER_BL_REQ T1 WHERE T.ORD_LN_DLY_PK=T1.REQ_BL_ID AND T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
			ps = conn.prepareStatement(sql);
			ps.setObject(1, proPlanId);
			ps.setObject(2, gxPlanNo);
			rs = ps.executeQuery();
			if (rs.next()) {
				bltype = rs.getString("BLTYPE");
			}
			rs.close();
			ps.close();

			PlnOrderRclSEntity plnOrderS = FrmPlanMaterialDbk.getPlanOrderS(
					conn, proPlanId, gxPlanNo, PlnOrderRclSEntity.class, "F");
			if (plnOrderS == null) {
				cro.setV_errMsg("未找到订单(" + proPlanId + "/" + gxPlanNo + ")信息!");
				return cro;
			}

			sql = CoreXmlSqlParsersFactory.getSql("addPlnFurn.SelectDesignKey");// 查询designkey和mscPline
			ps = conn.prepareStatement(sql);
			ps.setString(1, plnOrderS.getCraftFileNo());
			ps.setString(2, plnOrderS.getCraftSeq());
			rs = ps.executeQuery();
			if (rs.next()) {
				designKey = rs.getString("DESGIN_KEY");
			}
			rs.close();
			ps.close();

			// 查询交货状态
			sql = CoreXmlSqlParsersFactory.getSql("addPlnFurn.selectState");
			ps = conn.prepareStatement(sql);
			ps.setString(1, designKey);
			ps.setString(2, plnOrderS.getIndexSeq());
			ps.setString(3, plnOrderS.getDecision());
			rs = ps.executeQuery();
			if (rs.next()) {
				delievStateCode = rs.getString("BASECODE");
				delievStateName = rs.getString("BASENAME");
			}
			rs.close();

			ps.close();

			// 循环虚拟炉计划信息
			String heatPlanNo1 = "";
			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String heatPlanNo = list.get(0);
				if (heatPlanNo1.equals(heatPlanNo)) {
					continue;
				}
				if (heatPlanNo1.equals("") || !heatPlanNo1.equals(heatPlanNo)) {
					heatPlanNo1 = heatPlanNo;
				}
				// 查询炉计划信息
				PlnZyRclMEntity listM = FrmPlanStoveE.getQureyZyM(conn,
						heatPlanNo, "F", PlnZyRclMEntity.class);
				if (listM == null) {
					cro.setV_errMsg("炉计划已发生变化,请重新查询!");
					return cro;
				}
				// String proPlanId = listM.getProPlanId();
				// String gxPlanNo = listM.getGxPlanNo();
				// String plnDivideId = listM.getPlnDivideId();
				String plineCode = listM.getPlineCode();
				String judgeStoveNo = listM.getJudgeStoveNo();
				String gowhereName = "";
				String gowhereCode = "";
				String ifProduct = "0";
				if (flag.equals("0") && !listM.getPlanstatus().equals("计划")) {
					cro.setV_errMsg("选择的炉计划状态不是计划状态,不能下发!");
					return cro;
				}
				if (flag.equals("1") && !listM.getPlanstatus().equals("下发")) {
					cro.setV_errMsg("选择的炉计划不是下发状态,不能撤销下发!");
					return cro;
				}
				String zyBatchId = "";
				String planstatus = "";
				if (flag.equals("1")) {// 撤销下发
					if (Integer.parseInt(listM.getRealProcessSeq()) > 1) {
						cro.setV_errMsg("选择的炉计划是二次热处理,不能撤销下发!");
						return cro;
					}
					planstatus = "00";
					zyBatchId = "";
				} else {
					if (plnOrderS.getIfStoveIssued().equals("0")) {
						cro.setV_errMsg("订单(" + proPlanId + "/" + gxPlanNo
								+ "),未下发,请先下发订单锁定生产批次!");
						return cro;
					}
					planstatus = "10";
					zyBatchId = plnOrderS.getZyBatchId();
					if (zyBatchId.equals("")) {
						cro.setV_errMsg("生产批次不能为空,请确认!");
						return cro;
					}
					int countGz = 0;
					String gradenameM = "";
					// 查询热处理订单对应钢种
					String sqlZgS = "SELECT T.GRADENAME FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					ps = conn.prepareStatement(sqlZgS);
					ps.setObject(1, plnOrderS.getProPlanId());
					ps.setObject(2, plnOrderS.getGxPlanNo());
					rs = ps.executeQuery();
					while (rs.next()) {
						if (gradenameM.equals("")) {
							gradenameM = rs.getString("GRADENAME");
						}
						if (!gradenameM.equals(rs.getString("GRADENAME"))) {
							countGz++;
						}
					}
					rs.close();
					ps.close();
					if (countGz > 0) {
						cro.setV_errMsg("热处理订单(" + plnOrderS.getProPlanId()
								+ "/" + plnOrderS.getGxPlanNo() + ")对应上料炉号("
								+ listM.getFeedHeatNo() + ")钢种不同,请先拆分热处理订单!");
						return cro;
					}
					// 末工序获取去向
					String gowWhere = corePlanFurnProM.getPlineCodeGroup(conn,
							plineCode, proPlanId, gxPlanNo, "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, plineCode);
						ps.setObject(2, gowWhere);
						rs = ps.executeQuery();
						if (rs.next()) {
							gowhereName = rs.getString("STORAGE_NAME");
							gowhereCode = rs.getString("STORAGE_NO");
						}
						rs.close();
						ps.close();
					}
					int counnum = StoveHelper.getQueryStation(conn, proPlanId,
							gxPlanNo, "F");
					if (counnum > 0) {
						ifProduct = "1";
					}
					// // 判断判定炉号是否重复下发
					// String queryMjud =
					// "SELECT T.PLANSTATUS FROM PLN_ZY_RCL_M T  WHERE 1 = 1  AND T.JUDGE_STOVE_NO = ?  AND T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?  ORDER BY T.PLANSTATUS DESC";
					// ps = conn.prepareStatement(queryMjud);
					// ps.setObject(1, judgeStoveNo);
					// ps.setObject(2, proPlanId);
					// ps.setObject(3, gxPlanNo);
					// rs = ps.executeQuery();
					// if (rs.next()) {
					// if (!rs.getString("PLANSTATUS").equals("00")) {
					// cro.setV_errMsg("判定炉号(" + judgeStoveNo + ")在热处理订单("
					// + proPlanId + "/" + gxPlanNo
					// + ")下已下发,不能重复下发,请修改判定炉号!");
					// return cro;
					// }
					// }
					// rs.close();
					// ps.close();
				}
				// 修改虚拟炉计划
				String deleteZgM = "UPDATE PLN_ZY_RCL_M T SET T.ZY_BATCH_ID=?, T.PLANSTATUS=?,T.GOWHERE_CODE=?,T.GOWHERE_NAME=?,T.DOWNMAN=?,T.DOWNTIME=TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),"
						+ " T.CRAFT_FILE_NO=?,T.CRAFT_FILE_MAN=?,T.CRAFT_SEQ=?,T.IF_PRODUCT=?    WHERE T.HEAT_PLAN_NO=?";
				ps = conn.prepareStatement(deleteZgM);
				ps.setObject(1, zyBatchId);
				ps.setObject(2, planstatus);
				ps.setObject(3, gowhereCode);
				ps.setObject(4, gowhereName);
				ps.setObject(5, userName);
				ps.setObject(6, dateTime);
				ps.setObject(7, plnOrderS.getCraftFileNo());
				ps.setObject(8, plnOrderS.getCraftFileMan());
				ps.setObject(9, plnOrderS.getCraftSeq());
				ps.setObject(10, ifProduct);
				ps.setObject(11, heatPlanNo);
				ps.executeUpdate();
				ps.close();

				// 修改实际炉计划
				deleteZgM = "UPDATE PLN_ZY_RCL_C T SET T.ZY_BATCH_ID=? WHERE T.HEAT_PLAN_NO=?";
				ps = conn.prepareStatement(deleteZgM);
				ps.setObject(1, zyBatchId);
				ps.setObject(2, heatPlanNo);
				ps.executeUpdate();
				ps.close();

				if (flag.equals("1")) {
					// 撤销下工序虚拟炉计划
					String messeGx = PlanFurnProduction.deletePlnFurnJgx(
							listM.getProPlanId(), listM.getGxPlanNo(),
							userName, dateTime, heatPlanNo,
							listM.getPlnDivideId(), conn);
					if (!messeGx.equals("")) {
						cro.setV_errMsg(messeGx);
						return cro;
					}
					// if (bltype.equals("接箍料")) {
					// // 撤销接箍虚拟炉计划
					// String messeGxjg = PlanFurnProduction.deletePlnFurnJg(
					// proPlanId, gxPlanNo, userName, dateTime,
					// heatPlanNo, listM.getPlnDivideId(), conn);
					// if (!messeGxjg.equals("")) {
					// cro.setV_errMsg(messeGx);
					// return cro;
					// }
					//
					// }
				} else {
					// 新增下工序虚拟炉计划
					String messeGx = PlanFurnProduction.addPlnFurnJgx(
							listM.getProPlanId(), listM.getGxPlanNo(),
							userName, dateTime, heatPlanNo,
							listM.getPlnDivideId(), conn, delievStateCode,
							delievStateName);
					if (!messeGx.equals("")) {
						cro.setV_errMsg(messeGx);
						return cro;
					}
					// if (bltype.equals("接箍料")) {
					// // 新增接箍虚拟炉计划
					// String messeGxjg = PlanFurnProduction.addPlnFurnJg(
					// proPlanId, gxPlanNo, userName, dateTime,
					// heatPlanNo, listM.getPlnDivideId(), conn);
					// if (!messeGxjg.equals("")) {
					// cro.setV_errMsg(messeGx);
					// return cro;
					// }
					// }
				}
			}
			/*
			 * if (flag.equals("1")) { msg =
			 * writeDemand.cancelWriteDemandPlnSinger(jslist, "F", userName,
			 * tmsCon, conn); } else { msg =
			 * writeDemand.writeDemandPlnSinger(jslist, "F", userName, tmsCon,
			 * conn,possList); }
			 */
			if (!msg.equals("")) {
				cro.setV_errMsg("生成/删除运输需求出错!");
			}
			if (flag.equals("1")) {
				cro.setV_errMsg("撤销成功!");
				// 撤销，更新记录
				this.insertMesRclPlan(jslist, false, conn, cro);
			} else {
				// 新增写入
				this.insertMesRclPlan(jslist, true, conn, cro);
				cro.setV_errMsg("下发成功!");
			}
			conn.commit();
			// tmsCon.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null/* ||tmsCon != null */) {
					conn.rollback();
					// tmsCon.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
				/*
				 * if (tmsCon != null && !tmsCon.isClosed()) { tmsCon.close(); }
				 */
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 选择炉计划删除
	 */
	public CoreReturnObject doDeleteLu(ArrayList<ArrayList<String>> jslist,
			String userName) 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);
			Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			DecimalFormat df = new DecimalFormat("0000000000");
			int seq = 1;
			// 循环炉计划信息
			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String heatPlanNo = list.get(0);
				String heatPlanSeqNo = list.get(1);
				// 查询炉计信息

				PlnZyRclMEntity listM = FrmPlanStoveE.getQureyZyM(conn,
						heatPlanNo, "F", PlnZyRclMEntity.class);
				if (listM == null) {
					cro.setV_errMsg("炉计划已发生变化,请重新查询!");
					return cro;
				}

				if (!listM.getPlanstatus().equals("计划")) {
					cro.setV_errMsg("选择的热处理炉计划状态不是计划状态,不能删除!");
					return cro;
				}
				int lotNo = Integer.parseInt(listM.getLotNoSqe());
				String proPlanId = listM.getProPlanId();
				String gxPlanNo = listM.getGxPlanNo();
				if (!heatPlanSeqNo.equals("")) {// 删除实际炉计划
					PlnZyRclCEntity listC = FrmPlanStoveE.getQureyZyC(conn,
							heatPlanNo, heatPlanSeqNo, PlnZyRclCEntity.class,
							"F");
					if (listC == null) {
						cro.setV_errMsg("炉计划已发生变化,请重新查询!");
						return cro;
					}

					int plnNumGp = Integer.parseInt(listC.getPlanIndoubleNum());
					List<MatBcMEntityPln> matGpMlist = FrmRollTubeLibraryRcl
							.getQureyMatGpM(conn, listC, plnNumGp, heatPlanNo);
					if (matGpMlist == null) {
						cro.setV_errMsg("管坯物料已发生改变,请刷新!");
						return cro;
					}
					String proPlanIdNo = listC.getProPlanId() + "/"
							+ listC.getGxPlanNo();
					MatBcTrackEntity matTrack = FrmPlanMaterialDbk
							.getQureyMatTrack(conn, listC.getFeedHeatNo(),
									listC.getBatchNo(),
									listC.getBatchGroudNo(), plnNumGp, "1",
									proPlanIdNo, MatBcTrackEntity.class,
									"delete", "", "");
					if (matTrack == null) {
						return cro;
					}
					int matCount = 0;
					for (MatBcMEntityPln matGpM : matGpMlist) {
						if (!matGpM.getMatStatus().equals("80150103")) {
							cro.setV_errMsg("判定炉号为:" + matGpM.getJudgeStoveNo()
									+ ",不是材料已编计划状态,不能删除炉计划!");
							return cro;
						}
						String matStatus = "80150102";
						if (matGpM.getJudgeResultCode() == null
								|| matGpM.getJudgeResultCode().equals("")) {
							matStatus = "80150101";
						}
						matCount += Integer.parseInt(matGpM.getActCount());
						// 修改坯子库存信息
						String sqlUpdateMat = CoreXmlSqlParsersFactory
								.getSql("FrmPlanMaterialDbk.UpdateMatGp");
						ps = conn.prepareStatement(sqlUpdateMat);
						ps.setObject(1, matStatus);
						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();
					}
					String resumeSeq = dateFormat.format(now) + df.format(seq);
					// 生成利库日志
					matTrack.setResumeSeq(resumeSeq);
					matTrack.setEventId("900101");
					matTrack.setEventDesc("脱单");
					matTrack.setFormName("com.steering.pss.plnsaleord.planStove.FrmRollTubeLibraryRcl");
					matTrack.setCallFuncCoding("doDeleteLu");
					matTrack.setKeyvalue1("List<MatBcMEntityPln> matGpMlist");
					matTrack.setKeyvalue1Desc("物料主表关键字实体类集合");
					matTrack.setKeyvalue2("String userName");
					matTrack.setKeyvalue2Desc2("操作人");
					matTrack.setKeyvalue3("doDeleteLu");
					matTrack.setKeyvalue3Desc3("删除炉计划");
					matTrack.setProcessCdoe("F");
					matTrack.setMemo("");
					matTrack.setCreateName(userName);
					matTrack.setCreateTime(dateTime);
					seq++;
					String sqlAddTrack = EntityTool
							.fillSqlByEntity(
									CoreXmlSqlParsersFactory
											.getSql("FrmPlanMaterialDbk.addMatBcTrack"),
									matTrack);
					ps = conn.prepareStatement(sqlAddTrack);
					ps.executeUpdate();
					ps.close();

					if (matCount != plnNumGp) {
						cro.setV_errMsg("库存支数与实际炉计划支数不符,请确认!");
						return cro;
					}

					// 删除实际炉计划
					String deleteZgC = "DELETE PLN_ZY_RCL_C WHERE HEAT_PLAN_NO = ? AND HEAT_PLAN_SQE=?";
					ps = conn.prepareStatement(deleteZgC);
					ps.setObject(1, heatPlanNo);
					ps.setObject(2, heatPlanSeqNo);
					ps.executeUpdate();
					ps.close();

					// 查询实际炉计划是否全部删除
					int count = 0;
					String sql = "SELECT COUNT(*) COUNT FROM PLN_ZY_RCL_C T WHERE T.HEAT_PLAN_NO=?";
					ps = conn.prepareStatement(sql);
					ps.setObject(1, heatPlanNo);
					rs = ps.executeQuery();
					if (rs.next()) {
						count = rs.getInt("COUNT");
					}
					if (count == 0) {
						// 删除虚拟炉计划
						String deleteZgM = "DELETE PLN_ZY_RCL_M WHERE HEAT_PLAN_NO = ?";
						ps = conn.prepareStatement(deleteZgM);
						ps.setObject(1, heatPlanNo);
						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();
					}
				} else {
					// 删除虚拟炉计划
					String deleteZgM = "DELETE PLN_ZY_RCL_M WHERE HEAT_PLAN_NO = ?";
					ps = conn.prepareStatement(deleteZgM);
					ps.setObject(1, heatPlanNo);
					ps.executeUpdate();
					ps.close();

					String sql = "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(sql);
					ps.setObject(1, proPlanId);
					ps.setObject(2, gxPlanNo);
					ps.setObject(3, lotNo);
					ps.executeUpdate();
					ps.close();

					// 新增生产批号
					// StoveHelper.updatePlnRclGroup(conn, proPlanId, gxPlanNo,
					// listM.getPic());
					// 修改库存订单号
					String updateMat = "UPDATE MAT_BC_M T SET T.PRO_PLAN_ID_NEXT='', T.GX_PLAN_NO_NEXT='',T.NEXT_PROCESS_CDOE='',T.NEXT_PROCESS_DESC='',T.HEAT_PLAN_NO_NEXT=''"
							+ " WHERE T.JUDGE_STOVE_NO=? AND T.HEAT_PLAN_NO_NEXT=?  AND T.HANGING_FLAG='0'";
					ps = conn.prepareStatement(updateMat);
					ps.setObject(1, listM.getFeedHeatNo());
					ps.setObject(2, heatPlanNo);
					ps.executeUpdate();
					ps.close();
					// // 删除实际炉计划
					// String deleteZgC =
					// "DELETE PLN_ZY_RCL_C WHERE HEAT_PLAN_NO = ?";
					// ps = conn.prepareStatement(deleteZgC);
					// ps.setObject(1, heatPlanNo);
					// ps.executeUpdate();
					// ps.close();
				}

			}
			cro.setV_errMsg("删除成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					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;
	}

	/**
	 * 修改循环次数
	 */
	public CoreReturnObject doUpdate(ArrayList<ArrayList<String>> jslist,
			String userName) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// 循环炉计划信息
			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String heatPlanNo = list.get(0);
				String processSeq = list.get(1);
				// 查询炉计信息
				PlnZyJgxMEntity listM = FrmPlanStoveE.getQureyZyM(conn,
						heatPlanNo, "F", PlnZyJgxMEntity.class);
				if (listM == null) {
					cro.setV_errMsg("炉计划已发生变化,请重新查询!");
					return cro;
				}
				if (!listM.getPlanstatus().equals("计划")
						&& !listM.getPlanstatus().equals("下发")) {
					cro.setV_errMsg("选择的炉计划状态不是计划/下发状态,不能修改!");
					return cro;
				}
				// 修改虚拟炉计划
				String deleteZgM = "UPDATE PLN_ZY_RCL_M SET PROCESS_SEQ=?, UPDATE_NAME=?,UPDATE_TIME=SYSDATE WHERE HEAT_PLAN_NO = ?";
				ps = conn.prepareStatement(deleteZgM);
				ps.setObject(1, processSeq);
				ps.setObject(2, userName);
				ps.setObject(3, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("修改成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					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;
	}

	/**
	 * 修改爐归组
	 */
	public CoreReturnObject doUpdateGroup(ArrayList<ArrayList<String>> jslist,
			String userName, String processCode) throws ParseException {
		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;

			// 循环炉计划信息
			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String heatPlanNo = list.get(1);
				String LotNoGroup = list.get(0);
				if (processCode.equals("F")) {
					// 查询炉计信息
					PlnZyRclMEntity listM = FrmPlanStoveE.getQureyZyM(conn,
							heatPlanNo, "F", PlnZyRclMEntity.class);
					if (listM == null) {
						cro.setV_errMsg("炉计划已发生变化,请重新查询!");
						return cro;
					}
					// String sqlQcm =
					// "SELECT T.VALIDFLAG FROM QCM_ZG_JUGDE_APPLY T WHERE T.JUDGE_STOVE_NO=? AND T.PROCESS_CODE=? AND T.IS_FLAG='0' ";
					// ps = conn.prepareStatement(sqlQcm);
					// ps.setObject(1, listM.getJudgeStoveNo());
					// ps.setObject(2, "F");
					// rs = ps.executeQuery();
					// while (rs.next()) {
					// if (rs.getString("VALIDFLAG").equals("20")) {
					// cro.setV_errMsg("判定炉号:" + listM.getJudgeStoveNo()
					// + ",已判定不能修改炉归组！");
					// return cro;
					// }
					// }
					// rs.close();
					// ps.close();
					// 修改虚拟炉计划
					String updateM = "UPDATE PLN_ZY_RCL_M  SET LOT_NO_GROUP=?  WHERE HEAT_PLAN_NO = ?";
					ps = conn.prepareStatement(updateM);
					ps.setObject(1, LotNoGroup);
					ps.setObject(2, heatPlanNo);
					ps.executeUpdate();
					ps.close();

					// 修改送送判表
					String updateQcm = "UPDATE QCM_ZG_JUGDE_APPLY T SET T.LOT_NO_GROUP=?  WHERE T.JUDGE_STOVE_NO=? AND T.PROCESS_CODE=? AND T.IS_FLAG='0' AND T.VALIDFLAG<>'20'";
					ps = conn.prepareStatement(updateQcm);
					ps.setObject(1, LotNoGroup);
					ps.setObject(2, listM.getJudgeStoveNo());
					ps.setObject(3, "F");
					ps.executeUpdate();
					ps.close();

					// 修改检化验计划表
					String updateMQcm = "UPDATE QCM_ZC_CHECKCONSIGN T SET T.LOT_NO_GROUP=? WHERE T.JUDGE_STOVE_NO=? AND T.PROCESS_CODE='F' AND T.ORD_LN_DLY_PK = ?";
					ps = conn.prepareStatement(updateMQcm);
					ps.setObject(1, LotNoGroup);
					ps.setObject(2, listM.getJudgeStoveNo());
					ps.setObject(3, listM.getOrdLnDlyPk());
					ps.executeUpdate();
					ps.close();
					// 修改检验委托表
					String updatePipe = "UPDATE PIPE_CHECKCONSIGN_BASEINFO T SET T.LOT_NO_GROUP=? WHERE T.HEAT_NO=? AND T.PROCESS_CODE='F'";
					ps = jhyCon.prepareStatement(updatePipe);
					ps.setObject(1, LotNoGroup);
					ps.setObject(2, listM.getJudgeStoveNo());
					ps.executeUpdate();
					ps.close();
				} else if (processCode.equals("G")) {
					// 查询炉计信息
					PlnZyJgxMEntity listM = FrmPlanStoveE.getQureyZyM(conn,
							heatPlanNo, "G", PlnZyJgxMEntity.class);
					if (listM == null) {
						cro.setV_errMsg("炉计划已发生变化,请重新查询!");
						return cro;
					}
					// String sqlQcm =
					// "SELECT T.VALIDFLAG FROM QCM_ZG_JUGDE_APPLY T WHERE T.JUDGE_STOVE_NO=? AND T.PROCESS_CODE=? AND T.IS_FLAG='0' ";
					// ps = conn.prepareStatement(sqlQcm);
					// ps.setObject(1, listM.getJudgeStoveNo());
					// ps.setObject(2, "G");
					// rs = ps.executeQuery();
					// while (rs.next()) {
					// if (rs.getString("VALIDFLAG").equals("20")) {
					// cro.setV_errMsg("判定炉号:" + listM.getJudgeStoveNo()
					// + ",已判定不能修改炉归组！");
					// return cro;
					// }
					// }
					// rs.close();
					// ps.close();
					// 修改虚拟炉计划
					String updateM = "UPDATE PLN_ZY_JGX_M  SET LOT_NO_GROUP=?  WHERE HEAT_PLAN_NO = ?";
					ps = conn.prepareStatement(updateM);
					ps.setObject(1, LotNoGroup);
					ps.setObject(2, heatPlanNo);
					ps.executeUpdate();
					ps.close();

					// 修改送送判表
					String updateQcm = "UPDATE QCM_ZG_JUGDE_APPLY T SET T.LOT_NO_GROUP=?  WHERE T.JUDGE_STOVE_NO=? AND T.PROCESS_CODE=? AND T.IS_FLAG='0' AND T.VALIDFLAG<>'20'";
					ps = conn.prepareStatement(updateQcm);
					ps.setObject(1, LotNoGroup);
					ps.setObject(2, listM.getJudgeStoveNo());
					ps.setObject(3, "G");
					ps.executeUpdate();
					ps.close();

					// 修改检化验计划表
					String updateMQcm = "UPDATE QCM_ZC_CHECKCONSIGN T SET T.LOT_NO_GROUP=? WHERE T.JUDGE_STOVE_NO=? AND T.PROCESS_CODE='G' AND T.ORD_LN_DLY_PK = ?";
					ps = conn.prepareStatement(updateMQcm);
					ps.setObject(1, LotNoGroup);
					ps.setObject(2, listM.getJudgeStoveNo());
					ps.setObject(3, listM.getOrdLnDlyPk());
					ps.executeUpdate();
					ps.close();
					// 修改检验委托表
					String updatePipe = "UPDATE PIPE_CHECKCONSIGN_BASEINFO T SET T.LOT_NO_GROUP=? WHERE T.HEAT_NO=? AND T.PROCESS_CODE='G'";
					ps = jhyCon.prepareStatement(updatePipe);
					ps.setObject(1, LotNoGroup);
					ps.setObject(2, listM.getJudgeStoveNo());
					ps.executeUpdate();
					ps.close();
				}
			}
			cro.setV_errMsg("修改成功!");
			conn.commit();
			jhyCon.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
					jhyCon.rollback();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
					jhyCon.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 手动关闭炉计划
	 */
	public CoreReturnObject doLuClose(ArrayList<ArrayList<String>> jslist,
			String userName) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// 循环炉计划信息
			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String heatPlanNo = list.get(0);
				// 查询炉计信息
				PlnZyRclMEntity listM = FrmPlanStoveE.getQureyZyM(conn,
						heatPlanNo, "F", PlnZyRclMEntity.class);
				if (listM == null) {
					cro.setV_errMsg("炉计划已发生变化,请重新查询!");
					return cro;
				}
				if (listM.getPlanstatus().equals("关闭")) {
					cro.setV_errMsg("选择的热处理炉计划状态是关闭状态,不能重复关闭!");
					return cro;
				}

				// 关闭炉计划
				String deleteZgC = "UPDATE PLN_ZY_RCL_M T SET T.IS_CLOSE='1',T.PLANSTATUS='40' WHERE HEAT_PLAN_NO = ?";
				ps = conn.prepareStatement(deleteZgC);
				ps.setObject(1, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("关闭成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					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 parmList
	 * @return
	 */
	public CoreReturnObject updateGoWhere(ArrayList<String> parmList) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for (String str : parmList) {
				PlnZyRclMEntity plnZyZgEntity = EntityTool.getEntityByJSONStr(
						str, PlnZyRclMEntity.class);
				String updateGoWhereSql = CoreXmlSqlParsersFactory
						.getSql("FrmPlanStoveF.updateGoWhere");
				updateGoWhereSql = EntityTool.fillSqlByEntity(updateGoWhereSql,
						plnZyZgEntity);
				sqllist.add(updateGoWhereSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
					sqllist);
			if (cro.getV_errMsg().equals("")) {
				cro.setV_errMsg("修改成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 修改上料标识
	 * 
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updateLoadFlag(ArrayList<String> parmList,
			String userName) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for (String str : parmList) {
				PlnZyRclMEntity plnZyZgEntity = EntityTool.getEntityByJSONStr(
						str, PlnZyRclMEntity.class);
				if (plnZyZgEntity.getIsLoadFlag().equals("是")) {
					plnZyZgEntity.setIsLoadFlag("0");
				} else {
					plnZyZgEntity.setIsLoadFlag("1");
				}
				plnZyZgEntity.setIsLoadUsername(userName);
				String updateGoWhereSql = CoreXmlSqlParsersFactory
						.getSql("FrmPlanStoveF.updateLoadFlag");
				updateGoWhereSql = EntityTool.fillSqlByEntity(updateGoWhereSql,
						plnZyZgEntity);
				sqllist.add(updateGoWhereSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
					sqllist);
			if (cro.getV_errMsg().equals("")) {
				cro.setV_errMsg("修改成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 标识过磅
	 * 
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updateIsWeight(ArrayList<String> parmList) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for (String str : parmList) {
				PlnZyRclMEntity plnZyZgEntity = EntityTool.getEntityByJSONStr(
						str, PlnZyRclMEntity.class);
				if (!plnZyZgEntity.getPlanstatus().equals("计划")) {
					cro.setV_errMsg("炉计划不是计划状态的不允许修改过磅标识!");
					return cro;
				}
				if (plnZyZgEntity.getIsWeightFlag().equals("是")) {
					plnZyZgEntity.setIsWeightFlag("0");
				} else {
					plnZyZgEntity.setIsWeightFlag("1");
				}
				String updateGoWhereSql = CoreXmlSqlParsersFactory
						.getSql("FrmPlanStoveF.updateIsWeight");
				updateGoWhereSql = EntityTool.fillSqlByEntity(updateGoWhereSql,
						plnZyZgEntity);
				sqllist.add(updateGoWhereSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
					sqllist);
			if (cro.getV_errMsg().equals("")) {
				cro.setV_errMsg("修改成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/**
	 * 
	 * @param arr
	 *            HEAT_PLAN_NO的集合
	 * @param isAdd
	 *            true新增/false删除
	 * @param connection
	 * @param result
	 */
	public void insertMesRclPlan(ArrayList<ArrayList<String>> arr,
			boolean isAdd, Connection connection, CoreReturnObject result) {

		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ArrayList<ArrayList<String>> rowList = new ArrayList<>();
			for (int i = 0; i < arr.size(); i++) {
				ArrayList<String> item = arr.get(i);
				String querySql = "select C.HEAT_PLAN_SQE AS PLAN_ID,  M.GRADENAME, C.PLAN_INDOUBLE_NUM,  M.LENGTH_IN, M.OUTDIAMETER_IN, "+
                        " (M.OUTDIAMETER_IN - M.WALLTHICK_IN) AS BORE, M.WALLTHICK_IN,M.PROCESS_DESC_C, M.JUDGE_STOVE_NO,"
                        + " ORDER_NO ||'/'||ORDER_SEQ as ORD_NO, PROD_STANDARD,PRODUCNAME,C.PLAN_INDOUBLE_WT,M.IF_MONITOR"
					+ " FROM  PLN_ZY_RCL_C C,PLN_ZY_RCL_M M WHERE M.HEAT_PLAN_NO = C.HEAT_PLAN_NO "
					+ " AND C.HEAT_PLAN_NO=?";
				ps = connection.prepareCall(querySql);
				ps.setObject(1, item.get(0));
				rs = ps.executeQuery();
				while (rs.next()) {
					ArrayList<String> row = new ArrayList<>();
					row.add(UUID.randomUUID().toString().replaceAll("-", ""));// uuid
					row.add(rs.getString("PLAN_ID"));// plan_id
					row.add(rs.getString("GRADENAME"));// steel_grade
					row.add(rs.getString("PLAN_INDOUBLE_NUM"));// NUM
					row.add(rs.getString("LENGTH_IN"));// LEN
					row.add(rs.getString("OUTDIAMETER_IN"));// od
					row.add(rs.getString("BORE"));// bore
					row.add(rs.getString("WALLTHICK_IN"));// wt
					row.add(rs.getString("PROCESS_DESC_C"));// process
					if (isAdd) {
						row.add("0");// OPERATION_TYPE
					} else {
						row.add("2");// OPERATION_TYPE
					}
					row.add(rs.getString("JUDGE_STOVE_NO"));// JUDGE_STOVE_NO
					row.add(rs.getString("ORD_NO"));// ORD_NO
					row.add(rs.getString("PROD_STANDARD"));// PROD_STANDARD
					row.add(rs.getString("PRODUCNAME"));// PRODUCNAME
					row.add(rs.getString("PLAN_INDOUBLE_WT"));
					row.add(rs.getString("IF_MONITOR"));
					rowList.add(row);
				}
				rs.close();
				ps.close();
			}

			if (!rowList.isEmpty()) {
				String sql = "INSERT INTO MES_RCL_PLAN (UUID, PLAN_ID, STEEL_GRANDE, NUM, LEN, OD, BORE, WT, PROCESS,"
						+ " OPERATION_TYPE, CREATE_TIME, UPDATE_TIME, FLAGS,JUDGE_STOVE_NO,ORDER_NO,PROD_STANDARD,PRODUCNAME,PLAN_INDOUBLE_WT,IF_MONITOR) VALUES "
						+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, NULL, NULL,?,?,?,?,?,?)";
				ps = connection.prepareStatement(sql);
				for (int i = 0; i < rowList.size(); i++) {
					ArrayList<String> row = rowList.get(i);
					for (int j = 0; j < row.size(); j++) {
						ps.setObject(j + 1, row.get(j));
					}
					ps.addBatch();
				}
				ps.executeBatch();
				ps.clearBatch();
				ps.close();
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}  
	}

}
