/**
 * @(#)file    BidIngBiz.java
 * @(#)author  Son Hyung Min 
 * @(#)version 1.0
 * @(#)date    2014-06-23
 * @(#)since   JDK 1.4.2
 */
package kr.co.udapsoft.ebid.buyer.bid.purchase.biz;



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

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.Row;
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 kr.co.udapsoft.common.code.CommCodeManager;
import kr.co.udapsoft.ebid.buyer.common.file.FileManager;
import kr.co.udapsoft.ebid.buyer.sycs.user.biz.UserCommon;

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 BidResolutionListBiz extends Biz {

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

	public void doBiz() throws Exception {
        ValueObject user = new ValueObject();
		
		if(storage.compareEvent("SHEET_SELECT")){
			params.set("sheet1", getBoardList(params));
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
		}
	}

	/**
	 * 발주의뢰(외주) 접수를 검색하여 리턴
	 * @param Params
	 * @return
	 */
	private RowSet getBoardList(ValueObject param) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        
     //   String sqlstr = "";
        StrBuffer sqlstr = new StrBuffer();
        try{ 

        	sqlstr.append("				SELECT B.BID_NO                                                                                 \n");
        	sqlstr.append("				      ,  B.BID_DEG                                                                          	\n");
        	sqlstr.append("				      ,  B.VENDOR_CD                                                                        	\n");
        	sqlstr.append("				      ,  GET_CORP_NM_EBID(B.VENDOR_CD) AS VENDOR_NM                                             \n");
        	sqlstr.append("				      , A.BID_MASTER_NM                                                                      	\n");                                              
        	sqlstr.append("				      , A.ONBID_YN, A.DEMANDED_ID                                                                           	\n");                                                 
        	sqlstr.append("				      , TO_CHAR(A.REQUEST_DATE,'YYYY-MM-DD') AS REQUEST_DATE                                 	\n");                       
        	sqlstr.append("				      , TO_CHAR(A.RECEIPT_DATE,'YYYY-MM-DD') AS RECEIPT_DATE                                 	\n");
        	sqlstr.append("				      , TO_CHAR(A.OPEN_DT,'YYYY-MM-DD HH24:MI') AS OPEN_DT                                      \n");                      
        	sqlstr.append("				      , A.OPEN_EMPNM                                                                            \n");                                             
        	sqlstr.append("				      , TO_CHAR(C.TBE_FIN_DT,'YYYY-MM-DD HH24:MI') AS TBE_FIN_DT                                \n");
        	sqlstr.append("				      , GET_DEPT_NM(A.DEPT_CD)           AS DEPT_NM                                				\n");
        	sqlstr.append("				      , B.BID_STATUS_CD AS STATUS_CD                               				\n");
        	sqlstr.append("				FROM BID_MASTER A                                                                               \n");
        	sqlstr.append("				        , (SELECT BID_NO                                                                        \n");
        	sqlstr.append("				               , BID_DEG                                                                 		\n");
        	sqlstr.append("				               , VENDOR_CD                                                               		\n");
        	sqlstr.append("				               , BID_STATUS_CD                                                               		\n");
        	sqlstr.append("				           FROM BID_SUPP                                                                        \n");
        	sqlstr.append("				           WHERE SUCC_YN = 'Y'                                                                  \n");
        	sqlstr.append("				           ) B                                                                                  \n");
        	sqlstr.append("				        , TBE_INFO    C                                                                         \n");
        	sqlstr.append("				WHERE A.BID_NO = B.BID_NO                                                                       \n");
        	sqlstr.append("				AND      A.BID_DEG = B.BID_DEG                                                                  \n");
        	sqlstr.append("				AND A.STATUS_CD IN ('15','07','95', '20')                                                                       \n");
        	sqlstr.append("				 AND A.DEMANDED_KIND IN ('C','P','B')	                                                                \n");
        	sqlstr.append("				AND A.BID_NO = C.BID_NO(+)                                                                      \n");                                      
        	sqlstr.append("				AND A.BID_DEG = C.BID_DEG(+) 																	\n");

        	// 현장
        	if(!"".equals(params.get("P_DEPT_CD"))) {
        		sqlstr.append(" AND A.DEPT_CD = ?																												 \n");
        		search.addParameter(params.get("P_DEPT_CD"));
        	}
        	if(!param.get("P_BID_MASTER_NM").isEmpty())
        		sqlstr.append("   AND UPPER(A.BID_MASTER_NM) LIKE '%'|| '"+param.get("P_BID_MASTER_NM").toUpperCase()+"' ||'%'																	\n");
        	
        	if(!param.get("P_STATUS").isEmpty())
        		sqlstr.append("   AND B.BID_STATUS_CD = '"+param.get("P_STATUS")+"' 																	\n");
        	
        	
        	sqlstr.append("   ORDER BY OPEN_DT DESC 																																			\n");
			search.setStatement(sqlstr.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;
	}
	
}