package kr.co.udapsoft.ebid.buyer.common.lib.biz;

import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.persistent.Persistent;
import kr.co.hsnc.common.sql.persistent.PersistentImpl;

public class SelectSpotDeptBiz extends Biz {

	public SelectSpotDeptBiz(HandlerStorage storage) {
		super(storage);
	}
 
    public void doBiz() throws Exception {
    	saveSelectedSpot(params.get("site_code"));
    }

    private boolean saveSelectedSpot(String site_code) {

		try {
		
			Persistent persistent = new PersistentImpl(super.conn.getConnection());
			StringBuffer sqlstr = new StringBuffer();
			
			conn.begin();

			sqlstr.append(" UPDATE  ETEC_ERPIF.PUB0120T_SITE				\n");
			sqlstr.append(" SET     DEFAULT_YN = DECODE(SITE_CD,?,'Y','')	\n");
			sqlstr.append(" WHERE   USER_SABUN = ?							\n");
			  
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(site_code);
			persistent.addParameter(storage.getUser().get("USER_SABUN"));
			WAFLogger.debug(sqlstr);
			WAFLogger.debug(persistent.getParameters());
			persistent.execute();
			persistent.clearParameters();
				
			return true;
        }catch(Exception e) {
            super.doException(e);
            super.storage.setMessage(e.getMessage());
            super.storage.setDetailMessage(e);
            super.conn.setRollback();
            return false;
        }finally {
        	super.conn.end();
        }
	}


}
