package com.steering.pss.sale.base;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.db.DBCommon;

import java.sql.SQLException;
import java.util.ArrayList;

/**
 * 销售组织及片区基础信息管理类
 * @author WQ 2014/10/16
 * @version v1.0
 * @modify
 */
public class CoreSaleRegion extends DBCommon {
	
	/**
	 * 获取销售组织数据源。
	 * @param name
	 * @return
	 */
	public CoreReturnObject GetSaleRegion()
	{
		return this.getDataBySqlID("CoreSaleRegion.GetSaleRegion");
	}
	
	/**
	 * 获取销售组织科室名称。
	 * @param name
	 * @return
	 */
	public CoreReturnObject GetDEPARTNAME(String depatiId)
	{
		Object[] obj=new Object[]{depatiId};
		return this.getDataBySqlID("CoreSaleRegion.GetDEPARTNAME",obj);
	}
	public CoreReturnObject GetDepartNameLike(String depatiId)
	{
		Object[] obj=new Object[]{depatiId};
		return this.getDataBySqlID("CoreSaleRegion.GetDepartNameLike",obj);
	}
	
	/**
	 * 获取销售组织业务片区代码最大值
	 * @param name
	 * @return
	 */
	public CoreReturnObject GetMaxCode(String saleRegionCode) {
		Object[] obj = new Object[] { saleRegionCode };
		return this.getDataBySqlID("CoreSaleRegion.GetMaxCode", obj);
	}
	
	
	
	
	/**
	 * 判断用户名是否重复
	 * @param name
	 * @return
	 */
	public CoreReturnObject isRepeatName(String name,String saleRegionCode,String deaPid) {
		Object[] obj = new Object[] { name,saleRegionCode,deaPid };
		return this.getDataBySqlID("CoreSaleRegion.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};
        return this.getDataBySqlID("CoreSaleRegion.QUERY", params);
	}
	
	/**
     * 销售组织及片区基础信息新增
     * @param parm 参数
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
	public CoreReturnObject doAdd(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory.getSql("CoreSaleRegion.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("CoreSaleRegion.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("CoreSaleRegion.DELETE");
                params.add(new Object[] { operator,
                        plineCodes.get(i).toString() });
            }
            else {
                sqlIDList.add("CoreSaleRegion.RESUME");
                params.add(new Object[] { plineCodes.get(i).toString() });
            }
        }
		return this.setDataById(sqlIDList, params);
	}
}
