package com.steering.pss.judge.Bll;

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

import com.steering.comm.data.ComBaseInfo;
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.model.*;
import com.steering.pss.plnsaleord.planStove.entity.YdmBcInlistEntity;
import com.steering.pss.plnsaleord.stove.PlanFurnProduction;
import com.steering.pss.qcm.model.GenericEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignStdPicSmpEntity;
import com.steering.pss.sale.order.orderchange.CrmOrderProduceService;
import com.steering.pss.ydm.pipemanage.FrmBcIqInList;

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


public class BllRolledTubeColligateJudge extends DBCommon{
	
	/**
	 * 轧管成分判定
	 * judgeFlag 1正常判定  0缺项判定
	 * @return
	 */
    public CoreReturnObject judge(String judgeApplyCode, String judgeStoveNo,
    		String batchNo, String processCode, String user, String order,
    		String group, String judgeFileMemo, String judgeMemo, String judgeFlag,
    		ArrayList<String> checkDetailJsons){
		Connection con = null;
		Statement st = null;
		CoreReturnObject cro = new CoreReturnObject();
		SqlBuilder b;
		String step = "";
		Date now = new Date();
		try{
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			st = con.createStatement();
			
			b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
            QcmZgJugdeApplyEntity zgJudgeApply = EntityTool.getEntityBySqlNoClsCon(
            		b.toString(), con, QcmZgJugdeApplyEntity.class);
            
            String sql = CoreXmlSqlParsersFactory
                    .getSql("QcmZgJugdeApplyDAL.QueryByBatchNoAddResult");
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1, judgeApplyCode);
            ps.setString(2, judgeStoveNo);
            ps.setString(3, batchNo);
            ResultSet rs = ps.executeQuery();
            Boolean Isjinji = false;
            Boolean Iszhiliang = false;
            if (rs.next()) {
                if(rs.getString("PASS_APPLY_NO")!=null&&rs.getString("AUDIT_RESULT")!=null&&rs.getString("PASS_APPLY_NO").length()>0&&rs.getString("AUDIT_RESULT").length()>0){
                	Iszhiliang = true;
                }
                if(rs.getString("URGENT_PASS_NO")!=null&&rs.getString("URGENT_AUDIT_RESULT")!=null&&rs.getString("URGENT_PASS_NO").length()>0&&rs.getString("URGENT_AUDIT_RESULT").equals("审核通过")){
                	Isjinji = true;
                }
            }
            rs.close();
            ps.close();
            
            zgJudgeApply.setJudgeMaker(user);
            String oldJudgeResult = zgJudgeApply.getJudgeResultCode();
			if(zgJudgeApply.getXsFlag().equals("0") && zgJudgeApply.getInMold().equals("801701")
					&& !"120504".equals(zgJudgeApply.getSupplyUnit()) && zgJudgeApply.getTarget().equals("A")){
				cro.setV_errMsg("该记录为非计划记录，销售未确认，不能判定！");
				return cro;
			}
            if(oldJudgeResult.equals("40740709") && judgeFlag.equals("0")){
            	cro.setV_errMsg("该记录已判定为缺项合格，不能再次判定！");
            	return cro;
            }
            if(judgeFlag.equals("0") && oldJudgeResult.equals("40740701")){
            	cro.setV_errMsg("该记录已判定为合格，不能缺项判定！");
            	return cro;
            }
            if(!Isjinji&&!Iszhiliang&&judgeFlag.equals("0") && oldJudgeResult.equals("40740704")){
            	cro.setV_errMsg("该记录已判定为不合格，不能缺项判定！");
            	return cro;
            }
            if(judgeFlag.equals("1") && oldJudgeResult.equals("40740701")){
            	cro.setV_errMsg("该记录已判定为合格，不能判定！");
            	return cro;
            }
            if(//zgJudgeApply.getInstancyFlag().equals("0")
            		!Isjinji	&& judgeFlag.equals("0") && processCode.equals("F")){
            	cro.setV_errMsg("该记录还未紧急放行，不能缺项判定！");
            	return cro;
            }
//            if(!"120504".equals(zgJudgeApply.getSupplyUnit()) && processCode.equals("D") && judgeFlag.equals("0")){
//            	cro.setV_errMsg("非天淮数据，不能轧管缺项判定！");
//            	return cro;
//            }
            if("120504".equals(zgJudgeApply.getSupplyUnit()) && !zgJudgeApply.getTarget().equals("A") && judgeFlag.equals("0") && processCode.equals("D")){
            	cro.setV_errMsg("该记录非A字头，不能缺项判定！");
            	return cro;
            }
            if(zgJudgeApply.getInstancyFlag().equals("1") && judgeFlag.equals("0") && processCode.equals("D") && "120504".equals(zgJudgeApply.getSupplyUnit())){
            	cro.setV_errMsg("该记录已紧急放行，不能缺项判定！");
            	return cro;
            }
            
            //放行验证
            b = new SqlBuilder("JdgQcmBcPassApplyDAL.queryByBatchNo", zgJudgeApply.getJugdeApplyCode(),
                    zgJudgeApply.getJudgeStoveNo(), zgJudgeApply.getBatchNo(), zgJudgeApply.getProcessCode(), "0" );
            QcmBcPassApplyEntity quality = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, QcmBcPassApplyEntity.class);
            if(quality != null){
                if(quality.getAuditResult().equals("")){
                    cro.setV_errMsg("该炉号处于放行审核状态，不允许判定！");
                    return cro;
                }else if(quality.getAuditResult().equals("407504")){
                    cro.setV_errMsg("该炉号放行处置结果为降级/改判，请操作撤销判定！");
                    return cro;
                }else if(quality.getAuditResult().equals("407505")){
                    cro.setV_errMsg("该炉号放行处置结果为报废，请操作撤销判定！");
                    return cro;
                }else if(quality.getAuditResult().equals("407506")){
                    cro.setV_errMsg("该炉号放行处置结果为返工，请操作撤销判定！");
                    return cro;
                }
            }
            b = new SqlBuilder("JdgQcmBcPassApplyDAL.queryByBatchNo", zgJudgeApply.getJugdeApplyCode(),
                    zgJudgeApply.getJudgeStoveNo(), zgJudgeApply.getBatchNo(), zgJudgeApply.getProcessCode(), "1" );
            QcmBcPassApplyEntity urgent = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, QcmBcPassApplyEntity.class);
            if(urgent != null){
                if(urgent.getAuditResult().equals("0")){
                    cro.setV_errMsg("该炉号处于放行审核状态，不允许判定！");
                    return cro;
                }else if(urgent.getAuditResult().equals("")){
                    cro.setV_errMsg("放行处置结果为不通过，如需判定，请联系放行申请人删除放行单！");
                    return cro;
                }
            }
            if(zgJudgeApply.getProcessCode().equals("G")){
                if(!zgJudgeApply.getOrdLnDlyPk().startsWith("ZZB")){
                    b = new SqlBuilder("JdgMchFinalChekResult.getNoCheckCount",
                            zgJudgeApply.getJugdeApplyCode(), zgJudgeApply.getJudgeStoveNo(),
							zgJudgeApply.getBatchNo());
                    GenericEntity checkCount = EntityTool.getEntityBySqlNoClsCon(
                            b.toString(), con, GenericEntity.class);
                    if(!checkCount.getCount().equals("0")){
                        cro.setV_errMsg("该记录存在未抽检管号，不能判定！");
                        return cro;
                    }
                    b = new SqlBuilder("JdgMchFinalChekResult.getNoCheckTreatmentCount",
                            zgJudgeApply.getJugdeApplyCode(), zgJudgeApply.getJudgeStoveNo(),
							zgJudgeApply.getBatchNo());
                    GenericEntity checkTreatmentCount = EntityTool.getEntityBySqlNoClsCon(
                            b.toString(), con, GenericEntity.class);
                    if(!checkTreatmentCount.getCount().equals("0")){
                        cro.setV_errMsg("该记录存在未验证的入库检验处置单，不能判定！");
                        return cro;
                    }
                }
				//if(!zgJudgeApply.getPlineCode().equals("C034")&&!zgJudgeApply.getPlineCode().equals("C092") && zgJudgeApply.getTarget().equals("A")){
				if(!zgJudgeApply.getPlineCode().equals("C092")&&!zgJudgeApply.getPlineCode().equals("C102") &&!zgJudgeApply.getPlineCode().equals("C104") &&!zgJudgeApply.getPlineCode().equals("C107") &&!zgJudgeApply.getPlineCode().equals("C108") &&!zgJudgeApply.getPlineCode().equals("C109")  && zgJudgeApply.getTarget().equals("A")){
                    ArrayList<QcmZcJgxResultEntity> jgxResults = BllZcColligateJudge.getJgxResultInfo(
                            zgJudgeApply.getJugdeApplyCode(), zgJudgeApply.getJudgeStoveNo(),
                            zgJudgeApply.getBatchNo(), con);
                    for(QcmZcJgxResultEntity jgxResult : jgxResults){
                        if(jgxResult.getResult().equals("")){
                            cro.setV_errMsg("该记录的加工实绩项目不齐，不能判定！");
                            return cro;
                        }
                        if(jgxResult.getResult().equals("不合格")){
                            cro.setV_errMsg("该记录的加工实绩不合格，不能判定！");
                            return cro;
                        }
                    }
                }
			}
            
            //--------------------------验证是否被锁定。
            checkJudgeLock(b, zgJudgeApply, con);
            
            //无合同判定
            if(zgJudgeApply.getOrdLnDlyPk()==null || "".equals(zgJudgeApply.getOrdLnDlyPk())){

            	QcmBcJudgeEntity bcJudge = new QcmBcJudgeEntity();
            	bcJudge.setFaceResult("40740601");
            	bcJudge.setDetectResult("40740401");
            	bcJudge.setDetectResult2("40740401");
            	bcJudge.setSpecResult("40740301");
            	bcJudge.setWaterResult("40740501");
            	bcJudge.setProcessResult("40740801");
            	zgJudgeApply.setJudgeResultCode("40740701");
        		zgJudgeApply.setJudgeResult(getComBaseName("40740701", con));
        		bcJudge.setJudgeResult("40740701");
            	//写入半成品综合判定表
            	bcJudge.setMemo(judgeMemo);
            	bcJudge.setCreateName(user);
            	bcJudge.setJudgeStoveNo(judgeStoveNo);
            	bcJudge.setBatchNo(batchNo);
            	bcJudge.setProcessCdoe(processCode);
            	bcJudge.setPlineCode(zgJudgeApply.getPlineCode());
            	bcJudge.setDeliveryStateCode(zgJudgeApply.getDeliveryStateCode());
            	bcJudge.setDeliveryStateName(zgJudgeApply.getDeliveryStateName());
            	bcJudge.setJugdeApplyCode(judgeApplyCode);
            	bcJudge.setActCount(zgJudgeApply.getActCount());
            	bcJudge.setActWeight(zgJudgeApply.getActWeight());
            	bcJudge.setActTheoryWeight(zgJudgeApply.getActTheoryWeight());
            	//新增前作废有效的综合判定记录
            	b = new SqlBuilder("JdgQcmBcJudge.updateValid");
            	b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, judgeApplyCode, "0" });
            	st.executeUpdate(b.toString());
            	//新增判定记录
            	String sqlMaxPk = CoreXmlSqlParsersFactory.getSql("JdgQcmBcJudge.GetMaxPk");
            	GenericEntity maxPk = null;
                maxPk = EntityTool.getEntityBySqlNoClsCon(sqlMaxPk, con, GenericEntity.class);
                bcJudge.setJudgeId(maxPk.getMaxValue());
                String sqlInsert = CoreXmlSqlParsersFactory.getSql("JdgQcmBcJudge.Insert");
                sqlInsert = EntityTool.fillSqlByEntity(sqlInsert, bcJudge);
                st.executeUpdate(sqlInsert);
            	//回写申请判定表
                b = new SqlBuilder("QcmZgJugdeApplyDAL.setJudgeResult");
                b.Fill(new String[]{ zgJudgeApply.getJugdeApplyCode(), judgeStoveNo, batchNo, processCode,
                		"40740701", user, order, group, zgJudgeApply.getFaceResultCode(),
                		zgJudgeApply.getDetectResultCode(), zgJudgeApply.getSpecResultCode(),
                		zgJudgeApply.getWpressureResultCode(), zgJudgeApply.getProcessResultCode(),
                		"20", judgeMemo, bcJudge.getJudgeId(), zgJudgeApply.getChemResultCode(), 
                		zgJudgeApply.getPhyResultCode(), judgeFileMemo });
                st.executeUpdate(b.toString());
                if(!oldJudgeResult.equals("40740709")){
            		b = new SqlBuilder("QcmZgJugdeApplyDAL.setJudgeTime");
                	b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, processCode, "1" });
                	st.executeUpdate(b.toString());
            	}
                //修改申请判定表的结转年月
            	boolean instancy = false;
            	//对于A字头结转年月在成品判定写 紧急放行时写了结转年月，再次判定就不需要写了。
            	if(!zgJudgeApply.getTarget().equals("A")){
            		if(!instancy && !oldJudgeResult.equals("40740709")){
        	            b = new SqlBuilder("QcmZgJugdeApplyDAL.setBalYearMonth");
        	            b.Fill(new String[]{ zgJudgeApply.getJugdeApplyCode(), judgeStoveNo, batchNo,processCode,
								"120504".equals(zgJudgeApply.getSupplyUnit())?ComBaseInfo.GetBalYear_2416(now):ComBaseInfo.GetBalYear(now)  });
        	            st.executeUpdate(b.toString());
                    }
            	}

                
                
                b = new SqlBuilder("JdgMatBcQcmTrack.setJudgeResult");
                b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, zgJudgeApply.getJugdeApplyCode(),
                		bcJudge.getJudgeId(),
                		zgJudgeApply.getSteelStandrad(), bcJudge.getJudgeResult(),  user, judgeMemo,
                		"", "", "",
                		"", 
                		"", "", "", "",
                		"", zgJudgeApply.getFaceResultPath(), "",
                		zgJudgeApply.getSpecResultPath(), "",
                		zgJudgeApply.getDetectResultPath(), zgJudgeApply.getDetectResultPath1(),
                		zgJudgeApply.getWpressureResultPath(), "",
                		zgJudgeApply.getProcessResultPath(), "", zgJudgeApply.getFaceResultCode(),
                		zgJudgeApply.getSpecResultCode(), zgJudgeApply.getChemResultCode(),
                		zgJudgeApply.getPhyResultCode(), zgJudgeApply.getDetectResultCode(),
                		zgJudgeApply.getWpressureResultCode(), zgJudgeApply.getProcessResultCode()});
                st.executeUpdate(b.toString());

				b = new SqlBuilder("JdgMatBcM.queryByBatchNoApplyCodeRowS");
				b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
				MatBcMEntity mat = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, MatBcMEntity.class);
				if(mat != null && !zgJudgeApply.getActCount().equals(mat.getActCount()) && !zgJudgeApply.getProcessCode().equals("H")) {
					con.rollback();
					cro.setV_errMsg("判定支数与材料库存支数不一致，不能判定！");
					return cro;
				}
                //回写炼钢、锻造生产物料主表  更新条件应该是 末工序就是成品否者就是在制品。
                String matStatus = "";
            	b = new SqlBuilder("JdgMatBcM.queryByBatchNoApplyCodeFirstRow");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
                mat = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, MatBcMEntity.class);
                if(mat != null && !oldJudgeResult.equals("40740709")){
                	if(instancy){
            			if(zgJudgeApply.getTarget().equals("A") && mat.getMatStatus().equals("80150201")){
                        	matStatus = "80150202";
                        }else if(!zgJudgeApply.getTarget().equals("A") && mat.getMatStatus().equals("80150101")){
                        	matStatus = "80150102";
                        }
                	}else{
                		if(zgJudgeApply.getTarget().equals("A") && !mat.getMatStatus().equals("80150201")
                    			&& !mat.getMatStatus().equals("80150202")){
                    		con.rollback();
                    		cro.setV_errMsg("材料状态不是待判状态，不能判定！");
                        	return cro;
                    	}
                    	if(!zgJudgeApply.getTarget().equals("A") && !mat.getMatStatus().equals("80150101")
                    			&& !mat.getMatStatus().equals("80150102")){
                    		con.rollback();
                    		cro.setV_errMsg("材料状态不是待判状态，不能判定！");
                        	return cro;
                    	}
                    	if(zgJudgeApply.getTarget().equals("A")){
                        	matStatus = "80150202";
                        }else{
                        	matStatus = "80150102";
                        }
                	}
                }

                //判定不合格所属权不变。
                if((bcJudge.getJudgeResult().equals("40740701") || bcJudge.getJudgeResult().equals("40740702")
                		|| bcJudge.getJudgeResult().equals("40740709")) && !oldJudgeResult.equals("40740709")){
                	if(zgJudgeApply.getBelongCodeJugde().equals("")){
                		con.rollback();
                		cro.setV_errMsg("判定所属权为空，不能判定！");
                    	return cro;
                	}
                	b = new SqlBuilder("JdgMatBcM.updateBelong");
                    b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,  zgJudgeApply.getBelongCodeJugde(), zgJudgeApply.getBelongNameJugde() });
                    st.executeUpdate(b.toString());
                    b = new SqlBuilder("JdgMatBcBackup.updateBelong");
                    b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, zgJudgeApply.getBelongCodeJugde(), zgJudgeApply.getBelongNameJugde() });
                    st.executeUpdate(b.toString());
                    //新加逻辑，如果库位是天淮的，所属权归于天淮
                    if(zgJudgeApply.getSupplyUnit().equals("120504")){
                    	b = new SqlBuilder("JdgMatBcM.updateBelongByStorage");
                        b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,  "002001001", "生产计划部" });
                        st.executeUpdate(b.toString());
                        b = new SqlBuilder("JdgMatBcBackup.updateBelongByStorage");
                        b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,  "002001001", "生产计划部" });
                        st.executeUpdate(b.toString());
                    }
                }
                //*********************更新材料表
                String chemJudgeTime = "" ;
                String chemJudgeName = "" ;
                String phyJudgeTime = "" ;
                String phyJudgeName = "" ;
                
                //缺项合格只改结果（轧管缺项合格除外）
                if(oldJudgeResult.equals("40740709") && processCode.equals("F")){
                	b = new SqlBuilder("JdgMatBcM.updateJudgeResultOlny");
                    b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, bcJudge.getJudgeResult(),
                    		bcJudge.getCreateName(), bcJudge.getJudgeId() });
                    st.executeUpdate(b.toString());
                    b = new SqlBuilder("JdgMatBcBackup.updateJudgeResultOlny");
                    b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, bcJudge.getJudgeResult(),
                    		bcJudge.getCreateName(), bcJudge.getJudgeId() });
                    st.executeUpdate(b.toString());
                }else{
                	b = new SqlBuilder("JdgMatBcM.updateJudgeResult");
                    b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
                    		zgJudgeApply.getFaceResultCode(), "", "", zgJudgeApply.getSpecResultCode(), "", "",
                    		zgJudgeApply.getChemResultCode(), chemJudgeTime, chemJudgeName,
                    		zgJudgeApply.getPhyResultCode(), phyJudgeTime, phyJudgeName, zgJudgeApply.getWpressureResultCode(), 
                    		zgJudgeApply.getJudgeResultCode(), zgJudgeApply.getJudgeMaker(), bcJudge.getJudgeId(), zgJudgeApply.getDetectResultCode(),
                    		zgJudgeApply.getDetectResultCode1(), zgJudgeApply.getTestingGrade(), zgJudgeApply.getTestingType(),
                    		zgJudgeApply.getTestingGrade1(), zgJudgeApply.getTestingType1() });
                    st.executeUpdate(b.toString());
                    //更新材料历史表
                    b = new SqlBuilder("JdgMatBcBackup.updateJudgeResult");
                    b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
                    		zgJudgeApply.getFaceResultCode(), "", "", zgJudgeApply.getSpecResultCode(), "", "",
                    		zgJudgeApply.getChemResultCode(), chemJudgeTime, chemJudgeName,
                    		zgJudgeApply.getPhyResultCode(), phyJudgeTime, phyJudgeName, zgJudgeApply.getWpressureResultCode(), 
                    		zgJudgeApply.getJudgeResultCode(), zgJudgeApply.getJudgeMaker(), bcJudge.getJudgeId(), zgJudgeApply.getDetectResultCode(),
                    		zgJudgeApply.getDetectResultCode1(), zgJudgeApply.getTestingGrade(), zgJudgeApply.getTestingType(),
                    		zgJudgeApply.getTestingGrade1(), zgJudgeApply.getTestingType1() });
                    st.executeUpdate(b.toString());
                    //更新材料状态、入库标志
    	            b = new SqlBuilder("JdgMatBcM.updateInstockMatStatus");
    	            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
    	            		matStatus, "1" });
    	            st.executeUpdate(b.toString());
    	            //更新材料状态、入库标志
    	            b = new SqlBuilder("JdgMatBcBackup.updateInstockMatStatus");
    	            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
    	            		matStatus, "1" });
    	            st.executeUpdate(b.toString());
                }
            	
                if(!zgJudgeApply.getIsAllScrap().equals("5") && (bcJudge.getJudgeResult().equals("40740701")
    					|| bcJudge.getJudgeResult().equals("40740702")|| bcJudge.getJudgeResult().equals("40740709"))){
                	//紧急放行的判定不能写入库表， 紧急放行审核通过时写了
                	if(!instancy && !oldJudgeResult.equals("40740709") && !processCode.equals("F")){
                		//新增入库表
                		step = "[入库节点]";
                		b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
                        b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
                        ArrayList<com.steering.pss.ydm.entity.QcmZgJugdeApplyEntity> zgJudges = EntityTool.getEntitysBySqlNoClsCon(
                        		b.toString(), con, com.steering.pss.ydm.entity.QcmZgJugdeApplyEntity.class);
                		FrmBcIqInList bcIqInList = new FrmBcIqInList();
                		bcIqInList.insertBcInList(con, zgJudges, user);
                	}
                }
                
                //关闭本工序炉计划
                if(!zgJudgeApply.getIsAllScrap().equals("5") && !bcJudge.getJudgeResult().equals("")){
                	PlanFurnProduction.productClose(judgeStoveNo, con, zgJudgeApply.getProcessCode(), "1");
                }
    			step = "";

    			//更新接箍
    			CouplingMatMEntity couplingMatM = new CouplingMatMEntity();
    			couplingMatM.setJudgeResult(zgJudgeApply.getJudgeResult());
    			couplingMatM.setJudgeResultCode(zgJudgeApply.getJudgeResultCode());
    			couplingMatM.setJudgeMaker(user);
    			couplingMatM.setJugdeConvicted(bcJudge.getJudgeId());
    			couplingMatM.setJudgeStoveNo(zgJudgeApply.getJudgeStoveNo());
    			couplingMatM.setBatchNo(zgJudgeApply.getBatchNo());
    			couplingMatM.setDeterNo(zgJudgeApply.getJugdeApplyCode());
    			couplingMatM.setWoId(zgJudgeApply.getProOrderId());
    			String setJgJudgeInfo = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatM.setJudgeInfo");
    			setJgJudgeInfo = EntityTool.fillSqlByEntity(setJgJudgeInfo, couplingMatM);
    			st.executeUpdate(setJgJudgeInfo);
    			couplingMatM.setBelongCode(zgJudgeApply.getBelongCodeJugde());
    			couplingMatM.setBelongName(zgJudgeApply.getBelongNameJugde());
    			String setBelong = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatM.setBelong");
    			setBelong = EntityTool.fillSqlByEntity(setBelong, couplingMatM);
    			st.executeUpdate(setBelong);

    			CouplingMatButtressEntity couplingMatBut = new CouplingMatButtressEntity();
    			if(zgJudgeApply.getTarget().equals("A")){
    				couplingMatBut.setMatStatus("80150202");
    			}else{
    				couplingMatBut.setMatStatus("80150102");
    			}
    			String setJgMatStatus = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatButtress.setMatStatus");
    			setJgMatStatus = EntityTool.fillSqlByEntity(setJgMatStatus, couplingMatM);
    			setJgMatStatus = EntityTool.fillSqlByEntity(setJgMatStatus, couplingMatBut);
    			st.executeUpdate(setJgMatStatus);

    			//crm同步
    			if((bcJudge.getJudgeResult().equals("40740701") || bcJudge.getJudgeResult().equals("40740702")
    					|| bcJudge.getJudgeResult().equals("40740709")) && !oldJudgeResult.equals("40740709")){
    				// 通过判定单号，判定炉号查询判定信息
    				List<com.steering.pss.plnsaleord.stove.entity.QcmZgJugdeApplyEntity> qcmApp = PlanFurnProduction.getQcmZgApp(con, judgeApplyCode,
    						judgeStoveNo,processCode , batchNo);
    				CrmOrderProduceService crmOrderProduceService = new CrmOrderProduceService();
    				for (com.steering.pss.plnsaleord.stove.entity.QcmZgJugdeApplyEntity qcmGp : qcmApp) {
    					crmOrderProduceService.insertJudgeZGCrmOrderProduce(con,qcmGp,processCode,true);
    				}
    			}
    			con.commit();
    			return cro;
            }
            //无合同判定
            
            
            String ordLnPk = BllZcColligateJudge.getOrdLnPkByDlyPk(zgJudgeApply.getOrdLnDlyPk(), b, con);
            b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryGroupInfoByBatchNo");
            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
            QcmZgJugdeApplyEntity zgJudgeApplyGroup = EntityTool.getEntityBySqlNoClsCon(
            		b.toString(), con, QcmZgJugdeApplyEntity.class);
            zgJudgeApply.setActCount(zgJudgeApplyGroup.getActCount());
            zgJudgeApply.setActWeight(zgJudgeApplyGroup.getActWeight());
            zgJudgeApply.setActTheoryWeight(zgJudgeApplyGroup.getActTheoryWeight());
            QcmBcJudgeEntity bcJudge = new QcmBcJudgeEntity();
        	
        	QcmZcCheckconsignEntity consign = new QcmZcCheckconsignEntity();
        	consign.setOrdLnDlyPk(zgJudgeApply.getOrdLnDlyPk());
        	consign.setCraftSeq(zgJudgeApply.getCraftSeq());
        	consign.setIndexSeq(zgJudgeApply.getIndexSeq());
        	consign.setProcessCode(zgJudgeApply.getProcessCode());
        	consign.setCic(zgJudgeApply.getCic());
        	consign.setPic(zgJudgeApply.getPic());
        	consign.setStoveNo(zgJudgeApply.getStoveNo());
        	consign.setJudgeStoveNo(zgJudgeApply.getJudgeStoveNo());
        	consign.setBatchNo(zgJudgeApply.getBatchNo());
        	consign.setCraftSource("0");
        	consign.setLotNo(zgJudgeApply.getLotNo());
        	consign.setLotNoGroup(zgJudgeApply.getLotNoGroup());
        	consign.setProduccode(zgJudgeApply.getProduccode());
        	consign.setSteelcode(zgJudgeApply.getSteelcode());
        	consign.setPlineCode(zgJudgeApply.getPlineCode());
        	consign.setLikuProcessCode(zgJudgeApply.getLikuProcessCode());
        	
        	//获取所有试样组 验证缺项判定
            ArrayList<QcmZcCheckconsignDetailEntity> splines = BllRolledTubePhyJudge.getAllCraftPhySplines(
            		consign, ordLnPk, ordLnPk, new ArrayList<String>(), con);
            if(judgeFlag.equals("0")){
            	checkGapJudge(splines,processCode,zgJudgeApply);
            }
            
        	String judgeResult = BllRolledTubePhyJudge.setBcBatchResult(consign, ordLnPk, user, st, con,judgeFlag);
        	//boolean itemResult = judgeItem(zgJudgeApply, b, craftSource, con);
        	//直缝焊套管 不验证理化，性能结果体现在外购管质保书中。
        	if(!zgJudgeApply.getProduccode().equals("S000103") && !zgJudgeApply.getProduccode().equals("S000125")){
        		if(judgeResult.equals("") && !judgeFlag.equals("0")){
            		cro.setV_errMsg("该记录不符合判定条件，不能判定！");
                	return cro;
            	}
			}
        	
        	//验证样条坯料数
        	//获取理化预判炉批结果表
            b = new SqlBuilder("JdgQcmBcBatchResult.getByBatchNo");
            b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, "0", zgJudgeApply.getOrdLnDlyPk() });
            QcmBcBatchResultEntity batchResult = EntityTool.getEntityBySqlNoClsCon(
            		b.toString(), con, QcmBcBatchResultEntity.class);
            
        	if(batchResult != null){
        		zgJudgeApply.setChemResultCode(batchResult.getChemResultCode().equals("") ? zgJudgeApply.getChemResultCode() : batchResult.getChemResultCode());
                bcJudge.setChemResult(batchResult.getChemResultCode().equals("")? zgJudgeApply.getChemResultCode() : batchResult.getChemResultCode());
                zgJudgeApply.setPhyResultCode(batchResult.getPhyResultCode().equals("") ? zgJudgeApply.getPhyResultCode() : batchResult.getPhyResultCode());
            	bcJudge.setPhyResult(batchResult.getPhyResultCode().equals("") ? zgJudgeApply.getPhyResultCode() : batchResult.getPhyResultCode());
        	}
        	
        	//综合性验证各个判定项，得出综合结果
        	if(!zgJudgeApply.getFaceResultPath().equals("")){
        		zgJudgeApply.setFaceResultCode("40740601");
        		bcJudge.setFaceResult(zgJudgeApply.getFaceResultCode());
        	}
        	if(!zgJudgeApply.getDetectResultPath().equals("")){
        		zgJudgeApply.setDetectResultCode("40740401");
        		bcJudge.setDetectResult(zgJudgeApply.getDetectResultCode());
        	}
        	if(zgJudgeApply.getDetectResultPath1().equals("")){
        		zgJudgeApply.setDetectResultCode1("40740401");
        		bcJudge.setDetectResult2(zgJudgeApply.getDetectResultCode1());
        	}
        	if(!zgJudgeApply.getSpecResultPath().equals("")){
        		zgJudgeApply.setSpecResultCode("40740301");
        		bcJudge.setSpecResult(zgJudgeApply.getSpecResultCode());
        	}
        	if(!zgJudgeApply.getWpressureResultPath().equals("")){
        		zgJudgeApply.setWpressureResultCode("40740501");
        		bcJudge.setWaterResult(zgJudgeApply.getWpressureResultCode());
        	}
        	if(!zgJudgeApply.getProcessResultPath().equals("")){
        		zgJudgeApply.setProcessResultCode("40740801");
        		bcJudge.setProcessResult(zgJudgeApply.getProcessResultCode());
        	}
        	
        	ArrayList<String> itemResults = new ArrayList<String>();
        	itemResults.add(zgJudgeApply.getChemResultCode());
        	itemResults.add(zgJudgeApply.getPhyResultCode());
        	itemResults.add(zgJudgeApply.getFaceResultCode());
        	itemResults.add(zgJudgeApply.getDetectResultCode());
        	itemResults.add(zgJudgeApply.getDetectResultCode1());
        	itemResults.add(zgJudgeApply.getWpressureResultCode());
        	itemResults.add(zgJudgeApply.getProcessResultCode());
        	if(itemResults.contains("40740104") || itemResults.contains("40740204") ||
        			itemResults.contains("40740304") || itemResults.contains("40740404") ||
        			itemResults.contains("40740504") || itemResults.contains("40740804")){
        		zgJudgeApply.setJudgeResultCode("40740708");
        		zgJudgeApply.setJudgeResult(getComBaseName("40740708", con));
        		bcJudge.setJudgeResult("40740708");
        	}else if(itemResults.contains("40740103") || itemResults.contains("40740203")
        			|| itemResults.contains("40740303") || itemResults.contains("40740403")
        			|| itemResults.contains("40740503") || itemResults.contains("40740803")){
        		zgJudgeApply.setJudgeResultCode("40740707");
        		zgJudgeApply.setJudgeResult(getComBaseName("40740707", con));
        		bcJudge.setJudgeResult("40740707");
        	}else if(itemResults.contains("40740102") || itemResults.contains("40740202")
        			|| itemResults.contains("40740302") || itemResults.contains("40740402")
        			|| itemResults.contains("40740502") || itemResults.contains("40740602")
        			|| itemResults.contains("40740802")){
        		zgJudgeApply.setJudgeResultCode("40740704");
        		zgJudgeApply.setJudgeResult(getComBaseName("40740704", con));
        		bcJudge.setJudgeResult("40740704");
        	}else{
        		zgJudgeApply.setJudgeResultCode("40740701");
        		zgJudgeApply.setJudgeResult(getComBaseName("40740701", con));
        		bcJudge.setJudgeResult("40740701");
        	}

        	//备料码末工序判定
			//接箍保存成品判定记录和质保书数据
			String blOrdLnPk = BllZcColligateJudge.getOrdLnPkByDlyPk(zgJudgeApply.getOrdLnDlyPk(), b, con);
			b = new SqlBuilder("JdgCraftOrdDesignMscPlPrc.getEndProcessByOrdLnPk");
			b.Fill(new String[]{ blOrdLnPk, zgJudgeApply.getCraftSeq(), zgJudgeApply.getIndexSeq() });
			QcmZgJugdeApplyEntity endProcess = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, QcmZgJugdeApplyEntity.class);
			if(blOrdLnPk.startsWith("BL") && endProcess.getProcessCode().equals(zgJudgeApply.getProcessCode())){
				String zcJudgeResult = new BllCreateZbsInfo().refreshZbsData(
						zgJudgeApply, "1", "bc", checkDetailJsons, con, st);
				zgJudgeApply.setJudgeResultCode(zcJudgeResult);
				//zgJudgeApply.setJudgeResult(getComBaseName(zcJudgeResult, con));
				bcJudge.setJudgeResult(zcJudgeResult);
			}
        	
        	//判定不合格，如果有处置结果就根据处置结果得出最终判定结果
            b = new SqlBuilder("JdgQcmBcPassApplyDAL.queryByBatchNo");
        	b.Fill(new String[]{ zgJudgeApply.getJugdeApplyCode(), judgeStoveNo,
        			batchNo, processCode, "0" });
        	QcmBcPassApplyEntity qualityPass = EntityTool.getEntityBySqlNoClsCon(
        			b.toString(), con, QcmBcPassApplyEntity.class);
        	b = new SqlBuilder("JdgQcmBcPassApplyDAL.queryByBatchNo");
         	b.Fill(new String[]{ zgJudgeApply.getJugdeApplyCode(), judgeStoveNo,
         			batchNo, processCode, "1" });
         	QcmBcPassApplyEntity urgentPass = EntityTool.getEntityBySqlNoClsCon(
         			b.toString(), con, QcmBcPassApplyEntity.class);
            if(zgJudgeApply.getJudgeResultCode().equals("40740704") || zgJudgeApply.getJudgeResultCode().equals("40740708")){
            	if(qualityPass != null){
        			if(qualityPass.getAuditResult().equals("407502")
            				|| qualityPass.getAuditResult().equals("407503")){
            			zgJudgeApply.setJudgeResultCode("40740701");
            			bcJudge.setJudgeResult("40740701");
            		}else if(qualityPass.getAuditResult().equals("407504")){
            			cro.setV_errMsg("放行处置结果为降级/改判，请操作撤销判定！");
                    	return cro;
            		}else if(qualityPass.getAuditResult().equals("407505")){
            			cro.setV_errMsg("放行处置结果为报废，请操作撤销判定！");
                    	return cro;
            		}else if(qualityPass.getAuditResult().equals("407506")){
            			cro.setV_errMsg("放行处置结果为返工，请操作撤销判定！");
                    	return cro;
            		}
            	}
            	
            	if(urgentPass != null){
        			if(urgentPass.getAuditResult().equals("")){
        				cro.setV_errMsg("该炉号处于放行审核状态，不允许判定！");
                    	return cro;
        			}else if(urgentPass.getAuditResult().equals("0")){
        				cro.setV_errMsg("放行处置结果为不通过，如需判定，请联系放行申请人删除放行单！");
                    	return cro;
        			}
            	}
            }
            
            //缺项判定 少SSC
            if(judgeFlag.equals("0")&&!zgJudgeApply.getJudgeResultCode().equals("40740704")){
            	bcJudge.setJudgeResult("40740709");
            	zgJudgeApply.setJudgeResultCode("40740709");
            }
        	
        	//写入半成品综合判定表
        	bcJudge.setMemo(judgeMemo);
        	bcJudge.setCreateName(user);
        	bcJudge.setJudgeStoveNo(judgeStoveNo);
        	bcJudge.setBatchNo(batchNo);
        	bcJudge.setProcessCdoe(processCode);
        	bcJudge.setPlineCode(zgJudgeApply.getPlineCode());
        	bcJudge.setDeliveryStateCode(zgJudgeApply.getDeliveryStateCode());
        	bcJudge.setDeliveryStateName(zgJudgeApply.getDeliveryStateName());
        	bcJudge.setJugdeApplyCode(judgeApplyCode);
        	bcJudge.setActCount(zgJudgeApply.getActCount());
        	bcJudge.setActWeight(zgJudgeApply.getActWeight());
        	bcJudge.setActTheoryWeight(zgJudgeApply.getActTheoryWeight());
        	//新增前作废有效的综合判定记录
        	b = new SqlBuilder("JdgQcmBcJudge.updateValid");
        	b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, judgeApplyCode, "0" });
        	st.executeUpdate(b.toString());
        	//新增判定记录
        	String sqlMaxPk = CoreXmlSqlParsersFactory.getSql("JdgQcmBcJudge.GetMaxPk");
        	GenericEntity maxPk = null;
            maxPk = EntityTool.getEntityBySqlNoClsCon(sqlMaxPk, con, GenericEntity.class);
            bcJudge.setJudgeId(maxPk.getMaxValue());
            String sqlInsert = CoreXmlSqlParsersFactory.getSql("JdgQcmBcJudge.Insert");
            sqlInsert = EntityTool.fillSqlByEntity(sqlInsert, bcJudge);
            st.executeUpdate(sqlInsert);
            
            //如果缺项合格再次判定合格需要更新成品判定条件
            if(oldJudgeResult.equals("40740709") && bcJudge.getJudgeResult().equals("40740701") && processCode.equals("F")){
            	 //修改成品送判记录的判定条件
            	if(zgJudgeApply.getTarget().equals("A")){
            		b = new SqlBuilder("QcmZgJugdeApplyDAL.setZcJudgeCondition");
            		b.Fill(new String[]{ zgJudgeApply.getJugdeApplyCode(), zgJudgeApply.getJudgeStoveNo(), zgJudgeApply.getBatchNo(), "1" });
            		st.executeUpdate(b.toString());
            	}else{
            		//获取性能点工序
                    b = new SqlBuilder("CraftOrdDesignMscPlSti.getPhyProcess");
                    b.Fill(new String[]{ ordLnPk, zgJudgeApply.getCraftSeq(),
                    		zgJudgeApply.getIndexSeq() });
                    CraftOrdDesignMscPlStiEntity sti = EntityTool.getEntityBySqlNoClsCon(
                    		b.toString(), con, CraftOrdDesignMscPlStiEntity.class);
                	char cProcessCode = (char)(processCode.toCharArray()[0] + 1);
                	ArrayList<QcmZgJugdeApplyEntity> zcApplys = getZcJudgeApply(judgeStoveNo, batchNo,
                			String.valueOf(cProcessCode), sti.getProcessCode(), null, con);
                	for(QcmZgJugdeApplyEntity zcApply : zcApplys){
                		b = new SqlBuilder("QcmZgJugdeApplyDAL.setZcJudgeCondition");
                		b.Fill(new String[]{ zcApply.getJugdeApplyCode(), zcApply.getJudgeStoveNo(), zcApply.getBatchNo(), "1" });
                		st.executeUpdate(b.toString());
                	}
            	}
            }
            
            
        	//回写申请判定表
            b = new SqlBuilder("QcmZgJugdeApplyDAL.setJudgeResult");
            b.Fill(new String[]{ zgJudgeApply.getJugdeApplyCode(), judgeStoveNo, batchNo, processCode,
            		zgJudgeApply.getJudgeResultCode(), user, order, group, zgJudgeApply.getFaceResultCode(),
            		zgJudgeApply.getDetectResultCode(), zgJudgeApply.getSpecResultCode(),
            		zgJudgeApply.getWpressureResultCode(), zgJudgeApply.getProcessResultCode(),
            		"20", judgeMemo, bcJudge.getJudgeId(), zgJudgeApply.getChemResultCode(), 
            		zgJudgeApply.getPhyResultCode(), judgeFileMemo });
            st.executeUpdate(b.toString());
            if(!oldJudgeResult.equals("40740709")){
        		b = new SqlBuilder("QcmZgJugdeApplyDAL.setJudgeTime");
            	b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, processCode, "1" });
            	st.executeUpdate(b.toString());
        	}
            //修改申请判定表的结转年月
        	boolean instancy = false;
        	if(urgentPass != null){
        		instancy = true;
        	}
        	//对于A字头结转年月在成品判定写 紧急放行时写了结转年月，再次判定就不需要写了。
        	if(!zgJudgeApply.getTarget().equals("A")){
        		if(!instancy && !oldJudgeResult.equals("40740709")){
    	            b = new SqlBuilder("QcmZgJugdeApplyDAL.setBalYearMonth");
    	            b.Fill(new String[]{ zgJudgeApply.getJugdeApplyCode(), judgeStoveNo, batchNo,processCode,
							"120504".equals(zgJudgeApply.getSupplyUnit())?ComBaseInfo.GetBalYear_2416(now):ComBaseInfo.GetBalYear(now) });
    	            st.executeUpdate(b.toString());
                }
        	}
            //回写管坯申请判定表中的处置方式
            String auditResult = "407501";
            String auditMemo = "";
            if(qualityPass != null){
            	auditResult = qualityPass.getAuditResult();
            	auditMemo = qualityPass.getAuditMemo();
            }
            String strInstancy = instancy ? "1" : "0";
            b = new SqlBuilder("QcmZgJugdeApplyDAL.setAuditResult");
            b.Fill(new String[]{ zgJudgeApply.getJugdeApplyCode(), judgeStoveNo, batchNo,
            		processCode, auditResult, auditMemo, strInstancy });
            st.executeUpdate(b.toString());
            
            //修改放行单中的判定状态。
            b = new SqlBuilder("JdgQcmBcPassApplyDAL.setJudgeResult");
            b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, zgJudgeApply.getJugdeApplyCode(),
            		"0", bcJudge.getJudgeResult() });
            st.executeUpdate(b.toString());
            b = new SqlBuilder("JdgQcmBcPassApplyDAL.setJudgeResult");
            b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, zgJudgeApply.getJugdeApplyCode(),
            		"1", bcJudge.getJudgeResult() });
            st.executeUpdate(b.toString());
            
            //回写材料质量状态表
            QcmBcPassFlowEntity passFlow = null;
            if(qualityPass != null){
            	b = new SqlBuilder("JdgQcmBcPassFlow.getAllByPassApplyNo");
                b.Fill(new String[]{ qualityPass.getPassApplyNo() });
                passFlow = EntityTool.getEntityBySqlNoClsCon(
                		b.toString(), con, QcmBcPassFlowEntity.class);
            }else{
            	passFlow = new QcmBcPassFlowEntity();
            	qualityPass = new QcmBcPassApplyEntity();
            }
			
            b = new SqlBuilder("JdgMatBcQcmTrack.setJudgeResult");
            b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, zgJudgeApply.getJugdeApplyCode(),
            		bcJudge.getJudgeId(),
            		zgJudgeApply.getSteelStandrad(), bcJudge.getJudgeResult(),  user, judgeMemo,
            		qualityPass.getPassApplyNo(), qualityPass.getUnitCode(), qualityPass.getUnitDesc(),
            		qualityPass.getPassApplyTime(), 
            		auditResult, auditMemo, passFlow.getAuditUnit(), qualityPass.getAuditName(),
            		qualityPass.getAuditTime(), zgJudgeApply.getFaceResultPath(), "",
            		zgJudgeApply.getSpecResultPath(), "",
            		zgJudgeApply.getDetectResultPath(), zgJudgeApply.getDetectResultPath1(),
            		zgJudgeApply.getWpressureResultPath(), "",
            		zgJudgeApply.getProcessResultPath(), "", zgJudgeApply.getFaceResultCode(),
            		zgJudgeApply.getSpecResultCode(), zgJudgeApply.getChemResultCode(),
            		zgJudgeApply.getPhyResultCode(), zgJudgeApply.getDetectResultCode(),
            		zgJudgeApply.getWpressureResultCode(), zgJudgeApply.getProcessResultCode()});
            st.executeUpdate(b.toString());

			b = new SqlBuilder("JdgMatBcM.queryByBatchNoApplyCodeRowS");
			b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
			MatBcMEntity mat = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, MatBcMEntity.class);
			if(mat != null && !zgJudgeApply.getActCount().equals(mat.getActCount()) && !zgJudgeApply.getProcessCode().equals("H")) {
				con.rollback();
				cro.setV_errMsg("判定支数与材料库存支数不一致，不能判定！");
				return cro;
			}

            //回写炼钢、锻造生产物料主表  更新条件应该是 末工序就是成品否者就是在制品。
            String matStatus = "";
        	b = new SqlBuilder("JdgMatBcM.queryByBatchNoApplyCodeFirstRow");
            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
            mat = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, MatBcMEntity.class);
            if(mat != null && !oldJudgeResult.equals("40740709")){
            	if(instancy){
        			if(zgJudgeApply.getTarget().equals("A") && mat.getMatStatus().equals("80150201")){
                    	matStatus = "80150202";
                    }else if(!zgJudgeApply.getTarget().equals("A") && mat.getMatStatus().equals("80150101")){
                    	matStatus = "80150102";
                    }
            	}else{
            		if(zgJudgeApply.getTarget().equals("A") && !mat.getMatStatus().equals("80150201")
                			&& !mat.getMatStatus().equals("80150202")){
                		con.rollback();
                		cro.setV_errMsg("材料状态不是待判状态，不能判定！");
                    	return cro;
                	}
                	if(!zgJudgeApply.getTarget().equals("A") && !mat.getMatStatus().equals("80150101")
                			&& !mat.getMatStatus().equals("80150102")){
                		con.rollback();
                		cro.setV_errMsg("材料状态不是待判状态，不能判定！");
                    	return cro;
                	}
                	if(zgJudgeApply.getTarget().equals("A")){
                    	matStatus = "80150202";
                    }else{
                    	matStatus = "80150102";
                    }
            	}
            }
            
            //判定不合格所属权不变。
            if((bcJudge.getJudgeResult().equals("40740701") || bcJudge.getJudgeResult().equals("40740702")
            		|| bcJudge.getJudgeResult().equals("40740709")) && !oldJudgeResult.equals("40740709")){
            	if(zgJudgeApply.getBelongCodeJugde().equals("")){
            		con.rollback();
            		cro.setV_errMsg("判定所属权为空，不能判定！");
                	return cro;
            	}
            	b = new SqlBuilder("JdgMatBcM.updateBelong");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,  zgJudgeApply.getBelongCodeJugde(), zgJudgeApply.getBelongNameJugde() });
                st.executeUpdate(b.toString());
                b = new SqlBuilder("JdgMatBcBackup.updateBelong");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, zgJudgeApply.getBelongCodeJugde(), zgJudgeApply.getBelongNameJugde() });
                st.executeUpdate(b.toString());
            }
            //*********************更新材料表
            String chemJudgeTime = batchResult == null ? "" : batchResult.getJudgeTime();
            String chemJudgeName = batchResult == null ? "" : batchResult.getJudgeMaker();
            String phyJudgeTime = batchResult == null ? "" : batchResult.getJudgeTime();
            String phyJudgeName = batchResult == null ? "" : batchResult.getJudgeMaker();
            
            //缺项合格只改结果（轧管缺项合格除外）
            if(oldJudgeResult.equals("40740709") && processCode.equals("F")){
            	b = new SqlBuilder("JdgMatBcM.updateJudgeResultOlny");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, bcJudge.getJudgeResult(),
                		bcJudge.getCreateName(), bcJudge.getJudgeId() });
                st.executeUpdate(b.toString());
                b = new SqlBuilder("JdgMatBcBackup.updateJudgeResultOlny");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, bcJudge.getJudgeResult(),
                		bcJudge.getCreateName(), bcJudge.getJudgeId() });
                st.executeUpdate(b.toString());
            }else{
            	b = new SqlBuilder("JdgMatBcM.updateJudgeResult");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
                		zgJudgeApply.getFaceResultCode(), "", "", zgJudgeApply.getSpecResultCode(), "", "",
                		zgJudgeApply.getChemResultCode(), chemJudgeTime, chemJudgeName,
                		zgJudgeApply.getPhyResultCode(), phyJudgeTime, phyJudgeName, zgJudgeApply.getWpressureResultCode(), 
                		zgJudgeApply.getJudgeResultCode(), zgJudgeApply.getJudgeMaker(), bcJudge.getJudgeId(), zgJudgeApply.getDetectResultCode(),
                		zgJudgeApply.getDetectResultCode1(), zgJudgeApply.getTestingGrade(), zgJudgeApply.getTestingType(),
                		zgJudgeApply.getTestingGrade1(), zgJudgeApply.getTestingType1() });
                st.executeUpdate(b.toString());
                //更新材料历史表
                b = new SqlBuilder("JdgMatBcBackup.updateJudgeResult");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
                		zgJudgeApply.getFaceResultCode(), "", "", zgJudgeApply.getSpecResultCode(), "", "",
                		zgJudgeApply.getChemResultCode(), chemJudgeTime, chemJudgeName,
                		zgJudgeApply.getPhyResultCode(), phyJudgeTime, phyJudgeName, zgJudgeApply.getWpressureResultCode(), 
                		zgJudgeApply.getJudgeResultCode(), zgJudgeApply.getJudgeMaker(), bcJudge.getJudgeId(), zgJudgeApply.getDetectResultCode(),
                		zgJudgeApply.getDetectResultCode1(), zgJudgeApply.getTestingGrade(), zgJudgeApply.getTestingType(),
                		zgJudgeApply.getTestingGrade1(), zgJudgeApply.getTestingType1() });
                st.executeUpdate(b.toString());
                //更新材料状态、入库标志
	            b = new SqlBuilder("JdgMatBcM.updateInstockMatStatus");
	            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
	            		matStatus, "1" });
	            st.executeUpdate(b.toString());
	            //更新材料状态、入库标志
	            b = new SqlBuilder("JdgMatBcBackup.updateInstockMatStatus");
	            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
	            		matStatus, "1" });
	            st.executeUpdate(b.toString());
            }
        	
            if((bcJudge.getJudgeResult().equals("40740701")|| bcJudge.getJudgeResult().equals("40740702")|| bcJudge.getJudgeResult().equals("40740709"))){
            	
            	//紧急放行的判定不能写入库表， 紧急放行审核通过时写了
            	if(!instancy && (!oldJudgeResult.equals("40740709") || !processCode.equals("F"))){
            		//新增入库表
            		step = "[入库节点]";
            		b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
                    b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
                    ArrayList<com.steering.pss.ydm.entity.QcmZgJugdeApplyEntity> zgJudges = EntityTool.getEntitysBySqlNoClsCon(
                    		b.toString(), con, com.steering.pss.ydm.entity.QcmZgJugdeApplyEntity.class);
            		FrmBcIqInList bcIqInList = new FrmBcIqInList();
            		bcIqInList.insertBcInList(con, zgJudges, user);
            		if(!zgJudgeApply.getIsAllScrap().equals("5")){
            			//调用生成下工序生产计划。
                		step = "[计划节点]";
                		if(processCode.equals("D")){
                			PlanFurnProduction.addPlnZyC(judgeApplyCode, judgeStoveNo, user, con, batchNo);
                        }else if(processCode.equals("E")){
                        	PlanFurnProduction.addPlnZyCD(judgeApplyCode, judgeStoveNo, user, con, batchNo);
                        }else if(processCode.equals("F")){
                        	PlanFurnProduction.addPlnZyCF(judgeApplyCode, judgeStoveNo, user, con, batchNo);
                        }else if(processCode.equals("G")){
                            PlanFurnProduction.addPlnZyCG(judgeApplyCode, judgeStoveNo, user, con, batchNo);//加工判定
                        }
            		}
            	}
            }
            //新加逻辑，如果库位是天淮的，所属权归于天淮
            if(zgJudgeApply.getSupplyUnit().equals("120504")){
            	b = new SqlBuilder("JdgMatBcM.updateBelongByStorage");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,  "002001001", "生产计划部" });
                st.executeUpdate(b.toString());
                b = new SqlBuilder("JdgMatBcBackup.updateBelongByStorage");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,  "002001001", "生产计划部" });
                st.executeUpdate(b.toString());
            }
            
            //关闭本工序炉计划
            if(!zgJudgeApply.getIsAllScrap().equals("5") && !bcJudge.getJudgeResult().equals("")){
            	PlanFurnProduction.productClose(judgeStoveNo, con, zgJudgeApply.getProcessCode(), "1");
            }
			step = "";

			//更新接箍
			CouplingMatMEntity couplingMatM = new CouplingMatMEntity();
			couplingMatM.setJudgeResult(zgJudgeApply.getJudgeResult());
			couplingMatM.setJudgeResultCode(zgJudgeApply.getJudgeResultCode());
			couplingMatM.setJudgeMaker(user);
			couplingMatM.setJugdeConvicted(bcJudge.getJudgeId());
			couplingMatM.setJudgeStoveNo(zgJudgeApply.getJudgeStoveNo());
			couplingMatM.setBatchNo(zgJudgeApply.getBatchNo());
			couplingMatM.setDeterNo(zgJudgeApply.getJugdeApplyCode());
			couplingMatM.setWoId(zgJudgeApply.getProOrderId());
			String setJgJudgeInfo = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatM.setJudgeInfo");
			setJgJudgeInfo = EntityTool.fillSqlByEntity(setJgJudgeInfo, couplingMatM);
			st.executeUpdate(setJgJudgeInfo);
			couplingMatM.setBelongCode(zgJudgeApply.getBelongCodeJugde());
			couplingMatM.setBelongName(zgJudgeApply.getBelongNameJugde());
			String setBelong = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatM.setBelong");
			setBelong = EntityTool.fillSqlByEntity(setBelong, couplingMatM);
			st.executeUpdate(setBelong);

			CouplingMatButtressEntity couplingMatBut = new CouplingMatButtressEntity();
			if(zgJudgeApply.getTarget().equals("A")){
				couplingMatBut.setMatStatus("80150202");
			}else{
				couplingMatBut.setMatStatus("80150102");
			}
			String setJgMatStatus = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatButtress.setMatStatus");
			setJgMatStatus = EntityTool.fillSqlByEntity(setJgMatStatus, couplingMatM);
			setJgMatStatus = EntityTool.fillSqlByEntity(setJgMatStatus, couplingMatBut);
			st.executeUpdate(setJgMatStatus);
			
			if(processCode.equals("D")){
				// 更新进程表mil_processes数据
			    String updateProcess = CoreXmlSqlParsersFactory
						.getSql("QcmZgJugdeApplyDAL.insertMilProcess");// 更新进程表mil_processes数据
				PreparedStatement updateMilProcess = con
						.prepareStatement(updateProcess);
				updateMilProcess.setString(1, judgeStoveNo);
				updateMilProcess.setString(2, zgJudgeApply.getLotNo());
				updateMilProcess.setString(3, zgJudgeApply.getPlineCode());
				updateMilProcess.setString(4, zgJudgeApply.getProOrderId());
				updateMilProcess.setString(5, zgJudgeApply.getGxPlanNo());
				updateMilProcess.executeUpdate();
			}
			
			//crm同步
			if((bcJudge.getJudgeResult().equals("40740701") || bcJudge.getJudgeResult().equals("40740702")
					|| bcJudge.getJudgeResult().equals("40740709")) && !oldJudgeResult.equals("40740709")){
				// 通过判定单号，判定炉号查询判定信息
				List<com.steering.pss.plnsaleord.stove.entity.QcmZgJugdeApplyEntity> qcmApp = PlanFurnProduction.getQcmZgApp(con, judgeApplyCode,
						judgeStoveNo,processCode , batchNo);
				CrmOrderProduceService crmOrderProduceService = new CrmOrderProduceService();
				for (com.steering.pss.plnsaleord.stove.entity.QcmZgJugdeApplyEntity qcmGp : qcmApp) {
					crmOrderProduceService.insertJudgeZGCrmOrderProduce(con,qcmGp,processCode,true);
				}
			}

			con.commit();
			return cro;
		}catch(Exception ex){
			try {
				con.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			if(ex instanceof SQLException){
				cro.setV_errMsg("程序处理失败"+ step +"！");
			}else{
				cro.setV_errMsg("程序处理失败"+ step +"：" + ex.getMessage());
			}
			return cro;
		}finally{
			if(st != null){
				try {
					st.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(con != null){
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
    }
    
    /**
     * 查询成品送判信息
     * @param judgeStoveNo
     * @param processCode
     * @param con
     * @return
     */
    public static ArrayList<QcmZgJugdeApplyEntity> getZcJudgeApply(String judgeStoveNo, String batchNo,
    		String processCode, String phyProcess, ArrayList<QcmZgJugdeApplyEntity> zcApplys,
    		Connection con){
    	if(zcApplys == null){
    		zcApplys = new ArrayList<QcmZgJugdeApplyEntity>();
    	}
    	SqlBuilder b = null;
    	if(processCode.toCharArray()[0] >= phyProcess.toCharArray()[0]){
    		b = new SqlBuilder("QcmZgJugdeApplyDAL.getJudgeBatchNoByLoadStoveNoBatchNo");
    		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode });
    	}else{
    		b = new SqlBuilder("QcmZgJugdeApplyDAL.getJudgeBatchNoByLoadStoveNo");
    		b.Fill(new String[]{ judgeStoveNo, processCode });
    	}
		ArrayList<QcmZgJugdeApplyEntity> applys = EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, QcmZgJugdeApplyEntity.class);
		for(QcmZgJugdeApplyEntity apply : applys){
			if(apply.getTarget().equals("A")){
				zcApplys.add(apply);
			}else{
				char cProcessCode = (char)(processCode.toCharArray()[0] + 1);
				getZcJudgeApply(judgeStoveNo, batchNo, String.valueOf(cProcessCode), phyProcess, zcApplys, con);
			}
		}
		if(applys.size() == 0){
			if(processCode.toCharArray()[0] >= 'G'){
				return zcApplys;
			}else{
				char cProcessCode = (char)(processCode.toCharArray()[0] + 1);
				return getZcJudgeApply(judgeStoveNo, batchNo, String.valueOf(cProcessCode), phyProcess, zcApplys, con);
			}
		}else{
			return zcApplys;
		}
    }
    
    private void checkGapJudge(ArrayList<QcmZcCheckconsignDetailEntity> splines,String processCode,QcmZgJugdeApplyEntity zgJudgeApply) throws Exception{
    	boolean failed = false;
    	boolean noOther = false;
    	boolean noSsc = false;
    	
    	for(QcmZcCheckconsignDetailEntity spline : splines){
    		if(spline.getPhyCodeMin().equals("C0133"))
    		{
    			String a="";
    			a="1";
    		}
    		if(!spline.getSampleId().contains("F")){
    			boolean nkResult = true;
    			boolean existsF = false;
    			for(QcmZcCheckconsignDetailEntity spline2 : splines){
    				if(spline2.getPhyCodeMin().equals(spline.getPhyCodeMin()) && spline2.getSampleId().contains("F")){
    					existsF = true;
    					if(spline2.getNkResult().equals("0")){
    						nkResult = false;
    					}
    				}
    			}
    			
    			if(existsF){
    				if(!nkResult){
        				//failed = true; //暂时不合格的也能缺项判定
        				continue;
        			}
    			}else{
    				if(spline.getNkResult().equals("0")){
    					//failed = true;
    				}
    			}
    			
    			if((!spline.getPhyNameMax().contains("SSC") && spline.getNkResult().equals("0")) 
    				|| !spline.getPhyNameMax().contains("SSC") && spline.getJfResult().equals("0")) {
    				//zgJudgeApply.setJudgeResult("不合格");
    				zgJudgeApply.setPhyResultCode("40740302");
    			}
    			
    		}else{
    			if(spline.getNkResult().equals("0")){
        			//failed = true;
    				continue;
        		}
    		}
    		
    		String phyCodeMin = spline.getPhyCodeMin();
    		if(spline.getNkResult().equals("")){
    			if(phyCodeMin.equals("C0030") || phyCodeMin.equals("C0031")
    					|| phyCodeMin.equals("C0032") || phyCodeMin.equals("C0033")
    					|| phyCodeMin.equals("C0133") || phyCodeMin.equals("C0147")
    					|| phyCodeMin.equals("C0007") || phyCodeMin.equals("C0061")
    					|| phyCodeMin.equals("C0146") || phyCodeMin.equals("C0148")
    					|| phyCodeMin.equals("C0150") || phyCodeMin.equals("C0065")
						|| phyCodeMin.equals("C0160") || phyCodeMin.equals("C0114")
						|| phyCodeMin.equals("C0073") || phyCodeMin.equals("C0163")
						|| phyCodeMin.equals("C0166") || phyCodeMin.equals("C0167")
						|| phyCodeMin.equals("C0165") || phyCodeMin.equals("C0042")
						|| phyCodeMin.equals("C0145")){
    				noSsc = true;
        		}else{
        			noOther = true;
        		}
    		}
    	}
    	
    	if(failed){
    		throw new Exception("存在不合格项，不能缺项判定");
    	}
    	if(noOther && (!"D".equals(processCode) || !"120504".equals(zgJudgeApply.getSupplyUnit()))){
    		throw new Exception("非SSC试样组缺少判定结果，不能缺项判定");
    	}
    	if(!noSsc  && (!"D".equals(processCode) || !"120504".equals(zgJudgeApply.getSupplyUnit()))){
    		throw new Exception("试样组判定齐全，不能缺项判定");
    	}
    }
    
    /**
     * 验证探伤
     * @param judgeApplyCode
     * @param judgeStoveNo
     * @param batchNo
     * @return
     */
    public CoreReturnObject checkDetect(String judgeApplyCode, String judgeStoveNo, String batchNo){
    	Connection con = null;
    	CoreReturnObject cro = new CoreReturnObject();
    	try{
    		con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    		//获取探伤标准
    		SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
    		b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
    		QcmZgJugdeApplyEntity apply = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, QcmZgJugdeApplyEntity.class);
    		String ordLnPk = "";
    		String process = apply.getProcessCode();
    		if(apply.getIsAllScrap().equals("4")){
    			b = new SqlBuilder("JdgSlmOrderLineDelivery.getOrdLnPkByDlyPk");
    			b.Fill(new String[]{ apply.getOrdLnDlyPk() });
    			PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
    			ordLnPk = plnSaleord.getOrdLnPk();
    		}else{
    			b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
    			b.Fill(new String[]{ apply.getOrdLnDlyPk() });
    			PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
    			ordLnPk = plnSaleord.getOrdLnPk();
    		}
    		b = new SqlBuilder("CraftOrdDesignStdDic.getByOrdLnPkGroupByDicGroupSeq");
    		b.Fill(new String[]{ ordLnPk, apply.getCraftSeq(), apply.getIndexSeq(), apply.getProcessCode() });
    		ArrayList<CraftOrdDesignStdDicEntity> groupDics = EntityTool.getEntitysBySqlNoClsCon(b.toString(), con, CraftOrdDesignStdDicEntity.class);
    		for(CraftOrdDesignStdDicEntity groupDic : groupDics){
    			b = new SqlBuilder("CraftOrdDesignStdDic.getByOrdLnPkDicGroupSeq");
    			b.Fill(new String[]{ ordLnPk, apply.getCraftSeq(), apply.getIndexSeq(), apply.getProcessCode(), groupDic.getDic(), groupDic.getGroupSeq() });
    			ArrayList<CraftOrdDesignStdDicEntity> craftDics = EntityTool.getEntitysBySqlNoClsCon(b.toString(), con, CraftOrdDesignStdDicEntity.class);
    			boolean exist = false;
    			for(CraftOrdDesignStdDicEntity craftDic : craftDics){
    				String testGrade = craftDic.getLvDesc().toUpperCase();//等级
    				String testType = "";//种类
    				b = new SqlBuilder("JdgComBasePhy.getMemoByPhyCode");
    				b.Fill(new String[]{ craftDic.getPhyCode() });
    				ComBasePhyEntity basePhy = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, ComBasePhyEntity.class);
    				testType = basePhy.getMemo().toUpperCase();

    				//获取探伤实绩
					List<HttCrackDetectionParaEntity> detects = BllZcColligateJudge.getDetectInfo(
							judgeStoveNo, batchNo, apply.getProcessCode(), apply.getZpMLh(), con);
					if(process.equals("G")){
						for(HttCrackDetectionParaEntity detect : detects){
							if(craftDic.getPhyName().contains("分层")){
								if((!detect.getLamination().equals("") || !detect.getLamination().equals("/"))
										&& detect.getTestingType().equals(testType)){
									exist = true;
									break;
								}
							}else if(craftDic.getPhyName().contains("壁厚")){
								if((!detect.getWallThickness().equals("") && !detect.getWallThickness().equals("/"))
//										&& detect.getTestingType().equals(testType)
								){
									exist = true;
									break;
								}
							}else{
								if(detect.getTestingGrade().equals(testGrade) && detect.getTestingType().equals(testType)){
									exist = true;
									break;
								}
							}
						}
						if(exist){
							break;
						}
					}
					//2020-04-08 热处理探伤验证修改
					else if(process.equals("F")){
						if(craftDic.getPhyName().contains("分层")||craftDic.getPhyName().contains("壁厚")){
							if(craftDic.getPhyName().contains("分层")){
								for(HttCrackDetectionParaEntity detect : detects){
									if((!detect.getLamination().equals("") || !detect.getLamination().equals("/"))
											&& detect.getTestingType().equals(testType)){
										exist = true;
									}else{
										exist = false;
									}
								}
							}else if(craftDic.getPhyName().contains("壁厚")){
								for(HttCrackDetectionParaEntity detect : detects){
									if((!detect.getWallThickness().equals("") || !detect.getWallThickness().equals("/"))
											&& detect.getTestingType().equals(testType)){
										exist = true;
									}
									else{
										exist = false;
									}
								}
							}
						}
						else if(craftDic.getPositionDesc().contains("管端")){
							for(HttCrackDetectionParaEntity detect : detects){
								if((detect.getTestingPosition().equals("1") || process.equals("D"))
										&& (testGrade.equals(detect.getTestingGrade())
											|| (("E2H".equals(testGrade) || "E3H".equals(testGrade) || "E4H".equals(testGrade))
											&& detect.getTestingGrade().startsWith(testGrade)))
										&& testType.equals(detect.getTestingType())){
									exist = true;
								}else
								{
									exist = false;
								}
							}
						}else if(craftDic.getPositionDesc().contains("管体")){
							for(HttCrackDetectionParaEntity detect : detects){
								if((detect.getTestingPosition().equals("0") || process.equals("D")) &&
										(testGrade.equals(detect.getTestingGrade())
												|| (("E2H".equals(testGrade) || "E3H".equals(testGrade) || "E4H".equals(testGrade))
												&& detect.getTestingGrade().startsWith(testGrade)))
										&& testType.equals(detect.getTestingType())){
									exist = true;
								}else
								{
									exist = false;
								}
							}
						}else if(craftDic.getPositionDesc().contains("全长")){
							boolean gdExist = false;
							boolean gtExist = false;
							for(HttCrackDetectionParaEntity detect : detects){
								if((testGrade.equals(detect.getTestingGrade())
										|| (("E2H".equals(testGrade) || "E3H".equals(testGrade) || "E4H".equals(testGrade))
										&& detect.getTestingGrade().startsWith(testGrade))) &&
										testType.equals(detect.getTestingType())){
									if(process.equals("D")){
										gtExist = true;
										gdExist = true;
										break;
									}else{
										if(detect.getTestingPosition().equals("0")){
											gtExist = true;
										}else if(detect.getTestingPosition().equals("1")){
											gdExist = true;
										}
									}
								}
							}
							if(gdExist && gtExist){
								exist = true;
							}else
							{
								exist = false;
							}
						}
						else{
							exist = true;
						}
						if(!exist){
							break;
						}
					}
					else{
						boolean fullExist = false; //全长
						if(craftDic.getPositionDesc().contains("管端")){
							for(HttCrackDetectionParaEntity detect : detects){
								if((detect.getTestingPosition().equals("1") || process.equals("D"))
										&& (
											(testGrade.equals(detect.getTestingGrade()) || testGrade.equals(detect.getTestingGrade().toUpperCase()))
											|| (("E2H".equals(testGrade) || "E3H".equals(testGrade) || "E4H".equals(testGrade)) && detect.getTestingGrade().startsWith(testGrade))
										)
										&& testType.equals(detect.getTestingType())){
									exist = true;
									break;
								}
							}
						}else if(craftDic.getPositionDesc().contains("管体")){
							for(HttCrackDetectionParaEntity detect : detects){
								if((detect.getTestingPosition().equals("0") || process.equals("D"))
										&& (
											(testGrade.equals(detect.getTestingGrade()) || testGrade.equals(detect.getTestingGrade().toUpperCase()))
												|| (("E2H".equals(testGrade) || "E3H".equals(testGrade) || "E4H".equals(testGrade)) && detect.getTestingGrade().startsWith(testGrade))
										)
										&& testType.equals(detect.getTestingType())){
									exist = true;
									break;
								}
							}
						}else if(craftDic.getPositionDesc().contains("全长")){
							boolean gdExist = false;
							boolean gtExist = false;
							for(HttCrackDetectionParaEntity detect : detects){
								if(((testGrade.equals(detect.getTestingGrade()) || testGrade.equals(detect.getTestingGrade().toUpperCase()))
										|| (("E2H".equals(testGrade) || "E3H".equals(testGrade) || "E4H".equals(testGrade)) && detect.getTestingGrade().startsWith(testGrade)))
										&& testType.equals(detect.getTestingType())){
									if(process.equals("D")){
										gtExist = true;
										gdExist = true;
										break;
									}else{
										if(detect.getTestingPosition().equals("0")){
											gtExist = true;
										}else if(detect.getTestingPosition().equals("1")){
											gdExist = true;
										}
									}
								}
							}
							if(gdExist && gtExist){
								exist = true;
								break;
							}
						}
						if(exist){
							break;
						}
					}
    			}
    			if(!exist){
    				if(process.equals("D")){
    					cro.setResult("该炉批的探伤种类/等级不符合标准！");
    					return cro;
    				}
    				else{
    					cro.setResult("该炉批的探伤种类/等级/位置不符合标准！");
    					return cro;
    				}
				}
    		}
    		
    		return cro;
    	}catch(Exception ex){
    		cro.setV_errMsg(ex.getMessage());
    		return cro;
    	}finally{
    		try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}
    }
    
    public CoreReturnObject checkSampleCount(String judgeApplyCode, String judgeStoveNo,
    		String batchNo, String craftSource){
    	SqlBuilder b = null;
    	Connection con = null;
    	CoreReturnObject cro = new CoreReturnObject();
    	try{
    		con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
    		b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
            QcmZgJugdeApplyEntity zgJudgeApply = EntityTool.getEntityBySqlNoClsCon(
            		b.toString(), con, QcmZgJugdeApplyEntity.class);
            String craftProcess = zgJudgeApply.getLikuProcessCode().equals("") ? zgJudgeApply.getProcessCode() : zgJudgeApply.getLikuProcessCode();
            String ordLnPk = "";
    		if(zgJudgeApply.getIsAllScrap().equals("4")){
    			b = new SqlBuilder("JdgSlmOrderLineDelivery.getOrdLnPkByDlyPk");
    			b.Fill(new String[]{ zgJudgeApply.getOrdLnDlyPk() });
    			PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
    			ordLnPk = plnSaleord.getOrdLnPk();
    		}else{
    			b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
    			b.Fill(new String[]{ zgJudgeApply.getOrdLnDlyPk() });
    			PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
    			ordLnPk = plnSaleord.getOrdLnPk();
    		}
    		
    		b = new SqlBuilder("QcmGpJugdeApplyDAL.getPlineByStoveNo");
    		b.Fill(new String[]{ zgJudgeApply.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";
        		}
    		}
    		
        	b = new SqlBuilder("CraftOrdDesignStdPic.getPhyCnt");
        	b.Fill(new String[]{ ordLnPk, zgJudgeApply.getCraftSeq(),
        			craftProcess, craftSource, zgJudgeApply.getIndexSeq() });
        	GenericEntity phyCount = EntityTool.getEntityBySqlNoClsCon(
        			b.toString(), con, GenericEntity.class);
        	if(!phyCount.getCount().equals("0")){
        		ArrayList<QcmJhyPhySplineEntity> splineResults = new ArrayList<QcmJhyPhySplineEntity>();
        		b = new SqlBuilder("QcmJhyPhyresultDAL.QueryPhyMinByBatchNo");
            	b.Fill(new Object[]{ ordLnPk, zgJudgeApply.getCraftSeq(), zgJudgeApply.getIndexSeq(),
            			zgJudgeApply.getProcessCode(), zgJudgeApply.getPic(), zgJudgeApply.getJudgeStoveNo(),
            			zgJudgeApply.getBatchNo(), zgJudgeApply.getLotNo(), zgJudgeApply.getLotNoGroup(),
            			craftSource, "0", new String[]{}, "", "0", zgJudgeApply.getPlineCode(), ordLnPk, gpType,
            			craftProcess });
            	ArrayList<QcmJhyPhySplineEntity> phySplineResults = EntityTool.getEntitysBySqlNoClsCon(
                		b.toString(), con, QcmJhyPhySplineEntity.class);
            	for(QcmJhyPhySplineEntity phySplineResult : phySplineResults){
            		splineResults.add(phySplineResult);
            	}
            	
            	//重新热处理
            	b = new SqlBuilder("QcmJhyPhyresultDAL.QueryPhyMinByBatchNo");
            	b.Fill(new Object[]{ ordLnPk, zgJudgeApply.getCraftSeq(), zgJudgeApply.getIndexSeq(),
            			zgJudgeApply.getProcessCode(), zgJudgeApply.getPic(), zgJudgeApply.getJudgeStoveNo(),
            			zgJudgeApply.getBatchNo(), zgJudgeApply.getLotNo(),
            			zgJudgeApply.getLotNoGroup(), "0", "0", new String[]{}, "", "1", zgJudgeApply.getPlineCode(),
            			ordLnPk, gpType, craftProcess });
            	phySplineResults = EntityTool.getEntitysBySqlNoClsCon(
                		b.toString(), con, QcmJhyPhySplineEntity.class);
            	HashMap<String, ArrayList<QcmJhyPhySplineEntity>> phyMap = new HashMap<String, ArrayList<QcmJhyPhySplineEntity>>();
            	for(QcmJhyPhySplineEntity splineResult : splineResults){
            		if(!splineResult.getSampleNo().equals("")) continue;
            		if(phyMap.containsKey(splineResult.getPhyCodeMin())){
            			ArrayList<QcmJhyPhySplineEntity> tmpSplines = phyMap.get(splineResult.getPhyCodeMin());
            			tmpSplines.add(splineResult);
            		}else{
            			ArrayList<QcmJhyPhySplineEntity> tmpSplines = new ArrayList<QcmJhyPhySplineEntity>();
            			tmpSplines.add(splineResult);
            			phyMap.put(splineResult.getPhyCodeMin(), tmpSplines);
            		}
            	}
            	
            	for(String key : phyMap.keySet()){
            		boolean addRcl = false;
            		for(QcmJhyPhySplineEntity spline : phySplineResults){
            			if(spline.getSampleNo().equals("")) continue;
            			if(spline.getPhyCodeMin().equals(key)){
            				splineResults.add(spline);
            				addRcl = true;
            			}
            		}
            		if(addRcl){
            			ArrayList<QcmJhyPhySplineEntity> tmpSplines = phyMap.get(key);
            			for(QcmJhyPhySplineEntity tmpSpline : tmpSplines){
            				splineResults.remove(tmpSpline);
            			}
            		}
            	}
            	
            	//通过试样组分组
            	HashMap<String, String[]> phyCodeMins = new HashMap<String, String[]>();
            	for(QcmJhyPhySplineEntity result : splineResults){
            		String[] data = new String[]{ result.getJudgeStoveNo(), result.getBatchNo(), result.getRate() };
            		phyCodeMins.put(result.getPhyCodeMin(), data);
            	}
            	
            	for(String phyCodeMin : phyCodeMins.keySet())
            	{
            		int sampleNoCnt = 0;
    				for(QcmJhyPhySplineEntity splineResult : splineResults){
    					if(splineResult.getPhyCodeMin().equals(phyCodeMin)){
    						sampleNoCnt++;
    					}
    				}
    				b = new SqlBuilder("JdgCraftOrdDesignStdPicSmp.queryGroupCountByOrdLnPk");
        			b.Fill(new String[]{ ordLnPk, zgJudgeApply.getCraftSeq(),
        					zgJudgeApply.getIndexSeq(), craftProcess,
        					zgJudgeApply.getPic(), phyCodeMin, craftSource});
        			GenericEntity groupCount = EntityTool.getEntityBySqlNoClsCon(
        					b.toString(), con, GenericEntity.class);
        			int gCount = Integer.parseInt(groupCount.getCount());
        			if(sampleNoCnt < gCount){
        				cro.setResult("试样组【" + groupCount.getValue() + "】的试样号数量小于标准要求数量[" + String.valueOf(gCount) + "]！");
        				return cro;
        			}
            	}
        	}
        	
        	b = new SqlBuilder("CraftOrdDesignStdCic.getChemCnt");
        	b.Fill(new String[]{ ordLnPk, zgJudgeApply.getCraftSeq(),
        			craftSource, zgJudgeApply.getIndexSeq(), craftProcess });
        	GenericEntity chemCount = EntityTool.getEntityBySqlNoClsCon(
        			b.toString(), con, GenericEntity.class);
        	b = new SqlBuilder("JdgCraftOrdDesignStd.getProductCnt");
			b.Fill(new String[]{ ordLnPk, zgJudgeApply.getCraftSeq(),
					craftSource });
			CraftOrdDesignStdEntity craftStd = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, CraftOrdDesignStdEntity.class);
        	if(!chemCount.getCount().equals("0")){
        		b = new SqlBuilder("QcmJhyElementsDAL.getPhyMinByBatchNo");
            	b.Fill(new Object[]{ ordLnPk, zgJudgeApply.getCraftSeq(), zgJudgeApply.getJudgeStoveNo(),
            			zgJudgeApply.getBatchNo(), zgJudgeApply.getProcessCode(),
            			zgJudgeApply.getCic(), craftSource, craftStd.getRateN(), zgJudgeApply.getPlineCode(), ordLnPk, gpType });
            	ArrayList<QcmJhyPhySplineEntity> chemSplineResults = EntityTool.getEntitysBySqlNoClsCon(
                		b.toString(), con, QcmJhyPhySplineEntity.class);
            	
            	//分组
            	HashMap<String, HashMap<String, Integer>> mapPhyCounts = new HashMap<String, HashMap<String,Integer>>();
            	for(QcmJhyPhySplineEntity chemSplineResult : chemSplineResults){
            		String stove = chemSplineResult.getJudgeStoveNo();
            		String phyCodeMin = chemSplineResult.getPhyCodeMin();
            		if(mapPhyCounts.containsKey(stove)){
            			HashMap<String, Integer> mapPhyCount = mapPhyCounts.get(stove);
            			if(mapPhyCount.containsKey(phyCodeMin)){
            				mapPhyCount.put(phyCodeMin, mapPhyCount.get(phyCodeMin) + 1);
            			}else{
            				mapPhyCount.put(phyCodeMin, 1);
            			}
            		}else{
            			HashMap<String, Integer> newMapPhyCount = new HashMap<String, Integer>();
        				newMapPhyCount.put(phyCodeMin, 1);
        				mapPhyCounts.put(stove, newMapPhyCount);
            		}
            	}
            	
            	for(String stove : mapPhyCounts.keySet()){
            		HashMap<String, Integer> mapPhyCount = mapPhyCounts.get(stove);
            		for(String phyCodeMin : mapPhyCount.keySet()){
            			Integer count = mapPhyCount.get(phyCodeMin);
            			Integer gCount = Integer.parseInt(craftStd.getProductCntN());
            			if(count < gCount){
            				cro.setResult("试样组【化学】的试样号数量小于标准要求数量["+ String.valueOf(gCount) +"]！");
            				return cro;
            			}
            		}
            	}
        	}
        	
        	return cro;
    	}catch(Exception ex){
    		cro.setV_errMsg(ex.getMessage());
    		return cro;
    	}finally{
    		try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}
    }
    
    private void checkJudgeLock(SqlBuilder b, QcmZgJugdeApplyEntity zgJudgeApply,
    		Connection con) throws Exception{
        HashMap<String, QcmZgJugdeApplyEntity> applyMap = BllZcColligateJudge.getAllJudgeApply(
				zgJudgeApply.getJugdeApplyCode(), zgJudgeApply.getJudgeStoveNo(), zgJudgeApply.getBatchNo(),
				zgJudgeApply.getProcessCode(), zgJudgeApply.getUpperHeatplanId(), null, null, con);
        for(String key : applyMap.keySet()){
        	QcmZgJugdeApplyEntity apply = applyMap.get(key);
        	b = new SqlBuilder("JdgQcmJudgeLock.getLockInfo1");
//        	b.Fill(new String[]{ apply.getJudgeStoveNo(), applypply.getBatchNo(), apply.getProcessCode(),
//        			zgJudgeApply.getProcessCode() });
//			b.Fill(new String[]{ apply.getJudgeStoveNo(), apply.getBatchNo(), zgJudgeApply.getProcessCode() });
			b.Fill(new String[]{ apply.getJudgeStoveNo(), zgJudgeApply.getProcessCode() });
        	QcmJudgeLockEntity lockEntity = EntityTool.getEntityBySqlNoClsCon(
        			b.toString(), con, QcmJudgeLockEntity.class);
        	if(lockEntity != null){
        		throw new Exception("炉号：" + zgJudgeApply.getJudgeStoveNo() + " 批号：" + zgJudgeApply.getBatchNo()
        				+ "已被锁定，暂时无法操作！\r\n锁定人："+ lockEntity.getLockName() +" 锁定原因：" + lockEntity.getLockReason()
						+ "\r\n操作工序："+ apply.getProcessDesc() +" 操作炉号：" + apply.getJudgeStoveNo() + " 批号：" + apply.getBatchNo());
        	}
        }
    }
    
