/**
 * @(#)file    UserBiz.java
 * @(#)author 
 * @(#)version 1.0
 * @(#)date    
 * @(#)since   JDK1.4.11
 *
 * Copyright (c) 2002-2003 www.hwenc.com, Inc. All rights reserved.
 * This software is the proprietary information of hwenc, Inc.
 */
package kr.co.udapsoft.ebid.buyer.sycs.user.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.WAFConnectionImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;


/**
* 사용자 관리 비즈니스 클래스
*
* @version
* @
*/
public class UserBiz {
    
    private WAFConnectionImpl m_conn = new WAFConnectionImpl();

    /**
     * 본사사용자 등록을 위한 사원검색
     * 2003-07-22 17:10:24 by hanajava
     * @param sabun
     * @return
     */
    public static RowSet getUserList(String name, String sabun){

        String sqlstr = "";
        try {

            sqlstr += " SELECT   A.USER_SABUN,                \n"
                    + "          A.USER_NAME_K USER_NAME,                 \n"
                    + "          A.TEL_NO,                     \n"
                    + "          A.HAND_TEL_NO,                \n"
                    + "          B.T824CODE DUTY_CODE,                  \n"
                    + "          B.T824NAME DUTY_NAME,                  \n"
                    + "          C.DEPT_CD,                             \n"
                    + "          C.DEPT_NM DEPT_NAME,                   \n"
                    + "          C.DEPT_INI,                            \n"
                    + "          A.JUMIN_NO JUMIN,                     \n"
                    + "            (SELECT ACCT_ID                      \n"
                    + "              FROM      PUB0120T                 \n"
                    + "             WHERE     user_sabun = A.USER_SABUN  \n"
                    + "             and       rownum  = 1               \n"
                    + "             ) ACCT_ID,                          \n"
                    + "          A.DUTYC                     \n"    
                    + " FROM     PUB0130V A, KFA824TB B, ETEC_ERPIF.ACZ10100 C      \n"
                    + " WHERE    USER_NAME_K LIKE '%' || ? || '%'         \n"
                    + " AND      USER_SABUN LIKE '%' || ? || '%'         \n"
                    + " AND      B.T824CODE(+) = A.T101JIKCH            \n"
                    + " AND      C.DEPT_CD     = A.T101BUSEO            \n"
                    + " AND      A.T101DUTYC  != '30'                   \n"
                    + " ORDER BY A.T101NAMEK                            \n" ;        
            Search search = new SearchImpl();
            search.setStatement(sqlstr);
            search.addParameter(name);
            search.addParameter(sabun);
            return search.execute();
        }
        catch(Exception e) {

            return new RowSetImpl();
        }
    }

    /**
     * 사번에 해당하는 사용자가 IPS에 등록되었는지 확인한다.
     * @param sabun
     * @return
     */
    public boolean isExist(String sabun){

        boolean isExist = false;
        String sqlstr = "";
        try {

            sqlstr += " SELECT COUNT(1) CNT    \n"
                    + " FROM   PUB0120T        \n"
                    + " WHERE  USER_SABUN = ?  \n" ; 
            Search search = new SearchImpl();
            search.setStatement(sqlstr);
            search.addParameter(sabun);
            RowSet rowset = search.execute();
            if( rowset != null && rowset.getRow(0).getInt("cnt") > 0 ) {

                isExist = true;
            }
        }
        catch(Exception e){

        	WAFLogger.error("[Exception]UserBiz.isExist(" + sabun + ") : " + e.getMessage());
        }
        return isExist;
    }
}
