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.comm.ChemJudgeHelper;
import com.steering.pss.judge.comm.PhyJudgeHelper;
import com.steering.pss.judge.model.*;
import com.steering.pss.qcm.model.GenericEntity;
import com.steering.pss.sale.order.orderchange.CrmOrderProduceService;
import com.steering.pss.ydm.base.OverstockPipe;
import com.steering.pss.ydm.pipemanage.FrmBcIqInList;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;

public class BllZcColligateJudge extends DBCommon {

    /**
     * 成品判定
     *
     * @return
     */
    public CoreReturnObject judge(String judgeApplyCode, String judgeStoveNo,
                                  String batchNo, String processCode, String user, String order,
                                  String group, String judgeFileMemo, String judgeMemo,
                                  String zbsFlag, ArrayList<String> checkDetailJsons) {
        Connection con = null;
        Statement st = null;
        CoreReturnObject cro = new CoreReturnObject();
        Date now = new Date();
        SqlBuilder b;
        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 oldJudgeTolResult = zgJudgeApply.getJudgeTolresultCode();
//            if(zgJudgeApply.getXsFlag().equals("0") && zgJudgeApply.getInMold().equals("801701")
//                    && !"120504".equals(zgJudgeApply.getSupplyUnit()) && zgJudgeApply.getTarget().equals("A")){
//                cro.setV_errMsg("该记录为非计划记录，销售未确认，不能判定！");
//                return cro;
//            }
            String ordLnPk = "";
            if (zgJudgeApply.getOrdLnDlyPk() != null && !"".equals(zgJudgeApply.getOrdLnDlyPk())) {
                ordLnPk = getOrdLnPkByDlyPk(zgJudgeApply.getOrdLnDlyPk(), b, con);
            }
            HashMap<String, QcmZgJugdeApplyEntity> applyMap = getAllJudgeApply(
                    zgJudgeApply.getJugdeApplyCode(), zgJudgeApply.getJudgeStoveNo(), zgJudgeApply.getBatchNo(),
                    processCode, zgJudgeApply.getUpperHeatplanId(), null, null, con);
            String zgLoadStoveNo = "";
            if (applyMap.containsKey("D")) {
                zgLoadStoveNo = applyMap.get("D").getLoadJudgeStoveNo();
            }
            //获取判定结果
            String judgeResult = getJudgeResult(applyMap, zgLoadStoveNo, con);
            if (judgeResult.equals("") && !zgJudgeApply.getIsAllScrap().equals("4")
                    && zgJudgeApply.getTarget().equals("A")) {
                cro.setV_errMsg("工序判定结果不完整，不能判定");
                return cro;
            }

            if (zgJudgeApply.getCic().equals("")) {
                ComBaseProductEntity product = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, ComBaseProductEntity.class);
                String producType = product.getProducType();
                if (!producType.equals("C") && producType.equals("D") && producType.equals("E")) {
                    cro.setV_errMsg("送判单异常，找不到成分索引码");
                    return cro;
                }
            }

            //-------------------验证锁定
            checkJudgeLock(b, zgJudgeApply, applyMap, con);

            //************************成品判定*********************
            //直缝焊套管 新系统出加工信息质保书， 性能结果在外购的质保书中
            QcmZcJudgeEntity zcJudge = new QcmZcJudgeEntity();
            if (zgJudgeApply.getProduccode().equals("S000103") || zgJudgeApply.getProduccode().equals("S000125")) {
                zgJudgeApply.setJudgeTolresultCode("40740701");
                zcJudge.setJudgeResult("40740701");
            } else {
                zcJudge = BllZcColligateJudge.Judge("zc", zgJudgeApply, ordLnPk, applyMap, zbsFlag, checkDetailJsons, con);
//                zcJudge.setJudgeResult(judgeResult);
                if (zgJudgeApply.getJudgeTolresultCode().equals("40740709")
                        && zcJudge.getJudgeResult().equals("")) {
                    zgJudgeApply.setJudgeTolresultCode("40740709");
                    zcJudge.setJudgeResult("40740709");
                } else {
                    zgJudgeApply.setJudgeTolresultCode(zcJudge.getJudgeResult());
                }
            }

            if (!zcJudge.getErrorMsg().equals("")) {
                cro.setV_errMsg(zcJudge.getErrorMsg());
                return cro;
            }

            // 缺项合格 判定不合
            if (oldJudgeTolResult.equals("40740709") && "40740704".equals(zgJudgeApply.getJudgeTolresultCode())) {
                con.rollback();
                cro.setV_errMsg("缺项合格判定不合，不能判定！");
                return cro;
            }

            b = new SqlBuilder("JdgQcmZcPassApplyDAL.queryByBatchNo");
            b.Fill(new String[]{zgJudgeApply.getJugdeApplyCode(), judgeStoveNo,
                    batchNo});
            QcmZcPassApplyEntity zcPassApply = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, QcmZcPassApplyEntity.class);

            //判定不合格，如果有处置结果就根据处置结果得出最终判定结果
