package com.steering.mes.mcp.coup;

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

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

import com.steering.comm.converter.CoreConverter;
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.CouplingMatMEntity;
import com.steering.mes.mcp.entity.PhosphateResult;
import com.steering.mes.mcp.entity.PlnOrderJgEntity;
import com.steering.mes.mcp.entity.PlnZyJgEntity;
import com.steering.mes.mcp.entity.MchEntity.CouplingComInfoEntity;
import com.steering.mes.mcp.entity.MchEntity.PlnZyJgWorkbillEntity;

/**
 * 接箍磷化检测实绩
 * 
 * @author lzh520
 */
public class PhosphateResultService extends DBCommon {

	/*
	 * 查询磷化实绩支数
	 */
	public CoreReturnObject getphosphResult(String woid) {
		return this.getDataBySqlID("PhosphateResultService.getphosphResult",
				new Object[] { woid });
	}

	/**
	 * 查询操作工
	 */
	public CoreReturnObject queryMemo(String base) {
		return this.getDataBySqlID("PhosphateResultService.queryMemo",
				new Object[] { base });
	}

	/**
	 * 查询公共信息表备注
	 */
	public CoreReturnObject queryColUser(String base) {
		return this.getDataBySqlID("PhosphateResultService.queryColUser",
				new Object[] { base });
	}

	/**
	 * 查询入库实绩
	 */
	public CoreReturnObject getphosInResult(String startTime, String endTime,
			String[] starts, String woid, String judgeNo, String shift,
			String confirm) {
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("PhosphateResultService.getphosInResult");
		String sql = "";
		if (!startTime.equals("")) {

			sql += " AND T3.CREATE_TIME >=TO_DATE('"
					+ startTime
					+ "', 'YYYY-MM-DD HH24:MI:SS') AND T3.CREATE_TIME <=TO_DATE('"
					+ endTime + "', 'YYYY-MM-DD HH24:MI:SS')";

		}
		if (!woid.equals("")) {
			sql += " AND T1.WO_ID ='" + woid + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T1.JUDGE_STOVE_NO ='" + judgeNo + "'";
		}
		if (starts.length > 0) {
			sql += CoreConverter.toSqlConditionString("T1.ZY_BILL_STATUS",
					starts);
		}
		if (!shift.equals("")) {
			sql += " AND T3.COL_SHIFT ='" + shift + "'";
		}
		if (!confirm.equals("")) {
			sql += " AND T3.MATCONFIRM ='" + confirm + "'";
		}
		// if (!starts.equals("")) {
		// sql += " AND T.ZY_BILL_STATUS='" + starts + "'";
		// }
		sql1 = sql1.replace("#SOMETHING#", sql);
		return this.getData(sql1);
	}

