package com.steering.mes.SendRecive;

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

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;
import com.steering.common.EntityTool;
import com.steering.mes.mcp.common.PlanService;
import com.steering.mes.signature.MeanValueCalculation;
import com.steering.mes.zgmil.entity.MatBcMEntity;
import com.steering.mes.zgmil.entity.MilCheckDeatilSimpleEntity;
import com.steering.mes.zgmil.entity.MilOfflineReslutEntity;
import com.steering.mes.zgmil.entity.MilPlanEntity;

import oracle.jdbc.proxy.annotation.Pre;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;


public class FrmFilpOutStorage extends DBCommon{
	/***
	 * 查询库存数据
	 * @return
	 */
	public CoreReturnObject doQueryData(ArrayList<String> parmList,String[] storageArr,String qcmStatus,String flag)
	{
		String sql = "";
		if(flag.equals("BC"))
		{
			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.doQueryDataBc");
		}else if(flag.equals("ZC"))
		{
			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.doQueryDataZc");
		}

		if(!parmList.get(0).equals(""))
		{
			String strIn = " AND T.INSTOCK_TIME >=TO_DATE('" + parmList.get(0)
			+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.INSTOCK_TIME <=TO_DATE('"
			+ parmList.get(1) + "', 'YYYY-MM-DD HH24:MI:SS') ";
			sql = sql.replace("#INSTOCK_TIME#", strIn);
		}else
		{
			sql = sql.replace("#INSTOCK_TIME#", "");
		}
		if(!parmList.get(2).equals(""))
		{
			//String strJudgeNo = " AND T.JUDGE_STOVE_NO = '"+parmList.get(2).replace("，",",").split(",")+"'";
			String strJudgeNo = CoreConverter.toSqlConditionString("T.JUDGE_STOVE_NO", parmList.get(2).replace("，",",").split(","));
			sql = sql.replace("#JUDGE_STOVE_NO#", strJudgeNo);
		}else
		{
			sql = sql.replace("#JUDGE_STOVE_NO#", "");
		}
		if(!parmList.get(3).equals(""))
		{
			//String strJudgeNo = " AND T.FLAG_STOVE_NO_ZG = '"+parmList.get(3)+"'";
			String strJudgeNo = CoreConverter.toSqlConditionString("T.FLAG_STOVE_NO_ZG", parmList.get(3).replace("，",",").split(","));
			sql = sql.replace("#FLAG_STOVE_NO_ZG#", strJudgeNo);
		}else
		{
			sql = sql.replace("#FLAG_STOVE_NO_ZG#", "");
		}
		if(!parmList.get(4).equals(""))
		{
			sql = sql.replace("#ORDER_NO#", " AND T.ORDER_NO ||'/'||T.ORDER_SEQ LIKE '%"+parmList.get(4)+"%'");
		}else
		{
			sql = sql.replace("#ORDER_NO#", "");
		}
		String storageNo = CoreConverter.toSqlConditionString("S.STORAGE_NO", storageArr);
		sql = sql.replace("#STORAGE_NO#", storageNo);
		if(flag.equals("BC"))
		{
			if(qcmStatus.equals("00"))
			{
				sql = sql.replace("#QCM_STATUS#", " AND T.QCM_STAUS = '00'");
			}else if(qcmStatus.equals("22"))
			{
				sql = sql.replace("#QCM_STATUS#", " AND T.QCM_STAUS = '22'");
			}else if(qcmStatus.equals("11"))
			{
				sql = sql.replace("#QCM_STATUS#", " AND T.QCM_STAUS = '11'");
			}else
			{
				sql = sql.replace("#QCM_STATUS#", "");
			}
		}else
		{
			if(qcmStatus.equals("00"))
			{
				sql = sql.replace("#QCM_STATUS#", " ");
			}else if(qcmStatus.equals("33"))
			{
				sql 
				= sql.replace("#QCM_STATUS#", " ");
			}else
			{
				sql = sql.replace("#QCM_STATUS#", " AND T.QCM_STAUS = 'XXX'");
			}
		}
		System.out.print(sql);
		return this.getData(sql);
	}

	public CoreReturnObject getWarehousePermissionsStore(
			String[] validDataPurviewIds ,String tt) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("WarehousePermissions.getWarehousePermissionsStore");
		sql += CoreConverter.toSqlConditionString("T.MANAGEMENT_NO",
				validDataPurviewIds);
		sql += "   and  t.storage_addr_no<>'800988'  ORDER BY T.STORAGE_NAME ASC";
		return this.getData(sql);
	}
	public CoreReturnObject getWarehousePermissionsStore(
			String[] validDataPurviewIds) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("WarehousePermissions.getWarehousePermissionsStore");
		sql += CoreConverter.toSqlConditionString("T.MANAGEMENT_NO",
				validDataPurviewIds);
		sql += " ORDER BY T.STORAGE_NAME ASC";
		return this.getData(sql);
	}
//	TZH 24.4.24 注销物流接口
//	/**
//	 * 查询需求
//	 *
//	 * @param
//	 * @return
//	 */
//	public CoreReturnObject doQueryPlnC(String[] PlnNo
//	)
//	{
//
//		String sql = CoreXmlSqlParsersFactory
//				.getSql("TmsDemand.doQueryPlnC");
//
//
//		sql += CoreConverter.toSqlConditionString("M.PLN_NO", PlnNo);
//
//		sql += " Order by TO_NUMBER(M.PLN_SQE)";
//
//		return this.getData("TmsDao",sql);
//	}
	
//	TZH 24.4.24 注销物流接口
//	/***
//	 * 通过车号查询已派计划库存数据
//	 * @param carNo
//	 * @param arr
//	 * @return
//	 */
//	public  CoreReturnObject doQueryDataCarNo(String carNo,String[] arr) throws SQLException {
//		ArrayList<String> parmList = new ArrayList<String>();
//		CoreReturnObject cro = new CoreReturnObject();
//		Connection tmsCon = this.getDao("TmsDao").getConnection();
//		String selectSql = "";
//		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.doQueryJudgeNo");
//		sql += CoreConverter.toSqlConditionString("S.START_AREA_CODE",arr);
//		PreparedStatement psta = tmsCon.prepareStatement(sql);
//		psta.setString(1,carNo);
//		ResultSet rs = psta.executeQuery();
//		List<TmsPlnCEntity> list = EntityTool.getEntitysByRs(rs,
//				TmsPlnCEntity.class);
//		rs.close();
//		psta.close();
//		if(list !=null)
//		{
//			for(int i = 0;i<list.size();i++)
//			{
//				parmList.add(list.get(i).getHeatNo());
//			}
//		}
//		selectSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.doQueryDataCarMat");
//		String judegNo = CoreConverter.toSqlConditionStringList("T.JUDGE_STOVE_NO",parmList);
//		String storageNo = CoreConverter.toSqlConditionString("S.STORAGE_NO", arr);
//		selectSql = selectSql.replace("#JUDGE_STOVE_NO#",judegNo);
//		selectSql = selectSql.replace("#STORAGE_NO#",storageNo);
//		if(parmList.size() == 0)
//		{
//			selectSql = selectSql.replace("#JUDGE_STOVE_NO1#","AND T.JUDGE_STOVE_NO = ''");
//		}
//		else
//		{
//			selectSql = selectSql.replace("#JUDGE_STOVE_NO1#","");
//		}
//		return  this.getData(selectSql);
//
//	}

	/***
	 * 按材料号查询
	 * @return
	 */
	public CoreReturnObject doQueryDataMat(String matBcTity)
	{
		String sql = "";
		MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(matBcTity, 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");
		}

		if (matBcEntity.getProductFlag().equals("在制品")) {
			matBcEntity.setProductFlag("801401");
		} else if (matBcEntity.getProductFlag().equals("成品")) {
			matBcEntity.setProductFlag("801402");
		} else if (matBcEntity.getProductFlag().equals("商品")) {
			matBcEntity.setProductFlag("801403");
		}
		if(matBcEntity.getBarCode().equals("0"))
		{
			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getBcMatNo");
		}else
		{
			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getZcMatNo");
		}
		sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
		return this.getData(sql);
	}
	/***
	 * 获取所有管材的目标库
	 * @return
	 */
	public CoreReturnObject getStoreAll(String[] arr,String tt)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getStoreAll");
		//sql +=CoreConverter.toSqlConditionString("T.STORAGE_NO", arr);
		sql += "  and storage_addr_no<>'800988' ORDER BY T.STORAGE_NO, T.STORAGE_NAME";
		return this.getData(sql);
	}
	/***
     * 获取所有管材的目标库
     * @return
     */
    public CoreReturnObject getStoreAll(String[] arr)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getStoreAll");
    	//sql +=CoreConverter.nOtoSqlConditionString("T.STORAGE_NO", arr);
    	sql += " ORDER BY T.STORAGE_NO, T.STORAGE_NAME";
    	return this.getData(sql);
    }
    /***
	 * 查询目标仓库管理科室
	 * @param tarStorageNo
	 * @return
	 */
	public CoreReturnObject doQueryTarDepart(String tarStorageNo)
	{
		return this.getDataBySqlID("FrmFilpOutStorage.doQueryTarDepart", new Object[]{tarStorageNo});
	}
	/***
	 * 查询倒库出库记录
	 * @param parmList
	 * @param storageArr
	 * @return
	 */
	public CoreReturnObject doQueryOutList(ArrayList<String> parmList,String[] storageArr )
	{
		return doQueryOutList(parmList,storageArr,"");
	}
	public CoreReturnObject doQueryOutList(ArrayList<String> parmList,String[] storageArr,String customInfo)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.doQueryOutList");
		if(!parmList.get(0).equals(""))
		{
			sql += " AND T.OUTSTOCK_TIME >=TO_DATE('" + parmList.get(0)
			+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.OUTSTOCK_TIME <=TO_DATE('"
			+ parmList.get(1) + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}
		if(!parmList.get(2).equals(""))
		{
			sql += CoreConverter.toSqlConditionString("T.JUDGE_STOVE_NO", parmList.get(2).replace("，",",").split(","));
			//sql += " AND T.JUDGE_STOVE_NO = '"+parmList.get(2)+"'";
		}
		if(!parmList.get(3).equals(""))
		{
			sql += CoreConverter.toSqlConditionString("T.FLAG_STOVE_NO_ZG", parmList.get(3).replace("，",",").split(","));
			//sql += " AND T.FLAG_STOVE_NO_ZG = '"+parmList.get(3)+"'";
		}
		if(!parmList.get(4).equals(""))
		{
			sql += " AND T.PRO_ORDER_NO ='"+parmList.get(4)+"'";
		}
		sql += CoreConverter.toSqlConditionString("T.STORAGE_NO", storageArr);
		sql += " GROUP BY T.OUTSTOCK_DOC,T.VEHICLE_NO,T.STOVE_NO,T.JUDGE_STOVE_NO,T.BATCH_NO,T.BATCH_GROUD_NO,T.STORAGE_NO,T.TAR_STORAGE_NO,T.QCM_STAUS,T.OUT_TYPE,T.PRODUCT_FLAG,T.MATERIAL_NO,T.MATERIAL_NAME,OUT_BC,OUT_BZ";
		sql = "SELECT * FROM ("+sql+") T WHERE 1=1 ";
		if(!parmList.get(5).equals(""))
		{
			sql += " AND T.OUT_TYPE ='"+parmList.get(5)+"'";
		}
		if(!parmList.get(6).equals(""))
		{
			sql += " AND T.STORAGE_NAME  like '%"+parmList.get(6)+"%'";
		}
		if("A-lishi".equals(customInfo)){
			return this.getData("TgDao",sql);
		}
		return this.getData(sql);	
	}
	
