package com.eactive.eai.rms.onl.eaiengine.engine;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service("queueMonitoringService")
public class QueueMonitoringService extends BaseService {

	@Autowired
	private QueueMonitoringDao dao;
	
	public HashMap selectList(int startNum,int endNum,HashMap<String, Object> paramMap) throws Exception {
		
		//해당 인스턴스  셋팅
		String serverNm = DataSourceContextHolder.getDataSourceType().getName();
		paramMap.put("eaiSevrInstncName"   , serverNm.substring(0, 2));
		// 전체 목록수 얻기
		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 void insert(HashMap<String, Object> paramMap) throws Exception {
    	dao.insert(paramMap);
    }
    
	public HashMap selectListToExcel(HashMap<String, Object> paramMap ) throws Exception {

		//해당 인스턴스  셋팅
		String serverNm = DataSourceContextHolder.getDataSourceType().getName();
		paramMap.put("eaiSevrInstncName"   , serverNm.substring(0, 2));
		List list = dao.selectListToExcel(paramMap);

    	for(int i=0;i<list.size();i++){
			HashMap tmp = new HashMap();
			tmp = (HashMap)list.get(i);
			
			String queloadcnt = tmp.get("QUELOADCNT").toString();
			String quemaxsavecnt = tmp.get("QUEMAXSAVECNT").toString();
			tmp.put("QUELOADCNT", String.valueOf(queloadcnt));
			tmp.put("QUEMAXSAVECNT", String.valueOf(quemaxsavecnt));
		}
		
		
		HashMap map = new HashMap();

		map.put("list", list);

		return map;
	}
}
