package com.eactive.eai.rms.onl.manage.serviceinfo.jmsqueuemonitor;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.eactive.eai.rms.common.base.BaseService;


/**
 * JMS Queue 관리 서비스
 */
@Service("jmsQueueMonitorManService")
@Transactional(propagation = Propagation.REQUIRED)
public class JmsQueueMonitorManService extends BaseService {

    @Autowired
    @Qualifier("jmsQueueMonitorDao")
    private JmsQueueMonitorDao dao;
    
    
    /**
     * JMS Queue 관리 리스트 검색
     * @param vo
     * @return
     * @throws Exception
     */
    
    public HashMap selectList(int startNum,int endNum, HashMap<String, Object> paramMap) throws Exception {
 
		// 전체 목록수 얻기
		int totalCount = dao.selectListCount(paramMap);

		paramMap.put("startNum" , startNum);// 시작 record
		paramMap.put("endNum"   , endNum);// 끝 record

		List <HashMap<String, Object>> list = dao.selectList(paramMap);

		HashMap map = new HashMap();

		map.put("totalCount", totalCount);

		map.put("list", list);

		return map;
	}
    public HashMap selectListToExcel(HashMap<String, Object> paramMap ) throws Exception {

		List list = dao.selectListToExcel(paramMap);

		HashMap map = new HashMap();

		map.put("list", list);

		return map;
	}
    public HashMap selectDetail(String nonSynczTranQueName , String sevrInstncName) throws Exception {

		HashMap paramMap = new HashMap();
		paramMap.put("nonSynczTranQueName", nonSynczTranQueName);
		paramMap.put("sevrInstncName", sevrInstncName);

		return dao.selectDetail( paramMap);

	}
    public int selectBoxCount() throws Exception {
    	HashMap paramMap = new HashMap();
        int cnt = dao.selectBoxCount(paramMap);
        return cnt;
    }
    
    public int selectInstCount() throws Exception {
    	HashMap paramMap = new HashMap();
        int cnt = dao.selectInstCount(paramMap);
        return cnt;
    }
    public List selectQueueMonitoringList(HashMap<String, Object> paramMap) throws Exception {
    	
		List <HashMap<String, Object>> list = dao.selectQueueMonitoringList(paramMap);
		return list;
	}
//    public List<JmsQueueMonitorVo> findPageList(JmsQueueMonitorVo vo) throws Exception {
//    	if (vo.getBzwkDstcd() != null && vo.getBzwkDstcd().length() > 0) {
//        	vo.setBzwkDstcd(vo.getBzwkDstcd());
//        }
//        else {
//        	vo.setBzwkDstcd("");
//        }
//
//    	ArrayList<JmsQueueMonitorVo> voList = new ArrayList<JmsQueueMonitorVo>();
//    	try {
//        	List<HashMap> list = jmsQueueMonitorDaoBean.getList(vo);
//        	String bzwkName = null;
//        	String prevBzwkName = null;
//        	String queBzwkCtnt = null;
//        	String prevQueBzwkCtnt = null;
//        	
//        	String instCd = null;
//        	String prevInstCd = null;
//        	
//        	
//        	JmsQueueMonitorVo mvo = null;
//        	
//        	for (int i = 0; i < list.size(); i++) {
//        		Map hm = (Map) list.get(i);
//        		bzwkName = hm.get("EAIBzwkDstcd").toString();
//        		queBzwkCtnt = hm.get("EAIQueBzwkCtnt").toString();
//        		instCd = hm.get("EAISevrInstncName").toString();
//        		
//        		if( (prevBzwkName == null || ! bzwkName.equals(prevBzwkName) ) 
//        			|| (prevQueBzwkCtnt == null || ! queBzwkCtnt.equals(prevQueBzwkCtnt) )
//        			|| (prevInstCd == null || ! instCd.equals(prevInstCd) )
//        		){
//        			if(prevBzwkName != null) {
//        				voList.add(mvo);
//        			}
//        			mvo = new JmsQueueMonitorVo();
//        			mvo.setBzwkDstcd(bzwkName);
//        			mvo.setQueBzwkCtnt(queBzwkCtnt);
//        			mvo.setInstCd(instCd);
//        			mvo.setBzwkDstcdName(hm.get("BzwkDsticName").toString());        			
//        		}
//        		
//        		String usageDstcd = hm.get("QueUsagDstcd").toString();
//        		String queueName  = hm.get("NonSynczTranQueName").toString();
//        		
//        		if("1".equals(usageDstcd)) {
//        			mvo.setSendQueueName(queueName);
//        			mvo.setSendCount(0);
//        		}
//        		else if("2".equals(usageDstcd)) {
//        			mvo.setReceiveQueueName(queueName);
//        			mvo.setReceiveCount(0);
//        		}
//        		else if("3".equals(usageDstcd)) {
//        			mvo.setSendErrorQueueName(queueName);
//        			mvo.setSendErrorCount(0);
//        		}
//        		else if("4".equals(usageDstcd)) {
//        			mvo.setReceiveErrorQueueName(queueName);
//        			mvo.setReceiveErrorCount(0);
//        		}
//        		prevBzwkName = bzwkName;
//        		prevQueBzwkCtnt = queBzwkCtnt;
//        	}
//        	if(mvo != null) voList.add(mvo); // 마지막리스트를 적재        	
//        	
//        }
//        catch(Exception ex) {
//        	ex.printStackTrace();
//        }
//        
//        
//        return voList;
//        
//    }
//
//    /**
//     * JMS Queue 관리 상세조회
//     * @param vo
//     * @return
//     * @throws Exception
//     */
//    public JmsQueueMonitorVo findDetail(JmsQueueMonitorVo vo) throws Exception {
//
//        List<JmsQueueMonitorVo> voList = null;
//        List<HashMap> list = jmsQueueMonitorDaoBean.detail(vo);
//
//        if (list != null && list.size() > 0) {
//            return voList.get(0);
//        }
//
//        return null;
//    }

}
