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 CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.pss.sale.order.model.SlmBaseAddAskEntity;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.AddAskDaoImp;
import com.steering.pss.sale.order.qualityDesign.model.ComBaseAdditionalEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignAddAskStsEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrderAddAskEntity;

public class IAddAskDao implements AddAskDaoImp {
	/**
	 * 合同附加要求状态
	 * 
	 * @param con
	 *            连接字符串
	 * @param addAskNo
	 *            附加要求编号
	 * @return String
	 * @throws SQLException
	 */
	public List<String> getAddAskStatus(Connection con, String addAskNo)
			throws SQLException {
		List<String> statuses = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("IAddAskDao.getAddAskStatus");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, addAskNo);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String status = "";
			if (rs.getString("ADD_ASK_STATUS") == null) {
				status = "";
			} else {
				status = rs.getString("ADD_ASK_STATUS");
			}

			statuses.add(status);
		}
		rs.close();
		ps.close();
		return statuses;
	}
	
	/**
	 * 获取销售附加要求
	 * @param con
	 * @param addAskNo
	 * @return
	 */
	public ArrayList<SlmOrderAddAskEntity> getOrderAddAsk(Connection con,
			String addAskNo){
		SqlBuilder b = new SqlBuilder("IAddAskDao.getOrderAddAsk");
		b.Fill(new String[]{ addAskNo });
		return EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, SlmOrderAddAskEntity.class);
	}
	
	/**
	 * 获取标准附加要求
	 * @param con
	 * @param stdCode
	 * @return
	 */
	public ArrayList<ComBaseAdditionalEntity> getStdAddAsk(Connection con,
			String stdCode){
		SqlBuilder b = new SqlBuilder("IAddAskDao.getStdAddAsk");
		b.Fill(new String[]{ stdCode });
		return EntityTool.getEntitysBySqlNoClsCon(
				b.toString(), con, ComBaseAdditionalEntity.class);
	}
	
	/**
	 * 获取基础附加要求
	 * @param con
	 * @param askItemNo
	 * @return
	 */
	public SlmBaseAddAskEntity getBaseAddAsk(Connection con,
			String askItemNo){
		SqlBuilder b = new SqlBuilder("IAddAskDao.getBaseAddAsk");
		b.Fill(new String[]{ askItemNo });
		return EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, SlmBaseAddAskEntity.class);
	}
	
	/**
	 * 获取附加要求评审状态
	 * @param con
	 * @param ordLnPk
	 * @return
	 */
	public SlmOrdDesignAddAskStsEntity getDesignAddAskSts(Connection con,
			String ordLnPk){
		SqlBuilder b = new SqlBuilder("IAddAskDao.getDesignAddAskSts");
		b.Fill(new String[]{ ordLnPk });
		return EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, SlmOrdDesignAddAskStsEntity.class);
	}
}
