package com.steering.pss.plnsaleord.orderInfo;

import java.util.ArrayList;
import java.util.List;

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

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;

/**
 * 订单公共方法
 * 
 * @author Administrator
 * 
 */
public class OrderHelper extends DBCommon {
	/**
	 * 集合转字符数组
	 * 
	 * @param list
	 * @return
	 */
	public static String[] listToArray(ArrayList<String> list) {
		String[] array = new String[list.size()];
		for (int i = 0; i < list.size(); i++) {
			array[i] = list.get(i);
		}
		return array;
	}

	/**
	 * 查询轧管订单
	 * 
	 * @param orderNo
	 *            合同号
	 * @param proPlanId
	 *            　订单号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryZgOrderM(String orderNo, String proPlanId,
			String yearTime) {
		List<String> params = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryZgM");
		if (!orderNo.equals("")) {
			sql += "  AND T.ORDER_NO  || '&' LIKE '%' ||?|| '%'";
			params.add(orderNo);
		}
		if (!proPlanId.equals("")) {
			sql += "  AND T.PRO_PLAN_ID =?";
			params.add(proPlanId);
		}
		if (!yearTime.equals("")) {
			sql += "  AND T.PRO_MONTH=?";
			params.add(yearTime);
		}
		sql += " ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询轧管工序合同
	 * 
	 * @param orderNo
	 *            合同号
	 * @param proPlanId
	 *            　订单号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryZgOrderC(String orderNo, String proPlanId) {
		List<String> params = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryZgC");
		if (!orderNo.equals("")) {
			sql += "  AND T.ORDER_NO  || '&' LIKE '%' ||?|| '%'";
			params.add(orderNo);
		}
		if (!proPlanId.equals("")) {
			sql += "  AND T.PRO_PLAN_ID =?";
			params.add(proPlanId);
		}
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询轧管订单
	 * 
	 * @param planGroupNoList
	 *            　排产联动组号集合
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryZgM(ArrayList<String> planGroupNoList) {
		String[] param = OrderHelper.listToArray(planGroupNoList);
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryZgM");
		sql += " AND T.PRO_PLAN_ID IN(SELECT T1.PRO_PLAN_ID FROM PLN_ORDER_ZG T1 WHERE 1=1 ";
		sql += CoreConverter.toSqlConditionString("T1.PLAN_GROUP_ID", param);
		sql += ")ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql);
	}

	/**
	 * 查询轧管合同
	 * 
	 * @param planGroupNoList
	 *            　排产联动组号集合
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryZgC(ArrayList<String> planGroupNoList) {
		String[] param = OrderHelper.listToArray(planGroupNoList);
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryZgC");
		sql += CoreConverter.toSqlConditionString("T.PLAN_GROUP_ID", param);
		sql += " ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql);
	}

	/**
	 * 查询镦拔扩订单
	 * 
	 * @param orderNo
	 * @param proPlanId
	 * @param yearTime
	 * @return
	 */
	public CoreReturnObject queryDbkOrderM(String orderNo, String proPlanId,
			String yearTime) {
		List<String> params = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryDbkM");
		if (!orderNo.equals("")) {
			sql += " AND T.ORDER_NO  || '&' LIKE '%' ||?|| '%'";
			params.add(orderNo);
		}
		if (!proPlanId.equals("")) {
			sql += "  AND T.PRO_PLAN_ID =?";
			params.add(proPlanId);
		}
		if (!yearTime.equals("")) {
			sql += "  AND T.PRO_MONTH=?";
			params.add(yearTime);
		}
		sql += " ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询镦拔扩工序合同
	 * 
	 * @param orderNo
	 * @param proPlanId
	 * @return
	 */
	public CoreReturnObject queryDbkOrderC(String orderNo, String proPlanId) {
		List<String> params = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryDbkC");
		if (!orderNo.equals("")) {
			sql += " AND T.ORDER_NO  || '&' LIKE '%' ||?|| '%'";
			params.add(orderNo);
		}
		if (!proPlanId.equals("")) {
			sql += "  AND T.PRO_PLAN_ID =?";
			params.add(proPlanId);
		}
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询镦拔扩订单
	 * 
	 * @param planGroupNoList
	 *            　排产联动组号集合
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryDbkM(ArrayList<String> planGroupNoList) {
		String[] param = OrderHelper.listToArray(planGroupNoList);
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryDbkM");
		sql += " AND T.PRO_PLAN_ID IN(SELECT T1.PRO_PLAN_ID FROM PLN_ORDER_DBK T1 WHERE 1=1 ";
		sql += CoreConverter.toSqlConditionString("T1.PLAN_GROUP_ID", param);
		sql += ")ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql);
	}

	/**
	 * 查询镦拔扩合同
	 * 
	 * @param planGroupNoList
	 *            　排产联动组号集合
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryDbkC(ArrayList<String> planGroupNoList) {
		String[] param = OrderHelper.listToArray(planGroupNoList);
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryDbkC");
		sql += CoreConverter.toSqlConditionString("T.PLAN_GROUP_ID", param);
		sql += "ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql);
	}

	/**
	 * 查询热处理订单
	 * 
	 * @param orderNo
	 * @param proPlanId
	 * @param yearTime
	 * @return
	 */
	public CoreReturnObject queryRclOrderM(String orderNo, String proPlanId,
			String yearTime) {
		List<String> params = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryRclM");
		if (!orderNo.equals("")) {
			sql += " AND T.ORDER_NO  || '&' LIKE '%' ||?|| '%'";
			params.add(orderNo);
		}
		if (!proPlanId.equals("")) {
			sql += "  AND T.PRO_PLAN_ID =?";
			params.add(proPlanId);
		}
		if (!yearTime.equals("")) {
			sql += "  AND T.PRO_MONTH=?";
			params.add(yearTime);
		}
		sql += " ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询热处理工序合同
	 * 
	 * @param orderNo
	 * @param proPlanId
	 * @return
	 */
	public CoreReturnObject queryRclOrderC(String orderNo, String proPlanId) {
		List<String> params = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryRclC");
		if (!orderNo.equals("")) {
			sql += " AND T.ORDER_NO  || '&' LIKE '%' ||?|| '%'";
			params.add(orderNo);
		}
		if (!proPlanId.equals("")) {
			sql += "  AND T.PRO_PLAN_ID =?";
			params.add(proPlanId);
		}
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询热处理订单
	 * 
	 * @param planGroupNoList
	 *            　排产联动组号集合
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryRclM(ArrayList<String> planGroupNoList) {
		String[] param = OrderHelper.listToArray(planGroupNoList);
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryRclM");
		sql += " AND T.PRO_PLAN_ID IN(SELECT T1.PRO_PLAN_ID FROM PLN_ORDER_RCL T1 WHERE 1=1 ";
		sql += CoreConverter.toSqlConditionString("T1.PLAN_GROUP_ID", param);
		sql += ") ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql);
	}

	/**
	 * 查询热处理合同
	 * 
	 * @param planGroupNoList
	 *            　排产联动组号集合
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryRclC(ArrayList<String> planGroupNoList) {
		String[] param = OrderHelper.listToArray(planGroupNoList);
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryRclC");
		sql += CoreConverter.toSqlConditionString("T.PLAN_GROUP_ID", param);
		sql += " ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql);
	}

	/**
	 * 查询加工订单
	 * 
	 * @param orderNo
	 * @param proPlanId
	 * @param yearTime
	 * @return
	 */
	public CoreReturnObject queryJgxOrderM(String orderNo, String proPlanId,
			String yearTime) {
		List<String> params = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryJgxM");
		if (!orderNo.equals("")) {
			sql += " AND T.ORDER_NO  || '&' LIKE '%' ||?|| '%'";
			params.add(orderNo);
		}
		if (!proPlanId.equals("")) {
			sql += "  AND T.PRO_PLAN_ID =?";
			params.add(proPlanId);
		}
		if (!yearTime.equals("")) {
			sql += "  AND T.PRO_MONTH=?";
			params.add(yearTime);
		}
		sql += " ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询加工工序合同
	 * 
	 * @param orderNo
	 * @param proPlanId
	 * @return
	 */
	public CoreReturnObject queryJgxOrderC(String orderNo, String proPlanId) {
		List<String> params = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryJgxC");
		if (!orderNo.equals("")) {
			sql += " AND T.ORDER_NO  || '&' LIKE '%' ||?|| '%'";
			params.add(orderNo);
		}
		if (!proPlanId.equals("")) {
			sql += "  AND T.PRO_PLAN_ID =?";
			params.add(proPlanId);
		}
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询加工线订单
	 * 
	 * @param planGroupNoList
	 *            　排产联动组号集合
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryJgxM(ArrayList<String> planGroupNoList) {
		String[] param = OrderHelper.listToArray(planGroupNoList);
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryJgxM");
		sql += " AND T.PRO_PLAN_ID IN(SELECT T1.PRO_PLAN_ID FROM PLN_ORDER_JGX T1 WHERE 1=1 ";
		sql += CoreConverter.toSqlConditionString("T1.PLAN_GROUP_ID", param);
		sql += ")ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql);
	}

	/**
	 * 查询加工线合同
	 * 
	 * @param planGroupNoList
	 *            　排产联动组号集合
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryJgxC(ArrayList<String> planGroupNoList) {
		String[] param = OrderHelper.listToArray(planGroupNoList);
		String sql = CoreXmlSqlParsersFactory.getSql("OrderHelper.queryJgxC");
		sql += CoreConverter.toSqlConditionString("T.PLAN_GROUP_ID", param);
		sql += " ORDER BY T.PRO_PLAN_ID";
		return this.getData(sql);
	}

}
