/**********************************************************************************
 * 프로그램명 : PartRegist.java 프로그램설명 : 기관등록하기 위해 표현되는 빈 작 성 자 : 조용준 작 성 일 : 04.06.12 최신변경일 :
 ***********************************************************************************/

package kr.co.kihyun.beans.totsys.sysadm.part;

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

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

import kr.co.kihyun.db.*;

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

	private int count = 0;

	private String[] distIDList = null;
	private String[] distsysAuthList = null;

	public void executeQuery() {
		StringBuilder sql = new StringBuilder(90);

		try {
			sql.append("select id, sys_auth from ").append(MoumiEntity.getTableName(MDept.class))
					.append(" where id=organ");
			rs = execQuery(sql.toString());
			if (rs != null) {
				rs.last();
				count = rs.getRow();
				rs.beforeFirst();
			} else {
				return;
			}

			distIDList = new String[count];
			distsysAuthList = new String[count];

			// id values 배열에 가지고옴
			for (int i = 0; rs.next(); i++) {
				distIDList[i] = rs.getString(1);
				distsysAuthList[i] = rs.getString(2);
			}
		} 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[] getDistIDList() {
            //24.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by KWON,HAN
	    //	return distIDList;
                
            String[] ret = null;
            if( this.distIDList != null) {
                ret = new String[distIDList.length];
                for (int i=0; i<distIDList.length; i++) {
                    ret[i] = this.distIDList[i];
                }
            }
            return ret;
            //====================================================================                 
	}

	public String[] getDistsysAuthList() {
	    //	return distsysAuthList;
                
            String[] ret = null;
            if( this.distsysAuthList != null) {
                ret = new String[distsysAuthList.length];
                for (int i=0; i<distsysAuthList.length; i++) {
                    ret[i] = this.distsysAuthList[i];
                }
            }
            return ret;                
	}
}
