/**
 * @(#)file    ContPopBiz.java
 * @(#)author  Kim Myung Ho
 * @(#)version 1.0
 * @(#)date    2014-08-11
 * @(#)since   JDK 1.4.2
 */
package kr.co.udapsoft.ebid.buyer.cont.outside.biz;


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

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.config.WAFConfig;
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.common.util.Crosscert;
import kr.co.udapsoft.common.util.PDFMaker;
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.common.ui.InitCombo;
import com.udapsoft.waf.common.util.StringUtils;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

   
public class ContPopBiz extends Biz {

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

	public void doBiz() throws Exception {
        ValueObject user = new ValueObject();
        //WAFLogger.debug("ContPopBiz :  ~" + storage.getUser());

		boolean success = false;
		
		if(storage.compareEvent("")){
			
		}else if(storage.compareEvent("SHEET_SELECT")){
			params.set("sheet1", getContList(params));
			
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
			
		}	
	}

	/**
	 * 계약 결과 리스트 조회
	 * @param Params
	 * @return
	 */
	private RowSet getContList(ValueObject param) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        
        StrBuffer sql = new StrBuffer();
        
        /**
    	 * 2018.11.26
    	 * 이인오
    	 * 사용안할예정 경영정보 디비링크 삭제
    	 * 
        try{
        	sql.append("    SELECT A.ESTDESC 											 GR_ESTDESC --집행그룹명			\n");
        	sql.append("         , B.PAYITEM || '-' || B.COSTCODE || '-' || B.COSTTYPE   PCODE   	--집행내역코드      		\n");
        	sql.append("         , B.PAYITEM                                                     	--집행내역 대분류  		\n");
        	sql.append("         , B.COSTCODE                                                    	--집행내역 중분류   		\n");
        	sql.append("         , B.COSTTYPE                                                    	--집행내역 소분류   		\n");
        	sql.append("         , B.ESTDESC                                                     	--집행내역명        		\n");
        	sql.append("         , B.ESTAMT                                                     	--실행예산       		\n");
        	sql.append("      FROM (SELECT DEPT_CD, PAYITEM, ESTDESC                                                    \n");
        	sql.append("              FROM COP020T!CCSIF                                                                      \n");
        	sql.append("             WHERE COSTTYPE = 'A'                                                               \n");
        	sql.append("               AND DEPT_CD  = ?) 	A                                                           \n");
        	sql.append("	      , COP020T!CCSIF 				B                                                           \n");
        	sql.append("     WHERE A.DEPT_CD  = B.DEPT_CD                                                               \n");
        	sql.append("       AND A.PAYITEM  = B.PAYITEM                                                               \n");
        	sql.append("       AND B.COSTTYPE = ?                                                                       \n");

            if( !params.get("estdesc").equals("") ) {
                if( params.get("p_condition").equals("0") ) {
                    sql.append(" AND      UPPER(B.ESTDESC) like UPPER('%" + params.get("estdesc") + "%') \n");            
                } else if (params.get("p_condition").equals("1")) {
                    sql.append(" AND      UPPER(B.PAYITEM) like UPPER('" + params.get("estdesc") + "%') \n");
                }
            }

            sql.append("  ORDER BY A.ESTDESC, B.PAYITEM, B.COSTCODE, B.COSTTYPE                                         \n");
            
            search.setStatement(sql.toString());
            WAFLogger.debug(sql.toString());
            
            String sSiteCd = StringUtils.nvl(params.get("site"));
        	if(sSiteCd.length() <= 0) sSiteCd = StringUtils.nvl(storage.getUser().get("site_code"));
            
        	search.addParameter(sSiteCd);
        	search.addParameter( params.get("costtype"));
            rowSet = search.execute();
            
        	
        }
        catch (WAFSQLException se) {
            super.doException(se);
            this.storage.setSuccess(false);  
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
            //WAFLogger.debug("### WAFSQLException : " + se.getMessage());
        }
        finally {    
            if(rowSet == null){
            	rowSet = new RowSetImpl();
            }
        }
        */
        return rowSet;
	}
}