package com.steering.mes.mcp.coup;

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

import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.common.StringTool;
import com.steering.mes.mcp.Vrp.MeanValueCalculation;
import com.steering.mes.mcp.entity.ComMscJgEntity;
import com.steering.mes.mcp.entity.CouplingMatMEntity;
import com.steering.mes.mcp.entity.PlnGxJgPropSEntity;
import com.steering.mes.mcp.entity.QcmAddAskEntity;
import com.steering.mes.mcp.entity.QcmZgJugdeApplyEntity;
import com.steering.mes.mcp.entity.MchEntity.PlnZyJgWorkbillEntity;

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.Date;
import java.util.List;

public class FrmCouplingApplPro extends DBCommon {

	/**
	 * 查询合同附加要求信息 （QCM_ADD_ASK）
	 * 
	 * @param JugdeApplyCode
	 * @param JudgeStoveNo
	 * @return
	 */
	public CoreReturnObject QueryQcmAddAsk(String JugdeApplyCode,
			String JudgeStoveNo) {
		return this.getDataBySqlID("FrmCouplingApplPro.QueryQcmAddAsk",
				new Object[] { JugdeApplyCode, JudgeStoveNo });
	}

	/**
	 * 查询接箍单个重 （COM_MSC_JG）
	 * 
	 * @param JugdeApplyCode
	 * @param JudgeStoveNo
	 * @return
	 */
	public CoreReturnObject doQueryJgWt(String JugdeApplyCode) {
		return this.getDataBySqlID("FrmCouplingApplPro.doQueryJgWt",
				new Object[] { JugdeApplyCode });
	}

	/**
	 * 查询合同信息
	 * 
	 * @param ProOrderNo
	 * @return
	 */
	public CoreReturnObject doQueryplnSaleorder(String spec, String codeJgBl) {
		return this.getDataBySqlID("FrmCouplingApplPro.doQueryplnSaleorder",
				new Object[] { spec, codeJgBl });
	}

