package com.steering.pss.judge.Bll;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.pss.buybillet.Entity.PipeCheckconsignBaseinfoEntity;
import com.steering.pss.buybillet.Entity.PlnOrderZgSEntity;
import com.steering.pss.judge.model.CraftOrdDesignStdEntity;
import com.steering.pss.judge.model.MatBcMEntity;
import com.steering.pss.judge.model.PlnSaleordEntity;
import com.steering.pss.judge.model.PlnZyZgMEntity;
import com.steering.pss.judge.model.QcmJhyElementsEntity;
import com.steering.pss.judge.model.QcmJhyPhyresultEntity;
import com.steering.pss.judge.model.QcmZcCheckconsignDetailEntity;
import com.steering.pss.judge.model.QcmZcCheckconsignEntity;
import com.steering.pss.judge.model.QcmZgJugdeApplyEntity;
import com.steering.pss.judge.model.VrpGroupResultEntity;
import com.steering.pss.qcm.model.GenericEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignStdCicEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignStdPicEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignStdPicSmpEntity;

public class BllCreateGroupStoveInfo extends DBCommon{
	
	public CoreReturnObject Create(String processCode, String lotNo, String judgeStoveNo,
			String batchNo, String judgeApplyCode){
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = null;
		Statement st = null;
		Statement jhySt = null;
		Connection jhyCon = null;
		try{
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			st = con.createStatement();
			jhyCon = this.getDao("JhyDao").getConnection();
			jhyCon.setAutoCommit(false);
			jhySt = jhyCon.createStatement();
			SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
			b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
			QcmZgJugdeApplyEntity apply = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, QcmZgJugdeApplyEntity.class);
			if(apply.getZpMLh().equals("")){
				return cro;
			}
			Create(apply, con, st, jhyCon, jhySt);
			
			jhyCon.commit();
			con.commit();
		}catch(Exception ex){
			try {
				con.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				jhyCon.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(!ex.getMessage().equals("return")){
				cro.setV_errMsg(ex.getMessage());
			}
		}finally{
			try {
				st.close();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				jhySt.close();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {
				jhyCon.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return cro;
	}
	
	public CoreReturnObject Create(String processCode, String lotNo, String judgeStoveNo, String batchNo,
			String proPlanId, String gxPlanNo,String heatPlanNo, String lkProcessCode){
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		Connection jhyCon = this.getDao("JhyDao").getConnection();
		try{
			con.setAutoCommit(false);
			jhyCon.setAutoCommit(false);
			Create(processCode, lotNo, judgeStoveNo, batchNo, proPlanId, 
					gxPlanNo,con,jhyCon,heatPlanNo, lkProcessCode);
			
			con.commit();
			jhyCon.commit();
		}catch(Exception ex){
			try {
				con.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				jhyCon.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			cro.setV_errMsg(ex.getMessage());
		}finally{
			try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				jhyCon.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return cro;
	}
	
	/**
	 * 利库生成检验委托
	 * @param processCode
	 * @param judgeStoveNo
	 * @param batchNo
	 * @param con
	 * @throws Exception
	 */
	public void Create(String processCode, String lotNo, String judgeStoveNo, String batchNo,
			String proPlanId, String gxPlanNo, Connection con, Connection jhyCon,
			String heatPlanNo, String lkProcessCode) throws Exception{
		SqlBuilder b = null;
		Statement st = con.createStatement();
		Statement jhyst = jhyCon.createStatement();
		PlnOrderZgSEntity plnZgs = null;
		String craftProcess = "";
		if(lkProcessCode.equals("")) {
			craftProcess = processCode;
		}else {
			craftProcess = lkProcessCode;
		}
		if(lkProcessCode.equals("")) {
			plnZgs = getPlnOrderZgs(b, proPlanId, gxPlanNo, processCode, judgeStoveNo, craftProcess, con);
		}else {
			plnZgs = getPlnOrderZgs(b, proPlanId, gxPlanNo, processCode, judgeStoveNo, craftProcess, con);
		}
		
		copyConsignLk(processCode, judgeStoveNo, batchNo, plnZgs,con,jhyCon,st,jhyst,heatPlanNo,
				craftProcess, lkProcessCode);
		st.close();
		
//		Create(processCode, lotNo, judgeStoveNo, batchNo, proPlanId, gxPlanNo, judgeStoveNoM, judgeStoveNoColl,
//				"利库", con);
	}
	
	/**
	 * 生成组炉炉号的检验委托、检验实绩信息。
	 * @param con
	 * @throws Exception
	 */
	private void Create(QcmZgJugdeApplyEntity apply, Connection con, Statement st,
			Connection jhyCon, Statement jhySt) throws Exception {
		SqlBuilder b = null;
		String processCode = apply.getProcessCode();
		String judgeStoveNo = apply.getJudgeStoveNo();
		String batchNo = apply.getBatchNo();
		String lotNo = apply.getLotNo();
		ArrayList<VrpGroupResultEntity> groupResults = getOldStoveNo(judgeStoveNo, processCode, b, con);
		
		//如果没有组炉数据直接跳过
		if(groupResults.size() == 0){
			return;
		}
		//组炉炉号是否有检验委托, 如果有就不生成委托、检验信息。
//		boolean isGroup = checkGroupConsign(processCode, judgeStoveNo, batchNo, b, con);
//		if(!isGroup){
//			return;
//		}
		
		String judgeStoveNoM = "";
		String judgeStoveNoColl = "";
		judgeStoveNoM = groupResults.get(0).getZpJudgeStoveNo();
		if(!groupResults.get(0).getZpBatchNo().equals("")){
			judgeStoveNoM += "+" + groupResults.get(0).getZpBatchNo();
		}
		for(VrpGroupResultEntity groupResult : groupResults){
			if(judgeStoveNoColl.equals("")){
				judgeStoveNoColl = groupResult.getJudgeStoveNo();
				if(!groupResult.getBatchNo().equals("")){
					judgeStoveNoColl += "+" + groupResult.getBatchNo();
				}
			}else{
				judgeStoveNoColl += "," + groupResult.getJudgeStoveNo();
				if(!groupResult.getBatchNo().equals("")){
					judgeStoveNoColl += "+" + groupResult.getBatchNo();
				}
			}
		}
		
		//子炉号是否已判定
		HashMap<String, ArrayList<String>> subStoveBatchMap = checkSubJudge(
				processCode, judgeStoveNoColl, b, con);
		//子炉号是否都包含工艺里要求的检验项
		//checkSubCraftPhy(processCode, judgeStoveNo, batchNo, subJudgeStoveNos, b, con);
		//复制主炉号的委托、检验信息到组炉炉号中
		copyMainConsignJhy(processCode, lotNo, judgeStoveNo, batchNo, judgeStoveNoM,
				subStoveBatchMap, apply, b, con, st, jhyCon, jhySt);
	}

	public static ArrayList<VrpGroupResultEntity> getOldStoveNo(String groupStoveNo,
			String processCode, SqlBuilder b, Connection con) throws Exception {
		//各工序组炉表信息
		if(processCode.equals("D")){
			b = new SqlBuilder("JdgMilOfflineGroup.getOldJudgeStoveNo");
			b.Fill(new String[]{ groupStoveNo });
		}else if(processCode.equals("E")){
			b = new SqlBuilder("JdgVrpGroupResult.getOldJudgeStoveNo");
			b.Fill(new String[]{ groupStoveNo });
		}else if(processCode.equals("F")){
			b = new SqlBuilder("JdgHttGroupResult.getOldJudgeStoveNo");
			b.Fill(new String[]{ groupStoveNo });
		}else if(processCode.equals("G")){
			b = new SqlBuilder("JdgMchGroupResult.getOldJudgeStoveNo");
			b.Fill(new String[]{ groupStoveNo });
		}else{
			throw new Exception("工序异常！");
		}
		ArrayList<VrpGroupResultEntity> groupResults = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, VrpGroupResultEntity.class);

		return groupResults;
	}
	
	private boolean checkGroupConsign(String processCode, String judgeStoveNo,
			String batchNo, SqlBuilder b, Connection con){
		b = new SqlBuilder("JdgQcmZcCheckconsign.queryByBatchNoNoCheckNo");
		b.Fill(new Object[]{ judgeStoveNo, batchNo, processCode, new String[]{ "0", "4" } });
		ArrayList<QcmZcCheckconsignEntity> consigns = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, QcmZcCheckconsignEntity.class);
		if(consigns.size() == 0){
			return true;
		}else{
			boolean existsGroupConsin = false;
			for(QcmZcCheckconsignEntity consign : consigns){
				if(consign.getCheckNo().startsWith("P")){
					existsGroupConsin = true;
					break;
				}
			}
			if(existsGroupConsin){
				return true;
			}else{
				return false;
			}
		}
	}
	
	private HashMap<String, ArrayList<String>> checkSubJudge(String processCode, String judgeStoveNoColl,
			SqlBuilder b, Connection con) throws Exception{
		HashMap<String, ArrayList<String>> stoveBatchNoMap = new HashMap<String, ArrayList<String>>();
		String[] aryJudgeStoveNo = judgeStoveNoColl.split(",");
		for(String judgeStoveNoBatch : aryJudgeStoveNo){
			String judgeStoveNo = "";
			if(judgeStoveNoBatch.contains("+")){
				judgeStoveNo = judgeStoveNoBatch.split("\\+")[0];
				String batchNo = judgeStoveNoBatch.split("\\+")[1];
				
				if(stoveBatchNoMap.containsKey(judgeStoveNo)){
					ArrayList<String> batchNos = stoveBatchNoMap.get(judgeStoveNo);
					batchNos.add(batchNo);
				}else{
					ArrayList<String> batchNos = new ArrayList<String>();
					batchNos.add(batchNo);
					stoveBatchNoMap.put(judgeStoveNo, batchNos);
				}
			}else{
				judgeStoveNo = judgeStoveNoBatch;
				
				PlnZyZgMEntity plnZyM = getPlnZyM(b, processCode, judgeStoveNo, con);
				b = new SqlBuilder("JdgQcmZcCheckconsign.queryByJudgeStoveNo");
				b.Fill(new String[]{ judgeStoveNo, processCode, "0", plnZyM.getOrdLnDlyPk() });
				ArrayList<QcmZcCheckconsignEntity> consigns = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmZcCheckconsignEntity.class);
				if(consigns == null || consigns.size() == 0){
					throw new Exception("return");
				}else{
					for(QcmZcCheckconsignEntity consign : consigns){
						if(stoveBatchNoMap.containsKey(judgeStoveNo)){
							ArrayList<String> batchNos = stoveBatchNoMap.get(judgeStoveNo);
							batchNos.add(consign.getBatchNo());
						}else{
							ArrayList<String> batchNos = new ArrayList<String>();
							batchNos.add(consign.getBatchNo());
							stoveBatchNoMap.put(judgeStoveNo, batchNos);
						}
					}
				}
			}
			
			ArrayList<String> batchNos = stoveBatchNoMap.get(judgeStoveNo);
			for(String batchNo : batchNos){
				b = new SqlBuilder("JdgQcmBcChemJudgeDAL.queryCntByBatchNo");
				b.Fill(new Object[]{ judgeStoveNo, batchNo, processCode, new String[]{ "0", "4" } });
				GenericEntity chemCnt = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, GenericEntity.class);
				
				b = new SqlBuilder("JdgQcmBcPhyJudgeDAL.queryCntByBatchNo");
				b.Fill(new Object[]{ judgeStoveNo, batchNo, processCode, new String[]{ "0", "4" } });
				GenericEntity phyCnt = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, GenericEntity.class);
				if(chemCnt.getCount().equals("0") && phyCnt.getCount().equals("0")){
					throw new Exception("return");
				}
			}
		}
		
		return stoveBatchNoMap;
	}
	
