/*********************************************************************************************************
 * 프로그램명 : User.java 프로그램설명 : 사용자에 대한 정보를 얻을 수 있는 class 작성자 : 강원중 작성일 : 2003.12.09 변경일 : 2003.12.09
 **********************************************************************************************************/

package kr.co.kihyun.beans.user;

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 DeptView extends DBManager {
	private static final Logger LOG = LoggerFactory.getLogger(DeptView.class);

	private ResultSet rs = null;

	private String id = "";
	private String name = "";
	private String addr = "";
	private String phone = "";
	private String passcode = "";
	private String recoImg = "";
	private String partID = "";
	private String partName = "";
	private String upperName = "";
	private int sysAuth = 0;

	/******** 사용자의 소속 기관 한글 이름 ********/
	public void executeQuery(String id) {
		StringBuilder sql = new StringBuilder(250);
		try {
			sql.append("select dt.name dn, (select name from ")
					.append(MoumiEntity.getTableName(MDept.class))
					.append(" where id=dt.upper_dept) upper_name, ")
					.append("dt.addr, dt.phone, dt.passcode, dt.reco_img, dt.organ, pt.name pn, dt.sys_auth ")
					.append("from ").append(MoumiEntity.getTableName(MDept.class)).append(" dt, ")
					.append(MoumiEntity.getTableName(MDept.class)).append(" pt where dt.organ=pt.id and dt.id=?");
                        
			rs = execQuery(sql, id);
			if (rs.next()) {
				// id = rs.getString("dt.id");
				this.id = id;
				name = rs.getString(1);
				upperName = rs.getString(2);
				addr = rs.getString(3);
				phone = rs.getString(4);
				passcode = rs.getString(5);
				recoImg = rs.getString(6);
				partID = rs.getString(7);
				partName = rs.getString(8);
				sysAuth = rs.getInt(9);
			}
              //System.out.println(sql);
		} 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 void executeQuery2(String id) {
		String sql = "";
		try {
			sql="select dt.name dn from moumi_dept dt,moumi_dept pt where dt.organ=pt.id and dt.id=?";

			rs = execQuery(sql, id);
			if (rs.next()) {
				name = rs.getString(1);
			}
		} 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 boolean getID_AT_IS_MOUMI_TOT_REPORT(Long id)
   {
	  String sql="";
	  try
      {
	    sql="select id from ifdbmgr.is_moumi_tot_report where id=?";
	    rs=execQuery(sql,id);
	    if (rs.next()) return true;
            else return false;
	   }
          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 getAddr() {
		return addr;
	}

	public String getPhone() {
		return phone;
	}

	public String getPasscode() {
		return passcode;
	}

	public String getRecoImg() {
		return recoImg;
	}

	public String getPartID() {
		return partID;
	}

	public String getPartName() {
		return partName;
	}

	public String getUpperName() {
		return upperName;
	}

	public int getSysAuth() {
		return sysAuth;
	}
}
