package com.steering.mes.mcp.Vrp;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;
import com.steering.mes.mcp.common.PlanService;
import com.steering.mes.mcp.entity.*;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 镦拔扩上料实绩
 * 
 * @author lzh 2015-7-20
 */
public class FrmVrpLoading extends DBCommon {
	/**
	 * 查询镦拔扩计划
	 * 
	 * @param planNo
	 * @return String[] stats
	 */
	public CoreReturnObject getQueryDbkPlan(PlnZyDbkMEntity plan,
			String plinCode, String dobeside, String index) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpLoading.GetQueryDbkPlan");
		if (!plan.getHeatPlanNo().equals("")) {
			sql += " AND T.HEAT_PLAN_NO || '&' LIKE '%' || '"
					+ plan.getHeatPlanNo() + "' || '%'";
		}
		if (!plan.getJudgeStoveNo().equals("")) {
			sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '"
					+ plan.getJudgeStoveNo() + "' || '%'";
		}
		// sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", stats);
		// if (!plan.getPlanstatus().equals("")) {
		// sql += " AND T.PLANSTATUS ='" + plan.getPlanstatus() + "'";
		// }
		if (index.equals("0")) {
			sql += " AND NVL(T.BESIDE_STATUS,'/') < NVL('" + dobeside
					+ "','/')";
		} else if (index.equals("1")) {
			sql += " AND NVL(T.BESIDE_STATUS,'/') >= NVL('" + dobeside
					+ "','/')";
		}
		sql += " AND T.PLINE_CODE ='" + plinCode + "'";
		sql += "  ORDER BY T.PLANSTATUS DESC ) T3 ORDER BY T3.GX_PRO_SEQ,T3.PRO_PLAN_ID,T3.GX_PLAN_NO,T3.HEAT_PLAN_NO  ASC";
		return this.getData(sql);
	}

	/**
	 * 查询镦拔扩计划
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject getQueryDbkPlan(PlnZyDbkMEntity plan,
			String[] plinCodes, String dobeside, String index, String[] stats) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpLoading.GetQueryDbkPlan");
		if (!plan.getHeatPlanNo().equals("")) {
			sql += " AND T.HEAT_PLAN_NO || '&' LIKE '%' || '"
					+ plan.getHeatPlanNo() + "' || '%'";
		}
		if (!plan.getJudgeStoveNo().equals("")) {
			sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '"
					+ plan.getJudgeStoveNo() + "' || '%'";
		}
		if (!plan.getFeedHeatNo().equals("")) {
			sql += " AND T.FEED_HEAT_NO || '&' LIKE '%' || '"
					+ plan.getFeedHeatNo() + "' || '%'";
		}
		sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", stats);
		// if (!plan.getPlanstatus().equals("")) {
		// sql += " AND T.PLANSTATUS ='" + plan.getPlanstatus() + "'";
		// }
		if (index.equals("0")) {
			sql += " AND NVL(T.BESIDE_STATUS,'/') < NVL('" + dobeside
					+ "','/')";
		} else if (index.equals("1")) {
			sql += " AND NVL(T.BESIDE_STATUS,'/') >= NVL('" + dobeside
					+ "','/')";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);

		sql += "  ORDER BY T.PLANSTATUS DESC ) T3 ORDER BY T3.GX_PRO_SEQ,T3.PRO_PLAN_ID,T3.GX_PLAN_NO,T3.HEAT_PLAN_NO  ASC";
		return this.getData(sql);
	}

	/***
	 * 查询是否存在上料之后的数据
	 * 
	 * @param plan
	 * @return
	 */
	public CoreReturnObject getQueryInfoPlan(String gx, String planNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpLoading.getQueryInfoPlan");
		return this.getData(sql, new Object[] { gx, planNo });
	}

	/**
	 * 查询相同炉计划ID下的待上料支数的和
	 * 
	 * @param planNo
	 *            计划号
	 * @return
	 */
	public CoreReturnObject getquerymaternum(String heatno) {
		return this.getDataBySqlID("FrmVrpLoading.getquerymaternum",
				new Object[] { heatno });
	}

	/***
	 * 查询是否上料行
	 * 
	 * @param plan
	 * @return
	 */
	public CoreReturnObject getQueryOrderDbkS(String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpLoading.getQueryOrderDbkS");
		return this.getData(sql, new Object[] { plineCode, plineCode });
	}

	/***
	 *输入上料支数带出重量
	 * 
	 * @param plan
	 * @return
	 */
	public CoreReturnObject getQueryWeight(String numb, String judNo,
			String batchNo, String groupNo, String PlineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpLoading.getQueryWeight");
		return this.getData(sql, new Object[] { judNo, batchNo, groupNo,
				Integer.parseInt(numb) + 1 });
	}

	/**
	 * 每支材料对应的出库单号
	 * 
	 * @param conn
	 * @param strlist
	 *            出库类型
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public static String querySendOut(Connection conn, String strlist,
			String plineCode) throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmVrpLoading.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)
			throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmVrpLoading.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 load
	 * @return
	 */
	public CoreReturnObject saveLoadingResult(VrpLoadingResultEntity load,
			String hertNo, String hertSqe, String slgx, String plinCode,
			String groupNo) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
