/**
 * @(#)file    SYSRightPgmListSortFormBiz.java
 * @(#)author  
 * @(#)version 
 * @(#)date    
 * @(#)since   
 */
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 SYSRightPgmListSortFormWorkerBiz extends Biz{

    private static String ACCT_TABLE     = "PUB0120T";

    private static String R_TABLE        = "PUB0340T";
    private static String R_LIST_TABLE   = "PUB0350T";

    private static String PGM_TABLE      = "PUB0320T";
    private static String PGM_GR_TABLE   = "PUB0310T";
    private static String PGM_LIST_TABLE = "PUB0300T";
    private static String PGM_SYS_TABLE  = "PUB0390T";

    public SYSRightPgmListSortFormWorkerBiz(HandlerStorage storage) {

        super(storage);
    }

    public void doBiz() throws Exception {

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

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


    /**
     * 프로그램 순서를 변경한다.
	 * @param pgmListID
	 * @return
	 */
	private boolean updPgmListSeq(String[] pgmListID) {

        String sqlstr = "";
        try {
            conn.begin();

            sqlstr = " UPDATE " + PGM_LIST_TABLE + " \n"
                   + " SET    PGM_SEQ     = ?        \n"
                   + " WHERE  PGM_LIST_ID = ?        \n" ;

            Persistent persistent = new PersistentImpl(conn.getConnection());
            persistent.setStatement(sqlstr);

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

                persistent.addParameter(i + 1);
                persistent.addParameter(pgmListID[i]);
                persistent.execute();
                persistent.clearParameters();
            }
            
            return true;
        }
        catch(Exception e) {

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

            conn.end();
        }
    }
}
