package com.steering.ydm.bc;

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

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

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.common.StringTool;
import com.steering.mes.mcp.entity.MatBcMEntity;
import com.steering.mes.mcp.entity.YdmBcOutlistEntity;
import com.steering.mes.mcp.entity.YdmBcScrapoutlistEntity;

public class FrmDeleteMatBcM extends DBCommon{

	/***
	 * 查询
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject doQuery(ArrayList<String> parmList,String[] arr,String[] belongCodes)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.doQuery");
		String str1 = CoreConverter.toSqlConditionString("T.PLINE_CODE",arr);

		sql = sql.replace("#PLINE_CODE#",str1);

		if(!parmList.get(0).equals(""))
		{
			sql = sql.replace("#BAL_YEAR_MONTH#", " AND T.BAL_YEAR_MONTH = '"+parmList.get(0)+"'");
		}else
		{
			sql = sql.replace("#BAL_YEAR_MONTH#", "");
		}
		if(!parmList.get(1).equals(""))
		{
			sql = sql.replace("#JUDGE_STOVE_NO#", " AND T.JUDGE_STOVE_NO = '"+parmList.get(1)+"'");
		}else
		{
			sql = sql.replace("#JUDGE_STOVE_NO#", "");
		}
		sql = sql.replace("#BELONG_CODE#",CoreConverter.toSqlConditionString("T.BELONG_CODE",belongCodes));
		String str = " GROUP BY T.PRODUCT_FLAG,T.MAT_STATUS,T.LOT_NO,T.JUDGE_STOVE_NO,T.BATCH_NO,T.BATCH_GROUD_NO,T.STOVE_NO,T.MEMO,T.FLAG_STOVE_NO_ZG,";
		str += " T.PRO_ORDER_ID,T.QCM_STAUS,T.PRO_ORDER_NO,T.PRO_PLAN_ID_NEXT,T.GX_PLAN_NO_NEXT,S.STORAGE_NO,T.JUDGE_RESULT,T.MATERIAL_NO,T.MATERIAL_NAME,";
		str += " T.PROCESS_CDOE,T.PROCESS_DESC,T.PLINE_CODE,T.PLINE_NAME,T.BELONG_CODE,T.BELONG_NAME,T.GX_PLAN_NO,T.SCRAP_REASON,T.SCRAP_FRIM_FLAG,T.REDCHONG_FLAG,T.HANGING_FLAG";
		sql = sql.replace("#GROUP#", str);
		return this.getData(sql);
	}
	/***
	 * 查询废品
	 * @return
	 */
	public CoreReturnObject doQueryScrapList(ArrayList<String> scrapList)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.doQueryScrapList");
		if(!scrapList.get(0).equals(""))
		{
			sql += " AND T.BAL_YEAR_MONTH = '"+scrapList.get(0)+"'";
		}
		sql += " ORDER BY T.CRATE_TIME ASC";
		
