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

/**
 * 工序点类
 * 
 * @author Administrator
 * 
 */
public class OperationPointDao {

	/**
	 * 查询工序点
	 * 
	 * @param con
	 *            连接字符串
	 * @param msc
	 *            冶金规范码
	 * @param mscPline
	 *            全程产线号
	 * @param processCode
	 *            工序
	 * @return
	 * @throws SQLException
	 */
	public List<CraftOrdDesignMscPlStiEntity> getOperationPoint(Connection con,
			String msc, String mscPline, String processCode)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("OperationPointDao.getOperationPoint");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, mscPline);
		ps.setObject(3, processCode);
		ResultSet rs = ps.executeQuery();
		List<CraftOrdDesignMscPlStiEntity> points = EntityTool.getEntitysByRs(
				rs, CraftOrdDesignMscPlStiEntity.class);
		rs.close();
		ps.close();
		if (points != null && points.size() > 0) {
			for (CraftOrdDesignMscPlStiEntity point : points) {
				CraftTool.nullConverNullString(point);
			}
			return points;
		} else {
			return null;
		}
	}

	/**
	 * 保存工序点
	 * 
	 * @param con
	 *            连接字符串
	 * @param operationPoint
	 *            工序点类
	 * @throws SQLException
	 */
	public void saveOperationPoint(java.sql.Connection con,
			CraftOrdDesignMscPlStiEntity point) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("OperationPointDao.saveOperationPoint");
		sql = EntityTool.fillSqlByEntity(sql, point);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

}
