/**
 * @(#)file    PreRequestSignBiz.java
 * @(#)author  OK
 * @(#)version 1.0
 *
 * Copyright (c) www.udapsoft.co.kr, Inc.
 */
package kr.co.udapsoft.ebid.buyer.bid.outside.biz;

import oracle.toplink.internal.ox.StrBuffer;
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.sql.util.RowSetUtility;
import kr.co.hsnc.common.util.ValueObject;
import kr.co.udapsoft.ebid.buyer.common.file.FileManager;

import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

import kr.co.udapsoft.ebid.buyer.bid.purchase.biz.BidCommonBiz;

/**
 * 
 * @version 1.0
 */
public class BidSuccessSignBiz extends Biz {
	BidCommonBiz BidCommonBiz = new BidCommonBiz(storage);
	public BidSuccessSignBiz(HandlerStorage storage) {
		super(storage);
	}

    public void doBiz() throws Exception {
		ValueObject vo = new ValueObject();
		RowSet suppinfo = null;
		
		vo = getBidMaster(params.get("sign_bid_no"),params.get("sign_bid_deg"));	//입찰 정보 조회
		suppinfo = getSuppInfo(params.get("sign_bid_no"),params.get("sign_bid_deg"));	//입찰 업체 정보 조회

		
		//String doctitle = "-"+vo.get("BID_MASTER_NM")+vo.get("DEPT_NM");
		//2015.8.10 조재윤과장 요청 변경.
        String doctitle = "["+vo.get("DEPT_NM") + "]" + vo.get("BID_MASTER_NM");
		vo.set("doctitle", doctitle);
        
        storage.addValueObject(vo.get("DOC_ETC_IN"), BidCommonBiz.getfilelist(vo.get("DOC_ETC_IN"),vo.get("DEMANDED_ID"),vo.get("DOC_ETC_IN")));
        storage.addValueObject(vo.get("DOC_ETC_OUT"), BidCommonBiz.getfilelist(vo.get("DOC_ETC_OUT"),vo.get("DEMANDED_ID"),vo.get("DOC_ETC_OUT")));
        storage.addValueObject(vo.get("TOT_FILE_GB"), BidCommonBiz.getfilelist(vo.get("TOT_FILE_GB"),vo.get("DEMANDED_ID"),vo.get("TOT_FILE_GB")));
        
		storage.addValueObject("bidmaster", vo);
        storage.addRowSet("suppinfo", suppinfo);
        
        storage.addValueObject("SIGN_INFO", getSignInfo(vo.get("DEMANDED_ID")));
        storage.addValueObject("SIGN_INFO2", getSignInfo2(params.get("sign_bid_no"),params.get("sign_bid_deg")));
        
        RowSet getFileListRowSet = getFileListRowSet(params.get("sign_bid_no"),params.get("sign_bid_deg"));
        storage.addRowSet("getFileListRowSet", getFileListRowSet);
   }

    public ValueObject getBidMaster(String sign_bid_no,String sign_bid_deg) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        StrBuffer sqlstr = new StrBuffer();
        ValueObject rowObject = null;
        