	/**
	 * 获取订单
	 * @param b
	 * @param processCode
	 * @param judgeStoveNo
	 * @param con
	 * @return
	 * @throws Exception
	 */
	private PlnOrderZgSEntity getPlnOrderZgs(SqlBuilder b, String proPlanId, String gxPlanNo,
			String processCode, String judgeStoveNo, String craftProcess, Connection con) throws Exception{
		b = new SqlBuilder("JdgMatBcM.getCraftInfoByJudgeStoveNoProPlanId");
		b.Fill(new String[]{ judgeStoveNo, proPlanId, gxPlanNo, processCode });
		MatBcMEntity mat = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, MatBcMEntity.class);
		PlnOrderZgSEntity zgS = null;
		if(craftProcess.equals("D")){
			b = new SqlBuilder("JdgPlnOrderZgS.queryByPk");
			b.Fill(new String[]{ proPlanId, gxPlanNo });
			zgS = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, PlnOrderZgSEntity.class);
		}else if(craftProcess.equals("E")){
			b = new SqlBuilder("JdgPlnOrderDbkS.queryByPk");
			b.Fill(new String[]{proPlanId, gxPlanNo });
			zgS = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, PlnOrderZgSEntity.class);
		}else if(craftProcess.equals("F")){
			b = new SqlBuilder("JdgPlnOrderRclS.queryByPk");
			b.Fill(new String[]{ proPlanId, gxPlanNo });
			zgS = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, PlnOrderZgSEntity.class);
		}else if(craftProcess.equals("G")){
			b = new SqlBuilder("JdgPlnOrderJgxS.queryByPk");
			b.Fill(new String[]{ proPlanId, gxPlanNo });
			zgS = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, PlnOrderZgSEntity.class);
		}else{
			throw new Exception("工序异常");
		}
		
		zgS.setCic(mat.getCic());
		return zgS;
	}
	
	/**
	 * 获取炉计划
	 * @param b
	 * @param processCode
	 * @param judgeStoveNo
	 * @param con
	 * @return
	 * @throws Exception
	 */
	private PlnZyZgMEntity getPlnZyM(SqlBuilder b, String processCode, String judgeStoveNo,
			Connection con) throws Exception{
		PlnZyZgMEntity zyZg = null;
		if(processCode.equals("D")){
			b = new SqlBuilder("JdgPlnZyZgM.queryByJudgeStoveNo");
			b.Fill(new String[]{ judgeStoveNo });
			zyZg = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, PlnZyZgMEntity.class);
		}else if(processCode.equals("E")){
			b = new SqlBuilder("JdgPlnZyDbkM.queryByJudgeStoveNo");
			b.Fill(new String[]{ judgeStoveNo });
			zyZg = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, PlnZyZgMEntity.class);
		}else if(processCode.equals("F")){
			b = new SqlBuilder("JdgPlnZyRclM.queryByJudgeStoveNo");
			b.Fill(new String[]{ judgeStoveNo });
			zyZg = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, PlnZyZgMEntity.class);
		}else if(processCode.equals("G")){
			b = new SqlBuilder("JdgPlnZyJgxM.queryByJudgeStoveNo");
			b.Fill(new String[]{ judgeStoveNo });
			zyZg = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, PlnZyZgMEntity.class);
		}else{
			throw new Exception("工序异常");
		}
		
		return zyZg;
	}
	
