/**
 * @(#)file    SuppNotiDetailBiz.java
 * @(#)author  gyeongmo an
 * @(#)date    2014.7.18
 * @(#)Description: 협력업체 공지사항 상세
 *
 * Copyright (c) www.udapsoft.co.kr, Inc.
 * All rights reserved.
 */
package kr.co.udapsoft.ebid.supplier.portal.center.biz;

import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.Row;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.RowSetImpl;
import kr.co.hsnc.common.sql.WAFSQLException;
import kr.co.hsnc.common.sql.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.ebid.buyer.common.file.FileManager;

import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

public class SuppNotiDetailBiz extends Biz {

	public SuppNotiDetailBiz(HandlerStorage storage) {
		super(storage);
	}
	
	public void doBiz() throws Exception {
		ValueObject vo = new ValueObject();
    	if( storage.compareEvent("") ) {
    		String seq = params.get("seq");
			vo = getSuppNotiDetail();
	        storage.addValueObject("suppNotiDetailRowSet", vo);

	        RowSet rowSet = FileManager.getFileList("SUPP_NOTI_DETAIL", seq);
	        
	        String str="";
	        for(int i=0;i<rowSet.size();i++){
	        	Row row=rowSet.getRow(i);
	        	str += (i+1)+" : "+row.get("FILE_NAME")+" ("+ row.get("FILE_SIZE")+")";
	        	if(i+1!=rowSet.size()){
	        		str +="\r\n";
	        	}
	        }
	        
	        vo.set("SUPP_NOTI_DETAIL_FILE", str);
    	}else if(storage.compareEvent("GET_SUPP_NOTI_DETAIL")){
			String seq = params.get("seq");
			vo = getSuppNotiDetail();
	        storage.addValueObject("suppNotiDetailRowSet", vo);

	        RowSet rowSet = FileManager.getFileList("SUPP_NOTI_DETAIL", seq);
	        
	        String str="";
	        for(int i=0;i<rowSet.size();i++){
	        	Row row=rowSet.getRow(i);
	        	str += (i+1)+" : "+row.get("FILE_NAME")+" ("+ row.get("FILE_SIZE")+")";
	        	if(i+1!=rowSet.size()){
	        		str +="\r\n";
	        	}
	        }
	        
	        vo.set("SUPP_NOTI_DETAIL_FILE", str);
		} 
	}

	private ValueObject getSuppNotiDetail() {
        Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        StringBuffer sql = new StringBuffer();
        ValueObject vo = new ValueObject();
        try {
        	sql.append("	SELECT          		\n");
        	sql.append("		SEQ           		\n");
        	sql.append("		, NOTI_DIV    		\n");
        	sql.append("		, NOTI_DY    		\n");
        	sql.append("		, SUPP_OPEN_YN		\n");
        	sql.append("		, WRITE_NM    		\n");
        	sql.append("		, WRITE_ID    		\n");
        	sql.append("		, FILE_MAP_ID 		\n");
        	sql.append("		, TITLE       		\n");
        	sql.append("		, CONTENT     		\n");
        	sql.append("		, CRE_BY      		\n");
        	sql.append("		, CRE_DATE    		\n");
        	sql.append("		, UPD_BY      		\n");
        	sql.append("		, UPD_DATE    		\n");
        	sql.append("	FROM NOTI       		\n");
        	sql.append("	WHERE SEQ = '" + params.get("seq") + "'   		\n");
        	
        	search.setStatement(sql);
        	WAFLogger.debug(sql.toString());
            rowSet = search.execute();
            if(rowSet.size()>0){
                vo = RowSetUtility.getValueObject(rowSet.getRow(0));
            }
            return vo;
        }
        catch (WAFSQLException se) {
            super.doException(se);
            this.storage.setSuccess(false);
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        finally{
            if( vo == null) vo = new ValueObject();
            return vo;
        }
	}
	
}