/***********************************************************************************
 * @@ Program Name : RepoPerDocList.java Description : 보고자료 정보 목록 Author : 강원중 Create Date : 2004.10.13 History :
 * @@
 ***********************************************************************************/

package kr.co.kihyun.beans.totsys.repoper;

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.beans.entity.TotReport;

import kr.co.kihyun.db.DBManager;

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

public class RepoPerDocList extends DBManager {
	private static final Logger LOG = LoggerFactory.getLogger(RepoPerDocList.class);

	private ResultSet rs = null;
	private String[] deptList = null;

	public void allReportDeptList(Long docID) {
		StringBuilder sql = new StringBuilder(120);
		int count = 0;

		try {
			sql.append("select dt.id from ")
					.append(MoumiEntity.getTableName(TotReport.class)).append(" rt, ")
					.append(MoumiEntity.getTableName(MDept.class)).append(" dt ")
					.append("where rt.doc_id=? and rt.type=0 and rt.dept_id=dt.id");

			rs = execQuery(sql.toString(), docID);
			if (rs != null) {
				rs.last();
				count = rs.getRow();
				rs.beforeFirst();
			} else {
				return;
			}

			deptList = new String[count];

			for (int i = 0; rs.next(); i++) {
				deptList[i] = 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 String[] getDeptList() {
            //24.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by KWON,HAN
	    //	return deptList;
                
            String[] ret = null;
            if( this.deptList != null) {
                ret = new String[deptList.length];
                for (int i=0; i<deptList.length; i++) {
                    ret[i] = this.deptList[i];
                }
            }
            return ret;
            //====================================================================                  
	}
}
