package com.steering.mes.mcp.heatTreatment;

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 java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;

public class FrmHttInOnlineStore extends DBCommon {
    /**
     * 查询投入产出
     * @param list
     * @param startTim
     * @param endTim
     * @return
     */
    public CoreReturnObject doQuerySingleJugStove(String heatPlanNo) {

        String sql = "";
        sql = CoreXmlSqlParsersFactory
                .getSql("FrmHttInOnlineStore.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(HttPlan plan,
            String plinCode, String start, String end, String vluae) {
       String sql = "";
       sql = CoreXmlSqlParsersFactory
               .getSql("FrmHttInOnlineStore.doQuerymch");

       if (!plan.getHeatPlanNo().equals("")) {
           sql += " AND T1.HEAT_PLAN_NO || '&' LIKE '%' || '" + plan.getHeatPlanNo()
                   + "' || '%'";
       }
       if (!plan.getJudgeStoveNo().equals("")) {
           sql += " AND T1.JUDGE_STOVE_NO || '&' LIKE '%' || '" + plan.getJudgeStoveNo()
                   + "' || '%'";
       }
       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, String groupNo) {
        return this.getDataBySqlID("FrmHttInOnlineStore.doQuerySingle",
                new Object[] { heatNo, judge, batch, groupNo, heatNo, judge,
                        batch, groupNo });
    }
    /**
     * 查询相同炉计划ID下交库实绩状态
     * @param heatNo
     * @param judge
     * @param batch
     * @return
     */

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

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

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

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

    /**
     * 查询交库信息
     * @param list
     * @param startTim
     * @param endTim
     * @return
     */
    public CoreReturnObject doQueryLibrary(String plineCode, String start,
            String end, String jugeNo) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmHttInOnlineStore.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 (!plineCode.equals("")) {
            sql += "  AND T.PLINE_CODE ='" + plineCode + "'";
        }
        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.RPO_TIME, T.PRO_BC, T.PRO_BZ, T.INSTOCK_TIME, T.IN_BC, T.IN_BZ, T.HAND_FLAG, T.MEMO, "
                + "T.VALIDFLAG, T.CREATE_NAME, T.CREATE_TIME, T.UPDATE_NAME, T.UPDATE_TIME, T.ORD_PK, "
                + "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.IN_TIME_F, "
                + "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 HttPlan getSendDBKPlan(Connection con, String heatNo)
            throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmHttInOnlineStore.doQuery");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ResultSet rs = ps.executeQuery();
        List<HttPlan> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                HttPlan.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        }
        else {
            for (HttPlan 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("FrmHttInOnlineStore.UpdatePortBatch");// 修改管号队列重量
            PreparedStatement updatePortBatchPsta = con
                    .prepareStatement(updatePortBatch);
            String insertComInfoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.AddPlnInfo");// 新增热处理入库表
            PreparedStatement insertComInfoPsta = con
                    .prepareStatement(insertComInfoSql);
            
            String insertComInfoSqlXs = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStoreXs.AddPlnInfo");// 新增热处理销售入库表
            PreparedStatement insertComInfoPstaXs = con
                    .prepareStatement(insertComInfoSqlXs);
            
            String strMatM = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.AddMatM");// 末工序修改材料表状态
            PreparedStatement pstaMatM = con.prepareStatement(strMatM);
            
            String strMatMXs = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStoreXs.AddMatM");// 末工序修改材料表状态
            PreparedStatement pstaMatMXs = con.prepareStatement(strMatMXs);
            
            String addButt = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.AddYdmButt");// 新增库存位置信息
            PreparedStatement patButt = con.prepareStatement(addButt);
            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.AddComInfoResult");// 新增热处理公共信息
            PreparedStatement patsPlan = con.prepareStatement(addPlnInfo);
            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.UpdatePath1");// 修改队列表工艺路径,虚拟入库标志状态
            PreparedStatement pastupdatePath = con.prepareStatement(updatePath);

            String planJgSql = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.UpdatePlanResult1");// 修改计划表
            PreparedStatement planJgPsta = con.prepareStatement(planJgSql);
            
            String planJgSqlC = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.UpdatePlanResultC1");// 修改计划表从表
            PreparedStatement planJgPstaC = con.prepareStatement(planJgSqlC);
            // 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 lutime = "";
            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 banc = list.get(24);
            String banz = list.get(25);
            String name = 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";
            // }
            // }

            String planStatus = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.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("30")) {
                cor.setV_errMsg("该工单计划已生产完成！");
                return cor;
            }
            if (planStatus.equals("40")) {
                cor.setV_errMsg("该工单计划已关闭！");
                return cor;
            }
            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.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("FrmHttInOnlineStore.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 storageAtte = "";
            String storageAtteName = "";
            String storageType = "";
            String storageTypeName = "";
            String managNo = "";
            String managName = "";
            String depNo = "";
            String depName = "";
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.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("FrmHttInOnlineStore.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();
            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("FrmHttInOnlineStore.queryMaxMatNo");// 查询管号队列对应材料
            psta = con.prepareStatement(sqlloading);
            psta.setObject(1, judNo);
            psta.setObject(2, zgNo);
            psta.setObject(3, list.get(22));
            psta.setObject(4, matStart);
            psta.setObject(5, isSamp);
            psta.setObject(6, hertNo);
            psta.setObject(7, Integer.parseInt(sjnum) + 1);
            rs = psta.executeQuery();
            mat = EntityTool.getEntitysByRs(rs, VrpMatZcMEntity.class);
            rs.close();
            psta.close();
            if (mat == null) {
                cor.setV_errMsg("该交库工序已经结庐，不允许此操作！");
                return cor;
            }
            // 获取热处理计划表实体类
            HttPlan 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;
            String belongCode = "";
            String belongName = "";
            for (VrpMatZcMEntity matNo : mat) {
                actCount += Integer.parseInt(matNo.getActCount());
                weghit += Double.parseDouble(matNo.getActWeight());
                belongCode = matNo.getBelongCode();
                belongName = matNo.getBelongName();
                if (pln.getIsendgx().equals("1")) {// 判定是否末工序1是 0否
                    // 末工序修改材料表
                    pstaMatM.setObject(1, "801402");
                    pstaMatM.setObject(2, "80150201");
                    pstaMatMXs.setObject(1, "801402");
                    pstaMatMXs.setObject(2, "80150201");
                }
                else {
                    pstaMatM.setObject(1, "801401");
                    pstaMatM.setObject(2, "80150105");
                    pstaMatMXs.setObject(1, "801401");
                    pstaMatMXs.setObject(2, "80150105");
                }
                pstaMatM.setObject(3, "F");
                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");// [热处理工序]公差判定结果代码
                
                pstaMatMXs.setObject(3, "F");
                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")) {
                    pstaMatM.setObject(12, "00");// 热处理交库状态
                    pstaMatMXs.setObject(12, "00");// 热处理交库状态

                }
                else {
                    pstaMatM.setObject(12, "22");
                    pstaMatMXs.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, pln.getOutwlId());
                pstaMatM.setObject(24, pln.getOutwlDesc());
                pstaMatM.setObject(25, matNo.getMaterialNo());
                pstaMatM.setObject(26, matNo.getMaterialName());
                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, matNo.getActWeight());
                pstaMatM.setObject(40, matNo.getHttFlagStoveNoZg());
                pstaMatM.setObject(41, matNo.getMatNo());
                pstaMatM.addBatch();
                
                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, pln.getOutwlId());
                pstaMatMXs.setObject(24, pln.getOutwlDesc());
                pstaMatMXs.setObject(25, matNo.getMaterialNo());
                pstaMatMXs.setObject(26, matNo.getMaterialName());
                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, matNo.getActWeight());
                pstaMatMXs.setObject(40, matNo.getHttFlagStoveNoZg());
                pstaMatMXs.setObject(41, matNo.getMatNo());
                pstaMatMXs.addBatch();

