package com.steering.mes.mcp.Mch;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.mes.mcp.common.PlanService;
import com.steering.mes.mcp.entity.MchBugDEntity;
import com.steering.mes.mcp.entity.MchEntity.PlnZyJgxCEntity;
import com.steering.mes.mcp.entity.MchEntity.PlnZyJgxMEntity;
import com.steering.mes.mcp.entity.MchMtResultEntity;
import com.steering.mes.mcp.entity.MchOfflineResultDentity;
import com.steering.mes.mcp.entity.PortMchBatchSampleResultEntity;

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

/**
 * 湿磁粉探伤实绩
 * 
 * @author SZL
 *
 */
public class FrmDetectResult extends DBCommon {
	private String perStuts = "";

	/**
	 * 查询湿磁粉探伤实绩
	 */
	public CoreReturnObject getQueryExpandResult(String heatNo) {
		return this.getDataBySqlID("FrmDetectResult.getQueryExpandResult",
				new Object[] { heatNo });
	}

	/**
	 * 查询相同炉计划ID下湿磁粉探伤实绩状态
	 */
	public CoreReturnObject getQueryExpandResultStuts(String heatNo,
			String plinCode) {
//		String sql = CoreXmlSqlParsersFactory.getSql("FrmDetectResult.getQueryExpandResultStuts");
//		sql += "AND T.HEAT_PLAN_NO = '"+heatNo+"'";
//		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCode);
//		return this.getData(sql);
		return this.getDataBySqlID("FrmDetectResult.getQueryExpandResultStuts",
				new Object[] { heatNo, plinCode });
	}

	/**
	 * 查询探伤实绩合格支数的和
	 * 
	 * @param heatNo
	 * @return
	 */
	public CoreReturnObject getQueryExpandResult1(String heatNo) {
		return this.getDataBySqlID("FrmDetectResult.getQueryExpandResult1",
				new Object[] { heatNo });
	}

	/**
	 * 查询实绩里不同分切数的加工支数
	 * 
	 * @param heatNo
	 * @return
	 */
	public CoreReturnObject getQueryNum(String heatNo, String outnumcut) {
		return this.getDataBySqlID("FrmDetectResult.getquerynum", new Object[] {
				heatNo, outnumcut });
	}