//            b = new SqlBuilder("JdgQcmZcPassApplyDAL.queryByBatchNo");
//        	b.Fill(new String[]{ zgJudgeApply.getJugdeApplyCode(), judgeStoveNo,
//        			batchNo });
//        	QcmZcPassApplyEntity zcPassApply = EntityTool.getEntityBySqlNoClsCon(
//        			b.toString(), con, QcmZcPassApplyEntity.class);
//            if(zgJudgeApply.getJudgeTolresultCode().equals("40740704") || zgJudgeApply.getJudgeTolresultCode().equals("40740708")){
//            	if(zcPassApply != null && zcPassApply.getType().equals("0")){
//            		if(zcPassApply.getAuditResult().equals("407502")
//            				|| zcPassApply.getAuditResult().equals("407503")){
//            			zgJudgeApply.setJudgeTolresultCode("40740701");
//            			zcJudge.setJudgeResult("40740701");
//            		}else if(zcPassApply.getAuditResult().equals("407504")){
//            			cro.setV_errMsg("放行处置结果为降级/改判，请操作撤销判定！");
//                    	return cro;
//            		}else if(zcPassApply.getAuditResult().equals("407505")){
//            			cro.setV_errMsg("放行处置结果为报废，请操作撤销判定！");
//                    	return cro;
//            		}else if(zcPassApply.getAuditResult().equals("407506")){
//            			cro.setV_errMsg("放行处置结果为返工，请操作撤销判定！");
//                    	return cro;
//            		}
//            	}
//            }

            zcJudge.setMemo(judgeMemo);
            zcJudge.setCreateName(user);
            zcJudge.setStoveNo(zgJudgeApply.getStoveNo());
            zcJudge.setJudgeStoveNo(judgeStoveNo);
            zcJudge.setBatchNo(batchNo);
            zcJudge.setProcessCdoe(processCode);
            zcJudge.setPlineCode(zgJudgeApply.getPlineCode());
            zcJudge.setDeliveryStateCode(zgJudgeApply.getDeliveryStateCode());
            zcJudge.setDeliveryStateName(zgJudgeApply.getDeliveryStateName());
            zcJudge.setJugdeApplyCode(judgeApplyCode);
            zcJudge.setActCount(zgJudgeApply.getActCount());
            zcJudge.setActWeight(zgJudgeApply.getActWeight());
            zcJudge.setActTheoryWeight(zgJudgeApply.getActTheoryWeight());
            zcJudge.setOrdLnDlyPk(zgJudgeApply.getOrdLnDlyPk());
            //新增前作废有效的综合判定记录
            b = new SqlBuilder("JdgQcmZcJudge.updateValid");
            b.Fill(new String[]{judgeStoveNo, batchNo, judgeApplyCode, "0"});
            st.executeUpdate(b.toString());
            //新增判定记录
            saveJudge(zcJudge, "judge", b, con, st);

            //是否紧急放行
            boolean instancy = false;
            if (zcPassApply != null && zcPassApply.getType().equals("1")) {
                instancy = true;
            }
            //更新成品判定条件
            String zcJudgeCondition = "1";
            for (String key : applyMap.keySet()) {
                if (applyMap.get(key).getJudgeResultCode().equals("40740709")) {
                    zcJudgeCondition = "0";
                    break;
                }
            }

            String lengthType = "正尺";
            String lengthTypeNo = "0";
            String inStorageType = "A";
            String inStorageWeight = "0";
            // 长短尺 非计划入库
            List<ComLengthType> lengthTypes = getLengthTypes(ordLnPk);

            b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
            b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo});
            List<QcmZgJugdeApplyEntity> zgJudgeApplys = EntityTool.getEntitysBySqlNoClsCon(
                    b.toString(), con, QcmZgJugdeApplyEntity.class);

            if(lengthTypes == null || lengthTypes.size() <= 0){
                lengthTypes = getLengthTypes1(ordLnPk);
            }

            if(lengthTypes != null && lengthTypes.size() > 0){
                for (QcmZgJugdeApplyEntity judgeApply : zgJudgeApplys) {
                    for (ComLengthType type : lengthTypes) {
                        if (Double.parseDouble(judgeApply.getActLenMin()) < Double.parseDouble(type.getLenMin())) {
                            lengthType = "短尺";
                            lengthTypeNo = "2";
                        } else if(Double.parseDouble(judgeApply.getActLenMax()) > Double.parseDouble(type.getLenMax())){
                            lengthType = "长尺";
                            lengthTypeNo = "1";
                        }
                        if (lengthType.equals(type.getLengthType())) {
                            if("正尺".equals(lengthType) && Double.parseDouble(type.getPrdctWgt()) < (Double.parseDouble(type.getActWeight()) + Double.parseDouble(judgeApply.getActWeight()))){
                                inStorageType = "B";
                                if(Double.parseDouble(type.getActWeight()) > Double.parseDouble(type.getPrdctWgt())){
                                    inStorageWeight = judgeApply.getActWeight();
                                }
                                if(Double.parseDouble(type.getActWeight()) <= Double.parseDouble(type.getPrdctWgt())){
                                    inStorageWeight = String.valueOf((Double.parseDouble(type.getActWeight()) + Double.parseDouble(judgeApply.getActWeight())) - Double.parseDouble(type.getPrdctWgt()));
                                }
                                continue;
                            }
                            if(("长尺".equals(lengthType) && Double.parseDouble(type.getLongLenWeight()) < (Double.parseDouble(type.getActWeight()) + Double.parseDouble(judgeApply.getActWeight())))){
                                inStorageType = "C";
                                if(Double.parseDouble(type.getActWeight()) > Double.parseDouble(type.getLongLenWeight())){
                                    inStorageWeight = judgeApply.getActWeight();
                                }
                                if(Double.parseDouble(type.getActWeight()) <= Double.parseDouble(type.getLongLenWeight())) {
                                    inStorageWeight = String.valueOf((Double.parseDouble(type.getActWeight()) + Double.parseDouble(judgeApply.getActWeight())) - Double.parseDouble(type.getLongLenWeight()));
                                }
                                continue;
                            }
                            if(("短尺".equals(lengthType) && Double.parseDouble(type.getShrtLenWeight()) < (Double.parseDouble(type.getActWeight()) + Double.parseDouble(judgeApply.getActWeight())))){
                                inStorageType = "C";
                                if(Double.parseDouble(type.getActWeight()) > Double.parseDouble(type.getShrtLenWeight())){
                                    inStorageWeight = judgeApply.getActWeight();
                                }
                                if(Double.parseDouble(type.getActWeight()) <= Double.parseDouble(type.getShrtLenWeight())) {
                                    inStorageWeight = String.valueOf((Double.parseDouble(type.getActWeight()) + Double.parseDouble(judgeApply.getActWeight())) - Double.parseDouble(type.getShrtLenWeight()));
                                }
                                continue;
                            }
                        }
                    }
                    b = new SqlBuilder("QcmZgJugdeApplyDAL.setInStorageZc");
                    b.Fill(new String[]{judgeApply.getJugdeApplyCode(), judgeApply.getJudgeStoveNo(), judgeApply.getBatchNo(), processCode,judgeApply.getJugdeApplySequeno(),
                            inStorageType,inStorageWeight, lengthTypeNo, lengthTypeNo.equals("0")?"1":""});
                    st.executeUpdate(b.toString());
                    lengthType = "正尺";
                    lengthTypeNo = "0";
                    inStorageType = "A";
                    inStorageWeight = "0";
                }
            }

            //回写申请判定表
            b = new SqlBuilder("QcmZgJugdeApplyDAL.setJudgeResultZc");
            b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, processCode,
                    zcJudge.getJudgeResult(), user, order, group,
                    judgeMemo, zcJudge.getJudgeId(), judgeFileMemo, zcJudgeCondition});
            st.executeUpdate(b.toString());
            if (!oldJudgeTolResult.equals("40740709")) {
                b = new SqlBuilder("QcmZgJugdeApplyDAL.setJudgeTimeZc");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, processCode, "1"});
                st.executeUpdate(b.toString());
            }

            //修改结转年月
            //对于A字头结转年月在成品判定写  缺项合格的不修改结转年月
            if (zgJudgeApply.getTarget().equals("A") && !oldJudgeTolResult.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 (zcPassApply != null) {
                auditResult = zcPassApply.getAuditResult();
                auditMemo = zcPassApply.getAuditMemo();
            }
            String strInstancy = instancy ? "1" : "0";
            b = new SqlBuilder("QcmZgJugdeApplyDAL.setAuditResultZc");
            b.Fill(new String[]{zgJudgeApply.getJugdeApplyCode(), judgeStoveNo, batchNo,
                    processCode, auditResult, auditMemo, strInstancy});
            st.executeUpdate(b.toString());

            //修改放行单中的判定状态。
            b = new SqlBuilder("JdgQcmZcPassApplyDAL.setJudgeResult");
            b.Fill(new String[]{judgeStoveNo, batchNo, zgJudgeApply.getJugdeApplyCode(),
                    zcJudge.getJudgeResult()});
            st.executeUpdate(b.toString());

            if (!zgJudgeApply.getIsAllScrap().equals("4")) {
                //回写材料质量状态表
                b = new SqlBuilder("JdgMatBcQcmTrack.setJudgeTolResult");
                b.Fill(new String[]{judgeStoveNo, batchNo, processCode, zgJudgeApply.getJugdeApplyCode(),
                        zcJudge.getJudgeId(),
                        zgJudgeApply.getSteelStandrad(), zcJudge.getJudgeResult(), user, judgeMemo});
                st.executeUpdate(b.toString());

                //*********************更新材料表
                b = new SqlBuilder("JdgMatBcM.updateTolJudgeResult");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, zcJudge.getJudgeResult(),
                        user, zcJudge.getJudgeId()});
                st.executeUpdate(b.toString());
                if (!oldJudgeTolResult.equals("40740709")) {
                    b = new SqlBuilder("JdgMatBcM.updateTolJudgeTime");
                    b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, "1"});
                    st.executeUpdate(b.toString());
                }
                //更新材料历史表
                b = new SqlBuilder("JdgMatBcBackup.updateTolJudgeResult");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, zcJudge.getJudgeResult(),
                        user, zcJudge.getJudgeId()});
                st.executeUpdate(b.toString());
                if (!oldJudgeTolResult.equals("40740709")) {
                    b = new SqlBuilder("JdgMatBcBackup.updateTolJudgeTime");
                    b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, "1"});
                    st.executeUpdate(b.toString());
                }

                //更新利库改判表
                if (zgJudgeApply.getJudgeTolresultCode().equals("40740701")) {
                    b = new SqlBuilder("JdgQcmLkJudgeChange.setAgreeFlag");
                    b.Fill(new String[]{zgJudgeApply.getJugdeApplyCode() + zgJudgeApply.getJugdeApplySequeno(), "3"});
                    st.executeUpdate(b.toString());
                }
            }

            //修改成品材料表
            b = new SqlBuilder("JdgMatZcM.setJudgeResult");
            b.Fill(new String[]{judgeStoveNo, batchNo, zgJudgeApply.getBatchGroudNo(), zgJudgeApply.getOrdLnDlyPk(), zcJudge.getJudgeResult(),zgJudgeApply.getProOrderNo()});
            st.executeUpdate(b.toString());
            if (zgJudgeApply.getIsAllScrap().equals("4") && (zcJudge.getJudgeResult().equals("40740701")
                    || zcJudge.getJudgeResult().equals("40740709"))) {
                b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo});
                ArrayList<QcmZgJugdeApplyEntity> applys = EntityTool.getEntitysBySqlNoClsCon(
                        b.toString(), con, QcmZgJugdeApplyEntity.class);
                for (QcmZgJugdeApplyEntity apply : applys) {
                    b = new SqlBuilder("JdgMatZcM.setLkLock");
                    b.Fill(new String[]{judgeStoveNo, batchNo, apply.getBatchGroudNo(), apply.getOrdLnDlyPk(), "0", "0"});
                    st.executeUpdate(b.toString());
                }
            }

            // 修改半成品表的所属权 判定不合格所属权不变。
            if ((zcJudge.getJudgeResult().equals("40740701") || zcJudge.getJudgeResult().equals("40740702")
                    || zcJudge.getJudgeResult().equals("40740709")) && !oldJudgeTolResult.equals("40740709")) {
                if (zgJudgeApply.getBelongCodeJugde().equals("")) {
                    con.rollback();
                    cro.setV_errMsg("判定所属权为空，不能判定！");
                    return cro;
                }
                b = new SqlBuilder("JdgMatBcM.updateBelongZc");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, zgJudgeApply.getBelongCodeJugde(), zgJudgeApply.getBelongNameJugde()});
                st.executeUpdate(b.toString());
                b = new SqlBuilder("JdgMatBcBackup.updateBelongZc");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, zgJudgeApply.getBelongCodeJugde(), zgJudgeApply.getBelongNameJugde()});
                st.executeUpdate(b.toString());
            }

            //更新接箍材料表
            CouplingMatMEntity couplingMatM = new CouplingMatMEntity();
            couplingMatM.setJudgeTolresult(zcJudge.getJudgeResult());
            couplingMatM.setJudgeTolresultCode(zcJudge.getJudgeResult());
            couplingMatM.setJudgeTolmaker(user);
            couplingMatM.setJugdeTolconvicted(zcJudge.getJudgeId());
            couplingMatM.setJudgeStoveNo(zgJudgeApply.getJudgeStoveNo());
            couplingMatM.setBatchNo(zgJudgeApply.getBatchNo());
            couplingMatM.setDeterNo(zgJudgeApply.getJugdeApplyCode());
            couplingMatM.setWoId(zgJudgeApply.getProOrderId());
            String setJgJudgeInfo = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatM.setTolJudgeInfo");
            setJgJudgeInfo = EntityTool.fillSqlByEntity(setJgJudgeInfo, couplingMatM);
            st.executeUpdate(setJgJudgeInfo);

            //余材转压库综合判定增加产权出库记录
            if ("8".equals(zgJudgeApply.getIsAllScrap())) {
                OverstockPipe overstockPipe = new OverstockPipe();
                overstockPipe.addOutstockDoc(con,cro,judgeApplyCode);
            }

            //转存质保书
            new BllCreateZbsInfo().Create(judgeApplyCode, judgeStoveNo, batchNo, zbsFlag, oldJudgeTolResult,
                    false, "", zgJudgeApply.getOrdLnDlyPk(), con, st);
            if (!zgJudgeApply.getIsAllScrap().equals("4") && !oldJudgeTolResult.equals("40740709")) {
                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);
                if (zgJudges.get(0).getZbsFlag().equals("2")) {
                    new FrmBcIqInList().deleteMatBcA(con, zgJudges);
                }
            }

            //crm同步
            if ((zcJudge.getJudgeResult().equals("40740701") || zcJudge.getJudgeResult().equals("40740702")
                    || zcJudge.getJudgeResult().equals("40740709")) && !oldJudgeTolResult.equals("40740709")) {
                b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo});
                QcmZgJugdeApplyEntity CrmZgJudgeApply = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, QcmZgJugdeApplyEntity.class);
                CrmOrderProduceService crmOrderProduceService = new CrmOrderProduceService();
                crmOrderProduceService.insertJudgeCPCrmOrderProduce(con, CrmZgJudgeApply, true);
            }

            con.commit();
            return cro;
        } catch (Exception ex) {
            try {
                int zbsSeq = BllCreateZbsInfo.zbsSeq;
                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();
                }
            }
        }
    }

    private void checkJudgeLock(SqlBuilder b, QcmZgJugdeApplyEntity zgJudgeApply,
                                HashMap<String, QcmZgJugdeApplyEntity> applyMap, Connection con) throws Exception {
        for (String key : applyMap.keySet()) {
            QcmZgJugdeApplyEntity apply = applyMap.get(key);
            b = new SqlBuilder("JdgQcmJudgeLock.getLockInfo");
            String processCode = apply.getProcessCode();
            if (apply.getTarget().equals("A")) {
                processCode = "ZC";
            }
            b.Fill(new String[]{apply.getJudgeStoveNo(), apply.getBatchNo(), processCode,
                    "ZC"});
            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());
            }
        }
    }

    public static void saveJudge(QcmZcJudgeEntity zcJudge, String type, SqlBuilder b, Connection con, Statement st)
            throws SQLException {
        if (type.equals("judge")) {
            b = new SqlBuilder("JdgQcmZcJudge.GetMaxPk1");
        } else {
            b = new SqlBuilder("JdgQcmZcJudge.GetMaxPk0");
        }
        GenericEntity judgeId = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, GenericEntity.class);
        zcJudge.setJudgeId(judgeId.getMaxValue());
        String insertZcJudge = CoreXmlSqlParsersFactory.getSql("JdgQcmZcJudge.Insert");
        insertZcJudge = EntityTool.fillSqlByEntity(insertZcJudge, zcJudge);
        st.executeUpdate(insertZcJudge);

        int detailSeq = 0;
        for (QcmZcChemPhyDetailEntity detail : zcJudge.getDetails()) {
            detailSeq++;
            detail.setJudgeId(zcJudge.getJudgeId());
            detail.setDetailSeq(String.valueOf(detailSeq));
            String addZcDetail = CoreXmlSqlParsersFactory.getSql("JdgQcmZcChemPhyDetail.insert");
            addZcDetail = EntityTool.fillSqlByEntity(addZcDetail, detail);
            st.executeUpdate(addZcDetail);

            int chemResultSeq = 0;
            for (QcmZcChemColresultEntity chem : detail.getChems()) {
                chemResultSeq++;
                chem.setJudgeId(zcJudge.getJudgeId());
                chem.setDetailSeq(detail.getDetailSeq());
                chem.setResultSeq(String.valueOf(chemResultSeq));
                String addChem = CoreXmlSqlParsersFactory.getSql("JdgQcmZcChemColresult.insert");
                addChem = EntityTool.fillSqlByEntity(addChem, chem);
                st.executeUpdate(addChem);
            }

            int phyResultSeq = 0;
            for (QcmZcPhyColresultEntity phy : detail.getPhys()) {
                if (phy.getIsProductCheck().equals("1")) {
                    continue;//成品性能评测不需要保存判定数据。
                }
                phyResultSeq++;
                phy.setJudgeId(zcJudge.getJudgeId());
                phy.setDetailSeq(detail.getDetailSeq());
                phy.setResultSeq(String.valueOf(phyResultSeq));
                String addPhy = CoreXmlSqlParsersFactory.getSql("JdgQcmZcPhyColresult.insert");
                addPhy = EntityTool.fillSqlByEntity(addPhy, phy);
                st.executeUpdate(addPhy);
            }
        }
    }

    public static QcmZcJudgeEntity Judge(String judgeFlag, QcmZgJugdeApplyEntity curApply, String curOrdLnPk,
                                         HashMap<String, QcmZgJugdeApplyEntity> applyMap, String zbsFlag,
                                         ArrayList<String> checkDetailJsons, Connection con) throws Exception {
        SqlBuilder b = null;
        QcmZcJudgeEntity zcJudge = new QcmZcJudgeEntity();
        if (curOrdLnPk == null || "".equals(curOrdLnPk)) {
            zcJudge.setJudgeResult("40740701");
            return zcJudge;
        }
        BllCreateZbsInfo.CheckZbsDataComplete(curApply, curOrdLnPk, applyMap, zbsFlag, b, con);
        if (judgeFlag.equals("zc") && curApply.getZbsFlag().equals("2")) {
            zcJudge.setJudgeResult("40740701");
            return zcJudge;
        }

        ArrayList<QcmZcCheckconsignDetailEntity> checkDetails = new ArrayList<QcmZcCheckconsignDetailEntity>();
        for (String checkDetailJson : checkDetailJsons) {
            QcmZcCheckconsignDetailEntity checkDetail = EntityTool.getEntityByGson(checkDetailJson,
                    QcmZcCheckconsignDetailEntity.class);
            checkDetails.add(checkDetail);
        }

        //******工艺数据
        //各个工序是否有理化要求
        ArrayList<CraftOrdDesignMscPlPrcEntity> craftProcesses = getCraftPhyProcesses(curOrdLnPk,
                curApply.getCraftSeq(), curApply.getIndexSeq(), b, con);

        //获取炼钢判定记录
        String lgJudgeStoveNo = "";
        if (applyMap.containsKey("D")) {
            lgJudgeStoveNo = BllZcColligateJudge.getLgJudgeStoveNo(applyMap.get("D").getLoadJudgeStoveNo(), b, con);
        }
        b = new SqlBuilder("QcmLgJudgeDAL.queryByJudgeStoveNo");
        b.Fill(new String[]{lgJudgeStoveNo, "B"});
        QcmLgJudgeEntity lgJudge = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, QcmLgJudgeEntity.class);

        for (CraftOrdDesignMscPlPrcEntity craftProcess : craftProcesses) {
            if (craftProcess.getProcessCode().equals("B") || craftProcess.getProcessCode().equals("C")) {
                continue;
            }
            QcmZgJugdeApplyEntity apply = null;
            if (craftProcess.getProcessCode().equals("A")) {
                apply = applyMap.get("D");
                if (apply == null) {
                    apply = curApply;
                }
            } else {
                apply = applyMap.get(craftProcess.getProcessCode());
            }
            if (apply == null) {
                //throw new Exception("找不到" + craftProcess.getProcessDesc() + "工序对应的送判信息！");
                continue;
            }

            //工艺参数
            JudgeCraftParam cp = BllZcColligateJudge.getCraftParm(curApply, apply, b, con);
            //获取工序的合同行PK
            String proOrdLnPk = getOrdLnPkByDlyPk(apply.getProOrdLnDlyPk(), b, con);
            //获取成品判定记录
            b = new SqlBuilder("JdgQcmZcChemPhyDetail.getByBatchNoApplyCode");
            b.Fill(new String[]{curApply.getJudgeStoveNo(), curApply.getBatchNo(),
                    curApply.getJugdeApplyCode(), craftProcess.getProcessCode()});
            ArrayList<QcmZcChemPhyDetailEntity> oldDetails = EntityTool.getEntitysBySqlNoClsCon(b.toString(),
                    con, QcmZcChemPhyDetailEntity.class);
            if (craftProcess.getProcessCode().equals("A")) {
                b = new SqlBuilder("QcmJhyElementsDAL.getLgPhyMinByStoveNo");
                b.Fill(new String[]{cp.getOrdLnPk(), cp.getCraftSeq(), curApply.getStoveNo(), lgJudgeStoveNo, apply.getCic()});
                ArrayList<QcmZcCheckconsignDetailEntity> splines = EntityTool.getEntitysBySqlNoClsCon(
                        b.toString(), con, QcmZcCheckconsignDetailEntity.class);
                for (QcmZcCheckconsignDetailEntity spline : splines) {
                    //成分判定
                    QcmJhyElementsEntity jhyChem = getLgJhyChem(curApply.getStoveNo(), b, con);
                    ArrayList<CraftOrdDesignStdCicEntity> nkChems = getLgNkCraftChem(cp.getOrdLnPk(),
                            cp.getCraftSeq(), cp.getMscPline(), cp.getCic(), b, con);
                    Object[] chemResults = null;
                    if (jhyChem != null) {
                        ArrayList<CraftOrdDesignStdCicEntity> jfChems = getJfCraftChem(cp.getOrdLnPk(), cp.getCraftSeq(), b, spline.getProcessCode(), cp.getCic(), con);
                        chemResults = chemJudge(jhyChem, nkChems, jfChems, spline.getPhyCodeMin());
                        spline.setJfResult(chemResults[1].toString());
//        				//利库、外购管、在炼钢找不到判定记录的炉号二层表结果取成品判定的结果，否则沿用工序判定结果
//        				if(lgJudge == null || curApply.getIsAllScrap().equals("4") || curApply.getOrdLnDlyPk().startsWith("ZZB")){
//
//        				}
                        BllZcColligateJudge.DealwithLkDetailResult(spline, oldDetails, chemResults, checkDetails, apply.getProcessCode());
                    } else {
                        //直缝焊套管 新系统出加工信息质保书， 性能结果在外购的质保书中
                        if (!curApply.getProduccode().equals("S000103") && !curApply.getProduccode().equals("S000125")) {
                            if (apply.getProcessCode().equals("D")) {
                                throw new Exception("找不到熔炼成分实绩！");
                            }
                        }
//    					//利库、外购管、在炼钢找不到判定记录的炉号二层表结果取成品判定的结果，否则沿用工序判定结果
//        				if(lgJudge == null || curApply.getIsAllScrap().equals("4") && !curApply.getProcessCode().equals("H")){
//        					BllZcColligateJudge.DealwithLkDetailResult(spline, oldDetails, chemResults, checkDetails, apply.getProcessCode());
//        				}
                    }

                    //修改工艺相关信息为成品对应的合同的工艺信息
                    QcmZcChemPhyDetailEntity detail = EntityTool.copy(spline, QcmZcChemPhyDetailEntity.class);
                    detail.setProcessCode(craftProcess.getProcessCode());
                    detail.setJugdeApplyCode("");
                    detail.setZbsValidflag("1");
                    if (chemResults != null) {
                        for (QcmZcChemColresultEntity chem : (ArrayList<QcmZcChemColresultEntity>) chemResults[2]) {
                            detail.getChems().add(chem);
                        }
                    }
                    zcJudge.getDetails().add(detail);
                }
                if (splines.size() == 0) {
                    throw new Exception("找不到炼钢信息！");
                    //splineResults.add("0");
                }
            } else {
                BllZcColligateJudge.Judge(curApply, apply, cp, proOrdLnPk, zcJudge, checkDetails, oldDetails, b, con);
            }
        }

        //处理复取样
        BllZcColligateJudge.DealWithResampleLg(zcJudge);
        //若内控结果不合格，质保书标志改为无效
        BllZcColligateJudge.DealwithReSample(zcJudge);//(19-11-14暂时屏蔽)


        //汇总二层表结果
        ArrayList<String> zcResults = BllZcColligateJudge.GroupChemPhyDetailResult(
                zcJudge, craftProcesses, applyMap, curApply, lgJudge, b, con);

        //汇总成品综合结果
        if (craftProcesses.size() == 0) {
            String djResult = "40740701";
            for (QcmZgJugdeApplyEntity apply : applyMap.values()) {
                if (apply.getJudgeResultCode().equals("40740709")) {
                    djResult = "40740709";
                    break;
                }
            }
            zcJudge.setJudgeResult(djResult);
        } else {
            if (zcResults.contains("")) {
                zcJudge.setJudgeResult("");
            } else if (zcResults.contains("40740704")) {
                zcJudge.setJudgeResult("40740704");
            } else if (zcResults.contains("40740709")) {
                zcJudge.setJudgeResult("40740709");
            } else if (zcResults.contains("40740701")) {
                zcJudge.setJudgeResult("40740701");
            }

            //判定不合格，如果有处置结果就根据处置结果得出最终判定结果
            b = new SqlBuilder("JdgQcmZcPassApplyDAL.queryByBatchNo");
            b.Fill(new String[]{curApply.getJugdeApplyCode(), curApply.getJudgeStoveNo(),
                    curApply.getBatchNo()});
            QcmZcPassApplyEntity zcPassApply = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, QcmZcPassApplyEntity.class);
            if (zcJudge.getJudgeResult().equals("40740704") || zcJudge.getJudgeResult().equals("40740708")) {
                if (zcPassApply != null && zcPassApply.getType().equals("0")) {
                    if (zcPassApply.getAuditResult().equals("407502")
                            || zcPassApply.getAuditResult().equals("407503")) {
                    	if(zcResults.contains("40740709")){
                    		zcJudge.setJudgeResult("40740709");
                    	}else{
                            zcJudge.setJudgeResult("40740701");
                    	}
                    } else if (zcPassApply.getAuditResult().equals("407504")) {
                        zcJudge.setErrorMsg("放行处置结果为降级/改判，请操作撤销判定！");
                    } else if (zcPassApply.getAuditResult().equals("407505")) {
                        zcJudge.setErrorMsg("放行处置结果为报废，请操作撤销判定！");
                    } else if (zcPassApply.getAuditResult().equals("407506")) {
                        zcJudge.setErrorMsg("放行处置结果为返工，请操作撤销判定！");
                    }
                }
            }
        }

        //综合性验证各个判定项，得出综合结果
        String faceResult = getFaceResult(applyMap, con);
        zcJudge.setFaceResult(faceResult);
        String specResult = getSpecResult(applyMap, con);
        zcJudge.setSpecResult(specResult);
        String detectResult = getDetectResult(applyMap, con);
        zcJudge.setDetectResult(detectResult);
        String waterResult = getWaterResult(applyMap, con);
        zcJudge.setWaterResult(waterResult);
        String processResult = getProcessResult(applyMap, con);
        zcJudge.setProcessResult(processResult);
        setJudgeIdIntoZcJudge("D", zcJudge, applyMap);
        setJudgeIdIntoZcJudge("E", zcJudge, applyMap);
        setJudgeIdIntoZcJudge("F", zcJudge, applyMap);
        setJudgeIdIntoZcJudge("G", zcJudge, applyMap);

        //更新材料表 zbsId、利库锁定状态
        return zcJudge;
    }

    public static String getOrdLnPkByDlyPk(String ordLnDlyPk, SqlBuilder b, Connection con) {
        if (ordLnDlyPk.startsWith("ZZB")) {
            b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
        } else {
            b = new SqlBuilder("JdgSlmOrderLineDelivery.getOrdLnPkByDlyPk");
        }
        b.Fill(new String[]{ordLnDlyPk});
        PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);

        return plnSaleord.getOrdLnPk();
    }

    /**
     * 获取工艺参数
     *
     * @param curApply
     * @param apply
     * @param b
     * @param con
     * @return
     */
    public static JudgeCraftParam getCraftParm(QcmZgJugdeApplyEntity curApply, QcmZgJugdeApplyEntity apply,
                                               SqlBuilder b, Connection con) {
        JudgeCraftParam a = new JudgeCraftParam();

        PlnSaleordEntity plnSaleord;
        String producType = "";
        if (curApply != null) {
            b = new SqlBuilder("JdgComBaseProduct.getByPk", curApply.getProduccode());
            ComBaseProductEntity product = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, ComBaseProductEntity.class);
            producType = product.getProducType();
        }
        if ((curApply == null || curApply.getOrdLnDlyPk().startsWith("ZZB")
                || (producType.equals("C") || producType.equals("D") || producType.equals("E")))
                && apply.getOrdLnDlyPk().startsWith("ZZB")) {
            b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
            b.Fill(new String[]{apply.getOrdLnDlyPk()});
            plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
            a.setOrdLnDlyPk(apply.getOrdLnDlyPk());
            a.setOrdLnPk(plnSaleord.getOrdLnPk());
            a.setCraftSeq(apply.getCraftSeq());
            a.setMscPline(apply.getIndexSeq());
            a.setCic(apply.getCic());
            a.setPic(apply.getPic());
        } else {
            if (curApply == null) {
                b = new SqlBuilder("JdgSlmOrderLineDelivery.getOrdLnPkByDlyPk");
                b.Fill(new String[]{apply.getOrdLnDlyPk()});
                plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
                a.setOrdLnDlyPk(apply.getOrdLnDlyPk());
                a.setOrdLnPk(plnSaleord.getOrdLnPk());
                a.setCraftSeq(apply.getCraftSeq());
                a.setMscPline(apply.getIndexSeq());
                a.setCic(apply.getCic());
                a.setPic(apply.getPic());
            } else {
                if (producType.equals("C") || producType.equals("D") || producType.equals("E")) {
                    b = new SqlBuilder("JdgSlmOrderLineDelivery.getOrdLnPkByDlyPk");
                    b.Fill(new String[]{apply.getOrdLnDlyPk()});
                    plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
                    a.setOrdLnDlyPk(apply.getOrdLnDlyPk());
                    a.setOrdLnPk(plnSaleord.getOrdLnPk());
                    a.setCraftSeq(apply.getCraftSeq());
                    a.setMscPline(apply.getIndexSeq());
                    a.setCic(apply.getCic());
                    a.setPic(apply.getPic());
                } else {
                    b = new SqlBuilder("JdgSlmOrderLineDelivery.getOrdLnPkByDlyPk");
                    b.Fill(new String[]{curApply.getOrdLnDlyPk()});
                    plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
                    a.setOrdLnDlyPk(curApply.getOrdLnDlyPk());
                    a.setOrdLnPk(plnSaleord.getOrdLnPk());
                    a.setCraftSeq(curApply.getCraftSeq());
                    a.setMscPline(curApply.getIndexSeq());
                    a.setCic(curApply.getCic());
                    b = new SqlBuilder("CraftOrdDesignStdPic.getNkMinPic");
                    b.Fill(new String[]{a.getOrdLnPk(), a.getCraftSeq(), a.getMscPline(),
                            apply.getProcessCode()});
                    CraftOrdDesignStdPicEntity stdPic = EntityTool.getEntityBySqlNoClsCon(
                            b.toString(), con, CraftOrdDesignStdPicEntity.class);
                    a.setPic(stdPic.getPic());
                }
            }
        }

