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

/**
 * 产线删除
 * 
 * @author Administrator
 * 
 */
public class DeleteLineDao {

	/**
	 * 查询质量设计产线结果
	 * 
	 * @return
	 * @throws SQLException
	 */
	public List<CraftOrdDesignMscPlGxPrlEntity> getQualityDesignLine(
			Connection con, String ordLnPk) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DeleteLineDao.getQualityDesignLine");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, ordLnPk);
		ResultSet rs = ps.executeQuery();
		List<CraftOrdDesignMscPlGxPrlEntity> list = EntityTool.getEntitysByRs(
				rs, CraftOrdDesignMscPlGxPrlEntity.class);
		rs.close();
		ps.close();
		if (list != null && list.size() > 0) {
			for (CraftOrdDesignMscPlGxPrlEntity craftOrdDesignMscPlGxPrlEntity : list) {
				CraftTool.nullConverNullString(craftOrdDesignMscPlGxPrlEntity);
			}
			return list;
		} else {
			return null;
		}
	}
	
	/**
	 * 查询质量设计被禁用的产线
	 * @param con
	 * @param ordLnPk
	 * @return
	 */
	public ArrayList<String> getQualityDesignLine2(
			Connection con, String ordLnPk){
		SqlBuilder b = new SqlBuilder("DeleteLineDao.getQualityDesignLine2");
		b.Fill(new String[]{ordLnPk});
	    ArrayList<CraftOrdDesignMscPlGxPrlEntity> disablePlines = EntityTool.getEntitysBySqlNoClsCon(
	    		b.toString(), con, CraftOrdDesignMscPlGxPrlEntity.class);
		ArrayList<String> plines = new ArrayList<String>();
		for(CraftOrdDesignMscPlGxPrlEntity disablePline : disablePlines){
			plines.add(disablePline.getPlineCode());
		}
		
		return plines;
	}

	/**
	 * 删除工艺评审产线
	 * 
	 * @param con
	 * @param designKey
	 * @param mscPline
	 * @param processCode
	 * @param plineCode
	 * @throws SQLException
	 */
	public void deleteCraftLine(Connection con, String designKey,
			String mscPline, String processCode, String plineCode)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("DeleteLineDao.deleteCraftLine");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, mscPline);
		ps.setObject(3, processCode);
		ps.setObject(4, plineCode);
		ps.executeUpdate();
		ps.close();
	}

}
