package com.steering.mes.signature;

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

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

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;
import com.steering.common.EntityTool;
import com.steering.mes.zgmil.entity.MilEntrustedBillEntity;
import com.steering.mes.zgmil.entity.MilOfflineGroupEntity1;
import com.steering.mes.zgmil.entity.MilOfflineReslutEntity2;
import com.steering.mes.zgmil.entity.MilOfflineResultDetiaEntity;
import com.steering.mes.zgmil.entity.MilPlanEntity3;

public class FrmDownlineManage extends DBCommon {

	/***
	 * 查询下线实绩
	 * 
	 * @param parm
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryOffLine(ArrayList<String> parm,
			String startTim, String endTim, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmDownlineManage.doQueryOffLine");
		if (!startTim.equals("")) {
			sql += " AND T.OFFLINE_TIME >= to_date('"
					+ startTim
					+ "','YYYY-MM-DD HH24:MI:SS') AND T.OFFLINE_TIME <= to_date('"
					+ endTim + "','YYYY-MM-DD HH24:MI:SS')";
		}
		if (!parm.get(0).equals("")) {
			sql += " AND T.JUDGE_STOVE_NO LIKE '%" + parm.get(0) + "%' ";
		}
		if (!parm.get(2).equals("")) {
			sql += " AND T.OFFLINE_PRO LIKE '%" + parm.get(2) + "%' ";
		}
		//TZH ADD 新增工序合同号查询条件
		if (!parm.get(3).equals("")) {
			sql += " AND T.CONTRACT_NO LIKE '%" + parm.get(3) + "%'";
		}
		
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		return this.getData(sql);
	}

	/***
	 * 查询委外实绩
	 * 
	 * @param parm
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQuerySubcontract(ArrayList<String> parm,
			String startTim, String endTim, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmDownlineManage.doQuerySubcontract");
		if (!startTim.equals("")) {
			sql += " AND T.ENTRUSTED_TIME >= to_date('"
					+ startTim
					+ "','YYYY-MM-DD HH24:MI:SS') AND T.ENTRUSTED_TIME <= to_date('"
					+ endTim + "','YYYY-MM-DD HH24:MI:SS')";
		}
		if (!parm.get(0).equals("")) {
			sql += " AND T.JUDGE_STOVE_NO LIKE '%" + parm.get(0) + "%' ";
		}
		if (!parm.get(2).equals("")) {
			sql += " AND T.SUBCONTRACT_FLAG LIKE '%" + parm.get(2) + "%' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		return this.getData(sql);
	}

	/***
	 * 查询组炉履历
	 * 
	 * @param parm
	 * @param startTim
	 * @param endTim
	 * @return
	 */
	public CoreReturnObject doQueryFurnace(ArrayList<String> parm,
			String startTim, String endTim, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmDownlineManage.doQueryFurnace");
		if (!startTim.equals("")) {
			sql += " AND T.ZP_TIME >= to_date('" + startTim
					+ "','YYYY-MM-DD HH24:MI:SS') AND T.ZP_TIME <= to_date('"
					+ endTim + "','YYYY-MM-DD HH24:MI:SS')";
		}
		if (!parm.get(0).equals("")) {
			sql += " AND T.ZP_JUDGE_STOVE_NO LIKE '%" + parm.get(0) + "%' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		sql += " GROUP BY VARIETIES,PLINE_CODE,MODEL_DESC,ZP_JUDGE_STOVE_NO,ZP_LOT_NO,ZP_STANDRAD,ZP_STEEL,ZP_GRADE,ZP_LENGTH,ZP_LENGTH_RANGE,";
		sql += " ZP_LEVEL,ZP_SIZE,ZP_M_LH,ZP_S_LH,ZP_M_PH,REMARK,COL_USER,COL_SHIFT,COL_GROUP,DIAMETER,THICKNESS,OFFLINE_PRO";
		return this.getData(sql);
	}

	public CoreReturnObject doQueryFurnaceChildRow(ArrayList<String> parm,
			String startTim, String endTim, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmDownlineManage.doQueryFurnaceChildRow");
		if (!startTim.equals("")) {
			sql += " AND T.ZP_TIME >= to_date('" + startTim
					+ "','YYYY-MM-DD HH24:MI:SS') AND T.ZP_TIME <= to_date('"
					+ endTim + "','YYYY-MM-DD HH24:MI:SS')";
		}
		if (!parm.get(0).equals("")) {
			sql += " AND T.ZP_JUDGE_STOVE_NO LIKE '%" + parm.get(0) + "%' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		return this.getData(sql);
	}

	/***
	 * 查询质检委托实绩
	 * 
	 * @return
	 */
	public CoreReturnObject doQualityInspectionTrust(ArrayList<String> parm,
			String startTim, String endTim, String[] plineCodes) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmDownlineManage.doQualityInspectionTrust");
		if (!startTim.equals("")) {
			sql += " AND T.COL_TIME >= to_date('" + startTim
					+ "','YYYY-MM-DD HH24:MI:SS') AND T.COL_TIME <= to_date('"
					+ endTim + "','YYYY-MM-DD HH24:MI:SS')";
		}
		if (!parm.get(0).equals("")) {
			sql += " AND T.JUDGE_STOVE_NO LIKE '%" + parm.get(0) + "%' ";
		}
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCodes);
		return this.getData(sql);
	}