//		if (apply.getOrdLnDlyPk().startsWith("ZZB")) {
//			b = new SqlBuilder("JdgPlnSaleOrd.getOrdLnPkByDlyPk");
//			b.Fill(new String[]{apply.getOrdLnDlyPk()});
//			PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
//			a.setOrdLnDlyPk(apply.getOrdLnDlyPk());
//			a.setOrdLnPk(plnSaleord.getOrdLnPk());
//			a.setCraftSeq(apply.getCraftSeq());
//			a.setMscPline(apply.getIndexSeq());
//			a.setPic(apply.getPic());
//			a.setCic(apply.getCic());
//		} else {
//			if (curApply.getIsAllScrap().equals("4")) {
//				b = new SqlBuilder("JdgSlmOrderLineDelivery.getOrdLnPkByDlyPk");
//				b.Fill(new String[]{curApply.getOrdLnDlyPk()});
//				PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
//				a.setOrdLnDlyPk(curApply.getOrdLnDlyPk());
//				a.setOrdLnPk(plnSaleord.getOrdLnPk());
//				a.setCraftSeq(curApply.getCraftSeq());
//				a.setMscPline(curApply.getIndexSeq());
//				a.setCic(curApply.getCic());
//				b = new SqlBuilder("CraftOrdDesignStdPic.getNkMinPic");
//				b.Fill(new String[]{ a.getOrdLnPk(), a.getCraftSeq(), a.getMscPline(),
//						apply.getProcessCode() });
//				CraftOrdDesignStdPicEntity stdPic = EntityTool.getEntityBySqlNoClsCon(
//						b.toString(), con, CraftOrdDesignStdPicEntity.class);
//				a.setPic(stdPic.getPic());
//			} else {
//				b = new SqlBuilder("JdgSlmOrderLineDelivery.getOrdLnPkByDlyPk");
//				b.Fill(new String[]{apply.getOrdLnDlyPk()});
//				PlnSaleordEntity plnSaleord = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnSaleordEntity.class);
//				a.setOrdLnDlyPk(apply.getOrdLnDlyPk());
//				a.setOrdLnPk(plnSaleord.getOrdLnPk());
//				a.setCraftSeq(apply.getCraftSeq());
//				a.setMscPline(apply.getIndexSeq());
//				a.setPic(apply.getPic());
//				a.setCic(apply.getCic());
//			}
//		}

        return a;
    }

    @SuppressWarnings("unchecked")
    private static void Judge(QcmZgJugdeApplyEntity curApply, QcmZgJugdeApplyEntity apply, JudgeCraftParam cp,
                              String proOrdLnPk, QcmZcJudgeEntity zcJudge, ArrayList<QcmZcCheckconsignDetailEntity> checkDetails,
                              ArrayList<QcmZcChemPhyDetailEntity> oldDetails, SqlBuilder b, Connection con) throws Exception {
        //获取理化索引码
        QcmZcCheckconsignEntity consign = new QcmZcCheckconsignEntity();
        //consign.setOrdLnDlyPk(ordLnDlyPk);
        consign.setCraftSeq(cp.getCraftSeq());
        consign.setIndexSeq(cp.getMscPline());
        consign.setProcessCode(apply.getProcessCode());
        consign.setCic(cp.getCic());
        consign.setPic(cp.getPic());
        consign.setStoveNo(apply.getStoveNo());
        consign.setJudgeStoveNo(apply.getJudgeStoveNo());
        consign.setBatchNo(apply.getBatchNo());
        consign.setCraftSource("0");
        consign.setLotNo(apply.getLotNo());
        consign.setLotNoGroup(apply.getLotNoGroup());
        consign.setProduccode(apply.getProduccode());
        consign.setSteelcode(apply.getSteelcode());
        consign.setPlineCode(apply.getPlineCode());
        consign.setLikuProcessCode(apply.getLikuProcessCode());
        ArrayList<QcmZcCheckconsignDetailEntity> splines = BllRolledTubePhyJudge.getConsignDetailColligate(
                consign, apply.getJugdeApplyCode(), apply.getJudgeStoveNo(), apply.getBatchNo(), cp.getOrdLnPk(), proOrdLnPk, new ArrayList<String>(),
                curApply.getIsAllScrap(), curApply.getJugdeApplyCode(), curApply.getJudgeStoveNo(), curApply.getBatchNo(),
                "zc", con);
        for (QcmZcCheckconsignDetailEntity spline : splines) {
            if ("0".equals(spline.getIsQuote())) {
                continue;
            }
            if (spline.getIsMain().equals("0")) continue;
            if (spline.getPhyNameMin().equals("SSC-A法试验(1*1)")) {
                String s = "";
                s = "";
            }
            //如果品名为接箍坯料并且钢级为C110，预备硬度与替代洛氏硬度
            if (apply.getProduccode().equals("S000046") && apply.getSteelcode().equals("C209")
                    && spline.getPhyNameMin().contains("洛氏硬度")) {
                boolean existYb = false;
                for (QcmZcCheckconsignDetailEntity tmpSpline : splines) {
                    if (tmpSpline.getPhyNameMin().contains("预备硬度")) {
                        existYb = true;
                        break;
                    }
                }
                if (existYb) {
                    continue;
                }
            }
            if (spline.getPhyCodeMin().equals("HX")) {
                QcmJhyElementsEntity jhyChem = BllZcColligateJudge.getJhyChem(spline.getSampleId(), spline.getJudgeStoveNo(),
                        spline.getBatchNo(), apply.getProcessCode(), apply.getOrdLnDlyPk(), spline.getSampleNo(), b, con);
                Object[] chemResults = null;
                if (jhyChem != null) {
                    ArrayList<CraftOrdDesignStdCicEntity> nkChems = getNkCraftChem(cp.getOrdLnPk(),
                            cp.getCraftSeq(), cp.getMscPline(), cp.getCic(),
                            spline.getCraftSource(), b, con);
                    ArrayList<CraftOrdDesignStdCicEntity> jfChems = getJfCraftChem(cp.getOrdLnPk(),
                            cp.getCraftSeq(), b, spline.getProcessCode(), cp.getCic(), con);
                    chemResults = chemJudge(jhyChem, nkChems, jfChems, spline.getPhyCodeMin());
                }

                //只有成品利库或备料末工序需要修改工序结果
                if (curApply.getIsAllScrap().equals("4") || curApply.getOrdLnDlyPk().startsWith("ZZB")) {

                }
                String tmpNkResult = spline.getNkResult();
                String tmpJfResult = spline.getJfResult();
                BllZcColligateJudge.DealwithLkDetailResult(spline, oldDetails, chemResults, checkDetails, apply.getProcessCode());
                String phyCodeMin = spline.getPhyCodeMin();
//				if(spline.getNkResult().equals("1")){
//					//if(apply.get)
//				}
//				if(spline.getNkResult().equals("")){
//					if(phyCodeMin.equals("C0030") || phyCodeMin.equals("C0031")
//							|| phyCodeMin.equals("C0032") || phyCodeMin.equals("C0033")
//							|| phyCodeMin.equals("C0133")) {
//						if(apply.getJudgeResultCode().equals("40740709")){
//							spline.setNkResult();
//						}
//					}
//				}


                QcmZcChemPhyDetailEntity detail = EntityTool.copy(spline, QcmZcChemPhyDetailEntity.class);
                detail.setProcessCode(apply.getProcessCode());
                detail.setJugdeApplyCode(apply.getJugdeApplyCode());
                detail.setZbsValidflag("1");
                if (chemResults != null) {
                    for (QcmZcChemColresultEntity chem : (ArrayList<QcmZcChemColresultEntity>) chemResults[2]) {
                        detail.getChems().add(chem);
                    }
                }
                zcJudge.getDetails().add(detail);
            } else {
                ArrayList<QcmJhyPhyresultEntity> jhyPhys = BllZcColligateJudge.getJhyPhys(spline.getSampleId(),
                        spline.getJudgeStoveNo(), spline.getBatchNo(), apply.getProcessCode(), apply.getOrdLnDlyPk(),
                        spline.getSampleNo(), spline.getPhyCodeMin(), b, con);

                Object[] phyResults = null;
                ArrayList<CraftOrdDesignStdPicEntity> nkPhys = new ArrayList<CraftOrdDesignStdPicEntity>();
                if (jhyPhys.size() > 0) {
                    nkPhys = BllZcColligateJudge.getNkCraftPhy(cp.getOrdLnPk(),
                            cp.getCraftSeq(), cp.getMscPline(), apply.getProcessCode(), cp.getPic(),
                            spline.getPhyCodeMin(), spline.getCraftSource(), b, con);
                    ArrayList<CraftOrdDesignStdPicEntity> jfPhys = BllZcColligateJudge.getJfCraftPhy(cp.getOrdLnPk(),
                            cp.getCraftSeq(), cp.getMscPline(), apply.getProcessCode(), cp.getPic(),
                            spline.getPhyCodeMin(), b, con);
                    phyResults = phyJudge(jhyPhys, nkPhys, jfPhys, curApply, spline.getSampleId(),
                            spline.getPhyCodeMin(), spline.getStoveNo(), con);
                }

                //只有成品利库需要修改工序结果
//				if(curApply.getIsAllScrap().equals("4") || curApply.getOrdLnDlyPk().startsWith("ZZB")){
//
//				}
                BllZcColligateJudge.DealwithLkDetailResult(spline, oldDetails, phyResults, checkDetails, apply.getProcessCode());

//                for (CraftOrdDesignStdPicEntity craftDesingStdPic : nkPhys) {
//                    if(craftDesingStdPic.getPhyCodeMin().equals("C0002")){ // 夏比摆锤冲击试验-V型
//                        int i = 0;
//                        for (QcmJhyPhyresultEntity jhyPhyResult : jhyPhys) {
//                            if (craftDesingStdPic.getPhyCode().equals(jhyPhyResult.getPhyCode())
//                                    && craftDesingStdPic.getItemCodeF().equals(jhyPhyResult.getItemCodeF())
//                            ) {
//                                i++;
//                                continue;
//                            }
//                        }
////                        if (i == 0 && !apply.getJudgeResultCode().equals("40740709")) {
////                            spline.setResultSource("0");
////                        }
////
////                        //人工修改结果
////                        for (QcmZcCheckconsignDetailEntity checkDetail : checkDetails) {
////                            if (checkDetail.getSampleId().equals(spline.getSampleId()) && checkDetail.getSampleNo().equals(spline.getSampleNo())
////                                    && checkDetail.getPhyCodeMin().equals(spline.getPhyCodeMin())) {
////                                if (checkDetail.getChk().equals("True") || checkDetail.getResultSource().equals("1")) {
////                                    spline.setResultSource("1");
////                                    continue;
////                                }
////                            }
////                        }
//
//                        if(i == 0 && !apply.getJudgeResultCode().equals("40740709") && spline.getResultSource().equals("0")){
//                            throw new Exception(apply.getProcessDesc() + "工序缺少项目，(" +craftDesingStdPic.getPhyName()+ craftDesingStdPic.getItemNameF()+")，请人工处理！");
//                        }
//                    }
//                }
                if (jhyPhys.size() == 0 && spline.getResultSource().equals("0")
                        && !apply.getJudgeResultCode().equals("40740709")) {
                    throw new Exception(apply.getProcessDesc() + "工序缺少项目，请人工处理！");
                }

                QcmZcChemPhyDetailEntity detail = EntityTool.copy(spline, QcmZcChemPhyDetailEntity.class);
                detail.setProcessCode(apply.getProcessCode());
                detail.setJugdeApplyCode(apply.getJugdeApplyCode());
                detail.setZbsValidflag("1");
                if (phyResults != null) {
                    for (QcmZcPhyColresultEntity phy : (ArrayList<QcmZcPhyColresultEntity>) phyResults[2]) {
                        detail.getPhys().add(phy);
                    }
                }
                zcJudge.getDetails().add(detail);
            }
        }
    }

    private static void DealwithLkDetailResult(QcmZcCheckconsignDetailEntity spline, ArrayList<QcmZcChemPhyDetailEntity> oldDetails,
                                               Object[] judgeResults, ArrayList<QcmZcCheckconsignDetailEntity> checkDetails, String processCode) {
        for (QcmZcChemPhyDetailEntity oldDetail : oldDetails) {
            if (oldDetail.getCheckNo().equals(spline.getCheckNo()) && oldDetail.getSampleNo().equals(spline.getSampleNo())
                    && oldDetail.getPhyCodeMin().equals(spline.getPhyCodeMin())) {
                spline.setResultSource(oldDetail.getResultSource());
                spline.setNkResult(oldDetail.getNkResult());
                spline.setJfResult(oldDetail.getJfResult());
                break;
            }
        }
        if (judgeResults != null && !spline.getResultSource().equals("1")) {
            spline.setNkResult(judgeResults[0].toString());
            spline.setJfResult(judgeResults[1].toString());
        }
        if (spline.getResultSource().equals("")) {
            spline.setResultSource("0");
        }

        //对于利库给不了结果的可以人工修改
        for (QcmZcCheckconsignDetailEntity checkDetail : checkDetails) {
            if (checkDetail.getSampleId().equals(spline.getSampleId()) && checkDetail.getSampleNo().equals(spline.getSampleNo())
                    && checkDetail.getPhyCodeMin().equals(spline.getPhyCodeMin())) {
                if (checkDetail.getChk().equals("True") || checkDetail.getResultSource().equals("1")) {
                    spline.setResultSource("1");
                    //只有结果为3 系统处理不了的可以人工修改结果
                    spline.setNkResult(checkDetail.getNkResult());
                    spline.setJfResult(checkDetail.getJfResult());
                    break;
                }
            }
        }
    }

    private static void DealwithReSample(QcmZcJudgeEntity zcJudge) {
        for (int i = zcJudge.getDetails().size() - 1; i >= 0; i--) {
            QcmZcChemPhyDetailEntity detail = zcJudge.getDetails().get(i);
            if (detail.getProcessCode().equals("A")) continue;
            if (detail.getValidflag().equals("0") || detail.getZbsValidflag().equals("0") || detail.getCheckNo().contains("F"))
                continue;
            if (detail.getNkResult().equals("0")) {
                int fyCount = 0;
                for (QcmZcChemPhyDetailEntity detail2 : zcJudge.getDetails()) {
                    if (detail2.getProcessCode().equals(detail.getProcessCode()) && detail2.getPhyCodeMin().equals(detail.getPhyCodeMin())
                            && detail2.getCheckNo().contains("F") && !detail2.getNkResult().equals("0")) {
                        fyCount++;
                        if (fyCount > 1) {
                            detail2.setZbsValidflag("0");
                        }
                    }
                }

                if (fyCount > 0) {
                    detail.setZbsValidflag("0");
                }
            }
        }
    }

    private static void DealWithResampleLg(QcmZcJudgeEntity zcJudge) {
        for (int i = zcJudge.getDetails().size() - 1; i >= 0; i--) {
            QcmZcChemPhyDetailEntity detail = zcJudge.getDetails().get(i);
            if (detail.getProcessCode().equals("A")) {
                if (detail.getSampleNo().contains("F")) {
                    //如果有F的则去掉其他的试样号，只保留一个复验的试样号
                    for (int j = zcJudge.getDetails().size() - 1; j >= 0; j--) {
                        QcmZcChemPhyDetailEntity detail2 = zcJudge.getDetails().get(j);
                        if (detail2.getProcessCode().equals("A")) {
                            if (!detail2.getSampleNo().equals(detail.getSampleNo())) {
                                detail2.setZbsValidflag("0");
                            }
                        }
                    }
                    break;
                }
            }
        }
    }

    private static ArrayList<String> GroupChemPhyDetailResult(QcmZcJudgeEntity zcJudge,
                                                              ArrayList<CraftOrdDesignMscPlPrcEntity> craftProcesses,
                                                              HashMap<String, QcmZgJugdeApplyEntity> applyMap, QcmZgJugdeApplyEntity curApply,
                                                              QcmLgJudgeEntity lgJudge, SqlBuilder b, Connection con) throws Exception {
        ArrayList<String> zcResults = new ArrayList<String>();
        HashMap<String, ArrayList<String>> splineMaps = new HashMap<String, ArrayList<String>>();
        for (QcmZcChemPhyDetailEntity detail : zcJudge.getDetails()) {
            if (detail.getValidflag().equals("0") || detail.getZbsValidflag().equals("0")) continue;
            if (splineMaps.containsKey(detail.getProcessCode())) {
                ArrayList<String> tmpSplineResults = splineMaps.get(detail.getProcessCode());
                tmpSplineResults.add(detail.getNkResult());
            } else {
                ArrayList<String> tmpSplineResults = new ArrayList<String>();
                tmpSplineResults.add(detail.getNkResult());
                splineMaps.put(detail.getProcessCode(), tmpSplineResults);
            }
        }
        for (CraftOrdDesignMscPlPrcEntity craftProcess : craftProcesses) {
            if (craftProcess.getProcessCode().equals("B") || craftProcess.getProcessCode().equals("C")) {
                continue;
            }
            ArrayList<String> tmpSplineResults = splineMaps.get(craftProcess.getProcessCode());
            QcmZgJugdeApplyEntity apply = null;
            if (craftProcess.getProcessCode().equals("A")) {
                apply = applyMap.get("D");
            } else {
                apply = applyMap.get(craftProcess.getProcessCode());
            }
            if (apply == null) {
                continue;
            }
            String zcResult = "";
            //直缝焊套管 新系统出加工信息质保书， 性能结果在外购的质保书中
            if (curApply.getProduccode().equals("S000103") || curApply.getProduccode().equals("S000125")) {
                zcResult = "40740701";
                continue;
            }
//    		if(craftProcess.getProcessCode().equals("A")){
////    			if(lgJudge == null){
////    				if(tmpSplineResults.contains("")){
////						zcResult = "";
////            		}else if(tmpSplineResults.contains("0")){
////            			//zcResults.add("40740704");
////						zcResult = "40740704";
////            		}else if(tmpSplineResults.contains("1")){
////            			//zcResults.add("40740701");
////						zcResult = "40740701";
////            		}
////    			}else{
////    				b = new SqlBuilder("QcmGpJugdeApplyDAL.queryGpApplyByJudgeStoveNo2");
////    				b.Fill(new String[]{ apply.getLoadJudgeStoveNo() });
////    				QcmGpJudgeApplyEntity gpApply = EntityTool.getEntityBySqlNoClsCon(
////    						b.toString(), con, QcmGpJudgeApplyEntity.class);
////    				if(curApply.getOrdLnDlyPk().equals(gpApply.getOrdLnDlyPk())){
////						//zcResults.add(lgJudge.getJudgeresult());
////						zcResult = lgJudge.getJudgeresult();
////					}else{
////						if(tmpSplineResults.contains("")){
////							//zcResults.add("");
////							zcResult = "";
////						}else if(tmpSplineResults.contains("0")){
////							//zcResults.add("40740704");
////							zcResult = "40740704";
////						}else if(tmpSplineResults.contains("1")){
////							//zcResults.add("40740701");
////							zcResult= "40740701";
////						}
////					}
////    			}
//    		}else{
//				if(tmpSplineResults.contains("")){
//					//zcResults.add("");
//					zcResult = "";
//				}else if(tmpSplineResults.contains("0")){
//					//zcResults.add("40740704");
//					zcResult = "40740704";
//				}else if(tmpSplineResults.contains("1")){
//					//zcResults.add("40740701");
//					zcResult = "40740701";
//				}
//    		}
            if(tmpSplineResults==null){
            	continue;
            }
            if (tmpSplineResults.contains("")) {
                //zcResults.add("");
                zcResult = "";
            } else if (tmpSplineResults.contains("0")) {
                //zcResults.add("40740704");
                zcResult = "40740704";
            } else if (tmpSplineResults.contains("1")) {
                //zcResults.add("40740701");
                zcResult = "40740701";
            }

            if (zcResult.equals("")) {
                if (apply.getJudgeResultCode().equals("40740709")) {
                    zcResult = "40740709";
                }
            } else if (zcResult.equals("40740704")) {
                if (craftProcess.getProcessCode().equals("A")) {
                    b = new SqlBuilder("QcmGpPassApplyDAL.getPassResultByJudgeStoveNo");
                    b.Fill(new String[]{apply.getLoadJudgeStoveNo()});
                    QcmGpPassApplyEntity gpPass = EntityTool.getEntityBySqlNoClsCon(
                            b.toString(), con, QcmGpPassApplyEntity.class);
                    if (gpPass != null) {
                        if (gpPass.getAuditResult2().equals("407502")
                                || gpPass.getAuditResult2().equals("407503")) {
                            b = new SqlBuilder("QcmGpJugdeApplyDAL.queryGpApplyByJudgeStoveNo2");
                            b.Fill(new String[]{apply.getLoadJudgeStoveNo()});
                            List<QcmGpJudgeApplyEntity> gpApplys = EntityTool.getEntitysBySqlNoClsCon(
                                    b.toString(), con, QcmGpJudgeApplyEntity.class);
                            if (gpApplys.size() != 0) {
                                b = new SqlBuilder("JdgPlnOrderZgS.getProPlanIdByDlyPk");
                                b.Fill(new String[]{apply.getOrdLnDlyPk()});
                                List<PlnOrderZgSEntity> plnZgs = EntityTool.getEntitysBySqlNoClsCon(
                                        b.toString(), con, PlnOrderZgSEntity.class);
                                boolean sameOrder = false;
                                for (QcmGpJudgeApplyEntity gpApply : gpApplys) {
                                    for (PlnOrderZgSEntity plnZg : plnZgs) {
                                        if (gpApply.getProPlanId().equals(plnZg.getProPlanId())
                                                && gpApply.getGxPlanNo().equals(plnZg.getGxPlanNo())) {
                                            sameOrder = true;
                                        } else if (gpApply.getProPlanIdNext().equals(plnZg.getProPlanId())
                                                && gpApply.getGxPlanNoNext().equals(plnZg.getGxPlanNo())) {
                                            sameOrder = true;
                                        } else if (gpApply.getProPlanId().equals(plnZg.getGpreqId())) {
                                            sameOrder = true;
                                        } else if (gpApply.getProPlanId().equals(plnZg.getGpreqId())) {
                                            sameOrder = true;
                                        }
                                    }
                                }
                                if (sameOrder) {
                                    zcResult = "40740701";
                                }
                            }
                        }
                    }
                } else {
                    b = new SqlBuilder("JdgQcmBcPassApplyDAL.queryByBatchNo");
                    b.Fill(new String[]{apply.getJugdeApplyCode(), apply.getJudgeStoveNo(), apply.getBatchNo(),
                            apply.getProcessCode(), "0"});
                    QcmBcPassApplyEntity pass = EntityTool.getEntityBySqlNoClsCon(
                            b.toString(), con, QcmBcPassApplyEntity.class);
                    if (pass != null && apply.getJudgeResultCode().equals("40740701")) {
                        //只有合同号一样的放行才有效。
                        if (curApply.getProOrderNo().equals(pass.getProOrderNo())) {
                            zcResult = "40740701";
                        }
                    }
                }
            }
            if (zcResult.equals("") && "120504".equals(curApply.getSupplyUnit())) {
                //throw new Exception(craftProcess.getProcessDesc() + "无法自动给出判定结果！");
                zcResult = "40740704";
            }
            zcResults.add(zcResult);
        }

        return zcResults;
    }

