package com.steering.mes.mcp.Mch;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.converter.QualityDesignTool;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;
import com.steering.mes.mcp.collarMaterial.MeanValueCalculation;
import com.steering.mes.mcp.common.PlanService;
import com.steering.mes.mcp.entity.*;
import com.steering.mes.mcp.entity.MchEntity.PlnZyJgxMEntity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;

public class FrmMchInOnlineStore extends DBCommon {
    /**
     * 查询炉计划信息
     * @param heatPlanNo 计划号
     * @param heatnoLast 炉号
     * @param plinCode 产线
     * @param start 开始时间
     * @param end 结束时间
     * @param vluae 状态
     * @return
     */
	private String perStuts = "";
	public static String station = "";

    public CoreReturnObject doQuerySingleJugStove(String heatPlanNo) {

        String sql = "";
        sql = CoreXmlSqlParsersFactory
                .getSql("FrmMchInOnlineStore.doQuerySingleJugStove");

        if (!heatPlanNo.equals("")) {
            sql += " AND T1.HEAT_PLAN_NO ='" + heatPlanNo + "'";
        }     
        sql += ") T ORDER BY T.HEAT_PLAN_NO";
        return this.getData(sql);
    }

    /**
     * 查询加工队列信息
     */
    public CoreReturnObject doQuerymch(String heatPlanNo,
            String heatnoLast, String plinCode, String start, String end,
            String vluae) {
       String sql = "";
       sql = CoreXmlSqlParsersFactory
               .getSql("FrmMchInOnlineStore.doQuerymch");

       if (!heatPlanNo.equals("")) {
           sql += " AND T1.HEAT_PLAN_NO || '&' LIKE '%' || '" + heatPlanNo
                   + "' || '%'";
       }
       if (!heatnoLast.equals("")) {
           sql += " AND T1.JUDGE_STOVE_NO || '&' LIKE '%' || '" + heatnoLast
                   + "' || '%'";
       }
       if (!start.equals("")) {
           sql += " AND T1.CREATE_TIME >=TO_DATE('"
                   + start
                   + "', 'YYYY-MM-DD HH24:MI:SS')AND T1.CREATE_TIME <=TO_DATE('"
                   + end + "', 'YYYY-MM-DD HH24:MI:SS') ";
       }
       sql += " AND T1.PLINE_CODE ='" + plinCode + "'";
       if (vluae.equals("0")) {
           sql += " AND T1.PLANSTATUS IN ('20')";
       }
       else {
           sql += " AND T1.PLANSTATUS IN ('30','40')";
       }
       sql += " ORDER BY T1.HEAT_PLAN_NO";
       return this.getData(sql);
       
    }

    /**
     * 查询炉信息（剔除，合格，样管）
     * @param heatNo
     * @param judge
     * @param batch
     * @return
     */

    public CoreReturnObject doQuerySingleJug(String heatNo, String judge,
            String batch) {
        return this.getDataBySqlID("FrmMchInOnlineStore.doQuerySingle",
                new Object[] { heatNo, judge, batch, heatNo, judge,
                        batch});
    }

    
    /**
     * 查询相同炉计划ID下交库实绩状态
     * @param heatNo
     * @param judge
     * @param batch
     * @return
     */

    public CoreReturnObject getQueryExpandResultStuts(String heatNo, String plinCode) {
        return this.getDataBySqlID("FrmMchInOnlineStore.getQueryExpandResultStuts",
                new Object[] { heatNo, plinCode});
    }

    /**
     * 查询炉批信息
     * @param heatNo
     * @param mat
     * @param pipe
     * @return
     */

    public CoreReturnObject doQueryformat(String heatNo, String mat, String pipe) {
        return this.getDataBySqlID("FrmMchInOnlineStore.doQuerySingle1",
                new Object[] { mat, heatNo, pipe });
    }

    /**
     * 查询重量
     * @param heatNo
     * @param mat
     * @param pipe
     * @return
     */
    public CoreReturnObject doQueryWt(String heatNo, String mat, String pipe,
            String count) {
        return this
                .getDataBySqlID("FrmMchInOnlineStore.doQueryWt", new Object[] {
                        mat, heatNo, pipe, Integer.parseInt(count) + 1 });
    }

