package com.steering.pss.plnsaleord.order;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.math.BigDecimal;
import java.math.RoundingMode;
import javax.script.ScriptException;

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

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.base.CorePlnComm;
import com.steering.pss.plnsaleord.ordAmCal.PlnProducCal;
import com.steering.pss.plnsaleord.ordAmCal.model.InOrdParamEntity;
import com.steering.pss.plnsaleord.ordAmCal.model.OutOrdParamEntity;
import com.steering.pss.plnsaleord.order.baseMethod.CoreDefGourp;
import com.steering.pss.plnsaleord.order.baseMethod.CoreGetOrdAmount;
import com.steering.pss.plnsaleord.order.baseMethod.CoreOrdBase;
import com.steering.pss.plnsaleord.order.baseMethod.CoreOrderStdSic;
import com.steering.pss.plnsaleord.order.model.PlnOrderJgEntity;
import com.steering.pss.plnsaleord.order.model.PlnPorderBlReqEntity;
import com.steering.pss.plnsaleord.order.model.PlnSaleordEntity;
import com.steering.pss.plnsaleord.order.model.PlnSaleordProcEntity;
import com.steering.pss.sale.order.bomGeneration.model.BomEntity;
import com.steering.pss.sale.order.bomGeneration.server.BomMaterial;

/**
 * 排产合同接箍短节处理
 * 
 * @author xiaohai
 */
public class CorePlnOrdJgDjDeal extends DBCommon {
	/**
	 * 查询销售合同
	 * 
	 * @param list
	 *            查询参数
	 * @return object
	 */
	public CoreReturnObject querySaleOrder(ArrayList<Object> list) {
		CoreReturnObject cro = null;

		String sql = CoreXmlSqlParsersFactory.getSql("CorePlnOrdJgDjDeal.querySaleOrder");
		if(!list.get(0).equals(""))
		{
			sql += " AND T.ROLL_MONTH = '"+list.get(0)+"'";

		}
		list.remove(0);
		if(!list.get(0).equals(""))
		{
			sql += " AND T.ACCEPT_NO = '"+list.get(0)+"'";
		}
		list.remove(0);
		cro = this.getData(sql, list
				.toArray());
		return cro;
	}

