package com.steering.pss.ydm.pipemanage;

import java.math.BigDecimal;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

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

import com.ibm.websphere.security.Result;
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.base.FrmEndMaterial;
import com.steering.pss.ydm.base.MeanValueCalculation;
import com.steering.pss.ydm.entity.YdmZcInlistEntity;

import core.stlmes.server.sale.util.Convert;

/**
 * @author WHB 2015-3-4
 */
public class CorePipeInTemp extends DBCommon {

    /**
     * 合同查询
     * @param orderno 合同号
     * @param orderSeq 合同行号
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryOrder(String orderno, String orderSeq,String[] arr) {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.QueryOrder");
    	//sql += CoreConverter.toSqlConditionString("A.sale_org",arr);
    	if(!orderSeq.equals(""))
    	{
    		sql += " AND T1.ORDER_SEQ LIKE '%"+orderSeq+"%'";
    	}
    	String str= CoreConverter.toSqlConditionString("A.departid",arr);
    	str += "AND (("+str+ " AND T2.CREATE_DEPT IS NOT NULL) OR (T2.CREATE_DEPT IS NULL))";
    	sql += " ORDER BY T2.ORDER_NO,T1.ORDER_SEQ,T3.DELIVERY_NO ";
        return this.getData(sql,new Object[]{orderno});
        
//        String str= CoreConverter.toSqlConditionString("E.departid", arr);
//    	str = "AND ("+str+ " AND A.CREATE_DEPT IS NOT NULL) OR (A.CREATE_DEPT IS NULL)";
//    	sql+= str;
//    	sql += " ORDER BY A.ORDER_NO,B.ORDER_SEQ ASC";
    }

    /***
     * 单击事件查合同信息
     * @param orderno
     * @param orderSeq
     * @param arr
     * @return
     */
    public CoreReturnObject queryOrderClick(String orderno, String orderSeq,String[]arr)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.queryOrderClick");
    	//sql += CoreConverter.toSqlConditionString("A.sale_org", arr);
    	
    	sql+= CoreConverter.toSqlConditionString("T2.SALE_AREA_NO",arr);
    	//String str = CoreConverter.toSqlConditionString("A.SALE_ORG", arr);
    	//str += "AND (("+str+ " AND T2.CREATE_DEPT IS NOT NULL) OR (T2.CREATE_DEPT IS NULL))";
    	sql += " ORDER BY T2.ORDER_NO,T1.ORDER_SEQ,T3.DELIVERY_NO";
    	return this.getData(sql, new Object[]{orderno,orderSeq});
    }
    /***
     * 查询已缴库合同信息
     * @param orderno
     * @param orderSeq
     * @return
     */
    public CoreReturnObject queryOrder1(String orderno, String orderSeq)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.queryOrder1");
    	return this.getData(sql, new Object[]{orderno,orderSeq});
    }
    
    
    public CoreReturnObject queryOrder2(String orderno, String orderSeq)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.queryOrder2");
    	return this.getData(sql, new Object[]{orderno,orderSeq});
    }