    /**
     * 查询交库信息
     * @param list
     * @param startTim
     * @param endTim
     * @return
     */
    public CoreReturnObject doQueryLibrary(String plinCode, String start,
            String end, String jugeNo,String heatNo) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmMchInOnlineStore.doQueryLibrary");
        if (!start.equals("")) {
            sql += " AND T.CREATE_TIME >=TO_DATE('"
                    + start
                    + "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
                    + end + "', 'YYYY-MM-DD HH24:MI:SS') ";
        }
        if (!jugeNo.equals("")) {
            sql += "  AND T.HEATNO_LAST || '&' LIKE '%' || '" + jugeNo
                    + "' || '%'";
        }
        if (!plinCode.equals("")) {
            sql += "  AND T.PLINE_CODE ='" + plinCode + "'";
        }
        if (!heatNo.equals("")) {
            sql += "  AND M.HEAT_PLAN_NO ='" + heatNo + "'";
        }
        sql += " GROUP BY T.INSTOCK_DOC, T.INSTOCK_TYPE_CODE, T.INSTOCK_TYPE_NAME, T.JUDGE_STOVE_NO, "
                + "T.BATCH_NO, T.BATCH_GROUD_NO, T.MATERIAL_NAME, T.PRODUCNAME, T.STD_NAME, T.GRADENAME, "
                + "T.STEELNAME, T.STD_STYLE_DESC, T.SPEC_NAME, T.MODEL_DESC, T.PRO_ORDER_NO, T.PLINE_CODE, "
                + "T.PLINE_NAME, T.BELONG_CODE, T.BELONG_NAME, T.STORAGE_NO, T.LOCATION_NO, T.LARY_NO,"
                + " T.LOC_NO, T.STORAGE_ATTR, T.STORAGE_ATTR_NAME, T.STORAGE_TYPE_NAME, T.MANAGEMENT_NAME,"
                + " T.PRO_BC, T.PRO_BZ, T.IN_BC, T.IN_BZ, T.HAND_FLAG, T.MEMO, "
                + "T.VALIDFLAG, T.ORD_PK,T.CREATE_NAME, "
                + "T.ORD_LN_PK, T.ORD_LN_DLY_PK, T.DEPARTMENT_CODE, T.DEPARTMENT_DESC, T.ORDER_NO, T.ORDER_SEQ,"
                + " T.DELIVERY_NO, T.PRODUCT_FLAG, T.MAT_STATUS, T.JUDGE_STD_NAME, T.JUDGE_STD_CODE, "
                + "T.BAL_YEAR_MONTH, T.PIPMEMO, T.QCM_STAUS, B.STORAGE_NAME, T.ACT_DIMATER, T.ACT_HEIGHT,"
                + " T.ACT_LEN_MIN, T.ACT_LEN_MAX, M.HEAT_PLAN_NO";
        return this.getData(sql);
    }

    /***
     * 获取加工计划表实体类
     * @param con
     * @param heatNo
     * @return
     * @throws SQLException
     */
    public static PlnZyJgxMEntity getSendDBKPlan(Connection con, String heatNo)
            throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmMchInOnlineStore.doQuery");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyJgxMEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyJgxMEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        }
        else {
            for (PlnZyJgxMEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }

    /**
     * 新增交库实绩
     * @param result 交库实绩
     * @return·
     */
    public CoreReturnObject addLibraryResult(ArrayList<String> list,
            String hertNo, String SlGx, String gxname, String plineCode) {
        CoreReturnObject cor = new CoreReturnObject();
        Connection con = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        Date dt = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
        String systime = dateFormat.format(now);
        // String last = date.format(ca.getTime()) + " 21:00:00";
        try {
            con.setAutoCommit(false); // 取消自动提交事务
            String updatePortBatch = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.UpdatePortBatch");// 修改管号队列重量
            PreparedStatement updatePortBatchPsta = con
                    .prepareStatement(updatePortBatch);
            String insertComInfoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.AddPlnInfo");// 新增加工入库表
            PreparedStatement insertComInfoPsta = con
                    .prepareStatement(insertComInfoSql);
            
            String insertComInfoSqlXs = CoreXmlSqlParsersFactory
                    .getSql("xsmat.AddPlnInfo");// 新增加工销售入库表
            PreparedStatement insertComInfoPstaXs = con
                    .prepareStatement(insertComInfoSqlXs);
            
            String strMatM = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.AddMatM");// 末工序修改材料表状态
            PreparedStatement pstaMatM = con.prepareStatement(strMatM);
            
            String strMatMXs = CoreXmlSqlParsersFactory
                    .getSql("xsmat.AddMatM");// 末工序修改销售材料表状态
            PreparedStatement pstaMatMXs = con.prepareStatement(strMatMXs);
            
            String addButt = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.AddYdmButt");// 新增库存位置信息
            PreparedStatement patButt = con.prepareStatement(addButt);
            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.AddComInfoResult");// 新增加工公共信息
            PreparedStatement patsPlan = con.prepareStatement(addPlnInfo);
            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.UpdatePath1");// 修改队列表工艺路径,虚拟入库标志状态
            PreparedStatement pastupdatePath = con.prepareStatement(updatePath);

            String planJgSql = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.UpdatePlanResult1");// 修改计划表
            PreparedStatement planJgPsta = con.prepareStatement(planJgSql);
            
            String planJgSqlC = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.UpdatePlanResultC1");// 修改计划表从表
            PreparedStatement planJgPstaC = con.prepareStatement(planJgSqlC);
            
            String matNoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.UpdateMatNo");// 新增材料表
            PreparedStatement matNoPsta = con.prepareStatement(matNoSql);
            
            //新增销售入库
            String matNoSqlXs = CoreXmlSqlParsersFactory
                    .getSql("xsmat.UpdateMatNo");// 新增材料表
            PreparedStatement matNoPstaXs = con.prepareStatement(matNoSqlXs);
            
            
            // for (int i = 0; i < list1.size(); i++) {
            // ArrayList<String> list = (ArrayList<String>) list1.get(i);
            String judNo = list.get(1);// 炉号
            String zgNo = list.get(2);// 批号
            String sjnum = list.get(5);// 支数
            String sjwt = list.get(23);// 重量
            // String sjweight = list.get(6);
            // String failnum = list.get(7);
            // String failweight = list.get(8);
            String user = list.get(9);
            String bc = list.get(10);
            String bz = list.get(11);
            String strInBound = list.get(12);
            String strInMemo = list.get(13);
            String manage = list.get(14);
            String manageNmae = list.get(15);
            String stono = list.get(19);
            String matStart = list.get(17);
            String isSamp = list.get(18);
            String banci = list.get(24);
            String banzu = list.get(25);
            String coluser = list.get(26);
            // if (PlanService.compareDate(systime, last) == true) {
            // if (bc.equals("3")) {
            // ca.add(Calendar.DAY_OF_MONTH, 1);
            // lutime = date.format(ca.getTime()) + " 00:00:01";
            // }
            // }
            station = "1";
            String sqlloadings = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryperstu");// 查询信息表除了本工序之外最大的工序
            PreparedStatement pstas = con.prepareStatement(sqlloadings);
            pstas.setObject(1, hertNo);
            pstas.setObject(2, SlGx);
            ResultSet rss = pstas.executeQuery();
            if (rss.next()) {
            	perStuts = rss.getString("STATION_CODE");
//            	if(perStuts.equals("0"))
//            	{
//            		cor.setV_errMsg("无工序，不允许此操作!");
//                     return cor;
//            	}else 
            		if(perStuts.equals("701301"))
            	{
            		perStuts = "00";
            	}else if(perStuts.equals("701302"))
            	{
            		perStuts = "01";
            	}else if(perStuts.equals("701303"))
            	{
            		perStuts = "02";
            	}else if(perStuts.equals("701304"))
            	{
            		perStuts = "03";
            	}else if(perStuts.equals("701305"))
            	{
            		perStuts = "04";
            	}else if(perStuts.equals("701306"))
            	{
            		perStuts = "05";
            	}else if(perStuts.equals("701307"))
            	{
            		perStuts = "06";
            	}else if(perStuts.equals("701308"))
            	{
            		perStuts = "07";
            	}else if(perStuts.equals("701309"))
            	{
            		perStuts = "08";
            	}else if(perStuts.equals("701310"))
            	{
            		perStuts = "09";
            	}else if(perStuts.equals("701311"))
            	{
            		perStuts = "10";
            	}
            }
            rss.close();
            pstas.close();
            String planStatus = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryPlanJg");// 查询加工计划表状态
            PreparedStatement psta = con.prepareStatement(sqlloading);
            psta.setObject(1, hertNo);
            ResultSet rs = psta.executeQuery();
            if (rs.next()) {
                planStatus = rs.getString("PLANSTATUS");
            }
            rs.close();
            psta.close();
            if (planStatus.equals("3")) {
                cor.setV_errMsg("该工单计划已生产完成！");
                return cor;
            }
            if (planStatus.equals("4")) {
                cor.setV_errMsg("该工单计划已关闭！");
                return cor;
            }
            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.qureyGxComInfo");// 查询公共信息表工序点状态
            psta = con.prepareStatement(sql);
            psta.setObject(1, hertNo);
            psta.setObject(2, plineCode);
            psta.setObject(3, SlGx);
            rs = psta.executeQuery();
            while (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
                if (cutFalg.equals("1")) {
                    cor.setV_errMsg("工序" + rs.getString("STATION_DESC")
                            + "未结炉!");
                    return cor;
                }
            }
            rs.close();
            psta.close();

            int count = 0;
            String sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryPlanJg1");// 查询可交库支数
            PreparedStatement psta1 = con.prepareStatement(sqlloading1);
            psta1.setObject(1, hertNo);
            psta1.setObject(2, matStart);
            psta1.setObject(3, isSamp);
            ResultSet rs1 = psta1.executeQuery();
            if (rs1.next()) {
                count = Integer.parseInt(rs1.getString("ACT_COUNT"));
            }
            rs1.close();
            psta1.close();

            if (Integer.parseInt(list.get(21)) - count == 0) {
                cor.setV_errMsg("选择炉批信息已交库,不允许再次交库！");
                return cor;
            }
            String inStatus1 = "";
            String sqlloading3 = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.querystatus");// 查询公共信息表里交库工序的状态
            PreparedStatement psta3 = con.prepareStatement(sqlloading3);
            psta3.setObject(1, SlGx);
            psta3.setObject(2, hertNo);
            ResultSet rs3 = psta3.executeQuery();
            if (rs3.next()) {
                inStatus1 = rs3.getString("STATION_STATUS");
            }
            rs3.close();
            psta3.close();
            if (inStatus1.equals("2")) {
                cor.setV_errMsg("该交库工序已经结庐，不允许此操作！");
                return cor;
            }
            String storageAtte = "";
            String storageAtteName = "";
            String storageType = "";
            String storageTypeName = "";
            String managNo = "";
            String managName = "";
            String depNo = "";
            String depName = "";
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryStorageType");
            psta = con.prepareStatement(sqlloading);
            psta.setObject(1, stono);
            rs = psta.executeQuery();
            if (rs.next()) {
                storageAtte = rs.getString("STORAGE_ATTR");
                storageAtteName = rs.getString("STORAGE_ATTR_NAME");
                storageType = rs.getString("STORAGE_TYPE_NO");
                storageTypeName = rs.getString("STORAGE_TYPE_NAME");
                managNo = rs.getString("MANAGEMENT_NO");
                managName = rs.getString("MANAGEMENT_NAME");
                depNo = rs.getString("DEPARTMENT_CODE");
                depName = rs.getString("DEPARTMENT_DESC");
            }
            rs.close();
            psta.close();

//            ArrayList<String> matNoList = new ArrayList<String>();
//            // 查询材料号
//            sql = CoreXmlSqlParsersFactory
//                    .getSql("FrmMchInOnlineStore.doQueryWtMatNo");
//            psta = con.prepareStatement(sql);
//            psta.setObject(1, matStart);
//            psta.setObject(2, hertNo);
//            psta.setObject(3, isSamp);
//            psta.setObject(4, Integer.parseInt(sjnum) + 1);
//            rs = psta.executeQuery();
//            while (rs.next()) {
//                matNoList.add(rs.getString("MAT_NO"));
//            }
//            rs.close();
//            psta.close();
            ArrayList<String> matNoList = new ArrayList<String>();
            // 查询材料号
            sql = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.doQueryWtMatNo");
            psta = con.prepareStatement(sql);
            psta.setObject(1, matStart);
            psta.setObject(2, hertNo);
            psta.setObject(3, isSamp);
            psta.setObject(4, Integer.parseInt(sjnum) + 1);
            rs = psta.executeQuery();
            //matNoList = EntityTool.getEntitysByRs(rs, PortMchBatchSampleResultEntity.class);
            while (rs.next()) {
                matNoList.add(rs.getString("MAT_NO"));
            }
            rs.close();
            psta.close();
        
            int k = 0;
            List<double[]> listwt = MeanValueCalculation.MeanCalculation(Double
                    .parseDouble(sjwt), Integer.parseInt(sjnum));
            for (int j = 0; j < listwt.size(); j++) {
                double[] conW = listwt.get(j);
                if ((int) conW[0] >= 0) {
                    for (int z = 0; z < (int) conW[0]; z++) {
                        updatePortBatchPsta.setObject(1, String
                                .valueOf(conW[1]));
                        updatePortBatchPsta.setObject(2, matNoList.get(k));
                        updatePortBatchPsta.addBatch();
                        k++;
                    }
                }
            }
            updatePortBatchPsta.executeBatch();
            
            // 获取材料号
            List<VrpMatZcMEntity> mat = new ArrayList<VrpMatZcMEntity>();
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryMaxMatNo");// 查询管号队列对应材料
            psta = con.prepareStatement(sqlloading);
            psta.setObject(1, judNo);
            psta.setObject(2, zgNo);
            psta.setObject(3, matStart);
            psta.setObject(4, isSamp);
            psta.setObject(5, hertNo);
            psta.setObject(6, Integer.parseInt(sjnum) + 1);
            rs = psta.executeQuery();
            mat = EntityTool.getEntitysByRs(rs, VrpMatZcMEntity.class);
//            while(rs.next())
//            {
//            prcqcmstaus = rs.getString("PRC_QCM_STAUS");
//            }
                     
            rs.close();
            psta.close();
            
            String prcqcmstaus = "";
            String belongCode = "";
            String stoveno = "";
            String sampleflag = "";
            String proorderid = "";
            String proorderid1 = "";
            String proorderno = "";
            String proorderno1 = "";
            String crafno = "";
            String actlenmin = "";
            String actlenmax = "";
            String actcount = "";
            String actweight = "";
            String jugdeapplyflag = "";
            String jugdeapplycode = "";
            String jugdeapplytime = "";
            String faceresultcode = "";
            String chemresultcode = "";
            String phyresultcode = "";
            String detectresultcode = "";
            String judgeresultcode = "";
            String judgeresult = "";
            String judgeresulttime = "";
            String instocktime = "";
            String createname ="";
            String createtime = "";
            String ordpk = "";
            String ordlnpk = "";
            String ordlndlypk = "";
            String judgestdname = "";
            String judgestdcode = "";
            String sourecode = "";
            String sourename = "";
            String plngradename = "";
            String plngradecode = "";
            String lotno = "";
            String judgestoveno = "";
            String batchno = "";
            String batchgroupno = "";
            String matsqeno = "";
            String cuttingflag = "";
            String originmatno = "";
            String inputmaterialno = "";
            String inputmaterialname = "";
            String inputorigincode = "";
            String modelcode = "";
            String modeldesc = "";
            String stdcode = "";
            String stdname = "";
            String stdstyle = "";
            String stdstyledesc = "";
            String orderno = "";
            String orderseq = "";
            String orderseqno = "";
            String processcode = "";
            String processdesc = "";
            String nextprocesscode = "";
            String nextprocessdesc = "";
            String plinecode = "";
            String plinename = "";
            String actdimater = "";
            String actheight = "";
            String actlen = "";
            String belongName = "";
            String materialNo = "";
            String materialName = "";
            String vprflag ="";
            String producCode = "";
            String producName = "";
            String gradeCode = "";
            String gradeName = "";
            String steelCode = "";
            String steelName = "";
            String specCode = "";
            String specName = "";
            String lenNo = "";
            String lenDesc = "";
            String lenUnit = "";
            String matoriginCode = "";
            String matoriginName ="";            
            String productflag = "801402";
            String matstatus = "80150201";  
      
            // 获取材料表数据信息
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryMaxMatNo");// 查询材料表数据
            psta = con.prepareStatement(sqlloading);
            psta.setObject(1, judNo);
            psta.setObject(2, zgNo);
            psta.setObject(3, matStart);
            psta.setObject(4, isSamp);
            psta.setObject(5, hertNo);
            psta.setObject(6, Integer.parseInt(sjnum) + 1);
            rs = psta.executeQuery();
            while(rs.next())
            {
            prcqcmstaus = rs.getString("PRC_QCM_STAUS");
            belongCode = rs.getString("BELONG_CODE");
            judgestoveno = rs.getString("JUDGE_STOVE_NO");
            sampleflag = rs.getString("SAMPLE_FLAG");
            proorderid = rs.getString("PRO_ORDER_ID");
            proorderid1 = rs.getString("PRO_ORDER_ID1");
            proorderno = rs.getString("PRO_ORDER_NO");
            proorderno1 = rs.getString("PRO_ORDER_NO1");
            crafno = rs.getString("CRAF_NO");
            actlenmin = rs.getString("ACT_LEN_MIN");
            actlenmax = rs.getString("ACT_LEN_MAX");
            actcount = rs.getString("ACT_COUNT");
            actweight = rs.getString("ACT_WEIGHT");
            jugdeapplyflag = rs.getString("JUGDE_APPLY_FLAG");
            jugdeapplycode = rs.getString("JUGDE_APPLY_CODE");
            jugdeapplytime = dateFormat.format(rs.getTimestamp("JUGDE_APPLY_TIME"));
            faceresultcode = rs.getString("FACE_RESULT_CODE");
            chemresultcode = rs.getString("CHEM_RESULT_CODE");
            phyresultcode = rs.getString("PHY_RESULT_CODE");
            detectresultcode = rs.getString("DETECT_RESULT_CODE");
            judgeresultcode = rs.getString("JUDGE_RESULT_CODE");
            judgeresult = rs.getString("JUDGE_RESULT");
            judgeresulttime = dateFormat.format(rs.getTimestamp("JUDGE_RESULT_TIME"));
            instocktime = dateFormat.format(rs.getTimestamp("INSTOCK_TIME"));
            createname = rs.getString("CREATE_NAME");
            createtime = dateFormat.format(rs.getTimestamp("CREATE_TIME"));
            ordpk = rs.getString("ORD_PK");
            ordlnpk = rs.getString("ORD_LN_PK");
            ordlndlypk = rs.getString("ORD_LN_DLY_PK");
            judgestdname = rs.getString("JUDGE_STD_NAME");
            judgestdcode = rs.getString("JUDGE_STD_CODE");
            sourecode = rs.getString("SOURE_CODE");
            sourename = rs.getString("SOURE_NAME");
            plngradename = rs.getString("PLN_GRADENAME");
            plngradecode = rs.getString("PLN_GRADECODE");   
            lotno = rs.getString("LOT_NO");
            stoveno = rs.getString("STOVE_NO");
            batchno = rs.getString("BATCH_NO");
            batchgroupno = rs.getString("BATCH_GROUD_NO");
            matsqeno = rs.getString("MAT_SQE_NO");
            cuttingflag = rs.getString("CUTTING_FLAG");
            originmatno = rs.getString("ORIGIN_MAT_NO");
            inputmaterialno = rs.getString("INPUT_MATERIAL_NO");
            inputmaterialname = rs.getString("INPUT_MATERIAL_NAME");
            inputorigincode = rs.getString("INPUT_ORIGIN_CODE");
            modelcode = rs.getString("MODEL_CODE");
            modeldesc = rs.getString("MODEL_DESC");
            stdcode = rs.getString("STD_CODE");
            stdname = rs.getString("STD_NAME");
            stdstyle = rs.getString("STD_STYLE");
            stdstyledesc = rs.getString("STD_STYLE_DESC");
            orderno = rs.getString("ORDER_NO");
            orderseq = rs.getString("ORDER_SEQ");
            orderseqno = rs.getString("ORDER_SEQ_NO");
            processcode = rs.getString("PROCESS_CDOE");
            processdesc = rs.getString("PROCESS_DESC");
            nextprocesscode = rs.getString("NEXT_PROCESS_CDOE");
            nextprocessdesc = rs.getString("NEXT_PROCESS_DESC");
            plinecode = rs.getString("PLINE_CODE");
            plinename = rs.getString("PLINE_NAME");
            actdimater = rs.getString("ACT_DIMATER");
            actheight = rs.getString("ACT_HEIGHT");
            actlen = rs.getString("ACT_LEN");
            belongName = rs.getString("BELONG_NAME");
            materialNo = rs.getString("MATERIAL_NO");
            materialName = rs.getString("MATERIAL_NAME");
            vprflag = rs.getString("PRC_FLAG_STOVE_NO_ZG");
            producCode = rs.getString("PRODUCCODE");
            producName = rs.getString("PRODUCNAME");
            gradeCode = rs.getString("GRADECODE");
            gradeName = rs.getString("GRADENAME");
            steelCode = rs.getString("STEELCODE");
            steelName = rs.getString("STEELNAME");
            specCode = rs.getString("SPEC_CODE");
            specName = rs.getString("SPEC_NAME");
            lenNo = rs.getString("LEN_NO");
            lenDesc = rs.getString("LEN_DESC");
            lenUnit = rs.getString("LEN_UNIT");
            matoriginCode = rs.getString("MAT_ORIGIN_CODE");
            matoriginName = rs.getString("MAT_ORIGIN_NAME");
            
            }                  
            rs.close();
            psta.close();          
            if (mat == null) {
                cor.setV_errMsg("该交库工序已经结庐，不允许此操作！");
                return cor;
            }
            
            // 获取管号队列材料号
            List<PortMchBatchSampleResultEntity> MATNO = new ArrayList<PortMchBatchSampleResultEntity>();
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.doqueryportresult");// 查询管号队列对应材料
            psta = con.prepareStatement(sqlloading);     
            psta.setObject(1, matStart);
            psta.setObject(2, hertNo);
            psta.setObject(3, isSamp);
            psta.setObject(4, Integer.parseInt(sjnum) + 1);
            rs = psta.executeQuery();
            MATNO = EntityTool.getEntitysByRs(rs, PortMchBatchSampleResultEntity.class);            
            rs.close();
            psta.close();
       
            // 获取加工计划表实体类
            PlnZyJgxMEntity pln = getSendDBKPlan(con, hertNo);
            String inListDoc = querySendSqlDoc(con, strInBound, strInMemo,
                    plineCode);// 入库单号
            String A = querySendSql(con, inListDoc);// 入库流水号
            int g = Integer.parseInt(A.substring(A.length() - 4, A.length()));

            int actCount = 0;
            double weghit = 0;          
            
            for (PortMchBatchSampleResultEntity matNo : MATNO) {
                actCount += Integer.parseInt(matNo.getActCount());                
                weghit += Double.parseDouble(matNo.getActWeight());              
                pstaMatM.setObject(1, "801402");
                pstaMatM.setObject(2, "80150201");
                pstaMatM.setObject(3, "G");
                pstaMatM.setObject(4, "加工");
                pstaMatM.setObject(5, pln.getPlineCode());
                pstaMatM.setObject(6, pln.getPlineName());
                pstaMatM.setObject(7, "40740601");// [加工工序]表面判定结果代码
                pstaMatM.setObject(8, "40740101");// [加工工序]成分判定结果代码
                pstaMatM.setObject(9, pln.getGxPlanNo());// 工序排产序号1
                pstaMatM.setObject(10, "");// 工序排产序号1
                pstaMatM.setObject(11, "40740301");// [加工工序]公差判定结果代码
                if (matStart.equals("00")) {
                    pstaMatM.setObject(12, "00");// 加工交库状态
                }
                else {
                    pstaMatM.setObject(12, "22");
                }
                pstaMatM.setObject(13, pln.getHeatPlanNo());
                pstaMatM.setObject(14, pln.getProPlanId());// [加工工序]生产订单号（1）
                pstaMatM.setObject(15, "");// [加工工序]生产订单号（2）
                pstaMatM.setObject(16, pln.getOrderNo() + pln.getOrderSeq());// [加工工序]生产合同号（1）
                pstaMatM.setObject(17, "");// [加工工序]生产合同号（2）
                pstaMatM.setObject(18, pln.getZyBatchId());// 生产批号
                pstaMatM.setObject(19, "40740201");// [加工工序]性能判定结果代码(理化)
                pstaMatM.setObject(20, isSamp);// 样管标志
                pstaMatM.setObject(21, pln.getCraftFileNo());// 执行工艺号
                pstaMatM.setObject(22, "");// 质量分组号
                pstaMatM.setObject(23, materialNo);
                pstaMatM.setObject(24, materialName);
                pstaMatM.setObject(25, "");
                pstaMatM.setObject(26, "");
                pstaMatM.setObject(27, "");// 投料物料来源
                pstaMatM.setObject(28, "");// 下道工序Id
                pstaMatM.setObject(29, "");// 下道工序
                pstaMatM.setObject(30, pln.getPlineCode());
                pstaMatM.setObject(31, pln.getPlineName());
                pstaMatM.setObject(32, user);
                pstaMatM.setObject(33, systime);
                pstaMatM.setObject(34, "40740701");// [加工工序]综合判定结果代码
                pstaMatM.setObject(35, manage);
                pstaMatM.setObject(36, manageNmae);
                pstaMatM.setObject(37, list.get(19));
                pstaMatM.setObject(38, list.get(20));
                pstaMatM.setObject(39, vprflag);
                pstaMatM.setObject(40, matNo.getMatNo());
                pstaMatM.addBatch();
                
                pstaMatMXs.setObject(1, "801402");
                pstaMatMXs.setObject(2, "80150201");
                pstaMatMXs.setObject(3, "G");
                pstaMatMXs.setObject(4, "加工");
                pstaMatMXs.setObject(5, pln.getPlineCode());
                pstaMatMXs.setObject(6, pln.getPlineName());
                pstaMatMXs.setObject(7, "40740601");// [加工工序]表面判定结果代码
                pstaMatMXs.setObject(8, "40740101");// [加工工序]成分判定结果代码
                pstaMatMXs.setObject(9, pln.getGxPlanNo());// 工序排产序号1
                pstaMatMXs.setObject(10, "");// 工序排产序号1
                pstaMatMXs.setObject(11, "40740301");// [加工工序]公差判定结果代码
                if (matStart.equals("00")) {
                    pstaMatMXs.setObject(12, "00");// 加工交库状态
                }
                else {
                    pstaMatMXs.setObject(12, "22");
                }
                pstaMatMXs.setObject(13, pln.getHeatPlanNo());
                pstaMatMXs.setObject(14, pln.getProPlanId());// [加工工序]生产订单号（1）
                pstaMatMXs.setObject(15, "");// [加工工序]生产订单号（2）
                pstaMatMXs.setObject(16, pln.getOrderNo() + pln.getOrderSeq());// [加工工序]生产合同号（1）
                pstaMatMXs.setObject(17, "");// [加工工序]生产合同号（2）
                pstaMatMXs.setObject(18, pln.getZyBatchId());// 生产批号
                pstaMatMXs.setObject(19, "40740201");// [加工工序]性能判定结果代码(理化)
                pstaMatMXs.setObject(20, isSamp);// 样管标志
                pstaMatMXs.setObject(21, pln.getCraftFileNo());// 执行工艺号
                pstaMatMXs.setObject(22, "");// 质量分组号
                pstaMatMXs.setObject(23, materialNo);
                pstaMatMXs.setObject(24, materialName);
                pstaMatMXs.setObject(25, "");
                pstaMatMXs.setObject(26, "");
                pstaMatMXs.setObject(27, "");// 投料物料来源
                pstaMatMXs.setObject(28, "");// 下道工序Id
                pstaMatMXs.setObject(29, "");// 下道工序
                pstaMatMXs.setObject(30, pln.getPlineCode());
                pstaMatMXs.setObject(31, pln.getPlineName());
                pstaMatMXs.setObject(32, user);
                pstaMatMXs.setObject(33, systime);
                pstaMatMXs.setObject(34, "40740701");// [加工工序]综合判定结果代码
                pstaMatMXs.setObject(35, manage);
                pstaMatMXs.setObject(36, manageNmae);
                pstaMatMXs.setObject(37, list.get(19));
                pstaMatMXs.setObject(38, list.get(20));
                pstaMatMXs.setObject(39, vprflag);
                pstaMatMXs.setObject(40, matNo.getMatNo());
                pstaMatMXs.addBatch();

                // 新增位置表
                patButt.setObject(1, matNo.getMatNo());
                patButt.setObject(2, matNo.getJudgeStoveNo());
                patButt.setObject(3, matNo.getBatchNo());
                patButt.setObject(4, matNo.getGroupNo());
                patButt.setObject(5, stono);
                patButt.setObject(6, stono + "10101");
                patButt.setObject(7, "");
                patButt.setObject(8, "");
                patButt.setObject(9, storageAtte);
                patButt.setObject(10, storageAtteName);
                patButt.setObject(11, storageType);
                patButt.setObject(12, storageTypeName);
                patButt.setObject(13, managNo);
                patButt.setObject(14, managName);
                patButt.setObject(15, "");
                patButt.setObject(16, user);
                patButt.setObject(17, systime);
                patButt.setObject(18, depNo);
                patButt.setObject(19, depName);
                patButt.addBatch();

                // 新增入库表数据
                insertComInfoPsta.setObject(1, inListDoc
                        + StringTool.formatDecimal(g, "0000"));
                insertComInfoPsta.setObject(2, inListDoc);
                insertComInfoPsta.setObject(3, strInBound);
                insertComInfoPsta.setObject(4, "产出入库");
                insertComInfoPsta.setObject(5, "");
                insertComInfoPsta.setObject(6, matNo.getMatNo());
                insertComInfoPsta.setObject(7, matNo.getLotNo());
                insertComInfoPsta.setObject(8, matNo.getStoveNo());
                insertComInfoPsta.setObject(9, judNo);
                insertComInfoPsta.setObject(10, zgNo);
                insertComInfoPsta.setObject(11, batchgroupno);
                insertComInfoPsta.setObject(12, pln.getOutwlId());
                insertComInfoPsta.setObject(13, pln.getOutwlDesc());
                insertComInfoPsta.setObject(14, producCode);//
                insertComInfoPsta.setObject(15, producName);
                insertComInfoPsta.setObject(16, matNo.getStdCode());
                insertComInfoPsta.setObject(17, matNo.getStdName());
                insertComInfoPsta.setObject(18, gradeCode);
                insertComInfoPsta.setObject(19, gradeName);
                insertComInfoPsta.setObject(20, steelCode);
                insertComInfoPsta.setObject(21, steelName);
                insertComInfoPsta.setObject(22, matNo.getStdStyle());
                insertComInfoPsta.setObject(23, matNo.getStdStyleDesc());
                insertComInfoPsta.setObject(24, specCode);
                insertComInfoPsta.setObject(25, specName);
                insertComInfoPsta.setObject(26, matNo.getModelCode());
                insertComInfoPsta.setObject(27, matNo.getModelDesc());
                insertComInfoPsta.setObject(28, pln.getOrderNo()
                        + pln.getOrderSeq());
                insertComInfoPsta.setObject(29, pln.getPlineCode());
                insertComInfoPsta.setObject(30, pln.getPlineName());
                insertComInfoPsta.setObject(31, matNo.getActDimater());
                insertComInfoPsta.setObject(32, matNo.getActHeight());
                insertComInfoPsta.setObject(33, matNo.getActLen());
                insertComInfoPsta.setObject(34, matNo.getActLenMin());
                insertComInfoPsta.setObject(35, matNo.getActLenMax());
                insertComInfoPsta.setObject(36, matNo.getActCount());
                insertComInfoPsta.setObject(37, matNo.getActWeight());
                insertComInfoPsta.setObject(38, matNo.getActTheoryWeight());
                insertComInfoPsta.setObject(39, manage);
                insertComInfoPsta.setObject(40, manageNmae);
                insertComInfoPsta.setObject(41, stono);
                insertComInfoPsta.setObject(42, stono + "10101");
                insertComInfoPsta.setObject(43, "");
                insertComInfoPsta.setObject(44, "");
                insertComInfoPsta.setObject(45, storageAtte);
                insertComInfoPsta.setObject(46, storageAtteName);
                insertComInfoPsta.setObject(47, storageType);
                insertComInfoPsta.setObject(48, storageTypeName);
                insertComInfoPsta.setObject(49, managNo);
                insertComInfoPsta.setObject(50, managName);
                insertComInfoPsta.setObject(51, systime);
                insertComInfoPsta.setObject(52, bc);
                insertComInfoPsta.setObject(53, bz);
                insertComInfoPsta.setObject(54, systime);
                insertComInfoPsta.setObject(55, banci);
                insertComInfoPsta.setObject(56, banzu);
                insertComInfoPsta.setObject(57, "");
                insertComInfoPsta.setObject(58, coluser);
                insertComInfoPsta.setObject(59, systime);
                insertComInfoPsta.setObject(60, matNo.getOrdPk());
                insertComInfoPsta.setObject(61, matNo.getOrdLnPk());
                insertComInfoPsta.setObject(62, pln.getOrdLnDlyPk());
                insertComInfoPsta.setObject(63, depNo);
                insertComInfoPsta.setObject(64, depName);
                insertComInfoPsta.setObject(65, pln.getOrderNo());
                insertComInfoPsta.setObject(66, pln.getOrderSeq());
                insertComInfoPsta.setObject(67, pln.getDeliveryNo());
                insertComInfoPsta.setObject(68, "801402");
                insertComInfoPsta.setObject(69, "80150201");
                insertComInfoPsta.setObject(70, judgestdname);
                insertComInfoPsta.setObject(71, judgestdcode);
                insertComInfoPsta.setObject(72, systime);
                insertComInfoPsta.setObject(73, lenNo);
                insertComInfoPsta.setObject(74, lenDesc);
                insertComInfoPsta.setObject(75, lenUnit);
                insertComInfoPsta.setObject(76, "");
                insertComInfoPsta.setObject(77, sourecode);
                insertComInfoPsta.setObject(78, sourename);
                insertComInfoPsta.setObject(79, matoriginCode);
                insertComInfoPsta.setObject(80, matoriginName);
                insertComInfoPsta.setObject(81, "1");
                if (matStart.equals("00")) {
                    insertComInfoPsta.setObject(82, "00");// 交库状态
                }
                else {
                    insertComInfoPsta.setObject(82, "22");
                }
                insertComInfoPsta.addBatch();
                
                //新增销售入库数据

                // 新增入库表数据
                insertComInfoPstaXs.setObject(1, inListDoc
                        + StringTool.formatDecimal(g, "0000"));
                insertComInfoPstaXs.setObject(2, inListDoc);
                insertComInfoPstaXs.setObject(3, strInBound);
                insertComInfoPstaXs.setObject(4, "产出入库");
                insertComInfoPstaXs.setObject(5, "");
                insertComInfoPstaXs.setObject(6, matNo.getMatNo());
                insertComInfoPstaXs.setObject(7, matNo.getLotNo());
                insertComInfoPstaXs.setObject(8, matNo.getStoveNo());
                insertComInfoPstaXs.setObject(9, judNo);
                insertComInfoPstaXs.setObject(10, zgNo);
                insertComInfoPstaXs.setObject(11, batchgroupno);
                insertComInfoPstaXs.setObject(12, pln.getOutwlId());
                insertComInfoPstaXs.setObject(13, pln.getOutwlDesc());
                insertComInfoPstaXs.setObject(14, producCode);//
                insertComInfoPstaXs.setObject(15, producName);
                insertComInfoPstaXs.setObject(16, matNo.getStdCode());
                insertComInfoPstaXs.setObject(17, matNo.getStdName());
                insertComInfoPstaXs.setObject(18, gradeCode);
                insertComInfoPstaXs.setObject(19, gradeName);
                insertComInfoPstaXs.setObject(20, steelCode);
                insertComInfoPstaXs.setObject(21, steelName);
                insertComInfoPstaXs.setObject(22, matNo.getStdStyle());
                insertComInfoPstaXs.setObject(23, matNo.getStdStyleDesc());
                insertComInfoPstaXs.setObject(24, specCode);
                insertComInfoPstaXs.setObject(25, specName);
                insertComInfoPstaXs.setObject(26, matNo.getModelCode());
                insertComInfoPstaXs.setObject(27, matNo.getModelDesc());
                insertComInfoPstaXs.setObject(28, pln.getOrderNo()
                        + pln.getOrderSeq());
                insertComInfoPstaXs.setObject(29, pln.getPlineCode());
                insertComInfoPstaXs.setObject(30, pln.getPlineName());
                insertComInfoPstaXs.setObject(31, matNo.getActDimater());
                insertComInfoPstaXs.setObject(32, matNo.getActHeight());
                insertComInfoPstaXs.setObject(33, matNo.getActLen());
                insertComInfoPstaXs.setObject(34, matNo.getActLenMin());
                insertComInfoPstaXs.setObject(35, matNo.getActLenMax());
                insertComInfoPstaXs.setObject(36, matNo.getActCount());
                insertComInfoPstaXs.setObject(37, matNo.getActWeight());
                insertComInfoPstaXs.setObject(38, matNo.getActTheoryWeight());
                insertComInfoPstaXs.setObject(39, manage);
                insertComInfoPstaXs.setObject(40, manageNmae);
                insertComInfoPstaXs.setObject(41, stono);
                insertComInfoPstaXs.setObject(42, stono + "10101");
                insertComInfoPstaXs.setObject(43, "");
                insertComInfoPstaXs.setObject(44, "");
                insertComInfoPstaXs.setObject(45, storageAtte);
                insertComInfoPstaXs.setObject(46, storageAtteName);
                insertComInfoPstaXs.setObject(47, storageType);
                insertComInfoPstaXs.setObject(48, storageTypeName);
                insertComInfoPstaXs.setObject(49, managNo);
                insertComInfoPstaXs.setObject(50, managName);
                insertComInfoPstaXs.setObject(51, systime);
                insertComInfoPstaXs.setObject(52, bc);
                insertComInfoPstaXs.setObject(53, bz);
                insertComInfoPstaXs.setObject(54, systime);
                insertComInfoPstaXs.setObject(55, banci);
                insertComInfoPstaXs.setObject(56, banzu);
                insertComInfoPstaXs.setObject(57, "");
                insertComInfoPstaXs.setObject(58, coluser);
                insertComInfoPstaXs.setObject(59, systime);
                insertComInfoPstaXs.setObject(60, matNo.getOrdPk());
                insertComInfoPstaXs.setObject(61, matNo.getOrdLnPk());
                insertComInfoPstaXs.setObject(62, pln.getOrdLnDlyPk());
                insertComInfoPstaXs.setObject(63, depNo);
                insertComInfoPstaXs.setObject(64, depName);
                insertComInfoPstaXs.setObject(65, pln.getOrderNo());
                insertComInfoPstaXs.setObject(66, pln.getOrderSeq());
                insertComInfoPstaXs.setObject(67, pln.getDeliveryNo());
                insertComInfoPstaXs.setObject(68, "801402");
                insertComInfoPstaXs.setObject(69, "80150201");
                insertComInfoPstaXs.setObject(70, judgestdname);
                insertComInfoPstaXs.setObject(71, judgestdcode);
                insertComInfoPstaXs.setObject(72, systime);
                insertComInfoPstaXs.setObject(73, lenNo);
                insertComInfoPstaXs.setObject(74, lenDesc);
                insertComInfoPstaXs.setObject(75, lenUnit);
                insertComInfoPstaXs.setObject(76, "");
                insertComInfoPstaXs.setObject(77, sourecode);
                insertComInfoPstaXs.setObject(78, sourename);
                insertComInfoPstaXs.setObject(79, matoriginCode);
                insertComInfoPstaXs.setObject(80, matoriginName);
                insertComInfoPstaXs.setObject(81, "1");
                if (matStart.equals("00")) {
                    insertComInfoPstaXs.setObject(82, "00");// 交库状态
                }
                else {
                    insertComInfoPstaXs.setObject(82, "22");
                }
                insertComInfoPstaXs.addBatch();
                
                g++;
                // 查询产线下工序的位置
   				int cnum = 0;
   				String sqlloading8 = CoreXmlSqlParsersFactory
   						.getSql("FrmMchInOnlineStore.queryGxPosition");
   				psta = con.prepareStatement(sqlloading8);
   				psta.setObject(1, pln.getPlineCode());
   				rs = psta.executeQuery();
   				if (rs.next()) {
   					if (rs.getString("CNUM") == "" || rs.getString("CNUM") == null) {
   						cnum = 0;
   					} else {
   						cnum = Integer.parseInt(rs.getString("CNUM"));
   					}
   				}
   				rs.close();
   				psta.close();
                // 修改工艺路径
   				if (cnum != 0) {
                pastupdatePath.setObject(1, "1");
                pastupdatePath.setObject(2, 2*cnum-2);
                pastupdatePath.setObject(3, "1");
                pastupdatePath.setObject(4, 2*cnum);
                pastupdatePath.setObject(5, "1");
                pastupdatePath.setObject(6, matNo.getMatNo());
                pastupdatePath.setObject(7, hertNo);
                pastupdatePath.addBatch();
   				}
           	 String MatNosql = CoreXmlSqlParsersFactory
						.getSql("FrmMchInOnlineStore.getQueryMatNo");// 查询材料表里对应的材料号
				psta = con.prepareStatement(MatNosql);
				psta.setObject(1, matNo.getMatNo());
				ResultSet rs5 = psta.executeQuery();
				//listMat = EntityTool.getEntitysByRs(rs5, MatZcMEntity.class);
				 if (rs5.next()) {
				count = rs5.getInt("COUNT(0)");
				 }
				rs5.close();
				psta.close();
				if(count==0)
				{
                //新增材料表
                matNoPsta.setObject(1, matNo.getMatNo());
                matNoPsta.setObject(2, productflag);
                matNoPsta.setObject(3, matstatus);
                matNoPsta.setObject(4, lotno);
                matNoPsta.setObject(5, stoveno);
                matNoPsta.setObject(6, judgestoveno);
                matNoPsta.setObject(7, batchno);
                matNoPsta.setObject(8, batchgroupno);
                matNoPsta.setObject(9, matsqeno);
                matNoPsta.setObject(10, sampleflag);
                matNoPsta.setObject(11, cuttingflag);
                matNoPsta.setObject(12, originmatno);
                matNoPsta.setObject(13, materialNo);
                matNoPsta.setObject(14, materialName);
                matNoPsta.setObject(15, inputmaterialname);
                matNoPsta.setObject(16, inputmaterialno);
                matNoPsta.setObject(17, inputorigincode);
                matNoPsta.setObject(18, producCode);
                matNoPsta.setObject(19, producName);
                matNoPsta.setObject(20, steelCode);
                matNoPsta.setObject(21, steelName);
                matNoPsta.setObject(22, gradeCode);
                matNoPsta.setObject(23, gradeName);
                matNoPsta.setObject(24, specCode);
                matNoPsta.setObject(25, specName);
                matNoPsta.setObject(26, modelcode);
                matNoPsta.setObject(27, modeldesc);
                matNoPsta.setObject(28, stdcode);
                matNoPsta.setObject(29, stdname);
                matNoPsta.setObject(30, stdstyle);
                matNoPsta.setObject(31, stdstyledesc);
                matNoPsta.setObject(32, proorderno);
                matNoPsta.setObject(33, proorderno1);
                matNoPsta.setObject(34, proorderid);
                matNoPsta.setObject(35, proorderid1);
                matNoPsta.setObject(36, orderno);
                matNoPsta.setObject(37, orderseq);
                matNoPsta.setObject(38, orderseqno);
                matNoPsta.setObject(39, crafno);
                matNoPsta.setObject(40, "G");
                matNoPsta.setObject(41, "加工");
                matNoPsta.setObject(42, nextprocesscode);
                matNoPsta.setObject(43, nextprocessdesc);
                matNoPsta.setObject(44, pln.getPlineCode());
                matNoPsta.setObject(45, pln.getPlineName());
                matNoPsta.setObject(46, matoriginCode);
                matNoPsta.setObject(47, matoriginName);
                matNoPsta.setObject(48, actdimater);
                matNoPsta.setObject(49, actheight);
                matNoPsta.setObject(50, actlen);
                if (matStart.equals("00")) {
                	matNoPsta.setObject(51, "00");// 交库状态
                }
                else {
                	matNoPsta.setObject(51, "22");
                }
              
                matNoPsta.setObject(52, "40740301");
                matNoPsta.setObject(53, "40740101");
                matNoPsta.setObject(54, "40740601");
                matNoPsta.setObject(55, "40740201");
                matNoPsta.setObject(56, "40740701");
                matNoPsta.setObject(57, list.get(19));
                matNoPsta.setObject(58, list.get(20));
                matNoPsta.setObject(59, vprflag);
                matNoPsta.setObject(60, manage);
                matNoPsta.setObject(61, manageNmae);
                matNoPsta.setObject(62, systime);
                matNoPsta.setObject(63, user);
                matNoPsta.setObject(64, pln.getCraftFileNo());
                matNoPsta.setObject(65, isSamp);
                matNoPsta.setObject(66, pln.getZyBatchId());
                matNoPsta.setObject(67, pln.getOrderNo() + pln.getOrderSeq());
                matNoPsta.setObject(68, pln.getProPlanId());
                matNoPsta.setObject(69, pln.getHeatPlanNo());
                matNoPsta.setObject(70, pln.getGxPlanNo());
                matNoPsta.setObject(71, pln.getPlineCode());
                matNoPsta.setObject(72, pln.getPlineName());
                matNoPsta.setObject(73, actlenmin);
                matNoPsta.setObject(74, actlenmax);
                matNoPsta.setObject(75, actcount);
                matNoPsta.setObject(76, actweight);
                matNoPsta.setObject(77, jugdeapplyflag);
                matNoPsta.setObject(78, jugdeapplycode);
                matNoPsta.setObject(79, jugdeapplytime);
                matNoPsta.setObject(80, faceresultcode);
                matNoPsta.setObject(81, chemresultcode);
                matNoPsta.setObject(82, phyresultcode);
                matNoPsta.setObject(83, detectresultcode);
                matNoPsta.setObject(84, judgeresultcode);
                matNoPsta.setObject(85, judgeresult);
                matNoPsta.setObject(86, judgeresulttime);
                matNoPsta.setObject(87, instocktime);
                matNoPsta.setObject(88, createname);
                matNoPsta.setObject(89, createtime);
                matNoPsta.setObject(90, ordpk);
                matNoPsta.setObject(91, ordlnpk);
                matNoPsta.setObject(92, ordlndlypk);
                matNoPsta.setObject(93, judgestdname);
                matNoPsta.setObject(94, judgestdcode);
                matNoPsta.setObject(95, sourecode);
                matNoPsta.setObject(96, sourename);
                matNoPsta.setObject(97, plngradename);
                matNoPsta.setObject(98, plngradecode);
                
                //新增销售材料表
                matNoPstaXs.setObject(1, matNo.getMatNo());
                matNoPstaXs.setObject(2, productflag);
                matNoPstaXs.setObject(3, matstatus);
                matNoPstaXs.setObject(4, lotno);
                matNoPstaXs.setObject(5, stoveno);
                matNoPstaXs.setObject(6, judgestoveno);
                matNoPstaXs.setObject(7, batchno);
                matNoPstaXs.setObject(8, batchgroupno);
                matNoPstaXs.setObject(9, matsqeno);
                matNoPstaXs.setObject(10, sampleflag);
                matNoPstaXs.setObject(11, cuttingflag);
                matNoPstaXs.setObject(12, originmatno);
                matNoPstaXs.setObject(13, materialNo);
                matNoPstaXs.setObject(14, materialName);
                matNoPstaXs.setObject(15, inputmaterialname);
                matNoPstaXs.setObject(16, inputmaterialno);
                matNoPstaXs.setObject(17, inputorigincode);
                matNoPstaXs.setObject(18, producCode);
                matNoPstaXs.setObject(19, producName);
                matNoPstaXs.setObject(20, steelCode);
                matNoPstaXs.setObject(21, steelName);
                matNoPstaXs.setObject(22, gradeCode);
                matNoPstaXs.setObject(23, gradeName);
                matNoPstaXs.setObject(24, specCode);
                matNoPstaXs.setObject(25, specName);
                matNoPstaXs.setObject(26, modelcode);
                matNoPstaXs.setObject(27, modeldesc);
                matNoPstaXs.setObject(28, stdcode);
                matNoPstaXs.setObject(29, stdname);
                matNoPstaXs.setObject(30, stdstyle);
                matNoPstaXs.setObject(31, stdstyledesc);
                matNoPstaXs.setObject(32, proorderno);
                matNoPstaXs.setObject(33, proorderno1);
                matNoPstaXs.setObject(34, proorderid);
                matNoPstaXs.setObject(35, proorderid1);
                matNoPstaXs.setObject(36, orderno);
                matNoPstaXs.setObject(37, orderseq);
                matNoPstaXs.setObject(38, orderseqno);
                matNoPstaXs.setObject(39, crafno);
                matNoPstaXs.setObject(40, "G");
                matNoPstaXs.setObject(41, "加工");
                matNoPstaXs.setObject(42, nextprocesscode);
                matNoPstaXs.setObject(43, nextprocessdesc);
                matNoPstaXs.setObject(44, pln.getPlineCode());
                matNoPstaXs.setObject(45, pln.getPlineName());
                matNoPstaXs.setObject(46, matoriginCode);
                matNoPstaXs.setObject(47, matoriginName);
                matNoPstaXs.setObject(48, actdimater);
                matNoPstaXs.setObject(49, actheight);
                matNoPstaXs.setObject(50, actlen);
                if (matStart.equals("00")) {
                	matNoPstaXs.setObject(51, "00");// 交库状态
                }
                else {
                	matNoPstaXs.setObject(51, "22");
                }
              
                matNoPstaXs.setObject(52, "40740301");
                matNoPstaXs.setObject(53, "40740101");
                matNoPstaXs.setObject(54, "40740601");
                matNoPstaXs.setObject(55, "40740201");
                matNoPstaXs.setObject(56, "40740701");
                matNoPstaXs.setObject(57, list.get(19));
                matNoPstaXs.setObject(58, list.get(20));
                matNoPstaXs.setObject(59, vprflag);
                matNoPstaXs.setObject(60, manage);
                matNoPstaXs.setObject(61, manageNmae);
                matNoPstaXs.setObject(62, systime);
                matNoPstaXs.setObject(63, user);
                matNoPstaXs.setObject(64, pln.getCraftFileNo());
                matNoPstaXs.setObject(65, isSamp);
                matNoPstaXs.setObject(66, pln.getZyBatchId());
                matNoPstaXs.setObject(67, pln.getOrderNo() + pln.getOrderSeq());
                matNoPstaXs.setObject(68, pln.getProPlanId());
                matNoPstaXs.setObject(69, pln.getHeatPlanNo());
                matNoPstaXs.setObject(70, pln.getGxPlanNo());
                matNoPstaXs.setObject(71, pln.getPlineCode());
                matNoPstaXs.setObject(72, pln.getPlineName());
                matNoPstaXs.setObject(73, actlenmin);
                matNoPstaXs.setObject(74, actlenmax);
                matNoPstaXs.setObject(75, actcount);
                matNoPstaXs.setObject(76, actweight);
                matNoPstaXs.setObject(77, jugdeapplyflag);
                matNoPstaXs.setObject(78, jugdeapplycode);
                matNoPstaXs.setObject(79, jugdeapplytime);
                matNoPstaXs.setObject(80, faceresultcode);
                matNoPstaXs.setObject(81, chemresultcode);
                matNoPstaXs.setObject(82, phyresultcode);
                matNoPstaXs.setObject(83, detectresultcode);
                matNoPstaXs.setObject(84, judgeresultcode);
                matNoPstaXs.setObject(85, judgeresult);
                matNoPstaXs.setObject(86, judgeresulttime);
                matNoPstaXs.setObject(87, instocktime);
                matNoPstaXs.setObject(88, createname);
                matNoPstaXs.setObject(89, createtime);
                matNoPstaXs.setObject(90, ordpk);
                matNoPstaXs.setObject(91, ordlnpk);
                matNoPstaXs.setObject(92, ordlndlypk);
                matNoPstaXs.setObject(93, judgestdname);
                matNoPstaXs.setObject(94, judgestdcode);
                matNoPstaXs.setObject(95, sourecode);
                matNoPstaXs.setObject(96, sourename);
                matNoPstaXs.setObject(97, plngradename);
                matNoPstaXs.setObject(98, plngradecode);
                matNoPsta.addBatch();
                matNoPstaXs.addBatch();
				}
            }
            pstaMatM.executeBatch();
            pstaMatMXs.executeBatch();
            patButt.executeBatch();
            insertComInfoPsta.executeBatch();
            insertComInfoPstaXs.executeBatch();
            pastupdatePath.executeBatch();
            matNoPsta.executeBatch();
            matNoPstaXs.executeBatch();

            
            String resultNo = "";
            String sqlloading2 = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryExpandMaxRESULT");// 查询最大实绩编号
            psta = con.prepareStatement(sqlloading2);
            psta.setObject(1, pln.getPlineCode() + SlGx + matter1.format(dt));
            psta.setObject(2, date.format(dt));
            psta.setObject(3, pln.getPlineCode());
            psta.setObject(4, SlGx);
            ResultSet rs2 = psta.executeQuery();
            if (rs2.next()) {
                resultNo = rs2.getString("RESULT_NO");
            }
            rs2.close();
            psta.close();
            // 新增公共信息
            patsPlan.setObject(1, pln.getHeatPlanNo());
            patsPlan.setObject(2, resultNo);
            patsPlan.setObject(3, SlGx);
            patsPlan.setObject(4, gxname);
            patsPlan.setObject(5, "");// 品名代码
            patsPlan.setObject(6, "");// 品名
            patsPlan.setObject(7, "");// 钢种代码
            patsPlan.setObject(8, "");// 钢种
            patsPlan.setObject(9, "");// 扣型代码
            patsPlan.setObject(10, "");
            patsPlan.setObject(11, "");// 标准代码
            patsPlan.setObject(12, "");
            patsPlan.setObject(13, "");// 标准类别代码
            patsPlan.setObject(14, "");
            patsPlan.setObject(15, "");// 原料管规格代码
            patsPlan.setObject(16, "");
            patsPlan.setObject(17, "");// 产出规格代码
            patsPlan.setObject(18, "");
            patsPlan.setObject(19, "");// 产出外径
            patsPlan.setObject(20, "");// 产出壁厚
            patsPlan.setObject(21, "");// 产出长度
            patsPlan.setObject(22, "");// 产出长度下限
            patsPlan.setObject(23, "");// 产出长度上限
            if (matStart.equals("10")) {
                patsPlan.setObject(24, "0");
                patsPlan.setObject(25, "0");
                patsPlan.setObject(26, actCount);// 废品
                patsPlan.setObject(27, weghit);
            }
            else {
                patsPlan.setObject(24, actCount);
                patsPlan.setObject(25, weghit);
                patsPlan.setObject(26, "0");// 废品
                patsPlan.setObject(27, "0");
            }
            patsPlan.setObject(28, "");// 离线
            patsPlan.setObject(29, "");
            patsPlan.setObject(30, "");// 返线
            patsPlan.setObject(31, "");
            patsPlan.setObject(32, "");// 过磅重量
            patsPlan.setObject(33, inListDoc);// 入库单号
            patsPlan.setObject(34, systime);
            patsPlan.setObject(35, user);
            patsPlan.setObject(36, banci);
            patsPlan.setObject(37, banzu);
            patsPlan.setObject(38, systime);
            patsPlan.setObject(39, coluser);
            patsPlan.setObject(40, belongCode);
            patsPlan.setObject(41, belongName);
            patsPlan.addBatch();
            // 修改计划表
            if (matStart.equals("00")) {
                //planJgPsta.setObject(1, weghit);
                //planJgPsta.setObject(2, actCount);
                //planJgPsta.setObject(1, list.get(19));
                //planJgPsta.setObject(2, list.get(20));
                planJgPsta.setObject(1, hertNo);
                planJgPsta.addBatch();
                planJgPsta.executeBatch();
                planJgPstaC.setObject(1, weghit);
                planJgPstaC.setObject(2, actCount);
                planJgPstaC.setObject(3, hertNo);
                planJgPstaC.addBatch();
                planJgPstaC.executeBatch();
            }

            patsPlan.executeBatch();
            cor.setV_errMsg("交库成功！");
            con.commit();
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            if (con != null) {
                try {
                    cor.setV_errMsg(e.getMessage());
                    con.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    con.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cor;
    }

    /**
     * 删除交库实绩
     * @param result 删除交库实绩
     * @return
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject deleteLibraryResult(ArrayList<Object> pram,
            String SlGx, String jud, String batch, String plineCode,String plineName) {
        CoreReturnObject cor = new CoreReturnObject();
        Connection con = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(now);
        try {
            con.setAutoCommit(false); // 取消自动提交事务
            String comInfoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.DeleteComInfoResult");// 删除comInfo表
            PreparedStatement comInfoPsta = con.prepareStatement(comInfoSql);
            String planJgSql = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.UpdatePlanResult");// 修改计划表
            PreparedStatement planJgPsta = con.prepareStatement(planJgSql);
            String planJgSqlC = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.UpdatePlanResultC");// 修改计划从表
            PreparedStatement planJgPstaC = con.prepareStatement(planJgSqlC);
            String strMatM = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.AddMatM");// 修改加工材料表
            PreparedStatement pstaMatM = con.prepareStatement(strMatM);
            String strMatMXs = CoreXmlSqlParsersFactory
                    .getSql("matxs.AddMatM");// 修改加工材料表
            PreparedStatement pstaMatMXs = con.prepareStatement(strMatMXs);
            String strMatButters = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.DeleteMatButters");// 删除位置表
            PreparedStatement pstaMatButters = con
                    .prepareStatement(strMatButters);
            String deleteLin = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.DeleteLinResult");// 删除入库实绩表
            PreparedStatement pstadeleteLin = con.prepareStatement(deleteLin);
            
            String deleteLinXs = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStoreXs.DeleteLinResult");// 删除入库实绩表
            PreparedStatement pstadeleteLinXs = con.prepareStatement(deleteLinXs);
            
            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.UpdatePath1");// 修改队列表工艺路径,虚拟入库标志
            PreparedStatement pastupdatePath = con.prepareStatement(updatePath);
            
            String detePath = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.detelematno");// 删除交库时新增的材料表
            PreparedStatement detemat = con.prepareStatement(detePath);
            
            
            String detePathXs = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStoreXs.detelematno");// 删除销售交库时新增的材料表
            PreparedStatement detematXs = con.prepareStatement(detePathXs);
            
            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String hertNo = list.get(0);
                // String judNo = list.get(1);// 炉号
                // String zgNo = list.get(2);// 批号
                // String groupNo = list.get(3);// 组号
                String matStrat = list.get(4);
                String libCount = list.get(5);// 个数
                String weight = list.get(6);
                String name = list.get(7);
                String inList = list.get(8);
                // String prfalg = list.get(9);
                station = "2";
                String sqlloadings = CoreXmlSqlParsersFactory
                        .getSql("FrmMchInOnlineStore.queryperstu");// 查询信息表除了本工序之外最大的工序
                PreparedStatement pstas = con.prepareStatement(sqlloadings);
                pstas.setObject(1, hertNo);
                pstas.setObject(2, SlGx);
                ResultSet rss = pstas.executeQuery();
                if (rss.next()) {
                	perStuts = rss.getString("STATION_CODE");
//                	if(perStuts.equals("0"))
//                	{
//                		cor.setV_errMsg("无工序，不允许此操作!");
//                         return cor;
//                	}else 
                		if(perStuts.equals("701301"))
                	{
                		perStuts = "00";
                	}else if(perStuts.equals("701302"))
                	{
                		perStuts = "01";
                	}else if(perStuts.equals("701303"))
                	{
                		perStuts = "02";
                	}else if(perStuts.equals("701304"))
                	{
                		perStuts = "03";
                	}else if(perStuts.equals("701305"))
                	{
                		perStuts = "04";
                	}else if(perStuts.equals("701306"))
                	{
                		perStuts = "05";
                	}else if(perStuts.equals("701307"))
                	{
                		perStuts = "06";
                	}else if(perStuts.equals("701308"))
                	{
                		perStuts = "07";
                	}else if(perStuts.equals("701309"))
                	{
                		perStuts = "08";
                	}else if(perStuts.equals("701310"))
                	{
                		perStuts = "09";
                	}else if(perStuts.equals("701311"))
                	{
                		perStuts = "10";
                	}
                }
                rss.close();
                pstas.close();
                //删除交库时新增的材料表
                String Mat = "";
                String sqlmatno = CoreXmlSqlParsersFactory
                        .getSql("FrmMchInOnlineStore.querymchmatno");// 查询管号队列里最小的材料号
                PreparedStatement psta3 = con.prepareStatement(sqlmatno);
                psta3.setObject(1, hertNo);
                
                ResultSet rs3 = psta3.executeQuery();
                if (rs3.next()) {
                    Mat = rs3.getString("MAT_NO");
                }
                rs3.close();
                psta3.close();
                
                
                detemat.setObject(1, Mat);
                detemat.addBatch();
                
                detematXs.setObject(1, Mat);
                detematXs.addBatch();

                String inStatus1 = "";
                String belongCode = "";
                String belongName = "";
                String sqlloading1 = CoreXmlSqlParsersFactory
                        .getSql("FrmMchInOnlineStore.querystatus");// 查询公共信息表里交库工序状态
                PreparedStatement psta1 = con.prepareStatement(sqlloading1);
                psta1.setObject(1, SlGx);
                psta1.setObject(2, hertNo);
                ResultSet rs1 = psta1.executeQuery();
                if (rs1.next()) {
                    inStatus1 = rs1.getString("STATION_STATUS");
                    belongCode = rs1.getString("BELONG_CODE");
                    belongName = rs1.getString("BELONG_NAME");
                }
                rs1.close();
                psta1.close();
                if (inStatus1.equals("2")) {
                    cor.setV_errMsg("该计划交库工序已经结庐，不允许此操作！");
                    return cor;
                }
                int planStatus = 0;
                //String gxNameLast = "";
                String sqlloading = CoreXmlSqlParsersFactory
                        .getSql("FrmMchInOnlineStore.queryPlanJg");// 查询加工计划表状态
                PreparedStatement psta = con.prepareStatement(sqlloading);
                psta.setObject(1, hertNo);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    planStatus = Integer.parseInt(rs.getString("PLANSTATUS"));
                    //gxNameLast = rs.getString("GX_NAME_LAST");
                }
                rs.close();
                psta.close();
                if (planStatus > '2') {
                    cor.setV_errMsg("该工单计划已生产完成或已关闭！");
                    return cor;
                }
                // 获取材料号
                List<VrpMatZcMEntity> mat = new ArrayList<VrpMatZcMEntity>();
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("FrmMchInOnlineStore.queryMaxMatNo1");// 查询材料表成品的材料号
                psta = con.prepareStatement(sqlloading);
                psta.setObject(1, inList);
                psta.setObject(2, Integer.parseInt(libCount) + 1);
                rs = psta.executeQuery();
                mat = EntityTool.getEntitysByRs(rs, VrpMatZcMEntity.class);
                rs.close();
                psta.close();
                                             
                for (VrpMatZcMEntity matNo : mat) {
                    // 修改材料表
                    pstaMatM.setObject(1, "801401");
                    pstaMatM.setObject(2, "80150105");
//                    if (gxNameLast.equals("镦拔扩")) {
//                        pstaMatM.setObject(3, "E");
//                        pstaMatM.setObject(4, gxNameLast);
//                    }
//                    else if (gxNameLast.equals("热处理")) {
//                        pstaMatM.setObject(3, "F");
//                        pstaMatM.setObject(4, gxNameLast);
//                    }
//                    else {
//                        pstaMatM.setObject(3, "D");
//                        pstaMatM.setObject(4, gxNameLast);
//                    }
                    pstaMatM.setObject(3, "E");
                    pstaMatM.setObject(4, "镦拔扩");
                    pstaMatM.setObject(5, "");
                    pstaMatM.setObject(6, "");
                    pstaMatM.setObject(7, "");// [加工工序]表面判定结果代码
                    pstaMatM.setObject(8, "");// [加工工序]成分判定结果代码
                    pstaMatM.setObject(9, "");// 工序排产序号1
                    pstaMatM.setObject(10, "");// 工序排产序号1
                    pstaMatM.setObject(11, "");// [加工工序]公差判定结果代码
                    pstaMatM.setObject(12, "");// 加工交库状态
                    pstaMatM.setObject(13, "");
                    pstaMatM.setObject(14, "");// [加工工序]生产订单号（1）
                    pstaMatM.setObject(15, "");// [加工工序]生产订单号（2）
                    pstaMatM.setObject(16, "");// [加工工序]生产合同号（1）
                    pstaMatM.setObject(17, "");// [加工工序]生产合同号（2）
                    pstaMatM.setObject(18, "");// 生产批号
                    pstaMatM.setObject(19, "");// [加工工序]性能判定结果代码(理化)
                    pstaMatM.setObject(20, "");// 样管标志
                    pstaMatM.setObject(21, "");// 执行工艺号
                    pstaMatM.setObject(22, "");// 质量分组号
                    pstaMatM.setObject(23, matNo.getInputMaterialNo());
                    pstaMatM.setObject(24, matNo.getInputMaterialName());
                    pstaMatM.setObject(25, "");
                    pstaMatM.setObject(26, "");
                    pstaMatM.setObject(27, "");// 投料物料来源
                    pstaMatM.setObject(28, "G");// 下道工序Id
                    pstaMatM.setObject(29, "加工");// 下道工序
                    
                    pstaMatMXs.setObject(3, "E");
                    pstaMatMXs.setObject(4, "镦拔扩");
                    pstaMatMXs.setObject(5, "");
                    pstaMatMXs.setObject(6, "");
                    pstaMatMXs.setObject(7, "");// [加工工序]表面判定结果代码
                    pstaMatMXs.setObject(8, "");// [加工工序]成分判定结果代码
                    pstaMatMXs.setObject(9, "");// 工序排产序号1
                    pstaMatMXs.setObject(10, "");// 工序排产序号1
                    pstaMatMXs.setObject(11, "");// [加工工序]公差判定结果代码
                    pstaMatMXs.setObject(12, "");// 加工交库状态
                    pstaMatMXs.setObject(13, "");
                    pstaMatMXs.setObject(14, "");// [加工工序]生产订单号（1）
                    pstaMatMXs.setObject(15, "");// [加工工序]生产订单号（2）
                    pstaMatMXs.setObject(16, "");// [加工工序]生产合同号（1）
                    pstaMatMXs.setObject(17, "");// [加工工序]生产合同号（2）
                    pstaMatMXs.setObject(18, "");// 生产批号
                    pstaMatMXs.setObject(19, "");// [加工工序]性能判定结果代码(理化)
                    pstaMatMXs.setObject(20, "");// 样管标志
                    pstaMatMXs.setObject(21, "");// 执行工艺号
                    pstaMatMXs.setObject(22, "");// 质量分组号
                    pstaMatMXs.setObject(23, matNo.getInputMaterialNo());
                    pstaMatMXs.setObject(24, matNo.getInputMaterialName());
                    pstaMatMXs.setObject(25, "");
                    pstaMatMXs.setObject(26, "");
                    pstaMatMXs.setObject(27, "");// 投料物料来源
                    pstaMatMXs.setObject(28, "G");// 下道工序Id
                    pstaMatMXs.setObject(29, "加工");// 下道工序
                    
                   // if (gxNameLast.equals("镦拔扩")) {
                        pstaMatM.setObject(30, matNo.getVrpPlineCode());
                        pstaMatM.setObject(31, matNo.getVrpPlineName());
                        
                        pstaMatMXs.setObject(30, matNo.getVrpPlineCode());
                        pstaMatMXs.setObject(31, matNo.getVrpPlineName());
//                    }
//                    else if (gxNameLast.equals("热处理")) {
//                        pstaMatM.setObject(30, matNo.getHttPlineCode());
//                        pstaMatM.setObject(31, matNo.getHttPlineName());
//                    }
//                    else {
//                        pstaMatM.setObject(30, matNo.getZgPlineCode());
//                        pstaMatM.setObject(31, matNo.getZgPlineName());
//                    }
                    pstaMatM.setObject(32, name);
                    pstaMatM.setObject(33, systime);
                    pstaMatM.setObject(34, "");// [加工工序]综合判定结果代码
                    pstaMatM.setObject(35, belongCode);
                    pstaMatM.setObject(36, belongName);
                    pstaMatM.setObject(37, "");
                    pstaMatM.setObject(38, "");
                    pstaMatM.setObject(39, "");
                    pstaMatM.setObject(40, matNo.getMatNo());
                    pstaMatM.addBatch();
                    
                    pstaMatMXs.setObject(32, name);
                    pstaMatMXs.setObject(33, systime);
                    pstaMatMXs.setObject(34, "");// [加工工序]综合判定结果代码
                    pstaMatMXs.setObject(35, belongCode);
                    pstaMatMXs.setObject(36, belongName);
                    pstaMatMXs.setObject(37, "");
                    pstaMatMXs.setObject(38, "");
                    pstaMatMXs.setObject(39, "");
                    pstaMatMXs.setObject(40, matNo.getMatNo());
                    pstaMatMXs.addBatch();
                    
                  
                }
                // 获取材料号
                List<YdmZcButtressEntity> MAT = new ArrayList<YdmZcButtressEntity>();
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("FrmMchInOnlineStore.queryMaxMatNogai");// 查询位置表成品的材料号
                psta = con.prepareStatement(sqlloading);
                psta.setObject(1, Integer.parseInt(libCount) + 1);
                rs = psta.executeQuery();
                MAT = EntityTool.getEntitysByRs(rs, YdmZcButtressEntity.class);
                rs.close();
                psta.close();
                for(YdmZcButtressEntity matno:MAT)
                {
                // 删除位置表
                pstaMatButters.setObject(1, matno.getMatNo());
                pstaMatButters.addBatch();
                // 删除交库实绩表
                pstadeleteLin.setObject(1, matno.getMatNo());
                pstadeleteLin.setObject(2, inList);
                pstadeleteLin.addBatch();
                
             // 删除交库实绩表
                pstadeleteLinXs.setObject(1, matno.getMatNo());
                pstadeleteLinXs.setObject(2, inList);
                pstadeleteLinXs.addBatch();
                
                // 查询产线下工序的位置
				int cnum = 0;
				String sqlloading8 = CoreXmlSqlParsersFactory
						.getSql("FrmMchInOnlineStore.queryGxPosition");
				psta = con.prepareStatement(sqlloading8);
				psta.setObject(1, plineCode);
				rs = psta.executeQuery();
				if (rs.next()) {
					if (rs.getString("CNUM") == "" || rs.getString("CNUM") == null) {
						cnum = 0;
					} else {
						cnum = Integer.parseInt(rs.getString("CNUM"));
					}
				}
				rs.close();
				psta.close();
                // 修改工艺路径
				if(cnum!=0)
				{
                pastupdatePath.setObject(1, "1");
                pastupdatePath.setObject(2, 2*cnum-2);
                pastupdatePath.setObject(3, "0");
                pastupdatePath.setObject(4, 2*cnum);
                pastupdatePath.setObject(5, "0");
                pastupdatePath.setObject(6, matno.getMatNo());
                pastupdatePath.setObject(7, hertNo);
                pastupdatePath.addBatch();
				}
                }
                pstaMatM.executeBatch();
                pstaMatMXs.executeBatch();

                pstaMatButters.executeBatch();
                pstadeleteLin.executeBatch();
                pstadeleteLinXs.executeBatch();
                pastupdatePath.executeBatch();

                // 删除公共信息表
                comInfoPsta.setObject(1, hertNo);
                comInfoPsta.setObject(2, SlGx);
                comInfoPsta.setObject(3, inList);
                comInfoPsta.addBatch();

                if (matStrat.equals("合格")) {
                    // 修改计划表
                    //planJgPsta.setObject(1, weight);
                    //planJgPsta.setObject(2, libCount);

                    planJgPsta.setObject(1, perStuts);//“09”
                    planJgPsta.setObject(2, hertNo);
                    planJgPsta.addBatch();
                    
                    planJgPstaC.setObject(1, weight);
                    planJgPstaC.setObject(2, libCount);
                    planJgPstaC.setObject(3, hertNo);
                    planJgPstaC.addBatch();
                    
                }
            }
            detemat.executeBatch();
            detematXs.executeBatch();
            comInfoPsta.executeBatch();
            planJgPsta.executeBatch();
            planJgPstaC.executeBatch();

            cor.setV_errMsg("撤销交库成功！");
            con.commit();
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            if (con != null) {
                try {
                    cor.setV_errMsg(e.getMessage());
                    con.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    con.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cor;
    }

    /***
     * 结炉
     * @param jugeNo
     * @param plineCode
     * @return
     */
    public CoreReturnObject doBeside(String heraNo, String SlGx,
            String plineCode, String proPlanId, String gxPlanNo)
            throws Exception {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务

            String strMatButters = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.updateif");// 修改管号队列“是否入库”字段
            PreparedStatement pstaMatButters = connection
                    .prepareStatement(strMatButters);
            String updatePlanSql = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.doBeside");// 修改公共信息表的状态为生产完成
            PreparedStatement updatePlanPsta = connection
                    .prepareStatement(updatePlanSql);
            String updatepln = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.updatePln");// 修改加工计划表状态为生产完成
            PreparedStatement updateplnPsta = connection
                    .prepareStatement(updatepln);
            String updateplnId = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.updatePlnId");// 修改加工订单表状态为生产完成
            PreparedStatement updateplnPstaId = connection
                    .prepareStatement(updateplnId);
            String updateplnSeq = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.updatePlnGxProSeq");// 修改加工订单表下一顺序号状态为生产中
            PreparedStatement updateplnPstaSeq = connection
                    .prepareStatement(updateplnSeq);

            String inStatus = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.querystatus");// 查询公共信息表里交库工序状态
            PreparedStatement psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, SlGx);
            psta.setObject(2, heraNo);
            ResultSet rs = psta.executeQuery();
            if (rs.next()) {
                inStatus = rs.getString("STATION_STATUS");
            }
            rs.close();
            psta.close();
            if (inStatus.equals("2")) {
                cro.setV_errMsg("该交库工序已经结庐，不允许此操作！");
                return cro;
            }
            if (inStatus.equals("")) {
                cro.setV_errMsg("没有交库信息,不允许结炉!");
                return cro;
            }
            // 修改管号队列入库字段
            pstaMatButters.setObject(1, "1");
            pstaMatButters.setObject(2, heraNo);
            pstaMatButters.addBatch();
            pstaMatButters.executeBatch();

            // 修改公共表结炉状态
            updatePlanPsta.setString(1, "2");
            updatePlanPsta.setString(2, SlGx);
            updatePlanPsta.setString(3, heraNo);
            updatePlanPsta.addBatch();
            // 修改加工计划表

            updateplnPsta.setObject(1, "30");
            updateplnPsta.setObject(2, "10");
            updateplnPsta.setObject(3, heraNo);
            updateplnPsta.addBatch();
            updateplnPsta.executeBatch();
            pstaMatButters.executeBatch();
            updatePlanPsta.executeBatch();

//            int countReady = 0;
//            sqlloading = CoreXmlSqlParsersFactory
//                    .getSql("FrmMchInOnlineStore.queryProPlanReady");// 查询虚拟炉计划是否为零
//            psta = connection.prepareStatement(sqlloading);
//            psta.setObject(1, proPlanId);
//            psta.setObject(2, gxPlanNo);
//            rs = psta.executeQuery();
//            if (rs.next()) {
//                countReady = Integer.parseInt(rs.getString("COUNT"));
//            }
//            rs.close();
//            psta.close();
            int count = 0;
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryProPlanID");// 查询订单下是否还有未生产完成的炉计划
            psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, proPlanId);
            psta.setObject(2, gxPlanNo);
            rs = psta.executeQuery();
            if (rs.next()) {
                count = Integer.parseInt(rs.getString("COUNT"));
            }
            rs.close();
            psta.close();
            if (count == 0 ) {//&& countReady == 0
                updateplnPstaId.setObject(1, "2");
                updateplnPstaId.setObject(2, systime);
                updateplnPstaId.setObject(3, proPlanId);
                updateplnPstaId.setObject(4, gxPlanNo);
                updateplnPstaId.addBatch();
                updateplnPstaId.executeBatch();

                int gxProSeq = 0;
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("FrmMchInOnlineStore.queryProPlandBkS");// 查询订单排产顺序号和结束时间
                psta = connection.prepareStatement(sqlloading);
                psta.setObject(1, proPlanId);
                psta.setObject(2, gxPlanNo);
                rs = psta.executeQuery();
                if (rs.next()) {
                    gxProSeq = Integer.parseInt(rs.getString("GX_PRO_SEQ"));
                }
                rs.close();
                psta.close();
                com.steering.common.EntityTool.timeIncrease(connection,
                        gxProSeq, plineCode, systime, "E");
                updateplnPstaSeq.setObject(1, "1");
                updateplnPstaSeq.setObject(2, String.valueOf(gxProSeq + 1));
                updateplnPstaSeq.setObject(3, plineCode);
                updateplnPstaSeq.addBatch();
                updateplnPstaSeq.executeBatch();
            }

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

    /***
     * 撤销结炉
     * @param zYgNo
     * @return
     */
    public CoreReturnObject undoBeside(ArrayList<String> list, String SlGx,
            String plineCode) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务

            String strMatButters = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.updateif");// 修改管号队列“是否入库”字段
            PreparedStatement pstaMatButters = connection
                    .prepareStatement(strMatButters);
            String updatePlanSql = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.doBeside");// 修改公共信息表的状态为生产完成
            PreparedStatement updatePlanPsta = connection
                    .prepareStatement(updatePlanSql);
            String updatepln = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.updatePln");// 修改加工计划表状态为生产完成
            PreparedStatement updateplnPsta = connection
                    .prepareStatement(updatepln);
            String updateplnId = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.deletePlnId");// 修改加工订单表状态为生产中
            PreparedStatement updateplnPstaId = connection
                    .prepareStatement(updateplnId);
            String updateplnSeq = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.updatePlnGxProSeq");// 修改加工订单表下一顺序号状态为计划
            PreparedStatement updateplnPstaSeq = connection
                    .prepareStatement(updateplnSeq);

            String heraNo = list.get(0);
            String judNo = list.get(1);
            String batchNo = list.get(2);
            String proPlanId = list.get(3);
            String gxPlanNo = list.get(4);
            String sqlloadings = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryperstu");// 查询信息表除了本工序之外最大的工序
            PreparedStatement pstas = connection.prepareStatement(sqlloadings);
            pstas.setObject(1, heraNo);
            pstas.setObject(2, SlGx);
            ResultSet rss = pstas.executeQuery();
            if (rss.next()) {
            	perStuts = rss.getString("STATION_CODE");
//            	if(perStuts.equals("0"))
//            	{
//            		cro.setV_errMsg("无工序，不允许此操作!");
//                     return cro;
//            	}else 
            		if(perStuts.equals("701301"))
            	{
            		perStuts = "00";
            	}else if(perStuts.equals("701302"))
            	{
            		perStuts = "01";
            	}else if(perStuts.equals("701303"))
            	{
            		perStuts = "02";
            	}else if(perStuts.equals("701304"))
            	{
            		perStuts = "03";
            	}else if(perStuts.equals("701305"))
            	{
            		perStuts = "04";
            	}else if(perStuts.equals("701306"))
            	{
            		perStuts = "05";
            	}else if(perStuts.equals("701307"))
            	{
            		perStuts = "06";
            	}else if(perStuts.equals("701308"))
            	{
            		perStuts = "07";
            	}else if(perStuts.equals("701309"))
            	{
            		perStuts = "08";
            	}else if(perStuts.equals("701310"))
            	{
            		perStuts = "09";
            	}else if(perStuts.equals("701311"))
            	{
            		perStuts = "10";
            	}
            }
            rss.close();
            pstas.close();
            String inStatus = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.querystatus");// 查询公共信息表里交库工序状态
            PreparedStatement psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, SlGx);
            psta.setObject(2, heraNo);
            ResultSet rs = psta.executeQuery();
            if (rs.next()) {
                inStatus = rs.getString("STATION_STATUS");
            }
            rs.close();
            psta.close();
            if (inStatus.equals("1")) {
                cro.setV_errMsg("该交库工序未结庐，不允许此操作！");
                return cro;
            }
            if (inStatus.equals("")) {
                cro.setV_errMsg("没有交库信息,不允许此操作!");
                return cro;
            }
            int appCode = 0;
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryApCode");// 查询炉计划是否申请判定
            psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, judNo);
            psta.setObject(2, batchNo);
            rs = psta.executeQuery();
            if (rs.next()) {
                appCode = Integer.parseInt(rs.getString("COUNT"));
            }
            rs.close();
            psta.close();
            if (appCode != 0) {
                cro.setV_errMsg("该炉计划已申请判定，不允许此撤销结炉！");
                return cro;
            }
           
            // 修改管号队列入库字段
            pstaMatButters.setObject(1, "0");
            pstaMatButters.setObject(2, heraNo);
            pstaMatButters.addBatch();
            pstaMatButters.executeBatch();

            // 修改公共表结炉状态
            updatePlanPsta.setString(1, "1");
            updatePlanPsta.setString(2, SlGx);
            updatePlanPsta.setString(3, heraNo);
            updatePlanPsta.addBatch();
            // 修改加工计划表
            updateplnPsta.setObject(1, "20");
            updateplnPsta.setObject(2, perStuts);//"09"
            updateplnPsta.setObject(3, heraNo);
            updateplnPsta.addBatch();

            // 修改加工订单表
            updateplnPstaId.setObject(1, "1");
            updateplnPstaId.setObject(2, proPlanId);
            updateplnPstaId.setObject(3, gxPlanNo);
            updateplnPstaId.addBatch();

            updateplnPsta.executeBatch();
            pstaMatButters.executeBatch();
            updatePlanPsta.executeBatch();
            updateplnPstaId.executeBatch();

            int gxProSeq = 0;
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.queryProPlandBkS");// 查询订单排产顺序号和结束时间
            psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, proPlanId);
            psta.setObject(2, gxPlanNo);
            rs = psta.executeQuery();
            if (rs.next()) {
                gxProSeq = Integer.parseInt(rs.getString("GX_PRO_SEQ"));
            }
            rs.close();
            psta.close();

            updateplnPstaSeq.setObject(1, "0");
            updateplnPstaSeq.setObject(2, String.valueOf(gxProSeq + 1));
            updateplnPstaSeq.setObject(3, plineCode);
            updateplnPstaSeq.addBatch();
            updateplnPstaSeq.executeBatch();

            cro.setV_errMsg("撤销结炉成功!");
            connection.commit();
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            if (connection != null) {
                try {
                    cro.setV_errMsg(e.getMessage());
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cro;
    }
    
    /**
     * 离线
     * @param load
     * @return
     */
    public CoreReturnObject offLineExpandResult(ArrayList<MchOfflineResultDentity> list1,
            ArrayList<String> list, String plinCode, String storageNo) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        Date dt = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
        SimpleDateFormat matter = new SimpleDateFormat("yyyyMMdd");
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String addOff = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.AddOffLine");// 新增离线实绩
            PreparedStatement patAdd = connection.prepareStatement(addOff);
            String addOffD = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.AddOffLineD");// 新增离线实绩从表
            PreparedStatement patAddD = connection.prepareStatement(addOffD);
            String addButt = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.AddYdmButt");// 新增库存位置信息
            PreparedStatement patButt = connection.prepareStatement(addButt);
            String addIn = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.AddYdmInList");// 新增入库信息
            PreparedStatement patIn = connection.prepareStatement(addIn);
            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("FrmMchInOnlineStore.AddComInfoResult");// 新增公共信息
            PreparedStatement patsPlan = connection
                    .prepareStatement(addPlnInfo);
            String updateMat = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.UpdateMatNo");// 修改材料状态
            PreparedStatement patMatNo = connection.prepareStatement(updateMat);

            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.UpdatePathPortVrpcut");// 修改队列表工艺路径,材料，工序状态
            PreparedStatement pastupdatePath = connection
                    .prepareStatement(updatePath);

            String heatPlanNo = list.get(0);
            String slgx = list.get(1);		
            String slgxname = list.get(2);
            String name = list.get(3);
            String time = list.get(4);
            String bc = list.get(5);
            String bz = list.get(6);
            String count = list.get(7);
            String matStart = list.get(8);
            String isSamp = list.get(9);
             // 获取加工计划实体了
	            PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
	            		heatPlanNo);
            if (pln == null)
                return core;
            // if (!pln.getPlanstatus().equals("2")) {
            // core.setV_errMsg("该计划不是生产中的，请确认是否生产完成或未上料！");
            // return core;
            // }
            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.qureyGxComInfo");// 查询工序结炉状态
            PreparedStatement psta1 = connection.prepareStatement(sql);
            psta1.setString(1, heatPlanNo);
            psta1.setString(2, plinCode);
            psta1.setString(3, slgx);
            ResultSet rs = psta1.executeQuery();
            if (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
            }
            if (cutFalg.equals("2")) {
                core.setV_errMsg("已结炉,不允许此操作！");
                return core;
            }
            rs.close();
            psta1.close();
            List<PortMchBatchSampleResultEntity> matNo = new ArrayList<PortMchBatchSampleResultEntity>();
            String sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.queryPortVrpHgcut");// 查询管号队列里合格的数据
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, heatPlanNo);
            psta.setObject(2, Integer.parseInt(count) + 1);
            ResultSet rs2 = psta.executeQuery();
            matNo = EntityTool.getEntitysByRs(rs2,
            		PortMchBatchSampleResultEntity.class);
            rs2.close();
            psta.close();
            if (matNo == null) {
                core.setV_errMsg("管号队列全为样管，不能离线！");
                return core;
            }
            int batchCount = 0;
            sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.queryPortVrpBatchHg");// 查询管号队列里不是样管的合格支
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, heatPlanNo);
            rs2 = psta.executeQuery();
            if (rs2.next()) {
                batchCount = Integer.parseInt(rs2.getString("ACT_COUNT"));
            }
            rs2.close();
            psta.close();
            if (batchCount < Integer.parseInt(count)) {
                core.setV_errMsg("管号队列材料合格支数不足,请重新输入离线支数！");
                return core;
            }
            String inListDoc = querySendSqlDoc(connection, "800708", "LX",plinCode);// 入库单号
            String A = querySendSql(connection, inListDoc);
            int g = Integer.parseInt(A.substring(A.length() - 4, A.length()));

            String storageAtte = "";
            String storageAtteName = "";
            String storageType = "";
            String storageTypeName = "";
            String managNo = "";
            String managName = "";
            String depNo = "";
            String depName = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.queryStorageType");
            psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, storageNo);
            rs = psta.executeQuery();
            if (rs.next()) {
                storageAtte = rs.getString("STORAGE_ATTR");
                storageAtteName = rs.getString("STORAGE_ATTR_NAME");
                storageType = rs.getString("STORAGE_TYPE_NO");
                storageTypeName = rs.getString("STORAGE_TYPE_NAME");
                managNo = rs.getString("MANAGEMENT_NO");
                managName = rs.getString("MANAGEMENT_NAME");
                depNo = rs.getString("DEPARTMENT_CODE");
                depName = rs.getString("DEPARTMENT_DESC");
            }
            rs.close();
            psta.close();
            String judge = "";
            String batch = "";
            String procode = "";
            String proname = "";
            String stecode = "";
            String stename = "";
            String gracode = "";
            String graname = "";
            String modecode = "";
            String modedesc = "";
            String stdcode = "";
            String stdname = "";
            String stdstyle = "";
            String stdstyledesc = "";
            String actdimater = "";
            String actheight = "";
            String actlen = "";
            String actlenmin = "";
            String actlenmax = "";
            // 查询产线下工序的位置
				int cnum = 0;
				String sqlloading8 = CoreXmlSqlParsersFactory
						.getSql("FrmMchInOnlineStore.queryGxPosition");
				psta = connection.prepareStatement(sqlloading8);
				psta.setObject(1, pln.getPlineName());
				rs = psta.executeQuery();
				if (rs.next()) {
					if (rs.getString("CNUM") == "" || rs.getString("CNUM") == null) {
						cnum = 0;
					} else {
						cnum = Integer.parseInt(rs.getString("CNUM"));
					}
				}
				rs.close();
				psta.close();

            int countNum = 0;
            double weightNum = 0;
            for (PortMchBatchSampleResultEntity prot : matNo) {
                countNum += Integer.parseInt(prot.getActCount());
                weightNum += Double.parseDouble(prot.getActWeight());
                // 修改管号队列状态
                pastupdatePath.setObject(1, "1");//num
                pastupdatePath.setObject(2, 2 * cnum - 2);//num1
                pastupdatePath.setObject(3, "2");
                pastupdatePath.setObject(4, 2 * cnum);//num2
                pastupdatePath.setObject(5, "20");
                pastupdatePath.setObject(6, "10");
                pastupdatePath.setObject(7, slgx);
                pastupdatePath.setObject(8, heatPlanNo);
                pastupdatePath.setObject(9, prot.getMatNo());
                pastupdatePath.addBatch();

                // 新增位置表
                patButt.setObject(1, prot.getMatNo());
                patButt.setObject(2, prot.getJudgeStoveNo());
                patButt.setObject(3, prot.getBatchNo());
                patButt.setObject(4, prot.getGroupNo());
                patButt.setObject(5, storageNo);
                patButt.setObject(6, storageNo + "10101");
                patButt.setObject(7, "");
                patButt.setObject(8, "");
                patButt.setObject(9, storageAtte);
                patButt.setObject(10, storageAtteName);
                patButt.setObject(11, storageType);
                patButt.setObject(12, storageTypeName);
                patButt.setObject(13, managNo);
                patButt.setObject(14, managName);
                patButt.setObject(15, "");
                patButt.setObject(16, name);
                patButt.setObject(17, time);
                patButt.setObject(18, depNo);
                patButt.setObject(19, depName);
                patButt.addBatch();
                // 修改材料表状态
                patMatNo.setObject(1, "80150104");
                patMatNo.setObject(2, "11");
                patMatNo.setObject(3, prot.getMatNo());
                patMatNo.addBatch();
                List<MatZcMEntity> listMat = new ArrayList<MatZcMEntity>();
                listMat = EntityTool.getEntitysByRs(rs, MatZcMEntity.class);
                for(MatZcMEntity lvMat : listMat)
                {
                // 新增入库表数据
                patIn.setObject(1, inListDoc
                        + StringTool.formatDecimal(g, "0000"));
                patIn.setObject(2, inListDoc);
                patIn.setObject(3, "800708");
                patIn.setObject(4, "离线入库");
                patIn.setObject(5, "");
                patIn.setObject(6, prot.getMatNo());
                patIn.setObject(7, "");
                patIn.setObject(8, "");
                patIn.setObject(9, prot.getJudgeStoveNo());
                patIn.setObject(10, prot.getBatchNo());
                patIn.setObject(11, prot.getGroupNo());
                patIn.setObject(12, "");
                patIn.setObject(13, "");
                patIn.setObject(14, "");
                patIn.setObject(15, "");
                patIn.setObject(16, "");
                patIn.setObject(17, "");
                patIn.setObject(18, "");
                patIn.setObject(19, "");
                patIn.setObject(20, "");
                patIn.setObject(21, "");
                patIn.setObject(22, "");
                patIn.setObject(23, "");
                patIn.setObject(24, "");
                patIn.setObject(25, "");
                patIn.setObject(26, "");
                patIn.setObject(27, "");
                patIn.setObject(28, "");
                patIn.setObject(29, pln.getPlineCode());
                patIn.setObject(30, pln.getPlineName());
                patIn.setObject(31, prot.getActDimater());
                patIn.setObject(32, prot.getActHeight());
                patIn.setObject(33, prot.getActLen());
                patIn.setObject(34, prot.getActLenMin());
                patIn.setObject(35, prot.getActLenMax());
                patIn.setObject(36, prot.getActCount());
                patIn.setObject(37, prot.getActWeight());
                patIn.setObject(38, prot.getActTheoryWeight());
                patIn.setObject(39, "");// 组织
                patIn.setObject(40, "");
                patIn.setObject(41, storageNo);//
                patIn.setObject(42, storageNo + "10101");
                patIn.setObject(43, "");
                patIn.setObject(44, "");
                patIn.setObject(45, storageAtte);
                patIn.setObject(46, storageAtteName);
                patIn.setObject(47, storageType);
                patIn.setObject(48, storageTypeName);
                patIn.setObject(49, managNo);
                patIn.setObject(50, managName);
                patIn.setObject(51, time);
                patIn.setObject(52, bc);
                patIn.setObject(53, bz);
                patIn.setObject(54, time);
                patIn.setObject(55, bc);
                patIn.setObject(56, bz);
                patIn.setObject(57, "");
                patIn.setObject(58, name);
                patIn.setObject(59, time);
                patIn.setObject(60, lvMat.getOrdPk());// 合同pK
                patIn.setObject(61, lvMat.getOrdLnPk());
                patIn.setObject(62, pln.getOrdLnDlyPk());
                patIn.setObject(63, depNo);
                patIn.setObject(64, depName);
                patIn.setObject(65, pln.getOrderNo());// 合同号
                patIn.setObject(66, pln.getOrderSeq());
                patIn.setObject(67, pln.getDeliveryNo());
                patIn.setObject(68, "801401");
                patIn.setObject(69, "80150104");
                patIn.setObject(70, "");
                patIn.setObject(71, "");
                patIn.setObject(72, time);
                patIn.setObject(73, "");
                patIn.setObject(74, "");
                patIn.setObject(75, "");
                patIn.setObject(76, "");
                patIn.setObject(77, "");
                patIn.setObject(78, "");
                patIn.setObject(79, "");
                patIn.setObject(80, "");
                patIn.setObject(81, "1");
                patIn.addBatch();
                }
                g++;
                judge = prot.getJudgeStoveNo();
                batch = prot.getBatchNo();
                procode = prot.getProducCode();
                proname = prot.getProducName();
                stecode = prot.getSteelCode();
                stename = prot.getSteelName();
                gracode = prot.getGradeCode();
                graname = prot.getGradeName();
                modecode = prot.getModelCode();
                modedesc = prot.getModelDesc();
                stdcode = prot.getStdCode();
                stdname = prot.getStdName();
                stdstyle = prot.getStdStyle();
                stdstyledesc = prot.getStdStyleDesc();
                actdimater = prot.getActDimater();
                actheight = prot.getActHeight();
                actlen = prot.getActLen();
                actlenmin = prot.getActLenMin();
                actlenmax = prot.getActLenMax();
            }
            pastupdatePath.executeBatch();
            patButt.executeBatch();
            patIn.executeBatch();
            patMatNo.executeBatch();

            String ifMonitNo = "";
            if (pln.getIfMonitor().equals("是")) {
                ifMonitNo = "1";
            }
            else {
                ifMonitNo = "0";
            }
            String resultNo = "";
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.queryOffMaxRESULT");// 查询离线最大实绩编号
            psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, plinCode + slgx + "L" + matter1.format(dt));
            psta.setObject(2, matter.format(dt));
            psta.setObject(3, pln.getPlineCode());
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                resultNo = rs1.getString("RESULT_NO");
            }
            rs1.close();
            psta.close();
            int actCount = 0;
            double weghit = 0;
            // 获取材料号
            List<VrpMatZcMEntity> mat = new ArrayList<VrpMatZcMEntity>();
            mat = EntityTool.getEntitysByRs(rs, VrpMatZcMEntity.class);
            rs.close();
            psta.close();
            if (mat == null) {
            	core.setV_errMsg("该交库工序已经结庐，不允许此操作！");
                return core;
            }
            String belongCode = "";
            String belongName = "";
            for (VrpMatZcMEntity matNo1 : mat) {
                actCount += Integer.parseInt(matNo1.getActCount());
                weghit += Double.parseDouble(matNo1.getActWeight());
                belongCode = matNo1.getBelongCode();
                belongName = matNo1.getBelongName();
            }
            // 新增加工公共信息
            patsPlan.setObject(1, pln.getHeatPlanNo());
            patsPlan.setObject(2, resultNo);
            patsPlan.setObject(3, slgx);
            patsPlan.setObject(4, slgxname);
            patsPlan.setObject(5, "");// 品名代码
            patsPlan.setObject(6, "");// 品名
            patsPlan.setObject(7, "");// 钢种代码
            patsPlan.setObject(8, "");// 钢种
            patsPlan.setObject(9, "");// 扣型代码
            patsPlan.setObject(10, "");
            patsPlan.setObject(11, "");// 标准代码
            patsPlan.setObject(12, "");
            patsPlan.setObject(13, "");// 标准类别代码
            patsPlan.setObject(14, "");
            patsPlan.setObject(15, "");// 原料管规格代码
            patsPlan.setObject(16, "");
            patsPlan.setObject(17, "");// 产出规格代码
            patsPlan.setObject(18, "");
            patsPlan.setObject(19, "");// 产出外径
            patsPlan.setObject(20, "");// 产出壁厚
            patsPlan.setObject(21, "");// 产出长度
            patsPlan.setObject(22, "");// 产出长度下限
            patsPlan.setObject(23, "");// 产出长度上限
            if (matStart.equals("10")) {
                patsPlan.setObject(24, "0");
                patsPlan.setObject(25, "0");
                patsPlan.setObject(26, actCount);// 废品
                patsPlan.setObject(27, weghit);
            }
            else {
                patsPlan.setObject(24, actCount);
                patsPlan.setObject(25, weghit);
                patsPlan.setObject(26, "0");// 废品
                patsPlan.setObject(27, "0");
            }
            patsPlan.setObject(28, "");// 离线
            patsPlan.setObject(29, "");
            patsPlan.setObject(30, "");// 返线
            patsPlan.setObject(31, "");
            patsPlan.setObject(32, "");// 过磅重量
            patsPlan.setObject(33, inListDoc);// 入库单号
            patsPlan.setObject(34, systime);
            patsPlan.setObject(35, name);
            patsPlan.setObject(36, bc);
            patsPlan.setObject(37, bz);
            patsPlan.setObject(38, systime);
            patsPlan.setObject(39, "");
            patsPlan.setObject(40, belongCode);
            patsPlan.setObject(41, belongName);
            patsPlan.addBatch();

            List<MatZcMEntity> listMat = new ArrayList<MatZcMEntity>();
            String sqlMatNo = CoreXmlSqlParsersFactory
                    .getSql("FrmThreadingResult.queryMatZc");// 查询新增物料信息
            psta = connection.prepareStatement(sqlMatNo);
            psta.setObject(1, pln.getJudgeStoveNo());
            psta.setObject(2, pln.getBatchNo());
            psta.setObject(3, count + 1);
            rs = psta.executeQuery();
            listMat = EntityTool.getEntitysByRs(rs, MatZcMEntity.class);
            rs.close();
            psta.close();
            for (MatZcMEntity lvMat : listMat) {
            
         // 新增离线实绩
            patAdd.setObject(1, resultNo);
            patAdd.setObject(2, pln.getPlineCode());
            patAdd.setObject(3, pln.getPlineName());
            patAdd.setObject(4, slgx);
            patAdd.setObject(5, slgxname);
            patAdd.setObject(6, heatPlanNo);           
            patAdd.setObject(7, pln.getZyBatchId());         
            patAdd.setObject(8, pln.getProPlanId());
            patAdd.setObject(9, pln.getGxPlanNo());
            patAdd.setObject(10, judge);
            patAdd.setObject(11, batch);
            patAdd.setObject(13, lvMat.getProduccode());
            patAdd.setObject(14, lvMat.getProducname());
            patAdd.setObject(15, lvMat.getSteelcode());
            patAdd.setObject(16, lvMat.getSteelname());
            patAdd.setObject(17, lvMat.getGradecode());
            patAdd.setObject(18, lvMat.getGradename());
            patAdd.setObject(19, lvMat.getModelCode());
            patAdd.setObject(20, lvMat.getModelDesc());
            patAdd.setObject(21, lvMat.getStdCode());
            patAdd.setObject(22, lvMat.getStdName());
            patAdd.setObject(23, lvMat.getStdStyle());
            patAdd.setObject(24, lvMat.getStdStyleDesc());
            patAdd.setObject(25, actdimater);
            patAdd.setObject(26, actheight);
            patAdd.setObject(27, actlen);
            patAdd.setObject(28, actlenmin);
            patAdd.setObject(29, actlenmax);
            patAdd.setObject(30, pln.getOrdLnDlyPk());
            patAdd.setObject(31, pln.getOrderNo());
            patAdd.setObject(32, pln.getOrderSeq());
            patAdd.setObject(33, pln.getDeliveryNo());
            patAdd.setObject(34, countNum);
            patAdd.setObject(35, weightNum);
            patAdd.setObject(36, name);
            patAdd.setObject(37, bc);
            patAdd.setObject(38, bz);
            patAdd.setObject(39, time);
            }
         // 新增离线从表
            for (int i = 0; i < list1.size(); i++) {
                String resultsqe = "";
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("FrmCoupMakeupResult.querymaxsqe");// 查询从表最大序号 
                psta = connection.prepareStatement(sqlloading);
                psta.setObject(1, matter1.format(now));
                psta.setObject(2, heatPlanNo);
                psta.setObject(3, plinCode);
                ResultSet rs3 = psta.executeQuery();
                if (rs3.next()) {
                    resultsqe = rs3.getString("RESULT_SQE");
                }
            
                rs3.close();
                psta.close();
                MchOfflineResultDentity resultD = list1.get(i);
                patAddD.setObject(1, resultNo);
                patAddD.setObject(2, resultsqe);
                patAddD.setObject(3, heatPlanNo);
                patAddD.setObject(4, plinCode);
                patAddD.setObject(5, pln.getPlineName());
                patAddD.setObject(6, count);	          
                patAddD.setObject(7, resultD.getGowhereCode());
                patAddD.setObject(8, resultD.getGowhereName());
                patAddD.setObject(9, time);
                patAddD.setObject(10, slgx);
                patAddD.setObject(11, slgxname);
                patAddD.addBatch();
                patAddD.executeBatch();
            }
            patAdd.addBatch();
            patAdd.executeBatch();
            patsPlan.executeBatch();
            core.setV_errMsg("离线成功！");
            core.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            core.setV_errMsg(e.getMessage());
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return core;
    }


    /**
     * 每支材料对应的入库单号
     * @param conn c
     * @param strlist 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String querySendSqlDoc(Connection conn, String strlist, String memo,
            String plineCode) throws Exception {
        String seq = "";
        PreparedStatement psta = null;
        Date dt = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat matter2 = new SimpleDateFormat("yyMMdd");
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("FrmMchInOnlineStore.getInListDoc");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, memo + plineCode);
        psta.setString(2, matter2.format(dt));
        psta.setString(3, matter1.format(dt));
        psta.setString(4, strlist);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            seq = rs.getString("INSTOCK_DOC");
        }
        rs.close();
        psta.close();
        return seq;
    }

    /**
     * 每支材料对应的入库流水号
     * @param conn c
     * @param strlist 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String querySendSql(Connection conn, String strlist)
            throws Exception {
        String seq = "";
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("FrmMchInOnlineStore.getInListDoc1");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strlist);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            seq = rs.getString("INSTOCK_SQE");
        }
        rs.close();
        psta.close();
        return seq;
    }

}
