package com.steering.mes.mcp.Vrp;

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

import com.ibm.ws.webservices.xml.wassysapp.systemApp;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.mes.mcp.entity.MatBcMEntity;
import com.steering.mes.mcp.entity.PlnZyJgxMEntity1;
import com.steering.mes.mcp.entity.QcmZgJugdeApplyEntity;
import com.steering.mes.mcp.entity.QcmAddAskEntity;

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 FrmVrpApplyNew extends DBCommon {

	public CoreReturnObject getQueryRemark(String JudegStoveNO,String HeatPlanNo){
		String sql = CoreXmlSqlParsersFactory.getSql("FrmVrpApplyNew.getQueryRemark");
		return this.getData(sql,new Object[]{JudegStoveNO,HeatPlanNo});
	}

	public CoreReturnObject doQueryDeliveryNo(String ordLnPk) {
		String sql = "select T.ORD_LN_DLY_PK BASECODE,T.DELIVERY_NO BASENAME from SLM_ORDER_LINE_DELIVERY t where t.ord_ln_pk = '"+ordLnPk+"'\r\n" ;
		return this.getData(sql);
	}

	

	/***
	 * 查询炉信息
	 * 
	 * @param parmList
	 * @param arr
	 * @return
	 */
	public CoreReturnObject doQueryMat(ArrayList<String> parmList, String[] arr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.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.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')");
		} 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.JUGDE_APPLY_CODE 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.JUGDE_APPLY_CODE 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);
		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 +=
		// " GROUP BY T.HEAT_PLAN_NO,T.LOT_NO,T.JUDGE_STOVE_NO,T.PROCESS_CDOE,T.NEXT_PROCESS_CDOE";
		sql = sql
				.replace(
						"#GROUP_BY#",
						" GROUP BY T.HEAT_PLAN_NO_OLD,T.HEAT_PLAN_NO,T.LOT_NO,T.JUDGE_STOVE_NO,T.PROCESS_CDOE,T.NEXT_PROCESS_CDOE,T.JUGDE_APPLY_CODE");
		System.out.println(sql);
		return this.getData(sql);
	}

	/**
	 * 查询热处理槽长槽宽槽深
	 */
	public CoreReturnObject doQueryHttData(String heatNo, String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.doQueryHttData");
		if (!heatNo.equals("")) {
			sql += " AND T.HEAT_PLAN_NO = '" + heatNo + "'";
		}
		if (!plineCode.equals("")) {
			sql += " AND T.PLINE_CODE = '" + plineCode + "'";
		}
		return this.getData(sql);
	}

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

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

	/**
	 * 查询回磅重量
	 */
	public CoreReturnObject getQueryWt(String judgeStoveNo, String rownum) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.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("FrmVrpApplyNew.getQueryPlnRclM");
		if (!judgeStoveNo.equals("")) {
			sql += " AND JUDGE_STOVE_NO = '" + judgeStoveNo + "'";
		}
		return this.getData(sql);
	}

	/**
	 * 查询加工线是否下发
	 */
	public CoreReturnObject getQueryPlnJgx(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.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("FrmVrpApplyNew.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("FrmVrpApplyNew.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_NO,T1.STORAGE_NAME";
		return this.getData(sql);
	}

	/**
	 * 查询储位
	 */
	public CoreReturnObject doQueryBsStorage(String addrNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.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("FrmVrpApplyNew.doQueryTestingGrade");
		return this.getData(sql, new Object[] { SORTCODE });
	}

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

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

	/**
	 * 查询热处理二级工序
	 */
	public CoreReturnObject getQueryProcessRcl(String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.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("FrmVrpApplyNew.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 heatPlanNo, String judgeNo,
			String jugdeApplyCode, String value) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.doQueryJudgeBath");
		if (value.equals("0")) {
			// sql += " AND T.JUGDE_APPLY_CODE IS NULL";
			sql = sql.replace("#JUGDE_APPLY_CODE#",
					" AND T.JUGDE_APPLY_CODE IS NULL");
		} else if (value.equals("1")) {
			// sql += " AND T.JUGDE_APPLY_CODE IS NOT NULL";
			sql = sql.replace("#JUGDE_APPLY_CODE#",
					" AND T.JUGDE_APPLY_CODE IS NOT NULL");
		} else {
			sql = sql.replace("#JUGDE_APPLY_CODE#", " ");
		}

		if ("".equals(jugdeApplyCode)) {
			sql = sql.replace("#JUGDE_APPLY_CODE2#",
					" AND T.JUGDE_APPLY_CODE IS  NULL");
		} else {
			sql = sql.replace("#JUGDE_APPLY_CODE2#",
					" AND T.JUGDE_APPLY_CODE = '" + jugdeApplyCode + "'");
		}

		sql = sql
				.replace(
						"#GROUP_BY#",
						" GROUP BY T.HEAT_PLAN_NO_OLD,T.JUDGE_RESULT_TIME,T.JUGDE_APPLY_CODE,T.LOT_NO,T.STOVE_NO,T.JUDGE_STOVE_NO,T.BATCH_NO,T.BATCH_GROUD_NO,T.PRO_ORDER_NO,T.HEAT_PLAN_NO,T.PRO_PLAN_ID_NEXT,T.GX_PLAN_NO_NEXT,T.JUGDE_APPLY_SEQUENO,T.HEAT_PLAN_NO_NEXT,T.ORD_LN_DLY_PK,   t.LENGTH_TYPE");
		// sql +=
		// " GROUP BY T.JUGDE_APPLY_CODE,T.LOT_NO,T.STOVE_NO,T.JUDGE_STOVE_NO,T.BATCH_NO,T.BATCH_GROUD_NO,T.HEAT_PLAN_NO,T.PRO_PLAN_ID_NEXT,T.GX_PLAN_NO_NEXT,T.JUGDE_APPLY_SEQUENO,T.HEAT_PLAN_NO_NEXT";
		//System.out.println(sql);
		return this.getData(sql, new Object[] { heatPlanNo, judgeNo,
				heatPlanNo, judgeNo });
	}
	
	public CoreReturnObject doSaveOrdLnDlyPk(ArrayList<String > parmList) 
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		try {
			connection.setAutoCommit(false);
			String updateMatSql  = "";
			
			for (String str : parmList) {
			MatBcMEntity matBcEntity = EntityTool
				.getEntityByJSONStr(str, MatBcMEntity.class);
			updateMatSql = CoreXmlSqlParsersFactory
			.getSql("FrmVrpApplyNew.doSaveOrdLnDlyPk");
			String strLengType = matBcEntity.getLengthType().equals("正尺") ? "0" : matBcEntity.getLengthType().equals("长尺") ? "1": matBcEntity.getLengthType().equals("短尺") ? "2":  matBcEntity.getLengthType();
			matBcEntity.setLengthType(strLengType);
			updateMatSql = EntityTool.fillSqlByEntity(updateMatSql, matBcEntity);
			psta = connection.prepareStatement(updateMatSql);
			psta.addBatch();
			psta.executeBatch();
			}
			cro.setResult(1);
			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 heatPlanNo
	 * @param judgeNo
	 * @param value
	 * @return
	 */
	public CoreReturnObject doQueryJudgeBathCount(String heatPlanNo,
			String judgeNo, String value) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.doQueryJudgeBathCount");
		if (value.equals("0")) {
			sql += " AND T.JUGDE_APPLY_CODE IS NULL";
		} else if (value.equals("1")) {
			sql += " AND T.JUGDE_APPLY_CODE IS NOT NULL";
		}
		sql += " GROUP BY T.JUGDE_APPLY_CODE,T.LOT_NO,T.STOVE_NO,T.JUDGE_STOVE_NO,T.BATCH_NO,T.BATCH_GROUD_NO,T.HEAT_PLAN_NO,T.PRO_PLAN_ID_NEXT,T.GX_PLAN_NO_NEXT,T.JUGDE_APPLY_SEQUENO,T.HEAT_PLAN_NO_NEXT";
		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("FrmVrpApplyNew.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 groupNo, String plinCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.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 (!groupNo.equals("")) {
			sql += " AND T.BATCH_GROUD_NO = '" + groupNo + "'";
		}
		if (!plinCode.equals("")) {
			sql += " AND T.PLINE_CODE = '" + plinCode + "'";
		}
		return this.getData(sql);
	}

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

	/**
	 * 撤销申请判定限制
	 */
	public CoreReturnObject doQueryProcessRclDesc(String judgeNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.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("insertProssWt.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("insertProssWt.selectCount");
				psta = connection.prepareStatement(sql);
				psta.setString(1, list.get(0));
				psta.setString(2, list.get(2));
				psta.setString(3, list.get(3));
				psta.setString(4, list.get(4));
				psta.setString(5, list.get(5));
				psta.setString(6, list.get(6));
				psta.setString(7, list.get(7));
				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, list.get(0));
				psta.setString(2, list.get(2));
				psta.setString(3, list.get(3));
				psta.setString(4, list.get(4));
				psta.setString(5, list.get(5));
				psta.setString(6, list.get(6));
				psta.setString(7, list.get(7));
				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, String
									.valueOf(conW[1]));
							updateProssPsta.setString(3, list.get(8));
							updateProssPsta.setString(4, matNoList.get(k));
							updateProssPsta.setString(5, list.get(0));
							updateProssPsta.setString(6, list.get(2));
							updateProssPsta.setString(7, list.get(3));
							updateProssPsta.setString(8, list.get(4));
							updateProssPsta.setString(9, list.get(5));
							updateProssPsta.setString(10, list.get(7));
							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;
	}

	private Object lock = new Object();

	/***
	 * 申请判定
	 * 
	 * @param parmList
	 * @param memo
	 * @return
	 */
	public CoreReturnObject doDecision(ArrayList<String> parmList, String memo,
			String userName, String Process, String gx) {

		synchronized (lock) { // 增加同步锁 防止不同电脑同时送判,送判单号一致.

			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 = 0;// 申请判定顺序号
			String path = "";// 表检报告路径
			String face = "";// 判断标间是否有数据
			String detecePath = "";// 探伤报告路径
			String belongCodeJudge = "";
			String belongNameJudge = "";
			String heatPlanNo = "";
			String inputWeight = "";
			String inputCount = "";
			String producType = ""; // 品名类型(A-钢管(坯)、B-套管+接箍、C-短节+附件、D-接箍、E-双公短节)
			String zpMLh = ""; // 组批主炉号
			String zpColl = ""; // 组批炉号集合
			String groupId = "";
			String[] belong = null;
			int judgeAppCount = 0;
			int noOkCount = 0;
			String groupFlag = "";
			String JudgeStoveNo = "";

			String JudgeWithCoupling = ""; // 若有接箍 实绩存在哪个炉号上
			String BatchNoWithCoupling = ""; // 若有接箍 实绩存在哪个炉号上

			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>();
				if (Process.equals("E")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectNodeFlagVrpLiku");
				} else if (Process.equals("F")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectNodeFlagHttLiku");
				} else if (Process.equals("G")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectNodeFlagMchLiku");
				}
				sql = EntityTool.fillSqlByEntity(sql,
						EntityTool.getEntityByJSONStr(parmList.get(0),
								MatBcMEntity.class));
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				// List<PlnZyDbkMEntity> plnMEntity =
				// EntityTool.getEntitysByRs(rs,
				// PlnZyDbkMEntity.class);
				// List<PlnZyRclMEntity1> plnMEntity =
				// EntityTool.getEntitysByRs(rs,
				// PlnZyRclMEntity1.class);
				List<PlnZyJgxMEntity1> plnMEntityLiku = EntityTool
						.getEntitysByRs(rs, PlnZyJgxMEntity1.class);
				rs.close();
				psta.close();

				// 查询轧管计划表里主制程索引号
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.SelectNodeFlagMchLikuD");

				sql = EntityTool.fillSqlByEntity(sql,
						EntityTool.getEntityByJSONStr(parmList.get(0),
								MatBcMEntity.class));
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				// List<PlnZyDbkMEntity> plnMEntity =
				// EntityTool.getEntitysByRs(rs,
				// PlnZyDbkMEntity.class);
				// List<PlnZyRclMEntity1> plnMEntity =
				// EntityTool.getEntitysByRs(rs,
				// PlnZyRclMEntity1.class);
				List<PlnZyJgxMEntity1> plnMEntityLikuD = EntityTool
						.getEntitysByRs(rs, PlnZyJgxMEntity1.class);
				rs.close();
				psta.close();

				if (Process.equals("E")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectNodeFlagVrp");
				} else if (Process.equals("F")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectNodeFlagHtt");
				} else if (Process.equals("G")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectNodeFlagMch");
				}
				sql = EntityTool.fillSqlByEntity(sql,
						EntityTool.getEntityByJSONStr(parmList.get(0),
								MatBcMEntity.class));
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				// List<PlnZyDbkMEntity> plnMEntity =
				// EntityTool.getEntitysByRs(rs,
				// PlnZyDbkMEntity.class);
				// List<PlnZyRclMEntity1> plnMEntity =
				// EntityTool.getEntitysByRs(rs,
				// PlnZyRclMEntity1.class);
				List<PlnZyJgxMEntity1> plnMEntity = EntityTool.getEntitysByRs(
						rs, PlnZyJgxMEntity1.class);
				rs.close();
				psta.close();
				if (Process.equals("") || Process == null) {
					cro.setV_errMsg("工序代码是空,请检查!");
					return cro;
				}
				//
				// if (EntityTool.getEntityByJSONStr(parmList.get(0),
				// MatBcMEntity.class).getTarget().equals("C")) {
				// if (Process.equals("E")) {
				// if (!plnMEntity.get(0).getBesideStatus().equals("60")) {
				// cro.setV_errMsg("该炉在下线点未结炉,不允许申请判定!");
				// return cro;
				// }
				// } else if (Process.equals("F")) {
				// if (!plnMEntity.get(0).getBesideStatus().equals("90")) {
				// cro.setV_errMsg("该炉在下线点未结炉,不允许申请判定!");
				// return cro;
				// }
				// } else if (Process.equals("G")) {
				// if (!plnMEntity.get(0).getBesideStatus().equals("11")) {
				// cro.setV_errMsg("该炉在下线点未结炉,不允许申请判定!");
				// return cro;
				// }
				// }
				// }
				//
				// if (EntityTool.getEntityByJSONStr(parmList.get(0),
				// MatBcMEntity.class).getTarget().equals("C")) {
				// if (Process.equals("E")) {
				// if (!plnMEntity.get(0).getBesideStatus().equals("60")) {
				// cro.setV_errMsg("该炉在下线点未结炉,不允许申请判定!");
				// return cro;
				// }
				// } else if (Process.equals("F")) {
				// if (!plnMEntity.get(0).getBesideStatus().equals("90")) {
				// cro.setV_errMsg("该炉在下线点未结炉,不允许申请判定!");
				// return cro;
				// }
				// } else if (Process.equals("G")) {
				// if (!plnMEntity.get(0).getBesideStatus().equals("11")) {
				// cro.setV_errMsg("该炉在下线点未结炉,不允许申请判定!");
				// return cro;
				// }
				// }
				// }

				// if (EntityTool
				// .getEntityByJSONStr(parmList.get(0), MatBcMEntity.class)
				// .getTarget().equals("C")) {
				// if (Process.equals("E")) {
				// if (!plnMEntity.get(0).getBesideStatus().equals("60")) {
				// cro.setV_errMsg("该炉在下线点未结炉,不允许申请判定!");
				// return cro;
				// }
				// } else if (Process.equals("F")) {
				// if (!plnMEntity.get(0).getBesideStatus().equals("90")) {
				// cro.setV_errMsg("该炉在下线点未结炉,不允许申请判定!");
				// return cro;
				// }
				// } else if (Process.equals("G")) {
				// if (!plnMEntity.get(0).getBesideStatus().equals("11")) {
				// cro.setV_errMsg("该炉在下线点未结炉,不允许申请判定!");
				// return cro;
				// }
				// }
				// }

				if (EntityTool.getEntityByJSONStr(parmList.get(0),
						MatBcMEntity.class).getTarget().equals("A")) {
					EntityTool.getEntityByJSONStr(parmList.get(0),
							MatBcMEntity.class).setProductFlag("801402");
				} else {
					EntityTool.getEntityByJSONStr(parmList.get(0),
							MatBcMEntity.class).setProductFlag("801401");
				}
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.jugdeApplyNo");// 生成判定单号
				sql = EntityTool.fillSqlByEntity(sql,
						EntityTool.getEntityByJSONStr(parmList.get(0),
								MatBcMEntity.class));
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if (rs.next()) {
					judgeApplyNo = rs.getString("JUGDE_APPLY_CODE");
				}
				rs.close();
				psta.close();
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.SelectJudegNo");// 查询该炉是否已申请判定过了
				sql = EntityTool.fillSqlByEntity(sql,
						EntityTool.getEntityByJSONStr(parmList.get(0),
								MatBcMEntity.class));
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if (rs.next()) {
					judgeAppNo = rs.getString("JUGDE_APPLY_CODE");
				}
				rs.close();
				psta.close();

				belong = getBelongJudge(connection,
						EntityTool.getEntityByJSONStr(parmList.get(0),
								MatBcMEntity.class));

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

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.SelectCount");// 查询上工序不合格数据
				psta = connection.prepareStatement(sql);
				psta.setString(1, EntityTool.getEntityByJSONStr(
						parmList.get(0), MatBcMEntity.class).getJudgeStoveNo());
				psta.setString(2, Process);
				psta.setString(3, EntityTool.getEntityByJSONStr(
						parmList.get(0), MatBcMEntity.class).getBatchNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					noOkCount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (noOkCount > 0) {
					cro.setV_errMsg("上工序判定不合，不能送判!");
					return cro;
				}

				if (Process.equals("E")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectIsGroupE");// 查询是否是组炉计划
				} else if (Process.equals("F")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectIsGroupF");// 查询是否是组炉计划
				} else if (Process.equals("G")) {
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectIsGroupG");// 查询是否是组炉计划
				}

				psta = connection.prepareStatement(sql);
				psta
						.setString(1, EntityTool.getEntityByJSONStr(
								parmList.get(0), MatBcMEntity.class)
								.getHeatPlanNoOld());
				psta.setString(2, EntityTool.getEntityByJSONStr(
						parmList.get(0), MatBcMEntity.class).getJudgeStoveNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					groupFlag = rs.getString("IF_MATCH_ODD");
				}
				rs.close();
				psta.close();

				// 投料量一次带走，第二次送判为0
				List<String> batchNos = new ArrayList<String>();
				String insertJugdeApplyLog = CoreXmlSqlParsersFactory
    					.getSql("FrmVrpApplyNew.insertJugdeApplyLog");// 送判记录
    			PreparedStatement insertJugdeApplyLogPsta = connection
    					.prepareStatement(insertJugdeApplyLog);
				for (String str : parmList) {

					judgeSequenNo++;

					ArrayList<String> heatPlanNoArr = new ArrayList<String>();
					MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(
							str, MatBcMEntity.class);
					JudgeStoveNo = matBcEntity.getJudgeStoveNo();
					// 查询表检报告路径
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectFaceResultPath");
					sql = EntityTool.fillSqlByEntity(sql, EntityTool
							.getEntityByJSONStr(str, MatBcMEntity.class));
					psta = connection.prepareStatement(sql);
					rs = psta.executeQuery();
					if (rs.next()) {
						path = rs.getString("FACE_RESULT_PATH");
						face = rs.getString("HEAT_PLAN_NO");
					}
					rs.close();
					psta.close();
					// 查询探伤报告路径
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectDeteceResultPath");
					sql = EntityTool.fillSqlByEntity(sql, EntityTool
							.getEntityByJSONStr(str, MatBcMEntity.class));
					psta = connection.prepareStatement(sql);
					rs = psta.executeQuery();
					if (rs.next()) {
						detecePath = rs.getString("REPORT_PATH");
					}
					rs.close();
					psta.close();

					// 两台电脑操作，没有刷新判断是否重复
					int COUNT = 0;
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.QueryCode");
					sql = EntityTool.fillSqlByEntity(sql, EntityTool
							.getEntityByJSONStr(str, MatBcMEntity.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.getActCount())) {
						cro.setV_errMsg("该炉已经送判,不允许重复送判!");
						return cro;
					}
					String designKey = "";
					String indexSeq = "";
					String craftSeq = "";
					String craftFileNo = "";
					String baseCode = "";
					String baseName = "";
					String testingStandar = ""; // 探伤标准

					// 查询探伤标准
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.SelectTestingStandar");
					sql = EntityTool.fillSqlByEntity(sql, EntityTool
							.getEntityByJSONStr(str, MatBcMEntity.class));
					psta = connection.prepareStatement(sql);
					rs = psta.executeQuery();
					if (rs.next()) {
						testingStandar = rs.getString("TESTING_STANDAR");
					}
					rs.close();
					psta.close();
					if (testingStandar == null) {
						testingStandar = "";
					}

					String supplyUnit = "120501";
					String supplyUnitDesc = "天津钢管制造有限公司";
					// 查询制造商
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.selectSupplyUnit");
					psta = connection.prepareStatement(sql);
					psta.setString(1, JudgeStoveNo);
					psta.setString(2, Process);
					rs = psta.executeQuery();
					if (rs.next()) {
						supplyUnit = rs.getString("SUPPLY_UNIT");
						supplyUnitDesc = rs.getString("SUPPLY_UNIT_DESC");
					}
					rs.close();
					psta.close();

					if (testingStandar == null) {
						testingStandar = "";
					}
					inputCount = "";
					inputWeight = "";
					//查询已送判的批号
					if (Process.equals("E")) {
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectBatchNoVrp");
					} else if (Process.equals("F")) {
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectBatchNoHtt");
					} else if (Process.equals("G")) {
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectBatchNoMch");
					}
					sql = EntityTool.fillSqlByEntity(sql, EntityTool
							.getEntityByJSONStr(str, MatBcMEntity.class));
					psta = connection.prepareStatement(sql);
					rs = psta.executeQuery();
					if (rs.next()) {
						batchNos.add(rs.getString("BATCH_NO"));
					}
					rs.close();
					psta.close();

					if (!batchNos.contains(matBcEntity.getBatchNo()) && !Process.equals("G")) {
						//之前投料量代码在这
						// 查询投料量
						if (Process.equals("E")) {
							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectInputCountVrp");
						} else if (Process.equals("F")) {
							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectInputCountHtt");
						} 
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(str, MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							inputCount = rs.getString("ACT_COUNT");
							inputWeight = rs.getString("ACT_WEIGHT");
							if (inputCount == null) {
								inputCount = "0";
								inputWeight = "0.0";
							}
						}
						rs.close();
						psta.close();
						batchNos.add(matBcEntity.getBatchNo());
					} else {
						inputCount = "0";
						inputWeight = "0.0";
					}
					//zhoujl 添加限制 本次判定管号提取出来 用于获取投料量 进行分割
					if(Process.equals("G")){
						String matSql = "--以下是2025-09-18 新增 判定量取申请送判的管的对应的投料量\n" +
			                    " and s.mat_no in (select s.mat_no\n" +
			                    "  from PORT_MCH_BATCH_SAMPLE_RESULT S\n" +
			                    " WHERE S.MAT_NO in\n" +
			                    "       (SELECT mat_no\n" +
			                    "          FROM (SELECT T.MAT_NO,\n" +
			                    "                       T.PLINE_CODE,\n" +
			                    "                       T.GX_PLAN_NO_NEXT,\n" +
			                    "                       T.CREATE_TIME\n" +
			                    "                  FROM MAT_BC_M T\n" +
			                    "                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'\n" +
			                    "                   AND T.BATCH_NO = '#BATCH_NO#'\n" +
			                    "                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'\n" +
			                    "                   AND T.PLINE_CODE = '#PLINE_CODE#'\n" +
			                    "                   AND NVL(T.PRO_ORDER_ID, '/') = NVL('#PRO_ORDER_ID#', '/')\n" +
			                    "                   AND NVL(T.GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')\n" +
			                    "                   AND NVL(T.HEAT_PLAN_NO, '/') = NVL('#HEAT_PLAN_NO#', '/')\n" +
			                    "                   AND (CASE\n" +
			                    "                            WHEN T.LENGTH_TYPE = 0 THEN '正尺'\n" +
			                    "                            WHEN T.LENGTH_TYPE = 1 THEN '长池'\n" +
			                    "                            WHEN T.LENGTH_TYPE = 2 THEN '短尺'\n" +
			                    "                            ELSE '/'\n" +
			                    "                        END\n" +
			                    "                        ) = NVL('#LENGTH_TYPE#', '/')\n" +
			                    "                   AND T.QCM_STAUS = '00'\n" +
			                    "                   AND T.JUGDE_APPLY_CODE IS NULL\n" +
			                    "                UNION\n" +
			                    "                SELECT T.MAT_NO,\n" +
			                    "                       T.PLINE_CODE,\n" +
			                    "                       T.GX_PLAN_NO_NEXT,\n" +
			                    "                       T.CREATE_TIME\n" +
			                    "                  FROM MAT_BC_BACKUP T\n" +
			                    "                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'\n" +
			                    "                   AND T.BATCH_NO = '#BATCH_NO#'\n" +
			                    "                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'\n" +
			                    "                   AND T.PLINE_CODE = '#PLINE_CODE#'\n" +
			                    "                   AND NVL(T.PRO_ORDER_ID, '/') = NVL('#PRO_ORDER_ID#', '/')\n" +
			                    "                   AND NVL(T.GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')\n" +
			                    "                   AND NVL(T.HEAT_PLAN_NO, '/') = NVL('#HEAT_PLAN_NO#', '/')\n" +
			                    "                   AND (CASE\n" +
			                    "                            WHEN T.LENGTH_TYPE = 0 THEN '正尺'\n" +
			                    "                            WHEN T.LENGTH_TYPE = 1 THEN '长池'\n" +
			                    "                            WHEN T.LENGTH_TYPE = 2 THEN '短尺'\n" +
			                    "                            ELSE '/'\n" +
			                    "                        END\n" +
			                    "                        ) = NVL('#LENGTH_TYPE#', '/')\n" +
			                    "                   AND T.QCM_STAUS = '00'\n" +
			                    "                   AND T.JUGDE_APPLY_CODE IS NULL\n" +
			                    "                 ORDER BY MAT_NO ASC)\n" +
			                    "         WHERE ROWNUM <= '#ACT_COUNT#')\n" +
			                    "   AND (JUGDE_APPLY_CODE IS NULL OR NOT EXISTS\n" +
			                    "        (SELECT 1\n" +
			                    "           FROM QCM_ZG_JUGDE_APPLY\n" +
			                    "          WHERE JUGDE_APPLY_CODE = S.JUGDE_APPLY_CODE\n" +
			                    "            AND JUDGE_STOVE_NO = S.JUDGE_STOVE_NO\n" +
			                    "            AND BATCH_NO = S.PHY_BATCH_NO)) )"; 
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectInputCountMch");
						sql = sql + matSql;
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(str, MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							inputCount = rs.getString("ACT_COUNT");
							inputWeight = rs.getString("ACT_WEIGHT");
							if (inputCount == null) {
								inputCount = "0";
								inputWeight = "0.0";
							}
						}
						rs.close();
						psta.close();
					}
					//System.out.println("投料支数"+inputCount+"  投料量"+inputWeight);

					matBcEntity.setJugdeApplyCode(judgeApplyNo);
					matBcEntity.setJugdeApplyTime(systime);
					QcmZgJugdeApplyEntity qcmEntity = new QcmZgJugdeApplyEntity();
					qcmEntity.setInputCount(inputCount); // 投料量
					qcmEntity.setInputWeight(inputWeight); // 投料支
					qcmEntity.setOutputCount(inputCount);
					qcmEntity.setOutputWeight(inputWeight);
					qcmEntity.setTestingStandar(testingStandar); // 探伤标准
					qcmEntity.setStorageName(matBcEntity.getStorageName());
					qcmEntity.setStorageNo(matBcEntity.getStorageNo());
					qcmEntity.setJugdeApplyCode(judgeApplyNo);
					qcmEntity.setJugdeApplySequeno(String
							.valueOf(judgeSequenNo));
					qcmEntity.setStoveNo(matBcEntity.getStoveNo());
					qcmEntity.setLotNo(matBcEntity.getLotNo());
					qcmEntity.setJudgeStoveNo(matBcEntity.getJudgeStoveNo());
					qcmEntity.setBatchNo(matBcEntity.getBatchNo());
					qcmEntity.setBatchGroudNo(matBcEntity.getBatchGroudNo());
					qcmEntity.setQualityGroup("1");
					qcmEntity.setMaterialNo(matBcEntity.getMaterialNo());
					if (matBcEntity.getMaterialNo() == null
							|| matBcEntity.getMaterialNo() == "") {
						cro.setV_errMsg("计划里物料码为空,不允许申请判定!");
						return cro;
					}
					if(matBcEntity.getLengthType().equals("正尺")){
						qcmEntity.setLengthType("0");
					}else if(matBcEntity.getLengthType().equals("长尺")){
						qcmEntity.setLengthType("1");
					}else if(matBcEntity.getLengthType().equals("短尺")){
						qcmEntity.setLengthType("2");
					}else{
						qcmEntity.setLengthType(matBcEntity.getLengthType());
					}					
					qcmEntity.setMaterialName(matBcEntity.getMaterialName());
					qcmEntity.setProduccode(matBcEntity.getProduccode());
					qcmEntity.setProducname(matBcEntity.getProducname());
					qcmEntity.setSteelcode(matBcEntity.getSteelcode());
					qcmEntity.setSteelname(matBcEntity.getSteelname());
					qcmEntity.setStdStyle(matBcEntity.getStdStyle());
					qcmEntity.setStdStyleDesc(matBcEntity.getStdStyleDesc());
					qcmEntity.setSpecCode(matBcEntity.getSpecCode());
					qcmEntity.setSpecName(matBcEntity.getSpecName());
					qcmEntity.setModelCode(matBcEntity.getModelCode());
					qcmEntity.setModelDesc(matBcEntity.getModelDesc());
					qcmEntity.setGradecode(matBcEntity.getGradecode());
					qcmEntity.setGradename(matBcEntity.getGradename());
					qcmEntity.setStdCode(matBcEntity.getStdCode());
					qcmEntity.setStdName(matBcEntity.getStdName());
					qcmEntity.setActDimater(matBcEntity.getActDimater());
					qcmEntity.setActHeight(matBcEntity.getActHeight());
					qcmEntity.setActLenMin(matBcEntity.getActLenMin());
					qcmEntity.setActLenMax(matBcEntity.getActLenMax());
					qcmEntity.setActLen(matBcEntity.getActLen());
					qcmEntity.setInMold(matBcEntity.getInMold());
					//缴库量上限>累计送判吨（按计划入）,缴库量上限<累计送判吨（按计划入）+送判吨，送判支>预计可送判支
					if(matBcEntity.getTarget().equals(("A")) && matBcEntity.getInMold().equals("801703")){
						if(matBcEntity.getOrderUnit().equals("吨") && Double.parseDouble(matBcEntity.getPaydownWtMax())> Double.parseDouble(matBcEntity.getActWeight2()) && Double.parseDouble(matBcEntity.getPaydownWtMax())< Double.parseDouble(matBcEntity.getActWeight2()) + Double.parseDouble(matBcEntity.getActWeight()) && Integer.parseInt(matBcEntity.getActCount())> Integer.parseInt(matBcEntity.getKspz())){
							qcmEntity.setActCount(matBcEntity.getKspz());
						}else if(matBcEntity.getOrderUnit().equals("米")&& Double.parseDouble(matBcEntity.getPaydownWtMax())> Double.parseDouble(matBcEntity.getActLen2()) && Double.parseDouble(matBcEntity.getPaydownWtMax())< Double.parseDouble(matBcEntity.getActLen2()) + Double.parseDouble(matBcEntity.getActLen()) && Integer.parseInt(matBcEntity.getActCount())> Integer.parseInt(matBcEntity.getKspz())){
							qcmEntity.setActCount(matBcEntity.getKspz());
						}else if(matBcEntity.getOrderUnit().equals("英尺")&& Double.parseDouble(matBcEntity.getPaydownWtMax())> Double.parseDouble(matBcEntity.getActLen2()) && Double.parseDouble(matBcEntity.getPaydownWtMax())< Double.parseDouble(matBcEntity.getActLen2()) + Double.parseDouble(matBcEntity.getActLen()) && Integer.parseInt(matBcEntity.getActCount())> Integer.parseInt(matBcEntity.getKspz())){
							qcmEntity.setActCount(matBcEntity.getKspz());
						}else{
							qcmEntity.setActCount(matBcEntity.getActCount());
						}
						//成品，非计划，有拆分支，按拆分支送判
					}else if(matBcEntity.getTarget().equals(("A")) && matBcEntity.getInMold().equals("801701") && !matBcEntity.getCfz().equals("") && matBcEntity.getCfz()!= null){
						if( Double.parseDouble(matBcEntity.getCfz()) > 0){
							qcmEntity.setActCount(matBcEntity.getCfz());
						}
					}else{
						qcmEntity.setActCount(matBcEntity.getActCount());
					}
					// qcmEntity.setActTheoryWeight(matBcEntity.getActWeight());
					// qcmEntity.setActWeight(matBcEntity.getPonderGrossWt());
					qcmEntity.setActTheoryWeight(matBcEntity
							.getActTheoryWeight());
					if (matBcEntity.getPonderGrossWt().equals("")) {
						qcmEntity.setActWeight(matBcEntity.getActWeight());
					} else {
						qcmEntity.setActWeight(matBcEntity.getPonderGrossWt());
					}
					qcmEntity.setProOrderNo(matBcEntity.getProOrderNo());
					qcmEntity.setProOrderId(matBcEntity.getProOrderId());
					qcmEntity.setGxPlanNo(matBcEntity.getGxPlanNo());
					qcmEntity.setProPlanIdNext(matBcEntity.getProPlanIdNext());
					qcmEntity.setGxPlanNoNext(matBcEntity.getGxPlanNoNext());
					qcmEntity
							.setHeatPlanNoNext(matBcEntity.getHeatPlanNoNext());
					qcmEntity.setPlineCode(matBcEntity.getPlineCode());
					qcmEntity.setPlineName(matBcEntity.getPlineName());
					qcmEntity.setBelongCode(matBcEntity.getBelongCode());
					qcmEntity.setBelongName(matBcEntity.getBelongName());
					qcmEntity.setNextProcessCdoe(matBcEntity
							.getNextProcessCdoe());
					qcmEntity.setLotNoGroup(plnMEntity.get(0).getLotNoGroup());
					// if (!matBcEntity.getTarget().equals(
					// plnMEntity.get(0).getDecision())) {
					// cro.setV_errMsg("申请判定字头和计划字头不一致，不允许申请判定!");
					// return cro;
					// }
					qcmEntity.setLoadJudgeStoveNo(plnMEntity.get(0)
							.getFeedHeatNo());
					qcmEntity.setValidflag("00");
					qcmEntity.setApplyTime(systime);
					qcmEntity.setApplyName(userName);
					qcmEntity.setMemo(memo);
					if (matBcEntity.getNextProcessCdoe().equals("")) {
						qcmEntity.setIsendgx("1");
					} else {
						qcmEntity.setIsendgx("0");
					}
					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("");
					if (matBcEntity.getLockLiku().equals("正常")) {
						qcmEntity.setLkFlag("0");
					} else if (matBcEntity.getLockLiku().equals("利库")) {
						qcmEntity.setLkFlag("1");
					} else if (matBcEntity.getLockLiku().equals("精整利库")) {
						qcmEntity.setLkFlag("2");
					} else {
						qcmEntity.setLkFlag("3");
					}
					qcmEntity.setInstockFlag("0");
					qcmEntity.setOrdLnDlyPk(matBcEntity.getOrdLnDlyPk());
					qcmEntity.setBelongCodeJugde(belong[0]);// 判定后所属权
					qcmEntity.setBelongNameJugde(belong[1]);// 判定后所属权
					qcmEntity.setProcessCode(matBcEntity.getProcessCdoe());
					qcmEntity.setTarget(matBcEntity.getTarget());
					qcmEntity.setSpecCode(matBcEntity.getSpecCode());
					qcmEntity.setSpecName(matBcEntity.getSpecName());
					qcmEntity.setSupplyUnit(supplyUnit);
					qcmEntity.setSupplyUnitDesc(supplyUnitDesc);
					/*if (Process.equals("F")) {
						if (plnMEntity.get(0).getIfMatchOdd().equals("0")) {
							if (plnMEntity.get(0).getHeatPlanNoOld() != null
									&& !plnMEntity.get(0).getHeatPlanNoOld()
											.equals("")) {
								qcmEntity.setHeatPlanNo(plnMEntity.get(0)
										.getHeatPlanNoOld());
							} else {
								qcmEntity.setHeatPlanNo(matBcEntity
										.getHeatPlanNo());
							}

						} else {
							qcmEntity
									.setHeatPlanNo(matBcEntity.getHeatPlanNo());
						}
					} else {
						qcmEntity.setHeatPlanNo(matBcEntity.getHeatPlanNo());
					}*/

					//取材料表炉计划ID
					qcmEntity.setHeatPlanNo(matBcEntity.getHeatPlanNo());
					if (Process.equals("") || Process == null) {
						cro.setV_errMsg("工序代码是空,请检查!");
						return cro;
					} else if (Process.equals("E")) {
						// 镦拔扩申请判定
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectCraftNo");// 计划里查找工艺文件号，工艺序号
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.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.setString(1, designKey);
						psta.setString(2, indexSeq);
						psta.setString(3, matBcEntity.getTarget());
						rs = psta.executeQuery();
						if (rs.next()) {
							baseCode = rs.getString("BASECODE");
							baseName = rs.getString("BASENAME");
						}
						rs.close();
						psta.close();

						if (plnMEntity.get(0).getIfMatchOdd().equals("2")) {
							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectZgJudgeNoE");//
							sql = EntityTool.fillSqlByEntity(sql, EntityTool
									.getEntityByJSONStr(parmList.get(0),
											MatBcMEntity.class));
							psta = connection.prepareStatement(sql);
							rs = psta.executeQuery();
							if (rs.next()) {
								zpMLh = rs.getString("ZP_M_LH");
								groupId = rs.getString("GROUP_ID");
							}
							rs.close();
							psta.close();
							if (zpMLh == null || zpMLh.equals("")) {
								qcmEntity.setZpMLh("");
							} else {

								qcmEntity.setZpMLh(zpMLh);
							}

							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectJudgeNoE");//
							psta = connection.prepareStatement(sql);
							psta.setObject(1, groupId);
							rs = psta.executeQuery();
							if (rs.next()) {
								zpColl = rs.getString("ZP_COLL");
							}
							rs.close();
							psta.close();
						}
						if (zpColl == null || zpColl.equals("")) {
							qcmEntity.setZpColl("");
						} else {
							qcmEntity.setZpColl(zpColl);
						}

						qcmEntity.setCraftSeq(matBcEntity.getCraftSeq());
						qcmEntity.setCic(matBcEntity.getCic());

						if (matBcEntity.getLockLiku().trim().equals("精整利库")) {
							if (matBcEntity.getLikuProcessCode().equals("D")) {
								qcmEntity.setIndexSeq(plnMEntityLikuD.get(0)
										.getIndexSeq());
								qcmEntity.setPic(plnMEntityLikuD.get(0)
										.getPic());
								qcmEntity.setSic(plnMEntityLikuD.get(0)
										.getSic());
								qcmEntity.setDic(plnMEntityLikuD.get(0)
										.getDic());
								qcmEntity.setWic("");
								qcmEntity.setGic("");
								qcmEntity.setCheckNo(plnMEntityLikuD.get(0)
										.getCheckNo());
							} else {
								qcmEntity.setIndexSeq(plnMEntityLiku.get(0)
										.getIndexSeq());
								qcmEntity
										.setPic(plnMEntityLiku.get(0).getPic());
								qcmEntity
										.setSic(plnMEntityLiku.get(0).getSic());
								qcmEntity
										.setDic(plnMEntityLiku.get(0).getDic());
								qcmEntity.setWic("");
								qcmEntity.setGic("");
								qcmEntity.setCheckNo(plnMEntityLiku.get(0)
										.getCheckNo());
							}

						} else {
							qcmEntity.setIndexSeq(plnMEntity.get(0)
									.getIndexSeq());
							qcmEntity.setPic(plnMEntity.get(0).getPic());
							qcmEntity.setSic(plnMEntity.get(0).getSic());
							qcmEntity.setDic(plnMEntity.get(0).getDic());
							qcmEntity.setWic("");
							qcmEntity.setGic("");
							qcmEntity
									.setCheckNo(plnMEntity.get(0).getCheckNo());
						}
						qcmEntity.setDeliveryStateCode(baseCode);
						qcmEntity.setDeliveryStateName(baseName);
						qcmEntity.setCrafNo(matBcEntity.getCrafNo());
						qcmEntity.setHttType("");
						qcmEntity.setMinTemp("");
						qcmEntity.setHttTechnology("");
						qcmEntity.setNotchInfo("");
						qcmEntity.setNotchLength("");
						qcmEntity.setNotchWidth("");
						qcmEntity.setNotchDepth("");
						qcmEntity
								.setTestPressure(matBcEntity.getTestPressure());
						qcmEntity
								.setHoldtimeTime(matBcEntity.getHoldtimeTime());
						qcmEntity.setTestPressureY(matBcEntity
								.getTestPressureY());
						if (face == null || face == "") {
							qcmEntity.setFaceResultCode("");
						} else {
							qcmEntity.setFaceResultCode("40740601");
						}
						qcmEntity
								.setTestingGrade(matBcEntity.getTestingGrade());
						qcmEntity.setTestingType(matBcEntity.getTestingType());
						qcmEntity.setDetectResultCode(matBcEntity
								.getDetectResultCode());
						if (!"".equals(matBcEntity.getTestingStandar())) {
							qcmEntity.setTestingStandar(matBcEntity
									.getTestingStandar());
						}

						if ((plnMEntity.get(0).getIfProduct().trim()
								.equals("0"))) {
							qcmEntity.setSteelStandrad("+"
									+ plnMEntity.get(0).getPic() + "+"
									+ plnMEntity.get(0).getSic() + "+"
									+ plnMEntity.get(0).getDic());
						} else {
							qcmEntity.setSteelStandrad(matBcEntity.getCic()
									+ "+" + plnMEntity.get(0).getPic() + "+"
									+ plnMEntity.get(0).getSic() + "+"
									+ plnMEntity.get(0).getDic());
						}
						if (plnMEntity.get(0).getGowhereCode() == null
								|| plnMEntity.get(0).getGowhereCode() == "") {
							qcmEntity.setMatGowhereCode("");
							qcmEntity.setMatGowhereName("");
						} else {
							qcmEntity.setMatGowhereCode(plnMEntity.get(0)
									.getGowhereCode());
							qcmEntity.setMatGowhereName(plnMEntity.get(0)
									.getGowhereName());
						}
						int PortPiece = 0;
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpInStore.QueryVrpPortFailPiece");// 各实绩废品和
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							PortPiece = Integer.parseInt(rs
									.getString("ACT_COUNT"));
						}
						rs.close();
						psta.close();
						if (PortPiece == 0) {

							if (!plnMEntity.get(0).getPlanstatus().equals("30")
									&& !plnMEntity.get(0).getPlanstatus()
											.equals("40")) {
								cro.setV_errMsg("上料和下线支数已平,请下线结炉后送判！");
								return cro;
							}
						}

					} else if (Process.equals("F")) {
						// 热处理申请送判
						if (matBcEntity.getLikuProcessCode() == null
								|| matBcEntity.getLikuProcessCode() == "") {
							// 判断STEEL_STANDRAD是否包含DIC
							if (!plnMEntity.get(0).getDic().equals("")
									|| plnMEntity.get(0).getDic() != null) {
								if (detecePath == null || detecePath.equals("")) {
									cro.setV_errMsg("请上传探伤报告!");
									return cro;
								}
							}
						}
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectCraftNoRcl");// 计划里查找工艺文件号，工艺序号
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.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();
						// 如果没找到工艺文件，可能是组炉炉号
						if (craftSeq.equals("")) {
							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectCraftNoRcl2");// 计划里查找工艺文件号，工艺序号
							sql = EntityTool.fillSqlByEntity(sql, EntityTool
									.getEntityByJSONStr(parmList.get(0),
											MatBcMEntity.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.SelectCrackType");//
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							if (rs.getString("TESTING_TYPE") == null
									|| rs.getString("TESTING_TYPE") == "") {
								qcmEntity.setTestingType("");
							} else {
								qcmEntity.setTestingType(rs
										.getString("TESTING_TYPE"));
							}
						}
						rs.close();
						psta.close();
						String testingGrid = "";// 探伤等级
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectCrackGade");//
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							if (rs.getString("TESTING_GRAGE") == null) {
								qcmEntity.setTestingGrade("");
							} else {
								qcmEntity.setTestingGrade(rs
										.getString("TESTING_GRAGE"));
								testingGrid = rs.getString("TESTING_GRAGE");
							}
						}
						rs.close();
						psta.close();

						if (!matBcEntity.getPlineCode().equals("C091")) { // 天淮部分重新热处理
							// 重新热处理不允许申请判定
							int count = 0;
							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectQcmZcCheck");//
							sql = EntityTool.fillSqlByEntity(sql, EntityTool
									.getEntityByJSONStr(parmList.get(0),
											MatBcMEntity.class));
							psta = connection.prepareStatement(sql);
							rs = psta.executeQuery();
							if (rs.next()) {
								count = Integer.parseInt(rs.getString("COUNT"));
							}
							rs.close();
							psta.close();
							if (count > 0) {
								cro.setV_errMsg("此炉批已申请重新热处理，不允许申请判定!");
								return cro;
							}
						}

						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.SelectBaseCode");// 查询交货状态
						// psta = connection.prepareStatement(sql);
						// psta.setString(1, designKey);
						// psta.setString(2, indexSeq);
						// rs = psta.executeQuery();
						// if (rs.next()) {
						// baseCode = rs.getString("BASECODE");
						// baseName = rs.getString("BASENAME");
						// }
						// rs.close();
						// psta.close();
						// 利库组炉，离线组炉都要查组炉炉号
						// if (plnMEntity.get(0).getIfMatchOdd().equals("2")) {

						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectZgJudgeNoF");//
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							zpMLh = rs.getString("ZP_M_LH");
							groupId = rs.getString("GROUP_ID");
						}
						rs.close();
						psta.close();
						if (zpMLh == null || zpMLh.equals("")) {
							qcmEntity.setZpMLh("");
						} else {

							qcmEntity.setZpMLh(zpMLh);
						}

						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectJudgeNoF");//
						psta = connection.prepareStatement(sql);
						psta.setObject(1, groupId);
						rs = psta.executeQuery();
						if (rs.next()) {
							zpColl = rs.getString("ZP_COLL");
						}
						rs.close();
						psta.close();
						// }
						if (zpColl == null || zpColl.equals("")) {
							qcmEntity.setZpColl("");
						} else {
							qcmEntity.setZpColl(zpColl);
						}

						ArrayList<String> PortEntity = new ArrayList<String>();
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectNodePortEntity"); // 获取检验编号
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(str, MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						while (rs.next()) {
							PortEntity.add(rs.getString("CHECK_NO"));
						}
						rs.close();
						psta.close();
						qcmEntity.setCraftSeq(matBcEntity.getCraftSeq());
						if (matBcEntity.getLockLiku().trim().equals("精整利库")) {
							if (matBcEntity.getLikuProcessCode().equals("D")) {
								if (plnMEntityLikuD.size() <= 0) {
									cro.setV_errMsg("利库工序轧管，没有轧管计划!");
									return cro;
								}
								qcmEntity.setIndexSeq(plnMEntityLikuD.get(0)
										.getIndexSeq());
								qcmEntity.setPic(plnMEntityLikuD.get(0)
										.getPic());
								qcmEntity.setSic(plnMEntityLikuD.get(0)
										.getSic());
								qcmEntity.setDic(plnMEntityLikuD.get(0)
										.getDic());

								indexSeq = plnMEntityLikuD.get(0).getIndexSeq();
								craftSeq = plnMEntityLikuD.get(0).getCraftSeq();
								craftFileNo = plnMEntityLikuD.get(0)
										.getCraftFileNo();

								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();

							} else {
								qcmEntity.setIndexSeq(plnMEntityLiku.get(0)
										.getIndexSeq());
								qcmEntity
										.setPic(plnMEntityLiku.get(0).getPic());
								qcmEntity
										.setSic(plnMEntityLiku.get(0).getSic());
								qcmEntity
										.setDic(plnMEntityLiku.get(0).getDic());

							}

						} else {
							qcmEntity.setIndexSeq(plnMEntity.get(0)
									.getIndexSeq());
							qcmEntity.setPic(plnMEntity.get(0).getPic());
							qcmEntity.setSic(plnMEntity.get(0).getSic());
							qcmEntity.setDic(plnMEntity.get(0).getDic());

						}

						qcmEntity.setCic(matBcEntity.getCic());

						qcmEntity.setWic("");
						qcmEntity.setGic("");
						qcmEntity.setHttType(matBcEntity.getHttType());
						qcmEntity.setMinTemp(matBcEntity.getMinTemp());
						qcmEntity.setHttTechnology(matBcEntity
								.getHttTechnology());
						qcmEntity.setNotchInfo(matBcEntity.getNotchInfo());
						qcmEntity.setNotchLength(matBcEntity.getNotchLength());
						qcmEntity.setNotchWidth(matBcEntity.getNotchWidth());
						qcmEntity.setNotchDepth(matBcEntity.getNotchDepth());
						String Port = "";
						for (int i = 0; i < PortEntity.size(); i++) {
							if (i == 0) {
								Port = PortEntity.get(i) == null ? ""
										: PortEntity.get(i);
							} else {
								if (Port == "") {
									Port += PortEntity.get(i) == null ? ""
											: PortEntity.get(i);
								} else {
									if (PortEntity.get(i) == null) {
										Port += (PortEntity.get(i) == null ? ""
												: PortEntity.get(i));
									} else {
										Port += ',' + (PortEntity.get(i) == null ? ""
												: PortEntity.get(i));
									}
								}
							}
						}
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectBaseCode1");// 查询交货状态
						psta = connection.prepareStatement(sql);
						psta.setString(1, designKey);
						psta.setString(2, indexSeq);
						psta.setString(3, matBcEntity.getTarget());
						rs = psta.executeQuery();
						if (rs.next()) {
							baseCode = rs.getString("BASECODE");
							baseName = rs.getString("BASENAME");
						}
						rs.close();
						psta.close();
						qcmEntity.setCheckNo(Port);
						qcmEntity.setDeliveryStateCode(baseCode);
						qcmEntity.setDeliveryStateName(baseName);
						qcmEntity.setCrafNo(matBcEntity.getCrafNo());
						qcmEntity.setLikuProcessCode(matBcEntity
								.getLikuProcessCode());
						if ((plnMEntity.get(0).getIfProduct().trim()
								.equals("0"))) {
							qcmEntity.setSteelStandrad(plnMEntity.get(0)
									.getPic()
									+ "+"
									+ plnMEntity.get(0).getSic()
									+ "+"
									+ plnMEntity.get(0).getDic());
						} else {
							qcmEntity.setSteelStandrad(matBcEntity.getCic()
									+ "+" + plnMEntity.get(0).getPic() + "+"
									+ plnMEntity.get(0).getSic() + "+"
									+ plnMEntity.get(0).getDic());
						}
						if (plnMEntity.get(0).getGowhereCode() == null
								|| plnMEntity.get(0).getGowhereCode() == "") {
							qcmEntity.setMatGowhereCode("");
							qcmEntity.setMatGowhereName("");
						} else {
							qcmEntity.setMatGowhereCode(plnMEntity.get(0)
									.getGowhereCode());
							qcmEntity.setMatGowhereName(plnMEntity.get(0)
									.getGowhereName());
						}

						qcmEntity.setFaceResultPath("Htt/AppCheck/"
								+ matBcEntity.getJudgeStoveNo() + "/"
								+ matBcEntity.getHeatPlanNo() + "/");
						qcmEntity.setDetectResultPath("Htt/CrackDetect/"
								+ matBcEntity.getJudgeStoveNo() + "/"
								+ matBcEntity.getBatchNo() + "/"
								+ matBcEntity.getHeatPlanNo() + "/");
						qcmEntity.setFaceResultCode("40740601");
						if (testingGrid == "") {
							qcmEntity.setDetectResultCode("");
						} else {
							qcmEntity.setDetectResultCode("40740401");
						}
						int PortPiece = 0;
						// 获取镦拔扩计划从表实体类
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.QueryVrpPortPiece");// 各实绩废品和
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							PortPiece = Integer.parseInt(rs
									.getString("ACT_COUNT"));
						}
						rs.close();
						psta.close();
						if (PortPiece == 0) {

							if (!plnMEntity.get(0).getPlanstatus().equals("30")
									&& !plnMEntity.get(0).getPlanstatus()
											.equals("40")) {
								cro.setV_errMsg("上料和下线支数已平,请下线结炉后送判！");
								return cro;
							}
						}
					} else if (Process.equals("G")) {
						// 加工申请送判
						String Count = "";// 接箍从表是否有数据
						String Deal = "";// 接箍子表是否有值
						String matchOdd = "";// 是否组炉
						String orJudgeNo = "";// 原炉号
						String orBatchNo = "";// 原批号
						String count = "";// 接箍从表是否有数据

						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectProducType");// 查询品名类型
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							producType = rs.getString("PRODUC_TYPE");
						}
						rs.close();
						psta.close();

						if (NeedCheck(qcmEntity.getPlineCode(), producType)) {

							int CountUnCheck = 0; // 未进过复检的管号支数
							int CountTreament = 0; // 未验证处置单

							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectUnFinalCheckCount");//
							sql = EntityTool.fillSqlByEntity(sql, qcmEntity);
							psta = connection.prepareStatement(sql);
							rs = psta.executeQuery();
							if (rs.next()) {
								CountUnCheck = rs.getInt("COUNT");
							}
							rs.close();
							psta.close();

							if (CountUnCheck > 0) {
								cro.setV_errMsg("存在" + CountUnCheck
										+ "支管未入库检验，质检站入库检验未回报，请联系质检站！!");
								return cro;
							}

							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectUnCheckTreatmentCount");//
							sql = EntityTool.fillSqlByEntity(sql, qcmEntity);
							psta = connection.prepareStatement(sql);
							rs = psta.executeQuery();
							if (rs.next()) {
								CountTreament = rs.getInt("COUNT");
							}
							rs.close();
							psta.close();

							if (CountTreament > 0) {
								cro.setV_errMsg("送判管存在入库检验处置单未验证，请联系质检站！!");
								return cro;
							}
						}

						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectOrderJgData");//
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							Count = rs.getString("COUNT");
						}
						rs.close();
						psta.close();
						if (Integer.parseInt(Count) > 0) { // /需要录入接箍

							JudgeWithCoupling = qcmEntity.getJudgeStoveNo();
							BatchNoWithCoupling = qcmEntity.getBatchNo();

							int DetailCount = 0; // 拧接子表记录数

							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectMchResultD");
							psta = connection.prepareStatement(sql);
							psta.setObject(1, JudgeWithCoupling);
							psta.setObject(2, BatchNoWithCoupling);
							rs = psta.executeQuery();
							if (rs.next()) {
								DetailCount = rs.getInt("COUNT");
							}
							rs.close();
							psta.close();

							// /若是组炉记录 新炉号无拧接实绩 找原炉号是否存在
							if (DetailCount <= 0
									&& plnMEntity.get(0).getIfMatchOdd()
											.equals("2")) {

								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpApplyNew.SelectZgJudgeNoG");//
								sql = EntityTool.fillSqlByEntity(sql,
										EntityTool.getEntityByJSONStr(parmList
												.get(0), MatBcMEntity.class));
								psta = connection.prepareStatement(sql);
								rs = psta.executeQuery();
								if (rs.next()) {
									groupId = rs.getString("GROUP_ID");
								}
								rs.close();
								psta.close();

								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpApplyNew.SelectMatchOddJudgeNo");//
								psta = connection.prepareStatement(sql);
								psta.setObject(1, groupId);
								rs = psta.executeQuery();
								if (rs.next()) {
									JudgeWithCoupling = rs
											.getString("JUDGE_STOVE_NO");
									BatchNoWithCoupling = rs
											.getString("BATCH_NO");
								}
								rs.close();
								psta.close();

								sql = CoreXmlSqlParsersFactory
										.getSql("FrmVrpApplyNew.SelectMchResultD");
								psta = connection.prepareStatement(sql);
								psta.setObject(1, qcmEntity.getStoveNo());
								psta.setObject(2, qcmEntity.getBatchNo());
								rs = psta.executeQuery();
								if (rs.next()) {
									DetailCount = rs.getInt("COUNT");
								}
								rs.close();
								psta.close();

							}

							if (DetailCount <= 0) {
								cro.setV_errMsg("拧接未录入接箍信息!");
								return cro;
							}

						} else {

							// 无接箍合同 录入了接箍炉号（短节）
							int DetailCount = 0; // 拧接子表记录数

							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectMchResultD2");
							psta = connection.prepareStatement(sql);
							psta.setObject(1, qcmEntity.getHeatPlanNo());
							psta.setObject(2, qcmEntity.getJudgeStoveNo());
							psta.setObject(3, qcmEntity.getBatchNo());
							rs = psta.executeQuery();
							if (rs.next()) {
								DetailCount = rs.getInt("COUNT");
							}
							rs.close();
							psta.close();

							if (DetailCount > 0) {
								JudgeWithCoupling = qcmEntity.getJudgeStoveNo();
								BatchNoWithCoupling = qcmEntity.getBatchNo();
							}

						}

						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectCraftNoJgx");// 计划里查找工艺文件号，工艺序号
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.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.SelectBaseCode");// 查询交货状态
						// psta = connection.prepareStatement(sql);
						// psta.setString(1, designKey);
						// psta.setString(2, indexSeq);
						// rs = psta.executeQuery();
						// if (rs.next()) {
						// baseCode = rs.getString("BASECODE");
						// baseName = rs.getString("BASENAME");
						// }
						// rs.close();
						// psta.close();
						int ACOUNT = 0;
						String testPressure = ""; // 水压压力
						String holdtimeTime = ""; // 保压时间
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectIsWic");// 查询是否有水压要求
						psta = connection.prepareStatement(sql);
						psta.setString(1, "G");
						psta.setString(2, designKey);
						rs = psta.executeQuery();
						if (rs.next()) {
							ACOUNT = rs.getInt("ACOUNT");
						}
						rs.close();
						psta.close();
						if (ACOUNT > 0) {
							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.doQueryWicValue");// 查询水压
							psta = connection.prepareStatement(sql);
							psta
									.setString(1, plnMEntity.get(0)
											.getHeatPlanNo());
							psta.setString(2, plnMEntity.get(0)
									.getJudgeStoveNo());
							rs = psta.executeQuery();
							if (rs.next()) {
								testPressure = rs.getString("TEST_PRESSURE");
								holdtimeTime = rs.getString("HOLDTIME_TIME");
							}
							rs.close();
							psta.close();
							/*
							 * if(testPressure == "" && holdtimeTime == ""){
							 * cro.setV_errMsg("工艺要求水压，生产未做水压不能送判！"); return
							 * cro; }
							 */
						}
						// qcmEntity.setTestPressure(testPressure);
						// qcmEntity.setHoldtimeTime(holdtimeTime);

						String baseCodeG = ""; // 交货状态
						String baseNameG = ""; // 交货状态
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.SelectBaseCode1");// 查询交货状态
						psta = connection.prepareStatement(sql);
						psta.setString(1, designKey);
						psta.setString(2, indexSeq);
						psta.setString(3, matBcEntity.getTarget());
						rs = psta.executeQuery();
						if (rs.next()) {
							baseCode = rs.getString("BASECODE");
							baseName = rs.getString("BASENAME");
						}
						rs.close();
						psta.close();
						// 短节、附件 的交货状态取备料交货状态
						if (matBcEntity.getProducname().indexOf("短节") > 0
								|| matBcEntity.getProducname().indexOf("附件") > 0) {
							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectBaseCode2");// 查询交货状态
							psta = connection.prepareStatement(sql);
							psta.setString(1, designKey);
							//psta.setString(2, indexSeq);
							psta.setString(2, designKey);
							psta.setString(3, matBcEntity.getTarget());
							rs = psta.executeQuery();
							if (rs.next()) {
								baseCodeG = rs.getString("BASECODE");
								baseNameG = rs.getString("BASENAME");
							}
							rs.close();
							psta.close();
						}
						if (!baseCodeG.equals("")) {
							baseCode = baseCodeG;
							baseName = baseNameG;
						}

						if (plnMEntity.get(0).getIfMatchOdd().equals("2")) {
							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectZgJudgeNoG");//
							sql = EntityTool.fillSqlByEntity(sql, EntityTool
									.getEntityByJSONStr(parmList.get(0),
											MatBcMEntity.class));
							psta = connection.prepareStatement(sql);
							rs = psta.executeQuery();
							if (rs.next()) {
								zpMLh = rs.getString("ZP_M_LH");
								groupId = rs.getString("GROUP_ID");
							}
							rs.close();
							psta.close();
							if (zpMLh == null || zpMLh.equals("")) {
								qcmEntity.setZpMLh("");
							} else {

								qcmEntity.setZpMLh(zpMLh);
							}

							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.SelectJudgeNoG");//
							psta = connection.prepareStatement(sql);
							psta.setObject(1, groupId);
							rs = psta.executeQuery();
							if (rs.next()) {
								zpColl = rs.getString("ZP_COLL");
							}
							rs.close();
							psta.close();
						}
						if (zpColl == null || zpColl.equals("")) {
							qcmEntity.setZpColl("");
						} else {
							qcmEntity.setZpColl(zpColl);
						}
						qcmEntity.setCraftSeq(matBcEntity.getCraftSeq());
						if (matBcEntity.getLockLiku().trim().equals("精整利库")) {
							if (matBcEntity.getLikuProcessCode().equals("D")) {
								qcmEntity.setIndexSeq(plnMEntityLikuD.get(0)
										.getIndexSeq());
								qcmEntity.setPic(plnMEntityLikuD.get(0)
										.getPic());
								qcmEntity.setSic(plnMEntityLikuD.get(0)
										.getSic());
								qcmEntity.setDic(plnMEntityLikuD.get(0)
										.getDic());
								qcmEntity.setWic(plnMEntityLikuD.get(0)
										.getWic());
								qcmEntity.setGic(plnMEntityLikuD.get(0)
										.getGic());
								qcmEntity.setCheckNo(plnMEntityLikuD.get(0)
										.getCheckNo());
							} else {
								qcmEntity.setIndexSeq(plnMEntityLiku.get(0)
										.getIndexSeq());
								qcmEntity
										.setPic(plnMEntityLiku.get(0).getPic());
								qcmEntity
										.setSic(plnMEntityLiku.get(0).getSic());
								qcmEntity
										.setDic(plnMEntityLiku.get(0).getDic());
								qcmEntity
										.setWic(plnMEntityLiku.get(0).getWic());
								qcmEntity
										.setGic(plnMEntityLiku.get(0).getGic());
								qcmEntity.setCheckNo(plnMEntityLiku.get(0)
										.getCheckNo());
							}

						} else {
							qcmEntity.setIndexSeq(plnMEntity.get(0)
									.getIndexSeq());
							qcmEntity.setPic(plnMEntity.get(0).getPic());
							qcmEntity.setSic(plnMEntity.get(0).getSic());
							qcmEntity.setDic(plnMEntity.get(0).getDic());
							qcmEntity.setWic(plnMEntity.get(0).getWic());
							qcmEntity.setGic(plnMEntity.get(0).getGic());
							qcmEntity
									.setCheckNo(plnMEntity.get(0).getCheckNo());
						}

						qcmEntity.setCic(matBcEntity.getCic());
						qcmEntity.setDeliveryStateCode(baseCode);
						qcmEntity.setDeliveryStateName(baseName);
						qcmEntity.setCrafNo(matBcEntity.getCrafNo());
						qcmEntity.setHttType("");
						qcmEntity.setMinTemp("");
						qcmEntity.setHttTechnology("");
						qcmEntity.setNotchInfo("");
						qcmEntity.setNotchLength("");
						qcmEntity.setNotchWidth("");
						qcmEntity.setNotchDepth("");
						qcmEntity
								.setTestPressure(matBcEntity.getTestPressure());
						qcmEntity
								.setHoldtimeTime(matBcEntity.getHoldtimeTime());
						qcmEntity.setTestPressureY(matBcEntity
								.getTestPressureY());
						qcmEntity.setMchWatergageResult(matBcEntity
								.getMchWatergageResult());
						qcmEntity.setMchPathResult(matBcEntity
								.getMchPathResult());
						qcmEntity.setMchChamferingResult(matBcEntity
								.getMchChamferingResult());
						qcmEntity.setMchTwistinglyResult(matBcEntity
								.getMchTwistinglyResult());
						qcmEntity.setMchDimensionsResult(matBcEntity
								.getMchDimensionsResult());
						qcmEntity.setMchVisualResult(matBcEntity
								.getMchVisualResult());
						qcmEntity.setMchThreadInspectionResult(matBcEntity
								.getMchThreadInspectionResult());
						qcmEntity.setMchRemanenceResult(matBcEntity
								.getMchRemanenceResult());
						qcmEntity.setMchRadioactivityResult(matBcEntity
								.getMchRadioactivityResult());
						qcmEntity.setMchBevelResult(matBcEntity
								.getMchBevelResult());
						qcmEntity.setAngleVal(matBcEntity.getAngleVal());
						qcmEntity.setEdgeVal(matBcEntity.getEdgeVal());
						qcmEntity
								.setTestingGrade(matBcEntity.getTestingGrade());
						qcmEntity.setTestingType(matBcEntity.getTestingType());
						qcmEntity.setWpressureResultCode(matBcEntity
								.getWpressureResultCode());
						qcmEntity.setFaceResultCode(matBcEntity
								.getFaceResultCode());
						qcmEntity.setSpecResultCode(matBcEntity
								.getSpecResultCode());
						qcmEntity.setProcessResultCode("40740801");
						qcmEntity.setDetectResultCode(matBcEntity
								.getDetectResultCode());
						qcmEntity.setDriftModelMin(matBcEntity
								.getDriftModelMin());
						qcmEntity.setDriftModelMin2(matBcEntity
								.getDriftModelMin2());
						qcmEntity.setDriftModelLen(matBcEntity
								.getDriftModelLen());
						qcmEntity.setDriftModelLen2(matBcEntity
								.getDriftModelLen2());
						qcmEntity.setMeasuredTailPart(matBcEntity
								.getMeasuredTailPart());
						qcmEntity.setMeasuredEndPart(matBcEntity
								.getMeasuredEndPart());
						qcmEntity.setMeasuredMiddlePart(matBcEntity
								.getMeasuredMiddlePart());
						if (!"".equals(matBcEntity.getTestingStandar())) {
							qcmEntity.setTestingStandar(matBcEntity
									.getTestingStandar());
						}

						if ((plnMEntity.get(0).getIfProduct().trim()
								.equals("0"))) {
							qcmEntity.setSteelStandrad(plnMEntity.get(0)
									.getPic()
									+ "+"
									+ plnMEntity.get(0).getSic()
									+ "+"
									+ plnMEntity.get(0).getDic());
						} else {
							qcmEntity.setSteelStandrad(matBcEntity.getCic()
									+ "+" + plnMEntity.get(0).getPic() + "+"
									+ plnMEntity.get(0).getSic() + "+"
									+ plnMEntity.get(0).getDic() + "+"
									+ plnMEntity.get(0).getWic() + "+"
									+ plnMEntity.get(0).getGic());
						}
						if (plnMEntity.get(0).getGowhereCode() == null
								|| plnMEntity.get(0).getGowhereCode() == "") {
							qcmEntity.setMatGowhereCode("");
							qcmEntity.setMatGowhereName("");
						} else {
							qcmEntity.setMatGowhereCode(plnMEntity.get(0)
									.getGowhereCode());
							qcmEntity.setMatGowhereName(plnMEntity.get(0)
									.getGowhereName());
						}

						int CountErrorWt = 0;
						// 获取加工线计划从表实体类
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.QueryErrorWtCount");// 各实绩废品和
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							CountErrorWt = Integer.parseInt(rs
									.getString("COUNT"));
						}
						rs.close();
						psta.close();

						if (CountErrorWt > 0) {
							cro
									.setV_errMsg("存在与测量点重量不相同的管, 下线后测量点数据发生改变,请撤销交库,再重新交库!");
							return cro;
						}

						int PortPiece = 0;
						// 获取加工线计划从表实体类
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmVrpApplyNew.QueryMchPortPiece");// 各实绩废品和
						sql = EntityTool.fillSqlByEntity(sql, EntityTool
								.getEntityByJSONStr(parmList.get(0),
										MatBcMEntity.class));
						psta = connection.prepareStatement(sql);
						rs = psta.executeQuery();
						if (rs.next()) {
							PortPiece = Integer.parseInt(rs
									.getString("ACT_COUNT"));
						}
						rs.close();
						psta.close();
						if (PortPiece == 0) {

							String Status = "";
							sql = CoreXmlSqlParsersFactory
									.getSql("FrmVrpApplyNew.CheckStatus");// 各实绩废品和
							sql = EntityTool.fillSqlByEntity(sql, EntityTool
									.getEntityByJSONStr(parmList.get(0),
											MatBcMEntity.class));
							psta = connection.prepareStatement(sql);
							rs = psta.executeQuery();
							if (rs.next()) {
								Status = String.valueOf(rs
										.getString("BESIDE_STATUS"));
							}
							rs.close();
							psta.close();
							if (!Status.equals("11")) {
								cro.setV_errMsg("上料和下线支数已平,请下线结炉后送判！");
								return cro;
							}
						}
						/*
						 * if (LoadingPiece == InstorePiece + OfflinePiece -
						 * RePiece + PortPiece) { if (OfflinePiece == 0) { if
						 * (!plnMEntity.get(0).getPlanstatus().equals("30")) {
						 * cro.setV_errMsg("上料和下线支数已平,请下线结炉后送判！"); return cro; }
						 * } }
						 */
					}

					// 插入申请送判记录
					String insertJugdeApplySql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.insertJugdeApply");
					insertJugdeApplySql = EntityTool.fillSqlByEntity(
							insertJugdeApplySql, qcmEntity);
					sqllist.add(insertJugdeApplySql);

					qcmEntity.setHeatPlanNo(matBcEntity.getHeatPlanNo());

					// 写入日志
					
	    			insertJugdeApplyLogPsta.setString(1, qcmEntity.getProOrderId());
					insertJugdeApplyLogPsta.setString(2, qcmEntity.getJudgeStoveNo());
					insertJugdeApplyLogPsta.setString(3, qcmEntity.getBatchNo());
					insertJugdeApplyLogPsta.setString(4, qcmEntity.getBatchGroudNo());
					insertJugdeApplyLogPsta.setString(5, qcmEntity.getProcessCode());
					insertJugdeApplyLogPsta.setString(6, qcmEntity.getPlineCode());
					insertJugdeApplyLogPsta.setString(7, qcmEntity.getActCount());
					insertJugdeApplyLogPsta.setString(8, qcmEntity.getActWeight());
					insertJugdeApplyLogPsta.setString(9, userName);
					insertJugdeApplyLogPsta.setString(10, "1");

					
					int InstorePiece = 0;
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.QueryMatbcmPiece");// 交库后查库存表支数
					sql = EntityTool.fillSqlByEntity(sql, EntityTool
							.getEntityByJSONStr(str, MatBcMEntity.class));
					psta = connection.prepareStatement(sql);
					rs = psta.executeQuery();
					if (rs.next()) {
						InstorePiece = Integer.parseInt(rs
								.getString("REAL_OUTDOUBLE_NUM"));
					}
					rs.close();
					psta.close();
					if (Process.equals("F")) {
						if (InstorePiece < Integer.parseInt(qcmEntity
								.getActCount())) {
							cro.setV_errMsg("送判支数大于交库支数！");
							return cro;
						}
					}

					String updateMatBcSql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.updateMatBcJugdeApplyCode");
					updateMatBcSql = EntityTool.fillSqlByEntity(updateMatBcSql,
							qcmEntity);
					updateMatBcSql = updateMatBcSql.replace(
							"#JudgeWithCoupling#", JudgeWithCoupling).replace(
							"#BatchNoWithCoupling#", BatchNoWithCoupling);
					sqllist.add(updateMatBcSql);

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

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

					String updateLoadSql = CoreXmlSqlParsersFactory
							.getSql("FrmVrpApplyNew.updateLoad"); // 判定表写上料炉号、上料批号、打捆备注
					updateLoadSql = EntityTool.fillSqlByEntity(updateLoadSql,
							qcmEntity); 
					sqllist.add(updateLoadSql);

				}
				insertJugdeApplyLogPsta.addBatch();
				insertJugdeApplyLogPsta.executeBatch();
				cro = this.getDao(CoreConstantData.sysbeanstr)
						.ExcuteTransction(sqllist);
				connection.commit();
				if (cro.getV_errMsg().equals("")) {
					cro.setV_errMsg("申请判定成功!");
					cro.setResult(judgeApplyNo);
				}
			} 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,
			String gx) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String valueFlag = "";// 判定状态
		String applyNo = "";// 申请判定单
		String instock = "";// 缴库标志
		int acount = 0;
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for (String str : parmList) {
				MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str,
						MatBcMEntity.class);
				// sql = CoreXmlSqlParsersFactory
				// .getSql("FrmVrpApplyNew.SelectValueFlag");
				// sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
				// psta = connection.prepareStatement(sql);
				// rs = psta.executeQuery();
				// if (rs.next()) {
				// valueFlag = rs.getString("VALIDFLAG");
				// instock = rs.getString("INSTOCK_FLAG");
				// }
				// rs.close();
				// psta.close();// 11
				// String ProcessDesc = "";
				// PreparedStatement updateSqlPsta1 = null;
				// if(gx.equals("E"))
				// {
				// sql = CoreXmlSqlParsersFactory
				// .getSql("FrmVrpApplyNew.doQueryProcessDesc");
				// updateSqlPsta1 = connection
				// .prepareStatement(sql);
				// updateSqlPsta1.setObject(1, matBcEntity.getJudgeStoveNo());
				// rs = updateSqlPsta1.executeQuery();
				// }else if(gx.equals("F"))
				// {
				// sql = CoreXmlSqlParsersFactory
				// .getSql("FrmVrpApplyNew.doQueryProcessRclDesc");
				// updateSqlPsta1 = connection
				// .prepareStatement(sql);
				// updateSqlPsta1.setObject(1, matBcEntity.getJudgeStoveNo());
				// rs = updateSqlPsta1.executeQuery();
				// }
				// if (rs.next()) {
				// ProcessDesc = rs.getString("PROCESS_CODE_C");
				// }
				// if (instock.equals("1")) {
				// cro.setV_errMsg("质保部已经接收，不允许撤销申请判定!");
				// return cro;
				// } else {
				// if (!ProcessDesc.equals("B008")
				// && !ProcessDesc.equals("B010")&&!ProcessDesc.equals("B024"))
				// {
				// if (!valueFlag.equals("00") && !valueFlag.equals("10")) {
				// cro.setV_errMsg("该炉批已不是初始状态/撤判状态，不允许撤销申请判定!");
				// return cro;
				// }
				// }
				// }
				// rs.close();
				// updateSqlPsta1.close();
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.SelectMatbc"); // 查询材料在不在材料表
				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;
				}

				acount = 0;
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.SelectPassApply"); // 查询是否已紧急放行
				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;
				}

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

			}
			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, MatBcMEntity matBcEntity)
			throws SQLException {
		String[] belong = new String[2];
		String departMentCode = "";// 现有产线部门
		String nextDrpartMentCode = "";// 下一工序产线部门
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		/*
		 * sql = CoreXmlSqlParsersFactory
		 * .getSql("FrmVrpApplyNew.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();
		 */
		if (matBcEntity.getNextProcessCdoe().equals("")
				&& matBcEntity.getTarget().equals("A")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("doDecision.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) {
			if (matBcEntity.getPlineCode().equals("C072")
					|| matBcEntity.getPlineCode().equals("C092")
					|| matBcEntity.getPlineCode().equals("C102")
					|| matBcEntity.getPlineCode().equals("C091")
					|| matBcEntity.getPlineCode().equals("C107")) {
				//belong[0] = "100101";
				//belong[1] = "国内贸易部";
				belong[0] = "002023005";
				belong[1] = "产品制造部";
			} else {

				belong[0] = "002001001";
				belong[1] = "生产计划部";
			}
		}

		// sql = CoreXmlSqlParsersFactory
		// .getSql("FrmVrpApplyNew.SelectNextPlineBelong");// 查询下工序产线部门
		// if(matBcEntity.getNextProcessCdoe().equals("F"))
		// {
		// sql = sql.replace("#PLAN#", "PLN_ORDER_RCL_S");
		// }else if(matBcEntity.getNextProcessCdoe().equals("G"))
		// {
		// sql = sql.replace("#PLAN#", "PLN_ORDER_JGX_S");
		// }else
		// {
		// sql = sql.replace("#PLAN#", "PLN_ORDER_DBK_S");
		// }
		// sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
		// psta = con.prepareStatement(sql);
		// rs = psta.executeQuery();
		// if (rs.next()) {
		// nextDrpartMentCode = rs.getString("DEPARTMENT_CODE");
		// }
		// rs.close();
		// psta.close();
		// if(departMentCode.equals(nextDrpartMentCode))
		// {
		// belong[0] = matBcEntity.getBelongCode();
		// belong[1] = matBcEntity.getBelongName();
		// }else
		// {
		// belong[0] = "002001001";
		// belong[1] = "制造部";
		// }

		return belong;
	}

	/**
	 * 查询水压
	 * 
	 * @param heatNo
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject doQueryWicValue(String heatNo, String judgeStoveNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.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("FrmVrpApplyNew.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("FrmVrpApplyNew.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("FrmVrpApplyNew.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("FrmVrpApplyNew.doQueryHttCrackDetectionEt");
		return this.getData(sql, new Object[] { heatNo, judgeStoveNo,
				PROCESS_CODE });
	}

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

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

	/**
	 * 新增合同附加要求信息 （QCM_ADD_ASK）
	 * 
	 * @param arrayList
	 * @return
	 */
	public CoreReturnObject insertQcmAddAsk(ArrayList<String> arrayList,
			String JugdeApplyCode, String JudgeStoveNo) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = "";
		String sql1 = "";
		sql1 = "DELETE FROM QCM_ADD_ASK T WHERE T.JUGDE_APPLY_CODE = '"
				+ JugdeApplyCode + "' AND T.JUDGE_STOVE_NO = '" + JudgeStoveNo
				+ "'";
		sqllist.add(sql1);
		for (int i = 0; i < arrayList.size(); i++) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmVrpApplyNew.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);
	}

	/**
	 * 查询送判数据
	 * 
	 * @param list
	 * @param startTim
	 * @param endTim
	 * @param departMentId
	 * @param plineCode
	 * @param value
	 * @return
	 */
	public CoreReturnObject QueryZgJugdeApply(String jugeNo, String startTim,
			String endTim, String departMentId, String Process, String[] arr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.QueryZgJugdeApply");
		if (!startTim.equals("")) {
			sql += " AND T.APPLY_TIME >=TO_DATE('" + startTim
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.APPLY_TIME <=TO_DATE('"
					+ endTim + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		if (!"".equals(jugeNo)) {
			sql += " AND T.JUDGE_STOVE_NO = '" + jugeNo + "'";
		}
		if (!"".equals(Process)) {
			sql += " AND T.PROCESS_CODE = '" + Process + "'";
		}
		if (!"".equals(arr)) {
			sql += " AND T.PLINE_CODE IN  (  SELECT PLINE_CODE FROM COM_BASE_PLINE  WHERE VALIDFLAG='1'   "
					+ CoreConverter
							.toSqlConditionString("DEPARTMENT_CODE", arr) + ")";
		}
		return this.getData(sql);
	}

	/**
	 * 回报捆数
	 * 
	 * @param JugdeApplyCode
	 * @param JudgeStoveNo
	 * @return
	 */
	public CoreReturnObject updateBundleNum(String JugdeApplyCode,
			String JudgeStoveNo) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sql1 = CoreXmlSqlParsersFactory
					.getSql("FrmVrpApplyNew.updateBundleNum");
			PreparedStatement updateBundleNum = connection
					.prepareStatement(sql1);
			updateBundleNum.setString(1, JugdeApplyCode);
			updateBundleNum.setString(2, JudgeStoveNo);
			updateBundleNum.addBatch();
			updateBundleNum.executeBatch();
			connection.commit();
			cro.setV_errMsg("确认成功!");
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/**
	 * 修改已判
	 * 
	 * @param JugdeApplyCode
	 * @param JudgeStoveNo
	 * @return
	 */
	public CoreReturnObject DoUpdateJudge(String parmList) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			connection.setAutoCommit(false); // 取消自动提交事务

			MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(parmList,
					MatBcMEntity.class);

			if (matBcEntity.getProcessCdoe().equals("G")) {
				String sql1 = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.DoUpdateJudge1");
				PreparedStatement pat1 = connection.prepareStatement(sql1);

				String sql2 = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.DoUpdateJudge2");
				PreparedStatement pat2 = connection.prepareStatement(sql2);

				pat1.setObject(1, matBcEntity.getTestingGrade());
				pat1.setObject(2, matBcEntity.getTestingType());
				pat1.setObject(3, matBcEntity.getTestingStandar());
				pat1.setObject(4, matBcEntity.getJugdeApplyCode());
				pat1.addBatch();

				pat2.setObject(1, matBcEntity.getTestingGrade());
				pat2.setObject(2, matBcEntity.getTestingType());
				pat2.setObject(3, matBcEntity.getTestingStandar());
				pat2.setObject(4, matBcEntity.getJugdeApplyCode());
				pat2.addBatch();

				pat1.executeBatch();
				pat2.executeBatch();

			} else {
				String sql1 = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.DoUpdateJudge3");
				PreparedStatement pat1 = connection.prepareStatement(sql1);

				String sql2 = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.DoUpdateJudge4");
				PreparedStatement pat2 = connection.prepareStatement(sql2);

				pat1.setObject(1, matBcEntity.getNotchLength());
				pat1.setObject(2, matBcEntity.getNotchWidth());
				pat1.setObject(3, matBcEntity.getNotchDepth());
				pat1.setObject(4, matBcEntity.getHttType());
				pat1.setObject(5, matBcEntity.getMinTemp());
				pat1.setObject(6, matBcEntity.getHttTechnology());
				pat1.setObject(7, matBcEntity.getJugdeApplyCode());
				pat1.addBatch();

				pat2.setObject(1, matBcEntity.getNotchLength());
				pat2.setObject(2, matBcEntity.getNotchWidth());
				pat2.setObject(3, matBcEntity.getNotchDepth());
				pat2.setObject(4, matBcEntity.getHttType());
				pat2.setObject(5, matBcEntity.getMinTemp());
				pat2.setObject(6, matBcEntity.getHttTechnology());
				pat2.setObject(7, matBcEntity.getJugdeApplyCode());
				pat2.addBatch();

				pat1.executeBatch();
				pat2.executeBatch();

			}

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

	/***
	 * 检查是否过测量点
	 * 
	 * @param parmList
	 * @param memo
	 * @return
	 */
	public CoreReturnObject doCheckIsMeasure(ArrayList<String> parmList) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {

			int Count = 0;

			for (String str : parmList) {

				int C1 = 0;

				MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str,
						MatBcMEntity.class);

				String updateMatBcSql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.doCheckIsMeasure");
				updateMatBcSql = EntityTool.fillSqlByEntity(updateMatBcSql,
						matBcEntity);

				psta = connection.prepareStatement(updateMatBcSql);

				rs = psta.executeQuery();
				if (rs.next()) {
					C1 = rs.getInt("COUNT");
				}

				rs.close();
				psta.close();

				Count = Count + C1;

			}

			cro.setV_errMsg("获取成功!");
			cro.setResult(Count);

		} 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;
	}

	private boolean NeedCheck(String PlineCode, String ModelType) {
		/*
		 * if (ModelType.equals("C") || ModelType.equals("E")) { return false; }
		 * 
		 * if (PlineCode.equals("C034")) {
		 * 
		 * return false; }
		 * 
		 * 去掉移至判定界面判断
		 * 
		 * return true;
		 */
		return false;
	}

	/**
	 * 标识空跑
	 * 
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject DoKpFlag(ArrayList<String> parmList) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		String IS_CARRY_VOER = "";
		ResultSet rs = null;

		try {
			for (String str : parmList) {
				QcmZgJugdeApplyEntity matBcEntity = EntityTool
						.getEntityByJSONStr(str, QcmZgJugdeApplyEntity.class);

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.SelectCarryVoerStatus");// 查询是否结转
				sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if (rs.next()) {
					IS_CARRY_VOER = rs.getString("IS_CARRY_VOER");
				}
				rs.close();
				psta.close();
				if (IS_CARRY_VOER.equals("1")) {
					cro.setV_errMsg("炉号'" + matBcEntity.getJudgeStoveNo()
							+ "'已结转，不能修改!");
					return cro;
				}
				String updateMatBcSql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.DoKpFlag");
				updateMatBcSql = EntityTool.fillSqlByEntity(updateMatBcSql,
						matBcEntity);
				psta = connection.prepareStatement(updateMatBcSql);
				psta.addBatch();
				psta.executeBatch();
			}
			connection.commit();
			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 matZcTity
	 * @param flag 0-报检   1-必检 3-免检
	 * @return
	 */
	public CoreReturnObject inspection(ArrayList<String> list,String process,String flag) {
		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); // 取消自动提交事务
			for (int m = 0; m < list.size(); m++) {
				MatBcMEntity matZcTityS = EntityTool.getEntityByJSONStr(
						list.get(m), MatBcMEntity.class);

				String InspectionNO = ""; //报检编号
				sql = CoreXmlSqlParsersFactory.getSql("FrmVrpApplyNew.GetInspectionNO");
				PreparedStatement pst = connection.prepareStatement(sql);
				pst.setObject(1, matZcTityS.getPlineCode());
				pst.setObject(2, matZcTityS.getPlineCode());
				rs = pst.executeQuery();
				if (rs.next()) {
					InspectionNO = rs.getString("INSPECTION_NO");
				}
				rs.close();
				pst.close();
				
				String updateProssWtSql = CoreXmlSqlParsersFactory
						.getSql("FrmVrpApplyNew.inspection");
				updateProssWtSql = EntityTool.fillSqlByEntity(updateProssWtSql, matZcTityS);
				PreparedStatement updateProssPsta = connection
						.prepareStatement(updateProssWtSql);
				updateProssPsta.setString(1, InspectionNO);
				updateProssPsta.setString(2, process);
				updateProssPsta.setString(3, flag); 
				updateProssPsta.addBatch();
				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;
	}
	
	
	public CoreReturnObject doQueryPlineCodeBM( String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmVrpApplyNew.doQueryPlineCodeBM");
		if (!plineCode.equals("")) {
			sql += " AND T.PLINE_CODE = '" + plineCode + "'";
		}
		return this.getData(sql);
	}

}