//		TZH 24.4.24 注销物流接口
//		Connection connection2 = this.getDao("TmsDao").getConnection();
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
		Calendar ca = Calendar.getInstance();
		ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(now);
		String systime1 = com.steering.common.StringTool.GetBalYear("120501");//改25号结转
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
//			TZH 24.4.24 注销物流接口
//			connection2.setAutoCommit(false); // 取消自动提交事务
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.AddVrpshangliao");// 新增上料实绩
			PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
			String sqlupdate = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.updatevrpshangliao");// 修改计划从表
			PreparedStatement patupdate = connection
					.prepareStatement(sqlupdate);
			String sqlupdatepln = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.updatePlnZyRclMpln");// 修改镦拔扩计划表
			PreparedStatement patupdatepln = connection
					.prepareStatement(sqlupdatepln);
			String addPlnInfo = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.AddComInfoResult");// 新增公共信息
			PreparedStatement patsPlan = connection
					.prepareStatement(addPlnInfo);
			String deleteButt = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.deleteButter");// 删除位置表
			PreparedStatement patsButt = connection
					.prepareStatement(deleteButt);
			String deleteMat = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.CopyBcMat");// 复制物料主表到MAT_BC_BACKUP表
			PreparedStatement patsMat = connection.prepareStatement(deleteMat);
			String addOut = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.AddOutList");// 新增出库记录投料出库
			PreparedStatement patsAddOut = connection.prepareStatement(addOut);
			String addOutlist = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.AddOutListQuan");// 新增出库记录产权出库
			PreparedStatement patsAddOutlist = connection
					.prepareStatement(addOutlist);
			String updateMat = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.updateMatZcPlan");// 修改MAT_BC_BACKUP状态
			PreparedStatement patsUpMat = connection
					.prepareStatement(updateMat);
			String addport = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.AddPortVrp");// 新增管号队列
			PreparedStatement patsport = connection.prepareStatement(addport);

			String updatePath = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.UpdatePath");// 修改队列表工艺路径
			PreparedStatement pastupdatePath = connection
					.prepareStatement(updatePath);
			String deteleBcMat = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.DeteleBcMat");// 删除物料主表
			PreparedStatement deteleBcMatPath = connection
					.prepareStatement(deteleBcMat);
			String updatePlan = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.UpdatePlnVrp");// 修改炉计划是否分批
			PreparedStatement updatePlanPath = connection
					.prepareStatement(updatePlan);

			String deleteYdmBack = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.deleteYdmBack");//
			PreparedStatement patsdeleteYdmBack = connection
					.prepareStatement(deleteYdmBack);

			String insertYdmBack = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.insertYdmBack");//
			PreparedStatement patsinsertYdmBack = connection
					.prepareStatement(insertYdmBack);

			List<MatBcMEntity> listMat = new ArrayList<MatBcMEntity>();
			// 获取镦拔扩计划实体类
			PlnZyDbkMEntity pln = PlanService.getSendDBKPlanCInfo(connection,
					load.getHeatPlanNo());
			// 获取镦拔扩计划从表实体类
			PlnZyDbkCEntity plnC = PlanService.getSendDBKPlanCInfoC(connection,
					load.getHeatPlanNo(), hertSqe);
			String judNo = pln.getFeedHeatNo();// 炉号

			String batchNo = plnC.getBatchNo();// 批号
			// String groupNo = pln.getBatchGroudNo();// 组号
			String userName = load.getLoadUser();// 创建人
			int count = Integer.parseInt(load.getProNum());// 上料支数
			if (pln == null)
				return core;
			if (!pln.getPlanstatus().equals("10")
					&& !pln.getPlanstatus().equals("20")) {
				core.setV_errMsg("该计划不是下发或生产中的状态！");
				return core;
			}
			String cutFalg = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询 工序是否是结炉状态
			PreparedStatement psta1 = connection.prepareStatement(sql);
			psta1.setString(1, hertNo);
			psta1.setString(2, plinCode);
			psta1.setString(3, slgx);
			ResultSet rs = psta1.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			}
			if (cutFalg.equals("2")) {
				core.setV_errMsg("已结炉,不允许此操作！");
				return core;
			}
			rs.close();
			psta1.close();

			String checkNoShort = "";
			String sqlloadingshort = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.queryCheckNoShort");// 产线基础表里的检验委托号
			psta = connection.prepareStatement(sqlloadingshort);
			psta.setObject(1, pln.getPlineCode());
			ResultSet rs2 = psta.executeQuery();
			if (rs2.next()) {
				checkNoShort = rs2.getString("CHECK_NO_SHORT");
			}
			rs2.close();
			psta.close();

			String resultNo = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.queryKEY");// 查询最大实绩编号
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, plinCode + slgx + matter1.format(dt));
			psta.setObject(2, matter.format(dt));
			psta.setObject(3, pln.getPlineCode());
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				resultNo = rs1.getString("RESULT_NO");
			}
			rs1.close();
			psta.close();

			String StorageNo = PlanService.GetStorageIn(pln.getPlineCode(),
					connection);

			String sqlMatNo = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.queryMatZc");// 查询新增物料信息
			psta = connection.prepareStatement(sqlMatNo);
			psta.setObject(1, plnC.getJugdeApplyCode());
			psta.setObject(2, judNo);
			psta.setObject(3, batchNo);
			psta.setObject(4, groupNo);
			psta.setObject(5, StorageNo);
			// psta.setObject(4, pln.getPlineCode());
			psta.setObject(6, count + 1);
			rs = psta.executeQuery();
			listMat = EntityTool.getEntitysByRs(rs, MatBcMEntity.class);
			rs.close();
			psta.close();

			String sendOut = querySendOut(connection, "800801", plinCode);
			// 获取出库流水号
			String butessMatNo = querySendOutList(connection, sendOut);
			int outNo = Integer.parseInt(butessMatNo.substring(butessMatNo
					.length() - 4, butessMatNo.length()));

			String sendOutlist = querySendOut(connection, "800809", plinCode);

			// 获取出库流水号
			String butessMatNolist = querySendOutList(connection, sendOutlist);
			int outNolist = Integer.parseInt(butessMatNolist.substring(
					butessMatNolist.length() - 4, butessMatNolist.length()));
			double wegth = 0;
			String gyPath = "";
			if (plinCode.equals("C018")) {// 720旋扩
				gyPath = "1-0-0-0-0-0-0";
			}
			// else if (plinCode.equals("C021")) {//镦粗
			// }
			// else if (plinCode.equals("C013")) {//冷轧
			// }
			// else if (plinCode.equals("C018")) {
			// }
			else {
				gyPath = "1-0-0-0-0";
			}

			if (listMat.size() != count) {
				core.setV_errMsg("库存不够,无法上足" + count + "支");
				return core;
			}

			int CountInstorage = 0;

			for (MatBcMEntity lvMat : listMat) {

				if (lvMat.getStorageNo().equals("")) {
					core.setV_errMsg("库存正在倒运中,无法上料!");
					return core;
				}

				if (!lvMat.getStorageNo().equals(StorageNo)) {
					if (pln.getIsLoadFlag().equals("1")) {
						patsdeleteYdmBack.setObject(1, pln.getPlineCode());
						patsdeleteYdmBack.setObject(2, lvMat.getMatNo());
						patsdeleteYdmBack.addBatch();
						patsdeleteYdmBack.executeBatch();

						patsinsertYdmBack.setObject(1, pln.getPlineCode());
						patsinsertYdmBack.setObject(2, lvMat.getMatNo());
						patsinsertYdmBack.addBatch();
						patsinsertYdmBack.executeBatch();

					} else {

						if (CountInstorage == 0) {
							core.setV_errMsg("库存未在投料库,无法上料");
							return core;
						} else {
							core.setV_errMsg("只有" + CountInstorage
									+ "支在投料库 ,无法上足" + count + "支");
							return core;
						}
					}

				}
				CountInstorage++;

				if ("1".equals(lvMat.getLockFlag())) {
					core.setV_errMsg("库存存在质量封锁料,无法上足" + count + "支");
					return core;
				}

				if ("1".equals(lvMat.getMngLockFlag())) {
					core.setV_errMsg("库存存在管理封锁料,无法上足" + count + "支");
					return core;
				}

				int count1 = 0;
				String sql3 = CoreXmlSqlParsersFactory
						.getSql("FrmVrpLoading.qureymatno");// 查询管号队列里的材料号
				PreparedStatement psta3 = connection.prepareStatement(sql3);
				psta3.setString(1, lvMat.getMatNo());
				psta3.setString(2, lvMat.getHeatPlanNo());
				ResultSet rs3 = psta3.executeQuery();
				while (rs3.next()) {
					count1 = Integer.parseInt(rs3.getString("COUNT"));
				}
				rs3.close();
				psta3.close();
				if (count1 != 0) {
					// 修改工艺路径
					pastupdatePath.setObject(1, "0");
					pastupdatePath.setObject(2, hertNo);
					pastupdatePath.setObject(3, lvMat.getMatNo());
					pastupdatePath.addBatch();
					pastupdatePath.executeBatch();

					wegth = Double.parseDouble(load.getProWt());
				} else {
					if (pln.getDecision().equals("C")) {
						wegth += Double.parseDouble(lvMat.getActWeight());
						// 新增管号队列
						patsport.setObject(1, load.getHeatPlanNo());
						patsport.setObject(2, lvMat.getMatNo());
						patsport.setObject(3, "");
						patsport.setObject(4, "");
						patsport.setObject(5, pln.getZyBatchId());
						patsport.setObject(6, "");
						patsport.setObject(7, pln.getPlineCode());
						patsport.setObject(8, pln.getPlineName());
						patsport.setObject(9, pln.getJudgeStoveNo());
						patsport.setObject(10, plnC.getBatchNo());
						patsport.setObject(11, groupNo);
						patsport.setObject(12, pln.getStoveNo());
						patsport.setObject(13, lvMat.getActDimater());
						patsport.setObject(14, lvMat.getActHeight());
						patsport.setObject(15, pln.getAimlength());
						patsport.setObject(16, lvMat.getActLenMin());
						patsport.setObject(17, lvMat.getActLenMax());
						patsport.setObject(18, lvMat.getActCount());
						patsport.setObject(19, lvMat.getActWeight());
						patsport.setObject(20, lvMat.getActTheoryWeight());
						// patsport.setObject(19, String.format("%.3f",
						// (Double.parseDouble(lvMat.getActWeight())*Double.parseDouble(pln.getAimlength())/Double.parseDouble(lvMat.getActLen()))));
						// patsport.setObject(20, String.format("%.3f",
						// (Double.parseDouble(lvMat.getActTheoryWeight())*Double.parseDouble(pln.getAimlength())/Double.parseDouble(lvMat.getActLen()))));
						patsport.setObject(21, slgx);
						patsport.setObject(22, "00");
						patsport.setObject(23, userName);
						patsport.setObject(24, load.getLoadShift());
						patsport.setObject(25, load.getLoadGroup());
						patsport.setObject(26, systime);
						patsport.setObject(27, gyPath);
						patsport.setObject(28, pln.getFlagStoveNo());
						// patsport.setObject(29,
						// "".endsWith(pln.getPic())?lvMat.getBatchNo():"");
						patsport.setObject(29, checkNoShort + "999");
						patsport.setObject(30, pln.getFeedHeatNo());
						patsport.setObject(31, hertSqe);
						patsport.setObject(32, systime1);
						patsport.addBatch();

						updatePlanPath.setObject(1, "1");
						updatePlanPath.setObject(2, pln.getHeatPlanNo());
						updatePlanPath.addBatch();

					} else {
						wegth += Double.parseDouble(lvMat.getActWeight());
						// 新增管号队列
						patsport.setObject(1, load.getHeatPlanNo());
						patsport.setObject(2, lvMat.getMatNo());
						patsport.setObject(3, "");
						patsport.setObject(4, "");
						patsport.setObject(5, pln.getZyBatchId());
						patsport.setObject(6, "");
						patsport.setObject(7, pln.getPlineCode());
						patsport.setObject(8, pln.getPlineName());
						patsport.setObject(9, pln.getJudgeStoveNo());
						patsport.setObject(10, plnC.getBatchNo());
						patsport.setObject(11, groupNo);
						patsport.setObject(12, pln.getStoveNo());
						patsport.setObject(13, lvMat.getActDimater());
						patsport.setObject(14, lvMat.getActHeight());
						// patsport.setObject(15, lvMat.getActLen());
						patsport.setObject(15, pln.getAimlength());
						patsport.setObject(16, lvMat.getActLenMin());
						patsport.setObject(17, lvMat.getActLenMax());
						patsport.setObject(18, lvMat.getActCount());
						patsport.setObject(19, lvMat.getActWeight());
						patsport.setObject(20, lvMat.getActTheoryWeight());// String
																			// .format("%.6f",d)
						// patsport.setObject(19, String.format("%.3f",
						// (Double.parseDouble(lvMat.getActWeight())*Double.parseDouble(pln.getAimlength())/Double.parseDouble(lvMat.getActLen()))));
						// patsport.setObject(20, String.format("%.3f",
						// (Double.parseDouble(lvMat.getActTheoryWeight())*Double.parseDouble(pln.getAimlength())/Double.parseDouble(lvMat.getActLen()))));
						patsport.setObject(21, slgx);
						patsport.setObject(22, "00");
						patsport.setObject(23, userName);
						patsport.setObject(24, load.getLoadShift());
						patsport.setObject(25, load.getLoadGroup());
						patsport.setObject(26, systime);
						patsport.setObject(27, gyPath);
						patsport.setObject(28, pln.getJudgeStoveNo());
						// patsport.setObject(29,
						// "".endsWith(pln.getPic())?lvMat.getBatchNo():"");
						patsport.setObject(29, "");
						patsport.setObject(30, pln.getFeedHeatNo());
						patsport.setObject(31, hertSqe);
						patsport.setObject(32, systime1);
						patsport.addBatch();

					}
				}
				patsport.executeBatch();
				updatePlanPath.executeBatch();

				// 新增出库表 投料出库
				patsAddOut.setObject(1, sendOut
						+ StringTool.formatDecimal(outNo, "0000"));
				patsAddOut.setObject(2, load.getHeatPlanNo());
				patsAddOut.setObject(3, sendOut);
				patsAddOut.setObject(4, "800801");
				patsAddOut.setObject(5, "投料出库");
				patsAddOut.setObject(6, lvMat.getMatNo());
				patsAddOut.setObject(7, lvMat.getJudgeStoveNo());
				patsAddOut.setObject(8, lvMat.getBatchNo());
				patsAddOut.setObject(9, lvMat.getBatchGroudNo());
				patsAddOut.setObject(10, lvMat.getMaterialNo());
				patsAddOut.setObject(11, lvMat.getMaterialName());
				patsAddOut.setObject(12, lvMat.getProduccode());
				patsAddOut.setObject(13, lvMat.getProducname());
				patsAddOut.setObject(14, lvMat.getStdCode());
				patsAddOut.setObject(15, lvMat.getStdName());
				patsAddOut.setObject(16, lvMat.getGradecode());
				patsAddOut.setObject(17, lvMat.getGradename());
				patsAddOut.setObject(18, lvMat.getSteelcode());
				patsAddOut.setObject(19, lvMat.getSteelname());
				patsAddOut.setObject(20, lvMat.getStdStyle());
				patsAddOut.setObject(21, lvMat.getStdStyleDesc());
				patsAddOut.setObject(22, lvMat.getSpecCode());
				patsAddOut.setObject(23, lvMat.getSpecName());
				patsAddOut.setObject(24, lvMat.getModelCode());
				patsAddOut.setObject(25, lvMat.getModelDesc());
				patsAddOut.setObject(26, lvMat.getPlineCode());
				patsAddOut.setObject(27, lvMat.getPlineName());
				patsAddOut.setObject(28, lvMat.getActDimater());
				patsAddOut.setObject(29, lvMat.getActHeight());
				patsAddOut.setObject(30, String.valueOf(lvMat.getActLen()));
				patsAddOut.setObject(31, lvMat.getActLenMin());
				patsAddOut.setObject(32, lvMat.getActLenMax());
				patsAddOut.setObject(33, String.valueOf(lvMat.getActCount()));
				patsAddOut.setObject(34, String.valueOf(lvMat.getActWeight()));
				patsAddOut.setObject(35, String.valueOf(lvMat
						.getActTheoryWeight()));
				patsAddOut.setObject(36, lvMat.getBelongCode());
				patsAddOut.setObject(37, lvMat.getBelongName());
				patsAddOut.setObject(38, lvMat.getStorageNo());
				patsAddOut.setObject(39, lvMat.getLocationNo());
				patsAddOut.setObject(40, lvMat.getLaryNo());
				patsAddOut.setObject(41, lvMat.getLocNo());
				patsAddOut.setObject(42, lvMat.getStorageAttr());
				patsAddOut.setObject(43, lvMat.getStorageAttrName());
				patsAddOut.setObject(44, lvMat.getStorageTypeNo());
				patsAddOut.setObject(45, lvMat.getStorageTypeName());
				patsAddOut.setObject(46, lvMat.getManagementNo());
				patsAddOut.setObject(47, lvMat.getManagementName());
				patsAddOut.setObject(48, systime);
				patsAddOut.setObject(49, lvMat.getProBc());
				patsAddOut.setObject(50, lvMat.getProBz());
				patsAddOut.setObject(51, systime);
				patsAddOut.setObject(52, load.getLoadShift());
				patsAddOut.setObject(53, load.getLoadGroup());
				patsAddOut.setObject(54, userName);
				patsAddOut.setObject(55, systime);
				patsAddOut.setObject(56, lvMat.getOrdPk());
				patsAddOut.setObject(57, lvMat.getOrdLnPk());
				patsAddOut.setObject(58, lvMat.getOrdLnDlyPk());
				patsAddOut.setObject(59, lvMat.getDepartmentCode());
				patsAddOut.setObject(60, lvMat.getDepartmentDesc());
				patsAddOut.setObject(61, lvMat.getOrderNo());
				patsAddOut.setObject(62, lvMat.getOrderSeq());
				patsAddOut.setObject(63, pln.getDeliveryNo());
				patsAddOut.setObject(64, "801401");
				patsAddOut.setObject(65, "80150105");
				patsAddOut.setObject(66, lvMat.getJudgeStdCode());
				patsAddOut.setObject(67, lvMat.getJudgeStdName());
				patsAddOut.setObject(68, pln.getZyBatchId());
				patsAddOut.setObject(69, lvMat.getStoveNo());
				patsAddOut.setObject(70, plinCode);
				patsAddOut.setObject(71, plinCode);
				patsAddOut.setObject(72, pln.getOrderNo() + "/"
						+ pln.getOrderSeq());
				patsAddOut.setObject(73, systime1);
				patsAddOut.setObject(74, lvMat.getProcessCdoe());
				patsAddOut.setObject(75, lvMat.getProcessDesc());
				patsAddOut.addBatch();
				outNo++;

				// 新增出库表 产权出库
				patsAddOutlist.setObject(1, sendOutlist
						+ StringTool.formatDecimal(outNolist, "0000"));
				patsAddOutlist.setObject(2, load.getHeatPlanNo());
				patsAddOutlist.setObject(3, sendOutlist);
				patsAddOutlist.setObject(4, "800809");
				patsAddOutlist.setObject(5, "产权出库");
				patsAddOutlist.setObject(6, lvMat.getMatNo());
				patsAddOutlist.setObject(7, lvMat.getJudgeStoveNo());
				patsAddOutlist.setObject(8, lvMat.getBatchNo());
				patsAddOutlist.setObject(9, lvMat.getBatchGroudNo());
				patsAddOutlist.setObject(10, lvMat.getMaterialNo());
				patsAddOutlist.setObject(11, lvMat.getMaterialName());
				patsAddOutlist.setObject(12, lvMat.getProduccode());
				patsAddOutlist.setObject(13, lvMat.getProducname());
				patsAddOutlist.setObject(14, lvMat.getStdCode());
				patsAddOutlist.setObject(15, lvMat.getStdName());
				patsAddOutlist.setObject(16, lvMat.getGradecode());
				patsAddOutlist.setObject(17, lvMat.getGradename());
				patsAddOutlist.setObject(18, lvMat.getSteelcode());
				patsAddOutlist.setObject(19, lvMat.getSteelname());
				patsAddOutlist.setObject(20, lvMat.getStdStyle());
				patsAddOutlist.setObject(21, lvMat.getStdStyleDesc());
				patsAddOutlist.setObject(22, lvMat.getSpecCode());
				patsAddOutlist.setObject(23, lvMat.getSpecName());
				patsAddOutlist.setObject(24, lvMat.getModelCode());
				patsAddOutlist.setObject(25, lvMat.getModelDesc());
				patsAddOutlist.setObject(26, lvMat.getPlineCode());
				patsAddOutlist.setObject(27, lvMat.getPlineName());
				patsAddOutlist.setObject(28, lvMat.getActDimater());
				patsAddOutlist.setObject(29, lvMat.getActHeight());
				patsAddOutlist.setObject(30, String.valueOf(lvMat.getActLen()));
				patsAddOutlist.setObject(31, lvMat.getActLenMin());
				patsAddOutlist.setObject(32, lvMat.getActLenMax());
				patsAddOutlist.setObject(33, String
						.valueOf(lvMat.getActCount()));
				patsAddOutlist.setObject(34, String.valueOf(lvMat
						.getActWeight()));
				patsAddOutlist.setObject(35, String.valueOf(lvMat
						.getActTheoryWeight()));
				patsAddOutlist.setObject(36, lvMat.getBelongCode());
				patsAddOutlist.setObject(37, lvMat.getBelongName());
				patsAddOutlist.setObject(38, lvMat.getStorageNo());
				patsAddOutlist.setObject(39, lvMat.getLocationNo());
				patsAddOutlist.setObject(40, lvMat.getLaryNo());
				patsAddOutlist.setObject(41, lvMat.getLocNo());
				patsAddOutlist.setObject(42, lvMat.getStorageAttr());
				patsAddOutlist.setObject(43, lvMat.getStorageAttrName());
				patsAddOutlist.setObject(44, lvMat.getStorageTypeNo());
				patsAddOutlist.setObject(45, lvMat.getStorageTypeName());
				patsAddOutlist.setObject(46, lvMat.getManagementNo());
				patsAddOutlist.setObject(47, lvMat.getManagementName());
				patsAddOutlist.setObject(48, systime);
				patsAddOutlist.setObject(49, lvMat.getProBc());
				patsAddOutlist.setObject(50, lvMat.getProBz());
				patsAddOutlist.setObject(51, systime);
				patsAddOutlist.setObject(52, load.getLoadShift());
				patsAddOutlist.setObject(53, load.getLoadGroup());
				patsAddOutlist.setObject(54, userName);
				patsAddOutlist.setObject(55, systime);
				patsAddOutlist.setObject(56, lvMat.getOrdPk());
				patsAddOutlist.setObject(57, lvMat.getOrdLnPk());
				patsAddOutlist.setObject(58, lvMat.getOrdLnDlyPk());
				patsAddOutlist.setObject(59, lvMat.getDepartmentCode());
				patsAddOutlist.setObject(60, lvMat.getDepartmentDesc());
				patsAddOutlist.setObject(61, lvMat.getOrderNo());
				patsAddOutlist.setObject(62, lvMat.getOrderSeq());
				patsAddOutlist.setObject(63, pln.getDeliveryNo());
				patsAddOutlist.setObject(64, "801401");
				patsAddOutlist.setObject(65, "80150105");
				patsAddOutlist.setObject(66, lvMat.getJudgeStdCode());
				patsAddOutlist.setObject(67, lvMat.getJudgeStdName());
				patsAddOutlist.setObject(68, pln.getZyBatchId());
				patsAddOutlist.setObject(69, lvMat.getStoveNo());
				patsAddOutlist.setObject(70, plinCode);
				patsAddOutlist.setObject(71, plinCode);
				patsAddOutlist.setObject(72, pln.getOrderNo() + "/"
						+ pln.getOrderSeq());
				patsAddOutlist.setObject(73, systime1);
				patsAddOutlist.setObject(74, lvMat.getProcessCdoe());
				patsAddOutlist.setObject(75, lvMat.getProcessDesc());
				patsAddOutlist.addBatch();
				outNolist++;
				// 修改库存状态
				patsUpMat.setObject(1, "80150105");
				patsUpMat.setObject(2, lvMat.getMatNo());
				patsUpMat.addBatch();

				// 删除位置表
				patsButt.setObject(1, lvMat.getMatNo());
				patsButt.addBatch();

				// 复制物料主表到bakeup表
				patsMat.setObject(1, lvMat.getMatNo());
				patsMat.addBatch();

				// 删除物料主表
				deteleBcMatPath.setObject(1, lvMat.getMatNo());
				deteleBcMatPath.addBatch();

			}
			patsport.executeBatch();
			patsAddOut.executeBatch();
			patsAddOutlist.executeBatch();
			patsButt.executeBatch();
			patsUpMat.executeBatch();
			patsMat.executeBatch();
			deteleBcMatPath.executeBatch();
			// 新增上料实绩
			patAdd.setObject(1, resultNo);
			patAdd.setObject(2, pln.getHeatPlanNo());
			patAdd.setObject(3, pln.getZyBatchId());
			patAdd.setObject(4, pln.getProPlanId());
			patAdd.setObject(5, pln.getGxPlanNo());
			patAdd.setObject(6, pln.getPlineCode());
			patAdd.setObject(7, pln.getPlineName());
			patAdd.setObject(8, load.getProNum());
			// patAdd.setObject(9, load.getProWt());
			patAdd.setObject(9, wegth);
			patAdd.setObject(10, load.getFailNum());
			patAdd.setObject(11, load.getFailWt());
			patAdd.setObject(12, load.getOfflineNum());
			patAdd.setObject(13, load.getOfflineWt());
			patAdd.setObject(14, load.getReNum());
			patAdd.setObject(15, load.getReWt());
			patAdd.setObject(16, "");// 监制要求
			patAdd.setObject(17, pln.getIfMonitor());
			patAdd.setObject(18, load.getProducer());
			patAdd.setObject(19, pln.getPrdcrNo());
			if (load.getProducer().equals("")) {
				patAdd.setObject(20, "");
			} else {
				patAdd.setObject(20, load.getProducerTime());
			}
			patAdd.setObject(21, load.getLoadTime());
			patAdd.setObject(22, load.getLoadShift());
			patAdd.setObject(23, load.getLoadGroup());
			patAdd.setObject(24, load.getLoadUser());
			patAdd.setObject(25, "1");
			patAdd.setObject(26, systime);
			patAdd.setObject(27, systime1);
			patAdd.addBatch();
			// 新增公共信息
			patsPlan.setObject(1, resultNo);
			patsPlan.setObject(2, pln.getHeatPlanNo());
			patsPlan.setObject(3, slgx);
			patsPlan.setObject(4, slgx);
			patsPlan.setObject(5, pln.getPlineCode());
			patsPlan.setObject(6, pln.getPlineName());
			patsPlan.setObject(7, pln.getZyBatchId());
			patsPlan.setObject(8, pln.getProPlanId());
			patsPlan.setObject(9, pln.getGxPlanNo());
			patsPlan.setObject(10, pln.getIfMonitor());
			patsPlan.setObject(11, pln.getPrdcrNo());
			patsPlan.setObject(12, "");// 监制要求
			patsPlan.setObject(13, load.getProducer());
			if (load.getProducer().equals("")) {
				patsPlan.setObject(14, "");
			} else {
				patsPlan.setObject(14, load.getProducerTime());
			}

			patsPlan.setObject(15, pln.getCraftFileNo());
			patsPlan.setObject(16, pln.getCraftFileMan());
			patsPlan.setObject(17, pln.getCraftSeq());
			patsPlan.setObject(18, pln.getJudgeStoveNo());
			patsPlan.setObject(19, plnC.getBatchNo());
			patsPlan.setObject(20, groupNo);// 组号
			patsPlan.setObject(21, pln.getGradecode());
			patsPlan.setObject(22, pln.getGradename());
			patsPlan.setObject(23, pln.getLengthIn());
			patsPlan.setObject(24, pln.getOutdiameterIn());
			patsPlan.setObject(25, pln.getAimlength());
			patsPlan.setObject(26, pln.getWallthickIn());
			patsPlan.setObject(27, pln.getLengthminIn());
			patsPlan.setObject(28, pln.getLengthmaxIn());
			patsPlan.setObject(29, pln.getLenCuthead());
			patsPlan.setObject(30, pln.getLenCutend());
			patsPlan.setObject(31, pln.getAimoutdiameter());
			patsPlan.setObject(32, pln.getAimwallthick());
			patsPlan.setObject(33, pln.getOutwlId());// 物料码
			patsPlan.setObject(34, pln.getOutwlDesc());
			patsPlan.setObject(35, pln.getInwlId());
			patsPlan.setObject(36, pln.getInwlDesc());
			patsPlan.setObject(37, load.getProNum());
			patsPlan.setObject(38, load.getProWt());
			patsPlan.setObject(39, load.getFailNum());
			patsPlan.setObject(40, load.getFailWt());
			patsPlan.setObject(41, load.getOfflineNum());
			patsPlan.setObject(42, load.getOfflineWt());
			patsPlan.setObject(43, load.getReNum());
			patsPlan.setObject(44, load.getReWt());
			patsPlan.setObject(45, "1");
			patsPlan.setObject(46, load.getLoadTime());
			patsPlan.setObject(47, "");
			patsPlan.setObject(48, load.getLoadUser());
			patsPlan.setObject(49, load.getLoadShift());
			patsPlan.setObject(50, load.getLoadGroup());
			patsPlan.setObject(51, systime);
			patsPlan.setObject(52, "");
			patsPlan.setObject(53, pln.getSteelcode());
			patsPlan.setObject(54, pln.getSteelname());
			patsPlan.setObject(55, pln.getSpecCode());
			patsPlan.setObject(56, pln.getSpecName());
			patsPlan.addBatch();
			// 修改计划从表实际上料支、吨
			patupdate.setObject(1, load.getProNum());
			// patupdate.setObject(2, load.getProWt());
			patupdate.setObject(2, wegth);
			patupdate.setObject(3, pln.getHeatPlanNo());
			patupdate.setObject(4, batchNo);
			patupdate.setObject(5, groupNo);
			patupdate.addBatch();
			// 修改计划主表状态
			patupdatepln.setObject(1, load.getHeatPlanNo());
			patupdatepln.addBatch();
			patAdd.executeBatch();
			patsPlan.executeBatch();
			patupdate.executeBatch();
			patupdatepln.executeBatch();

			// 更新运输需求上料时间
			FrmVrpInStore frmVrpInStore = new FrmVrpInStore();