//	TZH 24.4.24 注销物流接口
//	/****
//	 * 查询运输需求
//	 * @param parmList
//	 * @param storageArr
//	 * @return
//	 */
//	public CoreReturnObject doQueryTmsDemand(ArrayList<String> parmList,String[] storageArr,String[] staus)
//	{
//		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.doQueryTmsDemand");
//		if(!parmList.get(0).equals(""))
//		{
//			sql += " AND T.CREATE_TIME >=TO_DATE('" + parmList.get(0)
//					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
//					+ parmList.get(1) + "', 'YYYY-MM-DD HH24:MI:SS') ";
//		}
//		if(!parmList.get(2).equals(""))
//		{
//			sql += " AND T.HEAT_NO = '"+parmList.get(2)+"'";
//		}
//		if(!parmList.get(3).equals(""))
//		{
//			sql += " AND T.LOGO_NO = '"+parmList.get(3)+"'";
//		}
//		if(staus.length > 0)
//		{
//			sql += CoreConverter.toSqlConditionString("T.VALIDFLAG", staus);
//		}
//		sql += CoreConverter.toSqlConditionString("T.START_AREA_CODE", storageArr);
//		sql += " ORDER BY T.TRANSPORT_START_TIME ASC";
//		return  this.getData("TmsDao",sql);
//	}
	/**
     * 查询产线
     * @return
     */
    public CoreReturnObject getPCode(String[] arr) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmFilpOutStorage.getPCode");
        sql += CoreConverter.toSqlConditionString("T.DEPARTMENT_CODE", arr);
        sql += " ORDER BY T.PLINE_NAME";
        return this.getData(sql);
    }
	/***
	 * 查询轧管炉计划
	 * @return
	 */
	public CoreReturnObject doQueryMilPlan(String lotNo,String judgeNo,String[] arr)
	{
		String sql = "SELECT * FROM (";
	    sql += CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.doQueryMilPlan");
	    if(!lotNo.equals(""))
	    {
	    	sql += " AND T.LOT_NO = '"+lotNo+"'";
	    }
	    if(!judgeNo.equals(""))
	    {
	    	sql += " AND T.JUDGE_STOVE_NO LIKE '"+judgeNo+"%'";
	    }
	    	
		sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", arr);
		sql += " ORDER BY T.START_TIME ASC)WHERE ACT_COUNT > 0";
		return this.getData(sql);
	}
	
	/***
	 * 查询目标库
	 * @param arr
	 * @return
	 */
	public CoreReturnObject doQueryStorageNo(String[] arr)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.doQueryStorageNo");
		//sql += CoreConverter.nOtoSqlConditionString("T.STORAGE_NO", arr);
		sql += " ORDER BY T.STORAGE_NO ASC";
		return this.getData(sql);
	}
	/***
	 * 修改去向
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updateGoWhere(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)
			{
				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 updateGoWhereSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.updateGoWhere");
				updateGoWhereSql = EntityTool.fillSqlByEntity(updateGoWhereSql, matBcEntity);
				sqllist.add(updateGoWhereSql);
			}
			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 updateFalgStove(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)
			{
				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 updateFlagStoveSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.updateFalgStove");
				updateFlagStoveSql = EntityTool.fillSqlByEntity(updateFlagStoveSql, matBcEntity);
				sqllist.add(updateFlagStoveSql);
			}
			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 milPlanTity
	 * @param parmList
	 * @param offProcess
	 * @return
	 */