                // 新增位置表
                patButt.setObject(1, matNo.getMatNo());
                patButt.setObject(2, matNo.getJudgeStoveNo());
                patButt.setObject(3, matNo.getBatchNo());
                patButt.setObject(4, matNo.getBatchGroudNo());
                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, pln.getBatchGroudNo());
                insertComInfoPsta.setObject(12, pln.getOutwlId());
                insertComInfoPsta.setObject(13, pln.getOutwlDesc());
                insertComInfoPsta.setObject(14, matNo.getProduccode());
                insertComInfoPsta.setObject(15, matNo.getProducname());
                insertComInfoPsta.setObject(16, matNo.getStdCode());
                insertComInfoPsta.setObject(17, matNo.getStdName());
                insertComInfoPsta.setObject(18, pln.getGradecode());
                insertComInfoPsta.setObject(19, pln.getGradename());
                insertComInfoPsta.setObject(20, matNo.getSteelcode());
                insertComInfoPsta.setObject(21, matNo.getSteelname());
                insertComInfoPsta.setObject(22, matNo.getStdStyle());
                insertComInfoPsta.setObject(23, matNo.getStdStyleDesc());
                insertComInfoPsta.setObject(24, matNo.getSpecCode());
                insertComInfoPsta.setObject(25, matNo.getSpecName());
                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, banc);
                insertComInfoPsta.setObject(56, banz);
                insertComInfoPsta.setObject(57, "");
                insertComInfoPsta.setObject(58, name);
                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());
                
                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, pln.getBatchGroudNo());
                insertComInfoPstaXs.setObject(12, pln.getOutwlId());
                insertComInfoPstaXs.setObject(13, pln.getOutwlDesc());
                insertComInfoPstaXs.setObject(14, matNo.getProduccode());
                insertComInfoPstaXs.setObject(15, matNo.getProducname());
                insertComInfoPstaXs.setObject(16, matNo.getStdCode());
                insertComInfoPstaXs.setObject(17, matNo.getStdName());
                insertComInfoPstaXs.setObject(18, pln.getGradecode());
                insertComInfoPstaXs.setObject(19, pln.getGradename());
                insertComInfoPstaXs.setObject(20, matNo.getSteelcode());
                insertComInfoPstaXs.setObject(21, matNo.getSteelname());
                insertComInfoPstaXs.setObject(22, matNo.getStdStyle());
                insertComInfoPstaXs.setObject(23, matNo.getStdStyleDesc());
                insertComInfoPstaXs.setObject(24, matNo.getSpecCode());
                insertComInfoPstaXs.setObject(25, matNo.getSpecName());
                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, banc);
                insertComInfoPstaXs.setObject(56, banz);
                insertComInfoPstaXs.setObject(57, "");
                insertComInfoPstaXs.setObject(58, name);
                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());
                
                if (pln.getIsendgx().equals("1")) {
                    insertComInfoPsta.setObject(68, "801402");
                    insertComInfoPsta.setObject(69, "80150201");
                    insertComInfoPstaXs.setObject(68, "801402");
                    insertComInfoPstaXs.setObject(69, "80150201");
                }
                else {
                    insertComInfoPsta.setObject(68, "801401");
                    insertComInfoPsta.setObject(69, "80150101");
                    insertComInfoPstaXs.setObject(68, "801401");
                    insertComInfoPstaXs.setObject(69, "80150101");
                }
                insertComInfoPsta.setObject(70, matNo.getJudgeStdName());
                insertComInfoPsta.setObject(71, matNo.getJudgeStdCode());
                insertComInfoPsta.setObject(72, systime);
                insertComInfoPsta.setObject(73, matNo.getLenNo());
                insertComInfoPsta.setObject(74, matNo.getLenDesc());
                insertComInfoPsta.setObject(75, matNo.getLenUnit());
                insertComInfoPsta.setObject(76, "");
                insertComInfoPsta.setObject(77, matNo.getSoureCode());
                insertComInfoPsta.setObject(78, matNo.getSoureName());
                insertComInfoPsta.setObject(79, matNo.getMatOriginCode());
                insertComInfoPsta.setObject(80, matNo.getMatOriginName());
                insertComInfoPsta.setObject(81, "1");
                insertComInfoPstaXs.setObject(70, matNo.getJudgeStdName());
                insertComInfoPstaXs.setObject(71, matNo.getJudgeStdCode());
                insertComInfoPstaXs.setObject(72, systime);
                insertComInfoPstaXs.setObject(73, matNo.getLenNo());
                insertComInfoPstaXs.setObject(74, matNo.getLenDesc());
                insertComInfoPstaXs.setObject(75, matNo.getLenUnit());
                insertComInfoPstaXs.setObject(76, "");
                insertComInfoPstaXs.setObject(77, matNo.getSoureCode());
                insertComInfoPstaXs.setObject(78, matNo.getSoureName());
                insertComInfoPstaXs.setObject(79, matNo.getMatOriginCode());
                insertComInfoPstaXs.setObject(80, matNo.getMatOriginName());
                insertComInfoPstaXs.setObject(81, "1");
                if (matStart.equals("00")) {
                    insertComInfoPsta.setObject(82, "00");// 交库状态
                    insertComInfoPstaXs.setObject(82, "00");// 交库状态
                }
                else {
                    insertComInfoPsta.setObject(82, "22");
                    insertComInfoPstaXs.setObject(82, "22");
                }
                insertComInfoPsta.addBatch();
                g++;
                // 修改工艺路径
                pastupdatePath.setObject(1, "1");
                pastupdatePath.setObject(2, "20");
                pastupdatePath.setObject(3, "1");
                pastupdatePath.setObject(4, "22");
                pastupdatePath.setObject(5, "1");
                pastupdatePath.setObject(6, matNo.getMatNo());
                pastupdatePath.setObject(7, hertNo);
                pastupdatePath.addBatch();

            }
            pstaMatM.executeBatch();
            pstaMatMXs.executeBatch();
            patButt.executeBatch();
            insertComInfoPsta.executeBatch();
            insertComInfoPstaXs.executeBatch();

            pastupdatePath.executeBatch();

            String resultNo = "";
            String sqlloading2 = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.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, "");// 产出长度上限
            if (matStart.equals("10")) {
                patsPlan.setObject(22, "0");
                patsPlan.setObject(23, "0");
                patsPlan.setObject(24, actCount);// 废品
                patsPlan.setObject(25, weghit);
            }
            else {
                patsPlan.setObject(22, actCount);
                patsPlan.setObject(23, weghit);
                patsPlan.setObject(24, "0");// 废品
                patsPlan.setObject(25, "0");
            }
            patsPlan.setObject(26, "");// 离线
            patsPlan.setObject(27, "");
            patsPlan.setObject(28, "");// 返线
            patsPlan.setObject(29, "");
            patsPlan.setObject(30, "");// 过磅重量
            patsPlan.setObject(31, inListDoc);// 入库单号
            patsPlan.setObject(32, systime);
            patsPlan.setObject(33, user);
            patsPlan.setObject(34, bc);
            patsPlan.setObject(35, bz);
            patsPlan.setObject(36, systime);
            patsPlan.setObject(37, "");
            patsPlan.setObject(38, belongCode);
            patsPlan.setObject(39, belongName);
            patsPlan.addBatch();
            patsPlan.executeBatch();
            // 修改计划表
            if (matStart.equals("00")) {
            	planJgPsta.setObject(1, hertNo);
                planJgPsta.addBatch();
                planJgPsta.executeBatch();
                planJgPstaC.setObject(1, weghit);
                planJgPstaC.setObject(2, actCount);
                planJgPstaC.setObject(3, hertNo);
                planJgPstaC.addBatch();
                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 result 删除交库实绩
     * @return
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject deleteLibraryResult(ArrayList<Object> pram,
            String SlGx, String jud, String batch, String plineCode) {
        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("FrmHttInOnlineStore.DeleteComInfoResult");// 删除comInfo表
            PreparedStatement comInfoPsta = con.prepareStatement(comInfoSql);
            String planJgSql = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.UpdatePlanResult");// 修改计划表
            PreparedStatement planJgPsta = con.prepareStatement(planJgSql);
            String planJgSqlC = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.UpdatePlanResultC");// 修改计划从表
            PreparedStatement planJgPstaC = con.prepareStatement(planJgSqlC);
            String strMatM = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.AddMatM");// 修改热处理材料表
            PreparedStatement pstaMatM = con.prepareStatement(strMatM);
            String strMatButters = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.DeleteMatButters");// 删除位置表
            PreparedStatement pstaMatButters = con
                    .prepareStatement(strMatButters);
            String deleteLin = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.DeleteLinResult");// 删除入库实绩表
            PreparedStatement pstadeleteLin = con.prepareStatement(deleteLin);
            String deleteLinXs = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStoreXs.DeleteLinResult");// 删除入库实绩表
            PreparedStatement pstadeleteLinXs = con.prepareStatement(deleteLinXs);
            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.UpdatePath1");// 修改队列表工艺路径,虚拟入库标志
            PreparedStatement pastupdatePath = con.prepareStatement(updatePath);
            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);

                String inStatus1 = "";
                String belongCode = "";
                String belongName = "";
                String sqlloading1 = CoreXmlSqlParsersFactory
                        .getSql("FrmHttInOnlineStore.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 sqlloading = CoreXmlSqlParsersFactory
                        .getSql("FrmHttInOnlineStore.queryPlanJg");// 查询热处理计划表状态
                PreparedStatement psta = con.prepareStatement(sqlloading);
                psta.setObject(1, hertNo);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    planStatus = Integer.parseInt(rs.getString("PLANSTATUS"));
                }
                rs.close();
                psta.close();
                if (planStatus > '2') {
                    cor.setV_errMsg("该工单计划已生产完成或已关闭！");
                    return cor;
                }
                //获取热处理实体类
                HttPlan pln = getSendDBKPlan(con, hertNo);
                // 获取材料号
                List<VrpMatZcMEntity> mat = new ArrayList<VrpMatZcMEntity>();
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("FrmHttInOnlineStore.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");                              
                    pstaMatM.setObject(3, "F");
                    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, "");
                    pstaMatM.setObject(24, "");
                    pstaMatM.setObject(25, matNo.getInputMaterialNo());
                    pstaMatM.setObject(26, matNo.getInputMaterialName());
                    pstaMatM.setObject(27, "");// 投料物料来源
                    pstaMatM.setObject(28, "F");// 下道工序Id
                    pstaMatM.setObject(29, "热处理");// 下道工序
                    pstaMatM.setObject(30, pln.getPlineCode());
                    pstaMatM.setObject(31, pln.getPlineName());
                    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, matNo.getActWeight());
                    pstaMatM.setObject(40, "");
                    pstaMatM.setObject(41, matNo.getMatNo());
                    pstaMatM.addBatch();

                    // 删除位置表
                    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();

                  
                    // 修改工艺路径
                    pastupdatePath.setObject(1, "1");
                    pastupdatePath.setObject(2, "20");
                    pastupdatePath.setObject(3, "0");
                    pastupdatePath.setObject(4, "22");
                    pastupdatePath.setObject(5, "0");
                    pastupdatePath.setObject(6, matNo.getMatNo());
                    pastupdatePath.setObject(7, hertNo);
                    pastupdatePath.addBatch();
                }
                pstaMatM.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, "80");//“09”
                    planJgPsta.setObject(2, hertNo);
                    planJgPsta.addBatch();
                    
                    planJgPstaC.setObject(1, weight);
                    planJgPstaC.setObject(2, libCount);
                    planJgPstaC.setObject(3, hertNo);
                    planJgPstaC.addBatch();
                }
            }
            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("FrmHttInOnlineStore.updateif");// 修改管号队列“是否入库”字段
            PreparedStatement pstaMatButters = connection
                    .prepareStatement(strMatButters);
            String updatePlanSql = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.doBeside");// 修改公共信息表的状态为生产完成
            PreparedStatement updatePlanPsta = connection
                    .prepareStatement(updatePlanSql);
            String updatepln = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.updatePln");// 修改热处理计划表状态为生产完成
            PreparedStatement updateplnPsta = connection
                    .prepareStatement(updatepln);
            String updateplnId = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.updatePlnId");// 修改镦拔扩订单表状态为生产完成
            PreparedStatement updateplnPstaId = connection
                    .prepareStatement(updateplnId);
            String updateplnSeq = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.updatePlnGxProSeq");// 修改镦拔扩订单表下一顺序号状态为生产中
            PreparedStatement updateplnPstaSeq = connection
                    .prepareStatement(updateplnSeq);

            String inStatus = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.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, "90");
            updateplnPsta.setObject(3, heraNo);
            updateplnPsta.addBatch();

            updateplnPsta.executeBatch();
            pstaMatButters.executeBatch();
            updatePlanPsta.executeBatch();
