/**
 * @(#)file    SYSRightPgmListWorkerDelBiz.java
 * @(#)author  
 */
package kr.co.udapsoft.ebid.buyer.sycs.security.biz;

import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.persistent.Persistent;
import kr.co.hsnc.common.sql.persistent.PersistentImpl;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

/**
 * 권한별 프로그램 목록 삭제 처리
 * 
 * @author DaeJin Lee
 */
public class SYSRightPgmListWorkerDelBiz extends Biz {
    private static String PGM_LIST_TABLE = "PUB0300T";

	public SYSRightPgmListWorkerDelBiz(HandlerStorage storage) {

		super(storage);
	}

	public void doBiz() throws Exception {

        String[] pgmListID = super.gets("pgm_list_id");
		//String[] pgmListID   =   new String[] {"11"};

        boolean success = delPgmList(pgmListID);
        storage.setSuccess(success);
	}

    /**
     * 권한별 프로그램 목록을 삭제.
	 * @param pgmListID
	 * @return
	 */
	private boolean delPgmList(String[] pgmListID) {
       //System.out.println("delbiz");
        String sqlstr = "";
        try {
            conn.begin();

            sqlstr = " DELETE                         \n"
                   + " FROM    " + PGM_LIST_TABLE + " \n"
                   + " WHERE   PGM_LIST_ID = ?        \n" ;

            Persistent persistent = new PersistentImpl(conn.getConnection());
            persistent.setStatement(sqlstr);
            //System.out.println("sqlstr==>"+sqlstr);

            for( int i = 0 ; i < pgmListID.length ; i++ ) {

                persistent.addParameter(pgmListID[i]);
               // System.out.println("delbizpgmListID[i]==>"+pgmListID[i]);
                persistent.execute();
                persistent.clearParameters();
            }
            
            return true;
        }
        catch(Exception e) {

            WAFLogger.error(this.getClass().getName() + " --> delPgmList() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            conn.setRollback();
            storage.setDetailMessage(e);
            return false;
        }
        finally {

            conn.end();
        }
    }
}
