/**
 * @(#)file    SuppDeptRequestSaveBiz.java
 * @(#)author  mklee
 * @(#)version 1.0
 * @(#)date    2017-02-20
 * @(#)since   JDK 1.4.2
 *
 * Copyright (c) www.hwenc.co.kr, Inc.
 * All rights reserved.
 * This software is the proprietary information of Hanwha E&C, Inc.
 */
package kr.co.udapsoft.ebid.buyer.supplier.outside.biz;

import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import oracle.toplink.internal.ox.StrBuffer;

import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.base.WAFMessages;
import kr.co.hsnc.common.logger.Logger;
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.sender.MessageSend;
import kr.co.udapsoft.common.sender.SmtpAuth;
import kr.co.udapsoft.ebid.buyer.supplier.purchase.biz.SuppJoinRequestListBiz;



import com.udapsoft.waf.common.util.StringUtils;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;


public class SuppDeptRequestSaveBiz extends Biz {

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

	public void doBiz() throws Exception {

		try 
        {
			super.conn.begin();
			if(storage.compareEvent(""))
			{
			}
			else if(storage.compareEvent("SAVE_DATA"))  //신규 
	        {
				saveData(super.conn.getConnection()); 
	        }
			else if(storage.compareEvent("UPDATE_DATA")) //업데이트 
	        {
				updateData(super.conn.getConnection()); 
			}
			else if(storage.compareEvent("DELETE_DATA")) //삭제 
	        {
			     deleteData(super.conn.getConnection());
			}else if(storage.compareEvent("DATA_APP")) //승인
	        {
				updateApp(super.conn.getConnection());
			}else if(storage.compareEvent("DATA_REJECT")) //반려
		    {
				boolean success = update_app_sub(super.conn.getConnection(), params);
				if (success == true){
					String message = "등록성공";
		            ValueObject errMsg = new ValueObject();
		            errMsg.set("errMsg", message);
		            storage.addValueObject("VALUEOBJECT", errMsg);	  
				}else{
					String message = "등록실패";
		            ValueObject errMsg = new ValueObject();
		            errMsg.set("errMsg", message);
		            storage.addValueObject("VALUEOBJECT", errMsg);	  
				}
				storage.setSuccess(success);
			}else if(storage.compareEvent("CHK_APPVAR")) //결재체크 
		    {
				storage.addValueObject("VALUEOBJECT", getCheck());
	    		storage.setSuccess(true);	
		    }
        }catch (Exception e) {
        	System.out.println(e.getMessage());
            WAFLogger.error(e);
            e.printStackTrace();
            super.conn.setRollback();
            throw new Exception(e);            
        }finally{
        	super.conn.close();
        }
    }
	
	
	private void saveData(Connection conn) throws Exception{

	    boolean success = false;
	    
	    try 
        {
            String yyyymmdd = (new java.text.SimpleDateFormat ("yyyyMMdd")).format (new java.util.Date());
            params.set("user_id", yyyymmdd);
            
            String corp_no = params.get("corp_reg_no").replace("-", "");
            String corp_gubun = "";
            
            corp_no = corp_no.substring(3, 5);
            
            if(corp_no.equals("81") || corp_no.equals("82") || corp_no.equals("83") ||corp_no.equals("84") || corp_no.equals("85") || corp_no.equals("86") || corp_no.equals("87") || corp_no.equals("88"))
            {
                corp_gubun = "1";
            }
            else
            {
                corp_gubun = "2";
            }
            params.set("corp_gubun", corp_gubun); 
            
            ValueObject corp_id = getCorp_no(conn); 
            
            if(!corp_id.get("cnt").equals("0"))
            {
                String message = "이미 등록된 사업자 번호 입니다.";
                Exception e = new Exception(message);

                ValueObject errMsg = new ValueObject();
                errMsg.set("errMsg", message);
                storage.addValueObject("VALUEOBJECT", errMsg);
                super.storage.setSuccess(false);
                throw e;
            }
            else
            {
                try 
                {
                    success = save_info(conn, params);  
                } catch (Exception e) {
                    e.printStackTrace();
                }
                
                
                if(success == true )
                {
                    String message = "등록성공";
                    ValueObject errMsg = new ValueObject();
                    errMsg.set("errMsg", message);
                    storage.addValueObject("VALUEOBJECT", errMsg);
                    
                    super.storage.setSuccess(success);
                }
                else
                {
                    String message = "등록실패";
                    Exception e = new Exception(message);
                    
                    ValueObject errMsg = new ValueObject();
                    errMsg.set("errMsg", message);
                    storage.addValueObject("VALUEOBJECT", errMsg);
                    
                    super.storage.setSuccess(false);
                    throw e;
                }
            }
            
        } catch (Exception e) {
            WAFLogger.error(e);
            e.printStackTrace();
            throw new Exception(e);            
        }  
	}
	
