package com.steering.pss.sale.order.qualityDesign.Dao.idao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.pss.sale.order.model.DesignStatusEntity;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.StatusDaoImp;
import com.steering.pss.sale.order.qualityDesign.ReturnsModel.DesignEntity;

/**
 * 设计状态 操作数据库类
 * 
 * @author Administrator
 * 
 */
public class IStatusDao implements StatusDaoImp {
	/**
	 * 增加设计状态 （合同行）
	 * 
	 * @param con
	 *            连接字符串
	 * @param designKey
	 *            designKey
	 * @param ordLnPk
	 *            合同行
	 * @param userName
	 *            操作人
	 * @throws SQLException
	 */
	public void addDesignStsTklg(Connection con, String designKey,
			String ordLnPk, String userName) throws SQLException {
		if (designKey.equals("") || ordLnPk.equals("")) {
			return;
		}
		String sql = CoreXmlSqlParsersFactory
				.getSql("IStatusDao.addDesignStsTklg");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, ordLnPk);
		ps.setObject(3, userName);
		ps.executeUpdate();
		ps.close();

	}

	/**
	 * 修改设计状态（合同行）
	 * 
	 * @param con
	 *            连接字符串
	 * @param designKey
	 *            designKey
	 * @param userName
	 *            操作人
	 * @param designSts
	 *            设计状态 (W:等待;S:通过;F:失败)
	 * @param prdcycMeet
	 *            生产周期满足(W:等待;S:满足;F:不满足)
	 * @throws SQLException
	 */
	public void updateDesignStsTklg(Connection con, String designKey,
			String userName, String designSts, String prdcycMeet)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("IStatusDao.updateDesignStsTklg");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designSts);
		ps.setObject(2, prdcycMeet);
		ps.setObject(3, userName);
		ps.setObject(4, designKey);
		ps.executeUpdate();
		ps.close();

	}

	/**
	 * 修改 技术设计状态明细
	 * 
	 * @param con
	 *            连接字符串
	 * @param comDesign
	 *            设计状态明细类
	 * @throws SQLException
	 *             异常
	 */
	public void updateDesignStatus(Connection con, DesignStatusEntity status)
			throws SQLException {
		if (status == null) {
			return;
		}
		String sql = CoreXmlSqlParsersFactory
				.getSql("IStatusDao.updateDesignStatus");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, status.getDesignSts());
		ps.setObject(2, status.getDesignStsRs());
		ps.setObject(3, status.getDesignStsDesc());
		ps.setObject(4, status.getMsc());
		ps.setObject(5, status.getUseCode());
		ps.setObject(6, status.getGradecode());
		ps.setObject(7, status.getDesignObjKey());
		ps.setObject(8, status.getUnitCode());
		ps.setObject(9, status.getUnitDesc());
		ps.setObject(10, status.getUpdateName());
		ps.setObject(11, status.getPsc());
		ps.setObject(12, status.getDesginKey());
		ps.setObject(13, status.getOrdLnPk());
		ps.setObject(14, status.getLstItem());

		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 新增 技术设计状态明细
	 * 
	 * @param con
	 *            连接字符串
	 * @param comDesign
	 *            设计状态明细类
	 * @return void
	 * @throws SQLException
	 *             异常
	 */
	public void addDesignStatus(Connection con, DesignStatusEntity status)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("IStatusDao.addDesignStatus");
		sql = sql.replaceAll("#DESGIN_KEY#", status.getDesginKey());
		sql = sql.replaceAll("#ORD_LN_PK#", status.getOrdLnPk());
		sql = sql.replaceAll("#SEQ_INDEX#", status.getSeqIndex());
		sql = sql.replaceAll("#LST_ITEM#", status.getLstItem());
		sql = sql.replaceAll("#DESIGN_STS#", status.getDesignSts());
		sql = sql.replaceAll("#DESIGN_STS_RS#", status.getDesignStsRs());
		sql = sql.replaceAll("#DESIGN_STS_DESC#", status.getDesignStsDesc());
		sql = sql.replaceAll("#PSC#", status.getPsc());
		sql = sql.replaceAll("#MSC#", status.getMsc());
		sql = sql.replaceAll("#USE_CODE#", status.getUseCode());
		sql = sql.replaceAll("#FINAL_USER#", status.getFinalUser());
		sql = sql.replaceAll("#GRADECODE#", status.getGradecode());
		sql = sql.replaceAll("#DESIGN_OBJ_KEY#", status.getDesignObjKey());
		sql = sql.replaceAll("#UNIT_CODE#", status.getUnitCode());
		sql = sql.replaceAll("#UNIT_DESC#", status.getUnitDesc());
		sql = sql.replaceAll("#CREATE_NAME#", status.getCreateName());
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 状态实体类赋值
	 * 
	 * @param reDesign
	 *            常用值实体类
	 * @param msc
	 *            冶金規范碼
	 * @param lstItem
	 *            明细项目
	 * @param designSts
	 *            设计状态
	 * @param designStsRs
	 *            设计状态原因
	 * @param designStsDesc
	 *            设计状态结果描述
	 * @param designObjKey
	 *            设计对象Key值
	 * @param unitCode
	 *            管理科室代码
	 * @param unitDesc
	 *            管理科室描述
	 * @return
	 */
	public DesignStatusEntity setDesignStatus(DesignEntity designEntity,
			String msc, String lstItem, String designSts, String designStsRs,
			String designStsDesc, String designObjKey, String unitCode,
			String unitDesc) {
		DesignStatusEntity status = new DesignStatusEntity();
		status.setDesginKey(designEntity.getDesignKey());
		status.setOrdLnPk(designEntity.getOrdLnPk());
		status.setLstItem(lstItem);
		status.setPsc(designEntity.getPsc());
		status.setMsc(msc);
		status.setDesignSts(designSts);
		status.setDesignStsRs(designStsRs);
		status.setDesignStsDesc(designStsDesc);
		status.setFinalUser(designEntity.getFinalUser());
		status.setDesignObjKey(designObjKey);
		status.setUnitCode(unitCode);
		status.setUnitDesc(unitDesc);
		status.setCreateName(designEntity.getUserName());
		status.setUpdateName(designEntity.getUserName());
		return status;
	}

}