//    public CoreReturnObject getOrderSEQ(String orderNo,String orderSeq)
//    {
//    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.getOrderSEQ");
//       return this.getData(sql, new Object[]{orderNo,orderSeq});	
//    }
    /***
     * 物料匹配情况下查合同
     * @param list
     * @param arr
     * @return
     */
    public CoreReturnObject queryOrderCx(ArrayList<String> list,String[] arr)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.queryOrderCx");
    	sql+= CoreConverter.toSqlConditionString("T2.SALE_AREA_NO",arr);
    	//str += "AND (("+str+ " AND T2.CREATE_DEPT IS NOT NULL) OR (T2.CREATE_DEPT IS NULL))";
    	//sql += CoreConverter.toSqlConditionString("A.departid",arr);
    	sql += " ORDER BY T2.ORDER_NO,T1.ORDER_SEQ,T3.DELIVERY_NO";
    	return this.getData(sql, list.toArray());
    }
    
    /***
     * 物料匹配情况下查合同(N80Q)
     * @param list
     * @param arr
     * @return
     */
    public CoreReturnObject queryOrderCxN(ArrayList<String> list,String[] arr)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.queryOrderCxN");
    	sql+= CoreConverter.toSqlConditionString("T2.SALE_AREA_NO",arr);
    	sql += " ORDER BY T2.ORDER_NO,T1.ORDER_SEQ,T3.DELIVERY_NO";
    	return this.getData(sql, new Object[]{list.get(0),list.get(2),list.get(3)});
    }
    /***
     * 修改库存位置
     * @param parm
     * @return
     */
    public CoreReturnObject updateStoreNo(ArrayList<Object> parm)
    {
    	CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
     
        ArrayList<String> list = new ArrayList<String>();
        String sqlupdate="";
        try {
        	 connection.setAutoCommit(false); // 取消自动提交事务
        	 String updateStoreSql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateStoreNo");
        	 PreparedStatement updateStorepsta = connection.prepareStatement(updateStoreSql);
        	 String updateButessSql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateButessStoreNo");
        	 PreparedStatement updateButesspsta = connection.prepareStatement(updateButessSql);
			for (int i = 0; i < parm.size(); i++) {
				list = (ArrayList<String>)parm.get(i);
				 ArrayList<String> matNo = new ArrayList<String>();//保存材料号
				String strSql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.SelectMatNo");
				psta = connection.prepareStatement(strSql);
//				psta.setString(1, list.get(1));
//				psta.setString(2, list.get(2));
//				psta.setString(3, list.get(3));
				psta.setString(1, list.get(4));
				psta.setString(2, list.get(5));
				psta.setString(3, list.get(6));
				//psta.setString(4, list.get(7));
				psta.setString(4, list.get(7));
				psta.setString(5, list.get(8));
				psta.setString(6, list.get(9));
//				if(!list.get(11).equals("") && !list.get(12).equals(""))
//				{
//					psta.setString(7, new DecimalFormat("0.00").format(Double
//							.parseDouble(list.get(11))));
//					psta.setString(8, new DecimalFormat("0.00").format(Double
//							.parseDouble(list.get(12))));
//				}else
//				{
//					psta.setString(7, list.get(11));
//					psta.setString(8, list.get(12));
//				}
				psta.setString(7, list.get(13));
				psta.setString(8, list.get(14));
				//psta.setString(11, list.get(15));
				ResultSet rs =  psta.executeQuery();
				while(rs.next())
				{
					matNo.add(rs.getString(1));
				}
				rs.close();
				psta.close();
				if(matNo.size()>0)
				{
					for(int j=0;j<matNo.size();j++)
					{
//						String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateStoreNo");
//						psta = connection.prepareStatement(sql);
						updateStorepsta.setString(1, list.get(0));
						updateStorepsta.setString(2, matNo.get(j));
						updateStorepsta.addBatch();
						
						updateButesspsta.setString(1, list.get(0));
						updateButesspsta.setString(2, list.get(0)+"10101");
						updateButesspsta.setString(3, matNo.get(j));
						updateButesspsta.addBatch();
//						sqlupdate = "UPDATE YDM_ZC_BUTTRESS T SET T.STORAGE_NO = '"
//								+ list.get(0) + "',T.LOCATION_NO = '" + list.get(0)
//								+ "10101" + "' WHERE T.MAT_NO = '"
//								+ matNo.get(j) + "'";
//						Statement sta = connection.createStatement();
//						sta.executeUpdate(sqlupdate);
//						sta.close();
					}
				}else
				{
					cro.setV_errMsg("此炉【"+list.get(4)+"】已做提单计划,不允许修改库存地!");
					return cro;
				}
			}
			cro.setResult(1);
			updateStorepsta.executeBatch();
			updateButesspsta.executeBatch();
			connection.commit();
			cro.setV_errMsg("修改成功!");
		} 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 parm
     * @return
     */
    public CoreReturnObject updatePipMemo(ArrayList<Object> parm)
    {
    	CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
     
        ArrayList<String> list = new ArrayList<String>();
        String sqlupdate="";
        try {
        	 connection.setAutoCommit(false); // 取消自动提交事务
			for (int i = 0; i < parm.size(); i++) {
				list = (ArrayList<String>)parm.get(i);
				 ArrayList<String> matNo = new ArrayList<String>();//保存材料号
				String strSql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.SelectMatNo");
				psta = connection.prepareStatement(strSql);
//				psta.setString(1, list.get(1));
//				psta.setString(2, list.get(2));
//				psta.setString(3, list.get(3));
				psta.setString(1, list.get(4));
				psta.setString(2, list.get(5));
				psta.setString(3, list.get(6));
				//psta.setString(4, list.get(7));
				psta.setString(4, list.get(7));
				psta.setString(5, list.get(8));
				psta.setString(6, list.get(9));
				//psta.setString(7, new DecimalFormat("0.00").format(Double.parseDouble(list.get(11))));
				//psta.setString(8, new DecimalFormat("0.00").format(Double.parseDouble(list.get(12))));
				psta.setString(7, list.get(13));
				psta.setString(8, list.get(14));
				//psta.setString(11, list.get(15));
				ResultSet rs =  psta.executeQuery();
				while(rs.next())
				{
					matNo.add(rs.getString(1));
				}
				rs.close();
				psta.close();
				if(matNo.size()>0)
				{
					for(int j=0;j<matNo.size();j++)
					{
						String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updatePipMemo");
						psta = connection.prepareStatement(sql);
						psta.setString(1, list.get(0));
						psta.setString(2, matNo.get(j));
						psta.executeUpdate();
						psta.close();
					}
				}else
				{
					cro.setV_errMsg("此炉【"+list.get(4)+"】已做提单计划,不允许修改入库备注!");
					return cro;
				}
			}
			cro.setResult(1);
			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 parm
     * @return
     */
    public CoreReturnObject updateFinishedProduct(ArrayList<ArrayList<String>> parm)
    {
    	CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        ArrayList<String> list = new ArrayList<String>();
        try {
        	 connection.setAutoCommit(false); // 取消自动提交事务
        	 String updateProductSql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateFinishedProduct");
        	 PreparedStatement updateProductPsta = connection.prepareStatement(updateProductSql);
			for (int i = 0; i < parm.size(); i++) {
				list = (ArrayList<String>)parm.get(i);
				updateProductPsta.setString(1, list.get(0));
				updateProductPsta.setString(2, list.get(1));
				updateProductPsta.setString(3, list.get(2));
				updateProductPsta.setString(4, list.get(3));
				updateProductPsta.setString(5, list.get(4));
				updateProductPsta.setString(6, list.get(5));
				updateProductPsta.setString(7, list.get(6));
				updateProductPsta.addBatch();
			}
			updateProductPsta.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 parm
     * @return
     */
    public CoreReturnObject updateCarryOverDate(ArrayList<Object> parm)
    {
    	CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
     
        ArrayList<String> list = new ArrayList<String>();
        String sqlupdate="";
        try {
        	 connection.setAutoCommit(false); // 取消自动提交事务
			for (int i = 0; i < parm.size(); i++) {
				list = (ArrayList<String>)parm.get(i);
				 ArrayList<String> matNo = new ArrayList<String>();//保存材料号
				String strSql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.SelectInList");
				psta = connection.prepareStatement(strSql);
//				psta.setString(1, list.get(1));
//				psta.setString(2, list.get(2));
//				psta.setString(3, list.get(3));
				psta.setString(1, list.get(4));
				psta.setString(2, list.get(5));
				psta.setString(3, list.get(6));
				//psta.setString(4, list.get(7));
				psta.setString(4, list.get(7));
				psta.setString(5, list.get(8));
				psta.setString(6, list.get(9));
				psta.setString(7, new DecimalFormat("0.00").format(Double.parseDouble(list.get(11))));
				psta.setString(8, new DecimalFormat("0.00").format(Double.parseDouble(list.get(12))));
				psta.setString(9, list.get(13));
				psta.setString(10, list.get(14));
				ResultSet rs =  psta.executeQuery();
				while(rs.next())
				{
					matNo.add(rs.getString(1));
				}
				rs.close();
				psta.close();
				for(int j=0;j<matNo.size();j++)
				{
					String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateCarryOverDate");
					psta = connection.prepareStatement(sql);
					psta.setString(1, list.get(0));
					psta.setString(2, list.get(0)+"02"+" 12:00:00");
					psta.setString(3, matNo.get(j));
					psta.executeUpdate();
					psta.close();
					
					sqlupdate = "UPDATE MAT_ZC_M T SET T.BAL_YEAR_MONTH = '"
							+ list.get(0) + "'WHERE T.MAT_NO = '"
							+ matNo.get(j) + "'";
					Statement sta = connection.createStatement();
					sta.executeUpdate(sqlupdate);
					sta.close();
				}
			}
			cro.setResult(1);
			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 departNo
     * @return
     */
    public CoreReturnObject querySaleOrg(String departNo)
    {
    	return this.getDataBySqlID("CorePipeInTemp.querySaleOrg", new Object[]{departNo});
    }
    /**
     * 材料查询
     * @param time1 开始时间
     * @param time2 结束时间
     * @return 平台统一返回对象
     */
    public CoreReturnObject getStoveNo(String time1, String time2) {
        Object[] obj = new Object[] { time1, time2 };
        String sql = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.GetStoveNo");
        return this.getData("MSSQL1Dao", sql, obj);
    }

    /**
     * 查询合同号
     * @return 平台统一返回对象
     */
    public CoreReturnObject getOrderNo() {
        return this.getDataBySqlID("CorePipeInTemp.GetOrderNo");
    }

    /**
     * 查询质量判定数据
     * @param parm 参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryMatData(ArrayList<Object> parm,String[] arr) {

        String timestart = parm.get(0).toString();
        String timeend = parm.get(1).toString();
        String lcode = parm.get(2).toString();
        //String lotno = parm.get(3).toString();
        String order = parm.get(3).toString();
        String stu = parm.get(4).toString();
        String[] arg = new String[3];
        String sql = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.QueryMatData");
        String str = "";
        if(arr.length>0)
        {
        	for(int i=0;i<arr.length;i++)
        	{
        		if(arr[i].equals("100102"))
        		{
        			if(arr.length>1)
        			{
        				//bb = "T.DEPARTM is null";
        				//sql += "("+aa+"or"+bb+")";
        				str= " AND (T.DEPARTM is null or T.DEPARTM LIKE '%国贸%')";
        				
        			}else
        			{
        				str= " AND T.DEPARTM LIKE '%国贸%'";
        			}
        			break;
        		}else
        		{
        			str = " AND T.DEPARTM is null";
        		}
        	}
        }
        sql +=str;
        //sql +=CoreConverter.toSqlConditionString("T.DEPARTM", arg);
        if(!(timestart.equals("") && timeend.equals("")))
        {
        sql += " and  t.testdate >= '" + timestart + "' and t.testdate <= '"
                + timeend + "'";
        }
        sql += " and upper(t.lcode)  LIKE upper('%" + lcode + "%')";
        //sql += " and t.lotno  LIKE '" + lotno + "%'";
        sql += " and t.cxstu!='20'";
        sql += " and upper(t.ordername) LIKE upper('%" + order+ "%')";
        sql += " and t.cxstu LIKE '" + stu + "%'";
        
        sql += "order by t.testdate,t.ordername";

        return this.getData("MSSQL1Dao", sql);
    }

    /***
     * 查询是否已缴库
     * @param ordername
     * @return
     */
    public CoreReturnObject getSqlServerStaus(String ordername,String heatNo,String lotNo,String unit,String wgt,String rccid)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.getSqlServerStaus");
    	sql +=" where T.ordername = '"+ordername+"'";
    	sql +=" and T.lcode = '"+heatNo+"'";
    	sql +=" and T.lotno = '"+lotNo+"'";
    	sql +=" and T.hgunit = '"+unit+"'";
    	sql +=" and T.hgweight = '"+wgt+"'";
    	sql +=" and T.rcdid = '"+ rccid+"'";
    	return this.getData("MSSQL1Dao", sql);
    }
    /**
     * 查询仓库号
     * @return 平台统一返回对象
     */
    public CoreReturnObject getStorageDetail() {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.GetStorageDetail");
    	sql += " order by STORAGE_NO,STORAGE_NAME asc";
        return this.getData(sql);

    }


	/**
	 * 查询仓库号
	 * @return 平台统一返回对象
	 */
	public CoreReturnObject getStorageDetail1(ArrayList<String> parm) {
		String strArea = "";
		if(parm.get(0).equals("120504"))
		{
			strArea = "1";
		}
		String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.GetStorageDetail");
		if(!strArea.equals(""))
		{
			sql += " AND SEAM_AREA = '"+strArea+"'";
		}
		sql += " order by STORAGE_NO,STORAGE_NAME asc";
		return this.getData(sql);
	}
    /**
     * 查询产线
     * @return 平台统一返回对象
     */
    public CoreReturnObject getFactoryDetail() {
        return this.getDataBySqlID("CorePipeInTemp.getFactoryDetail");
    }
    /**
     * 查询钢种
     * @return 平台统一返回对象
     */
    public CoreReturnObject getGradeDetail() {
        return this.getDataBySqlID("CorePipeInTemp.getGradeDetail");
    }
    /**
     * 查询该合同是否做计划
     * @param strorderno 合同号
     * @param strOrderSeq 合同行号
     * @param strDevNO 交货行
     * @return 平台统一返回对象
     */
    public CoreReturnObject querySendPlan(String strorderno,
            String strOrderSeq, String strDevNO) {
        return this.getDataBySqlID("CorePipeInTemp.QuerySendPlan",
                new Object[] { strorderno, strOrderSeq, strDevNO });
    }

    /**
     * 相同合同号的数据
     * @param parm 时间
     * @return 平台统一返回对象
     */
    public CoreReturnObject querySameOrderNoData(ArrayList<Object> parm) {
        Object[] obj = parm.toArray();
        String sql = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.QuerySameOrderNoData");
        return this.getData("MSSQL1Dao", sql, obj);
    }

    /**
     * 根据炉号、批号自动生成材料号
     * @param conn c
     * @param strLcode 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String queryMatNo(Connection conn, String strLcode, String strBatch)
            throws Exception {
        int count = 0;
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.QueryMatNo");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strLcode);
        psta.setString(2, strBatch);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            String res = rs.getString(1);
            if (res == null) {
                res = strLcode + strBatch + "0001";
            }
            else {
                count = Integer.parseInt(res.substring(res.length() - 4, res
                        .length()));
            }
        }
        rs.close();
        psta.close();
        return (strLcode + strBatch)
                + StringTool.formatDecimal(++count, "0000");
    }

    /**
     * 根据炉号、批号自动生成材料号
     * @param conn c
     * @param strLcode 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String queryMatNoM(Connection conn, String strLcode, String strBatch)
            throws Exception {
        int count = 0;
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.QueryMatNoM");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strLcode);
        psta.setString(2, strBatch);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            String res = rs.getString(1);
            if (res == null) {
                res = strLcode + strBatch + "0001";
            }
            else {
                count = Integer.parseInt(res.substring(res.length() - 4, res
                        .length()));
            }
        }
        rs.close();
        psta.close();
        return (strLcode + strBatch)
                + StringTool.formatDecimal(++count, "0000");
    }

    /**
     * 根据炉号、批号自动生成材料号
     * @param conn c
     * @param strLcode 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String queryMatNoM1(Connection conn, String strLcode, String strBatch)
            throws Exception {
        String matNo = "";
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.QueryMatNoM1");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strLcode);
        psta.setString(2, strBatch);
        psta.setString(3, strLcode);
        psta.setString(4, strBatch);
        psta.setString(5, strLcode);
        psta.setString(6, strBatch);
        psta.setString(7, strLcode);
        psta.setString(8, strBatch);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
        	matNo = rs.getString("MAT_NO");
        }
        rs.close();
        psta.close();
        return matNo;
    }
    
    /**
     * 根据炉号、批号自动生成材料号(入库表中)
     * @param conn c
     * @param strLcode 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String queryInListMatNoM(Connection conn, String strLcode, String strBatch)
            throws Exception {
        int count = 0;
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.queryInListMatNoM");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strLcode);
        psta.setString(2, strBatch);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            String res = rs.getString(1);
            if (res == null) {
                res = strLcode + strBatch + "0001";
            }
            else {
                count = Integer.parseInt(res.substring(res.length() - 4, res
                        .length()));
            }
        }
        rs.close();
        psta.close();
        return (strLcode + strBatch)
                + StringTool.formatDecimal(++count, "0000");
    }
    
    /**
     * 根据炉号、批号自动组号
     * @param conn c
     * @param strLcode 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String queryGroupNo(Connection conn, String strLcode, String strBatch)
            throws Exception {
        int count = 0;
        String groupNo = "";
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.queryGroupNo");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strLcode);
        psta.setString(2, strBatch);
        psta.setString(3, strLcode);
        psta.setString(4, strBatch);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
//            String res = rs.getString(1);
//            if (res == null) {
//                res = "001";
//            }
//            else {
//                count = Integer.parseInt(res.substring(res.length() - 3, res
//                        .length()));
//            }
        	groupNo = rs.getString("BATCH_GROUD_NO");
        }
        rs.close();
        psta.close();
        //return StringTool.formatDecimal(++count, "000");
        return groupNo;
    }
    
    /**
     * 根据炉号、批号自动组号
     * @param conn c
     * @param strLcode 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String queryGroupNoButress(Connection conn, String strLcode, String strBatch)
            throws Exception {
        int count = 0;
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.queryGroupNoButress");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strLcode);
        psta.setString(2, strBatch);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            String res = rs.getString(1);
            if (res == null) {
                res = "001";
            }
            else {
                count = Integer.parseInt(res.substring(res.length() - 3, res
                        .length()));
            }
        }
        rs.close();
        psta.close();
        return StringTool.formatDecimal(++count, "000");
    }
    
    /**
     * 根据炉号、批号自动组号(入库表)
     * @param conn c
     * @param strLcode 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String queryInListGroupNo(Connection conn, String strLcode, String strBatch)
            throws Exception {
        int count = 0;
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.queryInListGroupNo");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strLcode);
        psta.setString(2, strBatch);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            String res = rs.getString(1);
            if (res == null) {
                res = "001";
            }
            else {
                count = Integer.parseInt(res.substring(res.length() - 3, res
                        .length()));
            }
        }
        rs.close();
        psta.close();
        return StringTool.formatDecimal(++count, "000");
    }
    
    /***
     * 查询入库单号
     * @param list
     * @return
     */
    public CoreReturnObject getInListDoc(ArrayList<String> list)
    {
       return this.getDataBySqlID("CorePipeInTemp.getInListDoc", list.toArray());	
    }
    
    /**
     * 每支材料对应的入库流水号
     * @param conn c
     * @param strlist 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String querySendSql(Connection conn, String strlist)
            throws Exception {
        int seq = 0;
        String inListDocSeq = "";
         PreparedStatement psta = null;
         Date dt = new Date();
         SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.getInListDoc1");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strlist);
        psta.setString(2, strlist);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
//            String res = rs.getString(1);
//            if (res == null) {
//                res = strlist + "0001";
//            }
//            else {
//                seq = Integer.parseInt(res.substring(13, 17));
//            }
        	inListDocSeq = rs.getString("INSTOCK_SQE");
        }
        rs.close();
        psta.close();
        //return strlist + StringTool.formatDecimal(++seq, "0000");
        return inListDocSeq;
    }
    
    
    /**
     * 每支材料对应的入库单号
     * @param conn c
     * @param strlist 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String querySendSqlDoc(Connection conn, String strlist,String memo)
            throws Exception {
        int seq = 0;
        String inListDoc = "";
         PreparedStatement psta = null;
         Date dt = new Date();
         SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
         SimpleDateFormat matter2 = new SimpleDateFormat("yyMMdd");
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("CorePipeInTemp.getInListDocNew");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, memo);
        psta.setString(2, strlist);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
//            String res = rs.getString(1);
//            if (res == null) {
//                res = memo + matter2.format(dt) + "00001";
//            }
//            else {
//                seq = Integer.parseInt(res.substring(8, 13));
//            }
        	inListDoc = rs.getString("INSTOCK_DOC");
        }
        rs.close();
        psta.close();
        //return  memo + matter2.format(dt) + StringTool.formatDecimal(++seq, "00000");
        return inListDoc;
    }
    
    /**
     * 缴库
     * @param parm1 参数
     * @param parm2 参数
     * @param parm3 参数
     * @param parm4 参数
     * @return 平台统一返回对象
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject doPipeIn(ArrayList<Object> parm1,
            ArrayList<Object> parm2, ArrayList<Object> parm3,
            ArrayList<Object> parm4) {
    	CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Connection con = this.getDao("MSSQL1Dao").getConnection();
        PreparedStatement psta = null;
        ResultSet rs = null;
        Date now = new Date();
        String inListDoc = "";
        String groupNo = "";
        String butessMatNo = "";
        String materialCode = "";//物料码
        String materialName = "";//物料描述
        String materialCount = "";
        //Map<Object, Object> result = null;
        Map result = null;
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
        String systime = dateFormat.format(now);
        String yearMoth = df.format(now);
        String sql = "";
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            ArrayList<Object> sqlIDList = new ArrayList<Object>();
            ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
            
           String InsertButtresssql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.InsertButtress");
           PreparedStatement InsertButtresspsta = connection.prepareStatement(InsertButtresssql);
           
           String insertMat2sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.INSERTMAT2");
           PreparedStatement insertMat2psta = connection.prepareStatement(insertMat2sql);
           String insertMat2sqlXs = CoreXmlSqlParsersFactory.getSql("CorePipeInTempXs.INSERTMAT2");
           PreparedStatement insertMat2pstaXs = connection.prepareStatement(insertMat2sqlXs);
           
           String insertInlist1sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.insertInList1");
           PreparedStatement insertInlist1psta = connection.prepareStatement(insertInlist1sql);
           
           String insertInlist1sqlXs = CoreXmlSqlParsersFactory.getSql("CorePipeInTempXs.insertInList1");
           PreparedStatement insertInlist1pstaXs = connection.prepareStatement(insertInlist1sqlXs);
           
           String insertMatsql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.INSERTMAT");
           PreparedStatement insertMatpsta = connection.prepareStatement(insertMatsql);
           
           String insertMatsqlXs = CoreXmlSqlParsersFactory.getSql("CorePipeInTempXs.INSERTMAT");
           PreparedStatement insertMatpstaXs = connection.prepareStatement(insertMatsqlXs);
           
           String insertInlistsql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.insertInList");
           PreparedStatement insertInlistpsta = connection.prepareStatement(insertInlistsql);
           
           String insertInlistsqlXs = CoreXmlSqlParsersFactory.getSql("CorePipeInTempXs.insertInList");
           PreparedStatement insertInlistpstaXs = connection.prepareStatement(insertInlistsqlXs);
           
           String insertMat1sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.INSERTMAT1");
           PreparedStatement insertMat1psta = connection.prepareStatement(insertMat1sql);
           String insertMat1sqlXs = CoreXmlSqlParsersFactory.getSql("CorePipeInTempXs.INSERTMAT1");
           PreparedStatement insertMat1pstaXs = connection.prepareStatement(insertMat1sqlXs);
           String updatePln1sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updatePln1");
           PreparedStatement updatePln1psta = connection.prepareStatement(updatePln1sql);
           
           String updateProcess = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateProcess");
           PreparedStatement updateProcesspsta = connection.prepareStatement(updateProcess); //update进程表
           
           String updateSqlserver =  CoreXmlSqlParsersFactory
			.getSql("CorePipeInTemp.UPDATEINTERFACE");
           PreparedStatement updateSqlserverpsta = con.prepareStatement(updateSqlserver);
           String updateMaterialSql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateMaterial");
           PreparedStatement updateMaterialpsta = connection.prepareStatement(updateMaterialSql);
//           sql = CoreXmlSqlParsersFactory
//			.getSql("CorePipeInTemp.insertInList1");
//	insertMat1psta = connection.prepareStatement(sql);
            for (int i = 0; i < parm1.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) parm1.get(i);
                int count = Integer.parseInt(list.get(2).toString());
                String lcode = list.get(0).toString();
                String lotno = list.get(1).toString();
                //double strWgt = Double.parseDouble(list.get(8).toString());
                //butessMatNo = queryMatNo(connection, lcode, lotno);
                butessMatNo = queryMatNoM1(connection, lcode, lotno);
                int m = Integer.parseInt(butessMatNo.substring(butessMatNo.length() - 4, butessMatNo
                        .length()));
                //String groupNoButess = queryGroupNoButress(connection,list.get(0),list.get(1));
                String groupNoButess = queryGroupNo(connection,list.get(0),list.get(1));
                //groupNo = queryGroupNo(connection,list.get(0),list.get(1));
				for (int j = 0; j < count; j++) {
					InsertButtresspsta.setString(1, list.get(0));
					InsertButtresspsta.setString(2, list.get(1));
					InsertButtresspsta.setString(3, groupNoButess);
					InsertButtresspsta.setString(4, list.get(3));
					InsertButtresspsta.setString(5, list.get(4));
					InsertButtresspsta.setString(6, list.get(5));
					InsertButtresspsta.setString(7, list.get(6));
					InsertButtresspsta.setString(8, list.get(7));
					InsertButtresspsta.setString(9, (lcode + lotno)
							+ StringTool.formatDecimal(m, "0000"));
					InsertButtresspsta.setString(10, systime);
					InsertButtresspsta.setString(11, list.get(9));
					InsertButtresspsta.setString(12, list.get(10));
					InsertButtresspsta.setString(13, list.get(11));
					InsertButtresspsta.setString(14, list.get(12));
					InsertButtresspsta.addBatch();
//					InsertButtresspsta.executeUpdate();
//					InsertButtresspsta.close();
					m++;
				}
            }
            
            int allCount = 0;
            double htWgt = 0;
            double htLen = 0;
            // 这里获取了系统时间，不用数据库的SYSDATE，是因为数据可能太多，执行时间过长，导致缴库时间会有差异。
            for (int i = 0; i < parm2.size(); i++) {
            	ArrayList<String> list2 = (ArrayList<String>) parm2.get(i);
            	inListDoc = querySendSqlDoc(connection,list2.get(38),list2.get(35));
            	groupNo = queryGroupNo(connection,list2.get(0),list2.get(1));
                // int count = Integer.parseInt(list2.get(2).toString());
            	ArrayList<String> materialList = new ArrayList<String>();
            	materialList.add(list2.get(3));
            	materialList.add(list2.get(4));
            	materialList.add(list2.get(7));
            	materialList.add(list2.get(8));
            	materialList.add(list2.get(15));
            	materialList.add(list2.get(16));
            	materialList.add(list2.get(5));
            	materialList.add(list2.get(6));
            	materialList.add(list2.get(9));
            	materialList.add(list2.get(10));
            	String[] materialS = FrmEndMaterial.formEndMaterial(materialList, connection);
            	if(materialS == null)
            	{
            		cro.setV_errMsg("无产品大类基础信息,需维护产品基础信息!");
            		return cro;
            	}else
            	{
            		sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.SelectMaterialCode");
            		psta = connection.prepareStatement(sql);
            		psta.setString(1, materialS[0].toString());
            		rs = psta.executeQuery();
            		if(rs.next())
            		{
            			materialCount = rs.getString("ACOUNT");
            			if(Integer.parseInt(materialCount)>0)
            			{
            				updateMaterialpsta.setString(1, materialS[0].toString());
            				updateMaterialpsta.addBatch();
            			}
            		}
            		rs.close();
            		psta.close();
            	}
                String lcode = list2.get(0).toString();
                String lotno = list2.get(1).toString();
                int acb = Integer.parseInt(list2.get(42).toString());
                List<double[]> list = MeanValueCalculation.MeanCalculation(
                        Double.parseDouble(list2.get(34)), Integer
                                .parseInt(list2.get(2)));
                ArrayList<String> lengthList = null;
                if(!list2.get(44).equals(""))
                {
                	lengthList = new ArrayList<String>();
                    List<double[]> lenList = MeanValueCalculation.MeanCalculation(Double.parseDouble(list2.get(44)), Integer.parseInt(list2.get(2)));
                    for(int k = 0;k<lenList.size();k++)
                    {
                    	double[] conLen = lenList.get(k);
                    	if((int)conLen[0]>0)
                    	{
                    		for(int x = 0;x<(int)conLen[0];x++)
                    		{
                    			DecimalFormat dt = new DecimalFormat("0.000");
                    			lengthList.add(dt.format(conLen[1]));
                    		}
                    	}
                    }
                }
                 
                
                String matNo = queryMatNoM1(connection, lcode, lotno); //材料号
                int g = Integer.parseInt(matNo.substring(matNo.length() - 4, matNo.length()));
                String inListSeq = querySendSql(connection,inListDoc); //入库流水号
                int n = Integer.parseInt(inListSeq.substring(inListSeq.length() - 4, inListSeq.length()));
                for (int j = 0; j < list.size(); j++) {
                    double[] conW = list.get(j);
                    if ((int) conW[0] >= 0) {
						for (int z = 0; z < (int) conW[0]; z++) {
							if (list2.get(17).equals("")) {
								htWgt += Double.parseDouble(String
										.valueOf(conW[1]));
								insertMat2psta.setString(1, list2.get(0));
								insertMat2psta.setString(2, list2.get(1));
								insertMat2psta.setString(3, groupNo);
								insertMat2psta.setString(4, list2.get(3));
								insertMat2psta.setString(5, list2.get(4));
								insertMat2psta.setString(6, list2.get(5));
								insertMat2psta.setString(7, list2.get(6));
								insertMat2psta.setString(8, list2.get(7));
								insertMat2psta.setString(9, list2.get(8));
								insertMat2psta.setString(10, list2.get(9));
								insertMat2psta.setString(11, list2.get(10));
								insertMat2psta.setString(12, list2.get(11));
								insertMat2psta.setString(13, list2.get(12));

								insertMat2psta.setString(14, list2.get(40));
								insertMat2psta.setString(15, list2.get(41));

								insertMat2psta.setString(16, list2.get(15));
								insertMat2psta.setString(17, list2.get(16));

								insertMat2psta.setString(18, list2.get(17));
								insertMat2psta.setString(19, list2.get(18));
								insertMat2psta.setString(20, list2.get(19));

								insertMat2psta.setString(21, list2.get(20));
								insertMat2psta.setString(22, list2.get(21));
								insertMat2psta.setString(23, list2.get(22));
								insertMat2psta.setString(24, list2.get(23));
								insertMat2psta.setString(25, list2.get(24));
								// insertMat2psta.setString(26, list2.get(25));
								insertMat2psta.setString(26, list2.get(25));
								insertMat2psta.setString(27, list2.get(26));
								insertMat2psta.setString(28, list2.get(27));
								insertMat2psta.setString(29, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
								insertMat2psta.setString(30, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
								insertMat2psta.setString(31, list2.get(30));

								insertMat2psta.setString(32, list2.get(32));
								insertMat2psta.setObject(33, conW[1]);// 重量
								insertMat2psta.setString(34, systime);
								insertMat2psta.setString(35, systime);
								insertMat2psta.setString(36, (lcode + lotno)
							                + StringTool.formatDecimal(g, "0000"));
								insertMat2pstaXs.setString(1, list2.get(0));
								insertMat2pstaXs.setString(2, list2.get(1));
								insertMat2pstaXs.setString(3, groupNo);
								insertMat2pstaXs.setString(4, list2.get(3));
								insertMat2pstaXs.setString(5, list2.get(4));
								insertMat2pstaXs.setString(6, list2.get(5));
								insertMat2pstaXs.setString(7, list2.get(6));
								insertMat2pstaXs.setString(8, list2.get(7));
								insertMat2pstaXs.setString(9, list2.get(8));
								insertMat2pstaXs.setString(10, list2.get(9));
								insertMat2pstaXs.setString(11, list2.get(10));
								insertMat2pstaXs.setString(12, list2.get(11));
								insertMat2pstaXs.setString(13, list2.get(12));

								insertMat2pstaXs.setString(14, list2.get(40));
								insertMat2pstaXs.setString(15, list2.get(41));

								insertMat2pstaXs.setString(16, list2.get(15));
								insertMat2pstaXs.setString(17, list2.get(16));

								insertMat2pstaXs.setString(18, list2.get(17));
								insertMat2pstaXs.setString(19, list2.get(18));
								insertMat2pstaXs.setString(20, list2.get(19));

								insertMat2pstaXs.setString(21, list2.get(20));
								insertMat2pstaXs.setString(22, list2.get(21));
								insertMat2pstaXs.setString(23, list2.get(22));
								insertMat2pstaXs.setString(24, list2.get(23));
								insertMat2pstaXs.setString(25, list2.get(24));
								// insertMat2pstaXs.setString(26, list2.get(25));
								insertMat2pstaXs.setString(26, list2.get(25));
								insertMat2pstaXs.setString(27, list2.get(26));
								insertMat2pstaXs.setString(28, list2.get(27));
								insertMat2pstaXs.setString(29, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
								insertMat2pstaXs.setString(30, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
								insertMat2pstaXs.setString(31, list2.get(30));

								insertMat2pstaXs.setString(32, list2.get(32));
								insertMat2pstaXs.setObject(33, conW[1]);// 重量
								insertMat2pstaXs.setString(34, systime);
								insertMat2pstaXs.setString(35, systime);
								insertMat2pstaXs.setString(36, (lcode + lotno)
							                + StringTool.formatDecimal(g, "0000"));
								//insertMat2psta.setString(36, matNo);
								insertMat2psta.setString(37, list2.get(33));
								insertMat2pstaXs.setString(37, list2.get(33));

								if (!list2.get(44).equals("")) {
									insertMat2psta.setString(38, lengthList.get(allCount));
									insertMat2pstaXs.setString(38, lengthList.get(allCount));

								} else {
									insertMat2psta.setString(38, "");
									insertMat2pstaXs.setString(38, "");

								}
								insertMat2psta.setString(39, list2.get(47));
								insertMat2psta.setString(40, yearMoth);//结转年月
								insertMat2psta.setObject(41, list2.get(49));
								insertMat2psta.setString(42, list2.get(50));

								insertMat2psta.setString(43, list2.get(51));
								insertMat2psta.setString(44, list2.get(52));
								
								insertMat2psta.setString(45, list2.get(53));
								insertMat2psta.setString(46, list2.get(54));
								insertMat2psta.setString(47, list2.get(48));
								
								insertMat2psta.setString(48, list2.get(55));
								insertMat2psta.setString(49, list2.get(56));
								insertMat2psta.setString(50, list2.get(49));
								insertMat2psta.setString(51, list2.get(50));
								insertMat2psta.setString(52, materialS[0].toString());//物料码
								insertMat2psta.setString(53, materialS[1].toString());
								insertMat2psta.setString(54, list2.get(57));
								insertMat2psta.setString(55, list2.get(58));
								insertMat2psta.addBatch();
								
								insertMat2pstaXs.setString(39, list2.get(47));
								insertMat2pstaXs.setString(40, yearMoth);//结转年月
								insertMat2pstaXs.setObject(41, list2.get(49));
								insertMat2pstaXs.setString(42, list2.get(50));

								insertMat2pstaXs.setString(43, list2.get(51));
								insertMat2pstaXs.setString(44, list2.get(52));
								
								insertMat2pstaXs.setString(45, list2.get(53));
								insertMat2pstaXs.setString(46, list2.get(54));
								insertMat2pstaXs.setString(47, list2.get(48));
								
								insertMat2pstaXs.setString(48, list2.get(55));
								insertMat2pstaXs.setString(49, list2.get(56));
								insertMat2pstaXs.setString(50, list2.get(49));
								insertMat2pstaXs.setString(51, list2.get(50));
								insertMat2pstaXs.setString(52, materialS[0].toString());//物料码
								insertMat2pstaXs.setString(53, materialS[1].toString());
								insertMat2pstaXs.setString(54, list2.get(57));
								insertMat2pstaXs.setString(55, list2.get(58));
								insertMat2pstaXs.addBatch();
//								insertMat2psta.executeUpdate();
//								insertMat2psta.close();

								// 对缴库实绩表进行操作
								
								insertInlist1psta.setString(1, list2.get(36));
								insertInlist1psta.setString(2, list2.get(37));
								
							    insertInlist1psta.setString(3, inListDoc
						                + StringTool.formatDecimal(n, "0000"));
//								insertInlist1psta.setString(3, querySendSql(connection,
//										inListDoc));
								insertInlist1psta.setString(4, inListDoc);
								insertInlist1psta.setString(5, list2.get(38));
								insertInlist1psta.setString(6, "产出入库");
								
								insertInlist1psta.setString(7, (lcode + lotno)
						                + StringTool.formatDecimal(g, "0000"));
								//insertInlist1psta.setString(7, matNo);
								insertInlist1psta.setString(8, "");// 生产批号
								insertInlist1psta.setString(9, "");
								insertInlist1psta.setString(10, lcode);
								insertInlist1psta.setString(11, lotno);
								insertInlist1psta.setString(12, groupNo);// 组号
								insertInlist1psta.setString(13, list2.get(3));// 品名
								insertInlist1psta.setString(14, list2.get(4));

								insertInlist1psta.setString(15, list2.get(11));// 标准
								insertInlist1psta.setString(16, list2.get(12));

								insertInlist1psta.setString(17, list2.get(5));// 钢级
								insertInlist1psta.setString(18, list2.get(6));

								insertInlist1psta.setString(19, list2.get(15));// 标准类别
								insertInlist1psta.setString(20, list2.get(16));

								insertInlist1psta.setString(21, list2.get(7));// 产品规格
								insertInlist1psta.setString(22, list2.get(8));

								insertInlist1psta.setString(23, list2.get(9));// 扣型
								insertInlist1psta.setString(24, list2.get(10));

								insertInlist1psta.setString(25, list2.get(23));
								insertInlist1psta.setString(26, list2.get(24));// 外径壁厚
								insertInlist1psta.setString(27, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
								insertInlist1psta.setString(28, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
								insertInlist1psta.setString(29, "1");
								insertInlist1psta.setString(30, String.valueOf(conW[1]));
								// insertInlist1psta.setString(26, list2.get(24));
								insertInlist1psta.setString(31, "");// 理论重量
								insertInlist1psta.setString(32, list2.get(40));
								insertInlist1psta.setString(33, list2.get(41));
								insertInlist1psta.setString(34, list2.get(39));
								insertInlist1psta.setString(35, list2.get(33));
								insertInlist1psta.setString(36, "1");
								insertInlist1psta.setString(37, list2.get(30));

								insertInlist1psta.setString(38, systime);
								insertInlist1psta.setString(39, list2.get(17));
								insertInlist1psta.setString(40, list2.get(18));
								insertInlist1psta.setString(41, list2.get(19));

								insertInlist1psta.setString(42, list2.get(20));
								insertInlist1psta.setString(43, list2.get(21));
								insertInlist1psta.setString(44, list2.get(22));
								insertInlist1psta.setString(45, systime);
								insertInlist1psta.setString(46, list2.get(43));
								

								insertInlist1pstaXs.setString(1, list2.get(36));
								insertInlist1pstaXs.setString(2, list2.get(37));
								
							    insertInlist1pstaXs.setString(3, inListDoc
						                + StringTool.formatDecimal(n, "0000"));
//								insertInlist1pstaXs.setString(3, querySendSql(connection,
//										inListDoc));
								insertInlist1pstaXs.setString(4, inListDoc);
								insertInlist1pstaXs.setString(5, list2.get(38));
								insertInlist1pstaXs.setString(6, "产出入库");
								
								insertInlist1pstaXs.setString(7, (lcode + lotno)
						                + StringTool.formatDecimal(g, "0000"));
								//insertInlist1pstaXs.setString(7, matNo);
								insertInlist1pstaXs.setString(8, "");// 生产批号
								insertInlist1pstaXs.setString(9, "");
								insertInlist1pstaXs.setString(10, lcode);
								insertInlist1pstaXs.setString(11, lotno);
								insertInlist1pstaXs.setString(12, groupNo);// 组号
								insertInlist1pstaXs.setString(13, list2.get(3));// 品名
								insertInlist1pstaXs.setString(14, list2.get(4));

								insertInlist1pstaXs.setString(15, list2.get(11));// 标准
								insertInlist1pstaXs.setString(16, list2.get(12));

								insertInlist1pstaXs.setString(17, list2.get(5));// 钢级
								insertInlist1pstaXs.setString(18, list2.get(6));

								insertInlist1pstaXs.setString(19, list2.get(15));// 标准类别
								insertInlist1pstaXs.setString(20, list2.get(16));

								insertInlist1pstaXs.setString(21, list2.get(7));// 产品规格
								insertInlist1pstaXs.setString(22, list2.get(8));

								insertInlist1pstaXs.setString(23, list2.get(9));// 扣型
								insertInlist1pstaXs.setString(24, list2.get(10));

								insertInlist1pstaXs.setString(25, list2.get(23));
								insertInlist1pstaXs.setString(26, list2.get(24));// 外径壁厚
								insertInlist1pstaXs.setString(27, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
								insertInlist1pstaXs.setString(28, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
								insertInlist1pstaXs.setString(29, "1");
								insertInlist1pstaXs.setString(30, String.valueOf(conW[1]));
								// insertInlist1pstaXs.setString(26, list2.get(24));
								insertInlist1pstaXs.setString(31, "");// 理论重量
								insertInlist1pstaXs.setString(32, list2.get(40));
								insertInlist1pstaXs.setString(33, list2.get(41));
								insertInlist1pstaXs.setString(34, list2.get(39));
								insertInlist1pstaXs.setString(35, list2.get(33));
								insertInlist1pstaXs.setString(36, "1");
								insertInlist1pstaXs.setString(37, list2.get(30));

								insertInlist1pstaXs.setString(38, systime);
								insertInlist1pstaXs.setString(39, list2.get(17));
								insertInlist1pstaXs.setString(40, list2.get(18));
								insertInlist1pstaXs.setString(41, list2.get(19));

								insertInlist1pstaXs.setString(42, list2.get(20));
								insertInlist1pstaXs.setString(43, list2.get(21));
								insertInlist1pstaXs.setString(44, list2.get(22));
								insertInlist1pstaXs.setString(45, systime);
								insertInlist1pstaXs.setString(46, list2.get(43));
								
								if (!list2.get(44).equals("")) {
									insertInlist1psta
											.setString(47, lengthList
													.get(allCount));
									insertInlist1pstaXs
									.setString(47, lengthList
											.get(allCount));
								} else {
									insertInlist1psta.setString(47, "0");
									insertInlist1pstaXs.setString(47, "0");

								}
								insertInlist1psta.setString(48, list2.get(45));
								insertInlist1psta.setString(49, list2.get(46));
								insertInlist1psta.setString(50, list2.get(47));
								insertInlist1psta.setString(51, list2.get(49));
								insertInlist1psta.setString(52, list2.get(50));
								insertInlist1psta.setString(53, list2.get(51));
								insertInlist1psta.setString(54, list2.get(52));

								insertInlist1psta.setString(55, yearMoth);//结转年月
								insertInlist1psta.setString(56, systime);
								insertInlist1psta.setString(57, list2.get(53));
								//insertInlist1psta.setString(58, list2.get(54));
								insertInlist1psta.setString(58, list2.get(55));
								insertInlist1psta.setString(59, list2.get(56));
								insertInlist1psta.setString(60, list2.get(49));
								insertInlist1psta.setString(61, list2.get(50));
								insertInlist1psta.setString(62, materialS[0].toString());//物料码
								insertInlist1psta.setString(63, materialS[1].toString());
								insertInlist1psta.setString(64, list2.get(58));
								insertInlist1psta.setString(65, list2.get(57));
								insertInlist1psta.addBatch();
								
								insertInlist1pstaXs.setString(48, list2.get(45));
								insertInlist1pstaXs.setString(49, list2.get(46));
								insertInlist1pstaXs.setString(50, list2.get(47));
								insertInlist1pstaXs.setString(51, list2.get(49));
								insertInlist1pstaXs.setString(52, list2.get(50));
								insertInlist1pstaXs.setString(53, list2.get(51));
								insertInlist1pstaXs.setString(54, list2.get(52));

								insertInlist1pstaXs.setString(55, yearMoth);//结转年月
								insertInlist1pstaXs.setString(56, systime);
								insertInlist1pstaXs.setString(57, list2.get(53));
								//insertInlist1pstaXs.setString(58, list2.get(54));
								insertInlist1pstaXs.setString(58, list2.get(55));
								insertInlist1pstaXs.setString(59, list2.get(56));
								insertInlist1pstaXs.setString(60, list2.get(49));
								insertInlist1pstaXs.setString(61, list2.get(50));
								insertInlist1pstaXs.setString(62, materialS[0].toString());//物料码
								insertInlist1pstaXs.setString(63, materialS[1].toString());
								insertInlist1pstaXs.setString(64, list2.get(58));
								insertInlist1pstaXs.setString(65, list2.get(57));
								insertInlist1pstaXs.addBatch();
								
								//insertInlist1psta.executeUpdate();
								//insertInlist1psta.close();
							} else {
								if (allCount < acb) {
									htWgt += Double.parseDouble(String
											.valueOf(conW[1]));
									if(!list2.get(44).equals(""))
									{
										htLen += Double.parseDouble(lengthList.get(allCount));
									}
									insertMatpsta.setString(1, list2.get(0));
									insertMatpsta.setString(2, list2.get(1));
									insertMatpsta.setString(3, groupNo);
									insertMatpsta.setString(4, list2.get(3));
									insertMatpsta.setString(5, list2.get(4));
									insertMatpsta.setString(6, list2.get(5));
									insertMatpsta.setString(7, list2.get(6));
									insertMatpsta.setString(8, list2.get(7));
									insertMatpsta.setString(9, list2.get(8));
									insertMatpsta.setString(10, list2.get(9));
									insertMatpsta.setString(11, list2.get(10));
									insertMatpsta.setString(12, list2.get(11));
									insertMatpsta.setString(13, list2.get(12));

									insertMatpsta.setString(14, list2.get(40));
									insertMatpsta.setString(15, list2.get(41));

									insertMatpsta.setString(16, list2.get(15));
									insertMatpsta.setString(17, list2.get(16));

									insertMatpsta.setString(18, list2.get(17));
									insertMatpsta.setString(19, list2.get(18));
									insertMatpsta.setString(20, list2.get(19));

									insertMatpsta.setString(21, list2.get(20));
									insertMatpsta.setString(22, list2.get(21));
									insertMatpsta.setString(23, list2.get(22));
									insertMatpsta.setString(24, list2.get(23));
									insertMatpsta.setString(25, list2.get(24));
									// insertMatpsta.setString(26, list2.get(25));
									insertMatpsta.setString(26, list2.get(25));
									insertMatpsta.setString(27, list2.get(26));
									insertMatpsta.setString(28, list2.get(27));
									insertMatpsta.setString(29, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
									insertMatpsta.setString(30, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
									insertMatpsta.setString(31, list2.get(30));

									insertMatpsta.setString(32, list2.get(32));
									insertMatpsta.setObject(33, conW[1]);// 重量
									insertMatpsta.setString(34, systime);
									insertMatpsta.setString(35, systime);
									insertMatpsta.setString(36, (lcode + lotno)
							                + StringTool.formatDecimal(g, "0000"));
									
									insertMatpstaXs.setString(1, list2.get(0));
									insertMatpstaXs.setString(2, list2.get(1));
									insertMatpstaXs.setString(3, groupNo);
									insertMatpstaXs.setString(4, list2.get(3));
									insertMatpstaXs.setString(5, list2.get(4));
									insertMatpstaXs.setString(6, list2.get(5));
									insertMatpstaXs.setString(7, list2.get(6));
									insertMatpstaXs.setString(8, list2.get(7));
									insertMatpstaXs.setString(9, list2.get(8));
									insertMatpstaXs.setString(10, list2.get(9));
									insertMatpstaXs.setString(11, list2.get(10));
									insertMatpstaXs.setString(12, list2.get(11));
									insertMatpstaXs.setString(13, list2.get(12));

									insertMatpstaXs.setString(14, list2.get(40));
									insertMatpstaXs.setString(15, list2.get(41));

									insertMatpstaXs.setString(16, list2.get(15));
									insertMatpstaXs.setString(17, list2.get(16));

									insertMatpstaXs.setString(18, list2.get(17));
									insertMatpstaXs.setString(19, list2.get(18));
									insertMatpstaXs.setString(20, list2.get(19));

									insertMatpstaXs.setString(21, list2.get(20));
									insertMatpstaXs.setString(22, list2.get(21));
									insertMatpstaXs.setString(23, list2.get(22));
									insertMatpstaXs.setString(24, list2.get(23));
									insertMatpstaXs.setString(25, list2.get(24));
									// insertMatpstaXs.setString(26, list2.get(25));
									insertMatpstaXs.setString(26, list2.get(25));
									insertMatpstaXs.setString(27, list2.get(26));
									insertMatpstaXs.setString(28, list2.get(27));
									insertMatpstaXs.setString(29, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
									insertMatpstaXs.setString(30, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
									insertMatpstaXs.setString(31, list2.get(30));

									insertMatpstaXs.setString(32, list2.get(32));
									insertMatpstaXs.setObject(33, conW[1]);// 重量
									insertMatpstaXs.setString(34, systime);
									insertMatpstaXs.setString(35, systime);
									insertMatpstaXs.setString(36, (lcode + lotno)
							                + StringTool.formatDecimal(g, "0000"));
									
									//insertMatpsta.setString(36, matNo);
									insertMatpsta.setString(37, list2.get(33));
									insertMatpstaXs.setString(37, list2.get(33));
									if (!list2.get(44).equals("")) {
										insertMatpsta.setString(38, lengthList
												.get(allCount));
										insertMatpstaXs.setString(38, lengthList
												.get(allCount));
									} else {
										insertMatpsta.setString(38, "0");
										insertMatpstaXs.setString(38, "0");

									}
									insertMatpsta.setString(39, list2.get(47));
									insertMatpsta.setString(40, yearMoth);
									insertMatpsta.setObject(41, list2.get(49));
									insertMatpsta.setString(42, list2.get(50));

									insertMatpsta.setString(43, list2.get(51));
									insertMatpsta.setString(44, list2.get(52));
									insertMatpsta.setString(45, list2.get(53));
									insertMatpsta.setString(46, list2.get(54));
									insertMatpsta.setString(47, list2.get(48));//判定时间
									
									insertMatpsta.setString(48, list2.get(55));//来源
									insertMatpsta.setString(49, list2.get(56));
									insertMatpsta.setString(50, list2.get(49));
									insertMatpsta.setString(51, list2.get(50));
									insertMatpsta.setString(52, materialS[0].toString());
									insertMatpsta.setString(53, materialS[1].toString());
									insertMatpsta.setString(54, list2.get(57));
									insertMatpsta.setString(55, "801703");
									insertMatpsta.addBatch();
									
									insertMatpstaXs.setString(39, list2.get(47));
									insertMatpstaXs.setString(40, yearMoth);
									insertMatpstaXs.setObject(41, list2.get(49));
									insertMatpstaXs.setString(42, list2.get(50));

									insertMatpstaXs.setString(43, list2.get(51));
									insertMatpstaXs.setString(44, list2.get(52));
									insertMatpstaXs.setString(45, list2.get(53));
									insertMatpstaXs.setString(46, list2.get(54));
									insertMatpstaXs.setString(47, list2.get(48));//判定时间
									
									insertMatpstaXs.setString(48, list2.get(55));//来源
									insertMatpstaXs.setString(49, list2.get(56));
									insertMatpstaXs.setString(50, list2.get(49));
									insertMatpstaXs.setString(51, list2.get(50));
									insertMatpstaXs.setString(52, materialS[0].toString());
									insertMatpstaXs.setString(53, materialS[1].toString());
									insertMatpstaXs.setString(54, list2.get(57));
									insertMatpstaXs.setString(55, "801703");
									insertMatpstaXs.addBatch();
//									insertMatpsta.executeUpdate();
//									insertMatpsta.close();

									// 对缴库实绩表进行操作
									
									insertInlistpsta.setString(1, list2.get(36));
									insertInlistpsta.setString(2, list2.get(37));
									insertInlistpsta.setString(3, inListDoc
							                + StringTool.formatDecimal(n, "0000"));
//									insertInlistpsta.setString(3, querySendSql(connection,
//											inListDoc));
									insertInlistpsta.setString(4, inListDoc);
									insertInlistpsta.setString(5, list2.get(38));
									insertInlistpsta.setString(6, "产出入库");
									insertInlistpsta.setString(7, (lcode + lotno)
							                + StringTool.formatDecimal(g, "0000"));
									//insertInlistpsta.setString(7, matNo);
									insertInlistpsta.setString(8, "");// 生产批号
									insertInlistpsta.setString(9, "");
									insertInlistpsta.setString(10, lcode);
									insertInlistpsta.setString(11, lotno);
									insertInlistpsta.setString(12, groupNo);// 组号
									insertInlistpsta.setString(13, list2.get(3));// 品名
									insertInlistpsta.setString(14, list2.get(4));

									insertInlistpsta.setString(15, list2.get(11));// 标准
									insertInlistpsta.setString(16, list2.get(12));

									insertInlistpsta.setString(17, list2.get(5));// 钢级
									insertInlistpsta.setString(18, list2.get(6));

									insertInlistpsta.setString(19, list2.get(15));// 标准类别
									insertInlistpsta.setString(20, list2.get(16));

									insertInlistpsta.setString(21, list2.get(7));// 产品规格
									insertInlistpsta.setString(22, list2.get(8));

									insertInlistpsta.setString(23, list2.get(9));// 扣型
									insertInlistpsta.setString(24, list2.get(10));

									insertInlistpsta.setString(25, list2.get(23));
									insertInlistpsta.setString(26, list2.get(24));// 外径壁厚
									insertInlistpsta.setString(27, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
									insertInlistpsta.setString(28, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
									insertInlistpsta.setString(29, "1");
									insertInlistpsta.setString(30, String.valueOf(conW[1]));
									// insertInlistpsta.setString(26, list2.get(24));
									insertInlistpsta.setString(31, "");// 理论重量
									insertInlistpsta.setString(32, list2.get(40));
									insertInlistpsta.setString(33, list2.get(41));
									insertInlistpsta.setString(34, list2.get(39));
									insertInlistpsta.setString(35, list2.get(33));
									insertInlistpsta.setString(36, "1");
									insertInlistpsta.setString(37, list2.get(30));

									insertInlistpsta.setString(38, systime);
									insertInlistpsta.setString(39, list2.get(17));
									insertInlistpsta.setString(40, list2.get(18));
									insertInlistpsta.setString(41, list2.get(19));

									insertInlistpsta.setString(42, list2.get(20));
									insertInlistpsta.setString(43, list2.get(21));
									insertInlistpsta.setString(44, list2.get(22));
									insertInlistpsta.setString(45, systime);
									insertInlistpsta.setString(46, list2.get(43));
									
									insertInlistpstaXs.setString(1, list2.get(36));
									insertInlistpstaXs.setString(2, list2.get(37));
									insertInlistpstaXs.setString(3, inListDoc
							                + StringTool.formatDecimal(n, "0000"));
//									insertInlistpstaXs.setString(3, querySendSql(connection,
//											inListDoc));
									insertInlistpstaXs.setString(4, inListDoc);
									insertInlistpstaXs.setString(5, list2.get(38));
									insertInlistpstaXs.setString(6, "产出入库");
									insertInlistpstaXs.setString(7, (lcode + lotno)
							                + StringTool.formatDecimal(g, "0000"));
									//insertInlistpstaXs.setString(7, matNo);
									insertInlistpstaXs.setString(8, "");// 生产批号
									insertInlistpstaXs.setString(9, "");
									insertInlistpstaXs.setString(10, lcode);
									insertInlistpstaXs.setString(11, lotno);
									insertInlistpstaXs.setString(12, groupNo);// 组号
									insertInlistpstaXs.setString(13, list2.get(3));// 品名
									insertInlistpstaXs.setString(14, list2.get(4));

									insertInlistpstaXs.setString(15, list2.get(11));// 标准
									insertInlistpstaXs.setString(16, list2.get(12));

									insertInlistpstaXs.setString(17, list2.get(5));// 钢级
									insertInlistpstaXs.setString(18, list2.get(6));

									insertInlistpstaXs.setString(19, list2.get(15));// 标准类别
									insertInlistpstaXs.setString(20, list2.get(16));

									insertInlistpstaXs.setString(21, list2.get(7));// 产品规格
									insertInlistpstaXs.setString(22, list2.get(8));

									insertInlistpstaXs.setString(23, list2.get(9));// 扣型
									insertInlistpstaXs.setString(24, list2.get(10));

									insertInlistpstaXs.setString(25, list2.get(23));
									insertInlistpstaXs.setString(26, list2.get(24));// 外径壁厚
									insertInlistpstaXs.setString(27, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
									insertInlistpstaXs.setString(28, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
									insertInlistpstaXs.setString(29, "1");
									insertInlistpstaXs.setString(30, String.valueOf(conW[1]));
									// insertInlistpstaXs.setString(26, list2.get(24));
									insertInlistpstaXs.setString(31, "");// 理论重量
									insertInlistpstaXs.setString(32, list2.get(40));
									insertInlistpstaXs.setString(33, list2.get(41));
									insertInlistpstaXs.setString(34, list2.get(39));
									insertInlistpstaXs.setString(35, list2.get(33));
									insertInlistpstaXs.setString(36, "1");
									insertInlistpstaXs.setString(37, list2.get(30));

									insertInlistpstaXs.setString(38, systime);
									insertInlistpstaXs.setString(39, list2.get(17));
									insertInlistpstaXs.setString(40, list2.get(18));
									insertInlistpstaXs.setString(41, list2.get(19));

									insertInlistpstaXs.setString(42, list2.get(20));
									insertInlistpstaXs.setString(43, list2.get(21));
									insertInlistpstaXs.setString(44, list2.get(22));
									insertInlistpstaXs.setString(45, systime);
									insertInlistpstaXs.setString(46, list2.get(43));
									
									if (!list2.get(44).equals("")) {
										insertInlistpsta.setString(47, lengthList
												.get(allCount));
										insertInlistpstaXs.setString(47, lengthList
												.get(allCount));
									} else {
										insertInlistpsta.setString(47, "0");
										insertInlistpstaXs.setString(47, "0");
									}
									insertInlistpsta.setString(48, list2.get(45));
									insertInlistpsta.setString(49, list2.get(46));
									insertInlistpsta.setString(50, list2.get(47));
									insertInlistpsta.setString(51, list2.get(49));
									insertInlistpsta.setString(52, list2.get(50));
									insertInlistpsta.setString(53, list2.get(51));
									insertInlistpsta.setString(54, list2.get(52));

									insertInlistpsta.setString(55, yearMoth);
									insertInlistpsta.setString(56, systime);
									insertInlistpsta.setString(57, list2.get(53));
									//insertInlistpsta.setString(58, list2.get(54));
									insertInlistpsta.setString(58, list2.get(55));
									insertInlistpsta.setString(59, list2.get(56));
									insertInlistpsta.setString(60, list2.get(49));
									insertInlistpsta.setString(61, list2.get(50));
									insertInlistpsta.setString(62, materialS[0].toString());
									insertInlistpsta.setString(63, materialS[1].toString());
									insertInlistpsta.setString(64, "801703");
									insertInlistpsta.setString(65, list2.get(57));
									insertInlistpsta.addBatch();
									
									insertInlistpstaXs.setString(48, list2.get(45));
									insertInlistpstaXs.setString(49, list2.get(46));
									insertInlistpstaXs.setString(50, list2.get(47));
									insertInlistpstaXs.setString(51, list2.get(49));
									insertInlistpstaXs.setString(52, list2.get(50));
									insertInlistpstaXs.setString(53, list2.get(51));
									insertInlistpstaXs.setString(54, list2.get(52));

									insertInlistpstaXs.setString(55, yearMoth);
									insertInlistpstaXs.setString(56, systime);
									insertInlistpstaXs.setString(57, list2.get(53));
									//insertInlistpstaXs.setString(58, list2.get(54));
									insertInlistpstaXs.setString(58, list2.get(55));
									insertInlistpstaXs.setString(59, list2.get(56));
									insertInlistpstaXs.setString(60, list2.get(49));
									insertInlistpstaXs.setString(61, list2.get(50));
									insertInlistpstaXs.setString(62, materialS[0].toString());
									insertInlistpstaXs.setString(63, materialS[1].toString());
									insertInlistpstaXs.setString(64, "801703");
									insertInlistpstaXs.setString(65, list2.get(57));
									insertInlistpstaXs.addBatch();
									
								} else {
									
									insertMat1psta.setString(1, list2.get(0));
									insertMat1psta.setString(2, list2.get(1));
									insertMat1psta.setString(3, groupNo);
									insertMat1psta.setString(4, list2.get(3));
									insertMat1psta.setString(5, list2.get(4));
									insertMat1psta.setString(6, list2.get(5));
									insertMat1psta.setString(7, list2.get(6));
									insertMat1psta.setString(8, list2.get(7));
									insertMat1psta.setString(9, list2.get(8));
									insertMat1psta.setString(10, list2.get(9));
									insertMat1psta.setString(11, list2.get(10));
									insertMat1psta.setString(12, list2.get(11));
									insertMat1psta.setString(13, list2.get(12));

									insertMat1psta.setString(14, list2.get(40));
									insertMat1psta.setString(15, list2.get(41));

									insertMat1psta.setString(16, list2.get(15));
									insertMat1psta.setString(17, list2.get(16));

									// insertMat1psta.setString(18, list2.get(17));
									// insertMat1psta.setString(19, list2.get(18));
									// insertMat1psta.setString(20, list2.get(19));

									// insertMat1psta.setString(18, list2.get(20));
									// insertMat1psta.setString(19, list2.get(21));
									// insertMat1psta.setString(20, list2.get(22));
									insertMat1psta.setString(18, list2.get(23));
									insertMat1psta.setString(19, list2.get(24));
									insertMat1psta.setString(20, list2.get(25));
									// insertMat1psta.setString(21, list2.get(26));
									insertMat1psta.setString(21, list2.get(26));
									insertMat1psta.setString(22, list2.get(27));
									insertMat1psta.setString(23, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
									insertMat1psta.setString(24, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
									insertMat1psta.setString(25, list2.get(30));
									insertMat1psta.setString(26, list2.get(32));
									insertMat1psta.setObject(27, conW[1]);// 重量
									insertMat1psta.setString(28, systime);
									insertMat1psta.setString(29, systime);
									insertMat1psta.setString(30, (lcode + lotno)
							                + StringTool.formatDecimal(g, "0000"));
									
									insertMat1pstaXs.setString(1, list2.get(0));
									insertMat1pstaXs.setString(2, list2.get(1));
									insertMat1pstaXs.setString(3, groupNo);
									insertMat1pstaXs.setString(4, list2.get(3));
									insertMat1pstaXs.setString(5, list2.get(4));
									insertMat1pstaXs.setString(6, list2.get(5));
									insertMat1pstaXs.setString(7, list2.get(6));
									insertMat1pstaXs.setString(8, list2.get(7));
									insertMat1pstaXs.setString(9, list2.get(8));
									insertMat1pstaXs.setString(10, list2.get(9));
									insertMat1pstaXs.setString(11, list2.get(10));
									insertMat1pstaXs.setString(12, list2.get(11));
									insertMat1pstaXs.setString(13, list2.get(12));

									insertMat1pstaXs.setString(14, list2.get(40));
									insertMat1pstaXs.setString(15, list2.get(41));

									insertMat1pstaXs.setString(16, list2.get(15));
									insertMat1pstaXs.setString(17, list2.get(16));

									// insertMat1pstaXs.setString(18, list2.get(17));
									// insertMat1pstaXs.setString(19, list2.get(18));
									// insertMat1pstaXs.setString(20, list2.get(19));

									// insertMat1pstaXs.setString(18, list2.get(20));
									// insertMat1pstaXs.setString(19, list2.get(21));
									// insertMat1pstaXs.setString(20, list2.get(22));
									insertMat1pstaXs.setString(18, list2.get(23));
									insertMat1pstaXs.setString(19, list2.get(24));
									insertMat1pstaXs.setString(20, list2.get(25));
									// insertMat1pstaXs.setString(21, list2.get(26));
									insertMat1pstaXs.setString(21, list2.get(26));
									insertMat1pstaXs.setString(22, list2.get(27));
									insertMat1pstaXs.setString(23, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
									insertMat1pstaXs.setString(24, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
									insertMat1pstaXs.setString(25, list2.get(30));
									insertMat1pstaXs.setString(26, list2.get(32));
									insertMat1pstaXs.setObject(27, conW[1]);// 重量
									insertMat1pstaXs.setString(28, systime);
									insertMat1pstaXs.setString(29, systime);
									insertMat1pstaXs.setString(30, (lcode + lotno)
							                + StringTool.formatDecimal(g, "0000"));
									
									//insertMat1psta.setString(30, matNo);
									insertMat1psta.setString(31, list2.get(33));
									insertMat1pstaXs.setString(31, list2.get(33));

									if (!list2.get(44).equals("")) {
										insertMat1psta.setString(32, lengthList
												.get(allCount));
										insertMat1pstaXs.setString(32, lengthList
												.get(allCount));
									} else {
										insertMat1psta.setString(32, "0");
										insertMat1pstaXs.setString(32, "0");

									}
									insertMat1psta.setString(33, list2.get(47));
									insertMat1psta.setString(34, yearMoth);//结转年月
									insertMat1psta.setString(35, list2.get(49));
									insertMat1psta.setString(36, list2.get(50));
									insertMat1psta.setString(37, list2.get(51));
									insertMat1psta.setString(38, list2.get(52));
									insertMat1psta.setString(39, list2.get(53));
									insertMat1psta.setString(40, list2.get(54));
									insertMat1psta.setString(41, list2.get(48));
									insertMat1psta.setString(42, list2.get(55));//来源
									insertMat1psta.setString(43, list2.get(56));
									insertMat1psta.setString(44, list2.get(49));
									insertMat1psta.setString(45, list2.get(50));
									insertMat1psta.setString(46, materialS[0].toString());
									insertMat1psta.setString(47, materialS[1].toString());
									insertMat1psta.setString(48, list2.get(57));
									insertMat1psta.setString(49, list2.get(58));
									insertMat1psta.addBatch();
									
									insertMat1pstaXs.setString(33, list2.get(47));
									insertMat1pstaXs.setString(34, yearMoth);//结转年月
									insertMat1pstaXs.setString(35, list2.get(49));
									insertMat1pstaXs.setString(36, list2.get(50));
									insertMat1pstaXs.setString(37, list2.get(51));
									insertMat1pstaXs.setString(38, list2.get(52));
									insertMat1pstaXs.setString(39, list2.get(53));
									insertMat1pstaXs.setString(40, list2.get(54));
									insertMat1pstaXs.setString(41, list2.get(48));
									insertMat1pstaXs.setString(42, list2.get(55));//来源
									insertMat1pstaXs.setString(43, list2.get(56));
									insertMat1pstaXs.setString(44, list2.get(49));
									insertMat1pstaXs.setString(45, list2.get(50));
									insertMat1pstaXs.setString(46, materialS[0].toString());
									insertMat1pstaXs.setString(47, materialS[1].toString());
									insertMat1pstaXs.setString(48, list2.get(57));
									insertMat1pstaXs.setString(49, list2.get(58));
									insertMat1pstaXs.addBatch();
//									insertMat1psta.executeUpdate();
//									insertMat1psta.close();

									// 对缴库实绩表进行操作
									
									insertInlist1psta.setString(1, list2.get(36));
									insertInlist1psta.setString(2, list2.get(37));
									insertInlist1psta.setString(3, inListDoc
							                + StringTool.formatDecimal(n, "0000"));
//									insertInlist1psta.setString(3, querySendSql(connection,
//											inListDoc));
									insertInlist1psta.setString(4, inListDoc);
									insertInlist1psta.setString(5, list2.get(38));
									insertInlist1psta.setString(6, "产出入库");
									insertInlist1psta.setString(7, (lcode + lotno)
							                + StringTool.formatDecimal(g, "0000"));
									//insertInlist1psta.setString(7, matNo);
									insertInlist1psta.setString(8, "");// 生产批号
									insertInlist1psta.setString(9, "");
									insertInlist1psta.setString(10, lcode);
									insertInlist1psta.setString(11, lotno);
									insertInlist1psta.setString(12, groupNo);// 组号
									insertInlist1psta.setString(13, list2.get(3));// 品名
									insertInlist1psta.setString(14, list2.get(4));

									insertInlist1psta.setString(15, list2.get(11));// 标准
									insertInlist1psta.setString(16, list2.get(12));

									insertInlist1psta.setString(17, list2.get(5));// 钢级
									insertInlist1psta.setString(18, list2.get(6));

									insertInlist1psta.setString(19, list2.get(15));// 标准类别
									insertInlist1psta.setString(20, list2.get(16));

									insertInlist1psta.setString(21, list2.get(7));// 产品规格
									insertInlist1psta.setString(22, list2.get(8));

									insertInlist1psta.setString(23, list2.get(9));// 扣型
									insertInlist1psta.setString(24, list2.get(10));

									insertInlist1psta.setString(25, list2.get(23));
									insertInlist1psta.setString(26, list2.get(24));// 外径壁厚
									insertInlist1psta.setString(27, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
									insertInlist1psta.setString(28, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
									insertInlist1psta.setString(29, "1");
									insertInlist1psta.setString(30, String.valueOf(conW[1]));
									// insertInlist1psta.setString(26, list2.get(24));
									insertInlist1psta.setString(31, "");// 理论重量
									insertInlist1psta.setString(32, list2.get(40));
									insertInlist1psta.setString(33, list2.get(41));
									insertInlist1psta.setString(34, list2.get(39));
									insertInlist1psta.setString(35, list2.get(33));
									insertInlist1psta.setString(36, "1");
									insertInlist1psta.setString(37, list2.get(30));

									insertInlist1psta.setString(38, systime);
									insertInlist1psta.setString(39, list2.get(17));
									insertInlist1psta.setString(40, list2.get(18));
									insertInlist1psta.setString(41, list2.get(19));
									insertInlist1psta.setString(42, list2.get(20));

									insertInlist1psta.setString(43, list2.get(21));
									insertInlist1psta.setString(44, list2.get(22));
									
									insertInlist1psta.setString(45, systime);
									insertInlist1psta.setString(46, list2.get(43));
									
									insertInlist1pstaXs.setString(1, list2.get(36));
									insertInlist1pstaXs.setString(2, list2.get(37));
									insertInlist1pstaXs.setString(3, inListDoc
							                + StringTool.formatDecimal(n, "0000"));
//									insertInlist1pstaXs.setString(3, querySendSql(connection,
//											inListDoc));
									insertInlist1pstaXs.setString(4, inListDoc);
									insertInlist1pstaXs.setString(5, list2.get(38));
									insertInlist1pstaXs.setString(6, "产出入库");
									insertInlist1pstaXs.setString(7, (lcode + lotno)
							                + StringTool.formatDecimal(g, "0000"));
									//insertInlist1pstaXs.setString(7, matNo);
									insertInlist1pstaXs.setString(8, "");// 生产批号
									insertInlist1pstaXs.setString(9, "");
									insertInlist1pstaXs.setString(10, lcode);
									insertInlist1pstaXs.setString(11, lotno);
									insertInlist1pstaXs.setString(12, groupNo);// 组号
									insertInlist1pstaXs.setString(13, list2.get(3));// 品名
									insertInlist1pstaXs.setString(14, list2.get(4));

									insertInlist1pstaXs.setString(15, list2.get(11));// 标准
									insertInlist1pstaXs.setString(16, list2.get(12));

									insertInlist1pstaXs.setString(17, list2.get(5));// 钢级
									insertInlist1pstaXs.setString(18, list2.get(6));

									insertInlist1pstaXs.setString(19, list2.get(15));// 标准类别
									insertInlist1pstaXs.setString(20, list2.get(16));

									insertInlist1pstaXs.setString(21, list2.get(7));// 产品规格
									insertInlist1pstaXs.setString(22, list2.get(8));

									insertInlist1pstaXs.setString(23, list2.get(9));// 扣型
									insertInlist1pstaXs.setString(24, list2.get(10));

									insertInlist1pstaXs.setString(25, list2.get(23));
									insertInlist1pstaXs.setString(26, list2.get(24));// 外径壁厚
									insertInlist1pstaXs.setString(27, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(28))));
									insertInlist1pstaXs.setString(28, new DecimalFormat("0.00").format(Double.parseDouble(list2.get(29))));
									insertInlist1pstaXs.setString(29, "1");
									insertInlist1pstaXs.setString(30, String.valueOf(conW[1]));
									// insertInlist1pstaXs.setString(26, list2.get(24));
									insertInlist1pstaXs.setString(31, "");// 理论重量
									insertInlist1pstaXs.setString(32, list2.get(40));
									insertInlist1pstaXs.setString(33, list2.get(41));
									insertInlist1pstaXs.setString(34, list2.get(39));
									insertInlist1pstaXs.setString(35, list2.get(33));
									insertInlist1pstaXs.setString(36, "1");
									insertInlist1pstaXs.setString(37, list2.get(30));

									insertInlist1pstaXs.setString(38, systime);
									insertInlist1pstaXs.setString(39, list2.get(17));
									insertInlist1pstaXs.setString(40, list2.get(18));
									insertInlist1pstaXs.setString(41, list2.get(19));
									insertInlist1pstaXs.setString(42, list2.get(20));

									insertInlist1pstaXs.setString(43, list2.get(21));
									insertInlist1pstaXs.setString(44, list2.get(22));
									
									insertInlist1pstaXs.setString(45, systime);
									insertInlist1pstaXs.setString(46, list2.get(43));
									
									if (!list2.get(44).equals("")) {
										insertInlist1psta.setString(47, lengthList
												.get(allCount));
										insertInlist1pstaXs.setString(47, lengthList
												.get(allCount));
									} else {
										insertInlist1psta.setString(47, "0");
										insertInlist1pstaXs.setString(47, "0");

									}
									insertInlist1psta.setString(48, list2.get(45));
									insertInlist1psta.setString(49, list2.get(46));
									insertInlist1psta.setString(50, list2.get(47));
									insertInlist1psta.setString(51, list2.get(49));
									insertInlist1psta.setString(52, list2.get(50));
									insertInlist1psta.setString(53, list2.get(51));
									insertInlist1psta.setString(54, list2.get(52));

									insertInlist1psta.setString(55, yearMoth);
									insertInlist1psta.setString(56, systime);
									insertInlist1psta.setString(57, list2.get(53));
									//insertInlist1psta.setString(58, list2.get(54));
									insertInlist1psta.setString(58, list2.get(55));//来源
									insertInlist1psta.setString(59, list2.get(56));
									insertInlist1psta.setString(60, list2.get(49));//来源
									insertInlist1psta.setString(61, list2.get(50));
									insertInlist1psta.setString(62, materialS[0].toString());
									insertInlist1psta.setString(63, materialS[1].toString());
									insertInlist1psta.setString(64, list2.get(58));
									insertInlist1psta.setString(65, list2.get(57));
									insertInlist1psta.addBatch();
									
									insertInlist1pstaXs.setString(48, list2.get(45));
									insertInlist1pstaXs.setString(49, list2.get(46));
									insertInlist1pstaXs.setString(50, list2.get(47));
									insertInlist1pstaXs.setString(51, list2.get(49));
									insertInlist1pstaXs.setString(52, list2.get(50));
									insertInlist1pstaXs.setString(53, list2.get(51));
									insertInlist1pstaXs.setString(54, list2.get(52));

									insertInlist1pstaXs.setString(55, yearMoth);
									insertInlist1pstaXs.setString(56, systime);
									insertInlist1pstaXs.setString(57, list2.get(53));
									//insertInlist1pstaXs.setString(58, list2.get(54));
									insertInlist1pstaXs.setString(58, list2.get(55));//来源
									insertInlist1pstaXs.setString(59, list2.get(56));
									insertInlist1pstaXs.setString(60, list2.get(49));//来源
									insertInlist1pstaXs.setString(61, list2.get(50));
									insertInlist1pstaXs.setString(62, materialS[0].toString());
									insertInlist1pstaXs.setString(63, materialS[1].toString());
									insertInlist1pstaXs.setString(64, list2.get(58));
									insertInlist1pstaXs.setString(65, list2.get(57));
									insertInlist1pstaXs.addBatch();
									
								}
							}
							allCount++;
							n++;
							g++;
						}
                    }
                }
                updateProcesspsta.setString(1, String.valueOf(acb));
                updateProcesspsta.setString(2, new DecimalFormat("0.000").format(htWgt));
                updateProcesspsta.setString(3, new DecimalFormat("0.000").format(htLen));
                updateProcesspsta.setString(4, list2.get(22));
                updateProcesspsta.addBatch();

            }
            
            for (int i = 0; i < parm4.size(); i++) {
                ArrayList<Object> list4 = (ArrayList<Object>) parm4.get(i);
                double parm4Wgt = Double.parseDouble(list4.get(1).toString());
                updatePln1psta.setString(1, list4.get(3).toString());
                updatePln1psta.setString(2, list4.get(4).toString());
                updatePln1psta.setString(3, list4.get(5).toString());
                updatePln1psta.setString(4, list4.get(1).toString());
                updatePln1psta.setString(5, list4.get(3).toString());
                updatePln1psta.setString(6, list4.get(4).toString());
                updatePln1psta.setString(7, list4.get(5).toString());
                //DecimalFormat dt = new DecimalFormat("0.000");
                updatePln1psta.setString(8, new DecimalFormat("0.000").format(htWgt));
                //updatePln1psta.setString(9, list4.get(2).toString());
                updatePln1psta.setString(9, list4.get(3).toString());
                updatePln1psta.setString(10, list4.get(4).toString());
                updatePln1psta.setString(11, list4.get(5).toString());
                updatePln1psta.addBatch();
            }

			 result = this.getDao("MSSQL1Dao").CoreBeginTranscation();

			for (int i = 0; i < parm3.size(); i++) {
				sql = CoreXmlSqlParsersFactory
						.getSql("CorePipeInTemp.UPDATEINTERFACE");
				ArrayList<Object> list3 = (ArrayList<Object>) parm3.get(i);
				Object[] obj = list3.toArray();
				updateSqlserverpsta.setString(1, obj[0].toString());
				updateSqlserverpsta.setString(2, obj[1].toString());
				updateSqlserverpsta.setString(3, obj[2].toString());
				updateSqlserverpsta.setString(4, obj[3].toString());
				updateSqlserverpsta.setString(5, obj[4].toString());
				updateSqlserverpsta.setString(6, obj[5].toString());
				updateSqlserverpsta.setString(7, obj[6].toString());
				updateSqlserverpsta.addBatch();
				//cro = this.setData("MSSQL1Dao", sql, obj);
			}
			//cro = this.getDao("MSSQL1Dao").ExcuteTransction(sqlIDList, parmlist);
			
			InsertButtresspsta.executeBatch();
			insertMat2psta.executeBatch();
			insertInlist1psta.executeBatch();
			insertInlist1pstaXs.executeBatch();
			insertMatpsta.executeBatch();
			insertMatpstaXs.executeBatch();
			insertInlistpsta.executeBatch();
			insertInlistpstaXs.executeBatch();
			insertMat1psta.executeBatch();
			insertMat1pstaXs.executeBatch();
			updatePln1psta.executeBatch();
			updateProcesspsta.executeBatch();
			updateSqlserverpsta.executeBatch();
			updateMaterialpsta.executeBatch();
			this.getDao("MSSQL1Dao").CoreCommit(result);
			connection.commit();
			cro.setResult(1);
			cro.setV_errMsg("缴库成功!");
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            if (connection != null) {
                try {
                	cro.setV_errMsg(e.getMessage());
                	this.getDao("MSSQL1Dao").CoreRollBack(result);
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                    con.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cro;
    }

    /**
     * 库存查询
     * @param pram 参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject queryMat(ArrayList<String> pram,String[] arr,String startTim,String endTim) {
		String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.QUERYMAT");
		sql += CoreConverter.toSqlConditionString("T1.BELONG_CODE", arr);
		if (!startTim.equals("")) {
			sql += " AND T1.INSTOCK_TIME >=TO_DATE('"
					+ startTim
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T1.INSTOCK_TIME <=TO_DATE('"
					+ endTim + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		if(!pram.get(0).equals(""))
		{
			sql += " AND T1.JUDGE_STOVE_NO = '"+pram.get(0)+"'"; 
		}
		if(!pram.get(1).equals(""))
		{
			sql += " AND T1.ORDER_NO = '"+pram.get(1)+"'";
		}
		if(!pram.get(2).equals(""))
		{
			sql += " AND S.STORAGE_NO = '"+pram.get(2)+"'";
		}
		sql += " GROUP BY T1.JUDGE_STOVE_NO, T1.BATCH_NO, T1.BATCH_GROUD_NO,T1.PRODUCCODE,T1.PRODUCNAME,T1.STEELCODE,T1.STEELNAME,T1.SPEC_CODE,T1.SPEC_NAME,T1.MODEL_CODE,T1.GRADECODE,T1.GRADENAME,T1.STD_STYLE,T1.STD_STYLE_DESC,T1.PIPMEMO,T1.OLD_ORDER_NO,T1.MAT_STATUS,";
		sql += " T1.MODEL_DESC,T1.STD_CODE,T1.STD_NAME,T1.ORDER_NO,T1.ORDER_SEQ,T1.ORDER_SEQ_NO,T1.ACT_DIMATER,T1.ACT_HEIGHT,T1.LEN_NO,T1.LEN_DESC,T1.LEN_UNIT,T1.BELONG_CODE,T1.BELONG_NAME,T1.PLINE_CODE,T1.PLINE_NAME,T1.BAL_YEAR_MONTH,T1.FINISHPRO_MOLD,T1.IN_MOLD,";
		sql += " T1.ACT_LEN_MIN,T1.ACT_LEN_MAX,T1.CREATE_NAME,T2.STORAGE_NO,S.STORAGE_NAME,T1.MEMO,T1.PRODUCT_FLAG,T1.JUDGE_STD_CODE,T1.JUDGE_STD_NAME ORDER BY T1.BAL_YEAR_MONTH DESC";

        return this.getData(sql);
    }

    /***
     * 缴库实绩查询
     * @param list
     * @return
     */
    public CoreReturnObject queryInList(ArrayList<String> list,String[] arr,String startTim,String endTim)
    {
		String sql = CoreXmlSqlParsersFactory
				.getSql("CorePipeInTemp.queryInList");
		sql += CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
		if(!startTim.equals(""))
		{
			//sql += " AND IN_TIME_F>=TO_DATE('"+startTim+"','YYYY-MM-DD HH24:MI:SS') AND IN_TIME_F<= TO_DATE('"+endTim+"','YYYY-MM-DD HH24:MI:SS')";
			sql += " AND TRUNC(IN_TIME_F)>=TO_DATE('"+startTim+"','YYYY-MM-DD') AND TRUNC(IN_TIME_F)<= TO_DATE('"+endTim+"','YYYY-MM-DD')";
		}
		if(!list.get(0).equals(""))
		{
			sql += " AND T.JUDGE_STOVE_NO = '"+list.get(0)+"'";
		}
		if(!list.get(1).equals(""))
		{
			sql += " AND T.ORDER_NO = '"+list.get(1)+"'";
		}
		if(!list.get(2).equals(""))
		{
			sql += " AND T.STORAGE_NO = '"+list.get(2)+"'";
		}
		if(!list.get(3).equals(""))
		{
			sql += " AND T.BAL_YEAR_MONTH = '"+list.get(3)+"'";
		}
		sql += " group by t.JUDGE_STOVE_NO,t.BATCH_NO,t.INSTOCK_DOC,t.PRODUCCODE,t.PRODUCNAME,t.STD_CODE,t.STD_NAME,t.STEELCODE,t.STEELNAME,t.STD_STYLE,t.STD_STYLE_DESC,t.SPEC_CODE,t.SPEC_NAME,t.JUDGE_STD_CODE,t.JUDGE_STD_NAME,t.GRADECODE,t.GRADENAME,t.BAL_YEAR_MONTH,t.PIPMEMO,t.BATCH_GROUD_NO,";
		sql += " t.MODEL_DESC,t.ACT_DIMATER,t.ACT_HEIGHT,t.ACT_LEN_MIN,t.ACT_LEN_MAX,t.BELONG_CODE,t.BELONG_NAME,s.STORAGE_NAME,t.MEMO,t.CREATE_NAME,t.ORDER_NO,t.ORDER_SEQ,t.DELIVERY_NO,t.MODEL_CODE,t.PRODUCT_FLAG,t.ZB_RCDID,t.PLINE_CODE,t.PLINE_NAME,d.SALE_AREA_DESC,d.create_name,m.basename";
		sql += " order by t.instock_doc desc";
    		
    	return this.getData(sql);
    }
    
    /**
     * 撤销缴库
     * @param pram 参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject canclePipein(ArrayList<ArrayList<String>> list,
            ArrayList<ArrayList<String>> pram,ArrayList<ArrayList<String>> list2) {
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        
        ArrayList<String> sqllistSqlServer = new ArrayList<String>();
        ArrayList<Object[]> parmlistSqlServer = new ArrayList<Object[]>();
        String sqlQuery = "";
        String deleteSql = "";
        String deleteSqlXs = "";
        String insertSql = "";
        String insertSqlXs = "";
        String updateCancelProcess = "";
        PreparedStatement psta = null;
        PreparedStatement pstaXs = null;
        ResultSet rs = null;
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
        .getConnection();
        ArrayList<String> billMats = new ArrayList<String>(); // 保存物料号
		try {
			for (int i = 0; i < list.size(); i++) {
				ArrayList<String> list1 = list.get(i);
				Object[] obj = new Object[] { list1.get(0), list1.get(1),list1.get(11)};
//				Object[] obj1 = new Object[] { list1.get(0), list1.get(1),
//						list1.get(5), list1.get(6), list1.get(7), list1.get(8),
//						list1.get(9) };
				Object[] obj1 = new Object[]{list1.get(0), list1.get(1),list1.get(11)};
				Object[] obj2 = new Object[] { list1.get(0), list1.get(1),
						 list1.get(4) };
				Object[] obj3 = new Object[] {list1.get(4)};
				List<String[]> inCancelList = getCancelSumWgt(connection, list1.get(10));
				String[] arrCancel = null;
				if(inCancelList !=null)
				{
					arrCancel = inCancelList.get(0);
				}
				if(list1.get(10).contains("IA"))
				{
					sqlQuery = CoreXmlSqlParsersFactory
							.getSql("canclePipein.sqlQuery");// 查询物料号

					psta = connection.prepareStatement(sqlQuery);
					psta.setString(1, list1.get(0));
					psta.setString(2, list1.get(1));
//					psta.setString(3, list1.get(5));
//					psta.setString(4, list1.get(6));
//					psta.setString(5, list1.get(7));
//					psta.setString(6, list1.get(8));
//					psta.setString(7, list1.get(9));
					psta.setString(3, list1.get(11));
					rs = psta.executeQuery();
					billMats.clear();
					while (rs.next()) {
						billMats.add(rs.getString(1));
					}
					rs.close();
					psta.close();

					// 删除位置表
					for (int k = 0; k < billMats.size(); k++) {
						deleteSql = CoreXmlSqlParsersFactory
								.getSql("CorePipeInTemp.DELETELOCATION");
						deleteSqlXs = CoreXmlSqlParsersFactory
								.getSql("CorePipeInTempXs.DELETELOCATION");
						psta = connection.prepareStatement(deleteSql);
						pstaXs = connection.prepareStatement(deleteSqlXs);
						psta.setString(1, billMats.get(k));
						psta.executeUpdate();
						pstaXs.setString(1, billMats.get(k));
						pstaXs.executeUpdate();
						psta.close();
						pstaXs.close();
					}

					// 删除物料表
					sqllist.add(CoreXmlSqlParsersFactory
							.getSql("CorePipeInTemp.DELETEPIPEDIN"));
					sqllist.add(CoreXmlSqlParsersFactory
							.getSql("CorePipeInTempXs.DELETEPIPEDIN"));
					parmlist.add(obj1);

					// 修改判定数据状态
					sqllistSqlServer.add(CoreXmlSqlParsersFactory
							.getSql("CorePipeInTemp.UPDATEINTERFACE2"));
					parmlistSqlServer.add(obj2);
					
					updateCancelProcess = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateCancelProcess");
					psta = connection.prepareStatement(updateCancelProcess);
					psta.setString(1, arrCancel[0]);
					psta.setString(2, arrCancel[1]);
					psta.setString(3, arrCancel[2]);
					psta.setString(4, arrCancel[3]);
					psta.executeUpdate();
					psta.close();
				}
				if(list1.get(10).contains("AI"))
				{
					//查询入库所有信息
					sqlQuery = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.QueryInList");
					psta = connection.prepareStatement(sqlQuery);
					psta.setString(1, "IA"+list1.get(10).substring(2));
					rs = psta.executeQuery();
					List<YdmZcInlistEntity> inList=EntityTool.getEntitysByRs(rs, YdmZcInlistEntity.class);
					rs.close();
					psta.close();
					if(inList !=null && inList.size()>0)
					{
						for(YdmZcInlistEntity ydmInList :inList)
						{
							if(ydmInList.getProductFlag().equals("801403"))//商品
							{
								insertSql = CoreXmlSqlParsersFactory
										.getSql("CorePipeInTemp.REDINSERTMAT");
								insertSqlXs = CoreXmlSqlParsersFactory
										.getSql("CorePipeInTempXs.REDINSERTMAT");
								psta = connection.prepareStatement(insertSql);
								
								psta.setString(1, ydmInList.getJudgeStoveNo());
								psta.setString(2, ydmInList.getBatchNo());
								psta.setString(3, ydmInList.getBatchGroudNo());
								psta.setString(4, ydmInList.getProduccode());
								psta.setString(5, ydmInList.getProducname());
								psta.setString(6, ydmInList.getSteelcode());
								psta.setString(7, ydmInList.getSteelname());
								psta.setString(8, ydmInList.getSpecCode());
								psta.setString(9, ydmInList.getSpecName());
								psta.setString(10, ydmInList.getModelCode());
								psta.setString(11, ydmInList.getModelDesc());
								psta.setString(12, ydmInList.getStdCode());
								psta.setString(13, ydmInList.getStdName());
								psta.setString(14, ydmInList.getBelongCode());
								psta.setString(15, ydmInList.getBelongName());
								psta.setString(16, ydmInList.getStdStyle());
								psta.setString(17, ydmInList.getStdStyleDesc());
								psta.setString(18, ydmInList.getOrderNo());
								psta.setString(19, ydmInList.getOrderSeq());
								psta.setString(20, ydmInList.getDeliveryNo());
								psta.setString(21, ydmInList.getOrdPk());
								psta.setString(22, ydmInList.getOrdLnPk());
								psta.setString(23, ydmInList.getOrdLnDlyPk());
								psta.setString(24, ydmInList.getActDimater());
								psta.setString(25, ydmInList.getActHeight());
								psta.setString(26, "");
								psta.setString(27, "");
								psta.setString(28, "");
								psta.setString(29, ydmInList.getActLenMin());
								psta.setString(30, ydmInList.getActLenMax());
								psta.setString(31, ydmInList.getCreateName());
								psta.setString(32, ydmInList.getActCount());
								psta.setString(33, ydmInList.getActWeight());
								psta.setString(34, ydmInList.getCreateTime());
								psta.setString(35, ydmInList.getInstockTime());
								psta.setString(36, ydmInList.getMatNo());
								psta.setString(37, ydmInList.getMemo());
								psta.setString(38, "1");
								psta.setString(39, "1");
								psta.setString(40, ydmInList.getProductFlag());
								psta.setString(41, ydmInList.getMatStatus());
								psta.setString(42, ydmInList.getActLen());
								
								psta.setString(43, ydmInList.getJudgeStdName());
								psta.setString(44, ydmInList.getBalYearMonth());
								psta.setString(45, ydmInList.getPlineCode());
								psta.setString(46, ydmInList.getPlineName());
								psta.setString(47, ydmInList.getGradecode());
								psta.setString(48, ydmInList.getGradename());
								psta.executeUpdate();
								psta.close();
								pstaXs = connection.prepareStatement(insertSqlXs);
								pstaXs.setString(1, ydmInList.getJudgeStoveNo());
								pstaXs.setString(2, ydmInList.getBatchNo());
								pstaXs.setString(3, ydmInList.getBatchGroudNo());
								pstaXs.setString(4, ydmInList.getProduccode());
								pstaXs.setString(5, ydmInList.getProducname());
								pstaXs.setString(6, ydmInList.getSteelcode());
								pstaXs.setString(7, ydmInList.getSteelname());
								pstaXs.setString(8, ydmInList.getSpecCode());
								pstaXs.setString(9, ydmInList.getSpecName());
								pstaXs.setString(10, ydmInList.getModelCode());
								pstaXs.setString(11, ydmInList.getModelDesc());
								pstaXs.setString(12, ydmInList.getStdCode());
								pstaXs.setString(13, ydmInList.getStdName());
								pstaXs.setString(14, ydmInList.getBelongCode());
								pstaXs.setString(15, ydmInList.getBelongName());
								pstaXs.setString(16, ydmInList.getStdStyle());
								pstaXs.setString(17, ydmInList.getStdStyleDesc());
								pstaXs.setString(18, ydmInList.getOrderNo());
								pstaXs.setString(19, ydmInList.getOrderSeq());
								pstaXs.setString(20, ydmInList.getDeliveryNo());
								pstaXs.setString(21, ydmInList.getOrdPk());
								pstaXs.setString(22, ydmInList.getOrdLnPk());
								pstaXs.setString(23, ydmInList.getOrdLnDlyPk());
								pstaXs.setString(24, ydmInList.getActDimater());
								pstaXs.setString(25, ydmInList.getActHeight());
								pstaXs.setString(26, "");
								pstaXs.setString(27, "");
								pstaXs.setString(28, "");
								pstaXs.setString(29, ydmInList.getActLenMin());
								pstaXs.setString(30, ydmInList.getActLenMax());
								pstaXs.setString(31, ydmInList.getCreateName());
								pstaXs.setString(32, ydmInList.getActCount());
								pstaXs.setString(33, ydmInList.getActWeight());
								pstaXs.setString(34, ydmInList.getCreateTime());
								pstaXs.setString(35, ydmInList.getInstockTime());
								pstaXs.setString(36, ydmInList.getMatNo());
								pstaXs.setString(37, ydmInList.getMemo());
								pstaXs.setString(38, "1");
								pstaXs.setString(39, "1");
								pstaXs.setString(40, ydmInList.getProductFlag());
								pstaXs.setString(41, ydmInList.getMatStatus());
								pstaXs.setString(42, ydmInList.getActLen());
								
								pstaXs.setString(43, ydmInList.getJudgeStdName());
								pstaXs.setString(44, ydmInList.getBalYearMonth());
								pstaXs.setString(45, ydmInList.getPlineCode());
								pstaXs.setString(46, ydmInList.getPlineName());
								pstaXs.setString(47, ydmInList.getGradecode());
								pstaXs.setString(48, ydmInList.getGradename());
								pstaXs.executeUpdate();
								pstaXs.close();
							}
							else if(ydmInList.getProductFlag().equals("801402"))//成品
							{
								insertSql = CoreXmlSqlParsersFactory
										.getSql("CorePipeInTemp.REDINSERTMAT1");
								insertSqlXs = CoreXmlSqlParsersFactory
										.getSql("CorePipeInTempXs.REDINSERTMAT1");
								psta = connection.prepareStatement(insertSql);
								psta.setString(1, ydmInList.getJudgeStoveNo());
								psta.setString(2, ydmInList.getBatchNo());
								psta.setString(3, ydmInList.getBatchGroudNo());
								psta.setString(4, ydmInList.getProduccode());
								psta.setString(5, ydmInList.getProducname());
								psta.setString(6, ydmInList.getSteelcode());
								psta.setString(7, ydmInList.getSteelname());
								psta.setString(8, ydmInList.getSpecCode());
								psta.setString(9, ydmInList.getSpecName());
								psta.setString(10, ydmInList.getModelCode());
								psta.setString(11, ydmInList.getModelDesc());
								psta.setString(12, ydmInList.getStdCode());
								psta.setString(13, ydmInList.getStdName());
								psta.setString(14, ydmInList.getBelongCode());
								psta.setString(15, ydmInList.getBelongName());
								psta.setString(16, ydmInList.getStdStyle());
								psta.setString(17, ydmInList.getStdStyleDesc());
								
								psta.setString(18, ydmInList.getActDimater());
								psta.setString(19, ydmInList.getActHeight());
								psta.setString(20, "");
								psta.setString(21, "");
								psta.setString(22, "");
								psta.setString(23, ydmInList.getActLenMin());
								psta.setString(24, ydmInList.getActLenMax());
								psta.setString(25, ydmInList.getCreateName());
								psta.setString(26, ydmInList.getActCount());
								psta.setString(27, ydmInList.getActWeight());
								psta.setString(28, ydmInList.getCreateTime());
								psta.setString(29, ydmInList.getInstockTime());
								psta.setString(30, ydmInList.getMatNo());
								psta.setString(31, ydmInList.getMemo());
								psta.setString(32, "1");
								psta.setString(33, "1");
								psta.setString(34, ydmInList.getProductFlag());
								psta.setString(35, ydmInList.getMatStatus());
								psta.setString(36, ydmInList.getActLen());

								psta.setString(37, ydmInList.getJudgeStdName());
								psta.setString(38, ydmInList.getBalYearMonth());
								psta.setString(39, ydmInList.getPlineCode());
								psta.setString(40, ydmInList.getPlineName());
								psta.setString(41, ydmInList.getGradecode());
								psta.setString(42, ydmInList.getGradename());
								psta.executeUpdate();
								psta.close();
								
								pstaXs = connection.prepareStatement(insertSqlXs);
								pstaXs.setString(1, ydmInList.getJudgeStoveNo());
								pstaXs.setString(2, ydmInList.getBatchNo());
								pstaXs.setString(3, ydmInList.getBatchGroudNo());
								pstaXs.setString(4, ydmInList.getProduccode());
								pstaXs.setString(5, ydmInList.getProducname());
								pstaXs.setString(6, ydmInList.getSteelcode());
								pstaXs.setString(7, ydmInList.getSteelname());
								pstaXs.setString(8, ydmInList.getSpecCode());
								pstaXs.setString(9, ydmInList.getSpecName());
								pstaXs.setString(10, ydmInList.getModelCode());
								pstaXs.setString(11, ydmInList.getModelDesc());
								pstaXs.setString(12, ydmInList.getStdCode());
								pstaXs.setString(13, ydmInList.getStdName());
								pstaXs.setString(14, ydmInList.getBelongCode());
								pstaXs.setString(15, ydmInList.getBelongName());
								pstaXs.setString(16, ydmInList.getStdStyle());
								pstaXs.setString(17, ydmInList.getStdStyleDesc());
								
								pstaXs.setString(18, ydmInList.getActDimater());
								pstaXs.setString(19, ydmInList.getActHeight());
								pstaXs.setString(20, "");
								pstaXs.setString(21, "");
								pstaXs.setString(22, "");
								pstaXs.setString(23, ydmInList.getActLenMin());
								pstaXs.setString(24, ydmInList.getActLenMax());
								pstaXs.setString(25, ydmInList.getCreateName());
								pstaXs.setString(26, ydmInList.getActCount());
								pstaXs.setString(27, ydmInList.getActWeight());
								pstaXs.setString(28, ydmInList.getCreateTime());
								pstaXs.setString(29, ydmInList.getInstockTime());
								pstaXs.setString(30, ydmInList.getMatNo());
								pstaXs.setString(31, ydmInList.getMemo());
								pstaXs.setString(32, "1");
								pstaXs.setString(33, "1");
								pstaXs.setString(34, ydmInList.getProductFlag());
								pstaXs.setString(35, ydmInList.getMatStatus());
								pstaXs.setString(36, ydmInList.getActLen());

								pstaXs.setString(37, ydmInList.getJudgeStdName());
								pstaXs.setString(38, ydmInList.getBalYearMonth());
								pstaXs.setString(39, ydmInList.getPlineCode());
								pstaXs.setString(40, ydmInList.getPlineName());
								pstaXs.setString(41, ydmInList.getGradecode());
								pstaXs.setString(42, ydmInList.getGradename());
								pstaXs.executeUpdate();
								pstaXs.close();
							}
							insertSql = CoreXmlSqlParsersFactory
									.getSql("CorePipeInTemp.InsertButtress");
							psta = connection.prepareStatement(insertSql);
							psta.setString(1, ydmInList.getJudgeStoveNo());
							psta.setString(2, ydmInList.getBatchNo());
							psta.setString(3, ydmInList.getBatchGroudNo());
							psta.setString(4, ydmInList.getStorageNo());
							psta.setString(5, ydmInList.getStorageNo()
									+ "10101");
							psta.setString(6, ydmInList.getStorageTypeNo());
							psta.setString(7, ydmInList.getStorageTypeName());
							psta.setString(8, ydmInList.getCreateName());
							psta.setString(9, ydmInList.getMatNo());
							psta.setString(10, ydmInList.getCreateTime());
							psta.setString(11, ydmInList.getManagementNo());
							psta.setString(12, ydmInList.getManagementName());
							psta.setString(13, ydmInList.getDepartmentCode());
							psta.setString(14, ydmInList.getDepartmentDesc());
							psta.executeUpdate();
							psta.close();
						}
					}
					// 修改判定数据状态
					sqllistSqlServer.add(CoreXmlSqlParsersFactory
							.getSql("CorePipeInTemp.UPDATEINTERFACE2"));
					parmlistSqlServer.add(obj2);
					
					updateCancelProcess = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateCancelRedProcess");
					psta = connection.prepareStatement(updateCancelProcess);
					psta.setString(1, arrCancel[0]);
					psta.setString(2, arrCancel[1]);
					psta.setString(3, arrCancel[2]);
					psta.setString(4, arrCancel[3]);
					psta.executeUpdate();
					psta.close();
				}
				
				
			}
			connection.commit();
		} 
		catch (SQLException e)
		{
			e.printStackTrace();
		}

			for (int i = 0; i < pram.size(); i++) {
				if(pram.get(i).get(11).equals("801403"))
				{
					pram.get(i).remove(11);
					sqllist.add(CoreXmlSqlParsersFactory
							.getSql("CorePipeInTemp.UpdatePln"));
					parmlist.add(pram.get(i).toArray());
				}

			}
			for (int k = 0; k < list2.size(); k++) {
				// 删除入库表信息
				sqllist.add(CoreXmlSqlParsersFactory
						.getSql("CorePipeInTemp.DeleteInList"));
				parmlist.add(list2.get(k).toArray());
				
				//删除销售入库信息
				sqllist.add(CoreXmlSqlParsersFactory
						.getSql("CorePipeInTempXs.DeleteInList"));
				parmlist.add(list2.get(k).toArray());
			}
			
			this.getDao("MSSQL1Dao").ExcuteTransction(sqllistSqlServer,
					parmlistSqlServer);
			return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
					sqllist, parmlist);
		
    }

    /***
     * 根据入库单号 查询总支数、总重量
     * @param doc
     * @return
     */
    public CoreReturnObject getSumWgt(String doc)
    {
    	return this.getDataBySqlID("CorePipeInTemp.getSumWgt", new Object[]{doc});
    }
    /***
     * 查询物料表中数据是否变化
     * @param orderNo
     * @param orderNoseq
     * @param orderNoSeqno
     * @return
     */
    public CoreReturnObject queryMatNoStatus(String orderNo,String orderNoseq,String orderNoSeqno,String heatNo,String batchNo,String groupNo,String instockDoc)
    {
    	return this.getDataBySqlID("CorePipeInTemp.queryMatNoStatus", new Object[]{heatNo,batchNo,groupNo,instockDoc});
    }
    /**
     * 查询合同号+合同行号
     * @param pram 参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject getOrderNoSeq(ArrayList<String> pram) {
        return this.getDataBySqlID("CorePipeInTemp.GetOrderNoSeq", pram
                .toArray());
    }

    /**
     * 查询品种（扣型不为空）
     * @param pram 参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject getVarieties(ArrayList<String> pram) {
        return this.getDataBySqlID("CorePipeInTemp.GetVARIETIES", pram
                .toArray());
    }

    /**
     * 查询品种(扣型为空)
     * @param pram 参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject getVarieties1(ArrayList<String> pram) {
        return this.getDataBySqlID("CorePipeInTemp.GetVARIETIES1", pram
                .toArray());
    }

    /**
     * 查询品名
     * @return 平台统一返回对象
     */
    public CoreReturnObject getKind() {

        return this.getDataBySqlID("CorePipeInTemp.GETPRODUCT");
    }

    /**
     * 查询产品规格
     * @return 平台统一返回对象
     */
    public CoreReturnObject getSpec() {

        return this.getDataBySqlID("CorePipeInTemp.GETSPEC");
    }

    /**
     * 查询产品标准
     * @return 平台统一返回对象
     */
    public CoreReturnObject getSteel() {

        return this.getDataBySqlID("CorePipeInTemp.GETSTEEL");
    }

    /**
     * 查询钢级
     * @return 平台统一返回对象
     */
    public CoreReturnObject getModel() {

        return this.getDataBySqlID("CorePipeInTemp.GETMODEL");
    }

    /**
     * 根据合同查询
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject getOrderByProduct(ArrayList<Object> list) {
        return this.getDataBySqlID("CorePipeInTemp.GetOrderByProduct", list
                .toArray());
    }

    /**
     * 根据合同查询
     * @param list 传递参数
     * @return 平台统一返回对象
     */
    public CoreReturnObject getUpdateZbMatch(ArrayList<ArrayList<String>> list) {
        // CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        for (int i = 0; i < list.size(); i++) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CorePipeInTemp.getUpdateZbMatch"));
            parmlist.add(list.get(i).toArray());
            // cro=this.setData("MSSQL1Dao", sqllist, parmlist);
        }
        // return cro;
        return this.setData("MSSQL1Dao", sqllist, parmlist); // 执行事务处理（多个非查询，
        // 自动提交、回滚）
    }
    
    /***
     * 获取产销系统产线
     * @param factory
     * @return
     */
    public CoreReturnObject getFactory(String factory)
    {
    	return this.getDataBySqlID("CorePipeInTemp.getFactory", new Object[]{factory});
    }
    /***
     * 获取产销系统钢种
     * @return
     */
    public CoreReturnObject getGrade(String grade)
    {
    	return this.getDataBySqlID("CorePipeInTemp.getGrade", new Object[]{grade});
    }
    
    /***
     * 获取合同下缴库总量、估算总量、订货总量
     * @param orderNo
     * @return
     */
    public CoreReturnObject getOrderWgt(String orderNo)
    {
    	return this.getDataBySqlID("CorePipeInTemp.getOrderWgt", new Object[]{orderNo});
    }
    
    /***
     * 查询是否存在同合同数据
     * @param list
     * @return
     */
    public CoreReturnObject getMatchOrderNo(ArrayList<String> list)
    {
    	String sql =CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.getMatchOrderNo");
    	//String str= CoreConverter.toSqlConditionString("E.departid", arr);
    	//str += "AND (("+str+ " AND A.CREATE_DEPT IS NOT NULL) OR (A.CREATE_DEPT IS NULL))";
    	sql += " ORDER BY A.ORDER_NO,B.ORDER_SEQ ASC";
    	return this.getData(sql, list.toArray());
    }
    /***
     * 根据产品规格查找外径、壁厚
     * @param gg
     * @return
     */
    public CoreReturnObject getDiamter(String gg)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.getDiamter");
    	return this.getData(sql, new Object[]{gg});
    }
    
    /***
     * 根据rccid查询质保数据(红冲)
     * @param rccid
     * @return
     */
    public CoreReturnObject getSqlServerData(String rccid)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.getSqlServerData");
    	sql += " AND T.RCDID LIKE '"+rccid+"'";
    	return this.getData("MSSQL1Dao", sql);
    }
    
    /***
     * 根据炉批查找缴库数据(红冲)
     * @param heatNo
     * @param bacthNo
     * @return
     */
    public CoreReturnObject getInListData(String heatNo,String bacthNo)
    {
        return this.getDataBySqlID("CorePipeInTemp.getInListData", new Object[]{heatNo,bacthNo});	
    }
    
    /***
     * 缴库冲销
     * @return
     */
    public CoreReturnObject pipRedDashed(ArrayList<Object> parm1,
            ArrayList<Object> parm2, ArrayList<Object> parm3)
    {
    	CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        Date now = new Date();
        String inListDoc = ""; //入库单号
        String groupNo = "";//组号
        String sql = "";
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        String systime = dateFormat.format(now);
        Map<Object, Object> result = null;
       
        
        try {
            
            String deleteMatsql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.deleteMat");// 删除物料表
            PreparedStatement deleteMatpsta = connection.prepareStatement(deleteMatsql);
            
            String deleteMatsqlXs = CoreXmlSqlParsersFactory.getSql("CorePipeInTempXs.deleteMat");// 删除销售物料表
            PreparedStatement deleteMatpstaXs = connection.prepareStatement(deleteMatsqlXs);
            
            String deleteButtresssql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.deleteButtress");// 删除位置表
	        PreparedStatement deleteButtresspsta = connection.prepareStatement(deleteButtresssql);
            
	        String redInsertInListsql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.redInsertInList");// 插入入库表
	        PreparedStatement redInsertInListpsta = connection.prepareStatement(redInsertInListsql);
	        
	        
	        String redInsertInListsqlXs = CoreXmlSqlParsersFactory.getSql("CorePipeInTempXs.redInsertInList");// 插入入库表
	        PreparedStatement redInsertInListpstaXs = connection.prepareStatement(redInsertInListsqlXs);
	        
	        String updateMatWgtLensql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateMatWgtLen");// 修改物料重量长度
			PreparedStatement updateMatWgtLenpsta = connection.prepareStatement(updateMatWgtLensql);
			
			 String updateMatWgtLensqlXs = CoreXmlSqlParsersFactory.getSql("CorePipeInTempXs.updateMatWgtLen");// 修改销售物料重量长度
				PreparedStatement updateMatWgtLenpstaXs = connection.prepareStatement(updateMatWgtLensqlXs);
			
			String updateInListWgtLensql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateInListWgtLen"); //修改入库重量长度
			PreparedStatement updateInListWgtLenpsta = connection.prepareStatement(updateInListWgtLensql);
			
			String updateInListWgtLensqlXs = CoreXmlSqlParsersFactory.getSql("CorePipeInTempXs.updateInListWgtLen"); //修改入库重量长度
			PreparedStatement updateInListWgtLenpstaXs = connection.prepareStatement(updateInListWgtLensqlXs);
			
			
			String updateRedProcesssql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateRedProcess"); //写进程表
        	PreparedStatement updateRedProcesspsta = connection.prepareStatement(updateRedProcesssql);
        	
        	String updatePln2sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updatePln2"); //修改计划
            PreparedStatement updatePln2psta = connection.prepareStatement(updatePln2sql);
            connection.setAutoCommit(false); // 取消自动提交事务
            ArrayList<Object> sqlIDList = new ArrayList<Object>();
            ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
            ResultSet rs = null;
            int m =0;
            for(int i= 0;i<parm1.size();i++)
            {
            	ArrayList<String> matNo = new ArrayList<String>();//材料号
            	ArrayList<String> list2 = (ArrayList<String>) parm1.get(i);
            	inListDoc = list2.get(58);
            		//querySendSqlDoc(connection,list2.get(38),list2.get(35));
            	//groupNo = queryInListGroupNo(connection,list2.get(0),list2.get(1));
            	String lcode = list2.get(0).toString();
                String lotno = list2.get(1).toString();
                String group_No = list2.get(54).toString();//入库表中组号
                String flag = list2.get(53).toString();//材料类别
                String count = list2.get(42).toString();//冲红支数
                String inListSeq = querySendSql(connection, inListDoc);
                int n = Integer.parseInt(inListSeq.substring(inListSeq.length() - 4, inListSeq.length()));
                List<String[]> pipList = queryMatCount(connection,lcode,lotno); 
                String[] arrayStr = pipList.get(0);
                if(arrayStr[0]==null)
                {
                	cro.setV_errCode(-1);
                	cro.setV_errMsg("炉号"+lcode+"实际库存没有,不能进行冲红!");
                	return cro;
                }
                String acount = arrayStr[0].toString();
                //String inListMatNo = queryInListMatNoM(connection,lcode, lotno);
                int allcount = 0;
                ArrayList<String> wgtList = null;
                if(!list2.get(34).equals("")&& !list2.get(34).equals("0"))
                {
                	wgtList = new ArrayList<String>();
                	List<double[]> list = MeanValueCalculation.MeanCalculation(Math.abs(Double.parseDouble(list2.get(34))), Math.abs(Integer.parseInt(list2.get(2))));//重量
                	for(int k = 0;k<list.size();k++)
                    {
                    	double[] conLen = list.get(k);
                    	if((int)conLen[0]>0)
                    	{
                    		for(int x = 0;x<(int)conLen[0];x++)
                    		{
                    			DecimalFormat dt = new DecimalFormat("0.000");
                    			wgtList.add(dt.format(conLen[1]).toString());
                    		}
                    	}
                    }
                }
                ArrayList<String> lengthList = null;
                if(!list2.get(44).equals("") && !list2.get(44).equals("0"))
                {
                	lengthList = new ArrayList<String>();
                    List<double[]> lenList = MeanValueCalculation.MeanCalculation(Math.abs(Double.parseDouble(list2.get(44))), Math.abs(Integer.parseInt(list2.get(2))));
                    for(int k = 0;k<lenList.size();k++)
                    {
                    	double[] conLen = lenList.get(k);
                    	if((int)conLen[0]>0)
                    	{
                    		for(int x = 0;x<(int)conLen[0];x++)
                    		{
                    			DecimalFormat dt = new DecimalFormat("0.000");
                    			lengthList.add(dt.format(conLen[1]).toString());
                    		}
                    	}
                    }
                }
                ArrayList<String> calculateWgtList = null;
                if(!list2.get(56).equals("") && !list2.get(56).equals("0") && !list2.get(55).equals("") && list2.get(55).equals("0"))
                {
	                calculateWgtList = new ArrayList<String>();
	                List<double[]> calculateWgt = MeanValueCalculation.MeanCalculation(Math.abs(Double.parseDouble(list2.get(55))), Math.abs(Integer.parseInt(list2.get(56))));
	                for(int k = 0;k<calculateWgt.size();k++)
	                {
	                	double[] conLen = calculateWgt.get(k);
	                	if((int)conLen[0]>0)
	                	{
	                		for(int x = 0;x<(int)conLen[0];x++)
	                		{
	                			DecimalFormat dt = new DecimalFormat("0.000");
	                			calculateWgtList.add(dt.format(conLen[1]).toString());
	                		}
	                	}
	                }
                }
                ArrayList<String> calculateLenList =null;
                if(!list2.get(57).equals("")&& !list2.get(57).equals("0")&&!list2.get(56).equals("") && !list2.get(56).equals("0"))
                {
                	calculateLenList = new ArrayList<String>();
	                List<double[]> calculateLen = MeanValueCalculation.MeanCalculation(Math.abs(Double.parseDouble(list2.get(57))), Math.abs(Integer.parseInt(list2.get(56))));
	                for(int k = 0;k<calculateLen.size();k++)
	                {
	                	double[] conLen = calculateLen.get(k);
	                	if((int)conLen[0]>0)
	                	{
	                		for(int x = 0;x<(int)conLen[0];x++)
	                		{
	                			DecimalFormat dt = new DecimalFormat("0.000");
	                			calculateLenList.add(dt.format(conLen[1]).toString());
	                		}
	                	}
	                }
                }
                if((Integer.parseInt(count)+m+Integer.parseInt(acount))<0)
                {
                	cro.setV_errCode(-1);
                	cro.setV_errMsg("炉号"+lcode+"冲红支数比实际库存还多,不能进行冲红!");
                	return cro;
                }
                else if((Integer.parseInt(count)+m+Integer.parseInt(acount))==0)
                {
                	sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.getInListMatNo");
                	psta= connection.prepareStatement(sql);
                	psta.setString(1, lcode);
                	psta.setString(2, lotno);
                	psta.setString(3, group_No);
                	psta.setString(4, flag);
                	rs = psta.executeQuery();
                	while(rs.next())
                	{
                		matNo.add(rs.getString(1));
                		m++;
                	}
                	rs.close();
                	psta.close();
                	
					for (int j = 0; j < matNo.size(); j++) {
//						sql = CoreXmlSqlParsersFactory
//								.getSql("CorePipeInTemp.deleteMat");// 删除物料表
//						psta = connection.prepareStatement(sql);
						deleteMatpsta.setString(1, matNo.get(j));
						deleteMatpsta.addBatch();
						deleteMatpstaXs.setString(1, matNo.get(j));
						deleteMatpstaXs.addBatch();
//						deleteMatpsta.executeUpdate();
//						psta.close();

//						sql = CoreXmlSqlParsersFactory
//								.getSql("CorePipeInTemp.deleteButtress");// 删除位置表
//						psta = connection.prepareStatement(sql);
						deleteButtresspsta.setString(1, matNo.get(j));
						deleteButtresspsta.addBatch();
//						psta.executeUpdate();
//						psta.close();

//						sql = CoreXmlSqlParsersFactory
//								.getSql("CorePipeInTemp.redInsertInList");// 插入入库表
//						psta = connection.prepareStatement(sql);
						redInsertInListpsta.setString(1, list2.get(36));
						redInsertInListpsta.setString(2, list2.get(37));
						redInsertInListpsta.setString(3, inListDoc
				                + StringTool.formatDecimal(n, "0000"));
						redInsertInListpsta.setString(4, inListDoc);
						redInsertInListpsta.setString(5, list2.get(38));
						redInsertInListpsta.setString(6, "产出红冲");
						redInsertInListpsta.setString(7, matNo.get(j));
						redInsertInListpsta.setString(8, "");// 生产批号
						redInsertInListpsta.setString(9, "");
						redInsertInListpsta.setString(10, lcode);
						redInsertInListpsta.setString(11, lotno);
						redInsertInListpsta.setString(12, group_No);// 组号
						redInsertInListpsta.setString(13, list2.get(3));// 品名
						redInsertInListpsta.setString(14, list2.get(4));

						redInsertInListpsta.setString(15, list2.get(11));// 标准
						redInsertInListpsta.setString(16, list2.get(12));

						redInsertInListpsta.setString(17, list2.get(5));// 钢级
						redInsertInListpsta.setString(18, list2.get(6));

						redInsertInListpsta.setString(19, list2.get(15));// 标准类别
						redInsertInListpsta.setString(20, list2.get(16));

						redInsertInListpsta.setString(21, list2.get(7));// 产品规格
						redInsertInListpsta.setString(22, list2.get(8));

						redInsertInListpsta.setString(23, list2.get(9));// 扣型
						redInsertInListpsta.setString(24, list2.get(10));

						redInsertInListpsta.setString(25, list2.get(23));
						redInsertInListpsta.setString(26, list2.get(24));// 外径壁厚
						redInsertInListpsta.setString(27, list2.get(28));
						redInsertInListpsta.setString(28, list2.get(29));
						redInsertInListpsta.setString(29, "-1");
						
						redInsertInListpstaXs.setString(1, list2.get(36));
						redInsertInListpstaXs.setString(2, list2.get(37));
						redInsertInListpstaXs.setString(3, inListDoc
				                + StringTool.formatDecimal(n, "0000"));
						redInsertInListpstaXs.setString(4, inListDoc);
						redInsertInListpstaXs.setString(5, list2.get(38));
						redInsertInListpstaXs.setString(6, "产出红冲");
						redInsertInListpstaXs.setString(7, matNo.get(j));
						redInsertInListpstaXs.setString(8, "");// 生产批号
						redInsertInListpstaXs.setString(9, "");
						redInsertInListpstaXs.setString(10, lcode);
						redInsertInListpstaXs.setString(11, lotno);
						redInsertInListpstaXs.setString(12, group_No);// 组号
						redInsertInListpstaXs.setString(13, list2.get(3));// 品名
						redInsertInListpstaXs.setString(14, list2.get(4));

						redInsertInListpstaXs.setString(15, list2.get(11));// 标准
						redInsertInListpstaXs.setString(16, list2.get(12));

						redInsertInListpstaXs.setString(17, list2.get(5));// 钢级
						redInsertInListpstaXs.setString(18, list2.get(6));

						redInsertInListpstaXs.setString(19, list2.get(15));// 标准类别
						redInsertInListpstaXs.setString(20, list2.get(16));

						redInsertInListpstaXs.setString(21, list2.get(7));// 产品规格
						redInsertInListpstaXs.setString(22, list2.get(8));

						redInsertInListpstaXs.setString(23, list2.get(9));// 扣型
						redInsertInListpstaXs.setString(24, list2.get(10));

						redInsertInListpstaXs.setString(25, list2.get(23));
						redInsertInListpstaXs.setString(26, list2.get(24));// 外径壁厚
						redInsertInListpstaXs.setString(27, list2.get(28));
						redInsertInListpstaXs.setString(28, list2.get(29));
						redInsertInListpstaXs.setString(29, "-1");
						
						if (!list2.get(30).equals("")) {
							redInsertInListpsta.setString(30, "-"+wgtList.get(j));
							redInsertInListpstaXs.setString(30, "-"+wgtList.get(j));

						} else {
							redInsertInListpsta.setString(30, "0");
							redInsertInListpstaXs.setString(30, "0");

						}
						// redInsertInListpsta.setString(26, list2.get(24));
						redInsertInListpsta.setString(31, "");// 理论重量
						redInsertInListpsta.setString(32, list2.get(40));
						redInsertInListpsta.setString(33, list2.get(41));
						redInsertInListpsta.setString(34, list2.get(39));
						redInsertInListpsta.setString(35, list2.get(33));
						redInsertInListpsta.setString(36, "1");
						redInsertInListpsta.setString(37, list2.get(30));

						redInsertInListpsta.setString(38, systime);
						redInsertInListpsta.setString(39, list2.get(17));
						redInsertInListpsta.setString(40, list2.get(18));
						redInsertInListpsta.setString(41, list2.get(19));

						redInsertInListpsta.setString(42, list2.get(20));
						redInsertInListpsta.setString(43, list2.get(21));
						redInsertInListpsta.setString(44, list2.get(22));
						redInsertInListpsta.setString(45, list2.get(53));
						
						redInsertInListpstaXs.setString(31, "");// 理论重量
						redInsertInListpstaXs.setString(32, list2.get(40));
						redInsertInListpstaXs.setString(33, list2.get(41));
						redInsertInListpstaXs.setString(34, list2.get(39));
						redInsertInListpstaXs.setString(35, list2.get(33));
						redInsertInListpstaXs.setString(36, "1");
						redInsertInListpstaXs.setString(37, list2.get(30));

						redInsertInListpstaXs.setString(38, systime);
						redInsertInListpstaXs.setString(39, list2.get(17));
						redInsertInListpstaXs.setString(40, list2.get(18));
						redInsertInListpstaXs.setString(41, list2.get(19));

						redInsertInListpstaXs.setString(42, list2.get(20));
						redInsertInListpstaXs.setString(43, list2.get(21));
						redInsertInListpstaXs.setString(44, list2.get(22));
						redInsertInListpstaXs.setString(45, list2.get(53));
						
						if(list2.get(53).equals("801402"))
						{
							redInsertInListpsta.setString(46, "80150205");
							redInsertInListpstaXs.setString(46, "80150205");

						}else if(list2.get(53).equals("801403"))
						{
							redInsertInListpsta.setString(46, "80150301");
							redInsertInListpstaXs.setString(46, "80150205");

						}
						redInsertInListpsta.setString(47, systime);
						redInsertInListpsta.setString(48, list2.get(43));
						redInsertInListpstaXs.setString(47, systime);
						redInsertInListpstaXs.setString(48, list2.get(43));
						if (!list2.get(44).equals("")) {
							redInsertInListpsta.setString(49, "-"+lengthList.get(j));
							redInsertInListpstaXs.setString(49, "-"+lengthList.get(j));

						} else {
							redInsertInListpsta.setString(49, "");
							redInsertInListpstaXs.setString(49, "");

						}
						redInsertInListpsta.setString(50, list2.get(45));
						redInsertInListpsta.setString(51, list2.get(46));
						redInsertInListpsta.setString(52, list2.get(47));
						redInsertInListpsta.setString(53, list2.get(49));
						redInsertInListpsta.setString(54, list2.get(50));
						redInsertInListpsta.setString(55, list2.get(51));
						redInsertInListpsta.setString(56, list2.get(52));

						redInsertInListpsta.setString(57, list2.get(48));// 结算年月
						redInsertInListpsta.setString(58, systime);// 首次入库时间
						redInsertInListpsta.addBatch();
						
						redInsertInListpstaXs.setString(50, list2.get(45));
						redInsertInListpstaXs.setString(51, list2.get(46));
						redInsertInListpstaXs.setString(52, list2.get(47));
						redInsertInListpstaXs.setString(53, list2.get(49));
						redInsertInListpstaXs.setString(54, list2.get(50));
						redInsertInListpstaXs.setString(55, list2.get(51));
						redInsertInListpstaXs.setString(56, list2.get(52));

						redInsertInListpstaXs.setString(57, list2.get(48));// 结算年月
						redInsertInListpstaXs.setString(58, systime);// 首次入库时间
						redInsertInListpstaXs.addBatch();
						
						n++;
                	}
                }
                else if((Integer.parseInt(count)+m+Integer.parseInt(acount))>0)
                {
                	sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.getInListMatNo");
                	psta= connection.prepareStatement(sql);
                	psta.setString(1, lcode);
                	psta.setString(2, lotno);
                	psta.setString(3, group_No);
                	psta.setString(4, flag);
                	//psta.setInt(5, Math.abs(Integer.parseInt(count)));
                	rs = psta.executeQuery();
                	while(rs.next())
                	{
                		matNo.add(rs.getString(1));
                	}
                	rs.close();
                	psta.close();
                	for (int j = 0; j < Math.abs(Integer.parseInt(acount)); j++) {
//						sql = CoreXmlSqlParsersFactory
//								.getSql("CorePipeInTemp.deleteMat");// 删除物料表
//						psta = connection.prepareStatement(sql);
                		deleteMatpsta.setString(1, matNo.get(j));
						deleteMatpsta.addBatch();
						deleteMatpstaXs.setString(1, matNo.get(j));
						deleteMatpstaXs.addBatch();
						

//						sql = CoreXmlSqlParsersFactory
//								.getSql("CorePipeInTemp.deleteButtress");// 删除位置表
//						psta = connection.prepareStatement(sql);
						deleteButtresspsta.setString(1, matNo.get(j));
						deleteButtresspsta.addBatch();

//						sql = CoreXmlSqlParsersFactory
//								.getSql("CorePipeInTemp.redInsertInList");// 插入入库表
//						psta = connection.prepareStatement(sql);
						redInsertInListpsta.setString(1, list2.get(36));
						redInsertInListpsta.setString(2, list2.get(37));
						redInsertInListpsta.setString(3, inListDoc
				                + StringTool.formatDecimal(n, "0000"));
						redInsertInListpsta.setString(4, inListDoc);
						redInsertInListpsta.setString(5, list2.get(38));
						redInsertInListpsta.setString(6, "产出红冲");
						redInsertInListpsta.setString(7, matNo.get(j));
						redInsertInListpsta.setString(8, "");// 生产批号
						redInsertInListpsta.setString(9, "");
						redInsertInListpsta.setString(10, lcode);
						redInsertInListpsta.setString(11, lotno);
						redInsertInListpsta.setString(12, group_No);// 组号
						redInsertInListpsta.setString(13, list2.get(3));// 品名
						redInsertInListpsta.setString(14, list2.get(4));

						redInsertInListpsta.setString(15, list2.get(11));// 标准
						redInsertInListpsta.setString(16, list2.get(12));

						redInsertInListpsta.setString(17, list2.get(5));// 钢级
						redInsertInListpsta.setString(18, list2.get(6));

						redInsertInListpsta.setString(19, list2.get(15));// 标准类别
						redInsertInListpsta.setString(20, list2.get(16));

						redInsertInListpsta.setString(21, list2.get(7));// 产品规格
						redInsertInListpsta.setString(22, list2.get(8));

						redInsertInListpsta.setString(23, list2.get(9));// 扣型
						redInsertInListpsta.setString(24, list2.get(10));

						redInsertInListpsta.setString(25, list2.get(23));
						redInsertInListpsta.setString(26, list2.get(24));// 外径壁厚
						redInsertInListpsta.setString(27, list2.get(28));
						redInsertInListpsta.setString(28, list2.get(29));
						redInsertInListpsta.setString(29, "-1");
						
						redInsertInListpstaXs.setString(1, list2.get(36));
						redInsertInListpstaXs.setString(2, list2.get(37));
						redInsertInListpstaXs.setString(3, inListDoc
				                + StringTool.formatDecimal(n, "0000"));
						redInsertInListpstaXs.setString(4, inListDoc);
						redInsertInListpstaXs.setString(5, list2.get(38));
						redInsertInListpstaXs.setString(6, "产出红冲");
						redInsertInListpstaXs.setString(7, matNo.get(j));
						redInsertInListpstaXs.setString(8, "");// 生产批号
						redInsertInListpstaXs.setString(9, "");
						redInsertInListpstaXs.setString(10, lcode);
						redInsertInListpstaXs.setString(11, lotno);
						redInsertInListpstaXs.setString(12, group_No);// 组号
						redInsertInListpstaXs.setString(13, list2.get(3));// 品名
						redInsertInListpstaXs.setString(14, list2.get(4));

						redInsertInListpstaXs.setString(15, list2.get(11));// 标准
						redInsertInListpstaXs.setString(16, list2.get(12));

						redInsertInListpstaXs.setString(17, list2.get(5));// 钢级
						redInsertInListpstaXs.setString(18, list2.get(6));

						redInsertInListpstaXs.setString(19, list2.get(15));// 标准类别
						redInsertInListpstaXs.setString(20, list2.get(16));

						redInsertInListpstaXs.setString(21, list2.get(7));// 产品规格
						redInsertInListpstaXs.setString(22, list2.get(8));

						redInsertInListpstaXs.setString(23, list2.get(9));// 扣型
						redInsertInListpstaXs.setString(24, list2.get(10));

						redInsertInListpstaXs.setString(25, list2.get(23));
						redInsertInListpstaXs.setString(26, list2.get(24));// 外径壁厚
						redInsertInListpstaXs.setString(27, list2.get(28));
						redInsertInListpstaXs.setString(28, list2.get(29));
						redInsertInListpstaXs.setString(29, "-1");
						
						if (!list2.get(30).equals("")) {
							redInsertInListpsta.setString(30, "-"+wgtList.get(j));
							redInsertInListpstaXs.setString(30, "-"+wgtList.get(j));

						} else {
							redInsertInListpsta.setString(30, "0");
							redInsertInListpstaXs.setString(30, "0");

						}
						// redInsertInListpsta.setString(26, list2.get(24));
						redInsertInListpsta.setString(31, "");// 理论重量
						redInsertInListpsta.setString(32, list2.get(40));
						redInsertInListpsta.setString(33, list2.get(41));
						redInsertInListpsta.setString(34, list2.get(39));
						redInsertInListpsta.setString(35, list2.get(33));
						redInsertInListpsta.setString(36, "1");
						redInsertInListpsta.setString(37, list2.get(30));

						redInsertInListpsta.setString(38, systime);
						redInsertInListpsta.setString(39, list2.get(17));
						redInsertInListpsta.setString(40, list2.get(18));
						redInsertInListpsta.setString(41, list2.get(19));

						redInsertInListpsta.setString(42, list2.get(20));
						redInsertInListpsta.setString(43, list2.get(21));
						redInsertInListpsta.setString(44, list2.get(22));
						redInsertInListpsta.setString(45, list2.get(53));
						
						redInsertInListpstaXs.setString(31, "");// 理论重量
						redInsertInListpstaXs.setString(32, list2.get(40));
						redInsertInListpstaXs.setString(33, list2.get(41));
						redInsertInListpstaXs.setString(34, list2.get(39));
						redInsertInListpstaXs.setString(35, list2.get(33));
						redInsertInListpstaXs.setString(36, "1");
						redInsertInListpstaXs.setString(37, list2.get(30));

						redInsertInListpstaXs.setString(38, systime);
						redInsertInListpstaXs.setString(39, list2.get(17));
						redInsertInListpstaXs.setString(40, list2.get(18));
						redInsertInListpstaXs.setString(41, list2.get(19));

						redInsertInListpstaXs.setString(42, list2.get(20));
						redInsertInListpstaXs.setString(43, list2.get(21));
						redInsertInListpstaXs.setString(44, list2.get(22));
						redInsertInListpstaXs.setString(45, list2.get(53));
						
						if(list2.get(53).equals("801402"))
						{
							redInsertInListpsta.setString(46, "80150205");
							redInsertInListpstaXs.setString(46, "80150205");

						}else if(list2.get(53).equals("801403"))
						{
							redInsertInListpsta.setString(46, "80150301");
							redInsertInListpstaXs.setString(46, "80150301");

						}
						redInsertInListpsta.setString(47, systime);
						redInsertInListpsta.setString(48, list2.get(43));
						redInsertInListpstaXs.setString(47, systime);
						redInsertInListpstaXs.setString(48, list2.get(43));
						if (!list2.get(44).equals("")) {
							redInsertInListpsta.setString(49, "-"+lengthList.get(j));
							redInsertInListpstaXs.setString(49, "-"+lengthList.get(j));

						} else {
							redInsertInListpsta.setString(49, "");
							redInsertInListpstaXs.setString(49, "");

						}
						redInsertInListpsta.setString(50, list2.get(45));
						redInsertInListpsta.setString(51, list2.get(46));
						redInsertInListpsta.setString(52, list2.get(47));
						redInsertInListpsta.setString(53, list2.get(49));
						redInsertInListpsta.setString(54, list2.get(50));
						redInsertInListpsta.setString(55, list2.get(51));
						redInsertInListpsta.setString(56, list2.get(52));

						redInsertInListpsta.setString(57, list2.get(48));// 结算年月
						redInsertInListpsta.setString(58, systime);// 首次入库时间
						redInsertInListpsta.addBatch();
						
						redInsertInListpstaXs.setString(50, list2.get(45));
						redInsertInListpstaXs.setString(51, list2.get(46));
						redInsertInListpstaXs.setString(52, list2.get(47));
						redInsertInListpstaXs.setString(53, list2.get(49));
						redInsertInListpstaXs.setString(54, list2.get(50));
						redInsertInListpstaXs.setString(55, list2.get(51));
						redInsertInListpstaXs.setString(56, list2.get(52));

						redInsertInListpstaXs.setString(57, list2.get(48));// 结算年月
						redInsertInListpstaXs.setString(58, systime);// 首次入库时间
						redInsertInListpstaXs.addBatch();
						
						n++;
                	}
                	for(int k = Math.abs(Integer.parseInt(count));k<matNo.size();k++)
                	{
//						sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateMatWgtLen");// 修改重量长度
//						psta = connection.prepareStatement(sql);
                		updateMatWgtLenpsta.setString(1, calculateWgtList.get(k));
                		updateMatWgtLenpsta.setString(2, calculateLenList.get(k));
                		updateMatWgtLenpsta.setString(3, matNo.get(k));
                		updateMatWgtLenpsta.addBatch();
                		updateMatWgtLenpstaXs.setString(1, calculateWgtList.get(k));
                		updateMatWgtLenpstaXs.setString(2, calculateLenList.get(k));
                		updateMatWgtLenpstaXs.setString(3, matNo.get(k));
                		updateMatWgtLenpstaXs.addBatch();
						
						
//						sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateInListWgtLen");
//						psta = connection.prepareStatement(sql);
                		updateInListWgtLenpsta.setString(1, calculateWgtList.get(k));
                		updateInListWgtLenpsta.setString(2, calculateLenList.get(k));
                		updateInListWgtLenpsta.setString(3, matNo.get(k));
                		updateInListWgtLenpsta.addBatch();
                		
                		updateInListWgtLenpstaXs.setString(1, calculateWgtList.get(k));
                		updateInListWgtLenpstaXs.setString(2, calculateLenList.get(k));
                		updateInListWgtLenpstaXs.setString(3, matNo.get(k));
                		updateInListWgtLenpstaXs.addBatch();
                		
					}
                }
                
//                	sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.updateRedProcess");
//                	psta = connection.prepareStatement(sql);
				updateRedProcesspsta.setString(1, list2.get(42));
				updateRedProcesspsta.setString(2, list2.get(34));
				updateRedProcesspsta.setString(3, list2.get(44));
				updateRedProcesspsta.setString(4, list2.get(21));
				updateRedProcesspsta.addBatch();
				
            }
            for (int i = 0; i < parm2.size(); i++) {
                ArrayList<Object> list4 = (ArrayList<Object>) parm2.get(i);
                List<String[]> pipFList = queryMatCount(connection,list4.get(6).toString(),list4.get(7).toString(),list4.get(8).toString(),list4.get(9).toString()); 
                String[] arrayFStr = pipFList.get(0);
                if(arrayFStr[0] !=null && arrayFStr[1] !=null)
                {
					updatePln2psta.setString(1, list4.get(3).toString());
					updatePln2psta.setString(2, list4.get(4).toString());
					updatePln2psta.setString(3, list4.get(5).toString());
					updatePln2psta.setString(4, arrayFStr[0].toString());
					updatePln2psta.setString(5, list4.get(3).toString());
					updatePln2psta.setString(6, list4.get(4).toString());
					updatePln2psta.setString(7, list4.get(5).toString());
					updatePln2psta.setString(8, arrayFStr[1].toString());
					updatePln2psta.setString(9, list4.get(2).toString());
					updatePln2psta.setString(10, list4.get(3).toString());
					updatePln2psta.setString(11, list4.get(4).toString());
					updatePln2psta.setString(12, list4.get(5).toString());
					updatePln2psta.addBatch();
                }
            }
			result = this.getDao("TgDao").CoreBeginTranscation();
			for (int i = 0; i < parm3.size(); i++) {
					sql = CoreXmlSqlParsersFactory
							.getSql("CorePipeInTemp.UPDATEINTERFACE1");
					ArrayList<Object> list3 = (ArrayList<Object>) parm3.get(i);
					Object[] obj = list3.toArray();
					cro = this.setData("MSSQL1Dao", sql, obj);
		    }
		    cro = this.getDao("TgDao").ExcuteTransction(sqlIDList, parmlist);
		    this.getDao("TgDao").CoreCommit(result);
		    deleteMatpsta.executeBatch();
		    deleteMatpstaXs.executeBatch();

		    deleteButtresspsta.executeBatch();
		    redInsertInListpsta.executeBatch();
		    redInsertInListpstaXs.executeBatch();
		    updateMatWgtLenpsta.executeBatch();
		    updateMatWgtLenpstaXs.executeBatch();
		    updateInListWgtLenpsta.executeBatch();
		    updateInListWgtLenpstaXs.executeBatch();
		    updateRedProcesspsta.executeBatch();
		    updatePln2psta.executeBatch();
			cro.setV_errMsg("缴库红冲成功!");
			cro.setResult(1);
			connection.commit();
        }catch (Exception e) {
            System.out.println(e.getMessage());
            if (connection != null) {
                try {
                	this.getDao("TgDao").CoreRollBack(result);
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cro;
    }
    
    /***
     * 查找库存中的支数、重量、长度
     * @param con
     * @param lcode
     * @param lotno
     * @return
     */
    public static List<String[]>  queryMatCount(Connection con,String lcode,String lotno)
    {
    	int count = 0;
    	double wgt = 0.0;
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.queryMatCount");
    	PreparedStatement psta;
    	List<String[]> list = new ArrayList<String[]>();
		try {
			psta = con.prepareStatement(sql);
			psta.setString(1, lcode);
			psta.setString(2, lotno);
//			psta.setString(3, group_No);
//			psta.setString(4, flag);
	    	ResultSet rs = psta.executeQuery();
	    	if(rs.next())
	    	{
	    		String[] arr = new String[3];
	    		arr[0] = rs.getString("ACOUNT");
	    		arr[1] = rs.getString("AWEIGHT");
	    		arr[2] = rs.getString("LEN");
	    		list.add(arr);
	    	}
	    	rs.close();
	    	psta.close();
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
    	
    	return list;
    }
    
    public static List<String[]>  queryMatCount(Connection con,String lcode,String lotno,String groupNo,String flag)
    {
    	int count = 0;
    	double wgt = 0.0;
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.queryInListCountWgt");
    	PreparedStatement psta;
    	List<String[]> list = new ArrayList<String[]>();
		try {
			psta = con.prepareStatement(sql);
			psta.setString(1, lcode);
			psta.setString(2, lotno);
			psta.setString(3, groupNo);
			psta.setString(4, flag);
	    	ResultSet rs = psta.executeQuery();
	    	if(rs.next())
	    	{
	    		String[] arr = new String[3];
	    		arr[0] = rs.getString("ACOUNT");
	    		arr[1] = rs.getString("AWEIGHT");
	    		arr[2] = rs.getString("LEN");
	    		list.add(arr);
	    	}
	    	rs.close();
	    	psta.close();
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
    	return list;
    }
    
    /***
     * 查询撤销商品的总支数、重量、长度
     * @param con
     * @param inListDoc
     * @return
     */
    public List<String[]> getCancelSumWgt(Connection con,String inListDoc)
    {
    	int count = 0;
    	double wgt = 0.0;
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.queryCancelInListCountWgt");
    	PreparedStatement psta;
    	List<String[]> list = new ArrayList<String[]>();
		try {
			psta = con.prepareStatement(sql);
			psta.setString(1, inListDoc);
	    	ResultSet rs = psta.executeQuery();
	    	if(rs.next())
	    	{
	    		String[] arr = new String[4];
	    		arr[0] = rs.getString("ACOUNT");
	    		arr[1] = rs.getString("AWEIGHT");
	    		arr[2] = rs.getString("LEN");
	    		arr[3] = rs.getString("ORD_LN_DLY_PK");
	    		list.add(arr);
	    	}
	    	rs.close();
	    	psta.close();
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
    	return list;
    }
    
    /***
     * 缴库前改变质保数据状态
     * @param parm
     * @return
     */
    public CoreReturnObject updateStaus(ArrayList<Object> parm)
    {
    	Map<Object, Object> result = null;
    	CoreReturnObject cro = null;
    	String sql = "";
    	try
    	{
    	
    		result = this.getDao("TgDao").CoreBeginTranscation();
			for (int i = 0; i < parm.size(); i++) {
				sql = CoreXmlSqlParsersFactory
						.getSql("CorePipeInTemp.updateStausZB");
				ArrayList<Object> list3 = (ArrayList<Object>) parm.get(i);
				Object[] obj = list3.toArray();
				cro = this.setData("MSSQL1Dao", sql, obj);
			}
			cro.setResult(1);
			cro.setV_errMsg("剔除成功!");
			this.getDao("TgDao").CoreCommit(result);
    	}catch (Exception e) {
		    this.getDao("TgDao").CoreRollBack(result);	
		}
    	return cro;
    }
    
    /***
     * 外购下产线
     * @return
     */
    public CoreReturnObject getWg()
    {
    	return this.getDataBySqlID("CorePipeInTemp.getWg");
    }
    /***
     * 倒库下产线
     * @return
     */
    public CoreReturnObject getDk()
    {
    	return this.getDataBySqlID("CorePipeInTemp.getDk");
    }
    /***
     * 外委下产线
     * @return
     */
    public CoreReturnObject getWw()
    {
    	return this.getDataBySqlID("CorePipeInTemp.getWw");
    }
    
    /***
     * 查询是否有质量封锁
     * @param heatNo
     * @param bacthNO
     * @param groupNo
     * @return
     */
    public CoreReturnObject getLockFlag(String heatNo,String bacthNO,String groupNo)
    {
    	return this.getDataBySqlID("CorePipeInTemp.getLockFlag", new Object[]{heatNo,bacthNO,groupNo});
    }
    
    /***
     * 查询合同类型
     * @return
     */
    public CoreReturnObject doQueryOrderType(String orderNo)
    {
    	return this.getDataBySqlID("CorePipeInTemp.doQueryOrderType", new Object[]{orderNo});
    }
    /***
     * 查询是否存在商品
     * @return
     */
    public CoreReturnObject doQueryProFlag(ArrayList<String> list)
    {
    	return this.getDataBySqlID("CorePipeInTemp.doQueryProFlag", list.toArray());
    }
    /***
     * 查询成品类别
     * @return
     */
    public CoreReturnObject getFinishedProduct()
    {
    	return this.getDataBySqlID("CorePipeInTemp.getFinishedProduct");
    }
//    public CoreReturnObject getFinishedProduct1()
//    {
//    	return this.getDataBySqlID("CorePipeInTemp.getFinishedProduct1");
//    }
//   
    /***
     * 获取实时期末库存
     */
    public CoreReturnObject getRealTimeStore(String[] arr,String bathYear)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.getRealTimeStore");
    	String str  = CoreConverter.toSqlConditionString("F.BELONG_CODE", arr);
    	String str1  = CoreConverter.toSqlConditionString("T1.BELONG_CODE", arr);
    	sql = sql.replace("#CONDITIONS#", str);
    	sql = sql.replace("#CONDITIONS1#", str1);
    	return this.setData(sql,new Object[]{bathYear});
    }
    /***
     * 查询是否有期初数据
     * @param arr
     * @param bathYear
     * @return
     */
    public CoreReturnObject selectNowInial(String[] arr,String bathYear)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("CorePipeInTemp.selectNowInial");
    	sql += CoreConverter.toSqlConditionString("T.BELONG_CODE", arr);
    	return this.getData(sql, new Object[]{bathYear});
    }
}