	/**
	 * 湿磁粉探伤新增
	 * 
	 * @param load
	 * @return
	 */
	public CoreReturnObject saveExpandResult(MchMtResultEntity load,
			String hertNo, String slgx, String plinCode, String tetnum,
			String batchgroudno, String outnumcut, String lengthin,
			String lengthmaxin, String lengthminin,
			ArrayList<MchBugDEntity> list3, ArrayList<MchBugDEntity> list4,
			ArrayList<MchBugDEntity> list5) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		Date now = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat matter2 = new SimpleDateFormat("yyyyMMddHHmm");
		Calendar ca = Calendar.getInstance();
		ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(now);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.AddExpandResult");// 新增湿磁粉探伤
			PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
			String addPlnInfo = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.AddComInfoResult");// 新增公共信息
			PreparedStatement patsPlan = connection
					.prepareStatement(addPlnInfo);
			String addPlnInfo1 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.AddComInfoResult1");// 修改队列表材料，工序状态
			PreparedStatement patsPlan1 = connection
					.prepareStatement(addPlnInfo1);
			String updatePath = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.UpdatePath");// 修改队列表工艺路径
			PreparedStatement pastupdatePath = connection
					.prepareStatement(updatePath);
			String updatePln = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.UpdatePln");// 修改计划表工序状态
			PreparedStatement pastupdatePln = connection
					.prepareStatement(updatePln);
			String updatebugd = CoreXmlSqlParsersFactory
					.getSql("FrmMchBugD.Updatebugd");// 修改缺陷表实绩编号
			PreparedStatement pastupdatebugd = connection
					.prepareStatement(updatebugd);
			String sqlDelete = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResult.AddFailResult");// 新增绝废实绩
			PreparedStatement patDelete = connection
					.prepareStatement(sqlDelete);
			// String addConLoag = CoreXmlSqlParsersFactory
			// .getSql("FrmVrpExpandResult.AddConLoag");// 新增调度信息
			// PreparedStatement pastAddLoag = connection
			// .prepareStatement(addConLoag);
			String sqlloadings = CoreXmlSqlParsersFactory
					.getSql("FrmMchInOnlineStore.queryperstu");// 查询信息表除了本工序之外最大的工序
			PreparedStatement pstas = connection.prepareStatement(sqlloadings);
			pstas.setObject(1, hertNo);
			pstas.setObject(2, slgx);
			ResultSet rss = pstas.executeQuery();
			if (rss.next()) {
				perStuts = rss.getString("STATION_CODE");
				// if(perStuts.equals("0"))
				// {
				// core.setV_errMsg("无工序，不允许此操作!");
				// return core;
				// }else
				if (perStuts.equals("701301")) {
					perStuts = "00";
				} else if (perStuts.equals("701302")) {
					perStuts = "01";
				} else if (perStuts.equals("701303")) {
					perStuts = "02";
				} else if (perStuts.equals("701304")) {
					perStuts = "03";
				} else if (perStuts.equals("701305")) {
					perStuts = "04";
				} else if (perStuts.equals("701306")) {
					perStuts = "05";
				} else if (perStuts.equals("701307")) {
					perStuts = "06";
				} else if (perStuts.equals("701308")) {
					perStuts = "07";
				} else if (perStuts.equals("701309")) {
					perStuts = "08";
				} else if (perStuts.equals("701310")) {
					perStuts = "09";
				} else if (perStuts.equals("701311")) {
					perStuts = "10";
				}
			}
			rss.close();
			pstas.close();
			// 获取加工计划实体了
			PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
					load.getHeatPlanNo());
			// 获取加工计划从表实体了
			PlnZyJgxCEntity plnC = PlanService.getSendHttPlanCInfo3C(
					connection, load.getHeatPlanNo());
			if (pln == null)
				return core;
			if (!pln.getPlanstatus().equals("20")) {
				core.setV_errMsg("该计划不是生产中的，请确认是否生产完成或未上料！");
				return core;
			}

			String ifMonitNo = "";
			if (pln.getIfMonitor().equals("是")) {
				ifMonitNo = "1";
			} else {
				ifMonitNo = "0";
			}
			String cutFalg = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.qureyGxComInfo");// 查询工序结炉状态
			PreparedStatement psta1 = connection.prepareStatement(sql);
			psta1.setString(1, hertNo);
			psta1.setString(2, plinCode);
			psta1.setString(3, slgx);
			ResultSet rs = psta1.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			}
			if (cutFalg.equals("2")) {
				core.setV_errMsg("已结炉,不允许此操作！");
				return core;
			}
			rs.close();
			psta1.close();

			String perstuts = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmChamferingResult.queryPlnZy");// 查询计划表下线开始状态
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, hertNo);
			psta.setObject(2, plinCode);
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				perstuts = rs1.getString("PER_STATUS");
			}
			rs1.close();
			psta.close();
			if (perstuts == "10") {
				core.setV_errMsg("已经交库不允许此操作!");
				return core;
			}

			String resultNo = "";
			String sqlloading1 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.queryExpandMaxRESULT");// 查询最大实绩编号
			psta = connection.prepareStatement(sqlloading1);
			psta.setObject(1, plinCode + slgx + matter1.format(now));
			psta.setObject(2, matter.format(now));
			psta.setObject(3, pln.getPlineCode());
			ResultSet rs2 = psta.executeQuery();
			if (rs2.next()) {
				resultNo = rs2.getString("RESULT_NO");
			}
			rs2.close();
			psta.close();
			// 新增湿磁粉探伤实绩
			patAdd.setObject(1, resultNo);
			patAdd.setObject(2, load.getHeatPlanNo());
			patAdd.setObject(3, pln.getZyBatchId());
			patAdd.setObject(4, pln.getProPlanId());
			patAdd.setObject(5, pln.getGxPlanNo());
			patAdd.setObject(6, pln.getPlineCode());
			patAdd.setObject(7, pln.getPlineName());
			patAdd.setObject(8, load.getTetNum());
			patAdd.setObject(9, load.getCutNum());
			patAdd.setObject(10, load.getDubiousNum());
			patAdd.setObject(11, load.getFtestingNum());
			patAdd.setObject(12, load.getFpassNum());
			patAdd.setObject(13, load.getProNum());
			patAdd.setObject(14, load.getProWt());
			patAdd.setObject(15, load.getFailNum());
			patAdd.setObject(16, load.getFailWt());
			patAdd.setObject(17, load.getFailBill());
			patAdd.setObject(18, load.getOfflineNum());
			patAdd.setObject(19, load.getOfflineWt());
			patAdd.setObject(20, load.getReNum());
			patAdd.setObject(21, load.getReWt());
			patAdd.setObject(22, "");// 监制要求
			patAdd.setObject(23, pln.getIfMonitor());
			patAdd.setObject(24, load.getProducer());
			patAdd.setObject(25, pln.getPrdcrNo());
			if (load.getProducer().equals("")) {
				patAdd.setObject(26, "");
			} else {
				patAdd.setObject(26, load.getProducerTime());
			}
			patAdd.setObject(27, load.getRroTime());
			patAdd.setObject(28, load.getProShift());
			patAdd.setObject(29, load.getProGroup());
			patAdd.setObject(30, "1");
			patAdd.setObject(31, load.getCreateTime());
			patAdd.setObject(32, load.getTestingStandard1());
			patAdd.setObject(33, load.getTestingStandard2());
			patAdd.setObject(34, load.getTestingStandard3());
			patAdd.setObject(35, load.getTestingStandard4());
			patAdd.setObject(36, load.getTestingGrade1());
			patAdd.setObject(37, load.getTestingGrade2());
			patAdd.setObject(38, load.getTestingGrade3());
			patAdd.setObject(39, load.getTestingGrade4());
			patAdd.setObject(40, load.getShimMagIndic());
			patAdd.setObject(41, load.getShimMagType());
			patAdd.setObject(42, load.getMtType());
			patAdd.setObject(43, load.getMagSuspLiqCon());
			patAdd.setObject(44, load.getCoilCurInt());
			patAdd.setObject(45, load.getCtrStiCurInt());
			patAdd.setObject(46, load.getDemagVol());
			patAdd.setObject(47, load.getMtNote());
			patAdd.setObject(48, load.getUtMan());
			patAdd.setObject(49, load.getUtManGrade());
			patAdd.setObject(50, load.getSignMan());
			patAdd.setObject(51, load.getSignManGrade());
			patAdd.setObject(52, load.getCreateUser());
			patAdd.setObject(53, outnumcut);
			patAdd.setObject(54, lengthin);
			patAdd.setObject(55, lengthmaxin);
			patAdd.setObject(56, lengthminin);
			patAdd.addBatch();
			// 新增加工公共信息
			patsPlan.setObject(1, resultNo);
			patsPlan.setObject(2, pln.getZyBatchId());
			patsPlan.setObject(3, "");
			patsPlan.setObject(4, pln.getProPlanId());
			patsPlan.setObject(5, pln.getGxPlanNo());
			patsPlan.setObject(6, pln.getOrderSource());
			patsPlan.setObject(7, pln.getOrderNo());
			patsPlan.setObject(8, pln.getOrderSeq());
			patsPlan.setObject(9, pln.getReqBlId());
			patsPlan.setObject(10, pln.getPlineCode());
			patsPlan.setObject(11, pln.getPlineName());
			patsPlan.setObject(12, slgx);
			patsPlan.setObject(13, slgx);
			patsPlan.setObject(14, "");
			patsPlan.setObject(15, "");
			patsPlan.setObject(16, pln.getSteelcode());
			patsPlan.setObject(17, pln.getSteelname());
			patsPlan.setObject(18, pln.getOutdiameter());
			patsPlan.setObject(19, pln.getWallthick());
			patsPlan.setObject(20, "");
			patsPlan.setObject(21, "");
			patsPlan.setObject(22, "");
			patsPlan.setObject(23, "");
			patsPlan.setObject(24, "");
			patsPlan.setObject(25, "");
			patsPlan.setObject(26, "");
			patsPlan.setObject(27, "");
			patsPlan.setObject(28, pln.getOutwlId());
			patsPlan.setObject(29, pln.getOutwlDesc());
			patsPlan.setObject(30, pln.getInwlId());
			patsPlan.setObject(31, pln.getInwlDesc());
			patsPlan.setObject(32, pln.getMonitorPoint());
			patsPlan.setObject(33, ifMonitNo);
			patsPlan.setObject(34, pln.getPrdcrNo());
			patsPlan.setObject(35, load.getProducer());
			if (load.getProducer().equals("")) {
				patsPlan.setObject(36, "");
			} else {
				patsPlan.setObject(36, load.getProducerTime());
			}
			patsPlan.setObject(37, pln.getStationRoad());
			patsPlan.setObject(38, pln.getCraftFileNo());
			patsPlan.setObject(39, pln.getCraftFileMan());
			patsPlan.setObject(40, pln.getCraftSeq());
			patsPlan.setObject(41, load.getProNum());
			patsPlan.setObject(42, load.getProWt());
			patsPlan.setObject(43, load.getFailNum());
			patsPlan.setObject(44, load.getFailWt());
			patsPlan.setObject(45, load.getOfflineNum());
			patsPlan.setObject(46, load.getOfflineWt());
			patsPlan.setObject(47, load.getReNum());
			patsPlan.setObject(48, load.getReWt());
			patsPlan.setObject(49, "1");
			patsPlan.setObject(50, load.getRroTime());
			patsPlan.setObject(51, "");
			patsPlan.setObject(52, load.getProShift());
			patsPlan.setObject(53, load.getProGroup());
			patsPlan.setObject(54, "1");
			patsPlan.setObject(55, load.getCreateTime());
			patsPlan.setObject(56, load.getCreateUser());
			patsPlan.setObject(57, load.getHeatPlanNo());
			patsPlan.setObject(58, pln.getJudgeStoveNo());
			patsPlan.setObject(59, plnC.getBatchNo());
			patsPlan.setObject(60, batchgroudno);
			patsPlan.setObject(61, pln.getProduccode());
			patsPlan.setObject(62, pln.getProducname());
			patsPlan.setObject(63, outnumcut);
			patsPlan.setObject(64, pln.getSpecCode());
			patsPlan.setObject(65, pln.getSpecName());
			patsPlan.addBatch();

			// // 新增调度日志表
			// pastAddLoag.setObject(1, matter2.format(now));
			// pastAddLoag.setObject(2, pln.getPlineCode());
			// pastAddLoag.setObject(3, pln.getHeatnoLast());
			// pastAddLoag.setObject(4, pln.getZyBatchId());
			// pastAddLoag.setObject(5, pln.getOrderNo() + pln.getOrderSeq()
			// + pln.getDeliveryNo());
			// pastAddLoag.setObject(6, pln.getCraftFileNo());
			// pastAddLoag.setObject(7, pln.getPrdcrNo());
			// pastAddLoag.setObject(8, pln.getGradecode());
			// pastAddLoag.setObject(9, pln.getGradename());
			// pastAddLoag.setObject(10, load.getLoadShift());
			// pastAddLoag.setObject(11, load.getLoadGroup());
			// pastAddLoag.setObject(12, load.getProNum());
			// pastAddLoag.setObject(13, load.getProWt());
			// pastAddLoag.setObject(14, load.getFailNum());
			// pastAddLoag.setObject(15, load.getFailWt());
			// pastAddLoag.setObject(16, "1");
			// pastAddLoag.setObject(17, systime);
			// pastAddLoag.setObject(18, load.getLoadUser());
			// pastAddLoag.setObject(19, resultNo);
			// pastAddLoag.setObject(20, pln.getHeatPlanNo());
			// pastAddLoag.setObject(21, pln.getZgBatchNo());
			// pastAddLoag.setObject(22, pln.getBatchGroudNo());
			// pastAddLoag.addBatch();

			ArrayList<String> matNo = new ArrayList<String>();
			String sqlloading2 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.queryExpandNUM");// 查询管号队列里合格的材料号
			psta = connection.prepareStatement(sqlloading2);
			psta.setObject(1, hertNo);
			psta.setObject(2, Integer.parseInt(load.getFailNum()) + 1);
			ResultSet rs3 = psta.executeQuery();
			while (rs3.next()) {
				matNo.add(rs3.getString("MAT_NO"));
			}
			rs3.close();
			psta.close();
			// 修改材料状态，工序
			for (int i = 0; i < matNo.size(); i++) {
				patsPlan1.setObject(1, "10");
				patsPlan1.setObject(2, "701302");
				patsPlan1.setObject(3, hertNo);
				patsPlan1.setObject(4, matNo.get(i));
				patsPlan1.addBatch();
			}

			// 查询产线下工序的位置
			int cnum = 0;
			String sqlloading8 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.queryGxPosition");
			psta = connection.prepareStatement(sqlloading8);
			psta.setObject(1, pln.getPlineCode());
			rs = psta.executeQuery();
			if (rs.next()) {
				if (rs.getString("CNUM") == "" || rs.getString("CNUM") == null) {
					cnum = 0;
				} else {
					cnum = Integer.parseInt(rs.getString("CNUM"));
				}
			}
			rs.close();
			psta.close();
			// 修改工艺路径
			if (cnum != 0) {
				pastupdatePath.setObject(1, 2 * cnum - 2);
				pastupdatePath.setObject(2, "1");
				pastupdatePath.setObject(3, 2 * cnum);
				pastupdatePath.setObject(4, hertNo);
				if (tetnum.equals("") || tetnum == null) {
					pastupdatePath.setObject(5, load.getTetNum());
				} else {
					pastupdatePath.setObject(5, Integer.parseInt(tetnum));
				}
				pastupdatePath.addBatch();
				pastupdatePath.executeBatch();
			}