//    /**
//     * 验证项目是否判完整
//     * @param zgJudgeApply
//     * @param b
//     * @param craftSource
//     * @param con
//     * @return
//     */
//    private boolean judgeItem(QcmZgJugdeApplyEntity zgJudgeApply, SqlBuilder b,
//    		String craftSource, Connection con){
//    	ArrayList<QcmJhyPhySplineEntity> splineResults = new ArrayList<QcmJhyPhySplineEntity>();
//    	b = new SqlBuilder("CraftOrdDesignStdCic.getChemCnt");
//    	b.Fill(new String[]{ zgJudgeApply.getOrdLnDlyPk(), zgJudgeApply.getCraftSeq(), craftSource,
//    			zgJudgeApply.getIndexSeq(), zgJudgeApply.getProcessCode()});
//    	GenericEntity chemCount = EntityTool.getEntityBySqlNoClsCon(
//    			b.toString(), con, GenericEntity.class);
//    	if(!chemCount.getCount().equals("0")){
//    		b = new SqlBuilder("QcmJhyElementsDAL.getPhyMinByBatchNo");
//        	b.Fill(new Object[]{ zgJudgeApply.getOrdLnDlyPk(), zgJudgeApply.getCraftSeq(), zgJudgeApply.getJudgeStoveNo(),
//        			zgJudgeApply.getProcessCode(), craftSource,
//        			zgJudgeApply.getCic() });
//        	ArrayList<QcmJhyPhySplineEntity> chemSplineResults = EntityTool.getEntitysBySqlNoClsCon(
//            		b.toString(), con, QcmJhyPhySplineEntity.class);
//        	if(chemSplineResults.size() == 0){
//        		return false;
//        	}
//        	for(QcmJhyPhySplineEntity chemSplineResult : chemSplineResults){
//        		splineResults.add(chemSplineResult);
//        	}
//    	}
//    	b = new SqlBuilder("CraftOrdDesignStdPic.getPhyCnt");
//    	b.Fill(new String[]{ zgJudgeApply.getOrdLnDlyPk(), zgJudgeApply.getCraftSeq(),
//    			zgJudgeApply.getProcessCode(), craftSource });
//    	GenericEntity phyCount = EntityTool.getEntityBySqlNoClsCon(
//    			b.toString(), con, GenericEntity.class);
//    	if(!phyCount.getCount().equals("0")){
//    		b = new SqlBuilder("QcmJhyPhyresultDAL.QueryPhyMinByBatchNo");
//        	b.Fill(new Object[]{ zgJudgeApply.getOrdLnDlyPk(), zgJudgeApply.getCraftSeq(), zgJudgeApply.getIndexSeq(),
//        			zgJudgeApply.getProcessCode(), zgJudgeApply.getPic(), zgJudgeApply.getJudgeStoveNo(),
//        			zgJudgeApply.getBatchNo(), craftSource, zgJudgeApply.getLotNo(),
//        			zgJudgeApply.getLotNoGroup(), "0", new String[]{} });
//        	ArrayList<QcmJhyPhySplineEntity> phySplineResults = EntityTool.getEntitysBySqlNoClsCon(
//            		b.toString(), con, QcmJhyPhySplineEntity.class);
//        	if(phySplineResults.size() == 0){
//        		return false;
//        	}
//        	for(QcmJhyPhySplineEntity phySplineResult : phySplineResults){
//        		splineResults.add(phySplineResult);
//        	}
//    	}
//
//        for(QcmJhyPhySplineEntity splineResult : splineResults){
//			if(splineResult.getNkResult().equals("")){
//				return false;
//			}
//        }
//        
//        return true;
//    }
    
    public CoreReturnObject deleteJudge(String judgeApplyCode, String judgeStoveNo,
    		String batchNo, String processCode, String user){
    	Connection con = null;
    	Statement st = null;
    	CoreReturnObject cro = new CoreReturnObject();
    	cro.setV_errMsg("");
    	try{
    		SqlBuilder b;
        	con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
        	con.setAutoCommit(false);
        	st = con.createStatement();
        	
        	//获取送判信息
        	b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
        	b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
        	QcmZgJugdeApplyEntity judgeApply = EntityTool.getEntityBySqlNoClsCon(
        			b.toString(), con, QcmZgJugdeApplyEntity.class);
        	String oldJudgeResult = judgeApply.getJudgeResultCode();
        	
        	//获取计划信息
        	if(processCode.equals("D")){
        		b = new SqlBuilder("JdgPlnZyZgM.queryByJudgeStoveNo");
        	}else if(processCode.equals("E")){
        		b = new SqlBuilder("JdgPlnZyDbkM.queryByJudgeStoveNo");
        	}else if(processCode.equals("F")){
        		b = new SqlBuilder("JdgPlnZyRclM.queryByJudgeStoveNo");
        	}else if(processCode.equals("G")){
        		b = new SqlBuilder("JdgPlnZyJgxM.queryByJudgeStoveNo");
        	}else if(processCode.equals("H")){
				b = new SqlBuilder("JdgPlnZyJgM.queryByJudgeStoveNo");
			}
        	else{
        		cro.setV_errMsg("工序异常！");
        		return cro;
        	}
        	
        	b.Fill(new String[]{ judgeStoveNo });
        	PlnZyZgMEntity zyMEntity = EntityTool.getEntityBySqlNoClsCon(
        			b.toString(), con, PlnZyZgMEntity.class);
        	//组炉反线炉计划没有，MIL_PLAN中有
        	if(zyMEntity == null && judgeApply.getProcessCode().equals("D")){
				b = new SqlBuilder("JdgPlnZyZgM.queryByPk", judgeApply.getHeatPlanNo());
				zyMEntity = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, PlnZyZgMEntity.class);
			}
        	if(zyMEntity != null && !oldJudgeResult.equals("40740709") && !oldJudgeResult.equals("40740704")){
        		if(zyMEntity.getNextProcessCode().equals("E")){
            		b = new SqlBuilder("JdgPlnZyDbkC.queryByApplyCode");
            		b.Fill(new String[]{ judgeApply.getJudgeStoveNo(), judgeApply.getBatchNo(), judgeApply.getJugdeApplyCode() });
            		PlnZyDbkCEntity dbkC = EntityTool.getEntityBySqlNoClsCon(
                			b.toString(), con, PlnZyDbkCEntity.class);
            		if(!dbkC.getRealIndoubleNum().equals("") && !dbkC.getRealIndoubleNum().equals("0")){
            			cro.setV_errMsg("此炉批已经过镦拔扩，不能撤销判定！");
                		return cro;
            		}
            	}else if(zyMEntity.getNextProcessCode().equals("F")){
            		b = new SqlBuilder("JdgPlnZyRclC.queryByApplyCode");
            		b.Fill(new String[]{ judgeApply.getJudgeStoveNo(), judgeApply.getBatchNo(), judgeApply.getJugdeApplyCode() });
            		PlnZyRclCEntity rclC = EntityTool.getEntityBySqlNoClsCon(
                			b.toString(), con, PlnZyRclCEntity.class);
            		if(!rclC.getRealIndoubleNum().equals("") && !rclC.getRealIndoubleNum().equals("0")){
            			cro.setV_errMsg("此炉号已经过热处理，不能撤销判定！");
                		return cro;
            		}
            	}else if(zyMEntity.getNextProcessCode().equals("G")){
            		b = new SqlBuilder("JdgPlnZyJgxC.queryByApplyCode");
            		b.Fill(new String[]{ judgeApply.getJudgeStoveNo(), judgeApply.getBatchNo(), judgeApply.getJugdeApplyCode() });
            		PlnZyRclCEntity jgxC = EntityTool.getEntityBySqlNoClsCon(
                			b.toString(), con, PlnZyRclCEntity.class);
            		if(!jgxC.getRealIndoubleNum().equals("") && !jgxC.getRealIndoubleNum().equals("0")){
            			cro.setV_errMsg("此炉号已经过加工，不能撤销判定！");
                		return cro;
            		}
            	}
        	}
        	
        	
        	if(!oldJudgeResult.equals("40740709") && !oldJudgeResult.equals("40740704")){
        		if(!user.equals("SYSTEM") && judgeApply.getIsCarryVoer().equals("1")){
            		cro.setV_errMsg("此炉号已月末结转，不能撤销判定！");
                    return cro;
            	}
        	}
        	
        	b = new SqlBuilder("JdgMatBcM.queryLkFCnt");
        	b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
        	GenericEntity lkCnt = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, GenericEntity.class);
        	if(zyMEntity !=null && !lkCnt.getCount().equals("0") && !oldJudgeResult.equals("40740709") && !oldJudgeResult.equals("40740704")){
        		if(!user.equals("SYSTEM") && zyMEntity.getNextProcessCode().equals("E")){
        			b = new SqlBuilder("JdgPlnZyDbkM.queryByJudgeStoveNo");
            		b.Fill(new String[]{ judgeStoveNo });
            		PlnZyZgMEntity plnStatus = EntityTool.getEntityBySqlNoClsCon(
                			b.toString(), con, PlnZyZgMEntity.class);
            		if(plnStatus != null){
            			cro.setV_errMsg("此炉号已镦拔扩利库，不能撤销判定！\r\n（如需撤销判定请联系镦拔扩产线"+ plnStatus.getPlineName() +"的计划员）");
            			return cro;
            		}
        		}else if(!user.equals("SYSTEM") && zyMEntity.getNextProcessCode().equals("F")){
        			b = new SqlBuilder("JdgPlnZyRclM.queryByJudgeStoveNo");
            		b.Fill(new String[]{ judgeStoveNo });
            		PlnZyZgMEntity plnStatus = EntityTool.getEntityBySqlNoClsCon(
                			b.toString(), con, PlnZyZgMEntity.class);
            		if(plnStatus != null){
            			cro.setV_errMsg("此炉号已热处理利库，不能撤销判定！\r\n（如需撤销判定请联系热处理产线"+ plnStatus.getPlineName() +"的计划员）");
            			return cro;
            		}
        		}else if(!user.equals("SYSTEM") && zyMEntity.getNextProcessCode().equals("G")){
        			b = new SqlBuilder("JdgPlnZyJgxM.queryByJudgeStoveNo");
            		b.Fill(new String[]{ judgeStoveNo });
            		PlnZyZgMEntity plnStatus = EntityTool.getEntityBySqlNoClsCon(
                			b.toString(), con, PlnZyZgMEntity.class);
            		if(plnStatus != null){
            			cro.setV_errMsg("此炉号已加工利库，不能撤销判定！\r\n（如需撤销判定请联系加工产线"+ plnStatus.getPlineName() +"的计划员）");
            			return cro;
            		}
        		}
        	}
        	
        	//是否成品已判
        	if(!judgeApply.getJudgeTolresultCode().equals("")){
        		cro.setV_errMsg("此炉号成品综合已判定，不能撤销！");
    			return cro;
        	}
        	
        	//是否正在放行
        	b = new SqlBuilder("JdgQcmBcPassApplyDAL.queryByBatchNo");
        	b.Fill(new String[]{ judgeApply.getJugdeApplyCode(), judgeStoveNo, batchNo,
        			processCode, "0" });
        	QcmBcPassApplyEntity qualityPass = EntityTool.getEntityBySqlNoClsCon(
            		b.toString(), con, QcmBcPassApplyEntity.class);
        	if(!user.equals("SYSTEM") && qualityPass != null && qualityPass.getAuditResult().equals("")){
        		cro.setV_errMsg("此炉批的质量放行单正在审核，不能撤销判定！");
    			return cro;
        	}
        	b = new SqlBuilder("JdgQcmBcPassApplyDAL.queryByBatchNo");
        	b.Fill(new String[]{ judgeApply.getJugdeApplyCode(), judgeStoveNo, batchNo,
        			processCode, "0" });
        	QcmBcPassApplyEntity urgentPass = EntityTool.getEntityBySqlNoClsCon(
            		b.toString(), con, QcmBcPassApplyEntity.class);
        	if(!user.equals("SYSTEM") && urgentPass != null && urgentPass.getAuditResult().equals("")){
        		cro.setV_errMsg("此炉批的紧急放行单正在审核，不能撤销判定！");
    			return cro;
        	}
        	
        	//如果有处置方式，撤销判定只修改状态。
            if(judgeApply.getAuditResult().equals("407504") || judgeApply.getAuditResult().equals("407505")
            		|| judgeApply.getAuditResult().equals("407506")){
            	b = new SqlBuilder("QcmZgJugdeApplyDAL.setValidflag");
            	b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, processCode, "00" });
            	st.executeUpdate(b.toString());
            }else{
            	b = new SqlBuilder("QcmZgJugdeApplyDAL.setJudgeResult");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, processCode, "",
                		"", "", "", judgeApply.getFaceResultCode(), judgeApply.getDetectResultCode(),
						judgeApply.getSpecResultCode(), judgeApply.getWpressureResultCode(),
						judgeApply.getProcessResultCode(), "00", "", "", "", "", "" });
                st.executeUpdate(b.toString());
                b = new SqlBuilder("QcmZgJugdeApplyDAL.setJudgeTime");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, processCode, ""});
                st.executeUpdate(b.toString());
                if(!oldJudgeResult.equals("40740709")  && !oldJudgeResult.equals("40740704")){
                	//修改放行信息
//                    b = new SqlBuilder("QcmZgJugdeApplyDAL.setInstancyFlag");
//                    b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, processCode, "0" });
//                    st.executeUpdate(b.toString());
                    b = new SqlBuilder("QcmZgJugdeApplyDAL.setAuditResult");
                    b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
                    		processCode, "", "", "0" });
                    st.executeUpdate(b.toString());
                    //更新申请放行记录
                    b = new SqlBuilder("JdgQcmBcPassApplyDAL.setValidflagByBatchNo");
                    b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, judgeApplyCode, "0", "0", user });
                    st.executeUpdate(b.toString());
                    b = new SqlBuilder("JdgQcmBcPassApplyDAL.setValidflagByBatchNo");
                    b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, judgeApplyCode, "1", "0", user });
                    st.executeUpdate(b.toString());
                }
            }
            
            //更新判定记录表
            b = new SqlBuilder("JdgQcmBcJudge.updateValid");
            b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, judgeApplyCode, "0" });
            st.executeUpdate(b.toString());

			//更新判定记录表
			b = new SqlBuilder("JdgQcmZcJudge.updateValid");
			b.Fill(new String[]{ judgeStoveNo, batchNo, judgeApplyCode, "0" });
			st.executeUpdate(b.toString());
            //if(!judgeApply.getIsAllScrap().equals("5")&& !oldJudgeResult.equals("40740709") && !oldJudgeResult.equals("40740704")){
            if( !oldJudgeResult.equals("40740704")){
            	if(!"F".equals(processCode) || !oldJudgeResult.equals("40740709")){
            		if(!judgeApply.getIsAllScrap().equals("5")){
            			//删除炉计划
                        if(processCode.equals("D")){
                        	PlanFurnProduction.deletePlnC(judgeApplyCode, judgeStoveNo, user, con, batchNo,"1");
                        }else if(processCode.equals("E")){
                        	PlanFurnProduction.deletePlnCD(judgeApplyCode, judgeStoveNo, user, con, batchNo);
                        }else if(processCode.equals("F")){
                        	PlanFurnProduction.deletePlnCF(judgeApplyCode, judgeStoveNo, user, con, batchNo);
                        }else if(processCode.equals("G")){
                            PlanFurnProduction.deletePlnCG(judgeApplyCode, judgeStoveNo, user, con, batchNo);//加工判定
                        }
            		}
                    //删除入库表
                    b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
                    b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
                    ArrayList<com.steering.pss.ydm.entity.QcmZgJugdeApplyEntity> zgJudges = EntityTool.getEntitysBySqlNoClsCon(
                    		b.toString(), con, com.steering.pss.ydm.entity.QcmZgJugdeApplyEntity.class);

                    // 删除财务中间表
					for (com.steering.pss.ydm.entity.QcmZgJugdeApplyEntity zgJudge : zgJudges) {
						String getBcInListSql = CoreXmlSqlParsersFactory.getSql("FrmBcIqInList.getFmisBcInlist");
						getBcInListSql = EntityTool.fillSqlByEntity(getBcInListSql, zgJudge);
						YdmBcInlistEntity ydmBcInlistEntity = EntityTool.getEntityBySqlNoClsCon(
								getBcInListSql, con, YdmBcInlistEntity.class);
						if(ydmBcInlistEntity != null){
							con.rollback();
							cro.setV_errMsg("炉号："+ydmBcInlistEntity.getJudgeStoveNo()+"批号："+ydmBcInlistEntity.getBatchNo()+"组号："+ydmBcInlistEntity.getBatchGroudNo()+"已被财务系统接收，不能撤销判定！请联系财务系统相关人员！");
							return cro;
						}
						String delBcInListSql = CoreXmlSqlParsersFactory.getSql("FrmBcIqInList.delFmisBcInlist");
						delBcInListSql = EntityTool.fillSqlByEntity(delBcInListSql, zgJudge);
						st.executeUpdate(delBcInListSql);
					}
            		FrmBcIqInList bcIqInList = new FrmBcIqInList();
            		bcIqInList.cancelInsertBcInList(con, zgJudges);
            	}
            }
            
            //更新管坯材料表
