/**
 * @(#)file    SYSRightRegPgmListBiz.java
 * @(#)author  gyeongmo an
 * @(#)date    2014.6.22
 *
 * Copyright (c) www.udapsoft.co.kr, Inc.
 * All rights reserved.
 */
package kr.co.udapsoft.ebid.buyer.sycs.security.biz;

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.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.util.ValueObject;
import com.udapsoft.modular.web.ibsheet7.IBSheet7Factory;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

public class SYSRightRegPgmListBiz extends Biz {
    
    public SYSRightRegPgmListBiz(HandlerStorage storage) {
        super(storage);
    }
    public void doBiz() throws Exception {
    	if (storage.compareEvent("GET_PGL_LIST")) {
    		params.set("sheet1", getPglList(params));
    		storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
    	}else{
    		SYSRightCommon common = new SYSRightCommon();
    		
    		String systemSelectTag =  common.getSystemSelectTag(params.get("system_id"), "style='width:95%;height=18;'");
    		storage.addObject("SystemSelectTag", systemSelectTag);
    		
    		String selectText =  common.getSystemSelectTagCombo(params.get("system_id"), "style='width:220px;height=18;'");
    		storage.addObject("selectText", selectText);
    		
    		String selectValue =  common.getSystemSelectTagCode(params.get("system_id"), "style='width:220px;height=18;'");
    		storage.addObject("selectValue", selectValue);
    	}
    }
    

    private RowSet getPglList(ValueObject params) {
        Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        StringBuffer sql = new StringBuffer();
        String sortGb = params.get("sort_gb_value");
        
        if( sortGb.equals("") )
            sortGb = "PGM_ID";
        
        try {
        	sql.append("	SELECT  CONCAT(CONCAT(B.SYSTEM_ID, '@'),   B.SYSTEM_CODE)  AS SYSTEM_ID,                        	\n");
        	 sql.append("		A.PGM_NAME,                                                                                   	\n");
        	 sql.append("		A.SCREEN_NAME,                                                                                	\n");
        	 sql.append("		A.DSCR,                                                                                       	\n");
        	 sql.append("		F_GET_USER_NM(A.UPD_BY) UPD_BY,                                                                                     	\n");
        	 sql.append("		TO_DATE(A.UPD_DATE, 'YYYYMMDDHH24MISS') AS UPD_DATE,                                          	\n");
        	 sql.append("		B.SYSTEM_CODE AS SYSTEM_CODE,                                                                 	\n");
        	 sql.append("		A.PGM_ID AS PGM_ID                                                                            	\n");
        	 sql.append("	 FROM    PUB0320T     A ,                                                                       	\n");
        	 sql.append("	         PUB0390T B                                                                             	\n");
        	 sql.append("	 WHERE  A.SYSTEM_ID = B.SYSTEM_ID                                                               	\n");
        	 
        	 if(!"".equals(params.get("pgm_name2").trim())) {
        		 sql.append("	 AND A.PGM_NAME LIKE '%' || ? || '%'                                                            	\n");
        		 search.addParameter(params.get("pgm_name2").trim());
        	 }
        	 if(!"".equals(params.get("screen_name2").trim())) {
        		 sql.append("	 AND A.SCREEN_NAME LIKE '%' || ? || '%'                                                         	\n");
        		 search.addParameter(params.get("screen_name2").trim());
        	 }
        	 if(!"".equals(params.get("system_id").trim())) {
        		 sql.append("	 AND A.SYSTEM_ID = ?                                                                            	\n");
        		 search.addParameter(params.get("system_id").trim());
        	 }
        	 
        	 sql.append("	 ORDER BY " + sortGb + "                                                                                	\n");
            
            search.setStatement(sql);
            rowSet = search.execute();
        }
        catch (WAFSQLException se) {  
            super.doException(se);
            this.storage.setSuccess(false);
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        finally {    
            if(rowSet == null) rowSet = new RowSetImpl();
            return rowSet;
        }
    }
}
