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.craftDesign.tool.CraftTool;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.JGplDaoImp;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignMscJgPlEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignMscJgPlStiEntity;

public class IJGplDao implements JGplDaoImp {
	/**
	 * 查询接箍制程
	 * 
	 * @param con
	 * @param jgCode
	 * @return
	 * @throws SQLException
	 */
	public SlmOrdDesignMscJgPlEntity getJGpl(Connection con, String jgCode)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("IJGplDao.getJGpl");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, jgCode);
		ResultSet rs = ps.executeQuery();
		List<SlmOrdDesignMscJgPlEntity> list = EntityTool.getEntitysByRs(rs,
				SlmOrdDesignMscJgPlEntity.class);
		rs.close();
		ps.close();
		if (list != null && list.size() > 0) {
			for (SlmOrdDesignMscJgPlEntity slmOrdDesignMscJgPlEntity : list) {
				QualityDesignTool
						.nullConverNullString(slmOrdDesignMscJgPlEntity);
			}
			return list.get(0);
		} else {
			return null;
		}
	}

	/**
	 * 保存接箍制程
	 * 
	 * @param con
	 * @param jgplEntity
	 * @throws SQLException
	 */
	public void saveJGpl(Connection con, SlmOrdDesignMscJgPlEntity jgplEntity)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("IJGplDao.saveJGpl");
		sql = EntityTool.fillSqlByEntity(sql, jgplEntity);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 查询接箍制程工序点
	 * 
	 * @param con
	 * @param jgCode
	 * @param mscPline
	 * @return
	 * @throws SQLException
	 */
	public List<SlmOrdDesignMscJgPlStiEntity> getJGPlSti(Connection con,
			String jgCode, String mscPline) throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("MscJGPlDao.getJGPlSti");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, jgCode);
		ps.setObject(2, mscPline);
		ResultSet rs = ps.executeQuery();
		List<SlmOrdDesignMscJgPlStiEntity> list = EntityTool.getEntitysByRs(rs,
				SlmOrdDesignMscJgPlStiEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (SlmOrdDesignMscJgPlStiEntity craftOrdDesignMscPlStiEntity : list) {
				CraftTool.nullConverNullString(craftOrdDesignMscPlStiEntity);
			}
			return list;
		}
	}

	/**
	 * 保存接箍制程工序点
	 * 
	 * @param con
	 * @param mscPlStiEntity
	 * @throws SQLException
	 */
	public void saveJGPlSti(Connection con,
			SlmOrdDesignMscJgPlStiEntity mscPlStiEntity) throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("IJGplDao.saveJGPlSti");
		sql = EntityTool.fillSqlByEntity(sql, mscPlStiEntity);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 保存结箍的产线
	 * 
	 * @param con
	 * @param plineCode
	 * @param plineName
	 * @throws SQLException
	 */
	public void saveJGLine(Connection con, String designKey, String mscPline,
			String plineCode, String plineName, String wellCode, String wellDesc)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("IJGplDao.saveJGLine");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, mscPline);
		ps.setObject(3, "H");
		ps.setObject(4, plineCode);
		ps.setObject(5, plineName);
		ps.setObject(6, wellCode);
		ps.setObject(7, wellDesc);
		ps.executeUpdate();
		ps.close();
	}
}