//	private void checkSubCraftPhy(String processCode, String judgeStoveNo, String batchNo,
//			HashMap<String, String> judgeStoveNos,
//			SqlBuilder b, Connection con) throws Exception{
//		String ordLnDlyPk = "";
//		String craftSeq = "";
//		String mscPline = "";
//		String cic = "";
//		String pic = "";
//		
//		b = new SqlBuilder("JdgMatBcM.getCraftInfoByBatchNo");
//		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode });
//		MatBcMEntity matBcMEntity = EntityTool.getEntityBySqlNoClsCon(
//				b.toString(), con, MatBcMEntity.class);
//		String proPlanId = matBcMEntity.getProOrderId();
//		String gxPlanNo = matBcMEntity.getGxPlanNo();
//		cic = matBcMEntity.getCic();
//		if(processCode.equals("D")){
//			b = new SqlBuilder("JdgPlnOrderZgS.queryByPk");
//		}else if(processCode.equals("E")){
//			b = new SqlBuilder("JdgPlnOrderDbkS.queryByPk");
//		}else if(processCode.equals("F")){
//			b = new SqlBuilder("JdgPlnOrderRclS.queryByPk");
//		}else if(processCode.equals("G")){
//			b = new SqlBuilder("JdgPlnOrderJgxS.queryByPk");
//		}else{
//			throw new Exception("工序异常");
//		}
//		b.Fill(new String[]{ proPlanId, gxPlanNo });
//		PlnOrderZgSEntity plnZg = EntityTool.getEntityBySqlNoClsCon(
//				b.toString(), con, PlnOrderZgSEntity.class);
//		ordLnDlyPk = plnZg.getOrdLnDlyPk();
//		craftSeq = plnZg.getCraftSeq();
//		mscPline = plnZg.getIndexSeq();
//		pic = plnZg.getPic().split(",")[0];
//		
//		
//		b = new SqlBuilder("CraftOrdDesignStdCic.queryCraftChemByDlyLnPk");
//		b.Fill(new String[]{ ordLnDlyPk, craftSeq, mscPline, processCode, cic, "0" });
//		ArrayList<CraftOrdDesignStdCicEntity> craftChems = EntityTool.getEntitysBySqlNoClsCon(
//				b.toString(), con, CraftOrdDesignStdCicEntity.class);
//		b = new SqlBuilder("CraftOrdDesignStdPic.queryCraftPhyByDlyLnPk");
//		b.Fill(new String[]{ ordLnDlyPk, craftSeq, mscPline,
//				processCode, pic, "", "0" });
//		ArrayList<CraftOrdDesignStdPicEntity> craftPhys = EntityTool.getEntitysBySqlNoClsCon(
//				b.toString(), con, CraftOrdDesignStdPicEntity.class);
//		
//		for(String judgeStoveNoSub : judgeStoveNos.keySet()){
//			String batchNoSub = judgeStoveNos.get(judgeStoveNoSub);
//			if(craftChems.size() > 0){
//				PlnZyZgMEntity plnZy = getPlnZyM(b, processCode, judgeStoveNoSub, con);
//				b = new SqlBuilder("QcmJhyElementsDAL.getPhyByBatchNo");
//				b.Fill(new Object[]{ judgeStoveNoSub, batchNoSub, processCode, "0", plnZy.getOrdLnDlyPk()});
//				ArrayList<QcmJhyElementsEntity> jhyChems = EntityTool.getEntitysBySqlNoClsCon(
//						b.toString(), con, QcmJhyElementsEntity.class);
//				if(jhyChems.size() == 0){
//					throw new Exception("子炉号" + judgeStoveNoSub + "批号" + batchNoSub + "未找到检验记录");
//				}else{
//					for(CraftOrdDesignStdCicEntity craftChem : craftChems){
//						boolean exists = true;
//						for(QcmJhyElementsEntity jhyChem : jhyChems){
//							String fieldName = craftChem.getChemName();
//							if(fieldName.equals("As")){
//								fieldName = "Asn";
//							}
//							String value = EntityTool.getValue(jhyChem, fieldName);
//							if(value.equals("")){
//								exists = false;
//								break;
//							}
//						}
//						if(!exists){
//							throw new Exception("子炉号" + judgeStoveNoSub + "批号" + batchNoSub + ": 在检验信息中未找到化学元素" + craftChem.getChemName());
//						}
//					}
//				}
//			}
//			
//			if(craftPhys.size() > 0){
//				b = new SqlBuilder("QcmJhyPhyresultDAL.QueryByBatchNo");
//				b.Fill(new Object[]{ judgeStoveNoSub, batchNoSub, processCode, new String[]{"0", "1"} });
//				ArrayList<QcmJhyPhyresultEntity> jhyPhys = EntityTool.getEntitysBySqlNoClsCon(
//						b.toString(), con, QcmJhyPhyresultEntity.class);
//				if(jhyPhys.size() == 0){
//					throw new Exception("子炉号" + judgeStoveNoSub + "批号" + batchNoSub + "未找到检验记录");
//				}else{
//					for(CraftOrdDesignStdPicEntity craftPhy : craftPhys){
//						boolean exists = true;
//						for(QcmJhyPhyresultEntity jhyPhy : jhyPhys){
//							if(!craftPhy.getPhyCode().equals(jhyPhy.getPhyCode())){
//								exists = false;
//								break;
//							}
//						}
//						if(!exists){
//							throw new Exception("子炉号" + judgeStoveNoSub + "批号" + batchNoSub + ": 在检验信息中未找到检验项" + craftPhy.getPhyName());
//						}
//					}
//				}
//			}
//		}
//	}
	
	private void copyMainConsignJhy(String processCode, String lotNo, String judgeStoveNo, String batchNo,
			String judgeStoveNoBatchM, HashMap<String, ArrayList<String>> subStoveBatchMap,
			QcmZgJugdeApplyEntity apply, SqlBuilder b, Connection con, Statement st,
			Connection jhyCon, Statement jhySt) throws Exception{
		String judgeStoveNoM = judgeStoveNoBatchM.split("\\+")[0];
		String batchNoM = subStoveBatchMap.get(judgeStoveNoM).get(0);
		
		b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
		b.Fill(new String[]{ apply.getOrdLnDlyPk() });
		PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
		b = new SqlBuilder("CraftOrdDesignStdCic.queryCraftChemByOrdLnPk");
		b.Fill(new String[]{ plnSaleord.getOrdLnPk(), apply.getCraftSeq(), apply.getIndexSeq(),
				"A", apply.getCic(), "0" });
		ArrayList<CraftOrdDesignStdCicEntity> craftChems = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignStdCicEntity.class);
		b = new SqlBuilder("JdgCraftOrdDesignStd.getProductCnt");
		b.Fill(new String[]{ plnSaleord.getOrdLnPk(), apply.getCraftSeq(), "0" });
		CraftOrdDesignStdEntity craftStd = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignStdEntity.class);
		b = new SqlBuilder("CraftOrdDesignStdPic.queryCraftPhyByOrdLnPk");
		b.Fill(new String[]{ plnSaleord.getOrdLnPk(), apply.getCraftSeq(), apply.getIndexSeq(),
				processCode, apply.getPic(), "", "0" });
		ArrayList<CraftOrdDesignStdPicEntity> craftPhys = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignStdPicEntity.class);
		b = new SqlBuilder("JdgCraftOrdDesignStdPicSmp.getRate");
		b.Fill(new String[]{ plnSaleord.getOrdLnPk(), apply.getCraftSeq(), apply.getIndexSeq(),
				processCode, apply.getPic() });
		ArrayList<CraftOrdDesignStdPicSmpEntity> craftSmps = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignStdPicSmpEntity.class);
		
		//获取组炉主炉号最小的检验编号
		b = new SqlBuilder("JdgQcmZcCheckconsign.getOriginalByBatchNo");
		b.Fill(new Object[]{ judgeStoveNoM, batchNoM, "0", processCode });
		QcmZcCheckconsignEntity consignM = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, QcmZcCheckconsignEntity.class);

		b = new SqlBuilder("JdgQcmZcCheckconsign.getByBatchNoOrdLnPkCheckNo");
		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "0", apply.getOrdLnDlyPk(), "P" });
		QcmZcCheckconsignEntity oldConsign = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, QcmZcCheckconsignEntity.class);
		String checkNo = "";
		String F = "";
		if(oldConsign == null){
			//获取组炉炉号最大检验编号
			b = new SqlBuilder("JdgQcmZcCheckconsign.getMaxGroupCheckNo");
			b.Fill(new String[]{ judgeStoveNo, batchNo, "0", processCode });
			QcmZcCheckconsignEntity maxCheckNo = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, QcmZcCheckconsignEntity.class);
			if(!maxCheckNo.getCheckNo().equals("")){
				if(maxCheckNo.getCheckNo().contains("F")){
					checkNo = maxCheckNo.getCheckNo().replaceAll("F", "");
					String sN = String.valueOf(Integer.parseInt(checkNo.substring(1, 2)) + 1);
					if(sN.equals("10")){
						throw new Exception("此炉的检验编号已达上限，生成组炉检验编号失败！");
					}
					checkNo = "FP" + sN + checkNo.substring(2);
				}else{
					checkNo = maxCheckNo.getCheckNo();
					String sN = String.valueOf(Integer.parseInt(checkNo.substring(1, 2)) + 1);
					if(sN.equals("10")){
						throw new Exception("此炉的检验编号已达上限，生成组炉检验编号失败！");
					}
					checkNo = "P" + sN + checkNo.substring(2);
				}
			}else{
				if(consignM.getCheckNo().contains("F")){
					checkNo = consignM.getCheckNo().replaceAll("F", "");
					checkNo = "FP" + "0" + checkNo.substring(0, 2) + judgeStoveNo + checkNo.substring(8, 9);
				}else{
					checkNo = consignM.getCheckNo();
					checkNo = "P" + "0" + checkNo.substring(0, 2) + judgeStoveNo + checkNo.substring(8, 9);
				}
			}
		}else{
			checkNo = oldConsign.getCheckNo();
		}
		
		//删除委托
		b = new SqlBuilder("JdgQcmZcCheckconsign.deleteByBatchNoOrdLnPkCheckNo");
		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "0", apply.getOrdLnDlyPk(), "P" });
		st.executeUpdate(b.toString());
		
//		//删除126委托
//		b = new SqlBuilder("JdgPipeCheckConsignBaseInfo.deleteByJudgeNoOrderNo");
//		b.Fill(new String[]{ judgeStoveNo, processCode, NewSaleOrd.getOrderNo() + "/" + NewSaleOrd.getOrderSeq(), "P" });
//		jhySt.executeUpdate(b.toString());
		
		//复制委托
		String jsonM = EntityTool.getGsonByEntity(consignM);
		QcmZcCheckconsignEntity consign = EntityTool.getEntityByGson(jsonM, QcmZcCheckconsignEntity.class);
		consign.setCheckNo(checkNo);
		consign.setLotNo(lotNo);
		consign.setJudgeStoveNo(judgeStoveNo);
		consign.setBatchNo(batchNo);
		consign.setOrdLnDlyPk(apply.getOrdLnDlyPk());
		consign.setCraftSeq(apply.getCraftSeq());
		consign.setIndexSeq(apply.getIndexSeq());
		consign.setCic(apply.getCic());// 暂时用管坯CIC，应该用钢种去找对应的CIC
		consign.setPic(apply.getPic());
		consign.setCrafNo(apply.getCrafNo());
		consign.setSteelStandrad(apply.getSteelStandrad());
		String insertConsign = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckconsign.insert");
		insertConsign = EntityTool.fillSqlByEntity(insertConsign, consign);
		st.executeUpdate(insertConsign);
		