//    private static QcmZcChemPhyDetailEntity fillChemPhyDetail(QcmZcCheckconsignDetailEntity spline){
//    	QcmZcChemPhyDetailEntity detail = new QcmZcChemPhyDetailEntity();
//    	detail.setBarCode(spline.getBarCode());
//    	detail.setCheckNo(spline.getCheckNo());
//    	detail.setCraftSource(spline.getCraftSource());
//    	detail.setDescRate(spline.getDescRate());
//    	detail.setEic(spline.getEic());
//    	detail.setHeadMatNo(spline.getHeadMatNo());
//    	detail.setJfResult(spline.getJfResult());
//    	detail.setMatNo(spline.getMatNo());
//    	detail.setNkResult(spline.getNkResult());
//    	detail.setPhyCodeMin(spline.getPhyCodeMin());
//    	detail.setPhyNameMin(spline.getPhyNameMin());
//    	detail.setRate(spline.getRate());
//    	detail.setResultSource(spline.getResultSource());
//    	detail.setSampleCount(spline.getSampleCount());
//    	detail.setSampleLen(spline.getSampleLen());
//    	detail.setSampleNo(spline.getSampleNo());
//    	detail.setSampleNoMin(spline.getSampleNoMin());
//    	detail.setJudgeStoveNo(spline.getJudgeStoveNo());
//    	detail.setBatchNo(spline.getBatchNo());
//
//    	return detail;
//    }

    private static String[] getDetailResult(String phyCodeMin, ArrayList<String> phyNkResults, ArrayList<String> phyJfResults) {
        String[] detailResults = new String[2];
        String nkResult = "";
        String jfResult = "";
        if (phyNkResults.size() == 0) {
            nkResult = "";
        } else if (phyNkResults.contains("2")) {
            if (phyCodeMin.equals("HX")) {
                if (phyNkResults.contains("1")) {
                    nkResult = "0";
                } else {
                    nkResult = "";
                }
            } else {
                nkResult = "";
            }
        } else if (phyNkResults.contains("3")) {
            nkResult = "";
        } else if (phyNkResults.contains("0")) {
            nkResult = "0";
        } else {
            nkResult = "1";
        }

        if (phyJfResults.size() == 0) {
            jfResult = "";
        } else if (phyJfResults.contains("2")) {
            if (phyCodeMin.equals("HX")) {
                if (phyJfResults.contains("1")) {
                    jfResult = "0";
                } else {
                    jfResult = "";
                }
            } else {
                jfResult = "";
            }
        } else if (phyJfResults.contains("3")) {
            jfResult = "";
        } else if (phyJfResults.contains("0")) {
            jfResult = "0";
        } else {
            jfResult = "1";
        }

        detailResults[0] = nkResult;
        detailResults[1] = jfResult;
        return detailResults;
    }

    public static Object[] chemJudge(QcmJhyElementsEntity jhyChem, ArrayList<CraftOrdDesignStdCicEntity> nkChems,
                                      ArrayList<CraftOrdDesignStdCicEntity> jfChems, String phyCodeMin) {
        Object[] returnResults = new Object[]{"", "", null};
        //判定
        HashMap<String, String[]> jhyResults = new HashMap<String, String[]>();
        Object[] results = ChemJudgeHelper.Judge(jhyChem, nkChems, null, false);
        //添加成分元素
        if (results[1] != null) {
            @SuppressWarnings("unchecked")
            HashMap<String, String[]> judgeJhyResults = (HashMap<String, String[]>) results[1];
            ChemJudgeHelper.mergeChemResult(judgeJhyResults, jhyResults);
        }
        ArrayList<QcmZcChemColresultEntity> zcChemResults = FillZcChemResultEntity(jhyResults);
        results = ChemJudgeHelper.Judge(jhyChem, jfChems, null, true);
        //添加成分元素
        if (results[1] != null) {
            @SuppressWarnings("unchecked")
            HashMap<String, String[]> judgeJhyResults = (HashMap<String, String[]>) results[1];
            FillZcChemResultEntity(judgeJhyResults, zcChemResults);
        }

        ArrayList<String> phyNkResults = new ArrayList<String>();
        ArrayList<String> phyJfResults = new ArrayList<String>();
        for (QcmZcChemColresultEntity chemResult : zcChemResults) {
            phyNkResults.add(chemResult.getNkQualified());
            phyJfResults.add(chemResult.getJfQualified());
        }
        String[] detailResults = BllZcColligateJudge.getDetailResult(phyCodeMin, phyNkResults, phyJfResults);
        returnResults[0] = detailResults[0];
        returnResults[1] = detailResults[1];
        returnResults[2] = zcChemResults;
        return returnResults;
    }

    /**
     * 填充成品成分内控明细
     *
     * @param jhyResults
     * @return
     */
    private static ArrayList<QcmZcChemColresultEntity> FillZcChemResultEntity(
            HashMap<String, String[]> jhyResults) {
        ArrayList<QcmZcChemColresultEntity> results = new ArrayList<QcmZcChemColresultEntity>();
        for (String key : jhyResults.keySet()) {
            QcmZcChemColresultEntity result = new QcmZcChemColresultEntity();
            result.setChemName(key);
            result.setChemValue(jhyResults.get(key)[0]);
            result.setNkMin(jhyResults.get(key)[1]);
            result.setNkMax(jhyResults.get(key)[2]);
            result.setNkQualified(jhyResults.get(key)[3]);
            result.setUnqualifiedType(jhyResults.get(key)[4]);
            results.add(result);
        }

        return results;
    }

    /**
     * 填充成品交付明细
     *
     * @param jhyResults
     */
    private static void FillZcChemResultEntity(HashMap<String, String[]> jhyResults,
                                               ArrayList<QcmZcChemColresultEntity> zcChemResults) {
        for (String key : jhyResults.keySet()) {
            boolean exists = false;
            for (QcmZcChemColresultEntity zcChemResult : zcChemResults) {
                if (zcChemResult.getChemName().equals(key)) {
                    exists = true;
                    zcChemResult.setJfMin(jhyResults.get(key)[1]);
                    zcChemResult.setJfMax(jhyResults.get(key)[2]);
                    zcChemResult.setJfQualified(jhyResults.get(key)[3]);
                    break;
                }
            }
            if (!exists) {
                QcmZcChemColresultEntity zcChemResult = new QcmZcChemColresultEntity();
                zcChemResult.setChemName(key);
                zcChemResult.setChemValue(jhyResults.get(key)[0]);
                zcChemResult.setJfMin(jhyResults.get(key)[1]);
                zcChemResult.setJfMax(jhyResults.get(key)[2]);
                zcChemResult.setJfQualified(jhyResults.get(key)[3]);
                zcChemResult.setUnqualifiedType(jhyResults.get(key)[4]);
                zcChemResults.add(zcChemResult);
            }
        }
    }

    @SuppressWarnings("unchecked")
    private static Object[] phyJudge(ArrayList<QcmJhyPhyresultEntity> jhyPhys, ArrayList<CraftOrdDesignStdPicEntity> nkPhys,
                                     ArrayList<CraftOrdDesignStdPicEntity> jfPhys, QcmZgJugdeApplyEntity apply, String checkNo,
                                     String phyCodeMin, String stoveNo, Connection con) {
        Object[] returnResults = new Object[]{"", "", null};
        ArrayList<QcmZcPhyColresultEntity> zcPhyResults = new ArrayList<QcmZcPhyColresultEntity>();
        //判定内控
        Object[] results = PhyJudgeHelper.judge(jhyPhys, nkPhys, apply.getOrdLnDlyPk(), checkNo, stoveNo, "2", con);
        HashMap<String, QcmBcPhyresultEntity> nkPhyResultMap = new HashMap<String, QcmBcPhyresultEntity>();
        if (results[1] != null) {
            nkPhyResultMap = (HashMap<String, QcmBcPhyresultEntity>) results[1];
        }
        FillPhyResults(zcPhyResults, nkPhyResultMap, jhyPhys, true);

        //判定交付
        Object[] jfResults = PhyJudgeHelper.judge(jhyPhys, jfPhys, apply.getOrdLnDlyPk(),
                checkNo, stoveNo, "1", con);
        HashMap<String, QcmBcPhyresultEntity> jfPhyResultMap = new HashMap<String, QcmBcPhyresultEntity>();
        if (jfResults[1] != null) {
            jfPhyResultMap = (HashMap<String, QcmBcPhyresultEntity>) jfResults[1];
        }
        FillPhyResults(zcPhyResults, jfPhyResultMap, jhyPhys, false);

        ArrayList<String> phyNkResults = new ArrayList<String>();
        ArrayList<String> phyJfResults = new ArrayList<String>();
        for (QcmZcPhyColresultEntity phyResult : zcPhyResults) {
            phyNkResults.add(phyResult.getNkTolQualified());
            phyJfResults.add(phyResult.getJfTolQualified());
        }
        String[] detailResults = BllZcColligateJudge.getDetailResult(phyCodeMin, phyNkResults, phyJfResults);

        returnResults[0] = detailResults[0];
        returnResults[1] = detailResults[1];
        returnResults[2] = zcPhyResults;

        return returnResults;
    }

    /**
     * 填充内控结果和交付结果
     *
     * @param phyResults
     * @param isNk
     */
    private static void FillPhyResults(ArrayList<QcmZcPhyColresultEntity> returnResults,
                                       HashMap<String, QcmBcPhyresultEntity> phyResults, ArrayList<QcmJhyPhyresultEntity> jhyPhys,
                                       boolean isNk) {
        if (phyResults.size() == 0) return;
        for (String key : phyResults.keySet()) {
            QcmBcPhyresultEntity bcPhy = phyResults.get(key);
            for (QcmJhyPhyresultEntity jhyPhyResult : jhyPhys) {
                String tmpStr = jhyPhyResult.getPhyCode() + jhyPhyResult.getItemCodeF()
                        + jhyPhyResult.getItemCodeW() + jhyPhyResult.getItemCodeS();
                if (tmpStr.equals(key)) {
                    bcPhy.setValue1(jhyPhyResult.getValue1());
                    bcPhy.setValue2(jhyPhyResult.getValue2());
                    bcPhy.setValue3(jhyPhyResult.getValue3());
                    bcPhy.setValue4(jhyPhyResult.getValue4());
                    bcPhy.setValue5(jhyPhyResult.getValue5());
                    bcPhy.setValue6(jhyPhyResult.getValue6());
                    bcPhy.setValue7(jhyPhyResult.getValue7());
                    bcPhy.setValue8(jhyPhyResult.getValue8());
                    bcPhy.setValue9(jhyPhyResult.getValue9());
                    bcPhy.setValue10(jhyPhyResult.getValue10());
                    bcPhy.setValue11(jhyPhyResult.getValue11());
                    bcPhy.setValue12(jhyPhyResult.getValue12());
                    bcPhy.setValue13(jhyPhyResult.getValue13());
                    bcPhy.setValue14(jhyPhyResult.getValue14());
                    bcPhy.setValue15(jhyPhyResult.getValue15());
                    bcPhy.setAverage(jhyPhyResult.getAverage());
                    bcPhy.setIsGood(jhyPhyResult.getIsGood());
                    bcPhy.setIsDefect(jhyPhyResult.getIsDefect());
                    bcPhy.setCheckTemp(jhyPhyResult.getCheckTemp());
                    bcPhy.setHardnessType(jhyPhyResult.getHardnessType());
                    bcPhy.setPhyCodeDir(jhyPhyResult.getPhyCodeDir());
                    bcPhy.setPhyNameDir(jhyPhyResult.getPhyNameDir());
                    bcPhy.setSampleStyle(jhyPhyResult.getSampleStyle());
                    bcPhy.setSampleSize(jhyPhyResult.getSampleSize());
                    break;
                }
            }
            QcmZcPhyColresultEntity zcPhy = EntityTool.copy(bcPhy, QcmZcPhyColresultEntity.class);
            if (isNk) {
                returnResults.add(zcPhy);
            } else {
                for (QcmZcPhyColresultEntity returnResult : returnResults) {
                    if (returnResult.getPhyCode().equals(bcPhy.getPhyCode()) &&
                            returnResult.getItemCodeF().equals(bcPhy.getItemCodeF()) &&
                            returnResult.getItemCodeW().equals(bcPhy.getItemCodeW()) &&
                            returnResult.getItemCodeS().equals(bcPhy.getItemCodeS())) {
                        returnResult.setJfAddCondition(bcPhy.getNkAddCondition());
                        returnResult.setJfAddJudgeBasis(bcPhy.getNkAddJudgeBasis());
                        returnResult.setJfAddMax(bcPhy.getNkAddMax());
                        returnResult.setJfAddMin(bcPhy.getNkAddMin());
                        returnResult.setJfJudgeBasis(bcPhy.getNkJudgeBasis());
                        returnResult.setJfMax(bcPhy.getNkMax());
                        returnResult.setJfMin(bcPhy.getNkMin());
                        returnResult.setJfTolQualified(bcPhy.getNkTolQualified());
                    }
                }
            }
        }
    }

    public static ArrayList<CraftOrdDesignMscPlPrcEntity> getCraftPhyProcesses(String ordLnPk, String craftSeq,
                                                                               String mscPline, SqlBuilder b, Connection con) {
        //获取工艺信息
        b = new SqlBuilder("JdgCraftOrdDesignMscPlPrc.getPhyProcessByOrdLnPk");
        b.Fill(new String[]{ordLnPk, craftSeq, mscPline});
        ArrayList<CraftOrdDesignMscPlPrcEntity> craftPrcs = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, CraftOrdDesignMscPlPrcEntity.class);

        return craftPrcs;
    }

    public static ArrayList<CraftOrdDesignMscPlPrcEntity> getCraftProcesses(String ordLnPk, String craftSeq,
                                                                            String mscPline, SqlBuilder b, Connection con) {
        //获取工艺信息
        b = new SqlBuilder("JdgCraftOrdDesignMscPlPrc.getProcessByOrdLnPk");
        b.Fill(new String[]{ordLnPk, craftSeq, mscPline});
        ArrayList<CraftOrdDesignMscPlPrcEntity> craftPrcs = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, CraftOrdDesignMscPlPrcEntity.class);

        return craftPrcs;
    }

    private static ArrayList<CraftOrdDesignStdCicEntity> getLgNkCraftChem(String ordLnPk, String craftSeq,
                                                                          String mscPline, String cic, SqlBuilder b, Connection con) {
        b = new SqlBuilder("CraftOrdDesignStdCic.queryMeltingCraftChemByOrdLnPk");
        b.Fill(new String[]{ordLnPk, craftSeq, mscPline, "A", cic});
        ArrayList<CraftOrdDesignStdCicEntity> craftChems = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, CraftOrdDesignStdCicEntity.class);

        return craftChems;
    }

    private static ArrayList<CraftOrdDesignStdCicEntity> getNkCraftChem(String ordLnPk, String craftSeq,
                                                                        String mscPline, String cic, String craftSource, SqlBuilder b, Connection con) {
        b = new SqlBuilder("CraftOrdDesignStdCic.queryCraftChemByOrdLnPk");
        b.Fill(new String[]{ordLnPk, craftSeq, mscPline, "A", cic, craftSource});
        ArrayList<CraftOrdDesignStdCicEntity> craftChems = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, CraftOrdDesignStdCicEntity.class);

        return craftChems;
    }

    public static ArrayList<CraftOrdDesignStdCicEntity> getJfCraftChem(String ordLnPk, String craftSeq,
                                                                        SqlBuilder b, String processCode, String cic, Connection con) {
        //2020-07-23 增加氧氮氢相关，熔炼判定取内控，成品判定取交付
        if ("A".equals(processCode)) {
            b = new SqlBuilder("CraftOrdDesignStdCic.getCraftJfChemByOrdLnPkMaking");
            b.Fill(new String[]{ordLnPk, craftSeq, cic});
        } else {
            b = new SqlBuilder("CraftOrdDesignStdCic.getCraftJfChemByOrdLnPk");
            b.Fill(new String[]{ordLnPk, craftSeq});
        }
        ArrayList<CraftOrdDesignStdCicEntity> craftChems = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, CraftOrdDesignStdCicEntity.class);

        return craftChems;
    }

    private static ArrayList<CraftOrdDesignStdPicEntity> getNkCraftPhy(String ordLnPk, String craftSeq,
                                                                       String mscPline, String process, String pic, String phyCodeMin, String craftSource,
                                                                       SqlBuilder b, Connection con) {
        b = new SqlBuilder("CraftOrdDesignStdPic.queryCraftPhyByOrdLnPk");
        b.Fill(new Object[]{ordLnPk, craftSeq, mscPline, process, pic, new String[]{phyCodeMin}, craftSource});
        ArrayList<CraftOrdDesignStdPicEntity> craftPhys = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, CraftOrdDesignStdPicEntity.class);

        return craftPhys;
    }

    private static ArrayList<CraftOrdDesignStdPicEntity> getJfCraftPhy(String ordLnPk, String craftSeq,
                                                                       String mscPline, String process, String pic, String phyCodeMin,
                                                                       SqlBuilder b, Connection con) {
        b = new SqlBuilder("CraftOrdDesignStdPic.getCraftJfPhyByOrdLnPk");
        b.Fill(new Object[]{ordLnPk, craftSeq, phyCodeMin});
        ArrayList<CraftOrdDesignStdPicEntity> craftPhys = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, CraftOrdDesignStdPicEntity.class);

        return craftPhys;
    }

    private static ArrayList<CraftOrdDesignStdPicSmpEntity> getCraftPhySmp(String ordLnPk, String craftSeq,
                                                                           String mscPline, String process, String pic, SqlBuilder b, Connection con) {
        b = new SqlBuilder("JdgCraftOrdDesignStdPicSmp.getRate");
        b.Fill(new String[]{ordLnPk, craftSeq, mscPline, process, pic});
        ArrayList<CraftOrdDesignStdPicSmpEntity> craftPhySmps = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, CraftOrdDesignStdPicSmpEntity.class);

        return craftPhySmps;
    }

    private static ArrayList<CraftOrdDesignStdPicSmpEntity> getFdCraftPhySmp(String ordLnPk, String craftSeq,
                                                                             String mscPline, String process, String pic, SqlBuilder b, Connection con) {
        b = new SqlBuilder("JdgCraftOrdDesignStdPicSmp.getFdRate");
        b.Fill(new String[]{ordLnPk, craftSeq});
        ArrayList<CraftOrdDesignStdPicSmpEntity> craftPhySmps = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, CraftOrdDesignStdPicSmpEntity.class);

        return craftPhySmps;
    }

    public static QcmJhyElementsEntity getLgJhyChem(String stoveNo, SqlBuilder b, Connection con) {
        b = new SqlBuilder("QcmJhyElementsDAL.queryByStoveNo");
        b.Fill(new String[]{"A", stoveNo});
        QcmJhyElementsEntity jhyChem = EntityTool.getEntityBySqlNoClsCon(
                b.toString(), con, QcmJhyElementsEntity.class);

        return jhyChem;
    }

    private static QcmJhyElementsEntity getJhyChem(String checkNo, String judgeStoveNo, String batchNo,
                                                   String processCode, String ordLnDlyPk, String sampleNo, SqlBuilder b, Connection con) {
        b = new SqlBuilder("QcmJhyElementsDAL.queryBySampleNo");
        b.Fill(new String[]{processCode, judgeStoveNo, batchNo, checkNo, sampleNo});
        QcmJhyElementsEntity jhyChem = EntityTool.getEntityBySqlNoClsCon(
                b.toString(), con, QcmJhyElementsEntity.class);

        return jhyChem;
    }

    private static ArrayList<QcmJhyPhyresultEntity> getJhyPhys(String checkNo, String judgeStoveNo, String batchNo,
                                                               String processCode, String ordLnDlyPk, String sampleNo, String phyCodeMin, SqlBuilder b, Connection con) {
        b = new SqlBuilder("QcmJhyPhyresultDAL.QueryByBatchNoPhyMin");
        b.Fill(new String[]{judgeStoveNo, batchNo, checkNo, sampleNo, phyCodeMin, processCode});
        ArrayList<QcmJhyPhyresultEntity> jhyPhys = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, QcmJhyPhyresultEntity.class);

        return jhyPhys;
    }


    private static void setJudgeIdIntoZcJudge(String processCode, QcmZcJudgeEntity zcJudge,
                                              HashMap<String, QcmZgJugdeApplyEntity> applyMap) {
        for (String key : applyMap.keySet()) {
            QcmZgJugdeApplyEntity apply = applyMap.get(key);
            if (apply.getProcessCode().equals(processCode)) {
                zcJudge.setZgJudgeId(apply.getJugdeConvicted());
                zcJudge.setZgApplyCode(apply.getJugdeApplyCode());
                break;
            }
        }

        return;
    }

    public static String getLgJudgeStoveNo(String zgLoadJudgeNo, SqlBuilder b, Connection con) {
        String lgJudgeStoveNo = zgLoadJudgeNo;
        b = new SqlBuilder("QcmLgJudgeDAL.queryByJudgeStoveNo");
        b.Fill(new String[]{zgLoadJudgeNo, "B"});
        QcmLgJudgeEntity lgJudge = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, QcmLgJudgeEntity.class);
        if (lgJudge == null) {
            b = new SqlBuilder("JdgQcmGpJudgeChange.getJudgeStoveNo");
            b.Fill(new String[]{zgLoadJudgeNo});
            QcmLgJudgeEntity gpChange = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, QcmLgJudgeEntity.class);
            if (gpChange != null) {
                lgJudgeStoveNo = gpChange.getJudgeStoveNo();
            }
        }

        return lgJudgeStoveNo;
    }