//	public CoreReturnObject doOffline(String milPlanTity,ArrayList<String> parmList,String offProcess)
//	{
//		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 df = new SimpleDateFormat("yyyyMM");
//		String systime = dateFormat.format(now);
//		String bathYear = df.format(now);
//		String nodeStaus = "";//结炉状态
//		String startStaus = "";
//		int actCount = 0;//合格支
//		String opProcess = "";//工序点
//		String offType = "";//下线类别
//		String str[] = null;
//		double strWgt = 0.0;
//		String lengthCp[] = null;// 长度范围
//		String plineName = "";
//		String belongCode = "";
//		String belongName = "";
//		try {
//			ArrayList<String> sqllist = new ArrayList<String>();
//			MilPlanEntity milEntity = EntityTool.getEntityByJSONStr(milPlanTity, MilPlanEntity.class);
//			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.SelectMilNode");//查询结炉状态
//			sql = EntityTool.fillSqlByEntity(sql, milEntity);
//			psta = connection.prepareStatement(sql);
//			rs = psta.executeQuery();
//			if(rs.next())
//			{
//				nodeStaus = rs.getString("NODE_STATUS");
//				startStaus = rs.getString("STATUS");
//			}
//			rs.close();
//			psta.close();
//
//			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.SelectQualifiedCount");//查询合格支
//			sql = EntityTool.fillSqlByEntity(sql, milEntity);
//			psta = connection.prepareStatement(sql);
//			rs = psta.executeQuery();
//			if(rs.next())
//			{
//				actCount = Integer.parseInt(rs.getString("ACOUNT"));
//			}
//			rs.close();
//			psta.close();
//			if(Integer.parseInt(milEntity.getLxCount()) > actCount)
//			{
//				cro.setV_errMsg("离线时离线支不允许大于现有合格支!");
//				return cro;
//			}
//			if(Integer.parseInt(milEntity.getLxCount()) == 0)
//			{
//				cro.setV_errMsg("离线时离线支不能为0支!");
//				return cro;
//			}
//			if(offProcess.equals("9"))
//			{
//				if(!(Integer.parseInt(startStaus)>=75))
//				{
//					cro.setV_errMsg("矫直未开始,不允许进行矫直离线!");
//					return cro;
//				}
//			}else if(offProcess.equals("10"))
//			{
//				if(!(Integer.parseInt(startStaus)>=85))
//				{
//					cro.setV_errMsg("探伤未开始,不允许进行探伤离线!");
//					return cro;
//				}
//			}else if(offProcess.equals("11"))
//			{
//				if(!nodeStaus.equals("90"))
//				{
//					cro.setV_errMsg("表检未开始,不允许进行表检离线!");
//					return cro;
//				}
//			}
//			if(milEntity.getPlineCode().equals("C010"))
//			{
//			   	plineName = "168机组";
//			   	belongCode = "002001017003";
//			   	belongName = "168机组";
//			}else if(milEntity.getPlineCode().equals("C017"))
//			{
//				plineName = "460机组";
//				belongCode = "002001018003";
//				belongName = "460机组";
//			}else if(milEntity.getPlineCode().equals("C008"))
//			{
//				plineName = "250机组";
//				belongCode = "002001016003";
//				belongName = "250机组";
//			}else if(milEntity.getPlineCode().equals("C009"))
//			{
//				plineName = "258机组";
//				belongCode = "002001016002";
//				belongName = "258机组";
//			}
//
//			str = milEntity.getPipeSize().split("[*]");
//
//			String jugeNo = milEntity.getJudgeStoveNo().substring(0,6);
//			String bacthNo = "X";
//			String groupNo = "001";
//			String matNo = queryMatNoM(connection, jugeNo, bacthNo); // 材料号
//			int g = Integer.parseInt(matNo.substring(matNo.length() - 4, matNo
//					.length()));
//			lengthCp = milEntity.getLengthRange().replace("米", "").split(
//					"[-]");
//			str = milEntity.getPipeSize().split("[*]");
//			strWgt = 0.02466
//					* Double.parseDouble(str[1])
//					* (Math.abs(Double.parseDouble(str[0])
//							- Double.parseDouble(str[1])))
//					* Double.parseDouble(milEntity.getTargetLength())
//					* Integer.parseInt(milEntity.getLxCount()) / 1000;
//			List<double[]> list1 = MeanValueCalculation.MeanCalculation(Double
//					.parseDouble(new DecimalFormat("0.000").format(strWgt)),
//					Integer.parseInt(milEntity.getLxCount()));
//			for (int j = 0; j < list1.size(); j++) {
//				double[] conW = list1.get(j);
//				if ((int) conW[0] >= 0) {
//					for (int z = 0; z < (int) conW[0]; z++) {
//						MatBcMEntity matBcEntity = new MatBcMEntity();
//						matBcEntity.setJudgeStoveNo(jugeNo);
//						matBcEntity.setBatchNo(bacthNo);
//						matBcEntity.setBatchGroudNo(groupNo);
//						matBcEntity.setStorageNo(parmList.get(5));
//						matBcEntity.setLocationNo(parmList.get(6));
//						matBcEntity.setStorageTypeNo(parmList.get(7));
//						matBcEntity.setStorageTypeName(parmList.get(8));
//						matBcEntity.setCreateName(parmList.get(0));
//						matBcEntity.setCreateTime(systime);
//						matBcEntity.setMatNo((jugeNo + bacthNo)
//								+ StringTool.formatDecimal(g, "0000"));
//						matBcEntity.setManagementNo(parmList.get(1));
//						matBcEntity.setManagementName(parmList.get(2));
//						matBcEntity.setDepartmentCode(parmList.get(3));
//						matBcEntity.setDepartmentDesc(parmList.get(4));
//						matBcEntity.setActCount("1");
//						matBcEntity.setActWeight(String.valueOf(conW[1]));
//						matBcEntity.setProductFlag("801401");
//						matBcEntity.setMatStatus("80150104");
//						matBcEntity.setPlineCode(milEntity.getPlineCode());
//						matBcEntity.setPlineName(plineName);
//						matBcEntity.setQcmStaus("11");
//						matBcEntity.setHeatPlanNo(milEntity.getId());
//						matBcEntity.setZgStoveSqe(milEntity.getJudgeStoveNo());
//						matBcEntity.setProduccode(milEntity.getVarietiesCode());
//						matBcEntity.setProducname(milEntity.getVarieties());
//						matBcEntity.setSteelcode(milEntity.getSteelcode());
//						matBcEntity.setSteelname(milEntity.getSteelname());
//						matBcEntity.setSpecCode(milEntity.getPipeSizeCode());
//						matBcEntity.setSpecName(milEntity.getPipeSize().replace("*", "x"));
//						matBcEntity.setModelCode(milEntity.getBuckleTypeCode());
//						matBcEntity.setModelDesc(milEntity.getBuckleType());
//						matBcEntity.setStdCode(milEntity.getRollStandradCode());
//						matBcEntity.setStdName(milEntity.getRollStandrad());
//						matBcEntity.setStdStyle(milEntity.getStdStyle());
//						matBcEntity.setStdStyleDesc(milEntity.getStdStyleDesc());
//						matBcEntity.setActDimater(str[0]);
//						matBcEntity.setActHeight(str[1]);
//						matBcEntity.setActLenMin(lengthCp[0]);
//						matBcEntity.setActLenMax(lengthCp[1]);
//						matBcEntity.setLotNo(milEntity.getLotNo());
//						matBcEntity.setStoveNo(milEntity.getStoveNo());
//						matBcEntity.setProOrderNo(milEntity.getContractNo());
//						matBcEntity.setActLen(milEntity.getTargetLength());
//						matBcEntity.setTarget(milEntity.getTarget());
//						matBcEntity.setProcessStatus(milEntity.getProcessStatus());
//						matBcEntity.setBelongCode(belongCode);
//						matBcEntity.setBelongName(belongName);
//
//						String insertMatSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.insertMatSql");
//						insertMatSql = EntityTool.fillSqlByEntity(insertMatSql, matBcEntity);
//						sqllist.add(insertMatSql);
//						g++;
//					}
//				}
//			}
//			if(offProcess.equals("9"))
//			{
//				opProcess = "JZ";
//				offType = "3";
//			}else if(offProcess.equals("10"))
//			{
//				opProcess = "TS";
//				offType = "1";
//
//			}else if(offProcess.equals("11"))
//			{
//				opProcess = "ZJ";
//				offType = "0";
//			}else if(offProcess.equals("12"))
//			{
//				opProcess = "XX";
//				offType = "0";
//			}
//			MilOfflineReslutEntity milOffResultTity = new MilOfflineReslutEntity();
//			milOffResultTity.setId(milEntity.getId());
//			milOffResultTity.setStoveNo(milEntity.getStoveNo());
//			milOffResultTity.setLotNo(milEntity.getLotNo());
//			milOffResultTity.setJudgeStoveNo(milEntity.getJudgeStoveNo());
//			milOffResultTity.setProPlanId(milEntity.getProPlanId());
//			milOffResultTity.setGxPlanNo(milEntity.getGxPlanNo());
//			milOffResultTity.setProduccode(milEntity.getVarietiesCode());
//			milOffResultTity.setProducname(milEntity.getVarieties());
//			milOffResultTity.setSteelcode(milEntity.getSteelcode());
//			milOffResultTity.setSteelname(milEntity.getSteelname());
//			milOffResultTity.setGradecode(milEntity.getGradecode());
//			milOffResultTity.setGradename(milEntity.getGradename());
//			milOffResultTity.setSpecCode(milEntity.getPipeSizeCode());
//			milOffResultTity.setSpecName(milEntity.getPipeSize());
//			milOffResultTity.setModelCode(milEntity.getBuckleTypeCode());
//			milOffResultTity.setModelDesc(milEntity.getBuckleType());
//			milOffResultTity.setStdCode(milEntity.getRollStandradCode());
//			milOffResultTity.setStdName(milEntity.getRollStandrad());
//			milOffResultTity.setStdStyle(milEntity.getStdStyle());
//			milOffResultTity.setStdStyleDesc(milEntity.getStdStyleDesc());
//			milOffResultTity.setActLenRange(milEntity.getLengthRange());
//			milOffResultTity.setContractNo(milEntity.getContractNo());
//			milOffResultTity.setDiameter(milEntity.getPipeSize().split("[*]")[0]);
//			milOffResultTity.setThickness(milEntity.getPipeSize().split("[*]")[1]);
//			milOffResultTity.setLength(milEntity.getTargetLength());
//			milOffResultTity.setPlineCode(milEntity.getPlineCode());
//			milOffResultTity.setOfflinePro(opProcess);
//			milOffResultTity.setOfflineNum(milEntity.getLxCount());
//			milOffResultTity.setOfflineType(offType);
//			milOffResultTity.setOfflineTime(systime);
//			milOffResultTity.setColUser(parmList.get(0));
//			milOffResultTity.setColShift(parmList.get(3));
//			milOffResultTity.setColGroup(parmList.get(4));
//			milOffResultTity.setZpHeight(String.valueOf(strWgt));//重量
//			milOffResultTity.setTarget(milEntity.getTarget());
//			milOffResultTity.setImpProcess(milEntity.getImpProcess());
//
//			String offlineSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.OfflineResultSql");
//			offlineSql = EntityTool.fillSqlByEntity(offlineSql, milOffResultTity);
//			sqllist.add(offlineSql);
//
//
//			MilCheckDeatilSimpleEntity milCheckDeatilEntity = new MilCheckDeatilSimpleEntity();
//			milCheckDeatilEntity.setJudgeStoveNo(milEntity.getJudgeStoveNo());
//			milCheckDeatilEntity.setDefectCode("500335");
//			milCheckDeatilEntity.setDefectItem("其他");
//			milCheckDeatilEntity.setOfflineProduct(milEntity.getLxCount());
//			milCheckDeatilEntity.setResultNo(milEntity.getId());
//			milCheckDeatilEntity.setProPlanId(milEntity.getProPlanId());
//			milCheckDeatilEntity.setGxPlanNo(milEntity.getGxPlanNo());
//			if(offProcess.equals("11"))
//			{
//			    String insertCheckDeatilSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.insertCheckDeatil");
//			    insertCheckDeatilSql = EntityTool.fillSqlByEntity(insertCheckDeatilSql, milCheckDeatilEntity);
//			    sqllist.add(insertCheckDeatilSql);
//			}
//
//			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 matEntity
	 * @return
	 */
	public CoreReturnObject doQueryWgt(String matEntity)
	{
		String sql  = "";
		MatBcMEntity matGpmEntity = EntityTool.getEntityByJSONStr(matEntity, MatBcMEntity.class);
		if(matGpmEntity.getQcmStaus().equals("合格"))
		{
			matGpmEntity.setQcmStaus("00");
		}else if(matGpmEntity.getQcmStaus().equals("待处理"))
		{
			matGpmEntity.setQcmStaus("11");
		}else
		{
			matGpmEntity.setQcmStaus("22");
		}
		if(matGpmEntity.getBarCode().equals("0"))
		{
			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectOutBcWgt");
		}else
		{
			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectOutZcWgt");
		}
		
		sql = EntityTool.fillSqlByEntity(sql, matGpmEntity);
	    return this.getData(sql);	
	}
	
	/**
	 * 根据炉号、批号自动生成材料号
	 * 
	 * @param conn
	 *            c
	 * @param strLcode
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String queryMatNoM(Connection conn, String strLcode, String strBatch)
			throws Exception {
		int count = 0;
		String matNo = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmFilpOutStorage.queryMatNoM");
		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 (strLcode + strBatch)
		// + StringTool.formatDecimal(++count, "0000");
		return matNo;
	}
	/***
	 * 根据产线找在线库信息
	 * 
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject doQueryStoreNo(String plineCode) {
		return this.getDataBySqlID("FrmFilpOutStorage.doQueryStoreNo",
				new Object[] { plineCode });
	}


	//判断出库仓库与接收仓库是否为同区域
	public String queryStoreArea(MatBcMEntity matEntity, String tarStorageNo, Connection con) throws SQLException {
		String areaFlag = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		String storageNoArea = "";//出库仓库所属区域
		String tarStorageArea = "";//收料仓库所属区域
		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.queryStoreArea");
		ps = con.prepareStatement(sql);
		ps.setString(1,matEntity.getStorageNo());
		rs = ps.executeQuery();
		if(rs.next())
		{
			storageNoArea = rs.getString("SEAM_AREA");
		}
		rs.close();
		ps.close();


		String sql1 = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.queryStoreArea");
		ps = con.prepareStatement(sql);
		ps.setString(1,tarStorageNo);
		rs = ps.executeQuery();
		if(rs.next())
		{
			tarStorageArea = rs.getString("SEAM_AREA");
		}
		rs.close();
		ps.close();

		if(storageNoArea.equals("0") && tarStorageArea.equals("0"))
		{
			areaFlag = "1";
		}else
		{
			areaFlag = "0";
		}
		return  areaFlag;
	}

	/***
	 * 倒库出库
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject doAdd(ArrayList<String> parmList,ArrayList<String> list,String[] storageArr,String outType,String superCode)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		System.out.print(CoreConstantData.sysbeanstr);
//		Connection mcsCon = this.getDao("McmsDao").getConnection();//检斤
//		TZH 24.4.24 注销物流接口
//		Connection tmsCon = this.getDao("TmsDao").getConnection();//物流

		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String systime = dateFormat.format(now);

		Calendar calen = new GregorianCalendar();
		calen.setTime(now);
		calen.add(calen.DATE,1);
		now = calen.getTime();
		String systimeN = dateFormat.format(now);

		//String bathYear = df.format(now);
		String bathYear = ""; // 改25号结转
		int aCount = 0;
		String outDoc = "";//出库单号
		String inDoc = "";//入库单号
		String superName = "";
		String superCall = "";
		int tmsCount = 0;
		String endAreaCode = "";//卸点区域
		String msg = "";//错误消息
		String isCarUser = "";//是否限制了一车一卡
		String isCarUserBill = "";
		String tmsWNo = "";//运单号
		String arriveArea = "";//到达点区域

		String isLoading = "";//装点是否需要吊车
		String typeFlag = "";//判断是否和物流对接
		String possFlag = "";//过磅标识
		String predictNo = "";//预报编号
		String strFlag = "";//所在仓库所属单位、在线库标识
		String jlmatterNo = "";
		String jlmatterName = "";
		String forUnitNo = "";//发货单位编码
		String reciveUnitNo = "";//收货单位编码
		try {
			connection.setAutoCommit(false);
//			TZH 24.4.24 注销物流接口
//			tmsCon.setAutoCommit(false);
//			mcsCon.setAutoCommit(false);
			ArrayList<String> sqllist = new ArrayList<String>();
			//outDoc = getOutDoc(connection,EntityTool.getEntityByJSONStr(parmList.get(0), MatBcMEntity.class).getStorageNo(),"800803",systime,outType);
			//inDoc = getInDoc(connection,EntityTool.getEntityByJSONStr(parmList.get(0), MatBcMEntity.class).getMatGowhereCode(),"800703",systime);
			outDoc = list.get(12);

			MatBcMEntity ss = EntityTool.getEntityByJSONStr(parmList.get(0),
					MatBcMEntity.class);

			bathYear = com.steering.common.StringTool.GetBalYear(now,com.steering.common.StringTool.GetSupplyUnit(ss.getPlineCode())); // 改25号结转
			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.SelectStorageIsCarUser");
			psta = connection.prepareStatement(sql);
			psta.setString(1,ss.getStorageNo());
			rs = psta.executeQuery();
			if(rs.next())
			{
				isCarUser = rs.getString("IS_CAR_TAKING");
				isCarUserBill = rs.getString("IS_CAR_TAKING_BILL");
			}
			rs.close();
			psta.close();

			typeFlag = queryStoreArea(ss,list.get(0),connection);

			if(typeFlag.equals("1"))
			{
				if(!list.get(0).equals("LDC2") )
				{
					//判断司机是否接单并且扫码到达
					if((outType.equals("0") && isCarUser.equals("1")) || (outType.equals("1") && isCarUserBill.equals("1")))//写卡倒运/票据倒运
					{

						int m = 0;
						for(String strM : parmList)
						{
							MatBcMEntity strMatBcEntity = EntityTool.getEntityByJSONStr(strM,
									MatBcMEntity.class);


//							if((strMatBcEntity.getStorageNo().equals("LXW1")||strMatBcEntity.getStorageNo().equals("LGM4"))&&(list.get(0).equals("LBC1") || list.get(0).equals("LTF1") || list.get(0).equals("LAL1")))
//							{
//
//							}else
//							{


//							TZH 24.4.24 注销物流接口
//								sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectWayBill");
// 								psta = tmsCon.prepareStatement(sql);
//								psta.setString(1,strMatBcEntity.getJudgeStoveNo());
//								psta.setString(2,strMatBcEntity.getStorageNo());
//								psta.setString(3,list.get(8));
//								rs = psta.executeQuery();
//								if(rs.next())
//								{
//									tmsCount = Integer.parseInt(rs.getString("ACOUNT"));
//									endAreaCode = rs.getString("END_AREA_CODE");
//									tmsWNo = rs.getString("WAYBILL_NO");
//
//								}
//								rs.close();
//								psta.close();
								if(tmsCount == 0)
								{
									cro.setV_errMsg("该车辆"+ list.get(8)+ "不存在已接单并且扫到达二维码的运单或者派单判定炉号与实际装车判定炉号不符，不允许倒运!");
									return  cro;
								}else
								{
									if(!endAreaCode.equals(list.get(0)))
									{
										cro.setV_errMsg("倒运目标仓库与运输任务分派去向不一致,不允许倒运!");
										return  cro;
									}
								}

								//判断当前库存点是否需要吊车扫码
								sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectLoadingFlag");
								sql = EntityTool.fillSqlByEntity(sql,strMatBcEntity);
								psta = connection.prepareStatement(sql);
								rs = psta.executeQuery();
								if(rs.next())
								{
									isLoading = rs.getString("IS_CRANE_LOADING");
								}
								rs.close();
								psta.close();
								//判断是否吊车已扫码
								if(isLoading.equals("1"))
								{
									sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectTmsRelation");
//									TZH 24.4.24 注销物流接口
//									psta = tmsCon.prepareStatement(sql);
//									psta.setString(1,tmsWNo);
//									psta.setString(2,strMatBcEntity.getStorageNo());
//									rs = psta.executeQuery();
//									if(rs.next())
//									{
//										aCount = Integer.parseInt(rs.getString("ACOUNT"));
//									}
//									rs.close();
//									psta.close();
//									if(aCount == 0)
//									{
//										cro.setV_errMsg(strMatBcEntity.getStorageName() + "打卡前需吊车扫拖车司机运单二维码!");
//										return  cro;
//									}
								}

							//}
//							if((strMatBcEntity.getStorageNo().equals("LXW1")||strMatBcEntity.getStorageNo().equals("LGM4"))&&(list.get(0).equals("LBC1") || list.get(0).equals("LTF1") || list.get(0).equals("LAL1")))
//							{
//
//							}else
//							{
								
								sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectTraceMUnload");
//								TZH 24.4.24 注销物流接口
//								psta = tmsCon.prepareStatement(sql);
//								psta.setString(1,tmsWNo);
//								rs = psta.executeQuery();
//								if(rs.next())
//								{
//									arriveArea = rs.getString("UNLOADING_AREA_CODE");
//								}
//								rs.close();
//								psta.close();
								if(!arriveArea.equals(strMatBcEntity.getStorageNo()))
								{
									cro.setV_errMsg("装点区域与司机到达点区域不一致,不允许倒运!");
									return  cro;
								}
							//}

						}
						sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectJlMatter");
						sql = EntityTool.fillSqlByEntity(sql,ss);
//						psta = mcsCon.prepareStatement(sql);
						rs = psta.executeQuery();
						if(rs.next())
						{
							jlmatterNo = rs.getString("MATTER_NO");
							jlmatterName = rs.getString("MATTER_NAME");
						}
						rs.close();
						psta.close();
//						if(jlmatterNo.equals("")||jlmatterName.equals(""))
//						{
//							cro.setV_errMsg("倒库下发预报时产销物料未在计量系统的基础物料中,无法进行倒运!");
//							return  cro;
//						}

						// 查询品名是否计量
						String jlFlag = "";
						sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectjlFalgByProduct");
						psta = connection.prepareStatement(sql);
						psta.setString(1,ss.getProduccode());
						rs = psta.executeQuery();
						if(rs.next())
						{
							jlFlag = rs.getString("JL_FALG");
						}
						rs.close();
						psta.close();

						if(!StringUtils.isEmpty(jlFlag) && "1".equals(jlFlag)){
//							forUnitNo = getJlLoad(ss.getStorageNo(),mcsCon);
//							reciveUnitNo = getJlLoad(list.get(0),mcsCon);
//
//							String insertPreNoSql = "";
//							predictNo = getPreDictNo(mcsCon);
							PreTrackScaleEntity preEntity = new PreTrackScaleEntity();
							preEntity.setNoticeNo(outDoc);
							preEntity.setPredictionNo(predictNo);
							preEntity.setCarNo(list.get(8));
							preEntity.setMatterNo(jlmatterNo);
							preEntity.setMatterName(jlmatterName);
							preEntity.setContractNo(ss.getProOrderNo());
							preEntity.setForwardingUnitNo(forUnitNo);
							preEntity.setForwardingUnitName(ss.getStorageName());
							preEntity.setReceivingUintNo(reciveUnitNo);
							preEntity.setReceivingUintName(list.get(11));
							preEntity.setMaterialNo(ss.getMaterialNo());
							preEntity.setMaterialName(ss.getMaterialName());
							preEntity.setSpecNo(ss.getSpecCode());
							preEntity.setSpecName(ss.getSpecName());
							preEntity.setPredictionType("1");
							preEntity.setUsedType("0");
							preEntity.setValueFlag("1");
							preEntity.setCreateManNo("admin");
							preEntity.setCreateManName(list.get(1));
							preEntity.setCreateTime(systime);
							preEntity.setMeterTypeNo("001006011");
							preEntity.setMeterTypeName("中控倒运（下线管收货确认）");
							preEntity.setEffectiveNum("1");
							preEntity.setHeatNo(ss.getJudgeStoveNo());
							preEntity.setCarAllocationTime(systime);
							preEntity.setEffectiveStartTime(systime);//有效开始时间
							preEntity.setEffectiveEndTime(systimeN);//有效结束时间
							preEntity.setProcessNo("202403190011");


							//判断是否为废管
							if(ss.getQcmStaus().equals("废品"))
							{
	//							preEntity.setMatterNo("00761");
	//							preEntity.setMatterName("废管");
	//							preEntity.setHeatNo("000000");
	//							insertPreNoSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.InsertPreDictNo");
	//							insertPreNoSql = EntityTool.fillSqlByEntity(insertPreNoSql,preEntity);
	//							psta = mcsCon.prepareStatement(insertPreNoSql);
	//							psta.executeUpdate();
	//							psta.close();
							}else
							{
								//生成轧管、热处理计量预报
								if(ss.getProcessCdoe().equals("D"))
								{
									sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectTarFlag");
									sql = EntityTool.fillSqlByEntity(sql,ss);
									psta = connection.prepareStatement(sql);
									rs = psta.executeQuery();
									if(rs.next())
									{
										possFlag = rs.getString("PRT_FLAG");
									}
									rs.close();
									psta.close();
									if(possFlag.equals("1") && ss.getQcmStaus().equals("合格"))
									{
										// 查询计量供应商
										String jlgys = "";
										sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectjlgysByPline");
										psta = connection.prepareStatement(sql);
										psta.setString(1,ss.getPlineCode());
										rs = psta.executeQuery();
										if(rs.next())
										{
											jlgys = rs.getString("JL_SUPP");
										}
										rs.close();
										psta.close();
										if(StringUtils.isEmpty(jlgys))
										{
											cro.setV_errMsg(ss.getPlineName()+"没有维护计量供应商,无法生成计量预报,不允许倒运!");
											return  cro;
										}
										preEntity.setCustomerSupplierNo(jlgys);
										if(!"801401".equals(ss.getProductFlag()) && !"在制品".equals(ss.getProductFlag())){
											preEntity.setMeterTypeNo("001006010");
											preEntity.setMeterTypeName("中控倒运（下线管）");
											preEntity.setProcessNo("202403180010");
										}
										if(ss.getProducname().equals("接箍坯料")){
											preEntity.setMeterTypeNo("001006012");
											preEntity.setMeterTypeName("中控倒运（非下线管需收货确认）");
											preEntity.setProcessNo("202403300012");
										}
										// 计量预报
//										insertPreNoSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.InsertPreDictNo");
//										insertPreNoSql = EntityTool.fillSqlByEntity(insertPreNoSql,preEntity);
//										psta = mcsCon.prepareStatement(insertPreNoSql);
//										psta.executeUpdate();
//										psta.close();
										// 计量环节
//										String insertPreProcessLink = CoreXmlSqlParsersFactory.getSql("PreTrackNotice.InsertPreProcess_LINK");
//										insertPreProcessLink = EntityTool.fillSqlByEntity(insertPreProcessLink, preEntity);
//										psta = mcsCon.prepareStatement(insertPreProcessLink);
//										psta.executeUpdate();
//										psta.close();
									}

								}else if(ss.getProcessCdoe().equals("E")||ss.getProcessCdoe().equals("F"))
								{
									strFlag = getStorageFlag(ss.getStorageNo(),connection);
									if(ss.getTarget().equals("A") && strFlag.equals("1")&& ss.getQcmStaus().equals("合格"))
									{
										// 查询计量供应商
										String jlgys = "";
										sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectjlgysByPline");
										psta = connection.prepareStatement(sql);
										psta.setString(1,ss.getPlineCode());
										rs = psta.executeQuery();
										if(rs.next())
										{
											jlgys = rs.getString("JL_SUPP");
										}
										rs.close();
										psta.close();
										if(StringUtils.isEmpty(jlgys))
										{
											cro.setV_errMsg(ss.getPlineName()+"没有维护计量供应商,无法生成计量预报,不允许倒运!");
											return  cro;
										}
										preEntity.setCustomerSupplierNo(jlgys);
										if(!"801401".equals(ss.getProductFlag()) && !"在制品".equals(ss.getProductFlag())){
											preEntity.setMeterTypeNo("001006010");
											preEntity.setMeterTypeName("中控倒运（下线管）");
											preEntity.setProcessNo("202403180010");
										}
										if(ss.getProducname().equals("接箍坯料")){
											preEntity.setMeterTypeNo("001006012");
											preEntity.setMeterTypeName("中控倒运（非下线管需收货确认）");
											preEntity.setProcessNo("202403300012");
										}
//										// 计量预报
//										insertPreNoSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.InsertPreDictNo");
//										insertPreNoSql = EntityTool.fillSqlByEntity(insertPreNoSql,preEntity);
//										psta = mcsCon.prepareStatement(insertPreNoSql);
//										psta.executeUpdate();
//										psta.close();
//										// 计量环节
//										String insertPreProcessLink = CoreXmlSqlParsersFactory.getSql("PreTrackNotice.InsertPreProcess_LINK");
//										insertPreProcessLink = EntityTool.fillSqlByEntity(insertPreProcessLink, preEntity);
//										psta = mcsCon.prepareStatement(insertPreProcessLink);
//										psta.executeUpdate();
//										psta.close();
									}
								}else if(ss.getProcessCdoe().equals("G")  && ss.getPlineCode().equals("C069"))
								{
									strFlag = getStorageFlag(ss.getStorageNo(),connection);
									if(strFlag.equals("1")&& ss.getQcmStaus().equals("合格"))
									{
										// 查询计量供应商
										String jlgys = "";
										sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectjlgysByPline");
										psta = connection.prepareStatement(sql);
										psta.setString(1,ss.getPlineCode());
										rs = psta.executeQuery();
										if(rs.next())
										{
											jlgys = rs.getString("JL_SUPP");
										}
										rs.close();
										psta.close();
										if(StringUtils.isEmpty(jlgys))
										{
											cro.setV_errMsg(ss.getPlineName()+"没有维护计量供应商,无法生成计量预报,不允许倒运!");
											return  cro;
										}
										preEntity.setCustomerSupplierNo(jlgys);
										if(!"801401".equals(ss.getProductFlag()) && !"在制品".equals(ss.getProductFlag())){
											preEntity.setMeterTypeNo("001006010");
											preEntity.setMeterTypeName("中控倒运（下线管）");
											preEntity.setProcessNo("202403180010");
										}
										if(ss.getProducname().equals("接箍坯料")){
											preEntity.setMeterTypeNo("001006012");
											preEntity.setMeterTypeName("中控倒运（非下线管需收货确认）");
											preEntity.setProcessNo("202403300012");
										}
//										// 计量预报
//										insertPreNoSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.InsertPreDictNo");
//										insertPreNoSql = EntityTool.fillSqlByEntity(insertPreNoSql,preEntity);
//										psta = mcsCon.prepareStatement(insertPreNoSql);
//										psta.executeUpdate();
//										psta.close();
//										// 计量环节
//										String insertPreProcessLink = CoreXmlSqlParsersFactory.getSql("PreTrackNotice.InsertPreProcess_LINK");
//										insertPreProcessLink = EntityTool.fillSqlByEntity(insertPreProcessLink, preEntity);
//										psta = mcsCon.prepareStatement(insertPreProcessLink);
//										psta.executeUpdate();
//										psta.close();
									}
								}
							}

						}
					}
				}
			}




			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectSuper");
			psta = connection.prepareStatement(sql);
			psta.setString(1,superCode);
			rs = psta.executeQuery();
			if(rs.next())
			{
				superName = rs.getString("SUPERVISOR_NAME");
				superCall = rs.getString("SUPERVISOR_CALL");
			}
			rs.close();
			psta.close();
			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");
				}

				if (matBcEntity.getProductFlag().equals("在制品")) {
					matBcEntity.setProductFlag("801401");
				} else if (matBcEntity.getProductFlag().equals("成品")) {
					matBcEntity.setProductFlag("801402");
				} else if (matBcEntity.getProductFlag().equals("商品")) {
					matBcEntity.setProductFlag("801403");
				}

				if(matBcEntity.getMatNo().equals(""))
				{
					if (matBcEntity.getBarCode().equals("0")) {
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmFilpOutStorage.doQueryMatBcCount");// 查询库存支数
					} else if (matBcEntity.getBarCode().equals("1")) {
						sql = CoreXmlSqlParsersFactory
								.getSql("FrmFilpOutStorage.doQueryMatZcCount");// 查询库存支数
					}

					sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
					sql += CoreConverter.toSqlConditionString("S.STORAGE_NO",
							storageArr);
					psta = connection.prepareStatement(sql);
					rs = psta.executeQuery();
					if (rs.next()) {
						aCount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();

					if (Integer.parseInt(matBcEntity.getActCount()) > aCount) {
						cro.setV_errMsg("倒运支数大于库存支数，不允许进行倒运!");
						return cro;
					}
					if (matBcEntity.getBarCode().equals("0")) {
						if (matBcEntity.getQcmStaus().equals("22")
								&& (list.get(0).equals("LYY1") || list.get(0)
										.equals("LFG1"))||list.get(0).equals("LFG2")) {
							sql = CoreXmlSqlParsersFactory
									.getSql("FrmFilpOutStorage.doQueryMatBcScrap");
							sql += CoreConverter.toSqlConditionString(
									"S.STORAGE_NO", storageArr);
							sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
							psta = connection.prepareStatement(sql);
							rs = psta.executeQuery();
							if (rs.next()) {
								aCount = Integer.parseInt(rs.getString("ACOUNT"));
							}
							rs.close();
							psta.close();

							if (aCount > 0) {
								cro.setV_errMsg("废品支数有待审核的，不允许倒运!");
								return cro;
							}
						}
					}

					matBcEntity.setOutstockDoc(outDoc);
					matBcEntity.setOutstockTypeCode("800803");
					matBcEntity.setOutstockTypeName("倒库出库");
					matBcEntity.setOutBz(list.get(3));
					matBcEntity.setOutBc(list.get(2));
					matBcEntity.setCreateName(list.get(1));
					matBcEntity.setTarStorageNo(list.get(0));
					matBcEntity.setVehicleNo(list.get(8));
					matBcEntity.setIccarNo(list.get(9));
					matBcEntity.setMatGowhereCode(list.get(0));
					matBcEntity.setMatGowhereName(list.get(11));
					matBcEntity.setDriver(list.get(10));
					matBcEntity.setOutType(outType);
					matBcEntity.setSupervisorName(superName);
					matBcEntity.setSupervisorCall(superCall);
					//天淮去天淮室外成品库
					if(list.get(0).equals("LSN2")){
						matBcEntity.setOutstockPlanNo("1");
					}else{
						matBcEntity.setOutstockPlanNo("");
					}
					

					String insertOutSql = CoreXmlSqlParsersFactory
							.getSql("FrmFilpOutStorage.doAdd");
					insertOutSql = EntityTool.fillSqlByEntity(insertOutSql,
							matBcEntity);
					psta = connection.prepareStatement(insertOutSql);
					psta.executeUpdate();
					psta.close();
					//sqllist.add(insertOutSql);
				}else
				{
					if(matBcEntity.getQcmStaus().equals(22))
					{
						cro.setV_errMsg("废品不允许按支倒运!");
						return  cro;
					}
					String[] matNo = matBcEntity.getMatNo().split(",");
					for(int i = 0;i<matNo.length;i++)
					{
						matBcEntity.setOutstockDoc(outDoc);
						matBcEntity.setOutstockTypeCode("800803");
						matBcEntity.setOutstockTypeName("倒库出库");
						matBcEntity.setOutBz(list.get(3));
						matBcEntity.setOutBc(list.get(2));
						matBcEntity.setCreateName(list.get(1));
						matBcEntity.setTarStorageNo(list.get(0));
						matBcEntity.setVehicleNo(list.get(8));
						matBcEntity.setIccarNo(list.get(9));
						matBcEntity.setMatGowhereCode(list.get(0));
						matBcEntity.setMatGowhereName(list.get(11));
						matBcEntity.setDriver(list.get(10));
						matBcEntity.setOutType(outType);
						matBcEntity.setMatNoS(matNo[i]);
						//天淮去天淮室外成品库
						if(list.get(0).equals("LSN2")){
							matBcEntity.setOutstockPlanNo("1");
						}else{
							matBcEntity.setOutstockPlanNo("");
						}
						String insertOutSql = CoreXmlSqlParsersFactory
						.getSql("FrmFilpOutStorage.doAddMat");
				        insertOutSql = EntityTool.fillSqlByEntity(insertOutSql,
						matBcEntity);
						psta = connection.prepareStatement(insertOutSql);
						psta.executeUpdate();
						psta.close();
				        //sqllist.add(insertOutSql);
					}
				}

			}

//			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
//			if(cro.getV_errMsg().equals(""))
//			{
//				cro.setV_errMsg("倒库成功!");
//			}

			if(typeFlag.equals("1"))
			{
				if(!list.get(0).equals("LDC2") ) {
					if (( outType.equals("0") && isCarUser.equals("1") ) || ( outType.equals("1") && isCarUserBill.equals("1") ))//写卡倒运
					{
//						if (( ss.getStorageNo().equals("LXW1") || ss.getStorageNo().equals("LGM4") ) && ( list.get(0).equals("LBC1") || list.get(0).equals("LTF1") || list.get(0).equals("LAL1") )) {
//
//						} else {
//						TZH 24.4.24 注销物流接口
						/*
						msg = tmsLoadFrim(outDoc, list.get(8), tmsCon, connection, systime, bathYear,ss.getStorageNo());
						*/
						//}
					}
				}
			}


			if(msg.equals(""))
			{
				connection.commit();
//				TZH 24.4.24 注销物流接口
//				tmsCon.commit();
				//TZH 24.9.4 测试暂时注销
//				mcsCon.commit();
				cro.setV_errMsg("倒库成功!");
			}else
			{
				cro.setV_errMsg(msg);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
//			TZH 24.4.24 注销物流接口			
//			if (connection != null && tmsCon !=null && mcsCon !=null) {
				if (connection != null  ) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
//					TZH 24.4.24 注销物流接口
//					tmsCon.rollback();
//					mcsCon.rollback();
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
//				TZH 24.4.24 注销物流接口
//				if (tmsCon != null && !tmsCon.isClosed()) {
//					tmsCon.close();
//				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}


	/***
	 * 补发计量预报
	 * @param possList
	 * @param userName
	 * @return
	 */
	public CoreReturnObject addPreDictNo(ArrayList<String> possList,String userName)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Connection mcsCon = this.getDao("McmsDao").getConnection();
		PreparedStatement ps = null;
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String systime = dateFormat.format(now);


		Calendar calen = new GregorianCalendar();
		calen.setTime(now);
		calen.add(calen.DATE,1);
		now = calen.getTime();
		String systimeN = dateFormat.format(now);
		try {
			mcsCon.setAutoCommit(false);
			String sql = "";
			String jlmatterNo = "";//计量系统物料编号
			String jlmatterName = "";//计量系统物料名称
			String forUnitNo = "";//计量系统来源编号
			String predictNo = "";//预报编号
			String reciveUnitNo = "";//收货仓库名称
			int acount = 0;

			for(String str : possList)
			{
				YdmBcOutlistEntity ydmOutEntity = EntityTool.getEntityByJSONStr(str,
						YdmBcOutlistEntity.class);
				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectOutInformation");
				sql = EntityTool.fillSqlByEntity(sql,ydmOutEntity);
				ps = connection.prepareStatement(sql);
				rs = ps.executeQuery();
				List<YdmBcOutlistEntity> ydmEntity = EntityTool.getEntitysByRs(rs,YdmBcOutlistEntity.class);
				rs.close();
				ps.close();

				if(ydmEntity.get(0).getVehicleNo().equals(""))
				{
					cro.setV_errMsg("倒库单车号为空,不允许补发计量预报!");
					return  cro;
				}

				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectJlMatter");
				sql = EntityTool.fillSqlByEntity(sql,ydmEntity.get(0));
				ps = mcsCon.prepareStatement(sql);
				rs = ps.executeQuery();
				if(rs.next())
				{
					jlmatterNo = rs.getString("MATTER_NO");
					jlmatterName = rs.getString("MATTER_NAME");
				}
				rs.close();
				ps.close();
				if(jlmatterNo.equals("")||jlmatterName.equals(""))
				{
					cro.setV_errMsg("补发预报时产销物料未在计量系统的基础物料中,无法进行计量预报补发!");
					return  cro;
				}

				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectOutPreDictNo");
				sql = EntityTool.fillSqlByEntity(sql,ydmEntity.get(0));
				ps = mcsCon.prepareStatement(sql);
				rs = ps.executeQuery();
				if(rs.next())
				{
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				ps.close();
				if(acount > 0)
				{
					cro.setV_errMsg("该车辆预报已下发至计量中，不允许重复下发!");
					return cro;
				}

				// 查询品名是否计量
				String jlFlag = "";
				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectjlFalgByProduct");
				ps = connection.prepareStatement(sql);
				ps.setString(1,ydmEntity.get(0).getProduccode());
				rs = ps.executeQuery();
				if(rs.next())
				{
					jlFlag = rs.getString("JL_FALG");
				}
				rs.close();
				ps.close();

				if(!StringUtils.isEmpty(jlFlag) && !"1".equals(jlFlag)){
					cro.setV_errMsg("非下线管，不允许下发!");
					return cro;
				}

				forUnitNo = getJlLoad(ydmEntity.get(0).getStorageNo(),mcsCon);
				reciveUnitNo = getJlLoad(ydmEntity.get(0).getTarStorageNo(),mcsCon);

				predictNo = getPreDictNo(mcsCon);
				PreTrackScaleEntity preEntity = new PreTrackScaleEntity();
				preEntity.setNoticeNo(ydmEntity.get(0).getOutstockDoc());
				preEntity.setPredictionNo(predictNo);
				preEntity.setCarNo(ydmEntity.get(0).getVehicleNo());
				preEntity.setMatterNo(jlmatterNo);
				preEntity.setMatterName(jlmatterName);
				preEntity.setContractNo(ydmEntity.get(0).getProOrderNo());
				preEntity.setForwardingUnitNo(forUnitNo);
				preEntity.setForwardingUnitName(ydmEntity.get(0).getStorageName());
				preEntity.setReceivingUintNo(reciveUnitNo);
				preEntity.setReceivingUintName(ydmEntity.get(0).getTarStorageName());
				preEntity.setMaterialNo(ydmEntity.get(0).getMaterialNo());
				preEntity.setMaterialName(ydmEntity.get(0).getMaterialName());
				preEntity.setSpecNo(ydmEntity.get(0).getSpecCode());
				preEntity.setSpecName(ydmEntity.get(0).getSpecName());
				preEntity.setPredictionType("1");
				preEntity.setUsedType("0");
				preEntity.setValueFlag("1");
				preEntity.setCreateManNo("admin");
				preEntity.setCreateManName(userName);
				preEntity.setCreateTime(systime);
				preEntity.setMeterTypeNo("001006011");
				preEntity.setMeterTypeName("中控倒运（下线管收货确认）");
				preEntity.setEffectiveNum("1");
				preEntity.setHeatNo(ydmEntity.get(0).getJudgeStoveNo());
				preEntity.setEffectiveStartTime(systime);
				preEntity.setEffectiveEndTime(systimeN);
				preEntity.setProcessNo("202403190011");

				// 查询计量供应商
				String jlgys = "";
				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectjlgysByPline");
				ps = connection.prepareStatement(sql);
				ps.setString(1,ydmEntity.get(0).getPlineCode());
				rs = ps.executeQuery();
				if(rs.next())
				{
					jlgys = rs.getString("JL_SUPP");
				}
				rs.close();
				ps.close();
				if(StringUtils.isEmpty(jlgys))
				{
					cro.setV_errMsg(ydmEntity.get(0).getPlineName()+"没有维护计量供应商,无法生成计量预报!");
					return  cro;
				}
				preEntity.setCustomerSupplierNo(jlgys);
				if(!"801401".equals(ydmOutEntity.getProductFlag()) && !"在制品".equals(ydmOutEntity.getProductFlag())){
					preEntity.setMeterTypeNo("001006010");
					preEntity.setMeterTypeName("中控倒运（下线管）");
					preEntity.setProcessNo("202403180010");
				}
				if(ydmOutEntity.getProducname().equals("接箍坯料")){
					preEntity.setMeterTypeNo("001006012");
					preEntity.setMeterTypeName("中控倒运（非下线管需收货确认）");
					preEntity.setProcessNo("202403300012");
				}
				// 计量预报
				String insertPreDictNoSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.InsertPreDictNo");
				insertPreDictNoSql = EntityTool.fillSqlByEntity(insertPreDictNoSql,preEntity);
				ps = mcsCon.prepareStatement(insertPreDictNoSql);
				ps.executeUpdate();
				ps.close();
				// 计量环节
				String insertPreProcessLink = CoreXmlSqlParsersFactory.getSql("PreTrackNotice.InsertPreProcess_LINK");
				insertPreProcessLink = EntityTool.fillSqlByEntity(insertPreProcessLink, preEntity);
				ps = mcsCon.prepareStatement(insertPreProcessLink);
				ps.executeUpdate();
				ps.close();
			}

			mcsCon.commit();
			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) {
				}
			}
			if (mcsCon != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					mcsCon.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
			cro.setV_errMsg("计量预报补发失败!");
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	/***
	 * 查询计量系统中装卸点代码
	 * @param storageNo
	 * @param con
	 * @return
	 */
	public String getJlLoad(String storageNo,Connection con) throws SQLException {
		String loadCode = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getLoadCode");
		ps = con.prepareStatement(sql);
		ps.setString(1,storageNo);
		rs = ps.executeQuery();
		if(rs.next())
		{
			loadCode = rs.getString("LOAD_POINT_NO");
		}
		rs.close();
		ps.close();


		return  loadCode;
	}
	/***
	 * 查询仓库所属单位、是否在线库标识
	 * @param storageNo
	 * @param con
	 * @return
	 */
	public String getStorageFlag(String storageNo,Connection con) throws SQLException {
		String strFlag = "";
		int count = 0;
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getStorageFlag");
		ps = con.prepareStatement(sql);
		ps.setString(1,storageNo);
		rs = ps.executeQuery();
		if(rs.next())
		{
			count = Integer.parseInt(rs.getString("ACOUNT"));
		}
		rs.close();
		ps.close();
		if(count > 0)
		{
			strFlag = "1";
		}else
		{
			strFlag = "0";
		}

		return  strFlag;
	}

	/***
	 * 获取预报编号
	 * @param mcsCon
	 * @return
	 */
	public String getPreDictNo(Connection mcsCon) throws SQLException {
		String preDictNo = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getPreDictNo");
		ps = mcsCon.prepareStatement(sql);
		rs = ps.executeQuery();
		if(rs.next())
		{
			preDictNo = rs.getString("PREDICTION_NO");
		}
		rs.close();
		ps.close();
		return preDictNo;
	}
	/***
	 * 写卡时直接装车确认
	 * @param
	 * @param carNo
	 * @param tmsCon
	 * @return
	 */
	public String tmsLoadFrim(String outDoc,String carNo,Connection tmsCon,Connection con,String systime,String bathYear,String storageNo) throws SQLException {
		     String mesg  = "";
		     int lineStartCount = 0;
		     int lineEndCount = 0;
		     int outLineStartCount = 0;
		     int outLineEndCount = 0;
		     int unLoadCount = 0;
		     int updateTmsWCount = 0;
		try {


			String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.SelectWayM");
			PreparedStatement psta = tmsCon.prepareStatement(sql);
			psta.setString(1, carNo);
			ResultSet rs = psta.executeQuery();
			TmsWaybillMEntity tmsWayMEntity = EntityTool.getEntityByRs(rs,
					TmsWaybillMEntity.class);
			rs.close();
			psta.close();
			String wgt = "";

			//查询写拖车运单子表
			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectWgt");
			psta = con.prepareStatement(sql);
			psta.setString(1, outDoc);
			rs = psta.executeQuery();
			List<YdmBcOutlistEntity> list = EntityTool.getEntitysByRs(rs,
					YdmBcOutlistEntity.class);
			rs.close();
			psta.close();





			String startCode = "";
			String startDesc = "";
			String startAreaCode = "";
			String startAreaDesc = "";
			String endCode = "";
			String endDesc = "";
			String endAreaCode = "";
			String endAreaDesc = "";
			String processCode = "";
			String processDesc = "";
			String demandOrgCode = "";
			String demandOrgDesc ="";
			for (YdmBcOutlistEntity ydm : list) {
				TmsWaybillCEntity tmsWayCEntity = new TmsWaybillCEntity();

				tmsWayCEntity.setWaybillNo(tmsWayMEntity.getWaybillNo());

				tmsWayCEntity.setPlnNo(tmsWayMEntity.getPlnNo());

				tmsWayCEntity.setHeatNo(ydm.getJudgeStoveNo());
				tmsWayCEntity.setBatchNo(ydm.getBatchNo());
				tmsWayCEntity.setGroupNo(ydm.getBatchGroudNo());
				tmsWayCEntity.setLogoNo(ydm.getFlagStoveNoZg());
				tmsWayCEntity.setMaterialsCode(ydm.getMaterialNo());
				tmsWayCEntity.setMaterialsDesc(ydm.getMaterialName());
				tmsWayCEntity.setMaterialsSpec(ydm.getSpecName());
				tmsWayCEntity.setMaterialsDimater(ydm.getActDimater());
				tmsWayCEntity.setMaterialsHeight(ydm.getActHeight());
				tmsWayCEntity.setWaybillQtyVal(ydm.getActCount());
				tmsWayCEntity.setWaybillWtVal(ydm.getActWeight());
				tmsWayCEntity.setRefPlnNo(ydm.getOutstockDoc());
				tmsWayCEntity.setMatType("1");
				tmsWayCEntity.setSupervisorName(ydm.getSupervisorName());
				tmsWayCEntity.setSupervisorCall(ydm.getSupervisorCall());
				tmsWayCEntity.setPlineCode(ydm.getPlineCode());
				tmsWayCEntity.setPlineName(ydm.getPlineName());

				//查询工序代码
				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectProcess");
				psta = con.prepareStatement(sql);
				psta.setString(1,ydm.getPlineCode());

				rs = psta.executeQuery();
				if(rs.next())
				{
					processCode = rs.getString("PROCESS_CODE");
					processDesc = rs.getString("PROCESS_DESC");
				}
				rs.close();
				psta.close();

				tmsWayCEntity.setProcessCdoe(processCode);
				tmsWayCEntity.setProcessDesc(processDesc);

				tmsWayCEntity.setProduccode(ydm.getProduccode());
				tmsWayCEntity.setProducname(ydm.getProducname());
				tmsWayCEntity.setProductCode(ydm.getProductCode());
				tmsWayCEntity.setProductName(ydm.getProductName());
				tmsWayCEntity.setProductFlag(ydm.getProductFlag());
				tmsWayCEntity.setMatStatus(ydm.getMatStatus());
				tmsWayCEntity.setQcmStaus(ydm.getQcmStaus());

				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectStartArea");
				psta = tmsCon.prepareStatement(sql);
				psta.setString(1,tmsWayMEntity.getPlnNo());
				psta.setString(2,ydm.getJudgeStoveNo());
				psta.setString(3,ydm.getStorageNo());
				rs = psta.executeQuery();
				if(rs.next())
				{
					 startCode = rs.getString("START_NODE_CODE");
					 startDesc = rs.getString("START_NODE_DESC");
					 startAreaCode = rs.getString("START_AREA_CODE");
					 startAreaDesc = rs.getString("START_AREA_DESC");
					endCode = rs.getString("END_NODE_CODE");
					endDesc = rs.getString("END_NODE_DESC");
					endAreaCode = rs.getString("END_AREA_CODE");
					endAreaDesc = rs.getString("END_AREA_DESC");
					demandOrgCode = rs.getString("DEMAND_ORG_CODE");
					demandOrgDesc = rs.getString("DEMAND_ORG_DESC");
				}
				rs.close();
				psta.close();

				tmsWayCEntity.setStartNodeCode(startCode);
				tmsWayCEntity.setStartNodeDesc(startDesc);
				tmsWayCEntity.setStartAreaCode(startAreaCode);
				tmsWayCEntity.setStartAreaDesc(startAreaDesc);
				tmsWayCEntity.setEndNodeCode(endCode);
				tmsWayCEntity.setEndNodeDesc(endDesc);
				tmsWayCEntity.setEndAreaCode(endAreaCode);
				tmsWayCEntity.setEndAreaDesc(endAreaDesc);
				tmsWayCEntity.setDemandOrgCode(demandOrgCode);
				tmsWayCEntity.setDemandOrgDesc(demandOrgDesc);

				String insertWayCSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.insertWayC");
				insertWayCSql = EntityTool.fillSqlByEntity(insertWayCSql, tmsWayCEntity);
				psta = tmsCon.prepareStatement(insertWayCSql);
				psta.executeUpdate();
				psta.close();
			}
			//写装车实绩表
			TmsExecuteBEntity tmsExEntity = new TmsExecuteBEntity();
			tmsExEntity.setUnloadingCode(tmsWayMEntity.getStartNodeCode());
			tmsExEntity.setCarLicense(tmsWayMEntity.getCarLicense());
			tmsExEntity.setPlnNo(tmsWayMEntity.getPlnNo());
			tmsExEntity.setRefeNo(outDoc);
			tmsExEntity.setWaybillNo(tmsWayMEntity.getWaybillNo());
			tmsExEntity.setExecuteTime(systime);
			tmsExEntity.setAccountYearMonth(bathYear);
			tmsExEntity.setCreateTime(systime);
			String insertExcuteSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.insertExcute");
			insertExcuteSql = EntityTool.fillSqlByEntity(insertExcuteSql, tmsExEntity);
			psta = tmsCon.prepareStatement(insertExcuteSql);
			psta.executeUpdate();
			psta.close();

			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectLineCount");
			psta = tmsCon.prepareStatement(sql);
			psta.setString(1,tmsWayMEntity.getPlnNo());
			psta.setString(2,storageNo);
			rs = psta.executeQuery();
			if(rs.next())
			{
				lineStartCount = Integer.parseInt(rs.getString("ACOUNT"));
			}
			rs.close();
			psta.close();

			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectTmsWCount");
			psta = tmsCon.prepareStatement(sql);
			psta = tmsCon.prepareStatement(sql);
			psta.setString(1,tmsWayMEntity.getWaybillNo());
			psta.setString(2,storageNo);
			rs = psta.executeQuery();
			if(rs.next())
			{
				outLineStartCount = Integer.parseInt(rs.getString("ACOUNT"));
			}
			rs.close();
			psta.close();

			//出库写卡子记录与计划子记录路线条数一样写装车确认、装车离开
			if(lineStartCount == outLineStartCount)
			{
				//写跟踪表装车确认
				TmsTraceMEntity tmsTraceEntity = new TmsTraceMEntity();
				tmsTraceEntity.setWaybillNo(tmsWayMEntity.getWaybillNo());
				tmsTraceEntity.setNodeTypeCode("N02");
				tmsTraceEntity.setNodeTypeDesc("装卸点");
				tmsTraceEntity.setRefeNo(outDoc);
				//tmsTraceEntity.setTraceNo("3");
				tmsTraceEntity.setEventCode("RC04");
				tmsTraceEntity.setEventDesc("装车确认");
				tmsTraceEntity.setEventTime(systime);
				String insertTraceMSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.insertTraceM");
				insertTraceMSql = EntityTool.fillSqlByEntity(insertTraceMSql, tmsTraceEntity);
				psta = tmsCon.prepareStatement(insertTraceMSql);
				psta.executeUpdate();
				psta.close();


				//写跟踪表装车离开
				TmsTraceMEntity tmsTraceEntity1 = new TmsTraceMEntity();
				tmsTraceEntity1.setWaybillNo(tmsWayMEntity.getWaybillNo());
				tmsTraceEntity1.setNodeTypeCode("N02");
				tmsTraceEntity1.setNodeTypeDesc("装卸点");
				tmsTraceEntity1.setRefeNo(outDoc);
				//tmsTraceEntity1.setTraceNo("4");
				tmsTraceEntity1.setEventCode("RC14");
				tmsTraceEntity1.setEventDesc("装车离开");
				tmsTraceEntity1.setEventTime(systime);

				tmsTraceEntity1.setNodeCode(startCode);
				tmsTraceEntity1.setNodeDesc(startDesc);
				String insertTraceMSql1 = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.insertTraceM");
				insertTraceMSql1 = EntityTool.fillSqlByEntity(insertTraceMSql1, tmsTraceEntity1);
				psta = tmsCon.prepareStatement(insertTraceMSql1);
				psta.executeUpdate();
				psta.close();


				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectTmsPlnC");//查询计划子表
				sql = EntityTool.fillSqlByEntity(sql,tmsWayMEntity);
				psta = tmsCon.prepareStatement(sql);
				rs = psta.executeQuery();
				List<TmsPlnCEntity> tmsPlnCEntity = EntityTool.getEntitysByRs(rs,
						TmsPlnCEntity.class);
				rs.close();
				psta.close();
				for(TmsPlnCEntity tmPlnC:tmsPlnCEntity)
				{
					sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectTmsPlanCount");//判断时否多装点都已装完
					sql = EntityTool.fillSqlByEntity(sql,tmPlnC);
					psta = tmsCon.prepareStatement(sql);
					rs = psta.executeQuery();
					if(rs.next())
					{
						unLoadCount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if(unLoadCount == 0)
					{
						updateTmsWCount = updateTmsWCount + 1;
					}
				}


				if(updateTmsWCount > 0)
				{
					tmsWayMEntity.setValidflag("10");
				}else
				{
					tmsWayMEntity.setValidflag("40");
				}
				//修改运单主表

				String updateWayMSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.updateWayM");
				updateWayMSql = EntityTool.fillSqlByEntity(updateWayMSql, tmsWayMEntity);
				psta = tmsCon.prepareStatement(updateWayMSql);
				psta.executeUpdate();
				psta.close();
			}



			//装车时吊车单号不为空时
			if (!tmsWayMEntity.getCraneWaybillNo1().equals("")) {
				TmsWaybillCEntity tmsWayCEntity = new TmsWaybillCEntity();

				tmsWayCEntity.setWaybillNo(tmsWayMEntity.getCraneWaybillNo1());

				tmsWayCEntity.setWaybillNoT(tmsWayMEntity.getWaybillNo());//拖车运单号

				String insertCraneWayCSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.insertCraneWayC");
				insertCraneWayCSql = EntityTool.fillSqlByEntity(insertCraneWayCSql, tmsWayCEntity);
				psta = tmsCon.prepareStatement(insertCraneWayCSql);
				psta.executeUpdate();
				psta.close();
			}else
			{
				tmsWayMEntity.setNodeCode(startCode);
				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectTmsWayRealation");
				sql = EntityTool.fillSqlByEntity(sql,tmsWayMEntity);
				psta = tmsCon.prepareStatement(sql);
				rs = psta.executeQuery();
				List<TmsWaybillRelationEntity> realationList = EntityTool.getEntitysByRs(rs,
						TmsWaybillRelationEntity.class);
				rs.close();
				psta.close();
				if(realationList.size() > 0)
				{
					//TmsWaybillCEntity tmsWayCEntity = new TmsWaybillCEntity();


					String insertCraneWayCSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.insertCraneWayC");
					insertCraneWayCSql = EntityTool.fillSqlByEntity(insertCraneWayCSql, realationList.get(0));
					psta = tmsCon.prepareStatement(insertCraneWayCSql);
					psta.executeUpdate();
					psta.close();
				}

			}



		} catch (Exception e) {
			mesg = e.getMessage();
		}
		return mesg;

	}



	/***
	 * 撤销倒库
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject doDelete(ArrayList<String> parmList,ArrayList<String> possList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
//		TZH 24.4.24 注销物流接口
//		Connection tmsCon = this.getDao("TmsDao").getConnection();
//		Connection mscCon = this.getDao("McmsDao").getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		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 tarFlag = "";
		String  wayBillStaus = "";//运单状态
		String wayBillNo = "";//运单号
		int tarAcount = 0;
		String isCarUser = "";//是否限制了一车一卡
		String isCarUserBill = "";
		String plnNo = "";//计划号
		int plnLineCount = 0;
		String eventCode = "";//事件节点
		String nodeCode = "";
		String preDictNoFlag = "";//预报状态标识
		try {
//			TZH 24.4.24 注销物流接口
//			tmsCon.setAutoCommit(false);
//			mscCon.setAutoCommit(false);
			ArrayList<String> sqllist = new ArrayList<String>();

			for(String str1 : possList) {
				YdmBcOutlistEntity ydmBcOutDoc = EntityTool.getEntityByJSONStr(str1, YdmBcOutlistEntity.class);
				if(ydmBcOutDoc.getOutType().equals("写卡倒运") || ydmBcOutDoc.getOutType().equals("票据倒运")) {
					sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectWayBillStaus");
//					TZH 24.4.24 注销物流接口
//					psta = tmsCon.prepareStatement(sql);
//					psta.setString(1, ydmBcOutDoc.getOutstockDoc());
//					rs = psta.executeQuery();
//					if (rs.next()) {
//						wayBillStaus = rs.getString("VALIDFLAG");
//						wayBillNo = rs.getString("WAYBILL_NO");
//						plnNo = rs.getString("PLN_NO");
//					}
//					rs.close();
//					psta.close();
					if (!wayBillStaus.equals("")) {
						TmsWaybillMEntity tmsWaybillM = new TmsWaybillMEntity();
						tmsWaybillM.setPlnNo(plnNo);
						tmsWaybillM.setWaybillNo(wayBillNo);
//						TZH 24.4.24 注销物流接口
//						sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectLineCount");
//						psta = tmsCon.prepareStatement(sql);
//						psta.setString(1,tmsWaybillM.getPlnNo());
//						psta.setString(2,ydmBcOutDoc.getStorageNo());
//						rs = psta.executeQuery();
//						if (rs.next()) {
//							plnLineCount = Integer.parseInt(rs.getString("ACOUNT"));
//						}
//						rs.close();
//						psta.close();

						if (plnLineCount == 1) {
							if (!wayBillStaus.equals("40") && !wayBillStaus.equals("10")) {
								cro.setV_errMsg("司机运单不是装车离开状态,不允许撤销倒库!");
								return cro;
							}
						}
//						TZH 24.4.24 注销物流接口
//						sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectTraceM");
//						sql = EntityTool.fillSqlByEntity(sql,tmsWaybillM);
//						psta = tmsCon.prepareStatement(sql);
//						rs = psta.executeQuery();
//						if(rs.next())
//						{
//							eventCode = rs.getString("EVENT_CODE");
//						}
//						rs.close();
//						psta.close();
						if(!eventCode.equals("RC14"))
						{
							cro.setV_errMsg("司机不是装车离开状态,不允许撤销倒库!");
							return  cro;
						}
					}

				}


			for(String str : parmList)
			{
				YdmBcOutlistEntity ydmBcOutList = EntityTool.getEntityByJSONStr(str, YdmBcOutlistEntity.class);
				if(ydmBcOutList.getTarRecFlag().equals("已接收"))
				{
					cro.setV_errMsg("已接收的倒库单不允许撤销!");
					return cro;
				}
				if(ydmBcOutList.getQcmStaus().equals("合格"))
				{
					ydmBcOutList.setQcmStaus("00");
				}else if(ydmBcOutList.getQcmStaus().equals("待处理"))
				{
					ydmBcOutList.setQcmStaus("11");
				}else if(ydmBcOutList.getQcmStaus().equals("判废"))
				{
					ydmBcOutList.setQcmStaus("22");
				}

				if(ydmBcOutList.getTarRecFlag().equals("未接收"))
				{
					ydmBcOutList.setTarRecFlag("0");
				}else if(ydmBcOutList.getTarRecFlag().equals("已接收"))
				{
					ydmBcOutList.setTarRecFlag("1");
				}
				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectYdmOutTarFlag");
				sql = EntityTool.fillSqlByEntity(sql, ydmBcOutList);
				psta = connection.prepareStatement(sql);
				rs = psta.executeQuery();
				if(rs.next())
				{
					tarAcount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if(tarAcount > 0)
				{
					cro.setV_errMsg("物料已被接收,不允许撤销倒库!");
					return cro;
				}
				String deleteYdmOutSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.doDelte");
				deleteYdmOutSql = EntityTool.fillSqlByEntity(deleteYdmOutSql, ydmBcOutList);
				sqllist.add(deleteYdmOutSql);


				if(!wayBillNo.equals(""))
				{
					if(ydmBcOutList.getOutType().equals("写卡倒运") || ydmBcOutList.getOutType().equals("票据倒运"))
					{
						TmsWaybillMEntity tmsWaybillM = new TmsWaybillMEntity();
						tmsWaybillM.setPlnNo(plnNo);
						tmsWaybillM.setWaybillNo(wayBillNo);
						tmsWaybillM.setValidflag("20");
						tmsWaybillM.setLogoNo(ydmBcOutList.getFlagStoveNoZg());
						tmsWaybillM.setRefeNo(ydmBcOutList.getOutstockDoc());

//						TZH 24.4.24 注销物流接口
//						sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectTraceMNode");
//						sql = EntityTool.fillSqlByEntity(sql,tmsWaybillM);
//						psta = tmsCon.prepareStatement(sql);
//						rs = psta.executeQuery();
//						if(rs.next())
//						{
//							nodeCode = rs.getString("NODE_CODE");
//						}
//						rs.close();
//						psta.close();

						tmsWaybillM.setNodeCode(nodeCode);
//						TZH 24.4.24 注销物流接口
//						String updateWayBillSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.cancelLoadFrim");
//						updateWayBillSql = EntityTool.fillSqlByEntity(updateWayBillSql,tmsWaybillM);
//						psta = tmsCon.prepareStatement(updateWayBillSql);
//						psta.executeUpdate();
//						psta.close();
					}
				}


				}

//				sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.selectPreDictNoFlag");
//				sql = EntityTool.fillSqlByEntity(sql,ydmBcOutDoc);
//				psta = mscCon.prepareStatement(sql);
//				rs = psta.executeQuery();
//				if(rs.next())
//				{
//					preDictNoFlag = rs.getString("VALUE_FLAG");
//				}
//				rs.close();
//				psta.close();
//				if(preDictNoFlag.equals("1"))
//				{
//				String deletePreDictNoSql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.updatePreDoctNo");
//				deletePreDictNoSql = EntityTool.fillSqlByEntity(deletePreDictNoSql,ydmBcOutDoc);
//				psta = mscCon.prepareStatement(deletePreDictNoSql);
//				psta.executeUpdate();
//				psta.close();
//				}

			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
//				TZH 24.4.24 注销物流接口
//				tmsCon.commit();
				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) {
				}
			}
//			TZH 24.4.24 注销物流接口
//			if (tmsCon != null) {
//				try {
//					cro.setV_errMsg(e.getMessage());
//					tmsCon.rollback(); // 回滚事务
//				} catch (Exception e2) {
//				}
//			}
//			if (mscCon != null) {
//				try {
//					cro.setV_errMsg(e.getMessage());
//					mscCon.rollback(); // 回滚事务
//				} catch (Exception e2) {
//				}
//			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
//				TZH 24.4.24 注销物流接口
//				if (tmsCon != null && !tmsCon.isClosed()) {
//					tmsCon.close();
//				}
//				if (mscCon != null && !mscCon.isClosed()) {
//					mscCon.close();
//				}
			} catch (Exception e2) {
			}
		}
		return cro;
 }

	/***
	 * 生成入库单号
	 * @param connection
	 * @param matGowhereCode
	 * @param strBound
	 * @param systime
	 * @return
	 * @throws SQLException
	 */
	private String getInDoc(Connection connection, String matGowhereCode,
			String strBound, String systime) throws SQLException {
		String inDoc = "";
		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getInDoc");
		PreparedStatement psta = connection.prepareStatement(sql);
		psta.setString(1, systime);
		psta.setString(2, strBound);
		psta.setString(3, systime);
		ResultSet rs = psta.executeQuery();
		if(rs.next())
		{
			inDoc = rs.getString("INSTOCK_DOC");
		}
		rs.close();
		psta.close();
		
		return inDoc;
	}

	/***
	 * 生成出库单号
	 * @param connection
	 * @param storageNo
	 * @param strBound
	 * @param systime
	 * @return
	 * @throws SQLException
	 */
	private String getOutDoc(Connection connection, String storageNo,
			String strBound, String systime,String outType) throws SQLException {
		String outDoc = "";
		String sql = "";
		if(outType.equals("0"))
		{
			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getOutDoc1");
		}
		else
		{
			sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getOutDoc");
		}
		PreparedStatement psta = connection.prepareStatement(sql);
		psta.setString(1, storageNo);
		//psta.setString(2, strBound);
		psta.setString(2, storageNo);
		ResultSet rs = psta.executeQuery();
		if(rs.next())
		{
			outDoc = rs.getString("OUTSTOCK_DOC");
		}
		rs.close();
		psta.close();
		return outDoc;
	}
	
	/***
	 * 查询出库单号
	 * @param storageNo
	 * @param strBound
	 */
	public CoreReturnObject getOutDocS(String storageNo,String strBound)
	{
		return this.getDataBySqlID("FrmFilpOutStorage.getOutDoc", new Object[]{storageNo,storageNo});
	}
	
	/***
	 * 查询单号下是否有未接收数据
	 * @param outDoc
	 * @return
	 */
	public CoreReturnObject doQueryCount(String outDoc)
	{
		return this.getDataBySqlID("FrmFilpOutStorage.doQueryCount", new Object[]{outDoc});
	}

	/***
	 * 保存倒库单号
	 * @param outDoc
	 * @return
	 */
	public CoreReturnObject insertDoc(String outDoc)
	{
		return  this.setDataBySqlID("FrmFilpOutStorage.insertOutdoc",new Object[]{outDoc});
	}
	/***
	 * 删除倒库单号
	 * @param outDoc
	 * @return
	 */
	public CoreReturnObject deleteDoc(String outDoc)
	{
		return  this.setDataBySqlID("FrmFilpOutStorage.deleteDoc",new Object[]{outDoc});
	}
	/**
	 * 天淮去天淮室外成品库，过磅直接取倒运信息处理
	 * @param carNo
	 * @return
	 */
	public CoreReturnObject updateOutstockPlanNo(String carNo)
	{
		return  this.setDataBySqlID("FrmFilpOutStorage.updateOutstockPlanNo",new Object[]{carNo});
	}
	
	/**
	 * 天淮内倒车辆是否只有一个出库单号
	 * @param carNo
	 * @return
	 */
	public CoreReturnObject getCarNo(String carNo)
	{
		return this.getDataBySqlID("FrmFilpOutStorage.getCarNo", new Object[]{carNo});
	}

	/***
	 * 申请用车生成运输需求
	 * @param parmList
	 * @param userName
	 * @return
	 */
	public CoreReturnObject doWriteDemand(ArrayList<String> parmList,String userName,String tarStoageNo,String tarStorageName)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
//		TZH 24.4.24 注销物流接口
//		Connection tmsCon = this.getDao("TmsDao").getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		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);
		int acount = 0;
		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");
				}

				if (matBcEntity.getProductFlag().equals("在制品")) {
					matBcEntity.setProductFlag("801401");
				} else if (matBcEntity.getProductFlag().equals("成品")) {
					matBcEntity.setProductFlag("801402");
				} else if (matBcEntity.getProductFlag().equals("商品")) {
					matBcEntity.setProductFlag("801403");
				}
//				TZH 24.4.24 注销物流接口
//				String msg = writeDemand.writeOutDemand(matBcEntity,userName,tarStoageNo,tarStorageName,tmsCon,connection,"0","","","","","0");
//				if(!msg.equals(""))
//				{
//					acount = acount +1;
//
//				}
			}
			if(acount >0)
			{
				cro.setV_errMsg("申请用车出错!");
			}else
			{
				cro.setV_errMsg("申请用车成功!");
			}
			return  cro;

		} catch (Exception e) {
			System.out.println(e.getMessage());
//			TZH 24.4.24 注销物流接口
//			if (connection != null||tmsCon !=null) {
				if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
//					TZH 24.4.24 注销物流接口
//					tmsCon.rollback();
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
//				TZH 24.4.24 注销物流接口
//				if (tmsCon != null && !tmsCon.isClosed()) {
//					tmsCon.close();
//				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 撤销用车需求
	 * @param parmList
	 * @param userName
	 * @return
	 */
	public CoreReturnObject cancelDemand(ArrayList<String> parmList,String userName)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
//		TZH 24.4.24 注销物流接口
//		Connection tmsCon = this.getDao("TmsDao").getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		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);
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				TmsDemandMEntity tmsDemandMEntity = EntityTool.getEntityByJSONStr(str,TmsDemandMEntity.class);
//				TZH 24.4.24 注销物流接口
//				String msg = writeDemand.deleteDemand(tmsDemandMEntity,userName,tmsCon);
//				if(!msg.equals(""))
//				{
//					cro.setV_errMsg(msg);
//					return  cro;
//				}
			}
			cro.setV_errMsg("撤销成功!");
		} catch (Exception e) {
			System.out.println(e.getMessage());
//			TZH 24.4.24 注销物流接口
//			if (connection != null||tmsCon !=null) {
				if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
//					TZH 24.4.24 注销物流接口
//					tmsCon.rollback();
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
//				TZH 24.4.24 注销物流接口
//				if (tmsCon != null && !tmsCon.isClosed()) {
//					tmsCon.close();
//				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 加载监装人
	 * @param arr
	 * @param
	 * @return
	 */
	public CoreReturnObject getSuperName(String[] arr,String userGroup)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getSuperName");
		sql += CoreConverter.toSqlConditionString("T.OUT_REPOSITORY",arr);
		sql += " ) T2 WHERE T1.PLINE_CODE = T2.PLINE_CODE";
		sql += " AND T1.COL_GROUP = '"+userGroup+"'";
		return  this.getData(sql);
	}
	
	
