/**
 * @(#)file    SYSRightPgmListGrSortFormBiz.java
 * @(#)author  gyeongmo an
 * @(#)date    2014.6.18
 *
 * Copyright (c) www.udapsoft.co.kr, Inc.
 * All rights reserved.
 */
package kr.co.udapsoft.ebid.buyer.sycs.security.biz;

import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.RowSetImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

public class SYSRightPgmListGrSortFormBiz extends Biz  {
    private static String PGM_GR_TABLE   = "PUB0310T";
    private static String PGM_LIST_TABLE = "PUB0300T";

	public SYSRightPgmListGrSortFormBiz(HandlerStorage storage) {

		super(storage);
	}

    public void doBiz() throws Exception {

        String rightID = params.get("right_id");

        RowSet listRowSet = getPgmGrList(rightID);
        storage.addRowSet("ListRowSet", listRowSet);
	}

	/**
     * 해당 권한의 프로그램 그룹 목록을 리턴한다.
	 * @param rightID
	 * @return
	 */
	private RowSet getPgmGrList(String rightID) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        try {

            sqlstr = " SELECT   A.PGM_GR_ID, A.PGM_GR_SEQ, B.PGM_GR_NAME      \n"
                   + " FROM     ( SELECT   DISTINCT A.PGM_GR_ID, A.PGM_GR_SEQ \n"
                   + "            FROM     " + PGM_LIST_TABLE + " A ,         \n"
                   + "                     " + PGM_GR_TABLE   + " B           \n"
                   + "            WHERE    A.RIGHT_ID = ?                     \n"
                   + "            ORDER BY PGM_GR_SEQ ) A,                    \n"
                   + "          " + PGM_GR_TABLE + " B                        \n"
                   + " WHERE    A.PGM_GR_ID = B.PGM_GR_ID                     \n"
                   + " ORDER BY A.PGM_GR_SEQ                                  \n" ;
            search.setStatement(sqlstr);
            
            search.addParameter(rightID);

            listRowSet = search.execute();
        }
        catch(Exception e) {

            WAFLogger.error(this.getClass().getName() + " --> getPgmGrList() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {

            if( listRowSet == null ) listRowSet = new RowSetImpl();
            return listRowSet;
        }
    }
}
