package com.steering.pss.ydm.pipeleavefactory;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import CoreFS.Util.StringUtils;
import com.ibm.ws.http.HttpConnection;
import core.stlmes.server.sale.util.HttpConnectionLL;
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.google.gson.Gson;
import com.steering.comm.DefaultWebServiceRequest;
import com.steering.comm.ServiceToCx;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.data.ComBaseInfo;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.StringTool;
import com.steering.pss.ydm.base.MeanValueCalculation;
import com.steering.pss.ydm.entity.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;

/**
 * 装车实绩
 * 
 * @author Administrator TJG 2015-03-21
 */
public class FrmPipeLoad extends DBCommon {

	/**
	 * 查询发货实绩表信息
	 * 
	 * @param list
	 *            传递参数
	 * @return obj
	 */
	public CoreReturnObject queryDelivery(ArrayList<String> list,
			String[] storager, String storag, String prdCls) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPipeLoad.queryDelivery");
		if (storag.equals("")) {
			sql += CoreConverter.toSqlConditionString("T.OUT_STOCK_CODE",
					storager);
		} else {
			sql += " AND T.OUT_STOCK_CODE='" + storag + "'";
		}
		// if (prdCls.equals("405005")) {
		// sql+=" AND T.PRD_CLS='405005'";
		// }
		// else {
		// sql+=" AND (T.PRD_CLS!='405005' OR T.PRD_CLS IS NULL)";
		// }
		sql += " ORDER BY T.CREATE_TIME DESC";
		return this.getData(sql, list.toArray());
	}

	/**
	 * 查询发货实绩表理货单号对应的材料信息
	 * 
	 * @param list
	 *            传递参数
	 * @return obj
	 */
	public CoreReturnObject queryMativery(ArrayList<String> list) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPipeLoad.queryMativery");

		sql += "GROUP BY T.JUDGE_STOVE_NO, T.BATCH_NO,T.STD_CODE, T.GROUP_NO, T.ORDER_NO, T.ORDER_SEQ,T.LOCATION_NO, "
				+ "T.ORDER_SEQ_NO, T.LOADVEHICLE_NO, T.BILL_NO, T.TALLYSHEET_NO, T.VEHICLE_NO,T.CREDIT_NO,T.PORT_DESC,"
				+ "T.MATERIAL_NO, T.PRODUCNAME, T.GRADENAME, T.STEELNAME, T.SPEC_NAME, "
				+ "T.MODEL_DESC, T.STORAGE_NO,T.VSTEL_DESC, B.STORAGE_NAME, T.STD_NAME, T.STD_STYLE_DESC, T.CREATE_NAME,"
				+ "T.ORD_PK,T.ORD_LN_PK,T.ORD_LN_DLY_PK,T.ACT_LEN_MIN,T.ACT_LEN_MAX,S.SUPPLY_UNIT,RECORD_DATE2  ORDER BY T.JUDGE_STOVE_NO, T.BATCH_NO ASC";
		return this.getData(sql, list.toArray());
	}
	

	/**
	 * 查询发货实绩表理货单号对应的材料信息
	 *
	 * @param list
	 *            传递参数
	 * @return obj
	 */
	public CoreReturnObject queryMativery_Hw(ArrayList<String> list) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPipeLoad.queryMativery_Hw");

		sql += "  GROUP BY  T.BILL_NO," +
				"    T.TALLYSHEET_NO," +
				"    T.LOADVEHICLE_NO,"+
				"    T.JUDGE_STOVE_NO," +
				"    T.BATCH_NO," +
				"    T.GROUP_NO," +
				" 	  HOOK_WEIGHT";
		return this.getData(sql, list.toArray());
	}

	public CoreReturnObject insertHookWeight (ArrayList<Object> parm) throws SQLException {
		//查询是否存在
		String querySql = CoreXmlSqlParsersFactory
				.getSql("FrmPipeLoad.selCountHookWeight");
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = connection.prepareStatement(querySql);
		psta.setObject(1,parm.get(0));
		psta.setObject(2,parm.get(1));
		psta.setObject(3,parm.get(2));
		psta.setObject(4,parm.get(3));
		psta.setObject(5,parm.get(4));
		psta.setObject(6,parm.get(5));
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
				//存在则删除
				if(rs.getInt("COUNT(*)") > 0){
					CoreReturnObject cro = new CoreReturnObject();
					String strSql = CoreXmlSqlParsersFactory
							.getSql("FrmPipeLoad.deleteHookWeight");
					Object[] args  = new Object[]{parm.get(0),parm.get(1),parm.get(2)
							,parm.get(3),parm.get(4),parm.get(5)};
				 this.getDao("TgDao").ExcuteNonQuery(strSql,args );
				}
		}
		//新增
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory
				.getSql("FrmPipeLoad.insertHookWeight");
		try {
			cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
		}
		catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}

	public CoreReturnObject selCountHookWeight(ArrayList<Object> parm) {
		return this.getDataBySqlID("FrmPipeLoad.selCountHookWeight", parm.toArray());
	}

	/***
	 * 查询提单是否过磅
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject queryBillCFlag(String billNo) {
		return this.getDataBySqlID("FrmPipeLoad.queryBillCFlag",
				new Object[] { billNo });
	}

	/**
	 * 结转控制
	 * 
	 * @param
	 *
	 * @return obj
	 */
	public CoreReturnObject queryBaseInfo(String baseCode) {
		return this.getDataBySqlID("FrmPipeLoad.queryBaseInfo",
				new Object[] { baseCode });
	}

	/***
	 * 回写打印次数，打印时间
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject updatePintFlag(String time, String loadNo) {
		return this.setDataBySqlID("FrmPipeLoad.updatePintFlag", new Object[] {
				time, loadNo });
	}

	public static String format(double value) {
		BigDecimal bd = new BigDecimal(value);
		bd = bd.setScale(3, RoundingMode.HALF_UP);
		return bd.toString();
	}


	/**
	 * 获取过磅重量
	 * @param billNo
	 * @param tallysheetNo
	 * @param vehicleNo
	 * @param userName
	 * @return
	 */
	public CoreReturnObject GetUpdateNetWeight(String billNo, String tallysheetNo,String vehicleNo,String userName) {
		CoreReturnObject cro = new CoreReturnObject();

		Connection connection = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		//Connection limsCon = this.getDao("LimsDao").getConnection();注释天管计量 2024/4/24

		PreparedStatement psta = null;
		PreparedStatement ps = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			//limsCon.setAutoCommit(false); // 取消自动提交事务
			List<YdmZcLoadvehicleMatEntity> matEntities = new ArrayList<YdmZcLoadvehicleMatEntity>();
			Double netWeight = 0.0;
			String actualNo = "";
			// 获取装车材料信息
			String getMatInfoSql = CoreXmlSqlParsersFactory.getSql("FrmPipeLoad.getMatInfoSql");
			psta = connection.prepareStatement(getMatInfoSql);
			psta.setString(1, billNo);
			psta.setString(2, tallysheetNo);
			psta.setString(3, vehicleNo);
			ResultSet rs = psta.executeQuery();
			matEntities = EntityTool.getEntitysByRs(rs, YdmZcLoadvehicleMatEntity.class);
			rs.close();
			psta.close();

			// 获取计量过磅重量
			/*String getNetWeightSql = CoreXmlSqlParsersFactory.getSql("PreTrackNotice.getNetWeightSql");
			ps = limsCon.prepareStatement(getNetWeightSql);
			ps.setString(1, tallysheetNo);
			ps.setString(2, vehicleNo);
			ResultSet rs1 = ps.executeQuery();
			while (rs1.next()) {
				netWeight = rs1.getDouble(1);// 过磅重量
				actualNo = rs1.getString(2);// 过磅流水号
			}
			rs1.close();
			ps.close();*/

			if(netWeight <= 0.0 || StringUtils.isEmpty(actualNo)){
				cro.setV_errMsg("未获取到计量过磅重量！");
				return cro;
			}
			if (matEntities== null || matEntities.size()<=0) {
				cro.setV_errMsg("未获取到理货装车信息！");
				return cro;
			}
			Double netWeightResidue = netWeight;
			Double ratioTotal = 1.0;

			Date nowTime = new Date();
			SimpleDateFormat dfT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String strNowTime = dfT.format(nowTime);

			for (int i = 0; i < matEntities.size(); i++) {
				Double ratio = Double.parseDouble(matEntities.get(i).getActWeight()) / Double.parseDouble(matEntities.get(i).getActWeightSum());
				String ponderGrossWt = format(netWeight * ratio);
				if(i == matEntities.size() - 1){// 最后一条数据
					ponderGrossWt = netWeightResidue.toString();
				}

				String sqlupdate = "UPDATE YDM_ZC_LOADVEHICLE_MAT SET  UPDATE_NAME = '"
						+ userName
						+ "', UPDATE_TIME = TO_DATE('"
						+ strNowTime
						+ "','YYYY-MM-DD HH24:MI:SS'),PONDER_NO='"
						+ actualNo
						+ "',PONDER_GROSS_WT='"
						+ ponderGrossWt
						+ "'  WHERE LOADVEHICLE_SQE='"
						+ matEntities.get(i).getLoadvehicleSqe() + "'";
				Statement sta = connection.createStatement();
				sta.executeUpdate(sqlupdate);
				sta.close();

				netWeightResidue = netWeightResidue - Double.parseDouble(ponderGrossWt);
				ratioTotal = ratioTotal - ratio;
			}

			connection.commit();
			//limsCon.commit();
			cro.setV_errMsg("获取成功！");
			cro.setResult(1);
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
			/*if (limsCon != null) {
				try {
					limsCon.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}*/
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
				/*if (limsCon != null && !limsCon.isClosed()) {
					limsCon.close();
				}*/
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/**
	 * 修改发货实绩表信息
	 * 
	 * @param list
	 *            传递参数
	 * @return obj
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject updateDelivery(ArrayList<String> list,
			ArrayList<Object> pram) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlquery = "";
			String sqlupdate = "";
			ArrayList<String> billMats = new ArrayList<String>(); // 装车材料表主键
			// 数组长度等于装车支数和
			// String strSend = querySendTally(connection, sendList);
			for (int i = 0; i < pram.size(); i++) {
				billMats = new ArrayList<String>();
				ArrayList<String> list1 = (ArrayList<String>) pram.get(i);

				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.queryLodSqeNew");
				psta = connection.prepareStatement(sqlquery);
				psta.setString(1, list1.get(3));
				psta.setString(2, list1.get(4));
				psta.setString(3, list1.get(5));
				psta.setString(4, list1.get(6));
				psta.setString(5, list1.get(7));
				psta.setString(6, list1.get(8));
				psta.setString(7, list1.get(9));
				psta.setString(8, list1.get(11));
				psta.setString(9, list1.get(16));
				psta.setString(10, list1.get(17));
				psta.setString(11, list1.get(18));
				psta.setString(12, list1.get(19));
				psta.setString(13, list1.get(20));
				ResultSet rs = psta.executeQuery();
				while (rs.next()) {
					billMats.add(rs.getString(1));// 装车材料表主键
				}
				rs.close();
				psta.close();
				if (list1.get(15).equals("")) {
					sqlupdate = "UPDATE YDM_ZC_LOADVEHICLE_MAT SET VEHICLE_NO = '"
							+ list1.get(0)
							+ "', UPDATE_NAME = '"
							+ list1.get(1)
							+ "', UPDATE_TIME = TO_DATE('"
							+ list1.get(2)
							+ "','YYYY-MM-DD HH24:MI:SS')  WHERE BILL_NO='"
							+ list1.get(4)
							+ "' AND TALLYSHEET_NO='"
							+ list1.get(5)
							+ "' AND LOADVEHICLE_NO='"
							+ list1.get(3) + "'";
					Statement sta = connection.createStatement();
					sta.executeUpdate(sqlupdate);
					sta.close();
				} else {
					int k = 0;
					List<double[]> listWegiht = MeanValueCalculation
							.MeanCalculation(Double.parseDouble(list1.get(13)),
									Integer.parseInt(list1.get(14)));
					for (int j = 0; j < listWegiht.size(); j++) {
						double[] conW = listWegiht.get(j);
						if ((int) conW[0] >= 0) {
							for (int z = 0; z < (int) conW[0]; z++) {
								// for (int k = 0; k < billMats.size(); k++) {
								sqlupdate = "UPDATE YDM_ZC_LOADVEHICLE_MAT SET VEHICLE_NO = '"
										+ list1.get(0)
										+ "', UPDATE_NAME = '"
										+ list1.get(1)
										+ "', UPDATE_TIME = TO_DATE('"
										+ list1.get(2)
										+ "','YYYY-MM-DD HH24:MI:SS'),PONDER_NO='"
										+ list1.get(15)
										+ "',PONDER_GROSS_WT='"
										+ String.valueOf(conW[1])
										+ "'  WHERE LOADVEHICLE_SQE='"
										+ billMats.get(k) + "'";
								Statement sta = connection.createStatement();
								sta.executeUpdate(sqlupdate);
								sta.close();
								// }
								k++;
							}
						}
					}
				}
			}
			// String sqlupdate1 = CoreXmlSqlParsersFactory
			// .getSql("FrmPipeLoad.updateDelivery");
			// // Statement sta = connection.createStatement();
			// // sta.executeUpdate(sqlupdate, (String[]) list.toArray());
			// // sta.close();
			// this.setData(sqlupdate1, list.toArray());
			sqlupdate = "UPDATE YDM_ZC_LOADVEHICLE SET VEHICLE_NO='"
					+ list.get(0) + "',INFACTORY_TIME=TO_DATE('" + list.get(1)
					+ "','YYYY-MM-DD HH24:MI:SS')," + "DELIVY_TIME=TO_DATE('"
					+ list.get(2) + "','YYYY-MM-DD HH24:MI:SS'), MEMO='"
					+ list.get(3) + "' WHERE LOADVEHICLE_NO='" + list.get(4)
					+ "'  AND VALIDFLAG='1'";
			Statement sta = connection.createStatement();
			sta.executeUpdate(sqlupdate);
			sta.close();

			cro.setResult(billMats.size());
			connection.commit();

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
		// return this
		// .setDataBySqlID("FrmPipeLoad.updateDelivery", list.toArray());
	}

	/**
	 * 修改发货实绩表信息确认
	 * 
	 * @param list
	 *            传递参数
	 * @return obj
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject updateDelConfirm(ArrayList<Object> list,String[] arr ) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		//Connection wlCon = new DBCommon().getDao("TmsDao").getConnection();
		PreparedStatement psta = null;
		Date nowTime = new Date();
		SimpleDateFormat dfT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strNowTime = dfT.format(nowTime);
		/*SimpleDateFormat dfT = new SimpleDateFormat("yyyyMM");
		String strNowTime = dfT.format(nowTime);*/

		HashSet<String> stoves = new HashSet<>();
		HashSet<String> stovesrl = new HashSet<>();
		HashSet<String> lines = new HashSet<>();// 用于成分理化的检验结果发送
//		HashSet<String> others = new HashSet<>();// 用于探伤水压通径的检验结果发送

		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			//wlCon.setAutoCommit(false);
			//Statement wlStmt = wlCon.createStatement();
			String sqlquery = "";
			// String sqlupdate = CoreXmlSqlParsersFactory
			// .getSql("FrmPipeLoad.updateMatZcNo");// 修改材料表过磅重量
			// PreparedStatement psupdate =
			// connection.prepareStatement(sqlupdate);
			Gson gson = new Gson();
			Boolean interfaceState = false;
			String addMat = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.AddMatZcBackup");// 新增材料表MAT_ZC_BACKUP（删除位置表，材料表）
			PreparedStatement psAddMat = connection.prepareStatement(addMat);
			String sqlupdateload = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.updateDelConfirm");// 修改装车主表确认状态
			PreparedStatement psLoad = connection
					.prepareStatement(sqlupdateload);
			String sqlupdateloadMAT = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.updateMatConfirm");// 修改装车材料表状态
			PreparedStatement psLoadMat = connection
					.prepareStatement(sqlupdateloadMAT);
			String insertOut = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.insertOutList"); // 新增到出库表
			PreparedStatement pstaOut = connection.prepareStatement(insertOut);
			String insertOutXs = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoadXs.insertOutList"); // 新增到销售出库表
			PreparedStatement pstaOutXs = connection.prepareStatement(insertOutXs);
			// String deleteButtress = CoreXmlSqlParsersFactory
			// .getSql("FrmPipeEntruck.deleteButtress"); // 删除位置表
			// PreparedStatement pstaButtress = connection
			// .prepareStatement(deleteButtress);
			// String updatOut = CoreXmlSqlParsersFactory
			// .getSql("FrmPipeEntruck.updateOut"); // 修改出库表过磅重量
			// PreparedStatement updaout =
			// connection.prepareStatement(updatOut);
			/*String insertWlDelisery = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.insertWlDelivery"); // 新增到物流主表
			PreparedStatement pstaWlDelisery = wlCon.prepareStatement(insertWlDelisery);
			
			String insertWlMat = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.insertWlMat"); // 新增到物流从表
			PreparedStatement pstaWlMat = wlCon.prepareStatement(insertWlMat);
			
			String insertWlBill = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.insertWlBill"); // 新增到物流费用表
			PreparedStatement pstaWlBill = wlCon.prepareStatement(insertWlBill);*/
			
			String updatProOrd = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.updatProOrd"); // 回写进程表
			PreparedStatement pstaPro = connection
					.prepareStatement(updatProOrd);

			String insertCrmOut = CoreXmlSqlParsersFactory
					.getSql("CrmOutList.insertCrmOutList"); // 新增到crm出库表
			PreparedStatement pstaCrmOut = connection.prepareStatement(insertCrmOut);
			String addCrmMat = CoreXmlSqlParsersFactory
					.getSql("CrmMatZc.insertCrmMatZc_Back");//新增crm材料表，取MAT_ZC_BACKUP
			PreparedStatement psAddCrmMat = connection.prepareStatement(addCrmMat);

			List<YdmZcOutlistEntity1> ydmOut = new ArrayList<YdmZcOutlistEntity1>();

			JSONObject sendParams = new JSONObject(); // 所有的装车主从表一次行全部发过去
			JSONArray sendArr = new JSONArray();
			sendParams.put("params", sendArr);

			for (int i = 0; i < list.size(); i++) {
				ydmOut.clear();				
				ArrayList<String> list1 = (ArrayList<String>) list.get(i);
				String loadNo = list1.get(0);//装车单号
				String billNo = list1.get(1);
				String tallNo = list1.get(2);
				String velNo = list1.get(3);
				String name = list1.get(4);
				String strtime = list1.get(5);
				String bc = list1.get(6);
				String bz = list1.get(7);
				String userId=list1.get(8);

				//获取装车主表数据
				List<YdmZcLoadvehicleEntity> zcLoad = new ArrayList<YdmZcLoadvehicleEntity>();
				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.queryDeliveryByWl");
				psta = connection.prepareStatement(sqlquery);
				psta.setObject(1, loadNo);
				ResultSet rs4 = psta.executeQuery();
				zcLoad = EntityTool.getEntitysByRs(rs4,
						YdmZcLoadvehicleEntity.class);
				rs4.close();
				psta.close();

				// 第一个装车主从表信息：
				JSONObject main = new JSONObject();
				main.put("loadvehicleNo", zcLoad.get(0).getLoadvehicleNo());
				main.put("billNo", zcLoad.get(0).getBillNo());
				main.put("tallysheetNo", zcLoad.get(0).getTallysheetNo());
				main.put("loadvehicleType", "实际".equals(zcLoad.get(0).getLoadvehicleType()) ? "1" : "虚拟".equals(zcLoad.get(0).getLoadvehicleType()) ? "2" : "");
				main.put("affirmFlag", "1");
				main.put("vehicleNo", zcLoad.get(0).getVehicleNo());
				main.put("transType", "汽运".equals(zcLoad.get(0).getTransType()) ? "110501" : "火运".equals(zcLoad.get(0).getTransType()) ? "110502" : "");
				main.put("receivNo", zcLoad.get(0).getReceivNo());
				main.put("receivNm", zcLoad.get(0).getReceivNm());
				main.put("stationNo", zcLoad.get(0).getStationNo());
				main.put("stationNm", zcLoad.get(0).getStationNm());
				main.put("spclLnNo", zcLoad.get(0).getSpclLnNo());
				main.put("spclLnNm", zcLoad.get(0).getSpclLnNm());
				main.put("shipLotNo", zcLoad.get(0).getShipLotNo());
				main.put("plant", zcLoad.get(0).getPlant());
				main.put("plantDesc", zcLoad.get(0).getPlantDesc());
				main.put("vstelCode", zcLoad.get(0).getVstelCode());
				main.put("vstelDesc", zcLoad.get(0).getVstelDesc());
				main.put("carrierNo", zcLoad.get(0).getCarrierNo());
				main.put("carryCompanyCode", zcLoad.get(0).getCarryCompanyCode());
				main.put("carryCompanyName", zcLoad.get(0).getCarryCompanyName());
				main.put("stackingWt", zcLoad.get(0).getStackingWt());
				main.put("stackingPiece", zcLoad.get(0).getStackingPiece());
				main.put("stackingTotlLenTemp", zcLoad.get(0).getStackingTotlLen());
				main.put("weighFlag", zcLoad.get(0).getWeighFlag());
				main.put("ponderNo", zcLoad.get(0).getPonderNo());
				main.put("ponderGrossWt", zcLoad.get(0).getPonderGrossWt());
				main.put("outStockCode", zcLoad.get(0).getOutStockCode());
				main.put("delivyPlaceCode", zcLoad.get(0).getDelivyPlaceCode());
				main.put("delivyPlaceName", zcLoad.get(0).getDelivyPlaceName());
				main.put("stlmtUnitNo", zcLoad.get(0).getStlmtUnitNo());
				main.put("stlmtUnitNm", zcLoad.get(0).getStlmtUnitNm());
				main.put("infactoryTime", zcLoad.get(0).getInfactoryTime());
				main.put("loadTime", zcLoad.get(0).getLoadTime());
				main.put("delivyTime", zcLoad.get(0).getDelivyTime());
				main.put("stackingPrints", zcLoad.get(0).getStackingPrints());
				main.put("threeReadyNo", zcLoad.get(0).getThreeReadyNo());
				main.put("handheldNo", zcLoad.get(0).getHandheldNo());
				main.put("handheldFlag", zcLoad.get(0).getHandheldFlag());
				main.put("managementNo", zcLoad.get(0).getManagementNo());
				main.put("managementName", zcLoad.get(0).getManagementName());
				main.put("memo", zcLoad.get(0).getMemo());
				main.put("validflag", "无效".equals(zcLoad.get(0).getValidflag()) ? "0" : "有效".equals(zcLoad.get(0).getValidflag()) ? "1" : "");
				main.put("createName", zcLoad.get(0).getCreateName());
				main.put("createTime", zcLoad.get(0).getCreateTime());
				main.put("updateName", zcLoad.get(0).getUpdateName());
				main.put("updateTime", zcLoad.get(0).getUpdateTime());
				main.put("deleteName", zcLoad.get(0).getDeleteName());
				main.put("deleteTime", zcLoad.get(0).getDeleteTime());
				main.put("departmentCode", zcLoad.get(0).getDepartmentCode());
				main.put("departmentDesc", zcLoad.get(0).getDepartmentDesc());
				main.put("printFlag", ""); // 出库单打印时间 没有
				main.put("printNum", ""); // 打印次数 没有
				main.put("billNoSqe", "");
				main.put("zoutFlag", "0");
				main.put("port", zcLoad.get(0).getPort());
				main.put("prdCls", "");
				main.put("returnFlag", "0");
				main.put("stackingTotlLen", zcLoad.get(0).getStackingTotlLen());
				main.put("carrierCode", zcLoad.get(0).getCarrierCode());
				main.put("carrierName", zcLoad.get(0).getCarrierName());
				main.put("carLicense", zcLoad.get(0).getCarLicense());
				main.put("driverCode", zcLoad.get(0).getDriverCode());
				main.put("driverName", zcLoad.get(0).getDriverName());
				main.put("confirmName", "");
				main.put("confirmTime", "");



				//获取装车从表数据
				List<YdmZcMatEntityForWl> zcMatLoad = new ArrayList<YdmZcMatEntityForWl>();
				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.queryMativeryByWl1");
				psta = connection.prepareStatement(sqlquery);
				psta.setObject(1, loadNo);
				psta.setObject(2, billNo);
				psta.setObject(3, velNo);
				psta.setObject(4, tallNo);
				ResultSet rs3 = psta.executeQuery();
				zcMatLoad = EntityTool.getEntitysByRs(rs3,
						YdmZcMatEntityForWl.class);
				rs3.close();
				psta.close();

				// 拼接装车从表：
				JSONArray matarr = new JSONArray();
				for (YdmZcMatEntityForWl mat : zcMatLoad) {
					JSONObject matObj = new JSONObject();
					matObj.put("loadvehicleSqe", mat.getLoadvehicleSqe());
					matObj.put("id", mat.getLoadvehicleSqe());
					matObj.put("loadvehicleNo", mat.getLoadvehicleNo());
					matObj.put("billNo", mat.getBillNo());
					matObj.put("tallysheetNo", mat.getTallysheetNo());
					matObj.put("vehicleNo", mat.getVehicleNo());
					matObj.put("orderNo", mat.getOrderNo());
					matObj.put("orderSeq", mat.getOrderSeq());
					matObj.put("orderSeqNo", mat.getOrderSeqNo());
					matObj.put("proOrderNo", mat.getProOrderNo());
					matObj.put("matNo", mat.getMatNo());
					matObj.put("lotNo", mat.getLotNo());
					matObj.put("judgeStoveNo", mat.getJudgeStoveNo());
					matObj.put("batchNo", mat.getBatchNo());
					matObj.put("groupNo", mat.getGroupNo());
					matObj.put("stoveNo", mat.getStoveNo());
					matObj.put("materialNo", mat.getMaterialNo());
					matObj.put("materialName", mat.getMaterialName());
					matObj.put("produccode", mat.getProduccode());
					matObj.put("producname", mat.getProducname());
					matObj.put("stdCode", mat.getStdCode());
					matObj.put("stdName", mat.getStdName());
					matObj.put("gradecode", mat.getGradecode());
					matObj.put("gradename", mat.getGradename());
					matObj.put("steelcode", mat.getSteelcode());
					matObj.put("steelname", mat.getSteelname());
					matObj.put("stdStyle", mat.getStdStyle());
					matObj.put("stdStyleDesc", mat.getStdStyleDesc());
					matObj.put("specCode", mat.getSpecCode());
					matObj.put("specName", mat.getSpecName());
					matObj.put("modelCode", mat.getModelCode());
					matObj.put("modelDesc", mat.getModelDesc());
					matObj.put("processCdoe", mat.getProcessCdoe());
					matObj.put("processDesc", mat.getProcessDesc());
					matObj.put("plineCode", mat.getPlineCode());
					matObj.put("plineName", mat.getPlineName());
					matObj.put("actDimater", mat.getActDimater());
					matObj.put("actHeight", mat.getActHeight());
					matObj.put("actLenTemp", mat.getActLen());
					matObj.put("actLenMin", mat.getActLenMin());
					matObj.put("actLenMax", mat.getActLenMax());
					matObj.put("actCount", mat.getActCount());
					matObj.put("actWeight", mat.getActWeight());
					matObj.put("actTheoryWeight", mat.getActTheoryWeight());
					matObj.put("judgeResultCode", mat.getJudgeResultCode());
					matObj.put("proBc", mat.getProBc());
					matObj.put("proBz", mat.getProBz());
					matObj.put("rpoTime", mat.getRpoTime());
					matObj.put("senBc", mat.getSenBc());
					matObj.put("senBz", mat.getSenBz());
					matObj.put("senTime", mat.getSenTime());
					matObj.put("zbsBh", mat.getZbsBh());
					matObj.put("saleOrg", mat.getSaleOrg());
					matObj.put("saleOrgDesc", mat.getSaleOrgDesc());
					matObj.put("saleArea", mat.getSaleArea());
					matObj.put("storageTypeNo", mat.getStorageTypeNo());
					matObj.put("storageTypeName", mat.getStorageTypeName());
					matObj.put("managementNo", mat.getManagementNo());
					matObj.put("managementName", mat.getManagementName());
					matObj.put("uploadWebFlag", mat.getUploadWebFlag());
					matObj.put("storageNo", mat.getStorageNo());
					matObj.put("locationNo", mat.getLocationNo());
					matObj.put("laryNo", mat.getLaryNo());
					matObj.put("locNo", mat.getLocNo());
					matObj.put("transTpe", mat.getTransType());
					matObj.put("receivNo", mat.getReceivNo());
					matObj.put("receivNm", mat.getReceivNm());
					matObj.put("stationNo", mat.getStationNo());
					matObj.put("stationNm", mat.getStationNm());
					matObj.put("spclLnNo", mat.getSpclLnNo());
					matObj.put("spclLnNm", mat.getSpclLnNm());
					matObj.put("port_no", mat.getPortNo());
					matObj.put("plant", mat.getPlant());
					matObj.put("plantDesc", mat.getPlantDesc());
					matObj.put("vstel", mat.getVstel());
					matObj.put("vstelDesc", mat.getVstelDesc());
					matObj.put("carryCompanyCode", mat.getCarryCompanyCode());
					matObj.put("carryCompanyName", mat.getCarryCompanyName());
					matObj.put("outStockCode", mat.getOutStockCode());
					matObj.put("delivyPlaceCode", mat.getDelivyPlaceCode());
					matObj.put("delivyPlaceName", mat.getDelivyPlaceName());
					matObj.put("stlmtUnitNo", mat.getStlmtUnitNo());
					matObj.put("stlmtUnitNm", mat.getStlmtUnitNm());
					matObj.put("delivyTime", mat.getDelivyTime());
					matObj.put("memo", mat.getMemo());
					matObj.put("validflag", mat.getValidflag());
					matObj.put("createName", mat.getCreateName());
					matObj.put("createTime", mat.getCreateTime());
					matObj.put("updateName", mat.getUpdateName());
					matObj.put("updateTime", mat.getUpdateTime());
					matObj.put("deleteName", mat.getDeleteName());
					matObj.put("deleteTime", mat.getDeleteTime());
					matObj.put("ordPk", mat.getOrdPk());
					matObj.put("ordLnPk", mat.getOrdLnPk());
					matObj.put("ordLnDlyPk", mat.getOrdLnDlyPk());
					matObj.put("departmentCode", mat.getDepartmentCode());
					matObj.put("departmentDesc", mat.getDepartmentDesc());
					matObj.put("ponderNo", mat.getPonderNo());
					matObj.put("ponderGrossWt", mat.getPonderGrossWt());
					matObj.put("judgeStdName", mat.getJudgeStdName());
					matObj.put("judgeStdCode", mat.getJudgeStdCode());
					matObj.put("billNoSeq", "");
					matObj.put("sendNum", mat.getSendNum());
					matObj.put("zoutFlag", "");
					matObj.put("balYearMonth", "");
					matObj.put("creditNo", mat.getCreditNo());
					matObj.put("portDesc", mat.getPortDesc());
					matObj.put("actFixNum", mat.getActFixNum());
					matObj.put("actFixLen", mat.getActFixLen());
					matObj.put("returnFlag", mat.getReturnFlag());
					matObj.put("finishproMold", mat.getFinishproMold());
					matObj.put("inMold", mat.getInMold());
					matObj.put("orgBillNo", "");
					matObj.put("actLen", mat.getActLen());
					matObj.put("measuringSeq", mat.getMeasuringSeq());
					matObj.put("inType", "");
					matarr.add(matObj);

					lines.add(mat.getOrderNo() + mat.getOrderSeq() + "," + mat.getJudgeStoveNo() + "," + mat.getStoveNo());
//					others.add(mat.getOrderNo() + mat.getOrderSeq() + "," + mat.getMatNo());
				}
				main.put("ydmZcLoadvehicleMats", matarr);


				//获取提单主表数据
				List<YdmZcBillMEntity> billMEntity = new ArrayList<YdmZcBillMEntity>();
				sqlquery = CoreXmlSqlParsersFactory
						.getSql("CorePipeCarBill.getBillInfoByBillNoSeq");
				psta = connection.prepareStatement(sqlquery);
				psta.setObject(1, billNo);
				ResultSet rs5 = psta.executeQuery();
				billMEntity = EntityTool.getEntitysByRs(rs5,
						YdmZcBillMEntity.class);
				rs5.close();
				psta.close();
				
				
				// 判断是否确认
				String affigeFlag = "";
				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.queryaffigeFlag");
				psta = connection.prepareStatement(sqlquery);
				psta.setObject(1, billNo);
				psta.setObject(2, tallNo);
				psta.setObject(3, loadNo);
				ResultSet rs1 = psta.executeQuery();
				if (rs1.next()) {
					affigeFlag = rs1.getString("AFFIRM_FLAG");
				}
				rs1.close();
				psta.close();
				if (affigeFlag.equals("1")) {
					cro.setV_errMsg("您选择的记录已确认，不能进行此操作！");
					return cro;
				}

				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.queryLoadMatNo");
				psta = connection.prepareStatement(sqlquery);
				psta.setObject(1, loadNo);
				psta.setObject(2, billNo);
				psta.setObject(3, tallNo);
				psta.setObject(4, velNo);
				ResultSet rs = psta.executeQuery();
				ydmOut = EntityTool.getEntitysByRs(rs,
						YdmZcOutlistEntity1.class);
				rs.close();
				psta.close();
				if (ydmOut == null || ydmOut.size() == 0) {
					cro.setV_errMsg("装车数据发生改变，请刷新！");
					return cro;
				}
				String sendOut = FrmPipeEntruck.querySendOut(connection,
						"800805");
				// 获取出库流水号
				String butessMatNo = FrmPipeEntruck.querySendOutList(
						connection, sendOut, "800805");
				int outNo = Integer.parseInt(butessMatNo.substring(
						butessMatNo.length() - 4, butessMatNo.length()));
				
				String sendOutXs = FrmPipeEntruck.querySendOutXs(connection,
						"800805");
				// 获取出库流水号
				String butessMatNoXs = FrmPipeEntruck.querySendOutListXs(
						connection, sendOut, "800805");
				int outNoXs = Integer.parseInt(butessMatNoXs.substring(
						butessMatNoXs.length() - 4, butessMatNoXs.length()));
				String profalg = "";
				// 判断是否过磅
				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.queryBillCFlag");
				psta = connection.prepareStatement(sqlquery);
				psta.setObject(1, billNo);
				rs = psta.executeQuery();
				if (rs.next()) {
					profalg = rs.getString("PRT_FLAG");
				}
				rs.close();
				psta.close();
				
				// 获取制造商
				String supplyUnitCode="";
				String supplyUnit="";
				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.querySuppUnit");
				psta = connection.prepareStatement(sqlquery);
				psta.setObject(1, billNo);
				rs = psta.executeQuery();
				if (rs.next()) {
					supplyUnit = rs.getString("SUPPLY_UNIT");
					supplyUnitCode = rs.getString("SUPPLY_UNIT_CODE");
				}
				rs.close();
				psta.close();
				for (YdmZcOutlistEntity1 lvMat : ydmOut) {
					double count = Double.parseDouble(lvMat.getActCount());
					double wt = 0;
					if (profalg.equals("1")) {
						if (lvMat.getPonderNo().equals("")) {
							cro.setV_errMsg("请输入过磅单号！");
							return cro;
						}
						if (lvMat.getPonderGrossWt().equals("")) {
							cro.setV_errMsg("请输入过磅重量！");
							return cro;
						}
						wt = Double.parseDouble(lvMat.getPonderGrossWt());
					} else {
						wt = Double.parseDouble(lvMat.getActWeight());
					}

					// 新增出库表
					pstaOut.setString(1,
							sendOut + StringTool.formatDecimal(outNo, "0000"));
					pstaOut.setString(2, sendOut);
					pstaOut.setString(3, "800805");
					pstaOut.setString(4, "销售出库");
					pstaOut.setString(5, lvMat.getVehicleNo());
					pstaOut.setString(6, lvMat.getMatNo());
					pstaOut.setString(7, lvMat.getLotNo());
					pstaOut.setString(8, lvMat.getStoveNo());
					pstaOut.setString(9, lvMat.getJudgeStoveNo());
					pstaOut.setString(10, lvMat.getBatchNo());
					pstaOut.setString(11, lvMat.getBatchGroudNo());
					pstaOut.setString(12, lvMat.getMaterialNo());
					pstaOut.setString(13, lvMat.getMaterialName());
					pstaOut.setString(14, lvMat.getProduccode());
					pstaOut.setString(15, lvMat.getProducname());
					pstaOut.setString(16, lvMat.getStdCode());
					pstaOut.setString(17, lvMat.getStdName());
					pstaOut.setString(18, lvMat.getGradecode());
					pstaOut.setString(19, lvMat.getGradename());
					pstaOut.setString(20, lvMat.getSteelcode());
					pstaOut.setString(21, lvMat.getSteelname());
					pstaOut.setString(22, lvMat.getStdStyle());
					pstaOut.setString(23, lvMat.getStdStyleDesc());
					pstaOut.setString(24, lvMat.getSpecCode());
					pstaOut.setString(25, lvMat.getSpecName());
					pstaOut.setString(26, lvMat.getModelCode());
					pstaOut.setString(27, lvMat.getModelDesc());
					pstaOut.setString(28, lvMat.getPlineCode());
					pstaOut.setString(29, lvMat.getPlineName());
					pstaOut.setString(30, lvMat.getActDimater());
					pstaOut.setString(31, lvMat.getActHeight());
					pstaOut.setString(32, String.valueOf(lvMat.getActLen()));
					pstaOut.setString(33, lvMat.getActLenMin());
					pstaOut.setString(34, lvMat.getActLenMax());
					pstaOut.setString(35, lvMat.getActCount());
					pstaOut.setString(36, String.valueOf(lvMat.getActWeight()));
					pstaOut.setString(37,
							String.valueOf(lvMat.getActTheoryWeight()));
					pstaOut.setString(38, lvMat.getStorageNo());
					pstaOut.setString(39, lvMat.getLocationNo());
					pstaOut.setString(40, lvMat.getLaryNo());
					pstaOut.setString(41, lvMat.getLocNo());
					pstaOut.setString(42, lvMat.getStorageAttr());
					pstaOut.setString(43, lvMat.getStorageAttrName());
					pstaOut.setString(44, lvMat.getStorageTypeNo());
					pstaOut.setString(45, lvMat.getStorageTypeName());
					pstaOut.setString(46, lvMat.getManagementNo());
					pstaOut.setString(47, lvMat.getManagementName());
					
					//判定是否已开虚单 根据管号查 多查就多查吧 保险
					String loadvehicle_type = "1";
					sqlquery = "select m.loadvehicle_type from YDM_ZC_BILL_C c  JOIN YDM_ZC_BILL_m m  ON c.bill_no = m.bill_no where c.mat_no = '"+lvMat.getMatNo()+"' and m.loadvehicle_type = '2'";
					psta = connection.prepareStatement(sqlquery);
					rs1 = psta.executeQuery();
					if (rs1.next()) {
						loadvehicle_type = rs1.getString("loadvehicle_type");
					}
					rs1.close();
					psta.close();
					pstaOutXs.setString(1,sendOutXs + StringTool.formatDecimal(outNoXs, "0000"));
					pstaOutXs.setString(2, sendOutXs);
					pstaOutXs.setString(3, "800805");
					pstaOutXs.setString(4, "销售出库");
					pstaOutXs.setString(5, lvMat.getVehicleNo());
					pstaOutXs.setString(6, lvMat.getMatNo());
					pstaOutXs.setString(7, lvMat.getLotNo());
					pstaOutXs.setString(8, lvMat.getStoveNo());
					pstaOutXs.setString(9, lvMat.getJudgeStoveNo());
					pstaOutXs.setString(10, lvMat.getBatchNo());
					pstaOutXs.setString(11, lvMat.getBatchGroudNo());
					pstaOutXs.setString(12, lvMat.getMaterialNo());
					pstaOutXs.setString(13, lvMat.getMaterialName());
					pstaOutXs.setString(14, lvMat.getProduccode());
					pstaOutXs.setString(15, lvMat.getProducname());
					pstaOutXs.setString(16, lvMat.getStdCode());
					pstaOutXs.setString(17, lvMat.getStdName());
					pstaOutXs.setString(18, lvMat.getGradecode());
					pstaOutXs.setString(19, lvMat.getGradename());
					pstaOutXs.setString(20, lvMat.getSteelcode());
					pstaOutXs.setString(21, lvMat.getSteelname());
					pstaOutXs.setString(22, lvMat.getStdStyle());
					pstaOutXs.setString(23, lvMat.getStdStyleDesc());
					pstaOutXs.setString(24, lvMat.getSpecCode());
					pstaOutXs.setString(25, lvMat.getSpecName());
					pstaOutXs.setString(26, lvMat.getModelCode());
					pstaOutXs.setString(27, lvMat.getModelDesc());
					pstaOutXs.setString(28, lvMat.getPlineCode());
					pstaOutXs.setString(29, lvMat.getPlineName());
					pstaOutXs.setString(30, lvMat.getActDimater());
					pstaOutXs.setString(31, lvMat.getActHeight());
					pstaOutXs.setString(32, String.valueOf(lvMat.getActLen()));
					pstaOutXs.setString(33, lvMat.getActLenMin());
					pstaOutXs.setString(34, lvMat.getActLenMax());
					pstaOutXs.setString(35, lvMat.getActCount());
					pstaOutXs.setString(36, String.valueOf(lvMat.getActWeight()));
					pstaOutXs.setString(37,String.valueOf(lvMat.getActTheoryWeight()));
					pstaOutXs.setString(38, lvMat.getStorageNo());
					pstaOutXs.setString(39, lvMat.getLocationNo());
					pstaOutXs.setString(40, lvMat.getLaryNo());
					pstaOutXs.setString(41, lvMat.getLocNo());
					pstaOutXs.setString(42, lvMat.getStorageAttr());
					pstaOutXs.setString(43, lvMat.getStorageAttrName());
					pstaOutXs.setString(44, lvMat.getStorageTypeNo());
					pstaOutXs.setString(45, lvMat.getStorageTypeName());
					pstaOutXs.setString(46, lvMat.getManagementNo());
					pstaOutXs.setString(47, lvMat.getManagementName());
					
					if (lvMat.getRpoTime().equals("")) {
						pstaOut.setString(48, "");
						pstaOutXs.setString(48, "");

					} else {
						pstaOut.setString(48,
								lvMat.getRpoTime().substring(0, 19));
						pstaOutXs.setString(48,
								lvMat.getRpoTime().substring(0, 19));
					}
					pstaOut.setString(49, lvMat.getProBc());
					pstaOut.setString(50, lvMat.getProBz());
					pstaOut.setString(51, strNowTime);
					pstaOut.setString(52, bc);
					pstaOut.setString(53, bz);
					pstaOut.setString(54, name);
					pstaOut.setString(55, strNowTime);
					pstaOut.setString(56, lvMat.getOrdPk());
					pstaOut.setString(57, lvMat.getOrdLnPk());
					pstaOut.setString(58, lvMat.getOrdLnDlyPk());
					pstaOut.setString(59, lvMat.getOrderNo());
					pstaOut.setString(60, lvMat.getOrderSeq());
					pstaOut.setString(61, lvMat.getDeliveryNo());
					pstaOut.setString(62, lvMat.getDepartmentCode());
					pstaOut.setString(63, lvMat.getDepartmentDesc());
					pstaOut.setString(64, lvMat.getBelongCode());
					pstaOut.setString(65, lvMat.getBelongName());
					pstaOut.setString(66, "120504".equals(supplyUnitCode)? ComBaseInfo.GetBalYear_2416(nowTime): ComBaseInfo.GetBalYear(nowTime));
					pstaOut.setString(67, lvMat.getPonderNo());
					pstaOut.setString(68,
							String.valueOf(lvMat.getPonderGrossWt()));
					pstaOut.setString(69, String.valueOf(lvMat.getSendNum()));
					pstaOut.setString(70, lvMat.getVstel());
					pstaOut.setString(71, lvMat.getVstelDesc());
					pstaOut.setString(72, lvMat.getFinishproMold());
					pstaOut.setString(73, lvMat.getInMold());
					pstaOut.setString(74, lvMat.getMatNo());
					pstaOut.setString(75, billNo);
					pstaOut.setString(76, supplyUnitCode);
					pstaOut.setString(77, supplyUnit);
					pstaOut.setString(78, lvMat.getMatNo());
					pstaOut.setString(79, lvMat.getMatNo());
					pstaOut.setString(80, lvMat.getMatNo());
					pstaOut.setString(81, lvMat.getMatNo());
					pstaOut.addBatch();
					pstaOutXs.setString(49, lvMat.getProBc());
					pstaOutXs.setString(50, lvMat.getProBz());
					pstaOutXs.setString(51, strNowTime);
					pstaOutXs.setString(52, bc);
					pstaOutXs.setString(53, bz);
					pstaOutXs.setString(54, name);
					pstaOutXs.setString(55, strNowTime);
					pstaOutXs.setString(56, lvMat.getOrdPk());
					pstaOutXs.setString(57, lvMat.getOrdLnPk());
					pstaOutXs.setString(58, lvMat.getOrdLnDlyPk());
					pstaOutXs.setString(59, lvMat.getOrderNo());
					pstaOutXs.setString(60, lvMat.getOrderSeq());
					pstaOutXs.setString(61, lvMat.getDeliveryNo());
					pstaOutXs.setString(62, lvMat.getDepartmentCode());
					pstaOutXs.setString(63, lvMat.getDepartmentDesc());
					pstaOutXs.setString(64, lvMat.getBelongCode());
					pstaOutXs.setString(65, lvMat.getBelongName());
					pstaOutXs.setString(66, "120504".equals(supplyUnitCode)? ComBaseInfo.GetBalYear_2416(nowTime): ComBaseInfo.GetBalYear(nowTime));
					pstaOutXs.setString(67, lvMat.getPonderNo());
					pstaOutXs.setString(68,
							String.valueOf(lvMat.getPonderGrossWt()));
					pstaOutXs.setString(69, String.valueOf(lvMat.getSendNum()));
					pstaOutXs.setString(70, lvMat.getVstel());
					pstaOutXs.setString(71, lvMat.getVstelDesc());
					pstaOutXs.setString(72, lvMat.getFinishproMold());
					pstaOutXs.setString(73, lvMat.getInMold());
					pstaOutXs.setString(74, lvMat.getMatNo());
					pstaOutXs.setString(75, billNo);
					pstaOutXs.setString(76, supplyUnitCode);
					pstaOutXs.setString(77, supplyUnit);
					pstaOutXs.setString(78, lvMat.getMatNo());
					pstaOutXs.setString(79, lvMat.getMatNo());
					pstaOutXs.setString(80, lvMat.getMatNo());
					pstaOutXs.setString(81, lvMat.getMatNo());
					if(loadvehicle_type.equals("1")){//默认为实单 若查询到虚单则不执行
						pstaOutXs.addBatch();
					}
					
					outNo++;
					outNoXs++;

					//crm 出库表迁移
					pstaCrmOut.setString(1,lvMat.getLoadvehicleSqe());
					pstaCrmOut.setString(2,billNo);
					pstaCrmOut.setString(3,lvMat.getLoadvehicleNo());
					pstaCrmOut.setString(4,lvMat.getJudgeStoveNo());
					pstaCrmOut.setString(5, lvMat.getBatchNo());
					pstaCrmOut.setString(6, lvMat.getBatchGroudNo());
					pstaCrmOut.setString(7, lvMat.getMaterialNo());
					pstaCrmOut.setString(8, lvMat.getMaterialName());
					pstaCrmOut.setString(9, lvMat.getProduccode());
					pstaCrmOut.setString(10, lvMat.getProducname());
					pstaCrmOut.setString(11, lvMat.getStdCode());
					pstaCrmOut.setString(12, lvMat.getStdName());
					pstaCrmOut.setString(13, lvMat.getGradecode());
					pstaCrmOut.setString(14, lvMat.getGradename());
					pstaCrmOut.setString(15, lvMat.getSteelcode());
					pstaCrmOut.setString(16, lvMat.getSteelname());
					pstaCrmOut.setString(17, lvMat.getStdStyle());
					pstaCrmOut.setString(18, lvMat.getStdStyleDesc());
					pstaCrmOut.setString(19, lvMat.getSpecCode());
					pstaCrmOut.setString(20, lvMat.getSpecName());
					pstaCrmOut.setString(21, lvMat.getModelCode());
					pstaCrmOut.setString(22, lvMat.getModelDesc());
					pstaCrmOut.setString(23, lvMat.getActLenMin());
					pstaCrmOut.setString(24, lvMat.getActLenMax());
					pstaCrmOut.setString(25, lvMat.getActCount());
					if(!StringUtils.isEmpty(lvMat.getPonderNo())){
						if("虚拟".equals(zcLoad.get(0).getLoadvehicleType())){
							pstaCrmOut.setString(26, String.valueOf(lvMat.getActWeight()));
						} else if(!StringUtils.isEmpty(lvMat.getPonderGrossWt()) && Double.parseDouble(lvMat.getPonderGrossWt()) > 0){
							pstaCrmOut.setString(26, lvMat.getPonderGrossWt());
						} else {
							pstaCrmOut.setString(26, String.valueOf(lvMat.getActWeight()));
						}
					}else {
						pstaCrmOut.setString(26, String.valueOf(lvMat.getActWeight()));
					}
					pstaCrmOut.setString(27, String.valueOf(lvMat.getActLen()));
					pstaCrmOut.setString(28, lvMat.getStorageNo());
					pstaCrmOut.setString(29, lvMat.getStorageNo());
					pstaCrmOut.setString(30, lvMat.getSenTime());
					pstaCrmOut.setString(31, lvMat.getValidflagMat());
					pstaCrmOut.setString(32, lvMat.getOrderNo());
					pstaCrmOut.setString(33, lvMat.getOrderSeq());
					pstaCrmOut.setString(34, lvMat.getDeliveryNo());
					pstaCrmOut.setString(35, lvMat.getOrdPk());
					pstaCrmOut.setString(36, lvMat.getOrdLnPk());
					pstaCrmOut.setString(37, lvMat.getOrdLnDlyPk());
					pstaCrmOut.setString(38,"0");
					pstaCrmOut.setString(39, strNowTime);
					pstaCrmOut.setString(40,billNo);
					pstaCrmOut.setString(41,billNo);
					pstaCrmOut.setString(42,billNo);
					pstaCrmOut.setString(43,"120504".equals(supplyUnitCode)? ComBaseInfo.GetBalYear_2416(nowTime): ComBaseInfo.GetBalYear(nowTime));
					pstaCrmOut.setString(44,lvMat.getActDimater());
					pstaCrmOut.setString(45,lvMat.getActHeight());
					pstaCrmOut.setString(46,lvMat.getBelongCode());
					pstaCrmOut.setString(47,lvMat.getBelongName());
					pstaCrmOut.setString(48,"800805");
					pstaCrmOut.setString(49,"销售出库");
					pstaCrmOut.addBatch();

					pstaPro.setObject(1, count);
					pstaPro.setObject(2, wt);
					pstaPro.setObject(3, lvMat.getOrdLnDlyPk());
					pstaPro.addBatch();

					// 新增材料表MAT_ZC_BACKUP（删除位置，材料表）
					psAddMat.setObject(1, lvMat.getMatNo());
					psAddMat.setObject(2, lvMat.getMatNo());
					psAddMat.setObject(3, lvMat.getMatNo());
					psAddMat.setObject(4, lvMat.getMatNo());
					psAddMat.addBatch();

					//新增crm材料表
					psAddCrmMat.setObject(1,"2");
					psAddCrmMat.setObject(2,strNowTime);
					psAddCrmMat.setObject(3, lvMat.getMatNo());
					psAddCrmMat.addBatch();
				}
				String storageNo="";
				String storageName="";
				String sql = "";
				String mat_code = "";
				for (int j=0;j<zcMatLoad.size();j++) {
					YdmZcMatEntityForWl zcMat=zcMatLoad.get(j);
					/*pstaWlMat.setObject(1,zcMat.getLoadvehicleNo() + StringTool.formatDecimal(j+1, "000"));
					pstaWlMat.setObject(2, zcMat.getLoadvehicleNo());
					pstaWlMat.setObject(3, zcMat.getBillNo());
					pstaWlMat.setObject(4, zcMat.getTallysheetNo());
					pstaWlMat.setObject(5, zcMat.getVehicleNo());
					pstaWlMat.setObject(6, zcMat.getOrderNo());
					pstaWlMat.setObject(7, zcMat.getOrderSeq());
					pstaWlMat.setObject(8, zcMat.getOrderSeqNo());
					pstaWlMat.setObject(9, zcMat.getStoveNo());
					pstaWlMat.setObject(10, zcMat.getLotNo());
					pstaWlMat.setObject(11, zcMat.getJudgeStoveNo());
					pstaWlMat.setObject(12, zcMat.getBatchNo());
					pstaWlMat.setObject(13, zcMat.getGroupNo());
					pstaWlMat.setObject(14, zcMat.getMaterialNo());
					pstaWlMat.setObject(15, zcMat.getMaterialName());
					pstaWlMat.setObject(16, zcMat.getProduccode());
					pstaWlMat.setObject(17, zcMat.getProducname());
					pstaWlMat.setObject(18, zcMat.getStdCode());
					pstaWlMat.setObject(19, zcMat.getStdName());
					pstaWlMat.setObject(20, zcMat.getGradecode());
					pstaWlMat.setObject(21, zcMat.getGradename());
					pstaWlMat.setObject(22, zcMat.getSteelcode());
					pstaWlMat.setObject(23, zcMat.getSteelname());
					pstaWlMat.setObject(24, zcMat.getStdStyle());
					pstaWlMat.setObject(25, zcMat.getStdStyleDesc());
					pstaWlMat.setObject(26, zcMat.getSpecCode());
					pstaWlMat.setObject(27, zcMat.getSpecName());
					pstaWlMat.setObject(28, zcMat.getModelCode());
					pstaWlMat.setObject(29, zcMat.getModelDesc());
					pstaWlMat.setObject(30, zcMat.getPlineCode());
					pstaWlMat.setObject(31, zcMat.getPlineName());
					pstaWlMat.setObject(32, zcMat.getActDimater());
					pstaWlMat.setObject(33, zcMat.getActHeight());
					pstaWlMat.setObject(34, zcMat.getActLenMin());
					pstaWlMat.setObject(35, zcMat.getActLenMax());
					pstaWlMat.setObject(36, zcMat.getActCount());
					pstaWlMat.setObject(37, zcMat.getActWeight());
					pstaWlMat.setObject(38, zcMat.getPonderNo());//过磅单号
					pstaWlMat.setObject(39, zcMat.getPonderGrossWt());//过磅重量
					pstaWlMat.setObject(40, zcMat.getVstel());
					pstaWlMat.setObject(41, zcMat.getVstelDesc());
					pstaWlMat.setObject(42, zcMat.getStorageNo());
					pstaWlMat.setObject(43, zcMat.getStorageName());
					pstaWlMat.setObject(44, name);
					pstaWlMat.setObject(45, zcMat.getSendNum());
					pstaWlMat.setObject(46, zcMat.getOrdPk());
					pstaWlMat.setObject(47, zcMat.getOrdLnPk());
					pstaWlMat.setObject(48, zcMat.getOrdLnDlyPk());
					pstaWlMat.setObject(49, zcMat.getActLen());
					pstaWlMat.addBatch();*/
					if("".equals(storageNo)){
						storageNo=zcMat.getStorageNo();
						storageName=zcMat.getStorageName();
					}
				}
				
				//接口数据上传到产销
				if(zcLoad.get(0).getLoadvehicleNo().equals(zcMatLoad.get(0).getLoadvehicleNo())
						&& zcLoad.get(0).getTallysheetNo().equals(zcMatLoad.get(0).getTallysheetNo())
						&& zcLoad.get(0).getBillNo().equals(zcMatLoad.get(0).getBillNo())) {
					   List<JSONObject> jsonObjects  = new ArrayList<>();
					   JSONObject jsonObject =  new JSONObject();					 
					   jsonObject.put("form_code", "MESTHSO05");
					   jsonObject.put("form_name", "发货实绩");
					   jsonObject.put("form_time", strtime);
					   jsonObject.put("op_flag","N");
					   jsonObject.put("outbill_no",zcLoad.get(0).getLoadvehicleNo());
					   jsonObject.put("deliver_plan_num",zcLoad.get(0).getBillNo());
					   jsonObject.put("receive_customer",zcLoad.get(0).getReceivNm());
					   jsonObject.put("car_no",zcLoad.get(0).getVehicleNo());
					   jsonObject.put("load_quantity",zcLoad.get(0).getStackingPiece());
					   jsonObject.put("load_weight",zcLoad.get(0).getPonderGrossWt());
					   jsonObject.put("load_storage",zcLoad.get(0).getManagementName());
					   jsonObject.put("load_date",strtime);
					   jsonObject.put("load_name",list1.get(4));
					   jsonObject.put("customer_flag",billMEntity.get(0).getMemo());
					   jsonObject.put("is_outbill_no","0");
					   String order_no = "";
					   String order_seq = "";
					   for (YdmZcMatEntityForWl ls : zcMatLoad) {	
						   sql = "select GET_CP_CODE('"+ls.getGradename()+"', "
					                  +" '"+ls.getSteelname()+"', "
					                  +"  GET_DELIVERY_STATE2(d.desgin_key, c.index_seq), "
					                  +"  '"+ls.getProducname()+"', "
					                  +"  '"+ls.getModelDesc()+"', "
					                  +"  (select max(y.value_text) "
					                  +"     from cxuser.craft_ord_design_std_gic y "
					                  +"    where y.desgin_key in "
					                  +"          (select x.desgin_key "
					                  +"             from cxuser.craft_ord_design_msc x "
					                  +"            where x.ord_ln_pk in "
					                  +"                  (select b.ord_ln_pk "
					                  +"                     from cxuser.slm_order_line b "
					                  +"                    where b.ord_pk in "
					                  +"                          (select a.ord_pk "
					                  +"                             from cxuser.slm_order_head a "
					                  +"                            where a.order_no = z.order_no "
					                  +"                      and x.order_seq = z.order_seq "
					                  +"      AND SPECL_FL = '2')))), "
					                  +"  '"+ls.getActDimater()+"', "
					                  +"  '"+ls.getActHeight()+"', "
					                  +"  case "
					                   +"   when z.endgxname like '%热处理%' then "
					                  +"     'C' "
					                  +"    when z.endgxname like '%加工%' then "
					                  +"     'B' "
					                  +"    when z.endgxname like '%轧制%' then "
					                  +"     'A' "
					                   +"   else "
					                   +"    '产线无' "
					                 +"   end) prod_code "
					  +" from pln_saleord z "
					  +" left join pln_saleord_proc c "
					  +"   on c.order_no = z.order_no "
					  +"  and c.order_seq = z.order_seq "
					  +" left join craft_ord_design d "
					  +" on z.ord_ln_pk = d.ord_ln_pk "
					  +" and d.validflag = '1' "
					 +" where z.order_no || z.order_seq in "
					  +"      (select b.order_no || b.order_seq "
					  +"         from ydm_zc_loadvehicle_mat b "
					  +"        where b.mat_no = '"+ls.getMatNo()+"') ";
					   psta = connection.prepareStatement(sql);
					   ResultSet rs6 = psta.executeQuery();
					   JSONArray jacbc = StringTool.resultSetToJsonArry(rs6);
						rs6.close();
						psta.close();
						if(jacbc.size() >0){
							mat_code = jacbc.getJSONObject(0).getString("PROD_CODE");
						}else{
							mat_code = ls.getMatNo();
						}
						   JSONObject jsonObject1 =  new JSONObject();
						   jsonObject1.put("bundle_num",ls.getMatNo());
						   jsonObject1.put("count",ls.getActCount());
						   jsonObject1.put("theory_weight",ls.getActWeight());
						   jsonObject1.put("act_len",ls.getActLen());
						   jsonObject1.put("act_weight",ls.getPonderGrossWt());
						   jsonObject1.put("heat_no",ls.getStoveNo());
						   jsonObject1.put("total_length","");
						   jsonObject1.put("stock_id","");
						   jsonObject1.put("lot_no",ls.getBatchNo());
						   jsonObject1.put("stock_address_code",ls.getStorageNo());
						   jsonObject1.put("stock_address_name",ls.getStorageName());
						   jsonObject1.put("mate_code",mat_code);
						   jsonObject1.put("mate_name",ls.getMaterialName());
						   jsonObject1.put("std_code",ls.getStdCode());
						   jsonObject1.put("group_number",ls.getGroupNo());
						   jsonObject1.put("ord_ln_dly_pk",ls.getOrdLnDlyPk());
						   jsonObject1.put("load_vehicle_No",ls.getLoadvehicleNo());
						   order_no = ls.getOrderNo();
						   order_seq = ls.getOrderSeq();
						   jsonObject1.put("order_no",order_seq);
						   jsonObject1.put("order_no_main",order_no);
						   jsonObjects.add(jsonObject1);
					}
					   //zhoujl 2024-11-18 修改到里面那一层
					   jsonObject.put("order_no",order_seq);
					   jsonObject.put("order_no_main",order_no);
					   jsonObject.put("detailList",jsonObjects);
					   System.out.print(jsonObject.toString());
					   DefaultWebServiceRequest request = new DefaultWebServiceRequest();
					   String s = jsonObject.toString();
					   s = s.replaceAll("&", "' || '&' || '");
					   s = "<![CDATA["+s+"]]>";
					   request.setMsgBody(s);
					   request.setServiceId("MESTHSO05");
					   String result = ServiceToCx.callWebserviceASMX("http://172.54.10.24:8191/ReceiverService.asmx",request,
								"receiveMessage",jsonObject.toString());	
					   if(!result.equals("200")) {
						    cro.setV_errMsg("接口信息上传失败！");
							cro.setResult(1);
						    return cro;
					   }
				}
				pstaOut.executeBatch();
				pstaOutXs.executeBatch();
				pstaCrmOut.executeBatch();
				pstaPro.executeBatch();
				psAddMat.executeBatch();
				psAddCrmMat.executeBatch();
				
				// pstaButtress.setObject(1, billNo);
				// pstaButtress.setObject(2, loadNo);
				// pstaButtress.setObject(3, tallNo);
				// pstaButtress.setObject(4, velNo);
				// pstaButtress.addBatch();

				psLoad.setObject(1, name);
				psLoad.setObject(2, loadNo);
				psLoad.addBatch();
			    psLoad.executeBatch();
			    
				psLoadMat.setObject(1, loadNo);
				psLoadMat.addBatch();
				psLoadMat.executeBatch();

				//sql = CoreXmlSqlParsersFactory.getSql("");



				YdmZcLoadvehicleEntity loadEntity=zcLoad.get(0);
				/*pstaWlDelisery.setObject(1, loadEntity.getBillNo());
				pstaWlDelisery.setObject(2, loadEntity.getLoadvehicleNo());
				pstaWlDelisery.setObject(3, loadEntity.getTallysheetNo());
				pstaWlDelisery.setObject(4, loadEntity.getVehicleNo());
				pstaWlDelisery.setObject(5, loadEntity.getTransType());
				pstaWlDelisery.setObject(6, loadEntity.getReceivNo());
				pstaWlDelisery.setObject(7, loadEntity.getReceivNm());
				pstaWlDelisery.setObject(8, loadEntity.getStationNo());
				pstaWlDelisery.setObject(9, loadEntity.getStationNm());
				pstaWlDelisery.setObject(10, loadEntity.getSpclLnNo());
				pstaWlDelisery.setObject(11, loadEntity.getSpclLnNm());
				pstaWlDelisery.setObject(12, loadEntity.getStackingWt());
				pstaWlDelisery.setObject(13, loadEntity.getStackingPiece());
				pstaWlDelisery.setObject(14, loadEntity.getStackingTotlLen());
				pstaWlDelisery.setObject(15, loadEntity.getPonderGrossWt());
				pstaWlDelisery.setObject(16, name);
				pstaWlDelisery.setObject(17, loadEntity.getSaleOrg());
				pstaWlDelisery.setObject(18, loadEntity.getSaleOrgDesc());
				pstaWlDelisery.setObject(19, loadEntity.getSaleArea());
				pstaWlDelisery.setObject(20, "0");

				pstaWlDelisery.setObject(21, loadEntity.getCarrierCode());
				pstaWlDelisery.setObject(22, loadEntity.getCarrierName());
				pstaWlDelisery.setObject(23, loadEntity.getCarLicense());
				pstaWlDelisery.setObject(24, loadEntity.getDriverCode());
				pstaWlDelisery.setObject(25, loadEntity.getDriverName());
				pstaWlDelisery.setObject(26, storageNo);
				pstaWlDelisery.setObject(27, storageName);

				pstaWlDelisery.addBatch();
				pstaWlDelisery.executeBatch();
				pstaWlMat.executeBatch();*/
				if(arr.length>0){
					int seq=1;
					for(String type : arr){
						String typeName = "";
						sqlquery = CoreXmlSqlParsersFactory
								.getSql("FrmPipeLoad.queryConBaseInfo");
						psta = connection.prepareStatement(sqlquery);
						psta.setObject(1, type);
						rs = psta.executeQuery();
						if (rs.next()) {
							typeName = rs.getString("basename");
						}
						rs.close();
						psta.close();
						/*pstaWlBill.setObject(1, loadEntity.getLoadvehicleNo());
						pstaWlBill.setObject(2, seq);
						pstaWlBill.setObject(3, type);
						pstaWlBill.setObject(4, typeName);
						if("802113".equals(type)){
							pstaWlBill.setObject(5, "YS");
							pstaWlBill.setObject(6, "应收账单");
						}else{
							pstaWlBill.setObject(5, "YF");
							pstaWlBill.setObject(6, "应付账单");
						}
						pstaWlBill.setObject(7, "10");
						pstaWlBill.setObject(8, userId);
						pstaWlBill.setObject(9, name);
						pstaWlBill.addBatch();*/
						seq++;
					}
					//pstaWlBill.executeBatch();
				}


				// 暂时注释：20241024刘侣
//				if (zcLoad.get(0).getReceivNm().contains("天津钢管制造")) {
//
//
//				}


				// 发送提单及明细：
				psta = connection.prepareStatement("select to_char(ACT_END_TIME,'yyyy-MM-dd HH24:mi:ss') ACT_END_TIME,\n" +
					"ACT_NUM,to_char(ACT_START_TIME,'yyyy-MM-dd HH24:mi:ss') ACT_START_TIME,\n" +
					"ACT_TOTL_LEN,ACT_TOTL_LEN_TEMP,ACT_TRANS_TYPE,ACT_WT,AGENCY_FL,ASK_ITEM_NO,\n" +
					"BAL_YEAR_MONTH,BILL_NO,BILL_NO_SEQ,BILL_STATUS,BILL_TICKET_AFFRIM_NAME,\n" +
					"to_char(BILL_TICKET_AFFRIM_TIME,'yyyy-MM-dd HH24:mi:ss') BILL_TICKET_AFFRIM_TIME\n" +
					",BILL_TICKET_STATUS,CARRY_COMPANY_CODE,CARRY_COMPANY_NAME,CHECK_NO,CREATE_NAME,\n" +
					"to_char(CREATE_TIME,'yyyy-MM-dd HH24:mi:ss') CREATE_TIME,CREDIT_NO,CUSTOMER_NM,\n" +
					"CUSTOMER_NO,DELETE_NAME,to_char(DELETE_TIME,'yyyy-MM-dd HH24:mi:ss') DELETE_TIME\n" +
					",DELIVERY_NO,DELIVY_PLACE_CODE,DELIVY_PLACE_NAME,DELVRY_ADDR,DELVRY_WHEREABOUTS,\n" +
					"DEPARTMENT_CODE,DEPARTMENT_DESC,EXTRA_FLAG,FLAG_LEN,FST_DRAWEE_UNIT,IS_OVERSTOCK\n" +
					",ISPRECLOSE,ITEM_NO,LANGUAGE_CODE,LANGUAGE_NAME,LET_DELIVERY_FLAG,LICENSE_NO,\n" +
					"LOADVEHICLE_TYPE,LOCK_BILL_FLAG,MANAGEMENT_NAME,MANAGEMENT_NO,MEMO,METRIC_SYSTEM\n" +
					",ORD_LN_DLY_PK,ORD_LN_PK,ORD_PK,ORDER_NO,ORDER_SEQ,OUTSTOCK_TICKET_AFFRIM_NAME,\n" +
					"to_char(OUTSTOCK_TICKET_AFFRIM_TIME,'yyyy-MM-dd HH24:mi:ss') OUTSTOCK_TICKET_AFFRIM_TIME\n" +
					",OUTSTOCK_TICKET_STATUS,PICKUP_FLAG,to_char(PLAN_END_TIME,'yyyy-MM-dd HH24:mi:ss') PLAN_END_TIME\n" +
					",PLAN_NUM,to_char(PLAN_START_TIME,'yyyy-MM-dd HH24:mi:ss') PLAN_START_TIME,\n" +
					"PLAN_TOTL_LEN,PLAN_TOTL_LEN_TEMP,PLAN_TRANS_TYPE,PLAN_WT,PORT_DESC,PORT_NO,PRD_CLS\n" +
					",PRINT_FLAG,PRINT_NUM,PRINT_NUMBER,to_char(PRINT_TIME,'yyyy-MM-dd HH24:mi:ss') PRINT_TIME\n" +
					",PRODUCCODE,PRODUCNAME,REALINVOICENO,REALINVOICENO1,\n" +
					"to_char(REALINVOICENO_DATE,'yyyy-MM-dd HH24:mi:ss') REALINVOICENO_DATE,RECEIV_ADDR\n" +
					",RECEIV_NM,RECEIV_NO,RETURN_FLAG,SALE_ORG,SALE_ORG_DESC,SEND_PLAN_NO,SINGLE_NO,\n" +
					"SPCL_LN_NM,SPCL_LN_NO,SPEC_CODE,SPEC_NAME,STATION_NM,STATION_NO,STD_CODE,STD_NAME\n" +
					",STEELCODE,STEELNAME,STLMT_UNIT_NM,STLMT_UNIT_NO,STOVE_TICKET_FLAG,SUPPLY_UNIT,\n" +
					"SUPPLY_UNIT_DESC,TRANSMNY_TICKET_AFFRIM_NAME,\n" +
					"to_char(TRANSMNY_TICKET_AFFRIM_TIME,'yyyy-MM-dd HH24:mi:ss') TRANSMNY_TICKET_AFFRIM_TIME\n" +
					",TRANSMNY_TICKET_STATUS,UPDATE_NAME,to_char(UPDATE_TIME,'yyyy-MM-dd HH24:mi:ss') UPDATE_TIME\n" +
					",VALIDFLAG,VSTEL_CODE,VSTEL_DESC,WIND_UP_FLAG,ZBS_FLAG,ZBS_NAME,ZBS_NUM,ZBS_ORDER_NO\n" +
					",ZBS_ORDER_NO_NAME,to_char(ZBS_ORDER_NO_TIME,'yyyy-MM-dd HH24:mi:ss') ZBS_ORDER_NO_TIME\n" +
					",ZBS_PATH,ZBS_SOURCE,to_char(ZBS_TIME,'yyyy-MM-dd HH24:mi:ss') ZBS_TIME,\n" +
					"ZBS_TYPE_CODE,ZBS_TYPE_DESC,ZOUT_FLAG\n" +
					"from YDM_ZC_BILL_M where BILL_NO = ? and VALIDFLAG = '1' order by CREATE_TIME desc ");

				psta.setString(1, billNo);

				rs = psta.executeQuery();

				JSONArray billarr = new JSONArray();
				while (rs.next()) {
					JSONObject bill = new JSONObject();
					bill.put("actEndTime", rs.getString("ACT_END_TIME"));
					bill.put("actNum", rs.getString("ACT_NUM"));
					bill.put("actStartTime", rs.getString("ACT_START_TIME"));
					bill.put("actTotlLen", rs.getString("ACT_TOTL_LEN"));
					bill.put("actTotlLenTemp", rs.getString("ACT_TOTL_LEN_TEMP"));
					bill.put("actTransType", rs.getString("ACT_TRANS_TYPE"));
					bill.put("actWt", rs.getString("ACT_WT"));
					bill.put("agencyFl", rs.getString("AGENCY_FL"));
					bill.put("askItemNo", rs.getString("ASK_ITEM_NO"));
					bill.put("balYearMonth", rs.getString("BAL_YEAR_MONTH"));
					bill.put("billNo", rs.getString("BILL_NO"));
					bill.put("billNoSeq", rs.getString("BILL_NO_SEQ"));
					bill.put("billStatus", rs.getString("BILL_STATUS"));
					bill.put("billTicketAffrimName", rs.getString("BILL_TICKET_AFFRIM_NAME"));
					bill.put("billTicketAffrimTime", rs.getString("BILL_TICKET_AFFRIM_TIME"));
					bill.put("billTicketStatus", rs.getString("BILL_TICKET_STATUS"));
					bill.put("carryCompanyCode", rs.getString("CARRY_COMPANY_CODE"));
					bill.put("carryCompanyName", rs.getString("CARRY_COMPANY_NAME"));
					bill.put("checkNo", rs.getString("CHECK_NO"));
					bill.put("createName", rs.getString("CREATE_NAME"));
					bill.put("createTime", rs.getString("CREATE_TIME"));
					bill.put("creditNo", rs.getString("CREDIT_NO"));
					bill.put("customerNm", rs.getString("CUSTOMER_NM"));
					bill.put("customerNo", rs.getString("CUSTOMER_NO"));
					bill.put("deleteName", rs.getString("DELETE_NAME"));
					bill.put("deleteTime", rs.getString("DELETE_TIME"));
					bill.put("deliveryNo", rs.getString("DELIVERY_NO"));
					bill.put("delivyPlaceCode", rs.getString("DELIVY_PLACE_CODE"));
					bill.put("delivyPlaceName", rs.getString("DELIVY_PLACE_NAME"));
					bill.put("delvryAddr", rs.getString("DELVRY_ADDR"));
					bill.put("delvryWhereabouts", rs.getString("DELVRY_WHEREABOUTS"));
					bill.put("departmentCode", rs.getString("DEPARTMENT_CODE"));
					bill.put("departmentDesc", rs.getString("DEPARTMENT_DESC"));
					bill.put("extraFlag", rs.getString("EXTRA_FLAG"));
					bill.put("flagLen", rs.getString("FLAG_LEN"));
					bill.put("fstDraweeUnit", rs.getString("FST_DRAWEE_UNIT"));
					bill.put("id", rs.getString("BILL_NO_SEQ"));
					bill.put("isOverstock", rs.getString("IS_OVERSTOCK"));
					bill.put("ispreclose", rs.getString("ISPRECLOSE"));
					bill.put("itemNo", rs.getString("ITEM_NO"));
					bill.put("languageCode", rs.getString("LANGUAGE_CODE"));
					bill.put("languageName", rs.getString("LANGUAGE_NAME"));
					bill.put("letDeliveryFlag", rs.getString("LET_DELIVERY_FLAG"));
					bill.put("licenseNo", rs.getString("LICENSE_NO"));
					bill.put("loadvehicleType", rs.getString("LOADVEHICLE_TYPE"));
					bill.put("lockBillFlag", rs.getString("LOCK_BILL_FLAG"));
					bill.put("managementName", rs.getString("MANAGEMENT_NAME"));
					bill.put("managementNo", rs.getString("MANAGEMENT_NO"));
					bill.put("memo", rs.getString("MEMO"));
					bill.put("metricSystem", rs.getString("METRIC_SYSTEM"));
					bill.put("ordLnDlyPk", rs.getString("ORD_LN_DLY_PK"));
					bill.put("ordLnPk", rs.getString("ORD_LN_PK"));
					bill.put("ordPk", rs.getString("ORD_PK"));
					bill.put("orderNo", rs.getString("ORDER_NO"));
					bill.put("orderSeq", rs.getString("ORDER_SEQ"));
					bill.put("outstockTicketAffrimName", rs.getString("OUTSTOCK_TICKET_AFFRIM_NAME"));
					bill.put("outstockTicketAffrimTime", rs.getString("OUTSTOCK_TICKET_AFFRIM_TIME"));
					bill.put("outstockTicketStatus", rs.getString("OUTSTOCK_TICKET_STATUS"));
					bill.put("pickupFlag", rs.getString("PICKUP_FLAG"));
					bill.put("planEndTime", rs.getString("PLAN_END_TIME"));
					bill.put("planNum", rs.getString("PLAN_NUM"));
					bill.put("planStartTime", rs.getString("PLAN_START_TIME"));
					bill.put("planTotlLen", rs.getString("PLAN_TOTL_LEN"));
					bill.put("planTotlLenTemp", rs.getString("PLAN_TOTL_LEN_TEMP"));
					bill.put("planTransType", rs.getString("PLAN_TRANS_TYPE"));
					bill.put("planWt", rs.getString("PLAN_WT"));
					bill.put("portDesc", rs.getString("PORT_DESC"));
					bill.put("portNo", rs.getString("PORT_NO"));
					bill.put("prdCls", rs.getString("PRD_CLS"));
					bill.put("printFlag", rs.getString("PRINT_FLAG"));
					bill.put("printNum", rs.getString("PRINT_NUM"));
					bill.put("printNumber", rs.getString("PRINT_NUMBER"));
					bill.put("printTime", rs.getString("PRINT_TIME"));
					bill.put("produccode", rs.getString("PRODUCCODE"));
					bill.put("producname", rs.getString("PRODUCNAME"));
					bill.put("realinvoiceno", rs.getString("REALINVOICENO"));
					bill.put("realinvoiceno1", rs.getString("REALINVOICENO1"));
					bill.put("realinvoicenoDate", rs.getString("REALINVOICENO_DATE"));
					bill.put("receivAddr", rs.getString("RECEIV_ADDR"));
					bill.put("receivNm", rs.getString("RECEIV_NM"));
					bill.put("receivNo", rs.getString("RECEIV_NO"));
					bill.put("returnFlag", rs.getString("RETURN_FLAG"));
					bill.put("saleOrg", rs.getString("SALE_ORG"));
					bill.put("saleOrgDesc", rs.getString("SALE_ORG_DESC"));
					bill.put("sendPlanNo", rs.getString("SEND_PLAN_NO"));
					bill.put("singleNo", rs.getString("SINGLE_NO"));
					bill.put("spclLnNm", rs.getString("SPCL_LN_NM"));
					bill.put("spclLnNo", rs.getString("SPCL_LN_NO"));
					bill.put("specCode", rs.getString("SPEC_CODE"));
					bill.put("specName", rs.getString("SPEC_NAME"));
					bill.put("stationNm", rs.getString("STATION_NM"));
					bill.put("stationNo", rs.getString("STATION_NO"));
					bill.put("stdCode", rs.getString("STD_CODE"));
					bill.put("stdName", rs.getString("STD_NAME"));
					bill.put("steelcode", rs.getString("STEELCODE"));
					bill.put("steelname", rs.getString("STEELNAME"));
					bill.put("stlmtUnitNm", rs.getString("STLMT_UNIT_NM"));
					bill.put("stlmtUnitNo", rs.getString("STLMT_UNIT_NO"));
					bill.put("stoveTicketFlag", rs.getString("STOVE_TICKET_FLAG"));
					bill.put("supplyUnit", rs.getString("SUPPLY_UNIT"));
					bill.put("supplyUnitDesc", rs.getString("SUPPLY_UNIT_DESC"));
					bill.put("transmnyTicketAffrimName", rs.getString("TRANSMNY_TICKET_AFFRIM_NAME"));
					bill.put("transmnyTicketAffrimTime", rs.getString("TRANSMNY_TICKET_AFFRIM_TIME"));
					bill.put("transmnyTicketStatus", rs.getString("TRANSMNY_TICKET_STATUS"));
					bill.put("updateName", rs.getString("UPDATE_NAME"));
					bill.put("updateTime", rs.getString("UPDATE_TIME"));
					bill.put("validflag", rs.getString("VALIDFLAG"));
					bill.put("vstelCode", rs.getString("VSTEL_CODE"));
					bill.put("vstelDesc", rs.getString("VSTEL_DESC"));
					bill.put("windUpFlag", rs.getString("WIND_UP_FLAG"));
					bill.put("zbsFlag", rs.getString("ZBS_FLAG"));
					bill.put("zbsName", rs.getString("ZBS_NAME"));
					bill.put("zbsNum", rs.getString("ZBS_NUM"));
					bill.put("zbsOrderNo", rs.getString("ZBS_ORDER_NO"));
					bill.put("zbsOrderNoName", rs.getString("ZBS_ORDER_NO_NAME"));
					bill.put("zbsOrderNoTime", rs.getString("ZBS_ORDER_NO_TIME"));
					bill.put("zbsPath", rs.getString("ZBS_PATH"));
					bill.put("zbsSource", rs.getString("ZBS_SOURCE"));
					bill.put("zbsTime", rs.getString("ZBS_TIME"));
					bill.put("zbsTypeCode", rs.getString("ZBS_TYPE_CODE"));
					bill.put("zbsTypeDesc", rs.getString("ZBS_TYPE_DESC"));
					bill.put("zoutFlag", rs.getString("ZOUT_FLAG"));
					billarr.add(bill);
				}

				psta.close();
				rs.close();

				// 获取提单从表：
				psta = connection.prepareStatement("select ACT_COUNT,ACT_DIMATER,ACT_FIX_LEN,ACT_FIX_NUM,ACT_HEIGHT,ACT_LEN,ACT_LEN_MAX\n" +
					"    ,ACT_LEN_MIN,ACT_LEN_TEMP,ACT_THEORY_WEIGHT,ACT_WEIGHT,BATCH_NO,BILL_BATCH_NO,\n" +
					"    BILL_NO,BILL_SQE,BOUND_NUM,CREATE_NAME,to_char(CREATE_TIME,'yyyy-MM-dd HH24:mi:ss') CREATE_TIME\n" +
					"    ,DELETE_NAME,to_char(DELETE_TIME,'yyyy-MM-dd HH24:mi:ss') DELETE_TIME,DELIVERY_NO\n" +
					"    ,EDIT_FLAG,FINISHPRO_MOLD,GRADECODE,GRADENAME,GROUP_NO,IN_MOLD,IN_TYPE,JG_ZBS_ID\n" +
					"    ,JUDGE_RESULT_CODE,JUDGE_STOVE_NO,LOADVEHICLE_FLAG,LOCATION_NO,LOT_NO,MAT_NO,\n" +
					"    MATERIAL_NAME,MATERIAL_NO,MEMO,MODEL_CODE,MODEL_DESC,MOVE_LOAD_FLAG,ORD_LN_DLY_PK\n" +
					"    ,ORD_LN_PK,ORD_PK,ORDER_NO,ORDER_SEQ,PACK_NO,PLINE_CODE,PLINE_NAME,PRO_BC,PRO_BZ\n" +
					"    ,PRODUCCODE,PRODUCNAME,PRT_FLAG,RECEIVE_FLAG,RETURN_FLAG,\n" +
					"    to_char(RPO_TIME,'yyyy-MM-dd HH24:mi:ss') RPO_TIME,SEND_NUM,SPEC_CODE,SPEC_NAME,\n" +
					"    STD_CODE,STD_NAME,STD_STYLE,STD_STYLE_DESC,STEELCODE,STEELNAME,STORAGE_NO,\n" +
					"    STOVE_NO,UPDATE_NAME,to_char(UPDATE_TIME,'yyyy-MM-dd HH24:mi:ss') UPDATE_TIME,\n" +
					"    VALIDFLAG,VSTEL,VSTEL_DESC,YEAR_SEQ,ZBS_ID,\n" +
					"    (SELECT\n" +
					"    '天淮判定支数：'|| SUM(ACT_COUNT)FROM QCM_ZG_JUGDE_APPLY WHERE TARGET = 'A'\n" +
					"    AND JUDGE_TOLRESULT_CODE in ('40740701','40740709') AND JUDGE_STOVE_NO = T.JUDGE_STOVE_NO\n" +
					"    AND BATCH_NO =t.BATCH_NO\n" +
					"    AND ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) JUDGECOUNT\n" +
					"    from YDM_ZC_BILL_C t  where BILL_NO = ? \n" +
					"    and nvl(VALIDFLAG, '0') = '1' and nvl(LOADVEHICLE_FLAG,'0')='1'");
				psta.setString(1, billNo);

				rs = psta.executeQuery();
				JSONArray detArr = new JSONArray();
				while (rs.next()) {
					JSONObject det = new JSONObject();
					det.put("judgeCount", rs.getString("JUDGECOUNT"));
					det.put("actCount", rs.getString("ACT_COUNT"));
					det.put("actDimater", rs.getString("ACT_DIMATER"));
					det.put("actFixLen", rs.getString("ACT_FIX_LEN"));
					det.put("actFixNum", rs.getString("ACT_FIX_NUM"));
					det.put("actHeight", rs.getString("ACT_HEIGHT"));
					det.put("actLen", rs.getString("ACT_LEN"));
					det.put("actLenMax", rs.getString("ACT_LEN_MAX"));
					det.put("actLenMin", rs.getString("ACT_LEN_MIN"));
					det.put("actLenTemp", rs.getString("ACT_LEN_TEMP"));
					det.put("actTheoryWeight", rs.getString("ACT_THEORY_WEIGHT"));
					det.put("actWeight", rs.getString("ACT_WEIGHT"));
					det.put("batchNo", rs.getString("BATCH_NO"));
					det.put("billBatchNo", rs.getString("BILL_BATCH_NO"));
					det.put("billNo", rs.getString("BILL_NO"));
					det.put("billSqe", rs.getString("BILL_SQE"));
					det.put("boundNum", rs.getString("BOUND_NUM"));
					det.put("createName", rs.getString("CREATE_NAME"));
					det.put("createTime", rs.getObject("CREATE_TIME") == null ? billarr.getJSONObject(0).getString("createTime") : rs.getString("CREATE_TIME"));
					det.put("deleteName", rs.getString("DELETE_NAME"));
					det.put("deleteTime", rs.getString("DELETE_TIME"));
					det.put("deliveryNo", rs.getString("DELIVERY_NO"));
					det.put("editFlag", rs.getString("EDIT_FLAG"));
					det.put("finishproMold", rs.getString("FINISHPRO_MOLD"));
					det.put("gradecode", rs.getString("GRADECODE"));
					det.put("gradename", rs.getString("GRADENAME"));
					det.put("groupNo", rs.getString("GROUP_NO"));
					det.put("id", rs.getString("BILL_SQE"));
					det.put("inMold", rs.getString("IN_MOLD"));
					det.put("inType", rs.getString("IN_TYPE"));
					det.put("jgZbsId", rs.getString("JG_ZBS_ID"));
					det.put("judgeResultCode", rs.getString("JUDGE_RESULT_CODE"));
					det.put("judgeStoveNo", rs.getString("JUDGE_STOVE_NO"));
					det.put("loadvehicleFlag", rs.getString("LOADVEHICLE_FLAG"));
					det.put("locationNo", rs.getString("LOCATION_NO"));
					det.put("lotNo", rs.getString("LOT_NO"));
					det.put("matNo", rs.getString("MAT_NO"));
					det.put("materialName", rs.getString("MATERIAL_NAME"));
					det.put("materialNo", rs.getString("MATERIAL_NO"));
					det.put("memo", rs.getString("MEMO"));
					det.put("modelCode", rs.getString("MODEL_CODE"));
					det.put("modelDesc", rs.getString("MODEL_DESC"));
					det.put("moveLoadFlag", rs.getString("MOVE_LOAD_FLAG"));
					det.put("ordLnDlyPk", rs.getString("ORD_LN_DLY_PK"));
					det.put("ordLnPk", rs.getString("ORD_LN_PK"));
					det.put("ordPk", rs.getString("ORD_PK"));
					det.put("orderNo", rs.getString("ORDER_NO"));
					det.put("orderSeq", rs.getString("ORDER_SEQ"));
					det.put("packNo", rs.getString("PACK_NO"));
					det.put("plineCode", rs.getString("PLINE_CODE"));
					det.put("plineName", rs.getString("PLINE_NAME"));
					det.put("proBc", rs.getString("PRO_BC"));
					det.put("proBz", rs.getString("PRO_BZ"));
					det.put("produccode", rs.getString("PRODUCCODE"));
					det.put("producname", rs.getString("PRODUCNAME"));
					det.put("prtFlag", rs.getString("PRT_FLAG"));
					det.put("receiveFlag", rs.getString("RECEIVE_FLAG"));
					det.put("returnFlag", rs.getString("RETURN_FLAG"));
					det.put("rpoTime", rs.getString("RPO_TIME"));
					det.put("sendNum", rs.getString("SEND_NUM"));
					det.put("specCode", rs.getString("SPEC_CODE"));
					det.put("specName", rs.getString("SPEC_NAME"));
					det.put("stdCode", rs.getString("STD_CODE"));
					det.put("stdName", rs.getString("STD_NAME"));
					det.put("stdStyle", rs.getString("STD_STYLE"));
					det.put("stdStyleDesc", rs.getString("STD_STYLE_DESC"));
					det.put("steelcode", rs.getString("STEELCODE"));
					det.put("steelname", rs.getString("STEELNAME"));
					det.put("storageNo", rs.getString("STORAGE_NO"));
					det.put("stoveNo", rs.getString("STOVE_NO"));
					det.put("updateName", rs.getString("UPDATE_NAME"));
					det.put("updateTime", rs.getString("UPDATE_TIME"));
					det.put("validflag", rs.getString("VALIDFLAG"));
					det.put("vstel", rs.getString("VSTEL"));
					det.put("vstelDesc", rs.getString("VSTEL_DESC"));
					det.put("yearSeq", rs.getString("YEAR_SEQ"));
					det.put("zbsId", rs.getString("ZBS_ID"));

					detArr.add(det);
				}
				psta.close();
				rs.close();

				// 参数合并：
				JSONArray karr = new JSONArray();
				for (int i1 = 0; i1 < billarr.size(); i1++) {
					if (i1 == (billarr.size()-1)) {
						billarr.getJSONObject(i1).put("ydmZcBillCs", detArr);
					} else {
						billarr.getJSONObject(i1).put("ydmZcBillCs", karr);
					}
				}

				// 暂时注释：20241024刘侣
				if (!"".equals(billarr.getJSONObject(0).getString("customerNm")) && billarr.getJSONObject(0).getString("customerNm").contains("天津钢管制造")) {
					// 提取炉号：
					for (int i1 = 0; i1 < detArr.size(); i1++) {
						stoves.add(detArr.getJSONObject(i1).getString("judgeStoveNo"));
						stovesrl.add(detArr.getJSONObject(i1).getString("stoveNo"));
					}

//					System.out.println("zhuangchecanshu：" + main.toString());
					// 暂时注释：20240926刘侣
					// 发送装车信息：
					String result = HttpConnectionLL.postJsonParams("http://172.50.202.90:9003/v1/ydmzcloadvehicles/add", main.toString());

//					System.out.println(result);
					if ("".equals(result)) {
						// 失败后记录日志：
						//connection.rollback();
						logSave(connection, "loadSend", main.toString(), loadNo, "result未返回结果");
						//throw new Exception("未返回结果");
					}
					else if (result.contains("500")) {
						// 如果是主键冲突则不抛送错误：
						logSave(connection, "loadSend", main.toString(), loadNo, "装车信息推送天管失败");
					}else{
						// 成功后记录日志：
						logSave(connection, "loadSend", main.toString(), loadNo, "装车发送天管成功");
					}

//					System.out.println("tidancanshu" + bill.toString());
					// 发送：sendParams
					// 发送到天管系统：
					String resultbill = HttpConnectionLL.postJsonParams("http://172.50.202.90:9003//v1/ydmzcbills/add", billarr.toString());
//					System.out.println(resultbill);
					if ("".equals(resultbill)) {
						//connection.rollback();
						// 失败后记录日志：
						logSave(connection, "billSend", billarr.toString(), billNo, "resultbill未返回结果");
						//throw new Exception("未返回结果");
					}
					else if (resultbill.contains("500")) {
						// 如果是主键冲突则不抛送错误：
						logSave(connection, "billSend", billarr.toString(), billNo, "提单信息推送天管失败");
					}else{
						// 成功后记录日志：
						logSave(connection, "billSend", billarr.toString(), billNo, "提单发送天管成功");
						// end
					}
					
				}

			}

			// 暂时注释：20241024刘侣
			// 暂时注释：20240926刘侣
			// 发送完成后将炉号记录入 成分理化信息是否发送到天管中间表
			psta = connection.prepareStatement("insert into SEND_ELENCONSIGN_TEMP (JUDGE_STOVE_NO) values (?) ");
			for (String stove : stoves) {
				psta.setString(1, stove);
				psta.addBatch();
			}
			psta.executeBatch();
			psta.clearBatch();
			psta.close();

			// 记录需要发送的熔炼成分 炉号：
			psta = connection.prepareStatement("insert into SEND_ELENCONSIGN_TEMP (JUDGE_STOVE_NO,IS_SEND_CONSIGN,IS_RL) values (?,'1','1')");
			for (String stove : stovesrl) {
				psta.setString(1, stove);
				psta.addBatch();
			}
			psta.executeBatch();
			psta.clearBatch();
			psta.close();


			// 将 lines 和 others 记录到中间表：20241224刘侣
			// 将合同行号记录入中间表：20241224刘侣
			/*StringBuilder judgeStr = new StringBuilder();
			psta = connection.prepareStatement("");
			for (String line : lines) {
				judgeStr.append(line).append(",");
			}
			psta.setString(1, judgeStr.toString());
			psta.addBatch();
			psta.executeBatch();
			psta.clearBatch();
			psta.close();*/
			//周俊伶 修改为一个合同一个炉号一组数据
			String sqlString = "insert into SEND_JYINFOSMID (OPERATE_NO,OPERATE_TYPE) values (?,'1')";
			PreparedStatement ps3 = connection.prepareStatement(sqlString);
			for	(String line : lines){
				ps3.setObject(1, line);
                ps3.addBatch();
			}
			ps3.executeBatch();
            ps3.close();
			
			cro.setV_errMsg("确认成功！");
			cro.setResult(1);
			connection.commit();
			//wlCon.commit();
		} catch (Exception e) {
			cro.setV_errMsg(e.getMessage());
			cro.setV_errCode(-1);
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
			/*if (wlCon != null) {
				try {
					wlCon.rollback();
				} catch (Exception e2) {
				}
			}*/
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
			/*try {
				if (wlCon != null && !wlCon.isClosed()) {
					wlCon.close();
				}
			} catch (Exception e2) {
			}*/
		}
		return cro;
	}

	/**
	 * 日志记录方法
	 *
	 * @param
	 *
	 * @return obj
	 */
	public void logSave(Connection conLog, String methodNm, String params, String pkNo, String res) {
//		CoreReturnObject cro = new CoreReturnObject();
//		Connection conLog = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		//Connection wlCon = new DBCommon().getDao("TmsDao").getConnection();注释生产物流  2024/4/24 肖沅累
		PreparedStatement psLog = null;

		try {
			conLog.setAutoCommit(false); // 取消自动提交事务
			String sql = " insert into cx_to_mes_log " +
					"  (SOCKET_NAME,SOCKET_PARMER,SOCKET_TIME,KEY,OPERATE_RESULT) " +
					" values (?,?,sysdate,?,?)";
			psLog = conLog.prepareStatement(sql);
			psLog.setString(1, methodNm);
			psLog.setString(2, params);
			psLog.setString(3, pkNo);
			psLog.setString(4, res);
			psLog.execute();
			psLog.close();
		} catch (Exception e) {

			if (conLog != null) {
				try {
					conLog.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}

		} finally {
			try {
//				if (conLog != null && !conLog.isClosed()) {
//					conLog.close();
//				}
				/*if (wlCon != null && !wlCon.isClosed()) {
					wlCon.close();
				}*/
			} catch (Exception e2) {
			}
		}

	}


	/**
	 * 修改发货实绩表信息取消确认
	 * 
	 * @param list
	 *            传递参数
	 * @return obj
	 */
	public CoreReturnObject updateDelCancel(ArrayList<ArrayList<String>> list) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		//Connection wlCon = new DBCommon().getDao("TmsDao").getConnection();注释生产物流  2024/4/24 肖沅累
		PreparedStatement psta = null;
		JSONObject sendParams = new JSONObject();
		JSONArray noArr = new JSONArray();
		sendParams.put("loadNos", noArr);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			//wlCon.setAutoCommit(false);
			String sqlquery = "";
			Date nowTime = new Date();
			SimpleDateFormat dfT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String strNowTime = dfT.format(nowTime);
			Gson gson = new Gson();
			Boolean interfaceState = false;
			// String sqlupdate = CoreXmlSqlParsersFactory
			// .getSql("FrmPipeLoad.updateMatZcNo1");// 修改材料表过磅重量
			// PreparedStatement psupdate =
			// connection.prepareStatement(sqlupdate);
			String addMatNo = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.AddMatNoZc");// 新增材料表（删除材料表MAT_ZC_BACKUP）
			PreparedStatement psAddMatNo = connection
					.prepareStatement(addMatNo);
			String sqlupdateload = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.updateDelCancel");// 修改装车主表确认状态
			PreparedStatement psLoad = connection
					.prepareStatement(sqlupdateload);
			String sqlupdateloadMAT = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.updateMatCancel");// 修改装车材料表状态
			PreparedStatement psLoadMat = connection
					.prepareStatement(sqlupdateloadMAT);
			String insterButtr = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEntruck.AddButtress"); // 新增位置表
			PreparedStatement pstaButtr = connection
					.prepareStatement(insterButtr);
			String deleteOut = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEntruck.deleteOut"); // 删除出库表销售出库对应记录
			PreparedStatement pstaOut = connection.prepareStatement(deleteOut);
			String deleteOutXs = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEntruckXs.deleteOut"); // 删除出库表销售出库对应记录
			PreparedStatement pstaOutXs = connection.prepareStatement(deleteOutXs);
			String deleteProOrd = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.deleteProOrd"); // 回写进程表
			PreparedStatement pstaPro = connection
					.prepareStatement(deleteProOrd);
			/*String deleteWlM = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.deleteWlM"); // 删除物流主表
			PreparedStatement pstaWlM = wlCon.prepareStatement(deleteWlM);
			String deleteWlC = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.deleteWlC"); // 删除物流子表
			PreparedStatement pstaWlC = wlCon
					.prepareStatement(deleteWlC);
			String deleteWlBill = CoreXmlSqlParsersFactory
					.getSql("FrmPipeLoad.deleteWlBill"); // 删除物流费用表
			PreparedStatement pstaWlBill = wlCon
					.prepareStatement(deleteWlBill);*/

			String insertCrmOut = CoreXmlSqlParsersFactory
					.getSql("CrmOutList.insertCrmOutList"); // 新增到crm出库表
			PreparedStatement pstaCrmOut = connection.prepareStatement(insertCrmOut);
			String addCrmMat = CoreXmlSqlParsersFactory
					.getSql("CrmMatZc.insertCrmMatZc_M");//新增crm材料表，取MAT_ZC_M
			PreparedStatement psAddCrmMat = connection.prepareStatement(addCrmMat);

			String delZcOutlist = CoreXmlSqlParsersFactory
					.getSql("FrmPipeEntruck.delZcOutlist"); // 删除财务中间表
			PreparedStatement pstaDelZcOutlist = connection.prepareStatement(delZcOutlist);

			List<YdmZcOutlistEntity1> ydmOut = new ArrayList<YdmZcOutlistEntity1>();
			for (int i = 0; i < list.size(); i++) {
				ydmOut.clear();
				ArrayList<String> list1 = (ArrayList<String>) list.get(i);
				String loadNo = list1.get(0);//装车单号
				String billNo = list1.get(1);//提货单号
				String tallNo = list1.get(2);//理货单号
				String velNo = list1.get(3);//车船号
				String name = list1.get(4);
				String strTime = list1.get(5);
				
				noArr.add(loadNo);

				//判定是否被财务系统接收
				SqlBuilder b = new SqlBuilder("FrmPipeEntruck.getZcOutlist");
				b.Fill(new String[]{ billNo, loadNo, tallNo, velNo });
				YdmZcOutlistEntity zcOutlist = EntityTool.getEntityBySqlNoClsCon(b.toString(), connection, YdmZcOutlistEntity.class);
				if (zcOutlist!=null) {
					cro.setV_errMsg("炉号："+zcOutlist.getJudgeStoveNo()+"批号："+zcOutlist.getBatchNo()+"组号："+zcOutlist.getBatchGroudNo()+"已被财务系统接收，无法取消确认！请联系财务系统相关人员！");
					return cro;
				}
				// 删除财务中间表
				pstaDelZcOutlist.setObject(1,billNo);
				pstaDelZcOutlist.setObject(2,loadNo);
				pstaDelZcOutlist.setObject(3,tallNo);
				pstaDelZcOutlist.setObject(4,velNo);
				pstaDelZcOutlist.setObject(5,billNo);
				pstaDelZcOutlist.addBatch();

				// 判断是否结算
				/*String status = "";
				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.queryWlStatus");
				psta = wlCon.prepareStatement(sqlquery);
				psta.setObject(1, loadNo);
				ResultSet rs1 = psta.executeQuery();
				if (rs1.next()) {
					status = rs1.getString("staus");
				}
				rs1.close();
				psta.close();*/
				/*if (status.equals("1")) {
					cro.setV_errMsg("您选择的记录已结算，不能进行此操作！");
					return cro;
				}*/

				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.queryLoadMatNo");
				psta = connection.prepareStatement(sqlquery);
				psta.setObject(1, loadNo);
				psta.setObject(2, billNo);
				psta.setObject(3, tallNo);
				psta.setObject(4, velNo);
				ResultSet rs = psta.executeQuery();
				ydmOut = EntityTool.getEntitysByRs(rs,
						YdmZcOutlistEntity1.class);
				rs.close();
				psta.close();
				String profalg = "";
				// 判断是否过磅
				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.queryBillCFlag");
				psta = connection.prepareStatement(sqlquery);
				psta.setObject(1, billNo);
				rs = psta.executeQuery();
				if (rs.next()) {
					profalg = rs.getString("PRT_FLAG");
				}
				rs.close();
				psta.close();


				Integer ckjl = 0;
				// 判断出库记录
				sqlquery = CoreXmlSqlParsersFactory
						.getSql("FrmPipeLoad.queryOutlistFlag");
				psta = connection.prepareStatement(sqlquery);
				psta.setObject(1, billNo);
				psta.setObject(2, loadNo);
				psta.setObject(3, tallNo);
				psta.setObject(4, velNo);
				psta.setObject(5, billNo);
				rs = psta.executeQuery();
				if (rs.next()) {
					ckjl = rs.getInt("SL");
				}
				rs.close();
				psta.close();
				if (ckjl <= 0 ) {
					cro.setV_errMsg("未查询到出库记录，请重新查询刷新界面！");
					return cro;
				}

				for (YdmZcOutlistEntity1 com : ydmOut) {
					double count = Double.parseDouble(com.getActCount());
					double wt = 0;
					profalg ="0";
					if (profalg.equals("1")) {

						wt = Double.parseDouble(com.getPonderGrossWt());
					} else {
						wt = Double.parseDouble(com.getActWeight());
					}
					// 新增位置表
					pstaButtr.setString(1, com.getMatNo());
					pstaButtr.setString(2, com.getJudgeStoveNo());
					pstaButtr.setString(3, com.getBatchNo());
					pstaButtr.setString(4, com.getBatchGroudNo());
					pstaButtr.setString(5, com.getStorageNo());
					pstaButtr.setString(6, com.getLocationNo());
					pstaButtr.setObject(7, com.getLaryNo());
					pstaButtr.setObject(8, com.getLocNo());
					pstaButtr.setString(9, com.getStorageAttr());
					pstaButtr.setString(10, com.getStorageAttrName());
					pstaButtr.setString(11, com.getStorageTypeNo());
					pstaButtr.setString(12, com.getStorageTypeName());
					pstaButtr.setString(13, com.getManagementNo());
					pstaButtr.setString(14, com.getManagementName());
					pstaButtr.setString(15, com.getDepartmentCode());
					pstaButtr.setString(16, com.getDepartmentDesc());
					pstaButtr.setString(17, name);
					pstaButtr.setString(18, strNowTime);
					pstaButtr.addBatch();

					// 新增材料表（删除材料表MAT_ZC_BACKUP）
					psAddMatNo.setObject(1, com.getMatNo());
					psAddMatNo.setObject(2, com.getMatNo());
					psAddMatNo.setObject(3, com.getMatNo());
					psAddMatNo.addBatch();

					pstaPro.setObject(1, count);
					pstaPro.setObject(2, wt);
					pstaPro.setObject(3, com.getOrdLnDlyPk());
					pstaPro.addBatch();

					//crm 出库表迁移
					pstaCrmOut.setString(1,com.getLoadvehicleSqe());
					pstaCrmOut.setString(2,billNo);
					pstaCrmOut.setString(3,com.getLoadvehicleNo());
					pstaCrmOut.setString(4,com.getJudgeStoveNo());
					pstaCrmOut.setString(5, com.getBatchNo());
					pstaCrmOut.setString(6, com.getBatchGroudNo());
					pstaCrmOut.setString(7, com.getMaterialNo());
					pstaCrmOut.setString(8, com.getMaterialName());
					pstaCrmOut.setString(9, com.getProduccode());
					pstaCrmOut.setString(10, com.getProducname());
					pstaCrmOut.setString(11, com.getStdCode());
					pstaCrmOut.setString(12, com.getStdName());
					pstaCrmOut.setString(13, com.getGradecode());
					pstaCrmOut.setString(14, com.getGradename());
					pstaCrmOut.setString(15, com.getSteelcode());
					pstaCrmOut.setString(16, com.getSteelname());
					pstaCrmOut.setString(17, com.getStdStyle());
					pstaCrmOut.setString(18, com.getStdStyleDesc());
					pstaCrmOut.setString(19, com.getSpecCode());
					pstaCrmOut.setString(20, com.getSpecName());
					pstaCrmOut.setString(21, com.getModelCode());
					pstaCrmOut.setString(22, com.getModelDesc());
					pstaCrmOut.setString(23, com.getActLenMin());
					pstaCrmOut.setString(24, com.getActLenMax());
					pstaCrmOut.setString(25, com.getActCount());
					pstaCrmOut.setString(26, String.valueOf(wt));
					pstaCrmOut.setString(27, String.valueOf(com.getActLen()));
					pstaCrmOut.setString(28, com.getStorageNo());
					pstaCrmOut.setString(29, com.getStorageNo());
					pstaCrmOut.setString(30, com.getSenTime());
					pstaCrmOut.setString(31, com.getValidflagMat());
					pstaCrmOut.setString(32, com.getOrderNo());
					pstaCrmOut.setString(33, com.getOrderSeq());
					pstaCrmOut.setString(34, com.getDeliveryNo());
					pstaCrmOut.setString(35, com.getOrdPk());
					pstaCrmOut.setString(36, com.getOrdLnPk());
					pstaCrmOut.setString(37, com.getOrdLnDlyPk());
					pstaCrmOut.setString(38,"2");
					pstaCrmOut.setString(39,strNowTime);
					pstaCrmOut.setString(40,billNo);
					pstaCrmOut.setString(41,billNo);
					pstaCrmOut.setString(42,billNo);
					pstaCrmOut.setString(43,"120504".equals(com.getSupplyUnitCode())? ComBaseInfo.GetBalYear_2416(nowTime): ComBaseInfo.GetBalYear(nowTime));
					pstaCrmOut.setString(44,com.getActDimater());
					pstaCrmOut.setString(45,com.getActHeight());
					pstaCrmOut.setString(46,com.getBelongCode());
					pstaCrmOut.setString(47,com.getBelongName());
					pstaCrmOut.setString(48,"800805");
					pstaCrmOut.setString(49,"销售出库");
					pstaCrmOut.addBatch();

					// 新增crm材料表
					psAddCrmMat.setObject(1, "0");
					psAddCrmMat.setObject(2, strNowTime);
					psAddCrmMat.setObject(3, com.getMatNo());
					psAddCrmMat.addBatch();
				}
				pstaPro.executeBatch();
				pstaCrmOut.executeBatch();

				pstaOut.setObject(1, billNo);
				pstaOut.setObject(2, loadNo);
				pstaOut.setObject(3, tallNo);
				pstaOut.setObject(4, velNo);
				pstaOut.setObject(5, billNo);
				pstaOut.addBatch();
				
				pstaOutXs.setObject(1, billNo);
				pstaOutXs.setObject(2, loadNo);
				pstaOutXs.setObject(3, tallNo);
				pstaOutXs.setObject(4, velNo);
				pstaOutXs.setObject(5, billNo);
				pstaOutXs.addBatch();

				psLoad.setObject(1, loadNo);
				psLoad.addBatch();

				psLoadMat.setObject(1, loadNo);
				psLoadMat.addBatch();
				
				/*pstaWlM.setObject(1, loadNo);
				pstaWlM.addBatch();
				
				pstaWlC.setObject(1, loadNo);
				pstaWlC.addBatch();
				
				pstaWlBill.setObject(1, loadNo);
				pstaWlBill.addBatch();*/
				//接口数据上传到产销
				JSONObject jsonObject =  new JSONObject();
				   jsonObject.put("outbill_no",  loadNo);
				   jsonObject.put("op_flag", "D");
				   jsonObject.put("form_code","MESTHSO07");
				   jsonObject.put("form_name", "取消发货实绩");
				   DefaultWebServiceRequest request = new DefaultWebServiceRequest();
				   request.setMsgBody(jsonObject.toString());
				   request.setServiceId("MESTHSO07");
				   String result = ServiceToCx.callWebserviceASMX("http://172.54.10.24:8191/ReceiverService.asmx",request,
							"receiveMessage",jsonObject.toString());	
				   if(!result.equals("200")) {
					    cro.setV_errMsg("取消发货实绩失败！");
						cro.setResult(1);
					    return cro;
				   }


				// 暂时注释：20241024刘侣
				psta = connection.prepareStatement("select to_char(ACT_END_TIME,'yyyy-MM-dd HH24:mi:ss') ACT_END_TIME,\n" +
					"ACT_NUM,to_char(ACT_START_TIME,'yyyy-MM-dd HH24:mi:ss') ACT_START_TIME,\n" +
					"ACT_TOTL_LEN,ACT_TOTL_LEN_TEMP,ACT_TRANS_TYPE,ACT_WT,AGENCY_FL,ASK_ITEM_NO,\n" +
					"BAL_YEAR_MONTH,BILL_NO,BILL_NO_SEQ,BILL_STATUS,BILL_TICKET_AFFRIM_NAME,\n" +
					"to_char(BILL_TICKET_AFFRIM_TIME,'yyyy-MM-dd HH24:mi:ss') BILL_TICKET_AFFRIM_TIME\n" +
					",BILL_TICKET_STATUS,CARRY_COMPANY_CODE,CARRY_COMPANY_NAME,CHECK_NO,CREATE_NAME,\n" +
					"to_char(CREATE_TIME,'yyyy-MM-dd HH24:mi:ss') CREATE_TIME,CREDIT_NO,CUSTOMER_NM,\n" +
					"CUSTOMER_NO,DELETE_NAME,to_char(DELETE_TIME,'yyyy-MM-dd HH24:mi:ss') DELETE_TIME\n" +
					",DELIVERY_NO,DELIVY_PLACE_CODE,DELIVY_PLACE_NAME,DELVRY_ADDR,DELVRY_WHEREABOUTS,\n" +
					"DEPARTMENT_CODE,DEPARTMENT_DESC,EXTRA_FLAG,FLAG_LEN,FST_DRAWEE_UNIT,IS_OVERSTOCK\n" +
					",ISPRECLOSE,ITEM_NO,LANGUAGE_CODE,LANGUAGE_NAME,LET_DELIVERY_FLAG,LICENSE_NO,\n" +
					"LOADVEHICLE_TYPE,LOCK_BILL_FLAG,MANAGEMENT_NAME,MANAGEMENT_NO,MEMO,METRIC_SYSTEM\n" +
					",ORD_LN_DLY_PK,ORD_LN_PK,ORD_PK,ORDER_NO,ORDER_SEQ,OUTSTOCK_TICKET_AFFRIM_NAME,\n" +
					"to_char(OUTSTOCK_TICKET_AFFRIM_TIME,'yyyy-MM-dd HH24:mi:ss') OUTSTOCK_TICKET_AFFRIM_TIME\n" +
					",OUTSTOCK_TICKET_STATUS,PICKUP_FLAG,to_char(PLAN_END_TIME,'yyyy-MM-dd HH24:mi:ss') PLAN_END_TIME\n" +
					",PLAN_NUM,to_char(PLAN_START_TIME,'yyyy-MM-dd HH24:mi:ss') PLAN_START_TIME,\n" +
					"PLAN_TOTL_LEN,PLAN_TOTL_LEN_TEMP,PLAN_TRANS_TYPE,PLAN_WT,PORT_DESC,PORT_NO,PRD_CLS\n" +
					",PRINT_FLAG,PRINT_NUM,PRINT_NUMBER,to_char(PRINT_TIME,'yyyy-MM-dd HH24:mi:ss') PRINT_TIME\n" +
					",PRODUCCODE,PRODUCNAME,REALINVOICENO,REALINVOICENO1,\n" +
					"to_char(REALINVOICENO_DATE,'yyyy-MM-dd HH24:mi:ss') REALINVOICENO_DATE,RECEIV_ADDR\n" +
					",RECEIV_NM,RECEIV_NO,RETURN_FLAG,SALE_ORG,SALE_ORG_DESC,SEND_PLAN_NO,SINGLE_NO,\n" +
					"SPCL_LN_NM,SPCL_LN_NO,SPEC_CODE,SPEC_NAME,STATION_NM,STATION_NO,STD_CODE,STD_NAME\n" +
					",STEELCODE,STEELNAME,STLMT_UNIT_NM,STLMT_UNIT_NO,STOVE_TICKET_FLAG,SUPPLY_UNIT,\n" +
					"SUPPLY_UNIT_DESC,TRANSMNY_TICKET_AFFRIM_NAME,\n" +
					"to_char(TRANSMNY_TICKET_AFFRIM_TIME,'yyyy-MM-dd HH24:mi:ss') TRANSMNY_TICKET_AFFRIM_TIME\n" +
					",TRANSMNY_TICKET_STATUS,UPDATE_NAME,to_char(UPDATE_TIME,'yyyy-MM-dd HH24:mi:ss') UPDATE_TIME\n" +
					",VALIDFLAG,VSTEL_CODE,VSTEL_DESC,WIND_UP_FLAG,ZBS_FLAG,ZBS_NAME,ZBS_NUM,ZBS_ORDER_NO\n" +
					",ZBS_ORDER_NO_NAME,to_char(ZBS_ORDER_NO_TIME,'yyyy-MM-dd HH24:mi:ss') ZBS_ORDER_NO_TIME\n" +
					",ZBS_PATH,ZBS_SOURCE,to_char(ZBS_TIME,'yyyy-MM-dd HH24:mi:ss') ZBS_TIME,\n" +
					"ZBS_TYPE_CODE,ZBS_TYPE_DESC,ZOUT_FLAG\n" +
					"from YDM_ZC_BILL_M where BILL_NO = ? and VALIDFLAG = '1' order by CREATE_TIME desc ");

				psta.setString(1, billNo);

				rs = psta.executeQuery();

				JSONObject bill = new JSONObject();
				while (rs.next()) {
					bill.put("customerNm", rs.getString("CUSTOMER_NM"));
				}
				psta.close();
				rs.close();

				// 暂时注释：20241024刘侣 按照肖的要求 没必要撤回
				if (!"".equals(bill.getString("customerNm")) && bill.getString("customerNm").contains("天津钢管制造")) {
					// 暂时注释：20240926刘侣
					// 发送取消装车到天管：
					String resultZC = HttpConnectionLL.deleteJsonParams("http://172.50.202.90:9003/v1/ydmzcloadvehicles/" + loadNo);
//					System.out.println(resultZC);
					if ("".equals(resultZC)) {
						logSave(connection, "cancelload", loadNo, loadNo, "result未返回结果");
						//throw new Exception("未返回结果");
					}else{
						JSONObject resObjZC = JSONObject.fromObject(resultZC);
						if ("500".equals(resObjZC.getString("code"))) {
							logSave(connection, "cancelload", loadNo, loadNo, "装车信息撤回失败");
							//throw new Exception("取消装车信息：" + loadNo + " 发送至天管系统失败");
						} else {
							logSave(connection, "cancelload", loadNo, loadNo, "装车信息撤回成功");
						}
					}


					// 发送取消提单到天管： 取消装车不再删掉整个提单，而是在每次发送提单到天管时先删后推送 20241111 刘侣
//					String resultTD = HttpConnectionLL.deleteJsonParams("http://172.50.202.90:9003/v1/ydmzcbills/" + billNo);
////					System.out.println(resultTD);
//					if ("".equals(resultTD)) {
//						logSave(connection, "cancelload", loadNo, loadNo, "result未返回结果");
//						//throw new Exception("未返回结果");
//					}else{
//						JSONObject resObjTD = JSONObject.fromObject(resultTD);
//						if ("500".equals(resObjTD.getString("code"))) {
//							logSave(connection, "cancelload", loadNo, loadNo, "result未返回结果");
//							//throw new Exception("取消提单信息：" + billNo + " 发送至天管系统失败");
//						}
//					}

					// end
				}

			}
				/*sqlquery = "select t.* from YDM_ZC_LOADVEHICLE where LOADVEHICLE_NO = '"+loadNo+"'";
				psta = connection.prepareStatement(sqlquery);
				ResultSet rs2 = psta.executeQuery();
				if(rs2.next()) {
					String sqlquerys = "select t.* from YDM_ZC_LOADVEHICLE_MAT where LOADVEHICLE_NO = '"+loadNo+"'";
					PreparedStatement pstas = connection.prepareStatement(sqlquerys);
					ResultSet rs3 = pstas.executeQuery();
					List<YdmZcLoadvehicleEntity> zcLoad = EntityTool.getEntitysByRs(rs2,
							YdmZcLoadvehicleEntity.class);
					List<YdmZcMatEntityForWl> zcMatLoad = EntityTool.getEntitysByRs(rs3,
							YdmZcMatEntityForWl.class);
					
					if(zcLoad.get(0).getLoadvehicleNo().equals(zcMatLoad.get(0).getLoadvehicleNo())
							&& zcLoad.get(0).getTallysheetNo().equals(zcMatLoad.get(0).getTallysheetNo())
							&& zcLoad.get(0).getBillNo().equals(zcMatLoad.get(0).getBillNo())) {
						   
					}
					
				}
			}*/
			pstaDelZcOutlist.executeBatch();
			pstaButtr.executeBatch();
			pstaOut.executeBatch();
			pstaOutXs.executeBatch();
			psLoad.executeBatch();
			psLoadMat.executeBatch();
			psAddMatNo.executeBatch();
			psAddCrmMat.executeBatch();


			/*pstaWlM.executeBatch();
			pstaWlC.executeBatch();
			pstaWlBill.executeBatch();*/
			cro.setV_errMsg("取消确认成功！");
			cro.setResult(1);
			connection.commit();
			//wlCon.commit();
		} catch (Exception e) {
			cro.setV_errMsg(e.getMessage());
			cro.setV_errCode(-1);
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
			/*if (wlCon != null) {
				try {
					wlCon.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}*/
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
				/*if (wlCon != null && !wlCon.isClosed()) {
					wlCon.close();
				}*/
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/**
	 * 查询确认标志
	 * 
	 * @param list
	 *            传递参数
	 * @return obj
	 */
	public CoreReturnObject queryAppFlag(String list) {
		return this.getDataBySqlID("FrmPipeLoad.queryAppFlag",
				new Object[] { list });
	}

	/**
	 * 查询销售结算标志
	 * 
	 * @param list
	 *            传递参数
	 * @return obj
	 */
	public CoreReturnObject queryVelFalg(String list) {
		return this.getDataBySqlID("FrmPipeLoad.queryVelFalg",
				new Object[] { list });
	}

	/**
	 * 查询提单表状态
	 * 
	 * @param
	 *
	 * @return obj
	 */
	public CoreReturnObject queryBillType(String billType) {
		return this.getDataBySqlID("FrmPipeLoad.QueryBillType",
				new Object[] { billType });
	}

	/**
	 * 确认是查询是否输入过磅单号，过磅重量
	 * 
	 * @param
	 *
	 * @return obj
	 */
	public CoreReturnObject queryTallPond(String pond) {
		return this.getDataBySqlID("FrmPipeLoad.queryTallPond",
				new Object[] { pond });
	}

	/**
	 * 确认是查询是否输入过磅单号，过磅重量
	 * 
	 * @param list
	 *            传递参数
	 * @return obj
	 */
	public CoreReturnObject queryTallPond1(ArrayList<String> list) {
		return this
				.getDataBySqlID("FrmPipeLoad.queryTallPond1", list.toArray());
	}

	/***
	 * 查询炉批是否结转
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject selectYearMoth(ArrayList<String> list) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPipeLoad.selectYearMoth");
		return this.getData(sql, list.toArray());
	}
}