//		//复制126委托
//		String jsonPipeBase = EntityTool.getGsonByEntity(oldPipeBase);
//		PipeCheckconsignBaseinfoEntity pipeBase = EntityTool.getEntityByGson(
//				jsonPipeBase, PipeCheckconsignBaseinfoEntity.class);
//		String checkNoM = consignM.getCheckNo();
//		String checkNo126 = checkNoM.substring(0, 2) + judgeStoveNo + checkNoM.substring(checkNoM.length() - 1, checkNoM.length());
//		pipeBase.setCheckNo(checkNo126);
//		pipeBase.setLotNo(lotNo);
//		pipeBase.setHeatNo(judgeStoveNo);
//		pipeBase.setContractNo(NewSaleOrd.getOrderNo() + "/" + NewSaleOrd.getOrderSeq());
//		pipeBase.setCraftFileNo(apply.getCrafNo());
//		pipeBase.setIndexSeq(apply.getIndexSeq());
//		pipeBase.setCic(apply.getCic());
//		pipeBase.setPic(apply.getPic());
//		pipeBase.setLotNoGroup(apply.getLotNoGroup());
//		pipeBase.setCraftPath(craft.getCraftPath());
//		String insertBaseInfo = CoreXmlSqlParsersFactory.getSql("JdgPipeCheckConsignBaseInfo.insert");
//		insertBaseInfo = EntityTool.fillSqlByEntity(insertBaseInfo, pipeBase);
//		jhySt.executeUpdate(insertBaseInfo);
		
		//已添加主键  (按炉取样的会重复新增)
		ArrayList<String> detailPks = new ArrayList<String>(); //phyCodeMin+sampleNo
		ArrayList<String> jhyPhyPks = new ArrayList<String>(); //phyCode+sampleNo
		ArrayList<String> jhyChemPks = new ArrayList<String>(); //sampleNo
		//删除委托二层表
		b = new SqlBuilder("JdgQcmZcCheckConsignDetail.deleteByBatchNoOrdLnPkCheckNo");
		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "0", apply.getOrdLnDlyPk(), "P" });
		st.executeUpdate(b.toString());
		//复制委托二层表
		copyConsignDetail(craftStd, craftChems, craftSmps, consign, consignM, false, b, detailPks, con, st);
		//删除理化检验信息
		b = new SqlBuilder("QcmJhyPhyresultDAL.deleteByBatchNoOrdLnDlyPkCheckNo");
		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "0", apply.getOrdLnDlyPk(), "P" });
		st.executeUpdate(b.toString());
		//删除成分检验信息
		b = new SqlBuilder("QcmJhyElementsDAL.deleteByBathNoOrdLnDlyPkCheckNo");
		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "0", apply.getOrdLnDlyPk(), "P" });
		st.executeUpdate(b.toString());
		//复制检验实绩信息
		copyJhyData(craftStd, craftChems, craftSmps, craftPhys, consign, consignM, false, b, jhyPhyPks, jhyChemPks, con, st);
		
		//*************************处理组炉子炉号******************************
		for(String subJudgeStoveNo : subStoveBatchMap.keySet()){
			ArrayList<String> subBatchNos = subStoveBatchMap.get(subJudgeStoveNo);
			for(String subBatchNo : subBatchNos){
				//主炉号跳过。
				if(subJudgeStoveNo.equals(judgeStoveNoM) && subBatchNo.equals(batchNoM)){
					continue;
				}
				b = new SqlBuilder("JdgQcmZcCheckconsign.getOriginalByBatchNo");
				b.Fill(new Object[]{ subJudgeStoveNo, subBatchNo, "0", processCode });
				QcmZcCheckconsignEntity consignSub = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, QcmZcCheckconsignEntity.class);
				
				//复制委托二层表
				copyConsignDetail(craftStd, craftChems, craftSmps, consign, consignSub, true, b, detailPks, con, st);
				//复制检验实绩信息
				copyJhyData(craftStd, craftChems, craftSmps, craftPhys, consign, consignSub, true, b, jhyPhyPks, jhyChemPks, con, st);
			}
		}
		
		//去掉检验实绩表没有对应数据的二层表记录
		b = new SqlBuilder("JdgQcmZcCheckConsignDetail.deleteNoJhyData");
		b.Fill(new String[]{ checkNo });
		st.executeUpdate(b.toString());
	}
	
	private void copyConsignDetail(CraftOrdDesignStdEntity craftStd, ArrayList<CraftOrdDesignStdCicEntity> craftChems,
			ArrayList<CraftOrdDesignStdPicSmpEntity> craftSmps, QcmZcCheckconsignEntity consign, 
			QcmZcCheckconsignEntity consignSub, boolean isSubJudgeStoveNo,
			SqlBuilder b, ArrayList<String> detailPks,
			Connection con, Statement st) throws Exception{
		ArrayList<String> chems = new ArrayList<String>();
		for(CraftOrdDesignStdCicEntity craftChem : craftChems){
			if(chems.contains("HX") && chems.contains("ONH")) break;
			if(craftChem.equals("O") || craftChem.equals("N") || craftChem.equals("H")){
				if(chems.contains("ONH")){
					continue;
				}else{
					chems.add("ONH");
				}
			}else{
				if(chems.contains("HX")){
					continue;
				}else{
					chems.add("HX");
				}
			}
		}
		
//		String chemRate = "";
//		b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getOriginalRateByBatchNo");
//		b.Fill(new String[]{ consignSub.getJudgeStoveNo(), consignSub.getBatchNo(), 
//				consignSub.getProcessCode(), "0" });
//		ArrayList<QcmZcCheckconsignDetailEntity> details = EntityTool.getEntitysBySqlNoClsCon(
//				b.toString(), con, QcmZcCheckconsignDetailEntity.class);
//		for(QcmZcCheckconsignDetailEntity detail : details){
//			if(detail.getPhyCodeMax().equals("HX") || detail.getPhyCodeMax().equals("ONH")){
//				chemRate = detail.getRate();
//				break;
//			}
//		}
		
		ArrayList<QcmZcCheckconsignDetailEntity> chemDetails = new ArrayList<QcmZcCheckconsignDetailEntity>();
		for(String chem : chems){
//			}else{
//				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getByBatchNoPhyMin");
//				b.Fill(new String[]{ consignSub.getJudgeStoveNo(), consignSub.getBatchNo(),
//						consignSub.getProcessCode(), "0", consignSub.getOrdLnDlyPk(), phyCodeMin });
//			}
			if(craftStd.getRateN().equals("408603")){
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getOriginalByJudgeStoveNoPhyMin");
				b.Fill(new String[]{ consignSub.getJudgeStoveNo(), consignSub.getProcessCode(),
						"0", consignSub.getOrdLnDlyPk(), chem });
			}else{
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getOriginalByBatchNoPhyMin");
				b.Fill(new String[]{ consignSub.getJudgeStoveNo(), consignSub.getBatchNo(),
						consignSub.getProcessCode(), "0", consignSub.getOrdLnDlyPk(), chem });
			}
			ArrayList<QcmZcCheckconsignDetailEntity> tempChemDetails = new ArrayList<QcmZcCheckconsignDetailEntity>();
			tempChemDetails = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con, QcmZcCheckconsignDetailEntity.class);
//			if(tempChemDetails.size() == 0){
//				throw new Exception("原炉号" + consignSub.getJudgeStoveNo() + "批号" + consignSub.getBatchNo() + "未找到成分实绩信息");
//			}
			for(QcmZcCheckconsignDetailEntity chemDetail : tempChemDetails){
				chemDetails.add(chemDetail);
			}
		}
		
		//去除初验不合格项
		removeResampleDetail(chemDetails);
		
		//保存成分
		for(QcmZcCheckconsignDetailEntity chemDetail : chemDetails){
			//是否已添加
			if(detailPks.contains(chemDetail.getPhyCodeMax() + chemDetail.getSampleNo())){
				continue;
			}else{
				detailPks.add(chemDetail.getPhyCodeMax() + chemDetail.getSampleNo());
			}
			chemDetail.setCheckNo(consign.getCheckNo());
			chemDetail.setBatchNo(consign.getBatchNo());
			chemDetail.setOldJudgeStoveNo(consignSub.getJudgeStoveNo());
			chemDetail.setOldBatchNo(consignSub.getBatchNo());
			if(isSubJudgeStoveNo){
				chemDetail.setIsMain("0");
			}else{
				chemDetail.setIsMain("1");
			}
			String insertDetail = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckConsignDetail.insert");
			insertDetail = EntityTool.fillSqlByEntity(insertDetail, chemDetail);
			st.executeUpdate(insertDetail);
		}
		
		HashMap<String, String> phyCodeMins = new HashMap<String, String>();
		for(CraftOrdDesignStdPicSmpEntity craftSmp : craftSmps){
			if(phyCodeMins.containsKey(craftSmp.getPhyCodeMin())) continue;
			phyCodeMins.put(craftSmp.getPhyCodeMin(), craftSmp.getRate());
		}
		
		ArrayList<QcmZcCheckconsignDetailEntity> phyDetails = new ArrayList<QcmZcCheckconsignDetailEntity>();
		for(String phyCodeMin : phyCodeMins.keySet()){
			String rate = phyCodeMins.get(phyCodeMin);
			if(rate == null){
				String s = "";
			}
			//如果是生产批并且组炉炉号和组炉主炉号的生产批一样，那么不新增检验结果。
//			if(rate.equals("408601")){
//				continue;
//			}
			if(rate.equals("408601")){
				if(consign.getOrdLnDlyPk().equals(consignSub.getOrdLnDlyPk())){
					continue;
				}else{
					b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getOriginalByLotNoPhyMin");
					b.Fill(new String[]{ consignSub.getLotNo(), consignSub.getLotNoGroup(), consignSub.getProcessCode(),
							"0", consignSub.getOrdLnDlyPk(), phyCodeMin });
				}
			}else if(rate.equals("408603")){
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getOriginalByJudgeStoveNoPhyMin");
				b.Fill(new String[]{ consignSub.getJudgeStoveNo(), consignSub.getProcessCode(),
						"0", consignSub.getOrdLnDlyPk(), phyCodeMin });
			}else{
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getOriginalByBatchNoPhyMin");
				b.Fill(new String[]{ consignSub.getJudgeStoveNo(), consignSub.getBatchNo(),
						consignSub.getProcessCode(), "0", consignSub.getOrdLnDlyPk(), phyCodeMin });
			}
			ArrayList<QcmZcCheckconsignDetailEntity> tmpPhyDetails = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con, QcmZcCheckconsignDetailEntity.class);
			for(QcmZcCheckconsignDetailEntity phyDetail : tmpPhyDetails){
				phyDetails.add(phyDetail);
			}
		}
		
		//去除初验不合格项
		removeResampleDetail(phyDetails);
		
		//保存
		for(QcmZcCheckconsignDetailEntity phyDetail : phyDetails){
			//是否已添加
			if(detailPks.contains(phyDetail.getPhyCodeMax() + phyDetail.getSampleNo())){
				continue;
			}else{
				detailPks.add(phyDetail.getPhyCodeMax() + phyDetail.getSampleNo());
			}
			
			phyDetail.setCheckNo(consign.getCheckNo());
			phyDetail.setBatchNo(consign.getBatchNo());
			phyDetail.setOldJudgeStoveNo(consignSub.getJudgeStoveNo());
			phyDetail.setOldBatchNo(consignSub.getBatchNo());
			if(isSubJudgeStoveNo){
				phyDetail.setIsMain("0");
			}else{
				phyDetail.setIsMain("1");
			}
			String insertDetail = "";
			insertDetail = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckConsignDetail.insert");
			insertDetail = EntityTool.fillSqlByEntity(insertDetail, phyDetail);
			st.executeUpdate(insertDetail);
		}
	}
	
	private void copyJhyData(CraftOrdDesignStdEntity craftStd, ArrayList<CraftOrdDesignStdCicEntity> craftChems,
			ArrayList<CraftOrdDesignStdPicSmpEntity> craftSmps, ArrayList<CraftOrdDesignStdPicEntity> craftPhys,
			QcmZcCheckconsignEntity consign, QcmZcCheckconsignEntity consignSub,
			boolean isSubJudgeStoveNo, SqlBuilder b,ArrayList<String> jhyPhyPks,
			ArrayList<String> jhyChemPks, Connection con,
			Statement st) throws SQLException{
		
//		HashMap<String, String> rates = new HashMap<String, String>();
//		String chemRate = "";
//		b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getOriginalRateByBatchNo");
//		b.Fill(new String[]{ consignSub.getJudgeStoveNo(), consignSub.getBatchNo(), 
//				consignSub.getProcessCode(), "0" });
//		ArrayList<QcmZcCheckconsignDetailEntity> details = EntityTool.getEntitysBySqlNoClsCon(
//				b.toString(), con, QcmZcCheckconsignDetailEntity.class);
//		for(QcmZcCheckconsignDetailEntity detail : details){
//			if(detail.getPhyCodeMax().equals("HX") || detail.getPhyCodeMax().equals("ONH")){
//				chemRate = detail.getRate();
//			}else{
//				rates.put(detail.getPhyCodeMin(), detail.getRate());
//			}
//		}
		
		HashMap<String, String> phyCodeMins = new HashMap<String, String>();
		for(CraftOrdDesignStdPicSmpEntity craftSmp : craftSmps){
			if(phyCodeMins.containsKey(craftSmp.getPhyCodeMin())) continue;
			phyCodeMins.put(craftSmp.getPhyCodeMin(), craftSmp.getRate());
		}
		
		//复制成分实绩信息
		if(craftStd.getRateN().equals("408602")){
			b = new SqlBuilder("QcmJhyElementsDAL.getPhyByBatchNo");
			b.Fill(new String[]{ consignSub.getJudgeStoveNo(), consignSub.getBatchNo(),
					consignSub.getProcessCode(), "0", consignSub.getOrdLnDlyPk() });
		}else{
			b = new SqlBuilder("QcmJhyElementsDAL.getPhyByJudgeStoveNo");
			b.Fill(new String[]{ consignSub.getJudgeStoveNo(),
					consignSub.getProcessCode(), "0", consignSub.getOrdLnDlyPk() });
		}
		ArrayList<QcmJhyElementsEntity> jhyElements = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, QcmJhyElementsEntity.class);
		
		//去除初验不合格的成分
		removeChemResampleResult(jhyElements, b, con);
		
		for(QcmJhyElementsEntity jhyElement : jhyElements){
			//是否已添加
			if(jhyChemPks.contains(jhyElement.getSampleNo())){
				continue;
			}else{
				jhyChemPks.add(jhyElement.getSampleNo());
			}
			String insertChem = CoreXmlSqlParsersFactory.getSql("QcmJhyElementsDAL.insertQcmJhyElements");
			jhyElement.setSampleId(consign.getCheckNo());
			jhyElement.setAssayno(consign.getCheckNo() + "_" + jhyElement.getSampleNo() + "_C");
			jhyElement.setJudgeStoveNo(consign.getJudgeStoveNo());
			jhyElement.setBatchNo(consign.getBatchNo());
			jhyElement.setJudgeFlag("20");
			jhyElement.setLgJudgeFlag("00");
			insertChem = EntityTool.fillSqlByEntity(insertChem, jhyElement);
			st.executeUpdate(insertChem);
		}
		
		//复制理化实绩信息
		ArrayList<QcmJhyPhyresultEntity> jhyPhys = new ArrayList<QcmJhyPhyresultEntity>();
		for(CraftOrdDesignStdPicEntity craftPhy : craftPhys){
			if(craftPhy.getPhyCodeMin().equals("C0013")){
				String s = "";
				s = "";
			}
			String rate = phyCodeMins.get(craftPhy.getPhyCodeMin());
			if(rate == null) continue;
//			if(rate.equals("408601")){
//				continue;
//			}
			String itemCodeF = craftPhy.getItemCodeF();
			String itemCodeS = craftPhy.getItemCodeS();
			String itemCodeW = craftPhy.getItemCodeW();
			if(rate.equals("408601")){
				if(consign.getOrdLnDlyPk().equals(consignSub.getOrdLnDlyPk())){
					continue;
				}else{
					
					b = new SqlBuilder("QcmJhyPhyresultDAL.getByLotNoPhy");
					b.Fill(new String[]{ consignSub.getLotNo(), consignSub.getLotNoGroup(), consignSub.getProcessCode(), 
							"0", consignSub.getOrdLnDlyPk(), craftPhy.getPhyCode(), itemCodeF, itemCodeS, itemCodeW });
				}
			}else if(rate.equals("408603")){
				b = new SqlBuilder("QcmJhyPhyresultDAL.getByJudgeStoveNoPhy");
				b.Fill(new String[]{ consignSub.getJudgeStoveNo(), consignSub.getProcessCode(), 
						"0", consignSub.getOrdLnDlyPk(), craftPhy.getPhyCode(),
						itemCodeF, itemCodeS, itemCodeW });
			}else{
				b = new SqlBuilder("QcmJhyPhyresultDAL.getByBatchNoPhy");
				b.Fill(new String[]{ consignSub.getJudgeStoveNo(), consignSub.getBatchNo(),
						consignSub.getProcessCode(), "0", consignSub.getOrdLnDlyPk(), craftPhy.getPhyCode(),
						itemCodeF, itemCodeS, itemCodeW });
			}
			ArrayList<QcmJhyPhyresultEntity> tmpJhyPhys = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con, QcmJhyPhyresultEntity.class);
			for(QcmJhyPhyresultEntity jhyPhy : tmpJhyPhys){
				jhyPhys.add(jhyPhy);
			}
		}
		
		//去除理化初验不合的
		removePhyResampleResult(jhyPhys, b, con);
		
		for(QcmJhyPhyresultEntity jhyPhy : jhyPhys){
			//是否已添加
			if(jhyPhyPks.contains(jhyPhy.getPhyCode() + jhyPhy.getSampleNo())){
				continue;
			}else{
				jhyPhyPks.add(jhyPhy + jhyPhy.getSampleNo());
			}
			jhyPhy.setSampleId(consign.getCheckNo());
			jhyPhy.setLotNo(consign.getLotNo());
			jhyPhy.setJudgeStoveNo(consign.getJudgeStoveNo());
			jhyPhy.setBatchNo(consign.getBatchNo());
			jhyPhy.setJudgeFlag("00");
			String insertPhy = CoreXmlSqlParsersFactory.getSql("QcmJhyPhyresultDAL.Insert");
			insertPhy = EntityTool.fillSqlByEntity(insertPhy, jhyPhy);
			st.executeUpdate(insertPhy);
		}
	}
	
	private void removeResampleDetail(ArrayList<QcmZcCheckconsignDetailEntity> details){
		for(int i = details.size() - 1; i >= 0; i--){
			QcmZcCheckconsignDetailEntity detail = details.get(i);
			if(detail.getCheckNo().contains("F")){
				for(QcmZcCheckconsignDetailEntity chemDetail2 : details){
					if(chemDetail2.getPhyCodeMax().equals(detail.getPhyCodeMax())){
						if(!chemDetail2.getCheckNo().contains("F") && chemDetail2.getNkResult().equals("0")){
							chemDetail2.setNkResult(detail.getNkResult());
							chemDetail2.setJfResult(detail.getJfResult());
						}
					}
				}
				
				details.remove(i);
			}
		}
	}
	
	private void removeChemResampleResult(ArrayList<QcmJhyElementsEntity> jhyElements, SqlBuilder b, Connection con){
		//去除初验不合格的
		//处理成分复取样
		for(int i = jhyElements.size() - 1; i >= 0; i--){
			QcmJhyElementsEntity chem = jhyElements.get(i);
			if(chem.getSampleId().contains("F")){
				for(QcmJhyElementsEntity chem2 : jhyElements){
					if(!chem2.getSampleId().contains("F")){
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getByPk");
						b.Fill(new String[]{ chem2.getSampleId(), chem2.getBatchNo(), chem2.getSampleNo(), "HX" });
						QcmZcCheckconsignDetailEntity detailHx = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, QcmZcCheckconsignDetailEntity.class);
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getByPk");
						b.Fill(new String[]{ chem2.getSampleId(), chem2.getBatchNo(), chem2.getSampleNo(), "ONH" });
						QcmZcCheckconsignDetailEntity detailOnh = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, QcmZcCheckconsignDetailEntity.class);
						if(detailHx != null && detailHx.getNkResult().equals("0") || detailOnh != null && detailOnh.getNkResult().equals("0")){
							chem2.setAl(chem.getAl().equals("") ? chem2.getAl() : chem.getAl());
							chem2.setAl2o3(chem.getAl2o3().equals("") ? chem2.getAl2o3() : chem.getAl2o3());
							chem2.setAlins(chem.getAlins().equals("") ? chem2.getAlins() : chem.getAlins());
							chem2.setAls(chem.getAls().equals("") ? chem2.getAls() : chem.getAls());
							chem2.setAlt(chem.getAlt().equals("") ? chem2.getAlt() : chem.getAlt());
							chem2.setAsn(chem.getAsn().equals("") ? chem2.getAsn() : chem.getAsn());
							chem2.setB(chem.getB().equals("") ? chem2.getB() : chem.getB());
							chem2.setBi(chem.getBi().equals("") ? chem2.getBi() : chem.getBi());
							chem2.setBn(chem.getBn().equals("") ? chem2.getBn() : chem.getBn());
							chem2.setBs(chem.getBs().equals("") ? chem2.getBs() : chem.getBs());
							chem2.setC(chem.getC().equals("") ? chem2.getC() : chem.getC());
							chem2.setCa(chem.getCa().equals("") ? chem2.getCa() : chem.getCa());
							chem2.setCaf2(chem.getCaf2().equals("") ? chem2.getCaf2() : chem.getCaf2());
							chem2.setCao(chem.getCao().equals("") ? chem2.getCao() : chem.getCao());
							chem2.setCd(chem.getCd().equals("") ? chem2.getCd() : chem.getCd());
							chem2.setCe(chem.getCe().equals("") ? chem2.getCe() : chem.getCe());
							chem2.setCo(chem.getCo().equals("") ? chem2.getCo() : chem.getCo());
							chem2.setCr(chem.getCr().equals("") ? chem2.getCr() : chem.getCr());
							chem2.setCr2o3(chem.getCr2o3().equals("") ? chem2.getCr2o3() : chem.getCr2o3());
							chem2.setCu(chem.getCu().equals("") ? chem2.getCu() : chem.getCu());
							chem2.setFe(chem.getFe().equals("") ? chem2.getFe() : chem.getFe());
							chem2.setFe2o3(chem.getFe2o3().equals("") ? chem2.getFe2o3() : chem.getFe2o3());
							chem2.setFeo(chem.getFeo().equals("") ? chem2.getFeo() : chem.getFeo());
							chem2.setH(chem.getH().equals("") ? chem2.getH() : chem.getH());
							chem2.setH2o(chem.getH2o().equals("") ? chem2.getH2o() : chem.getH2o());
							chem2.setLa(chem.getLa().equals("") ? chem2.getLa() : chem.getLa());
							chem2.setMg(chem.getMg().equals("") ? chem2.getMg() : chem.getMg());
							chem2.setMgo(chem.getMgo().equals("") ? chem2.getMgo() : chem.getMgo());
							chem2.setMn(chem.getMn().equals("") ? chem2.getMn() : chem.getMn());
							chem2.setMno(chem.getMno().equals("") ? chem2.getMno() : chem.getMno());
							chem2.setMo(chem.getMo().equals("") ? chem2.getMo() : chem.getMo());
							chem2.setN(chem.getN().equals("") ? chem2.getN() : chem.getN());
							chem2.setNb(chem.getNb().equals("") ? chem2.getNb() : chem.getNb());
							chem2.setNi(chem.getNi().equals("") ? chem2.getNi() : chem.getNi());
							chem2.setO(chem.getO().equals("") ? chem2.getO() : chem.getO());
							chem2.setP(chem.getP().equals("") ? chem2.getP() : chem.getP());
							chem2.setP2o5(chem.getP2o5().equals("") ? chem2.getP2o5() : chem.getP2o5());
							chem2.setPb(chem.getPb().equals("") ? chem2.getPb() : chem.getPb());
							chem2.setS(chem.getS().equals("") ? chem2.getS() : chem.getS());
							chem2.setSb(chem.getSb().equals("") ? chem2.getSb() : chem.getSb());
							chem2.setSe(chem.getSe().equals("") ? chem2.getSe() : chem.getSe());
							chem2.setSi(chem.getSi().equals("") ? chem2.getSi() : chem.getSi());
							chem2.setSio2(chem.getSio2().equals("") ? chem2.getSio2() : chem.getSio2());
							chem2.setSn(chem.getSn().equals("") ? chem2.getSn() : chem.getSn());
							chem2.setTfe(chem.getTfe().equals("") ? chem2.getTfe() : chem.getTfe());
							chem2.setTfeo(chem.getTfeo().equals("") ? chem2.getTfeo() : chem.getTfeo());
							chem2.setTi(chem.getTi().equals("") ? chem2.getTi() : chem.getTi());
							chem2.setTio2(chem.getTio2().equals("") ? chem2.getTio2() : chem.getTio2());
							chem2.setV(chem.getV().equals("") ? chem2.getV() : chem.getV());
							chem2.setV2o5(chem.getV2o5().equals("") ? chem2.getV2o5() : chem.getV2o5());
							chem2.setW(chem.getW().equals("") ? chem2.getW() : chem.getW());
							chem2.setZn(chem.getZn().equals("") ? chem2.getZn() : chem.getZn());
							chem2.setZr(chem.getZr().equals("") ? chem2.getZr() : chem.getZr());
						}
					}
				}
				jhyElements.remove(i);
			}
		}
	}
	
	private void removePhyResampleResult(ArrayList<QcmJhyPhyresultEntity> jhyPhys, SqlBuilder b, Connection con){
		for(int i = jhyPhys.size() - 1; i >= 0; i--){
			QcmJhyPhyresultEntity phy = jhyPhys.get(i);
			if(phy.getSampleId().contains("F")){
				for(QcmJhyPhyresultEntity phy2 : jhyPhys){
					if(phy2.getPhyCode().equals(phy.getPhyCode())){
						if(!phy2.getSampleId().contains("F")){
							b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getByPk");
							b.Fill(new String[]{ phy2.getSampleId(), phy2.getBatchNo(), phy2.getSampleNo(), phy2.getPhyCodeMin() });
							QcmZcCheckconsignDetailEntity detail = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, QcmZcCheckconsignDetailEntity.class);
							if(detail != null && detail.getNkResult().equals("0")){
								phy2.setValue1(phy.getValue1());
								phy2.setValue2(phy.getValue2());
								phy2.setValue3(phy.getValue3());
								phy2.setValue4(phy.getValue4());
								phy2.setValue5(phy.getValue5());
								phy2.setValue6(phy.getValue6());
								phy2.setValue7(phy.getValue7());
								phy2.setValue8(phy.getValue8());
								phy2.setValue9(phy.getValue9());
								phy2.setValue10(phy.getValue10());
								phy2.setValue11(phy.getValue11());
								phy2.setValue12(phy.getValue12());
								phy2.setValue13(phy.getValue13());
								phy2.setValue14(phy.getValue14());
								phy2.setValue15(phy.getValue15());
								phy2.setAverage(phy.getAverage());
								phy2.setIsGood(phy.getIsGood());
								phy2.setIsDefect(phy.getIsDefect());
								phy2.setCheckTemp(phy.getCheckTemp());
								phy2.setHardnessType(phy.getHardnessType());
								phy2.setPhyCodeDir(phy.getPhyCodeDir());
								phy2.setPhyNameDir(phy.getPhyNameDir());
								phy2.setSampleStyle(phy.getSampleStyle());
								phy2.setSampleSize(phy.getSampleSize());
							}
						}
					}
				}
				jhyPhys.remove(i);
			}
		}
	}
	
	private void copyConsignLk(String processCode, String judgeStoveNo, String batchNo,
			PlnOrderZgSEntity plnZgs,Connection con,Connection jhyCon, Statement st,
			Statement jhyst,String heatPlanNo, String craftProcess, String lkProcessCode) throws Exception{
		SqlBuilder b = null;
		
		//已添加主键  (按炉取样的会重复新增)
		ArrayList<String> detailPks = new ArrayList<String>(); //phyCodeMin+sampleNo
		ArrayList<String> jhyPhyPks = new ArrayList<String>(); //phyCode+sampleNo
		ArrayList<String> jhyChemPks = new ArrayList<String>(); //sampleNo
		
		//获取原始委托信息
		b = new SqlBuilder("JdgQcmZcCheckconsign.getOriginalByBatchNo");
		b.Fill(new Object[]{ judgeStoveNo, batchNo, "0", processCode });
		ArrayList<QcmZcCheckconsignEntity> consigns = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, QcmZcCheckconsignEntity.class);
		if(consigns.size() == 0) return;
		QcmZcCheckconsignEntity oldConsign = EntityTool.copy(consigns.get(0), QcmZcCheckconsignEntity.class);
		
		String ordLnDlyPk = plnZgs.getOrdLnDlyPk();
		String craftSeq = plnZgs.getCraftSeq();
		String mscPline = plnZgs.getIndexSeq();
		String cic = plnZgs.getCic();