//			TZH 24.4.24 注销物流接口
//			frmVrpInStore.updateTmsDemandMLoadTime(connection, connection2,
//					core, hertNo, "E");
			if (core.getV_errMsg().equals("")) {
				core.setV_errMsg("上料成功！");
			}

			// 财务系统接口数据处理
			// FmisTool.addBcOutList(connection,core,load.getHeatPlanNo(),resultNo,"E");

			core.setResult(1);
			connection.commit();
//			TZH 24.4.24 注销物流接口
//			connection2.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
//					TZH 24.4.24 注销物流接口
//					connection2.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
//			TZH 24.4.24 注销物流接口
//			if (connection2 != null) {
//				try {
//					connection.rollback(); // 回滚事务
//					connection2.rollback(); // 回滚事务
//				} catch (Exception e2) {
//				}
//			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
//				TZH 24.4.24 注销物流接口
//				if (connection2 != null && !connection2.isClosed()) {
//					connection2.close();
//				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 撤销上料
	 * 
	 * @param planNo
	 * @return
	 */
	public CoreReturnObject returnLoadingResult(ArrayList<String> list,
			String herPlanNo, String plinCode, String gx, String outnumcut,
			String groupNo) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
//		TZH 24.4.24 注销物流接口
//		Connection connection2 = this.getDao("TmsDao").getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM",
				Locale.CHINA);
		String systime = dateFormat.format(now);
		String systime1 = com.steering.common.StringTool.GetBalYear("120501"); //改25号结转
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
//			TZH 24.4.24 注销物流接口
//			connection2.setAutoCommit(false); // 取消自动提交事务
			String sqlDelete = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.ReturnVrpLoadingResult");// 删除上料实绩
			PreparedStatement patDelete = connection
					.prepareStatement(sqlDelete);
			String sqlupdate = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.deleteDbkPlanM");// 删除时修改镦拔扩计划表
			PreparedStatement patupdate = connection
					.prepareStatement(sqlupdate);
			String sqlupdateplnc = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.deleteDbkPlanC");// 删除时修改镦拔扩计划从表
			PreparedStatement patupdateplnc = connection
					.prepareStatement(sqlupdateplnc);
			String updatePlnInfo = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.deleteVrpResult");// 删除镦拔扩公共信息
			PreparedStatement patsupdatePlan = connection
					.prepareStatement(updatePlnInfo);
			String deleteButt = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.addButter");// 新增位置表
			PreparedStatement patsButt = connection
					.prepareStatement(deleteButt);
			String addOut = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.DeleteOutList");// 删除出库记录投料出库
			PreparedStatement patsDeleteOut = connection
					.prepareStatement(addOut);
			String addOutList = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.DeleteOutListQuan");// 删除出库记录产权出库
			PreparedStatement patsDeleteOutList = connection
					.prepareStatement(addOutList);
			String updateMat = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.updateMatZcPlanStuts");// 修改MAT_BC_BACKUP状态
			PreparedStatement patsUpMat = connection
					.prepareStatement(updateMat);
			String addport = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.DeletePortVrp");// 删除管号队列
			PreparedStatement patsport = connection.prepareStatement(addport);
			String addBackup = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.CopyBackup");// 复制MAT_BC_BACKUP表到物料主表
			PreparedStatement patsAddBackup = connection
					.prepareStatement(addBackup);
			String deteleBackup = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.DeteleBackup");// 删除MAT_BC_BACKUP表
			PreparedStatement deteleBackupPath = connection
					.prepareStatement(deteleBackup);
			String updatePlan = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.UpdatePlnVrp");// 修改炉计划是否分批
			PreparedStatement updatePlanPath = connection
					.prepareStatement(updatePlan);
			String sql4 = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.deleteFmis");// 删除财务系统接口数据
			PreparedStatement deleteFmis = connection.prepareStatement(sql4);
			// 获取镦拔扩计划实体类
			PlnZyDbkMEntity pln = PlanService.getSendDBKPlanCInfo(connection,
					herPlanNo);
			// 获取镦拔扩计划从表实体类
			PlnZyDbkCEntity plnC = PlanService.getSendDBKPlanCInfoC(connection,
					herPlanNo);
			if (pln == null)
				return core;
			if (!pln.getPlanstatus().equals("20")) {
				core.setV_errMsg("该计划不是生产中的状态！");
				return core;
			}

			// 获取热处理计划实体了
			PlnOrderDbkSEntity VrpOrder = PlanService.getDBKOrder(connection,
					pln.getProPlanId(), pln.getGxPlanNo());

			if (VrpOrder == null) {
				core.setV_errMsg("无订单计划！");
				return core;
			}

			if (!VrpOrder.getExeStatus().equals("0")
					&& !VrpOrder.getExeStatus().equals("1")) {
				core.setV_errMsg("订单处于生产完成/关闭状态,无法撤销上料实绩！");
				return core;
			}

			String cutFalg = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序是否是结炉状态
			PreparedStatement psta = connection.prepareStatement(sql);
			psta.setString(1, herPlanNo);
			psta.setString(2, plinCode);
			psta.setString(3, gx);
			ResultSet rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			}
			if (cutFalg.equals("2")) {
				core.setV_errMsg("已结炉,不允许此操作！");
				return core;
			}
			rs.close();
			psta.close();

			// for (int i = 0; i < list1.size(); i++) {
			// ArrayList<String> list = (ArrayList<String>) list1.get(i);
			String resNo = list.get(0);
			String judNo = list.get(1);
			String batchNo = plnC.getBatchNo();
			int count = Integer.parseInt(list.get(3));
			String userName = list.get(4);
			String userTime = list.get(5);

			// 财务系统接口数据处理
			// FmisTool.deleteBcOutList(connection,core,herPlanNo,resNo,"E");
			String SYNC_FLAG = "0";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.SelectSyncFlag");// 查询财务系统同步状态
			psta = connection.prepareStatement(sql);
			psta.setObject(1, judNo);
			psta.setObject(2, batchNo);
			psta.setObject(3, herPlanNo);
			psta.setObject(4, count);
			rs = psta.executeQuery();
			if (rs.next()) {
				SYNC_FLAG = rs.getString("SYNC_FLAG");
			}
			rs.close();
			psta.close();
			if (SYNC_FLAG.equals("1")) {
				core.setV_errMsg("财务系统同步出库信息，请联系财务撤销同步信息!");
				return core;
			}
			// 删除财务系统接口数据
			deleteFmis.setObject(1, judNo);
			deleteFmis.setObject(2, batchNo);
			deleteFmis.setObject(3, herPlanNo);
			deleteFmis.setObject(4, count);
			deleteFmis.addBatch();
			deleteFmis.executeBatch();

			List<YdmBcOutlistEntity> listOut = new ArrayList<YdmBcOutlistEntity>();
			String sqlMatNo = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.queryYdmOut");// 查询出库信息
			psta = connection.prepareStatement(sqlMatNo);
			psta.setObject(1, judNo);
			psta.setObject(2, batchNo);
			psta.setObject(3, herPlanNo);
			psta.setObject(4, count + 1);
			rs = psta.executeQuery();
			listOut = EntityTool.getEntitysByRs(rs, YdmBcOutlistEntity.class);
			rs.close();
			psta.close();

			if (listOut.size() != count) {
				core.setV_errMsg("数据异常,无法找到出库记录！");
				return core;
			}
			if (pln.getDecision().equals("C")) {
				updatePlanPath.setObject(1, "0");
				updatePlanPath.setObject(2, pln.getHeatPlanNo());
				updatePlanPath.addBatch();
				updatePlanPath.executeBatch();
			}

			for (YdmBcOutlistEntity lvMat : listOut) {
				PortVrpBatchSampleResultEntity PortVrpBatchSampleResultEntity = PlanService
						.getPortVrpBatchSampleResultEntity(herPlanNo, lvMat
								.getMatNo(), connection);

				if (!PortVrpBatchSampleResultEntity.getMatStatus().equals("00")) {
					core.setV_errMsg("后续工序已经做了离线操作或者剔除,无法撤销！");
					return core;
				}

				if (PortVrpBatchSampleResultEntity.getInstoreFlag().equals("1")) {
					core.setV_errMsg("有物料已经做了交库,无法撤销！");
					return core;
				}

				// 修改库存状态
				patsUpMat.setObject(1, "80150103");
				patsUpMat.setObject(2, lvMat.getMatNo());
				patsUpMat.addBatch();

				// 新增位置表
				patsButt.setObject(1, lvMat.getMatNo());
				patsButt.setObject(2, lvMat.getJudgeStoveNo());
				patsButt.setObject(3, lvMat.getBatchNo());
				patsButt.setObject(4, lvMat.getBatchGroudNo());
				patsButt.setObject(5, lvMat.getStorageNo());
				patsButt.setObject(6, lvMat.getLocationNo());
				patsButt.setObject(7, lvMat.getLaryNo());
				patsButt.setObject(8, lvMat.getLocNo());
				patsButt.setObject(9, lvMat.getStorageAttr());
				patsButt.setObject(10, lvMat.getStorageAttrName());
				patsButt.setObject(11, lvMat.getStorageTypeNo());
				patsButt.setObject(12, lvMat.getStorageTypeName());
				patsButt.setObject(13, lvMat.getManagementNo());
				patsButt.setObject(14, lvMat.getManagementName());
				patsButt.setObject(15, userName);
				patsButt.setObject(16, userTime);
				patsButt.setObject(17, lvMat.getDepartmentCode());
				patsButt.setObject(18, lvMat.getDepartmentDesc());
				patsButt.addBatch();
				String OutlistMonth = "";
				String sqlqueryplan = CoreXmlSqlParsersFactory
						.getSql("FrmVrpLoading.OutlistMonth");// 查询出库表结算日期
				psta = connection.prepareStatement(sqlqueryplan);
				psta.setObject(1, lvMat.getOutstockSqe());
				rs = psta.executeQuery();
				if (rs.next()) {
					OutlistMonth = rs.getString("BAL_YEAR_MONTH");
				}
				rs.close();
				psta.close();
				if (!OutlistMonth.equals(systime1)) {
					core.setV_errMsg("上料结算日期和撤销上料结算日期不在同一个月，不允许撤销上料!");
					return core;
				}
				// 删除出库表投料出库
				patsDeleteOut.setObject(1, lvMat.getOutstockSqe());
				patsDeleteOut.addBatch();

				// 删除出库表产权出库
				patsDeleteOutList.setObject(1, lvMat.getMatNo());
				patsDeleteOutList.setObject(2, herPlanNo);
				patsDeleteOutList.addBatch();

				// 删除管号队列
				patsport.setObject(1, herPlanNo);
				patsport.setObject(2, lvMat.getMatNo());
				patsport.addBatch();

				// 复制backup表到物料主表
				patsAddBackup.setObject(1, lvMat.getMatNo());
				patsAddBackup.addBatch();

				// 删除backup表
				deteleBackupPath.setObject(1, lvMat.getMatNo());
				deteleBackupPath.addBatch();

			}
			patsUpMat.executeBatch();
			patsButt.executeBatch();
			patsDeleteOut.executeBatch();
			patsport.executeBatch();
			patsAddBackup.executeBatch();
			deteleBackupPath.executeBatch();
			/*
			 * List<YdmBcOutlistEntity> listOutlist = new
			 * ArrayList<YdmBcOutlistEntity>(); String sqlMatNolist =
			 * CoreXmlSqlParsersFactory
			 * .getSql("FrmVrpLoading.queryYdmOutlist");// 查询出库信息产权出库 psta =
			 * connection.prepareStatement(sqlMatNolist); psta.setObject(1,
			 * judNo); psta.setObject(2, batchNo); psta.setObject(3, herPlanNo);
			 * psta.setObject(4, count + 1); rs = psta.executeQuery();
			 * listOutlist = EntityTool.getEntitysByRs(rs,
			 * YdmBcOutlistEntity.class); rs.close(); psta.close(); for
			 * (YdmBcOutlistEntity lvMatlist : listOutlist) { // 删除出库表产权出库
			 * patsDeleteOutList.setObject(1, lvMatlist.getOutstockSqe());
			 * patsDeleteOutList.addBatch(); }
			 */
			patsDeleteOutList.executeBatch();

			// 删除上料实绩
			patDelete.setObject(1, resNo);
			patDelete.addBatch();
			// 删除上料公共信息
			patsupdatePlan.setObject(1, resNo);
			patsupdatePlan.addBatch();

			patDelete.executeBatch();
			patsupdatePlan.executeBatch();
			// 查询计划下剩余上料支、吨
			int countS = 0;
			double weghit = 0;
			int num = 0;
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.queryCountVrp");// 查询计划下剩余上料支、吨
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, herPlanNo);
			rs = psta.executeQuery();
			while (rs.next()) {
				countS = Integer.parseInt(rs.getString("COUN"));
				if (countS != 0) {
					weghit = Double.parseDouble(rs.getString("PRO_WT"));
					num = Integer.parseInt(rs.getString("PRO_NUM"));
				}
			}
			rs.close();
			psta.close();

			patupdateplnc.setObject(1, num);
			patupdateplnc.setObject(2, weghit);
			patupdateplnc.setObject(3, herPlanNo);
			patupdateplnc.setObject(4, judNo);
			patupdateplnc.setObject(5, batchNo);
			patupdateplnc.setObject(6, groupNo);
			patupdateplnc.addBatch();
			patupdateplnc.executeBatch();

			int pronum = 0;
			String sqlqueryplan = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.querypronum");// 查询计划从表上料支数和
			psta = connection.prepareStatement(sqlqueryplan);
			psta.setObject(1, herPlanNo);
			rs = psta.executeQuery();
			while (rs.next()) {
				pronum = Integer.parseInt(rs.getString("PRO_NUM"));
			}
			rs.close();
			psta.close();

			if (countS == 0 && pronum == 0) {
				patupdate.setObject(1, "00");
				patupdate.setObject(2, herPlanNo);
				patupdate.addBatch();
			} else if (countS == 0) {
				patupdate.setObject(1, "10");
				patupdate.setObject(2, herPlanNo);
				patupdate.addBatch();
			}
			patupdate.executeBatch();

			// 更新运输需求上料时间
			FrmVrpInStore frmVrpInStore = new FrmVrpInStore();
