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



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

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.Row;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.RowSetImpl;
import kr.co.hsnc.common.sql.WAFSQLException;
import kr.co.hsnc.common.sql.persistent.Persistent;
import kr.co.hsnc.common.sql.persistent.PersistentImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.sql.util.RowSetUtility;
import kr.co.hsnc.common.util.ValueObject;
import kr.co.udapsoft.common.code.CommCodeManager;
import kr.co.udapsoft.ebid.buyer.common.file.FileManager;
import kr.co.udapsoft.ebid.buyer.sycs.user.biz.UserCommon;

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

import kr.co.udapsoft.ebid.buyer.bid.outside.biz.ScrchInfoBiz;
   
public class ReBidSaveBiz extends Biz {

	public ReBidSaveBiz(HandlerStorage storage) {
		super(storage);
	}
	
	FileManager fileManager = new FileManager();

	public void doBiz() throws Exception {
        ValueObject user = new ValueObject();
		boolean success = false;
		if(storage.compareEvent("RE_BID_SAVE")){//견적의뢰
			success = rebidsave();
			// SMS // // E-Mail //
	    	if(success){
				int biddeg = params.getInt("BID_DEG")+1;
				params.set("BID_DEG", biddeg);
	    	}
		}else if(storage.compareEvent("RE_BID_UPDATE")){
			success = rebidUpdate();
		}else if(storage.compareEvent("RE_BID_DELETE")){
			success = rebidDelete();
		}
		
        super.storage.setSuccess(success);
        if(success)
        	storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
	}
	
