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.List;

import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.tools.EntityTool;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import com.steering.pss.sale.order.qualityDesign.model.ComBaseAdditionalEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignAddAskDiffEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignCicDiffEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignDicDiffEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignGicDiffEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignPicDiffEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignSicDiffEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignStdCicEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignStdDicEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignStdGicEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignStdPicEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignStdSicEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignStdWicEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignWicDiffEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrderAddAskEntity;

public class DifferenceValueDao {
	/**
	 * 交付标准 成分
	 * 
	 * @param con
	 * @param designKey
	 * @param flag
	 * @return
	 * @throws SQLException
	 */
	public List<SlmOrdDesignStdCicEntity> getChem(Connection con,
			String designKey, String flag) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.getChem");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, flag);
		ResultSet rs = ps.executeQuery();
		List<SlmOrdDesignStdCicEntity> list = EntityTool.getEntitysByRs(rs,
				SlmOrdDesignStdCicEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (SlmOrdDesignStdCicEntity slmOrdDesignStdCicEntity : list) {
				QualityDesignTool
						.nullConverNullString(slmOrdDesignStdCicEntity);
			}
			return list;
		}
	}

	/**
	 * 保存成分标准差值
	 * 
	 * @param con
	 * @param cicEntity
	 * @throws SQLException
	 */
	public void addChem(Connection con, SlmOrdDesignCicDiffEntity cicEntity)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.addChem");
		sql = EntityTool.fillSqlByEntity(sql, cicEntity);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 交付标准 理化
	 * 
	 * @param con
	 * @param designKey
	 * @param flag
	 * @return
	 * @throws SQLException
	 */
	public List<SlmOrdDesignStdPicEntity> getPhy(Connection con,
			String designKey, String flag) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.getPhy");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, flag);
		ResultSet rs = ps.executeQuery();
		List<SlmOrdDesignStdPicEntity> list = EntityTool.getEntitysByRs(rs,
				SlmOrdDesignStdPicEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (SlmOrdDesignStdPicEntity slmOrdDesignStdPicEntity : list) {
				QualityDesignTool
						.nullConverNullString(slmOrdDesignStdPicEntity);
			}
			return list;
		}
	}

	/**
	 * 保存理化标准差值
	 * 
	 * @param con
	 * @param cicEntity
	 * @throws SQLException
	 */
	public void addPhy(Connection con, SlmOrdDesignPicDiffEntity picEntity)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.addPhy");
		sql = EntityTool.fillSqlByEntity(sql, picEntity);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 交付标准 水压
	 * 
	 * @param con
	 * @param designKey
	 * @param flag
	 * @return
	 * @throws SQLException
	 */
	public SlmOrdDesignStdWicEntity getWater(Connection con, String designKey,
			String flag) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.getWater");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, flag);
		ResultSet rs = ps.executeQuery();
		List<SlmOrdDesignStdWicEntity> list = EntityTool.getEntitysByRs(rs,
				SlmOrdDesignStdWicEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (SlmOrdDesignStdWicEntity slmOrdDesignStdWicEntity : list) {
				QualityDesignTool
						.nullConverNullString(slmOrdDesignStdWicEntity);
			}
			return list.get(0);
		}
	}

	/**
	 * 保存水压标准差值
	 * 
	 * @param con
	 * @param cicEntity
	 * @throws SQLException
	 */
	public void addWater(Connection con, SlmOrdDesignWicDiffEntity wicEntity)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.addWater");
		sql = EntityTool.fillSqlByEntity(sql, wicEntity);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 交付标准 探伤
	 * 
	 * @param con
	 * @param designKey
	 * @param flag
	 * @return
	 * @throws SQLException
	 */
	public List<SlmOrdDesignStdDicEntity> getDete(Connection con,
			String designKey, String flag) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.getDete");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, flag);
		ResultSet rs = ps.executeQuery();
		List<SlmOrdDesignStdDicEntity> list = EntityTool.getEntitysByRs(rs,
				SlmOrdDesignStdDicEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (SlmOrdDesignStdDicEntity slmOrdDesignStdDicEntity : list) {
				QualityDesignTool
						.nullConverNullString(slmOrdDesignStdDicEntity);
			}
			return list;
		}
	}

	/**
	 * 保存探伤标准差值
	 * 
	 * @param con
	 * @param cicEntity
	 * @throws SQLException
	 */
	public void addDete(Connection con, SlmOrdDesignDicDiffEntity dicEntity)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.addDete");
		sql = EntityTool.fillSqlByEntity(sql, dicEntity);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 查询加工 标准
	 * 
	 * @param con
	 * @param designKey
	 * @param flag
	 * @return
	 * @throws SQLException
	 */
	public List<SlmOrdDesignStdGicEntity> getGprocess(Connection con,
			String designKey, String flag) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.getGprocess");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, flag);
		ResultSet rs = ps.executeQuery();
		List<SlmOrdDesignStdGicEntity> list = EntityTool.getEntitysByRs(rs,
				SlmOrdDesignStdGicEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			return list;
		}
	}

	/**
	 * 保存加工标准差值
	 * 
	 * @param con
	 * @param cicEntity
	 * @throws SQLException
	 */
	public void addGprocess(Connection con, SlmOrdDesignGicDiffEntity gicEntity)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.addGprocess");
		sql = EntityTool.fillSqlByEntity(sql, gicEntity);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 查询公差 标准
	 * 
	 * @param con
	 * @param designKey
	 * @param flag
	 * @return
	 * @throws SQLException
	 */
	public List<SlmOrdDesignStdSicEntity> getSpec(Connection con,
			String designKey, String flag) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.getSpec");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, flag);
		ResultSet rs = ps.executeQuery();
		List<SlmOrdDesignStdSicEntity> list = EntityTool.getEntitysByRs(rs,
				SlmOrdDesignStdSicEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			return list;
		}
	}

	/**
	 * 保存公差标准差值
	 * 
	 * @param con
	 * @param cicEntity
	 * @throws SQLException
	 */
	public void addSpec(Connection con, SlmOrdDesignSicDiffEntity sicEntity)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.addSpec");
		sql = EntityTool.fillSqlByEntity(sql, sicEntity);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 查询标准附加要求
	 * 
	 * @param con
	 * @param stdCode
	 * @return
	 * @throws SQLException
	 */
	public List<ComBaseAdditionalEntity> getStdAddAsk(Connection con,
			String stdCode) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.getStdAddAsk");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, stdCode);
		ResultSet rs = ps.executeQuery();
		List<ComBaseAdditionalEntity> list = EntityTool.getEntitysByRs(rs,
				ComBaseAdditionalEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			return list;
		}
	}

	/**
	 * 查询客户附加要求
	 * 
	 * @param con
	 * @param stdCode
	 * @return
	 * @throws SQLException
	 */
	public List<SlmOrderAddAskEntity> getAlphaAddAsk(Connection con,
			String addAskNo) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.getAlphaAddAsk");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, addAskNo);
		ResultSet rs = ps.executeQuery();
		List<SlmOrderAddAskEntity> list = EntityTool.getEntitysByRs(rs,
				SlmOrderAddAskEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			return list;
		}
	}

	/**
	 * 保存附加要求标准差值
	 * 
	 * @param con
	 * @param cicEntity
	 * @throws SQLException
	 */
	public void addAddAsk(Connection con, SlmOrdDesignAddAskDiffEntity addEntity)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DifferenceValueDao.addAddAsk");
		sql = EntityTool.fillSqlByEntity(sql, addEntity);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

}