	private void updateData(Connection conn) throws Exception{
	 
	    boolean success = false;
        
	    String corp_no = params.get("corp_reg_no").replace("-", "");
        String corp_gubun = "";
        
        corp_no = corp_no.substring(3, 5);
        
        if(corp_no.equals("81") || corp_no.equals("82") || corp_no.equals("83") ||corp_no.equals("84") || corp_no.equals("85") || corp_no.equals("86") || corp_no.equals("87")|| corp_no.equals("88"))
        {
            corp_gubun = "1";
        }
        else
        {
            corp_gubun = "2";
        }
        
        params.set("corp_gubun", corp_gubun); 
        
        try {
        	success = update_info(conn, params);//CON.BEGIN
			
        	if(success == true )
            {
                String message = "등록성공";
                ValueObject errMsg = new ValueObject();
                errMsg.set("errMsg", message);
                storage.addValueObject("VALUEOBJECT", errMsg);
                
                super.storage.setSuccess(success);
            }
            else
            {
                String message = "등록실패";
                Exception e = new Exception(message);
                
                ValueObject errMsg = new ValueObject();
                errMsg.set("errMsg", message);
                storage.addValueObject("VALUEOBJECT", errMsg);
                
                super.storage.setSuccess(false);
                throw e;
            }
		} catch (Exception e1) {
			String message = "등록실패";
			Exception e = new Exception(message);
			storage.setMessage(message.replace("\"", ""));
			storage.setSuccess(false);
			throw new Exception(e);
	    } 
	}
	
	private void updateApp(Connection conn) throws Exception{

	    boolean success1 = false;
	    boolean success2 = false;
	    boolean success3 = false;
        
        try {
        	String message = "등록성공";
            ValueObject errMsg = new ValueObject();
            
            //동일한 사업자번호 있는지 확인
            ValueObject corp_id_r = getCorp_no_r(conn); 
            
            if(!corp_id_r.get("cnt").equals("0"))
            {
                message = "이미 등록된 사업자 번호 입니다.";
                Exception e = new Exception(message);

                errMsg.set("errMsg", message);
                storage.addValueObject("VALUEOBJECT", errMsg);
                storage.setMessage(message);
                super.storage.setSuccess(false); 
                throw e;
            }
            
            String corp_id = getCorp_id(conn); 
		       
		    params.set("corp_id_r", corp_id);
        	success1 = update_app_sub(conn, params); 
        	success2 = insert_info(conn, params); 
        	success3 = insert_charge(conn, params); 
        	
        	if (success1 == true && success2 == true && success3 == true) {
        		message = "등록성공";
                errMsg.set("errMsg", message);
                storage.addValueObject("VALUEOBJECT", errMsg);
        	    storage.setSuccess(true);
        	}else{
        		message =  "등록실패" ;
        		Exception e = new Exception(message);
                errMsg.set("errMsg", message);
                storage.addValueObject("VALUEOBJECT", errMsg);
                storage.setMessage(message);
                storage.setSuccess(false);
                throw e;
        	}       	
			
		} catch (Exception e1) {
			ValueObject errMsg = new ValueObject();
			errMsg.set("errMsg", e1.getMessage());
			storage.addValueObject("VALUEOBJECT", errMsg);
			storage.setSuccess(false);
			throw new Exception(e1);
	    }  
	}
	
    public String getCorp_id(Connection conn) throws Exception{
        
        Persistent persistent_q = null;
        
        ValueObject row = null;
        StringBuffer sqlstr =  new StringBuffer();
        
        try{
            persistent_q = new PersistentImpl(conn);
            
            sqlstr.append("         SELECT SUPP_INFO_S.NEXTVAL AS SEQ                                \n");
            sqlstr.append("           FROM DUAL                                                  \n");
            
            persistent_q.setStatement(sqlstr.toString()); 
            row = RowSetUtility.getValueObject(persistent_q.query().getRow(0));
            
        }   
        catch(Exception e) {
            e.printStackTrace();
        } 
        return row.get("SEQ");
    }
    