	/**
	 * 查询入库实绩
	 */
	public CoreReturnObject getphosInResult(ArrayList<String> list1,
			String[] starts) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("PhosphateResultService.getphosInResult");
		String woid = list1.get(0);
		String plnNo = list1.get(1);
		String judgeNo = list1.get(2);
		String sql1 = "";
		if (!woid.equals("")) {
			sql1 += " AND T1.WO_ID ='" + woid + "'";
		}
		if (!plnNo.equals("")) {
			sql1 += " AND T1.HEAT_PLAN_NO ='" + plnNo + "'";
		}
		if (!judgeNo.equals("")) {
			sql1 += " AND T1.JUDGE_STOVE_NO ='" + judgeNo + "'";
		}
		if (starts.length > 0) {
			sql1 += CoreConverter.toSqlConditionString("T1.ZY_BILL_STATUS",
					starts);
		}
		sql = sql.replace("#SOMETHING#", sql1);
		return this.getData(sql);
	}

	/**
	 * 新增磷化检测实绩
	 * 
	 * @param con
	 * @param core
	 * @param result
	 * @param list1
	 * @param process
	 * @param pbGx
	 * @param list2
	 * @param seleCount
	 * @param woId
	 * @param flag
	 *            0-不限制切断个数，1-限制切断个数
	 * @return
	 * @throws SQLException
	 */
	public CoreReturnObject addPhosphateResult(Connection con,
			CoreReturnObject core, PhosphateResult result,
			ArrayList<Object> list1, String process, String pbGx,
			ArrayList<Object> list2, String seleCount, String woId, String flag)
			throws SQLException {
		PreparedStatement psta = null;
		ResultSet rs1 = null;
		PreparedStatement ps = null;
		Calendar ca = Calendar.getInstance();
		ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(dt);
		String last = matter.format(ca.getTime()) + " 21:00:00";
		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("PhosphateResultService.ProcessPlan.AddPhosphateResult");// 新增磷化/镀铜实绩
		PreparedStatement patAdd = con.prepareStatement(sqlAdd);
		String addphosp = CoreXmlSqlParsersFactory
				.getSql("PhosphateResultService.AddphorestD");// 新增磷化检验结果表
		PreparedStatement patsphosp = con.prepareStatement(addphosp);

		// 交库数据
		String strMatM = CoreXmlSqlParsersFactory
				.getSql("PhosphateResultService.AddMatM");// 新增接箍材料表
		PreparedStatement pstaMatM = con.prepareStatement(strMatM);
		String strMatButters = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.AddMatButters");// 新增位置表
		PreparedStatement pstaMatButters = con.prepareStatement(strMatButters);

		String strMatDeal = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.AddMatDeal");// 新增交易表
		PreparedStatement pstaMatDeal = con.prepareStatement(strMatDeal);

		String lutime = systime;
		if (PlanService.compareDate(systime, last) == true) {
			if (result.getColShft().equals("3")) {
				ca.add(Calendar.DAY_OF_MONTH, 1);
				lutime = matter.format(ca.getTime()) + " 00:00:01";
			}
		}

		int sjNum = Integer.parseInt(result.getColCount());
		String user = result.getColUser();
		String sqlloading = "";

		String stationStatus = "1";
		// 查询是否结炉
		String sqlcom = "SELECT COUNT(*) COUNT,NVL(MAX(T.STATION_STATUS),0) STATION_STATUS FROM COUPLING_COM_INFO T WHERE T.STATION_CODE = ?  AND T.WO_ID=?";
		psta = con.prepareStatement(sqlcom);
		psta.setString(1, process);
		psta.setString(2, woId);
		rs1 = psta.executeQuery();
		if (rs1.next()) {
			stationStatus = rs1.getString("STATION_STATUS");
		}
		rs1.close();
		psta.close();
		if (stationStatus.equals("2")) {
			core.setV_errMsg("该工单磷化实绩已结炉,不允许此操作!");
			return core;
		}
		// 查询工单信息
		PlnZyJgWorkbillEntity work = CoupLoadingService.getPlanWoId(con, woId,
				PlnZyJgWorkbillEntity.class);
		if (work == null) {
			core.setV_errMsg("未查询到工单信息,请确认!");
			return core;
		}
		if (!work.getZyBillStatus().equals("2")) {
			core.setV_errMsg("工单状态不是生产中,不允许此操作!");
			return core;
		}
		String singleWt = "";
		if (work.getCodeJg().equals("")) {
			core.setV_errMsg("接箍码为空请检查!");
			return core;
		} else {
			// 查询接箍单重
			String sqlloadingWt = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.QuerySingleWt");
			ps = con.prepareStatement(sqlloadingWt);
			ps.setObject(1, work.getCodeJg());
			ResultSet rst = ps.executeQuery();
			if (rst.next()) {
				singleWt = rst.getString("WEIGHT_JG");
			}
			rst.close();
			ps.close();
			if (Double.parseDouble(singleWt) <= 0.0) {
				core.setV_errMsg("接箍单重等于零,请检查!");
				return core;
			}
		}

		String resultNo = doAddResultNo(result.getPlineCode(), "10", result
				.getPlineCode()
				+ "10", con);
		String sqlloading1 = CoreXmlSqlParsersFactory
				.getSql("PhosphateResultService.queryLoadRESULT");// 查询最大实绩编号
		psta = con.prepareStatement(sqlloading1);
		psta.setObject(1, result.getPlineCode());
		psta.setObject(2, "10");
		psta.setObject(3, result.getPlineCode() + "10");
		rs1 = psta.executeQuery();
		if (rs1.next()) {
			resultNo = rs1.getString("RESULT_NO");
		}
		rs1.close();
		psta.close();
		// if (seleCount.equals("1")) {
		for (int i = 0; i < list1.size(); i++) {
			ArrayList<String> list = (ArrayList<String>) list1.get(i);
			String desNo = "";
			sqlloading = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.queryPhosResD");// 获取最大磷化检验结果序号
			psta = con.prepareStatement(sqlloading);
			psta.setObject(1, list.get(0));
			psta.setObject(2, matter1.format(dt));
			psta.setObject(3, resultNo);
			rs1 = psta.executeQuery();
			if (rs1.next()) {
				desNo = rs1.getString("DETAIL_NO");
			}
			rs1.close();
			psta.close();
			// 新增磷化检验结果
			patsphosp.setObject(1, desNo);
			patsphosp.setObject(2, resultNo);
			patsphosp.setObject(3, list.get(1));
			patsphosp.setObject(4, list.get(2));
			patsphosp.setObject(5, list.get(3));
			patsphosp.setObject(6, list.get(4));
			patsphosp.setObject(7, list.get(5));
			patsphosp.setObject(8, list.get(0));
			patsphosp.setObject(9, work.getHeatPlanNo());
			patsphosp.setObject(10, woId);
			patsphosp.addBatch();
			patsphosp.executeBatch();
		}
		// } else {
		// 新增镀铜/磷化实绩
		patAdd.setObject(1, resultNo);
		patAdd.setObject(2, result.getMembranceThick());
		patAdd.setObject(3, list2.get(0));
		patAdd.setObject(4, result.getAntiCorrosion());
		patAdd.setObject(5, result.getReactionTime());
		patAdd.setObject(6, list2.get(1));
		patAdd.setObject(7, result.getProducer());
		patAdd.setObject(8, result.getProducerTime());
		patAdd.setObject(9, result.getColShft());
		patAdd.setObject(10, result.getColGroup());
		patAdd.setObject(11, result.getColUser());
		patAdd.setObject(12, result.getColTime());
		patAdd.setObject(13, result.getPlineCode());
		patAdd.setObject(14, result.getPlanNo());
		patAdd.setObject(15, result.getRemark());
		patAdd.setObject(16, result.getColUser());
		patAdd.setObject(17, result.getCreateTime());
		patAdd.setObject(18, result.getColCount());
		patAdd.setObject(19, result.getColOperator());
		patAdd.setObject(20, list2.get(2));
		patAdd.setObject(21, result.getSprayContent());
		patAdd.setObject(22, result.getSprayCount());
		patAdd.setObject(23, "0");
		patAdd.setObject(24, woId);
		patAdd.setObject(25, work.getPlineName());
		patAdd.setObject(26, work.getJudgeStoveNo());
		patAdd.setObject(27, work.getBatchNo());
		patAdd.addBatch();
		patAdd.executeBatch();

		String storageNo = "";
		String storageAtte = "";
		String storageAtteName = "";
		String storageType = "";
		String storageTypeName = "";
		String managNo = "";
		String managName = "";
		sqlloading = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.queryStorageType");
		psta = con.prepareStatement(sqlloading);
		psta.setObject(1, work.getPlineCode());
		rs1 = psta.executeQuery();
		if (rs1.next()) {
			storageNo = rs1.getString("STORAGE_NO");
			storageAtte = rs1.getString("STORAGE_ATTR");
			storageAtteName = rs1.getString("STORAGE_ATTR_NAME");
			storageType = rs1.getString("STORAGE_TYPE_NO");
			storageTypeName = rs1.getString("STORAGE_TYPE_NAME");
			managNo = rs1.getString("MANAGEMENT_NO");
			managName = rs1.getString("MANAGEMENT_NAME");
		}
		rs1.close();
		psta.close();
		String belongCode = "";
		String belongName = "";
		sqlloading = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.selectBelong");
		psta = con.prepareStatement(sqlloading);
		psta.setObject(1, result.getPlineCode());
		rs1 = psta.executeQuery();
		if (rs1.next()) {
			belongCode = rs1.getString("DEPARTMENT_CODE");
			belongName = rs1.getString("DEPARTMENT_DESC");
		}
		rs1.close();
		psta.close();

		// 判断是否存在该工单已经离线
		String matNo = "";
		double SINGLEWEIGHT = 0;
		sqlloading = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.selectInCount");
		psta = con.prepareStatement(sqlloading);
		psta.setObject(1, work.getJudgeStoveNo());
		psta.setObject(2, work.getBatchNo());
		psta.setObject(3, work.getWoId());
		rs1 = psta.executeQuery();
		if (rs1.next()) {
			matNo = rs1.getString("Mat_No");
			SINGLEWEIGHT = rs1.getDouble("SINGLEWEIGHT");
		}
		rs1.close();
		psta.close();
		// 获取交易单号
		String dealOrde = doAddDealOrde("IA", "800701", con);
		// 获取材料号
		// String
		if (matNo == null || matNo.equals("")) {
			matNo = doAddMatNo(work.getJudgeStoveNo(), woId, con);
			// 查询锯切个数
			String cutNum = "";
			if (work.getIfsplit().equals("1")) {
				String sqlloadingOff = CoreXmlSqlParsersFactory
						.getSql("FrmInLibrary.QueryOffCut");// 查询委外返线个数
				psta = con.prepareStatement(sqlloadingOff);
				psta.setObject(1, woId);
				rs1 = psta.executeQuery();
				while (rs1.next()) {
					cutNum = rs1.getString("INCISION_NUM");
				}
				rs1.close();
				psta.close();
			} else {

				sqlloading1 = CoreXmlSqlParsersFactory
						.getSql("FrmInLibrary.queryCutPieces");// 锯切个数
				psta = con.prepareStatement(sqlloading1);
				psta.setObject(1, woId);
				rs1 = psta.executeQuery();
				while (rs1.next()) {
					cutNum = rs1.getString("PRO_NUM");
				}
				rs1.close();
				psta.close();
			}

			// 查询磷化个数
			String phosNum = "";
			sqlloading1 = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.queryPhosPieces");// 磷化个数
			psta = con.prepareStatement(sqlloading1);
			psta.setObject(1, woId);
			rs1 = psta.executeQuery();
			while (rs1.next()) {
				phosNum = rs1.getString("PRO_NUM");
			}
			rs1.close();
			psta.close();
			if (flag.equals("0")) {
				phosNum = result.getColCount();
			}
			if (Integer.parseInt(cutNum) >= Integer.parseInt(phosNum)
					+ Integer.parseInt(result.getColCount())
					|| flag.equals("0")) {
				// 新增材料表
				pstaMatM.setObject(1, woId);
				pstaMatM.setObject(2, matNo);
				pstaMatM.setObject(3, resultNo);
				pstaMatM.setObject(4, String.valueOf(result.getColCount()));
				if (work.getSingleweight().equals("")) {
					pstaMatM.setObject(5, 0);
				} else {
					pstaMatM.setObject(5, Double.parseDouble(result
							.getColCount())
							* Double.parseDouble(singleWt) / 1000);// 重量
				}
				pstaMatM.setObject(6, lutime);
				pstaMatM.setObject(7, result.getColShft());
				pstaMatM.setObject(8, result.getColGroup());
				pstaMatM.setObject(9, result.getColUser());
				pstaMatM.setObject(10, systime);
				pstaMatM.setObject(11, belongCode);
				pstaMatM.setObject(12, belongName);
				pstaMatM.setObject(13, "00");
				pstaMatM.addBatch();
				pstaMatM.executeBatch();

				// 新增材料从表
				pstaMatButters.setObject(1, matNo);
				pstaMatButters.setObject(2, "0001");
				if (work.getDecision().equals("A")) {
					pstaMatButters.setObject(3, "801402");
					pstaMatButters.setObject(4, "80150201");
				} else {
					pstaMatButters.setObject(3, "801401");
					pstaMatButters.setObject(4, "80150101");
				}

				pstaMatButters.setObject(5, "");
				pstaMatButters.setObject(6, result.getColCount());
				if (work.getSingleweight().equals("")) {
					pstaMatButters.setObject(7, 0);
				} else {
					pstaMatButters.setObject(7, Double.parseDouble(result
							.getColCount())
							* Double.parseDouble(singleWt) / 1000);
				}
				pstaMatButters.setObject(8, "");
				pstaMatButters.setObject(9, "");
				pstaMatButters.setObject(10, "");
				pstaMatButters.setObject(11, storageNo);
				pstaMatButters.setObject(12, storageNo + "10101");
				pstaMatButters.setObject(13, storageAtte);
				pstaMatButters.setObject(14, storageAtteName);
				pstaMatButters.setObject(15, storageType);
				pstaMatButters.setObject(16, storageTypeName);
				pstaMatButters.setObject(17, managNo);
				pstaMatButters.setObject(18, managName);
				pstaMatButters.setObject(19, "");
				pstaMatButters.setObject(20, result.getColUser());
				pstaMatButters.setObject(21, systime);
				pstaMatButters.setObject(22, "0");
				pstaMatButters.setObject(23, "");
				pstaMatButters.setObject(24, dealOrde);
				pstaMatButters.setObject(25, work.getLatheGrpNo());
				pstaMatButters.setObject(26, work.getLatheGrpNm());
				pstaMatButters.setObject(27, "B00002");
				pstaMatButters.addBatch();
				pstaMatButters.executeBatch();

				// 新增交易表
				pstaMatDeal.setObject(1, managNo);// 作业科室编码
				pstaMatDeal.setObject(2, managName);
				pstaMatDeal.setObject(3, "");
				pstaMatDeal.setObject(4, matNo);
				pstaMatDeal.setObject(5, resultNo);
				pstaMatDeal.setObject(6, "");
				pstaMatDeal.setObject(7, work.getMinD());
				pstaMatDeal.setObject(8, work.getMinH());
				pstaMatDeal.setObject(9, work.getDiameterJg());
				pstaMatDeal.setObject(10, work.getHeightJg());
				pstaMatDeal.setObject(11, work.getDiameter());
				pstaMatDeal.setObject(12, work.getCheckJVal());
				pstaMatDeal.setObject(13, work.getLengthJg());
				pstaMatDeal.setObject(14, "");// 监制人
				pstaMatDeal.setObject(15, "");// 监制时间
				pstaMatDeal.setObject(16, result.getColCount());
				pstaMatDeal.setObject(17, Integer
						.parseInt(result.getColCount())
						* Double.parseDouble(singleWt) / 1000);// 重量
				pstaMatDeal.setObject(18, lutime);
				pstaMatDeal.setObject(19, storageNo);
				pstaMatDeal.setObject(20, storageNo + "10101");
				pstaMatDeal.setObject(21, storageAtte);
				pstaMatDeal.setObject(22, storageAtteName);
				pstaMatDeal.setObject(23, storageType);
				pstaMatDeal.setObject(24, storageTypeName);
				pstaMatDeal.setObject(25, "");
				pstaMatDeal.setObject(26, result.getColUser());
				pstaMatDeal.setObject(27, systime);
				pstaMatDeal.setObject(28, "");
				pstaMatDeal.setObject(29, dealOrde);
				pstaMatDeal.setObject(30, systime);
				pstaMatDeal.setObject(31, "00");
				pstaMatDeal.setObject(32, "0001");
				pstaMatDeal.setObject(33, woId);
				pstaMatDeal.addBatch();
				pstaMatDeal.executeBatch();

			} else {
				core.setV_errMsg("磷化个数不能大于锯切个数!");
				return core;
			}

		} else {
			// 查询锯切个数
			String cutNum = "";

			if (work.getIfsplit().equals("1")) {
				String sqlloadingOff = CoreXmlSqlParsersFactory
						.getSql("FrmInLibrary.QueryOffCut");// 查询委外返线个数
				psta = con.prepareStatement(sqlloadingOff);
				psta.setObject(1, woId);
				rs1 = psta.executeQuery();
				while (rs1.next()) {
					cutNum = rs1.getString("INCISION_NUM");
				}
				rs1.close();
				psta.close();
			} else {

				sqlloading1 = CoreXmlSqlParsersFactory
						.getSql("FrmInLibrary.queryCutPieces");// 锯切个数
				psta = con.prepareStatement(sqlloading1);
				psta.setObject(1, woId);
				rs1 = psta.executeQuery();
				while (rs1.next()) {
					cutNum = rs1.getString("PRO_NUM");
				}
				rs1.close();
				psta.close();
			}
			// 查询磷化个数
			String phosNum = "";
			sqlloading1 = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.queryPhosPieces");// 磷化个数
			psta = con.prepareStatement(sqlloading1);
			psta.setObject(1, woId);
			rs1 = psta.executeQuery();
			while (rs1.next()) {
				phosNum = rs1.getString("PRO_NUM");
			}
			rs1.close();
			psta.close();
			if (Integer.parseInt(cutNum) >= Integer.parseInt(phosNum)
					+ Integer.parseInt(result.getColCount())
					|| flag.equals("0")) {
				// 修改接箍库存表
				String updateMat = "UPDATE COUPLING_MAT_M T SET T.PRO_NUM=TO_NUMBER(T.PRO_NUM)+TO_NUMBER(?),T.PRO_WT=TO_NUMBER(T.PRO_WT)+TO_NUMBER(?) WHERE T.MAT_NO=?";
				psta = con.prepareStatement(updateMat);
				psta.setObject(1, result.getColCount());
				psta.setObject(2, (SINGLEWEIGHT / 1000)
						* Integer.parseInt(result.getColCount()));
				psta.setObject(3, matNo);
				psta.executeUpdate();
				psta.close();
				// 修改接箍位置表
				String updateMatBut = " UPDATE COUPLING_MAT_BUTTRESS T SET T.PIECES=TO_NUMBER(T.PIECES)+TO_NUMBER(?),T.WEIGHT=TO_NUMBER(T.WEIGHT)+TO_NUMBER(?) WHERE T.MAT_NO=?";
				psta = con.prepareStatement(updateMatBut);
				psta.setObject(1, result.getColCount());
				psta.setObject(2, (SINGLEWEIGHT / 1000)
						* Integer.parseInt(result.getColCount()));
				psta.setObject(3, matNo);
				psta.executeUpdate();
				psta.close();

				// 修改接箍库交易表
				String updateMatDeal = "UPDATE COUPLING_MAT_DEAL T SET T.DEAL_NUM=TO_NUMBER(T.DEAL_NUM)+TO_NUMBER(?),T.DEAL_WT=TO_NUMBER(T.DEAL_WT)+TO_NUMBER(?) WHERE T.MAT_NO=? AND T.DEAL_TYPE_CODE = '800701'";
				psta = con.prepareStatement(updateMatDeal);
				psta.setObject(1, result.getColCount());
				psta.setObject(2, (SINGLEWEIGHT / 1000)
						* Integer.parseInt(result.getColCount()));
				psta.setObject(3, matNo);
				psta.executeUpdate();
				psta.close();

			} else {
				core.setV_errMsg("磷化个数不能大于锯切个数!");
				return core;
			}
		}
		String strPln = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.UpdateJGPln");// 修改计划表支数
		PreparedStatement pstaPln = con.prepareStatement(strPln);
		pstaPln.setObject(1, String.valueOf(sjNum));
		if (work.getSingleweight().equals("")) {
			pstaPln.setObject(2, 0);
		} else {
			pstaPln.setObject(2, sjNum * Double.parseDouble(singleWt) / 1000);// 重量
		}
		pstaPln.setObject(3, woId);
		pstaPln.addBatch();
		pstaPln.executeBatch();
		// 查询工单对应接箍成品合同
		List<PlnOrderJgEntity> orderJg = FrmInLibrary
				.getQureyCpOrder(con, woId);
		if (orderJg == null) {
			core.setV_errMsg("未找到接箍对应成品合同!");
			return core;
		}
		// 对应只有一个成品合同
		int num = 0;
		int orderNum = 0;
		for (PlnOrderJgEntity order : orderJg) {
			int count = 0;
			// 查询是否存在对应接箍工单详情
			String sqlMidd = "SELECT  COUNT(*) COUNT FROM PLN_ZY_JG_MIDDLE T WHERE T.WO_ID=? AND T.ORD_LN_DLY_PK=?  AND T.MAT_NO=? AND T.STATUS='0'";
			ps = con.prepareStatement(sqlMidd);
			ps.setObject(1, woId);
			ps.setObject(2, order.getOrdLnDlyPk());
			ps.setObject(3, matNo);
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				count = rs.getInt("COUNT");
			}
			rs.close();
			ps.close();

			if (orderJg.size() == 1) {
				if (count == 0) {
					// 新增接箍工单详细表
					String addPlnMidd = CoreXmlSqlParsersFactory
							.getSql("FrmInLibrary.AddPlnZyJgMidd");
					ps = con.prepareStatement(addPlnMidd);
					ps.setObject(1, order.getJgOrderno());
					ps.setObject(2, sjNum);
					ps
							.setObject(3, sjNum * Double.parseDouble(singleWt)
									/ 1000);
					ps.setObject(4, "");
					ps.setObject(5, user);
					ps.setObject(6, order.getOrderNo());
					ps.setObject(7, order.getOrderSeq());
					ps.setObject(8, order.getDeliveryNo());
					ps.setObject(9, order.getOrdLnDlyPk().substring(0,
							order.getOrdLnDlyPk().length() - 6));
					ps.setObject(10, order.getOrdLnDlyPk().substring(0,
							order.getOrdLnDlyPk().length() - 3));
					ps.setObject(11, order.getOrdLnDlyPk());
					ps.setObject(12, matNo);
					ps.setObject(13, order.getCraftSeq());
					ps.setObject(14, order.getCraftFileNo());
					ps.setObject(15, "0001");
					ps.setObject(16, woId);
					ps.executeUpdate();
					ps.close();
					
					// 新增接箍工单详细表(送判用)
					String addPlnMiddSp = CoreXmlSqlParsersFactory
							.getSql("FrmInLibrary.AddPlnZyJgMiddSp");
					ps = con.prepareStatement(addPlnMiddSp);
					ps.setObject(1, order.getJgOrderno());
					ps.setObject(2, sjNum);
					ps
							.setObject(3, sjNum * Double.parseDouble(singleWt)
									/ 1000);
					ps.setObject(4, "");
					ps.setObject(5, user);
					ps.setObject(6, order.getOrderNo());
					ps.setObject(7, order.getOrderSeq());
					ps.setObject(8, order.getDeliveryNo());
					ps.setObject(9, order.getOrdLnDlyPk().substring(0,
							order.getOrdLnDlyPk().length() - 6));
					ps.setObject(10, order.getOrdLnDlyPk().substring(0,
							order.getOrdLnDlyPk().length() - 3));
					ps.setObject(11, order.getOrdLnDlyPk());
					ps.setObject(12, matNo);
					ps.setObject(13, order.getCraftSeq());
					ps.setObject(14, order.getCraftFileNo());
					ps.setObject(15, "0001");
					ps.setObject(16, woId);
					ps.executeUpdate();
					ps.close();
				} else {
					// 修改接箍工单详情表
					String updateMidd = CoreXmlSqlParsersFactory
							.getSql("FrmInLibrary.updatePlnZyJgMidd");
					ps = con.prepareStatement(updateMidd);
					ps.setObject(1, sjNum);
					ps
							.setObject(2, sjNum * Double.parseDouble(singleWt)
									/ 1000);
					ps.setObject(3, woId);
					ps.setObject(4, order.getOrdLnDlyPk());
					ps.setObject(5, matNo);
					ps.setObject(6, "0001");
					ps.executeUpdate();
					ps.close();
					
				}
				// 修改接箍合同已挂个数
				String updateOrderJ = "UPDATE PLN_ORDER_JG T SET T.HANGKC_NUM=TO_NUMBER(NVL(T.HANGKC_NUM,0))+TO_NUMBER(?) WHERE T.JG_ORDERNO=?";
				ps = con.prepareStatement(updateOrderJ);
				ps.setObject(1, sjNum);
				ps.setObject(2, order.getJgOrderno());
				ps.executeUpdate();
				ps.close();
			} else {
				orderNum = (int) (Integer.parseInt(order.getOrdernum()) * (1 + 0.03));
				num = orderNum - Integer.parseInt(order.getHangkcNum());
				if (num <= 0) {
					continue;
				}
				if (sjNum <= 0) {
					continue;
				}
				if (sjNum - num < 0) {
					if (count == 0) {
						// 新增接箍工单详细表
						String addPlnMidd = CoreXmlSqlParsersFactory
								.getSql("FrmInLibrary.AddPlnZyJgMidd");
						ps = con.prepareStatement(addPlnMidd);
						ps.setObject(1, order.getJgOrderno());
						ps.setObject(2, sjNum);
						ps.setObject(3, sjNum * Double.parseDouble(singleWt)
								/ 1000);
						ps.setObject(4, "");
						ps.setObject(5, user);
						ps.setObject(6, order.getOrderNo());
						ps.setObject(7, order.getOrderSeq());
						ps.setObject(8, order.getDeliveryNo());
						ps.setObject(9, order.getOrdLnDlyPk().substring(0,
								order.getOrdLnDlyPk().length() - 6));
						ps.setObject(10, order.getOrdLnDlyPk().substring(0,
								order.getOrdLnDlyPk().length() - 3));
						ps.setObject(11, order.getOrdLnDlyPk());
						ps.setObject(12, matNo);
						ps.setObject(13, order.getCraftSeq());
						ps.setObject(14, order.getCraftFileNo());
						ps.setObject(15, "0001");
						ps.setObject(16, woId);
						ps.executeUpdate();
						ps.close();
						
						// 新增接箍工单详细表(送判用)
						String addPlnMiddSp = CoreXmlSqlParsersFactory
								.getSql("FrmInLibrary.AddPlnZyJgMiddSp");
						ps = con.prepareStatement(addPlnMiddSp);
						ps.setObject(1, order.getJgOrderno());
						ps.setObject(2, sjNum);
						ps.setObject(3, sjNum * Double.parseDouble(singleWt)
								/ 1000);
						ps.setObject(4, "");
						ps.setObject(5, user);
						ps.setObject(6, order.getOrderNo());
						ps.setObject(7, order.getOrderSeq());
						ps.setObject(8, order.getDeliveryNo());
						ps.setObject(9, order.getOrdLnDlyPk().substring(0,
								order.getOrdLnDlyPk().length() - 6));
						ps.setObject(10, order.getOrdLnDlyPk().substring(0,
								order.getOrdLnDlyPk().length() - 3));
						ps.setObject(11, order.getOrdLnDlyPk());
						ps.setObject(12, matNo);
						ps.setObject(13, order.getCraftSeq());
						ps.setObject(14, order.getCraftFileNo());
						ps.setObject(15, "0001");
						ps.setObject(16, woId);
						ps.executeUpdate();
						ps.close();
					} else {
						// 修改接箍工单详情表
						String updateMidd = CoreXmlSqlParsersFactory
								.getSql("FrmInLibrary.updatePlnZyJgMidd");
						ps = con.prepareStatement(updateMidd);
						ps.setObject(1, sjNum);
						ps.setObject(2, sjNum * Double.parseDouble(singleWt)
								/ 1000);
						ps.setObject(3, woId);
						ps.setObject(4, order.getOrdLnDlyPk());
						ps.setObject(5, matNo);
						ps.setObject(6, "0001");
						ps.executeUpdate();
						ps.close();
					}
					// 修改接箍合同已挂个数
					String updateOrderJ = "UPDATE PLN_ORDER_JG T SET T.HANGKC_NUM=TO_NUMBER(NVL(T.HANGKC_NUM,0))+TO_NUMBER(?) WHERE T.JG_ORDERNO=?";
					ps = con.prepareStatement(updateOrderJ);
					ps.setObject(1, sjNum);
					ps.setObject(2, order.getJgOrderno());
					ps.executeUpdate();
					ps.close();
					break;
				} else {
					if (count == 0) {
						// 新增接箍工单详细表
						String addPlnMidd = CoreXmlSqlParsersFactory
								.getSql("FrmInLibrary.AddPlnZyJgMidd");
						ps = con.prepareStatement(addPlnMidd);
						ps.setObject(1, order.getJgOrderno());
						ps.setObject(2, num);
						ps.setObject(3, num * Double.parseDouble(singleWt));
						ps.setObject(4, "");
						ps.setObject(5, user);
						ps.setObject(6, order.getOrderNo());
						ps.setObject(7, order.getOrderSeq());
						ps.setObject(8, order.getDeliveryNo());
						ps.setObject(9, order.getOrdLnDlyPk().substring(0,
								order.getOrdLnDlyPk().length() - 6));
						ps.setObject(10, order.getOrdLnDlyPk().substring(0,
								order.getOrdLnDlyPk().length() - 3));
						ps.setObject(11, order.getOrdLnDlyPk());
						ps.setObject(12, matNo);
						ps.setObject(13, order.getCraftSeq());
						ps.setObject(14, order.getCraftFileNo());
						ps.setObject(15, "0001");
						ps.setObject(16, woId);
						ps.executeUpdate();
						ps.close();
						
						// 新增接箍工单详细表(送判用)
						String addPlnMiddSp = CoreXmlSqlParsersFactory
								.getSql("FrmInLibrary.AddPlnZyJgMiddSp");
						ps = con.prepareStatement(addPlnMiddSp);
						ps.setObject(1, order.getJgOrderno());
						ps.setObject(2, num);
						ps.setObject(3, num * Double.parseDouble(singleWt));
						ps.setObject(4, "");
						ps.setObject(5, user);
						ps.setObject(6, order.getOrderNo());
						ps.setObject(7, order.getOrderSeq());
						ps.setObject(8, order.getDeliveryNo());
						ps.setObject(9, order.getOrdLnDlyPk().substring(0,
								order.getOrdLnDlyPk().length() - 6));
						ps.setObject(10, order.getOrdLnDlyPk().substring(0,
								order.getOrdLnDlyPk().length() - 3));
						ps.setObject(11, order.getOrdLnDlyPk());
						ps.setObject(12, matNo);
						ps.setObject(13, order.getCraftSeq());
						ps.setObject(14, order.getCraftFileNo());
						ps.setObject(15, "0001");
						ps.setObject(16, woId);
						ps.executeUpdate();
						ps.close();
					} else {
						// 修改接箍工单详情表
						String updateMidd = CoreXmlSqlParsersFactory
								.getSql("FrmInLibrary.updatePlnZyJgMidd");
						ps = con.prepareStatement(updateMidd);
						ps.setObject(1, sjNum);
						ps.setObject(2, sjNum * Double.parseDouble(singleWt)
								/ 1000);
						ps.setObject(3, woId);
						ps.setObject(4, order.getOrdLnDlyPk());
						ps.setObject(5, matNo);
						ps.setObject(6, "0001");
						ps.executeUpdate();
						ps.close();

					}
					// 修改接箍合同已挂个数
					String updateOrderJ = "UPDATE PLN_ORDER_JG T SET T.HANGKC_NUM=TO_NUMBER(NVL(T.HANGKC_NUM,0))+TO_NUMBER(?) WHERE T.JG_ORDERNO=?";
					ps = con.prepareStatement(updateOrderJ);
					ps.setObject(1, orderNum);
					ps.setObject(2, order.getJgOrderno());
					ps.executeUpdate();
					ps.close();
				}
				sjNum = sjNum - num;
			}

		}

		int count = 0;
		// 查询是否存在对应接箍工单详情
		String sqlMidd = "SELECT  COUNT(*) COUNT FROM PLN_ZY_JG_MIDDLE T WHERE T.WO_ID=? AND T.MAT_NO=? AND T.STATUS='0'";
		ps = con.prepareStatement(sqlMidd);
		ps.setObject(1, woId);
		ps.setObject(2, matNo);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		if (count == 0) {
			core.setV_errMsg("详细表无数据请检查!");
			return core;
		}

		CouplingComInfoEntity comInfo = new CouplingComInfoEntity();
		// 新增接箍公共信息
		comInfo.setResultNo(resultNo);
		comInfo.setWoId(work.getWoId());
		comInfo.setJudgeStoveNo(work.getJudgeStoveNo());
		comInfo.setProPlanId("");
		comInfo.setCodeJgBl(work.getCodeJgBl());
		comInfo.setIfOutRpo("0");
		comInfo.setPlineCode(work.getPlineCode());
		comInfo.setPlineName(work.getPlineName());
		comInfo.setStationCode("700310");
		comInfo.setStationDesc("磷化或镀铜");
		comInfo.setBatchNo(work.getBatchNo());
		comInfo.setBlWlId(work.getBlWlId());
		comInfo.setBlWlDesc(work.getBlWlDesc());
		comInfo.setMinD(work.getMinD());
		comInfo.setMinH(work.getMinH());
		comInfo.setAimlengthBl(work.getAimlengthBl());
		comInfo.setAimCutLen(work.getAimCutLen());
		comInfo.setLengthMax(work.getLengthMax());
		comInfo.setLengthMin(work.getLengthMin());
		comInfo.setTaper(work.getTaper());
		comInfo.setCodeJg(work.getCodeJg());
		comInfo.setGradecode(work.getGradecode());
		comInfo.setGradename(work.getGradename());
		comInfo.setSteelcode(work.getSteelcode());
		comInfo.setSteelname(work.getSteelname());
		comInfo.setModelCode(work.getModelCode());
		comInfo.setModelDesc(work.getModelDesc());
		comInfo.setOutdiameter(work.getDiameterJg());
		comInfo.setWallthick(work.getHeightJg());
		comInfo.setSpecJg(work.getSpecJg());
		comInfo.setSpecJgDesc(work.getSpecJgDesc());
		comInfo.setProduccodeJg(work.getProduccodeJg());
		comInfo.setProduccodeJgDesc(work.getProduccodeJgDesc());
		comInfo.setStdStyle(work.getStdStyle());
		comInfo.setStdStyleDesc(work.getStdStyleDesc());
		comInfo.setStdCode(work.getStdCode());
		comInfo.setStdName(work.getStdName());
		comInfo.setStyleJg(work.getStyleJg());
		comInfo.setDiameter(work.getDiameter());
		comInfo.setCheckJVal(work.getCheckJVal());
		comInfo.setAimlength(work.getLengthJg());
		comInfo.setSingleweight(work.getSingleweight());
		comInfo.setIfMonitorJg(work.getIfMonitorJg());
		comInfo.setPrdcrNo(work.getPrdcrNo());
		comInfo.setMachNo("");
		comInfo.setMachNm("");
		comInfo.setProNum(result.getColCount());
		comInfo.setProWt(String.valueOf(Integer.parseInt(result.getColCount())
				* Double.parseDouble(singleWt) / 1000));
		comInfo.setFailNum("0");
		comInfo.setFailWt("0");
		comInfo.setRroTime(lutime);
		comInfo.setProUser(result.getColUser());
		comInfo.setProShift(result.getColShft());
		comInfo.setProGroup(result.getColGroup());
		comInfo.setIfAllOutWork(work.getIfAllOutWork());
		comInfo.setCreateTime(systime);
		if (result.getColOperator() == null) {
			comInfo.setColOperator("");
		} else {
			comInfo.setColOperator(result.getColOperator());
		}

		comInfo.setOutwlId(work.getOutwlId());
		comInfo.setOutwlDesc(work.getOutwlDesc());
		comInfo.setStationStatus("1");
		// 新增接箍公共记录
		String addInfo = EntityTool.fillSqlByEntity(CoreXmlSqlParsersFactory
				.getSql("CoupLoadingService.AddPlnInfo"), comInfo);
		psta = con.prepareStatement(addInfo);
		psta.executeUpdate();
		psta.close();
		String sprayFlag = "0";// 喷标
		if (list2.get(2).equals("1")) {
			sprayFlag = "1";
			// 新增接箍公共信息
			comInfo.setResultNo(resultNo);
			comInfo.setWoId(work.getWoId());
			comInfo.setJudgeStoveNo(work.getJudgeStoveNo());
			comInfo.setProPlanId("");
			comInfo.setCodeJgBl(work.getCodeJgBl());
			comInfo.setIfOutRpo("0");
			comInfo.setPlineCode(work.getPlineCode());
			comInfo.setPlineName(work.getPlineName());
			comInfo.setStationCode(pbGx);
			comInfo.setStationDesc("喷标");
			comInfo.setBatchNo(work.getBatchNo());
			comInfo.setBlWlId(work.getBlWlId());
			comInfo.setBlWlDesc(work.getBlWlDesc());
			comInfo.setMinD(work.getMinD());
			comInfo.setMinH(work.getMinH());
			comInfo.setAimlengthBl(work.getAimlengthBl());
			comInfo.setAimCutLen(work.getAimCutLen());
			comInfo.setLengthMax(work.getLengthMax());
			comInfo.setLengthMin(work.getLengthMin());
			comInfo.setTaper(work.getTaper());
			comInfo.setCodeJg(work.getCodeJg());
			comInfo.setGradecode(work.getGradecode());
			comInfo.setGradename(work.getGradename());
			comInfo.setSteelcode(work.getSteelcode());
			comInfo.setSteelname(work.getSteelname());
			comInfo.setModelCode(work.getModelCode());
			comInfo.setModelDesc(work.getModelDesc());
			comInfo.setOutdiameter(work.getDiameterJg());
			comInfo.setWallthick(work.getHeightJg());
			comInfo.setSpecJg(work.getSpecJg());
			comInfo.setSpecJgDesc(work.getSpecJgDesc());
			comInfo.setProduccodeJg(work.getProduccodeJg());
			comInfo.setProduccodeJgDesc(work.getProduccodeJgDesc());
			comInfo.setStdStyle(work.getStdStyle());
			comInfo.setStdStyleDesc(work.getStdStyleDesc());
			comInfo.setStdCode(work.getStdCode());
			comInfo.setStdName(work.getStdName());
			comInfo.setStyleJg(work.getStyleJg());
			comInfo.setDiameter(work.getDiameter());
			comInfo.setCheckJVal(work.getCheckJVal());
			comInfo.setAimlength(work.getLengthJg());
			comInfo.setSingleweight(work.getSingleweight());
			comInfo.setIfMonitorJg(work.getIfMonitorJg());
			comInfo.setPrdcrNo(work.getPrdcrNo());
			comInfo.setMachNo("");
			comInfo.setMachNm("");
			comInfo.setProNum(result.getSprayCount());
			comInfo.setProWt(String.valueOf(Integer.parseInt(result
					.getSprayCount())
					* Double.parseDouble(singleWt) / 1000));
			comInfo.setFailNum("0");
			comInfo.setFailWt("0");
			comInfo.setRroTime(lutime);
			comInfo.setProUser(result.getColUser());
			comInfo.setProShift(result.getColShft());
			comInfo.setProGroup(result.getColGroup());
			comInfo.setIfAllOutWork(work.getIfAllOutWork());
			comInfo.setCreateTime(systime);
			comInfo.setColOperator(result.getColOperator());
			comInfo.setOutwlId(work.getOutwlId());
			comInfo.setOutwlDesc(work.getOutwlDesc());
			comInfo.setStationStatus("1");

			// 新增接箍公共记录
			addInfo = EntityTool.fillSqlByEntity(CoreXmlSqlParsersFactory
					.getSql("CoupLoadingService.AddPlnInfo"), comInfo);
			psta = con.prepareStatement(addInfo);
			psta.executeUpdate();
			psta.close();
		}
		return core;
	}

	/**
	 * 新增磷化检测实绩
	 * 
	 * @param result
	 *            磷化检测实绩
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject addPhosphateResult(PhosphateResult result,
			ArrayList<Object> list1, String process, String pbGx,
			ArrayList<Object> list2, String seleCount, String woId) {
		CoreReturnObject core = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();

		try {
			con.setAutoCommit(false); // 取消自动提交事务
			core = addPhosphateResult(con, core, result, list1, process, pbGx,
					list2, seleCount, woId, "1");
			if (core.getV_errMsg().equals("")) {
				core.setV_errMsg("新增成功！");
				core.setResult(1);
				con.commit();
			} else {
				return core;
			}

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

	/***
	 * 确认
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject getConfirm(ArrayList<ArrayList<String>> list1) {
		CoreReturnObject core = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs1 = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM",
				Locale.CHINA);
		String systime = dateFormat.format(now);
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String sqlDelete = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.getConfirm");// 修改是否确认字段
			PreparedStatement patDelete = con.prepareStatement(sqlDelete);

			for (int i = 0; i < list1.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) list1.get(i);
				String resNo = list.get(0);
				String user = list.get(1);
				String time = list.get(2);
				// 修改磷化实绩确认按钮
				patDelete.setObject(1, user);
				patDelete.setObject(2, time);
				patDelete.setObject(3, resNo);
				patDelete.addBatch();

			}
			patDelete.executeBatch();
			core.setV_errMsg("确认成功!");
			core.setResult(1);
			con.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (con != null) {
				try {
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/***
	 * 取消确认
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject getCancelConfirm(ArrayList<ArrayList<String>> list1) {
		CoreReturnObject core = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs1 = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM",
				Locale.CHINA);
		String systime = dateFormat.format(now);
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String sqlDelete = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.getCancelConfirm");// 修改是否确认字段
			PreparedStatement patDelete = con.prepareStatement(sqlDelete);

			for (int i = 0; i < list1.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) list1.get(i);
				String resNo = list.get(0);
				String user = list.get(1);
				String time = list.get(2);
				// 修改磷化实绩确认按钮
				patDelete.setObject(1, user);
				patDelete.setObject(2, time);
				patDelete.setObject(3, resNo);
				patDelete.addBatch();
				patDelete.executeBatch();
			}
			core.setV_errMsg("取消确认成功!");
			core.setResult(1);
			con.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (con != null) {
				try {
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/***
	 * 确认入库信息
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject getMatConfirm(ArrayList<ArrayList<String>> list1) {
		CoreReturnObject core = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs1 = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM",
				Locale.CHINA);
		String systime = dateFormat.format(now);
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String sqlDelete = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.getMatConfirm");// 修改是否确认字段
			PreparedStatement patDelete = con.prepareStatement(sqlDelete);

			for (int i = 0; i < list1.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) list1.get(i);
				String resNo = list.get(0);
				String shift = list.get(1);
				String judgeNo = list.get(2);
				String batchNo = list.get(3);
				String confirm = list.get(4);
				String user = list.get(5);
				String time = list.get(6);
				String tim = list.get(7);
				// 修改磷化实绩确认按钮
				patDelete.setObject(1, user);
				patDelete.setObject(2, time);
				patDelete.setObject(3, resNo);
				patDelete.setObject(4, shift);
				patDelete.setObject(5, judgeNo);
				patDelete.setObject(6, batchNo);
				patDelete.setObject(7, confirm);
				patDelete.setObject(8, tim);
				patDelete.addBatch();

			}
			patDelete.executeBatch();
			core.setV_errMsg("确认成功!");
			core.setResult(1);
			con.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (con != null) {
				try {
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/***
	 * 取消确认
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject getCancelMatConfirm(
			ArrayList<ArrayList<String>> list1) {
		CoreReturnObject core = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs1 = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM",
				Locale.CHINA);
		String systime = dateFormat.format(now);
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String sqlDelete = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.getCancelMatConfirm");// 修改是否确认字段
			PreparedStatement patDelete = con.prepareStatement(sqlDelete);

			for (int i = 0; i < list1.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) list1.get(i);
				String resNo = list.get(0);
				String shift = list.get(1);
				String judgeNo = list.get(2);
				String batchNo = list.get(3);
				String confirm = list.get(4);
				String user = list.get(5);
				String time = list.get(6);
				String tim = list.get(7);
				// 修改磷化实绩确认按钮
				patDelete.setObject(1, "");
				patDelete.setObject(2, "");
				patDelete.setObject(3, resNo);
				patDelete.setObject(4, shift);
				patDelete.setObject(5, judgeNo);
				patDelete.setObject(6, batchNo);
				patDelete.setObject(7, confirm);
				patDelete.setObject(8, tim);
				patDelete.addBatch();
				patDelete.executeBatch();
			}
			core.setV_errMsg("取消确认成功!");
			core.setResult(1);
			con.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (con != null) {
				try {
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 离线镀铜，磷化实绩
	 * 
	 * @param result
	 *            镀铜磷化实绩
	 * @return
	 */
	public CoreReturnObject lixianThreadingResult(ArrayList<String> list,
			String latGx, String GxName) {
		CoreReturnObject core = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		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);
		SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
		String systime = dateFormat.format(now);
		String last = date.format(ca.getTime()) + " 21:00:00";
		try {
			con.setAutoCommit(false); // 取消自动提交事务
			String insertResultSql = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.ProcessPlan.lixianThreadingResult");// 离线镀铜磷化实绩
			PreparedStatement insertResultPsta = con
					.prepareStatement(insertResultSql);
			String insertComInfoSql = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.lixianComInfoResult");// 离线ComInfo表
			PreparedStatement insertComInfoPsta = con
					.prepareStatement(insertComInfoSql);
			String insertofflineSql = CoreXmlSqlParsersFactory
					.getSql("CoupCutService.lixianofflineResult");// 离线表
			PreparedStatement insertofflinePsta = con
					.prepareStatement(insertofflineSql);
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.updatelixianofflineResult");// 修改工单工序的离线状态
			PreparedStatement updatePsta = con.prepareStatement(updateSql);
			String lutime = systime;

			String lixian = list.get(0);
			String WoId = list.get(1);
			String heatNo = list.get(2);
			String JudgeNo = list.get(3);
			String BatchNo = list.get(4);
			String PlineCode = list.get(5);
			String PlanName = list.get(6);
			String UserName = list.get(7);
			String bc = list.get(8);
			String bz = list.get(9);
			String time = list.get(10);
			String resultNo = list.get(11);
			String offline = list.get(12);
			String status = list.get(13);

			if (PlanService.compareDate(systime, last) == true) {
				if (bc.equals("3")) {
					ca.add(Calendar.DAY_OF_MONTH, 1);
					lutime = date.format(ca.getTime()) + " 00:00:0 31";
				}
			}
			// // 离线车丝
			// String resultNo = doAddResultNo(PlineCode, con);
			// 离线磷化镀铜
			insertResultPsta.setString(1, lixian);
			insertResultPsta.setString(2, resultNo);
			insertResultPsta.addBatch();

			// 离线磷化
			insertResultPsta.setString(1, lixian);
			insertResultPsta.setString(2, resultNo);
			insertResultPsta.addBatch();
			// 离线公共信息并修改计划车丝
			insertComInfoPsta.setString(1, heatNo);
			insertComInfoPsta.setString(2, "");
			insertComInfoPsta.setString(3, "");
			insertComInfoPsta.setString(4, "");
			insertComInfoPsta.setString(5, "");
			insertComInfoPsta.setString(6, "");
			insertComInfoPsta.setString(7, "");
			insertComInfoPsta.setString(8, "");
			insertComInfoPsta.setString(9, lixian);
			insertComInfoPsta.setString(10, lutime);
			insertComInfoPsta.setString(11, UserName);
			insertComInfoPsta.setString(12, bc);
			insertComInfoPsta.setString(13, bz);
			insertComInfoPsta.setString(14, resultNo);
			insertComInfoPsta.setString(15, "1");
			insertComInfoPsta.setString(16, latGx);
			insertComInfoPsta.setString(17, systime);
			insertComInfoPsta.setString(18, "");
			insertComInfoPsta.setString(19, WoId);
			insertComInfoPsta.addBatch();
			// 新增离线表信息
			insertofflinePsta.setString(1, resultNo);
			insertofflinePsta.setString(2, PlineCode);
			insertofflinePsta.setString(3, WoId);
			insertofflinePsta.setString(4, latGx);
			insertofflinePsta.setString(5, GxName);
			insertofflinePsta.setString(6, JudgeNo);
			insertofflinePsta.setString(7, BatchNo);
			insertofflinePsta.setString(8, lixian);
			insertofflinePsta.setString(9, "");
			insertofflinePsta.setString(10, "1");
			insertofflinePsta.setString(11, "");
			insertofflinePsta.setString(12, "");
			insertofflinePsta.setString(13, lutime);
			insertofflinePsta.setString(14, UserName);
			insertofflinePsta.setString(15, bc);
			insertofflinePsta.setString(16, bz);
			insertofflinePsta.setString(17, lutime);
			insertofflinePsta.setString(18, resultNo);
			insertofflinePsta.addBatch();
			updatePsta.setString(1, WoId);
			updatePsta.addBatch();
			updatePsta.executeBatch();
			insertResultPsta.executeBatch();
			insertComInfoPsta.executeBatch();
			insertofflinePsta.executeBatch();
			core.setV_errMsg("离线成功!");
			con.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (con != null) {
				try {
					core.setV_errMsg(e.getMessage());
					con.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 撤销离线
	 * 
	 * @param result
	 *            磷化检测实绩
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject unlixianThreadingResult(ArrayList<Object> list1,
			ArrayList<String> pram) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqldelete = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.ProcessPlan.lixianThreadingResult");// 修改磷化实绩
			PreparedStatement patdelete = connection
					.prepareStatement(sqldelete);
			String updatePlan = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.unlixianComInfoResult");// 撤销ComInfo表
			PreparedStatement patsUpPlan = connection
					.prepareStatement(updatePlan);
			String addPlnInfo = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.unlixianofflineResult");// 撤销离线表
			PreparedStatement patsPlan = connection
					.prepareStatement(addPlnInfo);
			String deletephosp = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.unupdatelixianofflineResult");// 修改工单表状态
			PreparedStatement patsdelPlan = connection
					.prepareStatement(deletephosp);
			String deletephosp1 = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.unupdatelixianofflineResult2");// 修改工单表状态
			PreparedStatement patsdelPlan1 = connection
					.prepareStatement(deletephosp1);

			String tuc = pram.get(0);
			String isSpray = pram.get(1);
			String woID = pram.get(2);
			// // 查询计划状态
			// int falg = 0;
			// int phfalg = 0;// 磷化状态
			// int cofalg = 0;// 镀铜状态
			// String sqlloading = CoreXmlSqlParsersFactory
			// .getSql("PhosphateResultService.queryPlanJg");
			// psta = connection.prepareStatement(sqlloading);
			// psta.setObject(1, planNo);
			// ResultSet rs1 = psta.executeQuery();
			// if (rs1.next()) {
			// falg = Integer.parseInt(rs1.getString("ZY_PLAN_STATUS"));
			// phfalg = Integer.parseInt(rs1.getString("PHOS_STATUS"));
			// cofalg = Integer.parseInt(rs1.getString("PLT_CU_STATUS"));
			// }
			// rs1.close();
			// psta.close();
			//
			// if (falg != 2) {
			// core.setV_errMsg("该炉次计划号不是生产中的状态,不允许删除！");
			// return core;
			// }
			// if (tuc.equals("0")) {
			// if (phfalg != 1) {
			// core.setV_errMsg("该炉次计划号磷化不是生产中的状态,不允许删除！");
			// return core;
			// }
			// }
			// else {
			// if (cofalg != 1) {
			// core.setV_errMsg("该炉次计划号镀铜不是生产中的状态,不允许删除！");
			// return core;
			// }
			// }
			// 判断删除限制
			for (int i = 0; i < list1.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) list1.get(i);
				String resultNo = list.get(0);
				String offNum = list.get(1);
				// 删除磷化实绩
				patdelete.setObject(1, "-" + offNum);
				patdelete.setObject(2, resultNo);
				patdelete.addBatch();
				// 删除磷化检验结果
				patsUpPlan.setObject(1, resultNo);
				patsUpPlan.setObject(2, woID);
				patsUpPlan.addBatch();
				// 删除接箍公共信息
				patsPlan.setObject(1, resultNo);
				patsPlan.addBatch();
			}
			patsPlan.executeBatch();
			patsUpPlan.executeBatch();
			patdelete.executeBatch();
			String isPray = "";
			if (isSpray.equals("无喷标")) {
				isPray = "2";
			} else if (isSpray.equals("是")) {
				isPray = "1";
			} else {
				isPray = "0";
			}
			int count = 0;
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.queryLodResult2");
			PreparedStatement psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, woID);
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				count = Integer.parseInt(rs1.getString("COUNT"));
			}
			rs1.close();
			psta.close();
			if (count == 0) {
				patsdelPlan.setObject(1, woID);
				patsdelPlan.addBatch();
				patsdelPlan.executeBatch();
			} else {
				patsdelPlan1.setObject(1, woID);
				patsdelPlan1.addBatch();
				patsdelPlan1.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 plineCode
	 * @param connection
	 * @return
	 */
	public String doAddResultNo(String plineCode, String gx, String resultno,
			Connection connection) {
		String resultNo = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
		String sqlloading = CoreXmlSqlParsersFactory
				.getSql("PhosphateResultService.queryLoadRESULT");// 查询最大实绩编号
		try {
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, plineCode);
			psta.setObject(2, gx);
			psta.setObject(3, resultno);
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				resultNo = rs1.getString("RESULT_NO");
			}
			rs1.close();
			psta.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return resultNo;
	}

	/**
	 * 新镀铜检测实绩
	 * 
	 * @param result
	 *            镀铜检测实绩
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject addCopperPlantResult(PhosphateResult result,
			ArrayList<Object> list1, String process, String pbGx,
			ArrayList<Object> list2, String seleCount) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs1 = null;
		Calendar ca = Calendar.getInstance();
		ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(dt);
		String last = matter.format(ca.getTime()) + " 21:00:00";
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.ProcessPlan.AddPhosphateResult");// 新增镀铜实绩
			PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
			String addPlnInfo = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.AddPlnInfo");// 新增接箍公共信息
			PreparedStatement patsPlan = connection
					.prepareStatement(addPlnInfo);
			String addphosp = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.AddphorestD");// 新增镀铜检验结果表
			PreparedStatement patsphosp = connection.prepareStatement(addphosp);
			String lutime = systime;
			if (PlanService.compareDate(systime, last) == true) {
				if (result.getColShft().equals("3")) {
					ca.add(Calendar.DAY_OF_MONTH, 1);
					lutime = matter.format(ca.getTime()) + " 00:00:01";
				}
			}
			// // 查询计划状态
			// int falg = 0;
			// int phfalg = 0;
			// String sqlloading = CoreXmlSqlParsersFactory
			// .getSql("PhosphateResultService.queryPlanJg");
			// psta = connection.prepareStatement(sqlloading);
			// psta.setObject(1, result.getPlanNo());
			// ResultSet rs1 = psta.executeQuery();
			// if (rs1.next()) {
			// falg = Integer.parseInt(rs1.getString("ZY_PLAN_STATUS"));
			// phfalg = Integer.parseInt(rs1.getString("PLT_CU_STATUS"));
			// }
			// rs1.close();
			// psta.close();
			//
			// if (falg != 2) {
			// core.setV_errMsg("该炉次计划号不是生产中的状态,不允许镀铜！");
			// return core;
			// }
			// if (phfalg != 1 && phfalg != 0) {
			// core.setV_errMsg("该炉次计划号镀铜状态不是生产中或计划,不允许镀铜！");
			// return core;
			// }
			// 获取计划实体了
			PlnZyJgEntity pln = PlanService.getSendPlanCInfo(connection, result
					.getPlanNo());
			String resultNo = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.queryLoadRESULT");// 查询最大实绩编号
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, result.getPlineCode());
			psta.setObject(2, matter1.format(dt));
			psta.setObject(3, result.getPlineCode());
			rs1 = psta.executeQuery();
			if (rs1.next()) {
				resultNo = rs1.getString("RESULT_NO");
			}
			rs1.close();
			psta.close();
			if (seleCount.equals("1")) {
				for (int i = 0; i < list1.size(); i++) {
					ArrayList<String> list = (ArrayList<String>) list1.get(i);
					String desNo = "";
					sqlloading = CoreXmlSqlParsersFactory
							.getSql("PhosphateResultService.queryPhosResD");// 获取最大镀铜检验结果序号
					psta = connection.prepareStatement(sqlloading);
					psta.setObject(1, list.get(0));
					psta.setObject(2, matter1.format(dt));
					psta.setObject(3, list.get(7));
					rs1 = psta.executeQuery();
					if (rs1.next()) {
						desNo = rs1.getString("DETAIL_NO");
					}
					rs1.close();
					psta.close();
					// 新增镀铜检验结果
					patsphosp.setObject(1, desNo);
					patsphosp.setObject(2, list.get(7));
					patsphosp.setObject(3, list.get(1));
					patsphosp.setObject(4, list.get(2));
					patsphosp.setObject(5, list.get(3));
					patsphosp.setObject(6, list.get(4));
					patsphosp.setObject(7, list.get(5));
					patsphosp.setObject(8, list.get(0));
					patsphosp.setObject(9, list.get(9));
					patsphosp.setObject(10, list.get(8));
					patsphosp.addBatch();
					patsphosp.executeBatch();
				}
			} else {
				// 新增镀铜实绩
				patAdd.setObject(1, resultNo);
				patAdd.setObject(2, result.getMembranceThick());
				patAdd.setObject(3, list2.get(0));
				patAdd.setObject(4, result.getAntiCorrosion());
				patAdd.setObject(5, result.getReactionTime());
				patAdd.setObject(6, list2.get(1));
				patAdd.setObject(7, result.getProducer());
				patAdd.setObject(8, result.getProducerTime());
				patAdd.setObject(9, result.getColShft());
				patAdd.setObject(10, result.getColGroup());
				patAdd.setObject(11, result.getColUser());
				patAdd.setObject(12, lutime);
				patAdd.setObject(13, result.getPlineCode());
				patAdd.setObject(14, result.getPlanNo());
				patAdd.setObject(15, result.getRemark());
				patAdd.setObject(16, result.getColUser());
				patAdd.setObject(17, systime);
				patAdd.setObject(18, result.getColCount());
				patAdd.setObject(19, result.getColOperator());
				patAdd.setObject(20, list2.get(2));
				patAdd.setObject(21, result.getSprayContent());
				patAdd.setObject(22, result.getSprayCount());
				patAdd.setObject(23, "0");
				patAdd.setObject(24, result.getWoId());
				patAdd.addBatch();
				// 新增接箍公共信息
				patsPlan.setObject(1, pln.getSteelcode());
				patsPlan.setObject(2, pln.getSteelname());
				patsPlan.setObject(3, pln.getModelCode());
				patsPlan.setObject(4, pln.getModelDesc());
				patsPlan.setObject(5, pln.getOutdiameter());
				patsPlan.setObject(6, pln.getWallthick());
				patsPlan.setObject(7, pln.getSpecJg());
				patsPlan.setObject(8, pln.getSpecJgDesc());
				patsPlan.setObject(9, pln.getStyleJg());
				patsPlan.setObject(10, pln.getDiameter());
				patsPlan.setObject(11, pln.getCheckJVal());
				patsPlan.setObject(12, pln.getAimlength());
				patsPlan.setObject(13, pln.getSingleweight());
				patsPlan.setObject(14, pln.getMonitordemand());
				patsPlan.setObject(15, pln.getIfMonitorJg());
				patsPlan.setObject(16, pln.getPrdcrNo());
				patsPlan.setObject(17, result.getProducer());// 监制人
				patsPlan.setObject(18, result.getProducerTime());// 监制到场时间
				patsPlan.setObject(19, pln.getCutMachGrpNo());
				patsPlan.setObject(20, pln.getCutMachGrpNm());
				patsPlan.setObject(21, result.getColCount());
				patsPlan.setObject(22, "");
				patsPlan.setObject(23, "");// 废品重量
				patsPlan.setObject(24, "");// 废品支数
				patsPlan.setObject(25, "");
				patsPlan.setObject(26, "");
				patsPlan.setObject(27, "1");
				patsPlan.setObject(28, lutime);
				patsPlan.setObject(29, "");
				patsPlan.setObject(30, result.getColUser());
				patsPlan.setObject(31, result.getColShft());
				patsPlan.setObject(32, result.getColGroup());
				patsPlan.setObject(33, resultNo);
				patsPlan.setObject(34, pln.getZyPlanId());
				patsPlan.setObject(35, pln.getProPlanId());
				patsPlan.setObject(36, pln.getCodeJgBl());
				patsPlan.setObject(37, pln.getJgGroupId());
				patsPlan.setObject(38, pln.getIfOutCut());
				patsPlan.setObject(39, pln.getPlineCode());
				patsPlan.setObject(40, pln.getPlineName());
				patsPlan.setObject(41, process);
				patsPlan.setObject(42, "镀铜");
				patsPlan.setObject(43, pln.getJudgeStoveNo());
				patsPlan.setObject(44, pln.getBatchNo());
				patsPlan.setObject(45, pln.getBlWlId());
				patsPlan.setObject(46, pln.getBlWlDesc());
				patsPlan.setObject(47, pln.getMinD());
				patsPlan.setObject(48, pln.getMinH());
				patsPlan.setObject(49, pln.getAimlengthBl());
				patsPlan.setObject(50, pln.getAimCutLen());
				patsPlan.setObject(51, pln.getLengthMin());
				patsPlan.setObject(52, pln.getLengthMax());
				patsPlan.setObject(53, pln.getTaper());
				patsPlan.setObject(54, pln.getCodeJg());
				patsPlan.setObject(55, pln.getGradecode());
				patsPlan.setObject(56, pln.getGradename());
				patsPlan.setObject(57, result.getIfAllOutWork());
				patsPlan.setObject(58, systime);
				patsPlan.setObject(59, result.getColOperator());
				patsPlan.setObject(60, result.getWoId());
				patsPlan.addBatch();
				String sprayFlag = "0";
				if (list2.get(2).equals("1")) {
					sprayFlag = "1";
					// 新增接箍公共信息
					patsPlan.setObject(1, pln.getSteelcode());
					patsPlan.setObject(2, pln.getSteelname());
					patsPlan.setObject(3, pln.getModelCode());
					patsPlan.setObject(4, pln.getModelDesc());
					patsPlan.setObject(5, pln.getOutdiameter());
					patsPlan.setObject(6, pln.getWallthick());
					patsPlan.setObject(7, pln.getSpecJg());
					patsPlan.setObject(8, pln.getSpecJgDesc());
					patsPlan.setObject(9, pln.getStyleJg());
					patsPlan.setObject(10, pln.getDiameter());
					patsPlan.setObject(11, pln.getCheckJVal());
					patsPlan.setObject(12, pln.getAimlength());
					patsPlan.setObject(13, pln.getSingleweight());
					patsPlan.setObject(14, pln.getMonitordemand());
					patsPlan.setObject(15, pln.getIfMonitorJg());
					patsPlan.setObject(16, pln.getPrdcrNo());
					patsPlan.setObject(17, result.getProducer());// 监制人
					patsPlan.setObject(18, result.getProducerTime());// 监制到场时间
					patsPlan.setObject(19, pln.getCutMachGrpNo());
					patsPlan.setObject(20, pln.getCutMachGrpNm());
					patsPlan.setObject(21, result.getSprayCount());
					patsPlan.setObject(22, "");
					patsPlan.setObject(23, "");// 废品重量
					patsPlan.setObject(24, "");// 废品支数
					patsPlan.setObject(25, "");
					patsPlan.setObject(26, "");
					patsPlan.setObject(27, "1");
					patsPlan.setObject(28, lutime);
					patsPlan.setObject(29, "");
					patsPlan.setObject(30, result.getColUser());
					patsPlan.setObject(31, result.getColShft());
					patsPlan.setObject(32, result.getColGroup());
					patsPlan.setObject(33, resultNo);
					patsPlan.setObject(34, pln.getZyPlanId());
					patsPlan.setObject(35, pln.getProPlanId());
					patsPlan.setObject(36, pln.getCodeJgBl());
					patsPlan.setObject(37, pln.getJgGroupId());
					patsPlan.setObject(38, pln.getIfOutCut());
					patsPlan.setObject(39, pln.getPlineCode());
					patsPlan.setObject(40, pln.getPlineName());
					patsPlan.setObject(41, pbGx);
					patsPlan.setObject(42, "喷标");
					patsPlan.setObject(43, pln.getJudgeStoveNo());
					patsPlan.setObject(44, pln.getBatchNo());
					patsPlan.setObject(45, pln.getBlWlId());
					patsPlan.setObject(46, pln.getBlWlDesc());
					patsPlan.setObject(47, pln.getMinD());
					patsPlan.setObject(48, pln.getMinH());
					patsPlan.setObject(49, pln.getAimlengthBl());
					patsPlan.setObject(50, pln.getAimCutLen());
					patsPlan.setObject(51, pln.getLengthMin());
					patsPlan.setObject(52, pln.getLengthMax());
					patsPlan.setObject(53, pln.getTaper());
					patsPlan.setObject(54, pln.getCodeJg());
					patsPlan.setObject(55, pln.getGradecode());
					patsPlan.setObject(56, pln.getGradename());
					patsPlan.setObject(57, result.getIfAllOutWork());
					patsPlan.setObject(58, systime);
					patsPlan.setObject(59, result.getColOperator());
					patsPlan.setObject(60, result.getWoId());
					patsPlan.addBatch();
				}

				patAdd.executeBatch();
				patsPlan.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 result
	 *            磷化检测实绩
	 * @return
	 */
	public CoreReturnObject updatePhosphateResult(PhosphateResult result,
			String process, String pbGx, String woId) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.updatePhosphateResult");// 修改磷化镀铜实绩
			PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
			String addPlnInfo = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.UpdatePlnInfo");// 修改接箍公共信息
			PreparedStatement patsPlan = connection
					.prepareStatement(addPlnInfo);

			// 查询工单信息
			PlnZyJgWorkbillEntity work = CoupLoadingService.getPlanWoId(
					connection, woId, PlnZyJgWorkbillEntity.class);
			if (work == null) {
				core.setV_errMsg("未查询到工单信息,请确认!");
				return core;
			}
			if (!work.getZyBillStatus().equals("2")) {
				core.setV_errMsg("工单状态不是生产中,不允许此操作!");
				return core;
			}
			// 修改磷化/镀铜实绩
			patAdd.setObject(1, result.getMembranceThick());
			patAdd.setObject(2, result.getAdhesion());
			patAdd.setObject(3, result.getAntiCorrosion());
			patAdd.setObject(4, result.getReactionTime());
			patAdd.setObject(5, result.getSurfaceCondition());
			patAdd.setObject(6, result.getRemark());
			patAdd.setObject(7, result.getColShft());
			patAdd.setObject(8, result.getColGroup());
			patAdd.setObject(9, result.getColUser());
			patAdd.setObject(10, result.getColTime());
			patAdd.setObject(11, result.getProducer());
			patAdd.setObject(12, result.getProducerTime());
			patAdd.setObject(13, result.getColCount());
			patAdd.setObject(14, result.getColOperator());
			patAdd.setObject(15, result.getSprayContent());
			patAdd.setObject(16, result.getSprayCount());
			patAdd.setObject(17, result.getResultNo());
			patAdd.addBatch();

			// 修改切割公共信息表
			double singlewt = Double.parseDouble(work.getSingleweight());// 接箍单重

			int hgCount = Integer.parseInt(result.getColCount());
			double hgWt = hgCount * singlewt / 1000;
			// 修改公共信息(磷化/镀铜工序点)
			patsPlan.setObject(1, hgCount);
			patsPlan.setObject(2, hgWt);
			patsPlan.setObject(3, "");
			patsPlan.setObject(4, result.getColShft());
			patsPlan.setObject(5, result.getColGroup());
			patsPlan.setObject(6, result.getColOperator());
			patsPlan.setObject(7, result.getProducer());
			patsPlan.setObject(8, result.getProducerTime());
			patsPlan.setObject(9, result.getResultNo());
			patsPlan.setObject(10, process);
			patsPlan.setObject(11, result.getWoId());
			patsPlan.addBatch();

			int spCount = Integer.parseInt(result.getSprayCount());
			double spWt = hgCount * singlewt / 1000;
			// 修改公共信息(喷标工序点)
			patsPlan.setObject(1, spCount);
			patsPlan.setObject(2, spWt);
			patsPlan.setObject(3, "");
			patsPlan.setObject(4, result.getColShft());
			patsPlan.setObject(5, result.getColGroup());
			patsPlan.setObject(6, result.getColOperator());
			patsPlan.setObject(7, result.getProducer());
			patsPlan.setObject(8, result.getProducerTime());
			patsPlan.setObject(9, result.getResultNo());
			patsPlan.setObject(10, pbGx);
			patsPlan.setObject(11, result.getWoId());
			patsPlan.addBatch();
			patAdd.executeBatch();
			patsPlan.executeBatch();

			core.setV_errMsg("修改成功！");
			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 result
	 *            磷化检测实绩
	 * @return
	 */
	public CoreReturnObject updateCopperPlanResult(PhosphateResult result,
			String process, String pbGx) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.updatePhosphateResult");// 修改镀铜实绩
			PreparedStatement patAdd = connection.prepareStatement(sqlAdd);

			String updatePlan = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.UpdaPlanStatus");// 修改工单表镀铜状态
			PreparedStatement patsUpPlan = connection
					.prepareStatement(updatePlan);
			String addPlnInfo = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.UpdatePlnInfo");// 修改接箍公共信息
			PreparedStatement patsPlan = connection
					.prepareStatement(addPlnInfo);
			// // 查询计划状态
			// int falg = 0;
			// int phfalg = 0;
			// String sqlloading = CoreXmlSqlParsersFactory
			// .getSql("PhosphateResultService.queryPlanJg");
			// psta = connection.prepareStatement(sqlloading);
			// psta.setObject(1, result.getPlanNo());
			// ResultSet rs1 = psta.executeQuery();
			// if (rs1.next()) {
			// falg = Integer.parseInt(rs1.getString("ZY_PLAN_STATUS"));
			// phfalg = Integer.parseInt(rs1.getString("PLT_CU_STATUS"));
			// }
			// rs1.close();
			// psta.close();
			//
			// if (falg != 2) {
			// core.setV_errMsg("该炉次计划号不是生产中的状态,不允许修改镀铜！");
			// return core;
			// }
			// if (phfalg != 1) {
			// core.setV_errMsg("该炉次计划号磷化状态不是生产中,不允许修改镀铜！");
			// return core;
			// }
			// 修改镀铜实绩
			patAdd.setObject(1, result.getMembranceThick());
			patAdd.setObject(2, result.getAdhesion());
			patAdd.setObject(3, result.getAntiCorrosion());
			patAdd.setObject(4, result.getReactionTime());
			patAdd.setObject(5, result.getSurfaceCondition());
			patAdd.setObject(6, result.getRemark());
			patAdd.setObject(7, result.getColShft());
			patAdd.setObject(8, result.getColGroup());
			patAdd.setObject(9, result.getColUser());
			patAdd.setObject(10, result.getColTime());
			patAdd.setObject(11, result.getProducer());
			patAdd.setObject(12, result.getProducerTime());
			patAdd.setObject(13, result.getColCount());
			patAdd.setObject(14, result.getColOperator());
			patAdd.setObject(15, result.getSprayContent());
			patAdd.setObject(16, result.getSprayCount());
			patAdd.setObject(17, result.getResultNo());
			patAdd.addBatch();
			// 修改公共信息(镀铜工序点)
			patsPlan.setObject(1, result.getColCount());
			patsPlan.setObject(2, "");
			patsPlan.setObject(3, result.getColShft());
			patsPlan.setObject(4, result.getColGroup());
			patsPlan.setObject(5, result.getColOperator());
			patsPlan.setObject(6, result.getProducer());
			patsPlan.setObject(7, result.getProducerTime());
			patsPlan.setObject(8, result.getResultNo());
			patsPlan.setObject(9, result.getPlanNo());
			patsPlan.setObject(10, process);
			patsPlan.setObject(11, result.getWoId());
			patsPlan.addBatch();
			// 修改公共信息(喷标工序点)
			patsPlan.setObject(1, result.getSprayCount());
			patsPlan.setObject(2, "");
			patsPlan.setObject(3, result.getColShft());
			patsPlan.setObject(4, result.getColGroup());
			patsPlan.setObject(5, result.getColOperator());
			patsPlan.setObject(6, result.getProducer());
			patsPlan.setObject(7, result.getProducerTime());
			patsPlan.setObject(8, result.getResultNo());
			patsPlan.setObject(9, result.getPlanNo());
			patsPlan.setObject(10, pbGx);
			patsPlan.setObject(11, result.getWoId());
			patsPlan.addBatch();
			patAdd.executeBatch();
			patsPlan.executeBatch();
			// 查询同一炉次计划号号下的实绩个数
			String count = "";
			String pbCount = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.queryRests");
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, result.getPlanNo());
			psta.setObject(2, result.getWoId());
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				count = rs1.getString("COL_COUNT");
				pbCount = rs1.getString("SPRAY_COUNT");
			}
			rs1.close();
			psta.close();
			// String sprayFlag = "0";
			// if (result.getIsSpray().equals("是")) {
			// sprayFlag = "1";
			// }
			// else {
			//
			// }

			// 修改炉次计划号状态
			patsUpPlan.setObject(1, "");
			patsUpPlan.setObject(2, pbCount);
			patsUpPlan.setObject(3, count);
			patsUpPlan.setObject(4, result.getPlanNo());
			patsUpPlan.setObject(5, result.getWoId());
			patsUpPlan.addBatch();
			patsUpPlan.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 connection
	 * @param core
	 * @param list1
	 * @param woId
	 * @return
	 * @throws SQLException
	 */
	public CoreReturnObject deletePhosphateResult(Connection connection,
			CoreReturnObject core, ArrayList<Object> list1, String woId)
			throws SQLException {
		PreparedStatement psta = null;
		PreparedStatement ps = null;
		ResultSet rs = null;

		connection.setAutoCommit(false); // 取消自动提交事务
		String sqldelete = CoreXmlSqlParsersFactory
				.getSql("PhosphateResultService.deletePhosphateResult");// 删除磷化实绩
		PreparedStatement patdelete = connection.prepareStatement(sqldelete);
		String addPlnInfo = CoreXmlSqlParsersFactory
				.getSql("PhosphateResultService.deletePlnInfo");// 删除接箍公共信息
		PreparedStatement patsPlan = connection.prepareStatement(addPlnInfo);
		String deletephosp = CoreXmlSqlParsersFactory
				.getSql("PhosphateResultService.DeletephorestD");// 删除磷化检验结果表
		PreparedStatement patsdelPlan = connection
				.prepareStatement(deletephosp);

		String strMatM = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.DeleteMatMDoBeside");// 删除接箍材料表
		PreparedStatement pstaMatM = connection.prepareStatement(strMatM);
		String strMatButters = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.DeleteMatButtersDoBeside");// 删除位置表
		PreparedStatement pstaMatButters = connection
				.prepareStatement(strMatButters);
		String strMatDeal = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.DeleteMatDealFail");// 删除交易表
		PreparedStatement pstaMatDeal = connection.prepareStatement(strMatDeal);

		// 查询工单信息
		PlnZyJgWorkbillEntity work = CoupLoadingService.getPlanWoId(connection,
				woId, PlnZyJgWorkbillEntity.class);
		if (work == null) {
			core.setV_errMsg("未查询到工单信息,请确认!");
			return core;
		}
		if (!work.getZyBillStatus().equals("2")) {
			core.setV_errMsg("工单状态不是生产中,不允许此操作!");
			return core;
		}
		String stationStatus = "1";
		// 查询是否结炉
		String sqlcom = "SELECT COUNT(*) COUNT,NVL(MAX(T.STATION_STATUS),0) STATION_STATUS FROM COUPLING_COM_INFO T WHERE T.STATION_CODE = ?  AND T.WO_ID=?";
		psta = connection.prepareStatement(sqlcom);
		psta.setString(1, "700310");
		psta.setString(2, woId);
		rs = psta.executeQuery();
		if (rs.next()) {
			stationStatus = rs.getString("STATION_STATUS");
		}
		rs.close();
		psta.close();
		if (stationStatus.equals("2")) {
			core.setV_errMsg("该工单磷化实绩已结炉,不允许此操作!");
			return core;
		}

		for (int i = 0; i < list1.size(); i++) {
			ArrayList<String> list = (ArrayList<String>) list1.get(i);
			String resultNo = list.get(0);
			String colCount = list.get(1);
			// 删除磷化实绩
			patdelete.setObject(1, resultNo);
			patdelete.addBatch();
			// 删除磷化检验结果
			patsdelPlan.setObject(1, resultNo);
			patsdelPlan.addBatch();
			// 删除接箍公共信息
			patsPlan.setObject(1, resultNo);
			patsPlan.setObject(2, woId);
			patsPlan.addBatch();
			// 查询库存总支数和
			String proNum = "";
			String sqlloading1 = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.selectMatCount");//
			psta = connection.prepareStatement(sqlloading1);
			psta.setObject(1, work.getJudgeStoveNo());
			psta.setObject(2, work.getBatchNo());
			psta.setObject(3, woId);
			rs = psta.executeQuery();
			while (rs.next()) {
				proNum = rs.getString("PRO_NUM");
			}
			rs.close();
			psta.close();
			// 查询材料表的材料号
			String matNo = "";
			double SINGLEWEIGHT = 0;
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.QueryMatNoDo");// 材料表的材料号
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, woId);
			psta.setObject(2, work.getJudgeStoveNo());
			psta.setObject(3, work.getBatchNo());
			rs = psta.executeQuery();
			while (rs.next()) {
				matNo = rs.getString("MAT_NO");
				SINGLEWEIGHT = Double.parseDouble(rs.getString("SINGLEWEIGHT"));
			}
			rs.close();
			psta.close();
			if (Integer.parseInt(colCount) >= Integer.parseInt(proNum)) {
				// 删除材料表
				pstaMatM.setObject(1, woId);
				pstaMatM.setObject(2, work.getJudgeStoveNo());
				pstaMatM.setObject(3, work.getBatchNo());
				pstaMatM.addBatch();
				// 删除位置表
				pstaMatButters.setObject(1, matNo);
				pstaMatButters.addBatch();
				// 删除交易表
				pstaMatDeal.setObject(1, matNo);
				pstaMatDeal.addBatch();
				pstaMatM.executeBatch();
				pstaMatButters.executeBatch();
				pstaMatDeal.executeBatch();

			} else {
				// 修改接箍库存表
				String updateMat = "UPDATE COUPLING_MAT_M T SET T.PRO_NUM=TO_NUMBER(T.PRO_NUM)+TO_NUMBER(?),T.PRO_WT=TO_NUMBER(T.PRO_WT)+TO_NUMBER(?) WHERE T.MAT_NO=?";
				psta = connection.prepareStatement(updateMat);
				psta.setObject(1, '-' + colCount);
				psta.setObject(2, '-' + (SINGLEWEIGHT / 1000)
						* Integer.parseInt(colCount));
				psta.setObject(3, matNo);
				psta.executeUpdate();
				psta.close();
				// 修改接箍位置表
				String updateMatBut = " UPDATE COUPLING_MAT_BUTTRESS T SET T.PIECES=TO_NUMBER(T.PIECES)+TO_NUMBER(?),T.WEIGHT=TO_NUMBER(T.WEIGHT)+TO_NUMBER(?) WHERE T.MAT_NO=?";
				psta = connection.prepareStatement(updateMatBut);
				psta.setObject(1, '-' + colCount);
				psta.setObject(2, '-' + (SINGLEWEIGHT / 1000)
						* Integer.parseInt(colCount));
				psta.setObject(3, matNo);
				psta.executeUpdate();
				psta.close();

				// 修改接箍库交易表
				String updateMatDeal = "UPDATE COUPLING_MAT_DEAL T SET T.DEAL_NUM=TO_NUMBER(T.DEAL_NUM)+TO_NUMBER(?),T.DEAL_WT=TO_NUMBER(T.DEAL_WT)+TO_NUMBER(?) WHERE T.MAT_NO=? AND T.DEAL_TYPE_CODE = '800701'";
				psta = connection.prepareStatement(updateMatDeal);
				psta.setObject(1, '-' + colCount);
				psta.setObject(2, '-' + (SINGLEWEIGHT / 1000)
						* Integer.parseInt(colCount));
				psta.setObject(3, matNo);
				psta.executeUpdate();
				psta.close();

			}
			patsPlan.executeBatch();
			patsdelPlan.executeBatch();
			patdelete.executeBatch();

			String strPln = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.UpdateJGPln");// 修改计划表支数
			PreparedStatement pstaPln = connection.prepareStatement(strPln);
			pstaPln.setObject(1, '-' + String.valueOf(colCount));
			if (work.getSingleweight().equals("")) {
				pstaPln.setObject(2, 0);
			} else {
				pstaPln.setObject(2, '-' + String.valueOf(Integer
						.parseInt(colCount)
						* Double.parseDouble(work.getSingleweight()) / 1000));// 重量
			}
			pstaPln.setObject(3, woId);
			pstaPln.addBatch();
			pstaPln.executeBatch();

			int plnNum = 0;
			double plnWt = 0;
			String guid = "";
			String jgOrderNo = "";
			// 查询接箍库存对应成品合同
			String sqlD = "SELECT NVL(T.PLAN_NUM,0) PLAN_NUM,NVL(T.PLAN_WT,0) PLAN_WT,T.GUID,T.JG_ORDERNO FROM PLN_ZY_JG_MIDDLE T WHERE T.MAT_NO =? AND T.WO_ID=?";
			ps = connection.prepareStatement(sqlD);
			ps.setObject(1, matNo);
			ps.setObject(2, woId);
			rs = ps.executeQuery();
			while (rs.next()) {
				plnNum = Integer.parseInt(rs.getString("PLAN_NUM"));
				plnWt = Double.parseDouble(rs.getString("PLAN_WT"));
				guid = rs.getString("GUID");
				jgOrderNo = rs.getString("JG_ORDERNO");
				if (Integer.parseInt(colCount) - plnNum >= 0) {
					// 删除接箍库存对应成品合同
					String deleteD = "DELETE PLN_ZY_JG_MIDDLE T WHERE T.GUID=?";
					psta = connection.prepareStatement(deleteD);
					psta.setObject(1, guid);
					psta.executeUpdate();
					psta.close();
					

					// 修改接箍合同表
					String updateOrder = "UPDATE PLN_ORDER_JG T SET T.HANGKC_NUM=TO_NUMBER(NVL(T.HANGKC_NUM,0))-TO_NUMBER(?) WHERE T.JG_ORDERNO=?";
					psta = connection.prepareStatement(updateOrder);
					psta.setObject(1, plnNum);
					psta.setObject(2, jgOrderNo);
					psta.executeUpdate();
					psta.close();
				} else {
					// 删除接箍库存对应成品合同
					String deleteD = "UPDATE PLN_ZY_JG_MIDDLE T SET T.PLAN_NUM=TO_NUMBER(NVL(T.PLAN_NUM,0))-TO_NUMBER(?) ,T.PLAN_WT=TO_NUMBER(NVL(T.PLAN_WT,0))-TO_NUMBER(?)  WHERE T.GUID=?";
					psta = connection.prepareStatement(deleteD);
					psta.setObject(1, colCount);
					psta.setObject(2, (SINGLEWEIGHT / 1000)
							* Integer.parseInt(colCount));
					psta.setObject(3, guid);
					psta.executeUpdate();
					psta.close();

					// 修改接箍合同表
					String updateOrder = "UPDATE PLN_ORDER_JG T SET T.HANGKC_NUM=TO_NUMBER(nvl(T.HANGKC_NUM,0))-TO_NUMBER(?) WHERE T.JG_ORDERNO=?";
					psta = connection.prepareStatement(updateOrder);
					psta.setObject(1, colCount);
					psta.setObject(2, jgOrderNo);
					psta.executeUpdate();
					psta.close();
				}
				colCount = String.valueOf(Integer.parseInt(colCount) - plnNum);
			}
			rs.close();
			ps.close();

		}
		return core;

	}

	/**
	 * 删除磷化检测实绩
	 * 
	 * @param result
	 *            磷化检测实绩
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject deletePhosphateResult(ArrayList<Object> list1,
			String woId) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			core = deletePhosphateResult(connection, core, list1, woId);
			if (core.getV_errMsg().equals("")) {
				core.setV_errMsg("删除成功！");
				core.setResult(1);
				connection.commit();
			} else {
				return core;
			}
		} 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 result
	 *            磷化检测实绩
	 * @return
	 */
	public CoreReturnObject updatePlanResult(String process, String pbGx,
			String woID) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date dt = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		String systime = dateFormat.format(dt);
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务

			// ///////交库数据
			String strMatM = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.AddMatM");// 新增接箍材料表
			PreparedStatement pstaMatM = connection.prepareStatement(strMatM);
			String strMatButters = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.AddMatButters");// 新增位置表
			PreparedStatement pstaMatButters = connection
					.prepareStatement(strMatButters);

			String strMatDeal = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.AddMatDeal");// 新增交易表
			PreparedStatement pstaMatDeal = connection
					.prepareStatement(strMatDeal);

			String updateSql1 = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.doBeside");
			PreparedStatement updateSqlPsta = connection
					.prepareStatement(updateSql1);
			// 查询工单信息
			PlnZyJgWorkbillEntity work = CoupLoadingService.getPlanWoId(
					connection, woID, PlnZyJgWorkbillEntity.class);
			if (work == null) {
				core.setV_errMsg("未查询到工单信息,请确认!");
				return core;
			}
			if (!work.getZyBillStatus().equals("2")) {
				core.setV_errMsg("工单状态不是生产中,不允许此操作!");
				return core;
			}
			// 查询有委外但是没有委外回报完毕
			String subCount = "";// 委外数据
			String sqlloadingw = CoreXmlSqlParsersFactory
					.getSql("CoupCutService.QueryCouplingOff");// 查询委外数据
			psta = connection.prepareStatement(sqlloadingw);
			psta.setObject(1, work.getWoId());
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				subCount = rs1.getString("COUNT");
			}
			/*if (Integer.parseInt(subCount) > 0) {
				core.setV_errMsg("有委外数据但没有委外回报!");
				return core;
			}*/
			rs1.close();
			psta.close();
			String status = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.queryComPlanJg");
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, work.getWoId());
			rs = psta.executeQuery();
			while (rs.next()) {
				status = rs.getString("STATION_STATUS");
				if (status.equals("1")) {
					core.setV_errMsg("该工单" + rs.getString("STATION_DESC")
							+ "未结炉！");
					return core;
				}
			}
			rs.close();
			psta.close();
			String singleWt = "";
			if (work.getCodeJg().equals("")) {
				core.setV_errMsg("接箍码为空请检查!");
				return core;
			} else {
				// 查询接箍单重
				String sqlloadingWt = CoreXmlSqlParsersFactory
						.getSql("PhosphateResultService.QuerySingleWt");
				psta = connection.prepareStatement(sqlloadingWt);
				psta.setObject(1, work.getCodeJg());
				ResultSet rst = psta.executeQuery();
				if (rst.next()) {
					singleWt = rst.getString("WEIGHT_JG");
				}
				rst.close();
				psta.close();
				if (Double.parseDouble(singleWt) <= 0.0) {
					core.setV_errMsg("接箍单重等于零,请检查!");
					return core;
				}
			}
			// int phosNum = 0;
			// // 查询磷化支数
			// String sqlCut =
			// "SELECT SUM(NVL(T.COL_COUNT,0)) COL_COUNT  FROM COUPLING_CUT_RESULT T WHERE T.WO_ID=?";
			// psta = connection.prepareStatement(sqlCut);
			// psta.setString(1, woID);
			// rs = psta.executeQuery();
			// if (rs.next()) {
			// phosNum = rs.getInt("COL_COUNT");
			// }
			// rs.close();
			// psta.close();
			// String updatePlan = CoreXmlSqlParsersFactory
			// .getSql("PhosphateResultService.updatePhosStatus");// 修改计划表磷化状态
			// PreparedStatement patsUpPlan = connection
			// .prepareStatement(updatePlan);
			// String updatePltPlan = CoreXmlSqlParsersFactory
			// .getSql("PhosphateResultService.updatePltStatus");// 修改工单表镀铜状态
			// PreparedStatement patsUpPltPlan = connection
			// .prepareStatement(updatePltPlan);
			//
			// if (phosNum != Integer.parseInt(work.getRealBlNum())) {
			// core.setV_errMsg("磷化支数与切割支数不符,不允许结炉!");
			// return core;
			// }
			int count = 0;
			String stationStatus = "1";
			// 查询是否结炉
			sql = "SELECT COUNT(*) COUNT,MAX(T.STATION_STATUS) STATION_STATUS FROM COUPLING_COM_INFO T WHERE T.STATION_CODE = ?  AND T.WO_ID=?";
			psta = connection.prepareStatement(sql);
			psta.setString(1, process);
			psta.setString(2, woID);
			rs = psta.executeQuery();
			if (rs.next()) {
				count = rs.getInt("COUNT");
				stationStatus = rs.getString("STATION_STATUS");
			}
			rs.close();
			psta.close();
			if (count == 0) {
				core.setV_errMsg("无磷化实绩,不允许此操作!");
				return core;
			}
			if (stationStatus.equals("2")) {
				core.setV_errMsg("该工单磷化实绩已结炉,不允许此操作!");
				return core;
			}
			// 修改公共信息表结炉标志
			String updateSql = "UPDATE COUPLING_COM_INFO T SET T.STATION_STATUS = '2' WHERE T.STATION_CODE = ? AND T.WO_ID = ?";
			psta = connection.prepareStatement(updateSql);
			psta.setObject(1, process);
			psta.setObject(2, woID);
			psta.executeUpdate();
			psta.close();

			psta = connection.prepareStatement(updateSql);
			psta.setObject(1, pbGx);
			psta.setObject(2, woID);
			psta.executeUpdate();
			psta.close();

			String storageNo = "";
			String storageAtte = "";
			String storageAtteName = "";
			String storageType = "";
			String storageTypeName = "";
			String managNo = "";
			String managName = "";
			sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.queryStorageType");
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, work.getPlineCode());
			rs = psta.executeQuery();
			if (rs.next()) {
				storageNo = rs.getString("STORAGE_NO");
				storageAtte = rs.getString("STORAGE_ATTR");
				storageAtteName = rs.getString("STORAGE_ATTR_NAME");
				storageType = rs.getString("STORAGE_TYPE_NO");
				storageTypeName = rs.getString("STORAGE_TYPE_NAME");
				managNo = rs.getString("MANAGEMENT_NO");
				managName = rs.getString("MANAGEMENT_NAME");
			}
			rs.close();
			psta.close();
			String belongCode = "";
			String belongName = "";
			sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.selectBelong");
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, work.getPlineCode());
			rs = psta.executeQuery();
			if (rs.next()) {
				belongCode = rs.getString("DEPARTMENT_CODE");
				belongName = rs.getString("DEPARTMENT_DESC");
			}
			rs.close();
			psta.close();

			// 查询锯切个数
			String cutNum = "";
			if (work.getIfsplit().equals("1")) {
				String sqlloadingOff = CoreXmlSqlParsersFactory
						.getSql("FrmInLibrary.QueryOffCut");// 查询委外返线个数
				psta = connection.prepareStatement(sqlloadingOff);
				psta.setObject(1, woID);
				rs = psta.executeQuery();
				while (rs.next()) {
					cutNum = rs.getString("INCISION_NUM");
				}
				rs.close();
				psta.close();
			} else {
				String sqlloading1 = CoreXmlSqlParsersFactory
						.getSql("FrmInLibrary.queryCutPieces");// 锯切个数
				psta = connection.prepareStatement(sqlloading1);
				psta.setObject(1, woID);
				rs = psta.executeQuery();
				while (rs.next()) {
					cutNum = rs.getString("PRO_NUM");
				}
				rs.close();
				psta.close();
			}
			// 查询磷化个数
			String phosNum = "";
			String sqlloading1 = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.queryPhosPieces");// 磷化个数
			psta = connection.prepareStatement(sqlloading1);
			psta.setObject(1, woID);
			rs = psta.executeQuery();
			while (rs.next()) {
				phosNum = rs.getString("PRO_NUM");
			}
			rs.close();
			psta.close();
			
			//查询返线交库数据
			String fxNum = "";
			String sqlloading2 = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.QueryPhosphateResult");
			psta = connection.prepareStatement(sqlloading2);
			psta.setObject(1, woID);
			rs = psta.executeQuery();
			while (rs.next()) {
				fxNum = rs.getString("count");
			}
			rs.close();
			psta.close();

			if (Integer.parseInt(cutNum) >= Integer.parseInt(phosNum) || Integer.parseInt(fxNum) > 0) {
				String failNum = "";
				if(Integer.parseInt(fxNum) > 0){
					cutNum = phosNum;
				}
				failNum = String.valueOf(Integer.parseInt(cutNum)
						- Integer.parseInt(phosNum));
				// 获取交易单号
				String dealOrde = doAddDealOrde("IA", "800701", connection);
				// 获取材料号
				String matNo = doAddMatNo(work.getJudgeStoveNo(), woID,
						connection);
				// 新增材料表
				/*
				 * pstaMatM.setObject(1, matNo); pstaMatM.setObject(2, "");
				 * pstaMatM.setObject(3, ""); pstaMatM.setObject(4, woID);
				 * pstaMatM.setObject(5, work.getPlineCode());
				 * pstaMatM.setObject(6, work.getPlineName());
				 * pstaMatM.setObject(7, work.getJudgeStoveNo());
				 * pstaMatM.setObject(8, work.getBatchNo());
				 * pstaMatM.setObject(9, work.getOutwlId());
				 * pstaMatM.setObject(10, work.getOutwlDesc());
				 * pstaMatM.setObject(11, work.getMinD());
				 * pstaMatM.setObject(12, work.getMinH());
				 * pstaMatM.setObject(13, work.getCodeJg());
				 * pstaMatM.setObject(14, work.getGradecode());
				 * pstaMatM.setObject(15, work.getGradename());
				 * pstaMatM.setObject(16, work.getSteelcode());
				 * pstaMatM.setObject(17, work.getSteelname());
				 * pstaMatM.setObject(18, work.getModelCode());
				 * pstaMatM.setObject(19, work.getModelDesc());
				 * pstaMatM.setObject(20, work.getDiameterJg());
				 * pstaMatM.setObject(21, work.getHeightJg());
				 * pstaMatM.setObject(22, work.getSpecJg());
				 * pstaMatM.setObject(23, work.getSpecJgDesc());
				 * pstaMatM.setObject(24, work.getStyleJg());
				 * pstaMatM.setObject(25, work.getDiameter());
				 * pstaMatM.setObject(26, work.getCheckJVal());
				 * pstaMatM.setObject(27, work.getLengthJg());
				 * pstaMatM.setObject(28, work.getSingleweight());
				 * pstaMatM.setObject(29, ""); pstaMatM.setObject(30,
				 * work.getIfMonitorJg()); pstaMatM.setObject(31,
				 * work.getPrdcrNo()); pstaMatM.setObject(32, "");
				 * pstaMatM.setObject(33, String.valueOf(failNum)); if
				 * (work.getSingleweight().equals("")) { pstaMatM.setObject(34,
				 * 0); } else { pstaMatM.setObject(34,
				 * Double.parseDouble(failNum) Double.parseDouble(singleWt) /
				 * 1000);// 重量 } pstaMatM.setObject(35, systime);
				 * pstaMatM.setObject(36, ""); pstaMatM.setObject(37, "");
				 * pstaMatM.setObject(38, "");// 操作人 pstaMatM.setObject(39, "");
				 * pstaMatM.setObject(40, systime); pstaMatM.setObject(41,
				 * systime); pstaMatM.setObject(42, belongCode);
				 * pstaMatM.setObject(43, belongName); pstaMatM.setObject(44,
				 * "22"); pstaMatM.setObject(45, work.getCraftSeq());
				 * pstaMatM.setObject(46, work.getCodeJgBl());
				 * pstaMatM.setObject(47, work.getStoveNo());
				 * pstaMatM.setObject(48, work.getFlagStoveNo());
				 * pstaMatM.setObject(49, work.getProduccodeJg());
				 * pstaMatM.setObject(50, work.getProduccodeJgDesc());
				 */

				pstaMatM.setObject(1, woID);
				pstaMatM.setObject(2, matNo);
				pstaMatM.setObject(3, "");
				pstaMatM.setObject(4, String.valueOf(failNum));
				if (work.getSingleweight().equals("")) {
					pstaMatM.setObject(5, 0);
				} else {
					pstaMatM.setObject(5, Double.parseDouble(failNum)
							* Double.parseDouble(singleWt) / 1000);// 重量
				}
				pstaMatM.setObject(6, systime);
				pstaMatM.setObject(7, "");
				pstaMatM.setObject(8, "");
				pstaMatM.setObject(9, "");
				pstaMatM.setObject(10, systime);
				pstaMatM.setObject(11, belongCode);
				pstaMatM.setObject(12, belongName);
				pstaMatM.setObject(13, "22");
				pstaMatM.addBatch();
				pstaMatM.executeBatch();
				pstaMatM.close();
				// 新增材料从表
				pstaMatButters.setObject(1, matNo);
				pstaMatButters.setObject(2, "0001");
				if (work.getDecision().equals("A")) {
					pstaMatButters.setObject(3, "801402");
					pstaMatButters.setObject(4, "80150201");
				} else {
					pstaMatButters.setObject(3, "801401");
					pstaMatButters.setObject(4, "80150101");
				}
				pstaMatButters.setObject(5, "");
				pstaMatButters.setObject(6, failNum);
				if (work.getSingleweight().equals("")) {
					pstaMatButters.setObject(7, 0);
				} else {
					pstaMatButters.setObject(7, Double.parseDouble(failNum)
							* Double.parseDouble(singleWt) / 1000);
				}
				pstaMatButters.setObject(8, "");
				pstaMatButters.setObject(9, "");
				pstaMatButters.setObject(10, "");
				pstaMatButters.setObject(11, storageNo);
				pstaMatButters.setObject(12, storageNo + "10101");
				pstaMatButters.setObject(13, storageAtte);
				pstaMatButters.setObject(14, storageAtteName);
				pstaMatButters.setObject(15, storageType);
				pstaMatButters.setObject(16, storageTypeName);
				pstaMatButters.setObject(17, managNo);
				pstaMatButters.setObject(18, managName);
				pstaMatButters.setObject(19, "");
				pstaMatButters.setObject(20, "");
				pstaMatButters.setObject(21, systime);
				pstaMatButters.setObject(22, "0");
				pstaMatButters.setObject(23, "");
				pstaMatButters.setObject(24, dealOrde);
				pstaMatButters.setObject(25, work.getLatheGrpNo());
				pstaMatButters.setObject(26, work.getLatheGrpNm());
				pstaMatButters.setObject(27, "B00002");
				pstaMatButters.addBatch();
				pstaMatButters.executeBatch();
				pstaMatButters.close();

				// 新增交易表
				pstaMatDeal.setObject(1, managNo);// 作业科室编码
				pstaMatDeal.setObject(2, managName);
				pstaMatDeal.setObject(3, "");
				pstaMatDeal.setObject(4, matNo);
				pstaMatDeal.setObject(5, "");
				pstaMatDeal.setObject(6, "");
				pstaMatDeal.setObject(7, work.getMinD());
				pstaMatDeal.setObject(8, work.getMinH());
				pstaMatDeal.setObject(9, work.getDiameterJg());
				pstaMatDeal.setObject(10, work.getHeightJg());
				pstaMatDeal.setObject(11, work.getDiameter());
				pstaMatDeal.setObject(12, work.getCheckJVal());
				pstaMatDeal.setObject(13, work.getLengthJg());
				pstaMatDeal.setObject(14, "");// 监制人
				pstaMatDeal.setObject(15, "");// 监制时间
				pstaMatDeal.setObject(16, failNum);
				pstaMatDeal.setObject(17, Integer.parseInt(failNum)
						* Double.parseDouble(singleWt) / 1000);// 重量
				pstaMatDeal.setObject(18, systime);
				pstaMatDeal.setObject(19, storageNo);
				pstaMatDeal.setObject(20, storageNo + "10101");
				pstaMatDeal.setObject(21, storageAtte);
				pstaMatDeal.setObject(22, storageAtteName);
				pstaMatDeal.setObject(23, storageType);
				pstaMatDeal.setObject(24, storageTypeName);
				pstaMatDeal.setObject(25, "");
				pstaMatDeal.setObject(26, "");
				pstaMatDeal.setObject(27, systime);
				pstaMatDeal.setObject(28, "");
				pstaMatDeal.setObject(29, dealOrde);
				pstaMatDeal.setObject(30, systime);
				pstaMatDeal.setObject(31, "10");
				pstaMatDeal.setObject(32, "0001");
				pstaMatDeal.setObject(33, woID);
				pstaMatDeal.addBatch();
				pstaMatDeal.executeBatch();
				pstaMatDeal.close();

			} else {
				core.setV_errMsg("磷化个数大于锯切个数,不允许结炉!");
				return core;
			}

			updateSqlPsta.setString(1, pbGx);
			updateSqlPsta.setString(2, woID);
			updateSqlPsta.addBatch();

			updateSqlPsta.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 result
	 *            磷化检测实绩
	 * @return
	 */
	public CoreReturnObject unDoCompleteResult(String process, String pbGx,
			String woID) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String strMatM = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.DeleteMatMFail");// 删除接箍材料表
			PreparedStatement pstaMatM = connection.prepareStatement(strMatM);
			String strMatButters = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.DeleteMatButtersFail");// 删除位置表
			PreparedStatement pstaMatButters = connection
					.prepareStatement(strMatButters);
			String strMatDeal = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.DeleteMatDealFail");// 删除交易表
			PreparedStatement pstaMatDeal = connection
					.prepareStatement(strMatDeal);
			String updateSql1 = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.unDoBeside");
			PreparedStatement updateSqlPsta = connection
					.prepareStatement(updateSql1);

			int cutFalg = 0;
			sql = CoreXmlSqlParsersFactory.getSql("FrmInLibrary.selectQcmApp");
			psta = connection.prepareStatement(sql);
			psta.setString(1, woID);
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = Integer.parseInt(rs.getString("ACOUNT"));
			}
			rs.close();
			psta.close();
			if (cutFalg == 0) {
				core.setV_errMsg("该炉已申请判定,不允许结炉回退!");
				return core;
			}
			// 查询工单信息
			PlnZyJgWorkbillEntity work = CoupLoadingService.getPlanWoId(
					connection, woID, PlnZyJgWorkbillEntity.class);
			if (work == null) {
				core.setV_errMsg("未查询到工单信息,请确认!");
				return core;
			}
			int count = 0;
			String stationStatus = "1";
			// 查询是否结炉
			sql = "SELECT COUNT(*) COUNT,MAX(T.STATION_STATUS) STATION_STATUS FROM COUPLING_COM_INFO T WHERE T.STATION_CODE = ?  AND T.WO_ID=?";
			psta = connection.prepareStatement(sql);
			psta.setString(1, process);
			psta.setString(2, woID);
			rs = psta.executeQuery();
			if (rs.next()) {
				count = rs.getInt("COUNT");
				stationStatus = rs.getString("STATION_STATUS");
			}
			rs.close();
			psta.close();

			if (count == 0) {
				core.setV_errMsg("无磷化实绩,不允许此操作!");
				return core;
			}
			if (stationStatus.equals("1")) {
				core.setV_errMsg("该工单磷化实绩未结炉,不允许此操作!");
				return core;
			}
			// 修改公共信息表结炉标志
			String updateSql = "UPDATE COUPLING_COM_INFO T SET T.STATION_STATUS = '1' WHERE T.STATION_CODE = ? AND T.WO_ID = ?";
			psta = connection.prepareStatement(updateSql);
			psta.setObject(1, process);
			psta.setObject(2, woID);
			psta.executeUpdate();
			psta.close();

			psta = connection.prepareStatement(updateSql);
			psta.setObject(1, pbGx);
			psta.setObject(2, woID);
			psta.executeUpdate();
			psta.close();
			// 查询材料表的材料号
			String matNo = "";
			String sqlloading1 = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.QueryMatNo");// 材料表的材料号
			psta = connection.prepareStatement(sqlloading1);
			psta.setObject(1, woID);
			psta.setObject(2, work.getJudgeStoveNo());
			psta.setObject(3, work.getBatchNo());
			rs = psta.executeQuery();
			while (rs.next()) {
				matNo = rs.getString("MAT_NO");
			}
			rs.close();
			psta.close();

			// 删除材料表
			pstaMatM.setObject(1, woID);
			pstaMatM.setObject(2, work.getJudgeStoveNo());
			pstaMatM.setObject(3, work.getBatchNo());
			pstaMatM.addBatch();
			// 删除位置表
			pstaMatButters.setObject(1, matNo);
			pstaMatButters.addBatch();
			// 删除交易表
			pstaMatDeal.setObject(1, matNo);
			pstaMatDeal.addBatch();
			pstaMatM.executeBatch();
			pstaMatButters.executeBatch();
			pstaMatDeal.executeBatch();

			updateSqlPsta.setString(1, pbGx);
			updateSqlPsta.setString(2, woID);
			updateSqlPsta.addBatch();

			updateSqlPsta.executeBatch();
			// String updatePlan = CoreXmlSqlParsersFactory
			// .getSql("PhosphateResultService.updatePhosStatus1");// 修改工单表磷化状态
			// PreparedStatement patsUpPlan = connection
			// .prepareStatement(updatePlan);
			// String updatePltPlan = CoreXmlSqlParsersFactory
			// .getSql("PhosphateResultService.updatePltStatus1");// 修改工单表镀铜状态
			// PreparedStatement patsUpPltPlan = connection
			// .prepareStatement(updatePltPlan);
			// String planNo = list.get(0);
			// String coatType = list.get(1);
			// String woID = list.get(3);
			// String ifcut = "";
			// if (list.get(4).equals("无喷标")) {
			// ifcut = "0";
			// } else {
			// ifcut = "1";
			// }
			// if (coatType.equals("磷化")) {
			// patsUpPlan.setObject(1, planNo);
			// patsUpPlan.setObject(2, woID);
			// patsUpPlan.setObject(3, ifcut);
			// patsUpPlan.setObject(4, planNo);
			// patsUpPlan.setObject(5, woID);
			// patsUpPlan.setObject(6, planNo);
			// patsUpPlan.setObject(7, process);
			// patsUpPlan.setObject(8, woID);
			// patsUpPlan.setObject(9, planNo);
			// patsUpPlan.setObject(10, pbGx);
			// patsUpPlan.setObject(11, woID);
			// patsUpPlan.addBatch();
			// patsUpPlan.executeBatch();
			// } else {
			// patsUpPltPlan.setObject(1, planNo);
			// patsUpPltPlan.setObject(2, woID);
			// patsUpPltPlan.setObject(3, ifcut);
			// patsUpPltPlan.setObject(4, planNo);
			// patsUpPltPlan.setObject(5, woID);
			// patsUpPltPlan.setObject(6, planNo);
			// patsUpPltPlan.setObject(7, process);
			// patsUpPltPlan.setObject(8, woID);
			// patsUpPltPlan.setObject(9, planNo);
			// patsUpPltPlan.setObject(10, pbGx);
			// patsUpPltPlan.setObject(11, woID);
			// patsUpPltPlan.addBatch();
			// patsUpPltPlan.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 result
	 *            磷化检测实绩
	 * @return
	 */
	public CoreReturnObject updatePhosphateResultD(
			ArrayList<ArrayList<String>> list) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updatePlan = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.UpdatePhosphateResultD");// 修改检验记录
			PreparedStatement patsUpPlan = connection
					.prepareStatement(updatePlan);
			for (int i = 0; i < list.size(); i++) {
				ArrayList<String> pram = (ArrayList<String>) list.get(i);
				patsUpPlan.setObject(1, pram.get(0));
				patsUpPlan.setObject(2, pram.get(1));
				patsUpPlan.setObject(3, pram.get(2));
				patsUpPlan.setObject(4, pram.get(3));
				patsUpPlan.setObject(5, pram.get(4));
				patsUpPlan.setObject(6, pram.get(7));
				patsUpPlan.setObject(7, pram.get(8));
				patsUpPlan.setObject(8, pram.get(6));
				patsUpPlan.setObject(9, pram.get(5));
				patsUpPlan.addBatch();
			}
			patsUpPlan.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 result
	 *            磷化检测实绩
	 * @return
	 */
	public CoreReturnObject deletePhosphateResultD(
			ArrayList<ArrayList<String>> list) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updatePlan = CoreXmlSqlParsersFactory
					.getSql("PhosphateResultService.DeletePhosphateResultD");// 删除检验记录
			PreparedStatement patsUpPlan = connection
					.prepareStatement(updatePlan);
			for (int i = 0; i < list.size(); i++) {
				ArrayList<String> pram = (ArrayList<String>) list.get(i);
				patsUpPlan.setObject(1, pram.get(0));
				patsUpPlan.addBatch();
				patsUpPlan.executeBatch();
				// int countD = 0;
				// String sqlloading = CoreXmlSqlParsersFactory
				// .getSql("PhosphateResultService.QueryInsResultD");
				// PreparedStatement psta = connection
				// .prepareStatement(sqlloading);
				// psta.setObject(1, pram.get(1));
				// ResultSet rs = psta.executeQuery();
				// if (rs.next()) {
				// countD = Integer.parseInt(rs.getString("count"));
				// }
				// rs.close();
				// psta.close();
				// if (countD == 0) {
				// int countR = 0;
				// sqlloading = CoreXmlSqlParsersFactory
				// .getSql("PhosphateResultService.QueryInsResult");
				// psta = connection.prepareStatement(sqlloading);
				// psta.setObject(1, pram.get(1));
				// rs = psta.executeQuery();
				// if (rs.next()) {
				// countR = Integer.parseInt(rs.getString("count"));
				// }
				// rs.close();
				// psta.close();
				// if (countR != 0) {
				// core.setV_errMsg("该磷化/镀铜实绩记录存在！");
				// return core;
				// }
				// }
			}
			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 planNOupdatePhosphateResult
	 * @return
	 */
	public CoreReturnObject getPhosphateResult(String woId) {
		return this.getDataBySqlID(
				"PhosphateResultService.ProcessPlan.GetPhosphateResult",
				new Object[] { woId });
	}

	/**
	 * 查询接箍磷化检测项配置表
	 * 
	 * @return
	 */
	public CoreReturnObject getPhosphateItem() {
		return this
				.getDataBySqlID("PhosphateResultService.ProcessPlan.CoupProcessItem");
	}

	/**
	 * 查询磷化检测项目
	 * 
	 * @return
	 */
	public CoreReturnObject queryPhosphateItem(String plinCode) {
		return this.getDataBySqlID("PhosphateResultService.queryPhosphateItem",
				new Object[] { plinCode });
	}

	/**
	 * 查询磷化检测项目
	 * 
	 * @return
	 */
	public CoreReturnObject queryPhosphateItem1(String itime) {
		return this.getDataBySqlID(
				"PhosphateResultService.queryPhosphateItem1",
				new Object[] { itime });
	}

	/**
	 * 查询接箍磷化检测结果表
	 * 
	 * @param planNO
	 * @return
	 */
	public CoreReturnObject getPhosphateRD(String resultNo, String woId) {
		return this.getDataBySqlID(
				"PhosphateResultService.ProcessPlan.CoupProcessRD",
				new Object[] { resultNo, woId });
	}

	/**
	 * @param planNO
	 * @param detailNo
	 * @return
	 */
	public CoreReturnObject getPhosphateRDByDetailNo(String planNO,
			String detailNo) {
		return this.getDataBySqlID(
				"PhosphateResultService.ProcessPlan.CoupProcessRDByDetailNo",
				new Object[] { planNO, detailNo });
	}

	/**
	 * @param planNO
	 * @return
	 */
	public CoreReturnObject queryPlanJg(String planNO) {
		return this.getDataBySqlID("PhosphateResultService.queryPlanJg",
				new Object[] { planNO });
	}

	/***
	 * 生产材料号
	 * 
	 * @param plineCode
	 * @param zygNo
	 * @param connection
	 * @return
	 */
	public String doAddMatNo(String judNo, String woId, Connection connection) {
		String MatNo = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		// SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
		String sqlloading = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.queryMaxMatNo");// 查询最大材料号

		try {
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, woId.replaceFirst("JG_", ""));
			psta.setObject(2, woId);
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				MatNo = rs1.getString("MAT_NO");
			}
			rs1.close();
			psta.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return MatNo;
	}

	/***
	 * 生成交易单号
	 * 
	 * @param plineCode
	 * @param zygNo
	 * @param connection
	 * @return
	 */
	public static String doAddDealOrde(String lx, String woId,
			Connection connection) {
		String resultNo = "";
		PreparedStatement psta = null;
		String sqlloading = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.queryMaxDealOrde");// 查询交易单号
		Date now = new Date();
		SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat date1 = new SimpleDateFormat("yyyy-MM-dd");
		String systime = date.format(now);
		try {
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, lx);
			psta.setObject(2, systime);
			psta.setObject(3, date1.format(now));
			psta.setObject(4, woId);
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				resultNo = rs1.getString("DEAL_ORDE");
			}
			rs1.close();
			psta.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return resultNo;
	}

}
