/**
 * @(#)file    OwnListSaveBiz.java
 * @(#)author  gyeongmo an
 * @(#)date    2014.7.2
 * Copyright (c) www.udapsoft.co.kr, Inc.
 */
package kr.co.udapsoft.ebid.buyer.sycs.own.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.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.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

public class MyInfoBiz extends Biz {
	public MyInfoBiz(HandlerStorage storage) {
		super(storage);
	}

	public void doBiz() throws Exception {
	    ValueObject SuppJoinRequestVo = new ValueObject();
	    
	    
	    System.out.println("=====================================");
	    
	    
	    SuppJoinRequestVo = getSuppJoinRequestList(params);
        
        storage.addValueObject("SuppJoinRequest", SuppJoinRequestVo);
	}
	
	
	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("                   CORP_ID              \n") 
                   .append("                 , USER_ID              \n")
                   .append("                 , USER_NAME                \n")
                   .append("                 , '' PASSWD                       \n") 
                   .append("                 , USER_NAME            \n")
                   .append("                 , DIVISION            \n")
                   .append("                 , POSITION         \n")
                   .append("                 , TEL_NUM         \n")
                   .append("                 , FAX_NUM         \n")
                   .append("                 , HP1                          \n")
                   .append("                 , HP2                          \n")
                   .append("                 , HP3                          \n")
                   .append("                 , EMAIL                                        \n")
                   .append("                  FROM SUPP_CHARGE                          \n")
                   .append("                 WHERE USER_ID= ?                                                                                                    \n");
            
                                    
                                    
                                    
            search.setStatement(sqlstr.toString());
            search.addParameter(params.get("p_user_id"));
            rowSet = search.execute();
            
            
            System.out.println(sqlstr.toString());
            System.out.println(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;
        }
    } 
	
	
	
	public boolean saveOwnList(ValueObject params) {
        Persistent persistent_u = null;
        StringBuffer sqlstr_u   = new StringBuffer();
        
		sqlstr_u.append("	UPDATE HEAD_OFFICE_INFO SET	\n");
		sqlstr_u.append("		CORP_REG_NO = ?          	\n");
		sqlstr_u.append("		, CORP_KOR = ?           	\n");
		sqlstr_u.append("		, CORP_ENG = ?           	\n");
		sqlstr_u.append("		, POST_NO = ?            	\n");
		sqlstr_u.append("		, ADDRESS = ?            	\n");
		sqlstr_u.append("		, CORP_STS = ?           	\n");
		sqlstr_u.append("		, BIZ_FORM = ?           	\n");
		sqlstr_u.append("		, REP_NAME = ?           	\n");
		sqlstr_u.append("		, CORP_TEL = ?           	\n");
		sqlstr_u.append("		, UPD_BY = ?             	\n");
		sqlstr_u.append("		, UPD_DATE = SYSDATE     	\n");
		
		try {
            conn.begin();
            persistent_u = new PersistentImpl(super.conn.getConnection());
            persistent_u.setStatement(sqlstr_u.toString());
            
            persistent_u.addParameter(params.get("corp_reg_no"));
            persistent_u.addParameter(params.get("corp_kor"));
            persistent_u.addParameter(params.get("corp_eng"));
            persistent_u.addParameter(params.get("post_no1") + params.get("post_no2"));
            persistent_u.addParameter(params.get("address"));
            persistent_u.addParameter(params.get("corp_sts"));
            persistent_u.addParameter(params.get("biz_form"));
            persistent_u.addParameter(params.get("rep_name"));
            persistent_u.addParameter(params.get("corp_tel"));
            persistent_u.addParameter(params.get("login_user"));
            
            WAFLogger.debug(sqlstr_u.toString());
            persistent_u.execute();
            persistent_u.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();
        }
    }
		
	
	

}
