package com.steering.pss.judge.Bll;

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.comm.tools.StringTool;
import com.steering.pss.judge.comm.PhyJudgeHelper;
import com.steering.pss.judge.model.*;
import com.steering.pss.qcm.model.GenericEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignStdPicSmpEntity;

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class BllRolledTubePhyJudge extends DBCommon{

	/**
     * 判定
     */
    public CoreReturnObject judge(String checkNo, String memo, String user,
    		ArrayList<String> checkDetailJsons){
    	Connection con = null;
    	Connection jhyCon = null;
		Statement st = null;
		Statement stJhy = null;
		CoreReturnObject cro = new CoreReturnObject();
		SqlBuilder b;
        try{
        	con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			jhyCon = new DBCommon().getDao("JhyDao").getConnection();
			jhyCon.setAutoCommit(false);
			
			st = con.createStatement();
			stJhy=jhyCon.createStatement();
			ArrayList<QcmZcCheckconsignDetailEntity> consignDetails = new ArrayList<QcmZcCheckconsignDetailEntity>();
			for(String checkDetailJson : checkDetailJsons){
				QcmZcCheckconsignDetailEntity checkDetail = EntityTool.getEntityByGson(checkDetailJson,
						QcmZcCheckconsignDetailEntity.class);
				consignDetails.add(checkDetail);
			}
            //获取检验委托表
            b = new SqlBuilder("JdgQcmZcCheckconsign.queryAllByCheckNo");
            b.Fill(new String[]{ checkNo });
            List<QcmZcCheckconsignEntity> tmpConsigns = EntityTool.getEntitysBySqlNoClsCon(
            		b.toString(), con, QcmZcCheckconsignEntity.class);
            List<QcmZcCheckconsignEntity> consigns = new ArrayList<QcmZcCheckconsignEntity>();
            for(QcmZcCheckconsignEntity tmpconsign : tmpConsigns){
            	consigns.add(0, tmpconsign);
            }
            
            for(QcmZcCheckconsignEntity consign : consigns){
            	b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getByBatchNoGroupBySampleNo");
                b.Fill(new String[]{ consign.getCheckNo(), consign.getJudgeStoveNo(),
                		consign.getBatchNo(), consign.getProcessCode() });
                ArrayList<QcmZcCheckconsignDetailEntity> groupDetails = EntityTool.getEntitysBySqlNoClsCon(
            			b.toString(), con, QcmZcCheckconsignDetailEntity.class);
//                if(consign.getSteelStandrad().contains("PIC") && groupSampleNos.size() == 0){
//                	cro.setV_errMsg("没有找到理化检验信息！");
//                	return cro;
//                }
                
        		b = new SqlBuilder("QcmJhyElementsDAL.queryAllByCheckNo");
        		b.Fill(new String[]{ consign.getCheckNo(), consign.getJudgeStoveNo(),
        				consign.getBatchNo(), consign.getProcessCode() });
        		List<QcmJhyElementsEntity> jhyElements = EntityTool.getEntitysBySqlNoClsCon(
        				b.toString(), con, QcmJhyElementsEntity.class);
//        		if(consign.getSteelStandrad().contains("CIC") && jhyElements.size() == 0){
//        			cro.setV_errMsg("没有找到化学检验信息！");
//                	return cro;
//        		}
        		
        		b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
        		b.Fill(new String[]{ consign.getOrdLnDlyPk() });
        		PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
        		
        		//判定内控
    			b = new SqlBuilder("CraftOrdDesignStdCic.queryCraftChemByOrdLnPk");
    			b.Fill(new String[]{ plnSaleord.getOrdLnPk(), consign.getCraftSeq(),
    					consign.getIndexSeq(), "A", consign.getCic(), consign.getCraftSource() });
    			ArrayList<CraftOrdDesignStdCicEntity> craftCics = EntityTool.getEntitysBySqlNoClsCon(
    					b.toString(), con, CraftOrdDesignStdCicEntity.class);
//                if(consign.getSteelStandrad().contains("CIC") && craftCics.size() == 0){
//                	cro.setV_errMsg("没有找到成分工艺信息！");
//                	return cro;
//                }
                
                //综合判定已判定不能再判
                b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo2");
                b.Fill(new String[]{ consign.getJudgeStoveNo(), consign.getBatchNo(), consign.getProcessCode(), "" });
                QcmZgJugdeApplyEntity zgApply = EntityTool.getEntityBySqlNoClsCon(
                		b.toString(), con, QcmZgJugdeApplyEntity.class);
                if(zgApply != null && !zgApply.getJudgeResultCode().equals("")){
//                	cro.setV_errMsg("已进行综合判定，不能操作！（如需重新判定，请撤销综合判定）");
//                	return cro;
                }
                
                //判定成分
                String chemJudgeId = "";
                if(jhyElements.size() > 0){
                	String[] chemResults = BllRolledTubeChemJudge.judge(consign, plnSaleord.getOrdLnPk(), jhyElements,
                			craftCics, user, memo, con, st);
                	chemJudgeId = chemResults[0];
                }
                
    			String phyJudgeId = "";
                if(groupDetails.size() > 0){
                	phyJudgeId = judge(groupDetails, consign, plnSaleord.getOrdLnPk(), user, st, con);
                }
                
                //保存委托二层表的判定结果
                String processCode = consign.getProcessCode();
                //String chemResult = setChemConsignDetail(consign, processCode, checkDetails, st, con);
                ArrayList<QcmZcCheckconsignDetailEntity> batchConsignDetails = new ArrayList<QcmZcCheckconsignDetailEntity>();
                for(QcmZcCheckconsignDetailEntity consignDetail : consignDetails){
                	if(consignDetail.getBatchNo().equals(consign.getBatchNo())){
                		batchConsignDetails.add(consignDetail);
                	}
                }
                String[] phyResults = setConsignDetail(consign, processCode, batchConsignDetails, st, con, stJhy);
                String phyResult = phyResults[0];
                String chemResult = phyResults[1];
                String isNoSsc = phyResults[2];
                String isNoHic = phyResults[3];
                String resample = phyResults[4];
                String judgeResult = phyResults[5];
                
                b = new SqlBuilder("JdgQcmZcCheckconsign.updateResult");
                b.Fill(new String[]{ consign.getCheckNo(), consign.getJudgeStoveNo(), consign.getBatchNo(),
                		processCode, phyResult, chemResult, judgeResult, user, memo, chemJudgeId,
                		phyJudgeId, "20", resample, isNoSsc, isNoHic });
                st.executeUpdate(b.toString());
                
                //写入首次判定时间
                b = new SqlBuilder("JdgQcmZcCheckconsign.updateConsignFirstDate");
                b.Fill(new String[]{ consign.getCheckNo(), consign.getJudgeStoveNo(), consign.getBatchNo(),
                		processCode});
                st.executeUpdate(b.toString());
                
              
            }
            
            boolean existLotRate = false;//按生产批取样
            boolean existStoveRate = false;//按炉取样
            boolean existFd = false;//首日检
            QcmZcCheckconsignEntity consignTmp = null;
            for(QcmZcCheckconsignEntity consign : consigns){
            	consignTmp = consign;
            	if(consign.getCraftSource().equals("1")){
            		existFd = true;
            		continue;
            	}
            	b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getByBatchNo");
            	b.Fill(new String[]{ consign.getCheckNo(), consign.getBatchNo() });
            	ArrayList<QcmZcCheckconsignDetailEntity> details = EntityTool.getEntitysBySqlNoClsCon(
            			b.toString(), con, QcmZcCheckconsignDetailEntity.class);
        		for(QcmZcCheckconsignDetailEntity detail : details){
            		if(detail.getRate().equals("408601")){
            			existLotRate = true;
            		}else if(detail.getRate().equals("408603")){
            			existStoveRate = true;
            		}
            	}
            	
        		if(existFd || existLotRate || existStoveRate) continue;
        		b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
        		b.Fill(new String[]{ consign.getOrdLnDlyPk() });
        		PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
                BllRolledTubePhyJudge.setBcBatchResult(consign, plnSaleord.getOrdLnPk(), user, st, con);
            }
            
            //保存炉批结果
            if(existFd){
        		b = new SqlBuilder("JdgQcmZcCheckconsign.getByOrdLnDlyPkPline");
        		b.Fill(new String[]{ consignTmp.getOrdLnDlyPk(), consignTmp.getPlineCode(), "0",
        				consignTmp.getProcessCode() });
        		ArrayList<QcmZcCheckconsignEntity> stoveConsigns = EntityTool.getEntitysBySqlNoClsCon(
        				b.toString(), con, QcmZcCheckconsignEntity.class);
        		for(QcmZcCheckconsignEntity stoveConsign : stoveConsigns){
        			b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
            		b.Fill(new String[]{ stoveConsign.getOrdLnDlyPk() });
            		PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
        			BllRolledTubePhyJudge.setBcBatchResult(stoveConsign, plnSaleord.getOrdLnPk(), user, st, con);
        		}
        	}else if(existLotRate){
				String loopValue = "-1";
				ArrayList<QcmZcCheckconsignEntity> lotConsigns = new ArrayList<QcmZcCheckconsignEntity>();
				if (consignTmp.getOrdLnDlyPk().length() > 35) {
					b = new SqlBuilder("JdgCraftOrdDesignStdPicSmp.getRate");
					b.Fill(new String[]{ consignTmp.getOrdLnDlyPk().substring(0,35), consignTmp.getCraftSeq(), consignTmp.getIndexSeq() , consignTmp.getProcessCode(), consignTmp.getPic() });
					ArrayList<CraftOrdDesignStdPicSmpEntity> tmpCraftSmps = EntityTool.getEntitysBySqlNoClsCon(
							b.toString(), con, CraftOrdDesignStdPicSmpEntity.class);

					for (CraftOrdDesignStdPicSmpEntity tmpCraftSmp : tmpCraftSmps) {
						if(tmpCraftSmp.getLoopValue().equals("0")){
							loopValue = tmpCraftSmp.getLoopValue();
						}
					}
				}
				if ("0".equals(loopValue)) {
					b = new SqlBuilder("JdgQcmZcCheckconsign.getByLotNo");
					b.Fill(new String[]{ consignTmp.getLotNo(), "", "0",
							consignTmp.getProcessCode() });
					lotConsigns = EntityTool.getEntitysBySqlNoClsCon(
							b.toString(), con, QcmZcCheckconsignEntity.class);
				} else {
					b = new SqlBuilder("JdgQcmZcCheckconsign.getByLotNo");
					b.Fill(new String[]{ consignTmp.getLotNo(), consignTmp.getLotNoGroup(), "0",
							consignTmp.getProcessCode() });
					lotConsigns = EntityTool.getEntitysBySqlNoClsCon(
							b.toString(), con, QcmZcCheckconsignEntity.class);
				}

        		for(QcmZcCheckconsignEntity lotConsign : lotConsigns){
        			b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
            		b.Fill(new String[]{ lotConsign.getOrdLnDlyPk() });
            		PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
        			BllRolledTubePhyJudge.setBcBatchResult(lotConsign, plnSaleord.getOrdLnPk(), user, st, con);
        		}
        	}else if(existStoveRate){
        		b = new SqlBuilder("JdgQcmZcCheckconsign.getByJudgeStoveNo");
        		b.Fill(new String[]{ consignTmp.getJudgeStoveNo(), "0",
        				consignTmp.getProcessCode() });
        		ArrayList<QcmZcCheckconsignEntity> stoveConsigns = EntityTool.getEntitysBySqlNoClsCon(
        				b.toString(), con, QcmZcCheckconsignEntity.class);
        		for(QcmZcCheckconsignEntity stoveConsign : stoveConsigns){
        			b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
            		b.Fill(new String[]{ stoveConsign.getOrdLnDlyPk() });
            		PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
        			BllRolledTubePhyJudge.setBcBatchResult(stoveConsign, plnSaleord.getOrdLnPk(), user, st, con);
        		}
        	}
            
        	//更新工序判定判定条件不正确的数据（临时用）
//            b = new SqlBuilder("QcmZgJugdeApplyDAL.GetTEMP");
//            ArrayList<QcmZcCheckconsignEntity> zcConsigns = EntityTool.getEntitysBySqlNoClsCon(
//            		b.toString(), con, QcmZcCheckconsignEntity.class);
//            for(QcmZcCheckconsignEntity zcConsign : zcConsigns){
//            	BllRolledTubePhyJudge.setBcBatchResult(zcConsign, user, st, con);
//            	con.commit();
//            }
            //新增入库记录 （临时用）
//            b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo2");
//            b.Fill(new String[]{ "585152", "17001", "F" });
//            ArrayList<com.steering.pss.ydm.entity.QcmZgJugdeApplyEntity> applys = EntityTool.getEntitysBySqlNoClsCon(
//            		b.toString(), con, com.steering.pss.ydm.entity.QcmZgJugdeApplyEntity.class);
//    		FrmBcIqInList bcIqInList = new FrmBcIqInList();
//    		bcIqInList.insertBcInList(con, applys, user);
            jhyCon.commit();
            con.commit();
            return cro;
        }catch(Exception ex){
            cro.setV_errMsg("程序异常：" + ex.getMessage());
            try {
            	jhyCon.rollback();
				con.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            return cro;
        }finally{
        	try {
				st.close();
				stJhy.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	try {
        		jhyCon.close();
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }
    }
    
    /**
     * 保存委托二层表判定结果
     * @param st
     * @param con
     * @throws SQLException
     */
    private String[] setConsignDetail(QcmZcCheckconsignEntity consign, String processCode,
    		ArrayList<QcmZcCheckconsignDetailEntity> consignDetails, Statement st, 
    		Connection con, Statement stJhy)
    		throws SQLException{
    	String[] results = new String[6];
    	SqlBuilder b = null;
    	String okFlag="0";
    	
    	ArrayList<String> phyResults = new ArrayList<String>();
    	ArrayList<String> chemResults = new ArrayList<String>();
    	boolean noSsc = false;
    	boolean noHic = false;
    	boolean noOther = false;
		for(QcmZcCheckconsignDetailEntity consignDetail : consignDetails){
			String chkNkResult = consignDetail.getNkResult();
			String chkJfResult = consignDetail.getJfResult();
			if(consignDetail.getPhyNameMin().contains("SSC-A法试验")){
				String s = "";
				s = "";
			}
			ArrayList<String> phyNkResults = new ArrayList<String>();
			ArrayList<String> phyJfResults = new ArrayList<String>();
			if(consignDetail.getPhyCodeMin().equals("HX")){
				b = new SqlBuilder("JdgQcmBcChemResult.getChemResultBySampleNo");
				b.Fill(new String[]{ consignDetail.getSampleId(), consignDetail.getJudgeStoveNo(),
						consignDetail.getBatchNo(), consignDetail.getSampleNo(), consign.getCraftSource() });
				ArrayList<QcmBcChemResultEntity> bcChemResults = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmBcChemResultEntity.class);
				for(QcmBcChemResultEntity bcChemResult : bcChemResults){
					phyNkResults.add(bcChemResult.getNkQualified());
					phyJfResults.add(bcChemResult.getJfQualified());
				}
			}else{
				b = new SqlBuilder("JdgQcmBcPhyResult.getPhyResultBySampleNoPhyMin");
				b.Fill(new String[]{ consignDetail.getSampleId(), consignDetail.getJudgeStoveNo(),
						consignDetail.getBatchNo(), consignDetail.getSampleNo(), consign.getCraftSource(),
						consignDetail.getPhyCodeMin() });
				ArrayList<QcmBcPhyresultEntity> bcPhyResults = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmBcPhyresultEntity.class);
				for(QcmBcPhyresultEntity bcPhyResult : bcPhyResults){
					phyNkResults.add(bcPhyResult.getNkTolQualified());
					phyJfResults.add(bcPhyResult.getJfTolQualified());
				}
			}
			
			if(phyNkResults.size() == 0){
				consignDetail.setNkResult("");
			}else if(phyNkResults.contains("2")){
				if(consignDetail.getPhyCodeMin().equals("HX")){
					if(phyNkResults.contains("1")){
						consignDetail.setNkResult("0");
					}else{
						consignDetail.setNkResult("");
					}
				}else{
					consignDetail.setNkResult("");
				}
			}else if(phyNkResults.contains("3")){
				consignDetail.setNkResult("");
			}else if(phyNkResults.contains("0")){
				consignDetail.setNkResult("0");
			}else{
				consignDetail.setNkResult("1");
			}
			if(phyJfResults.size() == 0){
				consignDetail.setJfResult("");
			}else if(phyJfResults.contains("2")){
				if(consignDetail.getPhyCodeMin().equals("HX")){
					if(phyJfResults.contains("1")){
						consignDetail.setJfResult("0");
					}else{
						consignDetail.setJfResult("");
					}
				}else{
					consignDetail.setJfResult("");
				}
			}else if(phyJfResults.contains("3")){
				consignDetail.setJfResult("");
			}else if(phyJfResults.contains("0")){
				consignDetail.setJfResult("0");
			}else{
				consignDetail.setJfResult("1");
			}
			
			if((phyNkResults.size() == 0 || phyNkResults.contains("3") || consignDetail.getPhyNameMin().contains("冲击试验"))
					&& (consignDetail.getChk().equals("True") || consignDetail.getResultSource().equals("1"))){
				consignDetail.setResultSource("1");
				//只有结果为3 系统处理不了的可以人工修改结果
				consignDetail.setNkResult(chkNkResult);
				consignDetail.setJfResult(chkJfResult);
				//修改判定结果
	    		b = new SqlBuilder("JdgQcmBcPhyResult.updatePhyJudge");
	    		b.Fill(new String[]{ consignDetail.getJudgeStoveNo(), consignDetail.getBatchNo(),
	    				consignDetail.getSampleId(), consignDetail.getSampleNo(), processCode,
	    				consignDetail.getPhyCodeMin(),
	    				chkNkResult, chkJfResult});
	    		st.execute(b.toString());
			}else{
				consignDetail.setResultSource("0");
			}
			
			if(consignDetail.getNkResult().equals("")){
				if(consignDetail.getPhyCodeMin().equals("C0030") || consignDetail.getPhyCodeMin().equals("C0031")
						|| consignDetail.getPhyCodeMin().equals("C0032") || consignDetail.getPhyCodeMin().equals("C0033")
						|| consignDetail.getPhyCodeMin().equals("C0133") || consignDetail.getPhyCodeMin().equals("C0147")
						|| consignDetail.getPhyCodeMin().equals("C0150")){
					noSsc = true;
				}else if(consignDetail.getPhyCodeMin().equals("C0007") || consignDetail.getPhyCodeMin().equals("C0146")
						||consignDetail.getPhyCodeMin().equals("C0061") || consignDetail.getPhyCodeMin().equals("C0148")
						|| consignDetail.getPhyCodeMin().equals("C0065")){
					noHic = true;
				}else {
					noOther = true;
				}
			}
			if(consignDetail.getPhyCodeMin().equals("HX")){
				chemResults.add(consignDetail.getNkResult());
			}else{
				phyResults.add(consignDetail.getNkResult());
			}
			b = new SqlBuilder("JdgQcmZcCheckConsignDetail.setJudgeResult");
			b.Fill(new String[]{ consignDetail.getSampleId(), consignDetail.getBatchNo(), consignDetail.getSampleNo(),
					consignDetail.getPhyCodeMin(), consignDetail.getNkResult(),
					consignDetail.getJfResult(), consignDetail.getResultSource() });
			st.executeUpdate(b.toString());
			// 如果是化学，还要更新ONH。
			if(consignDetail.getPhyCodeMin().equals("HX")){
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.setJudgeResult");
				b.Fill(new String[]{ consignDetail.getSampleId(), consignDetail.getBatchNo(), consignDetail.getSampleNo(),
						"ONH", consignDetail.getNkResult(), consignDetail.getJfResult(),
						consignDetail.getResultSource() });
				st.executeUpdate(b.toString());
			}
			
			//修改检化验判定合格标识 只修改理化
			if("0".equals(consignDetail.getNkResult())||"0".equals(consignDetail.getJfResult())){
				if(!consignDetail.getPhyCodeMin().equals("HX")){
					String sql = CoreXmlSqlParsersFactory
			                .getSql("JdgQcmZcCheckconsign.isLxPhy");
			        PreparedStatement ps = con.prepareStatement(sql);
			        ps.setObject(1, consignDetail.getPhyCodeMin());
			        String count="";
			        ResultSet rs = ps.executeQuery();
			        if (rs.next()) {
			        	count=rs.getString(1);
			        }
			        rs.close();
			        ps.close();
			        if(!"0".equals(count))
			        {
			        	okFlag="1";
			            
			        }
				}
			}
			
		}
		
		//修改检化验判定合格标识 只修改理化
		b = new SqlBuilder("JdgQcmZcCheckconsign.updatePipeFlag");
        b.Fill(new String[]{ okFlag, consign.getCheckNo()});
        stJhy.executeUpdate(b.toString());
        
		//判断是否取复样
		String resample = "";
		for(QcmZcCheckconsignDetailEntity consignDetail : consignDetails){
			if(consignDetail.getNkResult().equals("0")){
				int failCnt = 0;
				int judgeCnt = 0;
				for(QcmZcCheckconsignDetailEntity consignDetail2 : consignDetails){
					if(consignDetail.getPhyCodeMin().equals(consignDetail2.getPhyCodeMin())){
						judgeCnt++;
						if(consignDetail2.getNkResult().equals("0")){
							failCnt++;
						}
					}
				}
				if(judgeCnt == 0){
					resample = "1";
				}else{
					if(failCnt < judgeCnt){
    					resample = "1";
					}else{
						resample = "0";
						break;
					}
				}
			}else if(consignDetail.getNkResult().equals("")){
				if(!consignDetail.getPhyCodeMin().equals("C0030") && !consignDetail.getPhyCodeMin().equals("C0031")
						&& !consignDetail.getPhyCodeMin().equals("C0032") && !consignDetail.getPhyCodeMin().equals("C0033")
						&& !consignDetail.getPhyCodeMin().equals("C0133") && !consignDetail.getPhyCodeMin().equals("C0147")
                        && !consignDetail.getPhyCodeMin().equals("C0007") && !consignDetail.getPhyCodeMin().equals("C0146")
                        && !consignDetail.getPhyCodeMin().equals("C0150") && !consignDetail.getPhyCodeMin().equals("C0065")
                        && !consignDetail.getPhyCodeMin().equals("C0061") && !consignDetail.getPhyCodeMin().equals("C0148")){
					resample = "0";
					break;
				}
			}else{
				if(resample.equals("")){
					resample = "0";
				}
			}
		}
    	
    	String isNoSsc = "0";
    	if(noSsc && !noOther){
    		isNoSsc = "1";
    	}
    	String isNoHic = "0";
    	if(noHic && !noOther){
    		isNoHic = "1";
    	}
    	
    	results[2] = isNoSsc;
    	results[3] = isNoHic;
    	results[4] = resample;
    	
    	results[0] = "";
    	if(phyResults.contains("")){
    		results[0] = "";
    	}else if(phyResults.contains("0")){
    		results[0] = "40740202";
    	}else if(phyResults.contains("1")){
    		results[0] = "40740201";
    	}
    	
    	results[1] = "";
    	if(chemResults.contains("")){
    		results[1] = "";
    	}else if(chemResults.contains("0")){
    		results[1] = "40740102";
    	}else if(chemResults.contains("1")){
    		results[1] = "40740101";
    	}
    	
    	String judgeResult = "";
        ArrayList<String> allResults = new ArrayList<String>();
        if(chemResults.size() > 0){
        	allResults.add(results[1]);
        }
        if(phyResults.size() > 0){
        	allResults.add(results[0]);
        }
        
        if(allResults.contains("")){
        	judgeResult = "";
        }else if(allResults.contains("40740104") || allResults.contains("40740204")){
        	judgeResult = "40740708";
        }else if(allResults.contains("40740103") || allResults.contains("40740203")){
        	judgeResult = "40740707";
        }else if(allResults.contains("40740102") || allResults.contains("40740202")){
        	judgeResult = "40740704";
        }else{
        	judgeResult = "40740701";
        }
        results[5] = judgeResult;
        
    	return results;
    }

	/**
	 * 成品判定获取试样组客户端
	 * @param applyCode
	 * @param judgeStoveNo
	 * @param batchNo
	 * @param mscPline
	 * @param cic
	 * @param pic
	 * @param ordLnPk
	 * @param ordLnDlyPk
	 * @param craftSeq
	 * @param proOrdLnPk
	 * @param phyCodeMins
	 * @param zcIsAllScrap
	 * @param zcApplyCode
	 * @param zcJudgeStoveNo
	 * @param zcBatchNo
	 * @return
	 */
    public CoreReturnObject getConsignDetailColligate(String applyCode, String judgeStoveNo, String batchNo,
				  String mscPline, String cic, String pic, String ordLnPk, String ordLnDlyPk,
					String craftSeq, String proOrdLnPk, ArrayList<String> phyCodeMins,
					String zcIsAllScrap, String zcApplyCode, String zcJudgeStoveNo,
                    String zcBatchNo, String formFlag){
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = null;
		try{
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
			b.Fill(new String[]{ applyCode, judgeStoveNo, batchNo });
			QcmZgJugdeApplyEntity apply = EntityTool.getEntityBySqlNoClsCon(b.toString(),
					con, QcmZgJugdeApplyEntity.class);

			QcmZcCheckconsignEntity consign = new QcmZcCheckconsignEntity();
			consign.setOrdLnDlyPk(ordLnDlyPk);
			consign.setCraftSeq(craftSeq);
			consign.setIndexSeq(mscPline);
			consign.setProcessCode(apply.getProcessCode());
			consign.setCic(cic);
			consign.setPic(pic);
			consign.setStoveNo(apply.getStoveNo());
			consign.setJudgeStoveNo(apply.getJudgeStoveNo());
			consign.setBatchNo(apply.getBatchNo());
			consign.setCraftSource("0");
			consign.setLotNo(apply.getLotNo());
			consign.setLotNoGroup(apply.getLotNoGroup());
			consign.setProduccode(apply.getProduccode());
			consign.setSteelcode(apply.getSteelcode());
			consign.setPlineCode(apply.getPlineCode());
			consign.setLikuProcessCode(apply.getLikuProcessCode());

			ArrayList<QcmZcCheckconsignDetailEntity> consignDetails = getConsignDetailColligate(consign,
					applyCode, judgeStoveNo, batchNo, ordLnPk, proOrdLnPk, phyCodeMins, zcIsAllScrap,
					zcApplyCode, zcJudgeStoveNo, zcBatchNo, formFlag, con);
			cro.setResult(EntityTool.getGsonByEntity(consignDetails));
			return cro;
		}catch (Exception ex){
			cro.setV_errMsg(ex.getMessage());
			return cro;
		}finally {
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 成品判定获取试样组服务端
	 * @param consign
	 * @param applyCode
	 * @param judgeStoveNo
	 * @param batchNo
	 * @param ordLnPk
	 * @param proOrdLnPk
	 * @param phyCodeMins
	 * @param zcIsAllScrap
	 * @param zcApplyCode
	 * @param zcJudgeStoveNo
	 * @param zcBatchNo
	 * @return
	 */
	public static ArrayList<QcmZcCheckconsignDetailEntity> getConsignDetailColligate(
			QcmZcCheckconsignEntity consign, String applyCode, String judgeStoveNo, String batchNo,
			String ordLnPk, String proOrdLnPk, ArrayList<String> phyCodeMins, String zcIsAllScrap,
			String zcApplyCode, String zcJudgeStoveNo, String zcBatchNo, String formFlag, Connection con){
		SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
		b.Fill(new String[]{ applyCode, judgeStoveNo, batchNo });
		QcmZgJugdeApplyEntity apply = EntityTool.getEntityBySqlNoClsCon(b.toString(),
				con, QcmZgJugdeApplyEntity.class);
		ArrayList<QcmZcCheckconsignDetailEntity> consignDetails = getAllCraftPhySplines(
				consign, ordLnPk, proOrdLnPk, phyCodeMins, con);

		b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
		b.Fill(new String[]{ zcApplyCode, zcJudgeStoveNo, zcBatchNo });
		QcmZgJugdeApplyEntity zcApply = EntityTool.getEntityBySqlNoClsCon(b.toString(),
				con, QcmZgJugdeApplyEntity.class);
		String zcOrdLnPk = BllZcColligateJudge.getOrdLnPkByDlyPk(zcApply.getOrdLnDlyPk(), b, con);
		b = new SqlBuilder("JdgCraftOrdDesignMscPlPrc.getEndProcessByOrdLnPk");

		b.Fill(new String[]{ zcOrdLnPk, zcApply.getCraftSeq(), zcApply.getIndexSeq() });
		QcmZgJugdeApplyEntity endProcess = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, QcmZgJugdeApplyEntity.class);

		//处理成品利库判定结果
		b = new SqlBuilder("JdgComBaseProduct.getByPk", zcApply.getProduccode());
		ComBaseProductEntity product = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, ComBaseProductEntity.class);

        if(product != null) {
            String producType = product.getProducType();
            if (producType.equals("C") || producType.equals("D") || producType.equals("E")) {
                b = new SqlBuilder("JdgQcmZcChemPhyDetail.getByBatchNoZZb");
                b.Fill(new String[]{zcJudgeStoveNo, zcBatchNo, apply.getProcessCode()});
            } else {
                b = new SqlBuilder("JdgQcmZcChemPhyDetail.getByBatchNoApplyCode");
                b.Fill(new String[]{zcJudgeStoveNo, zcBatchNo, zcApplyCode, apply.getProcessCode()});
            }
        }else{
            b = new SqlBuilder("JdgQcmZcChemPhyDetail.getByBatchNoApplyCode");
            b.Fill(new String[]{zcJudgeStoveNo, zcBatchNo, zcApplyCode, apply.getProcessCode()});
        }

		ArrayList<QcmZcChemPhyDetailEntity> zcDetails = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, QcmZcChemPhyDetailEntity.class);
		for(QcmZcCheckconsignDetailEntity detail : consignDetails) {
			if(zcDetails.size() == 0){
				if(formFlag.equals("zc") || zcOrdLnPk.startsWith("BL") && endProcess.getProcessCode().equals(zcApply.getProcessCode())){
					detail.setResultSource("");
					detail.setJfResult("");
					detail.setNkResult("");
				}
			}else{
				for (QcmZcChemPhyDetailEntity zcDetail : zcDetails) {
					if (zcDetail.getCheckNo().equals(detail.getSampleId()) && zcDetail.getSampleNo().equals(detail.getSampleNo())
							&& zcDetail.getPhyCodeMin().equals(detail.getPhyCodeMin())) {
						detail.setResultSource(zcDetail.getResultSource());
						detail.setJfResult(zcDetail.getJfResult());
						detail.setNkResult(zcDetail.getNkResult());
						break;
					}
				}
			}
		}

		return consignDetails;
	}

	public CoreReturnObject getConsignDetailPhy(String checkNo, String ordLnPk, String processCode,
			String craftSeq, String mscPline, String cic, String pic, String craftProcess,
			ArrayList<String> phyCodeMins){
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = null;
		try{
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			SqlBuilder b = null;
			ArrayList<QcmZcCheckconsignDetailEntity> consignDetails = getPhyDetails(checkNo, ordLnPk,
					processCode, craftSeq, mscPline, cic, pic, craftProcess, phyCodeMins, b, con);
			cro.setResult(EntityTool.getGsonByEntity(consignDetails));

			return cro;
		}catch (Exception ex){
			cro.setV_errMsg(ex.getMessage());
			return cro;
		}finally {
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public CoreReturnObject getConsignDetailLg(String ordLnPk, String craftSeq, String stoveNo,
			String lgJudgeStoveNo, String cic, String zcApplyCode, String zcJudgeStoveNo,
			String zcBatchNo, String zcIsAllScrap){
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = null;
		try{
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			SqlBuilder b = null;
			ArrayList<QcmZcCheckconsignDetailEntity> consignDetails = getLgDetails(ordLnPk, craftSeq,
					stoveNo, lgJudgeStoveNo, cic, b, con);
			int cnt601F = 0;
			int cnt602F = 0;
			for(int i = consignDetails.size() - 1; i >= 0; i--){
				QcmZcCheckconsignDetailEntity consignDetail = consignDetails.get(i);
				if(consignDetail.getSampleNo().startsWith("601F")){
					cnt601F++;
					if(cnt601F >= 2){
						consignDetails.remove(i);
					}
				}
				if(consignDetail.getSampleNo().startsWith("602F")){
					cnt602F++;
					if(cnt602F >= 2){
						consignDetails.remove(i);
					}
				}
			}

			//处理成品利库判定结果
			if(!zcApplyCode.equals("")){
				b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo", zcApplyCode, zcJudgeStoveNo, zcBatchNo );
				QcmZgJugdeApplyEntity zcApply = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, QcmZgJugdeApplyEntity.class);
				b = new SqlBuilder("JdgComBaseProduct.getByPk", zcApply.getProduccode());
				ComBaseProductEntity product = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, ComBaseProductEntity.class);
				String producType = product.getProducType();
				if(producType.equals("C") || producType.equals("D") || producType.equals("E")){
					b = new SqlBuilder("JdgQcmZcChemPhyDetail.getByBatchNoZZb");
					b.Fill(new String[]{ zcJudgeStoveNo, zcBatchNo, "A" });
				}else{
					b = new SqlBuilder("JdgQcmZcChemPhyDetail.getByBatchNoApplyCode");
					b.Fill(new String[]{ zcJudgeStoveNo, zcBatchNo, zcApplyCode, "A" });
				}
				ArrayList<QcmZcChemPhyDetailEntity> zcDetails = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmZcChemPhyDetailEntity.class);
				for(QcmZcCheckconsignDetailEntity detail : consignDetails) {
					if(zcDetails.size() == 0){
						detail.setResultSource("");
						detail.setJfResult("");
						detail.setNkResult("");
					}else{
						for (QcmZcChemPhyDetailEntity zcDetail : zcDetails) {
							if (zcDetail.getCheckNo().equals(detail.getSampleId()) && zcDetail.getSampleNo().equals(detail.getSampleNo())
									&& zcDetail.getPhyCodeMin().equals(detail.getPhyCodeMin())) {
								detail.setResultSource(zcDetail.getResultSource());
								detail.setJfResult(zcDetail.getJfResult());
								detail.setNkResult(zcDetail.getNkResult());
								break;
							}
						}
					}
				}
			}

			cro.setResult(EntityTool.getGsonByEntity(consignDetails));

			return cro;
		}catch (Exception ex){
			cro.setV_errMsg(ex.getMessage());
			return cro;
		}finally {
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
    
    /**
     * 
     * @param consign
     * @param con
     * @return
     */
    public static ArrayList<QcmZcCheckconsignDetailEntity> getAllCraftPhySplines(QcmZcCheckconsignEntity consign,
    		String ordLnPk, String proOrdLnPk, ArrayList<String> phyCodeMins, Connection con){
    	SqlBuilder b = null;
    	String craftProcess = consign.getLikuProcessCode().equals("") ? consign.getProcessCode() : consign.getLikuProcessCode();
    	b = new SqlBuilder("QcmGpJugdeApplyDAL.getPlineByStoveNo");
		b.Fill(new String[]{ consign.getStoveNo() });
		QcmGpJudgeApplyEntity gpJudge = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, QcmGpJudgeApplyEntity.class);
		String gpType = "";
		if(gpJudge != null){
			if(gpJudge.getPlineCode().equals("C063") || gpJudge.getPlineCode().equals("C064")){
				gpType = "1";
    		}else{
    			gpType = "0";
    		}
		}

		ArrayList<QcmZcCheckconsignDetailEntity> details = getColligateDetails(consign.getJudgeStoveNo(), consign.getBatchNo(), consign.getLotNo(), consign.getLotNoGroup(),
				ordLnPk, proOrdLnPk, consign.getProcessCode(), "0", "", consign.getCraftSeq(),
				consign.getIndexSeq(), consign.getCic(), consign.getPic(), consign.getPlineCode(), gpType, craftProcess,
				phyCodeMins, b, con);

		//重新热处理
		ArrayList<QcmZcCheckconsignDetailEntity> rclDetails = getColligateDetails(consign.getJudgeStoveNo(), consign.getBatchNo(), consign.getLotNo(), consign.getLotNoGroup(),
				ordLnPk, proOrdLnPk, consign.getProcessCode(), "1", "", consign.getCraftSeq(),
				consign.getIndexSeq(), consign.getCic(), consign.getPic(), consign.getPlineCode(), gpType, craftProcess,
				phyCodeMins, b, con);
		HashMap<String, ArrayList<QcmZcCheckconsignDetailEntity>> phyMap = new HashMap<String, ArrayList<QcmZcCheckconsignDetailEntity>>();
		for(QcmZcCheckconsignDetailEntity detail : details){
			if(!detail.getSampleNo().equals("")) continue;
			if(phyMap.containsKey(detail.getPhyCodeMin())){
				ArrayList<QcmZcCheckconsignDetailEntity> tmpSplines = phyMap.get(detail.getPhyCodeMin());
				tmpSplines.add(detail);
			}else{
				ArrayList<QcmZcCheckconsignDetailEntity> tmpSplines = new ArrayList<QcmZcCheckconsignDetailEntity>();
				tmpSplines.add(detail);
				phyMap.put(detail.getPhyCodeMin(), tmpSplines);
			}
		}

		for(String key : phyMap.keySet()){
			boolean addRcl = false;
			for(QcmZcCheckconsignDetailEntity detail : rclDetails){
				if(detail.getSampleNo().equals("")) continue;
				if(detail.getPhyCodeMin().equals(key)){
					details.add(detail);
					addRcl = true;
				}
			}
			if(addRcl){
				ArrayList<QcmZcCheckconsignDetailEntity> tmpSplines = phyMap.get(key);
				for(QcmZcCheckconsignDetailEntity tmpSpline : tmpSplines){
					details.remove(tmpSpline);
				}
			}
		}

    	return details;
    }

    private static ArrayList<QcmZcCheckconsignDetailEntity> getColligateDetails(String judgeStoveNo, String batchNo,
			String lotNo, String lotNoGroup, String ordLnPk, String proOrdLnPk, String processCode,
			String rclFlag, String isMan, String craftSeq, String mscPline, String cic, String pic,
			String plineCode, String gpType, String craftProcess, ArrayList<String> phyCodeMins, SqlBuilder b,
			Connection con){
    	//查询理化工艺
		b = new SqlBuilder("CraftOrdDesignStdPic.getPhyCnt");
		b.Fill(new String[]{ ordLnPk, craftSeq, craftProcess, "0", mscPline });
		GenericEntity phyCount = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, GenericEntity.class);
		b = new SqlBuilder("CraftOrdDesignStdPic.getPhyCnt");
		b.Fill(new String[]{ ordLnPk, craftSeq, craftProcess, "1", mscPline });
		GenericEntity phyCountFd = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, GenericEntity.class);
		ArrayList<CraftOrdDesignStdPicSmpEntity> craftSmps = new ArrayList<CraftOrdDesignStdPicSmpEntity>();
		if(!phyCount.getCount().equals("0")){
			b = new SqlBuilder("JdgCraftOrdDesignStdPicSmp.getRate");
			b.Fill(new String[]{ ordLnPk, craftSeq, mscPline, craftProcess, pic });
			ArrayList<CraftOrdDesignStdPicSmpEntity> tmpCraftSmps = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con, CraftOrdDesignStdPicSmpEntity.class);
			for(CraftOrdDesignStdPicSmpEntity tmpCraftSmp : tmpCraftSmps){
				tmpCraftSmp.setCraftSource("0");
				craftSmps.add(tmpCraftSmp);
			}
		}
		if(!phyCountFd.getCount().equals("0")){
			b = new SqlBuilder("JdgCraftOrdDesignStdPicSmp.getFdRate");
			b.Fill(new String[]{ ordLnPk, craftSeq});
			ArrayList<CraftOrdDesignStdPicSmpEntity> tmpCraftSmps = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con, CraftOrdDesignStdPicSmpEntity.class);
			for(CraftOrdDesignStdPicSmpEntity tmpCraftSmp : tmpCraftSmps){
				tmpCraftSmp.setCraftSource("1");
				craftSmps.add(tmpCraftSmp);
			}
		}
		//查询成分工艺
		b = new SqlBuilder("CraftOrdDesignStdCic.getChemCnt");
		b.Fill(new String[]{ ordLnPk, craftSeq,
				"0", mscPline, craftProcess });
		GenericEntity chemCount = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, GenericEntity.class);
		b = new SqlBuilder("CraftOrdDesignStdCic.getChemCnt");
		b.Fill(new String[]{ ordLnPk, craftSeq, "1", mscPline, craftProcess });
		GenericEntity chemCountFd = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, GenericEntity.class);
		if(!chemCount.getCount().equals("0")){
			b = new SqlBuilder("JdgCraftOrdDesignStd.getProductCnt");
			b.Fill(new String[]{ ordLnPk, craftSeq, "0" });
			CraftOrdDesignStdEntity craftStd = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, CraftOrdDesignStdEntity.class);
			CraftOrdDesignStdPicSmpEntity chemSmp = new CraftOrdDesignStdPicSmpEntity();
			if(craftStd != null){
				chemSmp.setRate(craftStd.getRateN());
				chemSmp.setDescRate(craftStd.getDescRateN());
				chemSmp.setDescCount(craftStd.getProductCntN());
			}
			chemSmp.setSampleCount("1");
			chemSmp.setPhyCodeMin("HX");
			chemSmp.setPhyNameMin("化学");
			chemSmp.setPic(cic);
			chemSmp.setCraftSource("0");
			craftSmps.add(chemSmp);
		}
		if(!chemCountFd.getCount().equals("0")){
			b = new SqlBuilder("JdgCraftOrdDesignStd.getProductCnt");
			b.Fill(new String[]{ ordLnPk, craftSeq, "1" });
			CraftOrdDesignStdEntity craftStd = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, CraftOrdDesignStdEntity.class);
			CraftOrdDesignStdPicSmpEntity chemSmp = new CraftOrdDesignStdPicSmpEntity();
			if(craftStd != null){
				chemSmp.setRate(craftStd.getRateN());
				chemSmp.setDescRate(craftStd.getDescRateN());
				chemSmp.setDescCount(craftStd.getProductCntN());
			}
			chemSmp.setSampleCount("1");
			chemSmp.setPhyCodeMin("HX");
			chemSmp.setPhyNameMin("化学");
			chemSmp.setPic(cic);
			chemSmp.setCraftSource("1");
			craftSmps.add(chemSmp);
		}

		ArrayList<QcmZcCheckconsignDetailEntity> consignDetails = new ArrayList<QcmZcCheckconsignDetailEntity>();
		for(CraftOrdDesignStdPicSmpEntity craftSmp : craftSmps){
			if(phyCodeMins.size() != 0 && !phyCodeMins.contains(craftSmp.getPhyCodeMin())) continue;
			ArrayList<QcmZcCheckconsignDetailEntity> tmpConsignDetails = null;
			if(craftSmp.getCraftSource().equals("1")){//首日检
				if(ordLnPk.startsWith("BL")){
					b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetBLPhyMinByOrdLnPk");
					b.Fill(new String[]{ processCode, craftSmp.getCraftSource(), rclFlag, plineCode, ordLnPk,
							craftSmp.getPhyCodeMin(), isMan, gpType });
					tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
							b.toString(), con, QcmZcCheckconsignDetailEntity.class);
				}else{
					b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetPhyMinByOrdLnPk");
					b.Fill(new String[]{ processCode, craftSmp.getCraftSource(), rclFlag, plineCode, ordLnPk,
							craftSmp.getPhyCodeMin(), isMan, gpType });
					tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
							b.toString(), con, QcmZcCheckconsignDetailEntity.class);
				}
			}else if(craftSmp.getRate().equals("408601")){ // 生产批(炉)
				if(ordLnPk.startsWith("BL")){
					b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetBLPhyMinByLotNo");
					b.Fill(new String[]{ lotNo, lotNoGroup, processCode, craftSmp.getCraftSource(), rclFlag,
							craftSmp.getPhyCodeMin(), isMan, plineCode, ordLnPk });
					tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
							b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					if(tmpConsignDetails.size() == 0){
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetBLPhyMinByLotNo");
						b.Fill(new String[]{ lotNo, lotNoGroup, processCode, craftSmp.getCraftSource(), rclFlag,
								craftSmp.getPhyCodeMin(), isMan, "", "" });
						tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
								b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					}
					if(tmpConsignDetails.size() == 0 && "0".equals(craftSmp.getLoopValue())){ //循环值为0 按合同
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetBLPhyMinByLotNo");
						b.Fill(new String[]{ "", "", processCode, craftSmp.getCraftSource(), rclFlag,
								craftSmp.getPhyCodeMin(), isMan, plineCode, ordLnPk });
						tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
								b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					}
				}else{

					if("0".equals(craftSmp.getLoopValue())){ //循环值为0 按合同
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetPhyMinByLotNo");
						b.Fill(new String[]{ "", "", processCode, craftSmp.getCraftSource(), rclFlag,
								craftSmp.getPhyCodeMin(), isMan, plineCode, ordLnPk });
						tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
								b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					}
					if(tmpConsignDetails == null || tmpConsignDetails.size() == 0) {
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetPhyMinByLotNo");
						b.Fill(new String[]{lotNo, lotNoGroup, processCode, craftSmp.getCraftSource(), rclFlag,
								craftSmp.getPhyCodeMin(), isMan, plineCode, ordLnPk});
						tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
								b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					}
					if(tmpConsignDetails == null || tmpConsignDetails.size() == 0){
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetPhyMinByLotNo");
						b.Fill(new String[]{ lotNo, lotNoGroup, processCode, craftSmp.getCraftSource(), rclFlag,
								craftSmp.getPhyCodeMin(), isMan, "", "" });
						tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
								b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					}

				}
			}else if(craftSmp.getRate().equals("408603")){ // 炉
				if(ordLnPk.startsWith("BL")){
					b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetBLPhyMinByJudgeStoveNo");
					b.Fill(new String[]{ judgeStoveNo, processCode, craftSmp.getCraftSource(), rclFlag,
							craftSmp.getPhyCodeMin(), isMan, plineCode, ordLnPk });
					tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
							b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					if(tmpConsignDetails.size() == 0){
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetBLPhyMinByJudgeStoveNo");
						b.Fill(new String[]{ judgeStoveNo, processCode, craftSmp.getCraftSource(), rclFlag,
								craftSmp.getPhyCodeMin(), isMan, "", "" });
						tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
								b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					}
				}else{
					b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetPhyMinByJudgeStoveNo");
					b.Fill(new String[]{ judgeStoveNo, processCode, craftSmp.getCraftSource(), rclFlag,
							craftSmp.getPhyCodeMin(), isMan , plineCode, ordLnPk });
					tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
							b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					if(tmpConsignDetails.size() == 0){
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetPhyMinByJudgeStoveNo");
						b.Fill(new String[]{ judgeStoveNo, processCode, craftSmp.getCraftSource(), rclFlag,
								craftSmp.getPhyCodeMin(), isMan , "", "" });
						tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
								b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					}
				}
			}else{
				if(ordLnPk.startsWith("BL")){
					b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetBLPhyMinByBatchNo");
					b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, craftSmp.getCraftSource(), rclFlag,
							craftSmp.getPhyCodeMin(), isMan, ordLnPk });
					tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
							b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					if(tmpConsignDetails.size() == 0){
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetBLPhyMinByBatchNo");
						b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, craftSmp.getCraftSource(), rclFlag,
								craftSmp.getPhyCodeMin(), isMan, "" });
						tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
								b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					}
				}else{
					b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetPhyMinByBatchNo");
					b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, craftSmp.getCraftSource(), rclFlag,
							craftSmp.getPhyCodeMin(), isMan, ordLnPk });
					tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
							b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					if(tmpConsignDetails.size() == 0){
						b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetPhyMinByBatchNo");
						b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, craftSmp.getCraftSource(), rclFlag,
								craftSmp.getPhyCodeMin(), isMan, "" });
						tmpConsignDetails = EntityTool.getEntitysBySqlNoClsCon(
								b.toString(), con, QcmZcCheckconsignDetailEntity.class);
					}
				}
			}

			String descCount = "";
			if(craftSmp.getRate().equals("408603") && !craftSmp.getAttachPercent().equals("")){
				descCount = craftSmp.getAttachCount();
			}else{
				if(!craftSmp.getDescCount().equals("") && !craftSmp.getSampleCount().equals(""))
				descCount = String.valueOf(Integer.parseInt(craftSmp.getDescCount())
						* Integer.parseInt(craftSmp.getSampleCount()));
			}
			//获取标准备注
			String chemMemo = "";
			String phyMemo = "";
			if(craftSmp.getPhyCodeMin().equals("HX")){
				b = new SqlBuilder("CraftOrdDesignStdCic.getCraftChemMemo");
				b.Fill(new String[]{ ordLnPk, craftSeq, mscPline, processCode, cic });
				CraftOrdDesignStdCicEntity chemMemoEntity = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, CraftOrdDesignStdCicEntity.class);
				chemMemo = chemMemoEntity == null ? "" : chemMemoEntity.getStdmemo();
			}else{
				b = new SqlBuilder("CraftOrdDesignStdPic.getCraftPhyMemo");
				b.Fill(new String[]{ ordLnPk, craftSeq, mscPline, processCode, pic, craftSmp.getPhyCodeMin() });
				CraftOrdDesignStdPicEntity phyMemoEntity = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, CraftOrdDesignStdPicEntity.class);
				phyMemo = phyMemoEntity == null ? "" : phyMemoEntity.getStdmemo();
			}
			if(tmpConsignDetails.size() == 0 && rclFlag.equals("0")){
				QcmZcCheckconsignDetailEntity tmpDetail = new QcmZcCheckconsignDetailEntity();
				tmpDetail.setRate(craftSmp.getRate());
				tmpDetail.setDescRate(craftSmp.getDescRate());
				tmpDetail.setChk("False");
				tmpDetail.setDescCount(descCount);
				tmpDetail.setPhyCodeMin(craftSmp.getPhyCodeMin());
				tmpDetail.setPhyCodeMax(craftSmp.getPhyCodeMin());
				tmpDetail.setPhyNameMin(craftSmp.getPhyNameMin());
				tmpDetail.setPhyNameMax(craftSmp.getPhyNameMin());
				tmpDetail.setPic(craftSmp.getPic());
				tmpDetail.setCraftSource(craftSmp.getCraftSource());
				if(craftSmp.getPhyCodeMin().equals("HX")){
					tmpDetail.setStdMemo(chemMemo);
				}else{
					tmpDetail.setStdMemo(phyMemo);
				}
				if("0".equals(craftSmp.getIsCheck()) && "0".equals(craftSmp.getIsJudge()) && "0".equals(craftSmp.getIsQuote())){
					tmpDetail.setIsQuote("0");
				}
				consignDetails.add(tmpDetail);
			}else{
				for(QcmZcCheckconsignDetailEntity tmpConsignDetail : tmpConsignDetails){
					tmpConsignDetail.setRate(craftSmp.getRate());
					tmpConsignDetail.setDescRate(craftSmp.getDescRate());
					tmpConsignDetail.setChk("False");
					tmpConsignDetail.setDescCount(descCount);
					tmpConsignDetail.setPic(craftSmp.getPic());
					tmpConsignDetail.setCraftSource(craftSmp.getCraftSource());
					if(craftSmp.getPhyCodeMin().equals("HX")){
						tmpConsignDetail.setStdMemo(chemMemo);
					}else{
						tmpConsignDetail.setStdMemo(phyMemo);
					}
					if("0".equals(craftSmp.getIsCheck()) && "0".equals(craftSmp.getIsJudge()) && "0".equals(craftSmp.getIsQuote())){
						tmpConsignDetail.setIsQuote("0");
					}
					consignDetails.add(tmpConsignDetail);
				}
			}
		}

		return consignDetails;
	}

	private static ArrayList<QcmZcCheckconsignDetailEntity> getPhyDetails(String checkNo, String ordLnPk,
			String processCode, String craftSeq, String mscPline, String cic, String pic,
			String craftProcess, ArrayList<String> phyCodeMins, SqlBuilder b, Connection con){
    	b = new SqlBuilder("JdgQcmZcCheckConsignDetail.GetPhyMinByCheckNo");
    	b.Fill(new String[]{ checkNo });
		ArrayList<QcmZcCheckconsignDetailEntity> details = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, QcmZcCheckconsignDetailEntity.class);
		HashMap<String, String> phyMemos = new HashMap<String, String>();
		for(int i = details.size() - 1; i >= 0; i--){
			QcmZcCheckconsignDetailEntity detail = details.get(i);
			if(phyCodeMins.size() != 0 && !phyCodeMins.contains(detail.getPhyCodeMin())){
				details.remove(i);
				continue;
			}
			//处理工艺备注
			if(phyMemos.containsKey(detail.getPhyCodeMin())){
				detail.setStdMemo(phyMemos.get(detail.getPhyCodeMin()));
			}else{
				if(detail.getPhyCodeMin().equals("HX")){
					b = new SqlBuilder("CraftOrdDesignStdCic.getCraftChemMemo");
					b.Fill(new String[]{ ordLnPk, craftSeq, mscPline, processCode, cic });
					CraftOrdDesignStdCicEntity chemMemoEntity = EntityTool.getEntityBySqlNoClsCon(
							b.toString(), con, CraftOrdDesignStdCicEntity.class);
					String chemMemo = chemMemoEntity == null ? "" : chemMemoEntity.getStdmemo();
					phyMemos.put(detail.getPhyCodeMin(), chemMemo);
					detail.setStdMemo(chemMemo);
				}else{
					b = new SqlBuilder("CraftOrdDesignStdPic.getCraftPhyMemo");
					b.Fill(new String[]{ ordLnPk, craftSeq, mscPline, processCode, pic, detail.getPhyCodeMin() });
					CraftOrdDesignStdPicEntity phyMemoEntity = EntityTool.getEntityBySqlNoClsCon(
							b.toString(), con, CraftOrdDesignStdPicEntity.class);
					String phyMemo = phyMemoEntity == null ? "" : phyMemoEntity.getStdmemo();
					phyMemos.put(detail.getPhyCodeMin(), phyMemo);
					detail.setStdMemo(phyMemo);
				}
			}
			detail.setChk("False");
			if(detail.getCraftSource().equals("1")){
				if(detail.getPhyCodeMin().equals("HX")){
					detail.setPic("CIC");
				}else {
					detail.setPic("PIC");
				}
			}
		}

		return details;
	}

	private static ArrayList<QcmZcCheckconsignDetailEntity> getLgDetails(String ordLnPk, String craftSeq,
			String stoveNo, String lgJudgeStoveNo, String cic, SqlBuilder b, Connection con){
		b = new SqlBuilder("QcmJhyElementsDAL.getLgPhyMinByStoveNo");
		b.Fill(new String[]{ ordLnPk, craftSeq, stoveNo, lgJudgeStoveNo, cic });
		ArrayList<QcmZcCheckconsignDetailEntity> details = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, QcmZcCheckconsignDetailEntity.class);
		b = new SqlBuilder("JdgCraftOrdDesignStd.getProductCnt");
		b.Fill(new String[]{ ordLnPk, craftSeq, "0" });
		CraftOrdDesignStdEntity craftStd = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignStdEntity.class);
		for(QcmZcCheckconsignDetailEntity detail : details){
			detail.setDescCount(craftStd.getProductCntN());
		}

		return details;
	}
	public static String setBcBatchResult(QcmZcCheckconsignEntity consign, String ordLnPk, String user,
										  Statement st,  Connection con) throws SQLException {
    	return setBcBatchResult(consign,ordLnPk,user,st,con,"");
	}
    public static String setBcBatchResult(QcmZcCheckconsignEntity consign, String ordLnPk, String user,
    		Statement st,  Connection con,String judgeFlag) throws SQLException{
    	SqlBuilder b = null;
    	ArrayList<QcmZcCheckconsignDetailEntity> splineResults = getAllCraftPhySplines(
    			consign, ordLnPk, ordLnPk, new ArrayList<String>(), con);
    	
    	b = new SqlBuilder("CraftOrdDesignStdPic.getPhyCnt");
    	b.Fill(new String[]{ ordLnPk, consign.getCraftSeq(),
    			consign.getProcessCode(), "0", consign.getIndexSeq() });
    	GenericEntity phyCount = EntityTool.getEntityBySqlNoClsCon(
    			b.toString(), con, GenericEntity.class);
    	
    	b = new SqlBuilder("CraftOrdDesignStdCic.getChemCnt");
    	b.Fill(new String[]{ ordLnPk, consign.getCraftSeq(),
    			"0", consign.getIndexSeq(), consign.getProcessCode() });
    	GenericEntity chemCount = EntityTool.getEntityBySqlNoClsCon(
    			b.toString(), con, GenericEntity.class);
    	
    	boolean noSsc = false;
    	boolean noHic = false;
        boolean noOther = false;
        ArrayList<String> phyResults = new ArrayList<String>();
        ArrayList<String> chemResults = new ArrayList<String>();
        for(QcmZcCheckconsignDetailEntity splineResult : splineResults){
        	String phyCodeMin = splineResult.getPhyCodeMin();
        	if(!splineResult.getSampleId().contains("F")){
        		String reSampleId = "F" + splineResult.getSampleId();
        		StringBuilder sb = new StringBuilder(splineResult.getSampleId());
        		/*if(!judgeFlag.equals("0") && sb.length() > 0){
					sb.insert(1,"F"); // 供样，复样
				}*/
        		boolean existReSample = false;
        		for(QcmZcCheckconsignDetailEntity splineResult2 : splineResults){
            		if(reSampleId.equals(splineResult2.getSampleId()) //|| sb.toString().equals(splineResult2.getSampleId())
            				&& splineResult.getJudgeStoveNo().equals(splineResult2.getJudgeStoveNo())
            				&& splineResult.getBatchNo().equals(splineResult2.getBatchNo())
            				&& splineResult.getPhyCodeMin().equals(splineResult2.getPhyCodeMin())){
            			existReSample = true;
            			break;
            		}
            	}
        		//System.out.println(splineResult.getPhyNameMax());
        		if("0".equals(splineResult.getIsQuote())){
					existReSample = true;
				}
        		if(existReSample){
        			continue;
        		}else{
        			if(splineResult.getPhyCodeMin().equals(splineResult.getPhyCodeMin())){
        				if(splineResult.getNkResult().equals("")){
        					if(phyCodeMin.equals("C0030") || phyCodeMin.equals("C0031")
        							|| phyCodeMin.equals("C0032") || phyCodeMin.equals("C0033")
        							|| phyCodeMin.equals("C0133") || phyCodeMin.equals("C0147")
        							|| phyCodeMin.equals("C0150")){
        						noSsc = true;
        					}else if(phyCodeMin.equals("C0007") || phyCodeMin.equals("C0146")
        							||phyCodeMin.equals("C0061") || phyCodeMin.equals("C0148")
        							|| phyCodeMin.equals("C0065")){
        						noHic = true;
        					}else {
        						noOther = true;
        					}
        					if(splineResult.getPhyCodeMin().equals("HX")){
        						chemResults.add("");
        					}else{
        						if(consign.getProduccode().equals("S000046") && consign.getSteelcode().equals("C209")
        								&& splineResult.getPhyNameMin().contains("洛氏硬度")){
        							boolean existsYb = false;//是否有预备硬度
    								for(QcmZcCheckconsignDetailEntity splineResult2 : splineResults){
    				            		if(splineResult2.getPhyNameMin().contains("预备硬度")
    				            				&& !splineResult2.getNkResult().equals("")){
    				            			existsYb = true;
    				            			break;
    				            		}
    				            	}
    								if(existsYb){
    									continue;
    								}else{
    									phyResults.add("");
    								}
        						}else{
        							phyResults.add("");
        						}
        					}
        				}else if(splineResult.getNkResult().equals("0")){
        					if(splineResult.getPhyCodeMin().equals("HX")){
        						chemResults.add("40740102");
        					}else{
        						phyResults.add("40740202");
        					}
                    	}else if(splineResult.getNkResult().equals("1")){
                    		if(splineResult.getPhyCodeMin().equals("HX")){
        						chemResults.add("40740101");
        					}else{
        						phyResults.add("40740201");
        					}
                    	}
        			}
        		}
        	}else{
        		if(splineResult.getPhyCodeMin().equals(splineResult.getPhyCodeMin())){
    				if(splineResult.getNkResult().equals("")){
    					if(phyCodeMin.equals("C0030") || phyCodeMin.equals("C0031")
    							|| phyCodeMin.equals("C0032") || phyCodeMin.equals("C0033")
    							|| phyCodeMin.equals("C0133") || phyCodeMin.equals("C0147")
    							|| phyCodeMin.equals("C0150")){
    						noSsc = true;
    					}else if(phyCodeMin.equals("C0007") || phyCodeMin.equals("C0146")
    							||phyCodeMin.equals("C0061") || phyCodeMin.equals("C0148")
    							|| phyCodeMin.equals("C0065")){
    						noHic = true;
    					}else{
    						noOther = true;
    					}
    					if(splineResult.getPhyCodeMin().equals("HX")){
    						chemResults.add("");
    					}else{
    						if(consign.getProduccode().equals("S000046") && consign.getSteelcode().equals("C209")
    								&& splineResult.getPhyNameMin().contains("洛氏硬度")){
    							boolean existsYb = false;//是否有预备硬度
								for(QcmZcCheckconsignDetailEntity splineResult2 : splineResults){
				            		if(splineResult2.getPhyNameMin().contains("预备硬度")
				            				&& !splineResult2.getNkResult().equals("")){
				            			existsYb = true;
				            			break;
				            		}
				            	}
								if(existsYb){
									continue;
								}else{
									phyResults.add("");
								}
    						}else{
    							phyResults.add("");
    						}
    					}
    				}else if(splineResult.getNkResult().equals("0")){
    					if(splineResult.getPhyCodeMin().equals("HX")){
    						chemResults.add("40740102");
    					}else{
    						phyResults.add("40740202");
    					}
                	}else if(splineResult.getNkResult().equals("1")){
                		if(splineResult.getPhyCodeMin().equals("HX")){
    						chemResults.add("40740101");
    					}else{
    						phyResults.add("40740201");
    					}
                	}
    			}
        	}
        }
        String phyResult = "";
        if(phyResults.contains("")&&!phyResults.contains("40740202")){
        	phyResult = "";
        }else if(phyResults.contains("40740202")){
        	phyResult = "40740202";
        }else if(phyResults.contains("40740201")){
        	phyResult = "40740201";
        }
        String chemResult = "";
        if(chemResults.contains("")){
        	chemResult = "";
        }else if(chemResults.contains("40740102")){
        	chemResult = "40740102";
        }else if(chemResults.contains("40740101")){
        	chemResult = "40740101";
        }
        String isNoSsc = "0";
    	if(noSsc && !noOther){
    		isNoSsc = "1";
    	}
    	String isNoHic = "0";
    	if(noHic && !noOther){
    		isNoHic = "1";
    	}

    	String judgeResult = "";
        ArrayList<String> allResults = new ArrayList<String>();
        b = new SqlBuilder("CraftOrdDesignStdPic.getPhyCnt");
        b.Fill(new String[]{ ordLnPk, consign.getCraftSeq(), consign.getProcessCode(),
                "1", consign.getIndexSeq() });
        GenericEntity phyCountFd = EntityTool.getEntityBySqlNoClsCon(
                b.toString(), con, GenericEntity.class);
        if(!phyCount.getCount().equals("0") || !phyCountFd.getCount().equals("0")){
            allResults.add(phyResult);
        }
        b = new SqlBuilder("CraftOrdDesignStdCic.getChemCnt");
        b.Fill(new String[]{ ordLnPk, consign.getCraftSeq(), "1", consign.getIndexSeq(), consign.getProcessCode() });
        GenericEntity chemCountFd = EntityTool.getEntityBySqlNoClsCon(
                b.toString(), con, GenericEntity.class);
        if(!chemCount.getCount().equals("0") || !chemCountFd.getCount().equals("0")) {
            allResults.add(chemResult);
        }

        
        if(allResults.contains("")){
        	judgeResult = "";
        }else if(allResults.contains("40740104") || allResults.contains("40740204")){
        	judgeResult = "40740708";
        }else if(allResults.contains("40740103") || allResults.contains("40740203")){
        	judgeResult = "40740707";
        }else if(allResults.contains("40740102") || allResults.contains("40740202")){
        	judgeResult = "40740704";
        }else{
        	judgeResult = "40740701";
        }
        
        b = new SqlBuilder("JdgQcmBcBatchResult.getByBatchNo");
        b.Fill(new String[]{ consign.getJudgeStoveNo(), consign.getBatchNo(),
        		consign.getProcessCode(), "0", consign.getOrdLnDlyPk() });
        QcmBcBatchResultEntity batchResult = EntityTool.getEntityBySqlNoClsCon(
        		b.toString(), con, QcmBcBatchResultEntity.class);
        //验证CIC、PIC是否正常
        
        if(batchResult == null){
        	 batchResult = new QcmBcBatchResultEntity();
        	 batchResult.setJudgeStoveNo(consign.getJudgeStoveNo());
        	 batchResult.setBatchNo(consign.getBatchNo());
        	 batchResult.setProcessCode(consign.getProcessCode());
        	 batchResult.setCraftSource("0");
        	 batchResult.setPhyResultCode(phyResult);
        	 batchResult.setChemResultCode(chemResult);
        	 batchResult.setJudgeResultCode(judgeResult);
             batchResult.setIsNoSsc(isNoSsc);
             batchResult.setIsNoHic(isNoHic);
             batchResult.setCheckNoS(consign.getCheckNo());
             batchResult.setJudgeMaker(user);
             batchResult.setOrdLnDlyPk(consign.getOrdLnDlyPk());
             String sql = CoreXmlSqlParsersFactory.getSql("JdgQcmBcBatchResult.insert");
             sql = EntityTool.fillSqlByEntity(sql, batchResult);
             st.executeUpdate(sql);
        }else{
	       	 batchResult.setPhyResultCode(phyResult);
	       	 batchResult.setChemResultCode(chemResult);
	       	 batchResult.setJudgeResultCode(judgeResult);
	         batchResult.setIsNoSsc(isNoSsc);
	         batchResult.setIsNoHic(isNoHic);
	         batchResult.setJudgeMaker(user);
	         if(!batchResult.getCheckNoS().contains(consign.getCheckNo())){
	        	 batchResult.setCheckNoS(batchResult.getCheckNoS() + "," + consign.getCheckNo());
	         }
	         String sql = CoreXmlSqlParsersFactory.getSql("JdgQcmBcBatchResult.update");
             sql = EntityTool.fillSqlByEntity(sql, batchResult);
             st.executeUpdate(sql);
        }
        
        return judgeResult;
    }
    
    private String judge(ArrayList<QcmZcCheckconsignDetailEntity> groupDetails,
    		QcmZcCheckconsignEntity consign, String ordLnPk, String user, Statement st, Connection con)
    				throws SQLException{
		int i = 0;
		SqlBuilder b = new SqlBuilder("JdgQcmBcPhyjudgeDAL.getMaxPhyJudgeId");
    	GenericEntity maxPk = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, GenericEntity.class);
        String phyJudgeId = maxPk.getMaxValue();
        String phyResult = "";
    	for(QcmZcCheckconsignDetailEntity groupDetail : groupDetails){
        	i++;
        	b = new SqlBuilder("QcmJhyPhyresultDAL.QueryByBatchNoSampleNo");
        	b.Fill(new Object[]{ consign.getProcessCode(), consign.getCheckNo(), consign.getJudgeStoveNo(),
        			consign.getBatchNo(), groupDetail.getSampleNo() });
        	ArrayList<QcmJhyPhyresultEntity> jhyPhyResults = EntityTool.getEntitysBySqlNoClsCon(
        			b.toString(), con, QcmJhyPhyresultEntity.class);
        	String[] judgeResults = judge(consign, ordLnPk, phyJudgeId, String.valueOf(i),
        			user, jhyPhyResults, con, st);
        	//写入理化判断记录表
        	QcmBcPhyjudgeEntity phyJudge = new QcmBcPhyjudgeEntity();
        	phyJudge.setBatchNo(consign.getBatchNo());
        	phyJudge.setCreateName(user);
        	phyJudge.setHeatPlanNo("");
        	phyJudge.setJfPhyResult(judgeResults[1]);
        	phyJudge.setJudgegradecode(consign.getGradecode());
        	phyJudge.setJudgeresultPhy(judgeResults[0]);
        	phyJudge.setJudgeSeq(String.valueOf(i));
        	phyJudge.setJudgesteelcode(consign.getSteelcode());
        	phyJudge.setStoveNo(consign.getStoveNo());
        	phyJudge.setJudgeStoveNo(consign.getJudgeStoveNo());
        	phyJudge.setMemo(judgeResults[2]);
        	phyJudge.setMscPline(consign.getIndexSeq());
        	phyJudge.setObjectno("");
        	phyJudge.setPhyJudgeId(phyJudgeId);
        	phyJudge.setPhyResultId(phyJudgeId);
        	phyJudge.setOrdLnDlyPk(consign.getOrdLnDlyPk());
        	phyJudge.setCraftSeq(consign.getCraftSeq());
        	phyJudge.setPic(consign.getPic());
        	phyJudge.setPlineCode(consign.getPlineCode());
        	phyJudge.setProcessCdoe(consign.getProcessCode());
        	phyJudge.setProPlanId(consign.getProOrderId() + consign.getGxPlanNo());
        	phyJudge.setSampleNo(groupDetail.getSampleNo());
        	phyJudge.setSampleId(consign.getCheckNo());
        	phyJudge.setLotNo(consign.getLotNo());
        	phyJudge.setCraftSource(consign.getCraftSource());
        	b = new SqlBuilder("JdgQcmBcPhyjudgeDAL.updatePhyJudgeValid");
        	b.Fill(new String[]{ phyJudge.getJudgeStoveNo(), phyJudge.getBatchNo(),
        			phyJudge.getSampleNo(), phyJudge.getSampleId(), phyJudge.getProcessCdoe(), "0" });
        	st.executeUpdate(b.toString());
    		String sqlInsert = CoreXmlSqlParsersFactory.getSql("JdgQcmBcPhyjudgeDAL.Insert");
            sqlInsert = EntityTool.fillSqlByEntity(sqlInsert, phyJudge);
            st.executeUpdate(sqlInsert);
            
            if(phyResult.equals("")){
            	phyResult = judgeResults[0];
            }else if(phyResult.equals("40740201")){
            	phyResult = judgeResults[0];
            }
        }
    	
    	//修改理化检验表的判定状态
        b = new SqlBuilder("QcmJhyPhyresultDAL.updateJudgeFlagByBatchNo");
        b.Fill(new String[]{ consign.getCheckNo(), consign.getJudgeStoveNo(), consign.getBatchNo(),
        		consign.getProcessCode(), "20" });
        st.executeUpdate(b.toString());
        
        //修改理化判定结果中的汇总字段
        b = new SqlBuilder("JdgQcmBcPhyjudgeDAL.setSampleType");
        b.Fill(new String[]{ phyJudgeId, phyResult });
        st.executeUpdate(b.toString());
    	
    	return phyJudgeId;
    }
    
    @SuppressWarnings("unchecked")
	private String[] judge(QcmZcCheckconsignEntity consign, String ordLnPk, String phyJudgeId, String judgeSeq,
			String user, ArrayList<QcmJhyPhyresultEntity> jhyPhyResults, Connection con, Statement st)
					throws SQLException {
    	String nkResult = "";
    	String jfResult = "";
    	String memo = "";
    	HashMap<String, QcmBcPhyresultEntity> allResultMap = new HashMap<String, QcmBcPhyresultEntity>();
    	//判定内控
    	String craftProcess = consign.getLikuProcessCode().equals("") ? consign.getProcessCode() : consign.getLikuProcessCode();
		SqlBuilder b = new SqlBuilder("CraftOrdDesignStdPic.queryCraftPhyByOrdLnPk");
		b.Fill(new Object[]{ ordLnPk, consign.getCraftSeq(), consign.getIndexSeq(),
				craftProcess, consign.getPic(), "", consign.getCraftSource() });
		ArrayList<CraftOrdDesignStdPicEntity> craftPics = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignStdPicEntity.class);
		 
		Object[] results = PhyJudgeHelper.judge(jhyPhyResults, craftPics, consign.getOrdLnDlyPk(),
				 consign.getCheckNo(), consign.getStoveNo(), "2", con);
		 if(results[0].toString().equals("")){
			 nkResult = "40740201";
		 }else{
			 nkResult = "40740202";
			 memo = consign.getPic() + "：" + results[0].toString();
		 }
		 HashMap<String, QcmBcPhyresultEntity> nkPhyResultMap = new HashMap<String, QcmBcPhyresultEntity>();
		 if(results[1] != null){
			 nkPhyResultMap = (HashMap<String, QcmBcPhyresultEntity>)results[1];
		 }
		 FillPhyResults(allResultMap, nkPhyResultMap, true);
		 
		 //判定交付
		 b = new SqlBuilder("CraftOrdDesignStdPic.getCraftJfPhyByOrdLnPk");
		 b.Fill(new String[]{ ordLnPk, consign.getCraftSeq(), "" });
		 ArrayList<CraftOrdDesignStdPicEntity> craftJfPics = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con, CraftOrdDesignStdPicEntity.class);
		 if(craftJfPics.size() == 0){
			 jfResult = "";
		 }else{
			 Object[] jfResults = PhyJudgeHelper.judge(jhyPhyResults, craftJfPics, consign.getOrdLnDlyPk(),
					 consign.getCheckNo(), consign.getStoveNo(), "1", con);
			 if(jfResults[0].toString().equals("")){
				 jfResult = "40740203";
			 }else{
				 jfResult = "40740204";
				 memo = getJfPics(craftJfPics) + "：" + jfResults[0].toString();
			 }
			 HashMap<String, QcmBcPhyresultEntity> jfPhyResultMap = new HashMap<String, QcmBcPhyresultEntity>();
			 if(jfResults[1] != null){
				 jfPhyResultMap = (HashMap<String, QcmBcPhyresultEntity>)jfResults[1];
			 }
			 FillPhyResults(allResultMap, jfPhyResultMap, false);
		 }

         //写入理化判定结果集表
         int i = 0;
         for(String key : allResultMap.keySet()){
        	//QcmJhyPhyresultEntity jhyPhyResult
         	i++;
         	if(key.contains("P0003")){
         		String s="";
         		s="1";
         	}
         	String resultInsert = CoreXmlSqlParsersFactory.getSql("QcmBcPhyresultDAL.Insert");
         	resultInsert = StringTool.ReplaceAll(resultInsert, "#PHY_RESULT_ID#", phyJudgeId);
         	resultInsert = StringTool.ReplaceAll(resultInsert, "#PHY_RESULT_SEQ#", judgeSeq);
         	resultInsert = StringTool.ReplaceAll(resultInsert, "#XH#", String.valueOf(i));
         	resultInsert = StringTool.ReplaceAll(resultInsert, "#ALLRESULT#", "");
         	resultInsert = StringTool.ReplaceAll(resultInsert, "#CREATE_NAME#", user);
         	QcmBcPhyresultEntity bcPhyResult = allResultMap.get(key);
         	for(QcmJhyPhyresultEntity jhyPhyResult : jhyPhyResults){
         		String tmpStr = jhyPhyResult.getPhyCode() + jhyPhyResult.getItemCodeF()
         				+ jhyPhyResult.getItemCodeW() + jhyPhyResult.getItemCodeS();
         		if(tmpStr.equals(key)){
         			bcPhyResult.setValue1(jhyPhyResult.getValue1());
         			bcPhyResult.setValue2(jhyPhyResult.getValue2());
         			bcPhyResult.setValue3(jhyPhyResult.getValue3());
         			bcPhyResult.setValue4(jhyPhyResult.getValue4());
         			bcPhyResult.setValue5(jhyPhyResult.getValue5());
         			bcPhyResult.setValue6(jhyPhyResult.getValue6());
         			bcPhyResult.setValue7(jhyPhyResult.getValue7());
         			bcPhyResult.setValue8(jhyPhyResult.getValue8());
         			bcPhyResult.setValue9(jhyPhyResult.getValue9());
         			bcPhyResult.setValue10(jhyPhyResult.getValue10());
         			bcPhyResult.setValue11(jhyPhyResult.getValue11());
         			bcPhyResult.setValue12(jhyPhyResult.getValue12());
         			bcPhyResult.setValue13(jhyPhyResult.getValue13());
         			bcPhyResult.setValue14(jhyPhyResult.getValue14());
         			bcPhyResult.setValue15(jhyPhyResult.getValue15());
         			bcPhyResult.setAverage(jhyPhyResult.getAverage());
         			bcPhyResult.setIsGood(jhyPhyResult.getIsGood());
         			bcPhyResult.setIsDefect(jhyPhyResult.getIsDefect());
         			bcPhyResult.setCheckTemp(jhyPhyResult.getCheckTemp());
         			bcPhyResult.setHardnessType(jhyPhyResult.getHardnessType());
         			bcPhyResult.setPhyCodeDir(jhyPhyResult.getPhyCodeDir());
         			bcPhyResult.setPhyNameDir(jhyPhyResult.getPhyNameDir());
         			bcPhyResult.setSampleStyle(jhyPhyResult.getSampleStyle());
         			bcPhyResult.setSampleSize(jhyPhyResult.getSampleSize());
         			break;
         		}
         	}
         	resultInsert = EntityTool.fillSqlByEntity(resultInsert, bcPhyResult);
         	st.executeUpdate(resultInsert);
         }
    	
         return new String[]{ nkResult, jfResult, memo };
    }
    
    /**
     * 填充内控结果和交付结果
     * @param allResults
     * @param phyResults
     * @param isNk
     */
    private void FillPhyResults(HashMap<String, QcmBcPhyresultEntity> allResults,
    		HashMap<String, QcmBcPhyresultEntity> phyResults, boolean isNk){
    	if(phyResults.size() == 0) return;
    	for(String key : phyResults.keySet()){
			QcmBcPhyresultEntity phyResult = phyResults.get(key);
    		if(isNk){
    			allResults.put(key, phyResults.get(key));
    		}else{
    			for(QcmBcPhyresultEntity bcPhyResult : allResults.values()){
    				if(bcPhyResult.getPhyCode().equals(phyResult.getPhyCode())
					&& (phyResult.getPhyCodeMax().equals("R0002") || phyResult.getItemCodeF().equals("") || phyResult.getItemCodeF().equals(bcPhyResult.getItemCodeF()))
					&& (phyResult.getPhyCodeMax().equals("R0002") || phyResult.getItemCodeS().equals("") || phyResult.getItemCodeS().equals(bcPhyResult.getItemCodeS()))
					&& (phyResult.getPhyCodeMax().equals("R0002") || phyResult.getItemCodeW().equals("") || phyResult.getItemCodeW().equals(bcPhyResult.getItemCodeW()))){
						bcPhyResult.setJfAddCondition(phyResults.get(key).getNkAddCondition());
						bcPhyResult.setJfAddJudgeBasis(phyResults.get(key).getNkAddJudgeBasis());
						bcPhyResult.setJfAddMax(phyResults.get(key).getNkAddMax());
						bcPhyResult.setJfAddMin(phyResults.get(key).getNkAddMin());
						bcPhyResult.setJfAddQualified(phyResults.get(key).getNkAddQualified());
						bcPhyResult.setJfJudgeBasis(phyResults.get(key).getNkJudgeBasis());
						bcPhyResult.setJfMax(phyResults.get(key).getNkMax());
						bcPhyResult.setJfMin(phyResults.get(key).getNkMin());
						bcPhyResult.setJfQualified(phyResults.get(key).getNkQualified());
						bcPhyResult.setJfTolQualified(phyResults.get(key).getNkTolQualified());
					}
				}
    		}
    	}
    }
    
    /**
     * 获取交付理化索引集合
     * @param craftJfPics
     * @return
     */
    private String getJfPics(ArrayList<CraftOrdDesignStdPicEntity> craftJfPics){
    	String pics = "";
    	for(CraftOrdDesignStdPicEntity craftJfPic : craftJfPics){
    		if(pics.indexOf(craftJfPic.getPic()) == -1){
    			if(pics.equals("")){
    				pics = craftJfPic.getPic();
    			}else{
    				pics += "," + craftJfPic.getPic();
    			}
    		}
    	}
    	
    	return pics;
    }
    
