package com.steering.mes.mcp.heatTreatment;

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.StringTool;
import com.steering.common.EntityTool;
import com.steering.mes.mcp.Mch.FrmMcpLoading;
import com.steering.mes.mcp.common.OfflineHelper;
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.sql.SQLException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/***
 * 离线管理
 * 
 * @author TJG 2016/09/27
 */
public class FrmHttDownLineManage extends DBCommon {
	/**
	 * 离线查询
	 * 
	 * @param list
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryOffLine(ArrayList<String> list,
			String[] plineCode) {

		String sql = "";
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.doQueryOffLine");
		if (!list.get(0).equals("")) {
			sql += "  AND T.PRO_TIME BETWEEN TO_DATE('" + list.get(0)
					+ "','YYYY-MM-DD HH24:MI:SS') " + " AND TO_DATE('"
					+ list.get(1) + "','YYYY-MM-DD HH24:MI:SS')";
		}
		if (!list.get(2).equals("")) {
			sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '" + list.get(2)
					+ "' || '%'";
		}
		if (!list.get(3).equals("")) {
			sql += " AND T.ZY_BATCH_ID || '&' LIKE '%' || '" + list.get(3)
					+ "' || '%'";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);
		if (!list.get(4).equals("")) {
			sql += " AND T.STATION_CODE ='" + list.get(4) + "'";
		}
		if (list.get(5).equals("0")) {
			sql += " AND T1.PLANSTATUS <> '40' ";
		}else if(list.get(5).equals("1")){
			sql += " AND T1.PLANSTATUS = '40' ";
		}
		return this.getData(sql);
	}

	/**
	 * 离线查询
	 * 
	 * @param list
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryOffLine(ArrayList<String> list,
			String plineCode) {

		String sql = "";
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.doQueryOffLine");
		if (!list.get(0).equals("")) {
			sql += "  AND T.PRO_TIME BETWEEN TO_DATE('" + list.get(0)
					+ "','YYYY-MM-DD HH24:MI:SS') " + " AND TO_DATE('"
					+ list.get(1) + "','YYYY-MM-DD HH24:MI:SS')";
		}
		if (!list.get(2).equals("")) {
			sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '" + list.get(2)
					+ "' || '%'";
		}
		if (!list.get(3).equals("")) {
			sql += " AND T.ZY_BATCH_ID || '&' LIKE '%' || '" + list.get(3)
					+ "' || '%'";
		}

		if (!plineCode.equals("")) {

			sql += " AND T.PLINE_CODE= '" + plineCode + "'";
		}

		if (!list.get(4).equals("")) {
			sql += " AND T.STATION_CODE ='" + list.get(4) + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 查询工序点
	 * 
	 * @param list
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQuery(String sortCode) {

		String sql = "";
		sql = CoreXmlSqlParsersFactory.getSql("FrmHttDownLineManage.doQuery");
		return this.getData(sql, new Object[] { sortCode });
	}

	/**
	 * 查询工序点
	 * 
	 * @param list
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryGX(String plineCode) {

		String sql = "";
		sql = CoreXmlSqlParsersFactory.getSql("FrmHttDownLineManage.doQueryGX");
		return this.getData(sql, new Object[] { plineCode });
	}

	/**
	 * 组炉实绩查询
	 * 
	 * @param list
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryOffLineGroup(ArrayList<String> list,
			String[] plineCode) {

		String sql = "";
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.doQueryOffLineGroup");
		if (!list.get(0).equals("")) {
			sql += "  AND T.PRO_TIME BETWEEN TO_DATE('" + list.get(0)
					+ "','YYYY-MM-DD HH24:MI:SS') " + " AND TO_DATE('"
					+ list.get(1) + "','YYYY-MM-DD HH24:MI:SS')";
		}
		if (!list.get(2).equals("")) {
			sql += " AND (T.JUDGE_STOVE_NO LIKE '"
					+ list.get(2)
					+ "' || '%'  OR  EXISTS (SELECT 1 FROM HTT_GROUP_RESULT WHERE JUDGE_STOVE_NO LIKE '"
					+ list.get(2) + "%'  AND GROUP_ID =T.GROUP_ID))";
		}
		if (!list.get(3).equals("")) {
			sql += " AND T.ZY_BATCH_ID || '&' LIKE '%' || '" + list.get(3)
					+ "' || '%'";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);
		if (!list.get(4).equals("")) {
			sql += " AND T.STATION_CODE ='" + list.get(4) + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 组炉实绩查询
	 * 
	 * @return
	 */
	public CoreReturnObject doQueryOffGroupDetail(String[] GroupId) {

		String sql = "";
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.QueryGroupHttResult");
		sql += CoreConverter.toSqlConditionString("T.GROUP_ID", GroupId);
		return this.getData(sql);
	}

	/**
	 * 返线实绩查询
	 * 
	 * @param list
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryReturnLine(ArrayList<String> list,
			String[] plineCode) {

		String sql = "";
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.doQueryReturnLine");
		if (!list.get(0).equals("")) {
			sql += "  AND T.RE_TIME BETWEEN TO_DATE('" + list.get(0)
					+ "','YYYY-MM-DD HH24:MI:SS') " + " AND TO_DATE('"
					+ list.get(1) + "','YYYY-MM-DD HH24:MI:SS')";
		}
		if (!list.get(2).equals("")) {
			sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '" + list.get(2)
					+ "' || '%'";
		}
		if (!list.get(3).equals("")) {
			sql += " AND T.ZY_BATCH_ID || '&' LIKE '%' || '" + list.get(3)
					+ "' || '%'";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);
		if (!list.get(4).equals("")) {
			sql += " AND T.STATION_CODE ='" + list.get(4) + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 委外实绩查询
	 * 
	 * @param list
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryOutSourc(ArrayList<String> list,
			String[] plineCode) {

		String sql = "";
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.doQueryOutSourc");
		if (!list.get(0).equals("")) {
			sql += "  AND T.SUBCONTRACT_TIME BETWEEN TO_DATE('" + list.get(0)
					+ "','YYYY-MM-DD HH24:MI:SS') " + " AND TO_DATE('"
					+ list.get(1) + "','YYYY-MM-DD HH24:MI:SS')";
		}
		if (!list.get(2).equals("")) {
			sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '" + list.get(2)
					+ "' || '%'";
		}
		if (!list.get(3).equals("")) {
			sql += " AND T.ZY_BATCH_ID || '&' LIKE '%' || '" + list.get(3)
					+ "' || '%'";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);
		if (!list.get(4).equals("")) {
			sql += " AND T.SUBCONTRACT_LOG ='" + list.get(4) + "'";
		}
		return this.getData(sql);
	}

	/***
	 * 查询合同信息
	 * 
	 * @param orderNo
	 * @return
	 */
	public CoreReturnObject getOrder(String plineCode, String proId,
			String gxPlanId, String orderNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.getOrder");
		return this.getData(sql, new Object[] { plineCode, proId, gxPlanId,
				orderNo });
	}

