/**
 * @(#)file    SYSRightPgmListSortFormBiz.java
 * @(#)author  gyeongmo an
 * @(#)date    2014.7.2
 *
 * 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;

/**
 * 프로그램 순서 변경 Form 처리
 * 
 * @author DaeJin Lee
 */
public class SYSRightPgmListSortFormBiz extends Biz {
    private static String PGM_TABLE      = "PUB0320T";
    private static String PGM_LIST_TABLE = "PUB0300T";
    private static String PGM_SYS_TABLE  = "PUB0390T";

    private static String LINE = "--------------------";

    public SYSRightPgmListSortFormBiz(HandlerStorage storage) {

        super(storage);
    }

    public void doBiz() throws Exception {

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

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

    /**
     * 해당 프로그램 그룹에 프로그램 목록을 리턴한다.
	 * @param rightID
	 * @param pgmGrID
	 * @return
	 */
	private RowSet getPgmList(String rightID, String pgmGrID) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        try {   
            
            sqlstr = " SELECT  A.PGM_LIST_ID, DECODE(C.NAME, NULL, '"+LINE+"', '['||C.NAME||'] '||PGM_NAME) AS PGM_NAME  \n"
                   + " FROM     " + PGM_LIST_TABLE + " A,                                \n"
                   + "          " + PGM_TABLE      + " B,                                \n"
                   + "          " + PGM_SYS_TABLE  + " C                                 \n"
                   + " WHERE    A.PGM_ID = B.PGM_ID(+)                                   \n"
                   + " AND      A.RIGHT_ID  = ?                                          \n"
                   + " AND      A.PGM_GR_ID = ?                                          \n"
                   + " AND      B.SYSTEM_ID = C.SYSTEM_ID(+)                             \n"
                   + " ORDER BY A.PGM_SEQ, A.PGM_ID                                      \n" ;
            search.setStatement(sqlstr);
            
            search.addParameter(rightID);
            search.addParameter(pgmGrID);

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

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

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