		return this.getData(sql);
	}
	/***
	 * 查询废品出库详细信息
	 * @param outDoc
	 * @return
	 */
	public CoreReturnObject doQueryScrapOutList(String outDoc)
	{
		return this.getDataBySqlID("FrmDeleteMatBcM.doQueryScrapOutList", new Object[]{outDoc});
	}
	
	/***
	 * 删除数据
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject deleteMatBcMData(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String systime = dateFormat.format(now);
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str, MatBcMEntity.class);
				if(matBcEntity.getQcmStaus().equals("合格"))
				{
					matBcEntity.setQcmStaus("00");
				}else if(matBcEntity.getQcmStaus().equals("待处理"))
				{
				    matBcEntity.setQcmStaus("11");	
				}else if(matBcEntity.getQcmStaus().equals("判废"))
				{
					matBcEntity.setQcmStaus("22");
				}
				matBcEntity.setCreateTime(systime);
				String deleteSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.deleteMatBcMData");
				deleteSql = EntityTool.fillSqlByEntity(deleteSql, matBcEntity);
				sqllist.add(deleteSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("删除成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
		}

	/***
	 *修改标识炉号
	 * @return
	 */
	public CoreReturnObject  updateFlagStoveNo(ArrayList<String>parmList) {

		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str, MatBcMEntity.class);
				if(matBcEntity.getQcmStaus().equals("合格"))
				{
					matBcEntity.setQcmStaus("00");
				}else if(matBcEntity.getQcmStaus().equals("待处理"))
				{
					matBcEntity.setQcmStaus("11");
				}else if(matBcEntity.getQcmStaus().equals("判废"))
				{
					matBcEntity.setQcmStaus("22");
				}
				String updateFlagStoveNoSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.updateFlagStoveNo");
				updateFlagStoveNoSql = EntityTool.fillSqlByEntity(updateFlagStoveNoSql, matBcEntity);
				sqllist.add(updateFlagStoveNoSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}


	/***
	 * 调整库存位置
	 * @param parmList
	 * @return
	 */
	 public CoreReturnObject adjustStorageNo(ArrayList<String> parmList,String storageNo)
	 {
		 CoreReturnObject cro = new CoreReturnObject();
			Connection connection = this.getDao(CoreConstantData.sysbeanstr)
					.getConnection();
			String sql = "";
			PreparedStatement psta = null;
			ResultSet rs = null;
			try {
				ArrayList<String> sqllist = new ArrayList<String>();
				for(String str : parmList)
				{
					MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str, MatBcMEntity.class);
					if(matBcEntity.getQcmStaus().equals("合格"))
					{
						matBcEntity.setQcmStaus("00");
					}else if(matBcEntity.getQcmStaus().equals("待处理"))
					{
					    matBcEntity.setQcmStaus("11");	
					}else if(matBcEntity.getQcmStaus().equals("判废"))
					{
						matBcEntity.setQcmStaus("22");
					}
					String updateStorageSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.adjustStorageNo");
					updateStorageSql = updateStorageSql.replace("#NEW_STORAGE_NO#", storageNo);
					updateStorageSql = EntityTool.fillSqlByEntity(updateStorageSql, matBcEntity);
					sqllist.add(updateStorageSql);
				}
				cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
				if(cro.getV_errMsg().equals(""))
				{
					cro.setV_errMsg("调整成功!");
				}
			} catch (Exception e) {
				System.out.println(e.getMessage());
				if (connection != null) {
					try {
						cro.setV_errMsg(e.getMessage());
						connection.rollback(); // 回滚事务
					} catch (Exception e2) {
					}
				}
			} finally {
				try {
					if (connection != null && !connection.isClosed()) {
						connection.close();
					}
				} catch (Exception e2) {
				}
			}
			return cro;
	 }
	/***
	 * 查询重量
	 * @return
	 */
	public CoreReturnObject doQueryWeight(String matBcEntity)
	{
		MatBcMEntity matBcTity = EntityTool.getEntityByJSONStr(matBcEntity, MatBcMEntity.class);
		String sql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.doQueryWeight");
		sql = EntityTool.fillSqlByEntity(sql, matBcTity);
		return this.getData(sql);
		
	}
	
	/***
     * 获取所有仓库
     * @return
     */
    public CoreReturnObject getStorageNo()
    {
    	return this.getDataBySqlID("FrmDeleteMatBcM.getStorageNo");
    }
	/***
	 * 获取所有管坯仓库
	 * @return
	 */
	public CoreReturnObject getStorageNoGp()
	{
		return this.getDataBySqlID("FrmDeleteMatBcM.getStorageNoGp");
	}

	/***
	 * 获取所有物料码
	 * @return
	 */
    public CoreReturnObject getProcessMaterial()
	{
		return this.getDataBySqlID("FrmDeleteMatBcM.getProcessMaterial");
	}
	
    /***
     * 修改物料码
     * @param parmList
     * @return
     */
    public CoreReturnObject updateMaterial(ArrayList<String> parmList,String userName)
    {
    	CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
        "yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat df1 = new SimpleDateFormat("yyyyMM");
        String systime = dateFormat.format(now);
        //String yearMoth = df1.format(now);
		String yearMoth = ""; //改25号结转
		String outDoc = "";//出库单号
		String inDoc = "";//入库单号
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			outDoc = doQueryOutDoc(connection);
			inDoc = doQueryInDoc(connection);
			for(String str : parmList)
			{
				MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str, MatBcMEntity.class);
				yearMoth = StringTool.GetBalYear(now,StringTool.GetSupplyUnit(matBcEntity.getPlineCode())); //改25号结转
				matBcEntity.setInstockDoc(inDoc);
				matBcEntity.setOutstockDoc(outDoc);
				matBcEntity.setCreateTime(systime);
				matBcEntity.setBalYearMonth(yearMoth);
				matBcEntity.setCreateName(userName);
//				if(matBcEntity.getPlineCode().equals("100101") ||matBcEntity.getPlineCode().equals("100102")||matBcEntity.getPlineCode().equals("100103"))
//				{
//					if(matBcEntity.getProcessCdoe().equals("D"))
//					{
//						matBcEntity.setNewPlineCode("C008");
//						matBcEntity.setNewPlineName("250机组");
//					}else if(matBcEntity.getProcessCdoe().equals("E"))
//					{
//						matBcEntity.setNewPlineCode("C018");
//						matBcEntity.setNewPlineName("720旋扩");
//					}
//					else if(matBcEntity.getProcessCdoe().equals("F"))
//					{
//						matBcEntity.setNewPlineCode("C022");
//						matBcEntity.setNewPlineName("热处理01#（管加工1号热）");
//					}else
//					{
//						matBcEntity.setNewPlineCode(matBcEntity.getPlineCode());
//						matBcEntity.setNewPlineName(matBcEntity.getPlineName());
//					}
//				}else
//				{
					matBcEntity.setNewPlineCode(matBcEntity.getPlineCode());
					matBcEntity.setNewPlineName(matBcEntity.getPlineName());
				//}
				String insertOutInSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.insertOutIn");
				insertOutInSql = EntityTool.fillSqlByEntity(insertOutInSql, matBcEntity);
				sqllist.add(insertOutInSql);
				
				String updateSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.updateMaterial");
				updateSql = EntityTool.fillSqlByEntity(updateSql, matBcEntity);
				sqllist.add(updateSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
    }
    
    /***
	 * 出库单号
	 * @param
	 * @return
	 */
	private String doQueryOutDoc(Connection con) {
		String outDoc = "";
		String sql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.doQueryOutDoc");
		PreparedStatement psta = null;
		try {
			psta = con.prepareStatement(sql);
			ResultSet rs = psta.executeQuery();
			if(rs.next())
			{
				outDoc = rs.getString("OUTSTOCK_DOC");
			}
			rs.close();
			psta.close();
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return outDoc;
	}
	/***
	 * 生成入库单号
	 * @param
	 * @return
	 */
	private String doQueryInDoc(Connection con) {
		String inDoc = "";
		String sql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.doQueryInDoc");
		PreparedStatement psta = null;
		try {
			psta = con.prepareStatement(sql);
			ResultSet rs = psta.executeQuery();
			if(rs.next())
			{
				inDoc = rs.getString("INSTOCK_DOC");
			}
			rs.close();
			psta.close();
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return inDoc;
	}
    /***
     * 修改备注
     * @param parmList
     * @return
     */
    public CoreReturnObject updateMemo(ArrayList<String> parmList)
    {
    	CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str, MatBcMEntity.class);
				if(matBcEntity.getQcmStaus().equals("合格"))
				{
					matBcEntity.setQcmStaus("00");
				}else if(matBcEntity.getQcmStaus().equals("判废"))
				{
					matBcEntity.setQcmStaus("22");
				}else if(matBcEntity.getQcmStaus().equals("待处理"))
				{
					matBcEntity.setQcmStaus("11");
				}
				String updateSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.updateMemo");
				updateSql = EntityTool.fillSqlByEntity(updateSql, matBcEntity);
				sqllist.add(updateSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
    }

	/**
	 * 修改离线原因
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updateReason(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str, MatBcMEntity.class);
				String updateSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.updateReason");
				updateSql = EntityTool.fillSqlByEntity(updateSql, matBcEntity);
				sqllist.add(updateSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	/**
	 * 修改责任单位
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updateBelongCodeResponse(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str, MatBcMEntity.class);
				String updateSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.updateBelongCodeResponse");
				updateSql = EntityTool.fillSqlByEntity(updateSql, matBcEntity);
				sqllist.add(updateSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	/***
	 * 建立期初
	 * @return
	 */
	public CoreReturnObject setUpIntial()
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			
			String insertIntialSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.setUpIntial");
			sqllist.add(insertIntialSql);
			
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("期初建立成功!");
			}
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
		}
	/***
	 * 废品出库
	 * @return
	 */
	public CoreReturnObject scrapOut(ArrayList<String> parmList,String loadStorageNo,String loadStorageName,String userName)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String systime = dateFormat.format(now);
		//String bathYear = df.format(now);
		String bathYear = StringTool.GetBalYear(now,StringTool.GetSupplyUnit(EntityTool.getEntityByJSONStr(parmList.get(0), MatBcMEntity.class).getPlineCode())); //改25号结转
		String outDoc = "";//出库单号
		int allCount = 0;
		double allWgt = 0.0;
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		int scrapCount = 0;
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			outDoc = getOutListDoc(connection,"800803");
			
			for(String str : parmList)
			{
				MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str, MatBcMEntity.class);
				matBcEntity.setOutstockDoc(outDoc);
				matBcEntity.setOutstockTypeCode("800803");
				matBcEntity.setOutstockTypeName("倒库出库");
				matBcEntity.setCreateName(userName);
				matBcEntity.setOutstockTime(systime);
				matBcEntity.setBalYearMonth(bathYear);
				matBcEntity.setLoadPlineCode(loadStorageNo);
				matBcEntity.setLoadPlineName(loadStorageName);
				
				sql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.scrapAcount");
				sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					scrapCount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if(Integer.parseInt(matBcEntity.getActCount()) > scrapCount)
				{
					cro.setV_errMsg("废品出库支数大于废品审核支数,请刷新页面!");
					return cro;
				}
				
				String insertOutSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.scrapOut");
				insertOutSql = EntityTool.fillSqlByEntity(insertOutSql,matBcEntity);
				sqllist.add(insertOutSql);
				
				allCount = allCount + Integer.parseInt(matBcEntity.getActCount());
				allWgt = allWgt + Double.parseDouble(matBcEntity.getActWeight());
			}
			YdmBcScrapoutlistEntity ydmScrapOutEntity = new YdmBcScrapoutlistEntity();
			ydmScrapOutEntity.setOutstockDoc(outDoc);
			ydmScrapOutEntity.setOutstockTypeCode("800803");
			ydmScrapOutEntity.setOutstockTypeName("倒库出库");
			ydmScrapOutEntity.setFlagStoveNo(EntityTool.getEntityByJSONStr(parmList.get(0), MatBcMEntity.class).getFlagStoveNoZg());
			ydmScrapOutEntity.setActCount(String.valueOf(allCount));
			ydmScrapOutEntity.setActWeight(String.valueOf(allWgt));
			ydmScrapOutEntity.setCrateName(userName);
			ydmScrapOutEntity.setCrateTime(systime);
			ydmScrapOutEntity.setBalYearMonth(bathYear);
			String insertScraOutListSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.insertYdmBcScrap");
			insertScraOutListSql = EntityTool.fillSqlByEntity(insertScraOutListSql, ydmScrapOutEntity);
			sqllist.add(insertScraOutListSql);
			
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("出库成功!");
			}
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	/***
	 * 撤销废品出库清单
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject cancelScrapOut(ArrayList<String> parmList,String userName)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
			     YdmBcScrapoutlistEntity ydmEntity = EntityTool.getEntityByJSONStr(str, YdmBcScrapoutlistEntity.class);
			     ydmEntity.setCrateName(userName);
			     String cancelScrapSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.cancelScrapOut");
			     cancelScrapSql = EntityTool.fillSqlByEntity(cancelScrapSql, ydmEntity);
			     sqllist.add(cancelScrapSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("撤销成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	/***
	 * 逐炉撤销废品出库
	 * @return
	 */
	public CoreReturnObject cancelScrapJudgeNo(ArrayList<String> parmList,String userName)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
			     YdmBcOutlistEntity ydmEntity = EntityTool.getEntityByJSONStr(str, YdmBcOutlistEntity.class);
			     ydmEntity.setCreateName(userName);
			     String cancelScrapSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.cancelScrapJudgeNo");
			     cancelScrapSql = EntityTool.fillSqlByEntity(cancelScrapSql, ydmEntity);
			     sqllist.add(cancelScrapSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("撤销成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	
	/***
	 * 回报废品过磅量
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updatePorssWgt(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				YdmBcScrapoutlistEntity ydmBcEntity = EntityTool.getEntityByJSONStr(str, YdmBcScrapoutlistEntity.class);
				String updatePorssSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.updatePorssWgt");
				updatePorssSql = EntityTool.fillSqlByEntity(updatePorssSql, ydmBcEntity);
				sqllist.add(updatePorssSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("回报成功!");
			}
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	/***
	 * 责任单位修改
	 * @return
	 */
	public CoreReturnObject belongResponse(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				YdmBcOutlistEntity ydmBcOutEntity = EntityTool.getEntityByJSONStr(str, YdmBcOutlistEntity.class);
				String updateBelongSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.belongResponse");
				updateBelongSql = EntityTool.fillSqlByEntity(updateBelongSql, ydmBcOutEntity);
				sqllist.add(updateBelongSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	
	/***
	 * 置余材
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject takeBill(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str: parmList)
			{
				int count = 0;
				MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(str, MatBcMEntity.class);
				String sql = CoreXmlSqlParsersFactory
						.getSql("FrmDeleteMatBcM.QuerytakeBill");
				sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
				PreparedStatement pst = connection.prepareStatement(sql);
				ResultSet rs = pst.executeQuery();
				if (rs.next()) {
					count = Integer.parseInt(rs.getString("ACT_COUNT"));
				}
				rs.close();
				pst.close();
				if(count == 0){
					throw new Exception("炉号【" + matBcEntity.getJudgeStoveNo()
							+ "】数据异常或者在倒运途中, 置余材失败!");
				}
					
				String updateMatSql = CoreXmlSqlParsersFactory.getSql("FrmDeleteMatBcM.takeBill");
				updateMatSql = EntityTool.fillSqlByEntity(updateMatSql, matBcEntity);
				sqllist.add(updateMatSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("置余材成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	
	/***
	 * 获取出库单号
	 * 
	 * @param conn
	 * @param strInbound
	 * @return
	 * @throws SQLException
	 */
	public String getOutListDoc(Connection conn, String strInbound)
			throws SQLException {
		String inListDoc = "";
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmLoadMatData.getOutListDoc");
		PreparedStatement psta = conn.prepareStatement(sql);
		psta.setString(1, strInbound);
		psta.setString(2, strInbound);
		psta.setString(3, strInbound);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			inListDoc = rs.getString("OUTSTOCK_DOC");
		}
		rs.close();
		psta.close();
		return inListDoc;
	}
	
	public CoreReturnObject doQueryDepartM()
	{
		return this.getDataBySqlID("FrmDeleteMatBcM.doQueryDepartM");
	}

	public CoreReturnObject doQueryReason()
	{
		return this.getDataBySqlID("FrmDeleteMatBcM.queryReason");
	}

	public CoreReturnObject doPline()
	{
		return this.getDataBySqlID("FrmDeleteMatBcM.queryPline");
	}

	public CoreReturnObject doQueryBelong()
	{
		return this.getDataBySqlID("FrmDeleteMatBcM.doQueryBelong");
	}
}
