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.mes.zgmil.entity.MilSawRackEntity;
import com.steering.mes.zgmil.entity.MilSawResultDeatilEntity;
import com.steering.mes.zgmil.entity.MilSawResultEntity;

import com.steering.mes.zgmil.entity.MilSlabScrapSeqEntity;

/**
 * 管排锯实绩业务类
 * 
 * @author lr 2015/05/28
 * @version v1.0
 */
public class PipeSawResult extends DBCommon {
	/**
	 * 查询
	 * 
	 * @param JudgeStoveNo
	 *            炉号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject getResult(String JudgeStoveNo, Integer RowNo) {
		return this.getDataBySqlID("PipeSawResult.SingleResultQuery",
				new Object[] { JudgeStoveNo });
	}

	/**
	 * 查询分切实绩主表
	 */

	public CoreReturnObject GetSawResult(String JudgeStoveNo, String proPlanId,
			String gxPlanNo) {
		return this.getDataBySqlID("PipeSawResult.GetSawResult", new Object[] {
				JudgeStoveNo, proPlanId, gxPlanNo });
	}

	/**
	 * 查询管号队列
	 * 
	 * @param JudgeStoveNo
	 *            --炉号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject getMatRackSeq(String JudgeStoveNo,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("PipeSawResult.RackSeqQuery", new Object[] {
				JudgeStoveNo, proPlanId, gxPlanNo });
	}

	/**
	 * 开始分切 - 修改主计划状态 ，新增分切实绩信息
	 * 
	 * @param MilSawResultEntity
	 *            分切实绩实体类
	 * @return CoreReturnObject
	 */
	public CoreReturnObject startSaw(
			com.steering.mes.zgmil.entity.MilSawResultEntity MilSawResultEntity) {
		ArrayList<String> sqllist = new ArrayList<String>();

		String sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateMainPlanStatue");
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.AddResult");
		sql1 = EntityTool.fillSqlByEntity(sql1, MilSawResultEntity);
		sql = EntityTool.fillSqlByEntity(sql, MilSawResultEntity);
		sqllist.add(sql);
		sqllist.add(sql1);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	public CoreReturnObject pipsawfastback(String JudgeStoveNo,
			String ResultNo, String PlineCode, String proPlanId, String gxPlanNo) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql1 = "DELETE FROM  MIL_SAW_RESULT_DEATIL   t WHERE t.JUDGE_STOVE_NO = '"
				+ JudgeStoveNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ gxPlanNo + "','/')";
		String sql2 = "UPDATE MIL_SAW_RACK  SET  ROW_NO = '',  CUT_HEAD_LENGTH = '', SAW_NO = '',  SAW_NO_N = '',";
		sql2 += "	CUT_TRAIL_LENGTH='',ORDER_LENGTH='',CUT_TYPE='0',";
		sql2 += "REAL_ROLL_LENGTH='',LAST_ORDER_LENGTH='',COL_NO='',SCRAP_DBNUM=''";
		sql2 += " WHERE JUDGE_STOVE_NO = '" + JudgeStoveNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
				+ "','/')";
		String sql3 = "UPDATE MIL_STRAIGH_RACK T SET T.COL_NO='' WHERE T.Judge_Stove_No='"
				+ JudgeStoveNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ gxPlanNo + "','/')";
		String sql4 = "UPDATE MIL_TESTING_RACK T SET T.COL_NO='' WHERE T.Judge_Stove_No='"
				+ JudgeStoveNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ gxPlanNo + "','/')";
		String sql5 = "UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.ORDER_LENGTH = '',T.ACT_THEORY_WEIGHT = '' WHERE T.Judge_Stove_No='"
				+ JudgeStoveNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ gxPlanNo + "','/')";
		sqllist.add(sql2);
		sqllist.add(sql1);
		sqllist.add(sql3);
		sqllist.add(sql4);
		sqllist.add(sql5);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);

	}

	public CoreReturnObject UpdateRackrollLebgth(String heatno,
			String rollLength, String orderlegth, String proPlanId,
			String gxPlanNo) {
		String sql = "UPDATE MIL_SAW_RACK t SET t.Real_Roll_Length=";
		sql += rollLength;
		sql += " , t.last_order_length=";
		sql += orderlegth;
		sql += " WHERE t.judge_stove_no='";
		sql += heatno + "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
				+ "','/')";
		return this.setData(sql);
	}

	/**
	 * 新增分切排号实绩信息
	 * 
	 * @param MilSawResultDeatilEntity
	 *            分切子表实绩实体类
	 * @return CoreReturnObject
	 */
	public CoreReturnObject addRowResult(
			com.steering.mes.zgmil.entity.MilSawResultDeatilEntity MilSawResultDeatilEntity) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.AddRowResult");
		sql = EntityTool.fillSqlByEntity(sql, MilSawResultDeatilEntity);
		return this.setData(sql);

	}

	/**
	 * 修改分切排号实绩信息
	 * 
	 * @param MilSawResultDeatilEntity
	 *            分切子表实绩实体类
	 * @return CoreReturnObject
	 */
	public CoreReturnObject updateRowResult(
			com.steering.mes.zgmil.entity.MilSawResultDeatilEntity MilSawResultDeatilEntity) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateRowResult");
		sql = EntityTool.fillSqlByEntity(sql, MilSawResultDeatilEntity);
		return this.setData(sql);

	}

	/**
	 * 删除以剔除的管号
	 * 
	 * @param JudgeStoveNo
	 *            炉号
	 * @param ScrapNum
	 *            之前工序剔除支数
	 * @param MatCount
	 *            管号队列总支数
	 * @return CoreReturnObject
	 */
	public CoreReturnObject deleteScrapMat(String JudgeStoveNo,
			Integer ScrapNum, Integer MatCount) {

		CoreReturnObject cro = new CoreReturnObject();
		if (ScrapNum.equals(0)) {
			return cro;
		}
		Connection conn = null;
		PreparedStatement psta = null;
		try {
			conn = this.getDao("TgDao").getConnection();
			conn.setAutoCommit(false);
			String Sql = "delete from mil_saw_rack where seq in (";
			String SqlWhere = "";
			for (int i = 0; i < ScrapNum - 1; i++) {
				SqlWhere += MatCount - i + ", ";
			}
			SqlWhere += MatCount - ScrapNum + ")";
			Sql += SqlWhere;
			psta = conn.prepareStatement(Sql);

			psta.executeUpdate(Sql);
			psta.close();
			conn.commit();
			conn.close();
		} 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(0);
		return cro;
	}

	/**
	 * 结炉
	 * 
	 * @param MilSawResultEntity
	 *            分切实绩实体类
	 * @return CoreReturnObject
	 */
	public CoreReturnObject nodeResult(
			com.steering.mes.zgmil.entity.MilSawResultEntity MilSawResultEntity) {

		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateResult");
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateMainPlanNodeStatue");
		// String sql2 =
		// CoreXmlSqlParsersFactory.getSql("PipeSawResult.UpdateResultEndTime");
		sql = EntityTool.fillSqlByEntity(sql, MilSawResultEntity);
		sql1 = EntityTool.fillSqlByEntity(sql1, MilSawResultEntity);
		// sql2 = EntityTool.fillSqlByEntity(sql2, MilSawResultEntity);
		sqllist.add(sql);
		sqllist.add(sql1);
		// sqllist.add(sql2);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);

	}

	/**
	 * 剔除
	 * 
	 * @param MilScrapSlab
	 *            管坯剔除实体类
	 * @return CoreReturnObject
	 */
	public CoreReturnObject scrapMat(MilSlabScrapSeqEntity MilScrapSlab,
			String Flag) {
		ArrayList<String> sqllist = new ArrayList<String>();
		// 新增剔除管号序列
		String sql = CoreXmlSqlParsersFactory
				.getSql("FeedResult.AddScrapSlabSeq");
		// 修改上料表物料状态
		String sql1 = "";
		// 修改上料行剔除支数合格支数
		String sql2 = "";
		// 上料剔除
		if (Flag.equals("0")) {
			sql1 = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.UpdateFeedFeedNumStatue");
			sql2 = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.UpdateFeedRowFeedNum");
		} else {
			// 修改上料表物料状态 修改剔除支数
			sql1 = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.UpdateFeedDBNumStatue");
			sql2 = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.UpdateFeedRowDBNum");
		}
		sql = EntityTool.fillSqlByEntity(sql, MilScrapSlab);
		sql1 = EntityTool.fillSqlByEntity(sql1, MilScrapSlab);
		sql2 = EntityTool.fillSqlByEntity(sql2, MilScrapSlab);
		sqllist.add(sql);
		sqllist.add(sql1);
		sqllist.add(sql2);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 修改管号队列对应管的排号
	 * 
	 * @param
	 * @return CoreReturnObject
	 */
	public CoreReturnObject updateMatRowNo(
			MilSawResultDeatilEntity MilSawResultDeatil, Integer RowNum,
			String JudgeStoveNo) {

		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement psta = null;
		ResultSet rs = null;
		int seq = 0;
		try {
			conn = this.getDao("TgDao").getConnection();
			conn.setAutoCommit(false);
			String sql = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.UpdateMatRowNum");
			sql = EntityTool.fillSqlByEntity(sql, MilSawResultDeatil);

			String sql1 = "select min(seq) from mil_saw_rack where row_no is null and JudgeStoveNo =  '"
					+ JudgeStoveNo + "'";
			psta = conn.prepareStatement(sql1);
			rs = psta.executeQuery();
			while (rs.next()) {
				seq = rs.getInt(1);
			}
			rs.close();
			psta.close();
			String sqlWhere = " AND SEQ IN ( ";
			sqlWhere += "SELECT SEQ FROM MIL_SAW_RACK SEQ> " + (seq - 1)
					+ " AND STATUS = '0'  AND ROWNUM <" + (RowNum + 1)
					+ "and judge_stove_no ='" + JudgeStoveNo + "'";

			sql += sqlWhere;
			psta = conn.prepareStatement(sql);
			int count = psta.executeUpdate();
		} 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(0);
		return cro;
	}

	/**
	 * 查询已开始分切的炉计划信息
	 * 
	 * @param
	 * @return CoreReturnObject
	 */
	public CoreReturnObject getStartSaw() {
		return this.getDataBySqlID("PipeSawResult.GetStartSawQuery",
				new Object[] {});
	}

	/**
	 * 查询已出炉实绩
	 * 
	 * @param
	 * @return CoreReturnObject
	 */
	public CoreReturnObject GetSingleFurNodeResult(String PlineCode,
			String Shift, String Group, String StartTime, String EndTime) {
		return this.getDataBySqlID("PipeSawResult.SingleFurNodeResult",
				new Object[] { PlineCode, Shift, Group, StartTime, EndTime });
	}

	/**
	 * 结炉时剔除剔料序号表对应管坯
	 * 
	 * @param JudgeStoveNo
	 *            上料计划实体类
	 * @return CoreReturnObject
	 */
	public CoreReturnObject scrapNodeMat(String JudgeStoveNo) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement psta = null;
		PreparedStatement psta1 = null;
		try {
			conn = this.getDao("TgDao").getConnection();
			conn.setAutoCommit(false);

			String sql = "";

			ResultSet rs = null;
			ResultSet rs1 = null;
			ResultSet rs3 = null;
			ArrayList<int[]> seqlist = new ArrayList<int[]>();
			sql = CoreXmlSqlParsersFactory.getSql("FeedResult.SinglePlanQuery");
			psta = conn.prepareStatement(sql);
			psta.setString(1, JudgeStoveNo);
			rs = psta.executeQuery();
			while (rs.next()) {
				int SawNum = rs.getInt(3); // 分切数
				int DBNum = rs.getInt(8); // 倍尺数
				sql = CoreXmlSqlParsersFactory
						.getSql("FeedResult.ScrapSlabSeqQuery");
				psta1 = conn.prepareStatement(sql);
				psta1.setString(1, JudgeStoveNo);
				psta1.setString(2, "2"); // 加热炉
				rs1 = psta1.executeQuery();

				int Seq = 0;
				String ScrapTime = "";
				String Remark = "";
				String ScrapUser = "";
				String ScrapGroup = "";
				String ScrapShift = "";
				String TableName = "";
				String MatNo = "";
				String[] TableNameList = new String[] {
						"MIL_PERFORATION_HISTORY", "MIL_ROLLING_HISTORY",
						"MIL_REFUR_HISTORY", "MIL_SIZING_HISTORY",
						"MIL_SAW_HISTORY", "MIL_STRAIGH_HISTORY",
						"MIL_TESTING_HISTORY" };
				// 切前剔除
				while (rs1.next()) {
					Seq = rs1.getInt(1);
					ScrapTime = rs1.getString(2);
					Remark = rs1.getString(4);
					ScrapUser = rs1.getString(5);
					ScrapShift = rs1.getString(6);
					ScrapGroup = rs1.getString(7);
					// 查询剔除序号对应的管号
					sql = " SELECT MAT_NO FROM "
							+ " (SELECT ROWNUM AS ROW_NO ,SEQ,MAT_NO FROM MIL_FUR_HISTORY T WHERE DELETE_FLAG ='0' "
							+ " AND T.JUDGE_STOVE_NO = '" + JudgeStoveNo
							+ "' ORDER BY SEQ)WHERE row_no = " + Seq;
					psta = conn.prepareStatement(sql);
					rs3 = psta.executeQuery();
					while (rs3.next()) {
						MatNo = rs3.getString(1);
					}
					psta.close();

					// 修改上料历史表对应序号的管坯 为 1-剔除
					sql = CoreXmlSqlParsersFactory
							.getSql("PipeSawResult.UpdateFurHistory");
					psta = conn.prepareStatement(sql);
					psta.setInt(1, Seq);
					psta.setString(2, JudgeStoveNo);
					int UpdateFeedHistoryCount = psta.executeUpdate();
					psta.close();

					// 新增坯料剔除表
					sql = CoreXmlSqlParsersFactory
							.getSql("FeedResult.AddScrapSlab");
					psta = conn.prepareStatement(sql);
					psta.setString(1, JudgeStoveNo);
					psta.setInt(2, Seq);
					psta.setString(3, "2");
					psta.setString(4, MatNo);
					psta.setString(5, "0");
					psta.setString(6, ScrapUser);
					psta.setString(7, ScrapTime);
					psta.setString(8, ScrapShift);
					psta.setString(9, ScrapGroup);
					int AddScrapSlabCount = psta.executeUpdate();
					psta.close();

					// 修改历史表对应序号管坯状态为 1-剔除

					for (int i = 0; i < TableNameList.length; i++) {
						TableName = TableNameList[i];

						sql = "UPDATE "
								+ TableName
								+ " SET STATUS = '1'  WHERE JUDGE_STOVE_NO ='"
								+ JudgeStoveNo
								+ "'AND "
								+ "SEQ IN (SELECT SEQ FROM (SELECT ROWNUM AS ROW_NO , SEQ FROM "
								+ TableName + " T WHERE  T.DELETE_FLAG = '0'"
								+ "  AND T.JUDGE_STOVE_NO ='" + JudgeStoveNo
								+ "' ORDER BY SEQ )WHERE ";

						String sqllistRollUpdate = " ROW_NO in (";

						String sqlWhere = "";
						if (i < 5) {
							sqlWhere = Seq + "" + "))";
							sqllistRollUpdate = sqllistRollUpdate + sqlWhere;
							sql = sql + sqllistRollUpdate;
						}

						else {
							for (int j = 1; j < SawNum; j++) {
								sqlWhere += ((Seq - 1) * SawNum + j) + "" + ",";

							}
							sqlWhere = sqlWhere + ((Seq * SawNum) + "" + "))");
							sqllistRollUpdate = sqllistRollUpdate + sqlWhere;
							sql = sql + sqllistRollUpdate;

						}

						psta = conn.prepareStatement(sql);

						psta.executeUpdate(sql);
						psta.close();
					}

				}

				// 修改上料之后所有工序历史表status=1的管 delete_flag = 1
				for (int i = 0; i < TableNameList.length; i++) {
					TableName = TableNameList[i];
					sql = "update  " + TableName
							+ "  set delete_flag = '1' where status = '1'";
					psta = conn.prepareStatement(sql);
					psta.executeUpdate(sql);
					psta.close();
				}

			}
			// 修改上料历史表状态为0 的坯料状态为2
			conn.commit();
			rs3.close();
			rs1.close();
			psta1.close();
			rs.close();

			conn.close();
		} 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(0);
		return cro;
	}

	/**
	 * //查询该炉已切实绩明细
	 * 
	 * @param JudgeStoveNo
	 * @return
	 */
	public CoreReturnObject GetResultDetail(String JudgeStoveNo,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("PipeSawResult.GetResultDetail",
				new Object[] { JudgeStoveNo, proPlanId, gxPlanNo });
	}

	/**
	 * 添加管排明细
	 * 
	 * @param sawresultdetail
	 * @return
	 */
	public CoreReturnObject AddResultDetail(
			MilSawResultDeatilEntity sawresultdetail) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.AddResultDetail");
		sql = EntityTool.fillSqlByEntity(sql, sawresultdetail);
		return this.setData(sql);

	}

	/**
	 * 跟更新明细
	 */
	public CoreReturnObject UpdteResultDetail(
			MilSawResultDeatilEntity sawresultdetail) {
		String sql = "";
		if (sawresultdetail.getSawFlag().equals("1")) {
			if (sawresultdetail.getChange().equals("0")) {
				sql = CoreXmlSqlParsersFactory
						.getSql("PipeSawResult.UpdateResultDetail1#");
				sql = EntityTool.fillSqlByEntity(sql, sawresultdetail);
			}
			if (sawresultdetail.getChange().equals("1")) {
				sql = CoreXmlSqlParsersFactory
						.getSql("PipeSawResult.UpdateResultDetail2#");
				sql = EntityTool.fillSqlByEntity(sql, sawresultdetail);
			}
		}
		if (sawresultdetail.getSawFlag().equals("2")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.UpdateResultDetail2#");
			sql = EntityTool.fillSqlByEntity(sql, sawresultdetail);
		}

		return this.setData(sql);
	}

	/**
	 * 更新探伤，矫直跟踪记录COL_NO RowNum = 0; //设置默认排支数 tempROW_NO = 0;//排号 SAW_NUM =
	 * 0;//分切数
	 */
	public CoreReturnObject UpdteRackCOL_NO(String HeatNo, String colno,
			Integer RowNum, Integer SAW_NUM, String proPlanId, String gxPlanNo) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement psta = null;
		PreparedStatement psta1 = null;
		ResultSet rs = null;
		ResultSet rs1 = null;
		ResultSet rs3 = null;
		try {
			conn = this.getDao("TgDao").getConnection();
			conn.setAutoCommit(false);

			int rowcouts = 0;
			int seqmin = 1;
			int seqmax = 1;

			String sql = "";
			String sql1 = "";
			String sql2 = "";
			String sql3 = "";
			sql = "select Sum(t.row_count) as row_count from MIL_SAW_RESULT_DEATIL t WHERE t.judge_stove_no='";
			sql += HeatNo + "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
					+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
					+ "','/')";
			psta = conn.prepareStatement(sql);
			rs = psta.executeQuery();
			while (rs.next()) {
				rowcouts = rs.getInt(1);
			}
			seqmin = (rowcouts - RowNum) * SAW_NUM + 1;
			seqmax = rowcouts * SAW_NUM;

			sql1 = "update Mil_Testing_Rack t set t.COL_NO= '" + colno;
			sql1 += "'  where t.seq between " + seqmin;
			sql1 += "  and " + seqmax;
			sql1 += "and t.judge_stove_no= '" + HeatNo
					+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
					+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
					+ "','/')";
			this.setData(sql1);

			sql2 = "update MIL_STRAIGH_RACK t set t.COL_NO=' " + colno;
			sql2 += " ' where t.seq between " + seqmin;
			sql2 += "  and " + seqmax;
			sql2 += "and t.judge_stove_no= '" + HeatNo
					+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
					+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
					+ "','/')";
			this.setData(sql2);

			sql3 = "UPDATE MIL_SAW_RACK t SET t.col_no=";
			sql3 += colno;
			sql3 += " WHERE t.SEQ  in ( select SEQ FROM ( select a.seq AS SEQ from MIL_SAW_RACK a  where a.status=0 ";
			sql3 += " AND a.judge_stove_no='" + HeatNo
					+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
					+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
					+ "','/')";
			// sql3+=" AND a.ROW_NO is not null AND a.col_no is  null order  by a.seq ) WHERE rownum between 1 and ";
			sql3 += " AND a.ROW_NO is not null AND a.col_no is  null  order  by a.seq ) WHERE rownum between 1 and ";
			sql3 += RowNum;
			sql3 += ")";
			this.setData(sql3);

			rs.close();
			psta.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(0);
		return cro;
	}

	/**
	 * 锯切完成
	 */
	public CoreReturnObject UpdteResultDetailCUTEND(
			MilSawResultDeatilEntity sawresultdetail) {
		String sql = "";
		sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateResultDetailCUTEND");
		sql = EntityTool.fillSqlByEntity(sql, sawresultdetail);
		return this.setData(sql);

	}

	/**
	 * 更新跟踪记录表排号
	 */
	public CoreReturnObject UpdateSawRackRowNo(
			MilSawResultDeatilEntity sawresultdetail) {
		// return this.setDataBySqlID("PipeSawResult.UpdateSawRackRowNo", new
		// Object[]{RowNo,heatno,RowCount});
		String sql = "";
		sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateSawRackRowNo");
		sql = EntityTool.fillSqlByEntity(sql, sawresultdetail);
		return this.setData(sql);
	}

	/**
	 * 更新跟踪记录表管排锯记录
	 * 
	 * @param sawresultdetail
	 * @return
	 */
	public CoreReturnObject UpdateSawRack(
			MilSawResultDeatilEntity sawresultdetail) {
		// return this.setDataBySqlID("PipeSawResult.UpdateSawRackRowNo", new
		// Object[]{RowNo,heatno,RowCount});
		String sql = "";
		sql = CoreXmlSqlParsersFactory.getSql("PipeSawResult.UpdateSawRack");
		sql = EntityTool.fillSqlByEntity(sql, sawresultdetail);
		return this.setData(sql);
	}

	/**
	 * 获取跟踪记录表记录
	 */
	public CoreReturnObject GetSawRack(MilSawResultDeatilEntity sawresultdetail) {
		String sql = "";
		sql = CoreXmlSqlParsersFactory.getSql("PipeSawResult.GetSawRack");
		sql = EntityTool.fillSqlByEntity(sql, sawresultdetail);
		return this.getData(sql);
	}

	/**
	 * 剔管操作，：1、插入MIL_SLAB_SCRAP_SEQ表，2、管排锯跟踪记录表状态，3、修改加管排锯实绩表剔除支数
	 */
	public CoreReturnObject scrapInspectionMat(
			com.steering.mes.zgmil.entity.MilSlabScrapSeqEntity ScrapSlab) {
		ArrayList<String> sqllist = new ArrayList<String>();
		// 新增剔除管号序列
		String sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.AddScrapSlabSeq");
		// 修改管排锯跟踪表物料状态
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateFurStatue");
		// 修改管排锯实绩表剔除支数
		String sql2 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateFurScrapNum");

		sql = EntityTool.fillSqlByEntity(sql, ScrapSlab);
		sql1 = EntityTool.fillSqlByEntity(sql1, ScrapSlab);
		sql2 = EntityTool.fillSqlByEntity(sql2, ScrapSlab);
		sqllist.add(sql);
		sqllist.add(sql1);
		sqllist.add(sql2);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * /剔管操作，：1、插入MIL_SLAB_SCRAP_SEQ表，
	 */
	public CoreReturnObject scrapInspectionMatDBSEQ(
			com.steering.mes.zgmil.entity.MilSlabScrapSeqEntity ScrapSlab) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.AddScrapSlabSeq");
		sql = EntityTool.fillSqlByEntity(sql, ScrapSlab);
		return this.setData(sql);
	}

	/**
	 * 剔管操作:2、管排锯跟踪记录表状态，3、修改加管排锯实绩表剔除支数
	 */
	public CoreReturnObject scrapInspectionMatDB(
			com.steering.mes.zgmil.entity.MilSlabScrapSeqEntity ScrapSlab) {
		ArrayList<String> sqllist = new ArrayList<String>();
		// 新增剔除管号序列
		String sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.AddScrapSlabSeq");
		// 修改管排锯跟踪表物料状态
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateFurStatueDB");
		// 修改管排锯实绩表剔除支数
		String sql2 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateFurScrapNumDB");

		sql = EntityTool.fillSqlByEntity(sql, ScrapSlab);
		sql1 = EntityTool.fillSqlByEntity(sql1, ScrapSlab);
		sql2 = EntityTool.fillSqlByEntity(sql2, ScrapSlab);
		// sqllist.add(sql);
		sqllist.add(sql1);
		sqllist.add(sql2);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);

	}

	/**
	 * 获取切后剔除支数
	 */
	public CoreReturnObject GetRackScrpNum(String heatno, String seq,
			String proPlanId, String gxPlanNo) {
		String sql = "Select t.SCRAP_DBNUM   from MIL_SAW_RACK 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.seq= ";
		sql += seq;
		return this.getData(sql);
	}

	public CoreReturnObject GetRownoFromRack(String heatno, String seq) {
		String sql = "SELECT T.ROW_NO FROM MIL_SAW_RACK T  WHERE T.JUDGE_STOVE_NO='";
		sql += heatno;
		sql += "' AND T.SEQ=";
		sql += seq;
		return this.getData(sql);
	}

	public CoreReturnObject UpdateRackRowNo(MilSawRackEntity milsawrack,
			String rownobefor) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = "";
		String sql1 = "";
		String sql2 = "";

		sql = CoreXmlSqlParsersFactory.getSql("PipeSawResult.UpdateRackRowNo");
		sql = EntityTool.fillSqlByEntity(sql, milsawrack);

		sql1 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateSawDetailRowNoafter");
		sql1 = EntityTool.fillSqlByEntity(sql1, milsawrack);

		sql2 = "UPDATE MIL_SAW_RESULT_DEATIL T SET  T.ROW_COUNT = T.ROW_COUNT - 1 WHERE 1=1 AND T.JUDGE_STOVE_NO ='";
		sql2 += milsawrack.getJudgeStoveNo()
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ milsawrack.getProPlanId()
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ milsawrack.getGxPlanNo() + "','/')";
		sql2 += " AND  T.ROW_NO =";
		sql2 += rownobefor;

		sqllist.add(sql);
		sqllist.add(sql1);
		sqllist.add(sql2);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	public CoreReturnObject UpdateRackCutType(MilSawRackEntity milsawrack) {
		String sql = "";
		sql = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateRackCutType");
		sql = EntityTool.fillSqlByEntity(sql, milsawrack);
		return this.setData(sql);
	}

	public CoreReturnObject UpdateRackCutX(MilSawRackEntity milsawrack,
			Integer pro, String X, String chang) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String NameList[] = new String[] { "SAW_NO", "SAW_NO_N",
				"CUT_HEAD_LENGTH", "ORDER_LENGTH", "CUT_TRAIL_LENGTH" };
		String Name = NameList[pro];
		String sql = "UPDATE MIL_SAW_RACK T SET T." + Name + "=";
		sql += X;
		sql += " WHERE T.JUDGE_STOVE_NO='";
		sql += milsawrack.getJudgeStoveNo();
		sql += "'  AND T.ROW_NO=";
		sql += milsawrack.getRowNo();
		sqllist.add(sql);

		String sql1 = "";
		if (pro.equals(2) || pro.equals(3) || pro.equals(4)) {
			sql1 = "UPDATE MIL_SAW_RACK T SET T.LAST_ORDER_LENGTH= T.LAST_ORDER_LENGTH + ";
			sql1 += chang;
			sql1 += "  WHERE T.JUDGE_STOVE_NO='" + milsawrack.getJudgeStoveNo()
					+ "' AND T.ROW_NO= ";
			sql1 += milsawrack.getRowNo();
			sql1 += " AND T.CUT_TYPE=1";
			sqllist.add(sql1);
		}

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

	}

	/***
	 * 修改进程表长度、重量
	 * 
	 * @return
	 */
	public CoreReturnObject doUpdatePorcess(MilSawRackEntity milsawrack,
			String chang) {
		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 contraThick = "";// 控制壁厚
		String outDiameter = "";// 目标外径
		String producName = "";// 名称
		String proWgt = "";// 重量
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updatePortSql = CoreXmlSqlParsersFactory
					.getSql("doUpdatePorcess.updateLen");// 修改进程表长度重量
			PreparedStatement updatePortPsta = connection
					.prepareStatement(updatePortSql);
			sql = CoreXmlSqlParsersFactory
					.getSql("updatePortOrderLength.selectPipSize");
			psta = connection.prepareStatement(sql);
			psta.setString(1, milsawrack.getJudgeStoveNo());
			rs = psta.executeQuery();
			if (rs.next()) {
				contraThick = rs.getString("CONTROL_THICKP");
				// if(Double.parseDouble(rs.getString("AIMOUTDIAMETER")) > 0)
				// {
				// outDiameter = rs.getString("AIMOUTDIAMETER");
				// }else
				// {
				// outDiameter = rs.getString("OUTDIAMETER");
				// }
				outDiameter = rs.getString("OUTDIAMETER");
				producName = rs.getString("VARIETIES");
			}
			rs.close();
			psta.close();
			if (producName.contains("油管") || producName.contains("套管")
					|| producName.contains("接箍")) {
				if (producName.contains("管线")) {
					proWgt = new DecimalFormat("0.000").format(0.02466
							* Double.parseDouble(contraThick)
							* (Double.parseDouble(outDiameter) * 1.003 - Double
									.parseDouble(contraThick))
							* Double.parseDouble(chang) / 1000);
				} else {
					proWgt = new DecimalFormat("0.000").format(0.02466
							* Double.parseDouble(contraThick)
							* (Double.parseDouble(outDiameter) * 1.006 - Double
									.parseDouble(contraThick))
							* Double.parseDouble(chang) / 1000);
				}

			} else {
				proWgt = new DecimalFormat("0.000").format(0.02466
						* Double.parseDouble(contraThick)
						* (Double.parseDouble(outDiameter) - Double
								.parseDouble(contraThick))
						* Double.parseDouble(chang) / 1000);
			}
			updatePortPsta.setString(1, milsawrack.getJudgeStoveNo());
			updatePortPsta.setString(2, milsawrack.getJudgeStoveNo());
			updatePortPsta.setString(3, milsawrack.getRowNo());
			updatePortPsta.setString(4, chang);
			updatePortPsta.setString(5, proWgt);// 重量
			updatePortPsta.setString(6, milsawrack.getJudgeStoveNo());
			updatePortPsta.addBatch();
			updatePortPsta.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;
	}

	public CoreReturnObject GetSingleSawRack(MilSawRackEntity milsawrack) {
		String sql = "Select t.* from MIL_SAW_RACK t  WHERE t.judge_stove_no='"
				+ milsawrack.getJudgeStoveNo() + "' AND t.seq=";
		sql += milsawrack.getSeq();
		return this.getData(sql);
	}

	/**
	 * 2、更新实绩表（包括结炉时间）
	 * 
	 */
	public CoreReturnObject UpdateSawResult(
			com.steering.mes.zgmil.entity.MilSawResultEntity milsawresult,
			String saveflag) {
		ArrayList<String> arr = new ArrayList<String>();
		String sql = "";
		if (saveflag.equals("0")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.UpdateSawResult");
		}
		if (saveflag.equals("1")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.UpdateSawResultsaveflag");
		}
		sql = EntityTool.fillSqlByEntity(sql, milsawresult);
		arr.add(sql);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(arr);
	}

	/**
	 * 2、更新实绩表（包括结炉时间,结炉状态）， 3.更新主表NODE_STATUS
	 * 
	 * @param milsawresult
	 * @return
	 */
	public CoreReturnObject UpdateSawResultNode(
			com.steering.mes.zgmil.entity.MilSawResultEntity milsawresult) {
		ArrayList<String> arr = new ArrayList<String>();

		String sql1 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateSawResultNode");
		String sql2 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateMilPlanNode");
		String sql3 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateSawRackShift");
		String sql4 = CoreXmlSqlParsersFactory
				.getSql("PipeSawResult.UpdateResultShift");
		// 更新进程表mil_processes数据
		String updateProcess = CoreXmlSqlParsersFactory
				.getSql("FrmInOnlineStore.insertMilProcess2");
		sql1 = EntityTool.fillSqlByEntity(sql1, milsawresult);
		sql2 = EntityTool.fillSqlByEntity(sql2, milsawresult);
		sql3 = EntityTool.fillSqlByEntity(sql3, milsawresult);
		sql4 = EntityTool.fillSqlByEntity(sql4, milsawresult);
		updateProcess = EntityTool.fillSqlByEntity(updateProcess, milsawresult);
		arr.add(sql1);
		arr.add(sql2);
		arr.add(sql3);
		arr.add(sql4);
		arr.add(updateProcess);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(arr);

	}

	/**
	 * 判断上一道工序结炉状态
	 */
	public CoreReturnObject GetMIL_SIZING_RESULT(String JudgeStoveNo,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("PipeSawResult.GetMIL_SIZING_RESULT",
				new Object[] { JudgeStoveNo, proPlanId, gxPlanNo });
	}

	/**
	 * 查询结炉实绩
	 */
	public CoreReturnObject GetSingleNodeResult(String PliceCode, String Shift,
			String Group, String StartTime, String EndTime) {
		return this.getDataBySqlID("PipeSawResult.GetSingleNodeResult",
				new Object[] { PliceCode, Shift, Group, StartTime, EndTime });
	}

	/**
	 * 返回可切支数
	 * 
	 * @param heatno
	 * @param nodeFlag
	 * @return
	 */
	public CoreReturnObject LimitCut(String heatno, String nodefalg) {
		String sql = "";
		if (nodefalg.equals("1")) {
			sql = "select Count(JUDGE_STOVE_NO) as Counts   from  MIL_SAW_RACK t where t.JUDGE_STOVE_NO='";
			sql += heatno;
			sql += "'AND  t.mat_no is not null";
			sql += "  AND t.row_no is null AND t.STATUS=0";
		}
		if (nodefalg.equals("0")) {
			sql = "select Count(JUDGE_STOVE_NO) as Counts   from  MIL_SAW_RACK t where t.JUDGE_STOVE_NO='";
			sql += heatno;
			sql += "' AND t.row_no is null AND t.STATUS=0";
		}
		return this.getData(sql);
	}

	// 回退
	public CoreReturnObject UpdteResultDetailCUTBACK(Integer tempROW_NO,
			String JUDGE_STOVE_NO) {
		String sql = "";
		sql = "DELETE FROM MIL_SAW_RESULT_DEATIL WHERE  ROW_NO='";
		sql += tempROW_NO;
		sql += "' AND JUDGE_STOVE_NO='";
		sql += JUDGE_STOVE_NO;
		sql += "'";
		return this.setData(sql);
	}

	/**
	 * 计算已切的料
	 */
	public CoreReturnObject GetCutNum(String HeatNo, String proPlanId,
			String gxPlanNo) {
		String sql = "select Count(t.row_no) as CutNum from MIL_SAW_RACK 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.row_no is not null";
		return this.getData(sql);
	}

	/**
	 * 执行回退
	 */
	public CoreReturnObject UpdateRackRowNo(String HeatNo, Integer CutNum,
			Integer CutNumReal, Integer SAW_NUM, String proPlanId,
			String gxPlanNo) {
		ArrayList<String> arr = new ArrayList<String>();
		int temp = CutNum - CutNumReal;
		String sql = "update MIL_SAW_RACK t SET t.Row_No='',t.order_length='',t.Cut_Head_Length='',t.cut_trail_length='',t.saw_no='',t.saw_no_n=''";
		sql += " WHERE t.judge_stove_no='";
		sql += HeatNo + "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
				+ "','/')";
		sql += " AND t.seq between  ";
		sql += CutNumReal + 1;
		sql += " AND ";
		sql += CutNum;

		String sql1 = "Update MIL_STRAIGH_RACK t set t.col_no='' ";
		sql1 += " WHERE t.judge_stove_no='";
		sql1 += HeatNo + "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
				+ "','/')";
		sql1 += " AND t.seq between  ";
		sql1 += (CutNumReal) * SAW_NUM + 1;
		sql1 += " AND ";
		sql1 += CutNum * SAW_NUM;

		String sql2 = "Update MIL_TESTING_RACK t set t.col_no='' ";
		sql2 += " WHERE t.judge_stove_no='";
		sql2 += HeatNo + "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
				+ "','/')";
		sql2 += " AND t.seq between  ";
		sql2 += (CutNumReal) * SAW_NUM + 1;
		sql2 += " AND ";
		sql2 += CutNum * SAW_NUM;

		arr.add(sql);
		arr.add(sql1);
		arr.add(sql2);

		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(arr);
		// return this.setData(sql);
	}

	public CoreReturnObject QuNum(MilSawResultEntity milsawresult) {
		String sql = "";
		sql = CoreXmlSqlParsersFactory.getSql("PipeSawResult.QuNum");
		sql = EntityTool.fillSqlByEntity(sql, milsawresult);
		return this.setData(sql);
	}

	public CoreReturnObject SetResultCutTupe(String heatno) {
		String sql = "UPDATE MIL_SAW_RACK T SET  T.CUT_TYPE=1,";
		sql += " T.LAST_ORDER_LENGTH=T.REAL_ROLL_LENGTH-T.CUT_HEAD_LENGTH/1000-T.CUT_TRAIL_LENGTH/1000-T.ORDER_LENGTH*(SELECT (A.SAW_NUM-1) AS SAW_NUM  FROM MIL_SAW_RESULT A WHERE A.JUDGE_STOVE_NO=T.JUDGE_STOVE_NO)";
		sql += " WHERE T.JUDGE_STOVE_NO='" + heatno + "'";
		return this.setData(sql);
	}

	public CoreReturnObject SetResultCutTupeBack(String heatno) {
		String sql = "UPDATE MIL_SAW_RACK T SET  T.CUT_TYPE=0,";
		sql += " T.LAST_ORDER_LENGTH=T.ORDER_LENGTH";
		sql += " WHERE T.JUDGE_STOVE_NO='" + heatno + "'";
		return this.setData(sql);
	}

	/***
	 * 结炉赋值材料号到剔废表中
	 * 
	 * @param JudgeStoveNo
	 * @param ProcessNo
	 * @return
	 */
	public CoreReturnObject updateMilSlab(String JudgeStoveNo,
			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");
		String systime = dateFormat.format(now);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateMilSlabSql = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.updateMilSlab");
			PreparedStatement updateMilSlabPsta = connection
					.prepareStatement(updateMilSlabSql);
			updateMilSlabPsta.setString(1, JudgeStoveNo);
			updateMilSlabPsta.setString(2, proPlanId);
			updateMilSlabPsta.setString(3, gxPlanNo);
			updateMilSlabPsta.setString(4, JudgeStoveNo);
			updateMilSlabPsta.setString(5, proPlanId);
			updateMilSlabPsta.setString(6, gxPlanNo);
			updateMilSlabPsta.setString(7, JudgeStoveNo);
			updateMilSlabPsta.setString(8, proPlanId);
			updateMilSlabPsta.setString(9, gxPlanNo);
			updateMilSlabPsta.addBatch();

			updateMilSlabPsta.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 JudgeStoveNo
	 * @param ProcessNo
	 * @param opProcessNo
	 * @return
	 */
	public CoreReturnObject updateProcessP(String JudgeStoveNo,
			String ProcessNo, String opProcessNo, String proPlanId,
			String gxPlanNo, String lotNo, 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");
		String systime = dateFormat.format(now);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务

			// PreparedStatement updateProcessPsta =
			// connection.prepareStatement(updateProcessSql);
			sql = CoreXmlSqlParsersFactory.getSql("updateProcessP.selectScrap");
			psta = connection.prepareStatement(sql);
			psta.setString(1, JudgeStoveNo);
			psta.setString(2, proPlanId);
			psta.setString(3, gxPlanNo);
			rs = psta.executeQuery();
			List<MilSlabScrapSeqEntity> list = EntityTool.getEntitysByRs(rs,
					MilSlabScrapSeqEntity.class);

			rs.close();
			psta.close();

			for (int i = 0; i < list.size(); i++) {
				MilSlabScrapSeqEntity milSlabSeq = list.get(i);
				String updateProcessSql = CoreXmlSqlParsersFactory
						.getSql("updateProcessP.UpdateFlag");// 结炉剔除进程表中数据
				updateProcessSql = updateProcessSql.replace("#OP_PROCESS#",
						opProcessNo);
				updateProcessSql = EntityTool.fillSqlByEntity(updateProcessSql,
						milSlabSeq);
				PreparedStatement updateProcessPsta = connection
						.prepareStatement(updateProcessSql);
				updateProcessPsta.executeUpdate();
				updateProcessPsta.close();
				// updateProcessPsta.setInt(1,
				// Integer.parseInt(milSlabSeq.getProcessNo()));
				// updateProcessPsta.setString(2, milSlabSeq.getJudgeStoveNo());
				// updateProcessPsta.setString(3, milSlabSeq.getSeq());
				// updateProcessPsta.setString(4, opProcessNo);
				// updateProcessPsta.setString(5, milSlabSeq.getJudgeStoveNo());
				//				
				//				
				// updateProcessPsta.setInt(6,
				// Integer.parseInt(milSlabSeq.getProcessNo()));
				// updateProcessPsta.setString(7, milSlabSeq.getJudgeStoveNo());
				// updateProcessPsta.setString(8, opProcessNo);
				//				
				// updateProcessPsta.setString(9, milSlabSeq.getSeq());
				// updateProcessPsta.setString(10, opProcessNo);
				// updateProcessPsta.setString(11,
				// milSlabSeq.getJudgeStoveNo());
				//				
				// updateProcessPsta.addBatch();

			}
			// updateProcessPsta.executeBatch();
			String insertMatScrapSql = CoreXmlSqlParsersFactory
			.getSql("FrmOffLine.insertMatScrap");  //废品入半成品库存
			PreparedStatement insertMatScrapPsta = connection
			.prepareStatement(insertMatScrapSql);
			insertMatScrapPsta.setString(1, JudgeStoveNo);
			insertMatScrapPsta.setString(2, proPlanId);
			insertMatScrapPsta.setString(3, gxPlanNo);
			insertMatScrapPsta.setString(4, plineCode);
			insertMatScrapPsta.setString(5, ProcessNo);
			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 ProcessNo
	 * @return
	 */
	public CoreReturnObject assignmentMatNo(String jugeNo, 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");
		String systime = dateFormat.format(now);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertScrapSql = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.insertScrapSlab");
			PreparedStatement insertScrapPsta = connection
					.prepareStatement(insertScrapSql);

			String updateMatNoSql = CoreXmlSqlParsersFactory
					.getSql("PipeSawResult.assignmentMatNo");
			PreparedStatement updateMatNoPsta = connection
					.prepareStatement(updateMatNoSql);

			insertScrapPsta.setString(1, jugeNo);
			insertScrapPsta.setString(2, proPlanId);
			insertScrapPsta.setString(3, gxPlanNo);
			insertScrapPsta.setString(4, jugeNo);
			insertScrapPsta.setString(5, proPlanId);
			insertScrapPsta.setString(6, gxPlanNo);
			insertScrapPsta.setString(7, plineCode);
			insertScrapPsta.setString(8, proPlanId);
			insertScrapPsta.setString(9, gxPlanNo);
			insertScrapPsta.setString(10, plineCode);
			insertScrapPsta.setString(11, proPlanId);
			insertScrapPsta.setString(12, gxPlanNo);
			insertScrapPsta.addBatch();

			updateMatNoPsta.setString(1, jugeNo);
			updateMatNoPsta.setString(2, proPlanId);
			updateMatNoPsta.setString(3, gxPlanNo);
			updateMatNoPsta.setString(4, jugeNo);
			updateMatNoPsta.setString(5, proPlanId);
			updateMatNoPsta.setString(6, gxPlanNo);
			updateMatNoPsta.addBatch();

			insertScrapPsta.executeBatch();
			updateMatNoPsta.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;
	}

	/***
	 * 清空MIL_SLAB_SCRAP_SEQ材料号
	 * 
	 * @return
	 */
	public CoreReturnObject updateSlabSeq(String jugeNo, String proPlanId,
			String gxPlanNo) {
		return this.setDataBySqlID("PipeSawResult.updateSlabSeq", new Object[] {
				jugeNo, proPlanId, gxPlanNo });
	}
}
