package kr.co.udapsoft.ebid.buyer.common.lib.biz;

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;

import kr.co.hsnc.common.base.WAFLogger;

public class SearchSpotDeptNewBiz extends Biz {

	public SearchSpotDeptNewBiz(HandlerStorage storage) {
		super(storage);
	}
 
    public void doBiz() throws Exception {
    	
    	if(storage.compareEvent("")){
    		RowSet getDivisionRowSet = getDivisionRowSet();
    		storage.addRowSet("DivisionRowSet", getDivisionRowSet);
    	} else if (storage.compareEvent("GET_DEPT_LIST")) {
    		params.set("sheet1", getSpotDept2(params));
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
    	} else if (storage.compareEvent("CLEAR_DEPT")) {
    		storage.getUser().set("dept_cd", "");
    		storage.getUser().set("dept_nm", "");
    	} else{
    		params.set("sheet1", getSpotDeptErpNew(params));
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
    	}
    }

    /**
     * 현장코드 검색을 처리한다.(전체)
     * @param params
     * @return <code>RowSet</code>
     */
    public RowSet getSpotDept(ValueObject Params) {

        Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        StringBuffer sql = new StringBuffer();

        try {

			ValueObject user = storage.getUser();

			String dept_cd    		= user.get("DEPT_CD");
			String comon_dcr    	= user.get("COMON_DCR");
			String dept_cnt    		= user.get("DEPT_CNT");
			String deadflg_value	= params.get("deadflg_value");
			String mudept_yn		= user.get("MUDEPT_YN");
			
			if(!params.get("prp_key").equals("")){
				
				comon_dcr = "1";
				
			}
			
			//본사이고 계정타입이 관리자거나 경영지원(01)일때
			//1. 현장D, 본사B
		    //         일반사용자&본사   : 소속부서만 조회, 토건기획 토건본부 조회 
			//         else : 전체현장조회
			//         일반사용자 & acct_id_type = 사용자 : 소속본부
			//         일반사용자 & acct_id_type = default : 소속프로젝트
			//         else : 전체현장 
			if( comon_dcr.equals("1") ) {
				//현장 
				if( user.get("RIGHT_NAME").equals("SITE_CONT") && user.get("HEAD_GB").equals("F") ){
					sql.append(" SELECT  A.DEPT_CD													\n");
					sql.append("         ,A.DEPT_NM													\n");
					sql.append("         ,A.AC_UNIT_CD												\n");
					sql.append("         ,F_GET_CODE_NAME('101', A.AC_UNIT_CD) AS AC_UNIT_NM		\n");
					sql.append("         ,A.STD_CURRENCY_CD											\n");
					sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT		\n");
					sql.append(" FROM	ACZ10100V A													\n");
					sql.append("         ,PUB0120T C												\n");
					sql.append(" WHERE  A.DEPT_CD != '0000'										\n");
					sql.append(" AND	A.DEPT_CD = C.PSOSO   										\n");
					sql.append(" AND	C.USER_SABUN = '"+user.get("USER_SABUN")+"'				\n");
					if( !params.get("ac_unit_cd").equals("") ) {
						sql.append(" AND      A.AC_UNIT_CD = '" + params.get("ac_unit_cd") + "'          \n");
					}
					if( !deadflg_value.equals("") )
						sql.append(" AND      A.PRJ_OK = '"+deadflg_value+"'										\n");

					if( !params.get("DEPT_NM").equals("") )
						sql.append(" AND      UPPER(A.DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%')	\n");
					sql.append(" UNION ALL															\n");
					sql.append(" SELECT  A.DEPT_CD													\n");
					sql.append("         ,A.DEPT_NM													\n");
					sql.append("         ,A.AC_UNIT_CD												\n");
					sql.append("         ,F_GET_CODE_NAME('101', A.AC_UNIT_CD) AS AC_UNIT_NM		\n");
					sql.append("         ,A.STD_CURRENCY_CD											\n");
					sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT		\n");
					sql.append(" FROM	ACZ10100V A													\n");
					sql.append("         ,PUB0120T C												\n");
					sql.append("         ,ETEC_ERPIF.PUB0120T_SITE E								\n");
					sql.append(" WHERE     A.DEPT_CD != '0000'										\n");
					sql.append(" AND		C.USER_SABUN = E.USER_SABUN									\n");
					sql.append(" AND         A.DEPT_CD = E.SITE_CD     									\n");
					sql.append(" AND		C.USER_SABUN = '"+user.get("USER_SABUN")+"'				\n");
					if( !params.get("ac_unit_cd").equals("") ) {
						sql.append(" AND      A.AC_UNIT_CD = '" + params.get("ac_unit_cd") + "'          \n");
					}
					if( !deadflg_value.equals("") )
						sql.append(" AND      A.PRJ_OK = '"+deadflg_value+"'										\n");

					if( !params.get("DEPT_NM").equals("") )
						sql.append(" AND      UPPER(A.DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%')	\n");
					
				}else {  //본사
					if (user.get("RIGHT_NAME").equals("SITE_CONT") && user.get("HEAD_GB").equals("D") ) {
						//2016.5.20
						//사용자-소속본부조회
						if (user.get("ACCT_TYPE_ID").equals("10")){
							sql.append(" SELECT  A.DEPT_CD      																		\n");
							sql.append("         ,A.DEPT_NM     																		\n");
							sql.append("         ,A.AC_UNIT_CD                                 									  	    \n");
							sql.append("         ,F_GET_CODE_NAME('101', A.AC_UNIT_CD) AS AC_UNIT_NM                     				\n");
							sql.append("         ,A.STD_CURRENCY_CD                    												    \n");
							sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT								    \n");
							sql.append("   FROM	ACZ10100V A														                        \n");
							sql.append("  WHERE A.AC_UNIT_CD =(                          										        \n");
							sql.append("                         SELECT MAX(AC_UNIT_CD)                                    				\n");
							sql.append("                           FROM PUB0120T A                                        				\n");
							sql.append("                               ,ETEC_ERPIF.ACZ10101 B                              				\n");
							sql.append("                          WHERE A.DEPART_DEPT_CD = B.ACC_DEPT_CD(+)        						\n");
							sql.append("                            AND A.ACCT_ID =  "+user.get("ACCT_ID")+"	 )                    	\n");
							sql.append("    AND	A.DEPT_CD != '0000'																	    \n");
						}else{
						//else 본사발령자, 소속프로젝트,겸직프로젝트 하위현장 조회 
						    sql.append(" SELECT  A.DEPT_CD      																		\n");
						    sql.append("         ,A.DEPT_NM     																		\n");
						    sql.append("         ,A.AC_UNIT_CD                                 									  	    \n");
						    sql.append("         ,F_GET_CODE_NAME('101', A.AC_UNIT_CD) AS AC_UNIT_NM                     				\n");
						    sql.append("         ,A.STD_CURRENCY_CD                    												    \n");
						    sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT								    \n");
						    sql.append(" FROM	ACZ10100V A														                        \n");
			                sql.append("     ,( SELECT C.ACC_DEPT_CD  DEPT_CD                                                           \n"); 
                            sql.append("          FROM ETEC_ERPIF.PUB0120T_SITE A                                                       \n"); 
                            sql.append("              ,ETEC_ERPIF.SITE_MAPPING B                                                        \n"); 
                            sql.append("              ,ETEC_ERPIF.ACZ10101 C                                                            \n"); 
                            sql.append("         WHERE A.SITE_CD = B.EBID_SITE_CD(+)                                                    \n"); 
                            sql.append("           AND NVL(B.ERP_SITE_CD, A.SITE_CD) = C.ACC_DEPT_CD                                    \n"); 
                            sql.append("           AND A.USER_SABUN = '"+user.get("USER_SABUN")+"') B                                   \n");
						    sql.append("  WHERE A.DEPT_CD = B.DEPT_CD																    \n");
						    sql.append("    AND	A.DEPT_CD != '0000'																	    \n");
						}
							
					}
					else{
						sql.append(" SELECT  A.DEPT_CD      																		\n");
						sql.append("         ,A.DEPT_NM     																		\n");
						sql.append("         ,A.AC_UNIT_CD                                 									  	    \n");
						sql.append("         ,F_GET_CODE_NAME('101', A.AC_UNIT_CD) AS AC_UNIT_NM                     				\n");
						sql.append("         ,A.STD_CURRENCY_CD                    												    \n");
						sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT								    \n");
						sql.append(" FROM	ACZ10100V A														\n");
						sql.append("  WHERE    A.DEPT_CD != '0000'																	\n");
						
						if( !params.get("ac_unit_cd").equals("") ) {
							sql.append(" AND      A.AC_UNIT_CD = '" + params.get("ac_unit_cd") + "'          \n");
						}
					}					
				}
			//현장일때
			} else { 
				if( dept_cnt.equals("1") ){
					if( mudept_yn.equals("Y") ){
						sql.append(" SELECT  A.DEPT_CD      																	\n");
						sql.append("         ,A.DEPT_NM     																	\n");
						sql.append("         ,A.AC_UNIT_CD                                 										\n");
						sql.append("         ,F_GET_CODE_NAME('101', A.AC_UNIT_CD) AS AC_UNIT_NM                     			\n");
						sql.append("         ,A.STD_CURRENCY_CD                    												\n");
						sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT								\n");
						sql.append(" FROM	ACZ10100V A, ETEC_ERPIF.PUB0120T_SITE B															\n");
						sql.append(" WHERE	A.DEPT_CD = B.SITE_CD						\n");
						sql.append(" AND	B.ACCT_ID = "+user.get("ACCT_ID")+"													\n");
						sql.append("   AND A.AC_UNIT_CD != '50'                           										\n");
						sql.append(" AND	A.DEPT_CD != '0000'																	\n");
					}else {
						sql.append(" SELECT  A.DEPT_CD      																		\n");
						sql.append("         ,A.DEPT_NM     																		\n");
						sql.append("         ,A.AC_UNIT_CD                                 										\n");
						sql.append("         ,F_GET_CODE_NAME('101', A.AC_UNIT_CD) AS AC_UNIT_NM                     				\n");
						sql.append("         ,A.STD_CURRENCY_CD                    												\n");
						sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT								\n");
						sql.append(" FROM	ACZ10100V A																			\n");
						sql.append(" WHERE	A.DEPT_CD = '"+dept_cd+"'													\n");
						sql.append("   AND A.AC_UNIT_CD != '50'                           										\n");
						sql.append(" AND	A.DEPT_CD != '0000'																	\n");
					}
				}
			}
				
				if( !deadflg_value.equals("") )
					sql.append(" AND      A.PRJ_OK = '"+deadflg_value+"'										\n");

				if( !params.get("DEPT_NM").equals("") )
					sql.append(" AND      UPPER(A.DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%')	\n");

				if( user.get("RIGHT_NAME").equals("SITE_CONT") && user.get("HEAD_GB").equals("F") ){
			 	    sql.append(" ORDER BY DEPT_CD                   										\n");
				}else{
					sql.append(" ORDER BY A.DEPT_CD                   										\n");
				}
			 
			WAFLogger.debug(sql.toString());
        	search.setStatement(sql.toString());
            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 RowSet getSpotDeptErpNew(ValueObject Params) {
    	
    	Search search = new SearchImpl();
    	RowSet rowSet = new RowSetImpl();
    	StringBuffer sql = new StringBuffer();
    	
    	try {
    		
    		ValueObject user = storage.getUser();
    		
    		String deadflg_value			= params.get("deadflg_value");
    		
    		//기본소속권한 + ACCT_TYPE_ID(PUB0110T 0 디폴트, 1 관리자, 2 전현장, 10 사용자) : 전체현장권한 조회 
    		 if(user.get("RIGHT_NAME").equals("SITE_CONT") && user.get("ACCT_TYPE_ID").equals("2")){
    			 sql.append(" SELECT  A.DEPT_CD												\n");
    			 sql.append("         ,A.DEPT_NM											\n");
    			 sql.append("         ,A.AC_UNIT_CD											\n");
    			 sql.append("         ,F_GET_CODE_NAME('101',A.AC_UNIT_CD) AS AC_UNIT_NM	\n");
    			 sql.append("         ,A.STD_CURRENCY_CD									\n");
    			 sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT	\n");
    			 sql.append(" FROM    ETEC_ERPIF.ACZ10100 A									\n");
    			 sql.append(" WHERE   1 = 1													\n");
    			 if( !params.get("ac_unit_cd").equals("") )
    				 sql.append(" AND      A.AC_UNIT_CD = '" + params.get("ac_unit_cd") + "'\n");
    			 if( !deadflg_value.equals("") )
    				 sql.append(" AND      A.PRJ_OK = '"+deadflg_value+"'					\n");
    			 if( !params.get("DEPT_NM").equals("") )
    				 sql.append(" AND      UPPER(A.DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%')	\n");
    			 sql.append(" ORDER BY A.DEPT_CD											\n");
    		 //일반사용자 && 현장발령자 : 겸직현장 조회 
    		}else if( user.get("RIGHT_NAME").equals("SITE_CONT") && user.get("HEAD_GB").equals("F") ) {
    			sql.append(" SELECT  A.DEPT_CD												\n");
    			sql.append("         ,A.DEPT_NM												\n");
    			sql.append("         ,A.AC_UNIT_CD											\n");
    			sql.append("         ,F_GET_CODE_NAME('101',A.AC_UNIT_CD) AS AC_UNIT_NM		\n");
    			sql.append("         ,A.STD_CURRENCY_CD										\n");
    			sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT	\n");
    			sql.append(" FROM    ETEC_ERPIF.ACZ10100 A									\n");
    			sql.append("         ,ETEC_ERPIF.PUB0120T_SITE B							\n");
    			sql.append(" WHERE   A.DEPT_CD = B.SITE_CD									\n");
    			sql.append(" AND     B.USER_SABUN = '"+user.get("USER_SABUN")+"'			\n");
    			if( !params.get("ac_unit_cd").equals("") )
					sql.append(" AND      A.AC_UNIT_CD = '" + params.get("ac_unit_cd") + "'					\n");
				if( !deadflg_value.equals("") )
					sql.append(" AND      A.PRJ_OK = '"+deadflg_value+"'									\n");
				if( !params.get("DEPT_NM").equals("") )
					sql.append(" AND      UPPER(A.DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%')	\n");
    			sql.append(" ORDER BY B.CRE_DATE											\n");
    		//일반사용자 && 본사발령자 && 사용자계정 : 소속본부 현장조회  ACCT_TYPE_ID(PUB0110T 0 디폴트, 1 관리자, 10 사용자) 
    		}else if( user.get("RIGHT_NAME").equals("SITE_CONT") && user.get("HEAD_GB").equals("D") && user.get("ACCT_TYPE_ID").equals("10") ) {
    			sql.append(" SELECT  C.DEPT_CD												\n");
    			sql.append("         ,C.DEPT_NM												\n");
    			sql.append("         ,C.AC_UNIT_CD											\n");
    			sql.append("         ,F_GET_CODE_NAME('101',C.AC_UNIT_CD) AS AC_UNIT_NM		\n");
    			sql.append("         ,C.STD_CURRENCY_CD										\n");
    			sql.append("         ,F_GET_CURRENCY_DIGIT(C.STD_CURRENCY_CD) AS STD_DIGIT	\n");  
    			sql.append(" FROM    PUB0120T A												\n");
    			sql.append("         ,ETEC_ERPIF.ACZ10101 B									\n");
    			sql.append("         ,ETEC_ERPIF.ACZ10100 C									\n");
    			sql.append(" WHERE   A.BUSEO = B.ACC_DEPT_CD								\n");
    			sql.append(" AND     B.AC_UNIT_CD = C.AC_UNIT_CD							\n");
    			sql.append(" AND     A.USER_SABUN = '"+user.get("USER_SABUN")+"'			\n");
    			if( !params.get("ac_unit_cd").equals("") )
					sql.append(" AND      C.AC_UNIT_CD = '" + params.get("ac_unit_cd") + "'					\n");
				if( !deadflg_value.equals("") )
					sql.append(" AND      C.PRJ_OK = '"+deadflg_value+"'									\n");
				if( !params.get("DEPT_NM").equals("") )
					sql.append(" AND      UPPER(C.DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%')	\n");
    			sql.append(" ORDER BY C.DEPT_CD												\n");
    	
    		//일반사용자 && 본사발령자 && 그외계정 : 소속본부 하위현장 && 겸직현장 조회 
    		}else if( user.get("RIGHT_NAME").equals("SITE_CONT") && user.get("HEAD_GB").equals("D") && !user.get("ACCT_TYPE_ID").equals("10") ) {
    			
    			sql.append(" SELECT  DISTINCT DEPT_CD												\n");
		    	sql.append("         ,DEPT_NM														\n");
		    	sql.append("         ,AC_UNIT_CD													\n");
		    	sql.append("         ,AC_UNIT_NM													\n");
		    	sql.append("         ,STD_CURRENCY_CD												\n");
		    	sql.append("         ,STD_DIGIT														\n");
		    	sql.append(" FROM    (																\n");
		    	sql.append("         SELECT  B.DEPT_CD												\n");
		    	sql.append("                 ,B.DEPT_NM												\n");
		    	sql.append("                 ,B.AC_UNIT_CD											\n");
		    	sql.append("                 ,F_GET_CODE_NAME('101',B.AC_UNIT_CD) AS AC_UNIT_NM		\n");
		    	sql.append("                 ,B.STD_CURRENCY_CD										\n");
		    	sql.append("                 ,F_GET_CURRENCY_DIGIT(B.STD_CURRENCY_CD) AS STD_DIGIT	\n");
		    	sql.append("                 ,B.PRJ_OK												\n");
		    	sql.append("         FROM    PUB0120T A												\n");
		    	sql.append("                 ,ACZ10100 B											\n");
		    	sql.append("         WHERE   A.BUSEO = B.PRJ_CD										\n");
		    	sql.append("         AND     A.USER_SABUN = '"+user.get("USER_SABUN")+"'			\n");
		    	sql.append("         UNION ALL														\n");
		    	sql.append("         SELECT  A.DEPT_CD												\n");
		    	sql.append("                 ,A.DEPT_NM												\n");
		    	sql.append("                 ,A.AC_UNIT_CD											\n");
		    	sql.append("                 ,F_GET_CODE_NAME('101',A.AC_UNIT_CD) AS AC_UNIT_NM		\n");
		    	sql.append("                 ,A.STD_CURRENCY_CD										\n");
		    	sql.append("                 ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT	\n");
		    	sql.append("                 ,A.PRJ_OK												\n");
		    	sql.append("         FROM    ETEC_ERPIF.ACZ10100 A									\n");
		    	sql.append("                 ,ETEC_ERPIF.PUB0120T_SITE B							\n");
		    	sql.append("         WHERE   A.DEPT_CD = B.SITE_CD									\n");
		    	sql.append("         AND     B.USER_SABUN = '"+user.get("USER_SABUN")+"'			\n");
		    	sql.append("         )																\n");
		    	sql.append(" WHERE 1 = 1															\n");
		    	if( !params.get("ac_unit_cd").equals("") )
					sql.append(" AND      AC_UNIT_CD = '" + params.get("ac_unit_cd") + "'				\n");
				if( !deadflg_value.equals("") )
					sql.append(" AND      PRJ_OK = '"+deadflg_value+"'									\n");
				if( !params.get("DEPT_NM").equals("") )
					sql.append(" AND      UPPER(DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%')	\n");
		    	sql.append(" ORDER BY DEPT_CD														\n");
    	
		    //그외 : 전체현장조회
    		}else {
    			sql.append(" SELECT  A.DEPT_CD												\n");
    			sql.append("         ,A.DEPT_NM												\n");
    			sql.append("         ,A.AC_UNIT_CD											\n");
    			sql.append("         ,F_GET_CODE_NAME('101',A.AC_UNIT_CD) AS AC_UNIT_NM		\n");
    			sql.append("         ,A.STD_CURRENCY_CD										\n");
    			sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT	\n");
    			sql.append(" FROM    ETEC_ERPIF.ACZ10100 A									\n");
    			sql.append(" WHERE   1 = 1													\n");
    			if( !params.get("ac_unit_cd").equals("") )
					sql.append(" AND      A.AC_UNIT_CD = '" + params.get("ac_unit_cd") + "'					\n");
				if( !deadflg_value.equals("") )
					sql.append(" AND      A.PRJ_OK = '"+deadflg_value+"'									\n");
				if( !params.get("DEPT_NM").equals("") )
					sql.append(" AND      UPPER(A.DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%')	\n");
    			sql.append(" ORDER BY A.DEPT_CD											\n");
    		}
    		
    		System.out.println(sql.toString());
    		search.setStatement(sql.toString());
    		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;
    	}
    }
    
    /**
     * 2018.11.20
     * 이인오
     * 사용안함 경영정보 디비링크 삭제
     */
    
    public RowSet getSpotDeptForeign(ValueObject Params) {

        Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        StringBuffer sql = new StringBuffer();

        try {

			ValueObject user = storage.getUser();

			String dept_cd    		= user.get("DEPT_CD");
			String comon_dcr    	= user.get("COMON_DCR");
			String dept_cnt    		= user.get("DEPT_CNT");
			String deadflg			= params.get("deadflg");
			String mudept_yn		= user.get("MUDEPT_YN");
			//본사이고 계정타입이 관리자거나 경영지원(01)일때
			if( comon_dcr.equals("1") ) {
				sql.append(" SELECT  A.DEPT_CD      																		\n");
				sql.append("         ,A.DEPT_NM     																		\n");
				sql.append("         ,A.AC_UNIT_CD                                 										\n");
				sql.append("         ,F_GET_CODE_NAME('101', A.AC_UNIT_CD) AS AC_UNIT_NM                     				\n");
				sql.append("         ,A.STD_CURRENCY_CD                    												\n");
				sql.append("         ,A.LOCAL_CURRENCY_CD                    												\n");
				sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT								\n");
				sql.append("         ,B.MAPPING_SEQ							\n");
				sql.append(" FROM	ACZ10100 A, DEPT_MAPPING!CCSIF B																			\n");
				sql.append(" WHERE	A.DEPT_CD = B.DEPT_CD   																			\n");
				sql.append(" AND	A.DEPT_CD != '0000'																	\n");
				
				if( !params.get("ac_unit_cd").equals("") ) {
					sql.append(" AND      A.AC_UNIT_CD = '" + params.get("ac_unit_cd") + "'          \n");
				}
				
			//현장일때
			} else { 
				if( dept_cnt.equals("1") ){
					if( mudept_yn.equals("Y") ){
						sql.append(" SELECT  A.DEPT_CD      																	\n");
						sql.append("         ,A.DEPT_NM     																	\n");
						sql.append("         ,A.AC_UNIT_CD                                 										\n");
						sql.append("         ,F_GET_CODE_NAME('101', A.AC_UNIT_CD) AS AC_UNIT_NM                     			\n");
						sql.append("         ,A.STD_CURRENCY_CD                    												\n");
						sql.append("         ,A.LOCAL_CURRENCY_CD                    											\n");
						sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT								\n");
						sql.append("         ,F_GET_CURRENCY_DIGIT(A.LOCAL_CURRENCY_CD) AS LOCAL_DIGIT							\n");
						sql.append("         ,C.MAPPING_SEQ							\n");
						sql.append(" FROM	ACZ10100 A, PUB0130T_V B, DEPT_MAPPING!CCSIF C															\n");
						sql.append(" WHERE	SUBSTR(A.DEPT_CD,1,4) = SUBSTR(B.DEPT_CD,1,4)						\n");
						sql.append(" AND	A.DEPT_CD = C.DEPT_CD						\n");
						sql.append(" AND	B.ACCT_ID = "+user.get("ACCT_ID")+"													\n");
						sql.append(" AND	A.DEPT_CD != '0000'																	\n");
					}else {
						sql.append(" SELECT  A.DEPT_CD      																		\n");
						sql.append("         ,A.DEPT_NM     																		\n");
						sql.append("         ,A.AC_UNIT_CD                                 										\n");
						sql.append("         ,F_GET_CODE_NAME('101', A.AC_UNIT_CD) AS AC_UNIT_NM                     				\n");
						sql.append("         ,A.STD_CURRENCY_CD                    												\n");
						sql.append("         ,A.LOCAL_CURRENCY_CD                    												\n");
						sql.append("         ,F_GET_CURRENCY_DIGIT(A.STD_CURRENCY_CD) AS STD_DIGIT								\n");
						sql.append("         ,F_GET_CURRENCY_DIGIT(A.LOCAL_CURRENCY_CD) AS LOCAL_DIGIT							\n");
						sql.append("         ,B.MAPPING_SEQ							\n");
						sql.append(" FROM	ACZ10100 A, DEPT_MAPPING!CCSIF B																			\n");
						sql.append(" WHERE	A.DEPT_CD = B.DEPT_CD													\n");
						sql.append(" AND	SUBSTR(A.DEPT_CD,1,4) = '"+dept_cd+"'													\n");
						sql.append("   AND A.AC_UNIT_CD != '50'                           										\n");
						sql.append(" AND	A.DEPT_CD != '0000'																	\n");
					}
				}
			}
			

			if( !deadflg.equals("") )
				sql.append(" AND      A.PRJ_OK = '"+deadflg+"'										\n");

			if( !params.get("DEPT_NM").equals("") )
				sql.append(" AND      UPPER(A.DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%')	\n");

			sql.append(" ORDER BY A.DEPT_CD                   										\n");
			
        	search.setStatement(sql.toString());
        	WAFLogger.debug(sql.toString());
            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;
        }
    }
    
    private RowSet getSpotDeptAll(ValueObject Params) {
    	
    	Search search = new SearchImpl();
    	RowSet rowSet = new RowSetImpl();
    	StringBuffer sql = new StringBuffer();
    	
    	try {
    		
    		ValueObject user = storage.getUser();
    		
    		String dept_cd    		= user.get("DEPT_CD");
    		String comon_dcr    	= user.get("COMON_DCR");
    		String dept_cnt    		= user.get("DEPT_CNT");
    		String deadflg			= params.get("deadflg");
    		
    		//본사이고 계정타입이 관리자거나 경영지원(01)일때
    		if( comon_dcr.equals("1") ) {
    			sql.append(" SELECT  DEPT_CD      																		\n");
    			sql.append("         ,DEPT_NM     																		\n");
    			sql.append("         ,AC_UNIT_CD                                 										\n");
    			sql.append("         ,F_GET_CODE_NAME('101', AC_UNIT_CD) AS AC_UNIT_NM                     				\n");
    			sql.append("         ,STD_CURRENCY_CD                    												\n");
    			sql.append("         ,LOCAL_CURRENCY_CD                    												\n");
    			sql.append("         ,F_GET_CURRENCY_DIGIT(STD_CURRENCY_CD) AS STD_DIGIT								\n");
    			sql.append("         ,F_GET_CURRENCY_DIGIT(LOCAL_CURRENCY_CD) AS LOCAL_DIGIT							\n");
    			sql.append(" FROM	ETEC_ERPIF.ACZ10100																			\n");
    			sql.append(" WHERE	1 = 1   																			\n");
				sql.append("   AND AC_UNIT_CD != '50'                           										\n");
    			//sql.append(" AND	DEPT_CD != '0000'																	\n");
    			
    			if( !params.get("ac_unit_cd").equals("") ) {
    				sql.append(" AND      AC_UNIT_CD = '" + params.get("ac_unit_cd") + "'          \n");
    			}
    			
    			//현장일때
    		} else { 
    			if( dept_cnt.equals("1") ){
    				sql.append(" SELECT  DEPT_CD      																		\n");
    				sql.append("         ,DEPT_NM     																		\n");
    				sql.append("         ,AC_UNIT_CD                                 										\n");
    				sql.append("         ,F_GET_CODE_NAME('101', AC_UNIT_CD) AS AC_UNIT_NM                     				\n");
    				sql.append("         ,STD_CURRENCY_CD                    												\n");
    				sql.append("         ,LOCAL_CURRENCY_CD                    												\n");
    				sql.append("         ,F_GET_CURRENCY_DIGIT(STD_CURRENCY_CD) AS STD_DIGIT								\n");
    				sql.append("         ,F_GET_CURRENCY_DIGIT(LOCAL_CURRENCY_CD) AS LOCAL_DIGIT							\n");
    				sql.append(" FROM	ETEC_ERPIF.ACZ10100																			\n");
    				sql.append(" WHERE	DEPT_CD = '"+dept_cd+"'																\n");
    				sql.append("   AND AC_UNIT_CD != '50'                           										\n");
    				//sql.append(" AND	DEPT_CD != '0000'																	\n");
    			}
    		}
    		
    		
    		if( !deadflg.equals("") )
    			sql.append(" AND      PRJ_OK = '"+deadflg+"'										\n");
    		
    		if( !params.get("DEPT_NM").equals("") )
    			sql.append(" AND      UPPER(DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%')	\n");
    		
    		sql.append(" ORDER BY DEPT_CD                   										\n");
    		
    		search.setStatement(sql.toString());
    		WAFLogger.debug(sql.toString());
    		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 RowSet getDivisionRowSet() throws Exception {
		  
		  Search search = new SearchImpl();
		  RowSet listRowSet = null;
		  StringBuffer sql = new StringBuffer();
		  
		  ValueObject user = storage.getUser();
		  String head_dept_cd = user.get("HEAD_DEPT_CD");
		  String acc_dept_cd = user.get("ACC_DEPT_CD");
		  String comon_dcr = user.get("COMON_DCR");
		  
		  try{
				  sql.append("	SELECT '' AS DETAILCD, '전체' AS DETAILNM FROM DUAL							\n");
				  sql.append("	UNION ALL																	\n");
				  sql.append("	SELECT DETAILCD, DETAILNM FROM EBID_COM911T     				\n");
				  sql.append("		WHERE BASECD = '101'							\n");
				  if(head_dept_cd.equals("30")){
					  sql.append("			AND DETAILCD <> '10'     											\n");
					  sql.append("			AND DETAILCD <> '20'												\n");
					  sql.append("			AND DETAILCD <> '40'     											\n");
					  sql.append("			AND DETAILCD <> '50'												\n");
					  sql.append("			AND DETAILCD <> '60'												\n");
					  sql.append("			AND DETAILCD <> '99'       										\n");
				  }else{
					  sql.append("			AND DETAILCD <> '30'     											\n");
					  sql.append("			AND DETAILCD <> '40'     											\n");
					  sql.append("			AND DETAILCD <> '99'       										\n");
					  
				  }

				  WAFLogger.debug(sql.toString());
			  search.setStatement(sql.toString());
	          listRowSet = search.execute();
		  }
		  catch(WAFSQLException e) {
	          super.doException(e);
	          return null;
	      }
	      finally {
	          if( listRowSet == null ){
	        	  listRowSet = new RowSetImpl();
	          }
	          
	      }
	      return listRowSet;
		}
    
    /**
     * 현장코드 검색을 처리한다.(전체)
     * @param params
     * @return <code>RowSet</code>
     */
    /**
     * 2018.11.20
     * 이인오
     * 사용안함 경영정보 디비링크 삭제
     */
    public RowSet getSpotDept2(ValueObject Params) {

    	Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        StringBuffer sql = new StringBuffer();

        try {			
			sql.append(" SELECT   A.DEPT_CD, A.DEPT_NM, A.AC_UNIT_CD, A.REP_DEPT_CD, A.PRJ_OK, B.MAPPING_SEQ     \n");
			sql.append(" FROM     ACZ10100V A, DEPT_MAPPING!CCSIF B                                        \n");
			sql.append(" WHERE    A.DEPT_CD = B.DEPT_CD                                         		\n");
			sql.append(" AND	  A.DEPT_CD != '0000'                                     \n");
			
			//사업부
			if( !params.get("ac_unit_cd").equals("") )
				sql.append(" AND      A.AC_UNIT_CD = '" + params.get("ac_unit_cd") + "' \n");

			if( !params.get("DEADFLG").equals("") )
				sql.append(" AND      A.PRJ_OK = '" + params.get("deadflg") + "' \n");

			//부서명
			if( !params.get("DEPT_NM").equals("") )
				sql.append(" AND      UPPER(A.DEPT_NM) LIKE UPPER('%" + params.get("dept_nm") + "%') \n");

			sql.append(" ORDER BY A.DEPT_CD                   \n");
			
        	search.setStatement(sql.toString());
            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;
        }
    }
}
