/**
 * @(#)file    QuotDeptCodeListBiz.java
 * @(#)author  hoonseok choi
 * @(#)date    2023.01.10
 * @(#)Description: 견적용 현장코드 등록
 */
package kr.co.udapsoft.ebid.buyer.quot.outside.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.common.ui.HTMLMaker;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

public class QuotDeptCodeListBiz extends Biz {
    
	private static String CODE_TABLE   = "EBID_COM911T";
    
	public QuotDeptCodeListBiz(HandlerStorage storage) {
		super(storage);
	}

	/* (non-Javadoc)
	 * @see kr.co.hwenc.system.Biz#doBiz()
	 */
	public void doBiz() throws Exception {
		String systemId   = params.get("system_id");
		params.set("sheet1", getDetailListRowSet(params));
		storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
		// ibsheet 중점관리여부 콤보박스
        String selectHqText =  getHqSelectTagCombo(systemId, "style='width:220px;height=18;'");
        storage.addObject("selectHqText", selectHqText);
        /*   ibsheet 중점관리여부 콤보박스 (value) */
        String selectHqValue =  getHqSelectTagCode(systemId, "style='width:220px;height=18;'");
        storage.addObject("selectHqValue", selectHqValue);
	}

	public RowSet getDetailListRowSet(ValueObject Params) throws Exception {               
		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        String sqlstr = "";
        try {
        	sqlstr += " SELECT 			          \n"
        			+ "        SORT_NO,           \n"  
        			+ " 	   DETAILCD,          \n"
	                + "        DETAILNM,          \n"
	                + "        BASECD,            \n"
	                + "        CHG_CODE01,        \n"
	                + "        (SELECT USER_NAME FROM PUB0120T WHERE ACCT_ID = A.CRE_BY) CRE_NAME,             \n"
	                + "        CRE_DATE           \n"
	                + "   FROM EBID_COM911T A     \n"
	                + "  WHERE BASECD = '"+Params.get("BASECD")+"'  \n" 
	                + "  ORDER BY SORT_NO        \n" ;
        	
        	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;
        }
    }
	
	public String getHqSelectTagCombo(String selectedValue, String style) throws Exception{

        RowSet rowSet = getHqSelectTagCombo();

        return HTMLMaker.getSelectTagText4Sheet(rowSet);
    }
    
    public String getHqSelectTagCode(String selectedValue, String style) throws Exception{

        RowSet rowSet = getHqSelectTagCode();
        
        return HTMLMaker.getSelectTagValue4Sheet( rowSet);
    }
    
    /**
     * 검색을 위한 시스템 목록 리턴
     * @return
     */
    public RowSet getHqSelectTagCombo() throws Exception{
        
        Search search = new SearchImpl();
        RowSet sysRowSet = null;
        String sqlstr = "";
        try {

            sqlstr = " SELECT  DETAILNM, DETAILCD  					\n"
                   + " FROM     " + CODE_TABLE + "        				\n"
                   + " WHERE BASECD = 'QUOT_HQ_CD'      		  	\n"
                   + " ORDER BY SORT_NO ASC                          	\n";
            search.setStatement(sqlstr);
            sysRowSet = search.execute();
            
            WAFLogger.debug(sqlstr);
        }
        catch(Exception e) {

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

            if( sysRowSet == null ) sysRowSet = new RowSetImpl();
            return sysRowSet;
        }
    }
    
    /**
     * 검색을 위한 시스템 목록 리턴
     * @return
     */
    public RowSet getHqSelectTagCode() throws Exception{
        
        Search search = new SearchImpl();
        RowSet sysRowSet = null;
        String sqlstr = "";
        try {

            sqlstr = " SELECT  DETAILNM, DETAILCD  					\n"
                   + " FROM     " + CODE_TABLE + "        				\n"
                   + " WHERE BASECD = 'QUOT_HQ_CD'      		  	\n"
                   + " ORDER BY SORT_NO ASC                          	\n";
            search.setStatement(sqlstr);
            sysRowSet = search.execute();
            
            WAFLogger.debug(sqlstr);
        }
        catch(Exception e) {

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

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