package com.steering.pss.sale.order.qualityDesign.Dao.idao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.steering.pss.sale.order.model.ComPscEntity;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.CustSpecialAskDaoImp;

import CoreFS.SA08.CoreXmlSqlParsersFactory;

/**
 * 客户特殊要求bean类
 * 
 * @author Administrator
 * 
 */
public class ICustSpecialAskDao implements CustSpecialAskDaoImp {
	/**
	 * 查询最终用户
	 * 
	 * @param con
	 *            连接字符串
	 * @param custAlphaNo
	 *            客户alpha编号
	 * @return String
	 * @throws SQLException
	 */
	public String getFinalCustomer(Connection con, String custAlphaNo)
			throws SQLException {
		String finalCustNo = "";
		String sql = CoreXmlSqlParsersFactory
				.getSql("ICustSpecialAskDao.getFinalCustomer");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, custAlphaNo);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			finalCustNo = rs.getString("CHEM_ALPHA_NO");
		}
		rs.close();
		ps.close();
		return finalCustNo;
	}

	/**
	 * 查询最终客户
	 * 
	 * @param con
	 * @param userCode
	 *            用途码
	 * @return List<String>
	 * @throws SQLException
	 */
	public List<String> getFinalCusts(Connection con, String userCode)
			throws SQLException {
		List<String> finalCusts = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("ICustSpecialAskDao.getFinalCusts");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, userCode);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			finalCusts.add(rs.getString("CUST_CODE"));
		}
		rs.close();
		ps.close();
		return finalCusts;
	}

	/**
	 * 查询产品码的信息
	 * 
	 * @param con
	 *            连接字符串
	 * @param psc
	 *            产品码
	 * @return String
	 * @throws SQLException
	 */
	public ComPscEntity getPscInfo(Connection con, String psc)
			throws SQLException {

		String sql = CoreXmlSqlParsersFactory
				.getSql("ICustSpecialAskDao.getPscInfo");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, psc);
		ResultSet rs = ps.executeQuery();
		List<ComPscEntity> pscInfo = QualityDesignTool.getEntitysByRs(rs,
				ComPscEntity.class);
		rs.close();
		ps.close();
		if (pscInfo != null && pscInfo.size() != 0) {
			QualityDesignTool.nullConverNullString(pscInfo.get(0));
			return pscInfo.get(0);
		} else {
			return null;
		}
	}

}
