package com.steering.pss.sale.order.craftDesign.dao;

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.model.CraftOrdDesignMscJgPlEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscJgPlStiEntity;
import com.steering.pss.sale.order.craftDesign.tool.CraftTool;

/**
 * 工艺评审-接箍制程
 * 
 * @author Administrator
 * 
 */
public class MscJGPlDao {
	/**
	 * 查询接箍制程
	 * 
	 * @param con
	 * @param jgCode
	 * @return
	 * @throws SQLException
	 */
	public CraftOrdDesignMscJgPlEntity getJGpl(Connection con, String jgCode)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("MscJGplDao.getJGpl");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, jgCode);
		ResultSet rs = ps.executeQuery();
		List<CraftOrdDesignMscJgPlEntity> list = EntityTool.getEntitysByRs(rs,
				CraftOrdDesignMscJgPlEntity.class);
		rs.close();
		ps.close();
		if (list != null && list.size() > 0) {
			for (CraftOrdDesignMscJgPlEntity slmOrdDesignMscJgPlEntity : list) {
				CraftTool.nullConverNullString(slmOrdDesignMscJgPlEntity);
			}
			return list.get(0);
		} else {
			return null;
		}
	}

	/**
	 * 保存接箍制程
	 * 
	 * @param con
	 * @param jgplEntity
	 * @throws SQLException
	 */
	public void saveJGpl(Connection con, CraftOrdDesignMscJgPlEntity jgplEntity)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("MscJGplDao.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<CraftOrdDesignMscJgPlStiEntity> 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<CraftOrdDesignMscJgPlStiEntity> list = EntityTool.getEntitysByRs(
				rs, CraftOrdDesignMscJgPlStiEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (CraftOrdDesignMscJgPlStiEntity craftOrdDesignMscPlStiEntity : list) {
				CraftTool.nullConverNullString(craftOrdDesignMscPlStiEntity);
			}
			return list;
		}
	}

	/**
	 * 保存接箍制程工序点
	 * 
	 * @param con
	 * @param mscPlStiEntity
	 * @throws SQLException
	 */
	public void saveJGPlSti(Connection con,
			CraftOrdDesignMscJgPlStiEntity mscPlStiEntity) throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("MscJGplDao.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("MscJGplDao.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();
	}

}
