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.sleepycat.persist.impl.SimpleFormat;
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.entity.YdmZcOutlistEntity;
import com.steering.pss.ydm.entity.YdmZcOutlistEntity1;

/**
 * @author TJG 2015-04-09
 */
public class FrmPipeMoveIn extends DBCommon {

    /**
     * 查询倒库实绩
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryOutPerfo(ArrayList<String> list, String[] arr) {
        String strRegStart = list.get(3);
        String strRegEnd = list.get(4);
        String strWare = list.get(0);// 仓库号
        String strFurnace = list.get(2);// 炉号
        String moveInDoc = list.get(5);
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveIn.queryOutPerfo");
        sql += CoreConverter.toSqlConditionString("T.TAR_STORAGE_NO", arr);
        if (!strWare.equals("")) {
            sql += " AND T.TAR_STORAGE_NO='" + strWare + "'";
        }
        if (!strFurnace.equals("")) {
            sql += " AND T.JUDGE_STOVE_NO='" + strFurnace + "'";
        }
        if (!moveInDoc.equals("")) {
            sql += " AND T.OUTSTOCK_DOC LIKE || '&' LIKE ('%' || '" + moveInDoc
                    + "' || '%')";
        }
        sql += " AND T.CREATE_TIME BETWEEN TO_DATE('" + strRegStart
                + "', 'YYYY-MM-DD HH24:MI:SS') AND  TO_DATE('" + strRegEnd
                + "', 'YYYY-MM-DD HH24:MI:SS')";
        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";
        return this.getData(sql);
    }

    /**
     * 查询倒库实绩
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryOutPerfo1(ArrayList<String> list, String[] arr,String flag) {
        String condition = CoreConverter.toSqlConditionString("T.TAR_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.TAR_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(3).equals(""))
        {
			sql += " AND t.OUTSTOCK_TIME BETWEEN to_date('" + list.get(3)
					+ "', 'YYYY/MM/DD HH24:MI:SS')";
			sql += " AND to_date('" + list.get(4)
					+ "', 'YYYY/MM/DD HH24:MI:SS') ";
        }
        if(!list.get(5).equals(""))
        {
            sql += " AND T.OUTSTOCK_DOC LIKE '" + list.get(5)+ "'||'%'";
        }
        //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 queryInListInfo(ArrayList<String> list,
            String[] arr, String strOutbound) {
        String strRegStart = list.get(3);
        String strRegEnd = list.get(4);
        String strWare = list.get(0);// 仓库号
        String strFurnace = list.get(2);// 炉号
        String moveInDoc = list.get(5);

        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveIn.queryInListInfo");
        sql += CoreConverter.toSqlConditionString("T.STORAGE_NO", arr);
        if (!strWare.equals("")) {
            sql += " AND T.STORAGE_NO='" + strWare + "'";
        }
        if (!strFurnace.equals("")) {
            sql += " AND T.JUDGE_STOVE_NO='" + strFurnace + "'";
        }
        if (!moveInDoc.equals("")) {
            sql += " AND T.INSTOCK_DOC LIKE || '&' LIKE ('%' || '" + moveInDoc
                    + "' || '%')";
        }
        sql += " AND T.INSTOCK_TYPE_CODE='" + strOutbound + "'";
        sql += " AND T.INSTOCK_TIME BETWEEN TO_DATE('" + strRegStart
                + "', 'YYYY-MM-DD HH24:MI:SS') AND  TO_DATE('" + strRegEnd
                + "', 'YYYY-MM-DD HH24:MI:SS')";
        sql += "  GROUP BY T.INSTOCK_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.PRO_ORDER_NO, T.PLINE_NAME, T.ACT_DIMATER, "
                + " T.ACT_HEIGHT, T.ACT_LEN_MIN, T.ACT_LEN_MAX, T.BELONG_NAME,T.STORAGE_NO, T.LOCATION_NO,"
                + " B.STORAGE_NAME, T.STORAGE_ATTR_NAME, T.STORAGE_TYPE_NAME, T.MANAGEMENT_NAME, T.CREATE_NAME";
        return this.getData(sql);

    }

    
    /**
     * 查询入库实绩
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryInListInfo1(ArrayList<String> list,
            String[] arr, String strOutbound,String flag) {
        String strRegStart = list.get(3);
        String strRegEnd = list.get(4);
        String strWare = list.get(0);// 仓库号
        String strFurnace = list.get(2);// 炉号
        String moveInDoc = list.get(5);

        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveIn.queryInListInfo1");
        sql += CoreConverter.toSqlConditionString("T.STORAGE_NO", arr);
        sql += " AND S.BELONG_CODE NOT IN ('100101','100102','100103')";
        if (!strWare.equals("")) {
            sql += " AND T.STORAGE_NO='" + strWare + "'";
        }
        if (!strFurnace.equals("")) {
            sql += " AND T.JUDGE_STOVE_NO='" + strFurnace + "'";
        }
        if (!moveInDoc.equals("")) {
            sql += " AND T.INSTOCK_DOC LIKE || '&' LIKE ('%' || '" + moveInDoc
                    + "' || '%')";
        }
        sql += " AND T.INSTOCK_TYPE_CODE='" + strOutbound + "'";
        if(!strRegStart.equals(""))
        {
            sql += " AND T.INSTOCK_TIME BETWEEN TO_DATE('" + strRegStart
                + "', 'YYYY-MM-DD HH24:MI:SS') AND  TO_DATE('" + strRegEnd
                + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        sql += "  GROUP BY T.INSTOCK_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.PRO_ORDER_NO, T.PLINE_NAME, T.ACT_DIMATER, "
                + " T.ACT_HEIGHT, T.ACT_LEN_MIN, T.ACT_LEN_MAX, T.BELONG_NAME,T.STORAGE_NO, T.LOCATION_NO,"
                + " B.STORAGE_NAME, T.STORAGE_ATTR_NAME, T.STORAGE_TYPE_NAME, T.MANAGEMENT_NAME, T.CREATE_NAME";
        return this.getData(sql);

    }
    
    /**
     * 查询库存是否在库实绩支数
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryOutCount(String juNo, String batchNo,
            String gropNo) {
        return this.getDataBySqlID("FrmPipeMoveIn.queryOutCount", new Object[] {
                juNo, batchNo, gropNo });
    }

    /**
     * 根据出库单号查询出库实绩
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryOutListSend(ArrayList<Object> list) {

        String strparm = "";
        for (int i = 0; i < list.size(); i++) {
            strparm += "'" + list.get(i) + "',";
        }
        strparm = strparm.substring(0, strparm.length() - 1);
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveIn.queryOutListSend");
        String str = " AND T.OUTSTOCK_DOC IN("
                + strparm
                + ") AND t.VALIDFLAG = '1'"
                + " and t.TAR_REC_FLAG='0'"
                + " group by t.judge_stove_no, t.batch_no, t.batch_groud_no,t.TAR_STORAGE_NO,t.TAR_LOCATION_NO,"
                + "t.OUTSTOCK_DOC, t.TAR_REC_FLAG ORDER BY t.OUTSTOCK_DOC ASC";
        sql = sql + str;
        return this.getData(sql);
    }

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

    /**
     * 获取入库单号
     * @param conn c
     * @param strlist 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String queryinDocSql(Connection conn, String strType,
            String strInMemo) throws Exception {
        String seq = "";
        PreparedStatement psta = null;
        Date dt = new Date();
        SimpleDateFormat matter = new SimpleDateFormat("yyMMdd");
        SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("FrmPipeMoveIn.queryInDocList");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strInMemo + matter.format(dt));
        //psta.setString(2, matter1.format(dt));
        psta.setString(2, strType);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            seq = rs.getString(1);
        }
        rs.close();
        psta.close();
        return seq;
    }

    /**
     * 新增
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject addInList(ArrayList<ArrayList<String>> parm,
            String strInMemo) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        Date now = new Date();
        SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String systime = simple.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlquery = "";
            String sqlinsert = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveIn.AddMoveList"); // 新增到入库实绩表
            String sqlinsertXs = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveInXs.AddMoveList"); // 新增到销售入库实绩表
            PreparedStatement pstainsert = connection
                    .prepareStatement(sqlinsert);
            PreparedStatement pstainsertXs = connection
                    .prepareStatement(sqlinsertXs);
            String sqlinsertButtr = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveIn.AddButressList"); // 新增到位置表
            PreparedStatement pstainsertButtr = connection
                    .prepareStatement(sqlinsertButtr);
            String sqlupdate = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveIn.updateOutfalgList"); // 修改倒库标志
            PreparedStatement pstaupdate = connection
                    .prepareStatement(sqlupdate);
            for (int k = 0; k < parm.size(); k++) {
                ArrayList<String> list = (ArrayList<String>) parm.get(k);
                String juNo = list.get(1);// 炉号
                String batcNo = list.get(2);// 批号
                String groupNo = list.get(3);// 组号
                String outNo = list.get(4);// 出库单号
                String bc = list.get(5);
                String bz = list.get(6);
                String name = list.get(7);
                String strOutbound = list.get(8);// 入库类型
                String strOutname = list.get(9);

                int abc = Integer.parseInt(list.get(0));

                ArrayList<YdmZcOutlistEntity1> matNo = new ArrayList<YdmZcOutlistEntity1>();
                sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmPipeMoveIn.QueryAdd"); // 查詢出要新增的数据
                psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, juNo);
                psta.setObject(2, batcNo);
                psta.setObject(3, groupNo);
                psta.setObject(4, outNo);
                ResultSet rs1 = psta.executeQuery();
                matNo = EntityTool.getEntitysByRs(rs1,
                        YdmZcOutlistEntity1.class);
                rs1.close();
                psta.close();
                // sqlqueTarget = CoreXmlSqlParsersFactory
                // .getSql("FrmPipeMoveIn.queryTager");// 查询要新增的目标库号信息
                // psta = connection.prepareStatement(sqlqueTarget);
                // psta.setObject(1, list.get(10));
                // psta.setObject(2, list.get(11));
                // ResultSet rsTag = psta.executeQuery();
                // if (rsTag.next()) {}

                // 获取入库单号
                String inDoc = queryinDocSql(connection, strOutbound, strInMemo);

                // 获取入库流水号
                String butessMatNo = querySendSql(connection, inDoc);
                int inNo = Integer.parseInt(butessMatNo.substring(butessMatNo
                        .length() - 4, butessMatNo.length()));
                for (YdmZcOutlistEntity1 out : matNo) {

                    pstainsert.setObject(1, inDoc
                            + StringTool.formatDecimal(inNo, "0000"));
                    pstainsert.setObject(2, inDoc);
                    pstainsert.setObject(3, strOutbound);
                    pstainsert.setObject(4, strOutname);
                    pstainsert.setObject(5, list.get(12));
                    pstainsert.setObject(6, out.getMatNo());
                    pstainsert.setObject(7, out.getLotNo());
                    pstainsert.setObject(8, out.getStoveNo());
                    pstainsert.setObject(9, juNo);
                    pstainsert.setObject(10, batcNo);
                    pstainsert.setObject(11, groupNo);
                    pstainsert.setObject(12, out.getMaterialNo());
                    pstainsert.setObject(13, out.getMaterialName());
                    pstainsert.setObject(14, out.getProduccode());
                    pstainsert.setObject(15, out.getProducname());
                    pstainsert.setObject(16, out.getStdCode());
                    pstainsert.setObject(17, out.getStdName());
                    pstainsert.setObject(18, out.getGradecode());
                    pstainsert.setObject(19, out.getGradename());
                    pstainsert.setObject(20, out.getSteelcode());
                    pstainsert.setObject(21, out.getSteelname());
                    pstainsert.setObject(22, out.getStdStyle());
                    pstainsert.setObject(23, out.getStdStyleDesc());
                    pstainsert.setObject(24, out.getSpecCode());
                    pstainsert.setObject(25, out.getSpecName());
                    pstainsert.setObject(26, out.getModelCode());
                    pstainsert.setObject(27, out.getModelDesc());
                    pstainsert.setObject(28, out.getProOrderNo());
                    pstainsert.setObject(29, out.getPlineCode());
                    pstainsert.setObject(30, out.getPlineName());
                    pstainsert.setObject(31, out.getActDimater());
                    pstainsert.setObject(32, out.getActHeight());
                    pstainsert.setObject(33, out.getActLen());
                    pstainsert.setObject(34, out.getActLenMin());
                    pstainsert.setObject(35, out.getActLenMax());
                    pstainsert.setObject(36, "1");
                    pstainsert.setObject(37, out.getActWeight());
                    pstainsert.setObject(38, out.getActTheoryWeight());
                    pstainsert.setObject(39, out.getBelongCode());
                    pstainsert.setObject(40, out.getBelongName());
                    pstainsert.setObject(41, out.getTarStorageNo());
                    pstainsert.setObject(42, out.getTarLocationNo());
                    pstainsert.setObject(43, out.getTarLaryNo());
                    pstainsert.setObject(44, out.getTarLocNo());
                    pstainsert.setObject(45, out.getTarStorageAttr());
                    pstainsert.setObject(46, out.getTarStorageAttrName());
                    pstainsert.setObject(47, out.getTarStorageTypeNo());
                    pstainsert.setObject(48, out.getTarStorageTypeName());
                    pstainsert.setObject(49, out.getTarManagementNo());
                    pstainsert.setObject(50, out.getTarManagementName());
                    
                    pstainsertXs.setObject(1, inDoc
                            + StringTool.formatDecimal(inNo, "0000"));
                    pstainsertXs.setObject(2, inDoc);
                    pstainsertXs.setObject(3, strOutbound);
                    pstainsertXs.setObject(4, strOutname);
                    pstainsertXs.setObject(5, list.get(12));
                    pstainsertXs.setObject(6, out.getMatNo());
                    pstainsertXs.setObject(7, out.getLotNo());
                    pstainsertXs.setObject(8, out.getStoveNo());
                    pstainsertXs.setObject(9, juNo);
                    pstainsertXs.setObject(10, batcNo);
                    pstainsertXs.setObject(11, groupNo);
                    pstainsertXs.setObject(12, out.getMaterialNo());
                    pstainsertXs.setObject(13, out.getMaterialName());
                    pstainsertXs.setObject(14, out.getProduccode());
                    pstainsertXs.setObject(15, out.getProducname());
                    pstainsertXs.setObject(16, out.getStdCode());
                    pstainsertXs.setObject(17, out.getStdName());
                    pstainsertXs.setObject(18, out.getGradecode());
                    pstainsertXs.setObject(19, out.getGradename());
                    pstainsertXs.setObject(20, out.getSteelcode());
                    pstainsertXs.setObject(21, out.getSteelname());
                    pstainsertXs.setObject(22, out.getStdStyle());
                    pstainsertXs.setObject(23, out.getStdStyleDesc());
                    pstainsertXs.setObject(24, out.getSpecCode());
                    pstainsertXs.setObject(25, out.getSpecName());
                    pstainsertXs.setObject(26, out.getModelCode());
                    pstainsertXs.setObject(27, out.getModelDesc());
                    pstainsertXs.setObject(28, out.getProOrderNo());
                    pstainsertXs.setObject(29, out.getPlineCode());
                    pstainsertXs.setObject(30, out.getPlineName());
                    pstainsertXs.setObject(31, out.getActDimater());
                    pstainsertXs.setObject(32, out.getActHeight());
                    pstainsertXs.setObject(33, out.getActLen());
                    pstainsertXs.setObject(34, out.getActLenMin());
                    pstainsertXs.setObject(35, out.getActLenMax());
                    pstainsertXs.setObject(36, "1");
                    pstainsertXs.setObject(37, out.getActWeight());
                    pstainsertXs.setObject(38, out.getActTheoryWeight());
                    pstainsertXs.setObject(39, out.getBelongCode());
                    pstainsertXs.setObject(40, out.getBelongName());
                    pstainsertXs.setObject(41, out.getTarStorageNo());
                    pstainsertXs.setObject(42, out.getTarLocationNo());
                    pstainsertXs.setObject(43, out.getTarLaryNo());
                    pstainsertXs.setObject(44, out.getTarLocNo());
                    pstainsertXs.setObject(45, out.getTarStorageAttr());
                    pstainsertXs.setObject(46, out.getTarStorageAttrName());
                    pstainsertXs.setObject(47, out.getTarStorageTypeNo());
                    pstainsertXs.setObject(48, out.getTarStorageTypeName());
                    pstainsertXs.setObject(49, out.getTarManagementNo());
                    pstainsertXs.setObject(50, out.getTarManagementName());
                    
                    if (out.getRpoTime() == "") {
                        pstainsert.setObject(51, "");
                        pstainsertXs.setObject(51, "");

                    }
                    else {
                        pstainsert.setObject(51, out.getRpoTime().substring(0,
                                19));
                        pstainsertXs.setObject(51, out.getRpoTime().substring(0,
                                19));
                    }
                    pstainsert.setObject(52, out.getProBc());
                    pstainsert.setObject(53, out.getProBz());
                    pstainsert.setObject(54, bc);
                    pstainsert.setObject(55, bz);
                    pstainsert.setObject(56, name);
                    pstainsert.setObject(57, systime);
                    pstainsert.setObject(58, systime);
                    pstainsert.setObject(59, out.getTarDepartmentCode());
                    pstainsert.setObject(60, out.getTarDepartmentDesc());
                    pstainsert.setObject(61, out.getOrdPk());
                    pstainsert.setObject(62, out.getOrdLnPk());
                    pstainsert.setObject(63, out.getOrdLnDlyPk());
                    pstainsert.setObject(64, out.getOrderNo());
                    pstainsert.setObject(65, out.getOrderSeq());
                    pstainsert.setObject(66, out.getDeliveryNo());
                    pstainsert.setObject(67, out.getProductFlag());
                    pstainsert.setObject(68, out.getMatStatus());
                    pstainsert.setObject(69, systime);
                    pstainsert.setObject(70, out.getFinishproMold());
                    pstainsert.setObject(71, out.getInMold());
                    pstainsert.addBatch();
                    
                    pstainsertXs.setObject(52, out.getProBc());
                    pstainsertXs.setObject(53, out.getProBz());
                    pstainsertXs.setObject(54, bc);
                    pstainsertXs.setObject(55, bz);
                    pstainsertXs.setObject(56, name);
                    pstainsertXs.setObject(57, systime);
                    pstainsertXs.setObject(58, systime);
                    pstainsertXs.setObject(59, out.getTarDepartmentCode());
                    pstainsertXs.setObject(60, out.getTarDepartmentDesc());
                    pstainsertXs.setObject(61, out.getOrdPk());
                    pstainsertXs.setObject(62, out.getOrdLnPk());
                    pstainsertXs.setObject(63, out.getOrdLnDlyPk());
                    pstainsertXs.setObject(64, out.getOrderNo());
                    pstainsertXs.setObject(65, out.getOrderSeq());
                    pstainsertXs.setObject(66, out.getDeliveryNo());
                    pstainsertXs.setObject(67, out.getProductFlag());
                    pstainsertXs.setObject(68, out.getMatStatus());
                    pstainsertXs.setObject(69, systime);
                    pstainsertXs.setObject(70, out.getFinishproMold());
                    pstainsertXs.setObject(71, out.getInMold());
                    pstainsertXs.addBatch();
                    
                    inNo++;

                    // 对位置表进行插入操作
                    pstainsertButtr.setObject(1, out.getMatNo());
                    pstainsertButtr.setObject(2, juNo);
                    pstainsertButtr.setObject(3, batcNo);
                    pstainsertButtr.setObject(4, groupNo);// 组炉批号
                    pstainsertButtr.setObject(5, out.getTarStorageNo());
                    pstainsertButtr.setObject(6, out.getTarLocationNo());
                    pstainsertButtr.setObject(7, out.getTarStorageTypeNo());// 库类别代码
                    pstainsertButtr.setObject(8, out.getTarStorageTypeName());// 类别代码描述
                    pstainsertButtr.setObject(9, out.getTarManagementNo());// 科室代码
                    pstainsertButtr.setObject(10, out.getTarManagementName());// 科室代码描述
                    pstainsertButtr.setObject(11, name);
                    pstainsertButtr.setObject(12, systime);
                    pstainsertButtr.setObject(13, out.getTarDepartmentCode());
                    pstainsertButtr.setObject(14, out.getTarDepartmentDesc());
                    pstainsertButtr.setObject(15, out.getTarStorageAttr());
                    pstainsertButtr.setObject(16, out.getTarStorageAttrName());
                    pstainsertButtr.setObject(17, out.getTarLaryNo());
                    pstainsertButtr.setObject(18, out.getTarLocNo());
                    pstainsertButtr.addBatch();

                    // 修改倒库标志
                    pstaupdate.setObject(1, "1");
                    pstaupdate.setObject(2, systime);
                    pstaupdate.setObject(3, bc);
                    pstaupdate.setObject(4, bz);
                    pstaupdate.setObject(5, name);
                    pstaupdate.setObject(6, systime);
                    pstaupdate.setObject(7, out.getOutstockSqe());
                    pstaupdate.addBatch();

                }
                pstainsert.executeBatch();
                pstainsertXs.executeBatch();
                pstainsertButtr.executeBatch();
                pstaupdate.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>> parm,
            String strOutbound) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        Date now = new Date();
        SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String systime = simple.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqldelete = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveIn.deleteMoveList"); // 删除入库实绩表
            PreparedStatement pstadelete = connection
                    .prepareStatement(sqldelete);
            String sqldeleteXs = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveInXs.deleteMoveList"); // 删除销售入库实绩表
            PreparedStatement pstadeleteXs = connection
                    .prepareStatement(sqldeleteXs);
            String sqldeleteButtr = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveIn.deleteButressList"); // 删除到位置表
            PreparedStatement pstadeleteButtr = connection
                    .prepareStatement(sqldeleteButtr);
            String sqlupdate = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeMoveIn.updateOutfalgList1"); // 修改倒库标志
            PreparedStatement pstaupdate = connection
                    .prepareStatement(sqlupdate);

            for (int k = 0; k < parm.size(); k++) {
                ArrayList<String> list = (ArrayList<String>) parm.get(k);
                String juNo = list.get(1);// 炉号
                String batcNo = list.get(2);// 批号
                String groupNo = list.get(3);// 组号
                String inNo = list.get(0);// 入库单号
                String name = list.get(5);
                int sunUpdate = Integer.parseInt(list.get(4));

                // 获取材料号
                ArrayList<String> billMats = new ArrayList<String>();
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmPipeMoveIn.queryOutSqe");
                psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, strOutbound);
                psta.setObject(2, juNo);
                psta.setObject(3, batcNo);
                psta.setObject(4, groupNo);
                psta.setObject(5, inNo);
                ResultSet rs = psta.executeQuery();
                while (rs.next()) {
                    billMats.add(rs.getString("MAT_NO"));
                }
                rs.close();
                psta.close();

                for (int i = 0; i < billMats.size(); i++) {
                    // 删除位置表
                    pstadeleteButtr.setObject(1, billMats.get(i));
                    pstadeleteButtr.addBatch();
                    // 修改倒库标志
                    pstaupdate.setObject(1, "0");
                    pstaupdate.setObject(2, systime);
                    pstaupdate.setObject(3, "");
                    pstaupdate.setObject(4, "");
                    pstaupdate.setObject(5, name);
                    pstaupdate.setObject(6, systime);
                    pstaupdate.setObject(7, billMats.get(i));
                    pstaupdate.setObject(8, "800803");
                    pstaupdate.addBatch();
                }
                pstadeleteButtr.executeBatch();
                pstaupdate.executeBatch();

                // 删除入库表
                pstadelete.setObject(1, strOutbound);
                pstadelete.setObject(2, juNo);
                pstadelete.setObject(3, batcNo);
                pstadelete.setObject(4, groupNo);
                pstadelete.setObject(5, inNo);
                pstadelete.addBatch();
                
                // 删除销售入库表
                pstadeleteXs.setObject(1, strOutbound);
                pstadeleteXs.setObject(2, juNo);
                pstadeleteXs.setObject(3, batcNo);
                pstadeleteXs.setObject(4, groupNo);
                pstadeleteXs.setObject(5, inNo);
                pstadeleteXs.addBatch();
            }
            pstadelete.executeBatch();
            pstadeleteXs.executeBatch();
            cro.setV_errMsg("撤销收料成功！");
            cro.setResult(1);
            connection.commit();

        }
        catch (Exception 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;
    }
}