//    /**
//     * 查询轧管工序的上料炉号
//     * @param judgeStoveNo
//     * @param processCode
//     * @param con
//     * @return
//     */
//    public static String getZgLoadJudgeStoveNo(String judgeStoveNo, String batchNo, String processCode,
//    		String phyProcess, Connection con){
//    	SqlBuilder b = null;
//    	if(processCode.toCharArray()[0] >= phyProcess.toCharArray()[0]){
//    		b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo2");
//    		b.Fill(new String[]{ judgeStoveNo, batchNo, processCode });
//    	}else{
//    		b = new SqlBuilder("QcmZgJugdeApplyDAL.GetByJudgeStoveNo");
//    		b.Fill(new String[]{ judgeStoveNo, processCode });
//    	}
//		QcmZgJugdeApplyEntity apply = EntityTool.getEntityBySqlNoClsCon(
//				b.toString(), con, QcmZgJugdeApplyEntity.class);
//    	if(processCode.toCharArray()[0] <= 'D'){
//    		if(apply == null){
//    			return null;
//    		}else{
//    			return apply.getLoadJudgeStoveNo();
//    		}
//    	}else{
//    		String loadJudgeStoveNo = "";
//    		if(apply == null){
//    			loadJudgeStoveNo = judgeStoveNo;
//    		}else{
//    			loadJudgeStoveNo = apply.getLoadJudgeStoveNo();
//    		}
//    		char cProcessCode = (char)(processCode.toCharArray()[0] - 1);
//    		return getZgLoadJudgeStoveNo(loadJudgeStoveNo, batchNo, String.valueOf(cProcessCode), phyProcess, con);
//    	}
//    }

    /**
     * 查询所有送判信息
     *
     * @param judgeStoveNo
     * @param processCode
     * @param con
     * @return
     */
    public static HashMap<String, QcmZgJugdeApplyEntity> getAllJudgeApply(String judgeApplyCode, String judgeStoveNo,
                                                                          String batchNo, String processCode, String heatPlanNo, HashMap<String, QcmZgJugdeApplyEntity> map,
                                                                          JudgeCraftParam zzbCp, Connection con) {
        if (map == null) {
            map = new HashMap<String, QcmZgJugdeApplyEntity>();
        }
        SqlBuilder b = null;
        if (judgeApplyCode.equals("")) {
            b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo2");
            b.Fill(new String[]{judgeStoveNo, batchNo, processCode, heatPlanNo});
        } else {
            b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
            b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo});
        }

        QcmZgJugdeApplyEntity apply = EntityTool.getEntityBySqlNoClsCon(
                b.toString(), con, QcmZgJugdeApplyEntity.class);
        if (apply != null) {
            if (zzbCp != null)//合同管转备料管
            {
                apply.setOrdLnDlyPk(zzbCp.getOrdLnDlyPk());
                apply.setCraftSeq(zzbCp.getCraftSeq());
                apply.setIndexSeq(zzbCp.getMscPline());
                apply.setCic(zzbCp.getCic());
                b = new SqlBuilder("CraftOrdDesignStdPic.getNkMinPic");
                b.Fill(new String[]{zzbCp.getOrdLnPk(), zzbCp.getCraftSeq(), zzbCp.getMscPline(),
                        apply.getProcessCode()});
                CraftOrdDesignStdPicEntity stdPic = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, CraftOrdDesignStdPicEntity.class);
                apply.setPic(stdPic.getPic());
            }
            map.put(apply.getProcessCode(), apply);

            //合同管转备料管
            if (apply.getOrdLnDlyPk().startsWith("ZZB")) {
                zzbCp = getCraftParm(null, apply, b, con);
            }
        }
        if (apply != null) {
            if ("6".equals(apply.getIsAllScrap()) && !"".equals(apply.getLoadBatchNo())) {
                return getAllJudgeApply("", apply.getLoadJudgeStoveNo(), apply.getLoadBatchNo(), "H", getUpperPlanId(apply.getHeatPlanNo(), processCode, b, con),
                        null, zzbCp, con);
            }
        }
        if (processCode.toCharArray()[0] <= 'D') {
            return map;
        } else {
            String loadJudgeStoveNo = "";
            String loadBatchNo = "";
            String upHeatPlanNo = "";
            if (apply == null) {
                loadJudgeStoveNo = judgeStoveNo;
                loadBatchNo = batchNo;
                upHeatPlanNo = heatPlanNo;
            } else {
                loadJudgeStoveNo = apply.getLoadJudgeStoveNo();
                loadBatchNo = apply.getLoadBatchNo();
                upHeatPlanNo = getUpperPlanId(apply.getHeatPlanNo(), processCode, b, con);
            }
            char cProcessCode = (char) (processCode.toCharArray()[0] - 1);
            return getAllJudgeApply("", loadJudgeStoveNo, loadBatchNo, String.valueOf(cProcessCode),
                    upHeatPlanNo, map, zzbCp, con);
        }
    }


    /**
     * 查询所有送判信息(不带批号)
     *
     * @param judgeStoveNo
     * @param processCode
     * @param con
     * @return
     */
    public static HashMap<String, QcmZgJugdeApplyEntity> getAllJudgeApplyNoBatch(String judgeApplyCode, String judgeStoveNo,
                                                                                 String processCode, String heatPlanNo, HashMap<String, QcmZgJugdeApplyEntity> map,
                                                                                 JudgeCraftParam zzbCp, Connection con) {
        if (map == null) {
            map = new HashMap<String, QcmZgJugdeApplyEntity>();
        }
        SqlBuilder b = null;
        if (judgeApplyCode.equals("")) {
            b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryNoBatchNo2");
            b.Fill(new String[]{judgeStoveNo, processCode, heatPlanNo});
        } else {
            b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryNoBatchNo");
            b.Fill(new String[]{judgeApplyCode, judgeStoveNo});
        }

        QcmZgJugdeApplyEntity apply = EntityTool.getEntityBySqlNoClsCon(
                b.toString(), con, QcmZgJugdeApplyEntity.class);
        if (apply != null) {
            if (zzbCp != null)//合同管转备料管
            {
                apply.setOrdLnDlyPk(zzbCp.getOrdLnDlyPk());
                apply.setCraftSeq(zzbCp.getCraftSeq());
                apply.setIndexSeq(zzbCp.getMscPline());
                apply.setCic(zzbCp.getCic());
                b = new SqlBuilder("CraftOrdDesignStdPic.getNkMinPic");
                b.Fill(new String[]{zzbCp.getOrdLnPk(), zzbCp.getCraftSeq(), zzbCp.getMscPline(),
                        apply.getProcessCode()});
                CraftOrdDesignStdPicEntity stdPic = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, CraftOrdDesignStdPicEntity.class);
                apply.setPic(stdPic.getPic());
            }
            map.put(apply.getProcessCode(), apply);

            //合同管转备料管
            if (apply.getOrdLnDlyPk().startsWith("ZZB")) {
                zzbCp = getCraftParm(null, apply, b, con);
            }
        }

        if (processCode.toCharArray()[0] <= 'D') {
            return map;
        } else {
            String loadJudgeStoveNo = "";
            String upHeatPlanNo = "";
            if (apply == null) {
                loadJudgeStoveNo = judgeStoveNo;
                upHeatPlanNo = heatPlanNo;
            } else {
                loadJudgeStoveNo = apply.getLoadJudgeStoveNo();
                upHeatPlanNo = getUpperPlanId(apply.getHeatPlanNo(), processCode, b, con);
            }
            char cProcessCode = (char) (processCode.toCharArray()[0] - 1);
            return getAllJudgeApplyNoBatch("", loadJudgeStoveNo, String.valueOf(cProcessCode),
                    upHeatPlanNo, map, zzbCp, con);
        }
    }

    private static String getUpperPlanId(String headPlanNo, String processCode, SqlBuilder b, Connection con) {
        if (processCode.equals("D")) {
            b = new SqlBuilder("JdgPlnZyZgM.queryUpperByPk");
            b.Fill(new String[]{headPlanNo});
        } else if (processCode.equals("E")) {
            b = new SqlBuilder("JdgPlnZyDbkM.queryUpperByPk");
            b.Fill(new String[]{headPlanNo});
        } else if (processCode.equals("F")) {
            b = new SqlBuilder("JdgPlnZyRclM.queryUpperByPk");
            b.Fill(new String[]{headPlanNo});
        } else if (processCode.equals("G")) {
            b = new SqlBuilder("JdgPlnZyJgxM.queryUpperByPk");
            b.Fill(new String[]{headPlanNo});
        } else if (processCode.equals("H")) {
            b = new SqlBuilder("JdgPlnZyJgM.queryUpperByPk");
            b.Fill(new String[]{headPlanNo});
        } else {
            return headPlanNo;
        }

        PlnZyZgMEntity upper = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnZyZgMEntity.class);
        if (upper == null) return "";
        if (processCode.equals(upper.getUpperProcessCode())) {
            return getUpperPlanId(upper.getUpperHeatplanId(), processCode, b, con);
        } else {
            return upper.getUpperHeatplanId();
        }
    }

    public static String getJudgeResult(HashMap<String, QcmZgJugdeApplyEntity> applyMap, String lgJudgeStoveNo,
                                        Connection con) throws Exception {
        String judgeResult = "40740701";
        if (applyMap.size() == 0) throw new Exception("该炉号判定记录异常！");
        for (String key : applyMap.keySet()) {
            QcmZgJugdeApplyEntity apply = applyMap.get(key);
            if (apply.getJudgeResultCode().equals("")) {
                judgeResult = apply.getJudgeResultCode();
            } else if (apply.getJudgeResultCode().equals("40740709") && !judgeResult.equals("")) {
                judgeResult = apply.getJudgeResultCode();
            }
        }

        for (String key : applyMap.keySet()) {
            QcmZgJugdeApplyEntity apply = applyMap.get(key);
            if (apply.getProcessCode().equals("D")) {
                SqlBuilder b = new SqlBuilder("QcmLgJudgeDAL.queryByJudgeStoveNo");
                b.Fill(new String[]{lgJudgeStoveNo, "B"});
                QcmLgJudgeEntity lgJudge = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, QcmLgJudgeEntity.class);
                if (lgJudge == null) {
                    b = new SqlBuilder("JdgQcmGpJudgeChange.getJudgeStoveNo");
                    b.Fill(new String[]{lgJudgeStoveNo, "B"});
                    QcmGpJudgeChangeEntity judgeChange = EntityTool.getEntityBySqlNoClsCon(
                            b.toString(), con, QcmGpJudgeChangeEntity.class);
                    if (judgeChange == null) {
                        //throw new Exception("找不到该判定炉号对应的炼钢判定信息！");
                        break;
                    }
                    b = new SqlBuilder("QcmLgJudgeDAL.queryByJudgeStoveNo");
                    b.Fill(new String[]{judgeChange.getJudgeStoveNo(), "B"});
                    lgJudge = EntityTool.getEntityBySqlNoClsCon(
                            b.toString(), con, QcmLgJudgeEntity.class);
                }

                if (lgJudge == null) break;
                if (lgJudge.getJudgeresult().equals("")) {
                    judgeResult = lgJudge.getJudgeresult();
                } else if (lgJudge.getJudgeresult().equals("40740704") && !judgeResult.equals("")) {
                    judgeResult = lgJudge.getJudgeresult();
                }
                break;
            }
        }

        return judgeResult;
    }

    private static String getFaceResult(HashMap<String, QcmZgJugdeApplyEntity> applyMap, Connection con) {
        String faceResult = "";
        for (String key : applyMap.keySet()) {
            QcmZgJugdeApplyEntity apply = applyMap.get(key);
            if (!apply.getFaceResultCode().equals("")) {
                if (faceResult.equals("")) {
                    faceResult = apply.getFaceResultCode();
                } else {
                    if (apply.getFaceResultCode().equals("40740602")) {
                        faceResult = apply.getFaceResultCode();
                    }
                }
            }
        }

        return faceResult;
    }

    private static String getSpecResult(HashMap<String, QcmZgJugdeApplyEntity> applyMap, Connection con) {
        String specResult = "";
        for (String key : applyMap.keySet()) {
            QcmZgJugdeApplyEntity apply = applyMap.get(key);
            if (!apply.getSpecResultCode().equals("")) {
                if (specResult.equals("")) {
                    specResult = apply.getSpecResultCode();
                } else {
                    if (apply.getSpecResultCode().equals("40740302")) {
                        specResult = apply.getSpecResultCode();
                    }
                }
            }
        }

        return specResult;
    }

    private static String getDetectResult(HashMap<String, QcmZgJugdeApplyEntity> applyMap, Connection con) {
        String detectResult = "";
        for (String key : applyMap.keySet()) {
            QcmZgJugdeApplyEntity apply = applyMap.get(key);
            if (!apply.getDetectResultCode().equals("")) {
                if (detectResult.equals("")) {
                    detectResult = apply.getDetectResultCode();
                } else {
                    if (apply.getDetectResultCode().equals("40740402")) {
                        detectResult = apply.getDetectResultCode();
                    }
                }
            }
        }

        return detectResult;
    }

    private static String getWaterResult(HashMap<String, QcmZgJugdeApplyEntity> applyMap, Connection con) {
        String waterResult = "";
        for (String key : applyMap.keySet()) {
            QcmZgJugdeApplyEntity apply = applyMap.get(key);
            if (!apply.getWpressureResultCode().equals("")) {
                if (waterResult.equals("")) {
                    waterResult = apply.getWpressureResultCode();
                } else {
                    if (apply.getWpressureResultCode().equals("40740502")) {
                        waterResult = apply.getWpressureResultCode();
                    }
                }
            }
        }

        return waterResult;
    }

    private static String getProcessResult(HashMap<String, QcmZgJugdeApplyEntity> applyMap, Connection con) {
        String processResult = "";
        for (String key : applyMap.keySet()) {
            QcmZgJugdeApplyEntity apply = applyMap.get(key);
            if (!apply.getProcessResultCode().equals("")) {
                if (processResult.equals("")) {
                    processResult = apply.getProcessResultCode();
                } else {
                    if (apply.getProcessResultCode().equals("40740802")) {
                        processResult = apply.getProcessResultCode();
                    }
                }
            }
        }

        return processResult;
    }

