package com.steering.pss.ydm.pipemanage;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

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

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.StringTool;
import com.steering.pss.ydm.entity.MatZcMInfoEntity1;
import com.steering.pss.ydm.pipeleavefactory.FrmPipeEntruck;

/**
 * @author TJG 2015-03-27
 */
public class FrmPipeMoveOut extends DBCommon {
    /**
     * 查询倒库实绩
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryOutPerfo(ArrayList<String> list, String[] arr) {
        String condition = CoreConverter.toSqlConditionString("T.STORAGE_NO",
                arr);
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveOut.queryOutPerfo");
        sql = sql.replaceAll("#CONDITION#", condition);
        if(!list.get(1).equals(""))
        {
            sql += "  AND t.LOCATION_NO = '" + list.get(1) + "' ";
        }
        if(!list.get(2).equals(""))
        {
            sql += " AND t.judge_stove_no LIKE '" + list.get(2) + "' || '%'";
        }
        if(!list.get(5).equals(""))
        {
			sql += " AND t.OUTSTOCK_TIME BETWEEN to_date('" + list.get(5)
					+ "', 'YYYY/MM/DD HH24:MI:SS')";
			sql += " AND to_date('" + list.get(7)
					+ "', 'YYYY/MM/DD HH24:MI:SS') ";
        }
        sql += " AND T.OUTSTOCK_TYPE_CODE = '" + list.get(8)+ "'";
        //sql += " AND t.VALIDFLAG = '1'";
        sql += " GROUP BY T.OUTSTOCK_DOC, 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.PLINE_NAME, T.ACT_DIMATER, "
                + "    T.ACT_HEIGHT, T.ACT_LEN_MIN, T.ACT_LEN_MAX, T.BELONG_NAME, T.PRO_BC,     "
                + "T.PRO_BZ, T.TAR_STORAGE_NO, T.TAR_LOCATION_NO, B.STORAGE_NAME,    "
                + " T.TAR_STORAGE_ATTR_NAME, T.TAR_STORAGE_TYPE_NAME, T.MANAGEMENT_NAME,   "
                + "  T.CREATE_NAME, T.TAR_REC_FLAG";
        //sql += " ORDER BY t.OUTSTOCK_DOC ASC";
        return this.getData(sql);
    }

    /**
     * 查询倒库实绩
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryOutPerfo1(ArrayList<String> list, String[] arr,String flag) {
        String condition = CoreConverter.toSqlConditionString("T.STORAGE_NO",
                arr);
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveOut.queryOutPerfo1");
        String condition1 = " AND S.BELONG_CODE NOT IN ('100101','100102','100103')";
        sql = sql.replaceAll("#CONDITION#", condition);
        if(flag.equals("0"))
        {
        	sql = sql.replace("#CONDITION1#", condition1);
        }else
        {
        	sql = sql.replace("#CONDITION1#", "");
        }
        if(!list.get(0).equals(""))
        {
        	sql += "  AND T.STORAGE_NO = '" + list.get(0) + "' ";
        }
        if(!list.get(1).equals(""))
        {
            sql += "  AND t.LOCATION_NO = '" + list.get(1) + "' ";
        }
        if(!list.get(2).equals(""))
        {
            sql += " AND t.judge_stove_no LIKE '" + list.get(2) + "' || '%'";
        }
        if(!list.get(5).equals(""))
        {
			sql += " AND t.OUTSTOCK_TIME BETWEEN to_date('" + list.get(5)
					+ "', 'YYYY/MM/DD HH24:MI:SS')";
			sql += " AND to_date('" + list.get(7)
					+ "', 'YYYY/MM/DD HH24:MI:SS') ";
        }
        sql += " AND T.OUTSTOCK_TYPE_CODE = '" + list.get(8)+ "'";
        //sql += " AND t.VALIDFLAG = '1'";
        sql += " GROUP BY T.OUTSTOCK_DOC, 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.PLINE_NAME, T.ACT_DIMATER, "
                + "    T.ACT_HEIGHT, T.ACT_LEN_MIN, T.ACT_LEN_MAX, T.BELONG_NAME, T.PRO_BC,     "
                + "T.PRO_BZ, T.TAR_STORAGE_NO, T.TAR_LOCATION_NO, B.STORAGE_NAME,    "
                + " T.TAR_STORAGE_ATTR_NAME, T.TAR_STORAGE_TYPE_NAME, T.MANAGEMENT_NAME,   "
                + "  T.CREATE_NAME, T.TAR_REC_FLAG";
        //sql += " ORDER BY t.OUTSTOCK_DOC ASC";
        return this.getData(sql);
    }
    
    
    /**
     * 库存实绩查询
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryInventory(ArrayList<String> list, String[] arr) {
        String condition = CoreConverter.toSqlConditionString("B.STORAGE_NO",
                arr);
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveOut.queryInventory");
        sql = sql.replaceAll("#CONDITION#", condition);
        sql = sql.replace("#CONDITION1#", "");
        if(!list.get(0).equals(""))
        {
        	sql += " and B.STORAGE_NO = '" + list.get(0) + "'";
        }
        if(!list.get(1).equals(""))
        {
            sql += " AND B.LOCATION_NO = '" + list.get(1) + "'";
        }
        if(!list.get(2).equals(""))
        {
        	sql += " AND T.judge_stove_no LIKE '" + list.get(2) + "' || '%'";
        }
        if(!list.get(5).equals(""))
        {
			sql += " AND T.Instock_Time BETWEEN  to_date('" + list.get(5)
					+ "', 'YYYY/MM/DD HH24:MI:SS')";
			sql += " AND to_date('" + list.get(7)
					+ "', 'YYYY/MM/DD HH24:MI:SS')";
        }
        
        sql += " AND T.INSTOCK_FLAG = '1'";
        sql += " group by T.JUDGE_STOVE_NO, T.BATCH_NO, T.BATCH_GROUD_NO, T.MEMO, T.PRODUCT_FLAG, T.MAT_STATUS,"
                + " T.PRODUCNAME, T.STEELNAME, T.SPEC_NAME, T.GRADENAME, T.MODEL_DESC, T.STD_NAME, T.STD_STYLE_DESC, "
                + "T.ORDER_NO, T.ORDER_SEQ, T.ORDER_SEQ_NO, T.PLINE_NAME, T.MAT_ORIGIN_NAME, T.ACT_DIMATER, "
                + "T.ACT_HEIGHT, T.ACT_LEN_MIN, T.ACT_LEN_MAX, T.BELONG_NAME, T.JUDGE_RESULT, T.CREATE_NAME,"
                + " B.STORAGE_NO, B.LOCATION_NO, C.STORAGE_NAME";
        //sql += " ORDER BY t.judge_stove_no ASC";
        return this.getData(sql);
    }

    /**
     * 半成品库存实绩查询
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryInventory1(ArrayList<String> list, String[] arr,String flag) {
        String condition = CoreConverter.toSqlConditionString("B.STORAGE_NO",
                arr);
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveOut.queryInventory1");
        String condition1 = " AND T.BELONG_CODE NOT IN ('100101','100102','100103')";
        sql = sql.replaceAll("#CONDITION#", condition);
        if(flag.equals("0"))
        {
            sql = sql.replace("#CONDITION1#", condition1);
        }else
        {
        	sql = sql.replace("#CONDITION1#", "");
        }
        if(!list.get(0).equals(""))
        {
        	sql += " and B.STORAGE_NO = '" + list.get(0) + "'";
        }
        if(!list.get(1).equals(""))
        {
            sql += " AND B.LOCATION_NO = '" + list.get(1) + "'";
        }
        if(!list.get(2).equals(""))
        {
        	sql += " AND T.judge_stove_no LIKE '" + list.get(2) + "' || '%'";
        }
        if(!list.get(5).equals(""))
        {
			sql += " AND T.Instock_Time BETWEEN  to_date('" + list.get(5)
					+ "', 'YYYY/MM/DD HH24:MI:SS')";
			sql += " AND to_date('" + list.get(7)
					+ "', 'YYYY/MM/DD HH24:MI:SS')";
        }
        //sql += " AND T.INSTOCK_FLAG = '1'";
        sql += " group by T.JUDGE_STOVE_NO, T.BATCH_NO, T.BATCH_GROUD_NO, T.MEMO, T.PRODUCT_FLAG, T.MAT_STATUS,"
                + " T.PRODUCNAME, T.STEELNAME, T.SPEC_NAME, T.GRADENAME, T.MODEL_DESC, T.STD_NAME, T.STD_STYLE_DESC, "
                + "T.ORDER_NO, T.ORDER_SEQ, T.ORDER_SEQ_NO, T.PLINE_NAME, T.MAT_ORIGIN_NAME, T.ACT_DIMATER, "
                + "T.ACT_HEIGHT, T.ACT_LEN_MIN, T.ACT_LEN_MAX, T.BELONG_NAME, T.JUDGE_RESULT, T.CREATE_NAME,"
                + " B.STORAGE_NO, B.LOCATION_NO, C.STORAGE_NAME";
        //sql += " ORDER BY t.judge_stove_no ASC";
        return this.getData(sql);
    }

    
    /**
     * 查询出库单号
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryOutBillList(ArrayList<String> list) {
        return this.getDataBySqlID("FrmPipeMoveOut.queryOutBillList", list
                .toArray());
    }

    /**
     * 根据炉批组查询MAT_ZC_M材料是否在库
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryCount(ArrayList<String> list) {
        return this.getDataBySqlID("FrmPipeMoveOut.queryCount", list.toArray());
    }

    /**
     * 每支材料对应的倒库（出库）流水号
     * @param conn c
     * @param strlist 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String querySendSql(Connection conn, String strlist, String strType)
            throws Exception {
        String seq = "";
        PreparedStatement psta = null;
        Date dt = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveOut.queryOutList");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strlist);
        psta.setString(2, matter1.format(dt));
        psta.setString(3, strType);
        psta.setString(4, strlist);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            seq = rs.getString(1);
        }
        rs.close();
        psta.close();
        return seq;
    }

    /**
     * 新增
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject addMoveOut(ArrayList<ArrayList<String>> pram,
            String storage) {
        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");
        String systime = dateFormat.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务

            String sqlquery = ""; // 根据按炉批行查询MAT_ZC_M主键
            String sqlqueTarget = "";// 根据目标库号，料位号查询对应信息
            String sqlinsert = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveOut.AddMoveList"); // 新增到倒库实绩表
            String sqlinsertXs = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveOutXs.AddMoveList"); // 新增销售到倒库实绩表
            PreparedStatement pstainsert = connection
                    .prepareStatement(sqlinsert);
            PreparedStatement pstainsertXs = connection
                    .prepareStatement(sqlinsertXs);
            String sqldelete = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveOut.DeleteButtre");// 删除倒库物料库位信息
            PreparedStatement pstadelete = connection
                    .prepareStatement(sqldelete);

            String rowNo = "";
            String colNpo = "";
            String storageAttrNo = "";
            String storageAttrName = "";
            String storageTypeNo = "";
            String storageTypeName = "";
            String manageNo = "";
            String manageNmae = "";
            String locatNo = "";
            // 根据库位找料位
            sqlqueTarget = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveOut.queryTager");// 查询要新增的目标库号信息
            PreparedStatement psta1 = connection.prepareStatement(sqlqueTarget);
            psta1.setObject(1, storage);
            ResultSet rsTag = psta1.executeQuery();
            if (rsTag.next()) {
                rowNo = rsTag.getString("ROW_NO");
                colNpo = rsTag.getString("COL_NO");
                storageAttrNo = rsTag.getString("STORAGE_ATTR");
                storageAttrName = rsTag.getString("STORAGE_ATTR_NAME");
                storageTypeNo = rsTag.getString("STORAGE_TYPE_NO");
                storageTypeName = rsTag.getString("STORAGE_TYPE_NAME");
                manageNo = rsTag.getString("MANAGEMENT_NO");
                manageNmae = rsTag.getString("MANAGEMENT_NAME");
                locatNo = rsTag.getString("LOCATION_NO");
            }
            rsTag.close();
            psta1.close();

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String juNo = list.get(0);// 炉号
                String batNo = list.get(1);// 批号
                String groupNo = list.get(2);// 组号
                String storag = list.get(8);// 仓库号
                String lorg = list.get(9);// 料位号
                int abc = Integer.parseInt(list.get(14));
                ArrayList<MatZcMInfoEntity1> matNo = new ArrayList<MatZcMInfoEntity1>();
                sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmPipeMoveOut.QueryAdd"); // 查詢出要新增的数据
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, juNo);
                psta.setObject(2, batNo);
                psta.setObject(3, storag);
                psta.setObject(4, groupNo);
                psta.setObject(5, abc + 1);
                ResultSet rs1 = psta.executeQuery();
                matNo = EntityTool.getEntitysByRs(rs1, MatZcMInfoEntity1.class);
                rs1.close();
                psta.close();
                // 获取出库流水号
                String butessMatNo = querySendSql(connection, list.get(6), list
                        .get(15));
                int outNo = Integer.parseInt(butessMatNo.substring(butessMatNo
                        .length() - 4, butessMatNo.length()));

                for (MatZcMInfoEntity1 out : matNo) {
                    // 新增出库表
                    pstainsert.setObject(1, list.get(6)
                            + StringTool.formatDecimal(outNo, "0000"));
                    pstainsert.setObject(2, list.get(6));
                    pstainsert.setObject(3, list.get(7));
                    pstainsert.setObject(4, out.getMatNo());
                    pstainsert.setObject(5, out.getLotNo());
                    pstainsert.setObject(6, out.getStoveNo());
                    pstainsert.setObject(7, out.getJudgeStoveNo());
                    pstainsert.setObject(8, out.getBatchNo());
                    pstainsert.setObject(9, out.getBatchGroudNo());
                    pstainsert.setObject(10, out.getMaterialNo());
                    pstainsert.setObject(11, out.getMaterialName());
                    pstainsert.setObject(12, out.getProduccode());
                    pstainsert.setObject(13, out.getProducname());
                    pstainsert.setObject(14, out.getStdCode());
                    pstainsert.setObject(15, out.getStdName());
                    pstainsert.setObject(16, out.getGradecode());
                    pstainsert.setObject(17, out.getGradename());
                    pstainsert.setObject(18, out.getSteelcode());
                    pstainsert.setObject(19, out.getSteelname());
                    pstainsert.setObject(20, out.getStdStyle());
                    pstainsert.setObject(21, out.getStdStyleDesc());
                    pstainsert.setObject(22, out.getSpecCode());
                    pstainsert.setObject(23, out.getSpecName());
                    pstainsert.setObject(24, out.getModelCode());
                    pstainsert.setObject(25, out.getModelDesc());
                    pstainsert.setObject(26, out.getProOrderNo());
                    pstainsert.setObject(27, out.getPlineCode());
                    pstainsert.setObject(28, out.getPlineName());
                    pstainsert.setObject(29, out.getActDimater());
                    pstainsert.setObject(30, out.getActHeight());
                    pstainsert.setObject(31, out.getActLen());
                    pstainsert.setObject(32, out.getActLenMin());
                    pstainsert.setObject(33, out.getActLenMax());
                    pstainsert.setObject(34, "1");
                    pstainsert.setObject(35, out.getActWeight());
                    pstainsert.setObject(36, out.getActTheoryWeight());
                    pstainsert.setObject(37, out.getBelongCode());
                    pstainsert.setObject(38, out.getBelongName());
                    pstainsert.setObject(39, list.get(11));// 班次
                    pstainsert.setObject(40, list.get(12));// 班组
                    
                    pstainsertXs.setObject(1, list.get(6)
                            + StringTool.formatDecimal(outNo, "0000"));
                    pstainsertXs.setObject(2, list.get(6));
                    pstainsertXs.setObject(3, list.get(7));
                    pstainsertXs.setObject(4, out.getMatNo());
                    pstainsertXs.setObject(5, out.getLotNo());
                    pstainsertXs.setObject(6, out.getStoveNo());
                    pstainsertXs.setObject(7, out.getJudgeStoveNo());
                    pstainsertXs.setObject(8, out.getBatchNo());
                    pstainsertXs.setObject(9, out.getBatchGroudNo());
                    pstainsertXs.setObject(10, out.getMaterialNo());
                    pstainsertXs.setObject(11, out.getMaterialName());
                    pstainsertXs.setObject(12, out.getProduccode());
                    pstainsertXs.setObject(13, out.getProducname());
                    pstainsertXs.setObject(14, out.getStdCode());
                    pstainsertXs.setObject(15, out.getStdName());
                    pstainsertXs.setObject(16, out.getGradecode());
                    pstainsertXs.setObject(17, out.getGradename());
                    pstainsertXs.setObject(18, out.getSteelcode());
                    pstainsertXs.setObject(19, out.getSteelname());
                    pstainsertXs.setObject(20, out.getStdStyle());
                    pstainsertXs.setObject(21, out.getStdStyleDesc());
                    pstainsertXs.setObject(22, out.getSpecCode());
                    pstainsertXs.setObject(23, out.getSpecName());
                    pstainsertXs.setObject(24, out.getModelCode());
                    pstainsertXs.setObject(25, out.getModelDesc());
                    pstainsertXs.setObject(26, out.getProOrderNo());
                    pstainsertXs.setObject(27, out.getPlineCode());
                    pstainsertXs.setObject(28, out.getPlineName());
                    pstainsertXs.setObject(29, out.getActDimater());
                    pstainsertXs.setObject(30, out.getActHeight());
                    pstainsertXs.setObject(31, out.getActLen());
                    pstainsertXs.setObject(32, out.getActLenMin());
                    pstainsertXs.setObject(33, out.getActLenMax());
                    pstainsertXs.setObject(34, "1");
                    pstainsertXs.setObject(35, out.getActWeight());
                    pstainsertXs.setObject(36, out.getActTheoryWeight());
                    pstainsertXs.setObject(37, out.getBelongCode());
                    pstainsertXs.setObject(38, out.getBelongName());
                    pstainsertXs.setObject(39, list.get(11));// 班次
                    pstainsertXs.setObject(40, list.get(12));// 班组

                    if (out.getRpoTime() == "") {
                        pstainsert.setObject(41, "");
                        pstainsertXs.setObject(41, "");

                    }
                    else {
                        pstainsert.setObject(41, out.getRpoTime().substring(0,
                                19));
                        pstainsertXs.setObject(41, out.getRpoTime().substring(0,
                                19));
                    }
                    pstainsert.setObject(42, out.getProBc());
                    pstainsert.setObject(43, out.getProBz());
                    pstainsert.setObject(44, storage);
                    pstainsert.setObject(45, locatNo);
                    pstainsert.setObject(46, rowNo);
                    pstainsert.setObject(47, colNpo);
                    pstainsert.setObject(48, storageAttrNo);
                    pstainsert.setObject(49, storageAttrName);
                    pstainsert.setObject(50, storageTypeNo);
                    pstainsert.setObject(51, storageTypeName);
                    pstainsert.setObject(52, manageNo);
                    pstainsert.setObject(53, manageNmae);
                    pstainsert.setObject(54, out.getStorageNo());
                    pstainsert.setObject(55, out.getLocationNo());
                    pstainsert.setObject(56, out.getLaryNo());
                    pstainsert.setObject(57, out.getLocNo());
                    pstainsert.setObject(58, out.getStorageAttr());
                    pstainsert.setObject(59, out.getStorageAttrName());
                    pstainsert.setObject(60, out.getStorageTypeNo());
                    pstainsert.setObject(61, out.getStorageTypeName());
                    pstainsert.setObject(62, out.getManagementNo());
                    pstainsert.setObject(63, out.getManagementName());
                    pstainsert.setObject(64, list.get(13));
                    pstainsert.setObject(65, list.get(15));
                    pstainsert.setObject(66, list.get(16));
                    pstainsert.setObject(67, out.getOrderNo());
                    pstainsert.setObject(68, out.getOrderSeq());
                    pstainsert.setObject(69, out.getOrderSeqNo());
                    pstainsert.setObject(70, out.getOrdPk());
                    pstainsert.setObject(71, out.getOrdLnPk());
                    pstainsert.setObject(72, out.getOrdLnDlyPk());
                    pstainsert.setObject(73, out.getProductFlag());
                    pstainsert.setObject(74, out.getMatStatus());
                    pstainsert.setObject(75, systime);
                    pstainsert.setObject(76, systime);
                    pstainsert.addBatch();
                    pstainsertXs.setObject(42, out.getProBc());
                    pstainsertXs.setObject(43, out.getProBz());
                    pstainsertXs.setObject(44, storage);
                    pstainsertXs.setObject(45, locatNo);
                    pstainsertXs.setObject(46, rowNo);
                    pstainsertXs.setObject(47, colNpo);
                    pstainsertXs.setObject(48, storageAttrNo);
                    pstainsertXs.setObject(49, storageAttrName);
                    pstainsertXs.setObject(50, storageTypeNo);
                    pstainsertXs.setObject(51, storageTypeName);
                    pstainsertXs.setObject(52, manageNo);
                    pstainsertXs.setObject(53, manageNmae);
                    pstainsertXs.setObject(54, out.getStorageNo());
                    pstainsertXs.setObject(55, out.getLocationNo());
                    pstainsertXs.setObject(56, out.getLaryNo());
                    pstainsertXs.setObject(57, out.getLocNo());
                    pstainsertXs.setObject(58, out.getStorageAttr());
                    pstainsertXs.setObject(59, out.getStorageAttrName());
                    pstainsertXs.setObject(60, out.getStorageTypeNo());
                    pstainsertXs.setObject(61, out.getStorageTypeName());
                    pstainsertXs.setObject(62, out.getManagementNo());
                    pstainsertXs.setObject(63, out.getManagementName());
                    pstainsertXs.setObject(64, list.get(13));
                    pstainsertXs.setObject(65, list.get(15));
                    pstainsertXs.setObject(66, list.get(16));
                    pstainsertXs.setObject(67, out.getOrderNo());
                    pstainsertXs.setObject(68, out.getOrderSeq());
                    pstainsertXs.setObject(69, out.getOrderSeqNo());
                    pstainsertXs.setObject(70, out.getOrdPk());
                    pstainsertXs.setObject(71, out.getOrdLnPk());
                    pstainsertXs.setObject(72, out.getOrdLnDlyPk());
                    pstainsertXs.setObject(73, out.getProductFlag());
                    pstainsertXs.setObject(74, out.getMatStatus());
                    pstainsertXs.setObject(75, systime);
                    pstainsertXs.setObject(76, systime);
                    pstainsertXs.addBatch();
                    outNo++;
                    // 删除位置表
                    pstadelete.setObject(1, out.getMatNo());
                    pstadelete.addBatch();
                }
                pstainsert.executeBatch();
                pstainsertXs.executeBatch();
                pstadelete.executeBatch();
            }
            cro.setV_errMsg("倒库出库成功！");
            cro.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            cro.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 cro;
    }

    /**
     * 作废出库（倒库）实绩记录
     * @param list 传递参数
     * @return obj
     */
    public CoreReturnObject upDateInfo(ArrayList<ArrayList<String>> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            // 数组长度等于倒库出库支数和
            String sqlquery = "";
            String sqlinsert = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveOut.AddButtress"); // 新增库位信息
            PreparedStatement pstainster = connection
                    .prepareStatement(sqlinsert);
            String sqldelete = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveOut.deleteOutlist"); // 删除出库表
            PreparedStatement pstadelete = connection
                    .prepareStatement(sqldelete);
            String sqldeleteXs = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveOutXs.deleteOutlist"); // 删除销售出库表
            PreparedStatement pstadeleteXs = connection
                    .prepareStatement(sqldeleteXs);

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String outNo = list.get(0);// 出库单号
                String juNo = list.get(1);// 炉号
                String bathNo = list.get(2);// 批号
                String groupNo = list.get(3);// 组号
                String name = list.get(5);
                String time = list.get(6);
                int sunUpdate = Integer.parseInt(list.get(4));

                ArrayList<MatZcMInfoEntity1> matNo = new ArrayList<MatZcMInfoEntity1>();
                sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmPipeMoveOut.queryOutMatList"); // 查詢出要新增到ydm_zc_buttress表中的数据
                psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, outNo);
                psta.setObject(2, juNo);
                psta.setObject(3, bathNo);
                psta.setObject(4, groupNo);
                psta.setObject(5, sunUpdate + 1);
                ResultSet rs1 = psta.executeQuery();
                matNo = EntityTool.getEntitysByRs(rs1, MatZcMInfoEntity1.class);
                rs1.close();
                psta.close();

