package com.steering.mes.mcp.coup;

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.Vrp.MeanValueCalculation;
import com.steering.mes.mcp.entity.ComMscJgEntity;
import com.steering.mes.mcp.entity.CouplingMatMEntity;
import com.steering.mes.mcp.entity.MatBcMEntity;
import com.steering.mes.mcp.entity.PlnZyJgEntity;
import com.steering.mes.mcp.entity.PlnZyJgxMEntity1;
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 FrmCouplingApplPh extends DBCommon {

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

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

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

	/**
	 * 新增合同附加要求信息 （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("FrmCouplingApplPh.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("FrmCouplingApplPh.doUpdateJgWt");
			ComMscJgEntity qcmAddAskEntity = EntityTool.getEntityByJSONStr(
					arrayList.get(i), ComMscJgEntity.class);
			sql = EntityTool.fillSqlByEntity(sql, qcmAddAskEntity);
			sqllist.add(sql);

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPh.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("FrmCouplingApplPh.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(3).equals("0")) {
			sql += " AND T.JUGDE_APPLY_CODE IS NULL";
		} else if (parmList.get(3).equals("1")) {
			sql += " AND T.JUGDE_APPLY_CODE IS NOT NULL";
			sql += " AND T.JUDGE_RESULT_CODE IS NULL";
		}
		if (parmList.get(3).equals("2")) {
			sql += " AND T.JUDGE_RESULT_CODE IS NOT NULL";
		}

		return this.getData(sql);
	}

	/***
	 * 查询炉信息
	 * 
	 * @param parmList
	 * @param arr
	 * @return
	 */
	public CoreReturnObject doQueryMat(ArrayList<String> parmList, String[] arr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPh.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 T1.Apply_Time >=TO_DATE('"
									+ parmList.get(0)
									+ "', 'YYYY-MM-DD HH24:MI:SS')AND T1.Apply_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(3).equals("0")) {
			// sql += " AND T.JUGDE_APPLY_CODE IS NULL";
			sql = sql.replace("#JUGDE_APPLY_CODE#", " AND T.DETER_NO IS NULL");
		} else if (parmList.get(3).equals("1")) {
			// sql += " AND T.JUGDE_APPLY_CODE IS NOT NULL";
			sql = sql.replace("#JUGDE_APPLY_CODE#",
					" AND T.DETER_NO IS NOT NULL");
			sql = sql.replace("#JUDGE_RESULT_CODE#",
					" AND T1.JUDGE_RESULT_CODE IS NULL");
		} else {
			sql = sql.replace("#JUGDE_APPLY_CODE#", " ");
		}
		if (parmList.get(3).equals("2")) {
			// sql += " AND T1.JUDGE_RESULT_CODE IS NOT NULL";
			sql = sql.replace("#JUDGE_RESULT_CODE#",
					" AND T1.JUDGE_RESULT_CODE IS NOT NULL");
		} else {
			sql = sql.replace("#JUDGE_RESULT_CODE#", "");
		}
		// 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#", "");
		}
		sql = sql
				.replace(
						"#BELONG_CODE#",
						"AND T.PLINE_CODE IN  (  SELECT PLINE_CODE FROM COM_BASE_PLINE  WHERE VALIDFLAG='1'   "
								+ CoreConverter.toSqlConditionString(
										"DEPARTMENT_CODE", arr) + ")");
		sql = sql
				.replace(
						"#GROUP_BY#",
						" GROUP BY T.JUDGE_STOVE_NO,T.WO_ID,t.DETER_NO,t.BATCH_NO,MI.ORDER_NO,MI.ORDER_SEQ,MI.ORDER_SEQ_NO,MI.CRAFT_SEQ_ORD,MI.CRAFT_FILE_NO_ORD ");
		return this.getData(sql);
	}

	/**
	 * 查询加工线前工序紧急放行数据
	 */
	public CoreReturnObject doQueryQcmZgApplyData(String judgeNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.getQueryPlnRclM");
		if (!judgeStoveNo.equals("")) {
			sql += " AND JUDGE_STOVE_NO = '" + judgeStoveNo + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 查询加工线是否下发
	 */
	public CoreReturnObject getQueryPlnJgx(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.doQueryTestingGrade");
		return this.getData(sql, new Object[] { SORTCODE });
	}

	/**
	 * 查询热处理回火温度和工艺制度
	 */
	public CoreReturnObject doQueryHttTemp(String heatNo, String judgeNo,
			String plinCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.getQueryPlnJg");
		if (!judgeStoveNo.equals("")) {
			sql += " AND JUDGE_STOVE_NO = '" + judgeStoveNo + "'";
		}
		return this.getData(sql);
	}

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

	/**
	 * 查询热处理二级工序
	 */
	public CoreReturnObject getQueryProcessRcl(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.doQueryProcessDesc");
		if (judgeNo.equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + judgeNo + "'";
		}
		return this.getData(sql);
	}

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

	// /***
	// * 回报过磅重量
	// *
	// * @param parmList
	// * @return
	// */
	// public CoreReturnObject updateProWgt(ArrayList<String>
	// parmList,ArrayList<String> 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("insertProssWt.updateProWgt");
	// PreparedStatement updateProssPsta = connection
	// .prepareStatement(updateProssWtSql);
	// ArrayList<String> matNoList = new ArrayList<String>();
	// sql = CoreXmlSqlParsersFactory.getSql("insertProssWt.selectCount");
	// psta = connection.prepareStatement(sql);
	// psta.setString(1, parmList.get(0));
	// psta.setString(2, parmList.get(2));
	// rs = psta.executeQuery();
	// if (rs.next()) {
	// acount = Integer.parseInt(rs.getString("ACOUNT"));
	// }
	// rs.close();
	// psta.close();
	//
	// sql = CoreXmlSqlParsersFactory.getSql("insertProssWt.selectMatNo");
	// psta = connection.prepareStatement(sql);
	// psta.setString(1, parmList.get(0));
	// psta.setString(2, parmList.get(2));
	// rs = psta.executeQuery();
	// while (rs.next()) {
	// matNoList.add(rs.getString("MAT_NO"));
	// }
	// rs.close();
	// psta.close();
	// List<double[]> list1 = MeanValueCalculation.MeanCalculationPro(
	// Double.parseDouble(parmList.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, String.valueOf(conW[1]));
	// updateProssPsta.setString(3, matNoList.get(k));
	// updateProssPsta.setString(4, parmList.get(0));
	// updateProssPsta.setString(5, parmList.get(2));
	// 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
	 * @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("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.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) {
		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 detecePath = "";// 探伤报告路径
		String belongCodeJudge = "";
		String belongNameJudge = "";
		String heatPlanNo = "";
		String inputWeight = "";
		String inputCount = "";
		String zpMLh = "";
		String zpColl = "";
		String groupId = "";
		String[] belong = null;
		int judgeAppCount = 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 = df.format(now);
		try {
			ArrayList<String> sqllist = new ArrayList<String>();

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPh.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();

			// 判定字头问题
			if (EntityTool.getEntityByJSONStr(parmList.get(0),
					PlnZyJgWorkbillEntity.class).getDecision().equals("A")) {
				EntityTool.getEntityByJSONStr(parmList.get(0),
						CouplingMatMEntity.class).setProductFlag("801402");
			} else {
				EntityTool.getEntityByJSONStr(parmList.get(0),
						CouplingMatMEntity.class).setProductFlag("801401");
			}
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPh.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("FrmCouplingApplPh.SelectJudegNo");// 查询该炉是否已申请判定过了
			sql = EntityTool.fillSqlByEntity(sql, EntityTool
					.getEntityByJSONStr(parmList.get(0),
							CouplingMatMEntity.class));
			psta = connection.prepareStatement(sql);
			rs = psta.executeQuery();
			if (rs.next()) {
				judgeAppNo = rs.getString("JUGDE_APPLY_CODE");
			}
			rs.close();
			psta.close();

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPh.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(
					parmList.get(0), CouplingMatMEntity.class));

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPh.SelectJudegApplyCount");// 查询是否已送判
			psta = connection.prepareStatement(sql);
			psta.setString(1, EntityTool.getEntityByJSONStr(parmList.get(0),
					CouplingMatMEntity.class).getJudgeStoveNo());
			psta.setString(2, "H");
			rs = psta.executeQuery();
			if (rs.next()) {
				judgeAppCount = Integer.parseInt(rs.getString("ACOUNT"));
			}
			rs.close();
			psta.close();

			String status = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPh.SelectJgStuts");// 查询是否结炉
			psta = connection.prepareStatement(sql);
			psta.setString(1, EntityTool.getEntityByJSONStr(parmList.get(0),
					CouplingMatMEntity.class).getWoId());
			rs = psta.executeQuery();
			if (rs.next()) {
				status = rs.getString("STATION_STATUS");
				if (status.equals("1")) {
					cro.setV_errMsg("该工单" + rs.getString("STATION_DESC")
							+ "未结炉！");
					return cro;
				}
			}
			rs.close();
			psta.close();

			// //查询四项
			// String demandDetect= "";//查询探伤要求
			// String demandBlast = "";//查询喷砂要求
			// String demandCopper = "";//查询压印喷标
			// String demandBonder = "";//查询磷化镀铜
			// sql =
			// CoreXmlSqlParsersFactory.getSql("FrmCouplingApplPh.SelectDemand");//查询要求
			// psta = connection.prepareStatement(sql);
			// psta.setString(1, EntityTool
			// .getEntityByJSONStr(parmList.get(0),
			// CouplingMatMEntity.class).getWoId());
			// rs = psta.executeQuery();
			// if(rs.next())
			// {
			// demandCopper =
			// rs.getString("DEMAND_COPPER")==null?"":rs.getString("DEMAND_COPPER");
			// demandDetect =
			// rs.getString("DEMAND_DETECTION")==null?"":rs.getString("DEMAND_DETECTION");
			// demandBlast =
			// rs.getString("DEMAND_BLAST")==null?"":rs.getString("DEMAND_BLAST");
			// demandBonder =
			// rs.getString("DEMAND_BONDERIZING")==null?"":rs.getString("DEMAND_BONDERIZING");
			// String YaCopp = "";
			// String PenCopp = "";
			// String LinCopp = "";
			// String TanCopp = "";
			// String ShaCopp = "";
			// sql =
			// CoreXmlSqlParsersFactory.getSql("FrmCouplingApplPh.SelectDemandYayin");//查询要求压印
			// psta = connection.prepareStatement(sql);
			// psta.setString(1, EntityTool
			// .getEntityByJSONStr(parmList.get(0),
			// CouplingMatMEntity.class).getWoId());
			// rs = psta.executeQuery();
			// if(rs.next())
			// {
			// YaCopp = rs.getString("EMB_COUNT");
			// }
			// rs.close();
			// psta.close();
			//
			// sql =
			// CoreXmlSqlParsersFactory.getSql("FrmCouplingApplPh.SelectDemandPen");//查询要求磷化喷标
			// psta = connection.prepareStatement(sql);
			// psta.setString(1, EntityTool
			// .getEntityByJSONStr(parmList.get(0),
			// CouplingMatMEntity.class).getWoId());
			// rs = psta.executeQuery();
			// if(rs.next())
			// {
			// if(rs.getString("SPRAY_COUNT")==null)
			// {
			// PenCopp ="0";
			// }else{
			// PenCopp = rs.getString("SPRAY_COUNT");//喷标
			// }
			// if(rs.getString("COL_COUNT")==null)
			// {
			// LinCopp ="0";
			// }else{
			// LinCopp = rs.getString("COL_COUNT");//磷化
			// }
			//
			// }
			// rs.close();
			// psta.close();
			//
			// sql =
			// CoreXmlSqlParsersFactory.getSql("FrmCouplingApplPh.SelectDemandTan");//查询要求探伤
			// psta = connection.prepareStatement(sql);
			// psta.setString(1, EntityTool
			// .getEntityByJSONStr(parmList.get(0),
			// CouplingMatMEntity.class).getWoId());
			// rs = psta.executeQuery();
			// if(rs.next())
			// {
			// if(rs.getString("INSPECT_PIECES")==null||rs.getString("INSPECT_PIECES").equals(""))
			// {
			// TanCopp="0";
			// }else{
			// TanCopp = rs.getString("INSPECT_PIECES");//探伤
			// }
			//
			// }
			// rs.close();
			// psta.close();
			//
			// sql =
			// CoreXmlSqlParsersFactory.getSql("FrmCouplingApplPh.SelectDemandSha");//查询要求喷砂
			// psta = connection.prepareStatement(sql);
			// psta.setString(1, EntityTool
			// .getEntityByJSONStr(parmList.get(0),
			// CouplingMatMEntity.class).getWoId());
			// rs = psta.executeQuery();
			// if(rs.next())
			// {
			// if(rs.getString("SPRAY_COUNT")==null)
			// {
			// ShaCopp = "0";
			// }else{
			// ShaCopp = rs.getString("SPRAY_COUNT");//喷砂
			// }
			//
			// }
			// rs.close();
			// psta.close();
			//
			// if (demandCopper.equals("40840301")) {
			// if(YaCopp==null||YaCopp.equals("")||Integer.parseInt(YaCopp)<=0)
			// {
			// cro.setV_errMsg("该工单有压印要求但压印个数为零,不允许送判!");
			// return cro;
			// }
			//
			// }else if(demandCopper.equals("40840302"))
			// {
			// if(Integer.parseInt(PenCopp)<=0)
			// {
			// cro.setV_errMsg("该工单有喷标要求但喷标个数为零,不允许送判!");
			// return cro;
			// }
			// }else if(demandCopper.equals("40840303"))
			// {
			// if(Integer.parseInt(YaCopp)<=0||Integer.parseInt(PenCopp)<=0)
			// {
			// cro.setV_errMsg("该工单有压印、喷标要求但压印、喷标个数为零,不允许送判!");
			// return cro;
			// }
			// }
			//
			// if(demandDetect.equals("40840101"))
			// {
			// if(TanCopp==null||TanCopp.equals("")||Integer.parseInt(TanCopp)<=0)
			// {
			// cro.setV_errMsg("该工单有探伤要求但探伤个数为零,不允许送判!");
			// return cro;
			// }
			// }
			//
			// if(demandBlast.equals("40840401"))
			// {
			// if(ShaCopp==null||ShaCopp.equals("")||Integer.parseInt(ShaCopp)<=0)
			// {
			// cro.setV_errMsg("该工单有喷砂要求但喷砂个数为零,不允许送判!");
			// return cro;
			// }
			// }
			//
			//
			// }
			// rs.close();
			// psta.close();
			String belongCode = "";
			String belongName = "";
			String sqlloading = CoreXmlSqlParsersFactory
					.getSql("FrmInLibrary.selectBelong");
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, plnMEntity.get(0).getPlineCode());
			rs = psta.executeQuery();
			if (rs.next()) {
				belongCode = rs.getString("DEPARTMENT_CODE");
				belongName = rs.getString("DEPARTMENT_DESC");
			}
			rs.close();
			psta.close();

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

				PlnZyJgWorkbillEntity matBcEntity = EntityTool
						.getEntityByJSONStr(str, PlnZyJgWorkbillEntity.class);
				// 两台电脑操作，没有刷新判断是否重复
				int COUNT = 0;
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPh.QueryCode");
				sql = EntityTool.fillSqlByEntity(sql, EntityTool
						.getEntityByJSONStr(str, CouplingMatMEntity.class));
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if (rs.next()) {
					COUNT = Integer.parseInt(rs.getString("COUNT"));
				}
				rs.close();
				psta.close();
				if (COUNT < Integer.parseInt(matBcEntity.getProNum())) {
					cro.setV_errMsg("该炉已经送判,不允许重复送判!");
					return cro;
				}
				String deter = "";
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPh.QueryDeterNo");
				sql = EntityTool.fillSqlByEntity(sql, EntityTool
						.getEntityByJSONStr(str, CouplingMatMEntity.class));
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if (rs.next()) {
					deter = rs.getString("DETER") == null ? "" : rs
							.getString("DETER");
				}
				rs.close();
				psta.close();
				if (!deter.equals("0")) {
					cro.setV_errMsg("该工单已经送判,不允许重复送判!");
					return cro;
				}

				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.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(plnMEntity.get(0).getStoveNo());
				qcmEntity.setLotNo("1");
				qcmEntity.setJudgeStoveNo(matBcEntity.getJudgeStoveNo());
				qcmEntity.setBatchNo(matBcEntity.getBatchNo());
				qcmEntity.setBatchGroudNo("001");
				qcmEntity.setQualityGroup("1");
				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.setSteelcode(matBcEntity.getSteelcode());
				qcmEntity.setSteelname(matBcEntity.getSteelname());
				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.setModelCode(matBcEntity.getModelCode());
				qcmEntity.setModelDesc(matBcEntity.getModelDesc());
				qcmEntity.setGradecode(matBcEntity.getGradecode());
				qcmEntity.setGradename(matBcEntity.getGradename());
				qcmEntity.setStdCode(plnMEntity.get(0).getStdCode());
				qcmEntity.setStdName(plnMEntity.get(0).getStdName());
				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());
				// } else {
				// qcmEntity.setActWeight(matBcEntity.getPonderGrossWt());
				// }
				String orderInfo = "";
				String ordLn = "";
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPh.SelectOrderInfo");// 查询midd里合同信息
				sql = EntityTool.fillSqlByEntity(sql, EntityTool
						.getEntityByJSONStr(parmList.get(0),
								PlnZyJgWorkbillEntity.class));
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if (rs.next()) {
					orderInfo = rs.getString("PRO_ORDER_NO");
					ordLn = rs.getString("ORD_LN_DLY_PK");
				}
				rs.close();
				psta.close();
				if (orderInfo == null || orderInfo == "") {
					qcmEntity.setProOrderNo("");
				} else {
					qcmEntity.setProOrderNo(orderInfo);
				}
				if (ordLn == null || ordLn == "") {
					qcmEntity.setOrdLnDlyPk("");
				} else {
					qcmEntity.setOrdLnDlyPk(ordLn);
				}

				qcmEntity.setProOrderId(plnMEntity.get(0).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("");
				// if (!matBcEntity.getTarget().equals(
				// plnMEntity.get(0).getDecision())) {
				// cro.setV_errMsg("申请判定字头和计划字头不一致，不允许申请判定!");
				// return cro;
				// }
				qcmEntity.setLoadJudgeStoveNo(plnMEntity.get(0)
						.getJudgeStoveNo());
				qcmEntity.setValidflag("00");
				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);
				}
				/*
				 * if(detecePath == null) { qcmEntity.setDetectResultPath("");
				 * }else{ qcmEntity.setDetectResultPath(detecePath); }
				 */
				qcmEntity.setSpecResultPath("");
				qcmEntity.setChemResultPath("");
				qcmEntity.setPhyResultPath("");
				qcmEntity.setWpressureResultPath("");
				qcmEntity.setProcessResultPath("");
				String liku = "";
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPh.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");

				if(plnMEntity.get(0).getDecision().equals("A")){
					qcmEntity.setBelongCodeJugde(belong[0]);// 判定后所属权
					qcmEntity.setBelongNameJugde(belong[1]);// 判定后所属权
				}else{
					qcmEntity.setBelongCodeJugde("002001001");// 判定后所属权
					qcmEntity.setBelongNameJugde("生产计划部");// 判定后所属权
				}
				
				qcmEntity.setProcessCode("H");
				qcmEntity.setTarget(plnMEntity.get(0).getDecision());
				qcmEntity.setHeatPlanNo(plnMEntity.get(0).getHeatPlanNo());
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPh.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("FrmVrpApplyNew.SelectDesignKey");// 查询designkey和mscPline
				psta = connection.prepareStatement(sql);
				psta.setString(1, craftFileNo);
				psta.setString(2, craftFileNo);
				rs = psta.executeQuery();
				if (rs.next()) {
					designKey = rs.getString("DESGIN_KEY");
				}
				rs.close();
				psta.close();

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.SelectBaseCode1");// 查询交货状态
				psta = connection.prepareStatement(sql);
				psta = connection.prepareStatement(sql);
				psta.setString(1, designKey);
				psta.setString(2, indexSeq);
				psta.setString(3, plnMEntity.get(0).getDecision());
				rs = psta.executeQuery();
				if (rs.next()) {
					baseCode = rs.getString("BASECODE");
					baseName = rs.getString("BASENAME");
				}
				rs.close();
				psta.close();

				// sql = CoreXmlSqlParsersFactory
				// .getSql("FrmCouplingApplPh.SelectBaseCode1");// 查询交货状态
				// psta = connection.prepareStatement(sql);
				// psta.setString(1, designKey);
				// psta.setString(2, indexSeq);
				// psta.setString(3, plnMEntity.get(0).getDecision());
				// rs = psta.executeQuery();
				// if (rs.next()) {
				// baseCode = rs.getString("BASECODE");
				// baseName = rs.getString("BASENAME");
				// }
				// rs.close();
				// psta.close();
				qcmEntity.setZpMLh("");
				qcmEntity.setZpColl("");
				qcmEntity.setCraftSeq(matBcEntity.getCraftSeq());
				if (indexSeq == null) {
					qcmEntity.setIndexSeq("");
				} 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("");
				qcmEntity.setHttTechnology("");
				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("");

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

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

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

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

				String insertMatQcmBackSql = CoreXmlSqlParsersFactory
						.getSql("FrmCouplingApplPh.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("申请判定成功!");
			}
		} 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 applyNo = "";// 申请判定单
		String count = "";
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			// for (String str : parmList) {
			PlnZyJgWorkbillEntity matBcEntity = EntityTool.getEntityByJSONStr(
					parmList.get(0), PlnZyJgWorkbillEntity.class);
			applyNo = matBcEntity.getDeterNo();

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpApplyNew.SelectApplyNo");// 查询库存支数与送判支数是否一致
			psta = connection.prepareStatement(sql);
			psta.setString(1, applyNo);
			psta.setString(2, applyNo);
			rs = psta.executeQuery();
			if (rs.next()) {
				count = rs.getString("ACOUNT");
			}
			rs.close();
			psta.close();
			/*if (!count.equals("0")) {
				cro.setV_errMsg("该炉号库存不足,不允许撤销送判!");
				return cro;
			}*/

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

			String updatePlnZy = CoreXmlSqlParsersFactory
					.getSql("FrmCouplingApplPh.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,
			CouplingMatMEntity matBcEntity) throws SQLException {
		String[] belong = new String[2];
		String departMentCode = "";// 现有产线部门
		String nextDrpartMentCode = "";// 下一工序产线部门
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPh.SelectPlineBelong");
		sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
		psta = con.prepareStatement(sql);
		rs = psta.executeQuery();
		if (rs.next()) {
			departMentCode = rs.getString("DEPARTMENT_CODE");
		}
		rs.close();
		psta.close();
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPh.SelectOrderSlaOrg");// 查询合同所属部门
		sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
		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("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.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("FrmCouplingApplPh.doQueryHttCrackDetectionEt");
		return this.getData(sql, new Object[] { heatNo, judgeStoveNo,
				PROCESS_CODE });
	}
}
