package com.steering.pss.qcm;

import java.sql.SQLException;
import java.util.ArrayList;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;

/**
 * 镦拨扩基础信息管理类
 * 
 * @author WQ 2014/10/16
 * @version v1.0
 * @modify
 */
public class CoreUpsettingDialExpansion extends DBCommon {

	/**
	 * 判断产线、钢种外径壁厚是否唯一
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject isOnlyAdd(ArrayList<Object> parm) {
		Object[] obj = parm.toArray();
		return this.getDataBySqlID("CoreUpsettingDialExpansion.isOnlyAdd", obj);
	}

	/**
	 * 判断产线、钢种外径壁厚是否唯一
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject isOnlyUpdate(ArrayList<Object> parm) {
		Object[] obj = parm.toArray();
		return this.getDataBySqlID("CoreUpsettingDialExpansion.isOnlyUpdate",
				obj);
	}

	/**
	 * 获取序号最大值
	 * 
	 * @return
	 */
	public CoreReturnObject GetMaxSeq() {
		return this.getDataBySqlID("CoreUpsettingDialExpansion.GetMaxSeq");
	}

	/**
	 * 获取钢种代码和描述
	 * 
	 * @return
	 */
	public CoreReturnObject GetGZType() {
		return this.getDataBySqlID("CoreUpsettingDialExpansion.GetGZType");
	}

	/**
	 * 获取产线代码和描述
	 * 
	 * @return
	 */
	public CoreReturnObject GetProLineInfo() {
		return this.getDataBySqlID("CoreUpsettingDialExpansion.GetProLineInfo");
	}

	/**
	 * 镦拨扩基础信息查询
	 * 
	 * @param includeDeleted
	 *            是否包含已删除数据
	 * @param name
	 *            镦拨扩描述
	 * @return CoreReturnObject 必须返回CoreReturnObject
	 */
	public CoreReturnObject getLineList(ArrayList<String> list) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("CoreUpsettingDialExpansion.QUERY");
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", list.get(0));
		sql = StringTool.ReplaceAll(sql, "#PLINE_NAME#", list.get(1));
		sql = StringTool.ReplaceAll(sql, "#GRADECODE#", list.get(2));
		sql = StringTool.ReplaceAll(sql, "#DIMATER#", list.get(3));
		sql = StringTool.ReplaceAll(sql, "#HEIGHT#", list.get(4));

		return this.getData(sql);
	}

	/**
	 * 镦拨扩基础信息新增
	 * 
	 * @param parm
	 *            参数
	 * @return CoreReturnObject 必须返回CoreReturnObject
	 */
	public CoreReturnObject doAdd(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory
				.getSql("CoreUpsettingDialExpansion.ADD");
		try {
			cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}

	/**
	 * 镦拨扩基础信息修改
	 * 
	 * @param parm
	 *            参数
	 * @return CoreReturnObject 必须返回CoreReturnObject
	 */
	public CoreReturnObject doModify(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory
				.getSql("CoreUpsettingDialExpansion.MODIFY");
		try {
			cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}

	/**
	 * 镦拨扩基础信息删除或恢复
	 * 
	 * @param plineCodes
	 *            产线代码集合
	 * @param operator
	 *            操作人
	 * @param isDelete
	 *            true删除 false恢复
	 * @return CoreReturnObject 必须返回CoreReturnObject
	 */
	public CoreReturnObject deleteLineInfo(ArrayList<Object> plineCodes,
			String operator, Boolean isDelete) {
		ArrayList<String> sqlIDList = new ArrayList<String>();
		ArrayList<Object[]> params = new ArrayList<Object[]>();
		for (int i = 0; i < plineCodes.size(); i++) {
			if (isDelete) {
				sqlIDList.add("CoreUpsettingDialExpansion.DELETE");
				params.add(new Object[] { operator,
						plineCodes.get(i).toString() });
			} else {
				sqlIDList.add("CoreUpsettingDialExpansion.RESUME");
				params.add(new Object[] { plineCodes.get(i).toString() });
			}
		}
		return this.setDataById(sqlIDList, params);
	}

	/**
	 * 是否存在规格
	 * 
	 * @return
	 */
	public CoreReturnObject isExistSpec(String dimater, String height) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("CoreUpsettingDialExpansion.isExistSpec");
		sql = StringTool.ReplaceAll(sql, "#DIMATER#", dimater);
		sql = StringTool.ReplaceAll(sql, "#HEIGHT#", height);
		return this.getData(sql);
	}

	/**
	 * 初始化规格
	 * 
	 * @param parm
	 * @return
	 */
	public CoreReturnObject getSpec() {
		return this.getDataBySqlID("CoreUpsettingDialExpansion.getSpec");
	}
}