//	TZH 24.4.24 注销物流接口
//	/**
//	 * 查询需求
//	 *
//	 * @param
//	 * @return
//	 */
//	public CoreReturnObject doQueryPln(ArrayList<String> parmList,String[] storageNos,String[] status
//	)
//	{
//
//		String sql = CoreXmlSqlParsersFactory
//				.getSql("TmsDemand.doQueryPln");
//		if (!parmList.get(0).equals("")) {
//			sql += " AND M.CREATE_TIME >=TO_DATE('" + parmList.get(0)
//					+ "', 'YYYY-MM-DD HH24:MI:SS')";
//		}
//
//		if (!parmList.get(1).equals("")) {
//			sql += " AND M.CREATE_TIME <=TO_DATE('" + parmList.get(1)
//					+ "', 'YYYY-MM-DD HH24:MI:SS') ";
//		}
//
//		if(!"".equals(parmList.get(2))){
//			sql += "     and EXISTS (SELECT 1 FROM TMS_PLN_C WHERE  PLN_NO = M.PLN_NO " +
//					CoreConverter.toSqlConditionString("HEAT_NO", parmList.get(2).replace("，",",").split(","))
//					+" )";
//		}
//		if(!"".equals(parmList.get(3)))
//		{
//			sql += "     and EXISTS (SELECT 1 FROM TMS_PLN_C WHERE LOGO_NO= '"+  parmList.get(3) +"'  AND PLN_NO = M.PLN_NO)";
//		}
//		sql += CoreConverter.toSqlConditionString("M.VALIDFLAG", status);
//
//
//		sql += CoreConverter.toSqlConditionString("M.START_AREA_CODE", storageNos);
//		sql  = sql.replace("M.START_AREA_CODE","(M.START_AREA_CODE");
//		String str = CoreConverter.toSqlConditionString("M.END_AREA_CODE", storageNos);
//		str = str.replace("AND","OR");
//		sql += str + ")";
//		sql += " Order by M.TRANSPORT_START_TIME";
//
//		return this.getData("TmsDao",sql);
//	}

	/***
	 * 查询仓库所属区域
	 * @param storageNo
	 * @return
	 */
	public CoreReturnObject doQueryStorageArea(String storageNo)
	{
		return  this.getDataBySqlID("FrmFilpOutStorage.queryStoreArea",new Object[]{storageNo});
	}

	/***
	 * 查询已过皮重车辆
	 * @return
	 */
	public  CoreReturnObject doQueryCarNo()
	{
		return  this.getDataBySqlID("FrmFilpOutStorage.doQueryCarNo");
	}

	/**
	 * 根据科室ID查询对应的部门信息
	 * @param section 科室
	 * @return obj
	 */
	public CoreReturnObject getDeptBySection(String section){
		Object[] params = new Object[]{section};
		return this.getDataBySqlID("ComLgValidDataPurviewIds.getDepartmentBySectionID", params);
	}

	/**
	 * 根据部门表的ID获取对应的描述
	 * @param id
	 * @return
	 */
	public CoreReturnObject getDepartDescByDepartId(String id){
		String sql = CoreXmlSqlParsersFactory.getSql("ComLgValidDataPurviewIds.getDepartDescByDepartId");
		sql = StringTool.ReplaceAll(sql, "#DEPARTID#", id);

		return this.getData(sql);
	}
	
	/**
	 * 查询过磅重量
	 * @param outstockDoc
	 * @return
	 */
	public CoreReturnObject doQueryNetWeight(String outstockDoc) {
		//return null;
		return this.getDataBySqlID("JLDATEDao","FrmFilpOutStorage.doQueryNetWeight",
				new Object[] { outstockDoc });
	}
	
	
	