                for (MatZcMInfoEntity1 out : matNo) {
                    pstainster.setObject(1, out.getMatNo());
                    pstainster.setObject(2, out.getJudgeStoveNo());
                    pstainster.setObject(3, out.getBatchNo());
                    pstainster.setObject(4, out.getBatchGroudNo());
                    pstainster.setObject(5, out.getStorageNo());
                    pstainster.setObject(6, out.getLocationNo());
                    pstainster.setObject(7, out.getLaryNo());
                    pstainster.setObject(8, out.getLocNo());
                    pstainster.setObject(9, out.getStorageAttr());
                    pstainster.setObject(10, out.getStorageAttrName());
                    pstainster.setObject(11, out.getStorageTypeNo());
                    pstainster.setObject(12, out.getStorageTypeName());
                    pstainster.setObject(13, out.getManagementNo());
                    pstainster.setObject(14, out.getManagementName());
                    pstainster.setObject(15, name);
                    pstainster.setObject(16, time);
                    pstainster.addBatch();

                    pstadelete.setObject(1, out.getOutstockSqe());
                    pstadelete.addBatch();
                    pstadeleteXs.setObject(1, out.getOutstockSqe());
                    pstadeleteXs.addBatch();

                }
                pstainster.executeBatch();
                pstadelete.executeBatch();
                pstadeleteXs.executeBatch();

            }

            cro.setV_errMsg("撤销倒库成功！");
            cro.setResult(1);
            connection.commit();

        }
        catch (Exception e) {
            cro.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 cro;
    }

    /***
     * 获取所有钢管的目标库
     * @param storeNo
     * @return
     */
    public CoreReturnObject getStoreAll(String[] arr) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveOut.getStoreAll");
        //sql += CoreConverter.nOtoSqlConditionString("T.STORAGE_NO", arr);
        sql+=" ORDER BY T.STORAGE_NAME ASC";
        return this.getData(sql);
    }
    
	/***
     * 获取所有管材的目标库
     * @return
     */
    public CoreReturnObject getStoreAllByType(String[] arr)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("FrmPipeMoveOut.getStoreAllByType");
    	sql += " ORDER BY T.STORAGE_NO, T.STORAGE_NAME";
    	return this.getData(sql);
    }

    /***
     * 倒库时判断实际支数是否满足倒库要求
     * @param list
     * @return
     */
    /*
     * public CoreReturnObject getActualCount(ArrayList<String> list) { return
     * this.getDataBySqlID("FrmPipeMoveOut.getActualCount", list.toArray()); }
     */

    /***
     * 查询倒库数据是否满足要求
     */
    public CoreReturnObject getMatStaus(ArrayList<String> list) {
        return this
                .getDataBySqlID("FrmPipeMoveOut.getMatStaus", list.toArray());
    }
}