	/**
	 * 按规格查合同信息
	 * 
	 * @param spec
	 * @return
	 */
	public CoreReturnObject doQueryMat(String spec, String codeJgBl) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryMatSpec");
		sql += " AND T.SPEC_JG_DESC IN ('" + spec + "')";
		sql += " AND INSTR(T.CODE_BL_ALL,'" + codeJgBl + "') > 0";
		return this.getData(sql);
	}

	/**
	 * 新增合同附加要求信息 （QCM_ADD_ASK）
	 * 
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject insertQcmAddAsk(ArrayList<String> arrayList) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = "";
		for (int i = 0; i < arrayList.size(); i++) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPro.insertQcmAddAsk");
			QcmAddAskEntity qcmAddAskEntity = EntityTool.getEntityByJSONStr(
					arrayList.get(i), QcmAddAskEntity.class);
			sql = EntityTool.fillSqlByEntity(sql, qcmAddAskEntity);
			sqllist.add(sql);
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 修改单重 （COM_MSC_JG）
	 * 
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject doUpdateJgWt(ArrayList<String> arrayList,
			String woId) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = "";
		String CodeJg = "";
		for (int i = 0; i < arrayList.size(); i++) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPro.doUpdateJgWt");
			ComMscJgEntity qcmAddAskEntity = EntityTool.getEntityByJSONStr(
					arrayList.get(i), ComMscJgEntity.class);
			sql = EntityTool.fillSqlByEntity(sql, qcmAddAskEntity);
			sqllist.add(sql);

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPro.doUpdateJgCouplingWt");

			sql = EntityTool.fillSqlByEntity(sql, qcmAddAskEntity);
			sqllist.add(sql);
		}

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

	/**
	 * 查询送判数据
	 * 
	 * @param list
	 * @param startTim
	 * @param endTim
	 * @param departMentId
	 * @param plineCode
	 * @param value
	 * @return
	 */
	public CoreReturnObject QueryZgJugdeApply(ArrayList<String> parmList,
			String[] arr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.QueryZgJugdeApply");
		if (!parmList.get(2).equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + parmList.get(2) + "'";
		}
		if (!parmList.get(0).equals("")) {
			sql = sql += " AND T.APPLY_TIME >=TO_DATE('" + parmList.get(0)
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.APPLY_TIME <=TO_DATE('"
					+ parmList.get(1) + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		if (!parmList.get(4).equals("")) {
			sql += " AND T.PRO_ORDER_ID = '" + parmList.get(4) + "'";
		}

		return this.getData(sql);
	}

	/***
	 * 查询炉信息
	 * 
	 * @param parmList
	 * @param arr
	 * @return
	 */
	public CoreReturnObject doQueryMat(ArrayList<String> parmList, String[] arr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryMat");
		if (!parmList.get(0).equals("")) {
			// sql += " AND T.INSTOCK_TIME >=TO_DATE('"
			// + parmList.get(0)
			// + "', 'YYYY-MM-DD HH24:MI:SS')AND T.INSTOCK_TIME <=TO_DATE('"
			// + parmList.get(1) + "', 'YYYY-MM-DD HH24:MI:SS')";
			sql = sql
					.replace(
							"#INSTOCK_TIME#",
							" AND T.CREATE_TIME >=TO_DATE('"
									+ parmList.get(0)
									+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
									+ parmList.get(1)
									+ "', 'YYYY-MM-DD HH24:MI:SS')");
		} else {
			sql = sql.replace("#INSTOCK_TIME#", " ");
		}
		if (!parmList.get(2).equals("")) {
			// sql += " AND T.JUDGE_STOVE_NO = '" + parmList.get(2) + "'";
			sql = sql.replace("#JUDGE_STOVE_NO#", " AND T.JUDGE_STOVE_NO ='"
					+ parmList.get(2) + "'");
		} else {
			sql = sql.replace("#JUDGE_STOVE_NO#", " ");
		}
		// if (!parmList.get(4).equals("")) {
		// // sql += " AND T.JUDGE_STOVE_NO = '" + parmList.get(2) + "'";
		// sql = sql.replace("#PROCESS_CDOE#", " AND T.PROCESS_CDOE ='"
		// + parmList.get(4) + "'");
		// } else {
		// sql = sql.replace("#PROCESS_CDOE#", " ");
		// }
		// sql += CoreConverter.toSqlConditionString("T.BELONG_CODE", arr);
		if (!parmList.get(4).equals("")) {
			sql = sql.replace("#WO_ID#", " AND T.WO_ID = '" + parmList.get(4)
					+ "'");
		} else {
			sql = sql.replace("#WO_ID#", "");
		}
		return this.getData(sql);
	}

	// public CoreReturnObject doQueryMat(String spec) {
	// String sql = CoreXmlSqlParsersFactory
	// .getSql("FrmCouplingApplPro.doQueryMatSpec");
	// sql += " AND T.SPEC_NAME IN '" + spec + "'";
	// return this.getData(sql);
	// }

	/**
	 * 查询加工线前工序紧急放行数据
	 */
	public CoreReturnObject doQueryQcmZgApplyData(String judgeNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryQcmZgApplyData");
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeNo + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 查询回磅重量
	 */
	public CoreReturnObject getQueryWt(String judgeStoveNo, String rownum) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryWt");
		if (!judgeStoveNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "'";
			if (!rownum.equals("")) {
				sql += " AND ROWNUM <= '" + Integer.parseInt(rownum) + "'";
			}
		}
		return this.getData(sql);
	}

	/**
	 * 查询热处理是否下发
	 */
	public CoreReturnObject getQueryPlnRclM(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.getQueryPlnRclM");
		if (!judgeStoveNo.equals("")) {
			sql += " AND JUDGE_STOVE_NO = '" + judgeStoveNo + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 查询加工线是否下发
	 */
	public CoreReturnObject getQueryPlnJgx(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.getQueryPlnJgx");
		if (!judgeStoveNo.equals("")) {
			sql += " AND JUDGE_STOVE_NO = '" + judgeStoveNo + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 查询热处理类型
	 */
	public CoreReturnObject doQueryHttType(String heatNo, String judgeNo,
			String plinCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryHttType");
		if (!heatNo.equals("")) {
			sql += " AND T1.HEAT_PLAN_NO = '" + heatNo + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T1.JUDGE_STOVE_NO = '" + judgeNo + "'";
		}
		if (!plinCode.equals("")) {
			sql += " AND T1.PLINE_CODE = '" + plinCode + "'";
		}
		sql += " group by t1.process_code_c)";
		return this.getData(sql);
	}

	/**
	 * 查询储存位置
	 */
	public CoreReturnObject doQueryStorage(String judgeNo, String batchNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryStorage");
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeNo + "'";
		}
		if (!batchNo.equals("")) {
			sql += " AND T.BATCH_NO = '" + batchNo + "'";
		}
		sql += " GROUP BY T.JUDGE_STOVE_NO,T.BATCH_NO,T1.STORAGE_NAME";
		return this.getData(sql);
	}

	/**
	 * 查询储位
	 */
	public CoreReturnObject doQueryBsStorage(String addrNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryBsStorage");
		if (!addrNo.equals("")) {
			sql += " AND T.STORAGE_ADDR_NO = '" + addrNo + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 根据快速检索码查基础信息
	 * 
	 * @param SORTCODE
	 * @return
	 */
	public CoreReturnObject doQueryTestingGrade(String SORTCODE) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryTestingGrade");
		return this.getData(sql, new Object[] { SORTCODE });
	}

	/**
	 * 查询热处理回火温度和工艺制度
	 */
	public CoreReturnObject doQueryHttTemp(String heatNo, String judgeNo,
			String plinCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryHttTemp");
		if (!heatNo.equals("")) {
			// sql += " AND T1.HEAT_PLAN_NO = '" + heatNo + "'";
			sql = sql.replace("#HEAT_PLAN_NO#", "t2.HEAT_PLAN_NO = '" + heatNo
					+ "'");
			sql = sql.replace("#LHEAT_PLAN_NO#", "t.HEAT_PLAN_NO = '" + heatNo
					+ "'");
		}
		if (!plinCode.equals("")) {
			sql = sql.replace("#PLINE_CODE#", "t2.PLINE_CODE = '" + plinCode
					+ "'");
			sql = sql.replace("#LPLINE_CODE#", "t.PLINE_CODE = '" + plinCode
					+ "'");
		}
		return this.getData(sql);
	}

	/**
	 * 查询热处理回火温度和工艺制度
	 */
	public CoreReturnObject doQueryHttTempTech(String heatNo, String judgeNo,
			String plinCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryHttTempTech");
		if (!heatNo.equals("")) {
			// sql += " AND T1.HEAT_PLAN_NO = '" + heatNo + "'";
			sql = sql.replace("#LHEAT_PLAN_NO#", "t.HEAT_PLAN_NO = '" + heatNo
					+ "'");
		}
		if (!plinCode.equals("")) {
			sql = sql.replace("#LPLINE_CODE#", "t.PLINE_CODE = '" + plinCode
					+ "'");
		}
		return this.getData(sql);
	}

	/**
	 * 查询接箍是否下发
	 */
	public CoreReturnObject getQueryPlnJg(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.getQueryPlnJg");
		if (!judgeStoveNo.equals("")) {
			sql += " AND JUDGE_STOVE_NO = '" + judgeStoveNo + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 查询镦拔扩二级工序
	 */
	public CoreReturnObject getQueryProcess(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryProcess");
		if (!judgeStoveNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 查询热处理二级工序
	 */
	public CoreReturnObject getQueryProcessRcl(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.getQueryProcessRcl");
		if (!judgeStoveNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 查询加工线二级工序
	 * 
	 * @param judgeStoveNo
	 * @return
	 */
	public CoreReturnObject getQueryProcessJgx(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.getQueryProcessJgx");
		if (!judgeStoveNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeStoveNo + "'";
		}
		return this.getData(sql);
	}

	/***
	 * 查询炉批详细信息
	 * 
	 * @param heatPlanNo
	 * @param judgeNo
	 * @param value
	 * @return
	 */
	public CoreReturnObject doQueryJudgeBath(String woid, String judgeNo,
			String jugdeApplyCode, String value) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryJudgeBath");
		if (value.equals("0")) {
			// sql += " AND T.JUGDE_APPLY_CODE IS NULL";
			sql = sql.replace("#JUGDE_APPLY_CODE#", " AND T.DETER_NO IS NULL");
		} else if (value.equals("1")) {
			// sql += " AND T.JUGDE_APPLY_CODE IS NOT NULL";
			sql = sql.replace("#JUGDE_APPLY_CODE#",
					" AND T.DETER_NO IS NOT NULL");
		} else {
			sql = sql.replace("#JUGDE_APPLY_CODE#", " ");
		}
		if (!woid.equals("")) {
			sql = sql.replace("#WO_ID#", " AND T.WO_ID = '" + woid + "'");
		} else {
			sql = sql.replace("#WO_ID#", "");
		}
		if (!judgeNo.equals("")) {
			sql = sql.replace("#JUDGE_STOVE_NO#", " AND T.JUDGE_STOVE_NO = '"
					+ judgeNo + "'");
		} else {
			sql = sql.replace("#JUDGE_STOVE_NO#", "");
		}
		if ("".equals(jugdeApplyCode)) {
			sql = sql
					.replace("#JUGDE_APPLY_CODE2#", " AND T.DETER_NO IS  NULL");
		} else {
			sql = sql.replace("#JUGDE_APPLY_CODE2#", " AND T.DETER_NO = '"
					+ jugdeApplyCode + "'");
		}

		sql = sql
				.replace(
						"#GROUP_BY#",
						" GROUP BY T.DETER_NO,T.JUDGE_STOVE_NO,T.BATCH_NO,T.DETER_NO_SEQ,t.WO_ID,T1.ORDER_NO,T1.ORDER_SEQ,T1.ORDER_SEQ_NO,T1.CRAFT_SEQ_ORD,T1.CRAFT_FILE_NO_ORD");
		return this.getData(sql);
	}

	/***
	 * 查询炉批详细信息数量
	 * 
	 * @param heatPlanNo
	 * @param judgeNo
	 * @param value
	 * @return
	 */
	public CoreReturnObject doQueryJudgeBathCount(String heatPlanNo,
			String judgeNo, String value) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryJudgeBathCount");
		if (value.equals("0")) {
			sql += " AND T.DETER_NO IS NULL";
		} else if (value.equals("1")) {
			sql += " AND T.DETER_NO IS NOT NULL";
		}
		sql += " GROUP BY T.DETER_NO,T.JUDGE_STOVE_NO,T.BATCH_NO,T.DETER_NO_SEQ";
		return this.getData(sql, new Object[] { heatPlanNo, judgeNo });
	}

	/***
	 * 查询判定表
	 * 
	 * @param heatPlanNo
	 * @param judgeNo
	 * @param value
	 * @return
	 */
	public CoreReturnObject doQueryQcmApply(String heatPlanNo, String judgeNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryQcmApply");
		if (!heatPlanNo.equals("")) {
			sql += " AND T.HEAT_PLAN_NO = '" + heatPlanNo + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeNo + "'";
		}
		sql += " group by T.HTT_TYPE, T.MIN_TEMP, T.HTT_TECHNOLOGY,T.NOTCH_INFO,T.NOTCH_LENGTH,T.NOTCH_WIDTH,T.NOTCH_DEPTH";
		return this.getData(sql);
		// return this.getData(sql, new Object[] { heatPlanNo, judgeNo });
	}

	/**
	 * 撤销申请判定限制
	 */
	public CoreReturnObject SelectValueFlag(String judgeCode, String judgeseq,
			String judgeNo, String batchNo, String plinCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.SelectValueFlagData");
		if (!judgeCode.equals("")) {
			sql += " AND T.JUGDE_APPLY_CODE = '" + judgeCode + "'";
		}
		if (!judgeseq.equals("")) {
			sql += " AND T.JUGDE_APPLY_SEQUENO = '" + judgeseq + "'";
		}
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeNo + "'";
		}
		if (!batchNo.equals("")) {
			sql += " AND T.BATCH_NO = '" + batchNo + "'";
		}
		if (!plinCode.equals("")) {
			sql += " AND T.PLINE_CODE = '" + plinCode + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 撤销申请判定限制
	 */
	public CoreReturnObject doQueryProcessDesc(String judgeNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryProcessDesc");
		if (judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeNo + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 撤销申请判定限制
	 */
	public CoreReturnObject doQueryProcessRclDesc(String judgeNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryProcessRclDesc");
		if (!judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeNo + "'";
		}
		return this.getData(sql);
	}

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

		try {
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, judNo);
			psta.setObject(2, judNo);
			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;
	}

	/***
	 * 回报过磅重量
	 * 
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updateProWgt(ArrayList<String> parmList,
			ArrayList<Object> arrList) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		int acount = 0;
		int k = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务

			String updateProssWtSql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPro.updateProWgt");
			PreparedStatement updateProssPsta = connection
					.prepareStatement(updateProssWtSql);
			ArrayList<String> matNoList = new ArrayList<String>();
			for (int i = 0; i < arrList.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) arrList.get(i);
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPro.selectCount");
				psta = connection.prepareStatement(sql);
				psta.setString(1, list.get(0));
				psta.setString(2, list.get(2));
				psta.setString(3, list.get(3));
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPro.selectMatNo");
				psta = connection.prepareStatement(sql);
				psta.setString(1, list.get(0));
				psta.setString(2, list.get(2));
				psta.setString(3, list.get(3));
				rs = psta.executeQuery();
				while (rs.next()) {
					matNoList.add(rs.getString("MAT_NO"));
				}
				rs.close();
				psta.close();
				List<double[]> list1 = MeanValueCalculation.MeanCalculationPro(
						Double.parseDouble(list.get(1)), acount);
				for (int j = 0; j < list1.size(); j++) {
					double[] conW = list1.get(j);
					if ((int) conW[0] >= 0) {
						for (int z = 0; z < (int) conW[0]; z++) {
							updateProssPsta.setString(1, String
									.valueOf(conW[1]));
							updateProssPsta.setString(2, matNoList.get(k));
							updateProssPsta.setString(3, list.get(0));
							updateProssPsta.setString(4, list.get(2));
							updateProssPsta.setString(5, list.get(3));
							updateProssPsta.addBatch();
							k++;
						}
					}
				}
				updateProssPsta.executeBatch();
			}
			cro.setV_errMsg("回报成功!");
			connection.commit();
		} catch (SQLException e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 申请判定
	 * 
	 * @param parmList
	 * @param memo
	 * @return
	 */
	public CoreReturnObject doDecision(ArrayList<String> parmList,
			String userName, ArrayList<String> list, String num) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String judgeApplyNo = "";// 申请判定单号
		String judgeAppNo = "";// 已申请判定单号
		int judgeSequenNo = 1;// 申请判定顺序号
		String path = "";// 表检报告路径
		String face = "";// 判断标间是否有数据

		String minTemp = ""; // 最低回火温度
		String httTechnology = ""; // 热处理工艺制度
		String codeBL = ""; // 热处理备料码
		String[] belong = null;
		int acount = 0;
		String groupFlag = "";
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat dd = new SimpleDateFormat("yyyyMMdd");
		String systime = dateFormat.format(now);
		String yearMoth = "";//改25号结转
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			ArrayList<String> sqllist = new ArrayList<String>();

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

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

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPro.SelectNodeFlagVrp");

			sql = EntityTool.fillSqlByEntity(sql, EntityTool
					.getEntityByJSONStr(parmList.get(0),
							CouplingMatMEntity.class));
			psta = connection.prepareStatement(sql);
			rs = psta.executeQuery();

			List<PlnZyJgWorkbillEntity> plnMEntity = EntityTool.getEntitysByRs(
					rs, PlnZyJgWorkbillEntity.class);
			rs.close();
			psta.close();
			yearMoth = StringTool.GetBalYear(now,StringTool.GetSupplyUnit(plnMEntity.get(0).getPlineCode()));//改25号结转

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPro.jugdeApplyNo");// 生成判定单号
			sql = EntityTool.fillSqlByEntity(sql, EntityTool
					.getEntityByJSONStr(parmList.get(0),
							CouplingMatMEntity.class));
			psta = connection.prepareStatement(sql);
			rs = psta.executeQuery();
			if (rs.next()) {
				judgeApplyNo = rs.getString("JUGDE_APPLY_CODE");
			}
			rs.close();
			psta.close();
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPro.SelectJudegNoSequenNo");// 查询申请判定顺序号
			psta = connection.prepareStatement(sql);
			psta.setString(1, judgeAppNo);
			rs = psta.executeQuery();
			if (rs.next()) {
				judgeSequenNo = Integer.parseInt(rs
						.getString("JUGDE_APPLY_SEQUENO"));
			}
			rs.close();
			psta.close();

			belong = getBelongJudge(connection, EntityTool.getEntityByJSONStr(
					list.get(0), PlnGxJgPropSEntity.class));

			int m = 0;
			for (String str : parmList) {
				for (String strList : list) {

					CouplingMatMEntity matBcEntity = EntityTool
							.getEntityByJSONStr(str, CouplingMatMEntity.class);
					PlnGxJgPropSEntity plnSaleEntity = EntityTool
							.getEntityByJSONStr(strList,
									PlnGxJgPropSEntity.class);

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmCouplingApplPro.SelectCodeBl");// 查询热处理备料码
					psta = connection.prepareStatement(sql);
					psta.setString(1, matBcEntity.getJudgeStoveNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						codeBL = rs.getString("codeBL");
					}
					rs.close();
					psta.close();
					if (!codeBL.equals("")) {
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmCouplingApplPro.SelectCodeBlOrder");// 查询热处理备料码与成品合同
						psta = connection.prepareStatement(sql);
						psta.setString(1, plnSaleEntity.getOrderNo());
						psta.setString(2, plnSaleEntity.getOrderSeq());
						psta.setString(3, codeBL);
						rs = psta.executeQuery();
						if (rs.next()) {
							acount = Integer.parseInt(rs.getString("ACOUNT"));
						}
						rs.close();
						psta.close();
						if(acount == 0){
							cro.setV_errMsg("合同还缺少备料码【" +codeBL+ "】，请联系工艺人员！");
							return cro;
						}
					}

					String belongCode = "";
					String belongName = "";
					String sqlloading = CoreXmlSqlParsersFactory
							.getSql("FrmInLibrary.selectBelong");
					psta = connection.prepareStatement(sqlloading);
					if (matBcEntity.getPlineCode() == null
							|| matBcEntity.getPlineCode() == "") {
						psta.setObject(1, "");
					} else {
						psta.setObject(1, matBcEntity.getPlineCode());
					}
					rs = psta.executeQuery();
					if (rs.next()) {
						belongCode = rs.getString("DEPARTMENT_CODE");
						belongName = rs.getString("DEPARTMENT_DESC");
					}
					rs.close();
					psta.close();

					String ORD_LN_DLY_PK = "";
					String ORD_LN_PK = "";
					String STD_NAME = "";
					String STD_CODE = "";
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmCouplingApplPro.SelectOrdLnDlyPK");// 查询ORD_LN_DLY_PK,ORD_LN_PK，标准
					psta = connection.prepareStatement(sql);
					psta.setString(1, plnSaleEntity.getOrderNo());
					psta.setString(2, plnSaleEntity.getOrderSeq());
					rs = psta.executeQuery();
					if (rs.next()) {
						ORD_LN_DLY_PK = rs.getString("ORD_LN_DLY_PK");
						ORD_LN_PK = rs.getString("ORD_LN_PK");
						STD_NAME = rs.getString("STD_NAME");
						STD_CODE = rs.getString("STD_CODE");
					}
					rs.close();
					psta.close();

					// 获取材料号
					String matNo = doAddMatNo(matBcEntity.getJudgeStoveNo(),
							connection);
					// 获取交易单号
					String dealOrde = doAddDealOrde("IA", "800701", connection);
					pstaMatM.setObject(1, matNo);
					pstaMatM.setObject(2, matBcEntity.getProNum());
					pstaMatM.setObject(3, matBcEntity.getProWt());
					pstaMatM.setObject(4, judgeApplyNo);
					pstaMatM.setObject(5, String.valueOf(judgeSequenNo));
					pstaMatM.setObject(6, matBcEntity.getMatNo());
					pstaMatM.addBatch();
					pstaMatM.executeBatch();
					pstaMatM.close();

					pstaMatButters.setObject(1, matNo);
					pstaMatButters.setObject(2, matBcEntity.getProNum());
					pstaMatButters.setObject(3, matBcEntity.getProWt());
					pstaMatButters.setObject(4, matBcEntity.getMatNo());
					pstaMatButters.addBatch();
					pstaMatButters.executeBatch();
					pstaMatButters.close();

					pstaMatDeal.setObject(1, dealOrde);
					pstaMatDeal.setObject(2, matNo);
					pstaMatDeal.setObject(3, matBcEntity.getProNum());
					pstaMatDeal.setObject(4, matBcEntity.getProWt());
					pstaMatDeal.setObject(5, matBcEntity.getMatNo());
					pstaMatDeal.addBatch();
					pstaMatDeal.executeBatch();
					pstaMatDeal.close();

					String designKey = "";
					String indexSeq = "";
					String craftSeq = "";
					String craftFileNo = "";
					String baseCode = "";
					String baseName = "";
					String testingStandar = ""; // 探伤标准

					m++;
					// matBcEntity.setJugdeApplyCode(judgeApplyNo);
					// matBcEntity.setJugdeApplyTime(systime);
					QcmZgJugdeApplyEntity qcmEntity = new QcmZgJugdeApplyEntity();
					qcmEntity.setMatNo(matBcEntity.getMatNo());
					qcmEntity.setInputCount(matBcEntity.getProNum()); // 投料量
					qcmEntity.setInputWeight(matBcEntity.getProWt()); // 投料支
					qcmEntity.setOutputCount(matBcEntity.getProNum());
					qcmEntity.setOutputWeight(matBcEntity.getProWt());
					qcmEntity.setTestingStandar(testingStandar); // 探伤标准
					qcmEntity.setStorageName("");
					qcmEntity.setJugdeApplyCode(judgeApplyNo);
					qcmEntity.setJugdeApplySequeno(String
							.valueOf(judgeSequenNo));
					qcmEntity.setStoveNo(matBcEntity.getStoveNo());
					qcmEntity.setLotNo("1");
					qcmEntity.setJudgeStoveNo(matBcEntity.getJudgeStoveNo());
					qcmEntity.setBatchNo(matBcEntity.getBatchNo());
					qcmEntity.setBatchGroudNo("001");
					qcmEntity.setQualityGroup("1");
					if (plnMEntity.size() == 0) {
						qcmEntity.setMaterialNo(plnSaleEntity.getBlWlId());
						qcmEntity.setMaterialName(plnSaleEntity.getBlWlDesc());
						qcmEntity
								.setProduccode(plnSaleEntity.getProduccodeJg());
						qcmEntity.setProducname(plnSaleEntity
								.getProduccodeJgDesc());
						qcmEntity.setStdStyle(plnSaleEntity.getStdStyle());
						qcmEntity.setStdStyleDesc(plnSaleEntity
								.getStdStyleDesc());
						qcmEntity.setSpecCode(plnSaleEntity.getSpecJg());
						qcmEntity.setSpecName(plnSaleEntity.getSpecJgDesc());

						qcmEntity.setHeatPlanNo("");
						qcmEntity.setLoadBatchNo("");
					} else {
						qcmEntity.setMaterialNo(plnMEntity.get(0).getOutwlId());
						qcmEntity.setMaterialName(plnMEntity.get(0)
								.getOutwlDesc());
						qcmEntity.setProduccode(plnMEntity.get(0)
								.getProduccodeJg());
						qcmEntity.setProducname(plnMEntity.get(0)
								.getProduccodeJgDesc());
						qcmEntity.setStdStyle(plnMEntity.get(0).getStdStyle());
						qcmEntity.setStdStyleDesc(plnMEntity.get(0)
								.getStdStyleDesc());
						qcmEntity.setSpecCode(plnMEntity.get(0).getSpecJg());
						qcmEntity
								.setSpecName(plnMEntity.get(0).getSpecJgDesc());

						qcmEntity.setHeatPlanNo(plnMEntity.get(0)
								.getHeatPlanNo());
						qcmEntity
								.setLoadBatchNo(plnMEntity.get(0).getBatchNo());
					}

					qcmEntity.setStdCode(STD_CODE);
					qcmEntity.setStdName(STD_NAME);
					qcmEntity.setSteelcode(matBcEntity.getSteelcode());
					qcmEntity.setSteelname(matBcEntity.getSteelname());
					qcmEntity.setModelCode(matBcEntity.getModelCode());
					qcmEntity.setModelDesc(matBcEntity.getModelDesc());
					qcmEntity.setGradecode(matBcEntity.getGradecode());
					qcmEntity.setGradename(matBcEntity.getGradename());
					qcmEntity.setActDimater(matBcEntity.getOutdiameter());
					qcmEntity.setActHeight(matBcEntity.getWallthick());
					qcmEntity.setActLenMin("");
					qcmEntity.setActLenMax("");
					qcmEntity.setActLen(matBcEntity.getAimlength());
					qcmEntity.setActCount(matBcEntity.getProNum());
					// qcmEntity.setActTheoryWeight(matBcEntity.getActWeight());
					// qcmEntity.setActWeight(matBcEntity.getPonderGrossWt());
					qcmEntity.setActTheoryWeight(matBcEntity.getProWt());
					// if (matBcEntity.getPonderGrossWt().equals("")) {
					qcmEntity.setActWeight(matBcEntity.getProWt());
					qcmEntity.setProOrderNo(plnSaleEntity.getOrderNo() + "/"
							+ plnSaleEntity.getOrderSeq());
					if (ORD_LN_DLY_PK.equals("")) {
						qcmEntity.setOrdLnDlyPk(plnSaleEntity.getOrdLnDlyPk());
					} else {
						qcmEntity.setOrdLnDlyPk(ORD_LN_DLY_PK);
					}

					qcmEntity.setProOrderId(matBcEntity.getWoId());
					qcmEntity.setGxPlanNo("");
					qcmEntity.setProPlanIdNext("");
					qcmEntity.setGxPlanNoNext("");
					qcmEntity.setHeatPlanNoNext("");
					qcmEntity.setPlineCode(matBcEntity.getPlineCode());
					qcmEntity.setPlineName(matBcEntity.getPlineName());
					qcmEntity.setBelongCode(belongCode);
					qcmEntity.setBelongName(belongName);
					qcmEntity.setNextProcessCdoe("");
					qcmEntity.setLotNoGroup("");
					qcmEntity
							.setLoadJudgeStoveNo(matBcEntity.getJudgeStoveNo());

					qcmEntity.setValidflag("20");
					qcmEntity.setApplyTime(systime);
					qcmEntity.setApplyName(userName);
					qcmEntity.setMemo("");
					qcmEntity.setIsendgx("1");
					qcmEntity.setApplyFlag("0");
					qcmEntity.setBalYearMonth(yearMoth);
					if (path == null) {
						qcmEntity.setFaceResultPath("");
					} else {
						qcmEntity.setFaceResultPath(path);
					}
					qcmEntity.setSpecResultPath("");
					qcmEntity.setChemResultPath("");
					qcmEntity.setPhyResultPath("");
					qcmEntity.setWpressureResultPath("");
					qcmEntity.setProcessResultPath("");
					String liku = "";
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmCouplingApplPro.SelectLiku");// 查询利库标志
					sql = EntityTool.fillSqlByEntity(sql, EntityTool
							.getEntityByJSONStr(parmList.get(0),
									PlnZyJgWorkbillEntity.class));
					psta = connection.prepareStatement(sql);
					rs = psta.executeQuery();
					if (rs.next()) {
						liku = rs.getString("LOCK_LIKU") == null ? "" : rs
								.getString("LOCK_LIKU");
					}
					rs.close();
					psta.close();
					if (liku.equals("是")) {
						qcmEntity.setLkFlag("1");
					} else {
						qcmEntity.setLkFlag("0");
					}
					// if (matBcEntity.getLockLiku().equals("是")) {
					// qcmEntity.setLkFlag("1");
					// } else {
					// qcmEntity.setLkFlag("0");
					// }
					qcmEntity.setInstockFlag("0");

					qcmEntity.setBelongCodeJugde(belong[0]);// 判定后所属权
					qcmEntity.setBelongNameJugde(belong[1]);// 判定后所属权
					qcmEntity.setProcessCode("H");
					qcmEntity.setTarget("A");

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmCouplingApplPro.SelectCraftNoByPK");// 根据PK值查询工艺文件号，工艺文件序号
					psta = connection.prepareStatement(sql);
					psta.setString(1, ORD_LN_PK);
					rs = psta.executeQuery();
					if (rs.next()) {
						craftFileNo = rs.getString("CRAFT_NO");
						craftSeq = rs.getString("CRAFT_SEQ");
					}
					rs.close();
					psta.close();

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmCouplingApplPro.SelectCraftNo");// 计划里查找工艺文件号，工艺序号
					sql = EntityTool.fillSqlByEntity(sql, EntityTool
							.getEntityByJSONStr(parmList.get(0),
									PlnZyJgWorkbillEntity.class));
					psta = connection.prepareStatement(sql);
					rs = psta.executeQuery();
					if (rs.next()) {
						// craftSeq = rs.getString("CRAFT_SEQ");
						// craftFileNo = rs.getString("CRAFT_FILE_NO");
						indexSeq = rs.getString("INDEX_SEQ");
					}
					rs.close();
					psta.close();
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmCouplingApplPro.SelectDesignKey");// 查询designkey和mscPline
					psta = connection.prepareStatement(sql);
					psta.setString(1, plnSaleEntity.getCraftFileNo());
					psta.setString(2, plnSaleEntity.getCraftSeq());
					rs = psta.executeQuery();
					if (rs.next()) {
						designKey = rs.getString("DESGIN_KEY");
					}
					rs.close();
					psta.close();

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmCouplingApplPro.SelectMinTemp");// 查询热处理工艺制度和最低回火温度
					psta = connection.prepareStatement(sql);
					psta.setString(1, matBcEntity.getJudgeStoveNo());
					rs = psta.executeQuery();
					if (rs.next()) {
						minTemp = rs.getString("MIN_TEMP");
						httTechnology = rs.getString("HTT_TECHNOLOGY");
					}
					rs.close();
					psta.close();

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmCouplingApplPro.SelectBaseCodeState");// 查询交货状态
					psta = connection.prepareStatement(sql);
					sql = EntityTool.fillSqlByEntity(sql, EntityTool
							.getEntityByJSONStr(parmList.get(0),
									CouplingMatMEntity.class));
					psta = connection.prepareStatement(sql);
					rs = psta.executeQuery();
					if (rs.next()) {
						baseCode = rs.getString("BASECODE");
						baseName = rs.getString("BASENAME");
					}
					rs.close();
					psta.close();

					if (minTemp == null)
						minTemp = "";
					if (httTechnology == null)
						httTechnology = "";
					if (baseCode == null)
						baseCode = "";
					if (baseName == null)
						baseName = "";

					qcmEntity.setZpMLh("");
					qcmEntity.setZpColl("");
					qcmEntity.setCraftSeq(craftSeq);
					if (indexSeq == null) {
						qcmEntity.setIndexSeq("000001");
					} else {
						qcmEntity.setIndexSeq(indexSeq);
					}
					qcmEntity.setCic("");
					qcmEntity.setPic("");
					qcmEntity.setSic("");
					qcmEntity.setDic("");
					qcmEntity.setWic("");
					qcmEntity.setGic("");
					qcmEntity.setCheckNo("");
					qcmEntity.setDeliveryStateCode(baseCode);
					qcmEntity.setDeliveryStateName(baseName);
					// if(craftFileNo==null)
					// {
					// qcmEntity.setCrafNo("");
					// }else{
					qcmEntity.setCrafNo(craftFileNo);
					// }
					qcmEntity.setHttType("");
					qcmEntity.setMinTemp(minTemp);
					qcmEntity.setHttTechnology(httTechnology);
					qcmEntity.setNotchInfo("");
					qcmEntity.setNotchLength("");
					qcmEntity.setNotchWidth("");
					qcmEntity.setNotchDepth("");
					qcmEntity.setTestPressure("");
					qcmEntity.setHoldtimeTime("");
					qcmEntity.setTestPressureY("");
					if (face == null || face == "") {
						qcmEntity.setFaceResultCode("");
					} else {
						qcmEntity.setFaceResultCode("40740601");
					}
					qcmEntity.setTestingGrade("");
					qcmEntity.setTestingType("");
					qcmEntity.setDetectResultCode("");
					qcmEntity.setMatGowhereCode("");
					qcmEntity.setMatGowhereName("");
					qcmEntity.setJudgeResultCode(matBcEntity
							.getJudgeResultCode());
					qcmEntity.setJudgeResult(matBcEntity.getJudgeResult());
					qcmEntity.setJudgeResultTime(matBcEntity
							.getJudgeResultTime());

					String insertJugdeApplySql = CoreXmlSqlParsersFactory
							.getSql("FrmCouplingApplPro.insertJugdeApply");
					insertJugdeApplySql = EntityTool.fillSqlByEntity(
							insertJugdeApplySql, qcmEntity);
					sqllist.add(insertJugdeApplySql);

					String updateMatBcSql = CoreXmlSqlParsersFactory
							.getSql("FrmCouplingApplPro.updateMatBcJugdeApplyCode");
					updateMatBcSql = EntityTool.fillSqlByEntity(updateMatBcSql,
							qcmEntity);
					sqllist.add(updateMatBcSql);

					// String updateMatBcButt = CoreXmlSqlParsersFactory
					// .getSql("FrmCouplingApplPro.updateMatBcButter");// 修改库位
					// updateMatBcSql =
					// EntityTool.fillSqlByEntity(updateMatBcButt,
					// qcmEntity);
					// sqllist.add(updateMatBcSql);

					// String updatePlnZy = CoreXmlSqlParsersFactory
					// .getSql("FrmCouplingApplPro.updatePlnZyJgMiddleWork");//
					// 修改工单计划状态为生产完成
					// updatePlnZy = EntityTool.fillSqlByEntity(updatePlnZy,
					// matBcEntity);
					// sqllist.add(updatePlnZy);

					// String insertMatQcmBackSql = CoreXmlSqlParsersFactory
					// .getSql("FrmCouplingApplPro.insertMatQcmBack");
					// insertMatQcmBackSql = EntityTool.fillSqlByEntity(
					// insertMatQcmBackSql, qcmEntity);
					// sqllist.add(insertMatQcmBackSql);

					judgeSequenNo++;
				}
				cro = this.getDao(CoreConstantData.sysbeanstr)
						.ExcuteTransction(sqllist);
				if (cro.getV_errMsg().equals("")) {
					cro.setV_errMsg("转成品箍成功!");
					connection.commit();
				}
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 撤销申请判定
	 * 
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject cancelDoDecision(ArrayList<String> parmList) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String valueFlag = "";// 转成品标志位
		String applyNo = "";// 申请判定单
		int acount = 0;
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for (String str : parmList) {
				QcmZgJugdeApplyEntity matBcEntity = EntityTool
						.getEntityByJSONStr(str, QcmZgJugdeApplyEntity.class);

				if (!matBcEntity.getJudgeTolresult().equals("")) {
					cro.setV_errMsg("已综合判定，不能撤销!");
					return cro;
				}

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPro.SelectMatMackupAcount");// 查询接箍是否出库
				sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("acount"));
				}
				rs.close();
				psta.close();

				if (acount > 0) {
					cro.setV_errMsg("已出库，不能撤销!");
					return cro;
				}

				String updateSql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPro.updateQcmJudgeApply");
				updateSql = EntityTool.fillSqlByEntity(updateSql, matBcEntity);
				sqllist.add(updateSql);

				String deleteSql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPro.deleteQcmJudgeApply");
				deleteSql = EntityTool.fillSqlByEntity(deleteSql, matBcEntity);
				sqllist.add(deleteSql);

				// String updatePlnZy = CoreXmlSqlParsersFactory
				// .getSql("FrmCouplingApplPro.updatePlnZyJgMiddleCancel");//
				// 修改工单计划状态为生产中
				// updatePlnZy = EntityTool.fillSqlByEntity(updatePlnZy,
				// matBcEntity);
				// sqllist.add(updatePlnZy);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
					sqllist);
			if (cro.getV_errMsg().equals("")) {
				cro.setV_errMsg("撤销成功!");
				cro.setResult(applyNo);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 获取判定后所属权
	 * 
	 * @param matBcEntity
	 * @return
	 * @throws SQLException
	 */
	@SuppressWarnings("null")
	private String[] getBelongJudge(Connection con,
			PlnGxJgPropSEntity plnSaleEntity) throws SQLException {
		String[] belong = new String[2];
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.SelectOrderSlaOrg");// 查询合同所属部门
		sql = EntityTool.fillSqlByEntity(sql, plnSaleEntity);
		psta = con.prepareStatement(sql);
		rs = psta.executeQuery();
		if (rs.next()) {
			belong[0] = rs.getString("SALE_ORG");
			belong[1] = rs.getString("SALE_ORG_DESC");
		}
		rs.close();
		psta.close();
		if (belong[0] == null) {
			belong[0] = "002001001";
			belong[1] = "制造部";
		}
		return belong;
	}

	/**
	 * 查询水压
	 * 
	 * @param heatNo
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject doQueryWicValue(String heatNo, String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryWicValue");
		return this.getData(sql, new Object[] { heatNo, judgeStoveNo });
	}

	/**
	 * 查询加工通径结果
	 * 
	 * @param heatNo
	 * @param judgeStoveNo
	 * @return
	 */
	public CoreReturnObject doQueryMchPathResult(String heatNo,
			String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryMchPathResult");
		return this.getData(sql, new Object[] { heatNo, judgeStoveNo });
	}

	/**
	 * 查询加工倒棱结果
	 * 
	 * @param heatNo
	 * @param judgeStoveNo
	 * @return
	 */
	public CoreReturnObject doQueryMchChamferingResult(String heatNo,
			String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryMchChamferingResult");
		return this.getData(sql, new Object[] { heatNo, judgeStoveNo });
	}

	/**
	 * 查询加工拧接结果
	 * 
	 * @param heatNo
	 * @param judgeStoveNo
	 * @return
	 */
	public CoreReturnObject doQueryMchTwistinglyResult(String heatNo,
			String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryMchTwistinglyResult");
		return this.getData(sql, new Object[] { heatNo, judgeStoveNo });
	}

	/**
	 * 查询探伤结果
	 * 
	 * @param heatNo
	 * @param judgeStoveNo
	 * @param PROCESS_CODE
	 * @return
	 */
	public CoreReturnObject doQueryHttCrackDetectionEt(String heatNo,
			String judgeStoveNo, String PROCESS_CODE) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.doQueryHttCrackDetectionEt");
		return this.getData(sql, new Object[] { heatNo, judgeStoveNo,
				PROCESS_CODE });
	}
}