//			// 查询缺陷表对应的工序
//			String gx = "";
//			sqlloading = CoreXmlSqlParsersFactory.getSql("FrmMchBugD.queryGX");
//			psta = connection.prepareStatement(sqlloading);
//			psta.setObject(1, hertNo);
//			psta.setObject(2, plinCode);
//			rs = psta.executeQuery();
//			if (rs.next()) {
//				gx = rs.getString("RESULT_NO");
//			}
//			rs.close();
//			psta.close();
//			if (gx.equals("701302") && !load.getFailNum().equals("0")) {
//				pastupdatebugd.setObject(1, resultNo);
//				pastupdatebugd.setObject(2, hertNo);
//				pastupdatebugd.setObject(3, pln.getPlineCode());
//				pastupdatebugd.setObject(4, gx);
//				pastupdatebugd.addBatch();
//				pastupdatebugd.executeBatch();
//			}

			// 修改计划表工序状态
			pastupdatePln.setObject(1, hertNo);
			pastupdatePln.addBatch();
			pastupdatePln.executeBatch();

			patsPlan1.executeBatch();
			patAdd.executeBatch();
			patsPlan.executeBatch();

			String sqlAddD = CoreXmlSqlParsersFactory
					.getSql("FrmMchBugD.AddExpandDResult");// 新增可疑从表实绩
			PreparedStatement patAddD = connection.prepareStatement(sqlAddD);

			String sqlAddD1 = CoreXmlSqlParsersFactory
					.getSql("FrmMchBugD.AddExpandDResult1");// 新增废品从表实绩
			PreparedStatement patAddD1 = connection.prepareStatement(sqlAddD1);

			// 新增可疑从表实绩
			for (int i = 0; i < list3.size(); i++) {
				String failBill = "";
				String sqlloading3 = CoreXmlSqlParsersFactory
						.getSql("FrmMchBugD.queryMaxfailBill");// 生成废品缺陷编号
				psta = connection.prepareStatement(sqlloading3);
				psta.setObject(1, resultNo);
				psta.setObject(2, hertNo);
				psta.setObject(3, "00");
				ResultSet rs5 = psta.executeQuery();
				if (rs5.next()) {
					failBill = rs5.getString("FAIL_BILL");
				}
				rs5.close();
				psta.close();
				String mresultNo = "";
				String sqlloading4 = CoreXmlSqlParsersFactory
						.getSql("FrmMchBugD.queryJumpDRESULT");// 查询从表最大实绩编号
				psta = connection.prepareStatement(sqlloading4);
				psta.setObject(1, hertNo);
				ResultSet rs6 = psta.executeQuery();
				if (rs6.next()) {
					mresultNo = rs6.getString("FAIL_BILL_SQE");
				}

				rs6.close();
				psta.close();
				MchBugDEntity resultD = list3.get(i);
				patAddD.setObject(1, failBill);
				patAddD.setObject(2, mresultNo);
				patAddD.setObject(3, resultNo);
				patAddD.setObject(4, hertNo);
				patAddD.setObject(5, resultD.getFailTypeName());
				patAddD.setObject(6, resultD.getFailNum());
				patAddD.setObject(7, "1");
				patAddD.setObject(8, pln.getPlineCode());
				patAddD.addBatch();
				patAddD.executeBatch();
			}
			// 新增废品从表实绩
			for (int j = 0; j < list4.size(); j++) {
				String failBill = "";
				String sqlloading6 = CoreXmlSqlParsersFactory
						.getSql("FrmMchBugD.queryMaxfailBill");// 生成废品缺陷编号
				psta = connection.prepareStatement(sqlloading6);
				psta.setObject(1, resultNo);
				psta.setObject(2, hertNo);
				psta.setObject(3, "10");
				ResultSet rs6 = psta.executeQuery();
				if (rs6.next()) {
					failBill = rs6.getString("FAIL_BILL");
				}
				rs6.close();
				psta.close();
				String mresultNo = "";
				String sqlloading5 = CoreXmlSqlParsersFactory
						.getSql("FrmMchBugD.queryJumpDRESULT");// 查询从表最大实绩编号
				psta = connection.prepareStatement(sqlloading5);
				psta.setObject(1, hertNo);
				ResultSet rs4 = psta.executeQuery();
				if (rs4.next()) {
					mresultNo = rs4.getString("FAIL_BILL_SQE");
				}
				rs4.close();
				psta.close();
				MchBugDEntity resultD = list4.get(j);
				patAddD1.setObject(1, failBill);
				patAddD1.setObject(2, mresultNo);
				patAddD1.setObject(3, resultNo);
				patAddD1.setObject(4, hertNo);
				patAddD1.setObject(5, resultD.getFailTypeName());
				patAddD1.setObject(6, resultD.getFailNum());
				patAddD1.setObject(7, "1");
				patAddD1.setObject(8, pln.getPlineCode());
				patAddD1.setObject(9, "10");
				patAddD1.setObject(10, resultD.getFailDirect());
				patAddD1.addBatch();
				patAddD1.executeBatch();
			}
			int failCount = 0;
			// 新增绝废
			for (int m = 0; m < list5.size(); m++) {
				String failBill = "";
				String sqlloading6 = CoreXmlSqlParsersFactory
						.getSql("FrmMchBugD.queryMaxfailBill");// 生成废品缺陷编号
				psta = connection.prepareStatement(sqlloading6);
				psta.setObject(1, resultNo);
				psta.setObject(2, load.getHeatPlanNo());
				psta.setObject(3, "20");
				ResultSet rs6 = psta.executeQuery();
				if (rs6.next()) {
					failBill = rs6.getString("FAIL_BILL");
				}
				rs6.close();
				psta.close();
				String mresultNo = "";
				String sqlloading5 = CoreXmlSqlParsersFactory
						.getSql("FrmMchBugD.queryJumpDRESULT");// 查询从表最大实绩编号
				psta = connection.prepareStatement(sqlloading5);
				psta.setObject(1, load.getHeatPlanNo());
				ResultSet rs4 = psta.executeQuery();
				if (rs4.next()) {
					mresultNo = rs4.getString("FAIL_BILL_SQE");
				}
				rs4.close();
				psta.close();
				MchBugDEntity resultD = list5.get(m);
				failCount = failCount + Integer.parseInt(resultD.getFailNum());
				patDelete.setObject(1, failBill);
				patDelete.setObject(2, mresultNo);
				patDelete.setObject(3, resultNo);
				patDelete.setObject(4, load.getHeatPlanNo());
				patDelete.setObject(5, "");
				patDelete.setObject(6, resultD.getFailTypeName());
				patDelete.setObject(7, resultD.getFailNum());
				patDelete.setObject(8, "1");
				patDelete.setObject(9, pln.getPlineCode());
				patDelete.setObject(10, pln.getPlineName());
				patDelete.setObject(11, "20");
				patDelete.setObject(12, resultD.getFailDirect());

				patDelete.addBatch();
				patDelete.executeBatch();
			}
			String updateMatM = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResult.AddComInfoResult1");// 修改队列表材料，工序状态
			PreparedStatement patsUpdaeMatM = connection
					.prepareStatement(updateMatM);


			ArrayList<String> MatNo2 = new ArrayList<String>();
			String sqlloading5 = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResult.queryExpandNUM");// 查询管号队列里合格的材料号
			psta = connection.prepareStatement(sqlloading5);
			psta.setObject(1, load.getHeatPlanNo());
			psta.setObject(2, failCount + 1);
			ResultSet rs5 = psta.executeQuery();
			while (rs5.next()) {
				MatNo2.add(rs5.getString("MAT_NO"));
			}
			rs5.close();
			psta.close();
			// 如果有废品新增到材料表
			if (failCount != 0) {
				// 修改材料状态，工序
				for (int i = 0; i < MatNo2.size(); i++) {
					patsUpdaeMatM.setObject(1, "15");
					patsUpdaeMatM.setObject(2, "701302");
					patsUpdaeMatM.setObject(3, load.getHeatPlanNo());
					patsUpdaeMatM.setObject(4, MatNo2.get(i));
					patsUpdaeMatM.addBatch();


					PlanService.AddOffLineMat(connection,"G",load.getCreateUser(),"22",
							MatNo2.get(i),slgx, load.getHeatPlanNo());
				}
			}
			patsUpdaeMatM.executeBatch();
			// pastAddLoag.executeBatch();
			core.setV_errMsg("新增湿磁粉探伤成功！");
			core.setResult(1);
			connection.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 撤销湿磁粉探伤
	 * 
	 * @param planNo
	 * @return
	 */
	public CoreReturnObject deleteVrpExpandResult(ArrayList<String> list1,
			String herPlanNo, String plinCode, String gx, String tetnum,
			String outnumcut, Integer nnum,Integer detCount) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlDelete = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.deleteVrpExpandResult");// 删除湿磁粉探伤实绩
			PreparedStatement patDelete = connection
					.prepareStatement(sqlDelete);
			String updatePlnInfo = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.deleteComInfoResult");// 删除公共信息
			PreparedStatement patsupdatePlan = connection
					.prepareStatement(updatePlnInfo);
			String addPlnInfo1 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.AddComInfoResult1");// 查询材料状态和工序点编码
			PreparedStatement patsPlan1 = connection
					.prepareStatement(addPlnInfo1);
			String updatePath = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.UpdatePath");// 修改队列表工艺路径
			PreparedStatement pastupdatePath = connection
					.prepareStatement(updatePath);
			String updateMatm = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResult.AddComInfoResult2");// 修改管号队列绝废状态
			PreparedStatement patsPlan2 = connection
					.prepareStatement(updateMatm);
			String updatePln = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.UpdatePln1");// 撤销修改计划表工序状态
			PreparedStatement pastupdatePln = connection
					.prepareStatement(updatePln);
			// String deleteConLoag = CoreXmlSqlParsersFactory
			// .getSql("FrmVrpExpandResult.DeleteConLoag");// 删除调度日志
			// PreparedStatement pastDeleteLoag = connection
			// .prepareStatement(deleteConLoag);
			String sqlloadings = CoreXmlSqlParsersFactory
					.getSql("FrmMchInOnlineStore.queryperstu");// 查询信息表除了本工序之外最大的工序
			PreparedStatement pstas = connection.prepareStatement(sqlloadings);
			pstas.setObject(1, herPlanNo);
			pstas.setObject(2, gx);
			ResultSet rss = pstas.executeQuery();
			if (rss.next()) {
				perStuts = rss.getString("STATION_CODE");
				// if(perStuts.equals("0"))
				// {
				// core.setV_errMsg("无工序，不允许此操作!");
				// return core;
				// }else
				if (perStuts.equals("701301")) {
					perStuts = "00";
				} else if (perStuts.equals("701302")) {
					perStuts = "01";
				} else if (perStuts.equals("701303")) {
					perStuts = "02";
				} else if (perStuts.equals("701304")) {
					perStuts = "03";
				} else if (perStuts.equals("701305")) {
					perStuts = "04";
				} else if (perStuts.equals("701306")) {
					perStuts = "05";
				} else if (perStuts.equals("701307")) {
					perStuts = "06";
				} else if (perStuts.equals("701308")) {
					perStuts = "07";
				} else if (perStuts.equals("701309")) {
					perStuts = "08";
				} else if (perStuts.equals("701310")) {
					perStuts = "09";
				} else if (perStuts.equals("701311")) {
					perStuts = "10";
				}
			}
			rss.close();
			pstas.close();

			// 获取加工计划实体了
			PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
					herPlanNo);
			if (pln == null)
				return core;
			if (!pln.getPlanstatus().equals("20")) {
				core.setV_errMsg("该计划不是生产中的状态！");
				return core;
			}
			String cutFalg = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.qureyGxComInfo");// 查询工序是否是结炉状态
			PreparedStatement psta = connection.prepareStatement(sql);
			psta.setString(1, herPlanNo);
			psta.setString(2, plinCode);
			psta.setString(3, gx);
			ResultSet rs = psta.executeQuery();

			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			}
			rs.close();
			psta.close();
			if (cutFalg.equals("2")) {
				core.setV_errMsg("已结炉,不允许此操作！");
				return core;
			}

			int lxCount = 0;
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.qureyGxLxCount");// 查询是否离线
			psta = connection.prepareStatement(sql);
			psta.setString(1, herPlanNo);
			psta.setString(2, plinCode);
			psta.setString(3, gx);
			rs = psta.executeQuery();
			if (rs.next()) {
				lxCount = Integer.parseInt(rs.getString("COUNT"));
			}
			rs.close();
			psta.close();
			if (lxCount != 0) {
				core.setV_errMsg("该工序点有离线记录,不允许此操作！");
				return core;
			}
			// for (int i = 0; i < list1.size(); i++) {
			// ArrayList<String> list = (ArrayList<String>) list1.get(i);
			String resNo = list1.get(0);
			// 删除湿磁粉探伤实绩
			patDelete.setObject(1, resNo);
			patDelete.addBatch();
			// 删除湿磁粉探伤公共信息
			patsupdatePlan.setObject(1, resNo);
			patsupdatePlan.addBatch();
			// // 删除调度日志
			// pastDeleteLoag.setObject(1, herPlanNo);
			// pastDeleteLoag.setObject(2, resNo);
			// pastDeleteLoag.addBatch();

			patDelete.executeBatch();
			patsupdatePlan.executeBatch();
			// pastDeleteLoag.executeBatch();

			int count = 0;
			int num = 0;
			int FAIL = 0;
			String sqlloading1 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.queryExpandFailNUM");// 查询管号队列表里废品数量
			psta = connection.prepareStatement(sqlloading1);
			psta.setObject(1, herPlanNo);
			psta.setObject(2, gx);
			ResultSet rs2 = psta.executeQuery();
			if (rs2.next()) {
				count = Integer.parseInt(rs2.getString("ACT_COUNT"));
			}
			rs2.close();
			psta.close();
			String sqlloading2 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.queryExpandFailNUM1");// 查询工序废品数量
			psta = connection.prepareStatement(sqlloading2);
			psta.setObject(1, herPlanNo);
			ResultSet rs3 = psta.executeQuery();
			if (rs3.next()) {
				FAIL = Integer.parseInt(rs3.getString("FAIL_NUM"));
			}
			rs3.close();
			psta.close();
			 if (count < detCount) 
	            {
	            	core.setV_errMsg("管号队列的废品支数小于实绩废品支数，请检查!");
	                return core;
	            }else{
				ArrayList<String> matNo = new ArrayList<String>();
				String sqlloading3 = CoreXmlSqlParsersFactory
						.getSql("FrmDetectResult.queryExpandNUM2");// 查询管号队列表里废品材料号
				psta = connection.prepareStatement(sqlloading3);
				psta.setObject(1, herPlanNo);
				psta.setObject(2, gx);
				psta.setObject(3, detCount + 1);
				ResultSet rs4 = psta.executeQuery();
				while (rs4.next()) {
					matNo.add(rs4.getString("MAT_NO"));
				}
				rs4.close();
				psta.close();
				for (num = 0; num < matNo.size(); num++) {
					patsPlan1.setObject(1, "00");
					patsPlan1.setObject(2, "701302");
					patsPlan1.setObject(3, herPlanNo);
					patsPlan1.setObject(4, matNo.get(num));
					patsPlan1.addBatch();


				}
				patsPlan1.executeBatch();
			}

			// 查询产线下工序的位置
			int cnum = 0;
			String sqlloading8 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.queryGxPosition");
			psta = connection.prepareStatement(sqlloading8);
			psta.setObject(1, pln.getPlineName());
			rs = psta.executeQuery();
			if (rs.next()) {
				if (rs.getString("CNUM") == "" || rs.getString("CNUM") == null) {
					cnum = 0;
				} else {
					cnum = Integer.parseInt(rs.getString("CNUM"));
				}
			}
			rs.close();
			psta.close();
			// 修改工艺路径
			if (cnum != 0) {
				pastupdatePath.setObject(1, 2 * cnum - 2);
				pastupdatePath.setObject(2, "0");
				pastupdatePath.setObject(3, 2 * cnum);
				pastupdatePath.setObject(4, herPlanNo);
				pastupdatePath.setObject(5, Integer.parseInt(tetnum));
				pastupdatePath.addBatch();
				pastupdatePath.executeBatch();
			}
			ArrayList<String> matNo = new ArrayList<String>();
			String sqlloading3 = CoreXmlSqlParsersFactory
					.getSql("FrmMeasureResult.queryExpandNUM2");// 查询管号队列表里绝废材料号
			psta = connection.prepareStatement(sqlloading3);
			psta.setObject(1, herPlanNo);
			psta.setObject(2, gx);
			psta.setObject(3, nnum + 1);
			ResultSet rs4 = psta.executeQuery();
			while (rs4.next()) {
				matNo.add(rs4.getString("MAT_NO"));
			}
			rs4.close();
			psta.close();

			for (int i = 0; i < matNo.size(); i++) {
				patsPlan2.setObject(1, "00");
				patsPlan2.setObject(2, "701302");
				patsPlan2.setObject(3, herPlanNo);
				patsPlan2.setObject(4, matNo.get(i));
				patsPlan2.addBatch();

				PlanService.DeleteOffLineMat(connection,matNo.get(num));
			}
			patsPlan2.executeBatch();
			String sqlloadingdet = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.detelefailnum");// 删除废品缺陷实绩
			PreparedStatement pstadet = connection
					.prepareStatement(sqlloadingdet);
			pstadet.setString(1, resNo);
			pstadet.setString(2, herPlanNo);
			pstadet.setString(3, plinCode);
			pstadet.addBatch();
			pstadet.executeBatch();
			// 撤销修改计划状态
			pastupdatePln.setObject(1, perStuts);
			pastupdatePln.setObject(2, herPlanNo);
			pastupdatePln.addBatch();
			pastupdatePln.executeBatch();
			core.setV_errMsg("删除湿磁粉探伤成功！");
			core.setResult(1);
			connection.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 修改湿磁粉探伤
	 * 
	 * @param planNo
	 * @return
	 */
	public CoreReturnObject updateVrpExpandResult(MchMtResultEntity load,
			String gx) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(now);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlDelete = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.updateVrpExpandResult");// 修改湿磁粉探伤实绩
			PreparedStatement patDelete = connection
					.prepareStatement(sqlDelete);
			String updatePlnInfo = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.updateComInfoResult");// 修改公共信息
			PreparedStatement patsupdatePlan = connection
					.prepareStatement(updatePlnInfo);
			// String updateConLoag = CoreXmlSqlParsersFactory
			// .getSql("FrmVrpExpandResult.UpdateConLoag");// 修改调度日志
			// PreparedStatement pastUpdateLoag = connection
			// .prepareStatement(updateConLoag);
			String addPlnInfo1 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.AddComInfoResult1");// 查询材料状态和工序点编码
			PreparedStatement patsPlan1 = connection
					.prepareStatement(addPlnInfo1);



			// 获取加工计划实体了
			PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
					load.getHeatPlanNo());
			if (pln == null)
				return core;
			if (!pln.getPlanstatus().equals("20")) {
				core.setV_errMsg("该计划不是生产中的状态！");
				return core;
			}
			String cutFalg = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.qureyGxComInfo");// 查询工序是否是结炉状态
			PreparedStatement psta = connection.prepareStatement(sql);
			psta.setString(1, load.getHeatPlanNo());
			psta.setString(2, load.getPlineCode());
			psta.setString(3, gx);
			ResultSet rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			}
			if (cutFalg.equals("2")) {
				core.setV_errMsg("已结炉,不允许此操作！");
				return core;
			}
			rs.close();
			psta.close();
			// 修改湿磁粉探伤实绩
			patDelete.setObject(1, load.getTetNum());
			patDelete.setObject(2, load.getCutNum());
			patDelete.setObject(3, load.getDubiousNum());
			patDelete.setObject(4, load.getFtestingNum());
			patDelete.setObject(5, load.getFpassNum());
			patDelete.setObject(6, load.getProNum());
			patDelete.setObject(7, load.getProWt());
			patDelete.setObject(8, load.getFailNum());
			patDelete.setObject(9, load.getFailWt());
			patDelete.setObject(10, load.getFailBill());
			patDelete.setObject(11, load.getProducer());
			patDelete.setObject(12, load.getProducerTime());
			patDelete.setObject(13, load.getRroTime());
			patDelete.setObject(14, load.getProShift());
			patDelete.setObject(15, load.getProGroup());
			patDelete.setObject(16, load.getTestingStandard1());
			patDelete.setObject(17, load.getTestingStandard2());
			patDelete.setObject(18, load.getTestingStandard3());
			patDelete.setObject(19, load.getTestingStandard4());
			patDelete.setObject(20, load.getTestingGrade1());
			patDelete.setObject(21, load.getTestingGrade2());
			patDelete.setObject(22, load.getTestingGrade3());
			patDelete.setObject(23, load.getTestingGrade4());
			patDelete.setObject(24, load.getShimMagIndic());
			patDelete.setObject(25, load.getShimMagType());
			patDelete.setObject(26, load.getMtType());
			patDelete.setObject(27, load.getMagSuspLiqCon());
			patDelete.setObject(28, load.getCoilCurInt());
			patDelete.setObject(29, load.getCtrStiCurInt());
			patDelete.setObject(30, load.getDemagVol());
			patDelete.setObject(31, load.getMtNote());
			patDelete.setObject(32, load.getUtMan());
			patDelete.setObject(33, load.getUtManGrade());
			patDelete.setObject(34, load.getSignMan());
			patDelete.setObject(35, load.getSignManGrade());
			patDelete.setObject(36, systime);
			patDelete.setObject(37, load.getUpdateName());
			patDelete.setObject(38, load.getResultNo());
			patDelete.addBatch();
			// 修改湿磁粉探伤公共信息
			patsupdatePlan.setObject(1, load.getProducer());
			patsupdatePlan.setObject(2, load.getProducerTime());
			patsupdatePlan.setObject(3, load.getProNum());
			patsupdatePlan.setObject(4, load.getProWt());
			patsupdatePlan.setObject(5, load.getFailNum());
			patsupdatePlan.setObject(6, load.getFailWt());
			patsupdatePlan.setObject(7, load.getRroTime());
			patsupdatePlan.setObject(8, load.getProShift());
			patsupdatePlan.setObject(9, load.getProGroup());
			patsupdatePlan.setObject(10, load.getResultNo());
			patsupdatePlan.addBatch();

			// // 修改调度日志
			// pastUpdateLoag.setObject(1, load.getProNum());
			// pastUpdateLoag.setObject(2, load.getProWt());
			// pastUpdateLoag.setObject(3, load.getFailNum());
			// pastUpdateLoag.setObject(4, load.getFailWt());
			// pastUpdateLoag.setObject(5, load.getLoadShift());
			// pastUpdateLoag.setObject(6, load.getLoadGroup());
			// pastUpdateLoag.setObject(7, load.getResultNo());
			// pastUpdateLoag.setObject(8, load.getHeatPlanNo());
			// pastUpdateLoag.addBatch();

			patDelete.executeBatch();
			patsupdatePlan.executeBatch();
			// pastUpdateLoag.executeBatch();
			int count = 0;
			int num = 0;
			int FAIL = 0;
			String sqlloading1 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.queryExpandFailNUM");// 查询管号队列表里废品数量
			psta = connection.prepareStatement(sqlloading1);
			psta.setObject(1, load.getHeatPlanNo());
			psta.setObject(2, gx);
			ResultSet rs2 = psta.executeQuery();
			if (rs2.next()) {
				count = Integer.parseInt(rs2.getString("ACT_COUNT"));
			}
			rs2.close();
			psta.close();
			String sqlloading2 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.queryExpandFailNUM1");// 查询工序废品数量
			psta = connection.prepareStatement(sqlloading2);
			psta.setObject(1, load.getHeatPlanNo());
			ResultSet rs3 = psta.executeQuery();
			if (rs3.next()) {
				FAIL = Integer.parseInt(rs3.getString("FAIL_NUM"));
			}
			rs3.close();
			psta.close();
			if (count > FAIL) {
				num = count - FAIL;
				ArrayList<String> matNo = new ArrayList<String>();
				String sqlloading3 = CoreXmlSqlParsersFactory
						.getSql("FrmDetectResult.queryExpandNUM2");// 查询管号队列表里废品材料号
				psta = connection.prepareStatement(sqlloading3);
				psta.setObject(1, load.getHeatPlanNo());
				psta.setObject(2, gx);
				psta.setObject(3, num + 1);
				ResultSet rs4 = psta.executeQuery();
				while (rs4.next()) {
					matNo.add(rs4.getString("MAT_NO"));
				}
				rs4.close();
				psta.close();
				for (num = 0; num < matNo.size(); num++) {
					patsPlan1.setObject(1, "00");
					patsPlan1.setObject(2, gx);
					patsPlan1.setObject(3, load.getHeatPlanNo());
					patsPlan1.setObject(4, matNo.get(num));
					patsPlan1.addBatch();

					PlanService.DeleteOffLineMat(connection,matNo.get(num));
				}
				patsPlan1.executeBatch();
			} else if (count < FAIL) {
				num = FAIL - count;
				ArrayList<String> matNo1 = new ArrayList<String>();
				String sqlloading4 = CoreXmlSqlParsersFactory
						.getSql("FrmDetectResult.queryExpandNUM");// 查询管号队列表里合格材料号
				psta = connection.prepareStatement(sqlloading4);
				psta.setObject(1, load.getHeatPlanNo());
				psta.setObject(2, num + 1);
				ResultSet rs5 = psta.executeQuery();
				while (rs5.next()) {
					matNo1.add(rs5.getString("MAT_NO"));
				}
				rs5.close();
				psta.close();
				for (num = 0; num < matNo1.size(); num++) {
					patsPlan1.setObject(1, "10");
					patsPlan1.setObject(2, gx);
					patsPlan1.setObject(3, load.getHeatPlanNo());
					patsPlan1.setObject(4, matNo1.get(num));
					patsPlan1.addBatch();


					PlanService.AddOffLineMat(connection,"G",load.getCreateUser(),"22",
							matNo1.get(num),gx, load.getHeatPlanNo());

				}
				patsPlan1.executeBatch();
			}
			core.setV_errMsg("修改湿磁粉探伤成功！");
			core.setResult(1);
			connection.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

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

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

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

	/***
	 * 撤销结炉
	 * 
	 * @param zYgNo
	 * @return
	 */
	public CoreReturnObject undoBeside(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.deleteBeside");// 修改工序状态撤销结炉
			PreparedStatement updateSqlPsta = connection
					.prepareStatement(updateSql);
			String updatePln = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.doPlnBeside");// 修改计划表结炉状态
			PreparedStatement updatePlnPsta = connection
					.prepareStatement(updatePln);
			String sqlloadings = CoreXmlSqlParsersFactory
					.getSql("FrmMchInOnlineStore.queryperstu");// 查询信息表除了本工序之外最大的工序
			PreparedStatement pstas = connection.prepareStatement(sqlloadings);
			pstas.setObject(1, parm.get(0));
			pstas.setObject(2, parm.get(2));
			ResultSet rss = pstas.executeQuery();
			if (rss.next()) {
				perStuts = rss.getString("STATION_CODE");
				// if(perStuts.equals("0"))
				// {
				// cro.setV_errMsg("无工序，不允许此操作!");
				// return cro;
				// }else
				if (perStuts.equals("701301")) {
					perStuts = "00";
				} else if (perStuts.equals("701302")) {
					perStuts = "01";
				} else if (perStuts.equals("701303")) {
					perStuts = "02";
				} else if (perStuts.equals("701304")) {
					perStuts = "03";
				} else if (perStuts.equals("701305")) {
					perStuts = "04";
				} else if (perStuts.equals("701306")) {
					perStuts = "05";
				} else if (perStuts.equals("701307")) {
					perStuts = "06";
				} else if (perStuts.equals("701308")) {
					perStuts = "07";
				} else if (perStuts.equals("701309")) {
					perStuts = "08";
				} else if (perStuts.equals("701310")) {
					perStuts = "09";
				} else if (perStuts.equals("701311")) {
					perStuts = "10";
				}
			}
			rss.close();
			pstas.close();
			String cutFalg1 = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.qureyGxComInfo");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			psta.setString(2, parm.get(1));
			psta.setObject(3, Integer.parseInt(parm.get(2)) + 1);
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg1 = rs.getString("STATION_STATUS");
			}
			if (cutFalg1.equals("2")) {
				cro.setV_errMsg("下一道工序没有撤销结炉,不允许此工序撤销结炉!");
				return cro;
			}
			rs.close();
			psta.close();
			String cutFalg = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.qureyGxComInfo");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			psta.setString(2, parm.get(1));
			psta.setString(3, parm.get(2));
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
			} else {
				cro.setV_errMsg("无当前工序实绩,无法进行结炉!");
				return cro;
			}
			if (cutFalg.equals("1")) {
				cro.setV_errMsg("未结炉,不允许此操作！");
				return cro;
			}
			rs.close();
			psta.close();
			// 判断是否已经交库了
			String status = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmMcpLoading.qureyGxOnline");// 查询公共信息表有没有交库工序
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			rs = psta.executeQuery();
			if (rs.next()) {
				status = rs.getString("COUNT");
			}
			if (!status.equals("0")) {
				cro.setV_errMsg("该炉已经交库,无法撤销结炉!");
				return cro;
			}
			rs.close();
			psta.close();
			updateSqlPsta.setString(1, parm.get(0));
			updateSqlPsta.setString(2, parm.get(1));
			updateSqlPsta.setString(3, parm.get(2));
			updateSqlPsta.addBatch();

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

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

	/**
	 * 离线
	 * 
	 * @param load
	 * @return
	 */
	public CoreReturnObject offLineExpandResult(
			ArrayList<MchOfflineResultDentity> list1, MchMtResultEntity load,
			ArrayList<String> list, String plinCode, String storageNo,
			String batchgroudno, String outnumcut) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyyMMdd");
		Calendar ca = Calendar.getInstance();
		ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(now);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String addOff = CoreXmlSqlParsersFactory
					.getSql("FrmThreadingResult.AddOffLine");// 新增离线实绩
			PreparedStatement patAdd = connection.prepareStatement(addOff);
			String addOffD = CoreXmlSqlParsersFactory
					.getSql("FrmThreadingResult.AddOffLineD");// 新增离线实绩从表
			PreparedStatement patAddD = connection.prepareStatement(addOffD);
			String MarkOff = CoreXmlSqlParsersFactory
					.getSql("FrmThreadingResult.MarkUnCancelFlag");// 标记之前同炉批组返线的离线实绩为无法撤销数据
			PreparedStatement patMarkOff = connection.prepareStatement(MarkOff);

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

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


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


			String judge = "";
			String batch = "";
			String procode = "";
			String proname = "";
			String stecode = "";
			String stename = "";
			String gracode = "";
			String graname = "";
			String modecode = "";
			String modedesc = "";
			String stdcode = "";
			String stdname = "";
			String stdstyle = "";
			String stdstyledesc = "";
			String actdimater = "";
			String actheight = "";
			String actlen = "";
			String actlenmin = "";
			String actlenmax = "";
			// 查询产线下工序的位置
			int cnum = 0;
			String sqlloading8 = CoreXmlSqlParsersFactory
					.getSql("FrmDetectResult.queryGxPosition");
			psta = connection.prepareStatement(sqlloading8);
			psta.setObject(1, pln.getPlineName());
			rs = psta.executeQuery();
			if (rs.next()) {
				if (rs.getString("CNUM") == "" || rs.getString("CNUM") == null) {
					cnum = 0;
				} else {
					cnum = Integer.parseInt(rs.getString("CNUM"));
				}
			}
			rs.close();
			psta.close();
			if (cnum == 0) {
				core.setV_errMsg("该产线下没有这道工序,不允许此操作!");
				return core;
			}
			int countNum = 0;
			double weightNum = 0;
			for (PortMchBatchSampleResultEntity prot : matNo) {
				countNum += Integer.parseInt(prot.getActCount());
				weightNum += Double.parseDouble(prot.getActWeight());
				if (cnum != 0) {
					// 修改管号队列状态
					pastupdatePath.setObject(1, "1");
					pastupdatePath.setObject(2, 2 * cnum - 2);
					pastupdatePath.setObject(3, "2");
					pastupdatePath.setObject(4, 2 * cnum);
					pastupdatePath.setObject(5, "20");
					pastupdatePath.setObject(6, "10");
					pastupdatePath.setObject(7, slgx);
					pastupdatePath.setObject(8, heatPlanNo);
					pastupdatePath.setObject(9, prot.getMatNo());
					pastupdatePath.setObject(10, outnumcut);
					pastupdatePath.addBatch();
				}


				// 修改材料表状态
				patMatNo.setObject(1, "80150104");
				// patMatNo.setObject(2, "11");
				patMatNo.setObject(2, prot.getMatNo());
				patMatNo.addBatch();
				// List<MatZcMEntity> listMat = new ArrayList<MatZcMEntity>();
				// listMat = EntityTool.getEntitysByRs(rs, MatZcMEntity.class);
				// for(MatZcMEntity lvMat : listMat)
				// {
				// // 新增入库表数据
				// patIn.setObject(1, inListDoc
				// + StringTool.formatDecimal(g, "0000"));
				// patIn.setObject(2, inListDoc);
				// patIn.setObject(3, "800708");
				// patIn.setObject(4, "离线入库");
				// patIn.setObject(5, "");
				// patIn.setObject(6, prot.getMatNo());
				// patIn.setObject(7, "");
				// patIn.setObject(8, "");
				// patIn.setObject(9, prot.getJudgeStoveNo());
				// patIn.setObject(10, prot.getBatchNo());
				// patIn.setObject(11, prot.getGroupNo());
				// patIn.setObject(12, "");
				// patIn.setObject(13, "");
				// patIn.setObject(14, "");
				// patIn.setObject(15, "");
				// patIn.setObject(16, "");
				// patIn.setObject(17, "");
				// patIn.setObject(18, "");
				// patIn.setObject(19, "");
				// patIn.setObject(20, "");
				// patIn.setObject(21, "");
				// patIn.setObject(22, "");
				// patIn.setObject(23, "");
				// patIn.setObject(24, "");
				// patIn.setObject(25, "");
				// patIn.setObject(26, "");
				// patIn.setObject(27, "");
				// patIn.setObject(28, "");
				// patIn.setObject(29, pln.getPlineCode());
				// patIn.setObject(30, pln.getPlineName());
				// patIn.setObject(31, prot.getActDimater());
				// patIn.setObject(32, prot.getActHeight());
				// patIn.setObject(33, prot.getActLen());
				// patIn.setObject(34, prot.getActLenMin());
				// patIn.setObject(35, prot.getActLenMax());
				// patIn.setObject(36, prot.getActCount());
				// patIn.setObject(37, prot.getActWeight());
				// patIn.setObject(38, prot.getActTheoryWeight());
				// patIn.setObject(39, "");// 组织
				// patIn.setObject(40, "");
				// patIn.setObject(41, storageNo);//
				// patIn.setObject(42, storageNo + "10101");
				// patIn.setObject(43, "");
				// patIn.setObject(44, "");
				// patIn.setObject(45, storageAtte);
				// patIn.setObject(46, storageAtteName);
				// patIn.setObject(47, storageType);
				// patIn.setObject(48, storageTypeName);
				// patIn.setObject(49, managNo);
				// patIn.setObject(50, managName);
				// patIn.setObject(51, time);
				// patIn.setObject(52, bc);
				// patIn.setObject(53, bz);
				// patIn.setObject(54, time);
				// patIn.setObject(55, bc);
				// patIn.setObject(56, bz);
				// patIn.setObject(57, "");
				// patIn.setObject(58, name);
				// patIn.setObject(59, time);
				// patIn.setObject(60, lvMat.getOrdPk());// 合同pK
				// patIn.setObject(61, lvMat.getOrdLnPk());
				// patIn.setObject(62, pln.getOrdLnDlyPk());
				// patIn.setObject(63, depNo);
				// patIn.setObject(64, depName);
				// patIn.setObject(65, pln.getOrderNo());// 合同号
				// patIn.setObject(66, pln.getOrderSeq());
				// patIn.setObject(67, pln.getDeliveryNo());
				// patIn.setObject(68, "801401");
				// patIn.setObject(69, "80150104");
				// patIn.setObject(70, "");
				// patIn.setObject(71, "");
				// patIn.setObject(72, time);
				// patIn.setObject(73, "");
				// patIn.setObject(74, "");
				// patIn.setObject(75, "");
				// patIn.setObject(76, "");
				// patIn.setObject(77, "");
				// patIn.setObject(78, "");
				// patIn.setObject(79, "");
				// patIn.setObject(80, "");
				// patIn.setObject(81, "1");
				// patIn.addBatch();
				// }
				// g++;
				judge = prot.getJudgeStoveNo();
				batch = prot.getBatchNo();
				procode = prot.getProducCode();
				proname = prot.getProducName();
				stecode = prot.getSteelCode();
				stename = prot.getSteelName();
				gracode = prot.getGradeCode();
				graname = prot.getGradeName();
				modecode = prot.getModelCode();
				modedesc = prot.getModelDesc();
				stdcode = prot.getStdCode();
				stdname = prot.getStdName();
				stdstyle = prot.getStdStyle();
				stdstyledesc = prot.getStdStyleDesc();
				actdimater = prot.getActDimater();
				actheight = prot.getActHeight();
				actlen = prot.getActLen();
				actlenmin = prot.getActLenMin();
				actlenmax = prot.getActLenMax();
			}
			pastupdatePath.executeBatch();
			// patIn.executeBatch();
			patMatNo.executeBatch();

			String ifMonitNo = "";
			if (pln.getIfMonitor().equals("是")) {
				ifMonitNo = "1";
			} else {
				ifMonitNo = "0";
			}
			String resultNo = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmThreadingResult.queryOffMaxRESULT");// 查询离线最大实绩编号
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, plinCode + slgx + "L" + matter1.format(dt));
			psta.setObject(2, matter.format(dt));
			psta.setObject(3, pln.getPlineCode());
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				resultNo = rs1.getString("RESULT_NO");
			}
			rs1.close();
			psta.close();
		
			for (PortMchBatchSampleResultEntity lvMat : matNo) {
				// 新增离线实绩
				patAdd.setObject(1, resultNo);
				patAdd.setObject(2, pln.getPlineCode());
				patAdd.setObject(3, pln.getPlineName());
				patAdd.setObject(4, slgx);
				patAdd.setObject(5, slgxname);
				patAdd.setObject(6, heatPlanNo);
				patAdd.setObject(7, pln.getZyBatchId());

				patAdd.setObject(8, pln.getProPlanId());
				patAdd.setObject(9, pln.getGxPlanNo());

				patAdd.setObject(10, judge);
				patAdd.setObject(11, batch);
				patAdd.setObject(12, batchgroudno);
				patAdd.setObject(13, pln.getProduccode());
				patAdd.setObject(14, pln.getProducname());
				patAdd.setObject(15, pln.getSteelcode());
				patAdd.setObject(16, pln.getSteelname());
				patAdd.setObject(17, pln.getGradecode());
				patAdd.setObject(18, pln.getGradename());
				patAdd.setObject(19, pln.getModelCode());
				patAdd.setObject(20, pln.getModelDesc());
				patAdd.setObject(21, pln.getStdCode());
				patAdd.setObject(22, pln.getStdName());
				patAdd.setObject(23, pln.getStdStyle());
				patAdd.setObject(24, pln.getStdStyleDesc());
				patAdd.setObject(25, actdimater);
				patAdd.setObject(26, actheight);
				patAdd.setObject(27, actlen);
				patAdd.setObject(28, actlenmin);
				patAdd.setObject(29, actlenmax);
				patAdd.setObject(30, pln.getOrdLnDlyPk());
				patAdd.setObject(31, pln.getOrderNo());
				patAdd.setObject(32, pln.getOrderSeq());
				patAdd.setObject(33, pln.getDeliveryNo());
				patAdd.setObject(34, countNum);
				patAdd.setObject(35, weightNum);
				patAdd.setObject(36, name);
				patAdd.setObject(37, bc);
				patAdd.setObject(38, bz);
				patAdd.setObject(39, time);
				
				// 如果有离线新增到材料表
				if (!count.equals("") && !count.equals("0")) {
					PlanService.AddOffLineMat(connection,"G",load.getCreateUser(),"11",
							lvMat.getMatNo(),slgx, heatPlanNo);
				}
			}
			// 新增离线从表
			for (int i = 0; i < list1.size(); i++) {
				String failBill = "";
				// String sqlloading2 = CoreXmlSqlParsersFactory
				// .getSql("FrmMchBugD.queryMaxfailBill");// 生成废品缺陷编号
				// psta = connection.prepareStatement(sqlloading2);
				// psta.setObject(1, resultNo);
				// psta.setObject(2, heatNo);
				// psta.setObject(3, "1");
				// ResultSet rs1 = psta.executeQuery();
				// if (rs1.next()) {
				// failBill = rs1.getString("FAIL_BILL");
				// }
				// rs1.close();
				// psta.close();
				String resultsqe = "";
				sqlloading = CoreXmlSqlParsersFactory
						.getSql("FrmDetectResult.querymaxsqe");// 查询从表最大序号
				psta = connection.prepareStatement(sqlloading);
				psta.setObject(1, matter1.format(now));
				psta.setObject(2, heatPlanNo);
				psta.setObject(3, plinCode);
				ResultSet rs3 = psta.executeQuery();
				if (rs3.next()) {
					resultsqe = rs3.getString("RESULT_SQE");
				}

				rs3.close();
				psta.close();
				MchOfflineResultDentity resultD = list1.get(i);
				patAddD.setObject(1, resultNo);
				patAddD.setObject(2, resultsqe);
				patAddD.setObject(3, heatPlanNo);
				patAddD.setObject(4, plinCode);
				patAddD.setObject(5, pln.getPlineName());
				patAddD.setObject(6, count);
				patAddD.setObject(7, resultD.getGowhereCode());
				patAddD.setObject(8, resultD.getGowhereName());
				patAddD.setObject(9, slgx);
				patAddD.setObject(10, slgx);
				patAddD.setObject(11, slgxname);
				patAddD.addBatch();
				patAddD.executeBatch();
			}
			patAdd.addBatch();
			patAdd.executeBatch();
			
			patMarkOff.setObject(1, pln.getHeatPlanNo());
			patMarkOff.setObject(2, pln.getJudgeStoveNo());
			patMarkOff.setObject(3, pln.getBatchNo());
			patMarkOff.setObject(4, batchgroudno);
			patMarkOff.setObject(5, slgx);
			patMarkOff.addBatch();
			patMarkOff.executeBatch();

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

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

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