	/**
	 * 查询销售合同状态
	 * 
	 * @param
	 *
	 * @return object
	 */
	public CoreReturnObject querySaleStatus(String ordLnDlyPk) {
		CoreReturnObject cro = new CoreReturnObject();
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.querySaleStatus",
				new Object[] { ordLnDlyPk });
		return cro;
	}

	/**
	 * 查询短节合同状态
	 * 
	 * @param ordLnDlyPk
	 * @return
	 */
	public CoreReturnObject selectBlReqStatusByPk(String ordLnDlyPk) {
		CoreReturnObject cro = new CoreReturnObject();
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.selectBlReqStatusByPk",
				new Object[] { ordLnDlyPk });
		return cro;
	}

	/**
	 * 查询短节备料需求信息
	 * 
	 * @return object
	 */
	public CoreReturnObject queryDjBlNeed(ArrayList<Object> list) {
		CoreReturnObject cro = null;
		String sql  = CoreXmlSqlParsersFactory.getSql("CorePlnOrdJgDjDeal.queryDjBlNeed");
		if(!list.get(0).equals(""))
		{
			sql += " AND NVL(T1.ROLL_MONTH, '1') LIKE '%' || NVL('"+list.get(0)+"', '1') || '%' ";
		}
		if(!list.get(1).equals(""))
		{
			sql+= " AND NVL(T1.ACCEPT_NO, '1') LIKE '%' || NVL(NLS_UPPER('"+list.get(1)+"'), '1') || '%'";
		}
		if(!list.get(2).equals(""))
		{
			sql += " AND (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || NLS_UPPER('"+list.get(2)+"') || '%' ";
		}
		if(!list.get(3).equals(""))
		{
			sql += " AND T1.PORDERSTATUS LIKE '%' || '"+list.get(3)+"' || '%'";
		}
		if(!list.get(4).equals(""))
		{
			sql+= " AND DECODE('"+list.get(4)+"', '1', T1.JGORD_IS_OK, 1) != DECODE('"+list.get(5)+"', '1', '2', 2)";
		}
		if(!list.get(6).equals(""))
		{
			sql += " AND DECODE('"+list.get(6)+"', '1', T1.DJBL_REQ_IS_OK, 1) != DECODE('"+list.get(7)+"', '1', '2', 2)";
		}
		return  this.getData(sql);
//		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.queryDjBlNeed", list
//				.toArray());
//		return cro;
	}

	/**
	 * 修改短节备料需求
	 * 
	 * @param list
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject doUpdateDjBl(ArrayList<Object> list) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			String sqlUpdate = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.DoUpdateDjBl");
			PreparedStatement psta = conn.prepareStatement(sqlUpdate);
			for (int i = 0; i < list.size(); i++) {
				ArrayList<String> list1 = (ArrayList<String>) list.get(i);
				double aimwallthick = Double.parseDouble(list1.get(0));// 控制壁厚
				double lengthmax = Double.parseDouble(list1.get(1));// 最大长度
				double lengthmin = Double.parseDouble(list1.get(2));// 最小长度
				double aimlength = Double.parseDouble(list1.get(3));// 控制长度
				double jgblReqNum = Integer.parseInt(list1.get(4));// 备料需求支数
				double outdiameter = Double.parseDouble(list1.get(6));// 备料外径
				// 米单重
				double weight_one = 0.02466 * aimwallthick
						* (outdiameter - aimwallthick);
				// 备料单重
				double SingleWeight = weight_one * aimlength / 1000;
				// 备料需求重量（总重）
				double jgblReqWeight = SingleWeight * jgblReqNum;
				BigDecimal bgsingleWeight = new BigDecimal(SingleWeight)
						.setScale(3, RoundingMode.UP);
				BigDecimal bgjgblReqWeight = new BigDecimal(jgblReqWeight)
						.setScale(3, RoundingMode.UP);
				String reqBlId = list1.get(5);// 备料需求号
				String updateName = list1.get(7);// 修改人
				String updateTime = list1.get(8);// 修改时间
				// 查询短节备料需求状态
				String djBlStrat = "";
				String sqlselect = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.selectDjBl");
				ps = conn.prepareStatement(sqlselect);
				ps.setObject(1, reqBlId);
				ResultSet rs = ps.executeQuery();
				if (rs.next()) {
					djBlStrat = rs.getString("PLANSTATUS");
				}
				rs.close();
				ps.close();
				if (!djBlStrat.equals("0")) {
					cro.setV_errMsg("该短节备料需求已不是【待处理】状态！");
					return cro;
				}

				psta.setObject(1, aimwallthick);
				psta.setObject(2, lengthmax);
				psta.setObject(3, lengthmin);
				psta.setObject(4, aimlength);
				psta.setObject(5, jgblReqNum);
				psta.setObject(6, bgsingleWeight);
				psta.setObject(7, bgjgblReqWeight);
				psta.setObject(8, updateName);
				psta.setObject(9, updateTime);
				psta.setObject(10, reqBlId);
				psta.addBatch();
			}
			psta.executeBatch();
			cro.setV_errMsg("修改短节备料需求成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 查询接箍合同
	 * 
	 * @return object
	 */
	public CoreReturnObject queryJgOrder(ArrayList<Object> list) {
		CoreReturnObject cro = null;
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.queryJgOrder", list
				.toArray());
		return cro;
	}

	/**
	 * 接箍处理
	 * 
	 * @param list
	 * @param createMan
	 * @return
	 */
	public CoreReturnObject tranSactionJg(ArrayList<String> list,
			String createMan) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			String errMessage = "";
			int errNum = 0;
			for (String ordLnDlyPk : list) {
				String[] message = new String[1];
				PreparedStatement ps = null;
				String sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.querySaleStatus");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, ordLnDlyPk);
				ResultSet rs = ps.executeQuery();
				if (rs.next()) {
					String orderNO = rs.getString("ORDER_NO");
					String orderSeq = rs.getString("ORDER_SEQ");
					String deliveryNo = rs.getString("DELIVERY_NO");
					if (rs.getString("PORDERSTATUS").compareTo("1") < 0) {
						errNum++;
						errMessage = "合同：" + orderNO + "/" + orderSeq + "/"
								+ deliveryNo + "未接收或者已经退回！";
						continue;
					}
//					if (rs.getString("PORDERSTATUS").compareTo("3") > 0) {
//						errNum++;
//						errMessage = "合同：" + orderNO + "/" + orderSeq + "/"
//								+ deliveryNo + "已经生产完了！";
//						continue;
//					}
					if (rs.getString("JGORD_IS_OK").equals("1")) {
						errNum++;
						errMessage = "合同：" + orderNO + "/" + orderSeq + "/"
								+ deliveryNo + "已处理接箍！";
						continue;
					}
					if (rs.getString("JGORD_IS_OK").equals("2")) {
						errNum++;
						errMessage = "合同：" + orderNO + "/" + orderSeq + "/"
								+ deliveryNo + "没有接箍！";
						continue;
					}
					if (rs.getInt("ORDERNUM") == 0) {
						errNum++;
						errMessage = "合同：" + orderNO + "/" + orderSeq + "/"
								+ deliveryNo + "合同计划支数未知，请检查合同信息！";
						continue;
					}
					if (rs.getString("DESGIN_KEY") == null) {
						errNum++;
						errMessage = "合同行：" + orderNO + "/" + orderSeq
								+ "未找到有效工艺制定数据！";
						continue;
					}
					if (!dealJgOrd(conn, ordLnDlyPk, createMan, message)) {
						errNum++;
						errMessage = message[0];
						continue;
					}
				}
				rs.close();
				ps.close();
				conn.commit();
			}
			cro.setResult((list.size() - errNum) + "条操作成功，" + errNum
					+ "条操作失败。\n" + errMessage);
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 撤销接箍合同
	 * 
	 * @param list
	 * @param operaMan
	 * @return
	 */
	public CoreReturnObject cancelJg(ArrayList<String> list, String operaMan) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			String errMessage = "";
			int errNum = 0;

			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			for (String ordLnDlyPk : list) {
				PreparedStatement ps = null;
				String sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.querySaleStatus");
				String sqle = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.queryRelbyPlnOrd");
				String sqlDel = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.RollbackJg");
				String sqlOrd = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.updateJgSaleorder");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, ordLnDlyPk);
				ResultSet rs = ps.executeQuery();
				if (rs.next()) {
					PreparedStatement pst = null;
					String orderNO = rs.getString("ORDER_NO");
					String orderSeq = rs.getString("ORDER_SEQ");
					String deliveryNo = rs.getString("DELIVERY_NO");
					if (rs.getString("PORDERSTATUS").compareTo("1") < 0) {
						errNum++;
						errMessage = "合同：" + orderNO + "/" + orderSeq + "/"
								+ deliveryNo + "未接收或者已经退回！";
						continue;
					}
					if (rs.getString("PORDERSTATUS").compareTo("5") > 0) {
						errNum++;
						errMessage = "合同：" + orderNO + "/" + orderSeq + "/"
								+ deliveryNo + "已经生产完了！";
						continue;
					}
					if (!rs.getString("JGORD_IS_OK").equals("1")) {
						errNum++;
						errMessage = "合同：" + orderNO + "/" + orderSeq + "/"
								+ deliveryNo + "没有接箍合同！";
						continue;
					}

					pst = conn.prepareStatement(sqle);
					pst.setObject(1, ordLnDlyPk);
					ResultSet rsl = pst.executeQuery();
					if (rsl.next()) {
						errNum++;
						if (rsl.getString("JG_ORDERNO") != null) {
							errMessage = "接箍合同：" + rsl.getString("JG_ORDERNO")
									+ "已组订单！";
						}
						continue;
					}
					rsl.close();
					pst.close();

					pst = conn.prepareStatement(sqlDel);
					pst.setObject(1, ordLnDlyPk);
					pst.executeUpdate();
					pst.close();

					pst = conn.prepareStatement(sqlOrd);
					pst.setObject(1, "0");
					pst.setObject(2, "0");
					pst.setObject(3, ordLnDlyPk);
					pst.executeUpdate();
					pst.close();
				}
				rs.close();
				ps.close();
			}
			conn.commit();
			cro.setResult((list.size() - errNum) + "条操作成功，" + errNum
					+ "条操作失败。\n" + errMessage);
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 排产合同接箍合同制定
	 * 
	 * @param conn
	 * @param ordLnDlyPk
	 * @param createName
	 * @throws SQLException
	 */
	public static boolean dealJgOrd(Connection conn, String ordLnDlyPk,
			String createName, String[] message) throws SQLException {
		PreparedStatement ps = null;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CorePlnOrdJgDjDeal.queryCrfatDesgin");
		String sqlAdd = CoreXmlSqlParsersFactory
				.getSql("CorePlnOrdJgDjDeal.addJgOrd");
		String sqlOrd = CoreXmlSqlParsersFactory
				.getSql("CorePlnOrdJgDjDeal.updateJgSaleorder");
		ps = conn.prepareStatement(sql);
		ps.setObject(1, ordLnDlyPk);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			if (rs.getString("ORDER_NO") == null
					|| rs.getString("ORDER_SEQ") == null
					|| rs.getString("DELIVERY_NO") == null) {
				return false;
			}
			String orderNo = rs.getString("ORDER_NO");
			String orderSeq = rs.getString("ORDER_SEQ");
			String deliveryNo = rs.getString("DELIVERY_NO");

			if (rs.getString("DESGIN_KEY") == null) {
				message[0] = "未找到合同行" + orderNo + "/" + orderSeq + "有效工艺的制定数据！";
				return false;
			}

			PreparedStatement pst = null;
			String desginKey = rs.getString("DESGIN_KEY");
			int serialNum = 0;
			int ordNum = rs.getInt("ORDERNUM")
					+ (int) Math.ceil(rs.getInt("ORDERNUM")
							* rs.getDouble("DELVRY_RANGE_MAX") / 100);

			sql = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.queryCrfatMscJg");
			pst = conn.prepareStatement(sql);
			pst.setObject(1, desginKey);
			ResultSet rst = pst.executeQuery();
			if (!rst.next()) {
				message[0] = "合同行" + orderNo + "/" + orderSeq + "未找到有效的接箍码！";
				return false;
			}
			rst.close();
			pst.close();

			// 是否存在接箍合同
			sql = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.queryJgOrdSerialNum");
			pst = conn.prepareStatement(sql);
			pst.setObject(1, orderNo);
			pst.setObject(2, orderSeq);
			pst.setObject(3, deliveryNo);
			rst = pst.executeQuery();
			if (rst.next()) {
				// message[0] = "合同行" + orderNo + "/" + orderSeq + "/" +
				// deliveryNo
				// + "接箍合同已经形成过了！";
				return true;
			}
			rst.close();
			pst.close();

			sql = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.queryCrfatMscJg");
			pst = conn.prepareStatement(sql);
			pst.setObject(1, desginKey);
			rst = pst.executeQuery();
			while (rst.next()) {
				if (rst.getString("CODE_JG") == null
						|| rst.getString("CODE_JG").equals("")) {
					message[0] = "合同行" + orderNo + "/" + orderSeq + "接箍码不能为空！";
					return false;
				}
				PlnOrderJgEntity jgOrd = new PlnOrderJgEntity();
				String jgOrdNo = "";
				String codeJg = rst.getString("CODE_JG");
				double weightJg = rst.getDouble("WEIGHT_JG");
				double weightOrd = weightJg * ordNum / 1000;
				serialNum++;
				jgOrdNo = orderNo
						+ orderSeq
						+ deliveryNo
						+ "_G"
						+ CorePlnComm
								.padding(String.valueOf(serialNum), '0', 2);

				// 接箍监制
				String prdcrNo = "";
				String monitordemand = "";
				if (rs.getString("PRDCR_NO") != null) {
					prdcrNo = rs.getString("PRDCR_NO");
					sql = CoreXmlSqlParsersFactory
							.getSql("CorePlnOrdJgDjDeal.queryPrdcrLst");
					PreparedStatement pst1 = conn.prepareStatement(sql);
					pst1.setObject(1, prdcrNo);
					pst1.setObject(2, codeJg);
					ResultSet rst1 = pst1.executeQuery();
					if (rst1.next()) {
						if (rst1.getString("PRDCR_PRC_DESC") != null) {
							monitordemand = rst1.getString("PRDCR_PRC_DESC");
						}
					}
					rst1.close();
					pst1.close();
				}

				jgOrd.setJgOrderno(jgOrdNo);
				jgOrd.setOrderNo(orderNo);
				jgOrd.setOrderSeq(orderSeq);
				jgOrd.setDeliveryNo(deliveryNo);
				jgOrd.setOrderweight(String.valueOf(weightOrd));
				jgOrd.setOrdernum(String.valueOf(ordNum));
				jgOrd.setCodeJg(codeJg);
				jgOrd.setPrdcrNo(prdcrNo);
				jgOrd.setCreateName(createName);
				jgOrd.setMonitordemand(monitordemand);
				jgOrd.setOrdLnDlyPk(ordLnDlyPk);
				if (rst.getString("DEMAND_DETECTION") != null) {
					jgOrd.setDemandDetection(rst.getString("DEMAND_DETECTION"));
				}
				if (rst.getString("DEMAND_BONDERIZING") != null) {
					jgOrd.setDemandBonderizing(rst
							.getString("DEMAND_BONDERIZING"));
				}
				if (rst.getString("DEMAND_COPPER") != null) {
					jgOrd.setDemandCopper(rst.getString("DEMAND_COPPER"));
				}
				if (rst.getString("DEMAND_BLAST") != null) {
					jgOrd.setDemandBlast(rst.getString("DEMAND_BLAST"));
				}
				if (rst.getString("KEY_JG") != null) {
					jgOrd.setKeyJg(rst.getString("KEY_JG"));
				}
				// else {
				// message[0] = "合同:" + orderNo + "/" + orderSeq + "/"
				// + deliveryNo + "未找到接箍Key，无法确定四项要求内容。";
				// return false;
				// }

				if (!prdcrNo.equals("")) {
					jgOrd.setIfMonitorJg("1");
				} else {
					jgOrd.setIfMonitorJg("0");
				}

				// 新增接箍合同
				PreparedStatement psta = null;
				String sqlUp = EntityTool.fillSqlByEntity(sqlAdd, jgOrd);
				psta = conn.prepareStatement(sqlUp);
				psta.executeUpdate();
				psta.close();
			}
			rst.close();
			pst.close();

			pst = conn.prepareStatement(sqlOrd);
			pst.setObject(1, "1");
			pst.setObject(2, "0");
			pst.setObject(3, ordLnDlyPk);
			pst.executeUpdate();
			pst.close();
		}
		rs.close();
		ps.close();
		return true;
	}

	/**
	 * 短节备料处理
	 * 
	 * @param listBL
	 *            短节备料信息
	 * @param param
	 *            合同更新信息
	 * @return object
	 */
	public CoreReturnObject tranSactionDj(
			ArrayList<PlnPorderBlReqEntity> listBL,
			ArrayList<ArrayList<String>> param) {
		CoreReturnObject cro = new CoreReturnObject();
		ArrayList<String> sqllist = new ArrayList<String>();
		ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("CorePlnOrdJgDjDeal.SavePretreatBL");
		for (int i = 0; i < listBL.size(); i++) {
			String sqlAdd = EntityTool.fillSqlByEntity(sql, listBL.get(i));
			sqllist.add(sqlAdd);
			parmlist.add(new Object[] {});
		}
		for (int i = 0; i < param.size(); i++) {
			sqllist.add(CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.updateDjSaleorder"));
			parmlist.add(param.get(i).toArray());
		}

		cro = this.setData(sqllist, parmlist);
		return cro;
	}

	/**
	 * 更新短节备料组
	 * 
	 * @param list
	 *            短节备料组
	 * @return Object
	 */
	public CoreReturnObject updateDjBlGroup(ArrayList<String> list) {
		CoreReturnObject cro = new CoreReturnObject();
		cro = this.setDataBySqlID("CorePlnOrdJgDjDeal.updateDjBlGroup", list
				.toArray());
		return cro;
	}

	/**
	 * 撤消短节合同
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject doCancelDj(ArrayList<ArrayList<Object>> list) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			ArrayList<String> message = new ArrayList<String>();
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			for (int i = 0; i < list.size(); i++) {
				PreparedStatement ps = null;
				String sqle = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.RollbackDj");
				String sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.selectBlReqStatusByPk");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, list.get(i).get(0).toString());
				ResultSet rst = ps.executeQuery();
				String reQbLiD = "";
				while (rst.next()) {
					if (rst.getString("PLANSTATUS") != null
							&& !rst.getString("PLANSTATUS").trim().equals("0")) {
						message.add("备料需求" + rst.getString("REQ_BL_ID")
								+ "已经确认。");
						break;
					}
					reQbLiD = rst.getString("REQ_BL_ID");
				}
				rst.close();
				ps.close();

				// 删除备料需求
				ps = conn.prepareStatement(sqle);
				ps.setObject(1, reQbLiD.trim());
				ps.executeUpdate();
				ps.close();

				// 回写交货行表
				sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.updateDjSaleorder");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, "0");
				ps.setObject(2, list.get(i).get(0));
				ps.executeUpdate();
				ps.close();
			}
			conn.commit();
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 接箍料及短节备料确认
	 * 
	 * @param list
	 * @return
	 * @throws ScriptException
	 */
	public CoreReturnObject doConfirmBl(ArrayList<PlnPorderBlReqEntity> list,
			String creatName) throws ScriptException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			String acceptNo = "";
			ArrayList<String> message = new ArrayList<String>();
			String sqlNew = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.addPlnSaleOrdBl");
			String sqlPrc = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.addBlReqOrderPrc");
			String sqlblUp = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.updateBlReqInfo");
			String sqlAcp = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.getAcceptNum");
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);

			PreparedStatement pst = conn.prepareStatement(sqlAcp);
			ResultSet rst = pst.executeQuery();
			if (rst.next()) {
				if (rst.getString("ACCEPTNO") != null) {
					acceptNo = rst.getString("ACCEPTNO");
				}
			}
			rst.close();
			pst.close();

			for (PlnPorderBlReqEntity blReqEntity : list) {
				String codeBl = "";
				String unitDescProcess = "";// 科室
				String departname = "";// 部门
				String desginKey = "";
				PreparedStatement ps = null;
				ResultSet rs = null;
				String sql = "";
				String sqlAdd = "";
				String sqlUp = "";
				String sqlAddSale = "";
				String[] blMaterial = null;
				String[] ordNoSeq = null;
				String blReqId = blReqEntity.getReqBlId();
				PlnSaleordEntity ordEntity = new PlnSaleordEntity();
				PlnSaleordProcEntity ordProcEntity = new PlnSaleordProcEntity();
				sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.queryPlnBlReqStatus");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, blReqEntity.getReqBlId());
				rs = ps.executeQuery();
				blReqEntity = EntityTool.getEntityByRs(rs,
						PlnPorderBlReqEntity.class);
				if (blReqEntity == null) {
					message.add("未找到编号为：" + blReqId + "的备料需求。");
					continue;
				}
				if (!blReqEntity.getPlanstatus().equals("0")) {
					message.add("需求：" + blReqEntity.getReqBlId() + "已经确认过了。");
					continue;
				}
				rs.close();
				ps.close();

				ordEntity.setLengthmax(blReqEntity.getLengthmax());
				ordEntity.setLengthmin(blReqEntity.getLengthmin());
				ordEntity.setOrdLnDlyPk(blReqEntity.getReqBlId());
				ordProcEntity.setOrdLnDlyPk(blReqEntity.getReqBlId());
				if (blReqEntity.getCodeDjBl().trim().equals("")) {
					codeBl = blReqEntity.getCodeJgBl();
				} else {
					codeBl = blReqEntity.getCodeDjBl();
				}
				ordEntity.setOrdLnPk(codeBl);
				ordEntity.setOrdPk(codeBl);
				ordEntity.setAcceptNo(acceptNo);

				/* 获取监制编号 */
				String sqlPRDCR = "";
				if (blReqEntity.getBltype().equals("接箍料")) {
					sqlPRDCR = "select PRDCR_NO,PRDCR_DESC from SLM_ORDER_LINE_PRDCR where PRDCR_NO=(select max(t.PRDCR_NO) PRDCR_NO from PLN_ORDER_JG t where PRO_PLAN_ID in (select PRO_PLAN_ID from PLN_JG_AND_BL where REQ_BL_ID=?)) and VALIDFLAG='1' and CODE_JG is not null ";//and CODE_BL is not null
					ps = conn.prepareStatement(sqlPRDCR);
					ps.setObject(1, blReqEntity.getReqBlId());
					rs = ps.executeQuery();
					if (rs.next()) {
						if (rs.getString("PRDCR_NO") != null) {
							ordEntity.setPrdcrNo(rs.getString("PRDCR_NO"));
							ordEntity.setJzFileIfAll("1");
							ordEntity.setMonitordemand(rs
									.getString("PRDCR_DESC"));
						}
					}
				} else if (blReqEntity.getBltype().equals("短节备料")) {
					// sqlPRDCR =
					// "select PRDCR_NO,PRDCR_DESC from SLM_ORDER_LINE_PRDCR where PRDCR_NO=(select t.PRDCR_NO from PLN_SALEORD t where ORD_LN_DLY_PK= ?) and CODE_JG is null and CODE_BL= ?";
					sqlPRDCR = "select PRDCR_NO,PRDCR_DESC from SLM_ORDER_LINE_PRDCR where PRDCR_NO=(select t.PRDCR_NO from PLN_SALEORD t where ORD_LN_DLY_PK= ?) and CODE_JG is null and CODE_BL is not null and VALIDFLAG='1' ";
					ps = conn.prepareStatement(sqlPRDCR);
					ps.setObject(1, blReqEntity.getOrdLnDlyPk());
					// ps.setObject(2, codeBl);
					rs = ps.executeQuery();
					if (rs.next()) {
						if (rs.getString("PRDCR_NO") != null) {
							ordEntity.setPrdcrNo(rs.getString("PRDCR_NO"));
							ordEntity.setJzFileIfAll("1");
							ordEntity.setMonitordemand(rs
									.getString("PRDCR_DESC"));
						}
					}

				}

				/* 获取客户信息 */
				String sqlBuyInfo = "";
				if (blReqEntity.getBltype().equals("接箍料")) {
					sqlBuyInfo = "select BUYER_ID,BUYER_NAME,FINAL_USER,FINAL_USER_DESC from PLN_ORDER_JG where PRO_PLAN_ID in (select PRO_PLAN_ID from PLN_JG_AND_BL where REQ_BL_ID=?)";
					ps = conn.prepareStatement(sqlBuyInfo);
					ps.setObject(1, blReqEntity.getReqBlId());
					rs = ps.executeQuery();
					if (rs.next()) {
						if (rs.getString("BUYER_ID") != null) {
							ordEntity.setBuyerId(rs.getString("BUYER_ID"));
						}
						if (rs.getString("BUYER_NAME") != null) {
							ordEntity.setBuyerName(rs.getString("BUYER_NAME"));
						}
						if (rs.getString("FINAL_USER") != null) {
							ordEntity.setFinalUser(rs.getString("FINAL_USER"));
						}
						if (rs.getString("FINAL_USER_DESC") != null) {
							ordEntity.setFinalUserDesc(rs
									.getString("FINAL_USER_DESC"));
						}
					}
				} else if (blReqEntity.getBltype().equals("短节备料")) {
					sqlBuyInfo = "select BUYER_ID,BUYER_NAME,FINAL_USER,FINAL_USER_DESC from PLN_SALEORD t where ORD_LN_DLY_PK= ?";
					ps = conn.prepareStatement(sqlBuyInfo);
					ps.setObject(1, blReqEntity.getOrdLnDlyPk());
					rs = ps.executeQuery();
					if (rs.next()) {
						if (rs.getString("BUYER_ID") != null) {
							ordEntity.setBuyerId(rs.getString("BUYER_ID"));
						}
						if (rs.getString("BUYER_NAME") != null) {
							ordEntity.setBuyerName(rs.getString("BUYER_NAME"));
						}
						if (rs.getString("FINAL_USER") != null) {
							ordEntity.setFinalUser(rs.getString("FINAL_USER"));
						}
						if (rs.getString("FINAL_USER_DESC") != null) {
							ordEntity.setFinalUserDesc(rs
									.getString("FINAL_USER_DESC"));
						}
					}
				}

				/********* 获取备料MSC,PSC ********************/
				sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.selectPlnBlReqPscMsc");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, blReqEntity.getReqBlId());
				rs = ps.executeQuery();
				if (rs.next()) {
					if (rs.getString("PSC") != null) {
						blReqEntity.setPsc(rs.getString("PSC"));
						ordProcEntity.setPsc(rs.getString("PSC"));
						ordEntity.setPsc(rs.getString("PSC"));
					}
					if (rs.getString("MSC") != null) {
						blReqEntity.setMsc(rs.getString("MSC"));
						ordProcEntity.setMsc(rs.getString("MSC"));
						ordEntity.setMsc(rs.getString("MSC"));
					}
					if (rs.getString("DEPARTNAME") != null) {
						departname = rs.getString("DEPARTNAME");
					}
					if (rs.getString("UNIT_DESC_PROCESS") != null) {
						unitDescProcess = rs.getString("UNIT_DESC_PROCESS");
					}
				}
				rs.close();
				ps.close();

				if (ordProcEntity.getMsc().equals("")) {
					message.add("需求：" + blReqEntity.getReqBlId()
							+ "未找到冶金规范码（备料码：" + codeBl + "）。");
					continue;
				}

				blMaterial = getBlMaterial(conn, codeBl);
				if (blMaterial == null) {
					message.add("需求：" + blReqEntity.getReqBlId() + "的备料码"
							+ codeBl + "的物料编码生成出错。");
					continue;
				}

				ordNoSeq = blReqEntity.getReqBlId().split("/");
				ordProcEntity.setMaterialNo(blMaterial[0]);
				ordProcEntity.setMaterialDesc(blMaterial[1]);
				ordEntity.setMaterialNo(blMaterial[0]);
				ordEntity.setMaterialDesc(blMaterial[1]);
				ordEntity.setPipeProperty(CoreOrdBase.pipeProperty(ordEntity
						.getMaterialNo()));
				ordEntity.setCreateName(creatName);
				ordEntity.setUpdateName(creatName);
				if (ordNoSeq != null && ordNoSeq.length > 1) {
					ordEntity.setOrderNo(ordNoSeq[0]);
					ordEntity.setOrderSeq(ordNoSeq[1]);
				}
				ordEntity.setDeliveryNo("");

				blReqEntity.setPlanstatus("1");

				// 查询工艺评审
				sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.selectBlCraftDesgin");
				sql += " AND T.VALIDFLAG = '1'";
				ps = conn.prepareStatement(sql);
				ps.setObject(1, codeBl);
				rs = ps.executeQuery();
				if (rs.next()) {
					ordProcEntity.setCraftSeq(rs.getString("CRAFT_SEQ"));
					ordEntity.setCraftSeq(rs.getString("CRAFT_SEQ"));
					if (rs.getString("DESGIN_KEY") != null) {
						desginKey = rs.getString("DESGIN_KEY");
					}
					if (rs.getString("CRAFT_NAME") != null) {
						ordProcEntity.setCraftFileMan(rs
								.getString("CRAFT_NAME"));
						ordEntity.setCraftFileMan(rs.getString("CRAFT_NAME"));
					}
					if (rs.getString("CRAFT_NO") != null) {
						ordProcEntity.setCraftFileNo(rs.getString("CRAFT_NO"));
						ordEntity.setCraftFileNo(rs.getString("CRAFT_NO"));
					}
					if (rs.getString("CRAFT_NO_V") != null) {
						ordProcEntity.setCraftNoV(rs.getString("CRAFT_NO_V"));
						ordEntity.setCraftNoV(rs.getString("CRAFT_NO_V"));
					}
					rs.close();
					ps.close();
				} else {
					rs.close();
					ps.close();

					// 无生效的工艺评审，取序号最大的一条评审记录
					sql = CoreXmlSqlParsersFactory
							.getSql("CorePlnOrdJgDjDeal.selectBlCraftDesgin");
					sql += " ORDER BY T.CRAFT_SEQ DESC";
					ps = conn.prepareStatement(sql);
					ps.setObject(1, codeBl);
					rs = ps.executeQuery();
					if (rs.next()) {
						ordProcEntity.setCraftSeq(rs.getString("CRAFT_SEQ"));
						ordEntity.setCraftSeq(rs.getString("CRAFT_SEQ"));
						if (rs.getString("DESGIN_KEY") != null) {
							desginKey = rs.getString("DESGIN_KEY");
						}
						if (rs.getString("CRAFT_NAME") != null) {
							ordProcEntity.setCraftFileMan(rs
									.getString("CRAFT_NAME"));
							ordEntity.setCraftFileMan(rs
									.getString("CRAFT_NAME"));
						}
						if (rs.getString("CRAFT_NO") != null) {
							ordProcEntity.setCraftFileNo(rs
									.getString("CRAFT_NO"));
							ordEntity.setCraftFileNo(rs.getString("CRAFT_NO"));
						}
						if (rs.getString("CRAFT_NO_V") != null) {
							ordProcEntity.setCraftNoV(rs
									.getString("CRAFT_NO_V"));
							ordEntity.setCraftNoV(rs.getString("CRAFT_NO_V"));
						}
					} else {
						message.add("需求：" + blReqEntity.getReqBlId()
								+ "未找到工艺评审记录（备料码：" + codeBl + "）\n"
								+ departname + "-" + unitDescProcess + "。");
						continue;
					}
					rs.close();
					ps.close();
				}

				// 查询工艺制程
				sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.queryBlDesginPl");
				sql += " ORDER BY T.MSC_PLINE ASC";
				ps = conn.prepareStatement(sql);
				ps.setObject(1, desginKey);
				ps.setObject(2, desginKey);
				rs = ps.executeQuery();
				if (rs.next()) {
					String endGxName = "";
					String wholeDesc = "";
					if (rs.getString("WHOLE_BACKLOG") == null) {
						message.add("需求：" + blReqEntity.getReqBlId()
								+ "未找到制程，请查看备料码" + codeBl + "的工艺评审。");
						continue;
					}
					if (rs.getString("WHOLE_BACKLOG_DESC") != null) {
						wholeDesc = rs.getString("WHOLE_BACKLOG_DESC");
						endGxName = wholeDesc.substring(wholeDesc
								.lastIndexOf('-') + 1);
					}
					ordProcEntity.setIndexSeq(rs.getString("MSC_PLINE"));
					ordProcEntity.setProcessSeq(rs.getString("WHOLE_BACKLOG"));
					if (rs.getString("GRADENAME") != null) {
						ordProcEntity
								.setGradecodeAll(rs.getString("GRADENAME"));
					}
					ordEntity.setEndgxname(endGxName);
				} else {
					message.add("需求：" + blReqEntity.getReqBlId() + "未找到工艺"
							+ ordProcEntity.getCraftSeq() + "下的制程(备料码："
							+ codeBl + ")。");
					continue;
				}
				rs.close();
				ps.close();

				// 根据制程查询全程途经工序
				ordProcEntity.setGroupJgx("/");
				ordProcEntity.setGroupRcl("/");
				ordProcEntity.setBjType("/");
				sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.queryMscplPrc");
				ps = conn.prepareStatement(sql,
						ResultSet.TYPE_SCROLL_INSENSITIVE,
						ResultSet.CONCUR_READ_ONLY);
				ps.setObject(1, desginKey);
				ps.setObject(2, ordProcEntity.getIndexSeq());
				rs = ps.executeQuery();
				if (rs.next()) {
					String wholeBacklog = ordProcEntity.getProcessSeq();
					String endgxCode = wholeBacklog.substring(wholeBacklog
							.length() - 1);
					String gprocessC = ""; // 加工二级工序
					String fprocessC = ""; // 热处理二级工序
					rs.first();
					do {
						if (rs.getString("PROCESS_CODE").trim().equals("E")
								&& rs.getString("PROCESS_DESC_C") != null) {
							ordProcEntity.setBjType(rs
									.getString("PROCESS_DESC_C"));
						} else if (rs.getString("PROCESS_CODE").trim().equals(
								"G")
								&& rs.getString("PROCESS_CODE_C") != null) {
							gprocessC = rs.getString("PROCESS_CODE_C");
						} else if (rs.getString("PROCESS_CODE").trim().equals(
								"F")
								&& rs.getString("PROCESS_CODE_C") != null) {
							fprocessC = rs.getString("PROCESS_CODE_C");
							ordProcEntity.setProcDescCRcl(rs
									.getString("PROCESS_DESC_C"));
						}
					} while (rs.next());
					ordEntity.setProduceSort(CoreOrdBase.produceSort(endgxCode,
							"", gprocessC, fprocessC));
				} else {
					message.add("需求：" + blReqEntity.getReqBlId()
							+ "未找到制程途径工序，请查看备料码" + codeBl + "的工艺评审。");
					continue;
				}
				rs.close();
				ps.close();

				// 获取交付标准公差项索引
				sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.getCraftStdSic");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, desginKey);
				rs = ps.executeQuery();
				if (rs.next()) {
					if (rs.getString("SIC") != null) {
						ordEntity.setSpecstandard(rs.getString("SIC"));
					}
				}
				rs.close();
				ps.close();

				// 获取规格代码
				sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.getSpecBaseCode");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, blReqEntity.getOutdiameter());
				ps.setObject(2, blReqEntity.getWallthick());
				rs = ps.executeQuery();
				if (rs.next()) {
					if (rs.getString("SPEC_CODE") != null) {
						ordEntity.setSpecCode(rs.getString("SPEC_CODE"));
					}
					if (rs.getString("SPEC_NAME") != null) {
						ordEntity.setSpecName(rs.getString("SPEC_NAME"));
					}
				}
				rs.close();
				ps.close();

				// 获取钢种索引码
				String groupcic = "";
				String sqlcic = CoreXmlSqlParsersFactory
						.getSql("CorePlnSaleOrder.getSelectCicGroup");
				pst = conn.prepareStatement(sqlcic);
				pst.setObject(1, desginKey);
				// pst.setObject(2, ordProcEntity.getIndexSeq());
				rst = pst.executeQuery();
				if (rst.next()) {
					groupcic = rst.getString("CIC");
				}
				rst.close();
				pst.close();
				String[] groupCic1 = groupcic.split(",");
				// 去除数组中的空格
				List<String> tmp = new ArrayList<String>();
				for (String str : groupCic1) {
					if (str != null && str.length() != 0) {
						tmp.add(str.trim());
					}
				}
				groupCic1 = tmp.toArray(new String[0]);

				// 获取是否外购
				String outsBilletFl = "0";
				String sqlcBill = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.selectOutBillFi");
				pst = conn.prepareStatement(sqlcBill);
				pst.setObject(1, codeBl);
				rst = pst.executeQuery();
				if (rst.next()) {
					outsBilletFl = rst.getString("OUTS_BILLET_FL");
				}
				rst.close();
				pst.close();
				/** 监制 **/
				/*
				 * ordProcEntity.setPrdcrpro(CoreOrdLinePrdcrLst.getOrdPrdcrpro(
				 * conn, blReqEntity(), ordProcEntity.getIndexSeq()));
				 */

				sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.selectDesginBom");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, desginKey);
				ps.setObject(2, ordProcEntity.getIndexSeq());
				ps.setObject(3, ordProcEntity.getMsc());
				// ps.setObject(2, ordProcEntity.getMaterialNo());
				rs = ps.executeQuery();
				if (rs.next()) {
					boolean fl = false;
					int count = 0;
					String[] reason = new String[1];
					// String strGRADECODE_ALL = "";
					do {
						String dinMaterial = "";
						String dPline = "";
						String dPlineName = "";
						ordProcEntity.setBom(rs.getString("BOM"));
						// if (rs.getString("GRADENAME") != null) {
						// strGRADECODE_ALL = strGRADECODE_ALL
						// + rs.getString("GRADENAME");
						// }
						if (rs.getString("GRADECODE") != null) {
							ordProcEntity.setGradecode(rs
									.getString("GRADECODE"));
						}
						int coun = 0;
						String sqlc = CoreXmlSqlParsersFactory
								.getSql("FrmBomConfirm.getQueryGrade");
						sqlc += " AND INSTR(T.GRADECODE,'"
								+ rs.getString("GRADECODE") + "') > 0";
						sqlc += CoreConverter.toSqlConditionString("T.CIC",
								groupCic1);
						sqlc += " AND T1.PURCHASE_STD='" + outsBilletFl + "' ";
						pst = conn.prepareStatement(sqlc);
						rst = pst.executeQuery();
						if (rst.next()) {
							coun = 1;
						}
						rst.close();
						pst.close();
						if (coun == 0) {
							if (outsBilletFl.equals("0")) {
								reason[0] = "未找钢种[" + rs.getString("GRADENAME")
										+ "]自炼的索引码";
							} else {
								reason[0] = "未找钢种[" + rs.getString("GRADENAME")
										+ "]外购的索引码";
							}
							continue;
						}

						if (rs.getString("D_PLINE") != null) {
							ordProcEntity.setGroupRollAll(rs
									.getString("D_PLINE"));
						}

						if (rs.getString("E_IN_MATERIAL_DESC") != null) {
							ordProcEntity.setEInMaterialDesc(rs
									.getString("E_IN_MATERIAL_DESC"));
						}
						if (rs.getString("E_IN_MATERIAL_NO") != null) {
							ordProcEntity.setEInMaterialNo(rs
									.getString("E_IN_MATERIAL_NO"));
						}
						ordProcEntity.setDimaterYlg(String.valueOf(rs
								.getDouble("DIMATER")));
						ordProcEntity.setHeightYlg(String.valueOf(rs
								.getDouble("HEIGHT")));
						ordProcEntity.setGroupJgx(CoreDefGourp.getJgxDefGroup(
								conn, desginKey, ordProcEntity.getIndexSeq(),
								rs.getString("BOM")));
						ordProcEntity.setGroupRcl(CoreDefGourp.getRclDefGroup(
								conn, desginKey, ordProcEntity.getIndexSeq(),
								rs.getString("BOM")));
						if (ordProcEntity.getProcessSeq().contains("D")) {
							dPline = getBlDpine(conn, rs
									.getString("D_IN_MATERIAL_NO"), rs
									.getString("D_OUT_MATERIAL_NO"), desginKey,
									ordProcEntity.getIndexSeq());
							if (dPline.equals("")) {
								reason[0] = "未找到可用轧管机组";
								continue;
							}
							ordProcEntity.setGroupRoll(dPline);
						}

						if (ordProcEntity.getProcessSeq().contains("D")) {
							dPlineName = getBlDplineName(conn, rs
									.getString("D_IN_MATERIAL_NO"), rs
									.getString("D_OUT_MATERIAL_NO"), desginKey,
									ordProcEntity.getIndexSeq());
							if (dPlineName.equals("")) {
								reason[0] = "未找到可用轧管机组";
								continue;
							}
							ordProcEntity.setGroupRollName(dPlineName);
						}

						// /轧管投入物料(炼钢末工序产出物料)
						if (rs.getString("D_IN_MATERIAL_NO") != null
								&& !rs.getString("D_IN_MATERIAL_NO").equals("")) {
							dinMaterial = rs.getString("D_IN_MATERIAL_NO");
						} else if (rs.getString("C_OUT_MATERIAL_NO") != null
								&& !rs.getString("C_OUT_MATERIAL_NO")
										.equals("")) {
							dinMaterial = rs.getString("C_OUT_MATERIAL_NO");
						} else if (rs.getString("B_OUT_MATERIAL_NO") != null
								&& !rs.getString("B_OUT_MATERIAL_NO")
										.equals("")) {
							dinMaterial = rs.getString("B_OUT_MATERIAL_NO");
						} else if (rs.getString("A_OUT_MATERIAL_NO") != null
								&& !rs.getString("A_OUT_MATERIAL_NO")
										.equals("")) {
							dinMaterial = rs.getString("A_OUT_MATERIAL_NO");
						}
						ordProcEntity.setStuffProperty(CoreOrdBase
								.stuffProperty(dinMaterial));
						if (rs.getString("D_OUT_MATERIAL_NO") != null
								&& !rs.getString("D_OUT_MATERIAL_NO")
										.equals("")) {
							ordProcEntity.setAbc(CoreOrdBase.getPlnOrdZgAbc(rs
									.getString("D_OUT_MATERIAL_NO")));
						}
						// 合同量计算
						count++;
						if (!getOrdProcAmount(conn, desginKey, blReqEntity,
								ordEntity, ordProcEntity, reason)) {
							if (count > 10) {
								break;
							} else {
								continue;
							}
						}
						fl = true;
						break;
					} while (rs.next());

					// ordProcEntity.setGradecodeAll(strGRADECODE_ALL);

					if (!fl) {
						message.add("需求：" + blReqEntity.getReqBlId()
								+ reason[0] + "(备料码：" + codeBl + ")。");
						continue;
					}
				} else {
					message.add("需求：" + blReqEntity.getReqBlId()
							+ "未找到物料信息。(备料码：" + codeBl + ")。");
					continue;
				}
				rs.close();
				ps.close();

				ordProcEntity.setIfExport("/");
				ordProcEntity.setPlanIsOk("0");
				if (ordProcEntity.getProcessSeq().contains("F")) {
					// 判断是否经过热处理工序
					ordProcEntity.setFIsOk("0");
				} else {
					ordProcEntity.setFIsOk("2");
				}

				if (ordProcEntity.getProcessSeq().contains("G")) {
					// 判断是否经过管加工工序
					ordProcEntity.setGIsOk("0");
				} else {
					ordProcEntity.setGIsOk("2");
				}

				if (ordProcEntity.getProcessSeq().contains("D")) {
					// 判断是否经过轧管工序
					ordProcEntity.setDIsOk("0");
				} else {
					ordProcEntity.setDIsOk("2");
				}
				if (ordProcEntity.getProcessSeq().contains("E")) {
					// 判断是否经过镦拔扩工序
					ordProcEntity.setEIsOk("0");
				} else {
					ordProcEntity.setEIsOk("2");
				}

				// 新增提报表记录
				sqlAddSale = EntityTool.fillSqlByEntity(sqlNew, ordEntity);
				ps = conn.prepareStatement(sqlAddSale);
				ps.setObject(1, codeBl);
				ps.executeUpdate();
				ps.close();

				// 新增排产行
				sqlAdd = EntityTool.fillSqlByEntity(sqlPrc, ordProcEntity);
				ps = conn.prepareStatement(sqlAdd);
				ps.setObject(1, blReqEntity.getReqBlId());
				ps.executeUpdate();
				ps.close();

				sqlUp = EntityTool.fillSqlByEntity(sqlblUp, blReqEntity);
				ps = conn.prepareStatement(sqlUp);
				ps.executeUpdate();
				ps.close();

				conn.commit();
			}
			if (message.size() > 0) {
				cro.setResult((list.size() - message.size()) + "条操作成功，"
						+ message.size() + "条操作失败。\n" + message.get(0));
			} else {
				cro.setResult(list.size() + "条操作成功，0条操作失败。");
			}
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 取消确认
	 * 
	 * @param list
	 * @return
	 */
	public CoreReturnObject canCelConfirmBl(ArrayList<String> list) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			ArrayList<String> message = new ArrayList<String>();
			String sqlDel = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.deleteBlSaleOrd");
			String sqlDelPro = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.deleteBlPlnProc");
			String sqlUpBl = CoreXmlSqlParsersFactory
					.getSql("CorePlnOrdJgDjDeal.updateBlReqInfo");

			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);

			for (String blReqId : list) {
				PreparedStatement ps = null;
				ResultSet rs = null;
				String sqlUp = "";
				PlnPorderBlReqEntity blReqEntity = null;
				String sql = CoreXmlSqlParsersFactory
						.getSql("CorePlnOrdJgDjDeal.queryPlnBlReqStatus");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, blReqId);
				rs = ps.executeQuery();
				blReqEntity = EntityTool.getEntityByRs(rs,
						PlnPorderBlReqEntity.class);
				if (blReqEntity == null) {
					message.add("未找到编号为：" + blReqId + "的备料需求。");
					continue;
				}
				if (blReqEntity.getPlanstatus().compareTo("1") > 0) {
					message.add("需求：" + blReqEntity.getReqBlId() + "已经下发了。");
					continue;
				}
				if (blReqEntity.getPlanstatus().compareTo("1") < 0) {
					message.add("需求：" + blReqEntity.getReqBlId() + "还没有确认。");
					continue;
				}
				rs.close();
				ps.close();

				String planstttus = "";
				if (blReqEntity.getBltype().equals("短节备料")) {
					String sqlCpOrder = "SELECT MAX(T.PLANSTATUS) PLANSTATUS"
							+ "  FROM PLN_SALEORD_PROC T,PLN_PORDER_BL_REQ T1"
							+ " WHERE T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK AND T1.REQ_BL_ID = ?";
					ps = conn.prepareStatement(sqlCpOrder);
					ps.setObject(1, blReqId);
					rs = ps.executeQuery();
					if (rs.next()) {
						planstttus = rs.getString("PLANSTATUS");
					}
					rs.close();
					ps.close();
				} else {
					// 查询成品合同排产状态
					String sqlCpOrder = "SELECT MAX(T.PLANSTATUS) PLANSTATUS"
							+ "  FROM PLN_SALEORD_PROC T, PLN_ORDER_JG T1, PLN_GX_JG_M T2,PLN_JG_AND_BL T3"
							+ " WHERE T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK  "
							+ " AND T1.PRO_PLAN_ID = T2.PRO_PLAN_ID  AND T2.PRO_PLAN_ID = T3.PRO_PLAN_ID  AND T3.REQ_BL_ID = ?";
					ps = conn.prepareStatement(sqlCpOrder);
					ps.setObject(1, blReqId);
					rs = ps.executeQuery();
					if (rs.next()) {
						planstttus = rs.getString("PLANSTATUS");
					}
					rs.close();
					ps.close();
				}
				if (planstttus == null || planstttus.equals("")) {
					message.add("备料需求号" + blReqId + "无对应成品合同，不能删除");
					continue;
				}
				if (!planstttus.equals("1")) {
					message.add("备料需求号" + blReqId + "对应排产成品合同不是已接收状态，不能删除");
					continue;
				}
				// 删除提报表记录
				ps = conn.prepareStatement(sqlDel);
				ps.setObject(1, blReqId);
				ps.executeUpdate();
				ps.close();

				// 删除排产表记录
				ps = conn.prepareStatement(sqlDelPro);
				ps.setObject(1, blReqId);
				ps.executeUpdate();
				ps.close();

				// 更新备料表记录
				blReqEntity.setPlanstatus("0");
				sqlUp = EntityTool.fillSqlByEntity(sqlUpBl, blReqEntity);
				ps = conn.prepareStatement(sqlUp);
				ps.executeUpdate();
				ps.close();

				conn.commit();
			}
			if (message.size() > 0) {
				cro.setResult((list.size() - message.size()) + "条操作成功，"
						+ message.size() + "条操作失败。\n" + message.get(0));
			} else {
				cro.setResult(list.size() + "条操作成功，0条操作失败。");
			}
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 备料需求计算
	 * 
	 * @param conn
	 * @param desginKey
	 * @param blReqEntity
	 * @param ordProcEntity
	 * @param reason
	 * @return
	 * @throws SQLException
	 * @throws ScriptException
	 */
	public static boolean getOrdProcAmount(Connection conn, String desginKey,
			PlnPorderBlReqEntity blReqEntity, PlnSaleordEntity ordEntity,
			PlnSaleordProcEntity ordProcEntity, String[] reason)
			throws SQLException, ScriptException {
		double wallthick = Double.parseDouble(blReqEntity.getWallthick());
		double outdiameter = Double.parseDouble(blReqEntity.getOutdiameter());
		double orderQty = Double.parseDouble(blReqEntity.getJgblReqWeight());
		if (ordProcEntity.getProcessSeq().contains("D")
				&& !ordProcEntity.getGroupRoll().trim().equals("C072")
				&& !ordProcEntity.getGroupRoll().trim().equals("C065")
				&& !ordProcEntity.getGroupRoll().trim().equals("C066")) {
			/*********** 计算 **************/
			OutOrdParamEntity outOrdParam = null;
			InOrdParamEntity inOrdParam = null;
			double height = 0;
			ordEntity.setOrderQty(blReqEntity.getJgblReqWeight());
			height = Double.parseDouble(ordProcEntity.getHeightYlg());
			inOrdParam = CoreGetOrdAmount.getBlInOrdParam(conn, desginKey,
					blReqEntity, ordProcEntity);
			inOrdParam.setEndlenSpecstd(0);
			outOrdParam = PlnProducCal.calculate(conn, inOrdParam);
			if (outOrdParam.getErrCode() == -1) {
				reason[0] = "备料需求量转换出错（" + outOrdParam.getErrMessage() + "）。";
				return false;
			}
			blReqEntity.setAimwallthick(String.valueOf(outOrdParam
					.getAimWallthick()));
			blReqEntity
					.setAimlength(String.valueOf(outOrdParam.getAimLength()));
			blReqEntity.setJgblReqNum(String.valueOf(outOrdParam.getPlanNum()));

			ordEntity
					.setOrderweight(String.valueOf(outOrdParam.getWeightInA()));
			ordEntity.setOrdernum(String.valueOf(outOrdParam.getPlanNum()));
			ordEntity.setPlanweight(String.valueOf(outOrdParam.getWeightInA()));
			ordEntity.setPaydownWtMax(String.valueOf(outOrdParam
					.getWeightInAMax()));
			ordEntity.setPaydownWtMin(String.valueOf(outOrdParam
					.getWeightInAMin()));
			ordEntity.setWeightPerM(String.valueOf(outOrdParam.getWeightMi()));
			ordEntity.setLenToendMax(String.valueOf(outOrdParam
					.getLenToendMax()));
			ordEntity.setLenToendMin(String.valueOf(outOrdParam
					.getLenToendMin()));
			if (wallthick > 0) {
				ordEntity.setHeightOrdMin(String.valueOf(100
						* inOrdParam.getStdWallthickMin() / wallthick));
				ordEntity.setHeightOrdMax(String.valueOf(100
						* inOrdParam.getStdWallthickMax() / wallthick));
			}

			/******* 排产信息 ********/
			ordProcEntity.setWeightPerM(String.valueOf(outOrdParam
					.getWeightMi()));
			ordProcEntity
					.setPlanWtD(String.valueOf(outOrdParam.getWeightInA()));
			ordProcEntity.setPlanNumD(String.valueOf(outOrdParam.getPlanNum()));
			ordProcEntity.setAimLenRoll(String.valueOf(outOrdParam
					.getAimlengthZg()));
			ordProcEntity.setAimLenEnd(String.valueOf(outOrdParam
					.getAimLength()));
			ordProcEntity.setPlanPMain(String
					.valueOf(outOrdParam.getWeightPc()));
			ordProcEntity.setPlanTotLenD(String.valueOf((outOrdParam
					.getPlanNum() * outOrdParam.getAimLength())));
			ordProcEntity.setTotLenOneP(String.valueOf(outOrdParam
					.getTotLenOneP()));
			ordProcEntity.setCutNumP(String.valueOf(outOrdParam.getCutNumP()));
			ordProcEntity.setRollLength(String.valueOf(outOrdParam
					.getRollLength()));
			ordProcEntity.setAimWallthick(String.valueOf(outOrdParam
					.getAimWallthick()));
			ordProcEntity.setLenRollMax(String.valueOf(outOrdParam
					.getLenRollMax()));
			ordProcEntity.setLenRollMin(String.valueOf(outOrdParam
					.getLenRollMin()));
			if (inOrdParam.getNkWallthickMax() == 0
					&& inOrdParam.getNkWallthickMin() == 0) {
				ordProcEntity.setHeightNkMin(String.valueOf(100
						* inOrdParam.getStdWallthickMin() / wallthick));
				ordProcEntity.setHeightNkMax(String.valueOf(100
						* inOrdParam.getStdWallthickMax() / wallthick));
			} else if (height > 0) {
				ordProcEntity.setHeightNkMin(String.valueOf(100
						* inOrdParam.getNkWallthickMin() / height));
				ordProcEntity.setHeightNkMax(String.valueOf(100
						* inOrdParam.getNkWallthickMax() / height));
			}
			ordProcEntity.setOutdOrdMax(String.valueOf(inOrdParam
					.getOutdOrdMax()));
			ordProcEntity.setOutdOrdMin(String.valueOf(inOrdParam
					.getOutdOrdMin()));
			ordProcEntity.setAimOutdiameter(String.valueOf(outOrdParam
					.getAimOutdiameter()));
			ordProcEntity
					.setFeedRate(String.valueOf(outOrdParam.getFeedRate()));
			ordProcEntity.setCoefficient(String.valueOf(outOrdParam
					.getCoefficient()));
			ordProcEntity.setCoefficientMin(String.valueOf(outOrdParam
					.getCoefficientMin()));
			ordProcEntity.setPlanPMainMin(String.valueOf(outOrdParam
					.getPlanPMainMin()));
			ordProcEntity.setWeightKzM(String.valueOf(outOrdParam
					.getWeightKzM()));
			ordProcEntity
					.setAimWtEnd(String.valueOf(outOrdParam.getAimWtEnd()));

			return true;
		} else {
			/*********** 外购管 **************/
			double orderWeight = 0; // 合同量
			double aimlength = 0; // 目标长度
			int planNum = 0;// 合同支数
			double rate = 0;
			double rateMin = 0;
			double aimWallthick = wallthick;
			double weightMI = CoreOrdBase.WeightOfMi(outdiameter, aimWallthick);// 米单重
			double delvryRangeMax = 5;
			double delvryRangeMin = 5;
			Calendar now = Calendar.getInstance();
			int year = now.get(Calendar.YEAR);
			int month = now.get(Calendar.MONTH);
			double putRate = CorePlnSaleOrder.queryPutRate(conn, year, month);
			Double[] stdTole = CoreOrderStdSic.getConnStdTole(conn, desginKey,
					outdiameter, wallthick);
			if (stdTole == null) {
				stdTole = new Double[] { 0.0, 0.0 };
				/*
				 * reason[0] = "未找到交货标准公差。"; return false;
				 */
			}
			aimWallthick = wallthick + (stdTole[0] - stdTole[1]) / 2;

			rate = 1 + ((delvryRangeMax + delvryRangeMin) * putRate - delvryRangeMin) / 100;
			rateMin = 1 - delvryRangeMin / 100;
			orderWeight = orderQty;

			// 目标长度，取长度上下限中间值,计算计划支数
			if (!blReqEntity.getLengthmax().trim().equals("")
					&& !blReqEntity.getLengthmin().trim().equals("")) {
				double lengthMax = Double.parseDouble(blReqEntity
						.getLengthmax());
				double lengthMin = Double.parseDouble(blReqEntity
						.getLengthmin());
				aimlength = (lengthMax + lengthMin) / 2;
				if ((orderWeight % (aimlength * weightMI)) == 0) {
					planNum = (int) (orderWeight / (aimlength * weightMI));
				} else {
					planNum = (int) (orderWeight / (aimlength * weightMI)) + 1;
				}
			}
			blReqEntity.setAimwallthick(String.valueOf(aimWallthick));
			blReqEntity.setAimlength(String.valueOf(aimlength));
			blReqEntity.setJgblReqNum(String.valueOf(planNum));

			ordEntity.setOrderweight(String.valueOf(orderWeight));
			ordEntity.setOrdernum(String.valueOf(planNum));
			ordEntity.setWeightPerM(String.valueOf(weightMI));
			ordEntity.setPlanweight(String.valueOf(orderWeight));
			ordEntity.setPaydownWtMax(String.valueOf((orderWeight
					* delvryRangeMax / 100)));
			ordEntity.setPaydownWtMin(String.valueOf((orderWeight
					* delvryRangeMin / 100)));

			if (wallthick > 0) {
				ordEntity.setHeightOrdMax(String
						.valueOf((100 * stdTole[0] / wallthick)));
				ordEntity.setHeightOrdMin(String
						.valueOf((100 * stdTole[1] / wallthick)));
				ordProcEntity.setHeightNkMax(String
						.valueOf((100 * stdTole[0] / wallthick)));
				ordProcEntity.setHeightNkMin(String
						.valueOf((100 * stdTole[1] / wallthick)));
			}

			ordProcEntity.setPlanWtD(String.valueOf(orderWeight));
			ordProcEntity.setPlanNumD(String.valueOf(planNum));
			ordProcEntity.setWeightPerM(String.valueOf(weightMI));
			ordProcEntity.setAimLenEnd(String.valueOf(aimlength));
			ordProcEntity.setPlanPMain(String.valueOf((rate * orderWeight)));
			ordProcEntity.setPlanTotLenD(String.valueOf((planNum * aimlength)));
			ordProcEntity.setAimWallthick(String.valueOf(aimWallthick));
			ordProcEntity.setAimOutdiameter(String.valueOf(outdiameter));
			ordProcEntity.setFeedRate(String.valueOf(putRate));
			ordProcEntity.setCoefficient(String.valueOf(rate));
			ordProcEntity.setCoefficientMin(String.valueOf(rateMin));
			ordProcEntity
					.setPlanPMainMin(String.valueOf(rateMin * orderWeight));
			ordProcEntity.setWeightKzM(String.valueOf(weightMI));
			ordProcEntity.setAimWtEnd(String.valueOf(ordEntity.getWeightJg()
					/ 1000 + weightMI
					* (aimlength - ordEntity.getCheckJVal() / 1000)));

			return true;
		}
	}

	/**
	 * 备料轧管产线编码
	 * 
	 * @param conn
	 * @param dInMaterialNo
	 * @param dOutMaterialNo
	 * @param desginKey
	 * @param mscPline
	 * @return
	 * @throws SQLException
	 */
	public static String getBlDpine(Connection conn, String dInMaterialNo,
			String dOutMaterialNo, String desginKey, String mscPline)
			throws SQLException {
		String dPine = "";
		String sql = CoreXmlSqlParsersFactory
				.getSql("CoreOrdDesginBom.getBomMaterialDpl");
		PreparedStatement pst = conn.prepareStatement(sql,
				ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
		pst.setString(1, dInMaterialNo);
		pst.setString(2, dOutMaterialNo);
		pst.setString(3, desginKey);
		pst.setString(4, mscPline);
		ResultSet rst = pst.executeQuery();
		if (rst.next()) {
			do {
				if (rst.getString("PLINE_CODE").equals("C012")) {
					dPine = "C012";
					break;
				}
			} while (rst.next());

			if (dPine.equals("") && rst.first()) {
				dPine = rst.getString("PLINE_CODE");
			}
		}
		return dPine;
	}

	public static String getBlDplineName(Connection conn, String dInMaterialNo,
			String dOutMaterialNo, String desginKey, String mscPline)
			throws SQLException {
		String dPlineName = "";
		String sql = CoreXmlSqlParsersFactory
				.getSql("CoreOrdDesginBom.getBomMaterialDpl");
		PreparedStatement pst = conn.prepareStatement(sql,
				ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
		pst.setString(1, dInMaterialNo);
		pst.setString(2, dOutMaterialNo);
		pst.setString(3, desginKey);
		pst.setString(4, mscPline);
		ResultSet rst = pst.executeQuery();
		if (rst.next()) {
			do {
				if (rst.getString("PLINE_CODE").equals("C012")) {
					dPlineName = "ASSEL机组";
					break;
				}
			} while (rst.next());

			if (dPlineName.equals("") && rst.first()) {
				dPlineName = rst.getString("PLINE_NAME");
			}
		}
		return dPlineName;
	}

	/**
	 * 获取备料的物料编码、名称
	 * 
	 * @param conn
	 * @param blCode
	 * @return
	 * @throws SQLException
	 */
	public static String[] getBlMaterial(Connection conn, String blCode)
			throws SQLException {
		String[] material = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		BomEntity bomEntity = null;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CorePlnOrdJgDjDeal.selectBlBomMaterial");
		ps = conn.prepareStatement(sql);
		ps.setObject(1, blCode);
		rs = ps.executeQuery();
		bomEntity = EntityTool.getEntityByRs(rs, BomEntity.class);
		if (bomEntity == null) {
			return null;
		}
		rs.close();
		ps.close();
		material = BomMaterial.formEndMaterial(bomEntity, conn);
		return material;
	}

	/**************************************************/

	/**
	 * 查询备料清单表
	 * 
	 * @param str
	 *            查询参数
	 * @return object
	 */
	public CoreReturnObject queryBlList(String str) {
		CoreReturnObject cro = null;
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.queryBlList",
				new Object[] { str });
		return cro;
	}

	/**
	 * 查询备料
	 * 
	 * @param str
	 *            查询参数
	 * @return object
	 */
	public CoreReturnObject queryDesginBlList(String str) {
		CoreReturnObject cro = null;
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.queryDesginBlList",
				new Object[] { str });
		return cro;
	}

	/**
	 * 查询产品码
	 * 
	 * @param list
	 *            查询参数
	 * @return object
	 */
	public CoreReturnObject queryblPsc(ArrayList<String> list) {
		CoreReturnObject cro = null;
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.queryblPsc", list
				.toArray());
		return cro;
	}

	/**
	 * 根据产品码查找对应冶金规范码
	 * 
	 * @param str
	 *            查询参数
	 * @return object
	 */
	public CoreReturnObject queryPscForMsc(String str) {
		CoreReturnObject cro = null;
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.queryPscForMsc",
				new Object[] { str });
		return cro;
	}

	/**
	 * 根据DESGIN_KEY与备料组查询短节备料码
	 * 
	 * @param list
	 *            查询参数
	 * @return object
	 */
	public CoreReturnObject queryBlCodeByGp(ArrayList<String> list) {
		CoreReturnObject cro = null;
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.queryBlCodeByGp", list
				.toArray());
		return cro;
	}

	/**
	 * 根据DESGIN_KEY查询短节备料码
	 * 
	 * @param str
	 *            查询参数
	 * @return object
	 */
	public CoreReturnObject queryBlCode(String str) {
		CoreReturnObject cro = null;
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.queryBlCode",
				new Object[] { str });
		return cro;
	}

	/**
	 * 查询质量设计下的所有备料组
	 * 
	 * @param str
	 *            质量设计主键
	 * @param ordLnDlyPk
	 * @return object
	 */
	public CoreReturnObject queryBlGroup(String str, String ordLnDlyPk) {
		CoreReturnObject cro = null;
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.queryBlGroup",
				new Object[] { str, ordLnDlyPk });
		return cro;
	}

	/**
	 * 查询销售合同信息
	 * 
	 * @param str
	 * @return object
	 */
	public CoreReturnObject querySaleByPrimary(String str) {
		CoreReturnObject cro = null;
		cro = this.getDataBySqlID("CorePlnOrdJgDjDeal.querySaleByPrimary",
				new Object[] { str });
		return cro;
	}
	/****************************************************************/

}