/**
 * 
 */
package com.steering.mes.zgmil.coup;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.steering.comm.db.DBCommon;

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

import com.steering.common.EntityTool;
import com.steering.common.StringTool;
import com.steering.mes.signature.MeanValueCalculation;
import com.steering.mes.zgmil.entity.MilOfflineReslutEntity;
import com.steering.mes.zgmil.entity.MilPlanEntity3;

/**
 * @author ZJAY 下线，操作方法类
 */
public class FrmOffLine extends DBCommon {

	/**
	 * 查询可下线主计划
	 * 
	 * @param Node
	 * @return
	 */
	public CoreReturnObject GetMILPlan(String plineCode, String Node,
			String jugeNo, String proPlanId, String gxPlanNo) {
		String sql = "";
		if (Node.equals("TS"))// 探伤工序
		{
			if (plineCode.equals("C010"))// ET
			{
				sql = CoreXmlSqlParsersFactory.getSql("OffLine.GetMILPlan11");
			}
			if (plineCode.equals("C009") || plineCode.equals("C008")
					|| plineCode.equals("C017"))// MT
			{
				sql = CoreXmlSqlParsersFactory.getSql("OffLine.GetMILPlan12");
			}
			if (plineCode.equals(""))// UL
			{
				sql = CoreXmlSqlParsersFactory.getSql("OffLine.GetMILPlan13");
			}

		} else if (Node.equals("JZ")) {
			sql = CoreXmlSqlParsersFactory.getSql("OffLine.GetMILPlan0");
		} else {
			sql = CoreXmlSqlParsersFactory.getSql("OffLine.GetMILPlanXX");
		}
		return this.getData(sql, new Object[] { jugeNo, plineCode, proPlanId,
				gxPlanNo });
	}

	/**
	 * 
	 * @param heatno
	 *            炉号
	 * @param Node
	 *            工序 0-矫直 1-探伤
	 * @param test
	 *            0-矫直，1-ET，2-MT，3-UT
	 * @param ScrapNumBefore
	 *            可下线支数
	 * @param OfflineNum
	 *            下线支数
	 * @param isAll
	 *            是否整炉下线 0- 否 1- 是 1-更新对应实绩表 2-更新跟踪记录表 3-更新主表
	 * @param DelNums
	 *            剔除总支数
	 * @return
	 */
	public CoreReturnObject Offline(String heatno, String Node, String test,
			Integer ScrapNumBefore, Integer OfflineNum, Integer DelNums,
			String colno) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement psta = null;
		PreparedStatement pstats = null;
		PreparedStatement pstaR = null;
		PreparedStatement psta1 = null;
		PreparedStatement pstaNum = null;
		PreparedStatement pstaqa = null;

		ResultSet rsNum = null;

		String sql = "";
		String sqlts = "";
		String sqlR = "";
		String sql1 = "";
		String sqlNum = "";
		String sqlqa = "";

		int AddScrapSlabCount1 = 0;
		int AddScrapSlabCount2 = 0;
		int DelNum = 0;

		try {
			conn = this.getDao("TgDao").getConnection();
			conn.setAutoCommit(false);
			if (Node.equals("0"))// 矫直工序
			{
				sql = CoreXmlSqlParsersFactory.getSql("OffLine.UpdateRack0");
				sqlts = CoreXmlSqlParsersFactory
						.getSql("OffLine.UpdatetsRack0");
				if (test.equals("1"))// 1#台
				{
					sqlR = CoreXmlSqlParsersFactory
							.getSql("OffLine.UpdateResult01");
				}
				if (test.equals("2"))// 2#台
				{
					sqlR = CoreXmlSqlParsersFactory
							.getSql("OffLine.UpdateResult02");
				}
				if (test.equals("3"))// 3#台
				{
					sqlR = CoreXmlSqlParsersFactory
							.getSql("OffLine.UpdateResult03");
				}
				pstaR = conn.prepareStatement(sqlR);
				pstaR.setInt(1, OfflineNum);
				pstaR.setInt(2, OfflineNum);
				pstaR.setString(3, heatno);
				pstaR.executeUpdate();

				psta = conn.prepareStatement(sql);
				psta.setString(1, heatno);
				psta.setString(2, heatno);
				psta.setString(3, test);
				psta.setInt(4, OfflineNum);
				AddScrapSlabCount1 = psta.executeUpdate();
				psta.close();

				// -----探伤部分下线
				pstats = conn.prepareStatement(sqlts);
				pstats.setString(1, heatno);
				pstats.setString(2, heatno);
				pstats.setString(3, test);
				pstats.setInt(4, OfflineNum);
				AddScrapSlabCount1 = pstats.executeUpdate();
				pstats.close();

				sqlNum = "SELECT count(*) FROM MIL_STRAIGH_RACK t WHERE t.JUDGE_STOVE_NO='";
				sqlNum += heatno;
				sqlNum += "' AND t.status=1 AND t.SEQ BETWEEN ";
				sqlNum += ScrapNumBefore - OfflineNum + 1 + DelNums;
				sqlNum += " AND ";
				sqlNum += ScrapNumBefore + DelNums;

				pstaNum = conn.prepareStatement(sqlNum);
				rsNum = pstaNum.executeQuery();
				while (rsNum.next()) {
					DelNum = rsNum.getInt(1);
				}

			}
			if (Node.equals("1"))// 探伤工序
			{
				sql = CoreXmlSqlParsersFactory.getSql("OffLine.UpdateRack1");
				if (test.equals("1"))// ET
				{
					if (colno.equals("1")) {
						sqlR = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResult111");
					}
					if (colno.equals("2")) {
						sqlR = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResult112");
					}
					if (colno.equals("3")) {
						sqlR = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResult113");
					}
				}
				if (test.equals("2"))// MT
				{
					if (colno.equals("1")) {
						sqlR = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResult121");
					}
					if (colno.equals("2")) {
						sqlR = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResult122");
					}
				}
				if (test.equals("3"))// UT
				{
					if (colno.endsWith("1")) {
						sqlR = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResult131");
					}
					if (colno.endsWith("2")) {
						sqlR = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResult132");
					}
				}

				pstaR = conn.prepareStatement(sqlR);
				pstaR.setInt(1, OfflineNum);
				pstaR.setInt(2, OfflineNum);
				pstaR.setString(3, heatno);
				pstaR.executeUpdate();

				psta = conn.prepareStatement(sql);
				psta.setString(1, colno);
				psta.setString(2, heatno);
				psta.setString(3, heatno);
				psta.setInt(4, OfflineNum);
				AddScrapSlabCount1 = psta.executeUpdate();
				psta.close();

				sqlNum = "SELECT count(*) FROM MIL_TESTING_RACK t WHERE t.JUDGE_STOVE_NO='";
				sqlNum += heatno;
				sqlNum += "' AND t.status=1 AND t.SEQ BETWEEN ";
				sqlNum += ScrapNumBefore - OfflineNum + 1 + DelNums;
				sqlNum += " AND ";
				sqlNum += ScrapNumBefore + DelNums;

				pstaNum = conn.prepareStatement(sqlNum);
				rsNum = pstaNum.executeQuery();
				while (rsNum.next()) {
					DelNum = rsNum.getInt(1);
				}
			}
			// -----------部分操作台整炉下线（无AND t.col_no=?）
			// psta = conn.prepareStatement(sql);

			// int first=0;
			// if(ScrapNumBefore.equals(OfflineNum))
			// {
			// first = 1; //ScrapNumBefore - OfflineNum + 1+DelNums
			// }
			// else
			// {
			// first=ScrapNumBefore - OfflineNum+1+DelNums;
			// if(DelNum>0)
			// {
			// first=first-DelNum;
			// }
			// }

			// psta.setString(1, heatno);
			// psta.setInt(2, first);
			// psta.setInt(3, ScrapNumBefore+DelNums);
			// AddScrapSlabCount1 = psta.executeUpdate();
			// psta.close();
			// ---------------

			// if (Node.equals("0"))
			// {
			// //-----探伤部分下线
			// pstats = conn.prepareStatement(sqlts);
			// pstats.setString(1, heatno);
			// pstats.setString(2, colno);
			// pstats.setInt(3, OfflineNum);
			// AddScrapSlabCount1 = pstats.executeUpdate();
			// psta.close();
			//			
			// }
			// //-------矫直部分跟踪记录表修改
			sqlqa = CoreXmlSqlParsersFactory.getSql("OffLine.UpdateQARack");
			pstaqa = conn.prepareStatement(sqlqa);
			pstaqa.setString(1, heatno);
			pstaqa.setString(2, heatno);
			pstaqa.setInt(3, OfflineNum);
			AddScrapSlabCount1 = pstaqa.executeUpdate();
			pstaqa.close();

			if (ScrapNumBefore.equals(OfflineNum))// 整炉下线
			{
				sql1 = CoreXmlSqlParsersFactory.getSql("OffLine.UpdateMILPLAN");
				psta1 = conn.prepareStatement(sql1);
				psta1.setString(1, heatno);
				// AddScrapSlabCount2 = psta1.executeUpdate();
				psta1.close();
			}
			conn.commit();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		cro.setResult(1);
		return cro;
	}

	/**
	 * 本方法值针对探伤的下线回退 1.管号队列， 2.实绩 3.人工质检管号队列
	 * 
	 * @param heatno
	 * @param Node
	 * @param test
	 * @param ScrapNumBefore
	 * @param OfflineNum
	 * @param DelNums
	 * @param colno
	 * @return
	 */
	public CoreReturnObject OfflineBack(String heatno, String Node,
			String test, Integer ScrapNumBefore, Integer OfflineNum,
			Integer DelNums, String colno) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement pstarack = null;
		PreparedStatement pstaresult = null;
		PreparedStatement pstaqa = null;

		ResultSet rsNum = null;

		String sqlrack = "";
		String sqlresult = "";
		String sqlqa = "";

		try {
			conn = this.getDao("TgDao").getConnection();
			conn.setAutoCommit(false);

			if (Node.equals("1")) {
				sqlrack = CoreXmlSqlParsersFactory
						.getSql("OffLine.UpdateRackBack1");
				if (test.equals("1"))// ET
				{
					if (colno.equals("1")) {
						sqlresult = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResultBack111");
					}
					if (colno.equals("2")) {
						sqlresult = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResultBack112");
					}
					if (colno.equals("3")) {
						sqlresult = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResultBack113");
					}
				}
				if (test.equals("2"))// MT
				{
					if (colno.equals("1")) {
						sqlresult = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResultBack121");
					}
					if (colno.equals("2")) {
						sqlresult = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResultBack122");
					}
				}
				if (test.equals("3"))// UT
				{
					if (colno.endsWith("1")) {
						sqlresult = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResultBack131");
					}
					if (colno.endsWith("2")) {
						sqlresult = CoreXmlSqlParsersFactory
								.getSql("OffLine.UpdateResultBack132");
					}
				}
				pstarack = conn.prepareStatement(sqlrack);
				pstarack.setString(1, heatno);
				pstarack.setString(2, heatno);
				pstarack.setString(3, colno);
				pstarack.setInt(4, OfflineNum);
				pstarack.executeUpdate();
				pstarack.close();

				pstaresult = conn.prepareStatement(sqlresult);
				pstaresult.setInt(1, OfflineNum);
				pstaresult.setInt(2, OfflineNum);
				pstaresult.setString(3, heatno);
				pstaresult.executeUpdate();
				pstaresult.close();

				sqlqa = CoreXmlSqlParsersFactory
						.getSql("OffLine.UpdateQARackBack");
				pstaqa = conn.prepareStatement(sqlqa);
				pstaqa.setString(1, heatno);
				pstaqa.setString(2, heatno);
				pstaqa.setInt(3, OfflineNum);
				pstaqa.executeUpdate();
				pstaqa.close();

			}
			conn.commit();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		cro.setResult(1);
		return cro;
	}