//    private void FillQcmBcPhyResult(QcmJhyPhyresultEntity jhyPhyResult, QcmBcPhyresultEntity bcPhyResult){
//    	bcPhyResult.setAverage(jhyPhyResult.getAverage());
//    	bcPhyResult.setBatchNo(jhyPhyResult.getBatchNo());
//    	bcPhyResult.setFilePath(jhyPhyResult.getFilePath());
//    	bcPhyResult
//    }
    
    /**
	 * 获取工艺信息(轧管只能获取到个PIC)
	 * @param con
	 * @return
	 */
	public CraftOrdDesignMscPlPrcEntity getCraftInfo(String[] proPlanIds, String judgeStoveNo,
			Connection con){
		SqlBuilder b;
		if(proPlanIds[0].startsWith("ZG")){
			b = new SqlBuilder("JdgPlnOrderZgS.queryZgCraftPicByZgProPlanId");
		}else if(proPlanIds[0].startsWith("DBK")){
			b = new SqlBuilder("JdgPlnOrderDbkS.queryCraftPicByProPlanId");
		}else if(proPlanIds[0].startsWith("RCL")){
			b = new SqlBuilder("JdgPlnOrderRclS.queryCraftPicByProPlanId");
		}else{
			b = new SqlBuilder("JdgPlnOrderJgxS.queryCraftPicByProPlanId");
		}
		b.Fill(new Object[]{ proPlanIds[0], judgeStoveNo });
		CraftOrdDesignMscPlPrcEntity craftPrc = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, CraftOrdDesignMscPlPrcEntity.class);
		
		return craftPrc;
	}
    
    /**
	 * 删除检化验成分实绩
	 * @return
	 */
	public CoreReturnObject deleteJhyPhyResult(String checkNo, ArrayList<String> backJsons,String isFlag){
		Connection jhyCon = null;
		Connection qcmCon = null;
		Statement jhySt = null;
		Statement qcmSt = null;
		CoreReturnObject cro = new CoreReturnObject();
		try{
			jhyCon = this.getDao("JhyDao").getConnection();
			qcmCon = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			jhySt = jhyCon.createStatement();
			qcmSt = qcmCon.createStatement();
			jhyCon.setAutoCommit(false);
			qcmCon.setAutoCommit(false);
			SqlBuilder b;
			boolean isChem = false;
			boolean isPhy = false;
			for(String backJson : backJsons){
				QcmZcCheckconsignDetailEntity consignDetail = EntityTool.getEntityByGson(
						backJson, QcmZcCheckconsignDetailEntity.class);
				String judgeStoveNo = consignDetail.getJudgeStoveNo();
				String batchNo = consignDetail.getBatchNo();
				String phyCodeMin = consignDetail.getPhyCodeMin();
				//获取检验委托表
	            b = new SqlBuilder("JdgQcmZcCheckconsign.queryByBatchNo");
	            b.Fill(new String[]{ checkNo, judgeStoveNo, batchNo });
	            QcmZcCheckconsignEntity consign = EntityTool.getEntityBySqlNoClsCon(
	            		b.toString(), qcmCon, QcmZcCheckconsignEntity.class);
	            String processCode = consign.getProcessCode();
	            if(consign.getApplyResample().equals("1")){
            		cro.setV_errMsg("已申请复取样，不能退回！");
            		jhyCon.rollback();
            		qcmCon.rollback();
                	return cro;
            	}
            	if(consign.getCyclesFlag().equals("1")){
            		cro.setV_errMsg("已申请重新热处理，不能退回！");
            		jhyCon.rollback();
            		qcmCon.rollback();
                	return cro;
            	}
	            
				//综合判定已判定不能退回
    			b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo2");
                b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "" });
                QcmZgJugdeApplyEntity zgApply = EntityTool.getEntityBySql(
                		b.toString(), this.getDao(CoreConstantData.sysbeanstr).getConnection(),
                		QcmZgJugdeApplyEntity.class);
                if(zgApply != null && !zgApply.getJudgeResultCode().equals("") && "1".equals(isFlag)){
                	cro.setV_errMsg("已进行综合判定，不能退回！（如需回退，请撤销综合判定）");
                	jhyCon.rollback();
            		qcmCon.rollback();
                	return cro;
                }
                
                if(phyCodeMin.equals("HX") || phyCodeMin.equals("ONH")){
    				isChem = true;
    			}
    			
    			if(!phyCodeMin.equals("HX") && !phyCodeMin.equals("ONH")){
    				isPhy = true;
    			}
                
                //修改检化验状态
    			b = new SqlBuilder("JdgPipeCheckConsignDetail.setFlag");
    			b.Fill(new String[]{ checkNo, judgeStoveNo, batchNo, phyCodeMin,
    					consignDetail.getSampleNo(), "3"});
    			jhySt.executeUpdate(b.toString());
    			//修改其他试样组状态
    			if(!phyCodeMin.equals("HX") && !phyCodeMin.equals("ONH") && !phyCodeMin.equals("C0030")
    					&& !phyCodeMin.equals("C0031") && !phyCodeMin.equals("C0032")
    					&& !phyCodeMin.equals("C0033") && !phyCodeMin.equals("C0133")
                        && !phyCodeMin.equals("C0147") && !phyCodeMin.equals("C0007")
                        && !phyCodeMin.equals("C0146") && !phyCodeMin.equals("C0150")
                        && !phyCodeMin.equals("C0061") && !phyCodeMin.equals("C0148")
                        && !phyCodeMin.equals("C0065")){
    				b = new SqlBuilder("JdgPipeCheckConsignDetail.setPhyFlag");
    				b.Fill(new String[]{ checkNo, "4" });
    				jhySt.executeUpdate(b.toString());
    				
    				//清空委托二层表
    				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.setPhyJudgeResultByCheckNo");
    				b.Fill(new Object[]{ checkNo, batchNo, "", "", "" });
    				qcmSt.executeUpdate(b.toString());
    				
    				//删除QCM检化验理化实绩表
        			b = new SqlBuilder("QcmJhyPhyresultDAL.deleteJhyPhyByCheckNo");
        			b.Fill(new String[]{ checkNo, judgeStoveNo, batchNo });
        			qcmSt.executeUpdate(b.toString());
    			}else if(phyCodeMin.equals("C0030") || phyCodeMin.equals("C0031") || phyCodeMin.equals("C0032")
						|| phyCodeMin.equals("C0033") || phyCodeMin.equals("C0133") || phyCodeMin.equals("C0147")
						|| phyCodeMin.equals("C0150")){
    				b = new SqlBuilder("JdgPipeCheckConsignDetail.setPhySscFlag");
    				b.Fill(new String[]{ checkNo, "4" });
    				jhySt.executeUpdate(b.toString());
    				
    				//清空委托二层表
    				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.setPhySscJudgeResultByCheckNo");
    				b.Fill(new Object[]{ checkNo, batchNo, "", "", "" });
    				qcmSt.executeUpdate(b.toString());
    				
    				//删除QCM检化验理化实绩表
        			b = new SqlBuilder("QcmJhyPhyresultDAL.deleteJhyPhySscByCheckNo");
        			b.Fill(new String[]{ checkNo, judgeStoveNo, batchNo });
        			qcmSt.executeUpdate(b.toString());
    			}else if(phyCodeMin.equals("C0007") || phyCodeMin.equals("C0146")
    					||phyCodeMin.equals("C0061") || phyCodeMin.equals("C0148")
    					||phyCodeMin.equals("C0065")){
    				//清空委托二层表
    				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.setPhyHicJudgeResultByCheckNo");
    				b.Fill(new Object[]{ checkNo, batchNo, "", "", "" });
    				qcmSt.executeUpdate(b.toString());
    				
    				//删除QCM检化验理化实绩表
        			b = new SqlBuilder("QcmJhyPhyresultDAL.deleteJhyPhyHicByCheckNo");
        			b.Fill(new String[]{ checkNo, judgeStoveNo, batchNo });
        			qcmSt.executeUpdate(b.toString());
    			}
    			
    			//修改检化验退回说明
    			b = new SqlBuilder("JdgPipeCheckConsignDetail.setBackMemo");
    			b.Fill(new String[]{ checkNo, judgeStoveNo, batchNo, consignDetail.getPhyCodeMin(),
    					consignDetail.getSampleNo(), consignDetail.getBackMemo()});
    			jhySt.executeUpdate(b.toString());
    			if(consignDetail.getBackRcl().equals("True")){
    				b = new SqlBuilder("JdgPipeCheckConsignDetail.setRclFlag");
        			b.Fill(new String[]{ checkNo, judgeStoveNo, batchNo, consignDetail.getPhyCodeMin(),
        					consignDetail.getSampleNo(), "2"});
        			jhySt.executeUpdate(b.toString());
    			}
    			
    			//更新检验委托表
    			b = new SqlBuilder("JdgQcmZcCheckconsign.updateResult");
    			b.Fill(new String[]{ checkNo, judgeStoveNo, batchNo, processCode, "",
    					"", "", "", "", "", "", "00", "", "", "" });
    			qcmSt.executeUpdate(b.toString());
    			
    			//修改炉批结果表
    			b = new SqlBuilder("JdgQcmBcBatchResult.Clear");
    			b.Fill(new String[]{ consign.getJudgeStoveNo(), consign.getBatchNo(),
    					consign.getProcessCode(), consign.getCraftSource(), consign.getOrdLnDlyPk() });
    			qcmSt.executeUpdate(b.toString());
			}
			//修改126委托主表
			b = new SqlBuilder("JdgPipeCheckConsignBaseInfo.setFlag");
			b.Fill(new String[]{ checkNo, "2" });
			jhySt.executeUpdate(b.toString());
			//修改126委托表状态
			if(isChem){
				b = new SqlBuilder("JdgPipeCheckConsignDetail.setChemFlag");
				b.Fill(new String[]{ checkNo, "4" });
				jhySt.executeUpdate(b.toString());
			}
			
			//删除QCM检化验成分实绩表
			if(isChem){
				b = new SqlBuilder("QcmJhyElementsDAL.deleteJhyElementsByCheckNo");
    			b.Fill(new String[]{ checkNo });
    			qcmSt.executeUpdate(b.toString());
    			//作废成分判定记录
    			b = new SqlBuilder("JdgQcmBcChemJudgeDAL.setValidflagByCheckNo");
    			b.Fill(new String[]{ checkNo, "0" });
    			qcmSt.executeUpdate(b.toString());
			}
			
			if(isPhy){
				
    			//作废判定记录
    			b = new SqlBuilder("JdgQcmBcPhyjudgeDAL.updatePhyJudgeValidByCheckNo");
    			b.Fill(new String[]{ checkNo, "0" });
    			qcmSt.executeUpdate(b.toString());
    			b = new SqlBuilder("JdgQcmBcPhyjudgeDAL.updatePhyResultValidByCheckNo");
    			b.Fill(new String[]{ checkNo, "0" });
    			qcmSt.executeUpdate(b.toString());
			}
			
			//修改报齐状态
			b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getPhyMinQuote");
			b.Fill(new String[]{ checkNo });
			String quoteState = "";
			ArrayList<QcmZcCheckconsignDetailEntity> consignDetais = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), qcmCon, QcmZcCheckconsignDetailEntity.class);
			int noPhyMinCnt = 0;
			for(QcmZcCheckconsignDetailEntity consignDetai : consignDetais){
				if(consignDetai.getCnt().equals("0")){
					noPhyMinCnt++;
				}
			}
			if(noPhyMinCnt == 0){
				quoteState = "2";
			}else{
				if(noPhyMinCnt < consignDetais.size()){
					quoteState = "1";
				}else{
					quoteState = "0";
				}
			}
			b = new SqlBuilder("JdgQcmZcCheckconsign.updateQuoteState");
			b.Fill(new String[]{ checkNo, quoteState});
			qcmSt.executeUpdate(b.toString());
			
			//处理委托二层表
			//修改委托二层表的判定状态
			if(isChem){
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.setChemJudgeResultByCheckNo");
				b.Fill(new String[]{ checkNo, "", "", "" });
				qcmSt.executeUpdate(b.toString());
			}
