/**
 * @(#)file    UserListBiz.java
 * @(#)author  Joung Kyu Park
 * @(#)version 1.0
 * @(#)date    May 31, 2007
 * @(#)since   JDK 1.4.2
 *
 * Copyright (c) www.hwenc.co.kr, Inc.
 * All rights reserved.
 * This software is the proprietary information of Hanwha E&C, Inc.
 */
package kr.co.udapsoft.ebid.buyer.supplier.purchase.biz;



import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

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.persistent.Persistent;
import kr.co.hsnc.common.sql.persistent.PersistentImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.sql.util.RowSetUtility;
import kr.co.hsnc.common.util.ValueObject;

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






public class SuppJoinRequestBiz extends Biz {

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

	/* (non-Javadoc)
	 * @see kr.co.hwenc.system.Biz#doBiz()
	 */
	public void doBiz() throws Exception {

		
		
		WAFLogger.debug("event==============>" + storage.getEvent());
		
		ValueObject SuppJoinRequestVo = new ValueObject();
		
		if(storage.compareEvent(""))
		{
//	        RowSet acctTypeRowSet = common.getAcctTypeUseRowSet(storage.getUser().get("ACCT_TYPE_CODE"));
//	        storage.addRowSet("AcctTypeRowSet", acctTypeRowSet);
		    
		    ValueObject corp_id = getCorp_id(super.conn.getConnection()); 
            params.set("p_corp_id", corp_id.get("SEQ"));
            
            storage.addValueObject("SuppJoinRequest", SuppJoinRequestVo);
            
		}
		else if(storage.compareEvent("GET_DETAIL"))
        {
		    SuppJoinRequestVo = getSuppJoinRequestList(params);
		    
		    params.set("p_corp_id", SuppJoinRequestVo.get("corp_id"));
		    
		    storage.addValueObject("SuppJoinRequest", SuppJoinRequestVo);
		    
		    
        }
		
		
	}
	
	
	public ValueObject getCorp_id(Connection conn) throws Exception{
        
        Persistent persistent_q = null;
        
        
        ValueObject vo = new ValueObject();
        ValueObject row = null;
        StringBuffer sqlstr =  new StringBuffer();
        
        try{
            persistent_q = new PersistentImpl(conn);
            
            sqlstr.append("         SELECT SUPP_INFO_S.NEXTVAL AS SEQ  FROM DUAL                                                 \n");
            
            persistent_q.setStatement(sqlstr.toString()); 
            row = RowSetUtility.getValueObject(persistent_q.query().getRow(0));
            vo.set("seq", row.get("seq"));
        }
        catch(Exception e) {
            e.printStackTrace();
        }finally{
            if(vo == null) vo = new ValueObject();
        }
        return vo;
    }
	
	public ValueObject getSuppJoinRequestList(ValueObject params){
        Search search = new SearchImpl();
        ValueObject vo = null;
        RowSet rowSet = new RowSetImpl();
        
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            
            sqlstr.append("      SELECT                                                                                     \n")                    
                   .append("              A.CORP_REG_NO                                                                \n")                     
                   .append("            , A.CORP_KOR                                                                                                \n")
                   .append("            , A.REP_NAME                                                                                                 \n")
                   .append("            , DECODE(A.CORP_DIV_CD, '1', '법인', '개인') CORP_DIV_CD                                                    \n")
                   .append("            , A.REG_REQ_DT                                                                                                                                     \n")
                   .append("            , A.CRE_DATE                                                                                                                                         \n")
                   .append("            , DECODE(A.STATUS, '00', '가입요청', '01', '대기', '02', '가등록', '03', '등록', '91', '거래중지', '99', '거래취소', '작성중') STATUS        \n")
                   .append("            , A.STATUS STATUS_CODE        \n")
                   .append("            , B.USER_NAME                                                                                                                                   \n")
                   .append("            , B.EMAIL                                                                                                                                        \n")
                   .append("            , B.HP1                                                                                                                                            \n")
                   .append("            , B.HP2                                                                                                                                                    \n")
                   .append("            , B.HP3                                                                                                                                                       \n")
                   .append("            , A.CORP_ID                                                                                                                                                  \n")
                   .append("            , B.CHARGE_SEQ                                                                                                                                              \n")
                   .append("            , A.JOB_DIV                                                                                                                                              \n")
                   .append("            FROM SUPP_INFO A, SUPP_CHARGE B                                                                                                            \n")                            
                   .append("         WHERE A.CORP_ID = B.CORP_ID(+)                                                                                                         \n")
                   .append("          AND A.CORP_ID = ?                                                                                                       \n")
                   .append("          AND B.DEFAULT_YN = 'Y'                                                                                                      \n");
            
            search.setStatement(sqlstr.toString());
            search.addParameter(params.get("p_corp_id"));
            rowSet = search.execute();
            
            
            WAFLogger.debug(sqlstr.toString());
            WAFLogger.debug(search.getParameters());
            
            if(rowSet.size()>0){
                vo = RowSetUtility.getValueObject(rowSet.getRow(0));
            }
            
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }finally{
            if( vo == null) vo = new ValueObject();
            return vo;
        }
    } 

}