/**
 * @(#)file    TermsAgreeBiz.java
 * @(#)author  이성민
 * @(#)version 1.0
 *
 */
package kr.co.udapsoft.ebid.supplier.portal.result.biz;



import java.io.File;
import java.sql.Connection;

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 kr.co.udapsoft.common.util.Crosscert;
import m2soft.ers.invoker.InvokerException;
import m2soft.ers.invoker.http.ReportingServerInvoker;
import oracle.toplink.internal.ox.StrBuffer;

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





public class ResultDetail03SaveBiz extends Biz {

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

	/* (non-Javadoc)
	 * @see kr.co.hwenc.system.Biz#doBiz()
	 */
	public void doBiz() throws Exception 
	{
	    //System.out.println(":::::::::::::::::::::::::::::::::::::::::::::::::::::::ResultDetail03SaveBiz 내부::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
	    
	    if(storage.compareEvent("SAVE_LIST"))
        {
            boolean success = false;
            boolean success2 = true;
            String[] status = super.gets("sheet1.STATUS");
            
            try 
            {
                super.conn.begin();
                
                success = save_data(params); 
                
                for (int i = 0; i < status.length; i++) 
                {
                    //System.out.println(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                    if (IBSheet7Utils.equalStatusInsert(status[i])) 
                    {
                        success2 = save_sheet(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                    }
                }
                
                if(success2 == false) conn.setRollback();
                
                //System.out.println(success);
                
                
                super.storage.setSuccess(success);
                storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
                
            } catch (Exception e) {
                //System.out.println("save_data e======>" + e);
                e.printStackTrace();
                conn.setRollback();
            } finally {
                conn.end();
            }
            
        }
	    else if(storage.compareEvent("UPDATE_DATA"))
	    {
            boolean success = false;
            boolean success2 = true;
            String[] status = super.gets("sheet1.STATUS");
            System.out.println("update_data");
            try 
            {
                conn.begin();
                
                success = update_data(params); 
                
                for (int i = 0; i < status.length; i++) 
                {
                    if (IBSheet7Utils.equalStatusInsert(status[i])) 
                    {
                        success2 = save_sheet(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                    }
                    else if (IBSheet7Utils.equalStatusUpdate(status[i])) 
                    {
                        success2 = update_sheet(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                    }
                    else if (IBSheet7Utils.equalStatusDelete(status[i])) 
                    {
                        success2 = delete_sheet(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                    }
                }
                
                if(success2 == false) conn.setRollback();
                
                super.storage.setSuccess(success);
                storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
                
            } catch (Exception e) {
                //System.out.println("update_data e======>" + e);
                e.printStackTrace();
                conn.setRollback();
            } finally {
                conn.end();
            }
	    }
	    else if(storage.compareEvent("UPDATE_ISSUE"))
        {
            boolean success = false;
            boolean success2 = true;
            
            String[] status = super.gets("sheet1.STATUS");
            
            try 
            {
                conn.begin();
                
                success = update_data(params); 
                
                success = update_issue(params); 
                
                for (int i = 0; i < status.length; i++) 
                {
                    if (IBSheet7Utils.equalStatusInsert(status[i])) 
                    {
                        success2 = save_sheet(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                    }
                    else if (IBSheet7Utils.equalStatusUpdate(status[i])) 
                    {
                        success2 = update_sheet(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                    }
                    else if (IBSheet7Utils.equalStatusDelete(status[i])) 
                    {
                        success2 = delete_sheet(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                    }
                }
                
                if(success2 == false) conn.setRollback();
                
                
                super.storage.setSuccess(success);
                storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
                
                
                //System.out.println(success);
                
            } catch (Exception e) {
                //System.out.println("UPDATE_ISSUE e======>" + e);
                e.printStackTrace();
                conn.setRollback();
            } finally {
                
//                test();
                conn.end();
            }
            
            
            if(success == true)
            {
                String message = "등록성공";
                ValueObject errMsg = new ValueObject();
                errMsg.set("errMsg", message);
                storage.addValueObject("VALUEOBJECT", errMsg);
            }
            
            super.storage.setSuccess(success);
        }else if(storage.compareEvent("SIGN_OK")){
        
        	
            boolean success = false;
            
            try //저장
            {
                conn.begin();
                
                success = update_data(params); 
                
            } catch (Exception e) {
                //System.out.println("update_data e======>" + e);
                e.printStackTrace();
                conn.setRollback();
            } finally {
                conn.end();
            }
            
            updateSheet();
            success=sign();
            super.storage.setSuccess(success);
            storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
		}
    }
	
	public boolean sign() {
        try {
            conn.begin();
        	Crosscert Crosscert = new Crosscert();
           	String result = Crosscert.chkSignVerify(params.get("CONT_SIGNDATA"));//서명 인증 실시
        	if(result.equals("SIGN_SUCCESS")){//성공시 저장
        			CONT_SignOk(params);
            	}else{//실패시 에러
            		throw new Exception("서명검증에 실패하였습니다.");
            	}
            return true;
        }
        catch(Exception e) {
        	storage.addObject("ibsheet7Data", IBSheet7Utils.exceptionHandle(storage.request, e));
            WAFLogger.error(this.getClass().getName() + " --> save() : " + e.getMessage());
            WAFLogger.error(e);
            conn.setRollback();

            storage.setDetailMessage(e);
            return false;
        }
        finally {
            conn.end();
        }
    }
	
	public boolean updateSheet() {
        try {
            conn.begin();
            
            String[] status = super.gets("sheet1.STATUS");
            boolean success2 = true;
            
            for (int i = 0; i < status.length; i++) 
            {
                if (IBSheet7Utils.equalStatusInsert(status[i])) 
                {
                    success2 = save_sheet(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                }
                else if (IBSheet7Utils.equalStatusUpdate(status[i])) 
                {
                    success2 = update_sheet(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                }
                else if (IBSheet7Utils.equalStatusDelete(status[i])) 
                {
                    success2 = delete_sheet(IBSheet7Utils.getIBSheet7SqlParams("SHEET1", params, i));
                }
            }
            
            if(success2 == false) conn.setRollback();
            
            return true;
        }
        catch(Exception e) {
        	storage.addObject("ibsheet7Data", IBSheet7Utils.exceptionHandle(storage.request, e));
            WAFLogger.error(this.getClass().getName() + " --> save() : " + e.getMessage());
            WAFLogger.error(e);
            conn.setRollback();

            storage.setDetailMessage(e);
            return false;
        }
        finally {
            conn.end();
        }
    }
	
	private boolean save_data(ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            
            persistent = new PersistentImpl(super.conn.getConnection());
            
    sqlstr.append("             INSERT INTO RESULT_PLOOF_INFO                   \n")
            .append("               (                                               \n")
            .append("                   SUB_CONT_MOD_ID                \n")
            .append("                 , ACMP_YYYY                \n")
            .append("                 , SOC_CD                \n")
            .append("                 , DEPT_CD                \n")
            .append("                 , DEPT_NM                \n")
            .append("                 , ISSUE_NO                \n")
            .append("                 , ISU_VENDCD                \n")
            .append("                 , ISU_VENDNM                \n")
            .append("                 , ISU_PRES_NM                \n")
            .append("                 , ISU_ADDR                \n")
            .append("                 , ISU_PHONE                \n")
            .append("                 , REG_NO                \n")
            .append("                 , CONT_NM                \n")
            .append("                 , WORK_PLACE                \n")
            .append("                 , WORK_KIND                \n")
            .append("                 , LIC_NM                \n")
            .append("                 , LIC_ORG                \n")
            .append("                 , LIC_DATE                \n")
            .append("                 , CONT_CDATE                \n")
            .append("                 , CONT_SDATE                \n")
            .append("                 , CONT_EDATE                \n")
            .append("                 , CONT_LOC_NO                \n")
            .append("                 , ORD_NM                \n")
            .append("                 , ORI_CONT_NM                \n")
            .append("                 , CONT_WAY_NM                \n")
            .append("                 , CONT_KIND                \n")
            .append("                 , SUB_COMP_NM                \n")
            .append("                 , SUB_COMP_NO                \n")
            .append("                 , ENTRY_NO                \n")
            .append("                 , ETC                \n")
            .append("                 , CONT_TAMT                \n")
            .append("                 , CUR_CONT_AMT                \n")
            .append("                 , CUR_PAY_AMT                \n")
            .append("                 , CUR_PAY_SAMT                \n")
            .append("                 , CUR_PAY_NAMT                \n")
            .append("                 , CUR_CONT_AAMT                \n")
            .append("                 , PRV_PAY_AMT                \n")
            .append("                 , PRV_PAY_SAMT                \n")
            .append("                 , PRV_PAY_NAMT                \n")
            .append("                 , PRV_TRANS_AMT                \n")
            .append("                 , SUB_AMT                \n")
            .append("                 , GOV_MA_AMT                \n")
            .append("                 , OTHER_PAY_AMT                \n")
            .append("                 , REG_VENDNM                \n")
            .append("                 , REG_CORP_NO                \n")
            .append("                 , REG_PRES_NM                \n")
            .append("                 , REG_ADDR                \n")
            .append("                 , REG_PHONE                \n")
            .append("                 , ISU_CHARGE_NM                \n")
            .append("                 , ISU_REQ_HP1                \n")
            .append("                 , ISU_REQ_HP2                \n")
            .append("                 , ISU_REQ_HP3                \n")
            .append("                 , PROG_STAT_CD                \n")
            .append("                 , CORP_ID                \n")
            .append("                 , CON_AMT                \n")
            .append("                 , COMPOSIT_YN                                          \n")
            .append("                 , CONT_TAMT_O                                          \n")
            .append("                 , PRV_PAY_AMT_O                                          \n")
            .append("                 , CUR_PAY_AMT_O                                          \n")
            .append("                 , CUR_PAY_NAMT_O                                          \n")
            .append("                 , UPD_DATE                                          \n")
            .append("                 , ADD_01                                          \n")
            .append("                 , ADD_02                                          \n")
            .append("                 , CONT_TYPE                                          \n")
            .append("                 , MAIN_FIELD                                          \n")
            .append("               )VALUES(                            \n")
            .append("                    ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  SYSDATE                                 \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("                 ,  ?                                       \n")
            .append("               )                                            \n");
            
            
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("p_sub_cont_mod_id").trim());
            persistent.addParameter(params.get("p_acmp_yyyy").trim());
            persistent.addParameter(params.get("p_soc_cd").trim());
            persistent.addParameter(params.get("dept_cd").trim());
            persistent.addParameter(params.get("dept_nm").trim());
            persistent.addParameter(params.get("issue_no").trim());
            persistent.addParameter(params.get("isu_vendcd").trim());
            persistent.addParameter(params.get("isu_vendnm").trim());
            persistent.addParameter(params.get("isu_pres_nm").trim());
            persistent.addParameter(params.get("isu_addr").trim());
            persistent.addParameter(params.get("isu_phone").trim());
            persistent.addParameter(params.get("reg_no").trim());
            persistent.addParameter(params.get("cont_nm").trim());
            persistent.addParameter(params.get("work_place").trim());
            persistent.addParameter(params.get("work_kind").trim());
            persistent.addParameter(params.get("lic_nm").trim());
            persistent.addParameter(params.get("lic_org").trim());
            persistent.addParameter(params.get("lic_date").trim().replace("-", ""));
            persistent.addParameter(params.get("cont_cdate").trim().replace("-", ""));
            persistent.addParameter(params.get("cont_sdate").trim().replace("-", ""));
            persistent.addParameter(params.get("cont_edate").trim().replace("-", ""));
            persistent.addParameter(params.get("cont_loc_no").trim());
            persistent.addParameter(params.get("ord_nm").trim());
            persistent.addParameter(params.get("ori_cont_nm").trim());
            persistent.addParameter(params.get("cont_way_nm").trim());
            persistent.addParameter(params.get("cont_kind").trim());
            persistent.addParameter(params.get("sub_comp_nm").trim());
            persistent.addParameter(params.get("sub_comp_no").trim());
            persistent.addParameter(params.get("entry_no").trim());
            persistent.addParameter(params.get("etc").trim());
            persistent.addParameter(params.get("cont_tamt").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_cont_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_pay_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_pay_samt").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_pay_namt").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_cont_aamt").trim().replace(",", ""));
            persistent.addParameter(params.get("prv_pay_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("prv_pay_samt").trim().replace(",", ""));
            persistent.addParameter(params.get("prv_pay_namt").trim().replace(",", ""));
            persistent.addParameter(params.get("prv_trans_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("sub_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("gov_ma_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("other_pay_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("reg_vendnm").trim());
            persistent.addParameter(params.get("reg_corp_no").trim());
            persistent.addParameter(params.get("reg_pres_nm").trim());
            persistent.addParameter(params.get("reg_addr").trim());
            persistent.addParameter(params.get("reg_phone").trim());
            persistent.addParameter(params.get("isu_charge_nm").trim());
            persistent.addParameter(params.get("isu_req_hp1").trim());
            persistent.addParameter(params.get("isu_req_hp2").trim());
            persistent.addParameter(params.get("isu_req_hp3").trim());
            persistent.addParameter(params.get("prog_stat_cd").trim());
            persistent.addParameter(params.get("p_corp_id").trim());
            persistent.addParameter(params.get("con_amt").trim());
            persistent.addParameter(params.get("COMPOSIT_YN").trim());
            
            persistent.addParameter(params.get("cont_tamt_o").trim().replace(",", ""));
            persistent.addParameter(params.get("prv_pay_amt_o").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_pay_amt_o").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_pay_namt_o").trim().replace(",", ""));
            persistent.addParameter(params.get("ADD_01").trim());
            persistent.addParameter(params.get("ADD_02").trim());
            persistent.addParameter(params.get("cont_type").trim());
            persistent.addParameter(params.get("main_field").trim());
            
            
            //System.out.println(persistent.getParameters());
            //System.out.println(sqlstr.toString() );
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
            //System.out.println("e===>" +e);
            e.printStackTrace();
            return false;            
        }
    }
	
	
	private boolean update_data(ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            
            persistent = new PersistentImpl(super.conn.getConnection());
            
    sqlstr.append("             UPDATE RESULT_PLOOF_INFO SET                  \n")
            .append("                   ISSUE_NO  = ?              \n")
            .append("                 , LIC_ORG   = ?                    \n")
            .append("                 , LIC_DATE   = ?         \n")
            .append("                 , LIC_NM  = ?                  \n")
            .append("                 , REG_NO   = ?                  \n")
            .append("                 , CUR_CONT_AMT   = ?                  \n")
            .append("                 , CONT_TAMT   = ?                  \n")
            .append("                 , CUR_PAY_AMT   = ?                  \n")
            .append("                 , PRV_PAY_AMT   = ?                  \n")
            .append("                 , CUR_PAY_SAMT   = ?                  \n")
            .append("                 , PRV_PAY_SAMT   = ?                  \n")
            .append("                 , ETC  = ?                    \n")
            .append("                 , ISU_CHARGE_NM  = ?       \n")
            .append("                 , ISU_REQ_HP1    = ?                      \n")
            .append("                 , ISU_REQ_HP2    = ?                      \n")
            .append("                 , ISU_REQ_HP3    = ?                      \n")
            .append("                 , WORK_KIND  = ?                                           \n")
            .append("                 , CONT_LOC_NO  = ?                                           \n")
            .append("                 , WORK_PLACE  = ?                                           \n")
            .append("                 , ORD_NM  = ?                                           \n")
            .append("                 , ORI_CONT_NM  = ?                                           \n")
            .append("                 , CONT_WAY_NM  = ?                                           \n")
            .append("                 , CONT_KIND  = ?                                           \n")
            .append("                 , SUB_COMP_NM  = ?                                           \n")
            .append("                 , SUB_COMP_NO  = ?                                           \n")
            .append("                 , SUB_AMT  = ?                                           \n")
            .append("                 , ENTRY_NO  = ?                                           \n")
            .append("                 , OTHER_PAY_AMT  = ?                                           \n")
            .append("                 , CUR_CONT_AAMT  = ?                                           \n")
            .append("                 , PROG_STAT_CD  = ?                                           \n")
            .append("                 , COMPOSIT_YN  = ?                                           \n")
            .append("                 , PRV_TRANS_AMT  = ?                                           \n")
            .append("                 , CUR_PAY_NAMT  = ?                                           \n")
            .append("                 , GOV_MA_AMT  = ?                                           \n")
            .append("                 , PRV_PAY_NAMT  = ?                                           \n")
            .append("                 , ISU_ADDR  = ?                                           \n")
            .append("                 , CONT_NM  = ?                                           \n")
            .append("                 , UPD_DATE  = SYSDATE                                           \n")
            .append("                 , ADD_01  = ?                                           \n")
            .append("                 , ADD_02  = ?                                           \n")
            .append("                 , CONT_TYPE  = ?                                           \n")
            .append("                 , MAIN_FIELD  = ?                                           \n")
            .append("                 WHERE CORP_ID = ?                        \n")
            .append("                 AND SUB_CONT_MOD_ID = ?                        \n")
            .append("                 AND ACMP_YYYY = ?                        \n")
            .append("                 AND SOC_CD = ?                        \n");
            
    
            
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("issue_no").trim());
            persistent.addParameter(params.get("lic_org").trim());
            persistent.addParameter(params.get("lic_date").trim().replace("-", ""));
            persistent.addParameter(params.get("lic_nm").trim());
            persistent.addParameter(params.get("reg_no").trim());
            persistent.addParameter(params.get("cur_cont_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("cont_tamt").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_pay_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("prv_pay_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_pay_samt").trim().replace(",", ""));
            persistent.addParameter(params.get("prv_pay_samt").trim().replace(",", ""));
            persistent.addParameter(params.get("etc").trim());
            persistent.addParameter(params.get("isu_charge_nm").trim());
            persistent.addParameter(params.get("isu_req_hp1").trim());
            persistent.addParameter(params.get("isu_req_hp2").trim());
            persistent.addParameter(params.get("isu_req_hp3").trim());
            persistent.addParameter(params.get("work_kind").trim());
            persistent.addParameter(params.get("cont_loc_no").trim());
            persistent.addParameter(params.get("work_place").trim());
            persistent.addParameter(params.get("ord_nm").trim());
            persistent.addParameter(params.get("ori_cont_nm").trim());
            persistent.addParameter(params.get("cont_way_nm").trim());
            persistent.addParameter(params.get("cont_kind").trim());
            persistent.addParameter(params.get("sub_comp_nm").trim());
            persistent.addParameter(params.get("sub_comp_no").trim());
            persistent.addParameter(params.get("sub_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("entry_no").trim().replace(",", ""));
            persistent.addParameter(params.get("other_pay_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_cont_aamt").trim().replace(",", ""));
            persistent.addParameter(params.get("prog_stat_cd").trim());
            persistent.addParameter(params.get("COMPOSIT_YN").trim());
            persistent.addParameter(params.get("prv_trans_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("cur_pay_namt").trim().replace(",", ""));
            persistent.addParameter(params.get("gov_ma_amt").trim().replace(",", ""));
            persistent.addParameter(params.get("prv_pay_namt").trim().replace(",", ""));
            persistent.addParameter(params.get("isu_addr").trim().replace(",", ""));
            persistent.addParameter(params.get("cont_nm").trim().replace(",", ""));
            persistent.addParameter(params.get("ADD_01").trim());
            persistent.addParameter(params.get("ADD_02").trim());
            persistent.addParameter(params.get("CONT_TYPE").trim());
            persistent.addParameter(params.get("MAIN_FIELD").trim());
            
            persistent.addParameter(params.get("p_corp_id").trim());
            persistent.addParameter(params.get("p_sub_cont_mod_id").trim());
            persistent.addParameter(params.get("p_acmp_yyyy").trim());
            persistent.addParameter(params.get("p_soc_cd").trim());
            
            
            
            //System.out.println(persistent.getParameters());
            //System.out.println(sqlstr.toString());
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
            //System.out.println("e===>" +e);
            e.printStackTrace();
            return false;            
        }
    }
	
	
	private boolean update_issue(ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            
            persistent = new PersistentImpl(super.conn.getConnection());
            
    sqlstr.append("             UPDATE RESULT_PLOOF_INFO SET                  \n")
            .append("                   PROG_STAT_CD  = ?              \n")
            .append("                 WHERE CORP_ID = ?                        \n")
            .append("                 AND SUB_CONT_MOD_ID = ?                        \n")
            .append("                 AND ACMP_YYYY = ?                        \n")
            .append("                 AND SOC_CD = ?                        \n");
            
            
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("prog_stat_cd").trim());
            persistent.addParameter(params.get("p_corp_id").trim());
            persistent.addParameter(params.get("p_sub_cont_mod_id").trim());
            persistent.addParameter(params.get("p_acmp_yyyy").trim());
            persistent.addParameter(params.get("p_soc_cd").trim());
            
            
            
            //System.out.println(persistent.getParameters());
            //System.out.println(sqlstr.toString());
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
            //System.out.println("e===>" +e);
            e.printStackTrace();
            return false;            
        }
    }
	
	public void test() throws Exception
	{
	    ReportingServerInvoker invoker = new ReportingServerInvoker("http://211.38.140.244:8090/ReportingServer/service");
	      
	      invoker.setCharacterEncoding("euc-kr"); //캐릭터셋
	      invoker.setReconnectionCount(3);        //재접속 시도 회수
	      invoker.setConnectTimeout(10000);           //커넥션 타임아웃
	      invoker.setReadTimeout(30000);             //송수신 타임아웃

	      
	      invoker.addParameter("opcode", "500");
	      invoker.addParameter("mrd_path", "http://211.38.140.244:8082/report/mrd/buyer/supplier/outside/OutSupplierReport.mrd");
//	       invoker.addParameter("mrd_path", "/report/mrd/buyer/supplier/purchase/PuSupplierReport.mrd");
//	       invoker.addParameter("mrd_path", "http://211.38.140.244:8090/ReportingServer/mrd/qqqq.mrd");
	      invoker.addParameter("mrd_param", "/rp [79] [1] [2014]");
	      
//	       invoker.addParameter("mrd_param", "/rp [79]  [1]  [2014]");
	     
	      invoker.addParameter("export_type", "pdf");
	      invoker.addParameter("export_name","");
	      invoker.addParameter("protocol", "file");
	      
	      try
	      {
	        // 방법 1,2,3 중 한 가지를 선택하여 사용.
	                 // 방법 1 : 파일 경로 전달
//	      invoker.invoke("C:/test.pdf"); 
	        
	        // 방법 2 : 파일 객체 전달
	        invoker.invoke(new File("C:/pdf_test.pdf"));
	        
	        // 방법 3 : 스트림 전달
	        /*
	        InputStream is = null;
	        OutputStream os = null;
	        try
	        {
	           is = invoker.invokeAndGetStream();
	           os = new FileOutputStream(new File("C:/test.pdf"));
	                    
	           byte[] buffer = new byte[102400];
	           int read = -1;
	           while((read = is.read(buffer)) != -1)
	           {
	              os.write(buffer, 0, read);
	           }
	        }
	        finally
	        {
	        try{ if(is != null) is.close(); } catch(IOException ignore){}
	            try{ if(os != null) os.close(); } catch(IOException ignore){}
	                    
	            invoker.disconnect();
	        }
	      */
	      
	      }
	      catch(InvokerException e)
	      {
	         e.printStackTrace();
	         invoker.disconnect();
	      
	      }
	      
	      invoker.disconnect();
	}
	
	
	
	private boolean save_sheet(ValueObject sqlParams) throws Exception {
        Persistent persistent = null;
        StringBuffer sql = new StringBuffer();
        
        
        try {
            
            conn.begin();
            persistent = new PersistentImpl(super.conn.getConnection());
            
            sql.append("    INSERT INTO RESULT_PLOOF_DETAIL          \n ");
            sql.append("    (                                           \n ");
            sql.append("          SEQ                                   \n ");
            sql.append("        , SUB_CONT_MOD_ID                             \n ");
            sql.append("        , ACMP_YYYY                             \n ");
            sql.append("        , SOC_CD                   \n ");
            sql.append("        , CONT_NM                   \n ");
            sql.append("        , CONT_SDATE                   \n ");
            sql.append("        , CONT_EDATE                   \n ");
            sql.append("        , CONT_AMT                   \n ");
            sql.append("        , PRV_PAY_AMT                   \n ");
            sql.append("        , CUR_PAY_AMT                   \n ");
            sql.append("        , SCONT_AMT                   \n ");
            sql.append("        , PAY_NAMT                   \n ");
            sql.append("        , SUB_SOC_CD                   \n ");
            sql.append("        , UPD_DATE                   \n ");
            sql.append("        ) VALUES (                          \n ");
            sql.append("          (SELECT DECODE(MAX(SEQ), '', 1, MAX(SEQ)+1) FROM  RESULT_PLOOF_DETAIL WHERE SUB_CONT_MOD_ID = ? AND SOC_CD = ?  AND ACMP_YYYY = ? )                                   \n ");
            sql.append("         ,?                                      \n ");
            sql.append("         ,?                                      \n ");
            sql.append("         ,?                                      \n ");
            sql.append("         ,?                                      \n ");
            sql.append("        , ?                                   \n ");
            sql.append("        , ?                                   \n ");
            sql.append("        , ?                                   \n ");
            sql.append("        , ?                                   \n ");
            sql.append("        , ?                                   \n ");
            sql.append("        , ?                                   \n ");
            sql.append("        , ?                                   \n ");
            sql.append("        , ?                                   \n ");
            sql.append("        , SYSDATE                                   \n ");
            sql.append("        )                                       \n ");
            
            persistent.setStatement(sql.toString());
            persistent.addParameter(params.get("p_sub_cont_mod_id"));
            persistent.addParameter(params.get("p_soc_cd"));
            persistent.addParameter(params.get("p_acmp_yyyy"));
            persistent.addParameter(params.get("p_sub_cont_mod_id"));
            persistent.addParameter(params.get("p_acmp_yyyy"));
            persistent.addParameter(params.get("p_soc_cd"));
            
            persistent.addParameter(sqlParams.get("cont_nm"));
            persistent.addParameter(sqlParams.get("cont_sdate"));
            persistent.addParameter(sqlParams.get("cont_edate"));
            persistent.addParameter(sqlParams.get("cont_amt"));
            persistent.addParameter(sqlParams.get("prv_pay_amt"));
            persistent.addParameter(sqlParams.get("cur_pay_amt"));
            persistent.addParameter(sqlParams.get("scont_amt"));
            persistent.addParameter(sqlParams.get("pay_namt"));
            persistent.addParameter(sqlParams.get("sub_soc_cd"));
            
            //System.out.println(persistent.getParameters());
            //System.out.println(sql.toString());
            
            
            persistent.execute();
            persistent.clearParameters();
            
            return true;
        } catch(Exception e) {
//          e.printStackTrace();
            WAFLogger.error(this.getClass().getName() + " --> saveData() : " + e.getMessage());
            WAFLogger.error("SQL : " + persistent.toString());
            WAFLogger.error(e);
            conn.setRollback();
            throw e;
            
        }
        
        finally {
            super.conn.end();
        }
    }
	
	
	private boolean update_sheet(ValueObject sqlParams) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            
            persistent = new PersistentImpl(super.conn.getConnection());
            
            sqlstr.append("    UPDATE RESULT_PLOOF_DETAIL SET                  \n")
                   .append("         CONT_NM = ?                   \n ")
                   .append("        , CONT_SDATE = ?                   \n ")
                   .append("        , CONT_EDATE = ?                   \n ")
                   .append("        , CONT_AMT = ?                   \n ")
                   .append("        , PRV_PAY_AMT = ?                   \n ")
                   .append("        , CUR_PAY_AMT = ?                   \n ")
                   .append("        , SCONT_AMT = ?                   \n ")
                   .append("        , PAY_NAMT = ?                   \n ")
                   .append("        , SUB_SOC_CD = ?                   \n ")
                   .append("        , UPD_DATE = SYSDATE                   \n ")
                   .append("    WHERE  SUB_CONT_MOD_ID = ?                        \n")
                   .append("        AND ACMP_YYYY = ?                        \n")
                   .append("        AND SOC_CD = ?                        \n")
                   .append("        AND SEQ = ?                        \n");
            
            
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(sqlParams.get("cont_nm"));
            persistent.addParameter(sqlParams.get("cont_sdate").replace("-", ""));
            persistent.addParameter(sqlParams.get("cont_edate").replace("-", ""));
            persistent.addParameter(sqlParams.get("cont_amt"));
            persistent.addParameter(sqlParams.get("prv_pay_amt"));
            persistent.addParameter(sqlParams.get("cur_pay_amt"));
            persistent.addParameter(sqlParams.get("scont_amt"));
            persistent.addParameter(sqlParams.get("pay_namt"));
            persistent.addParameter(sqlParams.get("sub_soc_cd"));
            
            persistent.addParameter(sqlParams.get("sub_cont_mod_id").trim());
            persistent.addParameter(sqlParams.get("acmp_yyyy").trim());
            persistent.addParameter(sqlParams.get("soc_cd").trim());
            persistent.addParameter(sqlParams.get("seq").trim());
            
            
            
            //System.out.println(persistent.getParameters());
            //System.out.println(sqlstr.toString());
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
            //System.out.println("e===>" +e);
            e.printStackTrace();
            return false;            
        }
    }
	
	private boolean delete_sheet(ValueObject sqlParams) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            
            persistent = new PersistentImpl(super.conn.getConnection());
            
            sqlstr.append("    DELETE FROM  RESULT_PLOOF_DETAIL                   \n")
                   .append("    WHERE  SUB_CONT_MOD_ID = ?                        \n")
                   .append("        AND ACMP_YYYY = ?                        \n")
                   .append("        AND SOC_CD = ?                        \n")
                   .append("        AND SEQ = ?                        \n");
            
            
            persistent.setStatement(sqlstr.toString());
            
            persistent.addParameter(sqlParams.get("sub_cont_mod_id").trim());
            persistent.addParameter(sqlParams.get("acmp_yyyy").trim());
            persistent.addParameter(sqlParams.get("soc_cd").trim());
            persistent.addParameter(sqlParams.get("seq").trim());
            
            
            
            //System.out.println(persistent.getParameters());
            //System.out.println(sqlstr.toString());
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
            //System.out.println("e===>" +e);
            e.printStackTrace();
            return false;            
        }
    }
	
	
	public boolean CONT_SignOk(ValueObject valueObject) throws Exception {
	
        Persistent persistent = new PersistentImpl(super.conn.getConnection());
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("UPDATE RESULT_PLOOF_INFO SET  	\n");
        	sqlstr.append(" SUPP_SIGN_DT = SYSDATE					\n");
        	sqlstr.append(" ,SUPP_SIGN_USER = ?					\n");
        	sqlstr.append(" ,PROG_STAT_CD = ?					\n");
        	sqlstr.append("WHERE SUB_CONT_MOD_ID = ?						\n");
        	sqlstr.append("     AND SOC_CD = ?                        \n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("CONT_SIGNDN"));
            persistent.addParameter("20");
            persistent.addParameter(valueObject.get("P_SUB_CONT_MOD_ID"));
            persistent.addParameter(valueObject.get("p_soc_cd"));
            
            persistent.execute();
            //SUPP_SIGN_HASH
            ClobUtils.setClob( conn.getConnection(), "RESULT_PLOOF_INFO", "SUPP_SIGN_DATA", " WHERE SUB_CONT_MOD_ID = '"+valueObject.get("P_SUB_CONT_MOD_ID")+"' AND SOC_CD = '"+valueObject.get("p_soc_cd")+"'", valueObject.get("CONT_SIGNDATA"));
            
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            WAFLogger.error(sqlstr.toString());
            WAFLogger.error(persistent.getParameters());
            //System.out.println("Exception : " + e.getMessage());
            throw e;
        }
       
    }	
	
}