/**
 * @(#)file    BidPlanSaveBiz.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.text.SimpleDateFormat;
import java.util.Date;

import javax.sql.RowSet;

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.persistent.Persistent;
import kr.co.hsnc.common.sql.persistent.PersistentImpl;
import kr.co.hsnc.common.util.ValueObject;

import com.udapsoft.modular.web.ibsheet7.IBSheet7Factory;
import com.udapsoft.modular.web.ibsheet7.util.IBSheet7Utils;
import com.udapsoft.waf.common.util.StringUtils;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

   
public class OfflineBidSaveBiz extends Biz {

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

	public void doBiz() throws Exception {
		boolean success = false;
		params.set("login_user", storage.getUser().get("ACCT_ID"));
        success = saveProc(storage.getEvent(), params);
        super.storage.setSuccess(success);
        storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
	}
	  /**
     * 사용자 정보 저장
	 * @param event
	 * @param valueObject
	 * @return
	 */
	public boolean saveProc(String event, ValueObject valueObject) {
        try {
            conn.begin();

            if( event.equals("UPDATE") || event.equals("MASTER_UPDATE") || event.equals("SET_CORP_DELETE")) {
            	params.get("BID_NO");
            	updMaster(conn.getConnection(), params);
                if("Y".equals(params.get("TBE_FLAG"))){
                	tbeinfosave(conn.getConnection(), params);
                }
                String[] status = super.gets("sheet1.STATUS");
                
                for (int i = 0; i < status.length; i++) {
					if (IBSheet7Utils.equalStatusInsert(status[i])) {
						saveData(super.conn.getConnection(), IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
					}
					
					if (IBSheet7Utils.equalStatusUpdate(status[i])) {
						updateData(super.conn.getConnection(), IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
					}
					
					if (IBSheet7Utils.equalStatusDelete(status[i])) {
						deleteData(super.conn.getConnection(), IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
					}
				}
                if("MASTER_UPDATE".equals(event)){
                    //상태값 업데이트 /*2014-12-08 오프라인 결재로 인한 주석*/
            		//update_BidMaster(conn.getConnection(), params);
                }
                //2015.11.11 오프라인 For PO발생시. 
                if (valueObject.get("FOR_PO_YN").equals("Y")){
                	System.out.println("적용 체크 ");
                	//입찰내역적용 INSERT (BID_ITEM), DELETE(BID_ITEM, BID_SUPP_ESTI) UPDATE( PMM_DEMANDED_REQUEST.EBID_STATUS_CD = '04')
                	Persistent persistent = new PersistentImpl(conn.getConnection());
                    StrBuffer sqlstr = new StrBuffer();
                    try {
                    	sqlstr.append("DELETE BID_SUPP_ESTI						    \n");
                    	sqlstr.append("WHERE BID_NO = ? 					    	\n");
                    	persistent.setStatement(sqlstr.toString());
                        persistent.addParameter(valueObject.get("BID_NO"));
                        persistent.execute();
                        
                        sqlstr.reset();
                        persistent.clear();
                        
                        sqlstr.append("UPDATE BID_SUPP  					        \n");
                        sqlstr.append("   SET ESTI_TOT_AMT = NULL  	 	    	    \n");
                        sqlstr.append("      ,WON_ESTI_TOT_AMT = NULL  				\n");
                        sqlstr.append("      ,SELECT_TOT_AMT = NULL 				\n");
                        sqlstr.append("      ,RNNC_REASON = NULL 					\n");
                        sqlstr.append("WHERE BID_NO = ? 					    	\n");
                    	persistent.setStatement(sqlstr.toString());
                        persistent.addParameter(valueObject.get("BID_NO"));
                        persistent.execute();
                        
                        sqlstr.reset();
                        persistent.clear();
                        
                    	sqlstr.append("DELETE BID_ITEM						        \n");
                    	sqlstr.append("WHERE BID_NO = ? 					    	\n");
                    	persistent.setStatement(sqlstr.toString());
                        persistent.addParameter(valueObject.get("BID_NO"));
                        persistent.execute();
                        
                        sqlstr.reset();
                        persistent.clear();
                        
                        sqlstr.append("INSERT INTO BID_ITEM (                                       \n");
                        sqlstr.append("                 BID_NO                                      \n");
                        sqlstr.append("                ,BID_DEG                                     \n");
                        sqlstr.append("                ,MATERIAL_CD                                 \n");
                        sqlstr.append("                ,REQUEST_DATE                                \n");
                        sqlstr.append("                ,CONT_UNIT_AMT                               \n");
                        sqlstr.append("                ,ACT_UNIT_AMT                                \n");
                        sqlstr.append("                ,DEMANDED_PRI                                \n");
                        sqlstr.append("                ,DEMANDED_QTY                                \n");
                        sqlstr.append("                ,STD  )                                      \n");
                        sqlstr.append("			SELECT ?                    					    \n");
                        sqlstr.append("                ,?                                           \n");
                        sqlstr.append("                ,A.MATERIAL_CD                               \n");
                        sqlstr.append("                ,A.REQUEST_DATE                              \n");
                        sqlstr.append("                ,A.CONT_PRI                                  \n");
                        sqlstr.append("                ,A.DEMANDED_PRI                              \n");
                        sqlstr.append("                ,DECODE(NVL(A.DEMANDED_AMT,0),0,0,A.DEMANDED_AMT/A.DEMANDED_QTY)	                              \n");
                        sqlstr.append("                ,A.DEMANDED_QTY                              \n");
                        sqlstr.append("                ,B.MATERIAL_SPEC                             \n");
                        sqlstr.append("  	      FROM PMM_DEMANDED_ITEM A                          \n");
                        sqlstr.append("  	          ,PMM_COMM_MATERIAL_MASTER B                   \n");
                        sqlstr.append("          WHERE A.MATERIAL_CD = B.MATERIAL_CD(+)             \n");
                        sqlstr.append("            AND A.DEMANDED_ID = ?                            \n");
                        sqlstr.append("			 UNION ALL                   					    \n");
                        sqlstr.append("			SELECT ?                    					    \n");
                        sqlstr.append("                ,?                                           \n");
                        sqlstr.append("                ,'ZZZZZZ999'                                 \n");
                        sqlstr.append("                ,TO_CHAR(A.REQUEST_DATE,'YYYYMMDD')          \n");
                        sqlstr.append("                ,0                                           \n");
                        sqlstr.append("                ,0                                           \n");
                        sqlstr.append("                ,0	                                        \n");
                        sqlstr.append("                ,1                                           \n");
                        sqlstr.append("                ,''                                          \n");
                        sqlstr.append("  	      FROM PMM_DEMANDED_REQUEST A                       \n");
                        sqlstr.append("          WHERE A.DEMANDED_ID = ?                            \n");
                        sqlstr.append("            AND A.DEMANDED_KIND = 'B'                        \n");
                        //2018.4.4 단가조정코드 추가
                        
                        persistent.setStatement(sqlstr.toString());
                        persistent.addParameter(valueObject.get("BID_NO"));
                        persistent.addParameter(valueObject.get("BID_DEG"));
                        persistent.addParameter(valueObject.get("FOR_PO"));  //DEMANDED_ID
                        persistent.addParameter(valueObject.get("BID_NO"));   //2018.4.4 단가조정코드 추가
                        persistent.addParameter(valueObject.get("BID_DEG"));
                        persistent.addParameter(valueObject.get("FOR_PO"));  
                        
                        persistent.execute();
                        
                        sqlstr.reset();
                        persistent.clear();
                        sqlstr.append(" UPDATE PMM_DEMANDED_REQUEST 									\n");
            			sqlstr.append("    SET EBID_STATUS_CD = '04'			  				        \n");
            			sqlstr.append("  WHERE DEMANDED_ID=?											\n");
            			persistent.setStatement(sqlstr.toString());
            			persistent.addParameter(valueObject.get("FOR_PO")); //DEMANDED_ID
                        persistent.execute();
                        
                    }
                    catch(Exception e) {
                        WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
                        WAFLogger.error("SQL : " + sqlstr);
                        WAFLogger.error(e);
                        conn.setRollback();

                        storage.setDetailMessage(e);
                        return false;
                    }
                }
                else{
                	System.out.println("적용 체크 안함 ");
                	//발주의뢰만 입찰적용으로 변경 UPDATE( PMM_DEMANDED_REQUEST.EBID_STATUS_CD = '04')
                	Persistent persistent = new PersistentImpl(conn.getConnection());
                    StrBuffer sqlstr = new StrBuffer();
                    try {
            			sqlstr.append(" UPDATE PMM_DEMANDED_REQUEST 									\n");
            			sqlstr.append("    SET EBID_STATUS_CD = '04'			  				        \n");
            			sqlstr.append("  WHERE DEMANDED_ID=?											\n");
            			persistent.setStatement(sqlstr.toString());
            			persistent.addParameter(valueObject.get("FOR_PO")); //DEMANDED_ID
                        persistent.execute();
                        System.out.println("적용 안함:  " + valueObject.get("FOR_PO"));
                    }catch(Exception e) {
                        WAFLogger.error(this.getClass().getName() + " --> updMaster() : " + e.getMessage());
                        WAFLogger.error("SQL : " + sqlstr);
                        WAFLogger.error(e);
                        conn.setRollback();

                        storage.setDetailMessage(e);
                        return false;
                    }
                }
                
            }else if ( event.equals("FORM_DELETE") ){
            	//첨부파일 삭제
            	PUB0500T_del(conn.getConnection(), params);
            	//첨부파일 맵 삭제
            	PUB0510T_del(conn.getConnection(), params);
            	//견적대상업체 삭제
            	BID_SUPP_del(conn.getConnection(), params);
            	//기술검토 삭제
            	TBE_INFO_del(conn.getConnection(), params);
            	//입찰 내역 삭제
            	BID_ITEM_del(conn.getConnection(), params);
            	//마스터 삭제
            	BID_MASTER_del(conn.getConnection(), params);
            	//보고자 삭제
            	BID_OPEN_REPORT_del(conn.getConnection(), params);
            	//
            	PMM_DEMANDED_REQUEST_update(conn.getConnection());
        	}
            if( event.equals("SAVE")){
            	String[] status = super.gets("sheet1.STATUS");
            	for (int i = 0; i < status.length; i++) {
					if (IBSheet7Utils.equalStatusUpdate(status[i])) {
						bid_supp_esti_update(super.conn.getConnection(), IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
					}
				}
            	bid_pur_condi_insert(super.conn.getConnection(),params);
            	bid_supp_update(super.conn.getConnection(),params);
            	bid_master_update(super.conn.getConnection(),params);	//2023.10.25	Delivery Condition 업데이트
            }
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> saveProc() : " + e.getMessage());
            WAFLogger.error(e);
            conn.setRollback();

            storage.setDetailMessage(e);
            return false;
        }
        finally {
        	
            conn.end();
        }
    }

	/**
     * 사용자 수정
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void updMaster(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
			sqlstr.append(" UPDATE BID_MASTER 									\n");
			sqlstr.append("      SET BID_MASTER_NM=?					--		\n");
			sqlstr.append("      , CMPT_CD=?						--					\n");
			sqlstr.append("      , SUCC_CD=?						--					\n");
			sqlstr.append("      , NOTI_DY=?											\n");
			sqlstr.append("      , CONT_AMT=?										\n");
			sqlstr.append("      , ACT_AMT=?										\n");
			sqlstr.append("      , PUR_AMT=?                                        \n");  //구매예산추가 2015.3.2 mklee
			sqlstr.append("      , SITEDESC_FLAG=?			--					\n");
			sqlstr.append("      , SITEDESCCHRGPRSNID=?		--				\n");
			sqlstr.append("      , SITEDESC_CRG_NM=?		--					\n");
			sqlstr.append("      , SITEDESCTELNO=?		--						\n");
			sqlstr.append("      , SITEDESCEMAIL=?		--						\n");
			sqlstr.append("      , SITEDESCDATE=TO_DATE(?||?||?,'YYYYMMDDHH24MI')			--								\n");
			sqlstr.append("      , SITEDESCPLACE=?								\n");
			sqlstr.append("      , BID_FROM_DT=TO_DATE(?||?||?,'YYYYMMDDHH24MI')		--									\n");
			sqlstr.append("      , BID_TO_DT=TO_DATE(?||?||?,'YYYYMMDDHH24MI')												\n");
			sqlstr.append("      , PUREMPNO=?										\n");
			sqlstr.append("      , PO_EMPNM=?										\n");
			sqlstr.append("      , OPEN_EMPNM=?									\n");
			sqlstr.append("      , OPEN_EMPID=?									\n");
			sqlstr.append("      , OPEN_DT=SYSDATE								\n");
			sqlstr.append("      , TBE_FLAG=?										\n");
			sqlstr.append("      , CURRENCY_GB=?									\n");
			sqlstr.append("      , CURRENCY_GB_YN=?								\n");
			sqlstr.append("      , DELI_FROM_DY=?									\n");
			sqlstr.append("      , DELI_TO_DY=?										\n");
			sqlstr.append("      , CONTFUL_RATE=?									\n");
			sqlstr.append("      , CONTFUL_CONDI=?								\n");
			sqlstr.append("      , WARR_RATE=?										\n");
			sqlstr.append("      , WARR_CONDI=?									\n");
			sqlstr.append("      , INNER_REMARKS=?								\n");
			sqlstr.append("      , OUTER_REMARKS=?								\n");
			sqlstr.append("      , BID_APP_DATE=?									\n");
			sqlstr.append("      , BID_APP_NO=?										\n");
			sqlstr.append("      , STATUS_CD=?										\n");
			sqlstr.append("      , ACT_RATE=?										\n");
			sqlstr.append("       , PBC_DEFECT_CONDI=?							\n");
	        sqlstr.append("       , CBC_DERECT_TERM_CD=?						\n");
	        sqlstr.append("       , CBC_DEFECT_DAY=?							\n");
		    sqlstr.append("       , PBC_DEFECT_CONDI2=?							\n");
		    sqlstr.append("       , CBC_DERECT_TERM_CD2=?						\n");
		    sqlstr.append("       , CBC_DEFECT_DAY2=?								\n");
	        sqlstr.append("       , PBC_FRSTGUAR_RATE=?						\n");
	        sqlstr.append("       , PBC_FRSTGUAR_CONDI=?						\n");
	        sqlstr.append("       , PBC_REST_RATE=?								\n");
	        sqlstr.append("       , PBC_REST_CONDI=?								\n");
	        sqlstr.append("       , CPC_MID_RATE=?								\n");
	        sqlstr.append("       , PBC_MID_CONDI=?								\n");
	        sqlstr.append("       , CBC_FIRST_RATE=?								\n");
	        sqlstr.append("       , PBC_FIRST_CONDI=?							\n");
	        sqlstr.append("       , CBC_DAMAGE_RATE=?							\n");
	        sqlstr.append("       , CBC_DAMAGE_MAXRATE=?					\n");
	        sqlstr.append("       , PBC_OPTION_COMMENT=?					\n");
	        sqlstr.append("       , PBC_OPTION_YN=?								\n");
	        sqlstr.append("       , PBC_FEE_YN=?									\n");
	        sqlstr.append("       , DELIVERY_CONDITION=?						\n");
	        sqlstr.append("       , DELIVERY_CONDITION_YN=?					\n");
	        sqlstr.append("       , PBC_LANDTRAN_YN=?							\n");
	        sqlstr.append("       , PBC_PACK_YN=?									\n");
	        sqlstr.append("       , PBC_DOC_YN=?									\n");
	        sqlstr.append("       , PBC_TEST_YN=?									\n");
	        sqlstr.append("       , PBC_SPETOOL_YN=?							\n");
	        sqlstr.append("       , PBC_COMMISS_YN=?							\n");
	        sqlstr.append("       , PBC_INSTALL_YN=?								\n");
	        sqlstr.append("       , PBC_CBE_TYPE_CD=?							\n");
	        sqlstr.append("       , DIV_PO_YN=?										\n");
	        sqlstr.append("       , CBC_DAMAGE_CD=?										\n"); //2016.6.8추가 
			sqlstr.append("       , UPD_BY=?											\n");
			sqlstr.append("       , UPD_DATE=SYSDATE 									\n");
			sqlstr.append("       , MAIN_PR_CONTENTS=?									\n");
			sqlstr.append("       , BID_SUPP_SELECT_REASON=?							\n");		
		    sqlstr.append("	      , CONT_APP_REQ_DATE=? 								\n");	
			sqlstr.append("  WHERE BID_NO = ?											\n");
			sqlstr.append("  AND BID_DEG = ?											\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_MASTER_NM"));
            persistent.addParameter(valueObject.get("CMPT_CD"));
            persistent.addParameter(valueObject.get("SUCC_CD"));
            persistent.addParameter(StringUtils.replace(valueObject.get("NOTI_DY"),"-",""));
            persistent.addParameter(StringUtils.replace(valueObject.get("CONT_AMT"),",",""));
            persistent.addParameter(StringUtils.replace(valueObject.get("ACT_AMT"),",",""));
            persistent.addParameter(StringUtils.replace(valueObject.get("PUR_AMT"),",","")); //구매예산추가 2015.3.2 mklee
            persistent.addParameter(valueObject.get("SITEDESC_FLAG"));
            persistent.addParameter(valueObject.get("SITEDESCCHRGPRSNID"));
            persistent.addParameter(valueObject.get("SITEDESC_CRG_NM"));
            persistent.addParameter(valueObject.get("SITEDESCTELNO"));
            persistent.addParameter(valueObject.get("SITEDESCEMAIL"));
            persistent.addParameter(StringUtils.replace(valueObject.get("SITEDESCDATE"),"-",""));
            persistent.addParameter(valueObject.get("SITEDESCDATE_HH"));
            persistent.addParameter(valueObject.get("SITEDESCDATE_MI"));
            persistent.addParameter(valueObject.get("SITEDESCPLACE"));
            persistent.addParameter(StringUtils.replace(valueObject.get("BID_FROM_DT"),"-",""));
            persistent.addParameter(valueObject.get("BID_FROM_HH"));
            persistent.addParameter(valueObject.get("BID_FROM_MI"));
            persistent.addParameter(StringUtils.replace(valueObject.get("BID_TO_DT"),"-",""));
            persistent.addParameter(valueObject.get("BID_TO_HH"));
            persistent.addParameter(valueObject.get("BID_TO_MI"));
            persistent.addParameter(valueObject.get("PUREMPNO"));
            persistent.addParameter(valueObject.get("PO_EMPNM"));
            persistent.addParameter(valueObject.get("OPEN_EMPNM"));
            persistent.addParameter(valueObject.get("OPEN_EMPID"));
            persistent.addParameter(valueObject.get("TBE_FLAG"));
            persistent.addParameter(valueObject.get("CURRENCY_GB"));
            persistent.addParameter(valueObject.get("CURRENCY_GB_YN"));
            persistent.addParameter(StringUtils.replace(valueObject.get("DELI_FROM_DY"),"-",""));
            persistent.addParameter(StringUtils.replace(valueObject.get("DELI_TO_DY"),"-",""));
            persistent.addParameter(valueObject.get("CONTFUL_RATE"));
            persistent.addParameter(valueObject.get("CONTFUL_CONDI"));
            persistent.addParameter(valueObject.get("WARR_RATE"));
            persistent.addParameter(valueObject.get("WARR_CONDI"));
            persistent.addParameter(valueObject.get("INNER_REMARKS"));
            persistent.addParameter(valueObject.get("OUTER_REMARKS"));
            persistent.addParameter(valueObject.get("BID_APP_DATE"));
            persistent.addParameter(valueObject.get("BID_APP_NO"));
            persistent.addParameter(valueObject.get("STATUS_CD"));
            persistent.addParameter(valueObject.get("ACT_RATE"));
	        persistent.addParameter(valueObject.get("PBC_DEFECT_CONDI"));
	        persistent.addParameter(valueObject.get("CBC_DERECT_TERM_CD"));
	        persistent.addParameter(valueObject.get("CBC_DEFECT_DAY"));
	        persistent.addParameter(valueObject.get("PBC_DEFECT_CONDI2"));
	        persistent.addParameter(valueObject.get("CBC_DERECT_TERM_CD2"));
	        persistent.addParameter(valueObject.get("CBC_DEFECT_DAY2"));
	        persistent.addParameter(valueObject.get("PBC_FRSTGUAR_RATE"));
	        persistent.addParameter(valueObject.get("PBC_FRSTGUAR_CONDI"));
	        persistent.addParameter(valueObject.get("PBC_REST_RATE"));
	        persistent.addParameter(valueObject.get("PBC_REST_CONDI"));
	        persistent.addParameter(valueObject.get("CPC_MID_RATE"));
	        persistent.addParameter(valueObject.get("PBC_MID_CONDI"));
	        persistent.addParameter(valueObject.get("CBC_FIRST_RATE"));
	        persistent.addParameter(valueObject.get("PBC_FIRST_CONDI"));
	        persistent.addParameter(valueObject.get("CBC_DAMAGE_RATE"));
	        persistent.addParameter(valueObject.get("CBC_DAMAGE_MAXRATE"));
	        persistent.addParameter(valueObject.get("PBC_OPTION_COMMENT"));
	        persistent.addParameter(valueObject.get("PBC_OPTION_YN"));
	        persistent.addParameter(valueObject.get("PBC_FEE_YN"));
	        persistent.addParameter(valueObject.get("DELIVERY_CONDITION"));
	        persistent.addParameter(valueObject.get("DELIVERY_CONDITION_YN"));
	        persistent.addParameter(valueObject.get("PBC_LANDTRAN_YN"));
	        persistent.addParameter(valueObject.get("PBC_PACK_YN"));
	        persistent.addParameter(valueObject.get("PBC_DOC_YN"));
	        persistent.addParameter(valueObject.get("PBC_TEST_YN"));
	        persistent.addParameter(valueObject.get("PBC_SPETOOL_YN"));
	        persistent.addParameter(valueObject.get("PBC_COMMISS_YN"));
	        persistent.addParameter(valueObject.get("PBC_INSTALL_YN"));
	        persistent.addParameter(valueObject.get("PBC_CBE_TYPE_CD"));
	        persistent.addParameter(valueObject.get("DIV_PO_YN"));
	        persistent.addParameter(valueObject.get("CBC_DAMAGE_CD"));  //2016.6.8추가 
            persistent.addParameter(valueObject.get("login_user"));
            persistent.addParameter(valueObject.get("MAIN_PR_CONTENTS"));
            persistent.addParameter(valueObject.get("BID_SUPP_SELECT_REASON"));
            persistent.addParameter(StringUtils.replace(valueObject.get("CONT_APP_REQ_DATE"),"-",""));
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updMaster() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 사용자 수정
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void tbeinfosave(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("MERGE INTO TBE_INFO TI USING (									\n");
        	sqlstr.append("		        SELECT ? AS BID_NO										\n");
        	sqlstr.append("                ,? AS EVAL_EMPNM										\n");
        	sqlstr.append("                ,? AS BID_DEG												\n");
        	sqlstr.append("            	,TO_DATE(?,'YYYYMMDDHH24MISS') AS SUPP_REQ_DY										\n");
        	sqlstr.append("            	,? AS STATUS_CD											\n");
        	sqlstr.append("            	,? AS EVAL_EMPID										\n");
        	sqlstr.append("             	,? AS EVAL_TEL											\n");
        	sqlstr.append("            	,? AS EVAL_EMAIL										\n");
        	sqlstr.append("		        FROM DUAL													\n");
        	sqlstr.append("		    ) T ON (T.BID_NO = TI.BID_NO AND T.BID_DEG = TI.BID_DEG)	\n");
        	sqlstr.append("		WHEN MATCHED THEN													\n");
        	sqlstr.append("		    UPDATE SET TI.EVAL_EMPNM = T.EVAL_EMPNM								\n");
        	sqlstr.append("            ,TI.SUPP_REQ_DY = T.SUPP_REQ_DY							\n");
        	sqlstr.append("            ,TI.EVAL_EMPID = T.EVAL_EMPID								\n");
        	sqlstr.append("            ,TI.EVAL_TEL = T.EVAL_TEL										\n");
        	sqlstr.append("            ,TI.EVAL_EMAIL = T.EVAL_EMAIL									\n");
        	sqlstr.append("		WHEN NOT MATCHED THEN											\n");
        	sqlstr.append("			INSERT (TI.BID_NO,TI.BID_DEG,TI.EVAL_EMPNM,TI.SUPP_REQ_DY,TI.STATUS_CD,TI.EVAL_EMPID,TI.EVAL_TEL,TI.EVAL_EMAIL)									\n");
        	sqlstr.append("			VALUES (T.BID_NO,T.BID_DEG,T.EVAL_EMPNM,T.SUPP_REQ_DY,T.STATUS_CD,T.EVAL_EMPID,T.EVAL_TEL,T.EVAL_EMAIL)											\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("EVAL_EMPNM"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.addParameter(StringUtils.replace(valueObject.get("SUPP_REQ_DY"),"-",""));
            persistent.addParameter("01");
            persistent.addParameter(valueObject.get("EVAL_EMPID"));
            persistent.addParameter(valueObject.get("EVAL_TEL"));
            persistent.addParameter(valueObject.get("EVAL_EMAIL"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 파일 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void PUB0500T_del(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE PUB0500T						\n");
        	sqlstr.append("WHERE FILE_ID IN (SELECT FILE_ID FROM PUB0510T 						\n");
        	sqlstr.append("WHERE O_FILE_GB IN (?,?)						\n");
        	sqlstr.append("AND O_ID = ?)						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("DOC_ETC_IN"));
            persistent.addParameter(valueObject.get("DOC_ETC_OUT"));
            persistent.addParameter(valueObject.get("DEMANDED_ID"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 파일 맵 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void PUB0510T_del(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE PUB0510T 						\n");
        	sqlstr.append("WHERE O_FILE_GB IN (?,?)						\n");
        	sqlstr.append("AND O_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("DOC_ETC_IN"));
            persistent.addParameter(valueObject.get("DOC_ETC_OUT"));
            persistent.addParameter(valueObject.get("DEMANDED_ID"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 기술 검토 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void BID_SUPP_del(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE TBE_INFO						\n");
        	sqlstr.append("WHERE BID_NO = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 입찰업체 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void TBE_INFO_del(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE BID_SUPP						\n");
        	sqlstr.append("WHERE BID_NO = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 입찰 내역 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void BID_ITEM_del(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE BID_ITEM						\n");
        	sqlstr.append("WHERE BID_NO = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));

            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	
	/**
     * 입찰 마스터 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void BID_MASTER_del(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE  BID_MASTER						\n");
        	sqlstr.append("WHERE BID_NO = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 경적대상업체 저장
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void saveData(Connection connection, ValueObject valueObject) throws Exception {
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        String SITEPARTI_YN = "N";
        try {
        	sqlstr.append(" INSERT										\n");
        	sqlstr.append("   INTO BID_SUPP							\n");
        	sqlstr.append("        (										\n");
        	sqlstr.append("            BID_NO							\n");
        	sqlstr.append("          ,BID_DEG							\n");
        	sqlstr.append("          ,VENDOR_CD						\n");
        	sqlstr.append("          ,VENDOR_NO						\n");
        	sqlstr.append("          ,VENDOR_NAME					\n");
        	sqlstr.append("          ,REPRE_NO						\n");
        	sqlstr.append("          ,CHARGE_NAME					\n");
        	sqlstr.append("          ,CHAGE_HP						\n");
        	sqlstr.append("          ,CHARGE_EMAIL					\n");
        	sqlstr.append("          ,RECOMMEND_REASON			\n");
        	sqlstr.append("          ,RECM_DEPT_ID					\n");
        	sqlstr.append("          ,RECM_DEPT_NM				\n");
        	sqlstr.append("          ,SITEPARTI_YN					\n");
			sqlstr.append("          ,SITE_ATTEND_YN				\n");
			sqlstr.append("          ,FILE_GB							\n");
        	sqlstr.append("          ,CRE_BY							\n");
        	sqlstr.append("          ,CRE_DATE						\n");
        	sqlstr.append("        )										\n");
        	sqlstr.append("        VALUES								\n");
        	sqlstr.append("        ( ?										\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,?									\n");
        	sqlstr.append("          ,SYSDATE							\n");
        	sqlstr.append("        )										\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("BID_NO"));
            persistent.addParameter(params.get("BID_DEG"));
            persistent.addParameter(valueObject.get("VENDOR_CD"));
            persistent.addParameter(valueObject.get("VENDOR_NO"));
            persistent.addParameter(valueObject.get("VENDOR_NAME"));
            persistent.addParameter(valueObject.get("REPRE_NO"));
            persistent.addParameter(valueObject.get("CHARGE_NAME"));
            persistent.addParameter(valueObject.get("CHAGE_HP"));
            persistent.addParameter(valueObject.get("CHARGE_EMAIL"));
            persistent.addParameter(valueObject.get("RECOMMEND_REASON"));
            persistent.addParameter(valueObject.get("RECM_DEPT_ID"));
            persistent.addParameter(valueObject.get("RECM_DEPT_NM"));
            /*오프라인 일경우 현설 참여로 업데이트*/
        	if("N".equals(params.get("ONBID_YN")) || "오프라인".equals(params.get("ONBID_YN")))SITEPARTI_YN ="Y";
        	persistent.addParameter(SITEPARTI_YN);
        	persistent.addParameter(SITEPARTI_YN);
        	SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            Date now = new Date();
	        String FileGB = "INQ_"+valueObject.get("VENDOR_CD")+format.format(now)+"OFF";
	        persistent.addParameter(FileGB);
            persistent.addParameter(storage.getUser().get("ACCT_ID"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 경적대상업체 저장
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void updateData(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        String SITEPARTI_YN = "N";
        try {
        	sqlstr.append("UPDATE BID_SUPP								\n");
        	sqlstr.append("       SET VENDOR_NO=?						\n");
        	sqlstr.append("     , VENDOR_NAME=?							\n");
        	sqlstr.append("     , REPRE_NO=?									\n");
        	sqlstr.append("     , CHARGE_NAME=?							\n");
        	sqlstr.append("     , CHAGE_HP=?								\n");
        	sqlstr.append("     , CHARGE_EMAIL=?							\n");
        	sqlstr.append("     , RECOMMEND_REASON=?					\n");
        	sqlstr.append("     , RECM_DEPT_ID=?							\n");
        	sqlstr.append("     , RECM_DEPT_NM=?							\n");
        	sqlstr.append("     , SITEPARTI_YN=?							\n");
        	sqlstr.append("     , SITE_ATTEND_YN=?							\n");
        	sqlstr.append("     , FILE_GB = ?									\n");
        	sqlstr.append("     , UPD_BY=?									\n");
        	sqlstr.append("     , UPD_DATE=SYSDATE						\n");
        	sqlstr.append(" WHERE BID_NO = ?								\n");
        	sqlstr.append(" AND BID_DEG = ?									\n");
        	sqlstr.append(" AND VENDOR_CD = ?							\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("VENDOR_NO"));
            persistent.addParameter(valueObject.get("VENDOR_NAME"));
            persistent.addParameter(valueObject.get("REPRE_NO"));
            persistent.addParameter(valueObject.get("CHARGE_NAME"));
            persistent.addParameter(valueObject.get("CHAGE_HP"));
            persistent.addParameter(valueObject.get("CHARGE_EMAIL"));
            persistent.addParameter(valueObject.get("RECOMMEND_REASON"));
            persistent.addParameter(valueObject.get("RECM_DEPT_ID"));
            persistent.addParameter(valueObject.get("RECM_DEPT_NM"));
            /*오프라인 일경우 현설 참여로 업데이트*/
        	if("N".equals(params.get("ONBID_YN")) || "오프라인".equals(params.get("ONBID_YN")))SITEPARTI_YN ="Y";
        	persistent.addParameter(SITEPARTI_YN);
        	persistent.addParameter(SITEPARTI_YN);
        	
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            Date now = new Date();
	        String FileGB = "INQ_"+valueObject.get("VENDOR_CD")+format.format(now)+"OFF";
	        persistent.addParameter(FileGB);
	        
            persistent.addParameter(storage.getUser().get("ACCT_ID"));
            persistent.addParameter(params.get("BID_NO"));
            persistent.addParameter(params.get("BID_DEG"));
            persistent.addParameter(valueObject.get("VENDOR_CD"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }

	
	/**
     * 경적대상업체 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void deleteData(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	
            //2017.03.30수정. 업체삭제시 연관 테이블 모두 삭제 
            sqlstr.append("DELETE FROM BID_SUPP_ESTI				\n");
        	sqlstr.append(" WHERE  BID_NO = ?						\n");
        	sqlstr.append(" AND BID_DEG = ?							\n");
        	sqlstr.append(" AND VENDOR_CD = ?					\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.addParameter(valueObject.get("VENDOR_CD"));
            persistent.execute();
            
            sqlstr.reset();
            persistent.clear();
            sqlstr.append("DELETE FROM BID_PUR_CONDI				\n");
        	sqlstr.append(" WHERE  BID_NO = ?						\n");
        	sqlstr.append(" AND BID_DEG = ?							\n");
        	sqlstr.append(" AND VENDOR_CD = ?					\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.addParameter(valueObject.get("VENDOR_CD"));
            persistent.execute();
            
            sqlstr.reset();
            persistent.clear();
            sqlstr.append("DELETE FROM BID_PUR_ORDER				\n");
        	sqlstr.append(" WHERE  BID_NO = ?						\n");
        	sqlstr.append(" AND BID_DEG = ?							\n");
        	sqlstr.append(" AND VENDOR_CD = ?					\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.addParameter(valueObject.get("VENDOR_CD"));
            persistent.execute();
            sqlstr.reset();
            persistent.clear();
            //-----------------------------------2017.03.30 
            
            sqlstr.append("DELETE FROM BID_SUPP				\n");
        	sqlstr.append(" WHERE  BID_NO = ?						\n");
        	sqlstr.append(" AND BID_DEG = ?							\n");
        	sqlstr.append(" AND VENDOR_CD = ?					\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.addParameter(valueObject.get("VENDOR_CD"));
            persistent.execute();
            
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 결제 상태 업데이트
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void update_BidMaster(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("UPDATE BID_MASTER					\n");
        	sqlstr.append(" SET STATUS_CD = ?					\n");
        	sqlstr.append(" ,UPD_BY=?							\n");
        	sqlstr.append(" ,UPD_DATE = SYSDATE					\n");
        	sqlstr.append(" WHERE BID_NO = ?					\n");
        	sqlstr.append(" AND BID_DEG = ?						\n");
        	
            persistent.setStatement(sqlstr.toString());
           	persistent.addParameter("06");
            persistent.addParameter(storage.getUser().get("ACCT_ID"));
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	
	/**
	 * 발주의뢰 접수
	 * @return
	 */
	private void PMM_DEMANDED_REQUEST_update(Connection connection) throws Exception{
		StrBuffer sqlstr = new StrBuffer();
		Persistent pstmt = new PersistentImpl(connection);
        try{
			pstmt.clear();
			sqlstr = new StrBuffer();
			sqlstr.append("     UPDATE PMM_DEMANDED_REQUEST			                \n");
			sqlstr.append("       SET DEMANDED_STATUS = '3'					        \n");				
			sqlstr.append("            ,ONBID_YN = ''								\n");
			sqlstr.append("            ,RECEIPT_DATE = ''							\n");
			sqlstr.append("            ,RECEIPT_NO = ''								\n");
			sqlstr.append("            ,UPD_BY = ?									\n");
			sqlstr.append("            ,UPD_DATE = SYSDATE 						    \n");
			sqlstr.append("            WHERE DEMANDED_ID = ?					    \n");
        	pstmt.setStatement(sqlstr.toString());
			pstmt.addParameter(storage.getUser().get("acct_id"));
			pstmt.addParameter(params.get("DEMANDED_ID"));
			pstmt.execute();
        }catch (Exception e){
			WAFLogger.error(e);
			throw new Exception(e);
        }
	}
	
	/**
     * 견적 조건 저장
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_pur_condi_insert(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("MERGE INTO BID_PUR_CONDI PUR USING  	\n");
        	sqlstr.append("    (SELECT ? AS BID_NO 	\n");
        	sqlstr.append("         , ?  AS BID_DEG 	\n");
        	sqlstr.append("         , ?  AS VENDOR_CD 	\n");
        	sqlstr.append("         , ?  AS CURRENCY_GB_YN 	\n");
        	sqlstr.append("         , ?  AS CURRENCY_GB 	\n");
        	sqlstr.append("         , ?  AS INSTALL_YN 	\n");
        	sqlstr.append("         , ?  AS COMMISS_YN 	\n");
        	sqlstr.append("         , ?  AS SPETOOL_YN 	\n");
        	sqlstr.append("         , ?  AS TEST_YN 	\n");
        	sqlstr.append("         , ?  AS DOC_YN 	\n");
        	sqlstr.append("         , ?  AS PACK_YN 	\n");
        	sqlstr.append("         , ?  AS LANDTRAN_YN 	\n");
        	sqlstr.append("         , ?  AS DELIVERY_CONDITION_YN	\n"); 
        	sqlstr.append("         , ?  AS DELIVERY_CONDITION 	\n");
        	sqlstr.append("         , ?  AS FEE_NOTI 	\n");
        	sqlstr.append("         , ?  AS OPTION_NOTI 	\n");
        	sqlstr.append("         , ?  AS QUOT_NO 	\n");
        	sqlstr.append("         , ?  AS PAYCONDI_YN 	\n");
        	sqlstr.append("         , ?  AS PAYCONDI_NOT_NOTI 	\n");
        	sqlstr.append("         , ?  AS CONTFUL_YN 	\n");
        	sqlstr.append("         , ?  AS CONTFUL_NOT_NOTI	\n");
        	sqlstr.append("         , ?  AS FRSTGUAR_YN	\n");
        	sqlstr.append("         , ?  AS FRSTGUAR_NOT_NOTI	\n");
        	sqlstr.append("         , ?  AS WARR_YN	\n");
        	sqlstr.append("         , ?  AS WARR_NOT_NOTI	\n");
        	sqlstr.append("         , ?  AS DEFECT_YN	\n");
        	sqlstr.append("         , ?  AS DEFECT_NOT_NOTI	\n");
        	sqlstr.append("         , ?  AS BID_CONDI_NOTI	\n");
        	sqlstr.append("         , ?  AS CBC_FIRST_RATE	\n");
        	sqlstr.append("         , ?  AS PBC_FIRST_CONDI	\n");
        	sqlstr.append("         , ?  AS CPC_MID_RATE	\n");
        	sqlstr.append("         , ?  AS PBC_MID_CONDI	\n");
        	sqlstr.append("         , ?  AS PBC_REST_RATE	\n");
        	sqlstr.append("         , ?  AS PBC_REST_CONDI	\n");
        	sqlstr.append("         FROM DUAL) T ON (PUR.BID_NO = T.BID_NO AND PUR.BID_DEG = T.BID_DEG AND PUR.VENDOR_CD = T.VENDOR_CD)	\n");
        	sqlstr.append("         WHEN MATCHED THEN	\n");
        	sqlstr.append("         UPDATE SET CURRENCY_GB=T.CURRENCY_GB	\n");
        	sqlstr.append("         , PUR.INSTALL_YN=T.INSTALL_YN	\n");
        	sqlstr.append("         , PUR.COMMISS_YN=T.COMMISS_YN	\n");
        	sqlstr.append("         , PUR.SPETOOL_YN=T.SPETOOL_YN	\n");
        	sqlstr.append("         , PUR.TEST_YN=T.TEST_YN	\n");
        	sqlstr.append("         , PUR.DOC_YN=T.DOC_YN	\n");
        	sqlstr.append("         , PUR.PACK_YN=T.PACK_YN	\n");
        	sqlstr.append("         , PUR.LANDTRAN_YN=T.LANDTRAN_YN	\n");
        	sqlstr.append("         , PUR.DELIVERY_CONDITION=T.DELIVERY_CONDITION	\n");
        	sqlstr.append("         , PUR.FEE_NOTI=T.FEE_NOTI	\n");
        	sqlstr.append("         , PUR.OPTION_NOTI=T.OPTION_NOTI	\n");
        	sqlstr.append("         , PUR.QUOT_NO=T.QUOT_NO	\n");
        	sqlstr.append("         , PUR.PAYCONDI_YN=T.PAYCONDI_YN	\n");
        	sqlstr.append("         , PUR.PAYCONDI_NOT_NOTI=T.PAYCONDI_NOT_NOTI	\n");
        	sqlstr.append("         , PUR.CONTFUL_YN=T.CONTFUL_YN	\n");
        	sqlstr.append("         , PUR.CONTFUL_NOT_NOTI=T.CONTFUL_NOT_NOTI	\n");
        	sqlstr.append("         , PUR.FRSTGUAR_YN=T.FRSTGUAR_YN	\n");
        	sqlstr.append("         , PUR.FRSTGUAR_NOT_NOTI=T.FRSTGUAR_NOT_NOTI	\n");
        	sqlstr.append("         , PUR.WARR_YN=T.WARR_YN	\n");
        	sqlstr.append("         , PUR.WARR_NOT_NOTI=T.WARR_NOT_NOTI	\n");
        	sqlstr.append("         , PUR.DEFECT_YN=T.DEFECT_YN	\n");
        	sqlstr.append("         , PUR.DEFECT_NOT_NOTI=T.DEFECT_NOT_NOTI	\n");
        	sqlstr.append("         , PUR.BID_CONDI_NOTI=T.BID_CONDI_NOTI	\n");
        	sqlstr.append("         , CBC_FIRST_RATE = T.CBC_FIRST_RATE	\n");
        	sqlstr.append("         , PBC_FIRST_CONDI = T.PBC_FIRST_CONDI	\n");
        	sqlstr.append("         , CPC_MID_RATE = T.CPC_MID_RATE	\n");
        	sqlstr.append("         , PBC_MID_CONDI = T.PBC_MID_CONDI	\n");
        	sqlstr.append("         , PBC_REST_RATE = T.PBC_REST_RATE	\n");
        	sqlstr.append("         , PBC_REST_CONDI = T.PBC_REST_CONDI	\n");
        	sqlstr.append("         WHEN NOT MATCHED THEN		\n");
        	sqlstr.append("         INSERT (  PUR.BID_NO	\n");
        	sqlstr.append("         ,PUR.BID_DEG	\n");
        	sqlstr.append("         ,PUR.VENDOR_CD	\n");
        	sqlstr.append("         ,PUR.CURRENCY_GB_YN	\n");
        	sqlstr.append("         ,PUR.CURRENCY_GB	\n");
        	sqlstr.append("         ,PUR.INSTALL_YN	\n");
        	sqlstr.append("         ,PUR.COMMISS_YN	\n");
        	sqlstr.append("         ,PUR.SPETOOL_YN	\n");
        	sqlstr.append("         ,PUR.TEST_YN	\n");
        	sqlstr.append("         ,PUR.DOC_YN	\n");
        	sqlstr.append("         ,PUR.PACK_YN	\n");
        	sqlstr.append("         ,PUR.LANDTRAN_YN	\n");
        	sqlstr.append("         ,PUR.DELIVERY_CONDITION_YN	\n");
        	sqlstr.append("         ,PUR.DELIVERY_CONDITION	\n");
        	sqlstr.append("         ,PUR.FEE_NOTI	\n");
        	sqlstr.append("         ,PUR.OPTION_NOTI	\n");
        	sqlstr.append("         ,PUR.QUOT_NO	\n");
        	sqlstr.append("         ,PUR.PAYCONDI_YN	\n");
        	sqlstr.append("         ,PUR.PAYCONDI_NOT_NOTI	\n");
        	sqlstr.append("         ,PUR.CONTFUL_YN	\n");
        	sqlstr.append("         ,PUR.CONTFUL_NOT_NOTI	\n");
        	sqlstr.append("         ,PUR.FRSTGUAR_YN	\n");
        	sqlstr.append("         ,PUR.FRSTGUAR_NOT_NOTI	\n");
        	sqlstr.append("         ,PUR.WARR_YN	\n");
        	sqlstr.append("         ,PUR.WARR_NOT_NOTI	\n");
        	sqlstr.append("         ,PUR.DEFECT_YN	\n");
        	sqlstr.append("         ,PUR.DEFECT_NOT_NOTI	\n");
        	sqlstr.append("         ,PUR.BID_CONDI_NOTI 	\n");
        	sqlstr.append("         ,CBC_FIRST_RATE	\n");
        	sqlstr.append("         ,PBC_FIRST_CONDI	\n");
        	sqlstr.append("         ,CPC_MID_RATE	\n");
        	sqlstr.append("         ,PBC_MID_CONDI	\n");
        	sqlstr.append("         ,PBC_REST_RATE	\n");
        	sqlstr.append("         ,PBC_REST_CONDI	\n");
        	sqlstr.append("       )VALUES( 	\n");
        	sqlstr.append("           T.BID_NO	\n");
        	sqlstr.append("         ,T.BID_DEG	\n");
        	sqlstr.append("         ,T.VENDOR_CD	\n");
        	sqlstr.append("         ,T.CURRENCY_GB_YN	\n");
        	sqlstr.append("         ,T.CURRENCY_GB	\n");
        	sqlstr.append("         ,T.INSTALL_YN	\n");
        	sqlstr.append("         ,T.COMMISS_YN	\n");
        	sqlstr.append("         ,T.SPETOOL_YN	\n");
        	sqlstr.append("         ,T.TEST_YN	\n");
        	sqlstr.append("         ,T.DOC_YN	\n");
        	sqlstr.append("         ,T.PACK_YN	\n");
        	sqlstr.append("         ,T.LANDTRAN_YN	\n");
        	sqlstr.append("         ,T.DELIVERY_CONDITION_YN	\n");
        	sqlstr.append("         ,T.DELIVERY_CONDITION	\n");
        	sqlstr.append("         ,T.FEE_NOTI	\n");
        	sqlstr.append("         ,T.OPTION_NOTI	\n");
        	sqlstr.append("         ,T.QUOT_NO	\n");
        	sqlstr.append("         ,T.PAYCONDI_YN	\n");
        	sqlstr.append("         ,T.PAYCONDI_NOT_NOTI	\n");
        	sqlstr.append("         ,T.CONTFUL_YN	\n");
        	sqlstr.append("         ,T.CONTFUL_NOT_NOTI	\n");
        	sqlstr.append("         ,T.FRSTGUAR_YN	\n");
        	sqlstr.append("         ,T.FRSTGUAR_NOT_NOTI	\n");
        	sqlstr.append("         ,T.WARR_YN	\n");
        	sqlstr.append("         ,T.WARR_NOT_NOTI	\n");
        	sqlstr.append("         ,T.DEFECT_YN	\n");
        	sqlstr.append("         ,T.DEFECT_NOT_NOTI	\n");
        	sqlstr.append("         ,T.BID_CONDI_NOTI 	\n");
        	sqlstr.append("         ,T.CBC_FIRST_RATE	\n");
        	sqlstr.append("         ,T.PBC_FIRST_CONDI	\n");
        	sqlstr.append("         ,T.CPC_MID_RATE	\n");
        	sqlstr.append("         ,T.PBC_MID_CONDI	\n");
        	sqlstr.append("         ,T.PBC_REST_RATE	\n");
        	sqlstr.append("         ,T.PBC_REST_CONDI	\n");
        	sqlstr.append("       ) 	\n");
        	persistent.setStatement(sqlstr.toString());
        	persistent.addParameter(valueObject.get("BID_NO"));
        	persistent.addParameter(valueObject.get("BID_DEG"));
        	persistent.addParameter(valueObject.get("VENDOR_CD"));
        	persistent.addParameter(valueObject.get("CURRENCY_GB_YN"));
        	persistent.addParameter(valueObject.get("CURRENCY_GB"));
        	persistent.addParameter(valueObject.get("INSTALL_YN"));
        	persistent.addParameter(valueObject.get("COMMISS_YN"));
        	persistent.addParameter(valueObject.get("SPETOOL_YN"));
        	persistent.addParameter(valueObject.get("TEST_YN"));
        	persistent.addParameter(valueObject.get("DOC_YN"));
        	persistent.addParameter(valueObject.get("PACK_YN"));
        	persistent.addParameter(valueObject.get("LANDTRAN_YN"));
        	persistent.addParameter(valueObject.get("DELIVERY_CONDITION_YN")); 
        	persistent.addParameter(valueObject.get("DELIVERY_CONDITION"));
        	persistent.addParameter(valueObject.get("FEE_NOTI"));
        	persistent.addParameter(valueObject.get("OPTION_NOTI"));
        	persistent.addParameter(valueObject.get("QUOT_NO"));
        	persistent.addParameter(valueObject.get("PAYCONDI_YN"));
        	persistent.addParameter(valueObject.get("PAYCONDI_NOT_NOTI"));
        	persistent.addParameter(valueObject.get("CONTFUL_YN"));
        	persistent.addParameter(valueObject.get("CONTFUL_NOT_NOTI"));
        	persistent.addParameter(valueObject.get("FRSTGUAR_YN"));
        	persistent.addParameter(valueObject.get("FRSTGUAR_NOT_NOTI"));
        	persistent.addParameter(valueObject.get("WARR_YN"));
        	persistent.addParameter(valueObject.get("WARR_NOT_NOTI"));
        	persistent.addParameter(valueObject.get("DEFECT_YN"));
        	persistent.addParameter(valueObject.get("DEFECT_NOT_NOTI"));
        	persistent.addParameter(valueObject.get("BID_CONDI_NOTI"));
        	persistent.addParameter(valueObject.get("CBC_FIRST_RATE"));
        	persistent.addParameter(valueObject.get("PBC_FIRST_CONDI"));
        	persistent.addParameter(valueObject.get("CPC_MID_RATE"));
        	persistent.addParameter(valueObject.get("PBC_MID_CONDI"));
        	persistent.addParameter(valueObject.get("PBC_REST_RATE"));
        	persistent.addParameter(valueObject.get("PBC_REST_CONDI"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> bid_pur_condi_insert() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
    /**
     * 견적 금액 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_supp_esti_delete(Connection connection, ValueObject valueObject) throws Exception {
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append(" DELETE BID_SUPP_ESTI			\n");
        	sqlstr.append(" WHERE BID_NO = ? AND BID_DEG = ? AND VENDOR_CD = ?		\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.addParameter(valueObject.get("VENDOR_CD"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> bid_supp_esti_insert() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
    /**
     * 견적 금액 저장
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_supp_esti_insert(Connection connection, ValueObject valueObject) throws Exception {
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append(" INSERT INTO BID_SUPP_ESTI ( BID_NO,BID_DEG,MATERIAL_CD,VENDOR_CD,QTY,ROW_SUM_AMT,UNIT_COST,BASIS_CALCU,NOTI )			\n");
        	sqlstr.append("        VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? )		\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("BID_NO"));
            persistent.addParameter(params.get("BID_DEG"));
            persistent.addParameter(valueObject.get("MATERIAL_CD"));
            persistent.addParameter(params.get("VENDOR_CD"));
            persistent.addParameter(valueObject.get("QTY"));
            persistent.addParameter(valueObject.get("ROW_SUM_AMT"));
            persistent.addParameter(valueObject.get("UNIT_COST"));
            persistent.addParameter(valueObject.get("BASIS_CALCU"));
            persistent.addParameter(valueObject.get("NOTI"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> bid_supp_esti_insert() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 견적대상업체 총금액 업데이트
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_supp_update(Connection connection, ValueObject valueObject) throws Exception {
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("UPDATE BID_SUPP			\n");
        	sqlstr.append("SET ESTI_TOT_AMT = ?	\n");
        	sqlstr.append(",WON_ESTI_TOT_AMT = ? * NVL(EXCHANGE,1)		 	\n");  //2018.08.21 환율적용후 입찰금액 수정하는 경우 반영안되는 오류 수정.
        	sqlstr.append(",ATT_ID = ?						\n");
        	sqlstr.append(",FILE_GB = ?					\n");
        	sqlstr.append(",UPD_BY = ?					\n");
        	sqlstr.append(",UPD_DATE = SYSDATE		\n");
        	sqlstr.append("WHERE BID_NO = ?			\n");
        	sqlstr.append("AND BID_DEG = ?				\n");
        	sqlstr.append("AND VENDOR_CD = ?			\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("ESTI_TOT_AMT"));
            persistent.addParameter(valueObject.get("ESTI_TOT_AMT")); //2018.08.21
            persistent.addParameter(valueObject.get("ATT_ID"));
            persistent.addParameter(valueObject.get("FILE_GB"));
            persistent.addParameter(storage.getUser().get("ACCT_ID"));
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.addParameter(valueObject.get("VENDOR_CD"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> bid_supp_update() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 견적 금액 저장
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_supp_esti_update(Connection connection, ValueObject valueObject) throws Exception {
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	
        	sqlstr.append("  MERGE INTO BID_SUPP_ESTI TI USING																																					\n");
        	sqlstr.append("   ( SELECT ? AS BID_NO,? AS BID_DEG,? AS MATERIAL_CD,																															\n");
        	sqlstr.append("         ? AS VENDOR_CD,? AS QTY,? AS UNIT_COST,? AS BASIS_CALCU,																										\n");
        	sqlstr.append("         ? AS NOTI FROM DUAL )																																								\n");
        	sqlstr.append("   T ON (T.BID_NO = TI.BID_NO AND T.BID_DEG = TI.BID_DEG AND T.VENDOR_CD = TI.VENDOR_CD AND T.MATERIAL_CD = TI.MATERIAL_CD)				\n");
        	sqlstr.append("  WHEN MATCHED THEN																																											\n");
        	sqlstr.append("      UPDATE SET TI.QTY = T.QTY																																							\n");
        	sqlstr.append("      ,TI.UNIT_COST = T.UNIT_COST																																						\n");
        	sqlstr.append("      ,TI.BASIS_CALCU = T.BASIS_CALCU																																					\n");
        	sqlstr.append("      ,TI.NOTI = T.NOTI																																											\n");
        	sqlstr.append("  WHEN NOT MATCHED THEN																																									\n");
        	sqlstr.append("      INSERT (TI.BID_NO,TI.BID_DEG,TI.VENDOR_CD,TI.MATERIAL_CD,TI.QTY,TI.UNIT_COST,TI.BASIS_CALCU,TI.NOTI)											\n");
        	sqlstr.append("      VALUES (T.BID_NO,T.BID_DEG,T.VENDOR_CD,T.MATERIAL_CD,T.QTY,T.UNIT_COST,T.BASIS_CALCU,T.NOTI)													\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("BID_NO"));
            persistent.addParameter(params.get("BID_DEG"));
            persistent.addParameter(valueObject.get("MATERIAL_CD"));
            persistent.addParameter(params.get("VENDOR_CD"));
            persistent.addParameter(valueObject.get("QTY"));
            persistent.addParameter(valueObject.get("UNIT_COST"));
            persistent.addParameter(valueObject.get("BASIS_CALCU"));
            persistent.addParameter(valueObject.get("NOTI"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> bid_supp_esti_insert() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 보고자 전체 삭제
	 * @param connection
	 * @throws Exception
	 */
	public void BID_OPEN_REPORT_del(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE  BID_OPEN_REPORT						\n");
        	sqlstr.append("WHERE BID_NO = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }	
	
	/**
     * BID_MASTER.Delivery Condition 업데이트
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */	
	public void bid_master_update(Connection connection, ValueObject valueObject) throws Exception {
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("UPDATE BID_MASTER			\n");
        	sqlstr.append("SET DELIVERY_CONDITION = ?	\n");
        	sqlstr.append(",UPD_BY = ?					\n");
        	sqlstr.append(",UPD_DATE = SYSDATE		\n");
        	sqlstr.append("WHERE BID_NO = ?			\n");
        	sqlstr.append("AND BID_DEG = ?				\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("DELIVERY_CONDITION"));
            persistent.addParameter(storage.getUser().get("ACCT_ID"));
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> bid_master_update() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	
}