	/**
	 * 脱单
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject doTake(ArrayList<String> parm, String userName) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		int acount = 0;

		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertSql = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.insertVrpTakeReslut");// 插入脱单实绩表,脱单,回写PLN_ORDER_ZG_S
			PreparedStatement insertPsta = connection
					.prepareStatement(insertSql);

			for (String str : parm) {
				VrpOfflineResultEntity milOfflineEntity = EntityTool
						.getEntityByJSONStr(str, VrpOfflineResultEntity.class);

				// 查询是否已脱单
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.doQueryTake");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milOfflineEntity.getJudgeStoveNo());
				psta.setString(2, milOfflineEntity.getZyBatchId());
				psta.setString(3, milOfflineEntity.getStationCode());
				psta.setString(4, milOfflineEntity.getProPlanId());
				psta.setString(5, milOfflineEntity.getGxPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				// sql = CoreXmlSqlParsersFactory
				// .getSql("FrmVrpDownLineManage.doQueryTake2");
				// psta = connection.prepareStatement(sql);
				// psta.setString(1, milOfflineEntity.getJudgeStoveNo());
				// psta.setString(2, milOfflineEntity.getLotNo());
				// psta.setString(3, milOfflineEntity.getPlineCode());
				// rs = psta.executeQuery();
				// if (rs.next()) {
				// acount += Integer.parseInt(rs.getString("ACOUNT"));
				// }
				rs.close();
				psta.close();
				if (acount != 0) {
					cro.setV_errMsg("此炉已脱单,不可再次脱单!");
					return cro;
				}

				if (milOfflineEntity.getProPlanId().equals("")) {
					cro.setV_errMsg("此炉已脱单,不可再次脱单!");
					return cro;
				}

				insertPsta.setString(1, milOfflineEntity.getJudgeStoveNo());
				insertPsta.setString(2, milOfflineEntity.getStationCode());
				insertPsta.setString(3, milOfflineEntity.getPlineCode());
				insertPsta.setString(4, userName);
				insertPsta.addBatch();
			}
			insertPsta.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 result
	 * @return
	 */
	public CoreReturnObject doFurnace(ArrayList<String> parm,
			ArrayList<String> parm1, ArrayList<String> parm2) {
		CoreReturnObject cor = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyMMdd");
		String systime = dateFormat.format(now);
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String addOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.AddOffLineResu");// 新增修改离线表组炉记录
			PreparedStatement pstaAddOff = con.prepareStatement(addOff);
			// String updatePort = CoreXmlSqlParsersFactory
			// .getSql("FrmHttDownLineManage.UpdatePortVrp");// 修改管号队列表
			// PreparedStatement pstaUpdatePort =
			// con.prepareStatement(updatePort);
			String updateOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdateOffLineResu");// 修改离线表，新增组炉履历表
			PreparedStatement pstaUpdateOff = con.prepareStatement(updateOff);

			String updateMatFlagStoveNo = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.updateMatFlagStoveNo");// 修改离线数据标识炉号
			PreparedStatement pstaUpdateMatFlagStoveNo = con
					.prepareStatement(updateMatFlagStoveNo);

			String zlJusNo = parm2.get(0);
			String lotNo = parm2.get(1);
			String name = parm2.get(2);
			String bc = parm2.get(4);
			String bz = parm2.get(3);
			String zlBatchNo = ""; // 组炉批号

			String sqlCheck = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.queryHttM");
			psta = con.prepareStatement(sqlCheck);
			psta.setObject(1, zlJusNo);
			rs = psta.executeQuery();
			if (rs.next()) {

				throw new Exception("组炉炉号重复,不允许组炉!");
			}
			rs.close();
			psta.close();

			HttOfflineResultEntity tity = EntityTool.getEntityByJSONStr(parm1
					.get(0).toString(), HttOfflineResultEntity.class);
			String groupId = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.QueryGroupResult");// 查询组操作Id
			psta = con.prepareStatement(sql);
			psta.setString(1, dateFormat2.format(now));
			psta.setString(2, dateFormat1.format(now));
			rs = psta.executeQuery();
			if (rs.next()) {
				groupId = rs.getString("GROUP_ID");
			}
			rs.close();
			psta.close();

			String PlineCodeFlag = PlanService.GetPlineCodeFlag(con, tity
					.getPlineCode());
			if(lotNo.equals("") || null == lotNo ){
				zlBatchNo = PlineCodeFlag + "001";
			}else{
				zlBatchNo = lotNo;
			}

			int groupXh = 01;
			int totalCount = 0;// 组炉总支数
			double totalWeight = 0;// 组炉总重量
			for (String str : parm) {
				HttOfflineResultEntity vrpOfflineEntity = EntityTool
						.getEntityByJSONStr(str.toString(),
								HttOfflineResultEntity.class);
				int count = 0;
				String offgroupId = "";// 离线组炉Id
				String groupStart = "";// 组炉状态
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.QueryOffLineGroupStart");// 查询是否组炉
				psta = con.prepareStatement(sql);
				psta.setString(1, vrpOfflineEntity.getJudgeStoveNo());
				psta.setString(2, vrpOfflineEntity.getBatchNo());
				psta.setString(3, vrpOfflineEntity.getResultNo());
				psta.setString(4, vrpOfflineEntity.getHeatPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					offgroupId = rs.getString("GROUP_ID");
					groupStart = rs.getString("GROUP_LOG");
					count = Integer.parseInt(rs.getString("COUNT_NUM"));
				}
				rs.close();
				psta.close();
				if (offgroupId != null) {
					if (!offgroupId.equals("")) {
						cor.setV_errMsg("此炉已组炉!");
						return cor;
					}
				}
				if (groupStart.equals("1")) {
					cor.setV_errMsg("此炉是组炉炉号,不允许组炉!");
					return cor;
				}

				if (Integer.parseInt(vrpOfflineEntity.getOfflineBranch()) > count) {
					cor.setV_errMsg("此炉组炉支数大于离线支数,不允许组炉!");
					return cor;
				}
				DecimalFormat df = new DecimalFormat("0.000");
				double weight = (Double.parseDouble(vrpOfflineEntity
						.getOfflineWt()) / Integer.parseInt(vrpOfflineEntity
						.getOfflineNum()))
						* Integer.parseInt(vrpOfflineEntity.getOfflineBranch());
				String weight1 = df.format(weight);
				totalCount += Integer.parseInt(vrpOfflineEntity
						.getOfflineBranch());
				totalWeight += Double.parseDouble(weight1);

				// 修改离线数据标识炉号
				pstaUpdateMatFlagStoveNo.setObject(1, zlJusNo);
				pstaUpdateMatFlagStoveNo.setObject(2, vrpOfflineEntity
						.getJudgeStoveNo());
				pstaUpdateMatFlagStoveNo.setObject(3, vrpOfflineEntity.getBatchNo());
				pstaUpdateMatFlagStoveNo.setObject(4, "F");
				pstaUpdateMatFlagStoveNo.setObject(5, vrpOfflineEntity
						.getOfflineBranch());
				pstaUpdateMatFlagStoveNo.addBatch();
				// 修改组炉支数
				pstaUpdateOff.setObject(1, vrpOfflineEntity.getOfflineBranch());
				pstaUpdateOff.setObject(2, String.valueOf(weight1));
				pstaUpdateOff.setObject(3, systime);
				pstaUpdateOff.setObject(4, name);
				pstaUpdateOff.setObject(5, vrpOfflineEntity.getResultNo());
				// 新增组炉履历表
				pstaUpdateOff.setObject(6, groupId);
				pstaUpdateOff.setObject(7, StringTool.formatDecimal(groupXh,
						"00"));
				pstaUpdateOff.setObject(8, zlJusNo);// 组炉炉号
				pstaUpdateOff.setObject(9, zlBatchNo);// 组炉批号
				pstaUpdateOff.setObject(10, vrpOfflineEntity.getJudgeStoveNo());
				pstaUpdateOff.setObject(11, vrpOfflineEntity.getBatchNo());
				pstaUpdateOff
						.setObject(12, vrpOfflineEntity.getOfflineBranch());
				pstaUpdateOff.setObject(13, String.valueOf(weight1));// 重量
				pstaUpdateOff.setObject(14, name);
				pstaUpdateOff.setObject(15, bc);
				pstaUpdateOff.setObject(16, bz);
				pstaUpdateOff.setObject(17, systime);
				pstaUpdateOff.setObject(18, vrpOfflineEntity.getResultNo());
				pstaUpdateOff.addBatch();
				groupXh++;
			}
			pstaUpdateOff.executeBatch();
			pstaUpdateMatFlagStoveNo.executeBatch();

			String resultNo = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("AppearanceService.queryOffMaxRESULT1");// 查询离线最大实绩编号
			psta = con.prepareStatement(sqlloading);
			psta.setObject(1, tity.getPlineCode() + tity.getStationCode() + "L"
					+ dateFormat2.format(now));
			psta.setObject(2, tity.getPlineCode() + tity.getStationCode() + "L"
					+ dateFormat2.format(now));
			rs = psta.executeQuery();
			if (rs.next()) {
				resultNo = rs.getString("RESULT_NO");
			}
			rs.close();
			psta.close();

			// 新增离线实绩表
			pstaAddOff.setObject(1, resultNo);
			pstaAddOff.setObject(2, tity.getPlineCode());
			pstaAddOff.setObject(3, tity.getPlineName());
			pstaAddOff.setObject(4, tity.getStationCode());
			pstaAddOff.setObject(5, tity.getStationDesc());
			pstaAddOff.setObject(6, "");// 炉计划
			pstaAddOff.setObject(7, tity.getZyBatchId());// 生产批号
			pstaAddOff.setObject(8, tity.getProPlanId());
			pstaAddOff.setObject(9, tity.getGxPlanNo());
			pstaAddOff.setObject(10, zlJusNo);// 组炉炉号
			pstaAddOff.setObject(11, zlBatchNo);// 批号
			pstaAddOff.setObject(12, tity.getProduccode());
			pstaAddOff.setObject(13, tity.getProducname());
			pstaAddOff.setObject(14, tity.getSteelcode());
			pstaAddOff.setObject(15, tity.getSteelname());
			pstaAddOff.setObject(16, tity.getGradecode());
			pstaAddOff.setObject(17, tity.getGradename());
			pstaAddOff.setObject(18, tity.getModelCode());
			pstaAddOff.setObject(19, tity.getModelDesc());
			pstaAddOff.setObject(20, tity.getStdCode());
			pstaAddOff.setObject(21, tity.getStdName());
			pstaAddOff.setObject(22, tity.getStdStyle());
			pstaAddOff.setObject(23, tity.getStdStyleDesc());
			pstaAddOff.setObject(24, tity.getActDimater());
			pstaAddOff.setObject(25, tity.getActHeight());
			pstaAddOff.setObject(26, tity.getActLen());
			pstaAddOff.setObject(27, tity.getActLenMin());
			pstaAddOff.setObject(28, tity.getActLenMax());
			pstaAddOff.setObject(29, tity.getJudgeStoveNo());
			pstaAddOff.setObject(30, tity.getBatchNo());
			pstaAddOff.setObject(31, totalCount);
			pstaAddOff.setObject(32, totalWeight);
			pstaAddOff.setObject(33, name);
			pstaAddOff.setObject(34, bc);
			pstaAddOff.setObject(35, bz);
			pstaAddOff.setObject(36, systime);
			pstaAddOff.setObject(37, groupId);
			pstaAddOff.setObject(38, tity.getOrdLnDlyPk());
			pstaAddOff.setObject(39, tity.getOrderNo());
			pstaAddOff.setObject(40, tity.getOrderSeq());
			pstaAddOff.setObject(41, tity.getDeliveryNo());
			pstaAddOff.setObject(42, tity.getHeatPlanNo());
			pstaAddOff.setObject(43, tity.getBatchGroudNo());
			pstaAddOff.setObject(44, tity.getProcessSeq());
			pstaAddOff.addBatch();
			pstaAddOff.executeBatch();
			cor.setV_errMsg("组炉成功！");
			con.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (con != null) {
				try {
					cor.setV_errMsg(e.getMessage());
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return cor;
	}

	/**
	 * 撤销组炉
	 * 
	 * @param result
	 * @return
	 */
	public CoreReturnObject doCancelFurnace(ArrayList<String> parm) {
		CoreReturnObject cor = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		// Date now = new Date();
		// SimpleDateFormat dateFormat = new SimpleDateFormat(
		// "yyyy-MM-dd HH:mm:ss");
		// String systime = dateFormat.format(now);
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String addDelete = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.DeleteOffLineResu");// 删除离线表组炉记录
			PreparedStatement pstaAddDelete = con.prepareStatement(addDelete);
			String updateOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.DaeleteGroupResu");// 修改离线表，删除组炉履历表
			PreparedStatement pstaUpdateOff = con.prepareStatement(updateOff);
			String updateMatFlagStoveNo = CoreXmlSqlParsersFactory
			.getSql("FrmHttDownLineManage.updateMatFlagStoveNo");// 修改离线数据标识炉号
	PreparedStatement pstaUpdateMatFlagStoveNo = con
			.prepareStatement(updateMatFlagStoveNo);

			for (String str : parm) {
				HttOfflineResultEntity vrpOfflineEntity = EntityTool
						.getEntityByJSONStr(str.toString(),
								HttOfflineResultEntity.class);

				if (!vrpOfflineEntity.getSubcontractNum().equals("")
						&& !vrpOfflineEntity.getSubcontractNum().equals("0")) {
					cor.setV_errMsg("此组炉已经做过委托,不允许此操作!");
					return cor;
				}

				int count = 0;
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.QueryOffLineGroupId");// 查询组炉信息
				psta = con.prepareStatement(sql);
				psta.setString(1, vrpOfflineEntity.getResultNo());
				psta.setString(2, vrpOfflineEntity.getGroupId());
				rs = psta.executeQuery();
				if (rs.next()) {
					count = Integer.parseInt(rs.getString("COUNT"));
				}
				rs.close();
				psta.close();
				if (count == 0) {
					cor.setV_errMsg("此组炉信息已撤销,不允许此操作!");
					return cor;
				}
				int remCount = 0;// 返线支数
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.QueryOffLineGroupStart");// 查询是否组炉
				psta = con.prepareStatement(sql);
				psta.setString(1, vrpOfflineEntity.getJudgeStoveNo());
				psta.setString(2, vrpOfflineEntity.getBatchNo());
				psta.setString(3, vrpOfflineEntity.getResultNo());
				psta.setString(4, vrpOfflineEntity.getHeatPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					remCount = Integer.parseInt(rs.getString("RE_NUM"));
				}
				rs.close();
				psta.close();
				if (remCount == 0) {
					cor.setV_errMsg("此炉已返线!");
					return cor;
				}
				List<HttGroupResultEntity> list = new ArrayList<HttGroupResultEntity>();
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.QueryGroupVrpResult");// 查询组炉履历表信息
				psta = con.prepareStatement(sql);
				psta.setString(1, vrpOfflineEntity.getGroupId());
				rs = psta.executeQuery();
				list = EntityTool
						.getEntitysByRs(rs, HttGroupResultEntity.class);
				rs.close();
				psta.close();
				for (HttGroupResultEntity groupList : list) {

					// 修改离线数据标识炉号
					pstaUpdateMatFlagStoveNo.setObject(1, groupList.getJudgeStoveNo());
					pstaUpdateMatFlagStoveNo.setObject(2, groupList.getJudgeStoveNo());
					pstaUpdateMatFlagStoveNo.setObject(3, groupList.getBatchNo());
					pstaUpdateMatFlagStoveNo.setObject(4, "F");
					pstaUpdateMatFlagStoveNo.setObject(5, groupList.getGroupNum());
					pstaUpdateMatFlagStoveNo.addBatch();
					// 修改组炉支数
					pstaUpdateOff.setObject(1, groupList.getGroupNum());
					pstaUpdateOff.setObject(2, groupList.getGroupWt());
					pstaUpdateOff.setObject(3, "");
					pstaUpdateOff.setObject(4, "");
					pstaUpdateOff.setObject(5, groupList.getLxResultNo());
					// 删除组炉履历表
					pstaUpdateOff.setObject(6, groupList.getGroupId());
					pstaUpdateOff.setObject(7, groupList.getGroupXh());
					pstaUpdateOff.addBatch();
					
				}
				pstaUpdateOff.executeBatch();
				pstaUpdateMatFlagStoveNo.executeBatch();

				pstaAddDelete.setObject(1, vrpOfflineEntity.getResultNo());
				pstaAddDelete.setObject(2, vrpOfflineEntity.getGroupId());
				pstaAddDelete.addBatch();

			}
			pstaAddDelete.executeBatch();

			cor.setV_errMsg("撤销组炉成功！");
			con.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (con != null) {
				try {
					cor.setV_errMsg(e.getMessage());
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return cor;
	}

	/**
	 * 在线改判
	 * 
	 * @param result
	 * @return
	 */
	public CoreReturnObject doOnlineComm(ArrayList<String> parm,
			ArrayList<String> parm1) {
		CoreReturnObject cor = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String systime = dateFormat.format(now);
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String updateOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdateOffLineComm");// 修改离线表数据（改判）
			PreparedStatement pstaUpdateOff = con.prepareStatement(updateOff);

			String name = parm1.get(2);
			for (String str : parm) {
				HttOfflineResultEntity vrpOfflineEntity = EntityTool
						.getEntityByJSONStr(str.toString(),
								HttOfflineResultEntity.class);
				int count = 0;
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.QueryOffLineGroupStart");// 查询是否组炉
				psta = con.prepareStatement(sql);
				psta.setString(1, vrpOfflineEntity.getJudgeStoveNo());
				psta.setString(2, vrpOfflineEntity.getBatchNo());
				psta.setString(3, vrpOfflineEntity.getResultNo());
				psta.setString(4, vrpOfflineEntity.getHeatPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					count = Integer.parseInt(rs.getString("RE_NUM"));
				}
				rs.close();
				psta.close();
				if (count == 0) {
					cor.setV_errMsg("已返线,不允许改判！");
					return cor;
				}
				// 在线改判
				pstaUpdateOff.setObject(1, vrpOfflineEntity.getProduccode());
				pstaUpdateOff.setObject(2, vrpOfflineEntity.getProducname());
				pstaUpdateOff.setObject(3, vrpOfflineEntity.getSteelcode());
				pstaUpdateOff.setObject(4, vrpOfflineEntity.getSteelname());
				pstaUpdateOff.setObject(5, vrpOfflineEntity.getModelCode());
				pstaUpdateOff.setObject(6, vrpOfflineEntity.getModelDesc());
				pstaUpdateOff.setObject(7, vrpOfflineEntity.getStdCode());
				pstaUpdateOff.setObject(8, vrpOfflineEntity.getStdName());
				pstaUpdateOff.setObject(9, vrpOfflineEntity.getStdStyle());
				pstaUpdateOff.setObject(10, vrpOfflineEntity.getStdStyleDesc());
				pstaUpdateOff.setObject(11, vrpOfflineEntity.getActDimater());
				pstaUpdateOff.setObject(12, vrpOfflineEntity.getActHeight());
				pstaUpdateOff.setObject(13, vrpOfflineEntity.getActLen());
				pstaUpdateOff.setObject(14, vrpOfflineEntity.getOrdLnDlyPk());
				pstaUpdateOff.setObject(15, vrpOfflineEntity.getOrderNo());
				pstaUpdateOff.setObject(16, vrpOfflineEntity.getOrderSeq());
				pstaUpdateOff.setObject(17, vrpOfflineEntity.getDeliveryNo());
				pstaUpdateOff.setObject(18, systime);
				pstaUpdateOff.setObject(19, name);
				pstaUpdateOff.setObject(20, vrpOfflineEntity.getProPlanId());
				pstaUpdateOff.setObject(21, vrpOfflineEntity.getGxPlanNo());
				pstaUpdateOff.setObject(22, vrpOfflineEntity.getResultNo());
				pstaUpdateOff.addBatch();
			}
			pstaUpdateOff.executeBatch();
			cor.setV_errMsg("在线改判成功！");
			con.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (con != null) {
				try {
					cor.setV_errMsg(e.getMessage());
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return cor;
	}

	/**
	 * 根据炉号、批号自动生成材料号
	 * 
	 * @param conn
	 *            c
	 * @param strLcode
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String queryMatNoM(Connection conn, String strLcode, String strBatch)
			throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.queryMatNoM");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strLcode);
		psta.setString(2, strBatch);
		psta.setString(3, strLcode);
		psta.setString(4, strBatch);
		psta.setString(5, strLcode);
		psta.setString(6, strBatch);
		psta.setString(7, strLcode);
		psta.setString(8, strBatch);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("MAT_NO");
		}
		rs.close();
		psta.close();
		return seq;
	}

	/**
	 * 获取最大计划编号
	 * 
	 * @param conn
	 *            c
	 * @throws Exception
	 *             异常处理
	 */
	public static String queryPlanMaxNo(Connection conn) throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.queryPlanMaxNo");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, matter1.format(dt));
		psta.setString(2, matter.format(dt));
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("HEAT_PLAN_NO");
		}
		rs.close();
		psta.close();
		return seq;
	}

	/**
	 * 获计划状态
	 * 
	 * @param conn
	 *            c
	 * @throws Exception
	 *             异常处理
	 */
	public static String queryPlnZYDbkStrat(Connection conn, String heraNo)
			throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.doQueryPlanStrat");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, heraNo);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("PLANSTATUS");
		}
		rs.close();
		psta.close();
		return seq;
	}

	/**
	 *返线
	 * 
	 * @param result
	 * @return
	 */
	public CoreReturnObject doReturnLine(ArrayList<String> parm,
			ArrayList<String> parm1) {
		CoreReturnObject cor = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyMMdd");
		String systime = dateFormat.format(now);
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		
		String yearMoth = "";//改25号结转
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			/*
			 * String addOff = CoreXmlSqlParsersFactory
			 * .getSql("FrmHttDownLineManage.AddReturnResu");// 新增热处理计划表
			 * PreparedStatement pstaAddOff = con.prepareStatement(addOff);
			 * String addOffC = CoreXmlSqlParsersFactory
			 * .getSql("FrmHttDownLineManage.AddReturnResuC");// 新增热处理计划从表
			 * PreparedStatement pstaAddOffC = con.prepareStatement(addOffC);
			 */
			String updatePort = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdatePortVrpReturn");// 修改管号队列表
			PreparedStatement pstaUpdatePort = con.prepareStatement(updatePort);
			String updatePort1 = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.RestBatchInfo");// 修改管号队列表
			PreparedStatement pstaUpdatePort1 = con
					.prepareStatement(updatePort1);

			String BackUpBatchInfo = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.BackUpBatchInfo");// 修改管号队列表
			PreparedStatement pstaBackUpBatchInfo = con
					.prepareStatement(BackUpBatchInfo);

			String CancelBeside = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.doCancelBeside2");// 修改管号队列表
			PreparedStatement pstaCancelBeside = con
					.prepareStatement(CancelBeside);

			String addPort = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.AddPortVrpReturn");// 新增管号队列表
			PreparedStatement pstaAddPort = con.prepareStatement(addPort);
			/*
			 * String updateMat = CoreXmlSqlParsersFactory
			 * .getSql("FrmHttDownLineManage.UpdateMatReturn");// 修改材料表
			 * PreparedStatement pstaUpdateMat =
			 * con.prepareStatement(updateMat);
			 */

			String updateOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdateOff");// 修改离线表返线支数
			PreparedStatement pstaupdateOff = con.prepareStatement(updateOff);

			String UpdateHeatPlanID = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdateHeatPlanID");// 修改离线表返线支数
			PreparedStatement pstaUpdateHeatPlanID = con
					.prepareStatement(UpdateHeatPlanID);

			String deteleOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.deleteOfflineD");// 返线后删除离线记录
			PreparedStatement pstadeteleOff = con.prepareStatement(deteleOff);
			String updateStatus = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdateStatus");// 修改组炉返线材料状态30

			/*
			 * String updatePlnStatus = CoreXmlSqlParsersFactory
			 * .getSql("FrmHttDownLineManage.UpdatePlanStatus");//
			 * PreparedStatement pupdatePlnStatus =
			 * con.prepareStatement(updatePlnStatus);
			 */

			String updatePln = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.doPlnBeside");// 修改计划表结炉状态
			PreparedStatement updatePlnPsta = con.prepareStatement(updatePln);

			PreparedStatement pstaupdateStatus = con
					.prepareStatement(updateStatus);

			String plineCode = parm1.get(0);
			yearMoth = com.steering.common.StringTool.GetBalYear(com.steering.common.StringTool.GetSupplyUnit(plineCode));//改25号结转
			String name = parm1.get(1);
			String bz = parm1.get(2);
			String bc = parm1.get(3);
			String turnLinGx = parm1.get(4);// 返线工序点
			String storageNo = parm1.get(5);// 仓库
			String turnLinName = parm1.get(8);// 返线工序点
			String slgx = parm1.get(9);// 上料工序点
			String gwgx = parm1.get(10);// 
			String chgx = parm1.get(11);// 
			String dwgx = parm1.get(12);// 
			String djgx = parm1.get(13);// 
			String rjgx = parm1.get(14);// 
			String ljgx = parm1.get(15);// 
			String wgjygx = parm1.get(16);// 
			String tsgx = parm1.get(17);// 
			String gxh = slgx + "-" + gwgx + "-" + chgx + "-" + dwgx + "-"
					+ djgx + "-" + rjgx + "-" + ljgx + "-" + wgjygx + "-" + "0"
					+ "-" + tsgx + "-" + "0";
			String IsInstore = parm1.size() > 19 ? parm1.get(19) : "0";

			int NUM = 0;
			String gx = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.doQueryGXcount");
			psta = con.prepareStatement(sql);
			psta.setObject(1, plineCode);
			rs = psta.executeQuery();
			if (rs.next()) {
				NUM = Integer.parseInt(rs.getString("STATION_NAMES"));
			}
			rs.close();
			psta.close();
			if (NUM == 1) {
				gx = gxh.substring(0, 1);
			}
			if (NUM == 2) {
				gx = gxh.substring(0, 3);
			} else if (NUM == 3) {
				gx = gxh.substring(0, 5);
			} else if (NUM == 4) {
				gx = gxh.substring(0, 7);
			} else if (NUM == 5) {
				gx = gxh.substring(0, 9);
			} else if (NUM == 6) {
				gx = gxh.substring(0, 11);
			} else if (NUM == 7) {
				gx = gxh.substring(0, 13);
			} else if (NUM == 8) {
				gx = gxh.substring(0, 15);
			} else if (NUM == 9) {
				gx = gxh.substring(0, 17);
			} else if (NUM == 10) {
				gx = gxh.substring(0, 19);
			} else if (NUM == 11) {
				gx = gxh.substring(0, 21);
			}

			ArrayList<String> HeatPlanIds = new ArrayList<String>();

			for (String str : parm) {
				HttOfflineResultEntity HttOfflineResultEntity = EntityTool
						.getEntityByJSONStr(str.toString(),
								HttOfflineResultEntity.class);

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.doQueryOffLine2");//
				psta = con.prepareStatement(sql);
				psta.setString(1, HttOfflineResultEntity.getResultNo());
				rs = psta.executeQuery();
				String OfflineBranch = HttOfflineResultEntity
						.getOfflineBranch();
				List<HttOfflineResultEntity> data = EntityTool.getEntitysByRs(
						rs, HttOfflineResultEntity.class);

				psta.close();
				rs.close();
				if (data.size() <= 0) {
					cor.setV_errMsg("离线数据不存在,请刷新数据!");
					return cor;
				}

				HttOfflineResultEntity = data.get(0);
				HttOfflineResultEntity.setOfflineBranch(OfflineBranch);

				DecimalFormat df = new DecimalFormat("0.000");
				double weight = (Double.parseDouble(HttOfflineResultEntity
						.getOfflineWt()) / Integer
						.parseInt(HttOfflineResultEntity.getOfflineNum()))
						* Integer.parseInt(HttOfflineResultEntity
								.getOfflineBranch());
				String weight1 = df.format(weight);
				int count = 0;
				int remCount = 0;// 返线支数
				// String offgroupId = "";// 离线组炉Id
				String groupStart = "";// 组炉状态
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.QueryOffLineGroupStart");// 查询是否组炉
				psta = con.prepareStatement(sql);
				psta.setString(1, HttOfflineResultEntity.getJudgeStoveNo());
				psta.setString(2, HttOfflineResultEntity.getBatchNo());
				psta.setString(3, HttOfflineResultEntity.getResultNo());
				psta.setString(4, HttOfflineResultEntity.getHeatPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					// offgroupId = rs.getString("GROUP_ID");
					groupStart = rs.getString("GROUP_LOG");
					count = Integer.parseInt(rs.getString("COUNT_NUM"));
					remCount = Integer.parseInt(rs.getString("RE_NUM"));
				}
				rs.close();
				psta.close();
				if (remCount == 0) {
					cor.setV_errMsg("此炉已返线!");
					return cor;
				}

				if (Integer.parseInt(HttOfflineResultEntity.getTotalcount()) < Integer
						.parseInt(HttOfflineResultEntity.getOfflineBranch())) {
					cor.setV_errMsg("此炉返线支数大于离线支数,不允许返线!");
					return cor;
				}

				String matNoSqe = queryMatNoM(con, HttOfflineResultEntity
						.getJudgeStoveNo(), HttOfflineResultEntity.getBatchNo()); // 材料号
				int g = Integer.parseInt(matNoSqe.substring(
						matNoSqe.length() - 4, matNoSqe.length()));

				String inDoc = "";
				if (IsInstore.equals("1")) {

					inDoc = FrmMcpLoading.querySendIn(con, "800701");
				}

				// 获取最大镦拔扩计划编号
				// String plnNo = queryPlanMaxNo(con);
				if (groupStart.equals("1")) {

					List<HttGroupResultEntity> list = new ArrayList<HttGroupResultEntity>();
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmHttDownLineManage.QueryGroupVrpResult");// 查询组炉履历表信息
					psta = con.prepareStatement(sql);
					psta.setString(1, HttOfflineResultEntity.getGroupId());
					rs = psta.executeQuery();
					list = EntityTool.getEntitysByRs(rs,
							HttGroupResultEntity.class);
					rs.close();
					psta.close();

					String PlanStatus = "00";

					if (turnLinGx.equals("600201")) {
						PlanStatus = "00";

					} else if (turnLinGx.equals("600202")
							|| turnLinGx.equals("600203")
							|| turnLinGx.equals("600204")) {

						PlanStatus = "00";
					} else if (turnLinGx.equals("600205")
							|| turnLinGx.equals("600206")
							|| turnLinGx.equals("600207")) {
						PlanStatus = "30";

					} else if (turnLinGx.equals("600208")) {
						PlanStatus = "60";
					} else if (turnLinGx.equals("600209")) {
						PlanStatus = "70";
					} else if (turnLinGx.equals("600211")) {
						PlanStatus = "80";
					}

					PlnZyRclCEntity PlnZyRclCEntity = PlanService
							.AddNewRCLPlan(con, HttOfflineResultEntity, name,
									PlanStatus);

					HeatPlanIds.add(PlnZyRclCEntity.getHeatPlanNo() + ","
							+ PlnZyRclCEntity.getProPlanId() + ","
							+ PlnZyRclCEntity.getGxPlanNo());

					ArrayList<PortHttBatchSampleResultEntity> portData = new ArrayList<PortHttBatchSampleResultEntity>();
					PlnZyRclMEntity OldPln = PlanService.getSendHttPlanCInfo(
							con, HttOfflineResultEntity.getZyBatchId1());

					if (OldPln == null) {
						throw new Exception("找不到原炉计划信息!");
					}

					String ordPk = "";
					String ordLnPk = "";
					String belongCode = "";
					String belongName = "";

					if (IsInstore.equals("1")) {
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpInStore.selectBelong");
						sql = com.steering.comm.converter.EntityTool
								.fillSqlByEntity(sql, OldPln);
						psta = con.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							belongCode = rs.getString("DEPARTMENT_CODE");
							belongName = rs.getString("DEPARTMENT_DESC");
						}
						rs.close();
						psta.close();

						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpInStore.selectOrdPk");
						sql = com.steering.comm.converter.EntityTool
								.fillSqlByEntity(sql, OldPln);
						psta = con.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							ordPk = rs.getString("ORD_PK");
							ordLnPk = rs.getString("ORD_LN_PK");
						}
						rs.close();
						psta.close();
					}

					for (HttGroupResultEntity groupList : list) {

						sql = CoreXmlSqlParsersFactory
								.getSql("FrmHttDownLineManage.QueryOffMatNo4");// 查询管号队列离线材料号
						psta = con.prepareStatement(sql);
						psta.setString(1, groupList.getLxResultNo());
						rs = psta.executeQuery();
						ArrayList<PortHttBatchSampleResultEntity> list1 = EntityTool
								.getEntitysByRs(rs,
										PortHttBatchSampleResultEntity.class);
						portData.addAll(list1);
						rs.close();
						psta.close();

					}

					if (portData.size() < Integer
							.parseInt(HttOfflineResultEntity.getOfflineBranch())) {
						cor.setV_errMsg("管号队列无足够的离线管！");
						return cor;
					}

					for (int i = 0; i < portData.size(); i++) {

						pstaupdateStatus.setObject(1, portData.get(i)
								.getHeatPlanNo());
						pstaupdateStatus.setObject(2, portData.get(i)
								.getProcessSeq());
						pstaupdateStatus.setObject(3, portData.get(i)
								.getMatNo());
						pstaupdateStatus.addBatch();

						// 新增管号队列表
						pstaAddPort.setObject(1, PlnZyRclCEntity
								.getHeatPlanNo());
						pstaAddPort.setObject(2, portData.get(i).getMatNo());
						pstaAddPort.setObject(3, "");
						pstaAddPort.setObject(4, "");
						pstaAddPort.setObject(5, HttOfflineResultEntity
								.getZyBatchId());
						pstaAddPort.setObject(6, "");
						pstaAddPort.setObject(7, HttOfflineResultEntity
								.getPlineCode());
						pstaAddPort.setObject(8, HttOfflineResultEntity
								.getPlineName());
						pstaAddPort.setObject(9, HttOfflineResultEntity
								.getJudgeStoveNo());
						pstaAddPort.setObject(10, portData.get(i).getBatchNo());
						pstaAddPort.setObject(11, "001");
						pstaAddPort.setObject(12, PlnZyRclCEntity.getStoveNo());
						pstaAddPort.setObject(13, HttOfflineResultEntity
								.getJudgeStoveNo());
						pstaAddPort.setObject(14, HttOfflineResultEntity
								.getActDimater());
						pstaAddPort.setObject(15, HttOfflineResultEntity
								.getActHeight());
						pstaAddPort.setObject(16, portData.get(i).getActLen());
						pstaAddPort.setObject(17, portData.get(i)
								.getActLenMin());
						pstaAddPort.setObject(18, portData.get(i)
								.getActLenMax());
						pstaAddPort.setObject(19, "1");
						pstaAddPort.setObject(20, portData.get(i)
								.getActWeight());
						pstaAddPort.setObject(21, portData.get(i)
								.getActTheoryWeight());
						pstaAddPort.setObject(22, portData.get(i)
								.getMatStatus().equals("40") ? turnLinGx:
								"600201");
						pstaAddPort.setObject(23, "20");// 离线标志
						pstaAddPort.setObject(24, name);
						pstaAddPort.setObject(25, bc);
						pstaAddPort.setObject(26, bz);
						pstaAddPort.setObject(27, systime);
						// pstaAddPort.setObject(28, slgx + "-" + gwgx
						// + "-" + chgx + "-" + dwgx + "-"
						// + djgx + "-" + rjgx + "-" + ljgx
						// + "-" + wgjygx + "-" + "0" + "-"
						// + tsgx + "-" + "0");
						pstaAddPort.setObject(28, gx);
						pstaAddPort.setObject(29, turnLinGx);
						pstaAddPort.setObject(30, portData.get(i)
								.getMatStatus().equals("40") ? "40" : "00");// 材料状态

						pstaAddPort.setObject(31, HttOfflineResultEntity
								.getBatchNo());// 材料状态
						pstaAddPort.setObject(32, PlnZyRclCEntity
								.getHeatPlanSqe());// 材料状态
						pstaAddPort.setObject(33, HttOfflineResultEntity
								.getProcessSeq());// 材料状态
						pstaAddPort.setObject(34, PlnZyRclCEntity
								.getFeedHeatNo());// 材料状态
						pstaAddPort.setObject(35, IsInstore);
						pstaAddPort.setObject(36, portData.get(i)
								.getIsFailCheck());
						pstaAddPort.setObject(37, portData.get(i)
								.getBalYearMonthFail());
						
						pstaAddPort.setObject(38, yearMoth);
				
						pstaAddPort.addBatch();

						if (IsInstore.equals("0")) {
							if (!portData.get(i).getMatStatus().equals("40"))
								PlanService.DeleteOffLineMat(con, portData.get(
										i).getMatNo(), true,
										HttOfflineResultEntity.getPlineCode());
						} else {
							// region 返线入库 写入库记录 更新库存数据
							MatBcMEntity MatBcMEntity = OfflineHelper
									.getMatBcM(con, portData.get(i).getMatNo());
							if (MatBcMEntity == null
									|| MatBcMEntity.getMatNo().equals("")) {
								throw new Exception("找不到待处理库存!");
							}
							if (MatBcMEntity.getStorageNo().equals("")) {
								throw new Exception("离线管正在倒运途中,不允许此操作!");
							}

							MatBcMEntity matBcEntity = new MatBcMEntity();
							matBcEntity.setMatNo(portData.get(i).getMatNo());
							// matBcEntity.setTestCount(String.valueOf(n));
							matBcEntity.setInstockDoc(inDoc);
							matBcEntity.setInstockTypeCode("800701");
							matBcEntity.setInstockTypeName("产出入库");
							matBcEntity.setLaryNo("1");
							matBcEntity.setLotNo(OldPln.getZyBatchId());
							matBcEntity.setSampleFlag(portData.get(i)
									.getIsSamplePipe());

							if (!OldPln.getDecision().equals("A")
									|| !OldPln.getRealProcessSeq().equals(
											OldPln.getProcessSeq())) {
								matBcEntity.setProductFlag("801401");
								matBcEntity.setMatStatus("80150101");

							} else {
								matBcEntity.setProductFlag("801402");// 成品
								matBcEntity.setMatStatus("80150201");
							}
							matBcEntity.setJudgeStoveNo(HttOfflineResultEntity
									.getJudgeStoveNo());
							matBcEntity.setBatchNo(HttOfflineResultEntity
									.getBatchNo());
							matBcEntity.setMaterialNo(OldPln.getOutwlId());
							matBcEntity.setMaterialName(OldPln.getOutwlDesc());
							matBcEntity.setProduccode(OldPln.getProduccode());
							matBcEntity.setProducname(OldPln.getProducname());
							matBcEntity.setSteelcode(OldPln.getSteelcode());
							matBcEntity.setSteelname(OldPln.getSteelname());
							matBcEntity.setStdStyle(OldPln.getStdStyle());
							matBcEntity.setStdStyleDesc(OldPln
									.getStdStyleDesc());
							matBcEntity.setSpecCode(OldPln.getSpecCode());
							matBcEntity.setSpecName(OldPln.getSpecName());
							matBcEntity.setModelCode(OldPln.getModelCode());
							matBcEntity.setModelDesc(OldPln.getModelDesc());
							matBcEntity.setGradecode(OldPln.getGradecode());
							matBcEntity.setGradename(OldPln.getGradename());
							matBcEntity.setStdCode("");
							matBcEntity.setStdName(OldPln.getProdStandard());
							matBcEntity.setProOrderNo(OldPln.getOrderNo() + "/"
									+ OldPln.getOrderSeq());
							matBcEntity.setProcessCdoe("F");
							matBcEntity.setProcessDesc("热处理");
							matBcEntity.setNextProcessCdoe(OldPln
									.getRealProcessSeq().equals(
											OldPln.getProcessSeq()) ? OldPln
									.getNextProcessCode() : "F");
							matBcEntity.setNextProcessDesc("");
							matBcEntity.setHeatPlanNoNext(OldPln
									.getRealProcessSeq().equals(
											OldPln.getProcessSeq()) ? ""
									: OldPln.getHeatPlanNo());
							matBcEntity.setPlineCode(OldPln.getPlineCode());
							matBcEntity.setPlineName(OldPln.getPlineName());
							matBcEntity.setMatOriginCode("801302");
							matBcEntity.setMatOriginName("产线");
							matBcEntity.setActDimater(OldPln.getOutdiameter());
							matBcEntity.setActHeight(OldPln.getWallthick());
							matBcEntity.setActLenMin(portData.get(i)
									.getActLenMin());
							matBcEntity.setActLenMax(portData.get(i)
									.getActLenMax());
							matBcEntity.setBelongCode(belongCode);
							matBcEntity.setBelongName(belongName);
							matBcEntity.setCreateName(name);
							matBcEntity.setCreateTime(systime);


							matBcEntity.setBalYearMonth(yearMoth);
							matBcEntity.setJudgeStdCode("");
							matBcEntity.setJudgeStdName(OldPln
									.getOutputStandard());
							matBcEntity.setGxPlanNo(OldPln.getGxPlanNo());
							matBcEntity.setQcmStaus(portData.get(i)
									.getMatStatus().equals("40") ? "22" : "00");
							matBcEntity.setHeatPlanNo(OldPln.getHeatPlanNo());
							matBcEntity.setActCount(portData.get(i)
									.getActCount());
							matBcEntity.setProOrderId(OldPln.getProPlanId());
							matBcEntity.setGxPlanNo(OldPln.getGxPlanNo());
							matBcEntity.setPhyBatchNo(portData.get(i)
									.getPhyBatchNo());
							matBcEntity.setIsSamplePipe(portData.get(i)
									.getIsSamplePipe());
							matBcEntity.setCrafNo(OldPln.getCraftFileNo());
							matBcEntity.setCraftSeq(OldPln.getCraftSeq());
							matBcEntity.setOrdLnDlyPk(OldPln.getOrdLnDlyPk());
							matBcEntity.setOrderNo(OldPln.getOrderNo());
							matBcEntity.setOrderSeq(OldPln.getOrderSeq());
							matBcEntity.setOrderSeqNo(OldPln.getDeliveryNo());
							matBcEntity.setMatGowhereCode(OldPln
									.getGowhereCode());
							matBcEntity.setMatGowhereName(OldPln
									.getGowhereName());
							matBcEntity.setStoveNo(OldPln.getStoveNo());
							matBcEntity.setFlagStoveNoZg(portData.get(i)
									.getFlagStoveNo());
							matBcEntity.setTarget(OldPln.getDecision()); // 判定字头
							matBcEntity.setInBc(bc);
							matBcEntity.setInBz(bz);
							matBcEntity.setActLen(portData.get(i).getActLen());
							matBcEntity.setActWeight(portData.get(i)
									.getActWeight());
							matBcEntity.setActTheoryWeight(portData.get(i)
									.getActWeight());

							matBcEntity.setJudgeStdDes(OldPln.getCic() + "+"
									+ OldPln.getPic() + "+" + OldPln.getSic()
									+ "+" + OldPln.getDic());

							matBcEntity.setCic(OldPln.getCic());
							matBcEntity
									.setHeatPlanNoOld(OldPln.getHeatPlanNo());
							if (ordPk == null || ordPk.equals("")) {
								matBcEntity.setOrdPk("");
							} else {
								matBcEntity.setOrdPk(ordPk);
							}
							if (ordLnPk == null || ordLnPk.equals("")) {
								matBcEntity.setOrdLnPk("");
							} else {
								matBcEntity.setOrdLnPk(ordLnPk);
							}

							String updateMatsql = CoreXmlSqlParsersFactory
									.getSql("FrmMchInStore.updateMatBcM");// 返线交库
																			// 更改材料信息
							updateMatsql = com.steering.comm.converter.EntityTool
									.fillSqlByEntity(updateMatsql, matBcEntity);
							PreparedStatement pstaUpdateMatsql = con
									.prepareStatement(updateMatsql);
							pstaUpdateMatsql.addBatch();
							pstaUpdateMatsql.executeBatch();

							// endregion
						}
					}

					/* pupdatePlnStatus.executeBatch(); */
					pstaupdateStatus.executeBatch();

					pstaAddPort.executeBatch();

					if (IsInstore.equals("1")) {
						String updateMatsql = CoreXmlSqlParsersFactory
								.getSql("FrmHttInStore.insertVrpComInfo2");// 返线入库
																			// 插入公共信息表
						PreparedStatement pstaUpdateMatsql = con
								.prepareStatement(updateMatsql);
						pstaUpdateMatsql.setObject(1, inDoc);
						pstaUpdateMatsql.setObject(2, PlnZyRclCEntity
								.getHeatPlanNo());
						pstaUpdateMatsql.addBatch();
						pstaUpdateMatsql.executeBatch();

						String matGpNum = "";// 已分配到订单支数
						int gpreqCount = 0;// 未分配支数
						int inCount = portData.size();

						if (!OldPln.getNextProcessCode().equals("")
								&& OldPln.getRealProcessSeq().equals(
										OldPln.getProcessSeq())) {
							if (OldPln.getNextProcessCode().equals("G")) {
								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpInStore.selectPlnZyJg");
							} else if (OldPln.getNextProcessCode().equals("H")) {
								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpInStore.selectPlnZyJgm");
							}
							sql = com.steering.comm.converter.EntityTool
									.fillSqlByEntity(sql, OldPln);
							psta = con.prepareStatement(sql);
							rs = psta.executeQuery();

							List<PlnZyRclMEntity1> plnOrderZy = com.steering.comm.converter.EntityTool
									.getEntitysByRs(rs, PlnZyRclMEntity1.class);
							rs.close();
							psta.close();
							String codeBl = "";
							if (OldPln.getNextProcessCode().equals("H")) {
								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpInStore.selectPlnZyJgmProp");
								sql = com.steering.comm.converter.EntityTool
										.fillSqlByEntity(sql, OldPln);
								psta = con.prepareStatement(sql);
								rs = psta.executeQuery();
								if (rs.next()) {
									codeBl = rs.getString("CODE_JG_BL");
								}
								rs.close();
								psta.close();
							}
							for (int i = 0; i < plnOrderZy.size(); i++) {
								// 该订单下已分配多少支
								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpInStore.selectMatGpMNumZg");
								sql = com.steering.comm.converter.EntityTool
										.fillSqlByEntity(sql, plnOrderZy.get(i));
								psta = con.prepareStatement(sql);
								rs = psta.executeQuery();
								if (rs.next()) {
									matGpNum = rs.getString("ACT_COUNT");
								}
								rs.close();
								psta.close();
								if (OldPln.getNextProcessCode().equals("G")) {
									gpreqCount = Integer.parseInt(plnOrderZy
											.get(i).getPlnInsingleNum())
											- Integer.parseInt(matGpNum);
								} else if (OldPln.getNextProcessCode().equals(
										"H")) {
									gpreqCount = Integer.parseInt(plnOrderZy
											.get(i).getPlanBlNum())
											- Integer.parseInt(matGpNum);
								}

								MatBcMEntity matEntity = new MatBcMEntity();
								matEntity.setJudgeStoveNo(PlnZyRclCEntity
										.getJudgeStoveNo());
								matEntity.setProOrderId(OldPln.getProPlanId());
								matEntity.setGxPlanNo(OldPln.getGxPlanNo());
								matEntity.setHeatPlanNo(OldPln.getHeatPlanNo());
								matEntity.setProPlanIdNext(plnOrderZy.get(i)
										.getProPlanId());
								matEntity.setGxPlanNoNext(plnOrderZy.get(i)
										.getGxPlanNo());
								matEntity.setPlineCode(OldPln.getPlineCode());
								// matEntity.setCodeJgBl(plnOrderZy.get(i).getCodeJgBl());
								matEntity.setCodeJgBl(codeBl);
								matEntity.setHeatPlanNoNext(plnOrderZy.get(i)
										.getHeatPlanNo());

								if (i == plnOrderZy.size() - 1) {
									matEntity.setActCount(String
											.valueOf(inCount));
								} else if (inCount < gpreqCount) {
									matEntity.setActCount(String
											.valueOf(inCount));
								} else {
									matEntity.setActCount(String
											.valueOf(gpreqCount));
								}
								String updateMatBcMSql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpInStore.updateMatBcM");
								updateMatBcMSql = com.steering.comm.converter.EntityTool
										.fillSqlByEntity(updateMatBcMSql,
												matEntity);
								PreparedStatement pstaupdateMatBcMSql = con
										.prepareStatement(updateMatBcMSql);
								pstaupdateMatBcMSql.addBatch();
								pstaupdateMatBcMSql.executeBatch();

								inCount = inCount - gpreqCount;
								if (inCount <= 0 && i + 1 < plnOrderZy.size()) {
									break;
								}

							}
						}

					}

					pstaupdateOff.setObject(1,
							Integer.parseInt(HttOfflineResultEntity
									.getOfflineBranch())
									+ Integer.parseInt(HttOfflineResultEntity
											.getReNum()));
					pstaupdateOff.setObject(2, weight1);
					pstaupdateOff.setObject(3, systime);
					pstaupdateOff.setObject(4, name);
					pstaupdateOff.setObject(5, turnLinGx);
					pstaupdateOff.setObject(6, PlnZyRclCEntity.getHeatPlanNo());
					pstaupdateOff.setObject(7, HttOfflineResultEntity
							.getResultNo());
					pstaupdateOff.addBatch();

					pstaUpdateHeatPlanID.setObject(1, HttOfflineResultEntity
							.getResultNo());
					pstaUpdateHeatPlanID.addBatch();

				} else {

					String plnNo = HttOfflineResultEntity.getHeatPlanNo();

					PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(con,
							plnNo);

					if (pln == null) {
						cor.setV_errMsg("无炉计划数据,,不允许此操作！");
						return cor;
					}

					if (pln.getPlanstatus().equals("30")) {
						cor.setV_errMsg("该炉对应的计划已结炉,不允许次操作！");
						return cor;
					}
					if (pln.getPlanstatus().equals("40")) {
						cor.setV_errMsg("该炉对应的计划已关闭,不允许次操作！");
						return cor;
					}

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmHttDownLineManage.QueryOffMatNo2");// 查询管号队列离线材料号
					psta = con.prepareStatement(sql);
					psta.setString(1, HttOfflineResultEntity.getResultNo());
					rs = psta.executeQuery();
					ArrayList<PortHttBatchSampleResultEntity> ListPort = EntityTool
							.getEntitysByRs(rs,
									PortHttBatchSampleResultEntity.class);
					rs.close();
					psta.close();

					if (ListPort.size() == 0) {
						cor.setV_errMsg("管号队列无对应的材料！");
						return cor;
					}

					if (ListPort.size() < Integer
							.parseInt(HttOfflineResultEntity.getOfflineBranch())) {
						cor.setV_errMsg("管号队列无足够的离线管！");
						return cor;
					}

					if (ListPort.size() != Integer
							.parseInt(HttOfflineResultEntity.getTotalcount())) {
						cor.setV_errMsg("数据异常,队列离线支与离线记录剩余支不一致！");
						return cor;
					}

					String ordPk = "";
					String ordLnPk = "";
					String belongCode = "";
					String belongName = "";

					if (IsInstore.equals("1")) {
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpInStore.selectBelong");
						sql = com.steering.comm.converter.EntityTool
								.fillSqlByEntity(sql, pln);
						psta = con.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							belongCode = rs.getString("DEPARTMENT_CODE");
							belongName = rs.getString("DEPARTMENT_DESC");
						}
						rs.close();
						psta.close();

						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpInStore.selectOrdPk");
						sql = com.steering.comm.converter.EntityTool
								.fillSqlByEntity(sql, pln);
						psta = con.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							ordPk = rs.getString("ORD_PK");
							ordLnPk = rs.getString("ORD_LN_PK");
						}
						rs.close();
						psta.close();
					}

					for (int i = 0; i < Integer.parseInt(HttOfflineResultEntity
							.getOfflineBranch()); i++) {

						// 修改管号队列
						pstaUpdatePort.setObject(1, "00");
						pstaUpdatePort.setObject(2, "20");

						pstaUpdatePort.setObject(3, gx);
						pstaUpdatePort.setObject(4, turnLinGx);
						pstaUpdatePort.setObject(5, HttOfflineResultEntity
								.getFlagStoveNo());
						pstaUpdatePort.setObject(6, IsInstore);
						pstaUpdatePort.setObject(7, HttOfflineResultEntity
								.getHeatPlanNo());
						pstaUpdatePort.setObject(8, ListPort.get(i).getMatNo());
						pstaUpdatePort.addBatch();

						if (!HttOfflineResultEntity.getStationCode().equals(
								turnLinGx)
								&&

								pln.getProcessSeq().equals(
										pln.getRealProcessSeq())
								&& !pln.getProcessCodeC().equals("B024")
								&& turnLinGx.compareToIgnoreCase("600204") <= 0
								&& !HttOfflineResultEntity.getBatchNo().equals(
										"")) {

							if (IsInstore.equals("1")) {
								cor.setV_errMsg("需要重新热处理的不允许做返线入库,请用正常的返线操作");
								return cor;
							}

							if(!"C091".equals(pln.getPlineCode())) {

								String sqlGroup = CoreXmlSqlParsersFactory
										.getSql("FrmHttDownLineManage.checkReHtt");// 查询新增物料信息
								psta = con.prepareStatement(sqlGroup);
								psta.setObject(1, HttOfflineResultEntity
										.getJudgeStoveNo());
								psta.setObject(2, HttOfflineResultEntity
										.getBatchNo());
								rs = psta.executeQuery();
								if (rs.next()) {
									String CYCLES_FLAG = String.valueOf(rs
											.getString("CYCLES_FLAG"));
									if (!CYCLES_FLAG.equals("1")) {
										cor.setV_errMsg("炉号:"
												+ HttOfflineResultEntity
												.getJudgeStoveNo()
												+ " 批号:"
												+ HttOfflineResultEntity
												.getBatchNo()
												+ "已经委托, 但未申请重新热处理,请先申请重新热处理");
										return cor;
									}
								}
								rs.close();
								psta.close();
							}

							pstaBackUpBatchInfo.setObject(1,
									HttOfflineResultEntity.getHeatPlanNo());
							pstaBackUpBatchInfo.setObject(2, ListPort.get(i)
									.getMatNo());
							pstaBackUpBatchInfo.addBatch();
							if (i == 0) {
								pstaCancelBeside.setObject(1,
										HttOfflineResultEntity.getHeatPlanNo());
								pstaCancelBeside.setObject(2,
										HttOfflineResultEntity.getProcessSeq());
								pstaCancelBeside.addBatch();
								pstaCancelBeside.executeBatch();

								updatePlnPsta.setObject(1, "00");
								updatePlnPsta.setObject(2,
										HttOfflineResultEntity.getHeatPlanNo());
								updatePlnPsta.addBatch();
								updatePlnPsta.executeBatch();
							}

							pstaUpdatePort1.setObject(1, HttOfflineResultEntity
									.getHeatPlanNo());
							pstaUpdatePort1.setObject(2, ListPort.get(i)
									.getMatNo());
							pstaUpdatePort1.addBatch();
						}

						pstaUpdatePort.executeBatch();
						pstaBackUpBatchInfo.executeBatch();
						pstaUpdatePort1.executeBatch();

						if (IsInstore.equals("0")) {
							PlanService.DeleteOffLineMat(con, ListPort.get(i)
									.getMatNo(), true, HttOfflineResultEntity
									.getPlineCode());
						} else {
							// region 返线入库 写入库记录 更新库存数据
							MatBcMEntity MatBcMEntity = OfflineHelper
									.getMatBcM(con, ListPort.get(i).getMatNo());
							if (MatBcMEntity == null
									|| MatBcMEntity.getMatNo().equals("")) {
								throw new Exception("找不到待处理库存!");
							}
							if (MatBcMEntity.getStorageNo().equals("")) {
								throw new Exception("离线管正在倒运途中,不允许此操作!");
							}

							if (ListPort.get(i).getPhyBatchNo().equals("")) {
								cor.setV_errMsg("批号为空的不允许做返线入库,请用正常的返线操作");
								return cor;
							}

							MatBcMEntity matBcEntity = new MatBcMEntity();
							matBcEntity.setMatNo(ListPort.get(i).getMatNo());
							// matBcEntity.setTestCount(String.valueOf(n));
							matBcEntity.setInstockDoc(inDoc);
							matBcEntity.setInstockTypeCode("800701");
							matBcEntity.setInstockTypeName("产出入库");
							matBcEntity.setLaryNo("1");
							matBcEntity.setLotNo(pln.getZyBatchId());
							matBcEntity.setSampleFlag(ListPort.get(i)
									.getIsSamplePipe());

							if (!pln.getDecision().equals("A")
									|| !pln.getRealProcessSeq().equals(
											pln.getProcessSeq())) {
								matBcEntity.setProductFlag("801401");
								matBcEntity.setMatStatus("80150101");

							} else {
								matBcEntity.setProductFlag("801402");// 成品
								matBcEntity.setMatStatus("80150201");
							}
							matBcEntity.setJudgeStoveNo(HttOfflineResultEntity
									.getJudgeStoveNo());
							matBcEntity.setBatchNo(HttOfflineResultEntity
									.getBatchNo());
							matBcEntity.setMaterialNo(pln.getOutwlId());
							matBcEntity.setMaterialName(pln.getOutwlDesc());
							matBcEntity.setProduccode(pln.getProduccode());
							matBcEntity.setProducname(pln.getProducname());
							matBcEntity.setSteelcode(pln.getSteelcode());
							matBcEntity.setSteelname(pln.getSteelname());
							matBcEntity.setStdStyle(pln.getStdStyle());
							matBcEntity.setStdStyleDesc(pln.getStdStyleDesc());
							matBcEntity.setSpecCode(pln.getSpecCode());
							matBcEntity.setSpecName(pln.getSpecName());
							matBcEntity.setModelCode(pln.getModelCode());
							matBcEntity.setModelDesc(pln.getModelDesc());
							matBcEntity.setGradecode(pln.getGradecode());
							matBcEntity.setGradename(pln.getGradename());
							matBcEntity.setStdCode("");
							matBcEntity.setStdName(pln.getProdStandard());
							matBcEntity.setProOrderNo(pln.getOrderNo() + "/"
									+ pln.getOrderSeq());
							matBcEntity.setProcessCdoe("F");
							matBcEntity.setProcessDesc("热处理");
							matBcEntity.setNextProcessCdoe(pln
									.getRealProcessSeq().equals(
											pln.getProcessSeq()) ? pln
									.getNextProcessCode() : "F");
							matBcEntity.setNextProcessDesc("");
							matBcEntity.setHeatPlanNoNext(pln
									.getRealProcessSeq().equals(
											pln.getProcessSeq()) ? "" : pln
									.getHeatPlanNo());
							matBcEntity.setPlineCode(pln.getPlineCode());
							matBcEntity.setPlineName(pln.getPlineName());
							matBcEntity.setMatOriginCode("801302");
							matBcEntity.setMatOriginName("产线");
							matBcEntity.setActDimater(pln.getOutdiameter());
							matBcEntity.setActHeight(pln.getWallthick());
							matBcEntity.setActLenMin(ListPort.get(i)
									.getActLenMin());
							matBcEntity.setActLenMax(ListPort.get(i)
									.getActLenMax());
							matBcEntity.setBelongCode(belongCode);
							matBcEntity.setBelongName(belongName);
							matBcEntity.setCreateName(name);
							matBcEntity.setCreateTime(systime);
				

							matBcEntity.setBalYearMonth(yearMoth);
							matBcEntity.setJudgeStdCode("");
							matBcEntity
									.setJudgeStdName(pln.getOutputStandard());
							matBcEntity.setGxPlanNo(pln.getGxPlanNo());
							matBcEntity.setQcmStaus("00");
							matBcEntity.setHeatPlanNo(pln.getHeatPlanNo());
							matBcEntity.setActCount(ListPort.get(i)
									.getActCount());
							matBcEntity.setProOrderId(pln.getProPlanId());
							matBcEntity.setGxPlanNo(pln.getGxPlanNo());
							matBcEntity.setPhyBatchNo(ListPort.get(i)
									.getPhyBatchNo());
							matBcEntity.setIsSamplePipe(ListPort.get(i)
									.getIsSamplePipe());
							matBcEntity.setCrafNo(pln.getCraftFileNo());
							matBcEntity.setCraftSeq(pln.getCraftSeq());
							matBcEntity.setOrdLnDlyPk(pln.getOrdLnDlyPk());
							matBcEntity.setOrderNo(pln.getOrderNo());
							matBcEntity.setOrderSeq(pln.getOrderSeq());
							matBcEntity.setOrderSeqNo(pln.getDeliveryNo());
							matBcEntity.setMatGowhereCode(pln.getGowhereCode());
							matBcEntity.setMatGowhereName(pln.getGowhereName());
							matBcEntity.setStoveNo(pln.getStoveNo());
							matBcEntity.setFlagStoveNoZg(ListPort.get(i)
									.getFlagStoveNo());
							matBcEntity.setTarget(pln.getDecision()); // 判定字头
							matBcEntity.setInBc(bc);
							matBcEntity.setInBz(bz);
							matBcEntity.setActLen(ListPort.get(i).getActLen());
							matBcEntity.setActWeight(ListPort.get(i)
									.getActWeight());
							matBcEntity.setActTheoryWeight(ListPort.get(i)
									.getActWeight());

							if (pln.getIfProduct().equals("1")) {
								matBcEntity.setJudgeStdDes(pln.getCic() + "+"
										+ pln.getPic() + "+" + pln.getSic()
										+ "+" + pln.getDic());
							} else {
								matBcEntity.setJudgeStdDes("" + "+"
										+ pln.getPic() + "+" + pln.getSic()
										+ "+" + pln.getDic());
							}

							matBcEntity.setCic(pln.getCic());
							matBcEntity.setHeatPlanNoOld(pln.getHeatPlanNo());
							if (ordPk == null || ordPk.equals("")) {
								matBcEntity.setOrdPk("");
							} else {
								matBcEntity.setOrdPk(ordPk);
							}
							if (ordLnPk == null || ordLnPk.equals("")) {
								matBcEntity.setOrdLnPk("");
							} else {
								matBcEntity.setOrdLnPk(ordLnPk);
							}

							String updateMatsql = CoreXmlSqlParsersFactory
									.getSql("FrmMchInStore.updateMatBcM");// 返线交库
																			// 更改材料信息
							updateMatsql = com.steering.comm.converter.EntityTool
									.fillSqlByEntity(updateMatsql, matBcEntity);
							PreparedStatement pstaUpdateMatsql = con
									.prepareStatement(updateMatsql);
							pstaUpdateMatsql.addBatch();
							pstaUpdateMatsql.executeBatch();

							// endregion
						}

					}

					if (IsInstore.equals("1")) {
						String updateMatsql = CoreXmlSqlParsersFactory
								.getSql("FrmHttInStore.insertVrpComInfo2");// 返线入库
																			// 插入公共信息表
						PreparedStatement pstaUpdateMatsql = con
								.prepareStatement(updateMatsql);
						pstaUpdateMatsql.setObject(1, inDoc);
						pstaUpdateMatsql.setObject(2, pln.getHeatPlanNo());
						pstaUpdateMatsql.addBatch();
						pstaUpdateMatsql.executeBatch();

						String matGpNum = "";// 已分配到订单支数
						int gpreqCount = 0;// 未分配支数
						int inCount = Integer.parseInt(HttOfflineResultEntity
								.getOfflineBranch());

						if (!pln.getNextProcessCode().equals("")
								&& pln.getRealProcessSeq().equals(
										pln.getProcessSeq())) {
							if (pln.getNextProcessCode().equals("G")) {
								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpInStore.selectPlnZyJg");
							} else if (pln.getNextProcessCode().equals("H")) {
								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpInStore.selectPlnZyJgm");
							}
							sql = com.steering.comm.converter.EntityTool
									.fillSqlByEntity(sql, pln);
							psta = con.prepareStatement(sql);
							rs = psta.executeQuery();

							List<PlnZyRclMEntity1> plnOrderZy = com.steering.comm.converter.EntityTool
									.getEntitysByRs(rs, PlnZyRclMEntity1.class);
							rs.close();
							psta.close();
							String codeBl = "";
							if (pln.getNextProcessCode().equals("H")) {
								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpInStore.selectPlnZyJgmProp");
								sql = com.steering.comm.converter.EntityTool
										.fillSqlByEntity(sql, pln);
								psta = con.prepareStatement(sql);
								rs = psta.executeQuery();
								if (rs.next()) {
									codeBl = rs.getString("CODE_JG_BL");
								}
								rs.close();
								psta.close();
							}
							for (int i = 0; i < plnOrderZy.size(); i++) {
								// 该订单下已分配多少支
								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpInStore.selectMatGpMNumZg");
								sql = com.steering.comm.converter.EntityTool
										.fillSqlByEntity(sql, plnOrderZy.get(i));
								psta = con.prepareStatement(sql);
								rs = psta.executeQuery();
								if (rs.next()) {
									matGpNum = rs.getString("ACT_COUNT");
								}
								rs.close();
								psta.close();
								if (pln.getNextProcessCode().equals("G")) {
									gpreqCount = Integer.parseInt(plnOrderZy
											.get(i).getPlnInsingleNum())
											- Integer.parseInt(matGpNum);
								} else if (pln.getNextProcessCode().equals("H")) {
									gpreqCount = Integer.parseInt(plnOrderZy
											.get(i).getPlanBlNum())
											- Integer.parseInt(matGpNum);
								}

								MatBcMEntity matEntity = new MatBcMEntity();
								matEntity
										.setJudgeStoveNo(pln.getJudgeStoveNo());
								matEntity.setProOrderId(pln.getProPlanId());
								matEntity.setGxPlanNo(pln.getGxPlanNo());
								matEntity.setHeatPlanNo(pln.getHeatPlanNo());
								matEntity.setProPlanIdNext(plnOrderZy.get(i)
										.getProPlanId());
								matEntity.setGxPlanNoNext(plnOrderZy.get(i)
										.getGxPlanNo());
								matEntity.setPlineCode(pln.getPlineCode());
								// matEntity.setCodeJgBl(plnOrderZy.get(i).getCodeJgBl());
								matEntity.setCodeJgBl(codeBl);
								matEntity.setHeatPlanNoNext(plnOrderZy.get(i)
										.getHeatPlanNo());

								if (i == plnOrderZy.size() - 1) {
									matEntity.setActCount(String
											.valueOf(inCount));
								} else if (inCount < gpreqCount) {
									matEntity.setActCount(String
											.valueOf(inCount));
								} else {
									matEntity.setActCount(String
											.valueOf(gpreqCount));
								}
								String updateMatBcMSql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpInStore.updateMatBcM");
								updateMatBcMSql = com.steering.comm.converter.EntityTool
										.fillSqlByEntity(updateMatBcMSql,
												matEntity);
								PreparedStatement pstaupdateMatBcMSql = con
										.prepareStatement(updateMatBcMSql);
								pstaupdateMatBcMSql.addBatch();
								pstaupdateMatBcMSql.executeBatch();

								inCount = inCount - gpreqCount;
								if (inCount <= 0 && i + 1 < plnOrderZy.size()) {
									break;
								}

							}
						}

					}

					pstaupdateOff.setObject(1,
							Integer.parseInt(HttOfflineResultEntity
									.getOfflineBranch())
									+ Integer.parseInt(HttOfflineResultEntity
											.getReNum()));
					pstaupdateOff.setObject(2, Double.parseDouble(weight1)
							+ Double.parseDouble(HttOfflineResultEntity
									.getReWt()));
					pstaupdateOff.setObject(3, systime);
					pstaupdateOff.setObject(4, name);
					pstaupdateOff.setObject(5, turnLinGx);
					pstaupdateOff.setObject(6, HttOfflineResultEntity
							.getHeatPlanNo());
					pstaupdateOff.setObject(7, HttOfflineResultEntity
							.getResultNo());
					pstaupdateOff.addBatch();

					pstadeteleOff.setObject(1, HttOfflineResultEntity
							.getResultNo());
					pstadeteleOff.setObject(2, HttOfflineResultEntity
							.getHeatPlanNo());
					pstadeteleOff.setObject(3, HttOfflineResultEntity
							.getPlineCode());
					pstadeteleOff.addBatch();
					pstadeteleOff.executeBatch();
				}

			}
			pstaupdateOff.executeBatch();
			pstaUpdateHeatPlanID.executeBatch();

			cor.setResult(HeatPlanIds);
			cor.setV_errMsg("返线成功！");
			con.commit();

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (con != null) {
				try {
					cor.setV_errMsg(e.getMessage());
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return cor;
	}

	/**
	 *撤销返线
	 * 
	 * @param result
	 * @return
	 */
	public CoreReturnObject doCancelReturnLine(ArrayList<String> parm,
			ArrayList<String> parm1) {
		CoreReturnObject cor = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String systime = dateFormat.format(now);
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String deleteOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.DeleteReturnResu");// 删除镦拔扩计划表
			PreparedStatement pstaDeleteOff = con.prepareStatement(deleteOff);
			String deleteOffC = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.DeleteReturnResuC");// 删除镦拔扩计划从表
			PreparedStatement pstaDeleteOffC = con.prepareStatement(deleteOffC);
			String updatePort = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdatePortVrpReturn");// 修改管号队列表
			PreparedStatement pstaUpdatePort = con.prepareStatement(updatePort);

			String RecoverBatchInfo = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.RecoverBatchInfo");// 修改管号队列表
			PreparedStatement pstaRecoverBatchInfo = con
					.prepareStatement(RecoverBatchInfo);

			String DeleteBackUpBatchInfo = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.DeleteBackUpBatchInfo");// 修改管号队列表
			PreparedStatement pstaDeleteBackUpBatchInfo = con
					.prepareStatement(DeleteBackUpBatchInfo);

			String deletePort = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.DeletePortVrpReturn");// 删除管号队列表
			PreparedStatement pstaDeletePort = con.prepareStatement(deletePort);
			String updateMat = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdateMatReturn");// 修改材料表
			PreparedStatement pstaUpdateMat = con.prepareStatement(updateMat);

			String updateOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdateOff");// 修改离线表返线支数
			PreparedStatement pstaupdateOff = con.prepareStatement(updateOff);
			String updateStatus = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdateStatus1");// 修改组炉返线材料状态20
			PreparedStatement pstaupdateStatus = con
					.prepareStatement(updateStatus);

			String name = parm1.get(1);
			String storageNo = parm1.get(4);// 仓库

			for (String str : parm) {
				HttOfflineResultEntity HttOfflineResultEntity = EntityTool
						.getEntityByJSONStr(str.toString(),
								HttOfflineResultEntity.class);

				// String offgroupId = "";// 离线组炉Id
				String groupStart = "";// 组炉状态
				String flag = "";
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.QueryOffLineGroupStart");// 查询是否组炉
				psta = con.prepareStatement(sql);
				psta.setString(1, HttOfflineResultEntity.getJudgeStoveNo());
				psta.setString(2, HttOfflineResultEntity.getBatchNo());
				psta.setString(3, HttOfflineResultEntity.getResultNo());
				psta.setString(4, HttOfflineResultEntity.getHeatPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					groupStart = rs.getString("GROUP_LOG");
					flag = rs.getString("FLAG");
				}

				if (flag.equals("1")) {
					cor.setV_errMsg("物料已发生改变,不允许撤销!");
					return cor;
				}

				rs.close();
				psta.close();
				List<String> matNo = new ArrayList<String>();
				if (groupStart.equals("1")) {

					String UpdateHeatPlanID = CoreXmlSqlParsersFactory
							.getSql("FrmHttDownLineManage.UpdateHeatPlanID2");// 修改离线表返线支数
					PreparedStatement pstaUpdateHeatPlanID = con
							.prepareStatement(UpdateHeatPlanID);
					pstaUpdateHeatPlanID.setObject(1, HttOfflineResultEntity
							.getResultNo());
					pstaUpdateHeatPlanID.addBatch();
					pstaUpdateHeatPlanID.executeBatch();

					String UpdateOldPortStauts = CoreXmlSqlParsersFactory
							.getSql("FrmHttDownLineManage.UpdateOldPortStauts");//
					PreparedStatement pstaUpdateOldPortStauts = con
							.prepareStatement(UpdateOldPortStauts);
					pstaUpdateOldPortStauts.setObject(1, HttOfflineResultEntity
							.getResultNo());
					pstaUpdateOldPortStauts.addBatch();
					pstaUpdateOldPortStauts.executeBatch();

					int recount = 0;
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmHttDownLineManage.QueryComVrpRes");// 查询返线后是否存在实绩
					psta = con.prepareStatement(sql);
					psta.setString(1, HttOfflineResultEntity.getHeatPlanNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						recount = Integer.parseInt(rs.getString("COUNT"));
					}
					rs.close();
					psta.close();
					if (recount != 0) {
						cor.setV_errMsg("此炉已存在实绩,不允许此操作!");
						return cor;
					}

					recount = 0;
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmHttDownLineManage.QueryComVrpRes1");// 查询返线后是否存在实绩
					psta = con.prepareStatement(sql);
					psta.setString(1, HttOfflineResultEntity.getHeatPlanNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						recount = Integer.parseInt(rs.getString("COUNT"));
					}
					rs.close();
					psta.close();
					if (recount != 0) {
						cor.setV_errMsg("此炉有离线或者有废品,请先返线或者撤销剔除废品！");
						return cor;
					}

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmHttDownLineManage.QueryReturnMatNo1");// 查询返线材料号
					psta = con.prepareStatement(sql);

					psta.setString(1, HttOfflineResultEntity.getHeatPlanNo());
					psta.setObject(2, Integer.parseInt(HttOfflineResultEntity
							.getReNum()) + 1);
					rs = psta.executeQuery();
					while (rs.next()) {
						matNo.add(rs.getString("MAT_NO"));
					}
					rs.close();
					psta.close();

					if (matNo.size() == 0) {
						cor.setV_errMsg("物料已发生改变,不允许撤销!");
						return cor;
					}

					// 已组炉撤销返线
					for (int j = 0; j < matNo.size(); j++) {
						// 删除管号队列表
						pstaDeletePort.setObject(1, HttOfflineResultEntity
								.getHeatPlanNo());
						pstaDeletePort.setObject(2, matNo.get(j));
						pstaDeletePort.addBatch();
					}
					pstaDeletePort.executeBatch();

					PlanService.deletePlnFurnJgx(HttOfflineResultEntity
							.getHeatPlanNo(), con);

					// 删除镦拔扩计划表
					pstaDeleteOff.setObject(1, HttOfflineResultEntity
							.getHeatPlanNo());
					pstaDeleteOff.addBatch();
					pstaDeleteOff.executeBatch();

					// 删除镦拔扩计划从表
					pstaDeleteOffC.setObject(1, HttOfflineResultEntity
							.getHeatPlanNo());
					pstaDeleteOffC.addBatch();
					pstaDeleteOffC.executeBatch();

					// 修改离线表返线支数
					pstaupdateOff.setObject(1, "0");
					pstaupdateOff.setObject(2, "0");
					pstaupdateOff.setObject(3, systime);
					pstaupdateOff.setObject(4, name);
					pstaupdateOff.setObject(5, "");
					pstaupdateOff.setObject(6, "");
					pstaupdateOff.setObject(7, HttOfflineResultEntity
							.getResultNo());
					pstaupdateOff.addBatch();

					List<HttGroupResultEntity> list = new ArrayList<HttGroupResultEntity>();
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmHttDownLineManage.QueryGroupVrpResult");// 查询组炉履历表信息
					psta = con.prepareStatement(sql);
					psta.setString(1, HttOfflineResultEntity.getGroupId());
					rs = psta.executeQuery();
					list = EntityTool.getEntitysByRs(rs,
							HttGroupResultEntity.class);
					rs.close();
					psta.close();

					for (HttGroupResultEntity groupList : list) {
						matNo = new ArrayList<String>();
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmHttDownLineManage.QueryNewFurnMatNo");// 查询管号队列离线材料号
						psta = con.prepareStatement(sql);

						psta.setString(1, groupList.getLxResultNo());
						psta.setString(2, groupList.getLxResultNo());
						rs = psta.executeQuery();
						List<PortHttBatchSampleResultEntity> portData = EntityTool
								.getEntitysByRs(rs,
										PortHttBatchSampleResultEntity.class);
						rs.close();
						psta.close();

						if (portData.size() < Integer.parseInt(groupList
								.getGroupNum())) {
							cor.setV_errMsg("管号队列无足够的另组炉管,数据异常！");
							return cor;
						}

						for (int i = 0; i < portData.size(); i++) {
							if (!portData.get(i).getMatStatus().equals("40"))
								PlanService.AddOffLineMatWithResultNo(con, "F",
										name, "11", portData.get(i).getMatNo(),
										portData.get(i).getOpProcess(),
										portData.get(i).getHeatPlanNo(),
										portData.get(i).getResultNo());

							pstaupdateStatus.setObject(1, portData.get(i)
									.getHeatPlanNo());
							pstaupdateStatus.setObject(2, portData.get(i)
									.getProcessSeq());
							pstaupdateStatus.setObject(3, portData.get(i)
									.getMatNo());
							pstaupdateStatus.addBatch();
						}
					}

					pstaupdateStatus.executeBatch();

				} else {
					PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(con,
							HttOfflineResultEntity.getHeatPlanNo());

					if (pln == null) {
						cor.setV_errMsg("无炉计划数据,,不允许此操作！");
						return cor;
					}

					if (pln.getPlanstatus().equals("30")) {
						cor.setV_errMsg("该炉对应的计划已结炉,不允许次操作！");
						return cor;
					}
					if (pln.getPlanstatus().equals("40")) {
						cor.setV_errMsg("该炉对应的计划已关闭,不允许次操作！");
						return cor;
					}

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmHttDownLineManage.QueryReturnMatNo");// 查询管号队列返线材料号
					psta = con.prepareStatement(sql);
					psta.setString(1, HttOfflineResultEntity.getResultNo());
					rs = psta.executeQuery();
					while (rs.next()) {
						matNo.add(rs.getString("MAT_NO"));
					}
					rs.close();
					psta.close();
					if (matNo.size() == 0) {
						cor.setV_errMsg("物料已发生改变,不允许撤销!");
						return cor;
					}

					if (matNo.size() < Integer.parseInt(HttOfflineResultEntity
							.getReNum())) {
						cor.setV_errMsg("物料已发生改变,无法撤销！!");
						return cor;
					}

					for (int i = 0; i < matNo.size(); i++) {
						// 修改管号队列
						pstaUpdatePort.setObject(1, "20");
						pstaUpdatePort.setObject(2, "10");
						pstaUpdatePort.setObject(3, HttOfflineResultEntity
								.getGxsl()
								+ "-"
								+ HttOfflineResultEntity.getGxgw()
								+ "-"
								+ HttOfflineResultEntity.getGxch()
								+ "-"
								+ HttOfflineResultEntity.getGxdw()
								+ "-"
								+ HttOfflineResultEntity.getGxdj()
								+ "-"
								+ HttOfflineResultEntity.getGxrj()
								+ "-"
								+ HttOfflineResultEntity.getGxlj()
								+ "-"
								+ HttOfflineResultEntity.getGxwgjy()
								+ "-"
								+ "0"
								+ "-"
								+ HttOfflineResultEntity.getGxts()
								+ "-" + "0");
						pstaUpdatePort.setObject(4, "");
						pstaUpdatePort.setObject(5, HttOfflineResultEntity
								.getFlagStoveNo());
						pstaUpdatePort.setObject(6, "0");
						pstaUpdatePort.setObject(7, HttOfflineResultEntity
								.getHeatPlanNo());
						pstaUpdatePort.setObject(8, matNo.get(i));
						pstaUpdatePort.addBatch();

						if (pln.getRealProcessSeq().equals(
								pln.getRealProcessSeq())
								&& HttOfflineResultEntity.getReturnProcess()
										.compareToIgnoreCase("600204") <= 0
								&& !HttOfflineResultEntity.getBatchNo().equals(
										"")) {
							pstaRecoverBatchInfo.setObject(1,
									HttOfflineResultEntity.getBatchNo());
							pstaRecoverBatchInfo.setObject(2,
									HttOfflineResultEntity.getHeatPlanNo());
							pstaRecoverBatchInfo.setObject(3, matNo.get(i));
							pstaRecoverBatchInfo.setObject(4,
									HttOfflineResultEntity.getBatchNo());
							pstaRecoverBatchInfo.addBatch();

							pstaDeleteBackUpBatchInfo.setObject(1,
									HttOfflineResultEntity.getHeatPlanNo());
							pstaDeleteBackUpBatchInfo
									.setObject(2, matNo.get(i));
							pstaDeleteBackUpBatchInfo.setObject(3,
									HttOfflineResultEntity.getBatchNo());

							pstaDeleteBackUpBatchInfo.addBatch();
						}

						PlanService.AddOffLineMatWithResultNo(con, "F", name,
								"11", matNo.get(i), "", HttOfflineResultEntity
										.getHeatPlanNo(),
								HttOfflineResultEntity.getResultNo());

					}

					pstaUpdatePort.executeBatch();
					pstaRecoverBatchInfo.executeBatch();
					pstaDeleteBackUpBatchInfo.executeBatch();

					// 修改离线表返线支数
					pstaupdateOff.setObject(1, "0");
					pstaupdateOff.setObject(2, "0");
					pstaupdateOff.setObject(3, systime);
					pstaupdateOff.setObject(4, name);
					pstaupdateOff.setObject(5, "");
					pstaupdateOff.setObject(6, HttOfflineResultEntity
							.getHeatPlanNo());
					pstaupdateOff.setObject(7, HttOfflineResultEntity
							.getResultNo());
					pstaupdateOff.addBatch();
				}
			}
			pstaupdateOff.executeBatch();
			cor.setV_errMsg("撤销返线成功！");
			con.commit();

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (con != null) {
				try {
					cor.setV_errMsg(e.getMessage());
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return cor;
	}

	/**
	 * 获取最大委外编号
	 * 
	 * @param conn
	 *            c
	 * @throws Exception
	 *             异常处理
	 */
	public static String queryEntrustrMax(Connection conn) throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmHttDownLineManage.queryEntrustrMax");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, matter1.format(dt));
		psta.setString(2, matter.format(dt));
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("SUBCONTRACT_NO");
		}
		rs.close();
		psta.close();
		return seq;
	}

	/**
	 *委外加工
	 * 
	 * @param result
	 * @return
	 */
	public CoreReturnObject doOutSourc(ArrayList<String> parm,
			ArrayList<String> parm1) {
		CoreReturnObject cor = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String systime = dateFormat.format(now);
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String addOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.AddOutSourc");// 新增委外加工表
			PreparedStatement pstaAddSourc = con.prepareStatement(addOff);
			String updateOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdateOffOutSourc");// 修改离线表委外支数
			PreparedStatement pstaupdateOff = con.prepareStatement(updateOff);
			String memo = parm1.get(0);// 委托说明
			String plineCode = parm1.get(1);
			String name = parm1.get(2);
			String bc = parm1.get(4);
			String bz = parm1.get(3);

			String entrusNo = queryEntrustrMax(con);
			int g = 01;

			for (String str : parm) {
				HttOfflineResultEntity vrpOfflineEntity = EntityTool
						.getEntityByJSONStr(str.toString(),
								HttOfflineResultEntity.class);
				String plnStrat = queryPlnZYDbkStrat(con, vrpOfflineEntity
						.getHeatPlanNo());
				if (plnStrat.equals("3")) {
					cor.setV_errMsg("该炉对应的计划已结炉,不允许次操作！");
					return cor;
				}
				if (plnStrat.equals("4")) {
					cor.setV_errMsg("该炉对应的计划已关闭,不允许次操作！");
					return cor;
				}
				int count = 0;
				int remCount = 0;// 返线支数
				String groupStart = "";// 组炉状态
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.QueryOffLineGroupStart");// 查询是委外
				psta = con.prepareStatement(sql);
				psta.setString(1, vrpOfflineEntity.getJudgeStoveNo());
				psta.setString(2, vrpOfflineEntity.getBatchNo());
				psta.setString(3, vrpOfflineEntity.getResultNo());
				psta.setString(4, vrpOfflineEntity.getHeatPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					groupStart = rs.getString("GROUP_LOG");
					count = Integer.parseInt(rs.getString("COUNT_NUM"));
					remCount = Integer
							.parseInt(rs.getString("SUBCONTRACT_NUM"));
				}
				rs.close();
				psta.close();
				if (remCount == 0) {
					cor.setV_errMsg("选择的炉号已委外加工,不允许此操作!");
					return cor;
				}
				// 新增委外加工表
				pstaAddSourc.setObject(1, entrusNo);
				pstaAddSourc.setObject(2, StringTool.formatDecimal(g, "00"));
				pstaAddSourc.setObject(3, vrpOfflineEntity.getPlineCode());
				pstaAddSourc.setObject(4, vrpOfflineEntity.getPlineName());
				pstaAddSourc.setObject(5, vrpOfflineEntity.getStationCode());
				pstaAddSourc.setObject(6, vrpOfflineEntity.getStationDesc());
				pstaAddSourc.setObject(7, vrpOfflineEntity.getHeatPlanNo());
				pstaAddSourc.setObject(8, vrpOfflineEntity.getZyBatchId());
				pstaAddSourc.setObject(9, vrpOfflineEntity.getProPlanId());
				pstaAddSourc.setObject(10, vrpOfflineEntity.getGxPlanNo());
				pstaAddSourc.setObject(11, vrpOfflineEntity.getJudgeStoveNo());
				pstaAddSourc.setObject(12, vrpOfflineEntity.getBatchNo());
				pstaAddSourc.setObject(13, vrpOfflineEntity.getProduccode());
				pstaAddSourc.setObject(14, vrpOfflineEntity.getProducname());
				pstaAddSourc.setObject(15, vrpOfflineEntity.getSteelcode());
				pstaAddSourc.setObject(16, vrpOfflineEntity.getSteelname());
				pstaAddSourc.setObject(17, vrpOfflineEntity.getGradecode());
				pstaAddSourc.setObject(18, vrpOfflineEntity.getGradename());
				pstaAddSourc.setObject(19, vrpOfflineEntity.getModelCode());
				pstaAddSourc.setObject(20, vrpOfflineEntity.getModelDesc());
				pstaAddSourc.setObject(21, vrpOfflineEntity.getStdCode());
				pstaAddSourc.setObject(22, vrpOfflineEntity.getStdName());
				pstaAddSourc.setObject(23, vrpOfflineEntity.getStdStyle());
				pstaAddSourc.setObject(24, vrpOfflineEntity.getStdStyleDesc());
				pstaAddSourc.setObject(25, vrpOfflineEntity.getActDimater());
				pstaAddSourc.setObject(26, vrpOfflineEntity.getActHeight());
				pstaAddSourc.setObject(27, vrpOfflineEntity.getActLen());
				pstaAddSourc.setObject(28, vrpOfflineEntity.getActLenMin());
				pstaAddSourc.setObject(29, vrpOfflineEntity.getActLenMax());
				pstaAddSourc.setObject(30, "");// 工艺文件号
				pstaAddSourc.setObject(31, vrpOfflineEntity.getOfflineNum());
				pstaAddSourc.setObject(32, vrpOfflineEntity.getOfflineWt());
				pstaAddSourc.setObject(33, name);
				pstaAddSourc.setObject(34, bc);
				pstaAddSourc.setObject(35, bz);
				pstaAddSourc.setObject(36, systime);
				pstaAddSourc.setObject(37, "00");
				pstaAddSourc.setObject(38, memo);
				pstaAddSourc.setObject(39, vrpOfflineEntity.getResultNo());
				pstaAddSourc.addBatch();
				g++;
				// 修改离线表返线支数
				pstaupdateOff.setObject(1, vrpOfflineEntity.getOfflineNum());
				pstaupdateOff.setObject(2, vrpOfflineEntity.getOfflineWt());
				pstaupdateOff.setObject(3, systime);
				pstaupdateOff.setObject(4, name);
				pstaupdateOff.setObject(5, vrpOfflineEntity.getResultNo());
				pstaupdateOff.addBatch();
			}
			pstaAddSourc.executeBatch();
			pstaupdateOff.executeBatch();

			cor.setV_errMsg("委外加工成功！");
			con.commit();

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (con != null) {
				try {
					cor.setV_errMsg(e.getMessage());
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return cor;
	}

	/**
	 *撤销委外加工
	 * 
	 * @param result
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject doCancelOutSourc(ArrayList<Object> parm) {
		CoreReturnObject cor = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String deleteOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.deleteOutSourc");// 删除委外加工表
			PreparedStatement pstaDeleteSourc = con.prepareStatement(deleteOff);
			String updateOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.UpdateOffOutSourc");// 修改离线表委外支数
			PreparedStatement pstaupdateOff = con.prepareStatement(updateOff);

			for (int i = 0; i < parm.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) parm.get(i);
				String resuNo = list.get(0);// 离线主键
				String subNo = list.get(1);// 委托单号
				String subNoSeq = list.get(2);// 委托单序号
				String bc = list.get(4);
				String bz = list.get(3);
				String groupStart = "";// 状态
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.QuerySubConStart");// 查询委托状态
				psta = con.prepareStatement(sql);
				psta.setString(1, subNo);
				psta.setString(2, subNoSeq);
				rs = psta.executeQuery();
				if (rs.next()) {
					groupStart = rs.getString("SUBCONTRACT_LOG");
				}
				rs.close();
				psta.close();
				if (groupStart.equals("")) {
					cor.setV_errMsg("选择委外单已撤销,不允许此操作!");
					return cor;
				} else if (!groupStart.equals("00")) {
					cor.setV_errMsg("选择委外单不是委外申请状态,不允许此操作!");
					return cor;
				}
				// 删除委外加工表
				pstaDeleteSourc.setObject(1, subNo);
				pstaDeleteSourc.setObject(2, subNoSeq);
				pstaDeleteSourc.addBatch();

				// 修改离线表返线支数
				pstaupdateOff.setObject(1, "0");
				pstaupdateOff.setObject(2, "0");
				pstaupdateOff.setObject(3, "");
				pstaupdateOff.setObject(4, "");
				pstaupdateOff.setObject(5, resuNo);
				pstaupdateOff.addBatch();
			}
			pstaDeleteSourc.executeBatch();
			pstaupdateOff.executeBatch();

			cor.setV_errMsg("撤销委外加工成功！");
			con.commit();

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (con != null) {
				try {
					cor.setV_errMsg(e.getMessage());
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return cor;
	}

	/**
	 * 修改表示炉号
	 * 
	 * @param parm
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject doUpdateFlagStoveNo(ArrayList<Object> parm) {
		CoreReturnObject cor = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		// String sql = "";
		// PreparedStatement psta = null;
		// ResultSet rs = null;
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String updateOff = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.doUpdateFlagStoveNo");// 修改离线标识炉号
			PreparedStatement pstaupdateOff = con.prepareStatement(updateOff);

			String updateMatNo = CoreXmlSqlParsersFactory
					.getSql("FrmHttDownLineManage.doUpdateFlagStoveNo1");// 修改离线标识炉号
			PreparedStatement pstaupdateOff1 = con
					.prepareStatement(updateMatNo);

			for (int i = 0; i < parm.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) parm.get(i);
				String resuNo = list.get(1);// 离线主键
				String subNo = list.get(0);//
				String HeatPlanID = list.get(2);

				// 修改离线表返线支数
				pstaupdateOff.setObject(1, subNo);
				pstaupdateOff.setObject(2, resuNo);
				pstaupdateOff.addBatch();

				// 修改离线表返线支数
				pstaupdateOff1.setObject(1, subNo);
				pstaupdateOff1.setObject(2, HeatPlanID);
				pstaupdateOff1.setObject(3, resuNo);
				pstaupdateOff1.addBatch();
			}
			pstaupdateOff.executeBatch();
			pstaupdateOff1.executeBatch();

			cor.setV_errMsg("标识炉号修改成功！");
			con.commit();

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (con != null) {
				try {
					cor.setV_errMsg(e.getMessage());
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return cor;
	}

	/**
	 * 委内更换产线
	 * 
	 * @param HeatPlanIDs
	 *            需要委外的数据
	 * @param PlineCode
	 *            要更换产线的产线代码
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject DoInterDelegation(ArrayList<String> HeatPlanIDs,
			String PlineCode, String PlineName) {
		CoreReturnObject cor = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();

		try {
			con.setAutoCommit(false); // 取消自动提交事务

			String sql = "";

			for (String HeatPlanID : HeatPlanIDs) {

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.updateRclOffLine");
				PreparedStatement ps = con.prepareStatement(sql);
				ps.setObject(1, PlineCode);
				ps.setObject(2, PlineCode);
				ps.setObject(3, HeatPlanID);
				ps.executeUpdate();
				ps.close();

				/*
				 * sql =CoreXmlSqlParsersFactory.getSql(
				 * "FrmHttDownLineManage.updateRclPort"); ps =
				 * con.prepareStatement(sql); ps.setObject(1,PlineCode);
				 * ps.setObject(2,PlineCode); ps.setObject(3,HeatPlanID);
				 * ps.executeUpdate(); ps.close();
				 */

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.updateRclMPlan");
				ps = con.prepareStatement(sql);
				ps.setObject(1, PlineCode);
				ps.setObject(2, PlineCode);
				ps.setObject(3, PlineCode);
				ps.setObject(4, PlineCode);
				ps.setObject(5, HeatPlanID);
				ps.executeUpdate();
				ps.close();

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmHttDownLineManage.updateRclCPlan");
				ps = con.prepareStatement(sql);
				ps.setObject(1, PlineCode);
				ps.setObject(2, PlineCode);
				ps.setObject(3, PlineCode);
				ps.setObject(4, PlineCode);
				ps.setObject(5, HeatPlanID);
				ps.executeUpdate();
				ps.close();

			}

			cor.setV_errMsg("委内成功！");
			con.commit();

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (con != null) {
				try {
					cor.setV_errMsg(e.getMessage());
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return cor;
	}

	/**
	 * 根据产线能力与重量计算时长
	 * 
	 * @param wgt
	 * @param capacity
	 * @param beginTime
	 * @return TimeEntity
	 * @throws ParseException
	 */
	public TimeEntity calculateTime(int num, double capacity, String beginTime)
			throws ParseException {
		TimeEntity time = new TimeEntity();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		int userMinute = 0;
		if (capacity <= 0) {
			userMinute = 0;
		} else {
			userMinute = (int) Math.ceil((num / capacity * 60));
		}
		int userSecond = (int) userMinute * 60;
		String endTime = df.format(dateAddSecond(df.parse(beginTime),
				userSecond));
		time.setBeginTime(beginTime);
		time.setEndTime(endTime);
		time.setUserTime(String.valueOf(userMinute));
		return time;
	}

	/**
	 * 时间自动调整
	 * 
	 * @param con
	 * @param gxProSeq
	 * @param plineCode
	 * @param planTimeE
	 * @param processCode
	 * @throws SQLException
	 * @throws ParseException
	 */
	public void timeIncrease(Connection con, int gxProSeq, String plineCode,
			String planTimeE, String processCode) throws SQLException,
			ParseException {
		String sql = "";
		String updateSql = "";
		if (processCode.equals("B")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_ORDER_CAST_S t ";
			updateSql = "UPDATE PLN_ORDER_CAST_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("C")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_ORDER_DZ_S t";
			updateSql = "UPDATE PLN_ORDER_DZ_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("D")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_ORDER_ZG_S t";
			updateSql = "UPDATE PLN_ORDER_ZG_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("E")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_ORDER_DBK_S t";
			updateSql = "UPDATE PLN_ORDER_DBK_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("F")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_ORDER_RCL_S t";
			updateSql = "UPDATE PLN_ORDER_RCL_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("G")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from pln_order_jgx_s t";
			updateSql = "UPDATE PLN_ORDER_JGX_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("H")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_GX_JG_PROP_S t ";
			updateSql = "UPDATE PLN_GX_JG_PROP_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		}
		sql += " where t.pline_code=? and to_number(t.gx_pro_seq)>to_number(?) order by to_number(t.gx_pro_seq)";
		List<String[]> strArrList = new ArrayList<String[]>();
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, plineCode);
		ps.setObject(2, gxProSeq);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String[] strArr = new String[4];
			strArr[0] = rs.getString("plan_usetime");
			strArr[1] = rs.getString("pro_plan_id");
			strArr[2] = rs.getString("gx_plan_no");
			strArr[3] = rs.getString("pro_month");
			strArrList.add(strArr);
		}
		rs.close();
		ps.close();
		if (strArrList == null || strArrList.size() == 0) {
			return;
		}
		// 修改时间
		ps = con.prepareStatement(updateSql);
		final int batchSize = 1000;
		int count = 0;
		DateFormat df = new SimpleDateFormat("yyyy-MM");
		String planTimeB = planTimeE;
		for (int i = 0; i < strArrList.size(); i++) {
			String[] strArr = strArrList.get(i);
			if (processCode.equals("D")) {
				if (df.parse(strArr[3]).getTime() > df.parse(planTimeB)
						.getTime()) {
					planTimeB = strArr[3] + "-01 00:00:00";
				}
			}
			String planTimeE1 = addTime(planTimeB, strArr[0]);
			ps.setObject(1, planTimeB);
			ps.setObject(2, planTimeE1);
			ps.setObject(3, strArr[1]);
			ps.setObject(4, strArr[2]);
			ps.addBatch();
			if (++count % batchSize == 0) {
				ps.executeBatch();
			}
			planTimeB = planTimeE1;
		}
		ps.executeBatch();
		ps.close();
	}

	/**
	 * 时间计算
	 * 
	 * @param beginTime
	 *            开始时间
	 * @param useMinute
	 *            用时(分)
	 * @return String 结束时间
	 * @throws ParseException
	 */
	public static String addTime(String beginTime, String useMinute)
			throws ParseException {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		int useSecond = (int) (Double.parseDouble(useMinute) * 60);
		String endTime = df
				.format(dateAddSecond(df.parse(beginTime), useSecond));
		return endTime;
	}

	/**
	 * 时间增加秒
	 * 
	 * @param beginTime
	 * @param second
	 * @return
	 */
	public static Date dateAddSecond(Date beginTime, int second) {
		Calendar rightNow = Calendar.getInstance();
		rightNow.setTime(beginTime);
		rightNow.add(Calendar.SECOND, second);
		Date dt = rightNow.getTime();
		return dt;
	}

	/**
	 * 序号自增减
	 * 
	 * @param con
	 * @param plineCode
	 * @param gxProSeqB
	 * @param gxProSeqE
	 *            (如果没有上限，请设为负数)
	 * @param num
	 * @param processCode
	 * @throws SQLException
	 */
	public void seqIncrease(Connection con, String plineCode, int gxProSeqB,
			int gxProSeqE, int num, String processCode) throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = "update  PLN_ORDER_CAST_S T ";
		} else if (processCode.equals("C")) {
			sql = "update PLN_ORDER_DZ_S T ";
		} else if (processCode.equals("D")) {
			sql = "update  PLN_ORDER_ZG_S T ";
		} else if (processCode.equals("E")) {
			sql = "update  PLN_ORDER_DBK_S T ";
		} else if (processCode.equals("F")) {
			sql = "update  PLN_ORDER_RCL_S T ";
		} else if (processCode.equals("G")) {
			sql = "update PLN_ORDER_JGX_S T";
		} else if (processCode.equals("H")) {
			sql = "update PLN_GX_JG_PROP_S T";
		}
		sql += " SET T.GX_PRO_SEQ = TO_NUMBER(T.GX_PRO_SEQ) + TO_NUMBER(?) WHERE T.PLINE_CODE = ? AND TO_NUMBER(T.GX_PRO_SEQ) >= TO_NUMBER(?)";
		if (gxProSeqE > 0) {
			sql += "  AND TO_NUMBER(T.GX_PRO_SEQ) < TO_NUMBER(?) ";
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, num);
		ps.setObject(2, plineCode);
		ps.setObject(3, gxProSeqB);
		if (gxProSeqE > 0) {
			ps.setObject(4, gxProSeqE);
		}
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 查询最大排产序号
	 * 
	 * @param con
	 * @param proPlanId
	 * @param processCode
	 * @return
	 * @throws SQLException
	 */
	public String getMaxGxPlanNo(Connection con, String proPlanId,
			String processCode) throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_CAST_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("C")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_DZ_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("D")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_ZG_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("E")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_DBK_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("F")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_RCL_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("G")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_JGX_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("H")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_GX_JG_PROP_S T WHERE T.PRO_PLAN_ID =?";
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, proPlanId);
		ResultSet rs = ps.executeQuery();
		String gxPlanNo = "";
		if (rs.next()) {
			gxPlanNo = rs.getString("GX_PLAN_NO");
		}
		rs.close();
		ps.close();
		return gxPlanNo;
	}

}
