package com.steering.pss.sale.base;

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

import com.steering.comm.db.DBCommon;

/**
 * 专用线基础信息管理类
 * @author WQ 2014/10/16
 * @version v1.0
 * @modify
 */
public class CoreSpeclLine extends DBCommon {
	
	
	
	/**
	 * 判断用户名是否重复
	 * @param name
	 * @return
	 */
	public CoreReturnObject GetMaxCode(String stationCode) {
		Object[] obj = new Object[] { stationCode };
		return this.getDataBySqlID("CoreSpeclLine.GetMaxCode", obj);
	}
	
	
	/**
	 * 获取到站分类信息
	 * @param name
	 * @return
	 */
	public CoreReturnObject GetStation()
	{
		return this.getDataBySqlID("CoreSpeclLine.GetStation");
	}
	
	/**
	 * 判断用户名是否重复
	 * @param name
	 * @return
	 */
	public CoreReturnObject isRepeatName(String name) {
		Object[] obj = new Object[] { name };
		return this.getDataBySqlID("CoreSpeclLine.isRepeatName", obj);
	}
	
	/**
     * 专用线基础信息查询
     * @param includeDeleted 是否包含已删除数据
     * @param name 专用线描述
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
	public CoreReturnObject doQuery(Boolean includeDeleted,
            String name) {
        String deletedFlag = includeDeleted ? "0" : "";
        Object[] params = new Object[] { deletedFlag, name};
        return this.getDataBySqlID("CoreSpeclLine.QUERY", params);
	}
	
	/**
     * 专用线基础信息新增
     * @param parm 参数
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
	public CoreReturnObject doAdd(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory.getSql("CoreSpeclLine.ADD");
		try {
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}
	
	/**
     * 专用线基础信息修改
     * @param parm 参数
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
	public CoreReturnObject doUpdate(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory.getSql("CoreSpeclLine.UPDATE");
		try {
			cro = this.getDao(CoreConstantData.sysbeanstr).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("CoreSpeclLine.DELETE");
                params.add(new Object[] { operator,
                        plineCodes.get(i).toString() });
            }
            else {
                sqlIDList.add("CoreSpeclLine.RESUME");
                params.add(new Object[] { plineCodes.get(i).toString() });
            }
        }
		return this.setDataById(sqlIDList, params);
	}
}
