/**
 * @(#)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.outside.biz;



import java.sql.Connection;

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;

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 oracle.toplink.internal.ox.StrBuffer;

   
public class BidIngSaveBiz extends Biz {

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

	public void doBiz() throws Exception {
		boolean success = false;
		params.set("login_user", storage.getUser().get("ACCT_ID"));
		if(storage.compareEvent("UPDATE")) {
			success = saveProc(params);
		}else if (storage.compareEvent("COMPLETION")){//현설완료
			success = saveProc(params);
			if(success)status_update(super.conn.getConnection(),params);
        }else if(storage.compareEvent("FORM_CANCEL_UPDATE") || storage.compareEvent("FORM_POSTPONE_UPDATE")){//취소공고, 연기공고
        	success = BidingStatusUpdate(params,storage.getEvent());
        	
        }else if(storage.compareEvent("SET_CORP_DELETE")){//업체 삭제
        	success = SaveProcSupp(params);
        }
		// SMS // // E-Mail //
    	if(success){
        	ScrchInfoBiz ScrchInfo = new ScrchInfoBiz(storage);
        	if(storage.compareEvent("FORM_CANCEL_UPDATE")){
        		ScrchInfo.Send(params, "FORM_ING_CANCEL_UPDATE"); //2017.08.16 FORM_INT_CANCEL_UPDATE->FORM_ING_CANCEL_UPDATE
        	}else{
        		ScrchInfo.Send(params, storage.getEvent());
        	}
    	}
        super.storage.setSuccess(success);
        if(success)
        	storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
	}
	
	
	  /**
     * 사용자 정보 저장
	 * @param event
	 * @param valueObject
	 * @return
	 */
	public boolean saveProc(ValueObject valueObject) {
        try {
            conn.begin();
        	params.get("BID_NO");
            updUser(conn.getConnection(), params);
            if("Y".equals(params.get("TBE_FLAG"))){
            	tbeinfosave(conn.getConnection(), params);
            }else{//플랜트 상태값 변경
            	if (storage.compareEvent("COMPLETION")){//현설완료
	            	if("B".equals(params.get("DEMANDED_KIND"))) {
						update_mrreq_po(conn.getConnection(),"03");//입찰
	            	}
            	}
            }
            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));
				}
			}
            
            String demandedId = InterfaceOutERPiU.getDemandedId(params.get("BID_NO"), params.get("BID_DEG"));
            InterfaceOutERPiU.updateStatusPMM(demandedId, "04");
            
            return true;
        }
        catch(Exception e) {
        	storage.addObject("ibsheet7Data", IBSheet7Utils.exceptionHandle(storage.request, e));
            WAFLogger.error(this.getClass().getName() + " --> saveProc() : " + e.getMessage());
            WAFLogger.error(e);
            conn.setRollback();

            storage.setDetailMessage(e);
            return false;
        }
        finally {
        	
            conn.end();
        }
    }
	
	
	  /**
     * 사용자 정보 저장
	 * @param event
	 * @param valueObject
	 * @return
	 */
	public boolean SaveProcSupp(ValueObject valueObject) {
        try {
            conn.begin();
        	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));
				}
			}
            return true;
        }
        catch(Exception e) {
        	storage.addObject("ibsheet7Data", IBSheet7Utils.exceptionHandle(storage.request, 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 updUser(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_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("      , TBE_FLAG=?											\n");
			sqlstr.append("      , CURRENCY_GB=?											\n");
			sqlstr.append("      , CURRENCY_GB_YN=?											\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("      , PBC_DEFECT_CONDI= ?			\n");
			sqlstr.append("      , CBC_DERECT_TERM_CD= ?			\n");
			sqlstr.append("      , CBC_DEFECT_DAY= ?			\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("      , PAY_CON_RATE= ?				\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("      , OBC_CONT_TYPE_CD= ?				\n");
			sqlstr.append("      , OBC_FRST_CASH_RATE= ?				\n");
			sqlstr.append("      , OBC_FRST_CONDI= ?				\n");
			sqlstr.append("      , OBC_FRST_CNT_CONDI= ?				\n");
			sqlstr.append("      , OBC_MID_CASH_RATE= ?				\n");
			sqlstr.append("      , OBC_MID_BILL_RATE= ?				\n");
			sqlstr.append("      , OBC_MID_PAYDAY= ?				\n");
			sqlstr.append("      , OBC_MID_REQ_MONTH= ?				\n");
			sqlstr.append("      , OBC_MID_CNT= ?				\n");
			sqlstr.append("      , OBC_FIN_CASH_RATE= ?				\n");
			sqlstr.append("      , OBC_FIN_BILL_RATE= ?				\n");
			sqlstr.append("      , OBC_FIN_PAYDAY= ?				\n");
			sqlstr.append("      , OBC_FIN_CONDI= ?				\n");
			sqlstr.append("      , OBC_EMP_RATE= ?				\n");
			sqlstr.append("      , OBC_EMP_YN= ?				\n");
			sqlstr.append("      , OBC_PENSION_RATE= ?				\n");
			sqlstr.append("      , OBC_PENSION_YN= ?				\n");
			sqlstr.append("      , OBC_HEALTH_RATE= ?				\n");
			sqlstr.append("      , OBC_HEALTH_YN= ?				\n");
			sqlstr.append("      , OBC_ELDER_RATE= ?				\n");
			sqlstr.append("      , OBC_ELDER_YN= ?				\n");
			sqlstr.append("      , OBC_WORK_RATE= ?				\n");
			sqlstr.append("      , OBC_WORK_YN= ?				\n");
			sqlstr.append("      , OBC_RESIGN_RATE= ?				\n");
			sqlstr.append("      , OBC_RESIGN_YN= ?				\n");
			sqlstr.append("      , OBC_SAFE_RATE= ?				\n");
			sqlstr.append("      , OBC_SAFE_YN= ?				\n");
			sqlstr.append("      , OBC_ENV_RATE= ?				\n");
			sqlstr.append("      , OBC_ENV_YN= ?				\n");
			sqlstr.append("      , OBC_SITE_RATE= ?				\n");
			sqlstr.append("      , OBC_SITE_YN= ?				\n");
			sqlstr.append("      , OBC_DUTY_RATE= ?				\n");
			sqlstr.append("      , OBC_DUTY_YN= ?				\n");
			sqlstr.append("      , OBC_WARR_YN= ?				\n");
			sqlstr.append("      , OBC_IND_YN= ?				\n");
			sqlstr.append("      , OBC_FRST_CONT_RATE= ?				\n");
			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("  WHERE BID_NO = ?											\n");
			sqlstr.append("  AND BID_DEG = ?											\n");
            persistent.setStatement(sqlstr.toString());
            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(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("PBC_DEFECT_CONDI"));
            persistent.addParameter(valueObject.get("CBC_DERECT_TERM_CD"));
            persistent.addParameter(valueObject.get("CBC_DEFECT_DAY"));
            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("PAY_CON_RATE"));
            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("OBC_CONT_TYPE_CD"));
            persistent.addParameter(valueObject.get("OBC_FRST_CASH_RATE"));
            persistent.addParameter(valueObject.get("OBC_FRST_CONDI"));
            persistent.addParameter(valueObject.get("OBC_FRST_CNT_CONDI"));
            persistent.addParameter(valueObject.get("OBC_MID_CASH_RATE"));
            persistent.addParameter(valueObject.get("OBC_MID_BILL_RATE"));
            persistent.addParameter(valueObject.get("OBC_MID_PAYDAY"));
            persistent.addParameter(valueObject.get("OBC_MID_REQ_MONTH"));
            persistent.addParameter(valueObject.get("OBC_MID_CNT"));
            persistent.addParameter(valueObject.get("OBC_FIN_CASH_RATE"));
            persistent.addParameter(valueObject.get("OBC_FIN_BILL_RATE"));
            persistent.addParameter(valueObject.get("OBC_FIN_PAYDAY"));
            persistent.addParameter(valueObject.get("OBC_FIN_CONDI"));
            persistent.addParameter(valueObject.get("OBC_EMP_RATE"));
            persistent.addParameter(valueObject.get("OBC_EMP_YN"));
            persistent.addParameter(valueObject.get("OBC_PENSION_RATE"));
            persistent.addParameter(valueObject.get("OBC_PENSION_YN"));
            persistent.addParameter(valueObject.get("OBC_HEALTH_RATE"));
            persistent.addParameter(valueObject.get("OBC_HEALTH_YN"));
            persistent.addParameter(valueObject.get("OBC_ELDER_RATE"));
            persistent.addParameter(valueObject.get("OBC_ELDER_YN"));
            persistent.addParameter(valueObject.get("OBC_WORK_RATE"));
            persistent.addParameter(valueObject.get("OBC_WORK_YN"));
            persistent.addParameter(valueObject.get("OBC_RESIGN_RATE"));
            persistent.addParameter(valueObject.get("OBC_RESIGN_YN"));
            persistent.addParameter(valueObject.get("OBC_SAFE_RATE"));
            persistent.addParameter(valueObject.get("OBC_SAFE_YN"));
            persistent.addParameter(valueObject.get("OBC_ENV_RATE"));
            persistent.addParameter(valueObject.get("OBC_ENV_YN"));
            persistent.addParameter(valueObject.get("OBC_SITE_RATE"));
            persistent.addParameter(valueObject.get("OBC_SITE_YN"));
            persistent.addParameter(valueObject.get("OBC_DUTY_RATE"));
            persistent.addParameter(valueObject.get("OBC_DUTY_YN"));
            persistent.addParameter(valueObject.get("OBC_WARR_YN"));
            persistent.addParameter(valueObject.get("OBC_IND_YN"));
            persistent.addParameter(valueObject.get("OBC_FRST_CONT_RATE"));
            persistent.addParameter(valueObject.get("login_user"));
            persistent.addParameter(valueObject.get("MAIN_PR_CONTENTS"));
            persistent.addParameter(valueObject.get("BID_SUPP_SELECT_REASON"));
            /*where*/
            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;
        }
    }
	
	/**
     * 사용자 수정
	 * @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("             	,NVL(?,(SELECT TEL_NO FROM PUB0120T WHERE ACCT_ID = ?)) AS EVAL_TEL											\n");
        	sqlstr.append("            	,(SELECT E_MAIL FROM PUB0120T WHERE ACCT_ID = ?) 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_EMPID"));
            persistent.addParameter(valueObject.get("EVAL_EMPID"));
            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();
        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("          ,SITE_ATTEND_YN			\n");
        	sqlstr.append("          ,SITEPARTI_YN			\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("          ,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"));
            persistent.addParameter(valueObject.get("SITE_ATTEND_YN"));
            persistent.addParameter(valueObject.get("SITEPARTI_YN"));
            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();
        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("     , SITEPARTI_YN=?							\n");
        	sqlstr.append("     , RECM_DEPT_ID=?							\n");
        	sqlstr.append("     , RECM_DEPT_NM=?							\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("SITEPARTI_YN"));
            persistent.addParameter(valueObject.get("RECM_DEPT_ID"));
            persistent.addParameter(valueObject.get("RECM_DEPT_NM"));
            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 {
        	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(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 status_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 STATUS_CD = '04'		\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(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;
        }
    }
	
	  /**
     * 발주 정보 수정 
	 * @param event
	 * @param valueObject
	 * @return
	 */
	public boolean BidingStatusUpdate(ValueObject valueObject,String event) {
		conn.begin(); 
		StrBuffer sqlstr = new StrBuffer();

        try {
        	
    		if(storage.compareEvent("FORM_CANCEL_UPDATE")){//취소 공고 일경우 경영정보에 업데이트.
				if("B".equals(params.get("DEMANDED_KIND"))) {
					update_mrreq_po(conn.getConnection(),"91","9");//취소
				}
        	}
    		
        	Persistent persistent = new PersistentImpl(conn.getConnection());
            sqlstr.append("UPDATE BID_MASTER		\n");
        	sqlstr.append("SET STATUS_CD = '"+valueObject.get("STATUS_CD")+"'		\n");
        	if(event.equals("FORM_CANCEL_UPDATE")){//취소 공고
        		sqlstr.append(", CANCEL_REASON = '"+valueObject.get("CANCEL_REASON")+"'		\n");
        	}else if(event.equals("FORM_POSTPONE_UPDATE")){//연기공고
        		sqlstr.append(", POSTPONE_REASON = '"+valueObject.get("POSTPONE_REASON")+"'		\n");
        		sqlstr.append(", BID_TO_DT = TO_DATE('"+valueObject.get("BID_TO_DT")+"'||'"+valueObject.get("BID_TO_HH")+"'||'"+valueObject.get("BID_TO_MI")+"','YYYY-MM-DD HH24MISS')	\n");
        	}
        	if(!valueObject.get("DELAY_NOTI_YN").isEmpty())
        		sqlstr.append(", DELAY_NOTI_YN = '"+valueObject.get("DELAY_NOTI_YN")+"'		\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(storage.getUser().get("ACCT_ID"));
            persistent.addParameter(valueObject.get("BID_NO"));
            persistent.addParameter(valueObject.get("BID_DEG"));
            persistent.execute();
            
            
            String demandedId = InterfaceOutERPiU.getDemandedId(valueObject.get("BID_NO"), valueObject.get("BID_DEG"));
            InterfaceOutERPiU.updateStatusPMM(demandedId, valueObject.get("STATUS_CD"));
            
            
            return true;
        }
        catch(Exception e) {
        	storage.addObject("ibsheet7Data", IBSheet7Utils.exceptionHandle(storage.request, e));
            WAFLogger.error(this.getClass().getName() + " --> saveProc() : " + e.getMessage());
            WAFLogger.error(e);
            conn.setRollback();
            storage.setDetailMessage(e);
            return false;
        }
        finally {
        	
            conn.end();
        }
    }
	
	public boolean update_mrreq_po(Connection connection,String ebid_staus_code) throws Exception {
		return update_mrreq_po(connection,ebid_staus_code,"");
	}

	/**
	 * 발주의뢰 상태값 업데이트
	 * @return
	 */
	public boolean update_mrreq_po(Connection connection,String ebid_staus_code,String status_code) throws Exception {
		StrBuffer sqlstr = new StrBuffer();
		Persistent pstmt = new PersistentImpl(connection);
        try{
        		sqlstr.append("	UPDATE ETECEPC.MR_REQ_PO							\n");
				sqlstr.append("	SET EBID_STATUS = ?									\n");
				if("9".equals(status_code))
					sqlstr.append("	, REQ_STATUS = ?										\n");
				sqlstr.append("	WHERE BUYREQNO = ?									\n");
		       	pstmt.setStatement(sqlstr.toString());
		       	pstmt.addParameter(ebid_staus_code);
		       	if("9".equals(status_code))
		       		pstmt.addParameter("9");
				pstmt.addParameter(params.get("DEMANDED_ID"));
				pstmt.execute();
				return true;
	        }catch (Exception e){
				WAFLogger.error(e);
				throw new Exception(e);
	        }
	}
	
}