	/**
	 * 获取跟踪记录表总支数
	 */
	public CoreReturnObject GetCount(String heatno, String node, String test,
			String colno) {
		String sql = "";
		if (node.equals("0")) {
			sql = "select count(*) as counts from MIL_STRAIGH_RACK t WHERE t.Judge_Stove_No='";
			sql += heatno;
			sql += "' AND t.status<>1 AND t.offline_flag =0";
			sql += " AND t.col_no='";
			sql += test;
			sql += "' AND t.mat_no is not null";
			// sql+="' AND t.mat_no like '";
			// sql+=heatno;
			// sql+="%'";
			sql += " AND t.COL_SHIFT is null";
			sql += " AND t.COL_GROUP is null";
		}
		if (node.equals("1")) {
			sql = "select count(*) as counts from MIL_TESTING_RACK t WHERE t.Judge_Stove_No='";
			sql += heatno;
			sql += "' AND t.status<>1 AND t.offline_flag =0";
			sql += " AND t.col_no='";
			sql += colno;
			sql += "' AND t.mat_no is not null";
			// sql+="' AND t.mat_no like '";
			// sql+=heatno;
			// sql+="%'";
			sql += " AND t.COL_SHIFT is null";
			sql += " AND t.COL_GROUP is null";
		}
		return this.getData(sql);
	}

	public CoreReturnObject GetCountNEW(String heatno, String node,
			String test, String colno) {
		String sql = "";
		if (node.equals("1")) {
			sql = "select count(*) as counts from MIL_TESTING_RACK t WHERE t.Judge_Stove_No='";
			sql += heatno;
			sql += "' AND t.status<>1 AND t.offline_flag =0";
			sql += " AND (t.col_no='' OR t.col_no is null )";
			// sql+=" AND t.mat_no is not null";
			// sql+="' AND t.mat_no like '";
			// sql+=heatno;
			// sql+="%'";
		}
		return this.getData(sql);
	}

	/***
	 * 查询可下线支数
	 * 
	 * @param heatNo
	 * @return
	 */
	public CoreReturnObject getOffineCount(String heatNo, String plineCode,
			String proPlanId, String gxPlanNo) {
		String sql = CoreXmlSqlParsersFactory.getSql("OffLine.getOffineCount");
		if (plineCode.equals("C009") || plineCode.equals("C008")
				|| plineCode.equals("C017")) {
			sql = sql.replace("#TABLENAME#", "MIL_MT_RESULT");
		} else if (plineCode.equals("C010")) {
			sql = sql.replace("#TABLENAME#", "MIL_ET_RESULT");
		}
		return this.getData(sql, new Object[] { heatNo, proPlanId, gxPlanNo });
	}

	/***
	 * 查询矫直可下线支数
	 * 
	 * @param heatNo
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject getStraighteningCount(String heatNo,
			String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("OffLine.getStraighteningCount");
		return this.getData(sql, new Object[] { heatNo, plineCode });
	}

	/***
	 * 查询下线点可下线支数
	 * 
	 * @param heatNo
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject getOfflineXXCount(String heatNo, String plineCode,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("OffLine.getOfflineXXCount", new Object[] {
				heatNo, proPlanId, gxPlanNo, plineCode });
	}

	/*
	 * 获取剔除支数
	 */
	public CoreReturnObject GetDelNum(String heatno, String node) {
		String sql = "";
		if (node.equals("0")) {
			sql = "select count(*) as counts from MIL_STRAIGH_RACK t WHERE t.Judge_Stove_No='";
			sql += heatno;
			sql += "' AND t.status=1 AND t.offline_flag =0";
		}
		if (node.equals("1")) {
			sql = "select count(*) as counts from MIL_TESTING_RACK t WHERE t.Judge_Stove_No='";
			sql += heatno;
			sql += "' AND t.status=1 AND t.offline_flag =0";
		}
		return this.getData(sql);
	}

	/**
	 * 是否要插入下线实绩表
	 * 
	 * @param heatno
	 * @param processno
	 * @return
	 */
	public CoreReturnObject isInsertOfflineResult(String heatno,
			String processno, String proPlanId, String gxPlanNo) {
		String sql = "Select t.* from Mil_Offline_Reslut t Where t.judge_stove_no='";
		sql += heatno + "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
				+ "','/')";
		sql += " AND t.offline_pro='";
		sql += processno;
		sql += "'";
		return this.getData(sql);
	}

	public CoreReturnObject OfflineResultBack(String heatno, String Node,
			String test, Integer ScrapNumBefore, Integer OfflineNum,
			Integer DelNums, String colno) {
		String sql = "UPDATE MIL_OFFLINE_RESLUT T SET T.OFFLINE_NUM=T.OFFLINE_NUM-"
				+ OfflineNum + "";

		sql += " WHERE  t.judge_stove_no='" + heatno;
		sql += "' AND t.offline_pro='TS'";

		return this.setData(sql);
	}