	  /**
     * 재입찰
	 * @param event
	 * @param valueObject
	 * @return
	 */
	public boolean rebidsave() {
		conn.begin();
        try {
        	Connection con = conn.getConnection();
            if(params.get("BID_NO").isEmpty() || params.get("BID_DEG").isEmpty()){
            	throw new Exception("에러가 발생하였습니다.");
            }

            //BID_MASTER
            bid_master(con);

/*            if(params.get("TBE_FLAG").equals("Y")){
            	//tbeinfosave(conn.getConnection(),params);
            	callTbeSave(conn.getConnection(),params);
            }
            */
            bid_master_update(con);
            //FILE
            fileManager.copyFileList(con, params.get("DOC_ETC_IN"), params.get("DEMANDED_ID"), "BID_IN_"+(params.getInt("BID_DEG")+1), params.get("DEMANDED_ID"));
            fileManager.copyFileList(con, params.get("DOC_ETC_OUT"), params.get("DEMANDED_ID"),"BID_OUT_"+(params.getInt("BID_DEG")+1), params.get("DEMANDED_ID"));
            //BID_ITEM
            bid_item(con);
            //BID_SUPP    				견적대상업체 
            
            String[] status = super.gets("sheet1.STATUS");
            for (int i = 0; i < status.length; i++) {
				if (IBSheet7Utils.equalStatusInsert(status[i])) {
					saveData(con, IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
				}
				if(IBSheet7Utils.equalStatusUpdate(status[i])){
					updateData(con, IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
				}
				
				if (IBSheet7Utils.equalStatusDelete(status[i])) {
					deleteData(con, IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
				}
			}
            
            
            if(params.get("TBE_FLAG").equals("Y")){
            	//tbeinfosave(conn.getConnection(),params);
            	//callTbeSave(con,params);
            }
            
            //BID_OPEN_REPORT
            bid_open_report(con);
            
            String demandedId = InterfaceOutERPiU.getDemandedId(params.get("BID_NO"), params.get("BID_DEG"));
            InterfaceOutERPiU.updateStatusPMM(demandedId, "20");

            return true;
        }
        catch(Exception e) {
        	storage.addObject("ibsheet7Data", IBSheet7Utils.exceptionHandle(storage.request, e));
            WAFLogger.error(this.getClass().getName() + " --> rebidsave() : " + e.getMessage());
            WAFLogger.error(e);
            conn.setRollback();

            storage.setDetailMessage(e);
            return false;
        }
        finally {
        	
            conn.end();
        }
    }
	
	/**
	 * 재입찰
	 * @param event
	 * @param valueObject
	 * @return
	 */
	public boolean rebidUpdate() {
		conn.begin();
		try {
			Connection con = conn.getConnection();
			if(params.get("BID_NO").isEmpty() || params.get("BID_DEG").isEmpty()){
				throw new Exception("에러가 발생하였습니다.");
			}
			//BID_MASTER
			bid_masterUpdate(con);

			
			String[] status = super.gets("sheet1.STATUS");
			for (int i = 0; i < status.length; i++) {
				if (IBSheet7Utils.equalStatusInsert(status[i])) {
					saveData2(con, IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
				}
				if(IBSheet7Utils.equalStatusUpdate(status[i])){
					updateData2(con, IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
				}
				
				if (IBSheet7Utils.equalStatusDelete(status[i])) {
					deleteData(con, IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
				}
			}
			
			
            String demandedId = InterfaceOutERPiU.getDemandedId(params.get("BID_NO"), params.get("BID_DEG"));
            InterfaceOutERPiU.updateStatusPMM(demandedId, "20");
            
			//BID_SUPP    				견적대상업 체 
			/*if("Y".equals(params.get("TBE_FLAG"))){
				//tbeinfosave(conn.getConnection(), params);
				callTbeSave(con,params);
			}*/
			return true;
		}
		catch(Exception e) {
			storage.addObject("ibsheet7Data", IBSheet7Utils.exceptionHandle(storage.request, e));
			WAFLogger.error(this.getClass().getName() + " --> rebidsave() : " + e.getMessage());
			WAFLogger.error(e);
			conn.setRollback();
			
			storage.setDetailMessage(e);
			return false;
		}
		finally {
			
			conn.end();
		}
	}
	
	
	  /**
     * 재입찰
	 * @param event
	 * @param valueObject
	 * @return
	 */
	public boolean rebidDelete() {
		conn.begin();
        try {
        	Connection con = conn.getConnection();
            if(params.get("BID_NO").isEmpty() || params.get("BID_DEG").isEmpty()){
            	throw new Exception("에러가 발생하였습니다.");
            }
            fileManager.delFileMapProc(con, params.get("DOC_ETC_IN"),  params.get("DEMANDED_ID"));
            fileManager.delFileMapProc(con, params.get("DOC_ETC_OUT"),  params.get("DEMANDED_ID"));
            
            //BID_ITEM
            bid_item_delete(con);
            
            bid_supp_delete(con);
            
            //BID_MASTER
            bid_master_delete(con);
            
            bid_master_delete_update(con);
            //FILE
            //BID_SUPP    				견적대상업 체 
            /*if("Y".equals(params.get("TBE_FLAG"))){
            	//tbeinfosave(conn.getConnection(), params);
            	callTbeSave(con,params);
            }*/
            
            //BID_OPEN_REPORT
            bid_open_report_delete(con);
            
            return true;
        }
        catch(Exception e) {
        	storage.addObject("ibsheet7Data", IBSheet7Utils.exceptionHandle(storage.request, e));
            WAFLogger.error(this.getClass().getName() + " --> rebidsave() : " + e.getMessage());
            WAFLogger.error(e);
            conn.setRollback();

            storage.setDetailMessage(e);
            return false;
        }
        finally {
        	
            conn.end();
        }
    }
	
	/**
     * BID_MASTER 복사
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_master(Connection connection) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
				sqlstr.append("      INSERT INTO BID_MASTER 				\n");
				sqlstr.append("             (   BID_NO				\n");
				sqlstr.append("               ,BID_DEG				\n");
				sqlstr.append("               ,DEMANDED_ID				\n");
				sqlstr.append("               ,DEMANDED_NO				\n");
				sqlstr.append("               ,DEPT_CD				\n");
				sqlstr.append("               ,DEPT_NM				\n");
				sqlstr.append("               ,EMP_NO				\n");
				sqlstr.append("               ,DEMANDED_TITLE				\n");
				sqlstr.append("               ,DEMANDED_KIND				\n");
				sqlstr.append("               ,DEMANDED_DATE				\n");
				sqlstr.append("               ,REQUEST_DATE				\n");
				sqlstr.append("               ,REQ_DEPT_CD				\n");
				sqlstr.append("               ,REQ_DEPT_NM				\n");
				sqlstr.append("               ,EMP_NM				\n");
				sqlstr.append("               ,PAY_ITEM				\n");
				sqlstr.append("               ,COST_CODE				\n");
				sqlstr.append("               ,COST_TYPE				\n");
				sqlstr.append("               ,RECEIPT_DATE				\n");
				sqlstr.append("               ,ONBID_YN				\n");
				sqlstr.append("               ,CMPT_CD				\n");
				sqlstr.append("               ,SUCC_CD				\n");
				sqlstr.append("               ,NOTI_DY				\n");
				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				\n");
				sqlstr.append("               ,SITEDESCPLACE				\n");
				sqlstr.append("               ,BID_FROM_DT				\n");
				sqlstr.append("               ,BID_TO_DT				\n");
				sqlstr.append("               ,CONT_AMT				\n");
				sqlstr.append("               ,ACT_AMT				\n");
				sqlstr.append("               ,ACT_RATE				\n");
				sqlstr.append("               ,PUR_AMT                \n"); //구매외주 예산 2015.3.4 MKLEE
				sqlstr.append("               ,PUREMPNO				\n");
				sqlstr.append("               ,PO_EMPNM				\n");
				sqlstr.append("               ,OPEN_EMPNM				\n");
				sqlstr.append("               ,OPEN_EMPID				\n");
				sqlstr.append("               ,OPEN_DT				\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("               ,DELI_START_DT				\n");
				sqlstr.append("               ,DELI_END_DT				\n");
				sqlstr.append("               ,CONTFUL_RATE				\n");
				sqlstr.append("               ,CONTFUL_CONDI				\n");
				sqlstr.append("               ,WARR_RATE				\n");
				sqlstr.append("               ,WARR_CONDI				\n");
				sqlstr.append("               ,DELIVERY_CONDITION				\n");
				sqlstr.append("               ,DELIVERY_CONDITION_YN				\n");
				sqlstr.append("               ,DELIVERY_PLACE				\n");
				sqlstr.append("               ,INNER_REMARKS				\n");
				sqlstr.append("               ,OUTER_REMARKS				\n");
				sqlstr.append("               ,ATT_ID				\n");
				sqlstr.append("               ,BID_APP_DATE				\n");
				sqlstr.append("               ,BID_APP_NO				\n");
				sqlstr.append("               ,DOC_ETC_IN				\n");
				sqlstr.append("               ,DOC_ETC_OUT				\n");
				sqlstr.append("               ,BID_MASTER_NM				\n");
				sqlstr.append("               ,OUT_ITEM_CD				\n");
				sqlstr.append("               ,STATUS_CD				\n");
				sqlstr.append("               ,OBC_CONT_TYPE_CD				\n");
				sqlstr.append("               ,OBC_FRST_CONT_RATE				\n");
				sqlstr.append("               ,OBC_FRST_CONDI				\n");
				sqlstr.append("               ,OBC_FRST_CNT_CONDI				\n");
				sqlstr.append("               ,CPC_MID_RATE				\n");
				sqlstr.append("            	  ,OBC_MID_PAYDAY				\n");
				sqlstr.append("               ,OBC_MID_REQ_MONTH				\n");
				sqlstr.append("               ,OBC_MID_CNT				\n");
				sqlstr.append("               ,OBC_MID_CASH_RATE				\n");
				sqlstr.append("               ,OBC_MID_BILL_RATE				\n");
				sqlstr.append("               ,PBC_REST_RATE				\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("               ,CBC_FIRST_RATE              \n");
				sqlstr.append("               ,CBC_DEFECT_DAY                \n");
				sqlstr.append("               ,PAY_CON_RATE               \n");
				sqlstr.append("               ,CBC_DAMAGE_RATE               \n");
				sqlstr.append("               ,CBC_DAMAGE_MAXRATE            \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("               ,REBID_REASON				\n");
				sqlstr.append("               ,REBID_OUTREASON				\n");
				sqlstr.append("               ,CONF_NO				\n");
				sqlstr.append("               ,CRE_BY				\n");
				sqlstr.append("               ,CRE_DATE				\n");
				sqlstr.append("               ,MAIN_PR_CONTENTS				\n");
				sqlstr.append("               ,BID_SUPP_SELECT_REASON		\n");
				sqlstr.append("             )  				\n");
				sqlstr.append("      SELECT A.BID_NO,				\n");
				sqlstr.append("             TRIM(TO_CHAR(A.BID_DEG+1,'000')),				\n");
				sqlstr.append("             A.DEMANDED_ID,				\n");
				sqlstr.append("             A.DEMANDED_NO,				\n");
				sqlstr.append("             A.DEPT_CD,				\n");
				sqlstr.append("             A.DEPT_NM,				\n");
				sqlstr.append("             A.EMP_NO,				\n");
				sqlstr.append("             A.DEMANDED_TITLE,				\n");
				sqlstr.append("             A.DEMANDED_KIND,				\n");
				sqlstr.append("             A.DEMANDED_DATE,				\n");
				sqlstr.append("             A.REQUEST_DATE,				\n");
				sqlstr.append("             A.REQ_DEPT_CD,				\n");
				sqlstr.append("             A.REQ_DEPT_NM,				\n");
				sqlstr.append("             A.EMP_NM,				\n");
				sqlstr.append("             A.PAY_ITEM,				\n");
				sqlstr.append("             A.COST_CODE,				\n");
				sqlstr.append("             A.COST_TYPE,				\n");
				sqlstr.append("             A.RECEIPT_DATE,				\n");
				sqlstr.append("             A.ONBID_YN,				\n");
				sqlstr.append("             A.CMPT_CD,				\n");
				sqlstr.append("             A.SUCC_CD,				\n");
				sqlstr.append("             A.NOTI_DY,				\n");
				//sqlstr.append("             A.SITEDESC_FLAG,				\n");  2018.07.10
				//sqlstr.append("             A.SITEDESCCHRGPRSNID,				\n");
				//sqlstr.append("             A.SITEDESC_CRG_NM,				\n");
				//sqlstr.append("             A.SITEDESCTELNO,				\n");
				//sqlstr.append("             A.SITEDESCEMAIL,				\n");
				//sqlstr.append("             A.SITEDESCDATE,				\n");
				//sqlstr.append("             A.SITEDESCPLACE,				\n");
				sqlstr.append("             ?,				                        \n");  //A.SITEDESC_FLAG
				sqlstr.append("             ?,				                        \n");  //A.SITEDESCCHRGPRSNID
				sqlstr.append("             ?,				                        \n");  //A.SITEDESC_CRG_NM
				sqlstr.append("             ?,				                        \n");  //A.SITEDESCTELNO
				sqlstr.append("             ?,				                        \n");  //A.SITEDESCEMAIL
				sqlstr.append("             TO_DATE(?||?||?,'YYYY-MM-DDHH24MI'),	\n");  //A.SITEDESCDATE
				sqlstr.append("             ?,				                        \n");  //A.SITEDESCPLACE
				sqlstr.append("             TO_DATE(?||?||?,'YYYY-MM-DDHH24MI'),				\n");
				sqlstr.append("             TO_DATE(?||?||?,'YYYY-MM-DDHH24MI'),				\n");
				sqlstr.append("             ?,				\n");
				sqlstr.append("             ?,				\n");
				sqlstr.append("             ?,				\n");
				sqlstr.append("             ?,                                        \n"); //구매외주 예산 2015.3.4 MKLEE
				sqlstr.append("             ?,				\n");
				sqlstr.append("             ?,				\n");
				sqlstr.append("           	 ?,				\n");
				sqlstr.append("             ?,				\n");
				sqlstr.append("             null,				\n");
				sqlstr.append("             ?,				\n");
				sqlstr.append("             ?,				\n");
				sqlstr.append("             A.CURRENCY_GB_YN,				\n");
				//sqlstr.append("             A.DELI_FROM_DY,			                 	\n"); 
				//sqlstr.append("             A.DELI_TO_DY,			               	    \n"); 
				//sqlstr.append("             A.DELI_START_DT,				\n");
				//sqlstr.append("             A.DELI_END_DT,				\n");
				//2016.12.8 공가기간 대체
				sqlstr.append("             ?,				\n");  //DELI_FROM_DY
				sqlstr.append("             ?,				\n");  //DELI_TO_DY
				sqlstr.append("             ?,				\n");  //DELI_START_DT
				sqlstr.append("             ?,				\n");  //DELI_END_DT
				sqlstr.append("             ?,				\n");
				sqlstr.append("             A.CONTFUL_CONDI,				\n");
				sqlstr.append("             ?,				\n");
				sqlstr.append("             A.WARR_CONDI,				\n");
				sqlstr.append("             A.DELIVERY_CONDITION,				\n");
				sqlstr.append("             A.DELIVERY_CONDITION_YN,				\n");
				sqlstr.append("             A.DELIVERY_PLACE,				\n");
				sqlstr.append("             A.INNER_REMARKS,				\n");
				sqlstr.append("             A.OUTER_REMARKS,				\n");
				sqlstr.append("             A.ATT_ID,				\n");
				sqlstr.append("             A.BID_APP_DATE,				\n");
				sqlstr.append("             A.BID_APP_NO,				\n");
				sqlstr.append("             'BID_IN'||'_'||TO_NUMBER(A.BID_DEG+1),				\n");
				sqlstr.append("             'BID_OUT'||'_'||TO_NUMBER(A.BID_DEG+1),				\n");
				sqlstr.append("             A.BID_MASTER_NM,				\n");
				sqlstr.append("             A.OUT_ITEM_CD,				\n");
				sqlstr.append("             '20', --재입찰				\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("             ?,				\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("             ?,				\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("             CONF_NO,		\n");
				sqlstr.append("             ?,				\n");
				sqlstr.append("             SYSDATE,		\n");
				sqlstr.append("             ?,				\n");
				sqlstr.append("             ?				\n");
				sqlstr.append("        FROM BID_MASTER A	\n");
				sqlstr.append("      WHERE BID_NO = ?		\n");
				sqlstr.append("      AND BID_DEG = ?		\n");
				persistent.setStatement(sqlstr.toString());
				
				persistent.addParameter(params.get("SITEDESC_FLAG"));  //2018.07.09 
	            persistent.addParameter(params.get("SITEDESCCHRGPRSNID"));
	            persistent.addParameter(params.get("SITEDESCCHRGPRSNNM"));
	            persistent.addParameter(params.get("SITEDESCTELNO"));
	            persistent.addParameter(params.get("SITEDESCEMAIL"));
	            persistent.addParameter(StringUtils.replace(params.get("SITEDESCDATE"),"-",""));
	            persistent.addParameter(params.get("SITEDESCDATE_HH"));
	            persistent.addParameter(params.get("SITEDESCDATE_MI"));
	            persistent.addParameter(params.get("SITEDESCPLACE"));
	            
				
				persistent.addParameter(params.get("BID_FROM_DT"));
				persistent.addParameter(params.get("BID_FROM_HH"));
				persistent.addParameter(params.get("BID_FROM_MI"));
				persistent.addParameter(params.get("BID_TO_DT"));
				persistent.addParameter(params.get("BID_TO_HH"));
				persistent.addParameter(params.get("BID_TO_MI"));
				
				persistent.addParameter(params.get("CONT_AMT").replaceAll(",", ""));
				persistent.addParameter(params.get("ACT_AMT").replaceAll(",", ""));
				persistent.addParameter(params.get("ACT_RATE").replaceAll(",", ""));
				persistent.addParameter(params.get("PUR_AMT").replaceAll(",", ""));
				
				persistent.addParameter(params.get("PUREMPNO"));
				persistent.addParameter(params.get("PO_EMPNM"));
				persistent.addParameter(params.get("OPEN_EMPNM"));
				persistent.addParameter(params.get("OPEN_EMPID"));
				persistent.addParameter(params.get("TBE_FLAG"));
				/*추가 */
				persistent.addParameter(params.get("CURRENCY_GB"));
				persistent.addParameter(StringUtils.replace(params.get("DELI_FROM_DY"),"-",""));  //2016.12.8
	            persistent.addParameter(StringUtils.replace(params.get("DELI_TO_DY"),"-",""));
	            persistent.addParameter(StringUtils.replace(params.get("DELI_FROM_DY"),"-",""));
	            persistent.addParameter(StringUtils.replace(params.get("DELI_TO_DY"),"-",""));
				
				persistent.addParameter(params.get("CONTFUL_RATE"));
				persistent.addParameter(params.get("WARR_RATE"));
				
				persistent.addParameter(params.get("OBC_CONT_TYPE_CD"));
				persistent.addParameter(params.get("OBC_FRST_CONT_RATE"));
				persistent.addParameter(params.get("OBC_FRST_CONDI"));
				persistent.addParameter(params.get("OBC_FRST_CNT_CONDI"));
				persistent.addParameter(params.get("CPC_MID_RATE"));
				persistent.addParameter(params.get("OBC_MID_PAYDAY"));
				persistent.addParameter(params.get("OBC_MID_REQ_MONTH"));
				persistent.addParameter(params.get("OBC_MID_CNT"));
				persistent.addParameter(params.get("OBC_MID_CASH_RATE"));
				persistent.addParameter(params.get("OBC_MID_BILL_RATE"));
				persistent.addParameter(params.get("PBC_REST_RATE"));
				persistent.addParameter(params.get("OBC_FIN_CASH_RATE"));
				persistent.addParameter(params.get("OBC_FIN_BILL_RATE"));
				persistent.addParameter(params.get("OBC_FIN_PAYDAY"));
				persistent.addParameter(params.get("OBC_FIN_CONDI"));
				persistent.addParameter(params.get("CBC_FIRST_RATE"));
				persistent.addParameter(params.get("CBC_DEFECT_DAY"));
				persistent.addParameter(params.get("PAY_CON_RATE"));
				persistent.addParameter(params.get("CBC_DAMAGE_RATE"));
				persistent.addParameter(params.get("CBC_DAMAGE_MAXRATE"));
				persistent.addParameter(params.get("OBC_EMP_RATE"));
				persistent.addParameter(params.get("OBC_EMP_YN"));
				persistent.addParameter(params.get("OBC_PENSION_RATE"));
				persistent.addParameter(params.get("OBC_PENSION_YN"));
				persistent.addParameter(params.get("OBC_HEALTH_RATE"));
				persistent.addParameter(params.get("OBC_HEALTH_YN"));
				persistent.addParameter(params.get("OBC_ELDER_RATE"));
				persistent.addParameter(params.get("OBC_ELDER_YN"));
				persistent.addParameter(params.get("OBC_WORK_RATE"));
				persistent.addParameter(params.get("OBC_WORK_YN"));
				persistent.addParameter(params.get("OBC_RESIGN_RATE"));
				persistent.addParameter(params.get("OBC_RESIGN_YN"));
				persistent.addParameter(params.get("OBC_SAFE_RATE"));
				persistent.addParameter(params.get("OBC_SAFE_YN"));
				persistent.addParameter(params.get("OBC_ENV_RATE"));
				persistent.addParameter(params.get("OBC_ENV_YN"));
				persistent.addParameter(params.get("OBC_SITE_RATE"));
				persistent.addParameter(params.get("OBC_SITE_YN"));
				persistent.addParameter(params.get("OBC_DUTY_RATE"));
				persistent.addParameter(params.get("OBC_DUTY_YN"));
				persistent.addParameter(params.get("OBC_WARR_YN"));
				persistent.addParameter(params.get("OBC_IND_YN"));

				persistent.addParameter(params.get("REBID_REASON"));
				persistent.addParameter(params.get("REBID_OUTREASON"));
				persistent.addParameter(storage.getUser().get("ACCT_ID"));
				persistent.addParameter(params.get("MAIN_PR_CONTENTS"));
				persistent.addParameter(params.get("BID_SUPP_SELECT_REASON"));
				
				persistent.addParameter(params.get("BID_NO"));
				persistent.addParameter(params.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;
        }
    }
	
	
	/**
	 * BID_MASTER 복사
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_masterUpdate(Connection connection) 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(?||?||?,'YYYY-MM-DDHH24MI'), \n");
			sqlstr.append("				       BID_TO_DT             = TO_DATE(?||?||?,'YYYY-MM-DDHH24MI'), \n");
			sqlstr.append("				       PUR_AMT              = ?,                                	\n");
			sqlstr.append("				       CONT_AMT              = ?,                                	\n");
			sqlstr.append("				       ACT_AMT              = ?,                                	\n");
			sqlstr.append("				       ACT_RATE              = ?,                                	\n");
			sqlstr.append("				       PUREMPNO              = ?,                                	\n");
			sqlstr.append("				       PO_EMPNM              = ?,                                	\n");
			sqlstr.append("				       OPEN_EMPNM            = ?,                                	\n");
			sqlstr.append("				       OPEN_EMPID            = ?,                                	\n");
			sqlstr.append("				       INNER_REMARKS         = ?,                              		\n");
			sqlstr.append("				       OUTER_REMARKS         = ?,                              		\n");
			sqlstr.append("				       STATUS_CD             = '20',                               	\n");

			sqlstr.append("				       SITEDESC_FLAG = ?,             	\n");  //2018.07.09 재입찰 현설진행 
			sqlstr.append("				       SITEDESCCHRGPRSNID = ?,          \n");
			sqlstr.append("				       SITEDESCTELNO = ?,             	\n");
			sqlstr.append("				       SITEDESCEMAIL = ?,             	\n");
			sqlstr.append("                    SITEDESCDATE=TO_DATE(?||?||?,'YYYYMMDDHH24MI'),	 		\n");
			sqlstr.append("				       SITEDESCPLACE = ?,             	\n");
			
			sqlstr.append("				       CONTFUL_RATE             = ?,                               	\n");
			sqlstr.append("				       WARR_RATE             = ?,                               	\n");
			sqlstr.append("				       OBC_CONT_TYPE_CD             = ?,                               	\n");
			sqlstr.append("				       OBC_FRST_CONT_RATE             = ?,                               	\n");
			sqlstr.append("				       OBC_FRST_CONDI             = ?,                               	\n");
			sqlstr.append("				       OBC_FRST_CNT_CONDI             = ?,                               	\n");
			sqlstr.append("				       CPC_MID_RATE             = ?,                               	\n");
			sqlstr.append("				       OBC_MID_PAYDAY             = ?,                               	\n");
			sqlstr.append("				       OBC_MID_REQ_MONTH             = ?,                               	\n");
			sqlstr.append("				       OBC_MID_CNT             = ?,                               	\n");
			sqlstr.append("				       OBC_MID_CASH_RATE             = ?,                               	\n");
			sqlstr.append("				       OBC_MID_BILL_RATE             = ?,                               	\n");
			sqlstr.append("				       PBC_REST_RATE             = ?,                               	\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("				       CBC_FIRST_RATE             = ?,                               	\n");
			sqlstr.append("				       CBC_DEFECT_DAY             = ?,                               	\n");
			sqlstr.append("				       PAY_CON_RATE             = ?,                               	\n");
			sqlstr.append("				       CBC_DAMAGE_RATE             = ?,                               	\n");
			sqlstr.append("				       CBC_DAMAGE_MAXRATE             = ?,                               	\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("				       BID_MASTER_NM             = ?,                               	\n");  //2015.12.10 입찰명 수정 
			sqlstr.append("                    DELI_FROM_DY				= ?,                                \n"); //2016.12.8 
			sqlstr.append("                    DELI_TO_DY				= ?,                                \n");
			sqlstr.append("                    DELI_START_DT		    = ?,                                \n");
			sqlstr.append("                    DELI_END_DT				= ?,                                \n");
			
			sqlstr.append("				       REBID_REASON          = ?,                               	\n");
			sqlstr.append("				       REBID_OUTREASON        = ?                              		\n");
			sqlstr.append("				WHERE  BID_NO                = ?                                    \n");
			sqlstr.append("				AND    BID_DEG               = ?									\n");
            
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(params.get("BID_FROM_DT"));
			persistent.addParameter(params.get("BID_FROM_HH"));
			persistent.addParameter(params.get("BID_FROM_MI"));
			persistent.addParameter(params.get("BID_TO_DT"));
			persistent.addParameter(params.get("BID_TO_HH"));
			persistent.addParameter(params.get("BID_TO_MI"));
			
			persistent.addParameter(params.get("PUR_AMT").replaceAll(",", ""));
			persistent.addParameter(params.get("CONT_AMT").replaceAll(",", ""));
			persistent.addParameter(params.get("ACT_AMT").replaceAll(",", ""));
			persistent.addParameter(params.get("ACT_RATE").replaceAll(",", ""));
			
			persistent.addParameter(params.get("PUREMPNO"));
			persistent.addParameter(params.get("PO_EMPNM"));
			persistent.addParameter(params.get("OPEN_EMPNM"));
			persistent.addParameter(params.get("OPEN_EMPID"));
			persistent.addParameter(params.get("INNER_REMARKS"));
			persistent.addParameter(params.get("OUTER_REMARKS"));

			persistent.addParameter(params.get("SITEDESC_FLAG"));  //2018.07.09 견적설명회 
            persistent.addParameter(params.get("SITEDESCCHRGPRSNID"));
            persistent.addParameter(params.get("SITEDESCTELNO"));
            persistent.addParameter(params.get("SITEDESCEMAIL"));
            persistent.addParameter(StringUtils.replace(params.get("SITEDESCDATE"),"-",""));
            persistent.addParameter(params.get("SITEDESCDATE_HH"));
            persistent.addParameter(params.get("SITEDESCDATE_MI"));
            persistent.addParameter(params.get("SITEDESCPLACE"));
            System.out.println(params.get("SITEDESC_FLAG"));
            System.out.println(params.get("SITEDESCCHRGPRSNID"));
            System.out.println(params.get("SITEDESCTELNO"));
            System.out.println(params.get("SITEDESCEMAIL"));
            System.out.println(params.get("SITEDESCDATE"));
            System.out.println(params.get("SITEDESCDATE_HH"));
            System.out.println(params.get("SITEDESCDATE_MI"));
            System.out.println(params.get("SITEDESCPLACE"));
            
            persistent.addParameter(params.get("CONTFUL_RATE"));
			persistent.addParameter(params.get("WARR_RATE"));
			persistent.addParameter(params.get("OBC_CONT_TYPE_CD"));
			persistent.addParameter(params.get("OBC_FRST_CONT_RATE"));
			persistent.addParameter(params.get("OBC_FRST_CONDI"));
			persistent.addParameter(params.get("OBC_FRST_CNT_CONDI"));
			persistent.addParameter(params.get("CPC_MID_RATE"));
			persistent.addParameter(params.get("OBC_MID_PAYDAY"));
			persistent.addParameter(params.get("OBC_MID_REQ_MONTH"));
			persistent.addParameter(params.get("OBC_MID_CNT"));
			persistent.addParameter(params.get("OBC_MID_CASH_RATE"));
			persistent.addParameter(params.get("OBC_MID_BILL_RATE"));
			persistent.addParameter(params.get("PBC_REST_RATE"));
			persistent.addParameter(params.get("OBC_FIN_CASH_RATE"));
			persistent.addParameter(params.get("OBC_FIN_BILL_RATE"));
			persistent.addParameter(params.get("OBC_FIN_PAYDAY"));
			persistent.addParameter(params.get("OBC_FIN_CONDI"));
			persistent.addParameter(params.get("CBC_FIRST_RATE"));
			persistent.addParameter(params.get("CBC_DEFECT_DAY"));
			persistent.addParameter(params.get("PAY_CON_RATE"));
			persistent.addParameter(params.get("CBC_DAMAGE_RATE"));
			persistent.addParameter(params.get("CBC_DAMAGE_MAXRATE"));
			persistent.addParameter(params.get("OBC_EMP_RATE"));
			persistent.addParameter(params.get("OBC_EMP_YN"));
			persistent.addParameter(params.get("OBC_PENSION_RATE"));
			persistent.addParameter(params.get("OBC_PENSION_YN"));
			persistent.addParameter(params.get("OBC_HEALTH_RATE"));
			persistent.addParameter(params.get("OBC_HEALTH_YN"));
			persistent.addParameter(params.get("OBC_ELDER_RATE"));
			persistent.addParameter(params.get("OBC_ELDER_YN"));
			persistent.addParameter(params.get("OBC_WORK_RATE"));
			persistent.addParameter(params.get("OBC_WORK_YN"));
			persistent.addParameter(params.get("OBC_RESIGN_RATE"));
			persistent.addParameter(params.get("OBC_RESIGN_YN"));
			persistent.addParameter(params.get("OBC_SAFE_RATE"));
			persistent.addParameter(params.get("OBC_SAFE_YN"));
			persistent.addParameter(params.get("OBC_ENV_RATE"));
			persistent.addParameter(params.get("OBC_ENV_YN"));
			persistent.addParameter(params.get("OBC_SITE_RATE"));
			persistent.addParameter(params.get("OBC_SITE_YN"));
			persistent.addParameter(params.get("OBC_DUTY_RATE"));
			persistent.addParameter(params.get("OBC_DUTY_YN"));
			persistent.addParameter(params.get("OBC_WARR_YN"));
			persistent.addParameter(params.get("OBC_IND_YN"));
			persistent.addParameter(params.get("BID_MASTER_NM")); //2015.12.10 입찰명수정 
			
			persistent.addParameter(StringUtils.replace(params.get("DELI_FROM_DY"),"-",""));  //2016.12.8
            persistent.addParameter(StringUtils.replace(params.get("DELI_TO_DY"),"-",""));
            persistent.addParameter(StringUtils.replace(params.get("DELI_FROM_DY"),"-",""));
            persistent.addParameter(StringUtils.replace(params.get("DELI_TO_DY"),"-",""));
			persistent.addParameter(params.get("REBID_REASON")); //2015.3.3 재입찰사유 mklee
			persistent.addParameter(params.get("REBID_OUTREASON")); //2015-03-17 내부 재입찰 사유 chj
			
			persistent.addParameter(params.get("BID_NO"));
			persistent.addParameter(params.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;
		}
	}
	
	
	/**
     * BID_MASTER  기존 데이터 STATUS UPDATE
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_master_update(Connection connection) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        		sqlstr.append("       UPDATE BID_MASTER				\n");
				sqlstr.append("      SET STATUS_CD = '91' ,UPD_BY = ? ,UPD_DATE = SYSDATE WHERE BID_NO = ? AND BID_DEG = ?			\n");
				persistent.setStatement(sqlstr.toString());
				persistent.addParameter(storage.getUser().get("ACCT_ID"));
				persistent.addParameter(params.get("BID_NO"));
				persistent.addParameter(params.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 bid_item(Connection connection) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
				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("         ,ITEM_NAME 											\n");  //2018.10.31 재견적 내역 
				sqlstr.append("         ,ORD 											\n");
				sqlstr.append("         ,SQ_CORD											\n");
				sqlstr.append("         ,NO_CORD											\n");
				sqlstr.append("         ,CRE_DATE											\n");
				sqlstr.append("         ,CD_SITE, CD_CSTR, DL_CSTR						 	\n"); 
				sqlstr.append("       ) 													\n");
				sqlstr.append("SELECT A.BID_NO										\n");
				sqlstr.append("     , TRIM(TO_CHAR(A.BID_DEG+1,'000'))		\n");
				sqlstr.append("     , A.MATERIAL_CD								\n");
				sqlstr.append("     , A.REQUEST_DATE								\n");
				sqlstr.append("     , A.CONT_UNIT_AMT							\n");
				sqlstr.append("     , A.ACT_UNIT_AMT								\n");
				sqlstr.append("     , A.DEMANDED_PRI								\n");
				sqlstr.append("     , A.DEMANDED_QTY								\n");
				sqlstr.append("     , A.STD 											\n");
				sqlstr.append("     , A.ITEM_NAME 											\n");  //2018.10.31 재견적 내역 
				sqlstr.append("     , A.ORD 											\n");
				sqlstr.append("     , A.SQ_CORD											\n");
				sqlstr.append("     , A.NO_CORD											\n");
				sqlstr.append("     , SYSDATE											\n");
				sqlstr.append("     , A.CD_SITE , A.CD_CSTR ,A.DL_CSTR									\n"); 
				sqlstr.append("  FROM BID_ITEM A 									\n");
				sqlstr.append(" WHERE BID_NO= ?									\n");
				sqlstr.append("       AND BID_DEG= ?								\n");
				persistent.setStatement(sqlstr.toString());
				persistent.addParameter(params.get("BID_NO"));
				persistent.addParameter(params.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 updateData(Connection connection, ValueObject valueObject) throws Exception {
		if(!"1".equals(valueObject.get("CHECK"))){
			return;
		}
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
		        	sqlstr.append("      INSERT INTO BID_SUPP 	\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("               ,CURRENCY_GB	\n");
		        	sqlstr.append("               ,EXCHANGE	\n");
		        	sqlstr.append("               ,DELIVERY_CONDITION	\n");
		        	sqlstr.append("               ,RECM_DEPT_ID	\n");
		        	sqlstr.append("               ,RECM_DEPT_NM	\n");
		        	sqlstr.append("               ,RECM_EMPID	\n");
		        	sqlstr.append("               ,RECOMMEND_REASON	\n");
		        	//sqlstr.append("               ,SITEPARTI_YN	\n");  2018.07.06 재입찰 현설진행 
		        	//sqlstr.append("               ,SITE_ATTEND_YN	\n");  2018.07.06 재입찰 현설진행 
		        	sqlstr.append("               ,CRE_BY	\n");
		        	sqlstr.append("               ,CRE_DATE	\n");
		        	sqlstr.append("             ) 	\n");
		        	sqlstr.append("             SELECT A.BID_NO,	\n");
		        	sqlstr.append("             TRIM(TO_CHAR(A.BID_DEG+1,'000'))	,	\n");
		        	sqlstr.append("             A.VENDOR_CD,	\n");
		        	sqlstr.append("             A.VENDOR_NO,	\n");
		        	sqlstr.append("             A.VENDOR_NAME,	\n");
		        	sqlstr.append("             A.REPRE_NO,	\n");
		        	sqlstr.append("             A.CHARGE_NAME,	\n");
		        	sqlstr.append("             A.CHAGE_HP,	\n");
		        	sqlstr.append("             A.CHARGE_EMAIL,	\n");
		        	sqlstr.append("             A.CURRENCY_GB,	\n");
		        	sqlstr.append("             A.EXCHANGE,	\n");
		        	sqlstr.append("             A.DELIVERY_CONDITION,	\n");
		        	sqlstr.append("             A.RECM_DEPT_ID,	\n");
		        	sqlstr.append("             A.RECM_DEPT_NM,	\n");
		        	sqlstr.append("             A.RECM_EMPID,	\n");
		        	sqlstr.append("             A.RECOMMEND_REASON,	\n");
		        	//sqlstr.append("             'Y',	\n");  2018.07.06 재입찰 현설진행 
		        	//sqlstr.append("             'Y',	\n");  2018.07.06 재입찰 현설진행 
		        	sqlstr.append("             ?,	\n");
		        	sqlstr.append("             SYSDATE	\n");
		        	sqlstr.append("        FROM BID_SUPP A	\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(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 saveData(Connection connection, ValueObject valueObject) throws Exception {
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
		        	sqlstr.append("     INSERT INTO BID_SUPP ( BID_NO,BID_DEG,VENDOR_CD,VENDOR_NO,VENDOR_NAME,REPRE_NO,CHARGE_NAME,CHAGE_HP,CHARGE_EMAIL,RECM_DEPT_ID,RECM_DEPT_NM,CRE_BY,CRE_DATE) 	\n"); //2018.07.06 SITEPARTI_YN 재입찰 현설진행 추가
		        	sqlstr.append("     VALUES ( ?, TRIM(TO_CHAR(?+1,'000')), ?, ?, ?, ?, ?, ?, ?, ?, ?,?, SYSDATE  )	 \n");  //2018.07.06 'Y', 
            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("RECM_DEPT_ID"));
            persistent.addParameter(valueObject.get("RECM_DEPT_NM"));
            persistent.addParameter(storage.getUser().get("ACCT_ID"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> saveData() : " + 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(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 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("                ,TRIM(TO_CHAR(?,'000')) 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 HAND_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.getInt("BID_DEG")+1);
            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 saveData2(Connection connection, ValueObject valueObject) throws Exception {
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("     INSERT INTO BID_SUPP ( BID_NO,BID_DEG,VENDOR_CD,VENDOR_NO,VENDOR_NAME,REPRE_NO,CHARGE_NAME,CHAGE_HP,CHARGE_EMAIL,RECM_DEPT_ID,RECM_DEPT_NM,CRE_BY,CRE_DATE) 	\n");//2018.07.06 SITEPARTI_YN,
			sqlstr.append("     VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE  )	\n");	//'Y',2018.07.06		 
			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("RECM_DEPT_ID"));
			persistent.addParameter(valueObject.get("RECM_DEPT_NM"));
			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 updateData2(Connection connection, ValueObject valueObject) throws Exception {
		//if(!"1".equals(valueObject.get("CHECK"))){
		//	return;
		//}2018.07.06 재입찰 대상업체 업데이트 
		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"); 2018.07.06 재입찰 현설진행 
        	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"));  //2018.07.06 재입찰 현설진행 
            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 callTbeSave(Connection connection, ValueObject valueObject) throws Exception {

        CallableStatement cs = null;
        ValueObject rtnVo = new ValueObject();
        String sqlStr = "";
        try {
        	conn.begin();
        	sqlStr = "{call SP_RE_BID_TO_TBE(?, ?, ?, ?)}";
        	
        	//WAFLogger.debug("SQL : " + sqlStr); 
        	
            cs = connection.prepareCall(sqlStr);
            cs.setString(1, valueObject.get("BID_NO"));
            cs.setInt(2, valueObject.getInt("BID_DEG")+1);

            cs.registerOutParameter(3, java.sql.Types.VARCHAR);
            cs.registerOutParameter(4, java.sql.Types.VARCHAR);
            cs.execute();
            
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> callTbeSave() : " + e.getMessage());
            WAFLogger.error("SQL : " + cs.getString(3));
            WAFLogger.error(e);
            throw e;
        }
    }	
	
	/**
	 * 사용자 수정
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_item_delete(Connection connection) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("  DELETE FROM BID_ITEM 									\n");
			sqlstr.append(" WHERE BID_NO= ?									\n");
			sqlstr.append("       AND BID_DEG= ?								\n");
			
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(params.get("BID_NO"));
			persistent.addParameter(params.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 bid_supp_delete(Connection connection) 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");
			
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(params.get("BID_NO"));
			persistent.addParameter(params.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;
		}
	}
	
	/**
     * BID_MASTER 복사
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_master_delete(Connection connection) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
				sqlstr.append("      DELETE   FROM BID_MASTER A				\n");
				sqlstr.append("      WHERE BID_NO = ?				\n");
				sqlstr.append("      AND BID_DEG = ?				\n");
				persistent.setStatement(sqlstr.toString());
				
				persistent.addParameter(params.get("BID_NO"));
				persistent.addParameter(params.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;
        }
    }
	
	/**
	 * BID_MASTER  기존 데이터 STATUS UPDATE
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_master_delete_update(Connection connection) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("       UPDATE BID_MASTER				\n");
			sqlstr.append("      SET STATUS_CD = '06' ,UPD_BY = ? ,UPD_DATE = SYSDATE WHERE BID_NO = ? AND BID_DEG = ?			\n");
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(storage.getUser().get("ACCT_ID"));
			persistent.addParameter(params.get("BID_NO"));
			persistent.addParameter(params.getInt("BID_DEG")-1);
			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_open_report(Connection connection) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        
        try {
        	long ACT_AMT = Long.parseLong(params.get("ACT_AMT").replaceAll(",", ""));
            int bid_deg = Integer.parseInt(params.get("BID_DEG")) + 1;
            String cmpt_cd = params.get("CMPT_CD");
            //외주 개찰 금액제한 조회
        	ValueObject report_pay_grade = report_pay_grade();
        	long step1 = Long.parseLong(report_pay_grade.get("CHG_CODE01"));
        	long step2 = Long.parseLong(report_pay_grade.get("CHG_CODE02"));
        	
        	sqlstr.append("INSERT INTO BID_OPEN_REPORT(BID_NO, BID_DEG, EMP_ID, USER_NAME, GRADE_NAME, DEPART_DEPT_NM, OPEN_NO, CRE_BY, CRE_DATE)	\n");
            sqlstr.append("   SELECT '"+params.get("BID_NO")+"', '"+bid_deg+"' , ACCT_ID, USER_NAME, GRADE_NAME, DEPART_DEPT_NM, DETAILSORTNM, '"+storage.getUser().get("ACCT_ID")+"', SYSDATE		\n");
            sqlstr.append("   	FROM PUB0120T A, EBID_COM911T B		\n");
            sqlstr.append("    WHERE B.BASECD = 'REPORTER_LIST'		\n");
            sqlstr.append("      AND B.CHG_CODE02 = 'OUT'			\n");
            sqlstr.append("      AND A.ACCT_ID = B.DETAILCD			\n");

            if(cmpt_cd.equals("03")){	//수의계약은 팀장전결
            	sqlstr.append("      AND B.DETAILSORTNM < 2				\n");
            }else if( ACT_AMT == 0 ){
        		//0원 또는 STEP2 금액 이상인 경우 개찰 보고자 전체 등록
        	}else if(ACT_AMT <= step1){	//팀장전결
        		sqlstr.append("      AND B.DETAILSORTNM < 2				\n");
        	}else if(ACT_AMT <= step2){	//임원전결
        		sqlstr.append("      AND B.DETAILSORTNM < 3				\n");
        	}

			persistent.setStatement(sqlstr.toString());
			persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> bid_open_report() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 외주 개찰 보고자 전결규정 금액 한도를 조회한다.
	 * @param rightID
	 * @return
	 */
	public ValueObject report_pay_grade() {
        
		Search search = new SearchImpl();
		ValueObject valueobject = null;
		RowSet rowSet = new RowSetImpl();
		StrBuffer sqlstr = new StrBuffer();
        try {
        	
        	sqlstr.append(" SELECT CHG_CODE01, CHG_CODE02 FROM EBID_COM911T WHERE BASECD = 'REPORTER_PAY_GRADE' AND DETAILCD = 'OUT_STEP'  ");
			search.setStatement(sqlstr.toString());
            rowSet = search.execute();
            if( rowSet != null && rowSet.size() > 0 ){
            	valueobject = RowSetUtility.getValueObject(rowSet.getRow(0));
            }
        }
        catch (WAFSQLException se) {
            super.doException(se);
            this.storage.setSuccess(false);  
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        return valueobject;
    }
	
	/**
	 * 보고자 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void bid_open_report_delete(Connection connection) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("  DELETE FROM BID_OPEN_REPORT				\n");
			sqlstr.append("   WHERE BID_NO= ?							\n");
			sqlstr.append("     AND BID_DEG= ?							\n");
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(params.get("BID_NO"));
			persistent.addParameter(params.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;
		}
	}	
}