//    private String getChemResult(String matNo, String processCode, Connection con){
//    	SqlBuilder b;
//    	if(processCode.toCharArray()[0] < 'D'){
//    		b = new SqlBuilder("JdgMatBcQcmTrack.getByMatNoFirstRow");
//    		b.Fill(new String[]{ matNo, "D" });
//    		MatBcQcmtrackEntity qcmTrack = EntityTool.getEntityBySqlNoClsCon(
//        			b.toString(), con, MatBcQcmtrackEntity.class);
//    		b = new SqlBuilder("QcmLgJudgeDAL.queryByJudgeStoveNo");
//        	b.Fill(new String[]{ qcmTrack.getJudgeStoveNo(), "B" });
//            QcmLgJudgeEntity lgJudge = EntityTool.getEntityBySqlNoClsCon(
//        			b.toString(), con, QcmLgJudgeEntity.class);
//        	return lgJudge.getJudgeresultChem();
//    	}else{
//    		b = new SqlBuilder("JdgMatBcQcmTrack.getByMatNoFirstRow");
//    		b.Fill(new String[]{ matNo, processCode });
//    		MatBcQcmtrackEntity qcmTrack = EntityTool.getEntityBySqlNoClsCon(
//        			b.toString(), con, MatBcQcmtrackEntity.class);
//    		b = new SqlBuilder("JdgQcmBcJudge.getByJudgeId");
//    		b.Fill(new String[]{ qcmTrack.getMatNo() });
//    		QcmZcJudgeEntity zcJudge = EntityTool.getEntityBySqlNoClsCon(
//        			b.toString(), con, QcmZcJudgeEntity.class);
//    		if(zcJudge != null && !zcJudge.getChemResult().equals("")){
//    			return zcJudge.getChemResult();
//    		}else{
//    			processCode = String.valueOf((char)(processCode.toCharArray()[0] - 1));
//    			return getChemResult(matNo, processCode, con);
//    		}
//    	}
//    }

//    private String getPhyResult(String matNo, String processCode, Connection con){
//    	SqlBuilder b = new SqlBuilder("JdgMatBcQcmTrack.getByMatNoFirstRow");
//    	b.Fill(new String[]{ matNo, processCode });
//    	MatBcQcmtrackEntity qcmTrack = EntityTool.getEntityBySqlNoClsCon(
//    			b.toString(), con, MatBcQcmtrackEntity.class);
//		b = new SqlBuilder("JdgQcmBcJudge.getByJudgeId");
//    	b.Fill(new String[]{ qcmTrack.getJugdeConvicted() });
//    	QcmBcJudgeEntity bcJudge = EntityTool.getEntityBySqlNoClsCon(
//    			b.toString(), con, QcmBcJudgeEntity.class);
//    	if(bcJudge != null && !bcJudge.getPhyResult().equals("")){
//    		return bcJudge.getPhyResult();
//    	}else{
//    		return "";
//    	}
//    }

    public CoreReturnObject deleteJudge(String judgeApplyCode, String judgeStoveNo,
                                        String batchNo, String processCode, String user) {
        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();

            b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
            b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo});
            QcmZgJugdeApplyEntity judgeApply = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, QcmZgJugdeApplyEntity.class);
            if (judgeApply.getIsCarryVoer().equals("1")) {
                cro.setV_errMsg("此炉号已月末结转，不能撤销判定！");
                return cro;
            }
            if (judgeApply.getInstockFlag().equals("1") && !judgeApply.getIsAllScrap().equals("4")) {
                cro.setV_errMsg("此炉批已缴库，不能撤销判定！");
                return cro;
            }