//			TZH 24.4.24 注销物流接口
//			frmVrpInStore.updateTmsDemandMLoadTime(connection, connection2,
//					core, herPlanNo, "E");
			if (core.getV_errMsg().equals("")) {
				core.setV_errMsg("撤销上料成功！");
			}
			core.setResult(1);
			connection.commit();
//			TZH 24.4.24 注销物流接口
//			connection2.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
//					TZH 24.4.24 注销物流接口
//					connection2.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
//			TZH 24.4.24 注销物流接口
//			if (connection2 != null) {
//				try {
//					connection.rollback(); // 回滚事务
//					connection2.rollback(); // 回滚事务
//				} catch (Exception e2) {
//				}
//			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
//				TZH 24.4.24 注销物流接口
//				if (connection2 != null && !connection2.isClosed()) {
//					connection2.close();
//				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 查询上料实绩支数总和
	 * 
	 * @param planNo
	 *            计划号
	 * @return
	 */
	public CoreReturnObject getLoadResult1(String heatNo) {
		return this.getDataBySqlID("FrmVrpLoading.GetQuery1",
				new Object[] { heatNo });
	}

	/**
	 * 根据计划号查询镦拔扩上料实绩
	 * 
	 * @param planNo
	 *            计划号
	 * @return
	 */
	public CoreReturnObject getLoadResult(String heatNo) {
		return this.getDataBySqlID("FrmVrpLoading.GetQuery",
				new Object[] { heatNo });
	}

	/***
	 * 结炉
	 * 
	 * @param zYgNo
	 * @return
	 */
	public CoreReturnObject updateDoBeside(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.doBeside");// 修改工序状态为结炉
			PreparedStatement updateSqlPsta = connection
					.prepareStatement(updateSql);
			String updatePln = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.doPlnBeside");// 修改计划表结炉状态
			PreparedStatement updatePlnPsta = connection
					.prepareStatement(updatePln);
			String updateMatNo = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.updateMatNoStuts");// 修改材料表
			PreparedStatement updatePstaMatNo = connection
					.prepareStatement(updateMatNo);
			// int count = 0;
			String cutFalg = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			psta.setString(2, parm.get(1));
			psta.setString(3, parm.get(2));
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			} else {
				cro.setV_errMsg("无当前工序实绩,无法进行结炉!");
				return cro;
			}
			if (cutFalg.equals("2")) {
				cro.setV_errMsg("已结炉,不允许此操作！");
				return cro;
			}
			rs.close();
			psta.close();
			updateSqlPsta.setString(1, parm.get(0));
			updateSqlPsta.setString(2, parm.get(1));
			updateSqlPsta.setString(3, parm.get(2));
			updateSqlPsta.addBatch();

			// 修改计划结炉状态
			updatePlnPsta.setObject(1, "00");
			updatePlnPsta.setObject(2, parm.get(0));
			updatePlnPsta.addBatch();

			// 修改材料表状态
			updatePstaMatNo.setObject(1, parm.get(3));
			updatePstaMatNo.setObject(2, parm.get(4));
			updatePstaMatNo.setObject(3, parm.get(5));
			updatePstaMatNo.setObject(4, parm.get(6));
			// updatePstaMatNo.setObject(5, parm.get(1));
			// updatePstaMatNo.addBatch();
			updateSqlPsta.executeBatch();
			updatePlnPsta.executeBatch();
			// updatePstaMatNo.executeBatch();
			cro.setV_errMsg("结炉成功！");
			connection.commit();
		} 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 zYgNo
	 * @return
	 */
	public CoreReturnObject undoBeside(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.deleteBeside");// 修改工序状态撤销结炉
			PreparedStatement updateSqlPsta = connection
					.prepareStatement(updateSql);
			String updatePln = CoreXmlSqlParsersFactory
					.getSql("FrmVrpLoading.doPlnBeside");// 修改计划表结炉状态
			PreparedStatement updatePlnPsta = connection
					.prepareStatement(updatePln);

			String cutFalg1 = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			psta.setString(2, parm.get(1));
			psta.setObject(3, Integer.parseInt(parm.get(2)) + 1);
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg1 = rs.getString("STATION_STATUS");
			}
			if (cutFalg1.equals("2")) {
				cro.setV_errMsg("下一道工序没有撤销结炉,不允许此工序撤销结炉!");
				return cro;
			}
			rs.close();
			psta.close();
			String cutFalg = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			psta.setString(2, parm.get(1));
			psta.setString(3, parm.get(2));
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			} else {
				cro.setV_errMsg("无当前工序实绩,无法进行结炉!");
				return cro;
			}
			if (cutFalg.equals("1")) {
				cro.setV_errMsg("未结炉,不允许此操作！");
				return cro;
			}
			rs.close();
			psta.close();

			updateSqlPsta.setString(1, parm.get(0));
			updateSqlPsta.setString(2, parm.get(1));
			updateSqlPsta.setString(3, parm.get(2));
			updateSqlPsta.addBatch();

			// 修改计划结炉状态
			updatePlnPsta.setObject(1, "");
			updatePlnPsta.setObject(2, parm.get(0));
			updatePlnPsta.addBatch();
			updatePlnPsta.executeBatch();
			updateSqlPsta.executeBatch();

			cro.setV_errMsg("撤销结炉成功!");
			connection.commit();
		} 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 load
	 * @return
	 */
	public CoreReturnObject offLineExpandResult(ArrayList<String> list,
			String plinCode, String groupNo) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyyMMdd");
		Calendar ca = Calendar.getInstance();
		ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(now);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String addOff = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.AddOffLine");// 新增离线实绩
			PreparedStatement patAdd = connection.prepareStatement(addOff);
			String MarkOff = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.MarkUnCancelFlag");// 标记之前同炉批组返线的离线实绩为无法撤销数据
			PreparedStatement patMarkOff = connection.prepareStatement(MarkOff);

			// String addIn = CoreXmlSqlParsersFactory
			// .getSql("FrmVrpExpandResult.AddYdmInList");// 新增入库信息
			// PreparedStatement patIn = connection.prepareStatement(addIn);
			String updateMat = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.UpdateMatNo");// 修改材料状态
			PreparedStatement patMatNo = connection.prepareStatement(updateMat);

			String updatePath = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.UpdatePathPortVrp");// 修改队列表工艺路径,材料，工序状态
			PreparedStatement pastupdatePath = connection
					.prepareStatement(updatePath);

			String heatPlanNo = list.get(0);
			String slgx = list.get(1);
			String slgxname = list.get(2);
			String name = list.get(3);
			String time = list.get(4);
			String bc = list.get(5);
			String bz = list.get(6);
			String count = list.get(7);
			String judge = list.get(8);
			String batch = list.get(9);
			String txtMemo = list.get(10);

			int num = 0;
			int num1 = 0;
			int num2 = 0;
			if (plinCode.equals("C018")) {
				if (slgx.equals("650101")) {
					num = 0;
					num1 = 0;
					num2 = 2;
				} else if (slgx.equals("650102")) {
					num = 1;
					num1 = 2;
					num2 = 4;
				} else if (slgx.equals("650103")) {
					num = 1;
					num1 = 4;
					num2 = 6;
				} else if (slgx.equals("650104")) {
					num = 1;
					num1 = 6;
					num2 = 8;
				} else if (slgx.equals("650105")) {
					num = 1;
					num1 = 8;
					num2 = 10;
				} else if (slgx.equals("650106")) {
					num = 1;
					num1 = 10;
					num2 = 12;
				} else if (slgx.equals("650107")) {
					num = 1;
					num1 = 12;
					num2 = 14;
				}

			} else if (plinCode.equals("C021")) {
				if (slgx.equals("650401")) {
					num = 0;
					num1 = 0;
					num2 = 2;
				} else if (slgx.equals("650402")) {
					num = 1;
					num1 = 2;
					num2 = 4;
				} else if (slgx.equals("650403")) {
					num = 1;
					num1 = 4;
					num2 = 6;
				} else if (slgx.equals("650404")) {
					num = 1;
					num1 = 6;
					num2 = 8;
				} else if (slgx.equals("650405")) {
					num = 1;
					num1 = 8;
					num2 = 10;
				}
			} else if (plinCode.equals("C014")) {
				if (slgx.equals("650501")) {
					num = 0;
					num1 = 0;
					num2 = 2;
				} else if (slgx.equals("650502")) {
					num = 1;
					num1 = 2;
					num2 = 4;
				} else if (slgx.equals("650503")) {
					num = 1;
					num1 = 4;
					num2 = 6;
				} else if (slgx.equals("650504")) {
					num = 1;
					num1 = 6;
					num2 = 8;
				} else if (slgx.equals("650505")) {
					num = 1;
					num1 = 8;
					num2 = 10;
				}
			} else if (plinCode.equals("C013")) {
				if (slgx.equals("650601")) {
					num = 0;
					num1 = 0;
					num2 = 2;
				} else if (slgx.equals("650602")) {
					num = 1;
					num1 = 2;
					num2 = 4;
				} else if (slgx.equals("650603")) {
					num = 1;
					num1 = 4;
					num2 = 6;
				} else if (slgx.equals("650604")) {
					num = 1;
					num1 = 6;
					num2 = 8;
				} else if (slgx.equals("650605")) {
					num = 1;
					num1 = 8;
					num2 = 10;
				}
			} else if (plinCode.equals("C070")) {
				if (slgx.equals("650701")) {
					num = 0;
					num1 = 0;
					num2 = 2;
				} else if (slgx.equals("650702")) {
					num = 1;
					num1 = 2;
					num2 = 4;
				} else if (slgx.equals("650703")) {
					num = 1;
					num1 = 4;
					num2 = 6;
				} else if (slgx.equals("650704")) {
					num = 1;
					num1 = 6;
					num2 = 8;
				} else if (slgx.equals("650705")) {
					num = 1;
					num1 = 8;
					num2 = 10;
				}
			}

			// 获取镦拔扩计划实体类
			PlnZyDbkMEntity pln = PlanService.getSendDBKPlanCInfo(connection,
					heatPlanNo);
			// 获取镦拔扩计划实体类
			PlnZyDbkCEntity plnC = PlanService.getSendDBKPlanCInfoC(connection,
					heatPlanNo);
			if (pln == null)
				return core;
			// if (!pln.getPlanstatus().equals("2")) {
			// core.setV_errMsg("该计划不是生产中的，请确认是否生产完成或未上料！");
			// return core;
			// }
			String cutFalg = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序结炉状态
			PreparedStatement psta1 = connection.prepareStatement(sql);
			psta1.setString(1, heatPlanNo);
			psta1.setString(2, plinCode);
			psta1.setString(3, slgx);
			ResultSet rs = psta1.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			}
			if (cutFalg.equals("2")) {
				core.setV_errMsg("已结炉,不允许此操作！");
				return core;
			}
			rs.close();
			psta1.close();
			List<PortVrpBatchSampleResultEntity> matNo = new ArrayList<PortVrpBatchSampleResultEntity>();
			String sqlloading1 = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.queryPortVrpHg");// 查询管号队列里合格的材料号
			psta = connection.prepareStatement(sqlloading1);
			psta.setObject(1, heatPlanNo);
			psta.setObject(2, judge);
			psta.setObject(3, batch);
			psta.setObject(4, groupNo);
			psta.setObject(5, Integer.parseInt(count) + 1);
			ResultSet rs2 = psta.executeQuery();
			matNo = EntityTool.getEntitysByRs(rs2,
					PortVrpBatchSampleResultEntity.class);
			rs2.close();
			psta.close();
			if (matNo == null) {
				core.setV_errMsg("管号队列全为样管，不能离线！");
				return core;
			}
			int batchCount = 0;
			sqlloading1 = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.queryPortVrpBatchHg");// 查询管号队列里不是样管的合格支
			psta = connection.prepareStatement(sqlloading1);
			psta.setObject(1, heatPlanNo);
			rs2 = psta.executeQuery();
			if (rs2.next()) {
				batchCount = Integer.parseInt(rs2.getString("ACT_COUNT"));
			}
			rs2.close();
			psta.close();
			if (batchCount < Integer.parseInt(count)) {
				core.setV_errMsg("管号队列材料未交库合格支数不足,请重新输入离线支数！");
				return core;
			}
			String inListDoc = querySendSqlDoc(connection, "800708", "LX");// 入库单号
			String A = querySendSql(connection, inListDoc);
			int g = Integer.parseInt(A.substring(A.length() - 4, A.length()));

			String actdimater = "";
			String actheight = "";
			String actlen = "";
			String actlenmin = "";
			String actlenmax = "";

			String resultNo = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmVrpExpandResult.queryOffMaxRESULT");// 查询离线最大实绩编号
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, plinCode + slgx + "L" + matter1.format(dt));
			psta.setObject(2, matter.format(dt));
			psta.setObject(3, pln.getPlineCode());
			psta.setObject(4, plinCode + slgx + "L" + matter1.format(dt));
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				resultNo = rs1.getString("RESULT_NO");
			}
			rs1.close();
			psta.close();

			int countNum = 0;
			double weightNum = 0;
			for (PortVrpBatchSampleResultEntity prot : matNo) {
				countNum += Integer.parseInt(prot.getActCount());
				weightNum += Double.parseDouble(prot.getActWeight());
				// 修改管号队列状态
				pastupdatePath.setObject(1, num);
				pastupdatePath.setObject(2, num1);
				pastupdatePath.setObject(3, "2");
				pastupdatePath.setObject(4, num2);
				pastupdatePath.setObject(5, "20");
				pastupdatePath.setObject(6, "10");
				pastupdatePath.setObject(7, slgx);
				pastupdatePath.setObject(8, resultNo);
				pastupdatePath.setObject(9, heatPlanNo);
				pastupdatePath.setObject(10, prot.getMatNo());
				pastupdatePath.addBatch();

				// 修改材料表状态
				patMatNo.setObject(1, "80150104");
				// patMatNo.setObject(2, "11");
				patMatNo.setObject(2, prot.getMatNo());
				patMatNo.addBatch();
				// // 新增入库表数据
				// patIn.setObject(1, inListDoc
				// + StringTool.formatDecimal(g, "0000"));
				// patIn.setObject(2, inListDoc);
				// patIn.setObject(3, "800708");
				// patIn.setObject(4, "离线入库");
				// patIn.setObject(5, "");
				// patIn.setObject(6, prot.getMatNo());
				// patIn.setObject(7, "");
				// patIn.setObject(8, "");
				// patIn.setObject(9, prot.getJudgeStoveNo());
				// patIn.setObject(10, prot.getBatchNo());
				// patIn.setObject(11, prot.getGroupNo());
				// patIn.setObject(12, "");
				// patIn.setObject(13, "");
				// patIn.setObject(14, "");
				// patIn.setObject(15, "");
				// patIn.setObject(16, "");
				// patIn.setObject(17, "");
				// patIn.setObject(18, pln.getGradecode());
				// patIn.setObject(19, pln.getGradename());
				// patIn.setObject(20, "");
				// patIn.setObject(21, "");
				// patIn.setObject(22, "");
				// patIn.setObject(23, "");
				// patIn.setObject(24, "");
				// patIn.setObject(25, "");
				// patIn.setObject(26, "");
				// patIn.setObject(27, "");
				// patIn.setObject(28, "");
				// patIn.setObject(29, pln.getPlineCode());
				// patIn.setObject(30, pln.getPlineName());
				// patIn.setObject(31, prot.getActDimater());
				// patIn.setObject(32, prot.getActHeight());
				// patIn.setObject(33, prot.getActLen());
				// patIn.setObject(34, prot.getActLenMin());
				// patIn.setObject(35, prot.getActLenMax());
				// patIn.setObject(36, prot.getActCount());
				// patIn.setObject(37, prot.getActWeight());
				// patIn.setObject(38, prot.getActTheoryWeight());
				// patIn.setObject(39, "");// 组织
				// patIn.setObject(40, "");
				// patIn.setObject(41, storageNo);//
				// patIn.setObject(42, storageNo + "10101");
				// patIn.setObject(43, "");
				// patIn.setObject(44, "");
				// patIn.setObject(45, storageAtte);
				// patIn.setObject(46, storageAtteName);
				// patIn.setObject(47, storageType);
				// patIn.setObject(48, storageTypeName);
				// patIn.setObject(49, managNo);
				// patIn.setObject(50, managName);
				// patIn.setObject(51, time);
				// patIn.setObject(52, bc);
				// patIn.setObject(53, bz);
				// patIn.setObject(54, time);
				// patIn.setObject(55, bc);
				// patIn.setObject(56, bz);
				// patIn.setObject(57, "");
				// patIn.setObject(58, name);
				// patIn.setObject(59, time);
				// if(pln.getOrdLnDlyPk()==""||pln.getOrdLnDlyPk()==null)
				// {
				// patIn.setObject(60, "");// 合同pK
				// patIn.setObject(61, "");
				// }else
				// {
				// patIn.setObject(60, pln.getOrdLnDlyPk().substring(0,
				// pln.getOrdLnDlyPk().length() - 6));// 合同pK
				// patIn.setObject(61, pln.getOrdLnDlyPk().substring(0,
				// pln.getOrdLnDlyPk().length() - 3));
				// }
				// patIn.setObject(62, pln.getOrdLnDlyPk());
				// patIn.setObject(63, depNo);
				// patIn.setObject(64, depName);
				// patIn.setObject(65, pln.getOrderNo());// 合同号
				// patIn.setObject(66, pln.getOrderSeq());
				// patIn.setObject(67, pln.getDeliveryNo());
				// patIn.setObject(68, "801401");
				// patIn.setObject(69, "80150104");
				// patIn.setObject(70, "");
				// patIn.setObject(71, "");
				// patIn.setObject(72, time);
				// patIn.setObject(73, "");
				// patIn.setObject(74, "");
				// patIn.setObject(75, "");
				// patIn.setObject(76, "");
				// patIn.setObject(77, "");
				// patIn.setObject(78, "");
				// patIn.setObject(79, "");
				// patIn.setObject(80, "");
				// patIn.setObject(81, "1");
				// patIn.addBatch();
				// g++;
				judge = prot.getJudgeStoveNo();
				batch = prot.getBatchNo();
				actdimater = prot.getActDimater();
				actheight = prot.getActHeight();
				actlen = prot.getActLen();
				actlenmin = prot.getActLenMin();
				actlenmax = prot.getActLenMax();
			}
			pastupdatePath.executeBatch();
			// patIn.executeBatch();
			patMatNo.executeBatch();

			for (PortVrpBatchSampleResultEntity lvMat : matNo) {
				// 新增离线实绩
				patAdd.setObject(1, resultNo);
				patAdd.setObject(2, heatPlanNo);
				patAdd.setObject(3, slgx);
				patAdd.setObject(4, slgx);
				patAdd.setObject(5, pln.getPlineCode());
				patAdd.setObject(6, pln.getPlineName());
				patAdd.setObject(7, pln.getZyBatchId());
				patAdd.setObject(8, pln.getProPlanId());
				patAdd.setObject(9, pln.getGxPlanNo());

				patAdd.setObject(10, judge);
				patAdd.setObject(11, batch);
				patAdd.setObject(12, pln.getProduccode());
				patAdd.setObject(13, pln.getProducname());
				patAdd.setObject(14, pln.getSteelcode());
				patAdd.setObject(15, pln.getSteelname());
				patAdd.setObject(16, pln.getGradecode());
				patAdd.setObject(17, pln.getGradename());
				patAdd.setObject(18, pln.getModelCode());
				patAdd.setObject(19, pln.getModelDesc());
				patAdd.setObject(20, pln.getStdCode());
				patAdd.setObject(21, pln.getStdName());
				patAdd.setObject(22, pln.getStdStyle());
				patAdd.setObject(23, pln.getStdStyleDesc());
				patAdd.setObject(24, pln.getAimoutdiameter());
				patAdd.setObject(25, pln.getAimwallthick());
				patAdd.setObject(26, actlen);
				patAdd.setObject(27, actlenmin);
				patAdd.setObject(28, actlenmax);

				patAdd.setObject(29, countNum);
				patAdd.setObject(30, weightNum);
				patAdd.setObject(31, time);
				patAdd.setObject(32, name);
				patAdd.setObject(33, bc);
				patAdd.setObject(34, bz);
				patAdd.setObject(35, pln.getOrdLnDlyPk());
				patAdd.setObject(36, pln.getOrderNo());
				patAdd.setObject(37, pln.getOrderSeq());
				patAdd.setObject(38, pln.getDeliveryNo());
				patAdd.setObject(39, groupNo);
				patAdd.setObject(40, pln.getFlagStoveNo());
				patAdd.setObject(41, txtMemo);
				patAdd.setObject(42, pln.getFeedHeatNo());

				// 如果有废品新增到材料表
				if (!count.equals("") && !count.equals("0")) {

					PlanService.AddOffLineMatWithResultNo(connection, "E",
							name, "11", lvMat.getMatNo(), slgx, heatPlanNo,
							resultNo);
				}
			}

			patMarkOff.setObject(1, pln.getHeatPlanNo());
			patMarkOff.setObject(2, pln.getJudgeStoveNo());
			patMarkOff.setObject(3, batch);
			patMarkOff.setObject(4, groupNo);
			patMarkOff.setObject(5, slgx);
			patMarkOff.addBatch();
			patMarkOff.executeBatch();

			patAdd.addBatch();
			patAdd.executeBatch();

			core.setV_errMsg("离线成功！");
			core.setResult(1);
			connection.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 每支材料对应的入库单号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSqlDoc(Connection conn, String strlist, String memo)
			throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat matter2 = new SimpleDateFormat("yyMMdd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmVrpExpandResult.getInListDoc");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, memo);
		psta.setString(2, matter2.format(dt));
		psta.setString(3, matter1.format(dt));
		psta.setString(4, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("INSTOCK_DOC");
		}
		rs.close();
		psta.close();
		return seq;
	}

	/**
	 * 每支材料对应的入库流水号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSql(Connection conn, String strlist)
			throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmVrpExpandResult.getInListDoc1");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("INSTOCK_SQE");
		}
		rs.close();
		psta.close();
		return seq;
	}

}