//		if(processCode.equals(lkProcessCode)){
//			cic = "";
//		}
		String pic = plnZgs.getPic();
		
		b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
		b.Fill(new String[]{ ordLnDlyPk });
		PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
		
		//获取126委托信息(合同号+炉号)
		b = new SqlBuilder("JdgQcmZcCheckconsign.getPipeBaseInfo");
		b.Fill(new Object[]{ judgeStoveNo, plnZgs.getOrderNo() + "/" +plnZgs.getOrderSeq(), processCode });
		ArrayList<PipeCheckconsignBaseinfoEntity> consignsBaseInfo = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), jhyCon, PipeCheckconsignBaseinfoEntity.class);
		
		ArrayList<String> chems = new ArrayList<String>();
		b = new SqlBuilder("CraftOrdDesignStdCic.queryCraftChemByOrdLnPk");
		b.Fill(new String[]{ plnSaleord.getOrdLnPk(), craftSeq, mscPline, "A", cic, "0" });
		ArrayList<CraftOrdDesignStdCicEntity> craftChems = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignStdCicEntity.class);
		for(CraftOrdDesignStdCicEntity craftChem : craftChems){
			if(chems.contains("HX") && chems.contains("ONH")) break;
			if(craftChem.equals("O") || craftChem.equals("N") || craftChem.equals("H")){
				if(chems.contains("ONH")){
					continue;
				}else{
					chems.add("ONH");
				}
			}else{
				if(chems.contains("HX")){
					continue;
				}else{
					chems.add("HX");
				}
			}
		}
		b = new SqlBuilder("JdgCraftOrdDesignStd.getProductCnt");
		b.Fill(new String[]{ plnSaleord.getOrdLnPk(), craftSeq, "0" });
		CraftOrdDesignStdEntity craftStd = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignStdEntity.class);
		
		b = new SqlBuilder("CraftOrdDesignStdPic.queryCraftPhyByOrdLnPk");
		b.Fill(new String[]{ plnSaleord.getOrdLnPk(), craftSeq, mscPline, craftProcess, pic, "", "0" });
		ArrayList<CraftOrdDesignStdPicEntity> craftPhys = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignStdPicEntity.class);
		b = new SqlBuilder("JdgCraftOrdDesignStdPicSmp.getRate");
		b.Fill(new String[]{ plnSaleord.getOrdLnPk(), craftSeq, mscPline, craftProcess, pic });
		ArrayList<CraftOrdDesignStdPicSmpEntity> craftSmps = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignStdPicSmpEntity.class);
		
		if(consignsBaseInfo != null)
		{
			//删除126委托相关信息(同炉同合同号)
			for(PipeCheckconsignBaseinfoEntity pipeBase : consignsBaseInfo)
			{
				String deletePipeSql = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckconsign.deletePipeBase");
				deletePipeSql = EntityTool.fillSqlByEntity(deletePipeSql,pipeBase);
				jhyst.executeUpdate(deletePipeSql);
				
				//删除委托
				b = new SqlBuilder("JdgQcmZcCheckconsign.deleteByBatchNoOrdLnPkCheckNo1");
				b.Fill(new String[]{ pipeBase.getCheckNo() });
				st.executeUpdate(b.toString());
				//删除委托二层表
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.deleteByBatchNoOrdLnPkCheckNo1");
				b.Fill(new String[]{ pipeBase.getCheckNo() });
				st.executeUpdate(b.toString());
				//删除理化检验信息
				b = new SqlBuilder("QcmJhyPhyresultDAL.deleteByBatchNoOrdLnDlyPkCheckNo1");
				b.Fill(new String[]{ pipeBase.getCheckNo() });
				st.executeUpdate(b.toString());
				//删除成分检验信息
				b = new SqlBuilder("QcmJhyElementsDAL.deleteByBathNoOrdLnDlyPkCheckNo1");
				b.Fill(new String[]{ pipeBase.getCheckNo() });
				st.executeUpdate(b.toString());
			}
		}
		
		//删除委托
		b = new SqlBuilder("JdgQcmZcCheckconsign.deleteByBatchNoOrdLnPkCheckNo");
		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "0", ordLnDlyPk, "L" });
		st.executeUpdate(b.toString());
		
		//新增委托
		QcmZcCheckconsignEntity consign = consigns.get(0);
		String oldCheckNo = consign.getCheckNo();
		//获取组炉炉号最大检验编号
		/*b = new SqlBuilder("JdgQcmZcCheckconsign.getMaxLkCheckNo");
		b.Fill(new String[]{ consign.getJudgeStoveNo(), consign.getBatchNo(), "0",
				processCode, consign.getCheckNo() });*/
		
		b = new SqlBuilder("JdgQcmZcCheckconsign.getMaxLkCheckNoNew");
		b.Fill(new String[]{ consign.getJudgeStoveNo(), "0",
				processCode, consign.getCheckNo() });
		QcmZcCheckconsignEntity maxCheckNo = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, QcmZcCheckconsignEntity.class);
		String checkNo = "";
		if(!maxCheckNo.getCheckNo().equals("")){
			checkNo = maxCheckNo.getCheckNo();
			int a=checkNo.indexOf("L", 0);
			String sN = String.valueOf(Integer.parseInt(checkNo.substring(a+1, a+2)) + 1);
			if(sN.equals("10")){
				throw new Exception("此炉的检验编号已达上限，生成组炉检验编号失败！");
			}
			if(oldCheckNo.contains("F"))
			{
			    checkNo = "FL" + sN + oldCheckNo.substring(1);
			}else
			{
				checkNo = "L" + sN + oldCheckNo;
			}
		}else{
			if(oldCheckNo.contains("F"))
			{
			    checkNo = "FL" + "0" + oldCheckNo.substring(1);
			}else
			{
				checkNo = "L" + "0" + oldCheckNo;
			}
		}
		consign.setOldCheckNo(oldCheckNo);
		consign.setCheckNo(checkNo);
		consign.setOrdLnDlyPk(plnZgs.getOrdLnDlyPk());
		consign.setCraftSeq(plnZgs.getCraftSeq());
		consign.setIndexSeq(plnZgs.getIndexSeq());
		consign.setCic(plnZgs.getCic());
		consign.setPic(plnZgs.getPic());
		consign.setCrafNo(plnZgs.getCraftFileNo());
		String steelStandrad = plnZgs.getCic() + "+" + plnZgs.getPic() + "+" + plnZgs.getSic() + "+" +
				plnZgs.getDic() + "+" + plnZgs.getWic() + "+" + plnZgs.getGic();
		consign.setSteelStandrad(steelStandrad);
		consign.setContractNo(plnZgs.getOrderNo() + "/" + plnZgs.getOrderSeq());
		consign.setLikuProcessCode(lkProcessCode);
		String insertConsign = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckconsign.insert");
		insertConsign = EntityTool.fillSqlByEntity(insertConsign, consign);
		st.executeUpdate(insertConsign);
		//删除委托二层表
		b = new SqlBuilder("JdgQcmZcCheckConsignDetail.deleteByBatchNoOrdLnPkCheckNo");
		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "0", ordLnDlyPk, "L" });
		st.executeUpdate(b.toString());
		//新增委托二层表
		copyConsignDetail(craftStd, craftChems, craftSmps, consign, oldConsign, false, b, detailPks, con, st);
		//删除理化检验信息
		b = new SqlBuilder("QcmJhyPhyresultDAL.deleteByBatchNoOrdLnDlyPkCheckNo");
		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "0", ordLnDlyPk, "L" });
		st.executeUpdate(b.toString());
		//删除成分检验信息
		b = new SqlBuilder("QcmJhyElementsDAL.deleteByBathNoOrdLnDlyPkCheckNo");
		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "0", ordLnDlyPk, "L" });
		st.executeUpdate(b.toString());
		//复制检验实绩信息
		copyJhyData(craftStd, craftChems, craftSmps, craftPhys, consign, oldConsign, false, b, jhyPhyPks, jhyChemPks, con, st);
		//去掉检验实绩表没有对应数据的二层表记录
		b = new SqlBuilder("JdgQcmZcCheckConsignDetail.deleteNoJhyData");
		b.Fill(new String[]{ checkNo });
		st.executeUpdate(b.toString());
		
