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 com.steering.comm.db.DBCommon;

public class CoreStation extends DBCommon {
	/**
	 * 获取到站基础信息维护
	 * @param  rawy_buru, station_nm, validflag
	 * @return
	 */
	public CoreReturnObject ToQuery(String rawy_buru,String station_nm,String validflag) {
		String sql = "SELECT station_no, station_nm,  (SELECT REGION_NM FROM sel_admin_region WHERE region_no = st.region_no) region_nm,region_no, run_direct, distance, freight,"+
					 "telegrp_no,(SELECT basename FROM com_base_info WHERE basecode = st.rawy_buru) rawy_buru, memo, validflag,rawy_buru rawy_buru_no, create_name,"+
					 "TO_CHAR (create_time, 'yyyy-mm-dd hh24:mi:ss') create_time, update_name, TO_CHAR (update_time, 'yyyy-mm-dd hh24:mi:ss') update_time,delete_name, TO_CHAR (delete_time,'yyyy-mm-dd hh24:mi:ss') delete_time"+
					 " FROM slm_base_station st WHERE 1 = 1 "+rawy_buru+station_nm+validflag;
	 
		return this.getData(sql);
	}
	/**
	 * 获取所属铁路局 
	 */
	public CoreReturnObject GetRegIonCode() { 
		return this.getDataBySqlID("CoreStation.doQuerySlmBaseSta");
	}
	/**
	 * 获取数据是否重复 
	 */
	public CoreReturnObject GetQuerySave(String name) { 
		Object[] params = new Object[] {name};
		return this.getDataBySqlID("CoreStation.doQuerySave",params);
	} 
	/**
	 * 新增
	 */
	public CoreReturnObject SetAddStation(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory.getSql("CoreStation.toAdd");
		try {
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}
	/**
	 * 更新数据
	 */
	public CoreReturnObject SetUpdateStation(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory.getSql("CoreStation.doUpdate");
		try {
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}
	/**
	 * 作废
	 */
	public CoreReturnObject SetDeleteStation(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory.getSql("CoreStation.doDelete");
		try {
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}
	/**
	 * 恢复
	 */
	public CoreReturnObject SetRecoveryStation(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory.getSql("CoreStation.doRecovery");
		try {
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}
	/**
	 * 获取树形结构
	 * @param name
	 * @return
	 */
	public CoreReturnObject GetTivCode() {
		return this.getDataBySqlID("CoreStation.GetRegionTree");
	}
}
