/**
 * @(#)file    SuppReferenceListBiz.java
 * @(#)author  gyeongmo an
 * @(#)date    2014.7.18
 * @(#)Description: 협력업체 자료실
 *
 * Copyright (c) www.udapsoft.co.kr, Inc.
 * All rights reserved.
 */
package kr.co.udapsoft.ebid.supplier.portal.center.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.WAFSQLException;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.util.ValueObject;

import com.udapsoft.modular.web.ibsheet7.IBSheet7Factory;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;


public class SuppReferenceListBiz extends Biz {

	public SuppReferenceListBiz(HandlerStorage storage) {
		super(storage);
	}

	public void doBiz() throws Exception {
		if(storage.compareEvent("")){
			params.set("sheet1", getSuppReferenceList(params));
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
		} else if( storage.compareEvent("GET_SUPP_REFERENCE_LIST") ) {
			params.set("sheet1", getSuppReferenceList(params));
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
		}
	}
	
	private RowSet getSuppReferenceList(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        StringBuffer sqlstr = new StringBuffer();
        try {
        	sqlstr.append("	SELECT          	\n");
        	sqlstr.append("			NOTI_DY    	\n");
        	sqlstr.append("		, NOTI_DIV    	\n");
        	sqlstr.append("		, SEQ         	\n");
        	sqlstr.append("		, DECODE(SUPP_OPEN_YN, 'Y', '공개', '비공개') SUPP_OPEN_YN	\n");
        	sqlstr.append("		, TITLE       	\n");
        	sqlstr.append("		, WRITE_ID    	\n");
        	sqlstr.append("		, WRITE_NM    	\n");
        	sqlstr.append("		, ROW_NUMBER() OVER (ORDER BY SEQ ASC) BUNHO    	\n");
        	sqlstr.append("	FROM NOTI       	\n");
        	sqlstr.append("	WHERE NOTI_DIV = '2'			\n");
        	sqlstr.append("	AND SUPP_OPEN_YN = 'Y'	\n");
        	
        	if(!params.get("p_title").trim().equals("")) {
        		sqlstr.append("	AND TITLE LIKE '%' || ? || '%'       	\n");
        		search.addParameter(params.get("p_title").trim());
        	}
        	
        	sqlstr.append("	ORDER BY NOTI_DY DESC, SEQ DESC	\n");
             
            WAFLogger.debug(sqlstr.toString());
        	search.setStatement(sqlstr);
            rowSet = search.execute();
        }
        catch (WAFSQLException se) {
            super.doException(se);
            this.storage.setSuccess(false);
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        finally {    
            if(rowSet == null) rowSet = new RowSetImpl();
            return rowSet;
        }
	}
	
}