//		//新增委托
//		for(QcmZcCheckconsignEntity consign : consigns){
//			String oldCheckNo = consign.getCheckNo();
//			//获取组炉炉号最大检验编号
//			b = new SqlBuilder("JdgQcmZcCheckconsign.getMaxLkCheckNo");
//			b.Fill(new String[]{ consign.getJudgeStoveNo(), consign.getBatchNo(), "0",
//					processCode, consign.getCheckNo() });
//			QcmZcCheckconsignEntity maxCheckNo = EntityTool.getEntityBySqlNoClsCon(
//					b.toString(), con, QcmZcCheckconsignEntity.class);
//			String checkNo = "";
//			if(!maxCheckNo.getCheckNo().equals("")){
//				checkNo = maxCheckNo.getCheckNo();
//				String sN = String.valueOf(Integer.parseInt(checkNo.substring(1, 2)) + 1);
//				if(sN.equals("10")){
//					throw new Exception("此炉的检验编号已达上限，生成组炉检验编号失败！");
//				}
//				if(oldCheckNo.contains("F"))
//				{
//				    checkNo = "FL" + sN + oldCheckNo.substring(1);
//				}else
//				{
//					checkNo = "L" + sN + oldCheckNo;
//				}
//			}else{
//				if(oldCheckNo.contains("F"))
//				{
//				    checkNo = "FL" + "0" + oldCheckNo.substring(1);
//				}else
//				{
//					checkNo = "L" + "0" + oldCheckNo;
//				}
//			}
//			consign.setOldCheckNo(oldCheckNo);
//			consign.setCheckNo(checkNo);
//			consign.setOrdLnDlyPk(plnZgs.getOrdLnDlyPk());
//			consign.setCraftSeq(plnZgs.getCraftSeq());
//			consign.setIndexSeq(plnZgs.getIndexSeq());
//			consign.setCic(plnZgs.getCic());
//			consign.setPic(plnZgs.getPic());
//			consign.setCrafNo(plnZgs.getCraftFileNo());
//			String steelStandrad = plnZgs.getCic() + "+" + plnZgs.getPic() + "+" + plnZgs.getSic() + "+" +
//					plnZgs.getDic() + "+" + plnZgs.getWic() + "+" + plnZgs.getGic();
//			consign.setSteelStandrad(steelStandrad);
//			consign.setContractNo(plnZgs.getOrderNo() + "/" + plnZgs.getOrderSeq());
//			
//			String insertConsign = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckconsign.insert");
//			insertConsign = EntityTool.fillSqlByEntity(insertConsign, consign);
//			st.executeUpdate(insertConsign);
//			
//			//新增126委托主表
//			String insertBaseInfo = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckconsign.insertPipeBaseInfo");
//			insertBaseInfo = EntityTool.fillSqlByEntity(insertBaseInfo, consign);
//			jhyst.executeUpdate(insertBaseInfo);
//			
//			//新增委托二层表
//			copyConsignDetail(craftStd, craftChems, craftSmps, consign, oldConsign, false, b, detailPks, con, st);
////			b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getConsignDetailByCheckNo");
////			b.Fill(new String[]{ oldCheckNo });
////			ArrayList<QcmZcCheckconsignDetailEntity> details = EntityTool.getEntitysBySqlNoClsCon(
////					b.toString(), con, QcmZcCheckconsignDetailEntity.class);
////			//处理复取样
////			removeResampleDetail(details);
////			//移除新合同中没有要求的试样组
////			for(QcmZcCheckconsignDetailEntity detail : details){
////				boolean exists = false;
////				if(detail.getPhyCodeMin().equals("HX") || detail.getPhyCodeMin().equals("ONH")){
////					if(chems.contains(detail.getPhyCodeMin())){
////						exists = true;;
////					}
////				}else{
////					for(CraftOrdDesignStdPicEntity craftPhy : craftPhys){
////						if(detail.getPhyCodeMin().equals(craftPhy.getPhyCodeMin())){
////							exists = true;
////						}
////					}
////				}
////				if(!exists){
////					continue;
////				}
////				detail.setCheckNo(checkNo);
////				String insertDetail = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckConsignDetail.insert");
////				insertDetail = EntityTool.fillSqlByEntity(insertDetail, detail);
////				st.executeUpdate(insertDetail);
////			}
//			
//			//新增126委托二层表
//			b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getPipeDetialByCheckNo");
//			b.Fill(new String[]{ oldCheckNo });
//			ArrayList<PipeCheckconsignDetailEntity> jhydetails = EntityTool.getEntitysBySqlNoClsCon(
//					b.toString(), jhyCon, PipeCheckconsignDetailEntity.class);
//			for(PipeCheckconsignDetailEntity jhydetail : jhydetails){
//				boolean exists = false;
//				if(jhydetail.getPhyCodeMax().equals("HX") || jhydetail.getPhyCodeMax().equals("ONH")){
//					if(chems.contains(jhydetail.getPhyCodeMax())){
//						exists = true;
//					}
//				}else{
//					for(CraftOrdDesignStdPicEntity craftPhy : craftPhys){
//						if(jhydetail.getPhyCodeMax().equals(craftPhy.getPhyCodeMin())){
//							exists = true;;
//						}
//					}
//				}
//				if(!exists){
//					continue;
//				}
//				jhydetail.setCheckNo(checkNo);
//				String insertPipeDetail = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckConsignDetail.insertPipeDetial");
//				insertPipeDetail = EntityTool.fillSqlByEntity(insertPipeDetail, jhydetail);
//				jhyst.executeUpdate(insertPipeDetail);
//			}
//			
//			//新增化学检验结果
//			//复制检验实绩信息
//			copyJhyData(craftStd, craftChems, craftSmps, craftPhys, consign, oldConsign, false, b, jhyPhyPks, jhyChemPks, con, st);
////			b = new SqlBuilder("QcmJhyElementsDAL.queryAllByCheckNo");
////			b.Fill(new String[]{ oldCheckNo, judgeStoveNo, batchNo, processCode });
////			ArrayList<QcmJhyElementsEntity> elements = EntityTool.getEntitysBySqlNoClsCon(
////					b.toString(), con, QcmJhyElementsEntity.class);
////			//处理复取样
////			removeChemResampleResult(elements, b, jhyCon);
////			if(chems.size() > 0){
////				for(QcmJhyElementsEntity element : elements){
////					element.setSampleId(checkNo);
////					element.setAssayno(consign.getCheckNo() + "_" + element.getSampleNo() + "_C");
////					element.setJudgeFlag("20");
////					element.setLgJudgeFlag("00");
////					String insertChem = CoreXmlSqlParsersFactory.getSql("QcmJhyElementsDAL.insertQcmJhyElements");
////					insertChem = EntityTool.fillSqlByEntity(insertChem, element);
////					st.executeUpdate(insertChem);
////				}
////			}
//			
//			//新增126化学检验结果
//			b = new SqlBuilder("QcmJhyElementsDAL.queryPipeChemCheckNo");
//			b.Fill(new String[]{ oldCheckNo});
//			ArrayList<PipeCheckconsignChemdetailEntity> jhyelements = EntityTool.getEntitysBySqlNoClsCon(
//					b.toString(), jhyCon, PipeCheckconsignChemdetailEntity.class);
//			if(chems.size() > 0){
//				for(PipeCheckconsignChemdetailEntity element : jhyelements){
//					element.setCheckNo(checkNo);
//					String insertJhyChem = CoreXmlSqlParsersFactory.getSql("QcmJhyElementsDAL.insertPipeElements");
//					insertJhyChem = EntityTool.fillSqlByEntity(insertJhyChem, element);
//					jhyst.executeUpdate(insertJhyChem);
//				}
//			}
//			
//			//新增理化检验结果
////			b = new SqlBuilder("QcmJhyPhyresultDAL.QueryByCheckNoBatchNo");
////			b.Fill(new String[]{ judgeStoveNo, batchNo, oldCheckNo, processCode });
////			ArrayList<QcmJhyPhyresultEntity> phys = EntityTool.getEntitysBySqlNoClsCon(
////					b.toString(), con, QcmJhyPhyresultEntity.class);
////			//处理复取样
////			removePhyResampleResult(phys, b, jhyCon);
////			//
////			for(QcmJhyPhyresultEntity phy : phys){
////				boolean exists = false;
////				for(CraftOrdDesignStdPicEntity craftPhy : craftPhys){
////					if(craftPhy.getPhyCodeMin().equals(phy.getPhyCodeMin())){
////						exists = true;
////					}
////				}
////				if(!exists){
////					continue;
////				}
////				phy.setSampleId(checkNo);
////				phy.setJudgeFlag("00");
////				String insertPhy = CoreXmlSqlParsersFactory.getSql("QcmJhyPhyresultDAL.Insert");
////				insertPhy = EntityTool.fillSqlByEntity(insertPhy, phy);
////				st.executeUpdate(insertPhy);
////			}
//			
//			//新增126理化检验结果
//			b = new SqlBuilder("QcmJhyPhyresultDAL.QueryPipePhyDeial");
//			b.Fill(new String[]{ oldCheckNo});
//			ArrayList<PipeCheckconsignPhydetailEntity> jhyphys = EntityTool.getEntitysBySqlNoClsCon(
//					b.toString(), jhyCon, PipeCheckconsignPhydetailEntity.class);
//			for(PipeCheckconsignPhydetailEntity phy : jhyphys){
//				boolean exists = false;
//				for(CraftOrdDesignStdPicEntity craftPhy : craftPhys){
//					if(craftPhy.getPhyCodeMin().equals(phy.getPhyCodeMax())){
//						exists = true;
//					}
//				}
//				if(!exists){
//					continue;
//				}
//				phy.setCheckNo(checkNo);
//				String insertPhyDetial = CoreXmlSqlParsersFactory.getSql("QcmJhyPhyresultDAL.InsertPhyDetail");
//				insertPhyDetial = EntityTool.fillSqlByEntity(insertPhyDetial, phy);
//				jhyst.executeUpdate(insertPhyDetial);
//			}
//		}
	}
}