	/**
	 * 插入下线实绩
	 * 
	 * @param milofflineresult
	 * @return
	 */
	public CoreReturnObject InsertOfflineResult(
			MilOfflineReslutEntity milofflineresult) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("OffLine.InsertOfflineResult");
		sql = EntityTool.fillSqlByEntity(sql, milofflineresult);
		return this.setData(sql);
	}

	public CoreReturnObject UpdateOfflineResultNum(
			MilOfflineReslutEntity milofflineresult, String test, String colno) {
		String sql = "";
		if (milofflineresult.getOfflinePro().equals("JZ")) {
			if (test.equals("1")) {
				sql = CoreXmlSqlParsersFactory
						.getSql("OffLine.UpdateOfflineResultNum1");
			}
			if (test.equals("2")) {
				sql = CoreXmlSqlParsersFactory
						.getSql("OffLine.UpdateOfflineResultNum2");
			}
			if (test.equals("3")) {
				sql = CoreXmlSqlParsersFactory
						.getSql("OffLine.UpdateOfflineResultNum3");
			}
		}
		if (milofflineresult.getOfflinePro().equals("TS")) {
			if (colno.equals("1")) {
				sql = CoreXmlSqlParsersFactory
						.getSql("OffLine.UpdateOfflineResultNum1");
			}
			if (colno.equals("2")) {
				sql = CoreXmlSqlParsersFactory
						.getSql("OffLine.UpdateOfflineResultNum2");
			}
			if (colno.equals("3")) {
				sql = CoreXmlSqlParsersFactory
						.getSql("OffLine.UpdateOfflineResultNum3");
			}
		}
		sql = EntityTool.fillSqlByEntity(sql, milofflineresult);
		return this.setData(sql);
	}

	/**
	 * 更新下线实绩
	 * 
	 * @param milofflineresult
	 * @return
	 */
	public CoreReturnObject UpdateOfflineResult(
			MilOfflineReslutEntity milofflineresult, String node, String test,
			String colno) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("OffLine.UpdateOfflineResult");
		sql = EntityTool.fillSqlByEntity(sql, milofflineresult);
		return this.setData(sql);
	}

	public CoreReturnObject deleteOfflineResult(String heatno, String processno) {
		String sql = "DELETE from Mil_Offline_Reslut t Where t.judge_stove_no='";
		sql += heatno;
		sql += "' AND t.offline_pro='";
		sql += processno;
		sql += "'";
		return this.setData(sql);
	}

	/**
	 * 查询已下线支数
	 * 
	 * @param heatno
	 * @param node
	 * @return
	 */
	public CoreReturnObject GetCountHAS(String heatno, String node,
			String proPlanId, String gxPlanNo) {

		return this.getDataBySqlID("Offline.GetCountHAS", new Object[] {
				heatno, node, proPlanId, gxPlanNo });
	}

	/**
	 * 查询矫直已下线支数
	 * 
	 * @param heatno
	 * @param node
	 * @return
	 */
	public CoreReturnObject GetStraighteningCountHAS(String heatno, String node) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("Offline.GetStraighteningCountHAS");
		return this.getData(sql, new Object[] { heatno, node });
	}

	/**
	 * 查询下线点已下线支数
	 * 
	 * @param heatno
	 * @param node
	 * @return
	 */
	public CoreReturnObject getXXCountHAS(String heatno, String proPlanId,
			String gxPlanNo) {

		return this.getDataBySqlID("Offline.getXXCountHAS", new Object[] {
				heatno, proPlanId, gxPlanNo });
	}

	/**
	 * 获取探伤可调整支数
	 * 
	 * @param heatno
	 * @param test
	 * @return
	 */
	public CoreReturnObject GetTsNum(String heatno, String test) {
		String sql = "";
		sql = "select count(*) as counts from MIL_TESTING_RACK t WHERE t.Judge_Stove_No='";
		sql += heatno;
		sql += "' AND t.status=0 AND t.col_no=";
		sql += test;
		return this.getData(sql);
	}

	/**
	 * 子管分配调整
	 * 
	 * @param heatno
	 *            炉号
	 * @param Num
	 *            调整的数目
	 * @param StrColNofrom
	 *            子管来源台
	 * @param StrColNoto
	 *            子管去 向台
	 * @return
	 */
	public CoreReturnObject ColNoChanges(String heatno, String node,
			Integer Num, String StrColNofrom, String StrColNoto) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql1 = "";
		String sql2 = "";
		String sql3 = "";

		sql1 += "UPDATE MIL_STRAIGH_RACK t SET t.COL_NO =";
		sql1 += StrColNoto;
		sql1 += " WHERE t.JUDGE_STOVE_NO='"
				+ heatno
				+ "' AND  t.SEQ in (SELECT SEQ FROM (SELECT a.SEQ AS SEQ FROM MIL_STRAIGH_RACK a  WHERE a.JUDGE_STOVE_NO ='";
		sql1 += heatno;
		sql1 += "' AND a.COL_NO =";
		sql1 += StrColNofrom;
		sql1 += " AND a.STATUS =0 AND a.mat_no is not null ORDER BY a.SEQ desc) WHERE rownum between 1 AND ";
		sql1 += Num;
		sql1 += " )";

		sql2 += "UPDATE MIL_TESTING_RACK t SET t.COL_NO =";
		sql2 += StrColNoto;
		sql2 += " WHERE t.JUDGE_STOVE_NO='"
				+ heatno
				+ "' AND  t.SEQ in (SELECT SEQ FROM (SELECT a.SEQ AS SEQ FROM MIL_TESTING_RACK a  WHERE a.JUDGE_STOVE_NO ='";
		sql2 += heatno;
		sql2 += "' AND a.COL_NO =";
		sql2 += StrColNofrom;
		sql2 += " AND a.STATUS =0   ORDER BY a.SEQ desc) WHERE rownum between 1 AND ";
		sql2 += Num;
		sql2 += " )";

		sql3 += "UPDATE MIL_TESTING_RACK t SET t.COL_NO =";
		sql3 += StrColNoto;
		sql3 += " WHERE t.JUDGE_STOVE_NO='"
				+ heatno
				+ "' AND  t.SEQ in (SELECT SEQ FROM (SELECT a.SEQ AS SEQ FROM MIL_TESTING_RACK a  WHERE a.JUDGE_STOVE_NO ='";
		sql3 += heatno;
		sql3 += "' AND a.COL_NO =";
		sql3 += StrColNofrom;
		sql3 += " AND a.STATUS =0 AND a.mat_no is not null ORDER BY a.SEQ desc) WHERE rownum between 1 AND ";
		sql3 += Num;
		sql3 += " )";

		if (node.equals("0")) {
			sqllist.clear();
			sqllist.add(sql1);
			// sqllist.add(sql2);
		}
		if (node.equals("1")) {
			sqllist.clear();
			sqllist.add(sql3);
		}

		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	public CoreReturnObject GetTestingChangeNum(String heatno,
			String StrColNofrom) {
		String sql = "select count(t.judge_stove_no) AS counts from MIL_TESTING_RACK t WHERE t.status=0 AND t.judge_stove_no='";
		sql += heatno;
		sql += "' AND t.col_no =";
		sql += StrColNofrom;
		return this.getData(sql);
	}

	/***
	 * 下线操作(YM)
	 * 
	 * @param milPlanTity
	 * @param offlineNum
	 * @return
	 */
	public CoreReturnObject offLineTS(String milPlanTity, String offlineNum,
			String userName, String userGroup, String userOrder, String flag,
			ArrayList<String> list, String strInBound, String strInMemo,
			String plineCode, String proPlanId, String gxPlanNo) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String yearMoth = StringTool.GetBalYear(now,StringTool.GetSupplyUnit(plineCode));// 改25号结转
		String systime = dateFormat.format(now);
		String str[] = null;
		double strWgt = 0.0;
		String jugeNo = "";// 下线入在线库炉号
		String bacthNo = "";// 下线入在线库批号
		String groupNo = "";// 组号
		String lengthCp[] = null;// 长度范围
		String materiaNo = "";// 物料码
		String materiaName = "";// 物料描述
		String INWL_ID = "";// 投入物料编码
		String INWL_DESC = "";// 投入物料描述
		String CRAFT_SEQ = ""; // 工艺序号
		String judgeStdDes = ""; // 判定标准集合
		String cic = ""; // cic
		String offlineDoc = ""; // 离线单号
		String belongCode = ""; // 所属权
		String belongName = ""; // 所属权
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertOfflineResultSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.offLineTS");
			PreparedStatement insertOfflineResultPsta = connection
					.prepareStatement(insertOfflineResultSql);
			String insertMatSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertMatTS");
			PreparedStatement insertMatPsta = connection
					.prepareStatement(insertMatSql);
			String insertInListSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertInListX");// 待处理数据入在线库
			PreparedStatement insertListPsta = connection
					.prepareStatement(insertInListSql);
			String insertMilSlabSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertMilSlab");
			PreparedStatement insertMilSlabPsta = connection
					.prepareStatement(insertMilSlabSql);
			MilPlanEntity3 milPlantity = EntityTool.getEntityByJSONStr(
					milPlanTity, MilPlanEntity3.class);

			sql = CoreXmlSqlParsersFactory.getSql("FrmOffLine.offlineResult");// 查询离线实绩
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			psta.setString(2, milPlantity.getPlineCode());
			psta.setString(3, milPlantity.getProPlanId());
			psta.setString(4, milPlantity.getGxPlanNo());
			psta.setString(5, "TS");
			rs = psta.executeQuery();
			if (rs.next()) {
				offlineDoc = rs.getString("OFFLINE_DOC");
			}
			rs.close();
			psta.close();

			if ("".equals(offlineDoc) || offlineDoc == null) {
				sql = CoreXmlSqlParsersFactory.getSql("FrmOffLine.offlineDoc");// 离线单号
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if (rs.next()) {
					offlineDoc = rs.getString("OFFLINE_DOC");
				}
				rs.close();
				psta.close();
			}

			jugeNo = milPlantity.getJudgeStoveNo().replaceFirst("-.*", "");
			bacthNo = "X";
			groupNo = "001";

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectMaterialNo");// 查询物料码
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getProPlanId());
			psta.setString(2, milPlantity.getGxPlanNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				judgeStdDes = rs.getString("judgeStdDes");
				cic = rs.getString("CIC");
				materiaNo = rs.getString("OUTWL_ID");
				materiaName = rs.getString("OUTWL_DESC");
				INWL_ID = rs.getString("INWL_ID");
				INWL_DESC = rs.getString("INWL_DESC");
				CRAFT_SEQ = rs.getString("CRAFT_SEQ");
			}
			rs.close();
			psta.close();

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectBelongCode");// 查询产线、科室
			psta = connection.prepareStatement(sql);
			psta.setString(1, plineCode);
			rs = psta.executeQuery();
			if (rs.next()) {
				belongCode = rs.getString("DEPARTMENT_CODE");
				belongName = rs.getString("DEPARTMENT_DESC");
				milPlantity.setPlineName(rs.getString("PLINE_NAME"));
			}
			rs.close();
			psta.close();

			String inListDoc = querySendSqlDoc(connection, strInBound,
					strInMemo, plineCode, systime);// 入库单号
			String inListSeq = querySendSql(connection, inListDoc, plineCode); // 入库流水号
			int n = Integer.parseInt(inListSeq.substring(
					inListSeq.length() - 4, inListSeq.length()));

			String matNo = queryMatNoM(connection, jugeNo, bacthNo); // 材料号
			int g = Integer.parseInt(matNo.substring(matNo.length() - 4, matNo
					.length()));
			lengthCp = milPlantity.getLengthRange().split("[-]");
			str = milPlantity.getPipeSize().split("[*]");
			strWgt = 0.02466 * Double.parseDouble(str[1])
					* (Double.parseDouble(str[0]) - Double.parseDouble(str[1]))
					* Double.parseDouble(milPlantity.getTargetLength())
					* Integer.parseInt(offlineNum) / 1000;
			List<double[]> list1 = MeanValueCalculation.MeanCalculation(Double
					.parseDouble(new DecimalFormat("0.000").format(strWgt)),
					Integer.parseInt(offlineNum));
			for (int j = 0; j < list1.size(); j++) {
				double[] conW = list1.get(j);
				if ((int) conW[0] >= 0) {
					for (int z = 0; z < (int) conW[0]; z++) {
						insertMatPsta.setString(1, jugeNo);
						insertMatPsta.setString(2, bacthNo);
						insertMatPsta.setString(3, groupNo);
						insertMatPsta.setString(4, list.get(0));
						insertMatPsta.setString(5, list.get(1));
						insertMatPsta.setString(6, list.get(2));
						insertMatPsta.setString(7, list.get(3));
						insertMatPsta.setString(8, list.get(4));
						insertMatPsta.setString(9, (jugeNo + bacthNo)
								+ StringTool.formatDecimal(g, "0000"));
						insertMatPsta.setString(10, list.get(5));
						insertMatPsta.setString(11, list.get(6));
						insertMatPsta.setString(12, list.get(7));
						insertMatPsta.setString(13, list.get(8));

						insertMatPsta.setString(14, jugeNo);
						insertMatPsta.setString(15, bacthNo);
						insertMatPsta.setString(16, groupNo);
						insertMatPsta.setString(17, "1");
						insertMatPsta.setString(18, String.valueOf(conW[1]));
						insertMatPsta.setString(19, systime);
						insertMatPsta.setString(20, (jugeNo + bacthNo)
								+ StringTool.formatDecimal(g, "0000"));
						insertMatPsta.setString(21, "801401");
						insertMatPsta.setString(22, "80150104");
						insertMatPsta.setString(23, milPlantity.getPlineCode());
						insertMatPsta.setString(24, milPlantity.getPlineCode());
						insertMatPsta.setString(25, "11");
						insertMatPsta.setString(26, milPlantity.getId());
						insertMatPsta.setString(27, milPlantity
								.getJudgeStoveNo());
						insertMatPsta.setString(28, "");
						insertMatPsta.setString(29, milPlantity.getVarieties());
						insertMatPsta.setString(30, "");
						insertMatPsta.setString(31, milPlantity.getSteelname());
						insertMatPsta.setString(32, "");
						insertMatPsta.setString(33, milPlantity.getPipeSize()
								.replace("*", "x"));
						insertMatPsta.setString(34, "");
						insertMatPsta.setString(35, milPlantity.getGradename());
						insertMatPsta.setString(36, "");
						insertMatPsta
								.setString(37, milPlantity.getBuckleType());
						insertMatPsta.setString(38, "");
						insertMatPsta.setString(39, milPlantity
								.getRollStandrad());
						insertMatPsta.setString(40, belongCode);
						insertMatPsta.setString(41, belongName);
						insertMatPsta.setString(42, milPlantity.getStdStyle());
						insertMatPsta.setString(43, milPlantity
								.getStdStyleDesc());
						insertMatPsta.setString(44, str[0].toString());
						insertMatPsta.setString(45, str[1].toString());
						insertMatPsta.setString(46, lengthCp[0].toString());
						insertMatPsta.setString(47, lengthCp[1].toString());
						insertMatPsta.setString(48, milPlantity.getLotNo());
						insertMatPsta
								.setString(49, milPlantity.getContractNo());
						insertMatPsta.setString(50, milPlantity
								.getTargetLength());
						insertMatPsta.setString(51, milPlantity.getTarget());
						insertMatPsta.setString(52, milPlantity
								.getProcessStatus());
						insertMatPsta.setString(53, jugeNo);
						insertMatPsta.setString(54, milPlantity.getStoveNo());

						insertMatPsta.setString(55, materiaNo);
						insertMatPsta.setString(56, materiaName);
						insertMatPsta.setString(57, INWL_ID);
						insertMatPsta.setString(58, INWL_DESC);
						insertMatPsta.setString(59, cic);
						insertMatPsta.setString(60, judgeStdDes);
						insertMatPsta.setString(61, CRAFT_SEQ);
						insertMatPsta.setString(62, milPlantity.getProPlanId());
						insertMatPsta.setString(63, milPlantity.getGxPlanNo());
						insertMatPsta.setString(64, offlineDoc); // 离线单号
						insertMatPsta.addBatch();

						// milPlantity.getProPlanId()
						insertListPsta.setString(1, list.get(5));
						insertListPsta.setString(2, list.get(6));
						insertListPsta.setString(3, inListDoc
								+ StringTool.formatDecimal(n, "0000"));
						insertListPsta.setString(4, inListDoc);
						insertListPsta.setString(5, "800701");
						insertListPsta.setString(6, "产出入库");
						insertListPsta.setString(7, (jugeNo + bacthNo)
								+ StringTool.formatDecimal(g, "0000"));
						insertListPsta.setString(8, milPlantity.getLotNo()); // 生产批号
						insertListPsta.setString(9, milPlantity.getStoveNo()); // 熔炼炉号
						insertListPsta.setString(10, jugeNo);
						insertListPsta.setString(11, bacthNo);
						insertListPsta.setString(12, groupNo);

						insertListPsta.setString(13, "");
						insertListPsta
								.setString(14, milPlantity.getVarieties());
						insertListPsta.setString(15, "");// 标准
						insertListPsta.setString(16, milPlantity
								.getRollStandrad());
						insertListPsta.setString(17, "");
						insertListPsta
								.setString(18, milPlantity.getSteelname());
						insertListPsta.setString(19, "");
						insertListPsta.setString(20, milPlantity
								.getStdStyleDesc());
						insertListPsta.setString(21, "");
						insertListPsta.setString(22, milPlantity.getPipeSize()
								.replace("*", "x"));
						insertListPsta.setString(23, "");
						insertListPsta.setString(24, milPlantity
								.getBuckleType());

						insertListPsta.setString(25, milPlantity.getDimater());
						insertListPsta.setString(26, milPlantity.getHeight());
						insertListPsta
								.setString(27, milPlantity.getLengthmin());
						insertListPsta
								.setString(28, milPlantity.getLengthmax());
						insertListPsta.setString(29, "1");
						insertListPsta.setString(30, String.valueOf(conW[1]));
						insertListPsta.setString(31, String.valueOf(conW[1]));
						insertListPsta.setString(32, list.get(5));
						insertListPsta.setString(33, list.get(6));
						insertListPsta.setString(34, list.get(0));
						insertListPsta.setString(35, "");
						insertListPsta.setString(36, "1");
						insertListPsta.setString(37, list.get(4));
						insertListPsta.setString(38, systime);
						insertListPsta.setString(39, "");// 合同号
						insertListPsta.setString(40, "");
						insertListPsta.setString(41, "");
						insertListPsta.setString(42, "");
						insertListPsta.setString(43, "");
						insertListPsta.setString(44, "");

						insertListPsta.setString(45, "801401");
						insertListPsta.setString(46, "80150101");
						insertListPsta.setString(47, systime);
						insertListPsta.setString(48, milPlantity
								.getTargetLength());// 长度
						insertListPsta.setString(49, list.get(7));
						insertListPsta.setString(50, list.get(8));
						insertListPsta.setString(51, milPlantity
								.getRollStandrad());
						insertListPsta
								.setString(52, milPlantity.getPlineCode());
						insertListPsta
								.setString(53, milPlantity.getPlineName());
						insertListPsta
								.setString(54, milPlantity.getGradecode());
						insertListPsta
								.setString(55, milPlantity.getGradename());
						insertListPsta.setString(56, yearMoth);
						insertListPsta.setString(57, systime);
						insertListPsta.setString(58, "");
						insertListPsta.setString(59, "801302");
						insertListPsta.setString(60, "机组");
						insertListPsta
								.setString(61, milPlantity.getPlineCode());
						insertListPsta
								.setString(62, milPlantity.getPlineName());
						insertListPsta.setString(63, "");
						insertListPsta.setString(64, "");
						insertListPsta.setString(65, milPlantity
								.getContractNo());
						insertListPsta.setString(66, "11");
						insertListPsta.setString(67, milPlantity
								.getJudgeStoveNo());
						insertListPsta.setString(68, userOrder);
						insertListPsta.setString(69, userGroup);
						insertListPsta.addBatch();

						g++;
						n++;
					}
				}
			}
			insertMilSlabPsta.setString(1, milPlantity.getJudgeStoveNo());
			insertMilSlabPsta.setString(2, milPlantity.getPlineCode());
			insertMilSlabPsta.setString(3, proPlanId);
			insertMilSlabPsta.setString(4, gxPlanNo);
			insertMilSlabPsta.setInt(5, Integer.parseInt(offlineNum));
			insertMilSlabPsta.setString(6, "");
			insertMilSlabPsta.setString(7, "1");
			insertMilSlabPsta.setString(8, milPlantity.getJudgeStoveNo());
			insertMilSlabPsta.setString(9, "10");
			insertMilSlabPsta.setString(10, "0");
			insertMilSlabPsta.setString(11, "1");
			insertMilSlabPsta.setString(12, userName);
			insertMilSlabPsta.setString(13, userOrder);
			insertMilSlabPsta.setString(14, userGroup);
			insertMilSlabPsta.setString(15, milPlantity.getId());
			insertMilSlabPsta.setString(16, proPlanId);
			insertMilSlabPsta.setString(17, gxPlanNo);
			insertMilSlabPsta.addBatch();

			insertOfflineResultPsta.setString(1, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(2, milPlantity.getPlineCode());
			insertOfflineResultPsta.setString(3, proPlanId);
			insertOfflineResultPsta.setString(4, gxPlanNo);
			insertOfflineResultPsta.setString(5, offlineNum);
			insertOfflineResultPsta.setString(6, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(7, milPlantity.getVarieties());
			insertOfflineResultPsta.setString(8, milPlantity.getSteelcode());
			insertOfflineResultPsta.setString(9, milPlantity.getSteelname());
			insertOfflineResultPsta.setString(10, milPlantity.getGradecode());
			insertOfflineResultPsta.setString(11, milPlantity.getGradename());
			insertOfflineResultPsta
					.setString(12, milPlantity.getPipeSizeCode());
			insertOfflineResultPsta.setString(13, milPlantity.getPipeSize());// 规格
			insertOfflineResultPsta.setString(14, milPlantity
					.getBuckleTypeCode());
			insertOfflineResultPsta.setString(15, milPlantity.getBuckleType());
			insertOfflineResultPsta.setString(16, milPlantity
					.getRollStandradCode());
			insertOfflineResultPsta
					.setString(17, milPlantity.getRollStandrad());// 标准
			insertOfflineResultPsta.setString(18, milPlantity.getStdStyle());
			insertOfflineResultPsta
					.setString(19, milPlantity.getStdStyleDesc());
			insertOfflineResultPsta.setString(20, milPlantity.getLengthRange());
			insertOfflineResultPsta.setString(21, milPlantity.getContractNo());
			insertOfflineResultPsta.setString(22, milPlantity
					.getVarietiesCode());
			insertOfflineResultPsta.setString(23, milPlantity.getLotNo());
			insertOfflineResultPsta
					.setString(24, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(25, str[0].toString());
			insertOfflineResultPsta.setString(26, str[1].toString());
			insertOfflineResultPsta
					.setString(27, milPlantity.getTargetLength());

			insertOfflineResultPsta.setString(28, milPlantity.getPlineCode());
			insertOfflineResultPsta.setString(29, offlineNum);

			insertOfflineResultPsta.setString(30, flag);

			insertOfflineResultPsta.setString(31, systime);
			insertOfflineResultPsta.setString(32, userName);
			insertOfflineResultPsta.setString(33, userOrder);
			insertOfflineResultPsta.setString(34, userGroup);
			insertOfflineResultPsta.setString(35, new DecimalFormat("0.000")
					.format(strWgt));// 重量
			insertOfflineResultPsta.setString(36, milPlantity.getTarget());
			insertOfflineResultPsta.setString(37, milPlantity.getImpProcess());

			insertOfflineResultPsta.setString(38, milPlantity.getPlineCode());
			insertOfflineResultPsta.setString(39, milPlantity.getPlineCode());
			insertOfflineResultPsta.setString(40, milPlantity.getPlineCode());
			insertOfflineResultPsta.setString(41, offlineNum);
			insertOfflineResultPsta
					.setString(42, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(43, milPlantity.getPlineCode());

			insertOfflineResultPsta.setString(44, milPlantity.getPlineCode());
			insertOfflineResultPsta.setString(45, offlineNum);
			insertOfflineResultPsta
					.setString(46, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(47, milPlantity.getPlineCode());

			// insertOfflineResultPsta.setInt(44, Integer.parseInt(flag));
			// insertOfflineResultPsta.setString(45,
			// milPlantity.getJudgeStoveNo());
			// insertOfflineResultPsta.setString(46,
			// milPlantity.getJudgeStoveNo());
			// insertOfflineResultPsta.setString(47,
			// milPlantity.getPlineCode());
			// insertOfflineResultPsta.setString(48, offlineNum);
			// insertOfflineResultPsta.setString(49, systime);
			// insertOfflineResultPsta.setString(50,
			// milPlantity.getJudgeStoveNo());
			// insertOfflineResultPsta.setString(51,
			// milPlantity.getPlineCode());

			insertOfflineResultPsta
					.setString(48, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(49, milPlantity.getPlineCode());
			insertOfflineResultPsta.setInt(50, Integer.parseInt(offlineNum));
			insertOfflineResultPsta.setString(51, systime);
			insertOfflineResultPsta
					.setString(52, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(53, milPlantity.getPlineCode());

			insertOfflineResultPsta.setInt(54, Integer.parseInt(flag));
			insertOfflineResultPsta
					.setString(55, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta
					.setString(56, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta
					.setString(57, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta
					.setString(58, milPlantity.getJudgeStoveNo());

			insertMilSlabPsta.executeBatch();
			insertOfflineResultPsta.addBatch();
			insertMatPsta.executeBatch();
			insertListPsta.executeBatch();
			insertOfflineResultPsta.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 milPlanTity
	 * @param offlineNum
	 * @return
	 */
	public CoreReturnObject offLineJZ(String milPlanTity, String offlineNum,
			String userName, String userGroup, String userOrder, String flag,
			ArrayList<String> list, String strInBound, String strInMemo,
			String plineCode) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String systime = dateFormat.format(now);
		String yearMoth = df.format(now);
		String str[] = null;
		double strWgt = 0.0;
		String jugeNo = "";// 下线入在线库炉号
		String bacthNo = "";// 下线入在线库批号
		String groupNo = "";// 组号
		String lengthCp[] = null;// 长度范围
		String offlineDoc = ""; // 离线单号

		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertOfflineResultSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.offLineJZ");
			PreparedStatement insertOfflineResultPsta = connection
					.prepareStatement(insertOfflineResultSql);
			String insertMatSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertMatTS");
			PreparedStatement insertMatPsta = connection
					.prepareStatement(insertMatSql);
			String insertInListSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertInListX");// 待处理数据入在线库
			PreparedStatement insertListPsta = connection
					.prepareStatement(insertInListSql);
			String insertMilSlabSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertMilSlab1");
			PreparedStatement insertMilSlabPsta = connection
					.prepareStatement(insertMilSlabSql);
			MilPlanEntity3 milPlantity = EntityTool.getEntityByJSONStr(
					milPlanTity, MilPlanEntity3.class);

			sql = CoreXmlSqlParsersFactory.getSql("FrmOffLine.offlineDoc");// 离线单号
			psta = connection.prepareStatement(sql);
			rs = psta.executeQuery();
			if (rs.next()) {
				offlineDoc = rs.getString("OFFLINE_DOC");
			}
			rs.close();
			psta.close();

			jugeNo = milPlantity.getJudgeStoveNo().replaceFirst("-.*", "");
			bacthNo = "X";
			groupNo = "001";

			if (plineCode.equals("C010")) {
				milPlantity.setPlineName("168机组");
			} else if (plineCode.equals("C017")) {
				milPlantity.setPlineName("460机组");
			} else if (plineCode.equals("C009")) {
				milPlantity.setPlineName("258机组");
			} else if (plineCode.equals("C008")) {
				milPlantity.setPlineName("250机组");
			}

			String inListDoc = querySendSqlDoc(connection, strInBound,
					strInMemo, plineCode, systime);// 入库单号
			String inListSeq = querySendSql(connection, inListDoc, plineCode); // 入库流水号
			int n = Integer.parseInt(inListSeq.substring(
					inListSeq.length() - 4, inListSeq.length()));

			String matNo = queryMatNoM(connection, jugeNo, bacthNo); // 材料号
			int g = Integer.parseInt(matNo.substring(matNo.length() - 4, matNo
					.length()));
			lengthCp = milPlantity.getLengthRange().replace("米", "").split(
					"[-]");
			str = milPlantity.getPipeSize().split("[*]");
			strWgt = 0.02466 * Double.parseDouble(str[1])
					* (Double.parseDouble(str[0]) - Double.parseDouble(str[1]))
					* Double.parseDouble(milPlantity.getTargetLength())
					* Integer.parseInt(offlineNum) / 1000;
			List<double[]> list1 = MeanValueCalculation.MeanCalculation(Double
					.parseDouble(new DecimalFormat("0.000").format(strWgt)),
					Integer.parseInt(offlineNum));
			for (int j = 0; j < list1.size(); j++) {
				double[] conW = list1.get(j);
				if ((int) conW[0] >= 0) {
					for (int z = 0; z < (int) conW[0]; z++) {
						insertMatPsta.setString(1, jugeNo);
						insertMatPsta.setString(2, bacthNo);
						insertMatPsta.setString(3, groupNo);
						insertMatPsta.setString(4, list.get(0));
						insertMatPsta.setString(5, list.get(1));
						insertMatPsta.setString(6, list.get(2));
						insertMatPsta.setString(7, list.get(3));
						insertMatPsta.setString(8, list.get(4));
						insertMatPsta.setString(9, (jugeNo + bacthNo)
								+ StringTool.formatDecimal(g, "0000"));
						insertMatPsta.setString(10, list.get(5));
						insertMatPsta.setString(11, list.get(6));
						insertMatPsta.setString(12, list.get(7));
						insertMatPsta.setString(13, list.get(8));

						insertMatPsta.setString(14, jugeNo);
						insertMatPsta.setString(15, bacthNo);
						insertMatPsta.setString(16, groupNo);
						insertMatPsta.setString(17, "1");
						insertMatPsta.setString(18, String.valueOf(conW[1]));
						insertMatPsta.setString(19, systime);
						insertMatPsta.setString(20, (jugeNo + bacthNo)
								+ StringTool.formatDecimal(g, "0000"));
						insertMatPsta.setString(21, "801401");
						insertMatPsta.setString(22, "80150104");
						insertMatPsta.setString(23, milPlantity.getPlineCode());
						insertMatPsta.setString(24, milPlantity.getPlineName());
						insertMatPsta.setString(25, "11");
						insertMatPsta.setString(26, milPlantity.getId());
						insertMatPsta.setString(27, milPlantity
								.getJudgeStoveNo());
						insertMatPsta.setString(28, "");
						insertMatPsta.setString(29, milPlantity.getVarieties());
						insertMatPsta.setString(30, "");
						insertMatPsta.setString(31, milPlantity.getSteelname());
						insertMatPsta.setString(32, "");
						insertMatPsta.setString(33, milPlantity.getPipeSize()
								.replace("*", "x"));
						insertMatPsta.setString(34, "");
						insertMatPsta.setString(35, milPlantity.getGradename());
						insertMatPsta.setString(36, "");
						insertMatPsta
								.setString(37, milPlantity.getBuckleType());
						insertMatPsta.setString(38, "");
						insertMatPsta.setString(39, milPlantity
								.getRollStandrad());
						insertMatPsta.setString(40, list.get(5));
						insertMatPsta.setString(41, list.get(6));
						insertMatPsta.setString(42, milPlantity.getStdStyle());
						insertMatPsta.setString(43, milPlantity
								.getStdStyleDesc());
						insertMatPsta.setString(44, str[0].toString());
						insertMatPsta.setString(45, str[1].toString());
						insertMatPsta.setString(46, lengthCp[0].toString());
						insertMatPsta.setString(47, lengthCp[1].toString());
						insertMatPsta.setString(48, milPlantity.getLotNo());
						insertMatPsta
								.setString(49, milPlantity.getContractNo());
						insertMatPsta.setString(50, milPlantity
								.getTargetLength());
						insertMatPsta.setString(51, milPlantity.getTarget());
						insertMatPsta.setString(52, milPlantity
								.getProcessStatus());
						insertMatPsta.setString(53, jugeNo);
						insertMatPsta.setString(54, milPlantity.getStoveNo());

						insertMatPsta.addBatch();

						insertListPsta.setString(1, list.get(5));
						insertListPsta.setString(2, list.get(6));
						insertListPsta.setString(3, inListDoc
								+ StringTool.formatDecimal(n, "0000"));
						insertListPsta.setString(4, inListDoc);
						insertListPsta.setString(5, "800701");
						insertListPsta.setString(6, "产出入库");
						insertListPsta.setString(7, (jugeNo + bacthNo)
								+ StringTool.formatDecimal(g, "0000"));
						insertListPsta.setString(8, milPlantity.getLotNo());
						insertListPsta.setString(9, milPlantity.getStoveNo());
						insertListPsta.setString(10, jugeNo);
						insertListPsta.setString(11, bacthNo);
						insertListPsta.setString(12, groupNo);

						insertListPsta.setString(13, "");
						insertListPsta
								.setString(14, milPlantity.getVarieties());
						insertListPsta.setString(15, "");// 标准
						insertListPsta.setString(16, milPlantity
								.getRollStandrad());
						insertListPsta.setString(17, "");
						insertListPsta
								.setString(18, milPlantity.getSteelname());
						insertListPsta.setString(19, "");
						insertListPsta.setString(20, milPlantity
								.getStdStyleDesc());
						insertListPsta.setString(21, "");
						insertListPsta.setString(22, milPlantity.getPipeSize()
								.replace("*", "x"));
						insertListPsta.setString(23, "");
						insertListPsta.setString(24, milPlantity
								.getBuckleType());

						insertListPsta.setString(25, milPlantity.getDimater());
						insertListPsta.setString(26, milPlantity.getHeight());
						insertListPsta
								.setString(27, milPlantity.getLengthmin());
						insertListPsta
								.setString(28, milPlantity.getLengthmax());
						insertListPsta.setString(29, "1");
						insertListPsta.setString(30, String.valueOf(conW[1]));
						insertListPsta.setString(31, String.valueOf(conW[1]));
						insertListPsta.setString(32, list.get(5));
						insertListPsta.setString(33, list.get(6));
						insertListPsta.setString(34, list.get(0));
						insertListPsta.setString(35, "");
						insertListPsta.setString(36, "1");
						insertListPsta.setString(37, list.get(4));
						insertListPsta.setString(38, systime);
						insertListPsta.setString(39, "");// 合同号
						insertListPsta.setString(40, "");
						insertListPsta.setString(41, "");
						insertListPsta.setString(42, "");
						insertListPsta.setString(43, "");
						insertListPsta.setString(44, "");

						insertListPsta.setString(45, "801401");
						insertListPsta.setString(46, "80150101");
						insertListPsta.setString(47, systime);
						insertListPsta.setString(48, milPlantity
								.getTargetLength());// 长度
						insertListPsta.setString(49, list.get(7));
						insertListPsta.setString(50, list.get(8));
						insertListPsta.setString(51, milPlantity
								.getRollStandrad());
						insertListPsta
								.setString(52, milPlantity.getPlineCode());
						insertListPsta
								.setString(53, milPlantity.getPlineName());
						insertListPsta
								.setString(54, milPlantity.getGradecode());
						insertListPsta
								.setString(55, milPlantity.getGradename());
						insertListPsta.setString(56, yearMoth);
						insertListPsta.setString(57, systime);
						insertListPsta.setString(58, "");
						insertListPsta.setString(59, "801302");
						insertListPsta.setString(60, "机组");
						insertListPsta
								.setString(61, milPlantity.getPlineCode());
						insertListPsta
								.setString(62, milPlantity.getPlineName());
						insertListPsta.setString(63, "");
						insertListPsta.setString(64, "");
						insertListPsta.setString(65, milPlantity
								.getContractNo());
						insertListPsta.setString(66, "11");
						insertListPsta.setString(67, milPlantity
								.getJudgeStoveNo());
						insertListPsta.addBatch();
						g++;
						n++;
					}
				}
			}
			insertMilSlabPsta.setString(1, milPlantity.getJudgeStoveNo());
			insertMilSlabPsta.setString(2, milPlantity.getProPlanId());
			insertMilSlabPsta.setString(3, milPlantity.getGxPlanNo());
			insertMilSlabPsta.setString(4, milPlantity.getPlineCode());
			insertMilSlabPsta.setInt(5, Integer.parseInt(offlineNum));
			insertMilSlabPsta.setString(6, "");
			insertMilSlabPsta.setString(7, "1");
			insertMilSlabPsta.setString(8, milPlantity.getJudgeStoveNo());
			insertMilSlabPsta.setString(9, "9");
			insertMilSlabPsta.setString(10, "0");
			insertMilSlabPsta.setString(11, "1");
			insertMilSlabPsta.setString(12, userName);
			insertMilSlabPsta.setString(13, userOrder);
			insertMilSlabPsta.setString(14, userGroup);
			insertMilSlabPsta.setString(15, milPlantity.getId());
			insertMilSlabPsta.addBatch();

			insertOfflineResultPsta.setString(1, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(2, milPlantity.getPlineCode());
			insertOfflineResultPsta.setString(3, offlineNum);
			insertOfflineResultPsta.setString(4, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(5, milPlantity.getVarieties());
			insertOfflineResultPsta.setString(6, milPlantity.getSteelcode());
			insertOfflineResultPsta.setString(7, milPlantity.getSteelname());
			insertOfflineResultPsta.setString(8, milPlantity.getGradecode());
			insertOfflineResultPsta.setString(9, milPlantity.getGradename());
			insertOfflineResultPsta
					.setString(10, milPlantity.getPipeSizeCode());
			insertOfflineResultPsta.setString(11, milPlantity.getPipeSize());// 规格
			insertOfflineResultPsta.setString(12, milPlantity
					.getBuckleTypeCode());
			insertOfflineResultPsta.setString(13, milPlantity.getBuckleType()); // 扣型
			insertOfflineResultPsta.setString(14, milPlantity
					.getRollStandradCode());
			insertOfflineResultPsta
					.setString(15, milPlantity.getRollStandrad());// 标准
			insertOfflineResultPsta.setString(16, milPlantity.getStdStyle());
			insertOfflineResultPsta
					.setString(17, milPlantity.getStdStyleDesc()); // 标准类别
			insertOfflineResultPsta.setString(18, milPlantity.getLengthRange());
			insertOfflineResultPsta.setString(19, milPlantity.getContractNo());
			insertOfflineResultPsta.setString(20, milPlantity
					.getVarietiesCode()); // 品名代码
			insertOfflineResultPsta.setString(21, milPlantity.getLotNo());
			insertOfflineResultPsta
					.setString(22, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(23, str[0].toString());
			insertOfflineResultPsta.setString(24, str[1].toString());
			insertOfflineResultPsta
					.setString(25, milPlantity.getTargetLength());
			insertOfflineResultPsta.setString(26, milPlantity.getPlineCode());
			insertOfflineResultPsta.setString(27, offlineNum);
			insertOfflineResultPsta.setString(28, flag);
			insertOfflineResultPsta.setString(29, systime);
			insertOfflineResultPsta.setString(30, userName);
			insertOfflineResultPsta.setString(31, userOrder);
			insertOfflineResultPsta.setString(32, userGroup);
			insertOfflineResultPsta.setString(33, new DecimalFormat("0.000")
					.format(strWgt));// 重量
			insertOfflineResultPsta.setString(34, milPlantity.getTarget());
			insertOfflineResultPsta.setString(35, milPlantity.getImpProcess());

			insertOfflineResultPsta.setString(36, offlineNum);
			insertOfflineResultPsta.setString(37, offlineNum);
			insertOfflineResultPsta
					.setString(38, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(39, milPlantity.getPlineCode());

			insertOfflineResultPsta
					.setString(40, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(41, milPlantity.getPlineCode());
			insertOfflineResultPsta.setInt(42, Integer.parseInt(offlineNum));
			insertOfflineResultPsta.setString(43, systime);
			insertOfflineResultPsta
					.setString(44, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(45, milPlantity.getPlineCode());
			insertOfflineResultPsta.setInt(46, Integer.parseInt(flag));
			insertOfflineResultPsta
					.setString(47, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta
					.setString(48, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.addBatch();

			insertMilSlabPsta.executeBatch();
			insertMatPsta.executeBatch();
			insertListPsta.executeBatch();
			insertOfflineResultPsta.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 milPlanTity
	 * @param offlineNum
	 * @return
	 */
	public CoreReturnObject offLineXX(String milPlanTity, String offlineNum,
			String userName, String userGroup, String userOrder, String flag,
			ArrayList<String> list, String strInBound, String strInMemo,
			String plineCode) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String systime = dateFormat.format(now);
		String yearMoth = StringTool.GetBalYear(now,StringTool.GetSupplyUnit(plineCode));// 改25号结转
		String str[] = null;
		double strWgt = 0.0;
		String jugeNo = "";// 下线入在线库炉号
		String bacthNo = "";// 下线入在线库批号
		String groupNo = "";// 组号
		String lengthCp[] = null;// 长度范围

		String materiaNo = "";// 物料码
		String materiaName = "";// 物料描述
		String INWL_ID = "";// 投入物料编码
		String INWL_DESC = "";// 投入物料描述
		String CRAFT_SEQ = ""; // 工艺序号
		String judgeStdDes = ""; // 判定标准集合
		String cic = ""; // cic
		String offlineDoc = ""; // 离线单号
		String belongCode = ""; // 所属权
		String belongName = ""; // 所属权

		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertOfflineResultSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.offLineXX");
			PreparedStatement insertOfflineResultPsta = connection
					.prepareStatement(insertOfflineResultSql);
			String insertMatSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertMatTS");
			PreparedStatement insertMatPsta = connection
					.prepareStatement(insertMatSql);
			// String insertMilSlabSql =
			// CoreXmlSqlParsersFactory.getSql("FrmOffLine.insertMilSlab1");
			// PreparedStatement insertMilSlabPsta =
			// connection.prepareStatement(insertMilSlabSql);
			String insertInListSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertInListX");// 待处理数据入在线库
			PreparedStatement insertListPsta = connection
					.prepareStatement(insertInListSql);
			String insertInStoreResultSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertMilInstore");// 插入下线实绩表

			MilPlanEntity3 milPlantity = EntityTool.getEntityByJSONStr(
					milPlanTity, MilPlanEntity3.class);

			sql = CoreXmlSqlParsersFactory.getSql("FrmOffLine.offlineResult");// 查询离线实绩
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			psta.setString(2, milPlantity.getPlineCode());
			psta.setString(3, milPlantity.getProPlanId());
			psta.setString(4, milPlantity.getGxPlanNo());
			psta.setString(5, "XX");
			rs = psta.executeQuery();
			if (rs.next()) {
				offlineDoc = rs.getString("OFFLINE_DOC");
			}
			rs.close();
			psta.close();

			if ("".equals(offlineDoc) || offlineDoc == null) {
				sql = CoreXmlSqlParsersFactory.getSql("FrmOffLine.offlineDoc");// 离线单号
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if (rs.next()) {
					offlineDoc = rs.getString("OFFLINE_DOC");
				}
				rs.close();
				psta.close();
			}

			insertInStoreResultSql = EntityTool.fillSqlByEntity(
					insertInStoreResultSql, milPlantity);
			PreparedStatement insertInStoreResultPsta = connection
					.prepareStatement(insertInStoreResultSql);
			jugeNo = milPlantity.getJudgeStoveNo().replaceFirst("-.*", "");
			bacthNo = "X";
			groupNo = "001";

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectMaterialNo");// 查询物料码
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getProPlanId());
			psta.setString(2, milPlantity.getGxPlanNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				judgeStdDes = rs.getString("judgeStdDes");
				cic = rs.getString("CIC");
				materiaNo = rs.getString("OUTWL_ID");
				materiaName = rs.getString("OUTWL_DESC");
				INWL_ID = rs.getString("INWL_ID");
				INWL_DESC = rs.getString("INWL_DESC");
				CRAFT_SEQ = rs.getString("CRAFT_SEQ");
			}
			rs.close();
			psta.close();

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectBelongCode");// 查询产线、科室
			psta = connection.prepareStatement(sql);
			psta.setString(1, plineCode);
			rs = psta.executeQuery();
			if (rs.next()) {
				belongCode = rs.getString("DEPARTMENT_CODE");
				belongName = rs.getString("DEPARTMENT_DESC");
				milPlantity.setPlineName(rs.getString("PLINE_NAME"));
			}
			rs.close();
			psta.close();

			String inListDoc = querySendSqlDoc(connection, strInBound,
					strInMemo, plineCode, systime);// 入库单号
			String inListSeq = querySendSql(connection, inListDoc, plineCode); // 入库流水号
			int n = Integer.parseInt(inListSeq.substring(
					inListSeq.length() - 4, inListSeq.length()));

			String matNo = queryMatNoM(connection, jugeNo, bacthNo); // 材料号
			int g = Integer.parseInt(matNo.substring(matNo.length() - 4, matNo
					.length()));
			lengthCp = milPlantity.getLengthRange().replace("米", "").split(
					"[-]");
			str = milPlantity.getPipeSize().split("[*]");
			strWgt = 0.02466
					* Double.parseDouble(str[1])
					* (Math.abs(Double.parseDouble(str[0])
							- Double.parseDouble(str[1])))
					* Double.parseDouble(milPlantity.getTargetLength())
					* Integer.parseInt(offlineNum) / 1000;
			List<double[]> list1 = MeanValueCalculation.MeanCalculation(Double
					.parseDouble(new DecimalFormat("0.000").format(strWgt)),
					Integer.parseInt(offlineNum));
			for (int j = 0; j < list1.size(); j++) {
				double[] conW = list1.get(j);
				if ((int) conW[0] >= 0) {
					for (int z = 0; z < (int) conW[0]; z++) {
						insertMatPsta.setString(1, jugeNo);
						insertMatPsta.setString(2, bacthNo);
						insertMatPsta.setString(3, groupNo);
						insertMatPsta.setString(4, list.get(0));
						insertMatPsta.setString(5, list.get(1));
						insertMatPsta.setString(6, list.get(2));
						insertMatPsta.setString(7, list.get(3));
						insertMatPsta.setString(8, list.get(4));
						insertMatPsta.setString(9, (jugeNo + bacthNo)
								+ StringTool.formatDecimal(g, "0000"));
						insertMatPsta.setString(10, belongCode);
						insertMatPsta.setString(11, belongName);
						insertMatPsta.setString(12, belongCode);
						insertMatPsta.setString(13, belongName);

						insertMatPsta.setString(14, jugeNo);
						insertMatPsta.setString(15, bacthNo);
						insertMatPsta.setString(16, groupNo);
						insertMatPsta.setString(17, "1");
						insertMatPsta.setString(18, String.valueOf(conW[1]));
						insertMatPsta.setString(19, systime);
						insertMatPsta.setString(20, (jugeNo + bacthNo)
								+ StringTool.formatDecimal(g, "0000"));
						insertMatPsta.setString(21, "801401");
						insertMatPsta.setString(22, "80150104");
						insertMatPsta.setString(23, milPlantity.getPlineCode());
						insertMatPsta.setString(24, milPlantity.getPlineCode());
						insertMatPsta.setString(25, "11");
						insertMatPsta.setString(26, milPlantity.getId());
						insertMatPsta.setString(27, milPlantity
								.getJudgeStoveNo());
						insertMatPsta.setString(28, "");
						insertMatPsta.setString(29, milPlantity.getVarieties());
						insertMatPsta.setString(30, "");
						insertMatPsta.setString(31, milPlantity.getSteelname());
						insertMatPsta.setString(32, "");
						insertMatPsta.setString(33, milPlantity.getPipeSize()
								.replace("*", "x"));
						insertMatPsta.setString(34, "");
						insertMatPsta.setString(35, milPlantity.getGradename());
						insertMatPsta.setString(36, "");
						insertMatPsta
								.setString(37, milPlantity.getBuckleType());
						insertMatPsta.setString(38, "");
						insertMatPsta.setString(39, milPlantity
								.getRollStandrad());
						insertMatPsta.setString(40, belongCode);
						insertMatPsta.setString(41, list.get(8));
						insertMatPsta.setString(42, milPlantity.getStdStyle());
						insertMatPsta.setString(43, milPlantity
								.getStdStyleDesc());
						insertMatPsta.setString(44, str[0].toString());
						insertMatPsta.setString(45, str[1].toString());
						insertMatPsta.setString(46, lengthCp[0].toString());
						insertMatPsta.setString(47, lengthCp[1].toString());
						insertMatPsta.setString(48, milPlantity.getLotNo());
						insertMatPsta
								.setString(49, milPlantity.getContractNo());
						insertMatPsta.setString(50, milPlantity
								.getTargetLength());
						insertMatPsta.setString(51, milPlantity.getTarget());
						insertMatPsta.setString(52, milPlantity
								.getProcessStatus());
						insertMatPsta.setString(53, jugeNo);
						insertMatPsta.setString(54, milPlantity.getStoveNo());

						insertMatPsta.setString(55, materiaNo);
						insertMatPsta.setString(56, materiaName);
						insertMatPsta.setString(57, INWL_ID);
						insertMatPsta.setString(58, INWL_DESC);
						insertMatPsta.setString(59, cic);
						insertMatPsta.setString(60, judgeStdDes);
						insertMatPsta.setString(61, CRAFT_SEQ);
						insertMatPsta.setString(62, milPlantity.getProPlanId());
						insertMatPsta.setString(63, milPlantity.getGxPlanNo());
						insertMatPsta.setString(64, offlineDoc); // 离线单号
						insertMatPsta.addBatch();

						insertListPsta.setString(1, milPlantity.getMaterialNo());
						insertListPsta.setString(2, milPlantity.getMaterialDesc());
						insertListPsta.setString(3, inListDoc
								+ StringTool.formatDecimal(n, "0000"));
						insertListPsta.setString(4, inListDoc);
						insertListPsta.setString(5, "800701");
						insertListPsta.setString(6, "产出入库");
						insertListPsta.setString(7, (jugeNo + bacthNo)
								+ StringTool.formatDecimal(g, "0000"));
						insertListPsta.setString(8, milPlantity.getLotNo());
						insertListPsta.setString(9, milPlantity.getStoveNo());
						insertListPsta.setString(10, jugeNo);
						insertListPsta.setString(11, bacthNo);
						insertListPsta.setString(12, groupNo);

						insertListPsta.setString(13, "");
						insertListPsta
								.setString(14, milPlantity.getVarieties());
						insertListPsta.setString(15, "");// 标准
						insertListPsta.setString(16, milPlantity
								.getRollStandrad());
						insertListPsta.setString(17, "");
						insertListPsta
								.setString(18, milPlantity.getSteelname());
						insertListPsta.setString(19, "");
						insertListPsta.setString(20, milPlantity
								.getStdStyleDesc());
						insertListPsta.setString(21, "");
						insertListPsta.setString(22, milPlantity.getPipeSize()
								.replace("*", "x"));
						insertListPsta.setString(23, "");
						insertListPsta.setString(24, milPlantity
								.getBuckleType());

						insertListPsta.setString(25, milPlantity.getDimater());
						insertListPsta.setString(26, milPlantity.getHeight());
						insertListPsta
								.setString(27, milPlantity.getLengthmin());
						insertListPsta
								.setString(28, milPlantity.getLengthmax());
						insertListPsta.setString(29, "1");
						insertListPsta.setString(30, String.valueOf(conW[1]));
						insertListPsta.setString(31, String.valueOf(conW[1]));
						insertListPsta.setString(32, belongCode);
						insertListPsta.setString(33, belongName);
						insertListPsta.setString(34, list.get(0));
						insertListPsta.setString(35, "");
						insertListPsta.setString(36, "1");
						insertListPsta.setString(37, list.get(4));
						insertListPsta.setString(38, systime);
						insertListPsta.setString(39, "");// 合同号
						insertListPsta.setString(40, "");
						insertListPsta.setString(41, "");
						insertListPsta.setString(42, "");
						insertListPsta.setString(43, "");
						insertListPsta.setString(44, "");

						insertListPsta.setString(45, "801401");
						insertListPsta.setString(46, "80150101");
						insertListPsta.setString(47, systime);
						insertListPsta.setString(48, milPlantity
								.getTargetLength());// 长度
						insertListPsta.setString(49, belongCode);
						insertListPsta.setString(50, belongName);
						insertListPsta.setString(51, milPlantity
								.getRollStandrad());
						insertListPsta
								.setString(52, milPlantity.getPlineCode());
						insertListPsta
								.setString(53, milPlantity.getPlineName());
						insertListPsta
								.setString(54, milPlantity.getGradecode());
						insertListPsta
								.setString(55, milPlantity.getGradename());
						insertListPsta.setString(56, yearMoth);
						insertListPsta.setString(57, systime);
						insertListPsta.setString(58, "");
						insertListPsta.setString(59, "801302");
						insertListPsta.setString(60, "机组");
						insertListPsta
								.setString(61, milPlantity.getPlineCode());
						insertListPsta
								.setString(62, milPlantity.getPlineName());
						insertListPsta.setString(63, "");
						insertListPsta.setString(64, "");
						insertListPsta.setString(65, milPlantity
								.getContractNo());
						insertListPsta.setString(66, "11");
						insertListPsta.setString(67, milPlantity
								.getJudgeStoveNo());
						insertListPsta.setString(68, userOrder);
						insertListPsta.setString(69, userGroup);
						insertListPsta.addBatch();

						g++;
						n++;
					}
				}
			}
			// insertMilSlabPsta.setString(1, milPlantity.getJudgeStoveNo());
			// insertMilSlabPsta.setString(2, milPlantity.getPlineCode());
			// insertMilSlabPsta.setInt(3, Integer.parseInt(offlineNum));
			// insertMilSlabPsta.setString(4, "");
			// insertMilSlabPsta.setString(5, "1");
			// insertMilSlabPsta.setString(6, milPlantity.getJudgeStoveNo());
			// insertMilSlabPsta.setString(7, "9");
			// insertMilSlabPsta.setString(8, "0");
			// insertMilSlabPsta.setString(9, "1");
			// insertMilSlabPsta.setString(10, userName);
			// insertMilSlabPsta.setString(11, userOrder);
			// insertMilSlabPsta.setString(12, userGroup);
			// insertMilSlabPsta.setString(13, milPlantity.getId());
			// insertMilSlabPsta.addBatch();

			insertOfflineResultPsta.setString(1, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(2, milPlantity.getPlineCode());
			insertOfflineResultPsta.setString(3, milPlantity.getProPlanId());
			insertOfflineResultPsta.setString(4, milPlantity.getGxPlanNo());
			insertOfflineResultPsta.setString(5, offlineNum);
			insertOfflineResultPsta.setString(6, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(7, milPlantity.getVarieties());
			insertOfflineResultPsta.setString(8, milPlantity.getSteelcode());
			insertOfflineResultPsta.setString(9, milPlantity.getSteelname());
			insertOfflineResultPsta.setString(10, milPlantity.getGradecode());
			insertOfflineResultPsta.setString(11, milPlantity.getGradename());
			insertOfflineResultPsta
					.setString(12, milPlantity.getPipeSizeCode());
			insertOfflineResultPsta.setString(13, milPlantity.getPipeSize());// 规格
			insertOfflineResultPsta.setString(14, milPlantity
					.getBuckleTypeCode());
			insertOfflineResultPsta.setString(15, milPlantity.getBuckleType());
			insertOfflineResultPsta.setString(16, milPlantity
					.getRollStandradCode());
			insertOfflineResultPsta.setString(17, milPlantity
					.getProduceStandrad());// 标准
			insertOfflineResultPsta.setString(18, milPlantity.getStdStyle());
			insertOfflineResultPsta
					.setString(19, milPlantity.getStdStyleDesc());
			insertOfflineResultPsta.setString(20, milPlantity.getLengthRange());
			insertOfflineResultPsta.setString(21, milPlantity.getContractNo());
			insertOfflineResultPsta.setString(22, milPlantity.getProduccode());
			insertOfflineResultPsta.setString(23, milPlantity.getLotNo());
			insertOfflineResultPsta
					.setString(24, milPlantity.getJudgeStoveNo());
			insertOfflineResultPsta.setString(25, str[0].toString());
			insertOfflineResultPsta.setString(26, str[1].toString());
			insertOfflineResultPsta
					.setString(27, milPlantity.getTargetLength());
			insertOfflineResultPsta.setString(28, milPlantity.getPlineCode());
			insertOfflineResultPsta.setString(29, offlineNum);
			insertOfflineResultPsta.setString(30, flag);
			insertOfflineResultPsta.setString(31, systime);
			insertOfflineResultPsta.setString(32, userName);
			insertOfflineResultPsta.setString(33, userOrder);
			insertOfflineResultPsta.setString(34, userGroup);
			insertOfflineResultPsta.setString(35, new DecimalFormat("0.000")
					.format(strWgt));// 重量
			insertOfflineResultPsta.setString(36, milPlantity.getTarget());
			insertOfflineResultPsta.setString(37, milPlantity.getImpProcess());
			insertOfflineResultPsta.setString(38, offlineDoc); // 离线单号

			// insertOfflineResultPsta.setString(35,
			// milPlantity.getJudgeStoveNo());
			// insertOfflineResultPsta.setString(36,
			// milPlantity.getPlineCode());
			// insertOfflineResultPsta.setInt(37, Integer.parseInt(offlineNum));
			// //insertOfflineResultPsta.setString(42, systime);
			// insertOfflineResultPsta.setString(38,
			// milPlantity.getJudgeStoveNo());
			// insertOfflineResultPsta.setString(39,
			// milPlantity.getPlineCode());
			// insertOfflineResultPsta.setInt(45, Integer.parseInt(flag));
			// insertOfflineResultPsta.setString(46,
			// milPlantity.getJudgeStoveNo());
			// insertOfflineResultPsta.setString(47,
			// milPlantity.getJudgeStoveNo());

			// insertInStoreResultPsta.setString(1,
			// milPlantity.getJudgeStoveNo());
			// insertInStoreResultPsta.setString(2, milPlantity.getId());
			// insertInStoreResultPsta.setString(3, offlineNum);
			// insertInStoreResultPsta.setString(4,
			// milPlantity.getJudgeStoveNo());
			// insertInStoreResultPsta.setString(5, milPlantity.getId());
			// insertInStoreResultPsta.setString(6, milPlantity.getId());
			// insertInStoreResultPsta.setString(7,
			// milPlantity.getJudgeStoveNo());
			// insertInStoreResultPsta.setString(8, milPlantity.getLotNo());
			// insertInStoreResultPsta.setString(9, milPlantity.getPlineCode());
			// insertInStoreResultPsta.setString(10,
			// milPlantity.getGradename());
			// insertInStoreResultPsta.setString(11,
			// milPlantity.getTargetLength());
			// insertInStoreResultPsta.setString(12, offlineNum);
			insertInStoreResultPsta.setString(1, offlineNum);
			insertInStoreResultPsta.setString(2, offlineNum);
			insertInStoreResultPsta.addBatch();

			// insertMilSlabPsta.executeBatch();
			insertOfflineResultPsta.addBatch();
			insertMatPsta.executeBatch();
			insertListPsta.executeBatch();
			insertOfflineResultPsta.executeBatch();
			insertInStoreResultPsta.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 conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSqlDoc(Connection conn, String strlist, String memo,
			String plineCode, String systime) throws Exception {
		int seq = 0;
		String inListDoc = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat matter2 = new SimpleDateFormat("yyMMdd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmInOnlineStore.getInListDoc");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, memo);
		psta.setString(2, plineCode);
		psta.setString(3, systime);
		psta.setString(4, systime);
		// psta.setString(5, strlist);
		psta.setString(5, plineCode);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			// String res = rs.getString(1);
			// if (res == null) {
			// res = memo + plineCode + matter2.format(dt) + "00001";
			// } else {
			// //seq = Integer.parseInt(res.substring(8, 13));
			// seq = Integer.parseInt(res.substring(12, 17));
			// }
			inListDoc = rs.getString("INSTOCK_DOC");
		}
		rs.close();
		psta.close();
		// return memo + plineCode + matter2.format(dt)
		// + StringTool.formatDecimal(++seq, "00000");
		return inListDoc;
	}

	/**
	 * 每支材料对应的入库流水号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSql(Connection conn, String strlist, String plineCode)
			throws Exception {
		int seq = 0;
		String inListDocSeq = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmInOnlineStore.getInListDoc1");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strlist);
		psta.setString(2, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			// String res = rs.getString(1);
			// if (res == null) {
			// res = strlist + "0001";
			// } else {
			// //seq = Integer.parseInt(res.substring(13, 17));
			// seq = Integer.parseInt(res.substring(17, 21));
			// }
			inListDocSeq = rs.getString("INSTOCK_SQE");
		}
		rs.close();
		psta.close();
		// return strlist + StringTool.formatDecimal(++seq, "0000");
		return inListDocSeq;
	}

	/***
	 * 查询是否已录入实绩
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryResult(String jugeNo) {
		return this.getDataBySqlID("FrmOffLine.doQueryResult", new Object[] {
				jugeNo, jugeNo, jugeNo });
	}

	/***
	 * 下线回退
	 * 
	 * @return
	 */
	public CoreReturnObject newOfflineBack(String milPlanTity, String num,
			String offPro) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		String isOk = ""; // 0-未变仓库位置；1-已导运
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String systime = dateFormat.format(now);
		String nodeStaus = "";// 是否结炉
		int acount = 0;
		String str[] = null;
		double strWgt = 0.0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String deleteOffineSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.newOfflineBack");
			PreparedStatement deleteOfflinePsta = connection
					.prepareStatement(deleteOffineSql);
			String deleteMatSql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doDeleteMatData");// 删除虚拟库存
			PreparedStatement deleteMatPsta = connection
					.prepareStatement(deleteMatSql);

			MilPlanEntity3 milPlantity = EntityTool.getEntityByJSONStr(
					milPlanTity, MilPlanEntity3.class);
			str = milPlantity.getPipeSize().split("[*]");
			strWgt = 0.02466 * Double.parseDouble(str[1])
					* (Double.parseDouble(str[0]) - Double.parseDouble(str[1]))
					* Double.parseDouble(milPlantity.getTargetLength())
					* Integer.parseInt(num) / 1000;
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectMianPlanNode");
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			psta.setString(2, milPlantity.getProPlanId());
			psta.setString(3, milPlantity.getGxPlanNo());
			psta.setString(4, milPlantity.getJudgeStoveNo());
			psta.setString(5, milPlantity.getProPlanId());
			psta.setString(6, milPlantity.getGxPlanNo());
			psta.setString(7, milPlantity.getJudgeStoveNo());
			psta.setString(8, milPlantity.getProPlanId());
			psta.setString(9, milPlantity.getGxPlanNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				nodeStaus = rs.getString("NODE_FUR_FLAG");
			}
			rs.close();
			psta.close();
			if (nodeStaus.equals("1")) {
				cro.setV_errMsg("该炉已结炉,不允许进行下线回退!");
				return cro;
			}

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectOfflineResultDetia");
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			psta.setString(2, offPro);
			psta.setString(3, milPlantity.getProPlanId());
			psta.setString(4, milPlantity.getGxPlanNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				acount = Integer.parseInt(rs.getString("ACOUNT"));
			}
			rs.close();
			psta.close();
			if (acount > 0) {
				cro.setV_errMsg("该下线炉已进行组炉或者返线,不允许进行下线回退!");
				return cro;
			}

			acount = 0;
			sql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doQueryBackCount");// 查询可撤销的支数
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				acount = Integer.parseInt(rs.getString("ACOUNT").toString());
			}
			rs.close();
			psta.close();
			if (Integer.parseInt(num) > acount) {
				cro.setV_errMsg("输入的支数大于炉号:" + milPlantity.getJudgeStoveNo()
						+ "的可撤销支数" + acount + "!");
				return cro;
			}

			deleteOfflinePsta.setString(1, num);
			deleteOfflinePsta.setString(2, new DecimalFormat("0.000")
					.format(strWgt));
			deleteOfflinePsta.setString(3, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(4, offPro);

			deleteOfflinePsta.setString(5, num);
			deleteOfflinePsta.setString(6, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(7, num);
			deleteOfflinePsta.setString(8, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(9, num);
			deleteOfflinePsta.setString(10, milPlantity.getJudgeStoveNo());

			deleteOfflinePsta.setString(11, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(12, num);
			deleteOfflinePsta.setString(13, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(14, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(15, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(16, offPro);
			deleteOfflinePsta.setString(17, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(18, offPro);
			deleteOfflinePsta.setString(19, milPlantity.getJudgeStoveNo());

			deleteOfflinePsta.setString(20, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(21, num);
			deleteOfflinePsta.addBatch();

			deleteMatPsta.setString(1, milPlantity.getJudgeStoveNo());
			deleteMatPsta.setInt(2, Integer.parseInt(num));
			deleteMatPsta.addBatch();

			deleteOfflinePsta.executeBatch();
			deleteMatPsta.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;
	}

	/***
	 * 矫直下线回退
	 * 
	 * @return
	 */
	public CoreReturnObject newStaOfflineBack(String milPlanTity, String num,
			String offPro) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String systime = dateFormat.format(now);
		String nodeStaus = "";// 是否结炉
		int acount = 0;
		String str[] = null;
		double strWgt = 0.0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String deleteOffineSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.newStaOfflineBack");
			PreparedStatement deleteOfflinePsta = connection
					.prepareStatement(deleteOffineSql);
			String deleteMatSql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doDeleteMatData");// 删除虚拟库存
			PreparedStatement deleteMatPsta = connection
					.prepareStatement(deleteMatSql);

			MilPlanEntity3 milPlantity = EntityTool.getEntityByJSONStr(
					milPlanTity, MilPlanEntity3.class);
			str = milPlantity.getPipeSize().split("[*]");
			strWgt = 0.02466 * Double.parseDouble(str[1])
					* (Double.parseDouble(str[0]) - Double.parseDouble(str[1]))
					* Double.parseDouble(milPlantity.getTargetLength())
					* Integer.parseInt(num) / 1000;
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectMianPlanNode1");
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				nodeStaus = rs.getString("NODE_FUR_FLAG");
			}
			rs.close();
			psta.close();
			if (nodeStaus.equals("1")) {
				cro.setV_errMsg("该炉已结炉,不允许进行下线回退!");
				return cro;
			}

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectOfflineResultDetia");
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			psta.setString(2, offPro);
			psta.setString(3, milPlantity.getProPlanId());
			psta.setString(4, milPlantity.getGxPlanNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				acount = Integer.parseInt(rs.getString("ACOUNT"));
			}
			rs.close();
			psta.close();
			if (acount > 0) {
				cro.setV_errMsg("该下线炉已进行组炉或者返线,不允许进行下线回退!");
				return cro;
			}

			deleteOfflinePsta.setString(1, num);
			deleteOfflinePsta.setString(2, new DecimalFormat("0.000")
					.format(strWgt));
			deleteOfflinePsta.setString(3, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(4, offPro);

			deleteOfflinePsta.setString(5, num);
			deleteOfflinePsta.setString(6, num);
			deleteOfflinePsta.setString(7, milPlantity.getJudgeStoveNo());

			deleteOfflinePsta.setString(8, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(9, num);
			deleteOfflinePsta.setString(10, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(11, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(12, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(13, offPro);
			deleteOfflinePsta.setString(14, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(15, offPro);
			deleteOfflinePsta.setString(16, milPlantity.getJudgeStoveNo());

			deleteOfflinePsta.setString(17, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(18, num);
			deleteOfflinePsta.addBatch();

			deleteMatPsta.setString(1, milPlantity.getJudgeStoveNo());
			deleteMatPsta.setInt(2, Integer.parseInt(num));
			deleteMatPsta.addBatch();

			deleteOfflinePsta.executeBatch();
			deleteMatPsta.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;
	}

	/***
	 * 下线点离线回退
	 * 
	 * @return
	 */
	public CoreReturnObject newXXOfflineBack(String milPlanTity, String num,
			String offPro) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String systime = dateFormat.format(now);
		String nodeStaus = "";// 是否结炉
		int acount = 0;
		String isOk = ""; // 0-未变仓库位置；1-已导运
		String str[] = null;
		double strWgt = 0.0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String deleteOffineSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.newXXOfflineBack");
			PreparedStatement deleteOfflinePsta = connection
					.prepareStatement(deleteOffineSql);
			String deleteMilInStoreSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.deleteMilInStore");// 实绩表减下线支数
			PreparedStatement deleteMilInStorePsta = connection
					.prepareStatement(deleteMilInStoreSql);
			String deleteMatSql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doDeleteMatData");// 删除虚拟库存
			PreparedStatement deleteMatPsta = connection
					.prepareStatement(deleteMatSql);

			MilPlanEntity3 milPlantity = EntityTool.getEntityByJSONStr(
					milPlanTity, MilPlanEntity3.class);
			str = milPlantity.getPipeSize().split("[*]");
			strWgt = 0.02466 * Double.parseDouble(str[1])
					* (Double.parseDouble(str[0]) - Double.parseDouble(str[1]))
					* Double.parseDouble(milPlantity.getTargetLength())
					* Integer.parseInt(num) / 1000;
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectMianPlanXX");
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				nodeStaus = rs.getString("NODE_STATUS");
			}
			rs.close();
			psta.close();
			if (nodeStaus.equals("99")) {
				cro.setV_errMsg("该炉已结炉,不允许进行下线回退!");
				return cro;
			}

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectOfflineResultDetia");
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			psta.setString(2, offPro);
			psta.setString(3, milPlantity.getProPlanId());
			psta.setString(4, milPlantity.getGxPlanNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				acount = Integer.parseInt(rs.getString("ACOUNT"));
			}
			rs.close();
			psta.close();
			if (acount > 0) {
				cro.setV_errMsg("该下线炉已进行组炉或者返线或者委外,不允许进行下线回退!");
				return cro;
			}

			acount = 0;
			sql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doQueryBackCount");// 查询可撤销的支数
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				acount = Integer.parseInt(rs.getString("ACOUNT").toString());
			}
			rs.close();
			psta.close();

			int acount2 = 0;
			sql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doQueryOffCount");// 查询离线的支数
			psta = connection.prepareStatement(sql);
			psta.setString(1, milPlantity.getJudgeStoveNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				acount2 = Integer.parseInt(rs.getString("ACOUNT").toString());
			}
			rs.close();
			psta.close();
			if (acount2 > 0) {
				if (Integer.parseInt(num) > acount) {
					cro.setV_errMsg("输入的支数大于炉号:"
							+ milPlantity.getJudgeStoveNo() + "的可撤销支数" + acount
							+ "!");
					return cro;
				}
			}

			deleteOfflinePsta.setString(1, num);
			deleteOfflinePsta.setString(2, new DecimalFormat("0.000")
					.format(strWgt));
			deleteOfflinePsta.setString(3, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(4, offPro);

			// deleteOfflinePsta.setString(5, num);
			// deleteOfflinePsta.setString(6, num);
			// deleteOfflinePsta.setString(7, milPlantity.getJudgeStoveNo());

			deleteOfflinePsta.setString(5, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(6, num);
			// deleteOfflinePsta.setString(10, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(7, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(8, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(9, offPro);
			deleteOfflinePsta.setString(10, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(11, offPro);
			// deleteOfflinePsta.setString(16, milPlantity.getJudgeStoveNo());

			deleteOfflinePsta.setString(12, milPlantity.getJudgeStoveNo());
			deleteOfflinePsta.setString(13, num);
			deleteOfflinePsta.addBatch();

			deleteMatPsta.setString(1, milPlantity.getJudgeStoveNo());
			deleteMatPsta.setInt(2, Integer.parseInt(num));
			deleteMatPsta.addBatch();

			deleteMilInStorePsta.setString(1, num);
			deleteMilInStorePsta.setString(2, milPlantity.getId());
			deleteMilInStorePsta.setString(3, milPlantity.getJudgeStoveNo());
			deleteMilInStorePsta.setString(4, milPlantity.getProPlanId());
			deleteMilInStorePsta.setString(5, milPlantity.getGxPlanNo());
			deleteMilInStorePsta.addBatch();

			deleteOfflinePsta.executeBatch();
			// deleteMatPsta.executeBatch();
			deleteMilInStorePsta.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 conn
	 *            c
	 * @param strLcode
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String queryMatNoM(Connection conn, String strLcode, String strBatch)
			throws Exception {
		int count = 0;
		String matNo = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmInOnlineStore.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()) {
			matNo = rs.getString("MAT_NO");
		}
		rs.close();
		psta.close();
		// return (strLcode + strBatch)
		// + StringTool.formatDecimal(++count, "0000");
		return matNo;
	}

	/***
	 * 查询进程表合格支数
	 * 
	 * @return
	 */
	public CoreReturnObject doQueryJugeCount(String jugeNo) {
		return this.getDataBySqlID("FrmOffLine.doQueryJugeCount",
				new Object[] { jugeNo });
	}

	/***
	 * 查询进程表下线点已离线支数
	 * 
	 * @return
	 */
	public CoreReturnObject doQueryOfflineEdCount(String jugeNo) {
		return this.getDataBySqlID("FrmOffLine.doQueryOfflineEdCount",
				new Object[] { jugeNo });
	}

	/***
	 * 查询交库点交库和离线的支数
	 * 
	 * @param jugeNo
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject doQueryXxOfflinNum(String jugeNo, String plineCode,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("FrmOffLine.doQueryXxOfflinNum",
				new Object[] { jugeNo, plineCode, proPlanId, gxPlanNo });
	}

	/**
	 * 查询合格品支数
	 * 
	 * @param jugeNo
	 * @param plineCode
	 * @param proPlanId
	 * @param gxPlanNo
	 * @return
	 */
	public CoreReturnObject doQueryHgNum(String jugeNo, String plineCode,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("FrmOffLine.doQueryHgNum", new Object[] {
				jugeNo, plineCode, proPlanId, gxPlanNo });
	}

	/**
	 * 废品入半成品库存回退
	 * 
	 * @param JudgeStoveNo
	 * @param plineCode
	 * @param ProcessNo
	 * @return
	 */
	public CoreReturnObject insertMatScrapBack(String JudgeStoveNo,
			String proPlanId, String gxPlanNo, String plineCode,
			String ProcessNo) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertMatScrapSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertMatScrapBack"); // 废品入半成品库存回退
			PreparedStatement insertMatScrapPsta = connection
					.prepareStatement(insertMatScrapSql);
			insertMatScrapPsta.setString(1, JudgeStoveNo);
			insertMatScrapPsta.setString(2, proPlanId);
			insertMatScrapPsta.setString(3, gxPlanNo);
			insertMatScrapPsta.setString(4, plineCode);
			insertMatScrapPsta.addBatch();

			insertMatScrapPsta.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 jugeNo
	 * @param plineCode
	 * @param proPlanId
	 * @param gxPlanNo
	 * @return
	 */
	public CoreReturnObject doQueryMatScrap(String jugeNo, String plineCode,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("FrmOffLine.doQueryMatScrap", new Object[] {
				jugeNo, proPlanId, gxPlanNo, plineCode });
	}
}