//            String belongCode = "";
//            String belongName = "";
//            if(judgeApply.getPlineCode().equals("C002")){
//            	belongCode = "002001020004";
//            	belongName = "1#炼钢";
//            }else if(judgeApply.getPlineCode().equals("C004")){
//            	belongCode = "002001020006";
//            	belongName = "2#炼钢";
//            }else if(judgeApply.getPlineCode().equals("C005")){
//            	belongCode = "002001020008";
//            	belongName = "2#炼快锻";
//            }else if(judgeApply.getPlineCode().equals("C007")){
//            	belongCode = "002001020009";
//            	belongName = "3#炼钢";
//            }
            
            b = new SqlBuilder("JdgMatBcQcmTrack.setJudgeResult");
            b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, judgeApply.getJugdeApplyCode(),
            		"",
            		"", "",  "", "", "", "", "", "", "", "", "", "",
            		"", "", "", "", "", "", "", "", "", "", "", "",
            		"", "", "", "", "", ""});
            st.executeUpdate(b.toString());
            
            String matStatus = "";
            if(judgeApply.getTarget().equals("A")){
            	matStatus = "80150201";
            }else{
            	matStatus = "80150101";
            }
            //*********************更新材料表
            b = new SqlBuilder("JdgMatBcM.updateJudgeResult");
            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
            		"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
            		"", "", "", "", ""});
            st.executeUpdate(b.toString());
            //更新材料历史表
            b = new SqlBuilder("JdgMatBcBackup.updateJudgeResult");
            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
            		"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
            		"", "", "", "", ""});
            st.executeUpdate(b.toString());
            //if(!oldJudgeResult.equals("40740709") && !oldJudgeResult.equals("40740704")){
            //2020-06-02取消判定不合格不改材料状态限制
            if(!oldJudgeResult.equals("40740709") ){
            	//更新材料状态、入库标志
                b = new SqlBuilder("JdgMatBcM.updateInstockMatStatus");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
                		matStatus, "0" });
                st.executeUpdate(b.toString());
                //更新材料状态、入库标志
                b = new SqlBuilder("JdgMatBcBackup.updateInstockMatStatus");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo,
                		matStatus, "0" });
                st.executeUpdate(b.toString());
            }
            
            if(!oldJudgeResult.equals("40740709") && !oldJudgeResult.equals("40740704")){
            	//*********************更新材料表所属权
                b = new SqlBuilder("JdgMatBcM.updateBelong");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, judgeApply.getBelongCode(), judgeApply.getBelongName() });
                st.executeUpdate(b.toString());
                
                //更新材料历史表所属权
                b = new SqlBuilder("JdgMatBcBackup.updateBelong");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, judgeApply.getBelongCode(), judgeApply.getBelongName() });
                st.executeUpdate(b.toString());
                
                b = new SqlBuilder("JdgMatBcM.updateInstancy");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, "0" });
                st.executeUpdate(b.toString());
                
                //更新材料历史表
                b = new SqlBuilder("JdgMatBcBackup.updateInstancy");
                b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, "0" });
                st.executeUpdate(b.toString());
            }
            
            //取消关闭炉计划
            PlanFurnProduction.productClose(judgeStoveNo, con, processCode, "0");

            //更新接箍
			CouplingMatMEntity couplingMatM = new CouplingMatMEntity();
			couplingMatM.setJudgeResult("");
			couplingMatM.setJudgeResultCode("");
			couplingMatM.setJudgeMaker("");
			couplingMatM.setJudgeStoveNo(judgeApply.getJudgeStoveNo());
			couplingMatM.setBatchNo(judgeApply.getBatchNo());
			couplingMatM.setDeterNo(judgeApply.getJugdeApplyCode());
			couplingMatM.setWoId(judgeApply.getProOrderId());
			String setJgJudgeInfo = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatM.setJudgeInfo");
			setJgJudgeInfo = EntityTool.fillSqlByEntity(setJgJudgeInfo, couplingMatM);
			st.executeUpdate(setJgJudgeInfo);
			couplingMatM.setBelongCode(judgeApply.getBelongCode());
			couplingMatM.setBelongName(judgeApply.getBelongName());
			String setBelong = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatM.setBelong");
			setBelong = EntityTool.fillSqlByEntity(setBelong, couplingMatM);
			st.executeUpdate(setBelong);
			CouplingMatButtressEntity couplingMatBut = new CouplingMatButtressEntity();
			if(judgeApply.getTarget().equals("A")){
				couplingMatBut.setMatStatus("80150201");
			}else{
				couplingMatBut.setMatStatus("80150101");
			}
			String setJgMatStatus = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatButtress.setMatStatus");
			setJgMatStatus = EntityTool.fillSqlByEntity(setJgMatStatus, couplingMatM);
			setJgMatStatus = EntityTool.fillSqlByEntity(setJgMatStatus, couplingMatBut);
			st.executeUpdate(setJgMatStatus);


			//crm同步
			if(oldJudgeResult.equals("40740709")||oldJudgeResult.equals("40740701")){
				// 通过判定单号，判定炉号查询判定信息
				List<com.steering.pss.plnsaleord.stove.entity.QcmZgJugdeApplyEntity> qcmApp = PlanFurnProduction.getQcmZgApp(con, judgeApplyCode,
						judgeStoveNo, processCode, batchNo);
				CrmOrderProduceService crmOrderProduceService = new CrmOrderProduceService();
				for (com.steering.pss.plnsaleord.stove.entity.QcmZgJugdeApplyEntity qcmGp : qcmApp) {
					crmOrderProduceService.insertJudgeZGCrmOrderProduce(con, qcmGp, processCode,false);
				}
			}

            con.commit();
            return cro;
    	}catch(Exception ex){
    		try {
				con.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
    		cro.setV_errMsg("程序异常:" + ex.getMessage());
    		return cro;
    	}
    	finally{
        	
    		if(st != null)
    		{
    			try {
					st.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    		if(con != null){
    			try {
    				con.close();
    			} catch (SQLException e) {
    				e.printStackTrace();
    			}
    		}
    	}
    }
    
    /**
     * 更新备注
     * @param parms
     * @return
     */
    public CoreReturnObject UpdateMemo(ArrayList<String[]> parms){
    	ArrayList<String> sqllist = new ArrayList<String>();
    	SqlBuilder b;
    	for(String[] parm : parms){
    		b = new SqlBuilder("JdgQcmBcJudge.updateMemo");
    		b.Fill(new String[]{ parm[1], parm[2], parm[3], parm[4] });
    		sqllist.add(b.toString());
    		
    		b = new SqlBuilder("QcmZgJugdeApplyDAL.udpateJudgeMemo");
    		b.Fill(new String[]{ parm[0], parm[1], parm[2], parm[3], parm[4], parm[5] });
    		sqllist.add(b.toString());
    	}
    	
    	return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }
    
    /**
     * 放行申请
     * @param parms
     * @param processCode
     * @param user
     * @param unit
     * @param memo
     * @param passType
     * @return
     */
    public CoreReturnObject passApply(ArrayList<String[]> parms, String processCode,
    		String user, String unit, String unitDesc, String memo, String passType){
    	Connection con = null;
    	Statement st = null;
    	CoreReturnObject cro = new CoreReturnObject();
    	try{
        	SqlBuilder b;
        	con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
        	con.setAutoCommit(false);
        	st = con.createStatement();
        	for(String[]  parm : parms){
        		String judgeApplyCode = parm[0];
        		String judgeStoveNo = parm[1];
        		String batchNo = parm[2];
        		b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
        		b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
        		
        		QcmZgJugdeApplyEntity zgJudgeApply = EntityTool.getEntityBySqlNoClsCon(
        				b.toString(), con, QcmZgJugdeApplyEntity.class);
        		if(passType.equals("0")){
        			if(!zgJudgeApply.getJudgeResultCode().equals("40740704") && !zgJudgeApply.getJudgeResultCode().equals("40740708")
        					&& !zgJudgeApply.getJudgeResultCode().equals("40740707")){
            			cro.setV_errMsg("只有判定不合格的记录，才能申请质量放行！");
            			return cro;
            		}
        		}else{
        			if(!zgJudgeApply.getJudgeResultCode().equals("")){
            			cro.setV_errMsg("已判定的记录不能申请紧急放行！");
            			return cro;
            		}
        		}
        		
        		ResultSet rs = st.executeQuery(CoreXmlSqlParsersFactory.getSql(
        				"JdgQcmBcPassApplyDAL.getMaxPk"));
        		String passApplyNo = "";
        		if(rs.next()){
        			passApplyNo = rs.getString(1);
        			rs.close();
        		}
        		
        		b = new SqlBuilder("JdgQcmBcPassApplyDAL.GetApplyCnt");
        		b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo, processCode, passType });
        		ResultSet rsBcApplyCnt = st.executeQuery(b.toString());
        		int gpApplyCnt = 0;
        		if(rsBcApplyCnt.next())
        		{
        			gpApplyCnt = rsBcApplyCnt.getInt(1);
        		}
        		if(gpApplyCnt > 0) //如果有放行申请单，则不重复生成。
        		{
        			continue;
        		}
                
                //如果存在有效的放行单，作废掉。 （紧急放行后可以操作质量放行。）
                b = new SqlBuilder("JdgQcmBcPassApplyDAL.setValidflagByBatchNo");
	            b.Fill(new String[]{ judgeStoveNo, batchNo, processCode, judgeApplyCode, passType, "0", user });
	            st.executeUpdate(b.toString());
        		
        		b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
        		b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
        		List<QcmZgJugdeApplyEntity> zgJudgeApplys = EntityTool.getEntitysBySqlNoClsCon(
        				b.toString(), con, QcmZgJugdeApplyEntity.class);
        		for(QcmZgJugdeApplyEntity zgJudgeApplySub : zgJudgeApplys){
        			b = new SqlBuilder("JdgQcmBcPassApplyDAL.GetMaxSeq");
        			b.Fill(new String[]{ passApplyNo });
        			ResultSet rsMaxSeq = st.executeQuery(b.toString());
        			String passApplySeq = "";
        			if(rsMaxSeq.next()){
        				passApplySeq = rsMaxSeq.getString(1);
        			}
        			String sql = CoreXmlSqlParsersFactory.getSql("JdgQcmBcPassApplyDAL.Insert");
        			zgJudgeApplySub.setMemo(memo);
            		sql = EntityTool.fillSqlByEntity(sql, zgJudgeApplySub);
            		sql = StringTool.ReplaceAll(sql, "#PASS_APPLY_NAME#", user);
            		sql = StringTool.ReplaceAll(sql, "#PASS_APPLY_NO#", passApplyNo);
            		sql = StringTool.ReplaceAll(sql, "#PASS_APPLY_SEQ#", passApplySeq);
            		sql = StringTool.ReplaceAll(sql, "#UNIT_CODE#", unit);
            		sql = StringTool.ReplaceAll(sql, "#TYPE#", passType);
            		sql = StringTool.ReplaceAll(sql, "#PRO_PLAN_ID#", zgJudgeApplySub.getProOrderId());
            		sql = StringTool.ReplaceAll(sql, "#UNIT_DESC#", unitDesc);
            		st.executeUpdate(sql);
        		}

				//查询制造商
				b = new SqlBuilder("QcmZgJugdeApply.querySupplyUnit");
				b.Fill(parm[0]);
				ResultSet rsMaxSeq2 = st.executeQuery(b.toString());
				String supplyUnit = "";
				String seamArea ="";
				if(rsMaxSeq2.next()){
					supplyUnit = rsMaxSeq2.getString(1);
				}
				if(supplyUnit==null)
					seamArea = "0";
				else if(!supplyUnit.equals("") && supplyUnit.equals("120501")){
					seamArea = "0";
				}else if(!supplyUnit.equals("") && supplyUnit.equals("120504")){
					seamArea = "1";
				}
        		b = new SqlBuilder("JdgQcmBcPassConfig.getByJudgeResultToSu");
				b.Fill(new String[]{ zgJudgeApply.getJudgeResultCode(), processCode,seamArea });
				ArrayList<QcmBcPassConfigEntity> passConfigs = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmBcPassConfigEntity.class);
				if(passConfigs.size() == 0){
					con.rollback();
					cro.setV_errMsg("没有找到可用的评审流程，请配置评审流程！");
        			return cro;
				}
				int passFlowCnt = 0;
				for(QcmBcPassConfigEntity passConfig : passConfigs){
					b = new SqlBuilder("JdgQcmBcPassFlow.insert");
					String ctrAuditStep = "0";
					if(passFlowCnt == 0){
						ctrAuditStep = "1";
					}
					b.Fill(new String[]{ passApplyNo, passConfig.getAuditStep(),
							passConfig.getAuditUnit(), ctrAuditStep });
					st.executeUpdate(b.toString());
					passFlowCnt++;
				}
        	}
        	con.commit();
        	return cro;
    	}catch(Exception ex){
    		try {
				con.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
    		cro.setV_errMsg(ex.getMessage());
    		return cro;
    	}
    	finally{
    		if(st != null)
    		{
    			try {
					st.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    		try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
    	}
    }
    
    /**
     * 获取基础信息
     * @param baseCode
     * @param con
     * @return
     */
    private String getComBaseName(String baseCode, Connection con){
    	SqlBuilder b = new SqlBuilder("JdgComBaseInfo.QueryBaseName");
    	b.Fill(new String[]{ baseCode });
    	
    	ComBaseInfoEntity baseInfo = EntityTool.getEntityBySqlNoClsCon(
    			b.toString(), con, ComBaseInfoEntity.class);
    	if(baseInfo == null){
			return "";
		}else{
			return baseInfo.getBasename();
		}
    }
    
    /**
     * 申请复取样
     * @param judgeApplyCode
     * @param judgeStoveNo
     * @param batchNo
     * @return
     */
    public CoreReturnObject applyRepeatSpline(String judgeApplyCode, String judgeStoveNo, String batchNo,
    		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("QcmZgJugdeApplyDAL.QueryByBatchNo");
            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
            QcmZgJugdeApplyEntity zgJudgeApply = EntityTool.getEntityBySqlNoClsCon(
            		b.toString(), qcmCon, QcmZgJugdeApplyEntity.class);
            
            //获取成分判定结果
            b = new SqlBuilder("JdgQcmBcChemResult.getJudgeFail");
            b.Fill(new String[]{ zgJudgeApply.getJudgeStoveNo(), zgJudgeApply.getBatchNo(),
            		zgJudgeApply.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(chemResult.getChemType().equals("A")){
            		b = new SqlBuilder("JdgCheckConsignNoQualified.insert");
            		String isRepeat = "0";
            		if(chemResult.getSampleId().contains("F") || chemResult.getSampleId().contains("Z")){
            			isRepeat = "1";
            		}
                	b.Fill(new String[]{ chemResult.getSampleId(), chemResult.getSampleNo(),
                			"HX", "化学", "HX", "化学", chemResult.getChemCode(), chemResult.getChemName(),
                			chemResult.getJfQualified(), chemResult.getNkQualified(), chemResult.getLotNo(),
                			chemResult.getJudgeStoveNo(), chemResult.getBatchNo(), "0", chemResult.getPlineCode(),
                			user, isRepeat });
                	jhySt.executeUpdate(b.toString());
            	}else{//复合元素
            		ArrayList<String> chems = new ArrayList<String>();
            		String chemFormula = chemResult.getChemFormula();
            		for(ComBaseChemEntity baseChem : baseChems){
            			if(chemFormula.contains(baseChem.getChemName())){
            				chemFormula = chemFormula.replaceAll(baseChem.getChemName(), "");
            				chems.add(baseChem.getChemName());
            				break;
            			}
            		}
            		
            		for(String chem : chems){
            			b = new SqlBuilder("JdgQcmBcChemResult.getJudgeFailByChemName");
                        b.Fill(new String[]{ zgJudgeApply.getJudgeStoveNo(), zgJudgeApply.getBatchNo(),
                        		zgJudgeApply.getProcessCode(), chem });
                        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";
                    		}
                        	b.Fill(new String[]{ chemResult2.getSampleId(), chemResult2.getSampleNo(),
                        			"HX", "化学", "HX", "化学", chemResult2.getChemName(), chemResult2.getChemName(),
                        			chemResult2.getJfQualified(), chemResult2.getNkQualified(), chemResult2.getLotNo(),
                        			chemResult2.getJudgeStoveNo(), chemResult2.getBatchNo(), "0", chemResult2.getPlineCode(),
                        			user, isRepeat });
                        	jhySt.executeUpdate(b.toString());
                        }
                    }
            	}
            }
            
            //获取理化判定结果
            b = new SqlBuilder("QcmBcPhyresultDAL.getJudgeFail");
            b.Fill(new String[]{ zgJudgeApply.getJudgeStoveNo(), zgJudgeApply.getBatchNo(),
            		zgJudgeApply.getProcessCode() });
            ArrayList<QcmBcPhyresultEntity> phyResults = EntityTool.getEntitysBySqlNoClsCon(
            		b.toString(), qcmCon, QcmBcPhyresultEntity.class);
            for(QcmBcPhyresultEntity phyResult : phyResults){
            	b = new SqlBuilder("JdgCheckConsignNoQualified.insert");
            	String isRepeat = "0";
        		if(phyResult.getSampleId().contains("F") || phyResult.getSampleId().contains("Z")){
        			isRepeat = "1";
        		}
            	b.Fill(new String[]{ phyResult.getSampleId(), phyResult.getSampleNo(),
            			phyResult.getPhyCodeMin(), phyResult.getPhyNameMin(), phyResult.getPhyCodeMax(),
            			phyResult.getPhyNameMax(), phyResult.getPhyCode(), phyResult.getPhyName(),
            			phyResult.getJfQualified(), phyResult.getNkQualified(), phyResult.getLotNo(),
            			phyResult.getJudgeStoveNo(), phyResult.getBatchNo(), "0", phyResult.getPlineCode(),
            			user, isRepeat });
            	jhySt.executeUpdate(b.toString());
            }
            
            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 judgeStoveNo
     * @param batchNo
     * @param user
     * @return
     */
    public CoreReturnObject deleteRepeatSpline(String checkNo, String judgeStoveNo,
    		String batchNo, String user){
    	Connection jhyCon = null;
    	Statement jhySt = null;
    	CoreReturnObject cro = new CoreReturnObject();
    	try{
    		jhyCon = this.getDao("JhyDao").getConnection();
    		jhyCon.setAutoCommit(false);
    		jhySt = jhyCon.createStatement();
    		
    		SqlBuilder b = new SqlBuilder("JdgCheckConsignNoQualified.deleteCheckNoQualified");
    		b.Fill(new String[]{ checkNo, judgeStoveNo, batchNo });
    		jhySt.executeUpdate(b.toString());
    		
            jhyCon.commit();
            return cro;
    	}catch(Exception ex){
    		try {
    			jhyCon.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
    		
    		cro.setV_errMsg(ex.getMessage());
    		return cro;
    	}finally{
    		if(jhySt != null){
    			try {
					jhySt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    		if(jhyCon != null){
    			try {
					jhyCon.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
    		}
    	}
    }
    
    /**
     * 获取复取样数
     * @param lotNo
     * @param judgeStoveNo
     * @param batchNo
     * @param isSamples
     * @return
     */
    public CoreReturnObject getCheckNoQualifiedCnt(String lotNo, String judgeStoveNo,
    		String batchNo, String[] isSamples){
    	SqlBuilder b = new SqlBuilder("JdgCheckConsignNoQualified.getCount");
    	b.Fill(new Object[]{ lotNo, judgeStoveNo, batchNo, isSamples });
    	return this.getDao("JhyDao").ExcuteSortResultByQuery(b.toString());
//    	Connection jhyCon = null;
//    	Statement st = null;
//    	CoreReturnObject cro = new CoreReturnObject();
//    	try{
//    		jhyCon = this.getDao(CoreConstantData.sysbeanstr).getConnection();
//    		st = jhyCon.createStatement();
//        	
//        	SqlBuilder b = new SqlBuilder("JdgCheckConsignNoQualified.getCount");
//        	b.Fill(new Object[]{ lotNo, judgeStoveNo, batchNo, isSamples });
//        	
//    	}catch(Exception ex){
//    		cro.setV_errMsg("程序处理失败! " + ex.getMessage());
//    		return cro;
//    	}finally{
//    		try {
//				st.close();
//			} catch (SQLException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//    		try {
//				jhyCon.close();
//			} catch (SQLException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//    	}
    }
    
    public CoreReturnObject get126PhyDetail(String applyCode, String judgeStoveNo, String batchNo){
    	Connection con126 = null;
    	Connection con = null;
    	CoreReturnObject cro = new CoreReturnObject();
    	try{
    		con126 = this.getDao("JhyDao").getConnection();
    		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);
    		String ordLnPk = "";
    		if(apply.getIsAllScrap().equals("4")){
    			b = new SqlBuilder("JdgSlmOrderLineDelivery.getOrdLnPkByDlyPk");
    			b.Fill(new String[]{ apply.getOrdLnDlyPk() });
    			PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
    			ordLnPk = plnSaleord.getOrdLnPk();
    		}else{
    			b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
    			b.Fill(new String[]{ apply.getOrdLnDlyPk() });
    			PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
    			ordLnPk = plnSaleord.getOrdLnPk();
    		}
    		b = new SqlBuilder("JdgCraftOrdDesignStdPicSmp.getRate");
    		b.Fill(new String[]{ ordLnPk, apply.getCraftSeq(), apply.getIndexSeq(),
    				apply.getProcessCode(), apply.getPic() });
    		ArrayList<CraftOrdDesignStdPicSmpEntity> smps = EntityTool.getEntitysBySqlNoClsCon(
    				b.toString(), con, CraftOrdDesignStdPicSmpEntity.class);
    		ArrayList<PipeCheckconsignPhydetailEntity> jhyPhys = new ArrayList<PipeCheckconsignPhydetailEntity>();
    		for(CraftOrdDesignStdPicSmpEntity smp : smps){
    			if(smp.getPhyCodeMin().equals("C0030") || smp.getPhyCodeMin().equals("C0031") ||
    					smp.getPhyCodeMin().equals("C0032") || smp.getPhyCodeMin().equals("C0033")
    					|| smp.getPhyCodeMin().equals("C0133") || smp.getPhyCodeMin().equals("C0147")
    					|| smp.getPhyCodeMin().equals("C0007") || smp.getPhyCodeMin().equals("C0061")
    					|| smp.getPhyCodeMin().equals("C0146") || smp.getPhyCodeMin().equals("C0148")
    					|| smp.getPhyCodeMin().equals("C0150") || smp.getPhyCodeMin().equals("C0065")){
    				if(smp.getRate().equals("408601")){//生产批
    					b = new SqlBuilder("JdgPipeCheckConsignPhyDetail.getByPhyMinLotNo");
    					b.Fill(new String[]{ apply.getLotNo(), apply.getLotNoGroup(), apply.getProcessCode(), smp.getPhyCodeMin() });
    				}else if(smp.getRate().equals("408603")){//炉
    					b = new SqlBuilder("JdgPipeCheckConsignPhyDetail.getByPhyMinJudgeStoveNo");
    					b.Fill(new String[]{ judgeStoveNo, apply.getProcessCode(), smp.getPhyCodeMin() });
    				}else{//性能批
    					b = new SqlBuilder("JdgPipeCheckConsignPhyDetail.getByPhyMinBatchNo");
    					b.Fill(new String[]{ judgeStoveNo, batchNo, apply.getProcessCode(), smp.getPhyCodeMin() });
    				}
    				ArrayList<PipeCheckconsignPhydetailEntity> tmpJhyPhys = EntityTool.getEntitysBySqlNoClsCon(
    						b.toString(), con126, PipeCheckconsignPhydetailEntity.class);
    				for(PipeCheckconsignPhydetailEntity tmpJhyPhy : tmpJhyPhys){
    					jhyPhys.add(tmpJhyPhy);
    				}
    			}
    		}

    		//首日检
    		b = new SqlBuilder("JdgPipeCheckConsignPhyDetail.getSscByOrderNo");
			b.Fill(new String[]{ apply.getProOrderNo(), apply.getPlineCode(), apply.getProcessCode() });
			ArrayList<PipeCheckconsignPhydetailEntity> tmpJhyPhys = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con126, PipeCheckconsignPhydetailEntity.class);
			for(PipeCheckconsignPhydetailEntity tmpJhyPhy : tmpJhyPhys){
				jhyPhys.add(tmpJhyPhy);
			}
			
			cro.setResult(EntityTool.getGsonByEntity(jhyPhys));
			return cro;
    	}catch(Exception ex){
    		cro.setV_errMsg(ex.getMessage());
    		return cro;
    	}finally{
    		try {
				con126.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    		try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}
    }

	/**
	 * 更新自动判定标识
	 * @return
	 */
	public CoreReturnObject setAutoJudge(String judgeApplyCode, String judgeStoveNo, String batchNo){
		SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.setAutoJudge");
		b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });


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

	/**
	 * 复制轧管检验数据到热处理、墩拔扩
	 * @param applyCode
	 * @param judgeStoveNo
	 * @param batchNo
	 * @return
	 */
	public CoreReturnObject CopyZgJhyData(String applyCode, String judgeStoveNo, String batchNo,String processCode) {
		Connection con = null;
		Statement st = null;
		CoreReturnObject cro = new CoreReturnObject();
		try{
			SqlBuilder b;
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			st = con.createStatement();
			if(processCode==null)
				processCode="F";
			if(!processCode.equals("E"))
				processCode="F";
			b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo", applyCode, judgeStoveNo, batchNo);
			QcmZgJugdeApplyEntity curApply = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, QcmZgJugdeApplyEntity.class);
			HashMap<String, QcmZgJugdeApplyEntity> applys = BllZcColligateJudge.getAllJudgeApply(
					applyCode, judgeStoveNo, batchNo, curApply.getProcessCode(), curApply.getHeatPlanNo(),
					null, null, con);
			QcmZgJugdeApplyEntity rclApply = applys.get(processCode);
			if(rclApply == null) return cro;
			QcmZgJugdeApplyEntity zgApply = applys.get("D");
			if(zgApply == null) return cro;
			//查询轧管委托一层表
			b = new SqlBuilder("JdgQcmZcCheckconsign.getOriginalByBatchNo",
					new String[]{ zgApply.getJudgeStoveNo(), zgApply.getBatchNo(), "0", "D"});
			List<QcmZcCheckconsignEntity> zgConsigns = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con, QcmZcCheckconsignEntity.class);
			for(QcmZcCheckconsignEntity zgConsign : zgConsigns){
				String oldCheckNo = zgConsign.getCheckNo();
				String oldJudgeStoveNo = zgConsign.getJudgeStoveNo();
				String oldBatchNo = zgConsign.getBatchNo();
				String oldProcessCode = zgConsign.getProcessCode();
				String checkNo = GetCopyCheckNo(zgConsign, oldCheckNo, "D", b, con);
				zgConsign.setCheckNo(checkNo);
				zgConsign.setJudgeStoveNo(rclApply.getJudgeStoveNo());
				zgConsign.setBatchNo(rclApply.getBatchNo());
				zgConsign.setLotNo(rclApply.getLotNo());
				zgConsign.setLotNoGroup(rclApply.getLotNoGroup());
				zgConsign.setPlineCode(rclApply.getPlineCode());
				zgConsign.setPlineName(rclApply.getPlineName());
				zgConsign.setProcessCode(rclApply.getProcessCode());
				zgConsign.setOrdLnDlyPk(rclApply.getOrdLnDlyPk());
				zgConsign.setCraftSeq(rclApply.getCraftSeq());
				zgConsign.setIndexSeq(rclApply.getIndexSeq());
				zgConsign.setCic(rclApply.getCic());
				if(rclApply.getPic().equals(""))
					zgConsign.setPic(zgApply.getPic());
				else
					zgConsign.setPic(rclApply.getPic());
				zgConsign.setCrafNo(rclApply.getCrafNo());
				zgConsign.setJudgeResultCode("40740701");
				//zgConsign.setJudgeStoveNo();
				//删除委托一层表
				b = new SqlBuilder("JdgQcmZcCheckconsign.deleteByBatchNoOrdLnPkCheckNo1", checkNo);
				st.executeUpdate(b.toString());
				String insertConsign = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckconsign.insert");
				insertConsign = EntityTool.fillSqlByEntity(insertConsign, zgConsign);
				st.executeUpdate(insertConsign);

				//查询委托二层表
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getByBatchNo",
						oldCheckNo, oldBatchNo);
				List<QcmZcCheckconsignDetailEntity> zgDetails = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmZcCheckconsignDetailEntity.class);
				//删除二层
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.deleteByBatchNoOrdLnPkCheckNo1", checkNo);
				st.executeUpdate(b.toString());
				for(QcmZcCheckconsignDetailEntity zgDetail : zgDetails){
					zgDetail.setCheckNo(checkNo);
					zgDetail.setBatchNo(rclApply.getBatchNo());
					String insertDetail = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckConsignDetail.insert");
					insertDetail = EntityTool.fillSqlByEntity(insertDetail, zgDetail);
					st.executeUpdate(insertDetail);
				}

				//查询检验表
				b = new SqlBuilder("QcmJhyElementsDAL.queryAllByCheckNo",
						new String[]{ oldCheckNo, oldJudgeStoveNo, oldBatchNo, oldProcessCode });
				List<QcmJhyElementsEntity> jhyChems = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmJhyElementsEntity.class);
				//删除成分检验
				b = new SqlBuilder("QcmJhyElementsDAL.deleteByBathNoOrdLnDlyPkCheckNo1", checkNo);
				st.executeUpdate(b.toString());
				for(QcmJhyElementsEntity jhyChem : jhyChems){
					jhyChem.setSampleId(checkNo);
					jhyChem.setJudgeStoveNo(rclApply.getJudgeStoveNo());
					jhyChem.setBatchNo(rclApply.getBatchNo());
					jhyChem.setPlineCode(rclApply.getPlineCode());
					jhyChem.setAssayno(checkNo + "_" + jhyChem.getSampleNo() + "_C");
					String insertJhyChem = CoreXmlSqlParsersFactory.getSql("QcmJhyElementsDAL.insertQcmJhyElements");
					insertJhyChem = EntityTool.fillSqlByEntity(insertJhyChem, jhyChem);
					st.executeUpdate(insertJhyChem);
				}
				b = new SqlBuilder("QcmJhyPhyresultDAL.QueryByCheckNoBatchNo",
						new String[]{ oldJudgeStoveNo, oldBatchNo, oldCheckNo, oldProcessCode });
				List<QcmJhyPhyresultEntity> jhyPhys = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmJhyPhyresultEntity.class);
				//删除理化检验
				b = new SqlBuilder("QcmJhyPhyresultDAL.deleteByBatchNoOrdLnDlyPkCheckNo1", checkNo);
				st.executeUpdate(b.toString());
				for(QcmJhyPhyresultEntity jhyPhy : jhyPhys){
					jhyPhy.setSampleId(checkNo);
					jhyPhy.setJudgeStoveNo(rclApply.getJudgeStoveNo());
					jhyPhy.setBatchNo(rclApply.getBatchNo());
					jhyPhy.setLotNo(rclApply.getLotNo());
					jhyPhy.setLotNoGroup(rclApply.getLotNoGroup());
					jhyPhy.setPlineCode(rclApply.getPlineCode());
					String insertJhyPhy = CoreXmlSqlParsersFactory.getSql("QcmJhyPhyresultDAL.Insert");
					insertJhyPhy = EntityTool.fillSqlByEntity(insertJhyPhy, jhyPhy);
					st.executeUpdate(insertJhyPhy);
				}
			}

			con.commit();
		}catch(Exception ex){
			try {
				con.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			if(st != null){
				try {
					st.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(con != null){
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			cro.setV_errMsg(ex.getMessage());
		}

		return cro;
	}

	/**
	 * 复制热处理检验数据到轧管、墩拔扩
	 * @param applyCode
	 * @param judgeStoveNo
	 * @param batchNo
	 * @return
	 */
	public CoreReturnObject CopyRclJhyData(String applyCode, String judgeStoveNo, String batchNo,String processCode) {
		Connection con = null;
		Statement st = null;
		CoreReturnObject cro = new CoreReturnObject();
		try{
			SqlBuilder b;
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			st = con.createStatement();
			
			if(processCode==null)
				processCode="D";
			if(!processCode.equals("E"))
				processCode="D";
			//b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo", applyCode, judgeStoveNo, batchNo);
			//复制轧管数据不按批号复制 xml中复制原语句By改为No
			b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryNoBatchNo", applyCode, judgeStoveNo);
			QcmZgJugdeApplyEntity curApply = EntityTool.getEntityBySqlNoClsCon(
					b.toString(), con, QcmZgJugdeApplyEntity.class);
			HashMap<String, QcmZgJugdeApplyEntity> applys = BllZcColligateJudge.getAllJudgeApplyNoBatch(
					applyCode, judgeStoveNo,  curApply.getProcessCode(), curApply.getHeatPlanNo(),
					null, null, con);
			QcmZgJugdeApplyEntity rclApply = null;
			if(applys.containsKey("F")){
				rclApply = applys.get("F");
			}else{
				b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryNoBatchNo2",
						judgeStoveNo, "F", "");
				rclApply = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, QcmZgJugdeApplyEntity.class);
			}
			if(rclApply == null) return cro;
			QcmZgJugdeApplyEntity zgApply = applys.get(processCode);
			if(zgApply == null) return cro;
			//查询轧管委托一层表
			b = new SqlBuilder("JdgQcmZcCheckconsign.getOriginalNoBatchNo",
					new String[]{ rclApply.getJudgeStoveNo(), "0", "F" });
			List<QcmZcCheckconsignEntity> rclConsigns = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con, QcmZcCheckconsignEntity.class);
			for(QcmZcCheckconsignEntity rclConsign : rclConsigns){
				String oldCheckNo = rclConsign.getCheckNo();
				String oldJudgeStoveNo = rclConsign.getJudgeStoveNo();
				String oldBatchNo = rclConsign.getBatchNo();
				String oldProcessCode = rclConsign.getProcessCode();
				String checkNo = GetCopyCheckNo(rclConsign, oldCheckNo, "F", b, con);
				rclConsign.setCheckNo(checkNo);
				rclConsign.setJudgeStoveNo(zgApply.getJudgeStoveNo());
				rclConsign.setBatchNo(zgApply.getBatchNo());
				rclConsign.setLotNo(zgApply.getLotNo());
				rclConsign.setLotNoGroup(zgApply.getLotNoGroup());
				//rclConsign.setPlineCode(zgApply.getPlineCode());
				//rclConsign.setPlineName(zgApply.getPlineName());
                if(zgApply.getPlineCode().equals("")){
                    rclConsign.setPlineCode("C017");
                    rclConsign.setPlineName("460机组");
                }else{
                    rclConsign.setPlineCode(zgApply.getPlineCode());
                    rclConsign.setPlineName(zgApply.getPlineName());
                }
				rclConsign.setProcessCode(zgApply.getProcessCode());
				rclConsign.setOrdLnDlyPk(curApply.getOrdLnDlyPk());
				rclConsign.setCraftSeq(curApply.getCraftSeq());
				rclConsign.setIndexSeq(curApply.getIndexSeq());
				if("".equals(curApply.getCic()))
					rclConsign.setCic(rclConsign.getCic());
				else
					rclConsign.setCic(curApply.getCic());
				rclConsign.setPic(rclConsign.getPic());
				if(curApply.getPic().equals("")){
					String ordLnPk = BllZcColligateJudge.getOrdLnPkByDlyPk(curApply.getOrdLnDlyPk(), b, con);
					b = new SqlBuilder("CraftOrdDesignStdPic.getNkMinPic");
					b.Fill(new String[]{ ordLnPk, curApply.getCraftSeq(), curApply.getIndexSeq(),
							zgApply.getProcessCode() });
					CraftOrdDesignStdPicEntity stdPic = EntityTool.getEntityBySqlNoClsCon(
							b.toString(), con, CraftOrdDesignStdPicEntity.class);
					if(stdPic != null){
						if(!"".equals(stdPic.getPic()))
							rclConsign.setPic(stdPic.getPic());
					}
				}
				rclConsign.setCrafNo(curApply.getCrafNo());
				rclConsign.setJudgeResultCode("40740701");
				//zgConsign.setJudgeStoveNo();
				//删除委托一层表
				b = new SqlBuilder("JdgQcmZcCheckconsign.deleteByBatchNoOrdLnPkCheckNo1", checkNo);
				st.executeUpdate(b.toString());
				String insertConsign = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckconsign.insert");
				insertConsign = EntityTool.fillSqlByEntity(insertConsign, rclConsign);
				st.executeUpdate(insertConsign);

				//查询委托二层表
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.getNoBatchNo",
						oldCheckNo);
				List<QcmZcCheckconsignDetailEntity> rclDetails = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmZcCheckconsignDetailEntity.class);
				//删除二层
				b = new SqlBuilder("JdgQcmZcCheckConsignDetail.deleteByBatchNoOrdLnPkCheckNo1", checkNo);
				st.executeUpdate(b.toString());
				for(QcmZcCheckconsignDetailEntity rclDetail : rclDetails){
					rclDetail.setCheckNo(checkNo);
					rclDetail.setBatchNo(zgApply.getBatchNo());
					String insertDetail = CoreXmlSqlParsersFactory.getSql("JdgQcmZcCheckConsignDetail.insert");
					insertDetail = EntityTool.fillSqlByEntity(insertDetail, rclDetail);
					st.executeUpdate(insertDetail);
				}

				//查询检验表
				/*b = new SqlBuilder("QcmJhyElementsDAL.queryAllByCheckNo",
						new String[]{ oldCheckNo, oldJudgeStoveNo, oldBatchNo, oldProcessCode });*/
				b = new SqlBuilder("QcmJhyElementsDAL.queryAllNoBatchNo",
						new String[]{ oldCheckNo, oldJudgeStoveNo, oldBatchNo, oldProcessCode });
				List<QcmJhyElementsEntity> jhyChems = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmJhyElementsEntity.class);
				//删除成分检验
				b = new SqlBuilder("QcmJhyElementsDAL.deleteByBathNoOrdLnDlyPkCheckNo1", checkNo);
				st.executeUpdate(b.toString());
				for(QcmJhyElementsEntity jhyChem : jhyChems){
					jhyChem.setSampleId(checkNo);
					jhyChem.setJudgeStoveNo(zgApply.getJudgeStoveNo());
					jhyChem.setBatchNo(zgApply.getBatchNo());
					//jhyChem.setPlineCode(zgApply.getPlineCode());
					if(zgApply.getPlineCode().equals("")){
						jhyChem.setPlineCode("C017");
	                }else{
	                	jhyChem.setPlineCode(zgApply.getPlineCode());
	                }
					jhyChem.setAssayno(checkNo + "_" + jhyChem.getSampleNo() + "_C");
					String insertJhyChem = CoreXmlSqlParsersFactory.getSql("QcmJhyElementsDAL.insertQcmJhyElements");
					insertJhyChem = EntityTool.fillSqlByEntity(insertJhyChem, jhyChem);
					st.executeUpdate(insertJhyChem);
				}
				b = new SqlBuilder("QcmJhyPhyresultDAL.QueryByCheckNo",
						new String[]{ oldJudgeStoveNo, oldCheckNo, oldProcessCode });
				List<QcmJhyPhyresultEntity> jhyPhys = EntityTool.getEntitysBySqlNoClsCon(
						b.toString(), con, QcmJhyPhyresultEntity.class);
				//删除理化检验
				b = new SqlBuilder("QcmJhyPhyresultDAL.deleteByBatchNoOrdLnDlyPkCheckNo1", checkNo);
				st.executeUpdate(b.toString());
				for(QcmJhyPhyresultEntity jhyPhy : jhyPhys){
					jhyPhy.setSampleId(checkNo);
					jhyPhy.setJudgeStoveNo(zgApply.getJudgeStoveNo());
					jhyPhy.setBatchNo(zgApply.getBatchNo());
					jhyPhy.setLotNo(zgApply.getLotNo());
					jhyPhy.setLotNoGroup(zgApply.getLotNoGroup());
					//jhyPhy.setPlineCode(zgApply.getPlineCode());
					jhyPhy.setPlineCode("C017");
					if(zgApply.getPlineCode().equals("")){
						jhyPhy.setPlineCode("C017");
	                }else{
	                	jhyPhy.setPlineCode(zgApply.getPlineCode());
	                }
					jhyPhy.setJudgeFlag("20");
					//String insertJhyPhy = CoreXmlSqlParsersFactory.getSql("QcmJhyPhyresultDAL.Insert");
					//增加判定标识新增
					String insertJhyPhy = CoreXmlSqlParsersFactory.getSql("QcmJhyPhyresultDAL.InsertAndFlag");
					insertJhyPhy = EntityTool.fillSqlByEntity(insertJhyPhy, jhyPhy);
					st.executeUpdate(insertJhyPhy);
				}
			}

			con.commit();
		}catch(Exception ex){
			try {
				con.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			if(st != null){
				try {
					st.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(con != null){
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			cro.setV_errMsg(ex.getMessage());
		}

		return cro;
	}

	private String GetCopyCheckNo(QcmZcCheckconsignEntity rclConsign,
		String oldCheckNo, String process, SqlBuilder b, Connection con) throws Exception {
		String checkNo;
		b = new SqlBuilder("JdgQcmZcCheckconsign.getMaxLkCheckNo");
		b.Fill(new String[]{ rclConsign.getJudgeStoveNo(), rclConsign.getBatchNo(), "0",
				process, rclConsign.getCheckNo() });
		QcmZcCheckconsignEntity maxCheckNo = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, QcmZcCheckconsignEntity.class);
		if(!maxCheckNo.getCheckNo().equals("")){
			checkNo = maxCheckNo.getCheckNo();
			String sN = String.valueOf(Integer.parseInt(checkNo.substring(1, 2)) + 1);
			if(sN.equals("10")){
				throw new Exception("此炉的检验编号已达上限，生成组炉检验编号失败！");
			}
			if(oldCheckNo.contains("F"))
			{
				checkNo = "FD" + sN + oldCheckNo.substring(1);
			}else
			{
				checkNo = "D" + sN + oldCheckNo;
			}
		}else{
			if(oldCheckNo.contains("F"))
			{
				checkNo = "FD" + "0" + oldCheckNo.substring(1);
			}else
			{
				checkNo = "D" + "0" + oldCheckNo;
			}
		}

		return checkNo;
	}
	
	/**
	 * 轧管成分判定
	 * judgeFlag 1正常判定  0缺项判定
	 * @return
	 */
    public CoreReturnObject refreshStatus(String judgeApplyCode, String judgeStoveNo,
    		String batchNo, String user){
		Connection con = null;
		Statement st = null;
		CoreReturnObject cro = new CoreReturnObject();
		SqlBuilder b;
		String step = "";
		try{
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			st = con.createStatement();
			
			b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
            QcmZgJugdeApplyEntity zgJudgeApply = EntityTool.getEntityBySqlNoClsCon(
            		b.toString(), con, QcmZgJugdeApplyEntity.class);
            zgJudgeApply.setJudgeMaker(user);            
            String ordLnPk = BllZcColligateJudge.getOrdLnPkByDlyPk(zgJudgeApply.getOrdLnDlyPk(), b, con);    	
        	QcmZcCheckconsignEntity consign = new QcmZcCheckconsignEntity();
        	consign.setOrdLnDlyPk(zgJudgeApply.getOrdLnDlyPk());
        	consign.setCraftSeq(zgJudgeApply.getCraftSeq());
        	consign.setIndexSeq(zgJudgeApply.getIndexSeq());
        	consign.setProcessCode(zgJudgeApply.getProcessCode());
        	consign.setCic(zgJudgeApply.getCic());
        	consign.setPic(zgJudgeApply.getPic());
        	consign.setStoveNo(zgJudgeApply.getStoveNo());
        	consign.setJudgeStoveNo(zgJudgeApply.getJudgeStoveNo());
        	consign.setBatchNo(zgJudgeApply.getBatchNo());
        	consign.setCraftSource("0");
        	consign.setLotNo(zgJudgeApply.getLotNo());
        	consign.setLotNoGroup(zgJudgeApply.getLotNoGroup());
        	consign.setProduccode(zgJudgeApply.getProduccode());
        	consign.setSteelcode(zgJudgeApply.getSteelcode());
        	consign.setPlineCode(zgJudgeApply.getPlineCode());
        	consign.setLikuProcessCode(zgJudgeApply.getLikuProcessCode());
        	
        	BllRolledTubePhyJudge.setBcBatchResult(consign, ordLnPk, user, st, con);

			con.commit();
			return cro;
		}catch(Exception ex){
			try {
				con.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			if(ex instanceof SQLException){
				cro.setV_errMsg("程序处理失败"+ step +"！");
			}else{
				cro.setV_errMsg("程序处理失败"+ step +"：" + ex.getMessage());
			}
			return cro;
		}finally{
			if(st != null){
				try {
					st.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(con != null){
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
    }
    
	/**
	 * 轧管成分判定
	 * judgeFlag 1正常判定  0缺项判定
	 * @return
	 */
    public CoreReturnObject checkFsample(String judgeApplyCode, String judgeStoveNo,
    		String batchNo, String processCode){
		Connection con = null;
		CoreReturnObject cro = new CoreReturnObject();
		SqlBuilder b;
		try{
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			
			b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
            QcmZgJugdeApplyEntity zgJudgeApply = EntityTool.getEntityBySqlNoClsCon(
            		b.toString(), con, QcmZgJugdeApplyEntity.class);
            String ordLnPk = BllZcColligateJudge.getOrdLnPkByDlyPk(zgJudgeApply.getOrdLnDlyPk(), b, con);
            b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryGroupInfoByBatchNo");
            b.Fill(new String[]{ judgeApplyCode, judgeStoveNo, batchNo });
            QcmZgJugdeApplyEntity zgJudgeApplyGroup = EntityTool.getEntityBySqlNoClsCon(
            		b.toString(), con, QcmZgJugdeApplyEntity.class);
            zgJudgeApply.setActCount(zgJudgeApplyGroup.getActCount());
            zgJudgeApply.setActWeight(zgJudgeApplyGroup.getActWeight());
            zgJudgeApply.setActTheoryWeight(zgJudgeApplyGroup.getActTheoryWeight());
        	
        	QcmZcCheckconsignEntity consign = new QcmZcCheckconsignEntity();
        	consign.setOrdLnDlyPk(zgJudgeApply.getOrdLnDlyPk());
        	consign.setCraftSeq(zgJudgeApply.getCraftSeq());
        	consign.setIndexSeq(zgJudgeApply.getIndexSeq());
        	consign.setProcessCode(zgJudgeApply.getProcessCode());
        	consign.setCic(zgJudgeApply.getCic());
        	consign.setPic(zgJudgeApply.getPic());
        	consign.setStoveNo(zgJudgeApply.getStoveNo());
        	consign.setJudgeStoveNo(zgJudgeApply.getJudgeStoveNo());
        	consign.setBatchNo(zgJudgeApply.getBatchNo());
        	consign.setCraftSource("0");
        	consign.setLotNo(zgJudgeApply.getLotNo());
        	consign.setLotNoGroup(zgJudgeApply.getLotNoGroup());
        	consign.setProduccode(zgJudgeApply.getProduccode());
        	consign.setSteelcode(zgJudgeApply.getSteelcode());
        	consign.setPlineCode(zgJudgeApply.getPlineCode());
        	consign.setLikuProcessCode(zgJudgeApply.getLikuProcessCode());
        	
        	//获取所有试样组 验证缺项判定
            ArrayList<QcmZcCheckconsignDetailEntity> splines = BllRolledTubePhyJudge.getAllCraftPhySplines(
            		consign, ordLnPk, ordLnPk, new ArrayList<String>(), con);
            for(QcmZcCheckconsignDetailEntity entity:splines){
            	if(entity.getSampleId().contains("F")){
            		cro.setResult("该炉存在复验,不支持自动判定！");
        			return cro;
            	}
            }
			return cro;
		}catch(Exception ex){
    		cro.setV_errMsg(ex.getMessage());
    		return cro;
    	}finally{
    		try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}
    }
}