	/***
	 * 组炉批
	 * 
	 * @param parm
	 * @param parm1
	 * @param userName
	 * @param userGroup
	 * @param userOrder
	 * @return
	 */
	public CoreReturnObject doFurnace(ArrayList<String> parm,
			ArrayList<String> parm1, ArrayList<String> parm2) {
		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);
		int totalCount = 0;
		double strWgt = 0.0;
		int nodeCount = 0;// 结炉状态
		int jugeNoCount = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertSql = CoreXmlSqlParsersFactory
					.getSql("doFurnace.insertGroup");// 插入组炉批履历表
			PreparedStatement insertPsta = connection
					.prepareStatement(insertSql);
			String insertOfflineSql = CoreXmlSqlParsersFactory
					.getSql("doFurnace.insertOffline");// 插入下线表
			PreparedStatement insertOfflinePsta = connection
					.prepareStatement(insertOfflineSql);
			String deleteMatSql = CoreXmlSqlParsersFactory
					.getSql("doFurnace.deleteMat");// 消除库存
			PreparedStatement deleteMatPsta = connection
					.prepareStatement(deleteMatSql);
			String updatePortFlagSql = CoreXmlSqlParsersFactory
					.getSql("doFurnace.updatePortFlag");// 修改进程表组炉标识
			PreparedStatement updatePortFlagPsta = connection
					.prepareStatement(updatePortFlagSql);
			MilOfflineReslutEntity2 tity = EntityTool.getEntityByJSONStr(parm1
					.get(0).toString(), MilOfflineReslutEntity2.class);
			for (String str : parm) {
				MilOfflineReslutEntity2 milOfflineEntity = EntityTool
						.getEntityByJSONStr(str, MilOfflineReslutEntity2.class);
				sql = CoreXmlSqlParsersFactory
						.getSql("doFurnace.doQueryMilPlan");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milOfflineEntity.getJudgeStoveNo());
				psta.setString(2, milOfflineEntity.getLotNo());
				if (milOfflineEntity.getOfflinePro().equals("探伤")) {
					psta.setString(3, "90");
				} else if (milOfflineEntity.getOfflinePro().equals("矫直")) {
					psta.setString(3, "80");
				} else {
					psta.setString(3, "96");
				}
				/*
				 * psta.setString(4, milOfflineEntity.getProPlanId());
				 * psta.setString(5, milOfflineEntity.getGxPlanNo());
				 */
				rs = psta.executeQuery();
				if (rs.next()) {
					nodeCount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (nodeCount == 0) {
					cro.setV_errMsg("此炉未进行结炉,不允许进行组炉批!");
					return cro;
				}

				sql = CoreXmlSqlParsersFactory
						.getSql("doFurnace.doQueryMilPlanJugeNo");
				psta = connection.prepareStatement(sql);
				psta.setString(1, parm2.get(0));
				rs = psta.executeQuery();
				if (rs.next()) {
					jugeNoCount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (jugeNoCount > 0) {
					cro.setV_errMsg("此新炉号已存在计划中,不允许进行组炉批!");
					return cro;
				}

				sql = CoreXmlSqlParsersFactory
						.getSql("doFurnace.doQueryMilOfflineGroup");
				psta = connection.prepareStatement(sql);
				psta.setString(1, parm2.get(0));
				rs = psta.executeQuery();
				if (rs.next()) {
					jugeNoCount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (jugeNoCount > 0) {
					cro.setV_errMsg("此新炉号已存在组炉实际中,不允许进行组炉批!");
					return cro;
				}

				// 查询该炉是否是组炉炉号
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.doQueryZP");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milOfflineEntity.getJudgeStoveNo());
				psta.setString(2, milOfflineEntity.getJudgeStoveNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					jugeNoCount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (jugeNoCount > 0) {
					cro.setV_errMsg("炉号【" + milOfflineEntity.getJudgeStoveNo()
							+ "】是组炉炉号,不允许进行再次组炉批!");
					return cro;
				}

				// insertPsta.setString(1, tity.getPlineCode());
				insertPsta.setString(1, milOfflineEntity.getJudgeStoveNo());
				insertPsta.setString(2, milOfflineEntity.getLotNo());
				insertPsta.setString(3, milOfflineEntity.getPlineCode());
				insertPsta.setString(4, milOfflineEntity.getOfflineType());// 下线类型
				if (milOfflineEntity.getOfflinePro().equals("探伤")) {
					insertPsta.setString(5, "TS");// 下线工序
				} else if (milOfflineEntity.getOfflinePro().equals("质检")) {
					insertPsta.setString(5, "ZJ");// 下线工序
				} else if (milOfflineEntity.getOfflinePro().equals("交库")) {
					insertPsta.setString(5, "XX");// 下线工序
				}

				insertPsta.setString(6, tity.getProducname());
				insertPsta.setString(7, parm2.get(0));
				insertPsta.setString(8, parm2.get(1));
				insertPsta.setString(9, milOfflineEntity.getGroupNumCount());// 操作支数(组炉支数)
				insertPsta.setString(10, tity.getStdName());
				insertPsta.setString(11, tity.getSteelname());
				insertPsta.setString(12, tity.getGradename());
				insertPsta.setString(13, tity.getLength());
				insertPsta.setString(14, tity.getActLenRange());

				insertPsta.setString(15, tity.getSpecName());
				insertPsta.setString(16, tity.getJudgeStoveNo());
				insertPsta.setString(17, systime);
				insertPsta.setString(18, parm2.get(2));
				insertPsta.setString(19, parm2.get(3));
				insertPsta.setString(20, parm2.get(4));
				insertPsta.setString(21, tity.getDiameter());
				insertPsta.setString(22, tity.getThickness());
				insertPsta.setString(23, milOfflineEntity.getZpHeight());// 重量

				insertPsta.setString(24, milOfflineEntity.getGroupNumCount());
				insertPsta.setString(25, milOfflineEntity.getJudgeStoveNo());
				insertPsta.setString(26, milOfflineEntity.getLotNo());
				insertPsta.setString(27, milOfflineEntity.getPlineCode());
				insertPsta.setString(28, milOfflineEntity.getOfflineType());
				if (milOfflineEntity.getOfflinePro().equals("探伤")) {
					insertPsta.setString(29, "TS");// 下线工序
				} else if (milOfflineEntity.getOfflinePro().equals("质检")) {
					insertPsta.setString(29, "ZJ");// 下线工序
				} else if (milOfflineEntity.getOfflinePro().equals("交库")) {
					insertPsta.setString(29, "XX");// 下线工序
				}

				insertPsta.setString(30, milOfflineEntity.getGroupNumCount());
				insertPsta.setString(31, "");
				insertPsta.setString(32, systime);
				insertPsta.setString(33, parm2.get(2));
				insertPsta.setString(34, parm2.get(3));
				insertPsta.setString(35, parm2.get(4));

				insertPsta.setString(36, milOfflineEntity.getJudgeStoveNo());
				insertPsta.setString(37, milOfflineEntity.getLotNo());
				insertPsta.setString(38, milOfflineEntity.getPlineCode());
				insertPsta.setString(39, milOfflineEntity.getOfflineType());
				if (milOfflineEntity.getOfflinePro().equals("探伤")) {
					insertPsta.setString(40, "TS");// 下线工序
				} else if (milOfflineEntity.getOfflinePro().equals("质检")) {
					insertPsta.setString(40, "ZJ");// 下线工序
				} else if (milOfflineEntity.getOfflinePro().equals("交库")) {
					insertPsta.setString(40, "XX");// 下线工序
				}

				insertPsta.setString(41, milOfflineEntity.getJudgeStoveNo());
				insertPsta.setString(42, milOfflineEntity.getLotNo());
				insertPsta.setString(43, milOfflineEntity.getPlineCode());
				insertPsta.setString(44, milOfflineEntity.getOfflineType());
				insertPsta.addBatch();

				updatePortFlagPsta.setString(1, milOfflineEntity
						.getJudgeStoveNo());
				updatePortFlagPsta.setString(2, milOfflineEntity
						.getGroupNumCount());
				updatePortFlagPsta.setString(3, milOfflineEntity
						.getJudgeStoveNo());
				updatePortFlagPsta.addBatch();
				// deleteMatPsta.setString(1,
				// milOfflineEntity.getJudgeStoveNo().substring(0, 6));
				// deleteMatPsta.setString(2,
				// milOfflineEntity.getJudgeStoveNo().substring(0, 6));
				// deleteMatPsta.addBatch();
				totalCount = totalCount
						+ Integer.parseInt(milOfflineEntity.getGroupNumCount());
				strWgt = strWgt
						+ Double.parseDouble(milOfflineEntity.getZpHeight());
			}

			insertOfflinePsta.setString(1, tity.getJudgeStoveNo());
			insertOfflinePsta.setString(2, tity.getLotNo());
			insertOfflinePsta.setString(3, tity.getPlineCode());
			if (tity.getOfflinePro().equals("探伤")) {
				insertOfflinePsta.setString(4, "TS");
			} else if (tity.getOfflinePro().equals("质检")) {
				insertOfflinePsta.setString(4, "ZJ");
			} else if (tity.getOfflinePro().equals("交库")) {
				insertOfflinePsta.setString(4, "XX");
			}
			insertOfflinePsta.setString(5, tity.getOfflineType());
			insertOfflinePsta.setString(6, parm2.get(1));
			insertOfflinePsta.setString(7, parm2.get(0));
			insertOfflinePsta.setString(8, String.valueOf(totalCount));
			insertOfflinePsta.setString(9, systime);
			insertOfflinePsta.setString(10, parm2.get(2));
			insertOfflinePsta.setString(11, parm2.get(3));
			insertOfflinePsta.setString(12, parm2.get(4));
			insertOfflinePsta.setString(13, tity.getOfflineType());
			insertOfflinePsta.setString(14, String.valueOf(strWgt));// 重量
			// insertOfflinePsta.setInt(15, totalCount);//
			insertOfflinePsta.setString(15, parm2.get(0)); // 组批炉号
			insertOfflinePsta.addBatch();

			insertPsta.executeBatch();
			insertOfflinePsta.executeBatch();
			updatePortFlagPsta.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;
	}

	/***
	 * 撤销组炉批
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject doCancelFurnace(ArrayList<String> parm,
			ArrayList<String> parm1) {
		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);
		int acount = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String deleteSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.doCancelFurnace");
			PreparedStatement deletePsta = connection
					.prepareStatement(deleteSql);
			for (String str : parm) {
				MilOfflineGroupEntity1 milOfflineGroup = EntityTool
						.getEntityByJSONStr(str, MilOfflineGroupEntity1.class);
				sql = CoreXmlSqlParsersFactory
						.getSql("doCancelFurnace.doQueryOfflineResult");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milOfflineGroup.getZpLotNo());
				psta.setString(2, milOfflineGroup.getZpJudgeStoveNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (acount > 0) {
					cro.setV_errMsg("该炉信息已进行其他操作,不允许撤销!");
					return cro;
				}
				for (String str1 : parm1) {
					MilOfflineGroupEntity1 milOfflineGroup1 = EntityTool
							.getEntityByJSONStr(str1,
									MilOfflineGroupEntity1.class);
					deletePsta.setString(1, milOfflineGroup1
							.getOldZpJudgeStoveNo());
					deletePsta.setString(2, milOfflineGroup1.getZpCount());
					deletePsta.setString(3, milOfflineGroup1
							.getOldZpJudgeStoveNo());
					deletePsta
							.setString(4, milOfflineGroup.getZpJudgeStoveNo());
					deletePsta.setString(5, milOfflineGroup.getZpLotNo());
					deletePsta.setString(6, milOfflineGroup1.getOperationId());
					deletePsta.setString(7, milOfflineGroup1.getOperationId());
					deletePsta.setString(8, milOfflineGroup1.getZpCount());
					deletePsta.setString(9, milOfflineGroup1
							.getOldZpJudgeStoveNo());
					deletePsta.setString(10, milOfflineGroup1.getOldZpLotNo());
					deletePsta.setString(11, milOfflineGroup1.getOfflinePro());
					deletePsta.setString(12, milOfflineGroup1.getZpCount());
					deletePsta.setString(13, milOfflineGroup1
							.getOldZpJudgeStoveNo());
					deletePsta.setString(14, milOfflineGroup1.getOldZpLotNo());
					deletePsta.setString(15, milOfflineGroup1.getOfflinePro());

					deletePsta.addBatch();
				}

			}
			deletePsta.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 parm
	 * @return
	 */
	public CoreReturnObject qualityInspectionTrust(ArrayList<String> parm,
			ArrayList<String> parm2) {
		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);
		SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyMMdd");
		String systime1 = dateFormat1.format(now);

		int acount = 0;
		String isOk = ""; // 0-未变仓库位置；1-已导运
		String insertRackSql = "";
		PreparedStatement insertRackPsta = null;
		String insertRackSql1 = "";
		PreparedStatement insertRackPsta1 = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.qualityInspectionTrust1");// 插入计划
			PreparedStatement insertPsta = connection
					.prepareStatement(insertSql);
			String deleteMatSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.deleteMatStore");// 消亡待处理虚拟库存
			PreparedStatement deleteMatPsta = connection
					.prepareStatement(deleteMatSql);
			insertRackSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.insertRack");// 插入管号队列(质检返质检)
			insertRackPsta = connection.prepareStatement(insertRackSql);
			insertRackSql1 = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.insertRack1");// 插入管号队列(探伤返质检)
			insertRackPsta1 = connection.prepareStatement(insertRackSql1);
			String updateID = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.updateID"); // 统一组炉炉号进程表ID
			PreparedStatement updateIDPsta = connection
					.prepareStatement(updateID);
			for (String str : parm) {
				// insertRackSql =
				// CoreXmlSqlParsersFactory.getSql("FrmDownlineManage.insertRack");//插入管号队列
				MilOfflineReslutEntity2 tity = EntityTool.getEntityByJSONStr(
						str, MilOfflineReslutEntity2.class);

				// 查询是否已脱单
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.doQueryTake");
				psta = connection.prepareStatement(sql);
				psta.setString(1, tity.getJudgeStoveNo());
				psta.setString(2, tity.getLotNo());
				psta.setString(3, tity.getOfflinePro());
				psta.setString(4, tity.getProPlanId());
				psta.setString(5, tity.getGxPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.doQueryTake2");
				psta = connection.prepareStatement(sql);
				psta.setString(1, tity.getJudgeStoveNo());
				psta.setString(2, tity.getLotNo());
				psta.setString(3, tity.getPlineCode());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount += Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (acount != 0) {
					cro.setV_errMsg("此炉已脱单,请组炉后再生成质检委托!");
					return cro;
				}

				/*
				 * acount = 0; sql = CoreXmlSqlParsersFactory
				 * .getSql("FrmDownlineManage.doQuerySubcontract"); // 是否委外完成
				 * psta = connection.prepareStatement(sql); psta.setString(1,
				 * tity.getJudgeStoveNo()); psta.setString(2, tity.getLotNo());
				 * psta.setString(3, tity.getPlineCode()); rs =
				 * psta.executeQuery(); if (rs.next()) { acount =
				 * Integer.parseInt(rs.getString("ACOUNT")); } rs.close();
				 * psta.close(); if (acount != 0) {
				 * cro.setV_errMsg("有委外信息未处理完成,不能返线!"); return cro; }
				 */

				sql = CoreXmlSqlParsersFactory
						.getSql("SurfaceInspectionResult.doQueryCount");// 查询待处理是否已有转移的支数
				psta = connection.prepareStatement(sql);
				psta.setString(1, tity.getJudgeStoveNo());
				psta.setString(2, tity.getOfflineDoc());
				rs = psta.executeQuery();
				if (rs.next()) {
					isOk = rs.getString("ISOK").toString();
				}
				rs.close();
				psta.close();
				if (isOk.equals("1")) {
					cro.setV_errMsg("炉号" + tity.getJudgeStoveNo()
							+ "已导运到其它库,不能返线!");
					return cro;
				}

				if (tity.getOfflinePro().contains("质检")) {
					if (tity.getZpFlag().equals("正常下线")) {
						sql = CoreXmlSqlParsersFactory
								.getSql("doFurnace.doQueryMilPlan");
						psta = connection.prepareStatement(sql);
						psta.setString(1, tity.getJudgeStoveNo());
						psta.setString(2, tity.getLotNo());
						psta.setString(3, "96");
						/*
						 * psta.setString(4, tity.getProPlanId());
						 * psta.setString(5, tity.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;
						}

						sql = CoreXmlSqlParsersFactory
								.getSql("FrmDownlineManage.doQueryCckCount");// 查询待处理在产出库的支数
						psta = connection.prepareStatement(sql);
						psta.setString(1, tity.getJudgeStoveNo());
						psta.setString(2, tity.getOfflineDoc());
						rs = psta.executeQuery();
						if (rs.next()) {
							acount = Integer.parseInt(rs.getString("ACOUNT"));
						}
						rs.close();
						psta.close();
						if (acount < Integer.parseInt(tity.getGroupNumCount())) {
							cro.setV_errMsg("炉号" + tity.getJudgeStoveNo()
									+ "已导运到其它库,不能返线!");
							return cro;
						}

						insertRackPsta.setString(1, tity.getProPlanId()); // 轧管订单编号
						insertRackPsta.setString(2, tity.getGxPlanNo()); // 工序排产序号
						insertRackPsta.setString(3, tity.getJudgeStoveNo());
						insertRackPsta.setString(4, tity.getJudgeStoveNo());

						insertRackPsta.setString(5, tity.getPlineCode());
						insertRackPsta.setString(6, tity.getPlineCode());

						insertRackPsta.setString(7, tity.getPlineCode());
						insertRackPsta.setString(8, tity.getJudgeStoveNo());

						insertRackPsta.setString(9, tity.getLotNo());
						insertRackPsta.setString(10, tity.getPlineCode());
						insertRackPsta.setString(11, "0");
						insertRackPsta.setInt(12, Integer.parseInt(tity
								.getGroupNumCount()));

						insertRackPsta.setString(13, tity.getLotNo());
						insertRackPsta.setString(14, tity.getPlineCode());
						insertRackPsta.setString(15, systime);

						insertRackPsta.setString(16, tity.getLotNo());
						insertRackPsta.setString(17, "");

						insertRackPsta.setString(18, tity.getJudgeStoveNo());

						insertRackPsta.setString(19, tity.getLotNo());
						insertRackPsta.setString(20, tity.getPlineCode());
						insertRackPsta.setString(21, tity.getJudgeStoveNo());

						insertRackPsta.addBatch();

						deleteMatPsta.setString(1, tity.getJudgeStoveNo());
						deleteMatPsta.setString(2, tity.getOfflineDoc());
						deleteMatPsta.setInt(3, Integer.parseInt(tity
								.getGroupNumCount()));
						deleteMatPsta.addBatch();
					} else {// 组炉
						ArrayList<String> jugeNoList = new ArrayList<String>();
						ArrayList<String> lotNoList = new ArrayList<String>();
						ArrayList<String> acountList = new ArrayList<String>();
						ArrayList<String> proPlanIdList = new ArrayList<String>();
						ArrayList<String> gxPlanNoList = new ArrayList<String>();
						sql = CoreXmlSqlParsersFactory
								.getSql("qualityInspectionTrust.doQueryJugeNo");
						psta = connection.prepareStatement(sql);
						psta.setString(1, tity.getJudgeStoveNo());
						psta.setString(2, tity.getPlineCode());
						rs = psta.executeQuery();
						while (rs.next()) {
							jugeNoList.add(rs
									.getString("OLD_ZP_JUDGE_STOVE_NO"));
							lotNoList.add(rs.getString("OLD_ZP_LOT_NO"));
							acountList.add(rs.getString("ZP_COUNT"));
							proPlanIdList.add(rs.getString("PRO_PLAN_ID"));
							gxPlanNoList.add(rs.getString("GX_PLAN_NO"));
						}
						rs.close();
						psta.close();
						for (int i = 0; i < jugeNoList.size(); i++) {
							insertRackPsta.setString(1, tity.getProPlanId()); // 轧管订单编号
							insertRackPsta.setString(2, tity.getGxPlanNo()); // 工序排产序号
							insertRackPsta.setString(3, tity.getJudgeStoveNo());
							insertRackPsta.setString(4, tity.getJudgeStoveNo());

							insertRackPsta.setString(5, tity.getPlineCode());
							insertRackPsta.setString(6, tity.getPlineCode());

							insertRackPsta.setString(7, tity.getPlineCode());
							insertRackPsta.setString(8, jugeNoList.get(i));
							insertRackPsta.setString(9, lotNoList.get(i));
							insertRackPsta.setString(10, tity.getPlineCode());
							insertRackPsta.setString(11, "1");
							/*
							 * insertRackPsta.setInt(16, Integer
							 * .parseInt(acountList.get(i)));
							 */
							insertRackPsta.setInt(12, Integer.parseInt(tity
									.getGroupNumCount()));

							insertRackPsta.setString(13, tity.getLotNo());
							insertRackPsta.setString(14, tity.getPlineCode());
							insertRackPsta.setString(15, systime);

							insertRackPsta.setString(16, tity.getLotNo());
							insertRackPsta.setString(17, "");

							insertRackPsta.setString(18, jugeNoList.get(i));
							insertRackPsta.setString(19, tity.getLotNo());
							insertRackPsta.setString(20, tity.getPlineCode());
							insertRackPsta.setString(21, jugeNoList.get(i));

							insertRackPsta.addBatch();

							//组炉返线，删除的也是原炉号的离线数据
							deleteMatPsta.setString(1, tity.getJudgeStoveNo());
							deleteMatPsta.setString(2, tity.getOfflineDoc());
							deleteMatPsta.setInt(3, Integer.parseInt(acountList
									.get(i)));
							deleteMatPsta.addBatch();
						}

					}
				} else if (tity.getOfflinePro().contains("探伤")) {
					// 查询是否未探下线
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmDownlineManage.doQueryOfflineType");
					psta = connection.prepareStatement(sql);
					psta.setString(1, tity.getJudgeStoveNo());
					psta.setString(2, tity.getProPlanId());
					psta.setString(3, tity.getGxPlanNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("OFFLINE_TYPE"));
					}
					rs.close();
					psta.close();
					if (acount == 1) {
						cro.setV_errMsg("此炉是未探下线,不允许生成质检委托!");
						return cro;
					}

					if (tity.getZpFlag().equals("正常下线")) {
						sql = CoreXmlSqlParsersFactory
								.getSql("doFurnace.doQueryMilPlan");
						psta = connection.prepareStatement(sql);
						psta.setString(1, tity.getJudgeStoveNo());
						psta.setString(2, tity.getLotNo());
						psta.setString(3, "90");
						/*
						 * psta.setString(4, tity.getProPlanId());
						 * psta.setString(5, tity.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;
						}

						sql = CoreXmlSqlParsersFactory
								.getSql("FrmDownlineManage.doQueryCckCount");// 查询待处理在产出库的支数
						psta = connection.prepareStatement(sql);
						psta.setString(1, tity.getJudgeStoveNo());
						psta.setString(2, tity.getOfflineDoc());
						rs = psta.executeQuery();
						if (rs.next()) {
							acount = Integer.parseInt(rs.getString("ACOUNT"));
						}
						rs.close();
						psta.close();
						if (acount < Integer.parseInt(tity.getGroupNumCount())) {
							cro.setV_errMsg("炉号" + tity.getJudgeStoveNo()
									+ "已导运到其它库,不能返线!");
							return cro;
						}

						insertRackPsta1.setString(1, tity.getJudgeStoveNo());
						insertRackPsta1.setString(2, tity.getJudgeStoveNo());
						insertRackPsta1.setString(3, tity.getProPlanId()); // 轧管订单编号
						insertRackPsta1.setString(4, tity.getGxPlanNo()); // 工序排产序号
						insertRackPsta1.setString(5, tity.getPlineCode());
						insertRackPsta1.setString(6, tity.getPlineCode());
						insertRackPsta1.setString(7, tity.getProPlanId()); // 轧管订单编号
						insertRackPsta1.setString(8, tity.getGxPlanNo()); // 工序排产序号

						insertRackPsta1.setString(9, tity.getPlineCode());
						insertRackPsta1.setString(10, tity.getJudgeStoveNo());
						insertRackPsta1.setString(11, tity.getProPlanId()); // 轧管订单编号
						insertRackPsta1.setString(12, tity.getGxPlanNo()); // 工序排产序号
						insertRackPsta1.setString(13, tity.getLotNo());
						insertRackPsta1.setString(14, tity.getPlineCode());
						insertRackPsta1.setString(15, "0");
						insertRackPsta1.setInt(16, Integer.parseInt(tity
								.getGroupNumCount()));
						insertRackPsta1.setString(17, tity.getLotNo());
						insertRackPsta1.setString(18, tity.getPlineCode());
						insertRackPsta1.setString(19, systime);
						insertRackPsta1.setString(20, tity.getProPlanId()); // 轧管订单编号
						insertRackPsta1.setString(21, tity.getGxPlanNo()); // 工序排产序号

						insertRackPsta1.setString(22, tity.getLotNo());
						insertRackPsta1.setString(23, "");
						insertRackPsta1.setString(24, tity.getProPlanId()); // 轧管订单编号
						insertRackPsta1.setString(25, tity.getGxPlanNo()); // 工序排产序号
						insertRackPsta1.setString(26, tity.getJudgeStoveNo());

						insertRackPsta1.setString(27, tity.getLotNo());
						insertRackPsta1.setString(28, tity.getPlineCode());
						insertRackPsta1.setString(29, tity.getJudgeStoveNo());

						insertRackPsta1.addBatch();

						deleteMatPsta.setString(1, tity.getJudgeStoveNo());
						deleteMatPsta.setString(2, tity.getOfflineDoc());
						deleteMatPsta.setInt(3, Integer.parseInt(tity
								.getGroupNumCount()));
						deleteMatPsta.addBatch();
					} else {// 组炉
						ArrayList<String> jugeNoList = new ArrayList<String>();
						ArrayList<String> lotNoList = new ArrayList<String>();
						ArrayList<String> acountList = new ArrayList<String>();
						ArrayList<String> proPlanIdList = new ArrayList<String>();
						ArrayList<String> gxPlanNoList = new ArrayList<String>();
						sql = CoreXmlSqlParsersFactory
								.getSql("qualityInspectionTrust.doQueryJugeNo");
						psta = connection.prepareStatement(sql);
						psta.setString(1, tity.getJudgeStoveNo());
						psta.setString(2, tity.getPlineCode());
						rs = psta.executeQuery();
						while (rs.next()) {
							jugeNoList.add(rs
									.getString("OLD_ZP_JUDGE_STOVE_NO"));
							lotNoList.add(rs.getString("OLD_ZP_LOT_NO"));
							acountList.add(rs.getString("ZP_COUNT"));
							proPlanIdList.add(rs.getString("PRO_PLAN_ID"));
							gxPlanNoList.add(rs.getString("GX_PLAN_NO"));
						}
						rs.close();
						psta.close();
						for (int i = 0; i < jugeNoList.size(); i++) {
							insertRackPsta1
									.setString(1, tity.getJudgeStoveNo());
							insertRackPsta1
									.setString(2, tity.getJudgeStoveNo());
							insertRackPsta1.setString(3, tity.getProPlanId()); // 轧管订单编号
							insertRackPsta1.setString(4, tity.getGxPlanNo()); // 工序排产序号
							insertRackPsta1.setString(5, tity.getPlineCode());
							insertRackPsta1.setString(6, tity.getPlineCode());
							insertRackPsta1.setString(7, tity.getProPlanId()); // 轧管订单编号
							insertRackPsta1.setString(8, tity.getGxPlanNo()); // 工序排产序号

							insertRackPsta1.setString(9, tity.getPlineCode());
							insertRackPsta1.setString(10, jugeNoList.get(i));
							insertRackPsta1.setString(11, proPlanIdList.get(i)); // 轧管订单编号
							insertRackPsta1.setString(12, gxPlanNoList.get(i)); // 工序排产序号
							insertRackPsta1.setString(13, lotNoList.get(i));
							insertRackPsta1.setString(14, tity.getPlineCode());
							insertRackPsta1.setString(15, "1");
							insertRackPsta1.setInt(16, Integer
									.parseInt(acountList.get(i)));
							insertRackPsta1.setString(17, tity.getLotNo());
							insertRackPsta1.setString(18, tity.getPlineCode());
							insertRackPsta1.setString(19, systime);
							insertRackPsta1.setString(20, tity.getProPlanId()); // 轧管订单编号
							insertRackPsta1.setString(21, tity.getGxPlanNo()); // 工序排产序号

							insertRackPsta1.setString(22, tity.getLotNo());
							insertRackPsta1.setString(23, "");
							insertRackPsta1.setString(24, tity.getProPlanId()); // 轧管订单编号
							insertRackPsta1.setString(25, tity.getGxPlanNo()); // 工序排产序号
							insertRackPsta1.setString(26, jugeNoList.get(i));

							insertRackPsta1.setString(27, tity.getLotNo());
							insertRackPsta1.setString(28, tity.getPlineCode());
							insertRackPsta1.setString(29, jugeNoList.get(i));

							insertRackPsta1.addBatch();

							//组炉返线，删除的也是原炉号的离线数据
							deleteMatPsta.setString(1, tity.getJudgeStoveNo());
							deleteMatPsta.setString(2, tity.getOfflineDoc());
							deleteMatPsta.setInt(3, Integer.parseInt(acountList
									.get(i)));
							deleteMatPsta.addBatch();
						}
					}
				}
				insertPsta.setString(1, tity.getProPlanId()); // 轧管订单编号
				insertPsta.setString(2, tity.getGxPlanNo()); // 工序排产序号
				if (tity.getLotNo().endsWith("试轧料")) {
					insertPsta.setString(3, "");
				} else {
					insertPsta.setString(3, tity.getContractNo().substring(0,
							tity.getContractNo().indexOf("/")));
				}
				insertPsta.setString(4, tity.getContractNo());
				insertPsta.setString(5, tity.getJudgeStoveNo());
				insertPsta.setString(6, tity.getJudgeStoveNo());

				insertPsta.setString(7, tity.getPlineCode());
				insertPsta.setString(8, systime1);
				insertPsta.setString(9, tity.getPlineCode());
				insertPsta.setString(10, systime1);
				insertPsta.setString(11, systime1);
				// insertPsta.setString(5, tity.getPlineCode());
				if (tity.getZpFlag().equals("正常下线")) {
					insertPsta.setString(12, tity.getJudgeStoveNo());
				} else {
					insertPsta.setString(12, tity.getZpMLh());
				}
				insertPsta.setString(13, tity.getPlineCode());
				insertPsta.setString(14, tity.getGroupNumCount());
				insertPsta.setString(15, tity.getZpHeight());// 重量
				insertPsta.setString(16, systime);
				insertPsta.setString(17, systime);
				insertPsta.setString(18, systime);
				insertPsta.setString(19, tity.getStdName());
				insertPsta.setString(20, tity.getLotNo());

				insertPsta.setString(21, tity.getContractNo());
				insertPsta.setString(22, tity.getImpProcess());
				insertPsta.setString(23, tity.getLength());
				insertPsta.setString(24, tity.getProducname());
				insertPsta.setString(25, tity.getSpecName().replace("x", "*"));
				insertPsta.setString(26, tity.getModelDesc());
				insertPsta.setString(27, tity.getActLenRange());
				insertPsta.setString(28, tity.getStdName());
				insertPsta.setString(29, tity.getSteelcode());
				insertPsta.setString(30, tity.getSteelname());

				insertPsta.setString(31, tity.getProduccode());
				insertPsta.setString(32, tity.getSpecCode());
				insertPsta.setString(33, tity.getModelCode());
				insertPsta.setString(34, tity.getStdCode());
				insertPsta.setString(35, tity.getStdStyle());
				insertPsta.setString(36, tity.getStdStyleDesc());

				insertPsta.setString(37, tity.getLotNo());
				insertPsta.setString(38, tity.getJudgeStoveNo());
				insertPsta.setString(39, tity.getGroupNumCount());
				insertPsta.setString(40, tity.getZpHeight());// 重量
				insertPsta.setString(41, systime);
				insertPsta.setString(42, parm2.get(0));
				insertPsta.setString(43, parm2.get(1));
				insertPsta.setString(44, parm2.get(2));

				insertPsta.setString(45, tity.getOfflineType());
				insertPsta.setString(46, tity.getGroupNumCount());

				insertPsta.setString(47, tity.getJudgeStoveNo());

				insertPsta.setString(48, tity.getLotNo());
				insertPsta.setString(49, tity.getPlineCode());
				if (tity.getOfflinePro().equals("探伤")) {
					insertPsta.setString(50, "TS");
				} else {
					insertPsta.setString(50, "ZJ");
				}
				insertPsta.setString(51, tity.getOfflineType());

				insertPsta.setString(52, tity.getJudgeStoveNo());
				insertPsta.setString(53, tity.getLotNo());
				insertPsta.setString(54, tity.getPlineCode());
				if (tity.getOfflinePro().equals("探伤")) {
					insertPsta.setString(55, "TS");
				} else {
					insertPsta.setString(55, "ZJ");
				}
				insertPsta.setString(56, tity.getOfflineType());

				insertPsta.setString(57, tity.getJudgeStoveNo());
				insertPsta.setString(58, tity.getLotNo());
				insertPsta.setString(59, tity.getPlineCode());
				if (tity.getOfflinePro().equals("探伤")) {
					insertPsta.setString(60, "TS");
				} else {
					insertPsta.setString(60, "ZJ");
				}
				insertPsta.setString(61, tity.getOfflineType());

				insertPsta.addBatch();

				// 统一组炉炉号进程表ID
				if (!tity.getZpFlag().equals("正常下线")) {
					updateIDPsta.setString(1, tity.getJudgeStoveNo());
					updateIDPsta.addBatch();
				}
			}

			insertRackPsta.executeBatch(); // 插入管号队列
			insertRackPsta1.executeBatch();
			insertPsta.executeBatch(); // 插入计划
			deleteMatPsta.executeBatch(); // 消亡待处理虚拟库存
			updateIDPsta.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 parm
	 * @return
	 */
	public CoreReturnObject backPipe(ArrayList<String> parm,
			ArrayList<String> parm1) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		int acount = 0;
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String systime = dateFormat.format(now);
		String isOk = ""; // 0-未变仓库位置；1-已导运
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String backPipSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.backPipeMianPlan");// 插入计划、返线交库点
			// (委托产线写进程表待更新)
			PreparedStatement backPipPsta = connection
					.prepareStatement(backPipSql);
			String deleteMatSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.deleteMatStore");// 消亡待处理虚拟库存
			PreparedStatement deleteMatPsta = connection
					.prepareStatement(deleteMatSql);
			// String backPipProcessSql =
			// CoreXmlSqlParsersFactory.getSql("FrmDownlineManage.backPipePort");//生成新的进程管号队列
			// PreparedStatement backPipProcessPsta =
			// connection.prepareStatement(backPipProcessSql);
			String insertOutlistSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.insertOutlist");// 插入出库表计录
			PreparedStatement insertOutlistPsta = connection
					.prepareStatement(insertOutlistSql);
			for (String str : parm) {
				MilOfflineReslutEntity2 milOfflineRs = EntityTool
						.getEntityByJSONStr(str, MilOfflineReslutEntity2.class);

				// 查询是否已脱单
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.doQueryTake");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milOfflineRs.getJudgeStoveNo());
				psta.setString(2, milOfflineRs.getLotNo());
				psta.setString(3, milOfflineRs.getOfflinePro());
				psta.setString(4, milOfflineRs.getProPlanId());
				psta.setString(5, milOfflineRs.getGxPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.doQueryTake2");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milOfflineRs.getJudgeStoveNo());
				psta.setString(2, milOfflineRs.getLotNo());
				psta.setString(3, milOfflineRs.getPlineCode());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount += Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (acount != 0) {
					cro.setV_errMsg("此炉已脱单,请组炉后再返线!");
					return cro;
				}
				// 组炉不卡倒运
				if (milOfflineRs.getZpFlag().equals("正常下线")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("SurfaceInspectionResult.doQueryCount");// 查询待处理是否已有转移的支数
					psta = connection.prepareStatement(sql);
					psta.setString(1, milOfflineRs.getJudgeStoveNo());
					psta.setString(2, milOfflineRs.getOfflineDoc());
					rs = psta.executeQuery();
					if (rs.next()) {
						isOk = rs.getString("ISOK").toString();
					}
					rs.close();
					psta.close();
					if (isOk.equals("1")) {
						cro.setV_errMsg("炉号" + milOfflineRs.getJudgeStoveNo()
								+ "已导运到其它库,不能返线!");
						return cro;
					}

					acount = 0;
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmDownlineManage.doQueryCckCount");// 查询待处理在产出库的支数
					psta = connection.prepareStatement(sql);
					psta.setString(1, milOfflineRs.getJudgeStoveNo());
					psta.setString(2, milOfflineRs.getOfflineDoc());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if (acount < Integer.parseInt(milOfflineRs
							.getGroupNumCount())) {
						cro.setV_errMsg("炉号" + milOfflineRs.getJudgeStoveNo()
								+ "已导运到其它库,不能返线!");
						return cro;
					}

					acount = 0;
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmDownlineManage.doQueryNodeXX");// 查询下线点是否结炉
					psta = connection.prepareStatement(sql);
					psta.setString(1, milOfflineRs.getJudgeStoveNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if (acount < 1) {
						cro.setV_errMsg("下线点未结炉,不能返线!");
						return cro;
					}
				}

				if (milOfflineRs.getSubcontractCompleteCut().equals(""))
					milOfflineRs.setSubcontractCompleteCut("1");

				backPipPsta.setString(1, milOfflineRs.getJudgeStoveNo());
				backPipPsta.setString(2, milOfflineRs.getPlineCode());
				if(milOfflineRs.getZpFlag().equals("组炉批")){
					backPipPsta.setString(3, milOfflineRs.getZpMLh());
				}else{
					backPipPsta.setString(3, milOfflineRs.getJudgeStoveNo());
				}

				if (milOfflineRs.getLotNo().endsWith("试轧料")) {
					backPipPsta.setString(4, "");
				} else {
					backPipPsta.setString(4, milOfflineRs.getContractNo()
							.substring(0,
									milOfflineRs.getContractNo().indexOf("/")));
				}

				backPipPsta.setString(5, milOfflineRs.getContractNo());
				backPipPsta.setString(6, milOfflineRs.getJudgeStoveNo());
				backPipPsta.setString(7, milOfflineRs.getPlineCode());
				backPipPsta.setString(8, milOfflineRs.getPlineCode());
				
				backPipPsta.setString(9, milOfflineRs.getPlineCode());
				backPipPsta.setString(10, milOfflineRs.getGroupNumCount());
				if (milOfflineRs.getSubcontractNum().equals("0")) {
					backPipPsta.setString(11, new DecimalFormat("0.000")
							.format(Double.parseDouble(milOfflineRs
									.getZpHeight())));// 重量
				} else {
					backPipPsta.setString(11, new DecimalFormat("0.000")
							.format(Double.parseDouble(milOfflineRs
									.getSubcontractcompleteWgt())));// 重量
				}

				backPipPsta.setString(12, systime);
				backPipPsta.setString(13, systime);
				backPipPsta.setString(14, systime);
				backPipPsta.setString(15, milOfflineRs.getLotNo());

				backPipPsta.setString(16, milOfflineRs.getContractNo());
				backPipPsta.setString(17, milOfflineRs.getLength());
				backPipPsta.setString(18, milOfflineRs.getProducname());
				backPipPsta.setString(19, milOfflineRs.getSpecName());
				backPipPsta.setString(20, milOfflineRs.getModelDesc());
				backPipPsta.setString(21, milOfflineRs.getActLenRange());
				// backPipPsta.setString(22, milOfflineRs.getStdName());
				backPipPsta.setString(22, milOfflineRs.getSteelcode());
				backPipPsta.setString(23, milOfflineRs.getSteelname());

				backPipPsta.setString(24, milOfflineRs.getProduccode());
				backPipPsta.setString(25, milOfflineRs.getSpecCode());
				backPipPsta.setString(26, milOfflineRs.getModelCode());
				backPipPsta.setString(27, milOfflineRs.getStdCode());
				backPipPsta.setString(28, milOfflineRs.getStdStyle());
				backPipPsta.setString(29, milOfflineRs.getStdStyleDesc());

				backPipPsta.setString(30, milOfflineRs.getLotNo());
				backPipPsta.setString(31, milOfflineRs.getJudgeStoveNo());
				backPipPsta.setString(32, milOfflineRs.getGroupNumCount());
				if (milOfflineRs.getSubcontractNum().equals("0")) {
					backPipPsta.setString(33, new DecimalFormat("0.000")
							.format(Double.parseDouble(milOfflineRs
									.getZpHeight())));// 重量
				} else {
					backPipPsta.setString(33, new DecimalFormat("0.000")
							.format(Double.parseDouble(milOfflineRs
									.getSubcontractcompleteWgt())));// 重量
				}

				backPipPsta.setString(34, systime);
				backPipPsta.setString(35, "");
				backPipPsta.setString(36, parm1.get(0));
				backPipPsta.setString(37, parm1.get(1));
				backPipPsta.setString(38, parm1.get(2));
				backPipPsta.setString(39, "0");

				backPipPsta.setString(40, milOfflineRs.getGroupNumCount());
				backPipPsta.setString(41, milOfflineRs.getJudgeStoveNo());
				backPipPsta.setString(42, milOfflineRs.getLotNo());
				backPipPsta.setString(43, milOfflineRs.getPlineCode());
				backPipPsta.setString(44, milOfflineRs.getJudgeStoveNo());
				backPipPsta.setString(45, milOfflineRs.getLotNo());
				backPipPsta.setString(46, milOfflineRs.getPlineCode());
				// backPipPsta.setInt(38,
				// Integer.parseInt(milOfflineRs.getGroupNumCount()));
				if(milOfflineRs.getZpFlag().equals("组炉批")){
					backPipPsta.setString(47, milOfflineRs.getZpMLh());
				}else{
					backPipPsta.setString(47, milOfflineRs.getJudgeStoveNo());
				}
				backPipPsta.setString(48, milOfflineRs.getLotNo());
				backPipPsta.setString(49, milOfflineRs.getPlineCode());

				if (milOfflineRs.getZpFlag().equals("正常下线")) {
					backPipPsta.setString(50, milOfflineRs.getJudgeStoveNo());
				}else{
					backPipPsta.setString(50, milOfflineRs.getZpMLh());
				}
				
				backPipPsta.setString(51, milOfflineRs.getLotNo());
				backPipPsta.setString(52, milOfflineRs.getPlineCode());
				if (milOfflineRs.getSubcontractNum().equals("0")) {
					backPipPsta.setInt(53, Integer.parseInt(milOfflineRs
							.getGroupNumCount()));
					backPipPsta.setInt(54, 1);
					backPipPsta.setString(55, milOfflineRs.getLotNo());
					backPipPsta.setString(56, "");
					backPipPsta.setInt(57, 1);
					backPipPsta.setInt(58, 1);
					backPipPsta.setString(59, milOfflineRs.getJudgeStoveNo());
					backPipPsta.setInt(60, 0);
				} else {
					backPipPsta.setInt(53, Integer.parseInt(milOfflineRs
							.getSubcontractNum()));
					backPipPsta.setInt(54, Integer.parseInt(milOfflineRs
							.getSubcontractCompleteCut()));
					backPipPsta.setString(55, milOfflineRs.getLotNo());
					backPipPsta.setString(56, milOfflineRs
							.getSubcontractCompleteLen());
					backPipPsta.setInt(57, Integer.parseInt(milOfflineRs
							.getSubcontractCompleteCut()));
					backPipPsta.setInt(58, Integer.parseInt(milOfflineRs
							.getSubcontractCompleteCut()));
					backPipPsta.setString(59, milOfflineRs.getJudgeStoveNo());
					String num="";
					if(!milOfflineRs.getSubcontractscrapNum().equals("")&&milOfflineRs.getSubcontractscrapNum()!=null){
						num=milOfflineRs.getSubcontractscrapNum();
					}else{
						num = "0";
					}
					backPipPsta.setInt(60, Integer.parseInt(num));
				}

				backPipPsta.addBatch();

				// backPipProcessPsta.setString(1,
				// milOfflineRs.getJudgeStoveNo());
				// backPipProcessPsta.setString(2,
				// milOfflineRs.getJudgeStoveNo());
				// backPipProcessPsta.setString(3, milOfflineRs.getPlineCode());
				// backPipProcessPsta.setString(4, milOfflineRs.getPlineCode());
				// backPipProcessPsta.setString(5, milOfflineRs.getPlineCode());
				// backPipProcessPsta.setString(6,
				// milOfflineRs.getJudgeStoveNo());
				// backPipProcessPsta.setString(7, milOfflineRs.getLotNo());
				// backPipProcessPsta.setString(8, milOfflineRs.getPlineCode());
				// backPipProcessPsta.setInt(9,
				// Integer.parseInt(milOfflineRs.getSubcontractNum()));
				// backPipProcessPsta.setInt(10,
				// Integer.parseInt(milOfflineRs.getSubcontractCompleteCut()));
				// backPipProcessPsta.setInt(10,
				// Integer.parseInt(milOfflineRs.getSubcontractCompleteCut()));
				// backPipProcessPsta.setString(11, milOfflineRs.getLotNo());
				// backPipProcessPsta.setString(12,
				// milOfflineRs.getSubcontractCompleteLen());
				// backPipProcessPsta.setString(13,
				// milOfflineRs.getSubcontractCompleteCut());
				// backPipProcessPsta.setString(14,
				// milOfflineRs.getJudgeStoveNo());
				// backPipProcessPsta.setInt(15,
				// Integer.parseInt(milOfflineRs.getSubcontractscrapNum()));
				// backPipProcessPsta.addBatch();

				insertOutlistPsta.setString(1, milOfflineRs.getJudgeStoveNo());
				insertOutlistPsta.setString(2, parm1.get(3));
				insertOutlistPsta.setString(3, parm1.get(4));
				insertOutlistPsta.setInt(4, Integer.parseInt(milOfflineRs
						.getGroupNumCount()));
				insertOutlistPsta.setString(5, parm1.get(2));
				insertOutlistPsta.setString(6, parm1.get(1));
				insertOutlistPsta.setString(7, parm1.get(0));
				insertOutlistPsta.addBatch();
				String numb="";
				if(!milOfflineRs.getSubcontractscrapNum().equals("")&&milOfflineRs.getSubcontractscrapNum()!=null){
					numb=milOfflineRs.getSubcontractscrapNum();
				}else{
					numb = "0";
				}
				if(milOfflineRs.getZpFlag().equals("组炉批")){
					deleteMatPsta.setString(1, milOfflineRs.getZpMLh());
				}else{
					deleteMatPsta.setString(1, milOfflineRs.getJudgeStoveNo());
				}
				deleteMatPsta.setString(2, milOfflineRs.getOfflineDoc());
				deleteMatPsta.setInt(3, Integer.parseInt(milOfflineRs
						.getGroupNumCount())
						+ Integer.parseInt(numb));
				deleteMatPsta.addBatch();
			}
			backPipPsta.executeBatch();
			deleteMatPsta.executeBatch();
			// insertOutlistPsta.executeBatch(); //全部返线都不写出库表了。2018.4.17
			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 parm
	 * @param parm1
	 * @return
	 */
	public CoreReturnObject doBackLine(ArrayList<String> parm,
			ArrayList<String> parm1) {
		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);
		int acount = 0;
		String isOk = ""; // 0-未变仓库位置；1-已导运
		String str1[] = null;
		double strWgt = 0.0;
		int matCount = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.doBackLine");// 返线
			PreparedStatement insertPsta = connection
					.prepareStatement(insertSql);
			String insertTestRackSql = CoreXmlSqlParsersFactory
					.getSql("doBackLine.insertRack");// 生成管号队列
			PreparedStatement insertTestRackPsta = connection
					.prepareStatement(insertTestRackSql);
			String deleteInstoreSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.deleteMatStore");// 消除库存
			PreparedStatement deleteInstorePsta = connection
					.prepareStatement(deleteInstoreSql);
			String updateID = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.updateID"); // 统一组炉炉号进程表ID
			PreparedStatement updateIDPsta = connection
					.prepareStatement(updateID);
			for (String str : parm) {
				MilOfflineReslutEntity2 tity = EntityTool.getEntityByJSONStr(
						str, MilOfflineReslutEntity2.class);
				str1 = tity.getSpecName().split("[*]");
				strWgt = 0.02466
						* Double.parseDouble(str1[1])
						* (Double.parseDouble(str1[0]) - Double
								.parseDouble(str1[1]))
						* Double.parseDouble(tity.getLength())
						* Integer.parseInt(tity.getGroupNumCount()) / 1000;

				// 查询是否已脱单
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.doQueryTake");
				psta = connection.prepareStatement(sql);
				psta.setString(1, tity.getJudgeStoveNo());
				psta.setString(2, tity.getLotNo());
				psta.setString(3, tity.getOfflinePro());
				psta.setString(4, tity.getProPlanId());
				psta.setString(5, tity.getGxPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.doQueryTake2");
				psta = connection.prepareStatement(sql);
				psta.setString(1, tity.getJudgeStoveNo());
				psta.setString(2, tity.getLotNo());
				psta.setString(3, tity.getPlineCode());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount += Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (acount != 0) {
					cro.setV_errMsg("此炉已脱单,请组炉后再探伤返线!");
					return cro;
				}

				/*
				 * acount = 0; sql = CoreXmlSqlParsersFactory
				 * .getSql("FrmDownlineManage.doQuerySubcontract"); // 是否委外完成
				 * psta = connection.prepareStatement(sql); psta.setString(1,
				 * tity.getJudgeStoveNo()); psta.setString(2, tity.getLotNo());
				 * psta.setString(3, tity.getPlineCode()); rs =
				 * psta.executeQuery(); if (rs.next()) { acount =
				 * Integer.parseInt(rs.getString("ACOUNT")); } rs.close();
				 * psta.close(); if (acount != 0) {
				 * cro.setV_errMsg("有委外信息未处理完成,不能返线!"); return cro; }
				 */

				sql = CoreXmlSqlParsersFactory
						.getSql("SurfaceInspectionResult.doQueryCount");// 查询待处理是否已有转移的支数
				psta = connection.prepareStatement(sql);
				psta.setString(1, tity.getJudgeStoveNo());
				psta.setString(2, tity.getOfflineDoc());
				rs = psta.executeQuery();
				if (rs.next()) {
					isOk = rs.getString("ISOK").toString();
				}
				rs.close();
				psta.close();
				if (isOk.equals("1")) {
					cro.setV_errMsg("炉号" + tity.getJudgeStoveNo()
							+ "已导运到其它库,不能撤销!");
					return cro;
				}

				if (tity.getZpFlag().equals("正常下线")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("doFurnace.doQueryMilPlan");
					psta = connection.prepareStatement(sql);
					psta.setString(1, tity.getJudgeStoveNo());
					psta.setString(2, tity.getLotNo());
					psta.setInt(3, 90);
					/*
					 * psta.setString(4, tity.getProPlanId()); psta.setString(5,
					 * tity.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;
					}

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmDownlineManage.doQueryCckCount");// 查询待处理在产出库的支数
					psta = connection.prepareStatement(sql);
					psta.setString(1, tity.getJudgeStoveNo());
					psta.setString(2, tity.getOfflineDoc());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if (acount < Integer.parseInt(tity.getGroupNumCount())) {
						cro.setV_errMsg("炉号" + tity.getJudgeStoveNo()
								+ "已导运到其它库,不能返线!");
						return cro;
					}

					insertTestRackPsta.setString(1, tity.getJudgeStoveNo());
					insertTestRackPsta.setString(2, tity.getJudgeStoveNo());
					insertTestRackPsta.setString(3, tity.getProPlanId()); // 轧管订单编号
					insertTestRackPsta.setString(4, tity.getGxPlanNo()); // 工序排产序号
					insertTestRackPsta.setString(5, tity.getPlineCode());
					insertTestRackPsta.setString(6, tity.getPlineCode());
					insertTestRackPsta.setString(7, tity.getProPlanId()); // 轧管订单编号
					insertTestRackPsta.setString(8, tity.getGxPlanNo()); // 工序排产序号
					// insertTestRackPsta.setString(5, tity.getJudgeStoveNo());
					insertTestRackPsta.setString(9, tity.getPlineCode());
					insertTestRackPsta.setString(10, tity.getJudgeStoveNo());
					insertTestRackPsta.setString(11, tity.getProPlanId()); // 轧管订单编号
					insertTestRackPsta.setString(12, tity.getGxPlanNo()); // 工序排产序号
					insertTestRackPsta.setString(13, tity.getLotNo());
					insertTestRackPsta.setString(14, tity.getPlineCode());
					insertTestRackPsta.setString(15, "0");
					insertTestRackPsta.setInt(16, Integer.parseInt(tity
							.getGroupNumCount()));
					insertTestRackPsta.setString(17, tity.getLotNo());
					insertTestRackPsta.setString(18, tity.getPlineCode());
					insertTestRackPsta.setString(19, systime);
					insertTestRackPsta.setString(20, tity.getProPlanId()); // 轧管订单编号
					insertTestRackPsta.setString(21, tity.getGxPlanNo()); // 工序排产序号

					insertTestRackPsta.setString(22, tity.getLotNo());
					insertTestRackPsta.setString(23, tity.getPlineCode());
					insertTestRackPsta.setString(24, systime);
					insertTestRackPsta.setString(25, tity.getProPlanId()); // 轧管订单编号
					insertTestRackPsta.setString(26, tity.getGxPlanNo()); // 工序排产序号
					insertTestRackPsta.setString(27, tity.getLotNo());
					insertTestRackPsta.setString(28, "");// 熔炼炉号
					insertTestRackPsta.setString(29, tity.getProPlanId()); // 轧管订单编号
					insertTestRackPsta.setString(30, tity.getGxPlanNo()); // 工序排产序号
					insertTestRackPsta.setString(31, tity.getJudgeStoveNo());
					insertTestRackPsta.setString(32, tity.getLotNo());
					insertTestRackPsta.setString(33, tity.getPlineCode());
					insertTestRackPsta.setString(34, tity.getJudgeStoveNo());
					insertTestRackPsta.addBatch();

					deleteInstorePsta.setString(1, tity.getJudgeStoveNo());
					deleteInstorePsta.setString(2, tity.getOfflineDoc());
					deleteInstorePsta.setInt(3, Integer.parseInt(tity
							.getGroupNumCount()));
					deleteInstorePsta.addBatch();

				} else {
					ArrayList<String> jugeNoList = new ArrayList<String>();
					ArrayList<String> lotNoList = new ArrayList<String>();
					ArrayList<String> acountList = new ArrayList<String>();
					ArrayList<String> proPlanIdList = new ArrayList<String>();
					ArrayList<String> gxPlanNoList = new ArrayList<String>();
					sql = CoreXmlSqlParsersFactory
							.getSql("qualityInspectionTrust.doQueryJugeNo");
					psta = connection.prepareStatement(sql);
					psta.setString(1, tity.getJudgeStoveNo());
					psta.setString(2, tity.getPlineCode());
					rs = psta.executeQuery();
					while (rs.next()) {
						jugeNoList.add(rs.getString("OLD_ZP_JUDGE_STOVE_NO"));
						lotNoList.add(rs.getString("OLD_ZP_LOT_NO"));
						acountList.add(rs.getString("ZP_COUNT"));
						proPlanIdList.add(rs.getString("PRO_PLAN_ID"));
						gxPlanNoList.add(rs.getString("GX_PLAN_NO"));
					}
					rs.close();
					psta.close();
					for (int i = 0; i < jugeNoList.size(); i++) {
						insertTestRackPsta.setString(1, tity.getJudgeStoveNo());
						insertTestRackPsta.setString(2, tity.getJudgeStoveNo());
						insertTestRackPsta.setString(3, tity.getProPlanId()); // 轧管订单编号
						insertTestRackPsta.setString(4, tity.getGxPlanNo()); // 工序排产序号
						insertTestRackPsta.setString(5, tity.getPlineCode());
						insertTestRackPsta.setString(6, tity.getPlineCode());
						insertTestRackPsta.setString(7, tity.getProPlanId()); // 轧管订单编号
						insertTestRackPsta.setString(8, tity.getGxPlanNo()); // 工序排产序号
						insertTestRackPsta.setString(9, tity.getPlineCode());

						insertTestRackPsta.setString(10, jugeNoList.get(i));
						insertTestRackPsta.setString(11, proPlanIdList.get(i)); // 轧管订单编号
						insertTestRackPsta.setString(12, gxPlanNoList.get(i)); // 工序排产序号
						insertTestRackPsta.setString(13, lotNoList.get(i));

						insertTestRackPsta.setString(14, tity.getPlineCode());
						insertTestRackPsta.setString(15, "1");
						insertTestRackPsta.setInt(16, Integer
								.parseInt(acountList.get(i)));
						insertTestRackPsta.setString(17, tity.getLotNo());
						insertTestRackPsta.setString(18, tity.getPlineCode());
						insertTestRackPsta.setString(19, systime);
						insertTestRackPsta.setString(20, tity.getProPlanId()); // 轧管订单编号
						insertTestRackPsta.setString(21, tity.getGxPlanNo()); // 工序排产序号

						insertTestRackPsta.setString(22, tity.getLotNo());
						insertTestRackPsta.setString(23, tity.getPlineCode());
						insertTestRackPsta.setString(24, systime);
						insertTestRackPsta.setString(25, tity.getProPlanId()); // 轧管订单编号
						insertTestRackPsta.setString(26, tity.getGxPlanNo()); // 工序排产序号
						insertTestRackPsta.setString(27, tity.getLotNo());
						insertTestRackPsta.setString(28, "");
						insertTestRackPsta.setString(29, tity.getProPlanId()); // 轧管订单编号
						insertTestRackPsta.setString(30, tity.getGxPlanNo()); // 工序排产序号
						insertTestRackPsta.setString(31, jugeNoList.get(i));
						insertTestRackPsta.setString(32, lotNoList.get(i));
						insertTestRackPsta.setString(33, tity.getPlineCode());
						insertTestRackPsta.setString(34, jugeNoList.get(i));
						insertTestRackPsta.addBatch();

						deleteInstorePsta.setString(1, jugeNoList.get(i));
						deleteInstorePsta.setString(2, tity.getOfflineDoc());
						deleteInstorePsta.setInt(3, Integer.parseInt(acountList
								.get(i)));
						deleteInstorePsta.addBatch();
					}
				}

				if (tity.getLotNo().endsWith("试轧料")) {
					insertPsta.setString(1, "");
				} else {
					insertPsta.setString(1, tity.getContractNo().substring(0,
							tity.getContractNo().indexOf("/")));
				}

				insertPsta.setString(2, tity.getContractNo());
				insertPsta.setString(3, tity.getJudgeStoveNo());
				insertPsta.setString(4, tity.getJudgeStoveNo());
				insertPsta.setString(5, tity.getProPlanId()); // 轧管订单编号
				insertPsta.setString(6, tity.getGxPlanNo()); // 工序排产序号
				insertPsta.setString(7, tity.getPlineCode());
				insertPsta.setString(8, tity.getPlineCode());
				// insertPsta.setString(5, tity.getPlineCode());
				if (tity.getZpFlag().equals("正常下线")) {
					insertPsta.setString(9, tity.getJudgeStoveNo());
				} else {
					insertPsta.setString(9, tity.getZpMLh());
				}
				insertPsta.setString(10, tity.getProPlanId()); // 轧管订单编号
				insertPsta.setString(11, tity.getGxPlanNo()); // 工序排产序号
				insertPsta.setString(12, tity.getPlineCode());
				insertPsta.setString(13, tity.getGroupNumCount());
				insertPsta.setString(14, new DecimalFormat("0.000")
						.format(strWgt));// 重量
				insertPsta.setString(15, systime);
				insertPsta.setString(16, systime);
				insertPsta.setString(17, systime);
				insertPsta.setString(18, tity.getStdName());
				insertPsta.setString(19, tity.getLotNo());
				insertPsta.setString(20, tity.getContractNo());
				insertPsta.setString(21, tity.getImpProcess());
				insertPsta.setString(22, tity.getLength());
				insertPsta.setString(23, tity.getProducname());
				insertPsta.setString(24, tity.getSpecName());
				insertPsta.setString(25, tity.getModelDesc());
				insertPsta.setString(26, tity.getActLenRange());
				insertPsta.setString(27, tity.getStdName());
				insertPsta.setString(28, tity.getSteelcode());
				insertPsta.setString(29, tity.getSteelname());

				insertPsta.setString(30, tity.getProduccode());
				insertPsta.setString(31, tity.getSpecCode());
				insertPsta.setString(32, tity.getModelCode());
				insertPsta.setString(33, tity.getStdCode());
				insertPsta.setString(34, tity.getStdStyle());
				insertPsta.setString(35, tity.getStdStyleDesc());

				insertPsta.setString(36, tity.getLotNo());
				insertPsta.setString(37, tity.getJudgeStoveNo());
				insertPsta.setString(38, tity.getGroupNumCount());
				insertPsta.setString(39, new DecimalFormat("0.000")
						.format(strWgt));// 重量
				insertPsta.setString(40, systime);
				insertPsta.setString(41, "");
				insertPsta.setString(42, parm1.get(0));
				insertPsta.setString(43, parm1.get(1));
				insertPsta.setString(44, parm1.get(2));
				insertPsta.setString(45, tity.getOfflineType());

				insertPsta.setString(46, tity.getLotNo());
				// insertPsta.setString(24, tity.getPlineCode());
				insertPsta.setString(47, tity.getGroupNumCount());
				insertPsta.setString(48, tity.getGroupNumCount());
				insertPsta.setString(49, new DecimalFormat("0.000")
						.format(strWgt));// 重量(矫直实绩表)
				insertPsta.setString(50, parm1.get(3));
				insertPsta.setString(51, parm1.get(0));
				insertPsta.setString(52, parm1.get(1));
				insertPsta.setString(53, parm1.get(2));
				insertPsta.setString(54, systime);
				insertPsta.setString(55, systime);
				insertPsta.setString(56, systime);

				insertPsta.setString(57, tity.getGroupNumCount());
				insertPsta.setString(58, tity.getJudgeStoveNo());
				insertPsta.setString(59, tity.getLotNo());
				insertPsta.setString(60, tity.getPlineCode());
				insertPsta.setString(61, tity.getOfflineType());// 下线类型
				insertPsta.setString(62, tity.getJudgeStoveNo());
				insertPsta.setString(63, tity.getLotNo());
				insertPsta.setString(64, tity.getPlineCode());
				insertPsta.setString(65, tity.getOfflineType());
				insertPsta.setString(66, tity.getJudgeStoveNo());
				insertPsta.setString(67, tity.getLotNo());
				insertPsta.setString(68, tity.getPlineCode());
				insertPsta.setString(69, tity.getOfflineType());
				insertPsta.addBatch();

				// 统一组炉炉号进程表ID
				if (!tity.getZpFlag().equals("正常下线")) {
					updateIDPsta.setString(1, tity.getJudgeStoveNo());
					updateIDPsta.addBatch();
				}
			}
			insertTestRackPsta.executeBatch();
			deleteInstorePsta.executeBatch();
			insertPsta.executeBatch();
			updateIDPsta.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 parm
	 * @param parm1
	 * @return
	 */
	public CoreReturnObject doBackStaightLine(ArrayList<String> parm,
			ArrayList<String> parm1) {
		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);
		int acount = 0;
		String str1[] = null;
		double strWgt = 0.0;
		int matCount = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.doBackStaightLine");// 返线
			PreparedStatement insertPsta = connection
					.prepareStatement(insertSql);
			String insertTestRackSql = CoreXmlSqlParsersFactory
					.getSql("doBackStaightLine.insertRack");// 生成管号队列
			PreparedStatement insertTestRackPsta = connection
					.prepareStatement(insertTestRackSql);
			String deleteInstoreSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.deleteMatStore");// 消除库存
			PreparedStatement deleteInstorePsta = connection
					.prepareStatement(deleteInstoreSql);
			String updateID = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.updateID"); // 统一组炉炉号进程表ID
			PreparedStatement updateIDPsta = connection
					.prepareStatement(updateID);
			for (String str : parm) {
				MilOfflineReslutEntity2 tity = EntityTool.getEntityByJSONStr(
						str, MilOfflineReslutEntity2.class);
				if (tity.getSpecName().indexOf("*") > 0) {
					str1 = tity.getSpecName().split("[*]");
				} else {
					str1 = tity.getSpecName().split("[x]");
				}
				strWgt = 0.02466
						* Double.parseDouble(str1[1])
						* (Double.parseDouble(str1[0]) - Double
								.parseDouble(str1[1]))
						* Double.parseDouble(tity.getLength())
						* Integer.parseInt(tity.getGroupNumCount()) / 1000;
				sql = CoreXmlSqlParsersFactory
						.getSql("doFurnace.doQueryMilPlan");
				psta = connection.prepareStatement(sql);
				psta.setString(1, tity.getJudgeStoveNo());
				psta.setString(2, tity.getLotNo());
				psta.setInt(3, 80);
				/*
				 * psta.setString(4, tity.getProPlanId()); psta.setString(5,
				 * tity.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;
				}

				// 查询是否已脱单
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.doQueryTake");
				psta = connection.prepareStatement(sql);
				psta.setString(1, tity.getJudgeStoveNo());
				psta.setString(2, tity.getLotNo());
				psta.setString(3, tity.getOfflinePro());
				psta.setString(4, tity.getProPlanId());
				psta.setString(5, tity.getGxPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.doQueryTake2");
				psta = connection.prepareStatement(sql);
				psta = connection.prepareStatement(sql);
				psta.setString(1, tity.getJudgeStoveNo());
				psta.setString(2, tity.getLotNo());
				psta.setString(3, tity.getPlineCode());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount += Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (acount != 0) {
					cro.setV_errMsg("此炉已脱单,请组炉后再矫直返线!");
					return cro;
				}
				insertTestRackPsta.setString(1, tity.getJudgeStoveNo());
				insertTestRackPsta.setString(2, tity.getJudgeStoveNo());
				insertTestRackPsta.setString(3, tity.getProPlanId()); // 轧管订单编号
				insertTestRackPsta.setString(4, tity.getGxPlanNo()); // 工序排产序号
				insertTestRackPsta.setString(5, tity.getPlineCode());
				insertTestRackPsta.setString(6, tity.getPlineCode());
				insertTestRackPsta.setString(7, tity.getProPlanId()); // 轧管订单编号
				insertTestRackPsta.setString(8, tity.getGxPlanNo()); // 工序排产序号
				insertTestRackPsta.setString(9, tity.getPlineCode());
				insertTestRackPsta.setString(10, tity.getJudgeStoveNo());
				insertTestRackPsta.setString(11, tity.getProPlanId()); // 轧管订单编号
				insertTestRackPsta.setString(12, tity.getGxPlanNo()); // 工序排产序号
				insertTestRackPsta.setString(13, tity.getLotNo());
				insertTestRackPsta.setString(14, tity.getPlineCode());
				insertTestRackPsta.setInt(15, Integer.parseInt(tity
						.getGroupNumCount()));
				insertTestRackPsta.setString(16, tity.getLotNo());
				insertTestRackPsta.setString(17, tity.getPlineCode());
				insertTestRackPsta.setString(18, systime);
				insertTestRackPsta.setString(19, tity.getLotNo());
				insertTestRackPsta.setString(20, tity.getPlineCode());
				insertTestRackPsta.setString(21, systime);
				insertTestRackPsta.setString(22, tity.getLotNo());
				insertTestRackPsta.setString(23, tity.getPlineCode());
				insertTestRackPsta.setString(24, systime);

				insertTestRackPsta.setString(25, tity.getLotNo());
				insertTestRackPsta.setString(26, "");// 熔炼炉号
				insertTestRackPsta.setString(27, tity.getJudgeStoveNo());
				insertTestRackPsta.setString(28, tity.getLotNo());
				insertTestRackPsta.setString(29, tity.getPlineCode());
				insertTestRackPsta.setString(30, tity.getJudgeStoveNo());
				insertTestRackPsta.addBatch();

				deleteInstorePsta.setString(1, tity.getJudgeStoveNo());
				deleteInstorePsta.setString(2, tity.getOfflineDoc());
				deleteInstorePsta.setInt(3, Integer.parseInt(tity
						.getGroupNumCount()));
				deleteInstorePsta.addBatch();

				if (tity.getLotNo().endsWith("试轧料")) {
					insertPsta.setString(1, "");
					insertPsta.setString(2, "");
				} else {
					insertPsta.setString(1, tity.getContractNo().substring(0,
							tity.getContractNo().indexOf("/")));
					insertPsta.setString(2, tity.getContractNo().substring(0,
							tity.getContractNo().indexOf("/")));
				}

				insertPsta.setString(3, tity.getJudgeStoveNo());
				insertPsta.setString(4, tity.getJudgeStoveNo());
				insertPsta.setString(5, tity.getProPlanId()); // 轧管订单编号
				insertPsta.setString(6, tity.getGxPlanNo()); // 工序排产序号
				insertPsta.setString(7, tity.getPlineCode());
				insertPsta.setString(8, tity.getPlineCode());
				insertPsta.setString(9, tity.getJudgeStoveNo());
				insertPsta.setString(10, tity.getProPlanId()); // 轧管订单编号
				insertPsta.setString(11, tity.getGxPlanNo()); // 工序排产序号
				insertPsta.setString(12, tity.getPlineCode());
				insertPsta.setString(13, tity.getGroupNumCount());
				insertPsta.setString(14, new DecimalFormat("0.000")
						.format(strWgt));// 重量
				insertPsta.setString(15, systime);
				insertPsta.setString(16, systime);
				insertPsta.setString(17, systime);
				insertPsta.setString(18, tity.getStdName());
				insertPsta.setString(19, tity.getLotNo());

				insertPsta.setString(20, tity.getContractNo());
				insertPsta.setString(21, tity.getImpProcess());
				insertPsta.setString(22, tity.getLength());
				insertPsta.setString(23, tity.getProducname());
				insertPsta.setString(24, tity.getSpecName());
				insertPsta.setString(25, tity.getModelDesc());
				insertPsta.setString(26, tity.getActLenRange());
				insertPsta.setString(27, tity.getStdName());
				insertPsta.setString(28, tity.getSteelcode());
				insertPsta.setString(29, tity.getSteelname());

				insertPsta.setString(30, tity.getProduccode());
				insertPsta.setString(31, tity.getSpecCode());
				insertPsta.setString(32, tity.getModelCode());
				insertPsta.setString(33, tity.getStdCode());
				insertPsta.setString(34, tity.getStdStyle());
				insertPsta.setString(35, tity.getStdStyleDesc());

				insertPsta.setString(36, tity.getLotNo());
				insertPsta.setString(37, tity.getJudgeStoveNo());
				insertPsta.setString(38, tity.getGroupNumCount());
				insertPsta.setString(39, new DecimalFormat("0.000")
						.format(strWgt));// 重量
				insertPsta.setString(40, systime);
				insertPsta.setString(41, "");
				insertPsta.setString(42, parm1.get(0));
				insertPsta.setString(43, parm1.get(1));
				insertPsta.setString(44, parm1.get(2));
				insertPsta.setString(45, tity.getOfflineType());

				insertPsta.setString(46, tity.getGroupNumCount());
				insertPsta.setString(47, tity.getJudgeStoveNo());
				insertPsta.setString(48, tity.getProPlanId()); // 轧管订单编号
				insertPsta.setString(49, tity.getGxPlanNo()); // 工序排产序号
				insertPsta.setString(50, tity.getLotNo());
				insertPsta.setString(51, tity.getPlineCode());
				insertPsta.setString(52, tity.getJudgeStoveNo());
				insertPsta.setString(53, tity.getProPlanId()); // 轧管订单编号
				insertPsta.setString(54, tity.getGxPlanNo()); // 工序排产序号
				insertPsta.setString(55, tity.getLotNo());
				insertPsta.setString(56, tity.getPlineCode());
				insertPsta.setString(57, tity.getJudgeStoveNo());
				insertPsta.setString(58, tity.getProPlanId()); // 轧管订单编号
				insertPsta.setString(59, tity.getGxPlanNo()); // 工序排产序号
				insertPsta.setString(60, tity.getLotNo());
				insertPsta.setString(61, tity.getPlineCode());

				insertPsta.addBatch();

				// 统一组炉炉号进程表ID
				if (!tity.getZpFlag().equals("正常下线")) {
					updateIDPsta.setString(1, tity.getJudgeStoveNo());
					updateIDPsta.addBatch();
				}
			}
			insertTestRackPsta.executeBatch();
			deleteInstorePsta.executeBatch();
			insertPsta.executeBatch();
			updateIDPsta.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 parm
	 * @return
	 * @throws SQLException
	 */
	public CoreReturnObject cancelQualityInspectionTrust(
			ArrayList<String> parm, ArrayList<String> list, String strInBound,
			String strInMemo, String plineCode) throws SQLException {
		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);
		int acount = 0;
		String jugeNo = "";// 查询主计划炉号
		String bacthNo = "X";
		String[] str1 = null;
		String lengthCp[] = null;
		int n = 0;

		String materiaNo = "";// 物料码
		String materiaName = "";// 物料描述
		String INWL_ID = "";// 投入物料编码
		String INWL_DESC = "";// 投入物料描述
		String CRAFT_SEQ = ""; // 工艺序号
		String judgeStdDes = ""; // 判定标准集合
		String cic = ""; // cic
		String PRO_PLAN_ID = ""; // 轧管订单编号
		String GX_PLAN_NO = ""; // 工序排产序号

		String inListDoc = "";
		String inListSeq = "";
		String deleteSql = "update mil_qa_rack set SIMPLE_GROUP_NO = '' where rownum = 0";
		PreparedStatement deletePsta = connection.prepareStatement(deleteSql);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务

			String deleteBackLineSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.cancelBackLine");// 撤销探伤返线
			PreparedStatement deleteBackLinePsta = connection
					.prepareStatement(deleteBackLineSql);
			String deleteInstoreSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.canceInstroe");// 撤销入库转移
			PreparedStatement deleteInstorePsta = connection
					.prepareStatement(deleteInstoreSql);
			String insertMatSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.insertButressData");// 撤销时还原虚拟库存
			PreparedStatement insertMatPsta = connection
					.prepareStatement(insertMatSql);
			String deleteBackStaLineSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.cancelBackLineSta");
			PreparedStatement deleteBackStaLinePsta = connection
					.prepareStatement(deleteBackStaLineSql);// 撤销矫直返线
			String deleteBackPipeSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.cancelBackPipe");// 交库返线
			PreparedStatement deleteBackPipePsta = connection
					.prepareStatement(deleteBackPipeSql);
			for (String str : parm) {
				MilOfflineResultDetiaEntity milOfflineResultDetiaTity = EntityTool
						.getEntityByJSONStr(str,
								MilOfflineResultDetiaEntity.class);
				//判断是否交库
				sql = CoreXmlSqlParsersFactory
						.getSql("cancelQualityInspectionTrust.doQueryInstore");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milOfflineResultDetiaTity
						.getBackJudgeStoveNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (acount > 0) {
					cro.setV_errMsg("此炉在库存有数据未处理,不允许撤销!");
					return cro;
				}

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmOffLine.selectMaterialNo2");// 查询物料码
				psta = connection.prepareStatement(sql);
				psta.setString(1, milOfflineResultDetiaTity.getId());
				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");
					PRO_PLAN_ID = rs.getString("PRO_PLAN_ID");
					GX_PLAN_NO = rs.getString("GX_PLAN_NO");
				}
				rs.close();
				psta.close();

				if (milOfflineResultDetiaTity.getOperationType().equals("复检")) {
					if (milOfflineResultDetiaTity.getOfflineType().equals("0")) {
						deleteSql = CoreXmlSqlParsersFactory
								.getSql("FrmDownlineManage.cancelQualityInspectionTrust");// 撤销复检
						deletePsta = connection.prepareStatement(deleteSql);
						sql = CoreXmlSqlParsersFactory
								.getSql("cancelQualityInspectionTrust.doQueryResult");
						psta = connection.prepareStatement(sql);
						psta.setString(1, milOfflineResultDetiaTity.getId());
						psta.setString(2, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						rs = psta.executeQuery();
						if (rs.next()) {
							acount = Integer.parseInt(rs.getString("ACOUNT"));
						}
						rs.close();
						psta.close();
						if (acount > 0) {
							cro.setV_errMsg("此委托已生成生产实绩,不允许撤销!");
							return cro;
						}

						// 查询是否有交库点离线数据未撤销
						sql = CoreXmlSqlParsersFactory
								.getSql("cancelQualityInspectionTrust.doQueryOffline");
						psta = connection.prepareStatement(sql);
						psta.setString(1, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						rs = psta.executeQuery();
						if (rs.next()) {
							acount = Integer.parseInt(rs.getString("ACOUNT"));
						}
						rs.close();
						psta.close();
						if (acount > 0) {
							cro.setV_errMsg("此炉在下线点有离线,不允许撤销!");
							return cro;
						}

						deletePsta.setString(1, milOfflineResultDetiaTity
								.getId());
						deletePsta.setString(2, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						deletePsta.setString(3, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setString(4, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setString(5, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setInt(6, Integer
								.parseInt(milOfflineResultDetiaTity
										.getActCount()));
						deletePsta.setString(7, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setString(8, milOfflineResultDetiaTity
								.getOperationId());
						deletePsta.setString(9, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						deletePsta.setString(10, milOfflineResultDetiaTity
								.getId());
						deletePsta.setString(11, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						// deletePsta.setString(5,
						// milOfflineResultDetiaTity.getJudgeStoveNo());
						// deletePsta.setString(6,
						// milOfflineResultDetiaTity.getLotNo());
						deletePsta.setString(12, milOfflineResultDetiaTity
								.getActCount());
						deletePsta.setString(13, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setString(14, milOfflineResultDetiaTity
								.getLotNo());
						deletePsta.setString(15, milOfflineResultDetiaTity
								.getPlineCode());
						deletePsta.setString(16, "ZJ");
						deletePsta.setString(17, milOfflineResultDetiaTity
								.getId());
						deletePsta.setString(18, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						deletePsta.addBatch();

						// insertMatPsta.setString(1,
						// milOfflineResultDetiaTity.getJudgeStoveNo());
						// insertMatPsta.setInt(2,
						// Integer.parseInt(milOfflineResultDetiaTity.getActCount()));
						// insertMatPsta.setString(3, list.get(0));
						// insertMatPsta.setString(4, list.get(1));
						// insertMatPsta.setString(5, list.get(2));
						// insertMatPsta.setString(6, list.get(3));
						// insertMatPsta.setString(7, list.get(8));
						// insertMatPsta.setString(8, list.get(4));
						// insertMatPsta.setString(9, list.get(5));
						// insertMatPsta.setString(10, list.get(6));
						// insertMatPsta.setString(11, list.get(7));
						// insertMatPsta.addBatch();

					} else {
						deleteSql = CoreXmlSqlParsersFactory
								.getSql("FrmDownlineManage.cancelQualityInspectionTrustTS");// 撤销探伤复检
						deletePsta = connection.prepareStatement(deleteSql);
						sql = CoreXmlSqlParsersFactory
								.getSql("cancelQualityInspectionTrust.doQueryResult");
						psta = connection.prepareStatement(sql);
						psta.setString(1, milOfflineResultDetiaTity.getId());
						psta.setString(2, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						rs = psta.executeQuery();
						if (rs.next()) {
							acount = Integer.parseInt(rs.getString("ACOUNT"));
						}
						rs.close();
						psta.close();
						if (acount > 0) {
							cro.setV_errMsg("此委托已生成生产实绩,不允许撤销!");
							return cro;
						}

						// 查询是否有交库点离线数据未撤销
						sql = CoreXmlSqlParsersFactory
								.getSql("cancelQualityInspectionTrust.doQueryOffline");
						psta = connection.prepareStatement(sql);
						psta.setString(1, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						rs = psta.executeQuery();
						if (rs.next()) {
							acount = Integer.parseInt(rs.getString("ACOUNT"));
						}
						rs.close();
						psta.close();
						if (acount > 0) {
							cro.setV_errMsg("此炉在下线点有离线,不允许撤销!");
							return cro;
						}

						deletePsta.setString(1, milOfflineResultDetiaTity
								.getId());
						deletePsta.setString(2, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						deletePsta.setString(3, milOfflineResultDetiaTity
								.getOperationId());
						deletePsta.setString(4, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						deletePsta.setString(5, milOfflineResultDetiaTity
								.getId());
						deletePsta.setString(6, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						deletePsta.setString(7, milOfflineResultDetiaTity
								.getActCount());
						deletePsta.setString(8, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setString(9, milOfflineResultDetiaTity
								.getLotNo());
						deletePsta.setString(10, milOfflineResultDetiaTity
								.getPlineCode());
						deletePsta.setString(11, "TS");
						deletePsta.setString(12, milOfflineResultDetiaTity
								.getOfflineType());

						deletePsta.setString(13, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setString(14, "TS");
						deletePsta.setString(15, milOfflineResultDetiaTity
								.getOfflineType());
						deletePsta.setString(16, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setString(17, milOfflineResultDetiaTity
								.getOfflineType());
						deletePsta.setString(18, milOfflineResultDetiaTity
								.getOfflineType());
						deletePsta.setString(19, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setString(20, milOfflineResultDetiaTity
								.getPlineCode());
						deletePsta.setString(21, milOfflineResultDetiaTity
								.getOfflineType());
						deletePsta.setInt(22, Integer
								.parseInt(milOfflineResultDetiaTity
										.getActCount()));
						deletePsta.setString(23, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setString(24, milOfflineResultDetiaTity
								.getPlineCode());
						deletePsta.setString(25, milOfflineResultDetiaTity
								.getOfflineType());
						deletePsta.setString(26, milOfflineResultDetiaTity
								.getJudgeStoveNo());
						deletePsta.setString(27, milOfflineResultDetiaTity
								.getId());
						deletePsta.setString(28, milOfflineResultDetiaTity
								.getBackJudgeStoveNo());
						deletePsta.addBatch();

						// insertMatPsta.setString(1,
						// milOfflineResultDetiaTity.getJudgeStoveNo());
						// insertMatPsta.setInt(2,
						// Integer.parseInt(milOfflineResultDetiaTity.getActCount()));
						// insertMatPsta.setString(3, list.get(0));
						// insertMatPsta.setString(4, list.get(1));
						// insertMatPsta.setString(5, list.get(2));
						// insertMatPsta.setString(6, list.get(3));
						// insertMatPsta.setString(7, list.get(8));
						// insertMatPsta.setString(8, list.get(4));
						// insertMatPsta.setString(9, list.get(5));
						// insertMatPsta.setString(10, list.get(6));
						// insertMatPsta.setString(11, list.get(7));
						// insertMatPsta.addBatch();
					}

				} else if (milOfflineResultDetiaTity.getOperationType().equals(
						"探伤返线")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("cancelQualityInspectionTrust.doQueryBackLineResult");
					psta = connection.prepareStatement(sql);
					psta.setString(1, milOfflineResultDetiaTity.getId());
					psta.setString(2, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					psta.setString(3, milOfflineResultDetiaTity.getId());
					psta.setString(4, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					psta.setString(5, milOfflineResultDetiaTity.getId());
					psta.setString(6, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if (acount > 0) {
						cro.setV_errMsg("返线炉已生成生产实绩,不允许撤销!");
						return cro;
					}

					// 查询是否有交库点离线数据未撤销
					sql = CoreXmlSqlParsersFactory
							.getSql("cancelQualityInspectionTrust.doQueryOffline");
					psta = connection.prepareStatement(sql);
					psta.setString(1, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if (acount > 0) {
						cro.setV_errMsg("此炉在下线点有离线,不允许撤销!");
						return cro;
					}
					// deleteBackLinePsta.setString(1,
					// milOfflineResultDetiaTity.getId());
					// deleteBackLinePsta.setString(2, milOfflineResultDetiaTity
					// .getOperationId());
					// deleteBackLinePsta.setString(3,
					// milOfflineResultDetiaTity.getId());
					// deleteBackLinePsta.setString(4,
					// milOfflineResultDetiaTity.getId());
					// deleteBackLinePsta.setString(5,
					// milOfflineResultDetiaTity.getId());
					// deleteBackLinePsta.setString(6,
					// milOfflineResultDetiaTity.getActCount());
					// deleteBackLinePsta.setString(7,
					// milOfflineResultDetiaTity.getJudgeStoveNo());
					// deleteBackLinePsta.setString(8,
					// milOfflineResultDetiaTity.getOfflineType());
					// deleteBackLinePsta.setString(9,
					// milOfflineResultDetiaTity.getJudgeStoveNo());
					//					
					// deleteBackLinePsta.setString(10,
					// milOfflineResultDetiaTity.getPlineCode());
					// deleteBackLinePsta.setString(11,
					// milOfflineResultDetiaTity.getOfflineType());
					// deleteBackLinePsta.setInt(12,
					// Integer.parseInt(milOfflineResultDetiaTity.getActCount()));
					// deleteBackLinePsta.setString(13,
					// milOfflineResultDetiaTity.getJudgeStoveNo());
					// deleteBackLinePsta.setString(14,
					// milOfflineResultDetiaTity.getPlineCode());
					// deleteBackLinePsta.setString(15,
					// milOfflineResultDetiaTity.getJudgeStoveNo());
					// deleteBackLinePsta.setString(16,
					// milOfflineResultDetiaTity.getId());
					// deleteBackLinePsta.addBatch();

					deleteBackLinePsta.setString(1, milOfflineResultDetiaTity
							.getId());
					deleteBackLinePsta.setString(2, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					deleteBackLinePsta.setString(3, milOfflineResultDetiaTity
							.getOperationId());
					deleteBackLinePsta.setString(4, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					deleteBackLinePsta.setString(5, milOfflineResultDetiaTity
							.getId());
					deleteBackLinePsta.setString(6, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					deleteBackLinePsta.setString(7, milOfflineResultDetiaTity
							.getId());
					deleteBackLinePsta.setString(8, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					deleteBackLinePsta.setString(9, milOfflineResultDetiaTity
							.getId());
					deleteBackLinePsta.setString(10, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					deleteBackLinePsta.setString(11, milOfflineResultDetiaTity
							.getActCount());
					deleteBackLinePsta.setString(12, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					deleteBackLinePsta.setString(13, milOfflineResultDetiaTity
							.getOfflineType());
					deleteBackLinePsta.setString(14, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					deleteBackLinePsta.setString(15, milOfflineResultDetiaTity
							.getOfflineType());

					deleteBackLinePsta.setString(16, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					deleteBackLinePsta.setString(17, milOfflineResultDetiaTity
							.getOfflineType());

					deleteBackLinePsta.setString(18, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					deleteBackLinePsta.setString(19, milOfflineResultDetiaTity
							.getPlineCode());
					deleteBackLinePsta.setString(20, milOfflineResultDetiaTity
							.getOfflineType());
					deleteBackLinePsta.setInt(21, Integer
							.parseInt(milOfflineResultDetiaTity.getActCount()));
					deleteBackLinePsta.setString(22, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					deleteBackLinePsta.setString(23, milOfflineResultDetiaTity
							.getPlineCode());
					deleteBackLinePsta.setString(24, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					deleteBackLinePsta.setString(25, milOfflineResultDetiaTity
							.getId());
					deleteBackLinePsta.setString(26, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					deleteBackLinePsta.addBatch();

					// insertMatPsta.setString(1,
					// milOfflineResultDetiaTity.getJudgeStoveNo());
					// insertMatPsta.setInt(2,
					// Integer.parseInt(milOfflineResultDetiaTity.getActCount()));
					// insertMatPsta.setString(3, list.get(0));
					// insertMatPsta.setString(4, list.get(1));
					// insertMatPsta.setString(5, list.get(2));
					// insertMatPsta.setString(6, list.get(3));
					// insertMatPsta.setString(7, list.get(8));
					// insertMatPsta.setString(8, list.get(4));
					// insertMatPsta.setString(9, list.get(5));
					// insertMatPsta.setString(10, list.get(6));
					// insertMatPsta.setString(11, list.get(7));
					// insertMatPsta.addBatch();
				} else if (milOfflineResultDetiaTity.getOperationType().equals(
						"矫直返线")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("cancelQualityInspectionTrust.doQueryBackStaLineResult");
					psta = connection.prepareStatement(sql);
					psta.setString(1, milOfflineResultDetiaTity.getId());
					psta.setString(2, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if (acount > 0) {
						cro.setV_errMsg("返线炉已生成生产实绩,不允许撤销!");
						return cro;
					}

					// 查询是否有交库点离线数据未撤销
					sql = CoreXmlSqlParsersFactory
							.getSql("cancelQualityInspectionTrust.doQueryOffline");
					psta = connection.prepareStatement(sql);
					psta.setString(1, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if (acount > 0) {
						cro.setV_errMsg("此炉在下线点有离线,不允许撤销!");
						return cro;
					}
					deleteBackStaLinePsta.setString(1,
							milOfflineResultDetiaTity.getId());
					deleteBackStaLinePsta.setString(2,
							milOfflineResultDetiaTity.getBackJudgeStoveNo());
					deleteBackStaLinePsta.setString(3,
							milOfflineResultDetiaTity.getOperationId());
					deleteBackStaLinePsta.setString(4,
							milOfflineResultDetiaTity.getBackJudgeStoveNo());
					deleteBackStaLinePsta.setString(5,
							milOfflineResultDetiaTity.getId());
					deleteBackStaLinePsta.setString(6,
							milOfflineResultDetiaTity.getBackJudgeStoveNo());
					deleteBackStaLinePsta.setString(7,
							milOfflineResultDetiaTity.getId());
					deleteBackStaLinePsta.setString(8,
							milOfflineResultDetiaTity.getBackJudgeStoveNo());
					deleteBackStaLinePsta.setString(9,
							milOfflineResultDetiaTity.getId());
					deleteBackStaLinePsta.setString(10,
							milOfflineResultDetiaTity.getBackJudgeStoveNo());
					deleteBackStaLinePsta.setString(11,
							milOfflineResultDetiaTity.getActCount());
					deleteBackStaLinePsta.setString(12,
							milOfflineResultDetiaTity.getJudgeStoveNo());
					deleteBackStaLinePsta.setString(13,
							milOfflineResultDetiaTity.getJudgeStoveNo());
					deleteBackStaLinePsta.setString(14,
							milOfflineResultDetiaTity.getPlineCode());
					deleteBackStaLinePsta.setInt(15, Integer
							.parseInt(milOfflineResultDetiaTity.getActCount()));
					deleteBackStaLinePsta.setString(16,
							milOfflineResultDetiaTity.getJudgeStoveNo());
					deleteBackStaLinePsta.setString(17,
							milOfflineResultDetiaTity.getPlineCode());
					deleteBackStaLinePsta.setString(18,
							milOfflineResultDetiaTity.getJudgeStoveNo());
					deleteBackStaLinePsta.setString(19,
							milOfflineResultDetiaTity.getId());
					deleteBackStaLinePsta.setString(20,
							milOfflineResultDetiaTity.getBackJudgeStoveNo());
					deleteBackStaLinePsta.addBatch();
				} else if (milOfflineResultDetiaTity.getOperationType().equals(
						"交库返线")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("cancelQualityInspectionTrust.doQueryMat");
					psta = connection.prepareStatement(sql);
					psta.setString(1, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if (acount > 0) {
						cro.setV_errMsg("返线炉已有交库,不允许撤销!");
						return cro;
					}

					sql = CoreXmlSqlParsersFactory
							.getSql("cancelQualityInspectionTrust.doQueryEntrustAcount");
					psta = connection.prepareStatement(sql);
					psta.setString(1, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						n = Integer.parseInt(rs
								.getString("SUBCONTRACTSCRAP_NUM"));
					}
					rs.close();
					psta.close();

					deleteBackPipePsta.setString(1, milOfflineResultDetiaTity
							.getId());
					deleteBackPipePsta.setString(2, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					deleteBackPipePsta.setString(3, milOfflineResultDetiaTity
							.getOperationId());
					deleteBackPipePsta.setString(4, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					deleteBackPipePsta.setString(5, milOfflineResultDetiaTity
							.getActCount());
					deleteBackPipePsta.setString(6, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					deleteBackPipePsta.setString(7, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					deleteBackPipePsta.setString(8, milOfflineResultDetiaTity
							.getPlineCode());
					deleteBackPipePsta.setInt(9, Integer
							.parseInt(milOfflineResultDetiaTity.getActCount())
							+ n);
					deleteBackPipePsta.setString(10, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					deleteBackPipePsta.setString(11, milOfflineResultDetiaTity
							.getId());
					deleteBackPipePsta.setString(12, milOfflineResultDetiaTity
							.getBackJudgeStoveNo());
					deleteBackPipePsta.addBatch();
				}
				ArrayList<String> jugeNoList = new ArrayList<String>();
				ArrayList<String> lotNoList = new ArrayList<String>();
				ArrayList<String> acountList = new ArrayList<String>();
				ArrayList<String> wgtList = new ArrayList<String>();
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.selectMilOfflineGroup");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milOfflineResultDetiaTity.getJudgeStoveNo());
				rs = psta.executeQuery();
				while (rs.next()) {
					jugeNoList.add(rs.getString("OLD_ZP_JUDGE_STOVE_NO"));
					lotNoList.add(rs.getString("OLD_ZP_LOT_NO"));
					acountList.add(rs.getString("ZP_COUNT"));
					wgtList.add(rs.getString("ZP_HEIGHT"));
				}
				rs.close();
				psta.close();

				inListDoc = querySendSqlDoc(connection, strInBound, strInMemo,
						plineCode, systime);// 入库单号
				inListSeq = querySendSql(connection, inListDoc, plineCode); // 入库流水号
				n = Integer.parseInt(inListSeq.substring(
						inListSeq.length() - 4, inListSeq.length()));
				if (jugeNoList.size() == 0) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmDownlineManage.selectMilPlanData");// 查询炉计划信息
					psta = connection.prepareStatement(sql);
					psta.setString(1, milOfflineResultDetiaTity
							.getJudgeStoveNo());
					rs = psta.executeQuery();
					List<MilPlanEntity3> milPlanList = EntityTool
							.getEntitysByRs(rs, MilPlanEntity3.class);
					rs.close();
					psta.close();
					if (milPlanList == null) {
						cro.setV_errMsg("无该炉计划信息!");
						return cro;
					}
					if (milPlanList.get(0).getPlineCode().equals("C017")) {
						milPlanList.get(0).setPlineName("460机组");
					} else if (milPlanList.get(0).getPlineCode().equals("C008")) {
						milPlanList.get(0).setPlineName("250机组");
					} else if (milPlanList.get(0).getPlineCode().equals("C009")) {
						milPlanList.get(0).setPlineName("258机组");
					} else if (milPlanList.get(0).getPlineCode().equals("C010")) {
						milPlanList.get(0).setPlineName("168机组");
					} else if (milPlanList.get(0).getPlineCode().equals("C072")) {
						milPlanList.get(0).setPlineName("天淮508机组");
					}

					String matNo = queryMatNoM(connection,
							milOfflineResultDetiaTity.getJudgeStoveNo()
									.replaceFirst("-.*", ""), bacthNo); // 材料号
					int g = Integer.parseInt(matNo.substring(
							matNo.length() - 4, matNo.length()));
					MilPlanEntity3 milPlanTity = milPlanList.get(0);
					str1 = milPlanTity.getPipeSize().split("[*]");
					lengthCp = milPlanTity.getLengthRange().split("[-]");
					List<double[]> list1 = MeanValueCalculation
							.MeanCalculation(Double
									.parseDouble(milOfflineResultDetiaTity
											.getActWeight()), Integer
									.parseInt(milOfflineResultDetiaTity
											.getActCount()));
					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, milPlanTity
										.getJudgeStoveNo().replaceFirst("-.*",
												""));
								insertMatPsta.setString(2, bacthNo);
								insertMatPsta.setString(3, "001");
								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(8));
								insertMatPsta.setString(9, (milPlanTity
										.getJudgeStoveNo().replaceFirst("-.*",
												"") + bacthNo)
										+ StringTool.formatDecimal(g, "0000"));
								insertMatPsta.setString(10, list.get(4));
								insertMatPsta.setString(11, list.get(5));
								insertMatPsta.setString(12, list.get(6));
								insertMatPsta.setString(13, list.get(7));

								insertMatPsta.setString(14, milPlanTity
										.getJudgeStoveNo().replaceFirst("-.*",
												""));
								insertMatPsta.setString(15, bacthNo);
								insertMatPsta.setString(16, "001");
								insertMatPsta.setString(17, "1");
								insertMatPsta.setString(18, String
										.valueOf(conW[1]));
								insertMatPsta.setString(19, systime);
								insertMatPsta.setString(20, (milPlanTity
										.getJudgeStoveNo().replaceFirst("-.*",
												"") + 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(6));
								insertMatPsta.setString(41, list.get(7));
								insertMatPsta.setString(42, milPlanTity
										.getStdStyle());
								insertMatPsta.setString(43, milPlanTity
										.getStdStyleDesc());
								insertMatPsta.setString(44, str1[0].toString());
								insertMatPsta.setString(45, str1[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, milPlanTity
										.getJudgeStoveNo().replaceFirst("-.*",
												""));
								insertMatPsta.setString(54, yearMoth);

								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, PRO_PLAN_ID);
								insertMatPsta.setString(63, GX_PLAN_NO);
								insertMatPsta.setString(64, systime);

								insertMatPsta.setString(65, milPlanTity
										.getJudgeStoveNo());
								insertMatPsta.setString(66, milPlanTity
										.getJudgeStoveNo().replaceFirst("-.*",
												""));

								/*
								 * insertMatPsta.setString(55, list.get(5));
								 * insertMatPsta.setString(56, list.get(6));
								 * insertMatPsta.setString(57, inListDoc +
								 * StringTool.formatDecimal(n, "0000"));
								 * insertMatPsta.setString(58, inListDoc);
								 * insertMatPsta.setString(59, "800701");
								 * insertMatPsta.setString(60, "产出入库");
								 * insertMatPsta.setString(61,
								 * (milPlanTity.getJudgeStoveNo().substring(0,
								 * 6) + bacthNo) + StringTool.formatDecimal(g,
								 * "0000")); insertMatPsta.setString(62, "");
								 * insertMatPsta.setString(63, "");
								 * insertMatPsta.setString(64,
								 * milPlanTity.getJudgeStoveNo().substring(0,
								 * 6)); insertMatPsta.setString(65, bacthNo);
								 * insertMatPsta.setString(66, "001");
								 * 
								 * insertMatPsta.setString(67, "");
								 * insertMatPsta.setString(68,
								 * milPlanTity.getVarieties());
								 * insertMatPsta.setString(69, "");// 标准
								 * insertMatPsta.setString(70,
								 * milPlanTity.getRollStandrad());
								 * insertMatPsta.setString(71, "");
								 * insertMatPsta.setString(72,
								 * milPlanTity.getSteelname());
								 * insertMatPsta.setString(73, "");
								 * insertMatPsta.setString(74,
								 * milPlanTity.getStdStyleDesc());
								 * insertMatPsta.setString(75, "");
								 * insertMatPsta.setString(76,
								 * milPlanTity.getPipeSize() .replace("*",
								 * "x")); insertMatPsta.setString(77, "");
								 * insertMatPsta.setString(78,
								 * milPlanTity.getBuckleType());
								 * 
								 * insertMatPsta.setString(79,
								 * milPlanTity.getDimater());
								 * insertMatPsta.setString(80,
								 * milPlanTity.getHeight());
								 * insertMatPsta.setString(81,
								 * milPlanTity.getLengthmin());
								 * insertMatPsta.setString(82,
								 * milPlanTity.getLengthmax());
								 * insertMatPsta.setString(83, "1");
								 * insertMatPsta.setString(84,
								 * String.valueOf(conW[1]));
								 * insertMatPsta.setString(85,
								 * String.valueOf(conW[1]));
								 * insertMatPsta.setString(86, list.get(6));
								 * insertMatPsta.setString(87, list.get(5));
								 * insertMatPsta.setString(88, list.get(0));
								 * insertMatPsta.setString(89, "");
								 * insertMatPsta.setString(90, "1");
								 * insertMatPsta.setString(91, list.get(4));
								 * insertMatPsta.setString(92, systime);
								 * insertMatPsta.setString(93, "");//合同号
								 * insertMatPsta.setString(94, "");
								 * insertMatPsta.setString(95, "");
								 * insertMatPsta.setString(96, "");
								 * insertMatPsta.setString(97, "");
								 * insertMatPsta.setString(98, "");
								 * 
								 * insertMatPsta.setString(99, "801401");
								 * insertMatPsta.setString(100, "80150101");
								 * insertMatPsta.setString(101, systime);
								 * insertMatPsta.setString(102,
								 * milPlanTity.getTargetLength());// 长度
								 * insertMatPsta.setString(103, list.get(7));
								 * insertMatPsta.setString(104, list.get(8));
								 * insertMatPsta.setString(105,
								 * milPlanTity.getRollStandrad());
								 * insertMatPsta.setString(106,
								 * milPlanTity.getPlineCode());
								 * insertMatPsta.setString(107,
								 * milPlanTity.getPlineName());
								 * insertMatPsta.setString(108,
								 * milPlanTity.getGradecode());
								 * insertMatPsta.setString(109,
								 * milPlanTity.getGradename());
								 * insertMatPsta.setString(110, yearMoth);
								 * insertMatPsta.setString(111, systime);
								 * insertMatPsta.setString(112, "");
								 * insertMatPsta.setString(113, "801302");
								 * insertMatPsta.setString(114, "机组");
								 * insertMatPsta.setString(115,
								 * milPlanTity.getPlineCode());
								 * insertMatPsta.setString(116,
								 * milPlanTity.getPlineName());
								 * insertMatPsta.setString(117, "");
								 * insertMatPsta.setString(118, "");
								 * insertMatPsta.setString(119, milPlanTity
								 * .getContractNo());
								 * insertMatPsta.setString(120, "11");
								 * insertMatPsta.setString(121, milPlanTity
								 * .getJudgeStoveNo());
								 */
								insertMatPsta.addBatch();
								g++;
								n++;
							}
						}
					}
				} else {
					for (int i = 0; i < jugeNoList.size(); i++) {
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmDownlineManage.selectMilPlanData");// 查询炉计划信息
						psta = connection.prepareStatement(sql);
						psta.setString(1, jugeNoList.get(i));
						rs = psta.executeQuery();
						List<MilPlanEntity3> milPlanList = EntityTool
								.getEntitysByRs(rs, MilPlanEntity3.class);
						rs.close();
						psta.close();
						if (milPlanList == null) {
							cro.setV_errMsg("无该炉计划信息!");
							return cro;
						}

						String matNo = queryMatNoM(connection, jugeNoList
								.get(i).replaceFirst("-.*", ""), bacthNo); // 材料号
						int g = Integer.parseInt(matNo.substring(
								matNo.length() - 4, matNo.length()));
						MilPlanEntity3 milPlanTity = milPlanList.get(0);
						str1 = milPlanTity.getPipeSize().split("[*]");
						lengthCp = milPlanTity.getLengthRange().split("[-]");
						List<double[]> list1 = MeanValueCalculation
								.MeanCalculation(Double.parseDouble(wgtList
										.get(i)), Integer.parseInt(acountList
										.get(i)));
						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, jugeNoList
											.get(i).replaceFirst("-.*", ""));
									insertMatPsta.setString(2, bacthNo);
									insertMatPsta.setString(3, "001");
									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(8));
									insertMatPsta.setString(9,
											(jugeNoList.get(i).replaceFirst(
													"-.*", "") + bacthNo)
													+ StringTool.formatDecimal(
															g, "0000"));
									insertMatPsta.setString(10, list.get(4));
									insertMatPsta.setString(11, list.get(5));
									insertMatPsta.setString(12, list.get(6));
									insertMatPsta.setString(13, list.get(7));

									insertMatPsta.setString(14, jugeNoList.get(
											i).replaceFirst("-.*", ""));
									insertMatPsta.setString(15, bacthNo);
									insertMatPsta.setString(16, "001");
									insertMatPsta.setString(17, "1");
									insertMatPsta.setString(18, String
											.valueOf(conW[1]));
									insertMatPsta.setString(19, systime);
									insertMatPsta.setString(20,
											(jugeNoList.get(i).replaceFirst(
													"-.*", "") + bacthNo)
													+ StringTool.formatDecimal(
															g, "0000"));
									insertMatPsta.setString(21, "801401");
									insertMatPsta.setString(22, "80150104");
									insertMatPsta.setString(23, milPlanTity
											.getPlineCode());
									insertMatPsta.setString(24, "");
									insertMatPsta.setString(25, "11");
									insertMatPsta.setString(26, milPlanTity
											.getId());
									insertMatPsta.setString(27, jugeNoList
											.get(i));
									insertMatPsta.setString(28, "");
									insertMatPsta.setString(29, milPlanTity
											.getVarieties());
									insertMatPsta.setString(30, "");
									insertMatPsta.setString(31, milPlanTity
											.getSteelname());
									insertMatPsta.setString(32, "");
									insertMatPsta.setString(33, milPlanTity
											.getPipeSize());
									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(6));
									insertMatPsta.setString(41, list.get(7));
									insertMatPsta.setString(42, milPlanTity
											.getStdStyle());
									insertMatPsta.setString(43, milPlanTity
											.getStdStyleDesc());
									insertMatPsta.setString(44, str1[0]
											.toString());
									insertMatPsta.setString(45, str1[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, jugeNoList
											.get(i));
									insertMatPsta.setString(54, yearMoth);

									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, PRO_PLAN_ID);
									insertMatPsta.setString(63, GX_PLAN_NO);
									insertMatPsta.setString(64, systime);

									insertMatPsta.setString(65, milPlanTity
											.getJudgeStoveNo());
									insertMatPsta.setString(66, milPlanTity
											.getJudgeStoveNo().replaceFirst(
													"-.*", ""));

									/*
									 * insertMatPsta.setString(55, list.get(5));
									 * insertMatPsta.setString(56, list.get(6));
									 * insertMatPsta.setString(57, inListDoc +
									 * StringTool.formatDecimal(n, "0000"));
									 * insertMatPsta.setString(58, inListDoc);
									 * insertMatPsta.setString(59, "800701");
									 * insertMatPsta.setString(60, "产出入库");
									 * insertMatPsta.setString(61,
									 * (jugeNoList.get(i).replaceFirst("-.*",
									 * "") + bacthNo) +
									 * StringTool.formatDecimal(g, "0000"));
									 * insertMatPsta.setString(62, "");
									 * insertMatPsta.setString(63, "");
									 * insertMatPsta.setString(64,
									 * jugeNoList.get(i).replaceFirst("-.*",
									 * "")); insertMatPsta.setString(65,
									 * bacthNo); insertMatPsta.setString(66,
									 * "001");
									 */

									/*
									 * insertMatPsta.setString(67, "");
									 * insertMatPsta.setString(68,
									 * milPlanTity.getVarieties());
									 * insertMatPsta.setString(69, "");// 标准
									 * insertMatPsta.setString(70,
									 * milPlanTity.getRollStandrad());
									 * insertMatPsta.setString(71, "");
									 * insertMatPsta.setString(72,
									 * milPlanTity.getSteelname());
									 * insertMatPsta.setString(73, "");
									 * insertMatPsta.setString(74,
									 * milPlanTity.getStdStyleDesc());
									 * insertMatPsta.setString(75, "");
									 * insertMatPsta.setString(76,
									 * milPlanTity.getPipeSize() .replace("*",
									 * "x")); insertMatPsta.setString(77, "");
									 * insertMatPsta.setString(78,
									 * milPlanTity.getBuckleType());
									 * 
									 * insertMatPsta.setString(79,
									 * milPlanTity.getDimater());
									 * insertMatPsta.setString(80,
									 * milPlanTity.getHeight());
									 * insertMatPsta.setString(81,
									 * milPlanTity.getLengthmin());
									 * insertMatPsta.setString(82,
									 * milPlanTity.getLengthmax());
									 * insertMatPsta.setString(83, "1");
									 * insertMatPsta.setString(84,
									 * String.valueOf(conW[1]));
									 * insertMatPsta.setString(85,
									 * String.valueOf(conW[1]));
									 * insertMatPsta.setString(86, list.get(5));
									 * insertMatPsta.setString(87, list.get(6));
									 * insertMatPsta.setString(88, list.get(0));
									 * insertMatPsta.setString(89, "");
									 * insertMatPsta.setString(90, "1");
									 * insertMatPsta.setString(91, list.get(4));
									 * insertMatPsta.setString(92, systime);
									 * insertMatPsta.setString(93, "");//合同号
									 * insertMatPsta.setString(94, "");
									 * insertMatPsta.setString(95, "");
									 * insertMatPsta.setString(96, "");
									 * insertMatPsta.setString(97, "");
									 * insertMatPsta.setString(98, "");
									 * 
									 * insertMatPsta.setString(99, "801401");
									 * insertMatPsta.setString(100, "80150101");
									 * insertMatPsta.setString(101, systime);
									 * insertMatPsta.setString(102,
									 * milPlanTity.getTargetLength());// 长度
									 * insertMatPsta.setString(103,
									 * list.get(7));
									 * insertMatPsta.setString(104,
									 * list.get(8));
									 * insertMatPsta.setString(105,
									 * milPlanTity.getRollStandrad());
									 * insertMatPsta.setString(106,
									 * milPlanTity.getPlineCode());
									 * insertMatPsta.setString(107,
									 * milPlanTity.getPlineName());
									 * insertMatPsta.setString(108,
									 * milPlanTity.getGradecode());
									 * insertMatPsta.setString(109,
									 * milPlanTity.getGradename());
									 * insertMatPsta.setString(110, yearMoth);
									 * insertMatPsta.setString(111, systime);
									 * insertMatPsta.setString(112, "");
									 * insertMatPsta.setString(113, "801302");
									 * insertMatPsta.setString(114, "机组");
									 * insertMatPsta.setString(115,
									 * milPlanTity.getPlineCode());
									 * insertMatPsta.setString(116,
									 * milPlanTity.getPlineName());
									 * insertMatPsta.setString(117, "");
									 * insertMatPsta.setString(118, "");
									 * insertMatPsta.setString(119, milPlanTity
									 * .getContractNo());
									 * insertMatPsta.setString(120, "11");
									 * insertMatPsta.setString(121,
									 * jugeNoList.get(i));
									 */
									insertMatPsta.addBatch();
									g++;
									n++;
								}
							}
						}
					}
				}
			}
			deletePsta.executeBatch();
			deleteBackLinePsta.executeBatch();
			deleteBackStaLinePsta.executeBatch();
			insertMatPsta.executeBatch();
			// deleteInstorePsta.executeBatch();
			deleteBackPipePsta.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;
	}

	/***
	 * 委外加工
	 * 
	 * @return
	 */
	public CoreReturnObject doSubcontract(ArrayList<String> parm,
			ArrayList<String> parm1, String plineCode, String subType) {
		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 imProcess = "";// 工艺号
		String subContractNo = "";// 委外单号
		String subContractNoSeq = "";// 委外流水号
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String subcontractSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.doSubcontract");
			PreparedStatement subcontractPsta = connection
					.prepareStatement(subcontractSql);
			subContractNo = doQuerySubContractNo(connection, plineCode);
			subContractNoSeq = doQuerySubContractNoSeq(connection,
					subContractNo);
			int n = Integer.parseInt(subContractNoSeq.substring(
					subContractNoSeq.length() - 3, subContractNoSeq.length()));
			for (String str : parm) {
				MilOfflineReslutEntity2 milOffResult = EntityTool
						.getEntityByJSONStr(str, MilOfflineReslutEntity2.class);
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.selectMilPlanImProcess");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milOffResult.getJudgeStoveNo());
				psta.setString(2, milOffResult.getProPlanId());
				psta.setString(3, milOffResult.getGxPlanNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					imProcess = rs.getString("IMP_PROCESS");
				}
				rs.close();
				psta.close();
				// subcontractPsta.setString(1, milOffResult.getPlineCode());
				// subcontractPsta.setString(2, milOffResult.getPlineCode());
				subcontractPsta.setString(1, subContractNo
						+ StringTool.formatDecimal(n, "000"));
				subcontractPsta.setString(2, subContractNo);
				subcontractPsta.setString(3, milOffResult.getLotNo());
				subcontractPsta.setString(4, milOffResult.getStoveNo());
				subcontractPsta.setString(5, milOffResult.getJudgeStoveNo());
				subcontractPsta.setString(6, milOffResult.getPlineCode());
				if (milOffResult.getOfflinePro().equals("探伤")) {
					subcontractPsta.setString(7, "TS");
				} else if (milOffResult.getOfflinePro().equals("质检")) {
					subcontractPsta.setString(7, "ZJ");
				} else if (milOffResult.getOfflinePro().equals("交库")) {
					subcontractPsta.setString(7, "XX");
				}

				subcontractPsta.setString(8, milOffResult.getGroupNumCount());
				subcontractPsta.setString(9, systime);
				subcontractPsta.setString(10, parm1.get(4));
				subcontractPsta.setString(11, parm1.get(0));
				subcontractPsta.setString(12, parm1.get(2));
				subcontractPsta.setString(13, parm1.get(1));
				subcontractPsta.setString(14, "0");
				subcontractPsta.setString(15, milOffResult.getOfflineType());
				subcontractPsta.setString(16, String.valueOf(Integer
						.parseInt(milOffResult.getGroupNumCount())
						* Double.parseDouble(milOffResult.getZpHeight())
						/ Integer.parseInt(milOffResult.getOfflineNum())));
				subcontractPsta.setString(17, imProcess);// 执行工艺号

				subcontractPsta.setString(18, parm1.get(5));// 钢管处理
				subcontractPsta.setString(19, parm1.get(6));// 超声探伤
				subcontractPsta.setString(20, subType);
				subcontractPsta.setString(21, parm1.get(7));// 探伤类别
				subcontractPsta.setString(22, parm1.get(8));// 探伤等级
				subcontractPsta.setString(23, milOffResult.getProPlanId());// 轧管订单编号
				subcontractPsta.setString(24, milOffResult.getGxPlanNo());// 工序排产序号

				subcontractPsta.setString(25, milOffResult.getGroupNumCount());
				subcontractPsta.setString(26, milOffResult.getJudgeStoveNo());
				subcontractPsta.setString(27, milOffResult.getProPlanId());// 轧管订单编号
				subcontractPsta.setString(28, milOffResult.getGxPlanNo());// 工序排产序号
				subcontractPsta.setString(29, milOffResult.getLotNo());
				subcontractPsta.setString(30, milOffResult.getOfflineType());
				if (milOffResult.getOfflinePro().equals("探伤")) {
					subcontractPsta.setString(31, "TS");
				} else if (milOffResult.getOfflinePro().equals("质检")) {
					subcontractPsta.setString(31, "ZJ");
				} else if (milOffResult.getOfflinePro().equals("交库")) {
					subcontractPsta.setString(31, "XX");
				}
				subcontractPsta.setString(32, milOffResult.getJudgeStoveNo());
				subcontractPsta.setString(33, milOffResult.getProPlanId());// 轧管订单编号
				subcontractPsta.setString(34, milOffResult.getGxPlanNo());// 工序排产序号
				subcontractPsta.setString(35, milOffResult.getLotNo());
				subcontractPsta.setString(36, milOffResult.getOfflineType());
				if (milOffResult.getOfflinePro().equals("探伤")) {
					subcontractPsta.setString(37, "TS");
				} else if (milOffResult.getOfflinePro().equals("质检")) {
					subcontractPsta.setString(37, "ZJ");
				} else if (milOffResult.getOfflinePro().equals("交库")) {
					subcontractPsta.setString(37, "XX");
				}
				subcontractPsta.setString(38, milOffResult.getJudgeStoveNo());
				subcontractPsta.setString(39, milOffResult.getProPlanId());// 轧管订单编号
				subcontractPsta.setString(40, milOffResult.getGxPlanNo());// 工序排产序号
				subcontractPsta.setString(41, milOffResult.getLotNo());
				subcontractPsta.setString(42, milOffResult.getOfflineType());
				if (milOffResult.getOfflinePro().equals("探伤")) {
					subcontractPsta.setString(43, "TS");
				} else if (milOffResult.getOfflinePro().equals("质检")) {
					subcontractPsta.setString(43, "ZJ");
				} else if (milOffResult.getOfflinePro().equals("交库")) {
					subcontractPsta.setString(43, "XX");
				}
				subcontractPsta.addBatch();
				n++;
			}
			subcontractPsta.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
	 * @param plineCode
	 * @return
	 * @throws Exception
	 */
	public String doQuerySubContractNo(Connection conn, String plineCode)
			throws Exception {
		String subContractNo = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmDownlineManage.doQuerySubContractNo");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, plineCode);
		psta.setString(2, plineCode);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			subContractNo = rs.getString("SUBCONTRACT_NO");
		}
		rs.close();
		psta.close();
		return subContractNo;
	}

	/***
	 * 生成委外流水号
	 * 
	 * @param conn
	 * @param subContractNo
	 * @return
	 * @throws Exception
	 */
	public String doQuerySubContractNoSeq(Connection conn, String subContractNo)
			throws Exception {
		String subContractNoSeq = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmDownlineManage.doQuerySubContractNoSeq");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, subContractNo);
		psta.setString(2, subContractNo);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			subContractNoSeq = rs.getString("SUBCONTRACT_NO_SEQ");
		}
		rs.close();
		psta.close();
		return subContractNoSeq;
	}

	/***
	 * 委外加工完成
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject subcontractComplete(ArrayList<String> parm) {
		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 flag = "";
		String enTrustFlag = "";
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String subcontractCompleteSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.subcontractComplete");
			PreparedStatement subcontractCompletePsta = connection
					.prepareStatement(subcontractCompleteSql);
			for (String str : parm) {
				MilEntrustedBillEntity milEntity = EntityTool
						.getEntityByJSONStr(str, MilEntrustedBillEntity.class);
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.SelectSubcontractComplete");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milEntity.getSubcontractNoSeq());
				psta.setString(2, milEntity.getJudgeStoveNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					flag = rs.getString("SUBCONTRACT_FLAG");
				}
				rs.close();
				psta.close();
				if (flag.equals("1")) {
					cro.setV_errMsg("委外实绩已完成,不允许再次回报委外实绩!");
					return cro;
				}
				if (milEntity.getSubcontractType().equals("1")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmEntrustedCheck.selectEntrustFlag");
					psta = connection.prepareStatement(sql);
					psta.setString(1, milEntity.getSubcontractNoSeq());
					psta.setString(2, milEntity.getJudgeStoveNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						enTrustFlag = rs.getString("ENTRUSTED_FLAG");
					}
					rs.close();
					psta.close();
					if (enTrustFlag.equals("0") || enTrustFlag.equals("2")) {
						cro.setV_errMsg("未审核/审核不通过数据,委外加工无法完成!");
						return cro;
					}
				}
				subcontractCompletePsta.setString(1, milEntity
						.getSubcontractcompleteNum());
				subcontractCompletePsta.setString(2, String.valueOf(Integer
						.parseInt(milEntity.getSubcontractNum().toString())
						* Integer.parseInt(milEntity
								.getSubcontractCompleteCut())
						- Integer.parseInt(milEntity
								.getSubcontractcompleteNum())));
				subcontractCompletePsta.setString(3, milEntity
						.getSubcontractCompleteWgt());
				subcontractCompletePsta.setString(4, milEntity
						.getSubcontractCompleteLen());
				subcontractCompletePsta.setString(5, milEntity
						.getSubcontractCompleteCut());

				subcontractCompletePsta.setString(6, milEntity
						.getSubcontractNoSeq());
				subcontractCompletePsta.setString(7, milEntity
						.getSubcontractcompleteNum());
				subcontractCompletePsta.setString(8, milEntity
						.getSubcontractCompleteWgt());
				subcontractCompletePsta.setString(9, milEntity
						.getSubcontractCompleteCut());
				subcontractCompletePsta.setString(10, milEntity
						.getSubcontractCompleteLen());
				subcontractCompletePsta.setString(11, String.valueOf(Integer
						.parseInt(milEntity.getSubcontractNum().toString())
						* Integer.parseInt(milEntity
								.getSubcontractCompleteCut())
						- Integer.parseInt(milEntity
								.getSubcontractcompleteNum())));
				subcontractCompletePsta.setString(12, milEntity
						.getJudgeStoveNo());
				subcontractCompletePsta.setString(13, milEntity.getLotNo());
				subcontractCompletePsta.setString(14, milEntity
						.getOfflineType());
				subcontractCompletePsta
						.setString(15, milEntity.getOfflinePro());
				subcontractCompletePsta.setString(16, milEntity
						.getJudgeStoveNo());
				subcontractCompletePsta.setString(17, milEntity.getLotNo());
				subcontractCompletePsta.setString(18, milEntity
						.getOfflineType());
				subcontractCompletePsta
						.setString(19, milEntity.getOfflinePro());
				// subcontractCompletePsta.setString(20,
				// milEntity.getJudgeStoveNo());
				// if(milEntity.getOfflinePro().equals("TS"))
				// {
				// subcontractCompletePsta.setString(21, "10");
				// }else if(milEntity.getOfflinePro().equals("ZJ"))
				// {
				// subcontractCompletePsta.setString(21, "11");
				// }else if(milEntity.getOfflinePro().equals("XX"))
				// {
				// subcontractCompletePsta.setString(21, "12");
				// }
				// subcontractCompletePsta.setInt(22,
				// Integer.parseInt(milEntity.getSubcontractscrapNum()));
				// subcontractCompletePsta.setString(23,
				// milEntity.getJudgeStoveNo());
				// if(milEntity.getOfflinePro().equals("TS"))
				// {
				// subcontractCompletePsta.setString(24, "10");
				// }else if(milEntity.getOfflinePro().equals("ZJ"))
				// {
				// subcontractCompletePsta.setString(24, "11");
				// }else if(milEntity.getOfflinePro().equals("XX"))
				// {
				// subcontractCompletePsta.setString(24, "12");
				// }
				subcontractCompletePsta.setString(20, milEntity
						.getJudgeStoveNo());
				subcontractCompletePsta.setString(21, milEntity
						.getSubcontractNum());
				subcontractCompletePsta.setString(22, milEntity
						.getJudgeStoveNo());
				subcontractCompletePsta.setString(23, milEntity.getLotNo());
				subcontractCompletePsta.setString(24, milEntity
						.getOfflineType());
				subcontractCompletePsta
						.setString(25, milEntity.getOfflinePro());

				subcontractCompletePsta.setInt(26, Integer.parseInt(milEntity
						.getSubcontractcompleteNum()));
				subcontractCompletePsta.setString(27, milEntity
						.getJudgeStoveNo());
				subcontractCompletePsta.setString(28, milEntity.getLotNo());
				subcontractCompletePsta.setInt(29, Integer.parseInt(milEntity
						.getSubcontractNum()));
				subcontractCompletePsta.setString(30, milEntity
						.getJudgeStoveNo());
				subcontractCompletePsta.addBatch();
			}
			subcontractCompletePsta.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 parm
	 * @return
	 */
	public CoreReturnObject cancelSubcontractComplete(ArrayList<String> parm) {
		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 flag = "";
		String enTrustFlag = "";
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String cancelsubcontractCompleteSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.cancelSubcontractComplete");
			PreparedStatement cancelsubcontractCompletePsta = connection
					.prepareStatement(cancelsubcontractCompleteSql);
			for (String str : parm) {
				MilEntrustedBillEntity milEntity = EntityTool
						.getEntityByJSONStr(str, MilEntrustedBillEntity.class);
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.SelectSubcontractComplete");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milEntity.getSubcontractNoSeq());
				psta.setString(2, milEntity.getJudgeStoveNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					flag = rs.getString("SUBCONTRACT_FLAG");
				}
				rs.close();
				psta.close();
				if (!flag.equals("1")) {
					cro.setV_errMsg("委外实绩未完成,不允许撤销!");
					return cro;
				}
				cancelsubcontractCompletePsta.setString(1, milEntity
						.getSubcontractNoSeq());

				cancelsubcontractCompletePsta.setString(2, milEntity
						.getSubcontractcompleteNum());
				cancelsubcontractCompletePsta.setString(3, milEntity
						.getSubcontractCompleteWgt());
				cancelsubcontractCompletePsta.setString(4, milEntity
						.getJudgeStoveNo());
				cancelsubcontractCompletePsta
						.setString(5, milEntity.getLotNo());
				cancelsubcontractCompletePsta.setString(6, milEntity
						.getOfflineType());
				cancelsubcontractCompletePsta.setString(7, milEntity
						.getOfflinePro());

				cancelsubcontractCompletePsta.setString(8, milEntity
						.getJudgeStoveNo());
				cancelsubcontractCompletePsta
						.setString(9, milEntity.getLotNo());
				cancelsubcontractCompletePsta.setString(10, milEntity
						.getOfflineType());
				cancelsubcontractCompletePsta.setString(11, milEntity
						.getOfflinePro());

				cancelsubcontractCompletePsta.setString(12, milEntity
						.getJudgeStoveNo());
				cancelsubcontractCompletePsta.setString(13, milEntity
						.getLotNo());
				cancelsubcontractCompletePsta.setString(14, milEntity
						.getOfflineType());
				cancelsubcontractCompletePsta.setString(15, milEntity
						.getOfflinePro());

				cancelsubcontractCompletePsta.setInt(16, Integer
						.parseInt(milEntity.getSubcontractcompleteNum()));
				cancelsubcontractCompletePsta.setString(17, milEntity
						.getJudgeStoveNo());
				cancelsubcontractCompletePsta.setString(18, milEntity
						.getLotNo());
				cancelsubcontractCompletePsta.setInt(19, Integer
						.parseInt(milEntity.getSubcontractNum()));
				cancelsubcontractCompletePsta.setString(20, milEntity
						.getJudgeStoveNo());
				cancelsubcontractCompletePsta.addBatch();

			}
			cancelsubcontractCompletePsta.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 parm
	 * @return
	 */
	public CoreReturnObject cancelSubcontract(ArrayList<String> parm) {
		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 acount = "";
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String cancelSubcontractSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.cancelSubcontract");
			PreparedStatement cancelSubcontractPsta = connection
					.prepareStatement(cancelSubcontractSql);
			for (String str : parm) {
				MilEntrustedBillEntity milTity = EntityTool.getEntityByJSONStr(
						str, MilEntrustedBillEntity.class);
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmDownlineManage.selectSubcontract");
				psta = connection.prepareStatement(sql);
				psta.setString(1, milTity.getSubcontractNoSeq());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = rs.getString("ENTRUSTED_FLAG");
				}
				rs.close();
				psta.close();
				if (acount.equals("1")) {
					cro.setV_errMsg("审核通过的,不允许进行撤销");
					return cro;
				}
				cancelSubcontractPsta.setString(1, milTity
						.getSubcontractNoSeq());
				cancelSubcontractPsta.setString(2, milTity.getSubcontractNum());
				cancelSubcontractPsta.setString(3, acount);
				cancelSubcontractPsta.setString(4, milTity.getJudgeStoveNo());
				cancelSubcontractPsta.setString(5, milTity.getLotNo());
				cancelSubcontractPsta.setString(6, milTity.getOfflineType());
				cancelSubcontractPsta.setString(7, milTity.getOfflinePro());
				cancelSubcontractPsta.addBatch();
			}
			cancelSubcontractPsta.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 parm
	 * @return
	 */
	public CoreReturnObject updateOrderLength(ArrayList<String> parm) {
		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);
		int acount = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			Statement st = connection.createStatement();
			String updateLenSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.updateOrderLength");
			for (String str : parm) {
				MilOfflineReslutEntity2 milOffResult = EntityTool
						.getEntityByJSONStr(str, MilOfflineReslutEntity2.class);
				milOffResult.setSpecName(milOffResult.getSpecName().replace(
						"x", "*"));
				// sql =
				// CoreXmlSqlParsersFactory.getSql("FrmDownlineManage.selectPortNum");
				// psta = connection.prepareStatement(sql);
				// psta.setString(1, milOffResult.getZpJudgeStoveNo());
				// rs = psta.executeQuery();
				// if(rs.next())
				// {
				// acount = Integer.parseInt(rs.getString("ACOUNT"));
				// }
				// rs.close();
				// psta.close();
				// if(acount ==0)
				// {
				// cro.setV_errMsg("组炉信息未进行返线,不允许修改长度!");
				// return cro;
				// }
				updateLenSql = EntityTool.fillSqlByEntity(updateLenSql,
						milOffResult);
				st.addBatch(updateLenSql);
			}
			st.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 list
	 * @param parm
	 * @return
	 */
	public CoreReturnObject doPipe(ArrayList<String> list,
			ArrayList<String> parm, String strInBound, String strInMemo) {
		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 jugeNo = "";// 炉号
		String bacthNo = "";// 批号
		String inListDoc = "";
		String inListSeq = "";
		String groupNo = "";
		int n = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String doPipeSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.doPipe");
			PreparedStatement doPipePsta = connection
					.prepareStatement(doPipeSql);
			String updateInstoreSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.updateInstore");
			PreparedStatement updateInstorePsta = connection
					.prepareStatement(updateInstoreSql);
			String insertOffResultDeSql = CoreXmlSqlParsersFactory
					.getSql("FrmDownlineManage.insertDetail");
			PreparedStatement insertOffResultDePsta = connection
					.prepareStatement(insertOffResultDeSql);
			for (String str : parm) {
				MilOfflineReslutEntity2 milOfflineResult = EntityTool
						.getEntityByJSONStr(str, MilOfflineReslutEntity2.class);
				jugeNo = milOfflineResult.getJudgeStoveNo().replaceFirst("-.*",
						"");
				bacthNo = "X";

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

				groupNo = queryGroupNo(connection, jugeNo, bacthNo);// 组号

				String matNo = queryMatNoM(connection, jugeNo, bacthNo); // 材料号
				int g = Integer.parseInt(matNo.substring(matNo.length() - 4,
						matNo.length()));

				List<double[]> list1 = MeanValueCalculation.MeanCalculation(
						Double.parseDouble(new DecimalFormat("0.000")
								.format(Integer.parseInt(milOfflineResult
										.getGroupNumCount())
										* Double.parseDouble(milOfflineResult
												.getZpHeight())
										/ Integer.parseInt(milOfflineResult
												.getOfflineNum()))), Integer
								.parseInt(milOfflineResult.getGroupNumCount()));
				String[] strS = milOfflineResult.getActLenRange().split("-");
				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++) {
							doPipePsta.setString(1, jugeNo);
							doPipePsta.setString(2, bacthNo);
							doPipePsta.setString(3, groupNo);
							doPipePsta.setString(4, list.get(0));
							doPipePsta.setString(5, list.get(1));
							doPipePsta.setString(6, list.get(2));
							doPipePsta.setString(7, list.get(3));
							doPipePsta.setString(8, list.get(4));
							doPipePsta.setString(9, (jugeNo + bacthNo)
									+ StringTool.formatDecimal(g, "0000"));
							doPipePsta.setString(10, list.get(5));
							doPipePsta.setString(11, list.get(6));
							doPipePsta.setString(12, list.get(7));
							doPipePsta.setString(13, list.get(8));

							// doPipePsta.setString(14,
							// milOfflineResult.getJudgeStoveNo());
							// doPipePsta.setString(15, list.get(5));
							// doPipePsta.setString(16, list.get(6));
							// doPipePsta.setString(17, inListDoc
							// + StringTool.formatDecimal(n, "0000"));
							// doPipePsta.setString(18, inListDoc);
							// doPipePsta.setString(19, "800707");
							// doPipePsta.setString(20, "下线入库");
							// doPipePsta.setString(21, (jugeNo + bacthNo)
							// + StringTool.formatDecimal(g, "0000"));
							// doPipePsta.setString(22, "");
							// doPipePsta.setString(23, "");
							// doPipePsta.setString(24, jugeNo);
							// doPipePsta.setString(25, bacthNo);
							// doPipePsta.setString(26, groupNo);
							// doPipePsta.setString(27,
							// milOfflineResult.getProduccode());
							// doPipePsta.setString(28,
							// milOfflineResult.getProducname());
							// doPipePsta.setString(29,
							// milOfflineResult.getStdCode());
							// doPipePsta.setString(30,
							// milOfflineResult.getStdName());
							// doPipePsta.setString(31,
							// milOfflineResult.getSteelcode());
							// doPipePsta.setString(32,
							// milOfflineResult.getSteelname());
							// doPipePsta.setString(33,
							// milOfflineResult.getStdStyle());
							// doPipePsta.setString(34,
							// milOfflineResult.getStdStyleDesc());
							// doPipePsta.setString(35,
							// milOfflineResult.getSpecCode());
							// doPipePsta.setString(36,
							// milOfflineResult.getSpecName());
							// doPipePsta.setString(37,
							// milOfflineResult.getModelCode());
							// doPipePsta.setString(38,
							// milOfflineResult.getModelDesc());
							// doPipePsta.setString(39,
							// milOfflineResult.getDiameter());
							// doPipePsta.setString(40,
							// milOfflineResult.getThickness());
							// doPipePsta.setString(41, strS[0]);
							// doPipePsta.setString(42, strS[1]);
							// doPipePsta.setString(43, "1");
							// doPipePsta.setString(44,
							// String.valueOf(conW[1]));
							// doPipePsta.setString(45,
							// String.valueOf(conW[1]));
							// doPipePsta.setString(46, list.get(7));
							// doPipePsta.setString(47, list.get(8));
							// doPipePsta.setString(48, list.get(0));
							// doPipePsta.setString(49, "");
							// doPipePsta.setString(50, "1");
							// doPipePsta.setString(51, list.get(4));
							// doPipePsta.setString(52, "");
							// doPipePsta.setString(53, "");
							// doPipePsta.setString(54, "");
							// doPipePsta.setString(55, "");
							// doPipePsta.setString(56, "");
							// doPipePsta.setString(57, "");
							// doPipePsta.setString(58, "801401");
							// doPipePsta.setString(59, "80150104");
							// doPipePsta.setString(60, "");
							// doPipePsta.setString(61,
							// milOfflineResult.getLength());
							// doPipePsta.setString(62, list.get(7));
							// doPipePsta.setString(63, list.get(8));
							// doPipePsta.setString(64,
							// milOfflineResult.getStdName());
							// doPipePsta.setString(65,
							// milOfflineResult.getPlineCode());
							// doPipePsta.setString(66, "");//产线名称
							// doPipePsta.setString(67,
							// milOfflineResult.getGradecode());
							// doPipePsta.setString(68,
							// milOfflineResult.getGradename());
							// doPipePsta.setString(69, "");
							// doPipePsta.setString(70, "801302");
							// doPipePsta.setString(71, "机组");
							// doPipePsta.setString(72,
							// milOfflineResult.getPlineCode());
							// doPipePsta.setString(73, "");
							// doPipePsta.setString(74, "");//物料码
							// doPipePsta.setString(75, "");//物料描述
							// doPipePsta.setString(76,
							// milOfflineResult.getContractNo());

							doPipePsta.setString(14, jugeNo);
							doPipePsta.setString(15, bacthNo);
							doPipePsta.setString(16, groupNo);
							doPipePsta.setString(17, milOfflineResult
									.getProduccode());
							doPipePsta.setString(18, milOfflineResult
									.getProducname());
							doPipePsta.setString(19, milOfflineResult
									.getSteelcode());
							doPipePsta.setString(20, milOfflineResult
									.getSteelname());
							doPipePsta.setString(21, milOfflineResult
									.getSpecCode());
							doPipePsta.setString(22, milOfflineResult
									.getSpecName());
							doPipePsta.setString(23, milOfflineResult
									.getModelCode());
							doPipePsta.setString(24, milOfflineResult
									.getModelDesc());
							doPipePsta.setString(25, milOfflineResult
									.getStdCode());
							doPipePsta.setString(26, milOfflineResult
									.getStdName());
							doPipePsta.setString(27, list.get(7));
							doPipePsta.setString(28, list.get(8));
							doPipePsta.setString(29, milOfflineResult
									.getStdStyle());
							doPipePsta.setString(30, milOfflineResult
									.getStdStyleDesc());
							doPipePsta.setString(31, "");
							doPipePsta.setString(32, "");
							doPipePsta.setString(33, "");
							doPipePsta.setString(34, "");
							doPipePsta.setString(35, "");
							doPipePsta.setString(36, "");
							doPipePsta.setString(37, milOfflineResult
									.getDiameter());
							doPipePsta.setString(38, milOfflineResult
									.getThickness());
							doPipePsta.setString(39, "");
							doPipePsta.setString(40, "");
							doPipePsta.setString(41, "");
							doPipePsta.setString(42, strS[0]);
							doPipePsta.setString(43, strS[1]);
							doPipePsta.setString(44, list.get(4));
							doPipePsta.setString(45, "1");
							doPipePsta.setString(46, String.valueOf(conW[1]));
							doPipePsta.setString(47, (jugeNo + bacthNo)
									+ StringTool.formatDecimal(g, "0000"));
							doPipePsta.setString(48, "0");
							doPipePsta.setString(49, "1");
							doPipePsta.setString(50, "801401");
							doPipePsta.setString(51, "80150104");
							doPipePsta.setString(52, milOfflineResult
									.getLength());// 长度
							doPipePsta.setString(53, milOfflineResult
									.getStdName());
							doPipePsta.setString(54, milOfflineResult
									.getPlineCode());
							doPipePsta.setString(55, "");// 产线名称
							doPipePsta.setString(56, milOfflineResult
									.getGradecode());
							doPipePsta.setString(57, milOfflineResult
									.getGradename());
							doPipePsta.setString(58, "");
							doPipePsta.setString(59, "");
							doPipePsta.setString(60, "");
							doPipePsta.setString(61, "801302");
							doPipePsta.setString(62, "机组");
							doPipePsta.setString(63, milOfflineResult
									.getPlineCode());
							doPipePsta.setString(64, "");
							doPipePsta.setString(65, "");// 物料码
							doPipePsta.setString(66, "");
							doPipePsta.setString(67, milOfflineResult
									.getGradecode());
							doPipePsta.setString(68, milOfflineResult
									.getGradename());
							doPipePsta.setString(69, milOfflineResult
									.getSteelcode());
							doPipePsta.setString(70, milOfflineResult
									.getSteelname());
							doPipePsta.setString(71, milOfflineResult
									.getContractNo());
							doPipePsta.setString(72, "");
							doPipePsta.setString(73, "");
							doPipePsta.setString(74, "11");
							doPipePsta.setString(75, "");
							doPipePsta.setString(76, "");
							doPipePsta.setString(77, milOfflineResult
									.getJudgeStoveNo());

							doPipePsta.addBatch();
							n++;
							g++;
						}
					}
				}
				insertOffResultDePsta.setString(1, milOfflineResult.getLotNo());
				insertOffResultDePsta.setString(2, milOfflineResult
						.getJudgeStoveNo());
				insertOffResultDePsta.setString(3, milOfflineResult
						.getGroupNumCount());
				insertOffResultDePsta.setString(4, new DecimalFormat("0.000")
						.format(Integer.parseInt(milOfflineResult
								.getGroupNumCount())
								* Double.parseDouble(milOfflineResult
										.getZpHeight())
								/ Integer.parseInt(milOfflineResult
										.getOfflineNum())));
				insertOffResultDePsta.setString(5, systime);
				insertOffResultDePsta.setString(6, list.get(4));
				insertOffResultDePsta.setString(7, list.get(9));
				insertOffResultDePsta.setString(8, list.get(10));
				insertOffResultDePsta.setString(9, inListDoc);
				insertOffResultDePsta.setString(10, milOfflineResult
						.getPlineCode());
				insertOffResultDePsta.setString(11, "");
				insertOffResultDePsta.setString(12, milOfflineResult
						.getOfflineType());
				insertOffResultDePsta.addBatch();

				updateInstorePsta.setString(1, milOfflineResult
						.getGroupNumCount());
				updateInstorePsta.setString(2, milOfflineResult
						.getJudgeStoveNo());
				updateInstorePsta.setString(3, milOfflineResult.getLotNo());
				updateInstorePsta.setString(4, milOfflineResult
						.getOfflineType());
				updateInstorePsta.addBatch();
			}
			doPipePsta.executeBatch();
			insertOffResultDePsta.executeBatch();
			updateInstorePsta.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()) {
			// String res = rs.getString(1);
			// if (res == null) {
			// res = strLcode + strBatch + "0001";
			// } else {
			// count = Integer.parseInt(res.substring(res.length() - 4, res
			// .length()));
			// }
			matNo = rs.getString("MAT_NO");
		}
		rs.close();
		psta.close();
		// return (strLcode + strBatch)
		// + StringTool.formatDecimal(++count, "0000");
		return matNo;
	}

	/**
	 * 每支材料对应的入库单号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSqlDoc(Connection conn, String strlist, String memo)
			throws Exception {
		int seq = 0;
		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, matter1.format(dt));
		psta.setString(2, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			String res = rs.getString(1);
			if (res == null) {
				res = memo + matter2.format(dt) + "00001";
			} else {
				seq = Integer.parseInt(res.substring(8, 13));
			}
		}
		rs.close();
		psta.close();
		return memo + matter2.format(dt)
				+ StringTool.formatDecimal(++seq, "00000");
	}

	/**
	 * 每支材料对应的入库流水号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSql(Connection conn, String strlist)
			throws Exception {
		int seq = 0;
		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, matter1.format(dt));
		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));
			}
		}
		rs.close();
		psta.close();
		return strlist + StringTool.formatDecimal(++seq, "0000");
	}

	/**
	 * 根据炉号、批号自动组号
	 * 
	 * @param conn
	 *            c
	 * @param strLcode
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String queryGroupNo(Connection conn, String strLcode, String strBatch)
			throws Exception {
		int count = 0;
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmInOnlineStore.queryGroupNo");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strLcode);
		psta.setString(2, strBatch);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			String res = rs.getString(1);
			if (res == null) {
				res = "001";
			} else {
				count = Integer.parseInt(res.substring(res.length() - 3, res
						.length()));
			}
		}
		rs.close();
		psta.close();
		return StringTool.formatDecimal(++count, "000");
	}

	/***
	 * 查询品名
	 * 
	 * @return
	 */
	public CoreReturnObject doQueryProName() {
		return this.getDataBySqlID("FrmDownlineManage.doQueryProName");
	}

	/***
	 * 查询钢级
	 * 
	 * @return
	 */
	public CoreReturnObject doQuerySteelName() {
		return this.getDataBySqlID("FrmDownlineManage.doQuerySteelName");
	}

	/***
	 * 查询规格
	 * 
	 * @return
	 */
	public CoreReturnObject doQuerySpecName() {
		return this.getDataBySqlID("FrmDownlineManage.doQuerySpecName");
	}

	/***
	 * 查询扣型
	 * 
	 * @return
	 */
	public CoreReturnObject doQueryModleName() {
		return this.getDataBySqlID("FrmDownlineManage.doQueryModleName");
	}

	/***
	 * 查询标准类别
	 * 
	 * @return
	 */
	public CoreReturnObject doQueryStyName() {
		return this.getDataBySqlID("FrmDownlineManage.doQueryStyName");
	}

	/***
	 * 查询工序合同号
	 * 
	 * @return
	 */
	public CoreReturnObject doQueryOrderNo(String orderNo) {
		return this.getDataBySqlID("FrmDownlineManage.doQueryOrderNo",
				new Object[] { orderNo });
	}

	/***
	 * 查询离线库存支数
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryLxStore(String jugeNo) {
		return this.getDataBySqlID("FrmDownlineManage.doQueryLxStore",
				new Object[] { jugeNo });
	}

	/***
	 * 查询下线工序是否结炉
	 * 
	 * @param jugeNo
	 * @param offlinePro
	 * @return
	 */
	public CoreReturnObject doQueryNodesPro(String jugeNo, String offlinePro,
			String proPlanId, String gxPlanNo) {
		if (offlinePro.equals("探伤")) {
			return this.getDataBySqlID("doQueryNodesPro.TS", new Object[] {
					jugeNo, proPlanId, gxPlanNo, jugeNo, proPlanId, gxPlanNo });
		} else if (offlinePro.equals("质检")) {
			return this.getDataBySqlID("doQueryNodesPro.JZ", new Object[] {
					jugeNo, proPlanId, gxPlanNo });
		} else if (offlinePro.equals("交库")) {
			return this.getDataBySqlID("doQueryNodesPro.XX", new Object[] {
					jugeNo, proPlanId, gxPlanNo });
		} else {
			return null;
		}
	}

	/***
	 * 查询是否存在委外加工委托
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryEntust(String jugeNo, String proPlanId,
			String gxPlanNo) {
		return this.getDataBySqlID("FrmDownlineManage.doQueryEntust",
				new Object[] { jugeNo, proPlanId, gxPlanNo });
	}

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

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

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

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

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

				insertPsta.setString(1, milOfflineEntity.getJudgeStoveNo());
				insertPsta.setString(2, milOfflineEntity.getOfflinePro());
				insertPsta.setString(3, milOfflineEntity.getOfflineType());
				insertPsta.setString(4, milOfflineEntity.getPlineCode());
				insertPsta.setString(5, userName);
				insertPsta.addBatch();
			}
			insertPsta.executeBatch();

			cro.setV_errMsg("脱单成功!");
			connection.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/**
	 * 查询当月炉号数 并生成炉号 炉号为“F XX XX XXXX”
	 * 
	 * @return
	 */
	public CoreReturnObject doQueryZpJudgeStoveNo(String flag) {
		return this.getDataBySqlID("FrmDownlineManage.doQueryZpJudgeStoveNo",
				new Object[] { flag, flag, flag, flag });
	}
}