//	//==============eason add 2021-08-20=====================
//	//下面这个方法如果是内倒的业务不要调用，直接按原来的在预报表中插入数据就完事了，如果是采购或者销售的才调用，
//	public CoreReturnObject addPreTrackScale() throws SQLException{
//		ArrayList<String> sqllist = new ArrayList<String>();
//
//
//		Connection connection = this.getDao("McmsDao").getConnection();
//		PreparedStatement ps = null;
//		ResultSet rs = null;
//		//查询需要生成预报的表数据，查mes系统的表
//		ps = connection.prepareStatement("select * from xxx");
//		rs = ps.executeQuery();
//		List<YdmBcOutlistEntity> ydmEntity = EntityTool.getEntitysByRs(rs,YdmBcOutlistEntity.class);
//		rs.close();
//		ps.close();
//
//		//根据实际情况将数据构造预报并执行插入操作
//		for(YdmBcOutlistEntity ydm:ydmEntity){
//			//需要对数据的有效性验证，以及插入的数据比如物料、收发货单位需要转换
//			//创建人填写 mes,生产系统  ，  创建时间为new Date(),若插入计量系统有车号则配车时间也是new Date()，且valid_flag为1，没车号则valid_flag为0
//
//			//插入数据到预报表
//			sqllist.add("insert into pre_track_scale()values()");
//
//			//对环节、流程进行配置
//			{
//				String sql="select t1.process_no,t1.meter_type_no,t1.meter_type_name " +
//						"from METER_WORK_METER_PROCESS t1" +
//						"where t1.meter_type_no = '' and t1.VALUE_FLAG= '0'"; //METER_TYPE_NO的值  001006001对应采购进厂、001006002对应销售出厂、001006003对应中控倒运、001006004销售退货、001006005采购退货
//				//1、构造 METER_WORK_METER_PROCESS对象获取到上面的3个字段的值给对象然后将valid_flag设置位1，写上创建人mes/生产系统、创建时间new Date()，
//				//然后将预报中的预报编号prediction_no,car_no,matter_no,matter_name 赋值给这个对象
//				//将对象插入到表METER_WORK_METER_PROCESS中，主键规则yyyyMMdd+5位流水
//
//
//
//				sql="select  t1.prediction_no,t.process_no,t1.pre_process_no," +
//						"t.link_code,t.link_name,t.link_order_num SEQ_NO,t.LINK_NO " +
//						"from METER_WORK_METER_LINK t,METER_WORK_PRE_PROCESS t1 " +
//						"where t.process_no='pre_track_scale的主键' and t1.pre_process_no='METER_WORK_METER_PROCESS的主键'";
//				//2、查询流程下的所有环节进行循环
//				for(METER_WORK_METER_LINK x: METER_WORK_METER_LINK_Entity){
//					//然后给这个x一个主键  yyyyMMdd+4位流水，创建人，创建时间，如果这个对象的seq_no==1，且link_code等于"001021001" 则对象的value_flag设置为1，否则value_flag设置为0
//					//之后将数据插入表中
//					sqllist.add("insert into METER_WORK_METER_LINK()values()");
//
//				}
//
//			}
//
//
//			{
//
//				//对门岗核查信息及危化品进行处理
//				//1、构造一个对象与表 meter_work_car_check结构保持一致，同时给这个对象的prediction_no设定插入到pre_track_scale表的那个主键值、car_no、mnemonic_code=预报里的挂号、
//				//CUSTOMER_SUPPLIER_NO=预报的供应商编号   customer_supplier_name=预报的供应商名称
//				//2、根据物料编号查询危化品限载表数据，这个物料编号是计量系统的编号
//				String sql="select * from meter_base_limit_chemical where matter_no='xxxx'";
//				//3、若上面查到了数据则将查到的数据取第一条填充到1中构造的对象 给Transport_chemical='0' 给Limit_weight='2中查到的第一条数据的Limit_weight值'
//
//				//4、根据1中的对象在meter_work_car_check表中新增一条数据，其主键规则yyyyMMdd+4位流水
//				sqllist.add("insert into meter_work_car_check()values()");
//			}
//
//		}
//
//
//		sqllist.add("");
//		sqllist.add("");
//
//		return this.getDao("MSSQL1Dao").ExcuteTransction(sqllist);
//	}
	//=======================================================
}