        try {
        	sqlstr.append("SELECT (SELECT DEPART_DEPT_NM FROM PUB0120T WHERE ACCT_ID = A.EMP_NO) AS DEPART_DEPT_NM	--요청부서			\n");
			sqlstr.append("       ,F_GET_USER_NM('"+params.get("ACCT_ID")+"')  AS CRE_NAME --작성자				\n");
			sqlstr.append("       ,TO_CHAR(SYSDATE,'YYYY-MM-DD') AS CRE_DT --작성일				\n");
			sqlstr.append("       ,(select REPLACE(ORDER_COMP_NM,'T_','') from ETEC_ERPIF.ACZ10100 WHERE DEPT_CD = A.DEPT_CD) DEALER_NM -- 발주처				\n");
			sqlstr.append("       ,(SELECT DEPT_NM FROM ETEC_ERPIF.ACZ10100 WHERE DEPT_CD = A.DEPT_CD) AS DEPT_NM -- pjt명				\n");
			sqlstr.append("       ,A.SITEDESCDATE -- 현장설명 예정일				\n");
			sqlstr.append("       ,A.SITEDESCPLACE -- 현장설명 장소				\n");
			sqlstr.append("       ,A.BID_MASTER_NM  -- 계약명				\n");
			sqlstr.append("       ,A.BID_NO -- 발주의뢰번호				\n");
			sqlstr.append("       ,A.BID_DEG -- 차수				\n");
			sqlstr.append("       ,A.DEPT_CD -- 현장코드																																		\n");
			//sqlstr.append("       ,REPLACE(A.BID_NO,'INQ','PO') AS CONF_NO -- 계약번호				\n");
			sqlstr.append("       ,A.CONF_NO AS CONF_NO -- 계약번호				\n");  //2015.11.17수정 
			sqlstr.append("       ,F_GET_CODE_NAME('ONBID',A.ONBID_YN)||'/'||F_GET_CODE_NAME('CMPT_CD',A.CMPT_CD) AS BID_TYPE-- 입찰방식				\n");
			sqlstr.append("       ,A.ACT_AMT -- 예산금액				\n");
			sqlstr.append("       ,F_GET_HANGUL(A.ACT_AMT) AS ACT_AMT_NM -- 예산금액				\n");
			//sqlstr.append("       ,A.ACT_RATE -- 예산금액				\n");
			sqlstr.append("       ,A.CONT_AMT -- 예산금액				\n");
			sqlstr.append("       ,F_GET_HANGUL(A.CONT_AMT) AS CONT_AMT_NM -- 예산금액				\n");
			sqlstr.append("       ,A.DELIVERY_PLACE -- 현장위치				\n");
			sqlstr.append("       ,DECODE(DIV_PO_YN,'Y','',DECODE(A.ACT_AMT,'0',' ',REPLACE(TRIM(TO_CHAR(((B.ESTI_TOT_AMT*NVL(B.EXCHANGE, 1))/A.ACT_AMT * 100),'999,999,999.99')),'.00',''))) AS ACT_RATE-- 예산금액				\n");
			sqlstr.append("       ,DECODE(DIV_PO_YN,'Y','',DECODE(A.CONT_AMT,'0',' ',REPLACE(TRIM(TO_CHAR(((B.ESTI_TOT_AMT*NVL(B.EXCHANGE, 1))/A.CONT_AMT * 100),'999,999,999.99')),'.00',''))) AS CONT_RATE-- 예산금액				\n");
			sqlstr.append("       ,F_GET_CODE_NAME('PUR_LEAD_GB',A.DELIVERY_CONDITION) AS DELIVERY_CONDITION -- 인도조건			\n");
			sqlstr.append("       ,F_GET_CODE_NAME('PAY_DIV',A.PAY_DIV) AS PAY_DIV -- 계약범위			\n");
			sqlstr.append("       ,TO_CHAR(A.BID_TO_DT,'YYYY-MM-DD') AS BID_TO_DT --입찰마감일				\n");
			sqlstr.append("       ,TO_CHAR(TO_DATE(A.DELI_FROM_DY,'YYYYMMDD'),'YYYY-MM-DD')	AS DELI_FROM_DY			\n");
			sqlstr.append("       ,TO_CHAR(TO_DATE(A.DELI_TO_DY,'YYYYMMDD'),'YYYY-MM-DD')	AS DELI_TO_DY			\n");
			sqlstr.append("       ,TO_CHAR(TO_DATE(A.DELI_START_DT,'YYYYMMDD'),'YYYY-MM-DD') AS DELI_START_DT			\n");
			sqlstr.append("       ,TO_CHAR(TO_DATE(A.DELI_END_DT,'YYYYMMDD'),'YYYY-MM-DD')	AS DELI_END_DT			\n");
			sqlstr.append("       ,F_GET_CODE_NAME('PUR_LEAD_GB',A.DELIVERY_CONDITION) AS DELIVERY_CONDITION_NM --납품조건				\n");
			sqlstr.append("       ,DECODE(A.CBC_FIRST_RATE,'','',A.CBC_FIRST_RATE||'%') || A.PBC_FIRST_CONDI AS FIRST_AMT-- 선급금				\n");
			sqlstr.append("       ,DECODE(A.CPC_MID_RATE,'','',A.CPC_MID_RATE||'%') || A.PBC_MID_CONDI AS MID_AMT -- 중도금				\n");
			sqlstr.append("       ,DECODE(A.PBC_REST_RATE,'','',A.PBC_REST_RATE||'%') || A.PBC_REST_CONDI AS REST_AMT-- 잔금				\n");
			sqlstr.append("       ,A.WARR_RATE	--하자보증율		\n");
			sqlstr.append("       ,A.WARR_CONDI	--하자보증율		\n");
			sqlstr.append("       ,A.PBC_DEFECT_CONDI	--하자보증기간		\n");
			sqlstr.append("       ,A.CBC_DEFECT_DAY	--하자보증기간		\n");
			sqlstr.append("       ,A.CBC_DERECT_TERM_CD	--하자보증기간		\n");
			sqlstr.append("       ,F_GET_CODE_NAME('CBC_DERECT_TERM_CD',A.CBC_DERECT_TERM_CD)  AS CBC_DERECT_TERM_NM	--하자보증기간	\n");
			sqlstr.append("       ,A.CPC_MID_RATE			\n");
			sqlstr.append("       ,A.OBC_MID_PAYDAY			\n");
			sqlstr.append("       ,A.OBC_MID_CASH_RATE			\n");
			sqlstr.append("       ,A.OBC_MID_BILL_RATE			\n");
			sqlstr.append("       ,A.OBC_FIN_PAYDAY			\n");
			sqlstr.append("       ,A.OBC_FIN_CASH_RATE			\n");
			sqlstr.append("       ,A.OBC_FIN_BILL_RATE			\n");
			sqlstr.append("       ,A.OBC_FRST_CONT_RATE			\n");
			sqlstr.append("       ,A.PBC_REST_RATE			\n");
			sqlstr.append("       ,A.INNER_REMARKS			\n");
			sqlstr.append("       ,A.DOC_ETC_IN					\n");
			sqlstr.append("       ,A.OUTER_REMARKS			\n");
			sqlstr.append("       ,A.DOC_ETC_OUT				\n");
			sqlstr.append("       ,A.DEMANDED_ID				\n");
			sqlstr.append("       ,A.CMPT_CD						\n");
			sqlstr.append("       ,A.DELI_END_PLACE						\n");
			sqlstr.append("       ,B.FILE_GB						\n");
			sqlstr.append("       ,C.TOT_FILE_GB						\n");
			sqlstr.append("       ,(SELECT wmsys.wm_concat(VENDOR_NAME) CONCAT FROM BID_SUPP WHERE SUCC_YN = 'Y' AND BID_NO = A.BID_NO AND BID_DEG = A.BID_DEG	GROUP BY BID_NO,BID_DEG) AS VENDOR_NAME \n");
			sqlstr.append("       ,DECODE(A.CURRENCY_GB,'KRW','',T.CHG_CODE02) ||F_GET_D_CURRENCY(B.ESTI_TOT_AMT,F_GET_CURRENCY_DIGIT(NVL(A.CURRENCY_GB,'KRW'))) AS ESTI_TOT_AMT																		\n");
			sqlstr.append("       ,F_GET_HANGUL2(B.ESTI_TOT_AMT) AS ESTI_TOT_AMT_NM				\n");
			sqlstr.append("       ,B.VENDOR_CD				\n");
			sqlstr.append("       ,CHG_CODE02																															\n");
			sqlstr.append("       ,CHG_CODE06																															\n");
			sqlstr.append("		  ,A.CURRENCY_GB																														\n");
			sqlstr.append("		  ,F_GET_D_CURRENCY(NVL(WON_ESTI_TOT_AMT,0),0)   AS WON_ESTI_TOT_AMT																	\n");
			sqlstr.append("		  ,F_GET_HANGUL2(NVL(WON_ESTI_TOT_AMT,0)) AS WON_ESTI_AMT_NM																			\n");
			sqlstr.append("		  ,DECODE(DIV_PO_YN,'Y','',DECODE(A.ACT_AMT,'0',' ',REPLACE(TRIM(TO_CHAR((A.ACT_AMT - (B.ESTI_TOT_AMT*NVL(B.EXCHANGE, 1))),'999,999,999,999.99')),'.00',''))) AS ACT_SAVINGS    \n");
			sqlstr.append("       ,A.MAIN_PR_CONTENTS																															\n");
			sqlstr.append("       ,A.CBC_FIRST_RATE																																\n");
			sqlstr.append("       ,A.CONTFUL_RATE																																\n");
			sqlstr.append("       ,A.PO_PRC																																\n");
			sqlstr.append("       ,A.RES_PRC																																\n");
			sqlstr.append("       ,TO_CHAR(TO_DATE(A.CONT_APP_REQ_DATE,'YYYYMMDD'),'YYYY-MM-DD')	AS CONT_APP_REQ_DATE													\n");
			sqlstr.append("  FROM BID_MASTER A , BID_SUPP B , TBE_INFO C , EBID_COM911T T		\n");
			sqlstr.append("  WHERE A.BID_NO = '" + sign_bid_no + "'					\n");
			sqlstr.append("    AND A.BID_DEG = '" + sign_bid_deg + "'				\n");
			sqlstr.append("    AND A.BID_NO = B.BID_NO									\n");
			sqlstr.append("    AND A.BID_DEG = B.BID_DEG								\n");
			sqlstr.append("    AND A.BID_NO = C.BID_NO(+)									\n");
			sqlstr.append("    AND A.BID_DEG = C.BID_DEG(+)								\n");
			sqlstr.append("    AND B.SUCC_YN = 'Y'										\n");
			sqlstr.append("    AND T.BASECD = '911'										\n");
			sqlstr.append("    AND T.DETAILCD = A.CURRENCY_GB						\n");
            search.setStatement(sqlstr.toString());
            listRowSet = search.execute();
            rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getBidMaster() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {
            if( rowObject == null ) rowObject = new ValueObject();
            return rowObject;
        }
    }
    