	private boolean update_app_sub(Connection conn, ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            
            persistent = new PersistentImpl(conn);
            
            
            sqlstr.append("     UPDATE SUPP_INFO_REQ SET                          \n")
                   .append("          STATUS = ?                                  \n")
                   .append("         ,REJECT_REASON = ?                           \n")  
                   .append("         ,APP_EMP     = ?                             \n")
                   .append("         ,CORP_ID_R     = ?                             \n")
                   .append("         ,UPD_DATE   = TO_CHAR(SYSDATE, 'YYYY-MM-DD') \n")
                   .append("     WHERE CORP_ID = ?                                \n");
            
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("p_status").trim());
            persistent.addParameter(params.get("REJECT_REASON").trim());
            persistent.addParameter(storage.getUser().get("acct_id").trim());
            persistent.addParameter(params.get("corp_id_r").trim());
            persistent.addParameter(params.get("p_corp_id").trim());
            
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
        	WAFLogger.error("update_info====>" + e);
            e.printStackTrace();
            return false;            
        }
    }
	
	private boolean insert_info(Connection conn, ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            persistent = new PersistentImpl(conn);
            
            sqlstr.append("     INSERT INTO SUPP_INFO                       \n")
                   .append("     (                                          \n")
                   .append("          CORP_ID                               \n")
                   .append("         ,JOB_DIV --P:구매. O:외주                               \n")
                   .append("         ,IN_OUT_DIV --I:국내, O:국외                         \n")
                   .append("         ,CORP_REG_NO                           \n")
                   .append("         ,CORP_KOR                              \n")
                   .append("         ,REP_NAME                              \n")
                   .append("         ,CORP_DIV_CD                           \n")
                   .append("         ,STATUS                                \n")
                   .append("         ,CRE_BY                                \n")
                   .append("         ,CRE_DATE                              \n")
                   .append("     )SELECT                                    \n")
                   .append("          ?                                     \n")
                   .append("         ,JOB_DIV --P:구매. O:외주                               \n")
                   .append("         ,IN_OUT_DIV --I:국내, O:국외                         \n")
                   .append("         ,CORP_REG_NO                           \n")
                   .append("         ,CORP_KOR                              \n")
                   .append("         ,REP_NAME                              \n")
                   .append("         ,CORP_DIV_CD                           \n")
                   .append("         ,'AA'                                  \n")
                   .append("         ,CRE_BY                                \n")
                   .append("         ,SYSDATE                               \n")
                   .append("     FROM SUPP_INFO_REQ                         \n")
                   .append("     WHERE CORP_ID = ?                          \n");
            
            
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("corp_id_r"));
            persistent.addParameter(params.get("p_corp_id"));
            
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
        	WAFLogger.error("save_info========>" + e);
            e.printStackTrace();
            return false;            
        }
    }
	
	private boolean insert_charge(Connection conn, ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            
            persistent = new PersistentImpl(conn);
            
            
            sqlstr.append("                                               \n")
                   .append("         INSERT INTO SUPP_CHARGE              \n")
                   .append("         (                                    \n")
                   .append("             CHARGE_SEQ                       \n")
                   .append("            ,CORP_ID                          \n")
                   .append("            ,USER_ID                          \n")
                   .append("            ,DEFAULT_YN -- Y                  \n")
                   .append("            ,USER_NAME                        \n")
                   .append("            ,HP1                              \n")
                   .append("            ,HP2                              \n")
                   .append("            ,HP3                              \n") 
                   .append("            ,EMAIL                            \n")
                   .append("            ,USE_YN                           \n")
                   .append("            ,RIGHT_ID                         \n")
                   .append("            ,CRE_BY                           \n")
                   .append("            ,CRE_DATE                         \n")
                   .append("         )SELECT                              \n")
                   .append("            (SELECT DECODE(COUNT(CHARGE_SEQ), 0, 1, MAX(CHARGE_SEQ)+1)  SEQ FROM SUPP_CHARGE WHERE CORP_ID = ?  ) \n")
                   .append("            ,?                                \n")
                   .append("            ,TO_CHAR(SYSDATE, 'YYYYMMDD') || ?                                                                   \n")
                   .append("            ,'Y'                              \n")
                   .append("            ,USER_NAME                        \n")
                   .append("            ,HP1                              \n")
                   .append("            ,HP2                              \n")
                   .append("            ,HP3                              \n") 
                   .append("            ,EMAIL                            \n")
                   .append("            ,''                               \n")
                   .append("            ,'159'                            \n")
                   .append("            ,?                                \n")
                   .append("            ,TO_CHAR(SYSDATE, 'YYYY-MM-DD')   \n")
                   .append("        FROM SUPP_INFO_REQ                    \n")
                   .append("       WHERE CORP_ID = ?                      \n");
            
            
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("p_corp_id"));
            persistent.addParameter(params.get("corp_id_r"));
            persistent.addParameter("_" +  params.get("p_corp_id"));
            persistent.addParameter(storage.getUser().get("acct_id"));
            persistent.addParameter(params.get("p_corp_id"));
            
            
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
        	WAFLogger.error("save_charge======>" + e);
            e.printStackTrace();
            return false;
        }
    }
	
	private void deleteData(Connection conn) throws Exception{
		boolean success = false;
 
	    try {
			success = delete_info(conn, params); 
			if(success == true )
            {
                String message = "성공";
                ValueObject errMsg = new ValueObject();
                errMsg.set("errMsg", message);
                storage.addValueObject("VALUEOBJECT", errMsg);
                
                super.storage.setSuccess(success);
            }
            else
            {
                String message = "실패";
                Exception e = new Exception(message);
                
                ValueObject errMsg = new ValueObject();
                errMsg.set("errMsg", message);
                storage.addValueObject("VALUEOBJECT", errMsg);
                
                super.storage.setSuccess(false);
                throw e;
            }
		 
		} catch (Exception e1) {
			ValueObject errMsg = new ValueObject();
			errMsg.set("errMsg", e1.getMessage());
			storage.addValueObject("VALUEOBJECT", errMsg);
			
			storage.setSuccess(false);
			
			throw new Exception(e1);
		}
	}
	
	/**
	 * 협력업체 마스터 저장
	 * @param params
	 * @return
	 * @throws Exception
	 */
	private boolean save_info(Connection conn, ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        try{
            persistent = new PersistentImpl(conn);
            
            sqlstr.append("     INSERT INTO SUPP_INFO_REQ               \n")
                   .append("     (                                      \n")
                   .append("          CORP_ID                           \n")
                   .append("         ,JOB_DIV --P:구매. O:외주                       \n")
                   .append("         ,IN_OUT_DIV --I:국내, O:국외                 \n")
                   .append("         ,CORP_REG_NO                       \n")
                   .append("         ,CORP_KOR                          \n")
                   .append("         ,REP_NAME                          \n")
                   .append("         ,CORP_DIV_CD                       \n")
                   .append("         ,STATUS                            \n")
                   .append("         ,USER_NAME                         \n")
                   .append("         ,HP1                               \n")
                   .append("         ,HP2                               \n")
                   .append("         ,HP3                               \n")
                   .append("         ,EMAIL                             \n")
                   .append("         ,REQ_DATE                          \n")
                   .append("         ,REQ_EMP                           \n")
                   .append("         ,DEPT_CD                           \n")
                   .append("         ,DEPT_NM                           \n")
                   .append("         ,REQ_REMARK                        \n")
                   .append("         ,CRE_BY                            \n")
                   .append("         ,CRE_DATE                          \n")
                   .append("         ,CREDIT_CD                         \n")
                   .append("         ,CREDIT_VALUE                      \n")
                   .append("         ,SYEAR                             \n")
                   .append("         ,DEBT_AMT                          \n")
                   .append("         ,CAPITAL_AMT                       \n")
                   .append("         ,DEBT_RATE                         \n")
                   .append("         ,LIQUID_ASSET                      \n")
                   .append("         ,LIQUID_DEBT                       \n")
                   .append("         ,LIQUID_RATE                       \n")
                   .append("         ,LICENCE_YN                        \n")
                   .append("         ,ETC_YN                            \n") 
                   .append("         ,CASH_GRADE                        \n")
                   .append("     )VALUES(                               \n")
                   .append("          ?                                        \n")   //CORP_ID    
                   .append("         ,?                                        \n")   //JOB_DIV 
                   .append("         ,?                                        \n")   //IN_OUT_DIV 
                   .append("         ,?                                        \n")   //CORP_REG_NO
                   .append("         ,?                                        \n")   //CORP_KOR   
                   .append("         ,?                                        \n")   //REP_NAME   
                   .append("         ,?                                        \n")   //CORP_DIV_CD
                   .append("         ,?                                        \n")   //STATUS     
                   .append("         ,?                                        \n")   //USER_NAME  
                   .append("         ,?                                        \n")   //HP1        
                   .append("         ,?                                        \n")   //HP2        
                   .append("         ,?                                        \n")   //HP3        
                   .append("         ,?                                        \n")   //EMAIL      
                   .append("         ,TO_CHAR(SYSDATE, 'YYYY-MM-DD')           \n")   //REQ_DATE   
                   .append("         ,?                                        \n")   //REQ_EMP    
                   .append("         ,?                                        \n")   //DEPT_CD    
                   .append("         ,?                                        \n")   //DEPT_NM    
                   .append("         ,?                                        \n")   //REQ_REMARK 
                   .append("         ,?                                        \n")   //CRE_BY     
                   .append("         ,SYSDATE                                  \n")   //CRE_DATE   
                   .append("         ,?                                        \n")   //CREDIT_CD    
                   .append("         ,?                                        \n")   //CREDIT_VALUE 
                   .append("         ,?                                        \n")   //SYEAR        
                   .append("         ,?                                        \n")   //DEBT_AMT     
                   .append("         ,?                                        \n")   //CAPITAL_AMT  
                   .append("         ,?                                        \n")   //DEBT_RATE    
                   .append("         ,?                                        \n")   //LIQUID_ASSET 
                   .append("         ,?                                        \n")   //LIQUID_DEBT  
                   .append("         ,?                                        \n")   //LIQUID_RATE  
                   .append("         ,?                                        \n")   //LICENCE_YN   
                   .append("         ,?                                        \n")   //ETC_YN
                   .append("         ,?)                                       \n");  //CASH_GRADE       
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("p_corp_id"));
            persistent.addParameter("O");//job_div
            persistent.addParameter("I");
            persistent.addParameter(params.get("corp_reg_no").replace("-", ""));
            persistent.addParameter(params.get("corp_kor"));
            persistent.addParameter(params.get("rep_name"));
            persistent.addParameter(params.get("corp_gubun"));
            persistent.addParameter(params.get("p_status"));
            persistent.addParameter(params.get("USER_NAME"));
            persistent.addParameter(params.get("HP1"));
            persistent.addParameter(params.get("HP2"));
            persistent.addParameter(params.get("HP3"));
            persistent.addParameter(params.get("EMAIL"));
            //persistent.addParameter(params.get("REQ_DATE"));
            persistent.addParameter(params.get("REQ_EMP"));
            persistent.addParameter(params.get("DEPT_CD"));
            persistent.addParameter(params.get("DEPT_NM"));
            persistent.addParameter(params.get("REQ_REMARK"));
            persistent.addParameter(storage.getUser().get("acct_id"));
            persistent.addParameter(params.get("CREDIT_CD"));
            persistent.addParameter(params.get("CREDIT_VALUE"));
            persistent.addParameter(params.get("SYEAR"));
            persistent.addParameter(StringUtils.replace(params.get("DEBT_AMT"),",",""));
            persistent.addParameter(StringUtils.replace(params.get("CAPITAL_AMT"),",",""));   
            persistent.addParameter(StringUtils.replace(params.get("DEBT_RATE"),",",""));
            persistent.addParameter(StringUtils.replace(params.get("LIQUID_ASSET"),",","")); 
            persistent.addParameter(StringUtils.replace(params.get("LIQUID_DEBT"),",",""));
            persistent.addParameter(StringUtils.replace(params.get("LIQUID_RATE"),",",""));
            persistent.addParameter(params.get("LICENCE_YN"));
            persistent.addParameter(params.get("ETC_YN"));
            persistent.addParameter(params.get("CASH_GRADE"));
            persistent.execute();                     
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
        	WAFLogger.error("save_info========>" + e);
            e.printStackTrace();
            return false;            
        }
    }
	
	
	private boolean update_info(Connection conn, ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
        	persistent = new PersistentImpl(conn);
            
            
            sqlstr.append("     UPDATE SUPP_INFO_REQ SET                \n")
                   .append("          CORP_REG_NO = ?                   \n")
                   .append("         ,CORP_KOR = ?                      \n")
                   .append("         ,REP_NAME = ?                      \n")
                   .append("         ,STATUS = ?                        \n")
                   .append("         ,JOB_DIV    = ?                    \n")
                   .append("         ,USER_NAME  = ?                    \n")          
                   .append("         ,HP1        = ?                    \n")                
                   .append("         ,HP2        = ?                    \n")                
                   .append("         ,HP3        = ?                    \n")                
                   .append("         ,EMAIL      = ?                    \n")              
                   .append("         ,REQ_DATE   = TO_CHAR(SYSDATE, 'YYYY-MM-DD')   \n")           
                   .append("         ,REQ_EMP    = ?                    \n")            
                   .append("         ,DEPT_CD    = ?                    \n")            
                   .append("         ,DEPT_NM    = ?                    \n")                                                                       
                   .append("         ,REQ_REMARK = ?                    \n")                                                                    
                   .append("         ,UPD_BY     = ?                    \n")
                   .append("         ,UPD_DATE   = TO_CHAR(SYSDATE, 'YYYY-MM-DD')   \n")
                   .append("         ,CREDIT_CD   = ?                   \n")
                   .append("         ,CREDIT_VALUE= ?                   \n")
                   .append("         ,SYEAR       = ?                   \n")
                   .append("         ,DEBT_AMT    = ?                   \n")
                   .append("         ,CAPITAL_AMT = ?                   \n")
                   .append("         ,DEBT_RATE   = ?                   \n")
                   .append("         ,LIQUID_ASSET= ?                   \n")
                   .append("         ,LIQUID_DEBT = ?                   \n")
                   .append("         ,LIQUID_RATE = ?                   \n")
                   .append("         ,LICENCE_YN  = ?                   \n")
                   .append("         ,ETC_YN      = ?                   \n")
                   .append("         ,CASH_GRADE  = ?                   \n")
                   .append("     WHERE CORP_ID = ?                      \n");
            
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("corp_reg_no").replace("-", "").trim());
            persistent.addParameter(params.get("corp_kor").trim());
            persistent.addParameter(params.get("rep_name").trim());
            persistent.addParameter(params.get("p_status").trim());
            persistent.addParameter("O");//job_div
            
            persistent.addParameter(params.get("USER_NAME").trim());
            persistent.addParameter(params.get("HP1").trim());
            persistent.addParameter(params.get("HP2").trim());
            persistent.addParameter(params.get("HP3").trim());
            persistent.addParameter(params.get("EMAIL").trim());
            //persistent.addParameter(params.get("REQ_DATE").trim());
            persistent.addParameter(params.get("REQ_EMP").trim());
            persistent.addParameter(params.get("DEPT_CD").trim());
            persistent.addParameter(params.get("DEPT_NM").trim());
            persistent.addParameter(params.get("REQ_REMARK").trim());
            persistent.addParameter(storage.getUser().get("acct_id").trim());
            persistent.addParameter(params.get("CREDIT_CD"));
            persistent.addParameter(params.get("CREDIT_VALUE"));
            persistent.addParameter(params.get("SYEAR"));
            persistent.addParameter(StringUtils.replace(params.get("DEBT_AMT"),",",""));
            persistent.addParameter(StringUtils.replace(params.get("CAPITAL_AMT"),",",""));   
            persistent.addParameter(StringUtils.replace(params.get("DEBT_RATE"),",",""));
            persistent.addParameter(StringUtils.replace(params.get("LIQUID_ASSET"),",","")); 
            persistent.addParameter(StringUtils.replace(params.get("LIQUID_DEBT"),",",""));
            persistent.addParameter(StringUtils.replace(params.get("LIQUID_RATE"),",",""));
            persistent.addParameter(params.get("LICENCE_YN"));
            persistent.addParameter(params.get("ETC_YN"));
            persistent.addParameter(params.get("CASH_GRADE"));
            persistent.addParameter(params.get("p_corp_id").trim());
            
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
        	WAFLogger.error("update_info====>" + e);
            e.printStackTrace();
            return false;            
        }
    }
	
	
	
	private boolean delete_info(Connection conn, ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            persistent = new PersistentImpl(conn);
            
            
            sqlstr.append("     DELETE FROM  SUPP_INFO_REQ              \n")
                   .append("     WHERE CORP_ID = ?               \n");
            
            
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(params.get("p_corp_id").trim());
            
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
        	WAFLogger.error("delete_info====>" + e);
            e.printStackTrace();
            return false;            
        }
    }
    
        
	
	public ValueObject getCorp_no(Connection con) throws Exception{
        
        Persistent persistent_q = null;
        
        
        ValueObject vo = new ValueObject();
        ValueObject row = null;
        StringBuffer sqlstr =  new StringBuffer();
        
        try{
            persistent_q = new PersistentImpl(con);
            
            sqlstr.append("         SELECT COUNT(*) CNT                                                                       \n");
            sqlstr.append("           FROM (SELECT CORP_REG_NO FROM SUPP_INFO     WHERE CORP_REG_NO = ? AND JOB_DIV = 'O'       \n");
            sqlstr.append("                 UNION ALL                                                                         \n");
            sqlstr.append("                 SELECT CORP_REG_NO FROM SUPP_INFO_REQ WHERE CORP_REG_NO = ? AND JOB_DIV = 'O'  )    \n");
            
            persistent_q.setStatement(sqlstr.toString()); 
            persistent_q.addParameter(params.get("corp_reg_no").replace("-", ""));
            persistent_q.addParameter(params.get("corp_reg_no").replace("-", ""));
            
            row = RowSetUtility.getValueObject(persistent_q.query().getRow(0));
            vo.set("cnt", row.get("cnt"));
        }
        catch(Exception e) {
            e.printStackTrace();
        }finally{
            if(vo == null) vo = new ValueObject();
        }
        return vo;
    }	
	
    public ValueObject getCorp_no_r(Connection con) throws Exception{
        
        Persistent persistent_q = null;
        
        ValueObject vo = new ValueObject();
        ValueObject row = null;
        StringBuffer sqlstr =  new StringBuffer();
        
        try{
            persistent_q = new PersistentImpl(con);
            
            sqlstr.append("         SELECT COUNT(*) CNT FROM SUPP_INFO     WHERE CORP_REG_NO = ? AND JOB_DIV = 'O'       \n");
            
            persistent_q.setStatement(sqlstr.toString()); 
            persistent_q.addParameter(params.get("corp_reg_no").replace("-", ""));
            
            row = RowSetUtility.getValueObject(persistent_q.query().getRow(0));
            vo.set("cnt", row.get("cnt"));
        }
        catch(Exception e) {
            e.printStackTrace();
        }finally{
            if(vo == null) vo = new ValueObject();
        }
        return vo;
    }	
	
    public ValueObject getCheck() throws Exception{
	    Search search = new SearchImpl();
	    RowSet rowSet = new RowSetImpl();
        
        ValueObject row = null;
        StringBuffer sqlstr =  new StringBuffer();
        
        try{
            sqlstr.append(" SELECT  COUNT(*) AS CNT                                               	\n");
    		sqlstr.append(" FROM    SIGN001T                                                 	\n");
    		sqlstr.append("	WHERE SIGN_CLASS_CD = 'ebid_ocustD'											\n");
    		sqlstr.append("	AND SIGN_DECI_CLASS IN ('11','14')										\n");
    		sqlstr.append("	AND KEY_COL1 = '"+params.get("p_corp_id")+"'							\n");
    		sqlstr.append("	AND ATTR_6  = '0'  														\n");
            
    		search.setStatement(sqlstr.toString());
    		rowSet = search.execute();
    		System.out.println(sqlstr.toString());
    		if( rowSet != null && rowSet.size() > 0 ){
    			row = RowSetUtility.getValueObject(rowSet.getRow(0));
    		}    		
        }   
        catch(Exception e) {
            e.printStackTrace();
        } 
        finally{
        	if( row == null   ) row = new ValueObject();
        }
        return row;
    }

}