//			if(isPhy){
//				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.setPhyJudgeResultByCheckNo");
//				b.Fill(new String[]{ checkNo, "", "", "" });
//				qcmSt.executeUpdate(b.toString());
//			}
			
			
			jhyCon.commit();
			qcmCon.commit();
			return cro;
		}catch(Exception ex){
			try {
				jhyCon.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			try {
				qcmCon.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			cro.setV_errMsg(ex.getMessage());
			return cro;
		}
		finally{
			try {
				jhySt.close();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {
				jhyCon.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			try {
				qcmSt.close();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {
				qcmCon.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 更新备注
	 * @param memo
	 * @return
	 */
	public CoreReturnObject updateMemo(String checkNo, String processCode, String memo){
		SqlBuilder b = new SqlBuilder("JdgQcmZcCheckconsign.updateMemo");
		b.Fill(new String[]{ checkNo, processCode, memo });
		return this.setData(b.toString());
	}
	
	/**
	 * 更新是否重新热处理
	 * @param checkNo
	 * @param judgeStoveNo
	 * @return
	 */
	public CoreReturnObject applyCyClesFlag(String checkNo, String judgeStoveNo,
			ArrayList<String> batchNos){
		CoreReturnObject cro = new CoreReturnObject();
		SqlBuilder b = null;
		
		ArrayList<String> sqlList = new ArrayList<String>();
		for(String batchNo : batchNos){
			b = new SqlBuilder("JdgQcmZcCheckconsign.queryByBatchNo");
			b.Fill(new String[]{ checkNo, judgeStoveNo, batchNo });
			QcmZcCheckconsignEntity consign = EntityTool.getEntityBySql(
					b.toString(), this.getDao(CoreConstantData.sysbeanstr).getConnection(),
					QcmZcCheckconsignEntity.class);
			
			//综合判定已判定不能再判
			b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo2");
            b.Fill(new String[]{ consign.getJudgeStoveNo(), consign.getBatchNo(), consign.getProcessCode(), "" });
            QcmZgJugdeApplyEntity zgApply = EntityTool.getEntityBySql(
            		b.toString(), this.getDao(CoreConstantData.sysbeanstr).getConnection(),
            		QcmZgJugdeApplyEntity.class);
            if(zgApply != null && (zgApply.getJudgeResult().equals("40740701") || zgApply.getJudgeResult().equals("40740709"))){
            	cro.setV_errMsg("性能批号"+ batchNo +"已申请判定，请先撤销申请判定！");
    			return cro;
            }
            
            b = new SqlBuilder("JdgQcmZcCheckconsign.updateCyClesFlag");
			b.Fill(new String[]{ consign.getJudgeStoveNo(), consign.getBatchNo(),
					consign.getProcessCode(), "1" });
			sqlList.add(b.toString());
		}
		
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqlList);
	}
	
	/**
	 * 删除是否重新热处理
	 * @param checkNo
	 * @return
	 */
	public CoreReturnObject deleteCyClesFlag(String checkNo){
		SqlBuilder b = new SqlBuilder("JdgQcmZcCheckconsign.queryAllByCheckNo");
		b.Fill(new String[]{ checkNo });
		Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		ArrayList<QcmZcCheckconsignEntity> checkConsigns = EntityTool.getEntitysBySql(
				b.toString(), con, QcmZcCheckconsignEntity.class);
		ArrayList<String> sqlList = new ArrayList<String>();
		for(QcmZcCheckconsignEntity checkConsign : checkConsigns){
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			b = new SqlBuilder("JdgPortHitBatchSampleResult.queryCyCles");
			b.Fill(new String[]{ checkConsign.getJudgeStoveNo(), checkConsign.getBatchNo() });
			GenericEntity cnt = EntityTool.getEntityBySql(b.toString(), con, GenericEntity.class);
			if(!cnt.getCount().equals("0")){
				b = new SqlBuilder("JdgQcmZcCheckconsign.updateCyClesFlag");
				b.Fill(new String[]{ checkConsign.getJudgeStoveNo(), checkConsign.getBatchNo(),
						checkConsign.getProcessCode(), "0" });
				sqlList.add(b.toString());
			}
		}
		
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqlList);
	}
	
	/**
     * 申请复取样
     * @return
     */
    public CoreReturnObject applyResample(String checkNo, String user, ArrayList<String> jsons){
    	Connection qcmCon = null;
    	Connection jhyCon = null;
    	Statement qcmSt = null;
    	Statement jhySt = null;
    	CoreReturnObject cro = new CoreReturnObject();
    	try{
    		qcmCon = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    		qcmCon.setAutoCommit(false);
    		qcmSt = qcmCon.createStatement();
    		jhyCon = this.getDao("JhyDao").getConnection();
    		jhyCon.setAutoCommit(false);
    		jhySt = jhyCon.createStatement();
    		
    		SqlBuilder b = new SqlBuilder("JdgQcmZcCheckconsign.queryAllByCheckNo");
            b.Fill(new String[]{ checkNo });
            ArrayList<QcmZcCheckconsignEntity> zcChecks = EntityTool.getEntitysBySqlNoClsCon(
            		b.toString(), qcmCon, QcmZcCheckconsignEntity.class);
            int insertCount = 0;
            for(QcmZcCheckconsignEntity zcCheck : zcChecks){
                boolean containBatchNo = false;
        		HashMap<String, PipeCheckconsignNoqualifiedEntity> applyMaps = new HashMap<String, PipeCheckconsignNoqualifiedEntity>();
        		for(String json : jsons){
        			PipeCheckconsignNoqualifiedEntity check = EntityTool.getEntityByGson(json, PipeCheckconsignNoqualifiedEntity.class);
        			if(check.getJudgeStoveNo().equals(zcCheck.getJudgeStoveNo()) 
        					&& check.getBatchNo().equals(zcCheck.getBatchNo())){
        				check.setIsOriginal(check.getIsOriginal().equals("True") ? "1" : "0");
            			applyMaps.put(check.getPhyCodeMin(), check);
            			containBatchNo = true;
        			}
        		}
        		if(!containBatchNo){
        			continue;
        		}
        		
        		//综合判定已判定不能再判
    			b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo2");
                b.Fill(new String[]{ zcCheck.getJudgeStoveNo(), zcCheck.getBatchNo(),
                		zcCheck.getProcessCode(), "" });
                QcmZgJugdeApplyEntity zgApply = EntityTool.getEntityBySqlNoClsCon(
                		b.toString(), qcmCon, QcmZgJugdeApplyEntity.class);
                if(zgApply != null && (zgApply.getJudgeResultCode().equals("40740701") || zgApply.getJudgeResultCode().equals("40740709"))){
                	cro.setV_errMsg("已进行综合判定，不能申请复取样！（如需申请复取样，请撤销综合判定）");
                	return cro;
                }
                
                b = new SqlBuilder("JdgCheckConsignNoQualified.getCount");
                b.Fill(new Object[]{ checkNo, zcCheck.getJudgeStoveNo(),
                		new String[]{"1", "2", "3"} });
                GenericEntity checkCount = EntityTool.getEntityBySqlNoClsCon(
                		b.toString(), jhyCon, GenericEntity.class);
                if(!checkCount.getCount().equals("0")){
                	cro.setV_errMsg("该检验编号的申请复取样已被确认，不能重新申请！");
                	return cro;
                }
                b = new SqlBuilder("JdgCheckConsignNoQualified.deleteCheckNoQualified");
                b.Fill(new String[]{ checkNo, zcCheck.getJudgeStoveNo(), zcCheck.getBatchNo() });
                jhySt.executeUpdate(b.toString());
                
                //获取成分判定结果
                b = new SqlBuilder("JdgQcmBcChemResult.getJudgeFail");
                b.Fill(new String[]{ zcCheck.getCheckNo(), zcCheck.getJudgeStoveNo(),
                		zcCheck.getBatchNo(), zcCheck.getProcessCode() });
                ArrayList<QcmBcChemResultEntity> chemResults = EntityTool.getEntitysBySqlNoClsCon(
                		b.toString(), qcmCon, QcmBcChemResultEntity.class);
                b = new SqlBuilder("JdgComBaseChem.queryBaseChemOrderByLength");
                ArrayList<ComBaseChemEntity> baseChems = EntityTool.getEntitysBySqlNoClsCon(
                		b.toString(), qcmCon, ComBaseChemEntity.class);
                for(QcmBcChemResultEntity chemResult : chemResults){
                	if(!applyMaps.containsKey(chemResult.getChemName())) continue;
                	if(chemResult.getChemType().equals("A")){
                		b = new SqlBuilder("JdgCheckConsignNoQualified.insert");
                		String isRepeat = "0";
                		if(chemResult.getSampleId().contains("F") || chemResult.getSampleId().contains("Z")){
                			isRepeat = "1";
                		}
                		String phyCodeMax = "";
                		String phyNameMax = "";
                		if(chemResult.getChemName().equals("O") || chemResult.getChemName().equals("N")
                				|| chemResult.getChemName().equals("H")){
                			phyCodeMax = "ONH";
                			phyNameMax = "ONH";
                		}else{
                			phyCodeMax = "HX";
                			phyNameMax = "化学";
                		}
                		PipeCheckconsignNoqualifiedEntity check = applyMaps.get(chemResult.getChemName());
                    	b.Fill(new String[]{ chemResult.getSampleId(), chemResult.getSampleNo(),
                    			phyCodeMax, phyNameMax, phyCodeMax, phyNameMax, chemResult.getChemCode(), chemResult.getChemName(),
                    			chemResult.getJfQualified(), chemResult.getNkQualified(), chemResult.getLotNo(),
                    			chemResult.getJudgeStoveNo(), chemResult.getBatchNo(), "0", chemResult.getPlineCode(),
                    			user, isRepeat, check.getIsOriginal(), check.getSampleCount(), "", "", "", "", "", "" });
                    	jhySt.executeUpdate(b.toString());
                    	insertCount++;
                	}else{//复合元素
                		HashMap<String, String> chems = new HashMap<String, String>();
                		String chemFormula = chemResult.getChemFormula();
                		for(ComBaseChemEntity baseChem : baseChems){
                			if(chemFormula.contains(baseChem.getChemName())){
                				chemFormula = chemFormula.replaceAll(baseChem.getChemName(), "");
                				chems.put(baseChem.getChemCode(), baseChem.getChemName());
                			}
                		}
                		
                		for(String chemCode : chems.keySet()){
                			String chemName = chems.get(chemCode);
                			b = new SqlBuilder("JdgQcmBcChemResult.getJudgeFailByChem");
                            b.Fill(new String[]{ checkNo, zcCheck.getJudgeStoveNo(),
                            		zcCheck.getBatchNo(), zcCheck.getProcessCode(), chemName });
                            ArrayList<QcmBcChemResultEntity> chemResults2 = EntityTool.getEntitysBySqlNoClsCon(
                            		b.toString(), qcmCon, QcmBcChemResultEntity.class);
                            for(QcmBcChemResultEntity chemResult2 : chemResults2){
                        		b = new SqlBuilder("JdgCheckConsignNoQualified.insert");
                        		String isRepeat = "0";
                        		if(chemResult.getSampleId().contains("F") || chemResult.getSampleId().contains("Z")){
                        			isRepeat = "1";
                        		}
                        		PipeCheckconsignNoqualifiedEntity check = applyMaps.get(chemResult.getChemName());
                            	b.Fill(new String[]{ chemResult2.getSampleId(), chemResult2.getSampleNo(),
                            			"HX", "化学", "HX", "化学", chemCode, chemName,
                            			chemResult2.getJfQualified(), chemResult2.getNkQualified(), chemResult2.getLotNo(),
                            			chemResult2.getJudgeStoveNo(), chemResult2.getBatchNo(), "0", chemResult2.getPlineCode(),
                            			user, isRepeat, check.getIsOriginal(), check.getSampleCount(), "", "", "", "", "", "" });
                            	jhySt.executeUpdate(b.toString());
                            	insertCount++;
                            }
                        }
                	}
                }
                
                //获取理化判定结果
                b = new SqlBuilder("QcmBcPhyresultDAL.getJudgeInfo");
                b.Fill(new String[]{ checkNo, zcCheck.getJudgeStoveNo(), zcCheck.getBatchNo(), zcCheck.getProcessCode() });
                ArrayList<QcmBcPhyresultEntity> phyResults = EntityTool.getEntitysBySqlNoClsCon(
                		b.toString(), qcmCon, QcmBcPhyresultEntity.class);
                // SSC HIC试验取126
                b = new SqlBuilder("JdgPipeCheckConsignPhyDetail.getResampleData");
                b.Fill(new String[]{ checkNo, zcCheck.getJudgeStoveNo(), zcCheck.getBatchNo(), zcCheck.getProcessCode() });
                ArrayList<QcmBcPhyresultEntity> tmpPhyResults = EntityTool.getEntitysBySqlNoClsCon(
                		b.toString(), jhyCon, QcmBcPhyresultEntity.class);
                for(QcmBcPhyresultEntity tmpPhyResult : tmpPhyResults){
                	phyResults.add(tmpPhyResult);
                }
                for(QcmBcPhyresultEntity phyResult : phyResults){
                	if(!applyMaps.containsKey(phyResult.getPhyCodeMin())) continue;
                	b = new SqlBuilder("JdgCheckConsignNoQualified.insert");
                	String isRepeat = "0";
            		if(phyResult.getSampleId().contains("F") || phyResult.getSampleId().contains("Z")){
            			isRepeat = "1";
            		}
            		PipeCheckconsignNoqualifiedEntity check = applyMaps.get(phyResult.getPhyCodeMin());
                	b.Fill(new String[]{ phyResult.getSampleId(), phyResult.getSampleNo(),
                			phyResult.getPhyCodeMin(), phyResult.getPhyNameMin(), phyResult.getPhyCodeMax(),
                			phyResult.getPhyNameMax(), phyResult.getPhyCode(), phyResult.getPhyName(),
                			phyResult.getJfTolQualified(), phyResult.getNkTolQualified(), phyResult.getLotNo(),
                			phyResult.getJudgeStoveNo(), phyResult.getBatchNo(), "0", phyResult.getPlineCode(),
                			user, isRepeat, check.getIsOriginal(), check.getSampleCount(),
                			phyResult.getItemCodeF(), phyResult.getItemNameF(), phyResult.getItemCodeW(),
                			phyResult.getItemNameW(), phyResult.getItemCodeS(), phyResult.getItemNameS() });
                	jhySt.executeUpdate(b.toString());
                	insertCount++;
                }
                
                //修改委托表的复取样数据
                b = new SqlBuilder("JdgQcmZcCheckconsign.updateResampleData");
                b.Fill(new String[]{ checkNo, zcCheck.getJudgeStoveNo(), zcCheck.getBatchNo(),
                		zcCheck.getProcessCode(), "1" });
                qcmSt.executeUpdate(b.toString());
                
                //把炉批结果表的综合结果置空
                b = new SqlBuilder("JdgQcmBcBatchResult.clearJudgeResult");
                b.Fill(new String[]{ zcCheck.getJudgeStoveNo(), zcCheck.getBatchNo(),
                		zcCheck.getProcessCode(), zcCheck.getCraftSource(), zcCheck.getOrdLnDlyPk() });
                qcmSt.executeUpdate(b.toString());
            }
            
            if(insertCount == 0){
            	qcmCon.rollback();
            	jhyCon.rollback();
            	cro.setV_errMsg("该检验编号下找不到不合格的内控结果，不能申请复取样！");
            	return cro;
            }
            
            qcmCon.commit();
            jhyCon.commit();
            return cro;
    	}catch(Exception ex){
    		try {
    			qcmCon.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
    		
    		try {
    			jhyCon.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
    		
    		cro.setV_errMsg(ex.getMessage());
    		return cro;
    	}finally{
    		if(qcmSt != null){
    			try {
					qcmSt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    		if(qcmCon != null)
    		{
    			try {
    				qcmCon.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    		
    		if(jhySt != null){
    			try {
					jhySt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    		if(jhyCon != null){
    			try {
					jhyCon.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    	}
    }
    
    /**
     * 撤销复取样
     * @param user
     * @return
     */
    public CoreReturnObject deleteResample(String checkNo, String user){
    	Connection qcmCon = null;
    	Connection jhyCon = null;
    	Statement qcmSt = null;
    	Statement jhySt = null;
    	CoreReturnObject cro = new CoreReturnObject();
    	try{
    		qcmCon = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    		qcmCon.setAutoCommit(false);
    		qcmSt = qcmCon.createStatement();
    		jhyCon = this.getDao("JhyDao").getConnection();
    		jhyCon.setAutoCommit(false);
    		jhySt = jhyCon.createStatement();
    		
    		SqlBuilder b = new SqlBuilder("JdgQcmZcCheckconsign.queryAllByCheckNo");
            b.Fill(new String[]{ checkNo });
            ArrayList<QcmZcCheckconsignEntity> zcChecks = EntityTool.getEntitysBySqlNoClsCon(
            		b.toString(), qcmCon, QcmZcCheckconsignEntity.class);
            
            for(QcmZcCheckconsignEntity zcCheck : zcChecks){
            	//综合判定已判定不能再判
    			b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo2");
                b.Fill(new String[]{ checkNo, zcCheck.getJudgeStoveNo(), zcCheck.getBatchNo(),
                		zcCheck.getProcessCode(), "" });
                QcmZgJugdeApplyEntity zgApply = EntityTool.getEntityBySqlNoClsCon(
                		b.toString(), qcmCon,
                		QcmZgJugdeApplyEntity.class);
                if(zgApply != null && (zgApply.getJudgeResultCode().equals("40740701") || zgApply.getJudgeResultCode().equals("40740709"))){
                	cro.setV_errMsg("已进行综合判定，不能撤销复取样！（如需撤销复取样，请撤销综合判定）");
                	return cro;
                }
                
                //删除复取样数据
                b = new SqlBuilder("JdgQcmZcCheckconsign.updateResampleData");
                b.Fill(new String[]{ checkNo, zcCheck.getJudgeStoveNo(), zcCheck.getBatchNo(),
                		zcCheck.getProcessCode(),
                		"0" });
                qcmSt.executeUpdate(b.toString());
        		
        		b = new SqlBuilder("JdgCheckConsignNoQualified.deleteCheckNoQualified");
        		b.Fill(new String[]{ checkNo, zcCheck.getJudgeStoveNo(), zcCheck.getBatchNo() });
        		jhySt.executeUpdate(b.toString());
        		
        		if(zcCheck.getApplyResample().equals("1")){
        			//修改炉批结果表
        			b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
            		b.Fill(new String[]{ zcCheck.getOrdLnDlyPk() });
            		PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), qcmCon, PlnSaleordEntity.class);
        			BllRolledTubePhyJudge.setBcBatchResult(zcCheck, plnSaleord.getOrdLnPk(), user, qcmSt, qcmCon);
        		}
            }
    		
            jhyCon.commit();
            qcmCon.commit();
            return cro;
    	}catch(Exception ex){
    		try {
    			jhyCon.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
    		
    		cro.setV_errMsg(ex.getMessage());
    		return cro;
    	}finally{
    		if(qcmSt != null){
    			try {
					qcmSt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    		if(qcmCon != null)
    		{
    			try {
    				qcmCon.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    		
    		if(jhySt != null){
    			try {
					jhySt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    		if(jhyCon != null){
    			try {
					jhyCon.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    	}
    }
    
    /**
     * 获取复取样数
     * @param judgeStoveNo
     * @param isSamples
     * @return
     */
    public CoreReturnObject getCheckNoQualifiedCnt(String checkNo, String judgeStoveNo,
    		String[] isSamples){
    	SqlBuilder b = new SqlBuilder("JdgCheckConsignNoQualified.getCount");
    	b.Fill(new Object[]{ checkNo, judgeStoveNo, isSamples });
    	
    	return this.getDao("JhyDao").ExcuteSortResultByQuery(b.toString());
    }
    
    /**
     * 获取复取样数据
     * @return
     */
    public CoreReturnObject getCheckNoQualifiedData(String checkNo){
    	SqlBuilder b = new SqlBuilder("JdgCheckConsignNoQualified.getResampleData");
    	b.Fill(new Object[]{ checkNo });
    	
    	return this.getDao("JhyDao").ExcuteSortResultByQuery(b.toString());
    }
    
    /**
     * 获取退回备注
     * @param checkNo
     */
    public CoreReturnObject getBackMemo(String checkNo){
    	SqlBuilder b = new SqlBuilder("JdgPipeCheckConsignDetail.getBackMemo");
    	b.Fill(new Object[]{ checkNo });
    	
    	return this.getDao("JhyDao").ExcuteSortResultByQuery(b.toString());
    }
    
    /**
     * 刷新轧管工序-外购管工艺数据
     * @return
     */
    public CoreReturnObject refreshCraft(String ordLnPk, String ordLnDlyPk, String cic){
    	Connection con = null;
    	Statement st = null;
    	CoreReturnObject cro = new CoreReturnObject();
    	try{
    		String process = "D";
    		con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    		con.setAutoCommit(false);
    		st = con.createStatement();
    		SqlBuilder b = new SqlBuilder("JdgCraftOrdDesign.getNewByOrdLnPk");
        	b.Fill(new String[]{ ordLnPk });
        	CraftOrdDesignEntity design = EntityTool.getEntityBySqlNoClsCon(
        			b.toString(), con, CraftOrdDesignEntity.class);
        	b = new SqlBuilder("JdgMatBcM.getWgByOrdLnDlyPk");
        	b.Fill(new String[]{ ordLnDlyPk, process });
        	ArrayList<MatBcMEntity> mats = EntityTool.getEntitysBySqlNoClsCon(
        			b.toString(), con, MatBcMEntity.class);
        	for(MatBcMEntity mat : mats){
        		//获取轧管订单信息
        		b = new SqlBuilder("JdgPlnOrderZgS.queryByPk");
        		b.Fill(new String[]{ mat.getProOrderId(), mat.getGxPlanNo() });
        		PlnOrderZgSEntity plan = EntityTool.getEntityBySqlNoClsCon(
        				b.toString(), con, PlnOrderZgSEntity.class);
        		String pic = plan.getPic().split(",")[0];
        		String dic = plan.getDic().split(",")[0];
        		String sic = plan.getSic().split(",")[0];
        		String wic = plan.getWic().split(",")[0];
        		String gic = plan.getGic().split(",")[0];
        		b = new SqlBuilder("CraftOrdDesignMscPlSti.getChemStation");
        		b.Fill(new String[]{ design.getDesginKey(), plan.getIndexSeq(), process });
        		CraftOrdDesignMscPlStiEntity sti = EntityTool.getEntityBySqlNoClsCon(
        				b.toString(), con, CraftOrdDesignMscPlStiEntity.class);
        		String steelstandard = "";
        		if(sti != null){
        			steelstandard = cic;
        		}
        		steelstandard += "+" + pic + "+" + dic + "+" + sic + "+" + wic + "+" + gic;
        		
        		
        		//更新委托表
        		b = new SqlBuilder("JdgQcmZcCheckconsign.setCraftSeq");
        		b.Fill(new String[]{ mat.getJudgeStoveNo(), mat.getBatchNo(), process,
        				mat.getOrdLnDlyPk(), design.getCraftNo(), design.getCraftSeq(), cic, pic,
        				steelstandard });
        		st.executeUpdate(b.toString());
        		//更新送判表
        		b = new SqlBuilder("QcmZgJugdeApplyDAL.setCraftSeq");
        		b.Fill(new String[]{ mat.getJudgeStoveNo(), mat.getBatchNo(), process,
        				mat.getOrdLnDlyPk(), design.getCraftNo(), design.getCraftSeq(), cic, pic,
        				sic, dic, wic, gic, steelstandard });
        		st.executeUpdate(b.toString());
        		//更新材料表
        		b = new SqlBuilder("JdgMatBcM.setCraftSeq");
        		b.Fill(new String[]{ mat.getJudgeStoveNo(), mat.getBatchNo(), process,
        				mat.getOrdLnDlyPk(), design.getCraftNo(), design.getCraftSeq(), cic });
        		st.executeUpdate(b.toString());
        		b = new SqlBuilder("JdgMatBcBackup.setCraftSeq");
        		b.Fill(new String[]{ mat.getJudgeStoveNo(), mat.getBatchNo(), process,
        				mat.getOrdLnDlyPk(), design.getCraftNo(), design.getCraftSeq(), cic });
        		st.executeUpdate(b.toString());
        	}
        	
        	con.commit();
        	return cro;
    	}catch(Exception ex){
    		try {
				con.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    		cro.setV_errMsg(ex.getMessage());
    		return cro;
    	}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();
			}
    	}
    }

	/**
	 * 删除检验委托
	 * @param checkNo
	 * @return
	 */
	public CoreReturnObject DeleteCheckConsign(String checkNo){
		CoreReturnObject cro = new CoreReturnObject();
		if(!checkNo.contains("P") && !checkNo.contains("L") && !checkNo.contains("D")
				&& !checkNo.contains("G")){
			cro.setV_errMsg("只能删除组炉、利库、共样、复制的检验单！");
			return cro;
		}
		SqlBuilder b = new SqlBuilder("JdgQcmZcCheckconsign.setIsFlag", checkNo);

		return this.setData(b.toString());
	}
}