    public RowSet getSuppInfo(String sign_bid_no,String sign_bid_deg) {
    	Search search = new SearchImpl();
    	RowSet listRowSet = null;
    	StrBuffer sqlstr = new StrBuffer();
    	try {
    		sqlstr.append("SELECT A.VENDOR_NAME		\n");
			sqlstr.append(",A.RECM_DEPT_NM		\n");
			sqlstr.append(",B.CREDIT_GRADE		\n");
			sqlstr.append(",(SELECT CST_DOC_NAME FROM PUR1000T WHERE PUR_CONT_ID = C.PUR_CONT_ID) AS CST_DOC_NAME		\n");
			sqlstr.append("FROM BID_SUPP A		\n");
			sqlstr.append(", SUPP_INFO B		\n");
			sqlstr.append(", (SELECT MAX(PUR_CONT_ID) AS PUR_CONT_ID,CORP_ID FROM PUR1000T GROUP BY CORP_ID) C		\n");
			sqlstr.append("WHERE A.VENDOR_CD = B.CORP_ID(+)		\n");
			sqlstr.append("AND A.VENDOR_CD = C.CORP_ID(+)		\n");
			sqlstr.append("AND BID_NO = '"+sign_bid_no+"'			\n");
			sqlstr.append("AND BID_DEG = '"+sign_bid_deg+"'		\n");
    		search.setStatement(sqlstr.toString());
    		listRowSet = search.execute();
    	}
    	catch(Exception e) {
    		WAFLogger.error(this.getClass().getName() + " --> getSuppInfo() : " + e.getMessage());
    		WAFLogger.error("SQL : " + search.getStatement());
    		WAFLogger.error(e);
    		return null;
    	}
    	finally {
    		if( listRowSet == null ) listRowSet = null;
    		return listRowSet;
    	}
    }
    
