/*************************************************************************************************
 * 프로그램명 : PartView.java 프로그램설명 : 기관 상세 정보 작성자 : 조용준 작성일 : 04.06.11 변경일 :
 **************************************************************************************************/
package kr.co.kihyun.beans.totsys.sysadm.part;

import java.sql.ResultSet;
import java.sql.SQLException;
import kr.co.kihyun.beans.entity.MDept;
import kr.co.kihyun.beans.entity.MoumiEntity;

import kr.co.kihyun.db.DBManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PartView extends DBManager {
	private static final Logger LOG = LoggerFactory.getLogger(PartView.class);
	private ResultSet rs = null;

	private String id = "";
	private String name = "";
	private String sysAuth = "";
	private String des = "";
	private String upperID = "";

	public void executeQuery(String id) {
		StringBuilder sql = new StringBuilder(100);

		this.id = id;

		try {
			sql.append("select name, sys_auth, addr, upper_dept from ").append(MoumiEntity.getTableName(MDept.class))
					.append(" where id=organ and id=?");
			rs = execQuery(sql.toString(), id);
			if (rs.next()) {
				name = rs.getString(1);
				sysAuth = rs.getString(2);
				des = rs.getString(3);
				upperID = rs.getString(4);

			}
		} catch (SQLException sqlEx) {
			LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}",
					new Object[] { sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql });
			throw new RuntimeException(sqlEx);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		} finally {
			close(rs);
			execClose();
		}
	}

	public String getUpperName(String upperID) {
		StringBuilder sql = new StringBuilder(50);

		String upperName = "";
		try {
			sql.append("select name from ").append(MoumiEntity.getTableName(MDept.class))
					.append(" where id=organ and id=?");
			rs = execQuery(sql.toString(), upperID);
			if (rs.next()) {
				upperName = rs.getString(1);
			}
			return upperName;
		} catch (SQLException sqlEx) {
			LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}",
					new Object[] { sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql });
			throw new RuntimeException(sqlEx);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		} finally {
			close(rs);
			execClose();
		}
	}

	/**** 각각의 필드값 얻는 메소드 ****/
	public String getID() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getSysAuth() {
		return sysAuth;
	}

	public String getDes() {
		return des;
	}

	public String getUpperID() {
		return upperID;
	}

}
