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;

/**
 * 扣型基础信息管理类
 * @author WQ 2014/10/16
 * @version v1.0
 * @modify
 */
public class CoreBuckleType extends DBCommon {
	
	/**
	 * 获取扣型分类代码和描述
	 * @return
	 */
	public CoreReturnObject GetKType() {
		return this.getDataBySqlID("CoreBuckleType.GetKType");
	}
	
	
	/**
	 * 获取扣型代码最大值
	 * @param name
	 * @return
	 */
	public CoreReturnObject GetMaxCode() {
		return this.getDataBySqlID("CoreBuckleType.GetMaxCode");
	}
	
	
	/**
	 * 判断用户名是否重复
	 * @param name
	 * @return
	 */
	public CoreReturnObject GetName(String name) {
		Object[] obj = new Object[] { name };
		return this.getDataBySqlID("CoreBuckleType.GetName", obj);
	}
	
	/**
     * 扣型基础信息查询
     * @param includeDeleted 是否包含已删除数据
     * @param name 扣型描述
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
	public CoreReturnObject getLineList(Boolean includeDeleted,
            String name) {
        String deletedFlag = includeDeleted ? "0" : "";
        Object[] params = new Object[] { deletedFlag, name};
        return this.getDataBySqlID("CoreBuckleType.QUERY", params);
	}
	
	/**
     * 扣型基础信息新增
     * @param parm 参数
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
	public CoreReturnObject doAdd(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory.getSql("CoreBuckleType.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("CoreBuckleType.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("CoreBuckleType.DELETE");
                params.add(new Object[] { operator,
                        plineCodes.get(i).toString() });
            }
            else {
                sqlIDList.add("CoreBuckleType.RESUME");
                params.add(new Object[] { plineCodes.get(i).toString() });
            }
        }
		return this.setDataById(sqlIDList, params);
	}
}