    /** 첨부서류조회 
     * @return
     * @throws Exception
     */
    public RowSet getfileListRowSet(String payreqId, String code) throws Exception {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        StringBuffer sql = new StringBuffer();
        try {

    		sql.append("	SELECT distinct A.DETAILCD,								\n");
    		sql.append(" 		   A.DETAILNM,								\n");
    		sql.append(" 		   B.ID AS DOC_CD							\n");
    		sql.append("	FROM EBID_COM911T A, PUB0510T B				\n");
    		sql.append("	WHERE A.BASECD = 'PUR_PAY_FILE'					\n");
    		sql.append("	AND A.DETAILCD = B.ID(+)						\n");
    		sql.append("	AND B.FILE_GB(+) = '"+payreqId+"'				\n");
    		sql.append("	ORDER BY A.DETAILCD								\n");
    		
        	
            search.setStatement(sql.toString());
            
            listRowSet = search.execute();
            WAFLogger.debug(sql.toString());
            
           
            
        } catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getListRowSet() : \n" + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            
        } finally {
            if( listRowSet == null ) listRowSet = new RowSetImpl();
           
        }
        
        return listRowSet;
    }
    
    /**
	 * 발주의뢰 결재 정보 조회
	 * @param DEMANDED_ID
	 * @return
	 */
	private ValueObject getSignInfo(String DEMANDED_ID) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        ValueObject vo = new ValueObject();
        
     //   String sqlstr = "";
        StrBuffer sqlstr = new StrBuffer();
        try{
        	sqlstr.append("SELECT DEMANDED_ID, SIGN_CLASS_CD, DOC_ID, YEAR, SIGN_DECI_CLASS, APPROVAL_DATE, APPROVAL_SABUN, APPROVAL_USER                  \n");
        	sqlstr.append("FROM (                                                                                                                    \n");
        	sqlstr.append("          SELECT A.DEMANDED_ID, C.SIGN_CLASS_CD, C.DOC_ID, TO_CHAR(C.CRE_DATE,'YYYYMMDD') YEAR, SIGN_DECI_CLASS, APPROVAL_DATE, APPROVAL_SABUN, APPROVAL_USER  \n");
        	sqlstr.append("          FROM PMM_DEMANDED_REQUEST A, ETECEPC.MR_REQ_PO B, SIGN001T C                                              \n");
        	sqlstr.append("          WHERE A.DEMANDED_ID = B.BUYREQNO                                                      \n");
        	sqlstr.append("          AND B.APPR_ID = C.SIGN_INTERFACE_ID                                                                             \n");
        	sqlstr.append("          AND  C.SIGN_CLASS_CD = 'ebid_mrD'                                                                                    \n");
        	sqlstr.append("          AND C.SIGN_DECI_CLASS IN ( '14', '24')                                                                          \n");
        	sqlstr.append("          UNION ALL                                                                                                       \n");
        	sqlstr.append("          SELECT  A.DEMANDED_ID,  SIGN_CLASS_CD, DOC_ID, TO_CHAR(B.CRE_DATE,'YYYYMMDD') YEAR, SIGN_DECI_CLASS, APPROVAL_DATE, APPROVAL_SABUN, APPROVAL_USER    \n");
        	sqlstr.append("          FROM PMM_DEMANDED_REQUEST A, SIGN001T B                                                                   \n");
        	sqlstr.append("          WHERE  A.DEMANDED_KIND IN ('C', 'P',  'O')                                                                            \n");
        	sqlstr.append("          AND  B.SIGN_CLASS_CD = 'prD'                                                                                    \n");
        	sqlstr.append("          AND B.SIGN_DECI_CLASS IN ( '14', '24')                                                                          \n");
        	sqlstr.append("          AND A.DEMANDED_ID =  REGEXP_REPLACE(B.KEY_COL1,'[^0-9]')                                                                                  \n");
        	sqlstr.append(") A                                                                                                                       \n");
        	sqlstr.append("WHERE 1=1                                                                                                                 \n");
        	sqlstr.append("AND A.DEMANDED_ID = ?                                                                                                     \n");
        	sqlstr.append("ORDER BY DEMANDED_ID                                                                                                      \n");

        	
        	search.setStatement(sqlstr.toString());
        	search.addParameter(DEMANDED_ID);
            rowSet = search.execute();
            if(rowSet.size()>0){
            	vo = RowSetUtility.getValueObject(rowSet.getRow(0));
            }
        }
        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 vo;
	}
	/**
	 * 발주의뢰 결재 정보 조회
	 * @param DEMANDED_ID
	 * @return
	 */
	private ValueObject getSignInfo2(String bid_no, String bid_deg) {
		
		Search search = new SearchImpl();
		RowSet rowSet = new RowSetImpl();
		ValueObject vo = new ValueObject();
		
		//   String sqlstr = "";
		StrBuffer sqlstr = new StrBuffer();
		try{
			sqlstr.append("SELECT  A.BID_NO , A.BID_DEG ,  B.DOC_ID ,B.YEAR        		\n");
			sqlstr.append("from BID_MASTER A                                    		\n");
			sqlstr.append("   , (  SELECT KEY_COL1   									\n");
			sqlstr.append("             , KEY_COL2                              		\n");
			sqlstr.append("             , DOC_ID  ,TO_CHAR(B.CRE_DATE,'YYYYMMDD') YEAR  \n");
			sqlstr.append("        FROM SIGN001T B                        		\n");
			sqlstr.append("        WHERE SIGN_CLASS_CD IN ( 'ebid_oinqD' , 'ebid_orebqD')         \n");
			sqlstr.append("        AND SIGN_DECI_CLASS = '14'                   		\n");
			sqlstr.append("      ) B                                            		\n");
			sqlstr.append(" WHERE A.BID_NO = B.KEY_COL1(+)   							\n");
			sqlstr.append(" AND   A.BID_DEG = B.KEY_COL2(+)                   			\n");
			sqlstr.append(" AND   A.BID_NO =   ?                              			\n");
			sqlstr.append(" ORDER BY A.BID_DEG DESC                              		\n");
			
			
			search.setStatement(sqlstr.toString());
			search.addParameter(bid_no);
			rowSet = search.execute();
			if(rowSet.size()>0){
				vo = RowSetUtility.getValueObject(rowSet.getRow(0));
			}
		}
		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 vo;
	}
	
    /** 첨부서류조회 
     * @return
     * @throws Exception
     */
	private RowSet getFileListRowSet(String sign_bid_no, String sign_bid_deg) throws Exception {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        StringBuffer sqlstr = new StringBuffer();
        try {

        	sqlstr.append(" SELECT DISTINCT  \n");
        	sqlstr.append("        A.DETAILCD,						 \n");
        	sqlstr.append(" 	   A.DETAILNM,								 \n");
        	sqlstr.append(" 	   A.DETAILSORTNM,							 \n");
        	sqlstr.append(" 	   B.ID AS DOC_CD,							 \n");
        	sqlstr.append(" 	   'SUB_SUCCESSFILE_GB_" + sign_bid_no + "_" + sign_bid_deg + "' AS FILE_GB,	 \n");
        	sqlstr.append(" 	   NVL(B.ID, TO_NUMBER(A.DETAILCD)) AS ID,	 \n");
        	sqlstr.append(" 	   A.CHG_CODE02 AS EDIT_YN	 \n");
        	sqlstr.append("	FROM EBID_COM911T A, PUB0510T B					 \n");
        	sqlstr.append("	WHERE A.BASECD = 'SUB_SUCCESSFILE_GB'	 \n");
        	sqlstr.append("	AND A.CHG_CODE01 = 'Y'			 \n");
        	sqlstr.append("	AND A.DETAILCD = B.ID(+)						 \n");
        	sqlstr.append("	AND B.FILE_GB(+) = 'SUB_SUCCESSFILE_GB_" + sign_bid_no + "_" + sign_bid_deg + "'	 \n");
        	sqlstr.append("UNION ALL \n");
        	sqlstr.append("-- TBE 자료 \n");
        	sqlstr.append("SELECT DISTINCT \n");
        	sqlstr.append("       C.DETAILCD,         \n");
        	sqlstr.append("       C.DETAILNM, \n");
        	sqlstr.append("       C.DETAILSORTNM,  \n");
        	sqlstr.append("       B.ID AS DOC_CD,        \n");
        	sqlstr.append(" 	  A.TOT_FILE_GB AS FILE_GB,	 \n");
        	sqlstr.append(" 	  NVL(B.ID, A.DEMANDED_ID) AS ID,	 \n");
        	sqlstr.append(" 	  C.CHG_CODE02 AS EDIT_YN	 \n");
        	sqlstr.append("  FROM (     \n");
        	sqlstr.append("         SELECT A.DEMANDED_ID, NVL(B.TOT_FILE_GB, 'TBE_TOT" + sign_bid_no + sign_bid_deg + "') AS TOT_FILE_GB, '110' AS DETAILCD \n");
        	sqlstr.append("           FROM BID_MASTER A, TBE_INFO B  \n");
        	sqlstr.append("           WHERE A.BID_NO = '" + sign_bid_no + "'				 \n");
        	sqlstr.append("             AND A.BID_DEG = '" + sign_bid_deg + "'				 \n");
        	sqlstr.append("             AND A.BID_NO = B.BID_NO(+)							 \n");
        	sqlstr.append("             AND A.BID_DEG = B.BID_DEG(+)    \n");
        	sqlstr.append("       ) A, PUB0510T B, EBID_COM911T C     \n");
        	sqlstr.append(" WHERE A.DEMANDED_ID = B.ID(+) \n");
        	sqlstr.append("   AND A.TOT_FILE_GB = B.FILE_GB(+)    	 \n");
        	sqlstr.append("	  AND C.BASECD = 'SUB_SUCCESSFILE_GB'	 \n");
        	sqlstr.append("	  AND A.DETAILCD = C.DETAILCD    		 \n");
        	sqlstr.append("UNION ALL \n");
        	sqlstr.append("SELECT DETAILCD, \n");
        	sqlstr.append("       DETAILNM, \n");
        	sqlstr.append("       DETAILSORTNM,  \n");
        	sqlstr.append("       TO_NUMBER(DETAILCD) AS DOC_CD, \n");
        	sqlstr.append(" 	  '' AS FILE_GB,	 \n");
        	sqlstr.append(" 	  TO_NUMBER(DETAILCD) AS ID,	 \n");
        	sqlstr.append(" 	  CHG_CODE02 AS EDIT_YN	 \n");
        	sqlstr.append("  FROM EBID_COM911T      \n");
        	sqlstr.append("	WHERE BASECD = 'SUB_SUCCESSFILE_GB'	 \n");
        	sqlstr.append("	  AND DETAILCD = '130'			 \n");        	
        	sqlstr.append("UNION ALL \n");
        	sqlstr.append("-- 외부자료     \n");
        	sqlstr.append("SELECT DISTINCT  \n");
        	sqlstr.append("       C.DETAILCD, \n");
        	sqlstr.append("       C.DETAILNM, \n");
        	sqlstr.append("       C.DETAILSORTNM,  \n");
        	sqlstr.append("       B.ID AS DOC_CD,  \n");
        	sqlstr.append(" 	  A.DOC_ETC_OUT AS FILE_GB,	 \n");
        	sqlstr.append(" 	  NVL(B.ID, A.DEMANDED_ID) AS ID,	 \n");
        	sqlstr.append(" 	  C.CHG_CODE02 AS EDIT_YN	 \n");
        	sqlstr.append("  FROM BID_MASTER A, PUB0510T B, EBID_COM911T C  \n");
        	sqlstr.append("  WHERE A.BID_NO = '" + sign_bid_no + "'					\n");
        	sqlstr.append("    AND A.BID_DEG = '" + sign_bid_deg + "'				\n");
        	sqlstr.append("    AND A.DEMANDED_ID = B.ID(+) \n");
        	sqlstr.append("    AND A.DOC_ETC_OUT = B.FILE_GB(+)      \n");
        	sqlstr.append("	   AND C.BASECD = 'SUB_SUCCESSFILE_GB'	 \n");
        	sqlstr.append("	   AND C.DETAILCD = '160'       		 \n");
        	sqlstr.append("ORDER BY DETAILCD \n");
    		
            search.setStatement(sqlstr.toString());
            
            listRowSet = search.execute();
            WAFLogger.debug(sqlstr.toString());

        } catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getListRowSet() : \n" + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            
        } finally {
            if( listRowSet == null ) listRowSet = new RowSetImpl();
           
        }
        
        return listRowSet;
    }	
}