//        	if(judgeApply.getZbsFlag().equals("2")){
//        		cro.setV_errMsg("此炉批在老系统出质保书，不能撤销判定！");
//                return cro;
//        	}
            if (judgeApply.getIsAllScrap().equals("4")) {
                b = new SqlBuilder("JdgMatZcM.getMatStatus80150301");
                b.Fill(new String[]{judgeApply.getJudgeStoveNo(), judgeApply.getBatchNo(), judgeApply.getBatchGroudNo(), judgeApply.getOrdLnDlyPk()});
                MatZcMEntity zcMat = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, MatZcMEntity.class);
                if (zcMat != null) {
                    cro.setV_errMsg("物料状态已改变，不能撤销判定！");
                    return cro;
                }
            }

            //是否正在放行
            b = new SqlBuilder("JdgQcmZcPassApplyDAL.queryByBatchNo");
            b.Fill(new String[]{judgeApply.getJugdeApplyCode(), judgeStoveNo, batchNo});
            QcmZcPassApplyEntity passApply = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, QcmZcPassApplyEntity.class);
            if (passApply != null && passApply.getAuditResult().equals("")) {
                cro.setV_errMsg("此炉号有放行单正在审核，不能撤销判定！");
                return cro;
            }

            //如果有处置方式，撤销判定只修改状态。
            if (judgeApply.getAuditResult().equals("407504") || judgeApply.getAuditResult().equals("407505")
                    || judgeApply.getAuditResult().equals("407506")) {
                b = new SqlBuilder("QcmZgJugdeApplyDAL.setValidflagZc");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, processCode, "00"});
                st.executeUpdate(b.toString());
            } else {
                b = new SqlBuilder("QcmZgJugdeApplyDAL.setJudgeResultZc");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, processCode, "",
                        "", "", "", "", "", "", "1"});
                st.executeUpdate(b.toString());
                b = new SqlBuilder("QcmZgJugdeApplyDAL.setJudgeTimeZc");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, processCode, ""});
                st.executeUpdate(b.toString());

                //更新质保书标志
                b = new SqlBuilder("QcmZgJugdeApplyDAL.setZbsFlag");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, "0"});
                st.executeUpdate(b.toString());
                b = new SqlBuilder("JdgMatBcM.setZbsFlag");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, "0"});
                st.executeUpdate(b.toString());
                b = new SqlBuilder("JdgMatBcBackup.setZbsFlag");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, "0"});
                st.executeUpdate(b.toString());

                //修改紧急放行标志
                b = new SqlBuilder("QcmZgJugdeApplyDAL.setTolInstancyFlag");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, processCode, "0"});
                st.executeUpdate(b.toString());
                //更新申请放行记录
                b = new SqlBuilder("JdgQcmZcPassApplyDAL.setValidflag");
                b.Fill(new String[]{judgeStoveNo, batchNo, judgeApplyCode, "0", user});
                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("4")) {
                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);
                if (judgeApply.getZbsFlag().equals("2")) {
                    new FrmBcIqInList().insertMatBcA(con, zgJudges);
                }
            }

            //更新材料表
            b = new SqlBuilder("JdgMatBcM.updateTolJudgeResult");
            b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, "", "", ""});
            st.executeUpdate(b.toString());
            b = new SqlBuilder("JdgMatBcM.updateTolJudgeTime");
            b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, ""});
            st.executeUpdate(b.toString());
            //更新材料历史表
            b = new SqlBuilder("JdgMatBcBackup.updateTolJudgeResult");
            b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, "", "", ""});
            st.executeUpdate(b.toString());
            b = new SqlBuilder("JdgMatBcBackup.updateTolJudgeTime");
            b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, ""});
            st.executeUpdate(b.toString());

            //更新半成品材料表的所属权
            String judgeTolResult = judgeApply.getJudgeTolresultCode();
            if (!judgeTolResult.equals("40740709") && !judgeTolResult.equals("40740704")) {
                //*********************更新材料表所属权
                b = new SqlBuilder("JdgMatBcM.updateBelongZc");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, judgeApply.getBelongCode(), judgeApply.getBelongName()});
                st.executeUpdate(b.toString());

                //更新材料历史表所属权
                b = new SqlBuilder("JdgMatBcBackup.updateBelongZc");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo, judgeApply.getBelongCode(), judgeApply.getBelongName()});
                st.executeUpdate(b.toString());
            }

            if (judgeApply.getIsAllScrap().equals("4")) {
                //更新利库改判表
                b = new SqlBuilder("JdgQcmLkJudgeChange.setAgreeFlag");
                b.Fill(new String[]{judgeApply.getJugdeApplyCode() + judgeApply.getJugdeApplySequeno(), "1"});
                st.executeUpdate(b.toString());
                b = new SqlBuilder("JdgMatZcM.setLkLock");
                b.Fill(new String[]{judgeStoveNo, batchNo, judgeApply.getBatchGroudNo(), judgeApply.getOrdLnDlyPk(), "1", "2"});
                st.executeUpdate(b.toString());
            }

            // 余材转压库综合判定 产权出库记录
            if (judgeApply.getIsAllScrap().equals("8")) {
                OverstockPipe overstockPipe = new OverstockPipe();
                overstockPipe.deleteOutstockDoc(con,cro,judgeApplyCode);
            }

            //更新接箍材料表
            CouplingMatMEntity couplingMatM = new CouplingMatMEntity();
            couplingMatM.setJudgeTolresult("");
            couplingMatM.setJudgeTolresultCode("");
            couplingMatM.setJudgeTolmaker("");
            couplingMatM.setJudgeStoveNo(judgeApply.getJudgeStoveNo());
            couplingMatM.setBatchNo(judgeApply.getBatchNo());
            couplingMatM.setDeterNo(judgeApply.getJugdeApplyCode());
            couplingMatM.setWoId(judgeApply.getProOrderId());
            String setJgJudgeInfo = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatM.setTolJudgeInfo");
            setJgJudgeInfo = EntityTool.fillSqlByEntity(setJgJudgeInfo, couplingMatM);
            st.executeUpdate(setJgJudgeInfo);
            String setZbs = CoreXmlSqlParsersFactory.getSql("JdgCouplingMatM.setZbsId");
            setZbs = EntityTool.fillSqlByEntity(setZbs, couplingMatM);
            st.executeUpdate(setZbs);

            //crm同步
            if (judgeTolResult.equals("40740709") || judgeTolResult.equals("40740701")) {
                b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo});
                QcmZgJugdeApplyEntity CrmZgJudgeApply = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, QcmZgJugdeApplyEntity.class);
                CrmOrderProduceService crmOrderProduceService = new CrmOrderProduceService();
                crmOrderProduceService.insertJudgeCPCrmOrderProduce(con, CrmZgJudgeApply, 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("JdgQcmZcJudge.updateMemo");
            b.Fill(new String[]{parm[1], parm[2], parm[3], parm[4]});
            sqllist.add(b.toString());

            b = new SqlBuilder("QcmZgJugdeApplyDAL.udpateJudgeTolMemo");
            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);
    }

    public CoreReturnObject updateLotNoGroup(String[] parm) {
        parm[7] = UUID.randomUUID().toString().replace("-","");
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateZgLotNoGroup");
        b.Fill(parm);
        sqllist.add(b.toString());
        b = new SqlBuilder("QcmZgJugdeApplyDAL.insertLotNoRecord");
        b.Fill(parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    public CoreReturnObject updateCic(String[] parm) {
        parm[7] = UUID.randomUUID().toString().replace("-","");
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateZgCic");
        b.Fill(parm);
        sqllist.add(b.toString());
        b = new SqlBuilder("QcmZgJugdeApplyDAL.insertLotNoRecord");
        b.Fill(parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    public CoreReturnObject updatePic(String[] parm) {
        parm[7] = UUID.randomUUID().toString().replace("-","");
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateZgPic");
        b.Fill(parm);
        sqllist.add(b.toString());
        b = new SqlBuilder("QcmZgJugdeApplyDAL.insertLotNoRecord");
        b.Fill(parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    public CoreReturnObject updateZcCic(String[] parm) {
        parm[7] = UUID.randomUUID().toString().replace("-","");
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateZcCic");
        b.Fill(parm);
        sqllist.add(b.toString());
        b = new SqlBuilder("QcmZgJugdeApplyDAL.insertLotNoRecord");
        b.Fill(parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    public CoreReturnObject updateZcPic(String[] parm) {
        parm[7] = UUID.randomUUID().toString().replace("-","");
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateZcPic");
        b.Fill(parm);
        sqllist.add(b.toString());
        b = new SqlBuilder("QcmZgJugdeApplyDAL.insertLotNoRecord");
        b.Fill(parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    public CoreReturnObject updateZcLotNoGroup(String[] parm) {
        parm[7] = UUID.randomUUID().toString().replace("-","");
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateZcLotNoGroup");
        b.Fill(parm);
        sqllist.add(b.toString());
        b = new SqlBuilder("QcmZgJugdeApplyDAL.insertLotNoRecord");
        b.Fill(parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    public CoreReturnObject updateLotNo(String[] parm) {
        parm[7] = UUID.randomUUID().toString().replace("-","");
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateZgLotNo");
        b.Fill(parm);
        sqllist.add(b.toString());
        b = new SqlBuilder("QcmZgJugdeApplyDAL.insertLotNoRecord");
        b.Fill(parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    public CoreReturnObject updateZcLotNo(String[] parm) {
        parm[7] = UUID.randomUUID().toString().replace("-","");
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateZcLotNo");
        b.Fill(parm);
        sqllist.add(b.toString());
        b = new SqlBuilder("QcmZgJugdeApplyDAL.insertLotNoRecord");
        b.Fill(parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    public CoreReturnObject updateDeliveryStateZG(String[] parm) {
        parm[7] = UUID.randomUUID().toString().replace("-","");
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateDeliveryStateZG");
        b.Fill(parm);
        sqllist.add(b.toString());
        b = new SqlBuilder("QcmZgJugdeApplyDAL.insertLotNoRecord");
        b.Fill(parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    /**
     * 放行申请
     *
     * @param parms
     * @param user
     * @param unit
     * @param memo
     * @param passType
     * @return
     */
    public CoreReturnObject passApply(ArrayList<String[]> parms,
                                      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];
                String processCode = parm[3];
                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.getJudgeTolresultCode().equals("40740704") && !zgJudgeApply.getJudgeTolresultCode().equals("40740708")) {
                        cro.setV_errMsg("只有判定不合格的记录，才能申请质量放行！");
                        return cro;
                    }
                } else {
                    if (!zgJudgeApply.getJudgeTolresultCode().equals("")) {
                        cro.setV_errMsg("已判定的记录不能申请紧急放行！");
                        return cro;
                    }
                }

                ResultSet rs = st.executeQuery(CoreXmlSqlParsersFactory.getSql(
                        "JdgQcmZcPassApplyDAL.getMaxPk"));
                String passApplyNo = "";
                if (rs.next()) {
                    passApplyNo = rs.getString(1);
                    rs.close();
                }

                b = new SqlBuilder("JdgQcmZcPassApplyDAL.GetApplyCnt");
                b.Fill(new String[]{judgeApplyCode, judgeStoveNo, batchNo});
                ResultSet rsBcApplyCnt = st.executeQuery(b.toString());
                int gpApplyCnt = 0;
                if (rsBcApplyCnt.next()) {
                    gpApplyCnt = rsBcApplyCnt.getInt(1);
                }
                if (gpApplyCnt > 0) //如果有放行申请单，则不重复生成。
                {
                    continue;
                }

                //如果存在有效的放行单，作废掉。 （紧急放行后可以操作质量放行。）
                b = new SqlBuilder("JdgQcmZcPassApplyDAL.setValidflag");
                b.Fill(new String[]{judgeStoveNo, batchNo, judgeApplyCode, "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);
                b = new SqlBuilder("JdgQcmZcJudge.getByBatchNo");
                b.Fill(new String[]{judgeStoveNo, batchNo, processCode, judgeApplyCode});
                QcmZcJudgeEntity zcJudge = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, QcmZcJudgeEntity.class);
                for (QcmZgJugdeApplyEntity zgJudgeApplySub : zgJudgeApplys) {
                    b = new SqlBuilder("JdgQcmZcPassApplyDAL.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("JdgQcmZcPassApplyDAL.Insert");
                    zgJudgeApplySub.setMemo(memo);
                    zgJudgeApplySub.setChemResultCode(zcJudge.getChemResult());
                    zgJudgeApplySub.setPhyResultCode(zcJudge.getPhyResult());
                    zgJudgeApplySub.setDetectResultCode(zcJudge.getDetectResult());
                    zgJudgeApplySub.setFaceResultCode(zcJudge.getFaceResult());
                    zgJudgeApplySub.setSpecCode(zcJudge.getSpecResult());
                    zgJudgeApplySub.setWpressureResultCode(zcJudge.getWaterResult());
                    zgJudgeApplySub.setProcessResultCode(zcJudge.getProcessResult());
                    zgJudgeApplySub.setJudgeResultCode(zcJudge.getJudgeResult());

                    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.getByJudgeResult");
                b.Fill(new String[]{zgJudgeApply.getJudgeTolresultCode(), "0", seamArea});
                ArrayList<QcmBcPassConfigEntity> passConfigs = EntityTool.getEntitysBySqlNoClsCon(
                        b.toString(), con, QcmBcPassConfigEntity.class);
                for (QcmBcPassConfigEntity passConfig : passConfigs) {
                    b = new SqlBuilder("JdgQcmZcPassFlow.insert");
                    String ctrAuditStep = "0";
                    if (passConfig.getAuditStep().equals("1")) {
                        ctrAuditStep = "1";
                    }
                    b.Fill(new String[]{passApplyNo, passConfig.getAuditStep(),
                            passConfig.getAuditUnit(), ctrAuditStep});
                    st.executeUpdate(b.toString());
                }
            }
            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();
            }
        }
    }

    public static List<HttCrackDetectionParaEntity> getDetectInfo(String judgeStoveNo, String batchNo,
                                                                  String processCode, String zpMLh, Connection con) throws Exception {
        CoreReturnObject cro = new CoreReturnObject();
        SqlBuilder b = null;
        List<HttCrackDetectionParaEntity> detects = new ArrayList<HttCrackDetectionParaEntity>();

        if (processCode.equals("D")) {
            b = new SqlBuilder("JdgHttCrackDetectionEt.getZgInfo");
            b.Fill(new String[]{judgeStoveNo, batchNo});
        } else if (processCode.equals("E")) {
            b = new SqlBuilder("JdgHttCrackDetectionEt.getDbkInfo");
            b.Fill(new String[]{judgeStoveNo, batchNo, processCode});
        } else {
            b = new SqlBuilder("JdgHttCrackDetectionEt.getInfo");
            b.Fill(new String[]{judgeStoveNo, batchNo, processCode});
        }

        List<HttCrackDetectionParaEntity> tmpDetects = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, HttCrackDetectionParaEntity.class);
        for (HttCrackDetectionParaEntity tmpDetect : tmpDetects) {
            detects.add(tmpDetect);
        }

        if (!zpMLh.equals("")) {
            ArrayList<VrpGroupResultEntity> groupResults = BllCreateGroupStoveInfo.getOldStoveNo(
                    judgeStoveNo, processCode, b, con);
            for (VrpGroupResultEntity groupResult : groupResults) {
                if (processCode.equals("D")) {
                    b = new SqlBuilder("JdgHttCrackDetectionEt.getZgInfo");
                    b.Fill(new String[]{groupResult.getJudgeStoveNo(), groupResult.getBatchNo()});
                } else {
                    b = new SqlBuilder("JdgHttCrackDetectionEt.getInfo");
                    b.Fill(new String[]{groupResult.getJudgeStoveNo(), groupResult.getBatchNo(),
                            processCode});
                }
                tmpDetects = EntityTool.getEntitysBySqlNoClsCon(
                        b.toString(), con, HttCrackDetectionParaEntity.class);
                for (HttCrackDetectionParaEntity tmpDetect : tmpDetects) {
                    detects.add(tmpDetect);
                }
            }
        }

        return detects;
    }

    public CoreReturnObject getDetectInfo(String judgeStoveNo, String batchNo, String processCode, String zpMLh) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection con = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            List<HttCrackDetectionParaEntity> detects = getDetectInfo(judgeStoveNo,
                    batchNo, processCode, zpMLh, con);

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

    public CoreReturnObject getFaceInfo(String judgeStoveNo, String batchNo, String processCode, String zpMLh) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection con = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            SqlBuilder b = null;
            List<HttAppearancecheckResultEntity> faces = new ArrayList<HttAppearancecheckResultEntity>();

            if (processCode.equals("A")) {
                b = new SqlBuilder("JdgStlLgSurfaceM.getInfo");
                b.Fill(new String[]{judgeStoveNo});
            } else if (processCode.equals("D")) {
                b = new SqlBuilder("JdgMilSurfaceResult.getInfo");
                b.Fill(new String[]{judgeStoveNo});
            } else {
                b = new SqlBuilder("JdgHttAppearanceCheckResult.getInfo");
                b.Fill(new String[]{judgeStoveNo, processCode});
            }

            List<HttAppearancecheckResultEntity> tmpFaces = EntityTool.getEntitysBySqlNoClsCon(
                    b.toString(), con, HttAppearancecheckResultEntity.class);
            if (tmpFaces != null) {
                for (HttAppearancecheckResultEntity tmpFace : tmpFaces) {
                    faces.add(tmpFace);
                }
            }
            if (!zpMLh.equals("")) {
                ArrayList<VrpGroupResultEntity> groupResults = BllCreateGroupStoveInfo.getOldStoveNo(
                        judgeStoveNo, processCode, b, con);
                for (VrpGroupResultEntity groupResult : groupResults) {
                    if (processCode.equals("A")) {
                        b = new SqlBuilder("JdgStlLgSurfaceM.getInfo");
                        b.Fill(new String[]{groupResult.getJudgeStoveNo()});
                    } else if (processCode.equals("D")) {
                        b = new SqlBuilder("JdgMilSurfaceResult.getInfo");
                        b.Fill(new String[]{groupResult.getJudgeStoveNo()});
                    } else {
                        b = new SqlBuilder("JdgHttAppearanceCheckResult.getInfo");
                        b.Fill(new String[]{groupResult.getJudgeStoveNo(), groupResult.getBatchNo(), processCode});
                    }
                    tmpFaces = EntityTool.getEntitysBySqlNoClsCon(
                            b.toString(), con, HttAppearancecheckResultEntity.class);
                    for (HttAppearancecheckResultEntity tmpFace : tmpFaces) {
                        faces.add(tmpFace);
                    }
                }
            }

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

    public CoreReturnObject getFaceInfoByPline(String judgeStoveNo, String batchNo, String processCode, String zpMLh,String plineCode) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection con = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            SqlBuilder b = null;
            List<HttAppearancecheckResultEntity> faces = new ArrayList<HttAppearancecheckResultEntity>();

            if (processCode.equals("A")) {
                b = new SqlBuilder("JdgStlLgSurfaceM.getInfo");
                b.Fill(new String[]{judgeStoveNo});
            } else if (processCode.equals("D")) {
                b = new SqlBuilder("JdgMilSurfaceResult.getInfo");
                b.Fill(new String[]{judgeStoveNo});
            } else {
                b = new SqlBuilder("JdgHttAppearanceCheckResult.getInfoByPlineCode");
                b.Fill(new String[]{judgeStoveNo, processCode,plineCode});
            }

            List<HttAppearancecheckResultEntity> tmpFaces = EntityTool.getEntitysBySqlNoClsCon(
                    b.toString(), con, HttAppearancecheckResultEntity.class);
            for (HttAppearancecheckResultEntity tmpFace : tmpFaces) {
                faces.add(tmpFace);
            }
            if (!zpMLh.equals("")) {
                ArrayList<VrpGroupResultEntity> groupResults = BllCreateGroupStoveInfo.getOldStoveNo(
                        judgeStoveNo, processCode, b, con);
                for (VrpGroupResultEntity groupResult : groupResults) {
                    if (processCode.equals("A")) {
                        b = new SqlBuilder("JdgStlLgSurfaceM.getInfo");
                        b.Fill(new String[]{groupResult.getJudgeStoveNo()});
                    } else if (processCode.equals("D")) {
                        b = new SqlBuilder("JdgMilSurfaceResult.getInfo");
                        b.Fill(new String[]{groupResult.getJudgeStoveNo()});
                    } else {
                        b = new SqlBuilder("JdgHttAppearanceCheckResult.getInfoByPlineCode");
                        b.Fill(new String[]{groupResult.getJudgeStoveNo(), processCode,plineCode , groupResult.getBatchNo()});
                    }
                    tmpFaces = EntityTool.getEntitysBySqlNoClsCon(
                            b.toString(), con, HttAppearancecheckResultEntity.class);
                    for (HttAppearancecheckResultEntity tmpFace : tmpFaces) {
                        faces.add(tmpFace);
                    }
                }
            }

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

    public CoreReturnObject getSpecInfo(String judgeStoveNo, String batchNo, String processCode, String zpMLh) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection con = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            SqlBuilder b = null;
            List<QcmJudgeDetectEntity> specs = new ArrayList<QcmJudgeDetectEntity>();
            b = new SqlBuilder("QcmZgJugdeApplyDAL.getSpecFile");
            b.Fill(new String[]{judgeStoveNo, batchNo, processCode});

            List<QcmJudgeDetectEntity> tmpSpecs = EntityTool.getEntitysBySqlNoClsCon(
                    b.toString(), con, QcmJudgeDetectEntity.class);
            for (QcmJudgeDetectEntity tmpSpec : tmpSpecs) {
                specs.add(tmpSpec);
            }

            if (zpMLh.equals("")) {
                ArrayList<VrpGroupResultEntity> groupResults = BllCreateGroupStoveInfo.getOldStoveNo(
                        judgeStoveNo, processCode, b, con);
                for (VrpGroupResultEntity groupResult : groupResults) {
                    b = new SqlBuilder("QcmZgJugdeApplyDAL.getSpecFile");
                    b.Fill(new String[]{groupResult.getJudgeStoveNo(), groupResult.getBatchNo(), processCode});
                    tmpSpecs = EntityTool.getEntitysBySqlNoClsCon(
                            b.toString(), con, QcmJudgeDetectEntity.class);
                    for (QcmJudgeDetectEntity tmpSpec : tmpSpecs) {
                        specs.add(tmpSpec);
                    }
                }
            }

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

    /**
     * 刷新工艺版本
     *
     * @param applyCode
     * @param judgeStoveNo
     * @param batchNo
     * @return
     */
    public CoreReturnObject refreshCraft(String applyCode, String judgeStoveNo, String batchNo) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection con = null;
        Statement st = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            st = con.createStatement();
            SqlBuilder b = null;
            b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
            b.Fill(new String[]{applyCode, judgeStoveNo, batchNo});
            QcmZgJugdeApplyEntity apply = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, QcmZgJugdeApplyEntity.class);
            String ordLnPk = BllZcColligateJudge.getOrdLnPkByDlyPk(apply.getOrdLnDlyPk(), b, con);
            b = new SqlBuilder("JdgCraftOrdDesign.getNewByOrdLnPk");
            b.Fill(new String[]{ordLnPk});
            CraftOrdDesignEntity craft = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, CraftOrdDesignEntity.class);
            if (craft == null) {
                cro.setV_errMsg("找不到最新工艺，请确认最新工艺是否已生效！");
                return cro;
            }

            HashMap<String, QcmZgJugdeApplyEntity> applyMap = getAllJudgeApply(
                    applyCode, judgeStoveNo, batchNo,
                    apply.getProcessCode(), apply.getUpperHeatplanId(), null, null, con);

            for (QcmZgJugdeApplyEntity proApply : applyMap.values()) {
                if (proApply.getOrdLnDlyPk().startsWith("ZZB")) {
                    b = new SqlBuilder("QcmZgJugdeApplyDAL.updateCraftSeqBL");
                } else {
                    b = new SqlBuilder("QcmZgJugdeApplyDAL.updateCraftSeq");
                }
                b.Fill(new String[]{proApply.getJugdeApplyCode(), proApply.getJudgeStoveNo(),
                        proApply.getBatchNo()});
                st.executeUpdate(b.toString());
            }

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

    /**
     * 获取加工实绩
     *
     * @param applyCode
     * @param judgeStoveNo
     * @param batchNo
     * @param con
     * @return
     */
    public static ArrayList<QcmZcJgxResultEntity> getJgxResultInfo(String applyCode, String judgeStoveNo,
                                                                   String batchNo, Connection con) {
        ArrayList<QcmZcJgxResultEntity> jgxResults = new ArrayList<QcmZcJgxResultEntity>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.QueryByBatchNo");
        b.Fill(new String[]{applyCode, judgeStoveNo, batchNo});
        QcmZgJugdeApplyEntity apply = EntityTool.getEntityBySqlNoClsCon(
                b.toString(), con, QcmZgJugdeApplyEntity.class);
        String ordLnPk = getOrdLnPkByDlyPk(apply.getOrdLnDlyPk(), b, con);
        b = new SqlBuilder("CraftOrdDesignMscPlSti.getStation");
        b.Fill(new String[]{ordLnPk, apply.getCraftSeq(), apply.getIndexSeq(), apply.getProcessCode()});
        List<CraftOrdDesignMscPlStiEntity> craftStis = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, CraftOrdDesignMscPlStiEntity.class);
        //获取附加要求实绩
        b = new SqlBuilder("JdgQcmAddAsk.getAddaSK");
        b.Fill(new String[]{applyCode, judgeStoveNo});
        List<QcmAddAskEntity> addAsks = EntityTool.getEntitysBySqlNoClsCon(
                b.toString(), con, QcmAddAskEntity.class);
        //获取各项实绩
        for (CraftOrdDesignMscPlStiEntity craftSti : craftStis) {
            QcmZcJgxResultEntity jgxResult = new QcmZcJgxResultEntity();
            if (craftSti.getStationType().equals("403204")) {//探伤
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationType());
                //JdgHttCrackDetectionEt.getInfo
                b = new SqlBuilder("JdgHttCrackDetectionEt.getInfo");
                b.Fill(new String[]{judgeStoveNo, batchNo, apply.getProcessCode()});
                HttCrackDetectionEtEntity detect = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, HttCrackDetectionEtEntity.class);
                if (detect != null) {
                    jgxResult.setResult("合格");
                }
                jgxResults.add(jgxResult);
            } else if (craftSti.getStationCode().equals("70350")) {//表检
//					jgxResult.setItem(craftSti.getStationDesc());
//					jgxResult.setItemCode(craftSti.getStationCode());
//					if(!apply.getSpecResultCode().equals("")){
//						jgxResult.setResult("合格");
//					}
//					jgxResults.add(jgxResult);
            } else if (craftSti.getStationType().equals("403205")) {//水压
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationType());
                b = new SqlBuilder("JdgMchWatergageResult.getInfo");
                b.Fill(new String[]{judgeStoveNo, batchNo});
                MchWatergageResultEntity water = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, MchWatergageResultEntity.class);
                if (water != null) {
                    jgxResult.setResult("合格");
                }
                jgxResults.add(jgxResult);
            } else if (craftSti.getStationCode().equals("70250")) {//接箍拧接
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationCode());
                b = new SqlBuilder("JdgMchTwistinglyResult.getResultDInfo");
                b.Fill(new String[]{judgeStoveNo, batchNo});
                MchTwistinglyResultDEntity twisting = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, MchTwistinglyResultDEntity.class);
                if (twisting != null) {
                    jgxResult.setResult("合格");
                }
                jgxResults.add(jgxResult);
            } else if (craftSti.getStationCode().equals("70270")) {//通径
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationCode());
                b = new SqlBuilder("JdgMchPathResult.getInfo");
                b.Fill(new String[]{judgeStoveNo, batchNo});
                if (!apply.getMchPathResult().equals("")) {
                    //jgxResult.setResult("合格");
                    jgxResult.setResult(apply.getMchPathResult());
                }
                jgxResults.add(jgxResult);
            } else if (craftSti.getStationCode().equals("70232")) {//通径(工艺)
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationCode());
                if (!apply.getMchPathResult().equals("")) {
                    //jgxResult.setResult("合格");
                    jgxResult.setResult(apply.getMchPathResult());
                }
                jgxResults.add(jgxResult);
            } else if (craftSti.getStationCode().equals("70210")) {//车丝
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationCode());
                b = new SqlBuilder("JdgMchThreaderResult.getInfo");
                b.Fill(new String[]{judgeStoveNo, batchNo});
                MchThreaderResultEntity threader = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, MchThreaderResultEntity.class);
                if (threader != null) {
                    jgxResult.setResult("合格");
                }
                jgxResults.add(jgxResult);
            } else if (craftSti.getStationCode().equals("70230")) {//螺纹
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationCode());
                b = new SqlBuilder("JdgMchHreadResult.getInfo");
                b.Fill(new String[]{judgeStoveNo, batchNo});
                MchHreadResultEntity hreadResult = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, MchHreadResultEntity.class);
                if (hreadResult != null) {
                    jgxResult.setResult("合格");
                }
                jgxResults.add(jgxResult);
            } else if (craftSti.getStationCode().equals("70490")) {//倒棱
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationCode());
                b = new SqlBuilder("JdgMchChamferingResult.getInfo");
                b.Fill(new String[]{judgeStoveNo, batchNo});
                MchChamferingResultEntity chamfering = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, MchChamferingResultEntity.class);
                if (chamfering != null) {
                    jgxResult.setResult("合格");
                }
                jgxResults.add(jgxResult);
            } else if (craftSti.getStationCode().equals("70760")) {//剩磁
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationCode());
                if (!apply.getMchRemanenceResult().equals("")) {
                    //jgxResult.setResult("合格");
                    jgxResult.setResult(apply.getMchRemanenceResult());
                }
                jgxResults.add(jgxResult);
            } else if (craftSti.getStationCode().equals("70765")) {//放射性
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationCode());
                if (!apply.getMchRadioactivityResult().equals("")) {
                    //jgxResult.setResult("合格");
                    jgxResult.setResult(apply.getMchRadioactivityResult());
                }
                jgxResults.add(jgxResult);
            } else if (craftSti.getStationCode().equals("70530")) {//坡口
                jgxResult.setItem(craftSti.getStationDesc());
                jgxResult.setItemCode(craftSti.getStationCode());
                b = new SqlBuilder("JdgMchChamferingResult.getInfo");
                b.Fill(new String[]{judgeStoveNo, batchNo});
                MchChamferingResultEntity chamfering = EntityTool.getEntityBySqlNoClsCon(
                        b.toString(), con, MchChamferingResultEntity.class);
                if (chamfering != null) {
                    jgxResult.setResult("合格");
                }
                jgxResults.add(jgxResult);
            }

        }

        //抽检
        b = new SqlBuilder("JdgMchFinalChekResult.getInfo");
        b.Fill(new String[]{judgeStoveNo, batchNo});
        MchFinalCheckResultEntity finalCheck = EntityTool.getEntityBySqlNoClsCon(
                b.toString(), con, MchFinalCheckResultEntity.class
        );
        QcmZcJgxResultEntity rkResult = new QcmZcJgxResultEntity();
        rkResult.setItem("入库检验");
        rkResult.setItemCode("finalCheck");
        if (finalCheck != null) {
            rkResult.setItem("入库检验");
            b = new SqlBuilder("JdgMchFinalChekResult.getNoCheckCount",
                    apply.getJugdeApplyCode(), apply.getJudgeStoveNo(), apply.getBatchNo());
            GenericEntity checkCount = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, GenericEntity.class);
            b = new SqlBuilder("JdgMchFinalChekResult.getNoCheckTreatmentCount",
                    apply.getJugdeApplyCode(), apply.getJudgeStoveNo(), apply.getBatchNo());
            GenericEntity checkTreatmentCount = EntityTool.getEntityBySqlNoClsCon(
                    b.toString(), con, GenericEntity.class);
            if (checkCount.getCount().equals("0") && checkTreatmentCount.getCount().equals("0")) {
                rkResult.setResult("合格");
            }
        }
        jgxResults.add(rkResult);

        return jgxResults;
    }

    public CoreReturnObject getJgxResultInfo(String applyCode, String judgeStoveNo, String batchNo) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection con = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            ArrayList<QcmZcJgxResultEntity> jgxResults = getJgxResultInfo(applyCode,
                    judgeStoveNo, batchNo, con);

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

        return cro;
    }

    public CoreReturnObject updateCraftNo(String[] parm) {
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateCraftNo",parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    public CoreReturnObject updateJhyCraftNo(String[] parm) {
        ArrayList<String> sqllist = new ArrayList<String>();
        SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.updateJhyCraftNo",parm);
        sqllist.add(b.toString());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
    }

    public List<ComLengthType> getLengthTypes(String ordLnPk) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection con = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.getLengthType");
            b.Fill(new String[]{ordLnPk});
            return EntityTool.getEntitysBySql(b.toString(), con, ComLengthType.class);
        } catch (Exception ex) {
            try {
                con.rollback();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            cro.setV_errMsg(ex.getMessage());
            return null;
        } finally {
            try {
                if(con != null) {
                    con.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public List<ComLengthType> getLengthTypes1(String ordLnPk) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection con = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            SqlBuilder b = new SqlBuilder("QcmZgJugdeApplyDAL.getLengthType1");
            b.Fill(new String[]{ordLnPk});
            return EntityTool.getEntitysBySql(b.toString(), con, ComLengthType.class);
        } catch (Exception ex) {
            try {
                con.rollback();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            cro.setV_errMsg(ex.getMessage());
            return null;
        } finally {
            try {
                if(con != null) {
                    con.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}