//            int countReady = 0;
//            sqlloading = CoreXmlSqlParsersFactory
//                    .getSql("FrmHttInOnlineStore.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("FrmHttInOnlineStore.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) {
                updateplnPstaId.setObject(1, "2");
                updateplnPstaId.setObject(2, proPlanId);
                updateplnPstaId.setObject(3, gxPlanNo);
                updateplnPstaId.addBatch();
                updateplnPstaId.executeBatch();

                int gxProSeq = 0;
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("FrmHttInOnlineStore.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, "F");
                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("FrmHttInOnlineStore.updateif");// 修改管号队列“是否入库”字段
            PreparedStatement pstaMatButters = connection
                    .prepareStatement(strMatButters);
            String updatePlanSql = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.doBeside");// 修改公共信息表的状态为生产完成
            PreparedStatement updatePlanPsta = connection
                    .prepareStatement(updatePlanSql);
            String updatepln = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.updatePln");// 修改热处理计划表状态为生产完成
            PreparedStatement updateplnPsta = connection
                    .prepareStatement(updatepln);
            String updateplnId = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.deletePlnId");// 修改镦拔扩订单表状态为生产中
            PreparedStatement updateplnPstaId = connection
                    .prepareStatement(updateplnId);
            String updateplnSeq = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.updatePlnGxProSeq");// 修改镦拔扩订单表下一顺序号状态为计划
            PreparedStatement updateplnPstaSeq = connection
                    .prepareStatement(updateplnSeq);

            String heraNo = list.get(0);
            String judNo = list.get(1);
            String batchNo = list.get(2);
            String inStatus = "";
            String proPlanId = list.get(3);
            String gxPlanNo = list.get(4);
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.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("FrmHttInOnlineStore.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, "80");
            updateplnPsta.setObject(3, heraNo);
            updateplnPsta.addBatch();
            // 修改热处理订单表
            updateplnPstaId.setObject(1, "1");
            updateplnPstaId.setObject(2, proPlanId);
            updateplnPstaId.setObject(3, gxPlanNo);
            updateplnPstaId.addBatch();
            
            pstaMatButters.executeBatch();
            updateplnPsta.executeBatch();
            updatePlanPsta.executeBatch();
            updateplnPstaId.executeBatch();
            int gxProSeq = 0;
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.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 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("FrmHttInOnlineStore.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("FrmHttInOnlineStore.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;
    }
    
    
    /**
     * 离线
     * @param load
     * @return
     */
    public CoreReturnObject offLineExpandResult(ArrayList<HttOfflineResultDentity> list1,
            ArrayList<String> list, String plinCode, String storageNo,String groudno) {
        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("AppearanceService.AddOffLine");// 新增离线实绩
            PreparedStatement patAdd = connection.prepareStatement(addOff);
            String addOffD = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.AddOffLineD");// 新增离线实绩从表
            PreparedStatement patAddD = connection.prepareStatement(addOffD);
            String addButt = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.AddYdmButt");// 新增库存位置信息
            PreparedStatement patButt = connection.prepareStatement(addButt);
            String addIn = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.AddYdmInList");// 新增入库信息
            PreparedStatement patIn = connection.prepareStatement(addIn);
            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("FrmHttInOnlineStore.AddComInfoResult");// 新增公共信息
            PreparedStatement patsPlan = connection
                    .prepareStatement(addPlnInfo);
            String updateMat = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.UpdateMatNo");// 修改材料状态
            PreparedStatement patMatNo = connection.prepareStatement(updateMat);

            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.UpdatePathPortVrp");// 修改队列表工艺路径,材料，工序状态
            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);

            int num = 0;
            int num1 = 0;
            int num2 = 0;
                if (slgx.equals("600202")) {
                    num = 1;
                    num1 = 2;
                    num2 = 4;
                }
                else if (slgx.equals("600203")) {
                    num = 1;
                    num1 = 4;
                    num2 = 6;
                }
                else if (slgx.equals("600204")) {
                    num = 1;
                    num1 = 6;
                    num2 = 8;
                }
                else if (slgx.equals("600205")) {
                    num = 1;
                    num1 = 8;
                    num2 = 10;
                }
                else if (slgx.equals("600206")) {
                    num = 1;
                    num1 = 10;
                    num2 = 12;
                }
                else if (slgx.equals("600207")) {
                    num = 1;
                    num1 = 12;
                    num2 = 14;
                }
                else if (slgx.equals("600208")) {
                    num = 1;
                    num1 = 16;
                    num2 = 18;
                }
                else if (slgx.equals("600209")) {
                    num = 1;
                    num1 = 18;
                    num2 = 20;
                }
                else if (slgx.equals("600210")) {
                    num = 1;
                    num1 = 20;
                    num2 = 22;
                }
                else if (slgx.equals("600211")) {
                    num = 1;
                    num1 = 22;
                    num2 = 24;
                }
         
            // 获取墩拔扩计划实体类
                PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(connection,
                    heatPlanNo);
            if (pln == null)
                return core;
            // if (!pln.getPlanstatus().equals("2")) {
            // core.setV_errMsg("该计划不是生产中的，请确认是否生产完成或未上料！");
            // return core;
            // }
            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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<PortHttBatchSampleResultEntity> matNo = new ArrayList<PortHttBatchSampleResultEntity>();
            String sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.queryPortVrpHg");// 查询管号队列里合格的材料号
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, heatPlanNo);
            psta.setObject(2, Integer.parseInt(count) + 1);
            ResultSet rs2 = psta.executeQuery();
            matNo = EntityTool.getEntitysByRs(rs2,
            		PortHttBatchSampleResultEntity.class);
            rs2.close();
            psta.close();
            if (matNo == null) {
                core.setV_errMsg("管号队列全为样管，不能离线！");
                return core;
            }
            int batchCount = 0;
            sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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);// 入库单号querySendSqlDoc
            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("AppearanceService.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 countNum = 0;
            double weightNum = 0;
            for (PortHttBatchSampleResultEntity prot : matNo) {
                countNum += Integer.parseInt(prot.getActCount());
                weightNum += Double.parseDouble(prot.getActWeight());
                // 修改管号队列状态
                pastupdatePath.setObject(1, num);
                pastupdatePath.setObject(2, num1);
                pastupdatePath.setObject(3, "2");
                pastupdatePath.setObject(4, 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);
                rs.close();
                patMatNo.close();

				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, pln.getGradecode());
                patIn.setObject(19, pln.getGradename());
                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, pln.getOrdLnDlyPk().substring(0,
//                        pln.getOrdLnDlyPk().length() - 6));// 合同pK
//                patIn.setObject(61, pln.getOrdLnDlyPk().substring(0,
//                        pln.getOrdLnDlyPk().length() - 3));
                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();
                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("AppearanceService.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, "");// 产出长度上限
            if (matStart.equals("10")) {
                patsPlan.setObject(22, "0");
                patsPlan.setObject(23, "0");
                patsPlan.setObject(24, actCount);// 废品
                patsPlan.setObject(25, weghit);
            }
            else {
                patsPlan.setObject(22, actCount);
                patsPlan.setObject(23, weghit);
                patsPlan.setObject(24, "0");// 废品
                patsPlan.setObject(25, "0");
            }
            patsPlan.setObject(26, "");// 离线
            patsPlan.setObject(27, "");
            patsPlan.setObject(28, "");// 返线
            patsPlan.setObject(29, "");
            patsPlan.setObject(30, "");// 过磅重量
            patsPlan.setObject(31, inListDoc);// 入库单号
            patsPlan.setObject(32, systime);
            patsPlan.setObject(33, name);
            patsPlan.setObject(34, bc);
            patsPlan.setObject(35, bz);
            patsPlan.setObject(36, systime);
            patsPlan.setObject(37, "");
            patsPlan.setObject(38, belongCode);
            patsPlan.setObject(39, belongName);
            patsPlan.addBatch();
            patsPlan.executeBatch();
            List<MatZcMEntity> listMat = new ArrayList<MatZcMEntity>();
            String sqlMatNo = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.queryMatZc");// 查询新增物料信息
            psta = connection.prepareStatement(sqlMatNo);
            psta.setObject(1, pln.getJudgeStoveNo());
            psta.setObject(2, pln.getBatchNo());
            psta.setObject(3, groudno);
            psta.setObject(4, 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.getIndexSeq());
            patAdd.setObject(9, pln.getProPlanId());
            patAdd.setObject(10, pln.getGxPlanNo());

            patAdd.setObject(11, judge);
            patAdd.setObject(12, batch);
            patAdd.setObject(13, groudno);
            patAdd.setObject(14, lvMat.getProduccode());
            patAdd.setObject(15, lvMat.getProducname());
            patAdd.setObject(16, lvMat.getSteelcode());
            patAdd.setObject(17, lvMat.getSteelname());
            patAdd.setObject(18, lvMat.getGradecode());
            patAdd.setObject(19, lvMat.getGradename());
            patAdd.setObject(20, lvMat.getModelCode());
            patAdd.setObject(21, lvMat.getModelDesc());
            patAdd.setObject(22, lvMat.getStdCode());
            patAdd.setObject(23, lvMat.getStdName());
            patAdd.setObject(24, lvMat.getStdStyle());
            patAdd.setObject(25, lvMat.getStdStyleDesc());
            patAdd.setObject(26, actdimater);
            patAdd.setObject(27, actheight);
            patAdd.setObject(28, actlen);
            patAdd.setObject(29, actlenmin);
            patAdd.setObject(30, actlenmax);
            patAdd.setObject(31, pln.getOrdLnDlyPk());
            patAdd.setObject(32, pln.getOrderNo());
            patAdd.setObject(33, pln.getOrderSeq());
            patAdd.setObject(34, pln.getDeliveryNo());
            patAdd.setObject(35, countNum);
            patAdd.setObject(36, weightNum);
            patAdd.setObject(37, name);
            patAdd.setObject(38, bc);
            patAdd.setObject(39, bz);
            patAdd.setObject(40, time);
            }
            // 新增离线从表
            for (int i = 0; i < list1.size(); i++) {
                String resultsqe = "";
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("AppearanceService.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();
                HttOfflineResultDentity 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.addBatch();
                patAddD.executeBatch();
            }
            
            patAdd.addBatch();
            patAdd.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;
    }


}
